]> SALOME platform Git repositories - modules/shaper.git/blob - src/NewGeom/NewGeom_SalomeViewer.cpp
Salome HOME
30.10.2014. Redesigned boolean feature.
[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     : ModuleBase_IViewer(theParent),
15       mySelector(0)
16 {
17 }
18
19 //**********************************************
20 Handle(AIS_InteractiveContext) NewGeom_SalomeViewer::AISContext() const
21 {
22   if (mySelector && mySelector->viewer())
23     return mySelector->viewer()->getAISContext();
24   Handle(AIS_InteractiveContext) aNull;
25   return aNull;
26 }
27
28 //**********************************************
29 Handle(V3d_Viewer) NewGeom_SalomeViewer::v3dViewer() const
30 {
31   return mySelector->viewer()->getViewer3d();
32 }
33
34 //**********************************************
35 Handle(V3d_View) NewGeom_SalomeViewer::activeView() const
36 {
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();
41 }
42
43 //**********************************************
44 void NewGeom_SalomeViewer::setSelector(NewGeom_OCCSelector* theSel)
45 {
46   if (mySelector) {
47     if (mySelector == theSel)
48       return;
49     else {
50       mySelector->viewer()->getViewManager()->disconnect(this);
51     }
52   }
53   mySelector = theSel;
54   if (!mySelector)
55     return;
56   OCCViewer_Viewer* aViewer = mySelector->viewer();
57   SUIT_ViewManager* aMgr = aViewer->getViewManager();
58
59   connect(aMgr, SIGNAL(lastViewClosed(SUIT_ViewManager*)), this, SIGNAL(lastViewClosed()));
60   connect(aMgr, SIGNAL(tryCloseView(SUIT_ViewManager*)), this, SIGNAL(tryCloseView()));
61   connect(aMgr, SIGNAL(deleteView(SUIT_ViewManager*)), this, SIGNAL(deleteView()));
62   connect(aMgr, SIGNAL(viewCreated(SUIT_ViewManager*)), this, SIGNAL(viewCreated()));
63   connect(aMgr, SIGNAL(activated(SUIT_ViewManager*)), this, SIGNAL(activated()));
64
65   connect(aMgr, SIGNAL(mousePress(SUIT_ViewWindow*, QMouseEvent*)), this,
66           SLOT(onMousePress(SUIT_ViewWindow*, QMouseEvent*)));
67   connect(aMgr, SIGNAL(mouseRelease(SUIT_ViewWindow*, QMouseEvent*)), this,
68           SLOT(onMouseRelease(SUIT_ViewWindow*, QMouseEvent*)));
69   connect(aMgr, SIGNAL(mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)), this,
70           SLOT(onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*)));
71   connect(aMgr, SIGNAL(mouseMove(SUIT_ViewWindow*, QMouseEvent*)), this,
72           SLOT(onMouseMove(SUIT_ViewWindow*, QMouseEvent*)));
73   connect(aMgr, SIGNAL(keyPress(SUIT_ViewWindow*, QKeyEvent*)), this,
74           SLOT(onKeyPress(SUIT_ViewWindow*, QKeyEvent*)));
75   connect(aMgr, SIGNAL(keyRelease(SUIT_ViewWindow*, QKeyEvent*)), this,
76           SLOT(onKeyRelease(SUIT_ViewWindow*, QKeyEvent*)));
77
78   connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
79 }
80
81 //**********************************************
82 void NewGeom_SalomeViewer::onMousePress(SUIT_ViewWindow*, QMouseEvent* theEvent)
83 {
84   emit mousePress(theEvent);
85 }
86
87 //**********************************************
88 void NewGeom_SalomeViewer::onMouseRelease(SUIT_ViewWindow*, QMouseEvent* theEvent)
89 {
90   emit mouseRelease(theEvent);
91   //if ((theEvent->button() == Qt::RightButton) && 
92   //  (theEvent->modifiers() == Qt::NoModifier)) {
93   //  QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos());
94   //  emit contextMenuRequested(&aEvent);
95   //}
96 }
97
98 //**********************************************
99 void NewGeom_SalomeViewer::onMouseDoubleClick(SUIT_ViewWindow*, QMouseEvent* theEvent)
100 {
101   emit mouseDoubleClick(theEvent);
102 }
103
104 //**********************************************
105 void NewGeom_SalomeViewer::onMouseMove(SUIT_ViewWindow*, QMouseEvent* theEvent)
106 {
107   emit mouseMove(theEvent);
108 }
109
110 //**********************************************
111 void NewGeom_SalomeViewer::onKeyPress(SUIT_ViewWindow*, QKeyEvent* theEvent)
112 {
113   emit keyPress(theEvent);
114 }
115
116 //**********************************************
117 void NewGeom_SalomeViewer::onKeyRelease(SUIT_ViewWindow*, QKeyEvent* theEvent)
118 {
119   emit keyRelease(theEvent);
120 }
121
122 //**********************************************
123 void NewGeom_SalomeViewer::enableSelection(bool isEnabled)
124 {
125   mySelector->viewer()->enableSelection(isEnabled);
126 }
127
128 //**********************************************
129 bool NewGeom_SalomeViewer::isSelectionEnabled() const
130 {
131   return mySelector->viewer()->isSelectionEnabled();
132 }
133
134 //**********************************************
135 void NewGeom_SalomeViewer::enableMultiselection(bool isEnable)
136 {
137   mySelector->viewer()->enableMultiselection(isEnable);
138 }
139
140 //**********************************************
141 bool NewGeom_SalomeViewer::isMultiSelectionEnabled() const
142 {
143   return mySelector->viewer()->isMultiSelectionEnabled();
144 }
145
146 //**********************************************
147 void NewGeom_SalomeViewer::fitAll()
148 {
149   SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
150   OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
151   if (aVFrame) {
152     aVFrame->onFitAll();
153   }
154 }
155
156 //**********************************************
157 void NewGeom_SalomeViewer::setViewProjection(double theX, double theY, double theZ)
158 {
159   SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager();
160   OCCViewer_ViewFrame* aVFrame = dynamic_cast<OCCViewer_ViewFrame*>(aMgr->getActiveView());
161   if (aVFrame) {
162     Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView();
163     if (!aView3d.IsNull()) {
164       aView3d->SetProj(theX, theY, theZ);
165       aView3d->FitAll(0.01, true, true);
166       aView3d->SetZSize(0.);
167     }
168   }
169 }