#include "stdafx.h" #ifdef TASD #include "TDbStruReinBar.h" const Adesk::UInt8 TDbStruReinBar::g_nVersion = 1; IMPLEMENT_TENTBASE(TDbStruReinBar); ACRX_DXF_DEFINE_MEMBERS(ATSStruReinBar, ATSStruEntityBase, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, 1, ATS_STRUREINBAR, "ATS_STRUREINBAR图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com"); TDbStruReinBar::TDbStruReinBar() { TDbStruEntityBase::SetAt(KEY_KIND, (int)TDbStruReinBar::kNormal); SetStartHook(TStruHookInfo::kNone, 1); SetEndHook(TStruHookInfo::kNone, 2); m_dWidth = g_dReinbarWidth; m_dLengthS = g_dReinbarLenS; m_dLengthO = g_dReinbarLenO; m_dLengthB = g_dReinbarLenB; m_dDiaB = g_dReinbarDiaB; } TDbStruReinBar::~TDbStruReinBar() { } Acad::ErrorStatus TDbStruReinBar::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; } pFiler->readItem(&m_dWidth); pFiler->readItem(&m_dLengthS); pFiler->readItem(&m_dLengthO); pFiler->readItem(&m_dLengthB); pFiler->readItem(&m_dDiaB); ReadPoly2D(pFiler, m_polyOutline); return es; } Acad::ErrorStatus TDbStruReinBar::dwgOutFields(AcDbDwgFiler* pFiler) const { assertReadEnabled(); Acad::ErrorStatus es; es = TDbStruEntityBase::dwgOutFields(pFiler); if (Acad::eOk != es) { return es; } pFiler->writeItem(g_nVersion); pFiler->writeItem(m_dWidth); pFiler->writeItem(m_dLengthS); pFiler->writeItem(m_dLengthO); pFiler->writeItem(m_dLengthB); pFiler->writeItem(m_dDiaB); WritePoly2D(pFiler, m_polyOutline); return es; } Acad::ErrorStatus TDbStruReinBar::dxfInFields (AcDbDxfFiler* pFiler) { assertWriteEnabled(); return TDbStruEntityBase::dxfInFields(pFiler); } Acad::ErrorStatus TDbStruReinBar::dxfOutFields(AcDbDxfFiler* pFiler) const { assertReadEnabled(); return TDbStruEntityBase::dxfOutFields(pFiler); } Acad::ErrorStatus TDbStruReinBar::GetGripText(int i, CString &cs) const { if (i >= 0 && i <= m_polyOutline.Length()-1) { cs = _T("移动钢筋对象或移动该路径点"); } else { cs = _T("更改钩子方向"); } return Acad::eOk; } Acad::ErrorStatus TDbStruReinBar::ExplodeOrDraw2d(TGGiExplodeDrawBase &dc) const { assertReadEnabled(); // 钢筋类别-点钢筋 EType type; if (TDbStruEntityBase::GetAt(KEY_KIND, (int&)type) && type == kDot) { if (m_polyOutline.Length() >=1 ) { AcGePoint3d ptCenter = m_polyOutline.GetPointListAt(0); AcGePoint3d ptSolid1(ptCenter[X]-m_dWidth/2, ptCenter[Y], 0); AcGePoint3d ptSolid2(ptCenter[X]+m_dWidth/2, ptCenter[Y], 0); TGGePoly2D poly, polyDisperse; poly.InsertNodeAt(0, ptSolid1, PI); poly.InsertNodeAt(1, ptSolid2, PI); poly.InsertNodeAt(2, ptSolid1); poly.SetClosed(); poly.Disperse(polyDisperse); dc << TGGeSolid(polyDisperse); } return Acad::eOk; } // 钢筋类别-普通钢筋 // 钢筋 AcDbPolyline plBar; for (int i=0; i arHooks; if (GetAt(KEY_HOOK, arHooks)) { for (int j=0; j arHooks; if (GetAt(KEY_HOOK, arHooks)) { for (int i=0; i= 1) { gripPoints.append(m_polyOutline.GetPointListAt(0)); } return Acad::eOk; } // 普通钢筋 // 钢筋路径 for (int i=0; i arHooks; if (GetAt(KEY_HOOK, arHooks)) { for (int i=0; i= 0 && indices[i] <= m_polyOutline.Length()-1) { TADSGePoint3d ptMove; if (indices[i] == 0) { if (GetNumsOfHooksAt(0) <= 0) { // 移动路径点 ptMove = *m_polyOutline.GetPointListAt(0); ptMove += offset; m_polyOutline.SetPointListAt(0, ptMove); // 移动起始点钩子 TStruHookInfo hook; if (GetAt(KEY_HOOKS, hook) && hook.eType != TStruHookInfo::kNone) { hook.ptPos += offset; SetAt(KEY_HOOKS, hook); } return Acad::eOk; } } else { if (GetNumsOfHooksAt(indices[i]-1) <= 0 && GetNumsOfHooksAt(indices[i]) <= 0) { // 移动路径点 ptMove = *m_polyOutline.GetPointListAt(indices[i]); ptMove += offset; m_polyOutline.SetPointListAt(indices[i], ptMove); if (indices[i] == m_polyOutline.Length()-1) { // 移动终止点钩子 TStruHookInfo hook; if (GetAt(KEY_HOOKE, hook) && hook.eType != TStruHookInfo::kNone) { hook.ptPos += offset; SetAt(KEY_HOOKE, hook); } } return Acad::eOk; } } AcGeMatrix3d xform; xform.setToTranslation(offset); subTransformBy(xform); break; } else { // 改变钩子的象限 // 获得该夹点处的钩子 TStruHookInfo hook; int index = indices[i] - m_polyOutline.Length(); hook = GetHookFromGripPt(index); // 移动后的夹点位置 AcGePoint3d ptMoved = GetGripPoint(hook) + offset; // 获得该钩子的方向向量 AcGeVector3d vtDir1, vtDir2; GetAxisX(hook, vtDir1, vtDir2); hook.nQuadrant = GetNewQuadrant(hook, ptMoved, vtDir1, vtDir2); UpdateHookFromGripPt(index, hook); } } return Acad::eOk; } Acad::ErrorStatus TDbStruReinBar::subGetStretchPoints(AcGePoint3dArray& stretchPoints) const { return TDbStruEntityBase::subGetStretchPoints(stretchPoints); } Acad::ErrorStatus TDbStruReinBar::subMoveStretchPointsAt(const AcDbIntArray& indices, const AcGeVector3d& offset) { return subMoveGripPointsAt(indices, offset); } Acad::ErrorStatus TDbStruReinBar::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 TDbStruReinBar::subGetTransformedCopy( const AcGeMatrix3d& xform, AcDbEntity*& pEnt) const { return TDbStruEntityBase::subGetTransformedCopy(xform, pEnt); } Acad::ErrorStatus TDbStruReinBar::copyFrom(const AcRxObject* pSrc) { assertWriteEnabled(); if (pSrc->isKindOf(TDbStruReinBar::desc())) { TDbStruReinBar* pSrcReinBar = (TDbStruReinBar*)pSrc; GetSpecialtyData()->Empty(); GetSpecialtyData()->CopyFrom(pSrcReinBar->GetSpecialtyData()); m_polyOutline = pSrcReinBar->GetOutline(); // 钢筋路径 m_dWidth = pSrcReinBar->GetWidth(); // 宽度 } return Acad::eOk; } Acad::ErrorStatus TDbStruReinBar::subGetClassID(CLSID* pClsid) const { #if (ADS >= 17) assertReadEnabled(); #endif return Acad::eOk; } Acad::ErrorStatus TDbStruReinBar::subWblockClone( AcRxObject* pOwner, AcDbObject*& pClonedObject, AcDbIdMapping& idMap, Adesk::Boolean isPrimary) const { return TDbStruEntityBase::subWblockClone(pOwner, pClonedObject, idMap, isPrimary); } Acad::ErrorStatus TDbStruReinBar::subDeepClone( AcDbObject* pOwner, AcDbObject*& pClonedObject, AcDbIdMapping& idMap, Adesk::Boolean isPrimary) const { return TDbStruEntityBase::subDeepClone(pOwner, pClonedObject, idMap, isPrimary); } // 获得二维包围盒 Acad::ErrorStatus TDbStruReinBar::GetExtents2d(TADSGePoint3d &ptLow, TADSGePoint3d &ptUp) const { assertReadEnabled(); EType eType; if (TDbStruEntityBase::GetAt(KEY_KIND, (int&)eType)) { if (eType == kNormal) { m_polyOutline.GetExtend(ptLow, ptUp); } else { TADSGePoint3d ptCenter = m_polyOutline.GetPointListAt(0); ptLow = TADSGePoint3d(ptCenter.x - m_dWidth / 2, ptCenter.y - m_dWidth / 2, 0); ptUp = TADSGePoint3d(ptCenter.x + m_dWidth / 2, ptCenter.y + m_dWidth / 2, 0); } } return Acad::eOk; } // 获得三维包围盒 Acad::ErrorStatus TDbStruReinBar::GetExtents(TADSGePoint3d &ptLow, TADSGePoint3d &ptUp) const { return Acad::eNotImplementedYet; } //取动态属性显示数据 void TDbStruReinBar::GetTips(TDPtrList& lstInfo) const { TDbStruEntityBase::GetTips(lstInfo); } const TCHAR* TDbStruReinBar::GetDefaultLayer() const { return LAY_S_BEAM_RBAR_LINE; } BOOL TDbStruReinBar::IsValid() const { EType eType; TDbStruEntityBase::GetAt(KEY_KIND, (int&)eType); if (eType == kDot && m_polyOutline.Length() < 1) { return FALSE; } else if (eType == kNormal && m_polyOutline.Length() < 2) { return FALSE; } return TRUE; } // 支持夹点ctrl功能切换 int TDbStruReinBar::GetCtrlToggleIndex()const { return TDbStruEntityBase::GetCtrlToggleIndex(); } // 属性匹配 void TDbStruReinBar::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag) { assertWriteEnabled(); TDbStruEntityBase::CopyPropertiesFrom(pSrcEntity, gMatchFlag); TDbStruReinBar* pSrc = TDbStruReinBar::cast(pSrcEntity); if (pSrc != NULL) { m_dWidth = pSrc->m_dWidth; } } // 获得标准三维面 bool TDbStruReinBar::GetStandardFaceBody(AcDbVoidPtrArray& arFacePtrs) const { return TDbStruEntityBase::GetStandardFaceBody(arFacePtrs); } // 获得安全保护区 bool TDbStruReinBar::GetSafeProtectedSpace(AcDbVoidPtrArray& arFacePtrs) const { return TDbStruEntityBase::GetSafeProtectedSpace(arFacePtrs); } // 获得剖面 bool TDbStruReinBar::GetSection( const AcDbFace &face, const AcGeVector3d& vtPlaneSecDir, std::vector §ionRecords, AcDbVoidPtrArray& arFillPtrs) const { return TDbStruEntityBase::GetSection(face, vtPlaneSecDir, sectionRecords, arFillPtrs); } // 获得XML CString TDbStruReinBar::GetXml(const AcGeMatrix3d& mat) const { return TDbStruEntityBase::GetXml(mat); } TStruHookInfo TDbStruReinBar::GetHookFromGripPt(int index) { assertWriteEnabled(); CArray arHooks; GetHooksOrderByGrip(arHooks); return arHooks[index].hook; } void TDbStruReinBar::GetHooksOrderByGrip(CArray& arHooks) { assertReadEnabled(); SHook sHook; TStruHookInfo hook; if (GetAt(KEY_HOOKS, hook) && hook.eType != TStruHookInfo::kNone) { sHook.hook = hook; sHook.bIsStartOrEnd = 1; arHooks.Add(sHook); } if (GetAt(KEY_HOOKE, hook) && hook.eType != TStruHookInfo::kNone) { sHook.hook = hook; sHook.bIsStartOrEnd = -1; arHooks.Add(sHook); } CArray arHooksMid; if (GetAt(KEY_HOOK, arHooksMid)) { for (int i=0; i arHooks; GetHooksOrderByGrip(arHooks); if (index >= arHooks.GetSize()) { return; } SHook sHook = arHooks[index]; if (sHook.bIsStartOrEnd > 0) { SetAt(KEY_HOOKS, hook); } else if (sHook.bIsStartOrEnd < 0) { SetAt(KEY_HOOKE, hook); } else { CArray arHooksMid; GetAt(KEY_HOOK, arHooksMid); if (sHook.nIndex < arHooksMid.GetSize()) { arHooksMid[sHook.nIndex] = hook; SetAt(KEY_HOOK, arHooksMid); } } } int TDbStruReinBar::GetNewQuadrant(TStruHookInfo hook, AcGePoint3d ptMoved, AcGeVector3d vtAxis) { int nRet = hook.nQuadrant; // 钩子位置点到新夹点位置的向量 AcGeVector3d vtHookDir = ptMoved - hook.ptPos; vtHookDir.rotateBy(-AcGeVector2d(vtAxis.x, vtAxis.y).angle(), AcGeVector3d(0, 0, 1)); if (vtHookDir[X] > 0 && vtHookDir[Y] > 0) // 第一象限 { nRet = 1; } else if (vtHookDir[X] <=0 && vtHookDir[Y] > 0) // 第二象限 { nRet = 2; } else if (vtHookDir[X] > 0 && vtHookDir[Y] < 0) // 第四象限 { nRet = 4; } else // 第三象限 { nRet = 3; } if (IsStartHook(hook.ptPos)) { nRet = 4; if (vtHookDir[Y] > 0) { nRet = 1; } } else if (IsEndHook(hook.ptPos)) { nRet = 3; if (vtHookDir[Y] > 0) { nRet = 2; } } return nRet; } int TDbStruReinBar::GetNewQuadrant(TStruHookInfo hook, AcGePoint3d ptMoved, AcGeVector3d vtAxis1, AcGeVector3d vtAxis2) { int nRet = hook.nQuadrant; vtAxis1.normalize(); vtAxis2.normalize(); if (vtAxis1 == vtAxis2) { return GetNewQuadrant(hook, ptMoved, vtAxis1); } int nQua2 = GetNewQuadrant(hook, ptMoved, vtAxis2); // 基于第二条方向向量的象限位置 switch (GetNewQuadrant(hook, ptMoved, vtAxis1)) { case 1: // 第一象限 if (nQua2 == 1 || nQua2 == 4) { nRet = nQua2; } break; case 2: // 第二象限 if (nQua2 != 1 && nQua2 != 4) { nRet = 2; } break; case 3: // 第三象限 if (nQua2 != 1 && nQua2 != 4) { nRet = 3; } break; case 4: // 第四象限 if (nQua2 == 1 || nQua2 == 4) { nRet = nQua2; } break; default: break; } return nRet; } BOOL TDbStruReinBar::SetAt(LPCTSTR pszKey, const TStruHookInfo& hook) { assertWriteEnabled(); if (TDbStruEntityBase::SetAt(CString(pszKey)+_T("1"), hook.ptPos) && TDbStruEntityBase::SetAt(CString(pszKey)+_T("2"), hook.nQuadrant) && TDbStruEntityBase::SetAt(CString(pszKey)+_T("3"), (int)hook.eType)) { return TRUE; } return FALSE; } BOOL TDbStruReinBar::GetAt(LPCTSTR pszKey, TStruHookInfo& hook) const { assertReadEnabled(); if (TDbStruEntityBase::GetAt(CString(pszKey)+_T("1"), hook.ptPos) && TDbStruEntityBase::GetAt(CString(pszKey)+_T("2"), hook.nQuadrant) && TDbStruEntityBase::GetAt(CString(pszKey)+_T("3"), (int&)hook.eType)) { return TRUE; } return FALSE; } BOOL TDbStruReinBar::SetAt(LPCTSTR pszKey, const CArray& hooks) { assertWriteEnabled(); if (!TDbStruEntityBase::SetAt(pszKey, (int)hooks.GetSize())) { return FALSE; } for (int i=0; i& hooks) const { assertReadEnabled(); int nSize; if (!TDbStruEntityBase::GetAt(pszKey, nSize)) { return FALSE; } TStruHookInfo hook; for (int i=0; i 0) { hook.ptPos = *m_polyOutline.GetPointListAt(0); } BOOL bRet = SetAt(KEY_HOOKS, hook); return bRet; } BOOL TDbStruReinBar::SetEndHook(TStruHookInfo hook) { assertWriteEnabled(); if (m_polyOutline.Length() > 1) { hook.ptPos = *m_polyOutline.GetPointListAt(m_polyOutline.Length()-1); } BOOL bRet = SetAt(KEY_HOOKE, hook); return bRet; } BOOL TDbStruReinBar::GetStartHook(TStruHookInfo& hookS) { assertReadEnabled(); return GetAt(KEY_HOOKS, hookS); } BOOL TDbStruReinBar::GetEndHook(TStruHookInfo& hookE) { return GetAt(KEY_HOOKE, hookE); } // 添加一个中间钩子 BOOL TDbStruReinBar::AddMidHook(const TStruHookInfo& hook) { assertWriteEnabled(); if (!IsValid()) { return FALSE; } if (!m_polyOutline.HitTestOnCurve(hook.ptPos)) { return FALSE; } CArray arHooks; GetAt(KEY_HOOK, arHooks); // 检测是否含有相同位置的钩子 for (int i=0; i0) // 在顶点上 { if ((TADSGePoint3d)hook.ptPos == m_polyOutline.GetPointListAt(0)) { TGGeCurveSegment curve; m_polyOutline.Nth(nPos-1, curve); vtAxis1 = vtDir; vtAxis2 = vtAxis1.rotateBy(curve.Direction(hook.ptPos), AcGeVector3d(0, 0, 1)); if (m_polyOutline.GetBulge(nPos-1) < -_DIST_SNAP) { vtAxis1 = vtAxis2.rotateBy(PI, AcGeVector3d(0, 0, 1)); } } else if ((TADSGePoint3d)hook.ptPos == m_polyOutline.GetPointListAt(m_polyOutline.Length()-1)) { TGGeCurveSegment curve; m_polyOutline.Nth(nPos-2, curve); vtAxis1 = vtDir; vtAxis2 = vtAxis1.rotateBy(curve.Direction(hook.ptPos), AcGeVector3d(0, 0, 1)); if (m_polyOutline.GetBulge(nPos-2) < -_DIST_SNAP) { vtAxis1 = vtAxis2.rotateBy(PI, AcGeVector3d(0, 0, 1)); } } else { TGGeCurveSegment curve1, curve2; m_polyOutline.Nth(nPos - 2, curve1); m_polyOutline.Nth(nPos - 1, curve2); double dAngle = curve1.Direction(hook.ptPos); vtAxis1 = vtDir; vtAxis1.rotateBy(dAngle, AcGeVector3d(0, 0, 1)); if (m_polyOutline.GetBulge(nPos-2) < -_DIST_SNAP) { vtAxis1.rotateBy(PI, AcGeVector3d(0, 0, 1)); } dAngle = curve2.Direction(hook.ptPos); vtAxis2 = vtDir; vtAxis2.rotateBy(dAngle, AcGeVector3d(0, 0, 1)); if (m_polyOutline.GetBulge(nPos-1) < -_DIST_SNAP) { vtAxis2.rotateBy(PI, AcGeVector3d(0, 0, 1)); } } } else if (nPos<0) // 在线上 { nPos = abs(nPos); TGGeCurveSegment curve; m_polyOutline.Nth(nPos - 1, curve); double dAngle = curve.Direction(hook.ptPos); vtAxis1 = vtAxis2 = vtDir.rotateBy(dAngle, AcGeVector3d(0, 0, 1)); if (m_polyOutline.GetBulge(nPos-1) < -_DIST_SNAP) { vtAxis1 = vtAxis2 .rotateBy(PI, AcGeVector3d(0, 0, 1)); } } } // 获取路径点处的切线 void TDbStruReinBar::GetAxisX(int nIndex, AcGeVector3d& vtAxis1, AcGeVector3d& vtAxis2) const { TStruHookInfo hookTemp = TStruHookInfo(m_polyOutline.GetPointListAt(nIndex), TStruHookInfo::kNone, 1); GetAxisX(hookTemp, vtAxis1, vtAxis2); } // 获取夹点位置 AcGePoint3d TDbStruReinBar::GetGripPoint(const TStruHookInfo& hook) const { AcDbPolyline plOutline; GetHookOutLine(hook, plOutline); AcGePoint3d ptRet; plOutline.getPointAt(plOutline.numVerts()-1, ptRet); return ptRet; } int TDbStruReinBar::GetNumsOfHooksAt(int nIndex) { int nNums = 0; // 遍历中间钩子 CArray arHooks; if (GetAt(KEY_HOOK, arHooks)) { int nRet; for (int i=0; i hooks; if (GetAt(KEY_HOOK, hooks)) { hooks.RemoveAll(); SetAt(KEY_HOOK, hooks); } } // 重新设置起点和终点的钩子位置,使其始终和路径的起点和终点保持一致 void TDbStruReinBar::ReCalcPointHook() { assertWriteEnabled(); TStruHookInfo hook; if (GetAt(KEY_HOOKS, hook)) { hook.ptPos = *m_polyOutline.GetPointListAt(0); SetAt(KEY_HOOKS, hook); } if (GetAt(KEY_HOOKE, hook)) { hook.ptPos = *m_polyOutline.GetPointListAt(m_polyOutline.Length()-1); SetAt(KEY_HOOKE, hook); } } double TDbStruReinBar::GetLenS() const { assertReadEnabled(); return m_dLengthS; } void TDbStruReinBar::SetLenS(double dVal) { assertWriteEnabled(); m_dLengthS = dVal; } double TDbStruReinBar::GetLenO() const { assertReadEnabled(); return m_dLengthO; } void TDbStruReinBar::SetLenO(double dVal) { assertWriteEnabled(); m_dLengthO = dVal; } double TDbStruReinBar::GetLenB() const { assertReadEnabled(); return m_dLengthB; } void TDbStruReinBar::SetLenB(double dVal) { assertWriteEnabled(); m_dLengthB = dVal; } double TDbStruReinBar::GetDiaB() const { assertReadEnabled(); return m_dDiaB; } void TDbStruReinBar::SetDiaB(double dVal) { assertWriteEnabled(); m_dDiaB = dVal; } int TDbStruReinBar::GetFirstVersion()const { return 10; } bool TDbStruReinBar::IsModelEntity() const { return true; } AcDbCurve* TDbStruReinBar::GetBaseCurve()const { assertReadEnabled(); AcDbCurve* pCurve = m_polyOutline.AsAcDbCurve(); return pCurve; } Acad::ErrorStatus TDbStruReinBar::SetBaseCurve(AcDbCurve*pCurve) { assertWriteEnabled(); AcDbCurve *pCurve1 = (AcDbCurve*)pCurve->clone(); if (m_polyOutline.SetAcDbCurve(pCurve1)) { delete pCurve1; return Acad::eOk; } else { delete pCurve1; return Acad::eNotImplementedYet; } } void InitDbStruReinBar(BOOL bInit) { if (bInit) { TDbStruReinBar::rxInit(); acrxBuildClassHierarchy(); TDbStruReinBar::InitMatchProtocol(TRUE); } else { TDbStruReinBar::InitMatchProtocol(FALSE); deleteAcRxClass(TDbStruReinBar::desc()); } } #endif