]> SALOME platform Git repositories - modules/gui.git/blob - src/OCCViewer/OCCViewer_ViewModel.h
Salome HOME
dbddfa2391307b6d3fc63e97dfa5f5b83bd066fb
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewModel.h
1 //  Copyright (C) 2007-2008  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 #ifndef OCCVIEWER_VIEWMODEL_H
23 #define OCCVIEWER_VIEWMODEL_H
24
25 #include <QColor>
26 #include <QPoint>
27
28 #include "OCCViewer.h"
29
30 #include "SUIT_ViewModel.h"
31
32 #include <V3d_View.hxx>
33 #include <AIS_Trihedron.hxx>
34 #include <AIS_InteractiveContext.hxx>
35
36 class QMouseEvent;
37
38 class SUIT_ViewWindow;
39 class SUIT_Desktop;
40 class OCCViewer_ViewWindow;
41
42 class AIS_ListOfInteractive;
43
44 struct viewAspect
45 {
46 public:
47         double    scale;
48         double  centerX;
49         double  centerY;
50         double    projX;
51         double    projY;
52         double    projZ;
53         double    twist;
54         double      atX;
55         double      atY;
56         double      atZ;
57         double     eyeX;
58         double     eyeY;
59         double     eyeZ;
60         double   scaleX;
61         double   scaleY;
62         double   scaleZ;
63         QString    name;
64         bool     isVisible;
65         double   size;
66 };
67
68 typedef QList<viewAspect> viewAspectList;
69
70 #ifdef WIN32
71 #pragma warning( disable:4251 )
72 #endif
73
74 class OCCVIEWER_EXPORT OCCViewer_Viewer: public SUIT_ViewModel
75 {
76   Q_OBJECT
77
78 public:
79   static QString Type() { return "OCCViewer"; }
80
81   OCCViewer_Viewer( bool DisplayTrihedron = true, bool DisplayStaticTrihedron = true );
82   virtual ~OCCViewer_Viewer();
83
84   void update();
85
86   virtual SUIT_ViewWindow*        createView(SUIT_Desktop* theDesktop);
87   
88   virtual void                    setViewManager(SUIT_ViewManager* theViewManager);
89   virtual QString                 getType() const { return Type(); }
90
91   virtual void                    contextMenuPopup(QMenu*);
92   
93   void                            getSelectedObjects(AIS_ListOfInteractive& theList);
94   void                            setObjectsSelected(const AIS_ListOfInteractive& theList);
95   void                            setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO);}
96
97   void                            performSelectionChanged();
98   // emit signal selectionChanged
99
100   virtual const viewAspectList&   getViewAspects();
101   virtual void                    appendViewAspect( const viewAspect& );
102   virtual void                    updateViewAspects( const viewAspectList& );
103   virtual void                    clearViewAspects();
104
105   QColor                          backgroundColor() const;
106   void                            setBackgroundColor( const QColor& );
107
108   //! returns true if 3d Trihedron in viewer was created
109   bool                            trihedronActivated() const { return !myTrihedron.IsNull(); }
110
111   void                            toggleTrihedron();
112   bool                            isTrihedronVisible() const;
113   virtual void                    setTrihedronShown( const bool );
114
115   double                          trihedronSize() const;
116   virtual void                    setTrihedronSize( const double );
117
118 public slots:
119   void                            onClearViewAspects();
120  
121 public:
122   Handle(V3d_Viewer)              getViewer3d()    const { return myV3dViewer;}
123   Handle(V3d_Viewer)              getCollector3d() const { return myV3dCollector; }
124   Handle(AIS_InteractiveContext)  getAISContext()  const { return myAISContext; }
125   Handle(AIS_Trihedron)           getTrihedron()   const { return myTrihedron; }
126
127   void                            enableSelection(bool isEnabled);
128   bool                            isSelectionEnabled() const { return mySelectionEnabled; }
129
130   void                            enableMultiselection(bool isEnable);
131   bool                            isMultiSelectionEnabled() const { return myMultiSelectionEnabled; }
132
133   int                             getSelectionCount() const { return (!myAISContext.IsNull())? myAISContext->NbSelected():0; }
134   bool                            isStaticTrihedronDisplayed() { return myShowStaticTrihedron; }
135
136   /* Selection management */
137   bool    highlight( const Handle(AIS_InteractiveObject)&, bool, bool=true );
138   bool    unHighlightAll( bool=true ); 
139   bool    isInViewer( const Handle(AIS_InteractiveObject)&, bool=false );
140   bool    isVisible( const Handle(AIS_InteractiveObject)& );
141
142   void    setColor( const Handle(AIS_InteractiveObject)&, const QColor&, bool=true );
143   void    switchRepresentation( const Handle(AIS_InteractiveObject)&, int, bool=true );
144   void    setTransparency( const Handle(AIS_InteractiveObject)&, float, bool=true );
145   void    setIsos( const int u, const int v ); // number of isolines
146   void    isos( int& u, int& v ) const;
147
148 signals:
149   void selectionChanged();
150   void deselection();
151
152 protected:
153   void initView( OCCViewer_ViewWindow* view );
154
155 protected slots:
156   void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
157   void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
158   void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
159
160   void onDumpView();
161   void onChangeBgColor();
162
163 private:
164   Handle(V3d_Viewer)              myV3dViewer;
165   Handle(V3d_Viewer)              myV3dCollector;
166
167   Handle(AIS_Trihedron)           myTrihedron;
168   Handle(AIS_InteractiveContext)  myAISContext;
169
170   viewAspectList                  myViewAspects;
171
172   bool                            mySelectionEnabled;
173   bool                            myMultiSelectionEnabled;
174
175   QColor                          myBgColor;
176   QPoint                          myStartPnt, myEndPnt;
177
178   bool                            myShowStaticTrihedron;
179 };
180
181 #ifdef WIN32
182 #pragma warning( default:4251 )
183 #endif
184
185 #endif