Salome HOME
This commit was generated by cvs2git to track changes on a CVS vendor
[modules/kernel.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 name of component.
126 */
127 const char* SALOMEGUI_Swig::getComponentName( const char* ComponentUserName )
128 {
129   return QAD_Application::getDesktop()->getComponentName( ComponentUserName );
130 }
131 /*!
132   Returns the user name of component.
133 */
134 const char* SALOMEGUI_Swig::getComponentUserName( const char* ComponentName )
135 {
136   return QAD_Application::getDesktop()->getComponentUserName( ComponentName );
137 }
138
139 /*!
140   Returns the number of selected objects.
141 */
142 int SALOMEGUI_Swig::SelectedCount()
143 {
144   // VSR 06-05-03 ============================================================
145   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
146   QAD_Study* myStudy = getActiveStudy();
147   if ( !myStudy) return 0;
148   // end of VSR 06-05-03 =====================================================
149   SALOME_Selection* Sel
150     = SALOME_Selection::Selection( myStudy->getSelection() );
151   return Sel->IObjectCount();
152 }
153
154 /*!
155   Returns the selected object at index i.
156 */
157 const char* SALOMEGUI_Swig::getSelected(int i)
158 {
159   // VSR 06-05-03 ============================================================
160   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
161   QAD_Study* myStudy = getActiveStudy();
162   if ( !myStudy) return "";
163   // end of VSR 06-05-03 =====================================================
164   SALOME_Selection* Sel
165     = SALOME_Selection::Selection( myStudy->getSelection() );
166   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
167   int index = 0;
168   for(;It.More();It.Next())
169     {
170       Handle(SALOME_InteractiveObject) IObject = It.Value();
171       if ( i == index++ )
172         {
173           if ( IObject->hasEntry() )
174             return IObject->getEntry();
175         }
176     }
177   return "";
178 }
179
180 /*!
181   Add object with Entry into selection.
182 */
183 void SALOMEGUI_Swig::AddIObject(const char *Entry)
184 {
185   // VSR 06-05-03 ============================================================
186   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
187   QAD_Study* myStudy = getActiveStudy();
188   if ( !myStudy) return;
189   // end of VSR 06-05-03 =====================================================
190   SALOME_Selection* Sel
191     = SALOME_Selection::Selection( myStudy->getSelection() );
192
193   if ( !IsInCurrentView( Entry ) )
194     return;
195   
196   Handle(SALOME_InteractiveObject) IO = 
197     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
198   Sel->AddIObject( IO );
199 }
200
201
202 /*!
203   Removes object with Entry into selection.
204 */
205 void SALOMEGUI_Swig::RemoveIObject(const char *Entry)
206 {
207   // VSR 06-05-03 ============================================================
208   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
209   QAD_Study* myStudy = getActiveStudy();
210   if ( !myStudy) return;
211   // end of VSR 06-05-03 =====================================================
212   SALOME_Selection* Sel
213     = SALOME_Selection::Selection( myStudy->getSelection() );
214
215   if ( !IsInCurrentView( Entry ) )
216     return;
217
218   Handle(SALOME_InteractiveObject) IO = 
219     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
220   Sel->RemoveIObject( IO );
221 }
222
223
224 /*!
225   Removes all objects into selection.
226 */
227 void SALOMEGUI_Swig::ClearIObjects()
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   SALOME_Selection* Sel
235     = SALOME_Selection::Selection( myStudy->getSelection() );
236   Sel->ClearIObjects();
237 }
238
239 /*!
240   Display
241 */              
242 void SALOMEGUI_Swig::Display(const char *Entry)
243 {
244   // VSR 06-05-03 ============================================================
245   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
246   QAD_Study* myStudy = getActiveStudy();
247   if ( !myStudy) return;
248   // end of VSR 06-05-03 =====================================================
249
250   if ( !IsInCurrentView( Entry ) )
251     return;
252
253   Handle(SALOME_InteractiveObject) IO = 
254     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
255
256   myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Display(IO);
257 }
258
259 /*!
260   Display only
261 */
262 void SALOMEGUI_Swig::DisplayOnly(const char *Entry)
263 {
264   // VSR 06-05-03 ============================================================
265   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
266   QAD_Study* myStudy = getActiveStudy();
267   if ( !myStudy) return;
268   // end of VSR 06-05-03 =====================================================
269
270   if ( !IsInCurrentView( Entry ) )
271     return;
272
273   Handle(SALOME_InteractiveObject) IO = 
274     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
275
276   if ( !IO.IsNull() ) {
277     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->DisplayOnly(IO);
278   }
279 }
280
281 /*!
282   Erase
283 */
284 void SALOMEGUI_Swig::Erase(const char *Entry)
285 {
286   // VSR 06-05-03 ============================================================
287   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
288   QAD_Study* myStudy = getActiveStudy();
289   if ( !myStudy) return;
290   // end of VSR 06-05-03 =====================================================
291
292   if ( !IsInCurrentView( Entry ) )
293     return;
294
295   Handle(SALOME_InteractiveObject) IO = 
296     myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
297
298   myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Erase(IO);
299 }
300
301 /*!
302   Display all
303 */
304 void SALOMEGUI_Swig::DisplayAll()
305 {
306   // VSR 06-05-03 ============================================================
307   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
308   QAD_Study* myStudy = getActiveStudy();
309   if ( !myStudy) return;
310   // end of VSR 06-05-03 =====================================================
311   myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->DisplayAll();
312 }
313
314 /*!
315   Erase only
316 */
317 void SALOMEGUI_Swig::EraseAll()
318 {
319   // VSR 06-05-03 ============================================================
320   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
321   QAD_Study* myStudy = getActiveStudy();
322   if ( !myStudy) return;
323   // end of VSR 06-05-03 =====================================================
324   SALOME_Selection* Sel 
325     = SALOME_Selection::Selection( myStudy->getSelection() );
326   
327   Sel->ClearIObjects();
328   myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->EraseAll();
329 }
330
331 /*!
332   Checks if object is displayed in current viewer
333 */
334 bool SALOMEGUI_Swig::IsInCurrentView(const char *Entry)
335 {
336   // VSR 06-05-03 ============================================================
337   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
338   QAD_Study* myStudy = getActiveStudy();
339   if ( !myStudy) return false;
340   // end of VSR 06-05-03 =====================================================
341   return myStudy->isInViewer( Entry, myStudy->getActiveStudyFrame()->entry() );
342 }
343
344 /*!
345   Gets VTK renderer if available
346 */
347 //san:T3.13 - move getRenderer() implementation from here to SalomePy.cxx
348 /*vtkRenderer *SALOMEGUI_Swig::getRenderer(int viewId)
349 {
350   // VSR 06-05-03 ============================================================
351   //QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
352   QAD_Application* app = QAD_Application::getDesktop()->getActiveApp();
353   if ( !app ) return NULL;
354   QAD_Study* myStudy = app->getActiveStudy();
355   if ( !myStudy) return NULL;
356   // end of VSR 06-05-03 =====================================================
357   int nbStudyFrames = myStudy->getStudyFramesCount();
358   vtkRenderer *myRenderer = NULL;
359   if (viewId == -1) // find the first frame with VTK viewer & get renderer
360     {
361       int i=0;
362       for(i=0; i<nbStudyFrames; i++)
363         {
364           if ( myStudy->getStudyFrame(i)->getTypeView() == VIEW_VTK )
365             {
366               myRenderer = myStudy->getStudyFrame(i)->getRightFrame()->getViewFrame()->getRenderer();
367               break;
368             }
369         }
370     }
371   else     // get the VTK renderer of a given frame
372     {
373       SCRUTE(viewId);
374       if ((viewId >=0) && (viewId <nbStudyFrames))
375         myRenderer = myStudy->getStudyFrame(viewId)->getRightFrame()->getViewFrame()->getRenderer();
376     }
377   if (myRenderer == NULL) INFOS("No VTK Renderer available !");
378   return myRenderer;
379 }
380 */
381