1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 #include "XGUI_ViewerProxy.h"
4 #include "XGUI_Workshop.h"
5 #include "XGUI_SalomeConnector.h"
6 #include "XGUI_Displayer.h"
8 #include <AppElements_MainWindow.h>
9 #include <AppElements_ViewPort.h>
10 #include <AppElements_ViewWindow.h>
11 #include <AppElements_Viewer.h>
13 XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
14 : ModuleBase_IViewer(theParent),
19 Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
21 if (myWorkshop->isSalomeMode()) {
22 return myWorkshop->salomeConnector()->viewer()->AISContext();
24 return myWorkshop->mainWindow()->viewer()->AISContext();
28 Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const
30 if (myWorkshop->isSalomeMode()) {
31 return myWorkshop->salomeConnector()->viewer()->v3dViewer();
33 return myWorkshop->mainWindow()->viewer()->v3dViewer();
37 Handle(V3d_View) XGUI_ViewerProxy::activeView() const
39 if (myWorkshop->isSalomeMode()) {
40 return myWorkshop->salomeConnector()->viewer()->activeView();
42 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
43 return (aViewer->activeViewWindow()) ? aViewer->activeViewWindow()->viewPort()->getView() :
48 void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ)
50 Handle(V3d_View) aView3d = activeView();
51 if (!aView3d.IsNull()) {
52 aView3d->SetProj(theX, theY, theZ);
53 aView3d->FitAll(0.01, true);
54 aView3d->SetZSize(0.);
58 void XGUI_ViewerProxy::fitAll()
60 if (myWorkshop->isSalomeMode()) {
61 myWorkshop->salomeConnector()->viewer()->fitAll();
63 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
64 if (aViewer->activeViewWindow())
65 aViewer->activeViewWindow()->viewPort()->fitAll();
69 void XGUI_ViewerProxy::connectToViewer()
71 if (myWorkshop->isSalomeMode()) {
72 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
74 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
75 connect(aViewer, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)),
76 this, SIGNAL(tryCloseView(ModuleBase_IViewWindow*)));
78 connect(aViewer, SIGNAL(deleteView(ModuleBase_IViewWindow*)),
79 this, SIGNAL(deleteView(ModuleBase_IViewWindow*)));
81 connect(aViewer, SIGNAL(viewCreated(ModuleBase_IViewWindow*)),
82 this, SIGNAL(viewCreated(ModuleBase_IViewWindow*)));
84 connect(aViewer, SIGNAL(activated(ModuleBase_IViewWindow*)),
85 this, SIGNAL(activated(ModuleBase_IViewWindow*)));
87 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
88 this, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)));
90 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
91 this, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)));
93 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)), this,
94 SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
96 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
97 this, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)));
99 connect(aViewer, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)),
100 this, SIGNAL(keyPress(ModuleBase_IViewWindow*, QKeyEvent*)));
102 connect(aViewer, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)),
103 this, SIGNAL(keyRelease(ModuleBase_IViewWindow*, QKeyEvent*)));
105 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
106 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
107 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
110 AppElements_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
112 connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
114 connect(aViewer, SIGNAL(tryCloseView(AppElements_ViewWindow*)),
115 this, SLOT(onTryCloseView(AppElements_ViewWindow*)));
117 connect(aViewer, SIGNAL(deleteView(AppElements_ViewWindow*)),
118 this, SLOT(onDeleteView(AppElements_ViewWindow*)));
120 connect(aViewer, SIGNAL(viewCreated(AppElements_ViewWindow*)),
121 this, SLOT(onViewCreated(AppElements_ViewWindow*)));
123 connect(aViewer, SIGNAL(activated(AppElements_ViewWindow*)),
124 this, SLOT(onActivated(AppElements_ViewWindow*)));
126 connect(aViewer, SIGNAL(mousePress(AppElements_ViewWindow*, QMouseEvent*)), this,
127 SLOT(onMousePress(AppElements_ViewWindow*, QMouseEvent*)));
129 connect(aViewer, SIGNAL(mouseRelease(AppElements_ViewWindow*, QMouseEvent*)), this,
130 SLOT(onMouseRelease(AppElements_ViewWindow*, QMouseEvent*)));
132 connect(aViewer, SIGNAL(mouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)), this,
133 SLOT(onMouseDoubleClick(AppElements_ViewWindow*, QMouseEvent*)));
135 connect(aViewer, SIGNAL(mouseMove(AppElements_ViewWindow*, QMouseEvent*)), this,
136 SLOT(onMouseMove(AppElements_ViewWindow*, QMouseEvent*)));
138 connect(aViewer, SIGNAL(keyPress(AppElements_ViewWindow*, QKeyEvent*)), this,
139 SLOT(onKeyPress(AppElements_ViewWindow*, QKeyEvent*)));
141 connect(aViewer, SIGNAL(keyRelease(AppElements_ViewWindow*, QKeyEvent*)), this,
142 SLOT(onKeyRelease(AppElements_ViewWindow*, QKeyEvent*)));
144 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
145 connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
146 SIGNAL(contextMenuRequested(QContextMenuEvent*)));
151 void XGUI_ViewerProxy::onTryCloseView(AppElements_ViewWindow* theWnd)
153 emit tryCloseView(theWnd);
156 void XGUI_ViewerProxy::onDeleteView(AppElements_ViewWindow* theWnd)
158 emit deleteView(theWnd);
161 void XGUI_ViewerProxy::onViewCreated(AppElements_ViewWindow* theWnd)
163 emit viewCreated(theWnd);
166 void XGUI_ViewerProxy::onActivated(AppElements_ViewWindow* theWnd)
168 emit activated(theWnd);
171 void XGUI_ViewerProxy::onMousePress(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
173 emit mousePress(theWnd, theEvent);
176 void XGUI_ViewerProxy::onMouseRelease(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
178 emit mouseRelease(theWnd, theEvent);
181 void XGUI_ViewerProxy::onMouseDoubleClick(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
183 emit mouseDoubleClick(theWnd, theEvent);
186 void XGUI_ViewerProxy::onMouseMove(AppElements_ViewWindow* theWnd, QMouseEvent* theEvent)
188 emit mouseMove(theWnd, theEvent);
191 void XGUI_ViewerProxy::onKeyPress(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
193 emit keyPress(theWnd, theEvent);
196 void XGUI_ViewerProxy::onKeyRelease(AppElements_ViewWindow* theWnd, QKeyEvent* theEvent)
198 emit keyRelease(theWnd, theEvent);
203 //***************************************
204 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
206 if (myWorkshop->isSalomeMode()) {
207 myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
209 myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
213 //***************************************
214 bool XGUI_ViewerProxy::isSelectionEnabled() const
216 if (myWorkshop->isSalomeMode()) {
217 return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
219 return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
223 //***************************************
224 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
226 if (myWorkshop->isSalomeMode()) {
227 myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
229 myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
233 //***************************************
234 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
236 if (myWorkshop->isSalomeMode()) {
237 return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
239 return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
243 //***************************************
244 void XGUI_ViewerProxy::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
246 myWorkshop->displayer()->addSelectionFilter(theFilter);
249 //***************************************
250 void XGUI_ViewerProxy::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
252 myWorkshop->displayer()->removeSelectionFilter(theFilter);
255 //***************************************
256 void XGUI_ViewerProxy::clearSelectionFilters()
258 myWorkshop->displayer()->removeFilters();
261 //***************************************
262 void XGUI_ViewerProxy::update()
264 myWorkshop->displayer()->updateViewer();
267 //***************************************
268 bool XGUI_ViewerProxy::canDragByMouse() const
270 if (myWorkshop->isSalomeMode()) {
271 ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
272 return aViewer->canDragByMouse();