summaryrefslogtreecommitdiff
path: root/src/js/xcos/core/details.js
blob: fbeffda26e90b000421e1177ee5b670ec0a958dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// All arrays - separated by ',' or ';' or ' ' are taken to be 1 Dimensional
// Only during printing, their nomenclature will change
// Good read: http://javascript.info/tutorial/arguments#keyword-arguments

function scicos_block() {
	var options = arguments[0] || new Object();
	this.graphics = options.graphics || new scicos_graphics();
	this.model = options.model || new scicos_model();
	this.gui = options.gui || '';
	this.docs = options.docs || [];
}

function scicos_graphics() {
	var options = arguments[0] || new Object();
	this.orig = options.orig || [0, 0];
	this.sz = options.sz || [80, 80]; // Space and comma works the same!
	this.flip = options.flip || true;
	this.theta = options.theta || 0;
	this.exprs = options.exprs || [];
	this.pin = options.pin || [];
	this.pout = options.pout || [];
	this.pein = options.pein || [];
	this.peout = options.peout || [];
	this.gr_i = options.gr_i || [];
	this.id = options.id || '';
	this.in_implicit = options.in_implicit || [];
	this.out_implicit = options.out_implicit || ''; // There is only one!
	this.in_style = options.in_style || [];
	this.out_style = options.out_style || '';
	this.in_label = options.in_label || [];
	this.out_label = options.out_label || '';
	this.style = options.style || '';
}

function scicos_model() {
	var options = arguments[0] || new Object();
	this.sim = options.sim || '';
	this.in = options.in || [];
	this.in2 = options.in2 || [];
	this.intyp = options.intyp || [];
	this.out = options.out || [];
	this.out2 = options.out2 || [];
	this.outtyp = options.outtyp || 1;
	this.evtin = options.evtin || [];
	this.evtout = options.evtout || [];
	this.state = options.state || [];
	this.dstate = options.dstate || [];
	this.odstate = options.odstate || [];
	this.ipar = options.ipar || [];
	this.rpar = options.rpar || [];
	this.opar = options.opar || [];
	this.blocktype = options.blocktype || 'c';
	this.firing = options.firing || [];
	this.dep_ut = options.dep_ut || [false, false];
	this.label = options.label || ''; // If label not available, use image
	this.nzcross = options.nzcross || 0;
	this.nmode = options.nmode || 0;
	this.equations = options.equations || [];
	this.uid = options.uid || '';	
}

// This might also have to be overloaded
function scicos_diagram() {
	this.props = new scicos_params();
	this.objs = [];
	this.version = '';
	this.contrib = [];
}

// This might also have to be overloaded
function scicos_params() {
	this.wpar = [600, 450, 0, 0, 600, 450];
	this.titlex = 'Untitled';
	this.tf = 100000;
	this.tol = [Math.pow(10, -6), Math.pow(10, -6), Math.pow(10, -10), this.tf+1, 0, 1, 0];
	this.context = [];
	this.void1 = [];
	this.options = new default_options();
	this.void2 = [];
	this.void3 = [];
	this.doc = [];
}

// This might also have to be overloaded
function default_options() {
	var options = new Object();
    var col3d = [0.8, 0.8, 0.8];
    options['3D'] = [true, 33];
    options['Background'] = [8, 1]; // white,black
    options['Link'] = [1, 5]; // black,red
    options['ID'] = [[4, 1, 10, 1], [4, 1, 2, 1]];
    options['Cmap'] = col3d;
    return options;
}

function zeros(n){
	return new Array(n+1).join('0').split('').map(parseFloat);
}

function standard_define() {
	var sz = arguments[0];
	var model = arguments[1];
	var label = arguments[2];
	var gr_i = arguments[3] || [];
	
	var pin = [];
	var pout = [];
	var pein = [];
	var peout = [];
	
	var nin = model.in.length;
	if(nin > 0){
		pin = zeros(nin);
	}
	var nout = model.out.length;
	if(nout > 0){
		pout = zeros(nout);
	}
	var ncin = model.evtin.length;
	if(ncin > 0){
		pein = zeros(ncin);
	}
	var ncout = model.evtout.length;
	if(ncout > 0){
		peout = zeros(ncout);
	}
	gr_i = [gr_i, 8];
	if(gr_i[1] == []){
		gr_i[1] = 8;
	}
	if(gr_i[1] == 0){
		gr_i[1] = [];
	}
	var graphics_options = {
	  sz: sz,
	  pin: pin,
	  pout: pout,
	  pein: pein,
	  peout: peout,
	  gr_i: gr_i,
	  exprs: label
	};
	var graphics = new scicos_graphics(graphics_options);
	var block_options = {
	  graphics: graphics,
	  model: model,
	  gui: arguments.callee.caller.name
	};
	return new scicos_block(block_options);
}

function scicos_link (){
	this.xx = [];
	this.yy = [];
	this.id = '';
	this.thick = [0, 0];
	this.ct = [1, 1];
	this.from = [];
	this.to = [];
}

function ANDLOG_f(){
    var model = new scicos_model();
    model.sim = "andlog";
    model.out = [1];
    model.out2 = [1]; // null -> 1
    model.evtin = [-1,-1]; // 1, 1 -> -1, -1
    model.blocktype = "d";
    model.firing = [];
    model.dep_ut = [false, false];
    var gr_i = "xstringb(orig(1),orig(2),txt,sz(1),sz(2),'fill');";
    var block = new standard_define([80,80], model, 'LOGICAL<BR>AND', gr_i); // 3 -> 80
    
    // Style
    block.graphics.out_implicit = "E";
    block.graphics.out_style = "ExplicitOutputPort;align=right;verticalAlign=middle;spacing=10.0;rotation=0";
    block.graphics.style = "ANDLOG_f";
    return block;
}