Salome HOME
f63b3d77c17961b0f92a879d55782c74a471f7cb
[modules/shaper.git] / src / NewGeom / NewGeom_SalomeViewer.cpp
1 #include "NewGeom_SalomeViewer.h"
2 #include "NewGeom_OCCSelector.h"
3
4 #include <OCCViewer_ViewWindow.h>
5 #include <OCCViewer_ViewPort3d.h>
6 #include <OCCViewer_ViewFrame.h>
7
8 #include <SUIT_ViewManager.h>
9
10 #include <QMouseEvent>
11 #include <QContextMenuEvent>
12
13 NewGeom_SalomeViewer::NewGeom_SalomeViewer(QObject* theParent)
14     : XGUI_SalomeViewer(theParent),
15       mySelector(0)
16 {
17 }
18
19 //**********************************************
20 Handle(AIS_InteractiveContext) NewGeom_SalomeViewer::AISContext() const
21 {
22   return mySelector->viewer()->getAISContext();
23 }
24
25 //**********************************************
26 Handle(V3d_Viewer) NewGeom_SalomeViewer::v3dViewer() const
27 {
28   return mySelector->viewer()->getViewer3d();
29 }
30
31 //**********************************************
32 Handle(V3d_View) NewGeom_SalomeViewer::activeView() const
33 {
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();
38 }
39
40 //**********************************************
41 void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
42 {
43   if (mySelector) {
44     if (mySelector == theSel)
45       return;
46     else {
47       mySelector->viewer()->getViewManager()->disconnect(this);
48     }
49   }
50   mySelector = theSel;
51   OCCViewer_Viewer* aViewer = mySelector->viewer();
52   SUIT_ViewManager* aMgr = aViewer->getViewManager();
53
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()));
59
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*)));
72
73   connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
74 }
75
76 //**********************************************
77 void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent)
78 {
79   emit mousePress(theEvent);
80 }
81
82 //**********************************************
83 void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent)
84 {
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);
90   //}
91 }
92
93 //**********************************************
94 void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent)
95 {
96   emit mouseDoubleClick(theEvent);
97 }
98
99 //**********************************************
100 void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow*, QMouseEvent* theEvent)
101 {
102   emit mouseMove(theEvent);
103 }
104
105 //**********************************************
106 void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow*, QKeyEvent* theEvent)
107 {
108   emit keyPress(theEvent);
109 }
110
111 //**********************************************
112 void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow*, QKeyEvent* theEvent)
113 {
114   emit keyRelease(theEvent);
115 }
116
117 //**********************************************
118 void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
119 {
120   mySelector->viewer()->enableSelection(isEnabled);
121 }
122
123 //**********************************************
124 bool NewGeom_SalomeViewer::isSelectionEnabled() const
125 {
126   return mySelector->viewer()->isSelectionEnabled();
127 }
128
129 //**********************************************
130 void NewGeom_SalomeViewer::enableMultiselection(bool isEnable)
131 {
132   mySelector->viewer()->enableMultiselection(isEnable);
133 }
134
135 //**********************************************
136 bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
137 {
138   return mySelector->viewer()->isMultiSelectionEnabled();
139 }
140
141 //**********************************************
142 void NewGeom_SalomeViewer::fitAll()
143 {
144   SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
145   OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
146   if (aVFrame) {
147     aVFrame->onFitAll();
148   }
149 }