]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ViewerProxy.cpp
Salome HOME
Merge branch 'master' into BR_PYTHON_PLUGIN
[modules/shaper.git] / src / XGUI / XGUI_ViewerProxy.cpp
1 #include "XGUI_ViewerProxy.h"
2 #include "XGUI_Workshop.h"
3 #include "XGUI_MainWindow.h"
4 #include "XGUI_ViewPort.h"
5 #include "XGUI_ViewWindow.h"
6 #include "XGUI_Viewer.h"
7 #include "XGUI_SalomeConnector.h"
8
9 XGUI_ViewerProxy::XGUI_ViewerProxy(XGUI_Workshop* theParent)
10     : ModuleBase_IViewer(theParent),
11       myWorkshop(theParent)
12 {
13 }
14
15 Handle(AIS_InteractiveContext) XGUI_ViewerProxy::AISContext() const
16 {
17   if (myWorkshop->isSalomeMode()) {
18     return myWorkshop->salomeConnector()->viewer()->AISContext();
19   } else {
20     return myWorkshop->mainWindow()->viewer()->AISContext();
21   }
22 }
23
24 Handle(V3d_Viewer) XGUI_ViewerProxy::v3dViewer() const
25 {
26   if (myWorkshop->isSalomeMode()) {
27     return myWorkshop->salomeConnector()->viewer()->v3dViewer();
28   } else {
29     return myWorkshop->mainWindow()->viewer()->v3dViewer();
30   }
31 }
32
33 Handle(V3d_View) XGUI_ViewerProxy::activeView() const
34 {
35   if (myWorkshop->isSalomeMode()) {
36     return myWorkshop->salomeConnector()->viewer()->activeView();
37   } else {
38     XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
39     return (aViewer->activeViewWindow()) ? aViewer->activeViewWindow()->viewPort()->getView() :
40     Handle(V3d_View)();
41   }
42 }
43
44 void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ)
45 {
46   Handle(V3d_View) aView3d = activeView();
47   if (!aView3d.IsNull()) {
48     aView3d->SetProj(theX, theY, theZ);
49     aView3d->FitAll(0.01, true, true);
50     aView3d->SetZSize(0.);
51   }
52 }
53
54 void XGUI_ViewerProxy::fitAll()
55 {
56   if (myWorkshop->isSalomeMode()) {
57     myWorkshop->salomeConnector()->viewer()->fitAll();
58   } else {
59     XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
60     if (aViewer->activeViewWindow())
61       aViewer->activeViewWindow()->viewPort()->fitAll();
62   }
63 }
64
65 void XGUI_ViewerProxy::connectToViewer()
66 {
67   if (myWorkshop->isSalomeMode()) {
68     ModuleBase_IViewer* aViewer = myWorkshop->salomeConnector()->viewer();
69
70     connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
71     connect(aViewer, SIGNAL(tryCloseView()), this, SIGNAL(tryCloseView()));
72     connect(aViewer, SIGNAL(deleteView()), this, SIGNAL(deleteView()));
73     connect(aViewer, SIGNAL(viewCreated()), this, SIGNAL(viewCreated()));
74     connect(aViewer, SIGNAL(activated()), this, SIGNAL(activated()));
75
76     connect(aViewer, SIGNAL(mousePress(QMouseEvent*)), this, SIGNAL(mousePress(QMouseEvent*)));
77
78     connect(aViewer, SIGNAL(mouseRelease(QMouseEvent*)), this, SIGNAL(mouseRelease(QMouseEvent*)));
79
80     connect(aViewer, SIGNAL(mouseDoubleClick(QMouseEvent*)), this,
81             SIGNAL(mouseDoubleClick(QMouseEvent*)));
82
83     connect(aViewer, SIGNAL(mouseMove(QMouseEvent*)), this, SIGNAL(mouseMove(QMouseEvent*)));
84
85     connect(aViewer, SIGNAL(keyPress(QKeyEvent*)), this, SIGNAL(keyPress(QKeyEvent*)));
86
87     connect(aViewer, SIGNAL(keyRelease(QKeyEvent*)), this, SIGNAL(keyRelease(QKeyEvent*)));
88
89     connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
90     connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
91             SIGNAL(contextMenuRequested(QContextMenuEvent*)));
92
93   } else {
94     XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
95
96     connect(aViewer, SIGNAL(lastViewClosed()), this, SIGNAL(lastViewClosed()));
97     connect(aViewer, SIGNAL(tryCloseView(XGUI_ViewWindow*)), this, SIGNAL(tryCloseView()));
98     connect(aViewer, SIGNAL(deleteView(XGUI_ViewWindow*)), this, SIGNAL(deleteView()));
99     connect(aViewer, SIGNAL(viewCreated(XGUI_ViewWindow*)), this, SIGNAL(viewCreated()));
100     connect(aViewer, SIGNAL(activated(XGUI_ViewWindow*)), this, SIGNAL(activated()));
101
102     connect(aViewer, SIGNAL(mousePress(XGUI_ViewWindow*, QMouseEvent*)), this,
103             SLOT(onMousePress(XGUI_ViewWindow*, QMouseEvent*)));
104     connect(aViewer, SIGNAL(mouseRelease(XGUI_ViewWindow*, QMouseEvent*)), this,
105             SLOT(onMouseRelease(XGUI_ViewWindow*, QMouseEvent*)));
106     connect(aViewer, SIGNAL(mouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*)), this,
107             SLOT(onMouseDoubleClick(XGUI_ViewWindow*, QMouseEvent*)));
108     connect(aViewer, SIGNAL(mouseMove(XGUI_ViewWindow*, QMouseEvent*)), this,
109             SLOT(onMouseMove(XGUI_ViewWindow*, QMouseEvent*)));
110     connect(aViewer, SIGNAL(keyPress(XGUI_ViewWindow*, QKeyEvent*)), this,
111             SLOT(onKeyPress(XGUI_ViewWindow*, QKeyEvent*)));
112     connect(aViewer, SIGNAL(keyRelease(XGUI_ViewWindow*, QKeyEvent*)), this,
113             SLOT(onKeyRelease(XGUI_ViewWindow*, QKeyEvent*)));
114
115     connect(aViewer, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
116     connect(aViewer, SIGNAL(contextMenuRequested(QContextMenuEvent*)), this,
117             SIGNAL(contextMenuRequested(QContextMenuEvent*)));
118   }
119 }
120
121 void XGUI_ViewerProxy::onMousePress(XGUI_ViewWindow*, QMouseEvent* theEvent)
122 {
123   emit mousePress(theEvent);
124 }
125
126 void XGUI_ViewerProxy::onMouseRelease(XGUI_ViewWindow*, QMouseEvent* theEvent)
127 {
128   emit mouseRelease(theEvent);
129 }
130
131 void XGUI_ViewerProxy::onMouseDoubleClick(XGUI_ViewWindow*, QMouseEvent* theEvent)
132 {
133   emit mouseDoubleClick(theEvent);
134 }
135
136 void XGUI_ViewerProxy::onMouseMove(XGUI_ViewWindow*, QMouseEvent* theEvent)
137 {
138   emit mouseMove(theEvent);
139 }
140
141 void XGUI_ViewerProxy::onKeyPress(XGUI_ViewWindow*, QKeyEvent* theEvent)
142 {
143   emit keyPress(theEvent);
144 }
145
146 void XGUI_ViewerProxy::onKeyRelease(XGUI_ViewWindow*, QKeyEvent* theEvent)
147 {
148   emit keyRelease(theEvent);
149 }
150
151 //***************************************
152 void XGUI_ViewerProxy::enableSelection(bool isEnabled)
153 {
154   if (myWorkshop->isSalomeMode()) {
155     myWorkshop->salomeConnector()->viewer()->enableSelection(isEnabled);
156   } else {
157     myWorkshop->mainWindow()->viewer()->setSelectionEnabled(isEnabled);
158   }
159 }
160
161 //***************************************
162 bool XGUI_ViewerProxy::isSelectionEnabled() const
163 {
164   if (myWorkshop->isSalomeMode()) {
165     return myWorkshop->salomeConnector()->viewer()->isSelectionEnabled();
166   } else {
167     return myWorkshop->mainWindow()->viewer()->isSelectionEnabled();
168   }
169 }
170
171 //***************************************
172 void XGUI_ViewerProxy::enableMultiselection(bool isEnable)
173 {
174   if (myWorkshop->isSalomeMode()) {
175     myWorkshop->salomeConnector()->viewer()->enableMultiselection(isEnable);
176   } else {
177     myWorkshop->mainWindow()->viewer()->setMultiSelectionEnabled(isEnable);
178   }
179 }
180
181 //***************************************
182 bool XGUI_ViewerProxy::isMultiSelectionEnabled() const
183 {
184   if (myWorkshop->isSalomeMode()) {
185     return myWorkshop->salomeConnector()->viewer()->isMultiSelectionEnabled();
186   } else {
187     return myWorkshop->mainWindow()->viewer()->isMultiSelectionEnabled();
188   }
189 }