Files
envi-code/SourceCode/Code2026/tg_shs/shs_geLib/TGGiScreenDrawStream.cpp
T
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

359 lines
7.4 KiB
C++

//-------------------------------------------------------------------------------------------------------+
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : TGGiScreenDrawStream 类
// = Version : ver2.0
// = Author : wlw
// = CreateDate : 2002-09-09
// = Description: TGGiScreenDrawStream 定义
// = Maintainers:
//
//-------------------------------------------------------------------------------------------------------+
#include "StdAfx.h"
#include "TGGiScreenDrawStream.h"
#include "TSymbolTableRecord.h"
#include "TAcDbBlockTable.h"
#include "TchGlobalFunc.h"
#include "TchPrivateGlobalFunc.h"
TGGiScreenDrawStream::TGGiScreenDrawStream(short nColor, short nMode)
: m_nFrontColor(nColor), m_nDrawMode(nMode), m_nBackColor(0)
{
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 TGGeLine &ln)
{
_Draw(ln);
}
void TGGiScreenDrawStream::DrawXCurve(const TGGeCurveSegment & curve,double dThick)
{
Draw(curve);
}
void TGGiScreenDrawStream::DrawXPoly(const TGGePoly2D& poly,double dThick)
{
Draw(poly);
}
void TGGiScreenDrawStream::DrawXPoint(const TADSGePoint3d& pt)
{
Draw(pt);
}
void TGGiScreenDrawStream::DrawX3DFace(const TGGe3DFace& face)
{
Draw(face);
}
void TGGiScreenDrawStream::DrawXPoints(const TADSGePointList& pts)
{
Draw(pts);
}
void TGGiScreenDrawStream::DrawXEntity(const TEntitySet& e)
{
Draw(e);
}
const TCHAR * TGGiScreenDrawStream::Descriptor()
{
return _T("TGGiScreenDrawStream");
}
const TCHAR * TGGiScreenDrawStream::Desc()
{
return Descriptor();
}
void TGGiScreenDrawStream::_Draw(const TGGeLine &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 TGGiScreenDrawStream::Draw(const TGGeCurveSegment &cv)
{
if (cv.Is(CURVE_LINE))
{
Draw((const TGGeLine&)cv);
}
else if (cv.Is(CURVE_ARC))
{
Draw(cv.GetArc());
}
else if (cv.Is(CURVE_CIRCLE))
{
Draw(cv.GetCircle());
}
}
void TGGiScreenDrawStream::Draw(const TGGePoly2D & poly)
{
int nLen = poly.TotalSegments();
for (int i = 0; i < nLen; i++)
{
TGGeCurveSegment cv;
poly.Nth(i, cv);
Draw(cv);
}
}
void TGGiScreenDrawStream::Draw(const TGGeRectAngle & box)
{
TADSGePoint3d ptLowRight(box.upRight.x, box.lowLeft.y),
ptUpLeft(box.lowLeft.x, box.upRight.y);
Draw(TGGeLine(box.lowLeft, ptLowRight));
Draw(TGGeLine(ptLowRight, box.upRight));
Draw(TGGeLine(box.upRight, ptUpLeft));
Draw(TGGeLine(ptUpLeft, box.lowLeft));
}
void TGGiScreenDrawStream::Draw(const TGGeArc &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;
TADSGePointList pts;
for (int i = 0; i<= n; i++)
{
ads_real dDrt = arc.GetStarAngle() + i * dAng;
TADSGePoint3d ptVertex;
ads_polar(arc.GetCenterPt(), dDrt, arc.GetRadius(), ptVertex);
pts.Append(new TADSGePoint3d(ptVertex));
}
Draw(pts);
}
void TGGiScreenDrawStream::Draw(const TGGeCircle &cir, int nDiv)
{
ads_real dAng = PI * 2.0 / nDiv;
TADSGePointList pts;
for (int i = 0; i <= nDiv; i++)
{
ads_real drt = i * dAng;
TADSGePoint3d vertex;
ads_polar(cir.GetCenterPt(), drt, cir.GetRadius(), vertex);
pts.Append(new TADSGePoint3d(vertex));
}
Draw(pts);
}
// Same as Image
void TGGiScreenDrawStream::Draw(const TADSGePointList &pts, int bClose)
{
if (!pts)
{
return;
}
TADSGePoint3d ptStart = pts[0];
for(int i = 1; i < pts.Length(); i++)
{
TADSGePoint3d ptNext = pts[i];
Draw(TGGeLine(ptStart, ptNext));
ptStart = ptNext;
}
if (bClose)
{
Draw(TGGeLine(ptStart, pts[0]));
}
}
void TGGiScreenDrawStream::Draw(const TADSGePoint3d &pt, int nStyle, int nPercentage)
{
ads_real nSizePt = nPercentage * max(m_nModelX, m_nModelY) / 200.0; // half size
switch(nStyle)
{
case PS_DOTE:
Draw(TGGeLine(pt,pt));
break;
case PS_CROSS_SLANT:
Draw(TGGeLine(pt - TADSGePoint3d(nSizePt,nSizePt), pt + TADSGePoint3d(nSizePt,nSizePt)));
Draw(TGGeLine(pt - TADSGePoint3d(nSizePt,-nSizePt), pt + TADSGePoint3d(nSizePt,-nSizePt)));
break;
case PS_CROSS:
Draw(TGGeLine(pt - TADSGePoint3d(nSizePt), pt + TADSGePoint3d(nSizePt)));
Draw(TGGeLine(pt - TADSGePoint3d(0,nSizePt), pt + TADSGePoint3d(0, nSizePt)));
break;
case PS_BOX:
{
TADSGePointList pts;
pts.Append(new TADSGePoint3d(pt - TADSGePoint3d(nSizePt,nSizePt)));
pts.Append(new TADSGePoint3d(pt + TADSGePoint3d(nSizePt,-nSizePt)));
pts.Append(new TADSGePoint3d(pt + TADSGePoint3d(nSizePt,nSizePt)));
pts.Append(new TADSGePoint3d(pt + TADSGePoint3d(-nSizePt,nSizePt)));
Draw(pts, 1);
}
break;
case PS_NONE:
break;
default:
break;
}
}
void TGGiScreenDrawStream::Draw(const TGGe3DFace &face)
{
Draw(TGGeLine(face.GetVertex(0), face.GetVertex(1)));
Draw(TGGeLine(face.GetVertex(1), face.GetVertex(2)));
Draw(TGGeLine(face.GetVertex(2), face.GetVertex(3)));
Draw(TGGeLine(face.GetVertex(3), face.GetVertex(0)));
}
void TGGiScreenDrawStream::Draw(const TEntitySet &e, ads_matrix tranMat, int nBlkColor)
{
TEntitySet 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;
TAcDbSymbolTable 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"))
{
TGGeLine aLine(ent, LS_FINITE, tranMat);
Draw(aLine);
}
else if (sEntType == _T("3DFACE") && (m_nFlag & IMG_DRAW3D))
{
TGGe3DFace face(ent, tranMat);
Draw(face);
}
else if (sEntType == _T("ARC"))
{
TGGeArc arc(ent, tranMat);
Draw(arc);
}
else if (sEntType == _T("CIRCLE"))
{
TGGeCircle cir(ent, tranMat);
Draw(cir);
}
else if (sEntType == _T("POLYLINE"))
{
int nTag70 = 0;
ent.GetData(70, &nTag70);
if (nTag70 == 0 || nTag70 == 1)
{
TGGePoly2D poly(ent);
if (tranMat)
{
poly.TransUCS(tranMat);
}
Draw(poly, nTag70);
}
}
else if (sEntType == _T("SOLID") || sEntType == _T("TRACE"))
{
TGGe3DFace notFace;
for (int i = 0; i < 4; i++)
{
TADSGePoint3d vertex;
ent.GetData(10+i, vertex);
if (tranMat)
{
PointTransformBy(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);
TAcDbBlockTable blkTab(blk);
if (tranMat)
{
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
}