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 "HitAdapter.h" 21 #include "Hit.h" 22 #include "Model/Brush.h" 23 #include "Model/BrushFace.h" 24 #include "Model/Entity.h" 25 #include "Model/Group.h" 26 27 namespace TrenchBroom { 28 namespace Model { hitToNode(const Hit & hit)29 Node* hitToNode(const Hit& hit) { 30 if (hit.type() == Group::GroupHit) 31 return hit.target<Node*>(); 32 if (hit.type() == Entity::EntityHit) 33 return hit.target<Node*>(); 34 if (hit.type() == Brush::BrushHit) { 35 BrushFace* face = hit.target<BrushFace*>(); 36 return face->brush(); 37 } 38 return NULL; 39 } 40 hitToObject(const Hit & hit)41 Object* hitToObject(const Hit& hit) { 42 if (hit.type() == Group::GroupHit) 43 return hit.target<Object*>(); 44 if (hit.type() == Entity::EntityHit) 45 return hit.target<Object*>(); 46 if (hit.type() == Brush::BrushHit) { 47 BrushFace* face = hit.target<BrushFace*>(); 48 return face->brush(); 49 } 50 return NULL; 51 } 52 hitToGroup(const Hit & hit)53 Group* hitToGroup(const Hit& hit) { 54 if (hit.type() == Group::GroupHit) 55 return hit.target<Group*>(); 56 return NULL; 57 } 58 hitToEntity(const Hit & hit)59 Entity* hitToEntity(const Hit& hit) { 60 if (hit.type() == Entity::EntityHit) 61 return hit.target<Entity*>(); 62 return NULL; 63 } 64 hitToBrush(const Hit & hit)65 Brush* hitToBrush(const Hit& hit) { 66 if (hit.type() == Brush::BrushHit) 67 return hit.target<BrushFace*>()->brush(); 68 return NULL; 69 } 70 hitToFace(const Hit & hit)71 BrushFace* hitToFace(const Hit& hit) { 72 if (hit.type() == Brush::BrushHit) 73 return hit.target<BrushFace*>(); 74 return NULL; 75 } 76 } 77 } 78