1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 #include "XGUI_ViewerProxy.h"
4 #include "XGUI_Workshop.h"
5 #include "XGUI_SalomeConnector.h"
6 #include "XGUI_Displayer.h"
9 #include <AppElements_MainWindow.h>
10 #include <AppElements_ViewPort.h>
11 #include <AppElements_ViewWindow.h>
12 #include <AppElements_Viewer.h>
15 #include <ModuleBase_IViewWindow.h>
19 XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
20 : ModuleBase_IViewer(theParent),
25 void XGUI_ViewerProxy::connectViewProxy()
28 connect(myWorkshop->salomeConnector()->viewer(), SIGNAL(trihedronVisibilityChanged(bool)),
29 SIGNAL(trihedronVisibilityChanged(bool)));
31 connect(myWorkshop->mainWindow()->viewer(), SIGNAL(trihedronVisibilityChanged(bool)),
32 SIGNAL(trihedronVisibilityChanged(bool)));
36 Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
38 Handle(AIS_InteractiveContext) aContext;
40 aContext = myWorkshop->salomeConnector()->viewer()->AISContext();
42 aContext = myWorkshop->mainWindow()->viewer()->AISContext();
47 Handle(AIS_Trihedron) XGUI_ViewerProxy::trihedron() const
50 return myWorkshop->salomeConnector()->viewer()->trihedron();
52 return myWorkshop->mainWindow()->viewer()->trihedron();
56 Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const
59 return myWorkshop->salomeConnector()->viewer()->v3dViewer();
61 return myWorkshop->mainWindow()->viewer()->v3dViewer();
65 Handle(V3d_View) XGUI_ViewerProxy::activeView() const
68 return myWorkshop->salomeConnector()->viewer()->activeView();
70 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
71 return (aViewer->activeViewWindow()) ?
72 aViewer->activeViewWindow()->viewPortApp()->getView() :
77 QWidget* XGUI_ViewerProxy::activeViewPort() const
80 return myWorkshop->salomeConnector()->viewer()->activeViewPort();
82 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
83 return (aViewer->activeViewWindow()) ?
84 aViewer->activeViewWindow()->viewPortApp(): 0;
88 void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ, double theTwist)
90 Handle(V3d_View) aView3d = activeView();
91 if (!aView3d.IsNull()) {
92 aView3d->SetProj(theX, theY, theZ);
93 aView3d->SetTwist( theTwist );
94 aView3d->FitAll(0.01, false);
95 aView3d->SetZSize(0.);
96 if (aView3d->Depth() < 0.1)
97 aView3d->DepthFitAll();
101 void XGUI_ViewerProxy::fitAll()
104 myWorkshop->salomeConnector()->viewer()->fitAll();
106 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
107 if (aViewer->activeViewWindow())
108 aViewer->activeViewWindow()->viewPortApp()->fitAll();
112 void XGUI_ViewerProxy::connectToViewer()
115 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
117 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
118 connect(aViewer, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)),
119 this, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)));
121 connect(aViewer, SIGNAL(deleteView(ModuleBase_IViewWindow*)),
122 this, SIGNAL(deleteView(ModuleBase_IViewWindow*)));
124 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
125 this, SLOT(onViewCreated(ModuleBase_IViewWindow*)));
127 connect(aViewer, SIGNAL(activated(ModuleBase_IViewWindow*)),
128 this, SIGNAL(activated(ModuleBase_IViewWindow*)));
130 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
131 this, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)));
133 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
134 this, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
136 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)), this,
137 SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
139 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
140 this, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
142 connect(aViewer, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)),
143 this, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)));
145 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
146 this, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
148 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
150 connect(aViewer, SIGNAL(viewTransformed(int)), this, SIGNAL(viewTransformed(int)));
152 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
153 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
155 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
157 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
159 connect(aViewer, SIGNAL(tryCloseView(AppElements_ViewWindow*)),
160 this, SLOT(onTryCloseView(AppElements_ViewWindow*)));
162 connect(aViewer, SIGNAL(deleteView(AppElements_ViewWindow*)),
163 this, SLOT(onDeleteView(AppElements_ViewWindow*)));
165 connect(aViewer, SIGNAL(viewCreated(AppElements_ViewWindow*)),
166 this, SLOT(onViewCreated(AppElements_ViewWindow*)));
168 connect(aViewer, SIGNAL(activated(AppElements_ViewWindow*)),
169 this, SLOT(onActivated(AppElements_ViewWindow*)));
171 connect(aViewer, SIGNAL(mousePress(AppElements_ViewWindow*, QMouseEvent*)), this,
172 SLOT(onMousePress(AppElements_ViewWindow*, QMouseEvent*)));
174 connect(aViewer, SIGNAL(mouseRelease(AppElements_ViewWindow*, QMouseEvent*)), this,
175 SLOT(onMouseRelease(AppElements_ViewWindow*, QMouseEvent*)));
177 connect(aViewer, SIGNAL(mouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)), this,
178 SLOT(onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)));
180 connect(aViewer, SIGNAL(mouseMove(AppElements_ViewWindow*, QMouseEvent*)), this,
181 SLOT(onMouseMove(AppElements_ViewWindow*, QMouseEvent*)));
183 connect(aViewer, SIGNAL(keyPress(AppElements_ViewWindow*, QKeyEvent*)), this,
184 SLOT(onKeyPress(AppElements_ViewWindow*, QKeyEvent*)));
186 connect(aViewer, SIGNAL(keyRelease(AppElements_ViewWindow*, QKeyEvent*)), this,
187 SLOT(onKeyRelease(AppElements_ViewWindow*, QKeyEvent*)));
189 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
190 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
191 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
195 bool XGUI_ViewerProxy::eventFilter(QObject *theObject, QEvent *theEvent)
197 if (theEvent->type() == QEvent::Enter) {
198 emit enterViewPort();
200 else if (theEvent->type() == QEvent::Leave) {
201 emit leaveViewPort();
203 return ModuleBase_IViewer::eventFilter(theObject, theEvent);
206 void XGUI_ViewerProxy::onViewCreated(ModuleBase_IViewWindow* theWnd)
208 theWnd->viewPort()->installEventFilter(this);
210 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
212 emit viewCreated(theWnd);
216 void XGUI_ViewerProxy::onTryCloseView(AppElements_ViewWindow* theWnd)
218 emit tryCloseView(theWnd);
221 void XGUI_ViewerProxy::onDeleteView(AppElements_ViewWindow* theWnd)
223 if (myWindowScale.contains(theWnd->v3dView()))
224 myWindowScale.remove (theWnd->v3dView());
225 emit deleteView(theWnd);
228 void XGUI_ViewerProxy::onViewCreated(AppElements_ViewWindow* theWnd)
230 theWnd->viewPort()->installEventFilter(this);
232 connect(theWnd, SIGNAL(vpTransformationFinished(AppElements_ViewWindow::OperationType)),
233 this, SLOT(onViewTransformed(AppElements_ViewWindow::OperationType)));
235 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
237 emit viewCreated(theWnd);
240 void XGUI_ViewerProxy::onActivated(AppElements_ViewWindow* theWnd)
242 emit activated(theWnd);
245 void XGUI_ViewerProxy::onMousePress(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
247 emit mousePress(theWnd, theEvent);
250 void XGUI_ViewerProxy::onMouseRelease(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
252 emit mouseRelease(theWnd, theEvent);
255 void XGUI_ViewerProxy::onMouseDoubleClick(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
257 emit mouseDoubleClick(theWnd, theEvent);
260 void XGUI_ViewerProxy::onMouseMove(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
262 emit mouseMove(theWnd, theEvent);
265 void XGUI_ViewerProxy::onKeyPress(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
267 emit keyPress(theWnd, theEvent);
270 void XGUI_ViewerProxy::onKeyRelease(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
272 emit keyRelease(theWnd, theEvent);
275 void XGUI_ViewerProxy::onViewTransformed(AppElements_ViewWindow::OperationType theType)
277 emit viewTransformed((int) theType);
283 //***************************************
284 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
287 myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
289 myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
293 //***************************************
294 bool XGUI_ViewerProxy::isSelectionEnabled() const
297 return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
299 return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
303 //***************************************
304 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
307 myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
309 myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
313 //***************************************
314 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
317 return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
319 return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
323 //***************************************
324 bool XGUI_ViewerProxy::enableDrawMode(bool isEnabled)
327 return myWorkshop->salomeConnector()->viewer()->enableDrawMode(isEnabled);
329 return myWorkshop->mainWindow()->viewer()->enableDrawMode(isEnabled);
333 //***************************************
334 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
336 myWorkshop->displayer()->addSelectionFilter(theFilter);
339 //***************************************
340 void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
342 myWorkshop->displayer()->removeSelectionFilter(theFilter);
345 //***************************************
346 bool XGUI_ViewerProxy::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
348 return myWorkshop->displayer()->hasSelectionFilter(theFilter);
351 //***************************************
352 void XGUI_ViewerProxy::clearSelectionFilters()
354 myWorkshop->displayer()->removeFilters();
357 //***************************************
358 void XGUI_ViewerProxy::update()
360 myWorkshop->displayer()->updateViewer();
363 //***************************************
364 bool XGUI_ViewerProxy::canDragByMouse() const
366 if (myWorkshop->isSalomeMode()) {
367 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
368 return aViewer->canDragByMouse();
375 //***************************************
376 //void XGUI_ViewerProxy::Zfitall()
379 // myWorkshop->salomeConnector()->viewer()->Zfitall();
381 // AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
382 // AppElements_ViewWindow* aView = aViewer->activeViewWindow();
384 // Handle(V3d_View) aView3d = aView->v3dView();
385 // aView3d->ZFitAll();
386 // if (aView3d->Depth() < 0.1)
387 // aView3d->DepthFitAll();