~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to macros/scicos_blocks/Electrical/VariableResistor.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function [x,y,typ]=VariableResistor(job,arg1,arg2)
 
2
// Copyright INRIA
 
3
// exemple d'un bloc implicit, 
 
4
//   -  sans entree ni sortie de conditionnement
 
5
//   -  avec une entree et une sortie de type implicit et de dimension 1
 
6
//   - avec un dialogue de saisie de parametre
 
7
x=[];y=[];typ=[];
 
8
select job
 
9
case 'plot' then
 
10
  R=arg1.graphics.exprs;
 
11
  standard_draw(arg1,%f,VR_draw_ports)
 
12
case 'getinputs' then
 
13
  [x,y,typ]=VR_inputs(arg1)
 
14
case 'getoutputs' then
 
15
  [x,y,typ]=standard_outputs(arg1)
 
16
case 'getorigin' then
 
17
  [x,y]=standard_origin(arg1)
 
18
case 'set' then
 
19
  x=arg1;
 
20
case 'define' then
 
21
  model=scicos_model()
 
22
  model.sim='VariableResistor'
 
23
  model.blocktype='c'
 
24
  model.dep_ut=[%t %f]
 
25
  mo=modelica()
 
26
    mo.model='VariableResistor'
 
27
    mo.inputs=['p','R'];
 
28
    mo.outputs='n';
 
29
  model.equations=mo
 
30
  model.in=ones(size(mo.inputs,'*'),1)
 
31
  model.out=ones(size(mo.outputs,'*'),1)
 
32
  exprs=[]
 
33
  gr_i=[ 'xx=[0,1,1,7,7,8,7,7,1,1]/8;';
 
34
         'yy=[1,1,0,0,1,1,1,2,2,1]/2;';
 
35
         'xpoly(orig(1)+xx*sz(1),orig(2)+yy*sz(2)); ']  
 
36
  x=standard_define([2 0.18],model,exprs,list(gr_i,0))
 
37
  x.graphics.in_implicit=['I','E']
 
38
  x.graphics.out_implicit=['I']
 
39
end
 
40
endfunction
 
41
function VR_draw_ports(o)
 
42
[orig,sz,orient]=(o.graphics.orig,o.graphics.sz,o.graphics.flip)
 
43
    xset('pattern',default_color(0))
 
44
    dy=sz(2)/2
 
45
  // draw input/output ports
 
46
  //------------------------
 
47
  xset('pattern',default_color(1))
 
48
  if orient then  //standard orientation
 
49
    // set port shape
 
50
    out2=[ 0  -1
 
51
           1  -1
 
52
           1   1
 
53
           0   1]*diag([xf/7,yf/14])
 
54
    
 
55
    in2= [-1  -1
 
56
           0  -1
 
57
           0   1
 
58
          -1   1]*diag([xf/7,yf/14])
 
59
 
 
60
 
 
61
    xpoly(out2(:,1)+(orig(1)+sz(1)),..
 
62
          out2(:,2)+(orig(2)+sz(2)-dy),"lines",1)
 
63
 
 
64
    xfpoly(in2(:,1)+orig(1),..
 
65
           in2(:,2)+(orig(2)+sz(2)-dy),1)       
 
66
  else //tilded orientation
 
67
      out2=[0  -1
 
68
           -1  -1
 
69
           -1   1
 
70
            0   1]*diag([xf/7,yf/14])
 
71
      
 
72
      in2= [1  -1
 
73
            0  -1
 
74
            0   1
 
75
            1   1]*diag([xf/7,yf/14])
 
76
 
 
77
      
 
78
      xset('pattern',default_color(1))
 
79
      xpoly(out2(:,1)+ones(4,1)*orig(1)-1,..
 
80
            out2(:,2)+ones(4,1)*(orig(2)+sz(2)-dy),"lines",1)  
 
81
 
 
82
      xfpoly(in2(:,1)+ones(4,1)*(orig(1)+sz(1))+1,..
 
83
             in2(:,2)+ones(4,1)*(orig(2)+sz(2)-dy),1) 
 
84
  end
 
85
 
 
86
  // set port shape
 
87
 
 
88
  in= [-1/14  1/7
 
89
       0      0
 
90
       1/14   1/7
 
91
       -1/14  1/7]*diag([xf,yf])
 
92
 
 
93
 
 
94
  dx=sz(1)/2
 
95
    xfpoly(in(:,1)+ones(4,1)*(orig(1)+dx),..
 
96
           in(:,2)+ones(4,1)*(orig(2)+sz(2)),1)
 
97
 
 
98
 
 
99
endfunction 
 
100
 
 
101
function [x,y,typ]=VR_inputs(o)
 
102
  xf=60;yf=40
 
103
  graphics=o.graphics
 
104
  orig=graphics.orig;sz=graphics.sz;
 
105
  if graphics.flip then
 
106
    xo=orig(1);dx=-xf/7
 
107
  else
 
108
    xo=orig(1)+sz(1);dx=yf/7
 
109
  end
 
110
  y=orig(2)+sz(2)/2
 
111
  x=(xo+dx)*ones(y)
 
112
  
 
113
  x=[x,orig(1)+(sz(1)/2)]
 
114
  y=[y,orig(2)+yf/7+sz(2)]
 
115
  typ=[2 1]
 
116
endfunction