SHAPER  9.12.0
ModuleBase_IViewer.h
1 // Copyright (C) 2014-2023 CEA, EDF
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 email : webmaster.salome@opencascade.com
18 //
19 
20 #ifndef ModuleBase_IViewer_H
21 #define ModuleBase_IViewer_H
22 
23 #include "ModuleBase.h"
24 
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;
35 #ifdef HAVE_SALOME
36 class OCCViewer_Fitter;
37 #else
38 class AppElements_Fitter;
39 #endif
40 
46 class MODULEBASE_EXPORT ModuleBase_IViewer : public QObject
47 {
48 Q_OBJECT
49  public:
52  ModuleBase_IViewer(QObject* theParent);
53 
55  virtual Handle(AIS_InteractiveContext) AISContext() const = 0;
56 
58  virtual Handle(AIS_Trihedron) trihedron() const = 0;
59 
61  virtual Handle(V3d_Viewer) v3dViewer() const = 0;
62 
64  virtual Handle(V3d_View) activeView() const = 0;
65 
67  virtual QWidget* activeViewPort() const = 0;
68 
71  virtual void enableSelection(bool isEnabled) = 0;
72 
74  virtual bool isSelectionEnabled() const = 0;
75 
78  virtual void enableMultiselection(bool isEnable) = 0;
79 
81  virtual bool isMultiSelectionEnabled() const = 0;
82 
84  virtual bool enableDrawMode(bool isEnabled) = 0;
85 
87  virtual void fitAll() = 0;
88 
90  virtual void eraseAll() = 0;
91 
97  virtual void setViewProjection( double theX, double theY, double theZ,
98  double theTwist ) = 0;
99 
102  virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
103 
106  virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
107 
110  virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0;
111 
113  virtual void update() = 0;
114 
117  const double Scale(const Handle(V3d_View)& theView)
118  {
119  if (!myWindowScale.contains(theView))
120  myWindowScale.insert(theView, theView->Camera()->Scale());
121  return myWindowScale[theView];
122  }
123 
127  void SetScale(const Handle(V3d_View)& theView, const double theVal)
128  { myWindowScale[theView] = theVal; }
129 
132  virtual bool canDragByMouse() const { return true; }
133 
135  //virtual void Zfitall() = 0;
136 
138  virtual void updateHighlight() {}
139 
142  void set2dMode(bool is2d) {
143  myIs2dMode = is2d;
144  }
145 
147  bool is2dMode() const {
148  return myIs2dMode;
149  }
150 
151  // Methods for color scale management
152 
154  virtual bool isColorScaleVisible() const = 0;
155 
157  virtual void setColorScaleShown(bool on) = 0;
158 
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;
163 
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;
168 
170  // \param theMin is a minimal value
171  // \param theMax is a maximal value
172  virtual void setColorScaleRange(double theMin, double theMax) = 0;
173 
175  // \param theNb is number of intervals
176  virtual void setColorScaleIntervals(int theNb) = 0;
177 
179  // \param theH is number of intervals
180  virtual void setColorScaleTextHeigth(int theH) = 0;
181 
183  // \param theH is number of intervals
184  virtual void setColorScaleTextColor(const QColor& theColor) = 0;
185 
187  // \param theText is a title
188  virtual void setColorScaleTitle(const QString& theText) = 0;
189 
191  typedef std::list<std::pair<std::wstring, std::vector<int> > > TextColor;
192 
197  virtual void setText(const TextColor& theText, const int theSize) = 0;
198 
199 
202  myShowHighlight = true;
203  }
204 
207  myShowHighlight = false;
208  }
209 
210 #ifdef HAVE_SALOME
211  virtual void setFitter(OCCViewer_Fitter* theFitter) = 0;
212  virtual OCCViewer_Fitter* fitter() const = 0;
213 #else
214  virtual void setFitter(AppElements_Fitter* theFitter) = 0;
215  virtual AppElements_Fitter* fitter() const = 0;
216 #endif
217 
218  static Handle(Prs3d_Drawer) DefaultHighlightDrawer;
219 
220 
221 signals:
224 
227 
230 
233 
236 
238  void mousePress(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
239 
241  void mouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
242 
244  void mouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
245 
247  void mouseMove(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);
248 
250  void keyPress(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
251 
253  void keyRelease(ModuleBase_IViewWindow* theWnd, QKeyEvent* theEvent);
254 
257 
259  void contextMenuRequested(QContextMenuEvent*);
260 
263  void viewTransformed(int theTransformation);
264 
266  void trihedronVisibilityChanged(bool theState);
267 
268  protected:
270  QMap<Handle(V3d_View), double> myWindowScale;
271 
272  bool myIs2dMode;
273 
274  bool myShowHighlight;
275 };
276 
277 #endif
Interface to ViewWindow object which contains 3d scene.
Definition: ModuleBase_IViewWindow.h:34
A Base object for definition of connector object to Salome Viewer.
Definition: ModuleBase_IViewer.h:47
virtual bool canDragByMouse() const
Method returns True if the viewer can process editing objects by mouse drugging.
Definition: ModuleBase_IViewer.h:132
virtual void fitAll()=0
Perfroms the fit all for the active view.
virtual void setColorScaleTitle(const QString &theText)=0
Set title of color scale.
virtual void enableSelection(bool isEnabled)=0
Enable or disable selection in the viewer.
const double Scale(const Handle &&theView)
Returns a scale factor of the given view.
Definition: ModuleBase_IViewer.h:117
virtual void setColorScaleShown(bool on)=0
Show/Hide ColorScale object.
virtual void setColorScaleTextHeigth(int theH)=0
Set text heigth of color scale.
virtual void update()=0
Update current viewer.
void mousePress(ModuleBase_IViewWindow *theWnd, QMouseEvent *theEvent)
Signal emited on mouse press.
void contextMenuRequested(QContextMenuEvent *)
Signal emited on selection changed.
void viewTransformed(int theTransformation)
Signal emitted on transformation of view point in view window.
virtual void setColorScaleSize(double theW, double theH)=0
Set size of color scale.
virtual bool enableDrawMode(bool isEnabled)=0
Enable or disable draw mode in the viewer.
virtual void setColorScaleRange(double theMin, double theMax)=0
Set range of color scale.
QMap< Handle,, double > myWindowScale
A map for storing a scale factors dependent on view object.
Definition: ModuleBase_IViewer.h:270
void selectionChanged()
Signal emited on selection changed.
void viewCreated(ModuleBase_IViewWindow *theWnd)
Signal emited on creation of view window.
void SetScale(const Handle &&theView, const double theVal)
Remember a scale factor for the view object.
Definition: ModuleBase_IViewer.h:127
bool is2dMode() const
Returns current state of 2d mode flag.
Definition: ModuleBase_IViewer.h:147
void tryCloseView(ModuleBase_IViewWindow *theWnd)
Signal emited before view window is closed.
void showSelectionHighlight()
Switches On additional highlight for objects preselection.
Definition: ModuleBase_IViewer.h:201
virtual void setColorScaleIntervals(int theNb)=0
Set number of intervals of color scale.
void mouseDoubleClick(ModuleBase_IViewWindow *theWnd, QMouseEvent *theEvent)
Signal emited on mouse double click.
void trihedronVisibilityChanged(bool theState)
Signal emited on selection changed.
virtual void addSelectionFilter(const Handle &&theFilter)=0
Add selection filter to the viewer.
virtual void setColorScaleTextColor(const QColor &theColor)=0
Set color of text of color scale.
void keyPress(ModuleBase_IViewWindow *theWnd, QKeyEvent *theEvent)
Signal emited on key press.
virtual void updateHighlight()
Fit all along Z (perpendicular to display)
Definition: ModuleBase_IViewer.h:138
virtual bool hasSelectionFilter(const Handle &&theFilter)=0
Returns true if the selection filter is set to the viewer.
virtual void setColorScalePosition(double theX, double theY)=0
Set position of color scale.
virtual bool isSelectionEnabled() const =0
Returns true if selection is enabled.
void set2dMode(bool is2d)
Set flag which indicates that viewer is used for 2d operations.
Definition: ModuleBase_IViewer.h:142
void lastViewClosed()
Signal emited when last view window is closed.
virtual void setText(const TextColor &theText, const int theSize)=0
Sets the text displayed in right-top corner of the 3D view.
virtual void removeSelectionFilter(const Handle &&theFilter)=0
Remove selection filter from the viewer.
virtual void eraseAll()=0
Erases all presentations from the viewer.
std::list< std::pair< std::wstring, std::vector< int > > > TextColor
Type for mapping from text to color to display the names lines in different colors.
Definition: ModuleBase_IViewer.h:191
virtual bool isColorScaleVisible() const =0
Returns True if ColorScale is visible.
void mouseRelease(ModuleBase_IViewWindow *theWnd, QMouseEvent *theEvent)
Signal emited on mouse release.
virtual QWidget * activeViewPort() const =0
Returns currently active view port widget.
virtual void setViewProjection(double theX, double theY, double theZ, double theTwist)=0
Sets the view projection.
virtual bool isMultiSelectionEnabled() const =0
Returns true if multiselection is enabled.
void keyRelease(ModuleBase_IViewWindow *theWnd, QKeyEvent *theEvent)
Signal emited on key release.
virtual void enableMultiselection(bool isEnable)=0
Enable or disable multiselection in the viewer.
void activated(ModuleBase_IViewWindow *theWnd)
Signal emited on key release.
void hideSelectionHighlight()
Switches Off additional highlight for objects preselection.
Definition: ModuleBase_IViewer.h:206
void mouseMove(ModuleBase_IViewWindow *theWnd, QMouseEvent *theEvent)
Signal emited on mouse move.
void deleteView(ModuleBase_IViewWindow *theWnd)
Signal emited on delete view window.