1 #include "NewGeom_SalomeViewer.h"
2 #include "NewGeom_OCCSelector.h"
4 #include <OCCViewer_ViewWindow.h>
5 #include <OCCViewer_ViewPort3d.h>
6 #include <OCCViewer_ViewFrame.h>
8 #include <SUIT_ViewManager.h>
10 #include <QMouseEvent>
11 #include <QContextMenuEvent>
14 Handle(V3d_View) NewGeom_SalomeView::v3dView() const
16 SUIT_ViewManager* aMgr = myViewer->getViewManager();
17 OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
18 Handle(V3d_View) aView = aWnd->getViewPort()->getView();
22 //**********************************************
23 //**********************************************
24 //**********************************************
28 NewGeom_SalomeViewer::NewGeom_SalomeViewer(QObject* theParent)
29 : ModuleBase_IViewer(theParent),
30 mySelector(0), myView(0), myIsSelectionChanged(false)
34 NewGeom_SalomeViewer::~NewGeom_SalomeViewer()
41 //**********************************************
42 Handle(AIS_InteractiveContext) NewGeom_SalomeViewer::AISContext() const
44 if (mySelector && mySelector->viewer())
45 return mySelector->viewer()->getAISContext();
46 Handle(AIS_InteractiveContext) aNull;
50 //**********************************************
51 Handle(V3d_Viewer) NewGeom_SalomeViewer::v3dViewer() const
53 return mySelector->viewer()->getViewer3d();
56 //**********************************************
57 Handle(V3d_View) NewGeom_SalomeViewer::activeView() const
59 OCCViewer_Viewer* aViewer = mySelector->viewer();
60 SUIT_ViewManager* aMgr = aViewer->getViewManager();
61 OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
62 return aWnd->getViewPort()->getView();
65 //**********************************************
66 void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
69 if (mySelector == theSel)
72 mySelector->viewer()->getViewManager()->disconnect(this);
73 OCCViewer_Viewer* aViewer = mySelector->viewer();
75 aViewer->disconnect(this);
81 OCCViewer_Viewer* aViewer = mySelector->viewer();
82 SUIT_ViewManager* aMgr = aViewer->getViewManager();
84 myView = new NewGeom_SalomeView(mySelector->viewer());
86 // TODO: Provide ModuleBase_IViewWindow interface
87 connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)), this, SIGNAL(lastViewClosed()));
89 connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewWindow*)),
90 this, SLOT(onTryCloseView(SUIT_ViewWindow*)));
91 connect(aMgr, SIGNAL(deleteView(SUIT_ViewWindow*)),
92 this, SLOT(onDeleteView(SUIT_ViewWindow*)));
93 connect(aMgr, SIGNAL(viewCreated(SUIT_ViewWindow*)),
94 this, SLOT(onViewCreated(SUIT_ViewWindow*)));
95 connect(aMgr, SIGNAL(activated(SUIT_ViewWindow*)),
96 this, SLOT(onActivated(SUIT_ViewWindow*)));
98 connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), this,
99 SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
100 connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), this,
101 SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
102 connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)), this,
103 SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)));
104 connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), this,
105 SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
107 connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)), this,
108 SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
109 connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)), this,
110 SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*)));
112 connect(aViewer, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
115 //**********************************************
116 void NewGeom_SalomeViewer::onSelectionChanged()
118 // Selection event must be sent only after mouse release
119 myIsSelectionChanged = true;
122 //**********************************************
123 void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent)
125 emit mousePress(myView, theEvent);
128 //**********************************************
129 void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent)
131 emit mouseRelease(myView, theEvent);
132 if (myIsSelectionChanged) {
133 emit selectionChanged();
134 myIsSelectionChanged = false;
138 //**********************************************
139 void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent)
141 emit mouseDoubleClick(myView, theEvent);
144 //**********************************************
145 void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow*, QMouseEvent* theEvent)
147 emit mouseMove(myView, theEvent);
150 //**********************************************
151 void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow*, QKeyEvent* theEvent)
153 emit keyPress(myView, theEvent);
156 //**********************************************
157 void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow*, QKeyEvent* theEvent)
159 emit keyRelease(myView, theEvent);
162 //**********************************************
163 void NewGeom_SalomeViewer::onTryCloseView(SUIT_ViewWindow*)
165 emit tryCloseView(myView);
168 //**********************************************
169 void NewGeom_SalomeViewer::onDeleteView(SUIT_ViewWindow*)
171 emit deleteView(myView);
174 //**********************************************
175 void NewGeom_SalomeViewer::onViewCreated(SUIT_ViewWindow*)
177 emit viewCreated(myView);
180 //**********************************************
181 void NewGeom_SalomeViewer::onActivated(SUIT_ViewWindow*)
183 emit activated(myView);
186 //**********************************************
187 void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
189 mySelector->viewer()->enableSelection(isEnabled);
190 // there is a fix for a black-colored window
191 // the viewer rubber band is valid if the values delta is less than 1
192 // TODO: remove this row after moving to SALOME 7.5
193 mySelector->viewer()->setInteractionStyle(isEnabled ? SUIT_ViewModel::STANDARD
194 : SUIT_ViewModel::KEY_FREE);
197 //**********************************************
198 bool NewGeom_SalomeViewer::isSelectionEnabled() const
200 return mySelector->viewer()->isSelectionEnabled();
203 //**********************************************
204 void NewGeom_SalomeViewer::enableMultiselection(bool isEnable)
206 mySelector->viewer()->enableMultiselection(isEnable);
209 //**********************************************
210 bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
212 return mySelector->viewer()->isMultiSelectionEnabled();
215 //**********************************************
216 void NewGeom_SalomeViewer::fitAll()
218 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
219 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
225 //**********************************************
226 void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double theZ)
228 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
229 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
231 Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView();
232 if (!aView3d.IsNull()) {
233 aView3d->SetProj(theX, theY, theZ);
234 aView3d->FitAll(0.01, true, true);
235 aView3d->SetZSize(0.);
240 //***************************************
241 void NewGeom_SalomeViewer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
243 Handle(AIS_InteractiveContext) aContext = AISContext();
244 if (!aContext.IsNull()) {
245 aContext->AddFilter(theFilter);
249 //***************************************
250 void NewGeom_SalomeViewer::removeSelectionFilter(const Handle(SelectMgr_Filter)& theFilter)
252 Handle(AIS_InteractiveContext) aContext = AISContext();
253 if (!aContext.IsNull()) {
254 aContext->RemoveFilter(theFilter);
258 //***************************************
259 void NewGeom_SalomeViewer::clearSelectionFilters()
261 Handle(AIS_InteractiveContext) aContext = AISContext();
262 if (!aContext.IsNull()) {
263 aContext->RemoveFilters();