Salome HOME
NPAL16716. Compound: To create the groups of initial meshes.
[modules/smesh.git] / src / SMESH_I / SMESH_2smeshpy.cxx
index 998266806c6a5fb5cbf932c74eafd54a1259bb70..c9d70e0bf315b236e860f33e6dd4314d11dc1e28 100644 (file)
@@ -81,6 +81,7 @@ static TCollection_AsciiString theEmptyString;
 #undef DUMP_CONVERSION
 #endif
 
 #undef DUMP_CONVERSION
 #endif
 
+
 namespace {
 
   //================================================================================
 namespace {
 
   //================================================================================
@@ -250,7 +251,7 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand
   AddMeshAccessorMethod( aCommand );
 
   // Add access to a wrapped algorithm
   AddMeshAccessorMethod( aCommand );
 
   // Add access to a wrapped algorithm
-  AddAlgoAccessorMethod( aCommand ); // ??? what if algo won't be wrapped at all ???
+  //  AddAlgoAccessorMethod( aCommand ); // ??? what if algo won't be wrapped at all ???
 
   // PAL12227. PythonDump was not updated at proper time; result is
   //     aCriteria.append(SMESH.Filter.Criterion(17,26,0,'L1',26,25,1e-07,SMESH.EDGE,-1))
 
   // PAL12227. PythonDump was not updated at proper time; result is
   //     aCriteria.append(SMESH.Filter.Criterion(17,26,0,'L1',26,25,1e-07,SMESH.EDGE,-1))
@@ -287,16 +288,26 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand )
   // Concatenate( [mesh1, ...], ... )
   // CreateHypothesis( theHypType, theLibName )
   // Compute( mesh, geom )
   // Concatenate( [mesh1, ...], ... )
   // CreateHypothesis( theHypType, theLibName )
   // Compute( mesh, geom )
-
   // mesh creation
   if ( theCommand->GetMethod() == "CreateMesh" ||
   // mesh creation
   if ( theCommand->GetMethod() == "CreateMesh" ||
-       theCommand->GetMethod() == "CreateEmptyMesh" )
+       theCommand->GetMethod() == "CreateEmptyMesh" ||
+       theCommand->GetMethod() == "CreateMeshesFromUNV" ||
+       theCommand->GetMethod() == "CreateMeshesFromSTL")
   {
     Handle(_pyMesh) mesh = new _pyMesh( theCommand );
     myMeshes.insert( make_pair( mesh->GetID(), mesh ));
     return;
   }
 
   {
     Handle(_pyMesh) mesh = new _pyMesh( theCommand );
     myMeshes.insert( make_pair( mesh->GetID(), mesh ));
     return;
   }
 
+  if(theCommand->GetMethod() == "CreateMeshesFromMED")
+  {
+    for(int ind = 0;ind<theCommand->GetNbResultValues();ind++)
+    {
+      Handle(_pyMesh) mesh = new _pyMesh( theCommand, theCommand->GetResultValue(ind));
+      myMeshes.insert( make_pair( theCommand->GetResultValue(ind), mesh ));     
+    }
+  }
+
   // CreateHypothesis()
   if ( theCommand->GetMethod() == "CreateHypothesis" )
   {
   // CreateHypothesis()
   if ( theCommand->GetMethod() == "CreateHypothesis" )
   {
@@ -327,7 +338,8 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand )
   }
 
   // Concatenate( [mesh1, ...], ... )
   }
 
   // Concatenate( [mesh1, ...], ... )
-  if ( theCommand->GetMethod() == "Concatenate" )
+  if ( theCommand->GetMethod() == "Concatenate" ||
+       theCommand->GetMethod() == "ConcatenateWithGroups")
   {
     AddMeshAccessorMethod( theCommand );
   }
   {
     AddMeshAccessorMethod( theCommand );
   }
@@ -376,7 +388,7 @@ void _pyGen::Flush()
 
 //================================================================================
 /*!
 
 //================================================================================
 /*!
- * \brief Add access method to mesh that is an object or an argument
+ * \brief Add access method to mesh that is an argument
   * \param theCmd - command to add access method
   * \retval bool - true if added
  */
   * \param theCmd - command to add access method
   * \retval bool - true if added
  */
@@ -589,12 +601,32 @@ _pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd):
 {
   // convert my creation command
   Handle(_pyCommand) creationCmd = GetCreationCmd();
 {
   // convert my creation command
   Handle(_pyCommand) creationCmd = GetCreationCmd();
-  creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() );
-  creationCmd->SetMethod( "Mesh" );
+  TCollection_AsciiString str = creationCmd->GetMethod();
+  
+  creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() ); 
+  if(str != "CreateMeshesFromUNV" &&
+     str != "CreateMeshesFromMED" &&
+     str != "CreateMeshesFromSTL")
+    creationCmd->SetMethod( "Mesh" );
 
   theGen->SetAccessorMethod( GetID(), "GetMesh()" );
 }
 
 
   theGen->SetAccessorMethod( GetID(), "GetMesh()" );
 }
 
+//================================================================================
+/*!
+ * \brief 
+  * \param theCreationCmd - 
+ */
+//================================================================================
+_pyMesh::_pyMesh(const Handle(_pyCommand) theCreationCmd, const TCollection_AsciiString& id):
+  _pyObject(theCreationCmd), myHasEditor(false)
+{
+  // convert my creation command
+  Handle(_pyCommand) creationCmd = GetCreationCmd();
+  creationCmd->SetObject( SMESH_2smeshpy::SmeshpyName() ); 
+  theGen->SetAccessorMethod( id, "GetMesh()" );
+}
+
 //================================================================================
 /*!
  * \brief Convert a IDL API command of SMESH::Mesh to a method call of python Mesh
 //================================================================================
 /*!
  * \brief Convert a IDL API command of SMESH::Mesh to a method call of python Mesh
@@ -676,7 +708,7 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
       }
     }
     Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
       }
     }
     Handle(_pyHypothesis) hyp = theGen->FindHyp( hypID );
-    if ( ! hasAddCmd ) { // hypo addition already wrapped
+    if ( ! hasAddCmd && hypID.Length() != 0 ) { // hypo addition already wrapped
       // RemoveHypothesis(geom, hyp) --> RemoveHypothesis( hyp, geom=0 )
       _pyID geom = theCommand->GetArg( 1 );
       theCommand->RemoveArgs();
       // RemoveHypothesis(geom, hyp) --> RemoveHypothesis( hyp, geom=0 )
       _pyID geom = theCommand->GetArg( 1 );
       theCommand->RemoveArgs();
@@ -720,7 +752,7 @@ bool _pyMesh::NeedMeshAccess( const Handle(_pyCommand)& theCommand )
         "GetSubMeshElementsId","GetSubMeshNodesId","GetSubMeshElementType","Dump","GetNodeXYZ",
         "GetNodeInverseElements","GetShapeID","GetShapeIDForElem","GetElemNbNodes",
         "GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces",
         "GetSubMeshElementsId","GetSubMeshNodesId","GetSubMeshElementType","Dump","GetNodeXYZ",
         "GetNodeInverseElements","GetShapeID","GetShapeIDForElem","GetElemNbNodes",
         "GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces",
-        "IsPoly","IsQuadratic","BaryCenter","GetHypothesisList",
+        "IsPoly","IsQuadratic","BaryCenter","GetHypothesisList", "SetAutoColor", "GetAutoColor",
         "" }; // <- mark of end
     sameMethods.Insert( names );
   }
         "" }; // <- mark of end
     sameMethods.Insert( names );
   }
@@ -854,12 +886,20 @@ void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand)
       "MergeElements","MergeEqualElements","SewFreeBorders","SewConformFreeBorders",
       "SewBorderToSide","SewSideElements","ChangeElemNodes","GetLastCreatedNodes",
       "GetLastCreatedElems",
       "MergeElements","MergeEqualElements","SewFreeBorders","SewConformFreeBorders",
       "SewBorderToSide","SewSideElements","ChangeElemNodes","GetLastCreatedNodes",
       "GetLastCreatedElems",
-      "" }; // <- mark of end
+      "MirrorMakeMesh","MirrorObjectMakeMesh","TranslateMakeMesh",
+      "TranslateObjectMakeMesh","RotateMakeMesh","RotateObjectMakeMesh",
+      "" }; // <- mark of the end
     sameMethods.Insert( names );
   }
     sameMethods.Insert( names );
   }
+  //theGen->AddMeshAccessorMethod( theCommand ); // for *Object()
 
   if ( sameMethods.Contains( theCommand->GetMethod() )) {
     theCommand->SetObject( myMesh );
 
   if ( sameMethods.Contains( theCommand->GetMethod() )) {
     theCommand->SetObject( myMesh );
+
+    // meshes made by *MakeMesh() methods are not wrapped by _pyMesh,
+    // so let _pyMesh care of it (TMP?)
+    if ( theCommand->GetMethod().Search("MakeMesh") != -1 )
+      _pyMesh( new _pyCommand( theCommand->GetString(), 0 )); // for theGen->SetAccessorMethod()
   }
   else {
     // editor creation command is needed only if any editor function is called
   }
   else {
     // editor creation command is needed only if any editor function is called
@@ -1562,6 +1602,54 @@ const TCollection_AsciiString & _pyCommand::GetResultValue()
   return myRes;
 }
 
   return myRes;
 }
 
+//================================================================================
+/*!
+ * \brief Return number of python command result value ResultValue = Obj.Meth()
+  * \retval const int
+ */
+//================================================================================
+
+const int _pyCommand::GetNbResultValues()
+{
+  int begPos = 1;
+  int Nb=0;
+  int endPos = myString.Location( "=", 1, Length() );
+  TCollection_AsciiString str = "";
+  while ( begPos < endPos) {
+    str = GetWord( myString, begPos, true );
+    begPos = begPos+ str.Length();
+    Nb++;
+  }
+  return (Nb-1);
+}
+
+
+//================================================================================
+/*!
+ * \brief Return substring of python command looking like
+ *  ResultValue1 , ResultValue1,... = Obj.Meth() with res index
+ * \retval const TCollection_AsciiString & - ResultValue with res index substring
+ */
+//================================================================================
+const TCollection_AsciiString & _pyCommand::GetResultValue(int res)
+{
+  int begPos = 1;
+  int Nb=0;
+  int endPos = myString.Location( "=", 1, Length() );
+  while ( begPos < endPos) {
+    myRes = GetWord( myString, begPos, true );
+    begPos = begPos + myRes.Length();
+    Nb++;
+    if(res == Nb){
+      myRes.RemoveAll('[');myRes.RemoveAll(']');
+      return myRes;
+    }
+    if(Nb>res)
+      break;
+  }
+  return theEmptyString;
+}
+
 //================================================================================
 /*!
  * \brief Return substring of python command looking like ResVal = Object.Meth()
 //================================================================================
 /*!
  * \brief Return substring of python command looking like ResVal = Object.Meth()