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>
13 NewGeom_SalomeViewer::NewGeom_SalomeViewer(QObject* theParent)
14 : ModuleBase_IViewer(theParent),
19 //**********************************************
20 Handle(AIS_InteractiveContext) NewGeom_SalomeViewer::AISContext() const
22 if (mySelector && mySelector->viewer())
23 return mySelector->viewer()->getAISContext();
24 Handle(AIS_InteractiveContext) aNull;
28 //**********************************************
29 Handle(V3d_Viewer) NewGeom_SalomeViewer::v3dViewer() const
31 return mySelector->viewer()->getViewer3d();
34 //**********************************************
35 Handle(V3d_View) NewGeom_SalomeViewer::activeView() const
37 OCCViewer_Viewer* aViewer = mySelector->viewer();
38 SUIT_ViewManager* aMgr = aViewer->getViewManager();
39 OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
40 return aWnd->getViewPort()->getView();
43 //**********************************************
44 void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
47 if (mySelector == theSel)
50 mySelector->viewer()->getViewManager()->disconnect(this);
56 OCCViewer_Viewer* aViewer = mySelector->viewer();
57 SUIT_ViewManager* aMgr = aViewer->getViewManager();
59 connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)), this, SIGNAL(lastViewClosed()));
60 connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewManager*)), this, SIGNAL(tryCloseView()));
61 connect(aMgr, SIGNAL(deleteView(SUIT_ViewManager*)), this, SIGNAL(deleteView()));
62 connect(aMgr, SIGNAL(viewCreated(SUIT_ViewManager*)), this, SIGNAL(viewCreated()));
63 connect(aMgr, SIGNAL(activated(SUIT_ViewManager*)), this, SIGNAL(activated()));
65 connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), this,
66 SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
67 connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), this,
68 SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
69 connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)), this,
70 SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)));
71 connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), this,
72 SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
73 connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)), this,
74 SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
75 connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)), this,
76 SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*)));
78 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
81 //**********************************************
82 void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent)
84 emit mousePress(theEvent);
87 //**********************************************
88 void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent)
90 emit mouseRelease(theEvent);
91 //if ((theEvent->button() == Qt::RightButton) &&
92 // (theEvent->modifiers() == Qt::NoModifier)) {
93 // QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos());
94 // emit contextMenuRequested(&aEvent);
98 //**********************************************
99 void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent)
101 emit mouseDoubleClick(theEvent);
104 //**********************************************
105 void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow*, QMouseEvent* theEvent)
107 emit mouseMove(theEvent);
110 //**********************************************
111 void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow*, QKeyEvent* theEvent)
113 emit keyPress(theEvent);
116 //**********************************************
117 void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow*, QKeyEvent* theEvent)
119 emit keyRelease(theEvent);
122 //**********************************************
123 void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
125 mySelector->viewer()->enableSelection(isEnabled);
126 // there is a fix for a black-colored window
127 // the viewer rubber band is valid if the values delta is less than 1
128 // TODO: remove this row after moving to SALOME 7.5
129 mySelector->viewer()->setInteractionStyle(isEnabled ? SUIT_ViewModel::STANDARD
130 : SUIT_ViewModel::KEY_FREE);
133 //**********************************************
134 bool NewGeom_SalomeViewer::isSelectionEnabled() const
136 return mySelector->viewer()->isSelectionEnabled();
139 //**********************************************
140 void NewGeom_SalomeViewer::enableMultiselection(bool isEnable)
142 mySelector->viewer()->enableMultiselection(isEnable);
145 //**********************************************
146 bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
148 return mySelector->viewer()->isMultiSelectionEnabled();
151 //**********************************************
152 void NewGeom_SalomeViewer::fitAll()
154 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
155 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
161 //**********************************************
162 void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double theZ)
164 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
165 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
167 Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView();
168 if (!aView3d.IsNull()) {
169 aView3d->SetProj(theX, theY, theZ);
170 aView3d->FitAll(0.01, true, true);
171 aView3d->SetZSize(0.);