Files
envi-code/SourceCode/Code2026/Dimension/DbWellDim.cpp
T
2026-09-28 15:28:50 +08:00

1784 lines
46 KiB
C++

#include "stdafx.h"
#include "dbobjptr.h"
#include "PushProperty.h"
#include "AcDbObjectPtr.h"
#include "PushProperty.h"
#include "DbWellDim.h"
#include "aecdbtext.h"
#include "dbpipe.h"
#include "dbwell.h"
#include "DbPool.h"
#include "globalFunc.h"
#include "globalDefine.h"
namespace
{
int GetWellDeepPrecision()
{
return 3;
}
}
const Adesk::UInt8 CDbWellDim::g_nVersion = 1;
ACRX_DXF_DEFINE_MEMBERS(CDbWellDim, AecXDbSymbWithText, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
1, AEC_ZT_WELLDIM, "AEC_WELLDIM图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
CDbWellDim::CDbWellDim()
{
m_nTextHeight = 3.5;
}
BOOL CDbWellDim::IsValid() const
{
//BOOL bRet=AecXDbSymbWithText::IsValid();
//if(!bRet)
// return bRet;
return TRUE;
}
//Acad::ErrorStatus
//CDbWellDim::subGetClassID(CLSID* pClsid) const
//{
// return Acad::eOk;
//}
double CDbWellDim::GetText2BaseRatio() const
{
const EntityFields &fd = GetFields();
//double dDist = DocGetText2Base();
double dDist = g_DimOption::instance().g_nText2BaseRatio;
fd.GFD(_T("TEXT2BASERATIO"), dDist);
return dDist;
}
void CDbWellDim::SetText2BaseRatio(double dVal)
{
assertWriteEnabled();
EntityFields &fd = Fields();
bool bRet = fd.SFD(_T("TEXT2BASERATIO"), dVal);
}
// 提供对格式刷的支持
void CDbWellDim::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
{
assertWriteEnabled();
AecXDbSymbWithText::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
CDbWellDim *pSrc = CDbWellDim::cast(pSrcEntity);
if (pSrc) {
m_nTextBaseLen = pSrc->m_nTextBaseLen; //左右由正负控制
}
}
// 从DWG读入数据:
Acad::ErrorStatus CDbWellDim::dwgInFields(AcDbDwgFiler* pFiler)
{
assertWriteEnabled();
Acad::ErrorStatus es = AecXDbSymbWithText::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_iDrawMode);
pFiler->readItem(&m_nTextBaseLen);
pFiler->readItem((AcGePoint2d *)&m_ptStart);
pFiler->readItem((AcGePoint2d *)&m_ptTurn);
pFiler->readItem(&m_idWell);
return pFiler->filerStatus();
}
Acad::ErrorStatus CDbWellDim::dwgOutFields(AcDbDwgFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = AecXDbSymbWithText::dwgOutFields(pFiler);
if (es != Acad::eOk) return es;
pFiler->writeItem(g_nVersion);
pFiler->writeItem(m_iDrawMode);
pFiler->writeItem(m_nTextBaseLen);
pFiler->writeItem((const AcGePoint2d &)m_ptStart);
pFiler->writeItem((const AcGePoint2d &)m_ptTurn);
pFiler->writeItem(m_idWell);
return pFiler->filerStatus();
}
Acad::ErrorStatus CDbWellDim::dxfInFields(AcDbDxfFiler* pFiler)
{
assertWriteEnabled();
double n = m_nTextHeight;
Acad::ErrorStatus es = AecXDbSymbWithText::dxfInFields(pFiler);
if (es != Acad::eOk)
return pFiler->filerStatus();
if (!pFiler->atSubclassData(_T("CDbWellDim"))) {
return Acad::eBadDxfSequence;
}
int fieldsFlags = 0;
resbuf rb;
XPoint pt1, pt2;
double nBaseLen;
XString sText;
while ((es == Acad::eOk)
&& ((es = pFiler->readResBuf(&rb)) == Acad::eOk))
{
switch (rb.restype) {
case AcDb::kDxfXCoord:
pt1 = rb.resval.rpoint;
break;
case AcDb::kDxfXCoord + 1:
pt2 = rb.resval.rpoint;
break;
case AcDb::kDxfText:
sText = rb.resval.rstring;
free(rb.resval.rstring);
break;
case AcDb::kDxfReal + 1:
nBaseLen = rb.resval.rreal;
break;
default:
// An unrecognized group. Push it back so that
// the subclass can read it again.
pFiler->pushBackItem();
es = Acad::eEndOfFile;
break;
}
}
if (es != Acad::eEndOfFile)
return Acad::eInvalidResBuf;
m_ptStart = pt1;
m_ptTurn = pt2;
if (fabs(m_nTextHeight - n) > 0.01)//如果是修改了字高,还需要调整文字下面的线长
m_nTextBaseLen = GetDefaultTextBaseLen() * 1.5;
else
m_nTextBaseLen = nBaseLen;
return pFiler->filerStatus();
}
Acad::ErrorStatus CDbWellDim::dxfOutFields(AcDbDxfFiler* pFiler) const
{
assertReadEnabled();
Acad::ErrorStatus es = AecXDbSymbWithText::dxfOutFields(pFiler);
assert(es == Acad::eOk);
es = pFiler->writeItem(AcDb::kDxfSubclass, _T("CDbWellDim"));
assert(es == Acad::eOk);
pFiler->writePoint2d(AcDb::kDxfXCoord, m_ptStart.AsAcGePoint2d());
pFiler->writePoint2d(AcDb::kDxfXCoord + 1, m_ptTurn.AsAcGePoint2d());
pFiler->writeDouble(AcDb::kDxfReal + 1, m_nTextBaseLen);
return es;
}
Acad::ErrorStatus
CDbWellDim::subTransformBy(const AcGeMatrix3d& xform)
{
assertWriteEnabled();
AecXDbEntityBaseEx::subTransformBy(xform);
ads_matrix mat;
GlobalFunc::AsAdsMatrix(xform, mat);
m_ptStart.TransformBy(mat);
m_ptTurn.TransformBy(mat);
if (xform.isUniScaledOrtho())
m_nTextBaseLen *= xform(0, 0);
if (GlobalFunc::IsMirrorMatrix(xform)) { //设备镜像 sr add 2005/6/7
XPoint ptOrg, ptX(1000, 0), ptY(0, 1000);
ptOrg.TransformBy(xform);
ptX.TransformBy(xform);
ptY.TransformBy(xform);
double nA1 = CT_std_angle(ads_angle(ptOrg, ptY));
double nA2 = CT_std_angle(ads_angle(ptOrg, ptX));
if (fabs(nA2 - PI) < g_DimOption::instance()._angSnap)//以Y轴镜像需要把标注翻转,而以X轴镜像则不需要
m_nTextBaseLen = m_nTextBaseLen * (-1);
}
return Acad::eOk;
}
// Overriden functions for edit
Acad::ErrorStatus CDbWellDim::subGetGripPoints(AcGePoint3dArray& gripPoints,
AcDbIntArray& osnapModes,
AcDbIntArray& geomIds) const
{
assertReadEnabled();
return subGetStretchPoints(gripPoints);
}
// stretch points is diffrent from grep points, with no midpoint included
Acad::ErrorStatus
CDbWellDim::subGetStretchPoints(AcGePoint3dArray & gripPoints) const
{
assertReadEnabled();
gripPoints.append(m_ptStart);
gripPoints.append(m_ptTurn);
XPoint ptTemp;
ads_polar(m_ptTurn, m_nLayoutRotation, GetTextBaseLen() * GetPScale(), ptTemp);
// zxl 2013.10.22 add
if ((IsOnlyDim() || GetIsNewDim()) && GetBaseLineType() != 1)
{
std::vector<WELLDIMNODE> vecData;
GetPipeEleData(vecData);
WELLDIMNODE node;
GetDimLine(node, vecData);
ptTemp = node.ptEnd;
if (m_nTextBaseLen < 0 && IsOnlyDim() && !GetIsNewDim())
{
AcGeVector3d vt = node.ptTurn - node.ptEnd;
ptTemp += vt * 2;
}
}
gripPoints.append(ptTemp);
return Acad::eOk;
}
// 功能: 夹点操作
Acad::ErrorStatus CDbWellDim::subMoveGripPointsAt(
const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertWriteEnabled();
XPoint vtOffset(offset[0], offset[1]);
AcGeVector3d vtOld = m_ptTurn - m_ptStart;
AcGeVector3d vtX(1.0, 0, 0);
double dAngOld = vtX.angleTo(vtOld);
for (int i = 0; i < indices.length(); i++) {
int idx = indices[i];
if (idx == 0) { // Move vertex
m_ptStart += vtOffset;
}
else if (idx == 1) {
// zxl 2013.10.22 modify
// m_ptTurn += vtOffset;
m_ptTurn += vtOffset;
AcGeVector3d vtNew = m_ptTurn - m_ptStart;
double dAngNew = vtX.angleTo(vtNew);
if (GetIsNewDim() && GetBaseLineType() == 1)
{
SetOnlyDim(true);
}
if ((dAngOld > PI / 2 && dAngOld < PI * 3 / 2 && (dAngNew < PI / 2 || dAngNew > PI * 3 / 2) && IsOnlyDim() && GetBaseLineType() == 1)
|| (dAngNew > PI / 2 && dAngNew < PI * 3 / 2 && (dAngOld < PI / 2 || dAngOld > PI * 3 / 2) && IsOnlyDim() && GetBaseLineType() == 1))
{
SetTextBaseLen(-GetTextBaseLen());
}
}
else if (idx == 2) {
XVector3D vt(1.0, 0.0);
double nVal = GlobalFunc::operator&(vtOffset, vt);
//double nVal = (vtOffset & vt);
// zxl 2013.10.22 modify
// m_nTextBaseLen += nVal/GetPScale();
// if ((dAngOld > PI / 2 && dAngOld < PI * 3 / 2 && GetBaseLineType() != 1 && GetIsNewDim() && m_nTextBaseLen > 0)
// || ((dAngOld < PI / 2 || dAngOld > PI * 3 / 2) && GetBaseLineType() != 1 && GetIsNewDim() && m_nTextBaseLen < 0))
if (GetBaseLineType() != 1 && (GetIsNewDim() || IsOnlyDim()) && (dAngOld > PI / 2 && dAngOld < PI * 3 / 2))
{
m_nTextBaseLen -= nVal / GetPScale();
}
else
{
m_nTextBaseLen += nVal / GetPScale();
}
}
}
return Acad::eOk;
}
// 功能: 夹点操作
Acad::ErrorStatus CDbWellDim::subMoveStretchPointsAt(
const AcDbIntArray& indices,
const AcGeVector3d& offset)
{
assertWriteEnabled();
return subMoveGripPointsAt(indices, offset);
}
// 取得夹点说明
Acad::ErrorStatus CDbWellDim::GetGripText(int idx, CString &cs) const
{
Acad::ErrorStatus es = Acad::eOk;
if (idx == 0)
cs = _T("移动标注点");
else if (idx == 1)
cs = _T("移动转折点");
else
cs = _T("拉伸文字线");
return es;
}
// cet 2011.8.29 add 重新编写绘制管底标注
Acad::ErrorStatus CDbWellDim::DrawPipeEle(AcGiDraw &dc) const
{
// 获取标注信息
std::vector<WELLDIMNODE> vecData;
GetPipeEleData(vecData);
// cet 2012.8.21 add
if (vecData.empty())
{
return Acad::eOk;
}
// 绘制管内底标高
int nPos = 0; // 文字位置 0 上方 1 下方
switch (m_iDrawMode)
{
case 1:
case 7:
{
nPos = 0; // 上方
break;
}
case 5:
case 8:
{
nPos = 1; // 下方
break;
}
}
bool bOnly = IsOnlyDim() && IsSamePipeEle(vecData);
if (bOnly || GetIsNewDim()) // 管内底标高相同,进行单侧标注
{
WELLDIMNODE node;
GetDimLine(node, vecData);
// zxl 2013.06.34 add
if (GetBaseLineType() == 1)
{
XPoint ptE;
ads_polar(node.ptTurn, m_nLayoutRotation, GetTextBaseLen() * GetPScale(), ptE);
node.ptEnd = ptE;
node.dAngle = m_nLayoutRotation;
}
else if (m_nTextBaseLen < 0 && IsOnlyDim() && !GetIsNewDim())
{
AcGeVector3d vt = node.ptTurn - node.ptEnd;
node.ptEnd += vt * 2;
}
//cet 2011.11.11 modify 处理特殊角度标注位置
//DrawDimText(dc, nPos, node);
if (IsInAngleRange(node))
{
DrawDimText2(dc, nPos, node);
}
else
{
DrawDimText(dc, nPos, node);
}
}
else
{
// cet 2012.1.30 add 当单侧标注管底标高并且存在一个输出管和若干输入管时,输入管标高与输出管标高相同的不标注
AcDbObjectId idPipe;
if (IsOnlyDim() && IsExistOnlyEfferent(idPipe)) // 单侧标注并且存在唯一输出管, 删除不需要的标注
{
DeleteUnnecessariesNode(idPipe, vecData);
}
std::vector<WELLDIMNODE>::iterator it;
for (it = vecData.begin(); it != vecData.end(); it++)
{
//cet 2011.11.11 modify 处理特殊角度标注位置
//DrawDimText(dc, nPos, *it);
if (IsInAngleRange(*it))
{
DrawDimText2(dc, nPos, *it);
}
else
{
DrawDimText(dc, nPos, *it);
}
}
}
// 绘制井面标高
switch (m_iDrawMode)
{
case 7:
{
nPos = 1; // 下方
break;
}
case 8:
{
nPos = 0; // 上方
break;
}
default:
{
return Acad::eOk;
}
}
if (bOnly || GetIsNewDim()) // 管内底标高相同,进行单侧标注
{
WELLDIMNODE node;
GetDimLine(node, vecData);
node.sDimText = GetWellEleUp();
// zxl 2013.06.34 add
if (GetBaseLineType() == 1)
{
XPoint ptE;
ads_polar(node.ptTurn, m_nLayoutRotation, GetTextBaseLen() * GetPScale(), ptE);
node.ptEnd = ptE;
node.dAngle = m_nLayoutRotation;
}
else if (m_nTextBaseLen < 0 && IsOnlyDim() && !GetIsNewDim())
{
AcGeVector3d vt = node.ptTurn - node.ptEnd;
node.ptEnd += vt * 2;
}
//cet 2011.11.11 modify 处理特殊角度标注位置
//DrawDimText(dc, nPos, node, false);
if (IsInAngleRange(node))
{
DrawDimText2(dc, nPos, node, false);
}
else
{
DrawDimText(dc, nPos, node, false);
}
}
else
{
WELLDIMNODE node;
GetDimLine(node, vecData, false);
node.sDimText = GetWellEleUp();
//cet 2011.11.11 modify 处理特殊角度标注位置
//DrawDimText(dc, nPos, node, false);
if (IsInAngleRange(node))
{
DrawDimText2(dc, nPos, node, false);
}
else
{
DrawDimText(dc, nPos, node, false);
}
}
return Acad::eOk;
}
Acad::ErrorStatus CDbWellDim::DrawDimText(AcGiDraw &dc, int nDrawPos, const WELLDIMNODE &node, bool bDrawLine) const
{
// 绘制标注线
if (bDrawLine)
{
DrawLine(dc, XLine(node.ptTurn, node.ptEnd));
//dc << XLine(node.ptTurn, node.ptEnd);
}
// 绘制文字
AecXDbText text;
text.setPropertiesFrom(this);
text.SetHeight(m_nTextHeight);
text.SetStyleId(m_idTextStyle);
if (!!m_idTextLayer)
text.setColorIndex(GetTextColor());
double nText2Base = GetText2BaseRatio() * GetPScale();
PushProperty vProp(&text, dc);
// cet 2012.7.6 modify 对齐方式改由变量控制
// XPoint ptLoc;
// Midpoint(node.ptEnd, node.ptTurn, ptLoc);
AcGiDraw::TextAlignment align;
XPoint ptLoc = node.ptEnd;
AcGeVector3d vtDir = ptLoc - node.ptTurn;
double dAng = node.dAngle;
dAng -= m_nLayoutRotation;
GetAlignPoint(align, ptLoc, dAng, nDrawPos, vtDir);
if (nDrawPos == 0) // 文字在上方
{
vtDir.z = 0.0;
AcGeTol tol;
tol.setEqualVector(0.001);
if (AcGeVector3d::kXAxis.isPerpendicularTo(GlobalFunc::Wcs2Ucs(vtDir, TRUE), tol)) // 文字基线与Y轴平行
{
if (AcGeVector3d::kYAxis.isCodirectionalTo(GlobalFunc::Wcs2Ucs(vtDir, TRUE), tol)) // 与Y轴正方向相同
{
ads_polar(XPoint(ptLoc), m_nLayoutRotation + dAng - PI / 2, nText2Base, ptLoc);
dAng += PI;
// 外侧对齐
int nAlignType = 0;
if (GetAlignType(nAlignType) && nAlignType == 1)
{
align = AcGiDraw::kBottomRight;
}
}
else // 与Y轴反方向相同
{
ads_polar(XPoint(ptLoc), m_nLayoutRotation + dAng + PI / 2, nText2Base, ptLoc);
}
}
else
{
ads_polar(XPoint(ptLoc), m_nLayoutRotation + dAng + PI / 2, nText2Base, ptLoc);
}
//cet 2012.7.6 modify
//text.SetAlignment(AcGiDraw::kBottomCenter);
text.SetAlignment(align);
}
else if (nDrawPos == 1) // 文字在下方
{
vtDir.z = 0.0;
AcGeTol tol;
tol.setEqualVector(0.001);
if (AcGeVector3d::kXAxis.isPerpendicularTo(GlobalFunc::Wcs2Ucs(vtDir, TRUE), tol)) // 文字基线与Y轴平行
{
if (AcGeVector3d::kYAxis.isCodirectionalTo(GlobalFunc::Wcs2Ucs(vtDir, TRUE), tol)) // 与Y轴正方向相同
{
ads_polar(XPoint(ptLoc), m_nLayoutRotation + dAng + PI / 2, nText2Base, ptLoc);
dAng += PI;
// 外侧对齐
int nAlignType = 0;
if (GetAlignType(nAlignType) && nAlignType == 1)
{
align = AcGiDraw::kBottomRight;
}
}
else // 与Y轴反方向相同
{
ads_polar(XPoint(ptLoc), m_nLayoutRotation + dAng - PI / 2, nText2Base, ptLoc);
}
}
else
{
ads_polar(XPoint(ptLoc), m_nLayoutRotation + dAng - PI / 2, nText2Base, ptLoc);
}
//cet 2012.7.6 modify
//text.SetAlignment(AcGiDraw::kTopCenter);
text.SetAlignment(align);
text.SetLocation(ptLoc);
text.SetText(node.sDimText);
//因字体改变时可能导致文字基点与文字间距离(dTmp)增大,从而使上下标注距线
//距离不一致(偏移误差)(dTmp),所以用下述方法求出dTmp,移动基点位置使上下标注距线距离一致
XPoint ptMin, ptMax;
text.SetLayoutRotation(0.0); // 获得外包框的时候,一定不要考虑布局转角、文字转角
text.GetExtents2d(ptMin, ptMax);
double dTmp = 0.0; //文字距线的偏移误差
// 防止批量转旧时,无法得到文字外包围框
if (ptMin != XPoint() || ptMax != XPoint())
{
dTmp = ptLoc.y - ptMax.y;
}
ads_polar(XPoint(ptLoc), m_nLayoutRotation + node.dAngle + PI / 2, dTmp, ptLoc);
text.SetLayoutRotation(m_nLayoutRotation);// 恢复文字布局转角zxl 2013.06.25 add
}
text.SetLocation(ptLoc);
text.SetRotation(dAng);
text.SetText(node.sDimText);
//if (dc.IsFullExplode())
// text.ExplodeOrDraw2d(dc);
//else
DrawBaseEx(dc, text);
//dc.DrawEntity(text);
return Acad::eOk;
}
void CDbWellDim::GetDimLine(WELLDIMNODE &node, const std::vector<WELLDIMNODE> &vecData, bool bflow) const
{
// zxl 2013.06.27 modify 距离引线角度最大的基线为标注线
// if (bflow)
// {
// std::vector<WELLDIMNODE>::const_iterator it;
// for (it = vecData.begin(); it != vecData.end(); it++)
// {
// if (it->bFlowOut) // 下游管线
// {
// node.ptEnd = it->ptEnd;
// node.ptTurn = it->ptTurn;
// node.dAngle = it->dAngle;
// node.sDimText = it->sDimText;
// return;
// }
// }
// }
/*// 最左侧为标注线*/
std::vector<WELLDIMNODE>::const_iterator it;
for (it = vecData.begin(); it != vecData.end(); it++)
{
if (it == vecData.begin())
{
node.ptEnd = it->ptEnd;
node.ptTurn = it->ptTurn;
node.dAngle = it->dAngle;
node.sDimText = it->sDimText;
}
else
{
// XPoint pt1 = (*it).ptEnd;
// pt1 = GlobalFunc::Wcs2Ucs(pt1);
// if ((fabs(node.ptEnd.x - pt1.x) < 1e-3 && node.ptEnd.y > pt1.y) || node.ptEnd.x > pt1.x)
// {
AcGeVector3d vt1 = (*it).ptEnd - (*it).ptTurn;
AcGeVector3d vtNode = node.ptEnd - node.ptTurn;
AcGeVector3d vtLine = m_ptStart - node.ptTurn;
double dAng1 = vtLine.angleTo(vt1, AcGeVector3d::kZAxis);
double dAng2 = vtLine.angleTo(vtNode, AcGeVector3d::kZAxis);
if (dAng1 > PI)
{
dAng1 -= 2 * PI;
}
if (dAng2 > PI)
{
dAng2 -= 2 * PI;
}
if (fabs(dAng1) > fabs(dAng2))
{
node.ptEnd = it->ptEnd;
node.ptTurn = it->ptTurn;
node.dAngle = it->dAngle;
node.sDimText = it->sDimText;
}
}
}
}
void CDbWellDim::GetPipeEleData(std::vector<WELLDIMNODE> &vecData) const
{
// cet 2012.10.23 add
if (GetPipeDataFromPool(vecData))
{
return;
}
int iPre = GetWellDeepPrecision(); // 精度
OPENOBJ_BEGIN(m_idWell, AcDb::kForRead, AecXDbWell, pEquip);
if (pEquip != NULL)
{
int num = pEquip->GetInterfaceNum();
for (int i = 0; i < num; i++)
{
CPipeInterface face;
pEquip->GetInterface(i, face);
AcDbObjectId nextPipeId = face.m_idPipe;
// zxl 2013.06.06 add
if (GetIsNewDim() && nextPipeId != GetPipeId())
{
continue;
}
CString csPipeDownEle = pEquip->GetISysLabel(i);
if (csPipeDownEle == _T(""))//对于没有标高的管,不进行标注
continue;
double dDownEle = _tstof(csPipeDownEle);
CString sHead, sFormat;
sHead.Format(_T("%d"), iPre);
sFormat = _T("%.") + sHead + _T("f");
csPipeDownEle.Format(sFormat, dDownEle);
bool bflow = false;
OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, CDbPipe, pPipe);
if (pPipe != NULL)
{
TPipeSys::FlowDirection flow = pPipe->GetFlowDir();
if (flow == TPipeSys::kFromStart)
{
double dDist = pEquip->GetLocation().Distance2d(pPipe->GetStartPoint());
if (dDist < g_Option::instance()._DIST_SNAP)
{
bflow = true;
}
}
else
{
double dDist = pEquip->GetLocation().Distance2d(pPipe->GetEndPoint());
if (dDist < g_Option::instance()._DIST_SNAP)
{
bflow = true;
}
}
}
OPENOBJ_END();
XVector3D vt = pEquip->GetIDirection(i);
vt.Normalize();
double dlen = GetTextBaseLen() * GetPScale();
vt.Scale((GetTextBaseLen() * GetPScale()));
XPoint ptEnd = m_ptTurn;
ptEnd += vt;
double dAng = ads_angle(m_ptTurn, ptEnd);
dAng = GlobalFunc::Wcs2Ucs(dAng);
// if(dAng < (PI/2*3 + 0.001) && dAng > PI/2) cet 2011.11.11 modify [90, 270]
// {
// dAng -= PI;
// }
if (dAng < (PI / 2 * 3 + 0.001) && dAng > PI / 2 - 0.001)
{
dAng -= PI;
}
dAng = GlobalFunc::Ucs2Wcs(dAng);
WELLDIMNODE node;
node.sDimText = csPipeDownEle;
node.ptTurn = m_ptTurn;
node.ptEnd = ptEnd;
node.dAngle = dAng;
node.id = nextPipeId;
node.bFlowOut = bflow;
vecData.push_back(node);
}
}
OPENOBJ_END();
}
bool CDbWellDim::IsSamePipeEle(const std::vector<WELLDIMNODE> &vecData) const
{
bool bRet = true;
CString sEle1, sEle2;
std::vector<WELLDIMNODE>::const_iterator it;
for (it = vecData.begin(); it != vecData.end(); it++)
{
sEle1 = it->sDimText;
++it;
if (it == vecData.end())
{
break;
}
sEle2 = it->sDimText;
--it;
if (fabs(_tstof(sEle1) - _tstof(sEle2)) > 0.0001)
{
bRet = false;
}
}
return bRet;
}
inline CString CDbWellDim::GetWellEleUp() const
{
// cet 2012.10.23 add
int nPre = GetWellDeepPrecision(); // 精度
CString sHead, sFormat;
sHead.Format(_T("%d"), nPre);
sFormat = _T("%.") + sHead + _T("f");
CString sWellEle;
OPENOBJ_BEGIN(m_idWell, AcDb::kForRead, AecXDbWell, pEquip);
if (pEquip != NULL)
{
//cet 2012.10.23 modify
//sWellEle.Format(_T("%.3f"), pEquip->GetWellEleUp());
sWellEle.Format(sFormat, pEquip->GetWellEleUp());
}
OPENOBJ_END();
// 是化粪池时,读取化粪池地面标高
if (sWellEle.IsEmpty())
{
OPENOBJ_BEGIN(m_idWell, AcDb::kForRead, CDbPool, pPool);
if (pPool != NULL)
{
double dEle = pPool->GetGroundEle();
sWellEle.Format(sFormat, dEle);
}
OPENOBJ_END();
}
return sWellEle;
}
Acad::ErrorStatus CDbWellDim::DrawWellEle(AcGiDraw &dc) const
{
int iPre = GetWellDeepPrecision();
XPoint ptTemp;
ads_polar(m_ptTurn, m_nLayoutRotation, GetTextBaseLen() * GetPScale(), ptTemp);
DrawLine(dc, XLine(m_ptTurn, ptTemp));
//dc << XLine(m_ptTurn, ptTemp);
double nEle(0), nEle2(0);
CString csName;
OPENOBJ_BEGIN(m_idWell, AcDb::kForRead, AecXDbWell, pEquip);
if (pEquip) {
csName = pEquip->GetWellName();
nEle = pEquip->GetWellEleUp();
nEle2 = pEquip->GetWellEleDown();
}
OPENOBJ_END();
ads_name entWell;
acdbGetAdsName(entWell, m_idWell);
CString csDeepSand = GlobalFunc::ReadXdata(entWell, _T("TG-WELL-DeepSand"));
if (csDeepSand != _T(""))
{
double dDeepSand = _tstof(csDeepSand);
nEle2 = nEle2 - dDeepSand / 1000;
}
CString csEle, csEle2, sHead, sFormat;
sHead.Format(_T("%d"), iPre);
sFormat = _T("%.") + sHead + _T("f");
if (fabs(nEle) > 0.001)
csEle.Format(sFormat, nEle);
csEle2.Format(sFormat, nEle2);
//cet 2010.1.18 add
if (m_iDrawMode == 3 || m_iDrawMode == 4)
{
csEle = csName; //上标设置为井编号
}
if (m_iDrawMode == 3)
{
csEle2 = _T("");
}
//end
// cet 2010.5.14 add
if (m_iDrawMode == 6)
{
if (fabs(nEle2) <= 1e-3)
{
csEle = _T("");
}
else
{
csEle = csEle2;
}
csEle2 = _T("");
}
AecXDbText text;
text.setPropertiesFrom(this);
text.SetHeight(m_nTextHeight);
text.SetStyleId(m_idTextStyle);
if (!!m_idTextLayer)
text.setColorIndex(GetTextColor());
// text.setLayer(m_idTextLayer);
double nText2Base = GetText2BaseRatio() * GetPScale();
PushProperty vProp(&text, dc);
XPoint ptLoc = ptTemp;
ads_polar(XPoint(ptLoc), m_nLayoutRotation + PI / 2, nText2Base, ptLoc);
/*cet 2012.7.5 modify 根据变量设置对齐方式
//cet 2010.1.26 add
//根据文字对齐方式,将文字向内侧移动nText2Base / 2距离
if (m_nTextBaseLen < 0.0)
{
ads_polar(XPoint(ptLoc), m_nLayoutRotation, nText2Base / 2, ptLoc);
}
else
{
ads_polar(XPoint(ptLoc), m_nLayoutRotation + PI, nText2Base / 2, ptLoc);
}
text.SetAlignment(m_nTextBaseLen<0.0? AcGiDraw::kBottomLeft : AcGiDraw::kBottomRight);
text.SetLocation(ptLoc);
*/
AcGiDraw::TextAlignment align;
GetAlignPoint(align, ptLoc);
text.SetAlignment(align);
text.SetLocation(ptLoc);
text.SetText(csEle);
//if (dc.IsFullExplode())
// text.ExplodeOrDraw2d(dc);
//else
// dc.DrawEntity(text);
DrawBaseEx(dc, text);
//引出标注下端文字 2009/08/10 xz 初次修改,支持文字距线距离,2010.1.26 cet再次修改,支持文字距线端距离
//注意:以下程序重点是计算文字基点位置,此处算法(利用外包框)比较复杂,原因是:
//1: ACAD的windows字体插入基点和shx字体基点不一致, 如果用ptDraw.y - ptLoc.y求文字距线的距离,那么windows字体位置距离基线偏远
//2: 在某种特殊情况下,获取文字外包框失败,因此考虑了2种情况(谢真发现的)
if (fabs(nEle2) > 0.001 && csEle2 != _T(""))
{
//cet 2010.1.29 add 调整文字距线距离和文字距线端距离使上下标注距线距离和距线端距离一致
XPoint ptLoc = ptTemp;
ads_polar(XPoint(ptLoc), m_nLayoutRotation - PI / 2, nText2Base, ptLoc); //文字距线的距离
text.SetText(csEle2);
//cet 2012.7.5 modify 更加用户设置选择对齐方式
//text.SetAlignment(m_nTextBaseLen<0.0? AcGiDraw::kTopLeft : AcGiDraw::kTopRight);
text.SetAlignment(align);
text.SetLocation(ptLoc);
//因字体改变时可能导致文字基点与文字间距离(dTmp)增大,从而使上下标注距线
//距离不一致(偏移误差)(dTmp),所以用下述方法求出dTmp,移动基点位置使上下标注距线距离一致
XPoint ptMin, ptMax;
text.SetLayoutRotation(0.0); // 获得外包框的时候,一定不要考虑布局转角、文字转角
text.GetExtents2d(ptMin, ptMax);
double dTmp = 0.0; //文字距线的偏移误差
// 防止批量转旧时,无法得到文字外包围框
if (ptMin != XPoint() || ptMax != XPoint())
{
dTmp = ptLoc.y - ptMax.y;
}
text.SetLayoutRotation(m_nLayoutRotation);
XPoint ptDraw = ptLoc;
ads_polar(ptLoc, m_nLayoutRotation + PI / 2, dTmp, ptDraw); //调整文字距线的偏移误差
text.SetLocation(ptDraw);
/*cet 2012.7.5 modify
//调整文字距线端距离
if (m_nTextBaseLen < 0.0)
ads_polar(XPoint(ptDraw), m_nLayoutRotation, nText2Base / 2, ptDraw);
else
ads_polar(XPoint(ptDraw), m_nLayoutRotation + PI, nText2Base / 2, ptDraw);
text.SetLocation(ptDraw);
*/
GetAlignPoint(align, ptDraw);
text.SetLocation(ptDraw);
// cet 2010.1.29 del 原因:上下标注距线距离不一致
// XPoint ptMin, ptMax;
// text.SetText(csEle2);
// text.SetAlignment(m_nTextBaseLen<0.0? AcGiDraw::kTopLeft : AcGiDraw::kTopRight);
// text.SetLayoutRotation(0.0); // 获得外包框的时候,一定不要考虑布局转角、文字转角
// text.GetExtents2d(ptMin, ptMax);
//
// if (ptMin.Distance(ptMax) < 1e-3 && ptMax.Distance(XPoint()) < 1E-3)
// {
// //获取外包框GetExtents2d失败(转T3或者文字不在视图内的其他情况)
// XPoint ptLoc=ptTemp;
// ads_polar(XPoint(ptLoc), m_nLayoutRotation-PI/2, nText2Base, ptLoc);
// //cet 2010.1.26 add 根据文字对齐方式,将文字向线端内侧移动nText2Base / 2距离,否则齐线视觉效果不佳
// if (m_nTextBaseLen < 0.0)
// ads_polar(XPoint(ptLoc), m_nLayoutRotation, nText2Base / 2, ptLoc);
// else
// ads_polar(XPoint(ptLoc), m_nLayoutRotation + PI, nText2Base / 2, ptLoc);
// text.SetLocation(ptLoc);
// text.SetAlignment(m_nTextBaseLen<0.0? AcGiDraw::kTopLeft : AcGiDraw::kTopRight);
// }
// else
// {
// //正常获取文字外包框
// XPoint ptDraw = ptTemp;
// double dTmp = ptDraw.y - ptMax.y; //求文字距线的距离
// ads_polar(ptTemp, m_nLayoutRotation+PI/2, dTmp, ptDraw); //cet 2010.1.26 modify 支持UCS 原先:ads_polar(ptTemp, dRotation+PI/2, dTmp, ptDraw); dRotation=0
// //cet 2010.1.26 add 根据文字对齐方式,将文字向线端内侧移动nText2Base / 2距离,否则齐线视觉效果不佳
// if (m_nTextBaseLen < 0.0)
// ads_polar(XPoint(ptDraw), m_nLayoutRotation, nText2Base / 2, ptDraw);
// else
// ads_polar(XPoint(ptDraw), m_nLayoutRotation + PI, nText2Base / 2, ptDraw);
// text.SetLocation(ptDraw);
// text.SetLayoutRotation(m_nLayoutRotation);
// text.SetRotation(0.0);
// }
text.SetText(csEle2);
//if (dc.IsFullExplode())
// text.ExplodeOrDraw2d(dc);
//else
// dc.DrawEntity(text);
DrawBaseEx(dc, text);
}
// cet 2018.6.22 del
// csName.Insert(0,_T("^C"));
// csName.Format(_T("%s^C"), csName);
//圆圈文字
if (m_iDrawMode == 2)
{
text.SetLocation(ptTemp);
text.SetHeight(m_nTextHeight);
text.SetAlignment(m_nTextBaseLen < 0.0 ? AcGiDraw::kMiddleRight : AcGiDraw::kMiddleLeft);
text.SetText(csName);
// cet 2018.6.22 add 圆改为手动绘制(有些字体原方式显示的文字太小)
double dAngle = text.GetRotation();
AcDbExtents ext;
text.SetRotation(0);
if (text.getGeomExtents(ext) == Acad::eOk)
{
XPoint ptMid = ext.minPoint() + (ext.maxPoint() - ext.minPoint()) * 0.5;
double dDiameter = ext.maxPoint().distanceTo(ext.minPoint()) * 1.05;
AcGeVector3d vt = ptMid - ptTemp;
vt.z = 0.0;
vt.normalize();
AcGeMatrix3d mat;
mat.setToTranslation(vt * (dDiameter * 0.5 - fabs(ext.maxPoint().x - ext.minPoint().x) * 0.5));
text.transformBy(mat);
ptMid.TransformBy(mat);
XCircle cir(ptMid, dDiameter * 0.5);
DrawCircle(dc, cir);
//dc << cir;
}
else
{
csName.Insert(0, _T("^C"));
csName.Format(_T("%s^C"), csName);
text.SetText(csName);
}
text.SetRotation(dAngle);
//if (dc.IsFullExplode())
// text.ExplodeOrDraw2d(dc);
//else
// dc.DrawEntity(text);
DrawBaseEx(dc, text);
}
return Acad::eOk;
}
Acad::ErrorStatus
CDbWellDim::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;
}
assertReadEnabled();
if (!IsValid())
return Acad::eInvalidInput;
if (m_iDrawMode > 8 || m_iDrawMode < 0) // cet 2011.6.16 add
{
return Acad::eInvalidInput;
}
XLine line(m_ptStart, m_ptTurn);
DrawLine(dc, line);
//dc << line;
// cet 2010.1.18 del
// if(m_iDrawMode == 0 || m_iDrawMode == 2)
// cet 2010.5.14 del 增加一种新样式6
/*
// cet 2010.1.18 add
// 增加两种井标注样式
if(m_iDrawMode == 0 || m_iDrawMode == 2
|| m_iDrawMode == 3 || m_iDrawMode == 4)
DrawWellEle(dc);
else if(m_iDrawMode == 1 || m_iDrawMode == 5)//标注管底标高
DrawPipeEle(dc);
*/
if (m_iDrawMode == 0 || m_iDrawMode == 2 ||
m_iDrawMode == 3 || m_iDrawMode == 4 ||
m_iDrawMode == 6)
DrawWellEle(dc);
else if (m_iDrawMode == 1 || m_iDrawMode == 5 || m_iDrawMode == 7 || m_iDrawMode == 8)//标注管底标高 cet 2011.6.16 modify 增加样式8
DrawPipeEle(dc);
return Acad::eOk;
}
/* * * * * * * * * * 取 动 态 属 性 显 示 数 据 的 函 数 * * * * * * * * * */
void CDbWellDim::GetTips(DList<ObjInfoUnit> &lstInfo) const
{
lstInfo.Append(new ObjInfoUnit(_T("对象类型"), _T("井标注")));
lstInfo.Append(new ObjInfoUnit(_T("文字高度"), XString(_T("%.1fP"), m_nTextHeight)));
XString sTextStyle = GlobalFunc::GetSymbolName(m_idTextStyle);
lstInfo.Append(new ObjInfoUnit(_T("文字样式"), sTextStyle));
}
double CDbWellDim::GetMinTextBaseLen() const
{
AecXDbText text;
text.setPropertiesFrom(this);
text.SetHeight(m_nTextHeight);
text.SetStyleId(m_idTextStyle);
double nVal = 0.0;
XStringList lstTexts;
GetTexts(lstTexts);
for (int i = 0; i < lstTexts.Length(); i++) {
text.SetText(lstTexts[i]);
XPoint ptExt = text.GetExtents();
nVal = max(nVal, ptExt.x);
}
nVal /= GetPScale();
nVal += GetText2BaseRatio();
if (m_iDrawMode == 1 || m_iDrawMode == 5)
nVal = nVal * 1.2;
return nVal;
}
void CDbWellDim::GetTexts(XStringList &lstTexts) const
{
// cet 2012.10.23 add
if (GetTextsFromPool(lstTexts))
{
return;
}
if (m_iDrawMode == 0 || m_iDrawMode == 2) {
double nEle(0), nEle2(0);
OPENOBJ_BEGIN(m_idWell, AcDb::kForRead, AecXDbWell, pEquip);
if (pEquip) {
nEle = pEquip->GetWellEleUp();
nEle2 = pEquip->GetWellEleDown();
}
OPENOBJ_END();
CString csEle, csEle2;
csEle.Format(_T("%.3f"), nEle);
csEle2.Format(_T("%.3f"), nEle2);
lstTexts.Reset();
lstTexts.Append(tstrnew(csEle));
if (fabs(nEle2) > 0.001)
lstTexts.Append(tstrnew(csEle2));
}
else if (m_iDrawMode == 3) //cet 2010.1.18 add
{
CString strName;
OPENOBJ_BEGIN(m_idWell, AcDb::kForRead, AecXDbWell, pEquip);
if (pEquip != NULL)
{
strName = pEquip->GetWellName();
}
OPENOBJ_END();
lstTexts.Reset();
lstTexts.Append(tstrnew(strName));
}
else if (m_iDrawMode == 4) //cet 2010.1.18 add
{
double nEle2(0);
CString strName;
OPENOBJ_BEGIN(m_idWell, AcDb::kForRead, AecXDbWell, pEquip);
if (pEquip != NULL)
{
nEle2 = pEquip->GetWellEleDown();
strName = pEquip->GetWellName();
}
OPENOBJ_END();
CString csEle2;
csEle2.Format(_T("%.3f"), nEle2);
lstTexts.Reset();
lstTexts.Append(tstrnew(strName));
if (fabs(nEle2) > 0.001)
lstTexts.Append(tstrnew(csEle2));
}
else if (m_iDrawMode == 1 || m_iDrawMode == 5) {
OPENOBJ_BEGIN(m_idWell, AcDb::kForRead, AecXDbWell, pEquip);
if (pEquip) {
int num = pEquip->GetInterfaceNum();
for (int i = 0; i < num; i++) {
CPipeInterface face;
pEquip->GetInterface(i, face);
CString csPipeDownEle = pEquip->GetISysLabel(i);
lstTexts.Append(tstrnew(csPipeDownEle));
}
}
OPENOBJ_END();
}
else if (m_iDrawMode == 6) // cet 2010.5.14 add
{
double dEle2 = 0.0;
OPENOBJ_BEGIN(m_idWell, AcDb::kForRead, AecXDbWell, pEquip);
if (pEquip != NULL)
{
dEle2 = pEquip->GetWellEleDown();
}
OPENOBJ_END();
CString strEle;
strEle.Format(_T("%.3f"), dEle2);
lstTexts.Reset();
lstTexts.Append(tstrnew(strEle));
}
else if (m_iDrawMode == 7 || m_iDrawMode == 8) // cet 2011.3.16 add cet 2011.6.16 modify 增加样式8
{
OPENOBJ_BEGIN(m_idWell, AcDb::kForRead, AecXDbWell, pEquip);
if (pEquip != NULL)
{
int num = pEquip->GetInterfaceNum();
for (int i = 0; i < num; i++)
{
CPipeInterface face;
pEquip->GetInterface(i, face);
CString csPipeDownEle = pEquip->GetISysLabel(i);
lstTexts.Append(tstrnew(csPipeDownEle));
}
CString strEle;
strEle.Format(_T("%.3f"), pEquip->GetWellEleUp());
lstTexts.Append(tstrnew(strEle));
}
OPENOBJ_END();
}
}
double CDbWellDim::GetDefaultTextBaseLen() const
{
double nVal = 6.0;
nVal = max(nVal, GetMinTextBaseLen());
return nVal;
}
bool CDbWellDim::IsOnlyDim() const
{
assertReadEnabled();
const EntityFields &fd = GetFields();
Adesk::Boolean bRet = Adesk::kFalse;
fd.GFD(_T("WELLDIM_ONLY"), bRet);
std::vector<WELLDIMNODE> vecData;
GetPipeEleData(vecData);
bRet &= IsSamePipeEle(vecData);
return bRet == Adesk::kTrue ? true : false;
}
void CDbWellDim::SetOnlyDim(bool bOnly)
{
assertWriteEnabled();
EntityFields &fd = Fields();
fd.SFD(_T("WELLDIM_ONLY"), bOnly ? Adesk::kTrue : Adesk::kFalse);
}
Acad::ErrorStatus CDbWellDim::DrawDimText2(AcGiDraw &dc, int nDrawPos, const WELLDIMNODE &node, bool bDrawLine) const
{
// 绘制标注线
if (bDrawLine)
{
DrawLine(dc, XLine(node.ptTurn, node.ptEnd));
//dc << XLine(node.ptTurn, node.ptEnd);
}
// 绘制文字
AecXDbText text;
text.setPropertiesFrom(this);
text.SetHeight(m_nTextHeight);
text.SetStyleId(m_idTextStyle);
if (!!m_idTextLayer)
text.setColorIndex(GetTextColor());
double nText2Base = GetText2BaseRatio() * GetPScale();
PushProperty vProp(&text, dc);
// cet 2012.7.6 modify 对齐方式由变量控制
// XPoint ptLoc;
// Midpoint(node.ptEnd, node.ptTurn, ptLoc);
XPoint ptLoc = node.ptEnd;
AcGiDraw::TextAlignment align;
AcGeVector3d vtDir = ptLoc - node.ptTurn;
// zxl 2013.06.28 add
double dAng = node.dAngle;
dAng -= m_nLayoutRotation;
GetAlignPoint(align, ptLoc, dAng, nDrawPos, vtDir, true);
if (nDrawPos == 0) // 文字在上方
{
ads_polar(XPoint(ptLoc), m_nLayoutRotation + dAng - PI / 2, nText2Base, ptLoc);
//cet 2012.7.6 modify
//text.SetAlignment(AcGiDraw::kBottomCenter);
text.SetAlignment(align);
}
else if (nDrawPos == 1) // 文字在下方
{
ads_polar(XPoint(ptLoc), m_nLayoutRotation + dAng + PI / 2, nText2Base, ptLoc);
//cet 2012.7.6 modify
//text.SetAlignment(AcGiDraw::kTopCenter);
text.SetAlignment(align);
text.SetLocation(ptLoc);
text.SetText(node.sDimText);
//因字体改变时可能导致文字基点与文字间距离(dTmp)增大,从而使上下标注距线
//距离不一致(偏移误差)(dTmp),所以用下述方法求出dTmp,移动基点位置使上下标注距线距离一致
XPoint ptMin, ptMax;
text.SetLayoutRotation(0.0); // 获得外包框的时候,一定不要考虑布局转角、文字转角
text.GetExtents2d(ptMin, ptMax);
double dTmp = 0.0; //文字距线的偏移误差
// 防止批量转旧时,无法得到文字外包围框
if (ptMin != XPoint() || ptMax != XPoint())
{
dTmp = ptLoc.y - ptMax.y;
}
ads_polar(XPoint(ptLoc), m_nLayoutRotation + dAng - PI / 2, dTmp, ptLoc);
text.SetLayoutRotation(m_nLayoutRotation);
}
text.SetLocation(ptLoc);
text.SetRotation(dAng + PI);
text.SetText(node.sDimText);
//if (dc.IsFullExplode())
// text.ExplodeOrDraw2d(dc);
//else
// dc.DrawEntity(text);
DrawBaseEx(dc, text);
return Acad::eOk;
}
bool CDbWellDim::IsInAngleRange(const WELLDIMNODE &node) const
{
return false; // cet 2016.8.25 add 不再考虑特殊角度, 没有依据来源(有客户不认可)
bool bRet = false;
AcGeVector3d vtDir = node.ptEnd - node.ptTurn;
vtDir.z = 0.0;
vtDir.rotateBy(GlobalFunc::Wcs2Ucs(0.0), AcGeVector3d::kZAxis); // 转成ucs下向量
AcGeVector3d vtX = AcGeVector3d::kXAxis;
double dAngle = vtX.angleTo(vtDir, AcGeVector3d::kZAxis);
if (dAngle > PI / 2 - 0.001 && dAngle < PI * 2 / 3 + 0.001
|| dAngle > PI * 3 / 2 + 0.001 && dAngle < PI * 5 / 3 + 0.001)
{
bRet = true;
}
return bRet;
}
bool CDbWellDim::IsExistOnlyEfferent(AcDbObjectId &idPipe) const
{
idPipe = AcDbObjectId::kNull;
OPENOBJ_BEGIN(m_idWell, AcDb::kForRead, AecXDbWell, pEquip);
if (pEquip != NULL)
{
int num = pEquip->GetInterfaceNum();
for (int i = 0; i < num; i++)
{
CPipeInterface face;
pEquip->GetInterface(i, face);
AcDbObjectId nextPipeId = face.m_idPipe;
OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, CDbPipe, pPipe);
if (pPipe != NULL)
{
TPipeSys::FlowDirection flow = pPipe->GetFlowDir();
if (flow == TPipeSys::kFromStart)
{
double dDist = pEquip->GetLocation().Distance2d(pPipe->GetStartPoint());
if (dDist < g_Option::instance()._DIST_SNAP) // 输出管
{
if (idPipe.isNull())
{
idPipe = nextPipeId;
}
else // 存在多个输出管
{
idPipe = AcDbObjectId::kNull;
return false;
}
}
}
else
{
double dDist = pEquip->GetLocation().Distance2d(pPipe->GetEndPoint());
if (dDist < g_Option::instance()._DIST_SNAP) // 输出管
{
if (idPipe.isNull())
{
idPipe = nextPipeId;
}
else // 存在多个输出管
{
idPipe = AcDbObjectId::kNull;
return false;
}
}
}
}
OPENOBJ_END();
}
}
OPENOBJ_END();
return true;
}
void CDbWellDim::DeleteUnnecessariesNode(const AcDbObjectId &idPipe, std::vector<WELLDIMNODE> &vecData) const
{
// 找到输出管标高
double dEle = 0.0;
std::vector<WELLDIMNODE>::iterator it;
for (it = vecData.begin(); it != vecData.end(); it++)
{
if ((*it).id == idPipe)
{
dEle = _tstof((*it).sDimText);
break;
}
}
if (it == vecData.end())
{
return;
}
// 删除与输出管标高值相同的输入管
WELLDIMNODE node = *it;
vecData.erase(it);
std::vector<WELLDIMNODE> vecTemp(vecData);
vecData.clear();
vecData.push_back(node);
int nPre = GetWellDeepPrecision(); // 精度
double dPre = 1;
for (int i = 0; i < nPre; i++)
{
dPre *= 0.1;
}
if (nPre == 0)
{
dPre = 0.0;
}
for (it = vecTemp.begin(); it != vecTemp.end(); it++)
{
double dTemp = _tstof((*it).sDimText);
if (fabs(dTemp - dEle) < dPre)
{
continue;
}
vecData.push_back(*it);
}
}
bool CDbWellDim::GetAlignType(int &nType) const
{
const EntityFields &fd = GetFields();
Adesk::UInt8 nVal = 0;
if (fd.GFD(_T("ALIGN_TYPE"), nVal))
{
nType = nVal;
return true;
}
return false;
}
void CDbWellDim::SetAlignType(int nType)
{
assertWriteEnabled();
EntityFields &fd = Fields();
Adesk::UInt8 nVal = static_cast<Adesk::UInt8>(nType);
fd.SFD(_T("ALIGN_TYPE"), nVal);
}
void CDbWellDim::GetAlignPoint(AcGiDraw::TextAlignment &align, XPoint &ptLoc) const
{
int nAlignType = 0;
if (GetAlignType(nAlignType))
{
if (nAlignType == 0) // 居中
{
align = AcGiDraw::kBottomCenter;
}
else // 外侧
{
align = m_nTextBaseLen < 0.0 ? AcGiDraw::kBottomLeft : AcGiDraw::kBottomRight;
}
}
else // 老版本未设置对齐方式变量,按原来方式处理
{
align = m_nTextBaseLen < 0.0 ? AcGiDraw::kBottomLeft : AcGiDraw::kBottomRight;
}
if (align == AcGiDraw::kBottomLeft) // 左对齐
{
double nText2Base = GetText2BaseRatio() * GetPScale();
ads_polar(XPoint(ptLoc), m_nLayoutRotation, nText2Base / 2, ptLoc);
}
else if (align == AcGiDraw::kBottomRight) // 右对齐
{
double nText2Base = GetText2BaseRatio() * GetPScale();
ads_polar(XPoint(ptLoc), m_nLayoutRotation + PI, nText2Base / 2, ptLoc);
}
else if (align == AcGiDraw::kBottomCenter) // 居中
{
double dLen = GetTextBaseLen() * GetPScale();
ads_polar(XPoint(ptLoc), m_nLayoutRotation + PI, dLen / 2, ptLoc);
}
}
void CDbWellDim::GetAlignPoint(AcGiDraw::TextAlignment &align, XPoint &ptLoc, double dAngle, int nTextPos, const AcGeVector3d &vtDir, bool bRotateText) const
{
int nAlignType = 0;
// 确定标注文字方向
bool bLeft = false; // 标注文字是否在左侧
AcGeVector3d vt = vtDir;
vt.rotateBy(GlobalFunc::Wcs2Ucs(0.0), AcGeVector3d::kZAxis);
double dDirAngle = (AcGeVector3d::kXAxis).angleTo(vt, AcGeVector3d::kZAxis);
if (dDirAngle > PI * 1.5 + 0.001 && dDirAngle < 2 * PI + 0.001) // (PI*3/2, 2*PI]
{
bLeft = false;
}
else if (dDirAngle + 0.001 > 0.0 && dDirAngle + 0.001 < PI * 0.5) // [0,PI/2)
{
bLeft = false;
}
else if (dDirAngle + 0.001 > PI * 0.5 && dDirAngle < PI * 1.5 + 0.001) // [PI/2,PI*3/2]
{
bLeft = true;
}
// 确定对齐方式
if (GetAlignType(nAlignType))
{
if (nAlignType == 0) // 居中
{
if (nTextPos == 0) // 文字在上方
{
align = AcGiDraw::kBottomCenter;
}
else if (nTextPos == 1) // 文字在下方
{
align = AcGiDraw::kTopCenter;
}
}
else // 外侧
{
if (nTextPos == 0) // 文字在上方
{
align = bLeft ? AcGiDraw::kBottomLeft : AcGiDraw::kBottomRight;
}
else if (nTextPos == 1) // 文字在下方
{
align = bLeft ? AcGiDraw::kTopLeft : AcGiDraw::kTopRight;
}
}
}
else // 老版本未设置对齐方式变量,按原来方式处理
{
if (nTextPos == 0) // 文字在上方
{
align = AcGiDraw::kBottomCenter;
}
else if (nTextPos == 1) // 文字在下方
{
align = AcGiDraw::kTopCenter;
}
}
// 文字进行旋转了,需调整对齐方式
if (bRotateText)
{
if (align == AcGiDraw::kBottomLeft)
{
align = AcGiDraw::kBottomRight;
}
else if (align == AcGiDraw::kBottomRight)
{
align = AcGiDraw::kBottomLeft;
}
else if (align == AcGiDraw::kTopLeft)
{
align = AcGiDraw::kTopRight;
}
else if (align == AcGiDraw::kTopRight)
{
align = AcGiDraw::kTopLeft;
}
}
if (align == AcGiDraw::kBottomCenter || align == AcGiDraw::kTopCenter)
{
double dlen = GetTextBaseLen() * GetPScale();
if (bLeft)
{
ads_polar(XPoint(ptLoc), m_nLayoutRotation + dAngle, fabs(dlen) / 2, ptLoc);
}
else
{
ads_polar(XPoint(ptLoc), m_nLayoutRotation + dAngle + PI, fabs(dlen) / 2, ptLoc);
}
}
else if (align == AcGiDraw::kBottomLeft || align == AcGiDraw::kTopLeft)
{
double nText2Base = GetText2BaseRatio() * GetPScale();
nText2Base = bRotateText ? -1 * nText2Base : nText2Base;
ads_polar(XPoint(ptLoc), m_nLayoutRotation + dAngle, nText2Base / 2, ptLoc);
}
else if (align == AcGiDraw::kBottomRight || align == AcGiDraw::kTopRight)
{
double nText2Base = GetText2BaseRatio() * GetPScale();
nText2Base = bRotateText ? -1 * nText2Base : nText2Base;
ads_polar(XPoint(ptLoc), m_nLayoutRotation + dAngle + PI, nText2Base / 2, ptLoc);
}
}
bool CDbWellDim::GetPipeDataFromPool(std::vector<WELLDIMNODE> &vecData) const
{
bool bRet = false;
int iPre = GetWellDeepPrecision(); // 精度
OPENOBJ_BEGIN(m_idWell, AcDb::kForRead, CDbPool, pEquip);
if (pEquip != NULL)
{
bRet = true;
XPoint ptPipe;
int num = pEquip->GetInterfaceNum();
for (int i = 0; i < num; i++)
{
CPipeInterface face;
pEquip->GetInterface(i, face);
AcDbObjectId nextPipeId = face.m_idPipe;
// zxl 2013.06.06 add
if (GetIsNewDim() && nextPipeId != GetPipeId())
{
continue;
}
if (!nextPipeId.isValid() || nextPipeId.isErased())
{
continue;
}
ptPipe = face.m_ptLocation;
double dPipeDownEle = 0.0;
double dRadius = 0.0; // 内径半径
bool bflow = false;
AcGeVector3d vtPipe;
OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, CDbPipe, pPipe);
if (pPipe != NULL)
{
TPipeSys::FlowDirection flow = pPipe->GetFlowDir();
if (flow == TPipeSys::kFromStart)
{
double dDist = pEquip->GetLocation().Distance2d(pPipe->GetStartPoint());
if (dDist < g_Option::instance()._DIST_SNAP)
{
bflow = true;
}
}
else
{
double dDist = pEquip->GetLocation().Distance2d(pPipe->GetEndPoint());
if (dDist < g_Option::instance()._DIST_SNAP)
{
bflow = true;
}
}
// 与化粪池相连的管线端点
if (ptPipe.Distance2d(pPipe->StartPoint()) < 0.0001)
{
dPipeDownEle = pPipe->StartPoint().z;
vtPipe = pPipe->EndPoint() - pPipe->StartPoint();
}
else
{
dPipeDownEle = pPipe->EndPoint().z;
vtPipe = pPipe->StartPoint() - pPipe->EndPoint();
}
if (!GlobalFunc::DocGetCurMeterUnitDraw())
{
dPipeDownEle *= 0.001;
}
// cet 2018.2.2 modify 通过文件查询内径,对实体绘制效率影响较大
// CString csMat = GetPipeMaterialByIdx(pPipe->GetMaterial());
// dRadius = GetPipeDjByDn(csMat, (int)pPipe->GetDnDiameter()) * 0.5;
dRadius = (pPipe->OuterDn() - pPipe->GetPipeThick() * 2) * 0.5 * 0.001;
}
OPENOBJ_END();
CString sPipeDownEle;
CString sHead, sFormat;
sHead.Format(_T("%d"), iPre);
sFormat = _T("%.") + sHead + _T("f");
sPipeDownEle.Format(sFormat, dPipeDownEle - dRadius);
vtPipe.z = 0.0;
vtPipe.normalize();
double dlen = GetTextBaseLen() * GetPScale();
vtPipe *= ((GetTextBaseLen() * GetPScale()));
XPoint ptEnd = m_ptTurn;
ptEnd += vtPipe;
double dAng = ads_angle(m_ptTurn, ptEnd);
dAng = GlobalFunc::Wcs2Ucs(dAng);
if (dAng < (PI / 2 * 3 + 0.001) && dAng > PI / 2 - 0.001)
{
dAng -= PI;
}
dAng = GlobalFunc::Ucs2Wcs(dAng);
WELLDIMNODE node;
node.sDimText = sPipeDownEle;
node.ptTurn = m_ptTurn;
node.ptEnd = ptEnd;
node.dAngle = dAng;
node.id = nextPipeId;
node.bFlowOut = bflow;
vecData.push_back(node);
}
}
OPENOBJ_END();
return bRet;
}
bool CDbWellDim::GetTextsFromPool(XStringList &lstTexts) const
{
bool bRet = false;
// 非管底标注
if (m_iDrawMode != 1 && m_iDrawMode != 5 && m_iDrawMode != 7 && m_iDrawMode != 8)
{
return bRet;
}
OPENOBJ_BEGIN(m_idWell, AcDb::kForRead, CDbPool, pEquip);
if (pEquip != NULL)
{
bRet = true;
double dMeter = 1.0;
if (!GlobalFunc::DocGetCurMeterUnitDraw())
{
dMeter *= 0.001;
}
int num = pEquip->GetInterfaceNum();
int nPre = GetWellDeepPrecision(); // 精度
CString sHead, sFormat;
sHead.Format(_T("%d"), nPre);
sFormat = _T("%.") + sHead + _T("f");
XPoint ptPipe;
for (int i = 0; i < num; i++)
{
CPipeInterface face;
pEquip->GetInterface(i, face);
if (!face.m_idPipe.isValid() || face.m_idPipe.isErased())
{
continue;
}
ptPipe = face.m_ptLocation;
double dPipeDownEle = 0.0;
double dRadius = 0.0; // 内径半径
bool bflow = false;
AcGeVector3d vtPipe;
OPENOBJ_BEGIN(face.m_idPipe, AcDb::kForRead, CDbPipe, pPipe);
if (pPipe != NULL)
{
// 与化粪池相连的管线端点
if (ptPipe.Distance2d(pPipe->StartPoint()) < 0.0001)
{
dPipeDownEle = pPipe->StartPoint().z;
}
else
{
dPipeDownEle = pPipe->EndPoint().z;
}
// cet 2018.2.2 modify 通过文件查询内径,对实体绘制效率影响较大
// CString csMat = GetPipeMaterialByIdx(pPipe->GetMaterial());
// dRadius = GetPipeDjByDn(csMat, (int)pPipe->GetDnDiameter()) * 0.5;
dRadius = (pPipe->OuterDn() - pPipe->GetPipeThick() * 2) * 0.5 * 0.001;
}
OPENOBJ_END();
CString sPipeDownEle;
sPipeDownEle.Format(sFormat, dPipeDownEle * dMeter - dRadius);
lstTexts.Append(tstrnew(sPipeDownEle));
}
if (m_iDrawMode == 7 || m_iDrawMode == 8)
{
double dEle = pEquip->GetGroundEle();
CString sEle;
sEle.Format(sFormat, dEle);
lstTexts.Append(tstrnew(sEle));
}
}
OPENOBJ_END();
return bRet;
}
//////////////////////////////////////////////////////////////////////////
void InitDbWellDim(BOOL bTrue)
{
if (bTrue) {
CDbWellDim::rxInit();
//CDbWellDim::InitMatchProtocol(TRUE);
}
else {
//CDbWellDim::InitMatchProtocol(FALSE);
deleteAcRxClass(CDbWellDim::desc());
}
}