Processfile8.cpp
上传用户:hell82222
上传日期:2013-12-19
资源大小:1872k
文件大小:6k
源码类别:

CAD

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "FileSwitch.h"
  3. #include "IgesReader.h"
  4. #include "KmgReader.h"
  5. #include "KmDim.h"
  6. #include "DSSubst.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. extern CStdioFile g_CensorialFile; //监察转换进度的文件
  13. extern int g_mode;
  14. BOOL CKmgReader::processentity_dim(CKmDataManager* pData,KmObject* pObj,AD_OBJHANDLE handle)
  15. {
  16. if(!pObj)return FALSE;
  17. if(!pObj->IsKindOf(RUNTIME_CLASS(KmDim)))return FALSE;
  18. AD_OBJHANDLE hDimstyle;
  19. if(!m_adimstyle.Get(hDimstyle,((KmDim*)pObj)->GetDimStyleID()))
  20. {
  21. return FALSE;
  22. }
  23. //extern  AD_VMADDR ADCDECL adCreateBlobEx _((short chunksize));
  24. //#define                adCreateBlob() adCreateBlobEx(4096)
  25. //extern  short  ADCDECL adDeleteBlob _((AD_VMADDR blob));
  26. AD_VMADDR blob=adCreateBlob();//样式替代大小应小于4096
  27. KmDim* pDim=(KmDim*)pObj;
  28. KmDimStlAcsMgr* pDimStlAcsMgr=pDim->GetDSAMgr();
  29. if(pDimStlAcsMgr)
  30. {
  31. CDSSubst* pDSSubst=pDimStlAcsMgr->GetVarSel(pDim->GetDimStyleID());
  32. if(pDSSubst)
  33. {
  34. if(pDSSubst->GetSubstVarNum()!=0)
  35. {
  36. //BOOL processentity_dim_blob(CDSSubst* pDSSubst,AD_VMADDR blob);
  37. if(!processentity_dim_blob(pDSSubst,blob))
  38. {
  39. adDeleteBlob(blob);
  40. blob=NULL;
  41. }
  42. }
  43. else
  44. {
  45. adDeleteBlob(blob);
  46. blob=NULL;
  47. }
  48. }
  49. else
  50. {
  51. adDeleteBlob(blob);
  52. blob=NULL;
  53. }
  54. }
  55. else
  56. //如果没有样式替代则
  57. {
  58. adDeleteBlob(blob);
  59. blob=NULL;
  60. }
  61. if(pObj->IsKindOf(RUNTIME_CLASS(KmSimpleDim)))
  62. //(KmSimpleDim));
  63. //(KmCoSerialSimpleDim));
  64. //(KmDaSerialSimpleDim));
  65. //(KmGeSerialSimpleDim));
  66. //(KmSyHalfSimpleDim));
  67. //(KmSyDiameterDim));
  68. {
  69. if(!processentity_dim_simple(pData,pObj,handle,hDimstyle,blob))
  70. {
  71. adDeleteBlob(blob);
  72. return FALSE;
  73. }
  74. return TRUE;
  75. }
  76. else if(pObj->IsKindOf(RUNTIME_CLASS(KmRadiusDim)))
  77. //(KmRadiusDim));
  78. {
  79. if(!processentity_dim_radius(pData,pObj,handle,hDimstyle,blob))
  80. {
  81. adDeleteBlob(blob);
  82. return FALSE;
  83. }
  84. return TRUE;
  85. }
  86. else if(pObj->IsKindOf(RUNTIME_CLASS(KmDiameterDim)))
  87. //(KmDiameterDim));
  88. {
  89. if(!processentity_dim_diameter(pData,pObj,handle,hDimstyle,blob))
  90. {
  91. adDeleteBlob(blob);
  92. return FALSE;
  93. }
  94. return TRUE;
  95. }
  96. else if(pObj->IsKindOf(RUNTIME_CLASS(KmBaseAngleDim)))
  97. //(KmBaseAngleDim));
  98. //(KmArcLenDim));
  99. //(KmAngleDim));           
  100. //(KmVAngleDim));
  101. //(KmSyHalfAngleDim));
  102. {
  103. if(!processentity_dim_angle(pData,pObj,handle,hDimstyle,blob))
  104. {
  105. adDeleteBlob(blob);
  106. return FALSE;
  107. }
  108. return TRUE;
  109. }
  110. adDeleteBlob(blob);
  111. return FALSE;
  112. }
  113. BOOL CKmgReader::processentity_dim_simple(CKmDataManager* pData,KmObject* pObj,AD_OBJHANDLE hBlock,AD_OBJHANDLE hDimstyle,AD_VMADDR blob)
  114. {
  115. if(!pObj)return FALSE;
  116. if(!pObj->IsKindOf(RUNTIME_CLASS(KmSimpleDim)))return FALSE;
  117. KmSimpleDim* pSimpleDim=(KmSimpleDim*)pObj;
  118. //东方CAD保证LINEB与LT1B在同一条尺寸引出线上
  119. KmPoint p1=pSimpleDim->GetDimLt1B();
  120. KmPoint p2=pSimpleDim->GetDimLt2B();
  121. KmPoint p3=pSimpleDim->GetDimLineB();
  122. //AFX_EXT_API KmPoint OrthPt2Ln(KmPoint pt,KmPoint ptb,KmPoint pte)
  123. KmPoint p4=::OrthPt2Ln(p2,p1,p3);
  124. double dAng=calculate_2dangle(p4.x-p2.x,p4.y-p2.y);
  125. double dDis=::sqrt((p4.x-p2.x)*(p4.x-p2.x)+(p4.y-p2.y)*(p4.y-p2.y))*0.5;
  126. KmPoint p5;
  127. p5.x=p3.x+dDis*cos(dAng);
  128. p5.y=p3.y+dDis*sin(dAng);
  129. return m_pConverter->ConverterEntity_AdSimpleDim(pSimpleDim,
  130. p1,
  131. p2,
  132. p5,
  133. dAng,
  134. hBlock,hDimstyle,blob);
  135. }
  136. BOOL CKmgReader::processentity_dim_radius(CKmDataManager* pData,KmObject* pObj,AD_OBJHANDLE hBlock,AD_OBJHANDLE hDimstyle,AD_VMADDR blob)
  137. {
  138. if(!pObj)return FALSE;
  139. if(!pObj->IsKindOf(RUNTIME_CLASS(KmRadiusDim)))return FALSE;
  140. KmRadiusDim* pRadiusDim=(KmRadiusDim*)pObj;
  141. KmPoint p1=(pRadiusDim->GetDimLt1B()+pRadiusDim->GetDimLt2B());
  142. p1.x=p1.x*0.5;
  143. p1.y=p1.y*0.5;
  144. return m_pConverter->ConverterEntity_AdRadiusDim(pRadiusDim,
  145. p1,
  146. pRadiusDim->GetDimLineB(),
  147. hBlock,hDimstyle,blob);
  148. }
  149. BOOL CKmgReader::processentity_dim_diameter(CKmDataManager* pData,KmObject* pObj,AD_OBJHANDLE hBlock,AD_OBJHANDLE hDimstyle,AD_VMADDR blob)
  150. {
  151. if(!pObj)return FALSE;
  152. if(!pObj->IsKindOf(RUNTIME_CLASS(KmDiameterDim)))return FALSE;
  153. KmDiameterDim* pDiameterDim=(KmDiameterDim*)pObj;
  154. return m_pConverter->ConverterEntity_AdDiameterDim(pDiameterDim,
  155. pDiameterDim->GetDimLt1B(),
  156. pDiameterDim->GetDimLt2B(),
  157. hBlock,hDimstyle,blob);
  158. }
  159. BOOL CKmgReader::processentity_dim_angle(CKmDataManager* pData,KmObject* pObj,AD_OBJHANDLE hBlock,AD_OBJHANDLE hDimstyle,AD_VMADDR blob)
  160. {
  161. if(!pObj)return FALSE;
  162. if(!pObj->IsKindOf(RUNTIME_CLASS(KmBaseAngleDim)))return FALSE;
  163. KmBaseAngleDim* pBaseAngleDim=(KmBaseAngleDim*)pObj;
  164. KmPoint p1=pBaseAngleDim->GetDimLt1B();
  165. KmPoint p2=pBaseAngleDim->GetDimLineB();
  166. KmPoint p3=pBaseAngleDim->GetDimLt2B();
  167. KmPoint p4=pBaseAngleDim->GetVertex();
  168. KmPoint p5=pBaseAngleDim->GetDimLinePos();
  169. double dAngle1B=0.0;
  170. double dAngle2B=0.0;
  171. double dRadius=0.0;
  172. {//已知 p1  p2 表示尺寸界线1  p3表示尺寸界线2的起点 p4表示顶点 p5表示控制点 
  173. //求尺寸界线2的终点将它保存在p4
  174. dRadius=::sqrt((p4.x-p2.x)*(p4.x-p2.x)+(p4.y-p2.y)*(p4.y-p2.y));
  175. dAngle2B=calculate_2dangle(p3.x-p4.x,p3.y-p4.y);
  176. dAngle1B=calculate_2dangle(p1.x-p4.x,p1.y-p4.y);
  177. p4.x=p4.x+dRadius*cos(dAngle2B);
  178. p4.y=p4.y+dRadius*sin(dAngle2B);
  179. }
  180. {//对于p1与p2  p3与p4重合的情况需要适当偏移
  181. if( fabs(p1.x-p2.x)<PRECISION && fabs(p1.y-p2.y)<PRECISION )
  182. {
  183. p1.x=p1.x+dRadius*0.01*cos(dAngle1B+PI);
  184. p1.y=p1.y+dRadius*0.01*sin(dAngle1B+PI);
  185. }
  186. if( fabs(p3.x-p4.x)<PRECISION && fabs(p3.y-p4.y)<PRECISION )
  187. {
  188. p3.x=p3.x+dRadius*0.01*cos(dAngle2B+PI);
  189. p3.y=p3.y+dRadius*0.01*sin(dAngle2B+PI);
  190. }
  191. }
  192. return m_pConverter->ConverterEntity_AdAngleDim(pBaseAngleDim,
  193. p1,p2,p3,p4,p5,
  194. hBlock,hDimstyle,blob);
  195. }