File: do_replace.sci

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
file content (169 lines) | stat: -rw-r--r-- 4,340 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
function [scs_m,needcompile]=do_replace(scs_m,needcompile)
// Copyright INRIA
while %t
  // get replacement block
  [btn,xc,yc,win,Cmenu]=getclick()
  if Cmenu<>[] then
    Cmenu=resume(Cmenu)
  end
  kc=find(win==windows(:,2))
  if kc==[] then
    message('This window is not an active palette')
    k=[];break
  elseif windows(kc,1)<0 then //click dans une palette
    kpal=-windows(kc,1)
    palette=palettes(kpal)
    k=getblock(palette,[xc;yc])
    if k<>[] then o=palette(k),break,end
  elseif win==curwin then //click dans la fenetre courante
    k=getblock(scs_m,[xc;yc])
    if k<>[] then
      o=scs_m(k);graphics=o(2)
      for kk=5:8
	// mark port disconnected
	graphics(kk)=0*graphics(kk)
      end
      o(2)=graphics
      break,
    end
  else
    message('This window is not an active palette')
    k=[];break
  end
end
if k==[] then return,end
// get block to replace
xset('window',curwin);
while %t do
  [btn,xc,yc,win,Cmenu]=getclick()
  if Cmenu<>[] then
    Cmenu=resume(Cmenu)
  end
  k_n=getobj(scs_m,[xc;yc])
  if k_n<>[] then
    o_n=scs_m(k_n)
    if o_n(1)=='Block' then  break,end
  end
end
o(2)(3)=o_n(2)(3) // set same flip position
[ip,op,cip,cop]=o(2)(5:8)
[in,out,clkin,clkout]=o(3)(2:5)
nin=size(in,'*')
nout=size(out,'*')
nclkin=size(clkin,'*')
nclkout=size(clkout,'*')


[ip_n,op_n,cip_n,cop_n]=o_n(2)(5:8)
[in_n,out_n,clkin_n,clkout_n]=o_n(3)(2:5)
nin_n=size(in_n,'*')
nout_n=size(out_n,'*')
nclkin_n=size(clkin_n,'*')
nclkout_n=size(clkout_n,'*')


[ox,oy]=getorigin(o)
[ox_n,oy_n]=getorigin(o_n)


[xx,yy,t]=getinputs(o);xx=xx-ox;yy=yy-oy
[x_n,y_n,t_n]=getinputs(o_n);x_n=x_n-ox_n;y_n=y_n-oy_n
//Check inputs
wasconnected=%f
if ip_n<>[] then if find(ip_n>0)<>[] then wasconnected=%t,end,end
if wasconnected then
  if nin<>nin_n then
    message(['It is not yet possible to replace a block with'
	'connected inputs with an other block with '
	'different number of inputs'])
    ok=%f
    return
  elseif norm(xx(1:nin)-x_n(1:nin),1)>0.1|norm(yy(1:nin)-y_n(1:nin),1)>0.1 then
    message(['It is not yet possible to replace a block with'
	'connected inputs with an other block with inputs not '
	'relatively located in the same position'])
    ok=%f
    return
  else
    ip=ip_n
  end
end
//Check clock inputs
wasconnected=%f
if cip_n<>[] then if find(cip_n>0)<>[] then wasconnected=%t, end, end,
if wasconnected then
  if nclkin<>nclkin_n then
    message(['It is not yet possible to replace a block with'
	'connected clock inputs with an other block with '
	'different number of clock inputs'])
    ok=%f
    return
  elseif norm(xx(t==-1)-x_n(t==-1),1)>0.1|norm(yy(t==-1)-y_n(t==-1),1)>0.1 then
    message(['It is not yet possible to replace a block with'
	'connected clock inputs with an other block with clock inputs '
	'not relatively located in the same position'])
    ok=%f
    return
  else
    cip=cip_n
  end
end


[xx,yy,t]=getoutputs(o);xx=xx-ox;yy=yy-oy
[x_n,y_n,t_n]=getoutputs(o_n);x_n=x_n-ox_n;y_n=y_n-oy_n
//Check outputs
wasconnected=%f
if op_n<>[] then if find(op_n>0)<>[] then wasconnected=%t, end, end,
if wasconnected then
  if nout<>nout_n then
    message(['It is not yet possible to replace a block with'
	'connected outputs with an other block with '
	'different number of outputs'])
    ok=%f
    return
  elseif norm(xx(1:nout)-x_n(1:nout),1)>0.1|norm(yy(1:nout)-y_n(1:nout),1)>0.1 then
    message(['It is not yet possible to replace a block with'
	'connected outputs with an other block with outputs not '
	'relatively located in the same position'])
    ok=%f
    return
  else
    op=op_n
  end
end
//Check clock outputs
wasconnected=%f
if cop_n<>[] then if find(cop_n>0)<>[] then wasconnected=%t, end, end,
if wasconnected then
  if nclkout<>nclkout_n then
    message(['It is not yet possible to replace a block with'
	'connected clock outputs with an other block with '
	'different number of clock outputs'])
    ok=%f
    return
  elseif norm(xx(t==-1)-x_n(t==-1),1)>0.1|norm(yy(t==-1)-y_n(t==-1),1)>0.1 then
    message(['It is not yet possible to replace a block with'
	'connected clock outputs with an other block with clock outputs '
	'not relatively located in the same position'])
    ok=%f
    return
  else
    cop=cop_n
  end
end


o(2)(1)=[ox_n,oy_n]
o(2)(5)=ip
o(2)(6)=op
o(2)(7)=cip
o(2)(8)=cop
drawobj(o_n)
drawobj(o)
scs_m(k_n)=o
needcompile=4