#include "stdafx.h" ACRX_NO_CONS_DEFINE_MEMBERS(ATSPolyPathEnt, ATSEntity); const Adesk::UInt8 TDbPolyPathEnt::g_nVersion = 2; TDbPolyPathEnt::TDbPolyPathEnt() { } TDbPolyPathEnt::~TDbPolyPathEnt() { } BOOL TDbPolyPathEnt::IsValid() const { BOOL bRet=TDbEntity::IsValid(); if(!bRet) return bRet; XPoly2D polyPath; AcGeVector3d normal; GetPathPoly(polyPath,normal); bRet=(polyPath.Length()>1); return bRet; } // 提供对格式刷的支持 void TDbPolyPathEnt::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag) { assertWriteEnabled(); TDbEntity::CopyPropertiesFrom(pSrcEntity, gMatchFlag); TDbPolyPathEnt *pSrc=TDbPolyPathEnt::cast(pSrcEntity); if(pSrc) { } } Acad::ErrorStatus TDbPolyPathEnt::dwgInFields (AcDbDwgFiler* pFiler) { assertWriteEnabled(); Acad::ErrorStatus es = TDbEntity::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_idBind); return pFiler->filerStatus(); } Acad::ErrorStatus TDbPolyPathEnt::dwgOutFields(AcDbDwgFiler* pFiler) const { assertReadEnabled(); Acad::ErrorStatus es = TDbEntity::dwgOutFields(pFiler); if(es != Acad::eOk) return es; pFiler->writeItem(g_nVersion); pFiler->writeItem(m_idBind); return pFiler->filerStatus(); } Acad::ErrorStatus TDbPolyPathEnt::dxfInFields (AcDbDxfFiler* pFiler) { assertWriteEnabled(); Acad::ErrorStatus es= TDbEntity::dxfInFields(pFiler); if(es!=Acad::eOk) return es; if (!pFiler->atSubclassData(_T("TDbPolyPathEnt"))) { return Acad::eBadDxfSequence; } return pFiler->filerStatus(); // 不读入任何数据 } Acad::ErrorStatus TDbPolyPathEnt::dxfOutFields(AcDbDxfFiler* pFiler) const { assertReadEnabled(); Acad::ErrorStatus es; es = TDbEntity::dxfOutFields(pFiler); assert(es == Acad::eOk); es = pFiler->writeItem(AcDb::kDxfSubclass,_T("TDbPolyPathEnt")); assert(es == Acad::eOk); return es; } // ----------------------------------------------------------------------- Acad::ErrorStatus TDbPolyPathEnt::subGetOsnapPoints( AcDb::OsnapMode osnapMode, INT_PTR gsSelectionMark, const AcGePoint3d& ptPick, const AcGePoint3d& lastPoint, const AcGeMatrix3d& viewXform, AcGePoint3dArray& snapPoints, AcDbIntArray& geomIds) const { assertReadEnabled(); if(osnapMode==AcDb::kOsModeNode) { XVector3D vtNormal=GetNormal(); XPoly2D polyPath; AcGeVector3d normal; GetPathPoly(polyPath,normal); for(int i=0; iTransformBy(mat); // Modify on 2002/1/30 纠正弧段转角错误 if(IsMirrorMatrix(mat)) { for(int m=0; m=0 && nPrev=0 && nNext1.0E-5) { XArc prevArc=prevSeg.GetArc(); double nAngBeg=ads_angle(prevArc.GetCenterPt(), prevSeg.StartPoint()); double nAngEnd=ads_angle(prevArc.GetCenterPt(), ptStart); if(prevSeg.IsMinusArc()) { nPrevBulge=-CT_std_angle(nAngBeg-nAngEnd); } else { nPrevBulge=CT_std_angle(nAngEnd-nAngBeg); } } if(fabs(nextSeg.GetBulge())>1.0E-5) { XArc nextArc=nextSeg.GetArc(); double nAngBeg=ads_angle(nextArc.GetCenterPt(), ptEnd); double nAngEnd=ads_angle(nextArc.GetCenterPt(), nextSeg.EndPoint()); if(nextSeg.IsMinusArc()) { nNextBulge=-CT_std_angle(nAngBeg-nAngEnd); } else { nNextBulge=CT_std_angle(nAngEnd-nAngBeg); } } *poly2d[nEdgeIndex] = ptStart; if(nNext>=0 && nNext=0 && nPrevz = polyPath[n]->z; } polyPath = poly2d; } } } SetPathPoly(polyPath,vtNormal); return Acad::eOk; } //////////////////////////////////////////////////////// // 功能: 夹点操作 Acad::ErrorStatus TDbPolyPathEnt::subMoveStretchPointsAt( const AcDbIntArray& indices, const AcGeVector3d& offset) { assertWriteEnabled(); if(IsBind()) return Acad::eOk; AcGeVector3d vtNormal; XPoly2D polyPath; GetPathPoly(polyPath,vtNormal); int nVertexCount=polyPath.Length(); XPoint vtOffset=Wcs2Ecs(*(XPoint *)&offset, vtNormal); for (int i = 0; i < indices.length(); i++) { int idx = indices[i]; if(idxm_idBind = AcDbObjectId::kNull; return Acad::eOk; } /* ----------------------------------------------------------------------- */ ////////////////////////////////////////////////////////////////////// // derived from AcDbObject, Reactor的唤醒函数 // INSERT实体要被删除/恢复 void TDbPolyPathEnt::erased(const AcDbObject* pDbObj, Adesk::Boolean erasing) { if(pDbObj->objectId()==m_idBind && !isWriteEnabled() && isNotifyEnabled()) { Adesk::Boolean wasWritable; VERIFY(upgradeFromNotify(wasWritable)==Acad::eOk); assertWriteEnabled(); m_idBind=NULL; //erase(erasing); //UnBind(); VERIFY(downgradeToNotify(wasWritable)==Acad::eOk); } } // 绊定的实体发生变化 void TDbPolyPathEnt::modified(const AcDbObject* pDbObj) { if(pDbObj->objectId()==m_idBind && !isWriteEnabled() && isNotifyEnabled()) { const TEntityBase *pMaster = TEntityBase::Cast(pDbObj); if(pMaster) { Adesk::Boolean wasWritable; VERIFY(upgradeFromNotify(wasWritable)==Acad::eOk); assertWriteEnabled(); XPoly2D polyPath; AcGeVector3d normal; pMaster->GetBindPath(polyPath,normal); SetPathPoly(polyPath,normal); VERIFY(downgradeToNotify(wasWritable)==Acad::eOk); } } } void TDbPolyPathEnt::UnBind() { assertWriteEnabled(); AcDbObjectId id=objectId(); if(!!m_idBind) { OPENOBJ_BEGIN(m_idBind, AcDb::kForWrite, AcDbEntity, pEnt); if(pEnt) { if(!!id) pEnt->removePersistentReactor(id); m_idBind=AcDbObjectId::kNull; } OPENOBJ_END(); } } // 把当前目标绊定到一个对象上 // 注意: 目前仅用坡屋顶来绊定 Acad::ErrorStatus TDbPolyPathEnt::SetBindObject(const AcDbObjectId &id) { assertWriteEnabled(); OPENOBJ_BEGIN(id, AcDb::kForWrite, AcDbEntity, pEnt); const TEntityBase *pMaster = TEntityBase::Cast(pEnt); if(pEnt==NULL || !objectId()) return Acad::eInvalidInput; XPoly2D polyPath; AcGeVector3d normal; pMaster->GetBindPath(polyPath,normal); SetPathPoly(polyPath,normal); m_idBind = id; pEnt->addPersistentReactor(objectId()); OPENOBJ_END(); return Acad::eOk; } /////////////////////////////////////////////////////////////// XVector3D TDbPolyPathEnt::GetNormal() const { return XVector3D(0,0,1); } AcDbObjectId TDbPolyPathEnt::GetBindObjectId() const { assertReadEnabled(); return m_idBind; } BOOL TDbPolyPathEnt::IsBind() const { assertReadEnabled(); return (!!m_idBind); } void TDbPolyPathEnt::SetNormal(const XVector3D &vtNormal) { } void TDbPolyPathEnt::SetElevationAt(int idx, double nElev) { assertWriteEnabled(); XPoly2D polyPath; AcGeVector3d normal; GetPathPoly(polyPath,normal); ASSERT(idx>=0 && idxz=nElev; SetPathPoly(polyPath,normal); } void TDbPolyPathEnt::SetSweepAngleAt(int idx, double nAng) { assertWriteEnabled(); XPoly2D polyPath; AcGeVector3d normal; GetPathPoly(polyPath,normal); ASSERT(idx>=0 && idx=0 && idxz; } double TDbPolyPathEnt::GetSweepAngleAt(int idx) const { assertReadEnabled(); XPoly2D polyPath; AcGeVector3d normal; GetPathPoly(polyPath,normal); ASSERT(idx>=0 && idxz; polyPath.SetBulge(nPos, - ar2.Bulge()); polyPath.InsertNodeAt(nPos+1, ptAdd, ar1.Bulge()); } else { XCurveSegment seg1=seg, seg2=seg; seg1.SetPoints(seg.StartPoint(), ptOnCurve); seg2.SetPoints(ptOnCurve, seg.EndPoint()); ptOnCurve.z = polyPath[nPos]->z; polyPath.SetBulge(nPos, seg1.GetBulge()); polyPath.InsertNodeAt(nPos+1, ptAdd, seg2.GetBulge()); } SetPathPoly(polyPath,normal); return TRUE; } else if(nPos>0 && ptOnCurve!=ptAdd){ nPos--; if(nPos==0) { polyPath[nPos]; polyPath.InsertNodeAt(nPos, ptAdd); } else { polyPath.AppendNode(ptAdd); } SetPathPoly(polyPath,normal); return TRUE; } } return FALSE; } BOOL TDbPolyPathEnt::RemoveVertexAt(int nPos) { assertWriteEnabled(); XPoly2D polyPath; AcGeVector3d normal; GetPathPoly(polyPath,normal); ASSERT(nPos>=0 && nPos0 命中顶点; <0 命中边; 0--没有命中 // abs(nRet)-1 为命中目标序号 int TDbPolyPathEnt::HitTestOnBase2d(const XPoint &ptTest, double nTol) const { assertReadEnabled(); XPoly2D polyPath; AcGeVector3d normal; GetPathPoly(polyPath,normal); XPoint pt2d=ptTest; pt2d.z=0; /* for(int i=0; i