ImagingTools Core SDK
CView3dProviderComp.h
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ImtCore-Commercial
2#pragma once
3
4
5// ACF includes
6#include <ibase/ICommandsProvider.h>
7#include <iqtgui/TDesignerGuiObserverCompBase.h>
8#include <iqtgui/CHierarchicalCommand.h>
9#include <iqtgui/TRestorableGuiWrap.h>
10
11// ImtCore includes
12#include <imt3dview/IScene3dProvider.h>
13#include <imt3dview/IScene3dCamera.h>
14#include <imt3dgui/ISceneEventHandler.h>
15#include <imt3dgui/COpenGLWidget.h>
16
17
18namespace imt3dgui
19{
20
21
22class CView3dProviderCompAttrPart1:
23 public iqtgui::TRestorableGuiWrap<iqtgui::TGuiComponentBase<COpenGLWidget>>
24{
25public:
26 typedef iqtgui::TRestorableGuiWrap<iqtgui::TGuiComponentBase<COpenGLWidget>> BaseClass;
27
28 I_BEGIN_BASE_COMPONENT(CView3dProviderCompAttrPart1);
29 I_ASSIGN(m_showViewCommandsAttrPtr, "ShowViewCommands", "Show view commands", true, true);
30 I_ASSIGN(m_showEditCommandsAttrPtr, "ShowEditCommands", "Show commands for editing the 3D-objects", true, true);
31 I_ASSIGN(m_showRotationCommandsAttrPtr, "ShowRotationModeCommands", "Show rotation mode commands", true, true);
32 I_ASSIGN(m_showZoomCommandsAttrPtr, "ShowZoomCommands", "Show zoom-in/zoom-out commands", true, true);
33 I_ASSIGN(m_showSceneDecorationsCommandsAttrPtr, "ShowSceneDecorationsCommands", "Show grid/axis/ruler commands", true, true);
34 I_ASSIGN(m_showViewpointCommandsAttrPtr, "ShowViewpointCommands", "Show view point commands", true, true);
35 I_ASSIGN(m_showViewModeCommandsAttrPtr, "ShowViewModeCommands", "Show view mode commands", true, true);
36 I_ASSIGN(m_showZoomInCommandAttrPtr, "ShowShowZoomInCommand", "Enable command for zoom-in", true, false);
37 I_ASSIGN(m_showZoomOutCommandAttrPtr, "ShowShowZoomOutCommand", "Enable command for zoom-out", true, false);
38 I_ASSIGN(m_showShowGridCommandAttrPtr, "ShowShowGridCommand", "Enable command for show/hide grid", true, false);
39 I_ASSIGN(m_showShowAxisCommandAttrPtr, "ShowShowAxisCommands", "Enable command for show/hide axis", true, false);
40 I_ASSIGN(m_showShowRulerCommandAttrPtr, "ShowShowRulerCommands", "Enable command for show/hide ruler", true, false);
41 I_END_COMPONENT
42
43protected:
44 // show commands
45 I_ATTR(bool, m_showViewCommandsAttrPtr);
46 I_ATTR(bool, m_showEditCommandsAttrPtr);
47 I_ATTR(bool, m_showRotationCommandsAttrPtr);
48 I_ATTR(bool, m_showZoomCommandsAttrPtr);
49 I_ATTR(bool, m_showSceneDecorationsCommandsAttrPtr);
50 I_ATTR(bool, m_showViewpointCommandsAttrPtr);
51 I_ATTR(bool, m_showViewModeCommandsAttrPtr);
52
53 // show zoom commands
54 I_ATTR(bool, m_showZoomInCommandAttrPtr);
55 I_ATTR(bool, m_showZoomOutCommandAttrPtr);
56
57 // show scene decorations commands
58 I_ATTR(bool, m_showShowGridCommandAttrPtr);
59 I_ATTR(bool, m_showShowAxisCommandAttrPtr);
60 I_ATTR(bool, m_showShowRulerCommandAttrPtr);
61};
62
63class CView3dProviderCompAttrPart2: public CView3dProviderCompAttrPart1
64{
65public:
66 typedef CView3dProviderCompAttrPart1 BaseClass;
67
68 I_BEGIN_BASE_COMPONENT(CView3dProviderCompAttrPart2);
69 I_ASSIGN(m_showSetViewFromRightCommandAttrPtr, "ShowSetViewFromRightCommand", "Enable command for view from right", true, false);
70 I_ASSIGN(m_showSetViewFromFrontCommandAttrPtr, "ShowSetViewFromFrontCommand", "Enable command for view from front", true, false);
71 I_ASSIGN(m_showSetViewFromTopCommandAttrPtr, "ShowSetViewFromTopCommand", "Enable command for view from top", true, false);
72 I_ASSIGN(m_showSetViewFromLeftCommandAttrPtr, "ShowSetViewFromLeftCommand", "Enable command for view from left", true, false);
73 I_ASSIGN(m_showSetViewFromBottomCommandAttrPtr, "ShowSetViewFromBottomCommand", "Enable command for view from bottom", true, false);
74 I_ASSIGN(m_showSetViewFromBackCommandAttrPtr, "ShowSetViewFromBackCommand", "Enable command for view from back", true, false);
75 I_ASSIGN(m_showResetViewCommandAttrPtr, "ShowResetViewCommand", "Enable command for reset view", true, false);
76 I_ASSIGN(m_showPointSelectionCommandAttrPtr, "ShowPointSelectionCommand", "Enable command for point selection", true, false);
77 I_ASSIGN(m_showBoxSelectionCommandAttrPtr, "ShowBoxSelectionCommand", "Enable command for box selection", true, false);
78 I_ASSIGN(m_showCircleSelectionCommandAttrPtr, "ShowCircleSelectionCommand", "Enable command for circle selection", true, false);
79 I_ASSIGN(m_showClearSelectionCommandAttrPtr, "ShowClearSelectionCommand", "Enable command for clear selection", true, false);
80 I_ASSIGN(m_showAllSelectionCommandAttrPtr, "ShowAllSelectionCommand", "Enable command for all selection", true, false);
81 I_ASSIGN(m_showInvertSelectionCommandAttrPtr, "ShowInvertSelectionCommand", "Enable command for invert selection", true, false);
82 I_ASSIGN(m_showDeleteSelectionCommandAttrPtr, "ShowDeleteSelectionCommand", "Enable command for delete selection", true, false);
83 I_END_COMPONENT
84
85protected:
86 // show viewpoint commands
87 I_ATTR(bool, m_showSetViewFromRightCommandAttrPtr);
88 I_ATTR(bool, m_showSetViewFromFrontCommandAttrPtr);
89 I_ATTR(bool, m_showSetViewFromTopCommandAttrPtr);
90 I_ATTR(bool, m_showSetViewFromLeftCommandAttrPtr);
91 I_ATTR(bool, m_showSetViewFromBottomCommandAttrPtr);
92 I_ATTR(bool, m_showSetViewFromBackCommandAttrPtr);
93 I_ATTR(bool, m_showResetViewCommandAttrPtr);
94
95 // show selection commands
96 I_ATTR(bool, m_showPointSelectionCommandAttrPtr);
97 I_ATTR(bool, m_showBoxSelectionCommandAttrPtr);
98 I_ATTR(bool, m_showCircleSelectionCommandAttrPtr);
99 I_ATTR(bool, m_showClearSelectionCommandAttrPtr);
100 I_ATTR(bool, m_showAllSelectionCommandAttrPtr);
101 I_ATTR(bool, m_showInvertSelectionCommandAttrPtr);
102 I_ATTR(bool, m_showDeleteSelectionCommandAttrPtr);
103};
104
105
106class CView3dProviderCompAttrPart3: public CView3dProviderCompAttrPart2
107{
108public:
109 typedef CView3dProviderCompAttrPart2 BaseClass;
110
111 I_BEGIN_BASE_COMPONENT(CView3dProviderCompAttrPart3);
112 I_ASSIGN(m_showFreeRotationCommandAttrPtr, "ShowFreeRotationCommand", "Enable command for free rotation", true, false);
113 I_ASSIGN(m_showRotationAroundXCommandAttrPtr, "ShowRotationAroundXCommand", "Enable command for rotation around axis X", true, false);
114 I_ASSIGN(m_showRotationAroundYCommandAttrPtr, "ShowRotationAroundYCommand", "Enable command for rotation around axis Y", true, false);
115 I_ASSIGN(m_showRotationAroundZCommandAttrPtr, "ShowRotationAroundZCommand", "Enable command for rotation around axis Z", true, false);
116 I_ASSIGN(m_showViewModeCommandAttrPtr, "ShowViewModeCommand", "Show view mode command", true, false);
117 I_ASSIGN(m_showSelectionModeCommandAttrPtr, "ShowSelectionModeCommand", "Show selection mode command", true, false);
118 I_ASSIGN(m_defaultsUseAntialiasingAttrPtr, "UseAntialiasing", "Use rendering antialiasing", true, true);
119 I_ASSIGN(m_defaultsUseCullfaceAttrPtr, "UseCullFace", "Use cull face mode", true, true);
120 I_ASSIGN(m_defaultsUseBlendAttrPtr, "UseBlend", "Use blending mode", true, true);
121 I_END_COMPONENT
122
123protected:
124 // show rotation commands
125 I_ATTR(bool, m_showFreeRotationCommandAttrPtr);
126 I_ATTR(bool, m_showRotationAroundXCommandAttrPtr);
127 I_ATTR(bool, m_showRotationAroundYCommandAttrPtr);
128 I_ATTR(bool, m_showRotationAroundZCommandAttrPtr);
129
130 // show view mode commands
131 I_ATTR(bool, m_showViewModeCommandAttrPtr);
132 I_ATTR(bool, m_showSelectionModeCommandAttrPtr);
133
134 // defaults
135 I_ATTR(bool, m_defaultsUseAntialiasingAttrPtr);
136 I_ATTR(bool, m_defaultsUseCullfaceAttrPtr);
137 I_ATTR(bool, m_defaultsUseBlendAttrPtr);
138};
139
140
141class CView3dProviderComp:
142 public CView3dProviderCompAttrPart3,
143 virtual public ibase::ICommandsProvider,
144 virtual public imt3dview::IScene3dProvider,
145 virtual public ISceneEventHandler
146{
147 Q_OBJECT
148
149public:
150 typedef CView3dProviderCompAttrPart3 BaseClass;
151
152 enum CommandGroups
153 {
154 CG_ZOOM = 0xeaff,
155 CG_CAMERA_MODE,
156 CG_SHOW_SCENE_ITEMS,
157 CG_SCENE_FLAGS,
158 CG_SELECTION,
159 CG_SELECTION_ACTIONS,
160 CG_ROTATION,
161 CG_VIEW_MODE,
162 CG_PROJECTION_MODE,
163 CG_OTHER
164 };
165
166 I_BEGIN_COMPONENT(CView3dProviderComp);
167 I_REGISTER_INTERFACE(ibase::ICommandsProvider);
168 I_REGISTER_INTERFACE(imt3dview::IScene3dProvider);
169 I_REGISTER_SUBELEMENT(Scene);
170 I_REGISTER_SUBELEMENT_INTERFACE(Scene, imt3dview::IScene3d, ExtractScene);
171 I_ASSIGN(m_cameraCompPtr, "Camera", "Camera", true, "Camera");
172 I_END_COMPONENT
173
174 CView3dProviderComp();
175
176 // reimplemented (imt3dgui::ISceneEventHandler)
177 virtual void OnShowGrid(bool show) override;
178 virtual void OnShowAxis(bool show) override;
179 virtual void OnShowRuler(bool show) override;
180 virtual void OnPointSelection(const QPoint& point, bool clearPreviousSelection) override;
181 virtual void OnBoxSelection(const QRect& rect, bool clearPreviousSelection) override;
182 virtual void OnCircleSelection(const QRect& rect, bool clearPreviousSelection) override;
183 virtual void OnClearSelection() override;
184 virtual void OnAllSelection() override;
185 virtual void OnInvertSelection() override;
186 virtual void OnDeleteSelection() override;
187 virtual bool OnMousePress(QMouseEvent& e) override;
188 virtual bool OnMouseMove(QMouseEvent& e) override;
189 virtual bool OnMouseRelease(QMouseEvent& e) override;
190
191 // reimplemented (imt3dview::IScene3dProvider)
192 virtual imt3dview::IScene3d* GetScene() const override;
193
194 // reimplemented (ibase::ICommandsProvider)
195 virtual const ibase::IHierarchicalCommand* GetCommands() const override;
196
197protected:
198 // reimplemented (iqtgui::TRestorableGuiWrap)
199 virtual void OnRestoreSettings(const QSettings& settings) override;
200 virtual void OnSaveSettings(QSettings& settings) const override;
201
202 // reimplemented (iqtgui::CGuiComponentBase)
203 virtual void OnGuiCreated() override;
204 virtual void OnGuiRetranslate() override;
205 virtual void OnGuiDesignChanged() override;
206
207protected:
208 iqtgui::CHierarchicalCommand& GetShowGridCommand();
209 iqtgui::CHierarchicalCommand& GetShowAxisCommand();
210
211protected Q_SLOTS:
212 void OnZoomIn();
213 void OnZoomOut();
214 void OnShowGridCommand(bool checked);
215 void OnShowAxisCommand(bool checked);
216 void OnShowRulerCommand(bool checked);
217 void OnViewReset();
218 void OnViewFromRight();
219 void OnViewFromFront();
220 void OnViewFromTop();
221 void OnViewFromLeft();
222 void OnViewFromBottom();
223 void OnViewFromBack();
224 void OnUseAntialiasingCommand(bool checked);
225 void OnUseCullFaceCommand(bool checked);
226 void OnPointSelectionCommand(bool checked);
227 void OnBoxSelectionCommand(bool checked);
228 void OnCircleSelectionCommand(bool checked);
229 void OnClearSelectionCommand();
230 void OnAllSelectionCommand();
231 void OnInvertSelectionCommand();
232 void OnDeleteSelectionCommand();
233 void OnFreeRotationCommand();
234 void OnRotationAroundXCommand();
235 void OnRotationAroundYCommand();
236 void OnRotationAroundZCommand();
237 void OnViewModeCommand();
238 void OnSelectionModeCommand();
239 void OnPerspectiveModeCommand();
240 void OnOrthoModeCommand();
241
242private:
243 // static template methods for subelement access
244 template <class InterfaceType>
245 static InterfaceType* ExtractScene(CView3dProviderComp& component)
246 {
247 COpenGLWidget* widgetPtr = dynamic_cast<COpenGLWidget*>(component.GetWidget());
248 if (widgetPtr != NULL){
249 return widgetPtr->GetScene();
250 }
251
252 return NULL;
253 }
254
255 void EnableCommands(COpenGLWidget::ViewMode viewMode);
256 void UpdateCommands();
257
258private:
259 // commands
260 iqtgui::CHierarchicalCommand m_rootCommands;
261 iqtgui::CHierarchicalCommand m_viewCommands;
262 iqtgui::CHierarchicalCommand m_editCommands;
263 iqtgui::CHierarchicalCommand m_rotationCommands;
264
265 // zoom commands
266 iqtgui::CHierarchicalCommand m_zoomInCommand;
267 iqtgui::CHierarchicalCommand m_zoomOutCommand;
268
269 // show/hide scene decorations
270 iqtgui::CHierarchicalCommand m_showGridCommand;
271 iqtgui::CHierarchicalCommand m_showAxisCommand;
272 iqtgui::CHierarchicalCommand m_showRulerCommand;
273
274 // viewpoint commands
275 iqtgui::CHierarchicalCommand m_setViewFromRightCommand;
276 iqtgui::CHierarchicalCommand m_setViewFromFrontCommand;
277 iqtgui::CHierarchicalCommand m_setViewFromTopCommand;
278 iqtgui::CHierarchicalCommand m_setViewFromLeftCommand;
279 iqtgui::CHierarchicalCommand m_setViewFromBottomCommand;
280 iqtgui::CHierarchicalCommand m_setViewFromBackCommand;
281 iqtgui::CHierarchicalCommand m_resetViewCommand;
282
283 // rendering commands
284 iqtgui::CHierarchicalCommand m_useAntialiasingCommand;
285 iqtgui::CHierarchicalCommand m_useCullFaceCommand;
286
287 // selection commands
288 iqtgui::CHierarchicalCommand m_pointSelectionCommand;
289 iqtgui::CHierarchicalCommand m_boxSelectionCommand;
290 iqtgui::CHierarchicalCommand m_circleSelectionCommand;
291 iqtgui::CHierarchicalCommand m_clearSelectionCommand;
292 iqtgui::CHierarchicalCommand m_allSelectionCommand;
293 iqtgui::CHierarchicalCommand m_invertSelectionCommand;
294 iqtgui::CHierarchicalCommand m_deleteSelectionCommand;
295
296 // rotation commands
297 iqtgui::CHierarchicalCommand m_freeRotationCommand;
298 iqtgui::CHierarchicalCommand m_rotationAroundXCommand;
299 iqtgui::CHierarchicalCommand m_rotationAroundYCommand;
300 iqtgui::CHierarchicalCommand m_rotationAroundZCommand;
301
302 // view mode commands
303 iqtgui::CHierarchicalCommand m_viewModeCommand;
304 iqtgui::CHierarchicalCommand m_selectionModeCommand;
305
306 // projection mode commands
307 iqtgui::CHierarchicalCommand m_perspectiveModeCommand;
308 iqtgui::CHierarchicalCommand m_orthoModeCommand;
309
310protected:
311 I_REF(imt3dview::IScene3dCamera, m_cameraCompPtr);
312};
313
314
315} // namespace imt3dgui
316
317