Salome HOME
Copyrights update 2015.
[plugins/hexoticplugin.git] / src / HexoticPlugin / HexoticPlugin_Hypothesis.cxx
index 13c5dcd0199999fdf636db977572593377ccafd2..02e084d5c2b30f3297994f2003be4fe0afed43fe 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  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
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -46,10 +46,11 @@ HexoticPlugin_Hypothesis::HexoticPlugin_Hypothesis (int hypId, int studyId,
     _hexoticWorkingDirectory( GetDefaultHexoticWorkingDirectory() ),
     _hexoticSdMode(GetDefaultHexoticSdMode()),
     _hexoticVerbosity(GetDefaultHexoticVerbosity()),
-    _hexoticMaxMemory(GetDefaultHexoticMaxMemory())
+    _hexoticMaxMemory(GetDefaultHexoticMaxMemory()),
+    _sizeMaps(GetDefaultHexoticSizeMaps())
 {
   MESSAGE("HexoticPlugin_Hypothesis::HexoticPlugin_Hypothesis");
-  _name = "Hexotic_Parameters";
+  _name = GetHypType();
   _param_algo_dim = 3;
 }
 
@@ -75,14 +76,14 @@ void HexoticPlugin_Hypothesis::SetHexesMaxLevel(int theVal) {
 
 void HexoticPlugin_Hypothesis::SetMinSize(double theVal) {
   if (theVal != _minSize) {
-         _minSize = theVal;
+          _minSize = theVal;
     NotifySubMeshesHypothesisModification();
   }
 }
 
 void HexoticPlugin_Hypothesis::SetMaxSize(double theVal) {
   if (theVal != _maxSize) {
-         _maxSize = theVal;
+          _maxSize = theVal;
     NotifySubMeshesHypothesisModification();
   }
 }
@@ -119,13 +120,23 @@ void HexoticPlugin_Hypothesis::SetHexoticWorkingDirectory(const std::string& pat
 {
   if ( _hexoticWorkingDirectory != path ) {
     _hexoticWorkingDirectory = path;
+    if ( !path.empty() )
+    {
+#ifdef WIN32
+      if( path[ path.size()-1 ] != '\\')
+        _hexoticWorkingDirectory += '\\';
+#else
+      if( path[ path.size()-1 ] != '/')
+        _hexoticWorkingDirectory += '/';
+#endif
+    }
     NotifySubMeshesHypothesisModification();
   }
 }
 
 void HexoticPlugin_Hypothesis::SetHexoticSdMode(int theVal) {
   if (theVal != _hexoticSdMode) {
-         _hexoticSdMode = theVal;
+    _hexoticSdMode = theVal;
     NotifySubMeshesHypothesisModification();
   }
 }
@@ -144,6 +155,46 @@ void HexoticPlugin_Hypothesis::SetHexoticMaxMemory(int theVal) {
   }
 }
 
+bool HexoticPlugin_Hypothesis::AddSizeMap(std::string theEntry, double theSize) {
+  THexoticSizeMaps::iterator it;
+  it=_sizeMaps.find(theEntry);
+  
+  if(theSize <= 0)
+    return false;
+  
+  if( it == _sizeMaps.end() ) // If no size map is defined on the given object
+  {
+    _sizeMaps[theEntry] = theSize;
+    MESSAGE("NEW size map, entry :"<<theEntry<<", size : "<<theSize);
+    NotifySubMeshesHypothesisModification();
+    return true;
+  }
+  else if( it->second != theSize ) // If a size map exists with a different size value
+  {
+    it->second = theSize;
+    MESSAGE("MODIFIED size map, entry :"<<theEntry<<"with size : "<<theSize);
+    NotifySubMeshesHypothesisModification();
+    return true;
+  }
+  else
+  {
+    MESSAGE("NO size map added")
+    return false; // No size map added
+  }
+}
+
+bool HexoticPlugin_Hypothesis::UnsetSizeMap(std::string theEntry) {
+  THexoticSizeMaps::iterator it;
+  it=_sizeMaps.find(theEntry);
+  if( it != _sizeMaps.end() )
+  {
+    _sizeMaps.erase(it);  
+    return true;
+  }
+  else
+    return false;
+}
+
 //=============================================================================
 /*!
  *  
@@ -166,6 +217,16 @@ std::ostream& HexoticPlugin_Hypothesis::SaveTo(std::ostream& save)
   save<<"hexoticSdMode="<<_hexoticSdMode<<";";
   save<<"hexoticVerbosity="<<_hexoticVerbosity<<";";
   save<<"hexoticMaxMemory="<<_hexoticMaxMemory<<";";
+  THexoticSizeMaps::iterator it = _sizeMaps.begin();
+  if ( it != _sizeMaps.end() )
+  {
+    save<<"sizeMaps=";
+    for ( ; it!=_sizeMaps.end() ; it++ )
+    {
+      save<< it->first << "/" << it->second << "#" ;
+    }
+    save<<";";
+  }
   return save;
 }
 
@@ -210,6 +271,22 @@ std::istream& HexoticPlugin_Hypothesis::LoadFrom(std::istream& load)
       if (str3=="hexoticSdMode") _hexoticSdMode = atoi(str4.c_str());
       if (str3=="hexoticVerbosity") _hexoticVerbosity = atoi(str4.c_str());
       if (str3=="hexoticMaxMemory") _hexoticMaxMemory = atoi(str4.c_str());
+      if (str3=="sizeMaps")
+      {
+        std::string sm_substr, sm_substr1, sm_substr2;
+        int sm_pos = 0;
+        int sm_len = str4.length();
+        while ( sm_pos < sm_len )
+        {
+          int sm_found = str4.find('#',sm_pos);
+          sm_substr = str4.substr(sm_pos,sm_found-sm_pos);
+          int sm_slashpos = sm_substr.find('/',0);
+          sm_substr1 = sm_substr.substr(0,sm_slashpos);
+          sm_substr2 = sm_substr.substr(sm_slashpos+1);
+          _sizeMaps[sm_substr1] = atof(sm_substr2.c_str());
+          sm_pos = sm_found + 1;
+        }
+      }
    }
    return load;
 }
@@ -347,4 +424,9 @@ int HexoticPlugin_Hypothesis::GetDefaultHexoticMaxMemory()
   return 2048;
 }
 
+HexoticPlugin_Hypothesis::THexoticSizeMaps HexoticPlugin_Hypothesis::GetDefaultHexoticSizeMaps()
+{
+  return THexoticSizeMaps();
+}
+