From 3ad1fcdf71175c1200a9a638827b68cb21e200e1 Mon Sep 17 00:00:00 2001 From: prascle Date: Thu, 27 Jan 2005 17:47:18 +0000 Subject: [PATCH] PR: merge from tag mergeto_HEAD_26Jan05 --- bin/launchConfigureParser.py | 9 +- bin/runSalome.py | 28 ++ src/SALOMEGUI/PyInterp_base.cxx | 5 + src/SALOMEGUI/SALOMEGUI_Swig.cxx | 90 ++--- src/SALOMEGUI/SALOMEGUI_Swig.hxx | 2 + src/SALOMEGUI/SALOMEGUI_Swig.i | 2 + src/SALOME_SWIG_WITHOUTIHM/Makefile.in | 2 +- src/SALOME_SWIG_WITHOUTIHM/salome.py | 168 ++------- .../salome_ComponentGUI.py | 56 +++ src/SALOME_SWIG_WITHOUTIHM/salome_iapp.py | 74 ++++ src/SALOME_SWIG_WITHOUTIHM/salome_kernel.py | 55 +++ src/SALOME_SWIG_WITHOUTIHM/salome_study.py | 323 ++++++++++++++++++ 12 files changed, 639 insertions(+), 175 deletions(-) create mode 100644 src/SALOME_SWIG_WITHOUTIHM/salome_ComponentGUI.py create mode 100644 src/SALOME_SWIG_WITHOUTIHM/salome_iapp.py create mode 100644 src/SALOME_SWIG_WITHOUTIHM/salome_kernel.py create mode 100644 src/SALOME_SWIG_WITHOUTIHM/salome_study.py diff --git a/bin/launchConfigureParser.py b/bin/launchConfigureParser.py index b61515d19..403e0299b 100755 --- a/bin/launchConfigureParser.py +++ b/bin/launchConfigureParser.py @@ -124,7 +124,7 @@ else: 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"]: @@ -205,7 +205,7 @@ except: 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 @@ -233,7 +233,8 @@ if opts.has_key("h"): --containers=cpp,python,superv: (obsolete) launching of containers cpp, python and supervision or -c=cpp,python,superv : = get default from -e and -s --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 For each Salome module, the environment variable _ROOT_DIR must be set. The module name () must be uppercase. @@ -252,6 +253,8 @@ for opt in opts: 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': diff --git a/bin/runSalome.py b/bin/runSalome.py index 75a0cc9ae..3b76485fc 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -253,6 +253,22 @@ class Server: process_id[pid]=self.CMD +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 @@ -569,6 +585,18 @@ def startSalome(args, modules_list, modules_root_dir): 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 # ----------------------------------------------------------------------------- diff --git a/src/SALOMEGUI/PyInterp_base.cxx b/src/SALOMEGUI/PyInterp_base.cxx index 199381a54..153872048 100644 --- a/src/SALOMEGUI/PyInterp_base.cxx +++ b/src/SALOMEGUI/PyInterp_base.cxx @@ -258,6 +258,11 @@ int PyInterp_base::run(const char *command) _atFirst = false; return ret; } + ret = simpleRun("salome.salome_init()"); + if (ret) { + _atFirst = false; + return ret; + } _atFirst = false; } return simpleRun(command); diff --git a/src/SALOMEGUI/SALOMEGUI_Swig.cxx b/src/SALOMEGUI/SALOMEGUI_Swig.cxx index 6f0875682..0865d6b3c 100644 --- a/src/SALOMEGUI/SALOMEGUI_Swig.cxx +++ b/src/SALOMEGUI/SALOMEGUI_Swig.cxx @@ -44,11 +44,14 @@ using namespace std; -// asv : 3.12.04 : added checking for NULL GUI objects in almost all methods. In the scope -// of fixing bug PAL6869. Instance of this class is created every time "import salome" line -// is typed in stand-alone (Python console) or embedded (InLine nodes in Supervisor) python. -// SALOME GUI may not be created at this time (desktop and other objects), so checking if they -// are equal to NULL is neccessary. +// 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 ) { @@ -84,6 +87,17 @@ SALOMEGUI_Swig::~SALOMEGUI_Swig() // 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 */ @@ -100,9 +114,9 @@ QAD_Study* SALOMEGUI_Swig::getActiveStudy() */ void SALOMEGUI_Swig::updateObjBrowser( bool updateSelection ) { - if ( QAD_Study* aStudy = getActiveStudy() ) + if ( QAD_Study* myActiveStudy = getActiveStudy() ) ProcessVoidEvent( new TVoidMemFun1ArgEvent - ( aStudy, &QAD_Study::updateObjBrowser,updateSelection) ); + ( myActiveStudy, &QAD_Study::updateObjBrowser,updateSelection) ); } /*! @@ -110,8 +124,8 @@ void SALOMEGUI_Swig::updateObjBrowser( bool updateSelection ) */ int SALOMEGUI_Swig::getActiveStudyId() { - if ( QAD_Study* aStudy = getActiveStudy() ) - return aStudy->getStudyId(); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) + return myActiveStudy->getStudyId(); return 0; } @@ -120,8 +134,8 @@ int SALOMEGUI_Swig::getActiveStudyId() */ const char *SALOMEGUI_Swig::getActiveStudyName() { - if ( QAD_Study* aStudy = getActiveStudy() ) - return aStudy->getTitle().latin1(); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) + return myActiveStudy->getTitle().latin1(); return NULL; } @@ -149,8 +163,8 @@ const char* SALOMEGUI_Swig::getComponentUserName( const char* ComponentName ) */ int SALOMEGUI_Swig::SelectedCount() { - if ( QAD_Study* aStudy = getActiveStudy() ) { - SALOME_Selection* Sel = SALOME_Selection::Selection( aStudy->getSelection() ); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { + SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); return Sel->IObjectCount(); } return 0; @@ -161,8 +175,8 @@ int SALOMEGUI_Swig::SelectedCount() */ const char* SALOMEGUI_Swig::getSelected( int i ) { - if ( QAD_Study* aStudy = getActiveStudy() ) { - SALOME_Selection* Sel = SALOME_Selection::Selection( aStudy->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() ) { @@ -181,10 +195,10 @@ const char* SALOMEGUI_Swig::getSelected( int i ) */ void SALOMEGUI_Swig::AddIObject( const char *theEntry ) { - if ( QAD_Study* aStudy = getActiveStudy() ) { - SALOME_Selection* aSel = SALOME_Selection::Selection( aStudy->getSelection() ); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { + SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); if ( IsInCurrentView( theEntry ) ) { - Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( aStudy,theEntry ); + Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy,theEntry ); if ( anIO.IsNull() ) return; ProcessEvent( new TMemFun2ArgEventgetSelection() ); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { + SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); if ( IsInCurrentView( theEntry ) ) { - Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( aStudy,theEntry ); + Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy,theEntry ); if ( anIO.IsNull() ) return; ProcessEvent( new TMemFun2ArgEventgetSelection() ); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { + SALOME_Selection* aSel = SALOME_Selection::Selection( myActiveStudy->getSelection() ); ProcessVoidEvent( new TVoidMemFunEvent ( aSel, &SALOME_Selection::ClearIObjects ) ); } @@ -231,11 +245,11 @@ void SALOMEGUI_Swig::ClearIObjects() */ void SALOMEGUI_Swig::Display( const char *theEntry ) { - if ( QAD_Study* aStudy = getActiveStudy() ) { + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { if ( IsInCurrentView( theEntry ) ) { - Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( aStudy, theEntry ); + Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy, theEntry ); if ( anIO.IsNull() ) return; - QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( aStudy ); + QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy ); ProcessVoidEvent( new TVoidMemFun2ArgEvent @@ -249,11 +263,11 @@ void SALOMEGUI_Swig::Display( const char *theEntry ) */ void SALOMEGUI_Swig::DisplayOnly( const char *theEntry ) { - if ( QAD_Study* aStudy = getActiveStudy() ) { + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { if ( IsInCurrentView( theEntry ) ) { - Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( aStudy, theEntry ); + Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy, theEntry ); if ( anIO.IsNull() ) return; - QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( aStudy ); + QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy ); ProcessVoidEvent( new TVoidMemFun1ArgEvent @@ -267,11 +281,11 @@ void SALOMEGUI_Swig::DisplayOnly( const char *theEntry ) */ void SALOMEGUI_Swig::Erase( const char *theEntry ) { - if ( QAD_Study* aStudy = getActiveStudy() ) { + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { if ( IsInCurrentView( theEntry ) ) { - Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( aStudy, theEntry ); + Handle(SALOME_InteractiveObject) anIO = SALOME::FindIObject( myActiveStudy, theEntry ); if ( anIO.IsNull() ) return; - QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( aStudy ); + QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy ); ProcessVoidEvent( new TVoidMemFun2ArgEvent @@ -285,8 +299,8 @@ void SALOMEGUI_Swig::Erase( const char *theEntry ) */ void SALOMEGUI_Swig::DisplayAll() { - if ( QAD_Study* aStudy = getActiveStudy() ) { - QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( aStudy ); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { + QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy ); ProcessVoidEvent( new TVoidMemFunEvent ( aViewFrame, &QAD_ViewFrame::DisplayAll ) ); } @@ -298,8 +312,8 @@ void SALOMEGUI_Swig::DisplayAll() void SALOMEGUI_Swig::EraseAll() { ClearIObjects(); - if ( QAD_Study* aStudy = getActiveStudy() ) { - QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( aStudy ); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) { + QAD_ViewFrame* aViewFrame = SALOME::GetViewFrame( myActiveStudy ); ProcessVoidEvent ( new TVoidMemFunEvent ( aViewFrame, &QAD_ViewFrame::EraseAll ) ); } @@ -310,7 +324,7 @@ void SALOMEGUI_Swig::EraseAll() */ bool SALOMEGUI_Swig::IsInCurrentView( const char *theEntry ) { - if ( QAD_Study* aStudy = getActiveStudy() ) - return aStudy->isInViewer( theEntry, aStudy->getActiveStudyFrame()->entry() ); + if ( QAD_Study* myActiveStudy = getActiveStudy() ) + return myActiveStudy->isInViewer( theEntry, myActiveStudy->getActiveStudyFrame()->entry() ); return false; } diff --git a/src/SALOMEGUI/SALOMEGUI_Swig.hxx b/src/SALOMEGUI/SALOMEGUI_Swig.hxx index f61d26fd0..967c09377 100644 --- a/src/SALOMEGUI/SALOMEGUI_Swig.hxx +++ b/src/SALOMEGUI/SALOMEGUI_Swig.hxx @@ -51,6 +51,8 @@ public: SALOMEGUI_Swig(); ~SALOMEGUI_Swig(); + bool hasDesktop(); + void updateObjBrowser( bool updateSelection ); QAD_Study* getActiveStudy(); int getActiveStudyId(); diff --git a/src/SALOMEGUI/SALOMEGUI_Swig.i b/src/SALOMEGUI/SALOMEGUI_Swig.i index d5c5a5007..1910dad02 100644 --- a/src/SALOMEGUI/SALOMEGUI_Swig.i +++ b/src/SALOMEGUI/SALOMEGUI_Swig.i @@ -57,6 +57,8 @@ class SALOMEGUI_Swig SALOMEGUI_Swig(); ~SALOMEGUI_Swig(); + bool hasDesktop(); + void updateObjBrowser(bool); int getActiveStudyId(); const char *getActiveStudyName(); diff --git a/src/SALOME_SWIG_WITHOUTIHM/Makefile.in b/src/SALOME_SWIG_WITHOUTIHM/Makefile.in index 1c42c1ad6..be103f272 100755 --- a/src/SALOME_SWIG_WITHOUTIHM/Makefile.in +++ b/src/SALOME_SWIG_WITHOUTIHM/Makefile.in @@ -38,7 +38,7 @@ VPATH=.:@srcdir@:@top_srcdir@/idl 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 salome_ComponentGUI.py EXPORT_SHAREDPYSCRIPTS=kernel_shared_modules.py diff --git a/src/SALOME_SWIG_WITHOUTIHM/salome.py b/src/SALOME_SWIG_WITHOUTIHM/salome.py index 7cd1fb0af..e8d5d5bac 100755 --- a/src/SALOME_SWIG_WITHOUTIHM/salome.py +++ b/src/SALOME_SWIG_WITHOUTIHM/salome.py @@ -24,138 +24,40 @@ # Module : SALOME # $Header$ -from omniORB import CORBA -from LifeCycleCORBA import * -from libSALOME_Swig import * -import SALOMEDS -import Engines -from SALOME_NamingServicePy import * - -from SALOME_utilities import * - -#-------------------------------------------------------------------------- - -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 +from salome_kernel import * +from salome_study import * +from salome_iapp import * + +salome_initial=1 +def salome_init(theStudyId=0): + """ + Performs only once SALOME general purpose intialisation for scripts. + optional argument : theStudyId + When in embedded interpreter inside IAPP, theStudyId is not used + When used without GUI (external interpreter) + 0 : create a new study (default). + n (>0) : try connection to study with Id = n, or create a new one + if study not found. + If study creation, its Id may be different from theStudyId ! + Provides: + orb reference to CORBA + lcc a LifeCycleCorba instance + naming_service a naming service instance + cm reference to the container manager + sg access to SALOME GUI (when linked with IAPP GUI) + myStudyManager the study manager + myStudyId active study identifier + myStudy active study itself (CORBA reference) + myStudyName active study name + """ + global salome_initial + global orb, lcc, naming_service, cm + global sg + global myStudyManager, myStudyId, myStudy, myStudyName - #-------------------------------------------------------------------------- - -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) + if salome_initial: + salome_initial=0 + sg = salome_iapp_init() + orb, lcc, naming_service, cm = salome_kernel_init() + myStudyManager, myStudyId, myStudy, myStudyName =salome_study_init(theStudyId) -# get Container Manager -obj = naming_service.Resolve('/ContainerManager') -cm = obj._narrow(Engines.ContainerManager) diff --git a/src/SALOME_SWIG_WITHOUTIHM/salome_ComponentGUI.py b/src/SALOME_SWIG_WITHOUTIHM/salome_ComponentGUI.py new file mode 100644 index 000000000..617c88218 --- /dev/null +++ b/src/SALOME_SWIG_WITHOUTIHM/salome_ComponentGUI.py @@ -0,0 +1,56 @@ +# 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.py +# Author : Paul RASCLE, EDF +# Module : SALOME +# $Header$ + + +# to replace some function from _SWIG, outside GUI + +# --- From GeometryGUI_SWIG + + #-------------------------------------------------------------------------- + +def getIndexTopology(aSubId, aMainId): + return 0 + + #-------------------------------------------------------------------------- + +def getShapeTypeString(aSubId): + return "SubShape" + + #-------------------------------------------------------------------------- + +# --- From SMESHGUI_SWIG + + #-------------------------------------------------------------------------- + +def Init(studyId): + return + + #-------------------------------------------------------------------------- + +def SetName(objId, name): + return + + #-------------------------------------------------------------------------- diff --git a/src/SALOME_SWIG_WITHOUTIHM/salome_iapp.py b/src/SALOME_SWIG_WITHOUTIHM/salome_iapp.py new file mode 100644 index 000000000..befa0d075 --- /dev/null +++ b/src/SALOME_SWIG_WITHOUTIHM/salome_iapp.py @@ -0,0 +1,74 @@ +# 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 * +import salome_ComponentGUI + + #-------------------------------------------------------------------------- + +IN_SALOME_GUI=0 + +def ImportComponentGUI(ComponentName): + if IN_SALOME_GUI: + libName = "lib" + ComponentName + "_Swig" + command = "from " + libName + " import *" + exec ( command ) + constructor = ComponentName + "_Swig()" + command = "gui = " + constructor + exec ( command ) + return gui + else: + print "Warning: ImportComponentGUI(",ComponentName,") outside GUI !" + print "calls to GUI methods may crash..." + return salome_ComponentGUI + + #-------------------------------------------------------------------------- + +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 + + #-------------------------------------------------------------------------- + +salome_iapp_initial = 1 + +def salome_iapp_init(): + global salome_iapp_initial + global sg,IN_SALOME_GUI + + if salome_iapp_initial: + salome_iapp_initial=0 + + # create a SALOMEGUI_Swig instance + sg = SalomeGUI() + IN_SALOME_GUI=sg.hasDesktop() + return sg diff --git a/src/SALOME_SWIG_WITHOUTIHM/salome_kernel.py b/src/SALOME_SWIG_WITHOUTIHM/salome_kernel.py new file mode 100644 index 000000000..40fe9e124 --- /dev/null +++ b/src/SALOME_SWIG_WITHOUTIHM/salome_kernel.py @@ -0,0 +1,55 @@ +# 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 * +import Engines + +salome_kernel_initial=1 + +def salome_kernel_init(): + global salome_kernel_initial + global orb, lcc, naming_service, cm + + if salome_kernel_initial: + salome_kernel_initial = 0 + + # initialise the ORB + orb = CORBA.ORB_init([''], CORBA.ORB_ID) + + # create a LifeCycleCORBA instance + lcc = LifeCycleCORBA(orb) + + #create a naming service instance + naming_service = SALOME_NamingServicePy_i(orb) + + # get Container Manager + obj = naming_service.Resolve('/ContainerManager') + cm = obj._narrow(Engines.ContainerManager) + + return orb, lcc, naming_service, cm diff --git a/src/SALOME_SWIG_WITHOUTIHM/salome_study.py b/src/SALOME_SWIG_WITHOUTIHM/salome_study.py new file mode 100644 index 000000000..f643e844b --- /dev/null +++ b/src/SALOME_SWIG_WITHOUTIHM/salome_study.py @@ -0,0 +1,323 @@ +# 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$ + +import salome_kernel +import SALOMEDS +import salome_iapp + +#-------------------------------------------------------------------------- + +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 + + #-------------------------------------------------------------------------- + +def generateName(prefix = None): + import whrandom; + int = whrandom.randint(1,1000); + if prefix is None: + return "Study" + str(int) + else : + return prefix + str(int) + + #-------------------------------------------------------------------------- + +def PersistentPresentation(theStudy, theSO, theWithID): + # put the sobject's content (with subchildren) to the string + aResult = "" + attrs = theSO.GetAllAttributes() + aLen = len(attrs) + anUncopied = 0 + for a in range(0,aLen): + attr = attrs[a] + if isinstance(attr,SALOMEDS._objref_AttributeTreeNode): + anUncopied += 1 + elif isinstance(attr,SALOMEDS._objref_AttributeTarget): + anUncopied += 1 + elif isinstance(attr,SALOMEDS._objref_AttributeReal) or \ + isinstance(attr,SALOMEDS._objref_AttributeInteger) or \ + isinstance(attr,SALOMEDS._objref_AttributeName) or \ + isinstance(attr,SALOMEDS._objref_AttributeComment) or \ + isinstance(attr,SALOMEDS._objref_AttributePersistentRef) or \ + isinstance(attr,SALOMEDS._objref_AttributeLocalID) or \ + isinstance(attr,SALOMEDS._objref_AttributeUserID): + aResult += " attribute value: " + str(attr.Value()) + elif isinstance(attr,SALOMEDS._objref_AttributeIOR): + aResult += " attribute: IOR" + elif isinstance(attr,SALOMEDS._objref_AttributeSequenceOfReal) or \ + isinstance(attr,SALOMEDS._objref_AttributeSequenceOfInteger): + aResult += " Sequence: " + str(attr.CorbaSequence()) + elif isinstance(attr,SALOMEDS._objref_AttributeDrawable): + aResult += " Drawable: " + str(attr.IsDrawable()) + elif isinstance(attr,SALOMEDS._objref_AttributeSelectable): + aResult += " Selectable: " + str(attr.IsSelectable()) + elif isinstance(attr,SALOMEDS._objref_AttributeExpandable): + aResult += " Expandable: " + str(attr.IsExpandable()) + elif isinstance(attr,SALOMEDS._objref_AttributeOpened): + aResult += " Opened: " + str(attr.IsOpened()) + elif isinstance(attr,SALOMEDS._objref_AttributeTextColor): + aResult += " TextColor: " + str(attr.TextColor()) + elif isinstance(attr,SALOMEDS._objref_AttributeTextHighlightColor): + aResult += " TextHighlightColor: " + str(attr.TextHighlightColor()) + elif isinstance(attr,SALOMEDS._objref_AttributePixMap): + aResult += " PixMap: " + str(attr.GetPixMap()) + elif isinstance(attr,SALOMEDS._objref_AttributeTableOfInteger) or \ + isinstance(attr,SALOMEDS._objref_AttributeTableOfReal): + aResult += " Table with title: " + attr.GetTitle() + elif isinstance(attr,SALOMEDS._objref_AttributePythonObject): + aResult += " PythonObject: " + attr.GetObject() + + if theWithID: + aResult = "sobject: " + theSO.GetID() + " nbattrs: " + str(aLen - anUncopied) + aResult + '\n' + else: + aResult = " nbattrs: " + str(aLen - anUncopied) + aResult + '\n' + anIter = theStudy.NewChildIterator(theSO) + while anIter.More(): + aResult += PersistentPresentation(theStudy, anIter.Value(), theWithID) + anIter.Next() + return aResult + + #-------------------------------------------------------------------------- + +def GetTree(theSO): + # returns the document list tree (as list) + aResult = [theSO.GetID()] + anIter = myStudy.NewChildIterator(theSO) + while anIter.More(): + aResult += GetTree(anIter.Value()) + anIter.Next() + return aResult + + #-------------------------------------------------------------------------- + +def CheckCopyPaste(theSO, theInfo ,theComponentPaste): + aRoot = theSO + while aRoot.GetID() != "0:": + aRoot = aRoot.GetFather() + aTree = GetTree(aRoot) + aStudyPersist = PersistentPresentation(myStudy, aRoot, 1) + + if not myStudyManager.CanCopy(theSO): + raise RuntimeError, " for "+theInfo+" returns false" + + if not myStudyManager.Copy(theSO): + raise RuntimeError, " for "+theInfo+" returns false" + + + if not myStudyManager.CanPaste(theSO): + raise RuntimeError, " for "+theInfo+" returns false" + + # check: before paste study is not changed check + if aStudyPersist != PersistentPresentation(myStudy, aRoot, 1): + raise RuntimeError, "Study is changed before Paste calling for "+theInfo + + aSObj = theSO + if theComponentPaste: + aSObj = theSO.GetFatherComponent() + theInfo = theInfo + "(paste for component)" + if myStudyManager.Paste(aSObj) == None: + raise RuntimeError, " for "+theInfo+" returns None object" + aNewTree = GetTree(aRoot) + aLen = len(aTree) + for a in range(0,aLen): + if aTree[a] != aNewTree[a]: + return myStudy.FindObjectID(aNewTree[a]) + + if aLen < len(aNewTree): + return myStudy.FindObjectID(aNewTree[aLen]) + + raise RuntimeError, "After Copy calling the tree is not changed" + + #-------------------------------------------------------------------------- + +def FindFileInDataDir(filename): + import os + datadir = os.getenv("DATA_DIR") + if datadir is not None: + import string + dirs = string.split(datadir, ":") + for dir in dirs: + file = dir + "/" + filename + if os.path.exists(file): + return file; + datadir = os.getenv("KERNEL_ROOT_DIR") + "/examples/" + file = datadir + filename + if os.path.exists(file): + return file; + + return None + + #-------------------------------------------------------------------------- + +salome_study_ID = -1 + +def getActiveStudy(theStudyId=0): + global salome_study_ID + + print "getActiveStudy" + sg = salome_iapp.salome_iapp_init() + if salome_study_ID == -1: + if sg.hasDesktop(): + print "---in gui" + salome_study_ID = sg.getActiveStudyId() + else: + print "---outside gui" + if theStudyId: + aStudy=myStudyManager.GetStudyByID(theStudyId) + if aStudy: + print "connection to existing study ", theStudyId + salome_study_ID = theStudyId + if salome_study_ID == -1: + salome_study_ID = createNewStudy() + print"--- Study Id ", 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 + + #-------------------------------------------------------------------------- + +salome_study_initial = 1 + +def salome_study_init(theStudyId=0): + """ + Performs only once study creation or connection. + optional argument : theStudyId + When in embedded interpreter inside IAPP, theStudyId is not used + When used without GUI (external interpreter) + 0 : create a new study (default). + n (>0) : try connection to study with Id = n, or create a new one + if study not found. + """ + + global salome_study_initial + global myStudyManager, myStudyId, myStudy, myStudyName + global orb, lcc, naming_service, cm + + if salome_study_initial: + salome_study_initial = 0 + + orb, lcc, naming_service, cm = salome_kernel.salome_kernel_init() + + # 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(theStudyId) + print "myStudyId",myStudyId + myStudy = myStudyManager.GetStudyByID(myStudyId) + myStudyName = myStudy._get_Name() + + return myStudyManager, myStudyId, myStudy, myStudyName + -- 2.39.2