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