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 void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ, double theTwist)
57 Handle(V3d_View) aView3d = activeView();
58 if (!aView3d.IsNull()) {
59 aView3d->SetProj(theX, theY, theZ);
60 aView3d->SetTwist( theTwist );
61 aView3d->FitAll(0.01, true);
62 aView3d->SetZSize(0.);
63 if (aView3d->Depth() < 0.1)
64 aView3d->DepthFitAll();
68 void XGUI_ViewerProxy::fitAll()
71 myWorkshop->salomeConnector()->viewer()->fitAll();
73 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
74 if (aViewer->activeViewWindow())
75 aViewer->activeViewWindow()->viewPortApp()->fitAll();
79 void XGUI_ViewerProxy::connectToViewer()
82 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
84 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
85 connect(aViewer, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)),
86 this, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)));
88 connect(aViewer, SIGNAL(deleteView(ModuleBase_IViewWindow*)),
89 this, SIGNAL(deleteView(ModuleBase_IViewWindow*)));
91 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
92 this, SLOT(onViewCreated(ModuleBase_IViewWindow*)));
94 connect(aViewer, SIGNAL(activated(ModuleBase_IViewWindow*)),
95 this, SIGNAL(activated(ModuleBase_IViewWindow*)));
97 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
98 this, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)));
100 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
101 this, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
103 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)), this,
104 SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
106 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
107 this, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
109 connect(aViewer, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)),
110 this, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)));
112 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
113 this, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
115 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
117 connect(aViewer, SIGNAL(viewTransformed(int)), this, SIGNAL(viewTransformed(int)));
119 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
120 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
122 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
124 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
126 connect(aViewer, SIGNAL(tryCloseView(AppElements_ViewWindow*)),
127 this, SLOT(onTryCloseView(AppElements_ViewWindow*)));
129 connect(aViewer, SIGNAL(deleteView(AppElements_ViewWindow*)),
130 this, SLOT(onDeleteView(AppElements_ViewWindow*)));
132 connect(aViewer, SIGNAL(viewCreated(AppElements_ViewWindow*)),
133 this, SLOT(onViewCreated(AppElements_ViewWindow*)));
135 connect(aViewer, SIGNAL(activated(AppElements_ViewWindow*)),
136 this, SLOT(onActivated(AppElements_ViewWindow*)));
138 connect(aViewer, SIGNAL(mousePress(AppElements_ViewWindow*, QMouseEvent*)), this,
139 SLOT(onMousePress(AppElements_ViewWindow*, QMouseEvent*)));
141 connect(aViewer, SIGNAL(mouseRelease(AppElements_ViewWindow*, QMouseEvent*)), this,
142 SLOT(onMouseRelease(AppElements_ViewWindow*, QMouseEvent*)));
144 connect(aViewer, SIGNAL(mouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)), this,
145 SLOT(onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)));
147 connect(aViewer, SIGNAL(mouseMove(AppElements_ViewWindow*, QMouseEvent*)), this,
148 SLOT(onMouseMove(AppElements_ViewWindow*, QMouseEvent*)));
150 connect(aViewer, SIGNAL(keyPress(AppElements_ViewWindow*, QKeyEvent*)), this,
151 SLOT(onKeyPress(AppElements_ViewWindow*, QKeyEvent*)));
153 connect(aViewer, SIGNAL(keyRelease(AppElements_ViewWindow*, QKeyEvent*)), this,
154 SLOT(onKeyRelease(AppElements_ViewWindow*, QKeyEvent*)));
156 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
157 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
158 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
162 bool XGUI_ViewerProxy::eventFilter(QObject *theObject, QEvent *theEvent)
164 if (theEvent->type() == QEvent::Enter) {
165 emit enterViewPort();
167 else if (theEvent->type() == QEvent::Leave) {
168 emit leaveViewPort();
170 return ModuleBase_IViewer::eventFilter(theObject, theEvent);
173 void XGUI_ViewerProxy::onViewCreated(ModuleBase_IViewWindow* theWnd)
175 theWnd->viewPort()->installEventFilter(this);
177 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
179 emit viewCreated(theWnd);
183 void XGUI_ViewerProxy::onTryCloseView(AppElements_ViewWindow* theWnd)
185 emit tryCloseView(theWnd);
188 void XGUI_ViewerProxy::onDeleteView(AppElements_ViewWindow* theWnd)
190 if (myWindowScale.contains(theWnd->v3dView()))
191 myWindowScale.remove (theWnd->v3dView());
192 emit deleteView(theWnd);
195 void XGUI_ViewerProxy::onViewCreated(AppElements_ViewWindow* theWnd)
197 theWnd->viewPort()->installEventFilter(this);
199 connect(theWnd, SIGNAL(vpTransformationFinished(AppElements_ViewWindow::OperationType)),
200 this, SLOT(onViewTransformed(AppElements_ViewWindow::OperationType)));
202 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
204 emit viewCreated(theWnd);
207 void XGUI_ViewerProxy::onActivated(AppElements_ViewWindow* theWnd)
209 emit activated(theWnd);
212 void XGUI_ViewerProxy::onMousePress(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
214 emit mousePress(theWnd, theEvent);
217 void XGUI_ViewerProxy::onMouseRelease(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
219 emit mouseRelease(theWnd, theEvent);
222 void XGUI_ViewerProxy::onMouseDoubleClick(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
224 emit mouseDoubleClick(theWnd, theEvent);
227 void XGUI_ViewerProxy::onMouseMove(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
229 emit mouseMove(theWnd, theEvent);
232 void XGUI_ViewerProxy::onKeyPress(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
234 emit keyPress(theWnd, theEvent);
237 void XGUI_ViewerProxy::onKeyRelease(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
239 emit keyRelease(theWnd, theEvent);
242 void XGUI_ViewerProxy::onViewTransformed(AppElements_ViewWindow::OperationType theType)
244 emit viewTransformed((int) theType);
250 //***************************************
251 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
254 myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
256 myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
260 //***************************************
261 bool XGUI_ViewerProxy::isSelectionEnabled() const
264 return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
266 return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
270 //***************************************
271 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
274 myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
276 myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
280 //***************************************
281 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
284 return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
286 return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
290 //***************************************
291 bool XGUI_ViewerProxy::enableDrawMode(bool isEnabled)
294 return myWorkshop->salomeConnector()->viewer()->enableDrawMode(isEnabled);
296 return myWorkshop->mainWindow()->viewer()->enableDrawMode(isEnabled);
300 //***************************************
301 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
303 myWorkshop->displayer()->addSelectionFilter(theFilter);
306 //***************************************
307 void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
309 myWorkshop->displayer()->removeSelectionFilter(theFilter);
312 //***************************************
313 bool XGUI_ViewerProxy::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
315 return myWorkshop->displayer()->hasSelectionFilter(theFilter);
318 //***************************************
319 void XGUI_ViewerProxy::clearSelectionFilters()
321 myWorkshop->displayer()->removeFilters();
324 //***************************************
325 void XGUI_ViewerProxy::update()
327 myWorkshop->displayer()->updateViewer();
330 //***************************************
331 bool XGUI_ViewerProxy::canDragByMouse() const
333 if (myWorkshop->isSalomeMode()) {
334 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
335 return aViewer->canDragByMouse();
342 //***************************************
343 void XGUI_ViewerProxy::Zfitall()
346 myWorkshop->salomeConnector()->viewer()->Zfitall();
348 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
349 AppElements_ViewWindow* aView = aViewer->activeViewWindow();
351 Handle(V3d_View) aView3d = aView->v3dView();
353 if (aView3d->Depth() < 0.1)
354 aView3d->DepthFitAll();