📄 pmainform.h
字号:
//---------------------------------------------------------------------------
#ifndef pMainFormH
#define pMainFormH
//---------------------------------------------------------------------------
#include "stdio.h"
#include "math.h"
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Menus.hpp>
#include <Dialogs.hpp>
#include <ExtCtrls.hpp>
#include <Buttons.hpp>
#include <ComCtrls.hpp>
#include <ToolWin.hpp>
const int crPan = 1; //光标标志数
const int crZoomOut = 2;
const int crZoomIn = 3;
const int crZoomWin = 4;
const int crZoomBack = 5;
const int crDrawVector = 6;
const int crDrawNote = 7;
const int crSelectTarget= 8;
#define ZoomFactor 2. //缩放倍率
#define ZOOMOUT 10001
#define ZOOMIN 10002
#define PAN 10003
#define ZOOMBOX 10004
struct PNT{double x,y;};
int ZoomBox_minx;
int ZoomBox_miny;
int ZoomBox_maxx;
int ZoomBox_maxy;
bool Captured;
TColor ZoomBoxColor[4][2500];
PNT ptMouse,ptMouseTmp;
#define MAXPTS 20000
#define MAXTINS 100000
//#define MAXEDGES 30000
int eLstNo;
FILE * fptmp;
struct POINTSET {int pNum;
double *x,*y,xmin,xmax,ymin,ymax,dx,dy;} * pts;
struct TIN {int P1,P2,P3;};
struct TINS {int tNum; TIN *Tins;} * tins;
double GetScreenX(double x){return 80+x*4./10000.;}
double GetScreenY(double y){return (480-y*4./10000.-50);}
double GetMinDistance()
{
double Dmin=1.E+30,Dtmp,x1,y1,x2,y2;
for(int i=0;i<pts->pNum-1;i++)for(int j=i+1;j<pts->pNum;j++)
{
x1=pts->x[i]; y1=pts->y[i];
x2=pts->x[j]; y2=pts->y[j];
Dtmp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
if(Dtmp<Dmin)Dmin=Dtmp;
}
Dmin=sqrt(Dmin);
return Dmin/10000.;
}
void ReadPointSet(char * FileGEN)
{
randomize();
pts->pNum=0;
FILE * fp=fopen(FileGEN,"r+");
double xtmp,ytmp; char sTmp[20]; int i;
for(i=0;i<MAXPTS;i++){
fscanf(fp,"%s%lf%lf",&sTmp,&xtmp,&ytmp);
xtmp*=10000.;
ytmp*=10000.;
xtmp+=random(50);
ytmp+=random(50);
if(!isdigit(sTmp[0]))break;
else {pts->x[i]=xtmp; pts->y[i]=ytmp;}
} pts->pNum=i; fclose(fp);
}
void SetPointSetBox()
{
pts->xmin=1.E+30; pts->ymin=1.E+30;
pts->xmax=-1.E+30;pts->ymax=-1.E+30;
for(int i=0;i<pts->pNum;i++){
if(pts->x[i]<pts->xmin)pts->xmin=pts->x[i];
if(pts->y[i]<pts->ymin)pts->ymin=pts->y[i];
if(pts->x[i]>pts->xmax)pts->xmax=pts->x[i];
if(pts->y[i]>pts->ymax)pts->ymax=pts->y[i];
} pts->dx=pts->xmax-pts->xmin; pts->dy=pts->ymax-pts->ymin;
}
void SearchNearestPoint(int P1,int * PT2)
{
double Dmin=1.E+30,Dtmp,x1,y1,x2,y2;
x1=pts->x[P1]; y1=pts->y[P1];
for(int i=0;i<pts->pNum;i++)if(i!=P1)
{
x2=pts->x[i]; y2=pts->y[i];
Dtmp=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
if(Dtmp<Dmin){Dmin=Dtmp;*PT2=i;}
}
}
void InitArray()
{
pts=(POINTSET *)calloc(1,sizeof(POINTSET));
tins=(TINS *)calloc(1,sizeof(TINS));
pts->pNum=0;
tins->tNum=0;
pts->x=(double *)calloc(MAXPTS,sizeof(double));
pts->y=(double *)calloc(MAXPTS,sizeof(double));
tins->Tins=(TIN *)calloc(MAXTINS,sizeof(TIN));
for(int i=0;i<MAXPTS;i++){pts->x[i]=0.;pts->y[i]=0.;}
for(int i=0;i<MAXTINS;i++){tins->Tins[i].P1=0;tins->Tins[i].P2=0;tins->Tins[i].P3=0;}
}
void CircleBy3Points(double x1,double y1,double x2,double y2,double x3,double y3,double * x0,double * y0,double * R2)
{ //Get circle parameters by 3 points, Note: R2=R*R
double a1,b1,c1,a2,b2,c2;
a1=2*(x1-x2); b1=2*(y1-y2); c1=(x1*x1+y1*y1)-(x2*x2+y2*y2);
a2=2*(x2-x3); b2=2*(y2-y3); c2=(x2*x2+y2*y2)-(x3*x3+y3*y3);
*y0=(a2*c1-a1*c2)/(a2*b1-a1*b2);
*x0=(c1-b1*(*y0))/(a1);
*R2=(x1-*x0)*(x1-*x0)+(y1-*y0)*(y1-*y0);
}
void SearchNewPoint(int P1,int P2,int * P3,int LR)
{ //LR=1(Left);-1(Right)
double x1,x2,y1,y2,x,y,x0,y0,R; int isTin; *P3=-1;
x1=pts->x[P1]; y1=pts->y[P1]; x2=pts->x[P2]; y2=pts->y[P2];
for(int i=0;i<pts->pNum;i++)if(i!=P1&&i!=P2)
{
x=pts->x[i]; y=pts->y[i];
if((1.E+8*(x2-x1)*(y-y1)<1.E+8*(y2-y1)*(x-x1)&&LR==1)
||(1.E+8*(x1-x2)*(y-y2)<1.E+8*(y1-y2)*(x-x2)&&LR==-1))
{
isTin=1;
CircleBy3Points(x1,y1,x2,y2,x,y,&x0,&y0,&R); R=sqrt(R);
for(int j=0;j<pts->pNum;j++)if(j!=P1&&j!=P2&&j!=i)
{
if((x0-pts->x[j])*(x0-pts->x[j])+(y0-pts->y[j])*(y0-pts->y[j])<R*R)
{isTin=0;break;}
}
if(isTin==1){*P3=i; break;}
}
}
}
int isNewTin(int P1,int P2,int P3)
{
int isProper=1,PA,PB,PC;
if(P1<0||P2<0||P3<0||P1>=pts->pNum||P2>=pts->pNum||P3>=pts->pNum
||P1==P2||P1==P3||P2==P3)isProper=0;
else{
for(int i=0;i<tins->tNum;i++)
{
PA=tins->Tins[i].P1;
PB=tins->Tins[i].P2;
PC=tins->Tins[i].P3;
if(fabs(1.*(PA+99)*(PB+99)*(PC+99)-1.*(P1+99)*(P2+99)*(P3+99))<0.5
&&fabs(1.*(PA+97)*(PB+97)*(PC+97)-1.*(P1+97)*(P2+97)*(P3+97))<0.5
&&fabs(1.*(PA+96)*(PB+96)*(PC+96)-1.*(P1+96)*(P2+96)*(P3+96))<0.5
){isProper=0;break;}
}}
return isProper;
}
//---------------------------------------------------------------------------
class TMainForm : public TForm
{
__published: // IDE-managed Components
TMainMenu *MainMenu1;
TMenuItem *N1;
TMenuItem *N2;
TMenuItem *TIN1;
TMenuItem *N3;
TOpenDialog *OpenDialog;
TToolBar *ToolBar;
TSpeedButton *sButton1;
TSpeedButton *sButton2;
TSpeedButton *sButton3;
TSpeedButton *sButton4;
TSpeedButton *sButton5;
TSpeedButton *sButton6;
TSpeedButton *sButton7;
TSpeedButton *sButton8;
TStatusBar *sBar;
void __fastcall N3Click(TObject *Sender);
void __fastcall N2Click(TObject *Sender);
void __fastcall TIN1Click(TObject *Sender);
void __fastcall sButton1Click(TObject *Sender);
void __fastcall sButton4Click(TObject *Sender);
void __fastcall sButton5Click(TObject *Sender);
void __fastcall sButton6Click(TObject *Sender);
void __fastcall sButton7Click(TObject *Sender);
void __fastcall sButton8Click(TObject *Sender);
void __fastcall FormMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall FormMouseMove(TObject *Sender, TShiftState Shift,
int X, int Y);
void __fastcall FormMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall FormResize(TObject *Sender);
void __fastcall FormPaint(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TMainForm(TComponent* Owner);
AnsiString FileName;
void DrawPointSet();
void DrawLine(int P1,int P2);
void DrawTin(int No);
void DrawTinset();
void SetInitialTin();
void AddTin(int P1,int P2,int P3);
void TinGrow(int tNo);
bool OpenStatus;
void RefreshMap();
void ZoomFull();
float zoomratio; //缩放比例(=地图距离/屏幕距离)
float zoomratio0; //基本缩放比例(全局显示时的比例)
float xcenter,ycenter;//地图的缩放中心(该点显示在窗口的中心,但坐标为地图坐标)
int OperateID; //放大、缩小等操作状态
void GetScreenPoint(PNT * pt);
void GetMapPoint(PNT * pt);
};
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//---------------------------------------------------------------------------
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -