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