Salome HOME
Enable C++0x/C++11 support
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_Hypothesis.cxx
index 2b555570644e653de6148d89f90a8ca041362743..992fbd3df68fcdd42ed57cc0e3cc55762c7453c2 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D
+// Copyright (C) 2007-2015  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -82,7 +82,7 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
   _preCadFacesPeriodicityVector(GetDefaultPreCadFacesPeriodicityVector()),
   _preCadEdgesPeriodicityVector(GetDefaultPreCadEdgesPeriodicityVector())
 {
-  _name = "BLSURF_Parameters";
+  _name = GetHypType();
   _param_algo_dim = 2;
   
 //   _GMFFileMode = false; // GMF ascii mode
@@ -96,6 +96,10 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
                                             "proximity",                                // default = 0
                                             "rectify_jacobian",                         // default = 1
                                             "respect_geometry",                         // default = 1
+                                            "optimise_tiny_edges",                      // default = 0
+                                            "remove_duplicate_cad_faces",               // default = 1
+                                            "tiny_edge_avoid_surface_intersections",    // default = 1
+                                            "tiny_edge_respect_geometry",               // default = 0
                                             "" // mark of end
       };
 
@@ -108,6 +112,8 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
   const char* doubleOptionNames[] = {       "surface_intersections_processing_max_cost",// default = 15
                                             "periodic_tolerance",                       // default = diag/100
                                             "prox_ratio",
+                                            "volume_gradation",
+                                            "tiny_edge_optimisation_length",            // default = diag * 1e-6
                                             "" // mark of end
       };
   const char* charOptionNames[] = {         "required_entities",                        // default = "respect"
@@ -417,7 +423,7 @@ void BLSURFPlugin_Hypothesis::SetOptionValue(const std::string& optionName, cons
     throw (std::invalid_argument) {
   TOptionValues::iterator op_val = _option2value.find(optionName);
   if (op_val == _option2value.end()) {
-    std::string msg = "Unknown BLSURF option: '" + optionName + "'";
+    std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'";
     throw std::invalid_argument(msg);
   }
   if (op_val->second != optionValue) {
@@ -462,7 +468,7 @@ void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName
     throw (std::invalid_argument) {
   TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
   if (op_val == _preCADoption2value.end()) {
-    std::string msg = "Unknown BLSURF option: '" + optionName + "'";
+    std::string msg = "Unknown MG-CADSurf option: '" + optionName + "'";
     throw std::invalid_argument(msg);
   }
   if (op_val->second != optionValue) {
@@ -506,7 +512,7 @@ void BLSURFPlugin_Hypothesis::SetPreCADOptionValue(const std::string& optionName
 std::string BLSURFPlugin_Hypothesis::GetOptionValue(const std::string& optionName) throw (std::invalid_argument) {
   TOptionValues::iterator op_val = _option2value.find(optionName);
   if (op_val == _option2value.end()) {
-    std::string msg = "Unknown BLSURF option: <";
+    std::string msg = "Unknown MG-CADSurf option: <";
     msg += optionName + ">";
     throw std::invalid_argument(msg);
   }
@@ -526,16 +532,82 @@ std::string BLSURFPlugin_Hypothesis::GetPreCADOptionValue(const std::string& opt
 
 //=============================================================================
 void BLSURFPlugin_Hypothesis::ClearOption(const std::string& optionName) {
-  TOptionValues::iterator op_val = _option2value.find(optionName);
-  if (op_val != _option2value.end())
-    op_val->second.clear();
+  TOptionValues::iterator op_val = _customOption2value.find(optionName);
+  if (op_val != _customOption2value.end())
+   _customOption2value.erase(op_val);
+  else {
+    op_val = _option2value.find(optionName);
+    if (op_val != _option2value.end())
+      op_val->second.clear();
+  }
 }
 
 //=============================================================================
 void BLSURFPlugin_Hypothesis::ClearPreCADOption(const std::string& optionName) {
+  TOptionValues::iterator op_val = _customPreCADOption2value.find(optionName);
+  if (op_val != _customPreCADOption2value.end())
+    _customPreCADOption2value.erase(op_val);
+  else {
+    op_val = _preCADoption2value.find(optionName);
+    if (op_val != _preCADoption2value.end())
+      op_val->second.clear();
+  }
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::AddOption(const std::string& optionName, const std::string& optionValue)
+{
+  TOptionValues::iterator op_val = _option2value.find(optionName);
+  if (op_val != _option2value.end()) {
+    if (op_val->second != optionValue)
+      op_val->second = optionValue;
+  }
+  else {
+    op_val = _customOption2value.find(optionName);
+    if (op_val == _customOption2value.end())
+      _customOption2value[optionName] = optionValue;
+    else if (op_val->second != optionValue)
+      op_val->second = optionValue;
+  }
+  NotifySubMeshesHypothesisModification();
+}
+
+//=============================================================================
+void BLSURFPlugin_Hypothesis::AddPreCADOption(const std::string& optionName, const std::string& optionValue)
+{
   TOptionValues::iterator op_val = _preCADoption2value.find(optionName);
-  if (op_val != _preCADoption2value.end())
-    op_val->second.clear();
+  if (op_val != _preCADoption2value.end()) {
+    if (op_val->second != optionValue)
+      op_val->second = optionValue;
+  }
+  else {
+    op_val = _customPreCADOption2value.find(optionName);
+    if (op_val == _customPreCADOption2value.end())
+      _customPreCADOption2value[optionName] = optionValue;
+    else if (op_val->second != optionValue)
+      op_val->second = optionValue;
+  }
+  NotifySubMeshesHypothesisModification();
+}
+
+//=============================================================================
+std::string BLSURFPlugin_Hypothesis::GetOption(const std::string& optionName)
+{
+  TOptionValues::iterator op_val = _customOption2value.find(optionName);
+  if (op_val != _customOption2value.end())
+    return op_val->second;
+  else
+    return "";
+}
+
+//=============================================================================
+std::string BLSURFPlugin_Hypothesis::GetPreCADOption(const std::string& optionName)
+{
+  TOptionValues::iterator op_val = _customPreCADOption2value.find(optionName);
+  if (op_val != _customPreCADOption2value.end())
+    return op_val->second;
+  else
+    return "";
 }
 
 //=======================================================================
@@ -1342,7 +1414,7 @@ void BLSURFPlugin_Hypothesis::AddVertexPeriodicity(TEntry theEdge1Entry, TEntry
 //=============================================================================
 std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
    // We must keep at least the same number of arguments when increasing the SALOME version
-   // When BLSURF becomes CADMESH, some parameters were fused into a single one. Thus the same
+   // When MG-CADSurf becomes CADMESH, some parameters were fused into a single one. Thus the same
    // parameter can be written several times to keep the old global number of parameters.
 
    // Treat old options which are now in the advanced options
@@ -1389,6 +1461,16 @@ std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
     save << " " << "__OPTIONS_END__";
   }
   
+  op_val = _customOption2value.begin();
+  if (op_val != _customOption2value.end()) {
+    save << " " << "__CUSTOM_OPTIONS_BEGIN__";
+    for (; op_val != _customOption2value.end(); ++op_val) {
+      if (!op_val->second.empty())
+        save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
+    }
+    save << " " << "__CUSTOM_OPTIONS_END__";
+  }
+
   op_val = _preCADoption2value.begin();
   if (op_val != _preCADoption2value.end()) {
     save << " " << "__PRECAD_OPTIONS_BEGIN__";
@@ -1399,6 +1481,16 @@ std::ostream & BLSURFPlugin_Hypothesis::SaveTo(std::ostream & save) {
     save << " " << "__PRECAD_OPTIONS_END__";
   }
 
+  op_val = _customPreCADOption2value.begin();
+  if (op_val != _customPreCADOption2value.end()) {
+    save << " " << "__CUSTOM_PRECAD_OPTIONS_BEGIN__";
+    for (; op_val != _customPreCADOption2value.end(); ++op_val) {
+      if (!op_val->second.empty())
+        save << " " << op_val->first << " " << op_val->second << "%#"; // "%#" is a mark of value end
+    }
+    save << " " << "__CUSTOM_PRECAD_OPTIONS_END__";
+  }
+
   TSizeMap::iterator it_sm = _sizeMap.begin();
   if (it_sm != _sizeMap.end()) {
     save << " " << "__SIZEMAP_BEGIN__";
@@ -1775,7 +1867,9 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
 
   bool hasCADSurfOptions = false;
   bool hasOptions = false;
+  bool hasCustomOptions = false;
   bool hasPreCADOptions = false;
+  bool hasCustomPreCADOptions = false;
   bool hasSizeMap = false;
   bool hasAttractor = false;
   bool hasNewAttractor = false;
@@ -1795,8 +1889,12 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
     }
     if (option_or_sm == "__OPTIONS_BEGIN__")
       hasOptions = true;
+    else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
+      hasCustomOptions = true;
     else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
       hasPreCADOptions = true;
+    else if (option_or_sm == "__CUSTOM_PRECAD_OPTIONS_BEGIN__")
+      hasCustomPreCADOptions = true;
     else if (option_or_sm == "__SIZEMAP_BEGIN__")
       hasSizeMap = true;
     else if (option_or_sm == "__ATTRACTORS_BEGIN__")
@@ -1897,8 +1995,12 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
     if (isOK)
       if (option_or_sm == "__OPTIONS_BEGIN__")
         hasOptions = true;
+      else if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
+        hasCustomOptions = true;
       else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
         hasPreCADOptions = true;
+      else if (option_or_sm == "__CUSTOM_PRECAD_OPTIONS_BEGIN__")
+        hasCustomPreCADOptions = true;
       else if (option_or_sm == "__SIZEMAP_BEGIN__")
         hasSizeMap = true;
       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
@@ -1947,10 +2049,67 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
   }
 
   if (hasOptions) {
+    isOK = (load >> option_or_sm);
+    if (isOK)
+      if (option_or_sm == "__CUSTOM_OPTIONS_BEGIN__")
+        hasCustomOptions = true;
+      else if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
+        hasPreCADOptions = true;
+      else if (option_or_sm == "__CUSTOM_PRECAD_OPTIONS_BEGIN__")
+        hasCustomPreCADOptions = true;
+      else if (option_or_sm == "__SIZEMAP_BEGIN__")
+        hasSizeMap = true;
+      else if (option_or_sm == "__ATTRACTORS_BEGIN__")
+        hasAttractor = true;
+      else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
+        hasNewAttractor = true;
+      else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
+        hasEnforcedVertex = true;
+      else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
+        hasPreCADFacesPeriodicity = true;
+      else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
+        hasPreCADEdgesPeriodicity = true;
+      else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
+        hasFacesPeriodicity = true;
+      else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
+        hasEdgesPeriodicity = true;
+      else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
+        hasVerticesPeriodicity = true;
+  }
+
+  while (isOK && hasCustomOptions) {
+    isOK = (load >> optName);
+    if (isOK) {
+      if (optName == "__CUSTOM_OPTIONS_END__")
+        break;
+      isOK = (load >> optValue);
+    }
+    if (isOK) {
+      std::string& value = optValue;
+      int len = value.size();
+      // continue reading until "%#" encountered
+      while (value[len - 1] != '#' || value[len - 2] != '%') {
+        isOK = (load >> optValue);
+        if (isOK) {
+          value += " ";
+          value += optValue;
+          len = value.size();
+        } else {
+          break;
+        }
+      }
+      _customOption2value[optName] = value.substr(0,len-2);
+      value[len - 2] = '\0'; //cut off "%#"
+    }
+  }
+
+  if (hasCustomOptions) {
     isOK = (load >> option_or_sm);
     if (isOK)
       if (option_or_sm == "__PRECAD_OPTIONS_BEGIN__")
         hasPreCADOptions = true;
+      else if (option_or_sm == "__CUSTOM_PRECAD_OPTIONS_BEGIN__")
+        hasCustomPreCADOptions = true;
       else if (option_or_sm == "__SIZEMAP_BEGIN__")
         hasSizeMap = true;
       else if (option_or_sm == "__ATTRACTORS_BEGIN__")
@@ -1998,6 +2157,57 @@ std::istream & BLSURFPlugin_Hypothesis::LoadFrom(std::istream & load) {
   }
 
   if (hasPreCADOptions) {
+    isOK = (load >> option_or_sm);
+    if (isOK)
+      if (option_or_sm == "__CUSTOM_PRECAD_OPTIONS_BEGIN__")
+        hasCustomPreCADOptions = true;
+      else if (option_or_sm == "__SIZEMAP_BEGIN__")
+        hasSizeMap = true;
+      else if (option_or_sm == "__ATTRACTORS_BEGIN__")
+        hasAttractor = true;
+      else if (option_or_sm == "__NEW_ATTRACTORS_BEGIN__")
+        hasNewAttractor = true;
+      else if (option_or_sm == "__ENFORCED_VERTICES_BEGIN__")
+        hasEnforcedVertex = true;
+      else if (option_or_sm == "__PRECAD_FACES_PERIODICITY_BEGIN__")
+        hasPreCADFacesPeriodicity = true;
+      else if (option_or_sm == "__PRECAD_EDGES_PERIODICITY_BEGIN__")
+        hasPreCADEdgesPeriodicity = true;
+      else if (option_or_sm == "__FACES_PERIODICITY_BEGIN__")
+        hasFacesPeriodicity = true;
+      else if (option_or_sm == "__EDGES_PERIODICITY_BEGIN__")
+        hasEdgesPeriodicity = true;
+      else if (option_or_sm == "__VERTICES_PERIODICITY_BEGIN__")
+        hasVerticesPeriodicity = true;
+  }
+
+  while (isOK && hasCustomPreCADOptions) {
+    isOK = (load >> optName);
+    if (isOK) {
+      if (optName == "__CUSTOM_PRECAD_OPTIONS_END__")
+        break;
+      isOK = (load >> optValue);
+    }
+    if (isOK) {
+      std::string& value = optValue;
+      int len = value.size();
+      // continue reading until "%#" encountered
+      while (value[len - 1] != '#' || value[len - 2] != '%') {
+        isOK = (load >> optValue);
+        if (isOK) {
+          value += " ";
+          value += optValue;
+          len = value.size();
+        } else {
+          break;
+        }
+      }
+      _customPreCADOption2value[optName] = value.substr(0,len-2);
+      value[len - 2] = '\0'; //cut off "%#"
+    }
+  }
+
+  if (hasCustomPreCADOptions) {
     isOK = (load >> option_or_sm);
     if (isOK)
       if (option_or_sm == "__SIZEMAP_BEGIN__")