1 // Copyright (C) 2007-2012 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.
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 <utilities.h>
30 #define PT_REALARRAY 4
34 #define _AP_LISTS_LIST_ "AP_LISTS_LIST"
35 #define _AP_ENTRIES_LIST_ "AP_ENTRIES_LIST"
36 #define _AP_PROPERTIES_LIST_ "AP_PROPERTIES_LIST"
37 #define _AP_DUMP_PYTHON_ "AP_DUMP_PYTHON"
39 #define _PT_ID_ "_PT_OBJECT_ID_"
45 SALOMEDS_IParameters::SALOMEDS_IParameters(const _PTR(AttributeParameter)& ap)
49 _PTR(SObject) so = _ap->GetSObject();
50 _study = so->GetStudy();
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);
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);
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 >= v.size()) return "";
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 = v.size();
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 = v.size();
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 = v.size();
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 = v.size();
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 _ap->GetStrArray(entry).size()/2;
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 = val.rfind(separator);
236 else pos = val.find(separator);
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 if(!_study) return entry;
262 int pos = entry.rfind("_");
263 if(pos < 0 || pos >= entry.length()) return entry;
265 std::string compName(entry, 0, pos), compID, tail(entry, pos+1, entry.length()-1);
267 if(_compNames.find(compName) == _compNames.end()) {
268 _PTR(SObject) so = _study->FindComponent(compName);
269 if(!so) return entry;
270 compID = so->GetID();
271 _compNames[compName] = compID;
273 else compID = _compNames[compName];
275 std::string newEntry(compID);
276 newEntry += (":"+tail);
281 void SALOMEDS_IParameters::setDumpPython(_PTR(Study) study, const std::string& theID)
284 if(theID == "") anID = getDefaultVisualComponent();
287 _PTR(AttributeParameter) ap = study->GetCommonParameters(anID, 0);
288 ap->SetBool(_AP_DUMP_PYTHON_, !isDumpPython(study, theID));
291 bool SALOMEDS_IParameters::isDumpPython(_PTR(Study) study, const std::string& theID)
294 if(theID == "") anID = getDefaultVisualComponent();
297 _PTR(AttributeParameter) ap = study->GetCommonParameters(anID, 0);
298 if(!ap) return false;
299 if(!ap->IsSet(_AP_DUMP_PYTHON_, PT_BOOLEAN)) return false;
300 return (bool)ap->GetBool(_AP_DUMP_PYTHON_);
303 std::string SALOMEDS_IParameters::getDefaultVisualComponent()
305 return "Interface Applicative";