Salome HOME
Update from BR_V5_DEV 13feb09
[modules/kernel.git] / src / SALOMEDSImpl / SALOMEDSImpl_IParameters.cxx
index 02115ababb4f845e61fe582e019cc918c18b1e1c..6d4c990827445f1585766e4678bd44522f4e27b8 100644 (file)
@@ -1,26 +1,27 @@
-// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA 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.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-// Lesser General Public License for more details.
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-// You should have received a copy of the GNU Lesser General Public  
-// License along with this library; if not, write to the Free Software 
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-// See http://www.salome-platform.org/
+//  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.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 #include "SALOMEDSImpl_IParameters.hxx"
 #include <utilities.h>
 
-#include <TCollection_AsciiString.hxx>
-
 #include "SALOMEDSImpl_SObject.hxx"
 #include "SALOMEDSImpl_ChildIterator.hxx"
 
@@ -34,12 +35,12 @@ using namespace std;
 /*!
   Constructor
 */
-SALOMEDSImpl_IParameters::SALOMEDSImpl_IParameters(const Handle(SALOMEDSImpl_AttributeParameter)& ap)
+SALOMEDSImpl_IParameters::SALOMEDSImpl_IParameters(SALOMEDSImpl_AttributeParameter* ap)
 {
-  if(ap.IsNull()) return;
+  if(!ap) return;
   _ap = ap;
-  Handle(SALOMEDSImpl_SObject) so = _ap->GetSObject();
-  _study = so->GetStudy();
+  SALOMEDSImpl_SObject so = _ap->GetSObject();
+  _study = so.GetStudy();
 }
 
 SALOMEDSImpl_IParameters::~SALOMEDSImpl_IParameters()
@@ -49,7 +50,7 @@ SALOMEDSImpl_IParameters::~SALOMEDSImpl_IParameters()
 
 int SALOMEDSImpl_IParameters::append(const string& listName, const string& value)
 {
-  if(_ap.IsNull()) return -1;
+  if(!_ap) return -1;
   vector<string> v;
   if(!_ap->IsSet(listName, PT_STRARRAY)) {
     if(!_ap->IsSet(_AP_LISTS_LIST_, PT_STRARRAY)) _ap->SetStrArray(_AP_LISTS_LIST_, v);
@@ -67,7 +68,7 @@ int SALOMEDSImpl_IParameters::append(const string& listName, const string& value
 
 int SALOMEDSImpl_IParameters::nbValues(const string& listName)
 {
-  if(_ap.IsNull()) return -1;
+  if(!_ap) return -1;
   if(!_ap->IsSet(listName, PT_STRARRAY)) return 0;
   vector<string> v = _ap->GetStrArray(listName);
   return v.size();
@@ -76,7 +77,7 @@ int SALOMEDSImpl_IParameters::nbValues(const string& listName)
 vector<string> SALOMEDSImpl_IParameters::getValues(const string& listName)
 {
   vector<string> v;
-  if(_ap.IsNull()) return v;
+  if(!_ap) return v;
   if(!_ap->IsSet(listName, PT_STRARRAY)) return v;
   return _ap->GetStrArray(listName);
 }
@@ -84,7 +85,7 @@ vector<string> SALOMEDSImpl_IParameters::getValues(const string& listName)
 
 string SALOMEDSImpl_IParameters::getValue(const string& listName, int index)
 {
-  if(_ap.IsNull()) return "";
+  if(!_ap) return "";
   if(!_ap->IsSet(listName, PT_STRARRAY)) return "";
   vector<string> v = _ap->GetStrArray(listName);
   if(index >= v.size()) return ""; 
@@ -100,7 +101,7 @@ vector<string> SALOMEDSImpl_IParameters::getLists()
 
 void SALOMEDSImpl_IParameters::setParameter(const string& entry, const string& parameterName, const string& value)
 {
-  if(_ap.IsNull()) return;
+  if(!_ap) return;
   vector<string> v;
   if(!_ap->IsSet(entry, PT_STRARRAY)) {
     append(_AP_ENTRIES_LIST_, entry); //Add the entry to the internal list of entries
@@ -115,7 +116,7 @@ void SALOMEDSImpl_IParameters::setParameter(const string& entry, const string& p
 
 string SALOMEDSImpl_IParameters::getParameter(const string& entry, const string& parameterName)
 {
-  if(_ap.IsNull()) return "";
+  if(!_ap) return "";
   if(!_ap->IsSet(entry, PT_STRARRAY)) return "";
   vector<string> v = _ap->GetStrArray(entry);
   int length = v.size();
@@ -129,7 +130,7 @@ string SALOMEDSImpl_IParameters::getParameter(const string& entry, const string&
 vector<string> SALOMEDSImpl_IParameters::getAllParameterNames(const string& entry)
 {
   vector<string> v, names;
-  if(_ap.IsNull()) return v; 
+  if(!_ap) return v; 
   if(!_ap->IsSet(entry, PT_STRARRAY)) return v;
   v = _ap->GetStrArray(entry);
   int length = v.size();
@@ -142,7 +143,7 @@ vector<string> SALOMEDSImpl_IParameters::getAllParameterNames(const string& entr
 vector<string> SALOMEDSImpl_IParameters::getAllParameterValues(const string& entry)
 {
   vector<string> v, values;
-  if(_ap.IsNull()) return v; 
+  if(!_ap) return v; 
   if(!_ap->IsSet(entry, PT_STRARRAY)) return v;
   v = _ap->GetStrArray(entry);
   int length = v.size();
@@ -154,7 +155,7 @@ vector<string> SALOMEDSImpl_IParameters::getAllParameterValues(const string& ent
 
 int SALOMEDSImpl_IParameters::getNbParameters(const string& entry)
 {
-  if(_ap.IsNull()) return -1;
+  if(!_ap) return -1;
   if(!_ap->IsSet(entry, PT_STRARRAY)) return -1;
   return  _ap->GetStrArray(entry).size()/2;
 }
@@ -162,14 +163,14 @@ int SALOMEDSImpl_IParameters::getNbParameters(const string& entry)
 vector<string> SALOMEDSImpl_IParameters::getEntries()
 {
   vector<string> v;
-  if(_ap.IsNull()) return v;
+  if(!_ap) return v;
   if(!_ap->IsSet(_AP_ENTRIES_LIST_, PT_STRARRAY)) return v;
   return _ap->GetStrArray(_AP_ENTRIES_LIST_);
 }
 
 void SALOMEDSImpl_IParameters::setProperty(const string& name, const std::string& value)
 {
-  if(_ap.IsNull()) return;
+  if(!_ap) return;
   if(!_ap->IsSet(name, PT_STRING)) {
     append(_AP_PROPERTIES_LIST_, name); //Add the property to the internal list of properties
   }
@@ -178,7 +179,7 @@ void SALOMEDSImpl_IParameters::setProperty(const string& name, const std::string
 
 string SALOMEDSImpl_IParameters::getProperty(const string& name)
 {
-  if(_ap.IsNull()) return "";
+  if(!_ap) return "";
   if(!_ap->IsSet(name, PT_STRING)) return "";
   return _ap->GetString(name);
 }
@@ -186,7 +187,7 @@ string SALOMEDSImpl_IParameters::getProperty(const string& name)
 vector<string> SALOMEDSImpl_IParameters::getProperties()
 {
   vector<string> v;
-  if(_ap.IsNull()) return v;
+  if(!_ap) return v;
   if(!_ap->IsSet(_AP_PROPERTIES_LIST_, PT_STRARRAY)) return v;
   return _ap->GetStrArray(_AP_PROPERTIES_LIST_);
 }
@@ -195,14 +196,14 @@ string SALOMEDSImpl_IParameters::decodeEntry(const string& entry)
 {
   if(!_study) return entry;
   int pos = entry.rfind("_");
-  if(pos < 0 || pos >= entry.length()) return entry;
+  if(pos < 0 || pos >= entry.size()) return entry;
 
   string compName(entry, 0, pos), compID, tail(entry, pos+1, entry.length()-1);
   
   if(_compNames.find(compName) == _compNames.end()) {
-    Handle(SALOMEDSImpl_SObject) so = _study->FindComponent((char*)compName.c_str());
+    SALOMEDSImpl_SObject so = _study->FindComponent(compName);
     if(!so) return entry;
-    compID = so->GetID().ToCString();
+    compID = so.GetID();
     _compNames[compName] = compID;
   }
   else compID = _compNames[compName];
@@ -214,37 +215,37 @@ string SALOMEDSImpl_IParameters::decodeEntry(const string& entry)
 }
 
 
-bool SALOMEDSImpl_IParameters::isDumpPython(const Handle(SALOMEDSImpl_Study)& study, const string& theID)
+bool SALOMEDSImpl_IParameters::isDumpPython(SALOMEDSImpl_Study* study, const string& theID)
 {
   string anID;
   if(theID == "") anID = getDefaultVisualComponent();
   else anID = theID;
 
-  Handle(SALOMEDSImpl_AttributeParameter) ap = study->GetCommonParameters((char*)anID.c_str(), 0);
-  if(ap.IsNull()) return false;
+  SALOMEDSImpl_AttributeParameter* ap = study->GetCommonParameters((char*)anID.c_str(), 0);
+  if(!ap) return false;
   if(!ap->IsSet(_AP_DUMP_PYTHON_, PT_BOOLEAN)) return false;
   return (bool)ap->GetBool(_AP_DUMP_PYTHON_);
 }
 
 
-int SALOMEDSImpl_IParameters::getLastSavePoint(const Handle(SALOMEDSImpl_Study)& study, const string& theID)
+int SALOMEDSImpl_IParameters::getLastSavePoint(SALOMEDSImpl_Study* study, const string& theID)
 {
   string anID;
   if(theID == "") anID = getDefaultVisualComponent();
   else anID = theID;
 
 
-  Handle(SALOMEDSImpl_SObject) so = study->FindComponent((char*)anID.c_str());
-  if(so.IsNull()) return -1;
+  SALOMEDSImpl_SObject so = study->FindComponent(anID);
+  if(!so) return -1;
 
-  Handle(SALOMEDSImpl_StudyBuilder) builder = study->NewBuilder();
-  Handle(SALOMEDSImpl_ChildIterator) anIter ( study->NewChildIterator( so ) );
+  SALOMEDSImpl_StudyBuilder* builder = study->NewBuilder();
+  SALOMEDSImpl_ChildIterator anIter = study->NewChildIterator( so );
   int tag = -1;
-  for(; anIter->More(); anIter->Next())
+  for(; anIter.More(); anIter.Next())
   {
-    Handle(SALOMEDSImpl_SObject) val( anIter->Value() );
-    Handle(SALOMEDSImpl_GenericAttribute) genAttr;
-    if(builder->FindAttribute(val, genAttr, "AttributeParameter")) tag = val->Tag();
+    SALOMEDSImpl_SObject val( anIter.Value() );
+    DF_Attribute* genAttr;
+    if(builder->FindAttribute(val, genAttr, "AttributeParameter")) tag = val.Tag();
   }
 
   return tag;
@@ -252,13 +253,13 @@ int SALOMEDSImpl_IParameters::getLastSavePoint(const Handle(SALOMEDSImpl_Study)&
 
 
 
-string SALOMEDSImpl_IParameters::getStudyScript(const Handle(SALOMEDSImpl_Study)& study, int savePoint, const std::string& theID)
+string SALOMEDSImpl_IParameters::getStudyScript(SALOMEDSImpl_Study* study, int savePoint, const std::string& theID)
 {
   string anID;
   if(theID == "") anID = getDefaultVisualComponent();
   else anID = theID;
 
-  Handle(SALOMEDSImpl_AttributeParameter) ap = study->GetCommonParameters((char*)anID.c_str(), savePoint);
+  SALOMEDSImpl_AttributeParameter* ap = study->GetCommonParameters((char*)anID.c_str(), savePoint);
   SALOMEDSImpl_IParameters ip(ap);
 
   string dump("");
@@ -282,18 +283,23 @@ string SALOMEDSImpl_IParameters::getStudyScript(const Handle(SALOMEDSImpl_Study)
     for(int i = 0; i<v.size(); i++) {
       vector<string> lst = ip.getValues(v[i]);
       dump += "# fill list "+v[i]+"\n";
-      for(int j = 0; j < lst.size(); j++)
-       dump += "ipar.append(\""+v[i]+"\", \""+lst[j]+"\")\n";
+      for(int j = 0; j < lst.size(); j++) {
+       printf("### %s \nFind : %i\n",lst[j].c_str(), lst[j].find('\"'));
+       if (lst[j].find('\"') == -1)
+         dump += "ipar.append(\""+v[i]+"\", \""+lst[j]+"\")\n";
+       else
+         dump += "ipar.append(\""+v[i]+"\", \"\"\""+lst[j]+"\"\"\")\n";
+      }
     }
   }
 
   return dump;
 }
 
-string SALOMEDSImpl_IParameters::getDefaultScript(const Handle(SALOMEDSImpl_Study)& study, 
-                                             const string& moduleName, 
-                                             const string& shift, 
-                                             const string& theID)
+string SALOMEDSImpl_IParameters::getDefaultScript(SALOMEDSImpl_Study* study, 
+                                                 const string& moduleName, 
+                                                 const string& shift, 
+                                                 const string& theID)
 {
   string anID;
   if(theID == "") anID = getDefaultVisualComponent();
@@ -306,7 +312,7 @@ string SALOMEDSImpl_IParameters::getDefaultScript(const Handle(SALOMEDSImpl_Stud
   SALOMEDSImpl_IParameters ip = SALOMEDSImpl_IParameters(study->GetCommonParameters(anID.c_str(), savePoint));
   if(!isDumpPython(study)) return dump;
 
-  Handle(SALOMEDSImpl_AttributeParameter) ap = study->GetModuleParameters(anID.c_str(), moduleName.c_str(), savePoint);
+  SALOMEDSImpl_AttributeParameter* ap = study->GetModuleParameters(anID.c_str(), moduleName.c_str(), savePoint);
   ip = SALOMEDSImpl_IParameters(ap);
 
 
@@ -340,9 +346,9 @@ string SALOMEDSImpl_IParameters::getDefaultScript(const Handle(SALOMEDSImpl_Stud
       vector<string> names = ip.getAllParameterNames(v[i]);
       vector<string> values = ip.getAllParameterValues(v[i]);
       string decodedEntry = ip.decodeEntry(v[i]);
-      Handle(SALOMEDSImpl_SObject) so = study->FindObjectID((char*)decodedEntry.c_str());
+      SALOMEDSImpl_SObject so = study->FindObjectID(decodedEntry);
       string so_name("");
-      if(!so.IsNull()) so_name = so->GetName().ToCString();
+      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";