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 SUIT_ViewWindow* aWnd = aViewer->getViewManager()->getActiveView();
166 OCCViewer_ViewWindow* aViewWnd = dynamic_cast<OCCViewer_ViewWindow*>(aWnd);
168 return (aViewWnd->interactionStyle() == 0);
174 //**********************************************
175 void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow* theView, QKeyEvent* theEvent)
177 OCCViewer_ViewWindow* aViewWnd = dynamic_cast<OCCViewer_ViewWindow*>(theView);
178 Handle(AIS_InteractiveContext) aContext = AISContext();
179 Handle(V3d_View) aView = aViewWnd->getViewPort()->getView();
181 bool noModifiers = (theEvent->modifiers() == Qt::NoModifier);
182 if ((theEvent->key() == Qt::Key_N) && noModifiers) {
183 aContext->HilightNextDetected(aView);
184 } else if ((theEvent->key() == Qt::Key_P) && noModifiers) {
185 aContext->HilightPreviousDetected(aView);
187 emit keyPress(myView, theEvent);
190 //**********************************************
191 void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow* theView, QKeyEvent* theEvent)
193 emit keyRelease(myView, theEvent);
196 //**********************************************
197 void NewGeom_SalomeViewer::onTryCloseView(SUIT_ViewWindow*)
199 emit tryCloseView(myView);
202 //**********************************************
203 void NewGeom_SalomeViewer::onDeleteView(SUIT_ViewWindow*)
205 emit deleteView(myView);
208 //**********************************************
209 void NewGeom_SalomeViewer::onViewCreated(SUIT_ViewWindow*)
211 emit viewCreated(myView);
214 //**********************************************
215 void NewGeom_SalomeViewer::onActivated(SUIT_ViewWindow*)
217 emit activated(myView);
220 //**********************************************
221 void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
224 mySelector->viewer()->enableSelection(isEnabled);
225 // The enableSelection() in SALOME 7.5 cause of forced Viewer update(we have blinking)
226 // After this is corrected, the first row should be recommented, the last - removed
227 //mySelector->viewer()->setInteractionStyle(isEnabled ? SUIT_ViewModel::STANDARD
228 // : SUIT_ViewModel::KEY_FREE);
231 //**********************************************
232 bool NewGeom_SalomeViewer::isSelectionEnabled() const
235 return mySelector->viewer()->isSelectionEnabled();
238 //**********************************************
239 void NewGeom_SalomeViewer::enableMultiselection(bool isEnable)
242 mySelector->viewer()->enableMultiselection(isEnable);
245 //**********************************************
246 bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
249 return mySelector->viewer()->isMultiSelectionEnabled();
253 //**********************************************
254 void NewGeom_SalomeViewer::fitAll()
257 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
258 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
265 //**********************************************
266 void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double theZ)
271 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
272 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
274 Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView();
275 if (!aView3d.IsNull()) {
276 aView3d->SetProj(theX, theY, theZ);
277 aView3d->FitAll(0.01, true);
278 aView3d->SetZSize(0.);
283 //***************************************
284 void NewGeom_SalomeViewer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
286 Handle(AIS_InteractiveContext) aContext = AISContext();
287 if (!aContext.IsNull()) {
288 aContext->AddFilter(theFilter);
292 //***************************************
293 void NewGeom_SalomeViewer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
295 Handle(AIS_InteractiveContext) aContext = AISContext();
296 if (!aContext.IsNull()) {
297 aContext->RemoveFilter(theFilter);
301 //***************************************
302 void NewGeom_SalomeViewer::clearSelectionFilters()
304 Handle(AIS_InteractiveContext) aContext = AISContext();
305 if (!aContext.IsNull()) {
306 aContext->RemoveFilters();
310 //***************************************
311 void NewGeom_SalomeViewer::update()
313 Handle(AIS_InteractiveContext) aContext = AISContext();
314 if (!aContext.IsNull()) {
315 aContext->UpdateCurrentViewer();