Files
envi-code/SourceCode/Code2026/tg_shs/shs_TwtKernal/PipeDoubleDlg.cpp
T
2026-09-28 15:28:50 +08:00

1705 lines
43 KiB
C++

// PipeDoubleDlg.cpp : implementation file
//
#include "stdafx.h"
#include <PipeWireMonitor.h>
#include <dbPipeValve.h>
#include <DbFlangeFitting.h>
//#include <cbclass.h>
#include "PipeDoubleDlg.h"
#include "InsBlockDlg.h"
#include "jig.h"
#include "GlobalFunction.h"
#include "DbDoubleLinePipeReducer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//#ifdef _WIN64
#include"TGAs.h"
//#endif
extern AcDbObjectId Get3dBlockByDesName(const TCHAR* szDesName);
extern CString BuildDoubleLineValve();
//***************************************************************************************************
// 编辑双管节点
//***************************************************************************************************
int EditDoublePipeNode(AcDbObjectId id)
{
if(!id)
return RTERROR;
double nRate(1);
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbFlangeFitting, pNode);
if(!pNode)
return RTERROR;
CString csRate = pNode->GetNumber();
nRate = _tstof(csRate);
if(fabs(nRate) < 0.0001)
nRate = 1;
OPENOBJ_END();
CString csPrompt;
csPrompt.Format(_T("\n请输入自动连接件曲率参数<%.1f>"), nRate);
ads_getreal(csPrompt, &nRate);
csPrompt.Format(_T("%.1f"), nRate);
OPENOBJ_BEGIN(id, AcDb::kForWrite, TDbFlangeFitting, pNode);
if(pNode){
pNode->SetNumber(csPrompt);
}
OPENOBJ_END();
return RTNORM;
}
//***************************************************************************************************
// 编辑双管
//***************************************************************************************************
// cet 2012.11.2 add 检查双线水管是否需要连接变径
void UpdateDbPipeReducing(TDbDoubleLinePipe *pPipe, const AcGeVector3d &vtPipe, double dDn, const AcDbObjectId &idNode, int nSide)
{
TDbFlangeFitting *pFitting = NULL;
acdbOpenObject(pFitting, idNode, AcDb::kForRead);
if (pFitting != NULL)
{
int nNum = pFitting->GetInterfaceNum();
if (nNum > 2)
{
AcGeVector3d vtDir;
AcGeTol tol;
tol.setEqualVector(0.001);
TDbDoubleLinePipe *pPipe2 = NULL;
for (int i = 0; i < nNum; i++)
{
const TPipeInterface &face = pFitting->GetInterface(i);
if (face.m_idPipe == pPipe->objectId())
{
continue;
}
acdbOpenObject(pPipe2, face.m_idPipe, AcDb::kForWrite);
if (pPipe2 != NULL)
{
int nSide2 = 0;
if (face.m_ptLocation.Distance(pPipe2->EndPoint()) < 0.001)
{
nSide2 = 1;
}
vtDir = pPipe2->StartPoint() - pPipe2->EndPoint();
if (vtDir.isParallelTo(vtPipe, tol)) // fitting上与之平行的水管
{
if (fabs(dDn - pPipe2->GetDnDiameter()) > 0.001)
{
if(!pPipe2->IsLinkReducing(nSide2)) // 另一个水管上没有变径时
{
pPipe->SetLinkReducing(nSide, true);
}
}
else
{
if(pPipe2->IsLinkReducing(nSide2)) // 另一个水管上没有变径时
{
pPipe2->SetLinkReducing(nSide2, false);
}
pPipe->SetLinkReducing(nSide, false);
}
pPipe2->close();
break;
}
pPipe2->close();
}
}
}
pFitting->close();
}
}
int EditDoublePipe(AcDbObjectId id)
{
if(!id)
return RTERROR;
CTemporaryResourceOverride vTemp;
CPipeDoubleDlg dlg(1);
ads_name entTmp;
acdbGetAdsName(entTmp, id);
CString csPn = ReadXdata(entTmp, _T("TG-PIPE-FLANGE-PN"));
if(csPn == _T("0.25MPa"))
dlg.m_iPn = 0;
else if(csPn == _T("0.6MPa"))
dlg.m_iPn = 1;
else if(csPn == _T("1.0MPa"))
dlg.m_iPn = 2;
else if(csPn == _T("1.6MPa"))
dlg.m_iPn = 3;
//cet 2012.10.19 add 支持米单位
double dMeter = 1000;
if (DocGetCurMeterUnitDraw())
{
dMeter = 1.0;
}
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
if(!pPipe)
return RTERROR;
dlg.m_bIsVPipe = pPipe->IsVertical();
dlg.m_dRetDn = pPipe->GetDnDiameter();
dlg.m_iMode = pPipe->GetFlange();
// cet 2012.10.19 modify 支持米单位
// dlg.m_nEle = pPipe->StartPoint().z/1000;
// dlg.m_nEle2 = pPipe->EndPoint().z/1000;
dlg.m_nEle = pPipe->StartPoint().z / dMeter;
dlg.m_nEle2 = pPipe->EndPoint().z / dMeter;
dlg.m_nFlangeDn = pPipe->GetFlangeDn();
dlg.m_nFlangeThick = pPipe->GetFlangeThick();
OPENOBJ_END();
if(dlg.DoModal() != IDOK)
return RTNORM;
OPENOBJ_BEGIN(id, AcDb::kForWrite, TDbDoubleLinePipe, pPipe);
if(pPipe){
pPipe->SetWidth(dlg.m_dRetDn);
pPipe->SetDnDiameter(dlg.m_dRetDn);
pPipe->SetFlange(dlg.m_iMode);
XPoint ptStart, ptEnd;
ptStart = pPipe->StartPoint();
ptEnd = pPipe->EndPoint();
// cet 2012.10.19 modify 支持米单位
// ptStart.z = dlg.m_nEle*1000;
// ptEnd.z = dlg.m_nEle*1000;
ptStart.z = dlg.m_nEle * dMeter;
ptEnd.z = dlg.m_nEle * dMeter;
if(dlg.m_bIsVPipe)
{
// cet 2012.10.19 modify
// ptEnd.z = dlg.m_nEle2*1000;
ptEnd.z = dlg.m_nEle2 * dMeter;
}
else{
DList<AcDbObjectId> lstAttachment;
pPipe->GetAttachments(lstAttachment);
int len = lstAttachment.Length();
for(int m=0;m<len;m++){
AcDbObjectId idTmp = *lstAttachment[m];
OPENOBJ_BEGIN(idTmp, AcDb::kForWrite, TDbPipeAttachment, pValve);
if(pValve){
XPoint ptLoc = pValve->GetLocation();
ptLoc.z = ptStart.z;
pValve->SetLocation(ptLoc);
}
OPENOBJ_END();
}
}
pPipe->SetStartPoint(ptStart);
pPipe->SetEndPoint(ptEnd);
pPipe->SetFlangeDn(dlg.m_nFlangeDn);
pPipe->SetFlangeThick(dlg.m_nFlangeThick);
}
OPENOBJ_END();
if(dlg.m_iPn == 0)
csPn = _T("0.25MPa");
else if(dlg.m_iPn == 1)
csPn = _T("0.6MPa");
else if(dlg.m_iPn == 2)
csPn = _T("1.0MPa");
else if(dlg.m_iPn == 3)
csPn = _T("1.6MPa");
WriteXdata(entTmp, _T("TG-PIPE-FLANGE-PN"), csPn);
// cet 2013.4.27 add 更新管线上的标高标注
if (g_bIsElevDimChangeByPipeElev)
{
Entity xx(entTmp);
UpdateElevationDim(xx);
}
// 获得修改当前水管可能导致被合并的管线 cet 2012.11.15 add
std::vector<AcDbObjectId> vecIds;
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
if (pPipe != NULL)
{
AcGeVector3d vtPipe = pPipe->StartPoint() - pPipe->EndPoint();
AcGeTol tol;
tol.setEqualVector(0.001);
AcDbObjectId idNode;
for (int i = 0; i < 2; i++)
{
if (i == 0)
{
idNode = pPipe->GetNode(0);
}
else
{
idNode = pPipe->GetNode(1);
}
OPENOBJ_BEGIN(idNode, AcDb::kForRead, TDbPipeFitting, pFitting);
if (pFitting != NULL)
{
int nNum = pFitting->GetInterfaceNum();
if (nNum == 2)
{
for (int j = 0; j < nNum; j++)
{
const TPipeInterface &face = pFitting->GetInterface(j);
if (face.m_idPipe == id)
{
continue;
}
OPENOBJ_BEGIN(face.m_idPipe, AcDb::kForRead, TDbDoubleLinePipe, pPipe2);
if (pPipe2 != NULL)
{
AcGeVector3d vt = pPipe2->StartPoint() - pPipe2->EndPoint();
if (vtPipe.isParallelTo(vt, tol))
{
vecIds.push_back(face.m_idPipe);
}
}
OPENOBJ_END();
}
}
}
OPENOBJ_END();
}
}
OPENOBJ_END();
// 强制更新,检查是否有管线被合并了
vecIds.push_back(id);
TPipePerDocData *pData = GetCurPipeDocData();
pData->ApplyUpdates();
std::vector<AcDbObjectId> vecIdsTemp;
std::vector<AcDbObjectId>::iterator it;
for (it = vecIds.begin(); it != vecIds.end(); it++)
{
if (!it->isErased())
{
vecIdsTemp.push_back(*it);
}
}
if (vecIdsTemp.size() == vecIds.size()) // 没有管线被合并,只更新当前管线即可
{
vecIds.clear();
vecIds.push_back(id);
}
else // 有管线被合并, 更新剩余的管线
{
vecIds = vecIdsTemp;
}
// cet 2012.11.2 add 双线水管连接的fitting(三通四通)存在与之平行且不等径的
// 双线水管时,需在本水管fitting添加变径
TDbDoubleLinePipe *pPipe = NULL;
for (it = vecIds.begin(); it != vecIds.end(); it++)
{
id = *it;
acdbOpenObject(pPipe, id, AcDb::kForWrite);
if (pPipe != NULL)
{
AcGeVector3d vtPipe = pPipe->StartPoint() - pPipe->EndPoint();
double dDn = pPipe->GetDnDiameter();
AcDbObjectId idNode1 = pPipe->GetNode(0);
UpdateDbPipeReducing(pPipe, vtPipe, dDn, idNode1, 0);
AcDbObjectId idNode2 = pPipe->GetNode(1);
UpdateDbPipeReducing(pPipe, vtPipe, dDn, idNode2, 1);
pPipe->close();
}
}
return RTNORM;
}
//***************************************************************************************************
// 双线阀门
//***************************************************************************************************
double GetValveLength(CString csBlkName, double dDn)
{
double dRet(0);
CodeBase db;
XString fullFile;
if(!FindFile(_T("valve.dbf"), fullFile)) {
AfxMessageBox(_T("对不起,没有发现valve.dbf文件!"));
return dRet;
}
XDbfTable *pTable = db.Open(fullFile);
if(!pTable)
return dRet;
CString csName, csBlkName2;
double dDn2, dLength;
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){
GET_FIELD(pTable, _T("name"), csName);
GET_FIELD(pTable, _T("blkname"), csBlkName2);
GET_FIELD(pTable, _T("dn"), dDn2);
GET_FIELD(pTable, _T("length"), dLength);
if(_tcsicmp(csBlkName, csBlkName2) == 0 && fabs(dDn - dDn2) < 0.001){
return dLength;
}
}
return dRet;
}
void DoubleLineValave()
{
int nOsMode=0;
xg_getvar(_T("OSMODE"), &nOsMode);
nOsMode &= ~0x4000;
nOsMode |= OS_INT|OS_NEA;
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
CInsBlockDlg dlg(_T("VALVE"), 6, acedGetAcadFrame());
{
CTemporaryResourceOverride vTemp;
dlg.Create(IDD_INS_TWT_BLK, acedGetAcadFrame());
dlg.ShowWindow(SW_SHOW);
acedGetAcadDwgView()->SetFocus();
}
g_nInsBlkRotate = 0;
XPoint ptIns, ptOld;
xg_getvar(_T("VIEWCTR"), ptIns);
ptIns = Ucs2Wcs(ptIns);
InitLayer(LAY_EQUIP_VALVE);
XPushVarStr clayer(_T("CLAYER"), LAY_EQUIP_VALVE);
double nScaleY = 200;
double nScale = 150;
BOOL bReversal = FALSE;
BOOL bReversal2 = FALSE;
while(1){
TBlockEdJig jig(g_csInsBlkName, ptIns, nScale, nScaleY);
jig.SetPrompt(_T("\n请指定阀件的插入点 [左右翻转(F)/上下翻转(D)]<退出>:"));
jig.SetKeyword(_T("F D R"));
jig.m_bReversal = bReversal;
int nKeyIndex = 0;
int nRetCode = jig.DoIt(&nKeyIndex);
if(nRetCode == RTNORM)
ptIns = jig.GetPickPoint();
else if(nRetCode == RTKWORD){
if(nKeyIndex == 0)
bReversal = !bReversal;
else if(nKeyIndex == 1){
g_nInsBlkRotate += PI;
bReversal2 = !bReversal2;
}
else if(nKeyIndex == 2){
BuildDoubleLineValve();
dlg.Reset();
}
continue;
}
else
break;
XPushVar<int> vOsMode2(_T("OSMODE"), 0);
Entity entBase, ent3, ent4;
RBList rbMask(RTDXF0, _T("ATS_DOUBLELINEPIPE"), 8, _T("*"), NULL);
PickSet ss(SS_FREE);
XPoint ptUcs = Wcs2Ucs(ptIns);
GetPointPickSet(ptUcs, ss, rbMask, 50);//三维上选管,50可能选不上
long ee = ss.Length();
if(ss.Length() == 0)
GetPointPickSet(ptUcs, ss, rbMask, 150);
if(ss.Length() != 1)
continue;
entBase = ss[0L];
if(!entBase)
break;
XCurveSegment seg;
XVector3D vectBase;
AcDbObjectId idPipe = NULL;
OPENOBJ_BEGIN(entBase, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
pPipe->getClosestPointTo(ptIns, ptIns);
// pPipe->getClosestPointTo(ptIns, AcGeVector3d::kZAxis, ptIns); //2009-1-15 支持垂直管线
idPipe = pPipe->objectId();
XPoint ptS = pPipe->StartPoint();
XPoint ptE = pPipe->EndPoint();
// cet 2010.6.3 del 管线垂直时ptIns投影值有误
// ptS.z = 0;
// ptE.z = 0;
XCurveSegment seg2(ptS, ptE, 0);
seg2.ProjectToMe(ptIns, ptIns);
seg = seg2;
if(!pPipe->IsVertical())
{
ptIns.z = pPipe->StartPoint().z;
vectBase = XVector3D(seg.EndPoint().x - seg.StartPoint().x, seg.EndPoint().y - seg.StartPoint().y, 0);
}
else
vectBase = XVector3D(0,0,1);//垂直管线特别处理一下
nScaleY = pPipe->GetWidth();
nScale = nScaleY*3/4;
OPENOBJ_END();
// XVector3D vectBase(seg.EndPoint().x - seg.StartPoint().x, seg.EndPoint().y - seg.StartPoint().y, 0);
vectBase.Normalize();
AcGeVector3d vectOld = vectBase;
int iQuadrant = 0;
if(vectBase.y < -0.000001
||(vectBase.y<0.000001&&vectBase.y>=-0.000001&&vectBase.x<0)){ //管线逆向绘制
vectBase.x = -vectBase.x;
vectBase.y = -vectBase.y;
iQuadrant = 2;
}
if(bReversal && iQuadrant == 0)
iQuadrant = 1;
else if(bReversal && iQuadrant == 2)
iQuadrant = 3;
CString csTk, csRecord, csDesName;
SplitBlkStr(g_csInsBlkName, csTk, csRecord);
csTk = g_csDwbPath + csTk + _T(".tk");
csDesName = GetBlkDesName(csRecord, csTk);
AcDbObjectId recordId = GetBlkIdByName(g_csInsBlkName);
double nWidth = GetValveWidth(g_csInsBlkName);
double dLen = GetValveLength(g_csInsBlkName, nScaleY);
if(dLen > 0.001)
nScale = dLen/nWidth;
TDbPipeValve *pValve = new TDbPipeValve;
AcDbObjectId recordId3d = Get3dBlockByDesName((const TCHAR*)csDesName);
pValve->SetBlock3d(recordId3d);
pValve->SetBlock2d(recordId);
pValve->SetLocation(ptIns);
pValve->SetWidth(nWidth);
pValve->SetHasFlange(dlg.m_bNeedFlange);
pValve->SetFlangeWidth(0.25);
pValve->SetScale(nScale);
pValve->SetYScale(nScaleY);
pValve->SetFlangeDn(nScaleY+50);
pValve->setLayer(LAY_EQUIP_VALVE);
pValve->setColor(AcCmColor()); //随层
pValve->SetDirection(vectBase);
pValve->SetQuadrant(iQuadrant);
pValve->SetPipeId(idPipe);
AddToCurrentSpace(pValve, Adesk::kTrue);
TPipePerDocData *pData = GetCurPipeDocData();
pData->ApplyUpdates();
}
g_nInsBlkRotate = 0;
SHads_command(RTNONE);
dlg.DestroyWindow();
return;
}
//***************************************************************************************************
// 绘制双线水管
//***************************************************************************************************
// cet 2011.8.24 add
// 判断点是否在双线水管的边线端点上(注意:pt必须已在line上)
bool PtIsOnLine(const AcDbLine &line, const AcGePoint3d &pt)
{
// 求pt到线的投影点
AcGePoint3d pt1;
line.getClosestPointTo(pt, pt1);
// 比较投影点到端点的间距
AcGePoint3d ptS, ptE;
line.getStartPoint(ptS);
line.getEndPoint(ptE);
double dDistS = pt1.distanceTo(ptS);
double dDistE = pt1.distanceTo(ptE);
if (fabs(dDistS) < _DIST_SNAP || fabs(dDistE) < _DIST_SNAP)
{
return true;
}
return false;
}
// cet 2011.8.24 add
// 判断点是否在线的延长线上
bool PtIsOnExtendLine(const AcGePoint3d &pt, const AcDbLine &line)
{
AcGePoint3d ptS, ptE;
line.getStartPoint(ptS);
line.getEndPoint(ptE);
if (fabs(ptS.distanceTo(pt) + ptE.distanceTo(pt) - ptS.distanceTo(ptE)) < 0.001)
{
return false;
}
AcGeVector3d vt1 = ptS - pt;
AcGeVector3d vt2 = ptE - pt;
AcGeTol tol;
tol.setEqualVector(0.001);
if (vt1.isParallelTo(vt2, tol))
{
return true;
}
return false;
}
// cet 2011.8.24 add
// 修改管线管端点
void ModifyDoubleLinePipe(Entity &ent, const XPoint &pt)
{
AcDbObjectId idPipe;
acdbGetObjectId(idPipe, ent);
TDbDoubleLinePipe *pPipe = NULL;
acdbOpenObject(pPipe, idPipe, AcDb::kForWrite);
if (pPipe != NULL)
{
XPoint ptS = pPipe->GetStartPoint();
XPoint ptE = pPipe->GetEndPoint();
if (ptS.Distance(pt) < ptE.Distance(pt))
{
pPipe->SetStartPoint(pt);
}
else
{
pPipe->SetEndPoint(pt);
}
pPipe->close();
}
}
// cet 2011.8.24 add
// 过滤管线, 选出ptS,ptE有一点在在其边线上的双线管
void FiltrateDoubleLinePipe(PickSet &ss, XPoint &ptS, XPoint &ptE, PickSet &ss2)
{
XPoint ptS1, ptE1, pt1, pt2;
AcDbObjectId id;
TDbDoubleLinePipe *pPipe = NULL;
AcDbLine line;
for (long i = 0; i < ss.Length(); i++)
{
acdbGetObjectId(id, ss[i]);
acdbOpenObject(pPipe, id, AcDb::kForRead);
if (pPipe != NULL)
{
ptS1 = pPipe->GetStartPoint();
ptE1 = pPipe->GetEndPoint();
double dWidth = pPipe->GetWidth();
pPipe->close();
// cet 2012.10.19 add 支持米单位
if (DocGetCurMeterUnitDraw())
{
dWidth *= 0.001;
}
line.setStartPoint(ptS1);
line.setEndPoint(ptE1);
line.getClosestPointTo(ptS, pt1);
line.getClosestPointTo(ptE, pt2);
double dDist1 = ptS.Distance(pt1);
double dDist2 = ptE.Distance(pt2);
AcGeVector3d vt1 = pt1 - ptS, vt2 = pt2 - ptE;
AcGeVector3d vt = ptS1 - ptE1;
if (fabs(dDist1 - dWidth * 0.5) < _DIST_SNAP && vt.isPerpendicularTo(vt1)
|| fabs(dDist2 - dWidth * 0.5) < _DIST_SNAP && vt.isPerpendicularTo(vt2)) // 端点在双线管的边线上
{
ss2 += ss[i];
}
}
}
}
// cet 2011.8.24 add
// 当双线水管的端点在另一根双线水管的两条边线上时,中心线之间有交点而且在延长线上时,延长双线管
void ModifyDoubleLinePipe(Entity &ent)
{
AcDbObjectId idPipe;
acdbGetObjectId(idPipe, ent);
TDbDoubleLinePipe *pPipe = NULL;
acdbOpenObject(pPipe, idPipe, AcDb::kForRead);
if (NULL == pPipe)
{
return;
}
XPoint ptS = pPipe->GetStartPoint();
XPoint ptE = pPipe->GetEndPoint();
pPipe->close();
// 获取端点处的双线管
RBList rbMask(RTDXF0, _T("ATS_DOUBLELINEPIPE"), 8, _T("*"), NULL);
PickSet ss(SS_FREE), ss1(SS_FREE);
GetPointPickSet(Wcs2Ucs(ptS), ss, rbMask, 50);
GetPointPickSet(Wcs2Ucs(ptE), ss1, rbMask, 50);
ss -= ent;
ss1 -= ent;
ss += ss1;
// 选择端点在其边线上的双线管
PickSet ss2(SS_FREE);
FiltrateDoubleLinePipe(ss, ptS, ptE, ss2);
if (ss2.Length() == 0)
{
return;
}
// 处理双线管端点
AcDbLine line(ptS, ptE);
AcGePoint3dArray ptArr;
for (long i = 0; i < ss2.Length(); i++)
{
ptArr.setLogicalLength(0);
acdbGetObjectId(idPipe, ss2[i]);
acdbOpenObject(pPipe, idPipe, AcDb::kForRead);
if (pPipe != NULL)
{
XPoint pt1 = pPipe->GetStartPoint();
XPoint pt2 = pPipe->GetEndPoint();
pPipe->close();
AcDbLine line1(pt1, pt2);
line1.intersectWith(&line, AcDb::kExtendBoth, ptArr);
if (ptArr.length() == 1/* && PtIsOnExtendLine(ptArr[0], line)*/) // 并且交点在line的延长线上
{
ModifyDoubleLinePipe(ent, ptArr[0]);
// // 当双线水管的端点在另一根双线水管的两条边线的端点时,修改双线管
// if (PtIsOnLine(line1, ptS) || PtIsOnLine(line1, ptE))
// {
// ModifyDoubleLinePipe(ss2[i], ptArr[0]);
// }
}
}
}
}
//
void UpdateDbPipeDlg(CPipeDoubleDlg &dlg, const AcGePoint3d &ptGrip, const AcDbObjectId &id)
{
// 从大小接头启动绘制命令
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbDoubleLinePipeReducer, pReducer);
if (pReducer != NULL)
{
AcGePoint3d ptS, ptE, ptMid;
pReducer->GetPoints(ptS, ptMid, ptE);
if (ptS.distanceTo(ptGrip) < 0.001) // 起点启动绘制命令
{
dlg.UpdateDn(pReducer->GetSPipeDiameter());
}
else // 终点启动绘制命令
{
dlg.UpdateDn(pReducer->GetEPipeDiameter());
}
// 大小接头连接着管线时,读取管线压力
AcDbObjectId id1;
int nNum = pReducer->GetInterfaceNum();
for (int i = 0; i < nNum; i++)
{
const TPipeInterface &face = pReducer->GetInterface(i);
if (face.m_idPipe.isValid())
{
id1 = face.m_idPipe;
break;
}
}
ads_name ent;
acdbGetAdsName(ent, id1);
CString sPn = ReadXdata(ent, _T("TG-PIPE-FLANGE-PN"));
if (sPn.IsEmpty())
{
sPn = _T("1.0MPa");
}
sPn.TrimRight(_T("MPa"));
dlg.UpdatePress(_tstof(sPn));
dlg.m_iMode = pReducer->GetLinkType() == TDbDoubleLinePipeReducer::eJointing ? 1 : 0;
if (DocGetCurMeterUnitDraw())
{
dlg.m_nEle = ptGrip.z;
}
else
{
dlg.m_nEle = ptGrip.z * 0.001;
}
dlg.UpdateData(FALSE);
}
OPENOBJ_END();
// 从fitting启动绘制命令
// 管线压力
ads_name ent;
acdbGetAdsName(ent, id);
CString sPn = ReadXdata(ent, _T("TG-PIPE-FLANGE-PN"));
if (sPn.IsEmpty())
{
sPn = _T("1.0MPa");
}
sPn.TrimRight(_T("MPa"));
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
if (pPipe != NULL)
{
dlg.UpdateDn(pPipe->GetDnDiameter());
dlg.UpdatePress(_tstof(sPn));
dlg.m_iMode = pPipe->GetFlange();
if (DocGetCurMeterUnitDraw())
{
dlg.m_nEle = ptGrip.z;
}
else
{
dlg.m_nEle = ptGrip.z * 0.001;
}
dlg.UpdateData(FALSE);
}
OPENOBJ_END();
}
// 检查管线是否需要变径,i = 0 起点 i = 1 终点
void UpdateDbPipeRedecing(const AcDbObjectId &idFitting, const AcDbObjectId &idPipe, int i)
{
TDbFlangeFitting *pFitting = NULL;
acdbOpenObject(pFitting, idFitting, AcDb::kForWrite);
if (pFitting != NULL)
{
// 三通四通
if (pFitting->GetInterfaceNum() > 2)
{
double dWidth = 0.0;
double dFangleDn = 0.0;
double dFlangeThick = 0.0;
double dDn = 0.0;
// 同一fitting上与之平行的双线水管
bool bExist = false;
if (pFitting->GetWidth(idPipe, dWidth, dFangleDn, dFlangeThick, &dDn))
{
bExist = true;
TDbDoubleLinePipe *pPipe = NULL;
acdbOpenObject(pPipe, idPipe, AcDb::kForRead);
if (pPipe != NULL)
{
// 管径不同
if (fabs(dDn - pPipe->GetDnDiameter()) > 0.001)
{
if (pPipe->upgradeOpen() == Acad::eOk)
{
pPipe->SetLinkReducing(i, true);
pPipe->downgradeOpen();
}
}
pPipe->close();
}
}
// 考虑绘制前fitting为共线变径的情况 cet 2012.11.16 add
int nNum = pFitting->GetInterfaceNum();
if (nNum == 3 && !bExist)
{
XPoint ptLoc = pFitting->GetLocation();
AcDbObjectId id1, id2;
for(int i = 0; i < 3; ++i)
{
const TPipeInterface &face = pFitting->GetInterface(i);
if (face.m_idPipe == idPipe)
{
continue;
}
if (id1.isNull())
{
id1 = face.m_idPipe;
}
else
{
id2 = face.m_idPipe;
}
}
OPENOBJ_BEGIN(id1, AcDb::kForWrite, TDbDoubleLinePipe, pPipe1);
if (pPipe1 != NULL)
{
OPENOBJ_BEGIN(id2, AcDb::kForWrite, TDbDoubleLinePipe, pPipe2);
if (pPipe2 != NULL)
{
AcGeVector3d vt1 = pPipe1->StartPoint() - pPipe1->EndPoint();
AcGeVector3d vt2 = pPipe2->StartPoint() - pPipe2->EndPoint();
AcGeTol tol;
tol.setEqualVector(0.001);
double dDn1 = pPipe1->GetDnDiameter();
double dDn2 = pPipe2->GetDnDiameter();
if (vt1.isParallelTo(vt2, tol) && fabs(dDn1 - dDn2) > 0.001)
{
if (dDn1 > dDn2)
{
if (ptLoc.Distance(pPipe2->StartPoint()) < 0.001)
{
pPipe2->SetLinkReducing(0, true);
}
else
{
pPipe2->SetLinkReducing(1, true);
}
}
else
{
if (ptLoc.Distance(pPipe1->StartPoint()) < 0.001)
{
pPipe1->SetLinkReducing(0, true);
}
else
{
pPipe1->SetLinkReducing(1, true);
}
}
}
}
OPENOBJ_END();
}
OPENOBJ_END();
}
}
pFitting->close();
}
}
// 更新pt点的双线管fitting cet 2012.11.16 add
// 如果Fitting上存在与vtPipe同向的管线pipe1, 找出Fitting上与之共线的管线
// pipe2, pipe1和pipe2不等径且pipe2无变径时,pipe1进行变径
void UpdateDbPipeFitting(const XPoint &pt, const AcGeVector3d &vtPipe)
{
RBList rbMask(RTDXF0, _T("ATS_FLANGE"), NULL);
double dRange = 100;
if (DocGetCurMeterUnitDraw())
{
dRange = 1;
}
PickSet ss(SS_FREE);
GetPointPickSet(pt, ss, rbMask, dRange);
// 找出插入点在pt的fitting
int nLen = ss.Length();
Entity ent;
for(long i = 0; i < nLen; ++i)
{
OPENOBJ_BEGIN(ss[i], AcDb::kForRead, TDbFlangeFitting, pFitting);
if (pFitting != NULL)
{
// 非三通、四通不处理
if (pFitting->GetInterfaceNum() < 3)
{
continue;
}
if (pt.Distance(pFitting->GetLocation()) < 0.001)
{
ent = ss[i];
break;
}
}
OPENOBJ_END();
}
// 处理变径
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbFlangeFitting, pFitting);
if (pFitting != NULL)
{
int nNum = pFitting->GetInterfaceNum();
// 找出同向管线
AcDbObjectId idPipe;
double dDn = 0.0;
AcGeTol tol;
tol.setEqualVector(0.001);
AcGeVector3d vtPipe2;
for (int i = 0; i < nNum; ++i)
{
const TPipeInterface &face = pFitting->GetInterface(i);
OPENOBJ_BEGIN(face.m_idPipe, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
if (pPipe != NULL)
{
if (pt.Distance(pPipe->StartPoint()) < 0.001)
{
vtPipe2 = pPipe->EndPoint() - pPipe->StartPoint();
}
else
{
vtPipe2 = pPipe->StartPoint() - pPipe->EndPoint();
}
if (vtPipe.isCodirectionalTo(vtPipe2, tol))
{
dDn = pPipe->GetDnDiameter();
idPipe = face.m_idPipe;
break;
}
}
OPENOBJ_END();
}
if (idPipe.isNull())
{
return;
}
// 检查是否需要变径
bool bNeedReducing = false;
for(int j = 0; j < nNum; ++j)
{
const TPipeInterface &face = pFitting->GetInterface(j);
if (idPipe == face.m_idPipe)
{
continue;
}
OPENOBJ_BEGIN(face.m_idPipe, AcDb::kForRead, TDbDoubleLinePipe, pPipe);
if (pPipe != NULL)
{
int nSide = 0;
if (pt.Distance(pPipe->StartPoint()) < 0.001)
{
vtPipe2 = pPipe->EndPoint() - pPipe->StartPoint();
nSide = 0;
}
else
{
vtPipe2 = pPipe->StartPoint() - pPipe->EndPoint();
nSide = 1;
}
if (vtPipe.isParallelTo(vtPipe2, tol))
{
if (!pPipe->IsLinkReducing(nSide) && fabs(dDn - pPipe->GetDnDiameter()) > 0.001)
{
bNeedReducing = true;
}
break;
}
}
OPENOBJ_END();
}
if (!bNeedReducing)
{
return;
}
// 变径
OPENOBJ_BEGIN(idPipe, AcDb::kForWrite, TDbDoubleLinePipe, pPipe);
if (pPipe != NULL)
{
if (pt.Distance(pPipe->StartPoint()) < 0.001)
{
pPipe->SetLinkReducing(0, true);
}
else
{
pPipe->SetLinkReducing(1, true);
}
}
OPENOBJ_END();
}
OPENOBJ_END();
}
// 根据双线水管连接情况,实时生成变径 cet 2012.11.12 add
void UpdateDbPipeRedecing(Entity &ent)
{
AcDbObjectId idPipe;
acdbGetObjectId(idPipe, ent);
// 管线已经被删除(如合并管线所致)
if (idPipe.isErased())
{
TDbDoubleLinePipe *pPipe = NULL;
XPoint ptS, ptE;
acdbOpenObject(pPipe, idPipe, AcDb::kForRead, true);
if (pPipe != NULL)
{
ptS = pPipe->StartPoint();
ptE = pPipe->EndPoint();
pPipe->close();
}
if (!!ptS || !!ptE)
{
AcGeVector3d vtPipe = ptE - ptS;
UpdateDbPipeFitting(ptS, vtPipe);
UpdateDbPipeFitting(ptE, -vtPipe);
}
return;
}
TDbDoubleLinePipe *pPipe = NULL;
AcDbObjectId idNode1, idNode2;
acdbOpenObject(pPipe, idPipe, AcDb::kForRead);
if (pPipe != NULL)
{
idNode1 = pPipe->GetNode(0);
idNode2 = pPipe->GetNode(1);
pPipe->close();
}
UpdateDbPipeRedecing(idNode1, idPipe, 0);
UpdateDbPipeRedecing(idNode2, idPipe, 1);
}
void DrawDoublePipe()
{
CPipeDoubleDlg dlg(0, acedGetAcadFrame());
{
CTemporaryResourceOverride vTemp;
dlg.Create(IDD_PIPE_DOUBLE, acedGetAcadFrame());
}
dlg.ShowWindow(SW_SHOW);
acedGetAcadDwgView()->SetFocus();
int nOsMode=0;
xg_getvar(_T("OSMODE"), &nOsMode);
nOsMode &= ~0x4000;
nOsMode |= OS_INT|OS_NEA|OS_PER|OS_END;
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
//XPushVar<int> vOrthoMode(_T("ORTHOMODE"), 1); //f8 cet 2011.5.23 del
InitLayer(LAY_PIPE_DOUBLE);
InitDoteLayer(LAY_TWT_DOTE);
XPushVarStr clayer(_T("CLAYER"), LAY_PIPE_DOUBLE);
XPoint ptStart, ptEnd;
dlg.m_bInit = TRUE;
// cet 2012.11.7 modify 支持夹点启动命令
// if(ads_getpoint(NULL, _T("\n请输入起点:<退出>"), ptStart) != RTNORM){
// dlg.DestroyWindow();
// return;
// }
// dlg.UpdateData(TRUE);
AcGePoint3d ptGrip;
AcDbObjectId id;
if (GetGripCmdData(ptGrip, id)) // 获取夹点数据
{
ptStart = Wcs2Ucs(ptGrip);
// 更新对话框数据
UpdateDbPipeDlg(dlg, ptGrip, id);
}
else
{
if(ads_getpoint(NULL, _T("\n请输入起点:<退出>"), ptStart) != RTNORM){
dlg.DestroyWindow();
return;
}
dlg.UpdateData(TRUE);
}
Entity entLast;
RBList rbMask(RTDXF0, _T("ATS_DOUBLELINEPIPE"), 8, _T("*"), NULL);
PickSet ss(SS_FREE);
// cet 2012.10.18 modify 双线水管随前一管线标高时,重设标高
// GetPointPickSet(ptStart, ss, rbMask, 50);//三维上选管,50可能选不上
// ptStart = Ucs2Wcs(ptStart);
// long ee = ss.Length();
// if(ss.Length() == 1)
// {
// entLast = ss[0L];
// XPoint ptS, ptE;
// GetPipePoint(entLast, ptS, ptE);
//
// double dDist1 = ads_distance(ptS, ptStart);
// double dDist2 = ads_distance(ptE, ptStart);
// if(dDist1 < 100 || dDist2 < 100)
// {
// if(dDist1 < dDist2)
// ptStart = ptS;
// else
// ptStart = ptE;
// }
// dlg.m_nEle = ptS.z / 1000;
// dlg.UpdateData(FALSE);
// }
double dMeter = 1000;
double dRange = 50;
double dDist = 100;
if (DocGetCurMeterUnitDraw())
{
dMeter = 1.0;
dRange = 0.05;
dDist = 0.1;
}
GetPointPickSet(ptStart, ss, rbMask, dRange);//三维上选管,50可能选不上
ptStart = Ucs2Wcs(ptStart);
if (dlg.IsFrontDbPipeEle())
{
if(ss.Length() == 1)
{
entLast = ss[0L];
XPoint ptS, ptE;
GetPipePoint(entLast, ptS, ptE);
double dDist1 = ads_distance(ptS, ptStart);
double dDist2 = ads_distance(ptE, ptStart);
if(dDist1 < dDist || dDist2 < dDist)
{
if(dDist1 < dDist2)
ptStart = ptS;
else
ptStart = ptE;
}
dlg.m_nEle = ptS.z / dMeter;
dlg.UpdateData(FALSE);
}
}
// cet 2012.10.18 add 起点在另一根双线水管上时,根据情况生成扣弯
bool bCreatVDbPipe = false;
XPoint ptVDbPipeS, ptVDbPipeE;
if (!dlg.m_bIsVPipe /*&& fabs(ptStart.z - dlg.m_nEle * dMeter) > 0.001*/ && ss.Length() == 1)
{
XPoint pt1, pt2;
GetPipePoint(ss[0l], pt1, pt2);
// 非立管
if (pt1.Distance2d(pt2) > 0.001)
{
AcDbLine line(pt1, pt2);
AcGePoint3d ptInt;
// 获得管线上最近的点
if (line.getClosestPointTo(ptStart, ptInt) == Acad::eOk)
{
double dDn = 0.0;
OPENOBJ_BEGIN(ss[0l], AcDb::kForRead, TDbDoubleLinePipe, pPipe);
if (pPipe != NULL)
{
dDn = pPipe->GetDnDiameter();
}
OPENOBJ_END();
if (DocGetCurMeterUnitDraw())
{
dDn *= 0.001;
}
// 起点在双线水管上
if (dDn > 0.001 && ptStart.Distance2d(ptInt) < dDn * 0.5 + 0.001)
{
double dEle = ptStart.z;
ptStart = ptInt; // 将起点位置移动管线最近点
ptStart.z = dEle;
bCreatVDbPipe = true;
ptVDbPipeS = ptInt;
ptVDbPipeE = ptStart;
ptVDbPipeE.z = dlg.m_nEle*dMeter;
}
}
}
}
dlg.UpdateData(TRUE);
// ptStart.z = dlg.m_nEle*1000; cet 2012.10.19 modify 支持米单位
ptStart.z = dlg.m_nEle * dMeter;
XPointList lstPt;
lstPt.Append(new XPoint(ptStart));
while(1){
dlg.UpdateData(TRUE);
double nWidth = dlg.m_dRetDn;
CString csPn;
if(dlg.m_iPn == 0)
csPn = _T("0.25MPa");
else if(dlg.m_iPn == 1)
csPn = _T("0.6MPa");
else if(dlg.m_iPn == 2)
csPn = _T("1.0MPa");
else if(dlg.m_iPn == 3)
csPn = _T("1.6MPa");
TDoublePipeJig jig(ptStart, dlg.m_bIsVPipe, nWidth);
jig.SetPrompt(_T("\n请输入双线水管终点<退出>:"));
jig.SetKeyword(_T("D"));
int nKeyIndex;
int ret = jig.DoIt(&nKeyIndex);
if(ret == RTKWORD)
continue;
else if(ret != RTNORM)
break;
dlg.UpdateData(TRUE);
ptEnd = jig.GetPickPoint();
if(dlg.m_bIsVPipe){
TDbDoubleLinePipe *pPipe2 = new TDbDoubleLinePipe;
ptStart = jig.GetPickPoint();
//cet 2012.10.19 modify 支持米单位
//ptStart.z = dlg.m_nEle*1000;
//ptEnd.z = dlg.m_nEle2*1000;
ptStart.z = dlg.m_nEle * dMeter;
ptEnd.z = dlg.m_nEle2 * dMeter;
pPipe2->SetStartPoint(ptStart);
pPipe2->SetEndPoint(ptEnd);
pPipe2->SetWidth(nWidth);
// pPipe2->SetPipeWeight(0.35); cet 2012.10.18 modify 线宽随设置值
pPipe2->SetPipeWeight(g_dDbPipeLineWidth);
pPipe2->SetDnDiameter(nWidth);
pPipe2->SetFlange(dlg.m_iMode);
pPipe2->SetRate(g_nElbowRate);
pPipe2->SetFlangeDn(dlg.m_nFlangeDn);
pPipe2->SetFlangeThick(dlg.m_nFlangeThick);
pPipe2->SetDoteLayer(InitLayer(LAY_TWT_DOTE));
AddToCurrentSpace(pPipe2, Adesk::kTrue);
entLast.GetLast();
WriteXdata(entLast, _T("TG-PIPE-FLANGE-PN"), csPn);
ptStart = ptEnd;
TPipePerDocData *pData = GetCurPipeDocData();
pData->ApplyUpdates();
continue;
}
//cet 2012.10.19 modify 支持米单位
//ptEnd.z = dlg.m_nEle*1000;
ptEnd.z = dlg.m_nEle * dMeter;
lstPt.Append(new XPoint(ptEnd));
//cet 2012.10.19 modify 支持米单位
//if(fabs(ptStart.z - dlg.m_nEle*1000) > 0.00001 && lstPt.Length() > 2){ //与上一根管线有高差
if(fabs(ptStart.z - dlg.m_nEle * dMeter) > 0.00001 && lstPt.Length() > 2){ //与上一根管线有高差
TDbDoubleLinePipe *pPipe2 = new TDbDoubleLinePipe;
pPipe2->SetStartPoint(ptStart);
//cet 2012.10.19 modify 支持米单位
//ptStart.z = dlg.m_nEle*1000;
ptStart.z = dlg.m_nEle * dMeter;
pPipe2->SetEndPoint(ptStart);
pPipe2->SetWidth(nWidth);
// pPipe2->SetPipeWeight(0.35); cet 2012.10.18 modify 线宽随设置值
pPipe2->SetPipeWeight(g_dDbPipeLineWidth);
pPipe2->SetDnDiameter(nWidth);
pPipe2->SetFlange(dlg.m_iMode);
pPipe2->SetRate(g_nElbowRate);
pPipe2->SetFlangeDn(dlg.m_nFlangeDn);
pPipe2->SetFlangeThick(dlg.m_nFlangeThick);
pPipe2->SetDoteLayer(InitLayer(LAY_TWT_DOTE));
AddToCurrentSpace(pPipe2, Adesk::kTrue);
entLast.GetLast();
WriteXdata(entLast, _T("TG-PIPE-FLANGE-PN"), csPn);
}
//cet 2012.10.19 modify 支持米单位
//ptStart.z = dlg.m_nEle*1000;
ptStart.z = dlg.m_nEle * dMeter;
TDbDoubleLinePipe *pPipe = new TDbDoubleLinePipe;
pPipe->SetStartPoint(ptStart);
pPipe->SetEndPoint(ptEnd);
pPipe->SetWidth(nWidth);
// pPipe->SetPipeWeight(0.35); cet 2012.10.18 modify 线宽随设置值
pPipe->SetPipeWeight(g_dDbPipeLineWidth);
pPipe->SetDnDiameter(nWidth);
pPipe->SetFlange(dlg.m_iMode);
pPipe->SetRate(g_nElbowRate);
pPipe->SetFlangeDn(dlg.m_nFlangeDn);
pPipe->SetFlangeThick(dlg.m_nFlangeThick);
pPipe->SetDoteLayer(InitLayer(LAY_TWT_DOTE));
AddToCurrentSpace(pPipe, Adesk::kTrue);
entLast.GetLast();
ModifyDoubleLinePipe(entLast); // cet 2011.8.24 add 当双线管端点在其他双线管的边线时,修改端点
WriteXdata(entLast, _T("TG-PIPE-FLANGE-PN"), csPn);
ptStart = ptEnd;
// cet 2012.10.18 add 起点在双线水管且起点存在高差时生成扣弯
if (bCreatVDbPipe && fabs(ptVDbPipeS.z - dlg.m_nEle * dMeter) > 0.001)
{
bCreatVDbPipe = false;
TDbDoubleLinePipe *pNewDbPipe = new TDbDoubleLinePipe;
pNewDbPipe->SetStartPoint(ptVDbPipeS);
ptVDbPipeE.z = dlg.m_nEle * dMeter;
pNewDbPipe->SetEndPoint(ptVDbPipeE);
pNewDbPipe->SetWidth(dlg.m_dRetDn);
pNewDbPipe->SetPipeWeight(g_dDbPipeLineWidth);
pNewDbPipe->SetDnDiameter(dlg.m_dRetDn);
pNewDbPipe->SetFlange(dlg.m_iMode);
pNewDbPipe->SetRate(g_nElbowRate);
pNewDbPipe->SetFlangeDn(dlg.m_nFlangeDn);
pNewDbPipe->SetFlangeThick(dlg.m_nFlangeThick);
pNewDbPipe->SetDoteLayer(InitLayer(LAY_TWT_DOTE));
AddToCurrentSpace(pNewDbPipe, Adesk::kTrue);
}
TPipePerDocData *pData = GetCurPipeDocData();
pData->ApplyUpdates();
// 根据需要生成双线水管变径 cet 2012.11.12 add
UpdateDbPipeRedecing(entLast);
pData->ApplyUpdates();
}
dlg.DestroyWindow();
SHads_command(RTNONE);
}
/////////////////////////////////////////////////////////////////////////////
// CPipeDoubleDlg dialog
IMPLEMENT_DYNAMIC(CPipeDoubleDlg, CModelessDialog)
int CPipeDoubleDlg::m_iMode = 0;
//CString CPipeDoubleDlg::m_csDn = _T("200");
double CPipeDoubleDlg::m_dRetDn = 200;
BOOL CPipeDoubleDlg::m_bEle = TRUE; // cet 2012.10.18 add
double CPipeDoubleDlg::m_nEle = 0.0; // cet 2012.10.18 add
CPipeDoubleDlg::CPipeDoubleDlg(int iOpenMode, CWnd* pParent /*=NULL*/)
: CModelessDialog(CPipeDoubleDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPipeDoubleDlg)
// m_nEle = 0; cet 2012.10.18 del
m_nFlangeDn = 160;
m_nFlangeThick = 14;
m_bIsVPipe = FALSE;
m_nEle2 = 1;
m_iDn = 6;
m_iPn = 2;
//}}AFX_DATA_INIT
m_iOpenMode = iOpenMode;
m_bInit = FALSE;
m_pMenuEle = NULL; // cet 2012.10.18 add
}
CPipeDoubleDlg::~CPipeDoubleDlg()
{
if (m_pMenuEle != NULL)
{
m_pMenuEle->DestroyMenu();
delete m_pMenuEle;
}
}
void CPipeDoubleDlg::DoDataExchange(CDataExchange* pDX)
{
CModelessDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPipeDoubleDlg)
DDX_Control(pDX, IDC_COMBO_DN, m_comboDn);
DDX_Control(pDX, IDC_COMBO_PN, m_cmbPress);
DDX_Text(pDX, IDC_EDIT_ELEV, m_nEle);
DDX_Text(pDX, IDC_EDIT_FLANGEDN, m_nFlangeDn);
DDX_Text(pDX, IDC_EDIT_FLANGETHICK, m_nFlangeThick);
DDX_Check(pDX, IDC_CHECK_VPIPE, m_bIsVPipe);
DDX_Text(pDX, IDC_EDIT_ELEV2, m_nEle2);
DDX_CBIndex(pDX, IDC_COMBO_DN, m_iDn);
DDX_Radio(pDX, IDC_RADIO_MODE1, m_iMode);
DDX_CBIndex(pDX, IDC_COMBO_PN, m_iPn);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPipeDoubleDlg, CModelessDialog)
//{{AFX_MSG_MAP(CPipeDoubleDlg)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_RADIO_MODE1, OnRadioMode1)
ON_BN_CLICKED(IDC_RADIO_MODE2, OnRadioMode2)
ON_BN_CLICKED(IDC_CHECK_VPIPE, OnCheckVpipe)
ON_CBN_SELCHANGE(IDC_COMBO_DN, OnSelchangeComboDn)
ON_CBN_SELCHANGE(IDC_COMBO_PN, OnSelchangeComboPn)
ON_BN_CLICKED(IDC_BUTTON_POPMENU, OnButtonPopMenu)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPipeDoubleDlg message handlers
void CPipeDoubleDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
OpenSlide();
}
void CPipeDoubleDlg::OpenSlide()
{
UpdateData(TRUE);
CWnd *pImageBox = GetDlgItem(IDC_STATIC_VIEW);
CString csSldName;
CWnd *pWnd1 = GetDlgItem(IDC_EDIT_FLANGEDN);
CWnd *pWnd2 = GetDlgItem(IDC_EDIT_FLANGETHICK);
if(m_iMode == 0){
csSldName = _T("TWT(FL2)");
pWnd1->EnableWindow(TRUE);
pWnd2->EnableWindow(TRUE);
}
else if(m_iMode == 1){
csSldName = _T("TWT(FL3)");
pWnd1->EnableWindow(FALSE);
pWnd2->EnableWindow(FALSE);
}
csSldName = g_csSysPath + csSldName;
DrawSlide((const TCHAR*)csSldName, pImageBox);
}
BOOL CPipeDoubleDlg::OnInitDialog()
{
CModelessDialog::OnInitDialog();
ResetDn();
if(m_iOpenMode == 0){
CRect rect;
this->GetWindowRect(&rect);
rect.bottom -= 30;
this->MoveWindow(&rect);
}
// else{
int idx = m_comboDn.FindString(-1, XString(_T("%.0f"), m_dRetDn));
m_comboDn.SetCurSel(idx);
// }
OpenSlide();
CWnd *pWnd1 = GetDlgItem(IDC_CHECK_VPIPE);
if(m_iOpenMode == 0)
UpdateFlange();
else
pWnd1->EnableWindow(FALSE);
OnCheckVpipe();
UpdateFlange();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPipeDoubleDlg::ResetDn()
{
UpdateData(TRUE);
m_comboDn.ResetContent();
if(m_iMode == 1){
m_comboDn.AddString(_T("15"));
m_comboDn.AddString(_T("20"));
m_comboDn.AddString(_T("25"));
m_comboDn.AddString(_T("32"));
m_comboDn.AddString(_T("40"));
}
m_comboDn.AddString(_T("50"));
m_comboDn.AddString(_T("65"));
m_comboDn.AddString(_T("80"));
m_comboDn.AddString(_T("100"));
m_comboDn.AddString(_T("125"));
m_comboDn.AddString(_T("150"));
m_comboDn.AddString(_T("200"));
m_comboDn.AddString(_T("250"));
m_comboDn.AddString(_T("300"));
m_comboDn.AddString(_T("350"));
m_comboDn.AddString(_T("400"));
m_comboDn.AddString(_T("450"));
m_comboDn.AddString(_T("500"));
m_comboDn.AddString(_T("600"));
m_comboDn.AddString(_T("700"));
m_comboDn.AddString(_T("800"));
m_comboDn.AddString(_T("900"));
m_comboDn.AddString(_T("1000"));
m_comboDn.AddString(_T("1200"));
m_comboDn.AddString(_T("1400"));
m_comboDn.AddString(_T("1600"));
m_comboDn.AddString(_T("1800"));
m_comboDn.AddString(_T("2000"));
m_iDn = 0;
UpdateData(FALSE);
}
void CPipeDoubleDlg::OnRadioMode1()
{
OpenSlide();
// cet 2012.11.7 modiy 管径数据更改后,需更新管径关联数据
// ResetDn();
CString sDn, sTemp;
m_comboDn.GetLBText(m_iDn, sDn);
int nCount = m_comboDn.GetCount();
for (int i = 0; i < nCount; i++)
{
m_comboDn.GetLBText(i, sTemp);
if (sDn.CompareNoCase(sTemp) == 0)
{
m_iDn = i;
break;
}
}
UpdateData(FALSE);
OnSelchangeComboDn();
}
void CPipeDoubleDlg::OnRadioMode2()
{
OpenSlide();
// cet 2012.11.7 modiy 管径数据更改后,需更新管径关联数据
// ResetDn();
CString sDn, sTemp;
m_comboDn.GetLBText(m_iDn, sDn);
int nCount = m_comboDn.GetCount();
for (int i = 0; i < nCount; i++)
{
m_comboDn.GetLBText(i, sTemp);
if (sDn.CompareNoCase(sTemp) == 0)
{
m_iDn = i;
break;
}
}
UpdateData(FALSE);
OnSelchangeComboDn();
}
//以下数据采用《钢制管件》02S403 P75
void CPipeDoubleDlg::UpdateFlange()
{
UpdateData(TRUE);
GetFlangeDataByDn(m_iPn, m_dRetDn, m_nFlangeDn, m_nFlangeThick);
UpdateData(FALSE);
}
void CPipeDoubleDlg::OnCheckVpipe()
{
UpdateData(TRUE);
CWnd *pWnd = GetDlgItem(IDC_EDIT_ELEV2);
if(m_bIsVPipe)
pWnd->EnableWindow(TRUE);
else
pWnd->EnableWindow(FALSE);
if(m_iOpenMode == 0 && m_bInit == TRUE)
PostCommand(_T("D "), false);
}
void CPipeDoubleDlg::OnOK()
{
CModelessDialog::OnOK();
}
void CPipeDoubleDlg::OnSelchangeComboDn()
{
UpdateData(TRUE);
CString csDn;
int idx;
idx = m_comboDn.GetCurSel();
m_comboDn.GetLBText(idx, csDn);
m_dRetDn = _tstof(csDn);
UpdateFlange();
if(m_iOpenMode == 0 && m_bInit == TRUE)
PostCommand(_T("D "), false);
}
void CPipeDoubleDlg::OnSelchangeComboPn()
{
UpdateFlange();
}
void CPipeDoubleDlg::OnButtonPopMenu()
{
CWnd *pWnd = GetDlgItem(IDC_BUTTON_POPMENU);
CRect rc;
pWnd->GetWindowRect(rc);
if(m_pMenuEle != NULL)
{
m_pMenuEle->DestroyMenu();
m_pMenuEle->CreatePopupMenu();
}
else
{
m_pMenuEle = new CMenu;
m_pMenuEle->CreatePopupMenu();
}
if (m_bEle)
{
m_pMenuEle->AppendMenu(MF_CHECKED, WM_USER + 1, _T("自动读取前一管线标高"));
m_pMenuEle->AppendMenu(MF_UNCHECKED, WM_USER + 2, _T("不读取前一管线标高"));
}
else
{
m_pMenuEle->AppendMenu(MF_UNCHECKED, WM_USER + 1, _T("自动读取前一管线标高"));
m_pMenuEle->AppendMenu(MF_CHECKED, WM_USER + 2, _T("不读取前一管线标高"));
}
m_pMenuEle->TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_VERTICAL,
rc.left, rc.bottom, this, &rc);
}
BOOL CPipeDoubleDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
if (m_pMenuEle != NULL)
{
CString sCmd;
m_pMenuEle->GetMenuString(wParam, sCmd, MF_BYCOMMAND);
if (sCmd.Compare(_T("自动读取前一管线标高")) == 0)
{
m_bEle = true;
}
else if (sCmd.Compare(_T("不读取前一管线标高")) == 0)
{
m_bEle = false;
}
}
return CModelessDialog::OnCommand(wParam, lParam);
}
BOOL CPipeDoubleDlg::IsFrontDbPipeEle() const
{
return m_bEle;
}
void CPipeDoubleDlg::UpdateDn( double dDn )
{
int nCount = m_comboDn.GetCount();
CString sDn;
int nIndex = -1;
for(int i = 0; i < nCount; i++)
{
m_comboDn.GetLBText(i, sDn);
if (fabs(dDn - _tstof(sDn)) < 0.001)
{
nIndex = i;
break;
}
}
if (nIndex != -1)
{
m_comboDn.SetCurSel(nIndex);
m_iDn = nIndex;
UpdateData(FALSE);
OnSelchangeComboDn();
}
}
void CPipeDoubleDlg::UpdatePress( double dPress )
{
int nCount = m_cmbPress.GetCount();
CString sP;
int nIndex = -1;
for(int i = 0; i < nCount; i++)
{
m_cmbPress.GetLBText(i, sP);
sP.TrimRight(_T("MPa"));
if (fabs(dPress - _tstof(sP)) < 0.001)
{
nIndex = i;
break;
}
}
if (nIndex != -1)
{
m_cmbPress.SetCurSel(nIndex);
m_iPn = nIndex;
UpdateData(FALSE);
OnSelchangeComboPn();
}
}