2128 lines
52 KiB
C++
2128 lines
52 KiB
C++
|
||
#include "stdafx.h"
|
||
#include "TDbHvacDimension.h"
|
||
#include "dbproxy.h"
|
||
#include "TGripImp.h"
|
||
#include "dbtext.h"
|
||
#include "TDbPipeMatchPropertiesReactor.h"
|
||
|
||
|
||
// #define VERSION_HVACDIMENSION 1
|
||
#define VERSION_HVACDIMENSION 2 // change by hh 2013-9-2
|
||
GripAppData TDbHvacDimension::s_gripHvacAppData[GRIDDATANUM];
|
||
|
||
double g_dCmdOff = 100; // 命令夹点距离实体距离
|
||
|
||
//{{AFX_ARX_MACRO
|
||
ACRX_DXF_DEFINE_MEMBERS( TDbHvacDimension, TDbEntity,
|
||
AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
||
AcDbProxyEntity::kAllAllowedBits,
|
||
ATS_HVACDIMENSION, "图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
|
||
//}}AFX_ARX_MACRO
|
||
double TDbHvacDimension::m_dDensity = 0.0;
|
||
double TDbHvacDimension::m_dMoveVis = 0.0;
|
||
|
||
TDbHvacDimension::TDbHvacDimension()
|
||
{
|
||
m_pDuctXDataMap = NULL;
|
||
|
||
// m_xDataMap.SetAt(KEY_DXF, _T("ATS_HVACDIMENSION"));
|
||
m_XDataMap.SetAt(KEY_DXF, _T("ATS_HVACDIMENSION"));
|
||
SetArrowLen(350.0);
|
||
SetArrowStyle(1);
|
||
}
|
||
|
||
|
||
TDbHvacDimension::~TDbHvacDimension()
|
||
{
|
||
|
||
}
|
||
|
||
// 特性表用
|
||
Acad::ErrorStatus TDbHvacDimension::subGetClassID(CLSID* pClsid) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
// #if (ADS < 16)
|
||
// // {C7DFDF6A-A5F2-4add-ADCC-7AC0675AB6EB}
|
||
// CLSID CLSID_PipeBaseEntity = {0xC7DFDF6B, 0xA5F2, 0x4ADE, { 0xAD, 0xCC, 0x7A, 0xC0, 0x67, 0x5A, 0xB6, 0xEB }};
|
||
// #endif
|
||
//
|
||
// #if (ADS == 16)
|
||
// // {C7DFDF6A-A5F2-4add-ADCC-7AC0675AB6EC}
|
||
// CLSID CLSID_PipeBaseEntity = {0xC7DFDF6B, 0xA5F2, 0x4ADE, { 0xAD, 0xCC, 0x7A, 0xC0, 0x67, 0x5A, 0xB6, 0xEC }};
|
||
// #endif
|
||
//
|
||
// #if (ADS == 17)
|
||
// // {C7DFDF6A-A5F2-4add-ADCC-7AC0675AB6ED}
|
||
// CLSID CLSID_PipeBaseEntity = {0xC7DFDF6B, 0xA5F2, 0x4ADE, { 0xAD, 0xCC, 0x7A, 0xC0, 0x67, 0x5A, 0xB6, 0xED }};
|
||
// #endif
|
||
//
|
||
// #if (ADS == 18)
|
||
// CLSID CLSID_PipeBaseEntity = {0xC7DFDF6B, 0xA5F2, 0x4ADE, { 0xAD, 0xCC, 0x7A, 0xC0, 0x67, 0x5A, 0xB6, 0xEE }};
|
||
// #endif
|
||
//
|
||
// #if (ADS == 19)
|
||
// CLSID CLSID_PipeBaseEntity = {0xC7DFDF6B, 0xA5F2, 0x4ADE, { 0xAD, 0xCC, 0x7A, 0xC0, 0x67, 0x5A, 0xB6, 0xEE }};
|
||
// #endif
|
||
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
// 变换
|
||
Acad::ErrorStatus TDbHvacDimension::subTransformBy( const AcGeMatrix3d& xform )
|
||
{
|
||
assertWriteEnabled();
|
||
// 各点位置
|
||
XPoint ptBase(GetBasePoint()), ptLeader(GetLeadPoint());
|
||
XPoint ptDirect = ptBase;
|
||
ptBase.TransformBy(xform);
|
||
ptLeader.TransformBy(xform);
|
||
SetBasePoint(ptBase);
|
||
SetLeadPoint(ptLeader);
|
||
|
||
// 纠正角度
|
||
AcGeVector3d vtLead(ptLeader - ptBase);
|
||
double dAngle(GetTextAngle());
|
||
AcGeVector3d vtAngle(cos(dAngle), sin(dAngle), 0);
|
||
HvacDimType eTtype = GetType();
|
||
if (eTtype == eDimInnerPipe || eTtype == eDimAbovePipe || eTtype == eDimBelowPipe)
|
||
{
|
||
vtAngle.transformBy(xform);
|
||
dAngle = acutAngle(XPoint(), XPoint(vtAngle));
|
||
SetTextAngle(dAngle);
|
||
}
|
||
else if (eTtype == eDimLeadLine || eTtype == eDimLeadBound)
|
||
{
|
||
if (vtLead.angleTo(vtAngle) > PI * 0.5)
|
||
{
|
||
dAngle += PI;
|
||
// dAngle = AsStdAngle(dAngle);
|
||
dAngle = AngleRangeTo2PI(dAngle);
|
||
SetTextAngle(dAngle);
|
||
}
|
||
}
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
// 拉伸点设置
|
||
Acad::ErrorStatus TDbHvacDimension::subGetStretchPoints( AcGePoint3dArray& stretchPoints ) const
|
||
{
|
||
assertReadEnabled();
|
||
stretchPoints.append(GetBasePoint());
|
||
stretchPoints.append(GetLeadPoint());
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbHvacDimension::subMoveStretchPointsAt( const AcDbIntArray& indices,
|
||
const AcGeVector3d& offset )
|
||
{
|
||
return subMoveGripPointsAt(indices, offset);
|
||
}
|
||
|
||
// 夹点设置
|
||
Acad::ErrorStatus TDbHvacDimension::subGetGripPoints( AcGePoint3dArray& gripPoints,
|
||
AcDbIntArray& osnapModes,
|
||
AcDbIntArray& geomIds ) const
|
||
{
|
||
assertReadEnabled();
|
||
gripPoints.append(GetBasePoint());
|
||
osnapModes.append(0);
|
||
|
||
HvacDimType eType = GetType();
|
||
if (eType == eDimLeadLine || eType == eDimLeadBound)
|
||
{
|
||
gripPoints.append(GetLeadPoint());
|
||
osnapModes.append(1);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbHvacDimension::subMoveGripPointsAt( const AcDbIntArray& indices,
|
||
const AcGeVector3d& offset )
|
||
{
|
||
assertWriteEnabled();
|
||
//add by dyw 2014-7-17
|
||
if(!AllowMoveGirp())
|
||
return Acad::eOk;
|
||
//add end
|
||
AcGePoint3d ptMove;
|
||
int i(0);
|
||
for (i = 0; i < indices.length(); i++)
|
||
{
|
||
if (indices[i] == 0)
|
||
{
|
||
ptMove = GetBasePoint();
|
||
ptMove += offset;
|
||
SetBasePoint(ptMove);
|
||
}
|
||
else if (indices[i] == 1)
|
||
{
|
||
ptMove = GetLeadPoint();
|
||
ptMove += offset;
|
||
SetLeadPoint(ptMove);
|
||
}
|
||
|
||
// 纠正角度
|
||
double dAngle(GetTextAngle());
|
||
AcGeVector3d vtAngle(cos(dAngle), sin(dAngle), 0);
|
||
AcGeVector3d vtLead(GetLeadPoint() - GetBasePoint());
|
||
if (vtAngle.angleTo(vtLead) > PI * 0.5)
|
||
{
|
||
dAngle += PI;
|
||
// dAngle = AsStdAngle(dAngle);
|
||
dAngle = AngleRangeTo2PI(dAngle);
|
||
SetTextAngle(dAngle);
|
||
}
|
||
}
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
#if (ADS > 15)
|
||
Acad::ErrorStatus TDbHvacDimension::subMoveGripPointsAt( const AcDbVoidPtrArray& gripAppData,
|
||
const AcGeVector3d& offset,
|
||
const int bitflags )
|
||
{
|
||
assertWriteEnabled();
|
||
TDb::GripAppData* pAppData = NULL;
|
||
AcDbIntArray arIndex;
|
||
int nSize = gripAppData.length();
|
||
for (int i = 0;i < gripAppData.length();i++)
|
||
{
|
||
pAppData = (TDb::GripAppData*)gripAppData.at(i);
|
||
arIndex.append(pAppData->nIndex);
|
||
}
|
||
|
||
return subMoveGripPointsAt(arIndex, offset);
|
||
}
|
||
|
||
Acad::ErrorStatus TDbHvacDimension::subGetGripPoints( AcDbGripDataPtrArray& grips,
|
||
const double viewSize,
|
||
const int gripSize,
|
||
const AcGeVector3d& curViewDir,
|
||
const int bitflags ) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcDbIntArray osnapModes;
|
||
AcDbIntArray geomIds;
|
||
AcGePoint3dArray gripPoints;
|
||
Acad::ErrorStatus eSta = subGetGripPoints(gripPoints,osnapModes,geomIds);
|
||
|
||
AcDbGripData* pGripData = NULL;
|
||
CString csTip;
|
||
Position ePos = eDim0;
|
||
|
||
for (int i = 0; i < gripPoints.length() && i < GRIDDATANUM; i++)
|
||
{
|
||
pGripData = new AcDbGripData;
|
||
if (osnapModes[i] == 0)
|
||
{
|
||
ePos = eDim0;
|
||
csTip = _T("标注基点");
|
||
}
|
||
else if (osnapModes[i] == 1)
|
||
{
|
||
csTip = _T("引线点");
|
||
ePos = eDim1;
|
||
}
|
||
|
||
memset(&s_gripHvacAppData[i], 0, sizeof(GripAppData));
|
||
s_gripHvacAppData[i].nIndex = osnapModes[i];
|
||
s_gripHvacAppData[i].ePos = ePos;
|
||
s_gripHvacAppData[i].ptGrip = gripPoints.at(i);
|
||
_tcscpy(s_gripHvacAppData[i].szTip, csTip);
|
||
|
||
s_gripHvacAppData[i].pOwner = (AcDbEntity*)this;
|
||
pGripData->setGripPoint(gripPoints.at(i));
|
||
pGripData->setAppData((void*)&s_gripHvacAppData[i]);
|
||
pGripData->setToolTipFunc(GripCback::GripToolTipFunc);
|
||
grips.append(pGripData);
|
||
}
|
||
|
||
return eSta;
|
||
}
|
||
#endif
|
||
|
||
|
||
Acad::ErrorStatus TDbHvacDimension::subGetOsnapPoints( AcDb::OsnapMode osnapMode,
|
||
INT_PTR gsSelectionMark,
|
||
const AcGePoint3d& pickPoint,
|
||
const AcGePoint3d& lastPoint,
|
||
const AcGeMatrix3d& viewXform,
|
||
AcGePoint3dArray& snapPoints,
|
||
AcDbIntArray& geomIds ) const
|
||
{
|
||
assertReadEnabled();
|
||
if (AcDb::kOsModeEnd == osnapMode || AcDb::kOsModeNear == osnapMode) // 带引线的
|
||
{
|
||
HvacDimType eType = GetType();
|
||
if (eType == eDimLeadLine || eType == eDimLeadBound)
|
||
{
|
||
AcGePoint3d ptBase(GetBasePoint()), ptLead(GetLeadPoint()), ptDirect(GetDirectPoint());
|
||
AcGePlane plan(ptBase, ptLead, ptDirect);
|
||
|
||
AcGeVector3d vtNormal = TAuxTools::GetUcsZvt();
|
||
AcGePoint3d ptOrth = AcGePoint3d::kOrigin.orthoProject(plan);
|
||
plan.set(ptOrth, vtNormal);
|
||
|
||
double dEle = ptOrth.asVector().length();
|
||
if (!ptOrth.asVector().isCodirectionalTo(vtNormal))
|
||
dEle *= -1.0;
|
||
|
||
AcDbPolyline polyLine;
|
||
polyLine.addVertexAt(0, ptBase.convert2d(plan));
|
||
polyLine.addVertexAt(1, ptLead.convert2d(plan));
|
||
polyLine.addVertexAt(2, ptDirect.convert2d(plan));
|
||
return polyLine.getOsnapPoints(osnapMode,gsSelectionMark,pickPoint,lastPoint,viewXform,
|
||
snapPoints,geomIds);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (AcDb::kOsModeNode)
|
||
{
|
||
AcDbPoint dbPoint(GetBasePoint());
|
||
return dbPoint.getOsnapPoints(osnapMode,gsSelectionMark,pickPoint,lastPoint,viewXform,
|
||
snapPoints,geomIds);
|
||
}
|
||
}
|
||
|
||
return Acad::eNotImplementedYet;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbHvacDimension::dxfOutFields( AcDbDxfFiler* pFiler ) const
|
||
{
|
||
assertReadEnabled();
|
||
Acad::ErrorStatus es;
|
||
|
||
if ((es = TDbEntity::dxfOutFields(pFiler)) != Acad::eOk)
|
||
return es;
|
||
|
||
// Write subclass marker.
|
||
pFiler->writeItem(AcDb::kDxfSubclass, _T("TDbHvacDimension"));
|
||
|
||
// Write version number.
|
||
pFiler->writeItem(AcDb::kDxfInt16, (Adesk::UInt16) VERSION_HVACDIMENSION);
|
||
|
||
return es;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbHvacDimension::dxfInFields( AcDbDxfFiler* pFiler )
|
||
{
|
||
assertWriteEnabled();
|
||
struct resbuf rb;
|
||
|
||
if ((TDbEntity::dxfInFields(pFiler) != Acad::eOk) ||
|
||
!pFiler->atSubclassData(_T("TDbHvacDimension")))
|
||
return pFiler->filerStatus();
|
||
|
||
// Read version number.
|
||
pFiler->readItem(&rb);
|
||
if (rb.restype != AcDb::kDxfInt16)
|
||
{
|
||
pFiler->pushBackItem();
|
||
pFiler->setError(Acad::eInvalidDxfCode,
|
||
_T("Error: expected object version group code %d"),
|
||
AcDb::kDxfInt16);
|
||
return pFiler->filerStatus();
|
||
}
|
||
else
|
||
{
|
||
Adesk::UInt16 version = rb.resval.rint;
|
||
if (version > VERSION_HVACDIMENSION)
|
||
return Acad::eMakeMeProxy;
|
||
}
|
||
|
||
return pFiler->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus TDbHvacDimension::dwgOutFields( AcDbDwgFiler* pFiler ) const
|
||
{
|
||
assertReadEnabled();
|
||
Acad::ErrorStatus es;
|
||
|
||
// Call dwgOutFields from TDbInterfacesObj
|
||
if ((es = TDbEntity::dwgOutFields(pFiler)) != Acad::eOk)
|
||
return es;
|
||
|
||
// Write version number.
|
||
// change by hh 2013-09-02 XDataMap在基类中写入
|
||
// pFiler->writeItem((Adesk::UInt16) VERSION_HVACDIMENSION);
|
||
// m_xDataMap.dwgOutFields(pFiler);
|
||
if (g_nSaveTArchVer <= 9)
|
||
{
|
||
pFiler->writeItem((Adesk::UInt16) 1);
|
||
m_XDataMap.dwgOutFields(pFiler);
|
||
}
|
||
else
|
||
{
|
||
pFiler->writeItem((Adesk::UInt16) VERSION_HVACDIMENSION);
|
||
}
|
||
return pFiler->filerStatus();}
|
||
|
||
Acad::ErrorStatus TDbHvacDimension::dwgInFields( AcDbDwgFiler* pFiler )
|
||
{
|
||
assertWriteEnabled();
|
||
Acad::ErrorStatus es;
|
||
|
||
// Call dwgInFields from TDbInterfacesObj
|
||
if ((es = TDbEntity::dwgInFields(pFiler)) != Acad::eOk)
|
||
return es;
|
||
|
||
// Read version number.
|
||
Adesk::UInt16 version;
|
||
pFiler->readItem(&version);
|
||
if (version > VERSION_HVACDIMENSION)
|
||
return Acad::eMakeMeProxy;
|
||
|
||
// change by hh 2013-9-2
|
||
/*switch (version)
|
||
{
|
||
case (1):
|
||
{
|
||
m_xDataMap.dwgInFields(pFiler);
|
||
m_xDataMap.SetAt(KEY_THISID, objectId());
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}*/
|
||
if(2 > version)
|
||
{
|
||
m_XDataMap.dwgInFields(pFiler);
|
||
m_XDataMap.SetAt(KEY_THISID, objectId());
|
||
}
|
||
|
||
InitDuctXData();
|
||
|
||
return pFiler->filerStatus();
|
||
}
|
||
|
||
// 主绘制函数
|
||
Acad::ErrorStatus TDbHvacDimension::ExplodeOrDraw2d( XExplodeDraw &dc ) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
AcDbVoidPtrArray entityArr;
|
||
AcDbEntity* pEnt = NULL;
|
||
TDbText* pText = NULL;
|
||
MakeEntity(entityArr);
|
||
|
||
AcDbObjectId idOrigLayer = dc.GetLayerId();
|
||
|
||
for (int i = 0; i < entityArr.length(); i++)
|
||
{
|
||
pEnt = (AcDbEntity*)entityArr[i];
|
||
if (pEnt != NULL)
|
||
{
|
||
dc.SetLayer(pEnt->layerId());
|
||
pEnt->setColorIndex(colorIndex());
|
||
if(dc.IsFullExplode())
|
||
{
|
||
if (pEnt->isKindOf(TDbText::desc()))
|
||
{
|
||
pText = TDbText::cast(pEnt);
|
||
if (NULL != pText)
|
||
{
|
||
// change by hh 2013-1-14 未知的需求来源,固定为白色后用户意见较大,恢复原始。
|
||
// pText->setColorIndex(colorIndex());
|
||
// pText->setColorIndex(7);// 文字一直设置为白色Lixl add 2012-5-3
|
||
pText->setColorIndex(colorIndex());
|
||
// change end
|
||
pText->ExplodeOrDraw2d(dc);
|
||
}
|
||
}
|
||
else
|
||
dc.DrawEntity(*pEnt);
|
||
}
|
||
else
|
||
dc.DrawEntity(*pEnt);
|
||
|
||
// if (pEnt->isKindOf(TDbText::desc())) // 文字用dc.DrawEntity不能设颜色
|
||
// {
|
||
// pText = TDbText::cast(pEnt);
|
||
// if (NULL != pText)
|
||
// pText->ExplodeOrDraw2d(dc);
|
||
// }
|
||
// else
|
||
// dc.DrawEntity(*pEnt);
|
||
|
||
delete pEnt;
|
||
pEnt = NULL;
|
||
}
|
||
}
|
||
dc.SetLayer(idOrigLayer);
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus TDbHvacDimension::ExplodeOrDraw3d( XExplodeDraw &dc ) const
|
||
{
|
||
return Acad::eNotImplementedYet;
|
||
}
|
||
|
||
// 返回所有需要绘制的实体指针,用完负责删除
|
||
void TDbHvacDimension::MakeEntity( AcDbVoidPtrArray &entityArr ) const
|
||
{
|
||
HvacDimType eType = GetType();
|
||
AcGePoint3d ptBase(GetBasePoint());
|
||
AcDbObjectId idStyle = GetTextStyle();
|
||
double dHeigh = GetTextHeigh();
|
||
double dAngle = GetTextAngle();
|
||
|
||
// 矫正角度
|
||
XVector3D vt(cos(dAngle), sin(dAngle), 0);
|
||
if (TAuxTools::GetUcsXvt().angleTo(vt) > PI * 0.5)
|
||
vt *= -1;
|
||
|
||
AcGeVector3d vtUcsY = TAuxTools::GetUcsYvt();
|
||
if (vtUcsY.isCodirectionalTo(-vt.AsAcGeVector3d()))
|
||
vt = vtUcsY;
|
||
|
||
dAngle = acutAngle(XPoint(), vt);
|
||
|
||
CStringArray arrText;
|
||
if (!GetEachStr(GetText(), arrText) || arrText.GetSize() != 4)
|
||
return;
|
||
|
||
|
||
AcDbObjectId idLayer = layerId();
|
||
if (eType == eDimLeadLine || eType == eDimLeadBound) // 带引线及中间割线/边框
|
||
{
|
||
|
||
TDbText* pText1 = NULL, *pText2 = NULL, *pText3 = NULL, *pText4 = NULL;
|
||
pText1 = CrteatText(arrText[0], idLayer, idStyle, dHeigh, ptBase, dAngle);
|
||
pText2 = CrteatText(arrText[1], idLayer, idStyle, dHeigh, ptBase, dAngle);
|
||
pText3 = CrteatText(arrText[2], idLayer, idStyle, dHeigh, ptBase, dAngle);
|
||
pText4 = CrteatText(arrText[3], idLayer, idStyle, dHeigh, ptBase, dAngle);
|
||
|
||
AcGePoint3dArray ptArr;
|
||
GetKeyPoint(pText1, pText2, pText3, pText4, ptArr);
|
||
if (ptArr.length() == 9)
|
||
{
|
||
if (pText1 != NULL)
|
||
{
|
||
pText1->SetLocation(TAuxTools::Mid(ptArr[0], ptArr[4]));
|
||
|
||
entityArr.append(pText1);
|
||
}
|
||
if (pText2 != NULL)
|
||
{
|
||
pText2->SetLocation(TAuxTools::Mid(ptArr[1], ptArr[5]));
|
||
entityArr.append(pText2);
|
||
|
||
}
|
||
if (pText3 != NULL)
|
||
{
|
||
pText3->SetLocation(TAuxTools::Mid(ptArr[3], ptArr[7]));
|
||
|
||
entityArr.append(pText3);
|
||
}
|
||
if (pText4 != NULL)
|
||
{
|
||
pText4->SetLocation(TAuxTools::Mid(ptArr[4], ptArr[8]));
|
||
|
||
entityArr.append(pText4);
|
||
}
|
||
MakeLeadAndFrame(ptArr, entityArr);
|
||
}
|
||
else
|
||
{
|
||
if (pText1 != NULL)
|
||
delete pText1;
|
||
if (pText2 != NULL)
|
||
delete pText2;
|
||
if (pText3 != NULL)
|
||
delete pText3;
|
||
if (pText4 != NULL)
|
||
delete pText4;
|
||
}
|
||
}
|
||
else // 单行文字
|
||
{
|
||
CString csText = arrText[0] + arrText[1] + arrText[2] + arrText[3];
|
||
|
||
TDbText* pText = CrteatText(csText, idLayer, idStyle, dHeigh, ptBase, dAngle);
|
||
entityArr.append(pText);
|
||
}
|
||
}
|
||
|
||
// 创建引线及边框
|
||
void TDbHvacDimension::MakeLeadAndFrame( AcGePoint3dArray &ptArr, AcDbVoidPtrArray &entityArr ) const
|
||
{
|
||
AcDbObjectId idLayer = layerId();
|
||
// 引线
|
||
XPoint ptBase(GetBasePoint()), ptLead(GetLeadPoint());
|
||
AcDbLine* pLineLead = new AcDbLine(ptBase, ptLead);
|
||
pLineLead->setLayer(idLayer);
|
||
entityArr.append(pLineLead);
|
||
|
||
// 方向线
|
||
AcDbLine* pLineDirect = new AcDbLine(ptArr[3], ptArr[5]);
|
||
pLineDirect->setLayer(idLayer);
|
||
entityArr.append(pLineDirect);
|
||
|
||
// 边框
|
||
HvacDimType eType = GetType();
|
||
if (eType == eDimLeadBound)
|
||
{
|
||
CStringArray arrText;
|
||
if (!GetEachStr(GetText(), arrText) || arrText.GetSize() != 4)
|
||
return;
|
||
|
||
if (!arrText[0].IsEmpty() || !arrText[1].IsEmpty())
|
||
{
|
||
AcDbPolyline* pPolyLine = new AcDbPolyline;
|
||
pPolyLine->addVertexAt(0, ptArr[3].convert2d(AcGePlane::kXYPlane));
|
||
pPolyLine->addVertexAt(1, ptArr[0].convert2d(AcGePlane::kXYPlane));
|
||
pPolyLine->addVertexAt(2, ptArr[2].convert2d(AcGePlane::kXYPlane));
|
||
pPolyLine->addVertexAt(3, ptArr[5].convert2d(AcGePlane::kXYPlane));
|
||
pPolyLine->setLayer(idLayer);
|
||
entityArr.append(pPolyLine);
|
||
|
||
// 分割线
|
||
AcDbLine* pLineDivid = new AcDbLine(ptArr[1], ptArr[4]);
|
||
pLineDivid->setLayer(idLayer);
|
||
entityArr.append(pLineDivid);
|
||
}
|
||
|
||
if (!arrText[2].IsEmpty() || !arrText[3].IsEmpty())
|
||
{
|
||
AcDbPolyline* pPolyLine = new AcDbPolyline;
|
||
pPolyLine->addVertexAt(0, ptArr[3].convert2d(AcGePlane::kXYPlane));
|
||
pPolyLine->addVertexAt(1, ptArr[6].convert2d(AcGePlane::kXYPlane));
|
||
pPolyLine->addVertexAt(2, ptArr[8].convert2d(AcGePlane::kXYPlane));
|
||
pPolyLine->addVertexAt(3, ptArr[5].convert2d(AcGePlane::kXYPlane));
|
||
pPolyLine->setLayer(idLayer);
|
||
entityArr.append(pPolyLine);
|
||
|
||
// 分割线
|
||
AcDbLine* pLineDivid = new AcDbLine(ptArr[4], ptArr[7]);
|
||
pLineDivid->setLayer(idLayer);
|
||
entityArr.append(pLineDivid);
|
||
}
|
||
}
|
||
|
||
// 绘制箭头
|
||
if (GetArrowStyle() != 0)
|
||
MakeArrow(entityArr);
|
||
}
|
||
|
||
// 创建标注原点箭头
|
||
void TDbHvacDimension::MakeArrow( AcDbVoidPtrArray &entityArr ) const
|
||
{
|
||
int nArrowStyle = GetArrowStyle();
|
||
double dArrowLen = GetArrowLen() * GetPScale();
|
||
AcGePoint3d ptBase(GetBasePoint()), ptLead(GetLeadPoint());
|
||
AcGeVector3d vtNormal = TAuxTools::GetUcsZvt();
|
||
AcGeVector3d vtLead = (ptLead - ptBase).orthoProject(vtNormal).normalize();
|
||
AcGePoint3d ptSta, ptEnd;
|
||
if (nArrowStyle == 1) // 箭头
|
||
{
|
||
ptSta = ptBase;
|
||
ptEnd = ptBase + dArrowLen * vtLead;
|
||
double dEndWidth = dArrowLen * tan(8.0 * PI / 180.0) * 2;
|
||
|
||
AcDbPolyline* pPolyLine = new AcDbPolyline;
|
||
pPolyLine->addVertexAt(0, ptSta.convert2d(AcGePlane::kXYPlane));
|
||
pPolyLine->addVertexAt(1, ptEnd.convert2d(AcGePlane::kXYPlane));
|
||
pPolyLine->setWidthsAt(0, 0, dEndWidth);
|
||
pPolyLine->setLayer(layerId());
|
||
entityArr.append(pPolyLine);
|
||
}
|
||
else if (nArrowStyle == 2) // 十字
|
||
{
|
||
dArrowLen *= 0.5;
|
||
AcGeVector3d vtX(TAuxTools::GetUcsXvt());
|
||
AcGeVector3d vtY(TAuxTools::GetUcsYvt());
|
||
|
||
ptSta = ptBase - dArrowLen * vtX;
|
||
ptEnd = ptBase + dArrowLen * vtX;
|
||
AcDbLine* pLine1 = new AcDbLine(ptSta, ptEnd);
|
||
pLine1->setLayer(layerId());
|
||
|
||
ptSta = ptBase - dArrowLen * vtY;
|
||
ptEnd = ptBase + dArrowLen * vtY;
|
||
AcDbLine* pLine2 = new AcDbLine(ptSta, ptEnd);
|
||
pLine2->setLayer(layerId());
|
||
|
||
entityArr.append(pLine1);
|
||
entityArr.append(pLine2);
|
||
}
|
||
else if (nArrowStyle == 3) // 圆点
|
||
{
|
||
dArrowLen = dArrowLen * 0.8 / 12.0;
|
||
AcGeVector3d vtOff = dArrowLen * vtLead;
|
||
ptSta = ptBase + vtOff;
|
||
ptEnd = ptBase - vtOff;
|
||
|
||
AcDbPolyline* pPolyLine = new AcDbPolyline;
|
||
pPolyLine->addVertexAt(0, ptSta.convert2d(AcGePlane::kXYPlane), 1);
|
||
pPolyLine->addVertexAt(1, ptEnd.convert2d(AcGePlane::kXYPlane), 1);
|
||
pPolyLine->addVertexAt(2, ptSta.convert2d(AcGePlane::kXYPlane));
|
||
pPolyLine->setConstantWidth(dArrowLen * 2);
|
||
pPolyLine->setClosed(Adesk::kTrue);
|
||
pPolyLine->setLayer(layerId());
|
||
entityArr.append(pPolyLine);
|
||
}
|
||
}
|
||
|
||
// 获取标注各关键点
|
||
/*
|
||
0━━━━1━━━━━2
|
||
┃ Lable1 ┃Lable2 ┃
|
||
3━━━━4━━━━━5
|
||
┃ Lable3 ┃Lable4 ┃
|
||
6━━━━7━━━━━8
|
||
*/
|
||
void TDbHvacDimension::GetKeyPoint( TDbText* pText1, TDbText* pText2, TDbText* pText3, TDbText* pText4, AcGePoint3dArray &arrPoint ) const
|
||
{
|
||
int nSize = arrPoint.length();
|
||
if (nSize > 0)
|
||
arrPoint.removeSubArray(0, nSize - 1);
|
||
|
||
XPoint pt0, pt1, pt2, pt3, pt4, pt5, pt6, pt7, pt8;
|
||
XPoint ptLead = GetLeadPoint();
|
||
// pt3 = ptLead;
|
||
|
||
// 四个标注部分各长度
|
||
double dLen1 = GetTextLen(pText1);
|
||
double dLen2 = GetTextLen(pText2);
|
||
double dLen3 = GetTextLen(pText3);
|
||
double dLen4 = GetTextLen(pText4);
|
||
double dCol1Len = dLen1 > dLen3 ? dLen1:dLen3; // 第一列长度
|
||
double dCol2Len = dLen2 > dLen4 ? dLen2:dLen4; // 第二列长度
|
||
double dScale = GetPScale();
|
||
double dTextHeigh = GetTextHeigh();
|
||
// change by hh 2011-05-12 标注文字距基线系数使用建筑基本设定中的参数
|
||
// double dGapLen = g_nText2BaseRatio * dTextHeigh * dScale * 2;
|
||
double dGapLen = DocGetText2BaseRatio() * dTextHeigh * dScale * 2;
|
||
double dRowHeigh = dTextHeigh * dScale + dGapLen;
|
||
|
||
if (dCol1Len > 1e-3)
|
||
dCol1Len += dGapLen;
|
||
|
||
if (dCol2Len > 1e-3)
|
||
dCol2Len += dGapLen;
|
||
|
||
double dAngle = GetTextAngle();
|
||
AcGePoint3d ptBase(GetBasePoint());
|
||
AcGeVector3d vtDirect = ptLead - ptBase;
|
||
if (vtDirect.angleTo(TAuxTools::GetUcsXvt()) > PI * 0.5)
|
||
{
|
||
dAngle += PI;
|
||
acutPolar(ptLead, dAngle, -(dCol1Len + dCol2Len), pt3);
|
||
}
|
||
else
|
||
pt3 = ptLead;
|
||
|
||
acutPolar(pt3, dAngle, dCol1Len, pt4);
|
||
acutPolar(pt4, dAngle, dCol2Len, pt5);
|
||
|
||
double dAnglePer = dAngle + PI * 0.5;
|
||
acutPolar(pt3, dAnglePer, dRowHeigh, pt0);
|
||
acutPolar(pt3, dAnglePer, -dRowHeigh, pt6);
|
||
acutPolar(pt4, dAnglePer, dRowHeigh, pt1);
|
||
acutPolar(pt4, dAnglePer, -dRowHeigh, pt7);
|
||
acutPolar(pt5, dAnglePer, dRowHeigh, pt2);
|
||
acutPolar(pt5, dAnglePer, -dRowHeigh, pt8);
|
||
|
||
arrPoint.append(pt0);
|
||
arrPoint.append(pt1);
|
||
arrPoint.append(pt2);
|
||
arrPoint.append(pt3);
|
||
arrPoint.append(pt4);
|
||
arrPoint.append(pt5);
|
||
arrPoint.append(pt6);
|
||
arrPoint.append(pt7);
|
||
arrPoint.append(pt8);
|
||
}
|
||
|
||
// 炸开
|
||
Acad::ErrorStatus TDbHvacDimension::subExplode( AcDbVoidPtrArray& entitySet ) const
|
||
{
|
||
assertReadEnabled();
|
||
// MakeEntity(entitySet);
|
||
|
||
// 没有空白文字了,2010.03.05
|
||
// 删除空白的文字
|
||
// int i(0);
|
||
// AcDbEntity* pEnt = NULL;
|
||
// TDbText* pText = NULL;
|
||
// for (i = 0; i < entitySet.length(); i++)
|
||
// {
|
||
// pEnt = (AcDbEntity*)entitySet[i];
|
||
// if (NULL != pEnt && pEnt->isKindOf(TDbText::desc()))
|
||
// {
|
||
// pText = TDbText::cast(pEnt);
|
||
// if (pText != NULL && pText->GetText() == _T(""))
|
||
// {
|
||
// delete pText;
|
||
// entitySet.removeAt(i);
|
||
// i--;
|
||
// }
|
||
// }
|
||
// }
|
||
// return Acad::eOk;
|
||
return TDbEntity::subExplode(entitySet);
|
||
}
|
||
|
||
// BOOL TDbHvacDimension::SetAt(LPCTSTR pszKey,TXData& XData)
|
||
// {
|
||
// assertWriteEnabled();
|
||
//
|
||
// return m_xDataMap.SetAt(pszKey,XData);
|
||
// }
|
||
//
|
||
// BOOL TDbHvacDimension::GetAt(LPCTSTR pszKey,TXData& XData) const
|
||
// {
|
||
// assertReadEnabled();
|
||
//
|
||
// return m_xDataMap.GetAt(pszKey,XData);
|
||
// }
|
||
|
||
// 特性表信息
|
||
BOOL TDbHvacDimension::OPMInfo( LPCTSTR pszName, TDb::OPMInfo* pInfo )
|
||
{
|
||
if (isWriteEnabled())
|
||
assertWriteEnabled();
|
||
else
|
||
assertReadEnabled();
|
||
|
||
ASSERT(NULL != pszName && NULL != pInfo && NULL != m_pXDataMap);
|
||
|
||
if (0 == _tcsicmp(pszName, HDIM_DimType))
|
||
{
|
||
pInfo->bVisible = TRUE;
|
||
pInfo->bEditable = TRUE;
|
||
|
||
// 提供数据列表和对应关系
|
||
if (NULL != pInfo->parsValues && NULL != pInfo->parlValues)
|
||
{
|
||
pInfo->parsValues->Add(_T("管子左上标注"));
|
||
pInfo->parlValues->Add(TDb::eDimAbovePipe);
|
||
pInfo->parsValues->Add(_T("管子右下标注"));
|
||
pInfo->parlValues->Add(TDb::eDimBelowPipe);
|
||
pInfo->parsValues->Add(_T("管子中间标注"));
|
||
pInfo->parlValues->Add(TDb::eDimInnerPipe);
|
||
pInfo->parsValues->Add(_T("无边框引出标注"));
|
||
pInfo->parlValues->Add(TDb::eDimLeadLine);
|
||
pInfo->parsValues->Add(_T("有边框引出标注"));
|
||
pInfo->parlValues->Add(TDb::eDimLeadBound);
|
||
}
|
||
|
||
// 设置数据
|
||
if (NULL != pInfo->pXData && 0 != pInfo->pXData->nVt)
|
||
{
|
||
SetAt(pszName, *pInfo->pXData);
|
||
pInfo->pXData->nVt = 0; // 设置处理完成标识
|
||
HvacDimType eDimType = GetType();
|
||
if (eDimType != eDimLeadLine && eDimType != eDimLeadBound)
|
||
ResetDimLoct();
|
||
else
|
||
{
|
||
SetTextAngle(0.0);
|
||
AcGeMatrix3d mat;
|
||
transformBy(mat);
|
||
}
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
HvacDimType eDimType = GetType();
|
||
if (0 == _tcsicmp(pszName, HDIM_DimEleType))
|
||
{
|
||
pInfo->bVisible = TRUE;
|
||
pInfo->bEditable = TRUE;
|
||
|
||
// 提供数据列表和对应关系
|
||
if (NULL != pInfo->parsValues && NULL != pInfo->parlValues)
|
||
{
|
||
pInfo->parsValues->Add(_T("顶标高"));
|
||
pInfo->parlValues->Add(0);
|
||
pInfo->parsValues->Add(_T("中线标高"));
|
||
pInfo->parlValues->Add(1);
|
||
pInfo->parsValues->Add(_T("底标高"));
|
||
pInfo->parlValues->Add(2);
|
||
}
|
||
|
||
if (NULL != pInfo->pXData && 0 != pInfo->pXData->nVt)
|
||
{
|
||
SetAt(pszName, *pInfo->pXData);
|
||
TransTextToResult();
|
||
pInfo->pXData->nVt = 0;
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
// 直接传id,64位下会导致截断情况,com里不容易改,改用下面记录样式字符名方式,设置时再转为AcDbObjectId。
|
||
// 重新启用这种调用方法,Lixl modify 2012-5-16
|
||
#if ADS <= 17
|
||
if (0 == _tcsicmp(pszName, HDIM_DimTextId))
|
||
{
|
||
pInfo->bVisible = TRUE;
|
||
pInfo->bEditable = TRUE;
|
||
|
||
// 设置数据(必须手动设置,由于AcDbOjbectId::asOldId(),拷贝到前他图中不适用
|
||
if (NULL != pInfo->pXData && 0 != pInfo->pXData->nVt)
|
||
{
|
||
AcDbObjectId idStyle;
|
||
idStyle.setFromOldId((*pInfo->pXData).nVal);
|
||
SetTextStyle(idStyle);
|
||
pInfo->pXData->nVt = 0; // 设置处理完成标识
|
||
}
|
||
else
|
||
{
|
||
// 提供数据列表和对应关系
|
||
if (NULL != pInfo->parsValues && NULL != pInfo->parlValues)
|
||
{
|
||
CStringArray csArrStyle;
|
||
TAuxTools::GetAllTextStyleNameArray(csArrStyle);
|
||
int i(0);
|
||
for (i = 0; i < csArrStyle.GetSize(); i++)
|
||
{
|
||
pInfo->parsValues->Add(csArrStyle[i]);
|
||
pInfo->parlValues->Add((DWORD)GetTextStyleId(csArrStyle[i]).asOldId());
|
||
}
|
||
}
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
#else
|
||
if (0 == _tcsicmp(pszName, HDIM_DimTextId))
|
||
{
|
||
pInfo->bVisible = TRUE;
|
||
pInfo->bEditable = TRUE;
|
||
|
||
if (NULL != pInfo->pXData)
|
||
{
|
||
// 设置数据
|
||
if (0 != pInfo->pXData->nVt)
|
||
{
|
||
AcDbObjectId idStyle = InitTextStyle(pInfo->pXData->pszVal);
|
||
if (idStyle.isValid())
|
||
{
|
||
SetTextStyle(idStyle);
|
||
pInfo->pXData->nVt = 0; // 设置处理完成标识
|
||
}
|
||
}
|
||
else // 读数据,获取样式名
|
||
{
|
||
TCHAR* pTChar = TAuxTools::GetFontStyle(GetTextStyle());
|
||
if (NULL != pTChar)
|
||
{
|
||
pInfo->pXData->npszLen = 0;
|
||
pInfo->pXData->pszVal = NULL;
|
||
|
||
pInfo->pXData->pszVal = pTChar;
|
||
pInfo->pXData->npszLen = _tcslen(pTChar);
|
||
pInfo->pXData->nVt = TXSTR;
|
||
}
|
||
}
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
#endif
|
||
|
||
if (0 == _tcsicmp(pszName, HDIM_DimTextHeigh))
|
||
{
|
||
pInfo->bVisible = TRUE;
|
||
pInfo->bEditable = TRUE;
|
||
|
||
// 文字高度变化后,需重定位
|
||
if (NULL != pInfo->pXData && 0 != pInfo->pXData->nVt)
|
||
{
|
||
SetAt(pszName, *pInfo->pXData);
|
||
pInfo->pXData->nVt = 0; // 设置处理完成标识
|
||
if (eDimType == eDimInnerPipe)
|
||
ResetDimLoct();
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
if (0 == _tcsicmp(pszName, HDIM_DimTextAngle))
|
||
{
|
||
pInfo->bVisible = (eDimType != eDimLeadLine && eDimType != eDimLeadBound);
|
||
pInfo->bEditable = pInfo->bVisible;
|
||
|
||
if (NULL != pInfo->pXData)
|
||
{
|
||
if (0 == pInfo->pXData->nVt) // 读数据
|
||
{
|
||
pInfo->pXData->dVal[0] = GetTextAngle() * 180.0 / PI;
|
||
pInfo->pXData->nVt = TXDBL;
|
||
}
|
||
else
|
||
{
|
||
// 设置数据
|
||
SetTextAngle(pInfo->pXData->dVal[0] * PI / 180.0);
|
||
pInfo->pXData->nVt = 0; // 设置处理完成标识
|
||
}
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
if (0 == _tcsicmp(pszName, HDIM_DimArrowStyle))
|
||
{
|
||
pInfo->bVisible = (eDimType == eDimLeadLine || eDimType == eDimLeadBound);
|
||
pInfo->bEditable = pInfo->bVisible;
|
||
|
||
// 提供数据列表和对应关系
|
||
if (NULL != pInfo->parsValues && NULL != pInfo->parlValues)
|
||
{
|
||
pInfo->parsValues->Add(_T("无箭头"));
|
||
pInfo->parlValues->Add(0);
|
||
pInfo->parsValues->Add(_T("常规箭头"));
|
||
pInfo->parlValues->Add(1);
|
||
pInfo->parsValues->Add(_T("十字"));
|
||
pInfo->parlValues->Add(2);
|
||
pInfo->parsValues->Add(_T("圆点"));
|
||
pInfo->parlValues->Add(3);
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
if (0 == _tcsicmp(pszName, HDIM_DimArrowLen))
|
||
{
|
||
pInfo->bVisible = (eDimType == eDimLeadLine || eDimType == eDimLeadBound);
|
||
pInfo->bEditable = pInfo->bVisible;
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
return FALSE;
|
||
}
|
||
|
||
// TDbXDataMap* TDbHvacDimension::GetSpecialtyData()
|
||
// {
|
||
// if (isWriteEnabled())
|
||
// assertWriteEnabled();
|
||
// else
|
||
// assertReadEnabled();
|
||
//
|
||
// return &m_xDataMap;
|
||
// }
|
||
|
||
// TDbXDataMap* TDbHvacDimension::GetSpecialtyDataReadOnly() const
|
||
// {
|
||
// assertReadEnabled();
|
||
// return &m_xDataMap;
|
||
// }
|
||
|
||
AcGePoint3d TDbHvacDimension::GetBasePoint() const
|
||
{
|
||
assertReadEnabled();
|
||
AcGePoint3d ptBase;
|
||
m_XDataMap.GetAt(HDIM_DimBasePos, ptBase);
|
||
return ptBase;
|
||
}
|
||
|
||
AcGePoint3d TDbHvacDimension::GetLeadPoint() const
|
||
{
|
||
assertReadEnabled();
|
||
AcGePoint3d pt;
|
||
m_XDataMap.GetAt(HDIM_DimLeadPos, pt);
|
||
return pt;
|
||
}
|
||
|
||
TDb::HvacDimType TDbHvacDimension::GetType() const
|
||
{
|
||
assertReadEnabled();
|
||
HvacDimType eType(eDimInnerPipe);
|
||
m_XDataMap.GetAt(HDIM_DimType, (int&)eType);
|
||
return eType;
|
||
}
|
||
|
||
CString TDbHvacDimension::GetText() const
|
||
{
|
||
assertReadEnabled();
|
||
CString csText;
|
||
m_XDataMap.GetAt(HDIM_DimString, csText);
|
||
return csText;
|
||
}
|
||
|
||
CString TDbHvacDimension::GetFormatStr() const
|
||
{
|
||
assertReadEnabled();
|
||
CString csText;
|
||
m_XDataMap.GetAt(HDIM_DimFormat, csText);
|
||
return csText;
|
||
}
|
||
|
||
AcDbObjectId TDbHvacDimension::GetTextStyle() const
|
||
{
|
||
assertReadEnabled();
|
||
AcDbObjectId idTextStyle(AcDbObjectId::kNull);
|
||
m_XDataMap.GetAt(HDIM_DimTextId, idTextStyle);
|
||
return idTextStyle;
|
||
}
|
||
|
||
double TDbHvacDimension::GetTextHeigh() const
|
||
{
|
||
assertReadEnabled();
|
||
double dHeigh(0.0);
|
||
m_XDataMap.GetAt(HDIM_DimTextHeigh, dHeigh);
|
||
return dHeigh;
|
||
}
|
||
|
||
double TDbHvacDimension::GetTextAngle() const
|
||
{
|
||
assertReadEnabled();
|
||
double dAngle(0.0);
|
||
m_XDataMap.GetAt(HDIM_DimTextAngle, dAngle);
|
||
return dAngle;
|
||
}
|
||
|
||
double TDbHvacDimension::GetArrowLen() const
|
||
{
|
||
assertReadEnabled();
|
||
double dLen(0.0);
|
||
m_XDataMap.GetAt(HDIM_DimArrowLen, dLen);
|
||
return dLen;
|
||
}
|
||
|
||
int TDbHvacDimension::GetArrowStyle() const
|
||
{
|
||
assertReadEnabled();
|
||
int nStyle(0);
|
||
m_XDataMap.GetAt(HDIM_DimArrowStyle, nStyle);
|
||
return nStyle;
|
||
}
|
||
|
||
int TDbHvacDimension::GetEleType() const
|
||
{
|
||
assertReadEnabled();
|
||
int nType(0);
|
||
m_XDataMap.GetAt(HDIM_DimEleType, nType);
|
||
return nType;
|
||
}
|
||
|
||
void TDbHvacDimension::SetBasePoint( AcGePoint3d ptBase )
|
||
{
|
||
assertWriteEnabled();
|
||
assertReadEnabled();
|
||
m_XDataMap.SetAt(HDIM_DimBasePos, ptBase);
|
||
}
|
||
|
||
void TDbHvacDimension::SetLeadPoint( AcGePoint3d ptLead )
|
||
{
|
||
assertWriteEnabled();
|
||
m_XDataMap.SetAt(HDIM_DimLeadPos, ptLead);
|
||
}
|
||
|
||
void TDbHvacDimension::SetType( HvacDimType eType )
|
||
{
|
||
assertWriteEnabled();
|
||
m_XDataMap.SetAt(HDIM_DimType, eType);
|
||
}
|
||
|
||
void TDbHvacDimension::SetText( CString csText )
|
||
{
|
||
assertWriteEnabled();
|
||
m_XDataMap.SetAt(HDIM_DimString, csText);
|
||
}
|
||
|
||
void TDbHvacDimension::SetFormatStr( CString csText )
|
||
{
|
||
assertWriteEnabled();
|
||
m_XDataMap.SetAt(HDIM_DimFormat, csText);
|
||
}
|
||
|
||
void TDbHvacDimension::SetTextStyle( AcDbObjectId idText )
|
||
{
|
||
assertWriteEnabled();
|
||
m_XDataMap.SetAt(HDIM_DimTextId, idText, FALSE);
|
||
}
|
||
|
||
void TDbHvacDimension::SetTextHeigh( double dHeigh )
|
||
{
|
||
assertWriteEnabled();
|
||
m_XDataMap.SetAt(HDIM_DimTextHeigh, dHeigh);
|
||
}
|
||
|
||
void TDbHvacDimension::SetTextAngle( double dRotAngle )
|
||
{
|
||
assertWriteEnabled();
|
||
m_XDataMap.SetAt(HDIM_DimTextAngle, dRotAngle);
|
||
}
|
||
|
||
void TDbHvacDimension::SetArrowLen( double dArrowLen )
|
||
{
|
||
assertWriteEnabled();
|
||
m_XDataMap.SetAt(HDIM_DimArrowLen, dArrowLen);
|
||
}
|
||
|
||
void TDbHvacDimension::SetArrowStyle( int nStyle )
|
||
{
|
||
assertWriteEnabled();
|
||
m_XDataMap.SetAt(HDIM_DimArrowStyle, nStyle);
|
||
}
|
||
|
||
void TDbHvacDimension::SetEleType( int nStyle )
|
||
{
|
||
assertWriteEnabled();
|
||
m_XDataMap.SetAt(HDIM_DimEleType, nStyle);
|
||
}
|
||
|
||
void TDbHvacDimension::ResetDimLoct()
|
||
{
|
||
if (NULL == m_pDuctXDataMap)
|
||
return;
|
||
|
||
double dTextHeigh = GetTextHeigh();
|
||
double dScale = GetPScale();
|
||
AcGePoint3d ptStart, ptEnd, ptBase;
|
||
|
||
double dTextToDuct(0.0);
|
||
GetGlobalContext()->GetAt(HVAC_DIMTEXTTODUCT, dTextToDuct);
|
||
// add by dyc 2013/5/21
|
||
BOOL bSingleLine = TRUE;
|
||
m_pDuctXDataMap->GetAt(HVAC_IsSingleLine, bSingleLine);
|
||
|
||
double dGap(dTextToDuct * dScale); // 文字距风管边距离
|
||
|
||
AcGeVector3d vtNormal = AcGeVector3d::kZAxis;
|
||
AcGeVector3d vtX = TAuxTools::GetUcsXvt();
|
||
AcGeVector3d vtY = TAuxTools::GetUcsYvt();
|
||
AcGeVector3d vtDirect, vtDim; // 标注文字方向,标注距风管方向
|
||
|
||
m_pDuctXDataMap->GetAt(HDCT_START, ptStart);
|
||
m_pDuctXDataMap->GetAt(HDCT_END, ptEnd);
|
||
vtDirect = (ptEnd -ptStart);
|
||
|
||
HvacDuctType eDuctType = eStraight;
|
||
m_pDuctXDataMap->GetAt(HDCT_Type, (int&)eDuctType);
|
||
if (eDuctType == eSoft)
|
||
{
|
||
// 先找到弧管中间位置
|
||
AcDbArc arc;
|
||
GetDuctArc(arc);
|
||
double dEndPara(0.0), dStartPara(0.0);
|
||
arc.getStartParam(dStartPara);
|
||
arc.getEndParam(dEndPara);
|
||
arc.getPointAtParam((dEndPara+dStartPara)*0.5, ptBase);
|
||
arc.getFirstDeriv(ptBase, vtDirect);
|
||
}
|
||
else
|
||
{
|
||
AcDbLine lineDuct(ptStart, ptEnd);
|
||
lineDuct.getClosestPointTo(ptBase, ptBase, Adesk::kTrue);
|
||
ptBase = ptStart + (ptEnd - ptStart) * 0.5; // 应需求,自动居中对其
|
||
}
|
||
|
||
//add by myy 2014-9-17
|
||
vtDirect = vtDirect.orthoProject(vtNormal);
|
||
|
||
vtDirect.normalize();
|
||
|
||
if (vtDirect.angleTo(vtX) > PI * 0.5)
|
||
vtDirect *= -1; // 保持文字X正方向
|
||
|
||
if (vtDirect.isCodirectionalTo(-vtY)) // 保持文字Y正方向
|
||
vtDirect = vtY;
|
||
|
||
double dAngle = acutAngle(XPoint(), (XVector3D)vtDirect);
|
||
|
||
HvacDimType eDufaultType = eDimInnerPipe;
|
||
HvacDimType eType = GetType();
|
||
|
||
if (eType != eDimInnerPipe && eType != eDimAbovePipe && eType != eDimBelowPipe)
|
||
{
|
||
eType = eDufaultType;
|
||
SetType(eDufaultType);
|
||
}
|
||
|
||
if (eType == eDimInnerPipe) // 把标注点放在中心线上
|
||
{
|
||
}
|
||
else if (eType == eDimAbovePipe) // 把标注点放到管壁左上
|
||
{
|
||
vtDim = vtDirect;
|
||
vtDim = vtDim.rotateBy(PI * 0.5, vtNormal);
|
||
// add by dyc 2013/5/21
|
||
if (bSingleLine)
|
||
{
|
||
ptBase += (0 * 0.5 + dTextHeigh * dScale * 0.5 + dGap) * vtDim;
|
||
}
|
||
else
|
||
ptBase += (GetDuctWidth() * 0.5 + dTextHeigh * dScale * 0.5 + dGap) * vtDim;
|
||
}
|
||
else if (eType == eDimBelowPipe) // 把标注点放到管壁右下
|
||
{
|
||
vtDim = vtDirect;
|
||
vtDim = vtDim.rotateBy(PI * 0.5, vtNormal);
|
||
// add by dyc 2013/5/21
|
||
if (bSingleLine)
|
||
{
|
||
ptBase -= (0 * 0.5 + dTextHeigh * dScale * 0.5 + dGap) * vtDim;
|
||
}
|
||
else
|
||
ptBase -= (GetDuctWidth() * 0.5 + dTextHeigh * dScale * 0.5 + dGap) * vtDim;
|
||
}
|
||
|
||
SetBasePoint(ptBase);
|
||
SetTextAngle(dAngle);
|
||
}
|
||
|
||
// 返回弧管上距点取点的最近点
|
||
BOOL TDbHvacDimension::GetArcDuctClosePt( const AcGePoint3d& ptGive, AcGePoint3d &ptGet )
|
||
{
|
||
AcDbArc arc;
|
||
GetDuctArc(arc);
|
||
|
||
if (arc.getClosestPointTo(ptGive, ptGet) == Acad::eOk)
|
||
return TRUE;
|
||
|
||
return FALSE;
|
||
}
|
||
|
||
// 得到风管对应弧
|
||
void TDbHvacDimension::GetDuctArc(AcDbArc &arc)
|
||
{
|
||
if (NULL == m_pDuctXDataMap)
|
||
return;
|
||
|
||
AcGePoint3d ptStart, ptEnd;
|
||
AcGePoint3d ptCenter = GetArcDuctCenter();
|
||
m_pDuctXDataMap->GetAt(HDCT_START, ptStart);
|
||
m_pDuctXDataMap->GetAt(HDCT_END, ptEnd);
|
||
double dRadius = ptCenter.distanceTo(ptStart);
|
||
|
||
AcGeVector3d vtNormal;
|
||
m_pDuctXDataMap->GetAt(HVAC_Normal, vtNormal);
|
||
AcGeVector3d vtUcsX(TAuxTools::GetUcsXvt()), vtUcsZ(TAuxTools::GetUcsZvt());
|
||
ads_point vtAdsOcsAngle, vtAdsOcsX;
|
||
acdbWcs2Ecs(asDblArray(vtUcsX), vtAdsOcsX, asDblArray(vtNormal), true);
|
||
|
||
AcGeVector3d vtTX = asVec3d(vtAdsOcsX);
|
||
AcGeVector3d vtAngle = ptStart - ptCenter;
|
||
acdbWcs2Ecs(asDblArray(vtAngle), vtAdsOcsAngle, asDblArray(vtNormal), true);
|
||
double dStaAngle = vtTX.angleTo(vtAngle, vtNormal);
|
||
|
||
vtAngle = ptEnd - ptCenter;
|
||
acdbWcs2Ecs(asDblArray(vtAngle), vtAdsOcsAngle, asDblArray(vtNormal), true);
|
||
double dEndAngle = vtTX.angleTo(vtAngle, vtNormal);
|
||
|
||
// 负曲率时,转换起始终止角
|
||
double dBulge(0);
|
||
m_pDuctXDataMap->GetAt(HDCT_Bulge, dBulge);
|
||
if (dBulge < 0)
|
||
{
|
||
double dTemp = dStaAngle;
|
||
dStaAngle = dEndAngle;
|
||
dEndAngle = dTemp;
|
||
}
|
||
|
||
arc.setCenter(ptCenter);
|
||
arc.setNormal(vtNormal);
|
||
arc.setRadius(dRadius);
|
||
arc.setStartAngle(dStaAngle);
|
||
arc.setEndAngle(dEndAngle);
|
||
}
|
||
|
||
// 得到弧风管中心点
|
||
AcGePoint3d TDbHvacDimension::GetArcDuctCenter() const
|
||
{
|
||
if (NULL == m_pDuctXDataMap)
|
||
return AcGePoint3d::kOrigin;
|
||
|
||
AcGePoint3d ptS, ptE;
|
||
m_pDuctXDataMap->GetAt(HDCT_START, ptS);
|
||
m_pDuctXDataMap->GetAt(HDCT_END, ptE);
|
||
AcGeVector3d vtDirect = ptE - ptS;
|
||
vtDirect.normalize();
|
||
|
||
AcGeVector3d vtNormal;
|
||
m_pDuctXDataMap->GetAt(HVAC_Normal, vtNormal);
|
||
|
||
double dBulge(0), dPosiBulge(0);
|
||
m_pDuctXDataMap->GetAt(HDCT_Bulge, dBulge);
|
||
dPosiBulge = fabs(dBulge);
|
||
|
||
double dAngle = atan(dPosiBulge) * 4;
|
||
|
||
AcGeVector3d vtLevel = ptE - ptS;
|
||
vtLevel.rotateBy(-PI * 0.5, vtNormal);
|
||
vtLevel.normalize();
|
||
vtLevel *= ptS.distanceTo(ptE) * 0.5 * dBulge;
|
||
AcGePoint3d ptArcMid = ptS + ptS.distanceTo(ptE) * 0.5 * vtDirect;
|
||
ptArcMid += vtLevel;
|
||
|
||
dAngle /= 4;
|
||
double dDist = ptArcMid.distanceTo(ptE) * 0.5;
|
||
double dRadius = dDist / sin(dAngle);
|
||
vtLevel.normalize();
|
||
|
||
AcGePoint3d ptCenter = ptArcMid - dRadius * vtLevel;
|
||
return ptCenter;
|
||
}
|
||
|
||
|
||
AcGePoint3d TDbHvacDimension::GetDirectPoint() const
|
||
{
|
||
|
||
double dTextLen(100.0);
|
||
double dAngle(GetTextAngle());
|
||
AcGeVector3d vt(cos(dAngle), sin(dAngle), 0);
|
||
vt.normalize();
|
||
AcGePoint3d ptDirect = GetLeadPoint() + dTextLen * vt;
|
||
|
||
return ptDirect;
|
||
}
|
||
|
||
double TDbHvacDimension::GetTextLen( TDbText* pText ) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (NULL == pText)
|
||
return 0.0;
|
||
|
||
double dOrigAngle = pText->GetRotation();
|
||
pText->SetRotation(0.0); // 临时设角度, 便于求长度
|
||
AcDbExtents exTent;
|
||
pText->getGeomExtents(exTent);
|
||
AcGeVector3d vtPerl = AcGeVector3d::kYAxis;
|
||
AcGeVector3d vtLen = exTent.maxPoint() - exTent.minPoint();
|
||
vtLen = vtLen.orthoProject(vtPerl);
|
||
pText->SetRotation(dOrigAngle);
|
||
|
||
return vtLen.length();
|
||
}
|
||
|
||
// 转换各部分字符串 arrText数组0-4对应头文件中标注示意图中的4个lable
|
||
// SetText()传递的字符应符合 A|B|C|D 规则, abcd是四部分
|
||
BOOL TDbHvacDimension::TransTextToResult()
|
||
{
|
||
assertReadEnabled();
|
||
|
||
if (NULL == m_pDuctXDataMap)
|
||
return FALSE;
|
||
|
||
CStringArray arrResult;
|
||
if (!GetEachStr(GetFormatStr(), arrResult) || arrResult.GetSize() != 4)
|
||
return FALSE;
|
||
|
||
if (!arrResult[0].IsEmpty())
|
||
TranslateDimText(arrResult[0]);
|
||
|
||
if (!arrResult[1].IsEmpty())
|
||
TranslateDimText(arrResult[1]);
|
||
|
||
if (!arrResult[2].IsEmpty())
|
||
TranslateDimText(arrResult[2]);
|
||
|
||
if (!arrResult[3].IsEmpty())
|
||
TranslateDimText(arrResult[3]);
|
||
|
||
m_XDataMap.SetAt(HDIM_DimString, arrResult[0] + _T("|") + arrResult[1] + _T("|")
|
||
+ arrResult[2] + _T("|") + arrResult[3]);
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
BOOL TDbHvacDimension::GetEachStr( const CString &csText, CStringArray &arrText ) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
int nIndex1 = csText.Find(_T('|'), 0);
|
||
if (nIndex1 < 0)
|
||
return FALSE;
|
||
|
||
int nIndex2 = csText.Find(_T('|'), nIndex1 + 1);
|
||
if (nIndex2 < 0)
|
||
return FALSE;
|
||
|
||
int nIndex3 = csText.Find(_T('|'), nIndex2 + 1);
|
||
if (nIndex3 < 0)
|
||
return FALSE;
|
||
|
||
CString csStr1 = csText.Mid(0, nIndex1);
|
||
CString csStr2 = csText.Mid(nIndex1 + 1, nIndex2 - nIndex1 - 1);
|
||
CString csStr3 = csText.Mid(nIndex2 + 1, nIndex3 - nIndex2 - 1);
|
||
CString csStr4 = csText.Mid(nIndex3 + 1, csText.GetLength() - nIndex3 - 1);
|
||
|
||
arrText.RemoveAll();
|
||
arrText.Add(csStr1);
|
||
arrText.Add(csStr2);
|
||
arrText.Add(csStr3);
|
||
arrText.Add(csStr4);
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
// 转换格式字符为实际标注内容,按头文件“标注字符格式化字符说明”把实际变量值替换原宏标识
|
||
void TDbHvacDimension::TranslateDimText(CString &csText) const
|
||
{
|
||
HvacSectType eSect = eRectangular;
|
||
if (NULL != m_pDuctXDataMap)
|
||
m_pDuctXDataMap->GetAt(HVAC_SectType, (int&)eSect);
|
||
if (eSect == eCircular)
|
||
{
|
||
CString csStr;
|
||
int nWidth = csText.Find(DV_WIDTH, 0);
|
||
int nHeigh = csText.Find(DV_HEIGH, 0);
|
||
if (nWidth > -1 && nHeigh > -1)
|
||
{
|
||
csStr = csText.Mid(nWidth, nHeigh - nWidth + (int)_tcslen(DV_HEIGH));
|
||
int nFind = csText.Find(csStr, 0);
|
||
if (nFind > -1)
|
||
{
|
||
// change by hh 2011-10-11 圆形风管增加标注样式
|
||
// csText.Insert(nFind, _T("%%C"));
|
||
// ChangeTextIdByValue(csText, csStr);
|
||
int nStyleIdx = csText.Find(DV_THICK);
|
||
if(-1 == nStyleIdx)
|
||
{
|
||
csText.Insert(nFind, _T("%%C"));
|
||
ChangeTextIdByValue(csText, csStr);
|
||
}
|
||
else
|
||
{
|
||
// 圆形标志格式字符串类似于
|
||
|
||
int nLen = (int)_tcslen(DV_THICK);
|
||
// 取得圆风管标注样式
|
||
CString sStyle = csText.Mid(nStyleIdx + nLen, 1);
|
||
int nStyle = _ttoi(sStyle);
|
||
// 从格式化字符串中删除标注样式位
|
||
csText.Delete(nStyleIdx + nLen, 1);
|
||
|
||
//if(0 == nStyle || 2 == nStyle)
|
||
//{
|
||
csText.Delete(nStyleIdx - 1, nLen + 2); // 不标注厚度时 删除厚度格式串
|
||
if(0 == nStyle)
|
||
csText.Insert(nFind, _T("%%C"));
|
||
else
|
||
csText.Insert(nFind, _T("D"));
|
||
ChangeTextIdByValue(csText, csStr);
|
||
/*}
|
||
else 暂不标注壁厚参数
|
||
{
|
||
if(1 == nStyle)
|
||
csText.Insert(nFind, _T("%%C"));
|
||
else
|
||
csText.Insert(nFind, _T("D"));
|
||
ChangeTextIdByValue(csText, csStr);
|
||
ChangeTextIdByValue(csText, DV_THICK); // 风管壁厚
|
||
}*/
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
// add by hh 2011-10-11 移除圆形标注样式格式串
|
||
int nStyleIdx = csText.Find(DV_THICK);
|
||
if(-1 != nStyleIdx)
|
||
csText.Delete(nStyleIdx - 1, (int)_tcslen(DV_THICK) + 3);
|
||
|
||
if (csText.Find(DV_WIDTH, 0) > -1)
|
||
ChangeTextIdByValue(csText, DV_WIDTH);
|
||
if (csText.Find(DV_HEIGH, 0) > -1)
|
||
ChangeTextIdByValue(csText, DV_HEIGH);
|
||
}
|
||
|
||
if (csText.Find(DV_LENGTH, 0) > -1)
|
||
ChangeTextIdByValue(csText, DV_LENGTH);
|
||
if (csText.Find(DV_DIAMETER, 0) > -1)
|
||
ChangeTextIdByValue(csText, DV_DIAMETER);
|
||
if (csText.Find(DV_ELEVATION, 0) > -1)
|
||
ChangeTextIdByValue(csText, DV_ELEVATION);
|
||
if (csText.Find(DV_AIRVOL, 0) > -1)
|
||
ChangeTextIdByValue(csText, DV_AIRVOL);
|
||
if (csText.Find(DV_WAYRESIS, 0) > -1)
|
||
ChangeTextIdByValue(csText, DV_WAYRESIS);
|
||
if (csText.Find(DV_VELOCITY, 0) > -1)
|
||
ChangeTextIdByValue(csText, DV_VELOCITY);
|
||
if (csText.Find(DV_MATERIAL, 0) > -1)
|
||
ChangeTextIdByValue(csText, DV_MATERIAL);
|
||
}
|
||
|
||
// 根据变量名具体替换每个相应变量宏字符
|
||
void TDbHvacDimension::ChangeTextIdByValue( CString &csText, const CString &csTextid ) const
|
||
{
|
||
double dValue(0.0); // 变量实际值
|
||
CString csValue;
|
||
|
||
if (csTextid == DV_MATERIAL)
|
||
csValue = GetDuctMaterial();
|
||
else
|
||
{
|
||
if (csTextid == DV_LENGTH)
|
||
dValue = GetDuctLength();
|
||
else if (csTextid == DV_WIDTH || csTextid == DV_DIAMETER)
|
||
dValue = GetDuctWidth();
|
||
else if (csTextid == DV_HEIGH)
|
||
dValue = GetDuctHeigh();
|
||
else if (csTextid == DV_ELEVATION)
|
||
dValue = GetDuctEle();
|
||
else if (csTextid == DV_AIRVOL)
|
||
dValue = GetDuctAirVol();
|
||
else if (csTextid == DV_VELOCITY)
|
||
dValue = GetDuctVelocity();
|
||
else if (csTextid == DV_WAYRESIS)
|
||
dValue = GetDuctWayResis();
|
||
// else if (csTextid == DV_THICK) // add by hh 2011-10-11 圆形标注增加风管厚度(暂不使用)
|
||
// dValue = GetDuctWallThick();
|
||
else
|
||
{
|
||
// 圆形
|
||
if (csTextid.Find(DV_WIDTH, 0) > -1 && csTextid.Find(DV_HEIGH, 0) > -1)
|
||
dValue = GetDuctWidth();
|
||
}
|
||
|
||
int nIndex(-1); // 变量索引
|
||
CString csDeciNum(_T("0")); // 小数位数
|
||
int nDeciIndex(-1); // 小数位数位置索引
|
||
|
||
nIndex = csText.Find(csTextid, 0);
|
||
nDeciIndex = nIndex + (int)_tcslen(csTextid);
|
||
csDeciNum = csText.GetAt(nDeciIndex);
|
||
|
||
csValue.Format(_T("%.") + csDeciNum + _T("f"), dValue);
|
||
csText.Delete(nDeciIndex, 1);
|
||
}
|
||
|
||
csText.Replace(csTextid, csValue);
|
||
}
|
||
|
||
/*
|
||
void TDbHvacDimension::modified( const AcDbObject* dbObj )
|
||
{
|
||
if (NULL == dbObj || !dbObj->isKindOf(TDbHvacDuct::desc()))
|
||
return;
|
||
|
||
// 重新获取风管数据,避免带标注的风管break打断时崩溃
|
||
TDbHvacDuct* pDuct = TDbHvacDuct::cast(dbObj);
|
||
if (pDuct != NULL)
|
||
{
|
||
TDbXDataMap* pMap = pDuct->GetSpecialtyData();
|
||
if (NULL != pMap)
|
||
{
|
||
m_pDuctXDataMap = pMap;
|
||
TransTextToResult();
|
||
}
|
||
}
|
||
|
||
BOOL bWrite = FALSE;
|
||
Acad::ErrorStatus eState = upgradeFromNotify(bWrite);
|
||
if (eState != Acad::eOk)
|
||
return;
|
||
|
||
if (!isWriteEnabled())
|
||
{
|
||
if (upgradeOpen() != Acad::eOk)
|
||
return;
|
||
}
|
||
|
||
assertWriteEnabled();
|
||
downgradeToNotify(bWrite);
|
||
}
|
||
*/
|
||
|
||
double TDbHvacDimension::GetDuctWidth() const
|
||
{
|
||
double dWidth(0.0);
|
||
if (NULL != m_pDuctXDataMap)
|
||
m_pDuctXDataMap->GetAt(HDCT_Width, dWidth);
|
||
|
||
return dWidth;
|
||
}
|
||
|
||
double TDbHvacDimension::GetDuctHeigh() const
|
||
{
|
||
double dHeigh(0.0);
|
||
HvacSectType eSect(eRectangular);
|
||
|
||
if (NULL != m_pDuctXDataMap)
|
||
{
|
||
m_pDuctXDataMap->GetAt(HVAC_SectType, (int&)eSect);
|
||
if (eSect == eRectangular)
|
||
m_pDuctXDataMap->GetAt(HDCT_Thick, dHeigh);
|
||
else if (eSect == eCircular)
|
||
m_pDuctXDataMap->GetAt(HDCT_Diameter, dHeigh);
|
||
}
|
||
|
||
return dHeigh;
|
||
}
|
||
|
||
double TDbHvacDimension::GetDuctLength() const
|
||
{
|
||
if (NULL == m_pDuctXDataMap)
|
||
return 0.0;
|
||
|
||
double dLength(0.0);
|
||
AcGePoint3d ptSta, ptEnd;
|
||
m_pDuctXDataMap->GetAt(HDCT_START, ptSta);
|
||
m_pDuctXDataMap->GetAt(HDCT_END, ptEnd);
|
||
dLength = ptSta.distanceTo(ptEnd) * 1e-3;
|
||
|
||
return dLength;
|
||
}
|
||
|
||
double TDbHvacDimension::GetDuctEle() const
|
||
{
|
||
if (NULL == m_pDuctXDataMap)
|
||
return 0.0;
|
||
|
||
double dEle(0.0);
|
||
AcGePoint3d ptSta, ptEnd;
|
||
double dHeigh(0.0);
|
||
HvacSectType eSectType = eRectangular;
|
||
|
||
m_pDuctXDataMap->GetAt(HDCT_START, ptSta);
|
||
m_pDuctXDataMap->GetAt(HDCT_START, ptEnd);
|
||
|
||
//BEGIN=======================================================
|
||
m_pDuctXDataMap->GetAt(HVAC_SectType, (int &)eSectType);
|
||
if (eRectangular == eSectType) //方管
|
||
{
|
||
m_pDuctXDataMap->GetAt(HDCT_Thick, dHeigh);
|
||
}
|
||
else if (eCircular == eSectType) //圆管
|
||
{
|
||
m_pDuctXDataMap->GetAt(HDCT_Width, dHeigh);
|
||
}
|
||
//修改时间:2010-03-17
|
||
//修改人 :王亚东
|
||
//修改原因:修复风管标高标注异常的BUG(不区分圆管和方管)
|
||
//END=========================================================
|
||
|
||
int nEleType = GetEleType();
|
||
if (nEleType == 0)
|
||
{
|
||
dEle = (ptSta.z + ptEnd.z) * 0.5 * 1e-3;
|
||
dEle += dHeigh * 0.5 * 1e-3;
|
||
}
|
||
else if (nEleType == 1)
|
||
{
|
||
dEle = (ptSta.z + ptEnd.z) * 0.5 * 1e-3;
|
||
}
|
||
else if (nEleType == 2)
|
||
{
|
||
dEle = (ptSta.z + ptEnd.z) * 0.5 * 1e-3;
|
||
//double dHeigh(0.0);
|
||
//m_pDuctXDataMap->GetAt(HDCT_Thick, dHeigh);
|
||
dEle -= dHeigh * 0.5 * 1e-3;
|
||
}
|
||
|
||
return dEle;
|
||
}
|
||
|
||
double TDbHvacDimension::GetDuctWayResis() const
|
||
{
|
||
if (NULL == m_pDuctXDataMap)
|
||
return 0.0;
|
||
|
||
// temp, 以后有些数据比如温度、粗糙度提取全局数据
|
||
double dRough = 0.15;
|
||
double dTemp = 20.0;
|
||
double dWidth(0.0);
|
||
m_pDuctXDataMap->GetAt(HDCT_Width, dWidth);
|
||
int nSect(0);
|
||
m_pDuctXDataMap->GetAt(HVAC_SectType, nSect);
|
||
if (nSect == eRectangular || nSect == eOblate) // 扁圆暂按矩形算
|
||
{
|
||
double dHeigh(0.0);
|
||
m_pDuctXDataMap->GetAt(HDCT_Thick, dHeigh);
|
||
return TAuxTools::CalFricLoss(dTemp, dRough, dWidth, dHeigh, GetDuctLength(), GetDuctVelocity());
|
||
}
|
||
else if (nSect == eCircular)
|
||
{
|
||
return TAuxTools::CalFricLoss(dTemp, dRough, dWidth, GetDuctLength(), GetDuctVelocity());
|
||
}
|
||
|
||
return 0.0;
|
||
}
|
||
|
||
double TDbHvacDimension::GetDuctVelocity() const
|
||
{
|
||
double dVol = GetDuctAirVol();
|
||
double dArea = GetDuctSectArea();
|
||
if (dArea > 1e-6)
|
||
return dVol / dArea / 3600;
|
||
|
||
return 0.0;
|
||
}
|
||
|
||
double TDbHvacDimension::GetDuctAirVol() const
|
||
{
|
||
if (NULL == m_pDuctXDataMap)
|
||
return 0.0;
|
||
|
||
double dAirLoad(0.0);
|
||
m_pDuctXDataMap->GetAt(HVAC_AirLoad, dAirLoad);
|
||
|
||
return dAirLoad;
|
||
}
|
||
|
||
CString TDbHvacDimension::GetDuctMaterial() const
|
||
{
|
||
if (NULL == m_pDuctXDataMap)
|
||
return CString();
|
||
|
||
CString csMat;
|
||
m_pDuctXDataMap->GetAt(HVAC_Material, csMat);
|
||
|
||
return csMat;
|
||
}
|
||
|
||
double TDbHvacDimension::GetDuctSectArea() const
|
||
{
|
||
if (NULL == m_pDuctXDataMap)
|
||
return 0.0;
|
||
|
||
double dArea(0.0);
|
||
HvacSectType etype = eRectangular;
|
||
m_pDuctXDataMap->GetAt(HVAC_SectType, (int&)etype);
|
||
|
||
double dWidth(0.0), dHeigh(0.0);
|
||
m_pDuctXDataMap->GetAt(HDCT_Width, dWidth);
|
||
if (etype == eRectangular)
|
||
{
|
||
double dHeigh(0.0);
|
||
m_pDuctXDataMap->GetAt(HDCT_Thick, dHeigh);
|
||
dArea = dWidth * dHeigh * 1e-6;
|
||
}
|
||
else if (etype == eCircular)
|
||
{
|
||
dArea = dWidth * dWidth * 1e-6 * PI / 4; //修正圆形面积计算,wyd,2010-04-23
|
||
}
|
||
|
||
return dArea;
|
||
}
|
||
|
||
void TDbHvacDimension::UpdateDataMap( TDbXDataMap* pDataMap )
|
||
{
|
||
assertWriteEnabled();
|
||
m_pDuctXDataMap = pDataMap;
|
||
TransTextToResult();
|
||
}
|
||
|
||
void TDbHvacDimension::erased( const AcDbObject* dbObj, Adesk::Boolean pErasing /*= true*/ )
|
||
{
|
||
if (Adesk::kFalse == pErasing)
|
||
return;
|
||
|
||
#if ADS > 20
|
||
bool bWrite = false;
|
||
#else
|
||
BOOL bWrite = FALSE;
|
||
#endif
|
||
if (!isWriteEnabled())
|
||
{
|
||
Acad::ErrorStatus eState = upgradeFromNotify(bWrite);
|
||
if (eState != Acad::eOk)
|
||
return;
|
||
}
|
||
|
||
assertWriteEnabled();
|
||
removePersistentReactor(dbObj->id());
|
||
m_pDuctXDataMap = NULL;
|
||
downgradeToNotify(bWrite);
|
||
}
|
||
|
||
TDbText* TDbHvacDimension::CrteatText( const CString &csText, const AcDbObjectId &idLayer, const AcDbObjectId &idTextStyle, const double &dHeigh, const AcGePoint3d &ptBase, const double &dAngle ) const
|
||
{
|
||
if (csText.IsEmpty())
|
||
return NULL;
|
||
|
||
TDbText* pText = new TDbText;
|
||
pText->setPropertiesFrom(this);
|
||
pText->SetText(csText);
|
||
pText->setLayer(idLayer);
|
||
pText->SetStyleId(idTextStyle);
|
||
pText->SetHeight(dHeigh);
|
||
pText->SetLocation(ptBase);
|
||
pText->SetRotation(dAngle);
|
||
pText->SetAlignment(XExplodeDraw::kMiddleCenter);
|
||
|
||
return pText;
|
||
}
|
||
|
||
AecObjectEditMethod TDbHvacDimension::GetEditMethod() const
|
||
{
|
||
return TDbEntity::GetEditMethod();
|
||
}
|
||
|
||
// 初始化标注风管的XData数据
|
||
BOOL TDbHvacDimension::InitDuctXData()
|
||
{
|
||
BOOL bOK(FALSE);
|
||
m_pDuctXDataMap = NULL;
|
||
|
||
const AcDbVoidPtrArray* pArrVoidPt = reactors(); // 反应器数组
|
||
if (NULL == pArrVoidPt || pArrVoidPt->length() < 1)
|
||
return FALSE;
|
||
|
||
void* pReactSome = NULL; // 反应器指针
|
||
AcDbObjectId objId(AcDbObjectId::kNull); // 反应器对应实体id3.
|
||
int i(0);
|
||
for (i = 0; i < pArrVoidPt->length(); i++)
|
||
{
|
||
pReactSome = pArrVoidPt->at(i);
|
||
if (acdbIsPersistentReactor(pReactSome))
|
||
{
|
||
objId = acdbPersistentReactorObjectId(pReactSome);
|
||
OPENOBJ_BEGIN(objId, AcDb::kForRead, TDbHvacDuct, pDuct);
|
||
if (pDuct != NULL)
|
||
{
|
||
m_pDuctXDataMap = pDuct->GetSpecialtyData();
|
||
bOK = TRUE;
|
||
pDuct->close();
|
||
break;
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
}
|
||
|
||
return bOK;
|
||
}
|
||
|
||
int TDbHvacDimension::GetFirstVersion() const
|
||
{
|
||
return 8;
|
||
}
|
||
|
||
// 设置编辑文字
|
||
void TDbHvacDimension::SetSubText( long i, CString sText )
|
||
{
|
||
if (sText.IsEmpty())
|
||
return;
|
||
|
||
CStringArray csArr;
|
||
GetEachStr(GetText(), csArr);
|
||
if (i > csArr.GetSize() - 1)
|
||
return;
|
||
|
||
csArr.SetAt(i, sText);
|
||
CString csResult;
|
||
INT_PTR n(0), nSize = csArr.GetSize();
|
||
for (n = 0; n < nSize; n++)
|
||
{
|
||
csResult += csArr[n];
|
||
if (n < nSize - 1)
|
||
csResult += _T("|");
|
||
}
|
||
SetText(csResult);
|
||
}
|
||
|
||
// 查找文字sSubText,按posStart 中位置查找哪一部分
|
||
TTextPosition TDbHvacDimension::FindSubText( const TCHAR *sSubText, TTextPosition &posStart,
|
||
TTextRange *pRange /*= NULL*/ ) const
|
||
{
|
||
assertReadEnabled();
|
||
TTextPosition pos;
|
||
if (!sSubText || !sSubText[0])
|
||
return pos;
|
||
|
||
TTextPosition posNext = posStart;
|
||
while(1)
|
||
{
|
||
TDbText text;
|
||
if (!GetText(posNext.m_nCookies, text))
|
||
break;
|
||
|
||
TTextPosition posFind = text.FindSubText(sSubText, posNext, pRange);
|
||
if (!posFind)
|
||
{
|
||
posNext.m_nCookies++;
|
||
posNext.m_nTextPos = 0;
|
||
}
|
||
else
|
||
{
|
||
posStart = posNext;
|
||
if (!posStart)
|
||
{
|
||
posStart.m_nCookies++;
|
||
posStart.m_nTextPos = 0;
|
||
}
|
||
posFind.m_nCookies = posNext.m_nCookies;
|
||
pos = posFind;
|
||
break;
|
||
}
|
||
}
|
||
|
||
return pos;
|
||
}
|
||
|
||
// 按posRep索引替指定部分(共4部分)文字后,再按posRep索引,重新设置到标注数组
|
||
TTextPosition TDbHvacDimension::ReplaceSubText( const TTextPosition &posRep, const TCHAR *sRepText,
|
||
TTextRange *pRange /*= NULL*/ )
|
||
{
|
||
assertWriteEnabled();
|
||
TDbText text;
|
||
TTextPosition posNext;
|
||
if (!sRepText || !GetText(posRep.m_nCookies, text))
|
||
return posNext;
|
||
|
||
posNext = text.ReplaceSubText(posRep, sRepText, pRange);
|
||
if (!posNext)
|
||
{
|
||
posNext.m_nCookies = posRep.m_nCookies + 1;
|
||
posNext.m_nTextPos = 0;
|
||
}
|
||
|
||
CStringArray csArr;
|
||
GetEachStr(GetText(), csArr);
|
||
if (posRep.m_nCookies > csArr.GetSize() - 1)
|
||
return posNext;
|
||
|
||
csArr.SetAt(posRep.m_nCookies, text.GetText());
|
||
|
||
CString csResult;
|
||
INT_PTR n(0), nSize = csArr.GetSize();
|
||
for (n = 0; n < nSize; n++)
|
||
{
|
||
csResult += csArr[n];
|
||
if (n < nSize - 1)
|
||
csResult += _T("|");
|
||
}
|
||
SetText(csResult);
|
||
|
||
return posNext;
|
||
}
|
||
|
||
// 按 nIndex 索引获取标注文字
|
||
BOOL TDbHvacDimension::GetText( Adesk::UInt32 nIndex, TDbText &text ) const
|
||
{
|
||
if (nIndex < 0 || nIndex > 3 )
|
||
return FALSE;
|
||
|
||
CStringArray arrText;
|
||
if (!GetEachStr(GetText(), arrText) || nIndex > arrText.GetSize() - 1)
|
||
return FALSE;
|
||
|
||
text.setPropertiesFrom(this);
|
||
text.SetAlignment(XExplodeDraw::kMiddleCenter);
|
||
text.SetStyleId(GetTextStyle());
|
||
text.SetHeight(GetTextHeigh());
|
||
text.SetText(arrText[nIndex]);
|
||
text.SetLocation(GetTextBasePt(nIndex));
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
// 按 nIndex 索引获取标注文字基点
|
||
AcGePoint3d TDbHvacDimension::GetTextBasePt(Adesk::UInt32 nIndex) const
|
||
{
|
||
HvacDimType eType = GetType();
|
||
AcGePoint3d ptBase(GetBasePoint());
|
||
AcDbObjectId idStyle = GetTextStyle();
|
||
double dHeigh = GetTextHeigh();
|
||
double dAngle = GetTextAngle();
|
||
|
||
// 矫正角度
|
||
XVector3D vt(cos(dAngle), sin(dAngle), 0);
|
||
if (TAuxTools::GetUcsXvt().angleTo(vt) > PI * 0.5)
|
||
vt *= -1;
|
||
|
||
AcGeVector3d vtUcsY = TAuxTools::GetUcsYvt();
|
||
if (vtUcsY.isCodirectionalTo(-vt.AsAcGeVector3d()))
|
||
vt = vtUcsY;
|
||
|
||
dAngle = acutAngle(XPoint(), vt);
|
||
|
||
CStringArray arrText;
|
||
if (!GetEachStr(GetText(), arrText) || arrText.GetSize() != 4)
|
||
return ptBase;
|
||
|
||
AcDbObjectId idLayer = layerId();
|
||
if (eType == eDimLeadLine || eType == eDimLeadBound) // 带引线及中间割线/边框
|
||
{
|
||
|
||
TDbText* pText1 = NULL, *pText2 = NULL, *pText3 = NULL, *pText4 = NULL;
|
||
pText1 = CrteatText(arrText[0], idLayer, idStyle, dHeigh, ptBase, dAngle);
|
||
pText2 = CrteatText(arrText[1], idLayer, idStyle, dHeigh, ptBase, dAngle);
|
||
pText3 = CrteatText(arrText[2], idLayer, idStyle, dHeigh, ptBase, dAngle);
|
||
pText4 = CrteatText(arrText[3], idLayer, idStyle, dHeigh, ptBase, dAngle);
|
||
|
||
AcGePoint3dArray ptArr;
|
||
GetKeyPoint(pText1, pText2, pText3, pText4, ptArr);
|
||
if (ptArr.length() == 9)
|
||
{
|
||
if (pText1 != NULL)
|
||
{
|
||
delete pText1;
|
||
if (0 == nIndex)
|
||
ptBase = TAuxTools::Mid(ptArr[0], ptArr[4]);
|
||
}
|
||
|
||
if (pText2 != NULL)
|
||
{
|
||
delete pText2;
|
||
if (1 == nIndex)
|
||
ptBase = TAuxTools::Mid(ptArr[1], ptArr[5]);
|
||
}
|
||
|
||
if (pText3 != NULL)
|
||
{
|
||
delete pText3;
|
||
if (2 == nIndex)
|
||
ptBase = TAuxTools::Mid(ptArr[3], ptArr[7]);
|
||
}
|
||
if (pText4 != NULL)
|
||
{
|
||
delete pText4;
|
||
if (3 == nIndex)
|
||
ptBase = TAuxTools::Mid(ptArr[4], ptArr[8]);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (pText1 != NULL)
|
||
delete pText1;
|
||
if (pText2 != NULL)
|
||
delete pText2;
|
||
if (pText3 != NULL)
|
||
delete pText3;
|
||
if (pText4 != NULL)
|
||
delete pText4;
|
||
}
|
||
}
|
||
|
||
return ptBase;
|
||
}
|
||
|
||
BOOL TDbHvacDimension::AllowMoveGirp()
|
||
{
|
||
if(TDbDuctStretchRactor::m_arrId.length() == 0)
|
||
return TRUE;
|
||
|
||
const AcDbVoidPtrArray* pArrVoidPt = reactors(); // 反应器数组
|
||
if (NULL == pArrVoidPt || pArrVoidPt->length() < 1)
|
||
return TRUE;
|
||
|
||
void* pReactSome = NULL; // 反应器指针
|
||
AcDbObjectId objId(AcDbObjectId::kNull); // 反应器对应实体id3.
|
||
int i(0);
|
||
for (i = 0; i < pArrVoidPt->length(); i++)
|
||
{
|
||
pReactSome = pArrVoidPt->at(i);
|
||
if (acdbIsPersistentReactor(pReactSome))
|
||
{
|
||
objId = acdbPersistentReactorObjectId(pReactSome);
|
||
OPENOBJ_BEGIN(objId, AcDb::kForRead, TDbHvacDuct, pDuct);
|
||
if (pDuct != NULL)
|
||
{
|
||
if(TDbDuctStretchRactor::m_arrId.contains(objId))
|
||
return FALSE;
|
||
break;
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
}
|
||
|
||
return TRUE;
|
||
} |