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

374 lines
8.8 KiB
C++

#include "stdafx.h"
#include "TDbAreaRedLine.h"
#include "symdef.h"
#include "dbtext.h"
extern int g_nSymbTextT3Layer;
void InitAreaRedLine(BOOL bInit)
{
if (bInit)
TDbAreaRedLine::rxInit();
else
deleteAcRxClass(TDbAreaRedLine::desc());
}
ACRX_DXF_DEFINE_MEMBERS(ATSAreaRedLine, ATSCurveEntity, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
1, ATS_AREAREDLINE, "ATS_AREAREDLINE图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
IMPLEMENT_TENTBASE(TDbAreaRedLine);
TDbAreaRedLine::TDbAreaRedLine():
m_ucsPts(0),m_nTextHeight(0.35),
m_bShowStack(false),m_dAngle(0),m_nInsertPtIndex(0)
{
m_idTextStyle = InitTextStyle(TS_DIM);
}
TDbAreaRedLine::~TDbAreaRedLine() { }
void TDbAreaRedLine::CalcUcsPtByWcsPt(AcGePoint3d &ptWcs ) const
{
if (m_ucsPts.empty())
return;
AcGeVector3d vt;
vt = m_ucsPts[0].point - m_ptInsert;
ptWcs+=vt;
}
void TDbAreaRedLine::CalcWcsPtByUcsPt(AcGePoint3d &ptUcs ) const
{
if (m_ucsPts.empty())
return;
AcGeVector3d vt;
vt = m_ptInsert - m_ucsPts[0].point;
ptUcs+=vt;
}
void TDbAreaRedLine::SetSubText(long i,CString sText)
{
assertWriteEnabled();
SetNodeString(i, sText);
}
// 取夹点说明
Acad::ErrorStatus TDbAreaRedLine::GetGripText(int i, CString &cs) const
{
Acad::ErrorStatus es = Acad::eOk;
if( i>=0 && i<m_ucsPts.size() )
cs = _T("改变场地红线位置");
else
es = Acad::eInvalidInput;
return es;
}
Acad::ErrorStatus TDbAreaRedLine::subTransformBy( const AcGeMatrix3d& xform )
{
assertWriteEnabled();
m_ptInsert.transformBy(xform);
return Acad::eOk;
}
Acad::ErrorStatus TDbAreaRedLine::ExplodeOrDraw2d( TGGiExplodeDrawBase &dc ) const
{
AcDbObjectId idLayer = dc.GetLayerId();
int nCount = static_cast<int>(m_ucsPts.size());
if(nCount < 3) return Acad::eOk;
Adesk::UInt16 oldColor = dc.GetColor();
AcGeVector3d vec,vec01,vec21;
XPoint ptCur, ptPre, ptNext, ptText;
CString strStackText;
for(int i = 0; i < nCount; ++i)
{
if(i == 0)
ptPre = m_ucsPts[nCount - 1].point;
else
ptPre = ptCur;
ptCur = m_ucsPts[i].point;
ptNext = m_ucsPts[(i+1)%nCount].point;
dc.SetLayer(dc.GetLayerId());
DrawLine(dc, ptCur, ptNext);
dc.SetColor(oldColor);
}
if (dc.IsExportTch4()) // 炸开
{
// lgd add 140424,分解出来的文字的图层和颜色要随“高级选项”中的设置来处理
if (g_nSymbTextT3Layer==1 && !!m_idTextLayer)
{
dc.SetLayer(m_idTextLayer); // 文字层
dc.SetColor(256); //颜色随层
}
else
{
dc.SetLayer(idLayer); // 文字和标注放在同一层
dc.SetColor(7);
}
}
else // 绘制
{
dc.SetLayer(idLayer); // 文字和标注放在同一层
dc.SetColor(7);
}
//桩号
for(int i = 0; i < nCount; ++i)
{
if(i == 0)
ptPre = m_ucsPts[nCount - 1].point;
else
ptPre = ptCur;
ptCur = m_ucsPts[i].point;
ptNext = m_ucsPts[(i+1)%nCount].point;
if(m_bShowStack)
{
ptText = ptCur;
//向量01
vec01 = ptCur - ptPre;
//向量21
vec21 = ptCur - ptNext;
//求和
vec = vec01+vec21;
vec = vec.normalize();
ptText = ptText + vec*1.5*GetPScale();
DrawRedLineText(dc, ptText, m_ucsPts[i].string);
}
}
return Acad::eOk;
}
Acad::ErrorStatus TDbAreaRedLine::subGetGripPoints( AcGePoint3dArray&gripPoints,AcDbIntArray&,AcDbIntArray& ) const
{
assertReadEnabled();
XPoint pt;
int nCount = (int)m_ucsPts.size();
int nInsertIndex = m_nInsertPtIndex % nCount;
double rotate = GetLayoutRotation() + m_dAngle;
XPoint ptOffsertToOrign(m_ucsPts[nInsertIndex].point); //以第nInsertIndex个点作为插入点,需将形移至坐标原点,即所有的点减去相对于nInsertIndex的偏移
for (size_t i = 0; i < m_ucsPts.size(); ++i)
{
pt = m_ucsPts[i].point;
pt -= ptOffsertToOrign;
pt.Rotate(rotate);
pt = pt + m_ptInsert;
gripPoints.append(pt);
}
return Acad::eOk;
}
Acad::ErrorStatus TDbAreaRedLine::subMoveGripPointsAt( const AcDbIntArray& indices, const AcGeVector3d& offset )
{
assertWriteEnabled();
m_ptInsert += offset;
return Acad::eOk;
}
Acad::ErrorStatus TDbAreaRedLine::dwgInFields( AcDbDwgFiler* pFiler )
{
assertWriteEnabled();
Acad::ErrorStatus es;
if ((es = TDbCurveEntity::dwgInFields(pFiler)) != Acad::eOk)
return es;
Adesk::UInt8 nVer(0);
pFiler->readUInt8(&nVer);
if (nVer >= 1)
{
pFiler->readPoint3d(&m_ptInsert);
pFiler->readUInt16(&m_nInsertPtIndex);
pFiler->readBool(&m_bShowStack);
pFiler->readDouble(&m_dAngle);
Adesk::UInt32 nSize(0);
pFiler->readUInt32(&nSize);
AcGePoint3d pt(AcGePoint3d::kOrigin);
TCHAR* pszVal = NULL;
CString str;
SRedLinePoint sPt;
m_ucsPts.clear();
for (Adesk::UInt32 i = 0; i < nSize; ++i)
{
pFiler->readPoint3d(&pt);
pFiler->readString(&pszVal);
str = pszVal;
sPt.point = pt;
sPt.string = str;
m_ucsPts.push_back(sPt);
}
pFiler->readHardPointerId(&m_idTextStyle);
}
return pFiler->filerStatus();
}
Acad::ErrorStatus TDbAreaRedLine::dwgOutFields( AcDbDwgFiler* pFiler ) const
{
assertReadEnabled();
Acad::ErrorStatus es;
if ((es = TDbCurveEntity::dwgOutFields(pFiler)) != Acad::eOk)
return es;
pFiler->writeUInt8(1);
pFiler->writePoint3d(m_ptInsert);
pFiler->writeUInt16(m_nInsertPtIndex);
pFiler->writeBool(m_bShowStack);
pFiler->writeDouble(m_dAngle);
pFiler->writeUInt32(static_cast<UINT32>(m_ucsPts.size()));
for (size_t i = 0; i < m_ucsPts.size(); ++i)
{
const AcGePoint3d &ptUcs = m_ucsPts[i].point;
pFiler->writePoint3d(ptUcs);
const CString str = m_ucsPts[i].string;
pFiler->writeString((LPCTSTR)str);
}
pFiler->writeHardPointerId(m_idTextStyle);
return pFiler->filerStatus();
}
bool TDbAreaRedLine::SetNode( int nPos, SRedLinePoint& data )
{
if (nPos < 0)
{
return false;
}
if (m_ucsPts.size() > nPos)
{
m_ucsPts[nPos] = data;
}
else
{
m_ucsPts.push_back(data);
}
return true;
}
const SRedLinePoint& TDbAreaRedLine::GetNode( int nPos )
{
if (m_ucsPts.size() > nPos)
{
return m_ucsPts[nPos];
}
return SRedLinePoint();
}
void TDbAreaRedLine::RemoveNode( int nPos )
{
if (m_ucsPts.size() > nPos)
{
std::vector<SRedLinePoint>::iterator It = m_ucsPts.begin();
It+=nPos;
m_ucsPts.erase(It);
}
}
void TDbAreaRedLine::ResetNode()
{
m_ucsPts.clear();
}
const AcGePoint3d& TDbAreaRedLine::GetNodePoint( int nPos )
{
if ( nPos < GetNodeNum() && nPos >= 0 )
{
return m_ucsPts[nPos].point;
}
return AcGePoint3d::kOrigin;
}
bool TDbAreaRedLine::SetNodePoint( int nPos, AcGePoint3d point )
{
if ( nPos < GetNodeNum() && nPos >= 0 )
{
m_ucsPts[nPos].point = point;
return true;
}
else
{
return false;
}
}
const CString& TDbAreaRedLine::GetNodeString( int nPos )
{
if ( nPos < GetNodeNum() && nPos >= 0 )
{
return m_ucsPts[nPos].string;
}
return CString(_T(""));
}
bool TDbAreaRedLine::SetNodeString( int nPos, const CString& strStr )
{
if ( nPos < GetNodeNum() && nPos >= 0 )
{
m_ucsPts[nPos].string = strStr;
return true;
}
else
{
return false;
}
}
void TDbAreaRedLine::SetInsertPtIndex( int nInsertPtIndex )
{
int nTotalPt = (int)m_ucsPts.size();
if(nTotalPt == 0)
m_nInsertPtIndex = nInsertPtIndex ;
else
m_nInsertPtIndex = nInsertPtIndex % nTotalPt;
}
void TDbAreaRedLine::DrawLine( TGGiExplodeDrawBase &dc, XPoint& ptStart, XPoint& ptEnd ) const
{
XPoint ptInsert(m_ptInsert);
int nCount = (int)m_ucsPts.size();
int nInsertIndex = m_nInsertPtIndex % nCount;
XPoint ptOffsertToOrign(m_ucsPts[nInsertIndex].point); //以第nInsertIndex个点作为插入点,需将形移至坐标原点,即所有的点减去相对于nInsertIndex的偏移
XPoint ptFirst(ptStart), ptSecond(ptEnd);
ptFirst -= ptOffsertToOrign;
ptSecond -= ptOffsertToOrign;
double rotate = GetLayoutRotation() + m_dAngle;
ptFirst.Rotate(rotate);
ptSecond.Rotate(rotate);
ptFirst += m_ptInsert;
ptSecond += m_ptInsert;
TGGeLine line;
line.SetStartPoint(ptFirst);
line.SetEndPoint(ptSecond);
dc.DrawLine(line);
}
void TDbAreaRedLine::DrawRedLineText(TGGiExplodeDrawBase& dc, const XPoint& ptLoc, const CString& text) const
{
XPoint ptInsert(m_ptInsert);
int nCount = (int)m_ucsPts.size();
int nInsertIndex = m_nInsertPtIndex % nCount;
XPoint ptOffsertToOrign(m_ucsPts[nInsertIndex].point); //以第nInsertIndex个点作为插入点,需将形移至坐标原点,即所有的点减去相对于nInsertIndex的偏移
XPoint ptText(ptLoc);
ptText -= ptOffsertToOrign;
double rotate = m_dAngle + GetLayoutRotation();
ptText.Rotate(rotate);
ptText += m_ptInsert;
TDbText textLabel;
textLabel.SetAlignment(XExplodeDraw::kMiddleCenter);
textLabel.SetHeight(3.5);
textLabel.SetPScale(GetPScale());
textLabel.SetStyleId(m_idTextStyle);
textLabel.setLayer(dc.GetLayerId());
textLabel.setColorIndex(7);
textLabel.SetLayoutRotation(GetLayoutRotation());
textLabel.SetLocation(ptText);
textLabel.SetText(text);
if (dc.IsFullExplode())
textLabel.ExplodeOrDraw2d(dc);
else
dc.DrawEntity(textLabel);
}
int TDbAreaRedLine::GetFirstVersion() const
{
// 10 以前的版本一概炸碎
return 10;
}