287 lines
7.6 KiB
ObjectPascal
287 lines
7.6 KiB
ObjectPascal
unit UDessin;
|
|
|
|
interface
|
|
|
|
uses
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|
Dialogs, Menus, ExtCtrls, Math,
|
|
UInit, UDessinComposant;
|
|
|
|
procedure EffaceImage;
|
|
procedure Affichage;
|
|
procedure Decalage(x,y:integer);
|
|
procedure DeplaceSelection(x,y:integer);
|
|
|
|
implementation
|
|
|
|
uses Unit1,UTest;
|
|
|
|
// Efface l'image
|
|
procedure EffaceImage;
|
|
begin
|
|
with Form1.Image.Canvas do begin
|
|
Brush.Color:=ClrFd; //couleur de fond;
|
|
FillRect(ClipRect);
|
|
end; // with Form1.Image.Canvas
|
|
end;
|
|
|
|
procedure Affichage;
|
|
var x,y,k,i : integer;
|
|
xmin,ymin,xmax,ymax:integer;
|
|
xx,yy:integer;
|
|
begin
|
|
// test('Affichage');
|
|
|
|
i:=round(10/zoom);
|
|
|
|
Form1.Image.Canvas.Font.Size:=i;
|
|
|
|
if i<1 then i:=1;
|
|
if i>60 then i:=60;
|
|
|
|
xmin:=0;xmax:=0;
|
|
ymin:=0;ymax:=0;
|
|
|
|
for i:=0 to Nb_Relais - 1 do begin
|
|
if L_Relais[i].P.X>xmax then xmax:=L_Relais[i].P.X;
|
|
if L_Relais[i].P.X<xmin then xmin:=L_Relais[i].P.X;
|
|
if L_Relais[i].P.Y>ymax then ymax:=L_Relais[i].P.Y;
|
|
if L_Relais[i].P.Y<ymin then ymin:=L_Relais[i].P.Y;
|
|
end;
|
|
|
|
for i:=0 to Nb_Connect - 1 do begin
|
|
if L_Connect[i].P.X>xmax then xmax:=L_Connect[i].P.X;
|
|
if L_Connect[i].P.X<xmin then xmin:=L_Connect[i].P.X;
|
|
if L_Connect[i].P.Y>ymax then ymax:=L_Connect[i].P.Y;
|
|
if L_Connect[i].P.Y<ymin then ymin:=L_Connect[i].P.Y;
|
|
end;
|
|
|
|
for i:=0 to Nb_Contact - 1 do begin
|
|
if L_Contact[i].P.X>xmax then xmax:=L_Contact[i].P.X;
|
|
if L_Contact[i].P.X<xmin then xmin:=L_Contact[i].P.X;
|
|
if L_Contact[i].P.Y>ymax then ymax:=L_Contact[i].P.Y;
|
|
if L_Contact[i].P.Y<ymin then ymin:=L_Contact[i].P.Y;
|
|
end;
|
|
|
|
for i:=0 to Nb_Segment - 1 do begin
|
|
if L_Segment[i].P1.X>xmax then xmax:=L_Segment[i].P1.X;
|
|
if L_Segment[i].P1.X<xmin then xmin:=L_Segment[i].P1.X;
|
|
if L_Segment[i].P1.Y>ymax then ymax:=L_Segment[i].P1.Y;
|
|
if L_Segment[i].P1.Y<ymin then ymin:=L_Segment[i].P1.Y;
|
|
if L_Segment[i].P2.X>xmax then xmax:=L_Segment[i].P2.X;
|
|
if L_Segment[i].P2.X<xmin then xmin:=L_Segment[i].P2.X;
|
|
if L_Segment[i].P2.Y>ymax then ymax:=L_Segment[i].P2.Y;
|
|
if L_Segment[i].P2.Y<ymin then ymin:=L_Segment[i].P2.Y;
|
|
end;
|
|
|
|
for i:=0 to Nb_Alim - 1 do begin
|
|
if L_Alim[i].P.X>xmax then xmax:=L_Alim[i].P.X;
|
|
if L_Alim[i].P.X<xmin then xmin:=L_Alim[i].P.X;
|
|
if L_Alim[i].P.Y>ymax then ymax:=L_Alim[i].P.Y;
|
|
if L_Alim[i].P.Y<ymin then ymin:=L_Alim[i].P.Y;
|
|
end;
|
|
|
|
for i:=0 to Nb_Compo - 1 do begin
|
|
if L_Compo[i].P.X>xmax then xmax:=L_Compo[i].P.X;
|
|
if L_Compo[i].P.X<xmin then xmin:=L_Compo[i].P.X;
|
|
if L_Compo[i].P.Y>ymax then ymax:=L_Compo[i].P.Y;
|
|
if L_Compo[i].P.Y<ymin then ymin:=L_Compo[i].P.Y;
|
|
end;
|
|
|
|
for i:=0 to Nb_Lampe - 1 do begin
|
|
if L_Lampe[i].P.X>xmax then xmax:=L_Lampe[i].P.X;
|
|
if L_Lampe[i].P.X<xmin then xmin:=L_Lampe[i].P.X;
|
|
if L_Lampe[i].P.Y>ymax then ymax:=L_Lampe[i].P.Y;
|
|
if L_Lampe[i].P.Y<ymin then ymin:=L_Lampe[i].P.Y;
|
|
end;
|
|
|
|
|
|
xmax:=xmax+1;
|
|
sbx:=round(cordo(Form1.Image.Width-1)/4);
|
|
xx:=1+round(0.5+4*(xmax/cordo(Form1.Image.Width)-1));
|
|
if xx<0 then xx:=0;
|
|
form1.SB_Hor.Max:=xx;
|
|
|
|
ymax:=ymax+1;
|
|
sby:=round(cordo(Form1.Image.Height-1)/4);
|
|
yy:=1+round(0.5+4*(ymax/cordo(Form1.Image.Height)-1));
|
|
if yy<0 then yy:=0;
|
|
form1.SB_Ver.Max:=yy;
|
|
|
|
|
|
// form1.memo1.lines.Add('*');
|
|
// form1.memo1.lines.Add(IntToStr(Form1.Image.Width)+' c:'+IntToStr(cordo(Form1.Image.Width)));
|
|
// form1.memo1.lines.Add('max '+IntToStr(xmax)+' e:'+IntToStr(ecran(xmax)));
|
|
// form1.memo1.lines.Add(VarToStr(round(0.5+4*(xmax/cordo(Form1.Image.Width)-1))));
|
|
|
|
|
|
EffaceImage;
|
|
// Grille
|
|
with Form1.Image do begin
|
|
if Form1.Grille.Checked and not bexec then begin
|
|
Canvas.Pen.Color:=ClrGr;
|
|
Canvas.Pen.Style:=psSolid;
|
|
Canvas.Pen.Width:=1;
|
|
for x:=0 to 1+round(zoom*Width/Facteur) do begin // combien
|
|
k:= round(x*Facteur/zoom);
|
|
Canvas.MoveTo(k,0);
|
|
Canvas.LineTo(k,Height);
|
|
end; // for x
|
|
for y:=0 to 1+round(zoom*Height/Facteur) do begin
|
|
k:= round(y*Facteur/zoom);
|
|
Canvas.MoveTo(0,k); Canvas.LineTo(Width,k);
|
|
end; // for y
|
|
end; // if grille
|
|
|
|
|
|
for i:=0 to Nb_Segment - 1 do begin
|
|
EnCours:= (CompoEnCours='S') and (NumeroEnCours=i);
|
|
sss:=IntToStr(i);
|
|
DessineSegment(L_Segment[i]);
|
|
end;
|
|
|
|
for i:=0 to Nb_Alim - 1 do begin
|
|
EnCours:= (CompoEnCours='A') and (NumeroEnCours=i);
|
|
DessineAlim(L_Alim[i]);
|
|
end;
|
|
|
|
for i:=0 to Nb_Relais - 1 do begin
|
|
EnCours:= (CompoEnCours='R') and (NumeroEnCours=i);
|
|
DessineRelais(L_Relais[i]);
|
|
end;
|
|
|
|
for i:=0 to Nb_Lampe - 1 do begin
|
|
EnCours:= (CompoEnCours='L') and (NumeroEnCours=i);
|
|
DessineLampe(L_Lampe[i]);
|
|
end;
|
|
|
|
|
|
//**//**
|
|
for i:=0 to Nb_Contact - 1 do begin
|
|
EnCours:= (CompoEnCours='C') and (NumeroEnCours=i);
|
|
DessineContact(L_Contact[i]);
|
|
end;
|
|
|
|
|
|
for i:=0 to Nb_Compo - 1 do begin
|
|
EnCours:= (CompoEnCours='P') and (NumeroEnCours=i);
|
|
DessineCompo(L_Compo[i]);
|
|
end;
|
|
|
|
for i:=0 to Nb_Connect - 1 do begin
|
|
EnCours:= (CompoEnCours='X') and (NumeroEnCours=i);
|
|
DessineConnect(L_Connect[i]);
|
|
end;
|
|
|
|
if blier then begin
|
|
Form1.Image.Canvas.Pen.Color:=clBlue;
|
|
trait(dx,dy,fx,fy);
|
|
end;
|
|
|
|
if bselection then begin
|
|
Form1.Image.Canvas.Pen.Color:=cllime;
|
|
Form1.Image.Canvas.Brush.Style:=bsClear;
|
|
Form1.Image.Canvas.Rectangle(ecranx(dx),ecrany(dy),ecranx(fx),ecrany(fy));
|
|
end;
|
|
|
|
end; // With FPrinc.Image
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure Decalage(x,y:integer);
|
|
var i:integer;
|
|
begin
|
|
|
|
for i:=0 to Nb_Relais - 1 do begin
|
|
L_Relais[i].P.X:=L_Relais[i].P.X-x;
|
|
L_Relais[i].P.Y:=L_Relais[i].P.Y-y;
|
|
end;
|
|
for i:=0 to Nb_Lampe - 1 do begin
|
|
L_Lampe[i].P.X:=L_Lampe[i].P.X-x;
|
|
L_Lampe[i].P.Y:=L_Lampe[i].P.Y-y;
|
|
end;
|
|
|
|
|
|
for i:=0 to Nb_Connect - 1 do begin
|
|
L_Connect[i].P.X:=L_Connect[i].P.X-x;
|
|
L_Connect[i].P.Y:=L_Connect[i].P.Y-y;
|
|
end;
|
|
|
|
for i:=0 to Nb_Contact - 1 do begin
|
|
L_Contact[i].P.X:=L_Contact[i].P.X-x;
|
|
L_Contact[i].P.Y:=L_Contact[i].P.Y-y;
|
|
end;
|
|
|
|
for i:=0 to Nb_Segment - 1 do begin
|
|
L_Segment[i].P1.X:=L_Segment[i].P1.X-x;
|
|
L_Segment[i].P1.Y:=L_Segment[i].P1.Y-y;
|
|
L_Segment[i].P2.X:=L_Segment[i].P2.X-x;
|
|
L_Segment[i].P2.Y:=L_Segment[i].P2.Y-y;
|
|
end;
|
|
|
|
for i:=0 to Nb_Alim - 1 do begin
|
|
L_Alim[i].P.X:=L_Alim[i].P.X-x;
|
|
L_Alim[i].P.Y:=L_Alim[i].P.Y-y;
|
|
end;
|
|
|
|
for i:=0 to Nb_Compo - 1 do begin
|
|
L_Compo[i].P.X:=L_Compo[i].P.X-x;
|
|
L_Compo[i].P.Y:=L_Compo[i].P.Y-y;
|
|
end;
|
|
|
|
Affichage;
|
|
end;
|
|
|
|
|
|
procedure DeplaceSelection(x,y:integer);
|
|
var i:integer;
|
|
begin
|
|
for i:=0 to Nb_Relais - 1 do if L_Relais[i].Select then begin
|
|
L_Relais[i].P.X:=L_Relais[i].P.X-x;
|
|
L_Relais[i].P.Y:=L_Relais[i].P.Y-y;
|
|
end;
|
|
|
|
for i:=0 to Nb_Lampe - 1 do if L_Lampe[i].Select then begin
|
|
L_Lampe[i].P.X:=L_Lampe[i].P.X-x;
|
|
L_Lampe[i].P.Y:=L_Lampe[i].P.Y-y;
|
|
end;
|
|
|
|
for i:=0 to Nb_Connect - 1 do if L_Connect[i].Select then begin
|
|
L_Connect[i].P.X:=L_Connect[i].P.X-x;
|
|
L_Connect[i].P.Y:=L_Connect[i].P.Y-y;
|
|
end;
|
|
|
|
for i:=0 to Nb_Contact - 1 do if L_Contact[i].Select then begin
|
|
L_Contact[i].P.X:=L_Contact[i].P.X-x;
|
|
L_Contact[i].P.Y:=L_Contact[i].P.Y-y;
|
|
end;
|
|
|
|
for i:=0 to Nb_Segment - 1 do begin
|
|
if L_Segment[i].Select1 then begin
|
|
L_Segment[i].P1.X:=L_Segment[i].P1.X-x;
|
|
L_Segment[i].P1.Y:=L_Segment[i].P1.Y-y;
|
|
end;
|
|
if L_Segment[i].Select2 then begin
|
|
L_Segment[i].P2.X:=L_Segment[i].P2.X-x;
|
|
L_Segment[i].P2.Y:=L_Segment[i].P2.Y-y;
|
|
end;
|
|
end;
|
|
|
|
for i:=0 to Nb_Alim - 1 do if L_Alim[i].Select then begin
|
|
L_Alim[i].P.X:=L_Alim[i].P.X-x;
|
|
L_Alim[i].P.Y:=L_Alim[i].P.Y-y;
|
|
end;
|
|
|
|
for i:=0 to Nb_Compo - 1 do if L_Compo[i].Select then begin
|
|
L_Compo[i].P.X:=L_Compo[i].P.X-x;
|
|
L_Compo[i].P.Y:=L_Compo[i].P.Y-y;
|
|
end;
|
|
|
|
Affichage;
|
|
end;
|
|
|
|
|
|
end.
|