#include "stdafx.h" #include "AecDbSymbRupture.h" #include "globalFunc.h" #include "GePoly2D.h" const Adesk::UInt8 AecXDbSymbRupture::g_nVersion = 1; ACRX_DXF_DEFINE_MEMBERS(AecXDbSymbRupture, AecXDbEntityBaseEx, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent, 1, AEC_ZHEDUANXIAN, "AEC_ZHEDUANXIAN|缺乏上华解释器, 请下载上华软件|网址: www.shanghuasoft.com"); AecXDbSymbRupture::AecXDbSymbRupture() { m_nRuptureNum = 1; } AecXDbSymbRupture::~AecXDbSymbRupture() { } BOOL AecXDbSymbRupture::IsValid() const { //BOOL bRet = AecXDbEntityBaseEx::IsValid(); //if (!bRet) // return bRet; BOOL bRet = (m_ptStart.Distance2d(m_ptEnd) > g_Option::instance()._DIST_SNAP && m_nRuptureNum >= 1); return bRet; } //Acad::ErrorStatus //AecXDbSymbRupture::subGetClassID(CLSID* pClsid) const //{ // *pClsid = CLSID_ComSymbRupture; // return Acad::eOk; //} // 提供对格式刷的支持 void AecXDbSymbRupture::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag) { AssertWriteEnabled(); AecXDbEntityBaseEx::CopyPropertiesFrom(pSrcEntity, gMatchFlag); AecXDbSymbRupture *pSrc = AecXDbSymbRupture::cast(pSrcEntity); if (pSrc) { } } // 从DWG读入数据: Acad::ErrorStatus AecXDbSymbRupture::dwgInFields(AcDbDwgFiler* pFiler) { AssertWriteEnabled(); Acad::ErrorStatus es = AecXDbEntityBaseEx::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((AcGePoint2d *)&m_ptStart); pFiler->readItem((AcGePoint2d *)&m_ptEnd); pFiler->readItem(&m_nRuptureNum); return pFiler->filerStatus(); } Acad::ErrorStatus AecXDbSymbRupture::dwgOutFields(AcDbDwgFiler* pFiler) const { assertReadEnabled(); Acad::ErrorStatus es = AecXDbEntityBaseEx::dwgOutFields(pFiler); if (es != Acad::eOk) return es; pFiler->writeItem(g_nVersion); pFiler->writeItem((const AcGePoint2d &)m_ptStart); pFiler->writeItem((const AcGePoint2d &)m_ptEnd); pFiler->writeItem(m_nRuptureNum); return pFiler->filerStatus(); } Acad::ErrorStatus AecXDbSymbRupture::dxfInFields(AcDbDxfFiler* pFiler) { AssertWriteEnabled(); Acad::ErrorStatus es = AecXDbEntityBaseEx::dxfInFields(pFiler); if (es != Acad::eOk) return es; if (!pFiler->atSubclassData(_T("AecXDbSymbRupture"))) { return Acad::eBadDxfSequence; } ADSGePoint3d pt1, pt2; int num; resbuf rb; int fieldsFlags; while ((es == Acad::eOk) && ((es = pFiler->readResBuf(&rb)) == Acad::eOk)) { switch (rb.restype) { case AcDb::kDxfXCoord: pt1 = rb.resval.rpoint; fieldsFlags |= 0x1; break; case AcDb::kDxfXCoord + 1: pt2 = rb.resval.rpoint; fieldsFlags |= 0x2; break; case AcDb::kDxfInt16: num = rb.resval.rint; fieldsFlags |= 0x04; break; //fall through intentional default: // An unrecognized group. Push it back so that // the subclass can read it again. pFiler->pushBackItem(); es = Acad::eEndOfFile; break; } } // At this point the es variable must contain eEndOfFile // - either from readResBuf() or from pushback. If not, // it indicates that an error happened and we should // return immediately. // if (es != Acad::eEndOfFile) return Acad::eInvalidResBuf; if (!(fieldsFlags & 0x01)) { pFiler->setError(Acad::eMissingDxfField, _T("\nMissing DXF group code: 10")); return Acad::eMissingDxfField; } if (!(fieldsFlags & 0x02)) { pFiler->setError(Acad::eMissingDxfField, _T("\nMissing DXF group code: 11")); return Acad::eMissingDxfField; } m_ptStart = pt1; m_ptEnd = pt2; if (fieldsFlags & 0x04) m_nRuptureNum = num; return pFiler->filerStatus(); } Acad::ErrorStatus AecXDbSymbRupture::dxfOutFields(AcDbDxfFiler* pFiler) const { assertReadEnabled(); Acad::ErrorStatus es = AecXDbEntityBaseEx::dxfOutFields(pFiler); assert(es == Acad::eOk); es = pFiler->writeItem(AcDb::kDxfSubclass, _T("AecXDbSymbRupture")); assert(es == Acad::eOk); pFiler->writePoint2d(AcDb::kDxfXCoord, m_ptStart.AsAcGePoint2d()); pFiler->writePoint2d(AcDb::kDxfXCoord + 1, m_ptEnd.AsAcGePoint2d()); pFiler->writeInt16(AcDb::kDxfInt16, m_nRuptureNum); return pFiler->filerStatus(); } // ----------------------------------------------------------------------- // Overriden functions for edit // to do: // 允许通过夹点改变边界 Acad::ErrorStatus AecXDbSymbRupture::subGetGripPoints(AcGePoint3dArray& gripPoints, AcDbIntArray& osnapModes, AcDbIntArray& geomIds) const { assertReadEnabled(); gripPoints.append(m_ptStart); //0 gripPoints.append(m_ptEnd); //1 ADSGePoint3d ptMid; Midpoint(m_ptStart, m_ptEnd, ptMid); gripPoints.append(ptMid); return Acad::eOk; } // Modify on 2002/2/22 by ZJQ // 解决普通线和折断线同时stretch 的时候,不能同步拉伸 // Acad::ErrorStatus AecXDbSymbRupture::subGetStretchPoints(AcGePoint3dArray & stretchPoints) const { assertReadEnabled(); stretchPoints.append(m_ptStart); //0 stretchPoints.append(m_ptEnd); //1 return Acad::eOk; } // Active when being rotated, scaled, moved, etc. // Scale is disabled here Acad::ErrorStatus AecXDbSymbRupture::subTransformBy(const AcGeMatrix3d& xform) { AssertWriteEnabled(); AecXDbEntityBaseEx::subTransformBy(xform); ads_matrix mat; GlobalFunc::AsAdsMatrix(xform, mat); m_ptStart.TransformBy(mat); m_ptEnd.TransformBy(mat); return Acad::eOk; } // 功能: 夹点操作 Acad::ErrorStatus AecXDbSymbRupture::subMoveGripPointsAt( const AcDbIntArray& indices, const AcGeVector3d& offset) { using namespace GlobalFunc; AssertWriteEnabled(); ADSGePoint3d vtOffset(offset[0], offset[1]); for (int i = 0; i < indices.length(); i++) { int idx = indices[i]; if (idx == 0) // Move vertex { // modify by lgy 20120321,移动起点终点时可以固定方向移动和不固定方向移动 // m_ptStart += vtOffset; if (GetCtrlToggle()) // 不固定方向移动 { m_ptStart += vtOffset; } else { GeLine lineTemp(m_ptStart, m_ptEnd); double nDir = lineTemp.Direction(); Vector3D vt(cos(nDir), sin(nDir)); double dLength = vtOffset & vt; vt.Scale(dLength); m_ptStart += vt; } } else if (idx == 1) { // modify by lgy 20120321,移动起点终点时可以固定方向移动和不固定方向移动 // m_ptEnd += vtOffset; if (GetCtrlToggle()) // 不固定方向移动终点 { m_ptEnd += vtOffset; } else { GeLine lineTemp(m_ptStart, m_ptEnd); double nDir = lineTemp.Direction(); Vector3D vt(cos(nDir), sin(nDir)); double dLength = vtOffset & vt; vt.Scale(dLength); // 根据距离求移动的向量 m_ptEnd += vt; } } else if (idx == 2) { m_ptStart += vtOffset; m_ptEnd += vtOffset; } } return Acad::eOk; } // 功能: 夹点操作 Acad::ErrorStatus AecXDbSymbRupture::subMoveStretchPointsAt( const AcDbIntArray& indices, const AcGeVector3d& offset) { AssertWriteEnabled(); ADSGePoint3d vtOffset(offset[0], offset[1]); for (int i = 0; i < indices.length(); i++) { int idx = indices[i]; if (idx == 0) // Move vertex { m_ptStart += vtOffset; } else if (idx == 1) { m_ptEnd += vtOffset; } } return Acad::eOk; } // 取得夹点说明 Acad::ErrorStatus AecXDbSymbRupture::GetGripText(int i, CString &cs) const { Acad::ErrorStatus es = Acad::eOk; // modify by lgy 9.0要求CTRL切换固定方向和不固定方向 //if(i==0) // cs=_T("移动起点"); //else if(i==1) // cs=_T("移动终点"); if (i == 0) { cs = !GetCtrlToggle() ? _T("移动起点(ctrl-不固定方向)") : _T("移动起点(ctrl-固定方向)"); } else if (i == 1) { cs = !GetCtrlToggle() ? _T("移动终点(ctrl-不固定方向)") : _T("移动终点(ctrl-固定方向)"); } else if (i == 2) cs = _T("平移"); return es; } BOOL GetStdRupture(ADSGePoint3d ptStart, ADSGePoint3d ptEnd, double scale, GePoly2D &poly2d) { double d = 0.3 * scale; double L2 = (ads_distance(ptStart, ptEnd) - 7.5 * d) / 2.0; if (L2 < 0.0) { return FALSE; } else { double nDist1 = 7 * d / cos(20.0 / 180.0 * PI); double nDist2 = 7 * d / cos(10.0 / 180.0 * PI); double nAng1 = ads_angle(ptStart, ptEnd); ADSGePoint3d pt2, pt3, pt4, pt5; ads_polar(ptStart, nAng1, L2, pt2); ads_polar(pt2, nAng1 + 70.0 / 180.0 * PI, nDist1, pt3); ads_polar(pt3, nAng1 - 80.0 / 180.0 * PI, nDist2 * 2, pt4); ads_polar(pt2, nAng1, 7.5 * d, pt5); poly2d.AppendNode(ptStart); poly2d.AppendNode(pt2); poly2d.AppendNode(pt3); poly2d.AppendNode(pt4); poly2d.AppendNode(pt5); poly2d.AppendNode(ptEnd); } return TRUE; } Acad::ErrorStatus AecXDbSymbRupture::Draw2d(AcGiDraw &dc) const { assertReadEnabled(); GlobalFunc::_LoadConfig(); if (Has2DBuffer() && !dc.IsDragging()) { dc.SetColor(colorIndex()); dc.SetLayer(layerId()); BaseEx::_Draw2DBuffers(dc, true); return Acad::eOk; } double nAng = ads_angle(m_ptStart, m_ptEnd); double nDist = m_ptStart.Distance2d(m_ptEnd); ADSGePoint3d ptStart = m_ptStart; for (Adesk::UInt8 i = 0; i < m_nRuptureNum; i++) { ADSGePoint3d ptEnd; ads_polar(ptStart, nAng, nDist / m_nRuptureNum, ptEnd); GePoly2D poly(0); if (GetStdRupture(ptStart, ptEnd, GetPScale(), poly)) { //dc << poly; DrawPoly2D(dc, poly); } else { //dc << GeLine(ptStart, ptEnd); DrawLine(dc, ptStart, ptEnd); } ptStart = ptEnd; } return Acad::eOk; } // sg add 110301,支持统一标高 bool AecXDbSymbRupture::UnifyElevation(double dElevation) { AssertWriteEnabled(); m_ptStart.z = dElevation; m_ptEnd.z = dElevation; return true; } const TCHAR *AecXDbSymbRupture::GetDefaultLayer() const { extern TCHAR* LAY_OTHER_DIM; return LAY_OTHER_DIM; } DrawModeType AecXDbSymbRupture::GetDrawType() const { return k2DOnly; } /* * * * * * * * * * 取 动 态 属 性 显 示 数 据 的 函 数 * * * * * * * * * */ void AecXDbSymbRupture::GetTips(PtrList &lstInfo) const { lstInfo.Append(new ObjInfoUnit(_T("对象类型"), _T("折断线"))); lstInfo.Append(new ObjInfoUnit(_T("折断线长"), GlobalFunc::Dist2Str(m_ptStart.Distance2d(m_ptEnd)))); lstInfo.Append(new ObjInfoUnit(_T("折断线角度:"), GlobalFunc::Angle2Str(ads_angle(m_ptStart, m_ptEnd) * 180.0 / PI))); lstInfo.Append(new ObjInfoUnit(_T("折断数目"), TCString(_T("%d"), int(GetRuptureNum())))); } ADSGePoint3d AecXDbSymbRupture::GetStartPoint() const { return m_ptStart; } ADSGePoint3d AecXDbSymbRupture::GetEndPoint() const { return m_ptEnd; } Adesk::UInt8 AecXDbSymbRupture::GetRuptureNum() const { assertReadEnabled(); return m_nRuptureNum; } void AecXDbSymbRupture::SetRuptureNum(Adesk::UInt8 num) { AssertWriteEnabled(); m_nRuptureNum = num; } void AecXDbSymbRupture::SetStartPoint(ADSGePoint3d pt) { AssertWriteEnabled(); m_ptStart = pt; } void AecXDbSymbRupture::SetEndPoint(ADSGePoint3d pt) { AssertWriteEnabled(); m_ptEnd = pt; }