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>
16 #include <VInspectorAPI_PluginMgr.h>
\r
17 #include <VInspectorAPI_Communicator.h>
\r
19 static bool FirstCall = true;
\r
23 #include <ModuleBase_IViewWindow.h>
27 XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
28 : ModuleBase_IViewer(theParent),
33 void XGUI_ViewerProxy::connectViewProxy()
36 connect(myWorkshop->salomeConnector()->viewer(), SIGNAL(trihedronVisibilityChanged(bool)),
37 SIGNAL(trihedronVisibilityChanged(bool)));
39 connect(myWorkshop->mainWindow()->viewer(), SIGNAL(trihedronVisibilityChanged(bool)),
40 SIGNAL(trihedronVisibilityChanged(bool)));
44 Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
46 Handle(AIS_InteractiveContext) aContext;
48 aContext = myWorkshop->salomeConnector()->viewer()->AISContext();
50 aContext = myWorkshop->mainWindow()->viewer()->AISContext();
55 VInspectorAPI_PluginMgr::activateVInspector("VInspector.dll", aContext);
64 Handle(AIS_Trihedron) XGUI_ViewerProxy::trihedron() const
67 return myWorkshop->salomeConnector()->viewer()->trihedron();
69 return myWorkshop->mainWindow()->viewer()->trihedron();
73 Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const
76 return myWorkshop->salomeConnector()->viewer()->v3dViewer();
78 return myWorkshop->mainWindow()->viewer()->v3dViewer();
82 Handle(V3d_View) XGUI_ViewerProxy::activeView() const
85 return myWorkshop->salomeConnector()->viewer()->activeView();
87 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
88 return (aViewer->activeViewWindow()) ?
89 aViewer->activeViewWindow()->viewPortApp()->getView() :
94 QWidget* XGUI_ViewerProxy::activeViewPort() const
97 return myWorkshop->salomeConnector()->viewer()->activeViewPort();
99 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
100 return (aViewer->activeViewWindow()) ?
101 aViewer->activeViewWindow()->viewPortApp(): 0;
105 void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ, double theTwist)
107 Handle(V3d_View) aView3d = activeView();
108 if (!aView3d.IsNull()) {
109 aView3d->SetProj(theX, theY, theZ);
110 aView3d->SetTwist( theTwist );
111 aView3d->FitAll(0.01, false);
112 aView3d->SetZSize(0.);
113 if (aView3d->Depth() < 0.1)
114 aView3d->DepthFitAll();
118 void XGUI_ViewerProxy::fitAll()
121 myWorkshop->salomeConnector()->viewer()->fitAll();
123 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
124 if (aViewer->activeViewWindow())
125 aViewer->activeViewWindow()->viewPortApp()->fitAll();
129 void XGUI_ViewerProxy::connectToViewer()
132 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
134 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
135 connect(aViewer, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)),
136 this, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)));
138 connect(aViewer, SIGNAL(deleteView(ModuleBase_IViewWindow*)),
139 this, SIGNAL(deleteView(ModuleBase_IViewWindow*)));
141 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
142 this, SLOT(onViewCreated(ModuleBase_IViewWindow*)));
144 connect(aViewer, SIGNAL(activated(ModuleBase_IViewWindow*)),
145 this, SIGNAL(activated(ModuleBase_IViewWindow*)));
147 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
148 this, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)));
150 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
151 this, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
153 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)), this,
154 SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
156 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
157 this, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
159 connect(aViewer, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)),
160 this, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)));
162 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
163 this, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
165 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
167 connect(aViewer, SIGNAL(viewTransformed(int)), this, SIGNAL(viewTransformed(int)));
169 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
170 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
172 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
174 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
176 connect(aViewer, SIGNAL(tryCloseView(AppElements_ViewWindow*)),
177 this, SLOT(onTryCloseView(AppElements_ViewWindow*)));
179 connect(aViewer, SIGNAL(deleteView(AppElements_ViewWindow*)),
180 this, SLOT(onDeleteView(AppElements_ViewWindow*)));
182 connect(aViewer, SIGNAL(viewCreated(AppElements_ViewWindow*)),
183 this, SLOT(onViewCreated(AppElements_ViewWindow*)));
185 connect(aViewer, SIGNAL(activated(AppElements_ViewWindow*)),
186 this, SLOT(onActivated(AppElements_ViewWindow*)));
188 connect(aViewer, SIGNAL(mousePress(AppElements_ViewWindow*, QMouseEvent*)), this,
189 SLOT(onMousePress(AppElements_ViewWindow*, QMouseEvent*)));
191 connect(aViewer, SIGNAL(mouseRelease(AppElements_ViewWindow*, QMouseEvent*)), this,
192 SLOT(onMouseRelease(AppElements_ViewWindow*, QMouseEvent*)));
194 connect(aViewer, SIGNAL(mouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)), this,
195 SLOT(onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)));
197 connect(aViewer, SIGNAL(mouseMove(AppElements_ViewWindow*, QMouseEvent*)), this,
198 SLOT(onMouseMove(AppElements_ViewWindow*, QMouseEvent*)));
200 connect(aViewer, SIGNAL(keyPress(AppElements_ViewWindow*, QKeyEvent*)), this,
201 SLOT(onKeyPress(AppElements_ViewWindow*, QKeyEvent*)));
203 connect(aViewer, SIGNAL(keyRelease(AppElements_ViewWindow*, QKeyEvent*)), this,
204 SLOT(onKeyRelease(AppElements_ViewWindow*, QKeyEvent*)));
206 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
207 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
208 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
212 bool XGUI_ViewerProxy::eventFilter(QObject *theObject, QEvent *theEvent)
214 if (theEvent->type() == QEvent::Enter) {
215 emit enterViewPort();
217 else if (theEvent->type() == QEvent::Leave) {
218 emit leaveViewPort();
220 return ModuleBase_IViewer::eventFilter(theObject, theEvent);
223 void XGUI_ViewerProxy::onViewCreated(ModuleBase_IViewWindow* theWnd)
225 theWnd->viewPort()->installEventFilter(this);
227 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
229 emit viewCreated(theWnd);
233 void XGUI_ViewerProxy::onTryCloseView(AppElements_ViewWindow* theWnd)
235 emit tryCloseView(theWnd);
238 void XGUI_ViewerProxy::onDeleteView(AppElements_ViewWindow* theWnd)
240 if (myWindowScale.contains(theWnd->v3dView()))
241 myWindowScale.remove (theWnd->v3dView());
242 emit deleteView(theWnd);
245 void XGUI_ViewerProxy::onViewCreated(AppElements_ViewWindow* theWnd)
247 theWnd->viewPort()->installEventFilter(this);
249 connect(theWnd, SIGNAL(vpTransformationFinished(AppElements_ViewWindow::OperationType)),
250 this, SLOT(onViewTransformed(AppElements_ViewWindow::OperationType)));
252 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
254 emit viewCreated(theWnd);
257 void XGUI_ViewerProxy::onActivated(AppElements_ViewWindow* theWnd)
259 emit activated(theWnd);
262 void XGUI_ViewerProxy::onMousePress(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
264 emit mousePress(theWnd, theEvent);
267 void XGUI_ViewerProxy::onMouseRelease(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
269 emit mouseRelease(theWnd, theEvent);
272 void XGUI_ViewerProxy::onMouseDoubleClick(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
274 emit mouseDoubleClick(theWnd, theEvent);
277 void XGUI_ViewerProxy::onMouseMove(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
279 emit mouseMove(theWnd, theEvent);
282 void XGUI_ViewerProxy::onKeyPress(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
284 emit keyPress(theWnd, theEvent);
287 void XGUI_ViewerProxy::onKeyRelease(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
289 emit keyRelease(theWnd, theEvent);
292 void XGUI_ViewerProxy::onViewTransformed(AppElements_ViewWindow::OperationType theType)
294 emit viewTransformed((int) theType);
300 //***************************************
301 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
304 myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
306 myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
310 //***************************************
311 bool XGUI_ViewerProxy::isSelectionEnabled() const
314 return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
316 return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
320 //***************************************
321 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
324 myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
326 myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
330 //***************************************
331 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
334 return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
336 return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
340 //***************************************
341 bool XGUI_ViewerProxy::enableDrawMode(bool isEnabled)
344 return myWorkshop->salomeConnector()->viewer()->enableDrawMode(isEnabled);
346 return myWorkshop->mainWindow()->viewer()->enableDrawMode(isEnabled);
350 //***************************************
351 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
353 myWorkshop->displayer()->addSelectionFilter(theFilter);
356 //***************************************
357 void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
359 myWorkshop->displayer()->removeSelectionFilter(theFilter);
362 //***************************************
363 bool XGUI_ViewerProxy::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
365 return myWorkshop->displayer()->hasSelectionFilter(theFilter);
368 //***************************************
369 void XGUI_ViewerProxy::clearSelectionFilters()
371 myWorkshop->displayer()->removeFilters();
374 //***************************************
375 void XGUI_ViewerProxy::update()
377 myWorkshop->displayer()->updateViewer();
380 //***************************************
381 bool XGUI_ViewerProxy::canDragByMouse() const
383 if (myWorkshop->isSalomeMode()) {
384 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
385 return aViewer->canDragByMouse();
392 //***************************************
393 void XGUI_ViewerProxy::Zfitall()
396 myWorkshop->salomeConnector()->viewer()->Zfitall();
398 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
399 AppElements_ViewWindow* aView = aViewer->activeViewWindow();
401 Handle(V3d_View) aView3d = aView->v3dView();
403 if (aView3d->Depth() < 0.1)
404 aView3d->DepthFitAll();