Salome HOME
0021375: EDF 1671 SMESH: Dump study of current state
[modules/smesh.git] / src / SMESH_I / SMESH_2smeshpy.cxx
index 30e9a7348f9d20f2993c94f6db2e19d91fb4b18d..c8fe9b6abea9ba8dbc92ee6e5c43778a3611ac2a 100644 (file)
@@ -544,7 +544,9 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand
       if ( -1 < iGeom && iGeom < SMESH::Geom_POLYHEDRA+1 )
         Threshold = SMESH + types[ iGeom ];
     }
-    if ( ThresholdStr.Length() != 2 ) // not '' or ""
+    if ( ThresholdID.Length() != 2 && ThresholdStr.Length() != 2) // not '' or ""
+      aCommand->SetArg( 4, ThresholdID.SubString( 2, ThresholdID.Length()-1 )); // shape entry
+    else if ( ThresholdStr.Length() != 2 )
       aCommand->SetArg( 4, ThresholdStr );
     else if ( ThresholdID.Length() != 2 )
       aCommand->SetArg( 4, ThresholdID );
@@ -1547,6 +1549,10 @@ void _pyMesh::Flush()
         algo = newAlgo;
         // set algorithm creation
         theGen->SetCommandBefore( newCmd, addCmd );
+        myHypos.push_back( newAlgo );
+        if ( !myLastComputeCmd.IsNull() &&
+             newCmd->GetOrderNb() == myLastComputeCmd->GetOrderNb() + 1)
+          newAlgo->MeshComputed( myLastComputeCmd );
       }
       else
         newCmd->Clear();
@@ -1802,19 +1808,36 @@ void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand)
     if( pos != -1)
     {
       isPyMeshMethod = true;
+      bool is0DmethId  = ( method == "ExtrusionSweepMakeGroups0D" );
+      bool is0DmethObj = ( method == "ExtrusionSweepObject0DMakeGroups");
 
       // 1. Remove "MakeGroups" from the Command
       TCollection_AsciiString aMethod = theCommand->GetMethod();
       int nbArgsToAdd = diffLastTwoArgsMethods.Contains(aMethod) ? 2 : 1;
+      
+      if(is0DmethObj)
+        pos = pos-2;  //Remove "0D" from the Command too
       aMethod.Trunc(pos-1);
       theCommand->SetMethod(aMethod);
 
       // 2. And add last "True" argument(s)
       while(nbArgsToAdd--)
         theCommand->SetArg(theCommand->GetNbArgs()+1,"True");
+      if( is0DmethId || is0DmethObj )
+        theCommand->SetArg(theCommand->GetNbArgs()+1,"True");
     }
   }
 
+  // ExtrusionSweep0D() -> ExtrusionSweep()
+  // ExtrusionSweepObject0D() -> ExtrusionSweepObject()
+  if ( !isPyMeshMethod && ( method == "ExtrusionSweep0D"  ||
+                            method == "ExtrusionSweepObject0D" ))
+  {
+    isPyMeshMethod=true;
+    theCommand->SetMethod( method.SubString( 1, method.Length()-2));
+    theCommand->SetArg(theCommand->GetNbArgs()+1,"False");  //sets flag "MakeGroups = False"
+    theCommand->SetArg(theCommand->GetNbArgs()+1,"True");  //sets flag "IsNode = True"
+  }
   // set "ExtrusionAlongPathX()" instead of "ExtrusionAlongPathObjX()"
   if ( !isPyMeshMethod && method == "ExtrusionAlongPathObjX")
   {
@@ -2265,7 +2288,8 @@ bool _pyHypothesis::Addition2Creation( const Handle(_pyCommand)& theCmd,
 void _pyHypothesis::Process( const Handle(_pyCommand)& theCommand)
 {
   ASSERT( !myIsAlgo );
-  rememberCmdOfParameter( theCommand );
+  if ( !theGen->IsToKeepAllCommands() )
+    rememberCmdOfParameter( theCommand );
   // set args
   int nbArgs = 0;
   for ( int i = 1; i <= myArgMethods.Length(); ++i ) {
@@ -2290,9 +2314,8 @@ void _pyHypothesis::Process( const Handle(_pyCommand)& theCommand)
 
 void _pyHypothesis::Flush()
 {
-  if ( IsWrapped() ) {
-  }
-  else {
+  if ( !IsAlgo() )
+  {
     list < Handle(_pyCommand) >::iterator cmd = myArgCommands.begin();
     for ( ; cmd != myArgCommands.end(); ++cmd ) {
       // Add access to a wrapped mesh
@@ -2381,34 +2404,34 @@ bool _pyHypothesis::CanClear()
 
 void _pyHypothesis::ClearCommands()
 {
-  if ( !theGen->IsToKeepAllCommands() )
-  {
-    bool isUsed = false;
-    int lastComputeOrder = 0;
-    list<Handle(_pyCommand) >::iterator cmd = myComputeCmds.begin();
-    for ( ; cmd != myComputeCmds.end(); ++cmd )
-      if ( ! (*cmd)->IsEmpty() )
-      {
-        isUsed = true;
-        if ( (*cmd)->GetOrderNb() > lastComputeOrder )
-          lastComputeOrder = (*cmd)->GetOrderNb();
-      }
-    if ( !isUsed )
-    {
-      SetRemovedFromStudy( true );
-    }
-    else
-    {
-      // clear my commands invoked after lastComputeOrder
-      map<TCollection_AsciiString, list< Handle(_pyCommand) > >::iterator m2c;
-      for ( m2c = myMeth2Commands.begin(); m2c != myMeth2Commands.end(); ++m2c )
-      {
-        list< Handle(_pyCommand)> & cmds = m2c->second;
-        if ( !cmds.empty() && cmds.back()->GetOrderNb() > lastComputeOrder )
-          cmds.back()->Clear();
-      }
-    }
-  }
+  // if ( !theGen->IsToKeepAllCommands() )
+  // {
+  //   bool isUsed = false;
+  //   int lastComputeOrder = 0;
+  //   list<Handle(_pyCommand) >::iterator cmd = myComputeCmds.begin();
+  //   for ( ; cmd != myComputeCmds.end(); ++cmd )
+  //     if ( ! (*cmd)->IsEmpty() )
+  //     {
+  //       isUsed = true;
+  //       if ( (*cmd)->GetOrderNb() > lastComputeOrder )
+  //         lastComputeOrder = (*cmd)->GetOrderNb();
+  //     }
+  //   if ( !isUsed )
+  //   {
+  //     SetRemovedFromStudy( true );
+  //   }
+  //   else
+  //   {
+  //     // clear my commands invoked after lastComputeOrder
+  //     // map<TCollection_AsciiString, list< Handle(_pyCommand) > >::iterator m2c;
+  //     // for ( m2c = myMeth2Commands.begin(); m2c != myMeth2Commands.end(); ++m2c )
+  //     // {
+  //     //   list< Handle(_pyCommand)> & cmds = m2c->second;
+  //     //   if ( !cmds.empty() && cmds.back()->GetOrderNb() > lastComputeOrder )
+  //     //     cmds.back()->Clear();
+  //     // }
+  //   }
+  // }
   _pyObject::ClearCommands();
 }
 
@@ -2465,23 +2488,35 @@ bool _pyHypothesis::GetReferredMeshesAndGeom( list< Handle(_pyMesh) >& meshes )
 
 void _pyHypothesis::rememberCmdOfParameter( const Handle(_pyCommand) & theCommand )
 {
-  // not to clear commands setting different parameters via one method
+  // parameters are discriminated by method name
+  TCollection_AsciiString method = theCommand->GetMethod();
+
+  // discriminate commands setting different parameters via one method
   // by passing parameter names like e.g. SetOption("size", "0.2")
-  int quotePos = theCommand->GetString().FirstLocationInSet( "'\"", 1, theCommand->Length() );
-  if ( !quotePos )
+  if ( theCommand->GetString().FirstLocationInSet( "'\"", 1, theCommand->Length() ) &&
+       theCommand->GetNbArgs() > 1 )
   {
-    // parameters are discriminated by method name
-    list< Handle(_pyCommand)>& cmds = myMeth2Commands[ theCommand->GetMethod() ];
-    if ( !cmds.empty() && !isCmdUsedForCompute( cmds.back() ))
-    {
-      cmds.back()->Clear(); // previous parameter value has not been used
-      cmds.back() = theCommand;
-    }
-    else
+    // mangle method by appending a 1st textual arg (what if it's a variable name?!!!)
+    for ( int iArg = 1; iArg <= theCommand->GetNbArgs(); ++iArg )
     {
-      cmds.push_back( theCommand );
+      const TCollection_AsciiString& arg = theCommand->GetArg( iArg );
+      if ( arg.Value(1) != '\"' && arg.Value(1) != '\'' ) continue;
+      if ( !isalpha( arg.Value(2))) continue;
+      method += arg;
+      break;
     }
   }
+  // parameters are discriminated by method name
+  list< Handle(_pyCommand)>& cmds = myMeth2Commands[ theCommand->GetMethod() ];
+  if ( !cmds.empty() && !isCmdUsedForCompute( cmds.back() ))
+  {
+    cmds.back()->Clear(); // previous parameter value has not been used
+    cmds.back() = theCommand;
+  }
+  else
+  {
+    cmds.push_back( theCommand );
+  }
 }
 
 //================================================================================
@@ -2968,12 +3003,12 @@ const TCollection_AsciiString & _pyCommand::GetResultValue()
     if ( endPos )
     {
       begPos = 1;
-      while ( begPos < endPos && isblank( myString.Value( begPos ))) ++begPos;
+      while ( begPos < endPos && isspace( myString.Value( begPos ))) ++begPos;
       if ( begPos < endPos )
       {
         SetBegPos( RESULT_IND, begPos );
         --endPos;
-        while ( begPos < endPos && isblank( myString.Value( endPos ))) --endPos;
+        while ( begPos < endPos && isspace( myString.Value( endPos ))) --endPos;
         myRes = myString.SubString( begPos, endPos );
       }
     }
@@ -3445,7 +3480,7 @@ void _pyCommand::Comment()
   if ( IsEmpty() ) return;
 
   int i = 1;
-  while ( i <= Length() && isblank( myString.Value(i) )) ++i;
+  while ( i <= Length() && isspace( myString.Value(i) )) ++i;
   if ( i <= Length() )
   {
     myString.Insert( i, "#" );