From: ouv Date: Thu, 27 Nov 2008 11:54:54 +0000 (+0000) Subject: Dump Python extension X-Git-Tag: TG_DumpPython_Extension_3~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=490a83efa8cfb574e32c417760bf130df9f49c6f;p=modules%2Fsmesh.git Dump Python extension --- diff --git a/src/SMESH_I/SMESH_2smeshpy.cxx b/src/SMESH_I/SMESH_2smeshpy.cxx index f1673f85e..cad2d2f94 100644 --- a/src/SMESH_I/SMESH_2smeshpy.cxx +++ b/src/SMESH_I/SMESH_2smeshpy.cxx @@ -125,7 +125,7 @@ SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript, { theGen = new _pyGen( theEntry2AccessorMethod ); - SMESH_NoteBook * aNoteBook = new SMESH_NoteBook(); + SMESH_NoteBook * aNoteBook = new SMESH_NoteBook( theGen ); // split theScript into separate commands int from = 1, end = theScript.Length(), to; @@ -1916,7 +1916,8 @@ void _pyCommand::SetArg( int index, const TCollection_AsciiString& theArg) if ( pos < 1 ) // no index-th arg exist, append inexistent args { // find a closing parenthesis - if ( int lastArgInd = GetNbArgs() ) { + if ( GetNbArgs() != 0 && index <= GetNbArgs() ) { + int lastArgInd = GetNbArgs(); pos = GetBegPos( ARG1_IND + lastArgInd - 1 ) + GetArg( lastArgInd ).Length(); while ( pos > 0 && pos <= Length() && myString.Value( pos ) != ')' ) ++pos; diff --git a/src/SMESH_I/SMESH_2smeshpy.hxx b/src/SMESH_I/SMESH_2smeshpy.hxx index cb8586f01..d5a26c627 100644 --- a/src/SMESH_I/SMESH_2smeshpy.hxx +++ b/src/SMESH_I/SMESH_2smeshpy.hxx @@ -186,6 +186,7 @@ public: bool AddMeshAccessorMethod( Handle(_pyCommand) theCmd ) const; bool AddAlgoAccessorMethod( Handle(_pyCommand) theCmd ) const; const char* AccessorMethod() const; + const std::map< _pyID, Handle(_pyMeshEditor) >& getMeshEditors() const { return myMeshEditors; } private: std::map< _pyID, Handle(_pyMesh) > myMeshes; std::map< _pyID, Handle(_pyMeshEditor) > myMeshEditors; diff --git a/src/SMESH_I/SMESH_Gen_i_1.cxx b/src/SMESH_I/SMESH_Gen_i_1.cxx index 3846c2247..55412b182 100644 --- a/src/SMESH_I/SMESH_Gen_i_1.cxx +++ b/src/SMESH_I/SMESH_Gen_i_1.cxx @@ -878,32 +878,28 @@ void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theP return; SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theObject ); - if ( !aHyp->_is_nil() ) { - CORBA::String_var objStr = aHyp->GetParameters(); - TCollection_AsciiString aNewParams; - TCollection_AsciiString anInputParams; - SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters); + TCollection_AsciiString aNewParams; + TCollection_AsciiString anInputParams; + SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters); - SALOMEDS::GenericAttribute_var anAttr; - anAttr = aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString"); - SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr); - TCollection_AsciiString aOldParameters(aStringAttr->Value()); - SALOMEDS::ListOfStrings aVars= aSections[0]; - for(int i=0;iIsVariable(aVars[i].in()) ? - TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString(""); - if(i != aVars.length()-1) - anInputParams+=":"; - } - if(!aOldParameters.Length()) - aNewParams = anInputParams; - else - aNewParams = aOldParameters+"|"+anInputParams; - - aStringAttr->SetValue( aNewParams.ToCString() ); + SALOMEDS::GenericAttribute_var anAttr; + anAttr = aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString"); + SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr); + TCollection_AsciiString aOldParameters(aStringAttr->Value()); + SALOMEDS::ListOfStrings aVars= aSections[0]; + for(int i=0;iIsVariable(aVars[i].in()) ? + TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString(""); + if(i != aVars.length()-1) + anInputParams+=":"; } + if(!aOldParameters.Length()) + aNewParams = anInputParams; + else + aNewParams = aOldParameters+"|"+anInputParams; + + aStringAttr->SetValue( aNewParams.ToCString() ); } @@ -917,12 +913,10 @@ char* SMESH_Gen_i::GetParameters(CORBA::Object_ptr theObject) SALOMEDS::Study_ptr aStudy = GetCurrentStudy(); SALOMEDS::SObject_var aSObj = ObjectToSObject(aStudy,theObject); - SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow( theObject ); if(!aStudy->_is_nil() && !CORBA::is_nil(theObject) && - !aSObj->_is_nil() && - !aHyp->_is_nil()){ + !aSObj->_is_nil()){ SALOMEDS::GenericAttribute_var anAttr; if ( aSObj->FindAttribute(anAttr, "AttributeString")) { diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index 0b3659fb9..f7da16dce 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -2452,10 +2452,9 @@ void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements, CORBA::Boolean theCopy) { if ( !myPreviewMode ) { - TPythonDump() << "vector = " << theVector; TPythonDump() << this << ".Translate( " - << theIDsOfElements - << ", vector, " + << theIDsOfElements << ", " + << theVector << ", " << theCopy << " )"; } translate(theIDsOfElements, @@ -2475,8 +2474,8 @@ void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject, { if ( !myPreviewMode ) { TPythonDump() << this << ".TranslateObject( " - << theObject - << ", vector, " + << theObject << ", " + << theVector << ", " << theCopy << " )"; } SMESH::long_array_var anElementsId = theObject->GetIDs(); @@ -2497,12 +2496,11 @@ SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElement { SMESH::ListOfGroups * aGroups = translate(theIDsOfElements,theVector,true,true); if ( !myPreviewMode ) { - TPythonDump() << "vector = " << theVector; TPythonDump aPythonDump; DumpGroupsList(aPythonDump,aGroups); aPythonDump << this << ".TranslateMakeGroups( " - << theIDsOfElements - << ", vector )"; + << theIDsOfElements << ", " + << theVector << " )"; } return aGroups; } @@ -2521,12 +2519,11 @@ SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObjec if ( !myPreviewMode ) { - TPythonDump() << "vector = " << theVector; TPythonDump aPythonDump; DumpGroupsList(aPythonDump,aGroups); aPythonDump << this << ".TranslateObjectMakeGroups( " - << theObject - << ", vector )"; + << theObject << ", " + << theVector << " )"; } return aGroups; } diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index c5acc6a46..fe4381391 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -2535,3 +2535,50 @@ SALOME_MED::MedFileInfo* SMESH_Mesh_i::GetMEDFileInfo() } return res._retn(); } + +//============================================================================= +/*! + * \brief Sets list of notebook variables used for Mesh operations separated by ":" symbol + */ +//============================================================================= +void SMESH_Mesh_i::SetParameters(const char* theParameters) +{ + SMESH_Gen_i::GetSMESHGen()->UpdateParameters(SMESH::SMESH_Mesh::_narrow(_this()), + CORBA::string_dup(theParameters)); +} + +//============================================================================= +/*! + * \brief Returns list of notebook variables used for Mesh operations separated by ":" symbol + */ +//============================================================================= +char* SMESH_Mesh_i::GetParameters() +{ + SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen(); + return CORBA::string_dup(gen->GetParameters(SMESH::SMESH_Mesh::_narrow(_this()))); +} + +//============================================================================= +/*! + * \brief Returns list of notebook variables used for last Mesh operation + */ +//============================================================================= +SMESH::string_array* SMESH_Mesh_i::GetLastParameters() +{ + SMESH::string_array_var aResult = new SMESH::string_array(); + SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen(); + if(gen) { + char *aParameters = GetParameters(); + SALOMEDS::Study_ptr aStudy = gen->GetCurrentStudy(); + if(!aStudy->_is_nil()) { + SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters); + if(aSections->length() > 0) { + SALOMEDS::ListOfStrings aVars = aSections[aSections->length()-1]; + aResult->length(aVars.length()); + for(int i = 0;i < aVars.length();i++) + aResult[i] = CORBA::string_dup( aVars[i]); + } + } + } + return aResult._retn(); +} diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 6d0f5e47f..05c8789ee 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -446,6 +446,21 @@ public: */ virtual SALOME_MED::MedFileInfo* GetMEDFileInfo(); + /*! + * Sets list of notebook variables used for Mesh operations separated by ":" symbol + */ + void SetParameters (const char* theParameters); + + /*! + * Returns list of notebook variables used for Mesh operations separated by ":" symbol + */ + char* GetParameters(); + + /*! + * Returns list of notebook variables used for last Mesh operation + */ + SMESH::string_array* GetLastParameters(); + std::map _mapSubMesh_i; //NRI std::map _mapSubMesh; //NRI diff --git a/src/SMESH_I/SMESH_NoteBook.cxx b/src/SMESH_I/SMESH_NoteBook.cxx index ffdb9b114..b540a88da 100644 --- a/src/SMESH_I/SMESH_NoteBook.cxx +++ b/src/SMESH_I/SMESH_NoteBook.cxx @@ -23,6 +23,7 @@ #include "SMESH_2smeshpy.hxx" #include "SMESH_NoteBook.hxx" #include "SMESH_Gen_i.hxx" +#include "SMESH_PythonDump.hxx" #include #include @@ -118,7 +119,8 @@ TCollection_AsciiString ObjectStates::GetObjectType() const{ * \brief Constructor */ //================================================================================ -SMESH_NoteBook::SMESH_NoteBook() +SMESH_NoteBook::SMESH_NoteBook(Handle(_pyGen) theGen): + myGen( theGen ) { InitObjectMap(); } @@ -149,24 +151,73 @@ TCollection_AsciiString SMESH_NoteBook::ReplaceVariables(const TCollection_Ascii _pyCommand aCmd( theString, -1); TCollection_AsciiString aMethod = aCmd.GetMethod(); TCollection_AsciiString aObject = aCmd.GetObject(); + TCollection_AsciiString aResultValue = aCmd.GetResultValue(); + if(aMethod.IsEmpty()) + return theString; + + // check if method modifies the object itself TVariablesMap::const_iterator it = _objectMap.find(aObject); - if(!aMethod.IsEmpty() && it != _objectMap.end() ) { + if(it == _objectMap.end()) // check if method returns a new object + it = _objectMap.find(aResultValue); + + if(it == _objectMap.end()) { // check if method modifies a mesh using mesh editor + const std::map< _pyID, Handle(_pyMeshEditor) >& aMeshEditors = myGen->getMeshEditors(); + std::map< _pyID, Handle(_pyMeshEditor) >::const_iterator meIt = aMeshEditors.find(aObject); + if(meIt != aMeshEditors.end()) { + Handle(_pyMeshEditor) aMeshEditor = (*meIt).second; + if(!aMeshEditor.IsNull()) { + Handle(_pyCommand) aCreationCommand = aMeshEditor->GetCreationCmd(); + if(!aCreationCommand.IsNull()) { + TCollection_AsciiString aMesh = aCreationCommand->GetObject(); + it = _objectMap.find(aMesh); + } + } + } + } + + if(it != _objectMap.end()) { ObjectStates *aStates = (*it).second; - bool modified = false; if(MYDEBUG) cout<<"SMESH_NoteBook::ReplaceVariables :Object Type : "<GetObjectType()<GetObjectType().IsEqual("LocalLength")) { - if(aMethod == "SetLength") { + if(aMethod.IsEqual("SetLength")) { if(!aStates->GetCurrectState().at(0).IsEmpty() ) aCmd.SetArg(1,aStates->GetCurrectState().at(0)); aStates->IncrementState(); } - else if(aMethod == "SetPrecision") { + else if(aMethod.IsEqual("SetPrecision")) { if(!aStates->GetCurrectState().at(1).IsEmpty() ) aCmd.SetArg(1,aStates->GetCurrectState().at(1)); aStates->IncrementState(); } } + else if(aStates->GetObjectType().IsEqual("Mesh")) { + if(aMethod.IsEqual("Translate") || + aMethod.IsEqual("TranslateMakeGroups") || + aMethod.IsEqual("TranslateMakeMesh")) { + bool isVariableFound = false; + int anArgIndex = 0; + for(int i = 1, n = aCmd.GetNbArgs(); i <= n; i++) { + if(aCmd.GetArg(i).IsEqual("SMESH.PointStruct")) { + anArgIndex = i+1; + break; + } + } + if(anArgIndex > 0) { + for(int j = 0; j <= 2; j++) { + if(!aStates->GetCurrectState().at(j).IsEmpty()) { + isVariableFound = true; + aCmd.SetArg(anArgIndex+j, aStates->GetCurrectState().at(j)); + } + } + } + if(isVariableFound) { + aCmd.SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr"); + aCmd.SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr"); + } + aStates->IncrementState(); + } + } return aCmd.GetString(); } diff --git a/src/SMESH_I/SMESH_NoteBook.hxx b/src/SMESH_I/SMESH_NoteBook.hxx index e11f3bd5c..0eef2063d 100644 --- a/src/SMESH_I/SMESH_NoteBook.hxx +++ b/src/SMESH_I/SMESH_NoteBook.hxx @@ -58,7 +58,7 @@ private: class SMESH_NoteBook { public: - SMESH_NoteBook(); + SMESH_NoteBook(Handle(_pyGen) theGen); ~SMESH_NoteBook(); TCollection_AsciiString ReplaceVariables(const TCollection_AsciiString& theString) const; @@ -69,6 +69,7 @@ private: private: TVariablesMap _objectMap; + Handle(_pyGen) myGen; }; #endif //SMESH_NoteBook_HeaderFile diff --git a/src/SMESH_SWIG/smeshDC.py b/src/SMESH_SWIG/smeshDC.py index cf6243379..980126d96 100644 --- a/src/SMESH_SWIG/smeshDC.py +++ b/src/SMESH_SWIG/smeshDC.py @@ -158,6 +158,47 @@ PrecisionConfusion = 1e-07 # Salome notebook variable separator variable_separator = ":" +# Parametrized substitute for PointStruct +class PointStructStr: + + x = 0 + y = 0 + z = 0 + xStr = "" + yStr = "" + zStr = "" + + def __init__(self, xStr, yStr, zStr): + self.xStr = xStr + self.yStr = yStr + self.zStr = zStr + if isinstance(xStr, str) and notebook.isVariable(xStr): + self.x = notebook.get(xStr) + else: + self.x = xStr + if isinstance(yStr, str) and notebook.isVariable(yStr): + self.y = notebook.get(yStr) + else: + self.y = yStr + if isinstance(zStr, str) and notebook.isVariable(zStr): + self.z = notebook.get(zStr) + else: + self.z = zStr + +# Parametrized substitute for DirStruct +class DirStructStr: + + def __init__(self, pointStruct): + self.pointStruct = pointStruct + +# Returns list of variable values from salome notebook +def ParseDirStruct(Vector): + pntStr = Vector.pointStruct + pnt = PointStruct(pntStr.x, pntStr.y, pntStr.z) + Vector = DirStruct(pnt) + Parameters = str(pntStr.xStr) + ":" + str(pntStr.yStr) + ":" + str(pntStr.zStr) + return Vector, Parameters + def IsEqual(val1, val2, tol=PrecisionConfusion): if abs(val1 - val2) < tol: return True @@ -2463,13 +2504,17 @@ class Mesh: # @return list of created groups (SMESH_GroupBase) if MakeGroups=True, empty list otherwise # @ingroup l2_modif_trsf def Translate(self, IDsOfElements, Vector, Copy, MakeGroups=False): + Parameters = "" if IDsOfElements == []: IDsOfElements = self.GetElementsId() if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)): Vector = self.smeshpyD.GetDirStruct(Vector) + elif ( isinstance( Vector, DirStructStr ) ): + Vector,Parameters = ParseDirStruct(Vector) if Copy and MakeGroups: return self.editor.TranslateMakeGroups(IDsOfElements, Vector) self.editor.Translate(IDsOfElements, Vector, Copy) + self.mesh.SetParameters(Parameters) return [] ## Creates a new mesh of translated elements @@ -2480,11 +2525,15 @@ class Mesh: # @return instance of Mesh class # @ingroup l2_modif_trsf def TranslateMakeMesh(self, IDsOfElements, Vector, MakeGroups=False, NewMeshName=""): + Parameters = "" if IDsOfElements == []: IDsOfElements = self.GetElementsId() if ( isinstance( Vector, geompyDC.GEOM._objref_GEOM_Object)): Vector = self.smeshpyD.GetDirStruct(Vector) + elif ( isinstance( Vector, DirStructStr ) ): + Vector,Parameters = ParseDirStruct(Vector) mesh = self.editor.TranslateMakeMesh(IDsOfElements, Vector, MakeGroups, NewMeshName) + mesh.SetParameters(Parameters) return Mesh ( self.smeshpyD, self.geompyD, mesh ) ## Translates the object