Salome HOME
0021014: EDF 1583 SMESH: Improvement of the Python Dump for the creation of groups
authoreap <eap@opencascade.com>
Wed, 12 Oct 2011 18:06:28 +0000 (18:06 +0000)
committereap <eap@opencascade.com>
Wed, 12 Oct 2011 18:06:28 +0000 (18:06 +0000)
   set a more human readable name to the filter

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

index af9123b210aae038ffbd085318238e6bec9941d8..ccbbf50d532da285f32b4d05ced14d719a16d3cc 100644 (file)
@@ -204,10 +204,11 @@ SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript,
 _pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
                Resource_DataMapOfAsciiStringAsciiString& theObjectNames)
   : _pyObject( new _pyCommand( TPythonDump::SMESHGenName(), 0 )),
+    myNbCommands( 0 ),
     myID2AccessorMethod( theEntry2AccessorMethod ),
-    myObjectNames( theObjectNames )
+    myObjectNames( theObjectNames ),
+    myNbFilters( 0 )
 {
-  myNbCommands = 0;
   // make that GetID() to return TPythonDump::SMESHGenName()
   GetCreationCmd()->GetString() += "=";
 }
@@ -309,7 +310,14 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand
   // aFilterManager.CreateFilter() ?
   if ( aCommand->GetMethod() == "CreateFilter" )
   {
-    Handle(_pyObject) filter( new _pyFilter( aCommand ));
+    // Set a more human readable name to a filter
+    // aFilter0x7fbf6c71cfb0 -> aFilter_nb
+    _pyID newID, filterID = aCommand->GetResultValue();
+    int pos = filterID.Search( "0x" );
+    if ( pos > 1 )
+      newID = (filterID.SubString(1,pos-1) + "_") + _pyID( ++myNbFilters );
+
+    Handle(_pyObject) filter( new _pyFilter( aCommand, newID ));
     AddObject( filter );
   }
 
@@ -1585,6 +1593,9 @@ Handle(_pyHypothesis) _pyHypothesis::NewHypothesis( const Handle(_pyCommand)& th
   else if ( hypType == "Projection_2D" ) {
     algo->SetConvMethodAndType( "Projection2D", hypType.ToCString());
   }
+  else if ( hypType == "Projection_1D2D" ) {
+    algo->SetConvMethodAndType( "Projection1D2D", hypType.ToCString());
+  }
   else if ( hypType == "ProjectionSource2D" ) {
     hyp->SetConvMethodAndType( "SourceFace", "Projection_2D");
     hyp->AddArgMethod( "SetSourceFace");
@@ -2745,6 +2756,17 @@ void _pyGroup::Process( const Handle(_pyCommand)& theCommand)
   }
 }
 
+//================================================================================
+/*!
+ * \brief Constructor of _pyFilter
+ */
+//================================================================================
+
+_pyFilter::_pyFilter(const Handle(_pyCommand)& theCreationCmd, const _pyID& newID/*=""*/)
+  :_pyObject(theCreationCmd), myNewID( newID )
+{
+}
+
 //================================================================================
 /*!
  * \brief To convert creation of a filter by criteria
@@ -2753,6 +2775,9 @@ void _pyGroup::Process( const Handle(_pyCommand)& theCommand)
 
 void _pyFilter::Process( const Handle(_pyCommand)& theCommand)
 {
+  if ( !myNewID.IsEmpty() )
+    theCommand->SetObject( myNewID );
+
   // Convert the following set of commands into smesh.GetFilterFromCriteria(criteria)
   // aFilter0x2aaab0487080 = aFilterManager.CreateFilter()
   // aFilter0x2aaab0487080.SetCriteria(aCriteria)
@@ -2761,7 +2786,10 @@ void _pyFilter::Process( const Handle(_pyCommand)& theCommand)
   {
     // aFilter.SetCriteria(aCriteria) ->
     // aFilter = smesh.GetFilterFromCriteria(criteria)
-    theCommand->SetResultValue( GetID() );
+    if ( myNewID.IsEmpty() )
+      theCommand->SetResultValue( GetID() );
+    else
+      theCommand->SetResultValue( myNewID );
     theCommand->SetObject( SMESH_2smeshpy::GenName() );
     theCommand->SetMethod( "GetFilterFromCriteria" );
 
@@ -2773,3 +2801,15 @@ void _pyFilter::Process( const Handle(_pyCommand)& theCommand)
     theGen->AddMeshAccessorMethod( theCommand );
   }
 }
+
+//================================================================================
+/*!
+ * \brief Set new filter name to the creation command
+ */
+//================================================================================
+
+void _pyFilter::Flush()
+{
+  if ( !myNewID.IsEmpty() && GetCreationCmd()->IsEmpty() )
+    GetCreationCmd()->SetResultValue( myNewID );
+}
index fc787123aa5c2cc95f939aedd87afdefa9b7ec88..53cf02949f1c00c8b2b9a8e940fc0da75d9c50dd 100644 (file)
@@ -215,6 +215,7 @@ private:
   Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
   Resource_DataMapOfAsciiStringAsciiString& myObjectNames;
   Handle(_pyCommand)                       myLastCommand;
+  int                                      myNbFilters;
 
   DEFINE_STANDARD_RTTI (_pyGen)
 };
@@ -470,10 +471,11 @@ DEFINE_STANDARD_HANDLE (_pyGroup, _pyObject);
 // -------------------------------------------------------------------------------------
 class _pyFilter:  public _pyObject
 {
+  _pyID myNewID;
 public:
-  _pyFilter(const Handle(_pyCommand)& theCreationCmd):_pyObject(theCreationCmd) {}
+  _pyFilter(const Handle(_pyCommand)& theCreationCmd, const _pyID& newID="");
   void Process( const Handle(_pyCommand)& theCommand);
-  virtual void Flush() {}
+  virtual void Flush();
 
   DEFINE_STANDARD_RTTI (_pyFilter)
 };