Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[modules/shaper.git] / src / XGUI / XGUI_ViewerProxy.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
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<mailto:webmaster.salome@opencascade.com>
18 //
19
20 #ifndef XGUI_VIEWERPROXY_H
21 #define XGUI_VIEWERPROXY_H
22
23 #include "XGUI.h"
24 #include <ModuleBase_IViewer.h>
25
26 #include <AIS_Trihedron.hxx>
27
28 #ifndef HAVE_SALOME
29   #include <AppElements_ViewWindow.h>
30 #endif
31
32 class XGUI_Workshop;
33 /**
34  * \ingroup GUI
35  * Proxy class which repersents or AppElements_Viewer or Salome Viewer
36  * dependently on current launching environment.
37  * It is reccomennded to use this class in operation for accessing to viewer 
38  * functionality instead of direct access to a viewer
39  */
40 class XGUI_EXPORT XGUI_ViewerProxy : public ModuleBase_IViewer
41 {
42 Q_OBJECT
43  public:
44    /// Constructor
45    /// \param theParent a parent object
46   XGUI_ViewerProxy(XGUI_Workshop* theParent);
47
48   /// Connects some signals to the viewer from the module connector
49   void connectViewProxy();
50
51   //! Returns AIS_InteractiveContext from current OCCViewer
52   virtual Handle(AIS_InteractiveContext) AISContext() const;
53
54   //! Trihedron 3d object shown in the viewer
55   virtual Handle(AIS_Trihedron) trihedron() const;
56
57   //! Retrurns V3d_Vioewer from current viewer
58   virtual Handle(V3d_Viewer) v3dViewer() const;
59
60   //! Returns Vsd_View object from currently active view window
61   virtual Handle(V3d_View) activeView() const;
62
63   virtual QWidget* activeViewPort() const;
64
65   //! Enable or disable selection in the viewer
66   virtual void enableSelection(bool isEnabled);
67
68   //! Returns true if selection is enabled
69   virtual bool isSelectionEnabled() const;
70
71   //! Enable or disable multiselection in the viewer
72   virtual void enableMultiselection(bool isEnable);
73
74   //! Returns true if multiselection is enabled
75   virtual bool isMultiSelectionEnabled() const;
76
77   //! Enable or disable draw mode in the viewer
78   virtual bool enableDrawMode(bool isEnabled);
79
80   //! Sets the view projection
81   /// \param theX the X projection value
82   /// \param theY the Y projection value
83   /// \param theZ the Z projection value
84   /// \param theTwist the twist angle in radians
85   virtual void setViewProjection( double theX, double theY, double theZ,
86                                   double theTwist );
87
88   //! Sets the view fitted all
89   virtual void fitAll();
90
91   //! Erases all presentations from the viewer
92   virtual void eraseAll();
93
94   /// Connects to a viewer according to current environment
95   void connectToViewer();
96
97   /// Add selection filter to the viewer
98   virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
99
100   /// Remove selection filter from the viewer
101   virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
102
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);
106
107   /// Remove all selection filters from the viewer
108   virtual void clearSelectionFilters();
109
110   /// Update current viewer
111   virtual void update();
112
113   /// Method returns True if the viewer can process editing objects
114   /// by mouse drugging. If this is impossible thet it has to return False.
115   virtual bool canDragByMouse() const;
116
117   // Fit all along Z (perpendicular to display)
118   //virtual void Zfitall();
119
120 signals:
121   /// Emits by mouse entering the view port
122   void enterViewPort();
123
124   /// Emits by mouse leaving of the view port
125   void leaveViewPort();
126
127 protected:
128   /// processes the application signals to catch the mouse leaving state of the main window
129   /// \param theObject
130   /// \param theEvent
131   bool eventFilter(QObject *theObject, QEvent *theEvent);
132
133 private slots:
134   void onViewCreated(ModuleBase_IViewWindow* theWnd);
135
136 #ifndef HAVE_SALOME
137   void onTryCloseView(AppElements_ViewWindow*);
138   void onDeleteView(AppElements_ViewWindow*);
139   void onViewCreated(AppElements_ViewWindow*);
140   void onActivated(AppElements_ViewWindow*);
141
142   void onMousePress(AppElements_ViewWindow*, QMouseEvent*);
143   void onMouseRelease(AppElements_ViewWindow*, QMouseEvent*);
144   void onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*);
145   void onMouseMove(AppElements_ViewWindow*, QMouseEvent*);
146
147   void onKeyPress(AppElements_ViewWindow*, QKeyEvent*);
148   void onKeyRelease(AppElements_ViewWindow*, QKeyEvent*);
149
150   void onViewTransformed(AppElements_ViewWindow::OperationType);
151 #endif
152
153  private:
154   XGUI_Workshop* myWorkshop;
155 };
156
157 #endif