mResistor - Modified Resistor block
[x,y,typ] = mResistor(job,arg1,arg2)
- job : add here the parameter description
- arg1 : add here the parameter description
- arg2 : add here the parameter description
- x : add here the parameter description
- y : add here the parameter description
- typ : add here the parameter description
function [x,y,typ]=mResistor(job,arg1,arg2)
// Copyright INRIA
// exemple d'un bloc implicit,
// - sans entree ni sortie de conditionnement
// - avec une entree et une sortie de type implicit et de dimension 1
// - avec un dialogue de saisie de parametre
x=[];y=[];typ=[];
select job
case 'plot' then
R=arg1.graphics.exprs;
standard_draw(arg1,%f,mResistor_draw_ports)
//standard_draw(arg1,%f,bidon_draw_ports)
case 'getinputs' then
[x,y,typ]=mResistor_inputs(arg1)
case 'getoutputs' then
[x,y,typ]=mResistor_outputs(arg1)
case 'getorigin' then
[x,y]=standard_origin(arg1)
case 'set' then
x=arg1;
graphics=arg1.graphics;exprs=graphics.exprs
model=arg1.model;
while %t do
[ok,R,exprs]=getvalue('Set Resistor block parameter',..
'R (ohm)',list('vec',1),exprs)
if ~ok then break,end
model.rpar=R
model.equations.parameters(2)=list(R)
graphics.exprs=exprs
x.graphics=graphics;x.model=model
break
end
case 'define' then
model=scicos_model()
R=0.01
model.rpar=R
model.sim='resistor'
model.blocktype='c'
model.dep_ut=[%t %f]
mo=modelica()
mo.model='Resistor'
mo.inputs='p';
mo.outputs='n';
mo.parameters=list('R',list(R))
model.equations=mo
model.in=ones(size(mo.inputs,'*'),1)
model.out=ones(size(mo.outputs,'*'),1)
exprs=string(R)
gr_i=[ 'if orient==0|orient==1|orient==%T|orient==%f then';
'xx=[0,1,1,7,7,8,7,7,1,1]/8;';
'yy=[1,1,0,0,1,1,1,2,2,1]/2;';
'rect=xstringl(0,0,''R=''+R);'
'xstring(orig(1)+(sz(1)-rect(3))/2,orig(2)-rect(4)*1.2,''R=''+R);';
'else'
'yy=[0,1,1,7,7,8,7,7,1,1]/8;';
'xx=[1,1,0,0,1,1,1,2,2,1]/2;';
'rect=xstringl(0,0,''R=''+R);'
'xstring(orig(1)+rect(3)*0.5,orig(2)+(sz(2)-rect(4))/2,''R=''+R);'
'end'
'xpoly(orig(1)+xx*sz(1),orig(2)+yy*sz(2));'
]
x=standard_define([2 0.18],model,exprs,list(gr_i,0))
x.graphics.in_implicit=['I']
x.graphics.out_implicit=['I']
end
endfunction
function mResistor_draw_ports(o)
[orig,sz,orient]=(o.graphics.orig,o.graphics.sz,o.graphics.flip)
xset('pattern',default_color(0))
if orient==0|orient==%F
out=[0 -1
1 -1
1 1
0 1]*diag([xf/7,yf/14])
in=[-1 -1
0 -1
0 1
-1 1]*diag([xf/7,yf/14])
dy=sz(2)/2
xset('pattern',default_color(1))
xfpoly(in(:,1)+ones(4,1)*orig(1),in(:,2)+ones(4,1)*(orig(2)+dy),1)
xpoly(out(:,1)+ones(4,1)*(orig(1)+sz(1)),out(:,2)+ones(4,1)*(orig(2)+dy),"lines",1)
elseif orient==1|orient==%T
out=[0 -1
-1 -1
-1 1
0 1]*diag([xf/7,yf/14])
in=[1 -1
0 -1
0 1
1 1]*diag([xf/7,yf/14])
dy=sz(2)/2
xset('pattern',default_color(1))
xfpoly(in(:,1)+ones(4,1)*(orig(1)+sz(1))+1,in(:,2)+ones(4,1)*(orig(2)+sz(2)-dy),1)
xpoly(out(:,1)+ones(4,1)*orig(1)-1,out(:,2)+ones(4,1)*(orig(2)+dy),"lines",1)
elseif orient==0.5
in=[-1 -1
1 -1
1 1
-1 1]*diag([xf/14*0.6,yf/7])
out=[0 -1
1 -1
1 1
0 1]*diag([xf/14,yf/7])
dx=sz(1)/2
//xset('pattern',default_color(1))
xfpoly(in(:,1)+ones(4,1)*(orig(1)+dx),in(:,2)+ones(4,1)*(orig(2)+sz(2)+yf/7),1)
xpoly(out(:,1)+ones(4,1)*orig(1),out(:,2)+ones(4,1)*(orig(2)-1-yf/7),"lines",1)
elseif orient==1.5
in=[-1 -1
1 -1
1 1
-1 1]*diag([xf/14*0.6,yf/7])
out=[1 -1
0 -1
0 1
1 1]*diag([xf/14,yf/7])
dx=sz(1)/2
//xset('pattern',default_color(1))
xfpoly(in(:,1)+ones(4,1)*(orig(1)+dx),in(:,2)+ones(4,1)*(orig(2)-1-yf/7),1)
xpoly(out(:,1)+ones(4,1)*orig(1),out(:,2)+ones(4,1)*(orig(2)+sz(2)+yf/7),"lines",1)
end
xset('pattern',default_color(0))
endfunction
function [x,y,typ]=mResistor_inputs(arg1)
xf=60
yf=40
orig=arg1.graphics.orig;sz=arg1.graphics.sz;
orient=arg1.graphics.flip
dy=sz(2)/2
dx=sz(1)/2
if orient==0|orient==%F
x=orig(1)
y=orig(2)+dy
elseif orient==1|orient==%T
x=orig(1)+sz(1)
y=orig(2)+sz(2)-dy
elseif orient==0.5
x=orig(1)+dx
y=orig(2)+sz(2)+yf/7
elseif orient==1.5
x=orig(1)+dx
y=orig(2)-1-yf/7
end
typ=2
endfunction
function [x,y,typ]=mResistor_outputs(arg1)
xf=60
yf=40
orig=arg1.graphics.orig;sz=arg1.graphics.sz;
orient=arg1.graphics.flip
dy=sz(2)/2
dx=sz(1)/2
if orient==0|orient==%F
x=orig(1)+sz(1)
y=orig(2)+dy
elseif orient==1|orient==%T
x=orig(1)-1
y=orig(2)+dy
elseif orient==0.5
x=orig(1)
y=orig(2)-1-yf/7
elseif orient==1.5
x=orig(1)
y=orig(2)+sz(2)+yf/7
end
typ=2
endfunction
IRCOM Group
Alan Layec