1 // SALOME SALOMEGUI : implementation of desktop and GUI kernel
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SALOMEGUI_Swig.cxx
25 // Author : Nicolas REJNERI
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"
38 #include "SALOME_Selection.h"
39 #include "SALOME_InteractiveObject.hxx"
40 #include "SALOME_ListIteratorOfListIO.hxx"
46 SALOMEGUI_Swig::SALOMEGUI_Swig()
47 // VSR 06-05-03 : _studyId(0)
49 // MESSAGE("Constructeur");
55 SALOMEGUI_Swig::~SALOMEGUI_Swig()
57 // MESSAGE("Destructeur");
61 Gets active study or 0 if no study opened
63 QAD_Study* SALOMEGUI_Swig::getActiveStudy()
65 QAD_Application* app = QAD_Application::getDesktop()->getActiveApp();
66 if ( app ) return app->getActiveStudy();
71 Call when updated object browser.
73 void SALOMEGUI_Swig::updateObjBrowser( bool updateSelection )
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 );
84 Returns active Study Id.
86 int SALOMEGUI_Swig::getActiveStudyId()
91 // QAD_Study* myStudy = QAD_Application::getDesktop()->getActiveStudy();
92 // _name = myStudy->getTitle();
94 // VSR 06-05-03 ============================================================
95 // _studyId = QAD_Application::getDesktop()->getActiveStudy()->getStudyId();
97 QAD_Study* myActiveStudy = getActiveStudy();
98 if ( myActiveStudy) _studyId = myActiveStudy->getStudyId();
100 // end of VSR 06-05-03 =====================================================
106 Returns active Study Name.
108 const char *SALOMEGUI_Swig::getActiveStudyName()
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 =====================================================
120 // getActiveStudyId();
121 return _name.latin1();
125 Returns the name of component.
127 const char* SALOMEGUI_Swig::getComponentName( const char* ComponentUserName )
129 return QAD_Application::getDesktop()->getComponentName( ComponentUserName );
132 Returns the user name of component.
134 const char* SALOMEGUI_Swig::getComponentUserName( const char* ComponentName )
136 return QAD_Application::getDesktop()->getComponentUserName( ComponentName );
140 Returns the number of selected objects.
142 int SALOMEGUI_Swig::SelectedCount()
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();
155 Returns the selected object at index i.
157 const char* SALOMEGUI_Swig::getSelected(int i)
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() );
168 for(;It.More();It.Next())
170 Handle(SALOME_InteractiveObject) IObject = It.Value();
173 if ( IObject->hasEntry() )
174 return IObject->getEntry();
181 Add object with Entry into selection.
183 void SALOMEGUI_Swig::AddIObject(const char *Entry)
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() );
193 if ( !IsInCurrentView( Entry ) )
196 Handle(SALOME_InteractiveObject) IO =
197 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
198 Sel->AddIObject( IO );
203 Removes object with Entry into selection.
205 void SALOMEGUI_Swig::RemoveIObject(const char *Entry)
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() );
215 if ( !IsInCurrentView( Entry ) )
218 Handle(SALOME_InteractiveObject) IO =
219 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
220 Sel->RemoveIObject( IO );
225 Removes all objects into selection.
227 void SALOMEGUI_Swig::ClearIObjects()
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();
242 void SALOMEGUI_Swig::Display(const char *Entry)
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 =====================================================
250 if ( !IsInCurrentView( Entry ) )
253 Handle(SALOME_InteractiveObject) IO =
254 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
256 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Display(IO);
262 void SALOMEGUI_Swig::DisplayOnly(const char *Entry)
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 =====================================================
270 if ( !IsInCurrentView( Entry ) )
273 Handle(SALOME_InteractiveObject) IO =
274 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
276 if ( !IO.IsNull() ) {
277 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->DisplayOnly(IO);
284 void SALOMEGUI_Swig::Erase(const char *Entry)
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 =====================================================
292 if ( !IsInCurrentView( Entry ) )
295 Handle(SALOME_InteractiveObject) IO =
296 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
298 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Erase(IO);
304 void SALOMEGUI_Swig::DisplayAll()
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();
317 void SALOMEGUI_Swig::EraseAll()
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() );
327 Sel->ClearIObjects();
328 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->EraseAll();
332 Checks if object is displayed in current viewer
334 bool SALOMEGUI_Swig::IsInCurrentView(const char *Entry)
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() );
345 Gets VTK renderer if available
347 //san:T3.13 - move getRenderer() implementation from here to SalomePy.cxx
348 /*vtkRenderer *SALOMEGUI_Swig::getRenderer(int viewId)
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
362 for(i=0; i<nbStudyFrames; i++)
364 if ( myStudy->getStudyFrame(i)->getTypeView() == VIEW_VTK )
366 myRenderer = myStudy->getStudyFrame(i)->getRightFrame()->getViewFrame()->getRenderer();
371 else // get the VTK renderer of a given frame
374 if ((viewId >=0) && (viewId <nbStudyFrames))
375 myRenderer = myStudy->getStudyFrame(viewId)->getRightFrame()->getViewFrame()->getRenderer();
377 if (myRenderer == NULL) INFOS("No VTK Renderer available !");