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

1622 lines
40 KiB
C++

#include "stdafx.h"
#include "AcDbObjectPtr.h"
#include "PushProperty.h"
#include "DbPipeLabel.h"
#include "acgiutil.h "
#include "dbpipe.h"
// 处理双击修改标注的辅助函数 cet 2014.6.3 add
extern CString ReadXdata(const AcDbEntity*pEnt, const TCHAR*szName);
namespace
{
// 从左侧开始寻找第一个数字
int FindFirstDigit(const CString &sText)
{
int nDigitIndex = -1;
int nCount = sText.GetLength();
for (int i = 0; i < nCount; ++i)
{
TCHAR ch = sText.GetAt(i);
if (ch >= _T('0') && ch <= _T('9'))
{
nDigitIndex = i;
break;
}
}
return nDigitIndex;
}
// 判断是否值修改改了管径值,如果是则dDn返回管径值
bool IsOnlyModifiedPipeDn(CString sNewText, CString sOldText, double &dDn)
{
int nIndex1 = sNewText.Find(_T("x"));
int nIndex2 = sOldText.Find(_T("x"));
if (nIndex1 == -1 && nIndex2 != -1 || nIndex1 != -1 && nIndex2 == -1)
{
return false;
}
if (nIndex1 != -1) // 外径标注如“φ50x2.8”
{
CString sRight1 = sNewText.Right(sNewText.GetLength() - nIndex1);
CString sRight2 = sOldText.Right(sOldText.GetLength() - nIndex2);
if (sRight1 != sRight2)
{
return false;
}
CString sLeft1 = sNewText.Left(nIndex1);
CString sLeft2 = sOldText.Left(nIndex2);
sNewText = sLeft1;
sOldText = sLeft2;
}
// 从左侧寻找第一个数字
int nDigitIndex1 = FindFirstDigit(sNewText);
int nDigitIndex2 = FindFirstDigit(sOldText);
if (nDigitIndex1 == -1 || nDigitIndex2 == -1 || nDigitIndex1 != nDigitIndex2)
{
return false;
}
CString sLeft1 = sNewText.Left(nDigitIndex1); // 前缀
CString sLeft2 = sOldText.Left(nDigitIndex1); // 前缀
if (sLeft1 != sLeft2) // 修改了前缀值
{
return false;
}
int nCount = sNewText.GetLength();
CString sDn = sNewText.Right(nCount - nDigitIndex1); // 管径
dDn = _tstof(sDn);
return true;
}
// 标注文字类型 -1 未知 0 管径标注文字 1 管线文字
int DimTextType(CDbPipeText *pText)
{
int nType = pText->DimTextType();
if (nType != -1)
{
return nType;
}
// 未知情况继续分析
nType = 1; // 默认管线文字
CString sPipeText = pText->GetText();
OPENOBJ_BEGIN(pText->GetPipeId(), AcDb::kForRead, CDbPipe, pPipe)
if (pPipe != NULL)
{
CString sPipeR;
sPipeR.Format(_T("%.0f"), pPipe->GetDnDiameter());
if (sPipeText.Find(sPipeR) != -1) // 当做管径标注文字
{
nType = 0;
}
}
OPENOBJ_END()
return nType;
}
//以下数据采用《钢制管件》02S403 P75
void GetFlangeDataByDn(int m_iPn, double m_dRetDn, double &m_nFlangeDn, double &m_nFlangeThick)
{
if (m_iPn == 0) { //0.25MPa
if (fabs(m_dRetDn - 50) < 0.01) {
m_nFlangeDn = 140;
m_nFlangeThick = 12;
}
else if (fabs(m_dRetDn - 65) < 0.01) {
m_nFlangeDn = 160;
m_nFlangeThick = 14;
}
else if (fabs(m_dRetDn - 80) < 0.01) {
m_nFlangeDn = 190;
m_nFlangeThick = 14;
}
else if (fabs(m_dRetDn - 100) < 0.01) {
m_nFlangeDn = 210;
m_nFlangeThick = 14;
}
else if (fabs(m_dRetDn - 125) < 0.01) {
m_nFlangeDn = 240;
m_nFlangeThick = 14;
}
else if (fabs(m_dRetDn - 150) < 0.01) {
m_nFlangeDn = 265;
m_nFlangeThick = 16;
}
else if (fabs(m_dRetDn - 200) < 0.01) {
m_nFlangeDn = 320;
m_nFlangeThick = 18;
}
else if (fabs(m_dRetDn - 250) < 0.01) {
m_nFlangeDn = 375;
m_nFlangeThick = 22;
}
else if (fabs(m_dRetDn - 300) < 0.01) {
m_nFlangeDn = 440;
m_nFlangeThick = 22;
}
else if (fabs(m_dRetDn - 350) < 0.01) {
m_nFlangeDn = 490;
m_nFlangeThick = 22;
}
else if (fabs(m_dRetDn - 400) < 0.01) {
m_nFlangeDn = 540;
m_nFlangeThick = 22;
}
else if (fabs(m_dRetDn - 450) < 0.01) {
m_nFlangeDn = 595;
m_nFlangeThick = 24;
}
else if (fabs(m_dRetDn - 500) < 0.01) {
m_nFlangeDn = 645;
m_nFlangeThick = 24;
}
else if (fabs(m_dRetDn - 600) < 0.01) {
m_nFlangeDn = 755;
m_nFlangeThick = 24;
}
else if (fabs(m_dRetDn - 700) < 0.01) {
m_nFlangeDn = 860;
m_nFlangeThick = 26;
}
else if (fabs(m_dRetDn - 800) < 0.01) {
m_nFlangeDn = 975;
m_nFlangeThick = 26;
}
else if (fabs(m_dRetDn - 900) < 0.01) {
m_nFlangeDn = 1075;
m_nFlangeThick = 28;
}
else if (fabs(m_dRetDn - 1000) < 0.01) {
m_nFlangeDn = 1175;
m_nFlangeThick = 30;
}
else if (fabs(m_dRetDn - 1200) < 0.01) {
m_nFlangeDn = 1375;
m_nFlangeThick = 30;
}
else if (fabs(m_dRetDn - 1400) < 0.01) {
m_nFlangeDn = 1575;
m_nFlangeThick = 32;
}
else if (fabs(m_dRetDn - 1600) < 0.01) {
m_nFlangeDn = 1790;
m_nFlangeThick = 32;
}
else if (fabs(m_dRetDn - 1800) < 0.01) {
m_nFlangeDn = 1990;
m_nFlangeThick = 34;
}
else if (fabs(m_dRetDn - 2000) < 0.01) {
m_nFlangeDn = 2190;
m_nFlangeThick = 34;
}
}
else if (m_iPn == 1) {//0.6MPa
if (fabs(m_dRetDn - 50) < 0.01) {
m_nFlangeDn = 140;
m_nFlangeThick = 16;
}
else if (fabs(m_dRetDn - 65) < 0.01) {
m_nFlangeDn = 160;
m_nFlangeThick = 16;
}
else if (fabs(m_dRetDn - 80) < 0.01) {
m_nFlangeDn = 190;
m_nFlangeThick = 18;
}
else if (fabs(m_dRetDn - 100) < 0.01) {
m_nFlangeDn = 210;
m_nFlangeThick = 18;
}
else if (fabs(m_dRetDn - 125) < 0.01) {
m_nFlangeDn = 240;
m_nFlangeThick = 20;
}
else if (fabs(m_dRetDn - 150) < 0.01) {
m_nFlangeDn = 265;
m_nFlangeThick = 20;
}
else if (fabs(m_dRetDn - 200) < 0.01) {
m_nFlangeDn = 320;
m_nFlangeThick = 22;
}
else if (fabs(m_dRetDn - 250) < 0.01) {
m_nFlangeDn = 375;
m_nFlangeThick = 24;
}
else if (fabs(m_dRetDn - 300) < 0.01) {
m_nFlangeDn = 440;
m_nFlangeThick = 24;
}
else if (fabs(m_dRetDn - 350) < 0.01) {
m_nFlangeDn = 490;
m_nFlangeThick = 26;
}
else if (fabs(m_dRetDn - 400) < 0.01) {
m_nFlangeDn = 540;
m_nFlangeThick = 28;
}
else if (fabs(m_dRetDn - 450) < 0.01) {
m_nFlangeDn = 595;
m_nFlangeThick = 28;
}
else if (fabs(m_dRetDn - 500) < 0.01) {
m_nFlangeDn = 645;
m_nFlangeThick = 30;
}
else if (fabs(m_dRetDn - 600) < 0.01) {
m_nFlangeDn = 755;
m_nFlangeThick = 30;
}
else if (fabs(m_dRetDn - 700) < 0.01) {
m_nFlangeDn = 860;
m_nFlangeThick = 32;
}
else if (fabs(m_dRetDn - 800) < 0.01) {
m_nFlangeDn = 975;
m_nFlangeThick = 32;
}
else if (fabs(m_dRetDn - 900) < 0.01) {
m_nFlangeDn = 1075;
m_nFlangeThick = 34;
}
else if (fabs(m_dRetDn - 1000) < 0.01) {
m_nFlangeDn = 1175;
m_nFlangeThick = 36;
}
else if (fabs(m_dRetDn - 1200) < 0.01) {
m_nFlangeDn = 1405;
m_nFlangeThick = 38;
}
else if (fabs(m_dRetDn - 1400) < 0.01) {
m_nFlangeDn = 1630;
m_nFlangeThick = 44;
}
else if (fabs(m_dRetDn - 1600) < 0.01) {
m_nFlangeDn = 1830;
m_nFlangeThick = 46;
}
else if (fabs(m_dRetDn - 1800) < 0.01) {
m_nFlangeDn = 2045;
m_nFlangeThick = 52;
}
else if (fabs(m_dRetDn - 2000) < 0.01) {
m_nFlangeDn = 2265;
m_nFlangeThick = 54;
}
}
else if (m_iPn == 2) {//1.0MPa
if (fabs(m_dRetDn - 50) < 0.01) {
m_nFlangeDn = 165;
m_nFlangeThick = 18;
}
else if (fabs(m_dRetDn - 65) < 0.01) {
m_nFlangeDn = 185;
m_nFlangeThick = 20;
}
else if (fabs(m_dRetDn - 80) < 0.01) {
m_nFlangeDn = 200;
m_nFlangeThick = 20;
}
else if (fabs(m_dRetDn - 100) < 0.01) {
m_nFlangeDn = 220;
m_nFlangeThick = 22;
}
else if (fabs(m_dRetDn - 125) < 0.01) {
m_nFlangeDn = 250;
m_nFlangeThick = 24;
}
else if (fabs(m_dRetDn - 150) < 0.01) {
m_nFlangeDn = 285;
m_nFlangeThick = 24;
}
else if (fabs(m_dRetDn - 200) < 0.01) {
m_nFlangeDn = 340;
m_nFlangeThick = 24;
}
else if (fabs(m_dRetDn - 250) < 0.01) {
m_nFlangeDn = 395;
m_nFlangeThick = 26;
}
else if (fabs(m_dRetDn - 300) < 0.01) {
m_nFlangeDn = 445;
m_nFlangeThick = 28;
}
else if (fabs(m_dRetDn - 350) < 0.01) {
m_nFlangeDn = 505;
m_nFlangeThick = 28;
}
else if (fabs(m_dRetDn - 400) < 0.01) {
m_nFlangeDn = 565;
m_nFlangeThick = 30;
}
else if (fabs(m_dRetDn - 450) < 0.01) {
m_nFlangeDn = 615;
m_nFlangeThick = 30;
}
else if (fabs(m_dRetDn - 500) < 0.01) {
m_nFlangeDn = 670;
m_nFlangeThick = 32;
}
else if (fabs(m_dRetDn - 600) < 0.01) {
m_nFlangeDn = 780;
m_nFlangeThick = 36;
}
else if (fabs(m_dRetDn - 700) < 0.01) {
m_nFlangeDn = 895;
m_nFlangeThick = 36;
}
else if (fabs(m_dRetDn - 800) < 0.01) {
m_nFlangeDn = 1015;
m_nFlangeThick = 38;
}
else if (fabs(m_dRetDn - 900) < 0.01) {
m_nFlangeDn = 1115;
m_nFlangeThick = 42;
}
else if (fabs(m_dRetDn - 1000) < 0.01) {
m_nFlangeDn = 1230;
m_nFlangeThick = 44;
}
else if (fabs(m_dRetDn - 1200) < 0.01) {
m_nFlangeDn = 1455;
m_nFlangeThick = 48;
}
else if (fabs(m_dRetDn - 1400) < 0.01) {
m_nFlangeDn = 1675;
m_nFlangeThick = 54;
}
else if (fabs(m_dRetDn - 1600) < 0.01) {
m_nFlangeDn = 1915;
m_nFlangeThick = 62;
}
else if (fabs(m_dRetDn - 1800) < 0.01) {
m_nFlangeDn = 2115;
m_nFlangeThick = 66;
}
else if (fabs(m_dRetDn - 2000) < 0.01) {
m_nFlangeDn = 2325;
m_nFlangeThick = 72;
}
}
else if (m_iPn == 3) {//1.6MPa
if (fabs(m_dRetDn - 50) < 0.01) {
m_nFlangeDn = 165;
m_nFlangeThick = 22;
}
else if (fabs(m_dRetDn - 65) < 0.01) {
m_nFlangeDn = 185;
m_nFlangeThick = 24;
}
else if (fabs(m_dRetDn - 80) < 0.01) {
m_nFlangeDn = 200;
m_nFlangeThick = 24;
}
else if (fabs(m_dRetDn - 100) < 0.01) {
m_nFlangeDn = 220;
m_nFlangeThick = 26;
}
else if (fabs(m_dRetDn - 125) < 0.01) {
m_nFlangeDn = 250;
m_nFlangeThick = 28;
}
else if (fabs(m_dRetDn - 150) < 0.01) {
m_nFlangeDn = 285;
m_nFlangeThick = 28;
}
else if (fabs(m_dRetDn - 200) < 0.01) {
m_nFlangeDn = 340;
m_nFlangeThick = 30;
}
else if (fabs(m_dRetDn - 250) < 0.01) {
m_nFlangeDn = 405;
m_nFlangeThick = 32;
}
else if (fabs(m_dRetDn - 300) < 0.01) {
m_nFlangeDn = 460;
m_nFlangeThick = 32;
}
else if (fabs(m_dRetDn - 350) < 0.01) {
m_nFlangeDn = 520;
m_nFlangeThick = 34;
}
else if (fabs(m_dRetDn - 400) < 0.01) {
m_nFlangeDn = 580;
m_nFlangeThick = 38;
}
else if (fabs(m_dRetDn - 450) < 0.01) {
m_nFlangeDn = 640;
m_nFlangeThick = 42;
}
else if (fabs(m_dRetDn - 500) < 0.01) {
m_nFlangeDn = 715;
m_nFlangeThick = 48;
}
else if (fabs(m_dRetDn - 600) < 0.01) {
m_nFlangeDn = 840;
m_nFlangeThick = 50;
}
////////////////// pn 1。6MPA 没有以下管径,数据按1.0
else if (fabs(m_dRetDn - 700) < 0.01) {
m_nFlangeDn = 895;
m_nFlangeThick = 36;
}
else if (fabs(m_dRetDn - 800) < 0.01) {
m_nFlangeDn = 1015;
m_nFlangeThick = 38;
}
else if (fabs(m_dRetDn - 900) < 0.01) {
m_nFlangeDn = 1115;
m_nFlangeThick = 42;
}
else if (fabs(m_dRetDn - 1000) < 0.01) {
m_nFlangeDn = 1230;
m_nFlangeThick = 44;
}
else if (fabs(m_dRetDn - 1200) < 0.01) {
m_nFlangeDn = 1450;
m_nFlangeThick = 48;
}
else if (fabs(m_dRetDn - 1400) < 0.01) {
m_nFlangeDn = 1675;
m_nFlangeThick = 54;
}
else if (fabs(m_dRetDn - 1600) < 0.01) {
m_nFlangeDn = 1915;
m_nFlangeThick = 62;
}
else if (fabs(m_dRetDn - 1800) < 0.01) {
m_nFlangeDn = 2115;
m_nFlangeThick = 66;
}
else if (fabs(m_dRetDn - 2000) < 0.01) {
m_nFlangeDn = 2325;
m_nFlangeThick = 72;
}
}
}
}
const Adesk::UInt8 CLabelStyle::g_nVersion = 1;
CLabelStyle::CLabelStyle() :
m_dTextHeight(3.5), m_dTextRotation(0)
{
}
void CLabelStyle::CopyPropertiesFrom(AcDbEntity *pSrc, unsigned gMatchFlag)
{
CLabelStyle *pLabel = (CLabelStyle *)pSrc;
if (pLabel) {
m_idTextStyle = pLabel->m_idTextStyle;
m_dTextHeight = pLabel->m_dTextHeight;
m_dTextRotation = pLabel->m_dTextRotation;
}
}
BOOL CLabelStyle::IsValid() const
{
return m_idTextStyle.isValid() && m_dTextHeight > 1.0E-3;
}
Acad::ErrorStatus CLabelStyle::dwgInFields(AcDbDwgFiler* pFiler)
{
Acad::ErrorStatus es = Acad::eOk;
Adesk::UInt8 nVer;
pFiler->readItem(&nVer);
if (nVer > g_nVersion) {// Version is too new
return Acad::eMakeMeProxy;
}
pFiler->readItem(&m_idTextStyle);
pFiler->readItem(&m_dTextHeight);
pFiler->readItem(&m_dTextRotation);
return pFiler->filerStatus();
}
Acad::ErrorStatus CLabelStyle::dwgOutFields(AcDbDwgFiler* pFiler) const
{
Acad::ErrorStatus es = Acad::eOk;
pFiler->writeItem(g_nVersion);
pFiler->writeItem(m_idTextStyle);
pFiler->writeItem(m_dTextHeight);
pFiler->writeItem(m_dTextRotation);
return pFiler->filerStatus();
}
Acad::ErrorStatus CLabelStyle::dxfInFields(AcDbDxfFiler* pFiler)
{
Acad::ErrorStatus es = Acad::eOk;
resbuf rb;
while ((es == Acad::eOk) && ((es = pFiler->readResBuf(&rb)) == Acad::eOk)) {
switch (rb.restype) {
case AcDb::kDxfXReal:
m_dTextHeight = rb.resval.rreal;
break;
default:
pFiler->pushBackItem();
es = Acad::eEndOfFile;
break;
}
}
if (es != Acad::eEndOfFile)
return Acad::eInvalidResBuf;
return pFiler->filerStatus();
}
Acad::ErrorStatus CLabelStyle::dxfOutFields(AcDbDxfFiler* pFiler) const
{
Acad::ErrorStatus es = Acad::eOk;
pFiler->writeDouble(AcDb::kDxfXReal, m_dTextHeight);
return es;
}
Acad::ErrorStatus CLabelStyle::subTransformBy(const AcGeMatrix3d& xform)
{
GlobalFunc::AngleTransform(xform, m_dTextRotation);// 旋转角度
GlobalFunc::ScaleTransform(xform, m_dTextHeight);// 字高
return Acad::eOk;
}
//////////////////////////////////////////////////////////////////////////
ACRX_DXF_DEFINE_MEMBERS(CDbPipeLabel, CDbPipeAttachment, AcDb::kDHL_CURRENT,
AcDb::kMReleaseCurrent, 1, AEC_ZT_PIPELABEL,
"AEC_PIPELABEL图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
const Adesk::UInt8 CDbPipeLabel::g_nVersion = 1;
CDbPipeLabel::CDbPipeLabel() :
m_dDistToPipe(-300), m_typePipe(kCommon),
m_dPipeWidth(-1), m_dPipeHeight(-1)
{
}
void CDbPipeLabel::CopyPropertiesFrom(AcDbEntity *pSrc, unsigned gMatchFlag)
{
assertWriteEnabled();
CDbPipeAttachment::CopyPropertiesFrom(pSrc, gMatchFlag);
CLabelStyle::CopyPropertiesFrom(pSrc, gMatchFlag);
CDbPipeLabel *pLabel = CDbPipeLabel::cast(pSrc);
if (pLabel) {
m_dDistToPipe = pLabel->m_dDistToPipe;
}
}
//Acad::ErrorStatus CDbPipeLabel::subGetClassID(CLSID* pClsid) const
//{
// return Acad::eOk;
//}
BOOL CDbPipeLabel::IsValid() const
{
return /*CDbPipeAttachment::IsValid() && */CLabelStyle::IsValid();
}
Acad::ErrorStatus
CDbPipeLabel::subGetOsnapPoints(AcDb::OsnapMode osnapMode,
INT_PTR gsSelectionMark,
const AcGePoint3d& ptPick,
const AcGePoint3d& lastPoint,
const AcGeMatrix3d& viewXform,
AcGePoint3dArray& snapPoints,
AcDbIntArray& geomIds) const
{
Acad::ErrorStatus es = Acad::eOk;
if (osnapMode == AcDb::kOsModeIns || osnapMode == AcDb::kOsModeNode) {
XPoint ptLabel = GetLabelLocation();
snapPoints.append(ptLabel);
}
es = CDbPipeAttachment::subGetOsnapPoints(osnapMode, gsSelectionMark,
ptPick, lastPoint, viewXform, snapPoints, geomIds);
return es;
}
// 从DWG读入数据:
Acad::ErrorStatus CDbPipeLabel::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = Acad::eOk;
es = CDbPipeAttachment::dwgInFields(pFiler);
if (es != Acad::eOk) return es;
es = CLabelStyle::dwgInFields(pFiler);
if (es != Acad::eOk) return es;
Adesk::UInt8 nVer;
pFiler->readItem(&nVer);
if (nVer > g_nVersion) {// Version is too new
return Acad::eMakeMeProxy;
}
pFiler->readItem(&m_dDistToPipe);
pFiler->readItem(&m_dPipeWidth);
pFiler->readItem(&m_dPipeHeight);
Adesk::UInt8 nVar = 0;
pFiler->readItem(&nVar);
m_typePipe = (PipeType)((int)nVar);
GlobalFunc::ReadString(pFiler, m_sLeftText);
return pFiler->filerStatus();
}
Acad::ErrorStatus CDbPipeLabel::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = Acad::eOk;
es = CDbPipeAttachment::dwgOutFields(pFiler);
if (es != Acad::eOk) return es;
es = CLabelStyle::dwgOutFields(pFiler);
if (es != Acad::eOk) return es;
pFiler->writeItem(g_nVersion);
pFiler->writeItem(m_dDistToPipe);
pFiler->writeItem(m_dPipeWidth);
pFiler->writeItem(m_dPipeHeight);
pFiler->writeItem((Adesk::UInt8)((int)m_typePipe));
pFiler->writeItem((const TCHAR *)m_sLeftText);
return pFiler->filerStatus();
}
Acad::ErrorStatus CDbPipeLabel::dxfInFields(AcDbDxfFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = Acad::eOk;
es = CDbPipeAttachment::dxfInFields(pFiler);
if (es != Acad::eOk) return es;
es = CLabelStyle::dxfInFields(pFiler);
if (es != Acad::eOk) return es;
if (!pFiler->atSubclassData(_T("CDbPipeLabel"))) {
return Acad::eBadDxfSequence;
}
return pFiler->filerStatus();
}
Acad::ErrorStatus CDbPipeLabel::dxfOutFields(AcDbDxfFiler* pFiler) const
{
Acad::ErrorStatus es = Acad::eOk;
es = CDbPipeAttachment::dxfOutFields(pFiler);
assert(es == Acad::eOk);
es = CLabelStyle::dxfOutFields(pFiler);
assert(es == Acad::eOk);
es = pFiler->writeItem(AcDb::kDxfSubclass, _T("CDbPipeLabel"));
assert(es == Acad::eOk);
return es;
}
double CDbPipeLabel::GetMinLabelTextLen() const
{
double nVal = 0.0;
AecXDbText text;
text.setPropertiesFrom(this);
XPoint ptLabel = GetLabelLocation();
text.SetStyleId(m_idTextStyle);
text.SetText(GetLabelText());
text.SetRotation(0);
text.SetLocation(ptLabel);
text.SetHeight(m_dTextHeight);
text.SetAlignment(AcGiDraw::kMiddleCenter);
XPoint ptExt = text.GetExtents();
nVal = max(nVal, ptExt.x);
return nVal;
}
Acad::ErrorStatus CDbPipeLabel::Draw2d(AcGiDraw &dc) const
{
if (Has2DBuffer())
{
Draw2DBuffers(dc);
return Acad::eOk;
}
// cet 2016.10.17 add 图层关闭时,实体不显示,不进行绘制(打印时,也不会绘制)
//AcDbLayerTableRecordPointer player(this->layerId(), AcDb::kForRead);
//if (player.openStatus() == Acad::eOk && player->isOff())
//{
// return Acad::eOk;
//}
//if (!IsValid())
// return Acad::eInvalidInput;
AecXDbText text;
text.setPropertiesFrom(this);
text.SetStyleId(m_idTextStyle);
text.SetText(GetLabelText());
text.SetRotation(GetTextRotation());
XPoint ptLabel = GetLabelLocation();
text.SetLocation(ptLabel);
text.SetHeight(m_dTextHeight);
text.SetAlignment(AcGiDraw::kMiddleCenter);
//text.ExplodeOrDraw2d(dc);
DrawBaseEx(dc, text);
return Acad::eOk;
}
XString CDbPipeLabel::GetLabelText() const
{
OPENOBJ_BEGIN(m_idPipe, AcDb::kForRead, CDbPipe, pPipe);
if (pPipe)
{
if (pPipe->GetSysType() == TPipeSys::kVRVMedia)
{
CString sTmp = _T("%%C");
CString sLabel = _T(""), sGasDn = _T(""), sLiqDn = _T(""), sDGasDn = _T("");
sLabel = pPipe->GetLabel();
// change by hh 2014.6.24 冷媒管增加两种分隔符
CString sSplit = _T(",");
// int nStr = sLabel.Find(_T(","));
int nStr = sLabel.Find(sSplit);
if (0 > nStr)
{
sSplit = _T("/");
nStr = sLabel.Find(sSplit);
if (0 > nStr)
{
sSplit = _T(" ");
nStr = sLabel.Find(sSplit);
}
}
int nLength = sLabel.GetLength();
if (nStr < 0)
return sLabel;
//液管
sLiqDn = sLabel.Left(nStr);
sGasDn = sLabel.Right(nLength - nStr - 1);
// nStr = sGasDn.Find(_T(","));
nStr = sGasDn.Find(sSplit);
nLength = sGasDn.GetLength();
//气管
if (nStr < 0)
{
// sLabel.Format(_T("%s%s,%s%s"),sTmp,sLiqDn,sTmp,sGasDn);
sLabel.Format(_T("%s%s%s%s%s"), sTmp, sLiqDn, sSplit, sTmp, sGasDn);
}
//低压气管
else
{
CString sGasTmp = sGasDn;
sGasDn = sGasTmp.Left(nStr);
sDGasDn = sGasTmp.Right(nLength - nStr - 1);
// sLabel.Format(_T("%s%s,%s%s,%s%s"),sTmp,sLiqDn,sTmp,sGasDn,sTmp,sDGasDn);
sLabel.Format(_T("%s%s%s%s%s%s%s%s"), sTmp, sLiqDn, sSplit, sTmp, sGasDn, sSplit, sTmp, sDGasDn);
}
return sLabel;
}
}
OPENOBJ_END();
CString csLabel = _T(""), csLabelTemp = _T("");
csLabelTemp = m_sLeftText;
XString sLabel;
CString csTmp;
csTmp.Format(_T("%.0f"), m_dPipeWidth);
if (m_typePipe == kCommon)
{
csLabel.Format(_T("%s%s"), csLabelTemp, csTmp);
}
else
{
csLabel = csLabelTemp;
}
sLabel = (const TCHAR*)csLabel;
return sLabel;
}
void CDbPipeLabel::GetTips(DList<ObjInfoUnit> &info) const
{
info.Append(new ObjInfoUnit(_T("对象类型"), _T("管线标注")));
if (!m_idPipe.isValid())
info.Append(new ObjInfoUnit(_T("所属管线"), _T("无")));
// ...
}
Acad::ErrorStatus CDbPipeLabel::GetGripText(int idx, CString &cs) const
{
Acad::ErrorStatus es = Acad::eOk;
switch (idx) {
case 0: cs = _T("移动基点"); break;
case 1: cs = _T("移动文字"); break;
default: ASSERT(0);
}
return es;
}
Acad::ErrorStatus
CDbPipeLabel::subGetGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
assertReadEnabled();
Acad::ErrorStatus es = Acad::eOk;
es = CDbPipeAttachment::subGetGripPoints(gripPoints, osnapModes, geomIds);
if (es != Acad::eOk) return es;
XPoint ptLabel = GetLabelLocation();
gripPoints.append((AcGePoint3d)ptLabel);
return es;
}
Acad::ErrorStatus
CDbPipeLabel::subGetStretchPoints(AcGePoint3dArray & stretchPoints) const
{
assertReadEnabled();
Acad::ErrorStatus es = Acad::eOk;
es = CDbPipeAttachment::subGetStretchPoints(stretchPoints);
//if(es!=Acad::eOk) return es;
return es;
}
Acad::ErrorStatus CDbPipeLabel::GetExtents(XPoint &ptLow, XPoint &ptUp) const
{
Acad::ErrorStatus es = Acad::eOk;
es = CDbPipeAttachment::GetExtents(ptLow, ptUp);
if (es == Acad::eOk) {
if (ptLow == XPoint() && ptUp == XPoint()) {
ptLow = m_ptLocation;
ptUp = m_ptLocation;
}
else {
ptLow = Min(ptLow, m_ptLocation);
ptUp = Max(ptUp, m_ptLocation);
}
}
return es;
}
Acad::ErrorStatus
CDbPipeLabel::MoveGSPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
AcGeMatrix3d mat;
mat.setToTranslation(offset);
ADSGePoint3d ptStart, ptEnd;
for (int i = 0; i < indices.length(); i++) {
switch (indices[i]) {
case 1:
OPENOBJ_BEGIN(m_idPipe, AcDb::kForRead, CDbPipePrototype, pPipe);
if (pPipe != NULL) {
XPoint ptOffset = GetLabelLocation() + offset;
XCurveSegment seg;
seg = *pPipe;
ptStart = seg.GetStartPoint();
ptEnd = seg.GetEndPoint();
ptStart.z = ptEnd.z = 0;
seg.SetStartPoint(ptStart);
seg.SetEndPoint(ptEnd);
// seg.startPoint.z =0;
// seg.endPoint.z =0;
m_dDistToPipe = seg.GetDist2Me(ptOffset);
pPipe->getClosestPointTo(ptOffset, m_ptLocation);
}
OPENOBJ_END();
break;
default:;
}
}
return Acad::eOk;
}
Acad::ErrorStatus
CDbPipeLabel::subMoveGripPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertWriteEnabled();
Acad::ErrorStatus es = Acad::eOk;
es = CDbPipeAttachment::subMoveGripPointsAt(indices, offset);
if (es != Acad::eOk) return es;
es = MoveGSPointsAt(indices, offset);
return es;
}
Acad::ErrorStatus
CDbPipeLabel::subMoveStretchPointsAt(const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertWriteEnabled();
Acad::ErrorStatus es = Acad::eOk;
es = CDbPipeAttachment::subMoveStretchPointsAt(indices, offset);
//if(es!=Acad::eOk) return es;
//es = MoveGSPointsAt(indices,offset);
return es;
}
Acad::ErrorStatus CDbPipeLabel::subClose()
{
Acad::ErrorStatus es = CDbPipeAttachment::subClose();
return es;
}
Acad::ErrorStatus
CDbPipeLabel::subTransformBy(const AcGeMatrix3d& xform)
{
assertWriteEnabled();
Acad::ErrorStatus es = Acad::eOk;
es = CDbPipeAttachment::subTransformBy(xform);
if (es != Acad::eOk) return es;
es = CLabelStyle::subTransformBy(xform);
if (es != Acad::eOk) return es;
// 离管线的距离
GlobalFunc::ScaleTransform(xform, m_dDistToPipe);
return es;
}
XPoint CDbPipeLabel::GetLabelLocation() const
{
assertReadEnabled();
XPoint ptLabel;
//double dDir=ads_angle(GlobalFunc::Wcs2Ucs(m_vtLocation),XPoint()); cet 2012.2.6 modify
double dDir = ads_angle(GlobalFunc::Wcs2Ucs(XPoint()), GlobalFunc::Wcs2Ucs(m_vtLocation));
//dDir += PI/2; cet 2012.7. 13 modify
dDir -= PI / 2;
dDir = CT_std_angle(dDir);
// acutPolar(m_ptLocation,dDir,m_dDistToPipe,ptLabel); cet 2012.2.6 modify
acutPolar(GlobalFunc::Wcs2Ucs(m_ptLocation), dDir, m_dDistToPipe, ptLabel);
ptLabel = GlobalFunc::Ucs2Wcs(ptLabel);
return ptLabel;
}
double CDbPipeLabel::GetTextRotation() const
{
assertReadEnabled();
AcGeVector3d vtDir = m_vtLocation;
vtDir.z = 0.0;
vtDir = GlobalFunc::Wcs2Ucs(vtDir, TRUE); // 支持ucs下原点改变的情况
double dRotation = AcGeVector3d::kXAxis.angleTo(vtDir, AcGeVector3d::kZAxis);
dRotation = CT_std_angle(dRotation);
if (dRotation - 0.001 > PI / 2 && dRotation < 3 * PI / 2 + 0.001) // (PI * 0.5, PI * .15]
{
dRotation += PI;
dRotation = CT_std_angle(dRotation);
}
dRotation = GlobalFunc::Ucs2Wcs(dRotation);
return dRotation;
}
BOOL CDbPipeLabel::IsSingle(const CDbPipePrototype *pipe) const
{
BOOL bRet = TRUE;
const DList<AcDbSoftPointerId>& lstAttach = pipe->GetAttachments();
int nCount = lstAttach.Length();
for (int i = 0; i < nCount; i++) {
OPENOBJ_BEGIN(lstAttach[i], AcDb::kForRead, CDbPipeLabel, pLabel);
if (pLabel != NULL) {
if (pLabel->objectId() != objectId()) {
bRet = FALSE;
}
}
OPENOBJ_END();
}
return bRet;
}
void CDbPipeLabel::SetSubText(long i, CString sText)
{
assertWriteEnabled();
// 未曾修改
CString sOldText = (LPCTSTR)GetLabelText();
sText.TrimLeft();
sText.TrimRight();
if (sOldText == sText)
{
return;
}
// 未关联管线的标注可以随意更改文字
AcDbObjectId idPipe = GetPipeId();
if (!idPipe.isValid())
{
SetPipeType(CDbPipeLabel::kDuct);
SetLeftText(sText);
return;
}
// 是否只修改了管径
double dDn = 0.0;
if (!IsOnlyModifiedPipeDn(sText, sOldText, dDn))
{
return;
}
CDbPipe *pPipe = NULL;
acdbOpenObject(pPipe, idPipe, AcDb::kForWrite);
if (pPipe != NULL)
{
pPipe->SetDnDiameter(dDn);
// 双线水管,需更新法兰信息
//if (pPipe->isKindOf(TDbDoubleLinePipe::desc()))
//{
// TDbDoubleLinePipe *pDoublePipe = (TDbDoubleLinePipe*)pPipe;
// double dPipeDn = pDoublePipe->GetDnDiameter();
// CString sPn = ReadXdata(pDoublePipe, _T("TG-PIPE-FLANGE-PN"));
// int nPn = 0;
// if (sPn == _T("0.25MPa"))
// {
// nPn = 0;
// }
// else if (sPn == _T("0.6MPa"))
// {
// nPn = 1;
// }
// else if (sPn == _T("1.0MPa"))
// {
// nPn = 2;
// }
// else if (sPn == _T("1.6MPa"))
// {
// nPn = 3;
// }
// double dFlangeDn = 0.0, dFlangeThick = 0.0;
// GetFlangeDataByDn(nPn, dPipeDn, dFlangeDn, dFlangeThick);
// pDoublePipe->SetWidth(dPipeDn);
// pDoublePipe->SetFlangeDn(dFlangeDn);
// pDoublePipe->SetFlangeThick(dFlangeThick);
//}
pPipe->close();
}
SetPipeType(CDbPipeLabel::kDuct);
SetLeftText(sText);
}
//////////////////////////////////////////////////////////////////////////
ACRX_DXF_DEFINE_MEMBERS(CDbPipeText, CDbPipeAttachment, AcDb::kDHL_CURRENT,
AcDb::kMReleaseCurrent, 1, AEC_ZT_PIPETEXT,
"AEC_PIPETEXT图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
const Adesk::UInt8 CDbPipeText::g_nVersion = 1;
CDbPipeText::CDbPipeText()
{
}
void CDbPipeText::CopyPropertiesFrom(AcDbEntity *pSrc, unsigned gMatchFlag)
{
assertWriteEnabled();
CDbPipeAttachment::CopyPropertiesFrom(pSrc, gMatchFlag);
CLabelStyle::CopyPropertiesFrom(pSrc, gMatchFlag);
CDbPipeText *pText = CDbPipeText::cast(pSrc);
if (pText) {
m_sText = pText->m_sText;
}
}
//Acad::ErrorStatus CDbPipeText::subGetClassID(CLSID* pClsid) const
//{
// return Acad::eOk;
//}
BOOL CDbPipeText::IsValid() const
{
return /*CDbPipeAttachment::IsValid() && */CLabelStyle::IsValid();
}
// 从DWG读入数据:
Acad::ErrorStatus CDbPipeText::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = Acad::eOk;
es = CDbPipeAttachment::dwgInFields(pFiler);
if (es != Acad::eOk) return es;
es = CLabelStyle::dwgInFields(pFiler);
if (es != Acad::eOk) return es;
Adesk::UInt8 nVer;
pFiler->readItem(&nVer);
if (nVer > g_nVersion) {// Version is too new
return Acad::eMakeMeProxy;
}
GlobalFunc::ReadString(pFiler, m_sText);
return pFiler->filerStatus();
}
Acad::ErrorStatus CDbPipeText::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = Acad::eOk;
es = CDbPipeAttachment::dwgOutFields(pFiler);
if (es != Acad::eOk) return es;
es = CLabelStyle::dwgOutFields(pFiler);
if (es != Acad::eOk) return es;
pFiler->writeItem(g_nVersion);
pFiler->writeItem((const TCHAR *)m_sText);
return pFiler->filerStatus();
}
Acad::ErrorStatus CDbPipeText::dxfInFields(AcDbDxfFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = Acad::eOk;
es = CDbPipeAttachment::dxfInFields(pFiler);
if (es != Acad::eOk) return es;
es = CLabelStyle::dxfInFields(pFiler);
if (es != Acad::eOk) return es;
if (!pFiler->atSubclassData(_T("CDbPipeText"))) {
return Acad::eBadDxfSequence;
}
resbuf rb;
while ((es == Acad::eOk) && ((es = pFiler->readResBuf(&rb)) == Acad::eOk)) {
switch (rb.restype) {
case AcDb::kDxfXTextString:
m_sText = rb.resval.rstring;
break;
default:
pFiler->pushBackItem();
es = Acad::eEndOfFile;
break;
}
}
if (es != Acad::eEndOfFile)
return Acad::eInvalidResBuf;
return pFiler->filerStatus();
}
Acad::ErrorStatus CDbPipeText::dxfOutFields(AcDbDxfFiler* pFiler) const
{
Acad::ErrorStatus es = Acad::eOk;
es = CDbPipeAttachment::dxfOutFields(pFiler);
assert(es == Acad::eOk);
es = CLabelStyle::dxfOutFields(pFiler);
assert(es == Acad::eOk);
es = pFiler->writeItem(AcDb::kDxfSubclass, _T("CDbPipeText"));
assert(es == Acad::eOk);
pFiler->writeString(AcDb::kDxfXTextString, (const TCHAR*)m_sText);
return es;
}
Acad::ErrorStatus CDbPipeText::Draw2d(AcGiDraw &dc) const
{
// cet 2016.10.17 add 图层关闭时,实体不显示,不进行绘制(打印时,也不会绘制)
//AcDbLayerTableRecordPointer player(this->layerId(), AcDb::kForRead);
//if (player.openStatus() == Acad::eOk && player->isOff())
//{
// return Acad::eOk;
//}
//if (!IsValid())
// return Acad::eInvalidInput;
XPoint ptLocation = m_ptLocation;
ptLocation.z = 0;
AecXDbText text;
text.setPropertiesFrom(this);
text.SetStyleId(m_idTextStyle);
text.SetText(m_sText);
text.SetRotation(GetTextRotation());
text.SetLocation(ptLocation);
text.SetHeight(m_dTextHeight);
text.SetAlignment(AcGiDraw::kMiddleCenter);
PushProperty vProp(&text, dc);
DrawBaseEx(dc, text);
// dc.SetStyle(m_idTextStyle);
// dc.SetRotation(GetTextRotation());
// dc.SetLocation(ptLocation);
// dc.SetHeight(m_dTextHeight*GetPScale());
// dc.SetAlignment(AcGiDraw::kMiddleCenter);
// dc.DrawText(m_sText);
return Acad::eOk;
}
Acad::ErrorStatus CDbPipeText::GetGripText(int idx, CString &cs) const
{
Acad::ErrorStatus es = Acad::eOk;
switch (idx) {
case 0: cs = _T("平移"); break;
default: ASSERT(0);
}
return es;
}
double CDbPipeText::GetWidth() const
{
AcGiTextStyle txtStyle;
if (!m_idTextStyle.isValid())
return GetPScale();
Acad::ErrorStatus es = fromAcDbTextStyle(txtStyle, m_idTextStyle);
txtStyle.setTextSize(m_dTextHeight * GetPScale());
Adesk::Boolean bIncludeSpace = Adesk::kTrue;
// Windows字体,都需要包括前后空隙
TCHAR *pTypeface = NULL;
Adesk::Boolean bBold, bItalic;
#if ARX <= 20
int tmp0, tmp1;
BOOL bWinFont = (txtStyle.font(pTypeface, bBold, bItalic, tmp0, tmp1) == Acad::eOk);
#else
Charset charset;
Autodesk::AutoCAD::PAL::FontUtils::FontPitch pitch;
Autodesk::AutoCAD::PAL::FontUtils::FontFamily family;
BOOL bWinFont = (txtStyle.font(pTypeface, bBold, bItalic, charset, pitch, family) == Acad::eOk);
#endif
if (bWinFont) {
if (!pTypeface || !pTypeface[0])
bWinFont = FALSE;
}
if (pTypeface)
delete[] pTypeface;
if (bWinFont)
bIncludeSpace = Adesk::kTrue;
else {
bIncludeSpace = Adesk::kFalse;
const TCHAR *pShxFile = txtStyle.fileName();
if (pShxFile) {
SplitpathOperator paser(pShxFile);
_tcsupr(paser.m_sFileName);
TCHAR sFilter[] = _T("GBE*,GOTH*,ISO*,SCRIPT*,ROMAN*");
if (ads_wcmatch(paser.m_sFileName, sFilter) == RTNORM)
bIncludeSpace = Adesk::kTrue;
}
}
double nWidthScale(0.8), nHeightFactor(0);
OPENOBJ_BEGIN(m_idTextStyle, AcDb::kForRead, AcDbTextStyleTableRecord, pRec);
if (pRec) {
resbuf *pxData = pRec->xData(TCHXD); // 读扩展数据
if (pxData) {
resbuf *pNext = pxData->rbnext;
if (pNext && pNext->restype == 1040) {
nHeightFactor = pNext->resval.rreal;
pNext = pNext->rbnext;
if (pNext && pNext->restype == 1040)
nWidthScale = pNext->resval.rreal;
}
ads_relrb(pxData);
}
}
OPENOBJ_END();
AcGePoint2d ptExt = txtStyle.extents(m_sText, bIncludeSpace, -1, Adesk::kFalse);
double dScale = GetPScale();
double dWidth = 0;
//txtStyle.extents计算出来的外框,是英文宽度比例为1时候的,注意nWidthScale是上华的扩展数据
dWidth = fabs(ptExt.x) * nWidthScale;
// cet 2012.2.7 modify 由于某些未知原因,得到的宽度值有时不对
// 为保险起见,再求一次其外包框 用最大值
// return dWidth+2*dScale*g_dPipeTextDis;
double dPipeTextDist = .5;//GetPsPipeTextDis(this->database());
dWidth = dWidth + 2 * dScale * dPipeTextDist;
AecXDbText text;
text.setPropertiesFrom(this);
text.SetStyleId(m_idTextStyle);
text.SetText(m_sText);
text.SetRotation(0.0);
text.SetLocation(m_ptLocation);
text.SetHeight(m_dTextHeight);
text.SetAlignment(AcGiDraw::kMiddleCenter);
double dWidth2 = fabs(text.GetExtents().x);
dWidth2 += 2 * dScale * dPipeTextDist;
return (dWidth > dWidth2 ? dWidth : dWidth2);
}
extern BOOL StringAnalysis(const TCHAR *src, XString &sPrefix, int *num, int *numWidth);
//注意2种标注
// --- H ------ 管线类型标注, 如果修改了, 则同时修改同管线其它标注
// --- DN50 --- 单管管径标注, 如果修改了, 则同时更新管线标注
void CDbPipeText::SetSubText(long i, CString sText)
{
assertWriteEnabled();
// 未曾修改
CString sOldText = GetText();
sText.TrimLeft();
sText.TrimRight();
if (sOldText == sText)
{
return;
}
// 未关联管线的标注可以随意更改文字
AcDbObjectId idPipe = GetPipeId();
if (!idPipe.isValid())
{
SetText(sText);
return;
}
int nDimTextType = ::DimTextType(this);
if (nDimTextType == 0) // 处理管径标注文字
{
if (DimTextType() == -1)
{
DimTextType(0);
}
// 是否只修改了管径
double dDn = 0.0;
if (!IsOnlyModifiedPipeDn(sText, sOldText, dDn))
{
return;
}
bool bUpdateOtherDim = false;
DList<AcDbObjectId> lstAttachment;
CDbPipe *pPipe = NULL;
acdbOpenObject(pPipe, idPipe, AcDb::kForRead);
if (pPipe != NULL)
{
bUpdateOtherDim = pPipe->IsLinkedPipeDnDimText();
pPipe->GetAttachments(lstAttachment);
pPipe->close();
}
SetText(sText);
// 更新其他管线关联标注
if (!bUpdateOtherDim)
{
int nLen = lstAttachment.Length();
for (int m = 0; m < nLen; m++)
{
AcDbObjectId idTmp = *lstAttachment[m];
OPENOBJ_BEGIN(idTmp, AcDb::kForWrite, CDbPipeText, pText);
if (pText != NULL)
{
if (::DimTextType(pText) == 0)
{
pText->SetText(sText);
}
}
OPENOBJ_END();
}
}
// 更新管径
acdbOpenObject(pPipe, idPipe, AcDb::kForWrite);
if (pPipe != NULL)
{
pPipe->SetDnDiameter(dDn);
// 双线水管,需更新法兰信息
//if (pPipe->isKindOf(TDbDoubleLinePipe::desc()))
//{
// TDbDoubleLinePipe *pDoublePipe = (TDbDoubleLinePipe*)pPipe;
// double dPipeDn = pDoublePipe->GetDnDiameter();
// CString sPn = ReadXdata(pDoublePipe, _T("TG-PIPE-FLANGE-PN"));
// int nPn = 0;
// if (sPn == _T("0.25MPa"))
// {
// nPn = 0;
// }
// else if (sPn == _T("0.6MPa"))
// {
// nPn = 1;
// }
// else if (sPn == _T("1.0MPa"))
// {
// nPn = 2;
// }
// else if (sPn == _T("1.6MPa"))
// {
// nPn = 3;
// }
// double dFlangeDn = 0.0, dFlangeThick = 0.0;
// GetFlangeDataByDn(nPn, dPipeDn, dFlangeDn, dFlangeThick);
// pDoublePipe->SetWidth(dPipeDn);
// pDoublePipe->SetFlangeDn(dFlangeDn);
// pDoublePipe->SetFlangeThick(dFlangeThick);
//}
pPipe->close();
}
}
else if (nDimTextType == 1) // 管线文字
{
SetText(sText);
if (DimTextType() == -1)
{
DimTextType(1);
}
CDbPipe *pPipe = NULL;
acdbOpenObject(pPipe, idPipe, AcDb::kForWrite);
if (pPipe != NULL)
{
pPipe->SetLinkedPipeText(sText);
pPipe->close();
}
}
}
void CDbPipeText::GetTips(DList<ObjInfoUnit> &info) const
{
info.Append(new ObjInfoUnit(_T("对象类型"), _T("管线文字")));
if (!m_idPipe.isValid())
info.Append(new ObjInfoUnit(_T("所属管线"), _T("无")));
info.Append(new ObjInfoUnit(_T("文字内容"), (const TCHAR*)m_sText));
}
double CDbPipeText::GetTextRotation() const
{
assertReadEnabled();
AcGeVector3d vt = m_vtLocation;
vt.z = 0.0;
vt = GlobalFunc::Wcs2Ucs(vt, TRUE); // 支持ucs下原点改变的情况
double dRotation = (AcGeVector3d::kXAxis).angleTo(vt, AcGeVector3d::kZAxis);
if ((dRotation - 0.001) > PI / 2 && dRotation < 3 * PI / 2 + 0.001) // (PI * 0.5, PI *1.5]
{
dRotation += PI;
dRotation = CT_std_angle(dRotation);
}
dRotation = GlobalFunc::Ucs2Wcs(dRotation);
return dRotation;
}
int CDbPipeText::DimTextType()
{
EntityFields &fd = Fields();
Adesk::Int8 nVal = -1;
fd.GFD(_T("DIM_TEXT_TYPE"), nVal);
return nVal;
}
void CDbPipeText::DimTextType(Adesk::Int8 nDimTextType)
{
assertWriteEnabled();
EntityFields &fd = Fields();
fd.SFD(_T("DIM_TEXT_TYPE"), nDimTextType);
}
bool CDbPipeText::UpdateLinkedPipe(const CString &sDimText)
{
// 未关联管线的标注可以随意更改文字
AcDbObjectId idPipe = GetPipeId();
if (!idPipe.isValid())
{
return true;
}
// 未曾修改
CString sOldText = GetText();
CString sText = sDimText;
sText.TrimLeft();
sText.TrimRight();
int nDimTextType = ::DimTextType(this);
if (nDimTextType == 0) // 处理管径标注文字
{
if (DimTextType() == -1)
{
DimTextType(0);
}
// 是否只修改了管径
double dDn = 0.0;
if (!IsOnlyModifiedPipeDn(sText, sOldText, dDn))
{
return false;
}
bool bUpdateOtherDim = false;
DList<AcDbObjectId> lstAttachment;
CDbPipe *pPipe = NULL;
acdbOpenObject(pPipe, idPipe, AcDb::kForRead);
if (pPipe != NULL)
{
bUpdateOtherDim = pPipe->IsLinkedPipeDnDimText();
pPipe->GetAttachments(lstAttachment);
pPipe->close();
}
// 更新其他管线关联标注
if (!bUpdateOtherDim)
{
int nLen = lstAttachment.Length();
for (int m = 0; m < nLen; m++)
{
AcDbObjectId idTmp = *lstAttachment[m];
OPENOBJ_BEGIN(idTmp, AcDb::kForWrite, CDbPipeText, pText);
if (pText != NULL)
{
if (::DimTextType(pText) == 0)
{
pText->SetText(sText);
}
}
OPENOBJ_END();
}
}
// 更新管径
acdbOpenObject(pPipe, idPipe, AcDb::kForWrite);
if (pPipe != NULL)
{
pPipe->SetDnDiameter(dDn);
// 双线水管,需更新法兰信息
//if (pPipe->isKindOf(TDbDoubleLinePipe::desc()))
//{
// TDbDoubleLinePipe *pDoublePipe = (TDbDoubleLinePipe*)pPipe;
// double dPipeDn = pDoublePipe->GetDnDiameter();
// CString sPn = ReadXdata(pDoublePipe, _T("TG-PIPE-FLANGE-PN"));
// int nPn = 0;
// if (sPn == _T("0.25MPa"))
// {
// nPn = 0;
// }
// else if (sPn == _T("0.6MPa"))
// {
// nPn = 1;
// }
// else if (sPn == _T("1.0MPa"))
// {
// nPn = 2;
// }
// else if (sPn == _T("1.6MPa"))
// {
// nPn = 3;
// }
// double dFlangeDn = 0.0, dFlangeThick = 0.0;
// GetFlangeDataByDn(nPn, dPipeDn, dFlangeDn, dFlangeThick);
// pDoublePipe->SetWidth(dPipeDn);
// pDoublePipe->SetFlangeDn(dFlangeDn);
// pDoublePipe->SetFlangeThick(dFlangeThick);
//}
pPipe->close();
}
return true;
}
else if (nDimTextType == 1) // 管线文字
{
if (DimTextType() == -1)
{
DimTextType(1);
}
CDbPipe *pPipe = NULL;
acdbOpenObject(pPipe, idPipe, AcDb::kForWrite);
if (pPipe != NULL)
{
pPipe->SetLinkedPipeText(sText);
pPipe->close();
}
return true;
}
return false;
}
//////////////////////////////////////////////////////////////////////////
void InitDbLabel(BOOL bTrue)
{
if (bTrue) {
CDbPipeLabel::rxInit();
CDbPipeText::rxInit();
//CDbPipeLabel::InitMatchProtocol(TRUE);
//CDbPipeText::InitMatchProtocol(TRUE);
}
else {
//CDbPipeLabel::InitMatchProtocol(FALSE);
//CDbPipeText::InitMatchProtocol(FALSE);
deleteAcRxClass(CDbPipeLabel::desc());
deleteAcRxClass(CDbPipeText::desc());
}
}