3265 lines
102 KiB
C++
3265 lines
102 KiB
C++
#include "stdafx.h"
|
|
|
|
#include <PipeWireMonitor.h>
|
|
#include <dbPipeValve.h>
|
|
#include <DbEquipment.h>
|
|
//#include <cbclass.h>
|
|
|
|
#include "InsBlockDlg.h"
|
|
#include "SelectBlkDlg.h"
|
|
#include <iostream>
|
|
#include <vector>
|
|
#include <map>
|
|
#include <dbray.h>
|
|
// #include "TDb.h"
|
|
// #include "TDbECabletry.h"
|
|
// #include "TDbHvacDuct.h"
|
|
// #include "THvac.h"
|
|
// #include "TDbHvacFitting.h"
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CInsBlockDlg dialog
|
|
|
|
//#ifdef _WIN64
|
|
#include"TGAs.h"
|
|
//#endif
|
|
|
|
//extern Acad::ErrorStatus AssureInCurrentView_New(const XPoint &ptLow, const XPoint &ptUp);
|
|
BOOL TWBlock(PickSet &ss, const TCHAR* szFileName, XPoint ptIns, BOOL bSet0Layer = TRUE)
|
|
{
|
|
AcDbObjectIdArray cloneSet;
|
|
long len = ss.Length();
|
|
for(long i=0;i<len;i++){
|
|
Entity ent = ss[i];
|
|
AcDbObjectId id;
|
|
acdbGetObjectId(id, ent);
|
|
cloneSet.append(id);
|
|
}
|
|
AcDbDatabase db;
|
|
AcDbObjectId idMSpace = db.currentSpaceId();
|
|
AcDbIdMapping idMap;
|
|
acdbCurDwg()->wblockCloneObjects(cloneSet, idMSpace, idMap, AcDb::kDrcIgnore, false);
|
|
AcDbBlockTable *pTable = NULL;
|
|
db.getBlockTable(pTable, AcDb::kForRead);
|
|
if(!pTable)
|
|
return FALSE;
|
|
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(AcGeVector3d(-ptIns[0], -ptIns[1], -ptIns[2]));
|
|
AcDbBlockTableRecord *pBlockTableRecord = NULL;
|
|
VERIFY(pTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForRead)==Acad::eOk);
|
|
pTable->close();
|
|
if(!pBlockTableRecord)
|
|
return FALSE;
|
|
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
|
|
|
pBlockTableRecord->newIterator(pBlockIterator);
|
|
if(!pBlockIterator){
|
|
pBlockTableRecord->close();
|
|
return FALSE;
|
|
}
|
|
for(pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step()) {
|
|
AcDbEntity *pEnt = NULL;
|
|
pBlockIterator->getEntity(pEnt,AcDb::kForWrite);
|
|
if(pEnt){
|
|
if(bSet0Layer)
|
|
pEnt->setLayer(_T("0"));
|
|
pEnt->transformBy(mat);
|
|
pEnt->close();
|
|
}
|
|
}
|
|
delete pBlockIterator;
|
|
pBlockTableRecord->close();
|
|
#if (ADS>15)
|
|
acdbSaveAs2000(&db, szFileName);
|
|
#else
|
|
db.saveAs(szFileName);
|
|
#endif
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
void DoBuildSlide(void *pData)
|
|
{
|
|
//如果调用之前使用本应用的资源重载,这里必须push/pop ACAD的资源
|
|
acDocManager->pushAcadResourceHandle();
|
|
AcApDocument *pOldDoc=curDoc();
|
|
if (acDocManager->isApplicationContext()) {
|
|
if(acDocManager->appContextOpenDocument((const TCHAR *)pData)==Acad::eOk) {
|
|
PostCommand(_T("TgMakeSlide "), false);
|
|
acedPostCommand(_T("QSAVE\n"));
|
|
AcApDocument *pDoc=curDoc();
|
|
acDocManager->closeDocument(pDoc);
|
|
}
|
|
}
|
|
acDocManager->activateDocument(pOldDoc);
|
|
acDocManager->popResourceHandle();
|
|
}
|
|
|
|
|
|
|
|
void BuildSlide(PickSet &ssSel, XString xsFullSld)
|
|
{
|
|
ads_real xlen, ylen;
|
|
XPoint ptIns, ptCen;
|
|
ssSel.GetExtend(ptCen, &xlen, &ylen);
|
|
|
|
arxZoomTo(ptCen, xlen, ylen);
|
|
XPoint ptLow, ptUp;
|
|
AT_ScrCorner(ptLow, ptUp);
|
|
PickSet ssDel(SS_FREE);
|
|
ssDel.Get(_T("C"), ptLow, ptUp, RBList());
|
|
ssDel -= ssSel;
|
|
MakeVisible(ssDel, false);
|
|
SHads_command(RTSTR, _T("MSLIDE"), RTSTR, (TCHAR *)xsFullSld, RTNONE);
|
|
MakeVisible(ssDel, true);
|
|
ZOOMP;
|
|
|
|
}
|
|
|
|
|
|
void BuildEquipment(const TCHAR* szType)
|
|
{
|
|
g_ssPickFirst.Free();
|
|
|
|
int nOsMode=0;
|
|
xg_getvar(_T("OSMODE"), &nOsMode);
|
|
nOsMode &= ~0x4000;
|
|
nOsMode |= OS_INT|OS_NEA|OS_PER|OS_END|OS_CEN |OS_MID;
|
|
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
|
|
|
PickSet ssSel(SS_FREE);
|
|
if(SelectEntities(_T("\n请选择要做成图块的图元<退出>:"), ssSel, RBList()) != RTNORM)
|
|
return;
|
|
|
|
ads_real xlen, ylen;
|
|
XPoint ptIns;
|
|
ssSel.GetExtend(ptIns, &xlen, &ylen);
|
|
|
|
ads_getpoint(ptIns, _T("\n请点选插入点<中心点>:"), ptIns);
|
|
|
|
XPoint p0;
|
|
PickSet ssPt(SS_FREE);
|
|
XPushVarStr clayer(_T("CLAYER"), _T("0"));
|
|
|
|
TCHAR dwgPrefix[256]=_T("");
|
|
GetTempPath(255, dwgPrefix);
|
|
if(dwgPrefix[_tcslen(dwgPrefix)-1]!=_T('\\'))
|
|
_tcscat(dwgPrefix, _T("\\"));
|
|
XString xsFullSld, xsFullDwg;
|
|
xsFullSld << dwgPrefix << _T("_ELECBLK") << _T(".sld");
|
|
xsFullDwg << dwgPrefix << _T("_ELECBLK") << _T(".dwg");
|
|
|
|
BOOL flag = TWBlock(ssSel, xsFullDwg, ptIns);
|
|
BuildSlide(ssSel, xsFullSld);
|
|
|
|
// arxZoomTo(ptCen, xlen, ylen);
|
|
// XPoint ptLow, ptUp;
|
|
// AT_ScrCorner(ptLow, ptUp);
|
|
// PickSet ssDel(SS_FREE);
|
|
// ssDel.Get(_T("C"), ptLow, ptUp, RBList());
|
|
// ssDel -= ssSel;
|
|
// MakeVisible(ssDel, false);
|
|
// SHads_command(RTSTR, _T("MSLIDE"), RTSTR, (TCHAR *)xsFullSld, RTNONE);
|
|
// MakeVisible(ssDel, true);
|
|
// ZOOMP;
|
|
|
|
ssPt.Erase();
|
|
if(!flag){
|
|
AfxMessageBox(_T("造块失败!"));
|
|
return;
|
|
}
|
|
|
|
CString strPathTkName = g_csDwbPath + _T("ATTACHMENT.tk");
|
|
if(AddNewDwg2Dwb(strPathTkName, (const TCHAR*)xsFullDwg, (const TCHAR*)xsFullSld, szType, _T("新图块")).IsEmpty()) {
|
|
AfxMessageBox(_T("没有正确加入图库!"));
|
|
return;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
CString BuildDoubleLineValve()
|
|
{
|
|
g_ssPickFirst.Free();
|
|
|
|
int nOsMode=0;
|
|
xg_getvar(_T("OSMODE"), &nOsMode);
|
|
nOsMode &= ~0x4000;
|
|
nOsMode |= OS_INT|OS_NEA|OS_PER|OS_END|OS_CEN |OS_MID;
|
|
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
|
|
|
PickSet ssSel(SS_FREE);
|
|
if(SelectEntities(_T("\n请选择要做成图块的图元<退出>:"), ssSel, RBList()) != RTNORM)
|
|
return CString();
|
|
|
|
CString csDwb = g_csDwbPath + _T("TwtSys");
|
|
XString xsTmp1;
|
|
if(LoadDwbBlock(csDwb, _T("00000069"), xsTmp1) != RTNORM) // 显示点
|
|
return CString();
|
|
|
|
long ssLen = ssSel.Length();
|
|
PickSet ssDel(SS_FREE);
|
|
for(long i=0;i<ssLen;i++){
|
|
Entity entTmp = ssSel[i];
|
|
if(entTmp.Is(_T("POINT")))
|
|
ssDel += entTmp;
|
|
}
|
|
ssSel -= ssDel;
|
|
ads_real xlen, ylen;
|
|
XPoint ptIns;
|
|
ssSel.GetExtend(ptIns, &xlen, &ylen);
|
|
|
|
ads_getpoint(ptIns, _T("\n请点选插入点 <中心点>:"), ptIns);
|
|
|
|
XPoint p0;
|
|
PickSet ssPt(SS_FREE);
|
|
XPushVarStr clayer(_T("CLAYER"), _T("0"));
|
|
double nScale(200);
|
|
ads_getreal(_T("\n阀门Y坐标方向长度(所接的管线宽度)<200>:"), &nScale);
|
|
|
|
|
|
while(ads_getpoint(NULL,_T("\n请点取要作为接线点的点(图块外轮廓为圆的可不加接线点) <继续>:"), p0)==RTNORM){
|
|
AcDbObjectId id = InsertBlock((const TCHAR*)xsTmp1, asPnt3d(p0), 10, 10, 0, _T("0"));
|
|
ssDel += id;
|
|
Entity entPt;
|
|
SHads_command(RTSTR, _T("_point"), RT3DPOINT, &p0, RTNONE);
|
|
entPt.GetLast();
|
|
ssSel += entPt;
|
|
ssPt += entPt;
|
|
}
|
|
ssDel.Erase();
|
|
|
|
TCHAR dwgPrefix[256]=_T("");
|
|
GetTempPath(255, dwgPrefix);
|
|
if(dwgPrefix[_tcslen(dwgPrefix)-1]!=_T('\\'))
|
|
_tcscat(dwgPrefix, _T("\\"));
|
|
XString xsFullSld, xsFullDwg;
|
|
xsFullSld << dwgPrefix << _T("_ELECBLK") << _T(".sld");
|
|
xsFullDwg << dwgPrefix << _T("_ELECBLK") << _T(".dwg");
|
|
xlen = xlen*1.5;
|
|
ylen = ylen*1.5;
|
|
|
|
BuildSlide(ssSel, xsFullSld);
|
|
|
|
// arxZoomTo(ptIns, xlen, ylen);
|
|
// SHads_command(RTSTR, _T("MSLIDE"), RTSTR, (TCHAR *)xsFullSld, RTNONE);
|
|
// ZOOMP;
|
|
|
|
SHads_command(RTSTR, _T("scale"), RTPICKS, (TLong_ptr *)ssSel, RTSTR, _T(""),
|
|
RT3DPOINT, &ptIns, RTREAL, (1 / nScale), RTNONE);
|
|
BOOL flag = TWBlock(ssSel, xsFullDwg, ptIns, TRUE);
|
|
SHads_command(RTSTR, _T("scale"), RTPICKS, (TLong_ptr *)ssSel, RTSTR, _T(""),
|
|
RT3DPOINT, &ptIns, RTREAL, nScale, RTNONE);
|
|
|
|
// AcApDocument* pDoc = acDocManager->curDocument();
|
|
// if (pDoc) {
|
|
// acDocManager->executeInApplicationContext(DoBuildSlide, (void *)(const TCHAR *)xsFullDwg);
|
|
// }
|
|
|
|
ssPt.Erase();
|
|
if(!flag){
|
|
AfxMessageBox(_T("造块失败!"));
|
|
return CString();
|
|
}
|
|
CString strPathTkName = g_csDwbPath + _T("valve.tk");
|
|
CString csRecord = AddNewDwg2Dwb(strPathTkName, (const TCHAR*)xsFullDwg, (const TCHAR*)xsFullSld, _T("双线阀门"), _T("新阀门"));
|
|
|
|
if(csRecord.IsEmpty()) {
|
|
AfxMessageBox(_T("没有正确加入图库!"));
|
|
return CString();
|
|
}
|
|
|
|
return csRecord;
|
|
}
|
|
|
|
|
|
CString BuildValve(const TCHAR* szType, const TCHAR* szName)
|
|
{
|
|
g_ssPickFirst.Free();
|
|
|
|
int nOsMode=0;
|
|
xg_getvar(_T("OSMODE"), &nOsMode);
|
|
nOsMode &= ~0x4000;
|
|
nOsMode |= OS_INT|OS_NEA|OS_PER|OS_END|OS_CEN |OS_MID;
|
|
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
|
|
|
PickSet ssSel(SS_FREE);
|
|
if(SelectEntities(_T("\n请选择要做成图块的图元<退出>:"), ssSel, RBList()) != RTNORM)
|
|
return CString();
|
|
|
|
CString csDwb = g_csDwbPath + _T("TwtSys");
|
|
XString xsTmp1;
|
|
if(LoadDwbBlock(csDwb, _T("00000069"), xsTmp1) != RTNORM) // 显示点
|
|
return CString();
|
|
|
|
long ssLen = ssSel.Length();
|
|
PickSet ssDel(SS_FREE);
|
|
for(long i=0;i<ssLen;i++){
|
|
Entity entTmp = ssSel[i];
|
|
if(entTmp.Is(_T("POINT")))
|
|
ssDel += entTmp;
|
|
}
|
|
ssSel -= ssDel;
|
|
ads_real xlen, ylen;
|
|
XPoint ptIns;
|
|
ssSel.GetExtend(ptIns, &xlen, &ylen);
|
|
|
|
|
|
ads_getpoint(ptIns, _T("\n请点选插入点 <中心点>:"), ptIns);
|
|
|
|
XPoint p0;
|
|
PickSet ssPt(SS_FREE);
|
|
XPushVarStr clayer(_T("CLAYER"), _T("0"));
|
|
|
|
while(ads_getpoint(NULL,_T("\n请点取要作为接线点的点(图块外轮廓为圆的可不加接线点) <继续>:"), p0)==RTNORM){
|
|
AcDbObjectId id = InsertBlock((const TCHAR*)xsTmp1, asPnt3d(p0), 10, 10, 0, _T("0"));
|
|
ssDel += id;
|
|
Entity entPt;
|
|
SHads_command(RTSTR, _T("_point"), RT3DPOINT, &p0, RTNONE);
|
|
entPt.GetLast();
|
|
ssSel += entPt;
|
|
ssPt += entPt;
|
|
}
|
|
ssDel.Erase();
|
|
|
|
TCHAR dwgPrefix[256]=_T("");
|
|
GetTempPath(255, dwgPrefix);
|
|
if(dwgPrefix[_tcslen(dwgPrefix)-1]!=_T('\\'))
|
|
_tcscat(dwgPrefix, _T("\\"));
|
|
XString xsFullSld, xsFullDwg;
|
|
xsFullSld << dwgPrefix << _T("_ELECBLK") << _T(".sld");
|
|
xsFullDwg << dwgPrefix << _T("_ELECBLK") << _T(".dwg");
|
|
BOOL flag = TWBlock(ssSel, xsFullDwg, ptIns);
|
|
|
|
// AcApDocument* pDoc = acDocManager->curDocument();
|
|
// if (pDoc) {
|
|
// acDocManager->executeInApplicationContext(DoBuildSlide, (void *)(const TCHAR *)xsFullDwg);
|
|
// }
|
|
BuildSlide(ssSel, xsFullSld);
|
|
// arxZoomTo(ptIns, xlen, ylen);
|
|
// SHads_command(RTSTR, _T("MSLIDE"), RTSTR, (TCHAR *)xsFullSld, RTNONE);
|
|
// ZOOMP;
|
|
|
|
ssPt.Erase();
|
|
if(!flag){
|
|
AfxMessageBox(_T("造块失败!"));
|
|
return CString();
|
|
}
|
|
CString strPathTkName = g_csDwbPath + _T("valve_U.tk");
|
|
CString csRecord = AddNewDwg2Dwb(strPathTkName, (const TCHAR*)xsFullDwg, (const TCHAR*)xsFullSld, szType, szName);
|
|
|
|
if(csRecord.IsEmpty()) {
|
|
AfxMessageBox(_T("没有正确加入图库!"));
|
|
return CString();
|
|
}
|
|
|
|
return csRecord;
|
|
}
|
|
|
|
void BuildNewBlk(const TCHAR* szType)
|
|
{
|
|
g_ssPickFirst.Free();
|
|
|
|
int nOsMode=0;
|
|
xg_getvar(_T("OSMODE"), &nOsMode);
|
|
nOsMode &= ~0x4000;
|
|
nOsMode |= OS_INT|OS_NEA|OS_PER|OS_END|OS_CEN |OS_MID;
|
|
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
|
|
|
PickSet ssSel(SS_FREE);
|
|
if(SelectEntities(_T("\n请选择要做成图块的图元<退出>:"), ssSel, RBList()) != RTNORM)
|
|
return;
|
|
|
|
ads_real xlen, ylen;
|
|
XPoint ptIns;
|
|
ssSel.GetExtend(ptIns, &xlen, &ylen);
|
|
ads_getpoint(ptIns, _T("\n请点选插入点 <中心点>:"), ptIns);
|
|
|
|
TCHAR dwgPrefix[256]=_T("");
|
|
GetTempPath(255, dwgPrefix);
|
|
if(dwgPrefix[_tcslen(dwgPrefix)-1]!=_T('\\'))
|
|
_tcscat(dwgPrefix, _T("\\"));
|
|
XString xsFullSld, xsFullDwg;
|
|
xsFullSld << dwgPrefix << _T("_ELECBLK") << _T(".sld");
|
|
xsFullDwg << dwgPrefix << _T("_ELECBLK") << _T(".dwg");
|
|
|
|
BOOL flag = TWBlock(ssSel, xsFullDwg, ptIns);
|
|
// AcApDocument* pDoc = acDocManager->curDocument();
|
|
// if (pDoc) {
|
|
// acDocManager->executeInApplicationContext(DoBuildSlide, (void *)(const TCHAR *)xsFullDwg);
|
|
// }
|
|
BuildSlide(ssSel, xsFullSld);
|
|
// arxZoomTo(ptIns, xlen, ylen);
|
|
// SHads_command(RTSTR, _T("MSLIDE"), RTSTR, (TCHAR *)xsFullSld, RTNONE);
|
|
// ZOOMP;
|
|
|
|
|
|
if(!flag){
|
|
AfxMessageBox(_T("造块失败!"));
|
|
return;
|
|
}
|
|
CString strPathTkName = g_csDwbPath + _T("twtsys.tk");
|
|
if(AddNewDwg2Dwb(strPathTkName, (const TCHAR*)xsFullDwg, (const TCHAR*)xsFullSld, szType, _T("新图块")).IsEmpty()) {
|
|
AfxMessageBox(_T("没有正确加入图库!"));
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
|
|
|
|
//***************************************************************************************************
|
|
// 常用图块
|
|
//***************************************************************************************************
|
|
void InsTwtBlock()
|
|
{
|
|
int nOsMode=0;
|
|
xg_getvar(_T("OSMODE"), &nOsMode);
|
|
nOsMode &= ~0x4000;
|
|
nOsMode |= OS_INT|OS_NEA;
|
|
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
|
CInsBlockDlg dlg(_T("TwtSys"), 5, 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_TWT);
|
|
XPushVarStr clayer(_T("CLAYER"), LAY_TWT);
|
|
|
|
double nScale = 1;
|
|
BOOL bReversal = FALSE;
|
|
while(1){
|
|
if(dlg.m_iMode == 2){
|
|
BuildNewBlk(dlg.m_csPlanType);
|
|
dlg.m_iMode = 0;
|
|
dlg.Reset();
|
|
}
|
|
else if(dlg.m_iMode == 0){
|
|
TBlockEdJig jig(g_csInsBlkName, ptIns, nScale);
|
|
jig.SetPrompt(_T("\n请指定图块的插入点 [90度旋转(A)/左右翻转(F)/放大(E)/缩小(D)]<退出>:"));
|
|
jig.SetKeyword(_T("A F E D R"));
|
|
jig.m_bReversal = bReversal;
|
|
if(!!ptOld)
|
|
jig.m_ptRef = ptOld;
|
|
int nKeyIndex = 0;
|
|
int nRetCode = jig.DoIt(&nKeyIndex);
|
|
if(nRetCode == RTNORM) {
|
|
ptIns = jig.GetPickPoint();
|
|
ptOld = ptIns;
|
|
double nLen = jig.m_nSacle;
|
|
if(jig.m_bReversal)
|
|
SHads_command(RTSTR, _T(".INSERT"), RTSTR, (const TCHAR*)g_csInsBlkName, RT3DPOINT, &ptIns,
|
|
RTREAL, -nLen, RTREAL, nLen, RTREAL, Radian2Angle(g_nInsBlkRotate), RTNONE);
|
|
else
|
|
SHads_command(RTSTR, _T(".INSERT"), RTSTR, (const TCHAR*)g_csInsBlkName, RT3DPOINT, &ptIns,
|
|
RTREAL, nLen, RTREAL, nLen, RTREAL, Radian2Angle(g_nInsBlkRotate), RTNONE);
|
|
continue;
|
|
}
|
|
else if(nRetCode == RTKWORD){
|
|
if(nKeyIndex == 0)
|
|
g_nInsBlkRotate += PI/2;
|
|
else if(nKeyIndex == 1)
|
|
bReversal = !bReversal;
|
|
if(nKeyIndex == 2)
|
|
nScale += 1;
|
|
else if(nKeyIndex == 3 && jig.m_nSacle > 1)
|
|
nScale -= 1;
|
|
else
|
|
continue;
|
|
}
|
|
else{
|
|
g_nInsBlkRotate = 0;
|
|
dlg.DestroyWindow();
|
|
SHads_command(RTNONE);
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//***************************************************************************************************
|
|
// 系统附件
|
|
//***************************************************************************************************
|
|
void InsSysAttchment()
|
|
{
|
|
int nOsMode=0;
|
|
xg_getvar(_T("OSMODE"), &nOsMode);
|
|
nOsMode &= ~0x4000;
|
|
nOsMode |= OS_INT|OS_END;
|
|
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
|
CInsBlockDlg dlg(_T("ATTACHMENT"), 4, 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);
|
|
RBList rbMask(RTDXF0, _T("ATS_EQUIPMENT"), 8, _T("*"), NULL);
|
|
double nScale = 1;
|
|
BOOL bReversal = FALSE;
|
|
while(1){
|
|
if(!dlg.m_bSuccess)
|
|
break;
|
|
if(dlg.m_iMode == 0){
|
|
while(1){
|
|
TBlockEdJig jig(g_csInsBlkName, ptIns, nScale);
|
|
jig.SetPrompt(_T("\n请指定系统附件的插入点 [90度旋转(A)/左右翻转(F)/放大(E)/缩小(D)]<退出>:"));
|
|
jig.SetKeyword(_T("A F E D R"));
|
|
jig.m_bReversal = bReversal;
|
|
jig.m_nSacle = nScale;
|
|
if(!!ptOld)
|
|
jig.m_ptRef = ptOld;
|
|
int nKeyIndex = 0;
|
|
int nRetCode = jig.DoIt(&nKeyIndex);
|
|
if(nRetCode == RTNORM) {
|
|
ptIns = jig.GetPickPoint();
|
|
ptOld = ptIns;
|
|
|
|
AcDbObjectId recordId = GetBlkIdByName((const TCHAR*)g_csInsBlkName);
|
|
|
|
if(dlg.m_csCurType == _T("水处理设备") || dlg.m_csCurType == _T("水处理构筑物"))
|
|
{
|
|
SHads_command(RTSTR, _T(".INSERT"), RTSTR, (const TCHAR*)g_csInsBlkName, RT3DPOINT, &ptIns,
|
|
RTREAL, jig.m_nSacle, RTREAL, jig.m_nSacle, RTREAL, Radian2Angle(g_nInsBlkRotate), RTNONE);
|
|
CString csTk, csRecord;
|
|
CString csDesName;
|
|
SplitBlkStr(g_csInsBlkName, csTk, csRecord);
|
|
csTk = g_csDwbPath + csTk + _T(".tk");
|
|
csDesName = GetBlkDesName(csRecord, csTk);
|
|
if(csDesName.Find(_T("(炸开)"), 0) >= 0){ //红叶做的动态图块
|
|
Entity entLast;
|
|
entLast.GetLast();
|
|
SHads_command(RTSTR,_T("explode"),RTENAME, (TLong_ptr*)entLast, RTNONE);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
TDbEquipment *pEquip = new TDbEquipment;
|
|
pEquip->SetBlock2d(recordId);
|
|
pEquip->SetLocation(ptIns);
|
|
|
|
double nElevation(0), nRotate2(0);
|
|
CString csDesName;
|
|
int iPipeIdx(0);
|
|
double nRotate = Ucs2Wcs(g_nInsBlkRotate);
|
|
if(dlg.m_csCurType == _T("消防附件")){
|
|
Entity entWire = GetPipeByPt(ptIns, nElevation, iPipeIdx);
|
|
if(!!entWire){
|
|
XPoint pt3, pt4;
|
|
GetPipePoint(entWire, pt3, pt4);
|
|
nRotate = ads_angle(pt3, pt4);
|
|
}
|
|
}
|
|
|
|
pEquip->SetAngle(nRotate);
|
|
pEquip->SetScale(jig.m_nSacle);
|
|
pEquip->SetSpare(0);
|
|
BOOL bIsBreak = FALSE;
|
|
if(dlg.m_csCurType == _T("消防附件")){
|
|
CString csTk, csRecord;
|
|
SplitBlkStr(g_csInsBlkName, csTk, csRecord);
|
|
csTk = g_csDwbPath + csTk + _T(".tk");
|
|
csDesName = GetBlkDesName(csRecord, csTk);
|
|
if(csDesName.Find(_T("喷淋")) < 0){
|
|
InitLayer(LAY_EQ_FIRE);
|
|
pEquip->setLayer(LAY_EQ_FIRE);
|
|
}
|
|
else{
|
|
InitLayer(LAY_EQUIP_SPRINKLE);
|
|
pEquip->setLayer(LAY_EQUIP_SPRINKLE);
|
|
}
|
|
if(csDesName.Find(_T("(打断)"), 0) >= 0)
|
|
bIsBreak = TRUE;
|
|
else
|
|
bIsBreak = FALSE;
|
|
}
|
|
else if(dlg.m_csCurType == _T("给水附件"))
|
|
{
|
|
InitLayer(LAY_EQ_FEED);
|
|
pEquip->setLayer(LAY_EQ_FEED);
|
|
}
|
|
else if(dlg.m_csCurType == _T("排水附件"))
|
|
{
|
|
InitLayer(LAY_EQ_DIRT);
|
|
pEquip->setLayer(LAY_EQ_DIRT);
|
|
}
|
|
else
|
|
{
|
|
pEquip->setLayer(InitLayer(LAY_EQ_OTHER));
|
|
}
|
|
pEquip->setColor(AcCmColor()); //随层
|
|
pEquip->SetHidePipe(bIsBreak);
|
|
|
|
if(jig.m_bReversal)
|
|
pEquip->MirrorByY(TRUE);
|
|
AddToCurrentSpace(pEquip, Adesk::kTrue);
|
|
|
|
if(csDesName.Find(_T("(炸开)"), 0) >= 0){ //消防图块 水泵结合器 2008-6-6
|
|
Entity entLast;
|
|
entLast.GetLast();
|
|
SHads_command(RTSTR,_T("explode"),RTENAME, (TLong_ptr*)entLast, RTNONE);
|
|
entLast.GetLast();
|
|
SHads_command(RTSTR,_T("explode"),RTENAME, (TLong_ptr*)entLast, RTNONE);
|
|
}
|
|
TPipePerDocData *pData = GetCurPipeDocData();
|
|
pData->ApplyUpdates();
|
|
continue;
|
|
}
|
|
}
|
|
else if(nRetCode == RTKWORD){
|
|
if(nKeyIndex == 0)
|
|
g_nInsBlkRotate += PI/2;
|
|
else if(nKeyIndex == 1)
|
|
bReversal = !bReversal;
|
|
if(nKeyIndex == 2)
|
|
nScale += 1;
|
|
else if(nKeyIndex == 3 && jig.m_nSacle > 1)
|
|
nScale -= 1;
|
|
else
|
|
break;
|
|
continue;
|
|
}
|
|
else{
|
|
g_nInsBlkRotate = 0;
|
|
dlg.DestroyWindow();
|
|
SHads_command(RTNONE);
|
|
return;
|
|
}
|
|
|
|
}
|
|
}
|
|
else if(dlg.m_iMode == 1){
|
|
PickSet ss(SS_FREE);
|
|
g_ssPickFirst.Free();
|
|
Entity entTmp;
|
|
AcDbObjectId idRef = NULL;
|
|
int ret = SelectEntities(_T("\n请选取图中要被替换的附件范围<插入附件>:"), ss, rbMask);
|
|
if(ret != RTNORM){
|
|
dlg.m_iMode = 0;
|
|
dlg.m_ToolBar.CheckButton(ID_BUTTON_INSEQ, 1);
|
|
continue;
|
|
}
|
|
ret = SelectEntity(_T("\n请选取图中要被替换的样板附件<全部替换>:"), entTmp, rbMask);
|
|
if(ret == RTNORM){
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForRead, TDbEquipment, pEquip);
|
|
if(pEquip)
|
|
idRef = pEquip->GetBlock2d();
|
|
OPENOBJ_END();
|
|
}
|
|
AcDbObjectId recordId = GetBlkIdByName(g_csInsBlkName);
|
|
long len = ss.Length();
|
|
for(long i=0;i<len;i++){
|
|
Entity ent = ss[i];
|
|
OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbEquipment, pEquip);
|
|
if(idRef && idRef != pEquip->GetBlock2d())
|
|
continue;
|
|
pEquip->SetBlock2d(recordId);
|
|
pEquip->SetScale(1);
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
else if(dlg.m_iMode == 2){
|
|
BuildEquipment(dlg.m_csCurType);
|
|
dlg.m_iMode = 0;
|
|
dlg.Reset();
|
|
}
|
|
|
|
}
|
|
g_nInsBlkRotate = 0;
|
|
dlg.DestroyWindow();
|
|
return;
|
|
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 任意洁具
|
|
//***************************************************************************************************
|
|
void BuildNewSanitary(const TCHAR* szType)
|
|
{
|
|
g_ssPickFirst.Free();
|
|
|
|
int nOsMode=0;
|
|
xg_getvar(_T("OSMODE"), &nOsMode);
|
|
nOsMode &= ~0x4000;
|
|
nOsMode |= OS_INT|OS_NEA|OS_PER|OS_END|OS_CEN |OS_MID;
|
|
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
|
|
|
PickSet ssSel(SS_FREE);
|
|
if(SelectEntities(_T("\n请选择要做成图块的图元<退出>:"), ssSel, RBList()) != RTNORM)
|
|
return;
|
|
|
|
ads_real xlen, ylen;
|
|
XPoint ptIns;
|
|
ssSel.GetExtend(ptIns, &xlen, &ylen);
|
|
ads_getpoint(ptIns, _T("\n请点选插入点 <中心点>:"), ptIns);
|
|
|
|
TCHAR dwgPrefix[256]=_T("");
|
|
GetTempPath(255, dwgPrefix);
|
|
if(dwgPrefix[_tcslen(dwgPrefix)-1]!=_T('\\'))
|
|
_tcscat(dwgPrefix, _T("\\"));
|
|
XString xsFullSld, xsFullDwg;
|
|
xsFullSld << dwgPrefix << _T("_ELECBLK") << _T(".sld");
|
|
xsFullDwg << dwgPrefix << _T("_ELECBLK") << _T(".dwg");
|
|
|
|
BOOL flag = TWBlock(ssSel, xsFullDwg, ptIns);
|
|
BuildSlide(ssSel, xsFullSld);
|
|
// arxZoomTo(ptIns, xlen, ylen);
|
|
// SHads_command(RTSTR, _T("MSLIDE"), RTSTR, (TCHAR *)xsFullSld, RTNONE);
|
|
// ZOOMP;
|
|
|
|
// AcApDocument* pDoc = acDocManager->curDocument();
|
|
// if (pDoc) {
|
|
// acDocManager->executeInApplicationContext(DoBuildSlide, (void *)(const TCHAR *)xsFullDwg);
|
|
// }
|
|
|
|
if(!flag){
|
|
AfxMessageBox(_T("造块失败!"));
|
|
return;
|
|
}
|
|
CString strPathTkName = g_csDwbPath + _T("Sanitary.tk");
|
|
if(AddNewDwg2Dwb(strPathTkName, (const TCHAR*)xsFullDwg, (const TCHAR*)xsFullSld, szType, _T("新图块")).IsEmpty()) {
|
|
AfxMessageBox(_T("没有正确加入图库!"));
|
|
return;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
void DoReplaceSanitary()
|
|
{
|
|
Entity entBlk;
|
|
RBList rbMask = ads_buildlist( -4, _T("<or"),
|
|
-4, _T("<and"), RTDXF0, _T("INSERT"), -4, _T("and>"),
|
|
-4, _T("<and"), RTDXF0, _T("AEC_BLOCK_INSERT"), -4, _T("and>"),
|
|
-4, _T("or>"), NULL);
|
|
|
|
|
|
if(SelectEntity(_T("\n请选择要替换的洁具(整图替换):<退出>"), entBlk, rbMask) != RTNORM)
|
|
return;
|
|
TCHAR szBlkName[256];
|
|
entBlk.GetData(2, szBlkName);
|
|
|
|
AcDbObjectId recordId = GetBlkIdByName(g_csInsBlkName);
|
|
|
|
RBList rbMask2(RTDXF0, _T("INSERT,AEC_BLOCK_INSERT"), 2, szBlkName, NULL);
|
|
PickSet ss(SS_FREE);
|
|
ss.Get(_T("X"), NULL, NULL, rbMask2);
|
|
for(long i=0;i<ss.Length();i++){
|
|
Entity entTmp = ss[i];
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForWrite, AcDbBlockReference, pBlk);
|
|
if(pBlk){
|
|
pBlk->setBlockTableRecord(recordId);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
UpdateGraphic(ss);
|
|
|
|
}
|
|
|
|
void InsSanitary()
|
|
{
|
|
xg_setvar(_T("CMDECHO"), 0); // zxl 2012.01.31 add
|
|
int nOsMode=0;
|
|
xg_getvar(_T("OSMODE"), &nOsMode);
|
|
nOsMode &= ~0x4000;
|
|
nOsMode |= OS_INT|OS_NEA;
|
|
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
|
CInsBlockDlg dlg(_T("Sanitary"), 3, acedGetAcadFrame());
|
|
{
|
|
CTemporaryResourceOverride vTemp;
|
|
dlg.Create(IDD_INS_TWT_BLK, acedGetAcadFrame());
|
|
dlg.ShowWindow(SW_SHOW);
|
|
acedGetAcadDwgView()->SetFocus();
|
|
}
|
|
g_nInsBlkRotate = 0;
|
|
XPoint ptIns, ptOld, ptTmp;
|
|
xg_getvar(_T("VIEWCTR"), ptIns);
|
|
ptIns = Ucs2Wcs(ptIns);
|
|
|
|
InitLayer(LAY_SANIWARE);
|
|
XPushVarStr clayer(_T("CLAYER"), LAY_SANIWARE);
|
|
|
|
double nScale = 1;
|
|
double nDist2Wall = 0;
|
|
BOOL bReversal = FALSE;
|
|
while(1){
|
|
ads_polar(ptIns, g_nInsBlkRotate + PI/2, nDist2Wall, ptTmp);
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(AcGeVector3d(ptIns[0] - ptTmp[0], ptIns[1] - ptTmp[1], 0));
|
|
|
|
TBlockEdJig jig(g_csInsBlkName, ptIns, nScale);
|
|
jig.m_mat = mat;
|
|
jig.SetPrompt(_T("\n请指定洁具的插入点 [90度旋转(A)/左右翻转(F)/放大(E)/缩小(D)/距墙距离(C)/替换(P)]<退出>:"));
|
|
jig.SetKeyword(_T("A F E D C P W R"));
|
|
jig.m_bReversal = bReversal;
|
|
if(!!ptOld)
|
|
jig.m_ptRef = ptOld;
|
|
int nKeyIndex = 0;
|
|
int nRetCode = jig.DoIt(&nKeyIndex);
|
|
if(nRetCode == RTNORM) {
|
|
ptIns = jig.GetPickPoint();
|
|
ptOld = ptIns;
|
|
ptIns.TransformBy(mat);
|
|
double nLen = jig.m_nSacle;
|
|
XPoint ptUcs = Wcs2Ucs(ptIns);
|
|
if(jig.m_bReversal)
|
|
SHads_command(RTSTR, _T(".INSERT"), RTSTR, (const TCHAR*)g_csInsBlkName, RT3DPOINT, &ptUcs,
|
|
RTREAL, -nLen, RTREAL, nLen, RTREAL, Radian2Angle(g_nInsBlkRotate), RTNONE);
|
|
else
|
|
SHads_command(RTSTR, _T(".INSERT"), RTSTR, (const TCHAR*)g_csInsBlkName, RT3DPOINT, &ptUcs,
|
|
RTREAL, nLen, RTREAL, nLen, RTREAL, Radian2Angle(g_nInsBlkRotate), RTNONE);
|
|
continue;
|
|
}
|
|
else if(nRetCode == RTKWORD){
|
|
if(nKeyIndex == 0)
|
|
g_nInsBlkRotate += PI/2;
|
|
else if(nKeyIndex == 1)
|
|
bReversal = !bReversal;
|
|
else if(nKeyIndex == 2)
|
|
nScale += 1;
|
|
else if(nKeyIndex == 3 && jig.m_nSacle > 1)
|
|
nScale -= 1;
|
|
else if(nKeyIndex == 4){
|
|
CString csPrompt;
|
|
csPrompt.Format(_T("\n请输入离墙距离:<%.0f>"), nDist2Wall);
|
|
ads_getreal(csPrompt, &nDist2Wall);
|
|
}
|
|
else if(nKeyIndex == 5){ //替换
|
|
DoReplaceSanitary();
|
|
continue;
|
|
}
|
|
else if(nKeyIndex == 6)
|
|
continue;
|
|
else if(nKeyIndex == 7){
|
|
BuildNewSanitary(dlg.m_csCurType);
|
|
dlg.m_iMode = 0;
|
|
dlg.Reset();
|
|
continue;
|
|
}
|
|
}
|
|
else{
|
|
g_nInsBlkRotate = 0;
|
|
dlg.DestroyWindow();
|
|
SHads_command(RTNONE);
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 造阀门
|
|
//***************************************************************************************************
|
|
void BuildValveCmd()
|
|
{
|
|
TCHAR szText[256] = _T("新阀门");
|
|
ads_getstring(0, _T("\n请输入新阀门的名称<新阀门>:"), szText);
|
|
CString csRecord1 = BuildValve(_T("平面阀门"), szText);
|
|
TCHAR szTmp[32];
|
|
ads_getstring(0, _T("\n是否继续造新阀门的系统图块<N>:"), szTmp);
|
|
if(_tcsicmp(szTmp, _T("Y")) != 0)
|
|
return;
|
|
CString csRecord2 = BuildValve(_T("系统阀门"), szText);
|
|
|
|
CString csName;
|
|
CodeBase db;
|
|
CString csTk = g_csDwbPath + _T("valve_U.tk");
|
|
|
|
XDbfTable *pTable = db.Open(csTk);
|
|
if(!pTable)
|
|
{
|
|
CString csTmp;
|
|
csTmp.Format(_T("%s文件只读或损坏!"), csTk);
|
|
AfxMessageBox(csTmp);
|
|
return;
|
|
}
|
|
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){
|
|
CString sDrawing, sItem;
|
|
GET_FIELD(pTable, _T("drawing"), sDrawing);
|
|
GET_FIELD(pTable, _T("item"), sItem);
|
|
if(_tcscmp(sDrawing, csRecord1) == 0) {
|
|
csName.Format(_T("%s-%s"), szText, csRecord2);
|
|
SET_FIELD(pTable, _T("item"), (const TCHAR*)csName);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 造附件
|
|
//***************************************************************************************************
|
|
void BuildAttchCmd()
|
|
{
|
|
TCHAR szText[32];
|
|
CString csTmp = _T("给水附件");
|
|
ads_getstring(0, _T("\n请输入连接方式1给水附件2排水附件3消防附件<给水附件>:"), szText);
|
|
if(_tcsicmp(szText, _T("2")) == 0)
|
|
csTmp = _T("排水附件");
|
|
else if(_tcsicmp(szText, _T("3")) == 0)
|
|
csTmp = _T("消防附件");
|
|
BuildEquipment(csTmp);
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 阀门阀件
|
|
//***************************************************************************************************
|
|
AcDbObjectId Get3dBlockByDesName(const TCHAR* szDesName)
|
|
{
|
|
if(!g_bBlk3D)
|
|
return NULL;
|
|
//平面阀门描述名一般为 名字+(三维记录)+“-”+系统记录
|
|
//如 通用阀门(00000623)-00000337
|
|
CString csDes = szDesName;
|
|
int idx = csDes.Find(_T("("));
|
|
int idx2 = csDes.Find(_T(")"));
|
|
if(idx < 0 || idx2 < 0)
|
|
return NULL;
|
|
CString csRecord = csDes.Mid(idx+1, 8);
|
|
XString xsTmp;
|
|
CString csDwb = g_csDwbPath + _T("VALVE");
|
|
if(LoadDwbBlock(csDwb, csRecord, xsTmp) != RTNORM)//跌水井
|
|
return NULL;
|
|
AcDbObjectId recordId3d = GetBlkIdByName(xsTmp);
|
|
return recordId3d;
|
|
}
|
|
|
|
|
|
// ss中管线是否在xy面投影线重合
|
|
BOOL IsSuperposablePipe(PickSet &ss)
|
|
{
|
|
long len = ss.Length();
|
|
Entity ent = ss[0L];
|
|
XPoint ptStart, ptEnd;
|
|
GetPipePoint(ent, ptStart, ptEnd);
|
|
ptStart.z =0;
|
|
ptEnd.z =0;
|
|
AcGeVector3d vt(ptEnd.x - ptStart.x, ptEnd.y - ptStart.y, 0);
|
|
|
|
for(long k=1;k<len;k++){
|
|
Entity entTmp = ss[k];
|
|
XPoint pts, pte;
|
|
GetPipePoint(entTmp, pts, pte);
|
|
pts.z =0;
|
|
pte.z =0;
|
|
AcGeVector3d vt2(pte.x - pts.x, pte.y - pts.y, 0);
|
|
if(!vt.isParallelTo(vt2))
|
|
return FALSE;
|
|
// if(ptStart != pts && ptStart != pte && ptEnd != pts && ptEnd != pte)
|
|
// return FALSE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void DoInsValveByPipe(XPoint ptIns, Entity entPipe, BOOL bReversal, double nScale, CString csLayer)
|
|
{
|
|
XCurveSegment seg;
|
|
TPipeSys::SysType sysType;
|
|
OPENOBJ_BEGIN(entPipe, AcDb::kForRead, TDbPipe, pPipe);
|
|
XCurveSegment seg2(pPipe->StartPoint(), pPipe->EndPoint(), 0);
|
|
seg2.ProjectToMe(ptIns, ptIns);
|
|
sysType = pPipe->GetSysType();
|
|
seg = seg2;
|
|
OPENOBJ_END();
|
|
|
|
AcDbObjectId recordId = GetBlockIdFromString(g_csInsBlkName);
|
|
CString csTk, csRecord, csDesName;
|
|
SplitBlkStr(g_csInsBlkName, csTk, csRecord);
|
|
csTk = g_csDwbPath + csTk + _T(".tk");
|
|
csDesName = GetBlkDesName(csRecord, csTk);
|
|
|
|
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;
|
|
|
|
// cet 2011.11.10 add 处理特殊块
|
|
bool bHorizontal = false;
|
|
if (g_csInsBlkName.CompareNoCase(_T("$VALVE$00000591")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000761")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000607")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000605")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000597")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000595")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000593")) == 0)
|
|
{
|
|
iQuadrant = bReversal ? 1 : 0;
|
|
bHorizontal = true;
|
|
}
|
|
|
|
double nWidth = GetValveWidth(g_csInsBlkName);
|
|
TDbPipeValve *pValve = new TDbPipeValve;
|
|
AcDbObjectId recordId3d = Get3dBlockByDesName((const TCHAR*)csDesName);
|
|
pValve->SetBlock3d(recordId3d);
|
|
pValve->SetBlock2d(recordId);
|
|
pValve->SetLocation(ptIns);
|
|
pValve->SetWidth(nWidth);
|
|
pValve->SetFlangeWidth(50);
|
|
pValve->SetSysBlock((const TCHAR*)csDesName);
|
|
pValve->SetScale(nScale);
|
|
pValve->SetYScale(nScale);
|
|
pValve->SetFlangeDn(200);
|
|
pValve->setLayer(csLayer);
|
|
pValve->setColor(AcCmColor()); //随层
|
|
pValve->SetDirection(vectBase);
|
|
pValve->SetQuadrant(iQuadrant);
|
|
pValve->SetSysType(sysType);
|
|
pValve->SetHorizontal(bHorizontal); // cet 2011.11.10 add
|
|
AddToCurrentSpace(pValve, Adesk::kTrue);
|
|
|
|
}
|
|
|
|
|
|
|
|
CString GetValveLayBySys(TPipeSys::SysType sys)
|
|
{
|
|
CString csRet;
|
|
if(sys == TPipeSys::kFeedWater || sys == TPipeSys::kFeedWater2 || sys == TPipeSys::kFeedWater3) // cet 2011.12.6 modify 增加中高区
|
|
csRet = LAY_VALVE_FEED;
|
|
else if(sys == TPipeSys::kHeatFeedWater || sys == TPipeSys::kHeatFeedWater2 || sys == TPipeSys::kHeatFeedWater3) // cet 2011.12.6 modify 增加中高区
|
|
csRet = LAY_VALVE_HEADFEED;
|
|
else if(sys == TPipeSys::kHeatBackWater || sys == TPipeSys::kHeatBackWater2 || sys == TPipeSys::kHeatBackWater3) // cet 2011.12.6 modify 增加中高区
|
|
csRet = LAY_VALVE_HEADBACK;
|
|
else if(sys == TPipeSys::kDirtWater)
|
|
csRet = LAY_VALVE_DIRT;
|
|
else if(sys == TPipeSys::kUselessWater)
|
|
csRet = LAY_VALVE_USELESS;
|
|
else if(sys == TPipeSys::kRainWater)
|
|
csRet = LAY_VALVE_RAIN;
|
|
else if(sys == TPipeSys::kUsedWater || sys == TPipeSys::kUsedWater2 || sys == TPipeSys::kUsedWater3) // cet 2011.12.6 modify 增加中高区
|
|
csRet = LAY_VALVE_USED;
|
|
else if(sys == TPipeSys::kFireFighting || sys == TPipeSys::kFireFighting2 || sys == TPipeSys::kFireFighting3) // cet 2011.12.6 modify 增加中高区
|
|
csRet = LAY_VALVE_FIRE;
|
|
else if(sys == TPipeSys::kSprinkle || sys == TPipeSys::kSprinkle2 || sys == TPipeSys::kSprinkle3) // cet 2011.12.6 modify 增加中高区
|
|
csRet = LAY_VALVE_SPRINKLE;
|
|
else if(sys == TPipeSys::kCoagulate)
|
|
csRet = LAY_VALVE_COAGULATE;
|
|
else if(sys == TPipeSys::kDrink)
|
|
csRet = LAY_VALVE_DRINK;
|
|
else if(sys == TPipeSys::kPressDirt)
|
|
csRet = LAY_VALVE_PRESSDIRT;
|
|
else if(sys == TPipeSys::kPressUseless)
|
|
csRet = LAY_VALVE_PRESSUSELESS;
|
|
else if(sys == TPipeSys::kPressRain)
|
|
csRet = LAY_VALVE_PRESSRAIN;
|
|
else if(sys == TPipeSys::kCivilFeed)
|
|
csRet = LAY_VALVE_USER1;
|
|
else if(sys == TPipeSys::kCycleFeed)
|
|
csRet = LAY_VALVE_USER2;
|
|
else if(sys == TPipeSys::kOther)
|
|
csRet = LAY_VALVE_OTHER;
|
|
else if(sys == TPipeSys::kUser3) // cet 2011.12.1 add user3-user8
|
|
{
|
|
csRet = LAY_VALVE_USER3;
|
|
}
|
|
else if(sys == TPipeSys::kUser4)
|
|
{
|
|
csRet = LAY_VALVE_USER4;
|
|
}
|
|
else if(sys == TPipeSys::kUser5)
|
|
{
|
|
csRet = LAY_VALVE_USER5;
|
|
}
|
|
else if(sys == TPipeSys::kUser6)
|
|
{
|
|
csRet = LAY_VALVE_USER6;
|
|
}
|
|
else if(sys == TPipeSys::kUser7)
|
|
{
|
|
csRet = LAY_VALVE_USER7;
|
|
}
|
|
else if(sys == TPipeSys::kUser8)
|
|
{
|
|
csRet = LAY_VALVE_USER8;
|
|
}
|
|
return csRet;
|
|
}
|
|
|
|
// 利用参考实体,过滤选择实体
|
|
void FiltrateValve(PickSet &ssRet, PickSet &ssBase, PickSet &ssSel)
|
|
{
|
|
std::set<CString> setBlkNames;
|
|
long nLen = ssBase.Length();
|
|
for (long i = 0; i < nLen; ++i)
|
|
{
|
|
OPENOBJ_BEGIN(ssBase[i], AcDb::kForRead, TDbPipeValve, pValve);
|
|
if (pValve != NULL)
|
|
{
|
|
setBlkNames.insert(GetBlkNameById(pValve->GetBlock2d()));
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
nLen = ssSel.Length();
|
|
CString sBlkName;
|
|
std::set<CString>::iterator it;
|
|
std::set<CString>::iterator itBegin = setBlkNames.begin();
|
|
std::set<CString>::iterator itEnd = setBlkNames.end();
|
|
for (long j = 0; j < nLen; ++j)
|
|
{
|
|
OPENOBJ_BEGIN(ssSel[j], AcDb::kForRead, TDbPipeValve, pValve);
|
|
if (pValve != NULL)
|
|
{
|
|
sBlkName = GetBlkNameById(pValve->GetBlock2d());
|
|
it = std::find(itBegin, itEnd, sBlkName);
|
|
if (it != itEnd)
|
|
{
|
|
ssRet += ssSel[j];
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
|
|
void InsValve(const TCHAR* szGj)
|
|
{
|
|
int nOsMode=0;
|
|
xg_getvar(_T("OSMODE"), &nOsMode);
|
|
nOsMode &= ~0x4000;
|
|
nOsMode |= OS_INT|OS_NEA;
|
|
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
|
int iOpenMode(-1);
|
|
CString csLayer;
|
|
CString csPrompt1, csPrompt2, csPrompt3;
|
|
CString sPrompt4;
|
|
if(_tcsicmp(szGj, _T("阀件")) == 0){
|
|
iOpenMode = 0;
|
|
csPrompt1 = _T("\n请指定阀件的插入点 [放大(E)/缩小(D)/左右翻转(F)]<退出>:");
|
|
csPrompt2 = _T("\n请指定阀件的插入方向<完成>:");
|
|
// cet 2012.11.20 modify
|
|
// csPrompt3 = _T("\n请选取图中要被替换的阀门(多选)<插入阀门>:");
|
|
csPrompt3 = _T("\n请选取图中要被替换的阀门(多选){替换同名阀门(S)}<插入阀门>:");
|
|
sPrompt4 = _T("\n请选择参考阀门<退出>");
|
|
}
|
|
else if(_tcsicmp(szGj, _T("管道附件")) == 0){
|
|
iOpenMode = 1;
|
|
csPrompt1 = _T("\n请指定附件的插入点 [放大(E)/缩小(D)/左右翻转(F)]<退出>:");
|
|
csPrompt2 = _T("\n请指定附件的插入方向<完成>:");
|
|
// cet 2012.11.22 modify
|
|
// csPrompt3 = _T("\n请选取图中要被替换的附件(多选)<插入附件>:");
|
|
csPrompt3 = _T("\n请选取图中要被替换的附件(多选){替换同名附件(S)}<插入附件>:");
|
|
sPrompt4 = _T("\n请选择参考附件<退出>");
|
|
}
|
|
else if(_tcsicmp(szGj, _T("仪表")) == 0){
|
|
iOpenMode = 5;
|
|
csPrompt1 = _T("\n请指定仪表的插入点 [放大(E)/缩小(D)/左右翻转(F)]<退出>:");
|
|
csPrompt2 = _T("\n请指定仪表的插入方向<完成>:");
|
|
// cet 2012.11.22 modify
|
|
// csPrompt3 = _T("\n请选取图中要被替换的仪表(多选)<插入仪表>:");
|
|
csPrompt3 = _T("\n请选取图中要被替换的仪表(多选){替换同名仪表(S)}<插入仪表>:");
|
|
sPrompt4 = _T("\n请选择参考仪表<退出>");
|
|
}
|
|
|
|
CInsBlockDlg dlg(_T("VALVE"), iOpenMode, 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);
|
|
|
|
RBList rbMask(RTDXF0, _T("ATS_PIPEVALVE"), NULL);
|
|
RBList rbMaskPipe(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管")), NULL);
|
|
adsout << XString(_T("当前阀门插入比例:%.1f\n"), g_nValveScale);
|
|
// InitLayer(csLayer);
|
|
while(1){
|
|
if(!dlg.m_bSuccess)
|
|
break;
|
|
BOOL bContinue = FALSE;
|
|
double nScale = g_nValveScale;
|
|
BOOL bReversal = FALSE;
|
|
if(dlg.m_iMode == 0){
|
|
while(1){
|
|
TBlockEdJig jig(g_csInsBlkName, ptIns, nScale);
|
|
jig.m_nSacle = nScale*(DocGetPScale()/100);
|
|
jig.m_nSacleY = nScale*(DocGetPScale()/100);
|
|
jig.SetPrompt(csPrompt1);//_T("\n请指定阀件的插入点 {放大[E]/缩小[D]/左右翻转[F]}<退出>:");
|
|
jig.SetKeyword(_T("E D F R"));
|
|
jig.m_bReversal = bReversal;
|
|
if(!!ptOld)
|
|
jig.m_ptRef = ptOld;
|
|
int nKeyIndex = 0;
|
|
int nRetCode = jig.DoIt(&nKeyIndex);
|
|
if(nRetCode == RTNORM) {
|
|
ptIns = jig.GetPickPoint();
|
|
break;
|
|
}
|
|
else if(nRetCode == RTKWORD){
|
|
if(nKeyIndex == 0)
|
|
nScale += 0.5;
|
|
else if(nKeyIndex == 1 && jig.m_nSacle > 1)
|
|
nScale -= 0.5;
|
|
else if(nKeyIndex == 2)
|
|
bReversal = !bReversal;
|
|
else{
|
|
bContinue = TRUE;
|
|
break;
|
|
}
|
|
}
|
|
else{
|
|
g_nInsBlkRotate = 0;
|
|
dlg.DestroyWindow();
|
|
SHads_command(RTNONE);
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
if(bContinue)
|
|
continue;
|
|
XPoint ptUcs = Wcs2Ucs(ptIns);
|
|
PickSet ss(SS_FREE);
|
|
GetPointPickSet(ptUcs, ss, rbMaskPipe, int(0.5*DocGetPScale()));
|
|
double nn = ss.Length();
|
|
if(ss.Length() == 0)
|
|
GetPointPickSet(ptUcs, ss, rbMaskPipe, int(1.5*DocGetPScale()));
|
|
|
|
if(ss.Length() != 1){
|
|
if(IsSuperposablePipe(ss)){
|
|
for(long k=0;k<ss.Length();k++){
|
|
Entity entTmp = ss[k];
|
|
XPoint pts, pte;
|
|
GetPipePoint(entTmp, pts, pte);
|
|
ptIns.z = pts.z;
|
|
DoInsValveByPipe(ptIns, entTmp, bReversal, nScale, csLayer);
|
|
}
|
|
}
|
|
continue;
|
|
}
|
|
Entity entPipe = ss[0L];
|
|
|
|
|
|
XCurveSegment seg;
|
|
TPipeSys::SysType sysType;
|
|
OPENOBJ_BEGIN(entPipe, AcDb::kForRead, TDbPipe, pPipe);
|
|
if(pPipe){
|
|
XCurveSegment seg2(pPipe->StartPoint(), pPipe->EndPoint(), 0);
|
|
// seg2.ProjectToMe(ptIns, ptIns);
|
|
|
|
AcGePoint3d p1 = ptIns;
|
|
if(!pPipe->IsVertical())
|
|
p1.z = pPipe->StartPoint().z;
|
|
AcGePoint3d p2;
|
|
pPipe->getClosestPointTo(p1,p2);
|
|
ptIns = p2;
|
|
|
|
sysType = pPipe->GetSysType();
|
|
seg = seg2;
|
|
}
|
|
OPENOBJ_END();
|
|
ptOld = ptIns;
|
|
|
|
AcDbObjectId recordId = GetBlockIdFromString(g_csInsBlkName);
|
|
CString csTk, csRecord, csDesName;
|
|
SplitBlkStr(g_csInsBlkName, csTk, csRecord);
|
|
csTk = g_csDwbPath + csTk + _T(".tk");
|
|
csDesName = GetBlkDesName(csRecord, csTk);
|
|
|
|
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;
|
|
|
|
if(dlg.m_bNeedRotate){
|
|
AcGeVector3d vect = vectBase;
|
|
g_nInsBlkRotate = vect.angleTo(AcGeVector3d(1,0,0));
|
|
TBlockEdJig jig(g_csInsBlkName, ptIns, nScale, vect);
|
|
jig.SetPrompt(csPrompt2);//_T("\n请指定阀件的插入方向<完成>:")
|
|
int nKeyIndex2 = 0;
|
|
if(jig.DoIt(&nKeyIndex2) == RTNORM){
|
|
iQuadrant = jig.m_iQuadrant;
|
|
if(vectOld.y < -0.000001
|
|
||(vectOld.y<0.000001&&vectOld.y>=-0.000001&&vectOld.x<0)){ //管线逆向绘制
|
|
if(iQuadrant == 0)
|
|
iQuadrant = 2;
|
|
else if(iQuadrant == 1)
|
|
iQuadrant = 3;
|
|
else if(iQuadrant == 2)
|
|
iQuadrant = 0;
|
|
else if(iQuadrant == 3)
|
|
iQuadrant = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
// cet 2011.11.10 add 处理特殊块
|
|
bool bHorizontal = false;
|
|
if (g_csInsBlkName.CompareNoCase(_T("$VALVE$00000591")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000761")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000607")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000605")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000597")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000595")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000593")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000777")) == 0) // cet 2013.1.5 add 添加防虫网罩"$VALVE$00000777"
|
|
{
|
|
iQuadrant = bReversal ? 1 : 0;
|
|
// 允许用户选择图块方向 cet 2012.9.6 modify
|
|
// bHorizontal = true;
|
|
static std::map<CString,bool> mapDir;
|
|
bool bInit = false;
|
|
if (!bInit)
|
|
{
|
|
bInit = true;
|
|
// 默认全部水平布置
|
|
mapDir.insert(std::make_pair(CString(_T("$VALVE$00000591")), false));
|
|
mapDir.insert(std::make_pair(CString(_T("$VALVE$00000761")), false));
|
|
mapDir.insert(std::make_pair(CString(_T("$VALVE$00000607")), false));
|
|
mapDir.insert(std::make_pair(CString(_T("$VALVE$00000605")), false));
|
|
mapDir.insert(std::make_pair(CString(_T("$VALVE$00000597")), false));
|
|
mapDir.insert(std::make_pair(CString(_T("$VALVE$00000595")), false));
|
|
mapDir.insert(std::make_pair(CString(_T("$VALVE$00000593")), false));
|
|
mapDir.insert(std::make_pair(CString(_T("$VALVE$00000777")), false)); // cet 2013.1.5 add 添加防虫网罩"$VALVE$00000777"
|
|
}
|
|
|
|
std::map<CString,bool>::iterator it;
|
|
it = mapDir.find(g_csInsBlkName);
|
|
if(it->second) // 垂直
|
|
{
|
|
TCHAR szKey[10];
|
|
int nRet = RTNORM;
|
|
INITGET_BEG(0, _T("Y N"));
|
|
nRet = acedGetKword(_T("\n是否需要垂直管线处理<Y>"), szKey);
|
|
INITGET_END();
|
|
bHorizontal = false;
|
|
if (nRet == RTNORM && szKey[0] == _T('N'))
|
|
{
|
|
bHorizontal = true;
|
|
it->second = false;
|
|
}
|
|
}
|
|
else // 水平
|
|
{
|
|
TCHAR szKey[10];
|
|
int nRet = RTNORM;
|
|
INITGET_BEG(0, _T("Y N"));
|
|
nRet = acedGetKword(_T("\n是否需要垂直管线处理<N>"), szKey);
|
|
INITGET_END();
|
|
bHorizontal = true;
|
|
if (nRet == RTNORM && szKey[0] == _T('Y') )
|
|
{
|
|
bHorizontal = false;
|
|
it->second = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
csLayer = GetValveLayBySys(sysType);
|
|
InitLayer(csLayer);
|
|
double nWidth = GetValveWidth(g_csInsBlkName);
|
|
TDbPipeValve *pValve = new TDbPipeValve;
|
|
AcDbObjectId recordId3d = Get3dBlockByDesName((const TCHAR*)csDesName);
|
|
pValve->SetBlock3d(recordId3d);
|
|
pValve->SetBlock2d(recordId);
|
|
pValve->SetLocation(ptIns);
|
|
pValve->SetWidth(nWidth);
|
|
pValve->SetFlangeWidth(50);
|
|
pValve->SetSysBlock((const TCHAR*)csDesName);
|
|
pValve->SetScale(nScale);
|
|
pValve->SetYScale(nScale);
|
|
pValve->SetFlangeDn(200);
|
|
pValve->setLayer(csLayer);
|
|
pValve->setColor(AcCmColor()); //随层
|
|
pValve->SetDirection(vectBase);
|
|
pValve->SetQuadrant(iQuadrant);
|
|
pValve->SetSysType(sysType);
|
|
pValve->SetHorizontal(bHorizontal); // cet 2011.11.10 add 水平放置
|
|
AcDbObjectId idNew = AddToCurrentSpace(pValve, Adesk::kTrue);
|
|
|
|
}
|
|
else if(dlg.m_iMode == 1){
|
|
PickSet ss(SS_FREE);
|
|
g_ssPickFirst.Free();
|
|
// cet 2012.11.20 modify
|
|
// int ret = SelectEntities(csPrompt3, ss, rbMask);//_T("\n请选取图中要被替换的阀门(多选)<替换所有同名阀门>:")
|
|
// if(ret != RTNORM){
|
|
// dlg.m_iMode = 0;
|
|
// dlg.m_ToolBar.CheckButton(ID_BUTTON_INSVALVE, 1);
|
|
// continue;
|
|
// }
|
|
TCHAR chKey;
|
|
int nRet = SelectEntities(csPrompt3, ss, rbMask, _T("S"), chKey);
|
|
if (nRet == RTKWORD)
|
|
{
|
|
// 选择参考实体
|
|
PickSet ssBase(SS_FREE);
|
|
if(SelectEntities(sPrompt4, ssBase, rbMask) != RTNORM)
|
|
{
|
|
dlg.m_iMode = 0;
|
|
dlg.m_ToolBar.CheckButton(ID_BUTTON_INSVALVE, 1);
|
|
continue;
|
|
}
|
|
|
|
PickSet ssSel(SS_FREE);
|
|
int nSel = SelectEntities(_T("\n请选择范围{选择pline(P)/全图(A)}<退出>"), ssSel, rbMask, _T("P A"), chKey);
|
|
if (nSel == RTKWORD)
|
|
{
|
|
if (chKey == _T('p') || chKey == _T('P'))
|
|
{
|
|
Entity entPoly;
|
|
RBList rbMask2(RTDXF0, _T("LWPOLYLINE"), 8, _T("*"), NULL);
|
|
if(SelectEntity(_T("\n请选择表示范围的闭合PLINE:<退出>"), entPoly, rbMask2) != RTNORM)
|
|
{
|
|
dlg.m_iMode = 0;
|
|
dlg.m_ToolBar.CheckButton(ID_BUTTON_INSVALVE, 1);
|
|
continue;
|
|
}
|
|
XPoly2D poly2(entPoly);
|
|
XPoint ptLow3, ptUp3;
|
|
poly2.GetExtend(ptLow3, ptUp3);;
|
|
poly2.TransUCS(Groups(0), Groups(1));//Groups(0) wcs, Groups(1) ucs
|
|
RBList rbFence = poly2.Fence();
|
|
//AssureInCurrentView(ptLow3, ptUp3); cet 2011.12.31 add
|
|
AssureInCurrentView_New(ptLow3, ptUp3);
|
|
ssSel.Get(_T("CP"), rbFence, NULL, rbMask);
|
|
}
|
|
else
|
|
{
|
|
ssSel.Get(_T("X"), NULL, NULL, rbMask);
|
|
}
|
|
}
|
|
else if (nSel != RTNORM)
|
|
{
|
|
dlg.m_iMode = 0;
|
|
dlg.m_ToolBar.CheckButton(ID_BUTTON_INSVALVE, 1);
|
|
continue;
|
|
}
|
|
|
|
FiltrateValve(ss, ssBase, ssSel);
|
|
}
|
|
else if (nRet != RTNORM)
|
|
{
|
|
dlg.m_iMode = 0;
|
|
dlg.m_ToolBar.CheckButton(ID_BUTTON_INSVALVE, 1);
|
|
continue;
|
|
}
|
|
|
|
AcDbObjectId recordId = GetBlockIdFromString(g_csInsBlkName);
|
|
// cet 2011.11.10 add 处理特殊块
|
|
bool bSpecBlk = false;
|
|
if (g_csInsBlkName.CompareNoCase(_T("$VALVE$00000591")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000761")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000607")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000605")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000597")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000595")) == 0
|
|
|| g_csInsBlkName.CompareNoCase(_T("$VALVE$00000593")) == 0)
|
|
{
|
|
bSpecBlk = true;
|
|
}
|
|
|
|
double nWidth = GetValveWidth(g_csInsBlkName);
|
|
long len = ss.Length();
|
|
for(long i=0;i<len;i++){
|
|
Entity ent = ss[i];
|
|
OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbPipeValve, pValve);
|
|
pValve->SetBlock2d(recordId);
|
|
pValve->SetWidth(nWidth);
|
|
if (bSpecBlk) // cet 2011.11.10 add 处理特殊块
|
|
{
|
|
pValve->SetQuadrant(0);
|
|
pValve->SetHorizontal(TRUE);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
else if(dlg.m_iMode == 2){
|
|
if(dlg.m_bIsPlan)
|
|
BuildValve(dlg.m_csPlanType, _T("新图块"));
|
|
else
|
|
BuildValve(dlg.m_csSysType, _T("新图块"));
|
|
dlg.m_iMode = 0;
|
|
dlg.Reset();
|
|
}
|
|
TPipePerDocData *pData=GetCurPipeDocData();
|
|
pData->ApplyUpdates();
|
|
}
|
|
g_nInsBlkRotate = 0;
|
|
dlg.DestroyWindow();
|
|
return;
|
|
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 阀门阀件
|
|
//***************************************************************************************************
|
|
|
|
void CmdValve()
|
|
{
|
|
InsValve(_T("阀件"));
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 管道附件
|
|
//***************************************************************************************************
|
|
|
|
void CmdPipeAttachment()
|
|
{
|
|
InsValve(_T("管道附件"));
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 仪表
|
|
//***************************************************************************************************
|
|
void InsTwtMeter()
|
|
{
|
|
InsValve(_T("仪表"));
|
|
}
|
|
|
|
CString BlockName2SldName(const TCHAR* szBlkName)
|
|
{
|
|
CString csTk, csRecord, csRet;
|
|
SplitBlkStr(szBlkName, csTk, csRecord);
|
|
csRet.Format(_T("%s(%s)"), csTk, csRecord);
|
|
return csRet;
|
|
}
|
|
|
|
|
|
//***************************************************************************************************
|
|
// 设备缩放
|
|
//***************************************************************************************************
|
|
//CString GetEquipBlkName(Entity ent)
|
|
//{
|
|
//
|
|
// CString csRet;
|
|
// OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbEquipment, pEquip);
|
|
// if(pEquip){
|
|
// const TCHAR *szBlkName = NULL;
|
|
// AcDbObjectId eqId = pEquip->GetBlock2d();
|
|
// OPENOBJ_BEGIN(eqId, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
|
|
// if(pRecord)
|
|
// pRecord->getName(szBlkName);
|
|
// OPENOBJ_END();
|
|
// csRet = szBlkName;
|
|
// }
|
|
// OPENOBJ_END();
|
|
// OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipeValve, pValve);
|
|
// if(pValve){
|
|
// const TCHAR *szBlkName = NULL;
|
|
// AcDbObjectId eqId = pValve->GetBlock2d();
|
|
// OPENOBJ_BEGIN(eqId, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
|
|
// if(pRecord)
|
|
// pRecord->getName(szBlkName);
|
|
// OPENOBJ_END();
|
|
// csRet = szBlkName;
|
|
// }
|
|
// OPENOBJ_END();
|
|
// if(ent.Is(_T("INSERT"))){
|
|
// TCHAR szBlkName[256];
|
|
// ent.GetData(2, szBlkName);
|
|
// csRet = szBlkName;
|
|
// }
|
|
// return csRet;
|
|
//}
|
|
|
|
double GetEquipScale(Entity ent)
|
|
{
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbEquipment, pEquip);
|
|
if(pEquip){
|
|
return pEquip->GetScale();
|
|
}
|
|
OPENOBJ_END();
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipeValve, pValve);
|
|
if(pValve){
|
|
return pValve->GetScale();
|
|
}
|
|
OPENOBJ_END();
|
|
if(ent.Is(_T("INSERT"))){
|
|
double nScale;
|
|
ent.GetData(41, &nScale);
|
|
return nScale;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
//cet 2010.1.22 add
|
|
//获取雨水口依附的线
|
|
bool GetGullyLine(double dAngle, XPoint ptLoc, PickSet &ssName, RBList &rbMask, double dDist, AcDbObjectId &idLine)
|
|
{
|
|
//选择线
|
|
AcGeVector3d vtX = AcGeVector3d::kXAxis;
|
|
AcGeVector3d vtY;
|
|
vtX.rotateBy(dAngle,AcGeVector3d::kZAxis);
|
|
vtY = vtX;
|
|
vtY.rotateBy(PI/2, AcGeVector3d::kZAxis);
|
|
|
|
XPoint ptGeLB, ptGeLT, ptGeRT, ptGeRB;
|
|
ptGeLB = ptLoc - vtX *dDist / 2;
|
|
ptGeLB = ptGeLB - vtY * dDist / 2;
|
|
ptGeLT = ptGeLB + vtY * dDist;
|
|
ptGeRB = ptGeLB + vtX * dDist;
|
|
ptGeRT = ptGeRB + vtY * dDist;
|
|
|
|
|
|
TADSGePoint3d _pt1 = Wcs2Ucs(ptGeLB)
|
|
, _pt2 = Wcs2Ucs(ptGeLT)
|
|
, _pt3 = Wcs2Ucs(ptGeRT)
|
|
, _pt4 = Wcs2Ucs(ptGeRB);
|
|
RBList rbPt = acutBuildList(RTPOINT, &_pt1, RTPOINT, &_pt2, RTPOINT, &_pt3, RTPOINT, &_pt4, NULL);
|
|
|
|
acedSSGet(_T("CP"),rbPt,NULL,rbMask,ssName);
|
|
|
|
//检查选择集中是否有唯一一条线经过PtLoc点
|
|
Adesk::Int32 lLen = 0;
|
|
acedSSLength(ssName, &lLen);
|
|
int nCount = 0;
|
|
AcDbCurve *pCurve = NULL;
|
|
ads_name ssName2;
|
|
AcDbObjectId idEnt;
|
|
AcGePoint3d ptNearest;
|
|
for (int i = 0; i < lLen; i++)
|
|
{
|
|
acedSSName(ssName, i, ssName2);
|
|
acdbGetObjectId(idEnt, ssName2);
|
|
acdbOpenObject(pCurve, idEnt, AcDb::kForRead);
|
|
if(pCurve != NULL)
|
|
{
|
|
pCurve->getClosestPointTo(ptLoc, ptNearest);
|
|
if (ptLoc.Distance(ptNearest) < 1e-3)
|
|
{
|
|
idLine = idEnt;
|
|
nCount++;
|
|
}
|
|
pCurve->close();
|
|
}
|
|
}
|
|
|
|
if (nCount == 1)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
//cet 2010.1.15 add
|
|
//获取雨水口id和与其相连线的id,以便缩放后调整雨水口位置
|
|
void GetGullyAndRefLine(const PickSet &ssEquip, std::map<AcDbObjectId,AcDbObjectId> &mapId)
|
|
{
|
|
//获取缩放雨水口的id
|
|
std::vector<AcDbObjectId> EquId; //保存缩放雨水口的id
|
|
|
|
XPoint xptMin, xptMax;
|
|
ssEquip.GetExtend(xptMin, xptMax);
|
|
AssureInCurrentView_New(xptMin, xptMax);
|
|
|
|
long len = ssEquip.Length();
|
|
for(long i=0;i<len;i++)
|
|
{
|
|
Entity entTmp = ssEquip[i];
|
|
AcDbObjectId idEnt;
|
|
acdbGetObjectId(idEnt, entTmp);
|
|
|
|
TCHAR szName[50];
|
|
CString strName;
|
|
entTmp.GetData(2, szName);
|
|
strName = szName;
|
|
//"$TwtSys$00000425" 和"$TwtSys$00000424"为雨水口图块名
|
|
//if (strName.Compare(_T("$TwtSys$00000424")) == 0 || strName.Compare(_T("$TwtSys$00000425")) == 0) //zxl 2011.09.16 modify 新增雨水口类型
|
|
if (strName.Compare(_T("$TwtSys$00000424")) == 0 || strName.Compare(_T("$TwtSys$00000425")) == 0
|
|
|| strName.Compare(_T("$TwtSys$00000527")) == 0 || strName.Compare(_T("$TwtSys$00000528")) == 0)
|
|
{
|
|
EquId.push_back(idEnt);
|
|
}
|
|
}
|
|
|
|
//获取与雨水口相关联的线id
|
|
if (!EquId.empty())
|
|
{
|
|
std::vector<AcDbObjectId>::iterator iterEqu;
|
|
TDbEquipment *pEquip = NULL;
|
|
RBList rbMask = ads_buildlist(RTDXF0, _T("LINE,ARC,LWPOLYLINE,CIRCLE"), NULL);
|
|
Entity ent;
|
|
AcDbObjectId idEnt;
|
|
for (iterEqu = EquId.begin(); iterEqu != EquId.end(); iterEqu++)
|
|
{
|
|
//获取图块名
|
|
ads_name sName;
|
|
acdbGetAdsName(sName, *iterEqu);
|
|
Entity entTmp(sName);
|
|
TCHAR szName[50];
|
|
CString strName;
|
|
entTmp.GetData(2, szName);
|
|
strName = szName;
|
|
|
|
acdbOpenObject(pEquip, *iterEqu, AcDb::kForRead);
|
|
if(pEquip != NULL)
|
|
{
|
|
AcGePoint3d ptLoc = pEquip->GetLocation();
|
|
double dWidth = 0.0, dHeight = 0.0;
|
|
|
|
//根据雨水口类型获取其宽度
|
|
double dScale = pEquip->GetScale();
|
|
GetBlkRecordWidth(strName, dScale, dScale, dWidth, dHeight);
|
|
|
|
// XPoint xptMin, xptMax;
|
|
// pEquip->GetExtents(xptMin, xptMax);
|
|
double dAngle = pEquip->GetAngle();
|
|
pEquip->Close();
|
|
|
|
AcGeVector3d vtHor = AcGeVector3d::kXAxis;
|
|
vtHor.rotateBy(dAngle, AcGeVector3d::kZAxis); //向量与雨水口方向平行
|
|
vtHor.rotateBy(PI / 2, AcGeVector3d::kZAxis); //向量与雨水口方向垂直
|
|
|
|
//由于无法确定雨水口的方向,故取得雨水口上与其
|
|
//方向平行的两条边的中点, 以便获取经过两点之一
|
|
//的线(LINE, ARC, PLINE, CIRCLE)
|
|
dWidth = dWidth * DocGetPScale() / 100;
|
|
|
|
// AssureInCurrentView_New(xptMin, xptMax);
|
|
|
|
PickSet ssName1(SS_FREE), ssName2(SS_FREE);
|
|
|
|
XPoint ptTemp1 = ptLoc - vtHor * dWidth;
|
|
XPoint ptTemp2 = ptLoc + vtHor * dWidth;
|
|
|
|
AcDbObjectId idLine1, idLine2;
|
|
bool bSuc1 = false, bSuc2 = false;
|
|
bSuc1 = GetGullyLine(dAngle, ptTemp1, ssName1, rbMask, dWidth, idLine1);
|
|
bSuc2 = GetGullyLine(dAngle, ptTemp2, ssName2, rbMask, dWidth, idLine2);
|
|
|
|
if (bSuc1 && !bSuc2)
|
|
{
|
|
mapId.insert(std::pair<AcDbObjectId,AcDbObjectId>(*iterEqu, idLine1));
|
|
}
|
|
else if (!bSuc1 && bSuc2)
|
|
{
|
|
mapId.insert(std::pair<AcDbObjectId,AcDbObjectId>(*iterEqu, idLine2));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//cet 2010.1.15 add
|
|
//修正雨水口位置
|
|
void ModifyGullyPos(std::map<AcDbObjectId,AcDbObjectId> &mapId)
|
|
{
|
|
std::map<AcDbObjectId,AcDbObjectId>::iterator iter;
|
|
AcDbObjectId idEqu, idLine;
|
|
TDbEquipment *pEquip = NULL;
|
|
AcDbCurve *pCurve = NULL;
|
|
|
|
AcGeVector3d vtr(0, 0, 0);
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(vtr);
|
|
double dDist = 0; //设备到线的距离
|
|
AcDbObjectId idEnt1; //获取雨水口ID
|
|
for (iter = mapId.begin(); iter != mapId.end(); iter++)
|
|
{
|
|
idEqu = iter->first;
|
|
idLine = iter->second;
|
|
|
|
//获取图块名
|
|
ads_name sName;
|
|
acdbGetAdsName(sName, idEqu);
|
|
Entity entTmp(sName);
|
|
TCHAR szName[50];
|
|
CString strName;
|
|
entTmp.GetData(2, szName);
|
|
strName = szName;
|
|
|
|
acdbOpenObject(pEquip, idEqu, AcDb::kForWrite);
|
|
if(pEquip != NULL)
|
|
{
|
|
//根据雨水口类型获取其宽度
|
|
double dEquWidth = 0.0, dHeight = 0.0;
|
|
double dScale = pEquip->GetScale();
|
|
GetBlkRecordWidth(strName, dScale, dScale, dEquWidth, dHeight);
|
|
dEquWidth = dEquWidth * DocGetPScale() / 100;
|
|
AcGePoint3d ptLoc = asPnt3d(pEquip->GetLocation());
|
|
|
|
//因线(LINE, ARC, PLINE, CIRCLE)的父类是AcDbCurve
|
|
//可统一以AcDbCurve形式打开
|
|
acdbOpenObject(pCurve, idLine, AcDb::kForRead);
|
|
if (pCurve != NULL)
|
|
{
|
|
AcGePoint3d ptPro;
|
|
pCurve->getClosestPointTo(ptLoc, ptPro);
|
|
dDist = ptPro.distanceTo(ptLoc) - dEquWidth;
|
|
vtr = ptPro - ptLoc;
|
|
vtr.normalize();
|
|
vtr = vtr * dDist; //设备缩放后修改位置时移动的方向和距离
|
|
mat.setToTranslation(vtr);
|
|
pEquip->transformBy(mat);
|
|
|
|
pCurve->close();
|
|
}
|
|
|
|
pEquip->close();
|
|
|
|
//修改管线坐标
|
|
int nNum = pEquip->GetInterfaceNum();
|
|
for (int i = 0; i < nNum; i++)
|
|
{
|
|
idEnt1 = pEquip->GetIPipe(i);
|
|
TDbPipe *pPipe = NULL;
|
|
acdbOpenObject(pPipe, idEnt1, AcDb::kForWrite);
|
|
if (pPipe != NULL)
|
|
{
|
|
for (int j = 0; j < 2; j++)
|
|
{
|
|
idEnt1 = pPipe->GetNode(j);
|
|
|
|
if (pEquip->objectId() == idEnt1)
|
|
{
|
|
if (j == 0)
|
|
{
|
|
pPipe->SetStartPoint(pEquip->GetLocation());
|
|
}
|
|
else
|
|
{
|
|
pPipe->SetEndPoint(pEquip->GetLocation());
|
|
}
|
|
}
|
|
}
|
|
pPipe->close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void ScaleEquipment()
|
|
{
|
|
g_ssPickFirst.Free();
|
|
RBList rbMask = ads_buildlist( -4, _T("<or"),
|
|
-4, _T("<and"), RTDXF0, _T("INSERT"), 8, LAY_TWT_TREE, -4, _T("and>"),
|
|
-4, _T("<and"), RTDXF0, _T("ATS_EQUIPMENT"), 8, _T("*"), -4, _T("and>"),
|
|
-4, _T("<and"), RTDXF0, _T("ATS_PIPEVALVE"), 8, _T("*"), -4, _T("and>"),
|
|
-4, _T("or>"), NULL);
|
|
|
|
// RBList rbMask(RTDXF0, _T("ATS_EQUIPMENT"), 8, _T("*"), NULL);
|
|
Entity entEquip;
|
|
PickSet ssEquip(SS_FREE);
|
|
PickSet ssAll(SS_FREE);
|
|
|
|
int ret;
|
|
BOOL flag = FALSE;
|
|
BOOL IsUniform = FALSE;
|
|
ret = SelectEntities(_T("请选取要缩放的设备<缩放所有同名设备>:"), ssEquip, rbMask);
|
|
if(ret == RTCAN)
|
|
return;
|
|
if(ret != RTNORM){ //缩放所有同名设备
|
|
if(SelectEntity(_T("请选取要缩放的样板设备<退出>:"), entEquip, rbMask) != RTNORM)
|
|
return;
|
|
flag = TRUE;
|
|
ssAll.Get(_T("X"), NULL, NULL, rbMask);
|
|
CString csBlkName = GetEquipBlkName(entEquip);
|
|
double nEqScale = GetEquipScale(entEquip);
|
|
long lenAll = ssAll.Length();
|
|
for(long j=0;j<lenAll;j++){
|
|
Entity entTmp = ssAll[j];
|
|
CString csName = GetEquipBlkName(entTmp);
|
|
double nEqScale2 = GetEquipScale(entTmp);
|
|
if(csName == csBlkName){
|
|
if(nEqScale != nEqScale2)
|
|
IsUniform = TRUE;
|
|
ssEquip += entTmp;
|
|
}
|
|
}
|
|
}
|
|
ssEquip.Redraw(3);
|
|
double nScale(1);
|
|
ads_getreal(_T("\n请输入缩放比例 <1>"), &nScale);
|
|
if(nScale == 1 && !IsUniform){
|
|
ssEquip.Redraw(4);
|
|
return;
|
|
}
|
|
UNDOB;
|
|
long len = ssEquip.Length();
|
|
XPushVar<int> vOsMode(_T("OSMODE"), 0);
|
|
//cet 2010.1.15 add
|
|
//获取设备id和与其相连线的id,以便缩放后调整设备位置
|
|
std::map<AcDbObjectId, AcDbObjectId> mapId;
|
|
GetGullyAndRefLine(ssEquip, mapId);
|
|
|
|
for(long i=0;i<len;i++){
|
|
Entity entTmp = ssEquip[i];
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForWrite, TDbEquipment, pEquip);
|
|
if(pEquip){
|
|
double nOld = pEquip->GetScale();
|
|
pEquip->SetScale(nScale * nOld);
|
|
pEquip->SetYScale(nScale * nOld);
|
|
XPoint p1, p2;
|
|
p1 = pEquip->GetLocation();
|
|
p2 = pEquip->GetInsert();
|
|
if(p1 != p2){
|
|
AcDbExtents extents;
|
|
pEquip->getGeomExtents(extents);
|
|
AcGePoint3d pMax = extents.maxPoint();
|
|
AcGePoint3d pMin = extents.minPoint();
|
|
XPoint ptCen;
|
|
ptCen[0] = (pMax[0] + pMin[0]) / 2;
|
|
ptCen[1] = (pMax[1] + pMin[1]) / 2;
|
|
ptCen[2] = 0;
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(AcGeVector3d(p1[0] - ptCen[0], p1[1] - ptCen[1], 0));
|
|
p2.TransformBy(mat);
|
|
|
|
// cet 2011.3.21 add
|
|
CString strBlkName = GetBlkNameById(pEquip->GetBlock2d());
|
|
if (strBlkName.CompareNoCase(_T("$TWTSYS$00000386")) == 0 && !pEquip->IsAutoScale())
|
|
{
|
|
p2 = pEquip->GetInsert();
|
|
mat.setToTranslation(AcGeVector3d(p2[0] - p1[0], p2[1] - p1[1], 0) * (nScale - 1));
|
|
p2.TransformBy(mat);
|
|
}
|
|
|
|
pEquip->SetInsert(p2);
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForWrite, TDbPipeValve, pValve);
|
|
if(pValve){
|
|
double nOld = pValve->GetScale();
|
|
pValve->SetScale(nScale * nOld);
|
|
pValve->SetYScale(nScale * pValve->GetYScale());
|
|
}
|
|
OPENOBJ_END();
|
|
if(entTmp.Is(_T("INSERT"))){
|
|
double nOld(1);
|
|
entTmp.GetData(41, &nOld);
|
|
entTmp.SetData(41, nScale * nOld);
|
|
entTmp.SetData(42, nScale * nOld);
|
|
entTmp.SetData(43, nScale * nOld);
|
|
entTmp.Modify();
|
|
}
|
|
}
|
|
|
|
if(IsUniform){
|
|
if(SelectEntity(_T("同一设备存在不同比例,是否统一比例?请选取正确比例的样板设备<不统一比例>:"), entEquip, rbMask) != RTNORM)
|
|
{
|
|
//cet 2010.1.21 add
|
|
//调整设备缩放后的位置使其保持与线的相对位置关系,并调整与设备相连管线位置
|
|
ModifyGullyPos(mapId);
|
|
return;
|
|
}
|
|
double nEqScale = GetEquipScale(entEquip);
|
|
for(long i=0;i<len;i++){
|
|
Entity entTmp = ssEquip[i];
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForWrite, TDbEquipment, pEquip);
|
|
if(pEquip){
|
|
pEquip->SetScale(nEqScale);
|
|
pEquip->SetYScale(nEqScale);
|
|
}
|
|
OPENOBJ_END();
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForWrite, TDbPipeValve, pValve);
|
|
if(pValve){
|
|
pValve->SetScale(nEqScale);
|
|
pValve->SetYScale(nEqScale);
|
|
}
|
|
OPENOBJ_END();
|
|
if(entTmp.Is(_T("INSERT"))){
|
|
entTmp.SetData(41, nEqScale);
|
|
entTmp.SetData(42, nEqScale);
|
|
entTmp.SetData(43, nEqScale);
|
|
entTmp.Modify();
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
//cet 2010.1.15 add
|
|
//调整设备缩放后的位置使其保持与线的相对位置关系,并调整与设备相连管线位置
|
|
ModifyGullyPos(mapId);
|
|
UNDOE;
|
|
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 三四通阀
|
|
//***************************************************************************************************
|
|
|
|
void Ins34CornerValave()
|
|
{
|
|
int nOsMode=0;
|
|
xg_getvar(_T("OSMODE"), &nOsMode);
|
|
nOsMode &= ~0x4000;
|
|
nOsMode |= OS_INT;
|
|
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
|
RBList rbMask(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管")), NULL);
|
|
XPoint ptPick;
|
|
CString csDwb = g_csDwbPath + _T("TwtSys");
|
|
XString xsTmp;
|
|
if(ads_getpoint(NULL, _T("\n请点取管线的交叉点<退出>:"), ptPick) != RTNORM)
|
|
return;
|
|
PickSet ss(SS_FREE);
|
|
GetPointPickSet(ptPick, ss, rbMask, 50);
|
|
ptPick = Ucs2Wcs(ptPick);
|
|
long len = ss.Length();
|
|
if(len != 4 && len != 3){
|
|
ads_alert(_T("\n点取位置不正确!没有发现3根以上管线。"));
|
|
return;
|
|
}
|
|
XPoint ptInt;
|
|
XLine l1(1), l2(1), l3(1), l4(1);
|
|
for(long i=0;i<len;i++){
|
|
Entity ent = ss[i];
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe);
|
|
if(pPipe){
|
|
if(pPipe->IsVertical())
|
|
return;
|
|
if(i==0)
|
|
l1 = XLine(pPipe->StartPoint(), pPipe->EndPoint(), 1);
|
|
else if(i==1)
|
|
l2 = XLine(pPipe->StartPoint(), pPipe->EndPoint(), 1);
|
|
else if(i==2)
|
|
l3 = XLine(pPipe->StartPoint(), pPipe->EndPoint(), 1);
|
|
else if(i==3)
|
|
l4 = XLine(pPipe->StartPoint(), pPipe->EndPoint(), 1);
|
|
|
|
double nDist1 = ads_distance(ptPick, pPipe->GetStartPoint());
|
|
double nDist2 = ads_distance(ptPick, pPipe->GetEndPoint());
|
|
XPoint ptTmp = nDist1 > nDist2 ? pPipe->EndPoint() : pPipe->StartPoint();
|
|
if(!ptInt)
|
|
ptInt = ptTmp;
|
|
else if(ptTmp != ptInt)
|
|
return;
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
double nRotate(0);
|
|
CString csSysName;
|
|
if(len == 3){
|
|
if(LoadDwbBlock(csDwb, _T("00000213"), xsTmp) != RTNORM) //三通阀
|
|
return;
|
|
csSysName = _T("TWTSYS(00000224)");
|
|
if(Is2LineOnLine(l1, l2)){
|
|
AcGeVector3d vect1(l1.StartPoint().x - l1.EndPoint().x, l1.StartPoint().y - l1.EndPoint().y, 0);
|
|
AcGeVector3d vect2(l3.StartPoint().x - l3.EndPoint().x, l3.StartPoint().y - l3.EndPoint().y, 0);
|
|
vect1.normalize();
|
|
vect2.normalize();
|
|
nRotate = vect1.angleTo(vect2, AcGeVector3d::kZAxis);
|
|
if(fabs(nRotate - PI/2) < 0.001 || fabs(nRotate - PI/2*3) < 0.001){
|
|
XPoint ptTmp = ptInt == l3.StartPoint() ? l3.EndPoint() : l3.StartPoint();
|
|
nRotate = ads_angle(ptInt, ptTmp) - PI/2;
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
else if(Is2LineOnLine(l1, l3)){
|
|
AcGeVector3d vect1(l1.StartPoint().x - l1.EndPoint().x, l1.StartPoint().y - l1.EndPoint().y, 0);
|
|
AcGeVector3d vect2(l2.StartPoint().x - l2.EndPoint().x, l2.StartPoint().y - l2.EndPoint().y, 0);
|
|
vect1.normalize();
|
|
vect2.normalize();
|
|
nRotate = vect1.angleTo(vect2, AcGeVector3d::kZAxis);
|
|
if(fabs(nRotate - PI/2) < 0.001 || fabs(nRotate - PI/2*3) < 0.001){
|
|
XPoint ptTmp = ptInt == l2.StartPoint() ? l2.EndPoint() : l2.StartPoint();
|
|
nRotate = ads_angle(ptInt, ptTmp) - PI/2;
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
else if(Is2LineOnLine(l2, l3)){
|
|
AcGeVector3d vect1(l1.StartPoint().x - l1.EndPoint().x, l1.StartPoint().y - l1.EndPoint().y, 0);
|
|
AcGeVector3d vect2(l2.StartPoint().x - l2.EndPoint().x, l2.StartPoint().y - l2.EndPoint().y, 0);
|
|
vect1.normalize();
|
|
vect2.normalize();
|
|
nRotate = vect1.angleTo(vect2, AcGeVector3d::kZAxis);
|
|
if(fabs(nRotate - PI/2) < 0.001 || fabs(nRotate - PI/2*3) < 0.001){
|
|
XPoint ptTmp = ptInt == l1.StartPoint() ? l1.EndPoint() : l1.StartPoint();
|
|
nRotate = ads_angle(ptInt, ptTmp) - PI/2;
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
else if(len == 4){
|
|
csSysName = _T("TWTSYS(00000216)");
|
|
|
|
if(LoadDwbBlock(csDwb, _T("00000214"), xsTmp) != RTNORM) //四通阀
|
|
return;
|
|
if(Is2LineOnLine(l1, l2) && Is2LineOnLine(l3, l4)){
|
|
AcGeVector3d vect1(l1.StartPoint().x - l1.EndPoint().x, l1.StartPoint().y - l1.EndPoint().y, 0);
|
|
AcGeVector3d vect2(l3.StartPoint().x - l3.EndPoint().x, l3.StartPoint().y - l3.EndPoint().y, 0);
|
|
vect1.normalize();
|
|
vect2.normalize();
|
|
nRotate = vect1.angleTo(vect2, AcGeVector3d::kZAxis);
|
|
if(fabs(nRotate - PI/2) < 0.001 || fabs(nRotate - PI/2*3) < 0.001){
|
|
nRotate = ads_angle(l1.GetStartPoint(), l1.GetEndPoint());
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
else if(Is2LineOnLine(l1, l3) && Is2LineOnLine(l2, l4)){
|
|
AcGeVector3d vect1(l1.StartPoint().x - l1.EndPoint().x, l1.StartPoint().y - l1.EndPoint().y, 0);
|
|
AcGeVector3d vect2(l2.StartPoint().x - l2.EndPoint().x, l2.StartPoint().y - l2.EndPoint().y, 0);
|
|
vect1.normalize();
|
|
vect2.normalize();
|
|
nRotate = vect1.angleTo(vect2, AcGeVector3d::kZAxis);
|
|
if(fabs(nRotate - PI/2) < 0.001 || fabs(nRotate - PI/2*3) < 0.001){
|
|
nRotate = ads_angle(l1.GetStartPoint(), l1.GetEndPoint());
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
else if(Is2LineOnLine(l1, l4) && Is2LineOnLine(l2, l3)){
|
|
AcGeVector3d vect1(l1.StartPoint().x - l1.EndPoint().x, l1.StartPoint().y - l1.EndPoint().y, 0);
|
|
AcGeVector3d vect2(l2.StartPoint().x - l2.EndPoint().x, l2.StartPoint().y - l2.EndPoint().y, 0);
|
|
vect1.normalize();
|
|
vect2.normalize();
|
|
nRotate = vect1.angleTo(vect2, AcGeVector3d::kZAxis);
|
|
if(fabs(nRotate - PI/2) < 0.001 || fabs(nRotate - PI/2*3) < 0.001){
|
|
nRotate = ads_angle(l1.GetStartPoint(), l1.GetEndPoint());
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
else
|
|
return;
|
|
}
|
|
|
|
|
|
InitLayer(LAY_EQUIP_VALVE);
|
|
AcDbObjectId recordId = GetBlkIdByName((const TCHAR*)xsTmp);
|
|
TDbEquipment *pEquip = new TDbEquipment;
|
|
pEquip->SetBlock2d(recordId);
|
|
pEquip->SetHidePipe(TRUE);
|
|
pEquip->SetSysBlock((const TCHAR*)csSysName);
|
|
pEquip->SetLocation(ptInt);
|
|
pEquip->SetAngle(nRotate);
|
|
pEquip->setLayer(LAY_EQUIP_VALVE);
|
|
pEquip->setColor(AcCmColor()); //随层
|
|
AddToCurrentSpace(pEquip, Adesk::kTrue);
|
|
|
|
}
|
|
|
|
|
|
//***************************************************************************************************
|
|
// 角阀
|
|
//***************************************************************************************************
|
|
|
|
void InsCornerValave()
|
|
{
|
|
int nOsMode=0;
|
|
xg_getvar(_T("OSMODE"), &nOsMode);
|
|
nOsMode &= ~0x4000;
|
|
nOsMode |= OS_INT;
|
|
XPushVar<int> vOsMode(_T("OSMODE"), nOsMode);
|
|
RBList rbMask(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管")), NULL);
|
|
XPoint ptPick;
|
|
CString csDwb = g_csDwbPath + _T("TwtSys");
|
|
XString xsTmp;
|
|
if(LoadDwbBlock(csDwb, _T("00000378"), xsTmp) != RTNORM) //角阀
|
|
return;
|
|
|
|
if(ads_getpoint(NULL, _T("\n请点取管线的交叉点<退出>:"), ptPick) != RTNORM)
|
|
return;
|
|
PickSet ss(SS_FREE);
|
|
GetPointPickSet(ptPick, ss, rbMask, 50);
|
|
ptPick = Ucs2Wcs(ptPick);
|
|
long len = ss.Length();
|
|
if(len != 2)
|
|
return;
|
|
Entity ent1 = ss[0L];
|
|
Entity ent2 = ss[1L];
|
|
XPoint ptInt;
|
|
XLine l1(1), l2(1);
|
|
OPENOBJ_BEGIN(ent1, AcDb::kForRead, TDbPipe, pPipe);
|
|
if(pPipe){
|
|
if(pPipe->IsVertical())
|
|
return;
|
|
l1 = XLine(pPipe->StartPoint(), pPipe->EndPoint(), 1);
|
|
}
|
|
OPENOBJ_END();
|
|
OPENOBJ_BEGIN(ent2, AcDb::kForRead, TDbPipe, pPipe);
|
|
if(pPipe){
|
|
if(pPipe->IsVertical())
|
|
return;
|
|
l2 = XLine(pPipe->StartPoint(), pPipe->EndPoint(), 1);
|
|
}
|
|
OPENOBJ_END();
|
|
l1.Intersection(&l2, ptInt);
|
|
if(!ptInt)
|
|
return;
|
|
|
|
AcGeVector3d vect1(l1.StartPoint().x - l1.EndPoint().x, l1.StartPoint().y - l1.EndPoint().y, 0);
|
|
AcGeVector3d vect2(l2.StartPoint().x - l2.EndPoint().x, l2.StartPoint().y - l2.EndPoint().y, 0);
|
|
vect1.normalize();
|
|
vect2.normalize();
|
|
double nRotate = vect1.angleTo(vect2, AcGeVector3d::kZAxis);
|
|
if(fabs(nRotate - PI/2) < 0.001 || fabs(nRotate - PI/2*3) < 0.001){
|
|
XPoint ptTmp = ptInt == l1.StartPoint() ? l1.EndPoint() : l1.StartPoint();
|
|
nRotate = ads_angle(ptInt, ptTmp) + PI/2;
|
|
}
|
|
else
|
|
return;
|
|
InitLayer(LAY_EQUIP_VALVE);
|
|
AcDbObjectId recordId = GetBlkIdByName((const TCHAR*)xsTmp);
|
|
TDbEquipment *pEquip = new TDbEquipment;
|
|
pEquip->SetBlock2d(recordId);
|
|
pEquip->SetHidePipe(FALSE);
|
|
pEquip->SetSysBlock(_T("TWTSYS(00000378)"));
|
|
pEquip->SetLocation(ptInt);
|
|
pEquip->SetAngle(nRotate);
|
|
pEquip->setLayer(LAY_EQUIP_VALVE);
|
|
pEquip->setColor(AcCmColor()); //随层
|
|
AddToCurrentSpace(pEquip, Adesk::kTrue);
|
|
Entity entLast;
|
|
entLast.GetLast();
|
|
|
|
int itype = -1;
|
|
double dAng(0);
|
|
XPoint ptend, ptMid1, ptMid2;
|
|
l1.MidPoint(ptMid1);
|
|
l2.MidPoint(ptMid2);
|
|
ads_prompt(_T("\n请动态拖动阀门插入角度:<确定>"));
|
|
while(1){
|
|
struct resbuf pointbuf;
|
|
int iRet = ads_grread(5, &itype, &pointbuf);//得到动态点pointbuf
|
|
ads_point_set(pointbuf.resval.rpoint, ptend);//ptend动态点,也就是引出支线的结束点
|
|
if(itype != 5)
|
|
break;
|
|
|
|
double nDist1 = ads_distance(ptend, ptMid1);
|
|
double nDist2 = ads_distance(ptend, ptMid2);
|
|
if(nDist1 < nDist2){
|
|
XPoint ptTmp = ptInt == l1.StartPoint() ? l1.EndPoint() : l1.StartPoint();
|
|
dAng = ads_angle(ptInt, ptTmp) + PI/2;
|
|
}
|
|
else{
|
|
XPoint ptTmp = ptInt == l2.StartPoint() ? l2.EndPoint() : l2.StartPoint();
|
|
dAng = ads_angle(ptInt, ptTmp) + PI/2;
|
|
}
|
|
OPENOBJ_BEGIN(entLast, AcDb::kForWrite, TDbEquipment, pEquip);
|
|
if(pEquip){
|
|
pEquip->SetAngle(dAng);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
|
|
|
|
//***************************************************************************************************
|
|
// 改接线点 2007-2-28 SR 取消命令
|
|
//***************************************************************************************************
|
|
void ChangeBlkInsPt()
|
|
{
|
|
Entity ent;
|
|
RBList rbMask(RTDXF0, _T("ATS_EQUIPMENT"), 8, _T("*"), NULL);
|
|
if(SelectEntity(_T("\n请选择上华设备<退出>:"), ent, rbMask) == RTNORM){
|
|
XPoint ptIns, ptOld;
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbEquipment, pEquip);
|
|
if(pEquip){
|
|
int num = pEquip->GetInterfaceNum();
|
|
if(num < 1)
|
|
return;
|
|
ptIns = pEquip->GetLocation();
|
|
}
|
|
OPENOBJ_END();
|
|
ptOld = ptIns;
|
|
if(ads_getpoint(ptIns, _T("\n请点选新的接线点<取消>:"), ptIns) != RTNORM)
|
|
return;
|
|
ptIns = Ucs2Wcs(ptIns);
|
|
OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbEquipment, pEquip);
|
|
if(pEquip){
|
|
pEquip->SetLocation(ptIns);
|
|
int num = pEquip->GetInterfaceNum();
|
|
for(int i=0;i<num;i++){
|
|
TPipeInterface face;
|
|
pEquip->GetInterface(i, face);
|
|
AcDbObjectId PipeId = face.m_idPipe;
|
|
OPENOBJ_BEGIN(PipeId, AcDb::kForWrite, TDbPipe, pPipe);
|
|
if(pPipe){
|
|
XPoint ptS, ptE;
|
|
if(pPipe->StartPoint() == ptOld)
|
|
pPipe->SetStartPoint(ptIns);
|
|
else if(pPipe->EndPoint() == ptOld)
|
|
pPipe->SetEndPoint(ptIns);
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
//***************************************************************************************************
|
|
// 喷头转化
|
|
//***************************************************************************************************
|
|
|
|
void SprinklerConv()
|
|
{
|
|
//RBList rbMask(RTDXF0, _T("INSERT"), 8, _T("P_PL_PT"), NULL);
|
|
PickSet ss(SS_FREE);
|
|
PickSet ssdel(SS_FREE);
|
|
CString csDwb = g_csDwbPath + _T("TwtSys");
|
|
XString xsTmp, xsTmp3, xsTmp4;
|
|
if(LoadDwbBlock(csDwb, _T("00000125"), xsTmp) != RTNORM)
|
|
return;
|
|
if(g_bBlk3D){
|
|
if(LoadDwbBlock(csDwb, _T("00000365"), xsTmp3) != RTNORM)
|
|
return;
|
|
if(LoadDwbBlock(csDwb, _T("00000366"), xsTmp4) != RTNORM)
|
|
return;
|
|
}
|
|
CString m_csSysBlk1 = _T("TWTSYS(00000283)");
|
|
Entity entTemp;
|
|
RBList rbMask(RTDXF0, _T("INSERT,CIRCLE"), NULL);
|
|
if(SelectEntity(_T("\n请选择需要转化的样板喷头(圆或者图块):<退出>"), entTemp, rbMask) != RTNORM)
|
|
return;
|
|
TCHAR szLay[256];
|
|
entTemp.GetData(8, szLay);
|
|
BOOL bIsCircle = FALSE;
|
|
double dRadius(0);
|
|
if(entTemp.Is(_T("CIRCLE"))){
|
|
entTemp.GetData(40, &dRadius);
|
|
bIsCircle = TRUE;
|
|
RBList rbMask2(RTDXF0, _T("CIRCLE"), 8, szLay, NULL);
|
|
if(SelectEntities(_T("\n请选择需要转化的范围:<退出>"), ss, rbMask2) != RTNORM)
|
|
return;
|
|
}
|
|
else{
|
|
TCHAR szName[256];
|
|
entTemp.GetData(2, szName);
|
|
// if(!(_tcsicmp(szName, _T("PM_PTB")) == 0 || _tcsicmp(szName, _T("PM_PTA")) == 0 || _tcsicmp(szName, _T("xpt")) == 0|| _tcsicmp(szName, _T("$QC003_0")) == 0))
|
|
// return;
|
|
|
|
|
|
RBList rbMask2(RTDXF0, _T("INSERT"), 8, szLay, 2, szName, NULL);
|
|
if(SelectEntities(_T("\n请选择需要转化的范围:<退出>"), ss, rbMask2) != RTNORM)
|
|
return;
|
|
}
|
|
if(ss.Length() < 1)
|
|
return;
|
|
|
|
|
|
long len = ss.Length();
|
|
for(long i=0;i<len;i++){
|
|
Entity ent = ss[i];
|
|
|
|
double nScale;
|
|
XPoint ptLoc;
|
|
TCHAR szName[256];
|
|
if(ent.Is(_T("INSERT"))){
|
|
ent.GetData(2, szName);
|
|
// if(!(_tcsicmp(szName, _T("PM_PTB")) == 0 || _tcsicmp(szName, _T("PM_PTA")) == 0 || _tcsicmp(szName, _T("xpt")) == 0))
|
|
// continue;
|
|
|
|
AcDbExtents extents;
|
|
AcGeScale3d scale(1);
|
|
double x = 0, y = 0;
|
|
AcDbObjectId idBlk = GetBlockIdFromString(szName);
|
|
GetInsertExtend(idBlk, x, y);
|
|
|
|
ent.GetData(41, &nScale);
|
|
|
|
nScale = nScale*x/2.0;
|
|
nScale = nScale*100/DocGetPScale();
|
|
ent.GetData(10, ptLoc);
|
|
}
|
|
else{
|
|
double dRadius2(0);
|
|
ent.GetData(40, &nScale);
|
|
ent.GetData(10, ptLoc);
|
|
if(fabs(nScale - dRadius) > 0.001)
|
|
continue;
|
|
}
|
|
ptLoc.z = 0;
|
|
|
|
|
|
TDbEquipment *pEquip = new TDbEquipment;
|
|
pEquip->SetBlock2d(GetBlkIdByName(xsTmp));
|
|
|
|
|
|
if(_tcsicmp(szName, _T("PM_PTB")) == 0){ //上喷
|
|
pEquip->SetHidePipe(TRUE);
|
|
pEquip->SetPipeLength(250);
|
|
pEquip->SetBlock3d(GetBlkIdByName(xsTmp4));
|
|
}
|
|
else{
|
|
pEquip->SetHidePipe(FALSE);
|
|
pEquip->SetBlock3d(GetBlkIdByName(xsTmp3));
|
|
pEquip->SetPipeLength(-250);
|
|
}
|
|
|
|
pEquip->SetLocation(ptLoc);
|
|
pEquip->SetAngle(0);
|
|
// if(ent.Is(_T("INSERT")))
|
|
// pEquip->SetScale(nScale*g_nSprinklerRadius);
|
|
// else
|
|
pEquip->SetScale(nScale);
|
|
|
|
pEquip->SetSysBlock(m_csSysBlk1);
|
|
pEquip->setLayer(InitLayer(LAY_EQUIP_SPRINKLE));
|
|
pEquip->setColor(AcCmColor()); //随层
|
|
AddToCurrentSpace(pEquip, Adesk::kTrue);
|
|
ssdel += ent;
|
|
}
|
|
|
|
adsout << XString(_T("共有%d个喷头被转化为上华喷头"), ssdel.Length());
|
|
ssdel.Erase();
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 附件翻转
|
|
//***************************************************************************************************
|
|
void ReversalEquip()
|
|
{
|
|
g_ssPickFirst.Free();
|
|
PickSet ss(SS_FREE);
|
|
RBList rbMask(RTDXF0, _T("ATS_EQUIPMENT"), NULL);
|
|
|
|
if(SelectEntities(_T("\n请选择要翻转的附件:<退出>"), ss, rbMask) == RTNORM){
|
|
|
|
long len = ss.Length();
|
|
for(long i=0;i<len;i++)
|
|
{
|
|
Entity entSel = ss[i];
|
|
CString csBlkName = GetEquipBlkName(entSel);
|
|
CString csTk, csRecord, csDesName, csAllTk;
|
|
SplitBlkStr(csBlkName, csTk, csRecord);
|
|
csAllTk.Format(_T("%s%s.tk"), g_csDwbPath, (const TCHAR*)csTk);
|
|
|
|
XString xsTmpSys;
|
|
csDesName = GetBlkDesName((const TCHAR*)csRecord, (const TCHAR*)csAllTk);
|
|
csDesName = csDesName.Right(8);
|
|
csDesName = GetBlkDesName((const TCHAR*)csDesName, (const TCHAR*)csAllTk);
|
|
csDesName = csDesName.Right(8);
|
|
if(csDesName == _T("")){
|
|
TCHAR szText[32];
|
|
ads_getstring(0, _T("\n左右翻转<N上下翻转>(Y): "), szText);
|
|
OPENOBJ_BEGIN(entSel, AcDb::kForWrite, TDbEquipment, pEquip);
|
|
if(pEquip){
|
|
if(_tcsicmp(szText, _T("N")) == 0)
|
|
pEquip->MirrorByX(!pEquip->IsMirrorByX());
|
|
else
|
|
pEquip->MirrorByY(!pEquip->IsMirrorByY());
|
|
}
|
|
OPENOBJ_END();
|
|
continue;
|
|
}
|
|
csDesName = csTk + _T("(") + csDesName + _T(")");
|
|
|
|
if(LoadDwbBlock((const TCHAR*)csDesName, xsTmpSys) == RTNORM){
|
|
AcDbObjectId sysBlkId = GetBlkIdByName((const TCHAR*)xsTmpSys);
|
|
OPENOBJ_BEGIN(entSel, AcDb::kForWrite, TDbEquipment, pEquip);
|
|
if(pEquip){
|
|
pEquip->SetBlock2d(sysBlkId);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//***************************************************************************************************
|
|
// 洁具入库
|
|
//***************************************************************************************************
|
|
|
|
BOOL BlockInLib(Entity entBlk, const TCHAR* szFileName)
|
|
{
|
|
AcDbObjectId Id = NULL;
|
|
acdbGetObjectId(Id, entBlk);
|
|
AcDbBlockReference *pBlkRef = NULL;
|
|
acdbOpenObject(pBlkRef, Id, AcDb::kForRead);
|
|
if(!pBlkRef)
|
|
return FALSE;
|
|
AcGeMatrix3d matrix = pBlkRef->blockTransform();
|
|
pBlkRef->close();
|
|
matrix = matrix.inverse();
|
|
|
|
XPoint ptIns2;
|
|
entBlk.GetData(10, ptIns2);
|
|
AcGePoint3d ptIns = ptIns2;
|
|
ptIns = ptIns.transformBy(matrix);
|
|
|
|
TCHAR szBlkName[256];
|
|
entBlk.GetData(2, szBlkName);
|
|
AcDbBlockTableRecord *pRecord = NULL;
|
|
AcDbBlockTable* pBlockTable = NULL;
|
|
acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead);
|
|
if(!pBlockTable)
|
|
return FALSE;
|
|
if(Acad::eOk != pBlockTable->getAt(szBlkName, pRecord, AcDb::kForRead)){
|
|
pBlockTable->close();
|
|
return FALSE;
|
|
}
|
|
pBlockTable->close();
|
|
if(!pRecord)
|
|
return FALSE;
|
|
AcDbBlockTableRecordIterator *pIterator;
|
|
pRecord->newIterator(pIterator);
|
|
pRecord->close();
|
|
if(!pIterator)
|
|
return FALSE;
|
|
|
|
AcDbObjectIdArray cloneSet;
|
|
for(pIterator->start(); !pIterator->done(); pIterator->step()){
|
|
AcDbEntity *pEnt = NULL;
|
|
pIterator->getEntity(pEnt, AcDb::kForRead);
|
|
if(pEnt){
|
|
AcDbObjectId id = pEnt->objectId();
|
|
cloneSet.append(id);
|
|
pEnt->close();
|
|
}
|
|
}
|
|
delete pIterator;
|
|
|
|
|
|
AcDbDatabase db;
|
|
AcDbObjectId idMSpace = db.currentSpaceId();
|
|
AcDbIdMapping idMap;
|
|
acdbCurDwg()->wblockCloneObjects(cloneSet, idMSpace, idMap, AcDb::kDrcIgnore, false);
|
|
AcDbBlockTable *pTable = NULL;
|
|
db.getBlockTable(pTable, AcDb::kForRead);
|
|
if(!pTable)
|
|
return FALSE;
|
|
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(AcGeVector3d(-ptIns[0], -ptIns[1], -ptIns[2]));
|
|
AcDbBlockTableRecord *pBlockTableRecord = NULL;
|
|
VERIFY(pTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForRead)==Acad::eOk);
|
|
pTable->close();
|
|
if(!pBlockTableRecord)
|
|
return FALSE;
|
|
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
|
|
|
pBlockTableRecord->newIterator(pBlockIterator);
|
|
if(!pBlockIterator){
|
|
pBlockTableRecord->close();
|
|
return FALSE;
|
|
}
|
|
for(pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step()) {
|
|
AcDbEntity *pEnt = NULL;
|
|
pBlockIterator->getEntity(pEnt,AcDb::kForWrite);
|
|
if(pEnt){
|
|
pEnt->setLayer(_T("0"));
|
|
pEnt->transformBy(mat);
|
|
pEnt->close();
|
|
}
|
|
}
|
|
delete pBlockIterator;
|
|
pBlockTableRecord->close();
|
|
#if (ADS>15)
|
|
acdbSaveAs2000(&db, szFileName);
|
|
#else
|
|
db.saveAs(szFileName);
|
|
#endif
|
|
return TRUE;
|
|
}
|
|
|
|
void SanitaryInLib()
|
|
{
|
|
Entity entBlk;
|
|
RBList rbMask(RTDXF0, _T("INSERT"), 8, _T("*"), NULL);
|
|
|
|
if(SelectEntity(_T("\n请选择已经定义好的洁具:<退出>"), entBlk, rbMask) != RTNORM)
|
|
return;
|
|
TCHAR dwgPrefix[256]=_T("");
|
|
GetTempPath(255, dwgPrefix);
|
|
if(dwgPrefix[_tcslen(dwgPrefix)-1]!=_T('\\'))
|
|
_tcscat(dwgPrefix, _T("\\"));
|
|
XString xsFullSld, xsFullDwg;
|
|
xsFullSld << dwgPrefix << _T("_ELECBLK") << _T(".sld");
|
|
xsFullDwg << dwgPrefix << _T("_ELECBLK") << _T(".dwg");
|
|
if(!BlockInLib(entBlk, xsFullDwg))
|
|
return;
|
|
TCHAR szBlkName[256];
|
|
if(ads_getstring(0, _T("\n请输入洁具的名称:<新洁具>"), szBlkName) != RTNORM)
|
|
_tcscpy(szBlkName, _T("新洁具"));
|
|
if(_tcsicmp(szBlkName, _T("")) == 0)
|
|
_tcscpy(szBlkName, _T("新洁具"));
|
|
PickSet ssSel(SS_FREE);
|
|
ssSel += entBlk;
|
|
// AcApDocument* pDoc = acDocManager->curDocument();
|
|
// if (pDoc) {
|
|
// acDocManager->executeInApplicationContext(DoBuildSlide, (void *)(const TCHAR *)xsFullDwg);
|
|
// }
|
|
XPoint ptIns;
|
|
double xlen, ylen;
|
|
ssSel.GetExtend(ptIns, &xlen, &ylen);
|
|
BuildSlide(ssSel, xsFullSld);
|
|
// arxZoomTo(ptIns, xlen, ylen);
|
|
// SHads_command(RTSTR, _T("MSLIDE"), RTSTR, (TCHAR *)xsFullSld, RTNONE);
|
|
// ZOOMP;
|
|
|
|
CString csPathTkName = g_csDwbPath + _T("TwtSys.tk");
|
|
if(AddNewDwg2Dwb(csPathTkName, (const TCHAR*)xsFullDwg, (const TCHAR*)xsFullSld, _T("用户洁具"), szBlkName).IsEmpty()) {
|
|
AfxMessageBox(_T("没有正确加入图库!"));
|
|
}
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 镜像洁具转换
|
|
//***************************************************************************************************
|
|
|
|
void MirrorSantitary()
|
|
{
|
|
RBList rbMask(RTDXF0, _T("INSERT"), 8, _T("*"), NULL);
|
|
PickSet ssAll(SS_FREE);
|
|
ssAll.Get(_T("X"), NULL, NULL, rbMask);
|
|
long len = ssAll.Length();
|
|
adsout << _T("\n图中红叉表示镜像图块");
|
|
for(long i=0;i<len;i++){
|
|
Entity ent = ssAll[i];
|
|
XPoint ptInt;
|
|
ent.GetData(10, ptInt);
|
|
double nScaleX(1), nScaleY(1), nScaleZ(1);
|
|
ent.GetData(41, &nScaleX);
|
|
ent.GetData(42, &nScaleY);
|
|
ent.GetData(43, &nScaleZ);
|
|
if(nScaleX < 0 || nScaleY < 0 || nScaleZ < 0){
|
|
XPoint p1, p2, p3, p4;
|
|
ads_polar(ptInt, 0, 200, p1);
|
|
ads_polar(p1, PI/2, 200, p1);
|
|
ads_polar(ptInt, PI, 200, p2);
|
|
ads_polar(p2, PI/2, -200, p2);
|
|
ads_grdraw(p1, p2, 1, 0);
|
|
ads_polar(ptInt, PI/2, 200, p3);
|
|
ads_polar(p3, PI, 200, p3);
|
|
ads_polar(ptInt, PI/2, -200, p4);
|
|
ads_polar(p4, 0, 200, p4);
|
|
ads_grdraw(p3, p4, 1, 0);
|
|
}
|
|
}
|
|
PickSet ss(SS_FREE);
|
|
if(SelectEntities(_T("\n请选择恢复镜像的图块:<退出>"), ss, rbMask) != RTNORM)
|
|
return;
|
|
len = ss.Length();
|
|
for(i=0;i<len;i++){
|
|
Entity ent = ss[i];
|
|
double nScaleX(1), nScaleY(1), nRotate(0);
|
|
ent.GetData(41, &nScaleX);
|
|
ent.GetData(42, &nScaleY);
|
|
ent.GetData(50, &nRotate);
|
|
if(nScaleX > 0 && nScaleY > 0)
|
|
continue;
|
|
ent.SetData(41, fabs(nScaleX));
|
|
ent.SetData(42, fabs(nScaleY));
|
|
ent.Modify();
|
|
}
|
|
Entity entSel;
|
|
if(SelectEntity(_T("\n请选择角度正确的图块:<退出>"), entSel, rbMask) != RTNORM)
|
|
return;
|
|
|
|
double nRotate(0);
|
|
entSel.GetData(50, &nRotate);
|
|
len = ss.Length();
|
|
for(i=0;i<len;i++){
|
|
Entity ent = ss[i];
|
|
ent.SetData(50, nRotate);
|
|
ent.Modify();
|
|
}
|
|
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 洁具替换
|
|
//***************************************************************************************************
|
|
|
|
void ReplaceSanitary()
|
|
{
|
|
Entity entBlk;
|
|
RBList rbMask = ads_buildlist( -4, _T("<or"),
|
|
-4, _T("<and"), RTDXF0, _T("INSERT"), -4, _T("and>"),
|
|
-4, _T("<and"), RTDXF0, _T("AEC_BLOCK_INSERT"), -4, _T("and>"),
|
|
-4, _T("or>"), NULL);
|
|
|
|
// RBList rbMask(RTDXF0, _T("INSERT"), 8, _T("*"), NULL);
|
|
|
|
if(SelectEntity(_T("\n请选择要替换的洁具(整图替换):<退出>"), entBlk, rbMask) != RTNORM)
|
|
return;
|
|
TCHAR szBlkName[256];
|
|
entBlk.GetData(2, szBlkName);
|
|
XPoint ptLoc;
|
|
entBlk.GetData(10, ptLoc);
|
|
CString csSldName = BlockName2SldName(szBlkName);
|
|
CPoint ptDwgView;
|
|
int cvport=0;
|
|
VERIFY(xg_getvar(_T("CVPORT"), &cvport)==RTNORM);
|
|
acedCoordFromWorldToPixel(cvport, ptLoc, ptDwgView);
|
|
acedGetAcadDwgView()->ClientToScreen(&ptDwgView);
|
|
|
|
CTemporaryResourceOverride vTemp;
|
|
CSelectBlkDlg dlg;
|
|
dlg.m_staticSlide.m_iRowNum = 4;
|
|
dlg.m_staticSlide.m_iColNum = 4;
|
|
dlg.m_csTkName = _T("twtsys");
|
|
dlg.m_csType = _T("用户洁具");
|
|
dlg.m_ptBase = ptDwgView;
|
|
dlg.m_staticSlide.m_csCurRecord = csSldName;
|
|
if(dlg.DoModal() != IDOK)
|
|
return;
|
|
CString csRet = dlg.m_staticSlide.m_csCurRecord;
|
|
XString xsTKName, xsRocord;
|
|
SplitSlbName(csRet, xsTKName, xsRocord);
|
|
XString xsBlk;
|
|
LoadDwbBlock(xsTKName, xsRocord, xsBlk);
|
|
AcDbObjectId recordId = GetBlkIdByName(xsBlk);
|
|
|
|
RBList rbMask2(RTDXF0, _T("INSERT,AEC_BLOCK_INSERT"), 2, szBlkName, NULL);
|
|
PickSet ss(SS_FREE);
|
|
ss.Get(_T("X"), NULL, NULL, rbMask2);
|
|
for(long i=0;i<ss.Length();i++){
|
|
Entity entTmp = ss[i];
|
|
OPENOBJ_BEGIN(entTmp, AcDb::kForWrite, AcDbBlockReference, pBlk);
|
|
if(pBlk){
|
|
pBlk->setBlockTableRecord(recordId);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
}
|
|
|
|
//***************************************************************************************************
|
|
// 墙体开洞
|
|
//***************************************************************************************************
|
|
/*
|
|
XPoint Mid(XPoint ptStart, XPoint ptEnd)
|
|
{
|
|
XPoint ptCenter ;
|
|
ptCenter.x = (ptStart.x + ptEnd.x)/2;
|
|
ptCenter.y = (ptStart.y + ptEnd.y)/2;
|
|
ptCenter.z = (ptStart.z + ptEnd.z)/2;
|
|
|
|
return ptCenter;
|
|
}
|
|
|
|
void CreateHole(const AcDbObjectId &idWall, const XPoint &ptIns, double dWidth, double dHeight)
|
|
{
|
|
AcDbObjectId id2d = NULL;
|
|
CString csDwb = g_csDwbPath + _T("TwtSys");
|
|
XString xsTmp;
|
|
if(LoadDwbBlock(csDwb, _T("00000513"), xsTmp) != RTNORM)
|
|
return;
|
|
|
|
id2d = GetBlkIdByName(_T("$TWTSYS$00000513"));
|
|
if (!id2d.isValid())
|
|
{
|
|
return;
|
|
}
|
|
|
|
TDbOpening *pWin = new TDbOpening();
|
|
if (pWin == NULL)
|
|
return;
|
|
|
|
pWin->m_nIdStyle2d=id2d;
|
|
|
|
pWin->SetKind(TOpeningData::OP_HOLE);
|
|
// pWin->setLinetype(_T("DASHED"));
|
|
pWin->InitHardPointerId();
|
|
// pWin->m_pBayWin = new XBayWindow();
|
|
pWin->SetWidth(dWidth);
|
|
pWin->SetHeight(dHeight);
|
|
pWin->m_nOpStyle &= ~OPS_HOLE_FLAG1;
|
|
pWin->m_nOpStyle |= OPS_HOLE_FLAG2;
|
|
pWin->m_nOpStyle &= ~ OPS_ATHIGH;
|
|
|
|
//基础洞插入点
|
|
OPENOBJ_BEGIN(idWall, AcDb::kForWrite, TDbWall, pWall);
|
|
if (pWall != NULL)
|
|
{
|
|
XCurveSegment segL,segR;
|
|
pWall->GetSideCurve(segL,segR);
|
|
XPoint ptStart , ptEnd;
|
|
ptStart = Mid(segL.GetStartPoint(), segR.GetStartPoint());
|
|
ptEnd = Mid(segL.GetEndPoint(), segR.GetEndPoint());
|
|
|
|
XCurveSegment segCen(ptStart,ptEnd,segL.GetBulge());
|
|
|
|
//检验待插入洞的宽度高度
|
|
double dWallHeight = pWall->GetHeight();
|
|
if (ptStart.Distance2d(ptIns) < dWidth / 2 ||
|
|
ptEnd.Distance2d(ptIns) < dWidth / 2 ||
|
|
ptIns.z - ptStart.z < dHeight / 2 ||
|
|
dWallHeight - ptIns.z < dHeight / 2)
|
|
|
|
{
|
|
adsout << _T("\n不能插到该墙上(宽度或高度超出墙体)!");
|
|
delete pWin;
|
|
}
|
|
else
|
|
{
|
|
pWin->SetLocation(ptIns);
|
|
pWin->SetSill(ptIns.z - dHeight / 2);
|
|
|
|
if (pWall->Is(CURVE_ARC))
|
|
{
|
|
pWin->SetKind(TOpeningData::OP_HOLE);
|
|
pWin->m_nIdStyle2d = NULL;
|
|
}
|
|
|
|
if(pWall->CanInsertOpening(*pWin))
|
|
{
|
|
pWin->SetWallId(pWall->objectId());
|
|
//设置旋转角度
|
|
pWin->SetRotation(segCen.Direction(ptIns));
|
|
|
|
pWin->InitHardPointerId();
|
|
pWin->AddToMSpace(Adesk::kFalse);
|
|
pWin->setLayer(InitLayer(_T("TG_HOLE")));
|
|
pWall->assertWriteEnabled();
|
|
pWall->AddOpeningId(pWin->objectId());
|
|
pWin->close();
|
|
}
|
|
else
|
|
{
|
|
adsout << _T("\n不能插到该墙上(门窗高度或宽度方向超出墙体)!");
|
|
delete pWin;
|
|
}
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
// 获得墙体二维中心线
|
|
void GetLineByWall(std::map<AcDbLine*, AcDbObjectId> &mapWall, PickSet &ssWall)
|
|
{
|
|
TDbWall *pWall = NULL;
|
|
XPoint ptStart , ptEnd;
|
|
for (long i = 0; i < ssWall.Length(); i++)
|
|
{
|
|
AcDbObjectId idWall;
|
|
acdbGetObjectId(idWall, ssWall[i]);
|
|
pWall = NULL;
|
|
acdbOpenObject(pWall, idWall, AcDb::kForRead);
|
|
if (pWall != NULL)
|
|
{
|
|
XCurveSegment segL,segR;
|
|
pWall->GetSideCurve(segL,segR);
|
|
ptStart = Mid(segL.GetStartPoint(), segR.GetStartPoint());
|
|
ptEnd = Mid(segL.GetEndPoint(), segR.GetEndPoint());
|
|
pWall->close();
|
|
|
|
ptStart.z = 0;
|
|
ptEnd.z = 0;
|
|
AcDbLine *pLine = new AcDbLine(ptStart, ptEnd);
|
|
mapWall.insert(std::make_pair(pLine, idWall));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
// 原图中与墙体中心线相交的管线,桥架,风管,风管变径的信息存入data中
|
|
void GetLines(AcDbLine *pLine, std::map<AcDbLine*, AcDbObjectId> &data)
|
|
{
|
|
if (pLine == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
XPoint ptStart, ptEnd;
|
|
pLine->getStartPoint(ptStart);
|
|
pLine->getEndPoint(ptEnd);
|
|
PickSet ssSel(SS_FREE);
|
|
RBList rbFilter = acutBuildList(RTDXF0, _T("ATS_PIPE,ATS_CABLETRY,ATS_DBHVACDUCT,ATS_DBHFITTING"), NULL);
|
|
acedSSGet(_T("C"),&Wcs2Ucs(ptStart),&Wcs2Ucs(ptEnd),rbFilter,ssSel);
|
|
|
|
for (long i = 0; i < ssSel.Length(); i++)
|
|
{
|
|
AcDbObjectId idEnt;
|
|
acdbGetObjectId(idEnt, ssSel[i]);
|
|
AcDbEntity *pEnt = NULL;
|
|
acdbOpenObject(pEnt, idEnt, AcDb::kForRead);
|
|
if (pEnt != NULL)
|
|
{
|
|
TDbPipe *pPipe = TDbPipe::cast(pEnt);
|
|
TDbECabletry* pCabletry = TDbECabletry::cast(pEnt);
|
|
TDbHvacDuct *pDuct = TDbHvacDuct::cast(pEnt);
|
|
TDbHvacFitting *pFitting = TDbHvacFitting::cast(pEnt);
|
|
AcGePoint3d ptS, ptE;
|
|
BOOL bFlag = FALSE;
|
|
if (pPipe != NULL)
|
|
{
|
|
pPipe->getStartPoint(ptS);
|
|
pPipe->getEndPoint(ptE);
|
|
bFlag = TRUE;
|
|
}
|
|
else if (pCabletry != NULL)
|
|
{
|
|
ptS = pCabletry->StartPoint();
|
|
ptE = pCabletry->EndPoint();
|
|
bFlag = TRUE;
|
|
}
|
|
else if (pDuct != NULL )
|
|
{
|
|
ptS = pDuct->StartPoint();
|
|
ptE = pDuct->EndPoint();
|
|
bFlag = TRUE;
|
|
}
|
|
else if (pFitting != NULL)
|
|
{
|
|
TDb::TXData xData;
|
|
memset(&xData,0,sizeof(TDb::TXData));
|
|
pFitting->GetAt(KEY_RUNTIME, xData);
|
|
int nType = xData.nVal;
|
|
if (nType == TDb::eReduce) // 变径
|
|
{
|
|
TDb::TXData ptSData, ptEData;
|
|
memset(&ptSData,0,sizeof(TDb::TXData));
|
|
memset(&ptEData,0,sizeof(TDb::TXData));
|
|
pFitting->GetAt(HRED_StartPoint, ptSData);
|
|
pFitting->GetAt(HRED_EndPoint, ptEData);
|
|
ptS.x = ptSData.dVal[0];
|
|
ptS.y = ptSData.dVal[1];
|
|
ptS.z = ptSData.dVal[2];
|
|
ptE.x = ptEData.dVal[0];
|
|
ptE.y = ptEData.dVal[1];
|
|
ptE.z = ptEData.dVal[2];
|
|
bFlag = TRUE;
|
|
}
|
|
}
|
|
|
|
if(bFlag)
|
|
{
|
|
AcDbLine *pLine = new AcDbLine(ptS, ptE);
|
|
data.insert(std::make_pair(pLine, idEnt));
|
|
}
|
|
pEnt->close();
|
|
}
|
|
}
|
|
}
|
|
|
|
// 外部参考中的管线,桥架,风管,风管变径的信息存入data中
|
|
void GetLines(std::map<AcDbLine*, AcDbObjectId> &data)
|
|
{
|
|
PickSet ss(SS_FREE);
|
|
RBList rbMask = ads_buildlist(RTDXF0, _T("INSERT"), NULL);
|
|
ss.Get(_T("X"), NULL, NULL, rbMask);
|
|
for (long i = 0; i < ss.Length(); i++)
|
|
{
|
|
Entity ent = ss[i];
|
|
//读取外部参照实体
|
|
OPENOBJ_BEGIN(ent,AcDb::kForRead,AcDbBlockReference,pRef);
|
|
if (pRef != NULL)
|
|
{
|
|
AcGeMatrix3d Matrix = pRef->blockTransform();
|
|
AcDbObjectId idRecord = pRef->blockTableRecord();
|
|
OPENOBJ_BEGIN(idRecord,AcDb::kForRead,AcDbBlockTableRecord,pRec);
|
|
if (pRec != NULL)
|
|
{
|
|
AcGePoint3d ptIns2 = pRec->origin();
|
|
if (pRec->isFromExternalReference())
|
|
{
|
|
AcDbBlockTableRecordIterator *pIter = NULL;
|
|
pRec->newIterator(pIter);
|
|
|
|
if (pIter != NULL)
|
|
{
|
|
AcDbObjectId idEnt;
|
|
for (pIter->start();!pIter->done();pIter->step())
|
|
{
|
|
pIter->getEntityId(idEnt);
|
|
AcDbEntity *pEnt = NULL;
|
|
acdbOpenObject(pEnt, idEnt, AcDb::kForRead);
|
|
if (pEnt != NULL)
|
|
{
|
|
TDbPipe *pPipe = TDbPipe::cast(pEnt);
|
|
TDbECabletry* pCabletry = TDbECabletry::cast(pEnt);
|
|
TDbHvacDuct *pDuct = TDbHvacDuct::cast(pEnt);
|
|
TDbHvacFitting *pFitting = TDbHvacFitting::cast(pEnt);
|
|
AcGePoint3d ptS, ptE;
|
|
BOOL bFlag = FALSE;
|
|
if (pPipe != NULL)
|
|
{
|
|
pPipe->getStartPoint(ptS);
|
|
pPipe->getEndPoint(ptE);
|
|
bFlag = TRUE;
|
|
}
|
|
else if ( pCabletry != NULL)
|
|
{
|
|
ptS = pCabletry->StartPoint();
|
|
ptE = pCabletry->EndPoint();
|
|
bFlag = TRUE;
|
|
}
|
|
else if (pDuct != NULL )
|
|
{
|
|
ptS = pDuct->StartPoint();
|
|
ptE = pDuct->EndPoint();
|
|
bFlag = TRUE;
|
|
}
|
|
else if (pFitting != NULL)
|
|
{
|
|
TDb::TXData xData;
|
|
memset(&xData,0,sizeof(TDb::TXData));
|
|
pFitting->GetAt(KEY_RUNTIME, xData);
|
|
int nType = xData.nVal;
|
|
if (nType == TDb::eReduce) // 变径
|
|
{
|
|
TDb::TXData ptSData, ptEData;
|
|
memset(&ptSData,0,sizeof(TDb::TXData));
|
|
memset(&ptEData,0,sizeof(TDb::TXData));
|
|
pFitting->GetAt(HRED_StartPoint, ptSData);
|
|
pFitting->GetAt(HRED_EndPoint, ptEData);
|
|
ptS.x = ptSData.dVal[0];
|
|
ptS.y = ptSData.dVal[1];
|
|
ptS.z = ptSData.dVal[2];
|
|
ptE.x = ptEData.dVal[0];
|
|
ptE.y = ptEData.dVal[1];
|
|
ptE.z = ptEData.dVal[2];
|
|
bFlag = TRUE;
|
|
}
|
|
}
|
|
|
|
if (bFlag)
|
|
{
|
|
AcGeVector3d vt = AcGePoint3d::kOrigin - ptIns2;
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(vt);
|
|
AcDbLine *pLine = new AcDbLine(ptS, ptE);
|
|
pLine->transformBy(mat); // 平移至原点
|
|
pLine->transformBy(Matrix); //
|
|
data.insert(std::make_pair(pLine, idEnt));
|
|
}
|
|
}
|
|
}
|
|
delete pIter;
|
|
}
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
|
|
BOOL IsIntersect(AcDbLine *pLine, AcDbLine *pLine2, AcDbObjectId idEnt, AcGePoint3d &ptIns, double &dWidth, double &dHeight)
|
|
{
|
|
if (pLine == NULL || pLine2 == NULL)
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
AcGePoint3d pt1 = pLine2->startPoint(), pt2 = pLine2->endPoint();
|
|
pt1.z = 0.0;
|
|
pt2.z = 0.0;
|
|
|
|
AcDbLine line(pt1, pt2);
|
|
AcGePoint3dArray arPt;
|
|
pLine->intersectWith(&line, AcDb::kOnBothOperands, arPt);
|
|
if (arPt.length() != 1)
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
ptIns = arPt[0];
|
|
|
|
// 获取墙体宽高
|
|
BOOL bFlag = FALSE;
|
|
AcDbEntity *pEnt = NULL;
|
|
acdbOpenObject(pEnt, idEnt, AcDb::kForRead);
|
|
if (pEnt != NULL)
|
|
{
|
|
TDbPipe *pPipe = TDbPipe::cast(pEnt);
|
|
TDbECabletry* pCabletry = TDbECabletry::cast(pEnt);
|
|
TDbHvacDuct *pDuct = TDbHvacDuct::cast(pEnt);
|
|
TDbHvacFitting *pFiting = TDbHvacFitting::cast(pEnt);
|
|
if (pPipe != NULL) // 管线
|
|
{
|
|
dWidth = GetPipeOutDByDn(pPipe->GetMaterial(), pPipe->GetDnDiameter());
|
|
dHeight = dWidth;
|
|
}
|
|
else if (pCabletry != NULL) // 桥架
|
|
{
|
|
TDb::TXData xData1, xData2;
|
|
memset(&xData1,0,sizeof(TDb::TXData));
|
|
memset(&xData2,0,sizeof(TDb::TXData));
|
|
pCabletry->GetAt(KEY_B,xData1);
|
|
pCabletry->GetAt(KEY_H,xData2);
|
|
dWidth = xData1.dVal[0];
|
|
dHeight = xData2.dVal[0];
|
|
bFlag = TRUE;
|
|
}
|
|
else if (pDuct != NULL) // 风管
|
|
{
|
|
TDb::TXData xData;
|
|
memset(&xData,0,sizeof(TDb::TXData));
|
|
pDuct->GetAt(KEY_SectType, xData);
|
|
int nType = xData.nVal;
|
|
TDb::TXData xData1, xData2;
|
|
memset(&xData1,0,sizeof(TDb::TXData));
|
|
memset(&xData2,0,sizeof(TDb::TXData));
|
|
if (nType == 0) // 截面为矩形
|
|
{
|
|
pDuct->GetAt(HDCT_Width, xData1);
|
|
pDuct->GetAt(HDCT_Thick, xData2);
|
|
dWidth = xData1.dVal[0];
|
|
dHeight = xData2.dVal[0];
|
|
}
|
|
else if (nType == 1) // 截面为圆形
|
|
{
|
|
pDuct->GetAt(HDCT_Diameter, xData1);
|
|
dWidth = dHeight = xData1.dVal[0];
|
|
}
|
|
}
|
|
else if (pFiting != NULL) // 风管管件
|
|
{
|
|
TDb::TXData xData;
|
|
memset(&xData,0,sizeof(TDb::TXData));
|
|
pFiting->GetAt(KEY_RUNTIME, xData);
|
|
int nType = xData.nVal;
|
|
if (nType == TDb::eReduce) // 变径
|
|
{
|
|
TDb::TXData sectType1, sectType2;
|
|
memset(§Type1,0,sizeof(TDb::TXData));
|
|
memset(§Type2,0,sizeof(TDb::TXData));
|
|
pFiting->GetAt(HRED_StartSectType, sectType1);
|
|
pFiting->GetAt(HRED_EndSectType, sectType2);
|
|
double dWidth1 = 0.0, dWidth2 = 0.0, dHeight1 = 0.0, dHeight2 = 0.0;
|
|
if (sectType1.nVal == 0) // 截面为矩形
|
|
{
|
|
TDb::TXData xData1, xData2;
|
|
memset(&xData1,0,sizeof(TDb::TXData));
|
|
memset(&xData2,0,sizeof(TDb::TXData));
|
|
pFiting->GetAt(HRED_StartWidth, xData1);
|
|
pFiting->GetAt(HRED_StartThick, xData2);
|
|
dWidth1 = xData1.dVal[0];
|
|
dHeight1 = xData2.dVal[0];
|
|
}
|
|
else if (sectType1.nVal == 1) // 截面为圆形
|
|
{
|
|
TDb::TXData xData;
|
|
memset(&xData,0,sizeof(TDb::TXData));
|
|
pFiting->GetAt(HRED_StartDiameter, xData);
|
|
dWidth1 = dHeight1 = xData.dVal[0];
|
|
}
|
|
|
|
if (sectType2.nVal == 0) // 截面为矩形
|
|
{
|
|
TDb::TXData xData1, xData2;
|
|
memset(&xData1,0,sizeof(TDb::TXData));
|
|
memset(&xData2,0,sizeof(TDb::TXData));
|
|
pFiting->GetAt(HRED_EndWidth, xData1);
|
|
pFiting->GetAt(HRED_EndThick, xData2);
|
|
dWidth2 = xData1.dVal[0];
|
|
dHeight2 = xData2.dVal[0];
|
|
}
|
|
else if (sectType2.nVal == 1) // 截面为圆形
|
|
{
|
|
TDb::TXData xData;
|
|
memset(&xData,0,sizeof(TDb::TXData));
|
|
pFiting->GetAt(HRED_EndDiameter, xData);
|
|
dWidth2 = dHeight2 = xData.dVal[0];
|
|
}
|
|
|
|
dWidth = dWidth1 > dWidth2 ? dWidth1 : dWidth2;
|
|
dHeight = dHeight1 > dHeight2 ? dHeight1 : dHeight2;
|
|
}
|
|
}
|
|
pEnt->close();
|
|
}
|
|
|
|
double dHeight2 = dHeight;
|
|
dWidth += dWidth * 0.2; // 洞左右空隙
|
|
dHeight += dHeight * 0.2; // 洞上下空隙
|
|
|
|
// 求交点到线的投影
|
|
pLine2->getClosestPointTo(ptIns, ptIns);
|
|
if (bFlag)
|
|
{
|
|
ptIns.z += dHeight / 2 - dHeight2 * 0.1;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
// 主函数
|
|
void InsWallHole()
|
|
{
|
|
// 选择墙体
|
|
RBList rbMask = ads_buildlist(RTDXF0, _T("ATS_WALL"), NULL);
|
|
PickSet ssWall(SS_FREE);
|
|
if(SelectEntities(_T("\n请选择墙体<退出>"), ssWall, rbMask) != RTNORM)
|
|
{
|
|
return;
|
|
}
|
|
|
|
std::map<AcDbLine*, AcDbObjectId> data;
|
|
GetLines(data); // 获取外部引用中管线,桥架,风管,风管变径的信息
|
|
|
|
std::map<AcDbLine*, AcDbObjectId> mapWall;
|
|
GetLineByWall(mapWall, ssWall);
|
|
|
|
std::map<AcDbLine*, AcDbObjectId>::iterator it;
|
|
for (it = mapWall.begin(); it != mapWall.end(); it++)
|
|
{
|
|
AcDbLine *pLine = (*it).first;
|
|
GetLines(pLine, data); // 获取原图中管线,桥架,风管,风管变径的信息
|
|
|
|
AcDbObjectId idWall = (*it).second;
|
|
std::map<AcDbLine*, AcDbObjectId>::iterator it2;
|
|
for (it2 = data.begin(); it2 != data.end(); it2++)
|
|
{
|
|
XPoint ptIns;
|
|
double dWidth = 100, dHeight = 100;
|
|
if (IsIntersect(pLine, (*it2).first, (*it2).second, ptIns, dWidth, dHeight)) // 与墙体是否有交点
|
|
{
|
|
CreateHole(idWall, ptIns, dWidth, dHeight); // 在墙上开洞
|
|
}
|
|
}
|
|
}
|
|
|
|
// 删除数据
|
|
for (it = mapWall.begin(); it != mapWall.end(); it++)
|
|
{
|
|
if ((*it).first != NULL)
|
|
{
|
|
delete (*it).first;
|
|
}
|
|
}
|
|
mapWall.clear();
|
|
|
|
for(it = data.begin(); it != data.end(); it++)
|
|
{
|
|
if ((*it).first != NULL)
|
|
{
|
|
delete (*it).first;
|
|
}
|
|
}
|
|
data.clear();
|
|
|
|
return;
|
|
}
|
|
*/ |