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
55 return mySelector->viewer()->getViewer3d();
58 //**********************************************
59 Handle(V3d_View) NewGeom_SalomeViewer::activeView() const
61 OCCViewer_Viewer* aViewer = mySelector->viewer();
62 SUIT_ViewManager* aMgr = aViewer->getViewManager();
63 OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
64 return aWnd->getViewPort()->getView();
67 //**********************************************
68 void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
71 if (mySelector == theSel)
74 mySelector->viewer()->getViewManager()->disconnect(this);
75 OCCViewer_Viewer* aViewer = mySelector->viewer();
77 aViewer->disconnect(this);
83 OCCViewer_Viewer* aViewer = mySelector->viewer();
84 SUIT_ViewManager* aMgr = aViewer->getViewManager();
86 myView = new NewGeom_SalomeView(mySelector->viewer());
88 // TODO: Provide ModuleBase_IViewWindow interface
89 connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)), this, SIGNAL(lastViewClosed()));
91 connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewWindow*)),
92 this, SLOT(onTryCloseView(SUIT_ViewWindow*)));
93 connect(aMgr, SIGNAL(deleteView(SUIT_ViewWindow*)),
94 this, SLOT(onDeleteView(SUIT_ViewWindow*)));
95 connect(aMgr, SIGNAL(viewCreated(SUIT_ViewWindow*)),
96 this, SLOT(onViewCreated(SUIT_ViewWindow*)));
97 connect(aMgr, SIGNAL(activated(SUIT_ViewWindow*)),
98 this, SLOT(onActivated(SUIT_ViewWindow*)));
100 connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), this,
101 SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
102 connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), this,
103 SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
104 connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)), this,
105 SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)));
106 connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), this,
107 SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
109 connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)), this,
110 SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
111 connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)), this,
112 SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*)));
114 connect(aViewer, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
117 //**********************************************
118 void NewGeom_SalomeViewer::onSelectionChanged()
120 // Selection event must be sent only after mouse release
121 myIsSelectionChanged = true;
124 //**********************************************
125 void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent)
127 emit mousePress(myView, theEvent);
130 //**********************************************
131 void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent)
133 emit mouseRelease(myView, theEvent);
134 if (myIsSelectionChanged) {
135 emit selectionChanged();
136 myIsSelectionChanged = false;
140 //**********************************************
141 void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent)
143 emit mouseDoubleClick(myView, theEvent);
146 //**********************************************
147 void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow* theView, QMouseEvent* theEvent)
149 OCCViewer_ViewWindow* aViewWnd = dynamic_cast<OCCViewer_ViewWindow*>(theView);
150 Handle(AIS_InteractiveContext) aContext = AISContext();
151 if (aContext->HasDetected())
152 aViewWnd->getViewPort()->setFocus(Qt::MouseFocusReason);
153 emit mouseMove(myView, theEvent);
156 //**********************************************
157 void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow* theView, QKeyEvent* theEvent)
159 OCCViewer_ViewWindow* aViewWnd = dynamic_cast<OCCViewer_ViewWindow*>(theView);
160 Handle(AIS_InteractiveContext) aContext = AISContext();
161 Handle(V3d_View) aView = aViewWnd->getViewPort()->getView();
163 bool noModifiers = (theEvent->modifiers() == Qt::NoModifier);
164 if ((theEvent->key() == Qt::Key_N) && noModifiers) {
165 aContext->HilightNextDetected(aView);
166 } else if ((theEvent->key() == Qt::Key_P) && noModifiers) {
167 aContext->HilightPreviousDetected(aView);
169 emit keyPress(myView, theEvent);
172 //**********************************************
173 void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow* theView, QKeyEvent* theEvent)
175 emit keyRelease(myView, theEvent);
178 //**********************************************
179 void NewGeom_SalomeViewer::onTryCloseView(SUIT_ViewWindow*)
181 emit tryCloseView(myView);
184 //**********************************************
185 void NewGeom_SalomeViewer::onDeleteView(SUIT_ViewWindow*)
187 emit deleteView(myView);
190 //**********************************************
191 void NewGeom_SalomeViewer::onViewCreated(SUIT_ViewWindow*)
193 emit viewCreated(myView);
196 //**********************************************
197 void NewGeom_SalomeViewer::onActivated(SUIT_ViewWindow*)
199 emit activated(myView);
202 //**********************************************
203 void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
205 //mySelector->viewer()->enableSelection(isEnabled);
206 // The enableSelection() in SALOME 7.5 cause of forced Viewer update(we have blinking)
207 // After this is corrected, the first row should be recommented, the last - removed
208 mySelector->viewer()->setInteractionStyle(isEnabled ? SUIT_ViewModel::STANDARD
209 : SUIT_ViewModel::KEY_FREE);
212 //**********************************************
213 bool NewGeom_SalomeViewer::isSelectionEnabled() const
215 return mySelector->viewer()->isSelectionEnabled();
218 //**********************************************
219 void NewGeom_SalomeViewer::enableMultiselection(bool isEnable)
221 mySelector->viewer()->enableMultiselection(isEnable);
224 //**********************************************
225 bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
227 return mySelector->viewer()->isMultiSelectionEnabled();
230 //**********************************************
231 void NewGeom_SalomeViewer::fitAll()
233 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
234 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
240 //**********************************************
241 void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double theZ)
243 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
244 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
246 Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView();
247 if (!aView3d.IsNull()) {
248 aView3d->SetProj(theX, theY, theZ);
249 aView3d->FitAll(0.01, true);
250 aView3d->SetZSize(0.);
255 //***************************************
256 void NewGeom_SalomeViewer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
258 Handle(AIS_InteractiveContext) aContext = AISContext();
259 if (!aContext.IsNull()) {
260 aContext->AddFilter(theFilter);
264 //***************************************
265 void NewGeom_SalomeViewer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
267 Handle(AIS_InteractiveContext) aContext = AISContext();
268 if (!aContext.IsNull()) {
269 aContext->RemoveFilter(theFilter);
273 //***************************************
274 void NewGeom_SalomeViewer::clearSelectionFilters()
276 Handle(AIS_InteractiveContext) aContext = AISContext();
277 if (!aContext.IsNull()) {
278 aContext->RemoveFilters();
282 //***************************************
283 void NewGeom_SalomeViewer::update()
285 Handle(AIS_InteractiveContext) aContext = AISContext();
286 if (!aContext.IsNull()) {
287 aContext->UpdateCurrentViewer();