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"
8 #include <AppElements_MainWindow.h>
9 #include <AppElements_ViewPort.h>
10 #include <AppElements_ViewWindow.h>
11 #include <AppElements_Viewer.h>
15 XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
16 : ModuleBase_IViewer(theParent),
21 Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
23 if (myWorkshop->isSalomeMode()) {
24 return myWorkshop->salomeConnector()->viewer()->AISContext();
26 return myWorkshop->mainWindow()->viewer()->AISContext();
30 Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const
32 if (myWorkshop->isSalomeMode()) {
33 return myWorkshop->salomeConnector()->viewer()->v3dViewer();
35 return myWorkshop->mainWindow()->viewer()->v3dViewer();
39 Handle(V3d_View) XGUI_ViewerProxy::activeView() const
41 if (myWorkshop->isSalomeMode()) {
42 return myWorkshop->salomeConnector()->viewer()->activeView();
44 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
45 return (aViewer->activeViewWindow()) ? aViewer->activeViewWindow()->viewPortApp()->getView() :
50 void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ, double theTwist)
52 Handle(V3d_View) aView3d = activeView();
53 if (!aView3d.IsNull()) {
54 aView3d->SetProj(theX, theY, theZ);
55 aView3d->SetTwist( theTwist );
56 aView3d->FitAll(0.01, true);
57 aView3d->SetZSize(0.);
61 void XGUI_ViewerProxy::fitAll()
63 if (myWorkshop->isSalomeMode()) {
64 myWorkshop->salomeConnector()->viewer()->fitAll();
66 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
67 if (aViewer->activeViewWindow())
68 aViewer->activeViewWindow()->viewPortApp()->fitAll();
72 void XGUI_ViewerProxy::connectToViewer()
74 if (myWorkshop->isSalomeMode()) {
75 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
77 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
78 connect(aViewer, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)),
79 this, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)));
81 connect(aViewer, SIGNAL(deleteView(ModuleBase_IViewWindow*)),
82 this, SIGNAL(deleteView(ModuleBase_IViewWindow*)));
84 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
85 this, SLOT(onViewCreated(ModuleBase_IViewWindow*)));
87 connect(aViewer, SIGNAL(activated(ModuleBase_IViewWindow*)),
88 this, SIGNAL(activated(ModuleBase_IViewWindow*)));
90 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
91 this, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)));
93 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
94 this, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
96 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)), this,
97 SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
99 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
100 this, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
102 connect(aViewer, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)),
103 this, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)));
105 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
106 this, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
108 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
110 connect(aViewer, SIGNAL(viewTransformed(int)), this, SIGNAL(viewTransformed(int)));
112 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
113 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
115 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
117 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
119 connect(aViewer, SIGNAL(tryCloseView(AppElements_ViewWindow*)),
120 this, SLOT(onTryCloseView(AppElements_ViewWindow*)));
122 connect(aViewer, SIGNAL(deleteView(AppElements_ViewWindow*)),
123 this, SLOT(onDeleteView(AppElements_ViewWindow*)));
125 connect(aViewer, SIGNAL(viewCreated(AppElements_ViewWindow*)),
126 this, SLOT(onViewCreated(AppElements_ViewWindow*)));
128 connect(aViewer, SIGNAL(activated(AppElements_ViewWindow*)),
129 this, SLOT(onActivated(AppElements_ViewWindow*)));
131 connect(aViewer, SIGNAL(mousePress(AppElements_ViewWindow*, QMouseEvent*)), this,
132 SLOT(onMousePress(AppElements_ViewWindow*, QMouseEvent*)));
134 connect(aViewer, SIGNAL(mouseRelease(AppElements_ViewWindow*, QMouseEvent*)), this,
135 SLOT(onMouseRelease(AppElements_ViewWindow*, QMouseEvent*)));
137 connect(aViewer, SIGNAL(mouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)), this,
138 SLOT(onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)));
140 connect(aViewer, SIGNAL(mouseMove(AppElements_ViewWindow*, QMouseEvent*)), this,
141 SLOT(onMouseMove(AppElements_ViewWindow*, QMouseEvent*)));
143 connect(aViewer, SIGNAL(keyPress(AppElements_ViewWindow*, QKeyEvent*)), this,
144 SLOT(onKeyPress(AppElements_ViewWindow*, QKeyEvent*)));
146 connect(aViewer, SIGNAL(keyRelease(AppElements_ViewWindow*, QKeyEvent*)), this,
147 SLOT(onKeyRelease(AppElements_ViewWindow*, QKeyEvent*)));
149 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
150 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
151 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
155 bool XGUI_ViewerProxy::eventFilter(QObject *theObject, QEvent *theEvent)
157 if (theEvent->type() == QEvent::Enter) {
158 emit enterViewPort();
160 else if (theEvent->type() == QEvent::Leave) {
161 emit leaveViewPort();
163 return ModuleBase_IViewer::eventFilter(theObject, theEvent);
166 void XGUI_ViewerProxy::onTryCloseView(AppElements_ViewWindow* theWnd)
168 emit tryCloseView(theWnd);
171 void XGUI_ViewerProxy::onDeleteView(AppElements_ViewWindow* theWnd)
173 if (myWindowScale.contains(theWnd->v3dView()))
174 myWindowScale.remove (theWnd->v3dView());
175 emit deleteView(theWnd);
178 void XGUI_ViewerProxy::onViewCreated(ModuleBase_IViewWindow* theWnd)
180 theWnd->viewPort()->installEventFilter(this);
182 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
184 emit viewCreated(theWnd);
187 void XGUI_ViewerProxy::onViewCreated(AppElements_ViewWindow* theWnd)
189 theWnd->viewPort()->installEventFilter(this);
191 connect(theWnd, SIGNAL(vpTransformationFinished(AppElements_ViewWindow::OperationType)),
192 this, SLOT(onViewTransformed(AppElements_ViewWindow::OperationType)));
194 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
196 emit viewCreated(theWnd);
199 void XGUI_ViewerProxy::onActivated(AppElements_ViewWindow* theWnd)
201 emit activated(theWnd);
204 void XGUI_ViewerProxy::onMousePress(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
206 emit mousePress(theWnd, theEvent);
209 void XGUI_ViewerProxy::onMouseRelease(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
211 emit mouseRelease(theWnd, theEvent);
214 void XGUI_ViewerProxy::onMouseDoubleClick(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
216 emit mouseDoubleClick(theWnd, theEvent);
219 void XGUI_ViewerProxy::onMouseMove(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
221 emit mouseMove(theWnd, theEvent);
224 void XGUI_ViewerProxy::onKeyPress(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
226 emit keyPress(theWnd, theEvent);
229 void XGUI_ViewerProxy::onKeyRelease(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
231 emit keyRelease(theWnd, theEvent);
236 //***************************************
237 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
239 if (myWorkshop->isSalomeMode()) {
240 myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
242 myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
246 //***************************************
247 bool XGUI_ViewerProxy::isSelectionEnabled() const
249 if (myWorkshop->isSalomeMode()) {
250 return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
252 return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
256 //***************************************
257 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
259 if (myWorkshop->isSalomeMode()) {
260 myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
262 myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
266 //***************************************
267 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
269 if (myWorkshop->isSalomeMode()) {
270 return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
272 return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
276 //***************************************
277 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
279 myWorkshop->displayer()->addSelectionFilter(theFilter);
282 //***************************************
283 void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
285 myWorkshop->displayer()->removeSelectionFilter(theFilter);
288 //***************************************
289 bool XGUI_ViewerProxy::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
291 return myWorkshop->displayer()->hasSelectionFilter(theFilter);
294 //***************************************
295 void XGUI_ViewerProxy::clearSelectionFilters()
297 myWorkshop->displayer()->removeFilters();
300 //***************************************
301 void XGUI_ViewerProxy::update()
303 myWorkshop->displayer()->updateViewer();
306 //***************************************
307 bool XGUI_ViewerProxy::canDragByMouse() const
309 if (myWorkshop->isSalomeMode()) {
310 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
311 return aViewer->canDragByMouse();
317 //***************************************
318 void XGUI_ViewerProxy::onViewTransformed(AppElements_ViewWindow::OperationType theType)
320 emit viewTransformed((int) theType);
324 //***************************************
325 void XGUI_ViewerProxy::Zfitall()
327 if (myWorkshop->isSalomeMode()) {
328 myWorkshop->salomeConnector()->viewer()->Zfitall();
330 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
331 AppElements_ViewWindow* aView = aViewer->activeViewWindow();
333 aView->v3dView()->ZFitAll();