//-----------------------------------------------------------------------------+ // Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd. // = FileName : TGGiDrawStreamBase 类 // = Version : ver2.0 // = Author : wlw // = CreateDate : 2002-09-09 // = Description: TGGiDrawStreamBase 定义 // = Maintainers: // //-----------------------------------------------------------------------------+ #include "StdAfx.h" #include "TGGiDrawStreamBase.h" #include "TchGlobalFunc.h" #include "TchGlobalCurveFunc.h" #include "TConfigBase.h" TGGiDrawStreamBase::TGGiDrawStreamBase() { m_bClip = true; } TGGiDrawStreamBase::~TGGiDrawStreamBase() { DeleteAll(); } void TGGiDrawStreamBase::DeleteAll() { TGGiClipBoundary* pBd = NULL; for (long i = 0; i < m_lstClip.GetSize(); i++) { pBd = (TGGiClipBoundary*)m_lstClip.GetAt(i); delete pBd; } m_lstClip.RemoveAll(); } void TGGiDrawStreamBase::PushClip(const TGGePoly2D& poly,int flag) { if (!IsDragging()) { m_lstClip.Add(new TGGiClipBoundary(poly,flag)); } } void TGGiDrawStreamBase::PopClip() { if (m_lstClip.GetSize() > 0) { TGGiClipBoundary* pClipBd = (TGGiClipBoundary*)m_lstClip.GetAt(m_lstClip.GetSize() - 1); m_lstClip.RemoveAt(m_lstClip.GetSize() - 1); delete pClipBd; } } void TGGiDrawStreamBase::DrawXPoint(const TADSGePoint3d &pt) { } void TGGiDrawStreamBase::DrawXPoints(const TADSGePointList &pts) { } void TGGiDrawStreamBase::DrawX3DFace(const TGGe3DFace &face) { } void TGGiDrawStreamBase::DrawXEntity(const TEntitySet& ent) { } void TGGiDrawStreamBase::DrawSolid(const TGGePoly2D &polyOutline) { } void TGGiDrawStreamBase::DrawHatch(const TGGePoly2D &polyOutline, const TCHAR *pszPattern, double nScale) { } void TGGiDrawStreamBase::DrawHatchEx(const TGGePoly2D &polyOutline, const TCHAR *pszPattern, double nScale,double rotation) { } void TGGiDrawStreamBase::DrawHatchEx(const TGGeHatch &hatch) { } void TGGiDrawStreamBase::DrawEntity(const AcDbEntity& ent)const { } void TGGiDrawStreamBase::DrawBlock(const AcDbBlockTableRecord &blockRec, const TADSGePoint3d &ptInsert,const AcGeScale3d &scales, double nRot, BOOL bMakeBlock) { } TGGiDrawStreamBase & TGGiDrawStreamBase::operator << (const TADSGePointList &pts) { DrawXPoints(pts); return *this; } TGGiDrawStreamBase & TGGiDrawStreamBase::operator << (const TGGe3DFace &face) { DrawX3DFace(face); return *this; } TGGiDrawStreamBase & TGGiDrawStreamBase::operator << (const TEntitySet &e) { DrawXEntity(e); return *this; } bool TGGiDrawStreamBase::HasClip()const { return m_lstClip.GetSize() > 0; } const TCHAR *TGGiDrawStreamBase::Desc() { return _T("TGGiDrawStreamBase"); } Adesk::Boolean TGGiDrawStreamBase::IsDragging() const { return Adesk::kFalse; } TGGiDrawStreamBase& TGGiDrawStreamBase::operator <<(const TADSGePoint3d& pt) { if (HasClip()) { //裁剪 for (long i = 0; i < m_lstClip.GetSize(); i++) { if ( ((TGGiClipBoundary*)m_lstClip[i])->IsClip(pt)) { return *this; } } } DrawXPoint(pt); return *this; } TGGiDrawStreamBase & TGGiDrawStreamBase::operator << (const TDPtrList &lstCv) { if (HasClip()) { //modify by xlc on 100709 解决分解对象后影响裁剪的问题 CString strCmd; TConfigBase* pBase = GetGlobalConfigBase(); if (pBase != NULL) { strCmd = pBase->GetCurrentCommand(); pBase->Close(); } BOOL bSkipExt = FALSE; //是否忽略求包围盒 strCmd.MakeUpper(); if (strCmd.Find(_T("TEXPLODE")) >= 0 ||strCmd.Find(_T("TSAVEAS")) >= 0 ||strCmd.Find(_T("TBATSAVE")) >= 0) { bSkipExt = TRUE; } TADSGePoint3d ptMin,ptMax; AcDbExtents ext; TDPtrList lstCurve; for (long i = 0; i < lstCv.Length(); i++) { lstCurve.Append(new TGGeCurveSegment(lstCv[i])); if (!bSkipExt) { lstCv[i].GetExtend(ptMin,ptMax); if (i == 0) { ext.set(ptMin,ptMax); } else { ext.addPoint(ptMin); ext.addPoint(ptMax); } } } //裁剪 if(m_bClip) { for (i = 0; i < m_lstClip.GetSize() && lstCurve.Length() > 0; i++) { if ((bSkipExt) || ((TGGiClipBoundary*)m_lstClip[i])->IsExtentsClip(ext) ) { ((TGGiClipBoundary*)m_lstClip[i])->DoClip(lstCurve); } } } //输出 for (i = 0; i < lstCurve.Length(); i++) { DrawXCurve(*lstCurve[i]); } } else { for (long i = 0; i < lstCv.Length(); i++) { DrawXCurve(lstCv[i]); } } return *this; } TGGiDrawStreamBase& TGGiDrawStreamBase::operator <<(const TGGeCurveSegment& seg) { TDPtrList lstCurve; lstCurve.Append(new TGGeCurveSegment(seg)); return (*this) << lstCurve; } TGGiDrawStreamBase& TGGiDrawStreamBase::operator <<(const AcDbEntity &ent) { if (HasClip()) { TDPtrList lstEnt; lstEnt.Append((AcDbEntity*)ent.clone()); //裁剪 for (long i = 0; i < m_lstClip.GetSize() && lstEnt.Length() > 0; i++) { ((TGGiClipBoundary*)m_lstClip[i])->DoClip(lstEnt); } //输出 for (i = 0; i < lstEnt.Length(); i++) { DrawEntity(*lstEnt[i]); } } else { DrawEntity(ent); } return *this; } TGGiDrawStreamBase& TGGiDrawStreamBase::operator <<(const TAcDbBlockRefData& block) { AcDbBlockTableRecord *pRec = NULL; acdbOpenObject(pRec,block.m_idBlock,AcDb::kForRead); if (pRec != NULL) { if (HasClip()) { for (long i = 0; i < m_lstClip.GetSize(); i++) { if ((((TGGiClipBoundary*)m_lstClip[i])->GetClipType() & TGGiClipBoundary::kAcGiClip) == 0) { break; } } if (i < m_lstClip.GetSize()) { TDPtrList lstSeg; ads_matrix mat; ConstructMatrix(TADSGePoint3d(),block.m_ptLocation,block.m_scale3d[0], block.m_scale3d[1], block.m_scale3d[2], block.m_nRotation,mat); Get2DCurveFromBlock(*pRec, mat,lstSeg); (*this) << lstSeg; } else { DrawBlock(*pRec,block.m_ptLocation,block.m_scale3d,block.m_nRotation,block.m_bMakeBlock); } } else { DrawBlock(*pRec,block.m_ptLocation,block.m_scale3d,block.m_nRotation,block.m_bMakeBlock); } pRec->close(); } return *this; } TGGiDrawStreamBase& TGGiDrawStreamBase::operator <<(const TGGePoly2D& poly) { if (HasClip()) { for (int i = 0; i < poly.TotalSegments(); i++) { TGGeCurveSegment cv; poly.Nth(i, cv); *this << cv; } } else { DrawXPoly(poly); } return *this; } TGGiDrawStreamBase& TGGiDrawStreamBase::operator <<(const TGGeRectAngle &box) { TGGePoly2D poly(1); box.AsPoly2D(poly); return *this << poly; } TGGiDrawStreamBase &TGGiDrawStreamBase::operator <<(const TGGeHatch& hatch) { TDPtrList lstPoly; lstPoly.Append(new TGGePoly2D(hatch.GetHatchPoly())); //裁剪 for (long i = 0; i < m_lstClip.GetSize() && lstPoly.Length() > 0; i++) { ((TGGiClipBoundary*)m_lstClip[i])->DoClip(lstPoly); } if (hatch.GetPolys().size() != 1)//房间填充 DrawHatchEx(hatch); else { for (i = 0; i < lstPoly.Length(); i++) { DrawHatchEx(*lstPoly[i],hatch.GetHatchName(),hatch.GetHatchScale(),hatch.GetHatchRotation()); } } return *this; } TGGiDrawStreamBase &TGGiDrawStreamBase::operator <<(const TGGeSolid&solid) { TDPtrList lstPoly; lstPoly.Append(new TGGePoly2D(solid.m_poly)); //裁剪 if (m_bClip) { for (long i = 0; i < m_lstClip.GetSize() && lstPoly.Length() > 0; i++) { ((TGGiClipBoundary*)m_lstClip[i])->DoClip(lstPoly); } } for (long i = 0; i < lstPoly.Length(); i++) { DrawSolid(*lstPoly[i]); } return *this; } //由两曲线连接成的封闭区域进行填充 TGGiDrawStreamBase &TGGiDrawStreamBase::operator <<(const TGGeSolidCurve& sc) { TGGeCurveSegment cvOut = sc.m_cvOut,cvIn = sc.m_cvIn; BOOL bDrawSolid = TRUE; if (cvOut.Is(CURVE_ARC) && cvIn.Is(CURVE_ARC)) { TGGeArc arOut = cvOut.GetArc(); TGGeArc arIn = cvIn.GetArc(); if (arOut.AngleFlag(arIn.MidAngle()) == PR_OUTSIDE || arIn.AngleFlag(arOut.MidAngle()) == PR_OUTSIDE) { bDrawSolid = FALSE; } } if (bDrawSolid) { TGGePoly2D polySolid(1); polySolid.AppendNode(cvOut.StartPoint(), cvOut.GetBulge()); polySolid.AppendNode(cvOut.EndPoint()); polySolid.AppendNode(cvIn.EndPoint(), -cvIn.GetBulge()); polySolid.AppendNode(cvIn.StartPoint()); *this << TGGeSolid(polySolid); } else { } return *this; } TGGiDrawStreamBase& TGGiDrawStreamBase::operator <<(const TGGeLine &line) { TGGeCurveSegment seg; seg = line; return *this << seg; } TGGiDrawStreamBase& TGGiDrawStreamBase::operator <<(const TGGeArc &arc) { TGGeCurveSegment seg; seg = arc; return *this << seg; } TGGiDrawStreamBase& TGGiDrawStreamBase::operator <<(const TGGeCircle &cir) { TGGeCurveSegment seg; seg = cir; return *this << seg; } void TGGiDrawStreamBase::DrawXPoly(const TGGePoly2D &poly,double nThick) { int len = poly.TotalSegments(); for (int i = 0; i < len; i++) { TGGeCurveSegment cv; poly.Nth(i, cv); DrawXCurve(cv,nThick); } } bool TGGiDrawStreamBase::GetClipFlg() { return m_bClip; } void TGGiDrawStreamBase::SetClipFlg(bool bTrue) { m_bClip = bTrue; }