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