Processfile8.cpp
上传用户:hell82222
上传日期:2013-12-19
资源大小:1872k
文件大小:6k
- #include "stdafx.h"
- #include "FileSwitch.h"
- #include "IgesReader.h"
- #include "KmgReader.h"
- #include "KmDim.h"
- #include "DSSubst.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- extern CStdioFile g_CensorialFile; //监察转换进度的文件
- extern int g_mode;
- BOOL CKmgReader::processentity_dim(CKmDataManager* pData,KmObject* pObj,AD_OBJHANDLE handle)
- {
- if(!pObj)return FALSE;
- if(!pObj->IsKindOf(RUNTIME_CLASS(KmDim)))return FALSE;
- AD_OBJHANDLE hDimstyle;
- if(!m_adimstyle.Get(hDimstyle,((KmDim*)pObj)->GetDimStyleID()))
- {
- return FALSE;
- }
- //extern AD_VMADDR ADCDECL adCreateBlobEx _((short chunksize));
- //#define adCreateBlob() adCreateBlobEx(4096)
- //extern short ADCDECL adDeleteBlob _((AD_VMADDR blob));
- AD_VMADDR blob=adCreateBlob();//样式替代大小应小于4096
- KmDim* pDim=(KmDim*)pObj;
- KmDimStlAcsMgr* pDimStlAcsMgr=pDim->GetDSAMgr();
- if(pDimStlAcsMgr)
- {
- CDSSubst* pDSSubst=pDimStlAcsMgr->GetVarSel(pDim->GetDimStyleID());
- if(pDSSubst)
- {
- if(pDSSubst->GetSubstVarNum()!=0)
- {
- //BOOL processentity_dim_blob(CDSSubst* pDSSubst,AD_VMADDR blob);
- if(!processentity_dim_blob(pDSSubst,blob))
- {
- adDeleteBlob(blob);
- blob=NULL;
- }
- }
- else
- {
- adDeleteBlob(blob);
- blob=NULL;
- }
- }
- else
- {
- adDeleteBlob(blob);
- blob=NULL;
- }
- }
- else
- //如果没有样式替代则
- {
- adDeleteBlob(blob);
- blob=NULL;
- }
- if(pObj->IsKindOf(RUNTIME_CLASS(KmSimpleDim)))
- //(KmSimpleDim));
- //(KmCoSerialSimpleDim));
- //(KmDaSerialSimpleDim));
- //(KmGeSerialSimpleDim));
- //(KmSyHalfSimpleDim));
- //(KmSyDiameterDim));
- {
- if(!processentity_dim_simple(pData,pObj,handle,hDimstyle,blob))
- {
- adDeleteBlob(blob);
- return FALSE;
- }
- return TRUE;
- }
- else if(pObj->IsKindOf(RUNTIME_CLASS(KmRadiusDim)))
- //(KmRadiusDim));
- {
- if(!processentity_dim_radius(pData,pObj,handle,hDimstyle,blob))
- {
- adDeleteBlob(blob);
- return FALSE;
- }
- return TRUE;
- }
- else if(pObj->IsKindOf(RUNTIME_CLASS(KmDiameterDim)))
- //(KmDiameterDim));
- {
- if(!processentity_dim_diameter(pData,pObj,handle,hDimstyle,blob))
- {
- adDeleteBlob(blob);
- return FALSE;
- }
- return TRUE;
- }
- else if(pObj->IsKindOf(RUNTIME_CLASS(KmBaseAngleDim)))
- //(KmBaseAngleDim));
- //(KmArcLenDim));
- //(KmAngleDim));
- //(KmVAngleDim));
- //(KmSyHalfAngleDim));
- {
- if(!processentity_dim_angle(pData,pObj,handle,hDimstyle,blob))
- {
- adDeleteBlob(blob);
- return FALSE;
- }
- return TRUE;
- }
- adDeleteBlob(blob);
- return FALSE;
- }
- BOOL CKmgReader::processentity_dim_simple(CKmDataManager* pData,KmObject* pObj,AD_OBJHANDLE hBlock,AD_OBJHANDLE hDimstyle,AD_VMADDR blob)
- {
- if(!pObj)return FALSE;
- if(!pObj->IsKindOf(RUNTIME_CLASS(KmSimpleDim)))return FALSE;
- KmSimpleDim* pSimpleDim=(KmSimpleDim*)pObj;
- //东方CAD保证LINEB与LT1B在同一条尺寸引出线上
- KmPoint p1=pSimpleDim->GetDimLt1B();
- KmPoint p2=pSimpleDim->GetDimLt2B();
- KmPoint p3=pSimpleDim->GetDimLineB();
- //AFX_EXT_API KmPoint OrthPt2Ln(KmPoint pt,KmPoint ptb,KmPoint pte)
- KmPoint p4=::OrthPt2Ln(p2,p1,p3);
- double dAng=calculate_2dangle(p4.x-p2.x,p4.y-p2.y);
- double dDis=::sqrt((p4.x-p2.x)*(p4.x-p2.x)+(p4.y-p2.y)*(p4.y-p2.y))*0.5;
- KmPoint p5;
- p5.x=p3.x+dDis*cos(dAng);
- p5.y=p3.y+dDis*sin(dAng);
- return m_pConverter->ConverterEntity_AdSimpleDim(pSimpleDim,
- p1,
- p2,
- p5,
- dAng,
- hBlock,hDimstyle,blob);
- }
- BOOL CKmgReader::processentity_dim_radius(CKmDataManager* pData,KmObject* pObj,AD_OBJHANDLE hBlock,AD_OBJHANDLE hDimstyle,AD_VMADDR blob)
- {
- if(!pObj)return FALSE;
- if(!pObj->IsKindOf(RUNTIME_CLASS(KmRadiusDim)))return FALSE;
- KmRadiusDim* pRadiusDim=(KmRadiusDim*)pObj;
- KmPoint p1=(pRadiusDim->GetDimLt1B()+pRadiusDim->GetDimLt2B());
- p1.x=p1.x*0.5;
- p1.y=p1.y*0.5;
- return m_pConverter->ConverterEntity_AdRadiusDim(pRadiusDim,
- p1,
- pRadiusDim->GetDimLineB(),
- hBlock,hDimstyle,blob);
- }
- BOOL CKmgReader::processentity_dim_diameter(CKmDataManager* pData,KmObject* pObj,AD_OBJHANDLE hBlock,AD_OBJHANDLE hDimstyle,AD_VMADDR blob)
- {
- if(!pObj)return FALSE;
- if(!pObj->IsKindOf(RUNTIME_CLASS(KmDiameterDim)))return FALSE;
- KmDiameterDim* pDiameterDim=(KmDiameterDim*)pObj;
- return m_pConverter->ConverterEntity_AdDiameterDim(pDiameterDim,
- pDiameterDim->GetDimLt1B(),
- pDiameterDim->GetDimLt2B(),
- hBlock,hDimstyle,blob);
- }
- BOOL CKmgReader::processentity_dim_angle(CKmDataManager* pData,KmObject* pObj,AD_OBJHANDLE hBlock,AD_OBJHANDLE hDimstyle,AD_VMADDR blob)
- {
- if(!pObj)return FALSE;
- if(!pObj->IsKindOf(RUNTIME_CLASS(KmBaseAngleDim)))return FALSE;
- KmBaseAngleDim* pBaseAngleDim=(KmBaseAngleDim*)pObj;
- KmPoint p1=pBaseAngleDim->GetDimLt1B();
- KmPoint p2=pBaseAngleDim->GetDimLineB();
- KmPoint p3=pBaseAngleDim->GetDimLt2B();
- KmPoint p4=pBaseAngleDim->GetVertex();
- KmPoint p5=pBaseAngleDim->GetDimLinePos();
- double dAngle1B=0.0;
- double dAngle2B=0.0;
- double dRadius=0.0;
- {//已知 p1 p2 表示尺寸界线1 p3表示尺寸界线2的起点 p4表示顶点 p5表示控制点
- //求尺寸界线2的终点将它保存在p4
- dRadius=::sqrt((p4.x-p2.x)*(p4.x-p2.x)+(p4.y-p2.y)*(p4.y-p2.y));
- dAngle2B=calculate_2dangle(p3.x-p4.x,p3.y-p4.y);
- dAngle1B=calculate_2dangle(p1.x-p4.x,p1.y-p4.y);
- p4.x=p4.x+dRadius*cos(dAngle2B);
- p4.y=p4.y+dRadius*sin(dAngle2B);
- }
- {//对于p1与p2 p3与p4重合的情况需要适当偏移
- if( fabs(p1.x-p2.x)<PRECISION && fabs(p1.y-p2.y)<PRECISION )
- {
- p1.x=p1.x+dRadius*0.01*cos(dAngle1B+PI);
- p1.y=p1.y+dRadius*0.01*sin(dAngle1B+PI);
- }
- if( fabs(p3.x-p4.x)<PRECISION && fabs(p3.y-p4.y)<PRECISION )
- {
- p3.x=p3.x+dRadius*0.01*cos(dAngle2B+PI);
- p3.y=p3.y+dRadius*0.01*sin(dAngle2B+PI);
- }
- }
- return m_pConverter->ConverterEntity_AdAngleDim(pBaseAngleDim,
- p1,p2,p3,p4,p5,
- hBlock,hDimstyle,blob);
- }