582 lines
13 KiB
C++
582 lines
13 KiB
C++
//------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2012, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TDbStruSymbInsitu.cpp
|
|
// = Version : ver1.0
|
|
// = Author : zyc
|
|
// = CreateDate : 2012-07-11
|
|
// = Description: 原位标注实体类定义
|
|
// = Maintainers:
|
|
//
|
|
//------------------------------------------------------------------------+
|
|
|
|
#include "stdafx.h"
|
|
#ifdef TASD
|
|
#include "TDbStruSymbInsitu.h"
|
|
#include "TAsdKeyDefine.h"
|
|
|
|
#define ALIGN_LEFT 0
|
|
#define ALIGN_RIGHT 1
|
|
#define ALIGN_MID 2
|
|
|
|
extern double GetPageWidth( const CString &sText, const AcDbObjectId &styleId, double dTextHeight, bool AutoAdjust=true );
|
|
|
|
#define KEY_ADDSIZE _T("ASize") // 加腋尺寸 CString
|
|
|
|
const Adesk::UInt8 TDbStruSymbInsitu::g_nVersion = 1;
|
|
|
|
IMPLEMENT_TENTBASE(TDbStruSymbInsitu);
|
|
ACRX_DXF_DEFINE_MEMBERS(TDbStruSymbInsitu, TDbStruEntityBase, AcDb::kDHL_CURRENT,
|
|
AcDb::kMReleaseCurrent, 1, ATS_STRUSYMBINSITU,
|
|
"ATS_STRUSYMBINSITU图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
|
|
|
|
TDbStruSymbInsitu::TDbStruSymbInsitu()
|
|
{
|
|
SetAt(KEY_TH, 3.5);
|
|
SetAt(KEY_DISTRATE, 0.4);
|
|
SetAt(KEY_TS, InitTextStyle(TS_STANDARD));
|
|
SetAt(KEY_ALIGNFLAG, ALIGN_LEFT);
|
|
SetAt(KEY_MASK, 0);
|
|
}
|
|
|
|
TDbStruSymbInsitu::~TDbStruSymbInsitu()
|
|
{
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSymbInsitu::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 TDbStruSymbInsitu::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 TDbStruSymbInsitu::dxfInFields (AcDbDxfFiler* pFiler)
|
|
{
|
|
assertWriteEnabled();
|
|
return TDbStruEntityBase::dxfInFields(pFiler);
|
|
}
|
|
Acad::ErrorStatus TDbStruSymbInsitu::dxfOutFields(AcDbDxfFiler* pFiler) const
|
|
{
|
|
assertReadEnabled();
|
|
return TDbStruEntityBase::dxfOutFields(pFiler);
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSymbInsitu::GetGripText(int i, CString &cs) const
|
|
{
|
|
cs = _T("移动标注对象");
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSymbInsitu::ExplodeOrDraw2d(TGGiExplodeDrawBase &dc) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
// 标注文本
|
|
DrawDimText(dc);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSymbInsitu::ExplodeOrDraw3d(TGGiExplodeDrawBase &dc) const
|
|
{
|
|
return Acad::eNotImplementedYet;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSymbInsitu::subTransformBy(const AcGeMatrix3d& xform)
|
|
{
|
|
assertWriteEnabled();
|
|
AcGePoint3d ptPos;
|
|
AcGeVector3d vtDir;
|
|
if (GetAt(KEY_POS, ptPos) &&
|
|
GetAt(KEY_DIR, vtDir))
|
|
{
|
|
ptPos.transformBy(xform);
|
|
vtDir.transformBy(xform);
|
|
SetAt(KEY_POS, ptPos);
|
|
SetAt(KEY_DIR, vtDir);
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSymbInsitu::subGetGripPoints(AcGePoint3dArray& gripPoints,
|
|
AcDbIntArray& osnapModes,
|
|
AcDbIntArray& geomIds) const
|
|
{
|
|
assertReadEnabled();
|
|
AcGePoint3d ptPos;
|
|
if (GetAt(KEY_POS, ptPos))
|
|
{
|
|
gripPoints.append(ptPos);
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSymbInsitu::subMoveGripPointsAt(const AcDbIntArray& indices,
|
|
const AcGeVector3d& offset)
|
|
{
|
|
assertWriteEnabled();
|
|
for (int i=0; i<indices.length(); i++)
|
|
{
|
|
// 移动
|
|
AcGeMatrix3d xform;
|
|
xform.setToTranslation(offset);
|
|
subTransformBy(xform);
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSymbInsitu::subGetStretchPoints(AcGePoint3dArray& stretchPoints) const
|
|
{
|
|
return TDbStruEntityBase::subGetStretchPoints(stretchPoints);
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSymbInsitu::subMoveStretchPointsAt(const AcDbIntArray& indices,
|
|
const AcGeVector3d& offset)
|
|
{
|
|
return subMoveGripPointsAt(indices, offset);
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSymbInsitu::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 TDbStruSymbInsitu::subGetTransformedCopy(
|
|
const AcGeMatrix3d& xform,
|
|
AcDbEntity*& pEnt) const
|
|
{
|
|
return TDbStruEntityBase::subGetTransformedCopy(xform, pEnt);
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSymbInsitu::copyFrom(const AcRxObject* pSrc)
|
|
{
|
|
assertWriteEnabled();
|
|
if (pSrc->isKindOf(TDbStruSymbInsitu::desc()))
|
|
{
|
|
TDbStruSymbInsitu* pSymbInsitu = (TDbStruSymbInsitu*)pSrc;
|
|
GetSpecialtyData()->Empty();
|
|
GetSpecialtyData()->CopyFrom(pSymbInsitu->GetSpecialtyData());
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSymbInsitu::subGetClassID(CLSID* pClsid) const
|
|
{
|
|
#if (ADS >= 17)
|
|
assertReadEnabled();
|
|
#endif
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSymbInsitu::subWblockClone(
|
|
AcRxObject* pOwner,
|
|
AcDbObject*& pClonedObject,
|
|
AcDbIdMapping& idMap,
|
|
Adesk::Boolean isPrimary) const
|
|
{
|
|
return TDbStruEntityBase::subWblockClone(pOwner, pClonedObject, idMap, isPrimary);
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSymbInsitu::subDeepClone(
|
|
AcDbObject* pOwner,
|
|
AcDbObject*& pClonedObject,
|
|
AcDbIdMapping& idMap,
|
|
Adesk::Boolean isPrimary) const
|
|
{
|
|
return TDbStruEntityBase::subDeepClone(pOwner, pClonedObject, idMap, isPrimary);
|
|
}
|
|
|
|
// 获得二维包围盒
|
|
Acad::ErrorStatus TDbStruSymbInsitu::GetExtents2d(TADSGePoint3d &ptLow, TADSGePoint3d &ptUp) const
|
|
{
|
|
assertReadEnabled();
|
|
// 字高、行间距
|
|
double dTextHeight, dDistRate;
|
|
AcGePoint3d ptPos;
|
|
AcGeVector3d vtTextDir; // 文本的偏移方向
|
|
CString sText;
|
|
if (GetAt(KEY_TH, dTextHeight) &&
|
|
GetAt(KEY_DISTRATE, dDistRate) &&
|
|
GetAt(KEY_POS, ptPos) &&
|
|
GetAt(KEY_DIR, vtTextDir) &&
|
|
GetAt(KEY_TEXT, sText) )
|
|
{
|
|
CString sTemp;
|
|
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);
|
|
}
|
|
|
|
// 文本最长字符个数
|
|
double dCharNums = 0;
|
|
for (int i=0; i<arTexts.GetSize(); i++)
|
|
{
|
|
if (dCharNums < arTexts[i].GetLength())
|
|
{
|
|
dCharNums = arTexts[i].GetLength();
|
|
}
|
|
}
|
|
|
|
double dSpace = dDistRate*dTextHeight;
|
|
dTextHeight *= GetPScale();
|
|
ptLow = ptPos + vtTextDir.normalize() *
|
|
arTexts.GetSize() * (dTextHeight + dSpace);
|
|
ptUp = ptPos + vtTextDir.rotateBy(PI / 2.0f, AcGeVector3d(0, 0, 1)).normalize() *
|
|
dTextHeight / 3.0f * 2.0f * dCharNums;
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
// 获得三维包围盒
|
|
Acad::ErrorStatus TDbStruSymbInsitu::GetExtents(TADSGePoint3d &ptLow, TADSGePoint3d &ptUp) const
|
|
{
|
|
return Acad::eNotImplementedYet;
|
|
}
|
|
|
|
// 取动态属性显示数据
|
|
void TDbStruSymbInsitu::GetTips(TDPtrList<TObjInfoUnit>& lstInfo) const
|
|
{
|
|
TDbStruEntityBase::GetTips(lstInfo);
|
|
}
|
|
|
|
const TCHAR* TDbStruSymbInsitu::GetDefaultLayer() const
|
|
{
|
|
return TDbStruEntityBase::GetDefaultLayer();
|
|
}
|
|
|
|
void TDbStruSymbInsitu::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 TDbStruSymbInsitu::IsValid() const
|
|
{
|
|
return TRUE;
|
|
}
|
|
|
|
// 支持夹点ctrl功能切换
|
|
int TDbStruSymbInsitu::GetCtrlToggleIndex()const
|
|
{
|
|
return TDbStruEntityBase::GetCtrlToggleIndex();
|
|
}
|
|
|
|
// 属性匹配
|
|
void TDbStruSymbInsitu::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
|
|
{
|
|
assertWriteEnabled();
|
|
|
|
TDbStruEntityBase::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
|
|
TDbStruSymbInsitu* pSrc = TDbStruSymbInsitu::cast(pSrcEntity);
|
|
if (pSrc != NULL)
|
|
{
|
|
CString sDimText;
|
|
AcGePoint3d ptPos;
|
|
AcGeVector3d vtDir;
|
|
double dDistRate;
|
|
int iAlignFlag, iMaskFlag;
|
|
GetAt(KEY_TEXT, sDimText);
|
|
GetAt(KEY_POS, ptPos);
|
|
GetAt(KEY_DIR, vtDir);
|
|
GetAt(KEY_DISTRATE, dDistRate);
|
|
GetAt(KEY_ALIGNFLAG, iAlignFlag);
|
|
GetAt(KEY_MASK, iMaskFlag);
|
|
GetSpecialtyData()->Empty();
|
|
GetSpecialtyData()->CopyFrom(pSrc->GetSpecialtyData());
|
|
SetAt(KEY_TEXT, sDimText);
|
|
SetAt(KEY_POS, ptPos);
|
|
SetAt(KEY_DIR, vtDir);
|
|
SetAt(KEY_DISTRATE, dDistRate);
|
|
SetAt(KEY_ALIGNFLAG, iAlignFlag);
|
|
SetAt(KEY_MASK, iMaskFlag);
|
|
}
|
|
}
|
|
|
|
// 获得标准三维面
|
|
bool TDbStruSymbInsitu::GetStandardFaceBody(AcDbVoidPtrArray& arFacePtrs) const
|
|
{
|
|
return TDbStruEntityBase::GetStandardFaceBody(arFacePtrs);
|
|
}
|
|
|
|
// 获得安全保护区
|
|
bool TDbStruSymbInsitu::GetSafeProtectedSpace(AcDbVoidPtrArray& arFacePtrs) const
|
|
{
|
|
return TDbStruEntityBase::GetSafeProtectedSpace(arFacePtrs);
|
|
}
|
|
|
|
// 获得剖面
|
|
bool TDbStruSymbInsitu::GetSection(const AcDbFace &face,
|
|
const AcGeVector3d& vtPlaneSecDir,
|
|
std::vector<TObjSectionRecord> §ionRecords,
|
|
AcDbVoidPtrArray& arFillPtrs) const
|
|
{
|
|
return TDbStruEntityBase::GetSection(face, vtPlaneSecDir, sectionRecords, arFillPtrs);
|
|
}
|
|
|
|
// 获得XML
|
|
CString TDbStruSymbInsitu::GetXml(const AcGeMatrix3d& mat) const
|
|
{
|
|
return TDbStruEntityBase::GetXml(mat);
|
|
}
|
|
|
|
int TDbStruSymbInsitu::GetDimRows()
|
|
{
|
|
int iRows = 0;
|
|
CString sVerBar, sStirrup, sMidBar;
|
|
CString sSecSize, sTopSurElev, sHaunch;
|
|
if (GetAt(KEY_VERBAR, sVerBar) && !sVerBar.IsEmpty()){
|
|
++iRows;
|
|
}
|
|
if (GetAt(KEY_STIRRUP, sStirrup) && !sStirrup.IsEmpty()){
|
|
++iRows;
|
|
}
|
|
if (GetAt(KEY_MIDDLEBAR, sMidBar) && !sMidBar.IsEmpty()){
|
|
++iRows;
|
|
}
|
|
if (GetAt(KEY_SECSIZE, sSecSize) && !sSecSize.IsEmpty()){
|
|
++iRows;
|
|
}
|
|
if (GetAt(KEY_HEIGHTDIFF, sTopSurElev) && !sTopSurElev.IsEmpty()){
|
|
++iRows;
|
|
}
|
|
if (GetAt(KEY_ADDSIZE, sHaunch) && !sHaunch.IsEmpty()){
|
|
++iRows;
|
|
}
|
|
|
|
return iRows;
|
|
}
|
|
|
|
bool TDbStruSymbInsitu::DrawDimText(TGGiExplodeDrawBase& dc) const
|
|
{
|
|
double dHeight, dDistRate;
|
|
AcDbObjectId idTextStyle;
|
|
AcGePoint3d ptPos;
|
|
AcGeVector3d vtOffsetDir; // 后续文本偏移方向
|
|
double dAngle;
|
|
if (!GetAt(KEY_TH, dHeight) ||
|
|
!GetAt(KEY_DISTRATE, dDistRate) ||
|
|
!GetAt(KEY_TS, idTextStyle) ||
|
|
!GetAt(KEY_POS, ptPos) ||
|
|
!GetTextDir(vtOffsetDir) ||
|
|
!GetTextAngle(dAngle) )
|
|
{
|
|
return false;
|
|
}
|
|
|
|
dHeight *= GetPScale();
|
|
// 生成标注每行文本
|
|
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);
|
|
}
|
|
|
|
int iAlignFlag;
|
|
GetAt(KEY_ALIGNFLAG, iAlignFlag);
|
|
double dTextWidth = GetPageWidth(sTextSys, idTextStyle, dHeight, false) - dHeight/4.0;
|
|
TGGiExplodeDrawBase::TextAlignment textAlign = TGGiExplodeDrawBase::kTopLeft;
|
|
AcGeVector3d vtTemp = vtOffsetDir;
|
|
vtTemp.rotateBy(PI/2.0, AcGeVector3d(0,0,1));
|
|
if( iAlignFlag == ALIGN_RIGHT )
|
|
{
|
|
ptPos += vtTemp.normalize() * dTextWidth;
|
|
textAlign = TGGiExplodeDrawBase::kTopRight;
|
|
}
|
|
else if( iAlignFlag == ALIGN_MID )
|
|
{
|
|
ptPos += vtTemp.normalize() * dTextWidth/2.0;
|
|
textAlign = TGGiExplodeDrawBase::kTopCenter;
|
|
}
|
|
|
|
int iMaskFlag;
|
|
GetAt(KEY_MASK, iMaskFlag);
|
|
// 绘制标注
|
|
TDbText text;
|
|
text.setPropertiesFrom(this);
|
|
TPushProperty vProp(&text, dc);
|
|
double dInterval = dDistRate * dHeight;
|
|
for (int i=0; i<arTexts.GetCount(); i++)
|
|
{
|
|
text.SetMaskFlag(iMaskFlag);
|
|
text.SetStyleId(idTextStyle);
|
|
text.SetLocation(ptPos + vtOffsetDir.normalize() * i * (dHeight + dInterval));
|
|
text.SetAlignment(textAlign);
|
|
text.SetText(arTexts[i]);
|
|
text.SetHeight(dHeight, FALSE);
|
|
text.SetRotation(dAngle);
|
|
|
|
if (dc.IsFullExplode())
|
|
text.ExplodeOrDraw2d(dc);
|
|
else
|
|
dc.DrawEntity(text);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// 后续文本相对首行的偏移方向
|
|
bool TDbStruSymbInsitu::GetTextDir(AcGeVector3d& vtDir) const
|
|
{
|
|
AcGeVector3d vtLine;
|
|
if (!GetAt(KEY_DIR, vtLine))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (Wcs2Ucs(vtLine).AsAcGeVector2d().angle() - g_angleZero/2.0f > 0 && // angle > 0
|
|
!(Wcs2Ucs(vtLine).AsAcGeVector2d().angle() - PI > g_angleZero/2.0f)) // angle <= PI
|
|
{
|
|
vtDir = vtLine;
|
|
vtDir.rotateBy(PI, AcGeVector3d(0, 0, 1));
|
|
}
|
|
else
|
|
{
|
|
vtDir = vtLine;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
double TDbStruSymbInsitu::GetAngle() const
|
|
{
|
|
double dAngle(0);
|
|
if( GetTextAngle(dAngle) )
|
|
{
|
|
dAngle = AngleRangeTo2PI(dAngle);
|
|
if( dAngle - PI/2.0f > g_fZero )
|
|
{
|
|
dAngle -= PI;
|
|
}
|
|
}
|
|
|
|
return dAngle;
|
|
}
|
|
|
|
// 文本的倾斜角度
|
|
bool TDbStruSymbInsitu::GetTextAngle(double& dAngle) const
|
|
{
|
|
AcGeVector3d vtLine;
|
|
if (!GetAt(KEY_DIR, vtLine))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
double dTemp = Wcs2Ucs(vtLine).AsAcGeVector2d().angle();
|
|
if ( dTemp > g_angleZero && dTemp-PI < -g_angleZero ) // 0 < dTemp <= PI
|
|
{
|
|
dAngle = AcGeVector2d(vtLine.x, vtLine.y).angle() - PI / 2.0f;
|
|
}
|
|
else
|
|
{
|
|
dAngle = AcGeVector2d(vtLine.x, vtLine.y).angle() - PI / 2.0f * 3.0f;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
int TDbStruSymbInsitu::GetFirstVersion()const
|
|
{
|
|
return 10;
|
|
}
|
|
bool TDbStruSymbInsitu::IsModelEntity() const
|
|
{
|
|
return true;
|
|
}
|
|
|
|
void InitDbStruSymbInsitu(BOOL bInit)
|
|
{
|
|
if (bInit)
|
|
{
|
|
TDbStruSymbInsitu::rxInit();
|
|
acrxBuildClassHierarchy();
|
|
}
|
|
else
|
|
{
|
|
deleteAcRxClass(TDbStruSymbInsitu::desc());
|
|
}
|
|
}
|
|
#endif |