From: mpa Date: Thu, 24 Nov 2016 13:43:42 +0000 (+0300) Subject: add method NameChanged to update title name X-Git-Tag: Before_python3_27062017~1^2~19 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3ab949ae20e485075e7633362b8ff2af14ba5453;p=modules%2Fkernel.git add method NameChanged to update title name --- diff --git a/doc/salome/kernel_salome.dox b/doc/salome/kernel_salome.dox index 1ca301802..4fea5880d 100644 --- a/doc/salome/kernel_salome.dox +++ b/doc/salome/kernel_salome.dox @@ -179,7 +179,7 @@ window. The output for each object includes its entry ID, name, IOR (if there is one) and referenced object ID (for references). I.e. this is the same data the user can see in the Object Browser columns. \code -salome.DumpStudy(salome.myStudy) +salome.DumpStudy() \endcode \li \b IDToSObject() Get SALOMEDS object by its entry ID. diff --git a/src/Basics/Basics_DirUtils.cxx b/src/Basics/Basics_DirUtils.cxx index 38020be9a..a6ee8c0e3 100644 --- a/src/Basics/Basics_DirUtils.cxx +++ b/src/Basics/Basics_DirUtils.cxx @@ -57,7 +57,7 @@ namespace Kernel_Utils pos = tmp_str.rfind( _extension_ ); if( !with_extension && pos >= 0 ) - tmp_str = pos < (int)file_path.size()-1 ? file_path.substr( 0, pos ) : ""; + tmp_str = pos < (int)tmp_str.size()-1 ? tmp_str.substr( 0, pos ) : ""; return tmp_str; } diff --git a/src/KERNEL_PY/Help.py b/src/KERNEL_PY/Help.py index 7cebb8f65..4fd4a5e56 100755 --- a/src/KERNEL_PY/Help.py +++ b/src/KERNEL_PY/Help.py @@ -75,7 +75,7 @@ variables: methods : defined in SALOMEDS.idl methods: - salome.DumpStudy(study) : Dump a study, given the ior + salome.DumpStudy() : Dump a study, given the ior --- ''' print doc_salome diff --git a/src/KERNEL_PY/PyInterp.py b/src/KERNEL_PY/PyInterp.py index 8e4595e65..3c0787e4c 100755 --- a/src/KERNEL_PY/PyInterp.py +++ b/src/KERNEL_PY/PyInterp.py @@ -35,9 +35,10 @@ from SALOME_NamingServicePy import * #-------------------------------------------------------------------------- -def DumpComponent(Study, SO, offset): - it = Study.NewChildIterator(SO) - Builder = Study.NewBuilder() +def DumpComponent(SO, offset): + global myStudy + it = myStudy.NewChildIterator(SO) + Builder = myStudy.NewBuilder() while it.More(): CSO = it.Value() it.Next() @@ -60,18 +61,19 @@ def DumpComponent(Study, SO, offset): a = a + " " ofs = ofs +1 print a + ">" + RefSO.GetID() - DumpComponent(Study, CSO, offset+2) + DumpComponent(CSO, offset+2) #-------------------------------------------------------------------------- -def DumpStudy(Study): - itcomp = Study.NewComponentIterator() +def DumpStudy(): + global myStudy + itcomp = myStudy.NewComponentIterator() while itcomp.More(): SC = itcomp.Value() itcomp.Next() name = SC.ComponentDataType() print "-> ComponentDataType is " + name - DumpComponent(Study, SC, 1) + DumpComponent(SC, 1) #-------------------------------------------------------------------------- diff --git a/src/KERNEL_PY/__init__.py b/src/KERNEL_PY/__init__.py index 31adec9dd..e5d7c008e 100755 --- a/src/KERNEL_PY/__init__.py +++ b/src/KERNEL_PY/__init__.py @@ -167,7 +167,7 @@ myStudy, myStudyName=None,None salome_initial=1 def salome_init(embedded=0): """ - Performs only once SALOME general purpose intialisation for scripts. + Performs only once SALOME general purpose initialization for scripts. Provides: orb reference to CORBA lcc a LifeCycleCorba instance @@ -210,12 +210,11 @@ def salome_close(): try: # study can be clear either from GUI or directly with salome.myStudy.Clear() myStudy.Clear() + myStudy.Init() except: pass salome_initial=1 salome_iapp_close() - salome_study_close() - myStudy, myStudyName=None,None pass diff --git a/src/KERNEL_PY/salome_study.py b/src/KERNEL_PY/salome_study.py index bec5c191b..f249057f9 100755 --- a/src/KERNEL_PY/salome_study.py +++ b/src/KERNEL_PY/salome_study.py @@ -36,8 +36,9 @@ myStudyName = None #-------------------------------------------------------------------------- -def DumpComponent(Study, SO, Builder,offset): - it = Study.NewChildIterator(SO) +def DumpComponent(SO, Builder,offset): + global myStudy + it = myStudy.NewChildIterator(SO) while it.More(): CSO = it.Value() a=offset*"--" + ">" + CSO.GetID() @@ -56,17 +57,18 @@ def DumpComponent(Study, SO, Builder,offset): #-------------------------------------------------------------------------- -def DumpStudy(Study): +def DumpStudy(): """ Dump a study, given the ior """ - itcomp = Study.NewComponentIterator() - Builder = Study.NewBuilder() + global myStudy + itcomp = myStudy.NewComponentIterator() + Builder = myStudy.NewBuilder() while itcomp.More(): SC = itcomp.Value() name = SC.ComponentDataType() print "-> ComponentDataType is " + name - DumpComponent(Study, SC,Builder, 1) + DumpComponent(SC,Builder, 1) itcomp.Next() #-------------------------------------------------------------------------- @@ -84,6 +86,7 @@ def IDToObject(id): return myObj def ObjectToSObject(obj): + global myStudy mySO = None if obj is not None: ior = orb.object_to_string(obj) @@ -115,6 +118,7 @@ def generateName(prefix = None): #-------------------------------------------------------------------------- def PersistentPresentation(theSO, theWithID): + global myStudy # put the sobject's content (with subchildren) to the string aResult = "" attrs = theSO.GetAllAttributes() @@ -268,18 +272,9 @@ def FindFileInDataDir(filename): def openStudy(theStudyPath): print "openStudy" - salome.myStudy.Open(theStudyPath) - theStudyName = salome.myStudy._get_Name() - print theStudyPath, theStudyName - return theStudyName - - #-------------------------------------------------------------------------- -def clearStudy(): global myStudy - print "clearStudy" - myStudy.Clear() - myStudy = None - pass + myStudy.Open(theStudyPath) + print theStudyPath, myStudy._get_Name() #-------------------------------------------------------------------------- @@ -305,12 +300,10 @@ def salome_study_init(theStudyPath=None): if verbose(): print "Study found" pass - # get study name + import types + if theStudyPath and type(theStudyPath) == types.StringType: + openStudy(theStudyPath) + myStudyName = myStudy._get_Name() return myStudy, myStudyName - -def salome_study_close(): - global myStudy, myStudyName - myStudy, myStudyName = None, None - pass diff --git a/src/SALOMEDS/SALOMEDS_Client.cxx b/src/SALOMEDS/SALOMEDS_Client.cxx index 006d0b7f7..fd365b910 100644 --- a/src/SALOMEDS/SALOMEDS_Client.cxx +++ b/src/SALOMEDS/SALOMEDS_Client.cxx @@ -269,7 +269,7 @@ int main(int argc, char** argv) SALOME_NamingService * salomens = new SALOME_NamingService(orb); - MESSAGE("Create New Study "); + MESSAGE("Find Study "); CORBA::Object_ptr obj2 = salomens->Resolve("Study"); SALOMEDS::Study_var myStudy = SALOMEDS::Study::_narrow(obj2); diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index 8091ece62..3f0e83c50 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -269,6 +269,9 @@ void SALOMEDS_Study_i::Init() _impl->setNotifier(_notifier); _impl->setGenObjRegister( _genObjRegister ); + // update desktop title with new study name + NameChanged(); + // Notify GUI that study was created SALOME_NamingService *aNamingService = KERNEL::getNamingService(); CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); @@ -371,6 +374,9 @@ bool SALOMEDS_Study_i::Open(const char* aUrl) bool res = _impl->Open(std::string(aUrl)); + // update desktop title with new study name + NameChanged(); + if ( !res ) THROW_SALOME_CORBA_EXCEPTION("Impossible to Open study from file", SALOME::BAD_PARAM) return res; @@ -1064,6 +1070,9 @@ void SALOMEDS_Study_i::URL(const char* url) SALOMEDS::Locker lock; // URL is specified as IDL attribute: user exception cannot be raised _impl->URL(std::string((char*)url)); + + // update desktop title with new study name + NameChanged(); } void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry) @@ -1772,3 +1781,19 @@ CORBA::LongLong SALOMEDS_Study_i::GetLocalImpl(const char* theHostname, CORBA::L isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0; return reinterpret_cast(_impl); } + +void SALOMEDS_Study_i::NameChanged() +{ + // Notify GUI that the name of study was changed + SALOME_NamingService *aNamingService = KERNEL::getNamingService(); + CORBA::Object_var obj = aNamingService->Resolve("/Kernel/Session"); + SALOME::Session_var aSession = SALOME::Session::_narrow(obj); + if ( !CORBA::is_nil(aSession) ) { + std::stringstream ss; + ss << "studyNameChanged"; + std::string str = ss.str(); + SALOMEDS::unlock(); + aSession->emitMessageOneWay(str.c_str()); + SALOMEDS::lock(); + } +} diff --git a/src/SALOMEDS/SALOMEDS_Study_i.hxx b/src/SALOMEDS/SALOMEDS_Study_i.hxx index 20b3bd6d2..cfe22e265 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.hxx @@ -50,6 +50,8 @@ class Standard_EXPORT SALOMEDS_Study_i: public POA_SALOMEDS::Study { private: + + void NameChanged(); CORBA::ORB_var _orb; SALOMEDSImpl_Study* _impl; SALOMEDS_StudyBuilder_i* _builder;