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
20 #include "model/BaseObject.hxx"
22 namespace org_scilab_modules_scicos
29 std::vector<double> rpar;
30 std::vector<int> ipar;
31 std::vector<int> opar;
33 // opar default value is an empty list
34 Parameter() : rpar(), ipar(), opar(1, 0) {}
39 std::vector<double> state;
40 std::vector<double> dstate;
41 std::vector<int> odstate;
43 // odstate default value is an empty list
44 State() : state(), dstate(), odstate(1, 0) {}
48 * Mask list for all possible block scheduling descriptor from the simulator point of view.
52 * * SUMMATION == DEP_U
54 * * SWITCH_f == DEP_U | DEP_T
58 DEP_U = 1 << 0, //!< y=f(u)
59 DEP_T = 1 << 1, //!< y=f(x)
64 BLOCKTYPE_C = 'c', //!< N/A ; dummy value used to represent a 'c' blocktype (eg. not 'd')
65 BLOCKTYPE_D = 'd', //!< N/A ; dummy value used to represent a 'd' blocktype (eg. not 'c')
66 BLOCKTYPE_H = 'h', //!< N/A ; used to represent blocks composed by blocks
67 BLOCKTYPE_L = 'l', //!< synchronization block ; ifthenelse and eselect
68 BLOCKTYPE_M = 'm', //!< memorization block ; see the Scicos original paper
69 BLOCKTYPE_X = 'x', //!< derivable block without state ; these blocks will be treated as if they contain a state.
70 BLOCKTYPE_Z = 'z', //!< zero-crossing block ; see the Scicos original paper.
75 std::string functionName;
78 char dep_ut; //!< dep_ut_t masked value
79 char blocktype; //!< one of blocktype_t value
81 Descriptor() : functionName(), functionApi(0), dep_ut(0), blocktype(BLOCKTYPE_C) {}
92 Angle() : flip(true), theta(0) {};
93 Angle(const Angle& a) : flip(a.flip), theta(a.theta) {};
94 Angle(const std::vector<double>& a) : flip((a[0] == 0) ? false : true), theta(a[1]) {};
96 void fill(std::vector<double>& a) const
99 a[0] = (flip == false) ? 0 : 1;
102 bool operator==(const Angle& a) const
104 return flip == a.flip && theta == a.theta;
108 class Block: public BaseObject
111 Block() : BaseObject(BLOCK), m_parentDiagram(0), m_interfaceFunction(), m_geometry(), m_angle(),
112 m_exprs(std::vector<std::string> (1, "String")), m_label(), m_style(), m_nzcross(std::vector<int> (1, 0)), m_nmode(std::vector<int> (1, 0)), m_equations(), m_uid(), m_sim(), m_in(), m_out(), m_ein(), m_eout(),
113 m_parameter(), m_state(), m_parentBlock(0), m_children(), m_portReference(0) {};
114 Block(const Block& o) : BaseObject(BLOCK), m_parentDiagram(o.m_parentDiagram), m_interfaceFunction(o.m_interfaceFunction), m_geometry(o.m_geometry),
115 m_angle(o.m_angle), m_exprs(o.m_exprs), m_label(o.m_label), m_style(o.m_style), m_nzcross(o.m_nzcross), m_nmode(o.m_nmode), m_equations(o.m_equations), m_uid(o.m_uid),
116 m_sim(o.m_sim), m_in(o.m_in), m_out(o.m_out), m_ein(o.m_ein), m_eout(o.m_eout), m_parameter(o.m_parameter), m_state(o.m_state), m_parentBlock(o.m_parentBlock),
117 m_children(o.m_children), m_portReference(o.m_portReference) {};
121 friend class ::org_scilab_modules_scicos::Model;
123 void getChildren(std::vector<ScicosID>& v) const
125 v = this->m_children;
128 update_status_t setChildren(const std::vector<ScicosID>& children)
130 if (children == this->m_children)
135 this->m_children = children;
139 void getGeometry(std::vector<double>& v) const
144 update_status_t setGeometry(const std::vector<double>& v)
151 Geometry g = Geometry(v);
161 void getAngle(std::vector<double>& data) const
166 update_status_t setAngle(const std::vector<double>& data)
168 if (data.size() != 2)
173 Angle a = Angle(data);
183 void getExprs(std::vector<std::string>& data) const
188 update_status_t setExprs(const std::vector<std::string>& data)
199 void getLabel(std::string& data) const
204 update_status_t setLabel(const std::string& data)
215 void getIn(std::vector<ScicosID>& v) const
220 update_status_t setIn(const std::vector<ScicosID>& in)
222 if (in == this->m_in)
231 void getInterfaceFunction(std::string& fun) const
233 fun = m_interfaceFunction;
236 update_status_t setInterfaceFunction(const std::string& fun)
238 if (fun == m_interfaceFunction)
243 m_interfaceFunction = fun;
247 void getOut(std::vector<ScicosID>& v) const
252 update_status_t setOut(const std::vector<ScicosID>& out)
254 if (out == this->m_out)
263 void getEin(std::vector<ScicosID>& v) const
268 update_status_t setEin(const std::vector<ScicosID>& ein)
270 if (ein == this->m_ein)
279 void getEout(std::vector<ScicosID>& v) const
284 update_status_t setEout(const std::vector<ScicosID>& eout)
286 if (eout == this->m_eout)
295 const Parameter& getParameter() const
300 void setParameter(const Parameter& parameter)
302 this->m_parameter = parameter;
305 void getParentBlock(ScicosID& v) const
310 update_status_t setParentBlock(ScicosID parentBlock)
312 if (parentBlock == this->m_parentBlock)
317 this->m_parentBlock = parentBlock;
321 void getParentDiagram(ScicosID& v) const
326 update_status_t setParentDiagram(const ScicosID v)
328 if (v == m_parentDiagram)
337 void getPortReference(ScicosID& v) const
342 update_status_t setPortReference(const ScicosID v)
344 if (v == m_portReference)
353 const Descriptor& getSim() const
358 void setSim(const Descriptor& sim)
363 void getStyle(std::string& data) const
368 update_status_t setStyle(const std::string& data)
379 void getNZcross(std::vector<int>& data) const
384 update_status_t setNZcross(const std::vector<int>& data)
386 if (data == m_nzcross)
395 void getNMode(std::vector<int>& data) const
400 update_status_t setNMode(const std::vector<int>& data)
411 void getEquations(std::vector<std::string>& data) const
416 update_status_t setEquations(const std::vector<std::string>& data)
418 if (data == m_equations)
427 void getUID(std::string& data) const
432 update_status_t setUID(const std::string& data)
443 void getRpar(std::vector<double>& data) const
445 data = m_parameter.rpar;
448 update_status_t setRpar(const std::vector<double>& data)
450 if (data == m_parameter.rpar)
455 m_parameter.rpar = data;
459 void getIpar(std::vector<int>& data) const
461 data = m_parameter.ipar;
464 update_status_t setIpar(const std::vector<int>& data)
466 if (data == m_parameter.ipar)
471 m_parameter.ipar = data;
475 void getOpar(std::vector<int>& data) const
477 data = m_parameter.opar;
480 update_status_t setOpar(const std::vector<int>& data)
482 if (data == m_parameter.opar)
487 m_parameter.opar = data;
491 void getSimFunctionName(std::string& data) const
493 data = m_sim.functionName;
496 update_status_t setSimFunctionName(const std::string& data)
498 if (data == m_sim.functionName)
503 m_sim.functionName = data;
507 void getSimFunctionApi(int& data) const
509 data = m_sim.functionApi;
512 update_status_t setSimFunctionApi(const int data)
514 if (data == m_sim.functionApi)
519 m_sim.functionApi = data;
523 void getSimBlocktype(std::string& data) const
525 data = std::string(1, m_sim.blocktype);
528 update_status_t setSimBlocktype(const std::string data)
530 if (data.size() != 1)
535 char c = *(data.c_str());
537 if (c == m_sim.blocktype)
558 void getSimDepUT(std::vector<int>& data) const
561 switch (m_sim.dep_ut)
564 // data is already set to [0 0] here.
581 update_status_t setSimDepUT(const std::vector<int>& data)
583 if (data.size() != 2)
588 int dep = DEP_U & DEP_T;
605 if (dep == m_sim.dep_ut)
614 void getState(std::vector<double>& data) const
616 data = m_state.state;
619 update_status_t setState(const std::vector<double>& data)
621 if (data == m_state.state)
626 m_state.state = data;
630 void getDState(std::vector<double>& data) const
632 data = m_state.dstate;
635 update_status_t setDState(const std::vector<double>& data)
637 if (data == m_state.dstate)
642 m_state.dstate = data;
646 void getODState(std::vector<int>& data) const
648 data = m_state.odstate;
651 update_status_t setODState(const std::vector<int>& data)
653 if (data == m_state.odstate)
658 m_state.odstate = data;
663 ScicosID m_parentDiagram;
664 std::string m_interfaceFunction;
667 std::vector<std::string> m_exprs;
670 std::vector<int> m_nzcross;
671 std::vector<int> m_nmode;
672 std::vector<std::string> m_equations;
677 std::vector<ScicosID> m_in;
678 std::vector<ScicosID> m_out;
679 std::vector<ScicosID> m_ein;
680 std::vector<ScicosID> m_eout;
682 Parameter m_parameter;
686 * SuperBlock: the blocks, links and so on contained into this block
688 ScicosID m_parentBlock;
689 std::vector<ScicosID> m_children;
692 * I/O Blocks: the corresponding parent port
694 ScicosID m_portReference;
697 } /* namespace model */
698 } /* namespace org_scilab_modules_scicos */
700 #endif /* BLOCK_HXX_ */