KmgConverter.cpp
上传用户:hell82222
上传日期:2013-12-19
资源大小:1872k
文件大小:30k
- // KMCAD40-FileSwitch-KmgConverter.cpp-1.0
- // KmgConverter.cpp: implementation of the CKmgConverter class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "FileSwitch.h"
- #include "KmgConverter.h"
- #include "KmLayer.h"
- #include "showdef.h"
- #include "entdef.h"
- #include "KmEntity.h"
- #include "Block.h"
- #include "KmText.h"
- #include "KmGroup.h"
- #include "WordStyle.h"
- #include "DwgReader.h"
- #include "DBDef.h"
- #include "Reader.h"
- #include "KmSelectObjs.h"
- #include "dimstyle.h"
- #include <atlbase.h>
- #include "database.h"
- #include "ExtendInfoIdentify.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- extern CStdioFile g_CensorialFile; //监察转换进度的文件
- extern int g_mode;
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CKmgConverter::CKmgConverter(CCommandInfo* pCommand)
- {
- m_dSysDimScale=1.0;
- m_pCommand=pCommand;
- }
- CKmgConverter::~CKmgConverter()
- {
- }
- BOOL CKmgConverter::BeginConverter()
- {
- try
- {
- m_pDataManager=new CKmDataManager;
- ::SetActiveDataManager(m_pDataManager);
- m_pDataManager->Init();
- }
- catch(CMemoryException* e)
- {
- TCHAR szCause[255];
- e->GetErrorMessage(szCause, 255);
- _WRITE(str=szCause);
- return FALSE;
- }
- catch(...)
- {
- _WRITE(str="构造KM数据库时发生未知错误");
- return FALSE;
- }
- ::SetActiveDataManager(m_pDataManager);
- m_dDataVessel=DATAVESSEL_DATABASE;
- return TRUE;
- }
- BOOL CKmgConverter::EndConverter()
- {
- while(m_ModelSpace.GetCount()!=0)
- {
- delete m_ModelSpace.RemoveHead();
- }
-
- delete m_pDataManager;
- ::SetActiveDataManager(NULL);
- m_aLayerStatus.RemoveAll();
- return TRUE;
- }
- BOOL CKmgConverter::ConverterDbVar(KMDBVarID nID, VARIANT& var)
- {
- m_pDataManager->SetDBVar(nID,var);
- return TRUE;
- }
- DWORD CKmgConverter::ConverterEnthead_Layer(
- BOOL bOn,
- BOOL bFrozen,
- CString strName,
- int icolor,
- int ilwidth,
- int iltype)
- {
- KmLayer* pLayer=new KmLayer;
- pLayer->Off(!bOn);
- pLayer->Frozen(bFrozen);
- pLayer->SetLineWidth(ilwidth);
- pLayer->SetLineType(iltype);
- pLayer->SetName(strName);
- pLayer->SetColor(icolor);
- pLayer->SetDeclare("转换至"+strName+"层");
-
- CString strTemp=strName;
- int iSameNum=1;
- //需要判断重名的情况.
- UINT KmID=0;
- while( (KmID=m_pDataManager->AddLayer(pLayer))==0)
- {
- iSameNum++;
- strTemp.Format("%s#%d",strName,iSameNum);
- pLayer->SetName(strTemp);
- }
- delete pLayer;
- return KmID;
- }
- DWORD CKmgConverter::ConverterEnthead_Blockdefine(
- CString strName,
- CString strDescription)
- {
- static int iSameNum=1;
- CString strTemp;
- KmBlockDef* pBlockDef=new KmBlockDef;
- if(strName.Find('*'))//系统块
- {
- strTemp.Format("%s#%d",strName,iSameNum);
- pBlockDef->SetName(strTemp);
- iSameNum++;
- }
- else
- {
- pBlockDef->SetName(strName);
- }
- pBlockDef->SetDeclare("转换至"+strName+"块,描述:"+strDescription);
- strTemp=strName;
- UINT KmID=0;
- while( (KmID=m_pDataManager->AddBlockDef(pBlockDef))==0)
- {
- strTemp.Format("%s#%d",strName,iSameNum);
- pBlockDef->SetName(strTemp);
- iSameNum++;
- }
- delete pBlockDef;
- return KmID;
- }
- BOOL CKmgConverter::CheckNoUseBlock(DWORD dwKmID)
- {
- KmBlockDef* pBlockDef=m_pDataManager->GetBlockDef(dwKmID);
- if(!pBlockDef)
- {
- return FALSE;
- }
- if(pBlockDef->GetObjectNum()<=0)
- {
- m_pDataManager->DeleteBlockDef(dwKmID);
- return FALSE;
- }
- return TRUE;
- }
- BOOL CKmgConverter::SetDataVessel(int dVessel,DWORD dwKmID)
- {
- m_dDataVessel=dVessel;
- if(dVessel==DATAVESSEL_BLOCKDEF)
- {
- m_pActiveBlockDef=m_pDataManager->GetBlockDef(dwKmID);
- if(m_pActiveBlockDef)
- {
- return TRUE;
- }
- return FALSE;
- }
- return TRUE;
- }
- int CKmgConverter::GetDataVessel(DWORD& dwKmID)
- {
- dwKmID=-1;
- if(m_pActiveBlockDef&&m_dDataVessel==DATAVESSEL_BLOCKDEF)
- {
- try
- {
- dwKmID=m_pActiveBlockDef->GetID();
- }
- catch(...)
- {
- return m_dDataVessel;
- }
- }
- return m_dDataVessel;
- }
- void CKmgConverter::WriteEnthead(int ilwidth,int icolor,int iltype,double dlscale,UINT idlayer)
- {
- m_enthead.ilwidth = ilwidth ;
- m_enthead.icolor = icolor ;
- m_enthead.iltype = iltype ;
- m_enthead.dlscale = dlscale ;
- m_enthead.idlayer = idlayer ;
- }
- void CKmgConverter::WriteEnthead(int icolor,int iltype)
- {
- m_enthead.icolor = icolor ;
- m_enthead.iltype = iltype ;
- }
- /* x
- 函数说明:
- 功能:将模型空间的实体通过视口导入纸区空间。
- 参数:变换矩阵和变换范围。
- */
- void CKmgConverter::UniteModelToSpace(double xoffset,double yoffset,double zoffset,double scale,double minx,double miny,double maxx,double maxy,int mode)
- {
- //{准备变换矩阵。
- if(fabs(scale)<PRECISION)
- {
- scale=1.0;
- }
- KmPoint pOffset(xoffset,yoffset);
- KmPoint pZero(0.0,0.0);
- //}
- //{准备筛选矩形。
- KmRect rect(minx,maxy,maxx,miny);
- rect.NormalizeRect();
- //}
- //{准备临时变量。
- SELECTOBJS SelectedObjs;
- KmSelectObjs KmSelectedObjs(&SelectedObjs);
- KmObject* pObj=NULL;
- KmObject* pCopy=NULL;
- //}
- m_pDataManager->StartModify();
- POSITION pos=m_ModelSpace.GetHeadPosition();
- while(pos!=NULL)
- {
- pObj=m_ModelSpace.GetNext(pos);
- if(pObj)
- {
- pCopy=(KmObject*)pObj->GetRuntimeClass()->CreateObject();
- pCopy->Copy(pObj);
- if(pCopy->IsKindOf(RUNTIME_CLASS(KmGroup)))
- {
- ((KmGroup*)pCopy)->StartForbidRefresh();
- pCopy->Zoom(scale,pZero);
- pCopy->Move(pOffset);
- ((KmGroup*)pCopy)->EndForbidRefresh();
- }
- else
- {
- pCopy->Zoom(scale,pZero);
- pCopy->Move(pOffset);
- }
- pCopy->ReCalculateRect();
- //{如果实体的矩形与给定的矩形无交则不转换
- if(!pCopy->ConjointCalculatedRect(rect))
- {
- delete pCopy;
- continue;
- }
- //}
- //按布局(图纸空间)缩放标注 根据当前模型空间视口和图纸空间的比例确定比例因子。AutoCAD 把该值当作 0 保存在 DIMSCALE 系统变量里。
- if(pCopy->GetRuntimeClass()->IsDerivedFrom(RUNTIME_CLASS(KmDim)))
- {
- if(((KmDim*)pCopy)->GetDSAMgr())//对于尺寸如果它的DIMSCALE==0的话设置为s
- {
- {
- VARIANT var;
- memset(&var,0,sizeof(VARIANT));
- ((KmDim*)pCopy)->GetDSAMgr()->GetDsVar(DIMSCALE,var);
- if(fabs(var.dblVal)<PRECISION)
- {
- var.vt=VT_R8;
- var.dblVal=scale;
- ((KmDim*)pCopy)->GetDSAMgr()->SetDsVar(DIMSCALE,var);
- }
- else
- {
- var.vt=VT_R8;
- try
- {
- var.dblVal*=scale;
- }
- catch(...)
- {
- }
- ((KmDim*)pCopy)->GetDSAMgr()->SetDsVar(DIMSCALE,var);
- }
- }
- {
- VARIANT var;
- memset(&var,0,sizeof(VARIANT));
- ((KmDim*)pCopy)->GetDSAMgr()->GetDsVar(DIMLFAC,var);
- var.vt=VT_R8;
- try
- {
- var.dblVal/=scale;
- }
- catch(...)
- {
- }
- ((KmDim*)pCopy)->GetDSAMgr()->SetDsVar(DIMLFAC,var);
- }
- }
- }
- if((mode!=2)||(!pCopy->GetRuntimeClass()->IsDerivedFrom(RUNTIME_CLASS(KmCurve))))
- {
- m_pDataManager->AddObj(pCopy,TRUE);
- delete pCopy;
- continue;
- }
- KmSelectedObjs.RemoveAll();
- pCopy->DoRectSelect(7,rect,SelectedObjs);
- KmSelectedObjs.SelectUseful();
- KmSelectedObjs.AddObj2Database(m_pDataManager);
- KmSelectedObjs.RemoveAll();
- delete pCopy;
- }
- }
- KmSelectedObjs.RemoveAll();
- m_pDataManager->EndModify();
- }
- void CKmgConverter::Calculate_ChangeFont(CWordStyle* pWordStyle)
- {
- ASSERT(pWordStyle);
- CString strBigFontName;
- CString strFontName=pWordStyle->GetFontName();
- CString strFontName2;
- double dScale=1.0;
- double dHeightScale=1.0;
- FONTMAPITEM* pFontMapItem=NULL;
- int ipos=strFontName.Find(';');
- if(ipos!=-1)
- {
- strBigFontName=strFontName.Right(strFontName.GetLength()-ipos-1);
- strFontName=strFontName.Left(ipos);
- if(m_mapFont.Lookup(strFontName,(void* &)pFontMapItem))
- {
- ASSERT(pFontMapItem);
- strFontName2=pFontMapItem->m_strFontName;
- dScale=pFontMapItem->m_dScale;
- dHeightScale=pFontMapItem->m_dhegithscale;
- if(m_mapFont.Lookup(strBigFontName,(void* &)pFontMapItem))
- {
- ASSERT(pFontMapItem);
- pWordStyle->SetFontName(strFontName2+';'+pFontMapItem->m_strFontName);
- pWordStyle->SetHeight(pWordStyle->GetHeight()*pFontMapItem->m_dScale);//优先应用大字体的比例。
- pWordStyle->SetWFactor(pWordStyle->GetWFactor()*pFontMapItem->m_dhegithscale);
- }
- else
- {
- pWordStyle->SetFontName(strFontName2+';'+strBigFontName);
- pWordStyle->SetHeight(pWordStyle->GetHeight()*dScale);//优先应用大字体的比例。
- pWordStyle->SetWFactor(pWordStyle->GetWFactor()*dHeightScale);
- }
- }
- else if(m_mapFont.Lookup(strBigFontName,(void* &)pFontMapItem))
- {
- pWordStyle->SetFontName(strFontName+';'+pFontMapItem->m_strFontName);
- pWordStyle->SetHeight(pWordStyle->GetHeight()*pFontMapItem->m_dScale);//优先应用大字体的比例。
- pWordStyle->SetWFactor(pWordStyle->GetWFactor()*pFontMapItem->m_dhegithscale);
- }
- }
- else
- {
- if(m_mapFont.Lookup(strFontName,(void* &)pFontMapItem))
- {
- pWordStyle->SetFontName(pFontMapItem->m_strFontName);
- pWordStyle->SetHeight(pWordStyle->GetHeight()*pFontMapItem->m_dScale);//优先应用大字体的比例。
- pWordStyle->SetWFactor(pWordStyle->GetWFactor()*pFontMapItem->m_dhegithscale);
- }
- }
- }
- KMOBJECTID CKmgConverter::AddObject(KmObject* pObj,BOOL bSetHead)
- {
- if(bSetHead)
- {
- pObj->SetLayerID(m_enthead.idlayer);
- pObj->SetColor(m_enthead.icolor);
- pObj->SetView(VIEW_MAIN);
- pObj->SetWidth(m_enthead.ilwidth);
- if(pObj->IsKindOf(RUNTIME_CLASS(KmCurve)))
- {
- ((KmCurve*)pObj)->SetLineScale(m_enthead.dlscale);
- ((KmCurve*)pObj)->SetStyle(m_enthead.iltype);
- }
- }
- if(pObj->IsKindOf(RUNTIME_CLASS(KmGroup)))
- {
- ((KmGroup*)pObj)->ModifyGroupsPara();
- }
- if(pObj->IsKindOf(RUNTIME_CLASS(KmBlockRef)))
- {
- ((KmBlockRef*)pObj)->SetTransiformByGroup(TRUE);
- }
- if(pObj->IsKindOf(RUNTIME_CLASS(KmText)))
- {
- CWordStyle* pWordStyle;
- pObj->SetFlag(pObj->GetFlag()|TEXT_NODESCENT);
- if(!m_mapFont.IsEmpty())
- {
- for(int i=0;i<((KmText*)pObj)->GetWordStyleNum();i++)
- {
- pWordStyle=((KmText*)pObj)->GetNoNWordStyle(i);
- if(pWordStyle)
- {
- Calculate_ChangeFont(pWordStyle);
- }
- }
- }
- }
-
- KMOBJECTID id;
- switch(m_dDataVessel)
- {
- case DATAVESSEL_BLOCKDEF:
- if(m_pActiveBlockDef)
- {
- m_pActiveBlockDef->AddObject(pObj);
- #ifdef _DEBUG
- id.dwEntIndex=1;//m_pActiveBlockDef->GetObjectNum()-1;
- #else
- id.dwEntIndex=1;
- #endif
- }
- else
- {
- id.dwEntIndex=0;
- }
- delete pObj;
- pObj=NULL;
- break;
- case DATAVESSEL_DATABASE:
- m_pDataManager->StartModify();
- id=m_pDataManager->AddObj(pObj,TRUE);
- m_pDataManager->EndModify();
- delete pObj;
- pObj=NULL;
- break;
- case DATAVESSEL_MODELSPACE:
- m_ModelSpace.AddTail(pObj);
- #ifdef _DEBUG
- id.dwEntIndex=m_ModelSpace.GetCount()-1;
- #else
- id.dwEntIndex=1;
- #endif
- break;
- default:
- delete pObj;
- pObj=NULL;
- break;
- }
- return id;
- }
- BOOL CKmgConverter::SaveAndReinitDataBase(UINT utDimStyleReplace,CString strfilename,BOOL bModel)
- {
- if(utDimStyleReplace!=UINT(-1))
- {
- VARIANT var;
- memset(&var,0,sizeof(VARIANT));
- var.vt=VT_INT;var.intVal=DS_INVALID_ID;
-
- m_pDataManager->SetDBVar(SIMPLEDIMDEFAULTDS,var);
- m_pDataManager->SetDBVar(COSERIALDIMDEFAULTDS,var);
- m_pDataManager->SetDBVar(DASERIALDIMDEFAULTDS,var);
- m_pDataManager->SetDBVar(GESERIALDIMDEFAULTDS,var);
- m_pDataManager->SetDBVar(ORDINATEDIMDEFAULTDS,var);
- m_pDataManager->SetDBVar(DIAMETERDIMDEFAULTDS,var);
- m_pDataManager->SetDBVar(RADIUSDIMDEFAULTDS,var);
- m_pDataManager->SetDBVar(SYDIAMETERDIMDEFAULTDS,var);
- m_pDataManager->SetDBVar(ARCLENDIMDEFAULTDS,var);
- m_pDataManager->SetDBVar(ANGLEDIMDEFAULTDS,var);
- m_pDataManager->SetDBVar(VANGLEDIMDEFAULTDS,var);
- m_pDataManager->SetDBVar(SYHALFSIMPLEDIMDEFAULTDS,var);
- m_pDataManager->SetDBVar(SYHALFANGLEDIMDEFAULTDS,var);
- m_pDataManager->SetCurDimStyle(utDimStyleReplace);
- }
- // m_pDataManager->m_bDBOriginOrState=DB_ORIGIN_DWGCONV_1;
- m_pDataManager->GetLegend()->SetShowLegend(NULL,FALSE);
- KmLayer* pLayer=m_pDataManager->GetFirstLayer();
- if(pLayer!=NULL)
- {
- m_pDataManager->SetCurrentLayer(pLayer->GetID());
- }
- else
- {
- _WRITE(str="该文件中没有层,无法用KmCAD打开,转换中止");
- return FALSE;
- }
- CKmDataManager* pBack=::GetActiveDataManager();
- ::SetActiveDataManager(m_pDataManager);
- if(bModel)
- {
- KmObject* pObj;
- m_pDataManager->StartModify();
- POSITION pos=m_ModelSpace.GetHeadPosition();
- while(pos!=NULL)
- {
- pObj=m_ModelSpace.GetNext(pos);
- if(!pObj)continue;
- /*#ifdef _DEBUG for test
- {
- CString str;
- str.Format("n%s,%d",pObj->Type(),pObj->GetObjectID().dwEntIndex);
- TRACE(str);
- }
- #endif*/
- m_pDataManager->AddObj(pObj,TRUE);
- }
- m_pDataManager->EndModify();
- }
- ::SetActiveDataManager(pBack);
-
- if(!ConverterPreSave_IndentifyExtendInfo())
- {
- _WRITE(str="转换扩展信息失败");
- return FALSE;
- }
- LoadLayerStatus();
- if(!m_pDataManager->WriteFile( (LPCTSTR)strfilename) )
- {
- ResetLayerStatus();
- _WRITE(str="文件存盘失败");
- return FALSE;
- }
- ResetLayerStatus();
- m_pDataManager->ReInitDataBaseObjs();
- return TRUE;
- }
- UINT CKmgConverter::ConverterEnthead_Dimstyle(PAD_DIMSTYLE dimstyle,CArray<int,int>& acolor,int iLWidthDefault,CMatchList5& ashape,BOOL bAdjusted,double dTextHeight,double dArrowSize,double dDimValueRate,UINT utWordStyle)
- {
- // char flag; /* flag for dimstyle */
- CString strTemp;
- CDimStyle kmstyle;
- VARIANT var;
- memset(&var,0,sizeof(VARIANT));
-
- //DIMADEC = 0,//角度标注的小数位 VT_INT 0 0 0 0
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimadec;
- kmstyle.SetDimStlVar(DIMADEC,var);
- //DIMALT,// 选定的换算单位 VT_BOOL 关 关 关 关
- var.vt=VT_BOOL;var.boolVal=(VARIANT_BOOL)dimstyle->dimalt;
- kmstyle.SetDimStlVar(DIMALT,var);
- //DIMALTD,// 换算单位小数位 VT_INT 2 4 2 2
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimaltd;
- kmstyle.SetDimStlVar(DIMALTD,var);
- //DIMALTF,// 换算单位比例因子 VT_R8 25.4000 0.0394 0.0394 0.0394
- var.vt=VT_R8;var.dblVal=dimstyle->dimaltf;
- kmstyle.SetDimStlVar(DIMALTF,var);
- //DIMALTRND,//换算单位的舍入值 VT_R8 0.0000 0.0000 0.0000 0.0000
- var.vt=VT_R8;var.dblVal=dimstyle->dimaltrnd;
- kmstyle.SetDimStlVar(DIMALTRND,var);
- //DIMALTTD,// 换算公差的小数位 VT_INT 2 4 2 2
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimalttd;
- kmstyle.SetDimStlVar(DIMALTTD,var);
- //DIMALTTZ,// 控制换算公差的消零处理 VT_INT 0 0 0 0
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimalttz;
- kmstyle.SetDimStlVar(DIMALTTZ,var);
- //DIMALTU,// 换算单位 VT_INT 2 8 8 2
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimaltu;
- kmstyle.SetDimStlVar(DIMALTU,var);
- //DIMALTZ,// 控制换算单位的消零处理 VT_INT 0 0 0 0
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimaltz;
- kmstyle.SetDimStlVar(DIMALTZ,var);
- //DIMAPOST,// 表示换算单位的文字前缀和后缀VT_BSTR
- strTemp=dimstyle->dimapost;
- {
- VARIANT varTmp;
- memset(&varTmp,0,sizeof(VARIANT));
- CComBSTR bstrTmp = strTemp;
- varTmp.vt = VT_BSTR;
- varTmp.bstrVal = bstrTmp.Copy();
- kmstyle.SetDimStlVar(DIMPOST,varTmp);
- }
- //DIMASZ,// 箭头尺寸 VT_R8 0.1800 2.5000 2.5000 2.5000
- var.vt=VT_R8;
- if(bAdjusted)
- {
- var.dblVal=dArrowSize;
- }
- else
- {
- var.dblVal=dimstyle->dimasz;
- }
- kmstyle.SetDimStlVar(DIMASZ,var);
- //DIMATFIT,// 箭头及文字自适应调整 VT_INT 3 3 3 3
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimfit;
- kmstyle.SetDimStlVar(DIMATFIT,var);
- //DIMAUNIT,// 角度单位格式 VT_INT 0 0 0 0
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimaunit;
- kmstyle.SetDimStlVar(DIMAUNIT,var);
- //DIMAZIN,// 控制角度标注的消零处理 VT_INT 0 0 0 0
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimazin;
- kmstyle.SetDimStlVar(DIMAZIN,var);
- //DIMBLK,// 箭头块名称 VT_BSTR 闭合填充闭合填充闭合填充闭合填充
- // var.vt=VT_INT;var.intVal=dimstyle-;
- // kmstyle.SetDimStlVar(DIMATFIT,var);
- //DIMBLK1,// 第一箭头块名称 VT_BSTR 闭合填充闭合填充闭合填充闭合填充
- // var.vt=VT_INT;var.intVal=dimstyle-;
- // kmstyle.SetDimStlVar(DIMATFIT,var);
- //DIMBLK2,// 第二箭头块名称 VT_BSTR 闭合填充闭合填充闭合填充闭合填充
- // var.vt=VT_INT;var.intVal=dimstyle-;
- // kmstyle.SetDimStlVar(DIMATFIT,var);
- //DIMCEN,// 圆心标记的尺寸 VT_R8 0.0900 2.500 2.500 0.0000
- var.vt=VT_R8;var.dblVal=dimstyle->dimcen;
- kmstyle.SetDimStlVar(DIMCEN,var);
- //DIMDEC,// 标注的小数位 VT_INT 4 4 4 4
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimdec;
- kmstyle.SetDimStlVar(DIMDEC,var);
- //DIMDLE,// 尺寸线超出尺寸界线的距离VT_R8 0.0000 0.0000 0.0000 0.0000
- var.vt=VT_R8;var.dblVal=dimstyle->dimdle;
- kmstyle.SetDimStlVar(DIMDLE,var);
- //DIMDLI,// 尺寸线间距 VT_R8 0.3800 3.7500 3.7500 7.0000
- var.vt=VT_R8;var.dblVal=dimstyle->dimdli;
- kmstyle.SetDimStlVar(DIMDLI,var);
- //DIMDSEP,// 小数分隔符 VT_I1 . . . .
- var.vt=VT_I1;var.cVal=(char)dimstyle->dimdsep;
- kmstyle.SetDimStlVar(DIMDSEP,var);
- //DIMEXE,// 尺寸界线上超尺寸线的距离VT_R8 0.1800 1.2500 1.2500 1.0000
- var.vt=VT_R8;var.dblVal=dimstyle->dimexe;
- kmstyle.SetDimStlVar(DIMEXE,var);
- //DIMEXO,// 尺寸界线偏离原点的距离 VT_R8 0.0625 0.0625 0.0625 1.0000
- var.vt=VT_R8;var.dblVal=dimstyle->dimexo;
- kmstyle.SetDimStlVar(DIMEXO,var);
- //DIMFRAC,// 分数格式 VT_INT 0 0 0 0
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimfrac;
- kmstyle.SetDimStlVar(DIMFRAC,var);
- //DIMGAP,// 尺寸线与标注文字的间距 VT_R8 0.0900 0.6250 0.6250 0.0000
- var.vt=VT_R8;var.dblVal=dimstyle->dimgap;
- kmstyle.SetDimStlVar(DIMGAP,var);
- //DIMJUST,// 控制尺寸线上标注文字的水平对齐 VT_INT 0 0 0 0
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimjust;
- kmstyle.SetDimStlVar(DIMJUST,var);
- //DIMLDRBLK,//引线箭头块名称 VT_BSTR 闭合填充闭合填充闭合填充闭合填充
- // var.vt=VT_INT;var.intVal=dimstyle-;
- // kmstyle.SetDimStlVar(DIMLDRBLK,var);
- //DIMLFAC,// 线性单位的比例因子 VT_R8 1.000 1.000 1.000 1.000
- var.vt=VT_R8;
- if(bAdjusted)
- {
- var.dblVal=dDimValueRate;
- }
- else
- {
- var.dblVal=dimstyle->dimlfac;
- }
- kmstyle.SetDimStlVar(DIMLFAC,var);
- //DIMLIM,// 生成尺寸极限文字 VT_BOOL 关 关 关 关
- var.vt=VT_BOOL;var.boolVal=(VARIANT_BOOL)dimstyle->dimlim;
- kmstyle.SetDimStlVar(DIMLIM,var);
- //DIMLUNIT,// 线性单位的格式 VT_INT 2 6 6 2
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimunit;
- kmstyle.SetDimStlVar(DIMLUNIT,var);
- //DIMPOST,// 设置标注的文字前缀和后缀VT_BSTR
- strTemp=dimstyle->dimpost;
- {
- VARIANT varTmp;
- memset(&varTmp,0,sizeof(VARIANT));
- CComBSTR bstrTmp = strTemp;
- varTmp.vt = VT_BSTR;
- varTmp.bstrVal = bstrTmp.Copy();
- kmstyle.SetDimStlVar(DIMPOST,varTmp);
- }
- //DIMRND,// 标注距离的舍入值 VT_R8 0.0000 0.0000 0.0000 0.0000
- var.vt=VT_R8;var.dblVal=dimstyle->dimrnd;
- kmstyle.SetDimStlVar(DIMRND,var);
- //DIMSAH,// 分离箭头块 VT_BOOL 关 关 关 关
- var.vt=VT_BOOL;var.boolVal=(VARIANT_BOOL)dimstyle->dimsah;
- kmstyle.SetDimStlVar(DIMSAH,var);
- //DIMSCALE,// 全局比例因子 VT_R8 1.0000 1.0000 1.0000 1.0000
- var.vt=VT_R8;var.dblVal=dimstyle->dimscale;
- kmstyle.SetDimStlVar(DIMSCALE,var);
- //DIMSD1,// 禁止显示第一条尺寸线 VT_BOOL 关 关 关 关
- var.vt=VT_BOOL;var.boolVal=(VARIANT_BOOL)dimstyle->dimsd1;
- kmstyle.SetDimStlVar(DIMSD1,var);
- //DIMSD2,// 禁止显示第二条尺寸线 VT_BOOL 关 关 关 关
- var.vt=VT_BOOL;var.boolVal=(VARIANT_BOOL)dimstyle->dimsd2;
- kmstyle.SetDimStlVar(DIMSD2,var);
- //DIMSE1,// 禁止显示第一条尺寸界线 VT_BOOL 关 关 关 关
- var.vt=VT_BOOL;var.boolVal=(VARIANT_BOOL)dimstyle->dimse1;
- kmstyle.SetDimStlVar(DIMSE1,var);
- //DIMSE2,// 禁止显示第二条尺寸界线 VT_BOOL 关 关 关 关
- var.vt=VT_BOOL;var.boolVal=(VARIANT_BOOL)dimstyle->dimse2;
- kmstyle.SetDimStlVar(DIMSE2,var);
- //DIMSOXD,// 禁止尺寸界线之外的尺寸线VT_BOOL 关 关 关 开
- var.vt=VT_BOOL;var.boolVal=(VARIANT_BOOL)dimstyle->dimsoxd;
- kmstyle.SetDimStlVar(DIMSOXD,var);
- //DIMTAD,// 将标注文字置于尺寸线上方VT_INT 0 1 1 1
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimtad;
- kmstyle.SetDimStlVar(DIMTAD,var);
- //DIMTDEC,// 公差的小数位 VT_INT 4 4 4 4
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimtdec;
- kmstyle.SetDimStlVar(DIMTDEC,var);
- //DIMTFAC,// 公差对象的文字高度 VT_R8 1.0000 1.0000 1.0000 1.0000
- var.vt=VT_R8;var.dblVal=dimstyle->dimtfac;
- kmstyle.SetDimStlVar(DIMTFAC,var);
- //DIMTIH,// 水平放置尺寸界线内的标注文字 VT_BOOL 开 关 关 关
- var.vt=VT_BOOL;var.boolVal=(VARIANT_BOOL)dimstyle->dimtih;
- kmstyle.SetDimStlVar(DIMTIH,var);
- //DIMTIX,// 将标注文字置于尺寸界线内VT_BOOL 关 关 关 开
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimtix;
- kmstyle.SetDimStlVar(DIMTIX,var);
- //DIMTM,// 下偏差 VT_R8 0.0000 0.0000 0.0000 0.0000
- var.vt=VT_R8;var.dblVal=dimstyle->dimtm;
- kmstyle.SetDimStlVar(DIMTM,var);
- //DIMTMOVE,// 标注文字的移动规则 VT_INT 0 0 0 0
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimtmove;
- kmstyle.SetDimStlVar(DIMTMOVE,var);
- //DIMTOFL,// 强制尺寸线置于尺寸界线之间 VT_BOOL 关 开 开 开
- var.vt=VT_BOOL;var.boolVal=(VARIANT_BOOL)dimstyle->dimtofl;
- kmstyle.SetDimStlVar(DIMTOFL,var);
- //DIMTOH,// 水平放置尺寸界线外的标注文字 VT_BOOL 开 关 关 关
- var.vt=VT_BOOL;var.boolVal=(VARIANT_BOOL)dimstyle->dimtoh;
- kmstyle.SetDimStlVar(DIMTOH,var);
- //DIMTOL,// 公差的标注方式 VT_BOOL 关 关 关 关
- var.vt=VT_BOOL;var.boolVal=(VARIANT_BOOL)dimstyle->dimtol;
- kmstyle.SetDimStlVar(DIMTOL,var);
- //DIMTOLJ,// 公差的垂直对正方式 VT_INT 1 1 1 1
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimtolj;
- kmstyle.SetDimStlVar(DIMTOLJ,var);
- //DIMTP,// 上偏差 VT_R8 0.0000 0.0000 0.0000 0.0000
- var.vt=VT_R8;var.dblVal=dimstyle->dimtp;
- kmstyle.SetDimStlVar(DIMTP,var);
- //DIMTSZ,// 替代箭头的小斜线尺寸 VT_R8 0.0000 0.0000 0.0000 0.0000
- var.vt=VT_R8;var.dblVal=dimstyle->dimtsz;
- kmstyle.SetDimStlVar(DIMTSZ,var);
- //DIMTVP,// 标注文字的垂直位置 VT_R8 0.0000 0.0000 0.0000 0.0000
- var.vt=VT_R8;var.dblVal=dimstyle->dimtvp;
- kmstyle.SetDimStlVar(DIMTVP,var);
- //DIMTXSTY,// 标注文字样式 (VT_INT)标准 标准 标准 标准
- if(utWordStyle!=((UINT)-1))
- {
- var.vt=VT_INT;var.intVal=utWordStyle;
- kmstyle.SetDimStlVar(DIMTXSTY,var);
- }
- else
- {
- CMatch5* match;
- if(ashape.Get(dimstyle->shapefileobjhandle,match))
- {
- var.vt=VT_INT;var.intVal=match->m_shape->m_KmWordStyleID;
- kmstyle.SetDimStlVar(DIMTXSTY,var);
- }
- }
- //DIMTXT,// 标注文字高度 VT_R8 0.1800 2.5000 2.5000 2.5000
- var.vt=VT_R8;
- if(bAdjusted)
- {
- var.dblVal=dTextHeight;
- }
- else
- {
- var.dblVal=dimstyle->dimtxt;
- }
- kmstyle.SetDimStlVar(DIMTXT,var);
- //DIMTZIN,// 控制公差的消零处理 VT_INT 0 0 0 0
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimtzin;
- kmstyle.SetDimStlVar(DIMTZIN,var);
- //DIMUPT,// 控制用户定位文字 VT_BOOL 关 关 关 关
- var.vt=VT_BOOL;var.boolVal=(VARIANT_BOOL)dimstyle->dimupt;
- kmstyle.SetDimStlVar(DIMUPT,var);
- //DIMZIN,// 控制主单位值的消零处理 VT_INT 0 8 8 8*/
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimzin;
- kmstyle.SetDimStlVar(DIMZIN,var);
- //DIMCLRD,// 尺寸线和引线颜色 VT_INT 随块 随块 随块 随块
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimclrd;
- {
- try
- {
- if(var.intVal==AD_COLOR_BYBLOCK)
- {
- var.intVal=COLOR_BYBLOCK;//随块
- }
- else if(var.intVal==AD_COLOR_BYLAYER)
- {
- var.intVal=COLOR_BYLAYER;
- }
- else
- {
- if(var.intVal>=0 && var.intVal<acolor.GetSize())
- {
- var.intVal=acolor[var.intVal];
- }
- else
- {
- TRACE("errordata");
- }
-
- }
- }
- catch(...)
- {
- _WRITE(str="非法的颜色码");
- }
- }
- kmstyle.SetDimStlVar(DIMCLRD,var);
- //DIMCLRE,// 尺寸界线颜色 VT_INT 随块 随块 随块 随块
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimclre;
- {
- try
- {
- if(var.intVal==AD_COLOR_BYBLOCK)
- {
- var.intVal=COLOR_BYBLOCK;//随块
- }
- else if(var.intVal==AD_COLOR_BYLAYER)
- {
- var.intVal=COLOR_BYLAYER;
- }
- else
- {
- if(var.intVal>=0 && var.intVal<acolor.GetSize())
- {
- var.intVal=acolor[var.intVal];
- }
- else
- {
- TRACE("errordata");
- }
- }
- }
- catch(...)
- {
- _WRITE(str="非法的颜色码");
- }
- }
- kmstyle.SetDimStlVar(DIMCLRE,var);
- //DIMCLRT,// 标注文字的颜色 VT_INT 随块 随块 随块 随块
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimclrt;
- {
- try
- {
- if(var.intVal==AD_COLOR_BYBLOCK)
- {
- var.intVal=COLOR_BYBLOCK;//随块
- }
- else if(var.intVal==AD_COLOR_BYLAYER)
- {
- var.intVal=COLOR_BYLAYER;
- }
- else
- {
- if(var.intVal>=0 && var.intVal<acolor.GetSize())
- {
- var.intVal=acolor[var.intVal];
- }
- else
- {
- TRACE("errordata");
- }
- }
- }
- catch(...)
- {
- _WRITE(str="非法的颜色码");
- }
- }
- kmstyle.SetDimStlVar(DIMCLRT,var);
- //DIMLWD,// 尺寸线和引线线宽 VT_INT -2 -2 -2 -2
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimlwd;
- {
- if((unsigned short)var.intVal==AD_WEIGHT_DEFAULT)
- {
- var.intVal=iLWidthDefault;
- }
- else if((unsigned short)var.intVal==AD_WEIGHT_BYBLOCK)
- {
- var.intVal=LWIDTH_BYBLOCK;//随块
- }
- else if((unsigned short)var.intVal==AD_WEIGHT_BYLAYER)
- {
- var.intVal=LWIDTH_BYLAYER;
- }
- else
- {
- var.intVal=::GetLineWidthAsInt(double(abs(var.intVal))/100.0);
- }
- }
- kmstyle.SetDimStlVar(DIMLWD,var);
- //DIMLWE,// 尺寸界线线宽 VT_INT -2 -2 -2 -2
- var.vt=VT_INT;var.intVal=(int)dimstyle->dimlwe;
- {
- if((unsigned short)var.intVal==AD_WEIGHT_DEFAULT)
- {
- var.intVal=iLWidthDefault;
- }
- else if((unsigned short)var.intVal==AD_WEIGHT_BYBLOCK)
- {
- var.intVal=LWIDTH_BYBLOCK;//随块
- }
- else if((unsigned short)var.intVal==AD_WEIGHT_BYLAYER)
- {
- var.intVal=LWIDTH_BYLAYER;
- }
- else
- {
- var.intVal=::GetLineWidthAsInt(double(abs(var.intVal))/100.0);
- }
- }
- kmstyle.SetDimStlVar(DIMLWE,var);
- UINT kmid;
- CString strName=dimstyle->name;
- kmstyle.SetDeclare("转换至"+strName);
- kmstyle.SetName(strName);
- {
- CString strTemp;
- int index=0;
- kmstyle.SetID(0);
- while( (kmid=m_pDataManager->AddDimStyle(kmstyle,TRUE))==0 )
- {
- strTemp.Format("%s%d",strName,index);
- index++;
- kmstyle.SetName(strTemp);
- }
- }
- return kmid;
- }
- UINT CKmgConverter::ConverterEnthead_Dimstyle(CDimStyle cdimstyle,BOOL bAdjusted,double dTextHeight,double dArrowSize,double dDimValueRate,UINT utWordStyle)
- {
- CString strTemp;
- VARIANT var;
- memset(&var,0,sizeof(VARIANT));
-
- if(bAdjusted)
- {
- var.vt=VT_R8;
- var.dblVal=dArrowSize;
- cdimstyle.SetDimStlVar(DIMASZ,var);
-
- var.vt=VT_R8;
- var.dblVal=dDimValueRate;
- cdimstyle.SetDimStlVar(DIMLFAC,var);
- var.vt=VT_R8;
- var.dblVal=dTextHeight;
- cdimstyle.SetDimStlVar(DIMTXT,var);
- }
- if(utWordStyle!=((UINT)-1))
- {
- var.vt=VT_INT;
- var.intVal=utWordStyle;
- cdimstyle.SetDimStlVar(DIMTXSTY,var);
- }
- UINT kmid;
- CString strName=cdimstyle.GetName();
- {
- CString strTemp;
- int index=0;
- cdimstyle.SetID(0);
- while( (kmid=m_pDataManager->AddDimStyle(cdimstyle,TRUE))==0 )
- {
- strTemp.Format("%s%d",strName,index);
- index++;
- cdimstyle.SetName(strTemp);
- }
- }
- return kmid;
- }
- void CKmgConverter::ReActiveDataManager()
- {
- ::SetActiveDataManager(m_pDataManager);
- }
- void CKmgConverter::ConverterEnthead_XrefBlock(DWORD dwid,double x1,double y1,double z1,CString XrefPath)
- {
- KmBlockDef* pDef=m_pDataManager->GetBlockDef(dwid);
- if( pDef )
- {
- pDef->SetBasePt(KmPoint(x1,y1));
- pDef->SetXref(XrefPath);
- }
- }
- //转换扩展信息
- BOOL CKmgConverter::ConverterPreSave_IndentifyExtendInfo()
- {
- if(!m_pDataManager)
- {
- return FALSE;//数据库空
- }
- BOOL bRected;
- KmRect rectOutside;
- KmBuffer* pBuffer=NULL;
- {
- pBuffer=CExtendInfoIdentify::CreateExtendInfoSourceBuffer(m_pDataManager,bRected,rectOutside);
- if(pBuffer==NULL)
- {
- return FALSE;//生成buffer空
- }
- }
- CExtendInfoIdentify cExtendInfoIdentify(pBuffer);
- KmLegend* pLegend=new KmLegend(m_pDataManager);
- pLegend->SetShowLegend(NULL,FALSE);
- double dShowScale=-1;
- KmPoint ptRightBottom;
- if(!cExtendInfoIdentify.IdentifyLegend(pLegend,dShowScale,ptRightBottom))
- {
- delete pLegend;
- if(!ConverterPreSave_KmLegend(bRected,rectOutside))
- {
- _WRITE(str="设置图框失败");
- return FALSE;
- }
- return TRUE;//不进行后续识别
- }
- else
- {
- ASSERT(dShowScale>PRECISION);
- pLegend->SetMainData(pLegend->GetFigureSel(),pLegend->GetAddLength(),pLegend->GetDistrictFlag(),pLegend->GetDistrictXLength(),pLegend->GetDistrictYLength(),1,dShowScale,pLegend->GetXLength(),pLegend->GetYLength(),pLegend->GetLegendDistance());
- m_pDataManager->GetLegend()->SetMainData(pLegend->GetFigureSel(),pLegend->GetAddLength(),pLegend->GetDistrictFlag(),pLegend->GetDistrictXLength(),pLegend->GetDistrictYLength(),1,dShowScale,pLegend->GetXLength(),pLegend->GetYLength(),pLegend->GetLegendDistance());
- m_pDataManager->GetLegend()->Copy(pLegend);
- }
- if(dShowScale<PRECISION)
- {
- return TRUE;
- }
- //如果正确识别了图框则往下进行标题栏和明细栏的识别
- if(cExtendInfoIdentify.IdentifyProductInfo(dShowScale,ptRightBottom,m_pDataManager))
- {
- }
- return TRUE;
- }
- void CKmgConverter::SaveLayerStatus()
- {
- KmLayer* pLayer=m_pDataManager->GetFirstLayer();
- while(pLayer)
- {
- int iStatus=0;
- if(pLayer->IsFrozen())
- {
- pLayer->Frozen(FALSE);
- iStatus|=0x1;
- }
- if(pLayer->IsOff())
- {
- pLayer->Off(FALSE);
- iStatus|=0x2;
- }
- m_aLayerStatus.SetAt(pLayer->GetID(),iStatus);
- pLayer=m_pDataManager->GetNextLayer();
- }
- }
- void CKmgConverter::LoadLayerStatus()
- {
- KmLayer* pLayer=m_pDataManager->GetFirstLayer();
- while(pLayer)
- {
- int iStatus=0;
- m_aLayerStatus.Lookup(pLayer->GetID(),iStatus);
- if(iStatus&0x1)
- {
- pLayer->Frozen(TRUE);
- }
- if(iStatus&0x2)
- {
- pLayer->Off(TRUE);
- }
- pLayer=m_pDataManager->GetNextLayer();
- }
- }
- void CKmgConverter::ResetLayerStatus()
- {
- KmLayer* pLayer=m_pDataManager->GetFirstLayer();
- while(pLayer)
- {
- if(pLayer->IsFrozen())
- pLayer->Frozen(FALSE);
- if(pLayer->IsOff())
- pLayer->Off(FALSE);
- pLayer=m_pDataManager->GetNextLayer();
- }
- }