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 "FindGroupVisitor.h" 21 22 #include "Model/Node.h" 23 24 namespace TrenchBroom { 25 namespace Model { FindGroupVisitor(const bool findTopGroup)26 FindGroupVisitor::FindGroupVisitor(const bool findTopGroup) : 27 m_findTopGroup(findTopGroup) {} 28 doVisit(World * world)29 void FindGroupVisitor::doVisit(World* world) {} doVisit(Layer * layer)30 void FindGroupVisitor::doVisit(Layer* layer) {} 31 doVisit(Group * group)32 void FindGroupVisitor::doVisit(Group* group) { 33 setResult(group); 34 if (!m_findTopGroup) 35 cancel(); 36 } 37 doVisit(Entity * entity)38 void FindGroupVisitor::doVisit(Entity* entity) {} doVisit(Brush * brush)39 void FindGroupVisitor::doVisit(Brush* brush) {} 40 findGroup(Model::Node * node)41 Model::Group* findGroup(Model::Node* node) { 42 FindGroupVisitor visitor(false); 43 node->escalate(visitor); 44 if (!visitor.hasResult()) 45 return NULL; 46 return visitor.result(); 47 } 48 findTopGroup(Model::Node * node)49 Model::Group* findTopGroup(Model::Node* node) { 50 FindGroupVisitor visitor(true); 51 node->escalate(visitor); 52 if (!visitor.hasResult()) 53 return NULL; 54 return visitor.result(); 55 } 56 } 57 } 58