Salome HOME
Dump Python extension
authorouv <ouv@opencascade.com>
Thu, 27 Nov 2008 11:54:54 +0000 (11:54 +0000)
committerouv <ouv@opencascade.com>
Thu, 27 Nov 2008 11:54:54 +0000 (11:54 +0000)
src/SMESH_I/SMESH_2smeshpy.cxx
src/SMESH_I/SMESH_2smeshpy.hxx
src/SMESH_I/SMESH_Gen_i_1.cxx
src/SMESH_I/SMESH_MeshEditor_i.cxx
src/SMESH_I/SMESH_Mesh_i.cxx
src/SMESH_I/SMESH_Mesh_i.hxx
src/SMESH_I/SMESH_NoteBook.cxx
src/SMESH_I/SMESH_NoteBook.hxx
src/SMESH_SWIG/smeshDC.py

index f1673f85e4bf0920381649e182ce63bd6a6a2b6d..cad2d2f94832eeb24fff73e4e9bb168a3798ffd7 100644 (file)
@@ -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;
index cb8586f015db8b75eb23599712a97e4e44e2d51e..d5a26c627123899a956158dbf2fc00c1ba579074 100644 (file)
@@ -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;
index 3846c2247e264ddb6107b554f5c1c30718f2dc80..55412b182693415bf8af2cdecec1e7a37571f8ce 100644 (file)
@@ -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;i<aVars.length();i++ ) {
-      anInputParams += aStudy->IsVariable(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;i<aVars.length();i++ ) {
+    anInputParams += aStudy->IsVariable(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")) {
index 0b3659fb95b9133ec41de08032a5c608532c926c..f7da16dcecb619a34650d1eb2153bb76314e319d 100644 (file)
@@ -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;
 }
index c5acc6a466535d0f278844125fee8cce4e4c5c2f..fe43813912aed3fa8aca03a4043ac7b10f68e651 100644 (file)
@@ -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();
+}
index 6d0f5e47fcc297257bddbcb0103fe32a0b4d68ef..05c8789ee3f6607bf7dd7d8b7f7bde6cfc60e61d 100644 (file)
@@ -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<int, SMESH_subMesh_i*> _mapSubMesh_i; //NRI
   std::map<int, ::SMESH_subMesh*> _mapSubMesh;   //NRI
 
index ffdb9b114350a9f1558be18b0062621be5871965..b540a88da4465f928377767d4ff7e48ad97b2118 100644 (file)
@@ -23,6 +23,7 @@
 #include "SMESH_2smeshpy.hxx"
 #include "SMESH_NoteBook.hxx"
 #include "SMESH_Gen_i.hxx"
+#include "SMESH_PythonDump.hxx"
 
 #include <Resource_DataMapOfAsciiStringAsciiString.hxx>
 #include <TColStd_SequenceOfAsciiString.hxx>
@@ -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 : "<<aStates->GetObjectType()<<endl;
     if(aStates->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();
   }
   
index e11f3bd5cc036f48c4c52f316fc01e76847c78bd..0eef2063d590af5064239c27e64c85c1972c83d8 100644 (file)
@@ -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
index cf62433791f534605581b0114eab0660e5c8d45d..980126d96fc32f92ebcd9e598a037b8a5fa9de90 100644 (file)
@@ -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