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::eraseAll()
115 myWorkshop->salomeConnector()->viewer()->eraseAll();
120 void XGUI_ViewerProxy::connectToViewer()
123 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
125 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
126 connect(aViewer, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)),
127 this, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)));
129 connect(aViewer, SIGNAL(deleteView(ModuleBase_IViewWindow*)),
130 this, SIGNAL(deleteView(ModuleBase_IViewWindow*)));
132 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
133 this, SLOT(onViewCreated(ModuleBase_IViewWindow*)));
135 connect(aViewer, SIGNAL(activated(ModuleBase_IViewWindow*)),
136 this, SIGNAL(activated(ModuleBase_IViewWindow*)));
138 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
139 this, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)));
141 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
142 this, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
144 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)), this,
145 SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
147 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
148 this, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
150 connect(aViewer, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)),
151 this, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)));
153 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
154 this, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
156 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
158 connect(aViewer, SIGNAL(viewTransformed(int)), this, SIGNAL(viewTransformed(int)));
160 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
161 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
163 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
165 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
167 connect(aViewer, SIGNAL(tryCloseView(AppElements_ViewWindow*)),
168 this, SLOT(onTryCloseView(AppElements_ViewWindow*)));
170 connect(aViewer, SIGNAL(deleteView(AppElements_ViewWindow*)),
171 this, SLOT(onDeleteView(AppElements_ViewWindow*)));
173 connect(aViewer, SIGNAL(viewCreated(AppElements_ViewWindow*)),
174 this, SLOT(onViewCreated(AppElements_ViewWindow*)));
176 connect(aViewer, SIGNAL(activated(AppElements_ViewWindow*)),
177 this, SLOT(onActivated(AppElements_ViewWindow*)));
179 connect(aViewer, SIGNAL(mousePress(AppElements_ViewWindow*, QMouseEvent*)), this,
180 SLOT(onMousePress(AppElements_ViewWindow*, QMouseEvent*)));
182 connect(aViewer, SIGNAL(mouseRelease(AppElements_ViewWindow*, QMouseEvent*)), this,
183 SLOT(onMouseRelease(AppElements_ViewWindow*, QMouseEvent*)));
185 connect(aViewer, SIGNAL(mouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)), this,
186 SLOT(onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)));
188 connect(aViewer, SIGNAL(mouseMove(AppElements_ViewWindow*, QMouseEvent*)), this,
189 SLOT(onMouseMove(AppElements_ViewWindow*, QMouseEvent*)));
191 connect(aViewer, SIGNAL(keyPress(AppElements_ViewWindow*, QKeyEvent*)), this,
192 SLOT(onKeyPress(AppElements_ViewWindow*, QKeyEvent*)));
194 connect(aViewer, SIGNAL(keyRelease(AppElements_ViewWindow*, QKeyEvent*)), this,
195 SLOT(onKeyRelease(AppElements_ViewWindow*, QKeyEvent*)));
197 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
198 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
199 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
203 bool XGUI_ViewerProxy::eventFilter(QObject *theObject, QEvent *theEvent)
205 if (theEvent->type() == QEvent::Enter) {
206 emit enterViewPort();
208 else if (theEvent->type() == QEvent::Leave) {
209 emit leaveViewPort();
211 return ModuleBase_IViewer::eventFilter(theObject, theEvent);
214 void XGUI_ViewerProxy::onViewCreated(ModuleBase_IViewWindow* theWnd)
216 theWnd->viewPort()->installEventFilter(this);
218 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
220 emit viewCreated(theWnd);
224 void XGUI_ViewerProxy::onTryCloseView(AppElements_ViewWindow* theWnd)
226 emit tryCloseView(theWnd);
229 void XGUI_ViewerProxy::onDeleteView(AppElements_ViewWindow* theWnd)
231 if (myWindowScale.contains(theWnd->v3dView()))
232 myWindowScale.remove (theWnd->v3dView());
233 emit deleteView(theWnd);
236 void XGUI_ViewerProxy::onViewCreated(AppElements_ViewWindow* theWnd)
238 theWnd->viewPort()->installEventFilter(this);
240 connect(theWnd, SIGNAL(vpTransformationFinished(AppElements_ViewWindow::OperationType)),
241 this, SLOT(onViewTransformed(AppElements_ViewWindow::OperationType)));
243 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
245 emit viewCreated(theWnd);
248 void XGUI_ViewerProxy::onActivated(AppElements_ViewWindow* theWnd)
250 emit activated(theWnd);
253 void XGUI_ViewerProxy::onMousePress(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
255 emit mousePress(theWnd, theEvent);
258 void XGUI_ViewerProxy::onMouseRelease(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
260 emit mouseRelease(theWnd, theEvent);
263 void XGUI_ViewerProxy::onMouseDoubleClick(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
265 emit mouseDoubleClick(theWnd, theEvent);
268 void XGUI_ViewerProxy::onMouseMove(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
270 emit mouseMove(theWnd, theEvent);
273 void XGUI_ViewerProxy::onKeyPress(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
275 emit keyPress(theWnd, theEvent);
278 void XGUI_ViewerProxy::onKeyRelease(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
280 emit keyRelease(theWnd, theEvent);
283 void XGUI_ViewerProxy::onViewTransformed(AppElements_ViewWindow::OperationType theType)
285 emit viewTransformed((int) theType);
291 //***************************************
292 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
295 myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
297 myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
301 //***************************************
302 bool XGUI_ViewerProxy::isSelectionEnabled() const
305 return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
307 return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
311 //***************************************
312 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
315 myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
317 myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
321 //***************************************
322 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
325 return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
327 return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
331 //***************************************
332 bool XGUI_ViewerProxy::enableDrawMode(bool isEnabled)
335 return myWorkshop->salomeConnector()->viewer()->enableDrawMode(isEnabled);
337 return myWorkshop->mainWindow()->viewer()->enableDrawMode(isEnabled);
341 //***************************************
342 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
344 myWorkshop->displayer()->addSelectionFilter(theFilter);
347 //***************************************
348 void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
350 myWorkshop->displayer()->removeSelectionFilter(theFilter);
353 //***************************************
354 bool XGUI_ViewerProxy::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
356 return myWorkshop->displayer()->hasSelectionFilter(theFilter);
359 //***************************************
360 void XGUI_ViewerProxy::clearSelectionFilters()
362 myWorkshop->displayer()->removeFilters();
365 //***************************************
366 void XGUI_ViewerProxy::update()
368 myWorkshop->displayer()->updateViewer();
371 //***************************************
372 bool XGUI_ViewerProxy::canDragByMouse() const
374 if (myWorkshop->isSalomeMode()) {
375 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
376 return aViewer->canDragByMouse();
383 //***************************************
384 //void XGUI_ViewerProxy::Zfitall()
387 // myWorkshop->salomeConnector()->viewer()->Zfitall();
389 // AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
390 // AppElements_ViewWindow* aView = aViewer->activeViewWindow();
392 // Handle(V3d_View) aView3d = aView->v3dView();
393 // aView3d->ZFitAll();
394 // if (aView3d->Depth() < 0.1)
395 // aView3d->DepthFitAll();