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;
36 class OCCViewer_Fitter;
38 class AppElements_Fitter;
43 * A Base object for definition of connector object to
44 * Salome Viewer. Reimplemented in SHAPERGUI_SalomeViewer class
46 class MODULEBASE_EXPORT ModuleBase_IViewer : public QObject
51 /// \param theParent a parent object
52 ModuleBase_IViewer(QObject* theParent);
54 //! Returns AIS_InteractiveContext from current OCCViewer
55 virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
57 //! Trihedron 3d object shown in the viewer
58 virtual Handle(AIS_Trihedron) trihedron() const = 0;
60 //! Retrurns V3d_Vioewer from current viewer
61 virtual Handle(V3d_Viewer) v3dViewer() const = 0;
63 //! Returns Vsd_View object from currently active view window
64 virtual Handle(V3d_View) activeView() const = 0;
66 //! Returns currently active view port widget
67 virtual QWidget* activeViewPort() const = 0;
69 //! Enable or disable selection in the viewer
70 //! \param isEnabled is enable or disable flag
71 virtual void enableSelection(bool isEnabled) = 0;
73 //! Returns true if selection is enabled
74 virtual bool isSelectionEnabled() const = 0;
76 //! Enable or disable multiselection in the viewer
77 //! \param isEnable is enable or disable flag
78 virtual void enableMultiselection(bool isEnable) = 0;
80 //! Returns true if multiselection is enabled
81 virtual bool isMultiSelectionEnabled() const = 0;
83 //! Enable or disable draw mode in the viewer
84 virtual bool enableDrawMode(bool isEnabled) = 0;
86 //! Perfroms the fit all for the active view
87 virtual void fitAll() = 0;
89 //! Erases all presentations from the viewer
90 virtual void eraseAll() = 0;
92 //! Sets the view projection
93 /// \param theX the X projection value
94 /// \param theY the Y projection value
95 /// \param theZ the Z projection value
96 /// \param theTwist the twist angle in radians
97 virtual void setViewProjection( double theX, double theY, double theZ,
98 double theTwist ) = 0;
100 /// Add selection filter to the viewer
101 /// \param theFilter a selection filter
102 virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
104 /// Remove selection filter from the viewer
105 /// \param theFilter a selection filter
106 virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
108 /// Returns true if the selection filter is set to the viewer
109 /// \param theFilter a selection filter
110 virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
112 /// Update current viewer
113 virtual void update() = 0;
115 /// Returns a scale factor of the given view
116 /// \param theView a view object
117 const double Scale(const Handle(V3d_View)& theView)
119 if (!myWindowScale.contains(theView))
120 myWindowScale.insert(theView, theView->Camera()->Scale());
121 return myWindowScale[theView];
124 /// Remember a scale factor for the view object
125 /// \param theView a view object
126 /// \param theVal a scale factor
127 void SetScale(const Handle(V3d_View)& theView, const double theVal)
128 { myWindowScale[theView] = theVal; }
130 /// Method returns True if the viewer can process editing objects
131 /// by mouse drugging. If this is impossible thet it has to return False.
132 virtual bool canDragByMouse() const { return true; }
134 /// Fit all along Z (perpendicular to display)
135 //virtual void Zfitall() = 0;
137 /// Show highlight for pre-highlighted sub-shape
138 virtual void updateHighlight() {}
140 /// Set flag which indicates that viewer is used for 2d operations
141 /// \param is2d a new 2d mode state
142 void set2dMode(bool is2d) {
146 /// Returns current state of 2d mode flag
147 bool is2dMode() const {
151 // Methods for color scale management
153 //! Returns True if ColorScale is visible
154 virtual bool isColorScaleVisible() const = 0;
156 //! Show/Hide ColorScale object
157 virtual void setColorScaleShown(bool on) = 0;
159 //! Set position of color scale
160 // \param theX is X position relative to current view width
161 // \param theY is Y position relative to current view heigth
162 virtual void setColorScalePosition(double theX, double theY) = 0;
164 //! Set size of color scale
165 // \param theW is width relative to current view width
166 // \param theh is height relative to current view heigth
167 virtual void setColorScaleSize(double theW, double theH) = 0;
169 //! Set range of color scale
170 // \param theMin is a minimal value
171 // \param theMax is a maximal value
172 virtual void setColorScaleRange(double theMin, double theMax) = 0;
174 //! Set number of intervals of color scale
175 // \param theNb is number of intervals
176 virtual void setColorScaleIntervals(int theNb) = 0;
178 //! Set text heigth of color scale
179 // \param theH is number of intervals
180 virtual void setColorScaleTextHeigth(int theH) = 0;
182 //! Set color of text of color scale
183 // \param theH is number of intervals
184 virtual void setColorScaleTextColor(const QColor& theColor) = 0;
186 //! Set title of color scale
187 // \param theText is a title
188 virtual void setColorScaleTitle(const QString& theText) = 0;
190 /// Switches On additional highlight for objects preselection
191 void showSelectionHighlight() {
192 myShowHighlight = true;
195 /// Switches Off additional highlight for objects preselection
196 void hideSelectionHighlight() {
197 myShowHighlight = false;
201 virtual void setFitter(OCCViewer_Fitter* theFitter) = 0;
202 virtual OCCViewer_Fitter* fitter() const = 0;
204 virtual void setFitter(AppElements_Fitter* theFitter) = 0;
205 virtual AppElements_Fitter* fitter() const = 0;
208 static Handle(Prs3d_Drawer) DefaultHighlightDrawer;
212 /// Signal emited when last view window is closed
213 void lastViewClosed();
215 /// Signal emited before view window is closed
216 void tryCloseView(ModuleBase_IViewWindow* theWnd);
218 /// Signal emited on delete view window
219 void deleteView(ModuleBase_IViewWindow* theWnd);
221 /// Signal emited on creation of view window
222 void viewCreated(ModuleBase_IViewWindow* theWnd);
224 /// Signal emited on key release
225 void activated(ModuleBase_IViewWindow* theWnd);
227 /// Signal emited on mouse press
228 void mousePress(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
230 /// Signal emited on mouse release
231 void mouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
233 /// Signal emited on mouse double click
234 void mouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
236 /// Signal emited on mouse move
237 void mouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
239 /// Signal emited on key press
240 void keyPress(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
242 /// Signal emited on key release
243 void keyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
245 /// Signal emited on selection changed
246 void selectionChanged();
248 /// Signal emited on selection changed
249 void contextMenuRequested(QContextMenuEvent*);
251 /// Signal emitted on transformation of view point in view window
252 /// \param theTransformation type of transformation (see AppElements_ViewWindow::OperationType)
253 void viewTransformed(int theTransformation);
255 /// Signal emited on selection changed
256 void trihedronVisibilityChanged(bool theState);
259 /// A map for storing a scale factors dependent on view object
260 QMap<Handle(V3d_View), double> myWindowScale;
264 bool myShowHighlight;