
Файл Unit1.Cpp:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TDotForm *DotForm;
//---------------------------------------------------------------------------
__fastcall TDotForm::TDotForm(TComponent* Owner)
: TForm(Owner)
{
path = "";
}
//---------------------------------------------------------------------------
void __fastcall TDotForm::DotAddClick(TObject *Sender)
{
if(!DotX->Text.IsEmpty() && !DotY->Text.IsEmpty())
{
graph->AddDot(new Dot(StrToInt(DotX->Text), StrToInt(DotY->Text)));
DotList->Items->Add(DotX->Text + "; " + DotY->Text);
graph->Draw();
DotX->Text = "";
DotY->Text = "";
}
}
//---------------------------------------------------------------------------
void __fastcall TDotForm::DotRemoveClick(TObject *Sender)
{
graph->dots.erase(graph->dots.begin()+DotList->ItemIndex);
DotList->DeleteSelected();
graph->Draw();
}
//---------------------------------------------------------------------------
void __fastcall TDotForm::LineAddClick(TObject *Sender)
{
if(!LineX1->Text.IsEmpty() && !LineY1->Text.IsEmpty() && !LineX2->Text.IsEmpty() && !LineY2->Text.IsEmpty())
{
graph->AddDot(new Dot(StrToInt(LineX1->Text), StrToInt(LineY1->Text)));
graph->AddDot(new Dot(StrToInt(LineX2->Text), StrToInt(LineY2->Text)));
LineList->Items->Add("(" + LineX1->Text + "; " + LineY1->Text + "), (" + LineX2->Text + "; " + LineY2->Text + ")");
graph->Draw();
LineX1->Text = "";
LineY1->Text = "";
LineX2->Text = "";
LineY2->Text = "";
}
}
//---------------------------------------------------------------------------
void __fastcall TDotForm::LineRemoveClick(TObject *Sender)
{
graph->dots.erase(graph->dots.begin()+LineList->ItemIndex*2);
graph->dots.erase(graph->dots.begin()+(LineList->ItemIndex)*2 + 1);
LineList->DeleteSelected();
graph->Draw();
}
//---------------------------------------------------------------------------
void __fastcall TDotForm::PolyAddClick(TObject *Sender)
{
if(!PolyX->Text.IsEmpty() && !PolyY->Text.IsEmpty())
{
graph->AddDot(new Dot(StrToInt(PolyX->Text), StrToInt(PolyY->Text)));
PolyList->Items->Add(PolyX->Text + "; " + PolyY->Text);
graph->Draw();
PolyX->Text = "";
PolyY->Text = "";
}
}
//---------------------------------------------------------------------------
void __fastcall TDotForm::PolyRemoveClick(TObject *Sender)
{
graph->dots.erase(graph->dots.begin()+PolyList->ItemIndex);
PolyList->DeleteSelected();
graph->Draw();
}
//---------------------------------------------------------------------------
void __fastcall TDotForm::Dot1Click(TObject *Sender)
{
LinePanel->Visible = false;
PolyPanel->Visible = false;
DotPanel->Visible = true;
graph = (Graph *)(new GraphDot(DotImage, DotList));
graph->type = Graph::DOT;
}
//---------------------------------------------------------------------------
void __fastcall TDotForm::Line1Click(TObject *Sender)
{
PolyPanel->Visible = false;
DotPanel->Visible = false;
LinePanel->Visible = true;
graph = (Graph *)(new GraphLine(LineImage, LineList));
graph->type = Graph::LINE;
}
//---------------------------------------------------------------------------
void __fastcall TDotForm::Poly1Click(TObject *Sender)
{
DotPanel->Visible = false;
LinePanel->Visible = false;
PolyPanel->Visible = true;
graph = (Graph *)(new GraphPoly(PolyImage, PolyList));
graph->type = Graph::POLY;
}
//---------------------------------------------------------------------------
void __fastcall TDotForm::Exit1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TDotForm::Save1Click(TObject *Sender)
{
if(SaveDialog->Execute())
{
if(path != "")
graph->Save((const char*)path.c_str()) ;
else if(SaveDialog->Execute())
graph->Save((const char*)(path = SaveDialog->FileName).c_str()) ;
}
}
//---------------------------------------------------------------------------
void __fastcall TDotForm::Load1Click(TObject *Sender)
{
if(OpenDialog->Execute())
{
TListBox *list;
switch(graph->type)
{
case Graph::DOT:
list = DotList;
break;
case Graph::LINE: list = LineList; break;
case Graph::POLY: list = PolyList; break;
default: break;
}
graph->Load((const char*)(path = OpenDialog->FileName).c_str(), list);
}
}
//---------------------------------------------------------------------------