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"
27 #include <AIS_InteractiveContext.hxx>
28 #include <V3d_View.hxx>
29 #include <AIS_Trihedron.hxx>
33 class QContextMenuEvent;
34 class ModuleBase_IViewWindow;
38 * A Base object for definition of connector object to
39 * Salome Viewer. Reimplemented in SHAPERGUI_SalomeViewer class
41 class MODULEBASE_EXPORT ModuleBase_IViewer : public QObject
46 /// \param theParent a parent object
47 ModuleBase_IViewer(QObject* theParent);
49 //! Returns AIS_InteractiveContext from current OCCViewer
50 virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
52 //! Trihedron 3d object shown in the viewer
53 virtual Handle(AIS_Trihedron) trihedron() const = 0;
55 //! Retrurns V3d_Vioewer from current viewer
56 virtual Handle(V3d_Viewer) v3dViewer() const = 0;
58 //! Returns Vsd_View object from currently active view window
59 virtual Handle(V3d_View) activeView() const = 0;
61 //! Returns currently active view port widget
62 virtual QWidget* activeViewPort() const = 0;
64 //! Enable or disable selection in the viewer
65 //! \param isEnabled is enable or disable flag
66 virtual void enableSelection(bool isEnabled) = 0;
68 //! Returns true if selection is enabled
69 virtual bool isSelectionEnabled() const = 0;
71 //! Enable or disable multiselection in the viewer
72 //! \param isEnable is enable or disable flag
73 virtual void enableMultiselection(bool isEnable) = 0;
75 //! Returns true if multiselection is enabled
76 virtual bool isMultiSelectionEnabled() const = 0;
78 //! Enable or disable draw mode in the viewer
79 virtual bool enableDrawMode(bool isEnabled) = 0;
81 //! Perfroms the fit all for the active view
82 virtual void fitAll() = 0;
84 //! Erases all presentations from the viewer
85 virtual void eraseAll() = 0;
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;
95 /// Add selection filter to the viewer
96 /// \param theFilter a selection filter
97 virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
99 /// Remove selection filter from the viewer
100 /// \param theFilter a selection filter
101 virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
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;
107 /// Update current viewer
108 virtual void update() = 0;
110 /// Returns a scale factor of the given view
111 /// \param theView a view object
112 const double Scale(const Handle(V3d_View)& theView)
114 if (!myWindowScale.contains(theView))
115 myWindowScale.insert(theView, theView->Camera()->Scale());
116 return myWindowScale[theView];
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; }
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; }
129 /// Fit all along Z (perpendicular to display)
130 //virtual void Zfitall() = 0;
132 /// Show highlight for pre-highlighted sub-shape
133 virtual void updateHighlight() {}
135 /// Set flag which indicates that viewer is used for 2d operations
136 /// \param is2d a new 2d mode state
137 void set2dMode(bool is2d) {
141 /// Returns current state of 2d mode flag
142 bool is2dMode() const {
146 // Methods for color scale management
148 //! Returns True if ColorScale is visible
149 virtual bool isColorScaleVisible() const = 0;
151 //! Show/Hide ColorScale object
152 virtual void setColorScaleShown(bool on) = 0;
154 //! Set position of color scale
155 // \param theX is X position relative to current view width
156 // \param theY is Y position relative to current view heigth
157 virtual void setColorScalePosition(double theX, double theY) = 0;
159 //! Set size of color scale
160 // \param theW is width relative to current view width
161 // \param theh is height relative to current view heigth
162 virtual void setColorScaleSize(double theW, double theH) = 0;
164 //! Set range of color scale
165 // \param theMin is a minimal value
166 // \param theMax is a maximal value
167 virtual void setColorScaleRange(double theMin, double theMax) = 0;
169 //! Set number of intervals of color scale
170 // \param theNb is number of intervals
171 virtual void setColorScaleIntervals(int theNb) = 0;
173 //! Set text heigth of color scale
174 // \param theH is number of intervals
175 virtual void setColorScaleTextHeigth(int theH) = 0;
177 //! Set color of text of color scale
178 // \param theH is number of intervals
179 virtual void setColorScaleTextColor(const QColor& theColor) = 0;
181 //! Set title of color scale
182 // \param theText is a title
183 virtual void setColorScaleTitle(const QString& theText) = 0;
185 /// Switches On additional highlight for objects preselection
186 void showSelectionHighlight() {
187 myShowHighlight = true;
190 /// Switches Off additional highlight for objects preselection
191 void hideSelectionHighlight() {
192 myShowHighlight = false;
195 static Handle(Prs3d_Drawer) DefaultHighlightDrawer;
198 /// Signal emited when last view window is closed
199 void lastViewClosed();
201 /// Signal emited before view window is closed
202 void tryCloseView(ModuleBase_IViewWindow* theWnd);
204 /// Signal emited on delete view window
205 void deleteView(ModuleBase_IViewWindow* theWnd);
207 /// Signal emited on creation of view window
208 void viewCreated(ModuleBase_IViewWindow* theWnd);
210 /// Signal emited on key release
211 void activated(ModuleBase_IViewWindow* theWnd);
213 /// Signal emited on mouse press
214 void mousePress(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
216 /// Signal emited on mouse release
217 void mouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
219 /// Signal emited on mouse double click
220 void mouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
222 /// Signal emited on mouse move
223 void mouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
225 /// Signal emited on key press
226 void keyPress(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
228 /// Signal emited on key release
229 void keyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
231 /// Signal emited on selection changed
232 void selectionChanged();
234 /// Signal emited on selection changed
235 void contextMenuRequested(QContextMenuEvent*);
237 /// Signal emitted on transformation of view point in view window
238 /// \param theTransformation type of transformation (see AppElements_ViewWindow::OperationType)
239 void viewTransformed(int theTransformation);
241 /// Signal emited on selection changed
242 void trihedronVisibilityChanged(bool theState);
245 /// A map for storing a scale factors dependent on view object
246 QMap<Handle(V3d_View), double> myWindowScale;
250 bool myShowHighlight;