3 // Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
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.
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.
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.
19 // See the file ../license.txt
22 function [scs_m,DEL,DELL]=do_delete1(scs_m,K,gr)
26 //** BEWARE: this code is BUGGED : see the residual split after delete
27 //** this bug is older than Simone (see scilab 3.1.1)
29 //** 22 June 2006 : New Graphics Interface update
31 // Perform deletion of scs_m object whose index are given in the vector
32 // K and all other relevant objects (link, splits,..)
35 // - are replaced by the value : mlist("Deleted")
36 // - not to change the indexing: use do_purge to suppress them and to renumber objects
38 //** Perform deletion of [scs_m] object whose index are given in the vector
39 //** [K] and all other relevant objects (link, splits,..) in recursive way
41 //** Deleted objects are replaced by the value : mlist("Deleted")
42 //** ---> not to change the indexing:
43 //** ---> use [do_purge] to suppress them and to renumber objects
44 //** Similar strategy is used for the ghraphics object: to mantain the coherency
45 //** from the grphics object "gh_curwin.children.children(gr_k)" [Compund] list and the
46 //** scs_o.objs(k) data structure with the equation
48 //** gr_k = get_gri(k, o_size(1))
52 //** o_size = size(gh_curwin.children.children); // o_size(1) => length o_size(2) => 1
54 //** the graphics "Compound" object are NOT deleted BUT set to "invisible" with the propriety
56 //** gh_object.visible = "off" // You can't see me, by John Cena :) ... ask enrico.mannori
58 //** OK: ...looks simple... until you begin to fight with the code ...
61 DEL = [] // table of deleted objects
62 DELL= [] // table of redefined links
65 //** Delete object until "K" is empty
66 //** ----------------------------------------------------------------------------------------------
73 if find(DEL==k)==[] then
81 //**----------------------------------- Link -------------------------------------------
84 [ct,from,to]=(o.ct,o.from,o.to)
86 // free connected ports
87 if ct(2)==2 then //Implicit link
89 if or(scs_m.objs(from(1)).graphics.pin==k) & from(3)==1 then
90 scs_m.objs(from(1))=mark_prt(scs_m.objs(from(1)),from(2),"in",ct(2),0)
91 else //or(scs_m.objs(from(1)).graphics.pout==k) then
92 scs_m.objs(from(1))=mark_prt(scs_m.objs(from(1)),from(2),"out",ct(2),0)
95 if or(scs_m.objs(to(1)).graphics.pin==k) & to(3)==1 then
96 scs_m.objs(to(1))=mark_prt(scs_m.objs(to(1)),to(2),"in",ct(2),0)
97 else // or(scs_m.objs(to(1)).graphics.pout==k) then
98 scs_m.objs(to(1))=mark_prt(scs_m.objs(to(1)),to(2),"out",ct(2),0)
102 scs_m.objs(from(1))=mark_prt(scs_m.objs(from(1)),from(2),"out",ct(2),0)
103 scs_m.objs(to(1))=mark_prt(scs_m.objs(to(1)),to(2),"in",ct(2),0)
106 fromblock=scs_m.objs(from(1));
107 toblock=scs_m.objs(to(1));
109 if or(fromblock.gui==["SPLIT_f" "CLKSPLIT_f" "IMPSPLIT_f"]) then
110 //user kills a split output link:
112 //get links connected to the split block
113 connected=get_connected(scs_m,from(1))
114 if size(setdiff(connected,K),"*")==2 then
115 //RN: 22-7-2004 setdiff added above
116 //create a unique link with the split input and remaining
117 //output link and suppress the split block
118 if find(connected(2)==DEL)<>[] then // delete split
122 DEL=[DEL ksplit] //suppress split block
123 o1=scs_m.objs(connected(1));from1=o1.to;
124 o2=scs_m.objs(connected(2));
126 //create a unique link
127 if o1.from(1)==ksplit&o2.from(1)==ksplit then
128 //the two links come from the split: invert o1
129 w=o1.to;o1.to=o1.from;o1.from=w;
130 o1.xx=o1.xx($:-1:1);o1.yy=o1.yy($:-1:1);
131 elseif o1.to(1)==ksplit(1)&o2.to(1)==ksplit then
132 //the two links go from the split: invert o2
133 w=o2.to;o2.to=o2.from;o2.from=w;
134 o2.xx=o2.xx($:-1:1);o2.yy=o2.yy($:-1:1);
135 elseif o1.to(1)<>ksplit then
136 //o1 comes from the split while o2 goes to the split,
139 connected=connected([2 1]);
142 //now we can assume that o1 goes to the split and o2 comes
144 from1=o1.to;to2=o2.to;ct2=o2.ct
145 //the links comes from connected(1) block and
146 //goes to connected(2) block
148 if x1($-1)==x1($)&o2.xx(1)==o2.xx(2)|.. // both segs are vertical
149 y1($-1)==y1($)&o2.yy(1)==o2.yy(2) then //both segs are horiz
150 o1.xx=[x1(1:$-1);o2.xx(2:$)];
151 o1.yy=[y1(1:$-1);o2.yy(2:$)];
153 o1.xx=[x1(1:$-1);o2.xx];
154 o1.yy=[y1(1:$-1);o2.yy];
158 DEL = [DEL connected(1)] // suppress one link
159 DELL=[DELL connected(1)]
160 scs_m.objs(connected(2))=o1 //change link
162 scs_m.objs(to2(1))=mark_prt(scs_m.objs(to2(1)),to2(2),outin(to2(3)+1),ct2(2),..
164 scs_m.objs(o1.from(1))=mark_prt(scs_m.objs(o1.from(1)),o1.from(2),..
165 outin(o1.from(3)+1),o1.ct(2),connected(2))
168 end //get links connected to the split block
169 end // erase and delete link
171 if toblock.gui=="SPLIT_f"|toblock.gui=="CLKSPLIT_f" then //
172 //user kills a split input link
173 //ask for split deletion
175 elseif toblock.gui=="IMPSPLIT_f" then
176 //user kills a IMPsplit link:
178 //get links connected to the split block
179 connected=get_connected(scs_m,to(1))
180 if size(connected,"*")==2 then
181 //create a unique link with the split input and remaining
182 //output link and suppress the split block
183 if find(connected(2)==DEL)<>[] then // delete split
187 DEL=[DEL to(1)] //suppress split block
189 o1=scs_m.objs(connected(1));
190 o2=scs_m.objs(connected(2));
191 //o1 and o2 are the links that comes from the split
193 //create a unique link
194 to1=o1.to; //number of block at the boundary of link o1
195 to2=o2.to; //number of block at the boundary of link o2
196 if (o1.xx(1)==o1.xx(2)& o2.xx(1)==o2.xx(2))| ..
197 (o1.yy(1)==o1.yy(2)& o2.yy(1)==o2.yy(2)) then
198 o1.xx=o1.xx(2:$);o1.yy=o1.yy(2:$)
200 o1.xx=[o1.xx($:-1:1);o2.xx]
201 o1.yy=[o1.yy($:-1:1);o2.yy]
206 DEL=[DEL connected(1)] // suppress one link
207 DELL=[DELL connected(1)]
208 scs_m.objs(connected(2))=o1 //change link
210 scs_m.objs(to1(1))=mark_prt(scs_m.objs(to1(1)),..
211 to1(2),outin(to1(3)+1),o1.ct(2),connected(2))
212 scs_m.objs(to2(1))=mark_prt(scs_m.objs(to2(1)),to2(2),..
213 outin(to2(3)+1),ct(2), ...
215 end //if find(connected(2)==DEL)<>[]
217 end //if size(connected,'*')==2
219 end //elseif toblock.gui=='IMPSPLIT_f'
221 //** -------------------------------------- Block ---------------------------------------
222 elseif typ=="Block" then
224 // get connected links
225 connected=get_connected(scs_m,k)
226 //ask for connected links deletion
230 //**--------------------------------------- Text ----------------------------------------
231 elseif typ=="Text" then
234 //** ---------------------------- already "Deleted" object :) ----------------------------
235 elseif typ=="Deleted" then
238 //** --------------------------- in all the other possibles cases -----------------------
241 messagebox("This object can''t be deleted","modal");
243 end //** link / Block / Text / Deleted / other...
245 end //** ... end of while ()
246 //**---------------------------------- end of main while() loop ---------------------------
249 //** Scan all the deleted elements and update the graphics datastrucure
251 scs_m.objs(k) = mlist("Deleted"); //** mark the object as "Deleted"