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 : XGUI_SalomeViewer(theParent),
19 //**********************************************
20 Handle(AIS_InteractiveContext) NewGeom_SalomeViewer::AISContext() const
22 return mySelector->viewer()->getAISContext();
25 //**********************************************
26 Handle(V3d_Viewer) NewGeom_SalomeViewer::v3dViewer() const
28 return mySelector->viewer()->getViewer3d();
31 //**********************************************
32 Handle(V3d_View) NewGeom_SalomeViewer::activeView() const
34 OCCViewer_Viewer* aViewer = mySelector->viewer();
35 SUIT_ViewManager* aMgr = aViewer->getViewManager();
36 OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
37 return aWnd->getViewPort()->getView();
40 //**********************************************
41 void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
44 if (mySelector == theSel)
47 mySelector->viewer()->getViewManager()->disconnect(this);
51 OCCViewer_Viewer* aViewer = mySelector->viewer();
52 SUIT_ViewManager* aMgr = aViewer->getViewManager();
54 connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)), this, SIGNAL(lastViewClosed()));
55 connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewManager*)), this, SIGNAL(tryCloseView()));
56 connect(aMgr, SIGNAL(deleteView(SUIT_ViewManager*)), this, SIGNAL(deleteView()));
57 connect(aMgr, SIGNAL(viewCreated(SUIT_ViewManager*)), this, SIGNAL(viewCreated()));
58 connect(aMgr, SIGNAL(activated(SUIT_ViewManager*)), this, SIGNAL(activated()));
60 connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), this,
61 SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
62 connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), this,
63 SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
64 connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)), this,
65 SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)));
66 connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), this,
67 SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
68 connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)), this,
69 SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
70 connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)), this,
71 SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*)));
73 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
76 //**********************************************
77 void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent)
79 emit mousePress(theEvent);
82 //**********************************************
83 void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent)
85 emit mouseRelease(theEvent);
86 //if ((theEvent->button() == Qt::RightButton) &&
87 // (theEvent->modifiers() == Qt::NoModifier)) {
88 // QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos());
89 // emit contextMenuRequested(&aEvent);
93 //**********************************************
94 void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent)
96 emit mouseDoubleClick(theEvent);
99 //**********************************************
100 void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow*, QMouseEvent* theEvent)
102 emit mouseMove(theEvent);
105 //**********************************************
106 void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow*, QKeyEvent* theEvent)
108 emit keyPress(theEvent);
111 //**********************************************
112 void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow*, QKeyEvent* theEvent)
114 emit keyRelease(theEvent);
117 //**********************************************
118 void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
120 mySelector->viewer()->enableSelection(isEnabled);
123 //**********************************************
124 bool NewGeom_SalomeViewer::isSelectionEnabled() const
126 return mySelector->viewer()->isSelectionEnabled();
129 //**********************************************
130 void NewGeom_SalomeViewer::enableMultiselection(bool isEnable)
132 mySelector->viewer()->enableMultiselection(isEnable);
135 //**********************************************
136 bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
138 return mySelector->viewer()->isMultiSelectionEnabled();
141 //**********************************************
142 void NewGeom_SalomeViewer::fitAll()
144 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
145 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());