Salome HOME
PAL13073 (Submesh hypothesises do not work for NETGEN 1D-2D-3D)
authoreap <eap@opencascade.com>
Fri, 19 Jan 2007 14:43:59 +0000 (14:43 +0000)
committereap <eap@opencascade.com>
Fri, 19 Jan 2007 14:43:59 +0000 (14:43 +0000)
        add _pyCommand::GetIndentation() and addErrorTreatmentCmd()
        used to show status of not wrapped AddHypothesis() command

src/SMESH_I/SMESH_2smeshpy.cxx
src/SMESH_I/SMESH_2smeshpy.hxx

index e232506b6b15e6d9f71183066b84909b12d12b8b..b06a856246e62d79206cb5f9c2d3d1332e5dde9d 100644 (file)
@@ -153,7 +153,7 @@ _pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod
  */
 //================================================================================
 
-void _pyGen::AddCommand( const TCollection_AsciiString& theCommand)
+Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand)
 {
   // store theCommand in the sequence
   myCommands.push_back( new _pyCommand( theCommand, ++myNbCommands ));
@@ -166,25 +166,25 @@ void _pyGen::AddCommand( const TCollection_AsciiString& theCommand)
   _pyID objID = aCommand->GetObject();
 
   if ( objID.IsEmpty() )
-    return;
+    return aCommand;
 
   // SMESH_Gen method?
   if ( objID == this->GetID() ) {
     this->Process( aCommand );
-    return;
+    return aCommand;
   }
   // SMESH_Mesh method?
   map< _pyID, Handle(_pyMesh) >::iterator id_mesh = myMeshes.find( objID );
   if ( id_mesh != myMeshes.end() ) {
     id_mesh->second->Process( aCommand );
-    return;
+    return aCommand;
   }
   // SMESH_Hypothesis method?
   list< Handle(_pyHypothesis) >::iterator hyp = myHypos.begin();
   for ( ; hyp != myHypos.end(); ++hyp )
     if ( !(*hyp)->IsAlgo() && objID == (*hyp)->GetID() ) {
       (*hyp)->Process( aCommand );
-      return;
+      return aCommand;
     }
 
   // Add access to a wrapped mesh
@@ -211,6 +211,7 @@ void _pyGen::AddCommand( const TCollection_AsciiString& theCommand)
       aCommand->GetString() += tmpCmd.GetString();
     }
   }
+  return aCommand;
 }
 
 //================================================================================
@@ -617,6 +618,36 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
   }
 }
 
+namespace {
+
+  //================================================================================
+  /*!
+   * \brief add addition result treatement command
+    * \param addCmd - hypothesis addition command
+   */
+  //================================================================================
+
+  void addErrorTreatmentCmd( Handle(_pyCommand) & addCmd,
+                             const bool           isAlgo)
+  {
+    // addCmd: status = mesh.AddHypothesis( geom, hypo )
+    // treatement command:
+    //    def TreatHypoStatus(status, hypName, geomName, isAlgo):
+    TCollection_AsciiString status = addCmd->GetResultValue();
+    if ( !status.IsEmpty() ) {
+      const _pyID& geomID = addCmd->GetArg( 1 );
+      const _pyID& hypoID = addCmd->GetArg( 2 );
+      TCollection_AsciiString cmdStr = addCmd->GetIndentation() +
+        SMESH_2smeshpy::SmeshpyName() + ".TreatHypoStatus( " + status + ", " +
+        SMESH_2smeshpy::SmeshpyName() + ".GetName(" + hypoID + "), " +
+        SMESH_2smeshpy::SmeshpyName() + ".GetName(" + geomID + "), " +
+        (char*)( isAlgo ? "True" : "False" ) + " )";
+      Handle(_pyCommand) cmd = theGen->AddCommand( cmdStr );
+      addCmd->AddDependantCmd( cmd );
+    }
+  }
+}
+
 //================================================================================
 /*!
  * \brief Convert creation and addition of all algos and hypos
@@ -666,6 +697,8 @@ void _pyMesh::Flush()
       // mesh.GetMesh().AddHypothesis(geom, ALGO ) ->
       // mesh.GetMesh().AddHypothesis(geom, ALGO.GetAlgorithm() )
       addCmd->SetArg( 2, addCmd->GetArg( 2 ) + ".GetAlgorithm()" );
+      // add addition result treatement cmd
+      addErrorTreatmentCmd( addCmd, true );
     }
   }
 
@@ -690,6 +723,8 @@ void _pyMesh::Flush()
     else
     {
       AddMeshAccess( addCmd );
+      // add addition result treatement cmd
+      addErrorTreatmentCmd( addCmd, false );
     }
   }
 
@@ -1293,6 +1328,23 @@ void _pyCommand::SetBegPos( int thePartIndex, int thePosition )
   myBegPos( thePartIndex ) = thePosition;
 }
 
+//================================================================================
+/*!
+ * \brief Returns whitespace symbols at the line beginning
+  * \retval TCollection_AsciiString - result
+ */
+//================================================================================
+
+TCollection_AsciiString _pyCommand::GetIndentation()
+{
+  int end = 1;
+  if ( GetBegPos( RESULT_IND ) == UNKNOWN )
+    GetWord( myString, end, true );
+  else
+    end = GetBegPos( RESULT_IND );
+  return myString.SubString( 1, end - 1 );
+}
+
 //================================================================================
 /*!
  * \brief Return substring of python command looking like ResultValue = Obj.Meth()
index f5717cd2a386538862b3c5e4d42572d33de00829..3443ed791a3a2d1d85d453c71519084b8246d48b 100644 (file)
@@ -131,6 +131,7 @@ public:
   int Length() { return myString.Length(); }
   void Clear() { myString.Clear(); myBegPos.Clear(); }
   bool IsEmpty() const { return myString.IsEmpty(); }
+  TCollection_AsciiString GetIndentation();
   const TCollection_AsciiString & GetResultValue();
   const TCollection_AsciiString & GetObject();
   const TCollection_AsciiString & GetMethod();
@@ -191,7 +192,7 @@ class _pyGen: public _pyObject
 public:
   _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod);
   //~_pyGen();
-  void AddCommand( const TCollection_AsciiString& theCommand );
+  Handle(_pyCommand) AddCommand( const TCollection_AsciiString& theCommand );
   void Process( const Handle(_pyCommand)& theCommand );
   void Flush();
   Handle(_pyHypothesis) FindHyp( const _pyID& theHypID );