1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef ModuleBase_IViewer_H
21 #define ModuleBase_IViewer_H
23 #include "ModuleBase.h"
26 #include <AIS_InteractiveContext.hxx>
27 #include <V3d_View.hxx>
28 #include <AIS_Trihedron.hxx>
32 class QContextMenuEvent;
33 class ModuleBase_IViewWindow;
37 * A Base object for definition of connector object to
38 * Salome Viewer. Reimplemented in SHAPERGUI_SalomeViewer class
40 class MODULEBASE_EXPORT ModuleBase_IViewer : public QObject
45 /// \param theParent a parent object
46 ModuleBase_IViewer(QObject* theParent);
48 //! Returns AIS_InteractiveContext from current OCCViewer
49 virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
51 //! Trihedron 3d object shown in the viewer
52 virtual Handle(AIS_Trihedron) trihedron() const = 0;
54 //! Retrurns V3d_Vioewer from current viewer
55 virtual Handle(V3d_Viewer) v3dViewer() const = 0;
57 //! Returns Vsd_View object from currently active view window
58 virtual Handle(V3d_View) activeView() const = 0;
60 //! Returns currently active view port widget
61 virtual QWidget* activeViewPort() const = 0;
63 //! Enable or disable selection in the viewer
64 //! \param isEnabled is enable or disable flag
65 virtual void enableSelection(bool isEnabled) = 0;
67 //! Returns true if selection is enabled
68 virtual bool isSelectionEnabled() const = 0;
70 //! Enable or disable multiselection in the viewer
71 //! \param isEnable is enable or disable flag
72 virtual void enableMultiselection(bool isEnable) = 0;
74 //! Returns true if multiselection is enabled
75 virtual bool isMultiSelectionEnabled() const = 0;
77 //! Enable or disable draw mode in the viewer
78 virtual bool enableDrawMode(bool isEnabled) = 0;
80 //! Perfroms the fit all for the active view
81 virtual void fitAll() = 0;
83 //! Erases all presentations from the viewer
84 virtual void eraseAll() = 0;
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;
94 /// Add selection filter to the viewer
95 /// \param theFilter a selection filter
96 virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
98 /// Remove selection filter from the viewer
99 /// \param theFilter a selection filter
100 virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
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;
106 /// Update current viewer
107 virtual void update() = 0;
109 /// Returns a scale factor of the given view
110 /// \param theView a view object
111 const double Scale(const Handle(V3d_View)& theView)
113 if (!myWindowScale.contains(theView))
114 myWindowScale.insert(theView, theView->Camera()->Scale());
115 return myWindowScale[theView];
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; }
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; }
128 /// Fit all along Z (perpendicular to display)
129 //virtual void Zfitall() = 0;
131 /// Show highlight for pre-highlighted sub-shape
132 virtual void updateHighlight() {}
134 static Handle(Prs3d_Drawer) DefaultHighlightDrawer;
137 /// Signal emited when last view window is closed
138 void lastViewClosed();
140 /// Signal emited before view window is closed
141 void tryCloseView(ModuleBase_IViewWindow* theWnd);
143 /// Signal emited on delete view window
144 void deleteView(ModuleBase_IViewWindow* theWnd);
146 /// Signal emited on creation of view window
147 void viewCreated(ModuleBase_IViewWindow* theWnd);
149 /// Signal emited on key release
150 void activated(ModuleBase_IViewWindow* theWnd);
152 /// Signal emited on mouse press
153 void mousePress(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
155 /// Signal emited on mouse release
156 void mouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
158 /// Signal emited on mouse double click
159 void mouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
161 /// Signal emited on mouse move
162 void mouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
164 /// Signal emited on key press
165 void keyPress(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
167 /// Signal emited on key release
168 void keyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
170 /// Signal emited on selection changed
171 void selectionChanged();
173 /// Signal emited on selection changed
174 void contextMenuRequested(QContextMenuEvent*);
176 /// Signal emitted on transformation of view point in view window
177 /// \param theTransformation type of transformation (see AppElements_ViewWindow::OperationType)
178 void viewTransformed(int theTransformation);
180 /// Signal emited on selection changed
181 void trihedronVisibilityChanged(bool theState);
184 /// A map for storing a scale factors dependent on view object
185 QMap<Handle(V3d_View), double> myWindowScale;