//---------------------------------------------------------------------------
#include <vcl.h>
#include <vector.h>
#pragma hdrstop
#include <math.h>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
bool mousedown,distanceAble=false,mouseMove=false;
int xmouse,ymouse;
int xAxis,yAxis,Dcode,xAxisMin,yAxisMin,xAxisMax,yAxisMax,scale=1,scale2=0,click,xStart,yStart,xEnd,yEnd;
int dlatax,dlatay;
class Aperture
{
public:
int Number;
char Sharp;
double Radius;
double Hole;
double Height;
double Width;
void Evaluate(int Num,char Shar,double Rad,double Hol,double Hei,double Wid)
{
Number=Num; Sharp=Shar;Radius=Rad;Hole=Hol;Height=Hei;Width=Wid;
}
};
///////////////////////////////////////////////////////////////////
inline void Draw(TImage * img,Aperture aper)
{
img->Stretch=true;
img->Canvas->Pen->Color=clBlue;
if(aper.Sharp=='C')
{
switch (Dcode)
{
case 1:
img->Canvas->Pen->Width=aper.Radius*1000/scale;
img->Canvas->LineTo((xAxis-xAxisMin)/scale,(yAxis-yAxisMin)/scale);
break;
case 2:
img->Canvas->MoveTo((xAxis-xAxisMin)/scale,(yAxis-yAxisMin)/scale);
break;
case 3:img->Canvas->Ellipse((xAxis+aper.Radius*1000)/scale,(yAxis+aper.Radius*1000)/scale,(xAxis-aper.Radius*1000)/scale,(yAxis-aper.Radius*1000)/scale);
break;
default: break;
}
}
if(aper.Sharp == 'R')
{
switch (Dcode)
{
case 1:
img->Canvas->Pen->Width=aper.Height*1000;
img->Canvas->LineTo((xAxis-xAxisMin)/scale,(yAxis-yAxisMin)/scale);
break;
case 2:
img->Canvas->MoveTo((xAxis-xAxisMin)/scale,(yAxis-yAxisMin)/scale);
break;
case 3:
img->Canvas->Rectangle((xAxis+(aper.Height+aper.Width)*500)/scale,(yAxis+(aper.Height+aper.Width)*500)/scale,(xAxis-(aper.Height+aper.Width)*500)/scale,(yAxis-(aper.Height+aper.Width)*500)/scale);
break;
default: break;
}
}
}
///////////////////////////////////////////////////////////////////////////////
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
vector< Aperture> Ape;
Aperture tmp; int theOne;
TStringList * ger=new TStringList;
int xAxisBeg,xAxisEnd,yAxisBeg,yAxisEnd,xCenter,yCenter;
bool flag;
int Number;
char Sharp;
double Radius;
double Hole;
double Height;
double Width;
Image1->Picture->Assign(NULL);
if(OpenDialog1->Execute())
{
ger->LoadFromFile(OpenDialog1->FileName);
}
// RichEdit1->Lines->Add(ger->Count);
for(int i=0;i<ger->Count;i++) if( ger->Strings[i].Length()==0) {ger->Delete(i); i--;} //删除空行
// RichEdit1->Lines->Add(ger->Count);
flag=true;
for(int i=0;i<ger->Count;i++)
{
switch(ger->Strings[i][1])
{
case 'X':
{
int Xpos,Ypos,Dpos,Starpos;
if(ger->Strings[i].Pos('Y'))
{
Xpos=ger->Strings[i].Pos('X');
Starpos=ger->Strings[i].Pos('*');
Ypos=ger->Strings[i].Pos('Y');
xAxis=ger->Strings[i].SubString(Xpos+1,Ypos-Xpos-1).ToInt();
if(ger->Strings[i].Pos('D'))
{
Dpos=ger->Strings[i].Pos('D');
yAxis=ger->Strings[i].SubString(Ypos+1,Dpos-Ypos-1).ToInt();
Dcode=ger->Strings[i].SubString(Dpos+1,Starpos-Dpos-1).ToInt();
} //X开头 并且有Y
else
{
Dcode=2;
yAxis=ger->Strings[i].SubString(Ypos+1,Starpos-Ypos-1).ToInt();
}
}
else //没有y
{
Xpos=ger->Strings[i].Pos('X');
Starpos=ger->Strings[i].Pos('*');
if(ger->Strings[i].Pos('D'))
{
Dpos=ger->Strings[i].Pos('D');
xAxis=ger->Strings[i].SubString(Xpos+1,Dpos-Xpos-1).ToInt();
Dcode=ger->Strings[i].SubString(Dpos+1,Starpos-Dpos-1).ToInt();
}
else
{
Dcode=1;
xAxis=ger->Strings[i].SubString(Xpos+1,Starpos-Xpos-1).ToInt();
}
}
}
if(flag){xAxisMin=xAxis;yAxisMin=yAxis;xAxisMax=xAxis;yAxisMax=yAxis;}
xAxisMin=xAxisMin<xAxis?xAxisMin:xAxis;
yAxisMin=yAxisMin<yAxis?yAxisMin:yAxis;
xAxisMax=xAxisMax>xAxis?xAxisMax:xAxis;
yAxisMax=yAxisMax>yAxis?yAxisMax:yAxis;
flag=false;
break;
case 'Y':
{
int Ypos,Dpos,Starpos;
Starpos=ger->Strings[i].Pos('*');
Ypos=ger->Strings[i].Pos('Y');
if(ger->Strings[i].Pos('D'))
{
Dpos=ger->Strings[i].Pos('D');
yAxis=ger->Strings[i].SubString(Ypos+1,Dpos-Ypos-1).ToInt();
Dcode=ger->Strings[i].SubString(Dpos+1,Starpos-Dpos-1).ToInt();
}
else
{
Dcode=1;
yAxis=ger->Strings[i].SubString(Ypos+1,Starpos-Ypos-1).ToInt();
}
}
yAxisMin=yAxisMin<yAxis?yAxisMin:yAxis;
yAxisMax=yAxisMax>yAxis?yAxisMax:yAxis;
break;
default: break;
}
}
scale=1;
Image1->Stretch=true;
if((yAxisMax-yAxisMin)>12000||(xAxisMax-xAxisMin)>12000)
{
scale=2;
Image1->Height=(yAxisMax-yAxisMin)/scale;
Image1->Width=(xAxisMax-xAxisMin)/scale;//设置画布大小
}
else
{
Image1->Height=(yAxisMax-yAxisMin);
Image1->Width=(xAxisMax-xAxisMin);
}
for(int i=0;i<ger->Count;i++){
flag=false;
switch(ger->Strings[i][1])
{
case '%':
if(ger->Strings[i][2]=='A'&&ger->Strings[i][3]=='D')
{
//////////////////////////// 圆 /////////////////////////////////////////////////////////////////////
if (ger->Strings[i].Pos('C'))
{
Width=0;Height=0;
Sharp='C';
int Commapos,Cpos,Xpos,Starpos;
Cpos=ger->Strings[i].Pos('C');
Number=ger->Strings[i].SubString(5,Cpos-5).ToInt();
Commapos=ger->Strings[i].Pos(',');
if(ger->Strings[i].Pos('X'))
{
Xpos=ger->Strings[i].Pos('X');
Radius=ger->Strings[i].SubString(Commapos+1,Xpos-Commapos-1).ToDouble();
Starpos=ger->Strings[i].Pos('*');
Hole=ger->Strings[i].SubString(Xpos+1,Starpos-Xpos-1).ToDouble();
Width=0;Height=0;
}
else
{
Starpos=ger->Strings[i].Pos('*');
Radius=ger->Strings[i].SubString(Commapos+1,St