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)
52 Handle(V3d_View) aView3d = activeView();
53 if (!aView3d.IsNull()) {
54 aView3d->SetProj(theX, theY, theZ);
55 aView3d->FitAll(0.01, true);
56 aView3d->SetZSize(0.);
60 void XGUI_ViewerProxy::fitAll()
62 if (myWorkshop->isSalomeMode()) {
63 myWorkshop->salomeConnector()->viewer()->fitAll();
65 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
66 if (aViewer->activeViewWindow())
67 aViewer->activeViewWindow()->viewPortApp()->fitAll();
71 void XGUI_ViewerProxy::connectToViewer()
73 if (myWorkshop->isSalomeMode()) {
74 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
76 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
77 connect(aViewer, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)),
78 this, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)));
80 connect(aViewer, SIGNAL(deleteView(ModuleBase_IViewWindow*)),
81 this, SIGNAL(deleteView(ModuleBase_IViewWindow*)));
83 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
84 this, SLOT(onViewCreated(ModuleBase_IViewWindow*)));
86 connect(aViewer, SIGNAL(activated(ModuleBase_IViewWindow*)),
87 this, SIGNAL(activated(ModuleBase_IViewWindow*)));
89 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
90 this, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)));
92 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
93 this, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
95 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)), this,
96 SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
98 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
99 this, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
101 connect(aViewer, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)),
102 this, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)));
104 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
105 this, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
107 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
109 connect(aViewer, SIGNAL(viewTransformed(int)), this, SIGNAL(viewTransformed(int)));
111 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
112 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
114 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
116 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
118 connect(aViewer, SIGNAL(tryCloseView(AppElements_ViewWindow*)),
119 this, SLOT(onTryCloseView(AppElements_ViewWindow*)));
121 connect(aViewer, SIGNAL(deleteView(AppElements_ViewWindow*)),
122 this, SLOT(onDeleteView(AppElements_ViewWindow*)));
124 connect(aViewer, SIGNAL(viewCreated(AppElements_ViewWindow*)),
125 this, SLOT(onViewCreated(AppElements_ViewWindow*)));
127 connect(aViewer, SIGNAL(activated(AppElements_ViewWindow*)),
128 this, SLOT(onActivated(AppElements_ViewWindow*)));
130 connect(aViewer, SIGNAL(mousePress(AppElements_ViewWindow*, QMouseEvent*)), this,
131 SLOT(onMousePress(AppElements_ViewWindow*, QMouseEvent*)));
133 connect(aViewer, SIGNAL(mouseRelease(AppElements_ViewWindow*, QMouseEvent*)), this,
134 SLOT(onMouseRelease(AppElements_ViewWindow*, QMouseEvent*)));
136 connect(aViewer, SIGNAL(mouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)), this,
137 SLOT(onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)));
139 connect(aViewer, SIGNAL(mouseMove(AppElements_ViewWindow*, QMouseEvent*)), this,
140 SLOT(onMouseMove(AppElements_ViewWindow*, QMouseEvent*)));
142 connect(aViewer, SIGNAL(keyPress(AppElements_ViewWindow*, QKeyEvent*)), this,
143 SLOT(onKeyPress(AppElements_ViewWindow*, QKeyEvent*)));
145 connect(aViewer, SIGNAL(keyRelease(AppElements_ViewWindow*, QKeyEvent*)), this,
146 SLOT(onKeyRelease(AppElements_ViewWindow*, QKeyEvent*)));
148 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
149 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
150 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
154 bool XGUI_ViewerProxy::eventFilter(QObject *theObject, QEvent *theEvent)
156 if (theEvent->type() == QEvent::Enter) {
157 emit enterViewPort();
159 else if (theEvent->type() == QEvent::Leave) {
160 emit leaveViewPort();
162 return ModuleBase_IViewer::eventFilter(theObject, theEvent);
165 void XGUI_ViewerProxy::onTryCloseView(AppElements_ViewWindow* theWnd)
167 emit tryCloseView(theWnd);
170 void XGUI_ViewerProxy::onDeleteView(AppElements_ViewWindow* theWnd)
172 if (myWindowScale.contains(theWnd->v3dView()))
173 myWindowScale.remove (theWnd->v3dView());
174 emit deleteView(theWnd);
177 void XGUI_ViewerProxy::onViewCreated(ModuleBase_IViewWindow* theWnd)
179 theWnd->viewPort()->installEventFilter(this);
181 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
183 emit viewCreated(theWnd);
186 void XGUI_ViewerProxy::onViewCreated(AppElements_ViewWindow* theWnd)
188 theWnd->viewPort()->installEventFilter(this);
190 connect(theWnd, SIGNAL(vpTransformationFinished(AppElements_ViewWindow::OperationType)),
191 this, SLOT(onViewTransformed(AppElements_ViewWindow::OperationType)));
193 myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
195 emit viewCreated(theWnd);
198 void XGUI_ViewerProxy::onActivated(AppElements_ViewWindow* theWnd)
200 emit activated(theWnd);
203 void XGUI_ViewerProxy::onMousePress(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
205 emit mousePress(theWnd, theEvent);
208 void XGUI_ViewerProxy::onMouseRelease(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
210 emit mouseRelease(theWnd, theEvent);
213 void XGUI_ViewerProxy::onMouseDoubleClick(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
215 emit mouseDoubleClick(theWnd, theEvent);
218 void XGUI_ViewerProxy::onMouseMove(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
220 emit mouseMove(theWnd, theEvent);
223 void XGUI_ViewerProxy::onKeyPress(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
225 emit keyPress(theWnd, theEvent);
228 void XGUI_ViewerProxy::onKeyRelease(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
230 emit keyRelease(theWnd, theEvent);
235 //***************************************
236 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
238 if (myWorkshop->isSalomeMode()) {
239 myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
241 myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
245 //***************************************
246 bool XGUI_ViewerProxy::isSelectionEnabled() const
248 if (myWorkshop->isSalomeMode()) {
249 return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
251 return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
255 //***************************************
256 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
258 if (myWorkshop->isSalomeMode()) {
259 myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
261 myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
265 //***************************************
266 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
268 if (myWorkshop->isSalomeMode()) {
269 return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
271 return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
275 //***************************************
276 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
278 myWorkshop->displayer()->addSelectionFilter(theFilter);
281 //***************************************
282 void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
284 myWorkshop->displayer()->removeSelectionFilter(theFilter);
287 //***************************************
288 void XGUI_ViewerProxy::clearSelectionFilters()
290 myWorkshop->displayer()->removeFilters();
293 //***************************************
294 void XGUI_ViewerProxy::update()
296 myWorkshop->displayer()->updateViewer();
299 //***************************************
300 bool XGUI_ViewerProxy::canDragByMouse() const
302 if (myWorkshop->isSalomeMode()) {
303 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
304 return aViewer->canDragByMouse();
310 //***************************************
311 void XGUI_ViewerProxy::onViewTransformed(AppElements_ViewWindow::OperationType theType)
313 emit viewTransformed((int) theType);