2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2014-2014 - Scilab Enterprises - Clement DAVID
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
23 #include "utilities.hxx"
24 #include "Controller.hxx"
25 #include "ParamsAdapter.hxx"
28 #include "sci_malloc.h"
29 #include "charEncoding.h"
32 namespace org_scilab_modules_scicos
39 const std::wstring scsopt(L"scsopt");
40 const std::wstring ThreeD(L"3D");
41 const std::wstring Background(L"Background");
42 const std::wstring Link(L"Link");
43 const std::wstring ID(L"ID");
44 const std::wstring Cmap(L"Cmap");
49 static types::InternalType* get(const ParamsAdapter& /*adaptor*/, const Controller& /*controller*/)
51 // Return a default empty matrix.
52 return types::Double::Empty();
55 static bool set(ParamsAdapter& /*adaptor*/, types::InternalType* /*v*/, Controller& /*controller*/)
57 // everything should be right as the properties mapped using this adapter do not perform anything
65 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
67 ScicosID adaptee = adaptor.getAdaptee()->id();
70 controller.getObjectProperty(adaptee, DIAGRAM, TITLE, title);
72 controller.getObjectProperty(adaptee, DIAGRAM, PATH, path);
74 types::String* o = new types::String(2, 1);
75 o->set(0, title.data());
76 o->set(1, path.data());
81 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
83 if (v->getType() != types::InternalType::ScilabString)
88 ScicosID adaptee = adaptor.getAdaptee()->id();
92 types::String* current = v->getAs<types::String>();
93 if (current->getSize() == 1)
97 else if (current->getSize() == 2)
99 char* Path = wide_string_to_UTF8(current->get(1));
100 path = std::string(Path);
108 char* Title = wide_string_to_UTF8(current->get(0));
109 title = std::string(Title);
112 controller.setObjectProperty(adaptee, DIAGRAM, TITLE, title);
113 controller.setObjectProperty(adaptee, DIAGRAM, PATH, path);
121 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
123 ScicosID adaptee = adaptor.getAdaptee()->id();
126 types::Double* o = new types::Double(1, 7, &data);
128 std::vector<double> tol;
129 controller.getObjectProperty(adaptee, DIAGRAM, PROPERTIES, tol);
131 std::copy(tol.begin() + 1, tol.end(), stdext::checked_array_iterator<double*>( data, 7 ));
133 std::copy(tol.begin() + 1, tol.end(), data);
139 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
142 if (v->getType() != types::InternalType::ScilabDouble)
147 types::Double* current = v->getAs<types::Double>();
148 if (current->getSize() != 6 && current->getSize() != 7)
153 ScicosID adaptee = adaptor.getAdaptee()->id();
155 std::vector<double> tol;
156 controller.getObjectProperty(adaptee, DIAGRAM, PROPERTIES, tol);
158 std::copy(current->getReal(), current->getReal() + current->getSize(), tol.begin() + 1);
160 // In case the last parameter is missing
161 if (current->getSize() == 6)
166 controller.setObjectProperty(adaptee, DIAGRAM, PROPERTIES, tol);
174 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
176 ScicosID adaptee = adaptor.getAdaptee()->id();
178 std::vector<double> tf;
179 controller.getObjectProperty(adaptee, DIAGRAM, PROPERTIES, tf);
181 return new types::Double(tf[0]);
184 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
187 if (v->getType() != types::InternalType::ScilabDouble)
192 types::Double* current = v->getAs<types::Double>();
193 if (current->getSize() != 1)
198 ScicosID adaptee = adaptor.getAdaptee()->id();
200 std::vector<double> tol;
201 controller.getObjectProperty(adaptee, DIAGRAM, PROPERTIES, tol);
203 tol[0] = current->get(0);
205 controller.setObjectProperty(adaptee, DIAGRAM, PROPERTIES, tol);
213 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
215 ScicosID adaptee = adaptor.getAdaptee()->id();
217 std::vector<std::string> context;
218 controller.getObjectProperty(adaptee, DIAGRAM, DIAGRAM_CONTEXT, context);
220 if (context.size() == 0)
222 // An empty context returns an empty matrix
223 return types::Double::Empty();
226 types::String* o = new types::String((int)context.size(), 1);
227 for (int i = 0; i < (int)context.size(); ++i)
229 o->set(i, context[i].data());
235 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
237 if (v->getType() == types::InternalType::ScilabString)
239 types::String* current = v->getAs<types::String>();
240 // Only allow vectors and empty matrices
241 if (!current->isVector() && current->getSize() != 0)
246 ScicosID adaptee = adaptor.getAdaptee()->id();
248 std::vector<std::string> context (current->getSize());
249 for (int i = 0; i < (int)context.size(); ++i)
251 char* c_str = wide_string_to_UTF8(current->get(i));
252 context[i] = std::string(c_str);
256 controller.setObjectProperty(adaptee, DIAGRAM, DIAGRAM_CONTEXT, context);
259 else if (v->getType() == types::InternalType::ScilabDouble)
261 types::Double* current = v->getAs<types::Double>();
262 if (!current->isEmpty())
267 ScicosID adaptee = adaptor.getAdaptee()->id();
269 std::vector<std::string> context;
270 controller.setObjectProperty(adaptee, DIAGRAM, DIAGRAM_CONTEXT, context);
280 static types::InternalType* get(const ParamsAdapter& /*adaptor*/, const Controller& /*controller*/)
282 // Return a default 'scsopt'-typed tlist.
283 types::String* header = new types::String(1, 6);
284 header->set(0, scsopt.c_str());
285 header->set(1, ThreeD.c_str());
286 header->set(2, Background.c_str());
287 header->set(3, Link.c_str());
288 header->set(4, ID.c_str());
289 header->set(5, Cmap.c_str());
291 types::TList* Scsopt = new types::TList();
292 Scsopt->append(header);
294 types::List* ThreeDField = new types::List();
295 types::Bool* ThreeD1 = new types::Bool(1);
296 ThreeDField->append(ThreeD1);
297 types::Double* ThreeD2 = new types::Double(33);
298 ThreeDField->append(ThreeD2);
299 Scsopt->append(ThreeDField);
301 types::Double* BackgroundField = new types::Double(1, 2);
302 BackgroundField->set(0, 8);
303 BackgroundField->set(1, 1);
304 Scsopt->append(BackgroundField);
306 types::Double* LinkField = new types::Double(1, 2);
307 LinkField->set(0, 1);
308 LinkField->set(1, 5);
309 Scsopt->append(LinkField);
311 types::List* IDField = new types::List();
312 types::Double* ID1 = new types::Double(1, 4);
317 IDField->append(ID1);
318 types::Double* ID2 = new types::Double(1, 4);
323 IDField->append(ID2);
324 Scsopt->append(IDField);
326 types::Double* CmapField = new types::Double(1, 3);
327 CmapField->set(0, 0.8);
328 CmapField->set(1, 0.8);
329 CmapField->set(2, 0.8);
330 Scsopt->append(CmapField);
335 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
337 // The model does not store 'options'.
338 return dummy_property::set(adaptor, v, controller);
344 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& /*controller*/)
346 return adaptor.getDocContent();
349 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& /*controller*/)
351 adaptor.setDocContent(v->clone());
358 template<> property<ParamsAdapter>::props_t property<ParamsAdapter>::fields = property<ParamsAdapter>::props_t();
359 static void initialize_fields()
361 if (property<ParamsAdapter>::properties_have_not_been_set())
363 property<ParamsAdapter>::fields.reserve(10);
364 property<ParamsAdapter>::add_property(L"wpar", &dummy_property::get, &dummy_property::set);
365 property<ParamsAdapter>::add_property(L"title", &title::get, &title::set);
366 property<ParamsAdapter>::add_property(L"tol", &tol::get, &tol::set);
367 property<ParamsAdapter>::add_property(L"tf", &tf::get, &tf::set);
368 property<ParamsAdapter>::add_property(L"context", &context::get, &context::set);
369 property<ParamsAdapter>::add_property(L"void1", &dummy_property::get, &dummy_property::set);
370 property<ParamsAdapter>::add_property(L"options", &options::get, &options::set);
371 property<ParamsAdapter>::add_property(L"void2", &dummy_property::get, &dummy_property::set);
372 property<ParamsAdapter>::add_property(L"void3", &dummy_property::get, &dummy_property::set);
373 property<ParamsAdapter>::add_property(L"doc", &doc::get, &doc::set);
377 ParamsAdapter::ParamsAdapter() :
378 BaseAdapter<ParamsAdapter, org_scilab_modules_scicos::model::Diagram>(),
379 doc_content(new types::List())
384 ParamsAdapter::ParamsAdapter(const Controller& c, org_scilab_modules_scicos::model::Diagram* adaptee) :
385 BaseAdapter<ParamsAdapter, org_scilab_modules_scicos::model::Diagram>(c, adaptee),
386 doc_content(new types::List())
391 ParamsAdapter::~ParamsAdapter()
393 doc_content->DecreaseRef();
394 doc_content->killMe();
397 std::wstring ParamsAdapter::getTypeStr()
399 return getSharedTypeStr();
401 std::wstring ParamsAdapter::getShortTypeStr()
403 return getSharedTypeStr();
406 types::InternalType* ParamsAdapter::getDocContent() const
408 doc_content->IncreaseRef();
412 void ParamsAdapter::setDocContent(types::InternalType* v)
414 doc_content->DecreaseRef();
415 doc_content->killMe();
421 } /* namespace view_scilab */
422 } /* namespace org_scilab_modules_scicos */