1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "SALOMEDS_IParameters.hxx"
20 #include <utilities.h>
28 #define PT_REALARRAY 4
32 #define _AP_LISTS_LIST_ "AP_LISTS_LIST"
33 #define _AP_ENTRIES_LIST_ "AP_ENTRIES_LIST"
34 #define _AP_PROPERTIES_LIST_ "AP_PROPERTIES_LIST"
35 #define _AP_DUMP_PYTHON_ "AP_DUMP_PYTHON"
40 SALOMEDS_IParameters::SALOMEDS_IParameters(const _PTR(AttributeParameter)& ap)
44 _PTR(SObject) so = _ap->GetSObject();
45 _study = so->GetStudy();
48 SALOMEDS_IParameters::~SALOMEDS_IParameters()
53 int SALOMEDS_IParameters::append(const string& listName, const string& value)
57 if(!_ap->IsSet(listName, PT_STRARRAY)) {
58 if(!_ap->IsSet(_AP_LISTS_LIST_, PT_STRARRAY)) _ap->SetStrArray(_AP_LISTS_LIST_, v);
59 if(listName != _AP_ENTRIES_LIST_ &&
60 listName != _AP_PROPERTIES_LIST_) {
61 append(_AP_LISTS_LIST_, listName);
63 _ap->SetStrArray(listName, v);
65 v = _ap->GetStrArray(listName);
67 _ap->SetStrArray(listName, v);
71 int SALOMEDS_IParameters::nbValues(const string& listName)
74 if(!_ap->IsSet(listName, PT_STRARRAY)) return 0;
75 vector<string> v = _ap->GetStrArray(listName);
79 vector<string> SALOMEDS_IParameters::getValues(const string& listName)
83 if(!_ap->IsSet(listName, PT_STRARRAY)) return v;
84 return _ap->GetStrArray(listName);
88 string SALOMEDS_IParameters::getValue(const string& listName, int index)
91 if(!_ap->IsSet(listName, PT_STRARRAY)) return "";
92 vector<string> v = _ap->GetStrArray(listName);
93 if(index >= v.size()) return "";
97 vector<string> SALOMEDS_IParameters::getLists()
100 if(!_ap->IsSet(_AP_LISTS_LIST_, PT_STRARRAY)) return v;
101 return _ap->GetStrArray(_AP_LISTS_LIST_);
104 void SALOMEDS_IParameters::setParameter(const string& entry, const string& parameterName, const string& value)
108 if(!_ap->IsSet(entry, PT_STRARRAY)) {
109 append(_AP_ENTRIES_LIST_, entry); //Add the entry to the internal list of entries
110 _ap->SetStrArray(entry, v);
112 v = _ap->GetStrArray(entry);
113 v.push_back(parameterName);
115 _ap->SetStrArray(entry, v);
119 string SALOMEDS_IParameters::getParameter(const string& entry, const string& parameterName)
122 if(!_ap->IsSet(entry, PT_STRARRAY)) return "";
123 vector<string> v = _ap->GetStrArray(entry);
124 int length = v.size();
125 for(int i = 0; i<length; i+=1) {
126 if(v[i] == parameterName) return v[i+1];
132 vector<string> SALOMEDS_IParameters::getAllParameterNames(const string& entry)
134 vector<string> v, names;
136 if(!_ap->IsSet(entry, PT_STRARRAY)) return v;
137 v = _ap->GetStrArray(entry);
138 int length = v.size();
139 for(int i = 0; i<length; i+=2) {
140 names.push_back(v[i]);
145 vector<string> SALOMEDS_IParameters::getAllParameterValues(const string& entry)
147 vector<string> v, values;
149 if(!_ap->IsSet(entry, PT_STRARRAY)) return v;
150 v = _ap->GetStrArray(entry);
151 int length = v.size();
152 for(int i = 1; i<length; i+=2) {
153 values.push_back(v[i]);
158 int SALOMEDS_IParameters::getNbParameters(const string& entry)
161 if(!_ap->IsSet(entry, PT_STRARRAY)) return -1;
162 return _ap->GetStrArray(entry).size()/2;
165 vector<string> SALOMEDS_IParameters::getEntries()
169 if(!_ap->IsSet(_AP_ENTRIES_LIST_, PT_STRARRAY)) return v;
170 return _ap->GetStrArray(_AP_ENTRIES_LIST_);
173 void SALOMEDS_IParameters::setProperty(const string& name, const std::string& value)
176 if(!_ap->IsSet(name, PT_STRING)) {
177 append(_AP_PROPERTIES_LIST_, name); //Add the property to the internal list of properties
179 _ap->SetString(name, value);
182 string SALOMEDS_IParameters::getProperty(const string& name)
185 if(!_ap->IsSet(name, PT_STRING)) return "";
186 return _ap->GetString(name);
189 vector<string> SALOMEDS_IParameters::getProperties()
193 if(!_ap->IsSet(_AP_PROPERTIES_LIST_, PT_STRARRAY)) return v;
194 return _ap->GetStrArray(_AP_PROPERTIES_LIST_);
198 vector<string> SALOMEDS_IParameters::parseValue(const string& value, const char separator, bool fromEnd)
203 if(fromEnd) pos = val.rfind(separator);
204 else pos = val.find(separator);
212 part1 = val.substr(0, pos);
213 part2 = val.substr(pos+1, val.size());
219 string SALOMEDS_IParameters::encodeEntry(const string& entry, const string& compName)
221 string tail(entry, 6, entry.length()-1);
222 string newEntry(compName);
223 newEntry+=("_"+tail);
227 string SALOMEDS_IParameters::decodeEntry(const string& entry)
229 if(!_study) return entry;
230 int pos = entry.rfind("_");
231 if(pos < 0 || pos >= entry.length()) return entry;
233 string compName(entry, 0, pos), compID, tail(entry, pos+1, entry.length()-1);
235 if(_compNames.find(compName) == _compNames.end()) {
236 _PTR(SObject) so = _study->FindComponent(compName);
237 if(!so) return entry;
238 compID = so->GetID();
239 _compNames[compName] = compID;
241 else compID = _compNames[compName];
243 string newEntry(compID);
244 newEntry += (":"+tail);
249 void SALOMEDS_IParameters::setDumpPython(_PTR(Study) study, const string& theID)
252 if(theID == "") anID = getDefaultVisualComponent();
255 _PTR(AttributeParameter) ap = study->GetCommonParameters(anID, 0);
256 ap->SetBool(_AP_DUMP_PYTHON_, !isDumpPython(study, theID));
259 bool SALOMEDS_IParameters::isDumpPython(_PTR(Study) study, const string& theID)
262 if(theID == "") anID = getDefaultVisualComponent();
265 _PTR(AttributeParameter) ap = study->GetCommonParameters(anID, 0);
266 if(!ap) return false;
267 if(!ap->IsSet(_AP_DUMP_PYTHON_, PT_BOOLEAN)) return false;
268 return (bool)ap->GetBool(_AP_DUMP_PYTHON_);
271 string SALOMEDS_IParameters::getDefaultVisualComponent()
273 return "Interface Applicative";