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

1548 lines
44 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 "AecDbSymbMultiLeader.h"
#include "AecDbMText.h"
#include "globalFunc.h"
#include "PushProperty.h"
2026-10-04 00:04:20 +08:00
#define SMLF_PARALLEL 0x01 // 引线平行
2026-09-28 15:28:50 +08:00
const Adesk::UInt8 AecXDbSymbMultiLeader::g_nVersion = 5;
ACRX_DXF_DEFINE_MEMBERS(AecXDbSymbMultiLeader, AecXDbSymbWithText, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
2026-10-04 00:04:20 +08:00
1, AEC_YINCHUBIAOZU, "AEC_YINCHUBIAOZHU|缺乏上华解释器, 请下载上华软件|网址: www.shanghuasoft.com");
2026-09-28 15:28:50 +08:00
AecXDbSymbMultiLeader::AecXDbSymbMultiLeader()
{
m_nTextBaseLen = 10.0;
m_arrow = AecXDbSymbMultiLeader::kNone;
m_bSideText = FALSE;
m_nArrowSize = g_Option::instance().g_nArrowLen;
2026-10-04 00:04:20 +08:00
m_dText2BaseRatio = -1000; // 使用GlobalFunc::DocGetText2BaseRatio,sg add 081111
m_nTextAlign = kAtEnd; // sg add 090216,8.0的Beta2起使用
m_dPageWidth = 0; // 线上文字页宽控制,默认为单行文字
SetPageWidth2(0.0); // sg add 090410,线下文字页宽控制,默认为单行文字
m_bSymbMultiLeader = TRUE; // sg add 090723,默认为引出标注
2026-09-28 15:28:50 +08:00
2026-10-04 00:04:20 +08:00
// lxb add 111230,增加引线平行数据
2026-09-28 15:28:50 +08:00
m_nLeaderFlag = 0;
}
AecXDbSymbMultiLeader::~AecXDbSymbMultiLeader()
{
}
BOOL AecXDbSymbMultiLeader::IsValid() const
{
//BOOL bRet = AecXDbSymbWithText::IsValid();
//if (!bRet)
// return bRet;
BOOL bRet = (m_lstVertexes.Length() > 0);
return bRet;
}
const TCHAR * AecXDbSymbMultiLeader::GetDefaultLayer()const
{
extern TCHAR* LAY_LEADER_DIM;
return LAY_LEADER_DIM;
}
//Acad::ErrorStatus
//AecXDbSymbMultiLeader::subGetClassID(CLSID* pClsid) const
//{
// *pClsid = CLSID_ComSymbMultiLeader;
// return Acad::eOk;
//}
2026-10-04 00:04:20 +08:00
// 提供对格式刷的支持
2026-09-28 15:28:50 +08:00
void AecXDbSymbMultiLeader::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
{
AssertWriteEnabled();
AecXDbSymbWithText::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
AecXDbSymbMultiLeader *pSrc = AecXDbSymbMultiLeader::cast(pSrcEntity);
if (pSrc != NULL)
{
m_arrow = pSrc->m_arrow;
m_nArrowSize = pSrc->m_nArrowSize;
m_bSideText = pSrc->m_bSideText;
2026-10-04 00:04:20 +08:00
m_dText2BaseRatio = pSrc->m_dText2BaseRatio; // 文字距基线系数,sg add 081111
m_nTextAlign = pSrc->m_nTextAlign; // sg add 090401,文字相对于基线的对齐方式
//axc add 2015-12-17 电气短斜线在格式刷时重新计算第一个短斜线的两点
2026-09-28 15:28:50 +08:00
AcGeVector3d vtDir = pSrc->m_ptSortLineEnd - pSrc->m_ptSortLineStart;
if (m_lstVertexes.Length() > 0)
{
ADSGePoint3d ptLoca = *m_lstVertexes[0];
m_ptSortLineEnd = ptLoca + vtDir / 2;
m_ptSortLineStart = ptLoca - vtDir / 2;
}
//m_ptSortLineEnd = pSrc->m_ptSortLineEnd;
//m_ptSortLineStart = pSrc->m_ptSortLineStart;
}
}
2026-10-04 00:04:20 +08:00
// 从DWG读入数据:
2026-09-28 15:28:50 +08:00
Acad::ErrorStatus AecXDbSymbMultiLeader::dwgInFields(AcDbDwgFiler* pFiler)
{
AssertWriteEnabled();
Acad::ErrorStatus es = AecXDbSymbWithText::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;
}
Adesk::UInt8 nFlag;
pFiler->readItem(&nFlag);
m_arrow = (AecXDbSymbMultiLeader::TArrowStyle)nFlag;
pFiler->readItem((AcGePoint2d *)&m_ptLeader);
pFiler->readItem(&m_nTextBaseLen);
pFiler->readItem(&m_bSideText);
GlobalFunc::ReadString(pFiler, m_sText1);
GlobalFunc::ReadString(pFiler, m_sText2);
Adesk::UInt8 nNum = 0;
pFiler->readItem(&nNum);
m_lstVertexes.Reset();
for (Adesk::UInt8 i = 0; i < nNum; i++)
{
ADSGePoint3d ptVert;
pFiler->readItem((AcGePoint2d *)&ptVert);
m_lstVertexes.Append(new ADSGePoint3d(ptVert));
}
if (nVer > 1)
pFiler->readItem(&m_nArrowSize);
2026-10-04 00:04:20 +08:00
if (nVer > 2) // sg add 081111,sg modify 090216,8.0版本为3
2026-09-28 15:28:50 +08:00
{
pFiler->readItem(&m_dText2BaseRatio);
Adesk::UInt8 nTemp;
pFiler->readItem(&nTemp);
m_nTextAlign = (TSymbMLTextAlign)nTemp;
pFiler->readItem(&m_dPageWidth);
}
else
{
m_dText2BaseRatio = -1000;
m_nTextAlign = kAtEnd;
2026-10-04 00:04:20 +08:00
m_dPageWidth = 0; // 线上文字,默认为单行
2026-09-28 15:28:50 +08:00
}
2026-10-04 00:04:20 +08:00
// lxb add 111230,增加引线平行数据
if (nVer > 3) // 9.0版本
2026-09-28 15:28:50 +08:00
{
pFiler->readItem(&m_nLeaderFlag);
pFiler->readItem((AcGePoint2d*)&m_ptLeaderDirection);
}
2026-10-04 00:04:20 +08:00
else // 8.0及以前版本
2026-09-28 15:28:50 +08:00
{
m_nLeaderFlag = 0;
if (m_lstVertexes.Length() > 0)
{
m_ptLeaderDirection = m_lstVertexes[0]->AsAcGePoint3d();
}
}
if (nVer >= 5)
{
pFiler->readItem(&m_ptSortLineStart);
pFiler->readItem(&m_ptSortLineEnd);
}
return pFiler->filerStatus();
}
Acad::ErrorStatus AecXDbSymbMultiLeader::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = AecXDbSymbWithText::dwgOutFields(pFiler);
if (es != Acad::eOk)
return es;
// pFiler->writeItem(g_nVersion); // sg modify 081111
pFiler->writeItem(g_nVersion);
pFiler->writeItem((Adesk::UInt8)m_arrow);
pFiler->writeItem((const AcGePoint2d &)m_ptLeader);
pFiler->writeItem(m_nTextBaseLen);
pFiler->writeItem(m_bSideText);
pFiler->writeString(m_sText1);
pFiler->writeString(m_sText2);
Adesk::UInt8 nNum = m_lstVertexes.Length();
pFiler->writeItem(nNum);
for (Adesk::UInt8 i = 0; i < nNum; i++)
{
pFiler->writeItem((const AcGePoint2d &)m_lstVertexes[i]);
}
pFiler->writeItem(m_nArrowSize);
pFiler->writeItem(m_dText2BaseRatio);
pFiler->writeItem((Adesk::UInt8)m_nTextAlign);
pFiler->writeItem(m_dPageWidth);
pFiler->writeItem(m_nLeaderFlag);
pFiler->writeItem((const AcGePoint2d &)m_ptLeaderDirection);
pFiler->writeItem(m_ptSortLineStart);
pFiler->writeItem(m_ptSortLineEnd);
return pFiler->filerStatus();
}
Acad::ErrorStatus AecXDbSymbMultiLeader::dxfInFields(AcDbDxfFiler* pFiler)
{
return AecXDbSymbWithText::dxfInFields(pFiler);
}
Acad::ErrorStatus AecXDbSymbMultiLeader::dxfOutFields(AcDbDxfFiler* pFiler) const
{
return AecXDbSymbWithText::dxfOutFields(pFiler);
}
// -----------------------------------------------------------------------
// Active when being rotated, scaled, moved, etc.
// Scale is disabled here
Acad::ErrorStatus
AecXDbSymbMultiLeader::subTransformBy(const AcGeMatrix3d& xform)
{
AssertWriteEnabled();
// double nOldHeight = GetTextHeight();
// ADSGePoint3d ptTextBase = GetTextBasePoint();
2026-10-04 00:04:20 +08:00
ADSGePoint3d ptTextBase; // sg modify 090305,解决需求平台问题1866,GetTextBasePoint函数角度错误
2026-09-28 15:28:50 +08:00
ads_polar(m_ptLeader, m_nLayoutRotation, GetTextBaseLen(FALSE), ptTextBase);
2026-10-04 00:04:20 +08:00
AecXDbSymbWithText::subTransformBy(xform); // 当支持图纸旋转时,调用
2026-09-28 15:28:50 +08:00
ptTextBase.TransformBy(xform);
// double nScale = GetTextHeight()/nOldHeight;
ads_matrix mat;
GlobalFunc::AsAdsMatrix(xform, mat);
m_ptLeader.TransformBy(mat);
m_ptLeader.z = 0;
2026-10-04 00:04:20 +08:00
//lsd 2014-4-30 短斜线不跟着走的问题
2026-09-28 15:28:50 +08:00
ADSGePoint3d ptS(m_ptSortLineStart), ptE(m_ptSortLineEnd);
ptS.TransformBy(mat);
ptS.z = 0;
ptE.TransformBy(mat);
ptE.z = 0;
m_ptSortLineStart = ptS.AsAcGePoint3d();
m_ptSortLineEnd = ptE.AsAcGePoint3d();
//end
using namespace GlobalFunc;
Vector3D vt = ptTextBase - m_ptLeader,
vtBase(cos(m_nLayoutRotation), sin(m_nLayoutRotation));
2026-10-04 00:04:20 +08:00
// m_nTextBaseLen = (vt&vtBase)/GetPScale(); // sg modify 090317,只取符号,不改变大小
2026-09-28 15:28:50 +08:00
double dTmp = (vt & vtBase);
int nSign = (dTmp > -1.0E-5) ? 1 : (-1);
m_nTextBaseLen = nSign * fabs(m_nTextBaseLen);
2026-10-04 00:04:20 +08:00
if (xform.isUniScaledOrtho()) // sg add 090317,解决SCALE操作的问题
m_nTextBaseLen *= fabs(xform.scale()); // 只改大小,不考虑符号
2026-09-28 15:28:50 +08:00
// m_nTextBaseLen *= nScale;
for (int i = 0; i < m_lstVertexes.Length(); i++)
m_lstVertexes[i]->TransformBy(mat);
2026-10-04 00:04:20 +08:00
// add by lxb on 120104,维护不绘制的代表平行的引线方向点的变化
2026-09-28 15:28:50 +08:00
m_ptLeaderDirection.TransformBy(mat);
m_ptLeaderDirection.z = 0;
return Acad::eOk;
}
// Overriden functions for edit
Acad::ErrorStatus AecXDbSymbMultiLeader::subGetGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
assertReadEnabled();
2026-10-04 00:04:20 +08:00
// return getStretchPoints(gripPoints); // sg modify 090427,页宽夹点不支持stretch操作
2026-09-28 15:28:50 +08:00
Acad::ErrorStatus es = subGetStretchPoints(gripPoints);
2026-10-04 00:04:20 +08:00
// sg add 090413,文字内容不为空时,增加文字页宽拖拽夹点
2026-09-28 15:28:50 +08:00
ADSGePoint3d ptTemp;
2026-10-04 00:04:20 +08:00
if (!!m_sText1) // 线上文字
2026-09-28 15:28:50 +08:00
{
ADSGePoint3d ptTextLoc = GetTextPt();
double dPageWidth = GetPageWidth(FALSE);
2026-10-04 00:04:20 +08:00
if (IsUpText()) // 单行文字
2026-09-28 15:28:50 +08:00
{
ads_polar(ptTextLoc, GetLayoutRotation() + PI / 2, m_nTextHeight * GetPScale(), ptTextLoc);
if (m_nTextAlign == AecXDbSymbMultiLeader::kAtMiddle)
dPageWidth *= 0.5;
else if ((m_nTextBaseLen < 0.0 && m_nTextAlign == kAtStart) ||
(m_nTextBaseLen > 0.0 && m_nTextAlign == kAtEnd))
dPageWidth = 0;
}
ads_polar(ptTextLoc, GetLayoutRotation(), dPageWidth, ptTemp);
gripPoints.append(ptTemp);
}
2026-10-04 00:04:20 +08:00
if (!!m_sText2) // 线下文字
2026-09-28 15:28:50 +08:00
{
ADSGePoint3d ptTextLoc = GetText2Pt();
double dPageWidth = GetPageWidth2(FALSE);
2026-10-04 00:04:20 +08:00
if (IsDownText()) // 单行文字
2026-09-28 15:28:50 +08:00
{
if (m_nTextAlign == AecXDbSymbMultiLeader::kAtMiddle)
dPageWidth *= 0.5;
else if ((m_nTextBaseLen < 0.0 && m_nTextAlign == kAtStart) ||
(m_nTextBaseLen > 0.0 && m_nTextAlign == kAtEnd))
dPageWidth = 0;
}
ads_polar(ptTextLoc, GetLayoutRotation(), dPageWidth, ptTemp);
gripPoints.append(ptTemp);
}
return es;
}
// stretch points is diffrent from grep points, with no midpoint included
Acad::ErrorStatus
AecXDbSymbMultiLeader::subGetStretchPoints(AcGePoint3dArray & stretchPoints) const
{
assertReadEnabled();
stretchPoints.append(m_ptLeader);
ADSGePoint3d ptTemp;
ads_polar(m_ptLeader, GetLayoutRotation(), GetTextBaseLen(FALSE), ptTemp);
stretchPoints.append(ptTemp);
for (int i = 0; i < m_lstVertexes.Length(); i++)
stretchPoints.append(m_lstVertexes[i]);
return Acad::eOk;
}
2026-10-04 00:04:20 +08:00
// 功能: 夹点操作
2026-09-28 15:28:50 +08:00
Acad::ErrorStatus AecXDbSymbMultiLeader::subMoveGripPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
AssertWriteEnabled();
2026-10-04 00:04:20 +08:00
// 判断是否是所有的引注点都被选择为夹点,第2个标记用来标记,是否有引注点,被选中
2026-09-28 15:28:50 +08:00
bool bAllVertexes = true,
bHasVertexes = false;
for (int i = 0; i < m_lstVertexes.Length(); i++)
{
if (!indices.contains(i + 2))
bAllVertexes = false;
else
bHasVertexes = true;
}
2026-10-04 00:04:20 +08:00
// add by lxb on 2012/01/04,引注点和引线端点如果同时被选为夹点,则MOVE操作
2026-09-28 15:28:50 +08:00
if (indices.contains(0) && bAllVertexes)
{
AcGeMatrix3d mat;
mat.setToTranslation(offset);
return subTransformBy(mat);
}
ADSGePoint3d vtOffset(offset[0], offset[1]);
2026-10-04 00:04:20 +08:00
if (bAllVertexes) // 如果所有的标注点都被选中,并且没有选中引线端点,则需要修改对象内部点的位置,来改变引注方向
2026-09-28 15:28:50 +08:00
{
m_ptLeaderDirection += vtOffset;
}
2026-10-04 00:04:20 +08:00
BOOL bSkip1 = FALSE; // sg add 090514,当引线端点和文字基线点同时选中时,忽略文字基线点
2026-09-28 15:28:50 +08:00
if (indices.contains(0) && indices.contains(1))
bSkip1 = TRUE;
for (i = 0; i < indices.length(); i++)
{
int idx = indices[i];
2026-10-04 00:04:20 +08:00
if (idx == 0) // 移动引线端点
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
if (!bHasVertexes) // 如果选中某一个或几个引注点和引线端点,则认为是只改变引线长度,不改变引线方向
2026-09-28 15:28:50 +08:00
{
m_ptLeader += vtOffset;
2026-10-04 00:04:20 +08:00
// sg modify 090216/090514,解决需求平台问题496,此时,文字基线长不应该改变
2026-09-28 15:28:50 +08:00
int nLen1 = indices.length(),
nLen2 = m_lstVertexes.Length() + 2;
if (nLen1 > 1 && nLen1 < nLen2 && !indices.contains(1))
{
// m_nTextBaseLen -= vtOffset.x/GetPScale();
ADSGePoint3d vtOffset1 = vtOffset;
vtOffset1.Rotate(-GetLayoutRotation());
m_nTextBaseLen -= vtOffset1.x / GetPScale();
}
2026-10-04 00:04:20 +08:00
//lsd 2013-11-14 拖动转向
2026-09-28 15:28:50 +08:00
double dLen = GetTextBaseLen(FALSE);
ADSGePoint3d vtOffset2 = m_ptLeader - *m_lstVertexes[0];
if ((vtOffset2.x) * dLen < 0)
dLen *= -1;
SetTextBaseLen(dLen, FALSE);
//end
}
}
2026-10-04 00:04:20 +08:00
else if (idx == 1) // 移动文字基线
2026-09-28 15:28:50 +08:00
{
if (!bSkip1) // sg add 090514
{
// modified by whl on 070306
// m_nTextBaseLen += vtOffset.x/GetPScale();
ADSGePoint3d vtOffset1 = vtOffset;
vtOffset1.Rotate(-GetLayoutRotation());
2026-10-04 00:04:20 +08:00
// modify by lxb on 2012/01/05,防止基线长度夹点和引线端点夹点重合
2026-09-28 15:28:50 +08:00
// m_nTextBaseLen += vtOffset1.x/GetPScale();
double dLen = GetTextBaseLen(FALSE);
dLen += vtOffset1.x;
SetTextBaseLen(dLen, FALSE);
}
}
2026-10-04 00:04:20 +08:00
else // 移动(删除)引注点
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
//lsd 2014-4-30 移动短线
2026-09-28 15:28:50 +08:00
if (0 == i && idx == 2)
{
2026-10-04 00:04:20 +08:00
//保證每次只移動一次
2026-09-28 15:28:50 +08:00
m_ptSortLineStart += vtOffset;
m_ptSortLineEnd += vtOffset;
}
//end
int iVert = idx - 2;
if (iVert < m_lstVertexes.Length())
{
*m_lstVertexes[iVert] += vtOffset;
if (m_ptLeader.Distance2d(*m_lstVertexes[iVert]) < g_Option::instance()._DIST_SNAP)
{
if (indices.length() == 1 && m_lstVertexes.Length() > 1)
m_lstVertexes.Remove(iVert);
}
}
2026-10-04 00:04:20 +08:00
else // sg add 090413,增加文字页宽拖拽夹点
2026-09-28 15:28:50 +08:00
{
iVert = m_lstVertexes.Length() + 2;
2026-10-04 00:04:20 +08:00
if (!!m_sText1) // 线上文字
2026-09-28 15:28:50 +08:00
{
if (idx == iVert)
{
ADSGePoint3d vtOffset1 = vtOffset;
vtOffset1.Rotate(-GetLayoutRotation());
double dPageWidth = GetPageWidth(TRUE);
dPageWidth += vtOffset1.x / GetPScale();
2026-10-04 00:04:20 +08:00
if (dPageWidth > 1.0E-5) // sg add 090427,页宽不支持小于0
2026-09-28 15:28:50 +08:00
SetPageWidth(dPageWidth, TRUE);
}
iVert++;
}
2026-10-04 00:04:20 +08:00
if (!!m_sText2) // 线下文字
2026-09-28 15:28:50 +08:00
{
if (idx == iVert)
{
ADSGePoint3d vtOffset1 = vtOffset;
vtOffset1.Rotate(-GetLayoutRotation());
double dPageWidth = GetPageWidth2(TRUE);
dPageWidth += vtOffset1.x / GetPScale();
2026-10-04 00:04:20 +08:00
if (dPageWidth > 1.0E-5) // sg add 090427,页宽不支持小于0
2026-09-28 15:28:50 +08:00
SetPageWidth2(dPageWidth, TRUE);
}
iVert++;
}
}
}
}
return Acad::eOk;
}
2026-10-04 00:04:20 +08:00
// 功能: 夹点操作
2026-09-28 15:28:50 +08:00
Acad::ErrorStatus AecXDbSymbMultiLeader::subMoveStretchPointsAt(
const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
AssertWriteEnabled();
return subMoveGripPointsAt(indices, offset);
}
2026-10-04 00:04:20 +08:00
// 取得夹点说明
2026-09-28 15:28:50 +08:00
Acad::ErrorStatus AecXDbSymbMultiLeader::GetGripText(int idx, CString &cs) const
{
Acad::ErrorStatus es = Acad::eOk;
if (idx == 0)
2026-10-04 00:04:20 +08:00
cs = _T("移动引线端点");
2026-09-28 15:28:50 +08:00
else if (idx == 1)
2026-10-04 00:04:20 +08:00
cs = _T("移动文字基线");
2026-09-28 15:28:50 +08:00
else
{
2026-10-04 00:04:20 +08:00
// cs = _T("移动(删除)引注点"); // sg modify 090413,增加文字页宽拖拽夹点
2026-09-28 15:28:50 +08:00
int iVert = idx - 2;
if (iVert < m_lstVertexes.Length())
2026-10-04 00:04:20 +08:00
cs = _T("移动(删除)引注点");
2026-09-28 15:28:50 +08:00
else
{
iVert = m_lstVertexes.Length() + 2;
2026-10-04 00:04:20 +08:00
if (!!m_sText1) // 线上文字
2026-09-28 15:28:50 +08:00
{
if (iVert == idx)
2026-10-04 00:04:20 +08:00
cs = _T("修改文字1页宽");
2026-09-28 15:28:50 +08:00
iVert++;
}
2026-10-04 00:04:20 +08:00
if (!!m_sText2) // 线下文字
2026-09-28 15:28:50 +08:00
{
if (iVert == idx)
2026-10-04 00:04:20 +08:00
cs = _T("修改文字2页宽");
2026-09-28 15:28:50 +08:00
iVert++;
}
}
}
return es;
}
Acad::ErrorStatus
AecXDbSymbMultiLeader::Draw2d(AcGiDraw &dc) const
{
assertReadEnabled();
GlobalFunc::_LoadConfig();
if (Has2DBuffer() && !dc.IsDragging())
{
dc.SetColor(colorIndex());
dc.SetLayer(layerId());
BaseEx::_Draw2DBuffers(dc, true);
return Acad::eOk;
}
if (!IsValid())
return Acad::eInvalidInput;
int i = 0;
PtrList<GeLine> lnSet;
2026-10-04 00:04:20 +08:00
PtrList<GeLine> lnTmpSet; // sg add 120104,存放补充的平行线延长线
2026-09-28 15:28:50 +08:00
2026-10-04 00:04:20 +08:00
// lxb add 111230,增加引线平行的绘制
2026-09-28 15:28:50 +08:00
if (IsLeaderParall())
{
if (m_lstVertexes.Length() > 0)
{
double dTextBaseLen = GetTextBaseLen(FALSE);
if (fabs(dTextBaseLen) < 1.0E-6)
dTextBaseLen = GetDefaultTextBaseLen(FALSE);
ADSGePoint3d ptTemp, ptInter;
ads_polar(m_ptLeader, m_nLayoutRotation, dTextBaseLen, ptTemp);
2026-10-04 00:04:20 +08:00
GeLine textbaseline(m_ptLeader, ptTemp, LS_INFINITE); // 延长,直线
GeLine textbaseline1(m_ptLeader, ptTemp, LS_FINITE); // 不延长,线段
2026-09-28 15:28:50 +08:00
2026-10-04 00:04:20 +08:00
AcGeVector3d vec = m_ptLeader - m_ptLeaderDirection; // 平行引线方向
2026-09-28 15:28:50 +08:00
for (i = 0; i < m_lstVertexes.Length(); i++)
{
if (m_lstVertexes[i].Distance2d(m_ptLeader) < g_Option::instance()._DIST_SNAP)
continue;
GeLine line(m_lstVertexes[i], m_lstVertexes[i] + vec);
2026-10-04 00:04:20 +08:00
if (textbaseline1.Intersection(&line, ptInter) == 0) // 交点在线段外,需要延长文字基线
2026-09-28 15:28:50 +08:00
{
textbaseline.Intersection(&line, ptInter);
if (ptInter.Distance(m_ptLeader) < ptInter.Distance(ptTemp))
{
lnTmpSet.Append(new GeLine(m_ptLeader, ptInter, LS_FINITE));
}
else
{
lnTmpSet.Append(new GeLine(ptTemp, ptInter, LS_FINITE));
}
}
lnSet.Append(new GeLine(m_lstVertexes[i], ptInter, LS_FINITE));
}
for (i = 0; i < lnTmpSet.Length(); i++)
{
2026-10-04 00:04:20 +08:00
//dc << *lnTmpSet[i]; // 补充的平行线延长线
2026-09-28 15:28:50 +08:00
DrawLine(dc, *lnTmpSet[i]);
}
}
}
2026-10-04 00:04:20 +08:00
else // 引线不平行的情况
2026-09-28 15:28:50 +08:00
{
//for (int i=0; i<m_lstVertexes.Length(); i++)
for (i = 0; i < m_lstVertexes.Length(); i++)
{
ADSGePoint3d vertex = m_lstVertexes[i];
if (vertex.Distance2d(m_ptLeader) < g_Option::instance()._DIST_SNAP)
continue;
2026-10-04 00:04:20 +08:00
lnSet.Append(new GeLine(vertex, m_ptLeader)); // 引线
2026-09-28 15:28:50 +08:00
}
}
for (i = 0; i < lnSet.Length(); i++)
{
2026-10-04 00:04:20 +08:00
//dc << *lnSet[i]; // 绘制引线
2026-09-28 15:28:50 +08:00
DrawLine(dc, *lnSet[i]);
}
2026-10-04 00:04:20 +08:00
if (m_arrow != AecXDbSymbMultiLeader::kNone) // 绘制各种样式的箭头
2026-09-28 15:28:50 +08:00
{
double nArWidth = GetArrowSize(FALSE) * g_Option::instance().g_nArrowWidth / g_Option::instance().g_nArrowLen;
double nArLen = GetArrowSize(FALSE);
2026-10-04 00:04:20 +08:00
AcGePoint3d ptFirstS, ptFirstE;//循环第一次的直线起点和终点
2026-09-28 15:28:50 +08:00
for (i = 0; i < lnSet.Length(); i++)
{
GeLine *ln = lnSet[i];
AcDbPolyline pline;
pline.setPropertiesFrom(this);
ads_matrix mat;
ln->StartPoint().GetRotationMatrix(m_nLayoutRotation, mat);
2026-10-04 00:04:20 +08:00
if (m_arrow == AecXDbSymbMultiLeader::kArrow) // 箭头
2026-09-28 15:28:50 +08:00
{
if (ln->GetLength() < nArLen)
continue;
ADSGePoint3d ptTemp;
ads_polar(ln->StartPoint(), ln->Direction(), nArLen, ptTemp);
pline.addVertexAt(0, ln->StartPoint());
pline.addVertexAt(1, ptTemp);
pline.setWidthsAt(0, 0.0, nArWidth);
// pline.transformBy(GlobalFunc::AsAcGeMatrix3d(mat));
//dc.Polyline(pline);
DrawPline(dc, pline);
}
2026-10-04 00:04:20 +08:00
else if (m_arrow == AecXDbSymbMultiLeader::kCrossing) // 十字
2026-09-28 15:28:50 +08:00
{
GeLine ln1, ln2;
ln1.StartPoint() = ln->StartPoint() - ADSGePoint3d(nArLen / 2, 0);
ln1.EndPoint() = ln->StartPoint() + ADSGePoint3d(nArLen / 2, 0);
ln2.StartPoint() = ln->StartPoint() - ADSGePoint3d(0, nArLen / 2);
ln2.EndPoint() = ln->StartPoint() + ADSGePoint3d(0, nArLen / 2);
ln1.TransformBy(mat);
ln2.TransformBy(mat);
//dc << ln1 << ln2;
DrawLine(dc, ln1);
DrawLine(dc, ln2);
}
2026-10-04 00:04:20 +08:00
else if (m_arrow == AecXDbSymbMultiLeader::kDote) // 圆点
2026-09-28 15:28:50 +08:00
{
if (ln->GetLength() < nArWidth)
continue;
double nW = nArWidth / 4.0;
ADSGePoint3d pt1, pt2;
ads_polar(ln->StartPoint(), ln->Direction() + PI, nW, pt1);
ads_polar(ln->StartPoint(), ln->Direction(), nW, pt2);
pline.addVertexAt(0, pt1, 1.0);
pline.addVertexAt(1, pt2, 1.0);
//if (_tcscmp(dc.Desc(), XAcGiViewDraw::Descriptor()) == 0 && !objectId())
// ;
//else
// pline.setConstantWidth(nW * 2);
pline.setClosed(Adesk::kTrue);
pline.transformBy(GlobalFunc::AsAcGeMatrix3d(mat));
//dc.Polyline(pline);
DrawPline(dc, pline);
}
2026-10-04 00:04:20 +08:00
else if (m_arrow == AecXDbSymbMultiLeader::kSortLine) // 电气短线
2026-09-28 15:28:50 +08:00
{
//dc.DrawLine(GeLine(asDblArray(m_ptSortLineStart), asDblArray(m_ptSortLineEnd), LS_FINITE));
2026-10-04 00:04:20 +08:00
//axc add 2015-01-14 样式为短斜线时支持3种标准样式
//i=0时第一根短斜线始终保持与要标注的线呈45度,其余短斜线一律按照与引出直线呈45度
2026-09-28 15:28:50 +08:00
if (0 == i)
{
ptFirstS = ln->StartPoint().AsAcGePoint3d();
ptFirstE = ln->EndPoint().AsAcGePoint3d();
//dc.DrawLine(GeLine(asDblArray((const AcGePoint2d &)m_ptSortLineStart), asDblArray((const AcGePoint2d &)m_ptSortLineEnd), LS_FINITE));
DrawLine(dc, GeLine(asDblArray((const AcGePoint2d &)m_ptSortLineStart), asDblArray((const AcGePoint2d &)m_ptSortLineEnd), LS_FINITE));
}
else
{
2026-10-04 00:04:20 +08:00
//T20 v2.0以前版本的引出标注m_lstVertexes[0]与m_lstVertexes[1]相同
//究其原因是因为以前在往m_lstVertexes添加点时会事先执行lstVertexes.Remove();
//此操作没有被正确执行,后来改用lstVertexes.Reset();
//为了兼容以前的版本此处做个特殊处理,即判断i=0和i=1时两条线是否相同如果相同
2026-09-28 15:28:50 +08:00
if (ln->StartPoint().AsAcGePoint3d().isEqualTo(ptFirstS) &&
ln->EndPoint().AsAcGePoint3d().isEqualTo(ptFirstE))
{
continue;
}
GeLine lnSortLine;
AcGeVector3d vtSortLine = ln->EndPoint() - ln->StartPoint();
vtSortLine = vtSortLine.rotateBy(PI / 2, AcGeVector3d::kZAxis);
vtSortLine.normalize();
lnSortLine.StartPoint() = ln->StartPoint() - vtSortLine * nArLen / 2;
lnSortLine.EndPoint() = ln->StartPoint() + vtSortLine * nArLen / 2;
lnSortLine.TransformBy(mat);
//dc << lnSortLine;
DrawLine(dc, lnSortLine);
}
}
}
}
ADSGePoint3d ptTemp;
ads_polar(m_ptLeader, m_nLayoutRotation, GetTextBaseLen(FALSE), ptTemp);
2026-10-04 00:04:20 +08:00
//dc << GeLine(m_ptLeader, ptTemp); // 绘制文字基线
2026-09-28 15:28:50 +08:00
DrawLine(dc, m_ptLeader, ptTemp);
2026-10-04 00:04:20 +08:00
// sg modify 090409,将文字分为单行文字和多行文字
2026-09-28 15:28:50 +08:00
// double nText2Base = DocGetText2Base()*GetPScale();
2026-10-04 00:04:20 +08:00
double nText2Base = GetText2BaseRatio(FALSE, TRUE); // sg modify 081111,距基线系数
if (!!m_sText1 || g_Option::instance().g_bExplodeSubText) // 绘制线上文字
2026-09-28 15:28:50 +08:00
{
AecXDbText *pText = IsUpText() ? (new AecXDbText) : (new AecXDbMText);
AecXDbText &text = *pText;
text.SetPScale(GetPScale());
text.setPropertiesFrom(this);
2026-10-04 00:04:20 +08:00
// text.SetRotation(m_nTextRotation); // 文字一律使用布局转角
2026-09-28 15:28:50 +08:00
text.SetHeight(m_nTextHeight);
text.SetStyleId(m_idTextStyle);
text.SetText(m_sText1);
//if (dc.IsExportTch4()) // sg modify 090608
//{
2026-10-04 00:04:20 +08:00
// // sg add 120313,分解出来的文字的图层和颜色要随“高级选项”中的设置来处理
2026-09-28 15:28:50 +08:00
// // if (!!m_idTextLayer)
// if (g_nSymbTextT3Layer == 1 && !!m_idTextLayer)
// {
2026-10-04 00:04:20 +08:00
// text.setLayer(m_idTextLayer); // 文字层
// text.setColorIndex(256); // sg add 110616,解决坐标文字图形导出T3时候颜色错误
2026-09-28 15:28:50 +08:00
// }
// else
2026-10-04 00:04:20 +08:00
// text.setColorIndex(m_colorText); // 文字和标注放在同一层,文字的颜色为白色
2026-09-28 15:28:50 +08:00
//}
//else
2026-10-04 00:04:20 +08:00
text.setColorIndex(m_colorText); // sg add 090608,将文字和标注放在同一层,文字的颜色为白色
2026-09-28 15:28:50 +08:00
2026-10-04 00:04:20 +08:00
ADSGePoint3d ptLoc = GetTextPt(FALSE); // 文字位置点
2026-09-28 15:28:50 +08:00
text.SetLocation(ptLoc);
2026-10-04 00:04:20 +08:00
if (IsUpText()) // m_sText1为单行文字
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
if (m_bSideText) // 注:本段代码实际上未使用
2026-09-28 15:28:50 +08:00
text.SetAlignment((m_nTextBaseLen < 0.0) ? AcGiDraw::kMiddleLeft : AcGiDraw::kMiddleRight);
else
{
2026-10-04 00:04:20 +08:00
// sg modify 090401,处理对齐方式的问题
2026-09-28 15:28:50 +08:00
// text.SetAlignment(m_nTextBaseLen<0.0?AcGiDraw::kBottomLeft:AcGiDraw::kBottomRight);
AcGiDraw::TextAlignment nAlign = AcGiDraw::kBottomLeft;
2026-10-04 00:04:20 +08:00
if (m_nTextAlign == kAtMiddle) // 居中对齐
2026-09-28 15:28:50 +08:00
nAlign = AcGiDraw::kBottomCenter;
2026-10-04 00:04:20 +08:00
else if (m_nTextAlign == kAtStart) // 起端对齐
2026-09-28 15:28:50 +08:00
nAlign = (m_nTextBaseLen < 0.0 ? AcGiDraw::kBottomRight : nAlign);
2026-10-04 00:04:20 +08:00
else // 末端对齐
2026-09-28 15:28:50 +08:00
nAlign = (m_nTextBaseLen < 0.0 ? nAlign : AcGiDraw::kBottomRight);
text.SetAlignment(nAlign);
}
2026-10-04 00:04:20 +08:00
// sg add 090724,率先解决坐标文字,线上、下文字距离文字基线距离相等的问题
2026-09-28 15:28:50 +08:00
if (!m_bSymbMultiLeader)
{
ADSGePoint3d ptMin, ptMax;
2026-10-04 00:04:20 +08:00
text.SetLayoutRotation(0.0); // 获得外包框的时候,一定要不考虑布局转角、文字转角
2026-09-28 15:28:50 +08:00
text.GetExtents2d(ptMin, ptMax);
double dTmp = 0;
2026-10-04 00:04:20 +08:00
// sg add 090819,防止批量转旧时,无法得到文字外包围框
2026-09-28 15:28:50 +08:00
if (ptMin != ADSGePoint3d() || ptMax != ADSGePoint3d())
{
dTmp = ptLoc.y - ptMin.y;
}
text.SetLayoutRotation(m_nLayoutRotation);
ptLoc = GetTextPt();
ADSGePoint3d ptDraw = ptLoc;
ads_polar(ptLoc, m_nLayoutRotation + PI / 2, dTmp, ptDraw);
text.SetLocation(ptDraw);
}
}
2026-10-04 00:04:20 +08:00
else // m_sText1为多行文字
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
((AecXDbMText &)text).SetLineSpace(nText2Base, FALSE); // 行间距
((AecXDbMText &)text).SetPageWidth(GetPageWidth(FALSE), FALSE); // 页宽
text.SetAlignment(AcGiDraw::kLeft); // 对齐方式
2026-09-28 15:28:50 +08:00
}
PushProperty vProp(&text, dc);
//if (dc.IsFullExplode())
// text.ExplodeOrDraw2d(dc);
//else
// dc.DrawEntity(text);
DrawBaseEx(dc, text);
delete pText;
}
2026-10-04 00:04:20 +08:00
if (!!m_sText2 || g_Option::instance().g_bExplodeSubText) // 绘制线下文字
2026-09-28 15:28:50 +08:00
{
BOOL bText = IsDownText();
AecXDbText *pText = bText ? (new AecXDbText) : (new AecXDbMText);
AecXDbText &text = *pText;
text.SetPScale(GetPScale());
text.setPropertiesFrom(this);
text.SetHeight(m_nTextHeight);
text.SetStyleId(m_idTextStyle);
text.SetText(m_sText2);
//if (dc.IsExportTch4()) // sg modify 090608
//{
2026-10-04 00:04:20 +08:00
// // sg add 120313,分解出来的文字的图层和颜色要随“高级选项”中的设置来处理
2026-09-28 15:28:50 +08:00
// // if (!!m_idTextLayer)
// if (g_nSymbTextT3Layer == 1 && !!m_idTextLayer)
// {
2026-10-04 00:04:20 +08:00
// text.setLayer(m_idTextLayer); // 文字层
// text.setColorIndex(256); // sg add 110616,解决坐标文字图形导出T3时候颜色错误
2026-09-28 15:28:50 +08:00
// }
// else
2026-10-04 00:04:20 +08:00
// text.setColorIndex(m_colorText); // 文字和标注放在同一层,文字的颜色为白色
2026-09-28 15:28:50 +08:00
//}
//else
2026-10-04 00:04:20 +08:00
text.setColorIndex(m_colorText); // sg add 090608,将文字和标注放在同一层,文字的颜色为白色
2026-09-28 15:28:50 +08:00
2026-10-04 00:04:20 +08:00
ADSGePoint3d ptLoc = GetText2Pt(FALSE); // 文字位置点
2026-09-28 15:28:50 +08:00
text.SetLocation(ptLoc);
2026-10-04 00:04:20 +08:00
if (bText) // m_sText2为单行文字
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
// sg modify 090401,处理对齐方式的问题
2026-09-28 15:28:50 +08:00
// text.SetAlignment(m_nTextBaseLen<0.0?AcGiDraw::kTopLeft:AcGiDraw::kTopRight);
AcGiDraw::TextAlignment nAlign = AcGiDraw::kTopLeft;
2026-10-04 00:04:20 +08:00
if (m_nTextAlign == kAtMiddle) // 居中对齐
2026-09-28 15:28:50 +08:00
nAlign = AcGiDraw::kTopCenter;
2026-10-04 00:04:20 +08:00
else if (m_nTextAlign == kAtStart) // 起端对齐
2026-09-28 15:28:50 +08:00
nAlign = (m_nTextBaseLen < 0.0 ? AcGiDraw::kTopRight : nAlign);
2026-10-04 00:04:20 +08:00
else // 末端对齐
2026-09-28 15:28:50 +08:00
nAlign = (m_nTextBaseLen < 0.0 ? nAlign : AcGiDraw::kTopRight);
text.SetAlignment(nAlign);
2026-10-04 00:04:20 +08:00
// sg add 090724,率先解决坐标文字,线上、下文字距离文字基线距离相等的问题
2026-09-28 15:28:50 +08:00
if (!m_bSymbMultiLeader)
{
ADSGePoint3d ptMin, ptMax;
2026-10-04 00:04:20 +08:00
text.SetLayoutRotation(0.0); // 获得外包框的时候,一定要不考虑布局转角、文字转角
2026-09-28 15:28:50 +08:00
text.GetExtents2d(ptMin, ptMax);
double dTmp = 0;
2026-10-04 00:04:20 +08:00
// sg add 090819,防止批量转旧时,无法得到文字外包围框
2026-09-28 15:28:50 +08:00
if (ptMin != ADSGePoint3d() || ptMax != ADSGePoint3d())
{
dTmp = ptLoc.y - ptMax.y;
}
text.SetLayoutRotation(m_nLayoutRotation);
ptLoc = GetText2Pt();
ADSGePoint3d ptDraw = ptLoc;
ads_polar(ptLoc, m_nLayoutRotation + PI / 2, dTmp, ptDraw);
text.SetLocation(ptDraw);
}
}
2026-10-04 00:04:20 +08:00
else // m_sText2为多行文字
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
((AecXDbMText &)text).SetPageWidth(GetPageWidth2(FALSE), FALSE); // 页宽
((AecXDbMText &)text).SetLineSpace(nText2Base, FALSE); // 行间距
text.SetAlignment(AcGiDraw::kLeft); // 对齐方式
2026-09-28 15:28:50 +08:00
}
PushProperty vProp(&text, dc);
//if (dc.IsFullExplode())
// text.ExplodeOrDraw2d(dc);
//else
// dc.DrawEntity(text);
DrawBaseEx(dc, text);
delete pText;
}
return Acad::eOk;
}
2026-10-04 00:04:20 +08:00
// sg add 110301,支持统一标高
2026-09-28 15:28:50 +08:00
bool AecXDbSymbMultiLeader::UnifyElevation(double dElevation)
{
AssertWriteEnabled();
m_lstVertexes.SetElevation(dElevation);
m_ptLeader.z = dElevation;
m_ptLeaderDirection.z = dElevation;
return true;
}
int AecXDbSymbMultiLeader::ConvertText(TConvertTextPtr ptr, void *pData)
{
AssertWriteEnabled();
TCString sText;
int nRet = ptr(m_sText1, sText, pData);
if (nRet == RTNORM)
{
m_sText1 = sText;
}
int nRet1 = ptr(m_sText2, sText, pData);
if (nRet1 == RTNORM)
{
m_sText2 = sText;
}
else if (nRet1 == RTERROR)
nRet = nRet1;
return nRet;
}
BOOL AecXDbSymbMultiLeader::GetText(Adesk::UInt32 cookies, AecXDbText &text) const
{
if (cookies > 1)
return FALSE;
text.setPropertiesFrom(this);
text.SetRotation(0);
text.SetHeight(m_nTextHeight);
text.SetStyleId(m_idTextStyle);
ADSGePoint3d ptLoc;
2026-10-04 00:04:20 +08:00
if (cookies == 0) // 线上文字
2026-09-28 15:28:50 +08:00
{
ptLoc = GetTextPt();
text.SetText(m_sText1);
2026-10-04 00:04:20 +08:00
if (IsUpText()) // 单行文字
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
if (m_bSideText) // 注:该变量未使用
2026-09-28 15:28:50 +08:00
text.SetAlignment(m_nTextBaseLen < 0.0 ? AcGiDraw::kMiddleLeft : AcGiDraw::kMiddleRight);
else
{
AcGiDraw::TextAlignment nAlign = AcGiDraw::kBottomLeft;
2026-10-04 00:04:20 +08:00
if (m_nTextAlign == kAtMiddle) // 居中对齐
2026-09-28 15:28:50 +08:00
nAlign = AcGiDraw::kBottomCenter;
2026-10-04 00:04:20 +08:00
else if (m_nTextAlign == kAtStart) // 起端对齐
2026-09-28 15:28:50 +08:00
nAlign = (m_nTextBaseLen < 0.0 ? AcGiDraw::kBottomRight : nAlign);
2026-10-04 00:04:20 +08:00
else // 末端对齐
2026-09-28 15:28:50 +08:00
nAlign = (m_nTextBaseLen < 0.0 ? nAlign : AcGiDraw::kBottomRight);
text.SetAlignment(nAlign);
}
}
2026-10-04 00:04:20 +08:00
else // 多行文字
2026-09-28 15:28:50 +08:00
text.SetAlignment(AcGiDraw::kLeft);
}
2026-10-04 00:04:20 +08:00
else // 线下文字
2026-09-28 15:28:50 +08:00
{
ptLoc = GetText2Pt();
text.SetText(m_sText2);
2026-10-04 00:04:20 +08:00
if (IsDownText()) // 单行文字
2026-09-28 15:28:50 +08:00
{
AcGiDraw::TextAlignment nAlign = AcGiDraw::kTopLeft;
2026-10-04 00:04:20 +08:00
if (m_nTextAlign == kAtMiddle) // 居中对齐
2026-09-28 15:28:50 +08:00
nAlign = AcGiDraw::kTopCenter;
2026-10-04 00:04:20 +08:00
else if (m_nTextAlign == kAtStart) // 起端对齐
2026-09-28 15:28:50 +08:00
nAlign = (m_nTextBaseLen < 0.0 ? AcGiDraw::kTopRight : nAlign);
2026-10-04 00:04:20 +08:00
else // 末端对齐
2026-09-28 15:28:50 +08:00
nAlign = (m_nTextBaseLen < 0.0 ? nAlign : AcGiDraw::kTopRight);
text.SetAlignment(nAlign);
}
2026-10-04 00:04:20 +08:00
else // 多行文字
2026-09-28 15:28:50 +08:00
text.SetAlignment(AcGiDraw::kLeft);
}
text.SetLocation(ptLoc);
return TRUE;
}
2026-10-04 00:04:20 +08:00
// 返回发现的位置,同时posStart往前移动(以便继续找下一个使用),
2026-09-28 15:28:50 +08:00
TextPosition
AecXDbSymbMultiLeader::FindSubText(const TCHAR *sSubText, TextPosition &posStart,
TextRange *pRange) const
{
TextPosition pos;
if (!sSubText || !sSubText[0])
return pos;
TextPosition posNext = posStart;
double dRatio = GetText2BaseRatio(FALSE, TRUE);
while (1)
{
TextPosition posFind;
2026-10-04 00:04:20 +08:00
int nCookies = posNext.m_nCookies; // sg modify 090409,兼顾单行、多行文字
if (nCookies == 0) // 线上文字
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
if (IsUpText()) // 单行文字
2026-09-28 15:28:50 +08:00
{
AecXDbText text;
text.SetPScale(GetPScale());
if (!GetText(nCookies, text))
break;
posFind = text.FindSubText(sSubText, posNext, pRange);
}
2026-10-04 00:04:20 +08:00
else // 多行文字
2026-09-28 15:28:50 +08:00
{
AecXDbMText mText;
((AecXDbMText &)mText).SetLineSpace(dRatio, FALSE);
((AecXDbMText &)mText).SetPageWidth(GetPageWidth(FALSE), FALSE);
if (!GetText(nCookies, mText))
break;
posFind = mText.FindSubText(sSubText, posNext, pRange);
}
}
2026-10-04 00:04:20 +08:00
else // 线下文字
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
if (IsDownText()) // 单行文字
2026-09-28 15:28:50 +08:00
{
AecXDbText text;
text.SetPScale(GetPScale());
if (!GetText(nCookies, text))
break;
posFind = text.FindSubText(sSubText, posNext, pRange);
}
2026-10-04 00:04:20 +08:00
else // 多行文字
2026-09-28 15:28:50 +08:00
{
AecXDbMText mText;
double dPageWidth = GetPageWidth2(FALSE);
((AecXDbMText &)mText).SetPageWidth(dPageWidth, FALSE);
((AecXDbMText &)mText).SetLineSpace(dRatio, FALSE);
if (!GetText(nCookies, mText))
break;
posFind = mText.FindSubText(sSubText, posNext, pRange);
}
}
if (!posFind)
{
posNext.m_nCookies++;
posNext.m_nTextPos = 0;
}
else
{
posStart = posNext;
if (!posStart)
{
posStart.m_nCookies++;
posStart.m_nTextPos = 0;
}
posFind.m_nCookies = posNext.m_nCookies;
pos = posFind;
break;
}
}
return pos;
}
2026-10-04 00:04:20 +08:00
// 返回下一次查找的开始位置
2026-09-28 15:28:50 +08:00
TextPosition
AecXDbSymbMultiLeader::ReplaceSubText(const TextPosition &posRep, const TCHAR *sRepText,
TextRange *pRange)
{
AssertWriteEnabled();
TextPosition posNext;
double dRatio = GetText2BaseRatio(FALSE, TRUE);
2026-10-04 00:04:20 +08:00
int cookies = posRep.m_nCookies; // sg modify 090409,兼顾单行、多行文字
if (cookies == 0) // 线上文字
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
if (IsUpText()) // 单行文字
2026-09-28 15:28:50 +08:00
{
AecXDbText text;
text.SetPScale(GetPScale());
if (!sRepText || !GetText(cookies, text))
return posNext;
posNext = text.ReplaceSubText(posRep, sRepText, pRange);
SetText1(text.GetText());
}
2026-10-04 00:04:20 +08:00
else // 多行文字
2026-09-28 15:28:50 +08:00
{
AecXDbMText mText;
((AecXDbMText &)mText).SetLineSpace(dRatio, FALSE);
((AecXDbMText &)mText).SetPageWidth(GetPageWidth(FALSE), FALSE);
if (!sRepText || !GetText(cookies, mText))
return posNext;
posNext = mText.ReplaceSubText(posRep, sRepText, pRange);
SetText1(mText.GetText());
}
}
2026-10-04 00:04:20 +08:00
else // 线下文字
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
if (IsDownText()) // 单行文字
2026-09-28 15:28:50 +08:00
{
AecXDbText text;
text.SetPScale(GetPScale());
if (!sRepText || !GetText(cookies, text))
return posNext;
posNext = text.ReplaceSubText(posRep, sRepText, pRange);
SetText2(text.GetText());
}
2026-10-04 00:04:20 +08:00
else // 多行文字
2026-09-28 15:28:50 +08:00
{
AecXDbMText mText;
double dPageWidth = GetPageWidth2(FALSE);
((AecXDbMText &)mText).SetPageWidth(dPageWidth, FALSE);
((AecXDbMText &)mText).SetLineSpace(dRatio, FALSE);
if (!sRepText || !GetText(cookies, mText))
return posNext;
posNext = mText.ReplaceSubText(posRep, sRepText, pRange);
SetText2(mText.GetText());
}
}
if (!posNext)
{
posNext.m_nCookies = posRep.m_nCookies + 1;
posNext.m_nTextPos = 0;
}
return posNext;
}
2026-10-04 00:04:20 +08:00
/* * * * * * * * * * 取 动 态 属 性 显 示 数 据 的 函 数 * * * * * * * * * */
2026-09-28 15:28:50 +08:00
void AecXDbSymbMultiLeader::GetTips(PtrList<ObjInfoUnit> &lstInfo) const
{
2026-10-04 00:04:20 +08:00
lstInfo.Append(new ObjInfoUnit(_T("对象类型"), _T("引出标注")));
lstInfo.Append(new ObjInfoUnit(_T("文字1"), m_sText1));
lstInfo.Append(new ObjInfoUnit(_T("文字2"), m_sText2));
2026-09-28 15:28:50 +08:00
TCString sTextStyle = GlobalFunc::GetSymbolName(m_idTextStyle);
2026-10-04 00:04:20 +08:00
lstInfo.Append(new ObjInfoUnit(_T("文字样式"), sTextStyle));
2026-09-28 15:28:50 +08:00
TCString sHeight;
GlobalFunc::ftoa(m_nTextHeight, 1, sHeight);
sHeight << _T("P");
2026-10-04 00:04:20 +08:00
lstInfo.Append(new ObjInfoUnit(_T("文字高度"), sHeight));
2026-09-28 15:28:50 +08:00
}
double AecXDbSymbMultiLeader::GetMinTextBaseLen(BOOL bAsPaperUnit) const
{
if (!m_sText1 && !m_sText2)
return 0.0;
AecXDbText text;
text.SetPScale(GetPScale());
text.setPropertiesFrom(this);
text.SetHeight(m_nTextHeight);
text.SetStyleId(m_idTextStyle);
double nVal = 0.0;
if (!!m_sText1)
{
text.SetText(m_sText1);
ADSGePoint3d ptExt = text.GetExtents();
nVal = max(nVal, ptExt.x);
}
if (!!m_sText2)
{
text.SetText(m_sText2);
ADSGePoint3d ptExt = text.GetExtents();
nVal = max(nVal, ptExt.x);
}
if (bAsPaperUnit)
nVal /= GetPScale();
return nVal;
}
double AecXDbSymbMultiLeader::GetDefaultTextBaseLen(BOOL bAsPaperUnit) const
{
double nVal = 10.0;
if (!bAsPaperUnit)
nVal *= GetPScale();
return max(nVal, GetMinTextBaseLen(bAsPaperUnit));
}
ADSGePoint3d AecXDbSymbMultiLeader::GetLeaderPoint() const
{
return m_ptLeader;
}
const TCHAR * AecXDbSymbMultiLeader::GetText1() const
{
return (const TCHAR *)m_sText1;
}
const TCHAR * AecXDbSymbMultiLeader::GetText2() const
{
return (const TCHAR *)m_sText2;
}
BOOL AecXDbSymbMultiLeader::IsSideText() const
{
return m_bSideText;
}
double AecXDbSymbMultiLeader::GetTextBaseLen(BOOL bAsPaperUnit) const
{
double val = m_nTextBaseLen;
if (!bAsPaperUnit)
val *= GetPScale();
return val;
}
ADSGePoint3d AecXDbSymbMultiLeader::GetTextBasePoint() const
{
ADSGePoint3d pt;
ads_polar(m_ptLeader, 0.0, GetTextBaseLen(FALSE), pt);
return pt;
}
void AecXDbSymbMultiLeader::GetLeaderVertexes(ADSGePointList &pts) const
{
pts = m_lstVertexes;
}
AecXDbSymbMultiLeader::TArrowStyle AecXDbSymbMultiLeader::GetArrow() const
{
return m_arrow;
}
double AecXDbSymbMultiLeader::GetArrowSize(BOOL bAsPaperUnit) const
{
double nSize = m_nArrowSize;
if (!bAsPaperUnit)
nSize *= GetPScale();
return nSize;
}
2026-10-04 00:04:20 +08:00
// sg modify 120104,新增加的参数用于判断是否要给m_ptLeaderDirection赋值,内部数据用于引线平行样式
2026-09-28 15:28:50 +08:00
//void AecXDbSymbMultiLeader::SetLeaderVertexes(const ADSGePointList &pts, BOOL bUpdateLeaderDirection)
void AecXDbSymbMultiLeader::SetLeaderVertexes(const ADSGePointList &pts, BOOL bUpdateLeaderDirection)
{
AssertWriteEnabled();
m_lstVertexes = pts;
2026-10-04 00:04:20 +08:00
// sg add 120104,更新m_ptLeaderDirection
2026-09-28 15:28:50 +08:00
if (bUpdateLeaderDirection)
{
if (m_lstVertexes.Length() > 0)
{
m_ptLeaderDirection = m_lstVertexes[0]->AsAcGePoint3d();
}
}
}
void AecXDbSymbMultiLeader::SetSideText(BOOL bTrue)
{
AssertWriteEnabled();
m_bSideText = (bTrue != 0);
}
void AecXDbSymbMultiLeader::SetTextBaseLen(double val, BOOL bAsPaperUnit)
{
AssertWriteEnabled();
2026-10-04 00:04:20 +08:00
// add by lxb on 2012/01/05,防止基线长度夹点和引线端点夹点重合
2026-09-28 15:28:50 +08:00
if (fabs(val) < 1E-6)
{
return;
}
m_nTextBaseLen = val;
if (!bAsPaperUnit)
m_nTextBaseLen /= GetPScale();
}
void AecXDbSymbMultiLeader::SetArrow(AecXDbSymbMultiLeader::TArrowStyle ar)
{
AssertWriteEnabled();
m_arrow = ar;
}
void AecXDbSymbMultiLeader::SetLeaderPoint(ADSGePoint3d pt)
{
AssertWriteEnabled();
m_ptLeader = pt;
}
void AecXDbSymbMultiLeader::SetText2(const TCHAR *pszText)
{
AssertWriteEnabled();
m_sText2 = pszText;
}
void AecXDbSymbMultiLeader::SetText1(const TCHAR *pszText)
{
AssertWriteEnabled();
m_sText1 = pszText;
}
void AecXDbSymbMultiLeader::SetArrowSize(double nSize, BOOL bAsPaperUnit)
{
AssertWriteEnabled();
m_nArrowSize = nSize;
if (!bAsPaperUnit)
m_nArrowSize /= GetPScale();
}
double AecXDbSymbMultiLeader::GetText2BaseRatio(BOOL bAsPaperUnit, BOOL bRealDist) const
{
2026-10-04 00:04:20 +08:00
double dVal = m_dText2BaseRatio; // 系数
2026-09-28 15:28:50 +08:00
if (fabs(dVal + 1000) < 1.0E-5)
{
2026-10-04 00:04:20 +08:00
dVal = GlobalFunc::DocGetText2BaseRatio(); // 使用全局变量GlobalFunc::DocGetText2BaseRatio的值
2026-09-28 15:28:50 +08:00
}
if (bRealDist)
{
2026-10-04 00:04:20 +08:00
dVal *= m_nTextHeight; // 将“系数”转为“实际值”
2026-09-28 15:28:50 +08:00
}
2026-10-04 00:04:20 +08:00
if (!bAsPaperUnit) // 处理出图比例
2026-09-28 15:28:50 +08:00
{
dVal *= GetPScale();
}
return dVal;
}
void AecXDbSymbMultiLeader::SetText2BaseRatio(double dVal, BOOL bAsPaperUnit)
{
AssertWriteEnabled();
2026-10-04 00:04:20 +08:00
m_dText2BaseRatio = dVal; // 系数
2026-09-28 15:28:50 +08:00
if (!bAsPaperUnit)
{
m_dText2BaseRatio /= GetPScale();
}
}
AecXDbSymbMultiLeader::TSymbMLTextAlign AecXDbSymbMultiLeader::GetTextAlign() const
{
return m_nTextAlign;
}
void AecXDbSymbMultiLeader::SetTextAlign(TSymbMLTextAlign align)
{
AssertWriteEnabled();
m_nTextAlign = align;
}
void AecXDbSymbMultiLeader::SetPageWidth(double dVal, BOOL bAsPaperUnit)
{
AssertWriteEnabled();
m_dPageWidth = dVal;
if (!bAsPaperUnit)
{
m_dPageWidth /= GetPScale();
}
}
double AecXDbSymbMultiLeader::GetPageWidth(BOOL bAsPaperUnit) const
{
double dVal = m_dPageWidth;
if (fabs(dVal) < 1.0E-5)
{
AecXDbText text;
text.SetPScale(GetPScale());
text.setPropertiesFrom(this);
text.SetHeight(m_nTextHeight);
text.SetStyleId(m_idTextStyle);
text.SetText(m_sText1);
ADSGePoint3d ptExt = text.GetExtents();
dVal = ptExt.x;
if (bAsPaperUnit)
dVal /= GetPScale();
return dVal;
}
if (!bAsPaperUnit)
dVal *= GetPScale();
return dVal;
}
void AecXDbSymbMultiLeader::SetPageWidth2(double dVal, BOOL bAsPaperUnit)
{
AssertWriteEnabled();
double dPageWidth = dVal;
if (!bAsPaperUnit)
dPageWidth /= GetPScale();
EntityFields &fd = Fields();
2026-10-04 00:04:20 +08:00
fd.SFD(_T("线下文字页宽"), dPageWidth);
2026-09-28 15:28:50 +08:00
}
2026-10-04 00:04:20 +08:00
// sg add 090410,线下文字页宽,动态数据
2026-09-28 15:28:50 +08:00
double AecXDbSymbMultiLeader::GetPageWidth2(BOOL bAsPaperUnit) const
{
assertReadEnabled();
double dPageWidth(0.0);
const EntityFields &fd = GetFields();
2026-10-04 00:04:20 +08:00
fd.GFD(_T("线下文字页宽"), dPageWidth);
2026-09-28 15:28:50 +08:00
if (fabs(dPageWidth) < 1.0E-5)
{
AecXDbText text;
text.SetPScale(GetPScale());
text.setPropertiesFrom(this);
text.SetHeight(m_nTextHeight);
text.SetStyleId(m_idTextStyle);
text.SetText(m_sText2);
ADSGePoint3d ptExt = text.GetExtents();
dPageWidth = ptExt.x;
if (bAsPaperUnit)
dPageWidth /= GetPScale();
return dPageWidth;
}
if (!bAsPaperUnit)
dPageWidth *= GetPScale();
return dPageWidth;
}
// sg add 090413
2026-10-04 00:04:20 +08:00
BOOL AecXDbSymbMultiLeader::IsUpText() const // 线上文字,是否是单行文字
2026-09-28 15:28:50 +08:00
{
return fabs(m_dPageWidth) < 1.0E-5;
}
2026-10-04 00:04:20 +08:00
BOOL AecXDbSymbMultiLeader::IsDownText() const // 线下文字,是否是单行文字
2026-09-28 15:28:50 +08:00
{
double dPageWidth(0.0);
const EntityFields &fd = GetFields();
2026-10-04 00:04:20 +08:00
fd.GFD(_T("线下文字页宽"), dPageWidth);
2026-09-28 15:28:50 +08:00
return fabs(dPageWidth) < 1.0E-5;
}
2026-10-04 00:04:20 +08:00
// sg add 090413,分别计算两段文字位置点
2026-09-28 15:28:50 +08:00
ADSGePoint3d AecXDbSymbMultiLeader::GetTextPt(BOOL bUseLayout) const
{
2026-10-04 00:04:20 +08:00
// sg add 090724,如果是坐标标注,忽略引线距离末端距离
2026-09-28 15:28:50 +08:00
double dDistRatio = GlobalFunc::DocGetMultiLeaderDistRatio();
if (!m_bSymbMultiLeader)
dDistRatio = 0;
double dDist = dDistRatio * m_nTextHeight * GetPScale(),
dSign = 1.0;
if (fabs(m_nTextBaseLen) > 1.0E-5)
dSign = m_nTextBaseLen / (fabs(m_nTextBaseLen));
dDist *= dSign;
2026-10-04 00:04:20 +08:00
// sg add 090724,调整坐标上下文字距离基线距离
2026-09-28 15:28:50 +08:00
double dLayoutRotation = m_nLayoutRotation;
if (!m_bSymbMultiLeader)
{
if (!bUseLayout)
dLayoutRotation = 0;
}
ADSGePoint3d ptEnd, ptTemp;
2026-10-04 00:04:20 +08:00
ads_polar(m_ptLeader, dLayoutRotation, GetTextBaseLen(FALSE), ptEnd); // 文字基线
if (m_nTextAlign == kAtMiddle) // 居中对齐
2026-09-28 15:28:50 +08:00
{
Midpoint(m_ptLeader, ptEnd, ptTemp);
}
2026-10-04 00:04:20 +08:00
else if (m_nTextAlign == kAtStart) // 起端对齐
2026-09-28 15:28:50 +08:00
ads_polar(m_ptLeader, dLayoutRotation, dDist, ptTemp);
2026-10-04 00:04:20 +08:00
else // 末端对齐
2026-09-28 15:28:50 +08:00
ads_polar(ptEnd, dLayoutRotation, -dDist, ptTemp);
ADSGePoint3d ptRet = ptTemp;
2026-10-04 00:04:20 +08:00
double nText2Base = GetText2BaseRatio(FALSE, TRUE); // 距基线距离
if (!m_sText1 && g_Option::instance().g_bExplodeSubText) // 不绘制线上文字
2026-09-28 15:28:50 +08:00
{
ads_polar(ptRet, dLayoutRotation + PI / 2, nText2Base, ptRet);
return ptRet;
}
2026-10-04 00:04:20 +08:00
if (IsUpText()) // m_sText1为单行文字
2026-09-28 15:28:50 +08:00
{
2026-10-04 00:04:20 +08:00
if (m_bSideText) // 注:本段代码实际上未使用
2026-09-28 15:28:50 +08:00
{
if (m_nTextBaseLen < 0.0)
ads_polar(ptRet, PI + dLayoutRotation, nText2Base, ptRet);
else
ads_polar(ptRet, dLayoutRotation, nText2Base, ptRet);
}
else
ads_polar(ptRet, dLayoutRotation + PI / 2, nText2Base, ptRet);
}
2026-10-04 00:04:20 +08:00
else // m_sText1为多行文字
2026-09-28 15:28:50 +08:00
{
AecXDbMText text;
text.setPropertiesFrom(this);
text.SetHeight(m_nTextHeight);
text.SetStyleId(m_idTextStyle);
text.SetText(m_sText1);
text.SetAlignment(AcGiDraw::kLeft);
double dPageWidth = GetPageWidth(FALSE);
2026-10-04 00:04:20 +08:00
((AecXDbMText &)text).SetLineSpace(nText2Base, FALSE); // 行间距
((AecXDbMText &)text).SetPageWidth(dPageWidth, FALSE); // 页宽
2026-09-28 15:28:50 +08:00
Vector3D vtExt = text.GetExtents();
ads_polar(ptRet, m_nLayoutRotation + PI / 2, nText2Base + vtExt.y, ptRet);
2026-10-04 00:04:20 +08:00
if (m_nTextAlign == kAtMiddle) // 居中对齐
2026-09-28 15:28:50 +08:00
ads_polar(ptRet, m_nLayoutRotation, -dPageWidth * 0.5, ptRet);
else if ((m_nTextBaseLen < 0.0 && m_nTextAlign == kAtStart) ||
(m_nTextBaseLen > 0.0 && m_nTextAlign == kAtEnd))
ads_polar(ptRet, m_nLayoutRotation, -dPageWidth, ptRet);
}
return ptRet;
}
ADSGePoint3d AecXDbSymbMultiLeader::GetText2Pt(BOOL bUseLayout) const
{
2026-10-04 00:04:20 +08:00
// sg add 090724,如果是坐标标注,忽略引线距离末端距离
2026-09-28 15:28:50 +08:00
double dDistRatio = GlobalFunc::DocGetMultiLeaderDistRatio();
if (!m_bSymbMultiLeader)
dDistRatio = 0;
double dDist = dDistRatio * m_nTextHeight * GetPScale(),
dSign = 1.0;
if (fabs(m_nTextBaseLen) > 1.0E-5)
dSign = m_nTextBaseLen / (fabs(m_nTextBaseLen));
dDist *= dSign;
2026-10-04 00:04:20 +08:00
// sg add 090724,调整坐标上下文字距离基线距离
2026-09-28 15:28:50 +08:00
double dLayoutRotation = m_nLayoutRotation;
if (!m_bSymbMultiLeader)
{
if (!bUseLayout)
dLayoutRotation = 0;
}
ADSGePoint3d ptEnd, ptTemp;
2026-10-04 00:04:20 +08:00
ads_polar(m_ptLeader, dLayoutRotation, GetTextBaseLen(FALSE), ptEnd); // 文字基线
if (m_nTextAlign == kAtMiddle) // 居中对齐
2026-09-28 15:28:50 +08:00
{
Midpoint(m_ptLeader, ptEnd, ptTemp);
}
2026-10-04 00:04:20 +08:00
else if (m_nTextAlign == kAtStart) // 起端对齐
2026-09-28 15:28:50 +08:00
ads_polar(m_ptLeader, dLayoutRotation, dDist, ptTemp);
2026-10-04 00:04:20 +08:00
else // 末端对齐
2026-09-28 15:28:50 +08:00
ads_polar(ptEnd, dLayoutRotation, -dDist, ptTemp);
ADSGePoint3d ptRet = ptTemp;
2026-10-04 00:04:20 +08:00
double nText2Base = GetText2BaseRatio(FALSE, TRUE); // 距基线距离
2026-09-28 15:28:50 +08:00
ads_polar(ptRet, dLayoutRotation - PI / 2, nText2Base, ptRet);
2026-10-04 00:04:20 +08:00
if (!m_sText2 && g_Option::instance().g_bExplodeSubText) // 不绘制线下文字
2026-09-28 15:28:50 +08:00
return ptRet;
2026-10-04 00:04:20 +08:00
if (!IsDownText()) // m_sText2为多行文字
2026-09-28 15:28:50 +08:00
{
double dPageWidth = GetPageWidth2(FALSE);
2026-10-04 00:04:20 +08:00
if (m_nTextAlign == kAtMiddle) // 居中对齐
2026-09-28 15:28:50 +08:00
ads_polar(ptRet, dLayoutRotation, -dPageWidth * 0.5, ptRet);
else if ((m_nTextBaseLen < 0.0 && m_nTextAlign == kAtStart) ||
(m_nTextBaseLen > 0.0 && m_nTextAlign == kAtEnd))
ads_polar(ptRet, dLayoutRotation, -dPageWidth, ptRet);
}
return ptRet;
}
2026-10-04 00:04:20 +08:00
// sg add 090720,8.0正式版增加的临时变量,不保存,处理坐标标注的绘制问题
2026-09-28 15:28:50 +08:00
void AecXDbSymbMultiLeader::SetSymbMultiLeader(BOOL bSymbMultiLeader)
{
AssertWriteEnabled();
m_bSymbMultiLeader = bSymbMultiLeader;
}
2026-10-04 00:04:20 +08:00
// add by lxb on 111229,引线是否平行接口
2026-09-28 15:28:50 +08:00
void AecXDbSymbMultiLeader::SetLeaderParalle(BOOL bParallel)
{
AssertWriteEnabled();
if (bParallel)
{
m_nLeaderFlag |= SMLF_PARALLEL;
}
else
{
m_nLeaderFlag &= ~SMLF_PARALLEL;
}
}
BOOL AecXDbSymbMultiLeader::IsLeaderParall() const
{
return((m_nLeaderFlag & SMLF_PARALLEL) != 0);
}
2026-10-04 00:04:20 +08:00
// 获得引线平行时的平行方向点
2026-09-28 15:28:50 +08:00
void AecXDbSymbMultiLeader::SetLeaderDirection(ADSGePoint3d &pt)
{
AssertWriteEnabled();
m_ptLeaderDirection = pt;
}
ADSGePoint3d AecXDbSymbMultiLeader::GetLeaderDirection() const
{
return m_ptLeaderDirection;
}