Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
5_Звіт.doc
Скачиваний:
3
Добавлен:
27.04.2019
Размер:
3.83 Mб
Скачать

3.5. Текст програмних модулів

3.5.1. Модуль «ByuldSxemaUnit»

//Перевіряє чи є точка на лінії

function TBildSxema.IsPointOnLine(XY1, XY2, XY3 : TPoint): Boolean;

var

D1, D2, D3 : Real;

begin

Result := false;

D1 := sqrt(sqr(XY3.X - XY1.X) + sqr(XY3.Y - XY1.Y));

D2 := sqrt(sqr(XY2.X - XY3.X) + sqr(XY2.Y - XY3.Y));

D3 := sqrt(sqr(XY2.X - XY1.X) + sqr(XY2.Y - XY1.Y));

if abs((D1 + D2)-D3) < 0.1 then

Result := true;

end;

//Вибираємо ближню границю з кроком 10

function TBildSxema.GetNearPos( X1, Y1 : integer): TPoint; //Пошук ближньої точки;

begin

if (X1-(X1 div 10)*10)>5 then

Result.X:=(X1 div 10)*10+10

else

Result.X:=(X1 div 10)*10;

if (Y1-(Y1 div 10)*10)>5 then

Result.Y:=(Y1 div 10)*10+10

else

Result.Y:=(Y1 div 10)*10;

end;

//Задання початкових станів (занулення лічильників)

procedure TBildSxema.FormCreate(Sender: TObject);

begin

Select:=false;

LogMemo.Lines.Clear;

Cxema := TCxema.Create;

Cxema.ChipsCount:=0;

Cxema.LinesCount:=0;

Cxema.CircleCount:=0;

BildSxema.PaintBox1.Canvas.Pen.Color := clNavy;

end;

//Формує комбінації вхідних сигналів для заповнення таблиці істинності

Function kombination(x1:string):string;

Var

l : byte;

pp, code_comb: string;

begin

pp:='1';

For l:=BildSxema.StringGrid1.RowCount downto 1 do

begin

if (copy(x1,l,1)='0') and (pp='0') then

begin

x1[l]:='1';

pp:='0';

code_comb:=x1;

kombination:= code_comb;

exit;

end;

if (copy(x1,l,1)='1') and (pp='0') then

begin

x1[l]:='1';

pp:='0';

code_comb:=x1;

kombination:= code_comb;

exit;

end;

if (copy(x1,l,1)='0') and (pp='1') then

begin

x1[l]:='1';

pp:='0';

code_comb:=x1;

kombination:= code_comb;

exit;

end;

if (copy(x1,l,1)='1') and (pp='1') then

begin

x1[l]:='0';

pp:='1';

code_comb:=x1;

kombination:= code_comb;

end;

end;

code_comb:=x1;

kombination:=code_comb;

end;

//Обробка події миші при MouseDown

procedure TBildSxema.PaintBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

var

xs: TPoint;

begin

IsExist := False;

xs := GetNearPos(x,y);

xx := xs.X;

yy := xs.Y;

IsExistMove := False;

if BildSxema.SpeedButton4.Down then //Рисуємо лінію;

begin

LinePaint := true;

Inc(Cxema.LinesCount);

SetLength(Cxema.Lines, Cxema.LinesCount);

Cxema.Lines[Cxema.LinesCount - 1] := TLineLink.Create(Cxema.LinesCount);

Cxema.Lines[Cxema.LinesCount - 1].NumOfPoints := 0;

Cxema.AddLinePoint(Cxema.LinesCount - 1, Point(xx, yy)); //перша точка лінії

Cxema.Lines[Cxema.LinesCount - 1].LineID := Cxema.LinesCount - 1;

end;

BildSxema.IsExists(xx, yy); //провірка на існування елемента в заданих координатах

BildSxema.IsExistsMove(xx, yy); //провірка на існування елемента в заданих координатах при русі

if BildSxema.SpBut1.Down or BildSxema.SpBut2.Down or

BildSxema.SpBut3.Down or BildSxema.SpBut4.Down or

BildSxema.SpBut5.Down or BildSxema.SpBut6.Down or

BildSxema.SpBut7.Down or BildSxema.SpBut8.Down or

BildSxema.SpBut9.Down then

begin

if (not IsExist) and (not IsExistMove) then Cxema.AddElem(xx, yy); // додаємо новый элемент;

end else

if BildSxema.SpeedButton8.Down then

begin

if (not IsExist) and (not IsExistMove) then CreateBadEl(xx,yy);

one_Element;

end;

BildSxema.IsExists(xx, yy);

if IsExist=true then

if CheckBox1.Checked then Cxema.ElementXY.State:=false;// else

// Cxema.ElementXY.State:=true;

One_Element;

PaintBox1.Repaint;

end;

//Перемалювання всієї схеми (лог. елементів, ліній, зв’язків)

procedure TBildSxema.PaintBox1Paint(Sender: TObject);

var

i : Integer;

Rect : TRect;

ChipType : TChip;

begin

with Cxema do

begin

for i := 0 to ChipsCount - 1 do //Перерисовка ВСІХ елементів

begin

if Elements[i].fChipType=tc1 then

begin

if elements[i].State=true then Glob_Stat:=true else Glob_Stat:=false;

Elements[i].Draw1( Elements[i].Kx, Elements[i].Ky,

Elements[I].LeftLegs[0].Value,

Elements[I].FType,i );

end else

if Elements[i].fChipType=tc2 then

begin

if elements[i].State=true then Glob_Stat:=true else Glob_Stat:=false;

Elements[i].Draw2( Elements[i].Kx, Elements[i].Ky,

Elements[I].LeftLegs[0].Value,

Elements[I].LeftLegs[1].Value,

Elements[I].FType,i );

end else

if Elements[i].fChipType=tc3 then

begin

if elements[i].State=true then Glob_Stat:=true else Glob_Stat:=false;

Elements[i].Draw3( Elements[i].Kx, Elements[i].Ky,

Elements[I].LeftLegs[0].Value,

Elements[I].LeftLegs[1].Value,

Elements[I].LeftLegs[2].Value,

Elements[I].FType,i );

end;

end;

//Elements[i].Draw( Elements[i].Kx, Elements[i].Ky,

// Elements[I].LeftLegs[0].Value,

// Elements[I].LeftLegs[1].Value,

// Elements[I].LeftLegs[3].Value,

// Elements[I].FType );

for i := 0 to LinesCount - 1 do //Перемалювання ВСІХ ліній

Cxema.Lines[i].DrawLine(BildSxema.PaintBox1.Canvas);

end;

end;

//Обробка події миші MouseMove

procedure TBildSxema.PaintBox1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);

var

xs : TPoint;

begin

xs := GetNearPos(x, y);

xx := xs.X;

yy := xs.Y;

BildSxema.IsExists(xx, yy);

if LinePaint then //Малювання лінії (переміщення);

with Cxema do

begin

Cxema.Lines[Cxema.LinesCount - 1].NumOfPoints := 1;

Cxema.AddLinePoint(Cxema.LinesCount - 1, Point(Cxema.Lines[Cxema.LinesCount - 1].XYArr[0].X, y)); //кінцева точка лінії

Cxema.Lines[Cxema.LinesCount - 1].NumOfPoints := 2;

Cxema.AddLinePoint(Cxema.LinesCount - 1, Point(x, y)); // середня точка лінії

BildSxema.PaintBox1.Repaint;

end;

if IsExistMove and BildSxema.SpeedButton2.Down then DrawChip.MicroChip.MoveChip(xx, yy); //Переміщення

if ssLeft in Shift then BildSxema.PaintBox1.Repaint;

Statusbar1.Panels.Items[0].Text:='x='+inttostr(x);

Statusbar1.Panels.Items[1].Text:='y='+inttostr(y);

end;

//Обробка події миші MouseUp

procedure TBildSxema.PaintBox1MouseUp(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

var

xx, yy : Word;

xs, XY1, XY2 : TPoint;

begin

xs := GetNearPos(x,y);

xx := xs.X;

yy := xs.Y;

IsExistMove := False;

if BildSxema.SpeedButton4.Down then //рисование ліній

if Cxema.LinesCount<>0 then

begin

Cxema.Lines[Cxema.LinesCount - 1].NumOfPoints := 1;

Cxema.AddLinePoint(Cxema.LinesCount - 1, Point(Cxema.Lines[Cxema.LinesCount - 1].XYArr[0].X, yy));

Cxema.Lines[Cxema.LinesCount - 1].NumOfPoints := 2;

Cxema.AddLinePoint(Cxema.LinesCount - 1, Point(xx, yy));

LinePaint := false;

XY1.X := Cxema.Lines[Cxema.LinesCount - 1].XYArr[0].X;

XY1.Y := Cxema.Lines[Cxema.LinesCount - 1].XYArr[0].Y;

XY2.X := Cxema.Lines[Cxema.LinesCount - 1].XYArr[2].X;

XY2.Y := Cxema.Lines[Cxema.LinesCount - 1].XYArr[2].Y;

IsPointOnALLLines(XY1);

IsPointOnALLLines(XY2);

BildSxema.PaintBox1.Repaint;

end;

end;

//Чи є елемент з даними координатами (при русі)

procedure TBildSxema.IsExistsMove(xx, yy : Integer);

var

i : Integer;

begin

for i := 0 to Cxema.ChipsCount - 1 do

if (xx >= Cxema.Elements[i].Kx) and (xx <= Cxema.Elements[i].Kx + 70) then // Проверка вправо

if (yy >= Cxema.Elements[i].Ky) and (yy <= Cxema.Elements[i].Ky + 40) then // проверка вниз

begin

IsExistMove := true;

Cxema.ElementXY := Cxema.Elements[i];

end;

end;

//Чи є елемент з даними координатами

procedure TBildSxema.IsExists(xx, yy : Integer); //Провірка на існування чіпа з заданими координатами

var

i : Integer;

begin

for i := 0 to Cxema.ChipsCount - 1 do

begin

if (xx + 70 >= Cxema.Elements[i].Kx) and (xx + 70 <= Cxema.Elements[i].Kx + 140) then // проверка вправо

if (yy + 40 >= Cxema.Elements[i].Ky) and (yy + 40 <= Cxema.Elements[i].Ky + 80) then // проверка вверх

begin

IsExist := true;

end;

end;

end;

//Чи належить точка лінії іншій лінії

function TBildSxema.IsPointOnAllLines(XY: TPoint): boolean;

var

i, j : word;

XY1, XY2 : TPoint;

begin

Result := false;

//-------- чи належить точка лінії іншій лінії

if Cxema.LinesCount > 1 then

for i := 0 to Cxema.LinesCount - 2 do //по всіх лініях

if Cxema.Lines[i].NumOfPoints <> 1 then

for j := 0 to Cxema.Lines[i].NumOfPoints - 2 do //по лініях в лінії

begin

XY1.X := Cxema.Lines[i].XYArr[j].X;

XY1.Y := Cxema.Lines[i].XYArr[j].Y;

XY2.X := Cxema.Lines[i].XYArr[j + 1].X;

XY2.Y := Cxema.Lines[i].XYArr[j + 1].Y;

if IsPointOnLine(XY1, XY2, XY) then //рисуєм кружок

begin

Inc(Cxema.CircleCount);

SetLength(Cxema.Circle, Cxema.CircleCount);

Cxema.Circle[Cxema.CircleCount - 1].X := XY.X;

Cxema.Circle[Cxema.CircleCount - 1].Y := XY.Y;

Result := True;

end;

end;

//------

if Cxema.ChipsCount <> 0 then //чи належить елементу ліва верхня

for i := 0 to Cxema.ChipsCount - 1 do

begin

if (Cxema.Elements[i].Kx = XY.X) and (Cxema.Elements[i].Ky + 10 = XY.Y) then

begin

Inc(Cxema.CircleCount);

SetLength(Cxema.Circle,Cxema.CircleCount);

Cxema.Circle[Cxema.CircleCount-1].X := XY.X;

Cxema.Circle[Cxema.CircleCount-1].Y := XY.Y;

Result := True;

end;

//чи належить елементу ліва нижня

if (Cxema.Elements[i].Kx = XY.X) and (Cxema.Elements[i].Ky + 30 = XY.Y) then

begin

Inc(Cxema.CircleCount);

SetLength(Cxema.Circle, Cxema.CircleCount);

Cxema.Circle[Cxema.CircleCount-1].X := XY.X;

Cxema.Circle[Cxema.CircleCount-1].Y := XY.Y;

Result := True;

end;

//чи належить елементу права

if (Cxema.Elements[i].Kx + 70 = XY.X) and (Cxema.Elements[i].Ky + 20 = XY.Y) then

begin

Inc(Cxema.CircleCount);

SetLength(Cxema.Circle,Cxema.CircleCount);

Cxema.Circle[Cxema.CircleCount-1].X := XY.X;

Cxema.Circle[Cxema.CircleCount-1].Y := XY.Y;

Result := True;

end;

end;

end;

//Знищення останнього елемента

procedure TBildSxema.SpeedButton5Click(Sender: TObject);

begin

if Cxema.ChipsCount <> 0 then

begin

Dec(Cxema.ChipsCount);

Setlength(Cxema.Elements, Cxema.ChipsCount);

BildSxema.StatusBar1.Panels.Items[2].Text:='Кількість елементів '+IntToStr(Cxema.ChipsCount);

BildSxema.PaintBox1.Repaint;

end;

one_Element;

end;

//Знищення останньої лінії

procedure TBildSxema.SpeedButton6Click(Sender: TObject);

begin

if Cxema.LinesCount <> 0 then

begin

Dec(Cxema.LinesCount);

Setlength(Cxema.Lines, Cxema.LinesCount);

BildSxema.PaintBox1.Repaint;

end;

end;

//Симуляція схеми

procedure TBildSxema.SpeedButton7Click(Sender: TObject);

procedure MakeLinks; // Створення звязків між елементами

var

i : word;

XY : TPoint;

Chip: TMicroChip;

//встановлення значень лівих ніжок

procedure SetLeftLeg(IdChip, NumLeg, NumCLeg : word; LType : TLegStates);

begin

Inc(Chip.fLeftLegs[NumLeg].fConnectCount);

SetLength(Chip.fLeftLegs[NumLeg].fConnect, Chip.fLeftLegs[NumLeg].fConnectCount);

Chip.fLeftLegs[NumLeg].fConnect[Chip.fLeftLegs[NumLeg].fConnectCount - 1].ChipID := IdChip;

Chip.fLeftLegs[NumLeg].fConnect[Chip.fLeftLegs[NumLeg].fConnectCount - 1].LegType:=LType;

Chip.fLeftLegs[NumLeg].fConnect[Chip.fLeftLegs[NumLeg].fConnectCount - 1].NumberOfLeg := NumCLeg;

end;

//Встановлення значень правих ніжок

procedure SetRightLeg(IdChip, NumLeg, NumCLeg : word; LType : TLegStates);

begin

Inc(Chip.fRightLegs[NumLeg].fConnectCount);

SetLength(Chip.fRightLegs[NumLeg].fConnect, Chip.fRightLegs[NumLeg].fConnectCount);

Chip.fRightLegs[NumLeg].fConnect[Chip.fRightLegs[NumLeg].fConnectCount-1].ChipID := IdChip;

Chip.fRightLegs[NumLeg].fConnect[Chip.fRightLegs[NumLeg].fConnectCount-1].LegType := LType;

Chip.fRightLegs[NumLeg].fConnect[Chip.fRightLegs[NumLeg].fConnectCount-1].NumberOfLeg := NumCLeg;

end;

procedure SetAllLegs(LegNum : Word;Ch:Char); // Додавання ніжкам звязків

var

j, k : Word;

Chip1 : TMicroChip;

begin

if Cxema.LinesCount <> 0 then

for j := 0 to Cxema.LinesCount - 1 do

begin

if (Cxema.Lines[j].XYArr[0].X = XY.X) and (Cxema.Lines[j].XYArr[0].Y = XY.Y) then //чи належить дана лінія першій ніжці елемента

begin

for k := 0 to Cxema.ChipsCount - 1 do

begin

Chip1 := Cxema.Elements[k];

if (Cxema.Lines[j].XYArr[2].X = Chip1.Kx) and (Cxema.Lines[j].XYArr[2].Y = Chip1.Ky + 10) then //чи належить кінець лінії другому елементу (іншому)

begin

case Ch of

'L': begin SetLeftLeg(k, LegNum, 0, lsIn); end;

'R': begin SetRightLeg(k, LegNum, 0, lsIn); end;

end;

end;

if (Cxema.Lines[j].XYArr[2].X = Chip1.Kx) and (Cxema.Lines[j].XYArr[2].Y = Chip1.Ky+30) then

begin

case Ch of

'L': begin SetLeftLeg(k, LegNum, 1, lsIn); end;

'R': begin SetRightLeg(k, LegNum, 1, lsIn); end;

end;

end;

if (Cxema.Lines[j].XYArr[2].X = Chip1.Kx) and (Cxema.Lines[j].XYArr[2].Y = Chip1.Ky+50) then

begin

case Ch of

'L':begin SetLeftLeg(k, LegNum, 2, lsIn); end;

'R':begin SetRightLeg(k, LegNum, 2, lsIn); end;

end;

end;

case(chip1.fChipType) of

tc1: if (Cxema.Lines[j].XYArr[2].X = Chip1.Kx + 70) and (Cxema.Lines[j].XYArr[2].Y = Chip1.Ky + 10) then

begin

case Ch of

'L':begin SetLeftLeg(k, LegNum, 0, lsOut); end;

'R': LogMemo.Lines.Add('Помилка контактів!!!');

end;

end;

tc2: if (Cxema.Lines[j].XYArr[2].X = Chip1.Kx + 70) and (Cxema.Lines[j].XYArr[2].Y = Chip1.Ky + 20) then

begin

case Ch of

'L': SetLeftLeg(k, LegNum, 0, lsOut);

'R': LogMemo.Lines.Add('Помилка контактів!!!');

end;

end;

tc3: if (Cxema.Lines[j].XYArr[2].X = Chip1.Kx + 70) and (Cxema.Lines[j].XYArr[2].Y = Chip1.Ky + 30) then

begin

case Ch of

'L': SetLeftLeg(k, LegNum, 0, lsOut);

'R': LogMemo.Lines.Add('Помилка контактів!!!');

end;

end;

end;

end;

end;

end;

end;

begin

if Cxema.ChipsCount <> 0 then

for i := 0 to Cxema.ChipsCount - 1 do

begin

Chip := Cxema.Elements[i];

case chip.fChipType of

tc3:begin

Chip.fLeftLegs[0].fConnect := nil;

Chip.fLeftLegs[1].fConnect := nil;

Chip.fLeftLegs[2].fConnect := nil;

Chip.fRightLegs[0].fConnect := nil;

Chip.fLeftLegs[0].fConnectCount := 0;

Chip.fLeftLegs[1].fConnectCount := 0;

Chip.fLeftLegs[2].fConnectCount := 0;

Chip.fRightLegs[0].fConnectCount := 0;

XY.X := Chip.Kx;

XY.Y := Chip.Ky + 10;

SetAllLegs(0, 'L');

XY.X := Chip.Kx;

XY.Y := Chip.Ky + 30;

SetAllLegs(1, 'L');

XY.X := Chip.Kx;

XY.Y := Chip.Ky + 50;

SetAllLegs(3, 'L');

XY.X:=Chip.Kx + 70;

XY.Y:=Chip.Ky + 30;

SetAllLegs(0, 'R');

end;

tc2:begin

Chip.fLeftLegs[0].fConnect := nil;

Chip.fLeftLegs[1].fConnect := nil;

Chip.fRightLegs[0].fConnect := nil;

Chip.fLeftLegs[0].fConnectCount := 0;

Chip.fLeftLegs[1].fConnectCount := 0;

Chip.fRightLegs[0].fConnectCount := 0;

XY.X := Chip.Kx;

XY.Y := Chip.Ky + 10;

SetAllLegs(0, 'L');

XY.X := Chip.Kx;

XY.Y := Chip.Ky + 30;

SetAllLegs(1, 'L');

XY.X:=Chip.Kx + 70;

XY.Y:=Chip.Ky + 20;

SetAllLegs(0, 'R');

end;

tc1:begin

Chip.fLeftLegs[0].fConnect := nil;

Chip.fRightLegs[0].fConnect := nil;

Chip.fLeftLegs[0].fConnectCount := 0;

Chip.fRightLegs[0].fConnectCount := 0;

XY.X := Chip.Kx;

XY.Y := Chip.Ky + 10;

SetAllLegs(0, 'L');

XY.X:=Chip.Kx + 70;

XY.Y:=Chip.Ky + 10;

SetAllLegs(0, 'R');

end;

end;

end;

end;

function GetChipById(ID : Word) : TMicroChip; // Клас TMicroChip по його номеру

begin

result := nil;

if cxema.ChipsCount = 0 then exit;

result := Cxema.Elements[ID];

end;

procedure SimulateCxeme; //Емуляція схеми

var

p, c, t, CiD : Word;

begin

if Cxema.ChipsCount <> 0 then

for p := 0 to Cxema.ChipsCount - 1 do

begin

for t:=0 to 0 do //Цикл по лывих ногах

if Cxema.Elements[p].fLeftLegs[t].fConnectCount <> 0 then

begin

for C := 0 to Cxema.Elements[p].fLeftLegs[t].fConnectCount - 1 do //Цикл по приэднаних до чіпа елементів

begin

CiD := Cxema.Elements[p].fLeftLegs[t].fConnect[c].ChipID; // CiD Номер приєднаного чіпа

if CiD > p then // Перевірка номера приєднаного елемента

case Cxema.Elements[p].fLeftLegs[t].fConnect[C].LegType of

lsIn : Cxema.Elements[CiD].fLeftLegs[Cxema.Elements[p].fLeftLegs[t].fConnect[C].NumberOfLeg].Value := Cxema.Elements[p].fLeftLegs[t].Value;

lsOut: Cxema.Elements[CiD].fRightLegs[Cxema.Elements[p].fLeftLegs[t].fConnect[C].NumberOfLeg].Value := Cxema.Elements[p].fLeftLegs[t].Value;

end

else

case Cxema.Elements[p].fLeftLegs[t].fConnect[C].LegType of // якщо № приєднаного ел. менше даного

lsIn : Cxema.Elements[p].fLeftLegs[t].Value := Cxema.Elements[CiD].fLeftLegs[Cxema.Elements[p].fLeftLegs[t].fConnect[C].NumberOfLeg].Value;

lsOut: Cxema.Elements[p].fLeftLegs[t].Value := Cxema.Elements[CiD].fRightLegs[Cxema.Elements[p].fLeftLegs[t].fConnect[C].NumberOfLeg].Value;

end;

Cxema.Elements[CiD].SetLegsValue;

Cxema.Elements[p].SetLegsValue;

end;

end;

end;

procedure SimulateCxemeRet; //Емуляція схеми

var

p, c, t, CiD : Word;

i :integer;

begin

Cxema.Elements[CiD].SetLegsValue;

Cxema.Elements[p].SetLegsValue;

end;

end;

end;

begin

if cxema.ChipsCount=0 then begin

Application.MessageBox('Немає схеми для запуску!!!', 'Інформація !',

MB_OK + MB_ICONWARNING); end else

begin

Cxema.SortByXY; // Сортування по координатам з ліва на право

MakeLinks;

ShowLinkInMemo;

SimulateCxeme;

SimulateCxemeRet;

SimulateCxeme;

SimulateCxemeRet;

stringgrid1.RowCount:=count_in_value;

X_10_str2;

Statusbar1.Panels.Items[3].Text:='Кількість входів схеми '+inttostr(count_in_value);

Statusbar1.Panels.Items[4].Text:='Кількість незєднених елементів '+inttostr(count_free_element);

BildSxema.PaintBox1.Repaint;

Select:=true;

end;

end;

//Очистка схеми

procedure TBildSxema.Clear;

begin

if cxema.ChipsCount>0 then begin

if (Application.MessageBox('Ви дійсно бажаєте очистити схему ?',

'Підтведіть свої дії',

MB_YESNO + MB_ICONWARNING)) = IDYES then

begin

Cxema.Elements := nil;

Cxema.ChipsCount := 0;

Cxema.Lines := nil;

Cxema.LinesCount := 0;

Cxema.Circle:=nil;

Cxema.CircleCount:=0;

BildSxema.StatusBar1.Panels.Items[2].Text:='Кількість елементів 0';

BildSxema.PaintBox1.Repaint;

BildSxema.LogMemo.Lines.Clear;

end;

end;

end;

//Збереження схеми

procedure TBildSxema.New1Click(Sender: TObject);

begin

if cxema.ChipsCount>0 then begin

if (Application.MessageBox('Ви бажаєте зберегти схему ?',

'Підтведіть свої дії',

MB_YESNO + MB_ICONWARNING)) = IDYES then

begin

SaveDialog1.Execute;

save_(SaveDialog1.FileName);

Cxema.Elements := nil;

Cxema.ChipsCount := 0;

Cxema.Lines := nil;

Cxema.LinesCount := 0;

Cxema.Circle:=nil;

Cxema.CircleCount:=0;

BildSxema.StatusBar1.Panels.Items[2].Text:='Кількість елементів 0';

BildSxema.PaintBox1.Repaint;

BildSxema.LogMemo.Lines.Clear;

end else

begin

Cxema.Elements := nil;

Cxema.ChipsCount := 0;

Cxema.Lines := nil;

Cxema.LinesCount := 0;

Cxema.Circle:=nil;

Cxema.CircleCount:=0;

BildSxema.StatusBar1.Panels.Items[2].Text:='Кількість елементів 0';

BildSxema.PaintBox1.Repaint;

BildSxema.LogMemo.Lines.Clear;

end;

end;

end;

//Заповненя таблиці із відповідними значенями схеми і зчитування вихідних

procedure TBildSxema.NoConectLeg;

var

d,f,g,t:integer;

begin

g:=0;

if cxema.ChipsCount<>0 then

for d := 0 to cxema.ChipsCount-1 do

begin

case Cxema.Elements[d].fChipType of tc1: t:=0; tc2: t:=1; tc3: t:=2;end;

for f := 0 to t do

begin

if cxema.Elements[d].LeftLegs[f].fConectState=false then

begin

// stringgrid1.Cells[1,g]:=inttostr(Cxema.Elements[d].LeftLegs[f].Value);

Cxema.Elements[d].LeftLegs[f].Value:=strtoint(stringgrid1.Cells[1,g]);

inc(g);

stringgrid1.RowCount:=g;

end;

end;

if cxema.Elements[d].RightLegs[0].fConectState=false then

//panel5.Caption:='Result='+inttostr(Cxema.Elements[d].RightLegs[0].Value);

end;

end;

//Заповненя таблиці із відповідними значенями схеми і зчитування вихідних

procedure TBildSxema.NoConectLegIn;

var

d,f,g,t:integer;

begin

g:=0;

if cxema.ChipsCount<>0 then

for d := 0 to cxema.ChipsCount-1 do

begin

case Cxema.Elements[d].fChipType of tc1: t:=0; tc2: t:=1; tc3: t:=2;end;

for f := 0 to t do

begin

if cxema.Elements[d].LeftLegs[f].fConectState=false then

begin

stringgrid1.Cells[1,g]:=inttostr(Cxema.Elements[d].LeftLegs[f].Value);

//Cxema.Elements[d].LeftLegs[f].Value:=strtoint(stringgrid1.Cells[1,g]);

inc(g);

stringgrid1.RowCount:=g;

end;

end;

if cxema.Elements[d].RightLegs[0].fConectState=false then

//panel5.Caption:='Result='+inttostr(Cxema.Elements[d].RightLegs[0].Value);

end;

end;

//Виконання генетичного алгоритму в автоматичному режимі

procedure TBildSxema.N3Click(Sender: TObject);

begin

if label17.Caption=' ' then

begin

ShowMessage(' Задайте несправності. Якщо вони задані підтвердіть їх');

exit;

end;

GeneticForm.N1.Click;

while GeneticForm.Edit20.Text='' do

begin

GeneticForm.N2.Click;

GeneticForm.N3.Click;

GeneticForm.N4.Click;

end;

end;

procedure TBildSxema.N5Click(Sender: TObject);

var

I, n : Integer;

begin

n:=0;

For i:=0 to Cxema.ChipsCount-1 do

If cxema.Elements[i].State=false then inc(n);

ShowMessage('Відшукано : '+IntToStr(n)+ ' несправних елементів');

Label17.Caption:=IntToStr(n);

end;

//Формування таблиці істинності

procedure TBildSxema.SpeedButton9Click(Sender: TObject);

var

j, i, k, kk, kktt : integer;

n: double;

code_comb : string;

kt, zn : integer;

begin

if Select then begin

j:=0;

While StringGrid2.Cells[j,0]<>'' do begin

i:=0;

While StringGrid2.Cells[j,i]<>'' do begin

StringGrid2.Cells[j,i]:='';

Inc(i);

end;

Inc(j);

end;

For j:=1 to StringGrid1.RowCount do

StringGrid2.Cells[j-1,0]:=StringGrid1.Cells[0,j-1];

Dec(j);

n:=exp(j*ln(2));

kt:=Round(n);

n:=j;

code_comb:='';

Edit13.Text:=IntToStr(j);

For i:=1 to j do code_comb:=code_comb+'0';

For i:=1 to kt do begin

code_comb:=kombination(code_comb);

StringGrid2.Cells[250,i]:=code_comb;

For j:=1 to Length(code_comb) do

StringGrid2.Cells[j-1,i]:=copy(code_comb,j,1) ;

end;

Dec(j);

i:=1;

While i<=Cxema.ChipsCount do begin

StringGrid2.Cells[j,0]:='f'+IntToStr(i-1);

Inc(j);

Inc(i);

end;

kktt:=i;

For kk:=1 to kt do begin

For k:=0 to Cxema.ChipsCount do StringGrid1.Cells[1,k]:=StringGrid2.Cells[k,kk];

BildSxema.SpeedButton1Click(BildSxema);

BildSxema.SpeedButton7Click(BildSxema);

For j:=0 to Cxema.ChipsCount-1 do begin

zn:= Cxema.Elements[j].RightLegs[0].Value ;

StringGrid2.Cells[i,kk]:=IntToStr(zn);

// ShowMessage(StringGrid2.Cells[i,kk]);

Inc(i);

end;

i:=kktt;

end;

end;

end;

end.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]