1 #pragma once 2 3 #include "math/Plane3.h" 4 #include "math/line.h" 5 #include "render.h" 6 #include "selectionlib.h" 7 8 #include "SelectableComponents.h" 9 #include "VertexSelection.h" 10 #include "Face.h" 11 12 typedef const Plane3* PlanePointer; 13 typedef PlanePointer* PlanesIterator; 14 15 class FaceInstance 16 { 17 private: 18 Face* m_face; 19 ObservedSelectable m_selectable; 20 ObservedSelectable m_selectableVertices; 21 ObservedSelectable m_selectableEdges; 22 SelectionChangeCallback m_selectionChanged; 23 24 VertexSelection m_vertexSelection; 25 VertexSelection m_edgeSelection; 26 27 public: 28 FaceInstance (Face& face, const SelectionChangeCallback& observer); 29 FaceInstance (const FaceInstance& other); 30 FaceInstance& operator= (const FaceInstance& other); 31 Face& getFace (); 32 const Face& getFace () const; 33 Face* getFacePtr () const; 34 void selectedChanged (const Selectable& selectable); 35 typedef MemberCaller1<FaceInstance, const Selectable&, &FaceInstance::selectedChanged> SelectedChangedCaller; 36 37 bool selectedVertices () const; 38 bool selectedEdges () const; 39 bool isSelected () const; 40 void invertSelected(); 41 42 bool selectedComponents () const; 43 bool selectedComponents (SelectionSystem::EComponentMode mode) const; 44 void setSelected (SelectionSystem::EComponentMode mode, bool select); 45 46 template<typename Functor> 47 void SelectedVertices_foreach (Functor functor) const; 48 49 template<typename Functor> 50 void SelectedEdges_foreach (Functor functor) const; 51 52 template<typename Functor> 53 void SelectedFaces_foreach (Functor functor) const; 54 55 template<typename Functor> 56 void SelectedComponents_foreach (Functor functor) const; 57 58 void iterate_selected (AABB& aabb) const; 59 60 class RenderablePointVectorPushBack 61 { 62 RenderablePointVector& m_points; 63 public: RenderablePointVectorPushBack(RenderablePointVector & points)64 RenderablePointVectorPushBack (RenderablePointVector& points) : 65 m_points(points) 66 { 67 } operator()68 void operator() (const Vector3& point) const 69 { 70 const Colour4b colour_selected(0, 0, 255, 255); 71 m_points.push_back(PointVertex(point, colour_selected)); 72 } 73 }; 74 void iterate_selected (RenderablePointVector& points) const; 75 76 bool intersectVolume (const VolumeTest& volume, const Matrix4& localToWorld) const; 77 78 void render (Renderer& renderer, const VolumeTest& volume, const Matrix4& localToWorld) const; 79 80 void testSelect (SelectionTest& test, SelectionIntersection& best); 81 void testSelect (Selector& selector, SelectionTest& test); 82 void testSelect_centroid (Selector& selector, SelectionTest& test); 83 84 void selectPlane (Selector& selector, const Line& line, PlanesIterator first, PlanesIterator last, 85 const PlaneCallback& selectedPlaneCallback); 86 void selectReversedPlane (Selector& selector, const SelectedPlanes& selectedPlanes); 87 88 void transformComponents (const Matrix4& matrix); 89 90 void snapto (float snap); 91 92 void snapComponents (float snap); 93 void update_move_planepts_vertex (std::size_t index); 94 void update_move_planepts_vertex2 (std::size_t index, std::size_t other); 95 void update_selection_vertex (); 96 void select_vertex (std::size_t index, bool select); 97 bool selected_vertex (std::size_t index) const; 98 99 void update_move_planepts_edge (std::size_t index); 100 void update_selection_edge (); 101 void select_edge (std::size_t index, bool select); 102 bool selected_edge (std::size_t index) const; 103 const Vector3& centroid () const; 104 void connectivityChanged (); 105 }; 106 107 typedef std::vector<FaceInstance> FaceInstances; 108 typedef SelectionList<FaceInstance> FaceInstancesList; 109 110 class FaceInstanceSet 111 { 112 public: 113 FaceInstancesList m_faceInstances; 114 115 /** @brief Insert a new face instance into the selected faces list */ insert(FaceInstance & faceInstance)116 void insert (FaceInstance& faceInstance) 117 { 118 m_faceInstances.append(faceInstance); 119 } 120 /** @brief Removes a face instance from the selected faces list */ erase(FaceInstance & faceInstance)121 void erase (FaceInstance& faceInstance) 122 { 123 m_faceInstances.erase(faceInstance); 124 } 125 126 template<typename Functor> foreach(Functor functor)127 void foreach (Functor functor) 128 { 129 for (FaceInstancesList::iterator i = m_faceInstances.begin(); i != m_faceInstances.end(); ++i) { 130 functor(*(*i)); 131 } 132 } 133 134 /** @brief Wipes the list of selected faces */ empty()135 bool empty () const 136 { 137 return m_faceInstances.empty(); 138 } 139 140 /** @return The last entry of all the selected faces */ last()141 FaceInstance& last () const 142 { 143 return m_faceInstances.back(); 144 } 145 size()146 std::size_t size() const { 147 return m_faceInstances.size(); 148 } 149 }; 150 151 extern FaceInstanceSet g_SelectedFaceInstances; 152