1
/***************************************************************************
2
* Copyright (c) 2004 Jļæ½rgen Riegel <juergen.riegel@web.de> *
4
* This file is part of the FreeCAD CAx development system. *
6
* This library is free software; you can redistribute it and/or *
7
* modify it under the terms of the GNU Library General Public *
8
* License as published by the Free Software Foundation; either *
9
* version 2 of the License, or (at your option) any later version. *
11
* This library 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 Library General Public License for more details. *
16
* You should have received a copy of the GNU Library General Public *
17
* License along with this library; see the file COPYING.LIB. If not, *
18
* write to the Free Software Foundation, Inc., 59 Temple Place, *
19
* Suite 330, Boston, MA 02111-1307, USA *
21
***************************************************************************/
24
#ifndef GUI_VIEW3DINVENTORVIEWER_H
25
#define GUI_VIEW3DINVENTORVIEWER_H
35
#include <Base/Type.h>
36
#include <Inventor/Qt/viewers/SoQtViewer.h>
37
#include <Inventor/nodes/SoEventCallback.h>
38
#include <Inventor/Qt/SoQtCursor.h>
40
#include <Gui/Selection.h>
48
class SbSphereSheetProjector;
49
class SoEventCallback;
55
class SoFCBackgroundGradient;
56
class AbstractMouseModel;
57
class NavigationStyle;
60
/** The Inventor viewer
63
class GuiExport View3DInventorViewer : public SoQtViewer, public Gui::SelectionSingleton::ObserverType
65
SOQT_OBJECT_ABSTRACT_HEADER(View3DInventorViewer, SoQtViewer);
68
/// Background modes for the savePicture() method
69
enum eBackgroundType {
70
Current = 0, /**< Use the current viewer Background */
71
Black = 1, /**< Black background */
72
White = 2, /**< White background */
73
Transparent = 3, /**< Transparent background */
75
/// Pick modes for picking points in the scene
77
Lasso = 0, /**< Select objects using a lasso. */
78
Rectangle = 1, /**< Select objects using a rectangle. */
79
BoxZoom = 2, /**< Perform a box zoom. */
80
Clip = 3, /**< Clip objects using a lasso. */
82
/** @name Modus handling of the viewer
83
* Here the you can switch on/off several features
84
* and modies of the Viewer
88
ShowCoord=1, /**< Enables the Coordinate system in the corner. */
89
ShowFPS =2, /**< Enables the Frams per Second counter. */
90
SimpleBackground=4,/**< switch to a simple background. */
91
DisallowRotation=8,/**< switch of the rotation. */
92
DisallowPanning=16,/**< switch of the panning. */
93
DisallowZooming=32,/**< switch of the zooming. */
97
View3DInventorViewer (QWidget *parent, const char *name=NULL, SbBool embed=true,
98
Type type= SoQtViewer::BROWSER, SbBool build=true);
99
~View3DInventorViewer();
101
/// Observer message from the Selection
102
virtual void OnChange(Gui::SelectionSingleton::SubjectType &rCaller,
103
Gui::SelectionSingleton::MessageType Reason);
105
SoDirectionalLight* getBacklight(void) const;
106
void setBacklight(SbBool on);
107
SbBool isBacklight(void) const;
108
void setSceneGraph (SoNode *root);
110
void setAnimationEnabled(const SbBool enable);
111
SbBool isAnimationEnabled(void) const;
113
void startAnimating(const SbVec3f& axis, float velocity);
114
void stopAnimating(void);
115
SbBool isAnimating(void) const;
117
void setFeedbackVisibility(const SbBool enable);
118
SbBool isFeedbackVisible(void) const;
120
void setFeedbackSize(const int size);
121
int getFeedbackSize(void) const;
123
virtual void setViewing(SbBool enable);
124
virtual void setCursorEnabled(SbBool enable);
126
/** @name Handling of view providers */
128
/// adds an ViewProvider to the view, e.g. from a feature
129
void addViewProvider(ViewProvider*);
130
/// remove a ViewProvider
131
void removeViewProvider(ViewProvider*);
132
/// get view provider by path
133
ViewProvider* getViewProviderByPath(SoPath*) const;
134
/// get all view providers of given type
135
std::vector<ViewProvider*> getViewProvidersOfType(const Base::Type& typeId) const;
136
/// set the ViewProvider in special edit mode
137
bool setEdit(Gui::ViewProvider* p, int ModNum=0);
138
/// reset from edit mode
139
void resetEdit(void);
142
/** @name Making pictures */
145
* Creates an image with width \a w and height \a h of the current scene graph
146
* and exports the rendered scenegraph directly to file \a filename.
147
* If \a comment is set to '$MIBA' information regarding the MIBA standard is
148
* embedded to the picture, otherwise the \a comment is embedded as is.
149
* The appropriate file format must support embedding meta information which
150
* is provided by JPEG or PNG.
152
void savePicture(const char* filename, int w, int h, int eBackgroundType,
153
const char* comment) const;
154
void savePicture(int w, int h, int eBackgroundType, QImage&) const;
155
void saveGraphic(const char* filename, int pagesize, int eBackgroundType) const;
158
* Writes the current scenegraph to an Inventor file, either in ascii or binary.
160
bool dumpToFile(const char* filename, bool binary) const;
162
/** @name Picking methods */
164
void startPicking( ePickMode = Lasso );
166
bool isPicking() const;
167
const std::vector<SbVec2f>& getPickedPolygon(SbBool* clip_inner=0) const;
168
std::vector<int> tessellate(const std::vector<SbVec2f>&) const;
171
/** @name Edit methods */
173
void setEditing(SbBool edit);
174
SbBool isEditing() const { return this->editing; }
175
void setEditingCursor (const SoQtCursor& cursor);
176
void setEditingCursor (const QCursor& cursor);
177
void setRedirectToSceneGraph(SbBool redirect) { this->redirected = redirect; }
178
SbBool isRedirectedToSceneGraph() const { return this->redirected; }
181
/** @name Pick actions */
183
// calls a PickAction on the scene graph
184
bool pickPoint(const SbVec2s& pos,SbVec3f &point,SbVec3f &norm) const;
185
SoPickedPoint* pickPoint(const SbVec2s& pos) const;
186
SbBool pubSeekToPoint(const SbVec2s& pos);
187
void pubSeekToPoint(const SbVec3f& pos);
191
* Set up a callback function \a cb which will be invoked for the given eventtype.
192
* \a userdata will be given as the first argument to the callback function.
194
void addEventCallback(SoType eventtype, SoEventCallbackCB * cb, void* userdata = 0);
196
* Unregister the given callback function \a cb.
198
void removeEventCallback(SoType eventtype, SoEventCallbackCB * cb, void* userdata = 0);
200
/** @name Clipping plane, near and far plane */
202
/** Returns the view direction from the user's eye point in direction to the
203
* viewport which is actually the negative normal of the near plane.
204
* The vector is normalized to length of 1.
206
SbVec3f getViewDirection() const;
207
/** Returns the up direction */
208
SbVec3f getUpDirection() const;
209
/** Returns the 3d point on the focal plane to the given 2d point. */
210
SbVec3f getPointOnScreen(const SbVec2s&) const;
211
/** Returns the near plane represented by its normal and base point. */
212
void getNearPlane(SbVec3f& rcPt, SbVec3f& rcNormal) const;
213
/** Returns the far plane represented by its normal and base point. */
214
void getFarPlane(SbVec3f& rcPt, SbVec3f& rcNormal) const;
215
/** Adds or remove a manipulator to/from the scenegraph. */
216
void toggleClippingPlane();
217
/** Checks whether a clipping plane is set or not. */
218
bool hasClippingPlane() const;
219
/** Project the given normalized 2d point onto the near plane */
220
SbVec3f projectOnNearPlane(const SbVec2f&) const;
221
/** Project the given normalized 2d point onto the far plane */
222
SbVec3f projectOnFarPlane(const SbVec2f&) const;
226
* Set the camera's orientation. If isAnimationEnabled() returns
227
* \a TRUE the reorientation is animated, otherwise its directly
230
void setCameraOrientation(const SbRotation& rot);
232
* Zooms the viewport to the size of the bounding box.
234
void boxZoom(const SbBox2s&);
236
* Reposition the current camera so we can see the complete scene.
240
* Reposition the current camera so we can see all selected objects
241
* of the scene. Therefore we search for all SOFCSelection nodes, if
242
* none of them is selected nothing happens.
244
void viewSelection();
246
/** @name Draw routines */
248
void drawRect (int x, int y, int w, int h);
249
void drawLine (int x1, int y1, int x2, int y2);
252
void setGradientBackgroud(bool b);
253
void setGradientBackgroudColor(const SbColor& fromColor,
254
const SbColor& toColor);
255
void setGradientBackgroudColor(const SbColor& fromColor,
256
const SbColor& toColor,
257
const SbColor& midColor);
258
void setEnabledFPSCounter(bool b);
259
void setNavigationType(Base::Type);
262
virtual void actualRedraw(void);
263
virtual void setSeekMode(SbBool enable);
264
virtual void afterRealizeHook(void);
265
virtual void processEvent(QEvent * event);
266
SbBool processSoEventBase(const SoEvent * const ev);
267
virtual SbBool processSoEvent(const SoEvent * const ev);
268
void printDimension();
270
static void clearBuffer(void * userdata, SoAction * action);
271
static void interactionStartCB(void * data, SoQtViewer * viewer);
272
static void interactionFinishCB(void * data, SoQtViewer * viewer);
273
static void interactionLoggerCB(void * ud, SoAction* action);
276
static void selectCB(void * closure, SoPath * p);
277
static void deselectCB(void * closure, SoPath * p);
278
static void tessCB(void * v0, void * v1, void * v2, void * cbdata);
281
std::set<ViewProvider*> _ViewProviderSet;
282
ViewProvider* inEdit;
283
SoFCBackgroundGradient *pcBackGround;
284
SoSeparator * backgroundroot;
285
SoSeparator * foregroundroot;
286
SoRotationXYZ * arrowrotation;
287
SoDirectionalLight* backlight;
289
SoSeparator * pcViewProviderRoot;
290
SoEventCallback* pEventCallback;
291
NavigationStyle* navigation;
294
SbBool axiscrossEnabled;
297
void drawAxisCross(void);
298
static void drawArrow(void);
304
void setCursorRepresentation(int mode);
307
void addFlag(Flag*, FlagLayout::Position);
310
FlagLayout* _flaglayout;
313
friend class NavigationStyle;
318
#endif // GUI_VIEW3DINVENTORVIEWER_H