1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "MissingEntityClassnameIssueGenerator.h"
21 
22 #include "StringUtils.h"
23 #include "Assets/EntityDefinition.h"
24 #include "Model/Brush.h"
25 #include "Model/Entity.h"
26 #include "Model/Issue.h"
27 #include "Model/IssueQuickFix.h"
28 #include "Model/MapFacade.h"
29 
30 #include <cassert>
31 
32 namespace TrenchBroom {
33     namespace Model {
34         class MissingEntityClassnameIssueGenerator::MissingEntityClassnameIssue : public EntityIssue {
35         public:
36             static const IssueType Type;
37         public:
MissingEntityClassnameIssue(Entity * entity)38             MissingEntityClassnameIssue(Entity* entity) :
39             EntityIssue(entity) {}
40         private:
doGetType() const41             IssueType doGetType() const {
42                 return Type;
43             }
44 
doGetDescription() const45             const String doGetDescription() const {
46                 return "Entity has no classname property";
47             }
48         };
49 
50         const IssueType MissingEntityClassnameIssueGenerator::MissingEntityClassnameIssue::Type = Issue::freeType();
51 
52         class MissingEntityClassnameIssueGenerator::MissingEntityClassnameIssueQuickFix : public IssueQuickFix {
53         public:
MissingEntityClassnameIssueQuickFix()54             MissingEntityClassnameIssueQuickFix() :
55             IssueQuickFix("Delete entities") {}
56         private:
doApply(MapFacade * facade,const IssueList & issues) const57             void doApply(MapFacade* facade, const IssueList& issues) const {
58                 facade->deleteObjects();
59             }
60         };
61 
MissingEntityClassnameIssueGenerator()62         MissingEntityClassnameIssueGenerator::MissingEntityClassnameIssueGenerator() :
63         IssueGenerator(MissingEntityClassnameIssue::Type, "Missing entity classname") {
64             addQuickFix(new MissingEntityClassnameIssueQuickFix());
65         }
66 
doGenerate(Entity * entity,IssueList & issues) const67         void MissingEntityClassnameIssueGenerator::doGenerate(Entity* entity, IssueList& issues) const {
68             if (!entity->hasAttribute(AttributeNames::Classname))
69                 issues.push_back(new MissingEntityClassnameIssue(entity));
70         }
71     }
72 }
73