Xcos: Bug #9995 fixed - LOGICAL_OP drawing the parameters over block.
[scilab.git] / scilab / modules / scicos_blocks / macros / Misc / LOGICAL_OP.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]=LOGICAL_OP(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
33         if size(exprs,1)==2 then
34             exprs=[exprs;sci2exp(1);sci2exp(0)];
35         end
36         while %t do
37             [ok,nin,rule,Datatype,tp,exprs]=scicos_getvalue("Set parameters",..
38             ["number of inputs";..
39             "Operator: AND (0), OR (1), NAND (2), NOR (3), XOR (4), NOT (5)"
40             "Datatype (1=double 3=int32 ...)";..
41             "Bitwise Rule(0=No 1=yes)"],..
42             list("vec",1,"vec",1,"vec",1,"vec",1),exprs)
43             if ~ok then
44                 break,
45             end
46             nin=int(nin);
47             rule=int(rule);
48             tp=int(tp)
49             if nin<1 then
50                 message("Number of inputs must be >=1 ");
51                 ok=%f
52             elseif (rule<0)|(rule>5) then
53                 message("Incorrect operator "+string(rule)+" ; must be 0 to 5.");
54                 ok=%f
55             elseif (rule==5)&(nin>1) then
56                 message("Only one input allowed for NOT operation")
57                 nin=1
58             elseif ((Datatype==1)&(tp~=0))
59                 message ("Bitwise Rule is only activated when Data type is integer");
60                 ok=%f
61             end
62             if ok then
63                 if (tp~=0) then
64                     tp=1;
65                 end
66                 if Datatype==1 then
67                     model.sim=list("logicalop",4)
68                     model.ipar=[rule],
69                 else
70                     if Datatype==3 then
71                         model.sim=list("logicalop_i32",4)
72                     elseif Datatype==4 then
73                         model.sim=list("logicalop_i16",4)
74                     elseif Datatype==5 then
75                         model.sim=list("logicalop_i8",4)
76                     elseif Datatype==6 then
77                         model.sim=list("logicalop_ui32",4)
78                     elseif Datatype==7 then
79                         model.sim=list("logicalop_ui16",4)
80                     elseif Datatype==8 then
81                         model.sim=list("logicalop_ui8",4)
82                     else
83                         message ("Datatype is not supported");
84                         ok=%f;
85                     end
86                     model.ipar=[rule;tp];
87                 end
88                 if ok then
89                     it=Datatype*ones(nin,1);
90                     ot=Datatype;
91                     in=[-ones(nin,1) -2*ones(nin,1)]
92                     if (rule<>5)&(nin==1) then
93                         out=[1 1]
94                         [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[])
95                     else
96                         out=[-1 -2]
97                         [model,graphics,ok]=set_io(model,graphics,list(in,it),list(out,ot),[],[])
98                     end
99                 end
100                 if ok then
101                     if rule == 0 then
102                         label = "AND";
103                     elseif rule == 1 then
104                         label = "OR";
105                     elseif rule == 2 then
106                         label = "NAND";
107                     elseif rule == 3 then
108                         label = "NOR";
109                     elseif rule == 4 then
110                         label = "XOR";
111                     elseif rule == 5 then
112                         label = "NOT";
113                     end
114                     graphics.exprs=exprs;
115                     graphics.style = ["blockWithLabel;displayedLabel="+label];
116                     x.graphics=graphics;
117                     x.model=model
118                     break
119                 end
120             end
121         end
122     case "define" then
123         in=[-1;-1]
124         ipar=[0]
125         nin=2
126
127         model=scicos_model()
128         model.sim=list("logicalop",4)
129         model.in=in
130         model.out=-1
131         model.ipar=ipar
132         model.blocktype="c"
133         model.dep_ut=[%t %f]
134
135         exprs=[string(nin);string(ipar)]
136         gr_i=[]
137         x=standard_define([3 2],model,exprs,gr_i)
138     end
139 endfunction