unit UDessinComposant; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Menus, ExtCtrls,UInit,math; function cordo(i:integer):double; function cordox(i:integer):integer; function cordoy(i:integer):integer; function ecranx(r:real):integer; function ecrany(r:real):integer; procedure Trait(x1,y1,x2,y2:real); procedure DessineRelais(Rl:T_Relais); procedure DessineConnect(Cx:T_Connect); procedure DessineContact(Ct:T_Contact); procedure DessineSegment(Sg:T_Segment); procedure DessineAlim(Al:T_Alim); procedure DessineCompo(Cp:T_Compo); procedure DessineLampe(La:T_Lampe); implementation uses Unit1, UDessin,UTest,UPage; function cordo(i:integer):double; begin result:=(i/Facteur*zoom); end; function cordox(i:integer):integer; begin result:=round(i/Facteur*zoom)+Form1.SB_Hor.Position*sbx; end; function cordoy(i:integer):integer; begin result:=round(i/Facteur*zoom)+Form1.SB_Ver.Position*sby; end; function ecran(rx,ry:double):TPoint; begin result.X:=round((rx-Form1.SB_Hor.Position*sbx)*Facteur/zoom); result.Y:=round((ry-Form1.SB_Ver.Position*sby)*Facteur/zoom); end; function ecranx(r:real):integer; begin result:=round((r-Form1.SB_Hor.Position*sbx)*Facteur/zoom); end; function ecrany(r:real):integer; begin result:=round((r-Form1.SB_Ver.Position*sby)*Facteur/zoom); end; procedure Trait(x1,y1,x2,y2:real); begin // Form1.Image.Canvas.Pen.Color:=clyellow; Form1.Image.Canvas.Pen.Width:=1+round(1/zoom); Form1.Image.Canvas.MoveTo(ecranx(x1),ecrany(y1)); Form1.Image.Canvas.LineTo(ecranx(x2),ecrany(y2)); end; procedure TraitFort(x1,x2,y:real); // horizontal begin Form1.Image.Canvas.FillRect(Rect(ecranx(x1),ecrany(y-0.1),ecranx(x2),ecrany(y+0.1))); end; procedure TraitFin(x,y1,y2:real); // vertical begin Form1.Image.Canvas.FillRect(Rect(ecranx(x-0.05),ecrany(y1),ecranx(x+0.05),ecrany(y2))); end; procedure Rond(x,y:real); begin Form1.Image.Canvas.Brush.Style:=bsSolid; Form1.Image.Canvas.Ellipse(ecranx(x-0.3),ecrany(y-0.3),1+ecranx(x+0.3),1+ecrany(y+0.3)); end; procedure fleche(x,y:real;b:boolean); begin Form1.Image.Canvas.Pen.Color:=RGB(160,160,160); Form1.Image.Canvas.Pen.Width:=1+round(1/zoom); Form1.Image.Canvas.MoveTo(ecranx(x),ecrany(y+0.5)); Form1.Image.Canvas.LineTo(ecranx(x),ecrany(y-0.5)); if b then begin Form1.Image.Canvas.MoveTo(ecranx(x-0.25),ecrany(y-0.25)); Form1.Image.Canvas.LineTo(ecranx(x),ecrany(y-0.5)); Form1.Image.Canvas.LineTo(ecranx(x+0.25),ecrany(y-0.25)); end else begin Form1.Image.Canvas.MoveTo(ecranx(x-0.25),ecrany(y+0.25)); Form1.Image.Canvas.LineTo(ecranx(x),ecrany(y+0.5)); Form1.Image.Canvas.LineTo(ecranx(x+0.25),ecrany(y+0.25)); end; end; procedure Pivot1(x,y:real;b:boolean); begin Form1.Image.Canvas.Pen.Width:=1;//+round(1/zoom); if not b then Form1.Image.Canvas.Polygon([ecran(x-1,y-0.08), ecran(x-1,y+0.08), ecran(x+1,y+0.75+0.08), ecran(x+1,y+0.75-0.08)]) else Form1.Image.Canvas.Polygon([ecran(x-1,y-0.08), ecran(x-1,y+0.08), ecran(x+1,y+0.25+0.08), ecran(x+1,y+0.25-0.08)]); end; procedure Pivot2(x,y:real;b:boolean); begin Form1.Image.Canvas.Pen.Width:=1;//+round(1/zoom); if not b then Form1.Image.Canvas.Polygon([ecran(x+1,y-0.08), ecran(x+1,y+0.08), ecran(x-1,y+0.75+0.08), ecran(x-1,y+0.75-0.08)]) else Form1.Image.Canvas.Polygon([ecran(x+1,y-0.08), ecran(x+1,y+0.08), ecran(x-1,y+0.25+0.08), ecran(x-1,y+0.25-0.08)]); end; procedure Pivot3(x,y:real;b:boolean); begin Form1.Image.Canvas.Pen.Width:=1;//+round(1/zoom); if not b then Form1.Image.Canvas.Polygon([ecran(x-0.08,y+1), ecran(x+0.08,y+1), ecran(x-0.75+0.08,y-1), ecran(x-0.75-0.08,y-1)]) else Form1.Image.Canvas.Polygon([ecran(x-0.08,y+1), ecran(x+0.08,y+1), ecran(x+0.75+0.08,y-1), ecran(x+0.75-0.08,y-1)]); end; procedure Texte(x,y:real;s:string); begin Form1.Image.Canvas.TextOut(ecranx(x)-round(Form1.Image.Canvas.TextWidth(s)/2),ecrany(y),s); end; procedure ix(x,y:real); begin Form1.Image.Canvas.MoveTo(ecranx(x-1),ecrany(y-1)); Form1.Image.Canvas.LineTo(ecranx(x+1),ecrany(y+1)); Form1.Image.Canvas.MoveTo(ecranx(x+1),ecrany(y-1)); Form1.Image.Canvas.LineTo(ecranx(x-1),ecrany(y+1)); end; // Dessins procedure DessineRelais(Rl:T_Relais); var x,y:integer; cl:TColor; b:boolean; begin x:=Rl.P.X; y:=Rl.P.Y; b:=false; if (Rl.Fonction>=0) and (length(L_Fonction)>0) then b:=bExec and L_Fonction[Rl.Fonction].EtatP; //} cl:=clBlack; if (EnCours or Rl.Select) and not bExec then cl:=clBlue; Form1.Image.Canvas.Pen.Color:=cl; Form1.Image.Canvas.Brush.Color:=cl; // test(format('',[Rl.AppPot])); if Rl.modele='1' then begin TraitFort(x-1.3,x+1.3,y-1); TraitFort(x-1.3,x+1.3,y+1); TraitFin(x-1,y-1,y+1); TraitFin(x+1,y-1,y+1); Rond(x+1,y); Rond(x-1,y); if Form1.VisuelRelais.Checked then fleche(x,y,b); end; if Rl.modele='2' then begin TraitFort(x-1.3,x+1.3,y-0.5); TraitFort(x-1.3,x+1.3,y+1.5); TraitFin(x-1,y-0.5,y+1.5); TraitFin(x+1,y-0.5,y+1.5); Rond(x-1,y); Rond(x-1,y+1); if Form1.VisuelRelais.Checked then fleche(x,y+0.5,b); end; if Rl.modele='3' then begin TraitFort(x-1.3,x+1.3,y-0.5); TraitFort(x-1.3,x+1.3,y+1.5); TraitFin(x-1,y-0.5,y+1.5); TraitFin(x+1,y-0.5,y+1.5); Rond(x+1,y); Rond(x+1,y+1); if Form1.VisuelRelais.Checked then fleche(x,y+0.5,b); end; if Rl.modele='4' then begin TraitFort(x-1.3,x+1.3,y-1); TraitFort(x-1.3,x+1.3,y+1); TraitFin(x-1,y-1,y+1); TraitFin(x+1,y-1,y+1); Rond(x+1,y); Rond(x-1,y); Form1.Image.Canvas.FillRect(Rect(ecranx(x-1),ecrany(y-1),ecranx(x+1),ecrany(y-0.5))); if Form1.VisuelRelais.Checked then fleche(x,y,b); end; if Rl.modele='5' then begin TraitFort(x-1.3,x+1.3,y-0.5); TraitFort(x-1.3,x+1.3,y+1.5); TraitFin(x-1,y-0.5,y+1.5); TraitFin(x+1,y-0.5,y+1.5); Rond(x-1,y); Rond(x-1,y+1); Form1.Image.Canvas.FillRect(Rect(ecranx(x-1),ecrany(y-0.5),ecranx(x+1),ecrany(y))); if Form1.VisuelRelais.Checked then fleche(x,y+0.5,b); end; if Rl.modele='6' then begin TraitFort(x-1.3,x+1.3,y-0.5); TraitFort(x-1.3,x+1.3,y+1.5); TraitFin(x-1,y-0.5,y+1.5); TraitFin(x+1,y-0.5,y+1.5); Rond(x+1,y); Rond(x+1,y+1); Form1.Image.Canvas.FillRect(Rect(ecranx(x-1),ecrany(y-0.5),ecranx(x+1),ecrany(y))); if Form1.VisuelRelais.Checked then fleche(x,y+0.5,b); end; if Rl.modele='7' then begin TraitFort(x-1.3,x+1.3,y-1); TraitFort(x-1.3,x+1.3,y+1); TraitFin(x-1,y-1,y+1); TraitFin(x+1,y-1,y+1); Rond(x+1,y); Rond(x-1,y); Form1.Image.Canvas.FillRect(Rect(ecranx(x-1),ecrany(y+0.5),ecranx(x+1),ecrany(y+1))); if Form1.VisuelRelais.Checked then fleche(x,y,b); end; if Rl.modele='8' then begin TraitFort(x-1.3,x+1.3,y-0.5); TraitFort(x-1.3,x+1.3,y+1.5); TraitFin(x-1,y-0.5,y+1.5); TraitFin(x+1,y-0.5,y+1.5); Rond(x-1,y); Rond(x-1,y+1); Form1.Image.Canvas.FillRect(Rect(ecranx(x-1),ecrany(y+1),ecranx(x+1),ecrany(y+1.5))); if Form1.VisuelRelais.Checked then fleche(x,y+0.5,b); end; if Rl.modele='9' then begin TraitFort(x-1.3,x+1.3,y-0.5); TraitFort(x-1.3,x+1.3,y+1.5); TraitFin(x-1,y-0.5,y+1.5); TraitFin(x+1,y-0.5,y+1.5); Rond(x+1,y); Rond(x+1,y+1); Form1.Image.Canvas.FillRect(Rect(ecranx(x-1),ecrany(y+1),ecranx(x+1),ecrany(y+1.5))); if Form1.VisuelRelais.Checked then fleche(x,y+0.5,b); end; if Rl.modele='10' then begin TraitFort(x-2.3,x+2.3,y-0.5); TraitFort(x-2.3,x+2.3,y+1.5); TraitFin(x-2,y-0.5,y+1.5); TraitFin(x+2,y-0.5,y+1.5); TraitFin(x-0.4,y-0.5,y+1.5); TraitFin(x+0.4,y-0.5,y+1.5); Rond(x+2,y); Rond(x+2,y+1); Rond(x-2,y); Rond(x-2,y+1); end; if Rl.modele='11' then begin TraitFort(x-1.3,x+1.3,y-2); TraitFort(x-1.3,x+1.3,y); TraitFort(x-1.3,x+1.3,y+2); TraitFin(x-1,y-2,y+2); TraitFin(x+1,y-2,y+2); Rond(x+1,y-1); Rond(x-1,y-1); Rond(x+1,y+1); Rond(x-1,y+1); Form1.Image.Canvas.Font.Color:=cl; Form1.Image.Canvas.Brush.Color:=ClrFd; Form1.Image.Canvas.Brush.Style:=BsClear; Form1.Image.Canvas.TextOut(ecranx(x-0.4),ecrany(y-1.5),'A'); Form1.Image.Canvas.TextOut(ecranx(x-0.4),ecrany(y+0.5),'M'); if Form1.VisuelRelais.Checked then fleche(x,y,b); end; if Rl.modele='12' then begin TraitFort(x-1.3,x+1.3,y-2); TraitFort(x-1.3,x+1.3,y); TraitFort(x-1.3,x+1.3,y+2); TraitFin(x-1,y-2,y+2); TraitFin(x+1,y-2,y+2); Rond(x+1,y-1); Rond(x-1,y-1); Rond(x+1,y+1); Rond(x-1,y+1); Form1.Image.Canvas.Font.Color:=cl; Form1.Image.Canvas.Brush.Color:=ClrFd; Form1.Image.Canvas.Brush.Style:=BsClear; Form1.Image.Canvas.TextOut(ecranx(x-0.6),ecrany(y-1.5),'+ -'); Form1.Image.Canvas.TextOut(ecranx(x-0.6),ecrany(y+0.5),'+ -'); if Form1.VisuelRelais.Checked then fleche(x,y,b); end; if Rl.Visible then begin Form1.Image.Canvas.Font.Color:=cl; Form1.Image.Canvas.Brush.Color:=ClrFd; Form1.Image.Canvas.Brush.Style:=BsClear; Texte(x+Rl.Pd.X/2,y+Rl.Pd.Y/2,Rl.nom); end; end; procedure DessineConnect(Cx:T_Connect); var cl:TColor; begin cl:=clBlack; if (EnCours or Cx.Select) and not bExec then cl:=clBlue; if bexec and (form1.Potentiels1.Checked) then cl:=ClrPotentiel(L_Potentiel[Cx.AppaPotentiel].Rp,L_Potentiel[Cx.AppaPotentiel].Rm); if bexec and (form1.Courants1.Checked) then begin if Cx.Parcouru=1 then cl:=clRed; end; Form1.Image.Canvas.Pen.Color:=cl; Form1.Image.Canvas.Brush.Color:=cl; Rond(Cx.P.X,Cx.P.Y); end; procedure DessineAlim(Al:T_Alim); var cl:TColor; s:string; begin cl:=clBlack; if (EnCours or Al.Select) and not bExec then cl:=clBlue; if bexec and (form1.Potentiels1.Checked) then begin if Al.modele='1' then cl:=clRed; if Al.modele='2' then cl:=clBlue; if (Al.modele='3') and pulse then cl:=clRed; end; if bexec and (form1.Courants1.Checked) then begin if Al.Parcouru=1 then cl:=clRed; end; //test(format('',[Al.])); Form1.Image.Canvas.Pen.Color:=cl; Form1.Image.Canvas.Brush.Color:=cl; Rond(Al.P.X,Al.P.Y); Form1.Image.Canvas.Font.Color:=cl; Form1.Image.Canvas.Brush.Color:=ClrFd; Form1.Image.Canvas.Brush.Style:=BsClear; s:='+'; if Al.modele='2' then s:='-'; if Al.modele='3' then s:='p'; Form1.Image.Canvas.TextOut(ecranx(Al.P.X-0.8),ecrany(Al.P.Y-1),s); end; procedure DessineSegment(Sg:T_Segment); var cl:TColor; s:string; begin cl:=clBlack; if (EnCours or Sg.Select1 or Sg.Select2) and not bExec then cl:=clBlue; if bexec and (form1.Potentiels1.Checked) then cl:=ClrPotentiel(L_Potentiel[L_Branche[Sg.AppaBranche].AppaPotentiel].Rp,L_Potentiel[L_Branche[Sg.AppaBranche].AppaPotentiel].Rm); // test(format('',[Sg.])); if bexec and (form1.Courants1.Checked) then begin if L_Branche[Sg.AppaBranche].Courant=-1 then cl:=clBlack; if L_Branche[Sg.AppaBranche].Courant=0 then cl:=clBlack; if L_Branche[Sg.AppaBranche].Courant=1 then cl:=clRed; end; Form1.Image.Canvas.Pen.Color:=cl; Form1.Image.Canvas.Brush.Color:=cl; Trait(Sg.P1.X,Sg.P1.Y,Sg.P2.X,Sg.P2.Y); // affichage branche { Form1.Image.Canvas.Font.Color:=clGreen; Form1.Image.Canvas.Brush.Color:=ClrFd; Form1.Image.Canvas.Brush.Style:=BsClear; s:=IntToStr(Sg.AppaBranche); if Sg.AppaBranche