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