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

421 lines
13 KiB
C++

#include "stdafx.h"
#include "AcDbObjectPtr.h"
#include "globalFunc.h"
#include "PickEntSet.h"
#include "DbVerticalSection.h"
#include "TVerticalSectionEdJig.h"
#include "layerdef.h"
extern AcDbObjectId InitLayer(const TCHAR *szLayer, BOOL bApplyChange = TRUE);
//***************************************************************************************************
// 一分为二
//***************************************************************************************************
//绘制纵断面图
void DrawVerticalSection(DList<TWellData> &lstWellSys, int iScaleX, int iScaleY, double nGridScale, int iMode, double nDeepStart)
{
InitLayer(_T("0"));
GlobalFunc::PushVarStr clayer(_T("CLAYER"), _T("0"));
XPoint ptIns, ptStart, ptEnd;
xg_getvar(_T("VIEWCTR"), ptIns);
ptIns = GlobalFunc::Ucs2Wcs(ptIns);
PickSet ssDraw(SS_FREE);
ssDraw.IncludeBegin();
CDbVerticalSection *pSect = new CDbVerticalSection;
pSect->SetLayoutRotation(GlobalFunc::Ucs2Wcs(0.0));
pSect->SetInsert(ptIns);
pSect->SetGridScale(nGridScale);
pSect->SetScaleX(iScaleX);
pSect->SetScaleY(iScaleY);
pSect->SetCalcMode(iMode);
pSect->SetTextHeight(g_Option::instance().g_nTwtDimHeight);
pSect->SetTextStyleId(GlobalFunc::InitTwtTextStyle(g_Option::instance().g_csTwtDimStyle));
pSect->SetDoteLayer(InitLayer(LAY_TWT_DOTE));
pSect->SetWellDatas(lstWellSys);
pSect->setColor(AcCmColor()); //随层
pSect->SetStartDeep(nDeepStart);
pSect->SetTextLayer(InitLayer(LAY_TEXT));
pSect->SetGridLayer(GlobalFunc::InitGridLayer(LAY_TWT_GRID));
pSect->SetSectLayer(InitLayer(LAY_TWT_SECTION));
if (iMode == 3)
pSect->SetSheetHead(g_Option::instance().g_csVerticalSectionHeadFeed);
else
pSect->SetSheetHead(g_Option::instance().g_csVerticalSectionHead);
pSect->Calc();
double nHighEle = pSect->GetMaxDeep();
double nLowEle = pSect->GetMinDeep();
AcDbObjectId id = GlobalFunc::AddToCurrentSpace(pSect, Adesk::kTrue);
ssDraw.IncludeEnd();
ssDraw.Redraw(2);
ptIns = GlobalFunc::Wcs2Ucs(ptIns);
actrTransactionManager->flushGraphics(); //acad 刷新
XPoint xp;
if (GlobalFunc::DragMovePickSet(ssDraw, _T("\n请点取纵断面图位置<退出>: "), ptIns, xp) != RTNORM)
ssDraw.Erase();
}
void SplitVerticalSection()
{
Entity ent;
RBList rbMask(RTDXF0, _T("AEC_ZT_VERTICALSECTION"), NULL);
if (GlobalFunc::SelectEntity(_T("\n请选择纵断面图<退出>:"), ent, rbMask) != RTNORM)
return;
XPushVar<int> vOsMode(_T("OSMODE"), 0);
AcDbObjectId id = NULL;
acdbGetObjectId(id, ent);
CVerticalSectionEdJig jig(1);
jig.SetSheetId(id);
int nKeyIndex = 0;
int nCode = jig.DoIt(&nKeyIndex);
if (nCode != RTNORM)
return;
DList<TWellData> lstWellSys, lstWellSys1, lstWellSys2;
XPoint pt = jig.m_ptResult;
OPENOBJ_BEGIN(id, AcDb::kForRead, CDbVerticalSection, pVS)
if (pVS) {
double nWidth(0), nHeight(0);
XPoint ptTopLeft;
int nCol = pVS->HitTestOnVS2(pt, nWidth, nHeight, ptTopLeft);
double nStartDeep(0);
pVS->GetWellDatas(lstWellSys);
int nCount = lstWellSys.Length();
if (nCol < 2 || nCol > nCount - 2)//从前,从后都不可以分割
return;
BOOL bSplitIsWell = lstWellSys[nCol]->m_bIsWell;//从井分割还是从管
if (bSplitIsWell && lstWellSys[nCol]->m_csName == _T("HC"))
{
g_Option::instance().adsout << _T("不支持从化粪池切分!");
return;
}
int iPipeNum(0);
for (int i = 0; i < nCount; i++) {
TWellData *pData = new TWellData;
if (pVS->GetCalcMode() < 100)
*pData = *lstWellSys[i];
else
*pData = *lstWellSys[nCount - 1 - i];
if (i < nCol) {
lstWellSys1.Append(pData);
}
else if (i > nCol) {
lstWellSys2.Append(pData);
}
else if (i == nCol) {
lstWellSys1.Append(pData);
TWellData *pData2 = new TWellData;
if (pVS->GetCalcMode() < 100)
*pData2 = *lstWellSys[i];
else
*pData2 = *lstWellSys[nCount - 1 - i];
lstWellSys2.Append(pData2);
if (bSplitIsWell)
nStartDeep = pData->m_nUpEle - pData->m_nDownEle;
}
else
delete pData;
// 如果从管中分割,就增加1个井,井名称叫:断管
if (i == nCol - 1 && !bSplitIsWell) {
TWellData *pData2 = new TWellData;
if (pVS->GetCalcMode() < 100)
*pData2 = *lstWellSys[i];
else
*pData2 = *lstWellSys[nCount - 1 - i];
pData2->m_csName = _T("断管");
lstWellSys2.Append(pData2);
if (pVS->GetCalcMode() < 100)
nStartDeep = pData2->m_nUpEle - pData2->m_nDownEle;
}
else if (i == nCol + 1 && !bSplitIsWell) {
TWellData *pData2 = new TWellData;
if (pVS->GetCalcMode() < 100)
*pData2 = *lstWellSys[i];
else
*pData2 = *lstWellSys[nCount - 1 - i];
pData2->m_csName = _T("断管");
lstWellSys1.Append(pData2);
if (pVS->GetCalcMode() >= 100)
nStartDeep = pData2->m_nUpEle - pData2->m_nDownEle;
}
}
int nMode = pVS->GetCalcMode();
if (nMode >= 100)//倒的
{
lstWellSys1.Reverse();
lstWellSys2.Reverse();
DrawVerticalSection(lstWellSys1, pVS->GetScaleX(), pVS->GetScaleY(), pVS->GetGridScale(), nMode, nStartDeep);
DrawVerticalSection(lstWellSys2, pVS->GetScaleX(), pVS->GetScaleY(), pVS->GetGridScale(), nMode, pVS->GetStartDeep());
}
else
{
DrawVerticalSection(lstWellSys1, pVS->GetScaleX(), pVS->GetScaleY(), pVS->GetGridScale(), nMode, pVS->GetStartDeep());
DrawVerticalSection(lstWellSys2, pVS->GetScaleX(), pVS->GetScaleY(), pVS->GetGridScale(), nMode, nStartDeep);
}
}
OPENOBJ_END();
}
//***************************************************************************************************
// 修改管井
//***************************************************************************************************
void ModifyVSData()
{
Entity ent;
RBList rbMask(RTDXF0, _T("AEC_ZT_VERTICALSECTION"), NULL);
if (GlobalFunc::SelectEntity(_T("\n请选择纵断面图<退出>:"), ent, rbMask) != RTNORM)
return;
XPushVar<int> vOsMode(_T("OSMODE"), 0);
AcDbObjectId id = NULL;
acdbGetObjectId(id, ent);
CVerticalSectionEdJig jig(1);
jig.SetSheetId(id);
int nKeyIndex = 0;
while (1) {
jig.SetPrompt(_T("\n请点取要编辑的管线或井<退出>:"));
int nCode = jig.DoIt(&nKeyIndex);
if (nCode != RTNORM)
return;
XPoint pt = jig.m_ptResult;
OPENOBJ_BEGIN(id, AcDb::kForWrite, CDbVerticalSection, pVS)
if (pVS) {
double nWidth(0), nHeight(0);
XPoint ptTopLeft;
int nCol = pVS->HitTestOnVS2(pt, nWidth, nHeight, ptTopLeft);
if (nCol < 0)
return;
DList<TWellData> lstWellSys;
pVS->GetWellDatas(lstWellSys);
if (pVS->GetCalcMode() >= 100)
nCol = lstWellSys.Length() - nCol - 1;
if (lstWellSys[0]->m_csName == _T("断管"))
nCol = nCol + 2;
CString csPrompt;
TCHAR szText[32];
if (lstWellSys[nCol]->m_bIsWell) {
CString csNameWell = lstWellSys[nCol]->m_csName;
double nEleUp = lstWellSys[nCol]->m_nUpEle;
double nEleDown = lstWellSys[nCol]->m_nDownEle;
double nEleDownFrond = lstWellSys[nCol]->m_nFrondDownEle;
csPrompt.Format(_T("\n请给出设计地面标高(%.3f)<退出>:"), nEleUp);
if (ads_getreal(csPrompt, &nEleUp) == RTNORM)
lstWellSys[nCol]->m_nUpEle = nEleUp;
if (csNameWell == "HC") {
double dPoolEleDown(0), dPoolEleUp(0);
//OPENOBJ_BEGIN(lstWellSys[nCol]->m_ID, AcDb::kForRead, TDbPump, pEquip);
//if (pEquip) {
// dPoolEleDown = pEquip->GetPumpRaise();
// dPoolEleUp = pEquip->GetPumpQ();
//}
//OPENOBJ_END();
//csPrompt.Format(_T("\n请给出化粪池顶板标高(%.3f)<退出>:"), dPoolEleUp);
//ads_getreal(csPrompt, &dPoolEleUp);
//csPrompt.Format(_T("\n请给出化粪池底板标高(%.3f)<退出>:"), dPoolEleDown);
//ads_getreal(csPrompt, &dPoolEleDown);
//if (fabs(dPoolEleUp) > 0.001 && fabs(dPoolEleDown) > 0.001) {
// OPENOBJ_BEGIN(lstWellSys[nCol]->m_ID, AcDb::kForWrite, TDbPump, pEquip);
// if (pEquip) {
// pEquip->SetPumpRaise(dPoolEleDown);
// pEquip->SetPumpQ(dPoolEleUp);
// }
// OPENOBJ_END();
//}
}
else if (pVS->GetCalcMode() != 3) {
if (ads_getstring(NULL, _T("\n是否定义为跌水井?<N>"), szText) == RTNORM) {
if (_tcsicmp(szText, _T("Y")) == 0) {
csPrompt.Format(_T("\n请给出跌水井井底标高(%.3f)<退出>:"), nEleDown);
if (ads_getreal(csPrompt, &nEleDown) == RTNORM) {
lstWellSys[nCol]->m_nDownEle = nEleDown;
lstWellSys[nCol]->m_bIsDropWell = TRUE;
}
}
else // cet 2013.2.27 add 将井设置为跌水井
{
lstWellSys[nCol]->m_bIsDropWell = FALSE;
}
}
}
}
else {
int iDn = lstWellSys[nCol]->m_iDn;
double nI = lstWellSys[nCol]->m_nI;
csPrompt.Format(_T("\n请给出本段管线管径(%d)<退出>:"), iDn);
if (ads_getint(csPrompt, &iDn) == RTNORM)
lstWellSys[nCol]->m_iDn = iDn;
if (pVS->GetCalcMode() == 3) {//给水系统
double nEle = lstWellSys[nCol - 1]->m_nUpEle;
double nDownEle = lstWellSys[nCol - 1]->m_nDownEle;
double dFeedDeep = nEle - nDownEle - (double)iDn / 2000.0;
csPrompt.Format(_T("\n请给出覆土厚度(%.3f)<退出>:"), dFeedDeep);
if (ads_getreal(csPrompt, &dFeedDeep) == RTNORM) {
nDownEle = nEle - dFeedDeep - (double)iDn / 2000.0;
lstWellSys[nCol - 1]->m_nDownEle = nDownEle;
double nEle2 = lstWellSys[nCol + 1]->m_nUpEle;
nDownEle = nEle2 - dFeedDeep - (double)iDn / 2000.0;
lstWellSys[nCol + 1]->m_nFrondDownEle = nDownEle;
}
}
else {
csPrompt.Format(_T("\n请给出本段管线坡度(%.4f)<退出>:"), nI);
if (ads_getreal(csPrompt, &nI) == RTNORM)
lstWellSys[nCol]->m_nI = nI;
}
}
pVS->SetWellDatas(lstWellSys);
pVS->Calc();
}
OPENOBJ_END();
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
CVerticalSectionEdJig::CVerticalSectionEdJig(int iMode)
{
m_iMode = iMode;
}
CVerticalSectionEdJig::~CVerticalSectionEdJig()
{
}
// 转换成ADS代码
int CVerticalSectionEdJig::GetRetCode(int retCode, int *kwordId) const
{
int ret = retCode;
if (ret == AcEdJig::kCancel)
ret = RTCAN;
else if (ret == AcEdJig::kNull)
ret = RTNONE;
else if (ret <= 0)
ret = RTNORM;
else {
if (kwordId) *kwordId = ret - 1;
ret = RTKWORD;
}
return ret;
}
// 开始执行拖动
int CVerticalSectionEdJig::DoIt(int *keyIndex)
{
int nRetCode = 0;
setDispPrompt(m_sPrompt);
if (!!m_sKeyword && keyIndex) {
INITGET_BEG(-1, m_sKeyword);
try {
nRetCode = drag();
}
catch (...) {
nRetCode = AcEdJig::kCancel;
}
INITGET_END();
}
else {
try {
nRetCode = drag();
}
catch (...) {
nRetCode = AcEdJig::kCancel;
}
}
nRetCode = GetRetCode(nRetCode, keyIndex);
return nRetCode;
}
// 反馈
AcEdJig::DragStatus CVerticalSectionEdJig::sampler()
{
DragStatus stat;
setUserInputControls((UserInputControls)
(AcEdJig::kAccept3dCoordinates | AcEdJig::kNullResponseAccepted));
if (!!m_sKeyword) setKeywordList(m_sKeyword);
else setKeywordList(NULL);
XPoint ptTemp;
stat = acquirePoint(ptTemp);
if (stat == AcEdJig::kNormal) {
if (ptTemp.Distance2d(m_ptResult) > g_DimOption::instance()._distSnap) {
m_ptResult = ptTemp;
}
else
return AcEdJig::kNoChange;
}
return stat;
}
void CVerticalSectionEdJig::UpdateRegion(XPoint ptTopLeft, double nWidth, double nHeight, double nAng)
{
XPoint ptBotLeft, ptBotRight, ptTopRight;
ads_polar(ptTopLeft, nAng + PI / 2, nHeight, ptBotLeft);
ads_polar(ptBotLeft, nAng, nWidth, ptBotRight);
ads_polar(ptTopLeft, nAng, nWidth, ptTopRight);
m_entDraw.setPointAt(0, ptTopLeft);
m_entDraw.setPointAt(1, ptBotLeft);
m_entDraw.setPointAt(3, ptBotRight);
m_entDraw.setPointAt(2, ptTopRight);
}
void CVerticalSectionEdJig::UpdateRegion2(XPoint ptTopLeft, double nWidth, double nHeight, double nAng)
{
XPoint ptBotLeft, ptBotRight, ptTopRight;
ads_polar(ptTopLeft, nAng + PI, nWidth / 4, ptTopLeft);
ads_polar(ptTopLeft, nAng - PI / 2, nHeight, ptBotLeft);
ads_polar(ptBotLeft, nAng, nWidth / 2, ptBotRight);
ads_polar(ptTopLeft, nAng, nWidth / 2, ptTopRight);
m_entDraw.setPointAt(0, ptTopLeft);
m_entDraw.setPointAt(1, ptBotLeft);
m_entDraw.setPointAt(3, ptBotRight);
m_entDraw.setPointAt(2, ptTopRight);
}
// 更新实体数据
Adesk::Boolean CVerticalSectionEdJig::update()
{
Adesk::Boolean bRet = Adesk::kTrue;
ASSERT(!!m_idSheet);
OPENOBJ_BEGIN(m_idSheet, AcDb::kForRead, CDbVerticalSection, pSheet)
ASSERT(pSheet);
double nWidth(0), nHeight(0);
XPoint ptTopLeft;
if (m_iMode == 0) {
int nCol = pSheet->HitTestOnVS(m_ptResult, nWidth, nHeight, ptTopLeft);
double dAng = pSheet->GetLayoutRotation();
if (nCol > -1)
UpdateRegion(ptTopLeft, nWidth, nHeight, dAng);
}
else if (m_iMode == 1) {
int nCol = pSheet->HitTestOnVS2(m_ptResult, nWidth, nHeight, ptTopLeft);
double dAng = pSheet->GetLayoutRotation();
if (nCol > -1)
UpdateRegion2(ptTopLeft, nWidth, nHeight, dAng);
}
OPENOBJ_END();
return bRet;
}
AcDbEntity* CVerticalSectionEdJig::entity() const
{
return (AcDbEntity *)(&m_entDraw);
}