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