unit Uedit; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, ExtCtrls, UDessin, UDessinComposant,UFonctions, UInit; procedure AjouteComposant(S:string; x,y:integer); procedure AjouteSegment; procedure SupprimeComposant; procedure SelectionComposants; procedure Resegmentation; procedure RazEnCours; procedure RAZSelection; procedure PanneauEdition(x,y:integer); procedure RAZPanneauEdition; procedure ListeNom; function CompteurComposant(S:string):integer; implementation uses Unit1,UnitRelais, UTest; procedure AjouteComposant(S:string; x,y:integer); begin if pos('Im_rl',s)>0 then begin SetLength(L_Relais,Nb_Relais +1); L_Relais[Nb_Relais].P.X:=cordox(x); L_Relais[Nb_Relais].P.Y:=cordoy(y); L_Relais[Nb_Relais].modele:=copy(s,6,3); L_Relais[Nb_Relais].Visible:=true; L_Relais[Nb_Relais].nom:=''; CompoEnCours:='R'; NumeroEnCours:=Nb_Relais; L_Relais[Nb_Relais].Pd.X:=0; L_Relais[Nb_Relais].Pd.Y:=-4; if L_Relais[Nb_Relais].modele='1' then L_Relais[Nb_Relais].Pd.Y:=-5; if L_Relais[Nb_Relais].modele='4' then L_Relais[Nb_Relais].Pd.Y:=-5; if L_Relais[Nb_Relais].modele='7' then L_Relais[Nb_Relais].Pd.Y:=-5; if L_Relais[Nb_Relais].modele='11' then L_Relais[Nb_Relais].Pd.Y:=-7; if L_Relais[Nb_Relais].modele='12' then L_Relais[Nb_Relais].Pd.Y:=-7; inc(Nb_Relais); end; if pos('Im_cx',s)>0 then begin SetLength(L_Connect,Nb_Connect +1); L_Connect[Nb_Connect].P.X:=cordox(x); L_Connect[Nb_Connect].P.Y:=cordoy(y); CompoEnCours:='X'; NumeroEnCours:=Nb_Connect; inc(Nb_Connect); end; if pos('Im_ct',s)>0 then begin SetLength(L_Contact,Nb_Contact +1); L_Contact[Nb_Contact].P.X:=cordox(x); L_Contact[Nb_Contact].P.Y:=cordoy(y); L_Contact[Nb_Contact].modele:=copy(s,6,3); L_Contact[Nb_Contact].nom:=''; CompoEnCours:='C'; NumeroEnCours:=Nb_Contact; if (L_Contact[Nb_Contact].modele='10') or (L_Contact[Nb_Contact].modele='15') then L_Contact[Nb_Contact].Manuel:=true; if (L_Contact[Nb_Contact].modele='11') or (L_Contact[Nb_Contact].modele='12') or (L_Contact[Nb_Contact].modele='13') or (L_Contact[Nb_Contact].modele='14') or (L_Contact[Nb_Contact].modele='16') or (L_Contact[Nb_Contact].modele='17') then begin L_Contact[Nb_Contact].EtatI:=true; L_Contact[Nb_Contact].Manuel:=true; end; inc(Nb_Contact); end; if pos('Im_cp',s)>0 then begin SetLength(L_Compo,Nb_Compo +1); L_Compo[Nb_Compo].P.X:=cordox(x); L_Compo[Nb_Compo].P.Y:=cordoy(y); L_Compo[Nb_Compo].modele:=copy(s,6,3); CompoEnCours:='P'; NumeroEnCours:=Nb_Compo; inc(Nb_Compo); end; if pos('Im_al',s)>0 then begin SetLength(L_Alim,Nb_Alim +1); L_Alim[Nb_Alim].P.X:=cordox(x); L_Alim[Nb_Alim].P.Y:=cordoy(y); L_Alim[Nb_Alim].modele:=copy(s,6,3); CompoEnCours:='A'; NumeroEnCours:=Nb_Alim; inc(Nb_Alim); end; if pos('Im_la',s)>0 then begin SetLength(L_Lampe,Nb_Lampe +1); L_Lampe[Nb_Lampe].P.X:=cordox(x); L_Lampe[Nb_Lampe].P.Y:=cordoy(y); L_Lampe[Nb_Lampe].modele:=copy(s,6,3); L_Lampe[Nb_Lampe].Clr0:=clBlack; L_Lampe[Nb_Lampe].Clr1:=clRed; L_Lampe[Nb_Lampe].nom:=''; L_Lampe[Nb_Lampe].Pd.X:=0; L_Lampe[Nb_Lampe].Pd.Y:=0; if L_Lampe[Nb_Lampe].modele='1' then L_Lampe[Nb_Lampe].Pd.Y:=-5; if L_Lampe[Nb_Lampe].modele='2' then L_Lampe[Nb_Lampe].Pd.X:=5; CompoEnCours:='L'; NumeroEnCours:=Nb_Lampe; inc(Nb_Lampe); end; Affichage; end; procedure AjouteSegment; begin SetLength(L_Segment,Nb_Segment +1); L_Segment[Nb_Segment].P1.X:=round(dx); L_Segment[Nb_Segment].P1.Y:=round(dy); L_Segment[Nb_Segment].P2.X:=round(fx); L_Segment[Nb_Segment].P2.Y:=round(fy); CompoEnCours:='S'; NumeroEnCours:=Nb_Segment; inc(Nb_Segment); Affichage; end; procedure RazEnCours; var i:integer; begin CompoEnCours:=''; NumeroEnCours:=-1; EnCours:=false; for i:=0 to Nb_Contact - 1 do L_Contact[i].Select := false; end; procedure RAZSelection; var i:integer; begin for i:=0 to Nb_Relais - 1 do L_Relais[i].Select:=false; for i:=0 to Nb_Lampe - 1 do L_Lampe[i].Select:=false; for i:=0 to Nb_Connect - 1 do L_Connect[i].Select:=false; for i:=0 to Nb_Contact - 1 do L_Contact[i].Select:=false; for i:=0 to Nb_Compo - 1 do L_Compo[i].Select:=false; for i:=0 to Nb_Segment - 1 do begin L_Segment[i].Select1:=false; L_Segment[i].Select2:=false; end; for i:=0 to Nb_Alim - 1 do L_Alim[i].Select:=false; Affichage; end; procedure SupprimeComposant; var i:integer; begin i:=0; while i<= Nb_Relais - 1 do begin RAZPanneauEdition; if L_Relais[i].Select then begin L_Relais[i]:=L_Relais[nb_Relais-1]; dec(Nb_Relais); dec(i); end; inc(i); end; i:=0; while i<= Nb_Lampe - 1 do begin RAZPanneauEdition; if L_Lampe[i].Select then begin L_Lampe[i]:=L_Lampe[nb_Lampe-1]; dec(Nb_Lampe); dec(i); end; inc(i); end; i:=0; while i<= Nb_Connect - 1 do begin if L_Connect[i].Select then begin L_Connect[i]:=L_Connect[nb_Connect-1]; dec(Nb_Connect); dec(i); end; inc(i); end; i:=0; while i<= Nb_Contact - 1 do begin RAZPanneauEdition; if L_Contact[i].Select then begin L_Contact[i]:=L_Contact[nb_Contact-1]; dec(Nb_Contact); dec(i); end; inc(i); end; i:=0; while i<= Nb_Compo - 1 do begin if L_Compo[i].Select then begin L_Compo[i]:=L_Compo[nb_Compo-1]; dec(Nb_Compo); dec(i); end; inc(i); end; i:=0; while i<= Nb_Alim - 1 do begin if L_Alim[i].Select then begin L_Alim[i]:=L_Alim[nb_Alim-1]; dec(Nb_Alim); dec(i); end; inc(i); end; i:=0; while i<= Nb_Segment - 1 do begin if (L_Segment[i].Select1 and L_Segment[i].Select2) then begin L_Segment[i]:=L_Segment[nb_Segment-1]; dec(Nb_Segment); dec(i); end; inc(i); end; Affichage; end; procedure SelectionComposants; var i,ic:integer; d,d1,d2,d01,d02:real; sc:string; b:boolean; procedure swap(s:string); begin d:=d1; sc:=s; ic:=i; end; begin // Test('D Selection Composant'); // Form1.memo1.Lines.Add('Recherche entre '+IntToStr(dx)+','+IntToStr(dy)+' et '+IntToStr(fx)+','+IntToStr(fy)); RazEnCours; if (dx=fx) and (dy=fy) then begin d:=10000; ic:=-1; sc:=''; for i:=0 to Nb_Relais - 1 do begin d1:=sqrt(sqr(L_Relais[i].P.X-dx)+sqr(L_Relais[i].P.Y-dy)); if d1d01) and (d2>d02) then swap('S'); end; for i:=0 to Nb_Alim - 1 do begin d1:=sqrt(sqr(L_Alim[i].P.X-dx)+sqr(L_Alim[i].P.Y-dy)); if d1 0) and (L_Segment[j].P2.X-L_Segment[j].P1.X <> 0) then begin // non vertical cdi:=(L_Segment[i].P2.Y-L_Segment[i].P1.Y)/(L_Segment[i].P2.X-L_Segment[i].P1.X); // cd coef directeur cdj:=(L_Segment[j].P2.Y-L_Segment[j].P1.Y)/(L_Segment[j].P2.X-L_Segment[j].P1.X); if cdi=cdj then begin // si colinéaire cbi:=L_Segment[i].P1.Y-cdi*L_Segment[i].P1.X; // b (y=ax+b) cbj:=L_Segment[j].P1.Y-cdj*L_Segment[j].P1.X; if cbi=cbj then begin // si même droite b:=entre(L_Segment[i].P1.X,L_Segment[j].P1.X,L_Segment[j].P2.X) or entre(L_Segment[i].P2.X,L_Segment[j].P1.X,L_Segment[j].P2.X) or entre(L_Segment[j].P1.X,L_Segment[i].P1.X,L_Segment[i].P2.X) or entre(L_Segment[j].P2.X,L_Segment[i].P1.X,L_Segment[i].P2.X); if b then begin // si contigüe ou superposé bc:=true; x1:=L_Segment[i].P1.X;y1:=L_Segment[i].P1.Y; if x1>L_Segment[i].P2.X then begin x1:=L_Segment[i].P2.X;y1:=L_Segment[i].P2.Y; end; if x1>L_Segment[j].P1.X then begin x1:=L_Segment[j].P1.X;y1:=L_Segment[j].P1.Y; end; if x1>L_Segment[j].P2.X then begin x1:=L_Segment[j].P2.X;y1:=L_Segment[j].P2.Y; end; x2:=L_Segment[i].P1.X;y2:=L_Segment[i].P1.Y; if x2 0) and (L_Segment[j].P2.Y-L_Segment[j].P1.Y <> 0) then begin cdi:=(L_Segment[i].P2.X-L_Segment[i].P1.X)/(L_Segment[i].P2.Y-L_Segment[i].P1.Y); cdj:=(L_Segment[j].P2.X-L_Segment[j].P1.X)/(L_Segment[j].P2.Y-L_Segment[j].P1.Y); if cdi=cdj then begin cbi:=L_Segment[i].P1.X-cdi*L_Segment[i].P1.Y; cbj:=L_Segment[j].P1.X-cdj*L_Segment[j].P1.Y; if cbi=cbj then begin b:=entre(L_Segment[i].P1.Y,L_Segment[j].P1.Y,L_Segment[j].P2.Y) or entre(L_Segment[i].P2.Y,L_Segment[j].P1.Y,L_Segment[j].P2.Y) or entre(L_Segment[j].P1.Y,L_Segment[i].P1.Y,L_Segment[i].P2.Y) or entre(L_Segment[j].P2.Y,L_Segment[i].P1.Y,L_Segment[i].P2.Y); if b then begin bc:=true; x1:=L_Segment[i].P1.X;y1:=L_Segment[i].P1.Y; if y1>L_Segment[i].P2.Y then begin y1:=L_Segment[i].P2.Y;x1:=L_Segment[i].P2.X; end; if y1>L_Segment[j].P1.Y then begin y1:=L_Segment[j].P1.Y;x1:=L_Segment[j].P1.X; end; if y1>L_Segment[j].P2.Y then begin y1:=L_Segment[j].P2.Y;x1:=L_Segment[j].P2.X; end; x2:=L_Segment[i].P1.X;y2:=L_Segment[i].P1.Y; if y2 0) then begin cdi:=(L_Segment[i].P2.Y-L_Segment[i].P1.Y)/(L_Segment[i].P2.X-L_Segment[i].P1.X); cbi:=L_Segment[i].P1.Y-cdi*L_Segment[i].P1.X; b:=(L_Connect[j].P.Y=cdi*L_Connect[j].P.X+cbi) and entre(L_Connect[j].P.X,L_Segment[i].P1.X,L_Segment[i].P2.X) and (L_Connect[j].P.X<>L_Segment[i].P1.X) and (L_Connect[j].P.X<>L_Segment[i].P2.X); if b then begin bc:=true; SetLength(L_Segment,Nb_Segment +1); L_Segment[Nb_Segment].P1.X:=L_Connect[j].P.X; L_Segment[Nb_Segment].P1.Y:=L_Connect[j].P.Y; L_Segment[Nb_Segment].P2.X:=L_Segment[i].P2.X; L_Segment[Nb_Segment].P2.Y:=L_Segment[i].P2.Y; L_Segment[i].P2.X:=L_Connect[j].P.X; L_Segment[i].P2.Y:=L_Connect[j].P.Y; Inc(Nb_Segment); end; end; // verticaux if (L_Segment[i].P2.X-L_Segment[i].P1.X = 0) and (L_Segment[i].P2.Y-L_Segment[i].P1.Y <> 0) then begin cdi:=(L_Segment[i].P2.X-L_Segment[i].P1.X)/(L_Segment[i].P2.Y-L_Segment[i].P1.Y); cbi:=L_Segment[i].P1.X-cdi*L_Segment[i].P1.Y; b:=(L_Connect[j].P.X=cdi*L_Connect[j].P.Y+cbi) and entre(L_Connect[j].P.Y,L_Segment[i].P1.Y,L_Segment[i].P2.Y) and (L_Connect[j].P.Y<>L_Segment[i].P1.Y) and (L_Connect[j].P.Y<>L_Segment[i].P2.Y); if b then begin bc:=true; SetLength(L_Segment,Nb_Segment +1); L_Segment[Nb_Segment].P1.X:=L_Connect[j].P.X; L_Segment[Nb_Segment].P1.Y:=L_Connect[j].P.Y; L_Segment[Nb_Segment].P2.X:=L_Segment[i].P2.X; L_Segment[Nb_Segment].P2.Y:=L_Segment[i].P2.Y; L_Segment[i].P2.X:=L_Connect[j].P.X; L_Segment[i].P2.Y:=L_Connect[j].P.Y; Inc(Nb_Segment); end; end; end; until not bc; // tant qu'on scinde on revérifie end; function CompteurComposant(S:string):integer; var i,c:integer; begin c:=0; if S='C' then for i:=0 to Nb_Contact-1 do if L_Contact[i].Select then inc(c); if S='R' then for i:=0 to Nb_Relais-1 do if L_Relais[i].Select then inc(c); if S='L' then for i:=0 to Nb_Lampe-1 do if L_Lampe[i].Select then inc(c); Result:=c; end; procedure RAZPanneauEdition; begin With Form1 do begin Pnl_Contact.Visible:=false; Pnl_Relais.Visible:=false; Pnl_Lampe.Visible:=false; end; end; procedure ListeNom; var i:integer; begin With Form1 do begin CO_C_Nom.Clear; for i:=0 to Nb_Relais-1 do if L_Relais[i].nom<>'' then CO_C_Nom.Items.Add(L_Relais[i].nom); for i:=0 to Nb_Contact-1 do if L_Contact[i].Manuel and (L_Contact[i].nom<>'') then CO_C_Nom.Items.Add(L_Contact[i].nom); end; // With Form1 end; // Affiche les panneaux d'édition des composants procedure PanneauEdition(x,y:integer); var i:integer; begin RAZPanneauEdition; With Form1 do begin // Contact if CompteurComposant('C')=1 then begin Pnl_Contact.Visible:=true; for i:=0 to Nb_Contact-1 do if L_Contact[i].Select then begin CB_C_EtatI.Checked:=L_Contact[i].EtatI; CB_C_Manuel.Checked:=L_Contact[i].Manuel; CB_C_Visible.Checked:=L_Contact[i].Visible; CO_C_Nom.Text:=L_Contact[i].nom; SP_C_dx.Value:=L_Contact[i].Pd.X; SP_C_dy.Value:=L_Contact[i].Pd.Y; end; // for i end; // if CompteurComposant('C') // Relais if CompteurComposant('R')=1 then begin Pnl_Relais.Visible:=true; for i:=0 to Nb_Relais-1 do if L_Relais[i].Select then begin CB_R_Visible.Checked:=L_Relais[i].Visible; Ed_R_Nom.Text:=L_Relais[i].nom; SP_R_dx.Value:=L_Relais[i].Pd.X; SP_R_dy.Value:=L_Relais[i].Pd.Y; Ed_R_Tempo.Text:=IntToStr(L_Relais[i].tpr); end; // for i end; // if CompteurComposant('R') // Lampe if CompteurComposant('L')=1 then begin Pnl_Lampe.Visible:=true; for i:=0 to Nb_Lampe-1 do if L_Lampe[i].Select then begin CB_L_Visible.Checked:=L_Lampe[i].Visible; Ed_L_Nom.Text:=L_Lampe[i].nom; SP_L_dx.Value:=L_Lampe[i].Pd.X; SP_L_dy.Value:=L_Lampe[i].Pd.Y; PNL_L0.Color:=L_Lampe[i].Clr0; PNL_L1.Color:=L_Lampe[i].Clr1; end; // for i end; // if CompteurComposant('L') end; // with Form1 end; // PanneauEdition(x,y:integer); end.