558 lines
13 KiB
C++
558 lines
13 KiB
C++
#include "stdafx.h"
|
||
#include "DbStake.h"
|
||
#include "dbtext.h"
|
||
#include "dbtext.h"
|
||
|
||
const Adesk::UInt8 TDbStake::g_nVersion = 1;
|
||
|
||
ACRX_DXF_DEFINE_MEMBERS(ATSStake, ATSSymbWithText, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
||
1, ATS_STAKE, "ATS_STAKE图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
|
||
|
||
IMPLEMENT_TENTBASE(TDbStake);
|
||
|
||
|
||
void InitDbStake(BOOL bTrue)
|
||
{
|
||
if (bTrue)
|
||
{
|
||
TDbStake::rxInit();
|
||
TDbStake::InitMatchProtocol(TRUE);
|
||
}
|
||
else
|
||
{
|
||
TDbStake::InitMatchProtocol(FALSE);
|
||
deleteAcRxClass(TDbStake::desc());
|
||
}
|
||
}
|
||
|
||
TDbStake::TDbStake()
|
||
{
|
||
m_nStakeType = TStake::eVerLine;
|
||
m_nLablePosion = TStake::eLineLeft;
|
||
m_dScale = 1.0;
|
||
m_dLineLen = 0.0; //引线长度
|
||
m_dDerviDis = 0.0; //引出距离
|
||
|
||
m_dValue = 0.0; //值
|
||
m_nDecimal = 0; //小数点位数
|
||
m_dTextAng = 0.0; //文字角度
|
||
}
|
||
|
||
TDbStake::~TDbStake()
|
||
{
|
||
|
||
}
|
||
|
||
Acad::ErrorStatus TDbStake::subGetClassID(CLSID* pClsid) const
|
||
{
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbStake::dwgInFields (AcDbDwgFiler* pFiler)
|
||
{
|
||
assertWriteEnabled();
|
||
|
||
Acad::ErrorStatus es = TDbSymbWithText::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;
|
||
}
|
||
// cet 2017.8.14 modify 20平台调用readItem(Adesk::Boolean* pVal), 21平台调用readItem(Adesk::Int32* pVal)
|
||
// pFiler->readItem(&m_nStakeType);
|
||
// pFiler->readItem(&m_nLablePosion);
|
||
BOOL bVal = m_nStakeType;
|
||
FilerRead(pFiler, bVal);
|
||
m_nStakeType = bVal ? 1 : 0;
|
||
bVal = m_nLablePosion;
|
||
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;
|
||
ReadString(pFiler,sText);
|
||
m_sJoinChar = sText;
|
||
|
||
ReadString(pFiler,sText);
|
||
m_sText = sText;
|
||
// cet 2017.8.14 add int类型文件读写时使用Adesk::boolean类型,只能存在两个值,补救措施如下
|
||
const TEntityFields &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 TDbStake::dwgOutFields(AcDbDwgFiler *pFiler) const
|
||
{
|
||
assertReadEnabled();
|
||
Acad::ErrorStatus es = TDbSymbWithText::dwgOutFields(pFiler);
|
||
if(es != Acad::eOk)
|
||
return es;
|
||
|
||
pFiler->writeItem(g_nVersion);
|
||
// cet 2017.8.10 modify 20平台调用writeItem(Adesk::Boolean val),21平台调用writeItem(Adesk::Int32 val)
|
||
// pFiler->writeItem(m_nStakeType);
|
||
// pFiler->writeItem(m_nLablePosion);
|
||
FilerWrite(pFiler, m_nStakeType);
|
||
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 TDbStake::dxfInFields (AcDbDxfFiler *pFiler)
|
||
{
|
||
assertWriteEnabled();
|
||
|
||
Acad::ErrorStatus es = TDbSymbWithText::dxfInFields(pFiler);
|
||
if(es!=Acad::eOk)
|
||
return pFiler->filerStatus();
|
||
if (!pFiler->atSubclassData(_T("TDbStake")))
|
||
{
|
||
return Acad::eBadDxfSequence;
|
||
}
|
||
|
||
return pFiler->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus TDbStake::dxfOutFields(AcDbDxfFiler *pFiler) const
|
||
{
|
||
assertReadEnabled();
|
||
Acad::ErrorStatus es=TDbSymbWithText::dxfOutFields(pFiler);
|
||
assert(es == Acad::eOk);
|
||
es = pFiler->writeItem(AcDb::kDxfSubclass,_T("TDbStake"));
|
||
assert(es == Acad::eOk);
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbStake::subGetGripPoints(AcGePoint3dArray& gripPoints,
|
||
AcDbIntArray& osnapModes,
|
||
AcDbIntArray& geomIds) const
|
||
{
|
||
gripPoints.append(m_ptPositon);
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbStake::subGetStretchPoints(AcGePoint3dArray & stretchPoints) const
|
||
{
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbStake::subMoveGripPointsAt(const AcDbIntArray& indices, const AcGeVector3d& offset)
|
||
{
|
||
m_ptPositon += offset;
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbStake::subMoveStretchPointsAt(const AcDbIntArray& indices,const AcGeVector3d& offset)
|
||
{
|
||
return subMoveGripPointsAt(indices,offset);
|
||
}
|
||
|
||
Acad::ErrorStatus TDbStake::subTransformBy(const AcGeMatrix3d& xform)
|
||
{
|
||
assertWriteEnabled();
|
||
TDbEntity::subTransformBy(xform);
|
||
|
||
m_ptPositon.transformBy(xform);
|
||
m_vtDir.transformBy(xform);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbStake::ExplodeOrDraw2d(XExplodeDraw &dc) const
|
||
{
|
||
// cet 2016.10.17 add 图层关闭时,实体不显示,不进行绘制(打印时,也不会绘制)
|
||
AcDbLayerTableRecordPointer player(this->layerId(), AcDb::kForRead);
|
||
if (player.openStatus() == Acad::eOk && player->isOff())
|
||
{
|
||
return Acad::eOk;
|
||
}
|
||
//桩
|
||
ExplodeOrDraw2dStake(dc);
|
||
|
||
//文字
|
||
ExplodeOrDraw2dStakeText(dc);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
//设置位置
|
||
void TDbStake::SetPositon(const AcGePoint3d &pt)
|
||
{
|
||
assertWriteEnabled();
|
||
m_ptPositon = pt;
|
||
}
|
||
|
||
//设置文字
|
||
void TDbStake::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);
|
||
//文字是1000的多少倍
|
||
int nTextN = _ttoi(sTextN);
|
||
|
||
//除以1000后的余数
|
||
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;
|
||
}
|
||
|
||
//设置引线长度
|
||
void TDbStake::SetDerviLineLen(double dLen)
|
||
{
|
||
assertWriteEnabled();
|
||
m_dLineLen = dLen;
|
||
}
|
||
|
||
//设置引出距离
|
||
void TDbStake::SetDerviDis(double dDis)
|
||
{
|
||
assertWriteEnabled();
|
||
m_dDerviDis = dDis;
|
||
}
|
||
|
||
//设置桩标注类型
|
||
void TDbStake::SetStakeType(int nType)
|
||
{
|
||
assertWriteEnabled();
|
||
m_nStakeType = nType;
|
||
// cet 2017.8.14 add int类型文件读写时使用Adesk::boolean类型,只能存在两个值,补救措施如下
|
||
TEntityFields &fd = Fields();
|
||
fd.SFD(_T("STAKE_TYPE"), (Adesk::Int8)nType);
|
||
}
|
||
|
||
//设置桩放置方向
|
||
void TDbStake::SetStakeLablePlace(int nType)
|
||
{
|
||
assertWriteEnabled();
|
||
m_nLablePosion = nType;
|
||
// cet 2017.8.14 add int类型文件读写时使用Adesk::boolean类型,只能存在两个值,补救措施如下
|
||
TEntityFields &fd = Fields();
|
||
fd.SFD(_T("LABEL_POSITION"), (Adesk::Int8)nType);
|
||
}
|
||
|
||
//设置桩放置方向
|
||
void TDbStake::SetStakeDir(const AcGeVector3d &vt)
|
||
{
|
||
assertWriteEnabled();
|
||
m_vtDir = vt;
|
||
m_vtDir.normalize();
|
||
}
|
||
|
||
//桩
|
||
Acad::ErrorStatus TDbStake::ExplodeOrDraw2dStake(XExplodeDraw &dc) const
|
||
{
|
||
AcGePoint3d ptS,ptE;
|
||
AcGePoint3d ptPosition = m_ptPositon;
|
||
switch(m_nStakeType)
|
||
{
|
||
case TStake::eVerLine:
|
||
{
|
||
ptS = m_ptPositon + m_vtDir*2.0*DocGetPScale();
|
||
ptE = m_ptPositon - m_vtDir*2.0*DocGetPScale();
|
||
AcDbPolyline pPline;
|
||
pPline.addVertexAt(0,ptS.convert2d(AcGePlane::kXYPlane));
|
||
pPline.addVertexAt(1,ptE.convert2d(AcGePlane::kXYPlane));
|
||
pPline.setConstantWidth(0.5*DocGetPScale()*m_dScale);
|
||
|
||
pPline.setColorIndex(colorIndex());
|
||
dc.DrawEntity(pPline);
|
||
}
|
||
break;
|
||
case TStake::eCircle:
|
||
{
|
||
AcGePoint3d ptT1,ptT2;
|
||
ptS = m_ptPositon + m_vtDir*0.5*DocGetPScale();
|
||
ptE = m_ptPositon - m_vtDir*0.5*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*DocGetPScale());
|
||
|
||
pPline.setColorIndex(colorIndex());
|
||
dc.DrawEntity(pPline);
|
||
}
|
||
break;
|
||
case TStake::eCross:
|
||
{
|
||
AcDbPolyline pPline;
|
||
ptS = m_ptPositon + m_vtDir*1.0*DocGetPScale();
|
||
ptE = m_ptPositon - m_vtDir*1.0*DocGetPScale();
|
||
pPline.addVertexAt(0,ptS.convert2d(AcGePlane::kXYPlane));
|
||
pPline.addVertexAt(1,ptE.convert2d(AcGePlane::kXYPlane));
|
||
pPline.setConstantWidth(0.5*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*DocGetPScale();
|
||
ptE = m_ptPositon - vtDirT*1.0*DocGetPScale();
|
||
pPline2.addVertexAt(0,ptS.convert2d(AcGePlane::kXYPlane));
|
||
pPline2.addVertexAt(1,ptE.convert2d(AcGePlane::kXYPlane));
|
||
pPline2.setConstantWidth(0.5*DocGetPScale()*m_dScale);
|
||
pPline2.setColorIndex(colorIndex());
|
||
dc.DrawEntity(pPline2);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
//文字
|
||
Acad::ErrorStatus TDbStake::ExplodeOrDraw2dStakeText(XExplodeDraw &dc) const
|
||
{
|
||
//插入引线
|
||
//判引线的方向以及文字的角度
|
||
AcGeVector3d vtDir = m_vtDir;
|
||
XPoint ptS,ptE;
|
||
XPoint ptText;
|
||
if (m_nLablePosion == TStake::eLineRight)
|
||
{
|
||
vtDir.negate();
|
||
}
|
||
|
||
//插入文字位置在中间则不需要引线
|
||
if (m_nLablePosion != TStake::eLineCen)
|
||
{
|
||
ptS = m_ptPositon + vtDir*m_dDerviDis;
|
||
ptE = ptS + vtDir*m_dLineLen;
|
||
XLine line(ptS,ptE);
|
||
dc.DrawLine(line);
|
||
|
||
ptText = ptE + vtDir*0.5*DocGetPScale();
|
||
}
|
||
else
|
||
{
|
||
AcGeVector3d vtDirT = vtDir;
|
||
if (fabs(m_dTextAng - PI/2) > 1e-3)
|
||
vtDirT.rotateBy(PI/2,AcGeVector3d::kZAxis);
|
||
ptText = m_ptPositon + vtDirT*DocGetPScale()*(1.0+GetTextHeight()*0.5);
|
||
}
|
||
|
||
//计算文字旋转角度
|
||
double dRotate = 0.0;
|
||
AcGeVector3d vtX = Ucs2Wcs(AcGeVector3d::kXAxis);
|
||
AcGeVector3d vtY = 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()*DocGetPScale()*0.85;
|
||
}
|
||
}
|
||
|
||
// dRotate = vtDir.angleTo(vtX);
|
||
//文字
|
||
TDbText 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(Ucs2Wcs(dRotate));
|
||
// text.setLayer(this->GetTextLayerId());
|
||
text.setColorIndex(GetTextColor());
|
||
if (m_nLablePosion != TStake::eLineCen)
|
||
{
|
||
if (fabs(m_dTextAng - 0.0) < 1e-3)
|
||
text.SetAlignment(XExplodeDraw::kMiddleLeft);
|
||
else if (fabs(m_dTextAng - PI/2) < 1e-3)
|
||
text.SetAlignment(XExplodeDraw::kBottomCenter);
|
||
else
|
||
text.SetAlignment(XExplodeDraw::kMiddleRight);
|
||
}
|
||
else
|
||
text.SetAlignment(XExplodeDraw::kMiddleCenter);
|
||
|
||
TPushProperty vProp(&text, dc);
|
||
if(dc.IsFullExplode())
|
||
text.ExplodeOrDraw2d(dc);
|
||
else
|
||
dc.DrawEntity(text);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
//设置桩比例系数
|
||
void TDbStake::SetStakeScale(double dScale)
|
||
{
|
||
assertWriteEnabled();
|
||
m_dScale = dScale;
|
||
}
|
||
|
||
|
||
//得到插入点
|
||
AcGePoint3d TDbStake::GetLocation()
|
||
{
|
||
return m_ptPositon;
|
||
}
|
||
|
||
//得到当前文字
|
||
void TDbStake::GetText(CString &sText)
|
||
{
|
||
sText = m_sText;
|
||
}
|
||
|
||
//得到引线长度
|
||
double TDbStake::GetDerviLineLen()
|
||
{
|
||
return m_dLineLen;
|
||
}
|
||
|
||
//得到引出距离
|
||
double TDbStake::GetDerviDis()
|
||
{
|
||
return m_dDerviDis;
|
||
}
|
||
|
||
//得到标注类型
|
||
int TDbStake::GetStakeType()
|
||
{
|
||
return m_nStakeType;
|
||
}
|
||
|
||
//得到桩放置类型
|
||
int TDbStake::GetStakeLablePlace()
|
||
{
|
||
return m_nLablePosion;
|
||
}
|
||
|
||
//得到桩的值
|
||
double TDbStake::GetStakeValue()
|
||
{
|
||
return m_dValue;
|
||
}
|
||
|
||
//得到桩号前缀
|
||
void TDbStake::GetStakeBeforeChar(CString &sValue)
|
||
{
|
||
sValue = m_sJoinChar;
|
||
}
|
||
|
||
//修改桩前缀
|
||
void TDbStake::ChangeStakeBeforeChar(LPCTSTR lpChar)
|
||
{
|
||
if (lpChar != NULL)
|
||
{
|
||
m_sText.Replace(m_sJoinChar,lpChar);
|
||
|
||
m_sJoinChar = lpChar;
|
||
}
|
||
}
|
||
|
||
//设置小数点位数
|
||
void TDbStake::SetTextDecimal(int nNum)
|
||
{
|
||
assertWriteEnabled();
|
||
m_nDecimal = nNum;
|
||
}
|
||
|
||
//设置文字旋转角度
|
||
void TDbStake::SetTextAng(double dAng)
|
||
{
|
||
assertWriteEnabled();
|
||
m_dTextAng = dAng;
|
||
}
|
||
|
||
//得到小数点位数
|
||
int TDbStake::GetDecimalNum()
|
||
{
|
||
return m_nDecimal;
|
||
}
|
||
|
||
//得到文字旋转角度
|
||
double TDbStake::GetTextAng()
|
||
{
|
||
return m_dTextAng;
|
||
} |