* Bug 16320 fixed: typos in blocks interfaces + a few files
[scilab.git] / scilab / modules / scicos_blocks / macros / Sinks / CMSCOPE.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] = CMSCOPE(job,arg1,arg2)
23     x=[];
24     y=[];
25     typ=[];
26     select job
27     case "set" then
28         x=arg1;
29         graphics=arg1.graphics;
30         exprs=graphics.exprs
31
32         model=arg1.model;
33         //dstate=model.in
34         //pause
35         while %t do
36             [ok,in,clrs,win,wpos,wdim,ymin,ymax,per,N,heritance,nom,exprs]=..
37             scicos_getvalue(msprintf(_("Set %s block parameters"), "CMSCOPE"),..
38              _(["Input ports sizes";
39                 "Curves styles: Colors>0 | marks<0";
40                 "Output window number (-1 for automatic)";
41                 "Output window position";
42                 "Output window sizes";
43                 "Ymin vector";
44                 "Ymax vector";
45                 "Refresh periods";
46                 "Buffer size";
47                 "Accept herited events 0/1";
48                 "Name of Scope (label&Id)"]),..
49             list("vec",-1,"vec",-1,"vec",1,"vec",-1,"vec",-1,..
50             "vec","size(%1,''*'')","vec","size(%1,''*'')","vec","size(%1,''*'')",..
51             "vec",1,"vec",1,"str",1), exprs)
52             if ~ok then
53                 break,
54             end //user cancel modification
55             mess = []
56             if size(in,"*")<=0 then
57                 mess=[mess ; _("The block must have at least one input port"); " "]
58             end
59             if min(in)<=0 then
60                 mess=[mess ; _("Port sizes must be > 0") ; " "]
61             end
62             if size(clrs,"*")<sum(in) then
63                 msg = _("At least %d curves styles expected.")
64                 mess=[mess ; msprintf(msg, sum(in)) ; " "]
65             end
66             if size(wpos,"*")<>0 &size(wpos,"*")<>2 then
67                 mess = [mess ; _("''Window position'' must be [] or a 2 vector") ; " "]
68             end
69             if size(wdim,"*")<>0 &size(wdim,"*")<>2 then
70                 mess = [mess ; _("''Window sizes'' must be [] or a 2 vector") ; " "]
71             end
72             if win<-1 then
73                 mess=[mess ; _("The Window number must be >= -1") ; " "]
74             end
75             if size(per,"*")<>size(ymin,"*") then
76                 mess=[mess ; 
77                       _("The size of ''Refresh Periods'' must match the Ymin|Ymax''s one");
78                       " "]
79             end
80             for i = 1:size(per,"*")
81                 if (per(i)<=0) then
82                     mess=[mess ; _("All Refresh Periods must be > 0") ; " "]
83                 end
84             end
85             if N<2 then
86                 mess=[mess ; _("The Buffer size must be >= 2") ; " "]
87             end
88             if or(ymin>=ymax) then
89                 mess=[mess ; _("Ymax > Ymin is required") ; " "]
90             end
91             if ~or(heritance==[0 1]) then
92                 mess=[mess ; _("''Accept herited events'' must be 0 or 1") ; " "]
93             end
94
95             if mess <> [] then
96                 message([_("Some specified values are inconsistent:");
97                 " ";mess])
98             else
99                 in = in(:);
100                 a = size(in,1);
101                 in2 = ones(a,1);
102                 [model,graphics,ok]=set_io(model,graphics,list([in in2],ones(a,1)),list(),ones(1-heritance,1),[]);
103
104                 if wpos==[] then
105                     wpos=[-1;-1];
106                 end
107                 if wdim==[] then
108                     wdim=[-1;-1];
109                 end
110                 period=per(:)';
111                 yy=[ymin(:)';ymax(:)']
112                 rpar=[0;period(:);yy(:)]
113                 clrs=clrs(1:sum(in))
114                 ipar=[win;size(in,"*");N;wpos(:);wdim(:);in(:);clrs(:);heritance]
115                 //if prod(size(dstate))<>(sum(in)+1)*N+1 then
116                 //dstate=-eye((sum(in)+1)*N+1,1),
117                 //end
118                 model.evtin=ones(1-heritance,1)
119                 model.dstate=[]
120                 //model.dstate=dstate;
121                 model.rpar=rpar;
122                 model.ipar=ipar
123                 model.label=nom;
124                 graphics.id=nom;
125                 graphics.exprs=exprs;
126                 x.graphics=graphics;
127                 x.model=model
128                 //pause;
129                 break
130             end
131         end
132
133     case "define" then
134         win=-1;
135         in=[1;1]
136         wdim=[-1;-1]
137         wpos=[-1;-1]
138         clrs=[1;3;5;7;9;11;13;15];
139         N=20;
140
141         ymin=[-1;-5];
142         ymax=[1;5];
143         per=[30;30];
144         yy=[ymin(:)';ymax(:)']
145         period=per(:)'
146         model=scicos_model()
147         model.sim=list("cmscope",4)
148         model.in=in
149         model.in2=[1;1]
150         model.intyp=[1;1]
151         model.evtin=1
152         model.rpar=[0;period(:);yy(:)]
153         model.ipar=[win;size(in,"*");N;wpos(:);wdim(:);in(:);clrs(1:sum(in))]
154         model.blocktype="c"
155         model.dep_ut=[%t %f]
156
157         exprs=[strcat(string(in)," ");
158         strcat(string(clrs)," ");
159         string(win);
160         sci2exp([]);
161         sci2exp([]);
162         strcat(string(ymin)," ");
163         strcat(string(ymax)," ");
164         strcat(string(per)," ");
165         string(N);
166         string(0);
167         emptystr()];
168         gr_i=[]
169         x=standard_define([2 2],model,exprs,gr_i)
170     end
171 endfunction