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
17 #include "internal.hxx"
25 #include "utilities.hxx"
26 #include "Controller.hxx"
27 #include "DiagramAdapter.hxx"
28 #include "Adapters.hxx"
29 #include "ParamsAdapter.hxx"
30 #include "TextAdapter.hxx"
31 #include "BlockAdapter.hxx"
32 #include "LinkAdapter.hxx"
33 #include "model/BaseObject.hxx"
36 #include "sci_malloc.h"
37 #include "charEncoding.h"
40 namespace org_scilab_modules_scicos
50 static types::InternalType* get(const DiagramAdapter& adaptor, const Controller& controller)
52 ParamsAdapter localAdaptor = ParamsAdapter(adaptor.getAdaptee());
53 return localAdaptor.getAsTList(new types::TList(), controller);
56 static bool set(DiagramAdapter& adaptor, types::InternalType* v, Controller& controller)
58 ParamsAdapter localAdaptor = ParamsAdapter(adaptor.getAdaptee());
59 return localAdaptor.setAsTList(v, controller);
66 static types::InternalType* get(const DiagramAdapter& adaptor, const Controller& controller)
68 // FIXME: get all children of the Diagram and return them as a list
69 model::Diagram* adaptee = adaptor.getAdaptee();
71 std::vector<ScicosID> children;
72 controller.getObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, children);
74 types::List* o = new types::List();
76 for (int i = 0; i < static_cast<int>(children.size()); ++i)
78 model::BaseObject* item = Controller().getObject(children[i]);
83 model::Annotation* annotation = static_cast<model::Annotation*>(item);
84 TextAdapter* localAdaptor = new TextAdapter(annotation);
85 o->set(i, localAdaptor);
90 model::Block* block = static_cast<model::Block*>(item);
91 BlockAdapter* localAdaptor = new BlockAdapter(block);
92 o->set(i, localAdaptor);
97 model::Link* link = static_cast<model::Link*>(item);
98 LinkAdapter* localAdaptor = new LinkAdapter(link);
99 o->set(i, localAdaptor);
109 static bool set(DiagramAdapter& adaptor, types::InternalType* v, Controller& controller)
111 // FIXME implement, decode the list and set all children of the Diagram
112 if (v->getType() != types::InternalType::ScilabList)
117 model::Diagram* adaptee = adaptor.getAdaptee();
119 types::List* list = v->getAs<types::List>();
120 std::vector<ScicosID> diagramChildren (list->getSize());
121 for (int i = 0; i < list->getSize(); ++i)
123 if (list->get(i)->getType() != types::InternalType::ScilabUserType)
128 // Find the type of the input object through Adapters' mapping.
129 const Adapters::adapters_index_t adapter_index = Adapters::instance().lookup_by_typename(list->get(i)->getShortTypeStr());
131 // Then, each adapter gets linked to the diagram through its adaptee (PARENT_DIAGRAM)
132 // and the diagram's adaptee lists its adaptees (CHILDREN).
134 switch (adapter_index)
136 case Adapters::BLOCK_ADAPTER:
138 BlockAdapter* modelElement = list->get(i)->getAs<BlockAdapter>();
139 model::Block* subAdaptee = modelElement->getAdaptee();
141 controller.setObjectProperty(subAdaptee->id(), subAdaptee->kind(), PARENT_DIAGRAM, adaptee->id());
142 id = subAdaptee->id();
145 case Adapters::LINK_ADAPTER:
147 LinkAdapter* modelElement = list->get(i)->getAs<LinkAdapter>();
148 model::Link* subAdaptee = modelElement->getAdaptee();
150 controller.setObjectProperty(subAdaptee->id(), subAdaptee->kind(), PARENT_DIAGRAM, adaptee->id());
151 id = subAdaptee->id();
154 case Adapters::TEXT_ADAPTER:
156 TextAdapter* modelElement = list->get(i)->getAs<TextAdapter>();
157 model::Annotation* subAdaptee = modelElement->getAdaptee();
159 controller.setObjectProperty(subAdaptee->id(), subAdaptee->kind(), PARENT_DIAGRAM, adaptee->id());
160 id = subAdaptee->id();
167 diagramChildren[i] = id;
170 controller.setObjectProperty(adaptee->id(), adaptee->kind(), CHILDREN, diagramChildren);
178 static types::InternalType* get(const DiagramAdapter& adaptor, const Controller& controller)
180 model::Diagram* adaptee = adaptor.getAdaptee();
183 controller.getObjectProperty(adaptee->id(), adaptee->kind(), VERSION_NUMBER, version);
185 return new types::String(version.data());
188 static bool set(DiagramAdapter& adaptor, types::InternalType* v, Controller& controller)
190 if (v->getType() == types::InternalType::ScilabString)
192 types::String* current = v->getAs<types::String>();
193 if (current->getSize() != 1)
198 model::Diagram* adaptee = adaptor.getAdaptee();
200 char* c_str = wide_string_to_UTF8(current->get(0));
201 std::string version (c_str);
204 controller.setObjectProperty(adaptee->id(), adaptee->kind(), VERSION_NUMBER, version);
207 else if (v->getType() == types::InternalType::ScilabDouble)
209 types::Double* current = v->getAs<types::Double>();
210 if (current->getSize() != 0)
215 model::Diagram* adaptee = adaptor.getAdaptee();
218 controller.setObjectProperty(adaptee->id(), adaptee->kind(), VERSION_NUMBER, version);
229 static types::InternalType* get(const DiagramAdapter& adaptor, const Controller& controller)
231 // silent unused parameter warnings
234 return adaptor.getContribContent();
237 static bool set(DiagramAdapter& adaptor, types::InternalType* v, Controller& controller)
239 // silent unused parameter warnings
243 adaptor.setContribContent(v->clone());
250 template<> property<DiagramAdapter>::props_t property<DiagramAdapter>::fields = property<DiagramAdapter>::props_t();
252 DiagramAdapter::DiagramAdapter(const DiagramAdapter& o) :
253 BaseAdapter<DiagramAdapter, org_scilab_modules_scicos::model::Diagram>(o)
255 contrib_content = new types::List();
258 DiagramAdapter::DiagramAdapter(org_scilab_modules_scicos::model::Diagram* o) :
259 BaseAdapter<DiagramAdapter, org_scilab_modules_scicos::model::Diagram>(o)
261 if (property<DiagramAdapter>::properties_have_not_been_set())
263 property<DiagramAdapter>::fields.reserve(4);
264 property<DiagramAdapter>::add_property(L"props", &props::get, &props::set);
265 property<DiagramAdapter>::add_property(L"objs", &objs::get, &objs::set);
266 property<DiagramAdapter>::add_property(L"version", &version::get, &version::set);
267 property<DiagramAdapter>::add_property(L"contrib", &contrib::get, &contrib::set);
270 contrib_content = new types::List();
273 DiagramAdapter::~DiagramAdapter()
275 delete contrib_content;
278 std::wstring DiagramAdapter::getTypeStr()
280 return getSharedTypeStr();
282 std::wstring DiagramAdapter::getShortTypeStr()
284 return getSharedTypeStr();
287 types::InternalType* DiagramAdapter::getContribContent() const
289 return contrib_content->clone();
292 void DiagramAdapter::setContribContent(types::InternalType* v)
294 delete contrib_content;
295 contrib_content = v->clone();
298 } /* namespace view_scilab */
299 } /* namespace org_scilab_modules_scicos */