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