NavigationStyle.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net>     *
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_NAVIGATIONSTYLE_H
00025 #define GUI_NAVIGATIONSTYLE_H
00026 
00027 #include <Inventor/C/basic.h>
00028 #include <Inventor/SbBox2s.h>
00029 #include <Inventor/SbVec2f.h>
00030 #include <Inventor/SbVec2s.h>
00031 #include <Inventor/SbVec3f.h>
00032 #include <Inventor/SbPlane.h>
00033 #include <Inventor/SbRotation.h>
00034 #include <Inventor/SbTime.h>
00035 #include <QCursor>
00036 #include <QEvent>
00037 #include <Base/BaseClass.h>
00038 
00039 // forward declarations
00040 class SoEvent;
00041 class SoQtViewer;
00042 class SoCamera;
00043 class SoSensor;
00044 class SbSphereSheetProjector;
00045 
00046 namespace Gui {
00047 
00048 class View3DInventorViewer;
00049 class AbstractMouseSelection;
00050 
00054 class GuiExport NavigationStyleEvent : public QEvent
00055 {
00056 public:
00057     NavigationStyleEvent(const Base::Type& s);
00058     ~NavigationStyleEvent();
00059     const Base::Type& style() const;
00060 private:
00061     Base::Type t;
00062 };
00063 
00068 class GuiExport NavigationStyle : public Base::BaseClass
00069 {
00070     TYPESYSTEM_HEADER();
00071 
00072 public:
00073     enum ViewerMode {
00074         IDLE,
00075         INTERACT,
00076         ZOOMING,
00077         BOXZOOM,
00078         PANNING,
00079         DRAGGING,
00080         SPINNING,
00081         SEEK_WAIT_MODE,
00082         SEEK_MODE,
00083         SELECTION
00084     };
00085 
00086     enum SelectionMode {
00087         Lasso       = 0,  
00088         Rectangle   = 1,  
00089         BoxZoom     = 2,  
00090         Clip        = 3,  
00091     };
00092 
00093     enum OrbitStyle {
00094         Turntable,
00095         Trackball
00096     };
00097 
00098 public:
00099     NavigationStyle();
00100     virtual ~NavigationStyle();
00101 
00102     NavigationStyle& operator = (const NavigationStyle& ns);
00103     void setViewer(View3DInventorViewer*);
00104 
00105     void setAnimationEnabled(const SbBool enable);
00106     SbBool isAnimationEnabled(void) const;
00107 
00108     void startAnimating(const SbVec3f& axis, float velocity);
00109     void stopAnimating(void);
00110     SbBool isAnimating(void) const;
00111 
00112     void setZoomInverted(SbBool);
00113     SbBool isZoomInverted() const;
00114 
00115     void updateAnimation();
00116     void redraw();
00117 
00118     void setCameraOrientation(const SbRotation& rot);
00119     void lookAtPoint(const SbVec3f&);
00120     void boxZoom(const SbBox2s& box);
00121     virtual void viewAll();
00122 
00123     void setViewingMode(const ViewerMode newmode);
00124     int getViewingMode() const;
00125     virtual SbBool processEvent(const SoEvent * const ev);
00126 
00127     void setPopupMenuEnabled(const SbBool on);
00128     SbBool isPopupMenuEnabled(void) const;
00129 
00130     void startSelection(AbstractMouseSelection*);
00131     void startSelection(SelectionMode = Lasso);
00132     void stopSelection();
00133     SbBool isSelecting() const;
00134     const std::vector<SbVec2s>& getPolygon(SbBool* clip_inner=0) const;
00135 
00136     void setOrbitStyle(OrbitStyle style);
00137     OrbitStyle getOrbitStyle() const;
00138 
00139 protected:
00140     void initialize();
00141     void finalize();
00142 
00143     void interactiveCountInc(void);
00144     void interactiveCountDec(void);
00145     int getInteractiveCount(void) const;
00146 
00147     SbBool isViewing(void) const;
00148     void setViewing(SbBool);
00149     SbBool isSeekMode(void) const;
00150     void setSeekMode(SbBool enable);
00151     SbBool seekToPoint(const SbVec2s screenpos);
00152     void seekToPoint(const SbVec3f& scenepos);
00153     SbBool lookAtPoint(const SbVec2s screenpos);
00154 
00155     void reorientCamera(SoCamera * camera, const SbRotation & rot);
00156     void panCamera(SoCamera * camera,
00157                    float vpaspect,
00158                    const SbPlane & panplane,
00159                    const SbVec2f & previous,
00160                    const SbVec2f & current);
00161     void pan(SoCamera* camera);
00162     void panToCenter(const SbPlane & pplane, const SbVec2f & currpos);
00163     void zoom(SoCamera * camera, float diffvalue);
00164     void zoomByCursor(const SbVec2f & thispos, const SbVec2f & prevpos);
00165     void spin(const SbVec2f & pointerpos);
00166     SbBool doSpin();
00167 
00168     SbBool handleEventInForeground(const SoEvent* const e);
00169     virtual SbBool processSoEvent(const SoEvent * const ev);
00170     virtual void openPopupMenu(const SbVec2s& position);
00171 
00172     void clearLog(void);
00173     void addToLog(const SbVec2s pos, const SbTime time);
00174 
00175 protected:
00176     struct { // tracking mouse movement in a log
00177         short size;
00178         short historysize;
00179         SbVec2s * position;
00180         SbTime * time;
00181     } log;
00182 
00183     View3DInventorViewer* viewer;
00184     ViewerMode currentmode;
00185     SbVec2f lastmouseposition;
00186     SbPlane panningplane;
00187     SbTime prevRedrawTime;
00188     SbTime centerTime;
00189     SbBool lockrecenter;
00190     SbBool menuenabled;
00191     SbBool ctrldown, shiftdown, altdown;
00192     SbBool button1down, button2down, button3down;
00193     SbBool invertZoom;
00194 
00197     AbstractMouseSelection* mouseSelection;
00198     std::vector<SbVec2s> pcPolygon;
00199     SbBool clipInner;
00201 
00204     SbBool spinanimatingallowed;
00205     int spinsamplecounter;
00206     SbRotation spinincrement;
00207     SbRotation spinRotation;
00208     SbSphereSheetProjector * spinprojector;
00210 
00211 private:
00212     struct NavigationStyleP* pimpl;
00213     friend struct NavigationStyleP;
00214 };
00215 
00225 class GuiExport UserNavigationStyle : public NavigationStyle {
00226     TYPESYSTEM_HEADER();
00227 
00228 public:
00229     UserNavigationStyle(){}
00230     ~UserNavigationStyle(){}
00231     virtual const char* mouseButtons(ViewerMode) = 0;
00232 };
00233 
00234 class GuiExport InventorNavigationStyle : public UserNavigationStyle {
00235     typedef UserNavigationStyle inherited;
00236 
00237     TYPESYSTEM_HEADER();
00238 
00239 public:
00240     InventorNavigationStyle();
00241     ~InventorNavigationStyle();
00242     const char* mouseButtons(ViewerMode);
00243 
00244 protected:
00245     SbBool processSoEvent(const SoEvent * const ev);
00246 };
00247 
00248 class GuiExport CADNavigationStyle : public UserNavigationStyle {
00249     typedef UserNavigationStyle inherited;
00250 
00251     TYPESYSTEM_HEADER();
00252 
00253 public:
00254     CADNavigationStyle();
00255     ~CADNavigationStyle();
00256     const char* mouseButtons(ViewerMode);
00257 
00258 protected:
00259     SbBool processSoEvent(const SoEvent * const ev);
00260 
00261 private:
00262     SbBool lockButton1;
00263 };
00264 
00265 class GuiExport BlenderNavigationStyle : public UserNavigationStyle {
00266     typedef UserNavigationStyle inherited;
00267 
00268     TYPESYSTEM_HEADER();
00269 
00270 public:
00271     BlenderNavigationStyle();
00272     ~BlenderNavigationStyle();
00273     const char* mouseButtons(ViewerMode);
00274 
00275 protected:
00276     SbBool processSoEvent(const SoEvent * const ev);
00277 
00278 private:
00279     SbBool lockButton1;
00280 };
00281 
00282 } // namespace Gui
00283 
00284 #endif // GUI_NAVIGATIONSTYLE_H 

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