Initial commit with my code directory

This commit is contained in:
2024-04-18 11:56:48 +02:00
commit 0ecfdf0ba7
158 changed files with 60438 additions and 0 deletions

23
code_JMW/Project1.dpr Normal file
View File

@@ -0,0 +1,23 @@
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
UInit in 'UInit.pas',
UDessin in 'UDessin.pas',
Uedit in 'Uedit.pas',
UDessinComposant in 'UDessinComposant.pas',
UES in 'UES.pas',
Ufonctions in 'Ufonctions.pas',
Upage in 'Upage.pas',
Uexec in 'Uexec.pas',
Utest in 'Utest.pas';
{$R *.res}
begin
Application.Initialize;
Application.Title := 'AnimIES';
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

286
code_JMW/UDessin.pas Normal file
View File

@@ -0,0 +1,286 @@
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.

File diff suppressed because it is too large Load Diff

193
code_JMW/UES.pas Normal file
View File

@@ -0,0 +1,193 @@
unit UES;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls,IniFiles,
UInit,UTest;
procedure Enregistrer;
procedure Ouvrir;
implementation
uses Unit1;
procedure Enregistrer;
var
F:TIniFile;
i:integer;
begin
if Form1.SaveDialog.Execute then begin
F:=TIniFile.Create(Form1.SaveDialog.FileName);
F.WriteInteger('CP','R',Nb_Relais);
F.WriteInteger('CP','L',Nb_Lampe);
F.WriteInteger('CP','X',Nb_Connect);
F.WriteInteger('CP','C',Nb_Contact);
F.WriteInteger('CP','P',Nb_Compo);
F.WriteInteger('CP','S',Nb_Segment);
F.WriteInteger('CP','A',Nb_Alim);
for i:=0 to Nb_Relais-1 do begin
F.WriteInteger('R'+IntToStr(i),'x',L_Relais[i].P.x);
F.WriteInteger('R'+IntToStr(i),'y',L_Relais[i].P.y);
F.WriteInteger('R'+IntToStr(i),'dx',L_Relais[i].Pd.X);
F.WriteInteger('R'+IntToStr(i),'dy',L_Relais[i].Pd.Y);
F.WriteInteger('R'+IntToStr(i),'t',L_Relais[i].tpr);
F.WriteString('R'+IntToStr(i),'m',L_Relais[i].modele);
F.WriteString('R'+IntToStr(i),'n',L_Relais[i].nom);
F.WriteBool('R'+IntToStr(i),'v',L_Relais[i].Visible);
end;
for i:=0 to Nb_Lampe-1 do begin
F.WriteInteger('L'+IntToStr(i),'x',L_Lampe[i].P.x);
F.WriteInteger('L'+IntToStr(i),'y',L_Lampe[i].P.y);
F.WriteInteger('L'+IntToStr(i),'dx',L_Lampe[i].Pd.X);
F.WriteInteger('L'+IntToStr(i),'dy',L_Lampe[i].Pd.Y);
F.WriteInteger('L'+IntToStr(i),'C0',L_Lampe[i].Clr0);
F.WriteInteger('L'+IntToStr(i),'C1',L_Lampe[i].Clr1);
F.WriteString('L'+IntToStr(i),'m',L_Lampe[i].modele);
F.WriteString('L'+IntToStr(i),'n',L_Lampe[i].nom);
F.WriteBool('L'+IntToStr(i),'v',L_Lampe[i].Visible);
end;
for i:=0 to Nb_Connect-1 do begin
F.WriteInteger('X'+IntToStr(i),'x',L_Connect[i].P.X);
F.WriteInteger('X'+IntToStr(i),'y',L_Connect[i].P.Y);
end;
for i:=0 to Nb_Contact-1 do begin
F.WriteInteger('C'+IntToStr(i),'x',L_Contact[i].P.x);
F.WriteInteger('C'+IntToStr(i),'y',L_Contact[i].P.y);
F.WriteString('C'+IntToStr(i),'m',L_Contact[i].modele);
F.WriteBool('C'+IntToStr(i),'i',L_Contact[i].EtatI);
F.WriteBool('C'+IntToStr(i),'j',L_Contact[i].Manuel);
F.WriteString('C'+IntToStr(i),'n',L_Contact[i].nom);
F.WriteBool('C'+IntToStr(i),'v',L_Contact[i].Visible);
F.WriteInteger('C'+IntToStr(i),'dx',L_Contact[i].Pd.X);
F.WriteInteger('C'+IntToStr(i),'dy',L_Contact[i].Pd.Y);
end;
for i:=0 to Nb_Compo-1 do begin
F.WriteInteger('P'+IntToStr(i),'x',L_Compo[i].P.x);
F.WriteInteger('P'+IntToStr(i),'y',L_Compo[i].P.y);
F.WriteString('P'+IntToStr(i),'m',L_Compo[i].modele);
end;
for i:=0 to Nb_Segment-1 do begin
F.WriteInteger('S'+IntToStr(i),'xa',L_Segment[i].P1.X);
F.WriteInteger('S'+IntToStr(i),'ya',L_Segment[i].P1.Y);
F.WriteInteger('S'+IntToStr(i),'xb',L_Segment[i].P2.X);
F.WriteInteger('S'+IntToStr(i),'yb',L_Segment[i].P2.Y);
end;
for i:=0 to Nb_Alim-1 do begin
F.WriteInteger('A'+IntToStr(i),'x',L_Alim[i].P.x);
F.WriteInteger('A'+IntToStr(i),'y',L_Alim[i].P.y);
F.WriteString('A'+IntToStr(i),'m',L_Alim[i].modele);
end;
F.Free;
end;
end;
procedure Ouvrir;
var
F:TIniFile;
i:integer;
begin
if Form1.OpenDialog1.Execute then begin
Initialisation;
F:=TIniFile.Create(Form1.OpenDialog1.FileName);
Nb_Relais:=F.ReadInteger('CP','R',0);
Nb_Lampe:=F.ReadInteger('CP','L',0);
Nb_Connect:=F.ReadInteger('CP','X',0);
Nb_Contact:=F.ReadInteger('CP','C',0);
Nb_Compo:=F.ReadInteger('CP','P',0);
Nb_Segment:=F.ReadInteger('CP','S',0);
Nb_Alim:=F.ReadInteger('CP','A',0);
SetLength(L_Relais,Nb_Relais);
for i:=0 to Nb_Relais-1 do begin
L_Relais[i].P.x:=F.ReadInteger('R'+IntToStr(i),'x',0);
L_Relais[i].P.y:=F.ReadInteger('R'+IntToStr(i),'y',0);
L_Relais[i].Pd.X:=F.ReadInteger('R'+IntToStr(i),'dx',0);
L_Relais[i].Pd.Y:=F.ReadInteger('R'+IntToStr(i),'dy',0);
L_Relais[i].tpr:=F.ReadInteger('R'+IntToStr(i),'t',0);
L_Relais[i].modele:=F.ReadString('R'+IntToStr(i),'m','');
L_Relais[i].nom:=F.ReadString('R'+IntToStr(i),'n','');
L_Relais[i].Visible:=F.ReadBool('R'+IntToStr(i),'v',false);
end;
SetLength(L_Lampe,Nb_Lampe);
for i:=0 to Nb_Lampe-1 do begin
L_Lampe[i].P.x:=F.ReadInteger('L'+IntToStr(i),'x',0);
L_Lampe[i].P.y:=F.ReadInteger('L'+IntToStr(i),'y',0);
L_Lampe[i].Pd.X:=F.ReadInteger('L'+IntToStr(i),'dx',0);
L_Lampe[i].Pd.Y:=F.ReadInteger('L'+IntToStr(i),'dy',0);
L_Lampe[i].Clr0:=F.ReadInteger('L'+IntToStr(i),'C0',RGB(160,160,160));
L_Lampe[i].Clr1:=F.ReadInteger('L'+IntToStr(i),'C1',RGB(255,0,0));
L_Lampe[i].modele:=F.ReadString('L'+IntToStr(i),'m','');
L_Lampe[i].nom:=F.ReadString('L'+IntToStr(i),'n','');
L_Lampe[i].Visible:=F.ReadBool('L'+IntToStr(i),'v',false);
end;
SetLength(L_Connect,Nb_Connect);
for i:=0 to Nb_Connect-1 do begin
L_Connect[i].P.X:=F.ReadInteger('X'+IntToStr(i),'x',0);
L_Connect[i].P.Y:=F.ReadInteger('X'+IntToStr(i),'y',0);
end;
SetLength(L_Contact,Nb_Contact);
for i:=0 to Nb_Contact-1 do begin
L_Contact[i].P.x:=F.ReadInteger('C'+IntToStr(i),'x',0);
L_Contact[i].P.y:=F.ReadInteger('C'+IntToStr(i),'y',0);
L_Contact[i].modele:=F.ReadString('C'+IntToStr(i),'m','');
L_Contact[i].EtatI:=F.ReadBool('C'+IntToStr(i),'i',false);
L_Contact[i].Manuel:=F.ReadBool('C'+IntToStr(i),'j',false);
L_Contact[i].nom:=F.ReadString('C'+IntToStr(i),'n','');
L_Contact[i].Visible:=F.ReadBool('C'+IntToStr(i),'v',false);
L_Contact[i].Pd.X:=F.ReadInteger('C'+IntToStr(i),'dx',0);
L_Contact[i].Pd.Y:=F.ReadInteger('C'+IntToStr(i),'dy',0);
L_Contact[i].Select:=false;
end;
SetLength(L_Compo,Nb_Compo);
for i:=0 to Nb_Compo-1 do begin
L_Compo[i].P.x:=F.ReadInteger('P'+IntToStr(i),'x',0);
L_Compo[i].P.y:=F.ReadInteger('P'+IntToStr(i),'y',0);
L_Compo[i].modele:=F.ReadString('P'+IntToStr(i),'m','');
end;
SetLength(L_Segment,Nb_Segment);
for i:=0 to Nb_Segment-1 do begin
L_Segment[i].P1.X:=F.ReadInteger('S'+IntToStr(i),'xa',0);
L_Segment[i].P1.Y:=F.ReadInteger('S'+IntToStr(i),'ya',0);
L_Segment[i].P2.X:=F.ReadInteger('S'+IntToStr(i),'xb',0);
L_Segment[i].P2.Y:=F.ReadInteger('S'+IntToStr(i),'yb',0);
end;
SetLength(L_Alim,Nb_Alim);
for i:=0 to Nb_Alim-1 do begin
L_Alim[i].P.x:=F.ReadInteger('A'+IntToStr(i),'x',0);
L_Alim[i].P.y:=F.ReadInteger('A'+IntToStr(i),'y',0);
L_Alim[i].modele:=F.ReadString('A'+IntToStr(i),'m','');
end;
F.Free;
end;
end;
end.

258
code_JMW/UInit.pas Normal file
View File

@@ -0,0 +1,258 @@
unit UInit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls;
type
// T_APoints = array of TPoint;
T_Relais = record
P,Pd:TPoint;
modele,nom : string;
EtatB : boolean;
Select,Visible:boolean;
Fonction : integer;
AppPot : array [0..3] of integer;
tpo,tpr:longword;
end;
T_Connect = record
P:TPoint;
Select:boolean;
AppaPotentiel : integer;
Parcouru :integer;
end;
T_Contact = record
P,Pd:TPoint;
modele,nom : string;
Select, visible : boolean;
EtatI, EtatP, EtatF : boolean;
Manuel : boolean;
Fonction : integer;
Parcouru :integer;
cl0,cl1,cl2:TColor;
end;
T_Segment = record
P1,P2:TPoint;
Select1,Select2 : boolean;
Cote1,Cote2 : string;
AppaBranche : integer;
end;
T_Alim = record
P:TPoint;
modele : string;
Select:boolean;
Parcouru :integer;
end;
T_Compo = record
P:TPoint;
modele : string;
Select:boolean;
AppPot : array [0..3] of integer;
end;
T_Lampe = record
P,Pd:TPoint;
modele,nom : string;
Clr0,Clr1:TColor;
EtatB : boolean;
AppPot : array [0..3] of integer;
Select,Visible:boolean;
end;
T_Branche = record
AppaPotentiel : integer;
EtatP, EtatF : boolean;
CompSegments :array of integer;
Cote1,Cote2 : string;
Courant:integer;
Parcouru :integer;
end;
T_Potentiel = record
CompBranches :array of integer;
Rp,Rm,PRp,PRm,Np,Nm:integer;
end;
T_Fonction = record
nom,comp : string;
x:integer;
EtatP, EtatF : boolean;
end;
procedure Initialisation;
var
ClrFd : TColor=clWhite; // couleur de fond
ClrGr : TColor=$00C8C8C8; // couleur grille
Zoom : Real;
Facteur,sbx,sby : Integer;
Nb_Relais, Nb_Connect, Nb_Contact, Nb_Segment, Nb_Alim, Nb_Compo, Nb_Lampe : Integer;
Nb_Branche, Nb_Potentiel, Nb_Fonction : Integer;
L_Relais : array of T_Relais;
L_Connect : array of T_Connect;
L_Contact : array of T_Contact;
L_Compo : array of T_Compo;
L_Segment : array of T_Segment;
L_Alim : array of T_Alim;
L_Branche : array of T_Branche;
L_Potentiel : array of T_Potentiel;
L_Fonction : array of T_Fonction;
L_Lampe : array of T_Lampe;
// L_ContactX : array[0 .. 15] of T_APoints;
L_ContactX : array[0 .. 15] of array of TPoint;
L_CompoX : array[0 .. 4] of array of TPoint;
L_RelaisX : array[0 .. 14] of array of TPoint;
L_LampeX : array[0 .. 4] of array of TPoint;
dX, dY,fX, fY: double;
CompoEnCours,sss,EtatF:string;
NumeroEnCours:integer;
EnCours,pulse:boolean;
bEdit,bRelier,bLier,bExec,bExec2:boolean;
bSelectionner,bSelection: boolean;
gtm: LongInt;
bct:boolean;
gtc,gtc1:cardinal;
implementation
uses unit1, UDessin;
procedure Initialisation;
var i:integer;
begin
bRelier:=false;
bExec:=false;
bExec2:=false;
Zoom:=1;
Facteur:=16;
CompoEnCours:='';
NumeroEnCours:=-1;
EnCours:=false;
//Deplacer:=false;
Nb_relais:=0; Nb_Connect:=0;Nb_Contact:=0; Nb_Segment:=0; Nb_Alim:=0; Nb_Compo:=0;
Nb_Branche:=0; Nb_Potentiel:=0; Nb_Fonction:=0; Nb_Lampe:=0;
With Form1 do begin
//Pnl_Haut.Align:=alTop;
Pnl_Editer.Align:=alTop;
Pnl_Composants.Align:=alTop;
Pnl_Image.Align:=alClient;
Image.Align:=alClient;
Image.Canvas.Font.Name:='Arial';
Pnl_Editer.Visible:=false;
Pnl_Composants.Visible:=false;
end;
Affichage;
// affecte les connexions aux composants
for i:=1 to 17 do begin
setlength(L_ContactX[i],2);
if (i=1) or (i=2) or (i=10) or (i=13) or (i=14) or (i=15) or (i=16) or (i=17) then begin
L_ContactX[i,0]:=Point(-1,0);
L_ContactX[i,1]:=Point(1,0);
end;
if (i=3) or (i=11) then begin
L_ContactX[i,0]:=Point(-1,1);
L_ContactX[i,1]:=Point(1,1);
end;
if (i=4) or (i=12) then begin
L_ContactX[i,0]:=Point(-1,1);
L_ContactX[i,1]:=Point(1,1);
end;
if (i=7) then begin
L_ContactX[i,0]:=Point(1,-1);
L_ContactX[i,1]:=Point(0,1);
end;
if (i=8) then begin
L_ContactX[i,0]:=Point(-1,-1);
L_ContactX[i,1]:=Point(0,1);
end;
if (i=9) then begin
setlength(L_ContactX[i],3);
L_ContactX[i,0]:=Point(0,1);
L_ContactX[i,1]:=Point(1,-1);
L_ContactX[i,2]:=Point(-1,-1);
end;
if (i=5) then begin
setlength(L_ContactX[i],3);
L_ContactX[i,0]:=Point(-1,1);
L_ContactX[i,1]:=Point(1,0);
L_ContactX[i,2]:=Point(1,1);
end;
if (i=6) then begin
setlength(L_ContactX[i],3);
L_ContactX[i,0]:=Point(1,1);
L_ContactX[i,1]:=Point(-1,0);
L_ContactX[i,2]:=Point(-1,1);
end;
end; // ContactX
for i:=1 to 1 do begin
setlength(L_CompoX[i],2);
if (i=1) then begin
L_CompoX[i,0]:=Point(-1,0);
L_CompoX[i,1]:=Point(1,0);
end;
end; // CompoX
for i:=1 to 2 do begin
setlength(L_LampeX[i],2);
if (i=1) then begin
L_LampeX[i,0]:=Point(-1,0);
L_LampeX[i,1]:=Point(1,0);
end;
if (i=2) then begin
L_LampeX[i,0]:=Point(0,-1);
L_LampeX[i,1]:=Point(0,1);
end;
end; // LampeX
for i:=1 to 14 do begin
setlength(L_RelaisX[i],2);
if (i=1) or (i=4) or (i=7) then begin
L_RelaisX[i,0]:=Point(-1,0);
L_RelaisX[i,1]:=Point(1,0);
end;
if (i=2) or (i=5) or (i=8) then begin
L_RelaisX[i,0]:=Point(-1,0);
L_RelaisX[i,1]:=Point(-1,1);
end;
if (i=3) or (i=6) or (i=9) then begin
L_RelaisX[i,0]:=Point(1,0);
L_RelaisX[i,1]:=Point(1,1);
end;
if (i=10) then begin // basculeur
setlength(L_RelaisX[i],4);
L_RelaisX[i,0]:=Point(-2,0);
L_RelaisX[i,1]:=Point(-2,1);
L_RelaisX[i,2]:=Point(2,0);
L_RelaisX[i,3]:=Point(2,1);
end;
if (i=11) or (i=12) then begin // basculeur
setlength(L_RelaisX[i],4);
L_RelaisX[i,0]:=Point(-1,-1);
L_RelaisX[i,1]:=Point(1,-1);
L_RelaisX[i,2]:=Point(-1,1);
L_RelaisX[i,3]:=Point(1,1);
end;
end; // RelaisX
end;
end.

530
code_JMW/Uedit.pas Normal file
View File

@@ -0,0 +1,530 @@
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 d1<d then swap('R');
end;
for i:=0 to Nb_Lampe - 1 do begin
d1:=sqrt(sqr(L_Lampe[i].P.X-dx)+sqr(L_Lampe[i].P.Y-dy));
if d1<d then swap('L');
end;
for i:=0 to Nb_Connect - 1 do begin
d1:=sqrt(sqr(L_Connect[i].P.X-dx)+sqr(L_Connect[i].P.Y-dy));
if d1<d then swap('X');
end;
for i:=0 to Nb_Contact - 1 do begin
d1:=sqrt(sqr(L_Contact[i].P.X-dx)+sqr(L_Contact[i].P.Y-dy));
if d1<d then swap('C');
end;
for i:=0 to Nb_Compo - 1 do begin
d1:=sqrt(sqr(L_Compo[i].P.X-dx)+sqr(L_Compo[i].P.Y-dy));
if d1<d then swap('P');
end;
for i:=0 to Nb_Segment - 1 do begin
d01:= distance(L_Segment[i].P1.X,L_Segment[i].P1.Y,dx,dy);
d02:= distance(dx,dy,L_Segment[i].P2.X,L_Segment[i].P2.Y);;
d2:= distance(L_Segment[i].P1.X,L_Segment[i].P1.Y,L_Segment[i].P2.X,L_Segment[i].P2.Y);
d1:= dist_proj_ortho(L_Segment[i].P1.X,L_Segment[i].P1.Y,L_Segment[i].P2.X,L_Segment[i].P2.Y,dx,dy);
if (d1<d) and (d2>d01) 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<d then swap('A');
end;
for i:=0 to Nb_Relais - 1 do L_Relais[i].Select := (sc='R') and (i=ic);
for i:=0 to Nb_Lampe - 1 do L_Lampe[i].Select := (sc='L') and (i=ic);
for i:=0 to Nb_Connect - 1 do L_Connect[i].Select := (sc='X') and (i=ic);
for i:=0 to Nb_Contact - 1 do L_Contact[i].Select := (sc='C') and (i=ic);
for i:=0 to Nb_Compo - 1 do L_Compo[i].Select := (sc='P') and (i=ic);
for i:=0 to Nb_Segment - 1 do begin
L_Segment[i].Select1 := (sc='S') and (i=ic);
L_Segment[i].Select2 := (sc='S') and (i=ic);
end;
for i:=0 to Nb_Alim - 1 do L_Alim[i].Select := (sc='A') and (i=ic);
end else begin
for i:=0 to Nb_Relais - 1 do L_Relais[i].Select := entre(L_Relais[i].P.X,dx,fx) and entre(L_Relais[i].P.Y,dy,fy);
for i:=0 to Nb_Lampe - 1 do L_Lampe[i].Select := entre(L_Lampe[i].P.X,dx,fx) and entre(L_Lampe[i].P.Y,dy,fy);
for i:=0 to Nb_Connect - 1 do L_Connect[i].Select := entre(L_Connect[i].P.X,dx,fx) and entre(L_Connect[i].P.Y,dy,fy);
for i:=0 to Nb_Contact - 1 do L_Contact[i].Select := entre(L_Contact[i].P.X,dx,fx) and entre(L_Contact[i].P.Y,dy,fy);
for i:=0 to Nb_Compo - 1 do L_Compo[i].Select := entre(L_Compo[i].P.X,dx,fx) and entre(L_Compo[i].P.Y,dy,fy);
for i:=0 to Nb_Segment - 1 do begin
L_Segment[i].Select1 := entre(L_Segment[i].P1.X,dx,fx) and entre(L_Segment[i].P1.Y,dy,fy);
L_Segment[i].Select2 := entre(L_Segment[i].P2.X,dx,fx) and entre(L_Segment[i].P2.Y,dy,fy);
end;
for i:=0 to Nb_Alim - 1 do L_Alim[i].Select := entre(L_Alim[i].P.X,dx,fx) and entre(L_Alim[i].P.Y,dy,fy);
end;
b:=false;
for i:=0 to Nb_Relais - 1 do b:=b or L_Relais[i].Select;
for i:=0 to Nb_Lampe - 1 do b:=b or L_Lampe[i].Select;
for i:=0 to Nb_Connect - 1 do b:=b or L_Connect[i].Select;
for i:=0 to Nb_Contact - 1 do b:=b or L_Contact[i].Select;
for i:=0 to Nb_Compo - 1 do b:=b or L_Compo[i].Select;
for i:=0 to Nb_Segment - 1 do b:=b or L_Segment[i].Select1 or L_Segment[i].Select2;
for i:=0 to Nb_Alim - 1 do b:=b or L_Alim[i].Select;
Form1.BBtn_Gauche.Enabled:=b;
Form1.BBtn_Droite.Enabled:=b;
Form1.BBtn_Haut.Enabled:=b;
Form1.BBtn_Bas.Enabled:=b;
Form1.BBtn_Supprime.Enabled:=b;
Affichage;
end;
procedure Resegmentation;
var i,j,cc:integer;
cdi,cdj,cbi,cbj:double;
b,bc:boolean;
x1,y1,x2,y2 : integer;
Seg:T_Segment;
begin
// segment nuls mis <20> z<>ro et supprim<69>s plus tard
for i:=0 to Nb_Segment - 1 do begin
if (L_Segment[i].P1.X=L_Segment[i].P2.X) and (L_Segment[i].P1.Y=L_Segment[i].P2.Y) then begin
L_Segment[i].P1.X:=0; L_Segment[i].P1.Y:=0;
L_Segment[i].P2.X:=0; L_Segment[i].P2.Y:=0;
end;
end;
// Fait les lignes enti<74>res
repeat;
bc:=false;
for i:=0 to Nb_Segment - 2 do for j:=i+1 to Nb_Segment - 1 do begin
// non verticaux
if (L_Segment[i].P2.X-L_Segment[i].P1.X <> 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<69>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<69>e ou superpos<6F>
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<L_Segment[i].P2.X then begin x2:=L_Segment[i].P2.X;y2:=L_Segment[i].P2.Y; end;
if x2<L_Segment[j].P1.X then begin x2:=L_Segment[j].P1.X;y2:=L_Segment[j].P1.Y; end;
if x2<L_Segment[j].P2.X then begin x2:=L_Segment[j].P2.X;y2:=L_Segment[j].P2.Y; end;
L_Segment[i].P1.X:=x1; L_Segment[i].P1.Y:=y1;
L_Segment[i].P2.X:=x2; L_Segment[i].P2.Y:=y2;
L_Segment[j].P1.X:=0; L_Segment[j].P1.Y:=0; // mis <20> z<>ro sera supprimm<6D> plus tard
L_Segment[j].P2.X:=0; L_Segment[j].P2.Y:=0;
end;
end;
end;
end;
// verticaux
if (L_Segment[i].P2.X-L_Segment[i].P1.X = 0) and (L_Segment[j].P2.X-L_Segment[j].P1.X = 0) and (L_Segment[i].P2.Y-L_Segment[i].P1.Y <> 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<L_Segment[i].P2.Y then begin y2:=L_Segment[i].P2.Y;x2:=L_Segment[i].P2.X; end;
if y2<L_Segment[j].P1.Y then begin y2:=L_Segment[j].P1.Y;x2:=L_Segment[j].P1.X; end;
if y2<L_Segment[j].P2.Y then begin y2:=L_Segment[j].P2.Y;x2:=L_Segment[j].P2.X; end;
L_Segment[i].P1.X:=x1; L_Segment[i].P1.Y:=y1;
L_Segment[i].P2.X:=x2; L_Segment[i].P2.Y:=y2;
L_Segment[j].P1.X:=0; L_Segment[j].P1.Y:=0;
L_Segment[j].P2.X:=0; L_Segment[j].P2.Y:=0;
end; // if b
end; // if cbi=cbj
end; // if cdi=cdj
end; // if
end; // for i,j
// place les 0 <20> la fin
for i:=0 to Nb_Segment - 2 do for j:=i+1 to Nb_Segment - 1 do begin
if (L_Segment[i].P1.X=0) and (L_Segment[i].P1.Y=0) and (L_Segment[i].P2.X=0) and (L_Segment[i].P2.Y=0) then begin
Seg:=L_Segment[i];
L_Segment[i]:=L_Segment[j];
L_Segment[j]:=Seg;
end; //if
end; // for i,j
cc:=0; // compte les 0 et les supprime
for i:=0 to Nb_Segment - 1 do if (L_Segment[i].P1.X=0) and (L_Segment[i].P1.Y=0) and (L_Segment[i].P2.X=0) and (L_Segment[i].P2.Y=0) then inc(cc);
Nb_Segment:=Nb_Segment-cc;
Setlength(L_Segment,Nb_Segment);
until not bc; // tant qu'on fusionne on rev<65>rifie
//Scinde les segments sur les connexions
repeat;
bc:=false;
// non verticaux
for i:=0 to Nb_Segment - 1 do for j:=0 to Nb_Connect - 1 do begin
if (L_Segment[i].P2.X-L_Segment[i].P1.X <> 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<65>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'<27>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.

1060
code_JMW/Uexec.pas Normal file

File diff suppressed because it is too large Load Diff

39
code_JMW/Ufonctions.pas Normal file
View File

@@ -0,0 +1,39 @@
unit Ufonctions;
//uses
interface
//function distance (ax,ay,bx,by,cx,cy : integer):real;
function distance (ax,ay,bx,by : double):double;
function entre(v,l1,l2:double):boolean;
function dist_proj_ortho(ax,ay,bx,by,mx,my : double):double;
implementation
function distance (ax,ay,bx,by : double):double;
begin
// result:=sqrt((cx-ax)*(cx-ax)+(cy-ay)*(cy-ay))+sqrt((cx-bx)*(cx-bx)+(cy-by)*(cy-by))-sqrt((bx-ax)*(bx-ax) + (by-ay)*(by-ay));
result:=sqrt(sqr(bx-ax) + sqr(by-ay));
end;
function entre(v,l1,l2:double):boolean;
begin
result:=(l1<=v)and(v<=l2) or (l2<=v)and(v<=l1);
end;
function dist_proj_ortho(ax,ay,bx,by,mx,my : double):double;
begin
if ax=bx then result:=abs(mx-ax);
if ay=by then result:=abs(my-ay);
if (ax<>bx) and (ay<>by) then
result:=abs(((by-ay)/(bx-ax))*(mx-ax)+ay-my)/sqrt(1+sqr((by-ay)/(bx-ax)));
end;
end.

1612
code_JMW/Unit1.dfm Normal file

File diff suppressed because it is too large Load Diff

777
code_JMW/Unit1.pas Normal file
View File

@@ -0,0 +1,777 @@
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls, StdCtrls, Buttons,
UInit, UDessin, Uedit, UES, UDessinComposant, UPage, Spin, UExec, UTest,
ExtDlgs;
type
TForm1 = class(TForm)
Pnl_Haut: TPanel;
MainMenu: TMainMenu;
Fichier1: TMenuItem;
Memo1: TMemo;
Nouveau: TMenuItem;
M_Ouvrir: TMenuItem;
M_Enregistrer_sous: TMenuItem;
Pnl_Composants: TPanel;
Im_al1: TImage;
Im_al2: TImage;
Im_al3: TImage;
Im_cx: TImage;
Im_rl4: TImage;
Im_rl1: TImage;
Im_rl10: TImage;
Im_rl7: TImage;
Im_rl8: TImage;
Im_rl5: TImage;
Editer: TMenuItem;
M_Affichage: TMenuItem;
LoupeAg: TMenuItem;
LoupeRed: TMenuItem;
Grille: TMenuItem;
Taille_normale: TMenuItem;
Im_rl3: TImage;
Im_rl2: TImage;
Im_rl6: TImage;
Im_rl9: TImage;
Im_rl11: TImage;
Im_ct1: TImage;
Zoom_Max: TMenuItem;
Label1: TLabel;
Im_ct2: TImage;
Im_ct4: TImage;
Im_ct3: TImage;
Im_ct6: TImage;
Im_ct5: TImage;
OpenDialog1: TOpenDialog;
SaveDialog: TSaveDialog;
Im_ct7: TImage;
Im_ct8: TImage;
Im_ct9: TImage;
Zoom_min: TMenuItem;
M_Decalage: TMenuItem;
Vers_haut: TMenuItem;
Vers_bas: TMenuItem;
Vers_gauche: TMenuItem;
Vers_droite: TMenuItem;
Pnl_Image: TPanel;
Image: TImage;
SB_Hor: TScrollBar;
SB_Ver: TScrollBar;
Im_cp1: TImage;
Im_ct10: TImage;
Button1: TButton;
Executer: TMenuItem;
Pnl_Editer: TPanel;
BBtn_Supprime: TBitBtn;
SBtn_Selection: TSpeedButton;
SBtn_Deplace: TSpeedButton;
SBtn_Compo: TSpeedButton;
SBtn_Relier: TSpeedButton;
BBtn_Gauche: TBitBtn;
BBtn_Haut: TBitBtn;
BBtn_Bas: TBitBtn;
BBtn_Droite: TBitBtn;
SBtn_Label: TSpeedButton;
Pnl_Contact: TPanel;
CB_C_Manuel: TCheckBox;
CB_C_EtatI: TCheckBox;
Label2: TLabel;
Btn_C_ok: TButton;
Im_ct11: TImage;
Im_ct12: TImage;
Im_ct13: TImage;
Im_ct14: TImage;
Label7: TLabel;
CO_C_Nom: TComboBox;
CB_C_Visible: TCheckBox;
Label8: TLabel;
SP_C_dx: TSpinEdit;
Label9: TLabel;
SP_C_dy: TSpinEdit;
Timer1: TTimer;
Noir1: TMenuItem;
Potentiels1: TMenuItem;
Courants1: TMenuItem;
Im_ct15: TImage;
N2: TMenuItem;
VisuelRelais: TMenuItem;
Im_rl12: TImage;
Im_la1: TImage;
Im_la2: TImage;
Pnl_Lampe: TPanel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
ED_L_Nom: TEdit;
Btn_L_Ok: TButton;
SP_L_dx: TSpinEdit;
SP_L_dy: TSpinEdit;
CB_L_Visible: TCheckBox;
Pnl_Relais: TPanel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label10: TLabel;
ED_R_Nom: TEdit;
CB_R_EtatI: TCheckBox;
Btn_R_Ok: TButton;
SP_R_dx: TSpinEdit;
SP_R_dy: TSpinEdit;
CB_R_Visible: TCheckBox;
ED_R_Tempo: TEdit;
PNL_L0: TPanel;
PNL_L1: TPanel;
Label15: TLabel;
Label16: TLabel;
ColorDialog1: TColorDialog;
TmrPulse: TTimer;
SavePictureDialog1: TSavePictureDialog;
EnregistrerImage1: TMenuItem;
Visuelinteractif: TMenuItem;
Im_ct16: TImage;
Im_ct17: TImage;
Zoomajuster1: TMenuItem;
Memo2: TMemo;
Panel1: TPanel;
Button2: TButton;
Button4: TButton;
Button5: TButton;
Button3: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
procedure FormActivate(Sender: TObject);
procedure EditerClick(Sender: TObject);
procedure ImageDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
procedure ImageDragDrop(Sender, Source: TObject; X, Y: Integer);
procedure LoupeAgClick(Sender: TObject);
procedure LoupeRedClick(Sender: TObject);
procedure Taille_normaleClick(Sender: TObject);
procedure GrilleClick(Sender: TObject);
procedure Zoom_MaxClick(Sender: TObject);
procedure ImageMouseMove(Sender: TObject; Shift: TShiftState; X,Y: Integer);
procedure M_Enregistrer_sousClick(Sender: TObject);
procedure M_OuvrirClick(Sender: TObject);
procedure ImageMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure ImageMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure NouveauClick(Sender: TObject);
procedure Zoom_minClick(Sender: TObject);
procedure Vers_hautClick(Sender: TObject);
procedure Vers_gaucheClick(Sender: TObject);
procedure Vers_basClick(Sender: TObject);
procedure Vers_droiteClick(Sender: TObject);
procedure SB_HorChange(Sender: TObject);
procedure SB_VerChange(Sender: TObject);
procedure BBtn_SupprimeClick(Sender: TObject);
procedure ImageContextPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean);
procedure Button1Click(Sender: TObject);
procedure ExecuterClick(Sender: TObject);
procedure SBtn_CompoClick(Sender: TObject);
procedure SBtn_SelectionClick(Sender: TObject);
procedure SBtn_DeplaceClick(Sender: TObject);
procedure SBtn_RelierClick(Sender: TObject);
procedure SBtn_LabelClick(Sender: TObject);
procedure BBtn_BasClick(Sender: TObject);
procedure BBtn_HautClick(Sender: TObject);
procedure BBtn_GaucheClick(Sender: TObject);
procedure BBtn_DroiteClick(Sender: TObject);
procedure Btn_C_okClick(Sender: TObject);
procedure Btn_R_OkClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Memo1DblClick(Sender: TObject);
procedure Fichier1Click(Sender: TObject);
procedure Noir1Click(Sender: TObject);
procedure Potentiels1Click(Sender: TObject);
procedure Courants1Click(Sender: TObject);
procedure VisuelRelaisClick(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure ED_R_TempoKeyPress(Sender: TObject; var Key: Char);
procedure Btn_L_OkClick(Sender: TObject);
procedure PNLCLRClick(Sender: TObject);
procedure TmrPulseTimer(Sender: TObject);
procedure EnregistrerImage1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure VisuelinteractifClick(Sender: TObject);
procedure Zoomajuster1Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
private
{ D<>clarations priv<69>es }
public
{ D<>clarations publiques }
end;
var
Form1: TForm1;
const rmax=999;
implementation
{$R *.dfm}
// * Initialisation *
procedure TForm1.FormActivate(Sender: TObject);
begin
Initialisation;
end;
// * Zoom *
procedure TForm1.LoupeAgClick(Sender: TObject);
begin
If Zoom>0.5 then Zoom:=Zoom/1.15;
Affichage;
end;
procedure TForm1.LoupeRedClick(Sender: TObject);
begin
If Zoom<1.75 then Zoom:=Zoom*1.15;
Affichage;
end;
procedure TForm1.Taille_normaleClick(Sender: TObject);
begin
Zoom:=1;
Affichage;
end;
procedure TForm1.Zoom_minClick(Sender: TObject);
begin
Zoom:=2.1;
Affichage;
end;
procedure TForm1.Zoom_MaxClick(Sender: TObject);
begin
Zoom:=0.43;
Affichage;
end;
// * Grille *
procedure TForm1.GrilleClick(Sender: TObject);
begin
Grille.Checked:=not(Grille.Checked);
Affichage;
end;
// * D<>calage Image *
procedure TForm1.Vers_hautClick(Sender: TObject);
begin
Decalage(0,1);
end;
procedure TForm1.Vers_gaucheClick(Sender: TObject);
begin
Decalage(1,0);
end;
procedure TForm1.Vers_basClick(Sender: TObject);
begin
Decalage(0,-1);
end;
procedure TForm1.Vers_droiteClick(Sender: TObject);
begin
Decalage(-1,0);
end;
procedure TForm1.SB_HorChange(Sender: TObject);
begin
Affichage;
end;
procedure TForm1.SB_VerChange(Sender: TObject);
begin
Affichage;
end;
// * Menu Fichier *
procedure TForm1.M_Enregistrer_sousClick(Sender: TObject);
begin
Enregistrer;
end;
procedure TForm1.M_OuvrirClick(Sender: TObject);
begin
Ouvrir;
Affichage;
ListeNom;
end;
procedure TForm1.NouveauClick(Sender: TObject);
begin
Initialisation;
end;
// * Menu Editer *
procedure TForm1.EditerClick(Sender: TObject);
begin
bEdit:=true;
bExec:=false;
Panneaux;
end;
procedure TForm1.ImageDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
begin
Accept:=Sender is TImage;
end;
procedure TForm1.ImageDragDrop(Sender, Source: TObject; X, Y: Integer);
begin
// memo1.Lines.Add('ok '+(Source as TImage).Name);
AjouteComposant((Source as TImage).Name,X,Y);
end;
procedure TForm1.ImageMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
bRelier:=SBtn_Relier.Down and bEdit;
bSelectionner:= SBtn_Selection.Down and bEdit;
dx:=cordo(x)+Form1.SB_Hor.Position*sbx;
dy:=cordo(y)+Form1.SB_Ver.Position*sby;
fx:=cordo(x)+Form1.SB_Hor.Position*sbx;
fy:=cordo(y)+Form1.SB_Ver.Position*sby;
if bRelier then bLier:=true; // not (ssShift in Shift) and
if bSelectionner then bSelection:=true;
if bExec then SourisBas;
// if (ssShift in Shift) then RechercheComposant;
// if (ssCtrl in Shift) and (CompoEnCours<>'') then Deplacer:=true;
// ssShift, ssAlt, ssCtrl,
// ssLeft, ssRight, ssMiddle, ssDouble
// memo1.Lines.Add('MouseDown');
// if (ssShift in Shift) then memo1.Lines.Add('ssShift');
// if (ssAlt in Shift) then memo1.Lines.Add('ssAlt');
// if (ssCtrl in Shift) then memo1.Lines.Add('ssCtrl');
end;
procedure TForm1.ImageMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
if bLier or bSelection then begin
fx:=cordo(x)+Form1.SB_Hor.Position*sbx;
fy:=cordo(y)+Form1.SB_Ver.Position*sby;
Affichage;
end;
end;
procedure TForm1.ImageMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
fx:=cordo(x)+Form1.SB_Hor.Position*sbx;
fy:=cordo(y)+Form1.SB_Ver.Position*sby;
if bLier and ((fx<>dx) or (fy<>dy)) then AjouteSegment;
if bSelection then SelectionComposants;
if bExec then SourisHaut;
bLier:=false;
bSelection:=false;
if not bExec then Affichage;
end;
procedure TForm1.BBtn_SupprimeClick(Sender: TObject);
begin
SupprimeComposant;
end;
procedure TForm1.ImageContextPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean);
begin
if bEdit then PanneauEdition(MousePos.X,MousePos.Y);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Resegmentation;
end;
procedure TForm1.ExecuterClick(Sender: TObject);
begin
bEdit:=false;
bExec:=true;
Panneaux;
RAZSelection;
Resegmentation;
InitExec;
Affichage;
end;
procedure TForm1.SBtn_CompoClick(Sender: TObject);
begin
Panneaux;
end;
procedure TForm1.SBtn_SelectionClick(Sender: TObject);
begin
Panneaux;
end;
procedure TForm1.SBtn_DeplaceClick(Sender: TObject);
begin
Panneaux;
end;
procedure TForm1.SBtn_RelierClick(Sender: TObject);
begin
Panneaux;
end;
procedure TForm1.SBtn_LabelClick(Sender: TObject);
begin
Panneaux;
end;
procedure TForm1.BBtn_BasClick(Sender: TObject);
begin
DeplaceSelection(0,-1);
end;
procedure TForm1.BBtn_HautClick(Sender: TObject);
begin
DeplaceSelection(0,1);
end;
procedure TForm1.BBtn_GaucheClick(Sender: TObject);
begin
DeplaceSelection(1,0);
end;
procedure TForm1.BBtn_DroiteClick(Sender: TObject);
begin
DeplaceSelection(-1,0);
end;
procedure TForm1.Btn_C_okClick(Sender: TObject);
var i:integer;
begin
for i:=0 to Nb_Contact-1 do if L_Contact[i].Select then begin
L_Contact[i].EtatI:=CB_C_EtatI.Checked;
L_Contact[i].Manuel:=CB_C_Manuel.Checked;
L_Contact[i].nom:=CO_C_Nom.Text;
L_Contact[i].visible:=CB_C_visible.Checked;
L_Contact[i].Pd.X:=SP_C_dx.Value;
L_Contact[i].Pd.Y:=SP_C_dy.Value;
end;
RAZPanneauEdition;
ListeNom;
Affichage;
end;
procedure TForm1.Btn_R_OkClick(Sender: TObject);
var i:integer;
begin
for i:=0 to Nb_Relais-1 do if L_Relais[i].Select then begin
/// L_Relais[i].EtatI:=CB_R_EtatI.Checked;
L_Relais[i].Visible:=CB_R_Visible.Checked;
L_Relais[i].nom:=Ed_R_Nom.Text;
L_Relais[i].Pd.X:=SP_R_dx.Value;
L_Relais[i].Pd.Y:=SP_R_dy.Value;
L_Relais[i].tpr:=StrToInt('0'+Ed_R_Tempo.Text);
end;
RAZPanneauEdition;
ListeNom;
Affichage;
end;
procedure TForm1.Button2Click(Sender: TObject);
var F:TextFile;
S:string;
i,j:integer;
begin
AssignFile(F,'List.csv');
Rewrite(F);
Writeln(F,'Segments,');
Writeln(F,'n<>,P1,P2,C<>t<EFBFBD>1,C<>t<EFBFBD>2,Branche');
for i:=0 to Nb_Segment-1 do begin
s:=IntToStr(i)+',';
s:=s+'('+IntToStr(L_Segment[i].P1.X)+';'+IntToStr(L_Segment[i].P1.Y)+'),';
s:=s+'('+IntToStr(L_Segment[i].P2.X)+';'+IntToStr(L_Segment[i].P2.Y)+'),';
S:=s+L_Segment[i].Cote1+','+L_Segment[i].Cote2+',';
s:=s+IntToStr(L_Segment[i].AppaBranche)+',';
Writeln(F,s);
end;
Writeln(F,',');
Writeln(F,'Branches,');
Writeln(F,'n<>,C<>t<EFBFBD>1,C<>t<EFBFBD>2,Pot,S1,S2,S3,S4,S5,S6,S7,S8');
for i:=0 to length(L_Branche)-1 do begin
s:=IntToStr(i)+',';
s:=s+L_Branche[i].Cote1+','+L_Branche[i].Cote2+',';
s:=s+IntToStr(L_Branche[i].AppaPotentiel)+',';
for j:=0 to length(L_Branche[i].CompSegments)-1 do s:=s+IntToStr(L_Branche[i].CompSegments[j])+',';
Writeln(F,s);
end;
Writeln(F,',');
Writeln(F,'Potentiels,');
Writeln(F,'n<>,B1,B2,B3,B4,B5,B6,B7,B8');
for i:=0 to length(L_Potentiel)-1 do begin
s:=IntToStr(i)+',';
for j:=0 to length(L_Potentiel[i].CompBranches)-1 do s:=s+IntToStr(L_Potentiel[i].CompBranches[j])+',';
Writeln(F,s);
end;
CloseFile(F);
end;
procedure TForm1.Button3Click(Sender: TObject);
var i,j:integer;
s:string;
begin
test('Segments');
for i:=0 to Nb_Segment-1 do begin
s:=IntToStr(i)+',';
s:=s+'('+IntToStr(L_Segment[i].P1.X)+';'+IntToStr(L_Segment[i].P1.Y)+'),';
s:=s+'('+IntToStr(L_Segment[i].P2.X)+';'+IntToStr(L_Segment[i].P2.Y)+'),';
S:=s+L_Segment[i].Cote1+','+L_Segment[i].Cote2+',';
s:=s+IntToStr(L_Segment[i].AppaBranche)+',';
test(s);
end;
test2('Branches');
for i:=0 to length(L_Branche)-1 do begin
s:=IntToStr(i)+',';
s:=s+L_Branche[i].Cote1+','+L_Branche[i].Cote2+',';
s:=s+IntToStr(L_Branche[i].AppaPotentiel)+',';
S:=S+'C'+IntToStr(L_Branche[i].Courant);
for j:=0 to length(L_Branche[i].CompSegments)-1 do s:=s+IntToStr(L_Branche[i].CompSegments[j])+',';
test2(s);
end;
test('');
test('Potentiels');
for i:=0 to length(L_Potentiel)-1 do begin
s:=IntToStr(i)+',';
S:=S+IntToStr(L_Potentiel[i].Rp)+','+IntToStr(L_Potentiel[i].Rm)+',';
for j:=0 to length(L_Potentiel[i].CompBranches)-1 do s:=s+IntToStr(L_Potentiel[i].CompBranches[j])+',';
test(s);
end;
test('Fonctions');
for i:=0 to length(L_Fonction)-1 do begin
s:=IntToStr(i)+',';
s:=s+L_Fonction[i].comp+',';
s:=s+L_Fonction[i].nom+',';
s:=s+IntToStr(L_Fonction[i].x)+',';
test(s);
end;
test('Relais');
for i:=0 to length(L_Relais)-1 do begin
s:=IntToStr(i)+',';
s:=s+L_Relais[i].nom+',';
// s:=s+IntToStr(L_Relais[i].Fonction)+',';
S:=S+' 0:'+IntToStr(L_Relais[i].AppPot[0])+' 1:'+IntToStr(L_Relais[i].AppPot[1])+',';
test(s);
end;
test('Lampe');
for i:=0 to length(L_Lampe)-1 do begin
s:=IntToStr(i)+',';
s:=s+L_Lampe[i].nom+',';
// s:=s+IntToStr(L_Lampe[i].Fonction)+',';
//S:=S+' 0:'+IntToStr(L_Lampe[i].AppPot[0])+' 1:'+IntToStr(L_Lampe[i].AppPot[1])+',';
test(s);
end;
test('Contact');
for i:=0 to length(L_Contact)-1 do begin
s:=IntToStr(i)+',';
s:=s+L_Contact[i].nom+',';
s:=s+IntToStr(L_Contact[i].Fonction)+',';
test(s);
end;
end;
procedure TForm1.Memo1DblClick(Sender: TObject);
begin
memo1.Clear;
end;
procedure TForm1.Fichier1Click(Sender: TObject);
begin
bExec:=false;
end;
procedure TForm1.Noir1Click(Sender: TObject);
begin
ExecCouleur(1);
end;
procedure TForm1.Potentiels1Click(Sender: TObject);
begin
ExecCouleur(2);
end;
procedure TForm1.Courants1Click(Sender: TObject);
begin
ExecCouleur(3);
end;
procedure TForm1.VisuelRelaisClick(Sender: TObject);
begin
ExecVisuel;
end;
procedure TForm1.Button4Click(Sender: TObject);
var i:integer;
s:string;
begin
test('');
test('Potentiels');
for i:=0 to length(L_Potentiel)-1 do begin
s:=IntToStr(i)+',';
S:=S+IntToStr(L_Potentiel[i].Rp)+','+IntToStr(L_Potentiel[i].Rm);
// for j:=0 to length(L_Potentiel[i].CompBranches)-1 do s:=s+IntToStr(L_Potentiel[i].CompBranches[j])+',';
test(s);
end;
test('Relais');
for i:=0 to length(L_Relais)-1 do begin
s:=IntToStr(i)+',';
s:=s+L_Relais[i].nom+',';
// s:=s+IntToStr(L_Relais[i].Fonction)+',';
// S:=S+' 0:'+IntToStr(L_Relais[i].AppPot[0])+' 1:'+IntToStr(L_Relais[i].AppPot[1])+',';
// S:=S+' '+IntToStr(L_Relais[i].AppPot[0])+' 1:'+IntToStr(L_Relais[i].AppPot[1])+',';
S:=S+' '+ IntToStr(L_Potentiel[L_Relais[i].AppPot[0]].Rp)+','+IntToStr(L_Potentiel[L_Relais[i].AppPot[0]].Rm)+' ; '+IntToStr(L_Potentiel[L_Relais[i].AppPot[1]].Rp)+','+IntToStr(L_Potentiel[L_Relais[i].AppPot[1]].Rm);
test(s);
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Temporisations;
end;
procedure TForm1.ED_R_TempoKeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in [#8, '0'..'9']) then Key := #0;
end;
procedure TForm1.Btn_L_OkClick(Sender: TObject);
var i:integer;
begin
for i:=0 to Nb_Lampe-1 do if L_Lampe[i].Select then begin
L_lampe[i].Visible:=CB_L_Visible.Checked;
L_lampe[i].nom:=Ed_L_Nom.Text;
L_lampe[i].Pd.X:=SP_L_dx.Value;
L_lampe[i].Pd.Y:=SP_L_dy.Value;
L_Lampe[i].Clr0:=PNL_L0.Color;
L_Lampe[i].Clr1:=PNL_L1.Color;
end;
RAZPanneauEdition;
ListeNom;
Affichage;
end;
procedure TForm1.PNLCLRClick(Sender: TObject);
begin
if ColorDialog1.Execute then begin
if (Sender is TPanel) then (Sender as TPanel).Color:=ColorDialog1.Color;
end;
end;
procedure TForm1.TmrPulseTimer(Sender: TObject);
begin
pulse:=not pulse;
if bExec then CycleExec;
end;
procedure TForm1.EnregistrerImage1Click(Sender: TObject);
begin
if SavePictureDialog1.Execute then Image.Picture.SaveToFile(SavePictureDialog1.FileName);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
// DoubleBuffered := true;
end;
procedure TForm1.Button5Click(Sender: TObject);
var i:integer;
begin
for i:=0 to Nb_Fonction-1 do begin
test2(L_Fonction[i].nom+' '+IntToStr(L_Fonction[i].x));
end;
end;
procedure TForm1.VisuelinteractifClick(Sender: TObject);
begin
ExecInteractif;
end;
procedure TForm1.Zoomajuster1Click(Sender: TObject);
begin
// Zoom:=0.43;
Affichage;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
memo2.Visible:=false;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
memo2.Visible:=true;
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
memo2.Clear;
end;
procedure TForm1.Button9Click(Sender: TObject);
var i:integer;
s:string;
begin
memo2.Lines.Add('SEGMENTS');
s:=' # | xa, ya| xb, yb|c<>t<EFBFBD>1 |c<>t<EFBFBD>2 |Bra|S1|S2';
memo2.Lines.Add(s);
for i:=0 to Nb_Segment-1 do begin
s:=format('%3d|%3d,%3d|%3d,%3d|%-6s|%-6s|%3d|%-.2s|%-.2s',
[i,L_Segment[i].P1.X,L_Segment[i].P1.Y,L_Segment[i].P2.X,L_Segment[i].P2.Y,L_Segment[i].Cote1,L_Segment[i].Cote2,L_Segment[i].AppaBranche,VartoStr(L_Segment[i].Select1),VartoStr(L_Segment[i].Select1)]);
memo2.Lines.Add(s);
end;
memo2.Lines.Add('BRANCHES');
s:=' # |c<>t<EFBFBD>1 |c<>t<EFBFBD>2 |Cou|Par';
memo2.Lines.Add(s);
for i:=0 to length(L_Branche)-1 do begin
s:=format('%3d|%-6s|%-6s|%3d|%3d',
[i,L_Branche[i].Cote1,L_Branche[i].Cote2,L_Branche[i].Courant,L_Branche[i].Parcouru]);
memo2.Lines.Add(s);
end;
{
T_Branche = record
AppaPotentiel : integer;
EtatP, EtatF : boolean;
CompSegments :array of integer;
Cote1,Cote2 : string;
Courant:integer;
Parcouru :integer;
end;
}
end;
end.

35
code_JMW/UnitRelais.dfm Normal file
View File

@@ -0,0 +1,35 @@
object F_Relais: TF_Relais
Left = 492
Top = 246
Width = 274
Height = 346
Caption = 'F_Relais'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnClose = FormClose
PixelsPerInch = 120
TextHeight = 16
object Label1: TLabel
Left = 8
Top = 8
Width = 45
Height = 16
Caption = 'Relais :'
end
object LabeledEdit1: TLabeledEdit
Left = 49
Top = 27
Width = 114
Height = 24
EditLabel.Width = 38
EditLabel.Height = 16
EditLabel.Caption = 'Nom : '
LabelPosition = lpLeft
TabOrder = 0
end
end

32
code_JMW/UnitRelais.pas Normal file
View File

@@ -0,0 +1,32 @@
unit UnitRelais;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, UInit,Unit1;
type
TF_Relais = class(TForm)
Label1: TLabel;
LabeledEdit1: TLabeledEdit;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ D<>clarations priv<69>es }
public
{ D<>clarations publiques }
end;
var
F_Relais: TF_Relais;
implementation
{$R *.dfm}
procedure TF_Relais.FormClose(Sender: TObject; var Action: TCloseAction);
begin
L_Relais[NumeroEnCours].nom:=LabeledEdit1.Text;
end;
end.

83
code_JMW/Upage.pas Normal file
View File

@@ -0,0 +1,83 @@
unit Upage;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls,
UInit, UEdit;
procedure Panneaux;
procedure ExecCouleur(i:integer);
function ClPotentiel(sp,sm:string):TColor;
function ClrPotentiel(ip,im:integer):TColor;
procedure ExecVisuel;
procedure ExecInteractif;
implementation
uses unit1,utest;
procedure Panneaux;
begin
With Form1 do begin
Pnl_Composants.Visible:= false;
Pnl_Editer.Visible:=bEdit;
Pnl_Composants.Visible:=bEdit and SBtn_Compo.Down;
if (SBtn_Compo.Down or SBtn_Relier.Down) then RAZSelection;
if not bEdit then RAZPanneauEdition;
end;
end;
procedure ExecInteractif;
begin
With Form1 do begin
Visuelinteractif.Checked:=not Visuelinteractif.Checked;
end; // With
end;
procedure ExecVisuel;
begin
With Form1 do begin
VisuelRelais.Checked:=not VisuelRelais.Checked;
end; // With
end;
procedure ExecCouleur(i:integer);
begin
With Form1 do begin
Noir1.Checked:=(i=1);
Potentiels1.Checked:=(i=2);
Courants1.Checked:=(i=3);
end; // With
end;
function ClPotentiel(sp,sm:string):TColor;
Var cl:TColor;
begin
cl:=RGB(160,0,160);
// test(sp+' '+sm);
if (sp='+0') and (sm<>'-0') then cl:=RGB(255,0,0);
if (sm='-0') and (sp<>'+0') then cl:=RGB(0,0,255);
if (sm<>'N') then cl:=RGB(0,100,255);
if (sp<>'N') then cl:=RGB(255,100,0);
if (sm='N') and (sp='N') then cl:=RGB(100,100,100);
// result:=cl;
end;
function ClrPotentiel(ip,im:integer):TColor;
Var cl:TColor;
begin
cl:=RGB(160,0,160);
if (im=rmax) then cl:=RGB(255,160,160);
if (ip=rmax) then cl:=RGB(160,160,255);
if (ip=0) and (im<>0) then cl:=RGB(255,0,0);
if (im=0) and (ip<>0) then cl:=RGB(0,0,255);
if (im=rmax) and (ip=rmax) then cl:=RGB(100,100,100);
result:=cl;
end;
end.

27
code_JMW/Utest.pas Normal file
View File

@@ -0,0 +1,27 @@
unit Utest;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls,
UDessin, UDessinComposant,UFonctions, UInit,UEdit;
procedure test(v:variant);
procedure test2(v:variant);
implementation
uses Unit1;
procedure test(v:variant);
begin
form1.Memo1.Lines.Add(FormatDateTime('ss,zzz',now)+' '+VarTostr(v));
end;
procedure test2(v:variant);
begin
// form1.Memo1.Lines.Add(FormatDateTime('ss,zzz',now)+' '+VarTostr(v));
end;
end.