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
39 return myWorkshop->salomeConnector()->viewer()->AISContext();
41 return myWorkshop->mainWindow()->viewer()->AISContext();
45 Handle(AIS_Trihedron) XGUI_ViewerProxy::trihedron() const
48 return myWorkshop->salomeConnector()->viewer()->trihedron();
50 return myWorkshop->mainWindow()->viewer()->trihedron();
54 Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const
57 return myWorkshop->salomeConnector()->viewer()->v3dViewer();
59 return myWorkshop->mainWindow()->viewer()->v3dViewer();
63 Handle(V3d_View) XGUI_ViewerProxy::activeView() const
66 return myWorkshop->salomeConnector()->viewer()->activeView();
68 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
69 return (aViewer->activeViewWindow()) ?
70 aViewer->activeViewWindow()->viewPortApp()->getView() :
75 QWidget* XGUI_ViewerProxy::activeViewPort() const
78 return myWorkshop->salomeConnector()->viewer()->activeViewPort();
80 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
81 return (aViewer->activeViewWindow()) ?
82 aViewer->activeViewWindow()->viewPortApp(): 0;
86 void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ, double theTwist)
88 Handle(V3d_View) aView3d = activeView();
89 if (!aView3d.IsNull()) {
90 aView3d->SetProj(theX, theY, theZ);
91 aView3d->SetTwist( theTwist );
92 aView3d->FitAll(0.01, false);
93 aView3d->SetZSize(0.);
94 if (aView3d->Depth() < 0.1)
95 aView3d->DepthFitAll();
99 void XGUI_ViewerProxy::fitAll()
102 myWorkshop->salomeConnector()->viewer()->fitAll();
104 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
105 if (aViewer->activeViewWindow())
106 aViewer->activeViewWindow()->viewPortApp()->fitAll();
110 void XGUI_ViewerProxy::connectToViewer()
113 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
115 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
116 connect(aViewer, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)),
117 this, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)));
119 connect(aViewer, SIGNAL(deleteView(ModuleBase_IViewWindow*)),
120 this, SIGNAL(deleteView(ModuleBase_IViewWindow*)));
122 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
123 this, SLOT(onViewCreated(ModuleBase_IViewWindow*)));
125 connect(aViewer, SIGNAL(activated(ModuleBase_IViewWindow*)),
126 this, SIGNAL(activated(ModuleBase_IViewWindow*)));
128 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
129 this, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)));
131 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
132 this, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
134 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)), this,
135 SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
137 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
138 this, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
140 connect(aViewer, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)),
141 this, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)));
143 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
144 this, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
146 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
148 connect(aViewer, SIGNAL(viewTransformed(int)), this, SIGNAL(viewTransformed(int)));
150 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
151 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
153 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
155 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
157 connect(aViewer, SIGNAL(tryCloseView(AppElements_ViewWindow*)),
158 this, SLOT(onTryCloseView(AppElements_ViewWindow*)));
160 connect(aViewer, SIGNAL(deleteView(AppElements_ViewWindow*)),
161 this, SLOT(onDeleteView(AppElements_ViewWindow*)));
163 connect(aViewer, SIGNAL(viewCreated(AppElements_ViewWindow*)),
164 this, SLOT(onViewCreated(AppElements_ViewWindow*)));
166 connect(aViewer, SIGNAL(activated(AppElements_ViewWindow*)),
167 this, SLOT(onActivated(AppElements_ViewWindow*)));
169 connect(aViewer, SIGNAL(mousePress(AppElements_ViewWindow*, QMouseEvent*)), this,
170 SLOT(onMousePress(AppElements_ViewWindow*, QMouseEvent*)));
172 connect(aViewer, SIGNAL(mouseRelease(AppElements_ViewWindow*, QMouseEvent*)), this,
173 SLOT(onMouseRelease(AppElements_ViewWindow*, QMouseEvent*)));
175 connect(aViewer, SIGNAL(mouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)), this,
176 SLOT(onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)));
178 connect(aViewer, SIGNAL(mouseMove(AppElements_ViewWindow*, QMouseEvent*)), this,
179 SLOT(onMouseMove(AppElements_ViewWindow*, QMouseEvent*)));
181 connect(aViewer, SIGNAL(keyPress(AppElements_ViewWindow*, QKeyEvent*)), this,
182 SLOT(onKeyPress(AppElements_ViewWindow*, QKeyEvent*)));
184 connect(aViewer, SIGNAL(keyRelease(AppElements_ViewWindow*, QKeyEvent*)), this,
185 SLOT(onKeyRelease(AppElements_ViewWindow*, QKeyEvent*)));
187 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
188 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
189 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
193 bool XGUI_ViewerProxy::eventFilter(QObject *theObject, QEvent *theEvent)
195 if (theEvent->type() == QEvent::Enter) {
196 emit enterViewPort();
198 else if (theEvent->type() == QEvent::Leave) {
199 emit leaveViewPort();
201 return ModuleBase_IViewer::eventFilter(theObject, theEvent);
204 void XGUI_ViewerProxy::onViewCreated(ModuleBase_IViewWindow* theWnd)
206 theWnd->viewPort()->installEventFilter(this);
208 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
210 emit viewCreated(theWnd);
214 void XGUI_ViewerProxy::onTryCloseView(AppElements_ViewWindow* theWnd)
216 emit tryCloseView(theWnd);
219 void XGUI_ViewerProxy::onDeleteView(AppElements_ViewWindow* theWnd)
221 if (myWindowScale.contains(theWnd->v3dView()))
222 myWindowScale.remove (theWnd->v3dView());
223 emit deleteView(theWnd);
226 void XGUI_ViewerProxy::onViewCreated(AppElements_ViewWindow* theWnd)
228 theWnd->viewPort()->installEventFilter(this);
230 connect(theWnd, SIGNAL(vpTransformationFinished(AppElements_ViewWindow::OperationType)),
231 this, SLOT(onViewTransformed(AppElements_ViewWindow::OperationType)));
233 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
235 emit viewCreated(theWnd);
238 void XGUI_ViewerProxy::onActivated(AppElements_ViewWindow* theWnd)
240 emit activated(theWnd);
243 void XGUI_ViewerProxy::onMousePress(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
245 emit mousePress(theWnd, theEvent);
248 void XGUI_ViewerProxy::onMouseRelease(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
250 emit mouseRelease(theWnd, theEvent);
253 void XGUI_ViewerProxy::onMouseDoubleClick(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
255 emit mouseDoubleClick(theWnd, theEvent);
258 void XGUI_ViewerProxy::onMouseMove(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
260 emit mouseMove(theWnd, theEvent);
263 void XGUI_ViewerProxy::onKeyPress(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
265 emit keyPress(theWnd, theEvent);
268 void XGUI_ViewerProxy::onKeyRelease(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
270 emit keyRelease(theWnd, theEvent);
273 void XGUI_ViewerProxy::onViewTransformed(AppElements_ViewWindow::OperationType theType)
275 emit viewTransformed((int) theType);
281 //***************************************
282 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
285 myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
287 myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
291 //***************************************
292 bool XGUI_ViewerProxy::isSelectionEnabled() const
295 return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
297 return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
301 //***************************************
302 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
305 myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
307 myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
311 //***************************************
312 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
315 return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
317 return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
321 //***************************************
322 bool XGUI_ViewerProxy::enableDrawMode(bool isEnabled)
325 return myWorkshop->salomeConnector()->viewer()->enableDrawMode(isEnabled);
327 return myWorkshop->mainWindow()->viewer()->enableDrawMode(isEnabled);
331 //***************************************
332 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
334 myWorkshop->displayer()->addSelectionFilter(theFilter);
337 //***************************************
338 void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
340 myWorkshop->displayer()->removeSelectionFilter(theFilter);
343 //***************************************
344 bool XGUI_ViewerProxy::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
346 return myWorkshop->displayer()->hasSelectionFilter(theFilter);
349 //***************************************
350 void XGUI_ViewerProxy::clearSelectionFilters()
352 myWorkshop->displayer()->removeFilters();
355 //***************************************
356 void XGUI_ViewerProxy::update()
358 myWorkshop->displayer()->updateViewer();
361 //***************************************
362 bool XGUI_ViewerProxy::canDragByMouse() const
364 if (myWorkshop->isSalomeMode()) {
365 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
366 return aViewer->canDragByMouse();
373 //***************************************
374 void XGUI_ViewerProxy::Zfitall()
377 myWorkshop->salomeConnector()->viewer()->Zfitall();
379 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
380 AppElements_ViewWindow* aView = aViewer->activeViewWindow();
382 Handle(V3d_View) aView3d = aView->v3dView();
384 if (aView3d->Depth() < 0.1)
385 aView3d->DepthFitAll();