-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
View3DInventorViewer.h
370 lines (322 loc) · 14 KB
/
View3DInventorViewer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
/***************************************************************************
* Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef GUI_VIEW3DINVENTORVIEWER_H
#define GUI_VIEW3DINVENTORVIEWER_H
#include <list>
#include <map>
#include <set>
#include <vector>
#include <Base/Type.h>
#include <Inventor/Qt/viewers/SoQtViewer.h>
#include <Inventor/nodes/SoEventCallback.h>
#include <Inventor/Qt/SoQtCursor.h>
#include <QCursor>
#include <Gui/Selection.h>
class SoSeparator;
class SoShapeHints;
class SoMaterial;
class SoRotationXYZ;
class SbSphereSheetProjector;
class SoEventCallback;
class SbBox2s;
class SoVectorizeAction;
class QGLFramebufferObject;
class QImage;
class SoGroup;
namespace Gui {
class ViewProvider;
class SoFCBackgroundGradient;
class NavigationStyle;
class SoFCUnifiedSelection;
class Document;
class SoFCUnifiedSelection;
class GLGraphicsItem;
class SoShapeScale;
/** The Inventor viewer
*
*/
class GuiExport View3DInventorViewer : public SoQtViewer, public Gui::SelectionSingleton::ObserverType
{
SOQT_OBJECT_ABSTRACT_HEADER(View3DInventorViewer, SoQtViewer);
public:
/// Background modes for the savePicture() method
enum eBackgroundType {
Current = 0, /**< Use the current viewer Background */
Black = 1, /**< Black background */
White = 2, /**< White background */
Transparent = 3, /**< Transparent background */
};
/// Pick modes for picking points in the scene
enum SelectionMode {
Lasso = 0, /**< Select objects using a lasso. */
Rectangle = 1, /**< Select objects using a rectangle. */
Rubberband = 2, /**< Select objects using a rubberband. */
BoxZoom = 3, /**< Perform a box zoom. */
Clip = 4, /**< Clip objects using a lasso. */
};
/** @name Modus handling of the viewer
* Here the you can switch on/off several features
* and modies of the Viewer
*/
//@{
enum ViewerMod {
ShowCoord=1, /**< Enables the Coordinate system in the corner. */
ShowFPS =2, /**< Enables the Frams per Second counter. */
SimpleBackground=4,/**< switch to a simple background. */
DisallowRotation=8,/**< switch of the rotation. */
DisallowPanning=16,/**< switch of the panning. */
DisallowZooming=32,/**< switch of the zooming. */
};
//@}
View3DInventorViewer (QWidget *parent, const char *name=NULL, SbBool embed=true,
Type type= SoQtViewer::BROWSER, SbBool build=true);
virtual ~View3DInventorViewer();
/// Observer message from the Selection
virtual void OnChange(Gui::SelectionSingleton::SubjectType &rCaller,
Gui::SelectionSingleton::MessageType Reason);
SoDirectionalLight* getBacklight(void) const;
void setBacklight(SbBool on);
SbBool isBacklight(void) const;
void setSceneGraph (SoNode *root);
void setAnimationEnabled(const SbBool enable);
SbBool isAnimationEnabled(void) const;
void setPopupMenuEnabled(const SbBool on);
SbBool isPopupMenuEnabled(void) const;
void startAnimating(const SbVec3f& axis, float velocity);
void stopAnimating(void);
SbBool isAnimating(void) const;
void setFeedbackVisibility(const SbBool enable);
SbBool isFeedbackVisible(void) const;
void setFeedbackSize(const int size);
int getFeedbackSize(void) const;
void setRenderFramebuffer(const SbBool enable);
SbBool isRenderFramebuffer() const;
void renderToFramebuffer(QGLFramebufferObject*);
virtual void setViewing(SbBool enable);
virtual void setCursorEnabled(SbBool enable);
void addGraphicsItem(GLGraphicsItem*);
void removeGraphicsItem(GLGraphicsItem*);
std::list<GLGraphicsItem*> getGraphicsItems() const;
std::list<GLGraphicsItem*> getGraphicsItemsOfType(const Base::Type&) const;
void clearGraphicsItems();
/** @name Handling of view providers */
//@{
SbBool hasViewProvider(ViewProvider*) const;
/// adds an ViewProvider to the view, e.g. from a feature
void addViewProvider(ViewProvider*);
/// remove a ViewProvider
void removeViewProvider(ViewProvider*);
/// get view provider by path
ViewProvider* getViewProviderByPath(SoPath*) const;
ViewProvider* getViewProviderByPathFromTail(SoPath*) const;
/// get all view providers of given type
std::vector<ViewProvider*> getViewProvidersOfType(const Base::Type& typeId) const;
/// set the ViewProvider in special edit mode
SbBool setEditingViewProvider(Gui::ViewProvider* p, int ModNum=0);
/// return whether a view provider is edited
SbBool isEditingViewProvider() const;
/// reset from edit mode
void resetEditingViewProvider();
//@}
/** @name Making pictures */
//@{
/**
* Creates an image with width \a w and height \a h of the current scene graph
* and exports the rendered scenegraph to an image.
*/
void savePicture(int w, int h, int eBackgroundType, QImage&) const;
void saveGraphic(int pagesize, int eBackgroundType, SoVectorizeAction* va) const;
//@}
/**
* Writes the current scenegraph to an Inventor file, either in ascii or binary.
*/
bool dumpToFile(const char* filename, bool binary) const;
/** @name Selection methods */
//@{
void startSelection(SelectionMode = Lasso);
void stopSelection();
bool isSelecting() const;
std::vector<SbVec2f> getGLPolygon(SbBool* clip_inner=0) const;
std::vector<SbVec2f> getGLPolygon(const std::vector<SbVec2s>&) const;
const std::vector<SbVec2s>& getPolygon(SbBool* clip_inner=0) const;
//@}
/** @name Edit methods */
//@{
void setEditing(SbBool edit);
SbBool isEditing() const { return this->editing; }
void setEditingCursor (const SoQtCursor& cursor);
void setEditingCursor (const QCursor& cursor);
void setRedirectToSceneGraph(SbBool redirect) { this->redirected = redirect; }
SbBool isRedirectedToSceneGraph() const { return this->redirected; }
void setRedirectToSceneGraphEnabled(SbBool enable) { this->allowredir = enable; }
SbBool isRedirectToSceneGraphEnabled(void) const { return this->allowredir; }
//@}
/** @name Pick actions */
//@{
// calls a PickAction on the scene graph
bool pickPoint(const SbVec2s& pos,SbVec3f &point,SbVec3f &norm) const;
SoPickedPoint* pickPoint(const SbVec2s& pos) const;
const SoPickedPoint* getPickedPoint(SoEventCallback * n) const;
SbBool pubSeekToPoint(const SbVec2s& pos);
void pubSeekToPoint(const SbVec3f& pos);
//@}
/**
* Set up a callback function \a cb which will be invoked for the given eventtype.
* \a userdata will be given as the first argument to the callback function.
*/
void addEventCallback(SoType eventtype, SoEventCallbackCB * cb, void* userdata = 0);
/**
* Unregister the given callback function \a cb.
*/
void removeEventCallback(SoType eventtype, SoEventCallbackCB * cb, void* userdata = 0);
/** @name Clipping plane, near and far plane */
//@{
/** Returns the view direction from the user's eye point in direction to the
* viewport which is actually the negative normal of the near plane.
* The vector is normalized to length of 1.
*/
SbVec3f getViewDirection() const;
/** Returns the up direction */
SbVec3f getUpDirection() const;
/** Returns the 3d point on the focal plane to the given 2d point. */
SbVec3f getPointOnScreen(const SbVec2s&) const;
/** Returns the near plane represented by its normal and base point. */
void getNearPlane(SbVec3f& rcPt, SbVec3f& rcNormal) const;
/** Returns the far plane represented by its normal and base point. */
void getFarPlane(SbVec3f& rcPt, SbVec3f& rcNormal) const;
/** Adds or remove a manipulator to/from the scenegraph. */
void toggleClippingPlane();
/** Checks whether a clipping plane is set or not. */
bool hasClippingPlane() const;
/** Project the given normalized 2d point onto the near plane */
SbVec3f projectOnNearPlane(const SbVec2f&) const;
/** Project the given normalized 2d point onto the far plane */
SbVec3f projectOnFarPlane(const SbVec2f&) const;
//@}
/** @name Dimension controls
* the "turn*" functions are wired up to parameter groups through view3dinventor.
* don't call them directly. instead set the parameter groups.
* @see TaskDimension
*/
//@{
void turnAllDimensionsOn();
void turnAllDimensionsOff();
void turn3dDimensionsOn();
void turn3dDimensionsOff();
void turnDeltaDimensionsOn();
void turnDeltaDimensionsOff();
void eraseAllDimensions();
void addDimension3d(SoNode *node);
void addDimensionDelta(SoNode *node);
//@}
/**
* Set the camera's orientation. If isAnimationEnabled() returns
* \a TRUE the reorientation is animated, otherwise its directly
* set.
*/
void setCameraOrientation(const SbRotation& rot, SbBool moveTocenter=false);
void setCameraType(SoType t);
void moveCameraTo(const SbRotation& rot, const SbVec3f& pos, int steps, int ms);
/**
* Zooms the viewport to the size of the bounding box.
*/
void boxZoom(const SbBox2s&);
/**
* Reposition the current camera so we can see the complete scene.
*/
void viewAll();
void viewAll(float factor);
/**
* Reposition the current camera so we can see all selected objects
* of the scene. Therefore we search for all SOFCSelection nodes, if
* none of them is selected nothing happens.
*/
void viewSelection();
void setGradientBackground(bool b);
bool hasGradientBackground() const;
void setGradientBackgroundColor(const SbColor& fromColor,
const SbColor& toColor);
void setGradientBackgroundColor(const SbColor& fromColor,
const SbColor& toColor,
const SbColor& midColor);
void setEnabledFPSCounter(bool b);
void setNavigationType(Base::Type);
void setAxisCross(bool b);
bool hasAxisCross(void);
NavigationStyle* navigationStyle() const;
void setDocument(Gui::Document *pcDocument);
protected:
void renderScene();
void renderFramebuffer();
virtual void actualRedraw(void);
virtual void setSeekMode(SbBool enable);
virtual void afterRealizeHook(void);
virtual void processEvent(QEvent * event);
virtual SbBool processSoEvent(const SoEvent * const ev);
SbBool processSoEventBase(const SoEvent * const ev);
void printDimension();
void selectAll();
static void clearBuffer(void * userdata, SoAction * action);
static void setGLWidget(void * userdata, SoAction * action);
static void handleEventCB(void * userdata, SoEventCallback * n);
static void interactionStartCB(void * data, SoQtViewer * viewer);
static void interactionFinishCB(void * data, SoQtViewer * viewer);
static void interactionLoggerCB(void * ud, SoAction* action);
private:
static void selectCB(void * closure, SoPath * p);
static void deselectCB(void * closure, SoPath * p);
static SoPath * pickFilterCB(void * data, const SoPickedPoint * pick);
void initialize();
void drawAxisCross(void);
static void drawArrow(void);
void setCursorRepresentation(int mode);
private:
std::set<ViewProvider*> _ViewProviderSet;
std::map<SoSeparator*,ViewProvider*> _ViewProviderMap;
std::list<GLGraphicsItem*> graphicsItems;
ViewProvider* editViewProvider;
SoFCBackgroundGradient *pcBackGround;
SoSeparator * backgroundroot;
SoSeparator * foregroundroot;
SoDirectionalLight* backlight;
SoSeparator * pcViewProviderRoot;
SoEventCallback* pEventCallback;
NavigationStyle* navigation;
SoFCUnifiedSelection* selectionRoot;
QGLFramebufferObject* framebuffer;
SoSwitch *dimensionRoot;
// small axis cross in the corner
SbBool axiscrossEnabled;
int axiscrossSize;
// big one in the middle
SoShapeScale* axisCross;
SoGroup* axisGroup;
SbBool editing;
QCursor editCursor;
SbBool redirected;
SbBool allowredir;
// friends
friend class NavigationStyle;
friend class GLPainter;
};
} // namespace Gui
#endif // GUI_VIEW3DINVENTORVIEWER_H