Salome HOME
Copyrights update
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewModel.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
2 // 
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either 
6 // version 2.1 of the License.
7 // 
8 // This library is distributed in the hope that it will be useful 
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public  
14 // License along with this library; if not, write to the Free Software 
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/
18 //
19 #ifndef OCCVIEWER_VIEWMODEL_H
20 #define OCCVIEWER_VIEWMODEL_H
21
22 #include <qcolor.h>
23 #include <qcursor.h>
24
25 #include "OCCViewer.h"
26
27 #include "SUIT_ViewModel.h"
28
29 #include <V3d_View.hxx>
30 #include <AIS_Trihedron.hxx>
31 #include <AIS_ListOfInteractive.hxx>
32 #include <AIS_InteractiveContext.hxx>
33
34 class SUIT_ViewWindow;
35 class SUIT_Desktop;
36 class OCCViewer_ViewWindow;
37
38 struct viewAspect
39 {
40 public:
41         double    scale;
42         double  centerX;
43         double  centerY;
44         double    projX;
45         double    projY;
46         double    projZ;
47         double    twist;
48         double      atX;
49         double      atY;
50         double      atZ;
51         double     eyeX;
52         double     eyeY;
53         double     eyeZ;
54         QString    name;
55 };
56
57 typedef QValueList<viewAspect> viewAspectList;
58
59 #ifdef WIN32
60 #pragma warning( disable:4251 )
61 #endif
62
63 class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel
64 {
65   Q_OBJECT
66
67 public:
68   static QString Type() { return "OCCViewer"; }
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(QPopupMenu*);
81   
82   void                            getSelectedObjects(AIS_ListOfInteractive& theList);
83   void                            setObjectsSelected(const AIS_ListOfInteractive& theList);
84   void                            setSelected(const Handle(AIS_InteractiveObject)& theIO)
85   { myAISContext->SetSelected(theIO);}
86
87   void                            performSelectionChanged();
88   // emit signal selectionChanged
89
90   virtual const viewAspectList&   getViewAspects();
91   virtual void                    appendViewAspect( const viewAspect& );
92   virtual void                    updateViewAspects( const viewAspectList& );
93   virtual void                    clearViewAspects();
94
95   QColor                          backgroundColor() const;
96   void                            setBackgroundColor( const QColor& );
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   int                             trihedronSize() const;
106   virtual void                    setTrihedronSize( const int );
107
108 public slots:
109   void                            onClearViewAspects();
110  
111 public:
112   Handle(V3d_Viewer)              getViewer3d()    const { return myV3dViewer;}
113   Handle(V3d_Viewer)              getCollector3d() const { return myV3dCollector; }
114   Handle(AIS_InteractiveContext)  getAISContext()  const { return myAISContext; }
115   Handle(AIS_Trihedron)           getTrihedron()   const { return myTrihedron; }
116
117   void                            enableSelection(bool isEnabled);
118   bool                            isSelectionEnabled() const 
119   { return mySelectionEnabled; }
120
121   void                            enableMultiselection(bool isEnable);
122   bool                            isMultiSelectionEnabled() const 
123   { return myMultiSelectionEnabled; }
124
125   int                             getSelectionCount() const 
126   { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
127
128   /* Selection management */
129   bool          highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
130   bool          unHighlightAll( bool=true ); 
131   bool    isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
132   bool    isVisible( const Handle(AIS_InteractiveObject)& );
133
134   void    setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
135   void    switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
136   void    setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
137   void    setIsos( const int u, const int v ); // number of isolines
138   void    isos( int& u, int& v ) const;
139
140 signals:
141   void selectionChanged();
142
143 protected:
144   void initView( OCCViewer_ViewWindow* view );
145
146 protected slots:
147   void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
148   void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
149   void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
150
151   void onDumpView();
152   void onShowToolbar();
153   void onChangeBgColor();
154
155 private:
156   Handle(V3d_Viewer)              myV3dViewer;
157   Handle(V3d_Viewer)              myV3dCollector;
158
159   Handle(AIS_Trihedron)           myTrihedron;
160   Handle(AIS_InteractiveContext)  myAISContext;
161
162   viewAspectList                  myViewAspects;
163
164   bool                            mySelectionEnabled;
165   bool                            myMultiSelectionEnabled;
166
167   QColor                          myBgColor;
168   QPoint                          myStartPnt, myEndPnt;
169 };
170
171 #ifdef WIN32
172 #pragma warning( default:4251 )
173 #endif
174
175 #endif