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 Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
28 return myWorkshop->salomeConnector()->viewer()->AISContext();
30 return myWorkshop->mainWindow()->viewer()->AISContext();
34 Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const
37 return myWorkshop->salomeConnector()->viewer()->v3dViewer();
39 return myWorkshop->mainWindow()->viewer()->v3dViewer();
43 Handle(V3d_View) XGUI_ViewerProxy::activeView() const
46 return myWorkshop->salomeConnector()->viewer()->activeView();
48 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
49 return (aViewer->activeViewWindow()) ?
50 aViewer->activeViewWindow()->viewPortApp()->getView() :
55 QWidget* XGUI_ViewerProxy::activeViewPort() const
58 return myWorkshop->salomeConnector()->viewer()->activeViewPort();
60 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
61 return (aViewer->activeViewWindow()) ?
62 aViewer->activeViewWindow()->viewPortApp(): 0;
66 void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ, double theTwist)
68 Handle(V3d_View) aView3d = activeView();
69 if (!aView3d.IsNull()) {
70 aView3d->SetProj(theX, theY, theZ);
71 aView3d->SetTwist( theTwist );
72 aView3d->FitAll(0.01, false);
73 aView3d->SetZSize(0.);
74 if (aView3d->Depth() < 0.1)
75 aView3d->DepthFitAll();
79 void XGUI_ViewerProxy::fitAll()
82 myWorkshop->salomeConnector()->viewer()->fitAll();
84 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
85 if (aViewer->activeViewWindow())
86 aViewer->activeViewWindow()->viewPortApp()->fitAll();
90 void XGUI_ViewerProxy::connectToViewer()
93 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
95 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
96 connect(aViewer, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)),
97 this, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)));
99 connect(aViewer, SIGNAL(deleteView(ModuleBase_IViewWindow*)),
100 this, SIGNAL(deleteView(ModuleBase_IViewWindow*)));
102 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
103 this, SLOT(onViewCreated(ModuleBase_IViewWindow*)));
105 connect(aViewer, SIGNAL(activated(ModuleBase_IViewWindow*)),
106 this, SIGNAL(activated(ModuleBase_IViewWindow*)));
108 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
109 this, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)));
111 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
112 this, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
114 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)), this,
115 SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
117 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
118 this, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
120 connect(aViewer, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)),
121 this, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)));
123 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
124 this, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
126 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
128 connect(aViewer, SIGNAL(viewTransformed(int)), this, SIGNAL(viewTransformed(int)));
130 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
131 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
133 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
135 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
137 connect(aViewer, SIGNAL(tryCloseView(AppElements_ViewWindow*)),
138 this, SLOT(onTryCloseView(AppElements_ViewWindow*)));
140 connect(aViewer, SIGNAL(deleteView(AppElements_ViewWindow*)),
141 this, SLOT(onDeleteView(AppElements_ViewWindow*)));
143 connect(aViewer, SIGNAL(viewCreated(AppElements_ViewWindow*)),
144 this, SLOT(onViewCreated(AppElements_ViewWindow*)));
146 connect(aViewer, SIGNAL(activated(AppElements_ViewWindow*)),
147 this, SLOT(onActivated(AppElements_ViewWindow*)));
149 connect(aViewer, SIGNAL(mousePress(AppElements_ViewWindow*, QMouseEvent*)), this,
150 SLOT(onMousePress(AppElements_ViewWindow*, QMouseEvent*)));
152 connect(aViewer, SIGNAL(mouseRelease(AppElements_ViewWindow*, QMouseEvent*)), this,
153 SLOT(onMouseRelease(AppElements_ViewWindow*, QMouseEvent*)));
155 connect(aViewer, SIGNAL(mouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)), this,
156 SLOT(onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)));
158 connect(aViewer, SIGNAL(mouseMove(AppElements_ViewWindow*, QMouseEvent*)), this,
159 SLOT(onMouseMove(AppElements_ViewWindow*, QMouseEvent*)));
161 connect(aViewer, SIGNAL(keyPress(AppElements_ViewWindow*, QKeyEvent*)), this,
162 SLOT(onKeyPress(AppElements_ViewWindow*, QKeyEvent*)));
164 connect(aViewer, SIGNAL(keyRelease(AppElements_ViewWindow*, QKeyEvent*)), this,
165 SLOT(onKeyRelease(AppElements_ViewWindow*, QKeyEvent*)));
167 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
168 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
169 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
173 bool XGUI_ViewerProxy::eventFilter(QObject *theObject, QEvent *theEvent)
175 if (theEvent->type() == QEvent::Enter) {
176 emit enterViewPort();
178 else if (theEvent->type() == QEvent::Leave) {
179 emit leaveViewPort();
181 return ModuleBase_IViewer::eventFilter(theObject, theEvent);
184 void XGUI_ViewerProxy::onViewCreated(ModuleBase_IViewWindow* theWnd)
186 theWnd->viewPort()->installEventFilter(this);
188 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
190 emit viewCreated(theWnd);
194 void XGUI_ViewerProxy::onTryCloseView(AppElements_ViewWindow* theWnd)
196 emit tryCloseView(theWnd);
199 void XGUI_ViewerProxy::onDeleteView(AppElements_ViewWindow* theWnd)
201 if (myWindowScale.contains(theWnd->v3dView()))
202 myWindowScale.remove (theWnd->v3dView());
203 emit deleteView(theWnd);
206 void XGUI_ViewerProxy::onViewCreated(AppElements_ViewWindow* theWnd)
208 theWnd->viewPort()->installEventFilter(this);
210 connect(theWnd, SIGNAL(vpTransformationFinished(AppElements_ViewWindow::OperationType)),
211 this, SLOT(onViewTransformed(AppElements_ViewWindow::OperationType)));
213 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
215 emit viewCreated(theWnd);
218 void XGUI_ViewerProxy::onActivated(AppElements_ViewWindow* theWnd)
220 emit activated(theWnd);
223 void XGUI_ViewerProxy::onMousePress(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
225 emit mousePress(theWnd, theEvent);
228 void XGUI_ViewerProxy::onMouseRelease(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
230 emit mouseRelease(theWnd, theEvent);
233 void XGUI_ViewerProxy::onMouseDoubleClick(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
235 emit mouseDoubleClick(theWnd, theEvent);
238 void XGUI_ViewerProxy::onMouseMove(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
240 emit mouseMove(theWnd, theEvent);
243 void XGUI_ViewerProxy::onKeyPress(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
245 emit keyPress(theWnd, theEvent);
248 void XGUI_ViewerProxy::onKeyRelease(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
250 emit keyRelease(theWnd, theEvent);
253 void XGUI_ViewerProxy::onViewTransformed(AppElements_ViewWindow::OperationType theType)
255 emit viewTransformed((int) theType);
261 //***************************************
262 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
265 myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
267 myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
271 //***************************************
272 bool XGUI_ViewerProxy::isSelectionEnabled() const
275 return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
277 return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
281 //***************************************
282 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
285 myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
287 myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
291 //***************************************
292 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
295 return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
297 return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
301 //***************************************
302 bool XGUI_ViewerProxy::enableDrawMode(bool isEnabled)
305 return myWorkshop->salomeConnector()->viewer()->enableDrawMode(isEnabled);
307 return myWorkshop->mainWindow()->viewer()->enableDrawMode(isEnabled);
311 //***************************************
312 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
314 myWorkshop->displayer()->addSelectionFilter(theFilter);
317 //***************************************
318 void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
320 myWorkshop->displayer()->removeSelectionFilter(theFilter);
323 //***************************************
324 bool XGUI_ViewerProxy::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
326 return myWorkshop->displayer()->hasSelectionFilter(theFilter);
329 //***************************************
330 void XGUI_ViewerProxy::clearSelectionFilters()
332 myWorkshop->displayer()->removeFilters();
335 //***************************************
336 void XGUI_ViewerProxy::update()
338 myWorkshop->displayer()->updateViewer();
341 //***************************************
342 bool XGUI_ViewerProxy::canDragByMouse() const
344 if (myWorkshop->isSalomeMode()) {
345 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
346 return aViewer->canDragByMouse();
353 //***************************************
354 void XGUI_ViewerProxy::Zfitall()
357 myWorkshop->salomeConnector()->viewer()->Zfitall();
359 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
360 AppElements_ViewWindow* aView = aViewer->activeViewWindow();
362 Handle(V3d_View) aView3d = aView->v3dView();
364 if (aView3d->Depth() < 0.1)
365 aView3d->DepthFitAll();