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
29 #include "SALOMEGUI_Swig.hxx"
31 #include "QAD_Application.h"
32 #include "QAD_Desktop.h"
33 #include "QAD_Study.h"
34 #include "QAD_RightFrame.h"
35 #include "QAD_StudyFrame.h"
37 #include "SALOME_Event.hxx"
39 #include "SALOME_Selection.h"
40 #include "SALOME_InteractiveObject.hxx"
41 #include "SALOME_ListIteratorOfListIO.hxx"
43 #include "utilities.h"
47 // asv : 3.12.04 : added checking for NULL GUI objects in almost all methods.
48 // In the scope of fixing bug PAL6869.
49 // (PR : modify comments)
50 // Instance of this class is created every time "import salome" line is typed
51 // - in IAPP embedded Python interpretor (SALOME_Session_Server executable),
52 // - in inline Python nodes in Supervisor (in SALOME_Container executable),
53 // - in stand-alone Python console outside any executable.
54 // SALOME GUI(desktop and other objects) is only available in SALOME_Session_Server
57 QAD_ViewFrame* GetViewFrame( QAD_Study* theStudy ) {
59 if ( QAD_StudyFrame* aSF = theStudy->getActiveStudyFrame() )
60 if ( QAD_RightFrame* aRF = aSF->getRightFrame() )
61 return aRF->getViewFrame();
65 Handle(SALOME_InteractiveObject) FindIObject( QAD_Study* theStudy, const char *theEntry )
67 if ( QAD_ViewFrame* aVF = GetViewFrame( theStudy ) )
68 return aVF->FindIObject( theEntry );
69 return Handle(SALOME_InteractiveObject)(); // NULL Handle
77 SALOMEGUI_Swig::SALOMEGUI_Swig()
79 // MESSAGE("Constructeur");
85 SALOMEGUI_Swig::~SALOMEGUI_Swig()
87 // MESSAGE("Destructeur");
91 Check if GUI is available (if we are linked to IAPP)
93 bool SALOMEGUI_Swig::hasDesktop()
95 if ( QAD_Desktop* aDT = QAD_Application::getDesktop() )
102 Gets active study or 0 if no study opened
104 QAD_Study* SALOMEGUI_Swig::getActiveStudy()
106 if ( QAD_Desktop* aDT = QAD_Application::getDesktop() )
107 if ( QAD_Application* anApp = aDT->getActiveApp() )
108 return anApp->getActiveStudy();
113 Call when updated object browser.
115 void SALOMEGUI_Swig::updateObjBrowser( bool updateSelection )
117 if ( QAD_Study* myActiveStudy = getActiveStudy() )
118 ProcessVoidEvent( new TVoidMemFun1ArgEvent<QAD_Study,bool>
119 ( myActiveStudy, &QAD_Study::updateObjBrowser,updateSelection) );
123 Returns active Study Id.
125 int SALOMEGUI_Swig::getActiveStudyId()
127 if ( QAD_Study* myActiveStudy = getActiveStudy() )
128 return myActiveStudy->getStudyId();
133 Returns active Study Name.
135 const char *SALOMEGUI_Swig::getActiveStudyName()
137 if ( QAD_Study* myActiveStudy = getActiveStudy() )
138 return myActiveStudy->getTitle().latin1();
143 Returns the name of component.
145 const char* SALOMEGUI_Swig::getComponentName( const char* ComponentUserName )
147 if ( QAD_Desktop* aDT = QAD_Application::getDesktop() )
148 return aDT->getComponentName( ComponentUserName );
152 Returns the user name of component.
154 const char* SALOMEGUI_Swig::getComponentUserName( const char* ComponentName )
156 if ( QAD_Desktop* aDT = QAD_Application::getDesktop() )
157 return aDT->getComponentUserName( ComponentName );
162 Returns the number of selected objects.
164 int SALOMEGUI_Swig::SelectedCount()
166 if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
167 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
168 return Sel->IObjectCount();
174 Returns the selected object at index i.
176 const char* SALOMEGUI_Swig::getSelected( int i )
178 if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
179 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
180 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
182 for( ;It.More();It.Next() ) {
183 Handle(SALOME_InteractiveObject) IObject = It.Value();
185 if ( IObject->hasEntry() )
186 return IObject->getEntry();
194 Add object with Entry into selection.
196 void SALOMEGUI_Swig::AddIObject( const char *theEntry )
198 if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
199 SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
200 if ( IsInCurrentView( theEntry ) ) {
201 Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy,theEntry );
202 if ( anIO.IsNull() ) return;
203 ProcessEvent( new TMemFun2ArgEvent<SALOME_Selection,int,
204 const Handle(SALOME_InteractiveObject)&,bool,
205 Handle(SALOME_InteractiveObject)>
206 ( aSel, &SALOME_Selection::AddIObject, anIO, true ) );
213 Removes object with Entry into selection.
215 void SALOMEGUI_Swig::RemoveIObject( const char *theEntry )
217 if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
218 SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
219 if ( IsInCurrentView( theEntry ) ) {
220 Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy,theEntry );
221 if ( anIO.IsNull() ) return;
222 ProcessEvent( new TMemFun2ArgEvent<SALOME_Selection,int,
223 const Handle(SALOME_InteractiveObject)&, bool,
224 Handle(SALOME_InteractiveObject)>
225 ( aSel, &SALOME_Selection::RemoveIObject, anIO, true ) );
232 Removes all objects into selection.
234 void SALOMEGUI_Swig::ClearIObjects()
236 if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
237 SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
238 ProcessVoidEvent( new TVoidMemFunEvent<SALOME_Selection>
239 ( aSel, &SALOME_Selection::ClearIObjects ) );
246 void SALOMEGUI_Swig::Display( const char *theEntry )
248 if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
249 if ( IsInCurrentView( theEntry ) ) {
250 Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy, theEntry );
251 if ( anIO.IsNull() ) return;
252 QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
253 ProcessVoidEvent( new TVoidMemFun2ArgEvent<QAD_ViewFrame,
254 const Handle(SALOME_InteractiveObject)&, bool,
255 Handle(SALOME_InteractiveObject)>
256 ( aViewFrame, &QAD_ViewFrame::Display, anIO, true ) );
264 void SALOMEGUI_Swig::DisplayOnly( const char *theEntry )
266 if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
267 if ( IsInCurrentView( theEntry ) ) {
268 Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy, theEntry );
269 if ( anIO.IsNull() ) return;
270 QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
271 ProcessVoidEvent( new TVoidMemFun1ArgEvent<QAD_ViewFrame,
272 const Handle(SALOME_InteractiveObject)&,
273 Handle(SALOME_InteractiveObject)>
274 ( aViewFrame, &QAD_ViewFrame::DisplayOnly, anIO ) );
282 void SALOMEGUI_Swig::Erase( const char *theEntry )
284 if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
285 if ( IsInCurrentView( theEntry ) ) {
286 Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy, theEntry );
287 if ( anIO.IsNull() ) return;
288 QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
289 ProcessVoidEvent( new TVoidMemFun2ArgEvent<QAD_ViewFrame,
290 const Handle(SALOME_InteractiveObject)&, bool,
291 Handle(SALOME_InteractiveObject)>
292 ( aViewFrame, &QAD_ViewFrame::Erase, anIO, true ) );
300 void SALOMEGUI_Swig::DisplayAll()
302 if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
303 QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
304 ProcessVoidEvent( new TVoidMemFunEvent<QAD_ViewFrame>
305 ( aViewFrame, &QAD_ViewFrame::DisplayAll ) );
312 void SALOMEGUI_Swig::EraseAll()
315 if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
316 QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
317 ProcessVoidEvent ( new TVoidMemFunEvent<QAD_ViewFrame>
318 ( aViewFrame, &QAD_ViewFrame::EraseAll ) );
323 Checks if object is displayed in current viewer
325 bool SALOMEGUI_Swig::IsInCurrentView( const char *theEntry )
327 if ( QAD_Study* myActiveStudy = getActiveStudy() )
328 return myActiveStudy->isInViewer( theEntry, myActiveStudy->getActiveStudyFrame()->entry() );