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