Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / ModuleBase / ModuleBase_IViewer.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF 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, or (at your option) any later version.
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/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #ifndef ModuleBase_IViewer_H
21 #define ModuleBase_IViewer_H
22
23 #include "ModuleBase.h"
24 #include <QObject>
25 #include <QMap>
26 #include <AIS_InteractiveContext.hxx>
27 #include <V3d_View.hxx>
28 #include <AIS_Trihedron.hxx>
29
30 class QMouseEvent;
31 class QKeyEvent;
32 class QContextMenuEvent;
33 class ModuleBase_IViewWindow;
34
35 /**
36  * \ingroup GUI
37  * A Base object for definition of connector object to
38  * Salome Viewer. Reimplemented in SHAPERGUI_SalomeViewer class
39  */
40 class MODULEBASE_EXPORT ModuleBase_IViewer : public QObject
41 {
42 Q_OBJECT
43  public:
44    /// Constructor
45    /// \param theParent a parent object
46   ModuleBase_IViewer(QObject* theParent);
47
48   //! Returns AIS_InteractiveContext from current OCCViewer
49   virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
50
51   //! Trihedron 3d object shown in the viewer
52   virtual Handle(AIS_Trihedron) trihedron() const = 0;
53
54   //! Retrurns V3d_Vioewer from current viewer
55   virtual Handle(V3d_Viewer) v3dViewer() const = 0;
56
57   //! Returns Vsd_View object from currently active view window
58   virtual Handle(V3d_View) activeView() const = 0;
59
60   //! Returns currently active view port widget
61   virtual QWidget* activeViewPort() const = 0;
62
63   //! Enable or disable selection in the viewer
64   //! \param isEnabled is enable or disable flag
65   virtual void enableSelection(bool isEnabled) = 0;
66
67   //! Returns true if selection is enabled
68   virtual bool isSelectionEnabled() const = 0;
69
70   //! Enable or disable multiselection in the viewer
71   //! \param isEnable is enable or disable flag
72   virtual void enableMultiselection(bool isEnable) = 0;
73
74   //! Returns true if multiselection is enabled
75   virtual bool isMultiSelectionEnabled() const = 0;
76
77   //! Enable or disable draw mode in the viewer
78   virtual bool enableDrawMode(bool isEnabled) = 0;
79
80   //! Perfroms the fit all for the active view
81   virtual void fitAll() = 0;
82
83   //! Erases all presentations from the viewer
84   virtual void eraseAll() = 0;
85
86   //! Sets the view projection
87   /// \param theX the X projection value
88   /// \param theY the Y projection value
89   /// \param theZ the Z projection value
90   /// \param theTwist the twist angle in radians
91   virtual void setViewProjection( double theX, double theY, double theZ,
92                                   double theTwist ) = 0;
93
94   /// Add selection filter to the viewer
95   /// \param theFilter a selection filter
96   virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
97
98   /// Remove selection filter from the viewer
99   /// \param theFilter a selection filter
100   virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
101
102   /// Returns true if the selection filter is set to the viewer
103   /// \param theFilter a selection filter
104   virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
105
106   /// Update current viewer
107   virtual void update() = 0;
108
109   /// Returns a scale factor of the given view
110   /// \param theView a view object
111   const double Scale(const Handle(V3d_View)& theView)
112   {
113     if (!myWindowScale.contains(theView))
114       myWindowScale.insert(theView, theView->Camera()->Scale());
115     return myWindowScale[theView];
116   }
117
118   /// Remember a scale factor for the view object
119   /// \param theView a view object
120   /// \param theVal a scale factor
121   void SetScale(const Handle(V3d_View)& theView, const double theVal)
122   { myWindowScale[theView] = theVal; }
123
124   /// Method returns True if the viewer can process editing objects
125   /// by mouse drugging. If this is impossible thet it has to return False.
126   virtual bool canDragByMouse() const { return true; }
127
128   /// Fit all along Z (perpendicular to display)
129   //virtual void Zfitall() = 0;
130
131 signals:
132   /// Signal emited when last view window is closed
133   void lastViewClosed();
134
135   /// Signal emited before view window is closed
136   void tryCloseView(ModuleBase_IViewWindow* theWnd);
137
138   /// Signal emited on delete view window
139   void deleteView(ModuleBase_IViewWindow* theWnd);
140
141   /// Signal emited on creation of view window
142   void viewCreated(ModuleBase_IViewWindow* theWnd);
143
144   /// Signal emited on key release
145   void activated(ModuleBase_IViewWindow* theWnd);
146
147   /// Signal emited on mouse press
148   void mousePress(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
149
150   /// Signal emited on mouse release
151   void mouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
152
153   /// Signal emited on mouse double click
154   void mouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
155
156   /// Signal emited on mouse move
157   void mouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
158
159   /// Signal emited on key press
160   void keyPress(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
161
162   /// Signal emited on key release
163   void keyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
164
165   /// Signal emited on selection changed
166   void selectionChanged();
167
168   /// Signal emited on selection changed
169   void contextMenuRequested(QContextMenuEvent*);
170
171   /// Signal emitted on transformation of view point in view window
172   /// \param theTransformation type of transformation (see AppElements_ViewWindow::OperationType)
173   void viewTransformed(int theTransformation);
174
175   /// Signal emited on selection changed
176   void trihedronVisibilityChanged(bool theState);
177
178   protected:
179     /// A map for storing a scale factors dependent on view object
180     QMap<Handle(V3d_View), double> myWindowScale;
181 };
182
183 #endif