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
21 #include "Controller.hxx"
22 #include "ParamsAdapter.hxx"
25 #include "sci_malloc.h"
28 namespace org_scilab_modules_scicos
35 static const wchar_t* scsopt = L"scsopt";
40 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
45 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
47 // The model does not stock wpar.
55 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
57 model::Diagram* adaptee = adaptor.getAdaptee();
60 controller.getObjectProperty(adaptee->id(), adaptee->kind(), TITLE, title);
62 controller.getObjectProperty(adaptee->id(), adaptee->kind(), PATH, path);
64 types::String* o = new types::String(2, 1);
65 o->set(0, title.data());
66 o->set(1, path.data());
71 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
73 if (v->getType() != types::InternalType::ScilabString)
78 model::Diagram* adaptee = adaptor.getAdaptee();
82 types::String* current = v->getAs<types::String>();
83 if (current->getSize() == 1)
87 else if (current->getSize() == 2)
89 char* Path = wide_string_to_UTF8(current->get(1));
90 title = std::string(Path);
98 char* Title = wide_string_to_UTF8(current->get(0));
99 title = std::string(Title);
102 controller.setObjectProperty(adaptee->id(), adaptee->kind(), TITLE, title);
103 controller.setObjectProperty(adaptee->id(), adaptee->kind(), PATH, path);
111 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
113 model::Diagram* adaptee = adaptor.getAdaptee();
116 types::Double* o = new types::Double(7, 1, &data);
118 std::vector<double> tol;
119 controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
121 std::copy(tol.begin() + 1, tol.end(), data);
126 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
129 if (v->getType() != types::InternalType::ScilabDouble)
134 types::Double* current = v->getAs<types::Double>();
135 if (current->getSize() != 7)
140 model::Diagram* adaptee = adaptor.getAdaptee();
142 std::vector<double> tol;
143 controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
145 std::copy(current->getReal(), current->getReal() + current->getSize(), tol.begin() + 1);
147 controller.setObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
155 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
157 model::Diagram* adaptee = adaptor.getAdaptee();
159 std::vector<double> tf;
160 controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tf);
162 return new types::Double(tf[0]);
165 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
168 if (v->getType() != types::InternalType::ScilabDouble)
173 types::Double* current = v->getAs<types::Double>();
174 if (current->getSize() != 1)
179 model::Diagram* adaptee = adaptor.getAdaptee();
181 std::vector<double> tol;
182 controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
184 tol[0] = current->get(0);
186 controller.setObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
194 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
196 model::Diagram* adaptee = adaptor.getAdaptee();
198 std::vector<std::string> context;
199 controller.getObjectProperty(adaptee->id(), adaptee->kind(), CONTEXT, context);
201 types::String* o = new types::String(context.size(), 1);
202 for (size_t i = 0; i < context.size(); ++i)
204 o->set(i, context[i].data());
210 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
212 if (v->getType() == types::InternalType::ScilabString)
214 types::String* current = v->getAs<types::String>();
215 if (current->getCols() != 0 && current->getCols() != 1)
220 model::Diagram* adaptee = adaptor.getAdaptee();
222 std::vector<std::string> context (current->getSize());
223 for (size_t i = 0; i < context.size(); ++i)
225 char* c_str = wide_string_to_UTF8(current->get(i));
226 context[i] = std::string(c_str);
230 controller.setObjectProperty(adaptee->id(), adaptee->kind(), CONTEXT, context);
233 else if (v->getType() == types::InternalType::ScilabDouble)
235 types::Double* current = v->getAs<types::Double>();
236 if (current->getRows() != 0 || current->getCols() != 0)
241 model::Diagram* adaptee = adaptor.getAdaptee();
243 std::vector<std::string> context;
244 controller.setObjectProperty(adaptee->id(), adaptee->kind(), CONTEXT, context);
254 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
256 model::Diagram* adaptee = adaptor.getAdaptee();
258 // Return a dummy 'scsopt'-typed tlist.
259 types::String* header = new types::String(scsopt);
261 types::TList* Scsopt = new types::TList();
262 Scsopt->set(0, header);
266 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
268 // The model does not store 'options'.
275 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
277 return adaptor.getDocContent();
280 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
282 adaptor.setDocContent(v->clone());
289 template<> property<ParamsAdapter>::props_t property<ParamsAdapter>::fields = property<ParamsAdapter>::props_t();
291 ParamsAdapter::ParamsAdapter(const ParamsAdapter& o) :
292 BaseAdapter<ParamsAdapter, org_scilab_modules_scicos::model::Diagram>(o) {}
294 ParamsAdapter::ParamsAdapter(org_scilab_modules_scicos::model::Diagram* o) :
295 BaseAdapter<ParamsAdapter, org_scilab_modules_scicos::model::Diagram>(o)
297 if (property<ParamsAdapter>::properties_have_not_been_set())
299 property<ParamsAdapter>::fields.reserve(10);
300 property<ParamsAdapter>::add_property(L"wpar", &wpar::get, &wpar::set);
301 property<ParamsAdapter>::add_property(L"title", &title::get, &title::set);
302 property<ParamsAdapter>::add_property(L"tol", &tol::get, &tol::set);
303 property<ParamsAdapter>::add_property(L"tf", &tf::get, &tf::set);
304 property<ParamsAdapter>::add_property(L"context", &context::get, &context::set);
305 property<ParamsAdapter>::add_property(L"void1", &wpar::get, &wpar::set);
306 property<ParamsAdapter>::add_property(L"options", &options::get, &options::set);
307 property<ParamsAdapter>::add_property(L"void2", &wpar::get, &wpar::set);
308 property<ParamsAdapter>::add_property(L"void3", &wpar::get, &wpar::set);
309 property<ParamsAdapter>::add_property(L"doc", &doc::get, &doc::set);
312 doc_content = new types::List();
315 ParamsAdapter::~ParamsAdapter()
320 std::wstring ParamsAdapter::getTypeStr()
322 return getSharedTypeStr();
324 std::wstring ParamsAdapter::getShortTypeStr()
326 return getSharedTypeStr();
329 types::InternalType* ParamsAdapter::getDocContent() const
334 void ParamsAdapter::setDocContent(types::InternalType* v)
337 doc_content = v->clone();
340 } /* namespace view_scilab */
341 } /* namespace org_scilab_modules_scicos */