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 /// Set flag which indicates that viewer is used for 2d operations
135 /// \param is2d a new 2d mode state
136 void set2dMode(bool is2d) {
140 /// Returns current state of 2d mode flag
141 bool is2dMode() const {
145 // Methods for color scale management
147 //! Returns True if ColorScale is visible
148 virtual bool isColorScaleVisible() const = 0;
150 //! Show/Hide ColorScale object
151 virtual void setColorScaleShown(bool on) = 0;
153 //! Set position of color scale
154 // \param theX is X position relative to current view width
155 // \param theY is Y position relative to current view heigth
156 virtual void setColorScalePosition(double theX, double theY) = 0;
158 //! Set size of color scale
159 // \param theW is width relative to current view width
160 // \param theh is height relative to current view heigth
161 virtual void setColorScaleSize(double theW, double theH) = 0;
163 //! Set range of color scale
164 // \param theMin is a minimal value
165 // \param theMax is a maximal value
166 virtual void setColorScaleRange(double theMin, double theMax) = 0;
168 //! Set number of intervals of color scale
169 // \param theNb is number of intervals
170 virtual void setColorScaleIntervals(int theNb) = 0;
172 //! Set text heigth of color scale
173 // \param theH is number of intervals
174 virtual void setColorScaleTextHeigth(int theH) = 0;
176 //! Set color of text of color scale
177 // \param theH is number of intervals
178 virtual void setColorScaleTextColor(const QColor& theColor) = 0;
180 //! Set title of color scale
181 // \param theText is a title
182 virtual void setColorScaleTitle(const QString& theText) = 0;
184 /// Switches On additional highlight for objects preselection
185 void showSelectionHighlight() {
186 myShowHighlight = true;
189 /// Switches Off additional highlight for objects preselection
190 void hideSelectionHighlight() {
191 myShowHighlight = false;
194 static Handle(Prs3d_Drawer) DefaultHighlightDrawer;
197 /// Signal emited when last view window is closed
198 void lastViewClosed();
200 /// Signal emited before view window is closed
201 void tryCloseView(ModuleBase_IViewWindow* theWnd);
203 /// Signal emited on delete view window
204 void deleteView(ModuleBase_IViewWindow* theWnd);
206 /// Signal emited on creation of view window
207 void viewCreated(ModuleBase_IViewWindow* theWnd);
209 /// Signal emited on key release
210 void activated(ModuleBase_IViewWindow* theWnd);
212 /// Signal emited on mouse press
213 void mousePress(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
215 /// Signal emited on mouse release
216 void mouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
218 /// Signal emited on mouse double click
219 void mouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
221 /// Signal emited on mouse move
222 void mouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
224 /// Signal emited on key press
225 void keyPress(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
227 /// Signal emited on key release
228 void keyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
230 /// Signal emited on selection changed
231 void selectionChanged();
233 /// Signal emited on selection changed
234 void contextMenuRequested(QContextMenuEvent*);
236 /// Signal emitted on transformation of view point in view window
237 /// \param theTransformation type of transformation (see AppElements_ViewWindow::OperationType)
238 void viewTransformed(int theTransformation);
240 /// Signal emited on selection changed
241 void trihedronVisibilityChanged(bool theState);
244 /// A map for storing a scale factors dependent on view object
245 QMap<Handle(V3d_View), double> myWindowScale;
249 bool myShowHighlight;