📄 initform.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <fstream.h>
#pragma hdrstop
#include "InitForm.h"
#include "shortpath.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "HemisphereButton"
#pragma link "SUIImagePanel"
#pragma link "SUIButton"
#pragma link "SUIEdit"
#pragma link "SUIForm"
#pragma resource "*.dfm"
TFrm_init *Frm_init;
__fastcall TFrm_init::TFrm_init(TComponent* Owner) : TForm(Owner)
{
CompList=new TList;
}
//---------------------------------------------------------------------------
void __fastcall TFrm_init::FormCreate(TObject *Sender)
{
EdgeCreate=false ;
NodeCreate=true ;
Panel1->DoubleBuffered=true;
Button3->Enabled=false;
BtnTemp=0;
Row=0;
Rol=0;
}
//---------------------------------------------------------------------------
void __fastcall TFrm_init::MyBtnClick(TObject *Sender)
{
THemiBtn* pBtn;
if(EdgeCreate==true&&(pBtn=dynamic_cast<THemiBtn*>(Sender))!=0)
// if((pBtn=dynamic_cast<THemiBtn*>(Sender))!=0)
{
if(BtnTemp!=pBtn->Name||BitCount==0)
BitCount++;
BtnTemp=pBtn->Name;
if(BitCount==1)
{
Image1->Canvas->MoveTo(pBtn->Left+RADIO/2,pBtn->Top+RADIO/2);
char *str;
str=pBtn->Name.c_str();
Row=int(*str)-97;
Value1X=pBtn->Left;
Value1Y=pBtn->Top;
}
if(BitCount==2)
{ BitCount=0;
if(Edit1->Text.ToInt()>0&&Edit1->Text.ToInt()<100)
{
Image1->Canvas->Pen->Color=clBlack;
Image1->Canvas->Pen->Width=2;
Image1->Canvas->LineTo(pBtn->Left+RADIO/2,pBtn->Top+RADIO/2);
char* str;
str=pBtn->Name.c_str();
Rol=int(*str)-97;
Graph[Row][Rol]=StrToInt(Edit1->Text);
Graph[Rol][Row]=StrToInt(Edit1->Text);
Value2X=pBtn->Left;
Value2Y=pBtn->Top;
Image1->Canvas->TextOutA((Value1X+Value2X)/2,(Value1Y+Value2Y)/2,Edit1->Text);
pBtn=NULL;
}
else ShowMessage("输入的值应该在1-100之间");
}
}
}
void __fastcall TFrm_init::suitempButton1Click(TObject *Sender)
{
if(CompList->Count>1)
{ for(int i=0;i<CompList->Count;i++)
for(int j=0;j<CompList->Count;j++)
Graph[i][j]=0;
Button3->Enabled=true;
NodeCreate=false;
EdgeCreate=true;
Button1->Caption="开始创建边";
Button1->Enabled=false;
}
else ShowMessage("请先点击左侧空白区创建节点");
//CompCount=CompList->Count;
}
//---------------------------------------------------------------------------
void __fastcall TFrm_init::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(CompList->Count<MAX&&NodeCreate==true)
{
THemiBtn * HemiBtn;
HemiBtn=new THemiBtn(this);
HemiBtn->Parent=Panel1;
HemiBtn->Name=char(CompList->Count+97);
HemiBtn->Caption=char(CompList->Count+97);
HemiBtn->Top=Y-RADIO/2;
HemiBtn->Left=X-RADIO/2;
HemiBtn->Width=RADIO;
HemiBtn->Height=RADIO;
HemiBtn->OnClick=MyBtnClick;
CompList->Add(HemiBtn);
}
else return;
}
//---------------------------------------------------------------------------
void __fastcall TFrm_init::FormClose(TObject *Sender, TCloseAction &Action)
{
Action=caFree;
}
//---------------------------------------------------------------------------
void __fastcall TFrm_init::suitempButton3Click(TObject *Sender)
{
bool ok;
for(int i=0;i<MAX;i++)
for(int j=0;j<MAX;j++)
if(Graph[i][j]!=0)
{
ok=true;
break;
}
if(ok==true)
{
ofstream fout(DATAFILE);
fout<<CompList->Count;
for(int i=0;i<MAX;i++)
for(int j=0;j<MAX;j++)
fout<<Graph[i][j];
fout.close();
TMemoryStream *cms= new TMemoryStream();
for(int i=0;i<CompList->Count;i++)
cms->WriteComponent((THemiBtn*)(CompList->Items[i]));
cms->SaveToFile(CMPFILENAME);
ShowMessage("保存成功,请选择演示");
delete cms;
Frm_init->Close();
}
else ShowMessage("至少应该有一条边") ;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -