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