1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef SHAPERGUI_SalomeViewer_H
22 #define SHAPERGUI_SalomeViewer_H
24 #include "SHAPER_SHAPERGUI.h"
26 #include <ModuleBase_IViewer.h>
27 #include <ModuleBase_IViewWindow.h>
29 #include <OCCViewer_ViewWindow.h>
31 #include <V3d_View.hxx>
32 #include <AIS_Trihedron.hxx>
34 class SUIT_ViewWindow;
38 class SHAPERGUI_OCCSelector;
39 class OCCViewer_Viewer;
40 class SUIT_ViewManager;
44 * A class for providing access of SHAPERGUI functionality to
45 * SALOME view window functionality
47 class SHAPERGUI_SalomeView: public ModuleBase_IViewWindow
51 /// \param theViewer a reference to a viewer
52 SHAPERGUI_SalomeView(OCCViewer_Viewer* theViewer);
54 virtual Handle(V3d_View) v3dView() const;
56 /// Returns the view window view port
57 virtual QWidget* viewPort() const;
59 /// Set the current viewer
60 /// \param theViewer a viewer instance
61 void setViewer(OCCViewer_Viewer* theViewer) { myViewer = theViewer; }
63 /// Returns current viewer
64 OCCViewer_Viewer* viewer() const { return myViewer; }
66 /// Sets the current view
67 void setCurrentView(SUIT_ViewWindow* theView) { myCurrentView = theView; }
70 /// A reference to a viewer
71 OCCViewer_Viewer* myViewer;
72 SUIT_ViewWindow* myCurrentView;
78 * A class for providing access of SHAPERGUI functionality to
79 * SALOME viewer functionality
81 class SHAPERGUI_SalomeViewer : public ModuleBase_IViewer
86 /// \param theParent a parent object
87 SHAPERGUI_SalomeViewer(QObject* theParent);
89 ~SHAPERGUI_SalomeViewer();
91 //! Returns AIS_InteractiveContext from current OCCViewer
92 virtual Handle(AIS_InteractiveContext) AISContext() const;
94 //! Retrurns V3d_Vioewer from current viewer
95 virtual Handle(V3d_Viewer) v3dViewer() const;
97 //! Trihedron 3d object shown in the viewer
98 virtual Handle(AIS_Trihedron) trihedron() const;
100 //! Returns Vsd_View object from currently active view window
101 virtual Handle(V3d_View) activeView() const;
103 //! Returns viewer view port
104 virtual QWidget* activeViewPort() const;
106 //! Enable or disable selection in the viewer
107 virtual void enableSelection(bool isEnabled);
109 //! Returns true if selection is enabled
110 virtual bool isSelectionEnabled() const;
112 //! Enable or disable multiselection in the viewer
113 virtual void enableMultiselection(bool isEnable);
115 //! Returns true if multiselection is enabled
116 virtual bool isMultiSelectionEnabled() const;
118 //! Enable or disable draw mode in the viewer
119 virtual bool enableDrawMode(bool isEnabled);
121 //! For some signals it disconnects the window from usual signal and connect it to the module ones
122 void reconnectActions(SUIT_ViewWindow* theWindow, const bool theUseSHAPERSlot);
124 //! Perfroms the fit all for the active view
125 virtual void fitAll();
127 //! Erases all presentations from the viewer
128 virtual void eraseAll();
130 //! Sets the view projection
131 /// \param theX the X projection value
132 /// \param theY the Y projection value
133 /// \param theZ the Z projection value
134 /// \param theTwist the twist angle in radians
135 virtual void setViewProjection( double theX, double theY, double theZ,
139 /// \param theSel a selector instance
140 void setSelector(SHAPERGUI_OCCSelector* theSel);
142 /// Add selection filter to the viewer
143 virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
145 /// Remove selection filter from the viewer
146 virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
148 /// Returns true if the selection filter is set to the viewer
149 /// \param theFilter a selection filter
150 virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
152 /// Remove all selection filters from the viewer
153 virtual void clearSelectionFilters();
155 /// Returns current selector
156 SHAPERGUI_OCCSelector* selector() const
161 /// Update current viewer
162 virtual void update();
164 /// Method returns True if the viewer can process editing objects
165 /// by mouse drugging. If this is impossible thet it has to return False.
166 virtual bool canDragByMouse() const;
168 /// Activate or deactivate viewer
169 /// \param toActivate - activation flag
170 void activateViewer(bool toActivate);
172 // Fit all along Z (perpendicular to display)
173 //virtual void Zfitall();
176 void onMousePress(SUIT_ViewWindow*, QMouseEvent*);
177 void onMouseRelease(SUIT_ViewWindow*, QMouseEvent*);
178 void onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*);
179 void onMouseMove(SUIT_ViewWindow*, QMouseEvent*);
180 void onKeyPress(SUIT_ViewWindow*, QKeyEvent*);
181 void onKeyRelease(SUIT_ViewWindow*, QKeyEvent*);
183 void onTryCloseView(SUIT_ViewWindow*);
184 void onDeleteView(SUIT_ViewWindow*);
185 void onViewCreated(SUIT_ViewWindow*);
186 void onActivated(SUIT_ViewManager*);
188 void onSelectionChanged();
189 void onViewTransformed(OCCViewer_ViewWindow::OperationType);
191 /// Emit signal about trihedron visiblity change because SALOME sets
192 /// the trihedron visible by this signal.
193 /// It is necessary to activate the viewer trihedron in the current selection mode
194 void onViewPortMapped();
197 SHAPERGUI_OCCSelector* mySelector;
198 SHAPERGUI_SalomeView* myView;
199 bool myIsSelectionChanged;