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"
10 XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
11 : ModuleBase_IViewer(theParent),
16 Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
18 if (myWorkshop->isSalomeMode()) {
19 return myWorkshop->salomeConnector()->viewer()->AISContext();
21 return myWorkshop->mainWindow()->viewer()->AISContext();
25 Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const
27 if (myWorkshop->isSalomeMode()) {
28 return myWorkshop->salomeConnector()->viewer()->v3dViewer();
30 return myWorkshop->mainWindow()->viewer()->v3dViewer();
34 Handle(V3d_View) XGUI_ViewerProxy::activeView() const
36 if (myWorkshop->isSalomeMode()) {
37 return myWorkshop->salomeConnector()->viewer()->activeView();
39 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
40 return (aViewer->activeViewWindow()) ? aViewer->activeViewWindow()->viewPort()->getView() :
45 void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ)
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.);
55 void XGUI_ViewerProxy::fitAll()
57 if (myWorkshop->isSalomeMode()) {
58 myWorkshop->salomeConnector()->viewer()->fitAll();
60 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
61 if (aViewer->activeViewWindow())
62 aViewer->activeViewWindow()->viewPort()->fitAll();
66 void XGUI_ViewerProxy::connectToViewer()
68 if (myWorkshop->isSalomeMode()) {
69 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
71 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
72 connect(aViewer, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)),
73 this, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)));
75 connect(aViewer, SIGNAL(deleteView(ModuleBase_IViewWindow*)),
76 this, SIGNAL(deleteView(ModuleBase_IViewWindow*)));
78 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
79 this, SIGNAL(viewCreated(ModuleBase_IViewWindow*)));
81 connect(aViewer, SIGNAL(activated(ModuleBase_IViewWindow*)),
82 this, SIGNAL(activated(ModuleBase_IViewWindow*)));
84 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
85 this, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)));
87 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
88 this, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
90 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)), this,
91 SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
93 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
94 this, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
96 connect(aViewer, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)),
97 this, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)));
99 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
100 this, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
102 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
103 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
104 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
107 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
109 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
111 connect(aViewer, SIGNAL(tryCloseView(XGUI_ViewWindow*)),
112 this, SLOT(onTryCloseView(XGUI_ViewWindow*)));
114 connect(aViewer, SIGNAL(deleteView(XGUI_ViewWindow*)),
115 this, SLOT(onDeleteView(XGUI_ViewWindow*)));
117 connect(aViewer, SIGNAL(viewCreated(XGUI_ViewWindow*)),
118 this, SLOT(onViewCreated(XGUI_ViewWindow*)));
120 connect(aViewer, SIGNAL(activated(XGUI_ViewWindow*)),
121 this, SLOT(onActivated(XGUI_ViewWindow*)));
123 connect(aViewer, SIGNAL(mousePress(XGUI_ViewWindow*, QMouseEvent*)), this,
124 SLOT(onMousePress(XGUI_ViewWindow*, QMouseEvent*)));
126 connect(aViewer, SIGNAL(mouseRelease(XGUI_ViewWindow*, QMouseEvent*)), this,
127 SLOT(onMouseRelease(XGUI_ViewWindow*, QMouseEvent*)));
129 connect(aViewer, SIGNAL(mouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*)), this,
130 SLOT(onMouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*)));
132 connect(aViewer, SIGNAL(mouseMove(XGUI_ViewWindow*, QMouseEvent*)), this,
133 SLOT(onMouseMove(XGUI_ViewWindow*, QMouseEvent*)));
135 connect(aViewer, SIGNAL(keyPress(XGUI_ViewWindow*, QKeyEvent*)), this,
136 SLOT(onKeyPress(XGUI_ViewWindow*, QKeyEvent*)));
138 connect(aViewer, SIGNAL(keyRelease(XGUI_ViewWindow*, QKeyEvent*)), this,
139 SLOT(onKeyRelease(XGUI_ViewWindow*, QKeyEvent*)));
141 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
142 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
143 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
148 void XGUI_ViewerProxy::onTryCloseView(XGUI_ViewWindow* theWnd)
150 emit tryCloseView(theWnd);
153 void XGUI_ViewerProxy::onDeleteView(XGUI_ViewWindow* theWnd)
155 emit deleteView(theWnd);
158 void XGUI_ViewerProxy::onViewCreated(XGUI_ViewWindow* theWnd)
160 emit viewCreated(theWnd);
163 void XGUI_ViewerProxy::onActivated(XGUI_ViewWindow* theWnd)
165 emit activated(theWnd);
168 void XGUI_ViewerProxy::onMousePress(XGUI_ViewWindow* theWnd, QMouseEvent* theEvent)
170 emit mousePress(theWnd, theEvent);
173 void XGUI_ViewerProxy::onMouseRelease(XGUI_ViewWindow* theWnd, QMouseEvent* theEvent)
175 emit mouseRelease(theWnd, theEvent);
178 void XGUI_ViewerProxy::onMouseDoubleClick(XGUI_ViewWindow* theWnd, QMouseEvent* theEvent)
180 emit mouseDoubleClick(theWnd, theEvent);
183 void XGUI_ViewerProxy::onMouseMove(XGUI_ViewWindow* theWnd, QMouseEvent* theEvent)
185 emit mouseMove(theWnd, theEvent);
188 void XGUI_ViewerProxy::onKeyPress(XGUI_ViewWindow* theWnd, QKeyEvent* theEvent)
190 emit keyPress(theWnd, theEvent);
193 void XGUI_ViewerProxy::onKeyRelease(XGUI_ViewWindow* theWnd, QKeyEvent* theEvent)
195 emit keyRelease(theWnd, theEvent);
200 //***************************************
201 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
203 if (myWorkshop->isSalomeMode()) {
204 myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
206 myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
210 //***************************************
211 bool XGUI_ViewerProxy::isSelectionEnabled() const
213 if (myWorkshop->isSalomeMode()) {
214 return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
216 return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
220 //***************************************
221 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
223 if (myWorkshop->isSalomeMode()) {
224 myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
226 myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
230 //***************************************
231 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
233 if (myWorkshop->isSalomeMode()) {
234 return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
236 return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
240 //***************************************
241 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
243 myWorkshop->displayer()->addSelectionFilter(theFilter);
246 //***************************************
247 void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
249 myWorkshop->displayer()->removeSelectionFilter(theFilter);
252 //***************************************
253 void XGUI_ViewerProxy::clearSelectionFilters()
255 myWorkshop->displayer()->removeFilters();