// BAS_DRAW_FUN1.cpp: implementation of the BAS_DRAW_FUN class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Psapi.h"
#include <io.h>
#include "BAS_DRAW_FUN.h"
#include "GTZX.h"
#include "StationDataBase.h"
#include "GlobalData.h"

#define streq(s,t) (_tcscmp((s),(t))==0)
#define AppName  /*MSG1*/"GUADS" 
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#define new DEBUG_NEW
#endif

//#pragma  once
//#pragma  message("Psapi.h --> Linking with Psapi.lib")
//#pragma  comment(lib,"Psapi.lib")
#include "GTZX.h"
//#include "GTZX2.h"
//#include "ORI_SCALE.h"
//#include "tun.h"
//#include "GlobalZDMData.h"
//GuiFanCanShu mGJGuiFanCS;
//QuXianZheJiang m_ZJ;

extern ZCGTZX* pzLinep;
extern vector<ZCGTZX*> PGDArray;
extern vector<CBaseLine*> pJXGTZXArray;//全局变量
extern ZCGTZX* m_BEntity1;
extern Cshejicanshumdb GlobalSJYZ;
extern CString OLDPro;
extern Cshejicanshumdb GlobalSJYZDlg;
extern int BackGroundFill;
extern BOOL ssJYBZ;
// 预留标注加中括号
extern BOOL ssYLBZ;

int BAS_DRAW_FUN::JudgeAcharIsHaveCstring(ACHAR ZiFuChuan[], CString zifuchuan)
{
	int isHaveCstring = 0;
	CString CStringTemp = ZiFuChuan;
	int ReturnData = CStringTemp.Find(zifuchuan);
	if (ReturnData == -1)
		isHaveCstring = 0;
	else
		isHaveCstring = 1;
	return isHaveCstring;
}

double BAS_DRAW_FUN::spiral_xm(double A, double L) const
{
	double R, t, XM;
	R = A * A / L; t = A * A / (2.0 * R * R);
	XM = spiral_x(A, L) - R * sin(t);
	return(XM);
}

double BAS_DRAW_FUN::spiral_p(double A, double L) const
{
	double R, t, p;
	R = A * A / L; t = A * A / (2.0 * R * R);
	p = spiral_y(A, L) + R * cos(t) - R;
	return(p);
}

int BAS_DRAW_FUN::F_num(ACHAR* str, ACHAR c)
{
	int i, len, num = 0, smark, c1;

	smark = toupper(c);
	len = (int)_tcslen(str);
	for (i = len - 1; i >= 0; i--) {
		c1 = toupper(str[i]);
		if (c1 == smark)
		{
			num = i + 1; break;
		}
	}
	return(num);
}

// 函数里传入的参数X, Y均为线路坐标系，与CAD坐标系相反
double BAS_DRAW_FUN::CCW2(double dPt1X, double dPt1Y, double dPt2X, double dPt2Y, double dPt3X, double dPt3Y)
{
	double x1, x2, x3, y1, y2, y3, bx, by;

	double Val = 0.0;
	bx = (dPt1X + dPt2X + dPt3X) / 3.0;
	by = (dPt1Y + dPt2Y + dPt3Y) / 3.0;
	x1 = dPt1X - bx;
	x2 = dPt2X - bx;
	x3 = dPt3X - bx;
	y1 = dPt1Y - by;
	y2 = dPt2Y - by;
	y3 = dPt3Y - by;
	Val = (x1 * (y2 - y3) - x2 * (y1 - y3) + x3 * (y1 - y2));
	if (Val < 0.0) // 顺时针
		return -1.0;
	else
		return 1.0;
}

CString  BAS_DRAW_FUN::getBHID()
{
	CString NewID;
	SYSTEMTIME lpSystemTime;
	GetSystemTime(&lpSystemTime);
	int Year = lpSystemTime.wYear;
	int Month = lpSystemTime.wMonth;
	int Day = lpSystemTime.wDay;
	int Hour = lpSystemTime.wHour;
	int Minute = lpSystemTime.wMinute;
	int Second = lpSystemTime.wSecond;
	int Millsecond = lpSystemTime.wMilliseconds;
	int suiji1 = rand() % 100;
	int suiji2 = rand() % 100;
	NewID.Format(L"%d%d%d%d%d%d", Hour, Minute, Second, Millsecond, suiji1, suiji2);
	return NewID;
}

double  BAS_DRAW_FUN::GetSide(double Xo, double Yo, double x1, double y1, double x, double y) const
//左侧-，右+
{
	double s;
	s = (x - Xo) * (y1 - Yo) - (x1 - Xo) * (y - Yo);
	return s;
}

double  BAS_DRAW_FUN::Circle_XY_to_ML(double x, double y, const double array2[4 * MAXJDNUM][10], int kk)const
//x,y为给定圆上一点，kk为圆弧线元(不考虑回头)
{
	double x1, y1, x2, y2, s1, s2, s, ss1;

	s1 = array2[kk][6];
	s2 = array2[kk + 1][6];
	double R = array2[kk][1];
	x1 = array2[kk][8], y1 = array2[kk][9];
	x2 = array2[kk + 1][8], y2 = array2[kk + 1][9];
	ss1 = sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
	s = s1 + R * 2 * asin(0.5 * ss1 / R);

	double sfwj = array2[kk][5];
	double szx = array2[kk][4];

	double Xo, Yo, fwj1, fwj2, zxj;
	Xo = x1 + R * cos(sfwj + szx * 0.5 * PI);
	Yo = y1 + R * sin(sfwj + szx * 0.5 * PI);

	xyddaa(Xo, Yo, x1, y1, &fwj1);
	xyddaa(Xo, Yo, x, y, &fwj2);
	zxj = ZXJ(fwj2, fwj1);
	//ads_printf(L"s=%lf zxj=%lf zx=%lf %lf %lf %lf %lf\n",s,zxj,szx,Xo,Yo,x,y);
	if (zxj * szx < 0.0)
	{
		s = s1 + R * 2 * PI - R * 2 * asin(0.5 * ss1 / R);
	}
	// ss2 = sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
	// s = (s1*ss2+s2*ss1)/(ss1+ss2);
	//	  ads_printf(L"***R=%lf %lf %lf\n",R,s1,s);
	return s;
}

//2015.9传出所有里程，用于垂足
int BAS_DRAW_FUN::PROJ_ML_all(double array2[][10], int trow2,double xout, double yout, double xon, double yon, vector<double>& ml) const
{
	double x1, y1, x2, y2, x3, y3, x4, y4, s1, s2, s, ZJ, Alf1, Alf2, Alf, Xo, Yo, q, x, y, ZJ1, ZJ2, R;
	int i, kk[100], ii, xynum = 0;
	double LorR, X1[100], Y1[100], X2[100], Y2[100];
	double DistYCX = 1.0;

	double lc = array2[0][4];
	//起点向前延长1000m
	x2 = array2[0][1] + DistYCX * cos(rad(array2[0][3]) + PI);
	y2 = array2[0][2] + DistYCX * sin(rad(array2[0][3]) + PI);
	for (i = 1; i <= trow2; i++)
	{
		x1 = x2;
		y1 = y2;
		x2 = array2[i][8];
		y2 = array2[i][9];

		q = array2[i][0];
		// 	ads_printf(L"##x1=%lf,y1=%lf ,x2=%lf,y2=%lf,q=%lf\n",x1,y1,x2,y2,q);
		LorR = 1.0;
		/////////////////////////地铁将线路终点 线元属性赋为10
		if (q > 1.1 && q < 10)
		{
			LorR = array2[i][4];
		}
		//		ads_printf(L"%lf\n",array2[i][4]);
		if (i > 1)
			Alf1 = array2[i - 1][5];
		else
			Alf1 = rad(array2[i - 1][3]);

		Alf2 = array2[i][5];
		if (i == trow2)//终点向后延长1000m
		{
			//	ads_printf(L"Alf1=%lf Alf2=%lf\n",Alf1,Alf2);
			x2 = x2 + DistYCX * cos(Alf1);
			y2 = y2 + DistYCX * sin(Alf1);
		}
		x3 = x1 + 1000.0 * cos(0.5 * LorR * PI + Alf1);
		y3 = y1 + 1000.0 * sin(0.5 * LorR * PI + Alf1);

		x4 = x2 + 1000.0 * cos(0.5 * LorR * PI + Alf2);
		y4 = y2 + 1000.0 * sin(0.5 * LorR * PI + Alf2);

		s1 = GetSide(x3, y3, x1, y1, xon, yon);
		s2 = GetSide(x4, y4, x2, y2, xon, yon);

		if (s1 * s2 < 0.0001 || fabs(s1) < 0.00001 || fabs(s2) < 0.00001)
		{
			kk[xynum] = i;
			X1[xynum] = x1;
			Y1[xynum] = y1;
			X2[xynum] = x2;
			Y2[xynum] = y2;
			xynum++;//搜索出所有可能线元
		}
	}
	if (xynum == 0)
	{
		//ads_printf(L"指定点不在线路上(1)!\n");
		return -1;
	}
	double cml[100];
	for (i = 0; i < xynum; i++)
	{
		x1 = X1[i];
		y1 = Y1[i];
		x2 = X2[i];
		y2 = Y2[i];

		//搜索范围限制在kk-1-------kk段现元上
		if (kk[i] > 0)
		{
			q = array2[kk[i] - 1][0];
			LorR = array2[kk[i] - 1][4];//?左右转
		}
		else
		{
			q = array2[0][0];
			LorR = 0.0;//?左右转
		}
		//ads_printf(L"kk=%d,lc=%lf q=%lf %lf \n",kk,array2[kk][6],q,array2[kk-1][6]);
		//	LorR = 1;
		//	if(fabs(q) > 0.1)

		if (fabs(LorR) < 0.001)
			LorR = 1.0;

		if (kk[i] > 1)
			Alf1 = array2[kk[i] - 1][5];
		else
			Alf1 = rad(array2[kk[i] - 1][3]);

		Alf2 = array2[kk[i]][5];

		if (kk[i] > 1)
			lc = array2[kk[i] - 1][6];//当前线元起始里程

		if (q < 1.1)//直线
		{
			s1 = sqrt((xout - x1) * (xout - x1) + (yout - y1) * (yout - y1));
			xyddaa(x1, y1, xout, yout, &Alf2);
			ZJ = ZXJ(Alf2, Alf1);
			// 	ads_printf(L"ZJ=%lf Alf2=%lf Ald1=%lf\n",ZJ,Alf2,Alf1);
			cml[i] = lc + s1 * cos(ZJ);
		}
		else if (q < 2.1)//圆
		{
			R = array2[kk[i] - 1][1];

			Xo = array2[kk[i] - 1][8] + R * cos(array2[kk[i] - 1][5] + LorR * 0.5 * PI);
			Yo = array2[kk[i] - 1][9] + R * sin(array2[kk[i] - 1][5] + LorR * 0.5 * PI);


			s = 0.5 * (array2[kk[i]][6] - lc);
			x = x1 + s * cos(Alf1);
			y = y1 + s * sin(Alf1);
			xyddaa(Xo, Yo, xout, yout, &Alf);

			s1 = GetSide(x1, y1, Xo, Yo, x, y);
			s2 = GetSide(x1, y1, Xo, Yo, xout, yout);
			if (s1 * s2 < 0.001 || fabs(s1) < 0.00001 || fabs(s2) < 0.00001)
				Alf = Alf + PI;
			x = Xo + R * cos(Alf);
			y = Yo + R * sin(Alf);

			cml[i] = Circle_XY_to_ML(x, y, array2, kk[i] - 1);
		}
		else//缓和曲线
		{
			xyddaa(xout, yout, x1, y1, &Alf1);
			xyddaa(xout, yout, x2, y2, &Alf2);

			if (kk[i] > 1)
				ZJ1 = ZXJ(Alf1, array2[(kk[i]) - 1][5]);
			else
				ZJ1 = ZXJ(Alf1, rad(array2[(kk[i]) - 1][3]));

			ZJ2 = ZXJ(Alf2, array2[(kk[i])][5]);
			if (fabs(ZJ1) > 0.5 * PI)
				ii = 1;
			else
				ii = -1;

			s1 = lc;
			s2 = array2[(kk[i])][6];
		L20:
			s = 0.5 * (s1 + s2);
			cml[i] = s;
			struct xlpoint PZ;
			PZ.lc = s;
			xlpoint_pz(array2, trow2, &PZ);
			xyddaa(xout, yout, PZ.x, PZ.y, &Alf);
			ZJ = ZXJ(Alf, PZ.a);
			if ((ii == 1 && fabs(ZJ) > 0.5 * PI) || (ii == -1 && fabs(ZJ) < 0.5 * PI))
				s1 = s;
			else
				s2 = s;
			if (fabs(s2 - s1) > 0.00001)
				goto L20;
		}
	}
	//取出距离xon,yon的点
	ml.clear();
	for (i = 0; i < xynum; i++)
		ml.push_back(cml[i]);

	return 1;
}

void BAS_DRAW_FUN::split_ckml(ACHAR str[], double* ml, ACHAR* ck)
{
	int i, j, len, str_len, lplus;
	ACHAR  cml[STR_NORMAL];
	double tml = 0;
	*ml = 0;
	_tcscpy(ck, L"");
	/*                CIK   153 + 342.53
						.       .
					   len     lplus                               */
	ck[0] = '\0';
	len = F_num(str, 'K');
	lplus = F_num(str, '+');
	str_len = (int)_tcslen(str);
	for (i = 0; i < len; i++)
		ck[i] = str[i];
	ck[len] = '\0';


	if (lplus == 0) {
		for (i = len, j = 0; i < str_len; i++, j++)
			cml[j] = str[i];
		cml[j] = '\0';
	}
	else {
		j = 0;
		for (i = len; i < lplus - 1; i++)
			if (str[i] != ' ')
				cml[j++] = str[i];

		for (i = lplus; i < str_len; i++)
			if (str[i] != ' ')
				cml[j++] = str[i];
		cml[j] = '\0';
	};
	tml = _tstof(cml);
	*ml = tml;
	//tml *= 1000.0;
	//tml =  floor(tml);
	//*ml =  tml/1000.0;
}

int BAS_DRAW_FUN::getBPMTL(double a, double R, double L1, double L2, double* BPMTL)
{
	// BPTL[9]=B1,B2,P1,P2,M1,M2,T1,T2,L
	double A1, A2, aa, B1, B2, P1, P2, M1, M2, T1, T2, LS;
	A1 = sqrt(R * L1); A2 = sqrt(R * L2);
	aa = rad(a);

	if (R > 1.0e-6)
	{
		B1 = L1 * 0.5 / R;
		B2 = L2 * 0.5 / R;
	}
	else
	{
		B1 = 0;
		B2 = 0;
	}


	if (L1 < 0.0001) { P1 = 0.0; M1 = 0.0; }
	else { P1 = spiral_p(A1, L1); M1 = spiral_xm(A1, L1); };
	if (L2 < 0.0001) { P2 = 0.0; M2 = 0.0; }
	else { P2 = spiral_p(A2, L2); M2 = spiral_xm(A2, L2); };
	// P1=spiral_p(A1,L1);P2=spiral_p(A2,L2);//P1,P2
	// M1=spiral_xm(A1,L1);M2=spiral_xm(A2,L2);// M1,M2

	if (fabs(aa) > 1.0e-6)
	{
		T1 = (R + P1) * tan(aa * 0.5) + M1 - (P1 - P2) / sin(aa);
		T2 = (R + P2) * tan(aa * 0.5) + M2 + (P1 - P2) / sin(aa);
	}
	else
	{
		T1 = 0;
		T2 = 0;
	}

	LS = (aa - B1 - B2) * R + L1 + L2;
	*(BPMTL + 0) = B1;
	*(BPMTL + 1) = B2;
	*(BPMTL + 2) = P1;
	*(BPMTL + 3) = P2;
	*(BPMTL + 4) = M1;
	*(BPMTL + 5) = M2;
	*(BPMTL + 6) = T1;
	*(BPMTL + 7) = T2;
	*(BPMTL + 8) = LS;
	return(1);
}

int BAS_DRAW_FUN::covertRoman2ALB(ACHAR str[STR_EXTEND])
{
	if (_tcscmp(str, L"") == 0)
		return 0;
	int mp[100];
	if (str[0] > 99)
		return 0;
	int val[] = { 1000,900,500,400,100,90,50,40,10,9,5,4,1 };
	string r[] = { "M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I" };
	mp['I'] = 1;
	mp['V'] = 5;
	mp['X'] = 10;
	mp['L'] = 50;
	mp['C'] = 100;
	mp['D'] = 500;
	mp['M'] = 1000;
	int t, re, pre;
	re = pre = mp[str[0]];
	for (t = 1; str[t] != '\0'; t++)
	{
		if (mp[str[t]] <= pre)
			re += mp[str[t]];
		else
			re = re - 2 * pre + mp[str[t]];
		pre = str[t];
	}
	return re;
}

double BAS_DRAW_FUN::dms(double ddd)//度-》度分秒
{
	int d, m; double s;
	d = int(ddd + 0.000001);
	m = int((ddd - d + 0.000001) * 60.0);
	if (m < 0) m = 0;
	s = double(ddd - d) * 3600.0 - m * 60.0;
	if (s < 0) s = 0;
	return (d + m / 100.0 + s / 10000.0);
}

double BAS_DRAW_FUN::dms_rad(double rad)
{
	double d_ms, ddd;
	ddd = rad * 180.0 / PI;
	d_ms = dms(ddd);
	return (d_ms);
}

double  BAS_DRAW_FUN::Get_INDATA_L(double INDATA[5], int* jj)// 根据线元类型计算 L
{
	int j;
	double l = 0.0;
	j = (int)(INDATA[0] + 0.01);
	if (j == 1) l = INDATA[1];
	if (j == 2) l = INDATA[2];
	if (j == 3) //前缓
	{
		if (fabs(INDATA[2]) > 0.00001)
			l = INDATA[1] * INDATA[1] / INDATA[2];//A*A/R
		else
			l = 0.0;
	}

	if (j == 4)
	{
		if (fabs(INDATA[2]) > 0.00001)
			l = INDATA[1] * INDATA[1] / INDATA[2];
		else
			l = 0.0;
	}


	//   R1----> R2  (BIG---->SMALL)    of spiral
	//   A=INDATA[1];R1=INDATA[2];R2=INDATA[3];L1=A*A/R1;L2=A*A/R2;L=L2-L1;
	if (j == 5)
	{
		if (fabs(INDATA[2] * INDATA[3]) > 0.00001)
			l = INDATA[1] * INDATA[1] * (INDATA[2] - INDATA[3]) / (INDATA[2] * INDATA[3]);
		else
			l = 0.0;
	}

	//   R2----> R1  (SMALL---->big)             of spiral
	//    A=INDATA[1];R2=INDATA[2];R1=INDATA[3];L=A*A*(R2-R1)/R1/R2;L1=A*A/R1;L2=L1+L;ll=L1+l;
	if (j == 6)
	{
		if (fabs(INDATA[2] * INDATA[3]) > 0.00001)
			l = INDATA[1] * INDATA[1] * (INDATA[3] - INDATA[2]) / (INDATA[2] * INDATA[3]);
		else
			l = 0.0;
	}

	*jj = j;
	return l;
}

double BAS_DRAW_FUN::spiral_x(double A, double l)
{
	//	SpiralX ob;
	//	acutPrintf("X:%lf ",ob.SpiralGetX(A,l));

	if (A <= 0)return 0.0;
	double t = l * l / 2 / A / A;
	double sum = 0.0, dy = 0.0;
	int n = 0, max = 10;
	double c = 2 * A * A, dx = 0.0;
	for (n = 0; n < max; n++)
	{
		dx = pow(-1.0, n + 2) * pow(l, 4 * n + 1) / (4 * n + 1) / pow(c, 2 * n) / factorialfun(2 * n);//最后为阶乘
		sum += dx;
	}
	//	acutPrintf("  %lf\n",sum);
	//	AfxMessageBox("0");
	return sum;
}

double BAS_DRAW_FUN::spiral_y(double A, double l)
{
	//	SpiralY ob;
	//	acutPrintf("Y:%lf ",ob.SpiralGetY(A,l));

	if (A <= 0)return 0.0;
	double t = l * l / 2 / A / A;
	int n = 0, max = 10;
	double sum = 0.0, dy = 0.0;
	for (n = 1; n <= max; n++)
	{
		dy = pow(-1.0, n + 1) * pow(t, 0.5 * (4 * n - 1)) / (0.5 * (4 * n - 1)) / factorialfun(2 * n - 1);//最后为阶乘
		sum += dy;
	}
	sum = sum * A / sqrt(2.0);
	//	acutPrintf("  %lf\n",sum);
	//	AfxMessageBox("1");
	return sum;
}

long BAS_DRAW_FUN::factorialfun(int n)
{
	long result = 1;
	for (int i = 1; i < n + 1; i++)result *= i;
	return result;
}

int BAS_DRAW_FUN::xlzbxy(struct xlpoint* P0, struct xlpoint* PZ, double l, double INDATA[5], int display)
{
	double az, a0, aj, R, L, A, R1, R2, zy, L1, L2, ll, xm, ym, t1, t2, x, y;
	int type, re = 1;
	double ar1, ar2, ar, xr, yr, xr1, yr1, xr2, yr2;
	a0 = P0->a;//起始切线方位角
	type = (int)(INDATA[0] + 0.0001);//线元类型
	zy = INDATA[4];
	PZ->lc = P0->lc + l;
	switch (type)
	{
	case 1:    //   line
		PZ->x = P0->x + l * cos(a0);
		PZ->y = P0->y + l * sin(a0);
		PZ->a = P0->a; PZ->r = 1e40;
		break;
	case 2:   //    part of circle
		R = INDATA[1]; aj = l / R; az = a0 + zy * aj; t1 = R * tan(aj * .5); t2 = t1;
		xm = P0->x + t1 * cos(a0); ym = P0->y + t1 * sin(a0);
		PZ->x = xm + t2 * cos(az); PZ->y = ym + t2 * sin(az); PZ->a = az; PZ->r = R;
		break;
	case 3:   //    0=0--Ri-->R  l<=L&& Ri>R     of  spiral
		A = INDATA[1]; R = INDATA[2]; L = A * A / R; aj = l * l * .5 / R / L;
		x = spiral_x(A, l); y = spiral_y(A, l);
		t1 = x - y / tan(aj); t2 = y / sin(aj); az = a0 + aj * zy;
		xm = P0->x + t1 * cos(a0); ym = P0->y + t1 * sin(a0);
		PZ->x = xm + t2 * cos(az); PZ->y = ym + t2 * sin(az); PZ->a = az;
		if (l > 0) { PZ->r = A * A / l; }
		else { PZ->r = 1e40; };
		break;
	case 4:   //   R----> 0-0            of spiral
		A = INDATA[1]; R = INDATA[2]; L = A * A / R; ll = L - l;
		xr = spiral_x(A, L); yr = spiral_y(A, L);
		aj = ll * ll * .5 / R / L;
		x = spiral_x(A, ll); y = spiral_y(A, ll);
		az = P0->a + zy * L * .5 / R; PZ->a = az - zy * aj;
		if (ll > 0) { PZ->r = A * A / ll; }
		else { PZ->r = 1e40; };
		PZ->x = P0->x + (x - xr) * cos(az + PI) + (y - yr) * cos(az + PI - zy * .5 * PI);
		PZ->y = P0->y + (x - xr) * sin(az + PI) + (y - yr) * sin(az + PI - zy * .5 * PI);
		break;
	case 5:   //   R1----> R2  (BIG---->SMALL)    of spiral
		A = INDATA[1]; R1 = INDATA[2]; R2 = INDATA[3]; L1 = A * A / R1; L2 = A * A / R2;
		L = L2 - L1; ll = L1 + l;
		if (ll <= L2 + 0.01) {
			ar1 = L1 * .5 / R1; ar2 = L2 * .5 / R2; ar = ll * ll * .5 / R2 / L2; aj = ar - ar1;
			xr1 = spiral_x(A, L1); yr1 = spiral_y(A, L1);
			x = spiral_x(A, ll); y = spiral_y(A, ll);
			a0 = P0->a - zy * ar1; PZ->a = a0 + zy * ar;
			if (ll > 0) { PZ->r = A * A / ll; }
			else { PZ->r = 1e40; };
			PZ->x = P0->x + (x - xr1) * cos(a0) + (y - yr1) * cos(a0 + zy * .5 * PI);
			PZ->y = P0->y + (x - xr1) * sin(a0) + (y - yr1) * sin(a0 + zy * .5 * PI);
			re = 1;
		}
		else { re = 0; };
		break;
	case 6:   //   R2----> R1  (SMALL---->big)             of spiral
		A = INDATA[1]; R2 = INDATA[2]; R1 = INDATA[3]; L = A * A * (R1 - R2) / R1 / R2;
		L1 = A * A / R1; L2 = L1 + L; ll = L2 - l;
		if (ll <= L2) {
			ar1 = L1 * .5 / R1; ar2 = L2 * .5 / R2; ar = ll * ll * .5 / R2 / L2; aj = ar - ar1;
			xr2 = spiral_x(A, L2); yr2 = spiral_y(A, L2);
			x = spiral_x(A, ll); y = spiral_y(A, ll);
			az = P0->a + zy * ar2; PZ->a = az - zy * ar;
			if (ll > 0) { PZ->r = A * A / ll; }
			else { PZ->r = 1e40; };
			PZ->x = P0->x + (x - xr2) * cos(az + PI) + (y - yr2) * cos(az + PI - zy * .5 * PI);
			PZ->y = P0->y + (x - xr2) * sin(az + PI) + (y - yr2) * sin(az + PI - zy * .5 * PI);
			re = 1;
		}
		else { re = 0; };
		break;
	};
	if (PZ->a < 0.0) PZ->a = PZ->a + 2 * PI;
	if (PZ->a > 2 * PI) PZ->a = PZ->a - 2 * PI;
	return(re);
}

int  BAS_DRAW_FUN::xlpoint_pz(const double array2[][10], int trow2, struct xlpoint* PZ, int isprinttext)
{
	double l, dlc, lc;
	int i, j, k = 0, bz = -99;
	double INDATA2[5], jslc;
	struct xlpoint PB0, PEZ, * PBI, * PEI;
	PB0.lc = array2[0][4];
	PB0.x = array2[0][1];
	PB0.y = array2[0][2];
	PB0.a = rad(array2[0][3]);
	PB0.r = 1e40;
	dlc = array2[0][0];
	jslc = PZ->lc;
	PBI = &PB0; PEI = &PEZ;
	i = 0; bz = 99;
	if (jslc < PB0.lc + 0.0001)  //里程在起点里程之前
	{
		PZ->x = PB0.x;
		PZ->y = PB0.y;
		PZ->a = PB0.a;
		if (isprinttext == 1)
			AfxMessageBox(_T("1"));
		return 1;
	}
	if (jslc > array2[trow2][6] - 0.0001)  //里程在终点里程之后
	{
		PZ->a = array2[trow2][5];//线元起点方位角
		PZ->x = array2[trow2][8];  //x
		PZ->y = array2[trow2][9];  //y
		if (isprinttext == 1)
			AfxMessageBox(_T("2"));
		return 1;
	}
	do
	{
		i = i + 1;
		if (i >= trow2) bz = -99;
		if (bz > 0)
		{
			if (isprinttext == 1)
				AfxMessageBox(_T("3"));
			// 第 i 线元
			for (k = 0; k < 5; k++) INDATA2[k] = array2[i][k];
			l = Get_INDATA_L(INDATA2, &j);
			if (i == trow2 - 1)
				l += 0.1;//最后一个线元加一个毫米
			PBI->a = array2[i][5];

			////圆+线路长度为0
			//if( fabs(INDATA2[0]-2)<0.00001 && l<0.00000001 ) PZ->a = INDATA2[3];
			//if(l<0.00000001)
			//	return 1;

			PBI->lc = array2[i][6];
			PBI->r = array2[i][7];
			PBI->x = array2[i][8];
			PBI->y = array2[i][9];
			// l 为该线元的长度 m
			

			//	CCurvePokeCaluate a;
			//	PZ->lc= a.CalcmlTonewcml(PBI->lc,m_BZLC);
			// 
			//if (isprinttext == 1)
				//ads_printf(L"jslc=%lf %lf %lf\n", jslc, PBI->lc, l);

			if ((jslc <= PBI->lc + l) && (jslc >= PBI->lc - 0.0001)) // 考虑线元计算误差，增大0.0001m范围
				// 计算点在 i 线元上
			{

				lc = jslc - PBI->lc;

				if (lc <= 0.0) lc = 0.000000000001;
				xlzbxy(PBI, PZ, lc, INDATA2, 0);
				if (isprinttext == 1)
					//ads_printf(L"lc=%lf x=%lf,y=%lf\n", lc, PZ->x, PZ->y);

				k = 999;
				bz = -99;
			};
		}  // bz>0
	} while (bz > 0);

	if (k == 999) return j; //有解 j 为 线元类型
	else
	{
		return (-9); // 无解
	};
}

void BAS_DRAW_FUN::LCchr(ACHAR* GH, double lc, int NLC, ACHAR* ch, int mode)
{
	int ZFH = 1;
	long int zlc, gl;
	double bm;
	ACHAR  ch1[STR_NORMAL];
	if (lc < -0.001)
		ZFH = -1;
	lc = fabs(lc);
	if (lc > 1000000000)//里程超过1百万公里
	{
		_tcscpy(ch, GH);
		return;
	}
	bm = lc;
	zlc = (long int)((lc + 0.0005) / 1000.0);
	bm = bm - zlc * 1000.0;
	gl = zlc;

	//RY
	string tmp1 = to_string(gl);
	int len1 =(int)tmp1.length();
	char* str1 = new char[len1];
	for (int i = 0; i < len1; i++)
	{
		str1[i] = tmp1[i];
	}
	mbstowcs_s(0, ch1, len1, str1, _TRUNCATE);
	
	//ads_rtos(gl, 2, 0, (LPWSTR)ch1);
	_tcscpy(ch, GH);
	if (ZFH < 0)
		lstrcat(ch, L"-");
	lstrcat(ch, ch1);
	// lstrcat(ch,"+");
	if (bm < 0.00001)
		bm = 0;

	bm = bm + 1000.0;
	//	ACHAR  format[STR_NORMAL];
	//	_stprintf(format, L"%%0.%dlf", NLC);
	//	_stprintf(ch1, format, bm);

	//WXJ RY
	string tmp2 = to_string(bm);
	int len2 = (int)tmp2.length();
	char* str2 = new char[len2];
	for (int i = 0; i < len2; i++)
	{
		str2[i] = tmp2[i];
	}
	mbstowcs_s(0, ch1, len2, str2, _TRUNCATE);

	//ads_rtos(bm, 2, NLC, (LPWSTR)ch1);
	ch1[0] = '+';
	lstrcat(ch, ch1);
}

double   BAS_DRAW_FUN::ZXJ(double s2, double s1) const
{
	double s;
	s = s2 - s1;
	if (fabs(s) > PI)
	{
		if (s < 0.0) //偏角小于-PI
		{
			s = 2.0 * PI + s;
		}
		else      //偏角大于PI
		{
			s = s - 2.0 * PI;
		}
	}
	return(s);
}

////////////////////2010.3.18
double BAS_DRAW_FUN::PROJ_ML(double array2[][10], int trow2,
	double xout, double yout, double xon, double yon) const
{
	double x1, y1, x2, y2, x3, y3, x4, y4, s1, s2, s, ZJ, Alf1, Alf2, Alf, Xo, Yo, q, x, y, ZJ1, ZJ2, R;
	int i, kk[100], ii, xynum = 0;
	double LorR, X1[100], Y1[100], X2[100], Y2[100];
	double DistYCX = 1.0;

	double lc = array2[0][4];
	//起点向前延长1000m
	x2 = array2[0][1] + DistYCX * cos(rad(array2[0][3]) + PI);
	y2 = array2[0][2] + DistYCX * sin(rad(array2[0][3]) + PI);
	for (i = 1; i <= trow2; i++)
	{
		x1 = x2;
		y1 = y2;
		x2 = array2[i][8];
		y2 = array2[i][9];

		q = array2[i][0];
		// 	ads_printf(L"##x1=%lf,y1=%lf ,x2=%lf,y2=%lf,q=%lf\n",x1,y1,x2,y2,q);
		LorR = 1.0;
		/////////////////////////地铁将线路终点 线元属性赋为10
		if (q > 1.1 && q < 7.0)
		{
			LorR = array2[i][4];
		}
		//		ads_printf(L"%lf\n",array2[i][4]);
		if (i > 1)
			Alf1 = array2[i - 1][5];
		else
			Alf1 = rad(array2[i - 1][3]);

		Alf2 = array2[i][5];
		if (i == trow2)//终点向后延长1000m
		{
			//	ads_printf(L"Alf1=%lf Alf2=%lf\n",Alf1,Alf2);
			x2 = x2 + DistYCX * cos(Alf1);
			y2 = y2 + DistYCX * sin(Alf1);
		}
		x3 = x1 + 1000.0 * cos(0.5 * LorR * PI + Alf1);
		y3 = y1 + 1000.0 * sin(0.5 * LorR * PI + Alf1);

		x4 = x2 + 1000.0 * cos(0.5 * LorR * PI + Alf2);
		y4 = y2 + 1000.0 * sin(0.5 * LorR * PI + Alf2);

		s1 = GetSide(x3, y3, x1, y1, xon, yon);
		s2 = GetSide(x4, y4, x2, y2, xon, yon);

		if (s1 * s2 < 0.0001 || fabs(s1) < 0.00001 || fabs(s2) < 0.00001)
		{
			kk[xynum] = i;
			X1[xynum] = x1;
			Y1[xynum] = y1;
			X2[xynum] = x2;
			Y2[xynum] = y2;
			xynum++;//搜索出所有可能线元
		}
	}
	if (xynum == 0)
	{
		//ads_printf(L"指定点不在线路上(1)!\n");
		return -1.0;
	}
	double cml[100];
	for (i = 0; i < xynum; i++)
	{
		x1 = X1[i];
		y1 = Y1[i];
		x2 = X2[i];
		y2 = Y2[i];

		//搜索范围限制在kk-1-------kk段现元上
		if (kk[i] > 0)
		{
			q = array2[kk[i] - 1][0];
			LorR = array2[kk[i] - 1][4];//?左右转
		}
		else
		{
			q = array2[0][0];
			LorR = 0.0;//?左右转
		}
		//ads_printf(L"kk=%d,lc=%lf q=%lf %lf \n",kk,array2[kk][6],q,array2[kk-1][6]);
		//	LorR = 1;
		//	if(fabs(q) > 0.1)

		if (fabs(LorR) < 0.001)
			LorR = 1.0;

		if (kk[i] > 1)
			Alf1 = array2[kk[i] - 1][5];
		else
			Alf1 = rad(array2[kk[i] - 1][3]);

		Alf2 = array2[kk[i]][5];

		if (kk[i] > 1)
			lc = array2[kk[i] - 1][6];//当前线元起始里程

		if (q < 1.1)//直线
		{
			s1 = sqrt((xout - x1) * (xout - x1) + (yout - y1) * (yout - y1));
			xyddaa(x1, y1, xout, yout, &Alf2);
			ZJ = ZXJ(Alf2, Alf1);
			// 	ads_printf(L"ZJ=%lf Alf2=%lf Ald1=%lf\n",ZJ,Alf2,Alf1);
			cml[i] = lc + s1 * cos(ZJ);
		}
		else if (q < 2.1)//圆
		{
			R = array2[kk[i] - 1][1];

			Xo = array2[kk[i] - 1][8] + R * cos(array2[kk[i] - 1][5] + LorR * 0.5 * PI);
			Yo = array2[kk[i] - 1][9] + R * sin(array2[kk[i] - 1][5] + LorR * 0.5 * PI);


			s = 0.5 * (array2[kk[i]][6] - lc);
			x = x1 + s * cos(Alf1);
			y = y1 + s * sin(Alf1);
			xyddaa(Xo, Yo, xout, yout, &Alf);

			s1 = GetSide(x1, y1, Xo, Yo, x, y);
			s2 = GetSide(x1, y1, Xo, Yo, xout, yout);
			if (s1 * s2 < 0.001 || fabs(s1) < 0.00001 || fabs(s2) < 0.00001)
			{
				if (fabs(s2) < 0.001) // 20190603
				{
					//return array2[kk[i] - 1][6];
					cml[i] = array2[kk[i] - 1][6];
					continue;
				}
				else
					Alf = Alf + PI;
			}
			x = Xo + R * cos(Alf);
			y = Yo + R * sin(Alf);

			cml[i] = Circle_XY_to_ML(x, y, array2, kk[i] - 1);
		}
		else//缓和曲线
		{
			xyddaa(xout, yout, x1, y1, &Alf1);
			xyddaa(xout, yout, x2, y2, &Alf2);

			if (kk[i] > 1)
				ZJ1 = ZXJ(Alf1, array2[(kk[i]) - 1][5]);
			else
				ZJ1 = ZXJ(Alf1, rad(array2[(kk[i]) - 1][3]));

			ZJ2 = ZXJ(Alf2, array2[(kk[i])][5]);
			if (fabs(ZJ1 - 0.5 * PI) < 0.00001)
			{
				s = lc;
				return s;
			}
			else if (fabs(ZJ1) > 0.5 * PI)
				ii = 1;
			else
				ii = -1;

			s1 = lc;
			s2 = array2[(kk[i])][6];
		L20:
			s = 0.5 * (s1 + s2);
			cml[i] = s;
			struct xlpoint PZ;
			PZ.lc = s;
			xlpoint_pz(array2, trow2, &PZ);
			xyddaa(xout, yout, PZ.x, PZ.y, &Alf);
			ZJ = ZXJ(Alf, PZ.a);
			if ((ii == 1 && fabs(ZJ) > 0.5 * PI) || (ii == -1 && fabs(ZJ) < 0.5 * PI))
				s1 = s;
			else
				s2 = s;
			if (fabs(s2 - s1) > 0.00001)
				goto L20;
		}
	}
	//取出距离xon,yon的点
	double MinDis = 100000000000000.0, dist;
	for (i = 0; i < xynum; i++)
	{
		struct xlpoint PZ;
		PZ.lc = cml[i];
		xlpoint_pz(array2, trow2, &PZ);
		dist = sqrt((PZ.x - xon) * (PZ.x - xon) + (PZ.y - yon) * (PZ.y - yon));
		if (MinDis > dist)
		{
			s = cml[i];
			MinDis = dist;
		}
	}
	return s;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
//函数功能：判断两条线是否相交
//输入参数：两条线段的起终点
//输出参数：0为两条线直接相交，1为两条线的延长线相交，-1为两条线平行
int BAS_DRAW_FUN::INTERS(double* x, double* y, double X1, double Y1, double X2, double Y2, double X3, double Y3, double X4, double Y4)
{
	double A11, A12, A21, A22, B1, B2, D, D1, D2;
	int INF;
	double X1min, Y1min, X2min, Y2min, X1max, Y1max, X2max, Y2max;

	double dx = X1;
	double dy = Y1;
	X1 -= dx;
	Y1 -= dy;
	X2 -= dx;
	Y2 -= dy;
	X3 -= dx;
	Y3 -= dy;
	X4 -= dx;
	Y4 -= dy;

	A11 = Y2 - Y1;
	A12 = X1 - X2;
	A21 = Y4 - Y3;
	A22 = X3 - X4;
	B1 = X1 * Y2 - X2 * Y1;
	B2 = X3 * Y4 - X4 * Y3;
	D = A11 * A22 - A21 * A12;
	if (fabs(D) < 1.0E-6)
		INF = -1;
	else
	{
		D1 = B1 * A22 - B2 * A12;
		D2 = B2 * A11 - B1 * A21;

		*x = D1 / D;
		*y = D2 / D;
		X1min = min(X1, X2) - 0.00001;
		X1max = max(X1, X2) + 0.00001;
		Y1min = min(Y1, Y2) - 0.00001;
		Y1max = max(Y1, Y2) + 0.00001;
		X2min = min(X3, X4) - 0.00001;
		X2max = max(X3, X4) + 0.00001;
		Y2min = min(Y3, Y4) - 0.00001;
		Y2max = max(Y3, Y4) + 0.00001;

		if (X1min <= *x && *x <= X1max && Y1min <= *y && *y <= Y1max
			&& X2min <= *x && *x <= X2max
			&& Y2min <= *y && *y <= Y2max)
			INF = 0;
		else
			INF = 1;
	}

	*x += dx;
	*y += dy;

	return INF;
}

double BAS_DRAW_FUN::TYLC1(ACHAR ckml[STR_EXTEND], int NDL, DLBZ DLBTMP[STR_SHORT])
{
	//  由断链数据表 求某现场里程的统一里程
	double TLC = 0.0;
	double TLCtmp = 0.0;
	int iDL = 0;
	//起点里程
	double XLC;
	ACHAR GH[STR_MIN];
	split_ckml(ckml, &XLC, GH);
	TLC = XLC;

	CString strstr1, strstr2;
	short int numb = 0;//统计计算的连续里程的个数2005-08-26
	strstr1 = GH;
	strstr1.TrimLeft();
	strstr1.TrimRight();
	//strstr1.MakeLower();
	double continueLC = DLBTMP[0].BLC + DLBTMP[0].DL;//断链的统一里程
	for (iDL = 1; iDL < NDL; iDL++)
	{
		if ((DLBTMP[iDL - 1].BLC + DLBTMP[iDL - 1].DL - 0.00005 < XLC) && (XLC < DLBTMP[iDL].BLC + 0.00005))
		{
			strstr2 = DLBTMP[iDL - 1].EGH;
			strstr2.TrimLeft();
			strstr2.TrimRight();
			//strstr2.MakeLower();
			if (strstr1 == strstr2)
			{
				TLC = continueLC + XLC - DLBTMP[iDL - 1].BLC - DLBTMP[iDL - 1].DL;
				numb++;
			}
			else
			{
				strstr2 = DLBTMP[iDL].BGH;
				strstr2.TrimLeft();
				strstr2.TrimRight();
				//strstr2.MakeLower();
				if (strstr1 == strstr2)
				{
					TLC = continueLC + XLC - DLBTMP[iDL - 1].BLC - DLBTMP[iDL - 1].DL;
					numb++;
					strstr2.Format(L"第%d个断链的断后里程冠号%s与第%d个断链的断前里程冠号%s不一致,\n\n他将导致%s的计算不可靠",
						iDL - 1, DLBTMP[iDL - 1].EGH, iDL, DLBTMP[iDL].BGH, ckml);
					//AfxMessageBox(strstr2);
					//ads_printf(L"%s", strstr2);
				}
			}
		}
		continueLC = continueLC + DLBTMP[iDL].BLC - DLBTMP[iDL - 1].DL - DLBTMP[iDL - 1].BLC;
	}
	if (numb == 0)
	{
		if (XLC < DLBTMP[0].BLC + 0.00005)//在起点之外
		{
			strstr2 = DLBTMP[0].BGH;
			strstr2.TrimLeft();
			strstr2.TrimRight();
			//strstr2.MakeLower();
			if (strstr1 == strstr2)
			{
				TLC = DLBTMP[0].DL + XLC;
				numb++;
			}
		}
		else if (XLC > DLBTMP[iDL - 1].BLC + DLBTMP[iDL - 1].DL - 0.00005)
		{
			strstr2 = DLBTMP[iDL - 1].EGH;
			strstr2.TrimLeft();
			strstr2.TrimRight();
			//strstr2.MakeLower();
			if (strstr1 == strstr2)
			{
				TLC = continueLC + XLC - DLBTMP[iDL - 1].BLC - DLBTMP[iDL - 1].DL;
				numb++;
			}
		}
	}
	strstr1 = ckml;
	//if (numb > 1)
	//	AfxMessageBox("系统发现" + strstr1 + "在线路上有多个位置，可能是断链表数据有问题");
	//else if (numb == 0)
	//	AfxMessageBox("系统发现" + strstr1 + "在线路上没有其位置，可能是短链或断链表数据有问题");
	return TLC;
}

BOOL BAS_DRAW_FUN::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)
{
	//ADS
	// 导线法由导线数据文件求线位 L.SC.S.L.S.C.S.L...  得到线元文件
	double fb, fe, db, de, aa, c, lcb, lce, T0 = 0.0, interal = 18;
	ACHAR zy[STR_MIN];
	int i = 0, j = 0, k, color = 2, iq = 2;
	double BPMTL[10], T1, T2, L;
	double LCB, DDlength;
	int iDL = 0;
	double array_pxytmp[MAXJDNUM][4][5];// QXLRL[100][3];


	for (i = 0; i < 10; i++)
		BPMTL[i] = 0.0;
	for (i = 0; i < MAXJDNUM; i++)
	{
		for (k = 0; k < 4; k++)
		{
			for (j = 0; j < 5; j++)
				array_pxytmp[i][k][j] = 0.0;
		}
	}
	//起终点半径应为0    
	In_JDarray[0][4] = In_JDarray[In_NJD - 1][4] = In_JDarray[0][5] = In_JDarray[In_NJD - 1][5] = 0.0;

	db = xyddaa(In_JDarray[0][1], In_JDarray[0][2], In_JDarray[1][1], In_JDarray[1][2], &fb);
	//   In_JDarray[0][6]=fb;  
	lcb = In_JDarray[0][3];
	lce = lcb;
	fb = dms_rad(fb);
	array_pxytmp[0][0][0] = 10.0;
	// N(X)=ACAD_Y
	array_pxytmp[0][0][1] = In_JDarray[0][1];
	//E(Y)=ACAD_X
	array_pxytmp[0][0][2] = In_JDarray[0][2];
	// FA
	array_pxytmp[0][0][3] = fb;
	// LC
	array_pxytmp[0][0][4] = In_JDarray[0][3];
	//  DLB[0].BLC=In_JDarray[0][3];   DLB[0].DL=0.0;  NDL=1;   // 起点 作为一特殊断链点

	Out_QXB[0][0] = In_JDarray[0][3];  // 起点里程
	Out_QXB[0][1] = Out_QXB[0][0];
	Out_QXB[0][2] = Out_QXB[0][0];
	Out_QXB[0][3] = Out_QXB[0][0];
	Out_QXB[0][4] = Out_QXB[0][5] = Out_QXB[0][6] = Out_QXB[0][7] = Out_QXB[0][8] = 0.0;
	T0 = 0.0;
	if (In_NJD == 2) // 仅有两个交点,即一条直线时
	{
		array_pxytmp[1][0][0] = 1.0;
		array_pxytmp[1][0][1] = db;
	};

	LCB = Out_QXB[0][0]; // 起点里程
	DDlength = LCB;
	iDL = 1;
	double L01, L02;
	for (i = 1; i < In_NJD - 1; i++)
	{
		L01 = In_JDarray[i][3] < 1.0 ? 0.0 : In_JDarray[i][3];
		L02 = In_JDarray[i][5] < 1.0 ? 0.0 : In_JDarray[i][5];

		de = xyddaa(In_JDarray[i][1], In_JDarray[i][2], In_JDarray[i + 1][1], In_JDarray[i + 1][2], &fe);
		fe = dms_rad(fe);
		aa = rad(fe) - rad(fb);
		if (aa < -PI)
			aa = aa + 2 * PI;
		if (aa > PI)
			aa = aa - 2 * PI;
		if (aa > 0)
		{
			c = 1;
			_tcscpy(zy, L"y");
		}  //右偏
		else
		{
			c = -1;
			_tcscpy(zy, L"z");
		}//左偏
		aa = fabs(aa);
		aa = dms_rad(aa);
		//if (In_JDarray[i][4]<=0)
		//	break;
		getBPMTL(aa, In_JDarray[i][4], L01, L02, &BPMTL[0]);
		//		getBPMTL(aa,In_JDarray[i][4],In_JDarray[i][3],In_JDarray[i][5],&BPMTL[0]);
		T1 = BPMTL[6];
		T2 = BPMTL[7];
		L = BPMTL[8];

		//		if ( L<(In_JDarray[i][3]+In_JDarray[i][5]))
		if (L < (L01 + L02))
		{
			//return 0;
			//ads_printf(L"\n%d号曲线 前后缓和曲线重叠：缓长L1+L2=%10.3f>大于曲线长L=%10.3f ",i,In_JDarray[i][3]+In_JDarray[i][5],L);
		}
		//		else if((L-In_JDarray[i][3]-In_JDarray[i][5])<20.0)
		else if ((L - L01 - L02) < 20.0)
		{
			//return 0;
			//ads_printf(L"\n %d号曲线的(R=%8.1f)圆曲线长L=%10.3f 不足20m ",i,In_JDarray[i][4],L-In_JDarray[i][3]-In_JDarray[i][5]);
		}

		//曲线要数 角度为度.分秒
		Out_QXB[i][4] = aa;
		Out_QXB[i][5] = T1;
		Out_QXB[i][6] = T2;
		Out_QXB[i][7] = L;
		Out_QXB[i][8] = c;
		//  line
		array_pxytmp[i][0][0] = 1.0;
		array_pxytmp[i][0][1] = db - T1 - T0;

		//ZH (zy)
		Out_QXB[i][0] = Out_QXB[i - 1][3] + (db - T1 - T0);
		if ((db - T1 - T0) < 20.0)
		{
			//	ads_printf(L"\n %d号曲线起点ZH/ZY距前一曲线HZ/ZY距离=%-10.3f ",i+JD0-1,db-T1-T0);
			if ((db - T1 - T0) < 0)
			{
				//return 0;
				//ads_printf(L"超过前一曲线HZ/YZ不合法\n ");
			}
		}


		//		aa=sqrt(In_JDarray[i][3]*In_JDarray[i][4]);
		aa = sqrt(L01 * In_JDarray[i][4]);
		if (aa > 0.000000001)
		{
			array_pxytmp[i][1][0] = 3.0;
			array_pxytmp[i][1][1] = aa;
			//array_pxytmp[i][1][2]=QXLRL[i][1];
			array_pxytmp[i][1][2] = In_JDarray[i][4];
			array_pxytmp[i][1][3] = 0.0;
			array_pxytmp[i][1][4] = c;
		}
		// HY
		//		Out_QXB[i][1]=Out_QXB[i][0]+In_JDarray[i][3];
		Out_QXB[i][1] = Out_QXB[i][0] + L01;
		//  circle 
		//		aa=L-In_JDarray[i][3]-In_JDarray[i][5];
		aa = L - L01 - L02;
		if (aa > 0.000000001)
		{
			array_pxytmp[i][2][0] = 2.0;
			array_pxytmp[i][2][1] = In_JDarray[i][4];
			array_pxytmp[i][2][2] = aa;
			array_pxytmp[i][2][3] = 0.0;
			array_pxytmp[i][2][4] = c;
		}
		else//半径为0 转角要传递
		{
			array_pxytmp[i][2][0] = 2.0;  //性质
			array_pxytmp[i][2][1] = In_JDarray[i][4]; //R
			array_pxytmp[i][2][2] = aa; //yuan  chang 
			array_pxytmp[i][2][3] = rad(fe);

			array_pxytmp[i][2][4] = c;

		}
		// YH
		Out_QXB[i][2] = Out_QXB[i][1] + aa;
		//2-spiral
		//		aa=sqrt(In_JDarray[i][5]*In_JDarray[i][4]);
		aa = sqrt(L02 * In_JDarray[i][4]);
		if (aa > 0.000000001)
		{
			array_pxytmp[i][3][0] = 4.0;
			array_pxytmp[i][3][1] = aa;
			array_pxytmp[i][3][2] = In_JDarray[i][4];
			array_pxytmp[i][3][3] = 0.0;
			array_pxytmp[i][3][4] = c;
		}
		// HZ
		//		Out_QXB[i][3]=Out_QXB[i][2]+In_JDarray[i][5];
		Out_QXB[i][3] = Out_QXB[i][2] + L02;
		db = de;
		lcb = lce;
		fb = fe;
		T0 = T2;
	}
	//  line
	db = db - T0;
	if (db > 0.0000000001)
	{
		array_pxytmp[In_NJD - 1][0][0] = 1.0;
		array_pxytmp[In_NJD - 1][0][1] = db;
	}

	// 终点里程
	Out_QXB[In_NJD - 1][0] = Out_QXB[In_NJD - 2][3] + db;
	Out_xllen = Out_QXB[In_NJD - 1][0] - Out_QXB[0][0];
	Out_QXB[In_NJD - 1][1] = Out_QXB[In_NJD - 1][0];
	Out_QXB[In_NJD - 1][2] = Out_QXB[In_NJD - 1][0];
	Out_QXB[In_NJD - 1][3] = Out_QXB[In_NJD - 1][0];
	Out_QXB[In_NJD - 1][4] = Out_QXB[In_NJD - 1][5] = Out_QXB[In_NJD - 1][6] = Out_QXB[In_NJD - 1][7] = Out_QXB[In_NJD - 1][8] = 0.0;
	// 修改终点特殊断链点里程 (终点 作为一特殊断链点)

// 	_tcscpy(Sgh,DLB[NDL-1].BGH);
// 	_tcscpy(Egh,DLB[NDL-1].EGH);//修改终点断链冠号  2004.7.16
// 	lcb = XLC(Out_QXB[In_NJD-1][0],DLB[NDL-1].BGH,NDL-1);//2005-12-16
// 	if (_tcscmp(DLB[NDL-1].BGH,DLB[NDL-1].EGH) != 0 || fabs(DLB[NDL-1].DL) > 0.00001)
// 		lce = DLB[NDL-1].BLC + DLB[NDL-1].DL;//2005-12-16
// 	else
// 		lce = lcb;		
// 	setDLM(NDL-1,lcb,lce-lcb,Sgh,Egh); 	 
	//  起点
	double INDATA[5], l, L0;
	struct xlpoint PB0, PEZ;
	for (j = 0; j < 5; j++)
		Out_array[0][j] = array_pxytmp[0][0][j];
	Out_tarray = 1;
	///////除去起终交点 每个交点四个线元  ( 在只有圆曲线 没有 缓和曲线时  只有两个线元)
	for (i = 1; i < In_NJD - 1; i++)
	{
		for (k = 0; k < 4; k++)
		{
			for (j = 0; j < 5; j++)
				INDATA[j] = array_pxytmp[i][k][j];
			j = (int)(INDATA[0] + 0.01);
			l = 0.0;
			if (j == 1)
				l = INDATA[1];
			else if (j == 2)
				l = INDATA[2];
			else if (j == 3 || j == 4)
			{
				if (fabs(INDATA[2]) > 0.000001)
					l = INDATA[1] * INDATA[1] / INDATA[2];
				else
					l = 0.0;
			}
			else if (j == 5)
			{
				if (fabs(INDATA[2] * INDATA[3]) > 0.000001)
					l = INDATA[1] * INDATA[1] * (INDATA[2] - INDATA[3]) / (INDATA[2] * INDATA[3]);
				else
					l = 0.0;
			}
			else if (j == 6)
			{
				if (fabs(INDATA[2] * INDATA[3]) > 0.000001)
					l = INDATA[1] * INDATA[1] * (INDATA[3] - INDATA[2]) / (INDATA[2] * INDATA[3]);
				else
					l = 0.0;
			}
			// 求L0=？
			L0 = l;
			if (j == 2)
				L0 = INDATA[1];
			//		   ads_printf(L"l=%lf\n",l);
			if (L0 > 0.001)
			{
				for (int kk = 0; kk < 5; kk++)
					Out_array[Out_tarray][kk] = array_pxytmp[i][k][kk];
				if (j == 1)//直线
				{
					db = xyddaa(In_JDarray[i - 1][1], In_JDarray[i - 1][2], In_JDarray[i][1], In_JDarray[i][2], &fb);
					Out_array[Out_tarray][5] = fb;
					Out_array[Out_tarray][6] = Out_QXB[i - 1][3];
					Out_array[Out_tarray][7] = 1e40;
					Out_array[Out_tarray][8] = In_JDarray[i - 1][1] + Out_QXB[i - 1][6] * cos(fb);
					Out_array[Out_tarray][9] = In_JDarray[i - 1][2] + Out_QXB[i - 1][6] * sin(fb);
				}
				// ads_printf(L"\n %1.0f %10.3f %10.3f %1.0f",Out_array[trow][0],Out_array[trow][1],Out_array[trow][2],Out_array[trow][4]);
				Out_tarray = Out_tarray + 1;
			};
		};
	};
	//  终点
	for (j = 0; j < 5; j++)Out_array[Out_tarray][j] = array_pxytmp[In_NJD - 1][0][j];
	if (In_NJD > 2)
	{
		i = In_NJD - 1;
		db = xyddaa(In_JDarray[i - 1][1], In_JDarray[i - 1][2], In_JDarray[i][1], In_JDarray[i][2], &fb);
		Out_array[Out_tarray][5] = fb;
		Out_array[Out_tarray][6] = Out_QXB[i - 1][3];
		Out_array[Out_tarray][7] = 1e40;
		Out_array[Out_tarray][8] = In_JDarray[i - 1][1] + Out_QXB[i - 1][6] * cos(fb);
		Out_array[Out_tarray][9] = In_JDarray[i - 1][2] + Out_QXB[i - 1][6] * sin(fb);
	}

	Out_tarray = Out_tarray + 1;
	i = 0;
	PB0.lc = Out_array[0][4];
	PB0.x = Out_array[0][1];
	PB0.y = Out_array[0][2];
	PB0.a = rad(Out_array[0][3]);
	PB0.r = 1e40;
	Out_array[1][5] = PB0.a;
	Out_array[1][6] = PB0.lc;
	Out_array[1][7] = PB0.r;
	Out_array[1][8] = PB0.x;
	Out_array[1][9] = PB0.y;
	for (i = 1; i < Out_tarray; i++)
	{
		// 第 i 线元
		for (k = 0; k < 5; k++)
			INDATA[k] = Out_array[i][k];

		j = (int)(Out_array[i + 1][0] + 0.0001);
		if (j == 1)//下一单元是直线 
		{
			PB0.a = Out_array[i + 1][5];
			PB0.lc = Out_array[i + 1][6];
			PB0.r = Out_array[i + 1][7];
			PB0.x = Out_array[i + 1][8];
			PB0.y = Out_array[i + 1][9];
		}
		else
		{
			l = Get_INDATA_L(INDATA, &j);
			xlzbxy(&PB0, &PEZ, l, INDATA, 0);
			Out_array[i + 1][5] = PEZ.a;
			//if( fabs(array_pxytmp[i][2][0]-2)<0.00001 && l<0.00000001 ) Out_array[i+1][5] = INDATA[3];
			Out_array[i + 1][6] = PEZ.lc;
			Out_array[i + 1][7] = PEZ.r;//线元起点的半径,直圆\圆直为无穷大
			Out_array[i + 1][8] = PEZ.x;
			Out_array[i + 1][9] = PEZ.y;
			PB0 = PEZ;
		}
	}
	xlpoint PZ1;
	PZ1.lc = Out_QXB[In_NJD - 1][0];
	xlpoint_pz(Out_array, Out_tarray, &PZ1);

	/////////////////////////////线路终点线元属性 为10时  有可能投影函数投影不到
	Out_array[Out_tarray][0] = 10;
	Out_array[Out_tarray][1] = PZ1.x;
	Out_array[Out_tarray][2] = PZ1.y;
	Out_array[Out_tarray][3] = PZ1.a;
	Out_array[Out_tarray][4] = PZ1.lc;

	// 	StartCml = Out_QXB[0][0];
	// 	EndCml = Out_QXB[In_NJD-1][0];
	// 	double xlc=XLC(StartCml,GH,NDL);
	// 	_tcscpy(StartCKml,L"\0");
	// 	_tcscpy(StartCKml,LCchr(GH,xlc,NLC,1));
	// 	xlc=XLC(EndCml,GH,NDL);
	// 	_tcscpy(EndCKml,L"\0");
	// 	_tcscpy(EndCKml,LCchr(GH,xlc,NLC,1));
		//	acutPrintf("\n命令:");//plh07.19a

		/////////////////////////////临时用输出线元数组
	return 1;

}

//初始化道岔结构体
void BAS_DRAW_FUN::ChushiHuaDaochaData(Switch& DaochaData)
{
	_tcscpy(DaochaData.BianHao, L"");             //道岔内部编号
	_tcscpy(DaochaData.SuoshuDXBianHao, L"");             //所属渡线编号
	_tcscpy(DaochaData.DXGDBH, L"");
	DaochaData.SwitchNum = 0;        //道岔号数
	DaochaData.SwitchType = 1;        //道岔类型1.普通单开2.对称双开3.对称三开4.交分5.菱形交叉
	_tcscpy(DaochaData.InTrackNo, L"");         //a端所在股道(基线)编号
	_tcscpy(DaochaData.InTrackNo_b, L"");         //b端所在股道(基线)编号
	for (int i = 0; i < 4; i++)
		_tcscpy(DaochaData.OutTrackNo[i], L"");

	_tcscpy(DaochaData.TrackType, L"");      //钢轨类型：43、50、60、75kg
	_tcscpy(DaochaData.CZType, L"");             //岔枕类型：混凝土枕和木枕
	_tcscpy(DaochaData.TH, L"");                    //图号
	_tcscpy(DaochaData.SJST, L"");                //设计时态：既有/新建/预留/在建
	_tcscpy(DaochaData.BianHaoZT, L"");       //编号字头
	DaochaData.BZBianHao = 1;             //道岔标注编号
	DaochaData.JYBZBianHao = 1;             //道岔标注编号
	for (int i = 0; i < 7; i++)
	{
		DaochaData.XYArray[i];
	}
	//道岔线元数组
	DaochaData.chaxinLc = 0;
	DaochaData.duxiantype = 0;
	for (int i = 0; i < 7; i++)
	{
		for (int j = 0; j < 8; j++)
		{
			DaochaData.XYArraysddx[i][j] = 0;
		}

	}
	DaochaData.isduxian = 0;//是否渡线
	DaochaData.SdDxCanshu.m_R1;
	DaochaData.SdDxCanshu.m_CHJZXL1;
	DaochaData.SdDxCanshu.m_JZXL;
	DaochaData.SdDxCanshu.m_R2;
	DaochaData.SdDxCanshu.m_CHJZXL2;
	DaochaData.SdDxCanshu.m_XJJ;
	DaochaData.a = 0;
	DaochaData.b = 0;
	DaochaData.DaoquxianR = 0;
	//ACHAR CZTYPE[STR_SHORT];//岔枕类型
	DaochaData.m_Vz = 0;//直向速度
	DaochaData.m_VC = 0;//侧向速度
	DaochaData.m_Lq = 0; //道岔全长
	DaochaData.L1 = 0;//跟端至末根岔枕距离
	DaochaData.MaiRuVperDaoCha = 0;//每组道岔埋入体积
	DaochaData.m_ischeck = 1;
	DaochaData.m_IsChaiChu = 0;
	DaochaData.m_IsJYGaiYi = 0;

#ifdef ZCCSU
	DaochaData.m_isdrawJYBH = 1;
#else
	DaochaData.m_isdrawJYBH = 0;
#endif
	DaochaData.m_isdrawSJBH = 1;
	DaochaData.BZStyle = L"1编号";
	_tcscpy(DaochaData.CZJXStrArray, L"");
	DaochaData.XYNum = 0;
	DaochaData.SdDxCanshu.m_R1 = 0;
	DaochaData.SdDxCanshu.m_R2 = 0;
	DaochaData.SdDxCanshu.m_L01 = 0;
	DaochaData.SdDxCanshu.m_L02 = 0;
	DaochaData.SdDxCanshu.m_CHJZXL1 = 0;
	DaochaData.SdDxCanshu.m_CHJZXL2 = 0;
	DaochaData.SdDxCanshu.m_XJJ = 0;
	DaochaData.SdDxCanshu.m_JZXL = 0;
	DaochaData.q = 0;
	DaochaData.dist = 0;
	_tcscpy(DaochaData.Ckml, L"");
	DaochaData.m_LianSuo = 1;

	_tcscpy(DaochaData.PurposeDCBH, L"");
	_tcscpy(DaochaData.PurposeDCDesBH, L"");
}
int BAS_DRAW_FUN::ReadWorkdir()
{
	FILE* fp = NULL;
	CString  fname;
	//ACHAR str[STR_LONG];
	CString m_dirstr;
	CString chezhanname;
	return 1;
}
//道岔侧股方位角处理，当为四个道岔的渡线时，求出当前道岔侧股的真实方位角向量
bool BAS_DRAW_FUN::DaoChaCeGuFangWeiJiaoChuLi(double SingleXY[9], DVec3d& vec_CeGu)
{
	bool isSuccess = false;
	//首先根据道岔方位角计算向量
	DVec3d vec;//道岔直股方位角
	vec = calfwjvec(SingleXY[3]);
	vec.Normalize();
	DVec3d vec_Z;
	vec_Z.Init(0, 0, 1);
	DVec3d vec1, vec2;//道岔可能的侧股方位角
	vec1 = vec;
	vec2 = vec;
	//vec1 = vec1.RotateXY(SingleXY[1], DVec3d::AngleAndAxisOfRotationFromVectorToVector);
	//vec2 = vec2.RotateXY ((-1.0 * SingleXY[1]), DVec3d::AngleAndAxisOfRotationFromVectorToVector);
	//取出四个道岔中的另外三个道岔岔心点
	vector<DPoint3d> PtArray_ChaXin;
	PtArray_ChaXin.clear();
	DPoint3d Pt;//当前道岔的岔心点坐标
	Pt.Init(SingleXY[6], SingleXY[5], 0);
	for (int i = 0; i < m_DaochaDate.size(); i++)
	{
		DPoint3d Pt1;
		Pt1.Init(m_DaochaDate[i].XYArray[6], m_DaochaDate[i].XYArray[5], 0);
		if (Pt1.DistanceXY(Pt) < 0.001)//说明岔心点重合，是同一个道岔
			continue;
		else
			PtArray_ChaXin.push_back(Pt1);
	}
	//计算当前道岔与其余三个道岔连线的方位角向量
	vector<DVec3d> vecArray;
	vecArray.clear();
	for (int i = 0; i < PtArray_ChaXin.size(); i++)
	{
		DVec3d vecTemp;
		vecTemp = PtArray_ChaXin[i] - Pt;
		vecTemp.Normalize();
		vecArray.push_back(vecTemp);
	}
	//如果这三个向量中有一个向量与当前道岔可能存在的两个侧股向量相同，则返回成功，并返回该向量
	for (int i = 0; i < vecArray.size(); i++)
	{
		if ((vecArray[i].AngleTo(vec1) < 0.0001) || (vecArray[i].AngleTo(vec2) < 0.0001))
		{
			isSuccess = true;
			vec_CeGu = vecArray[i];
		}
	}
	vec_CeGu.Normalize();
	return isSuccess;
}
BOOL BAS_DRAW_FUN::GetSingleSwitchCoordinate1(double SingleXY[9], DPoint3d& StaPt, DPoint3d& End1, DPoint3d& End2, DPoint3d& End3, DPoint3d& End4, int isDaoChaNum4)
{
	int XYType = (int)(SingleXY[0] + 0.01);
	if (XYType == 1)//单开道岔
	{
		if (isDaoChaNum4 == 1)//说明是四个道岔的渡线
		{
			DVec3d vec_CeGu;//道岔侧股方位角向量
			bool isSuccess = false;
			isSuccess = DaoChaCeGuFangWeiJiaoChuLi(SingleXY, vec_CeGu);
			if (isSuccess == true)
			{
				DPoint3d Pt_ChaXin, End;
				Pt_ChaXin.Init(SingleXY[6], SingleXY[5], 0);
				End = Pt_ChaXin + vec_CeGu * SingleXY[8];
				//计算支线边终点	    
				End2.x = SingleXY[6] + SingleXY[8] * sin(SingleXY[3] + SingleXY[1] * SingleXY[2] * SingleXY[4]);
				End2.y = SingleXY[5] + SingleXY[8] * cos(SingleXY[3] + SingleXY[1] * SingleXY[2] * SingleXY[4]);
				End2.z = 0;
				if (End.DistanceXY(End2) > 0.01)//说明两者计算结果不一致
					SingleXY[2] *= -1;
			}
			////首先根据道岔方位角计算向量
			//AcGeVector3d vec;//道岔直股方位角
			//vec = BAS_DRAW_FUN.calfwjvec(SingleXY[3]);
			//vec.normalize();
			//AcGeVector3d vec_Z;
			//vec_Z.set(0,0,1);
			//AcGeVector3d vec1,vec2;//道岔可能的侧股方位角
			//vec1 = vec;
			//vec2 = vec;
			//vec1 = vec1.rotateBy(SingleXY[1],AcGeVector3d::kZAxis);
			//vec2 = vec2.rotateBy((-1.0 * SingleXY[1]),AcGeVector3d::kZAxis);
		}

		//计算直线边起点
		StaPt.x = SingleXY[6] - SingleXY[7] * sin(SingleXY[3]);
		StaPt.y = SingleXY[5] - SingleXY[7] * cos(SingleXY[3]);
		StaPt.z = 0;

		//计算直线边终点
		End1.x = SingleXY[6] + SingleXY[8] * sin(SingleXY[3]);
		End1.y = SingleXY[5] + SingleXY[8] * cos(SingleXY[3]);
		End1.z = 0;

		//计算支线边终点	    
		End2.x = SingleXY[6] + SingleXY[8] * sin(SingleXY[3] + SingleXY[1] * SingleXY[2] * SingleXY[4]);
		End2.y = SingleXY[5] + SingleXY[8] * cos(SingleXY[3] + SingleXY[1] * SingleXY[2] * SingleXY[4]);
		End2.z = 0;

		End3 = End2;
		End4 = End2;
	}
	else if (XYType == 2)//对称双开道岔
	{
		//计算起点
		StaPt.x = SingleXY[6] - SingleXY[7] * sin(SingleXY[3]);
		StaPt.y = SingleXY[5] - SingleXY[7] * cos(SingleXY[3]);
		StaPt.z = 0;

		//计算左偏终点
		End1.x = SingleXY[6] + SingleXY[8] * sin(SingleXY[3] - SingleXY[1] / 2.0);
		End1.y = SingleXY[5] + SingleXY[8] * cos(SingleXY[3] - SingleXY[1] / 2.0);
		End1.z = 0;

		//计算右偏终点	    
		End2.x = SingleXY[6] + SingleXY[8] * sin(SingleXY[3] + SingleXY[1] / 2.0);
		End2.y = SingleXY[5] + SingleXY[8] * cos(SingleXY[3] + SingleXY[1] / 2.0);
		End2.z = 0;

		End3 = End2;
		End4 = End2;
	}
	else if (XYType == 3)//对称三开道岔
	{
		//计算起点
		StaPt.x = SingleXY[6] - SingleXY[7] * sin(SingleXY[3]);
		StaPt.y = SingleXY[5] - SingleXY[7] * cos(SingleXY[3]);
		StaPt.z = 0;

		//计算直线边终点
		End1.x = SingleXY[6] + SingleXY[8] * sin(SingleXY[3]);
		End1.y = SingleXY[5] + SingleXY[8] * cos(SingleXY[3]);
		End1.z = 0;

		//计算左偏终点
		End2.x = SingleXY[6] + SingleXY[8] * sin(SingleXY[3] - SingleXY[1]);
		End2.y = SingleXY[5] + SingleXY[8] * cos(SingleXY[3] - SingleXY[1]);
		End2.z = 0;

		//计算右偏终点	    
		End3.x = SingleXY[6] + SingleXY[8] * sin(SingleXY[3] + SingleXY[1]);
		End3.y = SingleXY[5] + SingleXY[8] * cos(SingleXY[3] + SingleXY[1]);
		End3.z = 0;

		End4 = End3;
	}
	else if (XYType == 4 || XYType == 5)//交分道岔或菱形交叉
	{
		if (isDaoChaNum4 == 1)//说明是四个道岔的渡线
		{
			DVec3d vec_CeGu;//道岔侧股方位角向量
			bool isSuccess = false;
			isSuccess = DaoChaCeGuFangWeiJiaoChuLi(SingleXY, vec_CeGu);
			if (isSuccess == true)
			{
				DPoint3d Pt_ChaXin, End;
				Pt_ChaXin.Init(SingleXY[6], SingleXY[5], 0);
				End = Pt_ChaXin + vec_CeGu * SingleXY[8];
				//计算支线边终点	    
				End2.x = SingleXY[6] + SingleXY[8] * sin(SingleXY[3] + SingleXY[1] * SingleXY[2] * SingleXY[4]);
				End2.y = SingleXY[5] + SingleXY[8] * cos(SingleXY[3] + SingleXY[1] * SingleXY[2] * SingleXY[4]);
				End2.z = 0;
				if (End.DistanceXY(End2) > 0.01)//说明两者计算结果不一致
					SingleXY[2] *= -1;
			}
			////首先根据道岔方位角计算向量
			//AcGeVector3d vec;//道岔直股方位角
			//vec = BAS_DRAW_FUN.calfwjvec(SingleXY[3]);
			//vec.normalize();
			//AcGeVector3d vec_Z;
			//vec_Z.set(0,0,1);
			//AcGeVector3d vec1,vec2;//道岔可能的侧股方位角
			//vec1 = vec;
			//vec2 = vec;
			//vec1 = vec1.rotateBy(SingleXY[1],AcGeVector3d::kZAxis);
			//vec2 = vec2.rotateBy((-1.0 * SingleXY[1]),AcGeVector3d::kZAxis);
		}
		StaPt.x = SingleXY[6] - (SingleXY[8] / cos(SingleXY[1] / 2) + SingleXY[7] / cos(SingleXY[1] / 2)) * sin(SingleXY[3]);
		StaPt.y = SingleXY[5] - (SingleXY[8] / cos(SingleXY[1] / 2) + SingleXY[7] / cos(SingleXY[1] / 2)) * cos(SingleXY[3]);
		StaPt.z = 0;

		//计算直线边终点
		End1.x = SingleXY[6] + (SingleXY[8] / cos(SingleXY[1] / 2) + SingleXY[7] / cos(SingleXY[1] / 2)) * sin(SingleXY[3]);
		End1.y = SingleXY[5] + (SingleXY[8] / cos(SingleXY[1] / 2) + SingleXY[7] / cos(SingleXY[1] / 2)) * cos(SingleXY[3]);
		End1.z = 0;

		//计算支线边终点	    
		End2.x = SingleXY[6] + (SingleXY[8] / cos(SingleXY[1] / 2) + SingleXY[7] / cos(SingleXY[1] / 2)) * sin(SingleXY[3] + SingleXY[1] * SingleXY[2] * SingleXY[4]);
		End2.y = SingleXY[5] + (SingleXY[8] / cos(SingleXY[1] / 2) + SingleXY[7] / cos(SingleXY[1] / 2)) * cos(SingleXY[3] + SingleXY[1] * SingleXY[2] * SingleXY[4]);
		End2.z = 0;

		//计算支线边终点	    
		End3.x = SingleXY[6] - (SingleXY[8] / cos(SingleXY[1] / 2) + SingleXY[7] / cos(SingleXY[1] / 2)) * sin(SingleXY[3] + SingleXY[1] * SingleXY[2] * SingleXY[4]);
		End3.y = SingleXY[5] - (SingleXY[8] / cos(SingleXY[1] / 2) + SingleXY[7] / cos(SingleXY[1] / 2)) * cos(SingleXY[3] + SingleXY[1] * SingleXY[2] * SingleXY[4]);
		End3.z = 0;

		End4 = End3;

		////计算顺向左偏终点
		//End1.x = SingleXY[6] +SingleXY[7]*sin(SingleXY[3]-SingleXY[1]/2.0);
		//End1.y = SingleXY[5] +SingleXY[7]*cos(SingleXY[3]-SingleXY[1]/2.0);
		//End1.z = 0; 
		////计算顺向右偏终点
		//End2.x = SingleXY[6] +SingleXY[7]*sin(SingleXY[3]+SingleXY[1]/2.0);
		//End2.y = SingleXY[5] +SingleXY[7]*cos(SingleXY[3]+SingleXY[1]/2.0);
		//End2.z = 0; 

		////计算逆向左偏终点
		//End3.x = SingleXY[6] +SingleXY[7]*sin(SingleXY[3]-SingleXY[1]/2.0+pi);
		//End3.y = SingleXY[5] +SingleXY[7]*cos(SingleXY[3]-SingleXY[1]/2.0+pi);
		//End3.z = 0; 

		////计算逆向右偏终点	    
		//End4.x = SingleXY[6] +SingleXY[7]*sin(SingleXY[3]+SingleXY[1]/2.0+pi);
		//End4.y = SingleXY[5] +SingleXY[7]*cos(SingleXY[3]+SingleXY[1]/2.0+pi);
		//End4.z = 0; 
	}
	else
	{
		return FALSE;
	}
	return TRUE;

}
DVec3d BAS_DRAW_FUN::calfwjvec(double fwj)
{
	//将方位角控制在0-z*pi
	//for (;  fabs(fwj) > 2 * pi;)
	{
		if (fwj < -0.000001)
			fwj += 2 * pi;
		else if (fwj > 2 * pi - 0.00001)
			fwj -= 2 * pi;
	}
	DVec3d vec = DVec3d::From(1, 0, 0);
	if (fabs(fwj) < 0.0001 || fabs(fwj - 2 * pi) < 0.0001)
		vec.Init(0, 1, 0);
	else if (fabs(fwj - pi / 2.0) < 0.0001)
		vec.Init(1, 0, 0);
	else if (fabs(fwj - pi) < 0.0001)
		vec.Init(0, -1, 0);
	else if (fabs(fwj - 3.0 * pi / 2.0) < 0.0001)
		vec.Init(-1, 0, 0);
	else if (fwj > 0 && fwj < pi / 2.0)
		vec.Init(sin(fwj), cos(fwj), 0);
	else if (fwj<pi && fwj>pi / 2.0)
		vec.Init(cos(fwj - pi / 2.0), -1.0 * sin(fwj - pi / 2.0), 0);
	else if (fwj > pi && fwj < 3.0 * pi / 2.0)
		vec.Init(-1.0 * sin(fwj - pi), -1.0 * cos(fwj - pi), 0);
	else if (fwj < 2 * pi && fwj>3.0 * pi / 2.0)
		vec.Init(-1.0 * sin(2 * pi - fwj), cos(2 * pi - fwj), 0);

	vec.Normalize();
	return vec;
}
//void createAProjectedSolid(DPoint3dCR basePt)
//{
//	DPoint3d  pts[6];
//	pts[0] = basePt;
//	pts[1].x = pts[0].x;               pts[1].y = pts[0].y - g_1mu / 2;   pts[1].z = pts[0].z;
//	pts[2].x = pts[1].x + g_1mu / 2;   pts[2].y = pts[1].y;               pts[2].z = pts[0].z;
//	pts[3].x = pts[2].x;               pts[3].y = pts[2].y - g_1mu / 2;   pts[3].z = pts[0].z;
//	pts[4].x = pts[3].x + g_1mu / 2;   pts[4].y = pts[3].y;               pts[4].z = pts[0].z;
//	pts[5].x = pts[4].x;               pts[5].y = pts[0].y;               pts[5].z = pts[0].z;
//
//	CurveVectorPtr pCurveVec = CurveVector::CreateLinear(pts, 6, CurveVector::BOUNDARY_TYPE_Outer);
//	DVec3d extrusionVec = DVec3d::From(0, 0, g_1mu);
//	DgnExtrusionDetail  data(pCurveVec, extrusionVec, true);
//	ISolidPrimitivePtr pSolid = ISolidPrimitive::CreateDgnExtrusion(data);
//	EditElementHandle eeh;
//	DraftingElementSchema::ToElement(eeh, *pSolid, nullptr, *ACTIVEMODEL);
//	eeh.AddToModel();
//}

int BAS_DRAW_FUN::mscmp2(ACHAR atmp[], ACHAR btmp[])
{
	CString a;
	CString b;
	a = atmp;
	b = btmp;
	a.MakeUpper();
	b.MakeUpper();

	if (a.GetAt(0) > b.GetAt(0))
		return 1;
	else if (a.GetAt(0) < b.GetAt(0))
		return -1;
	else
	{
		CString alphabet1;
		CString alphabet2;
		alphabet1 = a;
		alphabet1.Replace(L"\\d+$", L"");
		alphabet2 = b;
		alphabet2.Replace(L"\\d+$", L"");
		int cmpAlphabet = alphabet1.CompareNoCase(alphabet2);
		if (cmpAlphabet != 0)
			return cmpAlphabet;

		CString numeric1;
		CString numeric2;
		numeric1 = a;
		numeric1.Replace(L"^[a-zA-Z]+", L"");
		numeric2 = b;
		numeric2.Replace(L"^[a-zA-Z]+", L"");

		if (numeric1 == L"")
			return -1;
		if (numeric2 == L"")
			return 1;
		int result = _wtoi(numeric1) - _wtoi(numeric2);
		return result;
	}
}

double BAS_DRAW_FUN::xyddaa(double xb, double yb, double xe, double ye, double& f)
{
	double dx, dy, dd, aa;

	dx = xe - xb; dy = ye - yb; dd = sqrt(dx * dx + dy * dy);
	if (fabs(dx) < 0.000001) {
		if (dy >= 0.0) aa = PI * 0.5;
		else /*if (dy<-0.000000000000001)*/ aa = PI * 1.5;
		f = aa;
		return(dd);
	}
	else { aa = atan(dy / dx); };

	if (dy >= 0 && dx < 0) { aa = aa + PI; }
	else if (dy < 0 && dx < 0) { aa = aa + PI; }
	else if (dy < 0 && dx>0) { aa = aa + 2 * PI; };
	if (aa < 0) { aa = aa + 2 * PI; }
	else if (aa > 2 * PI) { aa = aa - 2 * PI; };
	f = aa;
	return(dd);
}
double BAS_DRAW_FUN::xyddaa(double xb, double yb, double xe, double ye, double* f)
{
	double dx, dy, dd, aa;

	dx = xe - xb; dy = ye - yb; dd = sqrt(dx * dx + dy * dy);
	if (fabs(dx) < 0.000001) {
		if (dy >= 0.0) aa = PI * 0.5;
		else /*if (dy<-0.000000000000001)*/ aa = PI * 1.5;
		*f = aa;
		return(dd);
	}
	else { aa = atan(dy / dx); };

	if (dy >= 0 && dx < 0) { aa = aa + PI; }
	else if (dy < 0 && dx < 0) { aa = aa + PI; }
	else if (dy < 0 && dx>0) { aa = aa + 2 * PI; };
	if (aa < 0) { aa = aa + 2 * PI; }
	else if (aa > 2 * PI) { aa = aa - 2 * PI; };
	*f = aa;
	return(dd);
}

void BAS_DRAW_FUN::ChuizuToZx(int& inorout, double& dXchuizu, double& dYchuizu, double dXout, double dYout, double dXstart, double dYstart, double dXend, double dYend)
{
	double k = 0.0;//直线的斜率
	double b = 0.0;//将直线化为y=kx+b后的b值
	if (fabs(dYstart - dYend) < PRECISION) // 水平线，直接取垂足
	{
		dXchuizu = dXout;
		dYchuizu = (dYstart + dYend) / 2;
	}
	else if (fabs(dXstart - dXend) < PRECISION)// 竖直线，直接取垂足
	{
		dYchuizu = dYout;
		dXchuizu = (dXstart + dXend) / 2;
	}
	else // 有斜率的直线直接求得垂足
	{
		k = (dYend - dYstart) / (dXend - dXstart);
		b = dYstart - dXstart * k;
		dXchuizu = (dYout + dXout / k - b) / (k + 1 / k);
		dYchuizu = k * (dYout + dXout / k - b) / (k + 1 / k) + b;
	}

	if ((dXchuizu - dXstart) * (dXchuizu - dXend) <= 0 || (dYchuizu - dYstart) * (dYchuizu - dYend) <= 0)
		//if ((dXchuizu>dXstart&&dXchuizu<dXend)||(dYchuizu>dYstart&&dYchuizu<dYend))
	{
		inorout = 1;//垂足在直线线段内
		if (fabs(dYstart - dYend) < PRECISION)
		{
			if ((dXchuizu - dXstart) * (dXchuizu - dXend) > 0)
				inorout = 0;
		}

		if (fabs(dXstart - dXend) < PRECISION)
		{
			if ((dYchuizu - dYstart) * (dYchuizu - dYend) > 0)
				inorout = 0;
		}
	}
	else
		inorout = 0;
}

double BAS_DRAW_FUN::deg(double d_ms)
{
	int d, m;
	double s;
	d = int(d_ms + 0.000000001); m = int((d_ms - d) * 100.0 + 0.00000000001);
	s = d_ms * 10000.0 - d * 10000.0 - m * 100.0;
	return (d + m / 60.0 + s / 3600.0);
}

double BAS_DRAW_FUN::rad(double d_ms)
{
	double d;
	d = deg(d_ms);
	return (d * PI / 180.0);
}


//改变字符串格式 
//输入原始字串 如LS2-3-5 及字段总数 转换为LS0-002-003-005
void BAS_DRAW_FUN::ChangeTextType(ACHAR atmp[], int duannum, ACHAR res[STR_LONG])
{
	CString str = atmp;
	str.MakeUpper();
	vector<CString> StrArray;
	CString strtmp;
	//生成字母段位
	//检测首字符是否为字母，如果是找到第一个非字母，补齐位数（总共3位）
	//如果不是，直接000

	if (str[0] >= 'A' && str[0] <= 'Z')
	{
		strtmp = str.Mid(0, 1);
		str = str.Mid(1, str.GetLength());
		int ii = 1;
		while (str[0] >= 'A' && str[0] <= 'Z')
		{
			strtmp += str.Mid(0, 1);
			str = str.Mid(1, str.GetLength());
			ii++;
		}
		if (ii == 1)
			strtmp += L"00";
		if (ii == 2)
			strtmp += L"0";
	}
	else
	{
		int numtmp = str[0];
		//文字
		if (numtmp > 57)
		{
			strtmp = str.Mid(0, 1);
			str = str.Mid(1, str.GetLength());
			int ii = 1;
			while (str[0] > 57)
			{
				strtmp += str.Mid(0, 1);
				str = str.Mid(1, str.GetLength());
				ii++;
			}
			if (ii == 1)
				strtmp += L"文字";
			if (ii == 2)
				strtmp += L"文";
		}
		else
			strtmp = L"000";
	}
	StrArray.push_back(strtmp);
	//生成数字段位
	CString texttmp;
	texttmp = str.Mid(0, 1);
	if (texttmp == L"-")
	{
		str = str.Mid(1, str.GetLength());
	}
	str += L"-";
	int ei;

	while (str.Find(L"-") > 0)
	{
		ei = str.Find(L"-");
		texttmp = str.Mid(0, ei);
		str = str.Mid(ei + 1, str.GetLength());

		if (_wtoi(texttmp) / 100 > 0)
			strtmp = texttmp;
		else if (_wtoi(texttmp) / 10 > 0 && _wtoi(texttmp) / 10 < 10)
			strtmp = L"0" + texttmp;
		else
			strtmp = L"00" + texttmp;
		StrArray.push_back(strtmp);
	}

	if ((int)StrArray.size() < duannum)
	{
		for (int k = 1; k <= duannum - (int)StrArray.size(); k++)
			StrArray.push_back(L"000");
	}

	CString strFin;
	for (int i = 0; i < (int)StrArray.size(); i++)
	{
		strFin += StrArray[i];
		if (i != StrArray.size() - 1)
			strFin += L"-";
	}
	_tcscpy(res, strFin);
}