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"
9 XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
10 : ModuleBase_IViewer(theParent),
15 Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
17 if (myWorkshop->isSalomeMode()) {
18 return myWorkshop->salomeConnector()->viewer()->AISContext();
20 return myWorkshop->mainWindow()->viewer()->AISContext();
24 Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const
26 if (myWorkshop->isSalomeMode()) {
27 return myWorkshop->salomeConnector()->viewer()->v3dViewer();
29 return myWorkshop->mainWindow()->viewer()->v3dViewer();
33 Handle(V3d_View) XGUI_ViewerProxy::activeView() const
35 if (myWorkshop->isSalomeMode()) {
36 return myWorkshop->salomeConnector()->viewer()->activeView();
38 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
39 return (aViewer->activeViewWindow()) ? aViewer->activeViewWindow()->viewPort()->getView() :
44 void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ)
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.);
54 void XGUI_ViewerProxy::fitAll()
56 if (myWorkshop->isSalomeMode()) {
57 myWorkshop->salomeConnector()->viewer()->fitAll();
59 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
60 if (aViewer->activeViewWindow())
61 aViewer->activeViewWindow()->viewPort()->fitAll();
65 void XGUI_ViewerProxy::connectToViewer()
67 if (myWorkshop->isSalomeMode()) {
68 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
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()));
76 connect(aViewer, SIGNAL(mousePress(QMouseEvent*)), this, SIGNAL(mousePress(QMouseEvent*)));
78 connect(aViewer, SIGNAL(mouseRelease(QMouseEvent*)), this, SIGNAL(mouseRelease(QMouseEvent*)));
80 connect(aViewer, SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
81 SIGNAL(mouseDoubleClick(QMouseEvent*)));
83 connect(aViewer, SIGNAL(mouseMove(QMouseEvent*)), this, SIGNAL(mouseMove(QMouseEvent*)));
85 connect(aViewer, SIGNAL(keyPress(QKeyEvent*)), this, SIGNAL(keyPress(QKeyEvent*)));
87 connect(aViewer, SIGNAL(keyRelease(QKeyEvent*)), this, SIGNAL(keyRelease(QKeyEvent*)));
89 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
90 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
91 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
94 XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
96 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
98 connect(aViewer, SIGNAL(tryCloseView(XGUI_ViewWindow*)),
99 this, SLOT(onTryCloseView(XGUI_ViewWindow*)));
101 connect(aViewer, SIGNAL(deleteView(XGUI_ViewWindow*)),
102 this, SLOT(onDeleteView(XGUI_ViewWindow*)));
104 connect(aViewer, SIGNAL(viewCreated(XGUI_ViewWindow*)),
105 this, SLOT(onViewCreated(XGUI_ViewWindow*)));
107 connect(aViewer, SIGNAL(activated(XGUI_ViewWindow*)),
108 this, SLOT(onActivated(XGUI_ViewWindow*)));
110 connect(aViewer, SIGNAL(mousePress(XGUI_ViewWindow*, QMouseEvent*)), this,
111 SLOT(onMousePress(XGUI_ViewWindow*, QMouseEvent*)));
113 connect(aViewer, SIGNAL(mouseRelease(XGUI_ViewWindow*, QMouseEvent*)), this,
114 SLOT(onMouseRelease(XGUI_ViewWindow*, QMouseEvent*)));
116 connect(aViewer, SIGNAL(mouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*)), this,
117 SLOT(onMouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*)));
119 connect(aViewer, SIGNAL(mouseMove(XGUI_ViewWindow*, QMouseEvent*)), this,
120 SLOT(onMouseMove(XGUI_ViewWindow*, QMouseEvent*)));
122 connect(aViewer, SIGNAL(keyPress(XGUI_ViewWindow*, QKeyEvent*)), this,
123 SLOT(onKeyPress(XGUI_ViewWindow*, QKeyEvent*)));
125 connect(aViewer, SIGNAL(keyRelease(XGUI_ViewWindow*, QKeyEvent*)), this,
126 SLOT(onKeyRelease(XGUI_ViewWindow*, QKeyEvent*)));
128 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
129 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
130 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
135 void XGUI_ViewerProxy::onTryCloseView(XGUI_ViewWindow* theWnd)
137 emit tryCloseView(theWnd);
140 void XGUI_ViewerProxy::onDeleteView(XGUI_ViewWindow* theWnd)
142 emit deleteView(theWnd);
145 void XGUI_ViewerProxy::onViewCreated(XGUI_ViewWindow* theWnd)
147 emit viewCreated(theWnd);
150 void XGUI_ViewerProxy::onActivated(XGUI_ViewWindow* theWnd)
152 emit activated(theWnd);
155 void XGUI_ViewerProxy::onMousePress(XGUI_ViewWindow* theWnd, QMouseEvent* theEvent)
157 emit mousePress(theWnd, theEvent);
160 void XGUI_ViewerProxy::onMouseRelease(XGUI_ViewWindow* theWnd, QMouseEvent* theEvent)
162 emit mouseRelease(theWnd, theEvent);
165 void XGUI_ViewerProxy::onMouseDoubleClick(XGUI_ViewWindow* theWnd, QMouseEvent* theEvent)
167 emit mouseDoubleClick(theWnd, theEvent);
170 void XGUI_ViewerProxy::onMouseMove(XGUI_ViewWindow* theWnd, QMouseEvent* theEvent)
172 emit mouseMove(theWnd, theEvent);
175 void XGUI_ViewerProxy::onKeyPress(XGUI_ViewWindow* theWnd, QKeyEvent* theEvent)
177 emit keyPress(theWnd, theEvent);
180 void XGUI_ViewerProxy::onKeyRelease(XGUI_ViewWindow* theWnd, QKeyEvent* theEvent)
182 emit keyRelease(theWnd, theEvent);
187 //***************************************
188 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
190 if (myWorkshop->isSalomeMode()) {
191 myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
193 myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
197 //***************************************
198 bool XGUI_ViewerProxy::isSelectionEnabled() const
200 if (myWorkshop->isSalomeMode()) {
201 return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
203 return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
207 //***************************************
208 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
210 if (myWorkshop->isSalomeMode()) {
211 myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
213 myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
217 //***************************************
218 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
220 if (myWorkshop->isSalomeMode()) {
221 return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
223 return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
227 //***************************************
228 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
230 Handle(AIS_InteractiveContext) aContext = AISContext();
231 if (!aContext.IsNull()) {
232 aContext->AddFilter(theFilter);
236 //***************************************
237 void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
239 Handle(AIS_InteractiveContext) aContext = AISContext();
240 if (!aContext.IsNull()) {
241 aContext->RemoveFilter(theFilter);
245 //***************************************
246 void XGUI_ViewerProxy::clearSelectionFilters()
248 Handle(AIS_InteractiveContext) aContext = AISContext();
249 if (!aContext.IsNull()) {
250 aContext->RemoveFilters();