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