Back to index

salome-gui  6.5.0
Public Member Functions
SALOMEGUI_Swig Class Reference

Python interface module for SALOME GUI. More...

#include <SALOMEGUI_Swig.hxx>

List of all members.

Public Member Functions

 SALOMEGUI_Swig ()
 Constructor.
 ~SALOMEGUI_Swig ()
 Destructor.
bool hasDesktop ()
 Check GUI availability.
void updateObjBrowser (bool)
 Update active study's Object Browser.
int getActiveStudyId ()
 Get active study identifier.
const char * getActiveStudyName ()
 Get active study name.
const char * getComponentName (const char *)
 Get name of the component by its title (user name)
const char * getComponentUserName (const char *)
 Get title (user name) of the component by its name.
int SelectedCount ()
 Get number of selected items.
const char * getSelected (int i)
 Get entry of the specified selected item.
void AddIObject (const char *)
 Add an object to the current selection.
void RemoveIObject (const char *)
 Remove the object from the selection.
void ClearIObjects ()
 Clear selection (unselect all objects).
void Display (const char *)
 Display an object in the current view window.
void DisplayOnly (const char *)
 Displays an object in the current view window and erases all other ones.
void Erase (const char *)
 Erase an object in the current view window.
void DisplayAll ()
 Display all active module's presentable child objects in the current view window.
void EraseAll ()
 Erase all objects from the current view window.
bool IsInCurrentView (const char *)
 Check it the object is displayed in the current view window.
void UpdateView ()
 Update (repaint) current view window.
void FitAll ()
 Fit current view window to display all its contents.
void ResetView ()
 Reset current view window to the default state.
void ViewTop ()
 Switch current view window to show the top view.
void ViewBottom ()
 Switch current view window to show the bottom view.
void ViewLeft ()
 Switch current view window to show the left view.
void ViewRight ()
 Switch current view window to show the right view.
void ViewFront ()
 Switch current view window to show the front view.
void ViewBack ()
 Switch current view window to show the back view.

Detailed Description

Python interface module for SALOME GUI.

This module provides an access to the SALOME GUI implementing set of functions which can be used from Python. This module is implemented using SWIG wrappings for some GUI functionality:

Instance of this class is created every time "import salome" line is typed

SALOME GUI (desktop and other objects) is only available in SALOME_Session_Server. It means that it can not be accessed from the external Python console.

The usage in Python:

  import libSALOME_Swig
  sg = libSALOME_Swig.SALOMEGUI_Swig()
  if sg.hasDesktop():
      selcount = sg.SelectedCount()
      if selcount > 0:
          sg.Erase( sg.getSelected( 0 ) )
      pass

Definition at line 30 of file SALOMEGUI_Swig.hxx.


Constructor & Destructor Documentation

Constructor.

Definition at line 128 of file SALOMEGUI_Swig.cxx.

{
}

Destructor.

Definition at line 135 of file SALOMEGUI_Swig.cxx.

{
}

Member Function Documentation

void SALOMEGUI_Swig::AddIObject ( const char *  theEntry)

Add an object to the current selection.

Parameters:
theEntryobject entry

Definition at line 330 of file SALOMEGUI_Swig.cxx.

{
  class TEvent: public SALOME_Event
  {
  public:
    QString myEntry;
    TEvent( const char* theEntry ) : myEntry( theEntry ) {}
    virtual void Execute()
    {
      if ( LightApp_Application* anApp = getApplication() ) {
        LightApp_Study*       aStudy  = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
        LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
        if ( aStudy && aSelMgr ) {
          SALOME_ListIO anIOList;
          anIOList.Append( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) );
          aSelMgr->setSelectedObjects( anIOList, true );
        }
      }
    }
  };
  ProcessVoidEvent( new TEvent( theEntry ) );
}

Here is the call graph for this function:

Clear selection (unselect all objects).

Definition at line 395 of file SALOMEGUI_Swig.cxx.

{
  class TEvent: public SALOME_Event
  {
  public:
    TEvent() {}
    virtual void Execute()
    {
      if ( LightApp_Application* anApp = getApplication() ) {
        LightApp_Study* aStudy  = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
        LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
        if ( aStudy && aSelMgr )
          aSelMgr->clearSelected();
      }
    }
  };
  ProcessVoidEvent( new TEvent() );
}

Here is the call graph for this function:

void SALOMEGUI_Swig::Display ( const char *  theEntry)

Display an object in the current view window.

The presentable object should be previously created and displayed in this viewer.

Parameters:
theEntryobject entry

Definition at line 422 of file SALOMEGUI_Swig.cxx.

{
  class TEvent: public SALOME_Event
  {
    QString myEntry;
  public:
    TEvent( const char* theEntry ) : myEntry( theEntry ) {}
    virtual void Execute() {
      LightApp_Application* anApp  = getApplication();
      LightApp_Study*       aStudy = getActiveStudy();
      if ( anApp && aStudy ) {
       QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
       LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
       if ( d ) {
         QStringList entries;
         if( aStudy->isComponent( myEntry ) )
           aStudy->children( myEntry, entries );
         else
           entries.append( myEntry );
         foreach( QString entry, entries )
           d->Display( aStudy->referencedToEntry( entry ), false, 0 );
       }
      }
    }
  };
  ProcessVoidEvent( new TEvent( theEntry ) );
}

Here is the call graph for this function:

Display all active module's presentable child objects in the current view window.

The presentable objects should be previously created and displayed in this viewer.

Definition at line 539 of file SALOMEGUI_Swig.cxx.

{
  class TEvent: public SALOME_Event
  {
  public:
    TEvent() {}
    virtual void Execute()
    {
      LightApp_Application* anApp  = getApplication();
      LightApp_Study*       aStudy = getActiveStudy();
      if ( anApp && aStudy ) {
       QStringList comps;
       aStudy->components( comps );
       foreach( QString comp, comps ) {
         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
         if ( d ) {
           QStringList entries;
           aStudy->children( aStudy->centry( comp ), entries );
           foreach( QString entry, entries )
             d->Display( aStudy->referencedToEntry( entry ), false, 0 );
         }
       }
      }
    }
  };
  ProcessVoidEvent( new TEvent() );
}

Here is the call graph for this function:

void SALOMEGUI_Swig::DisplayOnly ( const char *  theEntry)

Displays an object in the current view window and erases all other ones.

The presentable object should be previously created and displayed in this viewer.

Parameters:
theEntryobject entry

Definition at line 459 of file SALOMEGUI_Swig.cxx.

{
  class TEvent: public SALOME_Event
  {
    QString myEntry;
  public:
    TEvent( const char* theEntry ) : myEntry( theEntry ) {}
    virtual void Execute()
    {
      LightApp_Application* anApp  = getApplication();
      LightApp_Study*       aStudy = getActiveStudy();
      if ( anApp && aStudy ) {
       QStringList comps;
       aStudy->components( comps );
       foreach( QString comp, comps ) {
         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
         if ( d ) d->EraseAll( false, false, 0 );
       }

       QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
       LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
       if ( d ) {
         QStringList entries;
         if( aStudy->isComponent( myEntry ) )
           aStudy->children( myEntry, entries );
         else
           entries.append( myEntry );
         foreach( QString entry, entries )
           d->Display( aStudy->referencedToEntry( entry ), false, 0 );
       }
      }
    }
  };
  ProcessVoidEvent( new TEvent( theEntry ) );
}

Here is the call graph for this function:

void SALOMEGUI_Swig::Erase ( const char *  theEntry)

Erase an object in the current view window.

The presentable object should be previously created and displayed in this viewer.

Parameters:
theEntryobject entry

Definition at line 503 of file SALOMEGUI_Swig.cxx.

{
  class TEvent: public SALOME_Event
  {
    QString myEntry;
  public:
    TEvent( const char* theEntry ) : myEntry( theEntry ) {}
    virtual void Execute()
    {
      LightApp_Application* anApp  = getApplication();
      LightApp_Study*       aStudy = getActiveStudy();
      if ( anApp && aStudy ) {
       QString mname = anApp->moduleTitle( aStudy->componentDataType( myEntry ) );
       LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( mname, true );
       if ( d ) {
         QStringList entries;
         if( aStudy->isComponent( myEntry ) )
           aStudy->children( myEntry, entries );
         else
           entries.append( myEntry );
         foreach( QString entry, entries )
           d->Erase( aStudy->referencedToEntry( entry ), false, false, 0 );
       }
      }
    }
  };
  ProcessVoidEvent( new TEvent( theEntry ) );
}

Here is the call graph for this function:

Erase all objects from the current view window.

Definition at line 570 of file SALOMEGUI_Swig.cxx.

{
  class TEvent: public SALOME_Event
  {
  public:
    TEvent() {}
    virtual void Execute()
    {
      LightApp_Application* anApp  = getApplication();
      LightApp_Study*       aStudy = getActiveStudy();
      if ( anApp && aStudy ) {
       QStringList comps;
       aStudy->components( comps );
       foreach( QString comp, comps ) {
         LightApp_Displayer* d = LightApp_Displayer::FindDisplayer( anApp->moduleTitle( comp ), true );
         if ( d ) d->EraseAll( false, false, 0 );
       }
      }
    }
  };
  ProcessVoidEvent( new TEvent() );
}

Here is the call graph for this function:

Fit current view window to display all its contents.

Definition at line 657 of file SALOMEGUI_Swig.cxx.

{
  class TEvent: public SALOME_Event
  {
  public:
    TEvent() {}
    virtual void Execute()
    {
      if ( LightApp_Application* anApp = getApplication() ) {
        SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
        if ( window ) {
          if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
            ( dynamic_cast<SVTK_ViewWindow*>( window ) )->onFitAll();
          else if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
            ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )->onFitAll();
          else if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
            ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )->onFitAll();
        }
      }
    }
  };
  ProcessVoidEvent( new TEvent() );
}

Here is the call graph for this function:

Get active study identifier.

Returns:
active study's ID or 0 if there is no active study

Definition at line 201 of file SALOMEGUI_Swig.cxx.

{
  return ProcessEvent( new TGetActiveStudyIdEvent() );
}

Here is the call graph for this function:

Get active study name.

Returns:
active study's name or null string if there is no active study

Definition at line 225 of file SALOMEGUI_Swig.cxx.

{
  std::string result = ProcessEvent( new TGetActiveStudyNameEvent() );
  return result.empty() ? 0 : result.c_str();
}

Here is the call graph for this function:

const char * SALOMEGUI_Swig::getComponentName ( const char *  componentUserName)

Get name of the component by its title (user name)

Parameters:
componentUserNamecomponent title (user name)
Returns:
component name or null string if component title is invalid

Definition at line 261 of file SALOMEGUI_Swig.cxx.

{
  QString result = ProcessEvent( new TGetComponentNameEvent( componentUserName, false ) );
  return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
}

Here is the call graph for this function:

const char * SALOMEGUI_Swig::getComponentUserName ( const char *  componentName)

Get title (user name) of the component by its name.

Parameters:
componentNamecomponent name
Returns:
component title or null string if component name is invalid

Definition at line 266 of file SALOMEGUI_Swig.cxx.

{
  QString result = ProcessEvent( new TGetComponentNameEvent( componentName, true ) );
  return result.isEmpty() ? 0 : strdup( result.toLatin1().constData() );
}

Here is the call graph for this function:

const char * SALOMEGUI_Swig::getSelected ( int  index)

Get entry of the specified selected item.

Parameters:
indexselected object index
Returns:
selected object entry (null string if index is invalid)

Definition at line 319 of file SALOMEGUI_Swig.cxx.

{
  QStringList selected = ProcessEvent( new TGetSelectedEvent() );
  return index >= 0 && index < selected.count() ? 
    strdup( selected[ index ].toLatin1().constData() ) : 0;
}

Here is the call graph for this function:

Check GUI availability.

Returns:
true if GUI is available

Definition at line 156 of file SALOMEGUI_Swig.cxx.

{
  return ProcessEvent( new THasDesktopEvent() );
}

Here is the call graph for this function:

bool SALOMEGUI_Swig::IsInCurrentView ( const char *  theEntry)

Check it the object is displayed in the current view window.

VSR: For the current moment implemented for OCC and VTK viewers only.

Parameters:
theEntryobject entry
Returns:
true if the object with given entry is displayed in the current viewer

Definition at line 625 of file SALOMEGUI_Swig.cxx.

{
  return ProcessEvent( new TIsInViewerEvent( theEntry ) );
}

Here is the call graph for this function:

void SALOMEGUI_Swig::RemoveIObject ( const char *  theEntry)

Remove the object from the selection.

Parameters:
theEntryobject entry

Definition at line 357 of file SALOMEGUI_Swig.cxx.

{
  class TEvent: public SALOME_Event
  {
  public:
    QString myEntry;
    TEvent( const char* theEntry ) : myEntry( theEntry ) {}
    virtual void Execute()
    {
      if ( LightApp_Application* anApp = getApplication() ) {
        LightApp_Study* aStudy  = dynamic_cast<LightApp_Study*>( anApp->activeStudy() ); // for sure!
        LightApp_SelectionMgr* aSelMgr = anApp->selectionMgr(); 
        if ( aStudy && aSelMgr ) {
          SALOME_ListIO anIOList;
          // VSR: temporary solution, until LightApp_SelectionMgr::unsetSelectedObjects() method appears
          // Lately this should be replaced by the following:
          // anIOList.Append( new SALOME_InteractiveObject( myEntry, "", "" ) );
          // aSelMgr->unsetSelectedObjects( anIOList );
          aSelMgr->selectedObjects( anIOList );
          SALOME_ListIteratorOfListIO anIter( anIOList );
          for( ; anIter.More(); anIter.Next() ) {
            if ( anIter.Value()->isSame( new SALOME_InteractiveObject( myEntry.toLatin1(), "", "" ) ) ) { 
              anIOList.Remove( anIter );
              aSelMgr->setSelectedObjects( anIOList, true );
              return;
            }
          }
        }
      }
    }
  };
  ProcessVoidEvent( new TEvent( theEntry ) );
}

Here is the call graph for this function:

Reset current view window to the default state.

Definition at line 684 of file SALOMEGUI_Swig.cxx.

{
  class TEvent: public SALOME_Event
  {
  public:
    TEvent() {}
    virtual void Execute()
    {
      if ( LightApp_Application* anApp = getApplication() ) {
        SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
        if ( window ) {
          if ( dynamic_cast<SVTK_ViewWindow*>( window ) )
            (dynamic_cast<SVTK_ViewWindow*>( window ))->onResetView();
          else if ( dynamic_cast<OCCViewer_ViewWindow*>( window ) )
            (dynamic_cast<OCCViewer_ViewWindow*>( window ))->onResetView();
          else if ( dynamic_cast<SPlot2d_ViewWindow*>( window ) )
            (dynamic_cast<SPlot2d_ViewWindow*>( window ))->onFitAll();
          // VSR: there is no 'ResetView' functionality for Plot2d viewer,
          // so we use 'FitAll' instead.
        }
      }
    }
  };
  ProcessVoidEvent( new TEvent() );
}

Here is the call graph for this function:

Get number of selected items.

Returns:
number of selected items in the active study

Definition at line 314 of file SALOMEGUI_Swig.cxx.

{
  QStringList selected = ProcessEvent( new TGetSelectedEvent() );
  return selected.count();
}

Here is the call graph for this function:

Update active study's Object Browser.

Parameters:
updateSelectionthis parameter is obsolete

Definition at line 165 of file SALOMEGUI_Swig.cxx.

{
  class TEvent: public SALOME_Event
  {
  public:
    TEvent() {}
    virtual void Execute()
    {
      if ( LightApp_Application* anApp = getApplication() ) {
        anApp->updateObjectBrowser();
        anApp->updateActions(); //SRN: added in order to update the toolbar
      }
    }
  };
  ProcessVoidEvent( new TEvent() );
}

Here is the call graph for this function:

Update (repaint) current view window.

Definition at line 633 of file SALOMEGUI_Swig.cxx.

{
  class TEvent: public SALOME_Event
  {
  public:
    TEvent() {}
    virtual void Execute()
    {
      if ( LightApp_Application* anApp = getApplication() ) {
        SUIT_ViewWindow* window = anApp->desktop()->activeWindow();
        if ( window ) {
          SALOME_View* view = dynamic_cast<SALOME_View*>( window->getViewManager()->getViewModel() );
          if ( view )
            view->Repaint();
        }
      }
    }
  };
  ProcessVoidEvent( new TEvent() );
}

Here is the call graph for this function:

Switch current view window to show the back view.

Definition at line 827 of file SALOMEGUI_Swig.cxx.

Here is the call graph for this function:

Switch current view window to show the bottom view.

Definition at line 795 of file SALOMEGUI_Swig.cxx.

Here is the call graph for this function:

Switch current view window to show the front view.

Definition at line 819 of file SALOMEGUI_Swig.cxx.

Here is the call graph for this function:

Switch current view window to show the left view.

Definition at line 803 of file SALOMEGUI_Swig.cxx.

Here is the call graph for this function:

Switch current view window to show the right view.

Definition at line 811 of file SALOMEGUI_Swig.cxx.

Here is the call graph for this function:

Switch current view window to show the top view.

Definition at line 787 of file SALOMEGUI_Swig.cxx.

Here is the call graph for this function:


The documentation for this class was generated from the following files: