Files
envi-code/SourceCode/Code2026/Dimension/TGGiScreenDrawStream.cpp
T
2026-09-28 15:28:50 +08:00

348 lines
6.9 KiB
C++

#include "StdAfx.h"
#include "TGGiScreenDrawStream.h"
#include "globalfunc.h"
#include "SymbolTableRecord.h"
#include "SHAcDbBlockTable.h"
TGGiScreenDrawStream::TGGiScreenDrawStream(short nColor, short nMode)
: m_nFrontColor(nColor), m_nDrawMode(nMode), m_nBackColor(0)
{
GlobalFunc::GetScreenSize(&m_nModelX, &m_nModelY);
m_nFlag = IMG_DRAW3D + IMG_UNISCALE;
}
TGGiScreenDrawStream::~TGGiScreenDrawStream()
{
}
void TGGiScreenDrawStream::SetColor(short nColor)
{
m_nFrontColor = nColor;
}
void TGGiScreenDrawStream::SetMode(short nMode)
{
m_nDrawMode = nMode;
}
void TGGiScreenDrawStream::Draw(const GeLine &ln)
{
_Draw(ln);
}
void TGGiScreenDrawStream::DrawXCurve(const GeCurveSegment & curve,double dThick)
{
Draw(curve);
}
void TGGiScreenDrawStream::DrawXPoly(const GePoly2D& poly,double dThick)
{
Draw(poly);
}
void TGGiScreenDrawStream::DrawXPoint(const ADSGePoint3d& pt)
{
Draw(pt);
}
void TGGiScreenDrawStream::DrawX3DFace(const Ge3DFace& face)
{
Draw(face);
}
void TGGiScreenDrawStream::DrawXPoints(const ADSGePointList& pts)
{
Draw(pts);
}
void TGGiScreenDrawStream::DrawXEntity(const EntitySet& e)
{
Draw(e);
}
const TCHAR * TGGiScreenDrawStream::Descriptor()
{
return _T("TGGiScreenDrawStream");
}
const TCHAR * TGGiScreenDrawStream::Desc()
{
return Descriptor();
}
void TGGiScreenDrawStream::_Draw(const GeLine &ln)
{
if (m_nFlag & IMG_WCS2UCS)
{
ads_grdraw(GlobalFunc::Wcs2Ucs(ln.GetStartPoint()), GlobalFunc::Wcs2Ucs(ln.GetEndPoint()), m_nFrontColor, m_nDrawMode);
}
else
{
ads_grdraw(ln.GetStartPoint(), ln.GetEndPoint(), m_nFrontColor, m_nDrawMode);
}
}
void TGGiScreenDrawStream::Draw(const GeCurveSegment &cv)
{
if (cv.Is(CURVE_LINE))
{
Draw((const GeLine&)cv);
}
else if (cv.Is(CURVE_ARC))
{
Draw(cv.GetArc());
}
else if (cv.Is(CURVE_CIRCLE))
{
Draw(cv.GetCircle());
}
}
void TGGiScreenDrawStream::Draw(const GePoly2D & poly)
{
int nLen = poly.TotalSegments();
for (int i = 0; i < nLen; i++)
{
GeCurveSegment cv;
poly.Nth(i, cv);
Draw(cv);
}
}
void TGGiScreenDrawStream::Draw(const GeRectAngle & box)
{
ADSGePoint3d ptLowRight(box.upRight.x, box.lowLeft.y),
ptUpLeft(box.lowLeft.x, box.upRight.y);
Draw(GeLine(box.lowLeft, ptLowRight));
Draw(GeLine(ptLowRight, box.upRight));
Draw(GeLine(box.upRight, ptUpLeft));
Draw(GeLine(ptUpLeft, box.lowLeft));
}
void TGGiScreenDrawStream::Draw(const GeArc &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;
ADSGePointList pts;
for (int i = 0; i<= n; i++)
{
ads_real dDrt = arc.GetStarAngle() + i * dAng;
ADSGePoint3d ptVertex;
ads_polar(arc.GetCenterPt(), dDrt, arc.GetRadius(), ptVertex);
pts.Append(new ADSGePoint3d(ptVertex));
}
Draw(pts);
}
void TGGiScreenDrawStream::Draw(const GeCircle &cir, int nDiv)
{
ads_real dAng = PI * 2.0 / nDiv;
ADSGePointList pts;
for (int i = 0; i <= nDiv; i++)
{
ads_real drt = i * dAng;
ADSGePoint3d vertex;
ads_polar(cir.GetCenterPt(), drt, cir.GetRadius(), vertex);
pts.Append(new ADSGePoint3d(vertex));
}
Draw(pts);
}
// Same as Image
void TGGiScreenDrawStream::Draw(const ADSGePointList &pts, int bClose)
{
if (!pts)
{
return;
}
ADSGePoint3d ptStart = pts[0];
for(int i = 1; i < pts.Length(); i++)
{
ADSGePoint3d ptNext = pts[i];
Draw(GeLine(ptStart, ptNext));
ptStart = ptNext;
}
if (bClose)
{
Draw(GeLine(ptStart, pts[0]));
}
}
void TGGiScreenDrawStream::Draw(const ADSGePoint3d &pt, int nStyle, int nPercentage)
{
ads_real nSizePt = nPercentage * max(m_nModelX, m_nModelY) / 200.0; // half size
switch(nStyle)
{
case PS_DOTE:
Draw(GeLine(pt,pt));
break;
case PS_CROSS_SLANT:
Draw(GeLine(pt - ADSGePoint3d(nSizePt,nSizePt), pt + ADSGePoint3d(nSizePt,nSizePt)));
Draw(GeLine(pt - ADSGePoint3d(nSizePt,-nSizePt), pt + ADSGePoint3d(nSizePt,-nSizePt)));
break;
case PS_CROSS:
Draw(GeLine(pt - ADSGePoint3d(nSizePt), pt + ADSGePoint3d(nSizePt)));
Draw(GeLine(pt - ADSGePoint3d(0,nSizePt), pt + ADSGePoint3d(0, nSizePt)));
break;
case PS_BOX:
{
ADSGePointList pts;
pts.Append(new ADSGePoint3d(pt - ADSGePoint3d(nSizePt,nSizePt)));
pts.Append(new ADSGePoint3d(pt + ADSGePoint3d(nSizePt,-nSizePt)));
pts.Append(new ADSGePoint3d(pt + ADSGePoint3d(nSizePt,nSizePt)));
pts.Append(new ADSGePoint3d(pt + ADSGePoint3d(-nSizePt,nSizePt)));
Draw(pts, 1);
}
break;
case PS_NONE:
break;
default:
break;
}
}
void TGGiScreenDrawStream::Draw(const Ge3DFace &face)
{
Draw(GeLine(face.GetVertex(0), face.GetVertex(1)));
Draw(GeLine(face.GetVertex(1), face.GetVertex(2)));
Draw(GeLine(face.GetVertex(2), face.GetVertex(3)));
Draw(GeLine(face.GetVertex(3), face.GetVertex(0)));
}
void TGGiScreenDrawStream::Draw(const EntitySet &e, ads_matrix tranMat, int nBlkColor)
{
EntitySet ent = e;
TCString sEntType;
ent.GetData(0, (TCHAR *)sEntType);
if (sEntType == _T("VERTEX") || sEntType == _T("SEQEND") || sEntType == _T("ENDBLK"))
{
return;
}
TCString sLayer;
ent.GetData(0, (TCHAR *)sLayer);
int nLayColor = 7;
SHAcDbSymbolTable 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"))
{
GeLine aLine(ent, LS_FINITE, tranMat);
Draw(aLine);
}
else if (sEntType == _T("3DFACE") && (m_nFlag & IMG_DRAW3D))
{
Ge3DFace face(ent, tranMat);
Draw(face);
}
else if (sEntType == _T("ARC"))
{
GeArc arc(ent, tranMat);
Draw(arc);
}
else if (sEntType == _T("CIRCLE"))
{
GeCircle cir(ent, tranMat);
Draw(cir);
}
else if (sEntType == _T("POLYLINE"))
{
int nTag70 = 0;
ent.GetData(70, &nTag70);
if (nTag70 == 0 || nTag70 == 1)
{
GePoly2D poly(ent);
if (tranMat)
{
poly.TransUCS(tranMat);
}
Draw(poly, nTag70);
}
}
else if (sEntType == _T("SOLID") || sEntType == _T("TRACE"))
{
Ge3DFace notFace;
for (int i = 0; i < 4; i++)
{
ADSGePoint3d vertex;
ent.GetData(10+i, vertex);
if (tranMat)
{
GlobalFunc::PointTransformBy(tranMat, vertex, vertex);
notFace.SetVertex(i, vertex);
}
else
{
notFace.SetVertex(i, vertex);
}
}
Draw(notFace);
}
else if (sEntType == _T("INSERT"))
{
ads_matrix mat, mat1;
GlobalFunc::GetInsertMatrix(ent, mat);
TCHAR blk[80] = _T("");
ent.GetData(2, blk);
SHAcDbBlockTable blkTab(blk);
if (tranMat)
{
GlobalFunc::SetToProductMatrix(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
}