Salome HOME
Merge remote branch 'origin/V7_4_BR'
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewModel.h
1 // Copyright (C) 2007-2014  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_VIEWMODEL_H
24 #define OCCVIEWER_VIEWMODEL_H
25
26 #include <QColor>
27 #include <QPoint>
28 #include <QVector>
29
30 #include "OCCViewer.h"
31 #include "OCCViewer_ClipPlane.h"
32
33 #include "Qtx.h"
34 #include "SUIT_ViewModel.h"
35
36 #include <V3d_View.hxx>
37 #include <AIS_Trihedron.hxx>
38 #include <AIS_InteractiveContext.hxx>
39 #include <Basics_OCCTVersion.hxx>
40 #include <Graphic3d_SequenceOfHClipPlane.hxx>
41
42 class QKeyEvent;
43 class QMouseEvent;
44
45 class SUIT_ViewWindow;
46 class SUIT_Desktop;
47 class OCCViewer_ClippingDlg;
48 class OCCViewer_ViewWindow;
49 class OCCViewer_ViewPort3d;
50
51 class AIS_ListOfInteractive;
52
53 class QtxAction;
54
55
56 #ifdef WIN32
57 #pragma warning( disable:4251 )
58 #endif
59
60 class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel
61 {
62   Q_OBJECT
63
64 public:
65   /*! supported gradient types */
66   enum { 
67     HorizontalGradient, VerticalGradient,
68     Diagonal1Gradient,  Diagonal2Gradient,
69     Corner1Gradient,    Corner2Gradient,
70     Corner3Gradient,    Corner4Gradient,
71     LastGradient = Corner4Gradient
72   };
73   
74   static QString           Type() { return "OCCViewer"; }
75   static QString           backgroundData( QStringList&, QIntList&, QIntList& );
76
77   OCCViewer_Viewer( bool DisplayTrihedron = true);
78   virtual ~OCCViewer_Viewer();
79
80   void update();
81
82   virtual SUIT_ViewWindow*        createView(SUIT_Desktop* theDesktop);
83   
84   virtual void                    setViewManager(SUIT_ViewManager* theViewManager);
85   virtual QString                 getType() const { return Type(); }
86
87   virtual void                    contextMenuPopup(QMenu*);
88   
89   void                            getSelectedObjects(AIS_ListOfInteractive& theList);
90   void                            setObjectsSelected(const AIS_ListOfInteractive& theList);
91   void                            setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO);}
92
93   void                            performSelectionChanged();
94   // emit signal selectionChanged
95
96   QColor                          backgroundColor() const;                              // obsolete
97   void                            setBackgroundColor( const QColor& );                  // obsolete
98   Qtx::BackgroundData             background() const;
99   void                            setBackground( const Qtx::BackgroundData& );
100
101   QColor                          backgroundColor(int theViewId) const;                 // obsolete
102   void                            setBackgroundColor( int theViewId, const QColor& );   // obsolete
103   Qtx::BackgroundData             background(int theViewId) const;
104   void                            setBackground( int theViewId, const Qtx::BackgroundData& );
105
106   //! returns true if 3d Trihedron in viewer was created
107   bool                            trihedronActivated() const { return !myTrihedron.IsNull(); }
108
109   void                            toggleTrihedron();
110   bool                            isTrihedronVisible() const;
111   virtual void                    setTrihedronShown( const bool );
112
113   double                          trihedronSize() const;
114   virtual void                    setTrihedronSize( const double , bool isRelative = true);
115   
116   bool                            trihedronRelative() const {return myIsRelative; }
117
118   // a utility functions, used by SALOME_View_s methods
119   bool                            computeTrihedronSize( double& theNewSize, double& theSize );
120   virtual double                  computeSceneSize(const Handle(V3d_View)&) const;
121
122   void                            updateTrihedron();
123   
124
125   virtual OCCViewer_ViewWindow*   createSubWindow();
126
127 public:
128   Handle(V3d_Viewer)              getViewer3d()    const { return myV3dViewer;}
129 #if OCC_VERSION_LARGE <= 0x06060000 
130   Handle(V3d_Viewer)              getCollector3d() const { return myV3dCollector; }
131 #endif
132   Handle(AIS_InteractiveContext)  getAISContext()  const { return myAISContext; }
133   Handle(AIS_Trihedron)           getTrihedron()   const { return myTrihedron; }
134
135   int                             getTopLayerId();
136
137   int                             interactionStyle() const;
138   void                            setInteractionStyle( const int );
139
140   int                             zoomingStyle() const;
141   void                            setZoomingStyle( const int );
142
143   void                            enablePreselection(bool isEnabled);
144   bool                            isPreselectionEnabled() const;
145   
146   void                            enableSelection(bool isEnabled);
147   bool                            isSelectionEnabled() const;
148
149   void                            setSelectionOptions( bool, bool );
150
151   void                            enableMultiselection(bool isEnable);
152   bool                            isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
153
154   int                             getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
155
156   void                            setStaticTrihedronDisplayed(const bool on);
157
158   /* Clip planes management */
159   Handle(Graphic3d_ClipPlane)     createClipPlane(const gp_Pln& thePlane, const Standard_Boolean theIsOn);
160   void                            setClipPlanes (ClipPlanesList theList);
161   ClipPlanesList                  getClipPlanes() const;
162   void                            applyExistingClipPlanesToObject (const Handle(AIS_InteractiveObject)& theObject);
163
164   OCCViewer_ClippingDlg*          getClippingDlg() const;
165   void                            setClippingDlg(OCCViewer_ClippingDlg* theDlg);
166   
167
168   /* Selection management */
169   bool    highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
170   bool    unHighlightAll( bool=true, bool=true ); 
171   bool    isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
172   bool    isVisible( const Handle(AIS_InteractiveObject)& );
173
174   void    setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
175   void    switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
176   void    setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
177   void    setIsos( const int u, const int v ); // number of isolines
178   void    isos( int& u, int& v ) const;
179
180   void    initView( OCCViewer_ViewWindow* view );
181
182 signals:
183   void selectionChanged();
184   void deselection();
185
186 protected slots:
187   virtual void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
188   virtual void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
189   virtual void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
190   virtual void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
191   virtual void onViewClosed(OCCViewer_ViewPort3d*);
192   virtual void onViewMapped(OCCViewer_ViewPort3d*);
193
194   void onDumpView();
195   void onChangeBackground();
196
197 protected:
198   Handle(V3d_Viewer)              myV3dViewer;
199
200 #if OCC_VERSION_LARGE <= 0x06060000
201   Handle(V3d_Viewer)              myV3dCollector;
202 #endif
203
204
205   Handle(AIS_Trihedron)           myTrihedron;
206   Handle(AIS_InteractiveContext)  myAISContext;
207
208   int                             myInteractionStyle;
209   int                             myZoomingStyle;
210
211   bool                            myPreselectionEnabled;
212   bool                            mySelectionEnabled;
213   bool                            myMultiSelectionEnabled;
214   bool                            myIsRelative;
215
216   int                             myTopLayerId;
217
218   //QColor                          myBgColor;
219   QPoint                          myStartPnt, myEndPnt, myCurPnt;
220
221   double                          myTrihedronSize;
222
223   QVector<Qtx::BackgroundData>    myBackgrounds;
224
225   OCCViewer_ClippingDlg*          myClippingDlg;
226
227   ClipPlanesList                  myClipPlanes;
228   Graphic3d_SequenceOfHClipPlane  myInternalClipPlanes;
229 };
230
231 #ifdef WIN32
232 #pragma warning( default:4251 )
233 #endif
234
235 #endif