View3DInventorViewer.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de>              *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #ifndef GUI_VIEW3DINVENTORVIEWER_H
00025 #define GUI_VIEW3DINVENTORVIEWER_H
00026 
00027 #include <set>
00028 #include <stack>
00029 
00030 #include <Base/Type.h>
00031 #include <Inventor/Qt/viewers/SoQtViewer.h>
00032 #include <Inventor/nodes/SoEventCallback.h>
00033 #include <Inventor/Qt/SoQtCursor.h>
00034 
00035 #include <Gui/Selection.h>
00036 #include <Gui/Flag.h>
00037 #include <QPointer>
00038 
00039 
00040 class SoSeparator;
00041 class SoShapeHints;
00042 class SoMaterial;
00043 class SoRotationXYZ;
00044 class SbSphereSheetProjector;
00045 class SoEventCallback;
00046 class SbBox2s;
00047 class SoVectorizeAction;
00048 
00049 namespace Gui {
00050 
00051 class ViewProvider;
00052 class SoFCBackgroundGradient;
00053 class NavigationStyle;
00054 class SoFCUnifiedSelection;
00055 
00059 class GuiExport View3DInventorViewer : public SoQtViewer, public Gui::SelectionSingleton::ObserverType
00060 {
00061     SOQT_OBJECT_ABSTRACT_HEADER(View3DInventorViewer, SoQtViewer);
00062 
00063 public:
00065     enum eBackgroundType { 
00066         Current     = 0,  
00067         Black       = 1,  
00068         White       = 2,  
00069         Transparent = 3,  
00070     };
00072     enum SelectionMode {
00073         Lasso       = 0,  
00074         Rectangle   = 1,  
00075         BoxZoom     = 2,  
00076         Clip        = 3,  
00077     };
00083     enum ViewerMod {
00084         ShowCoord=1,       
00085         ShowFPS  =2,       
00086         SimpleBackground=4,
00087         DisallowRotation=8,
00088         DisallowPanning=16,
00089         DisallowZooming=32,
00090     };
00092 
00093     View3DInventorViewer (QWidget *parent, const char *name=NULL, SbBool embed=true, 
00094                           Type type= SoQtViewer::BROWSER, SbBool build=true);
00095     virtual ~View3DInventorViewer();
00096 
00098     virtual void OnChange(Gui::SelectionSingleton::SubjectType &rCaller,
00099                           Gui::SelectionSingleton::MessageType Reason);
00100 
00101     SoDirectionalLight* getBacklight(void) const;
00102     void setBacklight(SbBool on);
00103     SbBool isBacklight(void) const;
00104     void setSceneGraph (SoNode *root);
00105 
00106     void setAnimationEnabled(const SbBool enable);
00107     SbBool isAnimationEnabled(void) const;
00108 
00109     void startAnimating(const SbVec3f& axis, float velocity);
00110     void stopAnimating(void);
00111     SbBool isAnimating(void) const;
00112 
00113     void setFeedbackVisibility(const SbBool enable);
00114     SbBool isFeedbackVisible(void) const;
00115 
00116     void setFeedbackSize(const int size);
00117     int getFeedbackSize(void) const;
00118 
00119     virtual void setViewing(SbBool enable);
00120     virtual void setCursorEnabled(SbBool enable);
00121 
00124     SbBool hasViewProvider(ViewProvider*) const;
00126     void addViewProvider(ViewProvider*);
00128     void removeViewProvider(ViewProvider*);
00130     ViewProvider* getViewProviderByPath(SoPath*) const;
00131     ViewProvider* getViewProviderByPathFromTail(SoPath*) const;
00133     std::vector<ViewProvider*> getViewProvidersOfType(const Base::Type& typeId) const;
00135     SbBool setEditingViewProvider(Gui::ViewProvider* p, int ModNum=0);
00137     SbBool isEditingViewProvider() const;
00139     void resetEditingViewProvider();
00141 
00152     void savePicture(const char* filename, int w, int h, int eBackgroundType,
00153                      const char* comment) const;
00154     void savePicture(int w, int h, int eBackgroundType, QImage&) const;
00155     void saveGraphic(int pagesize, int eBackgroundType, SoVectorizeAction* va) const;
00157 
00160     bool dumpToFile(const char* filename, bool binary) const;
00161 
00164     void startSelection(SelectionMode = Lasso);
00165     void stopSelection();
00166     bool isSelecting() const;
00167     std::vector<SbVec2f> getGLPolygon(SbBool* clip_inner=0) const;
00168     std::vector<SbVec2f> getGLPolygon(const std::vector<SbVec2s>&) const;
00169     const std::vector<SbVec2s>& getPolygon(SbBool* clip_inner=0) const;
00171 
00174     void setEditing(SbBool edit);
00175     SbBool isEditing() const { return this->editing; }
00176     void setEditingCursor (const SoQtCursor& cursor);
00177     void setEditingCursor (const QCursor& cursor);
00178     void setRedirectToSceneGraph(SbBool redirect) { this->redirected = redirect; }
00179     SbBool isRedirectedToSceneGraph() const { return this->redirected; }
00181 
00184     // calls a PickAction on the scene graph
00185     bool pickPoint(const SbVec2s& pos,SbVec3f &point,SbVec3f &norm) const;
00186     SoPickedPoint* pickPoint(const SbVec2s& pos) const;
00187     SbBool pubSeekToPoint(const SbVec2s& pos);
00188     void pubSeekToPoint(const SbVec3f& pos);
00190 
00195     void addEventCallback(SoType eventtype, SoEventCallbackCB * cb, void* userdata = 0);
00199     void removeEventCallback(SoType eventtype, SoEventCallbackCB * cb, void* userdata = 0);
00200 
00207     SbVec3f getViewDirection() const;
00209     SbVec3f getUpDirection() const;
00211     SbVec3f getPointOnScreen(const SbVec2s&) const;
00213     void getNearPlane(SbVec3f& rcPt, SbVec3f& rcNormal) const;
00215     void getFarPlane(SbVec3f& rcPt, SbVec3f& rcNormal) const;
00217     void toggleClippingPlane();
00219     bool hasClippingPlane() const;
00221     SbVec3f projectOnNearPlane(const SbVec2f&) const;
00223     SbVec3f projectOnFarPlane(const SbVec2f&) const;
00225 
00231     void setCameraOrientation(const SbRotation& rot);
00232     void setCameraType(SoType t);
00233     void moveCameraTo(const SbRotation& rot, const SbVec3f& pos, int steps, int ms);
00237     void boxZoom(const SbBox2s&);
00241     void viewAll();
00242     void viewAll(float factor);
00248     void viewSelection();
00249 
00252     void drawRect (int x, int y, int w, int h);
00253     void drawLine (int x1, int y1, int x2, int y2);
00255 
00256     void setGradientBackgroud(bool b);
00257     void setGradientBackgroudColor(const SbColor& fromColor,
00258                                    const SbColor& toColor);
00259     void setGradientBackgroudColor(const SbColor& fromColor,
00260                                    const SbColor& toColor,
00261                                    const SbColor& midColor);
00262     void setEnabledFPSCounter(bool b);
00263     void setNavigationType(Base::Type);
00264     NavigationStyle* navigationStyle() const;
00265 
00266 protected:
00267     virtual void actualRedraw(void);
00268     virtual void setSeekMode(SbBool enable);
00269     virtual void afterRealizeHook(void);
00270     virtual void processEvent(QEvent * event);
00271     virtual SbBool processSoEvent(const SoEvent * const ev);
00272     SbBool processSoEventBase(const SoEvent * const ev);
00273     void printDimension();
00274     void selectAll();
00275 
00276     static void clearBuffer(void * userdata, SoAction * action);
00277     static void setGLWidget(void * userdata, SoAction * action);
00278     static void handleEventCB(void * userdata, SoEventCallback * n);
00279     static void interactionStartCB(void * data, SoQtViewer * viewer);
00280     static void interactionFinishCB(void * data, SoQtViewer * viewer);
00281     static void interactionLoggerCB(void * ud, SoAction* action);
00282 
00283 private:
00284     static void selectCB(void * closure, SoPath * p);
00285     static void deselectCB(void * closure, SoPath * p);
00286     static SoPath * pickFilterCB(void * data, const SoPickedPoint * pick);
00287 
00288 private:
00289     std::set<ViewProvider*> _ViewProviderSet;
00290     std::map<SoSeparator*,ViewProvider*> _ViewProviderMap;
00291     ViewProvider* editViewProvider;
00292     SoFCBackgroundGradient *pcBackGround;
00293     SoSeparator * backgroundroot;
00294     SoSeparator * foregroundroot;
00295     SoRotationXYZ * arrowrotation;
00296     SoDirectionalLight* backlight;
00297 
00298     SoSeparator * pcViewProviderRoot;
00299     SoEventCallback* pEventCallback;
00300     NavigationStyle* navigation;
00301 
00302     void initialize();
00303     SbBool axiscrossEnabled;
00304     int axiscrossSize;
00305 
00306     void drawAxisCross(void);
00307     static void drawArrow(void);
00308 
00309     SbBool editing;
00310     QCursor editCursor;
00311     SbBool redirected;
00312 
00313     void setCursorRepresentation(int mode);
00314 
00315 public:
00316     void addFlag(Flag*, FlagLayout::Position);
00317 
00318 private:
00319     QPointer<FlagLayout> _flaglayout;
00320 
00321     // friends
00322     friend class NavigationStyle;
00323 };
00324 
00325 } // namespace Gui
00326 
00327 #endif  // GUI_VIEW3DINVENTORVIEWER_H
00328 

Generated on Wed Nov 23 19:00:57 2011 for FreeCAD by  doxygen 1.6.1