Salome HOME
Merge with Dev_1.5.0
[modules/shaper.git] / src / NewGeom / NewGeom_SalomeViewer.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3
4 #ifndef NewGeom_SalomeViewer_H
5 #define NewGeom_SalomeViewer_H
6
7 #include "NewGeom.h"
8
9 #include <ModuleBase_IViewer.h>
10 #include <ModuleBase_IViewWindow.h>
11
12 #include <OCCViewer_ViewWindow.h>
13
14 #include <V3d_View.hxx>
15
16 class SUIT_ViewWindow;
17 class QMouseEvent;
18 class QKeyEvent;
19
20 class NewGeom_OCCSelector;
21 class OCCViewer_Viewer;
22 class SUIT_ViewManager;
23
24 /**
25 * \ingroup Salome
26 * A class for providing access of NewGeom functionality to 
27 * SALOME view window functionality
28 */
29 class NewGeom_SalomeView: public ModuleBase_IViewWindow
30 {
31 public:
32   /// Constructor
33   /// \param theViewer a reference to a viewer
34   NewGeom_SalomeView(OCCViewer_Viewer* theViewer);
35
36   virtual Handle(V3d_View) v3dView() const;
37
38   /// Returns the view window view port
39   virtual QWidget* viewPort() const;
40
41   /// Set the current viewer
42   /// \param theViewer a viewer instance
43   void setViewer(OCCViewer_Viewer* theViewer) { myViewer = theViewer; }
44
45   /// Returns current viewer
46   OCCViewer_Viewer* viewer() const { return myViewer; }
47
48   /// Sets the current view
49   void setCurrentView(SUIT_ViewWindow* theView) { myCurrentView = theView; }
50
51 private:
52   /// A reference to a viewer
53   OCCViewer_Viewer* myViewer;
54   SUIT_ViewWindow* myCurrentView;
55 };
56
57
58 /**
59 * \ingroup Salome
60 * A class for providing access of NewGeom functionality to 
61 * SALOME viewer functionality
62 */
63 class NewGeom_SalomeViewer : public ModuleBase_IViewer
64 {
65 Q_OBJECT
66  public:
67    /// Constructor
68    /// \param theParent a parent object
69   NewGeom_SalomeViewer(QObject* theParent);
70
71   ~NewGeom_SalomeViewer();
72
73   //! Returns AIS_InteractiveContext from current OCCViewer
74   virtual Handle(AIS_InteractiveContext) AISContext() const;
75
76   //! Retrurns V3d_Vioewer from current viewer
77   virtual Handle(V3d_Viewer) v3dViewer() const;
78
79   //! Returns Vsd_View object from currently active view window
80   virtual Handle(V3d_View) activeView() const;
81
82   //! Enable or disable selection in the viewer
83   virtual void enableSelection(bool isEnabled);
84
85   //! Returns true if selection is enabled
86   virtual bool isSelectionEnabled() const;
87
88   //! Enable or disable multiselection in the viewer
89   virtual void enableMultiselection(bool isEnable);
90
91   //! Returns true if multiselection is enabled
92   virtual bool isMultiSelectionEnabled() const;
93
94   //! Enable or disable draw mode in the viewer
95   virtual bool enableDrawMode(bool isEnabled);
96
97   //! Perfroms the fit all for the active view
98   virtual void fitAll();
99
100   //! Sets the view projection
101   /// \param theX the X projection value
102   /// \param theY the Y projection value
103   /// \param theZ the Z projection value
104   /// \param theTwist the twist angle in radians
105   virtual void setViewProjection( double theX, double theY, double theZ,
106                                   double theTwist );
107
108   /// Set selector
109   /// \param theSel a selector instance
110   void setSelector(NewGeom_OCCSelector* theSel);
111
112   /// Add selection filter to the viewer
113   virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
114
115   /// Remove selection filter from the viewer
116   virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
117
118   /// Returns true if the selection filter is set to the viewer
119   /// \param theFilter a selection filter
120   virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
121
122   /// Remove all selection filters from the viewer
123   virtual void clearSelectionFilters();
124
125   /// Returns current selector
126   NewGeom_OCCSelector* selector() const
127   {
128     return mySelector;
129   }
130
131   /// Update current viewer
132   virtual void update();
133
134   /// Method returns True if the viewer can process editing objects 
135   /// by mouse drugging. If this is impossible thet it has to return False.
136   virtual bool canDragByMouse() const;
137
138   /// Activate or deactivate viewer
139   /// \param toActivate - activation flag
140   void activateViewer(bool toActivate);
141
142   // Fit all along Z (perpendicular to display)
143   virtual void Zfitall();
144
145  private slots:
146   void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
147   void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
148   void onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*);
149   void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
150   void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
151   void onKeyRelease(SUIT_ViewWindow*, QKeyEvent*);
152
153   void onTryCloseView(SUIT_ViewWindow*);
154   void onDeleteView(SUIT_ViewWindow*);
155   void onViewCreated(SUIT_ViewWindow*);
156   void onActivated(SUIT_ViewManager*);
157
158   void onSelectionChanged();
159   void onViewTransformed(OCCViewer_ViewWindow::OperationType);
160
161  private:
162   NewGeom_OCCSelector* mySelector;
163   NewGeom_SalomeView* myView;
164   bool myIsSelectionChanged;
165 };
166
167
168 #endif