1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 #include "NewGeom_SalomeViewer.h"
4 #include "NewGeom_OCCSelector.h"
6 #include <OCCViewer_ViewWindow.h>
7 #include <OCCViewer_ViewPort3d.h>
8 #include <OCCViewer_ViewFrame.h>
10 #include <SUIT_ViewManager.h>
12 #include <QMouseEvent>
13 #include <QContextMenuEvent>
16 Handle(V3d_View) NewGeom_SalomeView::v3dView() const
18 SUIT_ViewManager* aMgr = myViewer->getViewManager();
19 OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
20 Handle(V3d_View) aView = aWnd->getViewPort()->getView();
24 QWidget* NewGeom_SalomeView::viewPort() const
26 SUIT_ViewManager* aMgr = myViewer->getViewManager();
27 OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
28 return aWnd->getViewPort();
31 //**********************************************
32 //**********************************************
33 //**********************************************
37 NewGeom_SalomeViewer::NewGeom_SalomeViewer(QObject* theParent)
38 : ModuleBase_IViewer(theParent),
39 mySelector(0), myView(0), myIsSelectionChanged(false)
43 NewGeom_SalomeViewer::~NewGeom_SalomeViewer()
50 //**********************************************
51 Handle(AIS_InteractiveContext) NewGeom_SalomeViewer::AISContext() const
53 if (mySelector && mySelector->viewer())
54 return mySelector->viewer()->getAISContext();
55 Handle(AIS_InteractiveContext) aNull;
59 //**********************************************
60 Handle(V3d_Viewer) NewGeom_SalomeViewer::v3dViewer() const
63 return mySelector->viewer()->getViewer3d();
64 return Handle(V3d_Viewer)();
67 //**********************************************
68 Handle(V3d_View) NewGeom_SalomeViewer::activeView() const
71 OCCViewer_Viewer* aViewer = mySelector->viewer();
72 SUIT_ViewManager* aMgr = aViewer->getViewManager();
73 OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
74 return aWnd->getViewPort()->getView();
76 return Handle(V3d_View)();
79 //**********************************************
80 void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
83 if (mySelector == theSel)
86 mySelector->viewer()->getViewManager()->disconnect(this);
87 OCCViewer_Viewer* aViewer = mySelector->viewer();
89 aViewer->disconnect(this);
95 OCCViewer_Viewer* aViewer = mySelector->viewer();
96 SUIT_ViewManager* aMgr = aViewer->getViewManager();
98 myView = new NewGeom_SalomeView(mySelector->viewer());
100 // TODO: Provide ModuleBase_IViewWindow interface
101 connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)), this, SIGNAL(lastViewClosed()));
103 connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewWindow*)),
104 this, SLOT(onTryCloseView(SUIT_ViewWindow*)));
105 connect(aMgr, SIGNAL(deleteView(SUIT_ViewWindow*)),
106 this, SLOT(onDeleteView(SUIT_ViewWindow*)));
107 connect(aMgr, SIGNAL(viewCreated(SUIT_ViewWindow*)),
108 this, SLOT(onViewCreated(SUIT_ViewWindow*)));
109 connect(aMgr, SIGNAL(activated(SUIT_ViewWindow*)),
110 this, SLOT(onActivated(SUIT_ViewWindow*)));
112 connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), this,
113 SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
114 connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), this,
115 SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
116 connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)), this,
117 SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)));
118 connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), this,
119 SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
121 connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)), this,
122 SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
123 connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)), this,
124 SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*)));
126 connect(aViewer, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
129 //**********************************************
130 void NewGeom_SalomeViewer::onSelectionChanged()
132 // Selection event must be sent only after mouse release
133 myIsSelectionChanged = true;
136 //**********************************************
137 void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent)
139 emit mousePress(myView, theEvent);
142 //**********************************************
143 void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent)
145 emit mouseRelease(myView, theEvent);
146 if (myIsSelectionChanged) {
147 emit selectionChanged();
148 myIsSelectionChanged = false;
152 //**********************************************
153 void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent)
155 emit mouseDoubleClick(myView, theEvent);
158 //**********************************************
159 void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow* theView, QMouseEvent* theEvent)
161 OCCViewer_ViewWindow* aViewWnd = dynamic_cast<OCCViewer_ViewWindow*>(theView);
162 Handle(AIS_InteractiveContext) aContext = AISContext();
163 if (aContext->HasDetected()) // Set focus to provide key events in the view
164 aViewWnd->getViewPort()->setFocus(Qt::MouseFocusReason);
165 emit mouseMove(myView, theEvent);
168 //**********************************************
169 bool NewGeom_SalomeViewer::canDragByMouse() const
171 OCCViewer_Viewer* aViewer = mySelector->viewer();
172 SUIT_ViewWindow* aWnd = aViewer->getViewManager()->getActiveView();
173 OCCViewer_ViewWindow* aViewWnd = dynamic_cast<OCCViewer_ViewWindow*>(aWnd);
175 return (aViewWnd->interactionStyle() == 0);
181 //**********************************************
182 void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow* theView, QKeyEvent* theEvent)
184 OCCViewer_ViewWindow* aViewWnd = dynamic_cast<OCCViewer_ViewWindow*>(theView);
185 Handle(AIS_InteractiveContext) aContext = AISContext();
186 Handle(V3d_View) aView = aViewWnd->getViewPort()->getView();
188 bool noModifiers = (theEvent->modifiers() == Qt::NoModifier);
189 if ((theEvent->key() == Qt::Key_N) && noModifiers) {
190 aContext->HilightNextDetected(aView);
191 } else if ((theEvent->key() == Qt::Key_P) && noModifiers) {
192 aContext->HilightPreviousDetected(aView);
194 emit keyPress(myView, theEvent);
197 //**********************************************
198 void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow* theView, QKeyEvent* theEvent)
200 emit keyRelease(myView, theEvent);
203 //**********************************************
204 void NewGeom_SalomeViewer::onTryCloseView(SUIT_ViewWindow*)
206 emit tryCloseView(myView);
209 //**********************************************
210 void NewGeom_SalomeViewer::onDeleteView(SUIT_ViewWindow*)
212 emit deleteView(myView);
215 //**********************************************
216 void NewGeom_SalomeViewer::onViewCreated(SUIT_ViewWindow*)
218 emit viewCreated(myView);
221 //**********************************************
222 void NewGeom_SalomeViewer::onActivated(SUIT_ViewWindow*)
224 emit activated(myView);
227 //**********************************************
228 void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
231 mySelector->viewer()->enableSelection(isEnabled);
232 // The enableSelection() in SALOME 7.5 cause of forced Viewer update(we have blinking)
233 // After this is corrected, the first row should be recommented, the last - removed
234 //mySelector->viewer()->setInteractionStyle(isEnabled ? SUIT_ViewModel::STANDARD
235 // : SUIT_ViewModel::KEY_FREE);
238 //**********************************************
239 bool NewGeom_SalomeViewer::isSelectionEnabled() const
242 return mySelector->viewer()->isSelectionEnabled();
245 //**********************************************
246 void NewGeom_SalomeViewer::enableMultiselection(bool isEnable)
249 mySelector->viewer()->enableMultiselection(isEnable);
252 //**********************************************
253 bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
256 return mySelector->viewer()->isMultiSelectionEnabled();
260 //**********************************************
261 void NewGeom_SalomeViewer::fitAll()
264 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
265 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
272 //**********************************************
273 void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double theZ)
278 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
279 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
281 Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView();
282 if (!aView3d.IsNull()) {
283 aView3d->SetProj(theX, theY, theZ);
284 aView3d->FitAll(0.01, true);
285 aView3d->SetZSize(0.);
290 //***************************************
291 void NewGeom_SalomeViewer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
293 Handle(AIS_InteractiveContext) aContext = AISContext();
294 if (!aContext.IsNull()) {
295 aContext->AddFilter(theFilter);
299 //***************************************
300 void NewGeom_SalomeViewer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
302 Handle(AIS_InteractiveContext) aContext = AISContext();
303 if (!aContext.IsNull()) {
304 aContext->RemoveFilter(theFilter);
308 //***************************************
309 void NewGeom_SalomeViewer::clearSelectionFilters()
311 Handle(AIS_InteractiveContext) aContext = AISContext();
312 if (!aContext.IsNull()) {
313 aContext->RemoveFilters();
317 //***************************************
318 void NewGeom_SalomeViewer::update()
320 Handle(AIS_InteractiveContext) aContext = AISContext();
321 if (!aContext.IsNull()) {
322 aContext->UpdateCurrentViewer();