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 class NDEVR_DESIGN_API SnapController : public MouseControllerBase, public KeyControllerBase
45 {
46 public:
47 enum PointsDrawMode
48 {
51 , e_lines
52 , e_line_fan
54 };
55 enum LockMode
56 {
57 e_lock_ignore_snap//Ignores all snapping
58 , e_lock_to_nearest_snap//First snaps, then gets closest position to snap point
59 , e_lock_if_no_snap//only locks if there is no snaps
60 , e_only_allow_snap
61 , e_ignore//ignores lock guides
62 };
63 public:
64 explicit SnapController(DesignObjectLookup* manager);
65 virtual ~SnapController(){}
66 virtual void cancel();
67
68 virtual bool processMouseEvent(const MouseEvent& event, DesignObjectLookup* lookup, Camera* camera) override;
69 virtual bool processKeyEvent(const KeyEvent& event, DesignObjectLookup* lookup, Camera* camera) override;
70
71 void clearSnapSelection();
72 uint04 pointCount() const { return m_points.size(); }
73 virtual void setUpdateCallback(const std::function<void()>& callback) { m_update_callback = callback; }
74 virtual void setFinishedCallback(const std::function<void(bool is_accepted)>& callback) { m_finished_callback = callback; }
75 void lockAxis(uint01 axis, fltp08 lock) { m_lock_axis[axis] = lock; }
76 SelectionMode selectionMode() const { return m_selection_mode; }
77 void setSelectionMode(SelectionMode mode) { m_selection_mode = mode; }
78 Vertex<3, fltp08> currentLocation() const { return m_location; }
79 void setLockMode(LockMode mode);
80 void setLockLine(const LineSegment<3, fltp08>& line);
81 void setLockPlane(const Plane<3, fltp08>& plane);
82 void setCustomSnapManager(const ConstPointer<SnapsManager>& snap_manager) { m_custom_snap_manager = snap_manager; };
83 void setLocation(const Vertex<3, fltp08>& location, bool is_click = false, Camera* camera = nullptr);
84 void setShowLengthLabels(bool show);
85 void setShowPointLabels(bool show);
86
87 void setPointsDrawMode(PointsDrawMode mode) { m_point_draw_mode = mode; }
88 const Buffer<Vertex<3, fltp08>>& points() const { return m_points; }
89 Vertex<3, fltp08> lastPoint() const { return m_location; }
90 const Buffer<SnapPoint>& lastSnapPoints() const { return m_last_snap_points; }
91
92 Resource<SnapPoint> current_snap_point;
93 protected:
94 virtual void addPoint(const Vertex<3, fltp08>& point);
95 virtual void addPoint(const SnapPoint& point);
96 virtual void begin();
97 virtual void finish();
98 virtual void updateLocation(const Vertex<3, fltp08>& location, bool is_click, Camera* camera);
99 SelectionInfo getSelectionInfo(const MouseEvent& event, DesignObjectLookup* lookup, Camera* camera);
100 void addGuideLineModel();
101 void addGuidePointModel();
102 bool processMouseSnap(const MouseEvent& event, DesignObjectLookup* lookup, Camera* camera);
103 bool processMouseSelection(const MouseEvent& event, DesignObjectLookup* lookup, Camera* camera);
104 void setGuidePoint(uint04 index, const Vertex<3, fltp08>& p1, const UUID& material);
105 void setGuideLine(uint04 index, const Vertex<3, fltp08>& p1, const Vector<3, fltp08>& p2, const UUID& material);
106 void calcLockLineLocation(SnapPoint& point, const SelectionInfo& info);
107 void calcLockPlaneLocation(SnapPoint& point, const SelectionInfo& info);
108 void setGuideLineVisible(bool visible);
109 void setGuideLineVisible(uint04 index, bool visible);
110 void setGuidePointVisible(bool visible);
111 void setGuidePointVisible(uint04 index, bool visible);
112 void drawDefaultGuideLines(const SnapPoint& point);
113 Model setupGuideModel();
114 void updateRecentGeometry(const SnapPoint& point);
115 virtual SelectionInfo createSelectionInfo(const MouseEvent& event, Camera* camera);
116 SnapPoint calcSnapPoint(const SelectionInfo& info, DesignObjectLookup* lookup);
117 UUID pointMaterial(const SnapPoint& point);
118 UUID lineMaterial(const SnapPoint& point);
119 protected:
120 Buffer<Vertex<3, fltp08>> m_points;
121 Vertex<3, fltp08> m_location;
122 Vertex<3, fltp08> m_lock_axis;
123 LineSegment<3, fltp08> m_lock_line;
124 Plane<3, fltp08> m_lock_plane;
125
126 SnapPoint m_original_snap;
127 UUID m_current_line_material = Constant<UUID>::NaN;
128
129 UUID m_free_point_material = Constant<UUID>::NaN;
130 UUID m_point_material = Constant<UUID>::NaN;
131 UUID m_edge_point_material = Constant<UUID>::NaN;
132 UUID m_end_point_material = Constant<UUID>::NaN;
133 UUID m_mid_point_material = Constant<UUID>::NaN;
134 UUID m_center_point_material = Constant<UUID>::NaN;
135 UUID m_on_face_point_material = Constant<UUID>::NaN;
136
137 UUID m_free_line_material = Constant<UUID>::NaN;
138 UUID m_locked_line_material = Constant<UUID>::NaN;
139 UUID m_extend_line_material = Constant<UUID>::NaN;
140 UUID m_perpendicular_line_material = Constant<UUID>::NaN;
141 UUID m_tangent_line_material = Constant<UUID>::NaN;
142 UUID m_red_line_material = Constant<UUID>::NaN;
143 UUID m_green_line_material = Constant<UUID>::NaN;
144 UUID m_blue_line_material = Constant<UUID>::NaN;
145
146 UUID m_last_selection_camera= Constant<UUID>::NaN;
147
148 UUID m_guide_model = Constant<UUID>::NaN;
149 UUID m_line_mesh = Constant<UUID>::NaN;
150 UUID m_point_mesh = Constant<UUID>::NaN;
151 Buffer<UUID> m_guide_line_model;
152 Buffer<UUID> m_guide_point_model;
153
154 Buffer<UUID> m_line_guide_text;
155 Buffer<UUID> m_point_guide_text;
156
157 Buffer<UUID> m_guide_line_material;
158 Buffer<UUID> m_guide_point_material;
159
160 Buffer<std::pair<UUID, uint04>> m_last_lines;
161 Buffer<std::pair<UUID, uint04>> m_last_meshes;
162 Buffer<std::pair<UUID, uint04>> m_last_points;
163 ConstPointer<SnapsManager> m_custom_snap_manager;
164 PointsDrawMode m_point_draw_mode;
165 std::function<void()> m_update_callback;
166 std::function<void(bool is_accepted)> m_finished_callback;
167 DesignObjectLookup* m_manager;
168 SelectionMode m_selection_mode;
169 Buffer<SnapPoint> m_last_snap_points;
170 LockMode m_lock_mode;
171 bool m_is_active;
172 bool m_show_length_label;
173 bool m_show_location_label;
174 };
175}
176
177#endif
178
#define NDEVR_DESIGN_API
Definition DLLInfo.h:77
Definition ACIColor.h:37
SelectionMode
Definition SelectionArea.hpp:43
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120