525 lines
15 KiB
C++
525 lines
15 KiB
C++
#include "stdafx.h"
|
|
|
|
// 建立尺寸样式
|
|
TARCH_IMPEXP AcDbObjectId InitDimStyle(const TCHAR *pszStyle, const TCHAR *pszDimBlk)
|
|
{
|
|
//XString sName=GetDsName(pszStyle, nScale);
|
|
AcDbObjectId id=GetDimStyleId(pszStyle);;
|
|
if(!id)
|
|
{
|
|
AcDbObjectId idTextStyle=InitTextStyle(TS_DIM);
|
|
int nTextColor=GetTextStyleColor(idTextStyle);
|
|
if(!idTextStyle)
|
|
return id;
|
|
AcDbDimStyleTableRecord *pDimStyle=new AcDbDimStyleTableRecord;
|
|
AcCmColor clr;
|
|
clr.setColorIndex(7);
|
|
pDimStyle->setDimclrt(clr);
|
|
pDimStyle->setDimgap(1.0);
|
|
pDimStyle->setDimtxt(3.5);
|
|
pDimStyle->setDimblk(pszDimBlk);
|
|
pDimStyle->setDimtxsty(idTextStyle);
|
|
pDimStyle->setDimexe(2.5);
|
|
pDimStyle->setDimexo(3.0);
|
|
pDimStyle->setDimasz(1.0);
|
|
pDimStyle->setDimscale(1.0);
|
|
pDimStyle->setName(pszStyle);
|
|
//pDimStyle->setDimlwe(-1);
|
|
pDimStyle->setDimdli(0.0);
|
|
pDimStyle->setDimtofl(true);
|
|
//pDimStyle->setDimlwd(-1);
|
|
pDimStyle->setDimtmove(2);
|
|
pDimStyle->setDimtdec(0);
|
|
pDimStyle->setDimdec(0);
|
|
pDimStyle->setDimaunit(0); //十进制
|
|
|
|
if(g_bMeterUnitDraw||DocGetMeterUnitDim())//米单位绘制或米单位标注
|
|
{
|
|
pDimStyle->setDimdec(2);
|
|
if(!g_bMeterUnitDraw)
|
|
pDimStyle->setDimlfac(0.001);
|
|
}
|
|
|
|
pDimStyle->setDimadec(2); //保留2位小数
|
|
//pDimStyle->setDimaunit(1); //度分秒
|
|
//pDimStyle->setDimadec(3); //精确到秒
|
|
pDimStyle->setDimazin(2); //消除后续0
|
|
pDimStyle->setDimtoh(false);
|
|
pDimStyle->setDimtad(1);
|
|
pDimStyle->setDimtix(true);
|
|
pDimStyle->setDimtih(false);
|
|
|
|
if(nTextColor>0)
|
|
{
|
|
AcCmColor cmColor;
|
|
cmColor.setColorIndex(nTextColor);
|
|
pDimStyle->setDimclrt(cmColor);
|
|
}
|
|
//dimclrd=pDimStyle->dimclrd().colorIndex();
|
|
//dimclrt=pDimStyle->dimclrt().colorIndex();
|
|
id=AddDimStyle(pDimStyle, TRUE);
|
|
if(!id)
|
|
delete pDimStyle;
|
|
else {
|
|
if(_tcsicmp(pszDimBlk, _T("_ArchTick"))==0) {
|
|
|
|
XBlockTable rec(_T("_ArchTick"));
|
|
if(rec.ent.Is(_T("LWPOLYLINE"))) {
|
|
OPENOBJ_BEGIN(rec.ent, AcDb::kForWrite, AcDbPolyline, pline);
|
|
if(pline)
|
|
pline->setConstantWidth(DocGetHighBold());
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
return id;
|
|
}
|
|
|
|
|
|
struct TDimStyleInfo
|
|
{
|
|
TDimStyle ds; //名称
|
|
const TCHAR *szName; //名称
|
|
const TCHAR *szDimBlk; //箭头
|
|
};
|
|
|
|
TDimStyleInfo g_tchDimStyles[]={
|
|
{DS_STANDARD, _T("STANDARD"), _T(""),},
|
|
{DS_LINEAR, _T("_TCH_ARCH"), _T("_ArchTick"),},
|
|
{DS_ANGLE, _T("_TCH_DOTE"), _T("_Dot"), },
|
|
{DS_RADIUS, _T("_TCH_ARROW"), _T(""), },
|
|
};
|
|
|
|
AcDbObjectId InitDimStyle(TDimStyle ds)
|
|
{
|
|
extern BOOL g_nLineDimArrow; // 0--粗斜线; 1--细斜线;2-圆点
|
|
extern BOOL g_nAngleDimArrow; // 0--标准箭头; 1--圆点
|
|
//默认尺寸样式
|
|
//粗斜线
|
|
extern TARCH_IMPEXP CString g_sDim0;
|
|
extern TARCH_IMPEXP CString g_sDim0M_M;
|
|
extern TARCH_IMPEXP CString g_sDim0mm_M;
|
|
//细斜线
|
|
extern TARCH_IMPEXP CString g_sDim1;
|
|
extern TARCH_IMPEXP CString g_sDim1M_M;
|
|
extern TARCH_IMPEXP CString g_sDim1mm_M;
|
|
//圆点
|
|
extern TARCH_IMPEXP CString g_sDim2;
|
|
extern TARCH_IMPEXP CString g_sDim2M_M;
|
|
extern TARCH_IMPEXP CString g_sDim2mm_M;
|
|
//角度箭头
|
|
extern TARCH_IMPEXP CString g_sDimA0;
|
|
//角度圆点
|
|
extern TARCH_IMPEXP CString g_sDimA1;
|
|
|
|
AcDbObjectId idRet;
|
|
if(ds==DS_LINEAR)
|
|
{
|
|
if(DocGetMeterUnitDraw())//绘制M-标注M
|
|
{
|
|
if(g_nLineDimArrow==2)
|
|
{
|
|
idRet=GetDimStyleId(g_sDim2M_M);
|
|
if(!idRet)
|
|
idRet=InitDimStyle(g_sDim2M_M, _T("_Dot"));
|
|
}
|
|
else if(g_nLineDimArrow==1)
|
|
{
|
|
idRet=GetDimStyleId(g_sDim1M_M);
|
|
if(!idRet)
|
|
idRet=InitDimStyle(g_sDim1M_M, _T("_Oblique"));
|
|
}
|
|
else
|
|
{
|
|
idRet=GetDimStyleId(g_sDim0M_M);
|
|
if(!idRet)
|
|
idRet=InitDimStyle(g_sDim0M_M, _T("_ArchTick"));
|
|
}
|
|
}
|
|
else if(DocGetMeterUnitDim())//绘制mm-标注M
|
|
{
|
|
if(g_nLineDimArrow==2)
|
|
{
|
|
idRet=GetDimStyleId(g_sDim2mm_M);
|
|
if(!idRet)
|
|
idRet=InitDimStyle(g_sDim2mm_M, _T("_Dot"));
|
|
}
|
|
else if(g_nLineDimArrow==1)
|
|
{
|
|
idRet=GetDimStyleId(g_sDim1mm_M);
|
|
if(!idRet)
|
|
idRet=InitDimStyle(g_sDim1mm_M, _T("_Oblique"));
|
|
}
|
|
else
|
|
{
|
|
idRet=GetDimStyleId(g_sDim0mm_M);
|
|
if(!idRet)
|
|
idRet=InitDimStyle(g_sDim0mm_M, _T("_ArchTick"));
|
|
}
|
|
}
|
|
else//绘制mm-标注mm
|
|
{
|
|
if(g_nLineDimArrow==2)
|
|
{
|
|
idRet=GetDimStyleId(g_sDim2);
|
|
if(!idRet)
|
|
idRet=InitDimStyle(g_sDim2, _T("_Dot"));
|
|
}
|
|
else if(g_nLineDimArrow==1)
|
|
{
|
|
idRet=GetDimStyleId(g_sDim1);
|
|
if(!idRet)
|
|
idRet=InitDimStyle(g_sDim1, _T("_Oblique"));
|
|
}
|
|
else
|
|
{
|
|
idRet=GetDimStyleId(g_sDim0);
|
|
if(!idRet)
|
|
idRet=InitDimStyle(g_sDim0, _T("_ArchTick"));
|
|
}
|
|
}
|
|
}
|
|
else if(ds==DS_ANGLE)
|
|
{
|
|
if(g_nAngleDimArrow)
|
|
{
|
|
idRet=GetDimStyleId(g_sDimA1);
|
|
if(!idRet)
|
|
idRet=InitDimStyle(g_sDimA1, _T("_Dot"));
|
|
}
|
|
else
|
|
{
|
|
idRet=GetDimStyleId(g_sDimA0);
|
|
if(!idRet)
|
|
{
|
|
idRet=InitDimStyle(g_sDimA0, _T(""));
|
|
|
|
// sg add 120412,将箭头标注默认的箭头大小设置为2
|
|
OPENOBJ_BEGIN(idRet, AcDb::kForWrite, AcDbDimStyleTableRecord, pStyle);
|
|
if (pStyle != NULL)
|
|
{
|
|
pStyle->setDimasz(2);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
TDimStyleInfo *pInfo=&g_tchDimStyles[0];
|
|
for(int i=0; i<ELEMENTS(g_tchDimStyles); i++)
|
|
{
|
|
if(g_tchDimStyles[i].ds==ds)
|
|
{
|
|
pInfo=&(g_tchDimStyles[i]);
|
|
break;
|
|
}
|
|
}
|
|
|
|
idRet=GetDimStyleId(pInfo->szName);
|
|
if(!idRet)
|
|
{
|
|
idRet=InitDimStyle(pInfo->szName, pInfo->szDimBlk);
|
|
// jsx add 160713,将箭头标注默认的箭头大小设置为2
|
|
OPENOBJ_BEGIN(idRet, AcDb::kForWrite, AcDbDimStyleTableRecord, pStyle);
|
|
if (pStyle != NULL)
|
|
{
|
|
pStyle->setDimasz(2);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
return idRet;
|
|
}
|
|
|
|
//转成DIMN, DIMNxx
|
|
//AcDbObjectId TARCH_IMPEXP DimStyleTch2Acad(AcDbObjectId idTch, double nScale, BOOL bAngular, AcDbDatabase *pDb)
|
|
//{
|
|
// ASSERT(!!idTch);
|
|
// int iScale = AS_INT(nScale);
|
|
// double dimscale = nScale/100.0;
|
|
//
|
|
// XString sName;
|
|
// sName << (bAngular? _T("ANGL") : _T("DIMN"));
|
|
//
|
|
// if (iScale != 100)
|
|
// sName << iScale;
|
|
//
|
|
// AcDbObjectId idAcad = GetDimStyleId(sName, pDb);
|
|
// if (!idAcad)
|
|
// {
|
|
// OPENOBJ_BEGIN(idTch, AcDb::kForRead, AcDbDimStyleTableRecord, pStyle);
|
|
// if (pStyle != NULL)
|
|
// {
|
|
// AcDbDimStyleTableRecord *pNewStyle = (AcDbDimStyleTableRecord *)pStyle->clone();
|
|
// pNewStyle->setDimscale(dimscale);
|
|
// pNewStyle->setDimgap(150);
|
|
// pNewStyle->setDimtxt(300);
|
|
// pNewStyle->setDimexe(250);
|
|
// pNewStyle->setDimexo(300);
|
|
// pNewStyle->setDimasz(pStyle->dimasz()*100);
|
|
// pNewStyle->setName(sName); // !!!!!
|
|
// pNewStyle->setDimdli(0.0);
|
|
// pNewStyle->setDimse1(false);
|
|
// pNewStyle->setDimse2(false);
|
|
//
|
|
// AcDbObjectId idStyle=GetTextStyleId(_T("DIM_FONT"), pDb);
|
|
// AcDbObjectId idStyle = InitTextStyle(TS_DIMFONT,pDb);//modified by whl on 051230
|
|
// if (idStyle.isValid())
|
|
// pNewStyle->setDimtxsty(idStyle);
|
|
//
|
|
// idAcad = AddDimStyle(pNewStyle, TRUE, pDb);
|
|
// if (!idAcad)
|
|
// delete pNewStyle;
|
|
// }
|
|
// OPENOBJ_END();
|
|
// }
|
|
//
|
|
// 对有关的文字样式清0
|
|
// OPENOBJ_BEGIN(idAcad, AcDb::kForRead, AcDbDimStyleTableRecord, pStyle);
|
|
// if (pStyle != NULL)
|
|
// {
|
|
// AcDbObjectId idStyle = pStyle->dimtxsty();
|
|
// OPENOBJ_BEGIN(idStyle, AcDb::kForWrite, AcDbTextStyleTableRecord, pTxtStyle);
|
|
// if (pTxtStyle != NULL)
|
|
// {
|
|
// pTxtStyle->setTextSize(0.0);
|
|
// }
|
|
// OPENOBJ_END();
|
|
// }
|
|
// OPENOBJ_END();
|
|
// return idAcad;
|
|
//}
|
|
|
|
AcDbObjectId TARCH_IMPEXP DimStyleTch2Acad(AcDbObjectId idTch, double nScale, BOOL bAngular, AcDbDatabase *pDb, double dTxtHeight)
|
|
{
|
|
ASSERT(!!idTch);
|
|
//wlw mod 12.0903解决上华连续标注炸成cad的对齐标注后文字变大问题
|
|
//1.先生成与以前一样的一个文字样式
|
|
AcDbObjectId idTxtStyle; // 原有文字样式名
|
|
OPENOBJ_BEGIN(idTch, AcDb::kForRead, AcDbDimStyleTableRecord, pDimStyle);
|
|
if (pDimStyle != NULL)
|
|
{
|
|
idTxtStyle = pDimStyle->dimtxsty();
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
BOOL bWinFont = FALSE;//判断是否是windows字体 wlw add131119
|
|
AcGiTextStyle txtStyle;
|
|
if (fromAcDbTextStyle(txtStyle, idTxtStyle) == Acad::eOk)
|
|
{
|
|
int nRetFlag = txtStyle.loadStyleRec();
|
|
TCHAR *pWinFont = NULL;
|
|
#if ADS < 21
|
|
BOOL bold, italic;
|
|
int charset, pitch;
|
|
if (txtStyle.font(pWinFont, bold, italic, charset, pitch)==Acad::eOk && pWinFont && pWinFont[0])
|
|
#else
|
|
bool bold, italic;
|
|
Autodesk::AutoCAD::PAL::FontUtils::FontPitch pitch;
|
|
Autodesk::AutoCAD::PAL::FontUtils::FontFamily family;
|
|
Charset charset;
|
|
if (txtStyle.font(pWinFont, bold, italic, charset, pitch, family)==Acad::eOk && pWinFont && pWinFont[0])
|
|
#endif
|
|
{
|
|
delete [] pWinFont;
|
|
bWinFont = TRUE;
|
|
}
|
|
}
|
|
XString sTxtName = GetSymbolName(idTxtStyle);
|
|
_tcsupr(sTxtName);
|
|
|
|
XString sT3TxtName(256);
|
|
sT3TxtName << sTxtName << _T("_T3");
|
|
|
|
int nColor(0);
|
|
double dEnChScaleX(1.0),dEnChScaleY(1.0);
|
|
AcDbObjectId idNewTxtStyle;
|
|
OPENOBJ_BEGIN(idTxtStyle, AcDb::kForRead, AcDbTextStyleTableRecord, pTxtStyle);
|
|
if (pTxtStyle != NULL)
|
|
{
|
|
resbuf *pxData = pTxtStyle->xData(TCHXD);
|
|
if (pxData != NULL)
|
|
{
|
|
resbuf *pNext = pxData->rbnext;
|
|
if (pNext!=NULL && pNext->restype==1040)
|
|
{
|
|
dEnChScaleY = pNext->resval.rreal;
|
|
|
|
pNext = pNext->rbnext;
|
|
if (pNext!=NULL && pNext->restype==1040)
|
|
dEnChScaleX = pNext->resval.rreal;
|
|
|
|
pNext = pNext->rbnext;
|
|
if (pNext!=NULL && pNext->restype==1070)
|
|
nColor = pNext->resval.rint;
|
|
}
|
|
ads_relrb(pxData);
|
|
}
|
|
|
|
double dChXYScale = pTxtStyle->xScale();
|
|
if (fabs(dEnChScaleX-dEnChScaleY)>1.0E-5 || fabs(dEnChScaleX-1.0)>1.0E-5)
|
|
{
|
|
dChXYScale *= dEnChScaleX / dEnChScaleY;
|
|
}
|
|
|
|
idNewTxtStyle = GetTextStyleId(sT3TxtName, pDb);
|
|
if (!idNewTxtStyle)
|
|
{
|
|
AcDbTextStyleTableRecord *pNewTxtStyle = (AcDbTextStyleTableRecord*)pTxtStyle->clone();
|
|
pNewTxtStyle->setName(sT3TxtName);
|
|
if (!bWinFont)
|
|
{
|
|
pNewTxtStyle->setXScale(dChXYScale);
|
|
}
|
|
pNewTxtStyle->setTextSize(0.0);
|
|
idNewTxtStyle = AddTextStyle(pNewTxtStyle, TRUE, pDb);
|
|
}
|
|
OPENOBJ_END()
|
|
}
|
|
|
|
|
|
|
|
//2.生成一个新的标注样式,并把新的文字样式设置到里面
|
|
XString sName = GetSymbolName(idTch); // 原有的样式名称
|
|
_tcsupr(sName);
|
|
|
|
XString sNameTch(256);
|
|
int iScale = AS_INT(nScale);
|
|
sNameTch << sName << _T("&&") << iScale; // 增加原有比例,不管是否是100,增加“&&”为了好识别样式,方便读取旧图进行转化
|
|
|
|
AcDbObjectId idAcad = GetDimStyleId(sNameTch, pDb);
|
|
if (!idAcad.isValid())
|
|
{
|
|
OPENOBJ_BEGIN(idTch, AcDb::kForRead, AcDbDimStyleTableRecord, pStyle);
|
|
if (pStyle == NULL)
|
|
{
|
|
return AcDbObjectId::kNull;
|
|
}
|
|
double ddimTextH = pStyle->dimtxt();
|
|
|
|
AcDbDimStyleTableRecord *pNewStyle = (AcDbDimStyleTableRecord *)pStyle->clone();
|
|
pNewStyle->setDimscale(1.0);
|
|
pNewStyle->setDimtxsty(idNewTxtStyle);
|
|
//由于上华文字和cad文字的高度有差异,所以将dimgap()参数增加这个差异,否则文字会变位置。
|
|
double ddimgap = pStyle->dimgap();
|
|
ddimgap += ddimTextH * (1 - dEnChScaleY) * 0.5;
|
|
|
|
//单独计算windows字体上华文字的高度
|
|
TDbText dimText;
|
|
dimText.SetAlignment(XExplodeDraw::kMiddleCenter);
|
|
dimText.SetHeight(ddimTextH);
|
|
dimText.SetText(_T("1"));
|
|
dimText.SetStyleId(idTxtStyle);
|
|
dimText.SetPScale(nScale);
|
|
TTextLine lstTextParts;
|
|
dimText.GetTextParts(lstTextParts, FALSE);
|
|
double dDH(0.0);
|
|
if (lstTextParts.Length() > 0)
|
|
{
|
|
dDH = lstTextParts[0]->m_nHeight;
|
|
}
|
|
|
|
if (bWinFont)
|
|
{
|
|
//windows字体上华文字dimgap没有差异
|
|
pNewStyle->setDimgap(pStyle->dimgap() * nScale);
|
|
pNewStyle->setDimtxt(dDH);
|
|
}
|
|
else
|
|
{
|
|
pNewStyle->setDimgap(ddimgap * nScale);
|
|
pNewStyle->setDimtxt(ddimTextH * nScale * dEnChScaleY);
|
|
}
|
|
|
|
pNewStyle->setDimexe(pStyle->dimexe() * nScale);
|
|
pNewStyle->setDimexo(pStyle->dimexo() * nScale);
|
|
pNewStyle->setDimasz(pStyle->dimasz() * nScale);
|
|
pNewStyle->setDimdle(pStyle->dimdle() * nScale);
|
|
pNewStyle->setName(sNameTch);
|
|
pNewStyle->setDimdli(0.0);
|
|
pNewStyle->setDimse1(false);
|
|
pNewStyle->setDimse2(false);
|
|
|
|
idAcad = AddDimStyle(pNewStyle, TRUE, pDb);
|
|
OPENOBJ_END()
|
|
}
|
|
return idAcad;
|
|
|
|
// 对有关的文字样式清0
|
|
// OPENOBJ_BEGIN(idAcad, AcDb::kForRead, AcDbDimStyleTableRecord, pStyle);
|
|
// if (pStyle != NULL)
|
|
// {
|
|
// AcDbObjectId idStyle = pStyle->dimtxsty();
|
|
// OPENOBJ_BEGIN(idStyle, AcDb::kForWrite, AcDbTextStyleTableRecord, pTxtStyle);
|
|
// if (pTxtStyle != NULL)
|
|
// {
|
|
// pTxtStyle->setTextSize(0.0);
|
|
// }
|
|
// OPENOBJ_END();
|
|
// }
|
|
// OPENOBJ_END();
|
|
|
|
// 对有关的文字样式清0
|
|
// OPENOBJ_BEGIN(idAcad, AcDb::kForWrite, AcDbDimStyleTableRecord, pStyle);
|
|
// if (pStyle != NULL)
|
|
// {
|
|
// if (idNewTxtStyle.isValid())
|
|
// pStyle->setDimtxsty(idNewTxtStyle);
|
|
// pStyle->close();
|
|
// }
|
|
// OPENOBJ_END();
|
|
|
|
}
|
|
|
|
// 转成DIMN, DIMNxx
|
|
AcDbObjectId DimStyleAcad2Tch(AcDbObjectId idAcad, double &nScale)
|
|
{
|
|
ASSERT(!!idAcad);
|
|
int iScale=AS_INT(nScale);
|
|
XString sNameAcad=GetSymbolName(idAcad);
|
|
_tcsupr(sNameAcad);
|
|
|
|
TCHAR szWild[100]=_T("DIMN*,DIMA*,DIMB*");
|
|
BOOL bOldTch=(ads_wcmatch(sNameAcad, szWild)==RTNORM);
|
|
|
|
// sg add 120410,增加新的带“&&”的解析,如果转出去的样式名中,有“&&”,也是T3的样式,也需要乘以100
|
|
if (!bOldTch)
|
|
{
|
|
TCHAR szWildNew[100]=_T("*&&*");
|
|
bOldTch = (ads_wcmatch(sNameAcad, szWild) == RTNORM);
|
|
}
|
|
|
|
XString sNameTch(256);
|
|
sNameTch << sNameAcad << _T("$TCH"); //转化而来
|
|
AcDbObjectId idTch=GetDimStyleId(sNameTch);
|
|
nScale=DocGetPScale();
|
|
|
|
OPENOBJ_BEGIN(idAcad, AcDb::kForRead, AcDbDimStyleTableRecord, pStyle);
|
|
if(pStyle) {
|
|
if(bOldTch) {
|
|
nScale = 100.0*pStyle->dimscale();
|
|
}
|
|
if(!idTch) {
|
|
AcDbDimStyleTableRecord *pNewStyle=(AcDbDimStyleTableRecord *)pStyle->clone();
|
|
double nFactor=pNewStyle->dimscale()/nScale;
|
|
pNewStyle->setDimscale(1.0);
|
|
pNewStyle->setDimgap(nFactor*pNewStyle->dimgap());
|
|
pNewStyle->setDimtxt(nFactor*pNewStyle->dimtxt());
|
|
pNewStyle->setDimexe(nFactor*pNewStyle->dimexe());
|
|
pNewStyle->setDimexo(nFactor*pNewStyle->dimexo());
|
|
pNewStyle->setDimasz(nFactor*pNewStyle->dimasz());
|
|
pNewStyle->setName(sNameTch);
|
|
pNewStyle->setDimdli(nFactor*pNewStyle->dimdli());
|
|
pNewStyle->setDimdle(nFactor*pNewStyle->dimdle());//add by whl on 060219 超出标记调整
|
|
idTch=AddDimStyle(pNewStyle, TRUE);
|
|
if(!idTch)
|
|
delete pNewStyle;
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
return idTch;
|
|
} |