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 "EmptyBrushEntityIssueGenerator.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 EmptyBrushEntityIssueGenerator::EmptyBrushEntityIssue : public EntityIssue { 35 public: 36 static const IssueType Type; 37 public: EmptyBrushEntityIssue(Entity * entity)38 EmptyBrushEntityIssue(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()->classname() + " does not contain any brushes"; 47 } 48 }; 49 50 const IssueType EmptyBrushEntityIssueGenerator::EmptyBrushEntityIssue::Type = Issue::freeType(); 51 52 class EmptyBrushEntityIssueGenerator::EmptyBrushEntityIssueQuickFix : public IssueQuickFix { 53 public: EmptyBrushEntityIssueQuickFix()54 EmptyBrushEntityIssueQuickFix() : 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 EmptyBrushEntityIssueGenerator()62 EmptyBrushEntityIssueGenerator::EmptyBrushEntityIssueGenerator() : 63 IssueGenerator(EmptyBrushEntityIssue::Type, "Empty brush entity") { 64 addQuickFix(new EmptyBrushEntityIssueQuickFix()); 65 } 66 doGenerate(Entity * entity,IssueList & issues) const67 void EmptyBrushEntityIssueGenerator::doGenerate(Entity* entity, IssueList& issues) const { 68 assert(entity != NULL); 69 const Assets::EntityDefinition* definition = entity->definition(); 70 if (definition != NULL && definition->type() == Assets::EntityDefinition::Type_BrushEntity && !entity->hasChildren()) 71 issues.push_back(new EmptyBrushEntityIssue(entity)); 72 } 73 } 74 } 75