Salome HOME
Fix some bugs.
[modules/smesh.git] / src / SMESH_I / SMESH_NoteBook.cxx
index 3fa2d29d0542336a5494622195e10c99cf8639f5..ac3ae0c152a29c3cc10b9c56e718277b0f5ea948 100644 (file)
@@ -33,9 +33,9 @@
 #include <string>
 
 #ifdef _DEBUG_
-static int MYDEBUG = 1;
+static int MYDEBUG = 0;
 #else
-static int MYDEBUG = 1;
+static int MYDEBUG = 0;
 #endif
 
 using namespace std;
@@ -242,7 +242,7 @@ void SMESH_NoteBook::ReplaceVariables()
       }
     }
     
-    if(it != _objectMap.end() && !aMethod.IsEmpty()) {
+    if(it != _objectMap.end()) {
       ObjectStates *aStates = (*it).second;
       // Case for LocalLength hypothesis
       if(aStates->GetObjectType().IsEqual("LocalLength") && aStates->GetCurrectState().size() >= 2) {
@@ -307,6 +307,65 @@ void SMESH_NoteBook::ReplaceVariables()
         }
       }
 
+      // Case for MaxElementVolume hypothesis
+      else if(aStates->GetObjectType().IsEqual("MaxElementVolume")){
+        if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 1) {
+          if(!aStates->GetCurrectState().at(0).IsEmpty() )
+            aCmd->SetArg(1,aStates->GetCurrectState().at(0));
+          aStates->IncrementState();
+        }
+      }
+
+      // Case for NETGEN_Parameters_2D or NETGEN_Parameters_2D hypothesis
+      else if(aStates->GetObjectType().IsEqual("NETGEN_Parameters_2D") ||
+              aStates->GetObjectType().IsEqual("NETGEN_Parameters")){
+        if(aMethod == "SetMaxSize" && aStates->GetCurrectState().size() >= 1) {
+          if(!aStates->GetCurrectState().at(0).IsEmpty() )
+            aCmd->SetArg(1,aStates->GetCurrectState().at(0));
+          aStates->IncrementState();
+        }
+        else if(aMethod == "SetGrowthRate" && aStates->GetCurrectState().size() >= 2) {
+          if(!aStates->GetCurrectState().at(1).IsEmpty() )
+            aCmd->SetArg(1,aStates->GetCurrectState().at(1));
+          aStates->IncrementState();
+        }
+        else if(aMethod == "SetNbSegPerEdge" && aStates->GetCurrectState().size() >= 3) {
+          if(!aStates->GetCurrectState().at(2).IsEmpty() )
+            aCmd->SetArg(1,aStates->GetCurrectState().at(2));
+          aStates->IncrementState();
+        } 
+        else if(aMethod == "SetNbSegPerRadius" && aStates->GetCurrectState().size() >= 4) {
+          if(!aStates->GetCurrectState().at(3).IsEmpty() )
+            aCmd->SetArg(1,aStates->GetCurrectState().at(3));
+          aStates->IncrementState();
+        } 
+      }
+
+      // Case for NETGEN_SimpleParameters_3D or NETGEN_SimpleParameters_2D hypothesis
+      else if(aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_3D") ||
+              aStates->GetObjectType().IsEqual("NETGEN_SimpleParameters_2D")){
+
+        if((aMethod == "SetNumberOfSegments" || aMethod == "SetLocalLength") && 
+           aStates->GetCurrectState().size() >= 1) {
+          if(!aStates->GetCurrectState().at(0).IsEmpty() )
+            aCmd->SetArg(1,aStates->GetCurrectState().at(0));
+          aStates->IncrementState();
+        }
+        else if(aMethod == "SetMaxElementArea" && aStates->GetCurrectState().size() >= 2) {
+          if(!aStates->GetCurrectState().at(1).IsEmpty() )
+            aCmd->SetArg(1,aStates->GetCurrectState().at(1));
+          aStates->IncrementState();
+        }
+        else if(aMethod == "SetMaxElementVolume" && aStates->GetCurrectState().size() >= 3) {
+          if(!aStates->GetCurrectState().at(2).IsEmpty() )
+            aCmd->SetArg(1,aStates->GetCurrectState().at(2));
+          aStates->IncrementState();
+        }
+        else if(aMethod == "LengthFromEdges" || aMethod == "LengthFromFaces"){
+          aStates->IncrementState();
+        }
+      }
+      
       // Case for NumberOfLayers hypothesis
       else if(aStates->GetObjectType().IsEqual("NumberOfLayers")){
         if(aMethod == "SetNumberOfLayers" && aStates->GetCurrectState().size() >= 1) {
@@ -355,11 +414,39 @@ void SMESH_NoteBook::ReplaceVariables()
              }
            }
            else if(aCurrentStateSize == 6) { // translation by x1, x2, y1, y2, z1, z2
-             // TODO
+             // TODO: limitation until operations on the variables will be introduced
+             /*
+             isVariableFound = true;
+             for(int j = 0; j < 3; j++) {
+               TCollection_AsciiString anArg = aCmd->GetArg(anArgIndex+j);
+               TCollection_AsciiString aValue1 = aCurrentState.at(2*j), aValue2 = aCurrentState.at(2*j+1);
+               bool aV1 = !aValue1.IsEmpty();
+               bool aV2 = !aValue2.IsEmpty();
+               double aValue, aCurrentValue = anArg.IsRealValue() ? anArg.RealValue() : 0;
+               if(aV1 && !aV2) {
+                 if(!GetReal(aValue1, aValue))
+                   aValue = 0;
+                 aValue2 = TCollection_AsciiString( aValue + aCurrentValue );
+               }
+               else if(!aV1 && aV2) {
+                 if(!GetReal(aValue2, aValue))
+                   aValue = 0;
+                 aValue1 = TCollection_AsciiString( aValue - aCurrentValue );
+               }
+               else if(!aV1 && !aV2) {
+                 aValue1 = TCollection_AsciiString( 0 );
+                 aValue2 = TCollection_AsciiString( aCurrentValue );
+               }
+               aCmd->SetArg(anArgIndex+j, aValue1 + ", " + aValue2 );
+             }
+             */
            }
           }
           if(isVariableFound) {
-            aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
+            TCollection_AsciiString aDim;
+           if(aCurrentStateSize == 6)
+             aDim = "6";
+            aCmd->SetArg(anArgIndex - 1, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr"+aDim);
             aCmd->SetArg(anArgIndex - 2, TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".DirStructStr");
           }
           aStates->IncrementState();
@@ -367,9 +454,10 @@ void SMESH_NoteBook::ReplaceVariables()
        else if(aMethod.IsEqual("Rotate") ||
                aMethod.IsEqual("RotateMakeGroups") ||
                aMethod.IsEqual("RotateMakeMesh") ||
+               aMethod.IsEqual("RotationSweep") ||
+               aMethod.IsEqual("RotationSweepMakeGroups") ||
                aMethod.IsEqual("Mirror") ||
-               aMethod.IsEqual("MirrorMakeGroups") ||
-               aMethod.IsEqual("MirrorMakeMesh")) {
+               aMethod.IsEqual("MirrorMakeGroups")) {
          bool isSubstitute = false;
          int anArgIndex = 0;
          for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
@@ -381,7 +469,7 @@ void SMESH_NoteBook::ReplaceVariables()
          if(anArgIndex > 0) {
            for(int j = 0; j < aCurrentStateSize; j++) {
              if(!aCurrentState.at(j).IsEmpty()) {
-               if(j < 6) // from 0 to 5 - axis struct, 6 - angle
+               if(j < 6) // 0-5 - axis struct, 6 - angle (rotation & sweep), 7-8 - nbSteps and tolerance (sweep)
                  isSubstitute = true;
                aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
              }
@@ -419,7 +507,7 @@ void SMESH_NoteBook::ReplaceVariables()
          if(anArgIndex > 0) {
            for(int j = 0; j < aCurrentStateSize; j++) {
              if(!aCurrentState.at(j).IsEmpty()) {
-               if(j < 3) // from 0 to 2 - dir struct, 3 - number of steps
+               if(j < 3) // 0-2 - dir struct, 3 - number of steps
                  isSubstitute = true;
                aCmd->SetArg(anArgIndex+j, aCurrentState.at(j));
              }
@@ -431,6 +519,38 @@ void SMESH_NoteBook::ReplaceVariables()
          }
          aStates->IncrementState();
        }
+       else if(aMethod.IsEqual("ExtrusionAlongPath") ||
+               aMethod.IsEqual("ExtrusionAlongPathMakeGroups") ||
+               /* workaround for a bug in the command parsing algorithm */
+               aCmd->GetString().Search("ExtrusionAlongPathMakeGroups") != -1) {
+         int aNbAngles = aCurrentStateSize-3; // State looks like "Angle1:...:AngleN:X:Y:Z"
+         bool isSubstitute = false;
+         int anArgIndex = 0;
+         for(int i = 1, n = aCmd->GetNbArgs(); i <= n; i++) {
+           if(aCmd->GetArg(i).IsEqual("SMESH.PointStruct")) {
+             anArgIndex = i-1-aNbAngles;
+             break;
+           }
+         }
+         if(anArgIndex > 0) {
+           int j = 0;
+           for(; j < aNbAngles; j++) {
+             if(!aCurrentState.at(j).IsEmpty()) {
+               aCmd->SetArg(anArgIndex+j-1, aCurrentState.at(j));
+             }
+           }
+           for(; j < aNbAngles+3; j++) {
+             if(!aCurrentState.at(j).IsEmpty()) {
+               isSubstitute = true;
+               aCmd->SetArg(anArgIndex+j+2, aCurrentState.at(j));
+             }
+           }
+         }
+         if(isSubstitute)
+           aCmd->SetArg(anArgIndex + aNbAngles + 1,
+                        TCollection_AsciiString(SMESH_2smeshpy::SmeshpyName())+".PointStructStr");
+         aStates->IncrementState();
+       }
        else if(aMethod.IsEqual("TriToQuad") ||
                aMethod.IsEqual("Concatenate") ||
                aMethod.IsEqual("ConcatenateWithGroups")) {
@@ -606,3 +726,35 @@ TCollection_AsciiString SMESH_NoteBook::GetResultScript() const
     aResult+=_commands[i]->GetString()+"\n";
   return aResult;
 }
+
+//================================================================================
+/*!
+ *  \brief Return value of the variable
+ */
+//================================================================================
+bool SMESH_NoteBook::GetReal(const TCollection_AsciiString& theVarName, double& theValue)
+{
+  bool ok = false;
+
+  SMESH_Gen_i *aGen = SMESH_Gen_i::GetSMESHGen();
+  if(!aGen)
+    return ok;
+
+  SALOMEDS::Study_ptr aStudy = aGen->GetCurrentStudy();
+  if(aStudy->_is_nil())
+    return ok;
+
+  TCollection_AsciiString aVarName = theVarName;
+  aVarName.RemoveAll('\"');
+
+  if(aVarName.IsEmpty())
+    return ok;
+
+  const char* aName = aVarName.ToCString();
+  if(aStudy->IsVariable(aName) && (aStudy->IsReal(aName) || aStudy->IsInteger(aName))) {
+    theValue = aStudy->GetReal(aVarName.ToCString());
+    ok = true;
+  }
+
+  return ok;
+}