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