Files
envi-code/SourceCode/Code2026/Dimension/AecDbSymbComposing.cpp
T
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

2562 lines
67 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "stdafx.h"
#include "PushProperty.h"
#include "AecDbSymbComposing.h"
#include "AecDbMText.h"
#include "DualPtrList.h"
#include "AecDbText.h"
#include "EntityFields.h"
const Adesk::UInt8 AecXDbSymbComposing::g_nVersion = 3;//axc mod 2015-07-20 增加一个箭头样式
ACRX_DXF_DEFINE_MEMBERS(AecXDbSymbComposing, AecXDbSymbWithText, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
1, AEC_ZUOFABIAOZHU, "AEC_ZUOFABIAOZHU|缺乏上华解释器, 请下载上华软件|网址: www.shanghuasoft.com");
AecXDbSymbComposing::AecXDbSymbComposing()
{
m_nTextHeight = 3.5;
m_nTextBaseLen = 60; // add by whl on 060210
m_bSideText = TRUE;
// sg add 080904,sg modify 081023
m_dLineSpace = 0.14; // 0.5*DocGetText2Base/m_nTextHeight
m_dParagraphSpace = 0.57; // 2*DocGetText2Base/m_nTextHeight
m_dDist2Line = 0.29; // DocGetText2Base/m_nTextHeight
m_dPageWidth = 0; // 线端、单行文字
m_dText2BaseRatio = -1000; // sg add 081023,使用DocGetText2BaseRatio
m_nAlignment = AcGiDraw::kMiddleLeft;
m_arrowStyle = AecXDbSymbComposing::eDot;
// add by xly on 101228
m_bIsStretch = false;
}
AecXDbSymbComposing::~AecXDbSymbComposing()
{
}
AecXDbSymbComposing::TArrowStyle AecXDbSymbComposing::GetArrowStyle() const
{
return m_arrowStyle;
}
void AecXDbSymbComposing::SetArrowStyle(TArrowStyle arrowStyle)
{
AssertWriteEnabled();
m_arrowStyle = arrowStyle;
}
BOOL AecXDbSymbComposing::IsValid() const
{
//bRet = AecXDbSymbWithText::IsValid();
//if (!bRet)
// return bRet;
BOOL bRet = (!!m_sText);
return bRet;
}
//Acad::ErrorStatus
//AecXDbSymbComposing::subGetClassID(CLSID* pClsid) const
//{
// *pClsid = CLSID_ComSymbComposing;
// return Acad::eOk;
//}
// 提供对格式刷的支持
void AecXDbSymbComposing::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
{
AssertWriteEnabled();
AecXDbSymbWithText::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
AecXDbSymbComposing *pSrc = AecXDbSymbComposing::cast(pSrcEntity);
if (pSrc != NULL)
{
m_arrowStyle = pSrc->m_arrowStyle;
m_bSideText = pSrc->m_bSideText; // 文字在基线边上, 还是在基线上方
m_nTextBaseLen = pSrc->m_nTextBaseLen; // 左右由正负控制
// sg add 080904
m_dLineSpace = pSrc->m_dLineSpace; // 行距系数
m_dParagraphSpace = pSrc->m_dParagraphSpace; // 段距系数
m_dPageWidth = pSrc->m_dPageWidth; // 页宽
m_dDist2Line = pSrc->m_dDist2Line; // 文字距线距离
// sg add 081023
m_dText2BaseRatio = pSrc->m_dText2BaseRatio; // 文字距基线系数
m_nAlignment = pSrc->m_nAlignment; // 对齐方式
}
}
// 从DWG读入数据:
Acad::ErrorStatus AecXDbSymbComposing::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;
}
pFiler->readItem(&m_bSideText);
pFiler->readItem(&m_nTextBaseLen);
pFiler->readItem((AcGePoint2d *)&m_ptStart);
pFiler->readItem((AcGePoint2d *)&m_ptTurn);
GlobalFunc::ReadString(pFiler, m_sText);
if (nVer > 1) // sg modify 080904,8.0中的nVer为2,以前版本为1
{
pFiler->readItem(&m_dLineSpace);
pFiler->readItem(&m_dParagraphSpace);
pFiler->readItem(&m_dPageWidth);
pFiler->readItem(&m_dDist2Line);
pFiler->readItem(&m_dText2BaseRatio); // sg add 081024
Adesk::UInt8 nAlign;
pFiler->readItem(&nAlign);
m_nAlignment = (AcGiDraw::TextAlignment)nAlign;
}
else // 8.0以前版本,无以下距离变量,为保持绘制一致,修改默认值
{
//m_dLineSpace = 0.14; // 0.5*DocGetText2Base/m_nTextHeight
//m_dParagraphSpace = 0.57; // 2*DocGetText2Base/m_nTextHeight
//m_dDist2Line = 0.29; // DocGetText2Base/m_nTextHeight
//m_dPageWidth = 0; // 线端、单行文字
//m_dText2BaseRatio = -1000; // sg add 081023,使用DocGetText2BaseRatio
//m_nAlignment = AcGiDraw::kMiddleLeft;
//m_dLineSpace = 0.5 * GlobalFunc::DocGetText2Base() / m_nTextHeight; // 系数,0.5倍距基线
//m_dParagraphSpace = 4 * m_dLineSpace; // 2倍距基线
//double dBaseLen = m_nTextBaseLen;
//if (m_bSideText) // 文字在线端
//{
// m_dPageWidth = 0.0;
// m_dDist2Line = 2 * m_dLineSpace; // sg modify 081107,1倍距基线
// if (dBaseLen < -1.0E-5)
// {
// m_dDist2Line *= -1;
// }
//}
//else // 文字在线上
//{
// m_dDist2Line = m_dParagraphSpace; // 2倍距基线
// if (dBaseLen < -1.0E-5)
// {
// m_dDist2Line *= -1;
// }
// m_dPageWidth = dBaseLen - 2 * m_dDist2Line * m_nTextHeight;
//}
//SetAlignBySymbol();
}
if (nVer >= g_nVersion)
{
Adesk::UInt8 nFlag;
pFiler->readItem(&nFlag);
m_arrowStyle = (AecXDbSymbComposing::TArrowStyle)nFlag;
}
return pFiler->filerStatus();
}
Acad::ErrorStatus AecXDbSymbComposing::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = AecXDbSymbWithText::dwgOutFields(pFiler);
if (es != Acad::eOk)
return es;
pFiler->writeItem(g_nVersion);
pFiler->writeItem(m_bSideText);
pFiler->writeItem(m_nTextBaseLen);
pFiler->writeItem((const AcGePoint2d &)m_ptStart);
pFiler->writeItem((const AcGePoint2d &)m_ptTurn);
pFiler->writeString(m_sText);
pFiler->writeItem(m_dLineSpace);
pFiler->writeItem(m_dParagraphSpace);
pFiler->writeItem(m_dPageWidth);
pFiler->writeItem(m_dDist2Line);
pFiler->writeItem(m_dText2BaseRatio); // sg add 081024
pFiler->writeItem((Adesk::UInt8)m_nAlignment);
pFiler->writeItem((Adesk::UInt8)m_arrowStyle);
return pFiler->filerStatus();
}
Acad::ErrorStatus AecXDbSymbComposing::dxfInFields(AcDbDxfFiler* pFiler)
{
return AecXDbSymbWithText::dxfInFields(pFiler);
}
Acad::ErrorStatus AecXDbSymbComposing::dxfOutFields(AcDbDxfFiler* pFiler) const
{
return AecXDbSymbWithText::dxfOutFields(pFiler);
}
// -----------------------------------------------------------------------
// Active when being rotated, scaled, moved, etc.
// Scale is disabled here
Acad::ErrorStatus
AecXDbSymbComposing::subTransformBy(const AcGeMatrix3d& xform)
{
AssertWriteEnabled();
AecXDbSymbWithText::subTransformBy(xform);
ads_matrix mat;
GlobalFunc::AsAdsMatrix(xform, mat);
ADSGePoint3d ptSpare = m_ptTurn; // sg add 080912,解决镜像问题
m_ptStart.TransformBy(mat);
m_ptTurn.TransformBy(mat);
// sg add 081008,镜像时需要调整m_nTextBaseLen、m_dPageWidth、m_dDist2Line
if (GlobalFunc::IsMirrorMatrix(xform))
{
ADSGePoint3d ptBaseLen; // 变化之前线端位置
ads_polar(ptSpare, m_nLayoutRotation, GetTextBaseLen(FALSE), ptBaseLen);
ptBaseLen.TransformBy(mat); // 将夹点也进行镜像变化
// 重新设置正负,算法参考自tch_anotate工程中的TComposingEdJig::update函数
ads_matrix matRot;
m_ptStart.GetRotationMatrix(-m_nLayoutRotation, matRot);
ADSGePoint3d ptTurn = m_ptTurn.TransformAs(matRot),
ptLine = ptBaseLen.TransformAs(matRot);
double dTextBaseLen = fabs(GetTextBaseLen()),
dDist2Line = fabs(GetDist2Line(TRUE, FALSE)), // sg modify 081031,系数
dPageWidth = fabs(m_dPageWidth); // 考虑单行文字
if (ptLine.x < ptTurn.x - 1.0E-3)
{
dTextBaseLen *= -1;
dDist2Line *= -1;
dPageWidth *= -1;
}
SetTextBaseLen(dTextBaseLen);
SetDist2Line(dDist2Line);
SetPageWidth(dPageWidth);
SetAlignBySymbol(); // sg add 081104,同步修改单行文字的对齐方式
}
if (xform.isUniScaledOrtho()) // sg add 090317,支持scale操作
{
m_nTextBaseLen *= fabs(xform.scale()); // 只改大小,不考虑符号
m_dDist2Line *= fabs(xform.scale());
m_dPageWidth *= fabs(xform.scale());
}
// add by xly on 100920
// 计算每一个夹点的位置
if (HasOtherPoint())
{
AcGePoint3dArray aryPts, aryNewPts;
GetAllDots(aryPts);
AcGePoint3d ptTemp;
int nLength = aryPts.length();
for (int n = 0; n < nLength; n++)
{
ptTemp = aryPts[n];
ptTemp.transformBy(xform);
aryNewPts.append(ptTemp);
}
SetAllDots(aryNewPts);
}
return Acad::eOk;
}
// Overriden functions for edit
Acad::ErrorStatus AecXDbSymbComposing::subGetGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
assertReadEnabled();
// sg modify 090514,新增加的“文字位置点、文字页宽点”夹点,只提供夹点操作,不提供拉伸操作
// return getStretchPoints(gripPoints);
Acad::ErrorStatus es = subGetStretchPoints(gripPoints);
// add by xly on 101227 移除拉伸操作中的其他点
int nLen = gripPoints.length();
for (int i = 3; i < nLen; i++)
{
gripPoints.removeAt(i);
}
// sg add 081027,增加“文字位置点、文字页宽点”夹点
ADSGePoint3d ptTemp = GetEndPoint();
ads_polar(ptTemp, m_nLayoutRotation, GetDist2Line(FALSE, TRUE), ptTemp);
if (m_bSideText) // sg add 081104,线段文字,还要增加一个线长
{
ads_polar(ptTemp, m_nLayoutRotation, GetTextBaseLen(FALSE), ptTemp);
}
gripPoints.append(ptTemp); // 文字位置点
ads_polar(ptTemp, m_nLayoutRotation, GetPageWidth(FALSE), ptTemp);
gripPoints.append(ptTemp); // 文字页宽点
// add by xly on 100919 标注点的夹点添加
if (HasOtherPoint())
{
AcGePoint3dArray arPts;
GetAllDots(arPts);
int nLen = arPts.length();
for (int i = 0; i < nLen; i++)
{
gripPoints.append(arPts[i]);
}
}
return es;
}
Acad::ErrorStatus AecXDbSymbComposing::subGetGripPoints(AcDbGripDataPtrArray & grips, const double curViewUnitSize, const int gripSize, const AcGeVector3d & curViewDir, const int bitflags) const
{
return Acad::eNotImplementedYet;
}
// stretch points is diffrent from grep points, with no midpoint included
Acad::ErrorStatus
AecXDbSymbComposing::subGetStretchPoints(AcGePoint3dArray & stretchPoints) const
{
assertReadEnabled();
stretchPoints.append(m_ptStart);
stretchPoints.append(m_ptTurn);
ADSGePoint3d ptTemp;
ads_polar(m_ptTurn, m_nLayoutRotation, GetTextBaseLen(FALSE), ptTemp);
stretchPoints.append(ptTemp); // 拉伸引线点
// add by xly on 101227 标注点的夹点添加
if (HasOtherPoint())
{
AcGePoint3dArray arPts;
GetAllDots(arPts);
int nLen = arPts.length();
for (int i = 0; i < nLen; i++)
{
stretchPoints.append(arPts[i]);
}
}
return Acad::eOk;
}
// add by xly on 110308 做法标注夹点操作和拉伸操作的调整原则
// 做法标注标注点的夹点操作可以归纳成下面两句话:
// 拖动引线端头夹点时,标注点保持跟转折点距离不变
// 拖动转折点的时候,标注点保持跟引线端点的距离不变
// 功能: 夹点操作
Acad::ErrorStatus AecXDbSymbComposing::subMoveGripPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
AssertWriteEnabled();
ADSGePoint3d vtOffset(offset[0], offset[1]);
// dd by xly on 110309 保存拉伸时标注点的下标
AcDbIntArray aryIndex;
for (int i = 0; i < indices.length(); i++)
{
int idx = indices[i];
// 判断夹点操作时否是拉伸操作
if (m_bIsStretch)
{
// 跳过文字夹点的操作
if (idx > 2)
{
idx = idx + 2;
aryIndex.append(idx);
}
}
}
// 记录对象是否是整体拉伸
bool bIsMove(false);
if (indices.length() - aryIndex.length() > 1)
{
bIsMove = true;
}
double dMin(0.0),
dMax(0.0);
int nPosMax(-1),
nPosMin(-1);
AcGeIntArray aryMin, aryMax;
bool bIsChangeStart(false);
if (!bIsMove)
{
// add by xly on 110309 处理夹点的超越关系
AcGePoint3dArray arPtsAll;
GetAllDots(arPtsAll);
if (aryIndex.length() > 1)
{
// 记录拉伸标注点的边界点的位置
int nTemp = aryIndex[0] - 5;
if (nTemp < 0)
{
return Acad::eOk;
}
dMax = dMin = arPtsAll[nTemp].distanceTo(m_ptStart);
nPosMin = nPosMax = nTemp;
for (int n = 1; n < aryIndex.length(); n++)
{
nTemp = aryIndex[n] - 5;
double dTemp = arPtsAll[nTemp].distanceTo(m_ptStart);
if (dTemp > dMax)
{
dMax = dTemp;
nPosMax = nTemp;
}
else if (dTemp < dMin)
{
dMin = dTemp;
nPosMin = nTemp;
}
}
}
else if (aryIndex.length() == 1)// 只拉伸一个标注点
{
nPosMin = nPosMax = aryIndex[0] - 5;
}
// 以拉伸的边界点开始分界,分为距m_ptstart最小距离点和对大距离点
for (int n = 0; n < arPtsAll.length(); n++)
{
if (FindAryData(aryIndex, n + 5) < 0)
{
ADSGePoint3d ptTemp = arPtsAll[n];
double dLenMax = arPtsAll[nPosMax].distanceTo(m_ptStart);
double dLenMin = arPtsAll[nPosMin].distanceTo(m_ptStart);
double dLen = ptTemp.Distance(m_ptStart);
if (dLen > dLenMax)
{
aryMax.append(n);
}
else if (dLen < dLenMin)
{
aryMin.append(n);
}
}
}
}
// 夹点操作
for (i = 0; i < indices.length(); i++)
{
int idx = indices[i];
// 判断夹点操作时否是拉伸操作
if (m_bIsStretch)
{
// 跳过文字夹点的操作
if (idx > 2)
{
idx = idx + 2;
}
}
if (idx == 0) // 移动标注点
{
// modify by xly on 100919 其他标注点联动第一点
// m_ptStart += vtOffset;
// modify by xly on 110302 拉伸时不做添加标注点的操作
if (HasOtherPoint() && GetCtrlToggle() && !m_bIsStretch) // 加标注点
{
AcGePoint3d ptTemp = m_ptStart,
ptRet;
ptTemp += vtOffset;
// 计算投影点,夹点方向沿着直线方向
AcDbLine line(m_ptStart, m_ptTurn);
line.getClosestPointTo(ptTemp, ptRet, Adesk::kTrue);
// 增加点在直线的延长线上
if (ptRet.distanceTo(m_ptTurn) > m_ptStart.Distance2d(m_ptTurn))
{
ptTemp = m_ptStart;
m_ptStart = ptRet;
ptRet = ptTemp;
}
AddDotLoc(ptRet);
}
else // 移动、删除标注点或者是拉伸
{
m_ptStart += vtOffset;
// 是整体拉伸
if (bIsMove)
{
MoveOtherGrip(m_ptTurn);
}
else if (!m_bIsStretch)
{
MoveOtherGrip(m_ptTurn, true);
}
else
{
if (aryIndex.length() < 1)
{
MoveOtherGrip(m_ptTurn, true);
}
else
{
MoveOtherPoint(aryIndex, true);
}
}
}
}
else if (idx == 1) // 移动转折点
{
ADSGePoint3d ptTemp = m_ptTurn;
m_ptTurn += vtOffset;
// add by xly on 110121 增加是否是拉伸判断,拉伸操作时其他点不联动
// 是整体拉伸
if (bIsMove)
{
MoveOtherGrip(ptTemp);
}
else if (!m_bIsStretch)// 夹点操作
{
// add by xly on 100920 其他标注点联动拐点
MoveOtherGrip(m_ptStart, FALSE);
}
else // 拉伸操作
{
if (aryIndex.length() < 1)
{
MoveOtherGrip(m_ptStart, FALSE);
}
else
{
MoveOtherPoint(aryIndex, false);
}
}
}
else if (idx == 2) // 拉伸文字线
{
// Vector3D vt(1.0, 0.0); // sg modify 080910,修改任意转角下的拖拽
Vector3D vt(cos(m_nLayoutRotation), sin(m_nLayoutRotation));
using namespace GlobalFunc;
double nVal = (vtOffset & vt);
double dOldVal = m_nTextBaseLen; // sg add 080910,对应调整页宽及距线距离
m_nTextBaseLen += nVal / GetPScale();
if (dOldVal * m_nTextBaseLen < 1.0E-5) // 方向改变,要变号
{
SetAlignBySymbol(); // sg add 081104,同步修改单行文字的对齐方式
m_dDist2Line = -m_dDist2Line;
m_dPageWidth = -m_dPageWidth;
if (!m_bSideText) // 线上文字,页宽重新计算,sg modify 081105
{
nVal = fabs(m_nTextBaseLen) - fabs(dOldVal) + fabs(m_dPageWidth);
m_dPageWidth = nVal * GetDistSymbol();
}
}
else if (!m_bSideText) // 方向未改变,线上文字,sg add 081028
{
double dMinLen = m_dPageWidth + m_dDist2Line * m_nTextHeight; // 最小长度
if (fabs(m_nTextBaseLen) - fabs(dMinLen) < 1.0E-5)
{
m_dPageWidth += nVal / GetPScale(); // 同量修改页宽
}
}
}
else if (idx == 3) // 改变文字位置点,sg add 081105
{
Vector3D vt(cos(m_nLayoutRotation), sin(m_nLayoutRotation));
using namespace GlobalFunc;
double dVal = (vtOffset & vt), // 实际距离值
dRet = m_dDist2Line + dVal / GetPScale() / m_nTextHeight; // 系数
if (m_nTextBaseLen * dRet > -1.0E-5) // 符号相同
{
m_dDist2Line = dRet;
if (!m_bSideText) // 线上文字
{
// 以最大长度m_nTextBaseLen为界限
if (fabs(m_nTextBaseLen) - fabs(dRet * m_nTextHeight) > -1.0E-5)
{
m_dPageWidth -= dVal / GetPScale(); // 同量缩小页宽
}
else
{
m_nTextBaseLen += dVal / GetPScale(); // 同量修改线长
}
}
}
}
// modify by xly on 100919 添加其他标注点的夹点操作
//else // 改变文字宽度点,sg add 080909,sg add 081105
else if (idx == 4)
{
Vector3D vt(cos(m_nLayoutRotation), sin(m_nLayoutRotation));
using namespace GlobalFunc;
double dVal = (vtOffset & vt),
dRet = GetPageWidth(TRUE); // 兼容单行文字
dRet += dVal / GetPScale();
if (m_nTextBaseLen * dRet > -1.0E-5) // 符号相同
{
m_dPageWidth = dRet;
if (!m_bSideText) // 线上文字
{
double dMax = m_nTextBaseLen - m_dDist2Line * m_nTextHeight; // 最大长度
if (fabs(dRet) - fabs(dMax) > -1.0E-5)
{
m_nTextBaseLen += dVal / GetPScale(); // 同量修改线长
}
}
}
}
else // add by xly on 100919 添加其他标注点的夹点操作
{
if ((idx - 5 < 0) || !HasOtherPoint())
{
return Acad::eOk;
}
AcGePoint3dArray arPts;
GetAllDots(arPts);
AcGePoint3d ptTemp = arPts[idx - 5],
ptRet;
ptTemp += vtOffset; // 拖动到的位置
// 计算投影点,夹点方向沿着直线方向
AcDbLine line(m_ptStart, m_ptTurn);
line.getClosestPointTo(ptTemp, ptRet, Adesk::kTrue);
// 增加点、移动点时投影在直线的延长线上
bool bIsExtend = false;// add by xly on 110121 增加拉出线外的标记
if (ptRet.distanceTo(m_ptTurn) > m_ptStart.Distance2d(m_ptTurn))
{
AcGePoint3d pt;
pt = m_ptStart;
m_ptStart = ptRet;
ptRet = pt;
bIsExtend = true;
bIsChangeStart = true;
}
// 删除重合点,遍历每一个夹点的位置
bool bIsDouble = false;
for (int n = 0; n < arPts.length(); n++)
{
bIsDouble = false;
if (idx - 5 == n)
{
continue;
}
if (ptTemp == arPts[n] || (ptTemp == m_ptStart && !bIsExtend))
{
// 移动、删除标注点时,删除重合的拖动点
if (!GetCtrlToggle())
{
// 有重合删除重合点
DelDotLoc(idx - 5);
}
bIsDouble = true;
break;
}
}
if (m_bIsStretch) // 移动、删除标注点
{
SetDotLoc(idx - 5, ptRet);
continue;
}
if (!GetCtrlToggle()) // 移动、删除标注点
{
// modify by xly on 110303 调整位置
//// 删除重合点,遍历每一个夹点的位置
//bool bIsDouble = false;
//for (int n=0; n<arPts.length(); n++)
//{
// bIsDouble = false;
// if (idx-5 == n)
// {
// continue;
// }
// if (ptTemp == arPts[n] || (ptTemp == m_ptStart && !bIsExtend))
// {
// // 有重合删除重合点
// DelDotLoc(idx-5);
// bIsDouble = true;
// break;
// }
//}
if (!bIsDouble)
{
// 没有重合更新夹点
SetDotLoc(idx - 5, ptRet);
}
}
else if (!m_bIsStretch)// 加标注点
{
// modify by xly on 110303 增加重合点的 判断
//AddDotLoc(ptRet);
if (!bIsDouble)
{
AddDotLoc(ptRet);
}
}
}
}
// add by xly on 110310 增加拖动标注点的联动情况
if (aryIndex.length() > 0 && !bIsMove)
{
AcGePoint3dArray aryNewPts;
GetAllDots(aryNewPts);
int j = 0;
// 排序小顺序点,有不能放在线线上的点删除
SortAyry(aryMin);
for (j = aryMin.length() - 1; j > -1; j--)
{
int nTemp = aryMin[j];
if (aryNewPts[nTemp].distanceTo(m_ptStart) > aryNewPts[nPosMin].distanceTo(m_ptStart))
{
DelDotLoc(nTemp);
}
}
// 排序大顺序点,有不能放在线线上的点删除
SortAyry(aryMax);
for (j = aryMax.length() - 1; j > -1; j--)
{
int nTemp = aryMax[j];
if (aryNewPts[nTemp].distanceTo(m_ptTurn) > aryNewPts[nPosMax].distanceTo(m_ptTurn))
{
DelDotLoc(nTemp);
}
}
// 判断拉伸点与转折点的关系,如果是多个拉伸点,不合法时删除距转折点最近的点
if (aryIndex.length() > 1)
{
double dLenTurn = (aryNewPts[nPosMax].distanceTo(m_ptTurn) + aryNewPts[nPosMin].distanceTo(m_ptTurn)) - (dMax - dMin);
if (fabs(dLenTurn) < g_Option::instance()._DIST_SNAP)
{
DelDotLoc(nPosMax);
}
}
else if (aryIndex.length() == 1)//如果是1个拉伸点,不合法时删除点
{
if (aryNewPts[nPosMax].distanceTo(m_ptTurn) + aryNewPts[nPosMax].distanceTo(m_ptStart) > m_ptStart.Distance(m_ptTurn))
{
DelDotLoc(nPosMax);
}
}
// 拉伸到端点以外交换起始点
if (bIsChangeStart)
{
DelDotLoc(nPosMin);
}
}
m_bIsStretch = false;
return Acad::eOk;
}
// 功能: 夹点操作
Acad::ErrorStatus AecXDbSymbComposing::subMoveStretchPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
AssertWriteEnabled();
// sg add 090219,需求平台问题1648,整体拉伸时,变长问题
DualPtrList<int> indices1;
for (long i = 0; i < indices.length(); i++)
indices1.FindOrAddTail(indices[i]);
indices1.Arrange();
AcDbIntArray indices2;
if (indices1.Find(0) > -1 && indices1.Find(1) > -1) // 可认为是整体strech
{
indices2.append(0); // 整体拉伸时,忽略长度,只改变点位置
indices2.append(1);
}
else if (indices1.Find(0) < 0 && indices1.Find(1) > -1 && indices1.Find(2) > -1)
{
indices2.append(1); // sg add 090514,框选上半部分,只改变位置,不改长度
}
else
{
for (i = 0; i < indices1.GetLength(); i++)
indices2.append(indices1[i]);
}
// add by xly on 101227 其他标注点支持拉伸操作
m_bIsStretch = true;
// return moveGripPointsAt(indices, offset); // sg modify 090219
return subMoveGripPointsAt(indices2, offset);
}
// 取得夹点说明
Acad::ErrorStatus AecXDbSymbComposing::GetGripText(int idx, CString &cs) const
{
Acad::ErrorStatus es = Acad::eOk;
// modify by xly on 100919 更改夹点信息
if (idx == 0)
{
// cs = _T("移动标注点");
if (HasOtherPoint()) // 有其他标注点
{
// sg modify 101221,默认为移动、删除引注点
cs = GetCtrlToggle() ? _T("加标注点(Ctrl-移动、删除标注点)") : _T("移动、删除标注点(Ctrl-加标注点)");
}
else // 没有其他标注点
{
cs = _T("移动标注点");
}
}
else if (idx == 1)
cs = _T("移动转折点");
else if (idx == 2)
cs = _T("拉伸文字线");
else if (idx == 3)
cs = _T("改变文字位置点");
// modify by xly on 100919 添加其他点的夹点信息
// else
else if (idx == 4)
{
cs = _T("改变文字宽度点");
}
else
{
// sg modify 101221,默认为移动、删除引注点
cs = GetCtrlToggle() ? _T("加标注点(Ctrl-移动、删除标注点)") : _T("移动、删除标注点(Ctrl-加标注点)");
}
return es;
}
// sg add 080910
// sg modify 091109,整体进行了调整,解决导T6后,文字图层不正确的情况
//Acad::ErrorStatus AecXDbSymbComposing::DownGradeSave(int nDrawMode,
// AcDbVoidPtrArray &entSet, BOOL *bErase)
//{
// Acad::ErrorStatus es = Acad::eOk;
// if (g_nSaveTArchVer < 7) // 7.0开始才有圆圈文字
// {
// BOOL bHasCircle = FALSE; // 是否存在圆圈文字
// long num = GetSubTextNum();
// for (long i = 0; i < num; i++)
// {
// SubText* pSubText = GetSubText(i);
// if (pSubText != NULL)
// {
// CString sText = pSubText->GetText();
// delete pSubText;
// if (sText.Find(_T("^C")) != -1)
// {
// // 有圆圈文字,此时还要求完全炸开(参考AecXDbSymbWithText::DownGradeSave())
// bHasCircle = TRUE;
// break;
// }
// }
// }
//
// if (bHasCircle)
// {
// XPushMemVar<BOOL> vTemp(XExplodeStream::m_bFullExplode, TRUE); // 完全分解
// // sg add 091224,保证炸开的图层正确,临时设置为全部炸开
// XPushMemVar<BOOL> vTemp2(XExplodeStream::m_bExportTch4, TRUE);
// XExplodeStream dc(entSet);
// if (!OnExplodeOrDraw(dc))
// return Acad::eOk;
//
// dc.SetPropertiesFrom(this);
// if (nDrawMode == DRAW_2D)
// es = ExplodeOrDraw2d(dc);
// else
// es = ExplodeOrDraw3d(dc);
//
// if (bErase)
// *bErase = TRUE;
// return es;
// }
// }
//
// if (g_nSaveTArchVer < 8 && g_nSaveTArchVer>3) // 导出为T8以下格式,需要判断是否炸开
// {
// // 线端多行文字,8.0新增,应该炸开
// BOOL bExplode1 = m_bSideText && (fabs(m_dPageWidth) > 1.0E-5);
//
// ads_matrix matRot;
// m_ptStart.GetRotationMatrix(-m_nLayoutRotation, matRot);
// ADSGePoint3d ptTurn = m_ptTurn.TransformAs(matRot),
// ptStart = m_ptStart.TransformAs(matRot);
// // 线上文字,引线向下,8.0以前有BUG,应该炸开
// BOOL bExplode2 = !m_bSideText && (ptTurn.y < ptStart.y + 1.0E-3);
//
// // 对齐方式与8.0以前版本不同,8.5起有用,应该炸开
// AcGiDraw::TextAlignment align = XExplodeDraw::kLeft;
// if (IsText()) // 单行文字
// {
// double dTextBaseLen = GetTextBaseLen(TRUE);
// if (dTextBaseLen > -1.0E-5) // 文字在引线右侧
// {
// align = XExplodeDraw::kMiddleLeft;
// }
// else // 文字在引线左侧
// {
// align = XExplodeDraw::kMiddleRight;
// }
// }
// BOOL bExplode3 = align != m_nAlignment;
//
// if (bExplode1 || bExplode2 || bExplode3) // 需要炸开
// {
// XExplodeStream dc(entSet);
// if (!OnExplodeOrDraw(dc)) // sg add 090303,解决导出后,无遮挡关系的BUG
// return es;
//
// dc.SetPropertiesFrom(this);
// if (nDrawMode == DRAW_2D)
// es = ExplodeOrDraw2d(dc);
// else
// es = ExplodeOrDraw3d(dc);
//
// // sg add 090728,导出T7后,图层和颜色不正确的情况
// if (bExplode2 || bExplode1)
// {
// for (long i = 0; i < entSet.length(); i++)
// {
// AcDbEntity *pEnt = (AcDbEntity*)entSet[i];
// if (pEnt != NULL && pEnt->isKindOf(AecXDbMText::desc())) // 多行文字
// {
// AecXDbMText *pMText = AecXDbMText::cast(pEnt);
//
// // sg add 120313,分解出来的文字的图层和颜色要随“高级选项”中的设置来处理
// // if (!!m_idTextLayer)
// if (g_nSymbTextT3Layer == 1 && !!m_idTextLayer)
// {
// pMText->setLayer(m_idTextLayer);
// pMText->setColorIndex(colorIndex());
// }
// else
// pMText->setColorIndex(m_colorText);
// }
// }
// }
//
// if (bErase)
// *bErase = TRUE;
// return es; // this类的处理完成
// }
// else// add by xly on 110412 增加炸开,导出低版本时支持做法标注对象
// {
// if (HasOtherPoint()) // 需要炸开
// {
// AecXDbSymbComposing *pComposing = NULL; // sg modify 090325,防止导出T7崩溃
// {
// XPushMemVar<int> vTemp(g_nSaveTArchVer, _TCH_VERSION);
// pComposing = (AecXDbSymbComposing*)clone();
// }
// entSet.append(pComposing);
// AcDbObjectId idLayer = pComposing->layerId();
//
// AcGePoint3dArray arPts;
// GetAllDots(arPts);
//
// // i=-1时,为起始点添加圆点
// int nLength = arPts.length();
// GeLine leaderLine(m_ptStart, m_ptTurn);
// for (int i = -1; i < nLength; i++)
// {
// // 设置新的起点
// if (i > -1)
// {
// leaderLine.SetStartPoint(arPts[i]);
// }
//
// // 绘制圆点
// ads_matrix mat;
// leaderLine.StartPoint().GetRotationMatrix(m_nLayoutRotation, mat);
//
// // 获得圆点的大小
// double nW = GetCirPointSize() * GetPScale() / 4;
// ADSGePoint3d pt1, pt2;
// ads_polar(leaderLine.StartPoint(), leaderLine.Direction() + PI, nW, pt1);
// ads_polar(leaderLine.StartPoint(), leaderLine.Direction(), nW, pt2);
//
// AcDbPolyline *pline = new AcDbPolyline;
// pline->addVertexAt(0, pt1, 1.0);
// pline->addVertexAt(1, pt2, 1.0);
//
// pline->setConstantWidth(nW * 2);
// pline->setClosed(Adesk::kTrue);
// pline->setLayer(idLayer);
// pline->transformBy(AsAcGeMatrix3d(mat));
// entSet.append(pline);
// }
// if (bErase)
// {
// *bErase = TRUE;
// }
// return Acad::eOk;
// }
// }
// }
//
// // 其它情况交由基类去处理
// return AecXDbSymbWithText::DownGradeSave(nDrawMode, entSet, bErase);
//}
Acad::ErrorStatus
AecXDbSymbComposing::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;
TCStringList lstTexts;
GetTexts(lstTexts); // 拆分字符串
// modify by xly on 100919 定义引线对象,方便下面使用
//dc << GeLine(m_ptStart, m_ptTurn); // 引线
GeLine leaderLine(m_ptStart, m_ptTurn);
//dc << leaderLine;
DrawLine(dc, m_ptStart, m_ptTurn);
// double nLineSpace = (DocGetText2Base()*2+m_nTextHeight)*GetPScale();
double dParagraphSpace = GetParagraphSpace(FALSE, TRUE), // 段距,sg modify 081027
nLineSpace = dParagraphSpace + m_nTextHeight * GetPScale(); // sg modify 080911
ads_matrix matRot;
m_ptStart.GetRotationMatrix(-m_nLayoutRotation, matRot);
ADSGePoint3d ptTurn = m_ptTurn.TransformAs(matRot);
ADSGePoint3d ptStart = m_ptStart.TransformAs(matRot);
// if (ptTurn.y > ptStart.y + 1.0E-3)
BOOL bReverse = ptTurn.y > ptStart.y + 1.0E-3; // sg modify 080911
if (bReverse) // 颠倒文字顺序,nDist2Turn为正数
{
lstTexts.Reverse();
}
else // 按上下分正负,nDist2Turn为负数
{
nLineSpace = -nLineSpace; // 仅用于“单行文字”
}
// double nDist2End = (lstTexts.Length()-1)*nLineSpace;
double nTextBaseLen = GetTextBaseLen(FALSE); // 文字线长
// double nSpacer = DocGetText2Base()*GetPScale(); // modified by whl on 070629
// double nSpacer = DocGetText2Base()*GetPScale()*0.5;
double nSpacer = GetText2BaseRatio(FALSE, TRUE) * 0.5; // 文字距基线距离,sg modify 081027
double dLineSpace = GetLineSpace(FALSE, TRUE), // 行距,sg add 080911,sg modify 081027
dDist2Line = GetDist2Line(FALSE, TRUE), // 距线距离
dPageWidth = GetPageWidth(FALSE); // 页宽
double nDist2Turn = 0.0; // 距离m_ptTurn点的距离
int nLength = lstTexts.Length();
for (int i = 0; i < nLength; i++)
{
ADSGePoint3d ptTextBeg, ptTextEnd;
ptTextBeg = m_ptTurn;
ads_polar(ADSGePoint3d(ptTextBeg), m_nLayoutRotation + PI / 2, nDist2Turn, ptTextBeg);
ptTextEnd = ptTextBeg;
ads_polar(ADSGePoint3d(ptTextEnd), m_nLayoutRotation, nTextBaseLen, ptTextEnd);
if (i == nLength - 1)
{
ADSGePoint3d ptEnd;
ads_polar(m_ptTurn, m_nLayoutRotation + PI / 2.0, nDist2Turn, ptEnd);
//dc << GeLine(m_ptTurn, ptEnd);
DrawLine(dc, m_ptTurn, ptEnd);
}
// AecXDbText *pText = m_bSideText?(new AecXDbText):(new AecXDbMText); // sg modify 080911
AecXDbText *pText = (IsText()) ? (new AecXDbText) : (new AecXDbMText);
AecXDbText &text = *pText;
text.SetPScale(GetPScale());
text.setPropertiesFrom(this);
text.SetText(lstTexts[i]);
text.SetStyleId(m_idTextStyle);
// text.SetRotation(m_nRotation);
//if (dc.IsExportTch4()) // sg modify 090608
//{
// // sg add 120313,分解出来的文字的图层和颜色要随“高级选项”中的设置来处理
// // if (!!m_idTextLayer)
// if (g_nSymbTextT3Layer == 1 && !!m_idTextLayer)
// text.setLayer(m_idTextLayer); // 文字层
// else
// text.setColorIndex(m_colorText); // 文字和标注放在同一层,文字的颜色为白色
//}
//else
text.setColorIndex(m_colorText); // sg add 090608,将文字和标注放在同一层,文字的颜色为白色
text.SetHeight(m_nTextHeight);
text.SetAlignment(m_nAlignment); // 对齐方式一律使用实体变量,sg add 081027
ADSGePoint3d ptText = ptTextEnd; // 文字位置
ADSGePoint3d ptTempEnd = ptTextEnd.TransformAs(matRot);
ADSGePoint3d ptTempBeg = ptTextBeg.TransformAs(matRot);
// AcGiDraw::TextAlignment align; // sg delete 081027
// if (m_bSideText) // sg modify 080911,以下部分
if (IsText()) // 文字在线端,且为单行文字
{
ads_polar(ADSGePoint3d(ptText), m_nLayoutRotation, dDist2Line, ptText); // sg add 080911
// if (ptTempEnd.x > ptTempBeg.x) // 文字在引线右侧,sg delete 081027
// {
// align = XExplodeDraw::kMiddleLeft;
// ads_polar(ADSGePoint3d(ptText), m_nLayoutRotation, nSpacer, ptText);
// }
// else // 文字在引线左侧
// {
// align = XExplodeDraw::kMiddleRight;
// ads_polar(ADSGePoint3d(ptText), m_nLayoutRotation+PI, nSpacer, ptText);
// }
nDist2Turn += nLineSpace;
// text.SetAlignment(align);
}
else if (m_bSideText) // 文字在线端,但为多行文字,sg add 080911
{
((AecXDbMText &)text).SetLineSpace(dLineSpace, FALSE);
((AecXDbMText &)text).SetPageWidth(fabs(dPageWidth), FALSE);
// text.SetAlignment(XExplodeDraw::kLeft); // sg delete 081027
ads_polar(ADSGePoint3d(ptText), m_nLayoutRotation, dDist2Line, ptText);
if (ptTempEnd.x < ptTempBeg.x - 1.0E-3) // 多行文字均为左对齐
{
ads_polar(ADSGePoint3d(ptText), m_nLayoutRotation, dPageWidth, ptText);
}
ads_polar(ADSGePoint3d(ptText), m_nLayoutRotation + PI * 0.5, (m_nTextHeight / 2.0) * GetPScale(), ptText);
if (bReverse && (i != nLength - 1)) // 按上下分正负
{
AecXDbMText tmpText;
tmpText.setPropertiesFrom(this);
tmpText.SetHeight(m_nTextHeight);
tmpText.SetText(lstTexts[i + 1]);
tmpText.SetStyleId(m_idTextStyle);
((AecXDbMText &)tmpText).SetLineSpace(dLineSpace, FALSE);
((AecXDbMText &)tmpText).SetPageWidth(fabs(dPageWidth), FALSE);
tmpText.SetAlignment(m_nAlignment);
Vector3D vtExt = tmpText.GetExtents();
nDist2Turn += dParagraphSpace + vtExt.y;
}
else
{
Vector3D vtExt = text.GetExtents();
nDist2Turn = nDist2Turn - dParagraphSpace - vtExt.y;
}
}
else // 文字在线上,多行文字
{
if (ptTempEnd.x > ptTempBeg.x)
{
// ads_polar(ptTextBeg, m_nLayoutRotation, 4*nSpacer, ptText);
ads_polar(ptTextBeg, m_nLayoutRotation, dDist2Line, ptText);
}
else // 多行文字均为左对齐
{
ads_polar(ptTextBeg, m_nLayoutRotation, dPageWidth + dDist2Line, ptText);
}
// ((AecXDbMText &)text).SetPageWidth(max(fabs(nTextBaseLen)-4*nSpacer, nLineSpace), FALSE);
// ((AecXDbMText &)text).SetLineSpace(nSpacer, FALSE);
((AecXDbMText &)text).SetLineSpace(dLineSpace, FALSE);
((AecXDbMText &)text).SetPageWidth(fabs(dPageWidth), FALSE);
ads_polar(ADSGePoint3d(ptText), m_nLayoutRotation + PI / 2, nSpacer, ptText);
// align = XExplodeDraw::kLeft; // add by whl on 060215,sg delete 081027
// text.SetAlignment(align);
Vector3D vtExt = text.GetExtents();
// nDist2Turn += vtExt.y + nSpacer*4.0;
if (bReverse) // 按上下分正负
{
nDist2Turn += dParagraphSpace + vtExt.y;
}
else if (i != nLength - 1)
{
AecXDbMText tmpText;
tmpText.setPropertiesFrom(this);
tmpText.SetText(lstTexts[i + 1]);
tmpText.SetStyleId(m_idTextStyle);
tmpText.SetHeight(m_nTextHeight);
((AecXDbMText &)tmpText).SetLineSpace(dLineSpace, FALSE);
((AecXDbMText &)tmpText).SetPageWidth(fabs(dPageWidth), FALSE);
tmpText.SetAlignment(m_nAlignment);
Vector3D vtExtNext = tmpText.GetExtents();
nDist2Turn = nDist2Turn - dParagraphSpace - vtExtNext.y;
}
ads_polar(ADSGePoint3d(ptText), m_nLayoutRotation + PI / 2, vtExt.y + nSpacer, ptText);
}
// else // modified by whl on 060214
// {
// ((AecXDbMText &)text).SetPageWidth(max(fabs(nTextBaseLen)-4*nSpacer, nLineSpace), FALSE);
// ((AecXDbMText &)text).SetLineSpace(nSpacer, FALSE);
// align = XExplodeDraw::kLeft;
// text.SetAlignment(align);
// if (ptTempEnd.x>ptTempBeg.x)
// {
// ADSGePoint3d ptLow,ptUp;
// text.SetLayoutRotation(0);
// text.GetExtents2d(ptLow,ptUp);
// text.SetLayoutRotation(m_nLayoutRotation);
// ads_polar(ADSGePoint3d(ptTextEnd), m_nLayoutRotation+PI, ptUp.x-ptLow.x, ptText);
// }
// Vector3D vtExt = text.GetExtents();
// ads_polar(ADSGePoint3d(ptText), m_nLayoutRotation+PI/2, nSpacer, ptText);
// nDist2Turn += vtExt.y + nSpacer*4.0;
// ads_polar(ADSGePoint3d(ptText), m_nLayoutRotation+PI/2, vtExt.y+nSpacer, ptText);
// }
//dc << GeLine(ptTextBeg, ptTextEnd);
DrawLine(dc, ptTextBeg, ptTextEnd);
text.SetLocation(ptText);
{
PushProperty vProp(&text, dc);
//if (dc.IsFullExplode())
// text.ExplodeOrDraw2d(dc);
//else
//dc.DrawEntity(text);
DrawBaseEx(dc, text);
}
delete pText;
}
// add by xly on 100919 添加标注点的绘制函数
//////////////////////////////////Start////////////////////////////////////////
// 获得实体中的动态数组
if (!HasOtherPoint())
{
return Acad::eOk;
}
AcGePoint3dArray arPts;
GetAllDots(arPts);
// i=-1时,为起始点添加圆点
nLength = arPts.length();
for (i = -1; i < nLength; i++)
{
// 设置新的起点
if (i > -1)
{
leaderLine.SetStartPoint(arPts[i]);
}
//axc add 2015-07-20 电气增加短斜线样式
if (GetArrowStyle() == eSortLine)
{
AcGeVector3d vtSortLine = m_ptTurn - m_ptStart;
vtSortLine = vtSortLine.rotateBy(PI / 2, AcGeVector3d::kZAxis);
vtSortLine.normalize();
GeLine line;
line.StartPoint() = leaderLine.StartPoint() + GetCirPointSize() * vtSortLine * GetPScale() / 2;
line.EndPoint() = leaderLine.StartPoint() - GetCirPointSize() * vtSortLine * GetPScale() / 2;
line.TransformBy(matRot);
//dc << line;
DrawLine(dc, line);
}
else
{
// 绘制圆点
ads_matrix mat;
leaderLine.StartPoint().GetRotationMatrix(m_nLayoutRotation, mat);
// 获得圆点的大小
double nW = GetCirPointSize() * GetPScale() / 4;
ADSGePoint3d pt1, pt2;
ads_polar(leaderLine.StartPoint(), leaderLine.Direction() + PI, nW, pt1);
ads_polar(leaderLine.StartPoint(), leaderLine.Direction(), nW, pt2);
AcDbPolyline pline;
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));
DrawPline(dc, pline);
//dc.Polyline(pline);
}
}
//////////////////////////////////End////////////////////////////////////////
return Acad::eOk;
}
// sg add 110211,支持统一标高
bool AecXDbSymbComposing::UnifyElevation(double dElevation)
{
AssertWriteEnabled();
m_ptStart.z = dElevation;
m_ptTurn.z = dElevation;
if (HasOtherPoint()) // 圆点标注点
{
AcGePoint3dArray lstPts, lstNewPts;
GetAllDots(lstPts);
int nLength = lstPts.length();
for (int l = 0; l < nLength; l++)
{
AcGePoint3d ptTmp = lstPts[l];
ptTmp.z = 0;
lstNewPts.append(ptTmp);
}
SetAllDots(lstNewPts);
}
return true;
}
int AecXDbSymbComposing::ConvertText(TConvertTextPtr ptr, void *pData)
{
TCString sText;
int nRet = ptr(m_sText, sText, pData);
if (nRet == RTNORM)
{
AssertWriteEnabled();
m_sText = sText;
}
return nRet;
}
// sg modify 080912,081027
BOOL AecXDbSymbComposing::GetText(Adesk::UInt32 cookies, AecXDbText &text) const
{
TCStringList lstTexts;
GetTexts(lstTexts);
// if (m_ptTurn.y > m_ptStart.y + 1.0E-3)
ads_matrix matRot; // sg modify 080918
m_ptStart.GetRotationMatrix(-m_nLayoutRotation, matRot);
ADSGePoint3d ptTurn = m_ptTurn.TransformAs(matRot),
ptStart = m_ptStart.TransformAs(matRot);
BOOL bReverse = ptTurn.y > ptStart.y + 1.0E-3;
if (bReverse) // 颠倒文字顺序
lstTexts.Reverse();
int nLength = lstTexts.Length();
if ((int)cookies >= nLength)
{
return FALSE;
}
// double nSpacer = DocGetText2Base()*GetPScale(); // sg modify 081027
// double nLineSpace = nSpacer*2 + m_nTextHeight*GetPScale(); // sg delete 080912
double nSpacer = GetText2BaseRatio(FALSE, TRUE);
double nTextBaseLen = GetTextBaseLen(FALSE);
double dParagraphSpace = GetParagraphSpace(FALSE, TRUE), // sg add 080912
nLineSpace = dParagraphSpace + m_nTextHeight * GetPScale();
double dYDist2Turn = cookies * dParagraphSpace;
if (IsText()) // 单行文字
{
dYDist2Turn += cookies * m_nTextHeight * GetPScale();
if (!bReverse) // 按上下分正负
{
dYDist2Turn = -dYDist2Turn;
}
}
else // 多行文字
{
AecXDbMText mText;
mText.SetPScale(GetPScale());
mText.setPropertiesFrom(this);
mText.SetHeight(m_nTextHeight);
mText.SetStyleId(m_idTextStyle);
((AecXDbMText &)mText).SetLineSpace(GetLineSpace(FALSE, TRUE), FALSE);
((AecXDbMText &)mText).SetPageWidth(fabs(GetPageWidth(FALSE)), FALSE);
mText.SetAlignment(m_nAlignment);
int nStart = 1,
nEnd = cookies + 1;
if (m_bSideText != bReverse)
{
nStart = 0;
nEnd = cookies;
}
for (int i = nStart; i < nEnd; i++)
{
mText.SetText(lstTexts[i]);
ADSGePoint3d ptExt = mText.GetExtents();
dYDist2Turn += ptExt.y; // 文字总高度
}
if (!bReverse) // 按上下分正负
{
dYDist2Turn = -dYDist2Turn;
}
if (m_bSideText)
{
dYDist2Turn += 0.5 * m_nTextHeight * GetPScale();
}
else
{
mText.SetText(lstTexts[cookies]);
ADSGePoint3d ptExt = mText.GetExtents();
dYDist2Turn += ptExt.y + nSpacer;
}
}
ADSGePoint3d ptTextBeg, ptTextEnd;
// ptTextBeg = m_ptTurn;
ptTextBeg = ptTurn;
// ptTextBeg.y += nLineSpace*cookies;
ptTextBeg.y += dYDist2Turn;
ptTextEnd = ptTextBeg;
// ptTextEnd.x += nTextBaseLen;
ptTextEnd.x += GetDist2Line(FALSE, TRUE);
text.setPropertiesFrom(this);
text.SetText(lstTexts[cookies]);
text.SetStyleId(m_idTextStyle);
text.SetHeight(m_nTextHeight);
ADSGePoint3d ptText = ptTextEnd;
// AcGiDraw::TextAlignment align; // sg delete 081027
// if (m_bSideText)
if (IsText()) // 单行文字
{
ptText.x += nTextBaseLen;
// if (ptTextEnd.x > ptTextBeg.x)
// {
// align = XExplodeDraw::kMiddleLeft;
// ptText.x += nSpacer;
// }
// else
// {
// align = XExplodeDraw::kMiddleRight;
// ptText.x -= nSpacer;
// }
}
else // 多行文字
{
// ptText.y += nSpacer;
// if (ptTextEnd.x > ptTextBeg.x)
// align = XExplodeDraw::kBottomRight;
// else
// align = XExplodeDraw::kBottomLeft;
// align = XExplodeDraw::kLeft;
if (ptTextEnd.x < ptTextBeg.x)
{
ptText.x += GetPageWidth(FALSE);
}
if (m_bSideText)
{
ptText.x += nTextBaseLen;
}
}
ads_matrix mat; // sg add 080918
m_ptStart.GetRotationMatrix(m_nLayoutRotation, mat);
ptText = ptText.TransformAs(mat);
text.SetAlignment(m_nAlignment);
text.SetLocation(ptText);
return TRUE;
}
// 返回发现的位置,同时posStart往前移动(以便继续找下一个使用),
TextPosition
AecXDbSymbComposing::FindSubText(const TCHAR *sSubText, TextPosition &posStart, TextRange *pRange) const
{
TextPosition pos;
if (!sSubText || !sSubText[0])
return pos;
TextPosition posNext = posStart;
while (1)
{
// AecXDbText text;
// if (!GetText(posNext.m_nCookies, text))
// break;
//
// TextPosition posFind = text.FindSubText(sSubText, posNext, pRange);
TextPosition posFind; // sg modify 080917
if (IsText()) // 单行文字
{
AecXDbText text;
text.SetPScale(GetPScale());
if (!GetText(posNext.m_nCookies, text))
break;
text.SetRotation(m_nLayoutRotation);
text.SetLayoutRotation(0);
posFind = text.FindSubText(sSubText, posNext, pRange);
}
else // 多行文字
{
AecXDbMText text;
text.SetPScale(GetPScale());
if (!GetText(posNext.m_nCookies, text))
break;
text.SetRotation(m_nLayoutRotation);
text.SetLayoutRotation(0);
((AecXDbMText &)text).SetLineSpace(GetLineSpace(FALSE, TRUE), FALSE);
((AecXDbMText &)text).SetPageWidth(fabs(GetPageWidth(FALSE)), FALSE);
posFind = text.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;
}
// 返回下一次查找的开始位置
TextPosition
AecXDbSymbComposing::ReplaceSubText(const TextPosition &posRep, const TCHAR *sRepText, TextRange *pRange)
{
AssertWriteEnabled();
TextPosition posNext;
// AecXDbText text;
// if (!sRepText || !GetText(posRep.m_nCookies, text))
// return posNext;
// posNext = text.ReplaceSubText(posRep, sRepText, pRange);
CString csGetText; // sg modify 080917
if (IsText()) // 单行文字
{
AecXDbText text;
text.SetPScale(GetPScale());
if (!sRepText || !GetText(posRep.m_nCookies, text))
return posNext;
text.SetRotation(m_nLayoutRotation);
text.SetLayoutRotation(0);
posNext = text.ReplaceSubText(posRep, sRepText, pRange);
csGetText = text.GetText();
}
else // 多行文字
{
AecXDbMText text;
text.SetPScale(GetPScale());
if (!sRepText || !GetText(posRep.m_nCookies, text))
return posNext;
text.SetRotation(m_nLayoutRotation);
text.SetLayoutRotation(0);
((AecXDbMText &)text).SetLineSpace(GetLineSpace(FALSE, TRUE), FALSE);
((AecXDbMText &)text).SetPageWidth(fabs(GetPageWidth(FALSE)), FALSE);
posNext = text.ReplaceSubText(posRep, sRepText, pRange);
csGetText = text.GetText();
}
int cookies = posRep.m_nCookies;
TCStringList lstTexts;
GetTexts(lstTexts);
ads_matrix matRot; // sg add 081007
m_ptStart.GetRotationMatrix(-m_nLayoutRotation, matRot);
ADSGePoint3d ptTurn = m_ptTurn.TransformAs(matRot),
ptStart = m_ptStart.TransformAs(matRot);
// if (m_ptTurn.y > m_ptStart.y + 1.0E-3) // sg modify 081007
if (ptTurn.y > ptStart.y + 1.0E-3) // 颠倒文字顺序
lstTexts.Reverse();
if (cookies >= lstTexts.Length())
return posNext;
// lstTexts.Replace(tstrnew(text.GetText()), cookies); // sg modify 080917
lstTexts.Replace(tstrnew(csGetText), cookies);
// if (m_ptTurn.y > m_ptStart.y + 1.0E-3) // sg modify 081007
if (ptTurn.y > ptStart.y + 1.0E-3) // 颠倒文字顺序
lstTexts.Reverse();
CString csText;
for (int i = 0; i < lstTexts.Length(); i++)
{
TCHAR *str = lstTexts[i];
csText += str;
if (i < lstTexts.Length() - 1)
csText += _T("\r\n");
}
SetText(csText);
if (!posNext)
{
posNext.m_nCookies = posRep.m_nCookies + 1;
posNext.m_nTextPos = 0;
}
return posNext;
}
/* * * * * * * * * * 取 动 态 属 性 显 示 数 据 的 函 数 * * * * * * * * * */
void AecXDbSymbComposing::GetTips(PtrList<ObjInfoUnit> &lstInfo) const
{
// lstInfo.Append(new ObjInfoUnit(_T("对象类型"), _T("作法标注")));
lstInfo.Append(new ObjInfoUnit(_T("对象类型"), _T("做法标注"))); // sg modify 080905,根据需求反映,觉得原来是错别字
TCStringList lstTexts;
GetTexts(lstTexts);
int nLength = lstTexts.Length();
for (int i = 0; i < nLength; i++)
lstInfo.Append(new ObjInfoUnit(TCString(_T("文字%d"), i), lstTexts[i]));
lstInfo.Append(new ObjInfoUnit(_T("文字高度"), TCString(_T("%.1fP"), m_nTextHeight)));
TCString sTextStyle = GlobalFunc::GetSymbolName(m_idTextStyle);
lstInfo.Append(new ObjInfoUnit(_T("文字样式"), sTextStyle));
}
// Properties
const TCHAR *
AecXDbSymbComposing::GetText() const
{
return (const TCHAR *)m_sText;
}
void
AecXDbSymbComposing::GetTexts(TCStringList &lstTexts) const
{
TCString sText1;
sText1 = m_sText;
lstTexts.Reset();
TCHAR *p1 = (TCHAR *)sText1;
TCHAR *p2 = NULL;
TCHAR szWord[256] = _T("");
while (p2 = _tcschr(p1, _T('\n')))
{
GlobalFunc::StrCpy(szWord, p1, p2);
int nLen = (int)_tcslen(szWord);
if (nLen >= 1)
{
if (szWord[nLen - 1] == _T('\r'))
szWord[nLen - 1] = EOS;
}
lstTexts.Append(tstrnew(szWord));
p1 = p2;
p1++;
}
{
GlobalFunc::StrCpy(szWord, p1, p2);
lstTexts.Append(tstrnew(szWord));
}
}
SubText* AecXDbSymbComposing::HitTestText(ADSGePoint3d pt)const
{
SubText *pSubText = AecXDbSymbWithText::HitTestText(pt);
if (pSubText != NULL)
pSubText->SetMultiLine(false);
return pSubText;
}
SubText* AecXDbSymbComposing::GetSubText(long iText)const
{
SubText *pSubText = AecXDbSymbWithText::GetSubText(iText);
if (pSubText != NULL)
pSubText->SetMultiLine(false);
return pSubText;
}
void AecXDbSymbComposing::SetSubText(long iText, CString sText)
{
TCStringList lstTexts;
GetTexts(lstTexts);
int nLength = lstTexts.Length();
if (iText >= 0 && iText < nLength)
{
ads_matrix matRot;
m_ptStart.GetRotationMatrix(-m_nLayoutRotation, matRot);
ADSGePoint3d ptTurn = m_ptTurn.TransformAs(matRot);
ADSGePoint3d ptStart = m_ptStart.TransformAs(matRot);
if (ptTurn.y > ptStart.y + 1.0E-3)
iText = nLength - iText - 1;
CString sTemp;
for (long i = 0; i < iText; i++)
{
sTemp += lstTexts[i];
sTemp += _T("\r\n");
}
sTemp += sText + _T("\r\n");
for (i = iText + 1; i < nLength; i++)
{
sTemp += lstTexts[i];
sTemp += _T("\r\n");
}
sTemp = sTemp.Left(sTemp.GetLength() - 2);
SetText(sTemp);
}
}
ADSGePoint3d
AecXDbSymbComposing::GetStartPoint() const
{
return m_ptStart;
}
ADSGePoint3d
AecXDbSymbComposing::GetTurnPoint() const
{
return m_ptTurn;
}
ADSGePoint3d AecXDbSymbComposing::GetEndPoint() const // sg modify 080912、081030
{
// double nLineSpace = (DocGetText2Base()*2 + m_nTextHeight) * GetPScale();
TCStringList lstTexts;
GetTexts(lstTexts);
ads_matrix matRot;
m_ptStart.GetRotationMatrix(-m_nLayoutRotation, matRot);
ADSGePoint3d ptTurn = m_ptTurn.TransformAs(matRot),
ptStart = m_ptStart.TransformAs(matRot);
BOOL bReverse = ptTurn.y > ptStart.y + 1.0E-3;
if (bReverse) // 颠倒文字顺序
{
lstTexts.Reverse();
}
// double nDist2End = (lstTexts.Length()-1) * nLineSpace;
int nLength = lstTexts.Length();
double dParagraphSpace = GetParagraphSpace(FALSE, TRUE), // 段距
nDist2End = (nLength - 1) * dParagraphSpace;
if (IsText()) // 单行文字
{
nDist2End += (nLength - 1) * m_nTextHeight * GetPScale();
if (!bReverse) // ptTurn.y < ptStart.y
{
nDist2End = 0;
}
}
else // 多行文字
{
AecXDbMText text;
text.setPropertiesFrom(this);
text.SetHeight(m_nTextHeight);
text.SetStyleId(m_idTextStyle);
((AecXDbMText &)text).SetLineSpace(GetLineSpace(FALSE, TRUE), FALSE);
((AecXDbMText &)text).SetPageWidth(fabs(GetPageWidth(FALSE)), FALSE);
text.SetAlignment(m_nAlignment);
int nStart = 1,
nEnd = nLength;
if (m_bSideText != bReverse)
{
nStart = 0;
nEnd = nLength - 1;
}
for (int i = nStart; i < nEnd; i++)
{
text.SetText(lstTexts[i]);
ADSGePoint3d ptExt = text.GetExtents();
nDist2End += ptExt.y; // 多行文字,文字总高度
}
int nIndex = nLength - 1; // sg add 081104,Y值最大的文字索引号
if (!bReverse) // ptTurn.y < ptStart.y
{
nDist2End = 0;
nIndex = 0;
}
if (!m_bSideText) // 线上文字
{
text.SetText(lstTexts[nIndex]);
ADSGePoint3d ptExt = text.GetExtents();
nDist2End += ptExt.y + GetText2BaseRatio(FALSE, TRUE);
}
}
ADSGePoint3d ptEnd;
// 考虑getStretchPoints调用,无论什么位置关系,都需要增加半个字高
nDist2End += m_nTextHeight * 0.5 * GetPScale();
ads_polar(m_ptTurn, m_nLayoutRotation + PI / 2.0, nDist2End, ptEnd);
return ptEnd;
}
double AecXDbSymbComposing::GetTextBaseLen(BOOL bAsPaperUnit) const
{
double nVal = m_nTextBaseLen;
if (!bAsPaperUnit)
nVal *= GetPScale();
return nVal;
}
BOOL AecXDbSymbComposing::IsSideText() const
{
return m_bSideText;
}
double AecXDbSymbComposing::GetMinTextBaseLen(BOOL bAsPaperUnit) const
{
if (!m_sText)
return 0.0;
AecXDbText text;
text.SetPScale(GetPScale());
text.setPropertiesFrom(this);
text.SetHeight(m_nTextHeight);
text.SetStyleId(m_idTextStyle);
double nVal = 0.0;
TCStringList lstTexts;
GetTexts(lstTexts);
int nLength = lstTexts.Length();
for (int i = 0; i < nLength; i++)
{
text.SetText(lstTexts[i]);
ADSGePoint3d ptExt = text.GetExtents();
nVal = max(nVal, ptExt.x);
}
// nVal += DocGetText2Base() * GetPScale();
nVal += GetText2BaseRatio(FALSE, TRUE); // sg modify 081110
if (bAsPaperUnit)
nVal /= GetPScale();
return nVal;
}
double AecXDbSymbComposing::GetDefaultTextBaseLen(BOOL bAsPaperUnit) const
{
double nVal = 6.0;
if (!bAsPaperUnit)
nVal *= GetPScale();
if (!m_bSideText)
nVal = max(nVal, GetMinTextBaseLen(bAsPaperUnit));
return nVal;
}
void AecXDbSymbComposing::SetText(const TCHAR *pszText)
{
AssertWriteEnabled();
m_sText = pszText;
}
void AecXDbSymbComposing::SetStartPoint(ADSGePoint3d pt)
{
AssertWriteEnabled();
m_ptStart = pt;
}
void AecXDbSymbComposing::SetTurnPoint(ADSGePoint3d pt)
{
AssertWriteEnabled();
m_ptTurn = pt;
}
void AecXDbSymbComposing::SetTextBaseLen(double val, BOOL bAsPaperUnit)
{
AssertWriteEnabled();
m_nTextBaseLen = val;
if (!bAsPaperUnit)
m_nTextBaseLen /= GetPScale();
}
void AecXDbSymbComposing::SetSideText(BOOL bTrue)
{
AssertWriteEnabled();
m_bSideText = bTrue;
}
// sg add 080904,sg modify 081023,以下代码为8.0新增,为满足新需求
BOOL AecXDbSymbComposing::IsText() const
{
return m_bSideText && (fabs(m_dPageWidth) < 1.0E-5);
}
double AecXDbSymbComposing::GetParagraphSpace(BOOL bAsPaperUnit, BOOL bRealDist) const
{
double dVal = m_dParagraphSpace; // “系数”
if (bRealDist)
{
dVal *= m_nTextHeight; // 将“系数”转为“实际值”
}
if (!bAsPaperUnit) // 处理出图比例
{
dVal *= GetPScale();
}
return dVal;
}
double AecXDbSymbComposing::GetLineSpace(BOOL bAsPaperUnit, BOOL bRealDist) const
{
double dVal = m_dLineSpace; // “系数”
if (bRealDist)
{
dVal *= m_nTextHeight; // 将“系数”转为“实际值”
}
if (!bAsPaperUnit)
{
dVal *= GetPScale();
}
return dVal;
}
double AecXDbSymbComposing::GetDist2Line(BOOL bAsPaperUnit, BOOL bRealDist) const
{
double dVal = m_dDist2Line; // “系数”
if (bRealDist)
{
dVal *= m_nTextHeight; // 将“系数”转为“实际值”
}
if (!bAsPaperUnit)
{
dVal *= GetPScale();
}
return dVal;
}
double AecXDbSymbComposing::GetPageWidth(BOOL bAsPaperUnit) const
{
double dVal = m_dPageWidth;
if (IsText()) // m_dPageWidth=0的线端文字,表示单行文字
{
dVal = GetMinTextBaseLen(bAsPaperUnit);
dVal *= GetDistSymbol(); // 正负情况随“线”
return dVal;
}
if (!bAsPaperUnit)
{
dVal *= GetPScale();
}
return dVal;
}
void AecXDbSymbComposing::SetParagraphSpace(double dVal, BOOL bAsPaperUnit)
{
AssertWriteEnabled();
m_dParagraphSpace = dVal; // 系数
if (!bAsPaperUnit)
{
m_dParagraphSpace /= GetPScale();
}
}
void AecXDbSymbComposing::SetLineSpace(double dVal, BOOL bAsPaperUnit)
{
AssertWriteEnabled();
m_dLineSpace = dVal; // 系数
if (!bAsPaperUnit)
{
m_dLineSpace /= GetPScale();
}
}
void AecXDbSymbComposing::SetDist2Line(double dVal, BOOL bAsPaperUnit)
{
AssertWriteEnabled();
m_dDist2Line = dVal;
if (!bAsPaperUnit)
{
m_dDist2Line /= GetPScale();
}
}
void AecXDbSymbComposing::SetPageWidth(double dVal, BOOL bAsPaperUnit)
{
AssertWriteEnabled();
m_dPageWidth = dVal;
if (!bAsPaperUnit)
{
m_dPageWidth /= GetPScale();
}
}
// sg add 081023
double AecXDbSymbComposing::GetText2BaseRatio(BOOL bAsPaperUnit, BOOL bRealDist) const
{
double dVal = m_dText2BaseRatio; // 系数
if (fabs(dVal + 1000) < 1.0E-5)
{
dVal = GlobalFunc::DocGetText2BaseRatio(); // 使用全局变量DocGetText2BaseRatio的值
}
if (bRealDist)
{
dVal *= m_nTextHeight; // 将“系数”转为“实际值”
}
if (!bAsPaperUnit) // 处理出图比例
{
dVal *= GetPScale();
}
return dVal;
}
AcGiDraw::TextAlignment AecXDbSymbComposing::GetAlignment() const
{
return m_nAlignment;
}
void AecXDbSymbComposing::SetText2BaseRatio(double dVal, BOOL bAsPaperUnit)
{
AssertWriteEnabled();
m_dText2BaseRatio = dVal; // 系数
if (!bAsPaperUnit)
{
m_dText2BaseRatio /= GetPScale();
}
}
void AecXDbSymbComposing::SetAlignment(AcGiDraw::TextAlignment nAlign)
{
AssertWriteEnabled();
m_nAlignment = nAlign;
}
// sg add 081104,根据线长的正负符号,获得其他距离的正负符号、单行文字的默认对齐方式
double AecXDbSymbComposing::GetDistSymbol() const
{
if (fabs(m_nTextBaseLen) < 1.0E-5)
{
return 1.0;
}
double dRet = m_nTextBaseLen / fabs(m_nTextBaseLen);
return dRet;
}
void AecXDbSymbComposing::SetAlignBySymbol()
{
AssertWriteEnabled();
if (IsText()) // 单行文字
{
double dRet = GetTextBaseLen(TRUE);
if (dRet < -1.0E-5)
{
m_nAlignment = AcGiDraw::kMiddleRight;
return;
}
m_nAlignment = AcGiDraw::kMiddleLeft;
}
else // 多行文字
{
m_nAlignment = AcGiDraw::kLeft;
}
}
// add by xly on 100920 移动其他夹点
void AecXDbSymbComposing::MoveOtherGrip(AcGePoint3d ptStartBefor, bool bIsTurn)
{
if (!HasOtherPoint()) // 不存在圆点标注点
{
return;
}
// 获得动态数组
AcGePoint3dArray aryPts, aryNewPts;
GetAllDots(aryPts);
// 计算每一个夹点的位置
int nLength = aryPts.length();
if (nLength < 0)
{
return;
}
// 获得整个引线
GeLine line(m_ptStart, m_ptTurn);
double dLineLen = line.GetLength(), // 引线长度
dLineDir = line.Direction(); // 引线方向
AcGePoint3d ptTemp;
for (nLength = aryPts.length() - 1; nLength >= 0; nLength--)
{
// 端头距标注点的距离
double dLen = aryPts[nLength].distanceTo(ptStartBefor);
// 当拖动缩小时,如果相对距离不满足删除距端点最远的点
if (dLineLen < dLen)
{
continue;
}
// modify by xly on 110308 修改需求设置不同的定位点
if (bIsTurn)// 以转折点位定位点
{
ads_polar(m_ptTurn, dLineDir + PI, dLen, asDblArray(ptTemp));
}
else// 以端头点位定位点
{
ads_polar(m_ptStart, dLineDir, dLen, asDblArray(ptTemp));
}
aryNewPts.append(ptTemp);
}
SetAllDots(aryNewPts);
}
// add by xly on 100926 判断是否有其他标注点;有:TRUE;没有:FALSE
bool AecXDbSymbComposing::HasOtherPoint() const
{
assertReadEnabled();
return (GetDotsNum() > 0);
}
// sg add 101221,获得圆点数量
// 增加圆点数量
void AecXDbSymbComposing::PlusDotsNum(Adesk::UInt16 nPlusNum)
{
Adesk::UInt16 nNum = GetDotsNum();
AssertWriteEnabled();
EntityFields &fd = Fields();
nNum += nPlusNum;
fd.SFD(_T("圆点标注点数量"), nNum);
}
// 设置圆点数量
void AecXDbSymbComposing::SetDotsNum(Adesk::UInt16 nNum)
{
AssertWriteEnabled();
EntityFields &fd = Fields();
fd.SFD(_T("圆点标注点数量"), nNum);
}
Adesk::UInt16 AecXDbSymbComposing::GetDotsNum() const
{
assertReadEnabled();
const EntityFields &fd = GetFields();
Adesk::UInt16 nLength = 0;
// modify by xly on 110318 解决高低版本数据的兼容
//fd.GFD(_T("圆点标注点数量"), nLength);
long lNum = fd.GetSubFieldNum();
for (long l = 0; l < lNum; l++)
{
// 说明:EntityFields::Find函数,会临时改变成员函数,无法使用
const EntityField &subFd = fd.GetSubField(l);
if (_tcscmp(subFd.GetName(), _T("圆点标注点数量")) != 0)
{
continue;
}
else
{
subFd.GetData(nLength);
break;
}
}
return nLength;
}
// add by xly on 100928,一次性获得全部圆点标注点的动态数据
void AecXDbSymbComposing::GetAllDots(AcGePoint3dArray &arPts) const
{
assertReadEnabled();
// 获取对象内的动态数据组
const EntityFields &fd = GetFields();
AcGePoint3d point;
long lNum = fd.GetSubFieldNum();
for (long l = 0; l < lNum; l++)
{
// 说明:EntityFields::Find函数,会临时改变成员函数,无法使用
const EntityField &subFd = fd.GetSubField(l);
if (_tcscmp(subFd.GetName(), _T("圆点标注点")) != 0)
{
continue;
}
EntityField::DataType type = subFd.GetDataType();
if (type != EntityField::kGroup)
{
continue; // 不是组
}
EntityFields *ptFds = NULL;
subFd.GetData(ptFds);
long lLength = ptFds->GetSubFieldNum();
for (long i = 0; i < lLength; i++)
{
ptFds->GFD(i, point); // 取点坐标
arPts.append(point);
}
break;
}
}
// add by xly on 100928,添加一个圆点标注点到数组的最后
void AecXDbSymbComposing::AddDotLoc(const AcGePoint3d &ptLoc)
{
AssertWriteEnabled();
// 获取对象内的动态数据组
EntityFields &fd = Fields();
// “圆点标注点”的动态数据组
EntityFields *pNewFds = NULL;
// modify by xly on 110318 解决高低版本数据的兼容
//// 首先判断“圆点标注点”的动态数据是否存在
//long lFind = fd.Find(_T("圆点标注点"));
// 首先判断“圆点标注点”的动态数据是否存在
long lFind(-1);
long lNum = fd.GetSubFieldNum();
for (long n = 0; n < lNum; n++)
{
// 说明:EntityFields::Find函数,会临时改变成员函数,无法使用
const EntityField &subFd = fd.GetSubField(n);
if (_tcscmp(subFd.GetName(), _T("圆点标注点")) != 0)
{
continue;
}
else
{
lFind = n;
break;
}
}
if (lFind > -1) // 找到
{
EntityField &dot = fd.GetSubField(lFind);
dot.GetData(pNewFds); // 获取组数据
}
else // 找不到
{
EntityField *pDot = new EntityField(_T("圆点标注点"), EntityField::kGroup);
fd.Add(pDot); // 添加
pDot->GetData(pNewFds); // 获取组数据
}
// 在数组的最后面添加点
pNewFds->AFD(ptLoc);
// 设置圆点标注数量动态数据自增
PlusDotsNum(1);
}
// sg add 101221,一次行修改全部动态数据
void AecXDbSymbComposing::SetAllDots(const AcGePoint3dArray &aryPts)
{
AssertWriteEnabled();
// 获取对象内的动态数据组
EntityFields &fd = Fields();
// “圆点标注点”的动态数据组
EntityFields *pNewFds = NULL;
// modify by xly on 110318 解决高低版本数据的兼容
//// 首先判断“圆点标注点”的动态数据是否存在
//long lFind = fd.Find(_T("圆点标注点"));
// 首先判断“圆点标注点”的动态数据是否存在
long lFind(-1);
long lNum = fd.GetSubFieldNum();
for (long n = 0; n < lNum; n++)
{
// 说明:EntityFields::Find函数,会临时改变成员函数,无法使用
const EntityField &subFd = fd.GetSubField(n);
if (_tcscmp(subFd.GetName(), _T("圆点标注点")) != 0)
{
continue;
}
else
{
lFind = n;
break;
}
}
if (lFind > -1) // 找到
{
EntityField &dot = fd.GetSubField(lFind);
dot.GetData(pNewFds); // 获取组数据
}
else // 找不到
{
EntityField *pDot = new EntityField(_T("圆点标注点"), EntityField::kGroup);
fd.Add(pDot); // 添加
pDot->GetData(pNewFds); // 获取组数据
}
// 首先,全部清空
long lLength = pNewFds->GetSubFieldNum();
for (long l = 0; l < lLength; l++)
{
pNewFds->Del(l);
l--;
lLength--;
}
// 然后,一个一个重新设置数据,添加到数组的最后面
lLength = aryPts.length();
for (l = 0; l < lLength; l++)
{
pNewFds->AFD(aryPts[l]);
}
// 设置圆点标注数量动态数据
SetDotsNum((int)lLength);
}
// add by xly on 100928,设置数组索引为lIndex的数据
bool AecXDbSymbComposing::SetDotLoc(long lIndex, const AcGePoint3d &ptLoc)
{
int nNum = GetDotsNum(); // 获取圆点标注点数量
if ((lIndex < 0) && (lIndex > nNum))
{
return false; // 数组越界
}
AssertWriteEnabled(); // 此行必须有
// 获取对象内的动态数据组
EntityFields &fd = Fields();
// 标记是否找到正确的点
bool bRet = false;
long lNum = fd.GetSubFieldNum();
for (long l = 0; l < lNum; l++)
{
// 说明:EntityFields::Find函数,会临时改变成员函数,无法使用
const EntityField &subFd = fd.GetSubField(l);
if (_tcscmp(subFd.GetName(), _T("圆点标注点")) != 0)
{
continue;
}
EntityField::DataType type = subFd.GetDataType();
if (type != EntityField::kGroup)
{
continue; // 不是组
}
EntityFields *ptFds = NULL;
subFd.GetData(ptFds);
long lLength = ptFds->GetSubFieldNum();
if (lLength == 0)
{
continue; // 空集合
}
if (lIndex >= lLength)
{
break; // 数组越界
}
EntityField &pointFd = ptFds->GetSubField(lIndex);
pointFd.SetData(ptLoc);
bRet = true;
break;
}
return bRet;
}
// add by xly on 100928,删除数组索引为lIndex的数据
bool AecXDbSymbComposing::DelDotLoc(long lIndex)
{
int nNum = GetDotsNum(); // 获取圆点标注点数量
if ((lIndex < 0) && (lIndex > nNum))
{
return false; // 数组越界
}
AssertWriteEnabled(); // 此行必须有
// 获取对象内的动态数据组
EntityFields &fd = Fields();
// 标记是否找到正确的点
bool bRet = false;
long lNum = fd.GetSubFieldNum();
for (long l = 0; l < lNum; l++)
{
// 说明:EntityFields::Find函数,会临时改变成员函数,无法使用
const EntityField &subFd = fd.GetSubField(l);
if (_tcscmp(subFd.GetName(), _T("圆点标注点")) != 0)
{
continue;
}
EntityField::DataType type = subFd.GetDataType();
if (type != EntityField::kGroup)
{
continue; // 不是组
}
EntityFields *ptFds = NULL;
subFd.GetData(ptFds);
long lLength = ptFds->GetSubFieldNum();
if (lLength == 0)
{
continue; // 空集合
}
if (lIndex >= lLength)
{
break; // 数组越界
}
// 删除节点
ptFds->Del(lIndex);
bRet = true;
break;
}
if (bRet)
{
// 设置圆点标注数量动态数据自增
PlusDotsNum(-1);
}
return bRet;
}
// add xly on 100928,设置圆点的大小
void AecXDbSymbComposing::SetCirPointSize(double dVal)
{
AssertWriteEnabled();
// 注:有名字段,名称不容易重复
EntityFields &fd = Fields();
fd.SFD(_T("圆点大小"), dVal);
}
// add xly on 100928,获得圆点的大小
double AecXDbSymbComposing::GetCirPointSize()const
{
assertReadEnabled();
// 如果不存在“圆点大小”数据时,返回“0.0”
double dPageWidth(0.0);
const EntityFields &fd = GetFields();
// modify by xly on 110318 解决高低版本数据的兼容
//fd.GFD(_T("圆点大小"), dPageWidth);
long lNum = fd.GetSubFieldNum();
for (long l = 0; l < lNum; l++)
{
// 说明:EntityFields::Find函数,会临时改变成员函数,无法使用
const EntityField &subFd = fd.GetSubField(l);
if (_tcscmp(subFd.GetName(), _T("圆点大小")) != 0)
{
continue;
}
else
{
subFd.GetData(dPageWidth);
break;
}
}
return dPageWidth;
}
// add by xly on 110310 拉伸时移动没有框选到的其他夹点 aryInt存放拉伸的夹点的索引
void AecXDbSymbComposing::MoveOtherPoint(AcGeIntArray aryInt, bool bTurnPtBase)
{
// 获得所有夹点
AcGePoint3dArray arPts;
GetAllDots(arPts);
int nLen = arPts.length();
for (int i = nLen - 1; i >= 0; i--)
{
if (FindAryData(aryInt, i + 5) < 0)// 不是拉伸的夹点,联动
{
// 获得整个引线
GeLine line(m_ptStart, m_ptTurn);
double dLineLen = line.GetLength(), // 引线长度
dLineDir = line.Direction(); // 引线方向
AcGePoint3d ptTemp;
// modify by xly on 110308 修改需求设置不同的定位点
if (bTurnPtBase)// 以转折点位定位点
{
// 端头距标注点的距离
double dLen = arPts[i].distanceTo(m_ptTurn);
ads_polar(m_ptTurn, dLineDir + PI, dLen, asDblArray(ptTemp));
}
else// 以端头点位定位点
{
// 端头距标注点的距离
double dLen = arPts[i].distanceTo(m_ptStart);
ads_polar(m_ptStart, dLineDir, dLen, asDblArray(ptTemp));
}
SetDotLoc(i, ptTemp);
}
}
}
// add by xly on 110310为数组中的元素排序
void AecXDbSymbComposing::SortAyry(AcGeIntArray &aryInt)
{
int i, j, key;
int length = aryInt.length();
for (i = 1; i < length; i++)
{
key = aryInt[i];
// 把i之前大于array[i]的数据向后移动
for (j = i - 1; j >= 0 && aryInt[j] > key; j--)
{
aryInt[j + 1] = aryInt[j];
}
// 在合适位置安放当前元素
aryInt[j + 1] = key;
}
}
// add by xly on 110309 查找数组中的元素,返回位置值
int AecXDbSymbComposing::FindAryData(AcGeIntArray aryInt, int nData)
{
int nRet(-1);
for (int n = 0; n < aryInt.length(); n++)
{
int nTemp = aryInt[n];
if (nTemp == nData)
{
nRet = n;
}
}
return nRet;
}