* Bug #8784 fixed - Autoscale for cscope graph
[scilab.git] / scilab / modules / scicos_blocks / macros / Sinks / SCALE_CSCOPE.sci
1 //  Scicos
2 //
3 //  Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
4 //  Copyright (C) 2016-2017 - FOSSEE IIT Bombay - Dipti Ghosalkar
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 //
20 // See the file ../license.txt
21 //
22
23 function [x,y,typ]=SCALE_CSCOPE(job,arg1,arg2)
24     x=[];
25     y=[];
26     typ=[];
27     select job
28     case "set" then
29         x=arg1;
30         graphics=arg1.graphics;
31         exprs=graphics.exprs
32
33         model=arg1.model;
34         //dstate=model.in
35         while %t do
36             [ok,clrs,win,wpos,wdim,ymin,ymax,per,N,heritance,nom,autoscale,exprs]=scicos_getvalue(..
37             "Set Scope parameters",..
38             ["Color (>0) or mark (<0) vector (8 entries)";
39             "Output window number (-1 for automatic)";
40             "Output window position";
41             "Output window sizes";
42             "Ymin";
43             "Ymax";
44             "Refresh period";
45             "Buffer size"
46             "Accept herited events 0/1"
47             "Name of Scope (label&Id)"
48             "Auto scaling 0/1"],..     //For autoscaling ON/OFF
49             list("vec",8,"vec",1,"vec",-1,"vec",-1,"vec",1,..
50             "vec",1,"vec",1,"vec",1,"vec",1,"str",1,"vec",1),..
51             exprs)
52             if ~ok then
53                 break,
54             end //user cancel modification
55             mess=[]
56             if size(wpos,"*")<>0 &size(wpos,"*")<>2 then
57                 mess=[mess;"Window position must be [] or a 2 vector";" "]
58                 ok=%f
59             end
60             if size(wdim,"*")<>0 &size(wdim,"*")<>2 then
61                 mess=[mess;"Window dim must be [] or a 2 vector";" "]
62                 ok=%f
63             end
64             if win<-1 then
65                 mess=[mess;"Window number can''t be  < -1";" "]
66                 ok=%f
67             end
68             if per<=0 then
69                 mess=[mess;"Refresh period must be positive";" "]
70                 ok=%f
71             end
72             if N<2 then
73                 mess=[mess;"Buffer size must be at least 2";" "]
74                 ok=%f
75             end
76             if ymin>=ymax then
77                 mess=[mess;"Ymax must be greater than Ymin";" "]
78                 ok=%f
79             end
80             if ~or(heritance==[0 1]) then
81                 mess=[mess;"Accept herited events must be 0 or 1";" "]
82                 ok=%f
83             end
84             if autoscale <> 0 & autoscale <> 1 then
85                 mess=[mess;"Auto scaling must be 0:No or 1:Yes";" "]
86                 ok=%f
87             end
88             if ~ok then
89                 message(["Some specified values are inconsistent:";
90                 " ";mess])
91             end
92             if ok then
93                 [model,graphics,ok]=set_io(model,graphics,list([-1 1],1),list(),ones(1-heritance,1),[])
94             end
95
96             if ok then
97                 if wpos==[] then
98                     wpos=[-1;-1];
99                 end
100                 if wdim==[] then
101                     wdim=[-1;-1];
102                 end
103                 rpar=[autoscale;ymin;ymax;per]
104                 ipar=[win;1;N;clrs(:);wpos(:);wdim(:)]
105                 //if prod(size(dstate))<>(8+1)*N+1 then dstate=-eye((8+1)*N+1,1),end
106                 //model.dstate=[];
107                 model.rpar=rpar;
108                 model.ipar=ipar
109                 model.evtin=ones(1-heritance,1)
110                 model.label=nom;
111                 graphics.id=nom
112                 graphics.exprs=exprs;
113                 x.graphics=graphics;
114                 x.model=model
115                 break
116             end
117         end
118     case "define" then
119         win=-1;
120         wdim=[600;400]
121         wpos=[-1;-1]
122         clrs=[1;3;5;7;9;11;13;15];
123         N=20;
124         ymin=-15;
125         ymax=+15;
126         per=30;
127         autoscale=1;
128
129         model=scicos_model()
130         model.sim=list("scale_cscope",4)
131         model.in=-1
132         model.in2=1
133         model.evtin=1
134         model.rpar=[autoscale;ymin;ymax;per]  //As Oth element was not used, It is now utilise for scaling parameter
135         model.ipar=[win;1;N;clrs;wpos;wdim]
136         model.blocktype="c"
137         model.dep_ut=[%t %f]
138
139         exprs=[strcat(string(clrs)," ");
140         string(win);
141         sci2exp([]);
142         sci2exp(wdim);
143         string(ymin);
144         string(ymax);
145         string(per);
146         string(N);
147         string(0)';
148         emptystr()  //label-id
149         string(autoscale)];
150         gr_i=[]
151         x=standard_define([2 2],model,exprs,gr_i)
152     end
153 endfunction