Salome HOME
Issue #273: Add copyright string
[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 XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
14     : ModuleBase_IViewer(theParent),
15       myWorkshop(theParent)
16 {
17 }
18
19 Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
20 {
21   if (myWorkshop->isSalomeMode()) {
22     return myWorkshop->salomeConnector()->viewer()->AISContext();
23   } else {
24     return myWorkshop->mainWindow()->viewer()->AISContext();
25   }
26 }
27
28 Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const
29 {
30   if (myWorkshop->isSalomeMode()) {
31     return myWorkshop->salomeConnector()->viewer()->v3dViewer();
32   } else {
33     return myWorkshop->mainWindow()->viewer()->v3dViewer();
34   }
35 }
36
37 Handle(V3d_View) XGUI_ViewerProxy::activeView() const
38 {
39   if (myWorkshop->isSalomeMode()) {
40     return myWorkshop->salomeConnector()->viewer()->activeView();
41   } else {
42     AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
43     return (aViewer->activeViewWindow()) ? aViewer->activeViewWindow()->viewPort()->getView() :
44     Handle(V3d_View)();
45   }
46 }
47
48 void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ)
49 {
50   Handle(V3d_View) aView3d = activeView();
51   if (!aView3d.IsNull()) {
52     aView3d->SetProj(theX, theY, theZ);
53     aView3d->FitAll(0.01, true, true);
54     aView3d->SetZSize(0.);
55   }
56 }
57
58 void XGUI_ViewerProxy::fitAll()
59 {
60   if (myWorkshop->isSalomeMode()) {
61     myWorkshop->salomeConnector()->viewer()->fitAll();
62   } else {
63     AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
64     if (aViewer->activeViewWindow())
65       aViewer->activeViewWindow()->viewPort()->fitAll();
66   }
67 }
68
69 void XGUI_ViewerProxy::connectToViewer()
70 {
71   if (myWorkshop->isSalomeMode()) {
72     ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
73
74     connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
75     connect(aViewer, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)), 
76       this, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)));
77
78     connect(aViewer, SIGNAL(deleteView(ModuleBase_IViewWindow*)), 
79       this, SIGNAL(deleteView(ModuleBase_IViewWindow*)));
80
81     connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)), 
82       this, SIGNAL(viewCreated(ModuleBase_IViewWindow*)));
83
84     connect(aViewer, SIGNAL(activated(ModuleBase_IViewWindow*)), 
85       this, SIGNAL(activated(ModuleBase_IViewWindow*)));
86
87     connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)), 
88       this, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)));
89
90     connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)), 
91       this, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
92
93     connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)), this,
94             SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
95
96     connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)), 
97       this, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
98
99     connect(aViewer, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)), 
100       this, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)));
101
102     connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)), 
103       this, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
104
105     connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
106     connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
107             SIGNAL(contextMenuRequested(QContextMenuEvent*)));
108
109   } else {
110     AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
111
112     connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
113
114     connect(aViewer, SIGNAL(tryCloseView(AppElements_ViewWindow*)), 
115             this, SLOT(onTryCloseView(AppElements_ViewWindow*)));
116
117     connect(aViewer, SIGNAL(deleteView(AppElements_ViewWindow*)), 
118             this, SLOT(onDeleteView(AppElements_ViewWindow*)));
119
120     connect(aViewer, SIGNAL(viewCreated(AppElements_ViewWindow*)), 
121             this, SLOT(onViewCreated(AppElements_ViewWindow*)));
122
123     connect(aViewer, SIGNAL(activated(AppElements_ViewWindow*)), 
124             this, SLOT(onActivated(AppElements_ViewWindow*)));
125
126     connect(aViewer, SIGNAL(mousePress(AppElements_ViewWindow*, QMouseEvent*)), this,
127             SLOT(onMousePress(AppElements_ViewWindow*, QMouseEvent*)));
128
129     connect(aViewer, SIGNAL(mouseRelease(AppElements_ViewWindow*, QMouseEvent*)), this,
130             SLOT(onMouseRelease(AppElements_ViewWindow*, QMouseEvent*)));
131
132     connect(aViewer, SIGNAL(mouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)), this,
133             SLOT(onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)));
134
135     connect(aViewer, SIGNAL(mouseMove(AppElements_ViewWindow*, QMouseEvent*)), this,
136             SLOT(onMouseMove(AppElements_ViewWindow*, QMouseEvent*)));
137
138     connect(aViewer, SIGNAL(keyPress(AppElements_ViewWindow*, QKeyEvent*)), this,
139             SLOT(onKeyPress(AppElements_ViewWindow*, QKeyEvent*)));
140
141     connect(aViewer, SIGNAL(keyRelease(AppElements_ViewWindow*, QKeyEvent*)), this,
142             SLOT(onKeyRelease(AppElements_ViewWindow*, QKeyEvent*)));
143
144     connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
145     connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
146             SIGNAL(contextMenuRequested(QContextMenuEvent*)));
147   }
148 }
149
150
151 void XGUI_ViewerProxy::onTryCloseView(AppElements_ViewWindow* theWnd)
152 {
153   emit tryCloseView(theWnd);
154 }
155
156 void XGUI_ViewerProxy::onDeleteView(AppElements_ViewWindow* theWnd)
157 {
158   emit deleteView(theWnd);
159 }
160
161 void XGUI_ViewerProxy::onViewCreated(AppElements_ViewWindow* theWnd)
162 {
163   emit viewCreated(theWnd);
164 }
165
166 void XGUI_ViewerProxy::onActivated(AppElements_ViewWindow* theWnd)
167 {
168   emit activated(theWnd);
169 }
170
171 void XGUI_ViewerProxy::onMousePress(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
172 {
173   emit mousePress(theWnd, theEvent);
174 }
175
176 void XGUI_ViewerProxy::onMouseRelease(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
177 {
178   emit mouseRelease(theWnd, theEvent);
179 }
180
181 void XGUI_ViewerProxy::onMouseDoubleClick(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
182 {
183   emit mouseDoubleClick(theWnd, theEvent);
184 }
185
186 void XGUI_ViewerProxy::onMouseMove(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
187 {
188   emit mouseMove(theWnd, theEvent);
189 }
190
191 void XGUI_ViewerProxy::onKeyPress(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
192 {
193   emit keyPress(theWnd, theEvent);
194 }
195
196 void XGUI_ViewerProxy::onKeyRelease(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
197 {
198   emit keyRelease(theWnd, theEvent);
199 }
200
201
202
203 //***************************************
204 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
205 {
206   if (myWorkshop->isSalomeMode()) {
207     myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
208   } else {
209     myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
210   }
211 }
212
213 //***************************************
214 bool XGUI_ViewerProxy::isSelectionEnabled() const
215 {
216   if (myWorkshop->isSalomeMode()) {
217     return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
218   } else {
219     return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
220   }
221 }
222
223 //***************************************
224 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
225 {
226   if (myWorkshop->isSalomeMode()) {
227     myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
228   } else {
229     myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
230   }
231 }
232
233 //***************************************
234 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
235 {
236   if (myWorkshop->isSalomeMode()) {
237     return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
238   } else {
239     return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
240   }
241 }
242
243 //***************************************
244 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
245 {
246   myWorkshop->displayer()->addSelectionFilter(theFilter);
247 }
248
249 //***************************************
250 void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
251 {
252   myWorkshop->displayer()->removeSelectionFilter(theFilter);
253 }
254
255 //***************************************
256 void XGUI_ViewerProxy::clearSelectionFilters()
257 {
258   myWorkshop->displayer()->removeFilters();
259 }