summaryrefslogtreecommitdiff
path: root/js/IntegerOp/LOGIC.js
blob: d4ebdf7c5cd3ec02bed9b258172ffee6b92e3f25 (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
/* autogenerated from "macros/IntegerOp/LOGIC.sci" */
function LOGIC() {
    LOGIC.prototype.define = function LOGIC() {
        mat = [[0],[0],[0],[1]];
        model = scicos_model();
        model.sim = list("logic",4);
        model.in1 = [[1],[1]];
        model.in2 = [[1],[1]];
        model.out = 1;
        model.out2 = 1;
        model.evtin = 1;
        model.intyp = [5,5];
        model.outtyp = 5;
        model.opar = list(int8(mat));
        model.blocktype = "c";
        model.firing = false;
        model.dep_ut = [true,false];
        exprs = [[sci2exp(mat)],[sci2exp(0)]];
        gr_i = [];
        this.x = standard_define([2,2],model,exprs,gr_i);
    }
    LOGIC.prototype.details = function LOGIC() {
        return this.x;
    }
    LOGIC.prototype.get = function LOGIC() {
    }
    LOGIC.prototype.set = function LOGIC() {
        this.x = arg1;
        graphics = arg1.graphics;
        exprs = graphics.exprs;
        model = arg1.model;
        while (true) {
            [ok,mat,herit,exprs] = scicos_getvalue([[msprintf(gettext("Set %s block parameters"),"LOGIC")],[" "],[gettext("Combinatorial logic")],[" "],[gettext("  Rows of the matrix are the output values")],[gettext("  Number of rows must be a power of two.")],[gettext("  Number of columns gives the number of outputs.")],[" "]],[[gettext("Truth Table (matrix of outputs)")],[gettext("Accepts Inherited Events (0:No, 1:Yes)")]],list("mat",[-1,-2],"vec",1),exprs);
            if (!ok) {
                break;
            }
            nout = size(mat,2);
            nin = (log(size(mat,1))/log(2));
            u1 = floor(nin);
            if ((u1!=nin)) {
                block_parameter_error(msprintf(gettext("Wrong size for \'%s\' parameter: %d."),gettext("Truth Table"),size(mat,1)),gettext("Number of rows must be a power of two."));
                ok = false;
            } else if ((find(mat.slice()!=0&&mat.slice()!=1)!=[])) {
                block_parameter_error(msprintf(gettext("Wrong value for \'%s\' parameter."),gettext("Truth Table")),msprintf(gettext("Elements must be in the interval %s."),"[0, 1]"));
                ok = false;
            } else if (herit<0||herit>1) {
                block_parameter_error(msprintf(gettext("Wrong value for \'%s\' parameter: %d."),gettext("Accepts Inherited Events"),herit),msprintf(gettext("Must be in the interval %s."),"[0, 1]"));
                ok = false;
            }
            if (ok) {
                in1 = [ones(nin,1),ones(nin,1)];
                out = [ones(nout,1),ones(nout,1)];
                it = 5*ones(1,nin);
                ot = 5*ones(1,nout);
                [model,graphics,ok] = set_io(model,graphics,list(in1,it),list(out,ot),ones(1-herit,1),[]);
            }
            if (ok) {
                graphics.exprs = exprs;
                mat = int8(mat);
                model.opar = list(mat);
                this.x.graphics = graphics;
                this.x.model = model;
                break;
            }
        }
    }
}