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

599 lines
17 KiB
C++

// PipeFloorDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PipeFloorDlg.h"
#include "TDoubleLineJig.h"
#include "Twt_pump.h"
//#include <dbwall.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
void DrawFloorPipe()
{
int nOsMode=0;
xg_getvar(_T("OSMODE"), &nOsMode);
nOsMode &= ~0x4000;
nOsMode |= OS_INT|OS_NEA|OS_PER|OS_END|OS_CEN;
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
XPoint ptStart, ptEnd;
CPipeFloorDlg dlg(acedGetAcadFrame());
{
CTemporaryResourceOverride vTemp;
dlg.Create(IDD_PIPE_FLOOR, acedGetAcadFrame());
}
dlg.ShowWindow(SW_SHOW);
acedGetAcadDwgView()->SetFocus();
int iRet;
XString sKeyword;
INITGET_BEG(0, _T("S"));
iRet = ads_getpoint(NULL, _T("\n请输入起点[选取行向线(S)]:<退出>"), ptStart);
INITGET_END();
//提示用户从当前屏幕选择行向线
if(iRet == RTKWORD){
double s_angle(0);
int err_value = get_line_angle(s_angle);
if(err_value == RTNORM){
s_angle = s_angle*180/PI;
dlg.m_nAngle = s_angle;
dlg.UpdateData(FALSE);
iRet = ads_getpoint(NULL,_T("\n请输入起始点:<退出>"),ptStart);
}
}
if(iRet != RTNORM){
dlg.DestroyWindow();
return;
}
ptStart = Ucs2Wcs(ptStart);
InitLayer(_T("PIPE-地暖"));
XPushVarStr clayer(_T("CLAYER"), _T("PIPE-地暖"));
XPushVar<int> vOrthoMode(_T("ORTHOMODE"), 0); //f8
while(1){
dlg.UpdateData(TRUE);
TFloorPipeJig jig(&dlg, ptStart, ptStart, dlg.m_iLeftDist,
dlg.m_iRightDist, dlg.m_iTopDist, dlg.m_iBottomDist,
A2R(dlg.m_nAngle), dlg.m_iDirection+1, 1);
jig.SetPrompt(_T("\n请输入终点[改变进出口方向(A)]<退出>:"));
int nKeyIdx;
jig.SetKeyword(_T("A"));
int ret = jig.DoIt(&nKeyIdx);
if(ret == RTKWORD){
if(dlg.m_iDirection == 7)
dlg.m_iDirection = 0;
else
dlg.m_iDirection++;
dlg.UpdateData(FALSE);
continue;
}
else if(ret != RTNORM){
dlg.DestroyWindow();
return;
}
ptEnd = jig.GetPickPoint();
break;
}
TDbFloorPipe *pFloor = new TDbFloorPipe;
pFloor->SetParam(ptStart, ptEnd, dlg.m_iLeftDist,
dlg.m_iRightDist, dlg.m_iTopDist, dlg.m_iBottomDist,
A2R(dlg.m_nAngle), dlg.m_iDirection+1, 1);
pFloor->SetRadius(100);
AddToCurrentSpace(pFloor, Adesk::kTrue);
dlg.DestroyWindow();
}
//***************************************************************************************************
// 编辑地暖盘管
//***************************************************************************************************
int EditFloorPipe(AcDbObjectId id)
{
if(!id)
return RTERROR;
CTemporaryResourceOverride vTemp;
CPipeFloorDlg dlg;
dlg.m_bIsEditDlg = TRUE;
XPoint ptS, ptE, ptCenter;
double angle, angleDiff;
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbFloorPipe, pPipe);
if(!pPipe)
return RTERROR;
dlg.m_iLeftDist = (int)pPipe->GetPipeLeftDist();
dlg.m_iRightDist = (int)pPipe->GetPipeRightDist();
dlg.m_iTopDist = (int)pPipe->GetPipeTopDist();
dlg.m_iBottomDist = (int)pPipe->GetPipeBottomDist();
dlg.m_iDirection = pPipe->GetEntryType()-1;
dlg.m_nAngle = R2A(pPipe->GetAngle());
ptS = pPipe->GetStartPoint();
ptE = pPipe->GetEndPoint();
angle = dlg.m_nAngle;
OPENOBJ_END();
if(fabs(dlg.m_nAngle) < 0.0001)
dlg.m_nAngle = 0.0;
if(dlg.DoModal() != IDOK)
return RTNORM;
OPENOBJ_BEGIN(id, AcDb::kForWrite, TDbFloorPipe, pPipe);
if(!pPipe)
return RTERROR;
pPipe->SetPipeLeftDist(dlg.m_iLeftDist);
pPipe->SetPipeRightDist(dlg.m_iRightDist);
pPipe->SetPipeTopDist(dlg.m_iTopDist);
pPipe->SetPipeBottomDist(dlg.m_iBottomDist);
pPipe->SetEntryType(dlg.m_iDirection+1);
pPipe->SetAngle(A2R(dlg.m_nAngle));
angleDiff = dlg.m_nAngle - angle;
if(fabs(angleDiff) > 0.1)
{
angleDiff = A2R(angleDiff);
Midpoint(ptS, ptE, ptCenter);
AcGeMatrix3d mat = AcGeMatrix3d::rotation(angleDiff, AcGeVector3d(0,0,1), ptCenter);
ptS.TransformBy(mat);
ptE.TransformBy(mat);
pPipe->SetStartPoint(ptS);
pPipe->SetEndPoint(ptE);
}
OPENOBJ_END();
return RTNORM;
}
//***************************************************************************************************
// 双线盘管
//***************************************************************************************************
//道路相连时,要进行FILLET处理
void FilletNextFloorPipe(Entity ent1, Entity ent2, Entity ent3, Entity ent4, double nFilletRad)
{
XPoint ptInt;
//line1, line2是刚绘制的道路2线
XLine line1(ent1, LS_FINITE);
XLine line2(ent2, LS_FINITE);
//line3, line4是已经绘制的道路2线
XLine line3(ent3, LS_FINITE);
XLine line4(ent4, LS_FINITE);
//4条线均为 _T("LS_FINITE") 有限长, 目的是求线上交点, 而不是延长线交点
line1.SetLineFlag(1);
line2.SetLineFlag(1);
line3.SetLineFlag(1);
line4.SetLineFlag(1);
BOOL bFlag = FALSE;
BOOL bBreak = TRUE;
int iIntersecton(-1);
int ret1 = line1.Intersection(&line3, ptInt);
int ret2 = line1.Intersection(&line4, ptInt);
if(ret1 == 1 && ret2 == 0){
iIntersecton = 1;
bFlag = FALSE;
}
else if(ret1 == 0 && ret2 == 1){
iIntersecton = 2;
bFlag = TRUE;
}
else if(ret1 == 0 && ret2 == 0){
ret1 = line2.Intersection(&line3, ptInt);
ret2 = line2.Intersection(&line4, ptInt);
if(ret1 == 1 && ret2 == 0){
iIntersecton = 3;
bFlag = TRUE;
}
else if(ret1 == 0 && ret2 == 1){
iIntersecton = 4;
bFlag = FALSE;
}
else
bBreak = FALSE;//2道路宽度不等时(4根线没有交点), 不需要做FILLET处理
}
//4条线必然有2条线已经相交, 他们是一对, 另外2个是一对
if(bFlag && bBreak){
FilletEntity(ent2, ent3, nFilletRad);
FilletEntity(ent1, ent4, nFilletRad);
}
else if(!bFlag && bBreak){
FilletEntity(ent1, ent3, nFilletRad);
FilletEntity(ent2, ent4, nFilletRad);
}
}
BOOL GetFloorPipeByPoint(XPoint &pt, double &nWidth)
{
BOOL bRet(FALSE);
RBList rbMaskPipe(RTDXF0, _T("ATS_FLOORPIPE"), 8, _T("PIPE-地暖"), NULL);
PickSet ss(SS_FREE);
XPoint ptUcs = Wcs2Ucs(pt);
GetPointPickSet(ptUcs, ss, rbMaskPipe, 5);
XPoint ptAnother;
int len = ss.Length();
if(len == 1){
OPENOBJ_BEGIN(ss[0L], AcDb::kForRead, TDbFloorPipe, pPipe);
if(pPipe){
double dist = ads_distance(pt, pPipe->m_ptEntry);
if(dist < pPipe->GetPipeLeftDist()){
nWidth = pPipe->GetPipeLeftDist();
if(pPipe->GetEntryType() == 1 || pPipe->GetEntryType() == 4)
ads_polar(pPipe->m_ptEntry, 0, nWidth, ptAnother);
else if(pPipe->GetEntryType() == 2 || pPipe->GetEntryType() == 7)
ads_polar(pPipe->m_ptEntry, PI/2, nWidth, ptAnother);
else if(pPipe->GetEntryType() == 3 || pPipe->GetEntryType() == 6)
ads_polar(pPipe->m_ptEntry, PI/2*3, nWidth, ptAnother);
else if(pPipe->GetEntryType() == 5 || pPipe->GetEntryType() == 8)
ads_polar(pPipe->m_ptEntry, PI, nWidth, ptAnother);
Midpoint(pPipe->m_ptEntry, ptAnother, pt);
return TRUE;
}
}
OPENOBJ_END();
}
return bRet;
}
Entity GetFloorPipeByEndPoint(XPoint pt, XPoint &ptEnd)
{
Entity entRet;
RBList rbMaskPipe(RTDXF0, _T("LINE"), 8, _T("PIPE-地暖"), NULL);
PickSet ss(SS_FREE);
XPoint ptUcs = Wcs2Ucs(pt);
GetPointPickSet(ptUcs, ss, rbMaskPipe, 5);
if(ss.Length() == 1){
entRet = ss[0L];
XPoint p1, p2;
XLine line(entRet);
line.GetStartPoint(p1);
line.GetEndPoint(p2);
double n1 = ads_distance(pt, p1);
double n2 = ads_distance(pt, p2);
if(n1 < 50)
ptEnd = p1;
else if(n2 < 50)
ptEnd = p2;
else
return Entity();
}
return entRet;
}
Entity GetAnotherFloorPipeByPoint(XPoint pt, Entity entFirst)
{
if(!entFirst)
return Entity();
Entity entRet;
RBList rbMaskPipe(RTDXF0, _T("LINE"), 8, _T("PIPE-地暖"), NULL);
PickSet ss(SS_FREE);
XPoint ptUcs = Wcs2Ucs(pt);
GetPointPickSet(ptUcs, ss, rbMaskPipe, 300);
ss -= entFirst;
PickSet ssTmp(SS_FREE);
long len = ss.Length();
for(long i=0;i<len;i++){
Entity entTmp = ss[i];
XLine line1(entFirst);
XPoint ptS, ptE;
line1.GetStartPoint(ptS);
line1.GetEndPoint(ptE);
double ang1 = ads_angle(ptS, ptE);
if(ang1 > (PI*2 - 0.0001))
ang1 -= PI*2;
XLine line2(entTmp);
line2.GetStartPoint(ptS);
line2.GetEndPoint(ptE);
double ang2 = ads_angle(ptS, ptE);
if(ang2 > (PI*2 - 0.0001))
ang2 -= PI*2;
double n = ang1 - ang2;
if(fabs(n) > 0.01 && fabs(n - PI) > 0.01)
continue;
ssTmp += entTmp;
}
if(ssTmp.Length() == 1)
entRet = ssTmp[0L];
return entRet;
}
void DoubleFloorLine()
{
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);
XPoint ptStart, ptEnd, ptOld;
if(ads_getpoint(NULL, _T("\n请点取管线起点<退出>"), ptStart) != RTNORM){
return;
}
ptStart = Ucs2Wcs(ptStart);
double nWidth = 2 * DocGetPScale();
Entity ent1, ent2, entOld1, entOld2, entOldOld1, entOldOld2;
//接散双线
entOld1 = GetFloorPipeByEndPoint(ptStart, ptEnd);
if(!!entOld1)
entOld2 = GetAnotherFloorPipeByPoint(ptStart, entOld1);
if(!!entOld1 && !!entOld2){
XPoint p1;
XLine line(entOld2);
ptEnd.Project(&line, p1);
Midpoint(p1, ptEnd, ptStart);
nWidth = ads_distance(ptEnd, p1);
}
else//接上华盘管
GetFloorPipeByPoint(ptStart, nWidth);
double nFilletRad = nWidth/2;
InitLayer(_T("PIPE-地暖"));
XPushVarStr clayer(_T("CLAYER"), _T("PIPE-地暖"));
while(1){
TDoubleLineJig jig(ptStart, nWidth);
jig.SetPrompt(_T("\n请输入终点[双管间距(W)]/倒角半径(R)/回退(U)]<退出>:"));
jig.SetKeyword(_T("W R U"));
int nKeyIndex;
int ret = jig.DoIt(&nKeyIndex);
if(ret == RTKWORD){
CString csPrompt;
if(nKeyIndex == 0){
csPrompt.Format(_T("\n请输入双管间距<%.0f>:"), nWidth);
ads_getdist(ptStart, csPrompt, &nWidth);
}
else if(nKeyIndex == 1){
csPrompt.Format(_T("\n请输入盘管倒角半径<%.0f>:"), nFilletRad);
ads_getdist(ptStart, csPrompt, &nFilletRad);
}
else if(nKeyIndex == 2){
if(ptStart == ptOld)
continue;
ads_command(RTSTR, _T("UNDO"), RTSTR, _T("BACK"), RTNONE);
entOld1 = entOldOld1;
entOld2 = entOldOld2;
ptStart = ptOld;
}
continue;
}
else if(ret != RTNORM){
break;
}
ads_command(RTSTR, _T(".UNDO"), RTSTR, _T("MARK"), RTNONE); // Make a undo mark
ptEnd = jig.GetPickPoint();
double nAng = ads_angle(ptStart, ptEnd);
XPoint ptS1, ptS2, ptE1, ptE2;
ads_polar(ptStart, nAng + PI/2, nWidth/2, ptS1);
ads_polar(ptStart, nAng - PI/2, nWidth/2, ptS2);
ads_polar(ptEnd, nAng + PI/2, nWidth/2, ptE1);
ads_polar(ptEnd, nAng - PI/2, nWidth/2, ptE2);
DrawLine(ptS1, ptE1);
ent1.GetLast();
DrawLine(ptS2, ptE2);
ent2.GetLast();
if(!!entOld1 && !!entOld2)
FilletNextFloorPipe(entOld1, entOld2, ent1, ent2, nFilletRad);
entOldOld1 = entOld1;
entOldOld2 = entOld2;
entOld1 = ent1;
entOld2 = ent2;
ptOld = ptStart;
ptStart = ptEnd;
}
ads_command(RTNONE);
}
//***************************************************************************************************
// 选择盘管
//***************************************************************************************************
void GetConnectLineByLine(Entity ent, Entity &entRet1, Entity &entRet2)
{
if(!(ent.Is(_T("LINE")) || ent.Is(_T("ARC"))))
return;
XPoint ptStart, ptEnd;
RBList rbMask = ads_buildlist( -4, _T("<or"),
-4, _T("<and"), RTDXF0, _T("LINE"), 8, _T("PIPE-地暖*"), -4, _T("and>"),
-4, _T("<and"), RTDXF0, _T("ARC"), 8, _T("PIPE-地暖*"), -4, _T("and>"),
-4, _T("or>"), NULL);
if(ent.Is(_T("LINE"))){
XLine line(ent);
line.GetStartPoint(ptStart);
line.GetEndPoint(ptEnd);
}
else if(ent.Is(_T("ARC"))){
XArc arc(ent);
arc.GetStartPoint(ptStart);
arc.GetEndPoint(ptEnd);
}
if(!!ptStart){
PickSet ss(SS_FREE);
GetPointPickSet(Wcs2Ucs(ptStart), ss, rbMask, 10);
ss -= ent;
if(ss.Length() == 2){
Entity ent1 = ss[0L];
Entity ent2 = ss[1L];
if(ent1.Is(_T("LINE"))){
XLine lineTmp(ent1, 1);
if(lineTmp.GetLength() < 0.1)
ss -= ent1;
}
if(ent2.Is(_T("LINE"))){
XLine lineTmp(ent2, 1);
if(lineTmp.GetLength() < 0.1)
ss -= ent2;
}
}
long len = ss.Length();
if(len == 1)
entRet1 = ss[0L];
}
if(!!ptEnd){
PickSet ss(SS_FREE);
GetPointPickSet(Wcs2Ucs(ptEnd), ss, rbMask, 10);
ss -= ent;
if(ss.Length() == 2){
Entity ent1 = ss[0L];
Entity ent2 = ss[1L];
if(ent1.Is(_T("LINE"))){
XLine lineTmp(ent1, 1);
if(lineTmp.GetLength() < 0.1)
ss -= ent1;
}
if(ent2.Is(_T("LINE"))){
XLine lineTmp(ent2, 1);
if(lineTmp.GetLength() < 0.1)
ss -= ent2;
}
}
long len = ss.Length();
if(len == 1)
entRet2 = ss[0L];
}
}
BOOL SearchFloorPipeSys(Entity ent, Entity entFront, PickSet &ssAll)
{
Entity ent1, ent2, entThis;
GetConnectLineByLine(ent, ent1, ent2);
if(ent1 == entFront)
entThis = ent2;
else
entThis = ent1;
if(!entThis)
return FALSE;
ssAll += entThis;
SearchFloorPipeSys(entThis, ent, ssAll);
return TRUE;
}
void SelectFloorPipe()
{
RBList rbMask = ads_buildlist( -4, _T("<or"),
-4, _T("<and"), RTDXF0, _T("LINE"), 8, _T("PIPE-地暖*"), -4, _T("and>"),
-4, _T("<and"), RTDXF0, _T("ARC"), 8, _T("PIPE-地暖*"), -4, _T("and>"),
-4, _T("or>"), NULL);
Entity entPipe, ent1, ent2;
if(SelectEntity(_T("\n请选择一根盘管:<退出>"), entPipe, rbMask) != RTNORM)
return;
PickSet ss(SS_FREE);
GetConnectLineByLine(entPipe, ent1, ent2);
SearchFloorPipeSys(entPipe, ent1, ss);
SearchFloorPipeSys(entPipe, ent2, ss);
long len = ss.Length();
double nLength(0);
for(long i=0;i<len;i++){
Entity entTmp = ss[i];
XCurveSegment seg(entTmp);
nLength += seg.GetLength();
}
ss+=entPipe;
adsout << _T("\n盘管总长度为:") << nLength/1000 << _T("米");
ads_sssetfirst(ss, ss);
}
/////////////////////////////////////////////////////////////////////////////
// CPipeFloorDlg dialog
IMPLEMENT_DYNAMIC(CPipeFloorDlg, CModelessDialog)
CPipeFloorDlg::CPipeFloorDlg(CWnd* pParent /*=NULL*/)
: CModelessDialog(CPipeFloorDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPipeFloorDlg)
m_nAngle = 0.0;
m_iDirection = 0;
m_iLeftDist = 200;
m_iRightDist = 200;
m_iTopDist = 200;
m_iBottomDist = 200;
//}}AFX_DATA_INIT
m_bIsEditDlg = FALSE;
}
void CPipeFloorDlg::DoDataExchange(CDataExchange* pDX)
{
CModelessDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPipeFloorDlg)
DDX_Text(pDX, IDC_EDIT_ANGLE, m_nAngle);
DDX_CBIndex(pDX, IDC_COMBO_DIRCTION, m_iDirection);
DDX_Text(pDX, IDC_EDIT_LEFTDIST, m_iLeftDist);
DDX_Text(pDX, IDC_EDIT_RIGHTDIST, m_iRightDist);
DDX_Text(pDX, IDC_EDIT_TOPDIST, m_iTopDist);
DDX_Text(pDX, IDC_EDIT_BOTTOMDIST, m_iBottomDist);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPipeFloorDlg, CModelessDialog)
//{{AFX_MSG_MAP(CPipeFloorDlg)
ON_WM_PAINT()
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPipeFloorDlg message handlers
BOOL CPipeFloorDlg::OnInitDialog()
{
CModelessDialog::OnInitDialog();
if(!m_bIsEditDlg){
CRect rect;
this->GetWindowRect(&rect);
rect.bottom -= 30;
this->MoveWindow(&rect);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPipeFloorDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
OpenSlide();
}
void CPipeFloorDlg::OnClose()
{
CModelessDialog::OnClose();
acedPostCommand(_T("\33\33"));
}
void CPipeFloorDlg::OpenSlide()
{
UpdateData();
CWnd *pWnd = GetDlgItem(IDC_STATIC_PREVIEW);
DrawSlide(_T("Twt(FLOOR)"), pWnd);
// if(m_iPlace == 0)
// DrawSlide(_T("THvac(FLOOR1)"), pWnd);
// else if(m_iPlace == 1)
// DrawSlide(_T("THvac(FLOOR2)"), pWnd);
// else if(m_iPlace == 2)
// DrawSlide(_T("THvac(FLOOR3)"), pWnd);
// else if(m_iPlace == 3)
// DrawSlide(_T("THvac(FLOOR4)"), pWnd);
// else if(m_iPlace == 4)
// DrawSlide(_T("THvac(FLOOR5)"), pWnd);
// else if(m_iPlace == 5)
// DrawSlide(_T("THvac(FLOOR6)"), pWnd);
}