f622ba9a8c7a3fb54f6d8f96e795f3f9e129842b
[scilab.git] / scilab / modules / scicos_blocks / macros / Sources / STEP_FUNCTION.sci
1 //  Scicos
2 //
3 //  Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 //
19 // See the file ../license.txt
20 //
21
22 function [x,y,typ]=STEP_FUNCTION(job,arg1,arg2)
23     x=[];
24     y=[];
25     typ=[];
26     select job
27     case "set" then
28         // look for the internal edge trigger block
29         for i=1:length(arg1.model.rpar.objs) do
30             o = arg1.model.rpar.objs(i);
31             if typeof(o) == "Block" & o.gui == "STEP" then
32                 ppath = list(i);
33                 break;
34             end
35         end
36         newpar=list();
37         for path=ppath do
38             np=size(path,"*")
39             spath=list()
40             for k=1:np
41                 spath($+1)="model"
42                 spath($+1)="rpar"
43                 spath($+1)="objs"
44                 spath($+1)=path(k)
45             end
46             xx=arg1(spath)// get the block
47             execstr("xxn="+xx.gui+"(''set'',xx)")
48
49             if diffobjs(xxn,xx) then
50                 model=xx.model
51                 model_n=xxn.model
52                 if ~is_modelica_block(xx) then
53                     modified=or(model.sim<>model_n.sim)|..
54                     ~isequal(model.state,model_n.state)|..
55                     ~isequal(model.dstate,model_n.dstate)|..
56                     ~isequal(model.rpar,model_n.rpar)|..
57                     ~isequal(model.ipar,model_n.ipar)|..
58                     ~isequal(model.label,model_n.label)
59                     if or(model.in<>model_n.in)|or(model.out<>model_n.out) then
60                         // input or output port sizes changed
61                         needcompile=1
62                     end
63                     if or(model.firing<>model_n.firing)  then
64                         // initexe changed
65                         needcompile=2
66                     end
67                     if model.sim=="input"|model.sim=="output" then
68                         if model.ipar<>model_n.ipar then
69                             needcompile=4
70                         end
71                     end
72                     if or(model.blocktype<>model_n.blocktype)|..
73                         or(model.dep_ut<>model_n.dep_ut)  then
74                         // type 'c','d','z','l' or dep_ut changed
75                         needcompile=4
76                     end
77                     if (model.nzcross<>model_n.nzcross)|(model.nmode<>model_n.nmode) then
78                         // size of zero cross changed
79                         needcompile=4
80                     end
81                     if prod(size(model_n.sim))>1 then
82                         if model_n.sim(2)>1000 then  // Fortran or C Block
83                             if model.sim(1)<>model_n.sim(1) then  //function name has changed
84                                 needcompile=4
85                             end
86                         end
87                     end
88                 else //implicit block
89                     //force compilation if an implicit block has been edited
90                     modified=or(model_n<>model)
91                     eq=model.equations;eqn=model_n.equations;
92                     if or(eq.model<>eqn.model)|or(eq.inputs<>eqn.inputs)|..
93                         or(eq.outputs<>eqn.outputs) then
94                         needcompile=4
95                     end
96                 end
97
98                 // parameter or states changed
99                 arg1(spath)=xxn// Update
100                 newpar(size(newpar)+1)=path// Notify modification
101             end
102         end
103         x=arg1
104         y=needcompile
105         typ=newpar
106     case "define" then
107         scs_m_1=scicos_diagram();
108         scs_m_1.objs(1) = STEP("define");
109         scs_m_1.objs(2) = OUT_f("define");
110         scs_m_1.objs(3) = scicos_link();
111         scs_m_1.objs(4) = scicos_link();
112
113         // STEP
114         blk = scs_m_1.objs(1);
115         graphics = blk.graphics;
116         model = blk.model;
117
118         graphics.orig = [0 0];
119         graphics.sz = [40 40];
120
121         graphics.pein = 4;
122         graphics.peout = 4;
123         graphics.pout = 3;
124
125         blk.graphics = graphics;
126         blk.model = model;
127         scs_m_1.objs(1) = blk;
128
129         // OUT_f
130         blk = scs_m_1.objs(2);
131         graphics = blk.graphics;
132         model = blk.model;
133
134         graphics.orig = [80 10];
135         graphics.sz = [20 20];
136
137         graphics.exprs = ["1"];
138         model.ipar = 1;
139
140         graphics.pin = 3;
141
142         blk.graphics = graphics;
143         blk.model = model;
144         scs_m_1.objs(2) = blk;
145
146         // STEP -> OUT_f
147         lnk = scs_m_1.objs(3);
148
149         lnk.from = [1 1 0];
150         lnk.to = [2 1 1];
151
152         scs_m_1.objs(3) = lnk;
153
154         // STEP -> STEP
155         lnk = scs_m_1.objs(4);
156
157         lnk.xx = [0 20  -20 -20 20 1];
158         lnk.yy = [0 -20 -20  60 60 1];
159
160         lnk.ct = [5 -1];
161         lnk.from = [1 1 0];
162         lnk.to = [1 1 1];
163
164         scs_m_1.objs(4) = lnk;
165
166         clear blk lnk
167
168         model=scicos_model();
169         model.sim = "csuper";
170         model.out = 1;
171         model.out2=1;
172         model.outtyp=1;
173
174         model.rpar = scs_m_1;
175
176         gr_i=[]
177         x=standard_define([2 2],model,[],gr_i)
178     end
179 endfunction
180