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