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*, QMouseEvent* theEvent)
149 emit mouseMove(myView, theEvent);
152 //**********************************************
153 void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow*, QKeyEvent* theEvent)
155 emit keyPress(myView, theEvent);
158 //**********************************************
159 void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow*, QKeyEvent* theEvent)
161 emit keyRelease(myView, theEvent);
164 //**********************************************
165 void NewGeom_SalomeViewer::onTryCloseView(SUIT_ViewWindow*)
167 emit tryCloseView(myView);
170 //**********************************************
171 void NewGeom_SalomeViewer::onDeleteView(SUIT_ViewWindow*)
173 emit deleteView(myView);
176 //**********************************************
177 void NewGeom_SalomeViewer::onViewCreated(SUIT_ViewWindow*)
179 emit viewCreated(myView);
182 //**********************************************
183 void NewGeom_SalomeViewer::onActivated(SUIT_ViewWindow*)
185 emit activated(myView);
188 //**********************************************
189 void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
191 //mySelector->viewer()->enableSelection(isEnabled);
192 // The enableSelection() in SALOME 7.5 cause of forced Viewer update(we have blinking)
193 // After this is corrected, the first row should be recommented, the last - removed
194 mySelector->viewer()->setInteractionStyle(isEnabled ? SUIT_ViewModel::STANDARD
195 : SUIT_ViewModel::KEY_FREE);
198 //**********************************************
199 bool NewGeom_SalomeViewer::isSelectionEnabled() const
201 return mySelector->viewer()->isSelectionEnabled();
204 //**********************************************
205 void NewGeom_SalomeViewer::enableMultiselection(bool isEnable)
207 mySelector->viewer()->enableMultiselection(isEnable);
210 //**********************************************
211 bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
213 return mySelector->viewer()->isMultiSelectionEnabled();
216 //**********************************************
217 void NewGeom_SalomeViewer::fitAll()
219 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
220 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
226 //**********************************************
227 void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double theZ)
229 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
230 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
232 Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView();
233 if (!aView3d.IsNull()) {
234 aView3d->SetProj(theX, theY, theZ);
235 aView3d->FitAll(0.01, true);
236 aView3d->SetZSize(0.);
241 //***************************************
242 void NewGeom_SalomeViewer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
244 Handle(AIS_InteractiveContext) aContext = AISContext();
245 if (!aContext.IsNull()) {
246 aContext->AddFilter(theFilter);
250 //***************************************
251 void NewGeom_SalomeViewer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
253 Handle(AIS_InteractiveContext) aContext = AISContext();
254 if (!aContext.IsNull()) {
255 aContext->RemoveFilter(theFilter);
259 //***************************************
260 void NewGeom_SalomeViewer::clearSelectionFilters()
262 Handle(AIS_InteractiveContext) aContext = AISContext();
263 if (!aContext.IsNull()) {
264 aContext->RemoveFilters();
268 //***************************************
269 void NewGeom_SalomeViewer::update()
271 Handle(AIS_InteractiveContext) aContext = AISContext();
272 if (!aContext.IsNull()) {
273 aContext->UpdateCurrentViewer();