Processfile7.cpp
上传用户:hell82222
上传日期:2013-12-19
资源大小:1872k
文件大小:14k
- // KMCAD40-FileSwitch-Processfile7.cpp-1.0
- // KmgReader.cpp: implementation of the CKmgReader class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "FileSwitch.h"
- #include "KmgReader.h"
- #include "Database.h"
- #include "Reader.h"
- #include "CShow.h"
- #include "KmObject.h"
- #include "EntDef.h"
- #include "block.h"
- #include "KmDim.h"
- #include "KmSymbl.h"
- #include "KmTable.h"
- #include "KmSection.h"
- #include "KmPartNo.h"
- #include "ArcText.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(CKmDataManager* pData)
- {
- KmBuffer buff;
- CShow* pShow = new CGDIShow((CWnd*)NULL);
- KmObject* pObj;
- for(UINT index=0;index<::GetEntDicSize();index++)
- {
- if(!::GetEntDicAt(index))continue;
- KmIteratorPtr pI(pData->CreateIterator(::GetEntDicAt(index)));
-
- KmObject* pTemp=(KmObject*)::GetEntDicAt(index)->CreateObject();
- if(!pTemp)continue;
- if(pTemp->Type()=="KmBlockRef")
- {
- for(pI->First(); !pI->IsDone(); pI->Next())
- {
- pObj = pI->CurrentItem();
- if(((KmBlockRef*)pObj)->GetKmAttrMap())
- {
- if(((KmBlockRef*)pObj)->GetKmAttrMap()->GetAttrItems())
- {
- if(((KmBlockRef*)pObj)->GetKmAttrMap()->GetAttrItems()->GetCount())
- {//如果是属性块则另行创建块定义
- processentityhead(pData,pObj);
- CMatch2* match=new CMatch2;
- //1.创建块定义
- CString str;
- str.Format("%s%d",pObj->GetObjectID().GetClassID(),pObj->GetObjectID().dwEntIndex);
- m_pConverter->ConverterEntity_KmBlockdef(str,match);
- m_pConverter->SetBlockDataVassel(match->m_handle);
- //2.增加AD_ENT_BLOCK
- m_pConverter->AddBegBlkSign(0.0,0.0,0.0);
- processentityhead(pData,pObj);
- processentity_buf(pData,pObj);
- m_pConverter->AddEndBlkSign();
- m_pConverter->ConverterEntity_AdInsert(0.0,0.0,0.0,1.0,1.0,1.0,0.0,match->m_handle);
- delete match;
- continue;
- }
- }
- }
- processentityhead(pData,pObj);
- AD_OBJHANDLE handle;
- KmBlockRef* pRef=(KmBlockRef*)pObj;
- m_ablock.Get(handle,pRef->GetBlockDefID());
- m_pConverter->ConverterEntity_AdInsert(pRef->GetInsertPoint().x,pRef->GetInsertPoint().y,0.0,pRef->GetScale(),pRef->GetScale(),pRef->GetScale(),pRef->GetAngle(),handle);
- }
- }
- else if( (pTemp->IsKindOf(RUNTIME_CLASS(KmSymbl)))||
- //(pTemp->IsKindOf(RUNTIME_CLASS(KmTable)))||
- (pTemp->IsKindOf(RUNTIME_CLASS(KmText)))||
- (pTemp->IsKindOf(RUNTIME_CLASS(KmArcText)))||
- (pTemp->IsKindOf(RUNTIME_CLASS(KmPartSerialNo)))||
- (pTemp->IsKindOf(RUNTIME_CLASS(KmSection))))
- {
- for(pI->First(); !pI->IsDone(); pI->Next())
- {
- pObj = pI->CurrentItem();
- if(pObj->GetFlag()&KMOBJ_HIDED)
- {
- continue;
- }
- processentityhead(pData,pObj);
- CMatch2* match=new CMatch2;
- //1.创建块定义
- CString str;
- str.Format("%s%d",pObj->GetObjectID().GetClassID(),pObj->GetObjectID().dwEntIndex);
- m_pConverter->ConverterEntity_KmBlockdef(str,match);
- m_pConverter->SetBlockDataVassel(match->m_handle);
- //2.增加AD_ENT_BLOCK
- m_pConverter->AddBegBlkSign(0.0,0.0,0.0);
- processentityhead(pData,pObj);
- processentity_buf(pData,pObj);
- m_pConverter->AddEndBlkSign();
- m_pConverter->ConverterEntity_AdInsert(0.0,0.0,0.0,1.0,1.0,1.0,0.0,match->m_handle);
- delete match;
- }
- }
- else if( pTemp->IsKindOf(RUNTIME_CLASS(KmDim)) )
- {
- for(pI->First(); !pI->IsDone(); pI->Next())
- {
- pObj = pI->CurrentItem();
- CMatch2* match=new CMatch2;
- //1.创建块定义
- CString str;
- str.Format("%s%d",pObj->GetObjectID().GetClassID(),pObj->GetObjectID().dwEntIndex);
- m_pConverter->ConverterEntity_KmBlockdef(str,match);
- m_pConverter->SetBlockDataVassel(match->m_handle);
- //2.增加AD_ENT_BLOCK
- m_pConverter->AddBegBlkSign(0.0,0.0,0.0);
- processentityhead(pData,pObj);
- processentity_buf(pData,pObj);
- m_pConverter->AddEndBlkSign();
- processentityhead(pData,pObj);
- if(!processentity_dim(pData,pObj,match->m_handle))
- {
- delete match;
- m_pConverter->ConverterEntity_AdInsert(0.0,0.0,0.0,1.0,1.0,1.0,0.0,match->m_handle);
- }
- else
- {
- delete match;
- }
- }
- }
- else if( pTemp->IsKindOf(RUNTIME_CLASS(KmLine)) )
- {
- for(pI->First(); !pI->IsDone(); pI->Next())
- {
- pObj = pI->CurrentItem();
- processentityhead(pData,pObj);
- m_pConverter->ConverterEntity_AdLine(((KmLine*)pObj)->bx,((KmLine*)pObj)->by,0.0,((KmLine*)pObj)->ex,((KmLine*)pObj)->ey,0.0);
- }
- }
- else if( pTemp->IsKindOf(RUNTIME_CLASS(KmCircle)) )
- {
- for(pI->First(); !pI->IsDone(); pI->Next())
- {
- pObj = pI->CurrentItem();
- processentityhead(pData,pObj);
- if(((KmCircle*)pObj)->message&MESSAGE_CIRCLE_FULL)
- {
- m_pConverter->ConverterEntity_AdCircle(((KmCircle*)pObj)->GetCenter().x,((KmCircle*)pObj)->GetCenter().y,0,((KmCircle*)pObj)->GetRadius());
- }
- else if(((KmCircle*)pObj)->message&MESSAGE_CIRCLE_NEGATIVE)
- {
- m_pConverter->ConverterEntity_AdArc(((KmCircle*)pObj)->GetCenter().x,((KmCircle*)pObj)->GetCenter().y,0,((KmCircle*)pObj)->GetRadius(),((KmCircle*)pObj)->e_angle,((KmCircle*)pObj)->b_angle);
- }
- else
- {
- m_pConverter->ConverterEntity_AdArc(((KmCircle*)pObj)->GetCenter().x,((KmCircle*)pObj)->GetCenter().y,0,((KmCircle*)pObj)->GetRadius(),((KmCircle*)pObj)->b_angle,((KmCircle*)pObj)->e_angle);
- }
- }
- }
- else
- {
- for(pI->First(); !pI->IsDone(); pI->Next())
- {
- pObj = pI->CurrentItem();
- processentityhead(pData,pObj);
- if(!processentity(pData,pObj))
- {
- pObj->Draw(pShow,pObj->color,DRAWPRESENT,&buff);
- }
- }
- }
- delete pTemp;
- }
- int size=buff.GetLineBuffSize();
- for(int i=0;i<size;i++)
- {
- if(!processentity_buf_line(pData,buff.GetLineEnt(i)))
- {
- _WRITE(str="转换buf直线失败");
- }
- }
- size=buff.GetCircleBuffSize();
- for(i=0;i<size;i++)
- {
- if(!processentity_buf_circle(pData,buff.GetCircleEnt(i)))
- {
- _WRITE(str="转换buf圆失败");
- }
- }
- size=buff.GetRegionBuffSize();
- for(i=0;i<size;i++)
- {
- if(!processentity_buf_region(pData,buff.GetRegionEnt(i)))
- {
- _WRITE(str="转换buf区域失败");
- }
- }
- size=buff.GetTextBuffSize();
- for(i=0;i<size;i++)
- {
- if(!processentity_buf_text(pData,buff.GetTextEnt(i)))
- {
- _WRITE(str="转换buf文字失败");
- }
- }
- delete pShow;
- buff.ClearKmBuffer();
- return TRUE;
- }
- BOOL CKmgReader::processentity(CKmDataManager* pData,KmObject* pObj)
- {
- return processentity_buf(pData,pObj);
- }
- BOOL CKmgReader::processentity_buf(CKmDataManager* pData,KmObject* pObj)
- {
- KmBuffer buff;
- CShow* pShow = new CGDIShow((CWnd*)NULL);
- pObj->Draw(pShow,pObj->color,DRAWPRESENT,&buff);
- int size=buff.GetLineBuffSize();
- for(int i=0;i<size;i++)
- {
- if(!processentity_buf_line(pData,buff.GetLineEnt(i)))
- {
- _WRITE(str="转换buf直线失败");
- }
- }
- size=buff.GetCircleBuffSize();
- for(i=0;i<size;i++)
- {
- if(!processentity_buf_circle(pData,buff.GetCircleEnt(i)))
- {
- _WRITE(str="转换buf圆失败");
- }
- }
- size=buff.GetRegionBuffSize();
- for(i=0;i<size;i++)
- {
- if(!processentity_buf_region(pData,buff.GetRegionEnt(i)))
- {
- _WRITE(str="转换buf区域失败");
- }
- }
- size=buff.GetTextBuffSize();
- for(i=0;i<size;i++)
- {
- if(!processentity_buf_text(pData,buff.GetTextEnt(i)))
- {
- _WRITE(str="转换buf文字失败");
- }
- }
- delete pShow;
- buff.ClearKmBuffer();
- return TRUE;
- }
- BOOL CKmgReader::processentity_buf_line(CKmDataManager* pData,S_LINE_BUFFER* line)
- {
- ENTDWGHEAD headback=m_pConverter->m_enthead;
- short scolor;
- if(line->Color==COLOR_BYBLOCK)
- {
- scolor=AD_COLOR_BYBLOCK;
- }
- else if(line->Color==COLOR_BYLAYER)
- {
- scolor=AD_COLOR_BYLAYER;
- }
- else
- {
- scolor=AD_COLOR_BYLAYER;
- for(int i=1;i<m_aColor.GetSize();i++)
- {
- if( (fabs(GetRValue(line->Color)-GetRValue(m_aColor[i]))+
- fabs(GetGValue(line->Color)-GetGValue(m_aColor[i]))+
- fabs(GetBValue(line->Color)-GetBValue(m_aColor[i])))<20)
- {
- scolor=i;
- break;
- }
- }
- }
- //2
- short swidth=1;
- double dscale=1.0;
- AD_OBJHANDLE hltype;
- if(line->Width==ABS_THIN_WIDTH)
- {
- swidth=0;
- }
- else if(line->Width==LWIDTH_BYLAYER)
- {
- swidth=(short)AD_WEIGHT_BYLAYER;
- }
- else if(line->Width==LWIDTH_BYBLOCK)
- {
- swidth=(short)AD_WEIGHT_BYBLOCK;
- }
- else
- {
- swidth=(short)(::GetLineWidthAsDouble(line->Width)*100.0);
- if(swidth<=5)swidth=5;
- else if(swidth<=9)swidth=9;
- else if(swidth<=13)swidth=13;
- else if(swidth<=15)swidth=15;
- else if(swidth<=18)swidth=18;
- else if(swidth<=20)swidth=20;
- else if(swidth<=25)swidth=25;
- else if(swidth<=30)swidth=30;
- else if(swidth<=35)swidth=35;
- else if(swidth<=40)swidth=40;
- else if(swidth<=50)swidth=50;
- else if(swidth<=53)swidth=53;
- else if(swidth<=60)swidth=60;
- else if(swidth<=70)swidth=70;
- else if(swidth<=80)swidth=80;
- else if(swidth<=90)swidth=90;
- else if(swidth<=100)swidth=100;
- else if(swidth<=106)swidth=106;
- else if(swidth<=120)swidth=120;
- else if(swidth<=140)swidth=140;
- else if(swidth<=158)swidth=158;
- else if(swidth<=200)swidth=200;
- else swidth=211;
- }
- m_altype.Get(hltype,line->LineType);
- dscale=line->LineScale;
- m_pConverter->WriteEnthead(scolor,swidth,dscale,hltype,headback.hlayer);
- m_pConverter->ConverterEntity_AdLine(line->P1.x,line->P1.y,0,line->P2.x,line->P2.y,0);
- m_pConverter->m_enthead=headback;
- return TRUE;
- }
- BOOL CKmgReader::processentity_buf_circle(CKmDataManager* pData,S_CIRCLE_BUFFER* circle)
- {
- ENTDWGHEAD headback=m_pConverter->m_enthead;
- short scolor;
- if(circle->Color==COLOR_BYBLOCK)
- {
- scolor=AD_COLOR_BYBLOCK;
- }
- else if(circle->Color==COLOR_BYLAYER)
- {
- scolor=AD_COLOR_BYLAYER;
- }
- else
- {
- scolor=AD_COLOR_BYLAYER;
- for(int i=1;i<m_aColor.GetSize();i++)
- {
- if( (fabs(GetRValue(circle->Color)-GetRValue(m_aColor[i]))+
- fabs(GetGValue(circle->Color)-GetGValue(m_aColor[i]))+
- fabs(GetBValue(circle->Color)-GetBValue(m_aColor[i])))<20)
- {
- scolor=i;
- break;
- }
- }
- }
- //2
- short swidth=1;
- double dscale=1.0;
- AD_OBJHANDLE hltype;
- if(circle->Width==ABS_THIN_WIDTH)
- {
- swidth=0;
- }
- else if(circle->Width==LWIDTH_BYLAYER)
- {
- swidth=(short)AD_WEIGHT_BYLAYER;
- }
- else if(circle->Width==LWIDTH_BYBLOCK)
- {
- swidth=(short)AD_WEIGHT_BYBLOCK;
- }
- else
- {
- swidth=(short)(::GetLineWidthAsDouble(circle->Width)*100.0);
- if(swidth<=5)swidth=5;
- else if(swidth<=9)swidth=9;
- else if(swidth<=13)swidth=13;
- else if(swidth<=15)swidth=15;
- else if(swidth<=18)swidth=18;
- else if(swidth<=20)swidth=20;
- else if(swidth<=25)swidth=25;
- else if(swidth<=30)swidth=30;
- else if(swidth<=35)swidth=35;
- else if(swidth<=40)swidth=40;
- else if(swidth<=50)swidth=50;
- else if(swidth<=53)swidth=53;
- else if(swidth<=60)swidth=60;
- else if(swidth<=70)swidth=70;
- else if(swidth<=80)swidth=80;
- else if(swidth<=90)swidth=90;
- else if(swidth<=100)swidth=100;
- else if(swidth<=106)swidth=106;
- else if(swidth<=120)swidth=120;
- else if(swidth<=140)swidth=140;
- else if(swidth<=158)swidth=158;
- else if(swidth<=200)swidth=200;
- else swidth=211;
- }
- m_altype.Get(hltype,circle->LineType);
- dscale=circle->LineScale;
- m_pConverter->WriteEnthead(scolor,swidth,dscale,hltype,headback.hlayer);
- if(circle->message&MESSAGE_CIRCLE_FULL)
- {
- m_pConverter->ConverterEntity_AdCircle(circle->center.x,circle->center.y,0,circle->radius);
- }
- else if(circle->message&MESSAGE_CIRCLE_NEGATIVE)
- {
- m_pConverter->ConverterEntity_AdArc(circle->center.x,circle->center.y,0,circle->radius,circle->e_angle,circle->b_angle);
- }
- else
- {
- m_pConverter->ConverterEntity_AdArc(circle->center.x,circle->center.y,0,circle->radius,circle->b_angle,circle->e_angle);
- }
- m_pConverter->m_enthead=headback;
- return TRUE;
- }
- BOOL CKmgReader::processentity_buf_region(CKmDataManager* pData,S_REGION* region)
- {
- short scolor = AD_COLOR_BYLAYER;
- if(region->Color==COLOR_BYBLOCK)
- {
- scolor=AD_COLOR_BYBLOCK;
- }
- else if(region->Color==COLOR_BYLAYER)
- {
- scolor=AD_COLOR_BYLAYER;
- }
- else
- {
- for(int i=1;i<m_aColor.GetSize();i++)
- {
- if( (fabs(GetRValue(region->Color)-GetRValue(m_aColor[i]))+
- fabs(GetGValue(region->Color)-GetGValue(m_aColor[i]))+
- fabs(GetBValue(region->Color)-GetBValue(m_aColor[i])))<20)
- {
- scolor=i;
- break;
- }
- }
- }
- if(region->ptNum==3)
- {
- m_pConverter->ConverterEntity_AdSolid(scolor,region->p1.x,region->p1.y,region->p2.x,region->p2.y,region->p3.x,region->p3.y,region->p3.x,region->p3.y);
- }
- else if(region->ptNum==4)
- {
- m_pConverter->ConverterEntity_AdSolid(scolor,region->p1.x,region->p1.y,region->p2.x,region->p2.y,region->p3.x,region->p3.y,region->p4.x,region->p4.y);
- }
- return TRUE;
- }
- BOOL CKmgReader::processentity_buf_text(CKmDataManager* pData,S_TEXT* text)
- {
- ENTDWGHEAD headback=m_pConverter->m_enthead;
- short scolor;
- if(text->m_dwColor==COLOR_BYBLOCK)
- {
- scolor=AD_COLOR_BYBLOCK;
- }
- else if(text->m_dwColor==COLOR_BYLAYER)
- {
- scolor=AD_COLOR_BYLAYER;
- }
- else
- {
- scolor=AD_COLOR_BYLAYER;
- for(int i=1;i<m_aColor.GetSize();i++)
- {
- if( (fabs(GetRValue(text->m_dwColor)-GetRValue(m_aColor[i]))+
- fabs(GetGValue(text->m_dwColor)-GetGValue(m_aColor[i]))+
- fabs(GetBValue(text->m_dwColor)-GetBValue(m_aColor[i])))<20)
- {
- scolor=i;
- break;
- }
- }
- }
- m_pConverter->WriteEnthead(scolor,headback.swidth,headback.dscale,headback.hltype,headback.hlayer);
- m_pConverter->ConverterEntity_AdText(text);
- m_pConverter->m_enthead=headback;
- return TRUE;
- }