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