2 #include "NewGeom_SalomeViewer.h"
3 #include "NewGeom_OCCSelector.h"
5 #include <OCCViewer_ViewWindow.h>
6 #include <OCCViewer_ViewPort3d.h>
7 #include <OCCViewer_ViewFrame.h>
9 #include <SUIT_ViewManager.h>
11 #include <QMouseEvent>
12 #include <QContextMenuEvent>
15 NewGeom_SalomeViewer::NewGeom_SalomeViewer(QObject* theParent)
16 : XGUI_SalomeViewer(theParent), mySelector(0)
20 //**********************************************
21 Handle(AIS_InteractiveContext) NewGeom_SalomeViewer::AISContext() const
23 return mySelector->viewer()->getAISContext();
26 //**********************************************
27 Handle(V3d_Viewer) NewGeom_SalomeViewer::v3dViewer() const
29 return mySelector->viewer()->getViewer3d();
32 //**********************************************
33 Handle(V3d_View) NewGeom_SalomeViewer::activeView() const
35 OCCViewer_Viewer* aViewer = mySelector->viewer();
36 SUIT_ViewManager* aMgr = aViewer->getViewManager();
37 OCCViewer_ViewWindow* aWnd = static_cast<OCCViewer_ViewWindow*>(aMgr->getActiveView());
38 return aWnd->getViewPort()->getView();
41 //**********************************************
42 void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
45 if (mySelector == theSel)
48 mySelector->viewer()->getViewManager()->disconnect(this);
52 OCCViewer_Viewer* aViewer = mySelector->viewer();
53 SUIT_ViewManager* aMgr = aViewer->getViewManager();
55 connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)),
56 this, SIGNAL(lastViewClosed()));
57 connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewManager*)),
58 this, SIGNAL(tryCloseView()));
59 connect(aMgr, SIGNAL(deleteView(SUIT_ViewManager*)),
60 this, SIGNAL(deleteView()));
61 connect(aMgr, SIGNAL(viewCreated(SUIT_ViewManager*)),
62 this, SIGNAL(viewCreated()));
63 connect(aMgr, SIGNAL(activated(SUIT_ViewManager*)),
64 this, SIGNAL(activated()));
66 connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)),
67 this, SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
68 connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)),
69 this, SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
70 connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)),
71 this, SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)));
72 connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)),
73 this, SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
74 connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)),
75 this, SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
76 connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)),
77 this, SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*)));
79 connect(aViewer, SIGNAL(selectionChanged()),
80 this, SIGNAL(selectionChanged()));
83 //**********************************************
84 void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent)
86 emit mousePress(theEvent);
89 //**********************************************
90 void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent)
92 emit mouseRelease(theEvent);
93 //if ((theEvent->button() == Qt::RightButton) &&
94 // (theEvent->modifiers() == Qt::NoModifier)) {
95 // QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos());
96 // emit contextMenuRequested(&aEvent);
100 //**********************************************
101 void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent)
103 emit mouseDoubleClick(theEvent);
106 //**********************************************
107 void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow*, QMouseEvent* theEvent)
109 emit mouseMove(theEvent);
112 //**********************************************
113 void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow*, QKeyEvent* theEvent)
115 emit keyPress(theEvent);
118 //**********************************************
119 void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow*, QKeyEvent* theEvent)
121 emit keyRelease(theEvent);
124 //**********************************************
125 void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
127 mySelector->viewer()->enableSelection(isEnabled);
130 //**********************************************
131 bool NewGeom_SalomeViewer::isSelectionEnabled() const
133 return mySelector->viewer()->isSelectionEnabled();
136 //**********************************************
137 void NewGeom_SalomeViewer::enableMultiselection(bool isEnable)
139 mySelector->viewer()->enableMultiselection(isEnable);
142 //**********************************************
143 bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
145 return mySelector->viewer()->isMultiSelectionEnabled();
148 //**********************************************
149 void NewGeom_SalomeViewer::fitAll()
151 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
152 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());