Salome HOME
sources v1.2
[modules/yacs.git] / src / SALOMEGUI / SALOMEGUI_Swig.cxx
1 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SALOMEGUI_Swig.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 using namespace std;
30 #include "QAD_Application.h"
31 #include "QAD_Desktop.h"
32 #include "QAD_Study.h"
33 #include "QAD_RightFrame.h"
34 #include "QAD_StudyFrame.h"
35 #include "SALOMEGUI_Swig.hxx"
36 #include "utilities.h"
37
38 #include "SALOME_Selection.h"
39 #include "SALOME_InteractiveObject.hxx"
40 #include "SALOME_ListIteratorOfListIO.hxx"
41
42
43 /*!
44   Constructor
45 */
46 SALOMEGUI_Swig::SALOMEGUI_Swig()
47 // VSR 06-05-03 : _studyId(0)
48 {
49   //  MESSAGE("Constructeur");
50 }
51
52 /*!
53   Destructor
54 */
55 SALOMEGUI_Swig::~SALOMEGUI_Swig()
56 {
57   //  MESSAGE("Destructeur");
58 }
59
60 /*!
61   Gets active study or 0 if no study opened
62 */
63 QAD_Study* SALOMEGUI_Swig::getActiveStudy()
64 {
65   QAD_Application* app = QAD_Application::getDesktop()->getActiveApp();
66   if ( app ) return app->getActiveStudy();
67   return 0;
68 }
69
70 /*!
71   Call when updated object browser.
72 */
73 void SALOMEGUI_Swig::updateObjBrowser( bool updateSelection )
74 {
75   // VSR 06-05-03 ============================================================
76   //QAD_Study* myActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
77   QAD_Study* myActiveStudy = getActiveStudy();
78   if ( !myActiveStudy) return;
79   // end of VSR 06-05-03 =====================================================
80   myActiveStudy->updateObjBrowser( updateSelection );
81 }
82
83 /*!
84   Returns active Study Id.
85 */
86 int SALOMEGUI_Swig::getActiveStudyId()
87 {
88   // NRI 24-02-03 :
89   //  if (_studyId ==0)
90   //    {
91   //  QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
92   //  _name = myStudy->getTitle();
93
94   // VSR 06-05-03 ============================================================
95   // _studyId = QAD_Application::getDesktop()->getActiveStudy()->getStudyId();
96   int _studyId = 0;
97   QAD_Study* myActiveStudy = getActiveStudy();
98   if ( myActiveStudy) _studyId = myActiveStudy->getStudyId();
99   // SCRUTE(_studyId);
100   // end of VSR 06-05-03 =====================================================
101   //    }
102   return _studyId;
103 }
104
105 /*!
106   Returns active Study Name.
107 */
108 const char *SALOMEGUI_Swig::getActiveStudyName()
109 {
110   // VSR 06-05-03 ============================================================
111   // QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
112   // _name = myStudy->getTitle();
113   QString _name = QString::null;
114   QAD_Study* myActiveStudy = getActiveStudy();
115   if ( myActiveStudy) _name = myActiveStudy->getTitle();
116   // end of VSR 06-05-03 =====================================================
117
118   // NRI 24-02-03 :
119   //if (_studyId ==0) 
120   //  getActiveStudyId();
121   return _name.latin1();
122 }
123
124 /*!
125   Returns the number of selected objects.
126 */
127 int SALOMEGUI_Swig::SelectedCount()
128 {
129   // VSR 06-05-03 ============================================================
130   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
131   QAD_Study* myStudy = getActiveStudy();
132   if ( !myStudy) return 0;
133   // end of VSR 06-05-03 =====================================================
134   SALOME_Selection* Sel
135     = SALOME_Selection::Selection( myStudy->getSelection() );
136   return Sel->IObjectCount();
137 }
138
139 /*!
140   Returns the selected object at index i.
141 */
142 const char* SALOMEGUI_Swig::getSelected(int i)
143 {
144   // VSR 06-05-03 ============================================================
145   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
146   QAD_Study* myStudy = getActiveStudy();
147   if ( !myStudy) return "";
148   // end of VSR 06-05-03 =====================================================
149   SALOME_Selection* Sel
150     = SALOME_Selection::Selection( myStudy->getSelection() );
151   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
152   int index = 0;
153   for(;It.More();It.Next())
154     {
155       Handle(SALOME_InteractiveObject) IObject = It.Value();
156       if ( i == index++ )
157         {
158           if ( IObject->hasEntry() )
159             return IObject->getEntry();
160         }
161     }
162   return "";
163 }
164
165 /*!
166   Add object with Entry into selection.
167 */
168 void SALOMEGUI_Swig::AddIObject(const char *Entry)
169 {
170   // VSR 06-05-03 ============================================================
171   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
172   QAD_Study* myStudy = getActiveStudy();
173   if ( !myStudy) return;
174   // end of VSR 06-05-03 =====================================================
175   SALOME_Selection* Sel
176     = SALOME_Selection::Selection( myStudy->getSelection() );
177
178   if ( !IsInCurrentView( Entry ) )
179     return;
180   
181   Handle(SALOME_InteractiveObject) IO = 
182     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
183   Sel->AddIObject( IO );
184 }
185
186
187 /*!
188   Removes object with Entry into selection.
189 */
190 void SALOMEGUI_Swig::RemoveIObject(const char *Entry)
191 {
192   // VSR 06-05-03 ============================================================
193   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
194   QAD_Study* myStudy = getActiveStudy();
195   if ( !myStudy) return;
196   // end of VSR 06-05-03 =====================================================
197   SALOME_Selection* Sel
198     = SALOME_Selection::Selection( myStudy->getSelection() );
199
200   if ( !IsInCurrentView( Entry ) )
201     return;
202
203   Handle(SALOME_InteractiveObject) IO = 
204     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
205   Sel->RemoveIObject( IO );
206 }
207
208
209 /*!
210   Removes all objects into selection.
211 */
212 void SALOMEGUI_Swig::ClearIObjects()
213 {
214   // VSR 06-05-03 ============================================================
215   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
216   QAD_Study* myStudy = getActiveStudy();
217   if ( !myStudy) return;
218   // end of VSR 06-05-03 =====================================================
219   SALOME_Selection* Sel
220     = SALOME_Selection::Selection( myStudy->getSelection() );
221   Sel->ClearIObjects();
222 }
223
224 /*!
225   Display
226 */              
227 void SALOMEGUI_Swig::Display(const char *Entry)
228 {
229   // VSR 06-05-03 ============================================================
230   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
231   QAD_Study* myStudy = getActiveStudy();
232   if ( !myStudy) return;
233   // end of VSR 06-05-03 =====================================================
234
235   if ( !IsInCurrentView( Entry ) )
236     return;
237
238   Handle(SALOME_InteractiveObject) IO = 
239     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
240
241   myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Display(IO);
242 }
243
244 /*!
245   Display only
246 */
247 void SALOMEGUI_Swig::DisplayOnly(const char *Entry)
248 {
249   // VSR 06-05-03 ============================================================
250   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
251   QAD_Study* myStudy = getActiveStudy();
252   if ( !myStudy) return;
253   // end of VSR 06-05-03 =====================================================
254
255   if ( !IsInCurrentView( Entry ) )
256     return;
257
258   Handle(SALOME_InteractiveObject) IO = 
259     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
260
261   if ( !IO.IsNull() ) {
262     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->DisplayOnly(IO);
263   }
264 }
265
266 /*!
267   Erase
268 */
269 void SALOMEGUI_Swig::Erase(const char *Entry)
270 {
271   // VSR 06-05-03 ============================================================
272   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
273   QAD_Study* myStudy = getActiveStudy();
274   if ( !myStudy) return;
275   // end of VSR 06-05-03 =====================================================
276
277   if ( !IsInCurrentView( Entry ) )
278     return;
279
280   Handle(SALOME_InteractiveObject) IO = 
281     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
282
283   myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Erase(IO);
284 }
285
286 /*!
287   Display all
288 */
289 void SALOMEGUI_Swig::DisplayAll()
290 {
291   // VSR 06-05-03 ============================================================
292   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
293   QAD_Study* myStudy = getActiveStudy();
294   if ( !myStudy) return;
295   // end of VSR 06-05-03 =====================================================
296   myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->DisplayAll();
297 }
298
299 /*!
300   Erase only
301 */
302 void SALOMEGUI_Swig::EraseAll()
303 {
304   // VSR 06-05-03 ============================================================
305   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
306   QAD_Study* myStudy = getActiveStudy();
307   if ( !myStudy) return;
308   // end of VSR 06-05-03 =====================================================
309   SALOME_Selection* Sel 
310     = SALOME_Selection::Selection( myStudy->getSelection() );
311   
312   Sel->ClearIObjects();
313   myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->EraseAll();
314 }
315
316 /*!
317   Checks if object is displayed in current viewer
318 */
319 bool SALOMEGUI_Swig::IsInCurrentView(const char *Entry)
320 {
321   // VSR 06-05-03 ============================================================
322   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
323   QAD_Study* myStudy = getActiveStudy();
324   if ( !myStudy) return false;
325   // end of VSR 06-05-03 =====================================================
326   return myStudy->isInViewer( Entry, myStudy->getActiveStudyFrame()->entry() );
327 }
328
329 /*!
330   Gets VTK renderer if available
331 */
332 //san:T3.13 - move getRenderer() implementation from here to SalomePy.cxx
333 /*vtkRenderer *SALOMEGUI_Swig::getRenderer(int viewId)
334 {
335   // VSR 06-05-03 ============================================================
336   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
337   QAD_Application* app = QAD_Application::getDesktop()->getActiveApp();
338   if ( !app ) return NULL;
339   QAD_Study* myStudy = app->getActiveStudy();
340   if ( !myStudy) return NULL;
341   // end of VSR 06-05-03 =====================================================
342   int nbStudyFrames = myStudy->getStudyFramesCount();
343   vtkRenderer *myRenderer = NULL;
344   if (viewId == -1) // find the first frame with VTK viewer & get renderer
345     {
346       int i=0;
347       for(i=0; i<nbStudyFrames; i++)
348         {
349           if ( myStudy->getStudyFrame(i)->getTypeView() == VIEW_VTK )
350             {
351               myRenderer = myStudy->getStudyFrame(i)->getRightFrame()->getViewFrame()->getRenderer();
352               break;
353             }
354         }
355     }
356   else     // get the VTK renderer of a given frame
357     {
358       SCRUTE(viewId);
359       if ((viewId >=0) && (viewId <nbStudyFrames))
360         myRenderer = myStudy->getStudyFrame(viewId)->getRightFrame()->getViewFrame()->getRenderer();
361     }
362   if (myRenderer == NULL) INFOS("No VTK Renderer available !");
363   return myRenderer;
364 }
365 */
366