API Documentation
Loading...
Searching...
No Matches
SnapController.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Design
28File: SnapController
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/SnapPoint.h>
34#include <NDEVR/MouseController.h>
35#if NDEVR_VIEWPORT
36#include <NDEVR/KeyController.h>
37#include <NDEVR/SelectionArea.h>
38#include <NDEVR/Plane.h>
39#include <functional>
40namespace NDEVR
41{
42
43 class DesignObjectLookup;
44
45 /**--------------------------------------------------------------------------------------------------
46 \brief Allows for mouse snaps to certain key points of interest in the software. Can also create
47 visuals to help with user mouse interaction with DesignObjectLookup.
48 **/
49 class NDEVR_DESIGN_API SnapController : public MouseControllerBase, public KeyControllerBase
50 {
51 public:
52 enum PointsDrawMode
53 {
56 , e_lines
57 , e_line_fan
59 };
60 enum LockMode
61 {
62 e_lock_ignore_snap//Ignores all snapping
63 , e_lock_to_nearest_snap//First snaps, then gets closest position to snap point
64 , e_lock_if_no_snap//only locks if there is no snaps
65 , e_only_allow_snap
66 , e_ignore//ignores lock guides
67 };
68 public:
69 explicit SnapController(DesignObjectLookup* manager);
70 virtual ~SnapController(){}
71 virtual void cancel();
72
73 virtual bool processMouseEvent(const MouseEvent& event, DesignObjectLookup* lookup, Camera* camera) override;
74 virtual bool processKeyEvent(const KeyEvent& event, DesignObjectLookup* lookup, Camera* camera) override;
75
76 void clearSnapSelection();
77 uint04 pointCount() const { return m_points.size(); }
78 virtual void setUpdateCallback(const std::function<void()>& callback) { m_update_callback = callback; }
79 virtual void setFinishedCallback(const std::function<void(bool is_accepted)>& callback) { m_finished_callback = callback; }
80 void lockAxis(uint01 axis, fltp08 lock) { m_lock_axis[axis] = lock; }
81 SelectionMode selectionMode() const { return m_selection_mode; }
82 void setSelectionMode(SelectionMode mode) { m_selection_mode = mode; }
83 Vertex<3, fltp08> currentLocation() const { return m_location; }
84 void setLockMode(LockMode mode);
85 void setLockLine(const LineSegment<3, fltp08>& line);
86 void setLockPlane(const Plane<3, fltp08>& plane);
87 void setCustomSnapManager(const ConstPointer<SnapsManager>& snap_manager) { m_custom_snap_manager = snap_manager; };
88 void setLocation(const Vertex<3, fltp08>& location, bool is_click = false, Camera* camera = nullptr);
89 void setShowLengthLabels(bool show);
90 void setShowPointLabels(bool show);
91
92 void setPointsDrawMode(PointsDrawMode mode) { m_point_draw_mode = mode; }
93 const Buffer<Vertex<3, fltp08>>& points() const { return m_points; }
94 Vertex<3, fltp08> lastPoint() const { return m_location; }
95 const Buffer<SnapPoint>& lastSnapPoints() const { return m_last_snap_points; }
96
97 Resource<SnapPoint> current_snap_point;
98 protected:
99 virtual void addPoint(const Vertex<3, fltp08>& point);
100 virtual void addPoint(const SnapPoint& point);
101 virtual void begin();
102 virtual void finish();
103 virtual void updateLocation(const Vertex<3, fltp08>& location, bool is_click, Camera* camera);
104 SelectionInfo getSelectionInfo(const MouseEvent& event, DesignObjectLookup* lookup, Camera* camera);
105 void addGuideLineModel();
106 void addGuidePointModel();
107 bool processMouseSnap(const MouseEvent& event, DesignObjectLookup* lookup, Camera* camera);
108 bool processMouseSelection(const MouseEvent& event, DesignObjectLookup* lookup, Camera* camera);
109 void setGuidePoint(uint04 index, const Vertex<3, fltp08>& p1, const UUID& material);
110 void setGuideLine(uint04 index, const Vertex<3, fltp08>& p1, const Vector<3, fltp08>& p2, const UUID& material);
111 void calcLockLineLocation(SnapPoint& point, const SelectionInfo& info);
112 void calcLockPlaneLocation(SnapPoint& point, const SelectionInfo& info);
113 void setGuideLineVisible(bool visible);
114 void setGuideLineVisible(uint04 index, bool visible);
115 void setGuidePointVisible(bool visible);
116 void setGuidePointVisible(uint04 index, bool visible);
117 void drawDefaultGuideLines(const SnapPoint& point);
118 Model setupGuideModel();
119 void updateRecentGeometry(const SnapPoint& point);
120 virtual SelectionInfo createSelectionInfo(const MouseEvent& event, Camera* camera);
121 SnapPoint calcSnapPoint(const SelectionInfo& info, DesignObjectLookup* lookup);
122 UUID pointMaterial(const SnapPoint& point);
123 UUID lineMaterial(const SnapPoint& point);
124 protected:
125 Buffer<Vertex<3, fltp08>> m_points;
126 Vertex<3, fltp08> m_location;
127 Vertex<3, fltp08> m_lock_axis;
128 LineSegment<3, fltp08> m_lock_line;
129 Plane<3, fltp08> m_lock_plane;
130
131 SnapPoint m_original_snap;
132 UUID m_current_line_material = Constant<UUID>::Invalid;
133
134 UUID m_free_point_material = Constant<UUID>::Invalid;
135 UUID m_point_material = Constant<UUID>::Invalid;
136 UUID m_edge_point_material = Constant<UUID>::Invalid;
137 UUID m_end_point_material = Constant<UUID>::Invalid;
138 UUID m_mid_point_material = Constant<UUID>::Invalid;
139 UUID m_center_point_material = Constant<UUID>::Invalid;
140 UUID m_on_face_point_material = Constant<UUID>::Invalid;
141
142 UUID m_free_line_material = Constant<UUID>::Invalid;
143 UUID m_locked_line_material = Constant<UUID>::Invalid;
144 UUID m_extend_line_material = Constant<UUID>::Invalid;
145 UUID m_perpendicular_line_material = Constant<UUID>::Invalid;
146 UUID m_tangent_line_material = Constant<UUID>::Invalid;
147 UUID m_red_line_material = Constant<UUID>::Invalid;
148 UUID m_green_line_material = Constant<UUID>::Invalid;
149 UUID m_blue_line_material = Constant<UUID>::Invalid;
150
151 UUID m_last_selection_camera= Constant<UUID>::Invalid;
152
153 UUID m_guide_model = Constant<UUID>::Invalid;
154 UUID m_line_mesh = Constant<UUID>::Invalid;
155 UUID m_point_mesh = Constant<UUID>::Invalid;
156 Buffer<UUID> m_guide_line_model;
157 Buffer<UUID> m_guide_point_model;
158
159 Buffer<UUID> m_line_guide_text;
160 Buffer<UUID> m_point_guide_text;
161
162 Buffer<UUID> m_guide_line_material;
163 Buffer<UUID> m_guide_point_material;
164
165 Buffer<std::pair<UUID, uint04>> m_last_lines;
166 Buffer<std::pair<UUID, uint04>> m_last_meshes;
167 Buffer<std::pair<UUID, uint04>> m_last_points;
168 ConstPointer<SnapsManager> m_custom_snap_manager;
169 PointsDrawMode m_point_draw_mode;
170 std::function<void()> m_update_callback;
171 std::function<void(bool is_accepted)> m_finished_callback;
172 DesignObjectLookup* m_manager;
173 SelectionMode m_selection_mode;
174 Buffer<SnapPoint> m_last_snap_points;
175 LockMode m_lock_mode;
176 bool m_is_active;
177 bool m_show_length_label;
178 bool m_show_location_label;
179 };
180}
181
182#endif
183
#define NDEVR_DESIGN_API
Definition DLLInfo.h:55
Definition ACIColor.h:37
SelectionMode
Definition SelectionArea.hpp:46
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96