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 number of selected objects.
127 int SALOMEGUI_Swig::SelectedCount()
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();
140 Returns the selected object at index i.
142 const char* SALOMEGUI_Swig::getSelected(int i)
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() );
153 for(;It.More();It.Next())
155 Handle(SALOME_InteractiveObject) IObject = It.Value();
158 if ( IObject->hasEntry() )
159 return IObject->getEntry();
166 Add object with Entry into selection.
168 void SALOMEGUI_Swig::AddIObject(const char *Entry)
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() );
178 if ( !IsInCurrentView( Entry ) )
181 Handle(SALOME_InteractiveObject) IO =
182 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
183 Sel->AddIObject( IO );
188 Removes object with Entry into selection.
190 void SALOMEGUI_Swig::RemoveIObject(const char *Entry)
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() );
200 if ( !IsInCurrentView( Entry ) )
203 Handle(SALOME_InteractiveObject) IO =
204 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
205 Sel->RemoveIObject( IO );
210 Removes all objects into selection.
212 void SALOMEGUI_Swig::ClearIObjects()
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();
227 void SALOMEGUI_Swig::Display(const char *Entry)
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 =====================================================
235 if ( !IsInCurrentView( Entry ) )
238 Handle(SALOME_InteractiveObject) IO =
239 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
241 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Display(IO);
247 void SALOMEGUI_Swig::DisplayOnly(const char *Entry)
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 =====================================================
255 if ( !IsInCurrentView( Entry ) )
258 Handle(SALOME_InteractiveObject) IO =
259 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
261 if ( !IO.IsNull() ) {
262 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->DisplayOnly(IO);
269 void SALOMEGUI_Swig::Erase(const char *Entry)
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 =====================================================
277 if ( !IsInCurrentView( Entry ) )
280 Handle(SALOME_InteractiveObject) IO =
281 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->FindIObject( Entry );
283 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Erase(IO);
289 void SALOMEGUI_Swig::DisplayAll()
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();
302 void SALOMEGUI_Swig::EraseAll()
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() );
312 Sel->ClearIObjects();
313 myStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->EraseAll();
317 Checks if object is displayed in current viewer
319 bool SALOMEGUI_Swig::IsInCurrentView(const char *Entry)
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() );
330 Gets VTK renderer if available
332 //san:T3.13 - move getRenderer() implementation from here to SalomePy.cxx
333 /*vtkRenderer *SALOMEGUI_Swig::getRenderer(int viewId)
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
347 for(i=0; i<nbStudyFrames; i++)
349 if ( myStudy->getStudyFrame(i)->getTypeView() == VIEW_VTK )
351 myRenderer = myStudy->getStudyFrame(i)->getRightFrame()->getViewFrame()->getRenderer();
356 else // get the VTK renderer of a given frame
359 if ((viewId >=0) && (viewId <nbStudyFrames))
360 myRenderer = myStudy->getStudyFrame(viewId)->getRightFrame()->getViewFrame()->getRenderer();
362 if (myRenderer == NULL) INFOS("No VTK Renderer available !");