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