summaryrefslogtreecommitdiff
path: root/js/IntegerOp/LOGIC.js
blob: eaba81edf109d222b3078279b1b464feb4088465 (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
/* autogenerated from "macros/IntegerOp/LOGIC.sci" */
function LOGIC() {
    LOGIC.prototype.define = function LOGIC() {
        this.mat = [[0],[0],[0],[1]];
        this.model = scicos_model();
        this.model.sim = list(new ScilabString(["logic"]), new ScilabDouble([4]));
        this.model.in = new ScilabDouble([1],[1]);
        this.model.in2 = new ScilabDouble([1],[1]);
        this.model.out = new ScilabDouble([1]);
        this.model.out2 = new ScilabDouble([1]);
        this.model.evtin = new ScilabDouble([1]);
        this.model.intyp = new ScilabDouble([5,5]);
        this.model.outtyp = new ScilabDouble([5]);
        this.model.opar = list(new ScilabDouble([int8(this.mat)]));
        this.model.blocktype = new ScilabString(["c"]);
        this.model.firing = new ScilabBoolean([false]);
        this.model.dep_ut = new ScilabBoolean([true,false]);
        var exprs = [[sci2exp(this.mat)],[sci2exp(0)]];
        var gr_i = new ScilabString(["xstringb(orig(1),orig(2),\"LOGIC\",sz(1),sz(2));"]);
        this.x = new standard_define(new ScilabDouble([2,2]),this.model,new ScilabDouble(exprs),gr_i);
        return new BasicBlock(this.x);
    }
    LOGIC.prototype.details = function LOGIC() {
        return this.x;
    }
    LOGIC.prototype.get = function LOGIC() {
        var options = {
            mat:["Truth Table (matrix of outputs)",this.mat.toString().replace(/,/g," ")],
            herit:["Accepts Inherited Events (0:No, 1:Yes)",this.herit],
        }
        return options;
    }
    LOGIC.prototype.set = function LOGIC() {
        var exprs = this.graphics.exprs;
        while (true) {
            var ok = true;
            this.mat = inverse(arguments[0]["mat"]);
            this.herit = arguments[0]["herit"];
            if (!ok) {
                break;
            }
            var nout = size(this.mat,2);
            var nin = (log(size(this.mat,1))/log(2));
            var u1 = floor(nin);
            if ((u1!=nin)) {
                block_parameter_error(msprintf("Wrong size for \'%s\' parameter: %d.","Truth Table",size(this.mat,1)),"Number of rows must be a power of two.");
                var ok = false;
            } else if ((find(this.mat.slice()!=0&&this.mat.slice()!=1).length!=0)) {
                block_parameter_error(msprintf("Wrong value for \'%s\' parameter.","Truth Table"),msprintf("Elements must be in the interval %s.","[0, 1]"));
                var ok = false;
            } else if (this.herit<0||this.herit>1) {
                block_parameter_error(msprintf("Wrong value for \'%s\' parameter: %d.","Accepts Inherited Events",this.herit),msprintf("Must be in the interval %s.","[0, 1]"));
                var ok = false;
            }
            if (ok) {
                var in1 = [ones(nin,1),ones(nin,1)];
                var out = [ones(nout,1),ones(nout,1)];
                var it = 5*ones(1,nin);
                var ot = 5*ones(1,nout);
                var tmpvar0 = set_io(this.model,this.graphics,list(in1,it),list(out,ot),ones(1-this.herit,1),[]);
                this.model = tmpvar0[0];
                this.graphics = tmpvar0[1];
                var ok = tmpvar0[2];
            }
            if (ok) {
                this.graphics.exprs = new ScilabDouble([exprs]);
                this.mat = int8(this.mat);
                this.model.opar = list(new ScilabDouble([this.mat]));
                this.x.graphics = this.graphics;
                this.x.model = this.model;
                break;
            }
        }
        return new BasicBlock(this.x);
    }
}