1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #ifndef XGUI_VIEWERPROXY_H
21 #define XGUI_VIEWERPROXY_H
24 #include <ModuleBase_IViewer.h>
25 #include <ModelAPI_Feature.h>
26 #include <ModelAPI_Result.h>
28 #include <AIS_Trihedron.hxx>
29 #include <AIS_ListOfInteractive.hxx>
32 #include <OCCViewer_ViewModel.h>
34 #include <AppElements_Viewer.h>
35 #include <AppElements_ViewWindow.h>
43 * Proxy class which repersents or AppElements_Viewer or Salome Viewer
44 * dependently on current launching environment.
45 * It is reccomennded to use this class in operation for accessing to viewer
46 * functionality instead of direct access to a viewer
48 class XGUI_EXPORT XGUI_ViewerProxy : public ModuleBase_IViewer
53 /// \param theParent a parent object
54 XGUI_ViewerProxy(XGUI_Workshop* theParent);
56 /// Connects some signals to the viewer from the module connector
57 void connectViewProxy();
59 //! Returns AIS_InteractiveContext from current OCCViewer
60 virtual Handle(AIS_InteractiveContext) AISContext() const;
62 //! Trihedron 3d object shown in the viewer
63 virtual Handle(AIS_Trihedron) trihedron() const;
65 //! Retrurns V3d_Vioewer from current viewer
66 virtual Handle(V3d_Viewer) v3dViewer() const;
68 //! Returns Vsd_View object from currently active view window
69 virtual Handle(V3d_View) activeView() const;
71 virtual QWidget* activeViewPort() const;
73 //! Enable or disable selection in the viewer
74 virtual void enableSelection(bool isEnabled);
76 //! Returns true if selection is enabled
77 virtual bool isSelectionEnabled() const;
79 //! Enable or disable multiselection in the viewer
80 virtual void enableMultiselection(bool isEnable);
82 //! Returns true if multiselection is enabled
83 virtual bool isMultiSelectionEnabled() const;
85 //! Enable or disable draw mode in the viewer
86 virtual bool enableDrawMode(bool isEnabled);
88 //! Sets the view projection
89 /// \param theX the X projection value
90 /// \param theY the Y projection value
91 /// \param theZ the Z projection value
92 /// \param theTwist the twist angle in radians
93 virtual void setViewProjection( double theX, double theY, double theZ,
96 //! Sets the view fitted all
97 virtual void fitAll();
99 //! Erases all presentations from the viewer
100 virtual void eraseAll();
102 /// Connects to a viewer according to current environment
103 void connectToViewer();
105 /// Add selection filter to the viewer
106 virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
108 /// Remove selection filter from the viewer
109 virtual void removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
111 /// Returns true if the selection filter is set to the viewer
112 /// \param theFilter a selection filter
113 virtual bool hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter);
115 /// Remove all selection filters from the viewer
116 virtual void clearSelectionFilters();
118 /// Update current viewer
119 virtual void update();
121 /// Method returns True if the viewer can process editing objects
122 /// by mouse drugging. If this is impossible thet it has to return False.
123 virtual bool canDragByMouse() const;
125 virtual void updateHighlight();
127 // Methods for color scale management
129 //! Returns True if ColorScale is visible
130 virtual bool isColorScaleVisible() const;
132 //! Show/Hide ColorScale object
133 virtual void setColorScaleShown(bool on);
135 //! Set position of color scale
136 // \param theX is X position relative to current view width
137 // \param theY is Y position relative to current view heigth
138 virtual void setColorScalePosition(double theX, double theY);
140 //! Set size of color scale
141 // \param theW is width relative to current view width
142 // \param theh is height relative to current view heigth
143 virtual void setColorScaleSize(double theW, double theH);
145 //! Set range of color scale
146 // \param theMin is a minimal value
147 // \param theMax is a maximal value
148 virtual void setColorScaleRange(double theMin, double theMax);
150 //! Set number of intervals of color scale
151 // \param theNb is number of intervals
152 virtual void setColorScaleIntervals(int theNb);
154 //! Set text heigth of color scale
155 // \param theH is number of intervals
156 virtual void setColorScaleTextHeigth(int theH);
158 //! Set color of text of color scale
159 // \param theH is number of intervals
160 virtual void setColorScaleTextColor(const QColor& theColor);
162 //! Set title of color scale
163 // \param theText is a title
164 virtual void setColorScaleTitle(const QString& theText);
166 //! Set color scale parameters according to user preferences and window size
167 void setupColorScale();
169 // Fit all along Z (perpendicular to display)
170 //virtual void Zfitall();
173 virtual void setFitter(OCCViewer_Fitter* theFitter);
174 virtual OCCViewer_Fitter* fitter() const;
176 virtual void setFitter(AppElements_Fitter* theFitter);
177 virtual AppElements_Fitter* fitter() const;
181 /// Emits by mouse entering the view port
182 void enterViewPort();
184 /// Emits by mouse leaving of the view port
185 void leaveViewPort();
188 /// processes the application signals to catch the mouse leaving state of the main window
191 bool eventFilter(QObject *theObject, QEvent *theEvent);
194 void onViewCreated(ModuleBase_IViewWindow* theWnd);
197 void onTryCloseView(AppElements_ViewWindow*);
198 void onDeleteView(AppElements_ViewWindow*);
199 void onViewCreated(AppElements_ViewWindow*);
200 void onActivated(AppElements_ViewWindow*);
202 void onMousePress(AppElements_ViewWindow*, QMouseEvent*);
203 void onMouseRelease(AppElements_ViewWindow*, QMouseEvent*);
204 void onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*);
205 void onMouseMove(AppElements_ViewWindow*, QMouseEvent*);
207 void onKeyPress(AppElements_ViewWindow*, QKeyEvent*);
208 void onKeyRelease(AppElements_ViewWindow*, QKeyEvent*);
210 void onViewTransformed(AppElements_ViewWindow::OperationType);
212 void onMouseMove(ModuleBase_IViewWindow*, QMouseEvent*);
213 void onKeyPress(ModuleBase_IViewWindow*, QKeyEvent*);
214 void onKeyRelease(ModuleBase_IViewWindow*, QKeyEvent*);
218 void displayHighlight(FeaturePtr theFeature, const TopoDS_Shape& theIgnoreShape);
219 bool eraseHighlight();
222 XGUI_Workshop* myWorkshop;
224 AIS_ListOfInteractive myHighlights;