567 lines
13 KiB
C++
567 lines
13 KiB
C++
//------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2012, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TDbStruSelfBase.cpp
|
|
// = Version : ver1.0
|
|
// = Author : zyc
|
|
// = CreateDate : 2012-11-05
|
|
// = Description: 独立基础平面图类定义
|
|
// = Maintainers:
|
|
//
|
|
//------------------------------------------------------------------------+
|
|
#include "stdafx.h"
|
|
#ifdef TASD
|
|
#include "TDbStruSelfBase.h"
|
|
#include "TAsdKeyDefine.h"
|
|
#include "TConfigInfo.h"
|
|
#include "TDbStruBeam.h"
|
|
|
|
const Adesk::UInt8 TDbStruSelfBase::g_nVersion = 1;
|
|
ACRX_DXF_DEFINE_MEMBERS(ATSStruSelfBase, ATSStruEntityBase, AcDb::kDHL_CURRENT,
|
|
AcDb::kMReleaseCurrent, 1, ATS_STRUSELFBASE,
|
|
"ATS_STRUSELFBASE图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
|
|
IMPLEMENT_TENTBASE(TDbStruSelfBase);
|
|
|
|
TDbStruSelfBase::TDbStruSelfBase()
|
|
{
|
|
SetAt(KEY_H2, 0.0);
|
|
SetAt(KEY_SECTYP, ST_RECT);
|
|
SetAt(KEY_AXANG, 0.0);
|
|
SetAt(KEY_INSPTX, 0.0);
|
|
SetAt(KEY_INSPTY, 0.0);
|
|
m_arAssocBeamIds.setLogicalLength(0);
|
|
}
|
|
|
|
TDbStruSelfBase::~TDbStruSelfBase()
|
|
{
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSelfBase::dwgInFields(AcDbDwgFiler* pFiler)
|
|
{
|
|
assertWriteEnabled();
|
|
Acad::ErrorStatus es = TDbStruEntityBase::dwgInFields(pFiler);
|
|
if (es != Acad::eOk)
|
|
{
|
|
return es;
|
|
}
|
|
Adesk::UInt8 nVer;
|
|
pFiler->readUInt8(&nVer);
|
|
if (nVer > g_nVersion)
|
|
{
|
|
return Acad::eMakeMeProxy;
|
|
}
|
|
ReadPoly2D(pFiler, m_polyOutline);
|
|
|
|
// xy平面关联对象ID数组
|
|
Adesk::UInt8 nCount = 0;
|
|
pFiler->readItem(&nCount);
|
|
AcDbSoftPointerId id;
|
|
m_arAssocBeamIds.setLogicalLength(0);
|
|
for(Adesk::UInt8 i = 0; i < nCount; i++)
|
|
{
|
|
pFiler->readItem(&id);
|
|
m_arAssocBeamIds.append(id);
|
|
}
|
|
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSelfBase::dwgOutFields(AcDbDwgFiler* pFiler) const
|
|
{
|
|
assertReadEnabled();
|
|
Acad::ErrorStatus es = TDbStruEntityBase::dwgOutFields(pFiler);
|
|
if (es != Acad::eOk)
|
|
{
|
|
return es;
|
|
}
|
|
pFiler->writeUInt8(g_nVersion);
|
|
WritePoly2D(pFiler, m_polyOutline);
|
|
|
|
// 关联梁对象ID数组
|
|
Adesk::UInt8 nCount=(Adesk::UInt8)m_arAssocBeamIds.length();
|
|
pFiler->writeItem(nCount);
|
|
for (Adesk::UInt8 i = 0; i < nCount; i++)
|
|
{
|
|
pFiler->writeItem(AcDbSoftPointerId(m_arAssocBeamIds[i]));
|
|
}
|
|
|
|
return pFiler->filerStatus();
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSelfBase::subTransformBy(const AcGeMatrix3d& xform)
|
|
{
|
|
assertWriteEnabled();
|
|
|
|
// 基点
|
|
double dInsPtX, dInsPtY;
|
|
AcGePoint3d ptBase;
|
|
AcGePoint3d ptInsert;
|
|
GetAt(KEY_POS, ptInsert);
|
|
GetAt(KEY_INSPTX, dInsPtX);
|
|
GetAt(KEY_INSPTY, dInsPtY);
|
|
ptInsert = Wcs2Ucs(ptInsert).AsAcGePoint3d();
|
|
ptBase.x = ptInsert.x - dInsPtX;
|
|
ptBase.y = ptInsert.y - dInsPtY;
|
|
|
|
m_polyOutline.TransformBy(xform);
|
|
|
|
// 截面类型
|
|
int iSecType;
|
|
GetAt(KEY_SECTYP, iSecType);
|
|
switch (iSecType)
|
|
{
|
|
case ST_RECT:
|
|
UpdateInfoFromOutlineRect();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
GetAt(KEY_POS, ptInsert);
|
|
ptInsert = Wcs2Ucs(ptInsert).AsAcGePoint3d();
|
|
dInsPtX = ptInsert.x - ptBase.x;
|
|
dInsPtY = ptInsert.y - ptBase.y;
|
|
SetAt(KEY_INSPTX, dInsPtX);
|
|
SetAt(KEY_INSPTY, dInsPtY);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
// 根据轮廓线获取实体数据:插入点、宽、高,矩形
|
|
void TDbStruSelfBase::UpdateInfoFromOutlineRect()
|
|
{
|
|
if (m_polyOutline.Length() < 4)
|
|
{
|
|
return;
|
|
}
|
|
TADSGePoint3d *pt1, *pt2, *pt3;
|
|
pt1 = m_polyOutline.GetPointListAt(0); // 左下角
|
|
pt2 = m_polyOutline.GetPointListAt(1); // 右下角
|
|
pt3 = m_polyOutline.GetPointListAt(2); // 右上角
|
|
TADSGePoint3d ptInsert;
|
|
Midpoint((*pt1), (*pt3), ptInsert); // 对角线中点,即轮廓线中点
|
|
SetAt(KEY_POS, ptInsert.AsAcGePoint3d());
|
|
SetAt(KEY_B, pt1->Distance2d(*pt2));
|
|
SetAt(KEY_H, pt2->Distance2d(*pt3));
|
|
|
|
TADSGePoint3d vtPt1ToPt2 = *pt2 - *pt1;
|
|
SetAt(KEY_AXANG, vtPt1ToPt2.AsAcGeVector2d().angle());
|
|
}
|
|
|
|
// 根据实体数据生成轮廓线,矩形
|
|
void TDbStruSelfBase::UpdateInfoToOutlineRect()
|
|
{
|
|
m_polyOutline.Reset();
|
|
|
|
AcGePoint3d ptInsert;
|
|
double dB, dH, dAngle;
|
|
if (!GetAt(KEY_POS, ptInsert) ||
|
|
!GetAt(KEY_B, dB) ||
|
|
!GetAt(KEY_H, dH) ||
|
|
!GetAt(KEY_AXANG, dAngle))
|
|
{
|
|
return;
|
|
}
|
|
|
|
TADSGePoint3d ptIns = ptInsert;
|
|
|
|
double dRight = ptIns.x + dB / 2.0;
|
|
double dLeft = ptIns.x - dB / 2.0;
|
|
double dTop = ptIns.y + dH / 2.0;
|
|
double dBottom = ptIns.y - dH / 2.0;
|
|
|
|
m_polyOutline.InsertNodeAt(0, TADSGePoint3d(dLeft, dBottom, 0));
|
|
m_polyOutline.InsertNodeAt(1, TADSGePoint3d(dRight, dBottom, 0));
|
|
m_polyOutline.InsertNodeAt(2, TADSGePoint3d(dRight, dTop, 0));
|
|
m_polyOutline.InsertNodeAt(3, TADSGePoint3d(dLeft, dTop, 0));
|
|
m_polyOutline.SetClosed();
|
|
|
|
AcGeMatrix3d xform;
|
|
xform.setToRotation(dAngle, AcGeVector3d(0, 0, 1), ptInsert);
|
|
m_polyOutline.TransformBy(xform);
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSelfBase::subGetGripPoints(AcGePoint3dArray &gripPoints,
|
|
AcDbIntArray &osnapModes,
|
|
AcDbIntArray &geomIds) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
// 插入点
|
|
AcGePoint3d ptInsert;
|
|
GetAt(KEY_POS, ptInsert);
|
|
gripPoints.append(ptInsert);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSelfBase::subGetStretchPoints(AcGePoint3dArray& stretchPoints) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
AcDbIntArray osnapModes, geomIds;
|
|
return subGetGripPoints(stretchPoints, osnapModes, geomIds);
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSelfBase::subMoveGripPointsAt(const AcDbIntArray &indices,
|
|
const AcGeVector3d &offset)
|
|
{
|
|
if (GetCtrlToggle())
|
|
{
|
|
// 移动基础
|
|
AcGeMatrix3d xform;
|
|
xform.setToTranslation(offset);
|
|
subTransformBy(xform);
|
|
}
|
|
else
|
|
{
|
|
// 中心旋转
|
|
AcGePoint3d ptInsert;
|
|
GetAt(KEY_POS, ptInsert);
|
|
|
|
TADSGePoint3d temp(offset);
|
|
double dAngle = Wcs2Ucs(temp.AsAcGeVector2d().angle()); // 旋转角度
|
|
|
|
AcGeMatrix3d xform;
|
|
xform.setToRotation(dAngle, AcGeVector3d(0, 0, 1), ptInsert);
|
|
subTransformBy(xform);
|
|
}
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSelfBase::subMoveStretchPointsAt(const AcDbIntArray &indices,
|
|
const AcGeVector3d &offset)
|
|
{
|
|
assertWriteEnabled();
|
|
return subMoveGripPointsAt(indices, offset);
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSelfBase::subGetClassID(CLSID* pClsid) const
|
|
{
|
|
#if (ADS >= 17)
|
|
assertReadEnabled();
|
|
#endif
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSelfBase::GetGripText(int i, CString &cs) const
|
|
{
|
|
if (GetCtrlToggle())
|
|
{
|
|
cs = _T("移动(Ctrl-中心旋转)");
|
|
}
|
|
else
|
|
{
|
|
cs = _T("中心旋转(Ctrl-移动)");
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSelfBase::ExplodeOrDraw2d(TGGiExplodeDrawBase &dc) const
|
|
{
|
|
assertReadEnabled();
|
|
|
|
if (m_polyOutline.Length() < 1)
|
|
{
|
|
return Acad::eOk;
|
|
}
|
|
|
|
int i = 0;
|
|
long iClipCount = 0; //特殊裁剪边界计数
|
|
//地梁裁剪边界
|
|
TGGePoly2D poly;
|
|
for (i = 0; i < m_arAssocBeamIds.length(); i++)
|
|
{
|
|
OPENOBJ_BEGIN(m_arAssocBeamIds[i], AcDb::kForRead, TDbStruBeam, pEnt);
|
|
if (pEnt)
|
|
{
|
|
pEnt->GetPoly2D(poly);
|
|
poly.SetElevation(0);
|
|
|
|
dc.PushClip(poly);
|
|
iClipCount++;
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
//AcDbPolyline outline;
|
|
//outline.setClosed(Adesk::kTrue);
|
|
//outline.setNormal(AcGeVector3d(0, 0, 1));
|
|
//for (i = 0; i < m_polyOutline.Length(); ++i)
|
|
//{
|
|
// outline.addVertexAt(i, m_polyOutline.GetPointListAt(i).AsAcGePoint2d());
|
|
//}
|
|
//dc.DrawEntity(outline);
|
|
TGGePoly2D outline = m_polyOutline;
|
|
outline.SetElevation(0);
|
|
dc << outline;
|
|
|
|
// 填充
|
|
//int nHatchType = 0;
|
|
//GetAt(KEY_HATCH, nHatchType);
|
|
//if((nHatchType == 0 && DocGetIsSolidFill() && DocGetWallHatch() ) || nHatchType == 1)
|
|
//{
|
|
// CString sHatchType = DocGetWallHPatte();
|
|
// if (_tcsicmp(sHatchType, _T("SOLID")) == 0)
|
|
// {
|
|
// dc << TGGeSolid(m_polyOutline);
|
|
// }
|
|
// else
|
|
// {
|
|
// dc << TGGeHatch(m_polyOutline, sHatchType, GetPScale());
|
|
// }
|
|
//}
|
|
|
|
// 加粗
|
|
if (DocGetIsLineWeight() && DocGetWallIsLW())
|
|
{
|
|
double dLineWidth = DocGetConWallLWeight() * GetPScale(); // 线宽
|
|
TGGePoly2D polyDest;
|
|
if (m_polyOutline.PathArea() > 0) // 顺时针
|
|
{
|
|
m_polyOutline.Offset(dLineWidth, polyDest);
|
|
}
|
|
else
|
|
{
|
|
m_polyOutline.Offset(dLineWidth * (-1), polyDest);
|
|
}
|
|
if (m_polyOutline.Length() != polyDest.Length())
|
|
{
|
|
while (iClipCount > 0)
|
|
{
|
|
dc.PopClip();
|
|
iClipCount--;
|
|
}
|
|
return Acad::eInvalidInput;
|
|
}
|
|
|
|
TGGePoly2D poly2dNew;
|
|
for (int i = 0; i < m_polyOutline.Length() - 1; i++)
|
|
{
|
|
poly2dNew.Reset();
|
|
poly2dNew.AppendNode(m_polyOutline.GetPointListAt(i), m_polyOutline.m_ardbulges[i]);
|
|
poly2dNew.AppendNode(m_polyOutline.GetPointListAt(i+1));
|
|
poly2dNew.AppendNode(*polyDest.GetPointListAt(i+1), *(polyDest.m_ardbulges[i]) * (-1));
|
|
poly2dNew.AppendNode(*polyDest.GetPointListAt(i));
|
|
poly2dNew.SetClosed();
|
|
dc << TGGeSolid(poly2dNew);
|
|
}
|
|
poly2dNew.Reset();
|
|
poly2dNew.AppendNode(m_polyOutline.GetPointListAt(m_polyOutline.Length() - 1), m_polyOutline.m_ardbulges[m_polyOutline.Length() - 1]);
|
|
poly2dNew.AppendNode(m_polyOutline.GetPointListAt(0));
|
|
poly2dNew.AppendNode(*polyDest.GetPointListAt(0), *(polyDest.m_ardbulges[polyDest.Length() - 1]) * (-1));
|
|
poly2dNew.AppendNode(*polyDest.GetPointListAt(polyDest.Length() - 1));
|
|
poly2dNew.SetClosed();
|
|
dc << TGGeSolid(poly2dNew);
|
|
}
|
|
|
|
while (iClipCount > 0)
|
|
{
|
|
dc.PopClip();
|
|
iClipCount--;
|
|
}
|
|
|
|
// 编号
|
|
CString sNumber;
|
|
if (GetAt(KEY_CLAB, sNumber) &&
|
|
!sNumber.IsEmpty())
|
|
{
|
|
double dAxAngle;
|
|
GetAt(KEY_AXANG, dAxAngle); // 转角
|
|
|
|
TADSGePoint3d ptPos = m_polyOutline.GetPointListAt(1); // 轮廓线右下角的点
|
|
TADSGePoint3d vtDir = ptPos - m_polyOutline.GetPointListAt(0);
|
|
vtDir.z = 0;
|
|
vtDir.Normalize();
|
|
|
|
// 右下角点向左偏移200,向上偏移150,得到文字的位置点
|
|
double dOffsetLeft = 200, dOffsetUp = 150;
|
|
double dTextHeight = 3.5;
|
|
TADSGePoint3d vtTemp = vtDir;
|
|
vtTemp.Rotate(PI / 2.0);
|
|
vtTemp.Normalize();
|
|
ptPos = ptPos.AsAcGePoint3d() + vtDir.AsAcGeVector3d() * (-dOffsetLeft);
|
|
ptPos = ptPos.AsAcGePoint3d() + vtTemp.AsAcGeVector3d() * dOffsetUp;
|
|
|
|
TDbText text;
|
|
text.setPropertiesFrom(this);
|
|
text.SetAlignment(TGGiExplodeDrawBase::kBottomRight);
|
|
text.SetHeight(dTextHeight);
|
|
text.SetRotation(dAxAngle);
|
|
text.SetStyleId(GetTextStyleId(_T("Standard")));
|
|
text.SetText(sNumber);
|
|
text.SetLocation(ptPos);
|
|
dc.DrawEntity(text);
|
|
}
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSelfBase::GetExtents2d(TADSGePoint3d &ptLow, TADSGePoint3d &ptUp) const
|
|
{
|
|
assertReadEnabled();
|
|
m_polyOutline.GetExtend(ptLow, ptUp);
|
|
ptLow.z = 0.0;
|
|
ptUp.z = 0.0;
|
|
return Acad::eOk;
|
|
}
|
|
|
|
Acad::ErrorStatus TDbStruSelfBase::GetExtents(TADSGePoint3d &ptLow, TADSGePoint3d &ptUp) const
|
|
{
|
|
assertReadEnabled();
|
|
GetExtents2d(ptLow, ptUp);
|
|
AcGePoint3d ptInsert;
|
|
double dZHeight;
|
|
if (GetAt(KEY_POS, ptInsert) &&
|
|
GetAt(KEY_H2, dZHeight))
|
|
{
|
|
ptLow.z = ptUp.z = ptInsert.z;
|
|
ptLow.z -= dZHeight;
|
|
}
|
|
return Acad::eOk;
|
|
}
|
|
|
|
const TCHAR* TDbStruSelfBase::GetDefaultLayer() const
|
|
{
|
|
return LAY_S_BASE_SINGLE_LINE;
|
|
}
|
|
|
|
BOOL TDbStruSelfBase::IsValid() const
|
|
{
|
|
int iType;
|
|
double dB, dH, dAngle;
|
|
AcGePoint3d ptInsert;
|
|
if (GetAt(KEY_B, dB) &&
|
|
GetAt(KEY_H, dH) &&
|
|
GetAt(KEY_AXANG, dAngle) &&
|
|
GetAt(KEY_POS, ptInsert) &&
|
|
GetAt(KEY_SECTYP, iType) &&
|
|
m_polyOutline.Length() > 0)
|
|
{
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
// 支持夹点ctrl功能切换
|
|
int TDbStruSelfBase::GetCtrlToggleIndex() const
|
|
{
|
|
return 12;
|
|
}
|
|
void TDbStruSelfBase::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
|
|
{
|
|
assertWriteEnabled();
|
|
TDbStruEntityBase::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
|
|
|
|
TDbStruSelfBase* pEnt = TDbStruSelfBase::cast(pSrcEntity);
|
|
if (pEnt != NULL)
|
|
{
|
|
int iSecType;
|
|
double dB, dH, dZHeight, dAngle, dInsPtX, dInsPtY;
|
|
AcGePoint3d ptInsert;
|
|
GetAt(KEY_SECTYP, iSecType);
|
|
GetAt(KEY_B, dB);
|
|
GetAt(KEY_H, dH);
|
|
GetAt(KEY_POS, ptInsert);
|
|
GetAt(KEY_AXANG, dAngle);
|
|
GetAt(KEY_H2, dZHeight);
|
|
GetAt(KEY_INSPTX, dInsPtX);
|
|
GetAt(KEY_INSPTY, dInsPtY);
|
|
|
|
GetSpecialtyData()->Empty();
|
|
*GetSpecialtyData() = *pEnt->GetSpecialtyData();
|
|
|
|
SetAt(KEY_SECTYP, iSecType);
|
|
SetAt(KEY_B, dB);
|
|
SetAt(KEY_H, dH);
|
|
SetAt(KEY_POS, ptInsert);
|
|
SetAt(KEY_AXANG, dAngle);
|
|
SetAt(KEY_H2, dZHeight);
|
|
SetAt(KEY_INSPTX, dInsPtX);
|
|
SetAt(KEY_INSPTY, dInsPtY);
|
|
}
|
|
}
|
|
|
|
TEntityBase::DrawType TDbStruSelfBase::GetDrawType() const
|
|
{
|
|
return TEntityBase::k2DOnly;
|
|
}
|
|
|
|
bool TDbStruSelfBase::GetStandardFaceBody(AcDbVoidPtrArray& arFacePtrs) const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool TDbStruSelfBase::GetSafeProtectedSpace(AcDbVoidPtrArray& arFacePtrs) const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
bool TDbStruSelfBase::GetSection(const AcDbFace &face,
|
|
const AcGeVector3d &vtPlaneSecDir,
|
|
std::vector<TObjSectionRecord> §ionRecords,
|
|
AcDbVoidPtrArray &arFillPtrs) const
|
|
{
|
|
return false;
|
|
}
|
|
|
|
CString TDbStruSelfBase::GetXml(const AcGeMatrix3d& mat) const
|
|
{
|
|
return _T("");
|
|
}
|
|
|
|
// 生成轮廓线
|
|
void TDbStruSelfBase::GenerateOutline()
|
|
{
|
|
UpdateInfoToOutlineRect();
|
|
}
|
|
|
|
// 获取轮廓线
|
|
const TGGePoly2D& TDbStruSelfBase::GetOutline()
|
|
{
|
|
return m_polyOutline;
|
|
}
|
|
|
|
// 裁剪关系数组操作
|
|
void TDbStruSelfBase::SetAssocIds(const AcDbObjectIdArray& ids)
|
|
{
|
|
assertWriteEnabled();
|
|
m_arAssocBeamIds.setLogicalLength(0);
|
|
m_arAssocBeamIds = ids;
|
|
}
|
|
void TDbStruSelfBase::GetAssocIds(AcDbObjectIdArray& ids)
|
|
{
|
|
assertReadEnabled();
|
|
ids.setLogicalLength(0);
|
|
ids = m_arAssocBeamIds;
|
|
}
|
|
void TDbStruSelfBase::RemoveAssocIds(const AcDbObjectId& id)
|
|
{
|
|
assertWriteEnabled();
|
|
m_arAssocBeamIds.remove(id);
|
|
}
|
|
|
|
int TDbStruSelfBase::GetFirstVersion()const
|
|
{
|
|
return 10;
|
|
}
|
|
bool TDbStruSelfBase::IsModelEntity() const
|
|
{
|
|
return true;
|
|
}
|
|
|
|
void InitDbStruSelfBase(BOOL bInit)
|
|
{
|
|
if (bInit)
|
|
{
|
|
TDbStruSelfBase::rxInit();
|
|
acrxBuildClassHierarchy();
|
|
TDbStruSelfBase::InitMatchProtocol(TRUE);
|
|
}
|
|
else
|
|
{
|
|
TDbStruSelfBase::InitMatchProtocol(FALSE);
|
|
deleteAcRxClass(TDbStruSelfBase::desc());
|
|
}
|
|
}
|
|
#endif |