for aKey in ("containers","embedded","key","modules","standalone"):
if not args.has_key(aKey):
args[aKey]=[]
-for aKey in ("gui","logger","file","xterm","portkill","killall"):
+for aKey in ("gui","logger","file","xterm","portkill","killall","interp"):
if not args.has_key(aKey):
args[aKey]=0
if args["file"]:
opterror=0
for opt in opts:
- if not opt in ("h","g","l","f","x","m","e","s","c","p","k","t"):
+ if not opt in ("h","g","l","f","x","m","e","s","c","p","k","t","i"):
print "command line error: -", opt
opterror=1
print """USAGE: runSalome.py [options]
[command line options] :
--help or -h : print this help
- --gui or -g : lancement du GUI
+ --gui or -g : GUI launch
--terminal -t : launching without gui (to deny --gui)
- --logger or -l : redirection des messages via CORBA
- --file=filename or -l=filename: redirection des messages dans un fichier
- --xterm or -x : les serveurs ouvrent une fenêtre xterm et les messages sont affichés dans cette fenêtre
- --modules=module1,module2,... : où modulen est le nom d'un module Salome à charger dans le catalogue
+ --logger or -l : trace collection via CORBA
+ --file=filename or -f=filename: trace collection in a file
+ --xterm or -x : each program in a separate xterm
+ --modules=module1,module2,... : list of salome modules to put into the module catalog
or -m=module1,module2,...
--embedded=registry,study,moduleCatalog,cppContainer
or -e=registry,study,moduleCatalog,cppContainer
- : serveurs CORBA embarqués (par defaut: registry,study,moduleCatalog,cppContainer)
- : (logger,pyContainer,supervContainer ne peuvent pas être embarqués
+ : servers embedded in session server (default: registry,study,moduleCatalog,cppContainer)
+ : (logger,pyContainer,supervContainer can't be embedded)
--standalone=registry,study,moduleCatalog,cppContainer,pyContainer,supervContainer
or -s=registry,study,moduleCatalog,cppContainer,pyContainer,supervContainer
- : executables serveurs CORBA indépendants (par défaut: pyContainer,supervContainer)
- --containers=cpp,python,superv: (obsolete) lancement des containers cpp, python et de supervision
- or -c=cpp,python,superv : = on prend les defauts de -e et -s
+ : standalone CORBA servers (default: pyContainer,supervContainer)
+ --containers=cpp,python,superv: obsolete ( cpp, python and supervision container launch)
+ or -c=cpp,python,superv : see --embedded, --standalone
--portkill or -p : kill the salome with current port
- --killall or -k : kill salome
+ --killall or -k : kill all salome sessions
+ --interp=n or -i=n : number of additional xterm to open, with session environment
La variable d'environnement <modulen>_ROOT_DIR doit etre préalablement
positionnée (modulen doit etre en majuscule).
args['file'] = opts['f']
elif opt == 'x':
args['xterm'] = 1
+ elif opt == 'i':
+ args['interp'] = opts['i']
elif opt == 'm':
args['modules'] = opts['m']
elif opt == 'e':
# ---
+class InterpServer(Server):
+ def __init__(self,args):
+ self.args=args
+ env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")]
+ #self.CMD=['xterm', '-iconic', '-sb', '-sl', '500', '-hold','-e']+ env_ld_library_path + ['python']
+ self.CMD=['xterm', '-e', 'python']
+
+ def run(self):
+ global process_id
+ command = self.CMD
+ print "command = ", command
+ pid = os.spawnvp(os.P_NOWAIT, command[0], command)
+ process_id[pid]=self.CMD
+
+# ---
+
class CatalogServer(Server):
def __init__(self,args):
self.args=args
print "Start SALOME, elapsed time : %5.1f seconds"% (end_time[4]
- init_time[4])
+ #
+ # additionnal external python interpreters
+ #
+
+ nbaddi = int(args['interp'][0])
+ print "additional external python interpreters: ", nbaddi
+ if nbaddi:
+ for i in range(nbaddi):
+ print "i=",i
+ anInterp=InterpServer(args)
+ anInterp.run()
+
return clt
# -----------------------------------------------------------------------------
using namespace std;
+// asv : 3.12.04 : added checking for NULL GUI objects in almost all methods.
+// In the scope of fixing bug PAL6869.
+// (PR : modify comments)
+// Instance of this class is created every time "import salome" line is typed
+// - in IAPP embedded Python interpretor (SALOME_Session_Server executable),
+// - in inline Python nodes in Supervisor (in SALOME_Container executable),
+// - in stand-alone Python console outside any executable.
+// SALOME GUI(desktop and other objects) is only available in SALOME_Session_Server
+
namespace SALOME{
- QAD_ViewFrame* GetViewFrame(QAD_Study* theStudy){
- return theStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame();
+ QAD_ViewFrame* GetViewFrame( QAD_Study* theStudy ) {
+ if ( theStudy )
+ if ( QAD_StudyFrame* aSF = theStudy->getActiveStudyFrame() )
+ if ( QAD_RightFrame* aRF = aSF->getRightFrame() )
+ return aRF->getViewFrame();
+ return 0;
}
- Handle(SALOME_InteractiveObject) FindIObject(QAD_Study* theStudy, const char *theEntry)
+ Handle(SALOME_InteractiveObject) FindIObject( QAD_Study* theStudy, const char *theEntry )
{
- return GetViewFrame(theStudy)->FindIObject(theEntry);
+ if ( QAD_ViewFrame* aVF = GetViewFrame( theStudy ) )
+ return aVF->FindIObject( theEntry );
+ return Handle(SALOME_InteractiveObject)(); // NULL Handle
}
}
// MESSAGE("Destructeur");
}
+/*!
+ Check if GUI is available (if we are linked to IAPP)
+*/
+bool SALOMEGUI_Swig::hasDesktop()
+{
+ if ( QAD_Desktop* aDT = QAD_Application::getDesktop() )
+ return true;
+ else
+ return false;
+}
+
/*!
Gets active study or 0 if no study opened
*/
QAD_Study* SALOMEGUI_Swig::getActiveStudy()
{
- if(QAD_Application* app = QAD_Application::getDesktop()->getActiveApp())
- return app->getActiveStudy();
+ if ( QAD_Desktop* aDT = QAD_Application::getDesktop() )
+ if ( QAD_Application* anApp = aDT->getActiveApp() )
+ return anApp->getActiveStudy();
return 0;
}
*/
void SALOMEGUI_Swig::updateObjBrowser( bool updateSelection )
{
- if(QAD_Study* myActiveStudy = getActiveStudy())
- ProcessVoidEvent(new TVoidMemFun1ArgEvent<QAD_Study,bool>
- (myActiveStudy,&QAD_Study::updateObjBrowser,updateSelection));
+ if ( QAD_Study* myActiveStudy = getActiveStudy() )
+ ProcessVoidEvent( new TVoidMemFun1ArgEvent<QAD_Study,bool>
+ ( myActiveStudy, &QAD_Study::updateObjBrowser,updateSelection) );
}
/*!
*/
int SALOMEGUI_Swig::getActiveStudyId()
{
- if(QAD_Study* myActiveStudy = getActiveStudy())
+ if ( QAD_Study* myActiveStudy = getActiveStudy() )
return myActiveStudy->getStudyId();
return 0;
}
*/
const char *SALOMEGUI_Swig::getActiveStudyName()
{
- if(QAD_Study* myActiveStudy = getActiveStudy())
+ if ( QAD_Study* myActiveStudy = getActiveStudy() )
return myActiveStudy->getTitle().latin1();
- return QString::null;
+ return NULL;
}
/*!
*/
const char* SALOMEGUI_Swig::getComponentName( const char* ComponentUserName )
{
- return QAD_Application::getDesktop()->getComponentName( ComponentUserName );
+ if ( QAD_Desktop* aDT = QAD_Application::getDesktop() )
+ return aDT->getComponentName( ComponentUserName );
+ return NULL;
}
/*!
Returns the user name of component.
*/
const char* SALOMEGUI_Swig::getComponentUserName( const char* ComponentName )
{
- return QAD_Application::getDesktop()->getComponentUserName( ComponentName );
+ if ( QAD_Desktop* aDT = QAD_Application::getDesktop() )
+ return aDT->getComponentUserName( ComponentName );
+ return NULL;
}
/*!
*/
int SALOMEGUI_Swig::SelectedCount()
{
- if(QAD_Study* myStudy = getActiveStudy()){
- SALOME_Selection* Sel = SALOME_Selection::Selection(myStudy->getSelection());
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
return Sel->IObjectCount();
}
return 0;
/*!
Returns the selected object at index i.
*/
-const char* SALOMEGUI_Swig::getSelected(int i)
+const char* SALOMEGUI_Swig::getSelected( int i )
{
- if(QAD_Study* myStudy = getActiveStudy()){
- SALOME_Selection* Sel = SALOME_Selection::Selection( myStudy->getSelection() );
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
int index = 0;
- for(;It.More();It.Next()){
+ for( ;It.More();It.Next() ) {
Handle(SALOME_InteractiveObject) IObject = It.Value();
if( i == index++ ){
if ( IObject->hasEntry() )
/*!
Add object with Entry into selection.
*/
-void SALOMEGUI_Swig::AddIObject(const char *theEntry)
+void SALOMEGUI_Swig::AddIObject( const char *theEntry )
{
- if(QAD_Study* myStudy = getActiveStudy()){
- SALOME_Selection* aSel = SALOME_Selection::Selection( myStudy->getSelection() );
- if(IsInCurrentView(theEntry)){
- Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(myStudy,theEntry);
- if(anIO.IsNull()) return;
- ProcessEvent(new TMemFun2ArgEvent<SALOME_Selection,int,
- const Handle(SALOME_InteractiveObject)&,bool,
- Handle(SALOME_InteractiveObject)>
- (aSel,&SALOME_Selection::AddIObject,anIO,true));
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
+ if ( IsInCurrentView( theEntry ) ) {
+ Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy,theEntry );
+ if ( anIO.IsNull() ) return;
+ ProcessEvent( new TMemFun2ArgEvent<SALOME_Selection,int,
+ const Handle(SALOME_InteractiveObject)&,bool,
+ Handle(SALOME_InteractiveObject)>
+ ( aSel, &SALOME_Selection::AddIObject, anIO, true ) );
}
}
}
/*!
Removes object with Entry into selection.
*/
-void SALOMEGUI_Swig::RemoveIObject(const char *theEntry)
+void SALOMEGUI_Swig::RemoveIObject( const char *theEntry )
{
- if(QAD_Study* myStudy = getActiveStudy()){
- SALOME_Selection* aSel = SALOME_Selection::Selection( myStudy->getSelection() );
- if(IsInCurrentView(theEntry)){
- Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(myStudy,theEntry);
- if(anIO.IsNull()) return;
- ProcessEvent(new TMemFun2ArgEvent<SALOME_Selection,int,
- const Handle(SALOME_InteractiveObject)&,bool,
- Handle(SALOME_InteractiveObject)>
- (aSel,&SALOME_Selection::RemoveIObject,anIO,true));
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
+ if ( IsInCurrentView( theEntry ) ) {
+ Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy,theEntry );
+ if ( anIO.IsNull() ) return;
+ ProcessEvent( new TMemFun2ArgEvent<SALOME_Selection,int,
+ const Handle(SALOME_InteractiveObject)&, bool,
+ Handle(SALOME_InteractiveObject)>
+ ( aSel, &SALOME_Selection::RemoveIObject, anIO, true ) );
}
}
}
*/
void SALOMEGUI_Swig::ClearIObjects()
{
- if(QAD_Study* myStudy = getActiveStudy()){
- SALOME_Selection* aSel = SALOME_Selection::Selection( myStudy->getSelection() );
- ProcessVoidEvent(new TVoidMemFunEvent<SALOME_Selection>
- (aSel,&SALOME_Selection::ClearIObjects));
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
+ ProcessVoidEvent( new TVoidMemFunEvent<SALOME_Selection>
+ ( aSel, &SALOME_Selection::ClearIObjects ) );
}
}
/*!
Display
*/
-void SALOMEGUI_Swig::Display(const char *theEntry)
+void SALOMEGUI_Swig::Display( const char *theEntry )
{
- if(QAD_Study* myStudy = getActiveStudy()){
- if(IsInCurrentView(theEntry)){
- Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(myStudy,theEntry);
- if(anIO.IsNull()) return;
- QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame(myStudy);
- ProcessVoidEvent(new TVoidMemFun2ArgEvent<QAD_ViewFrame,
- const Handle(SALOME_InteractiveObject)&,bool,
- Handle(SALOME_InteractiveObject)>
- (aViewFrame,&QAD_ViewFrame::Display,anIO,true));
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ if ( IsInCurrentView( theEntry ) ) {
+ Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy, theEntry );
+ if ( anIO.IsNull() ) return;
+ QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
+ ProcessVoidEvent( new TVoidMemFun2ArgEvent<QAD_ViewFrame,
+ const Handle(SALOME_InteractiveObject)&, bool,
+ Handle(SALOME_InteractiveObject)>
+ ( aViewFrame, &QAD_ViewFrame::Display, anIO, true ) );
}
}
}
/*!
Display only
*/
-void SALOMEGUI_Swig::DisplayOnly(const char *theEntry)
+void SALOMEGUI_Swig::DisplayOnly( const char *theEntry )
{
- if(QAD_Study* myStudy = getActiveStudy()){
- if(IsInCurrentView(theEntry)){
- Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(myStudy,theEntry);
- if(anIO.IsNull()) return;
- QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame(myStudy);
- ProcessVoidEvent(new TVoidMemFun1ArgEvent<QAD_ViewFrame,
- const Handle(SALOME_InteractiveObject)&,
- Handle(SALOME_InteractiveObject)>
- (aViewFrame,&QAD_ViewFrame::DisplayOnly,anIO));
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ if ( IsInCurrentView( theEntry ) ) {
+ Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy, theEntry );
+ if ( anIO.IsNull() ) return;
+ QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
+ ProcessVoidEvent( new TVoidMemFun1ArgEvent<QAD_ViewFrame,
+ const Handle(SALOME_InteractiveObject)&,
+ Handle(SALOME_InteractiveObject)>
+ ( aViewFrame, &QAD_ViewFrame::DisplayOnly, anIO ) );
}
}
}
/*!
Erase
*/
-void SALOMEGUI_Swig::Erase(const char *theEntry)
+void SALOMEGUI_Swig::Erase( const char *theEntry )
{
- if(QAD_Study* myStudy = getActiveStudy()){
- if(IsInCurrentView(theEntry)){
- Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject(myStudy,theEntry);
- if(anIO.IsNull()) return;
- QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame(myStudy);
- ProcessVoidEvent(new TVoidMemFun2ArgEvent<QAD_ViewFrame,
- const Handle(SALOME_InteractiveObject)&,bool,
- Handle(SALOME_InteractiveObject)>
- (aViewFrame,&QAD_ViewFrame::Erase,anIO,true));
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ if ( IsInCurrentView( theEntry ) ) {
+ Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy, theEntry );
+ if ( anIO.IsNull() ) return;
+ QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
+ ProcessVoidEvent( new TVoidMemFun2ArgEvent<QAD_ViewFrame,
+ const Handle(SALOME_InteractiveObject)&, bool,
+ Handle(SALOME_InteractiveObject)>
+ ( aViewFrame, &QAD_ViewFrame::Erase, anIO, true ) );
}
}
}
*/
void SALOMEGUI_Swig::DisplayAll()
{
- if(QAD_Study* myStudy = getActiveStudy()){
- QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame(myStudy);
- ProcessVoidEvent(new TVoidMemFunEvent<QAD_ViewFrame>
- (aViewFrame,&QAD_ViewFrame::DisplayAll));
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
+ ProcessVoidEvent( new TVoidMemFunEvent<QAD_ViewFrame>
+ ( aViewFrame, &QAD_ViewFrame::DisplayAll ) );
}
}
void SALOMEGUI_Swig::EraseAll()
{
ClearIObjects();
- if(QAD_Study* myStudy = getActiveStudy()){
- QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame(myStudy);
- ProcessVoidEvent(new TVoidMemFunEvent<QAD_ViewFrame>
- (aViewFrame,&QAD_ViewFrame::EraseAll));
+ if ( QAD_Study* myActiveStudy = getActiveStudy() ) {
+ QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy );
+ ProcessVoidEvent ( new TVoidMemFunEvent<QAD_ViewFrame>
+ ( aViewFrame, &QAD_ViewFrame::EraseAll ) );
}
}
/*!
Checks if object is displayed in current viewer
*/
-bool SALOMEGUI_Swig::IsInCurrentView(const char *theEntry)
+bool SALOMEGUI_Swig::IsInCurrentView( const char *theEntry )
{
- if(QAD_Study* myStudy = getActiveStudy())
- return myStudy->isInViewer( theEntry, myStudy->getActiveStudyFrame()->entry() );
+ if ( QAD_Study* myActiveStudy = getActiveStudy() )
+ return myActiveStudy->isInViewer( theEntry, myActiveStudy->getActiveStudyFrame()->entry() );
return false;
}
SALOMEGUI_Swig();
~SALOMEGUI_Swig();
+ bool hasDesktop();
+
void updateObjBrowser( bool updateSelection );
QAD_Study* getActiveStudy();
int getActiveStudyId();
SALOMEGUI_Swig();
~SALOMEGUI_Swig();
+ bool hasDesktop();
+
void updateObjBrowser(bool);
int getActiveStudyId();
const char *getActiveStudyName();
LIB_SRC =
#SWIG_DEF = libSALOME_Swig.i
-EXPORT_PYSCRIPTS = Help.py PyInterp.py salome.py examplevtk1.py supervisionexample.py supervisiongeomexample.py salome_shared_modules.py batchmode_salome.py test_table.py test_big_table.py test_many_objects.py import_hook.py salome_test.py
+EXPORT_PYSCRIPTS = Help.py PyInterp.py salome.py examplevtk1.py supervisionexample.py supervisiongeomexample.py salome_shared_modules.py batchmode_salome.py test_table.py test_big_table.py test_many_objects.py import_hook.py salome_test.py salome_kernel.py salome_study.py salome_iapp.py
EXPORT_SHAREDPYSCRIPTS=kernel_shared_modules.py
# Module : SALOME
# $Header$
-from omniORB import CORBA
-from LifeCycleCORBA import *
-from libSALOME_Swig import *
-import SALOMEDS
-from SALOME_NamingServicePy import *
+from salome_kernel import *
+from salome_study import *
+from salome_iapp import *
-from SALOME_utilities import *
+IN_SALOME_GUI=sg.hasDesktop()
-#--------------------------------------------------------------------------
-
-def DumpComponent(Study, SO, offset):
- it = Study.NewChildIterator(SO)
- Builder = Study.NewBuilder()
- while it.More():
- CSO = it.Value()
- it.Next()
- anAttr = Builder.FindOrCreateAttribute(CSO, "AttributeName")
- AtName = anAttr._narrow(SALOMEDS.AttributeName)
- t_name = AtName.Value()
- if t_name[0] == 1:
- ofs = 1
- a = ""
- while ofs <= offset:
- a = a + "--"
- ofs = ofs +1
- MESSAGE( a + ">" + str(CSO.GetID()) + " " + str(t_name[1]) )
- t_RefSO = CSO.ReferencedObject()
- if t_RefSO[0] == 1:
- RefSO = t_RefSO[1]
- ofs = 1
- a = ""
- while ofs <= offset:
- a = a + " "
- ofs = ofs +1
- MESSAGE( a + ">" + str(RefSO.GetID()) )
- DumpComponent(Study, CSO, offset+2)
-
- #--------------------------------------------------------------------------
-
-def DumpStudy(Study):
- itcomp = Study.NewComponentIterator()
- while itcomp.More():
- SC = itcomp.Value()
- itcomp.Next()
- name = SC.ComponentDataType()
- MESSAGE( "-> ComponentDataType is " + name )
- DumpComponent(Study, SC, 1)
-
-
- #--------------------------------------------------------------------------
-
-def ImportComponentGUI(ComponentName):
- libName = "lib" + ComponentName + "_Swig"
- command = "from " + libName + " import *"
- exec ( command )
- constructor = ComponentName + "_Swig()"
- command = "gui = " + constructor
- exec ( command )
- return gui
-
- #--------------------------------------------------------------------------
-
-def SalomeGUIgetAllSelected(self):
- selNumber = self.SelectedCount()
- listSelected = []
- for i in range(selNumber):
- listSelected.append(self.getSelected(i))
- return listSelected
-
-class SalomeGUI(SALOMEGUI_Swig):
- getAllSelected = SalomeGUIgetAllSelected
-
- #--------------------------------------------------------------------------
-
-def IDToObject(id):
- myObj = None
- mySO = myStudy.FindObjectID(id);
- if mySO is not None:
- ok, anAttr = mySO.FindAttribute("AttributeIOR")
- if ok:
- AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
- if AtIOR.Value() != "":
- myObj = orb.string_to_object(AtIOR.Value())
- return myObj
-
-def ObjectToSObject(obj):
- mySO = None
- if obj is not None:
- ior = orb.object_to_string(obj)
- if ior != "":
- mySO = myStudy.FindObjectIOR(ior)
- return mySO
-
-def ObjectToID(obj):
- mySO = ObjectToSObject(obj)
- if mySO:
- return mySO.GetID()
- return ""
-
-def IDToSObject(id):
- mySO = myStudy.FindObjectID(id);
- return mySO
-
- #--------------------------------------------------------------------------
-
-# initialise the ORB
-orb = CORBA.ORB_init([''], CORBA.ORB_ID)
-
-# create an LifeCycleCORBA instance
-lcc = LifeCycleCORBA(orb)
-
-# create an SALOMEGUI_Swig instance
-sg = SalomeGUI()
-
-#create an naming service instance
-naming_service = SALOME_NamingServicePy_i(orb)
-
-# get active study name and id
-myStudyName = sg.getActiveStudyName()
-MESSAGE( myStudyName )
-
-myStudyId = sg.getActiveStudyId()
-MESSAGE( str(myStudyId) )
-
-# get Study Manager reference
-obj = naming_service.Resolve('myStudyManager')
-myStudyManager = obj._narrow(SALOMEDS.StudyManager)
-
-# get active study
-myStudy = myStudyManager.GetStudyByName(myStudyName)
--- /dev/null
+# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+#
+#
+#
+# File : salome_iapp.py
+# Author : Paul RASCLE, EDF
+# Module : SALOME
+# $Header$
+
+from libSALOME_Swig import *
+
+ #--------------------------------------------------------------------------
+
+def ImportComponentGUI(ComponentName):
+ libName = "lib" + ComponentName + "_Swig"
+ command = "from " + libName + " import *"
+ exec ( command )
+ constructor = ComponentName + "_Swig()"
+ command = "gui = " + constructor
+ exec ( command )
+ return gui
+
+ #--------------------------------------------------------------------------
+
+def SalomeGUIgetAllSelected(self):
+ selNumber = self.SelectedCount()
+ listSelected = []
+ for i in range(selNumber):
+ listSelected.append(self.getSelected(i))
+ return listSelected
+
+class SalomeGUI(SALOMEGUI_Swig):
+ getAllSelected = SalomeGUIgetAllSelected
+
+ #--------------------------------------------------------------------------
+
+# create an SALOMEGUI_Swig instance
+sg = SalomeGUI()
+
--- /dev/null
+# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+#
+#
+#
+# File : salome_kernel.py
+# Author : Paul RASCLE, EDF
+# Module : SALOME
+# $Header$
+
+from omniORB import CORBA
+from LifeCycleCORBA import *
+from SALOME_NamingServicePy import *
+from SALOME_utilities import *
+
+# initialise the ORB
+orb = CORBA.ORB_init([''], CORBA.ORB_ID)
+
+# create an LifeCycleCORBA instance
+lcc = LifeCycleCORBA(orb)
+
+#create an naming service instance
+naming_service = SALOME_NamingServicePy_i(orb)
--- /dev/null
+# Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+#
+#
+#
+# File : salome_study.py
+# Author : Paul RASCLE, EDF
+# Module : SALOME
+# $Header$
+
+from salome_iapp import sg
+from salome_kernel import *
+import SALOMEDS
+
+#--------------------------------------------------------------------------
+
+def DumpComponent(Study, SO, offset):
+ it = Study.NewChildIterator(SO)
+ Builder = Study.NewBuilder()
+ while it.More():
+ CSO = it.Value()
+ it.Next()
+ anAttr = Builder.FindOrCreateAttribute(CSO, "AttributeName")
+ AtName = anAttr._narrow(SALOMEDS.AttributeName)
+ t_name = AtName.Value()
+ if t_name[0] == 1:
+ ofs = 1
+ a = ""
+ while ofs <= offset:
+ a = a + "--"
+ ofs = ofs +1
+ MESSAGE( a + ">" + str(CSO.GetID()) + " " + str(t_name[1]) )
+ t_RefSO = CSO.ReferencedObject()
+ if t_RefSO[0] == 1:
+ RefSO = t_RefSO[1]
+ ofs = 1
+ a = ""
+ while ofs <= offset:
+ a = a + " "
+ ofs = ofs +1
+ MESSAGE( a + ">" + str(RefSO.GetID()) )
+ DumpComponent(Study, CSO, offset+2)
+
+ #--------------------------------------------------------------------------
+
+def DumpStudy(Study):
+ itcomp = Study.NewComponentIterator()
+ while itcomp.More():
+ SC = itcomp.Value()
+ itcomp.Next()
+ name = SC.ComponentDataType()
+ MESSAGE( "-> ComponentDataType is " + name )
+ DumpComponent(Study, SC, 1)
+
+
+ #--------------------------------------------------------------------------
+
+def IDToObject(id):
+ myObj = None
+ mySO = myStudy.FindObjectID(id);
+ if mySO is not None:
+ ok, anAttr = mySO.FindAttribute("AttributeIOR")
+ if ok:
+ AtIOR = anAttr._narrow(SALOMEDS.AttributeIOR)
+ if AtIOR.Value() != "":
+ myObj = orb.string_to_object(AtIOR.Value())
+ return myObj
+
+def ObjectToSObject(obj):
+ mySO = None
+ if obj is not None:
+ ior = orb.object_to_string(obj)
+ if ior != "":
+ mySO = myStudy.FindObjectIOR(ior)
+ return mySO
+
+def ObjectToID(obj):
+ mySO = ObjectToSObject(obj)
+ if mySO:
+ return mySO.GetID()
+ return ""
+
+def IDToSObject(id):
+ mySO = myStudy.FindObjectID(id);
+ return mySO
+
+ #--------------------------------------------------------------------------
+
+salome_study_ID = -1
+
+def getActiveStudy():
+ global salome_study_ID
+ print "getActiveStudy"
+ if salome_study_ID == -1:
+ if sg.hasDesktop():
+ print "---in gui"
+ salome_study_ID = sg.getActiveStudyId()
+ else:
+ print "---outside gui"
+ salome_study_ID = createNewStudy()
+ print"---", salome_study_ID
+ return salome_study_ID
+
+ #--------------------------------------------------------------------------
+
+def createNewStudy():
+ print "createNewStudy"
+ i=1
+ aStudyName = "noName"
+ nameAlreadyInUse = 1
+ listOfOpenStudies = myStudyManager.GetOpenStudies()
+ print listOfOpenStudies
+ while nameAlreadyInUse:
+ aStudyName = "extStudy_%d"%i
+ if aStudyName not in listOfOpenStudies:
+ nameAlreadyInUse=0
+ else:
+ i = i+1
+ theStudy = myStudyManager.NewStudy(aStudyName)
+ theStudyId = theStudy._get_StudyId()
+ print aStudyName, theStudyId
+ return theStudyId
+
+ #--------------------------------------------------------------------------
+
+# get Study Manager reference
+print "looking for studyManager ..."
+obj = naming_service.Resolve('myStudyManager')
+myStudyManager = obj._narrow(SALOMEDS.StudyManager)
+print "studyManager found"
+
+# get active study Id, ref and name
+myStudyId = getActiveStudy()
+print "myStudyId",myStudyId
+myStudy = myStudyManager.GetStudyByID(myStudyId)
+myStudyName = myStudy._get_Name()
+
+
+