Minsky
schema2.h
Go to the documentation of this file.
1 /*
2  @copyright Steve Keen 2017
3  @author Russell Standish
4  This file is part of Minsky.
5 
6  Minsky is free software: you can redistribute it and/or modify it
7  under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Minsky is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Minsky. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
25 #ifndef SCHEMA_2_H
26 #define SCHEMA_2_H
27 
28 #include "model/minsky.h"
29 #include "model/ravelWrap.h"
30 #include "model/sheet.h"
31 #include "schema/schema1.h"
32 #include "schemaHelper.h"
33 #include "classdesc.h"
34 #include "plotOptions.h"
35 #include "polyXMLBase.h"
36 #include "polyJsonBase.h"
37 #include "simulation.h"
38 #include "ravelState-schema2.h"
39 
40 #include "optional.h"
41 
42 #include <xsd_generate_base.h>
43 #include <vector>
44 #include <string>
45 
46 
47 namespace schema2
48 {
49 
51  using namespace std;
52  using namespace classdesc;
53  using classdesc::shared_ptr;
54  using minsky::Optional;
55 
57  void unpack(classdesc::pack_t&, civita::TensorVal&);
58 
59  struct Note
60  {
62  Note() {}
63  Note(const minsky::NoteBase& x): detailedText(x.detailedText()), tooltip(x.tooltip()) {}
64  Note(const schema1::Item& x): detailedText(x.detailedText), tooltip(x.tooltip) {}
65  };
66 
67  // attribute common to all items
68  struct ItemBase: public minsky::PlotOptions<Note>
69  {
70  int id=-1;
71  std::string type;
72  float x=0, y=0;
73  float zoomFactor=1;
74  double rotation=0;
75  std::vector<int> ports;
76  ItemBase() {}
77  ItemBase(int id, const minsky::Item& it, const std::vector<int>& ports):
78  minsky::PlotOptions<Note>(Note(it)), id(id), type(it.classType()),
79  x(it.m_x), y(it.m_y), zoomFactor(it.zoomFactor()), rotation(it.rotation()),
80  ports(ports) {}
81  ItemBase(const schema1::Item& it, const std::string& type="Item"):
82  PlotOptions<Note>(it), id(it.id), type(type) {}
83  };
84 
85  struct Slider
86  {
87  bool visible=true, stepRel=false;
88  double min, max, step;
89  Slider() {}
90  Slider(bool v, bool stepRel, double min, double max, double step):
91  visible(v), stepRel(stepRel), min(min), max(max), step(step) {}
92  };
93 
94  struct Item: public ItemBase
95  {
97  Optional<std::string> name; //name, description or title
107  // Operation tensor parameters
110  // Godley Icon specific fields
113  Optional<float> iconScale; // for handling legacy schemas
114  // group specific fields
116  Optional<classdesc::CDATA> tensorData; // used for saving tensor data attached to parameters
118 
119  Item() {}
120  // minsky object importers
121  Item(const schema1::Item& it): ItemBase(it) {}
122 
123  // schema1 importers
125  ItemBase(it, "Operation:"+minsky::OperationType::typeName(it.type)),
126  name(it.name), dataOpData(it.data) {
127  if (it.intVar>-1) intVar=it.intVar;
128  ports=it.ports;
129  // rewrite deprecated constants as variables
131  {
132  type="Variable:constant";
133  init.reset(new std::string(std::to_string(it.value)));
134  }
135  }
137  ItemBase(it, "Variable:"+minsky::VariableType::typeName(it.type)),
138  name(it.name), init(it.init) {ports=it.ports;}
139  Item(const schema1::Godley& it);
140  Item(const schema1::Plot& it):
141  ItemBase(it, "PlotWidget"), name(it.title)
142  {
143  logx=it.logx;
144  logy=it.logy;
145  xlabel=it.xlabel;
146  ylabel=it.ylabel;
147  y1label=it.y1label;
148  if (it.legend) legend=*it.legend;
149  ports=it.ports;
150  }
151  Item(const schema1::Group& it): ItemBase(it,"Group"), name(it.name) {}
152  Item(const schema1::Switch& it): ItemBase(it,"SwitchIcon") {ports=it.ports;}
153 
154  void addLayout(const schema1::UnionLayout& layout) {
155  x=layout.x;
156  y=layout.y;
157  rotation=layout.rotation;
158  if (layout.width>=0)
159  width.reset(new float(layout.width));
160  else if (type=="PlotWidget")
161  width.reset(new float(150));
162  if (layout.height>=0)
163  height.reset(new float(layout.height));
164  else if (type=="PlotWidget")
165  height.reset(new float(150));
166  if (layout.sliderBoundsSet)
167  slider.reset(new Slider(layout.sliderVisible,layout.sliderStepRel,
168  layout.sliderMin,layout.sliderMax,layout.sliderStep));
169  }
170  };
171 
172 
173  struct Wire: public Note
174  {
175  int id=-1;
176  int from=-1, to=-1;
178  Wire() {}
179  Wire(const schema1::Wire& w): Note(w), id(w.id), from(w.from), to(w.to) {}
180  void addLayout(const schema1::UnionLayout& layout) {
181  if (layout.coords.size()>4)
182  coords.reset(new std::vector<float>(layout.coords));
183  }
184  };
185 
186  struct Group: public Item
187  {
188  vector<int> items;
190  Group() {}
193  Item(g), items(g.items) {}
194  };
195 
196 
197  struct Minsky
198  {
199  static const int version=2;
200  int schemaVersion=Minsky::version;
201  vector<Wire> wires;
202  vector<Item> items;
203  vector<Group> groups;
205  double zoomFactor=1;
206  vector<minsky::Bookmark> bookmarks;
207  minsky::Dimensions dimensions;
208  minsky::ConversionsMap conversions;
209 
210  Minsky(): schemaVersion(0) {} // schemaVersion defined on read in
211  Minsky(const schema1::Minsky& m);
212 
214  Minsky(classdesc::xml_unpack_t& data): schemaVersion(0)
215  {minsky::loadSchema<schema1::Minsky>(*this,data,"Minsky");}
216  };
217 
218 
219 }
220 
221 
222 #include "schema2.cd"
223 #include "schema2.xcd"
224 
225 #endif
vector< int > ports
Definition: schema1.h:153
Optional< classdesc::CDATA > tensorData
Definition: schema2.h:116
ItemBase(int id, const minsky::Item &it, const std::vector< int > &ports)
Definition: schema2.h:77
Optional< int > lockGroup
Definition: schema2.h:105
shared_ptr< Side > legend
Definition: schema1.h:154
Optional< std::map< double, double > > dataOpData
Definition: schema2.h:102
Note(const minsky::NoteBase &x)
Definition: schema2.h:63
Optional< std::vector< float > > coords
Definition: schema2.h:177
Optional< std::vector< minsky::Bookmark > > bookmarks
Definition: schema2.h:115
Optional< std::string > axis
Definition: schema2.h:108
Optional< Slider > slider
Definition: schema2.h:100
Item(const schema1::Item &it)
Definition: schema2.h:121
vector< Group > groups
Definition: schema2.h:203
void addLayout(const schema1::UnionLayout &layout)
Definition: schema2.h:180
std::string type
Definition: schema2.h:71
Optional< std::string > units
Definition: schema2.h:99
STL namespace.
vector< Wire > wires
Definition: schema2.h:201
Note(const schema1::Item &x)
Definition: schema2.h:64
Optional< float > iconScale
Definition: schema2.h:113
minsky::Dimensions dimensions
Definition: schema2.h:207
string xlabel
Definition: schema1.h:156
convenience class to omit writing XML records when data absent or empty
Definition: optional.h:39
Slider(bool v, bool stepRel, double min, double max, double step)
Definition: schema2.h:90
Optional< double > arg
Definition: schema2.h:109
minsky::OperationType::Type type
Definition: schema1.h:123
Optional< std::vector< minsky::GodleyAssetClass::AssetClass > > assetClasses
Definition: schema2.h:112
Optional< float > width
Definition: schema2.h:96
ItemBase(const schema1::Item &it, const std::string &type="Item")
Definition: schema2.h:81
Item(const schema1::Plot &it)
Definition: schema2.h:140
Wire(const schema1::Wire &w)
Definition: schema2.h:179
struct TCLcmd::trap::init_t init
minsky::Simulation rungeKutta
Definition: schema2.h:204
structure representing a union of all of the above Layout classes, for xml_unpack ...
Definition: schema1.h:313
vector< int > items
Definition: schema2.h:188
Creation and access to the minskyTCL_obj object, which has code to record whenever Minsky&#39;s state cha...
Definition: constMap.h:22
static const int version
Definition: schema2.h:199
Optional< std::string > filename
Definition: schema2.h:103
Item(const schema1::Switch &it)
Definition: schema2.h:152
Item(const schema1::Operation &it)
Definition: schema2.h:124
Optional< RavelState > ravelState
Definition: schema2.h:104
Optional< std::string > init
Definition: schema2.h:98
string ylabel
Definition: schema1.h:156
string y1label
Definition: schema1.h:156
Optional< minsky::Dimensions > dimensions
Definition: schema2.h:106
std::vector< int > ports
Definition: schema2.h:75
void unpack(classdesc::pack_t &b, civita::XVector &a)
Definition: schema2.cc:26
step
Definition: minsky.tcl:1289
Item(const schema1::Variable &it)
Definition: schema2.h:136
Optional< std::vector< ecolab::Plot::LineStyle > > palette
Definition: schema2.h:117
vector< int > ports
Definition: schema1.h:181
vector< Item > items
Definition: schema2.h:202
Optional< std::string > name
Definition: schema2.h:97
void addLayout(const schema1::UnionLayout &layout)
Definition: schema2.h:154
double step
Definition: schema2.h:88
Item(const schema1::Group &it)
Definition: schema2.h:151
Optional< vector< int > > outVariables
Definition: schema2.h:189
Optional< std::string > tooltip
Definition: schema2.h:61
string to_string(CONST84 char *x)
Definition: minskyTCLObj.h:33
vector< int > ports
Definition: schema1.h:141
vector< minsky::Bookmark > bookmarks
Definition: schema2.h:206
Optional< std::vector< std::vector< std::string > > > data
Definition: schema2.h:111
Optional< int > intVar
Definition: schema2.h:101
Group(const schema1::Group &g)
note this assumes that ids have been uniquified prior to this call
Definition: schema2.h:192
vector< float > coords
Definition: schema1.h:259
Minsky(classdesc::xml_unpack_t &data)
populate schema from XML data
Definition: schema2.h:214
minsky::ConversionsMap conversions
Definition: schema2.h:208
vector< int > ports
Definition: schema1.h:125