~ubuntu-branches/ubuntu/maverick/freecad/maverick

« back to all changes in this revision

Viewing changes to src/Gui/View3DInventorViewer.h

  • Committer: Bazaar Package Importer
  • Author(s): Teemu Ikonen
  • Date: 2009-07-16 18:37:41 UTC
  • Revision ID: james.westby@ubuntu.com-20090716183741-oww9kcxqrk991i1n
Tags: upstream-0.8.2237
ImportĀ upstreamĀ versionĀ 0.8.2237

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (c) 2004 Jļæ½rgen Riegel <juergen.riegel@web.de>              *
 
3
 *                                                                         *
 
4
 *   This file is part of the FreeCAD CAx development system.              *
 
5
 *                                                                         *
 
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.      *
 
10
 *                                                                         *
 
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.                  *
 
15
 *                                                                         *
 
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                                *
 
20
 *                                                                         *
 
21
 ***************************************************************************/
 
22
 
 
23
 
 
24
#ifndef GUI_VIEW3DINVENTORVIEWER_H
 
25
#define GUI_VIEW3DINVENTORVIEWER_H
 
26
 
 
27
 
 
28
#ifndef __Qt4All__
 
29
# include "Qt4All.h"
 
30
#endif
 
31
 
 
32
#include <set>
 
33
#include <stack>
 
34
 
 
35
#include <Base/Type.h>
 
36
#include <Inventor/Qt/viewers/SoQtViewer.h>
 
37
#include <Inventor/nodes/SoEventCallback.h>
 
38
#include <Inventor/Qt/SoQtCursor.h>
 
39
 
 
40
#include <Gui/Selection.h>
 
41
#include <Gui/Flag.h>
 
42
 
 
43
 
 
44
class SoSeparator;
 
45
class SoShapeHints;
 
46
class SoMaterial;
 
47
class SoRotationXYZ;
 
48
class SbSphereSheetProjector;
 
49
class SoEventCallback;
 
50
class SbBox2s;
 
51
 
 
52
namespace Gui {
 
53
 
 
54
class ViewProvider;
 
55
class SoFCBackgroundGradient;
 
56
class AbstractMouseModel;
 
57
class NavigationStyle;
 
58
 
 
59
 
 
60
/** The Inventor viewer
 
61
 *
 
62
 */
 
63
class GuiExport View3DInventorViewer : public SoQtViewer, public Gui::SelectionSingleton::ObserverType
 
64
{
 
65
    SOQT_OBJECT_ABSTRACT_HEADER(View3DInventorViewer, SoQtViewer);
 
66
 
 
67
public:
 
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  */
 
74
    };
 
75
    /// Pick modes for picking points in the scene
 
76
    enum ePickMode {
 
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. */
 
81
    };
 
82
    /** @name Modus handling of the viewer
 
83
      * Here the you can switch on/off several features
 
84
      * and modies of the Viewer
 
85
      */
 
86
    //@{
 
87
    enum ViewerMod {
 
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. */
 
94
    };
 
95
    //@}
 
96
 
 
97
    View3DInventorViewer (QWidget *parent, const char *name=NULL, SbBool embed=true, 
 
98
                          Type type= SoQtViewer::BROWSER, SbBool build=true);
 
99
    ~View3DInventorViewer();
 
100
 
 
101
    /// Observer message from the Selection
 
102
    virtual void OnChange(Gui::SelectionSingleton::SubjectType &rCaller,
 
103
                          Gui::SelectionSingleton::MessageType Reason);
 
104
 
 
105
    SoDirectionalLight* getBacklight(void) const;
 
106
    void setBacklight(SbBool on);
 
107
    SbBool isBacklight(void) const;
 
108
    void setSceneGraph (SoNode *root);
 
109
 
 
110
    void setAnimationEnabled(const SbBool enable);
 
111
    SbBool isAnimationEnabled(void) const;
 
112
 
 
113
    void startAnimating(const SbVec3f& axis, float velocity);
 
114
    void stopAnimating(void);
 
115
    SbBool isAnimating(void) const;
 
116
 
 
117
    void setFeedbackVisibility(const SbBool enable);
 
118
    SbBool isFeedbackVisible(void) const;
 
119
 
 
120
    void setFeedbackSize(const int size);
 
121
    int getFeedbackSize(void) const;
 
122
 
 
123
    virtual void setViewing(SbBool enable);
 
124
    virtual void setCursorEnabled(SbBool enable);
 
125
 
 
126
    /** @name Handling of view providers */
 
127
    //@{
 
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);
 
140
    //@}
 
141
 
 
142
    /** @name Making pictures */
 
143
    //@{
 
144
    /**
 
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.
 
151
     */
 
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;
 
156
    //@}
 
157
    /**
 
158
     * Writes the current scenegraph to an Inventor file, either in ascii or binary. 
 
159
     */
 
160
    bool dumpToFile(const char* filename, bool binary) const;
 
161
 
 
162
    /** @name Picking methods */
 
163
    //@{
 
164
    void startPicking( ePickMode = Lasso );
 
165
    void stopPicking();
 
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;
 
169
    //@}
 
170
 
 
171
    /** @name Edit methods */
 
172
    //@{
 
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; }
 
179
    //@}
 
180
 
 
181
    /** @name Pick actions */
 
182
    //@{
 
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);
 
188
    //@}
 
189
 
 
190
    /**
 
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. 
 
193
     */
 
194
    void addEventCallback(SoType eventtype, SoEventCallbackCB * cb, void* userdata = 0);
 
195
    /**
 
196
     * Unregister the given callback function \a cb.
 
197
     */
 
198
    void removeEventCallback(SoType eventtype, SoEventCallbackCB * cb, void* userdata = 0);
 
199
 
 
200
    /** @name Clipping plane, near and far plane */
 
201
    //@{
 
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.
 
205
     */
 
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;
 
223
    //@}
 
224
 
 
225
    /**
 
226
     * Set the camera's orientation. If isAnimationEnabled() returns
 
227
     * \a TRUE the reorientation is animated, otherwise its directly
 
228
     * set.
 
229
     */
 
230
    void setCameraOrientation(const SbRotation& rot);
 
231
    /** 
 
232
     * Zooms the viewport to the size of the bounding box. 
 
233
     */
 
234
    void boxZoom(const SbBox2s&);
 
235
    /**
 
236
     * Reposition the current camera so we can see the complete scene.
 
237
     */
 
238
    void viewAll();
 
239
    /**
 
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.
 
243
     */
 
244
    void viewSelection();
 
245
 
 
246
    /** @name Draw routines */
 
247
    //@{
 
248
    void drawRect (int x, int y, int w, int h);
 
249
    void drawLine (int x1, int y1, int x2, int y2);
 
250
    //@}
 
251
 
 
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);
 
260
 
 
261
protected:
 
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();
 
269
 
 
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);
 
274
 
 
275
private:
 
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);
 
279
 
 
280
private:
 
281
    std::set<ViewProvider*> _ViewProviderSet;
 
282
    ViewProvider* inEdit;
 
283
    SoFCBackgroundGradient *pcBackGround;
 
284
    SoSeparator * backgroundroot;
 
285
    SoSeparator * foregroundroot;
 
286
    SoRotationXYZ * arrowrotation;
 
287
    SoDirectionalLight* backlight;
 
288
 
 
289
    SoSeparator * pcViewProviderRoot;
 
290
    SoEventCallback* pEventCallback;
 
291
    NavigationStyle* navigation;
 
292
 
 
293
    void initialize();
 
294
    SbBool axiscrossEnabled;
 
295
    int axiscrossSize;
 
296
 
 
297
    void drawAxisCross(void);
 
298
    static void drawArrow(void);
 
299
 
 
300
    SbBool editing;
 
301
    QCursor editCursor;
 
302
    SbBool redirected;
 
303
 
 
304
    void setCursorRepresentation(int mode);
 
305
 
 
306
public:
 
307
    void addFlag(Flag*, FlagLayout::Position);
 
308
 
 
309
private:
 
310
    FlagLayout* _flaglayout;
 
311
 
 
312
    // friends
 
313
    friend class NavigationStyle;
 
314
};
 
315
 
 
316
} // namespace Gui
 
317
 
 
318
#endif  // GUI_VIEW3DINVENTORVIEWER_H
 
319