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 "ParamsAdapter.hxx"
23 namespace org_scilab_modules_scicos
33 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
38 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
40 // The model does not stock wpar.
48 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
50 model::Diagram* adaptee = adaptor.getAdaptee();
53 controller.getObjectProperty(adaptee->id(), adaptee->kind(), TITLE, title);
55 controller.getObjectProperty(adaptee->id(), adaptee->kind(), PATH, path);
57 types::String* o = new types::String(2, 1);
58 o->set(0, title.data());
59 o->set(1, path.data());
64 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
66 if (v->getType() != types::InternalType::ScilabString)
71 model::Diagram* adaptee = adaptor.getAdaptee();
75 types::String* current = v->getAs<types::String>();
76 if (current->getSize() == 1)
80 else if (current->getSize() == 2)
82 char* Path = wide_string_to_UTF8(current->get(1));
83 title = std::string(Path);
91 char* Title = wide_string_to_UTF8(current->get(0));
92 title = std::string(Title);
95 controller.setObjectProperty(adaptee->id(), adaptee->kind(), TITLE, title);
96 controller.setObjectProperty(adaptee->id(), adaptee->kind(), PATH, path);
104 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
106 model::Diagram* adaptee = adaptor.getAdaptee();
109 types::Double* o = new types::Double(7, 1, &data);
111 std::vector<double> tol;
112 controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
114 std::copy(tol.begin() + 1, tol.end(), data);
119 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
122 if (v->getType() != types::InternalType::ScilabDouble)
127 types::Double* current = v->getAs<types::Double>();
128 if (current->getSize() != 7)
133 model::Diagram* adaptee = adaptor.getAdaptee();
135 std::vector<double> tol;
136 controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
138 std::copy(current->getReal(), current->getReal() + current->getSize(), tol.begin() + 1);
140 controller.setObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
148 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
150 model::Diagram* adaptee = adaptor.getAdaptee();
152 std::vector<double> tf;
153 controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tf);
155 return new types::Double(tf[0]);
158 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
161 if (v->getType() != types::InternalType::ScilabDouble)
166 types::Double* current = v->getAs<types::Double>();
167 if (current->getSize() != 1)
172 model::Diagram* adaptee = adaptor.getAdaptee();
174 std::vector<double> tol;
175 controller.getObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
177 tol[0] = current->get(0);
179 controller.setObjectProperty(adaptee->id(), adaptee->kind(), PROPERTIES, tol);
187 static types::InternalType* get(const ParamsAdapter& adaptor, const Controller& controller)
189 model::Diagram* adaptee = adaptor.getAdaptee();
191 std::vector<std::string> context;
192 controller.getObjectProperty(adaptee->id(), adaptee->kind(), CONTEXT, context);
194 types::String* o = new types::String(context.size(), 1);
195 for (size_t i = 0; i < context.size(); ++i)
197 o->set(i, context[i].data());
203 static bool set(ParamsAdapter& adaptor, types::InternalType* v, Controller& controller)
205 if (v->getType() == types::InternalType::ScilabString)
207 types::String* current = v->getAs<types::String>();
208 if (current->getCols() != 0 && current->getCols() != 1)
213 model::Diagram* adaptee = adaptor.getAdaptee();
215 std::vector<std::string> context (current->getSize());
216 for (size_t i = 0; i < context.size(); ++i)
218 char* c_str = wide_string_to_UTF8(current->get(i));
219 context[i] = std::string(c_str);
223 controller.setObjectProperty(adaptee->id(), adaptee->kind(), CONTEXT, context);
226 else if (v->getType() == types::InternalType::ScilabDouble)
228 types::Double* current = v->getAs<types::Double>();
229 if (current->getRows() != 0 || current->getCols() != 0)
234 model::Diagram* adaptee = adaptor.getAdaptee();
236 std::vector<std::string> context;
237 controller.setObjectProperty(adaptee->id(), adaptee->kind(), CONTEXT, context);
246 template<> property<ParamsAdapter>::props_t property<ParamsAdapter>::fields = property<ParamsAdapter>::props_t();
248 ParamsAdapter::ParamsAdapter(const ParamsAdapter& o) :
249 BaseAdapter<ParamsAdapter, org_scilab_modules_scicos::model::Diagram>(o) {}
251 ParamsAdapter::ParamsAdapter(org_scilab_modules_scicos::model::Diagram* o) :
252 BaseAdapter<ParamsAdapter, org_scilab_modules_scicos::model::Diagram>(o)
254 if (property<ParamsAdapter>::properties_have_not_been_set())
256 property<ParamsAdapter>::fields.reserve(10);
257 property<ParamsAdapter>::add_property(L"wpar", &wpar::get, &wpar::set);
258 property<ParamsAdapter>::add_property(L"title", &title::get, &title::set);
259 property<ParamsAdapter>::add_property(L"tol", &tol::get, &tol::set);
260 property<ParamsAdapter>::add_property(L"tf", &tf::get, &tf::set);
261 property<ParamsAdapter>::add_property(L"context", &context::get, &context::set);
262 property<ParamsAdapter>::add_property(L"void1", &wpar::get, &wpar::set);
263 property<ParamsAdapter>::add_property(L"options", &wpar::get, &wpar::set);
264 property<ParamsAdapter>::add_property(L"void2", &wpar::get, &wpar::set);
265 property<ParamsAdapter>::add_property(L"void3", &wpar::get, &wpar::set);
266 property<ParamsAdapter>::add_property(L"doc", &wpar::get, &wpar::set);
270 ParamsAdapter::~ParamsAdapter()
274 std::wstring ParamsAdapter::getTypeStr()
276 return getSharedTypeStr();
278 std::wstring ParamsAdapter::getShortTypeStr()
280 return getSharedTypeStr();
283 } /* namespace view_scilab */
284 } /* namespace org_scilab_modules_scicos */