Salome HOME
Issue #1860: fix end lines with spaces
[modules/shaper.git] / src / SHAPERGUI / SHAPERGUI_SalomeViewer.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3
4 #ifndef SHAPERGUI_SalomeViewer_H
5 #define SHAPERGUI_SalomeViewer_H
6
7 #include "SHAPER_SHAPERGUI.h"
8
9 #include <ModuleBase_IViewer.h>
10 #include <ModuleBase_IViewWindow.h>
11
12 #include <OCCViewer_ViewWindow.h>
13
14 #include <V3d_View.hxx>
15 #include <AIS_Trihedron.hxx>
16
17 class SUIT_ViewWindow;
18 class QMouseEvent;
19 class QKeyEvent;
20
21 class SHAPERGUI_OCCSelector;
22 class OCCViewer_Viewer;
23 class SUIT_ViewManager;
24
25 /**
26 * \ingroup Salome
27 * A class for providing access of SHAPERGUI functionality to 
28 * SALOME view window functionality
29 */
30 class SHAPERGUI_SalomeView: public ModuleBase_IViewWindow
31 {
32 public:
33   /// Constructor
34   /// \param theViewer a reference to a viewer
35   SHAPERGUI_SalomeView(OCCViewer_Viewer* theViewer);
36
37   virtual Handle(V3d_View) v3dView() const;
38
39   /// Returns the view window view port
40   virtual QWidget* viewPort() const;
41
42   /// Set the current viewer
43   /// \param theViewer a viewer instance
44   void setViewer(OCCViewer_Viewer* theViewer) { myViewer = theViewer; }
45
46   /// Returns current viewer
47   OCCViewer_Viewer* viewer() const { return myViewer; }
48
49   /// Sets the current view
50   void setCurrentView(SUIT_ViewWindow* theView) { myCurrentView = theView; }
51
52 private:
53   /// A reference to a viewer
54   OCCViewer_Viewer* myViewer;
55   SUIT_ViewWindow* myCurrentView;
56 };
57
58
59 /**
60 * \ingroup Salome
61 * A class for providing access of SHAPERGUI functionality to 
62 * SALOME viewer functionality
63 */
64 class SHAPERGUI_SalomeViewer : public ModuleBase_IViewer
65 {
66 Q_OBJECT
67  public:
68    /// Constructor
69    /// \param theParent a parent object
70   SHAPERGUI_SalomeViewer(QObject* theParent);
71
72   ~SHAPERGUI_SalomeViewer();
73
74   //! Returns AIS_InteractiveContext from current OCCViewer
75   virtual Handle(AIS_InteractiveContext) AISContext() const;
76
77   //! Retrurns V3d_Vioewer from current viewer
78   virtual Handle(V3d_Viewer) v3dViewer() const;
79
80   //! Trihedron 3d object shown in the viewer
81   virtual Handle(AIS_Trihedron) trihedron() const;
82
83   //! Returns Vsd_View object from currently active view window
84   virtual Handle(V3d_View) activeView() const;
85
86   //! Returns viewer view port
87   virtual QWidget* activeViewPort() const;
88
89   //! Enable or disable selection in the viewer
90   virtual void enableSelection(bool isEnabled);
91
92   //! Returns true if selection is enabled
93   virtual bool isSelectionEnabled() const;
94
95   //! Enable or disable multiselection in the viewer
96   virtual void enableMultiselection(bool isEnable);
97
98   //! Returns true if multiselection is enabled
99   virtual bool isMultiSelectionEnabled() const;
100
101   //! Enable or disable draw mode in the viewer
102   virtual bool enableDrawMode(bool isEnabled);
103
104   //! For some signals it disconnects the window from usual signal and connect it to the module ones
105   void reconnectActions(SUIT_ViewWindow* theWindow, const bool theUseSHAPERSlot);
106
107   //! Perfroms the fit all for the active view
108   virtual void fitAll();
109
110   //! Sets the view projection
111   /// \param theX the X projection value
112   /// \param theY the Y projection value
113   /// \param theZ the Z projection value
114   /// \param theTwist the twist angle in radians
115   virtual void setViewProjection( double theX, double theY, double theZ,
116                                   double theTwist );
117
118   /// Set selector
119   /// \param theSel a selector instance
120   void setSelector(SHAPERGUI_OCCSelector* theSel);
121
122   /// Add selection filter to the viewer
123   virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
124
125   /// Remove selection filter from the viewer
126   virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
127
128   /// Returns true if the selection filter is set to the viewer
129   /// \param theFilter a selection filter
130   virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
131
132   /// Remove all selection filters from the viewer
133   virtual void clearSelectionFilters();
134
135   /// Returns current selector
136   SHAPERGUI_OCCSelector* selector() const
137   {
138     return mySelector;
139   }
140
141   /// Update current viewer
142   virtual void update();
143
144   /// Method returns True if the viewer can process editing objects
145   /// by mouse drugging. If this is impossible thet it has to return False.
146   virtual bool canDragByMouse() const;
147
148   /// Activate or deactivate viewer
149   /// \param toActivate - activation flag
150   void activateViewer(bool toActivate);
151
152   // Fit all along Z (perpendicular to display)
153   virtual void Zfitall();
154
155  private slots:
156   void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
157   void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
158   void onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*);
159   void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
160   void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
161   void onKeyRelease(SUIT_ViewWindow*, QKeyEvent*);
162
163   void onTryCloseView(SUIT_ViewWindow*);
164   void onDeleteView(SUIT_ViewWindow*);
165   void onViewCreated(SUIT_ViewWindow*);
166   void onActivated(SUIT_ViewManager*);
167
168   void onSelectionChanged();
169   void onViewTransformed(OCCViewer_ViewWindow::OperationType);
170
171   /// Emit signal about trihedron visiblity change because SALOME sets
172   /// the trihedron visible by this signal.
173   /// It is necessary to activate the viewer trihedron in the current selection mode
174   void onViewPortMapped();
175
176  private:
177   SHAPERGUI_OCCSelector* mySelector;
178   SHAPERGUI_SalomeView* myView;
179   bool myIsSelectionChanged;
180 };
181
182
183 #endif