calculate.cpp
上传用户:hell82222
上传日期:2013-12-19
资源大小:1872k
文件大小:33k
- #include "stdafx.h"
- #include "FileSwitch.h"
- #include "Reader.h"
- #include "DwgReader.h"
- #include "KmSection.h"
- #include "CShow.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- CString CReader::m_strACADpath="";
- CString CReader::m_strAddPath="";
- double CReader::calculate_3d2pdistance(double x1,double y1,double z1,double x2,double y2,double z2)
- {
- return sqrt( (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2) );
- }
- double CReader::calculate_3ddpdistance(double dx,double dy,double dz)
- {
- return sqrt( dx*dx+dy*dy+dz*dz );
- }
- double CReader::calculate_2dangle(double dx,double dy)
- {
- double r=sqrt(dx*dx+dy*dy);
- if(r<0.00000001)
- {
- return 0;
- }
- double cosv=dx/r;
- if(cosv>=1.0)
- {
- return 0;
- }
- if(cosv<=-1.0)
- {
- return PI;
- }
- double sinv=dy/r;
- if(sinv>=0)
- {
- return acos(cosv);
- }
- else
- {
- return (2*PI-acos(cosv));
- }
- }
- KmPoint CReader::calculate_2drotate(double xo,double yo,double dx,double dy,double ra)
- {
- KmMatrix matrix;//旋转矩阵
- matrix.r11 = cos(ra);
- matrix.r21 = sin(ra);
- matrix.r31 = 0.0;
- matrix.r12 = -sin(ra);
- matrix.r22 = cos(ra);
- matrix.r32 = 0.0;
- matrix.r13 = xo*(1.0 - cos(ra)) + yo*sin(ra);
- matrix.r23 = yo*(1.0 - cos(ra)) - xo*sin(ra);
- matrix.r33 = 1.0;
- KmPoint pt(xo+dx,yo+dy);
- pt = matrix * pt;
- return pt;
- }
- void CDwgReader::calculate_3dbulgelines(CArray<CVector*,CVector*>&avectors)
- {
- for(int i=1;i<avectors.GetSize();i++)
- {
- if(fabs(avectors[i-1]->m_bulge)<= 1e-6)
- {
- if(avectors[i-1]->m_bwidth&&avectors[i-1]->m_widthbegin<1.0e-6)
- {
- m_pConverter->ConverterEntiey_KmArrowHead(avectors[i-1]->m_x,avectors[i-1]->m_y,avectors[i]->m_x,avectors[i]->m_y,avectors[i-1]->m_widthend);
- }
- else if(avectors[i-1]->m_bwidth&&avectors[i-1]->m_widthend<1.0e-6)
- {
- m_pConverter->ConverterEntiey_KmArrowHead(avectors[i]->m_x,avectors[i]->m_y,avectors[i-1]->m_x,avectors[i-1]->m_y,avectors[i-1]->m_widthbegin);
- }
- else
- {
- m_pConverter->ConverterEntiey_KmLine(avectors[i-1]->m_x,avectors[i-1]->m_y,avectors[i-1]->m_z,avectors[i]->m_x,avectors[i]->m_y,avectors[i]->m_z);
- }
- }
- else
- {
- double b = sqrt( (avectors[i-1]->m_x-avectors[i]->m_x)*(avectors[i-1]->m_x-avectors[i]->m_x)+
- (avectors[i-1]->m_y-avectors[i]->m_y)*(avectors[i-1]->m_y-avectors[i]->m_y) );
- double d = fabs( b/2/(2*avectors[i-1]->m_bulge/(1-avectors[i-1]->m_bulge*avectors[i-1]->m_bulge) ) );
- double bert;
- if(avectors[i-1]->m_bulge<0)
- {
- if( (avectors[i-1]->m_bulge + 1) < 0 )
- {
- bert=atan2(avectors[i]->m_y-avectors[i-1]->m_y,avectors[i]->m_x-avectors[i-1]->m_x) - PI/2;
- }
- else
- {
- bert=atan2(avectors[i]->m_y-avectors[i-1]->m_y,avectors[i]->m_x-avectors[i-1]->m_x) + PI/2;
- }
- }
- else
- {
- if( (avectors[i-1]->m_bulge - 1) > 0 )
- {
- bert=atan2(avectors[i]->m_y-avectors[i-1]->m_y,avectors[i]->m_x-avectors[i-1]->m_x) + PI/2;
- }
- else
- {
- bert=atan2(avectors[i]->m_y-avectors[i-1]->m_y,avectors[i]->m_x-avectors[i-1]->m_x) - PI/2;
- }
- }
- double radius = sqrt((b/2)*(b/2) + d*d );
- double cir_x = (avectors[i-1]->m_x+avectors[i]->m_x)/2 - d*cos(bert);
- double cir_y = (avectors[i-1]->m_y+avectors[i]->m_y)/2 - d*sin(bert);
- double b_angle = atan2( avectors[i-1]->m_y-cir_y, avectors[i-1]->m_x-cir_x );
- double e_angle = atan2( avectors[i]->m_y-cir_y, avectors[i]->m_x-cir_x );
- if(avectors[i-1]->m_bulge<0)
- {
- m_pConverter->ConverterEntiey_KmArc(cir_x,cir_y,0,radius,e_angle,b_angle);
- }
- else
- {
- m_pConverter->ConverterEntiey_KmArc(cir_x,cir_y,0,radius,b_angle,e_angle);
- }
- }
- }
- }
- BOOL CDwgReader::calculate_BackView()
- {
- if(adenhd->entflags&AD_EXTRUSION_INFO_VALID)
- {
- if(fabs(adenhd->extrusion[0])<0.00000001)
- {
- if(fabs(adenhd->extrusion[1])<0.00000001)
- {
- if(fabs(adenhd->extrusion[2]+1.0)<0.00000001)
- {
- return TRUE;
- }
- }
- }
- }
- return FALSE;
- }
- //搜索dwg图纸所用的文件,并将它拷贝到kmcad的同名目录中.
- void CReader::calculate_DefaultExamineFile(CString& filename2,CString sondir,CString sonkmdir)
- {
- if(sonkmdir.IsEmpty())sonkmdir=sondir;
- CString temppath;
- CString tempname;
- for(int index=0;index<filename2.GetLength();index++)
- {
- if(filename2[index]=='\')
- {
- if(!tempname.IsEmpty())
- {
- temppath+=tempname;
- temppath+="\";
- tempname.Empty();
- }
- }
- else
- {
- tempname+=filename2[index];
- }
- }
- if(!temppath.IsEmpty())
- {
- CString filetemp=temppath+tempname;
- CFileFind filefind;
- if( filefind.FindFile(filetemp) )
- {
- calculate_CopyFile(filetemp,tempname,sonkmdir);
- filefind.Close();
- }
- }
- CString filename=filename2=tempname;
- for(int i=0;i<=1;i++)
- {
- if((i==1)&&(filename2!=filename))
- {
- filename2=filename;
- }
- else if(i==1)
- {
- //没有找到型文件
- break;
- }
- CFileFind filefind;
- //1.直接在kmcad的目录中寻找.
- {
- TCHAR szFileName[MAX_PATH];
- ::GetModuleFileName(::GetModuleHandle(_T("FileSwitch.dll")),szFileName,MAX_PATH);
- (*_tcsrchr(szFileName,'\'))=' ';
- CString strPath=szFileName;
- strPath+="\";
- strPath+=sonkmdir;
- strPath+="\";
- strPath+=filename;
- if(filefind.FindFile(strPath))
- {
- filename=strPath;
- filefind.Close();
- return;
- }
- }
- //2.直接在硬盘上搜索该文件.
- if(filefind.FindFile(filename))
- {
- CString name;
- for(int i=filename.GetLength();i>0;i--)
- {
- if(filename.GetAt(i-1)=='\')
- {
- break;
- }
- if(filename.GetAt(i-1)=='/')
- {
- break;
- }
- name+=filename.GetAt(i-1);
- }
- filename=calculate_CopyFile(filename,name,sonkmdir);
- filefind.Close();
- return;
- }
- if(!m_strAddPath.IsEmpty())
- {
- CString filenametemp;
- filenametemp=m_strAddPath+tempname;
- if(filefind.FindFile(filenametemp))
- {
- CString name;
- for(int i=filenametemp.GetLength();i>0;i--)
- {
- if(filenametemp.GetAt(i-1)=='\')
- {
- break;
- }
- if(filenametemp.GetAt(i-1)=='/')
- {
- break;
- }
- name+=filenametemp.GetAt(i-1);
- }
- filenametemp=calculate_CopyFile(filenametemp,name,sonkmdir);
- filefind.Close();
- return;
- }
- }
- //3.在用户提供的acad路径中寻找该文件.
- CString strPath;
- for(int i=0;i<m_strACADpath.GetLength();i++)
- {
- if(m_strACADpath.GetAt(i)!=';')
- {
- strPath+=m_strACADpath.GetAt(i);
- }
- else
- {
- if(strPath.GetLength()>0)
- {
- if(strPath.GetAt(strPath.GetLength()-1)!='\')
- {
- strPath+="\";
- }
- if(sondir.GetLength()>0)
- {
- strPath+=sondir;
- strPath+='\';
- }
- strPath+=filename;
- if(filefind.FindFile(strPath))
- {
- filename=calculate_CopyFile(strPath,filename,sonkmdir);
- return;
- }
- }
- strPath.Empty();
- }
- }
- //3.在系统环境中寻找.
- char *envptr;
- if ((envptr=getenv("ACAD"))!=NULL)//在系统路径中寻找
- {
- CString strPaths=envptr;
- for(int i=0;i<strPaths.GetLength();i++)
- {
- if(strPaths.GetAt(i)!=';')
- {
- strPath+=strPaths.GetAt(i);
- }
- else
- {
- if(strPath.GetLength()>0)
- {
- if(strPath.GetAt(strPath.GetLength()-1)!='\')
- {
- strPath+="\";
- }
- CString strTemp=strPath;
- if(sondir.GetLength()>0)
- {
- strPath+=sondir;
- strPath+='\';
- }
- strTemp+=filename;
- if(filefind.FindFile(strTemp))
- {
- filename=calculate_CopyFile(strPath,filename,sonkmdir);
- filefind.Close();
- return;
- }
- strPath+=filename;
- if(filefind.FindFile(strPath))
- {
- filename=calculate_CopyFile(strPath,filename,sonkmdir);
- filefind.Close();
- return;
- }
- }
- strPath.Empty();
- }
- }
- }
- //5.在注册表中寻找.
- //○1通过RegOpenKey函数打开注册表.
- HKEY hKey;
- if(RegOpenKey(HKEY_LOCAL_MACHINE,"Software\Autodesk\AutoCAD",&hKey)==ERROR_SUCCESS)
- {
- //○2通过RegQueryValueEx进行键值查询.
- DWORD dwType=REG_SZ;
- BYTE szData[100];
- DWORD dwSize=sizeof(szData);
- if(RegQueryValueEx(hKey,"CurVer",0,&dwType,szData,&dwSize)==ERROR_SUCCESS)
- {
- CString strKey="Software\Autodesk\AutoCAD\";
- strKey+=(char*)szData;
- if(RegOpenKey(HKEY_LOCAL_MACHINE,strKey,&hKey)==ERROR_SUCCESS)
- {
- dwSize=sizeof(szData);
- if(RegQueryValueEx(hKey,"CurVer",0,&dwType,szData,&dwSize)==ERROR_SUCCESS)
- {
- strKey+='\';
- strKey+=(char*)szData;
- if(RegOpenKey(HKEY_LOCAL_MACHINE,strKey,&hKey)==ERROR_SUCCESS)
- {
- dwSize=sizeof(szData);
- if(RegQueryValueEx(hKey,"AcadLocation",0,&dwType,szData,&dwSize)==ERROR_SUCCESS)
- {
- strPath.Empty();
- strPath=(char*)szData;
- if(strPath.GetLength()>0)
- {
- if(strPath.GetAt(strPath.GetLength()-1)!='\')
- {
- strPath+="\";
- }
- if(sondir.GetLength()>0)
- {
- strPath+=sondir;
- strPath+='\';
- }
- strPath+=filename;
- if(filefind.FindFile(strPath))
- {
- filename=calculate_CopyFile(strPath,filename,sonkmdir);
- return;
- }
- }
- strPath.Empty();
- }
- }
- }
- }
- }
- }
- }
- //filefind.Close();
- //没有找到型文件
- }
- CString CReader::calculate_CopyFile(CString fullfilename,CString filename,CString sondir)
- {
- CFileFind filefind;
- CString strPath;
- {
- TCHAR szFileName[MAX_PATH];
- ::GetModuleFileName(::GetModuleHandle(_T("FileSwitch.dll")),szFileName,MAX_PATH);
- (*_tcsrchr(szFileName,'\'))=' ';
- strPath=szFileName;
- strPath+="\";
- strPath+=sondir;
- strPath+="\";
- strPath+=filename;
- if(filefind.FindFile(strPath))
- {
- filefind.Close();
- return strPath;
- }
- }
- if(!filefind.FindFile(fullfilename))
- {
- //错误:没有找到指定的文件.
- filefind.Close();
- return fullfilename;
- }
- //copy file fullfilename to strpath
- {
- ::CopyFile(fullfilename,strPath,TRUE);
- }
- if(filefind.FindFile(strPath))
- {
- filefind.Close();
- return strPath;
- }
- filefind.Close();
- return fullfilename;
- }
- void CReader::calculate_path_line(PATH2* path,double x1,double y1,double x2,double y2)
- {
- path->points.Add(KmPoint(x1,y1));
- path->bugle.Add(1);
- path->Center.Add(KmPoint(x2,y2));
- path->Radius.Add(0);
- path->b_angle.Add(0);
- path->e_angle.Add(0);
- }
- void CReader::calculate_path_arc(PATH2* path,double x1,double y1,double r,double ba,double ea,short full)
- {
-
- double b_angle=ba;//作逆弧处理
- double e_angle=ea;
- if(full)
- {
- path->points.Add(KmPoint(0,0));
- path->bugle.Add(0);
- path->Center.Add(KmPoint(x1,y1));
- path->Radius.Add(r);
- path->b_angle.Add(0);
- path->e_angle.Add(360);
- }
- else
- {
- path->points.Add(KmPoint(0,0));
- path->bugle.Add(0);
- path->Center.Add(KmPoint(x1,y1));
- path->Radius.Add(r);
- path->b_angle.Add(ba);
- path->e_angle.Add(ea);
- }
- }
- void CReader::calculate_path_object(PATH2* path,KmObject* pObj)
- {
- KmBuffer aBuffer;
- S_LINE_BUFFER* pLineBuffer;
- S_CIRCLE_BUFFER* pCircleBuffer;
- CShow* pShow = new CGDIShow((CWnd*)NULL);
- pObj->Draw(pShow,0,DRAWPRESENT,&aBuffer);
-
- for(int i=0;i<aBuffer.GetLineBuffSize();i++)
- {
- pLineBuffer=aBuffer.GetLineEnt(i);
- calculate_path_line(path,pLineBuffer->P1.x,pLineBuffer->P1.y,pLineBuffer->P2.x,pLineBuffer->P2.y);
- }
- for(i=0;i<aBuffer.GetCircleBuffSize();i++)
- {
- pCircleBuffer=aBuffer.GetCircleEnt(i);
- if(pCircleBuffer->message&MESSAGE_CIRCLE_FULL)
- {
- calculate_path_arc(path,pCircleBuffer->center.x,pCircleBuffer->center.y,pCircleBuffer->radius,0,0,1);
- }
- else if(pCircleBuffer->message&MESSAGE_CIRCLE_NEGATIVE)//顺弧
- {
- calculate_path_arc(path,pCircleBuffer->center.x,pCircleBuffer->center.y,pCircleBuffer->radius,pCircleBuffer->e_angle,pCircleBuffer->b_angle,0);
- }
- else
- {
- calculate_path_arc(path,pCircleBuffer->center.x,pCircleBuffer->center.y,pCircleBuffer->radius,pCircleBuffer->b_angle,pCircleBuffer->e_angle,0);
- }
- }
- aBuffer.ClearKmBuffer();
- delete pShow;
- }
- void CReader::calculate_path_bugleline(PATH2* path,double x1,double y1,double bugle,double x2,double y2)
- {
- if(fabs(bugle)<0.0000001)
- {
- calculate_path_line(path,x1,y1,x2,y2);
- return;
- }
- KmCircle* pCircle=new KmCircle;
- /*
- KmPoint Point_X1; //存放圆上的第三点
- KmPoint Point_X2; //存放圆上的第三点
- KmPoint Point_X3; //存放圆上的第三点
- Point_X1.x=x1;
- Point_X1.x=y1;
- Point_X2.x=x2;
- Point_X2.x=y2;
- KmPoint ChangPoint;
- KmPoint MidPoint; //弦Point_X1Point_X2上的中点
- double length ; //Point_X1,Point_X2之间线段长度
- double hight; //弦Point_X1Point_X2上的高
- double borderlen;
- double SaveAngle; //与弧相关角的SIN或COS值
- double X;
-
- length=sqrt((Point_X1.x-Point_X2.x)*(Point_X1.x-Point_X2.x)+(Point_X1.y-Point_X2.y)*(Point_X1.y-Point_X2.y));
- hight=(length*bugle)/2;
- MidPoint.x=(Point_X1.x+Point_X2.x)/2;
- MidPoint.y=(Point_X1.y+Point_X2.y)/2;
- if((Point_X1.y==MidPoint.y)&&(Point_X1.x>MidPoint.x))//当弦与X轴平行
- {
- Point_X3.y=MidPoint.y+hight;
- Point_X3.x=MidPoint.x;
- }
- else if((Point_X1.y==MidPoint.y)&&(Point_X1.x<MidPoint.x))//当弦与Y轴平行
- {
- Point_X3.y=MidPoint.y-hight;
- Point_X3.x=MidPoint.x;
- }
- else
- {
- if(bugle>0) //弧为逆时针方向
- {
- borderlen=fabs(MidPoint.x-Point_X2.x);
- SaveAngle=borderlen/length*2;
- if((Point_X2.y>Point_X1.y)&&(Point_X2.x<Point_X1.x))
- {
- Point_X3.y=MidPoint.y+(hight*SaveAngle);
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x+X;
- }
- else if((Point_X2.y>Point_X1.y)&&(Point_X2.x>Point_X1.x))
- {
- Point_X3.y=MidPoint.y-(hight*SaveAngle);
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x+X;
- }
- else if((Point_X2.y<Point_X1.y)&&(Point_X2.x>Point_X1.x))
- {
- Point_X3.y=MidPoint.y-(hight*SaveAngle);
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x-X;
- }
- else if((Point_X2.y<Point_X1.y)&&(Point_X2.x<Point_X1.x))
- {
- Point_X3.y=(MidPoint.y+(hight*SaveAngle));
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x-X;
- }
- }
- else
- {
- borderlen=fabs(MidPoint.x-Point_X2.x);
- SaveAngle=borderlen/length*2;
- if((Point_X2.y>Point_X1.y)&&(Point_X2.x<Point_X1.x))
- {
- Point_X3.y=MidPoint.y+(hight*SaveAngle);
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x-X;
- }
- else if((Point_X2.y>Point_X1.y)&&(Point_X2.x>Point_X1.x))
- {
- Point_X3.y=MidPoint.y-(hight*SaveAngle);
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x-X;
- }
- else if((Point_X2.y<Point_X1.y)&&(Point_X2.x>Point_X1.x))
- {
- Point_X3.y=MidPoint.y-(hight*SaveAngle);
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x+X;
- }
- else if((Point_X2.y<Point_X1.y)&&(Point_X2.x<Point_X1.x))
- {
- Point_X3.y=(MidPoint.y+(hight*SaveAngle));
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x+X;
- }
- }
- }
- calculate_path_line(path,Point_X1.x,Point_X1.y,Point_X3.x,Point_X3.y);
- calculate_path_line(path,Point_X2.x,Point_X2.y,Point_X3.x,Point_X3.y);
- calculate_path_line(path,Point_X1.x,Point_X1.y,Point_X2.x,Point_X2.y);
- */
- calculate_Get_CIRCLE(*pCircle,bugle,KmPoint(x1,y1),KmPoint(x2,y2));
- calculate_path_object(path,pCircle);
- delete pCircle;
- }
- void CReader::calculate_Get_CIRCLE(CIRCLE &rCircle,double bugle,KmPoint Point_X1,KmPoint Point_X2)
- {
- KmPoint Point_X3; //存放圆上的第三点
- KmPoint ChangPoint;
- KmPoint MidPoint; //弦Point_X1Point_X2上的中点
- double length ; //Point_X1,Point_X2之间线段长度
- double hight; //弦Point_X1Point_X2上的高
- double borderlen;
- double SaveAngle; //与弧相关角的SIN或COS值
- double X;
-
- length=sqrt((Point_X1.x-Point_X2.x)*(Point_X1.x-Point_X2.x)+(Point_X1.y-Point_X2.y)*(Point_X1.y-Point_X2.y));
- hight=(length*bugle)/2;
- MidPoint.x=(Point_X1.x+Point_X2.x)/2;
- MidPoint.y=(Point_X1.y+Point_X2.y)/2;
- if((Point_X1.y==MidPoint.y)&&(Point_X1.x>MidPoint.x))//当弦与X轴平行且弧向上弯曲
- {
- Point_X3.y=MidPoint.y+hight;
- Point_X3.x=MidPoint.x;
- }
- else if((Point_X1.y==MidPoint.y)&&(Point_X1.x<MidPoint.x))//当弦与X轴平行且弧向下弯曲
- {
- Point_X3.y=MidPoint.y-hight;
- Point_X3.x=MidPoint.x;
- }
- else if((Point_X1.x==MidPoint.x)&&(Point_X1.y<MidPoint.y))//当弦与Y轴平行且弧向右弯曲
- {
- Point_X3.x=MidPoint.x+hight;
- Point_X3.y=MidPoint.y;
- }
-
- else if((Point_X1.x==MidPoint.x)&&(Point_X1.y>MidPoint.y))//当弦与Y轴平行且弧向左弯曲
- {
- Point_X3.x=MidPoint.x-hight;
- Point_X3.y=MidPoint.y;
- }
- else
- {
- if(bugle>0) //弧为逆时针方向
- {
- borderlen=fabs(MidPoint.x-Point_X2.x);
- SaveAngle=borderlen/length*2;
- if((Point_X2.y>Point_X1.y)&&(Point_X2.x<Point_X1.x))
- {
- Point_X3.y=MidPoint.y+(hight*SaveAngle);
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x+X;
- }
- else if((Point_X2.y>Point_X1.y)&&(Point_X2.x>Point_X1.x))
- {
- Point_X3.y=MidPoint.y-(hight*SaveAngle);
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x+X;
- }
- else if((Point_X2.y<Point_X1.y)&&(Point_X2.x>Point_X1.x))
- {
- Point_X3.y=MidPoint.y-(hight*SaveAngle);
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x-X;
- }
- else if((Point_X2.y<Point_X1.y)&&(Point_X2.x<Point_X1.x))
- {
- Point_X3.y=(MidPoint.y+(hight*SaveAngle));
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x-X;
- }
- }
- else
- {
- borderlen=fabs(MidPoint.x-Point_X2.x);
- SaveAngle=borderlen/length*2;
- if((Point_X2.y>Point_X1.y)&&(Point_X2.x<Point_X1.x))
- {
- Point_X3.y=MidPoint.y+(hight*SaveAngle);
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x-X;
- }
- else if((Point_X2.y>Point_X1.y)&&(Point_X2.x>Point_X1.x))
- {
- Point_X3.y=MidPoint.y-(hight*SaveAngle);
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x-X;
- }
- else if((Point_X2.y<Point_X1.y)&&(Point_X2.x>Point_X1.x))
- {
- Point_X3.y=MidPoint.y-(hight*SaveAngle);
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x+X;
- }
- else if((Point_X2.y<Point_X1.y)&&(Point_X2.x<Point_X1.x))
- {
- Point_X3.y=(MidPoint.y+(hight*SaveAngle));
- X=sqrt (fabs(hight*hight-hight*SaveAngle*hight*SaveAngle));
- Point_X3.x=MidPoint.x+X;
- }
- }
- }
- if(bugle>0) //弧为逆时针方向 counter-clockwise
- {
- calculate_three_point_Getcircle(rCircle,Point_X3,Point_X1,Point_X2,TRUE); //通过Point_X1,Point_X3,Point_X2求圆
- }
- else
- {
- calculate_three_point_Getcircle(rCircle,Point_X3,Point_X1,Point_X2,FALSE); //通过Point_X1,Point_X3,Point_X2求圆
- }
- }
- //KmPoint1为中点
- void CReader::calculate_three_point_Getcircle(CIRCLE &rCircle,KmPoint KmPoint1,KmPoint KmPoint2,KmPoint KmPoint3,BOOL bccw)
- {
- double mid_sita;
- double rxyo[3];
- double sita1,sita2,s1,s2;
-
- double first_seed_x=KmPoint1.x;
- double first_seed_y=KmPoint1.y;
- double second_seed_x=KmPoint2.x;
- double second_seed_y=KmPoint2.y;
- double third_seed_x=KmPoint3.x;
- double third_seed_y=KmPoint3.y;
- if(fabs(second_seed_y-first_seed_y)<0.0000001&&fabs(second_seed_x-first_seed_x)<0.0000001) return;
- if(fabs(third_seed_y-first_seed_y)<0.0000001&&fabs(third_seed_x-first_seed_x)<0.0000001) return;
- //计算三点圆的圆心.
- cal_r_xyo(rxyo,first_seed_x,first_seed_y,second_seed_x,second_seed_y,third_seed_x,third_seed_y);
- sita1=atan2(second_seed_y-first_seed_y,second_seed_x-first_seed_x);
- sita2=atan2(third_seed_y-first_seed_y,third_seed_x-first_seed_x);
- s1=standard(rad_to_deg(sita1));
- s2=standard(rad_to_deg(sita2));
-
- rCircle.xo=rxyo[1];
- rCircle.yo=rxyo[2];
- rCircle.r=rxyo[0];
- {//1
- if(fabs(first_seed_y-rxyo[2])<0.0000001&&fabs(first_seed_x-rxyo[1])<0.0000001)return;
- if(fabs(third_seed_y-rxyo[2])<0.0000001&&fabs(third_seed_x-rxyo[1])<0.0000001)return;
- if(fabs(second_seed_y-rxyo[2])<0.0000001&&fabs(second_seed_x-rxyo[1])<0.0000001)return;
- rCircle.b_angle=standard(rad_to_deg(atan2(second_seed_y-rxyo[2],second_seed_x-rxyo[1])));
- rCircle.e_angle=standard(rad_to_deg(atan2(third_seed_y-rxyo[2],third_seed_x-rxyo[1])));
- mid_sita=(standard(rad_to_deg(atan2(first_seed_y-rxyo[2],first_seed_x-rxyo[1]))));
- //if((mid_sita<rCircle.b_angle||mid_sita>rCircle.e_angle)&&rCircle.b_angle<rCircle.e_angle||mid_sita>rCircle.e_angle&&rCircle.b_angle>mid_sita)
- if(!bccw)
- {//2
- mid_sita=rCircle.b_angle;
- rCircle.b_angle=rCircle.e_angle;
- rCircle.e_angle=mid_sita;
- }//2
- rCircle.message=MESSAGE_CIRCLE_POSITIVE;
- }//1
- }
- int CReader::calculate_cal_r_xyo(double rxyo[3],double first_seed_x,double first_seed_y,double second_seed_x,double second_seed_y,double third_seed_x,double third_seed_y)
- //求圆//rxyo[3]圆心//second_seed_x,second_seed_y,third_seed_x,third_seed_y)//圆上的点
- {
- if(fabs(first_seed_x-third_seed_x)>=fabs(second_seed_x-third_seed_x))
- {
- return(calculate_get_r_xyo(rxyo,first_seed_x,first_seed_y,second_seed_x,second_seed_y,
- third_seed_x,third_seed_y));
- }
- else
- {
- return (calculate_get_r_xyo(rxyo,second_seed_x,second_seed_y,first_seed_x,first_seed_y,
- third_seed_x,third_seed_y));
- }
- }
- int CReader::calculate_get_r_xyo(double rxyo[3],double x1,double y1,double x2,double y2,double x3,double y3)
- //求圆心
- //rxyo[3] 出访圆新的缓存
- //x1,y1,x2,y2,x3,y3圆上的三点
- {
- double circle_a1,circle_b1,circle_c1;
- double m,n,k,a2,b2,c2;
- double d,e,f;
- circle_a1=x1*x1+y1*y1;
- circle_b1=x2*x2+y2*y2;
- circle_c1=x3*x3+y3*y3;
- if(fabs(x1-x3)<0.0000001) return 0;
- a2=(circle_a1-circle_c1)/(x1-x3);
- b2=circle_b1-circle_c1;
- c2=circle_c1;
- m=(y1-y3)/(x1-x3);
- k=y2-y3-(y1-y3)/(x1-x3)*(x2-x3);
- n=y3-(y1-y3)/(x1-x3)*x3;
- circle_a1=a2;
- circle_b1=b2-a2*(x2-x3);
- circle_c1=c2-x3*a2;
- if(fabs(k)<0.0000001) return 0;
- d=-circle_a1+circle_b1/k*m;
- e=-circle_b1/k;
- f=-circle_c1+circle_b1/k*n;
- rxyo[0]=sqrt(d*d+e*e-4.0*f)*0.5;
- rxyo[1]=-d*0.5;
- rxyo[2]=-e*0.5;
- return 1;
- }
- BOOL CReader::calculate_findshape(AD_DB_HANDLE dwghandle,AD_OBJHANDLE shapefileobjhandle,int whichshape,double *px,double *py,double dAng,int bound_high,double text_h, double text_w,KmBuffer* pBuffer)
- {
- AD_TB adtbtemp;
- //extern short ADCDECL adSeekShapefile _((AD_DB_HANDLE handle,AD_OBJHANDLE thehandle,PAD_SHPTB theshptb));
- short sReturnValue = adSeekShapefile(dwghandle,shapefileobjhandle,&adtbtemp.shptb);
- if(sReturnValue!=1)
- {
- return FALSE;
- }
- CString filename=adtbtemp.shptb.file;
- if(filename.IsEmpty()){return FALSE;}
- CFileFind filefind;
- if(!filefind.FindFile(filename))
- {
- calculate_DefaultExamineFile(filename,"SUPPORT");
- {
- TCHAR szFileName[MAX_PATH];
- ::GetModuleFileName(::GetModuleHandle(_T("FileSwitch.dll")),szFileName,MAX_PATH);
- (*_tcsrchr(szFileName,'\'))=' ';
- CString strPath=szFileName;
- strPath+="\";
- strPath+="SUPPORT";
- strPath+="\";
- strPath+=filename;
- if(!filefind.FindFile(strPath))
- {
- filefind.Close();
- return FALSE;
- }
- filename=strPath;
- }
- }
- //BYTE24 CHAR* 文件格式标记
- //BYTE2 int 形的起始序号
- //BYTE2 int 形的中止序号
- //BYTE2 int 形的数量
- //循环BYTE2 int 形的序号
- // BYTE2 int 形的字节长度
- //循环BYTE至0 CHAR* 形的名称
- // BYTE形的长度shorts形的内容
- //BYTE3 CHAR* 结束标记"EOF"
- CFile file;
- if(!file.Open(filename,CFile::modeRead))
- {
- return FALSE;
- }
- __int8 byte;
- __int16 data;
- __int16 iBegin;
- __int16 iEnd;
- __int16 iNum;
- CArray<__int16,__int16> iLengths;
- if(file.Seek(24,CFile::begin)!=24){try{file.Close();}catch(...){};return FALSE;}
- if(file.Read(&data,2)!=2){try{file.Close();}catch(...){};return FALSE;}iBegin=data;
- if(file.Read(&data,2)!=2){try{file.Close();}catch(...){};return FALSE;}iEnd=data;
- if(file.Read(&data,2)!=2){try{file.Close();}catch(...){};return FALSE;}iNum=data;
- if(iNum!=(fabs(iEnd-iBegin)+1)){try{file.Close();}catch(...){};return FALSE;}
- if(iEnd<iBegin){data=iBegin;iBegin=iEnd;iEnd=data;}
- if(whichshape<iBegin||whichshape>iEnd){try{file.Close();}catch(...){};return FALSE;}
- for(__int16 index=iBegin;index<=iEnd;index++)
- {
- if(file.Read(&data,2)!=2){try{file.Close();}catch(...){};return FALSE;}
- if(index!=data){try{file.Close();}catch(...){};return FALSE;}
- if(file.Read(&data,2)!=2){try{file.Close();}catch(...){};return FALSE;}
- iLengths.Add(data);
- }
- if(iLengths[whichshape-iBegin]>2000){try{file.Close();}catch(...){};return FALSE;}
- __int32 iPos=30+iNum*4;
- for(index=0;index<(whichshape-iBegin);index++)
- {
- iPos+=iLengths[index];
- }
- if(file.Seek(iPos,CFile::begin)!=iPos){try{file.Close();}catch(...){};return FALSE;}
- CString strShapeName;
- for(index=0;index<25;index++)
- {
- if(file.Read(&byte,1)!=1){try{file.Close();}catch(...){};return FALSE;}
- if(byte==0)break;
- strShapeName+=byte;
- if(index==24){try{file.Close();}catch(...){};return FALSE;}
- }
- char str[2000];
- if( file.Read(str,iLengths[whichshape-iBegin]-strShapeName.GetLength()-1)!=((UINT)(iLengths[whichshape-iBegin]-strShapeName.GetLength()-1))){try{file.Close();}catch(...){};return FALSE;}
- file.Close();
- CreateShape(dwghandle,shapefileobjhandle,str,iLengths[whichshape-iBegin]-strShapeName.GetLength()-1,px,py,dAng,bound_high,text_h,text_w,pBuffer);
- filefind.Close();
- return TRUE;
- }
- double calculate_findTTFHightRate(CString strFontName)
- {
- FONTMAPITEM* pFontMapItem=NULL;
- if(CConverter::m_mapFont.Lookup(strFontName,(void* &)pFontMapItem))
- {
- strFontName=pFontMapItem->m_strFontName;
- }
- double dRate=1.0;
- if(strFontName.Find('.')!=-1)return dRate;
- CWinApp* pApp=::AfxGetApp();
- CString strTemp;
- if(pApp)
- {
- strTemp = pApp->GetProfileString(_T("DwgFontHightRate"),strFontName,"-1.0");
- dRate = ::atof(LPCTSTR(strTemp));
- if(dRate>0)
- {
- return dRate;
- }
- }
- dRate=1.0;
- CFont fonttext;fonttext.CreateFont(1000,0,0,0,0,FALSE,FALSE,0,DEFAULT_CHARSET,0,0,0,0,strFontName);
- CWnd* pDesktop=CWnd::FromHandle(::GetDesktopWindow());
- CDC* pDC=pDesktop->GetDC();
- CFont* fontold=pDC->SelectObject(&fonttext);
- TEXTMETRIC tm;
- pDC->GetTextMetrics(&tm);
- pDC->SelectObject(fontold);
- if(fonttext.GetSafeHandle())
- fonttext.DeleteObject();
- try
- {
- dRate= ((double)(tm.tmHeight-tm.tmInternalLeading))*((double)(tm.tmAscent-tm.tmInternalLeading))/( ((double)(tm.tmHeight-tm.tmInternalLeading))*TEXT_ADJUST*((double)(tm.tmHeight+tm.tmExternalLeading)) );
- }
- catch(...)
- {
- dRate=1.0;
- }
- strTemp.Format("%lf",dRate);
- pApp->WriteProfileString(_T("DwgFontHightRate"),strFontName, strTemp);//用于保证保存了数据
- return dRate;
- }
- double calculate_findTTFWidthRate(CString strFontName)
- {
- FONTMAPITEM* pFontMapItem=NULL;
- if(CConverter::m_mapFont.Lookup(strFontName,(void* &)pFontMapItem))
- {
- strFontName=pFontMapItem->m_strFontName;
- }
- double dRate=1.0;
- if(strFontName.Find('.')!=-1)return dRate;
- CWinApp* pApp=::AfxGetApp();
- CString strTemp;
- if(pApp)
- {
- strTemp = pApp->GetProfileString(_T("DwgFontWidthRate"),strFontName,"-1.0");
- dRate = ::atof(LPCTSTR(strTemp));
- if(dRate>0)
- {
- return dRate;
- }
- }
- dRate=1.0;
- CFont fonttext;fonttext.CreateFont(1000,0,0,0,0,FALSE,FALSE,0,DEFAULT_CHARSET,0,0,0,0,strFontName);
- CWnd* pDesktop=CWnd::FromHandle(::GetDesktopWindow());
- CDC* pDC=pDesktop->GetDC();
- CFont* fontold=pDC->SelectObject(&fonttext);
- TEXTMETRIC tm;
- pDC->GetTextMetrics(&tm);
- pDC->SelectObject(fontold);
- if(fonttext.GetSafeHandle())
- fonttext.DeleteObject();
- try
- {
- dRate=((double)tm.tmAveCharWidth)/((double)tm.tmHeight)*2.0;
- }
- catch(...)
- {
- dRate=1.0;
- }
- strTemp.Format("%lf",dRate);
- pApp->WriteProfileString(_T("DwgFontWidthRate"),strFontName, strTemp);//用于保证保存了数据
- return dRate;
- }
- double calculate_findTTFPosRate(CString strFontName)
- {
- FONTMAPITEM* pFontMapItem=NULL;
- if(CConverter::m_mapFont.Lookup(strFontName,(void* &)pFontMapItem))
- {
- strFontName=pFontMapItem->m_strFontName;
- }
- double dRate=1.0;
- if(strFontName.Find('.')!=-1)return dRate;
- CWinApp* pApp=::AfxGetApp();
- CString strTemp;
- if(pApp)
- {
- strTemp = pApp->GetProfileString(_T("DwgFontPosRate"),strFontName,"-1.0");
- dRate = ::atof(LPCTSTR(strTemp));
- if(dRate>0)
- {
- return dRate;
- }
- }
- dRate=1.0;
- CFont fonttext;fonttext.CreateFont(1000,0,0,0,0,FALSE,FALSE,0,DEFAULT_CHARSET,0,0,0,0,strFontName);
- CWnd* pDesktop=CWnd::FromHandle(::GetDesktopWindow());
- CDC* pDC=pDesktop->GetDC();
- CFont* fontold=pDC->SelectObject(&fonttext);
- TEXTMETRIC tm;
- pDC->GetTextMetrics(&tm);
- pDC->SelectObject(fontold);
- if(fonttext.GetSafeHandle())
- fonttext.DeleteObject();
- try
- {
- //a=1.0+字高调整系数*TEXT_ADJUST*(扩展+发音)/(字高-线下-发音)
- dRate=1.0+::calculate_findTTFHightRate(strFontName)*TEXT_ADJUST*(tm.tmExternalLeading+
- tm.tmInternalLeading)/(1000.0-tm.tmDescent-tm.tmInternalLeading);
- }
- catch(...)
- {
- dRate=1.0;
- }
- strTemp.Format("%lf",dRate);
- pApp->WriteProfileString(_T("DwgFontPosRate"),strFontName, strTemp);//用于保证保存了数据
- return dRate;
- }
- BOOL CALLBACK AFX_EXPORT CReader::EnumFamScreenCallBack(ENUMLOGFONT* pelf,
- NEWTEXTMETRICEX* /*lpntm*/, int FontType, LPVOID lp)
- {
- if (FontType & RASTER_FONTTYPE)
- return 1;
-
- LOGFONT& lf = pelf->elfLogFont;
- if ((lf.lfCharSet != ANSI_CHARSET)
- &&(lf.lfCharSet != OEM_CHARSET)
- &&(lf.lfCharSet != SYMBOL_CHARSET)
- &&(lf.lfCharSet != GB2312_CHARSET) )
- return 1 ;
- // CStringArray* strarray;
- // strarray = (CStringArray*)lp;
- // strarray->Add(lf.lfFaceName);
- CString strfilename;
- strfilename=lf.lfFaceName;
- // strfilename.MakeLower();
- CTypedPtrMap<CMapStringToPtr, CString, void*>* pMapFont =
- (CTypedPtrMap<CMapStringToPtr, CString, void*>*)lp;
- void *p;
- if(!pMapFont->Lookup(strfilename,p))
- {
- CString strTemp=strfilename;
- strTemp.MakeLower();
- if(strTemp=="symusic"||
- strTemp=="romand"||
- strTemp=="romans"||
- strTemp=="romant"||
- strTemp=="scriptc"||
- strTemp=="scripts"||
- strTemp=="syastro"||
- strTemp=="symap"||
- strTemp=="monotxt"||
- strTemp=="symeteo"||
- strTemp=="italict"||
- strTemp=="symath"||
- strTemp=="gothici"||
- strTemp=="bigfont"||
- strTemp=="complex"||
- strTemp=="romanc"||
- strTemp=="gothicg"||
- strTemp=="greekc"||
- strTemp=="greeks"||
- strTemp=="isocp"||
- strTemp=="isocp2"||
- strTemp=="isocp3"||
- strTemp=="isoct"||
- strTemp=="isoct2"||
- strTemp=="isoct3"||
- strTemp=="italic"||
- strTemp=="italicc"||
- strTemp=="gothice"||
- strTemp=="gbeitc"||
- strTemp=="gbcbig"||
- strTemp=="chineset"||
- strTemp=="extfont"||
- strTemp=="whgdtxt"||
- strTemp=="whgtxt"||
- strTemp=="whtmtxt"||
- strTemp=="htgtxt"||
- strTemp=="gbenor")
- {
- TRACE("同名 采用形文字");
- }
- else
- {
- pMapFont->SetAt(strfilename,NULL);
- }
- }
- return 1;
- }
- BOOL CALLBACK AFX_EXPORT CReader::EnumFamScreenCallBackEx(ENUMLOGFONTEX* pelf,
- NEWTEXTMETRICEX* /*lpntm*/, int FontType, LPVOID lp)
- {
- if (FontType & RASTER_FONTTYPE)
- return 1;
-
- LOGFONT& lf = pelf->elfLogFont;
- if ((lf.lfCharSet != ANSI_CHARSET)
- &&(lf.lfCharSet != OEM_CHARSET)
- &&(lf.lfCharSet != SYMBOL_CHARSET)
- &&(lf.lfCharSet != GB2312_CHARSET) )
- return 1;
- // CStringArray* strarray;
- // strarray = (CStringArray*)lp;
- // strarray->Add(lf.lfFaceName);
- CString strfilename;
- strfilename=lf.lfFaceName;
- // strfilename.MakeLower();
- CTypedPtrMap<CMapStringToPtr, CString, void*>* pMapFont =
- (CTypedPtrMap<CMapStringToPtr, CString, void*>*)lp;
- void *p;
- if(!pMapFont->Lookup(strfilename,p))
- {
- CString strTemp=strfilename;
- strTemp.MakeLower();
- if(strTemp=="symusic"||
- strTemp=="romand"||
- strTemp=="romans"||
- strTemp=="romant"||
- strTemp=="scriptc"||
- strTemp=="scripts"||
- strTemp=="syastro"||
- strTemp=="symap"||
- strTemp=="monotxt"||
- strTemp=="symeteo"||
- strTemp=="italict"||
- strTemp=="symath"||
- strTemp=="gothici"||
- strTemp=="bigfont"||
- strTemp=="complex"||
- strTemp=="romanc"||
- strTemp=="gothicg"||
- strTemp=="greekc"||
- strTemp=="greeks"||
- strTemp=="isocp"||
- strTemp=="isocp2"||
- strTemp=="isocp3"||
- strTemp=="isoct"||
- strTemp=="isoct2"||
- strTemp=="isoct3"||
- strTemp=="italic"||
- strTemp=="italicc"||
- strTemp=="gothice"||
- strTemp=="gbeitc"||
- strTemp=="gbcbig"||
- strTemp=="chineset"||
- strTemp=="extfont"||
- strTemp=="whgdtxt"||
- strTemp=="whgtxt"||
- strTemp=="whtmtxt"||
- strTemp=="htgtxt"||
- strTemp=="gbenor")
- {
- TRACE("同名 采用形文字");
- }
- else
- {
- pMapFont->SetAt(strfilename,NULL);
- }
- }
- return 1;
- }
- void CReader::calculate_findfonts(CTypedPtrMap<CMapStringToPtr, CString, void*>* pMapFont)
- {
- if(!pMapFont)return;
- pMapFont->RemoveAll();
- LOGFONT lf;
- memset(&lf, 0, sizeof(LOGFONT));
- lf.lfCharSet = DEFAULT_CHARSET;
- CDC dcScreen;
- dcScreen.Attach(::GetDC(NULL));
- HDC hDC = dcScreen.m_hDC;
- DWORD dwVersion = ::GetVersion();
- BOOL m_bWin4 = (BYTE)dwVersion >= 4;
- if (m_bWin4)
- {
- ::EnumFontFamiliesEx(hDC, &lf,
- (FONTENUMPROC) EnumFamScreenCallBackEx, (LPARAM)pMapFont, NULL);
- }
- else
- {
- ::EnumFontFamilies(hDC, NULL,
- (FONTENUMPROC) EnumFamScreenCallBack, (LPARAM)pMapFont);
- }
- }