//-------------------------------------------------------------------------------------------------------+ // Copyright (C), 1998-2007, SH Software Co. Ltd. // = FileName : XScreenDc 类 // = Version : ver2.0 // = Author : zjq // = CreateDate : 2002-09-09 // = Description: XScreenDc 定义 // = Maintainers: // //-------------------------------------------------------------------------------------------------------+ #include "StdAfx.h" #include "XScreenDc.h" #include "SymbolTable.h" #include "XBlockTable.h" #include "XGlobalFunc.h" #include "XPrivateGlobalFunc.h" XScreenDc::XScreenDc(short nColor, short nMode) : m_nFrontColor(nColor), m_nDrawMode(nMode), m_nBackColor(0) { AT_ScrSize(&m_nModelX, &m_nModelY); m_nFlag = IMG_DRAW3D + IMG_UNISCALE; } XScreenDc::~XScreenDc() { } void XScreenDc::SetColor(short nColor) { m_nFrontColor = nColor; } void XScreenDc::SetMode(short nMode) { m_nDrawMode = nMode; } void XScreenDc::Draw(const XLine &ln) { _Draw(ln); } void XScreenDc::DrawXCurve(const XCurveSegment & curve,double dThick) { Draw(curve); } void XScreenDc::DrawXPoly(const XPoly2D& poly,double dThick) { Draw(poly); } void XScreenDc::DrawXPoint(const XPoint& pt) { Draw(pt); } void XScreenDc::DrawX3DFace(const X3DFace& face) { Draw(face); } void XScreenDc::DrawXPoints(const XPointList& pts) { Draw(pts); } void XScreenDc::DrawXEntity(const Entity& e) { Draw(e); } const TCHAR * XScreenDc::Descriptor() { return _T("XScreenDc"); } const TCHAR * XScreenDc::Desc() { return Descriptor(); } void XScreenDc::_Draw(const XLine &ln) { if (m_nFlag & IMG_WCS2UCS) { ads_grdraw(Wcs2Ucs(ln.GetStartPoint()), Wcs2Ucs(ln.GetEndPoint()), m_nFrontColor, m_nDrawMode); } else { ads_grdraw(ln.GetStartPoint(), ln.GetEndPoint(), m_nFrontColor, m_nDrawMode); } } void XScreenDc::Draw(const XCurveSegment &cv) { if (cv.Is(CURVE_LINE)) { Draw((const XLine&)cv); } else if (cv.Is(CURVE_ARC)) { Draw(cv.GetArc()); } else if (cv.Is(CURVE_CIRCLE)) { Draw(cv.GetCircle()); } } void XScreenDc::Draw(const XPoly2D & poly) { int nLen = poly.TotalSegments(); for (int i = 0; i < nLen; i++) { XCurveSegment cv; poly.Nth(i, cv); Draw(cv); } } void XScreenDc::Draw(const XRectAngle & box) { XPoint ptLowRight(box.upRight.x, box.lowLeft.y), ptUpLeft(box.lowLeft.x, box.upRight.y); Draw(XLine(box.lowLeft, ptLowRight)); Draw(XLine(ptLowRight, box.upRight)); Draw(XLine(box.upRight, ptUpLeft)); Draw(XLine(ptUpLeft, box.lowLeft)); } void XScreenDc::Draw(const XArc &arc, int nDiv) { ads_real dIntAng = fabs(arc.Bulge()); int n = (int)(dIntAng / PI / 2.0 * nDiv); // 弧段数 if (n <= 0) { n = 1; } ads_real dAng = dIntAng / n; XPointList pts; for (int i = 0; i<= n; i++) { ads_real dDrt = arc.GetStarAngle() + i * dAng; XPoint ptVertex; ads_polar(arc.GetCenterPt(), dDrt, arc.GetRadius(), ptVertex); pts.Append(new XPoint(ptVertex)); } Draw(pts); } void XScreenDc::Draw(const XCircle &cir, int nDiv) { ads_real dAng = PI * 2.0 / nDiv; XPointList pts; for (int i = 0; i <= nDiv; i++) { ads_real drt = i * dAng; XPoint vertex; ads_polar(cir.GetCenterPt(), drt, cir.GetRadius(), vertex); pts.Append(new XPoint(vertex)); } Draw(pts); } // Same as Image void XScreenDc::Draw(const XPointList &pts, int bClose) { if (!pts) { return; } XPoint ptStart = pts[0]; for(int i = 1; i < pts.Length(); i++) { XPoint ptNext = pts[i]; Draw(XLine(ptStart, ptNext)); ptStart = ptNext; } if (bClose) { Draw(XLine(ptStart, pts[0])); } } void XScreenDc::Draw(const XPoint &pt, int nStyle, int nPercentage) { ads_real nSizePt = nPercentage * max(m_nModelX, m_nModelY) / 200.0; // half size switch(nStyle) { case PS_DOTE: Draw(XLine(pt,pt)); break; case PS_CROSS_SLANT: Draw(XLine(pt - XPoint(nSizePt,nSizePt), pt + XPoint(nSizePt,nSizePt))); Draw(XLine(pt - XPoint(nSizePt,-nSizePt), pt + XPoint(nSizePt,-nSizePt))); break; case PS_CROSS: Draw(XLine(pt - XPoint(nSizePt), pt + XPoint(nSizePt))); Draw(XLine(pt - XPoint(0,nSizePt), pt + XPoint(0, nSizePt))); break; case PS_BOX: { XPointList pts; pts.Append(new XPoint(pt - XPoint(nSizePt,nSizePt))); pts.Append(new XPoint(pt + XPoint(nSizePt,-nSizePt))); pts.Append(new XPoint(pt + XPoint(nSizePt,nSizePt))); pts.Append(new XPoint(pt + XPoint(-nSizePt,nSizePt))); Draw(pts, 1); } break; case PS_NONE: break; default: break; } } void XScreenDc::Draw(const X3DFace &face) { Draw(XLine(face.GetVertex(0), face.GetVertex(1))); Draw(XLine(face.GetVertex(1), face.GetVertex(2))); Draw(XLine(face.GetVertex(2), face.GetVertex(3))); Draw(XLine(face.GetVertex(3), face.GetVertex(0))); } void XScreenDc::Draw(const Entity &e, ads_matrix tranMat, int nBlkColor) { Entity ent = e; XString sEntType; ent.GetData(0, (TCHAR *)sEntType); if (sEntType == _T("VERTEX") || sEntType == _T("SEQEND") || sEntType == _T("ENDBLK")) { return; } XString sLayer; ent.GetData(0, (TCHAR *)sLayer); int nLayColor = 7; XSymbolTable tabLayer(_T("LAYER"), sLayer); tabLayer.GetData(62, &nLayColor); int nOldColor = m_nFrontColor; int nColor = 0; if (ent.GetData(62,&nColor) != RTNORM) { nColor = nLayColor; // bylayer } else if (!nColor) { nColor = nBlkColor; // byblock } if (!nColor) { nColor = 7; } m_nFrontColor = nColor; // change front color if (sEntType == _T("LINE")) { XLine aLine(ent, LS_FINITE, tranMat); Draw(aLine); } else if (sEntType == _T("3DFACE") && (m_nFlag & IMG_DRAW3D)) { X3DFace face(ent, tranMat); Draw(face); } else if (sEntType == _T("ARC")) { XArc arc(ent, tranMat); Draw(arc); } else if (sEntType == _T("CIRCLE")) { XCircle cir(ent, tranMat); Draw(cir); } else if (sEntType == _T("POLYLINE")) { int nTag70 = 0; ent.GetData(70, &nTag70); if (nTag70 == 0 || nTag70 == 1) { XPoly2D poly(ent); if (tranMat) { poly.TransUCS(tranMat); } Draw(poly, nTag70); } } else if (sEntType == _T("SOLID") || sEntType == _T("TRACE")) { X3DFace notFace; for (int i = 0; i < 4; i++) { XPoint vertex; ent.GetData(10+i, vertex); if (tranMat) { AT_xformpt(tranMat, vertex, vertex); notFace.SetVertex(i, vertex); } else { notFace.SetVertex(i, vertex); } } Draw(notFace); } else if (sEntType == _T("INSERT")) { ads_matrix mat, mat1; GetInsertMatrix(ent, mat); TCHAR blk[80] = _T(""); ent.GetData(2, blk); XBlockTable blkTab(blk); if (tranMat) { AT_multiply_matrix(tranMat, mat, mat1); } else { memcpy(mat1, mat, sizeof(ads_matrix)); } do { Draw(blkTab.ent, mat1, nColor); } while(blkTab.EntNext() == RTNORM); } m_nFrontColor = nOldColor; // Restore front color }