]> SALOME platform Git repositories - modules/gui.git/blob - src/OCCViewer/OCCViewer_ViewWindow.h
Salome HOME
c0a0237715f49cdcf90942aff477cc060bc035ba
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewWindow.h
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 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 GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef OCCVIEWER_VIEWWINDOW_H
24 #define OCCVIEWER_VIEWWINDOW_H
25
26 #include "OCCViewer.h"
27 #include "Qtx.h"
28 #include "SUIT_ViewWindow.h"
29 #include <gp_Pnt.hxx>
30 #include <V3d_Plane.hxx>
31 #include <TopAbs_ShapeEnum.hxx>
32
33 class QtxRectRubberBand;
34 class SUIT_Desktop;
35 class OCCViewer_ViewPort3d;
36 class OCCViewer_ViewSketcher;
37 class OCCViewer_AxialScaleDlg;
38 class OCCViewer_SetRotationPointDlg;
39 class OCCViewer_Viewer;
40 class OCCViewer_CubeAxesDlg;
41 class QtxAction;
42
43 struct viewAspect
44 {
45 public:
46   double    scale;
47   double  centerX; // deprecated since OCCT 6.7.1
48   double  centerY; // deprecated since OCCT 6.7.1
49   double    projX;
50   double    projY;
51   double    projZ;
52   double    twist;
53   double      atX;
54   double      atY;
55   double      atZ;
56   double     eyeX;
57   double     eyeY;
58   double     eyeZ;
59   double   scaleX;
60   double   scaleY;
61   double   scaleZ;
62   QString    name;
63   bool     isVisible;
64   double   size;
65   // graduated trihedron
66   bool    gtIsVisible;
67   bool    gtDrawNameX;
68   bool    gtDrawNameY;
69   bool    gtDrawNameZ;
70   QString gtNameX;
71   QString gtNameY;
72   QString gtNameZ;
73   int     gtNameColorRX;
74   int     gtNameColorGX;
75   int     gtNameColorBX;
76   int     gtNameColorRY;
77   int     gtNameColorGY;
78   int     gtNameColorBY;
79   int     gtNameColorRZ;
80   int     gtNameColorGZ;
81   int     gtNameColorBZ;
82   bool    gtDrawValuesX;
83   bool    gtDrawValuesY;
84   bool    gtDrawValuesZ;
85   int     gtNbValuesX;
86   int     gtNbValuesY;
87   int     gtNbValuesZ;
88   int     gtOffsetX;
89   int     gtOffsetY;
90   int     gtOffsetZ;
91   int     gtColorRX;
92   int     gtColorGX;
93   int     gtColorBX;
94   int     gtColorRY;
95   int     gtColorGY;
96   int     gtColorBY;
97   int     gtColorRZ;
98   int     gtColorGZ;
99   int     gtColorBZ;
100   bool    gtDrawTickmarksX;
101   bool    gtDrawTickmarksY;
102   bool    gtDrawTickmarksZ;
103   int     gtTickmarkLengthX;
104   int     gtTickmarkLengthY;
105   int     gtTickmarkLengthZ;
106
107 public:
108   viewAspect()
109   : scale( 0.0 ),
110     centerX( 0.0 ), centerY( 0.0 ),
111     projX( 0.0 ), projY( 0.0 ), projZ( 0.0 ),
112     twist( 0.0 ),
113     atX( 0.0 ), atY( 0.0 ), atZ( 0.0 ),
114     eyeX( 0.0 ), eyeY( 0.0 ), eyeZ( 0.0 ),
115     scaleX( 0.0 ), scaleY( 0.0 ), scaleZ( 0.0 ),
116     name(),
117     isVisible( false ),
118     size( 0.0 ),
119     gtIsVisible( false ),
120     gtDrawNameX( false ), gtDrawNameY( false ), gtDrawNameZ( false ),
121     gtNameX(), gtNameY(), gtNameZ(), 
122     gtNameColorRX( 0 ), gtNameColorGX( 0 ), gtNameColorBX( 0 ),
123     gtNameColorRY( 0 ), gtNameColorGY( 0 ), gtNameColorBY( 0 ),
124     gtNameColorRZ( 0 ), gtNameColorGZ( 0 ), gtNameColorBZ( 0 ),
125     gtDrawValuesX( false ), gtDrawValuesY( false ), gtDrawValuesZ( false ),
126     gtNbValuesX( 0 ), gtNbValuesY( 0 ), gtNbValuesZ( 0 ),
127     gtOffsetX( 0 ), gtOffsetY( 0 ), gtOffsetZ( 0 ),
128     gtColorRX( 0 ), gtColorGX( 0 ), gtColorBX( 0 ),
129     gtColorRY( 0 ), gtColorGY( 0 ), gtColorBY( 0 ),
130     gtColorRZ( 0 ), gtColorGZ( 0 ), gtColorBZ( 0 ),
131     gtDrawTickmarksX( false ), gtDrawTickmarksY( false ), gtDrawTickmarksZ( false ),
132     gtTickmarkLengthX( 0 ), gtTickmarkLengthY( 0 ), gtTickmarkLengthZ( 0 ) {}
133 };
134
135 typedef QList<viewAspect> viewAspectList;
136
137 #ifdef WIN32
138 #pragma warning( disable:4251 )
139 #endif
140
141 class OCCVIEWER_EXPORT OCCViewer_ViewWindow : public SUIT_ViewWindow  
142 {
143   Q_OBJECT
144
145 public:
146   enum { DumpId, FitAllId, FitRectId, FitSelectionId, ZoomId, PanId, GlobalPanId,
147          ChangeRotationPointId, RotationId,
148          FrontId, BackId, TopId, BottomId, LeftId, RightId, ClockWiseId, AntiClockWiseId,
149          ResetId, CloneId, ClippingId, MemId, RestoreId,
150          TrihedronShowId, AxialScaleId, GraduatedAxesId, AmbientId,
151          SwitchInteractionStyleId, SwitchZoomingStyleId, 
152          SwitchPreselectionId, SwitchSelectionId,
153          MaximizedId, SynchronizeId, ReturnTo3dViewId,
154          OrthographicId, PerspectiveId,
155          UserId };
156
157   enum OperationType{ NOTHING, PANVIEW, ZOOMVIEW, ROTATE, 
158                       PANGLOBAL, WINDOWFIT, FITALLVIEW, FITSELECTION, RESETVIEW,
159                       FRONTVIEW, BACKVIEW, TOPVIEW, BOTTOMVIEW, LEFTVIEW, RIGHTVIEW,
160                       CLOCKWISEVIEW, ANTICLOCKWISEVIEW, PROJECTION };
161
162   enum RotationPointType{ GRAVITY, SELECTED };
163
164   enum SketchingType { NoSketching, Rect, Polygon };
165
166   enum Mode2dType { No2dMode, XYPlane, XZPlane, YZPlane };
167
168   enum ProjectionType { Orthographic, Perspective };
169   
170   OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel);
171   virtual ~OCCViewer_ViewWindow();
172
173   virtual OCCViewer_ViewWindow* getView( const int ) const;
174
175   virtual OCCViewer_ViewPort3d* getViewPort();
176
177   virtual bool eventFilter(QObject* watched, QEvent* e);
178
179   virtual void performRestoring( const viewAspect&, bool = false );
180   
181   virtual void initLayout();
182
183   virtual void updateEnabledDrawMode();
184
185   virtual void setCuttingPlane( bool on, const double x = 0 , const double y = 0 , const double z = 0,
186                                 const double dx = 0, const double dy = 0, const double dz = 1);
187
188   virtual void setCuttingPlane( bool on, const gp_Pln thePln );
189
190   virtual bool isCuttingPlane();
191
192   virtual QString   getVisualParameters();
193   virtual void      setVisualParameters( const QString& parameters );
194
195   virtual void                    initSketchers();
196   virtual OCCViewer_ViewSketcher* getSketcher( const int );
197
198   virtual void                    activateSketching( int );
199
200   virtual int                     interactionStyle() const;
201   virtual void                    setInteractionStyle( const int );
202  
203   virtual int                     zoomingStyle() const;
204   virtual void                    setZoomingStyle( const int );
205
206   virtual bool                    isPreselectionEnabled() const;
207   virtual void                    enablePreselection( bool );   
208   virtual bool                    isSelectionEnabled() const;
209   virtual void                    enableSelection( bool );
210  
211   virtual int                     projectionType() const;
212   virtual void                    setProjectionType( int );
213
214   void setTransformEnabled( const OperationType, const bool );
215   bool transformEnabled( const OperationType ) const;
216
217   void            set2dMode( Mode2dType );
218   Mode2dType      get2dMode() const { return my2dMode; }
219
220   void            setMaximized( bool, bool = true );
221   bool            isMaximized() const;
222   void            setReturnedTo3dView( bool = true );
223   
224   void            setSketcherStyle( bool enable );
225   bool            isSketcherStyle() const;
226
227   virtual QColor  backgroundColor() const;                      // obsolete
228   virtual void    setBackgroundColor( const QColor& );          // obsolete
229
230   virtual void    showStaticTrihedron( bool );
231
232   virtual Qtx::BackgroundData  background() const;
233   virtual void                 setBackground( const Qtx::BackgroundData& );
234
235   virtual const   viewAspectList& getViewAspects();
236   virtual void                    appendViewAspect( const viewAspect& );
237   virtual void                    updateViewAspects( const viewAspectList& );
238   virtual void                    clearViewAspects();
239
240   virtual SUIT_CameraProperties   cameraProperties();
241
242 public slots:
243   virtual void onFrontView();
244   virtual void onViewFitAll();
245   virtual void onBackView();
246   virtual void onClipping(bool on);
247   virtual void onTopView();
248   virtual void onBottomView();
249   virtual void onLeftView();
250   virtual void onRightView();
251   virtual void onClockWiseView();
252   virtual void onAntiClockWiseView();
253   virtual void onProjectionType();
254   virtual void onResetView();
255   virtual void onFitAll();
256   virtual void onFitSelection();
257   virtual void activateZoom();
258   virtual void activateWindowFit();
259   virtual void activateRotation();
260   virtual void activatePanning();
261   virtual void activateGlobalPanning();
262   virtual void onSetRotationPoint( bool on );
263   virtual void onCloneView();
264   virtual void onAxialScale();
265   virtual void onGraduatedAxes();
266   virtual void onAmbientToogle();
267   virtual void onMemorizeView();
268   virtual void onRestoreView();
269   virtual void onTrihedronShow(bool);
270   virtual void setRestoreFlag();
271   virtual void onSwitchInteractionStyle( bool on );
272   virtual void onSwitchZoomingStyle( bool on );
273   virtual void onSwitchPreselection( bool on );
274   virtual void onSwitchSelection( bool on );
275
276   virtual void activateSetRotationGravity();
277   virtual void activateSetRotationSelected( double theX, double theY, double theZ );
278   virtual void activateStartPointSelection( TopAbs_ShapeEnum );
279   virtual void updateGravityCoords();
280    
281   virtual void showEvent( QShowEvent * );
282   virtual void hideEvent( QHideEvent * );
283
284   virtual void onMaximizedView();
285   virtual void returnTo3dView();
286
287 signals:
288   void vpTransformationStarted(OCCViewer_ViewWindow::OperationType type);
289   void vpTransformationFinished(OCCViewer_ViewWindow::OperationType type);
290   void viewCloned( SUIT_ViewWindow* );
291
292   void Show( QShowEvent * );
293   void Hide( QHideEvent * );
294   void maximized( OCCViewer_ViewWindow*, bool );
295   void returnedTo3d( );
296
297 protected slots:
298   void synchronize( SUIT_ViewWindow* );
299
300 public:
301   virtual QImage dumpView();
302   virtual bool   dumpViewToFormat( const QImage&, const QString& fileName, const QString& format );
303
304 protected:
305   virtual QString  filter() const;
306
307   /* Transformation selected but not started yet */
308   bool transformRequested() const;
309   bool setTransformRequested ( OperationType );
310
311   /* Transformation is selected and already started */
312   bool          transformInProcess() const;
313   void          setTransformInProcess( bool );
314
315   void vpMousePressEvent(QMouseEvent* theEvent);
316   void vpMouseReleaseEvent(QMouseEvent* theEvent);
317   void vpMouseMoveEvent(QMouseEvent* theEvent);
318
319   void resetState();
320   void drawRect();
321   void endDrawRect();
322
323   void createActions();
324   void createToolBar();
325  
326   virtual OperationType getButtonState(QMouseEvent* theEvent, int theInteractionStyle);
327
328   viewAspect getViewParams() const;
329
330   bool computeGravityCenter( double& theX, double& theY, double& theZ );
331
332   virtual void                          onSketchingStarted();
333   virtual void                          onSketchingFinished();
334
335   virtual OCCViewer_ViewSketcher*       createSketcher( int );
336
337   void                                  saveCursor();
338
339   OCCViewer_ViewSketcher*               mypSketcher;
340   QList<OCCViewer_ViewSketcher*>        mySketchers;
341
342   int                                   myCurSketch;
343
344   OperationType         myOperation;
345   OCCViewer_Viewer*     myModel;
346   OCCViewer_ViewPort3d* myViewPort;
347
348   OCCViewer_CubeAxesDlg* myCubeAxesDlg;
349
350   RotationPointType     myCurrPointType;
351   RotationPointType     myPrevPointType;
352   gp_Pnt                mySelectedPoint;
353   bool                  myRotationPointSelection;
354
355   int                                   myRestoreFlag;
356
357   int                                   myStartX;
358   int                                   myStartY;
359   int                                   myCurrX;
360   int                                   myCurrY;
361
362   bool                  myEventStarted;       // set when transformation is in process 
363   bool                  myCursorIsHand;                 
364   bool                  myDrawRect;           // set when a rect is used for selection or magnify 
365   bool                  myEnableDrawMode;
366   bool                  myPaintersRedrawing;  // set to draw with external painters  
367   bool                  IsSketcherStyle;
368   bool                  myIsKeyFree;
369   
370   QCursor               myCursor;
371
372   double myCurScale;
373
374 private:
375   OCCViewer_AxialScaleDlg* myScalingDlg;
376
377   OCCViewer_SetRotationPointDlg* mySetRotationPointDlg;
378   QtxAction* mySetRotationPointAction;
379
380   QtxRectRubberBand* myRectBand; //!< selection rectangle rubber band
381
382   bool mySelectionEnabled;
383   bool myPreselectionEnabled;
384   int myInteractionStyle;
385
386   typedef QMap<OperationType, bool> MapOfTransformStatus;
387   MapOfTransformStatus myStatus;
388
389   Mode2dType my2dMode;
390
391   Handle(V3d_Plane) myReserveClipPlane;
392
393   viewAspectList myViewAspects;
394 };
395
396 #ifdef WIN32
397 #pragma warning( default:4251 )
398 #endif
399
400 #endif