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

436 lines
13 KiB
C++

// TVerticalSectionEdJig.cpp: implementation of the TVerticalSectionEdJig class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <tapi.h>
#include <twtdef.h>
#include <DbVerticalSection.h>
#include <DbPump.h>
#include "TVerticalSectionEdJig.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
//***************************************************************************************************
// 一分为二
//***************************************************************************************************
//绘制纵断面图
void DrawVerticalSection(DList<TWellData> &lstWellSys, int iScaleX, int iScaleY, double nGridScale, int iMode, double nDeepStart)
{
InitLayer(_T("0"));
XPushVarStr clayer(_T("CLAYER"), _T("0"));
XPoint ptIns, ptStart, ptEnd;
xg_getvar(_T("VIEWCTR"), ptIns);
ptIns = Ucs2Wcs(ptIns);
PickSet ssDraw(SS_FREE);
ssDraw.IncludeBegin();
TDbVerticalSection *pSect = new TDbVerticalSection;
pSect->SetLayoutRotation(Ucs2Wcs(0.0));
pSect->SetInsert(ptIns);
pSect->SetGridScale(nGridScale);
pSect->SetScaleX(iScaleX);
pSect->SetScaleY(iScaleY);
pSect->SetCalcMode(iMode);
pSect->SetTextHeight(g_nTwtDimHeight);
pSect->SetTextStyleId(InitTwtTextStyle(g_csTwtDimStyle));
pSect->SetDoteLayer(InitLayer(LAY_TWT_DOTE));
pSect->SetWellDatas(lstWellSys);
pSect->setColor(AcCmColor()); //随层
pSect->SetStartDeep(nDeepStart);
pSect->SetTextLayer(InitLayer(LAY_TEXT));
pSect->SetGridLayer(InitGridLayer(LAY_TWT_GRID));
pSect->SetSectLayer(InitLayer(LAY_TWT_SECTION));
if(iMode == 3)
pSect->SetSheetHead(g_csVerticalSectionHeadFeed);
else
pSect->SetSheetHead(g_csVerticalSectionHead);
pSect->Calc();
double nHighEle = pSect->GetMaxDeep();
double nLowEle = pSect->GetMinDeep();
AcDbObjectId id = AddToCurrentSpace(pSect, Adesk::kTrue);
ssDraw.IncludeEnd();
ssDraw.Redraw(2);
ptIns = Wcs2Ucs(ptIns);
actrTransactionManager->flushGraphics(); //acad 刷新
XPoint xp;
if(DragMovePickSet(ssDraw, _T("\n请点取纵断面图位置<退出>: "), ptIns, xp) != RTNORM)
ssDraw.Erase();
}
void SplitVerticalSection()
{
Entity ent;
RBList rbMask(RTDXF0, _T("ATS_VERTICALSECTION"), NULL);
if(SelectEntity(_T("\n请选择纵断面图<退出>:"), ent, rbMask) != RTNORM)
return;
XPushVar<int> vOsMode(_T("OSMODE"), 0);
AcDbObjectId id = NULL;
acdbGetObjectId(id, ent);
TVerticalSectionEdJig 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, TDbVerticalSection, 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"))
{
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("ATS_VERTICALSECTION"), NULL);
if(SelectEntity(_T("\n请选择纵断面图<退出>:"), ent, rbMask) != RTNORM)
return;
XPushVar<int> vOsMode(_T("OSMODE"), 0);
AcDbObjectId id = NULL;
acdbGetObjectId(id, ent);
TVerticalSectionEdJig 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, TDbVerticalSection, 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();
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
TVerticalSectionEdJig::TVerticalSectionEdJig(int iMode)
{
m_iMode = iMode;
}
TVerticalSectionEdJig::~TVerticalSectionEdJig()
{
}
// 转换成ADS代码
int TVerticalSectionEdJig::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 TVerticalSectionEdJig::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 TVerticalSectionEdJig::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)>_distSnap) {
m_ptResult=ptTemp;
} else
return AcEdJig::kNoChange;
}
return stat;
}
void TVerticalSectionEdJig::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 TVerticalSectionEdJig::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 TVerticalSectionEdJig::update()
{
Adesk::Boolean bRet=Adesk::kTrue;
ASSERT(!!m_idSheet);
OPENOBJ_BEGIN(m_idSheet, AcDb::kForRead, TDbVerticalSection, 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* TVerticalSectionEdJig::entity() const
{
return (AcDbEntity *)(&m_entDraw);
}