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

1704 lines
52 KiB
C++

// SprinklerByLineDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DbEquipment.h"
#include "DbPipe.h"
#include "XRect.h"
#include "layerdef.h"
#include "SprinklerByLineDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern AcDbObjectId InitLayer(const TCHAR *szLayer, AcDbDatabase *pDb = NULL);
//**************************************************************************
// 直线喷头
//**************************************************************************
void SprinklerByLine()
{
CString csDwb = g_csDwbPath + _T("TwtSys");
XString xsTmp, xsTmp2, xsTmp3, xsTmp4, xsTmp5, xsTmp6, xsTmp7, xsTmp2d, xsTmp3d;
XString xsTmp8, xsTmp9, xsTmp10;//zxl 2011.12.19 add 增加水喷雾喷头
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000125"), xsTmp) != RTNORM)
return;
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000128"), xsTmp2) != RTNORM)
return;
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000131"), xsTmp6) != RTNORM)
return;
if (GlobalFunc::LoadDwbBlock(csDwb, _T("00000283"), XString()) != RTNORM) // cet 2011.2.28 add 剖切时需要的图块
{
return;
}
if (GlobalFunc::LoadDwbBlock(csDwb, _T("00000529"), xsTmp8) != RTNORM)//zxl 2011.12.19 add 增加水喷雾喷头
{
return;
}
if (GlobalFunc::LoadDwbBlock(csDwb, _T("00000540"), xsTmp9) != RTNORM) // cet 2013.1.5 add 直立型水幕
{
return;
}
if (GlobalFunc::LoadDwbBlock(csDwb, _T("00000541"), xsTmp10) != RTNORM) // cet 2013.1.5 add 下垂型水幕
{
return;
}
if(g_Option::instance().g_bBlk3D){
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000365"), xsTmp3) != RTNORM)
return;
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000366"), xsTmp4) != RTNORM)
return;
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000367"), xsTmp5) != RTNORM)
return;
if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000417"), xsTmp7) != RTNORM)
return;
}
//XString xsTmp, xsTmp2, xsTmp3, xsTmp4, xsTmp5;
//if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000125"), xsTmp) != RTNORM)
// return;
//if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000128"), xsTmp2) != RTNORM)
// return;
//if(g_Option::instance().g_bBlk3D){
// if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000365"), xsTmp3) != RTNORM)
// return;
// if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000366"), xsTmp4) != RTNORM)
// return;
// if(GlobalFunc::LoadDwbBlock(csDwb, _T("00000367"), xsTmp5) != RTNORM)
// return;
//}
int nOsMode=0;
xg_getvar(_T("OSMODE"), &nOsMode);
nOsMode &= ~0x4000;
nOsMode |= OS_INT|OS_NEA;
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
CSprinklerByLineDlg dlg(acedGetAcadFrame());
{
CTemporaryResourceOverride vTemp;
dlg.Create(IDD_SPRINKLER_LINE, acedGetAcadFrame());
dlg.ShowWindow(SW_SHOW);
acedGetAcadDwgView()->SetFocus();
}
CString m_csSysBlk1 = _T("TWTSYS(00000283)");
CString m_csSysBlk2 = _T("TWTSYS(00000130)");
CString m_csSysBlk3 = _T("TWTSYS(00000530)");//水喷雾 系统 zxl 2011.12.19 add
XPoint ptStart, ptEnd;
int iRet;
iRet = ads_getpoint(NULL, _T("请输入起始点<退出>:"), ptStart);
ptStart = GlobalFunc::Ucs2Wcs(ptStart);
if(iRet != RTNORM ){
dlg.DestroyWindow();
return;
}
if(dlg.m_bDrawCir)
g_Option::instance().adsout << _T("\n外圆表示喷淋头保护范围");
TSprinklerJig jig(&dlg, ptStart);
jig.SetPrompt(_T("\n请输入终点<退出>:"));
int nKeyIdx;
if(jig.DoIt(&nKeyIdx) != RTNORM){
dlg.DestroyWindow();
return;
}
ptEnd = jig.GetPickPoint();
XPushVar<int> vOsMode2(_T("OSMODE"), 0);
int len = jig.m_pDrawEnt->m_lstPt.Length();
GlobalFunc::InitPipeLayer(LAY_PIPE_SPRINKLE);
InitLayer(LAY_EQUIP_SPRINKLE);
double nAng(0);
if(len > 1){
XPoint pt3 = *jig.m_pDrawEnt->m_lstPt[0];
XPoint pt4 = *jig.m_pDrawEnt->m_lstPt[1];
nAng = ads_angle(pt3, pt4);
}
if(dlg.m_iType == 0){
xsTmp2d = xsTmp;
xsTmp3d = xsTmp4;
}
else if(dlg.m_iType == 1){
xsTmp2d = xsTmp;
xsTmp3d = xsTmp3;
}
else if(dlg.m_iType == 2){
xsTmp2d = xsTmp2;
xsTmp3d = xsTmp5;
}
else if(dlg.m_iType == 3){
xsTmp2d = xsTmp6;
xsTmp3d = xsTmp7;
}
else if (dlg.m_iType == 4)//zxl 2011.12.19 add 增加水喷雾喷头
{
xsTmp2d = xsTmp8;
xsTmp3d = xsTmp3;
}
else if (dlg.m_iType == 5) // cet 2013.1.5 add 直立型水幕
{
xsTmp2d = xsTmp9;
xsTmp3d = xsTmp4;
}
else if (dlg.m_iType == 6) // cet 2013.1.5 add 下垂型水幕
{
xsTmp2d = xsTmp10;
xsTmp3d = xsTmp3;
}
for(int i=0;i<len;i++){
XPoint pt = *jig.m_pDrawEnt->m_lstPt[i];
CDbEquipment *pEquip = new CDbEquipment;
pEquip->SetBlock2d(GlobalFunc::GetBlkIdByName(xsTmp2d));
pEquip->SetBlock3d(GlobalFunc::GetBlkIdByName(xsTmp3d));
//pEquip->SetSysBlock(m_csSysBlk1);
if(dlg.m_iType == 1){
pEquip->SetHidePipe(FALSE);//下喷
pEquip->SetPipeLength(-250);
pEquip->SetSysBlock(m_csSysBlk1);
}
else if(dlg.m_iType == 3){
pEquip->SetHidePipe(TRUE);//侧喷
pEquip->SetPipeLength(-250);
pEquip->SetSysBlock(m_csSysBlk2);
}
else if (dlg.m_iType == 4)//zxl 2011.12.19 add 增加水喷雾喷头
{
pEquip->SetHidePipe(TRUE);
pEquip->SetPipeLength(-250);
pEquip->SetSysBlock(m_csSysBlk3);
}
else if (dlg.m_iType == 5) // cet 2013.1.5 add 增加直立型水幕
{
pEquip->SetHidePipe(TRUE);
pEquip->SetPipeLength(250);
pEquip->SetSysBlock(_T("TWTSYS(00000542)"));
}
else if (dlg.m_iType == 6) // cet 2013.1.5 add 增加下垂型水幕
{
pEquip->SetHidePipe(TRUE);
pEquip->SetPipeLength(-250);
pEquip->SetSysBlock(_T("TWTSYS(00000542)"));
}
else
{
pEquip->SetHidePipe(TRUE);
pEquip->SetPipeLength(250);
pEquip->SetSysBlock(m_csSysBlk1);
}
// if(dlg.m_iType == 2){
// pEquip->SetBlock2d(GlobalFunc::GetBlkIdByName(xsTmp2));
// pEquip->SetHidePipe(TRUE);
// pEquip->SetPipeLength(250);
// pEquip->SetBlock3d(GlobalFunc::GetBlkIdByName(xsTmp5));
// }
// else{
// pEquip->SetBlock2d(GlobalFunc::GetBlkIdByName(xsTmp));
// if(dlg.m_iType == 0){ //上喷
// pEquip->SetHidePipe(TRUE);
// pEquip->SetPipeLength(250);
// pEquip->SetBlock3d(GlobalFunc::GetBlkIdByName(xsTmp4));
// }
// else if(dlg.m_iType == 1){
// pEquip->SetHidePipe(FALSE);
// pEquip->SetBlock3d(GlobalFunc::GetBlkIdByName(xsTmp3));
// pEquip->SetPipeLength(-250);
// }
// }
pt.z = dlg.m_nEle * 1000;
pEquip->SetLocation(pt);
pEquip->SetAngle(nAng);
pEquip->SetNumber(_T("CIRCLE-1"));
pEquip->SetScale(g_Option::instance().g_nSprinklerRadius);
pEquip->setLayer(LAY_EQUIP_SPRINKLE);
pEquip->setColor(AcCmColor()); //随层
GlobalFunc::AddToCurrentSpace(pEquip, Adesk::kTrue);
Entity entLast;
entLast.GetLast();
GlobalFunc::WriteXdata(entLast, _T("HYDRANT_RADIUS"), dlg.m_csRadius);
if(i == 0)
continue;
XPoint p1, p2;
p1 = *jig.m_pDrawEnt->m_lstPt[i-1];
p2 = pt;
p1.z = dlg.m_nEle * 1000;
p2.z = dlg.m_nEle * 1000;
CDbPipe *pPipe = new CDbPipe;
pPipe->SetPipeWeight(g_Option::instance().g_nPipeWidth[8]);
pPipe->SetStartPoint(p1);
pPipe->SetEndPoint(p2);
pPipe->setLayer(LAY_PIPE_SPRINKLE);
pPipe->setLinetype(GlobalFunc::GetPipeWireLayLineType(LAY_PIPE_SPRINKLE));
pPipe->SetDnDiameter(g_Option::instance().g_iDefaultPipeDn);
pPipe->SetModelType(TPipeSys::kModel);
pPipe->SetSysType(TPipeSys::kSprinkle);
pPipe->SetRadius(g_Option::instance().g_nPipeRadius[8]);
pPipe->setColor(AcCmColor()); //随层
GlobalFunc::AddToCurrentSpace(pPipe, Adesk::kTrue);
}
if(dlg.m_iMode == 1)
dlg.m_iOldDist = dlg.m_iDist;
dlg.DestroyWindow();
SHads_command(RTNONE);
}
/////////////////////////////////////////////////////////////////////////////
// CSprinklerByLineDlg dialog
IMPLEMENT_DYNAMIC(CSprinklerByLineDlg, CDialog)
int CSprinklerByLineDlg::m_iNum = 5;
int CSprinklerByLineDlg::m_iDist = 3600;
int CSprinklerByLineDlg::m_iMode = 0;
int CSprinklerByLineDlg::m_iOldDist = 3600;
int CSprinklerByLineDlg::m_iType = 1;
double CSprinklerByLineDlg::m_nEle = 0;
CSprinklerByLineDlg::CSprinklerByLineDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSprinklerByLineDlg::IDD, pParent),m_spinDist(100)
{
//{{AFX_DATA_INIT(CSprinklerByLineDlg)
m_bDrawCir = FALSE;
m_csRadius = _T("2.12");
m_iDist2Wall = 1400;
//}}AFX_DATA_INIT
}
void CSprinklerByLineDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSprinklerByLineDlg)
DDX_Control(pDX, IDC_EDIT_DIST2, m_editDist2Wall);
DDX_Control(pDX, IDC_EDIT_DIST, m_editDist);
DDX_Control(pDX, IDC_EDIT_ELE, m_editEle);
DDX_Control(pDX, IDC_SPIN_DIST, m_spinDist);
DDX_Check(pDX, IDC_CHECK_DRAW, m_bDrawCir);
DDX_CBString(pDX, IDC_COMBO_RADIUS, m_csRadius);
DDX_Text(pDX, IDC_EDIT_DIST2, m_iDist2Wall);
DDX_Text(pDX, IDC_EDIT_DIST, m_iDist);
DDX_Radio(pDX, IDC_RADIO_POS1, m_iType);
DDX_Text(pDX, IDC_EDIT_ELE, m_nEle);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSprinklerByLineDlg, CDialog)
//{{AFX_MSG_MAP(CSprinklerByLineDlg)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_CHECK_DRAW, OnCheckDraw)
ON_EN_KILLFOCUS(IDC_EDIT_DIST, OnKillfocusEditDist)
ON_EN_KILLFOCUS(IDC_EDIT_DIST2, OnKillfocusEditDist2)
ON_EN_KILLFOCUS(IDC_EDIT_ELE, OnKillfocusEditEle)
ON_CBN_KILLFOCUS(IDC_COMBO_RADIUS, OnKillfocusComboRadius)
ON_MESSAGE(WM_ACAD_KEEPFOCUS, onAcadKeepFocus)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSprinklerByLineDlg message handlers
BOOL CSprinklerByLineDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_editEle.SetDataType(CRealEdit::eReal);
m_editDist2Wall.SetDataType(CRealEdit::eReal);
m_editDist.SetDataType(CRealEdit::eReal);
m_spinDist.SetRange(0,10000);
OnCheckDraw();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSprinklerByLineDlg::OnClose()
{
CDialog::OnClose();
acedPostCommand(_T("\33\33"));
}
void CSprinklerByLineDlg::OnCheckDraw()
{
UpdateData();
CWnd *pWnd1 = GetDlgItem(IDC_COMBO_RADIUS);
pWnd1->EnableWindow(m_bDrawCir);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
// 角度为负数时构造RECT不正确,这里修改一下 zxl 2014.01.08 add
void ModifyRect(XRect &rect)
{
XPoint ptS = rect.m_ptS, ptE = rect.m_ptE;
double dAng = rect.m_nAngle;
double dAngle = ads_angle(ptS, ptE);
dAng = dAng / 180 * PI;
double dAngDst = dAng;
while (fabs(dAngDst) > PI / 2)
{
if (dAngDst > 0)
{
dAngDst -= PI / 2;
}
else
{
dAngDst += PI / 2;
}
}
if (dAngle > (PI / 2 + dAngDst + GlobalFunc::Wcs2Ucs(0.0)) && dAngle < (2 * PI + GlobalFunc::Wcs2Ucs(0.0)) && dAng < GlobalFunc::Wcs2Ucs(0.0))
{
AcGeVector3d vtY(0, -1, 0);
vtY = vtY.rotateBy(dAng + GlobalFunc::Wcs2Ucs(0.0), AcGeVector3d::kZAxis);
AcDbLine line(ptS, ptS + vtY * 100);
line.setStartPoint(ptS);
line.setEndPoint(ptS + vtY * 100);
XPoint pt1, pt2, ptMid;
line.getClosestPointTo(ptE, pt1, Adesk::kTrue);
Midpoint(ptS, ptE, ptMid);
AcGeVector3d vt = ptMid - pt1;
pt2 = ptMid + vt;
rect.upRight = rect.lowRight;
rect.lowRight = pt2;
rect.lowLeft = rect.upLeft;
rect.upLeft = pt1;
rect.nWidth = ptS.Distance2d(pt2);
rect.nHeight = ptS.Distance2d(pt1);
rect.x_angle = ads_angle(ptS, pt2);
rect.y_angle = ads_angle(ptS, pt1);
}
}
CSprinklerPreview::CSprinklerPreview(CSprinklerByLineDlg *dlg, XPoint ptStart, XPoint ptEnd)
{
// m_dDist = 0;
m_ptStart = ptStart;
m_ptEnd = ptEnd;
m_pDrawLine = NULL;
m_pDrawRect = NULL;
m_pdlg = dlg;
m_pdlg2 = NULL;
m_pdlg3 = NULL;
m_pdlg4 = NULL;
m_pdlg5 = NULL;
m_pdlg6 = NULL;
}
CSprinklerPreview::CSprinklerPreview(CSprinklerByArcDlg *dlg, XPoint ptStart, XPoint ptEnd)
{
// m_dDist = 0;
m_ptStart = ptStart;
m_ptMid = ptEnd;
m_pDrawLine = NULL;
m_pDrawRect = NULL;
m_pdlg6 = dlg;
m_pdlg = NULL;
m_pdlg2 = NULL;
m_pdlg3 = NULL;
m_pdlg4 = NULL;
m_pdlg5 = NULL;
}
CSprinklerPreview::CSprinklerPreview(CSprinklerByRectDlg *dlg, XPoint ptStart, XPoint ptEnd)
{
// m_dDist = 0;
m_ptStart = ptStart;
m_ptEnd = ptEnd;
m_pDrawLine = NULL;
m_pDrawRect = NULL;
m_pdlg2 = dlg;
m_pdlg4 = NULL;
m_pdlg3 = NULL;
m_pdlg = NULL;
m_pdlg5 = NULL;
m_pdlg6 = NULL;
}
CSprinklerPreview::CSprinklerPreview(CSprinkIsometryDlg *dlg, XPoint ptStart, XPoint ptEnd, double nXDist, double nYDist)
{
// m_dDist = 0;
m_ptStart = ptStart;
m_ptEnd = ptEnd;
m_pDrawLine = NULL;
m_pDrawRect = NULL;
m_pdlg3 = dlg;
m_pdlg2 = NULL;
m_pdlg4 = NULL;
m_pdlg5 = NULL;
m_pdlg6 = NULL;
m_pdlg = NULL;
m_nXDist = nXDist;
m_nYDist = nYDist;
}
CSprinklerPreview::CSprinklerPreview(CSprinklerByFreeDlg *dlg, XPoint ptStart, XPoint ptEnd)
{
// m_dDist = 0;
m_ptStart = ptStart;
m_ptEnd = ptEnd;
m_pDrawLine = NULL;
m_pDrawRect = NULL;
m_pdlg3 = NULL;
m_pdlg2 = NULL;
m_pdlg5 = NULL;
m_pdlg6 = NULL;
m_pdlg = NULL;
m_pdlg4 = dlg;
m_bNeedText = TRUE;
}
CSprinklerPreview::CSprinklerPreview(CSprinklerBySectionDlg *dlg, XPoint pt1, XPoint pt2, XPoint pt3)
{
m_pDrawLine = NULL;
m_pDrawRect = NULL;
m_ptStart = pt1;
m_ptEnd = pt2;
m_ptMid = pt3;
m_pdlg5 = dlg;
m_pdlg3 = NULL;
m_pdlg2 = NULL;
m_pdlg6 = NULL;
m_pdlg4 = NULL;
m_pdlg = NULL;
// m_dDist = 0;
}
CSprinklerPreview::CSprinklerPreview(XPoint ptStart, XPoint ptEnd)
{
m_ptStart = ptStart;
m_ptEnd = ptEnd;
m_pDrawLine = NULL;
m_pDrawRect = NULL;
m_pdlg3 = NULL;
m_pdlg2 = NULL;
m_pdlg = NULL;
m_pdlg4 = NULL;
m_pdlg5 = NULL;
m_pdlg6 = NULL;
m_bNeedText = TRUE;
// m_dDist = 0;
}
CSprinklerPreview::~CSprinklerPreview()
{
if(m_pDrawLine)
delete m_pDrawLine;
if(m_pDrawRect)
delete m_pDrawRect;
}
//等距布置
BOOL GetIsometryInsPt(XPoint ptS, XPoint ptE, double nXDist, double nYDist, double nAngle, double row_dist, double col_dist, XPointList &lstInsPt, int &iRow, int &iCol)
{
// cet 2011.5.10 add 将ptS, ptE点z值设为0,防止标高不一致导致rect构造错误
ptS.z = 0;
ptE.z = 0;
XRect rect(ptS, ptE, nAngle);
ModifyRect(rect);// 矩形构造不正确,重新构造 zxl 2014.01.08 add
ads_polar(ptS, rect.x_angle, nXDist, ptS);
ads_polar(ptS, rect.y_angle, nYDist, ptS);
XPoint ptTmp(ptS), ptNew(ptS), ptYNew;
lstInsPt.Reset();
lstInsPt.NewAppend(ptS);//第一列
iRow = 1;
ads_polar(ptS, rect.y_angle, col_dist, ptYNew);
double nDist = ads_distance(ptS, ptYNew);
while(nDist < (rect.nHeight - nYDist)){
XPoint ptTmp2 = ptYNew;
lstInsPt.NewAppend(ptYNew);
ads_polar(ptTmp2, rect.y_angle, col_dist, ptYNew);
nDist = ads_distance(ptTmp, ptYNew);
}
ads_polar(ptTmp, rect.x_angle, row_dist, ptNew);
nDist = ads_distance(ptTmp, ptNew);
while(nDist < (rect.nWidth - nXDist)){
iRow ++;
ptTmp = ptNew;
lstInsPt.NewAppend(ptNew);
ads_polar(ptTmp, rect.y_angle, col_dist, ptYNew);
nDist = ads_distance(ptTmp, ptYNew);
iCol = 1;
while(nDist < (rect.nHeight-nYDist)){
iCol ++;
XPoint ptTmp2 = ptYNew;
lstInsPt.NewAppend(ptYNew);
ads_polar(ptTmp2, rect.y_angle, col_dist, ptYNew);
nDist = ads_distance(ptTmp, ptYNew);
}
ads_polar(ptTmp, rect.x_angle, row_dist, ptNew);
nDist = ads_distance(ptS, ptNew);
}
return TRUE;
}
// cet 2011.4.15 add
double GetArcLenByChord(XArc &arc, double nChord)
{
double nRadius = arc.GetRadius();
double nTmp = nChord / (2.0*nRadius);
nTmp = asin(nTmp) * 2.0 * nRadius;
return nTmp;
}
// cet 2011.4.15 add
// 将一段线均分N个点, 但间距是50倍数(喷淋系统) 喷头间距模数:g_iSprinklerDistMod
void GetPointListSprinkler(XCurveSegment seg, int iNum, XPointList &lstPt, double nShortDist, double nDist2Wall)
{
// 增加对喷头间距模数的控制
int nMod1 = 100, nMod2 = 25;
if (g_Option::instance().g_iSprinklerDistMod == 100)
{
nMod1 = 1000;
nMod2 = 50;
}
if(seg.Is(CURVE_LINE)){
XLine line = seg.GetLine();
double angLine = ads_angle(line.StartPoint(), line.EndPoint());
double distLine = line.GetLength() / iNum / 2; // 喷头间距的一半
if(distLine < nShortDist && nShortDist > 0) // 喷头间距不小于最小间距nShortDist*2
distLine = nShortDist;
// 调整喷头间距使其长度是模数的整数倍
double nTmp1 = distLine / nMod1;
double nTmp2 = distLine - ((int)nTmp1)*nMod1;
double nTmp3 = nTmp2 / nMod2 + 0.5;
int iTmp1 = (int)nTmp3;
distLine = (int)nTmp1 * nMod1 + iTmp1 * nMod2;
int n = 1;
XPoint ptTemp;
double nFisrtDist = (line.GetLength() - distLine * (iNum-1) * 2) / 2; // 第一点距墙的距离
while(nFisrtDist > nDist2Wall){ // 距墙的距离大于最小距墙距离时,调整喷头间距值
distLine += nMod2; // 喷头间距的一半调整时相应增幅为模数的一半,以便满足喷头间距为模数的整数倍
nFisrtDist = nFisrtDist - iNum * nMod2; // 所有喷头间距调整后,第一点距墙的距离
}
// zxl 2013.08.27 add 距墙的距离小于2.4米时喷头居中布置
if(line.GetLength() < 2400 && iNum == 1)
nFisrtDist = line.GetLength() / 2;
// 调整第一点距墙距离,使其是模数的整数倍
nTmp1 = nFisrtDist / nMod1;
nTmp2 = nFisrtDist - ((int)nTmp1)*nMod1;
nTmp3 = nTmp2 / (nMod2 * 2) + 0.5;
iTmp1 = (int)nTmp3;
nFisrtDist = (int)nTmp1 * nMod1 + iTmp1 * (nMod2 * 2);
ads_polar(line.StartPoint(), angLine, nFisrtDist, ptTemp);
lstPt.NewAppend(ptTemp);
while(n < iNum){
ads_polar(line.StartPoint(), angLine, (2*n)*distLine + nFisrtDist, ptTemp);
lstPt.NewAppend(ptTemp);
n++;
}
}
else if(seg.Is(CURVE_ARC)){
XArc arc = seg.GetArc();
nShortDist = nShortDist*2;
XPoint ptStart, ptEnd;
arc.GetStartPoint(ptStart);
arc.GetEndPoint(ptEnd);
double distLine = arc.GetLength() / iNum; // 喷头间距
// 调整喷头间距使其长度是模数的整数倍
double nTmp1 = distLine / nMod1;
double nTmp2 = distLine - ((int)nTmp1)*nMod1;
double nTmp3 = nTmp2 / (nMod2 * 2) + 0.5;
int iTmp1 = (int)nTmp3;
distLine = (int)nTmp1 * nMod1 + iTmp1 * (nMod2 * 2);
// 当距墙距离大于最小值时,调整喷头间距并且喷头间距必须是模数的整数倍
int n = 1;
XPoint ptTemp;
double nFisrtDist = (arc.GetLength() - distLine * (iNum-1)) / 2; // 第一点距墙距离
while(nFisrtDist > nDist2Wall){
distLine += nMod2 * 2; // 保证喷头间距是模数的整数倍
nFisrtDist = nFisrtDist - iNum*nMod2;
}
// 调整第一点距墙距离,使其是模数的整数倍
nTmp1 = nFisrtDist / nMod1;
nTmp2 = nFisrtDist - ((int)nTmp1)*nMod1;
nTmp3 = nTmp2 / (nMod2 * 2) + 0.5;
iTmp1 = (int)nTmp3;
nFisrtDist = (int)nTmp1 * nMod1 + iTmp1 * (nMod2 * 2);
nFisrtDist = GetArcLenByChord(arc, nFisrtDist);
AcDbArc *pArc=new AcDbArc;
pArc->setCenter(arc.GetCenterPt());
pArc->setRadius(arc.GetRadius());
pArc->setStartAngle(arc.GetStarAngle());
pArc->setEndAngle(arc.GetEndAngle());
pArc->getPointAtDist(nFisrtDist, ptTemp);
lstPt.NewAppend(ptTemp);
distLine = GetArcLenByChord(arc, distLine);
if(distLine > 0.001){
while(distLine > 0.001 && n < iNum){
pArc->getPointAtDist(n*distLine + nFisrtDist, ptTemp);
lstPt.NewAppend(ptTemp);
n++;
}
}
delete pArc;
}
}
//矩形布置
BOOL GetRectInsPt(XPoint ptS, XPoint ptE, double nAngle, int row_num, int col_num, XPointList &lstInsPt, double nShortDist, double nDist2Wall)
{
lstInsPt.Reset();
XRect rect(ptS, ptE, nAngle);
ModifyRect(rect);// 矩形构造不正确,重新构造 zxl 2014.01.08 add
XLine line(rect.upLeft, rect.lowLeft, 1);
XCurveSegment seg;
XPointList lstPt;
seg = line;
// cet 2011.4.15 add 增加对喷头间距模数的控制
//GlobalFunc::GetPointList(seg, row_num, lstPt, nShortDist, nDist2Wall);
GetPointListSprinkler(seg, row_num, lstPt, nShortDist, nDist2Wall);
if(lstPt.Length() != row_num)
return FALSE;
for(int i=0;i<row_num;i++){
XPoint pt1, pt2;
pt1 = *lstPt[i];
ads_polar(pt1, rect.x_angle, rect.nWidth, pt2);
XLine lineTmp(pt1, pt2, 1);
XPointList lstPt2;
XCurveSegment seg2;
seg2 = lineTmp;
// cet 2011.4.15 add 增加对喷头间距模数的控制
//GlobalFunc::GetPointList(seg2, col_num, lstPt2, nShortDist, nDist2Wall);
GetPointListSprinkler(seg2, col_num, lstPt2, nShortDist, nDist2Wall);
if(lstPt2.Length() != col_num)
break;
int iCount = 0;
for(int j=0;j<col_num;j++){
iCount ++;
XPoint ptIns;
ptIns = *lstPt2[j];
lstInsPt.NewAppend(ptIns);
}
}
return TRUE;
}
//矩形布置,并多返回行节点序列,列节点序列,预演用
BOOL GetRectInsPt(XPoint ptS, XPoint ptE, double nAngle, int row_num, int col_num, XPointList &lstInsPt, double nShortDist, double nDist2Wall, XPointList &lstPtRow, XPointList &lstPtCol)
{
lstInsPt.Reset();
XRect rect(ptS, ptE, nAngle);
ModifyRect(rect);// 矩形构造不正确,重新构造 zxl 2014.01.08 add
if(rect.nHeight > 1000000 || rect.nWidth > 1000000)
{
double dd = 0;
}
XLine line(rect.upLeft, rect.lowLeft, 1);
XCurveSegment seg;
XPointList lstPt;
seg = line;
// cet 2011.4.15 add 增加对喷头间距模数的控制
//GlobalFunc::GetPointList(seg, row_num, lstPt, nShortDist, nDist2Wall);
GetPointListSprinkler(seg, row_num, lstPt, nShortDist, nDist2Wall);
lstPtRow.NewAppend(rect.upLeft);
// cet 2011.4.15 add 增加对喷头间距模数的控制
//GlobalFunc::GetPointList(seg, row_num, lstPtRow, nShortDist, nDist2Wall);
GetPointListSprinkler(seg, row_num, lstPtRow, nShortDist, nDist2Wall);
lstPtRow.NewAppend(rect.lowLeft);
if(lstPt.Length() != row_num)
return FALSE;
for(int i=0;i<row_num;i++){
XPoint pt1, pt2;
pt1 = *lstPt[i];
ads_polar(pt1, rect.x_angle, rect.nWidth, pt2);
XLine lineTmp(pt1, pt2, 1);
XPointList lstPt2;
XCurveSegment seg2;
seg2 = lineTmp;
// cet 2011.4.15 add 增加对喷头间距模数的控制
//GlobalFunc::GetPointList(seg2, col_num, lstPt2, nShortDist, nDist2Wall);
GetPointListSprinkler(seg2, col_num, lstPt2, nShortDist, nDist2Wall);
if(i == 0 ){
lstPtCol.NewAppend(pt1);
// cet 2011.4.15 add 增加对喷头间距模数的控制
//GlobalFunc::GetPointList(seg2, col_num, lstPtCol, nShortDist, nDist2Wall);
GetPointListSprinkler(seg2, col_num, lstPtCol, nShortDist, nDist2Wall);
lstPtCol.NewAppend(pt2);
}
if(lstPt2.Length() != col_num)
break;
int iCount = 0;
for(int j=0;j<col_num;j++){
iCount ++;
XPoint ptIns;
ptIns = *lstPt2[j];
lstInsPt.NewAppend(ptIns);
}
}
return TRUE;
}
//将一段线按喷淋规矩均分N个点
void GetPtPointList(XLine &line, int iNum, XPointList &lstPt, BOOL bIsReverse = FALSE)
{
if(iNum < 2)
return;
double angLine = ads_angle(line.GetStartPoint(), line.GetEndPoint());
XPoint ptTemp, ptStart;
ptStart = line.StartPoint();
if(bIsReverse){
angLine = ads_angle(line.GetEndPoint(), line.GetStartPoint());
ptStart = line.EndPoint();
}
double distLine = line.GetLength() / (iNum-0.5);
ads_polar(ptStart, angLine, distLine/4, ptTemp);
lstPt.NewAppend(ptTemp);
int n = 1;
while(n < iNum){
ads_polar(ptStart, angLine, n*distLine, ptTemp);
lstPt.NewAppend(ptTemp);
n++;
}
}
//按喷淋规矩, 菱形布置
BOOL GetDiamondInsPt(XPoint ptS, XPoint ptE, double nAngle, int row_num, int col_num, XPointList &lstInsPt, BOOL bIsColPipe = TRUE)
{
lstInsPt.Reset();
XRect rect(ptS, ptE, nAngle);
ModifyRect(rect);// 矩形构造不正确,重新构造 zxl 2014.01.08 add
int count1(0), count2(0);
XCurveSegment seg;
if(bIsColPipe){ //列接管
XLine line(rect.upLeft, rect.upRight, 1);
seg = line;
count1 = col_num;
count2 = row_num;
}
else{
XLine line(rect.upLeft, rect.lowLeft, 1);
seg = line;
count1 = row_num;
count2 = col_num;
}
XPointList lstPt;
GlobalFunc::GetPointList(seg, count1, lstPt);
if(lstPt.Length() != count1)
return FALSE;
for(int i=0;i<count1;i++){
XPoint pt1, pt2;
pt1 = *lstPt[i];
if(bIsColPipe) //列接管
ads_polar(pt1, rect.y_angle, rect.nHeight, pt2);
else
ads_polar(pt1, rect.x_angle, rect.nWidth, pt2);
XLine lineTmp(pt1, pt2, 1);
XPointList lstPt2;
GetPtPointList(lineTmp, count2, lstPt2, i % 2);
if(lstPt2.Length() != count2)
return FALSE;
for(int j=0;j<count2;j++){
XPoint ptIns;
ptIns = *lstPt2[j];
lstInsPt.NewAppend(ptIns);
}
}
return TRUE;
}
//已知大弧,求布置最外圈的弧
void GetOutArc(XArc &outArc, double nRadius, XArc &retArc, int row_num, double nShortDist, double nDist2Wall)
{
XCurveSegment seg;
XPointList lstPt3;
XPoint ptStart, ptEnd, ptTmp;
outArc.GetStartPoint(ptStart);
outArc.GetEndPoint(ptEnd);
ads_polar(ptStart, outArc.GetStarAngle(), -nRadius, ptTmp);
seg = XLine(ptStart, ptTmp);
// cet 2011.4.15 add 增加对喷头间距模数的控制
//GlobalFunc::GetPointList(seg, row_num, lstPt3, nShortDist, nDist2Wall);
GetPointListSprinkler(seg, row_num, lstPt3, nShortDist, nDist2Wall);
if(lstPt3.Length() < 1)
return;
ptTmp = *lstPt3[0];
double nDist = ads_distance(ptTmp, outArc.GetCenterPt());
XArc arc2(outArc.GetCenterPt(), nDist, outArc.GetStarAngle(), outArc.GetEndAngle());
retArc = arc2;
}
BOOL GetSectorInsPt(XArc &arc, double nRadius, int row_num, int col_num, XPointList &lstInsPt, double nShortDist, double nDist2Wall, XPointList &lstPtCol, XPointList &lstPtRow)
{
if(row_num < 0 || col_num < 0)
return TRUE;
lstInsPt.Reset();
lstPtCol.Reset();
XArc arc2;
GetOutArc(arc, nRadius, arc2, row_num, nShortDist, nDist2Wall);
XCurveSegment seg;
seg = arc2;
XPointList lstPt;
// cet 2011.4.15 add 增加对喷头间距模数的控制
//GlobalFunc::GetPointList(seg, col_num, lstPt, nShortDist, nDist2Wall);
GetPointListSprinkler(seg, col_num, lstPt, nShortDist, nDist2Wall);
if(lstPt.Length() != col_num)
return TRUE;
lstPtCol.NewAppend(seg.StartPoint());
// cet 2011.4.15 add 增加对喷头间距模数的控制
//GlobalFunc::GetPointList(seg, col_num, lstPtCol, nShortDist, nDist2Wall);
GetPointListSprinkler(seg, col_num, lstPtCol, nShortDist, nDist2Wall);
lstPtCol.NewAppend(seg.EndPoint());
for(int i=1;i<=col_num;i++){
XPoint pt1, pt2;
pt1 = *lstPt[i-1];
double angle = ads_angle(arc.GetCenterPt(), pt1);
ads_polar(arc.GetCenterPt(), angle, arc.GetRadius(), pt1);
ads_polar(arc.GetCenterPt(), angle, arc.GetRadius()-nRadius, pt2);
XLine line(pt1, pt2);
XCurveSegment seg2;
seg2 = line;
XPointList lstPt2;
// cet 2011.4.15 add 增加对喷头间距模数的控制
//GlobalFunc::GetPointList(seg2, row_num, lstPt2, nShortDist, nDist2Wall);
GetPointListSprinkler(seg2, row_num, lstPt2, nShortDist, nDist2Wall);
if(i == 1 ){
lstPtRow.NewAppend(seg2.StartPoint());
// cet 2011.4.15 add 增加对喷头间距模数的控制
//GlobalFunc::GetPointList(seg2, row_num, lstPtRow, nShortDist, nDist2Wall);
GetPointListSprinkler(seg2, row_num, lstPtRow, nShortDist, nDist2Wall);
lstPtRow.NewAppend(seg2.EndPoint());
}
if(lstPt2.Length() != row_num)
break;
int iCount = 0;
for(int j=0;j<lstPt2.Length();j++){
iCount ++;
XPoint ptIns;
ptIns = *lstPt2[j];
lstInsPt.NewAppend(ptIns);
}
}
return TRUE;
}
int GetCurvePartNum(XCurveSegment seg, int iDist, double nDist2Wall)
{
double nShortDist(2400);
if(iDist < 2400)
iDist = 2400;
double dLength = seg.GetLength();
int iNum = (int)(seg.GetLength() / iDist);
double dNum = seg.GetLength() / iDist;
if(dNum - iNum > 0)
iNum ++;
/* cet 2011.5.110 modify 返回值需随模数值变化而变化
if(seg.Is(CURVE_LINE)){
XLine line = seg.GetLine();
double angLine = ads_angle(line.GetStartPoint(), line.GetEndPoint());
double distLine = line.GetLength() / iNum;
if(distLine < nShortDist)
distLine = nShortDist;
double nTmp1 = distLine / 100;
double nTmp2 = distLine - ((int)nTmp1)*100;
double nTmp3 = nTmp2 / 50 + 0.5;
int iTmp1 = (int)nTmp3;
distLine = (int)nTmp1 * 100 + iTmp1 * 50;
int n = 1;
XPoint ptTemp;
double nFisrtDist = (line.GetLength() - distLine * (iNum-1)) / 2;
while(nFisrtDist > nDist2Wall){
distLine += 50;
nFisrtDist = nFisrtDist - iNum*25;
if(distLine > iDist){
iNum ++;
break;
}
}
}
*/
// 增加对喷头间距模数的控制
int nMod1 = 100, nMod2 = 50;
if (g_Option::instance().g_iSprinklerDistMod == 100)
{
nMod1 = 1000;
nMod2 = 100;
}
if (seg.Is(CURVE_LINE))
{
XLine line = seg.GetLine();
double angLine = ads_angle(line.GetStartPoint(), line.GetEndPoint());
double distLine = line.GetLength() / iNum;
if(distLine < nShortDist)
distLine = nShortDist;
double nTmp1 = distLine / nMod1;
double nTmp2 = distLine - ((int)nTmp1)*nMod1;
double nTmp3 = nTmp2 / nMod2 + 0.5;
int iTmp1 = (int)nTmp3;
distLine = (int)nTmp1 * nMod1 + iTmp1 * nMod2;
int n = 1;
XPoint ptTemp;
double nFisrtDist = (line.GetLength() - distLine * (iNum-1)) / 2;
while(nFisrtDist > nDist2Wall)
{
distLine += nMod2;
nFisrtDist = nFisrtDist - iNum*(nMod2*0.5);
if(distLine > iDist)
{
iNum ++;
break;
}
}
}
// if(seg.Length() / iNum < 2400) sr 2009-4-14 删除 长3800,需要布置2列
// iNum --;
if(seg.GetLength() < 200) //规范规定,喷头距墙至少100 sr 2009-4-14
iNum = 0;
return iNum;
}
Adesk::Boolean CSprinklerPreview::subWorldDraw(AcGiWorldDraw *pWd)
{
double nSprinklerRadius(1);
// if(g_bEquipByScale)
nSprinklerRadius = g_Option::instance().g_nSprinklerRadius *GlobalFunc::DocGetPScale()/100;
// else
// nSprinklerRadius = g_nSprinklerRadius;
if(m_pdlg != NULL){ //两点均布
if(m_pDrawLine)
delete m_pDrawLine;
XLine line(m_ptStart, m_ptEnd, 1);
XCurveSegment seg;
m_lstPt.Reset();
seg = line;
m_pdlg->UpdateData(TRUE);
if(!pWd->isDragging()){
m_pDrawLine = new AcDbLine(m_ptStart, m_ptEnd);
m_pDrawLine->worldDraw(pWd);
}
double nShortDist(1200);
double nDist2Wall = m_pdlg->m_iDist2Wall-20;
int iDist = m_pdlg->m_iDist;
int num = GetCurvePartNum(seg, iDist, nDist2Wall);
if(num < 1)
return Adesk::kTrue;;
// cet 2011.4.15 add 增加对喷头间距模数的控制
//GlobalFunc::GetPointList(seg, num, m_lstPt, nShortDist, nDist2Wall);
GetPointListSprinkler(seg, num, m_lstPt, nShortDist, nDist2Wall);
//显示间距
CString csRowDist;
for(int j=-1;j<m_lstPt.Length();j++){
XPoint ptTmp1, ptTmp2;
if(j == -1)
ptTmp1 = seg.StartPoint();
else
ptTmp1 = *m_lstPt[j];
if(j == m_lstPt.Length()-1)
ptTmp2 = seg.EndPoint();
else
ptTmp2 = *m_lstPt[j+1];
double nDist3 = ads_distance(ptTmp1, ptTmp2);
XLine line(ptTmp1, ptTmp2);
line.MidPoint(ptTmp1);
csRowDist.Format(_T("%.0f"), nDist3);
AcDbText text;
text.setRotation(GlobalFunc::Radian2Angle(GlobalFunc::Ucs2Wcs(0.0)));
text.setHeight(350);
text.setTextString(csRowDist);
text.setTextStyle(GlobalFunc::GetTextStyleId(_T("STANDARD")));
text.setPosition(ptTmp1);
text.worldDraw(pWd);
}
int len = m_lstPt.Length();
double nProtect = _tstof(m_pdlg->m_csRadius)*1000;
for(int i=0;i<len;i++){
XPoint pt = *m_lstPt[i];
AcDbCircle cir(pt, AcGeVector3d::kZAxis, nSprinklerRadius);
cir.worldDraw(pWd);
if(m_pdlg->m_bDrawCir){//绘制保护范围
AcDbCircle cir2(pt, AcGeVector3d::kZAxis, nProtect);
cir2.worldDraw(pWd);
}
}
}
else if(m_pdlg6 != NULL){//弧线布置
XArc arc(m_ptStart, m_ptEnd, m_ptMid);
XCurveSegment seg;
m_lstPt.Reset();
seg = arc;
m_pdlg6->UpdateData(TRUE);
AcDbArc arc1(arc.GetCenterPt(), arc.GetRadius(), arc.GetStarAngle(), arc.GetEndAngle());
arc1.worldDraw(pWd);
if(m_pdlg6->m_iMode == 1){ //均布
GlobalFunc::GetPointList(seg, m_pdlg6->m_iNum, m_lstPt, m_pdlg6->m_iDist2Wall);
}
else if(m_pdlg6->m_iMode == 0){//等距
GlobalFunc::GetPointList(seg, m_pdlg6->m_dDist, m_lstPt);
}
int len = m_lstPt.Length();
double nProtect = _tstof(m_pdlg6->m_csRadius)*1000;
for(int i=0;i<len;i++){
XPoint pt = *m_lstPt[i];
AcDbCircle cir(pt, AcGeVector3d::kZAxis, nSprinklerRadius);
cir.worldDraw(pWd);
if(m_pdlg6->m_bDrawCir){//绘制保护范围
AcDbCircle cir2(pt, AcGeVector3d::kZAxis, nProtect);
cir2.worldDraw(pWd);
}
}
}
else if(m_pdlg2 != NULL){//矩形布置或菱形布置
double nDist1(0), nDist2(0);
if(m_pDrawRect)
delete m_pDrawRect;
m_lstPt.Reset();
m_pdlg2->UpdateData(TRUE);
double dAngle = m_pdlg2->m_nAngle + GlobalFunc::Radian2Angle(GlobalFunc::Ucs2Wcs(0.0));
m_ptStart.z = 0;
m_ptEnd.z =0;
XRect rect(m_ptStart, m_ptEnd, dAngle);
ModifyRect(rect);// 矩形构造不正确,重新构造 zxl 2014.01.08 add
// m_ptStart.z = 0; cet 2011.5.10 modify 移到rect前避免起始点标高不一致导致构造的rect错误
// m_ptEnd.z =0;
XPoint p1 = rect.lowLeft;
XPoint p2 = rect.lowRight;
XPoly2D poly;
rect.AsPoly2D(poly);
m_pDrawRect = new AcDbPolyline;
GlobalFunc::PolyConvert(poly, *m_pDrawRect);
m_pDrawRect->worldDraw(pWd);
int iRow(0), iCol(0);
double nShortDist(0);
double nDist2Wall = m_pdlg2->m_nDist2Wall-0;//sr 2009-3-12 把-20 改为 -0 ,不记得当初为什么-20
if(m_pdlg2->m_iType == 0){
iRow = m_pdlg2->m_iRow;
iCol = m_pdlg2->m_iCol;
}
else{ //根据最大间距(对话框),最小间距2.4米确定行列数
nShortDist = m_pdlg2->m_dMinDist / 2;
int iColDist = m_pdlg2->m_iCol;
int iRowDist = m_pdlg2->m_iRow;
XLine line1(rect.lowLeft, rect.lowRight);
XCurveSegment seg1;
seg1 = line1;
iCol = GetCurvePartNum(seg1, iColDist, nDist2Wall);
XLine line2(rect.upLeft, rect.lowLeft);
XCurveSegment seg2;
seg2 = line2;
iRow = GetCurvePartNum(seg2, iRowDist, nDist2Wall);
if(iRow > 1000)
{
iRow = 1;
}
if(iCol > 1000)
iCol = 1;
// 无法划分时直接返回 cet 2012.12.19 add
if (iCol == 0 || iRow == 0)
{
return Adesk::kFalse;
}
}
XPointList lstPt, lstPt2;
if(m_pdlg2->m_iMode == 0)
{
GetRectInsPt(m_ptStart, m_ptEnd, m_pdlg2->m_nAngle + GlobalFunc::Radian2Angle(GlobalFunc::Ucs2Wcs(0.0)), iRow, iCol, m_lstPt, nShortDist, nDist2Wall, lstPt, lstPt2);
// cet 2012.12.19 add 按行列间距布置时,考虑距墙最小间距
int nLen = lstPt2.Length();
// if (m_pdlg2->m_iType == 1 && nLen >= 3) cet 2013.4.15 modify 控制是否需要考虑距墙最小间距, x轴y轴方向均考虑
int nLen2 = lstPt.Length();
if (m_pdlg2->m_bMinDistToWall && m_pdlg2->m_iType == 1 && nLen >= 3)
{
double dDist1 = lstPt2[0]->Distance2d(*lstPt2[1]);
double dDist2 = lstPt2[nLen - 1]->Distance2d(*lstPt2[nLen - 2]);
// cet 2013.4.15 add 考虑列距墙距离
double dDist3 = lstPt[0]->Distance2d(*lstPt[1]);
double dDist4 = lstPt[nLen2 - 1]->Distance2d(*lstPt[nLen2 - 2]);
double dDist = m_pdlg2->m_dMinDistToWall;
double dTol = 0.001; // 误差
if (GlobalFunc::DocGetCurMeterUnitDraw())
{
dDist *= 0.001;
}
// 小于最小距墙间距 cet 2013.4.15 modify 考虑列距墙距离
if (dDist1 + dTol < dDist || dDist2 + dTol < dDist || dDist3 + dTol < dDist || dDist4 + dTol < dDist)
{
return Adesk::kFalse;
}
}
}
else
GetDiamondInsPt(m_ptStart, m_ptEnd, m_pdlg2->m_nAngle + GlobalFunc::Radian2Angle(GlobalFunc::Ucs2Wcs(0.0)), iRow, iCol, m_lstPt, m_pdlg2->m_iConPipe);
if(m_pdlg2->m_iRow > 1 && m_pdlg2->m_iCol > 1 && m_lstPt.Length() > 3){
if(m_pdlg2->m_iMode == 0){
nDist1 = rect.nWidth / iCol;
nDist2 = rect.nHeight / iRow;
}
else{
if(m_pdlg2->m_iConPipe == 0){ //行接管
nDist1 = rect.nWidth / (iCol - 0.5);
nDist2 = rect.nHeight / iRow;
}
else if(m_pdlg2->m_iConPipe == 1){//列接管
nDist1 = rect.nWidth / iCol;
nDist2 = rect.nHeight / (iRow - 0.5);
}
}
}
//显示间距
int len = m_lstPt.Length();
CString csRowDist;
double nDist4(0);
for(int j=0;j<lstPt.Length()-1;j++){
XPoint ptTmp1 = *lstPt[j];
XPoint ptTmp2 = *lstPt[j+1];
double nDist3 = ads_distance(ptTmp1, ptTmp2);
if(j == 0)
nDist4 = nDist3;
ads_polar(ptTmp1, m_pdlg2->m_nAngle + GlobalFunc::Radian2Angle(GlobalFunc::Ucs2Wcs(0.0)) + rect.y_angle, nDist3/2, ptTmp1);
csRowDist.Format(_T("%.0f"), nDist3);
AcDbText text;
text.setRotation(m_pdlg2->m_nAngle + GlobalFunc::Radian2Angle(GlobalFunc::Ucs2Wcs(0.0)));
text.setHeight(350);
text.setTextString(csRowDist);
text.setTextStyle(GlobalFunc::GetTextStyleId(_T("STANDARD")));
text.setPosition(ptTmp1);
text.worldDraw(pWd);
}
for(j=0;j<lstPt2.Length()-1;j++){
XPoint ptTmp1 = *lstPt2[j];
XPoint ptTmp2 = *lstPt2[j+1];
double nDist3 = ads_distance(ptTmp1, ptTmp2);
ads_polar(ptTmp1, m_pdlg2->m_nAngle + GlobalFunc::Radian2Angle(GlobalFunc::Ucs2Wcs(0.0)) + rect.x_angle, nDist3/2, ptTmp1);
ads_polar(ptTmp1, rect.y_angle, -nDist4, ptTmp1);
csRowDist.Format(_T("%.0f"), nDist3);
AcDbText text;
text.setRotation(m_pdlg2->m_nAngle + GlobalFunc::Radian2Angle(GlobalFunc::Ucs2Wcs(0.0)));
text.setHeight(350);
text.setTextString(csRowDist);
text.setTextStyle(GlobalFunc::GetTextStyleId(_T("STANDARD")));
text.setPosition(ptTmp1);
text.worldDraw(pWd);
}
//显示喷头&保护圆
double nProtect = _tstof(m_pdlg2->m_csRadius) * 1000;
for(int i=0;i<len;i++){
XPoint pt = *m_lstPt[i];
AcDbCircle cir(pt, AcGeVector3d::kZAxis, nSprinklerRadius);
cir.worldDraw(pWd);
if(m_pdlg2->m_bDrawCir){//绘制保护范围
AcDbCircle cir2(pt, AcGeVector3d::kZAxis, nProtect);
cir2.worldDraw(pWd);
}
}
}
else if(m_pdlg3 != NULL){//等距布置喷头
m_pdlg3->UpdateData(TRUE);
int iRow, iCol;
GetIsometryInsPt(m_ptStart, m_ptEnd, m_pdlg3->m_nRow2Wall, m_pdlg3->m_nCol2Wall, m_pdlg3->m_nAngle + GlobalFunc::Radian2Angle(GlobalFunc::Ucs2Wcs(0.0)), m_pdlg3->m_nXDist, m_pdlg3->m_nYDist, m_lstPt, iRow, iCol);
int len = m_lstPt.Length();
double nProtect = _tstof(m_pdlg3->m_csRadius) * 1000;
for(int i=0;i<len;i++){
XPoint pt = *m_lstPt[i];
AcDbCircle cir(pt, AcGeVector3d::kZAxis, nSprinklerRadius);
cir.worldDraw(pWd);
if(m_pdlg3->m_bDrawCir){
AcDbCircle cir2(pt, AcGeVector3d::kZAxis, nProtect);
cir2.worldDraw(pWd);
}
}
}
else if(m_pdlg5 != NULL){//扇形布置喷头
XArc arc(m_ptStart, m_ptMid, m_ptEnd);
AcDbArc arc2(arc.GetCenterPt(), arc.GetRadius(), arc.GetStarAngle(), arc.GetEndAngle());
arc2.worldDraw(pWd);
XPoint pt1, pt2, pt3, pt4;
ads_polar(arc.GetCenterPt(), arc.GetStarAngle(), arc.GetRadius() - m_nRadius, pt1);
ads_polar(arc.GetCenterPt(), arc.GetEndAngle(), arc.GetRadius() - m_nRadius, pt2);
ads_polar(arc.GetCenterPt(), arc.GetStarAngle(), arc.GetRadius(), pt3);
ads_polar(arc.GetCenterPt(), arc.GetEndAngle(), arc.GetRadius(), pt4);
if(arc.GetRadius() > m_nRadius){
AcDbArc arc3(arc.GetCenterPt(), arc.GetRadius() - m_nRadius, arc.GetStarAngle(), arc.GetEndAngle());
arc3.worldDraw(pWd);
AcDbLine l1(pt3, pt1);
l1.worldDraw(pWd);
AcDbLine l2(pt4, pt2);
l2.worldDraw(pWd);
}
else{
AcDbLine l1(pt3, arc.GetCenterPt());
l1.worldDraw(pWd);
AcDbLine l2(pt4, arc.GetCenterPt());
l2.worldDraw(pWd);
}
m_pdlg5->UpdateData(TRUE);
//确定行、列数
int iRow(0), iCol(0);
double nShortDist(1200);
double nDist2Wall = m_pdlg5->m_nDist2Wall-20;
iRow = (int)(m_nRadius / m_pdlg5->m_iRow);
if(m_nRadius / m_pdlg5->m_iRow - iRow > 0)
iRow ++;
double nTmp = m_nRadius / iRow / 2;
XArc arc4(arc.GetCenterPt(), arc.GetRadius() - nTmp, arc.GetStarAngle(), arc.GetEndAngle());
iCol = (int)(arc4.GetLength() / m_pdlg5->m_iCol);
if(arc4.GetLength() / m_pdlg5->m_iCol - iCol > 0)
iCol ++;
double nDist1 = arc4.GetLength() / iCol;
double nDist2 = m_nRadius / iRow;
// zxl 2013.08.26 modify
// if(nDist1 < 2400)//如果小于2.4米,调整行列数,首先满足规范最小间距
// iCol --;
// if(nDist2 < 2400)
// iRow --;
if (nDist1 < 200)
{
iCol = 0;//规范规定,喷头距墙至少100
m_lstPt.Reset();
}
if (nDist2 < 200)
{
iRow = 0;
m_lstPt.Reset();
}
if(iCol < 1 || iRow < 1 )
return Adesk::kTrue;
XPointList lstPt2;
GetSectorInsPt(arc, m_nRadius, iRow, iCol, m_lstPt, nShortDist, nDist2Wall , m_pdlg5->m_lstPt, lstPt2);
m_pdlg5->m_iRowNum = iRow;
m_pdlg5->m_iColNum = iCol;
m_pdlg5->m_nRadius = m_nRadius;
// cet 2011.5.25 add 获得标注点
m_pdlg5->m_lstColPt = m_pdlg5->m_lstPt;
m_pdlg5->m_lstRowPt = lstPt2;
//显示间距
int len = m_lstPt.Length();
CString csRowDist;
double nDist4(0);
for(int j=0;j<m_pdlg5->m_lstPt.Length()-1;j++){
XPoint ptTmp1 = *m_pdlg5->m_lstPt[j];
XPoint ptTmp2 = *m_pdlg5->m_lstPt[j+1];
double nDist3 = ads_distance(ptTmp1, ptTmp2);
XLine line(ptTmp1, ptTmp2);
line.MidPoint(ptTmp1);
csRowDist.Format(_T("%.0f"), nDist3);
AcDbText text;
text.setRotation(GlobalFunc::Radian2Angle(GlobalFunc::Ucs2Wcs(0.0)));
text.setHeight(350);
text.setTextString(csRowDist);
text.setTextStyle(GlobalFunc::GetTextStyleId(_T("STANDARD")));
text.setPosition(ptTmp1);
text.worldDraw(pWd);
}
for(j=0;j<lstPt2.Length()-1;j++){
XPoint ptTmp1 = *lstPt2[j];
XPoint ptTmp2 = *lstPt2[j+1];
double nDist3 = ads_distance(ptTmp1, ptTmp2);
XLine line(ptTmp1, ptTmp2);
line.MidPoint(ptTmp1);
csRowDist.Format(_T("%.0f"), nDist3);
AcDbText text;
text.setRotation(GlobalFunc::Radian2Angle(GlobalFunc::Ucs2Wcs(0.0)));
text.setHeight(350);
text.setTextString(csRowDist);
text.setTextStyle(GlobalFunc::GetTextStyleId(_T("STANDARD")));
text.setPosition(ptTmp1);
text.worldDraw(pWd);
}
len = m_lstPt.Length();
double nProtect = _tstof(m_pdlg5->m_csRadius) * 1000;
for(int i=0;i<len;i++){
XPoint pt = *m_lstPt[i];
AcDbCircle cir(pt, AcGeVector3d::kZAxis, nSprinklerRadius);
cir.worldDraw(pWd);
if(m_pdlg5->m_bDrawCir){
AcDbCircle cir2(pt, AcGeVector3d::kZAxis, nProtect);
cir2.worldDraw(pWd);
}
}
}
else{
// if(m_dDist > 0){//两点定距
// if(m_pDrawLine)
// delete m_pDrawLine;
// XLine line(m_ptStart, m_ptEnd, 1);
// XCurveSegment seg;
// m_lstPt.Reset();
// seg = line;
// if(!pWd->isDragging()){
// m_pDrawLine = new AcDbLine(m_ptStart, m_ptEnd);
// m_pDrawLine->worldDraw(pWd);
// }
// GlobalFunc::GetPointList(seg, m_dDist, m_lstPt);
// int len = m_lstPt.Length();
//
// for(int i=0;i<len;i++){
// XPoint pt = *m_lstPt[i];
// AcDbCircle cir(pt, AcGeVector3d::kZAxis, nSprinklerRadius);
// cir.worldDraw(pWd);
// }
// }
// else{//任意布置
XPoint pt = m_ptEnd;
AcDbCircle cir(pt, AcGeVector3d::kZAxis, nSprinklerRadius);
cir.worldDraw(pWd);
if(m_pdlg4 != NULL && m_pdlg4->m_bDrawCir){//绘制保护范围
double nProtect = _tstof(m_pdlg4->m_csRadius) * 1000;
AcDbCircle cir2(pt, AcGeVector3d::kZAxis, nProtect);
cir2.worldDraw(pWd);
}
double nDist = ads_distance(m_ptStart, m_ptEnd);
double nAng = ads_angle(m_ptStart, m_ptEnd);
XPoint ptText;
if (nAng > PI/2 && nAng <= PI+PI/2)
ads_polar(m_ptStart, nAng, nDist/2+300, ptText);
else
ads_polar(m_ptStart, nAng, nDist/2-300, ptText);
ads_polar(ptText, nAng+PI/2, 100, ptText);
if (nAng > PI/2 && nAng <= PI+PI/2) {
ads_polar(ptText, nAng-PI/2, 100*2, ptText);
nAng += PI;
}
if(m_bNeedText){
CString csDist;
csDist.Format(_T("%.0f"), nDist);
AcDbText text;
text.setRotation(nAng);
text.setHeight(3.5*GlobalFunc::DocGetPScale());
text.setTextString(csDist);
text.setTextStyle(GlobalFunc::GetTextStyleId(_T("STANDARD")));
text.setPosition(ptText);
text.setAlignmentPoint(ptText);
text.worldDraw(pWd);
}
// }
}
return Adesk::kTrue;
}
TSprinklerJig::TSprinklerJig(XPoint pt1)
{
m_ptStart = pt1;
m_ptEnd = pt1;
m_iPipeType = 0;
m_nDist = 0;
m_nLockAng =-1;
m_pDrawEnt = new CSprinklerPreview(m_ptStart, m_ptEnd);
}
TSprinklerJig::TSprinklerJig(CSprinklerByLineDlg *dlg, XPoint pt1)
{
m_ptStart = pt1;
m_ptEnd = pt1;
m_nDist = 0;
m_nLockAng =-1;
m_pDrawEnt = new CSprinklerPreview(dlg, m_ptStart, m_ptEnd);
}
TSprinklerJig::TSprinklerJig(CSprinklerByArcDlg *dlg, XPoint pt1, XPoint pt2)
{
m_ptStart = pt1;
m_ptEnd = pt2;
m_nDist = 0;
m_nLockAng =-1;
m_pDrawEnt = new CSprinklerPreview(dlg, m_ptStart, m_ptEnd);
}
TSprinklerJig::TSprinklerJig(CSprinklerByFreeDlg *dlg, XPoint pt1)
{
m_ptStart = pt1;
m_ptEnd = pt1;
m_nDist = 0;
m_nLockAng =-1;
m_pDrawEnt = new CSprinklerPreview(dlg, m_ptStart, m_ptEnd);
}
TSprinklerJig::TSprinklerJig(CSprinklerBySectionDlg *dlg, XPoint pt1, XPoint pt2, XPoint pt3)
{
m_ptStart = pt1;
m_ptEnd = pt2;
m_nDist = 0;
m_ptMid = pt3;
m_pDrawEnt = new CSprinklerPreview(dlg, m_ptStart, m_ptEnd, m_ptMid);
}
TSprinklerJig::TSprinklerJig(CSprinklerByRectDlg *dlg, XPoint pt1)
{
m_ptStart = pt1;
m_ptEnd = pt1;
m_nDist = 0;
m_nLockAng =-1;
m_pDrawEnt = new CSprinklerPreview(dlg, m_ptStart, m_ptEnd);
}
TSprinklerJig::TSprinklerJig(CSprinkIsometryDlg *dlg, XPoint pt1, double nXDist, double nYDist)
{
m_ptStart = pt1;
m_ptEnd = pt1;
m_nDist = 0;
m_nLockAng = -1;
m_pDrawEnt = new CSprinklerPreview(dlg, m_ptStart, m_ptEnd, nXDist, nYDist);
}
TSprinklerJig::~TSprinklerJig()
{
if(m_pDrawEnt)
delete m_pDrawEnt;
}
void TSprinklerJig::SetStartPoint(XPoint pt)
{
m_ptStart = pt;
m_pDrawEnt->m_ptStart = m_ptStart;
}
void TSprinklerJig::SetDist(double dDist)
{
m_nDist = dDist;
// if(dDist < 0){//两点均布
// m_pDrawEnt->m_dDist = fabs(dDist);
// m_nDist = 0;
// }
}
AcEdJig::DragStatus
TSprinklerJig::GetPoint(XPoint &pt)
{
if(m_nLockAng > -1)
return acquirePoint(pt);
if(!!m_ptMid){ //扇形布置
XArc arc(m_ptStart, m_ptMid, m_ptEnd);
XPoint ptBase;
arc.MidPoint(ptBase);
AcGePoint3d ptBase2 = asPnt3d(ptBase);
return acquirePoint(pt, ptBase2);
}
return acquirePoint(pt, m_ptStart.AsAcGePoint3d());
}
int TSprinklerJig::DoIt(int *keyIndex)
{
int nRet = TSymbEdJig::DoIt(keyIndex);
return nRet;
}
XPoint TSprinklerJig::GetCorrectPt()
{
XPoint ptTmp = m_ptResult;
if(m_nLockAng > -1){
// m_ptRef = XPoint();
XPoint ptTmp2 = m_ptStart;
ptTmp2.z = 0;
double nAngle = ads_angle(ptTmp2, m_ptResult) - m_nLockAng;
double nDist = ads_distance(ptTmp2, m_ptResult);
if(nAngle > PI/2 && nAngle < PI/2*3)
ads_polar(m_ptStart, m_nLockAng, -nDist, ptTmp);
else
ads_polar(m_ptStart, m_nLockAng, nDist, ptTmp);
}
return ptTmp;
}
// 更新实体数据
Adesk::Boolean TSprinklerJig::update()
{
Adesk::Boolean bRet=Adesk::kTrue;
if(!!m_ptMid){ //扇形布置
XArc arc(m_ptStart, m_ptMid, m_ptEnd);
XPoint ptBase;
arc.MidPoint(ptBase);
double nDist = ads_distance(arc.GetCenterPt(), m_ptResult);
double nDist2 = ads_distance(ptBase, m_ptResult);
if(nDist < arc.GetRadius() && nDist2 < arc.GetRadius())
nDist = arc.GetRadius() - nDist;
else
nDist = arc.GetRadius();
m_pDrawEnt->m_nRadius = nDist;
}
else{
XPoint ptTmp = m_ptResult;
if(m_nLockAng > -1){
ptTmp = GetCorrectPt();
}
if(m_nDist > 1){
double nAng = ads_angle(m_ptStart, ptTmp);
ads_polar(m_ptStart, nAng, m_nDist, ptTmp);
m_pDrawEnt->m_bNeedText = FALSE;
}
else
m_pDrawEnt->m_bNeedText = TRUE;
m_ptResult = ptTmp;
m_pDrawEnt->m_ptEnd = ptTmp;
}
return bRet;
}
AcDbEntity* TSprinklerJig::entity() const
{
return (AcDbEntity *)m_pDrawEnt;
}
void CSprinklerByLineDlg::OnKillfocusEditDist()
{
double dData = m_iDist;
CString sText;
m_editDist.GetWindowText(sText);
m_iDist = _tstof(sText);
if (m_iDist <= 0 || !GlobalFunc::IsStrAllNum(sText) || sText.Find(_T('.')) > 0)
{
m_iDist = dData;
UpdateData(FALSE);
acedGetAcadDwgView()->SetFocus();
m_editDist.SetFocus();
m_editDist.SetSel(0, -1);
}
}
void CSprinklerByLineDlg::OnKillfocusEditDist2()
{
double dData = m_iDist2Wall;
CString sText;
m_editDist2Wall.GetWindowText(sText);
m_iDist2Wall = _tstof(sText);
if (m_iDist2Wall <= 0 || !GlobalFunc::IsStrAllNum(sText) || sText.Find(_T('.')) > 0)
{
m_iDist2Wall = dData;
UpdateData(FALSE);
acedGetAcadDwgView()->SetFocus();
m_editDist2Wall.SetFocus();
m_editDist2Wall.SetSel(0, -1);
}
}
void CSprinklerByLineDlg::OnKillfocusEditEle()
{
double dData = m_nEle;
CString sText;
m_editEle.GetWindowText(sText);
m_nEle = _tstof(sText);
if (sText.IsEmpty() || !GlobalFunc::IsStrAllNum(sText))
{
m_nEle = dData;
UpdateData(FALSE);
acedGetAcadDwgView()->SetFocus();
m_editEle.SetFocus();
m_editEle.SetSel(0, -1);
}
}
void CSprinklerByLineDlg::OnKillfocusComboRadius()
{
CString csData = m_csRadius;
CEdit *pWnd = (CEdit *)GetDlgItem(IDC_COMBO_RADIUS);
if (pWnd == NULL)
{
return;
}
CString sText;
pWnd->GetWindowText(sText);
double dNewData = _tstof(sText);
if (dNewData <= 0 || !GlobalFunc::IsStrAllNum(sText))
{
m_csRadius = csData;
UpdateData(FALSE);
acedGetAcadDwgView()->SetFocus();
pWnd->SetFocus();
pWnd->SetSel(0, -1);
}
}
LONG_PTR CSprinklerByLineDlg::onAcadKeepFocus(UINT_PTR, LONG_PTR)
{
POINT pt;
::GetCursorPos(&pt);
CRect rect;
GetWindowRect(&rect);
if (!(rect.PtInRect(pt)))
{
return FALSE;
}
return TRUE;
}