1 // Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SALOMEDS_IParameters.hxx"
24 #include <SALOMEDSClient_ClientFactory.hxx>
25 #include <SALOME_KernelServices.hxx>
26 #include <utilities.h>
32 #define PT_REALARRAY 4
36 #define _AP_LISTS_LIST_ "AP_LISTS_LIST"
37 #define _AP_ENTRIES_LIST_ "AP_ENTRIES_LIST"
38 #define _AP_PROPERTIES_LIST_ "AP_PROPERTIES_LIST"
39 #define _AP_DUMP_PYTHON_ "AP_DUMP_PYTHON"
41 #define _PT_ID_ "_PT_OBJECT_ID_"
47 SALOMEDS_IParameters::SALOMEDS_IParameters(const _PTR(AttributeParameter)& ap)
53 SALOMEDS_IParameters::~SALOMEDS_IParameters()
58 int SALOMEDS_IParameters::append(const std::string& listName, const std::string& value)
61 std::vector<std::string> v;
62 if(!_ap->IsSet(listName, PT_STRARRAY)) {
63 if(!_ap->IsSet(_AP_LISTS_LIST_, PT_STRARRAY)) _ap->SetStrArray(_AP_LISTS_LIST_, v);
64 if(listName != _AP_ENTRIES_LIST_ &&
65 listName != _AP_PROPERTIES_LIST_) {
66 append(_AP_LISTS_LIST_, listName);
68 _ap->SetStrArray(listName, v);
70 v = _ap->GetStrArray(listName);
72 _ap->SetStrArray(listName, v);
73 return (int)(v.size()-1); //!< TODO: conversion from size_t to int
76 int SALOMEDS_IParameters::nbValues(const std::string& listName)
79 if(!_ap->IsSet(listName, PT_STRARRAY)) return 0;
80 std::vector<std::string> v = _ap->GetStrArray(listName);
81 return (int)v.size(); //!< TODO: conversion from size_t to int
84 std::vector<std::string> SALOMEDS_IParameters::getValues(const std::string& listName)
86 std::vector<std::string> v;
88 if(!_ap->IsSet(listName, PT_STRARRAY)) return v;
89 return _ap->GetStrArray(listName);
93 std::string SALOMEDS_IParameters::getValue(const std::string& listName, int index)
96 if(!_ap->IsSet(listName, PT_STRARRAY)) return "";
97 std::vector<std::string> v = _ap->GetStrArray(listName);
98 if(index >= (int)v.size()) return ""; //TODO: mismatch signed/unsigned
102 std::vector<std::string> SALOMEDS_IParameters::getLists()
104 std::vector<std::string> v;
105 if(!_ap->IsSet(_AP_LISTS_LIST_, PT_STRARRAY)) return v;
106 return _ap->GetStrArray(_AP_LISTS_LIST_);
109 void SALOMEDS_IParameters::setParameter(const std::string& entry, const std::string& parameterName, const std::string& value)
112 std::vector<std::string> v;
113 if(!_ap->IsSet(entry, PT_STRARRAY)) {
114 append(_AP_ENTRIES_LIST_, entry); //Add the entry to the internal list of entries
115 _ap->SetStrArray(entry, v);
117 v = _ap->GetStrArray(entry);
118 v.push_back(parameterName);
120 _ap->SetStrArray(entry, v);
124 std::string SALOMEDS_IParameters::getParameter(const std::string& entry, const std::string& parameterName)
127 if(!_ap->IsSet(entry, PT_STRARRAY)) return "";
128 std::vector<std::string> v = _ap->GetStrArray(entry);
129 int length = (int)v.size(); //!< TODO: conversion from size_t to int
130 for(int i = 0; i<length; i+=1) {
131 if(v[i] == parameterName) return v[i+1];
137 std::vector<std::string> SALOMEDS_IParameters::getAllParameterNames(const std::string& entry)
139 std::vector<std::string> v, names;
141 if(!_ap->IsSet(entry, PT_STRARRAY)) return v;
142 v = _ap->GetStrArray(entry);
143 int length = (int)v.size(); //!< TODO: conversion from size_t to int
144 for(int i = 0; i<length; i+=2) {
145 names.push_back(v[i]);
151 std::string SALOMEDS_IParameters::getIdParameter(const std::string& entry)
154 if(!_ap->IsSet(entry, PT_STRARRAY)) return "";
155 std::vector<std::string> v = _ap->GetStrArray(entry);
156 int length = (int)v.size(); //!< TODO: conversion from size_t to int
157 for(int i = 0; i<length; i+=1) {
158 if(v[i] == _PT_ID_) return v[i+1];
163 void SALOMEDS_IParameters::setIdParameter(const std::string& entry, const std::string& value)
166 std::vector<std::string> v;
167 if(!_ap->IsSet(entry, PT_STRARRAY)) {
168 append(_AP_ENTRIES_LIST_, entry); //Add the entry to the internal list of entries
169 _ap->SetStrArray(entry, v);
171 v = _ap->GetStrArray(entry);
172 v.push_back(_PT_ID_);
174 _ap->SetStrArray(entry, v);
177 std::vector<std::string> SALOMEDS_IParameters::getAllParameterValues(const std::string& entry)
179 std::vector<std::string> v, values;
181 if(!_ap->IsSet(entry, PT_STRARRAY)) return v;
182 v = _ap->GetStrArray(entry);
183 int length = (int)v.size(); //!< TODO: conversion from size_t to int
184 for(int i = 1; i<length; i+=2) {
185 values.push_back(v[i]);
190 int SALOMEDS_IParameters::getNbParameters(const std::string& entry)
193 if(!_ap->IsSet(entry, PT_STRARRAY)) return -1;
194 return (int)(_ap->GetStrArray(entry).size()/2); //!< TODO: conversion from size_t to int
197 std::vector<std::string> SALOMEDS_IParameters::getEntries()
199 std::vector<std::string> v;
201 if(!_ap->IsSet(_AP_ENTRIES_LIST_, PT_STRARRAY)) return v;
202 return _ap->GetStrArray(_AP_ENTRIES_LIST_);
205 void SALOMEDS_IParameters::setProperty(const std::string& name, const std::string& value)
208 if(!_ap->IsSet(name, PT_STRING)) {
209 append(_AP_PROPERTIES_LIST_, name); //Add the property to the internal list of properties
211 _ap->SetString(name, value);
214 std::string SALOMEDS_IParameters::getProperty(const std::string& name)
217 if(!_ap->IsSet(name, PT_STRING)) return "";
218 return _ap->GetString(name);
221 std::vector<std::string> SALOMEDS_IParameters::getProperties()
223 std::vector<std::string> v;
225 if(!_ap->IsSet(_AP_PROPERTIES_LIST_, PT_STRARRAY)) return v;
226 return _ap->GetStrArray(_AP_PROPERTIES_LIST_);
230 std::vector<std::string> SALOMEDS_IParameters::parseValue(const std::string& value, const char separator, bool fromEnd)
232 std::string val(value);
233 std::vector<std::string> v;
235 if(fromEnd) pos = (int)val.rfind(separator); //!< TODO: conversion from size_t to int
236 else pos = (int)val.find(separator); //!< TODO: conversion from size_t to int
243 std::string part1, part2;
244 part1 = val.substr(0, pos);
245 part2 = val.substr(pos+1, val.size());
251 std::string SALOMEDS_IParameters::encodeEntry(const std::string& entry, const std::string& compName)
253 std::string tail(entry, 6, entry.length()-1);
254 std::string newEntry(compName);
255 newEntry+=("_"+tail);
259 std::string SALOMEDS_IParameters::decodeEntry(const std::string& entry)
261 int pos = (int)entry.rfind("_"); //!< TODO: conversion from size_t to int
262 if(pos < 0 || pos >= (int)entry.length()) return entry; //TODO: mismatch signed/unsigned
264 std::string compName(entry, 0, pos), compID, tail(entry, pos+1, entry.length()-1);
266 if(_compNames.find(compName) == _compNames.end()) {
267 _PTR(SObject) so = ClientFactory::Study(KERNEL::getStudyServant())->FindComponent(compName);
268 if(!so) return entry;
269 compID = so->GetID();
270 _compNames[compName] = compID;
272 else compID = _compNames[compName];
274 std::string newEntry(compID);
275 newEntry += (":"+tail);
280 void SALOMEDS_IParameters::setDumpPython(const std::string& theID)
283 if(theID == "") anID = getDefaultVisualComponent();
286 _PTR(AttributeParameter) ap = ClientFactory::Study(KERNEL::getStudyServant())->GetCommonParameters(anID, 0);
287 ap->SetBool(_AP_DUMP_PYTHON_, !isDumpPython(theID));
290 bool SALOMEDS_IParameters::isDumpPython(const std::string& theID)
293 if(theID == "") anID = getDefaultVisualComponent();
296 _PTR(AttributeParameter) ap = ClientFactory::Study(KERNEL::getStudyServant())->GetCommonParameters(anID, 0);
297 if(!ap) return false;
298 if(!ap->IsSet(_AP_DUMP_PYTHON_, PT_BOOLEAN)) return false;
299 return (bool)ap->GetBool(_AP_DUMP_PYTHON_);
302 std::string SALOMEDS_IParameters::getDefaultVisualComponent()
304 return "Interface Applicative";