7ceadd98ee6959c3a4a6ec066424cdb5350de564
[scilab.git] / scilab / modules / scicos_blocks / macros / NonLinear / PRODUCT.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] = PRODUCT(job,arg1,arg2)
23     x=[];y=[];typ=[];
24     select job
25     case "plot" then
26         sgn=arg1.model.ipar
27         standard_draw(arg1)
28     case "getinputs" then
29         [x,y,typ]=standard_inputs(arg1)
30     case "getoutputs" then
31         [x,y,typ]=standard_outputs(arg1)
32     case "getorigin" then
33         [x,y]=standard_origin(arg1)
34     case "set" then
35         x=arg1;
36         graphics=arg1.graphics
37         model=arg1.model
38         exprs=graphics.exprs
39         while %t do
40             [ok,sgn,exprs]=scicos_getvalue(["         Set multiplication block parameters";
41             "(multiplication is set with + 1, division with -1)";""],...
42             "Number of inputs or sign vector",...
43             list("vec",-1),exprs)
44             if ~ok then break,end
45             sgn=sgn(:);
46             if size(sgn,1)==1 then
47                 if sgn<1 then
48                     message("Number of inputs must be > 0")
49                     ok=%f
50                 elseif sgn==1 then
51                     in=-1
52                     sgn=[]
53                     nout=1
54                 else
55                     in=-ones(sgn,1)
56                     sgn=ones(sgn,1)
57                     nout=-1
58                 end
59             else
60                 if ~and(abs(sgn)==1) then
61                     message("Signs can only be +1 or -1")
62                     ok=%f
63                 else
64                     in=-ones(size(sgn,1),1)
65                     nout=-1
66                 end
67             end
68             if ok then
69                 [model,graphics,ok]=check_io(model,graphics,in,nout,[],[])
70             end
71             if ok then
72                 model.ipar=sgn
73                 graphics.exprs=exprs
74                 x.graphics=graphics;x.model=model
75                 break
76             end
77         end
78     case "define" then
79         sgn=[1;-1]
80         model=scicos_model()
81         model.sim=list("product",4)
82         model.in=[-1;-1]
83         model.out=-1
84         model.ipar=sgn
85         model.blocktype="c"
86         model.dep_ut=[%t %f]
87
88
89         exprs=sci2exp(sgn)
90         gr_i=["[x,y,typ]=standard_inputs(o) ";
91         "dd=sz(1)/8,de=0,"
92         "if ~arg1.graphics.flip then dd=6*sz(1)/8,de=-sz(1)/8,end"
93         "for k=1:size(x,''*'')";
94         "if size(sgn,1)>1 then"
95         "  if sgn(k)>0 then";
96         "    xstring(orig(1)+dd,y(k)-4,''*'')";
97         "  else";
98         "    xstring(orig(1)+dd,y(k)-4,''/'')";
99         "  end";
100         "end";
101         "end";
102         "xx=sz(1)*[.8 .8 .4  .4]+orig(1)+de";
103         "yy=sz(2)*[.2 .8 .8  .2]+orig(2)";
104         "xpoly(xx,yy,''lines'')"
105         "txt=''Product'';"
106         "style=5;"
107         "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
108         "if ~exists(''%zoom'') then %zoom=1, end;"
109         "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
110         "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
111         "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
112         "e=gce();"
113         "e.font_style=style;"]
114         x=standard_define([2 3],model, exprs,gr_i)
115     end
116 endfunction