Salome HOME
Fix for the bug "IPAL22425 TC6.3.0: Wrong Dump of Study".
authorrnv <rnv@opencascade.com>
Fri, 29 Apr 2011 12:19:45 +0000 (12:19 +0000)
committerrnv <rnv@opencascade.com>
Fri, 29 Apr 2011 12:19:45 +0000 (12:19 +0000)
src/SALOMEDS/SALOMEDS_IParameters.cxx
src/SALOMEDS/SALOMEDS_IParameters.hxx
src/SALOMEDSClient/SALOMEDSClient_IParameters.hxx
src/SALOMEDSImpl/SALOMEDSImpl_IParameters.cxx
src/SALOMEDSImpl/SALOMEDSImpl_IParameters.hxx
src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx

index 54000374e883c3df53ab66faad97ef4216c8cb13..37f11d8d8dd130c3c0cad49baa2b6b6b24d85707 100644 (file)
@@ -36,6 +36,9 @@
 #define _AP_PROPERTIES_LIST_ "AP_PROPERTIES_LIST"
 #define _AP_DUMP_PYTHON_ "AP_DUMP_PYTHON"
 
+#define _PT_ID_ "_PT_OBJECT_ID_"
+
+
 /*!
   Constructor
 */
@@ -144,6 +147,33 @@ std::vector<std::string> SALOMEDS_IParameters::getAllParameterNames(const std::s
   return names;
 }
 
+
+std::string SALOMEDS_IParameters::getIdParameter(const std::string& entry)
+{
+  if(!_ap) return "";
+  if(!_ap->IsSet(entry, PT_STRARRAY)) return "";
+  std::vector<std::string> v = _ap->GetStrArray(entry);
+  int length = v.size();
+  for(int i = 0; i<length; i+=1) {
+    if(v[i] == _PT_ID_) return v[i+1];
+  }
+  return "";
+}
+
+void SALOMEDS_IParameters::setIdParameter(const std::string& entry, const std::string& value)
+{
+  if(!_ap) return;
+  std::vector<std::string> v;
+  if(!_ap->IsSet(entry, PT_STRARRAY)) {
+    append(_AP_ENTRIES_LIST_, entry); //Add the entry to the internal list of entries
+    _ap->SetStrArray(entry, v);
+  }
+  v = _ap->GetStrArray(entry);
+  v.push_back(_PT_ID_);
+  v.push_back(value);
+  _ap->SetStrArray(entry, v);
+}
+
 std::vector<std::string> SALOMEDS_IParameters::getAllParameterValues(const std::string& entry)
 {
   std::vector<std::string> v, values;
index fe5860b62048b9bd0079b701f7086826524969c3..30c10bd1f5276449478ddb197711704fa903ec31 100644 (file)
@@ -77,6 +77,16 @@ public:
    */
   virtual std::string getParameter(const std::string& entry, const std::string& parameterName);
 
+  /*!
+    Sets an id parameter value for the given entry.
+   */
+  virtual void setIdParameter(const std::string& entry, const std::string& value);
+
+  /*!
+    Gets an id parameter value for the given entry
+   */
+  virtual std::string getIdParameter(const std::string& entry);
+
   /*!
     Returns all parameter names of the given entry
    */
index 54eaf507fc7a555e3ea8c466d3dcf114429c3dee..6e6124fda1c33ca3843c112e72b887c3cb1c8a56 100644 (file)
@@ -76,6 +76,16 @@ public:
    */
   virtual std::string getParameter(const std::string& entry, const std::string& parameterName) = 0;
 
+  /*!
+    Sets an id parameter value for the given entry.
+   */
+  virtual void setIdParameter(const std::string& entry, const std::string& value) = 0;
+
+  /*!
+    Gets an id parameter value for the given entry
+   */
+  virtual std::string getIdParameter(const std::string& entry) = 0;
+
   /*!
     Returns all parameter names of the given entry
    */
index f113c55a5434597316d5bfdeed97d53b802e1ded..c991539623117c3bb540f11603a4805e57cca11c 100644 (file)
@@ -31,6 +31,8 @@
 #define _AP_PROPERTIES_LIST_ "AP_PROPERTIES_LIST"
 #define _AP_DUMP_PYTHON_ "AP_DUMP_PYTHON"
 
+#define _PT_ID_ "_PT_OBJECT_ID_"
+
 /*!
   Constructor
 */
@@ -126,6 +128,33 @@ std::string SALOMEDSImpl_IParameters::getParameter(const std::string& entry, con
 }
 
 
+void SALOMEDSImpl_IParameters::setIdParameter(const std::string& entry, const std::string& value)
+{
+  if(!_ap) return;
+  std::vector<std::string> v;
+  if(!_ap->IsSet(entry, PT_STRARRAY)) {
+    append(_AP_ENTRIES_LIST_, entry); //Add the entry to the internal list of entries
+    _ap->SetStrArray(entry, v);
+  }
+  v = _ap->GetStrArray(entry);
+  v.push_back(_PT_ID_);
+  v.push_back(value);
+  _ap->SetStrArray(entry, v);
+}
+
+
+std::string SALOMEDSImpl_IParameters::getIdParameter(const std::string& entry)
+{
+  if(!_ap) return "";
+  if(!_ap->IsSet(entry, PT_STRARRAY)) return "";
+  std::vector<std::string> v = _ap->GetStrArray(entry);
+  int length = v.size();
+  for(int i = 0; i<length; i+=1) {
+    if(v[i] == _PT_ID_) return v[i+1];
+  }
+  return "";
+}
+
 std::vector<std::string> SALOMEDSImpl_IParameters::getAllParameterNames(const std::string& entry)
 {
   std::vector<std::string> v, names;
@@ -347,9 +376,27 @@ std::string SALOMEDSImpl_IParameters::getDefaultScript(SALOMEDSImpl_Study* study
       SALOMEDSImpl_SObject so = study->FindObjectID(decodedEntry);
       std::string so_name("");
       if(so) so_name = so.GetName();
-      dump += shift + "# set up entry " + v[i] +" ("+so_name+")" + " parameters" + "\n";
-      for(int j = 0; j < names.size() && j < values.size(); j++)
-        dump += shift + "ipar.setParameter(\"" + v[i] + "\", \"" + names[j] + "\", \"" + values[j] + "\")\n";
+      
+      //Try to find id parameter 
+      std::vector<std::string>::iterator it = std::find(names.begin(), names.end(), _PT_ID_ );
+      bool hasId = it !=  names.end();
+      bool onlyId = hasId && names.size() == 1;
+      
+      if(!onlyId) {
+       dump += shift + "# set up entry " + v[i] +" ("+so_name+")" + " parameters" + "\n";
+       if(hasId) {
+         int idIndex = std::distance(names.begin(), it);
+         dump += shift + "objId = " + values[idIndex] + "\n";
+       }
+          
+       for(int j = 0; j < names.size() && j < values.size(); j++) {
+         if(names[j] == _PT_ID_) continue;
+         if(hasId)
+           dump += shift + "ipar.setParameter(" + "objId" + ", \"" + names[j] + "\", \"" + values[j] + "\")\n";
+         else
+           dump += shift + "ipar.setParameter(\"" + v[i] + "\", \"" + names[j] + "\", \"" + values[j] + "\")\n";
+       }
+      }
     }
   }
   
index 712a676fcb5c1e2da52a03cbce467b932a058efd..9ed72eb9b5d7b1f00c2c966925377fd832b48c1e 100644 (file)
@@ -78,6 +78,16 @@ public:
   */
   virtual std::string getParameter(const std::string& entry, const std::string& parameterName);
 
+  /*!
+    Sets an id parameter value for the given entry.
+   */
+  virtual void setIdParameter(const std::string& entry, const std::string& value);
+
+  /*!
+    Gets an id parameter value for the given entry
+   */
+  virtual std::string getIdParameter(const std::string& entry);
+
   /*!
   Returns all parameter names of the given entry
   */
index 67c8ce04eb123975869764a95e322bf684679aea..3ee0561140a2c6b5380d1cace2ede4193812560a 100644 (file)
@@ -1524,12 +1524,24 @@ void SALOMEDSImpl_Study::Modify()
 //============================================================================
 SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetCommonParameters(const char* theID, int theSavePoint)
 {
-  if (theSavePoint < 0) return NULL;
+  if (theSavePoint < -1) return NULL;
   SALOMEDSImpl_StudyBuilder* builder = NewBuilder();
   SALOMEDSImpl_SObject so = FindComponent((char*)theID);
   if (!so) so = builder->NewComponent((char*)theID);
   SALOMEDSImpl_AttributeParameter* attParam = NULL;
 
+  if (theSavePoint == -1) {
+    int ctag = 1;
+    DF_Label savePointLabel = so.GetLabel().FindChild( ctag, /*create=*/0 );
+    DF_Label prevPointLabel;
+    while ( !savePointLabel.IsNull() ) {
+      ctag++;
+      prevPointLabel = savePointLabel;
+      savePointLabel = so.GetLabel().FindChild( ctag, /*create=*/0 );
+    }
+    if ( !prevPointLabel.IsNull() )
+      so = GetSObject( prevPointLabel );
+  }
   if (theSavePoint > 0) { // Try to find SObject that contains attribute parameter ...
     DF_Label savePointLabel = so.GetLabel().FindChild( theSavePoint, /*create=*/0 );
     if ( !savePointLabel.IsNull() )
@@ -1558,7 +1570,7 @@ SALOMEDSImpl_AttributeParameter* SALOMEDSImpl_Study::GetModuleParameters(const c
                                                                          const char* theModuleName,
                                                                          int theSavePoint)
 {
-  if(theSavePoint <= 0) return NULL;
+  if(theSavePoint < -1) return NULL;
   SALOMEDSImpl_AttributeParameter* main_ap = GetCommonParameters(theID, theSavePoint);
   SALOMEDSImpl_SObject main_so = main_ap->GetSObject();
   SALOMEDSImpl_AttributeParameter* par = NULL;