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 #include "XGUI_ViewerProxy.h"
22 #include "XGUI_Workshop.h"
23 #include "XGUI_SalomeConnector.h"
24 #include "XGUI_Displayer.h"
27 #include <AppElements_MainWindow.h>
28 #include <AppElements_ViewPort.h>
29 #include <AppElements_ViewWindow.h>
30 #include <AppElements_Viewer.h>
33 #include <ModuleBase_IViewWindow.h>
37 XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
38 : ModuleBase_IViewer(theParent),
43 void XGUI_ViewerProxy::connectViewProxy()
46 connect(myWorkshop->salomeConnector()->viewer(), SIGNAL(trihedronVisibilityChanged(bool)),
47 SIGNAL(trihedronVisibilityChanged(bool)));
49 connect(myWorkshop->mainWindow()->viewer(), SIGNAL(trihedronVisibilityChanged(bool)),
50 SIGNAL(trihedronVisibilityChanged(bool)));
54 Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
56 Handle(AIS_InteractiveContext) aContext;
58 aContext = myWorkshop->salomeConnector()->viewer()->AISContext();
60 aContext = myWorkshop->mainWindow()->viewer()->AISContext();
65 Handle(AIS_Trihedron) XGUI_ViewerProxy::trihedron() const
68 return myWorkshop->salomeConnector()->viewer()->trihedron();
70 return myWorkshop->mainWindow()->viewer()->trihedron();
74 Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const
77 return myWorkshop->salomeConnector()->viewer()->v3dViewer();
79 return myWorkshop->mainWindow()->viewer()->v3dViewer();
83 Handle(V3d_View) XGUI_ViewerProxy::activeView() const
86 return myWorkshop->salomeConnector()->viewer()->activeView();
88 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
89 return (aViewer->activeViewWindow()) ?
90 aViewer->activeViewWindow()->viewPortApp()->getView() :
95 QWidget* XGUI_ViewerProxy::activeViewPort() const
98 return myWorkshop->salomeConnector()->viewer()->activeViewPort();
100 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
101 return (aViewer->activeViewWindow()) ?
102 aViewer->activeViewWindow()->viewPortApp(): 0;
106 void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ, double theTwist)
108 Handle(V3d_View) aView3d = activeView();
109 if (!aView3d.IsNull()) {
110 aView3d->SetProj(theX, theY, theZ);
111 aView3d->SetTwist( theTwist );
112 aView3d->FitAll(0.01, false);
113 aView3d->SetZSize(0.);
114 if (aView3d->Depth() < 0.1)
115 aView3d->DepthFitAll();
119 void XGUI_ViewerProxy::fitAll()
122 myWorkshop->salomeConnector()->viewer()->fitAll();
124 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
125 if (aViewer->activeViewWindow())
126 aViewer->activeViewWindow()->viewPortApp()->fitAll();
130 void XGUI_ViewerProxy::eraseAll()
133 myWorkshop->salomeConnector()->viewer()->eraseAll();
138 void XGUI_ViewerProxy::connectToViewer()
141 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
143 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
144 connect(aViewer, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)),
145 this, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)));
147 connect(aViewer, SIGNAL(deleteView(ModuleBase_IViewWindow*)),
148 this, SIGNAL(deleteView(ModuleBase_IViewWindow*)));
150 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
151 this, SLOT(onViewCreated(ModuleBase_IViewWindow*)));
153 connect(aViewer, SIGNAL(activated(ModuleBase_IViewWindow*)),
154 this, SIGNAL(activated(ModuleBase_IViewWindow*)));
156 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
157 this, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)));
159 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
160 this, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
162 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)), this,
163 SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
165 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
166 this, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
168 connect(aViewer, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)),
169 this, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)));
171 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
172 this, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
174 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
176 connect(aViewer, SIGNAL(viewTransformed(int)), this, SIGNAL(viewTransformed(int)));
178 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
179 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
181 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
183 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
185 connect(aViewer, SIGNAL(tryCloseView(AppElements_ViewWindow*)),
186 this, SLOT(onTryCloseView(AppElements_ViewWindow*)));
188 connect(aViewer, SIGNAL(deleteView(AppElements_ViewWindow*)),
189 this, SLOT(onDeleteView(AppElements_ViewWindow*)));
191 connect(aViewer, SIGNAL(viewCreated(AppElements_ViewWindow*)),
192 this, SLOT(onViewCreated(AppElements_ViewWindow*)));
194 connect(aViewer, SIGNAL(activated(AppElements_ViewWindow*)),
195 this, SLOT(onActivated(AppElements_ViewWindow*)));
197 connect(aViewer, SIGNAL(mousePress(AppElements_ViewWindow*, QMouseEvent*)), this,
198 SLOT(onMousePress(AppElements_ViewWindow*, QMouseEvent*)));
200 connect(aViewer, SIGNAL(mouseRelease(AppElements_ViewWindow*, QMouseEvent*)), this,
201 SLOT(onMouseRelease(AppElements_ViewWindow*, QMouseEvent*)));
203 connect(aViewer, SIGNAL(mouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)), this,
204 SLOT(onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)));
206 connect(aViewer, SIGNAL(mouseMove(AppElements_ViewWindow*, QMouseEvent*)), this,
207 SLOT(onMouseMove(AppElements_ViewWindow*, QMouseEvent*)));
209 connect(aViewer, SIGNAL(keyPress(AppElements_ViewWindow*, QKeyEvent*)), this,
210 SLOT(onKeyPress(AppElements_ViewWindow*, QKeyEvent*)));
212 connect(aViewer, SIGNAL(keyRelease(AppElements_ViewWindow*, QKeyEvent*)), this,
213 SLOT(onKeyRelease(AppElements_ViewWindow*, QKeyEvent*)));
215 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
216 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
217 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
221 bool XGUI_ViewerProxy::eventFilter(QObject *theObject, QEvent *theEvent)
223 if (theEvent->type() == QEvent::Enter) {
224 emit enterViewPort();
226 else if (theEvent->type() == QEvent::Leave) {
227 emit leaveViewPort();
229 return ModuleBase_IViewer::eventFilter(theObject, theEvent);
232 void XGUI_ViewerProxy::onViewCreated(ModuleBase_IViewWindow* theWnd)
234 theWnd->viewPort()->installEventFilter(this);
236 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
238 emit viewCreated(theWnd);
242 void XGUI_ViewerProxy::onTryCloseView(AppElements_ViewWindow* theWnd)
244 emit tryCloseView(theWnd);
247 void XGUI_ViewerProxy::onDeleteView(AppElements_ViewWindow* theWnd)
249 if (myWindowScale.contains(theWnd->v3dView()))
250 myWindowScale.remove (theWnd->v3dView());
251 emit deleteView(theWnd);
254 void XGUI_ViewerProxy::onViewCreated(AppElements_ViewWindow* theWnd)
256 theWnd->viewPort()->installEventFilter(this);
258 connect(theWnd, SIGNAL(vpTransformationFinished(AppElements_ViewWindow::OperationType)),
259 this, SLOT(onViewTransformed(AppElements_ViewWindow::OperationType)));
261 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
263 emit viewCreated(theWnd);
266 void XGUI_ViewerProxy::onActivated(AppElements_ViewWindow* theWnd)
268 emit activated(theWnd);
271 void XGUI_ViewerProxy::onMousePress(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
273 emit mousePress(theWnd, theEvent);
276 void XGUI_ViewerProxy::onMouseRelease(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
278 emit mouseRelease(theWnd, theEvent);
281 void XGUI_ViewerProxy::onMouseDoubleClick(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
283 emit mouseDoubleClick(theWnd, theEvent);
286 void XGUI_ViewerProxy::onMouseMove(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
288 emit mouseMove(theWnd, theEvent);
291 void XGUI_ViewerProxy::onKeyPress(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
293 emit keyPress(theWnd, theEvent);
296 void XGUI_ViewerProxy::onKeyRelease(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
298 emit keyRelease(theWnd, theEvent);
301 void XGUI_ViewerProxy::onViewTransformed(AppElements_ViewWindow::OperationType theType)
303 emit viewTransformed((int) theType);
309 //***************************************
310 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
313 myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
315 myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
319 //***************************************
320 bool XGUI_ViewerProxy::isSelectionEnabled() const
323 return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
325 return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
329 //***************************************
330 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
333 myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
335 myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
339 //***************************************
340 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
343 return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
345 return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
349 //***************************************
350 bool XGUI_ViewerProxy::enableDrawMode(bool isEnabled)
353 return myWorkshop->salomeConnector()->viewer()->enableDrawMode(isEnabled);
355 return myWorkshop->mainWindow()->viewer()->enableDrawMode(isEnabled);
359 //***************************************
360 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
362 myWorkshop->displayer()->addSelectionFilter(theFilter);
365 //***************************************
366 void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
368 myWorkshop->displayer()->removeSelectionFilter(theFilter);
371 //***************************************
372 bool XGUI_ViewerProxy::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
374 return myWorkshop->displayer()->hasSelectionFilter(theFilter);
377 //***************************************
378 void XGUI_ViewerProxy::clearSelectionFilters()
380 myWorkshop->displayer()->removeFilters();
383 //***************************************
384 void XGUI_ViewerProxy::update()
386 myWorkshop->displayer()->updateViewer();
389 //***************************************
390 bool XGUI_ViewerProxy::canDragByMouse() const
392 if (myWorkshop->isSalomeMode()) {
393 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
394 return aViewer->canDragByMouse();
401 //***************************************
402 //void XGUI_ViewerProxy::Zfitall()
405 // myWorkshop->salomeConnector()->viewer()->Zfitall();
407 // AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
408 // AppElements_ViewWindow* aView = aViewer->activeViewWindow();
410 // Handle(V3d_View) aView3d = aView->v3dView();
411 // aView3d->ZFitAll();
412 // if (aView3d->Depth() < 0.1)
413 // aView3d->DepthFitAll();