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 #ifndef TrenchBroom_VertexTool 21 #define TrenchBroom_VertexTool 22 23 #include "StringUtils.h" 24 #include "TrenchBroom.h" 25 #include "VecMath.h" 26 #include "Model/Hit.h" 27 #include "View/Tool.h" 28 #include "View/UndoableCommand.h" 29 #include "View/VertexHandleManager.h" 30 31 namespace TrenchBroom { 32 namespace Model { 33 class PickResult; 34 class SelectionResult; 35 } 36 37 namespace Renderer { 38 class Camera; 39 class RenderBatch; 40 class RenderContext; 41 } 42 43 namespace View { 44 class Grid; 45 class InputState; 46 class Lasso; 47 class MovementRestriction; 48 class Selection; 49 50 class VertexTool : public Tool { 51 public: 52 typedef enum { 53 MR_Continue, 54 MR_Deny, 55 MR_Cancel 56 } MoveResult; 57 private: 58 typedef enum { 59 Mode_Move, 60 Mode_Split 61 } Mode; 62 63 MapDocumentWPtr m_document; 64 VertexHandleManager m_handleManager; 65 Mode m_mode; 66 size_t m_changeCount; 67 bool m_ignoreChangeNotifications; 68 Vec3 m_dragHandlePosition; 69 bool m_dragging; 70 public: 71 VertexTool(MapDocumentWPtr document); 72 73 const Grid& grid() const; 74 75 void pick(const Ray3& pickRay, const Renderer::Camera& camera, Model::PickResult& pickResult); 76 77 bool deselectAll(); 78 bool mergeVertices(const Model::Hit& hit); 79 bool handleDoubleClicked(const Model::Hit& hit); 80 bool select(const Model::Hit::List& hits, bool addToSelection); 81 void select(const Lasso& lasso, bool modifySelection); 82 83 bool beginMove(const Model::Hit& hit); 84 MoveResult move(const Vec3& delta); 85 void endMove(); 86 void cancelMove(); 87 88 void renderHandles(Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch); 89 void renderHighlight(Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch); 90 void renderHighlight(Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch, const Vec3& position); 91 void renderEdgeHighlight(Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch, const Vec3& handlePosition); 92 void renderFaceHighlight(Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch, const Vec3& handlePosition); 93 void renderGuide(Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch); 94 void renderGuide(Renderer::RenderContext& renderContext, Renderer::RenderBatch& renderBatch, const Vec3& position); 95 96 bool cancel(); 97 98 bool handleBrushes(const Vec3& position, Model::BrushSet& brushes) const; 99 bool handleSelected(const Vec3& position) const; 100 bool hasSelectedHandles() const; 101 void moveVerticesAndRebuildBrushGeometry(const Vec3& delta); 102 bool canSnapVertices() const; 103 void snapVertices(size_t snapTo); 104 private: 105 void selectVertex(const Model::Hit::List& hits, bool addToSelection); 106 void selectEdge(const Model::Hit::List& hits, bool addToSelection); 107 void selectFace(const Model::Hit::List& hits, bool addToSelection); 108 109 String actionName() const; 110 111 MoveResult moveVertices(const Vec3& delta); 112 MoveResult doMoveVertices(const Vec3& delta); 113 MoveResult doMoveEdges(const Vec3& delta); 114 MoveResult doMoveFaces(const Vec3& delta); 115 MoveResult doSplitEdges(const Vec3& delta); 116 MoveResult doSplitFaces(const Vec3& delta); 117 118 void rebuildBrushGeometry(); 119 120 bool doActivate(); 121 bool doDeactivate(); 122 123 void bindObservers(); 124 void unbindObservers(); 125 126 void commandDo(Command::Ptr command); 127 void commandDone(Command::Ptr command); 128 void commandDoFailed(Command::Ptr command); 129 void commandUndo(UndoableCommand::Ptr command); 130 void commandUndone(UndoableCommand::Ptr command); 131 void commandUndoFailed(UndoableCommand::Ptr command); 132 133 void commandDoOrUndo(Command::Ptr command); 134 void commandDoneOrUndoFailed(Command::Ptr command); 135 void commandDoFailedOrUndone(Command::Ptr command); 136 bool isVertexCommand(const Command::Ptr command) const; 137 138 void selectionDidChange(const Selection& selection); 139 void nodesWillChange(const Model::NodeList& nodes); 140 void nodesDidChange(const Model::NodeList& nodes); 141 private: // implement Tool interface 142 String doGetIconName() const; 143 }; 144 } 145 } 146 147 #endif /* defined(TrenchBroom_VertexTool) */ 148