]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ViewerProxy.cpp
Salome HOME
Issue #2159 Hide all incomplete behavior
[modules/shaper.git] / src / XGUI / XGUI_ViewerProxy.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 #include "XGUI_ViewerProxy.h"
4 #include "XGUI_Workshop.h"
5 #include "XGUI_SalomeConnector.h"
6 #include "XGUI_Displayer.h"
7
8 #ifndef HAVE_SALOME
9   #include <AppElements_MainWindow.h>
10   #include <AppElements_ViewPort.h>
11   #include <AppElements_ViewWindow.h>
12   #include <AppElements_Viewer.h>
13 #endif
14
15 #include <ModuleBase_IViewWindow.h>
16
17 #include <QEvent>
18
19 XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
20     : ModuleBase_IViewer(theParent),
21       myWorkshop(theParent)
22 {
23 }
24
25 void XGUI_ViewerProxy::connectViewProxy()
26 {
27 #ifdef HAVE_SALOME
28   connect(myWorkshop->salomeConnector()->viewer(), SIGNAL(trihedronVisibilityChanged(bool)),
29          SIGNAL(trihedronVisibilityChanged(bool)));
30 #else
31   connect(myWorkshop->mainWindow()->viewer(), SIGNAL(trihedronVisibilityChanged(bool)),
32          SIGNAL(trihedronVisibilityChanged(bool)));
33 #endif
34 }
35
36 Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
37 {
38   Handle(AIS_InteractiveContext) aContext;
39 #ifdef HAVE_SALOME
40   aContext = myWorkshop->salomeConnector()->viewer()->AISContext();
41 #else
42   aContext = myWorkshop->mainWindow()->viewer()->AISContext();
43 #endif
44   return aContext;
45 }
46
47 Handle(AIS_Trihedron) XGUI_ViewerProxy::trihedron() const
48 {
49 #ifdef HAVE_SALOME
50   return myWorkshop->salomeConnector()->viewer()->trihedron();
51 #else
52   return myWorkshop->mainWindow()->viewer()->trihedron();
53 #endif
54 }
55
56 Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const
57 {
58 #ifdef HAVE_SALOME
59   return myWorkshop->salomeConnector()->viewer()->v3dViewer();
60 #else
61   return myWorkshop->mainWindow()->viewer()->v3dViewer();
62 #endif
63 }
64
65 Handle(V3d_View) XGUI_ViewerProxy::activeView() const
66 {
67 #ifdef HAVE_SALOME
68   return myWorkshop->salomeConnector()->viewer()->activeView();
69 #else
70   AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
71   return (aViewer->activeViewWindow()) ?
72     aViewer->activeViewWindow()->viewPortApp()->getView() :
73     Handle(V3d_View)();
74 #endif
75 }
76
77 QWidget* XGUI_ViewerProxy::activeViewPort() const
78 {
79 #ifdef HAVE_SALOME
80   return myWorkshop->salomeConnector()->viewer()->activeViewPort();
81 #else
82   AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
83   return (aViewer->activeViewWindow()) ?
84          aViewer->activeViewWindow()->viewPortApp(): 0;
85 #endif
86 }
87
88 void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ, double theTwist)
89 {
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();
98   }
99 }
100
101 void XGUI_ViewerProxy::fitAll()
102 {
103 #ifdef HAVE_SALOME
104   myWorkshop->salomeConnector()->viewer()->fitAll();
105 #else
106   AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
107   if (aViewer->activeViewWindow())
108     aViewer->activeViewWindow()->viewPortApp()->fitAll();
109 #endif
110 }
111
112 void XGUI_ViewerProxy::eraseAll()
113 {
114 #ifdef HAVE_SALOME
115   myWorkshop->salomeConnector()->viewer()->eraseAll();
116 #else
117 #endif
118 }
119
120 void XGUI_ViewerProxy::connectToViewer()
121 {
122 #ifdef HAVE_SALOME
123   ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
124
125   connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
126   connect(aViewer, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)),
127     this, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)));
128
129   connect(aViewer, SIGNAL(deleteView(ModuleBase_IViewWindow*)),
130     this, SIGNAL(deleteView(ModuleBase_IViewWindow*)));
131
132   connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
133     this, SLOT(onViewCreated(ModuleBase_IViewWindow*)));
134
135   connect(aViewer, SIGNAL(activated(ModuleBase_IViewWindow*)),
136     this, SIGNAL(activated(ModuleBase_IViewWindow*)));
137
138   connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
139     this, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)));
140
141   connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
142     this, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
143
144   connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)), this,
145           SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
146
147   connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
148     this, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
149
150   connect(aViewer, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)),
151     this, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)));
152
153   connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
154     this, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
155
156   connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
157
158   connect(aViewer, SIGNAL(viewTransformed(int)), this, SIGNAL(viewTransformed(int)));
159
160   connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
161           SIGNAL(contextMenuRequested(QContextMenuEvent*)));
162 #else
163   AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
164
165   connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
166
167   connect(aViewer, SIGNAL(tryCloseView(AppElements_ViewWindow*)),
168           this, SLOT(onTryCloseView(AppElements_ViewWindow*)));
169
170   connect(aViewer, SIGNAL(deleteView(AppElements_ViewWindow*)),
171           this, SLOT(onDeleteView(AppElements_ViewWindow*)));
172
173   connect(aViewer, SIGNAL(viewCreated(AppElements_ViewWindow*)),
174           this, SLOT(onViewCreated(AppElements_ViewWindow*)));
175
176   connect(aViewer, SIGNAL(activated(AppElements_ViewWindow*)),
177           this, SLOT(onActivated(AppElements_ViewWindow*)));
178
179   connect(aViewer, SIGNAL(mousePress(AppElements_ViewWindow*, QMouseEvent*)), this,
180           SLOT(onMousePress(AppElements_ViewWindow*, QMouseEvent*)));
181
182   connect(aViewer, SIGNAL(mouseRelease(AppElements_ViewWindow*, QMouseEvent*)), this,
183           SLOT(onMouseRelease(AppElements_ViewWindow*, QMouseEvent*)));
184
185   connect(aViewer, SIGNAL(mouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)), this,
186           SLOT(onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)));
187
188   connect(aViewer, SIGNAL(mouseMove(AppElements_ViewWindow*, QMouseEvent*)), this,
189           SLOT(onMouseMove(AppElements_ViewWindow*, QMouseEvent*)));
190
191   connect(aViewer, SIGNAL(keyPress(AppElements_ViewWindow*, QKeyEvent*)), this,
192           SLOT(onKeyPress(AppElements_ViewWindow*, QKeyEvent*)));
193
194   connect(aViewer, SIGNAL(keyRelease(AppElements_ViewWindow*, QKeyEvent*)), this,
195           SLOT(onKeyRelease(AppElements_ViewWindow*, QKeyEvent*)));
196
197   connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
198   connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
199           SIGNAL(contextMenuRequested(QContextMenuEvent*)));
200 #endif
201 }
202
203 bool XGUI_ViewerProxy::eventFilter(QObject *theObject, QEvent *theEvent)
204 {
205   if (theEvent->type() == QEvent::Enter) {
206     emit enterViewPort();
207   }
208   else if (theEvent->type() == QEvent::Leave) {
209     emit leaveViewPort();
210   }
211   return ModuleBase_IViewer::eventFilter(theObject, theEvent);
212 }
213
214 void XGUI_ViewerProxy::onViewCreated(ModuleBase_IViewWindow* theWnd)
215 {
216   theWnd->viewPort()->installEventFilter(this);
217
218   myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
219
220   emit viewCreated(theWnd);
221 }
222
223 #ifndef HAVE_SALOME
224 void XGUI_ViewerProxy::onTryCloseView(AppElements_ViewWindow* theWnd)
225 {
226   emit tryCloseView(theWnd);
227 }
228
229 void XGUI_ViewerProxy::onDeleteView(AppElements_ViewWindow* theWnd)
230 {
231   if (myWindowScale.contains(theWnd->v3dView()))
232     myWindowScale.remove (theWnd->v3dView());
233   emit deleteView(theWnd);
234 }
235
236 void XGUI_ViewerProxy::onViewCreated(AppElements_ViewWindow* theWnd)
237 {
238   theWnd->viewPort()->installEventFilter(this);
239
240   connect(theWnd, SIGNAL(vpTransformationFinished(AppElements_ViewWindow::OperationType)),
241     this, SLOT(onViewTransformed(AppElements_ViewWindow::OperationType)));
242
243   myWindowScale.insert (theWnd->v3dView(), theWnd->v3dView()->Camera()->Scale());
244
245   emit viewCreated(theWnd);
246 }
247
248 void XGUI_ViewerProxy::onActivated(AppElements_ViewWindow* theWnd)
249 {
250   emit activated(theWnd);
251 }
252
253 void XGUI_ViewerProxy::onMousePress(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
254 {
255   emit mousePress(theWnd, theEvent);
256 }
257
258 void XGUI_ViewerProxy::onMouseRelease(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
259 {
260   emit mouseRelease(theWnd, theEvent);
261 }
262
263 void XGUI_ViewerProxy::onMouseDoubleClick(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
264 {
265   emit mouseDoubleClick(theWnd, theEvent);
266 }
267
268 void XGUI_ViewerProxy::onMouseMove(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
269 {
270   emit mouseMove(theWnd, theEvent);
271 }
272
273 void XGUI_ViewerProxy::onKeyPress(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
274 {
275   emit keyPress(theWnd, theEvent);
276 }
277
278 void XGUI_ViewerProxy::onKeyRelease(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
279 {
280   emit keyRelease(theWnd, theEvent);
281 }
282
283 void XGUI_ViewerProxy::onViewTransformed(AppElements_ViewWindow::OperationType theType)
284 {
285   emit viewTransformed((int) theType);
286 }
287
288 #endif
289
290
291 //***************************************
292 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
293 {
294 #ifdef HAVE_SALOME
295   myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
296 #else
297   myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
298 #endif
299 }
300
301 //***************************************
302 bool XGUI_ViewerProxy::isSelectionEnabled() const
303 {
304 #ifdef HAVE_SALOME
305   return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
306 #else
307   return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
308 #endif
309 }
310
311 //***************************************
312 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
313 {
314 #ifdef HAVE_SALOME
315   myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
316 #else
317   myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
318 #endif
319 }
320
321 //***************************************
322 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
323 {
324 #ifdef HAVE_SALOME
325   return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
326 #else
327   return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
328 #endif
329 }
330
331 //***************************************
332 bool XGUI_ViewerProxy::enableDrawMode(bool isEnabled)
333 {
334 #ifdef HAVE_SALOME
335   return myWorkshop->salomeConnector()->viewer()->enableDrawMode(isEnabled);
336 #else
337   return myWorkshop->mainWindow()->viewer()->enableDrawMode(isEnabled);
338 #endif
339 }
340
341 //***************************************
342 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
343 {
344   myWorkshop->displayer()->addSelectionFilter(theFilter);
345 }
346
347 //***************************************
348 void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
349 {
350   myWorkshop->displayer()->removeSelectionFilter(theFilter);
351 }
352
353 //***************************************
354 bool XGUI_ViewerProxy::hasSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
355 {
356   return myWorkshop->displayer()->hasSelectionFilter(theFilter);
357 }
358
359 //***************************************
360 void XGUI_ViewerProxy::clearSelectionFilters()
361 {
362   myWorkshop->displayer()->removeFilters();
363 }
364
365 //***************************************
366 void XGUI_ViewerProxy::update()
367 {
368   myWorkshop->displayer()->updateViewer();
369 }
370
371 //***************************************
372 bool XGUI_ViewerProxy::canDragByMouse() const
373 {
374   if (myWorkshop->isSalomeMode()) {
375     ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
376     return aViewer->canDragByMouse();
377   } else {
378     return true;
379   }
380 }
381
382
383 //***************************************
384 //void XGUI_ViewerProxy::Zfitall()
385 //{
386 //#ifdef HAVE_SALOME
387 //  myWorkshop->salomeConnector()->viewer()->Zfitall();
388 //#else
389 //  AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
390 //  AppElements_ViewWindow* aView = aViewer->activeViewWindow();
391 //  if (aView) {
392 //    Handle(V3d_View) aView3d = aView->v3dView();
393 //    aView3d->ZFitAll();
394 //    if (aView3d->Depth() < 0.1)
395 //      aView3d->DepthFitAll();
396 //  }
397 //#endif
398 //}