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