Xcos: Bug #9995 fixed - The RELATION_OP box drawn.
[scilab.git] / scilab / modules / scicos_blocks / macros / Misc / RELATIONALOP.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] = RELATIONALOP(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         model=arg1.model;
32         if size(exprs,1)==2 then
33             exprs=[exprs;sci2exp(1)];
34         end
35         while %t do
36             [ok,rule,zcr,Datatype,exprs]=scicos_getvalue("Set parameters",..
37             ["Operator: == (0), ~= (1), < (2), <= (3), > (4), >= (5)";..
38             "Use zero crossing (no: 0), (yes: 1)"
39             "Datatype (1=double 3=int32 ...)"],..
40             list("vec",1,"vec",1,"vec",1),exprs)
41             if ~ok then
42                 break,
43             end
44             rule=int(rule);
45             if zcr<>0 then
46                 zcr=1,
47             end
48             if (rule<0)|(rule>5) then
49                 message("Incorrect operator "+string(rule)+" ; must be 0 to 5.")
50                 ok=%f;
51             end
52             if (Datatype==1) then
53                 model.sim=list("relational_op",4)
54             elseif (Datatype==3|Datatype==9) then
55                 model.sim=list("relational_op_i32",4)
56             elseif(Datatype==4) then
57                 model.sim=list("relational_op_i16",4)
58             elseif(Datatype==5) then
59                 model.sim=list("relational_op_i8",4)
60             elseif(Datatype==6) then
61                 model.sim=list("relational_op_ui32",4)
62             elseif(Datatype==7) then
63                 model.sim=list("relational_op_ui16",4)
64             elseif(Datatype==8) then
65                 model.sim=list("relational_op_ui8",4)
66             else
67                 message("Datatype is not supported");
68                 ok=%f;
69             end
70             if ok then
71                 it=Datatype*ones(1,2)
72                 ot=Datatype
73                 in=[-1 -2;-1 -2]
74                 out=[-1 -2]
75                 [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[])
76             end
77             if ok then
78                 if rule == 0 then
79                     label = "==";
80                 elseif rule == 1 then
81                     label = "~=";
82                 elseif rule == 2 then
83                     label = "&lt";
84                 elseif rule == 3 then
85                     label = "&lt=";
86                 elseif rule == 4 then
87                     label = "&gt";
88                 elseif rule == 5 then
89                     label = "&gt=";
90                 end
91                 graphics.exprs=exprs;
92                 graphics.style=["fontSize=13;fontStyle=1;displayedLabel="+label];
93                 model.ipar=[rule],
94                 model.nzcross=zcr,
95                 model.nmode=zcr,
96                 x.graphics=graphics;
97                 x.model=model
98                 break
99             end
100         end
101     case "define" then
102         ipar=[2]
103         label="&lt";
104         model=scicos_model()
105         model.sim=list("relationalop",4)
106         model.in=[1;1]
107         model.out=1
108         model.ipar=ipar
109         model.blocktype="c"
110         model.dep_ut=[%t %f]
111         exprs=[string(ipar);string(0)]
112         gr_i=[]
113         x=standard_define([2 2],model,exprs,gr_i)
114         x.graphics.style=["fontSize=13;fontStyle=1;displayedLabel="+label];
115     end
116 endfunction