Files
envi-code/SourceCode/Code2026/Dimension/AecDbSymbWithText.cpp
T

250 lines
5.8 KiB
C++
Raw Normal View History

2026-10-04 00:04:20 +08:00
#include "stdafx.h"
2026-09-28 15:28:50 +08:00
#include "AecDbSymbWithText.h"
#include "DimOptionData.h"
/////////////////////////////////////////////////////////////
2026-10-04 00:04:20 +08:00
// 符号标注类
2026-09-28 15:28:50 +08:00
/////////////////////////////////////////////////////////////
2026-10-04 00:04:20 +08:00
// ver:1-TArch5;2-TArch6;3,TArch7-3
2026-09-28 15:28:50 +08:00
const Adesk::UInt8 AecXDbSymbWithText::g_nVersion = 3;
extern AcDbObjectId InitLayer(const TCHAR *szLayer, AcDbDatabase *pDb = NULL);
ACRX_NO_CONS_DEFINE_MEMBERS(AecXDbSymbWithText, AecXDbEntityBaseEx);
AecXDbSymbWithText::AecXDbSymbWithText()
{
m_nTextHeight = 3.5;
m_nTextRotation = 0.0;
m_colorText = 7;
}
AecXDbSymbWithText::~AecXDbSymbWithText()
{
}
const TCHAR* AecXDbSymbWithText::GetDefaultLayer()const
{
extern TCHAR* LAY_OTHER_DIM;
return LAY_OTHER_DIM;
}
//BOOL AecXDbSymbWithText::IsValid() const
//{
// BOOL bRet = TDbEntity::IsValid();
// if (!bRet)
// return bRet;
// bRet = (m_nTextHeight > 1.0E-3 && !!m_idTextStyle);
// return bRet;
//}
2026-10-04 00:04:20 +08:00
// 提供对格式刷的支持
2026-09-28 15:28:50 +08:00
void AecXDbSymbWithText::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
{
assertWriteEnabled();
AecXDbEntityBaseEx::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
AecXDbSymbWithText *pSrc = AecXDbSymbWithText::cast(pSrcEntity);
if (pSrc)
{
if (database() == NULL ||
pSrcEntity->database() == NULL ||
database() == pSrcEntity->database()) // add by whl on 060317
{
m_idTextStyle = pSrc->m_idTextStyle;
m_idTextLayer = pSrc->m_idTextLayer;
}
2026-10-04 00:04:20 +08:00
m_nTextHeight = pSrc->m_nTextHeight; // 第一端线距离端点, 第二端线距离第一端线
2026-09-28 15:28:50 +08:00
m_nTextRotation = pSrc->m_nTextRotation;
m_colorText = pSrc->m_colorText;
}
}
//Acad::ErrorStatus
//AecXDbSymbWithText::DownGradeSave(int nDrawMode, AcDbVoidPtrArray &entSet, BOOL *bErase)
//{
2026-10-04 00:04:20 +08:00
// if (g_nSaveTArchVer < 7) // 7.0开始才有圆圈文字
2026-09-28 15:28:50 +08:00
// {
// BOOL bHasCircle = FALSE;
// long num = GetSubTextNum();
// for (long i = 0; i < num; i++)
// {
// TSubText* pSubText = GetSubText(i);
// if (pSubText != NULL)
// {
// CString sText = pSubText->GetText();
// delete pSubText;
// if (sText.Find(_T("^C")) != -1)
// {
// bHasCircle = TRUE;
// break;
// }
// }
// }
//
// if (bHasCircle)
// {
2026-10-04 00:04:20 +08:00
// XPushMemVar<BOOL> vTemp(XExplodeStream::m_bFullExplode, TRUE); // 完全分解
2026-09-28 15:28:50 +08:00
// XExplodeStream dc(entSet);
2026-10-04 00:04:20 +08:00
// if (!OnExplodeOrDraw(dc)) // sg add 090303,解决导出后,无遮挡关系的BUG
2026-09-28 15:28:50 +08:00
// return Acad::eOk;
//
// dc.SetPropertiesFrom(this);
// Acad::ErrorStatus es = Acad::eOk;
// if (nDrawMode == DRAW_2D)
// es = ExplodeOrDraw2d(dc);
// else
// es = ExplodeOrDraw3d(dc);
// if (bErase)
// *bErase = TRUE;
// return es;
// }
// }
// return TDbEntity::DownGradeSave(nDrawMode, entSet, bErase);
//}
2026-10-04 00:04:20 +08:00
// 从DWG读入数据:
2026-09-28 15:28:50 +08:00
Acad::ErrorStatus AecXDbSymbWithText::dwgInFields(AcDbDwgFiler* pFiler)
{
extern TCHAR* LAY_TEXT;
assertWriteEnabled();
Acad::ErrorStatus es = AecXDbEntityBaseEx::dwgInFields(pFiler);
if (es != Acad::eOk)
return es;
Adesk::UInt8 nVer;
pFiler->readItem(&nVer);
if (nVer > g_nVersion) { // Version is too new
return Acad::eMakeMeProxy;
}
pFiler->readItem(&m_idTextStyle);
pFiler->readItem(&m_nTextHeight);
if (nVer > 1)
{
pFiler->readItem(&m_nTextRotation);
pFiler->readItem(&m_idTextLayer);
}
else
{
m_nTextRotation = 0.0;
if (database() == acdbCurDwg())
m_idTextLayer = InitLayer(LAY_TEXT, FALSE);
else
m_idTextLayer = GlobalFunc::GetLayerIdFromString(LAY_TEXT, database());
}
if (nVer > 2)
pFiler->readItem(&m_colorText);
else
{
2026-10-04 00:04:20 +08:00
m_colorText = 7; // sg add 090608,对于7以前的图纸,默认使用白色
2026-09-28 15:28:50 +08:00
}
return pFiler->filerStatus();
}
Acad::ErrorStatus AecXDbSymbWithText::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = AecXDbEntityBaseEx::dwgOutFields(pFiler);
if (es != Acad::eOk)
return es;
pFiler->writeItem(g_nVersion);
pFiler->writeItem(m_idTextStyle);
pFiler->writeItem(m_nTextHeight);
pFiler->writeItem(m_nTextRotation);
pFiler->writeItem(m_idTextLayer);
pFiler->writeItem(m_colorText);
return pFiler->filerStatus();
}
Acad::ErrorStatus AecXDbSymbWithText::dxfInFields(AcDbDxfFiler* pFiler)
{
return AecXDbEntityBaseEx::dxfInFields(pFiler);
}
Acad::ErrorStatus AecXDbSymbWithText::dxfOutFields(AcDbDxfFiler* pFiler) const
{
return AecXDbEntityBaseEx::dxfOutFields(pFiler);
}
Acad::ErrorStatus
AecXDbSymbWithText::subTransformBy(const AcGeMatrix3d& xform)
{
AecXDbEntityBaseEx::subTransformBy(xform);
if (!g_Option::instance().g_bLayoutRotate)
{
AcGeVector3d vt(cos(m_nTextRotation), sin(m_nTextRotation), 0.0);
vt.transformBy(xform);
m_nTextRotation = ads_angle(ADSGePoint3d(), ADSGePoint3d(vt[0], vt[1]));
}
return Acad::eOk;
}
DrawModeType
AecXDbSymbWithText::GetDrawType() const
{
return k2DOnly;
}
double AecXDbSymbWithText::GetTextHeight() const
{
return m_nTextHeight;
}
AcDbObjectId AecXDbSymbWithText::GetTextStyleId() const
{
return m_idTextStyle;
}
AcDbObjectId AecXDbSymbWithText::GetTextLayerId() const
{
return m_idTextLayer;
}
void AecXDbSymbWithText::SetTextHeight(double nHeight)
{
assertWriteEnabled();
m_nTextHeight = nHeight;
}
void AecXDbSymbWithText::SetTextStyleId(AcDbObjectId id)
{
assertWriteEnabled();
m_idTextStyle = id;
}
void AecXDbSymbWithText::SetTextLayerId(AcDbObjectId id)
{
assertWriteEnabled();
m_idTextLayer = id;
}
void AecXDbSymbWithText::SetTextRotation(double nRot)
{
assertWriteEnabled();
m_nTextRotation = GlobalFunc::AngleRangeTo2PI(nRot);
}
double AecXDbSymbWithText::GetTextRotation() const
{
return m_nTextRotation;
}
BOOL AecXDbSymbWithText::IsTextRotated() const {
return (fabs(m_nTextRotation) > g_DimOption::instance()._angSnap);
}
2026-10-04 00:04:20 +08:00
// sg add 090608,增加颜色设置接口
2026-09-28 15:28:50 +08:00
void AecXDbSymbWithText::SetTextColor(Adesk::UInt16 color)
{
assertWriteEnabled();
m_colorText = color;
}
Adesk::UInt16 AecXDbSymbWithText::GetTextColor() const
{
return m_colorText;
}