#pragma once

#include <stdlib.h>

#include <string.h>
#include <math.h>
#include <assert.h>
#include "Datastruct.h"
#include <Bentley/bvector.h>
#include "StationDataBase.h"
//#include <Mstn/PSolid/mssolid.h>
//#include <Mstn\PSolid\mssolid.fdf>
//#include <Mstn\MdlApi\msbrepcommon.r.h>

#define MAXJDNUM 20
#define MAXXLJDNUM 100
#define MAXXLBPDNUM 200
#define MAXBPDNUM 20
#define MAXDLNUM 10
#define MAXXLDLNUM 30
#define PRECISION 1.0e-6
#define Spoint(pt, x, y, z)  pt[X] = (x);  pt[Y] = (y);  pt[Z] = (z)
#define Cpoint(d, s)   d[X] = s[X];  d[Y] = s[Y];  d[Z] = s[Z]


class BAS_DRAW_FUN
{
public:
	double ZXJ(double s2, double s1) const;
	static int  F_num(ACHAR* str, ACHAR c);
	static double xyddaa(double xb, double yb, double xe, double ye, double& f);
	static double xyddaa(double xb, double yb, double xe, double ye, double* f);
	double GetSide(double Xo, double Yo, double x1, double y1, double x, double y) const;
	double Circle_XY_to_ML(double x, double y, const double array2[4 * MAXJDNUM][10], int kk) const;
	static void ChuizuToZx(int& inorout, double& dXchuizu, double& dYchuizu, double dXout, double dYout, double dXstart, double dYstart, double dXend, double dYend);
	int PROJ_ML_all(double array2[][10], int trow2, double xout, double yout, double xon, double yon, vector<double>& ml) const;
	static double deg(double d_ms);
	static double rad(double d_ms);
	static void split_ckml(ACHAR str[], double* ml, ACHAR* ck);
	static double CCW2(double dPt1X, double dPt1Y, double dPt2X, double dPt2Y, double dPt3X, double dPt3Y);
	static double dms(double ddd);
	int getBPMTL(double a, double R, double L1, double L2, double* BPMTL);
	static double  Get_INDATA_L(double INDATA[5], int* jj);
	static int xlzbxy(struct xlpoint* P0, struct xlpoint* PZ, double l, double INDATA[5], int display);
	static double spiral_x(double A, double l);
	static double spiral_y(double A, double l);
	static long factorialfun(int n);
	double spiral_xm(double A, double L) const;
	double spiral_p(double A, double L) const;
	static CString  getBHID();
	static  double TYLC1(ACHAR ckml[STR_EXTEND], int NDL, DLBZ DLBTMP[STR_SHORT]);
	static int  xlpoint_pz(const double array2[][10], int trow2, struct xlpoint* PZ, int isprinttext = 0);
	static void LCchr(ACHAR* GH, double lc, int NLC, ACHAR* ch, int mode = 1);
	static int INTERS(double* x, double* y, double X1, double Y1, double X2, double Y2, double X3, double Y3, double X4, double Y4);
	BOOL CalXYArray(double In_JDarray[MAXJDNUM][7], int In_NJD, double Out_array[4 * MAXJDNUM][10], int& Out_tarray, double Out_QXB[MAXJDNUM][9], double& Out_xllen);
	static int JudgeAcharIsHaveCstring(ACHAR ZiFuChuan[], CString zifuchuan);
	//求道岔接出点位置  isDaoChaNum4为1时，表示当前是四个道岔的渡线
	BOOL GetSingleSwitchCoordinate1(double SingleXY[9], DPoint3d& StaPt, DPoint3d& End1, DPoint3d& End2, DPoint3d& End3, DPoint3d& End4, int isDaoChaNum4 = 0);
	//为处理交叉渡线添加的
	bool DaoChaCeGuFangWeiJiaoChuLi(double SingleXY[9], DVec3d& vec_CeGu);
	std::vector<Switch>m_DaochaDate;
	static DVec3d calfwjvec(double fwj);
	double PROJ_ML(double array2[][10], int trow2, double xout, double yout, double xon, double yon) const;
	static void ChushiHuaDaochaData(Switch& DaochaData);
	static void ChangeTextType(ACHAR atmp[], int duannum, ACHAR res[STR_LONG]);
	static int mscmp2(ACHAR atmp[], ACHAR btmp[]);
	static double dms_rad(double rad);
	int covertRoman2ALB(ACHAR str[STR_EXTEND]);
	//struct xlpoint
	//{
	//	double x, y, a, r, lc;
	//	xlpoint()
	//	{
	//		x = 0.0;
	//		y = 0.0;
	//		a = 0.0;
	//		r = 0.0;
	//		lc = 0.0;
	//	}
	//	~xlpoint()
	//	{
	//		x = 0.0;
	//		y = 0.0;
	//		a = 0.0;
	//		r = 0.0;
	//		lc = 0.0;
	//	}
	//};//此处的x、y与CAD中的X、Y相反
	static int ReadWorkdir();

};