Files
envi-code/SourceCode/Code2026/tg_shs/shs_kernal/TDbStruSymbFocus.cpp
T
2026-09-28 15:28:50 +08:00

1112 lines
24 KiB
C++

//------------------------------------------------------------------------+
// Copyright (C), 1998-2012, Beijing Tangent Software Co. Ltd.
// = FileName : TDbStruSymbFocus.cpp
// = Version : ver1.0
// = Author : zyc
// = CreateDate : 2012-06-18
// = Description: 集中标注实体类定义
// = Maintainers:
//
//------------------------------------------------------------------------+
#include "stdafx.h"
#ifdef TASD
#include "TDbStruSymbFocus.h"
// 计算单行文本宽度 sText-文本内容, styleId-文字样式, dHeight-文字高度
double CalcTextLen(const CString &sText, const AcDbObjectId &styleId, double dHeight)
{
if( styleId.isNull() || sText.IsEmpty() )
{
return 0.0;
}
TDbText text;
text.SetHeight(dHeight);
text.SetStyleId(styleId);
text.SetText(sText);
text.SetAlignment(TGGiExplodeDrawBase::kBottomLeft);
text.SetLocation(XPoint());
XPoint ptMin, ptMax;
text.GetExtents2d(ptMin, ptMax);
return fabs(ptMax.x-ptMin.x);
}
// 根据以\n分隔的字符串(TDbMText的Text)获取PageWidth
double GetPageWidth( const CString &sText, const AcDbObjectId &styleId, double dTextHeight, bool AutoAdjust = true )
{// dTextHeight为文字高度
double dPageWidth(0);
CString sTemp=sText, sValue;
int iPos;
double dTemp;
while( (iPos=sTemp.Find('\n')) != -1 )
{
sValue = sTemp.Left(iPos);
sValue.TrimRight();
dTemp = CalcTextLen(sValue, styleId, dTextHeight);
dPageWidth = max(dTemp, dPageWidth);
sTemp = sTemp.Mid(iPos+1);
}
sTemp.TrimRight();
dTemp = CalcTextLen(sTemp, styleId, dTextHeight);
dPageWidth = max(dTemp, dPageWidth);
if( AutoAdjust )
{
dPageWidth += CalcTextLen(_T("0"), styleId, dTextHeight); // 文字的位置点和文字之间会有空隙 适当的增加页宽
}
dPageWidth /= DocGetPScale();
return dPageWidth;
}
const Adesk::UInt8 TDbStruSymbFocus::g_nVersion = 1;
extern double g_dDistInBeam; // 进出梁长度
IMPLEMENT_TENTBASE(TDbStruSymbFocus);
ACRX_DXF_DEFINE_MEMBERS(TDbStruSymbFocus, TDbStruEntityBase, AcDb::kDHL_CURRENT,
AcDb::kMReleaseCurrent, 1, ATS_STRUSYMBFOCUS,
"ATS_STRUSYMBFOCUS图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
TDbStruSymbFocus::TDbStruSymbFocus()
{
SetAt(KEY_TH, 3.5f);
SetAt(KEY_DISTRATE, 0.4f); // 行间距系数
SetAt(KEY_TS, InitTextStyle(TS_STANDARD));
SetAt(KEY_ISLEFT, FALSE); // 默认右侧或者上测
SetAt(KEY_SHOW_DOT, FALSE);
SetAt(KEY_POINT_DIA, 0.0);
SetAt(KEY_TEXT, _T(""));
SetAt(KEY_LINEFLAG, 0);
SetAt(KEY_ALIGNFLAG, ALIGN_LEFT);
SetAt(KEY_WCOLU, FALSE); // 非墙柱样式
SetAt(KEY_AXANG, 0.0);
}
TDbStruSymbFocus::~TDbStruSymbFocus()
{
}
Acad::ErrorStatus TDbStruSymbFocus::dwgInFields (AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es;
es = TDbStruEntityBase::dwgInFields(pFiler);
if (Acad::eOk != es)
{
return es;
}
Adesk::UInt8 nVer;
pFiler->readItem(&nVer);
if(nVer>g_nVersion)
{
return Acad::eMakeMeProxy;
}
return es;
}
Acad::ErrorStatus TDbStruSymbFocus::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es;
es = TDbStruEntityBase::dwgOutFields(pFiler);
if (Acad::eOk != es)
{
return es;
}
pFiler->writeItem(g_nVersion);
return es;
}
Acad::ErrorStatus TDbStruSymbFocus::dxfInFields (AcDbDxfFiler* pFiler)
{
assertWriteEnabled();
return TDbStruEntityBase::dxfInFields(pFiler);
}
Acad::ErrorStatus TDbStruSymbFocus::dxfOutFields(AcDbDxfFiler* pFiler) const
{
assertReadEnabled();
return TDbStruEntityBase::dxfOutFields(pFiler);
}
Acad::ErrorStatus TDbStruSymbFocus::GetGripText(int i, CString &cs) const
{
int iLineFlag;
GetAt(KEY_LINEFLAG, iLineFlag);
if( iLineFlag != kColuLine )
{
AcGePoint3d ptFront;
if( GetAt(KEY_FRONT, ptFront) )
{
if (i == 0)
{
if( GetCtrlToggle() )
{
cs = _T("移动对象(Ctrl-拉伸)");
}
else
{
cs = _T("拉伸(Ctrl-移动对象)");
}
}
else if (i == 1)
{
cs = _T("移动文字");
}
else
{
cs = _T("移动引线");
}
}
else
{
if (i == 0)
{
cs = _T("移动对象");
}
else if (i == 1)
{
cs = _T("移动文字");
}
}
}
else
{
if (i == 0)
{
cs = _T("移动标注点");
}
else if (i == 1)
{
cs = _T("移动文字");
}
else
{
cs = _T("移动对象");
}
}
return Acad::eOk;
}
Acad::ErrorStatus TDbStruSymbFocus::ExplodeOrDraw2d(TGGiExplodeDrawBase &dc) const
{
assertReadEnabled();
// 标注线
DrawDimLine(dc);
// 标注文本
DrawDimText(dc);
return Acad::eOk;
}
Acad::ErrorStatus TDbStruSymbFocus::ExplodeOrDraw3d(TGGiExplodeDrawBase &dc) const
{
return Acad::eNotImplementedYet;
}
Acad::ErrorStatus TDbStruSymbFocus::subTransformBy(const AcGeMatrix3d& xform)
{
assertWriteEnabled();
AcGePoint3d ptStart, ptEnd;
if (GetAt(KEY_START, ptStart) &&
GetAt(KEY_END, ptEnd))
{
ptStart.transformBy(xform);
ptEnd.transformBy(xform);
SetAt(KEY_START, ptStart);
SetAt(KEY_END, ptEnd);
}
AcGePoint3d ptFront;
if( GetAt(KEY_FRONT, ptFront) )
{
ptFront.transformBy(xform);
if( ptFront != ptStart )
{
SetAt(KEY_FRONT, ptFront);
}
}
return Acad::eOk;
}
Acad::ErrorStatus TDbStruSymbFocus::subGetGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
assertReadEnabled();
AcGePoint3d ptStart;
if( GetAt(KEY_START, ptStart) )
{
gripPoints.append(ptStart);
}
AcGePoint3d ptEnd;
if( GetAt(KEY_END, ptEnd) )
{
gripPoints.append(ptEnd);
}
int iLineFlag;
GetAt(KEY_LINEFLAG, iLineFlag);
if( iLineFlag == kColuLine )
{
AcGePoint3d ptMid;
Midpoint(ptStart, ptEnd, ptMid);
gripPoints.append(ptMid);
}
else if( iLineFlag == kOther )
{
AcGePoint3d ptFront;
if( GetAt(KEY_FRONT, ptFront) )
{
gripPoints.append(ptFront);
}
}
return Acad::eOk;
}
Acad::ErrorStatus TDbStruSymbFocus::subMoveGripPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertWriteEnabled();
BOOL bWallColu, bFlag;
int iLineFlag;
GetAt(KEY_LINEFLAG, iLineFlag);
GetAt(KEY_WCOLU, bWallColu);
AcGePoint3d ptStart;
GetAt(KEY_START, ptStart);
AcGePoint3d ptFront;
bool bFront = GetAt(KEY_FRONT, ptFront);
for (int i=0; i<indices.length(); i++)
{
bFlag = TRUE;
if (indices[i] == 0)
{
if( iLineFlag==kColuLine )
{// 移动起点夹点
ptStart += offset;
SetAt(KEY_START, ptStart);
}
else
{
if( bFront )
{
if( GetCtrlToggle() )
{
// 移动
AcGeMatrix3d xform;
xform.setToTranslation(offset);
subTransformBy(xform);
bFlag = FALSE;
}
else
{
ptStart += offset;
SetAt(KEY_START, ptStart);
AcGePoint3d ptEnd;
if (GetAt(KEY_END, ptEnd))
{
ptEnd += offset;
SetAt(KEY_END, ptEnd);
}
}
}
else
{
// 移动
AcGeMatrix3d xform;
xform.setToTranslation(offset);
subTransformBy(xform);
bFlag = FALSE;
}
}
}
else if( indices[i] == 1 )
{
// 移动终点夹点
AcGePoint3d ptEnd;
if (GetAt(KEY_END, ptEnd))
{
//ptEnd += offTemp;
ptEnd += offset;
AcGePoint3d ptStart;
if( ptEnd != ptStart )
{
SetAt(KEY_END, ptEnd);
}
}
}
else
{
bFlag = FALSE;
if( iLineFlag == kOther )
{
AcGePoint3d ptFront;
if( GetAt(KEY_FRONT, ptFront) )
{
ptFront += offset;
SetAt(KEY_FRONT, ptFront);
}
}
else
{
AcGeMatrix3d xform;
xform.setToTranslation(offset);
subTransformBy(xform);
}
}
if( bFlag )
{// 重新设置标注位置
if( GetAt(KEY_LINEFLAG, iLineFlag) && iLineFlag==kColuLine )
{
AcGePoint3d ptEnd;
if( GetAt(KEY_END, ptEnd) )
{
XPoint ptVec = ptEnd - ptStart;
double dAngle = ptVec.AsAcGeVector2d().angle();
if( dAngle < PI*0.5f || dAngle > PI*1.5f )
{
SetAt(KEY_ISLEFT, FALSE);
}
else
{
SetAt(KEY_ISLEFT, TRUE);
}
}
}
}
}
return Acad::eOk;
}
Acad::ErrorStatus TDbStruSymbFocus::subGetStretchPoints(AcGePoint3dArray& stretchPoints) const
{
assertReadEnabled();
AcDbIntArray osnapModes;
AcDbIntArray geomIds;
return subGetGripPoints(stretchPoints, osnapModes, geomIds);
}
Acad::ErrorStatus TDbStruSymbFocus::subMoveStretchPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertWriteEnabled();
return subMoveGripPointsAt(indices, offset);
}
Acad::ErrorStatus TDbStruSymbFocus::subGetOsnapPoints(
AcDb::OsnapMode osnapMode,
INT_PTR gsSelectionMark,
const AcGePoint3d& pickPoint,
const AcGePoint3d& lastPoint,
const AcGeMatrix3d& viewXform,
AcGePoint3dArray& snapPoints,
AcDbIntArray& geomIds) const
{
return TDbStruEntityBase::subGetOsnapPoints(osnapMode, gsSelectionMark, pickPoint, lastPoint,
viewXform, snapPoints, geomIds);
}
Acad::ErrorStatus TDbStruSymbFocus::subGetTransformedCopy(
const AcGeMatrix3d& xform,
AcDbEntity*& pEnt) const
{
return TDbStruEntityBase::subGetTransformedCopy(xform, pEnt);
}
Acad::ErrorStatus TDbStruSymbFocus::copyFrom(const AcRxObject* pSrc)
{
assertWriteEnabled();
if (pSrc->isKindOf(TDbStruSymbFocus::desc()))
{
TDbStruSymbFocus* pSymbFocus = (TDbStruSymbFocus*)pSrc;
GetSpecialtyData()->Empty();
GetSpecialtyData()->CopyFrom(pSymbFocus->GetSpecialtyData());
}
return Acad::eOk;
}
Acad::ErrorStatus TDbStruSymbFocus::subGetClassID(CLSID* pClsid) const
{
#if (ADS >= 17)
assertReadEnabled();
#endif
return Acad::eOk;
}
Acad::ErrorStatus TDbStruSymbFocus::subWblockClone(
AcRxObject* pOwner,
AcDbObject*& pClonedObject,
AcDbIdMapping& idMap,
Adesk::Boolean isPrimary) const
{
return TDbStruEntityBase::subWblockClone(pOwner, pClonedObject, idMap, isPrimary);
}
Acad::ErrorStatus TDbStruSymbFocus::subDeepClone(
AcDbObject* pOwner,
AcDbObject*& pClonedObject,
AcDbIdMapping& idMap,
Adesk::Boolean isPrimary) const
{
return TDbStruEntityBase::subDeepClone(pOwner, pClonedObject, idMap, isPrimary);
}
// 获得二维包围盒
Acad::ErrorStatus TDbStruSymbFocus::GetExtents2d(TADSGePoint3d &ptLow, TADSGePoint3d &ptUp) const
{
assertReadEnabled();
return Acad::eOk;
}
// 获得三维包围盒
Acad::ErrorStatus TDbStruSymbFocus::GetExtents(TADSGePoint3d &ptLow, TADSGePoint3d &ptUp) const
{
return Acad::eNotImplementedYet;
}
//取动态属性显示数据
void TDbStruSymbFocus::GetTips(TDPtrList<TObjInfoUnit>& lstInfo) const
{
TDbStruEntityBase::GetTips(lstInfo);
}
const TCHAR* TDbStruSymbFocus::GetDefaultLayer() const
{
return TDbStruEntityBase::GetDefaultLayer();
}
void TDbStruSymbFocus::SetSubText(long i,CString sText)
{
assertWriteEnabled();
CString sDimText, sTemp;
if( !GetAt(KEY_TEXT, sDimText) )
{
return ;
}
CStringArray arTexts;
int iPos;
while( (iPos=sDimText.Find('\n')) != -1 )
{
sTemp = sDimText.Left(iPos);
arTexts.Add(sTemp);
sDimText = sDimText.Mid(iPos+1);
}
if( !sDimText.IsEmpty() )
{
arTexts.Add(sDimText);
}
int iIndex = (int)i;
int iSize = arTexts.GetSize();
if( iIndex+1 > iSize || iIndex < 0 )
{
return ;
}
arTexts[iIndex] = sText;
sDimText = arTexts[0];
for( int j=1; j<iSize; ++j )
{
sDimText += _T("\n") + arTexts[j];
}
SetAt(KEY_TEXT, sDimText);
}
BOOL TDbStruSymbFocus::IsValid() const
{
return TRUE;
}
// 支持夹点ctrl功能切换
int TDbStruSymbFocus::GetCtrlToggleIndex()const
{
return TDbStruEntityBase::GetCtrlToggleIndex();
}
// 属性匹配
void TDbStruSymbFocus::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
{
assertWriteEnabled();
TDbStruEntityBase::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
TDbStruSymbFocus* pSrc = TDbStruSymbFocus::cast(pSrcEntity);
if (pSrc != NULL)
{
BOOL bWallColu, bShowDot;
int iLineFlag, iAlignFlag;
double dDia, dAngle, dDistRate;
CString sText;
AcGePoint3d ptStart, ptEnd, ptFront;
GetAt(KEY_TEXT, sText);
GetAt(KEY_START, ptStart);
GetAt(KEY_END, ptEnd);
GetAt(KEY_POINT_DIA, dDia);
GetAt(KEY_SHOW_DOT, bShowDot);
GetAt(KEY_LINEFLAG, iLineFlag);
GetAt(KEY_ALIGNFLAG, iAlignFlag);
GetAt(KEY_DISTRATE, dDistRate);
GetAt(KEY_WCOLU, bWallColu);
GetAt(KEY_FRONT, ptFront);
GetAt(KEY_AXANG, dAngle);
GetSpecialtyData()->Empty();
GetSpecialtyData()->CopyFrom(pSrc->GetSpecialtyData());
SetAt(KEY_TEXT, sText);
SetAt(KEY_START, ptStart);
SetAt(KEY_END, ptEnd);
SetAt(KEY_SHOW_DOT, bShowDot);
SetAt(KEY_POINT_DIA, dDia);
SetAt(KEY_LINEFLAG, iLineFlag);
SetAt(KEY_ALIGNFLAG, iAlignFlag);
SetAt(KEY_DISTRATE, dDistRate);
SetAt(KEY_WCOLU, bWallColu);
SetAt(KEY_FRONT, ptFront);
SetAt(KEY_AXANG, dAngle);
}
}
// 获得标准三维面
bool TDbStruSymbFocus::GetStandardFaceBody(AcDbVoidPtrArray& arFacePtrs) const
{
return TDbStruEntityBase::GetStandardFaceBody(arFacePtrs);
}
// 获得安全保护区
bool TDbStruSymbFocus::GetSafeProtectedSpace(AcDbVoidPtrArray& arFacePtrs) const
{
return TDbStruEntityBase::GetSafeProtectedSpace(arFacePtrs);
}
// 获得剖面
bool TDbStruSymbFocus::GetSection(const AcDbFace &face,
const AcGeVector3d& vtPlaneSecDir,
std::vector<TObjSectionRecord> &sectionRecords,
AcDbVoidPtrArray& arFillPtrs) const
{
return TDbStruEntityBase::GetSection(face, vtPlaneSecDir, sectionRecords, arFillPtrs);
}
// 获得XML
CString TDbStruSymbFocus::GetXml(const AcGeMatrix3d& mat) const
{
return TDbStruEntityBase::GetXml(mat);
}
int TDbStruSymbFocus::GetFirstVersion()const
{
return 10;
}
bool TDbStruSymbFocus::IsModelEntity() const
{
return true;
}
bool TDbStruSymbFocus::IsSimpleLineDim() const
{
assertReadEnabled();
int iLineFlag;
GetAt(KEY_LINEFLAG, iLineFlag);
if( iLineFlag != kColuLine )
{
return true;
}
return false;
}
double TDbStruSymbFocus::GetRotation() const
{
double dAngle = 0.0;
if( IsSimpleLineDim() )
{
AcGePoint3d ptStart, ptEnd;
GetAt(KEY_START, ptStart);
GetAt(KEY_END, ptEnd);
AcGeVector3d vtLine = ptEnd - ptStart;
dAngle = AngleRangeTo2PI(Wcs2Ucs(vtLine).AsAcGeVector2d().angle()-PI/2.0);
}
else
{
GetAt(KEY_AXANG, dAngle);
dAngle = AngleRangeTo2PI(dAngle);
}
return dAngle;
}
void TDbStruSymbFocus::SetRotation(double dAngle)
{
assertWriteEnabled();
if( IsSimpleLineDim() )
{
AcGePoint3d ptStart, ptEnd;
GetAt(KEY_START, ptStart);
GetAt(KEY_END, ptEnd);
AcGeVector3d vtLine = ptEnd - ptStart;
double dAngleOld = AngleRangeTo2PI(Wcs2Ucs(vtLine).AsAcGeVector2d().angle()-PI/2.0);
dAngle -= dAngleOld;
AcGeMatrix3d mat;
mat.setToRotation(dAngle, AcGeVector3d(0,0,1), ptStart);
ptEnd.transformBy(mat);
SetAt(KEY_END, ptEnd);
}
else
{
SetAt(KEY_AXANG, dAngle);
}
}
BOOL TDbStruSymbFocus::GetThirdPoint(AcGePoint3d &ptThird) const
{
assertReadEnabled();
int iLineFlag;
double dHeight;
AcDbObjectId idTextStyle;
GetAt(KEY_LINEFLAG, iLineFlag);
GetAt(KEY_TH, dHeight);
GetAt(KEY_TS, idTextStyle);
dHeight *= GetPScale();
BOOL bWallColu;
GetAt(KEY_WCOLU, bWallColu);
if( iLineFlag == kColuLine && bWallColu )
{
// 生成标注每行文本
CString sText;
GetAt(KEY_TEXT, sText);
double dLength = GetPageWidth(sText, idTextStyle, dHeight) + dHeight/3.0f;
AcGeVector3d vtTemp(1, 0, 0);
BOOL bIsLeft;
GetAt(KEY_ISLEFT, bIsLeft);
if( bIsLeft )
{
vtTemp.x = -1;
}
AcGePoint3d ptEnd;
GetAt(KEY_END, ptEnd);
ptThird = ptEnd + vtTemp.normalize()*dLength;
double dAxAng;
GetAt(KEY_AXANG, dAxAng);
AcGeMatrix3d mat;
mat.setToRotation(dAxAng, AcGeVector3d(0,0,1), ptEnd);
ptThird.transformBy(mat);
return TRUE;
}
return FALSE;
}
// 标注线
bool TDbStruSymbFocus::DrawDimLine(TGGiExplodeDrawBase& dc) const
{
AcGePoint3d ptStart;
AcGePoint3d ptEnd;
double dDia;
BOOL bShowDot;
if (!GetAt(KEY_START, ptStart) ||
!GetAt(KEY_END, ptEnd) ||
!GetAt(KEY_POINT_DIA, dDia) ||
!GetAt(KEY_SHOW_DOT, bShowDot))
{
return false;
}
AcGePoint3d ptFront, ptPos=ptStart;
AcDbPolyline poly;
int iLineFlag;
GetAt(KEY_LINEFLAG, iLineFlag);
int iIndex = 0;
if( iLineFlag==kOther &&
GetAt(KEY_FRONT, ptFront) )
{
poly.addVertexAt(iIndex++, AcGePoint2d(ptFront.x, ptFront.y));
ptPos = ptFront;
}
poly.addVertexAt(iIndex++, AcGePoint2d(ptStart.x, ptStart.y));
poly.addVertexAt(iIndex++, AcGePoint2d(ptEnd.x, ptEnd.y));
AcGePoint3d ptThird;
if( GetThirdPoint(ptThird) )
{
poly.addVertexAt(iIndex++, AcGePoint2d(ptThird.x, ptThird.y));
}
dc.DrawEntity(poly);
if( bShowDot && dDia>g_fZero )
{
// 标注线起始端圆点
TGGePoly2D polySolid;
GetSolidCircle(ptPos, dDia/2.0f*GetPScale(), polySolid);
dc << TGGeSolid(polySolid);
}
return true;
}
bool TDbStruSymbFocus::DrawDimText(TGGiExplodeDrawBase& dc) const
{
BOOL bIsLeft;
double dHeight, dDistRate;
if (!GetAt(KEY_ISLEFT, bIsLeft) ||
!GetAt(KEY_TH, dHeight) ||
!GetAt(KEY_DISTRATE, dDistRate) )
{
return false;
}
dHeight *= GetPScale();
double dInterval = dHeight * dDistRate; // 文字间距
AcDbObjectId idTextStyle;
if (!GetAt(KEY_TS, idTextStyle))
{
return false;
}
// 生成标注每行文本
CString sText, sTemp;
if( !GetAt(KEY_TEXT, sText) )
{
return false;
}
CString sTextSys = sText;
CStringArray arTexts;
int iPos;
while( (iPos=sText.Find('\n')) != -1 )
{
sTemp = sText.Left(iPos);
arTexts.Add(sTemp);
sText = sText.Mid(iPos+1);
}
if( !sText.IsEmpty() )
{
arTexts.Add(sText);
}
AcGePoint3d ptFirstLine; // 首行文本位置
AcGeVector3d vtOffsetDir; // 后续文本偏移方向
double dAngle; // 文本的倾斜角度
double dOffset = 80.0f; // 文本与标注线的偏移距离
int iSize = arTexts.GetCount();
if( iSize < 1 )
{
return false;
}
if (!GetDrawTextInfo(ptFirstLine,
vtOffsetDir,
dAngle,
bIsLeft,
dHeight,
dInterval,
iSize))
{
return false;
}
int iLineFlag;
XExplodeDraw::TextAlignment textAlig = bIsLeft ? XExplodeDraw::kTopRight : XExplodeDraw::kTopLeft;
GetAt(KEY_LINEFLAG, iLineFlag);
BOOL bWallColu, bColuDim=FALSE;
GetAt(KEY_WCOLU, bWallColu);
double dLength = 0.0f;
double dTextWidth = GetPageWidth(sTextSys, idTextStyle, dHeight, false) - dHeight/4.0;
if( !bWallColu && iLineFlag == kColuLine )
{// 柱截面标注
bColuDim = TRUE;
textAlig = XExplodeDraw::kTopLeft;
AcGePoint3d ptStart;
AcGePoint3d ptEnd;
GetAt(KEY_START, ptStart);
GetAt(KEY_END, ptEnd);
AcGeVector3d vtLine = ptEnd - ptStart;
double dView = Wcs2Ucs(vtLine).AsAcGeVector2d().angle();
AcGeVector3d vtTemp(-1, 0, 0);
if( dView-PI*0.5f>g_angleZero && dView-PI<g_angleZero )
{
dLength = CalcTextLen(arTexts[iSize-1], idTextStyle, dHeight/GetPScale());
ptFirstLine += vtTemp.normalize() * dLength;
}
else if( dView-PI>g_angleZero && dView-PI*1.5f<g_angleZero )
{
dLength = CalcTextLen(arTexts[0], idTextStyle, dHeight/GetPScale());
ptFirstLine += vtTemp.normalize() * dLength;
}
else if( dView-PI*1.5>g_angleZero && dView-PI*2.0<g_angleZero )
{
dLength = CalcTextLen(arTexts[0], idTextStyle, dHeight/GetPScale());
}
else
{
dLength = CalcTextLen(arTexts[iSize-1], idTextStyle, dHeight/GetPScale());
}
}
int iAlignFlag;
GetAt(KEY_ALIGNFLAG, iAlignFlag);
AcGeVector3d vtTemp = vtOffsetDir;
if( bIsLeft )
{
vtTemp.rotateBy(-PI/2.0, AcGeVector3d(0,0,1));
if( ALIGN_LEFT == iAlignFlag )
{
if( !bColuDim )
{
ptFirstLine += vtTemp.normalize() * dTextWidth;
}
textAlig = XExplodeDraw::kTopLeft;
}
else if( ALIGN_MID == iAlignFlag )
{
if( bColuDim )
{
ptFirstLine -= vtTemp.normalize() * dLength/2.0;
}
else
{
ptFirstLine += vtTemp.normalize() * dTextWidth/2.0;
}
textAlig = XExplodeDraw::kTopCenter;
}
else
{
ptFirstLine -= vtTemp.normalize() * dLength;
textAlig = XExplodeDraw::kTopRight;
}
}
else
{
vtTemp.rotateBy(PI/2.0, AcGeVector3d(0,0,1));
if( ALIGN_RIGHT == iAlignFlag )
{
if( bColuDim && dLength > g_fZero )
{
ptFirstLine += vtTemp.normalize() * dLength;
}
else
{
ptFirstLine += vtTemp.normalize() * dTextWidth;
}
textAlig = XExplodeDraw::kTopRight;
}
else if( ALIGN_MID == iAlignFlag )
{
if( bColuDim && dLength > g_fZero )
{
ptFirstLine += vtTemp.normalize() * dLength/2.0;
}
else
{
ptFirstLine += vtTemp.normalize() * dTextWidth/2.0;
}
textAlig = XExplodeDraw::kTopCenter;
}
else
{
textAlig = XExplodeDraw::kTopLeft;
}
}
double dAxAng(0);
if( !IsSimpleLineDim() )
{
GetAt(KEY_AXANG, dAxAng);
}
AcGeMatrix3d mat;
AcGePoint3d ptEnd;
GetAt(KEY_END, ptEnd);
mat.setToRotation(dAxAng, AcGeVector3d(0,0,1), ptEnd);
TDbText text;
text.setPropertiesFrom(this);
TPushProperty vProp(&text, dc);
for (int i=0; i<iSize; i++)
{
text.SetStyleId(idTextStyle);
text.SetLocation(ptFirstLine + vtOffsetDir.normalize() * i * (dHeight + dInterval));
text.SetAlignment(textAlig);
text.SetText(arTexts[i]);
text.SetHeight(dHeight, FALSE);
text.SetRotation(dAngle);
text.transformBy(mat);
if (dc.IsFullExplode())
text.ExplodeOrDraw2d(dc);
else
dc.DrawEntity(text);
}
return true;
}
// 获取文本行数
int TDbStruSymbFocus::GetRowsNums() const
{
int iIndex;
int iRows = 5;
if (!GetAt(KEY_KIND, iIndex))
{
return iRows;
}
switch (iIndex)
{
case 1: // 三行显示
iRows = 3;
break;
case 2: // 四行显示
iRows = 4;
break;
case 3: // 五行显示
{
CString sHeightDiff;
if (GetAt(KEY_HEIGHTDIFF, sHeightDiff) &&
sHeightDiff.IsEmpty())
{
iRows = 4;
}
}
break;
case 0: // 自动分行
default:
iRows = 8;
break;
}
return iRows;
}
// 获取绘制文本需要的信息
bool TDbStruSymbFocus::GetDrawTextInfo(AcGePoint3d& ptFirstLine, // 首行文本位置
AcGeVector3d& vtOffsetDir, // 后续文本偏移方向
double& dAngle, // 文本的倾斜角度
BOOL bIsLeft,
double dHeight,
double dInterval,
int iRows) const
{
// 标注线起点到终点的方向向量
AcGePoint3d ptStart;
AcGePoint3d ptEnd;
if (!GetAt(KEY_START, ptStart) ||
!GetAt(KEY_END, ptEnd))
{
return false;
}
AcGeVector3d vtLine = ptEnd - ptStart;
double dView = Wcs2Ucs(vtLine).AsAcGeVector2d().angle();
int iLineFlag;
GetAt(KEY_LINEFLAG, iLineFlag);
double dOffset = dHeight / 4.0f; // 文本与标注线的偏移距离
bool bUp = false;
// 文本的倾斜角度保证始终小于90度,
if (dView>g_angleZero && dView-PI < g_angleZero) // angle > 0 && angle <= PI
{
bUp = true;
if( iLineFlag == kColuLine )
{
vtLine.set(0, 1.0f, 0);
}
// 文本的倾斜角度
dAngle = AcGeVector2d(vtLine.x, vtLine.y).angle() - PI / 2.0f;
AcGeVector3d vtTemp = vtLine;
if (bIsLeft)
{
vtTemp.rotateBy(PI / 2.0f, AcGeVector3d(0, 0, 1));
}
else
{
vtTemp.rotateBy(-PI / 2.0f, AcGeVector3d(0, 0, 1));
}
// 首行文本位置
ptFirstLine = ptEnd + vtTemp.normalize() * (bIsLeft ? (dOffset * 2) : dOffset);
// 后续文本相对于首行文本位置的偏移方向
vtOffsetDir = vtLine;
vtOffsetDir.rotateBy(PI, AcGeVector3d(0, 0, 1));
}
else
{
if( iLineFlag == kColuLine )
{
vtLine.set(0, -1.0f, 0);
}
// 文本的倾斜角度
dAngle = AcGeVector2d(vtLine.x, vtLine.y).angle() - PI / 2.0f * 3.0f;
// 后续文本偏移方向
vtOffsetDir = vtLine;
AcGeVector3d vtTemp = vtLine;
if (bIsLeft)
{
vtTemp.rotateBy(-PI / 2.0f, AcGeVector3d(0, 0, 1));
// 首行文本位置
ptFirstLine = ptEnd + vtTemp.normalize() * (bIsLeft ? (dOffset * 2) : dOffset);
vtTemp.rotateBy(-PI / 2.0f, AcGeVector3d(0, 0, 1));
ptFirstLine = ptFirstLine + vtTemp.normalize() *
((iRows - 1) * dInterval + iRows * dHeight);
}
else
{
vtTemp.rotateBy(PI / 2.0f, AcGeVector3d(0, 0, 1));
// 首行文本位置
ptFirstLine = ptEnd + vtTemp.normalize() * (bIsLeft ? (dOffset * 2) : dOffset);
vtTemp.rotateBy(PI / 2.0f, AcGeVector3d(0, 0, 1));
ptFirstLine = ptFirstLine + vtTemp.normalize() *
((iRows - 1) * dInterval + iRows * dHeight);
}
}
if( iLineFlag == kColuLine )
{
ptFirstLine += vtLine.normalize() * ((iRows-1) * dInterval + iRows * dHeight);
BOOL bWallColu;
if( GetAt(KEY_WCOLU, bWallColu) && bWallColu )
{
if( bUp )
{
ptFirstLine += vtLine.normalize() * dInterval;
}
else
{
ptFirstLine += vtLine.normalize() * dInterval/2.0f;
}
}
dAngle = 0.0f;
if( dView-PI*0.5f>g_angleZero && dView-PI*1.5f<g_angleZero )
{
AcGeVector3d vtTemp(-1, 0, 0);
}
}
return true;
}
void TDbStruSymbFocus::GetSolidCircle(AcGePoint3d ptCenter,
double dRadius,
TGGePoly2D& plCircle) const
{
AcGePoint3d ptSolid1(ptCenter[X]-dRadius, ptCenter[Y], 0);
AcGePoint3d ptSolid2(ptCenter[X]+dRadius, ptCenter[Y], 0);
TGGePoly2D poly;
poly.InsertNodeAt(0, ptSolid1, PI);
poly.InsertNodeAt(1, ptSolid2, PI);
poly.InsertNodeAt(2, ptSolid1);
poly.SetClosed();
poly.Disperse(plCircle);
}
void InitDbStruSymbFocus(BOOL bInit)
{
if (bInit)
{
TDbStruSymbFocus::rxInit();
acrxBuildClassHierarchy();
TDbStruSymbFocus::InitMatchProtocol(TRUE);
}
else
{
TDbStruSymbFocus::InitMatchProtocol(FALSE);
deleteAcRxClass(TDbStruSymbFocus::desc());
}
}
#endif