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 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);
54 OCCViewer_Viewer* aViewer = mySelector->viewer();
55 SUIT_ViewManager* aMgr = aViewer->getViewManager();
57 connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)), this, SIGNAL(lastViewClosed()));
58 connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewManager*)), this, SIGNAL(tryCloseView()));
59 connect(aMgr, SIGNAL(deleteView(SUIT_ViewManager*)), this, SIGNAL(deleteView()));
60 connect(aMgr, SIGNAL(viewCreated(SUIT_ViewManager*)), this, SIGNAL(viewCreated()));
61 connect(aMgr, SIGNAL(activated(SUIT_ViewManager*)), this, SIGNAL(activated()));
63 connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), this,
64 SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
65 connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), this,
66 SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
67 connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)), this,
68 SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)));
69 connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), this,
70 SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
71 connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)), this,
72 SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
73 connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)), this,
74 SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*)));
76 connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
79 //**********************************************
80 void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent)
82 emit mousePress(theEvent);
85 //**********************************************
86 void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent)
88 emit mouseRelease(theEvent);
89 //if ((theEvent->button() == Qt::RightButton) &&
90 // (theEvent->modifiers() == Qt::NoModifier)) {
91 // QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos());
92 // emit contextMenuRequested(&aEvent);
96 //**********************************************
97 void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent)
99 emit mouseDoubleClick(theEvent);
102 //**********************************************
103 void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow*, QMouseEvent* theEvent)
105 emit mouseMove(theEvent);
108 //**********************************************
109 void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow*, QKeyEvent* theEvent)
111 emit keyPress(theEvent);
114 //**********************************************
115 void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow*, QKeyEvent* theEvent)
117 emit keyRelease(theEvent);
120 //**********************************************
121 void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
123 mySelector->viewer()->enableSelection(isEnabled);
126 //**********************************************
127 bool NewGeom_SalomeViewer::isSelectionEnabled() const
129 return mySelector->viewer()->isSelectionEnabled();
132 //**********************************************
133 void NewGeom_SalomeViewer::enableMultiselection(bool isEnable)
135 mySelector->viewer()->enableMultiselection(isEnable);
138 //**********************************************
139 bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
141 return mySelector->viewer()->isMultiSelectionEnabled();
144 //**********************************************
145 void NewGeom_SalomeViewer::fitAll()
147 SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
148 OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());