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 //**********************************************
25 //**********************************************
26 //**********************************************
30 NewGeom_SalomeViewer::NewGeom_SalomeViewer(QObject* theParent)
31 : ModuleBase_IViewer(theParent),
32 mySelector(0), myView(0), myIsSelectionChanged(false)
36 NewGeom_SalomeViewer::~NewGeom_SalomeViewer()
43 //**********************************************
44 Handle(AIS_InteractiveContext) NewGeom_SalomeViewer::AISContext() const
46 if (mySelector && mySelector->viewer())
47 return mySelector->viewer()->getAISContext();
48 Handle(AIS_InteractiveContext) aNull;
52 //**********************************************
53 Handle(V3d_Viewer) NewGeom_SalomeViewer::v3dViewer() const
56 return mySelector->viewer()->getViewer3d();
57 return Handle(V3d_Viewer)();
60 //**********************************************
61 Handle(V3d_View) NewGeom_SalomeViewer::activeView() const
64 OCCViewer_Viewer* aViewer = mySelector->viewer();
65 SUIT_ViewManager* aMgr = aViewer->getViewManager();
66 OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
67 return aWnd->getViewPort()->getView();
69 return Handle(V3d_View)();
72 //**********************************************
73 void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
76 if (mySelector == theSel)
79 mySelector->viewer()->getViewManager()->disconnect(this);
80 OCCViewer_Viewer* aViewer = mySelector->viewer();
82 aViewer->disconnect(this);
88 OCCViewer_Viewer* aViewer = mySelector->viewer();
89 SUIT_ViewManager* aMgr = aViewer->getViewManager();
91 myView = new NewGeom_SalomeView(mySelector->viewer());
93 // TODO: Provide ModuleBase_IViewWindow interface
94 connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)), this, SIGNAL(lastViewClosed()));
96 connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewWindow*)),
97 this, SLOT(onTryCloseView(SUIT_ViewWindow*)));
98 connect(aMgr, SIGNAL(deleteView(SUIT_ViewWindow*)),
99 this, SLOT(onDeleteView(SUIT_ViewWindow*)));
100 connect(aMgr, SIGNAL(viewCreated(SUIT_ViewWindow*)),
101 this, SLOT(onViewCreated(SUIT_ViewWindow*)));
102 connect(aMgr, SIGNAL(activated(SUIT_ViewWindow*)),
103 this, SLOT(onActivated(SUIT_ViewWindow*)));
105 connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), this,
106 SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
107 connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), this,
108 SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
109 connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)), this,
110 SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)));
111 connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), this,
112 SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
114 connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)), this,
115 SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
116 connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)), this,
117 SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*)));
119 connect(aViewer, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
122 //**********************************************
123 void NewGeom_SalomeViewer::onSelectionChanged()
125 // Selection event must be sent only after mouse release
126 myIsSelectionChanged = true;
129 //**********************************************
130 void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent)
132 emit mousePress(myView, theEvent);
135 //**********************************************
136 void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent)
138 emit mouseRelease(myView, theEvent);
139 if (myIsSelectionChanged) {
140 emit selectionChanged();
141 myIsSelectionChanged = false;
145 //**********************************************
146 void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent)
148 emit mouseDoubleClick(myView, theEvent);
151 //**********************************************
152 void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow* theView, QMouseEvent* theEvent)
154 OCCViewer_ViewWindow* aViewWnd = dynamic_cast<OCCViewer_ViewWindow*>(theView);
155 Handle(AIS_InteractiveContext) aContext = AISContext();
156 if (aContext->HasDetected()) // Set focus to provide key events in the view
157 aViewWnd->getViewPort()->setFocus(Qt::MouseFocusReason);
158 emit mouseMove(myView, theEvent);
161 //**********************************************
162 bool NewGeom_SalomeViewer::canDragByMouse() const
164 OCCViewer_Viewer* aViewer = mySelector->viewer();
165 return (aViewer->interactionStyle() != 0);
169 //**********************************************
170 void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow* theView, QKeyEvent* theEvent)
172 OCCViewer_ViewWindow* aViewWnd = dynamic_cast<OCCViewer_ViewWindow*>(theView);
173 Handle(AIS_InteractiveContext) aContext = AISContext();
174 Handle(V3d_View) aView = aViewWnd->getViewPort()->getView();
176 bool noModifiers = (theEvent->modifiers() == Qt::NoModifier);
177 if ((theEvent->key() == Qt::Key_N) && noModifiers) {
178 aContext->HilightNextDetected(aView);
179 } else if ((theEvent->key() == Qt::Key_P) && noModifiers) {
180 aContext->HilightPreviousDetected(aView);
182 emit keyPress(myView, theEvent);
185 //**********************************************
186 void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow* theView, QKeyEvent* theEvent)
188 emit keyRelease(myView, theEvent);
191 //**********************************************
192 void NewGeom_SalomeViewer::onTryCloseView(SUIT_ViewWindow*)
194 emit tryCloseView(myView);
197 //**********************************************
198 void NewGeom_SalomeViewer::onDeleteView(SUIT_ViewWindow*)
200 emit deleteView(myView);
203 //**********************************************
204 void NewGeom_SalomeViewer::onViewCreated(SUIT_ViewWindow*)
206 emit viewCreated(myView);
209 //**********************************************
210 void NewGeom_SalomeViewer::onActivated(SUIT_ViewWindow*)
212 emit activated(myView);
215 //**********************************************
216 void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
219 mySelector->viewer()->enableSelection(isEnabled);
220 // The enableSelection() in SALOME 7.5 cause of forced Viewer update(we have blinking)
221 // After this is corrected, the first row should be recommented, the last - removed
222 //mySelector->viewer()->setInteractionStyle(isEnabled ? SUIT_ViewModel::STANDARD
223 // : SUIT_ViewModel::KEY_FREE);
226 //**********************************************
227 bool NewGeom_SalomeViewer::isSelectionEnabled() const
230 return mySelector->viewer()->isSelectionEnabled();
233 //**********************************************
234 void NewGeom_SalomeViewer::enableMultiselection(bool isEnable)
237 mySelector->viewer()->enableMultiselection(isEnable);
240 //**********************************************
241 bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
244 return mySelector->viewer()->isMultiSelectionEnabled();
248 //**********************************************
249 void NewGeom_SalomeViewer::fitAll()
252 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
253 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
260 //**********************************************
261 void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double theZ)
266 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
267 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
269 Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView();
270 if (!aView3d.IsNull()) {
271 aView3d->SetProj(theX, theY, theZ);
272 aView3d->FitAll(0.01, true);
273 aView3d->SetZSize(0.);
278 //***************************************
279 void NewGeom_SalomeViewer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
281 Handle(AIS_InteractiveContext) aContext = AISContext();
282 if (!aContext.IsNull()) {
283 aContext->AddFilter(theFilter);
287 //***************************************
288 void NewGeom_SalomeViewer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
290 Handle(AIS_InteractiveContext) aContext = AISContext();
291 if (!aContext.IsNull()) {
292 aContext->RemoveFilter(theFilter);
296 //***************************************
297 void NewGeom_SalomeViewer::clearSelectionFilters()
299 Handle(AIS_InteractiveContext) aContext = AISContext();
300 if (!aContext.IsNull()) {
301 aContext->RemoveFilters();
305 //***************************************
306 void NewGeom_SalomeViewer::update()
308 Handle(AIS_InteractiveContext) aContext = AISContext();
309 if (!aContext.IsNull()) {
310 aContext->UpdateCurrentViewer();