823 lines
25 KiB
C++
823 lines
25 KiB
C++
/********************************************************************
|
|
created: 2004/03/18
|
|
created: 18:3:2004 11:28
|
|
filename: f:\tg_dev\telecdev\twtkernal\sprinkleredit.cpp
|
|
file path: f:\tg_dev\telecdev\twtkernal
|
|
file base: sprinkleredit
|
|
file ext: cpp
|
|
author: 沈睿
|
|
|
|
purpose: 喷头编辑文件, 主要是喷头定位
|
|
*********************************************************************/
|
|
|
|
#include "stdafx.h"
|
|
//#include <dbwall.h>
|
|
#include <TipWnd.h>
|
|
#include <DbEquipment.h>
|
|
#include <DbDimension.h>
|
|
#include "DbVPipeDim.h"
|
|
|
|
//***************************************************************************************************
|
|
// 喷头定位
|
|
//***************************************************************************************************
|
|
XCurveSegment GetBlkPickSegment(Entity entBlk, XPoint ptPick, BOOL &bTrue);
|
|
|
|
// cet 2011.9.1 add 移动立管标注
|
|
void MoveVPipeDim(const XPoint &pt, const AcGeMatrix3d &mat, double dLen)
|
|
{
|
|
PickSet ssDim(SS_FREE);
|
|
RBList rbMaskDim(RTDXF0, _T("ATS_VPIPEDIM"), NULL);
|
|
XRectAngle rect(Wcs2Ucs(pt), dLen, dLen);
|
|
ssDim.Get(_T("C"), rect.GetLowLeft(), rect.GetUpRight(), rbMaskDim);
|
|
for (long i = 0; i < ssDim.Length(); i++)
|
|
{
|
|
OPENOBJ_BEGIN(ssDim[i], AcDb::kForWrite, TDbVPipeDim , pDim);
|
|
if (pDim != NULL)
|
|
{
|
|
pDim->subTransformBy(mat);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
|
|
void DoModifySprinklerLoc(Entity entRef, Entity entSprink, XPoint ptPick)
|
|
{
|
|
RBList rbMask = ads_buildlist( -4, _T("<or"),
|
|
-4, _T("<and"), RTDXF0, _T("ATS_EQUIPMENT"), 8, LAY_EQUIP_SPRINKLE, -4, _T("and>"),
|
|
-4, _T("<and"), RTDXF0, _T("ATS_PIPE"), 8, LAY_PIPE_SPRINKLE, -4, _T("and>"),
|
|
-4, _T("or>"), NULL);
|
|
|
|
CPoint ptDwgView;
|
|
int cvport=0;
|
|
VERIFY(xg_getvar(_T("CVPORT"), &cvport)==RTNORM);
|
|
acedCoordFromWorldToPixel(cvport, ptPick, ptDwgView);
|
|
CTemporaryResourceOverride vTmp;
|
|
XPoint ptSprink;
|
|
if(entSprink.Is(_T("ATS_EQUIPMENT"))){
|
|
OPENOBJ_BEGIN(entSprink, AcDb::kForRead, TDbEquipment, pEquip);
|
|
if(pEquip){
|
|
ptSprink = pEquip->GetLocation();
|
|
ptSprink.z = 0;
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else if(entSprink.Is(_T("ATS_PIPE"))){
|
|
OPENOBJ_BEGIN(entSprink, AcDb::kForRead, TDbPipe, pPipe);
|
|
if(!pPipe || !pPipe->IsVertical()){
|
|
AfxMessageBox(_T("不是立管!"));
|
|
return;
|
|
}
|
|
ptSprink = pPipe->StartPoint();
|
|
ptSprink.z = 0;
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
CString csText;
|
|
XPoint ptInt;
|
|
double nDist(0);
|
|
|
|
if(entRef.Is(_T("LINE"))){
|
|
XLine line(entRef, 1);
|
|
ptSprink.Project(&line, ptInt);
|
|
ptInt.z = 0;
|
|
nDist = ads_distance(ptSprink, ptInt);
|
|
}
|
|
else if(entRef.Is(_T("ATS_EQUIPMENT"))){
|
|
XPoint ptNewLoc;
|
|
OPENOBJ_BEGIN(entRef, AcDb::kForRead, TDbEquipment, pEquip);
|
|
if(pEquip){
|
|
ptInt = pEquip->GetLocation();
|
|
ptInt.z = 0;
|
|
}
|
|
OPENOBJ_END();
|
|
nDist = ads_distance(ptSprink, ptInt);
|
|
}
|
|
else if(entRef.Is(_T("ATS_WALL"))){
|
|
XCurveSegment lCurve, rCurve;
|
|
OPENOBJ_BEGIN(entRef, AcDb::kForRead, TDbWall, pWall);
|
|
if(pWall) {
|
|
XPoint ptNew1, ptNew2;
|
|
pWall->GetSideCurve(lCurve, rCurve);
|
|
lCurve.ProjectToMe(ptSprink, ptNew1);
|
|
rCurve.ProjectToMe(ptSprink, ptNew2);
|
|
ptNew1.z = 0.0; // cet 2011.9.1 add
|
|
ptNew2.z = 0.0; // cet 2011.9.1 add
|
|
double nDist1 = ads_distance(ptSprink, ptNew1);
|
|
double nDist2 = ads_distance(ptSprink, ptNew2);
|
|
if(nDist1 < nDist2){
|
|
nDist = nDist1;
|
|
ptInt = ptNew1;
|
|
}
|
|
else{
|
|
nDist = nDist2;
|
|
ptInt = ptNew2;
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else if (entRef.Is(_T("INSERT")))// cet 2011.5.24 add
|
|
{
|
|
XCurveSegment SelCurve;
|
|
BOOL bIsLeft = TRUE;
|
|
SelCurve = GetBlkPickSegment(entRef, ptPick, bIsLeft);
|
|
if(!!SelCurve)
|
|
{
|
|
XPoint ptTmp;
|
|
ptSprink.Project(&SelCurve, ptTmp);
|
|
ptTmp.z = 0.0; // cet 2011.9.1 add
|
|
nDist = ads_distance(ptSprink, ptTmp);
|
|
ptInt = ptTmp;
|
|
}
|
|
else // 获取参考失败直接返回
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
else if (entRef.Is(_T("ATS_COLUMN"))) // cet 2011.8.31 add 支持柱子
|
|
{
|
|
XCurveSegment seg;
|
|
OPENOBJ_BEGIN(entRef, AcDb::kForRead, TDbColumn, pColumn);
|
|
if(pColumn != NULL)
|
|
{
|
|
XPoly2D poly;
|
|
pColumn->GetOutline(poly);
|
|
int nNum = poly.TotalSegments();
|
|
for (int i = 0; i < nNum; i++)
|
|
{
|
|
poly.Nth(i, seg);
|
|
if (seg.GetCurveType() == CURVE_LINE)
|
|
{
|
|
XLine line(seg.GetStartPoint(), seg.GetEndPoint(), 1);
|
|
if (IsPtOnLine(ptPick, line, 50))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
if (!seg) // 未找到直接返回
|
|
{
|
|
return;
|
|
}
|
|
|
|
XPoint ptTmp;
|
|
ptSprink.Project(&seg, ptTmp);
|
|
ptTmp.z = 0.0;
|
|
nDist = ads_distance(ptSprink, ptTmp);
|
|
ptInt = ptTmp;
|
|
}
|
|
else if (entRef.Is(_T("LWPOLYLINE")) || entRef.Is(_T("POLYLINE")))// zxl 2013.10.30 add 支持pline线
|
|
{
|
|
XCurveSegment seg, seg1;
|
|
XPoly2D poly(entRef);
|
|
int nNum = poly.TotalSegments();
|
|
for (int i = 0; i < nNum; i++)
|
|
{
|
|
poly.Nth(i, seg1);
|
|
if (seg1.GetCurveType() == CURVE_LINE)
|
|
{
|
|
XLine line(seg1.GetStartPoint(), seg1.GetEndPoint(), 0);
|
|
if (IsPtOnLine(ptPick, line, 50))
|
|
{
|
|
seg = seg1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!seg) // 未找到直接返回
|
|
{
|
|
return;
|
|
}
|
|
|
|
XPoint ptTmp;
|
|
ptSprink.Project(&seg, ptTmp);
|
|
ptTmp.z = 0.0;
|
|
nDist = ads_distance(ptSprink, ptTmp);
|
|
ptInt = ptTmp;
|
|
}
|
|
else
|
|
return;
|
|
csText.Format(_T("%.0f"), nDist);
|
|
XPoint ptTmp;
|
|
double nAng = ads_angle(ptSprink, ptInt);
|
|
InitSheetHook(TRUE);
|
|
CEdit *pEdit = new CEdit();
|
|
pEdit->Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP |WS_BORDER | ES_AUTOHSCROLL | ES_WANTRETURN,
|
|
CRect(ptDwgView.x, ptDwgView.y,ptDwgView.x+100,ptDwgView.y +20), acedGetAcadDwgView(), IDC_USER_SHEET_EDIT);
|
|
pEdit->SetWindowText(csText);
|
|
int lenText = csText.GetLength();
|
|
pEdit->SetSel(0, lenText);
|
|
pEdit->SetFocus();
|
|
int nKey, ret;
|
|
ads_prompt(_T("\n请在编辑框内输入新的距离<回车键完成, ESC键退出>"));
|
|
while(1){
|
|
ret = ads_getint(_T(""), &nKey);
|
|
if(ret == RTNONE && g_nKey != 0) {
|
|
if(g_nKey == VK_ESCAPE)
|
|
break;
|
|
if(g_nKey == VK_RETURN || g_nKey == VK_RBUTTON){
|
|
CString csTmp;
|
|
pEdit->GetWindowText(csTmp);
|
|
double nEle = _tstof(csTmp);
|
|
ads_polar(ptSprink, nAng, nDist - nEle, ptTmp);
|
|
break;
|
|
}
|
|
}
|
|
else if(ret == RTCAN)
|
|
break;
|
|
}
|
|
InitSheetHook(FALSE);
|
|
if(pEdit)
|
|
pEdit->DestroyWindow();
|
|
delete pEdit;
|
|
|
|
if(!ptTmp)
|
|
return;
|
|
|
|
if(entSprink.Is(_T("ATS_PIPE"))){
|
|
AcGeMatrix3d mat; // cet 2011.9.1 add
|
|
XPoint pt; // cet 2011.9.1 add 立管原来位置
|
|
double dLen = 100; // cet 2011.9.1 add 标注搜索范围
|
|
OPENOBJ_BEGIN(entSprink, AcDb::kForWrite, TDbPipe, pPipe);
|
|
if(!pPipe || !pPipe->IsVertical()){
|
|
return;
|
|
}
|
|
// cet 2011.9.1 add 获得联动立管标注的矩阵
|
|
dLen = pPipe->GetRadius()*pPipe->GetPScale();
|
|
pt = pPipe->StartPoint();
|
|
AcGeVector3d vt = ptTmp - pt;
|
|
vt.z = 0.0;
|
|
mat.setToTranslation(vt);
|
|
|
|
ptTmp.z = pPipe->StartPoint().z;
|
|
pPipe->SetStartPoint(ptTmp);
|
|
ptTmp.z = pPipe->EndPoint().z;
|
|
pPipe->SetEndPoint(ptTmp);
|
|
OPENOBJ_END();
|
|
MoveVPipeDim(pt, mat, dLen); // cet 2011.9.1 add 移动立管编号
|
|
return;
|
|
}
|
|
|
|
AcGeVector3d vectTmp(ptTmp.x - ptSprink.x, ptTmp.y - ptSprink.y, 0);
|
|
AcGeVector3d vectTmp2(ptSprink.x - ptTmp.x, ptSprink.y - ptTmp.y, 0);
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(vectTmp2);
|
|
|
|
XPushVar<int> vOsMode(_T("OSMODE"), 0);
|
|
PickSet ss(SS_FREE);
|
|
if(SelectEntities(_T("\n请选择联动喷头及管线:<只移动本喷头>"), ss, rbMask) != RTNORM){
|
|
ss+=entSprink;
|
|
OPENOBJ_BEGIN(entSprink, AcDb::kForWrite, TDbEquipment, pEquip);
|
|
if(pEquip){
|
|
ptTmp.z = pEquip->GetLocation().z;
|
|
pEquip->SetLocation(ptTmp);
|
|
pEquip->SetInsert(ptTmp);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else{
|
|
ss+=entSprink;
|
|
// zxl 2013.11.05 modify 未考虑ucs
|
|
// SHads_command(RTSTR, _T("MOVE"), RTPICKS, (TLong_ptr *)ss, RTSTR, _T(""),
|
|
// RT3DPOINT, &ptSprink, RT3DPOINT, &ptTmp, RTNONE);
|
|
|
|
TADSGePoint3d _pt1(Wcs2Ucs(ptSprink)), _pt2(Wcs2Ucs(ptTmp));
|
|
SHads_command(RTSTR, _T("MOVE"), RTPICKS, (TLong_ptr *)ss, RTSTR, _T(""),
|
|
RT3DPOINT, &_pt1, RT3DPOINT, &_pt2, RTNONE);
|
|
|
|
}
|
|
for(long j=0;j<ss.Length();j++){
|
|
Entity ent = ss[j];
|
|
XPoint ptOldLoc, ptNewLoc;
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbEquipment, pEquip);
|
|
if(pEquip){
|
|
int num = pEquip->GetInterfaceNum();
|
|
ptNewLoc = pEquip->GetLocation();
|
|
ptOldLoc = ptNewLoc;
|
|
ptOldLoc.TransformBy(mat);
|
|
if(num == 1){
|
|
TPipeInterface face;
|
|
pEquip->GetInterface(0, face);
|
|
AcDbObjectId PipeId = face.m_idPipe;
|
|
OPENOBJ_BEGIN(PipeId, AcDb::kForWrite, TDbPipe, pPipe);
|
|
if(pPipe){
|
|
XPoint ptStart, ptEnd;
|
|
pPipe->getStartPoint(ptStart);
|
|
pPipe->getEndPoint(ptEnd);
|
|
if(ptStart == ptOldLoc)
|
|
pPipe->SetStartPoint(ptNewLoc);
|
|
else if(ptEnd == ptOldLoc)
|
|
pPipe->SetEndPoint(ptNewLoc);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
|
|
PickSet ssDim(SS_FREE);
|
|
RBList rbMaskDim(RTDXF0, _T("ATS_DIMENSION2"), NULL);
|
|
XRectAngle rect(ptSprink, 650, 650);
|
|
ssDim.Get(_T("C"), rect.GetLowLeft(), rect.GetUpRight(), rbMaskDim);
|
|
long len = ssDim.Length();
|
|
ptSprink.z = 0;
|
|
for(long i=0;i<len;i++){
|
|
Entity entDim = ssDim[i];
|
|
OPENOBJ_BEGIN(entDim, AcDb::kForWrite, TDbDimension2, pDim);
|
|
if(pDim){
|
|
AcGePoint3dArray gripPoints;
|
|
AcDbIntArray osnapModes;
|
|
AcDbIntArray geomIds;
|
|
pDim->getGripPoints(gripPoints,osnapModes,geomIds);
|
|
int ptlen = gripPoints.length();
|
|
for (int n=0;n<ptlen;n++) {
|
|
XPoint pti = gripPoints[n];
|
|
if(pti == ptSprink){
|
|
AcDbIntArray indices;
|
|
indices.append(n);
|
|
pDim->moveGripPointsAt(indices, vectTmp);
|
|
}
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
XCurveSegment GetBlkPickSegment(Entity entBlk, XPoint ptPick, BOOL &bTrue)
|
|
{
|
|
//第一步,得到块参考矩阵
|
|
AcDbBlockReference *pBlkRef = NULL;
|
|
AcDbObjectId id = NULL;
|
|
acdbGetObjectId(id, entBlk);
|
|
acdbOpenObject(pBlkRef, id, AcDb::kForRead);
|
|
if(!pBlkRef)
|
|
return XCurveSegment();
|
|
AcGeMatrix3d mat = pBlkRef->blockTransform();
|
|
if(pBlkRef)
|
|
pBlkRef->close();
|
|
|
|
double xscale;
|
|
entBlk.GetData(41, &xscale);
|
|
xscale = fabs(xscale);
|
|
|
|
//第二步,得到块记录遍历器
|
|
TCHAR szBlkName[256];
|
|
entBlk.GetData(2, szBlkName);
|
|
AcDbBlockTable* pBlockTable = NULL;
|
|
AcDbBlockTableRecord *pRecord = NULL;
|
|
acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead);
|
|
if(Acad::eOk != pBlockTable->getAt(szBlkName, pRecord, AcDb::kForRead))
|
|
return XCurveSegment();
|
|
pBlockTable->close();
|
|
if(pRecord->isFromExternalReference() == true){
|
|
XPoint ptOrigin = pRecord->origin();
|
|
AcGeMatrix3d mat2;
|
|
mat2.setToTranslation(AcGeVector3d(-ptOrigin[0], -ptOrigin[1], -ptOrigin[2]));
|
|
mat *= mat2;
|
|
}
|
|
|
|
|
|
AcDbBlockTableRecordIterator *pIterator = NULL;
|
|
pRecord->newIterator(pIterator);
|
|
BOOL bIsWall5 = FALSE;
|
|
XCurveSegment seg;
|
|
if(pRecord)
|
|
pRecord->close();
|
|
|
|
for(pIterator->start(); !pIterator->done(); pIterator->step()){
|
|
AcDbEntity *pEnt;
|
|
pIterator->getEntity(pEnt, AcDb::kForRead);
|
|
AcDbLine *pLine = NULL;
|
|
TDbWall *pWall = NULL;
|
|
TDbColumn *pColumn = NULL; // cet 2011.8.31 add
|
|
|
|
// zxl 2013.10.30 add
|
|
Entity ent;
|
|
ads_name name;
|
|
acdbGetAdsName(name, pEnt->id());
|
|
ent = name;
|
|
|
|
if(pWall = TDbWall::cast(pEnt)){ //特别支持5。0墙体
|
|
XCurveSegment lCurve, rCurve;
|
|
pWall->GetSideCurve(lCurve, rCurve);
|
|
if(lCurve.Is(CURVE_LINE)){
|
|
AcGePoint3d ptStart = lCurve.GetStartPoint();
|
|
ptStart = ptStart.transformBy(mat);
|
|
AcGePoint3d ptEnd = lCurve.GetEndPoint();
|
|
ptEnd = ptEnd.transformBy(mat);
|
|
ptStart.z = 0.0; // cet 2011.9.1 add
|
|
ptEnd.z = 0.0; // cet 2011.9.1 add
|
|
XLine line(asDblArray(ptStart), asDblArray(ptEnd), 1);
|
|
seg = line;
|
|
if(IsPtOnLine(ptPick, line, 50)){
|
|
bTrue = TRUE;
|
|
bIsWall5 = TRUE;
|
|
pEnt->close();
|
|
delete pIterator;
|
|
return seg;
|
|
}
|
|
}
|
|
if(rCurve.Is(CURVE_LINE)){
|
|
AcGePoint3d ptStart = rCurve.GetStartPoint();
|
|
ptStart = ptStart.transformBy(mat);
|
|
AcGePoint3d ptEnd = rCurve.GetEndPoint();
|
|
ptEnd = ptEnd.transformBy(mat);
|
|
ptStart.z = 0.0; // cet 2011.9.1 add
|
|
ptEnd.z = 0.0; // cet 2011.9.1 add
|
|
XLine line(asDblArray(ptStart), asDblArray(ptEnd), 1);
|
|
seg = line;
|
|
if(IsPtOnLine(ptPick, line, 50)){
|
|
bIsWall5 = TRUE;
|
|
bTrue = FALSE;
|
|
pEnt->close();
|
|
delete pIterator;
|
|
return seg;
|
|
}
|
|
}
|
|
}
|
|
else if (pLine = AcDbLine::cast(pEnt)) // cet 2011.5.24 add
|
|
{
|
|
AcGePoint3d ptStart, ptEnd;
|
|
pLine->getStartPoint(ptStart);
|
|
pLine->getEndPoint(ptEnd);
|
|
ptStart = ptStart.transformBy(mat);
|
|
ptEnd = ptEnd.transformBy(mat);
|
|
ptStart.z = 0.0; // cet 2011.9.1 add
|
|
ptEnd.z = 0.0; // cet 2011.9.1 add
|
|
XLine line(asDblArray(ptStart), asDblArray(ptEnd), 1);
|
|
seg = line;
|
|
if(IsPtOnLine(ptPick, line, 50))
|
|
{
|
|
bTrue = FALSE;
|
|
pEnt->close();
|
|
delete pIterator;
|
|
return seg;
|
|
}
|
|
}
|
|
else if (pColumn = TDbColumn::cast(pEnt)) // cet 2011.8.31 add 支持柱子
|
|
{
|
|
XPoly2D poly;
|
|
pColumn->GetOutline(poly);
|
|
int nNum = poly.TotalSegments();
|
|
XPoint ptS, ptE;
|
|
for (int i = 0; i < nNum; i++)
|
|
{
|
|
poly.Nth(i, seg);
|
|
if (seg.GetCurveType() == CURVE_LINE)
|
|
{
|
|
ptS = seg.GetStartPoint();
|
|
ptE = seg.GetEndPoint();
|
|
ptS.TransformBy(mat);
|
|
ptE.TransformBy(mat);
|
|
ptS.z = 0.0;
|
|
ptE.z = 0.0;
|
|
XLine line(ptE, ptS, 1);
|
|
if (IsPtOnLine(ptPick, line, 50))
|
|
{
|
|
bTrue = FALSE;
|
|
pEnt->close();
|
|
delete pIterator;
|
|
seg.SetStartPoint(ptS);
|
|
seg.SetEndPoint(ptE);
|
|
return seg;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
else if (ent.Is(_T("LWPOLYLINE")) || ent.Is(_T("POLYLINE"))) // zxl 2013.10.30 add 支持pline线
|
|
{
|
|
XPoly2D poly(ent);
|
|
int nNum = poly.TotalSegments();
|
|
XPoint ptS, ptE;
|
|
XCurveSegment seg1;
|
|
for (int i = 0; i < nNum; i++)
|
|
{
|
|
poly.Nth(i, seg1);
|
|
if (seg.GetCurveType() == CURVE_LINE)
|
|
{
|
|
ptS = seg1.GetStartPoint();
|
|
ptE = seg1.GetEndPoint();
|
|
ptS.TransformBy(mat);
|
|
ptE.TransformBy(mat);
|
|
ptS.z = 0.0;
|
|
ptE.z = 0.0;
|
|
XLine line(ptE, ptS, 1);
|
|
if (IsPtOnLine(ptPick, line, 50))
|
|
{
|
|
bTrue = FALSE;
|
|
pEnt->close();
|
|
delete pIterator;
|
|
seg.SetStartPoint(ptS);
|
|
seg.SetEndPoint(ptE);
|
|
return seg;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
pEnt->close();
|
|
}
|
|
if(pIterator)
|
|
delete pIterator;
|
|
|
|
return XCurveSegment();
|
|
}
|
|
|
|
|
|
|
|
|
|
void SprinklerOrientation()
|
|
{
|
|
Entity entSel;
|
|
RBList rbMaskSel = ads_buildlist( -4, _T("<or"),
|
|
-4, _T("<and"), RTDXF0, _T("ATS_EQUIPMENT"), 8, LAY_EQUIP_SPRINKLE, -4, _T("and>"),
|
|
-4, _T("<and"), RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管")), -4, _T("and>"),
|
|
-4, _T("or>"), NULL);
|
|
|
|
|
|
if(SelectEntity(_T("\n请选择需要定位的喷头或立管<退出>:"), entSel, rbMaskSel) != RTNORM)
|
|
return;
|
|
XPoint ptSprink;
|
|
if(entSel.Is(_T("ATS_EQUIPMENT"))){
|
|
OPENOBJ_BEGIN(entSel, AcDb::kForRead, TDbEquipment, pEquip);
|
|
if(pEquip){
|
|
ptSprink = pEquip->GetLocation();
|
|
ptSprink.z = 0;
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else if(entSel.Is(_T("ATS_PIPE"))){
|
|
OPENOBJ_BEGIN(entSel, AcDb::kForRead, TDbPipe, pPipe);
|
|
if(!pPipe || !pPipe->IsVertical()){
|
|
AfxMessageBox(_T("不是立管!"));
|
|
return;
|
|
}
|
|
ptSprink = pPipe->StartPoint();
|
|
ptSprink.z = 0;
|
|
OPENOBJ_END();
|
|
}
|
|
entSel.Redraw(3);
|
|
|
|
RBList rbMask1(RTDXF0, _T("ATS_EQUIPMENT"), 8, LAY_EQUIP_SPRINKLE, NULL);
|
|
RBList rbMask2(RTDXF0, _T("LINE"), 8, _T("*"), NULL);
|
|
RBList rbMask3(RTDXF0, _T("ATS_WALL"), 8, _T("*"), NULL);
|
|
RBList rbMask4(RTDXF0, _T("INSERT"), 8, _T("*"), NULL);
|
|
RBList rbMask5(RTDXF0, _T("ATS_COLUMN"), 8, _T("*"), NULL); // cet 2011.8.31 add
|
|
RBList rbMask6(RTDXF0, _T("LWPOLYLINE"), 8, _T("*"), NULL);// zxl 2013.10.29 add
|
|
RBList rbMask7(RTDXF0, _T("POLYLINE"), 8, _T("*"), NULL);// zxl 2013.10.29 add
|
|
|
|
|
|
int pickbox;
|
|
int type(0);
|
|
XPoint pt1,pt2;
|
|
Entity entTag;
|
|
PickSet ssAll(SS_FREE);
|
|
VERIFY(xg_getvar(_T("PICKBOX"), &pickbox)==RTNORM);
|
|
CTipWnd *pTextDlg = NULL;
|
|
ads_prompt(_T("\n请选择参考位置,如墙、喷头<退出>:"));
|
|
for (;;) {
|
|
|
|
|
|
resbuf result;
|
|
type = 2;
|
|
if (ads_grread(5,&type,&result) != RTNORM) break;
|
|
if (type != 5 && type!=3 && type!=12 && type!=11) break;
|
|
pt1[0] = result.resval.rpoint[0];
|
|
pt1[1] = result.resval.rpoint[1];
|
|
pt1[2] = 0.0;
|
|
if(type==3) {
|
|
PickSet s(SS_FREE);
|
|
if (ads_ssget(NULL,pt1,NULL,NULL,s) == RTNORM ) {
|
|
entTag = s[0L];
|
|
if(!entTag.MatchBase(rbMask1) && !entTag.MatchBase(rbMask2) && !entTag.MatchBase(rbMask3) && !entTag.MatchBase(rbMask4) && !entTag.MatchBase(rbMask5) && !entTag.MatchBase(rbMask6) && !entTag.MatchBase(rbMask7)) // cet 2011.8.31 modify 支持柱子
|
|
continue;
|
|
if (pTextDlg) {
|
|
pTextDlg->DestroyWindow();
|
|
delete pTextDlg;
|
|
pTextDlg = NULL;
|
|
}
|
|
DoModifySprinklerLoc(entTag, entSel, Ucs2Wcs(pt1));
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
else if(type == 11){ //右键进行编辑
|
|
break;
|
|
}
|
|
|
|
if (ads_distance(pt1,pt2) > 0.1) {
|
|
if (pTextDlg) {
|
|
pTextDlg->DestroyWindow();
|
|
delete pTextDlg;
|
|
pTextDlg = NULL;
|
|
}
|
|
PickSet s(SS_FREE);
|
|
if (ads_ssget(NULL,pt1,NULL,NULL,s) != RTNORM ) {
|
|
continue;
|
|
}
|
|
Groups g1(1), g0(0);
|
|
ads_trans(XPoint(pt1), (resbuf *)&g1, (resbuf *)&g0, 0, pt1);
|
|
|
|
// 构造WCS到Dcs的转换矩阵
|
|
AcGeMatrix3d transWcsToDcs;
|
|
XPoint xAxesWcs(1,0,0), yAxesWcs(0,1,0), zAxesWcs(0,0,1),
|
|
xAxesDcs, yAxesDcs, zAxesDcs;
|
|
XPoint ptOrginWcs(0,0,0), ptOrginDcs(0,0,0);
|
|
Groups fromWcs(0), toDcs(2);
|
|
ads_trans(ptOrginWcs, (resbuf *)&fromWcs, (resbuf *)&toDcs, 0, ptOrginDcs);
|
|
ads_trans(xAxesWcs, (resbuf *)&fromWcs, (resbuf *)&toDcs, 1, xAxesDcs);
|
|
ads_trans(yAxesWcs, (resbuf *)&fromWcs, (resbuf *)&toDcs, 1, yAxesDcs);
|
|
ads_trans(zAxesWcs, (resbuf *)&fromWcs, (resbuf *)&toDcs, 1, zAxesDcs);
|
|
transWcsToDcs.setCoordSystem(ptOrginDcs, xAxesDcs, yAxesDcs, zAxesDcs);
|
|
|
|
double nMinDist=0.0;
|
|
Entity entNearest;
|
|
long lCount=s.Length();
|
|
for(long i=0L; i<lCount; i++) {
|
|
Entity ent=s[i];
|
|
if(!ent.MatchBase(rbMask1) && !ent.MatchBase(rbMask2) && !ent.MatchBase(rbMask3) && !ent.MatchBase(rbMask4) && !entTag.MatchBase(rbMask5) && !entTag.MatchBase(rbMask6)&& !entTag.MatchBase(rbMask7)) // cet 2011.8.31 modify 支持柱子
|
|
continue;
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbEntity, pEnt);
|
|
if(!pEnt)
|
|
continue;
|
|
AcGePoint3dArray points;
|
|
XPoint ptTemp;
|
|
AcDbIntArray ar;
|
|
pEnt->getOsnapPoints(AcDb::kOsModeNear, 0, pt1, ptTemp, transWcsToDcs, points, ar);
|
|
XPoint ptNear;
|
|
if(!GetNearestPoint(points, pt1, ptNear))
|
|
continue;
|
|
ptNear.z=pt1.z;
|
|
double nDist=ptNear.Distance(pt1);
|
|
if(!entNearest || nDist<nMinDist) {
|
|
entNearest=ent;
|
|
nMinDist=nDist;
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
if(!entNearest) {
|
|
if(lCount>0)
|
|
entNearest=s[0L];
|
|
if(!entNearest)
|
|
continue;
|
|
}
|
|
if(entNearest == entSel)
|
|
continue;
|
|
DList<CBlockStruct> lstInfo;
|
|
double nDist(0);
|
|
if(entNearest.MatchBase(rbMask2)){
|
|
XLine line(entNearest, 1);
|
|
XPoint ptTmp;
|
|
ptSprink.Project(&line, ptTmp);
|
|
ptTmp.z = 0.0; // cet 2011.9.1 add
|
|
nDist = ads_distance(ptSprink, ptTmp);
|
|
}
|
|
else if(entNearest.MatchBase(rbMask1)){
|
|
XPoint ptNewLoc;
|
|
OPENOBJ_BEGIN(entNearest, AcDb::kForRead, TDbEquipment, pEquip);
|
|
if(pEquip){
|
|
ptNewLoc = pEquip->GetLocation();
|
|
ptNewLoc.z = 0;
|
|
}
|
|
OPENOBJ_END();
|
|
nDist = ads_distance(ptSprink, ptNewLoc);
|
|
}
|
|
else if(entNearest.MatchBase(rbMask3)){
|
|
XCurveSegment lCurve, rCurve;
|
|
OPENOBJ_BEGIN(entNearest, AcDb::kForRead, TDbWall, pWall);
|
|
if(pWall) {
|
|
XPoint ptNew1, ptNew2;
|
|
pWall->GetSideCurve(lCurve, rCurve);
|
|
lCurve.ProjectToMe(ptSprink, ptNew1);
|
|
rCurve.ProjectToMe(ptSprink, ptNew2);
|
|
ptNew1.z = 0.0; // cet 2011.9.1 add
|
|
ptNew2.z = 0.0; // cet 2011.9.1 add
|
|
nDist = ads_distance(ptSprink, ptNew1) < ads_distance(ptSprink, ptNew2) ? ads_distance(ptSprink, ptNew1) : ads_distance(ptSprink, ptNew2);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
else if(entNearest.MatchBase(rbMask4))//外部参考 2011-5-24 sr
|
|
{
|
|
XCurveSegment SelCurve;
|
|
BOOL bIsLeft = TRUE;
|
|
SelCurve = GetBlkPickSegment(entNearest, pt1, bIsLeft);
|
|
if(!!SelCurve)
|
|
{
|
|
XPoint ptTmp;
|
|
ptSprink.Project(&SelCurve, ptTmp);
|
|
ptTmp.z = 0.0; // cet 2011.9.1 add
|
|
nDist = ads_distance(ptSprink, ptTmp);
|
|
}
|
|
else // 获取参考失败直接返回
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
else if (entNearest.MatchBase(rbMask5)) // cet 2011.8.31 add 支持柱子
|
|
{
|
|
XCurveSegment seg;
|
|
OPENOBJ_BEGIN(entNearest, AcDb::kForRead, TDbColumn, pColumn);
|
|
if(pColumn != NULL)
|
|
{
|
|
XPoly2D poly;
|
|
pColumn->GetOutline(poly);
|
|
int nNum = poly.TotalSegments();
|
|
for (int i = 0; i < nNum; i++)
|
|
{
|
|
poly.Nth(i, seg);
|
|
if (seg.GetCurveType() == CURVE_LINE)
|
|
{
|
|
XLine line(seg.GetStartPoint(), seg.GetEndPoint(), 1);
|
|
if (IsPtOnLine(pt1, line, 50))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
if (!seg) // 未找到直接返回
|
|
{
|
|
continue;
|
|
}
|
|
|
|
XPoint ptTmp;
|
|
ptSprink.Project(&seg, ptTmp);
|
|
ptTmp.z = 0.0;
|
|
nDist = ads_distance(ptSprink, ptTmp);
|
|
}
|
|
else if (entNearest.MatchBase(rbMask6) || entNearest.MatchBase(rbMask7))// zxl 2013.10.30 add 支持pline线
|
|
{
|
|
XCurveSegment seg, seg1;
|
|
XPoly2D poly(entNearest);
|
|
int nNum = poly.TotalSegments();
|
|
for (int i = 0; i < nNum; i++)
|
|
{
|
|
poly.Nth(i, seg1);
|
|
if (seg1.GetCurveType() == CURVE_LINE)
|
|
{
|
|
XLine line(seg1.GetStartPoint(), seg1.GetEndPoint(), 0);
|
|
if (IsPtOnLine(pt1, line, 50))
|
|
{
|
|
seg = seg1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!seg) // 未找到直接返回
|
|
{
|
|
continue;
|
|
}
|
|
|
|
XPoint ptTmp;
|
|
ptSprink.Project(&seg, ptTmp);
|
|
ptTmp.z = 0.0;
|
|
nDist = ads_distance(ptSprink, ptTmp);
|
|
}
|
|
|
|
else
|
|
continue;
|
|
if(fabs(pt1.z - pt2.z) < _distSnap && nDist > 0){
|
|
CBlockStruct *pInfo = new CBlockStruct();
|
|
pInfo->m_csRecord = _T("离喷头距离");
|
|
pInfo->m_csDesName.Format(_T("%.0f"), nDist);
|
|
lstInfo.Append(pInfo);
|
|
}
|
|
else // cet 2011.5.24 add
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if(!pTextDlg){
|
|
CPoint pt;
|
|
int cvport;
|
|
VERIFY(xg_getvar(_T("CVPORT"), &cvport)==RTNORM);
|
|
acedCoordFromWorldToPixel(cvport, pt1, pt);
|
|
acedGetAcadDwgView()->ClientToScreen(&pt);
|
|
acedGetAcadFrame()->ScreenToClient(&pt);
|
|
pTextDlg = new CTipWnd();
|
|
pTextDlg->Create(lstInfo, pt.x+pickbox*2, pt.y+pickbox*2, acedGetAcadFrame());
|
|
acedGetAcadDwgView()->SetFocus();
|
|
}
|
|
|
|
}
|
|
}
|
|
entSel.Redraw(4);
|
|
if(pTextDlg){
|
|
pTextDlg->DestroyWindow();
|
|
delete pTextDlg;
|
|
}
|
|
SHads_command(RTSTR, _T(".REDRAW"), RTNONE);
|
|
}
|
|
|
|
|