Files
envi-code/SourceCode/Code2026/Dimension/DbStake.cpp
T

559 lines
13 KiB
C++
Raw Normal View History

2026-10-04 00:04:20 +08:00
#include "stdafx.h"
2026-09-28 15:28:50 +08:00
#include "AcDbObjectPtr.h"
#include "dbobjptr.h"
#include "DbStake.h"
#include "aecdbtext.h"
#include "PushProperty.h"
const Adesk::UInt8 CDbStake::g_nVersion = 1;
ACRX_DXF_DEFINE_MEMBERS(CDbStake, AecXDbSymbWithText, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
2026-10-04 00:04:20 +08:00
1, AEC_ZT_STAKE, "AEC_STAKE图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
2026-09-28 15:28:50 +08:00
void InitDbStake(BOOL bTrue)
{
if (bTrue)
{
CDbStake::rxInit();
//CDbStake::InitMatchProtocol(TRUE);
}
else
{
//CDbStake::InitMatchProtocol(FALSE);
deleteAcRxClass(CDbStake::desc());
}
}
CDbStake::CDbStake()
{
m_nStakeType = TStake::eVerLine;
m_nLablePosion = TStake::eLineLeft;
m_dScale = 1.0;
2026-10-04 00:04:20 +08:00
m_dLineLen = 0.0; //引线长度
m_dDerviDis = 0.0; //引出距离
2026-09-28 15:28:50 +08:00
2026-10-04 00:04:20 +08:00
m_dValue = 0.0; //值
m_nDecimal = 0; //小数点位数
m_dTextAng = 0.0; //文字角度
2026-09-28 15:28:50 +08:00
}
CDbStake::~CDbStake()
{
}
//Acad::ErrorStatus CDbStake::subGetClassID(CLSID* pClsid) const
//{
// return Acad::eOk;
//}
Acad::ErrorStatus CDbStake::dwgInFields (AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = AecXDbSymbWithText::dwgInFields(pFiler);
if(es != Acad::eOk)
return es;
Adesk::UInt8 nVer = 0;
pFiler->readItem(&nVer);
if(nVer>g_nVersion)
{// Version is too new
return Acad::eMakeMeProxy;
}
2026-10-04 00:04:20 +08:00
// cet 2017.8.14 modify 20平台调用readItem(Adesk::Boolean* pVal), 21平台调用readItem(Adesk::Int32* pVal)
2026-09-28 15:28:50 +08:00
// pFiler->readItem(&m_nStakeType);
// pFiler->readItem(&m_nLablePosion);
BOOL bVal = m_nStakeType;
GlobalFunc::FilerRead(pFiler, bVal);
m_nStakeType = bVal ? 1 : 0;
bVal = m_nLablePosion;
GlobalFunc::FilerRead(pFiler, bVal);
m_nLablePosion = bVal ? 1 : 0;
Adesk::UInt16 nDecimal = 0;
pFiler->readItem(&nDecimal);
m_nDecimal = nDecimal;
pFiler->readItem(&m_ptPositon);
pFiler->readItem(&m_vtDir);
pFiler->readItem(&m_dLineLen);
pFiler->readItem(&m_dDerviDis);
pFiler->readItem(&m_dScale);
pFiler->readItem(&m_dValue);
pFiler->readItem(&m_dTextAng);
XString sText;
GlobalFunc::ReadString(pFiler,sText);
m_sJoinChar = sText;
GlobalFunc::ReadString(pFiler,sText);
m_sText = sText;
2026-10-04 00:04:20 +08:00
// cet 2017.8.14 add int类型文件读写时使用Adesk::boolean类型,只能存在两个值,补救措施如下
2026-09-28 15:28:50 +08:00
const EntityFields &fd = Fields();
Adesk::Int8 nVal = 0;
if (fd.GFD(_T("STAKE_TYPE"), nVal))
{
m_nStakeType = nVal;
}
if (fd.GFD(_T("LABEL_POSITION"), nVal))
{
m_nLablePosion = nVal;
}
return pFiler->filerStatus();
}
Acad::ErrorStatus CDbStake::dwgOutFields(AcDbDwgFiler *pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = AecXDbSymbWithText::dwgOutFields(pFiler);
if(es != Acad::eOk)
return es;
pFiler->writeItem(g_nVersion);
2026-10-04 00:04:20 +08:00
// cet 2017.8.10 modify 20平台调用writeItem(Adesk::Boolean val),21平台调用writeItem(Adesk::Int32 val)
2026-09-28 15:28:50 +08:00
// pFiler->writeItem(m_nStakeType);
// pFiler->writeItem(m_nLablePosion);
GlobalFunc::FilerWrite(pFiler, m_nStakeType);
GlobalFunc::FilerWrite(pFiler, m_nLablePosion);
pFiler->writeItem(Adesk::UInt16(m_nDecimal));
pFiler->writeItem(m_ptPositon);
pFiler->writeItem(m_vtDir);
pFiler->writeItem(m_dLineLen);
pFiler->writeItem(m_dDerviDis);
pFiler->writeItem(m_dScale);
pFiler->writeItem(m_dValue);
pFiler->writeItem(m_dTextAng);
pFiler->writeString((LPCTSTR)m_sJoinChar);
pFiler->writeString((LPCTSTR)m_sText);
return pFiler->filerStatus();
}
Acad::ErrorStatus CDbStake::dxfInFields (AcDbDxfFiler *pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = AecXDbSymbWithText::dxfInFields(pFiler);
if(es!=Acad::eOk)
return pFiler->filerStatus();
if (!pFiler->atSubclassData(_T("CDbStake")))
{
return Acad::eBadDxfSequence;
}
return pFiler->filerStatus();
}
Acad::ErrorStatus CDbStake::dxfOutFields(AcDbDxfFiler *pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es=AecXDbSymbWithText::dxfOutFields(pFiler);
assert(es == Acad::eOk);
es = pFiler->writeItem(AcDb::kDxfSubclass,_T("CDbStake"));
assert(es == Acad::eOk);
return Acad::eOk;
}
Acad::ErrorStatus CDbStake::subGetGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
gripPoints.append(m_ptPositon);
return Acad::eOk;
}
Acad::ErrorStatus CDbStake::subGetStretchPoints(AcGePoint3dArray & stretchPoints) const
{
return Acad::eOk;
}
Acad::ErrorStatus CDbStake::subMoveGripPointsAt(const AcDbIntArray& indices, const AcGeVector3d& offset)
{
m_ptPositon += offset;
return Acad::eOk;
}
Acad::ErrorStatus CDbStake::subMoveStretchPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset)
{
return subMoveGripPointsAt(indices,offset);
}
Acad::ErrorStatus CDbStake::subTransformBy(const AcGeMatrix3d& xform)
{
assertWriteEnabled();
AecXDbEntityBaseEx::subTransformBy(xform);
m_ptPositon.transformBy(xform);
m_vtDir.transformBy(xform);
return Acad::eOk;
}
Acad::ErrorStatus CDbStake::Draw2d(AcGiDraw &dc) const
{
2026-10-04 00:04:20 +08:00
// cet 2016.10.17 add 图层关闭时,实体不显示,不进行绘制(打印时,也不会绘制)
2026-09-28 15:28:50 +08:00
AcDbLayerTableRecordPointer player(this->layerId(), AcDb::kForRead);
if (player.openStatus() == Acad::eOk && player->isOff())
{
return Acad::eOk;
}
2026-10-04 00:04:20 +08:00
//桩
2026-09-28 15:28:50 +08:00
ExplodeOrDraw2dStake(dc);
2026-10-04 00:04:20 +08:00
//文字
2026-09-28 15:28:50 +08:00
ExplodeOrDraw2dStakeText(dc);
return Acad::eOk;
}
2026-10-04 00:04:20 +08:00
//设置位置
2026-09-28 15:28:50 +08:00
void CDbStake::SetPositon(const AcGePoint3d &pt)
{
assertWriteEnabled();
m_ptPositon = pt;
}
2026-10-04 00:04:20 +08:00
//设置文字
2026-09-28 15:28:50 +08:00
void CDbStake::SetText(LPCTSTR lpChar,double dValue)
{
assertWriteEnabled();
m_dValue = dValue;
if (lpChar != NULL)
m_sJoinChar = lpChar;
double dTextN = dValue/1000;
CString sTextN,sText;
sTextN.Format(_T("%.8f"),dTextN);
2026-10-04 00:04:20 +08:00
//文字是1000的多少倍
2026-09-28 15:28:50 +08:00
int nTextN = _ttoi(sTextN);
2026-10-04 00:04:20 +08:00
//除以1000后的余数
2026-09-28 15:28:50 +08:00
double dTextResidue = fabs(dValue-1000*nTextN) + 0.0;
sTextN.Format(_T("%.0f"),dTextResidue);
double dTmpTextN = _tstof(sTextN);
if (dTmpTextN - dTextResidue >= 1/pow(10.0,m_nDecimal+1))
dTmpTextN -= 1.0;
sTextN.Format(_T("%.0f"),dTmpTextN);
int nLen = sTextN.GetLength();
if (dTextResidue-dTmpTextN <= 1/pow(10.0,m_nDecimal))
{
if (nLen == 1)
sText.Format(_T("%s%d+00%.0f"),m_sJoinChar,nTextN,dTextResidue);
else if (nLen == 2)
sText.Format(_T("%s%d+0%.0f"),m_sJoinChar,nTextN,dTextResidue);
else
sText.Format(_T("%s%d+%.0f"),m_sJoinChar,nTextN,dTextResidue);
}
else
{
if (nLen == 1)
sText.Format(_T("%s%d+00%.0f"),m_sJoinChar,nTextN,dTmpTextN);
else if (nLen == 2)
sText.Format(_T("%s%d+0%.0f"),m_sJoinChar,nTextN,dTmpTextN);
else
sText.Format(_T("%s%d+%.0f"),m_sJoinChar,nTextN,dTmpTextN);
int decimal = 0, sign = 0;
char *buffer = NULL;
buffer = _fcvt( dTextResidue-dTmpTextN+1.0, m_nDecimal, &decimal, &sign );
CString sTmp;
sTmp = buffer;
sTmp = sTmp.Mid(1);
sText += _T(".");
sText += sTmp;
}
m_sText = sText;
}
2026-10-04 00:04:20 +08:00
//设置引线长度
2026-09-28 15:28:50 +08:00
void CDbStake::SetDerviLineLen(double dLen)
{
assertWriteEnabled();
m_dLineLen = dLen;
}
2026-10-04 00:04:20 +08:00
//设置引出距离
2026-09-28 15:28:50 +08:00
void CDbStake::SetDerviDis(double dDis)
{
assertWriteEnabled();
m_dDerviDis = dDis;
}
2026-10-04 00:04:20 +08:00
//设置桩标注类型
2026-09-28 15:28:50 +08:00
void CDbStake::SetStakeType(int nType)
{
assertWriteEnabled();
m_nStakeType = nType;
2026-10-04 00:04:20 +08:00
// cet 2017.8.14 add int类型文件读写时使用Adesk::boolean类型,只能存在两个值,补救措施如下
2026-09-28 15:28:50 +08:00
EntityFields &fd = Fields();
fd.SFD(_T("STAKE_TYPE"), (Adesk::Int8)nType);
}
2026-10-04 00:04:20 +08:00
//设置桩放置方向
2026-09-28 15:28:50 +08:00
void CDbStake::SetStakeLablePlace(int nType)
{
assertWriteEnabled();
m_nLablePosion = nType;
2026-10-04 00:04:20 +08:00
// cet 2017.8.14 add int类型文件读写时使用Adesk::boolean类型,只能存在两个值,补救措施如下
2026-09-28 15:28:50 +08:00
EntityFields &fd = Fields();
fd.SFD(_T("LABEL_POSITION"), (Adesk::Int8)nType);
}
2026-10-04 00:04:20 +08:00
//设置桩放置方向
2026-09-28 15:28:50 +08:00
void CDbStake::SetStakeDir(const AcGeVector3d &vt)
{
assertWriteEnabled();
m_vtDir = vt;
m_vtDir.normalize();
}
2026-10-04 00:04:20 +08:00
//桩
2026-09-28 15:28:50 +08:00
Acad::ErrorStatus CDbStake::ExplodeOrDraw2dStake(AcGiDraw &dc) const
{
AcGePoint3d ptS,ptE;
AcGePoint3d ptPosition = m_ptPositon;
switch(m_nStakeType)
{
case TStake::eVerLine:
{
ptS = m_ptPositon + m_vtDir*2.0*GlobalFunc::DocGetPScale();
ptE = m_ptPositon - m_vtDir*2.0*GlobalFunc::DocGetPScale();
AcDbPolyline pPline;
pPline.addVertexAt(0,ptS.convert2d(AcGePlane::kXYPlane));
pPline.addVertexAt(1,ptE.convert2d(AcGePlane::kXYPlane));
pPline.setConstantWidth(0.5*GlobalFunc::DocGetPScale()*m_dScale);
pPline.setColorIndex(colorIndex());
dc.DrawEntity(pPline);
}
break;
case TStake::eCircle:
{
AcGePoint3d ptT1,ptT2;
ptS = m_ptPositon + m_vtDir*0.5*GlobalFunc::DocGetPScale();
ptE = m_ptPositon - m_vtDir*0.5*GlobalFunc::DocGetPScale();
AcGeVector3d vt1(ptS-m_ptPositon);
AcGeVector3d vt2(ptE-m_ptPositon);
double dAngle1 = vt1.angleTo(vt2);
double dBulge1 = tan(0.25 * dAngle1);
double dAngle2 = vt2.angleTo(vt1);
double dBulge2 = tan(0.25 * dAngle2);
AcDbPolyline pPline;
pPline.addVertexAt(0,ptS.convert2d(AcGePlane::kXYPlane),dBulge1);
pPline.addVertexAt(1,ptE.convert2d(AcGePlane::kXYPlane),dBulge2);
pPline.addVertexAt(2,ptS.convert2d(AcGePlane::kXYPlane),dBulge1);
pPline.setClosed(Adesk::kTrue);
pPline.setConstantWidth(m_dScale*GlobalFunc::DocGetPScale());
pPline.setColorIndex(colorIndex());
dc.DrawEntity(pPline);
}
break;
case TStake::eCross:
{
AcDbPolyline pPline;
ptS = m_ptPositon + m_vtDir*1.0*GlobalFunc::DocGetPScale();
ptE = m_ptPositon - m_vtDir*1.0*GlobalFunc::DocGetPScale();
pPline.addVertexAt(0,ptS.convert2d(AcGePlane::kXYPlane));
pPline.addVertexAt(1,ptE.convert2d(AcGePlane::kXYPlane));
pPline.setConstantWidth(0.5*GlobalFunc::DocGetPScale()*m_dScale);
pPline.setColorIndex(colorIndex());
dc.DrawEntity(pPline);
AcDbPolyline pPline2;
AcGeVector3d vtDirT = m_vtDir;
vtDirT.rotateBy(PI/2,AcGeVector3d::kZAxis);
ptS = m_ptPositon + vtDirT*1.0*GlobalFunc::DocGetPScale();
ptE = m_ptPositon - vtDirT*1.0*GlobalFunc::DocGetPScale();
pPline2.addVertexAt(0,ptS.convert2d(AcGePlane::kXYPlane));
pPline2.addVertexAt(1,ptE.convert2d(AcGePlane::kXYPlane));
pPline2.setConstantWidth(0.5*GlobalFunc::DocGetPScale()*m_dScale);
pPline2.setColorIndex(colorIndex());
dc.DrawEntity(pPline2);
}
break;
default:
break;
}
return Acad::eOk;
}
2026-10-04 00:04:20 +08:00
//文字
2026-09-28 15:28:50 +08:00
Acad::ErrorStatus CDbStake::ExplodeOrDraw2dStakeText(AcGiDraw &dc) const
{
2026-10-04 00:04:20 +08:00
//插入引线
//判引线的方向以及文字的角度
2026-09-28 15:28:50 +08:00
AcGeVector3d vtDir = m_vtDir;
XPoint ptS,ptE;
XPoint ptText;
if (m_nLablePosion == TStake::eLineRight)
{
vtDir.negate();
}
2026-10-04 00:04:20 +08:00
//插入文字位置在中间则不需要引线
2026-09-28 15:28:50 +08:00
if (m_nLablePosion != TStake::eLineCen)
{
ptS = m_ptPositon + vtDir*m_dDerviDis;
ptE = ptS + vtDir*m_dLineLen;
XLine line(ptS,ptE);
//dc.DrawLine(line);
DrawLine(dc, line);
ptText = ptE + vtDir*0.5*GlobalFunc::DocGetPScale();
}
else
{
AcGeVector3d vtDirT = vtDir;
if (fabs(m_dTextAng - PI/2) > 1e-3)
vtDirT.rotateBy(PI/2,AcGeVector3d::kZAxis);
ptText = m_ptPositon + vtDirT*GlobalFunc::DocGetPScale()*(1.0+GetTextHeight()*0.5);
}
2026-10-04 00:04:20 +08:00
//计算文字旋转角度
2026-09-28 15:28:50 +08:00
double dRotate = 0.0;
AcGeVector3d vtX = GlobalFunc::Ucs2Wcs(AcGeVector3d::kXAxis);
AcGeVector3d vtY = GlobalFunc::Ucs2Wcs(AcGeVector3d::kYAxis);
if (vtDir.angleTo(vtY) < PI/2)
{
dRotate = vtDir.angleTo(vtX);
}
else
{
dRotate = 2*PI - vtDir.angleTo(vtX);
if (fabs(m_dTextAng - PI/2) < 1e-3)
{
dRotate += PI;
ptText += vtDir*GetTextHeight()*GlobalFunc::DocGetPScale()*0.85;
}
}
// dRotate = vtDir.angleTo(vtX);
2026-10-04 00:04:20 +08:00
//文字
2026-09-28 15:28:50 +08:00
AecXDbText text;
text.setPropertiesFrom(this);
text.SetText((const TCHAR*)m_sText);
AcDbObjectId id = this->GetTextStyleId();
text.SetStyleId(id);
text.SetLocation(XPoint(ptText));
text.SetHeight(this->GetTextHeight());
dRotate += (2*PI - m_dTextAng);
text.SetRotation(GlobalFunc::Ucs2Wcs(dRotate));
// text.setLayer(this->GetTextLayerId());
text.setColorIndex(GetTextColor());
if (m_nLablePosion != TStake::eLineCen)
{
if (fabs(m_dTextAng - 0.0) < 1e-3)
text.SetAlignment(AcGiDraw::kMiddleLeft);
else if (fabs(m_dTextAng - PI/2) < 1e-3)
text.SetAlignment(AcGiDraw::kBottomCenter);
else
text.SetAlignment(AcGiDraw::kMiddleRight);
}
else
text.SetAlignment(AcGiDraw::kMiddleCenter);
PushProperty vProp(&text, dc);
//if(dc.IsFullExplode())
// text.ExplodeOrDraw2d(dc);
//else
// dc.DrawEntity(text);
DrawBaseEx(dc, text);
return Acad::eOk;
}
2026-10-04 00:04:20 +08:00
//设置桩比例系数
2026-09-28 15:28:50 +08:00
void CDbStake::SetStakeScale(double dScale)
{
assertWriteEnabled();
m_dScale = dScale;
}
2026-10-04 00:04:20 +08:00
//得到插入点
2026-09-28 15:28:50 +08:00
AcGePoint3d CDbStake::GetLocation()
{
return m_ptPositon;
}
2026-10-04 00:04:20 +08:00
//得到当前文字
2026-09-28 15:28:50 +08:00
void CDbStake::GetText(CString &sText)
{
sText = m_sText;
}
2026-10-04 00:04:20 +08:00
//得到引线长度
2026-09-28 15:28:50 +08:00
double CDbStake::GetDerviLineLen()
{
return m_dLineLen;
}
2026-10-04 00:04:20 +08:00
//得到引出距离
2026-09-28 15:28:50 +08:00
double CDbStake::GetDerviDis()
{
return m_dDerviDis;
}
2026-10-04 00:04:20 +08:00
//得到标注类型
2026-09-28 15:28:50 +08:00
int CDbStake::GetStakeType()
{
return m_nStakeType;
}
2026-10-04 00:04:20 +08:00
//得到桩放置类型
2026-09-28 15:28:50 +08:00
int CDbStake::GetStakeLablePlace()
{
return m_nLablePosion;
}
2026-10-04 00:04:20 +08:00
//得到桩的值
2026-09-28 15:28:50 +08:00
double CDbStake::GetStakeValue()
{
return m_dValue;
}
2026-10-04 00:04:20 +08:00
//得到桩号前缀
2026-09-28 15:28:50 +08:00
void CDbStake::GetStakeBeforeChar(CString &sValue)
{
sValue = m_sJoinChar;
}
2026-10-04 00:04:20 +08:00
//修改桩前缀
2026-09-28 15:28:50 +08:00
void CDbStake::ChangeStakeBeforeChar(LPCTSTR lpChar)
{
if (lpChar != NULL)
{
m_sText.Replace(m_sJoinChar,lpChar);
m_sJoinChar = lpChar;
}
}
2026-10-04 00:04:20 +08:00
//设置小数点位数
2026-09-28 15:28:50 +08:00
void CDbStake::SetTextDecimal(int nNum)
{
assertWriteEnabled();
m_nDecimal = nNum;
}
2026-10-04 00:04:20 +08:00
//设置文字旋转角度
2026-09-28 15:28:50 +08:00
void CDbStake::SetTextAng(double dAng)
{
assertWriteEnabled();
m_dTextAng = dAng;
}
2026-10-04 00:04:20 +08:00
//得到小数点位数
2026-09-28 15:28:50 +08:00
int CDbStake::GetDecimalNum()
{
return m_nDecimal;
}
2026-10-04 00:04:20 +08:00
//得到文字旋转角度
2026-09-28 15:28:50 +08:00
double CDbStake::GetTextAng()
{
return m_dTextAng;
}