#include "stdafx.h" #include "StdArx.h" #include "AecComplexCurveDraw.h" #include "dbsymutl.h" #include "math.h" #include "AecCoverBooleanOper.h" #include "KTSetting.h" #include "KTCADUtilityEx.h" #define COLOR_BYLAYER 256 #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif static const Adesk::UInt16 kColorByLayer = 256; extern AcGePoint3d GetArcMidPoint(AcDbArc* pArc); extern Acad::ErrorStatus AddToModelSpace(AcDbEntity* pEnt,AcDbDatabase* pDb = NULL,bool bClose = true); extern AcGePoint3d MidPoint(const AcGePoint3d& pt1,const AcGePoint3d& pt2); static void FreeBuffer(int n,AcDbVoidPtrArray& arEntPtrs) { AcDbEntity* pEnt = NULL; while(arEntPtrs.length() > n ) { pEnt = (AcDbEntity*)arEntPtrs.last(); if (pEnt != NULL) { pEnt->erase(); pEnt->close(); arEntPtrs.removeLast(); DELETE_PTR(pEnt); } } } AecComplexCurve::AecComplexCurve() { } AecComplexCurve::AecComplexCurve(const AecComplexCurve& src) { m_arCurElements.Append(src.m_arCurElements); //for (int i = 0;i < src.m_arCurElements.GetSize();i++) //{ // m_arCurElements.Add(src.at(i)); //} } AecComplexCurve::~AecComplexCurve() { } AecComplexCurve& AecComplexCurve::operator = (const AecComplexCurve& src) { if (this != &src) { m_arCurElements.RemoveAll(); m_arCurElements.Append(src.m_arCurElements); //for (int i = 0;i < src.m_arCurElements.GetSize();i++) //{ // m_arCurElements.Add(src.at(i)); //} } return *this; } AecComplexCurve& AecComplexCurve::copyFrom(const AecComplexCurve& src) { if (this != &src) { m_arCurElements.RemoveAll(); m_arCurElements.Append(src.m_arCurElements); //for (int i = 0;i < src.m_arCurElements.GetSize();i++) //{ // m_arCurElements.Add(src.at(i)); //} } return *this; } Acad::ErrorStatus AecComplexCurve::transformBy(const AcGeMatrix3d& xform) { for (int i = 0;i < m_arCurElements.GetSize();i++) { AecEqui::AecCurveElement& el = m_arCurElements.ElementAt(i); el.ptGe[0].transformBy(xform); el.ptGe[1].transformBy(xform); el.ptGe[2].transformBy(xform); } return Acad::eOk; } void AecComplexCurve::setColorIndex(int nColor) { for (int i = 0; i < m_arCurElements.GetSize(); i++) { AecEqui::AecCurveElement &el = m_arCurElements.ElementAt(i); el.nColorIndex = nColor; } } AecEqui::AecCurveElement AecComplexCurve::operator [] (int nIndex) { ASSERT(nIndex > -1 && nIndex < m_arCurElements.GetSize()); return m_arCurElements[nIndex]; } const AecEqui::AecCurveElement AecComplexCurve::operator [] (int nIndex) const { ASSERT(nIndex > -1 && nIndex < m_arCurElements.GetSize()); return m_arCurElements.GetAt(nIndex); } AcDbCurve* AecComplexCurve::segat(int nIndex) { ASSERT(nIndex > -1 && nIndex < m_arCurElements.GetSize()); AecEqui::AecCurveElement el = m_arCurElements.GetAt(nIndex); AcDbCurve* pCurve = NULL; if ( el.ptGe[1].isEqualTo(el.ptGe[2]) ) { pCurve = new AcDbLine(el.ptGe[0],el.ptGe[1]); } else { AcDbArc* pArc = NULL; MakeArc(el,pArc); pCurve = pArc; } if (el.idSubLay.isValid()) pCurve->setLayer(el.idSubLay); if (el.idSubLty.isValid()) pCurve->setLinetype(el.idSubLty); return pCurve; } int AecComplexCurve::GetElementType(const AecEqui::AecCurveElement& el) { if (el.ptGe[1].distanceTo(el.ptGe[2]) < 1.e-2) return (int)AecEqui::eLine; return (int)AecEqui::eArc; } BOOL AecComplexCurve::MakeArc(const AecEqui::AecCurveElement& el,AcDbArc*& pArc) { AcDbArc* pArcThis = NULL; AcGeCircArc3d cirArc3d; cirArc3d.set(el.ptGe[0],el.ptGe[1],el.ptGe[2]); AcGeVector3d vtNorm = cirArc3d.normal(); AcDbCircle cir; cir.setCenter(cirArc3d.center()); cir.setRadius(cirArc3d.radius()); cir.setNormal(vtNorm); AcGePoint3dArray arPts; arPts.append(el.ptGe[0]); arPts.append(el.ptGe[2]); AcDbVoidPtrArray arCurPtrs; cir.getSplitCurves(arPts,arCurPtrs); double dPara = 0.0; AcDbCurve* pCurve = NULL; AcDbCurve* pCurvet = NULL; for (int j = 0;j < arCurPtrs.length();j++) { pCurve = (AcDbCurve*)arCurPtrs.at(j); if (pCurve != NULL) { if (Acad::eOk == pCurve->getParamAtPoint(el.ptGe[1],dPara)) { AcDbArc* pArct = AcDbArc::cast(pCurve); if (pArct != NULL) { pArcThis = pArct; arCurPtrs.removeAt(j); pCurvet = (AcDbCurve*)arCurPtrs.first(); DELETE_PTR(pCurvet); pArc = pArct; return TRUE; } } } } return FALSE; } BOOL AecComplexCurve::MakeLine(const AecEqui::AecCurveElement& el,AcDbLine*& pLine) { pLine = new AcDbLine(el.ptGe[0],el.ptGe[1]); return TRUE; } BOOL AecComplexCurve::MakeCurve(const AecEqui::AecCurveElement& el,AcDbCurve*& pCurve) { if (GetElementType(el) == AecEqui::eLine) { AcDbLine* pLine = NULL; MakeLine(el,pLine); pCurve = pLine; } else { AcDbArc* pArc = NULL; MakeArc(el,pArc); pCurve = pArc; } return pCurve != NULL ? TRUE : FALSE; } Acad::ErrorStatus AecComplexCurve::IntersectWith(AecEqui::AecCurveElement& el1,AecEqui::AecCurveElement& el2,AcDb::Intersect nType,AcGePoint3dArray& arPts) { AcDbCurve* pCurve1 = NULL; AecComplexCurve::MakeCurve(el1,pCurve1); AcDbCurve* pCurve2 = NULL; AecComplexCurve::MakeCurve(el2,pCurve2); if (pCurve1 != NULL && pCurve2 != NULL) { pCurve1->intersectWith(pCurve2,nType,arPts); delete pCurve1; delete pCurve2; //TEST //pCurve1->setColorIndex(1); //pCurve2->setColorIndex(2); //AddToModelSpace(pCurve1); //AddToModelSpace(pCurve2); } return arPts.isEmpty() ? Acad::eNotImplemented : Acad::eOk; } BOOL AecComplexCurve::MakeElement(AecEqui::AecCurveElement& el,const AcDbCurve* pCurve) { if (pCurve == NULL) return FALSE; AcDbLine* pLn = AcDbLine::cast(pCurve); if (pLn != NULL) { el.ptGe[0] = pLn->startPoint(); el.ptGe[1] = pLn->endPoint(); el.ptGe[2] = el.ptGe[1]; return TRUE; } AcDbArc* pArc = AcDbArc::cast(pCurve); if (pArc != NULL) { pArc->getStartPoint(el.ptGe[0]); pArc->getEndPoint(el.ptGe[2]); el.ptGe[1] = GetArcMidPoint(pArc); return TRUE; } return FALSE; } Acad::ErrorStatus AecComplexCurve::ExtendTo(AecEqui::AecCurveElement& el,const AcGePoint3d& ptTo) { AcDbCurve* pCurve1 = NULL; AecComplexCurve::MakeCurve(el,pCurve1); if (pCurve1 != NULL) { AcGePoint3d pt1,pt2; pCurve1->getStartPoint(pt1); pCurve1->getEndPoint(pt2); bool bExSta = false; double dDis1 = pt1.distanceTo(ptTo);//Sta-To double dDis2 = pt2.distanceTo(ptTo);//End-To if (dDis1 < dDis2) { bExSta = true; } pCurve1->getClosestPointTo(ptTo,pt1,Adesk::kTrue); pCurve1->extend(bExSta,pt1); AecComplexCurve::MakeElement(el,pCurve1); delete pCurve1; return Acad::eOk; } return Acad::eInvalidInput; } Acad::ErrorStatus AecComplexCurve::dxfOutFields(AcDbDxfFiler* pFiler) const { return Acad::eOk; } Acad::ErrorStatus AecComplexCurve::dxfInFields(AcDbDxfFiler* pFiler) { return Acad::eOk; } Acad::ErrorStatus AecComplexCurve::dwgOutFields(AcDbDwgFiler* pFiler) const { Adesk::Int32 nLen = m_arCurElements.GetSize(); pFiler->writeInt32(nLen); for (int i = 0;i < nLen;i++) { const AecEqui::AecCurveElement& el = m_arCurElements.GetAt(i); pFiler->writePoint3d(el.ptGe[0]); pFiler->writePoint3d(el.ptGe[1]); pFiler->writePoint3d(el.ptGe[2]); pFiler->writeInt16(el.bHided); pFiler->writeInt32(el.gsMark); pFiler->writeDouble(el.dWidth); } return Acad::eOk; } Acad::ErrorStatus AecComplexCurve::dwgInFields(AcDbDwgFiler* pFiler) { Adesk::Int32 nLen = 0; pFiler->readInt32(&nLen); m_arCurElements.RemoveAll(); AecEqui::AecCurveElement el; for (int i = 0;i < nLen;i++) { pFiler->readPoint3d(&el.ptGe[0]); pFiler->readPoint3d(&el.ptGe[1]); pFiler->readPoint3d(&el.ptGe[2]); pFiler->readInt16(&el.bHided); Adesk::Int32 nVal = 0; pFiler->readInt32(&nVal); el.gsMark = nVal; pFiler->readDouble(&el.dWidth); m_arCurElements.Add(el); } return Acad::eOk; } AecEqui::AecCurveElement AecComplexCurve::at(int nIndex) const { ASSERT(nIndex > -1 && nIndex < m_arCurElements.GetSize()); return m_arCurElements.GetAt(nIndex); } AecEqui::AecCurveElement& AecComplexCurve::atByRef(int nIndex) { ASSERT(nIndex > -1 && nIndex < m_arCurElements.GetSize()); return m_arCurElements.ElementAt(nIndex); } const AecEqui::AecCurveElement& AecComplexCurve::atByCstRef(int nIndex) const { ASSERT(nIndex > -1 && nIndex < m_arCurElements.GetSize()); return m_arCurElements.ElementAt(nIndex); } AecComplexCurve& AecComplexCurve::setAt(int nIndex, AecEqui::AecCurveElement& value) { m_arCurElements.SetAt(nIndex,value); return *this; } AecEqui::AecCurveElement AecComplexCurve::first() { ASSERT(m_arCurElements.GetSize() > 0); return m_arCurElements[0]; } const AecEqui::AecCurveElement AecComplexCurve::first() const { ASSERT(m_arCurElements.GetSize() > 0); return m_arCurElements[0]; } AecEqui::AecCurveElement AecComplexCurve::last() { ASSERT(m_arCurElements.GetSize() > 0); return m_arCurElements[m_arCurElements.GetSize() - 1]; } const AecEqui::AecCurveElement AecComplexCurve::last() const { ASSERT(m_arCurElements.GetSize() > 0); return m_arCurElements.GetAt(m_arCurElements.GetSize() - 1); } int AecComplexCurve::append(const AecEqui::AecCurveElement& value) { m_arCurElements.Add((AecEqui::AecCurveElement&)value); return (int)(m_arCurElements.GetSize() - 1); } AecComplexCurve& AecComplexCurve::append(const AecComplexCurve& src) { AecEqui::AecCurveElement el; for (int i = 0;i < src.m_arCurElements.GetSize();i++) { el = src.at(i); m_arCurElements.Add(el); } return *this; } int AecComplexCurve::append(AcDbCurve* pCurve) { if (pCurve == NULL) return -1; AecEqui::AecCurveElement el; memset(&el,0,sizeof(AecEqui::AecCurveElement)); AcDbPolyline* pPl = AcDbPolyline::cast(pCurve); if (pPl != NULL) { int nIndex = -1; AcDbVoidPtrArray arSegs; pPl->explode(arSegs); AcDbCurve* pCurveT = NULL; for(int i = 0;i < arSegs.length();i++) { pCurveT = (AcDbCurve*)arSegs.at(i); if ( MakeElement(el,pCurveT) ) { nIndex = append(el); } delete pCurveT; } return nIndex; } else { if ( MakeElement(el,pCurve) ) { return append(el); } } return -1; } AecEqui::AecCurveElement AecComplexCurve::removeAt(int nIndex) { ASSERT(nIndex > -1 && nIndex < m_arCurElements.GetSize()); AecEqui::AecCurveElement el = m_arCurElements.GetAt(nIndex); m_arCurElements.RemoveAt(nIndex); return el; } BOOL AecComplexCurve::remove(AecEqui::AecCurveElement& value, int start) { BOOL bSuccess = FALSE; AecEqui::AecCurveElement el; memset(&el,0,sizeof(AecEqui::AecCurveElement)); int i = start; while(i < m_arCurElements.GetSize()) { el = m_arCurElements.GetAt(i); if (isEqual(el,value)) { m_arCurElements.RemoveAt(i); bSuccess = TRUE; } else { i++; } } return bSuccess; } BOOL AecComplexCurve::isEqual(const AecEqui::AecCurveElement& value1,const AecEqui::AecCurveElement& value2) const { if (value1.ptGe[0].distanceTo(value2.ptGe[0]) < 1.e-6 && value1.ptGe[1].distanceTo(value2.ptGe[1]) < 1.e-6 && value1.ptGe[2].distanceTo(value2.ptGe[2]) < 1.e-6) { return TRUE; } return FALSE; } BOOL AecComplexCurve::CanBoolUnite(const AecEqui::AecCurveElement& el) const { //判断el 的起始点是否和空白处连接 AcGePoint3dArray arPts; for (int i = 0;i < m_arCurElements.GetSize();i++) { const AecEqui::AecCurveElement& elThis = m_arCurElements.ElementAt(i); if (arPts.find(elThis.ptGe[0]) == -1) { arPts.append(elThis.ptGe[0]); } if (arPts.find(elThis.ptGe[2]) == -1) { arPts.append(elThis.ptGe[2]); } } if (arPts.find(el.ptGe[0]) != -1 || arPts.find(el.ptGe[2]) != -1)//表示有可能首尾相接 { int nFoundAt = -1; if (!find(el,nFoundAt,0)) { return TRUE; } } return FALSE; } int AecComplexCurve::logicalLength() const { return (int)m_arCurElements.GetSize(); } void AecComplexCurve::setLogicalLength(int nIndex) { if (nIndex == 0) { m_arCurElements.RemoveAll(); } } void AecComplexCurve::removeAll() { m_arCurElements.RemoveAll(); } AecEqui::AecCurveElement AecComplexCurve::removeFirst() { ASSERT(m_arCurElements.GetSize() > 0); AecEqui::AecCurveElement el = m_arCurElements.GetAt(0); m_arCurElements.RemoveAt(0); return el; } AecEqui::AecCurveElement AecComplexCurve::removeLast() { ASSERT(m_arCurElements.GetSize() > 0); AecEqui::AecCurveElement el = m_arCurElements.GetAt(m_arCurElements.GetSize() - 1); m_arCurElements.RemoveAt(m_arCurElements.GetSize() - 1); return el; } BOOL AecComplexCurve::find(const AecEqui::AecCurveElement& value, int& foundAt,int start) const { BOOL bSuccess = FALSE; AecEqui::AecCurveElement el; memset(&el,0,sizeof(AecEqui::AecCurveElement)); int i = start; while(i < m_arCurElements.GetSize()) { el = m_arCurElements.GetAt(i); if (isEqual(el,value)) { foundAt = i; break; } else { i++; } } return bSuccess; } int AecComplexCurve::length() const { return (int)m_arCurElements.GetSize(); } BOOL AecComplexCurve::isEmpty() const { return (m_arCurElements.GetSize() == 0) ? TRUE : FALSE; } void AecComplexCurve::setSubElementGsMark(int nGsMark) { for (int i = 0;i < m_arCurElements.GetSize();i++) { m_arCurElements[i].gsMark = nGsMark; } } typedef struct PointParam { AcGePoint3d ptOn; double dParam; }POINTPARAM; static bool ComparePtparam(PointParam ptParam1,PointParam ptParam2) { if (ptParam1.dParam - ptParam2.dParam < 1.e-10) { return true; } return false; } void SortPoints(AcGePoint3dArray& points,AcDbCurve* pLine) { PointParam ptParam; std::vector points2; for (int i = 0;i < points.length();i++) { ptParam.ptOn = points.at(i); pLine->getParamAtPoint(points.at(i),ptParam.dParam); points2.push_back(ptParam); } std::sort(points2.begin(),points2.end(),ComparePtparam); points.setLogicalLength(0); std::vector::iterator it; for (it = points2.begin(); it < points2.end(); it++) { points.append((*it).ptOn); } } bool AecComplexCurve::merge(AecEqui::AecCurveElement& el0,AecEqui::AecCurveElement& el1,AecEqui::AecCurveElement*& pelAdd) { pelAdd = NULL; //效率不高的办法 if (el0.bHided != el1.bHided)//属性一致 { return false; } //实线虚线要一致 if (el0.gsMark != el1.gsMark) //属性一致 return false; //线形一致 if (el0.idSubLty != el1.idSubLty)//线形一致 return false; if (el0.ptGe[2].distanceTo(el0.ptGe[1]) < 1.e-6)//line { if (el1.ptGe[2].distanceTo(el1.ptGe[1]) < 1.e-6)//line { //判断线是否首尾连接 //判断线是否有交集 AcGeVector3d vt1 = el0.ptGe[2] - el0.ptGe[0]; AcGeVector3d vt2 = el1.ptGe[2] - el1.ptGe[0]; if (vt1.isParallelTo(vt2))//平行 { AcDbLine ln(el0.ptGe[2],el0.ptGe[0]); AcGePoint3d ptTemp; ln.getClosestPointTo(el1.ptGe[0],ptTemp,Adesk::kTrue); if (ptTemp.distanceTo(el1.ptGe[0]) < 1.e-6)//共线 { //长度之和<=总长 有关系 double dL1 = vt1.length(); double dL2 = vt2.length(); AcGePoint3dArray arPts; arPts.append(el0.ptGe[0]); arPts.append(el0.ptGe[2]); arPts.append(el1.ptGe[0]); arPts.append(el1.ptGe[2]); SortPoints(arPts,&ln); double dL = arPts.first().distanceTo(arPts.last());//合成后的总长 if ( (dL - ( dL1 + dL2) ) < 1.e-6)//有交集和连接 L<=L1+L2 { el0.ptGe[0] = arPts.first(); el0.ptGe[1] = arPts.last(); el0.ptGe[2] = arPts.last(); return true; } } } } } else//arc { //比较啰嗦,没有找到更好的办法 if (el1.ptGe[2].distanceTo(el1.ptGe[1]) > 1.e-3) { AcDbArc* pArc0 = NULL; AcDbArc* pArc1 = NULL; MakeArc(el0,pArc0); MakeArc(el1,pArc1); if (pArc0 != NULL && pArc1 != NULL) { double dR = pArc0->radius(); double dr = pArc1->radius(); if ( fabs(dr - dR) < 1.e-6)//共r { if (pArc0->center().distanceTo(pArc1->center()) < 1.e-6)//共心 { //起点或终点落在对方上,有交集关系 double dPa = 0.0; if ( Acad::eOk == pArc0->getParamAtPoint(el1.ptGe[0],dPa) || Acad::eOk == pArc0->getParamAtPoint(el1.ptGe[2],dPa) || Acad::eOk == pArc1->getParamAtPoint(el0.ptGe[0],dPa) || Acad::eOk == pArc1->getParamAtPoint(el0.ptGe[2],dPa) ) { AcGePoint3dArray arPts; //找延申出的点 double dT = 0.0; if ( Acad::eOk != pArc0->getParamAtPoint(el1.ptGe[0],dT)) { arPts.append(el1.ptGe[0]); } if ( Acad::eOk != pArc0->getParamAtPoint(el1.ptGe[2],dT)) { arPts.append(el1.ptGe[2]); } AcGePoint3d ptOn1,ptOn2; if (arPts.length() == 1)//外部一个点 el1 局部属于el0 { //外部点,判断靠近sta,or end pArc0->getClosestPointTo(arPts.first(),ptOn1,Adesk::kFalse); pArc0->getClosestPointTo(arPts.first(),ptOn2,Adesk::kFalse); double dL1 = ptOn1.distanceTo(el0.ptGe[0]); double dL2 = ptOn2.distanceTo(el0.ptGe[2]); if ( (dL1 - dL2) < 1.e-6)//靠近sta { el0.ptGe[0] = arPts.first(); } else//靠近end { el0.ptGe[2] = arPts.first(); } return true; } else if (arPts.length() == 2)//外部2个点 el0 属于 el1 { //大包围 el0.ptGe[0] = arPts.first(); el0.ptGe[2] = arPts.last(); delete pArc0; delete pArc1; return true; } else//外部没有点; el1 属于 el0; 或组成圆 { //取最大的圆弧 double dE0 = 0.0,dE1 = 0.0; pArc0->getEndParam(dE0); pArc1->getEndParam(dE1); double dL0 = 0.0,dL1 = 0.0; pArc0->getDistAtParam(dE0,dL0); pArc1->getDistAtParam(dE1,dL1); AcDbArc* pArcMax = NULL; AcDbArc* pArcMin = NULL; if (dL0 > dL1)//el0 最大 { pArcMax = pArc0; pArcMin = pArc1; } else { pArcMax = pArc1; pArcMin = pArc0; } //取反弧 ptOn1 = GetArcMidPoint(pArcMax); AcGeVector3d vt1 = pArcMax->center() - ptOn1; ptOn1 = pArcMax->center() + vt1; AcGePoint3d pt1,pt2; pArcMax->getStartPoint(pt1); pArcMax->getEndPoint(pt2); AcDbArc* pArcF = AecCoverBooleanOper::FormatArc(pt1,ptOn1,pt2); if (pArcF != NULL) { pArcF->getStartPoint(pt1); pArcF->getEndPoint(pt2); //反弧的点落在对方弧上 if ( Acad::eOk == pArcMin->getParamAtPoint(pt1,dE0) && Acad::eOk == pArcMin->getParamAtPoint(pt2,dE1)) { //el0,el1合成圆 pArcMax->getStartPoint(el0.ptGe[0]); pArcMax->getEndPoint(el0.ptGe[2]); el0.ptGe[1] = GetArcMidPoint(pArcMax); pelAdd = new AecEqui::AecCurveElement; memcpy(pelAdd,&el0,sizeof(AecEqui::AecCurveElement)); pArcF->getStartPoint(el0.ptGe[0]); pArcF->getEndPoint(el0.ptGe[2]); el0.ptGe[1] = GetArcMidPoint(pArcF); delete pArc0; delete pArc1; delete pArcF; return TRUE; } delete pArcF; } //取最大的弧 pArcMax->getStartPoint(el0.ptGe[0]); pArcMax->getEndPoint(el0.ptGe[2]); el0.ptGe[1] = GetArcMidPoint(pArcMax); delete pArc0; delete pArc1; return true; } delete pArc0; delete pArc1; return false; } else { //没有交集,不可以并 } } } delete pArc0; delete pArc1; } } } return false; } void AecComplexCurve::merge() { AecEqui::AecCurveElement* pelT = NULL; int nPos = 0; while( nPos < m_arCurElements.GetSize() ) { AecEqui::AecCurveElement& el = m_arCurElements.GetAt(nPos); for (int j = nPos + 1;j < m_arCurElements.GetSize();j++) { AecEqui::AecCurveElement& el0 = m_arCurElements.GetAt(j); pelT = NULL; if ( merge(el,el0,pelT)) { if (pelT != NULL) { //合成圆 m_arCurElements.SetAt(j,*pelT); nPos ++; break; } else { m_arCurElements.RemoveAt(j); j -= 1; } } } nPos++; } } void AecComplexCurve::boolSubtract() { //先取出所有的挖空线 //然后余下的实线布尔减 CArray arSub; CArray arRel; for (int j = 0;j < m_arCurElements.GetSize();j++) { AecEqui::AecCurveElement& el = m_arCurElements.GetAt(j); if (el.bHided)//隐藏 { arSub.Add(el); } else { arRel.Add(el); } } CArray arEl; for (int i = 0;i < arRel.GetSize();i++) { AecEqui::AecCurveElement& elR = arRel.GetAt(i); for (int n = 0;n < arSub.GetSize();n++) { AecEqui::AecCurveElement& elH = arSub.GetAt(n); if ( -1 == boolSubtract(elR,elH,arEl) ) { //不处理 arEl.Add(elR); } else { //处理结果已经在arEl中 } } } m_arCurElements.RemoveAll(); if (!arEl.IsEmpty()) { m_arCurElements.Append(arEl); } } int AecComplexCurve::boolSubtract(AecEqui::AecCurveElement& el0,AecEqui::AecCurveElement& el1,CArray& arEl0) { AecEqui::AecCurveElement elT; memcpy(&elT,&el0,sizeof(AecEqui::AecCurveElement)); if (el0.ptGe[2].distanceTo(el0.ptGe[1]) < 1.e-6 && el1.ptGe[2].distanceTo(el1.ptGe[1]) < 1.e-6 )//line { //判断线是否首尾连接 //判断线是否有交集 AcGeVector3d vt1 = el0.ptGe[2] - el0.ptGe[0]; AcGeVector3d vt2 = el1.ptGe[2] - el1.ptGe[0]; if (vt1.isParallelTo(vt2))//平行 { AcDbLine ln; ln.setStartPoint(el0.ptGe[0]); ln.setEndPoint(el0.ptGe[2]); AcGePoint3d ptOn; ln.getClosestPointTo(el1.ptGe[0],ptOn,Adesk::kTrue); double dDis = ptOn.distanceTo(el1.ptGe[0]); if (dDis < 1.e-3 )//共线 { AcDbLine* pLn0 = NULL; AcDbLine* pLn1 = NULL; MakeLine(el0,pLn0); MakeLine(el1,pLn1); //起点或终点落在对方上,有关系 double dPa = 0.0; if (Acad::eOk == pLn0->getParamAtPoint(el1.ptGe[0],dPa) || Acad::eOk == pLn0->getParamAtPoint(el1.ptGe[2],dPa) || Acad::eOk == pLn1->getParamAtPoint(el0.ptGe[0],dPa) || Acad::eOk == pLn1->getParamAtPoint(el0.ptGe[2],dPa)) { AcGePoint3dArray arPts; arPts.append(el0.ptGe[0]); arPts.append(el0.ptGe[2]); if (arPts.find(el1.ptGe[0]) == -1) arPts.append(el1.ptGe[0]); if (arPts.find(el1.ptGe[2]) == -1) arPts.append(el1.ptGe[2]); SortPoints(arPts,&ln); //重合 if (arPts.length() == 2) return arEl0.GetSize(); for (int i = 0;i < arPts.length() - 1;i++) { ptOn = MidPoint(arPts.at(i),arPts.at(i+1)); vt1 = ptOn - el1.ptGe[0]; vt2 = ptOn - el1.ptGe[2]; if (vt1.isCodirectionalTo(vt2))//同向,在虚之外 { vt1 = ptOn - el0.ptGe[0]; vt2 = ptOn - el0.ptGe[2]; if (!vt1.isCodirectionalTo(vt2))//同向,在实之内 { elT.ptGe[0] = arPts.at(i); elT.ptGe[1] = arPts.at(i+1); elT.ptGe[2] = elT.ptGe[1]; arEl0.Add(elT); } } } //处理结果 return arEl0.GetSize(); } else { return -1;//不处理 } } else { return -1;////不处理 } } else { return -1;//不处理 } } else { AcDbArc* pArc0 = NULL; AcDbArc* pArc1 = NULL; MakeArc(el0,pArc0); MakeArc(el1,pArc1); if (pArc0 != NULL && pArc1 != NULL) { double dR = pArc0->radius(); double dr = pArc1->radius(); if ( fabs(dr - dR) < 1.e-6)//共半径 { if (pArc0->center().distanceTo(pArc1->center()) < 1.e-6)//共圆心 { //起点或终点落在对方上,有关系 double dPa = 0.0; if ( Acad::eOk == pArc0->getParamAtPoint(el1.ptGe[0],dPa) || Acad::eOk == pArc0->getParamAtPoint(el1.ptGe[2],dPa) || Acad::eOk == pArc1->getParamAtPoint(el0.ptGe[0],dPa) || Acad::eOk == pArc1->getParamAtPoint(el0.ptGe[2],dPa)) { AcGePoint3dArray arPts; arPts.append(el0.ptGe[0]); arPts.append(el0.ptGe[2]); if (arPts.find(el1.ptGe[0]) == -1) arPts.append(el1.ptGe[0]); if (arPts.find(el1.ptGe[2]) == -1) arPts.append(el1.ptGe[2]); //重合 if (arPts.length() == 2) { AcGePoint3d ptS0, ptS1; pArc0->getStartPoint(ptS0); pArc1->getStartPoint(ptS1); if (ptS0.distanceTo(ptS1) < 1.e-3) { return arEl0.GetSize(); } } AcDbCircle cir; cir.setCenter(pArc0->center()); cir.setRadius(pArc0->radius()); cir.setNormal(pArc0->normal()); SortPoints(arPts,&cir); AcDbVoidPtrArray arCurPtrs; cir.getSplitCurves(arPts,arCurPtrs); //去掉在虚的上的 double dT = 0.0; AcGePoint3d ptOn; AcDbArc* pArcT = NULL; for (int i = 0;i < arCurPtrs.length();i++) { pArcT = (AcDbArc*)arCurPtrs.at(i); ptOn = GetArcMidPoint(pArcT); if ( Acad::eOk == pArc1->getParamAtPoint(ptOn,dT)) { arCurPtrs.removeAt(i); i -= 1; delete pArcT; continue; } } //拾取在实的上的 for (int i = 0;i < arCurPtrs.length();i++) { pArcT = (AcDbArc*)arCurPtrs.at(i); ptOn = GetArcMidPoint(pArcT); if (Acad::eOk == pArc0->getParamAtPoint(ptOn,dT)) { MakeElement(elT,pArcT); arEl0.Add(elT); delete pArcT; arCurPtrs.removeAt(i); i -= 1; } } //余下的释放 FreeBuffer(0,arCurPtrs); //处理结果 return arEl0.GetSize(); } else { delete pArc0; delete pArc1; return -1;//不处理 } } else { delete pArc0; delete pArc1; return -1;//不处理 } } else { delete pArc0; delete pArc1; return -1;//不处理 } } } return -1;//不处理 } void AecComplexCurve::OrthoProjectedToXYPlane(double dz ) { for (int j = 0;j < m_arCurElements.GetSize();j++) { AecEqui::AecCurveElement& el = m_arCurElements.GetAt(j); el.ptGe[0].z = dz; el.ptGe[1].z = dz; el.ptGe[2].z = dz; } } AcDbPolyline* AecComplexCurve::MakePoly() const { AcDbCurve* pCurve = NULL; AcDbVoidPtrArray arCurPtrs,arRes; for (int j = 0; j < m_arCurElements.GetSize(); j++) { const AecEqui::AecCurveElement &el = m_arCurElements.GetAt(j); if (AecComplexCurve::MakeCurve(el, pCurve)) { arCurPtrs.append(pCurve); } } AcDbPolyline* pPl = (AcDbPolyline *)KTCADUtilityEx::ConvertBoundCurve(arCurPtrs, arRes); return pPl; } AecComplexCurveDraw::AecComplexCurveDraw() { m_bHideDraw = 0; } AecComplexCurveDraw::~AecComplexCurveDraw() { } AecComplexCurveDraw::AecComplexCurveDraw(const AecComplexCurveDraw& src) { m_idOwner = src.m_idOwner; if (src.m_curEdage.length() > 0) { m_curEdage = src.m_curEdage; m_bHideDraw = src.m_bHideDraw; } } void AecComplexCurveDraw::SetOwnerId(AcDbObjectId& id) { m_idOwner = id; } AcDbObjectId AecComplexCurveDraw::GetOwnerId() { return m_idOwner; } void AecComplexCurveDraw::SetEdage(const AecComplexCurve& curEdage) { m_curEdage.removeAll(); for (int i = 0; i < curEdage.length(); i++) { m_curEdage.append(curEdage.at(i)); } } BOOL AecComplexCurveDraw::RemoveEdage() { m_curEdage.removeAll(); return TRUE; } BOOL AecComplexCurveDraw::GetEdage(AecComplexCurve& curEdage) { for (int i = 0; i < m_curEdage.length(); i++) { curEdage.append(m_curEdage.at(i)); } return TRUE; } AecComplexCurve& AecComplexCurveDraw::GetRefEdage() { return m_curEdage; } const AecComplexCurve& AecComplexCurveDraw::GetRefEdage() const { return m_curEdage; } void AecComplexCurveDraw::SetHideDraw(Adesk::Int32 bHideDraw) { m_bHideDraw = bHideDraw; } Adesk::Int32 AecComplexCurveDraw::GetHideDraw() const { return m_bHideDraw; } void AecComplexCurveDraw::ExtendStartAndEnd(double dExtLen) { AcGeTol tol; tol.setEqualPoint(1); AcGeVector3d vtExtent; int i(0); for (i = 0; i < m_curEdage.length(); i++) { if (m_curEdage.atByRef(i).ptGe[1].isEqualTo(m_curEdage.atByRef(i).ptGe[2], tol)) // 直线 { vtExtent = (m_curEdage.atByRef(i).ptGe[1] - m_curEdage.atByRef(i).ptGe[0]).normalize() * dExtLen; m_curEdage.atByRef(i).ptGe[0] -= vtExtent; m_curEdage.atByRef(i).ptGe[1] += vtExtent; m_curEdage.atByRef(i).ptGe[2] = m_curEdage.atByRef(i).ptGe[1]; } else // 圆弧,少数情况 { AcGeCircArc3d arc(m_curEdage.atByRef(i).ptGe[0], m_curEdage.atByRef(i).ptGe[1], m_curEdage.atByRef(i).ptGe[2]); // double dPercent = dExtLen / (arc.radius() * 2 * PI); // double dRote = PI*2 * dPercent; // 换算如下 double dRote = dExtLen / arc.radius(); AcGeVector3d vtNormal = arc.normal(); AcGePoint3d ptCenter = arc.center(); m_curEdage.atByRef(i).ptGe[0].rotateBy(-dRote, vtNormal, ptCenter); m_curEdage.atByRef(i).ptGe[2].rotateBy(dRote, vtNormal, ptCenter); } } } BOOL AecComplexCurveDraw::GetEdage(AecComplexCurve& curEdage) const { for (int i = 0; i < m_curEdage.length(); i++) { curEdage.append(m_curEdage.at(i)); } return TRUE; } BOOL AecComplexCurveDraw::HasEdage() const { return m_curEdage.isEmpty() ? FALSE : TRUE; } void AecComplexCurveDraw::merge() { m_curEdage.merge(); } void AecComplexCurveDraw::boolSubtract() { m_curEdage.boolSubtract(); } AecComplexCurveDraw& AecComplexCurveDraw::operator = (const AecComplexCurveDraw& src) { if (this != &src) { m_idOwner = src.m_idOwner; m_curEdage.setLogicalLength(0); for (int i = 0; i < src.m_curEdage.length(); i++) { m_curEdage.append(src.m_curEdage.at(i)); } } return *this; } void AecComplexCurveDraw::SetColor(int nColor) { for (int i = 0; i < m_curEdage.length(); i++) { m_curEdage.atByRef(i).nColorIndex = nColor; } } AecComplexCurveDraw& AecComplexCurveDraw::copyFrom(const AecComplexCurveDraw& src) { if (this != &src) { m_idOwner = src.m_idOwner; m_bHideDraw = src.m_bHideDraw; m_curEdage.setLogicalLength(0); for (int i = 0; i < src.m_curEdage.length(); i++) { m_curEdage.append(src.m_curEdage.at(i)); } } return *this; } Acad::ErrorStatus AecComplexCurveDraw::dxfOutFields(AcDbDxfFiler* pFiler) const { return pFiler->filerStatus(); } Acad::ErrorStatus AecComplexCurveDraw::dxfInFields(AcDbDxfFiler* pFiler) { return pFiler->filerStatus(); } Acad::ErrorStatus AecComplexCurveDraw::dwgOutFields(AcDbDwgFiler* pFiler, Adesk::UInt32 nVer) const { if (pFiler != NULL) { pFiler->writeSoftPointerId(m_idOwner); pFiler->writeInt32(m_bHideDraw); Adesk::UInt32 lLen = m_curEdage.length(); pFiler->writeUInt32(lLen); for (Adesk::UInt32 i = 0; i < lLen; i++) { pFiler->writePoint3d(m_curEdage.at(i).ptGe[0]); pFiler->writePoint3d(m_curEdage.at(i).ptGe[1]); pFiler->writePoint3d(m_curEdage.at(i).ptGe[2]); pFiler->writeInt16(m_curEdage.at(i).bHided); pFiler->writeInt32(m_curEdage.at(i).gsMark); pFiler->writeDouble(m_curEdage.at(i).dWidth); //补充 if (nVer > 1) { pFiler->writeSoftPointerId(m_curEdage.at(i).idSubLay); pFiler->writeSoftPointerId(m_curEdage.at(i).idSubLty); pFiler->writeUInt16(m_curEdage.at(i).nColorIndex); } } } return pFiler->filerStatus(); } Acad::ErrorStatus AecComplexCurveDraw::dwgInFields(AcDbDwgFiler* pFiler,Adesk::UInt32 nVer) { if (pFiler != NULL) { pFiler->readSoftPointerId(&m_idOwner); pFiler->readInt32(&m_bHideDraw); AecEqui::AecCurveElement curEl; memset(&curEl, 0, sizeof(AecEqui::AecCurveElement)); Adesk::UInt32 lLen = 0l; pFiler->readUInt32(&lLen); m_curEdage.setLogicalLength(0); for (Adesk::UInt32 i = 0; i < lLen; i++) { pFiler->readPoint3d(&curEl.ptGe[0]); pFiler->readPoint3d(&curEl.ptGe[1]); pFiler->readPoint3d(&curEl.ptGe[2]); pFiler->readInt16((Adesk::Int16*)&curEl.bHided); pFiler->readInt32((Adesk::Int32*)&curEl.gsMark); pFiler->readDouble(&curEl.dWidth); //补充 if (nVer > 1) { AcDbSoftPointerId idT; pFiler->readSoftPointerId(&idT); curEl.idSubLay = idT; pFiler->readSoftPointerId(&idT); curEl.idSubLty = idT; pFiler->readUInt16(&curEl.nColorIndex); } m_curEdage.append(curEl); } } return pFiler->filerStatus(); } void AecComplexCurveDraw::OrthProjectEl2XYPlan(AecEqui::AecCurveElement& el) const { AcGePoint3d ptGe; for (int i = 0; i < 3; i++) { ptGe = el.ptGe[i].orthoProject(AcGePlane::kXYPlane); el.ptGe[i] = ptGe; } } Adesk::Boolean AecComplexCurveDraw::Draw2d(AcGiDraw &dc, const AcDbObjectId& idReal, const AcDbObjectId& idDash, const AcDbObjectId& idCen, AecEqui::AecCurveElement* pElTmpl, BOOL bWeight, BOOL bCenWeight, double dPScale) const { //从注册表中读取显示方式 AcDbObjectId idOld, idOldLt; BOOL bHideDraw = m_bHideDraw; int nColorIndexOld = -1, nCount = 0; nColorIndexOld = dc.GetColor(); //显示 AecEqui::AecCurveElement el; memset(&el, 0, sizeof(AecEqui::AecCurveElement)); nColorIndexOld = dc.GetColor(); dc.SetColor(kColorByLayer); for (int i = 0; i < m_curEdage.length(); i++) { el = m_curEdage.at(i); if (el.gsMark == -2) { dc.SetColor(el.nColorIndex); } //投影到XY面 OrthProjectEl2XYPlan(el); //宽度属性 if (pElTmpl != NULL) { el.dWidth = pElTmpl->dWidth; } if (el.ptGe[1].distanceTo(el.ptGe[2]) < AcGeContext::gTol.equalPoint()) //直线 { if (el.bHided) // 虚线 + 画 { if (bHideDraw)//显示 { if (el.gsMark == -1)//中心线 { idOldLt = dc.GetLineTypeId(); idOld = dc.GetLayerId(); if (!el.idSubLay.isValid()) { dc.SetColorLayer(COLOR_BYLAYER, idDash); } else { dc.SetColorLayer(COLOR_BYLAYER, el.idSubLay); } if (el.idSubLty.isValid()) { dc.SetLineType(el.idSubLty); } if (el.dWidth > 1.e-6) //有宽度 { if (bCenWeight) //中心线,且宽度显示 { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl); if (pPl != NULL) { pPl->setConstantWidth(el.dWidth * dPScale); dc.DrawPolyline(*pPl); DELETE_PTR(pPl); } } else //有宽度,不显示,画单线 { dc.DrawLine(AcGeLineSeg3d(el.ptGe[0], el.ptGe[1])); } } else //没有宽度 { dc.DrawLine(AcGeLineSeg3d(el.ptGe[0], el.ptGe[1])); } dc.SetLayer(idOld); dc.SetLineType(idOldLt); } else //非中心线 { idOld = dc.GetLayerId(); idOldLt = dc.GetLineTypeId(); if (!el.idSubLay.isValid()) { dc.SetLayer(idDash); dc.SetColorLayer(COLOR_BYLAYER, idDash); } else { dc.SetLayer(el.idSubLay); dc.SetColorLayer(COLOR_BYLAYER, el.idSubLay); } if (el.idSubLty.isValid()) { dc.SetLineType(el.idSubLty); } if (el.dWidth > 1.e-6) //有宽度 { if (bWeight) //中心线,且宽度显示 { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl); if (pPl != NULL) { if (el.gsMark == -2) pPl->setColorIndex(el.nColorIndex); pPl->setConstantWidth(el.dWidth * dPScale); dc.DrawPolyline(*pPl); DELETE_PTR(pPl); } } else //有宽度,但不显示,画单线 { dc.DrawLine(AcGeLineSeg3d(el.ptGe[0], el.ptGe[1])); } } else { dc.DrawLine(AcGeLineSeg3d(el.ptGe[0], el.ptGe[1])); } dc.SetLayer(idOld); dc.SetLineType(idOldLt); } } } else // 实线 { if (el.gsMark == -1) //中心线 { idOldLt = dc.GetLineTypeId(); idOld = dc.GetLayerId(); if (!el.idSubLay.isValid()) { dc.SetLayer(idCen); dc.SetColorLayer(COLOR_BYLAYER, idCen); } else { dc.SetLayer(el.idSubLay); dc.SetColorLayer(COLOR_BYLAYER, el.idSubLay); } if (el.idSubLty.isValid()) { dc.SetLineType(el.idSubLty); } if (el.dWidth > 1.e-6 && bCenWeight) { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl); if (pPl != NULL) { pPl->setConstantWidth(el.dWidth * dPScale); dc.DrawPolyline(*pPl); DELETE_PTR(pPl); } } else { dc.DrawLine(AcGeLineSeg3d(el.ptGe[0], el.ptGe[1])); } dc.SetLayer(idOld); dc.SetLineType(idOldLt); } else //非中心线 { if (el.ptGe[0].distanceTo(el.ptGe[1]) > 1.e-10) //不重合 { idOldLt = dc.GetLineTypeId(); idOld = dc.GetLayerId(); if (!el.idSubLay.isValid()) { dc.SetLayer(idReal); dc.SetColorLayer(COLOR_BYLAYER, idReal); if (el.gsMark == -2)//隔板线 { dc.SetColorLayer(el.nColorIndex, idReal); //隔板线保持 实线 AcDbObjectId idLineType = KTSetting::InitLineStyle(_T("CONTINUOUS")); dc.SetLineType(idLineType); } } else { dc.SetLayer(el.idSubLay); dc.SetColorLayer(COLOR_BYLAYER, el.idSubLay); if (el.gsMark == -2)//隔板线 { dc.SetColorLayer(el.nColorIndex, idReal); //隔板线保持 实线 AcDbObjectId idLineType = KTSetting::InitLineStyle(_T("CONTINUOUS")); dc.SetLineType(idLineType); } } if (el.idSubLty.isValid()) { dc.SetLineType(el.idSubLty); } if (el.dWidth > 1.e-6 && bWeight) { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl); if (pPl != NULL) { if (el.gsMark == -2) pPl->setColorIndex(el.nColorIndex); pPl->setConstantWidth(el.dWidth * dPScale); dc.DrawPolyline(*pPl); DELETE_PTR(pPl); } } else { dc.DrawLine(AcGeLineSeg3d(el.ptGe[0], el.ptGe[1])); } dc.SetLayer(idOld); dc.SetLineType(idOldLt); } } } } else //ARC 圆弧 { if (el.bHided)// 虚线 + 画 { if (bHideDraw) //显示 { if (el.gsMark == -1) //中心线 { idOldLt = dc.GetLineTypeId(); idOld = dc.GetLayerId(); if (!el.idSubLay.isValid()) { dc.SetLayer(idDash); dc.SetColorLayer(COLOR_BYLAYER, idDash); } else { dc.SetLayer(el.idSubLay); dc.SetColorLayer(COLOR_BYLAYER, el.idSubLay); } if (el.idSubLty.isValid()) { dc.SetLineType(el.idSubLty); } if (el.dWidth > 1.e-6 && bCenWeight) { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl, TRUE); if (pPl != NULL) { pPl->setConstantWidth(el.dWidth * dPScale); dc.DrawPolyline(*pPl); DELETE_PTR(pPl); } } else { //判断是否是三维 { dc.DrawCircularArc(el.ptGe[0], el.ptGe[1], el.ptGe[2]); } } dc.SetLayer(idOld); dc.SetLineType(idOldLt); } else //非中心线 { if (el.ptGe[0].distanceTo(el.ptGe[1]) > 1.e-10) //不重合 { idOldLt = dc.GetLineTypeId(); idOld = dc.GetLayerId(); if (!el.idSubLay.isValid()) { dc.SetLayer(idDash); dc.SetColorLayer(COLOR_BYLAYER, idDash); } else { dc.SetLayer(el.idSubLay); dc.SetColorLayer(COLOR_BYLAYER, el.idSubLay); } if (el.idSubLty.isValid()) { dc.SetLineType(el.idSubLty); } if (el.dWidth > 1.e-6 && bWeight) //宽度显示 { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl, TRUE); if (pPl != NULL) { if (el.gsMark == -2) pPl->setColorIndex(el.nColorIndex); pPl->setConstantWidth(el.dWidth * dPScale); dc.DrawPolyline(*pPl); DELETE_PTR(pPl); } } else { //判断是否是三维 { dc.DrawCircularArc(el.ptGe[0], el.ptGe[1], el.ptGe[2]); } } dc.SetLayer(idOld); dc.SetLineType(idOldLt); } } } } else// 实 { if (el.gsMark == -1) //中心线 { idOldLt = dc.GetLineTypeId(); idOld = dc.GetLayerId(); if (!el.idSubLay.isValid()) { dc.SetLayer(idCen); dc.SetColorLayer(COLOR_BYLAYER, idCen); } else { dc.SetLayer(el.idSubLay); dc.SetColorLayer(COLOR_BYLAYER, el.idSubLay); } if (el.idSubLty.isValid()) { dc.SetLineType(el.idSubLty); } if (el.dWidth > 1.e-6 && bCenWeight) { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl, TRUE); if (pPl != NULL) { pPl->setConstantWidth(el.dWidth * dPScale); dc.DrawPolyline(*pPl); DELETE_PTR(pPl); } } else { //判断是否是三维 { dc.DrawCircularArc(el.ptGe[0], el.ptGe[1], el.ptGe[2]); } } dc.SetLayer(idOld); dc.SetLineType(idOldLt); } else //非中心线 { idOldLt = dc.GetLineTypeId(); idOld = dc.GetLayerId(); if (!el.idSubLay.isValid()) { dc.SetLayer(idReal); dc.SetColorLayer(COLOR_BYLAYER, idReal); if (el.gsMark == -2)//隔板线 { dc.SetColorLayer(el.nColorIndex, idReal); //隔板线保持 实线 AcDbObjectId idLineType = KTSetting::InitLineStyle(_T("CONTINUOUS")); dc.SetLineType(idLineType); } } else { dc.SetLayer(el.idSubLay); dc.SetColorLayer(COLOR_BYLAYER, el.idSubLay); } if (el.idSubLty.isValid()) { dc.SetLineType(el.idSubLty); } if (el.dWidth > 1.e-6 && bWeight) //宽度显示 { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl, TRUE); if (pPl != NULL) { if (el.gsMark == -2) pPl->setColorIndex(el.nColorIndex); pPl->setConstantWidth(el.dWidth * dPScale); dc.DrawPolyline(*pPl); DELETE_PTR(pPl); } } else { //判断是否是三维 { dc.DrawCircularArc(el.ptGe[0], el.ptGe[1], el.ptGe[2]); } } dc.SetLayer(idOld); dc.SetLineType(idOldLt); } } } } dc.SetColor(nColorIndexOld); return Adesk::kTrue; } Adesk::Boolean AecComplexCurveDraw::Draw2d(AcGiDraw& dc) const { return Draw2d(dc,dc.GetLayerId(),dc.GetLayerId(),dc.GetLayerId()); } Adesk::Boolean AecComplexCurveDraw::explode(AcDbVoidPtrArray& entitySet, const AcDbObjectId& idReal, const AcDbObjectId& idDash, const AcDbObjectId& idCen, AecEqui::AecCurveElement* pElTmpl, BOOL bWeight, BOOL bCenWeight) { //从注册表中读取显示方式 AcDbObjectId idOld, idOldLt; BOOL bHideDraw = m_bHideDraw; int nColorIndexOld = -1, nCount = 0; //显示 AecEqui::AecCurveElement el; memset(&el, 0, sizeof(AecEqui::AecCurveElement)); for (int i = 0; i < m_curEdage.length(); i++) { el = m_curEdage.at(i); //复制来自模板的宽度属性等 if (pElTmpl != NULL) { el.dWidth = pElTmpl->dWidth; } if (el.ptGe[1].distanceTo(el.ptGe[2]) < AcGeContext::gTol.equalPoint()) //直线 { if (el.bHided) // 虚线 + 画 { if (bHideDraw)//显示 { if (el.gsMark == -1)//中心线 { if (el.dWidth > 1.e-6) //有宽度 { if (bCenWeight) //中心线,且宽度显示 { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl); if (pPl != NULL) { SetProperty(el, pPl, idReal, idDash, idCen); entitySet.append(pPl); } } else //有宽度,但不显示,画单线 { el.dWidth = 0.0; AcDbLine* pLine = NULL; MakeLine(el, pLine); if (pLine != NULL) { SetProperty(el, pLine, idReal, idDash, idCen); entitySet.append(pLine); } } } else //没有宽度 { el.dWidth = 0.0; AcDbLine* pLine = NULL; MakeLine(el, pLine); if (pLine != NULL) { SetProperty(el, pLine, idReal, idDash, idCen); entitySet.append(pLine); } } } else //非中心线 { if (el.dWidth > 1.e-6) //有宽度 { if (bWeight) //中心线,且宽度显示 { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl); if (pPl != NULL) { SetProperty(el, pPl, idReal, idDash, idCen); entitySet.append(pPl); } } else //有宽度,但不显示,画单线 { el.dWidth = 0.0; AcDbLine* pLine = NULL; MakeLine(el, pLine); if (pLine != NULL) { SetProperty(el, pLine, idReal, idDash, idCen); entitySet.append(pLine); } } } else { el.dWidth = 0.0; AcDbLine* pLine = NULL; MakeLine(el, pLine); if (pLine != NULL) { SetProperty(el, pLine, idReal, idDash, idCen); entitySet.append(pLine); } } } } } else // 实线 { if (el.gsMark == -1) //中心线 { if (el.dWidth > 1.e-6 && bCenWeight) { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl); if (pPl != NULL) { SetProperty(el, pPl, idReal, idDash, idCen); entitySet.append(pPl); } } else { el.dWidth = 0.0; AcDbLine* pLine = NULL; MakeLine(el, pLine); if (pLine != NULL) { SetProperty(el, pLine, idReal, idDash, idCen); entitySet.append(pLine); } } } else //非中心线 { if (el.ptGe[0].distanceTo(el.ptGe[1]) > 1.e-10) //不重合 { if (el.dWidth > 1.e-6 && bWeight) { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl); if (pPl != NULL) { SetProperty(el, pPl, idReal, idDash, idCen); entitySet.append(pPl); } } else { el.dWidth = 0.0; AcDbLine* pLine = NULL; MakeLine(el, pLine); if (pLine != NULL) { SetProperty(el, pLine, idReal, idDash, idCen); entitySet.append(pLine); } } } } } } else //ARC 圆弧 { if (el.bHided)// 虚线 + 画 { if (bHideDraw) //显示 { if (el.gsMark == -1) //中心线 { if (el.dWidth > 1.e-6 && bCenWeight) { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl, TRUE); if (pPl != NULL) { SetProperty(el, pPl, idReal, idDash, idCen); entitySet.append(pPl); } } else { el.dWidth = 0.0; AcDbArc* pArc = NULL; MakeArc(el, pArc); if (pArc != NULL) { SetProperty(el, pArc, idReal, idDash, idCen); entitySet.append(pArc); } } } else //非中心线 { if (el.ptGe[0].distanceTo(el.ptGe[1]) > 1.e-10) //不重合 { if (el.dWidth > 1.e-6 && bWeight) //宽度显示 { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl, TRUE); if (pPl != NULL) { SetProperty(el, pPl, idReal, idDash, idCen); entitySet.append(pPl); } } else { el.dWidth = 0.0; AcDbArc* pArc = NULL; MakeArc(el, pArc); if (pArc != NULL) { SetProperty(el, pArc, idReal, idDash, idCen); entitySet.append(pArc); } } } } } } else// 实 { if (el.gsMark == -1) //中心线 { if (el.dWidth > 1.e-6 && bCenWeight) { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl, TRUE); if (pPl != NULL) { SetProperty(el, pPl, idReal, idDash, idCen); entitySet.append(pPl); } } else { el.dWidth = 0.0; AcDbArc* pArc = NULL; MakeArc(el, pArc); if (pArc != NULL) { SetProperty(el, pArc, idReal, idDash, idCen); entitySet.append(pArc); } } } else //非中心线 { if (el.dWidth > 1.e-6 && bWeight) //宽度显示 { AcDbPolyline* pPl = NULL; MakePolgon(el, pPl, TRUE); if (pPl != NULL) { SetProperty(el, pPl, idReal, idDash, idCen); entitySet.append(pPl); } } else { el.dWidth = 0.0; AcDbArc* pArc = NULL; MakeArc(el, pArc); if (pArc != NULL) { SetProperty(el, pArc, idReal, idDash, idCen); entitySet.append(pArc); } } } } } } return Adesk::kTrue; } Acad::ErrorStatus AecComplexCurveDraw::transformBy(const AcGeMatrix3d& xform) { m_curEdage.transformBy(xform); return Acad::eOk; } void AecComplexCurveDraw::OrthoProject2XY() { m_curEdage.OrthoProjectedToXYPlane(); } void AecComplexCurveDraw::SetProperty(AecEqui::AecCurveElement& el, AcDbEntity* pEnt, const AcDbObjectId& idReal, const AcDbObjectId& idDash, const AcDbObjectId& idCen) { if (pEnt == NULL) return; //从注册表中读取显示方式 BOOL bHideDraw = m_bHideDraw; //颜色非随块和随层 if (el.nColorIndex != 0 && el.nColorIndex != 256) { pEnt->setColorIndex(el.nColorIndex); } else { pEnt->setColorIndex(256);//bylayer } if (el.bHided) // 虚线 + 画 { if (bHideDraw)//显示 { if (el.gsMark == -1)//中心线 { if (!el.idSubLay.isValid()) { pEnt->setLayer(idDash); } else { pEnt->setLayer(el.idSubLay); } if (el.idSubLty.isValid()) { pEnt->setLinetype(el.idSubLty); } } else //非中心线 { if (!el.idSubLay.isValid()) { pEnt->setLayer(idDash); } else { pEnt->setLayer(el.idSubLay); } if (el.idSubLty.isValid()) { pEnt->setLinetype(el.idSubLty); } } } } else // 实线 { if (el.gsMark == -1) //中心线 { if (!el.idSubLay.isValid()) { pEnt->setLayer(idCen); } else { pEnt->setLayer(el.idSubLay); } if (el.idSubLty.isValid()) { pEnt->setLinetype(el.idSubLay); } } else //非中心线 { if (el.ptGe[0].distanceTo(el.ptGe[1]) > 1.e-10) //不重合 { if (!el.idSubLay.isValid()) { pEnt->setLayer(idReal); } else { pEnt->setLayer(el.idSubLay); } if (el.idSubLty.isValid()) { pEnt->setLinetype(el.idSubLty); } } } } } BOOL AecComplexCurveDraw::MakeArc(AecEqui::AecCurveElement& el, AcDbArc*& pArc) const { pArc = AecCoverBooleanOper::FormatArc(el.ptGe[0], el.ptGe[1], el.ptGe[2]); if (pArc != NULL) { return TRUE; } return FALSE; } BOOL AecComplexCurveDraw::MakeLine(AecEqui::AecCurveElement& el, AcDbLine*& pLine) const { pLine = new AcDbLine(el.ptGe[0], el.ptGe[1]); return TRUE; } BOOL AecComplexCurveDraw::MakePolgon(AecEqui::AecCurveElement& el, AcDbPolyline*& pPl, BOOL bIsArc) const { if (bIsArc) { AcDbArc* pArc = AecCoverBooleanOper::FormatArc(el.ptGe[0], el.ptGe[1], el.ptGe[2]); if (pArc != NULL) { AcDbVoidPtrArray arCur,arRes; arCur.append(pArc); pPl = (AcDbPolyline*)KTCADUtilityEx::ConvertBoundCurve(arCur,arRes); if (pPl != NULL) { pPl->setConstantWidth(el.dWidth); } DELETE_PTR(pArc); } } else { AcGeVector3d vtLine = el.ptGe[1] - el.ptGe[0]; if (!vtLine.isZeroLength()) { AcGePlane plan = AcGePlane::kXYPlane; pPl = new AcDbPolyline; pPl->addVertexAt(0, el.ptGe[0].convert2d(plan)); pPl->addVertexAt(1, el.ptGe[1].convert2d(plan)); pPl->setElevation(0.0); pPl->setNormal(AcGeVector3d::kZAxis); pPl->setConstantWidth(el.dWidth); return TRUE; } } return FALSE; }