7187 lines
199 KiB
C++
7187 lines
199 KiB
C++
#include "StdAfx.h"
|
||
#include "rxregsvc.h"
|
||
#include "TGAs.h"
|
||
#include "Block.h"
|
||
#include "dbxline.h"
|
||
#include "DbEquipment.h"
|
||
#include "DbDoubleLinePipe.h"
|
||
#include "DbPipeLabel.h"
|
||
#include "DbVPipeDim.h"
|
||
#include "dbwell.h"
|
||
#include "DbPipeValve.h"
|
||
#include "DbPump.h"
|
||
#include "xtext.h"
|
||
#include "XFilePathName.h"
|
||
#include "DbPool.h"
|
||
#include "XBlock.h"
|
||
|
||
#define E6TOL 1.e-6
|
||
|
||
int CALLBACK EnumFontFamExProc2(ENUMLOGFONTEX *lplf, NEWTEXTMETRICEX *lpntme,
|
||
int FontType, LONG lParam)
|
||
{
|
||
if (!(FontType & TRUETYPE_FONTTYPE))
|
||
return 1;
|
||
if (*(lplf->elfLogFont.lfFaceName))
|
||
{
|
||
if (!_tcsicmp(lplf->elfLogFont.lfFaceName, _T("marlett")))
|
||
return 1;
|
||
|
||
if (g_lstWinfont.Index(lplf->elfLogFont.lfFaceName, 0) < 0 &&
|
||
_tcsicmp((const TCHAR*)lplf->elfScript, _T("CHINESE_GB2312")) == 0) {// winFont
|
||
g_lstWinfont.Append(tstrnew(lplf->elfLogFont.lfFaceName));
|
||
g_lstCharset.Append(new int(lplf->elfLogFont.lfCharSet));
|
||
g_lstPitch.Append(new int(lplf->elfLogFont.lfPitchAndFamily));
|
||
}
|
||
}
|
||
return 1;
|
||
}
|
||
|
||
int CALLBACK EnumFontFamExProc33(ENUMLOGFONTEX *lplf, NEWTEXTMETRICEX *lpntme,
|
||
int FontType, LONG lParam)
|
||
{
|
||
if (!(FontType & TRUETYPE_FONTTYPE))
|
||
return 1;
|
||
if (*(lplf->elfLogFont.lfFaceName))
|
||
{
|
||
if (!_tcsicmp(lplf->elfLogFont.lfFaceName, _T("marlett")))
|
||
return 1;
|
||
|
||
if (g_lstWinfont.Index(lplf->elfLogFont.lfFaceName, 0) < 0 &&
|
||
_tcsicmp((const TCHAR*)lplf->elfScript, _T("CHINESE_GB2312")) == 0) {// winFont
|
||
g_lstWinfont.Append(tstrnew(lplf->elfLogFont.lfFaceName));
|
||
g_lstCharset.Append(new int(lplf->elfLogFont.lfCharSet));
|
||
g_lstPitch.Append(new int(lplf->elfLogFont.lfPitchAndFamily));
|
||
}
|
||
}
|
||
return 1;
|
||
}
|
||
|
||
void DrawSlide(const TCHAR*szPath, CWnd* pWnd)
|
||
{
|
||
CImageDC img;
|
||
CDC *pDC = pWnd->GetDC();
|
||
CRect rc;
|
||
pWnd->GetClientRect(&rc);
|
||
img.InitDC(pDC, rc, GetAcadBackColor());
|
||
img.PaintSlide(szPath);
|
||
img.SetDC(NULL);
|
||
pWnd->ReleaseDC(pDC);
|
||
}
|
||
|
||
void SplitBlkStr(const TCHAR *szInput, CString &csTK, CString &csRecord)
|
||
{
|
||
// CString csInput = szInput;
|
||
// int idx = csInput.Find(_T('$'));
|
||
// if(idx > 0)
|
||
// {
|
||
// CString csTmp;
|
||
// csTmp = csInput.Right(csInput.GetLength() - idx);
|
||
// SplitBlkStr(csTmp, csTK, csRecord);
|
||
// return;
|
||
// }//以上几句 沈睿 2011-6-24加,有的图块名是有前缀的。一般都是从$开头
|
||
|
||
int len = (int)_tcslen(szInput);
|
||
TCHAR szTemp[256] = _T("");
|
||
int j = 0;
|
||
BOOL bfisrt = TRUE;
|
||
szTemp[0] = _T('\0');
|
||
for (int i = 0; i <= len; i++)
|
||
{
|
||
if (szInput[i] != _T('\0') && szInput[i] != _T('$'))
|
||
szTemp[j] = szInput[i];
|
||
else {
|
||
szTemp[j] = _T('\0');
|
||
if (szTemp[0] != _T('\0') && bfisrt) {
|
||
csTK = szTemp;
|
||
bfisrt = FALSE;
|
||
}
|
||
else if (szTemp[0] != _T('\0') && !bfisrt) {
|
||
csRecord = szTemp;
|
||
}
|
||
j = -1;
|
||
}
|
||
j++;
|
||
}
|
||
|
||
}
|
||
|
||
AcDbObjectId GetBlkIdByName(const TCHAR* szBlkName)
|
||
{
|
||
return GetBlockIdFromString(szBlkName);
|
||
}
|
||
|
||
AcDbObjectId InitTwtTextStyle(const TCHAR *szTextStyle)
|
||
{
|
||
AcDbObjectId idRet;
|
||
idRet = GetTextStyleId(szTextStyle);
|
||
if (!idRet) {
|
||
|
||
g_lstWinfont.Reset();
|
||
g_lstCharset.Reset();
|
||
g_lstPitch.Reset();
|
||
CDC *pDC = acedGetAcadDwgView()->GetDC();
|
||
ASSERT(pDC);
|
||
LOGFONT lf;
|
||
ZeroMemory(&lf, sizeof(lf));
|
||
lf.lfCharSet = DEFAULT_CHARSET;
|
||
EnumFontFamiliesEx(pDC->m_hDC, &lf,
|
||
(FONTENUMPROC)EnumFontFamExProc33, NULL, 0);
|
||
acedGetAcadDwgView()->ReleaseDC(pDC);
|
||
|
||
AcDbTextStyleTableRecord *pStyle = new AcDbTextStyleTableRecord;
|
||
pStyle->setName(szTextStyle);
|
||
if (_tcsicmp(szTextStyle, g_csPipeDnStyle) == 0) { //管径标注
|
||
pStyle->setTextSize(g_nPipeDnHeight);
|
||
pStyle->setXScale(g_nPipeDnScale);
|
||
int idx = g_lstWinfont.Index(g_csPipeDnChn);
|
||
if (idx < 0) {
|
||
pStyle->setFileName(g_csPipeDnEng);
|
||
pStyle->setBigFontFileName(g_csPipeDnChn);
|
||
}
|
||
else {
|
||
int iCharset = *g_lstCharset[idx];
|
||
int iPitch = *g_lstPitch[idx];
|
||
#if ADS > 20
|
||
pStyle->setFont(g_csPipeDnChn, false, false, (Charset)iCharset, (Autodesk::AutoCAD::PAL::FontUtils::FontPitch)iPitch, Autodesk::AutoCAD::PAL::FontUtils::FontFamily::kDoNotCare);
|
||
#else
|
||
pStyle->setFont(g_csPipeDnChn, FALSE, FALSE, iCharset, iPitch);
|
||
#endif
|
||
// modify by cq 2017-01-05 支持CAD2017
|
||
}
|
||
}
|
||
else if (_tcsicmp(szTextStyle, g_csVPipeStyle) == 0) {//立管标注
|
||
pStyle->setTextSize(g_nVPipeHeight);
|
||
pStyle->setXScale(g_nVPipeScale);
|
||
int idx = g_lstWinfont.Index(g_csVPipeChn);
|
||
if (idx < 0) {
|
||
pStyle->setFileName(g_csVPipeEng);
|
||
pStyle->setBigFontFileName(g_csVPipeChn);
|
||
}
|
||
else {
|
||
int iCharset = *g_lstCharset[idx];
|
||
int iPitch = *g_lstPitch[idx];
|
||
#if ADS > 20
|
||
pStyle->setFont(g_csVPipeChn, false, false, (Charset)iCharset, (Autodesk::AutoCAD::PAL::FontUtils::FontPitch)iPitch, Autodesk::AutoCAD::PAL::FontUtils::FontFamily::kDoNotCare);
|
||
#else
|
||
pStyle->setFont(g_csVPipeChn, FALSE, FALSE, iCharset, iPitch);
|
||
#endif
|
||
// modify by cq 2017-01-05 支持CAD2017
|
||
}
|
||
}
|
||
else if (_tcsicmp(szTextStyle, g_csPipeTextStyle) == 0) {//管线文字
|
||
pStyle->setTextSize(g_nPipeTextHeight);
|
||
pStyle->setXScale(g_nPipeTextScale);
|
||
int idx = g_lstWinfont.Index(g_csPipeTextChn);
|
||
if (idx < 0) {
|
||
pStyle->setFileName(g_csPipeTextEng);
|
||
pStyle->setBigFontFileName(g_csPipeTextChn);
|
||
}
|
||
else {
|
||
int iCharset = *g_lstCharset[idx];
|
||
int iPitch = *g_lstPitch[idx];
|
||
#if ADS > 20
|
||
pStyle->setFont(g_csPipeTextChn, false, false, (Charset)iCharset, (Autodesk::AutoCAD::PAL::FontUtils::FontPitch)iPitch, Autodesk::AutoCAD::PAL::FontUtils::FontFamily::kDoNotCare);
|
||
#else
|
||
pStyle->setFont(g_csPipeTextChn, FALSE, FALSE, iCharset, iPitch);
|
||
#endif
|
||
// modify by cq 2017-01-05 支持CAD2017
|
||
}
|
||
}
|
||
else if (_tcsicmp(szTextStyle, g_csCircleTextStyle) == 0) {//圆中文字
|
||
pStyle->setTextSize(g_nCircleTextHeight);
|
||
pStyle->setXScale(g_nCircleTextScale);
|
||
int idx = g_lstWinfont.Index(g_csCircleTextChn);
|
||
if (idx < 0) {
|
||
pStyle->setFileName(g_csCircleTextEng);
|
||
pStyle->setBigFontFileName(g_csCircleTextChn);
|
||
}
|
||
else {
|
||
int iCharset = *g_lstCharset[idx];
|
||
int iPitch = *g_lstPitch[idx];
|
||
#if ADS > 20
|
||
pStyle->setFont(g_csCircleTextChn, false, false, (Charset)iCharset, (Autodesk::AutoCAD::PAL::FontUtils::FontPitch)iPitch, Autodesk::AutoCAD::PAL::FontUtils::FontFamily::kDoNotCare);
|
||
#else
|
||
pStyle->setFont(g_csCircleTextChn, FALSE, FALSE, iCharset, iPitch);
|
||
#endif
|
||
// modify by cq 2017-01-05 支持CAD2017
|
||
}
|
||
}
|
||
else if (_tcsicmp(szTextStyle, g_csSanTextStyle) == 0) {//洁具标注 sr add 2010-12-16
|
||
pStyle->setTextSize(g_nSanTextHeight);
|
||
pStyle->setXScale(g_nSanTextScale);
|
||
int idx = g_lstWinfont.Index(g_csSanTextChn);
|
||
if (idx < 0) {
|
||
pStyle->setFileName(g_csSanTextEng);
|
||
pStyle->setBigFontFileName(g_csSanTextChn);
|
||
}
|
||
else {
|
||
int iCharset = *g_lstCharset[idx];
|
||
int iPitch = *g_lstPitch[idx];
|
||
#if ADS > 20
|
||
pStyle->setFont(g_csSanTextChn, false, false, (Charset)iCharset, (Autodesk::AutoCAD::PAL::FontUtils::FontPitch)iPitch, Autodesk::AutoCAD::PAL::FontUtils::FontFamily::kDoNotCare);
|
||
#else
|
||
pStyle->setFont(g_csSanTextChn, FALSE, FALSE, iCharset, iPitch);
|
||
#endif
|
||
// modify by cq 2017-01-05 支持CAD2017
|
||
}
|
||
}
|
||
else if (_tcsicmp(szTextStyle, g_csDimWellStyle) == 0) { //井标注
|
||
pStyle->setTextSize(g_nDimWellHeight);
|
||
pStyle->setXScale(g_nDimWellScale);
|
||
int idx = g_lstWinfont.Index(g_csDimWellChn);
|
||
if (idx < 0) {
|
||
pStyle->setFileName(g_csDimWellEng);
|
||
pStyle->setBigFontFileName(g_csDimWellChn);
|
||
}
|
||
else {
|
||
int iCharset = *g_lstCharset[idx];
|
||
int iPitch = *g_lstPitch[idx];
|
||
#if ADS > 20
|
||
pStyle->setFont(g_csDimWellChn, false, false, (Charset)iCharset, (Autodesk::AutoCAD::PAL::FontUtils::FontPitch)iPitch, Autodesk::AutoCAD::PAL::FontUtils::FontFamily::kDoNotCare);
|
||
#else
|
||
pStyle->setFont(g_csDimWellChn, FALSE, FALSE, iCharset, iPitch);
|
||
#endif
|
||
// modify by cq 2017-01-05 支持CAD2017
|
||
}
|
||
}
|
||
else if (_tcsicmp(szTextStyle, g_csSheetStyle) == 0) { //表格文字
|
||
pStyle->setTextSize(g_nSheetHeight);
|
||
pStyle->setXScale(g_nSheetScale);
|
||
int idx = g_lstWinfont.Index(g_csSheetChn);
|
||
if (idx < 0) {
|
||
pStyle->setFileName(g_csSheetEng);
|
||
pStyle->setBigFontFileName(g_csSheetChn);
|
||
}
|
||
else {
|
||
int iCharset = *g_lstCharset[idx];
|
||
int iPitch = *g_lstPitch[idx];
|
||
#if ADS > 20
|
||
pStyle->setFont(g_csSheetChn, false, false, (Charset)iCharset, (Autodesk::AutoCAD::PAL::FontUtils::FontPitch)iPitch, Autodesk::AutoCAD::PAL::FontUtils::FontFamily::kDoNotCare);
|
||
#else
|
||
pStyle->setFont(g_csSheetChn, FALSE, FALSE, iCharset, iPitch);
|
||
#endif
|
||
// modify by cq 2017-01-05 支持CAD2017
|
||
}
|
||
}
|
||
else if (_tcsicmp(szTextStyle, g_csTwtDimStyle) == 0) { //标注文字
|
||
pStyle->setTextSize(g_nTwtDimHeight);
|
||
pStyle->setXScale(g_nDimScale);
|
||
int idx = g_lstWinfont.Index(g_csDimChn);
|
||
if (idx < 0) {
|
||
pStyle->setFileName(g_csDimEng);
|
||
pStyle->setBigFontFileName(g_csDimChn);
|
||
}
|
||
else {
|
||
int iCharset = *g_lstCharset[idx];
|
||
int iPitch = *g_lstPitch[idx];
|
||
#if ADS > 20
|
||
pStyle->setFont(g_csDimChn, false, false, (Charset)iCharset, (Autodesk::AutoCAD::PAL::FontUtils::FontPitch)iPitch, Autodesk::AutoCAD::PAL::FontUtils::FontFamily::kDoNotCare);
|
||
#else
|
||
pStyle->setFont(g_csDimChn, FALSE, FALSE, iCharset, iPitch);
|
||
#endif
|
||
// modify by cq 2017-01-05 支持CAD2017
|
||
}
|
||
}
|
||
else if (_tcsicmp(szTextStyle, g_csEleDimStyle) == 0) { //标高文字 cet 2012.7.3 add
|
||
pStyle->setTextSize(g_nEleDimHeight);
|
||
pStyle->setXScale(g_nEleDimScale);
|
||
int idx = g_lstWinfont.Index(g_csEleDimChn);
|
||
if (idx < 0) {
|
||
pStyle->setFileName(g_csEleDimEng);
|
||
pStyle->setBigFontFileName(g_csEleDimChn);
|
||
}
|
||
else {
|
||
int iCharset = *g_lstCharset[idx];
|
||
int iPitch = *g_lstPitch[idx];
|
||
#if ADS > 20
|
||
pStyle->setFont(g_csEleDimChn, false, false, (Charset)iCharset, (Autodesk::AutoCAD::PAL::FontUtils::FontPitch)iPitch, Autodesk::AutoCAD::PAL::FontUtils::FontFamily::kDoNotCare);
|
||
#else
|
||
pStyle->setFont(g_csEleDimChn, FALSE, FALSE, iCharset, iPitch);
|
||
#endif
|
||
// modify by cq 2017-01-05 支持CAD2017
|
||
}
|
||
}
|
||
|
||
// 扩展数据
|
||
resbuf *pXData = ads_buildlist(1001, TCHXD, 1040, 1.0, 1040, 0.8, 1070, 0, NULL);
|
||
if (!XSymbolTable(_T("APPID"), TCHXD))
|
||
ads_regapp(TCHXD);
|
||
pStyle->setXData(pXData);
|
||
ads_relrb(pXData);
|
||
idRet = AddTextStyle(pStyle, TRUE);
|
||
}
|
||
xg_setvar(_T("TEXTSTYLE"), szTextStyle);
|
||
|
||
return idRet;
|
||
}
|
||
|
||
CString ReadXdata(Entity ent, const TCHAR*szName)
|
||
{
|
||
AcDbObjectId eId;
|
||
AcDbEntity *pEnt = NULL;
|
||
acdbGetObjectId(eId, ent);
|
||
acdbOpenObject(pEnt, eId, AcDb::kForRead);
|
||
if (!pEnt)
|
||
return _T("");
|
||
resbuf *pRb = pEnt->xData(szName);
|
||
|
||
CString csRet;
|
||
if (pRb != NULL) {
|
||
resbuf *pTemp = pRb;
|
||
if (pTemp->rbnext != NULL) {
|
||
pTemp = pTemp->rbnext;
|
||
if (pTemp->restype == 1000)
|
||
csRet = pTemp->resval.rstring;
|
||
}
|
||
}
|
||
ads_relrb(pRb);
|
||
pEnt->close();
|
||
return csRet;
|
||
}
|
||
|
||
//写扩展数据
|
||
BOOL WriteXdata(Entity ent, const TCHAR*szName, const TCHAR*szValue)
|
||
{
|
||
AcDbObjectId eId;
|
||
AcDbEntity *pEnt = NULL;
|
||
acdbGetObjectId(eId, ent);
|
||
if (!XSymbolTable(_T("APPID"), szName))
|
||
ads_regapp(szName);
|
||
acdbOpenObject(pEnt, eId, AcDb::kForWrite);
|
||
if (!pEnt)
|
||
return FALSE;
|
||
resbuf *pXData = ads_buildlist(1001, szName, 1000, szValue, NULL);
|
||
pEnt->setXData(pXData);
|
||
ads_relrb(pXData);
|
||
pEnt->close();
|
||
return TRUE;
|
||
}
|
||
|
||
double GetValveWidth(const TCHAR* szBlockName)
|
||
{
|
||
XPointList lstPt;
|
||
AcDbBlockTableRecord *pRecord = NULL;
|
||
AcDbBlockTable* pBlockTable = NULL;
|
||
acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead);
|
||
AcDbBlockTableRecordIterator *pIterator = NULL;
|
||
|
||
if (Acad::eOk != pBlockTable->getAt(szBlockName, pRecord, AcDb::kForRead)) {
|
||
pBlockTable->close();
|
||
return -1;
|
||
}
|
||
if (pBlockTable)
|
||
pBlockTable->close();
|
||
pRecord->newIterator(pIterator);
|
||
if (pRecord)
|
||
pRecord->close();
|
||
|
||
for (pIterator->start(); !pIterator->done(); pIterator->step()) {
|
||
AcDbEntity *pEnt;
|
||
pIterator->getEntity(pEnt, AcDb::kForRead);
|
||
AcDbPoint *pPoint = NULL;
|
||
if (pPoint = AcDbPoint::cast(pEnt)) {
|
||
AcGePoint3d ptIns = pPoint->position();
|
||
lstPt.NewAppend(ptIns);
|
||
}
|
||
pEnt->close();
|
||
}
|
||
if (pIterator)
|
||
delete pIterator;
|
||
if (lstPt.Length() != 2)
|
||
return -1;
|
||
XPoint pt1 = *lstPt[0];
|
||
XPoint pt2 = *lstPt[1];
|
||
return ads_distance(pt1, pt2);
|
||
}
|
||
|
||
void GetAllPipeAndNodeByPipe(AcDbObjectId pipeId, AcDbObjectId idFront, PickSet &ss)
|
||
{
|
||
Entity entFront;
|
||
OPENOBJ_BEGIN(pipeId, AcDb::kForRead, TDbPipe, pPipe);
|
||
if(pPipe){
|
||
AcDbObjectId nodeId1(NULL), nodeId2(NULL);
|
||
nodeId1 = pPipe->GetNode(0);
|
||
nodeId2 = pPipe->GetNode(1);
|
||
if(idFront != nodeId1 && !!nodeId1){
|
||
ss += nodeId1;
|
||
}
|
||
if(idFront != nodeId2 && !!nodeId2){
|
||
ss += nodeId2;
|
||
}
|
||
int len = ss.Length();
|
||
}
|
||
OPENOBJ_END();
|
||
return;
|
||
}
|
||
|
||
BOOL IsPlanHydrant(AcDbObjectId idNode)
|
||
{
|
||
if(!idNode)
|
||
return FALSE;
|
||
|
||
AcDbObjectId idBlk = NULL;
|
||
OPENOBJ_BEGIN(idNode, AcDb::kForRead, TDbEquipment, pEquip);
|
||
if(pEquip)
|
||
idBlk = pEquip->GetBlock2d();
|
||
else
|
||
return FALSE;
|
||
OPENOBJ_END();
|
||
|
||
XString xsTmp1 = _T("$twtsys$00000386");
|
||
XString xsTmp2 = _T("$twtsys$00000383");
|
||
const TCHAR *szBlkName = NULL;
|
||
OPENOBJ_BEGIN(idBlk, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
|
||
if(pRecord){
|
||
pRecord->getName(szBlkName);
|
||
}
|
||
OPENOBJ_END();
|
||
if(_tcsicmp(szBlkName, xsTmp2) == 0 || _tcsicmp(szBlkName, xsTmp1) == 0)
|
||
return TRUE;
|
||
else
|
||
return FALSE;
|
||
}
|
||
|
||
BOOL IsSysSprinkler(AcDbObjectId idNode)
|
||
{
|
||
if(!idNode)
|
||
return FALSE;
|
||
AcDbObjectId idBlk = NULL;
|
||
OPENOBJ_BEGIN(idNode, AcDb::kForRead, TDbEquipment, pEquip);
|
||
if(pEquip)
|
||
idBlk = pEquip->GetBlock2d();
|
||
else
|
||
return FALSE;
|
||
OPENOBJ_END();
|
||
|
||
XString xsTmp1 = _T("$twtsys$00000126");
|
||
XString xsTmp2 = _T("$twtsys$00000283");
|
||
XString xsTmp3 = _T("$twtsys$00000130");
|
||
XString xsTmp4 = _T("$twtsys$00000542"); //CET 2012-1-6 ADD
|
||
const TCHAR *szBlkName = NULL;
|
||
OPENOBJ_BEGIN(idBlk, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
|
||
if(pRecord){
|
||
pRecord->getName(szBlkName);
|
||
}
|
||
OPENOBJ_END();
|
||
if(_tcsicmp(szBlkName, xsTmp2) == 0 || _tcsicmp(szBlkName, xsTmp1) == 0 ||
|
||
_tcsicmp(szBlkName, xsTmp3) == 0 || _tcsicmp(szBlkName, xsTmp4) == 0) //是喷头
|
||
return TRUE;
|
||
else
|
||
return FALSE;
|
||
}
|
||
|
||
int GetNodeType(Entity ent)
|
||
{
|
||
if(ent.Is(_T("ATS_PIPE")) || ent.Is(_T("ATS_PIPECANAL")))
|
||
return 0;
|
||
else if(ent.Is(_T("ATS_WELL")))
|
||
return 3;
|
||
else if(ent.Is(_T("ATS_EQUIPMENT"))){
|
||
AcDbObjectId id = NULL;
|
||
acdbGetObjectId(id, ent);
|
||
if(IsSprinkler(id) || IsSysSprinkler(id) || IsPlanHydrant(id))
|
||
return 2;
|
||
// if(IsPool(id))
|
||
// return 4;
|
||
// else
|
||
return -1;
|
||
}
|
||
else if(ent.Is(_T("ATS_POOL")))
|
||
return 4;
|
||
|
||
else if(ent.Is(_T("ATS_PIPEFITTING")))
|
||
return 1;
|
||
else
|
||
return -1;
|
||
}
|
||
|
||
void GetAllPipeAndNodeByNode(AcDbObjectId nodeId, AcDbObjectId idFront, PickSet &ss)
|
||
{
|
||
OPENOBJ_BEGIN(nodeId, AcDb::kForRead, TDbPipeNode, pNode);
|
||
if(pNode){
|
||
int num = pNode->GetInterfaceNum();
|
||
for(int i=0;i<num;i++){
|
||
TPipeInterface face;
|
||
pNode->GetInterface(i, face);
|
||
AcDbObjectId nextPipeId = face.m_idPipe;
|
||
if(nextPipeId == NULL)
|
||
continue;
|
||
// OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, TDbPipe, pPipe);
|
||
// if(pPipe){
|
||
// if(pPipe->Length() < pPipe->GetPScale()/20)
|
||
// continue;
|
||
// }
|
||
// OPENOBJ_END();// 沈睿 remove it 2008-3-3 【喷淋管径】有时候有特短的管线
|
||
if(idFront == nextPipeId)
|
||
continue;
|
||
ss += nextPipeId;
|
||
int len = ss.Length();
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
BOOL SearchSprinkPipeSys(Entity ent, AcDbObjectId idFront, SSearchPipeList *pListAll, PickSet &ssAll)
|
||
{
|
||
AcDbObjectId id = NULL;
|
||
acdbGetObjectId(id, ent);
|
||
pListAll->m_ID = id;
|
||
AcDbObjectIdArray idArray;
|
||
int len(0);
|
||
{
|
||
PickSet ss(SS_FREE);
|
||
if (ent.Is(_T("ATS_PIPE")) || ent.Is(_T("ATS_PIPECANAL")))
|
||
GetAllPipeAndNodeByPipe(id, idFront, ss);
|
||
else
|
||
GetAllPipeAndNodeByNode(id, idFront, ss);
|
||
for (long j = 0; j < ss.Length(); j++) {
|
||
Entity entTmp = ss[j];
|
||
if (entTmp.In(&ssAll) > 0) {
|
||
PickSet ssLoop(SS_FREE);
|
||
ssLoop += entTmp;
|
||
//发现有回路,一直顺着头找所有的选择集,并把他们亮显
|
||
SSearchPipeList *pNode = NULL;
|
||
if (pListAll->m_pPrevious != NULL)
|
||
pNode = pListAll->m_pPrevious;
|
||
while (pNode != NULL) {
|
||
ssLoop += pNode->m_ID;
|
||
if (pNode->m_pPrevious != NULL)
|
||
pNode = pNode->m_pPrevious;
|
||
else
|
||
break;
|
||
}
|
||
ssLoop.Redraw(3);
|
||
return FALSE;
|
||
}
|
||
}
|
||
ssAll += ss;
|
||
len = ss.Length();
|
||
for (long i = 0; i < ss.Length(); i++) {
|
||
Entity entTmp = ss[i];
|
||
AcDbObjectId idTmp = NULL;
|
||
acdbGetObjectId(idTmp, entTmp);
|
||
idArray.append(idTmp);
|
||
}
|
||
}
|
||
len = idArray.length();
|
||
|
||
for (long i = 0; i < len; i++) {
|
||
AcDbObjectId idTmp = idArray[i];
|
||
ads_name entTmp;
|
||
acdbGetAdsName(entTmp, idTmp);
|
||
SSearchPipeList *pList = new SSearchPipeList();
|
||
pList->m_ID = idTmp;
|
||
pList->m_iType = GetNodeType(entTmp);
|
||
pList->m_pPrevious = pListAll;
|
||
pListAll->m_lstNode.Append(pList);
|
||
if (!SearchSprinkPipeSys(entTmp, id, pList, ssAll)) {
|
||
return FALSE;
|
||
}
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
double GetValBetween2(double n1, double n2, double nRange1, double nRange2, double nFactor)
|
||
{
|
||
if(n1 < 0 || n2 < 0)
|
||
return -1;
|
||
double nSmall = nRange1 < nRange2 ? nRange1 : nRange2;
|
||
nRange1 = fabs(nRange1 - nRange2);
|
||
nSmall = nFactor - nSmall;
|
||
nSmall = nSmall/nRange1;
|
||
double nRet = n1 < n2 ? n1 : n2;
|
||
nRet = nRet + fabs(n1 - n2)*nSmall;
|
||
return nRet;
|
||
}
|
||
|
||
double GetFullByPercentQ(double nPercentQ)
|
||
{
|
||
//差值法查表 2003规范 P107页
|
||
double nAc(0);
|
||
if (nPercentQ <= 0.005)
|
||
nAc = GetValBetween2(0, 0.05, 0, 0.005, nPercentQ);
|
||
else if (nPercentQ > 0.005 && nPercentQ <= 0.021)
|
||
nAc = GetValBetween2(0.05, 0.1, 0.005, 0.021, nPercentQ);
|
||
else if (nPercentQ > 0.021 && nPercentQ <= 0.049)
|
||
nAc = GetValBetween2(0.1, 0.15, 0.021, 0.049, nPercentQ);
|
||
else if (nPercentQ > 0.049 && nPercentQ <= 0.088)
|
||
nAc = GetValBetween2(0.15, 0.2, 0.049, 0.088, nPercentQ);
|
||
else if (nPercentQ > 0.088 && nPercentQ <= 0.137)
|
||
nAc = GetValBetween2(0.2, 0.25, 0.088, 0.137, nPercentQ);
|
||
else if (nPercentQ > 0.137 && nPercentQ <= 0.196)
|
||
nAc = GetValBetween2(0.25, 0.3, 0.137, 0.196, nPercentQ);
|
||
else if (nPercentQ > 0.196 && nPercentQ <= 0.263)
|
||
nAc = GetValBetween2(0.3, 0.35, 0.196, 0.263, nPercentQ);
|
||
else if (nPercentQ > 0.263 && nPercentQ <= 0.337)
|
||
nAc = GetValBetween2(0.35, 0.4, 0.263, 0.337, nPercentQ);
|
||
else if (nPercentQ > 0.337 && nPercentQ <= 0.417)
|
||
nAc = GetValBetween2(0.4, 0.45, 0.337, 0.417, nPercentQ);
|
||
else if (nPercentQ > 0.417 && nPercentQ <= 0.5)
|
||
nAc = GetValBetween2(0.45, 0.5, 0.417, 0.5, nPercentQ);
|
||
else if (nPercentQ > 0.5 && nPercentQ <= 0.586)
|
||
nAc = GetValBetween2(0.5, 0.55, 0.5, 0.586, nPercentQ);
|
||
else if (nPercentQ > 0.586 && nPercentQ <= 0.672)
|
||
nAc = GetValBetween2(0.55, 0.6, 0.586, 0.672, nPercentQ);
|
||
else if (nPercentQ > 0.672 && nPercentQ <= 0.756)
|
||
nAc = GetValBetween2(0.6, 0.65, 0.672, 0.756, nPercentQ);
|
||
else if (nPercentQ > 0.756 && nPercentQ <= 0.837)
|
||
nAc = GetValBetween2(0.65, 0.7, 0.756, 0.837, nPercentQ);
|
||
else if (nPercentQ > 0.837 && nPercentQ <= 0.912)
|
||
nAc = GetValBetween2(0.7, 0.75, 0.837, 0.912, nPercentQ);
|
||
else if (nPercentQ > 0.912 && nPercentQ <= 0.977)
|
||
nAc = GetValBetween2(0.75, 0.8, 0.912, 0.977, nPercentQ);
|
||
else if (nPercentQ > 0.977 && nPercentQ <= 1.03)
|
||
nAc = GetValBetween2(0.8, 0.85, 0.977, 1.03, nPercentQ);
|
||
else if (nPercentQ > 1.03 && nPercentQ <= 1.066)
|
||
nAc = GetValBetween2(0.85, 0.9, 1.03, 1.066, nPercentQ);
|
||
else if (nPercentQ > 1.066 && nPercentQ <= 1.075)
|
||
nAc = GetValBetween2(0.9, 0.95, 1.066, 1.075, nPercentQ);
|
||
else if (nPercentQ > 1.075)
|
||
nAc = GetValBetween2(0.95, 1, 1.075, 2.0, nPercentQ);
|
||
else if (fabs(nPercentQ - 1) < 0.001)
|
||
nAc = 1;
|
||
|
||
return nAc;
|
||
}
|
||
|
||
CString GetPipeMaterialByIdx(int idx)
|
||
{
|
||
if (idx < 0)
|
||
return _T("");
|
||
XStringList lst;
|
||
GetPipeMaterialList(lst);
|
||
if (idx > lst.Length()) {
|
||
adsout << _T("没有发现用户自定义管材。请确认sys/pipe.dbf文件是否是最新版。\n");
|
||
return _T("");
|
||
}
|
||
CString csMat = (const TCHAR*)lst[idx];
|
||
return csMat;
|
||
}
|
||
|
||
BOOL IsExistLayer(const TCHAR* szLayer)
|
||
{
|
||
BOOL bHasIt;
|
||
AcDbLayerTable *pLayerTable = NULL;
|
||
acdbCurDwg()->getLayerTable(pLayerTable, AcDb::kForRead);
|
||
bHasIt = pLayerTable->has(szLayer);
|
||
pLayerTable->close();
|
||
return bHasIt;
|
||
}
|
||
|
||
AcDbObjectId InitPipeLayer(const TCHAR* szLay)
|
||
{
|
||
AcDbObjectId id = NULL;
|
||
if (!IsExistLayer(szLay)) {
|
||
id = InitLayer(szLay);
|
||
int idx = GetPipeLayerIdxByName(szLay);
|
||
if (idx > -1)
|
||
SetLayerLineType(szLay, g_csTwtLineType[idx]);
|
||
}
|
||
else
|
||
id = InitLayer(szLay);
|
||
return id;
|
||
}
|
||
|
||
CString GetBlkNameById(AcDbObjectId id)
|
||
{
|
||
CString csBlkName;
|
||
const TCHAR *szBlkName = NULL;
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
|
||
if (pRecord)
|
||
pRecord->getName(szBlkName);
|
||
OPENOBJ_END();
|
||
csBlkName = szBlkName;
|
||
return csBlkName;
|
||
}
|
||
|
||
void GetPipePoint(Entity ent, XPoint &pt1, XPoint& pt2, XPoint &ptMid)
|
||
{
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe);
|
||
if (pPipe) {
|
||
pt1 = pPipe->StartPoint();
|
||
pt2 = pPipe->EndPoint();
|
||
if (pPipe->Is(CURVE_LINE))
|
||
Midpoint(pt1, pt2, ptMid)
|
||
else if (pPipe->Is(CURVE_ARC)) {
|
||
XArc arc = pPipe->GetArc();
|
||
arc.MidPoint(ptMid);
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
void GetPipePoint(Entity ent, XPoint &pt1, XPoint& pt2)
|
||
{
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe);
|
||
if (pPipe) {
|
||
pt1 = pPipe->StartPoint();
|
||
pt2 = pPipe->EndPoint();
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
void HideDialog(CWnd *pWnd, BOOL Flag)
|
||
{
|
||
if (Flag) {
|
||
pWnd->GetParent()->EnableWindow(TRUE);
|
||
pWnd->GetParent()->SetFocus();
|
||
pWnd->GetParent()->SetActiveWindow();
|
||
pWnd->ShowWindow(SW_HIDE);
|
||
}
|
||
else {
|
||
pWnd->GetParent()->EnableWindow(FALSE);
|
||
pWnd->EnableWindow(TRUE);
|
||
pWnd->SetActiveWindow();
|
||
pWnd->ShowWindow(SW_SHOW);
|
||
}
|
||
}
|
||
|
||
void GetPointPickSet(XPoint pt, PickSet &ss, const RBList &rbMask, int len)//注意:pt是UCS点
|
||
{
|
||
double dLen = len;
|
||
// if(DocGetMeterUnitDraw())
|
||
// dLen = dLen / 100.0;
|
||
XPoint ptTemp1, ptTemp2;
|
||
ptTemp1.x = pt.x - dLen;
|
||
ptTemp1.y = pt.y + dLen;
|
||
ptTemp2.x = pt.x + dLen;
|
||
ptTemp2.y = pt.y - dLen;
|
||
//sr add 2006-4-28 支持三维上插入阀门
|
||
ptTemp1.z = pt.z;
|
||
ptTemp2.z = pt.z;
|
||
|
||
XLine line(ptTemp1, ptTemp2, 1);
|
||
// line.Make();
|
||
ss.Get(_T("C"), ptTemp1, ptTemp2, rbMask);
|
||
|
||
long len1 = ss.Length();
|
||
for (long i = 0; i < len1; i++) {
|
||
Entity ent = ss[i];
|
||
}
|
||
|
||
}
|
||
|
||
TPipeSys::SysType GetPipeSysByLayer(const TCHAR* szLayer)
|
||
{
|
||
CString csLayer = szLayer;
|
||
TPipeSys::SysType sys;
|
||
/* cet 2011.12.9 modify
|
||
if(csLayer == LAY_PIPE_SPRINKLE || csLayer == LAY_PIPE_SPRINKLE2 || csLayer == LAY_PIPE_SPRINKLE3 ||
|
||
csLayer == LAY_VPIPE_SPRINKLE || csLayer == LAY_VPIPE_SPRINKLE2 || csLayer == LAY_VPIPE_SPRINKLE3)
|
||
sys = TPipeSys::kSprinkle;
|
||
else if(csLayer == LAY_PIPE_FIRE || csLayer == LAY_PIPE_FIRE2 || csLayer == LAY_PIPE_FIRE3 ||
|
||
csLayer == LAY_VPIPE_FIRE || csLayer == LAY_VPIPE_FIRE2 || csLayer == LAY_VPIPE_FIRE3)
|
||
sys = TPipeSys::kFireFighting;
|
||
else if(csLayer == LAY_PIPE_USED || csLayer == LAY_PIPE_USED2 || csLayer == LAY_PIPE_USED3 ||
|
||
csLayer == LAY_VPIPE_USED || csLayer == LAY_VPIPE_USED2 || csLayer == LAY_VPIPE_USED3)
|
||
sys = TPipeSys::kUsedWater;
|
||
else if(csLayer == LAY_PIPE_FEED || csLayer == LAY_PIPE_FEED2 || csLayer == LAY_PIPE_FEED3 ||
|
||
csLayer == LAY_VPIPE_FEED || csLayer == LAY_VPIPE_FEED2 || csLayer == LAY_VPIPE_FEED3 )
|
||
sys = TPipeSys::kFeedWater;
|
||
else if(csLayer == LAY_PIPE_HEADFEED || csLayer == LAY_PIPE_HEADFEED2 || csLayer == LAY_PIPE_HEADFEED3 ||
|
||
csLayer == LAY_VPIPE_HEADFEED || csLayer == LAY_VPIPE_HEADFEED2 || csLayer == LAY_VPIPE_HEADFEED3)
|
||
sys = TPipeSys::kHeatFeedWater;
|
||
else if(csLayer == LAY_PIPE_HEADBACK || csLayer == LAY_PIPE_HEADBACK2 || csLayer == LAY_PIPE_HEADBACK3 ||
|
||
csLayer == LAY_VPIPE_HEADBACK || csLayer == LAY_VPIPE_HEADBACK2 || csLayer == LAY_VPIPE_HEADBACK3)
|
||
sys = TPipeSys::kHeatBackWater;
|
||
*/
|
||
if (csLayer == LAY_PIPE_SPRINKLE || csLayer == LAY_VPIPE_SPRINKLE)
|
||
sys = TPipeSys::kSprinkle;
|
||
else if (csLayer == LAY_PIPE_SPRINKLE2 || csLayer == LAY_VPIPE_SPRINKLE2)
|
||
sys = TPipeSys::kSprinkle2;
|
||
else if (csLayer == LAY_PIPE_SPRINKLE3 || csLayer == LAY_VPIPE_SPRINKLE3)
|
||
sys = TPipeSys::kSprinkle3;
|
||
else if (csLayer == LAY_PIPE_FIRE || csLayer == LAY_VPIPE_FIRE)
|
||
sys = TPipeSys::kFireFighting;
|
||
else if (csLayer == LAY_PIPE_FIRE2 || csLayer == LAY_VPIPE_FIRE2)
|
||
sys = TPipeSys::kFireFighting2;
|
||
else if (csLayer == LAY_PIPE_FIRE3 || csLayer == LAY_VPIPE_FIRE3)
|
||
sys = TPipeSys::kFireFighting3;
|
||
else if (csLayer == LAY_PIPE_USED || csLayer == LAY_VPIPE_USED)
|
||
sys = TPipeSys::kUsedWater;
|
||
else if (csLayer == LAY_PIPE_USED2 || csLayer == LAY_VPIPE_USED2)
|
||
sys = TPipeSys::kUsedWater2;
|
||
else if (csLayer == LAY_PIPE_USED3 || csLayer == LAY_VPIPE_USED3)
|
||
sys = TPipeSys::kUsedWater3;
|
||
else if (csLayer == LAY_PIPE_FEED || csLayer == LAY_VPIPE_FEED)
|
||
sys = TPipeSys::kFeedWater;
|
||
else if (csLayer == LAY_PIPE_FEED2 || csLayer == LAY_VPIPE_FEED2)
|
||
sys = TPipeSys::kFeedWater2;
|
||
else if (csLayer == LAY_PIPE_FEED3 || csLayer == LAY_VPIPE_FEED3)
|
||
sys = TPipeSys::kFeedWater3;
|
||
else if (csLayer == LAY_PIPE_HEADFEED || csLayer == LAY_VPIPE_HEADFEED)
|
||
sys = TPipeSys::kHeatFeedWater;
|
||
else if (csLayer == LAY_PIPE_HEADFEED2 || csLayer == LAY_VPIPE_HEADFEED2)
|
||
sys = TPipeSys::kHeatFeedWater2;
|
||
else if (csLayer == LAY_PIPE_HEADFEED3 || csLayer == LAY_VPIPE_HEADFEED3)
|
||
sys = TPipeSys::kHeatFeedWater3;
|
||
else if (csLayer == LAY_PIPE_HEADBACK || csLayer == LAY_VPIPE_HEADBACK)
|
||
sys = TPipeSys::kHeatBackWater;
|
||
else if (csLayer == LAY_PIPE_HEADBACK2 || csLayer == LAY_VPIPE_HEADBACK2)
|
||
sys = TPipeSys::kHeatBackWater2;
|
||
else if (csLayer == LAY_PIPE_HEADBACK3 || csLayer == LAY_VPIPE_HEADBACK3)
|
||
sys = TPipeSys::kHeatBackWater3;
|
||
|
||
else if (csLayer == LAY_PIPE_DIRT || csLayer == LAY_VPIPE_DIRT)
|
||
sys = TPipeSys::kDirtWater;
|
||
else if (csLayer == LAY_PIPE_USELESS || csLayer == LAY_VPIPE_USELESS)
|
||
sys = TPipeSys::kUselessWater;
|
||
else if (csLayer == LAY_PIPE_RAIN || csLayer == LAY_VPIPE_RAIN)
|
||
sys = TPipeSys::kRainWater;
|
||
else if (csLayer == LAY_PIPE_COAGULATE || csLayer == LAY_VPIPE_COAGULATE)
|
||
sys = TPipeSys::kCoagulate;
|
||
else if (csLayer == LAY_PIPE_DRINK || csLayer == LAY_VPIPE_DRINK)
|
||
sys = TPipeSys::kDrink;
|
||
else if (csLayer == LAY_PIPE_PRESSDIRT || csLayer == LAY_VPIPE_PRESSDIRT)
|
||
sys = TPipeSys::kPressDirt;
|
||
else if (csLayer == LAY_PIPE_PRESSUSELESS || csLayer == LAY_VPIPE_PRESSUSELESS)
|
||
sys = TPipeSys::kPressUseless;
|
||
else if (csLayer == LAY_PIPE_PRESSRAIN || csLayer == LAY_VPIPE_PRESSRAIN)
|
||
sys = TPipeSys::kPressRain;
|
||
else if (csLayer == LAY_PIPE_OTHER || csLayer == LAY_VPIPE_OTHER)
|
||
sys = TPipeSys::kOther;
|
||
else if (csLayer == LAY_PIPE_USER1 || csLayer == LAY_VPIPE_USER1)
|
||
sys = TPipeSys::kCivilFeed;
|
||
else if (csLayer == LAY_PIPE_USER2 || csLayer == LAY_VPIPE_USER2)
|
||
sys = TPipeSys::kCycleFeed;
|
||
else if (csLayer == LAY_PIPE_USER3 || csLayer == LAY_VPIPE_USER3) // cet 2011.12.1 add kUer3 - kUser8
|
||
sys = TPipeSys::kUser3;
|
||
else if (csLayer == LAY_PIPE_USER4 || csLayer == LAY_VPIPE_USER4)
|
||
sys = TPipeSys::kUser4;
|
||
else if (csLayer == LAY_PIPE_USER5 || csLayer == LAY_VPIPE_USER5)
|
||
sys = TPipeSys::kUser5;
|
||
else if (csLayer == LAY_PIPE_USER6 || csLayer == LAY_VPIPE_USER6)
|
||
sys = TPipeSys::kUser6;
|
||
else if (csLayer == LAY_PIPE_USER7 || csLayer == LAY_VPIPE_USER7)
|
||
sys = TPipeSys::kUser7;
|
||
else if (csLayer == LAY_PIPE_USER8 || csLayer == LAY_VPIPE_USER8)
|
||
sys = TPipeSys::kUser8;
|
||
else
|
||
sys = TPipeSys::kUnknownSys;
|
||
return sys;
|
||
}
|
||
|
||
CString GetLayerLineType(const TCHAR* szLayer)
|
||
{
|
||
CString csRet;
|
||
AcDbObjectId idLayer = GetLayerIdFromString(szLayer);
|
||
if (!idLayer)
|
||
return csRet;
|
||
OPENOBJ_BEGIN(idLayer, AcDb::kForRead, AcDbLayerTableRecord, pLayer);
|
||
if (pLayer) {
|
||
AcDbObjectId id = pLayer->linetypeObjectId();
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, AcDbLinetypeTableRecord, pStyle);
|
||
if (pStyle) {
|
||
const TCHAR* szName;
|
||
pStyle->getName(szName);
|
||
csRet = szName;
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
}
|
||
OPENOBJ_END();
|
||
return csRet;
|
||
}
|
||
|
||
CString GetDnByMat(const TCHAR* szMat)
|
||
{
|
||
CodeBase db;
|
||
int Number;
|
||
CString csType, csValue, csRemark;
|
||
XString fullFile;
|
||
if (!FindFile(_T("DataStore.dbf"), fullFile)) {
|
||
Callme(_T("对不起,没有发现DataStore.dbf文件!"));
|
||
return _T("");
|
||
}
|
||
XDbfTable *pTable = db.Open(fullFile);
|
||
pTable->MoveFirst();
|
||
while (!pTable->IsEOF()) {
|
||
GET_FIELD(pTable, _T("TypeNumber"), Number);
|
||
GET_FIELD(pTable, _T("TypeName"), csType);
|
||
GET_FIELD(pTable, _T("TypeValue"), csValue);
|
||
GET_FIELD(pTable, _T("Remark"), csRemark);
|
||
if (Number == 40 && _tcsicmp((const TCHAR*)csValue, szMat) == 0) {
|
||
return csRemark;
|
||
}
|
||
pTable->MoveNext();
|
||
}
|
||
return _T("DN");
|
||
}
|
||
|
||
CString GetPipeWireLayLineType(const TCHAR* szLayer)
|
||
{
|
||
CString csRet;
|
||
AcDbObjectId idLayer = GetLayerIdFromString(szLayer);
|
||
if (!idLayer)
|
||
return csRet;
|
||
OPENOBJ_BEGIN(idLayer, AcDb::kForRead, AcDbLayerTableRecord, pLayer);
|
||
if (pLayer) {
|
||
AcDbObjectId id = pLayer->linetypeObjectId();
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, AcDbLinetypeTableRecord, pStyle);
|
||
if (pStyle) {
|
||
const TCHAR* szName;
|
||
pStyle->getName(szName);
|
||
csRet = szName;
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
}
|
||
OPENOBJ_END();
|
||
if (g_bLineTypeByLayer)
|
||
csRet = _T("ByLayer");
|
||
return csRet;
|
||
}
|
||
|
||
void SetLayerColorIdx(const TCHAR *szLayer, int iColor)
|
||
{
|
||
DList<CLayerData> lstLayer;
|
||
XString fullFile;
|
||
if (FindFile(_T("layerdef.dat"), fullFile)) {
|
||
FILE *fp = fopen(_AS(fullFile), "r");
|
||
if (!fp)
|
||
return;
|
||
while (!feof(fp)) {
|
||
char sBuf[256] = "";
|
||
TCHAR cName[256] = _T(""), eName[256] = _T(""), sColor[256] = _T(""), sLineType[256] = _T(""), sDes[256] = _T("");
|
||
fgets(sBuf, 255, fp);
|
||
if (sBuf[0]) {
|
||
CT_strnth(TString(sBuf), 1, cName);
|
||
CT_strnth(TString(sBuf), 2, eName);
|
||
CT_strnth(TString(sBuf), 3, sColor);
|
||
CT_strnth(TString(sBuf), 4, sLineType);
|
||
CT_strnth(TString(sBuf), 5, sDes);
|
||
}
|
||
if (cName[0] && eName[0]) {
|
||
int nColor = _ttoi(sColor);
|
||
lstLayer.Append(new CLayerData(eName, cName, sLineType, sDes, nColor));
|
||
}
|
||
}
|
||
fclose(fp);
|
||
}
|
||
int len = lstLayer.Length();
|
||
for (int i = 0; i < len; i++) {
|
||
if (_tcscmp(lstLayer[i]->m_csEName, szLayer) == 0) {
|
||
lstLayer[i]->m_iColor = iColor;
|
||
break;
|
||
}
|
||
}
|
||
|
||
FILE *fp = fopen(_AS(fullFile), "w");
|
||
if (!fp)
|
||
return;
|
||
len = lstLayer.Length();
|
||
for (i = 0; i < len; i++) {
|
||
CString csColor;
|
||
csColor.Format(_T("%d"), lstLayer[i]->m_iColor);
|
||
CString csTmp = lstLayer[i]->m_csCName + _T(" ") + lstLayer[i]->m_csEName + _T(" ") + csColor + _T(" ")
|
||
+ lstLayer[i]->m_csLinetype + _T(" ") + lstLayer[i]->m_csDes + _T("\n");
|
||
fputs(_AS(csTmp), fp);
|
||
}
|
||
fclose(fp);
|
||
|
||
AcDbObjectId idLayer = GetLayerIdFromString(szLayer);
|
||
if (!idLayer)
|
||
return;
|
||
OPENOBJ_BEGIN(idLayer, AcDb::kForWrite, AcDbLayerTableRecord, pLayer);
|
||
if (pLayer) {
|
||
AcCmColor color;
|
||
color.setColorIndex(iColor);
|
||
pLayer->setColor(color);
|
||
}
|
||
else {
|
||
AfxMessageBox(_T("层写保护!"));
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
}
|
||
void GetAllTgLineType(XStringList &lstLineTypeName, XStringList &lstLineTypeComment)
|
||
{
|
||
lstLineTypeName.Append(tstrnew(_T("CONTINUOUS")));
|
||
lstLineTypeComment.Append(tstrnew(_T("──────────")));
|
||
XString xsDbfFile;
|
||
if (!FindFile(_T("linetype.dbf"), xsDbfFile)) {
|
||
AfxMessageBox(_T("对不起,没有发现linetype.dbf文件!"));
|
||
return;
|
||
}
|
||
CodeBase db;
|
||
XDbfTable *pTable = db.Open(xsDbfFile);
|
||
if (!pTable) {
|
||
CString csTmp;
|
||
csTmp.Format(_T("%s文件只读或损坏!"), xsDbfFile);
|
||
AfxMessageBox(csTmp);
|
||
|
||
// AfxMessageBox(_T("TK文件只读或损坏!"));
|
||
return;
|
||
}
|
||
|
||
for (pTable->MoveFirst(); !pTable->IsEOF(); pTable->MoveNext()) {
|
||
CString sName, sComment;
|
||
GET_FIELD(pTable, _T("Name"), sName);
|
||
GET_FIELD(pTable, _T("Comment"), sComment);
|
||
lstLineTypeName.Append(tstrnew(sName));
|
||
lstLineTypeComment.Append(tstrnew(sComment));
|
||
}
|
||
}
|
||
|
||
int GetPipeLayerIdxByName(const TCHAR* szLayer)
|
||
{
|
||
CString csLayer;
|
||
csLayer = (const TCHAR*)szLayer;
|
||
|
||
int ret = 0;
|
||
if (csLayer == LAY_PIPE_FEED || csLayer == LAY_VPIPE_FEED)
|
||
ret = 0;
|
||
else if (csLayer == LAY_PIPE_HEADFEED || csLayer == LAY_VPIPE_HEADFEED)
|
||
ret = 1;
|
||
else if (csLayer == LAY_PIPE_HEADBACK || csLayer == LAY_VPIPE_HEADBACK)
|
||
ret = 2;
|
||
else if (csLayer == LAY_PIPE_DIRT || csLayer == LAY_VPIPE_DIRT)
|
||
ret = 3;
|
||
else if (csLayer == LAY_PIPE_USELESS || csLayer == LAY_VPIPE_USELESS)
|
||
ret = 4;
|
||
else if (csLayer == LAY_PIPE_RAIN || csLayer == LAY_VPIPE_RAIN)
|
||
ret = 5;
|
||
else if (csLayer == LAY_PIPE_USED || csLayer == LAY_VPIPE_USED)
|
||
ret = 6;
|
||
else if (csLayer == LAY_PIPE_FIRE || csLayer == LAY_VPIPE_FIRE)
|
||
ret = 7;
|
||
else if (csLayer == LAY_PIPE_SPRINKLE || csLayer == LAY_VPIPE_SPRINKLE)
|
||
ret = 8;
|
||
else if (csLayer == LAY_PIPE_COAGULATE || csLayer == LAY_VPIPE_COAGULATE)
|
||
ret = 9;
|
||
else if (csLayer == LAY_PIPE_DRINK || csLayer == LAY_VPIPE_DRINK)
|
||
ret = 10;
|
||
else if (csLayer == LAY_PIPE_PRESSDIRT || csLayer == LAY_VPIPE_PRESSDIRT)
|
||
ret = 11;
|
||
else if (csLayer == LAY_PIPE_PRESSUSELESS || csLayer == LAY_VPIPE_PRESSUSELESS)
|
||
ret = 12;
|
||
else if (csLayer == LAY_PIPE_PRESSRAIN || csLayer == LAY_VPIPE_PRESSRAIN)
|
||
ret = 13;
|
||
else if (csLayer == LAY_PIPE_OTHER || csLayer == LAY_VPIPE_OTHER)
|
||
ret = 14;
|
||
else if (csLayer == LAY_PIPE_USER1 || csLayer == LAY_VPIPE_USER1)
|
||
ret = 15;
|
||
else if (csLayer == LAY_PIPE_USER2 || csLayer == LAY_VPIPE_USER2)
|
||
ret = 16;
|
||
else if (csLayer == LAY_PIPE_FEED2 || csLayer == LAY_VPIPE_FEED2)
|
||
ret = 17;
|
||
else if (csLayer == LAY_PIPE_FEED3 || csLayer == LAY_VPIPE_FEED3)
|
||
ret = 18;
|
||
else if (csLayer == LAY_PIPE_HEADFEED2 || csLayer == LAY_VPIPE_HEADFEED2)
|
||
ret = 19;
|
||
else if (csLayer == LAY_PIPE_HEADFEED3 || csLayer == LAY_VPIPE_HEADFEED3)
|
||
ret = 20;
|
||
else if (csLayer == LAY_PIPE_HEADBACK2 || csLayer == LAY_VPIPE_HEADBACK2)
|
||
ret = 21;
|
||
else if (csLayer == LAY_PIPE_HEADBACK3 || csLayer == LAY_VPIPE_HEADBACK3)
|
||
ret = 22;
|
||
else if (csLayer == LAY_PIPE_FIRE2 || csLayer == LAY_VPIPE_FIRE2)
|
||
ret = 23;
|
||
else if (csLayer == LAY_PIPE_FIRE3 || csLayer == LAY_VPIPE_FIRE3)
|
||
ret = 24;
|
||
else if (csLayer == LAY_PIPE_SPRINKLE2 || csLayer == LAY_VPIPE_SPRINKLE2)
|
||
ret = 25;
|
||
else if (csLayer == LAY_PIPE_SPRINKLE3 || csLayer == LAY_VPIPE_SPRINKLE3)
|
||
ret = 26;
|
||
else if (csLayer == LAY_PIPE_USED2 || csLayer == LAY_VPIPE_USED2)
|
||
ret = 27;
|
||
else if (csLayer == LAY_PIPE_USED3 || csLayer == LAY_VPIPE_USED3)
|
||
ret = 28;
|
||
else if (csLayer == LAY_VPIPE_USER3 || csLayer == LAY_PIPE_USER3) // cet 2011.12.1 add 29 - 34
|
||
ret = 29;
|
||
else if (csLayer == LAY_VPIPE_USER4 || csLayer == LAY_PIPE_USER4)
|
||
ret = 30;
|
||
else if (csLayer == LAY_VPIPE_USER5 || csLayer == LAY_PIPE_USER5)
|
||
ret = 31;
|
||
else if (csLayer == LAY_VPIPE_USER6 || csLayer == LAY_PIPE_USER6)
|
||
ret = 32;
|
||
else if (csLayer == LAY_VPIPE_USER7 || csLayer == LAY_PIPE_USER7)
|
||
ret = 33;
|
||
else if (csLayer == LAY_VPIPE_USER8 || csLayer == LAY_PIPE_USER8)
|
||
ret = 34;
|
||
else
|
||
ret = -1;
|
||
return ret;
|
||
}
|
||
|
||
CString GetPipeLayerByIdx(int iLayer)
|
||
{
|
||
if (iLayer > 34 || iLayer < 0)
|
||
return CString();
|
||
CString csLayer[] = { LAY_PIPE_FEED, LAY_PIPE_HEADFEED, LAY_PIPE_HEADBACK, LAY_PIPE_DIRT,
|
||
LAY_PIPE_USELESS, LAY_PIPE_RAIN, LAY_PIPE_USED, LAY_PIPE_FIRE, LAY_PIPE_SPRINKLE,
|
||
LAY_PIPE_COAGULATE, LAY_PIPE_DRINK, LAY_PIPE_PRESSDIRT, LAY_PIPE_PRESSUSELESS,
|
||
LAY_PIPE_PRESSRAIN, LAY_PIPE_OTHER, LAY_PIPE_USER1, LAY_PIPE_USER2,
|
||
LAY_PIPE_FEED2,LAY_PIPE_FEED3, LAY_PIPE_HEADFEED2,LAY_PIPE_HEADFEED3,
|
||
LAY_PIPE_HEADBACK2,LAY_PIPE_HEADBACK3,LAY_PIPE_FIRE2,LAY_PIPE_FIRE3,
|
||
LAY_PIPE_SPRINKLE2,LAY_PIPE_SPRINKLE3,LAY_PIPE_USED2,LAY_PIPE_USED3,
|
||
LAY_PIPE_USER3, LAY_PIPE_USER4, LAY_PIPE_USER5, LAY_PIPE_USER6, LAY_PIPE_USER7, // cet 2011.12.1 add user3-user8
|
||
LAY_PIPE_USER8,
|
||
};
|
||
return csLayer[iLayer];
|
||
}
|
||
|
||
void UpdateMultDim()
|
||
{
|
||
RBList rbMaskDim(RTDXF0, _T("ATS_PIPEMULTDIM"), NULL);
|
||
PickSet ssDim(SS_FREE);
|
||
ssDim.Get(_T("X"), NULL, NULL, rbMaskDim);
|
||
long len = ssDim.Length();
|
||
if (len > 0)
|
||
UpdateGraphic(ssDim);
|
||
}
|
||
|
||
void UpdateMultDim(Entity ent)
|
||
{
|
||
XPoint ptS, ptE;
|
||
GetPipePoint(ent, ptS, ptE);
|
||
if (IsPipeVertical(ent)) {
|
||
double nRadius(0);
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe);
|
||
if (pPipe) {
|
||
nRadius = pPipe->GetRadius() * pPipe->GetPScale();
|
||
}
|
||
OPENOBJ_END();
|
||
ptS.z = 0;
|
||
ptS.x -= nRadius;
|
||
ptS.y -= nRadius;
|
||
ptE.z = 0;
|
||
ptE.x += nRadius;
|
||
ptE.y += nRadius;
|
||
}
|
||
XPoint ptUcsS, ptUcsE;
|
||
ptUcsS = Wcs2Ucs(ptS);
|
||
ptUcsE = Wcs2Ucs(ptE);
|
||
ptUcsS.z = 0;
|
||
ptUcsE.z = 0;
|
||
//更新引出标注
|
||
RBList rbMaskDim(RTDXF0, _T("ATS_PIPEMULTDIM"), NULL);
|
||
PickSet ssDim(SS_FREE);
|
||
ssDim.Get(_T("C"), ptUcsS, ptUcsE, rbMaskDim);
|
||
long len = ssDim.Length();
|
||
if (len > 0)
|
||
UpdateGraphic(ssDim);
|
||
}
|
||
|
||
AcDbObjectId GetLinetypeIdFromString2(const TCHAR* pStr)
|
||
{
|
||
|
||
AcDbDatabase *pDb = acdbCurDwg();
|
||
AcDbObjectId id;
|
||
if (pStr) {
|
||
AcDbLinetypeTable* pLinetypeTable = NULL;
|
||
|
||
//modified by whl on 060301
|
||
//Acad::ErrorStatus err = acdbCurDwg()->getLinetypeTable(
|
||
Acad::ErrorStatus err = pDb->getLinetypeTable(
|
||
|
||
pLinetypeTable, AcDb::kForRead);
|
||
if (err == Acad::eOk && pLinetypeTable) {
|
||
err = pLinetypeTable->getAt(pStr, id);
|
||
pLinetypeTable->close();
|
||
}
|
||
}
|
||
return id;
|
||
}
|
||
|
||
AcDbObjectId InitLineTypeTextStyle()
|
||
{
|
||
AcDbObjectId idRet = GetTextStyleId(g_csLineTypeStyle);
|
||
if (idRet == NULL) {
|
||
|
||
g_lstWinfont.Reset();
|
||
g_lstCharset.Reset();
|
||
g_lstPitch.Reset();
|
||
|
||
CDC *pDC = acedGetAcadDwgView()->GetDC();
|
||
ASSERT(pDC);
|
||
LOGFONT lf;
|
||
ZeroMemory(&lf, sizeof(lf));
|
||
lf.lfCharSet = DEFAULT_CHARSET;
|
||
EnumFontFamiliesEx(pDC->m_hDC, &lf,
|
||
(FONTENUMPROC)EnumFontFamExProc2, NULL, 0);
|
||
acedGetAcadDwgView()->ReleaseDC(pDC);
|
||
|
||
AcDbTextStyleTableRecord *pStyle = new AcDbTextStyleTableRecord;
|
||
pStyle->setName(g_csLineTypeStyle);
|
||
pStyle->setTextSize(g_dLineTypeHeight);
|
||
|
||
int idx = g_lstWinfont.Index(g_csLineTypeChnShx);
|
||
if (idx < 0) {
|
||
pStyle->setFileName(g_csLineTypeEngShx);
|
||
pStyle->setBigFontFileName(g_csLineTypeChnShx);
|
||
}
|
||
else {
|
||
int iCharset = *g_lstCharset[idx];
|
||
int iPitch = *g_lstPitch[idx];
|
||
#if ADS > 20
|
||
pStyle->setFont(g_csLineTypeChnShx, false, false, (Charset)iCharset, (Autodesk::AutoCAD::PAL::FontUtils::FontPitch)iPitch, Autodesk::AutoCAD::PAL::FontUtils::FontFamily::kDoNotCare);
|
||
#else
|
||
pStyle->setFont(g_csLineTypeChnShx, FALSE, FALSE, iCharset, iPitch);
|
||
#endif
|
||
// modify by cq 2017-01-05 支持CAD2017
|
||
}
|
||
pStyle->setXScale(g_dLineTypeScale);
|
||
idRet = AddTextStyle(pStyle, TRUE);
|
||
}
|
||
return idRet;
|
||
}
|
||
|
||
AcDbObjectId InitLineTypeTextStyle_Thunder()
|
||
{
|
||
AcDbObjectId idRet = GetTextStyleId(_T("TG_LINETYPE_THUND"));
|
||
if (idRet == NULL) {
|
||
|
||
g_lstWinfont.Reset();
|
||
g_lstCharset.Reset();
|
||
g_lstPitch.Reset();
|
||
|
||
CDC *pDC = acedGetAcadDwgView()->GetDC();
|
||
ASSERT(pDC);
|
||
LOGFONT lf;
|
||
ZeroMemory(&lf, sizeof(lf));
|
||
lf.lfCharSet = DEFAULT_CHARSET;
|
||
EnumFontFamiliesEx(pDC->m_hDC, &lf,
|
||
(FONTENUMPROC)EnumFontFamExProc2, NULL, 0);
|
||
acedGetAcadDwgView()->ReleaseDC(pDC);
|
||
|
||
AcDbTextStyleTableRecord *pStyle = new AcDbTextStyleTableRecord;
|
||
pStyle->setName(_T("TG_LINETYPE_THUND"));
|
||
pStyle->setTextSize(5.5);
|
||
|
||
int idx = g_lstWinfont.Index(g_csLineTypeChnShx);
|
||
if (idx < 0) {
|
||
pStyle->setFileName(g_csLineTypeEngShx);
|
||
pStyle->setBigFontFileName(g_csLineTypeChnShx);
|
||
}
|
||
else {
|
||
int iCharset = *g_lstCharset[idx];
|
||
int iPitch = *g_lstPitch[idx];
|
||
#if ADS > 20
|
||
pStyle->setFont(g_csLineTypeChnShx, false, false, (Charset)iCharset, (Autodesk::AutoCAD::PAL::FontUtils::FontPitch)iPitch, Autodesk::AutoCAD::PAL::FontUtils::FontFamily::kDoNotCare);
|
||
#else
|
||
pStyle->setFont(g_csLineTypeChnShx, FALSE, FALSE, iCharset, iPitch);
|
||
#endif
|
||
// modify by cq 2017-01-05 支持CAD2017
|
||
}
|
||
|
||
pStyle->setXScale(g_dLineTypeScale);
|
||
idRet = AddTextStyle(pStyle, TRUE);
|
||
}
|
||
return idRet;
|
||
}
|
||
|
||
void GetLineDashData(int i, CString csContent, double &dLen, CString &csText, CString &csStyle, double &dScale, double &dRotation, double &dX, double &dY)
|
||
{
|
||
int idx1 = csContent.Find(_T("["));
|
||
int idx(0);
|
||
CString csDesh;
|
||
while (idx1 > -1) {
|
||
int idx2 = csContent.Find(_T("]"), idx1);
|
||
if (idx2 < 0)
|
||
break;
|
||
CString csTmp;
|
||
csTmp = csContent.Mid(idx1 + 1, idx2 - idx1 - 1);
|
||
if (idx == i) {
|
||
csDesh = csTmp;
|
||
break;
|
||
}
|
||
idx++;
|
||
idx1 = csContent.Find(_T("["), idx2);
|
||
}
|
||
if (csDesh == _T(""))
|
||
return;
|
||
|
||
idx1 = csDesh.Find(_T(","));
|
||
CString csTmp = csDesh.Mid(0, idx1);
|
||
dLen = _tstof(csTmp);
|
||
int idx2 = csDesh.Find(_T(","), idx1 + 1);
|
||
idx = 1;
|
||
while (idx1 > -1) {
|
||
csTmp = csDesh.Mid(idx1 + 1, idx2 - idx1 - 1);
|
||
idx1 = idx2;
|
||
idx2 = csDesh.Find(_T(","), idx1 + 1);
|
||
if (idx == 1)
|
||
csText = csTmp;
|
||
else if (idx == 2)
|
||
csStyle = csTmp;
|
||
else if (idx == 3)
|
||
dScale = _tstof(csTmp);
|
||
else if (idx == 4)
|
||
dRotation = _tstof(csTmp);
|
||
else if (idx == 5)
|
||
dX = _tstof(csTmp);
|
||
else if (idx == 6)
|
||
dY = _tstof(csTmp);
|
||
idx++;
|
||
if (idx2 < 0)
|
||
break;
|
||
}
|
||
}
|
||
|
||
AcDbObjectId CreateShxStyle(CString csShxFile)
|
||
{
|
||
AcDbObjectId idRet = GetTextStyleId(csShxFile);
|
||
if (idRet == NULL) {
|
||
AcDbTextStyleTableRecord *pStyle = new AcDbTextStyleTableRecord;
|
||
pStyle->setName(csShxFile);
|
||
pStyle->setFileName(csShxFile);
|
||
pStyle->setIsShapeFile(TRUE);
|
||
idRet = AddTextStyle(pStyle, TRUE);
|
||
}
|
||
return idRet;
|
||
}
|
||
|
||
BOOL LoadLineType(CString csName, CString csComment, int num, bool fit, double dLength, CString csContent)
|
||
{
|
||
|
||
// AcDbObjectId idRet=InitLineTypeTextStyle();
|
||
if (csName.Find(_T("×")) > -1)
|
||
InitLineTypeTextStyle_Thunder();
|
||
else
|
||
InitLineTypeTextStyle();
|
||
|
||
AcDbLinetypeTable *pLinetypeTbl = NULL;
|
||
acdbCurDwg()->getLinetypeTable(pLinetypeTbl, AcDb::kForWrite);
|
||
if (pLinetypeTbl == NULL) {
|
||
return FALSE;
|
||
}
|
||
|
||
BOOL bHasIt = pLinetypeTbl->has((const TCHAR*)csName);
|
||
if (bHasIt) {
|
||
pLinetypeTbl->close();
|
||
adsout << _T("\n已经存在同名线型!");
|
||
return FALSE;
|
||
}
|
||
AcDbLinetypeTableRecord* newRec = new AcDbLinetypeTableRecord;
|
||
newRec->setName(csName);
|
||
const TCHAR* szName;
|
||
newRec->getName(szName);
|
||
if (_tcsicmp(szName, _T("")) == 0) {
|
||
pLinetypeTbl->close();
|
||
adsout << _T("\n线形名非法,建议使用全角!");
|
||
delete newRec;
|
||
return FALSE;
|
||
}
|
||
|
||
newRec->setAsciiDescription(csComment);
|
||
newRec->setComments(csComment);
|
||
|
||
newRec->setPatternLength(dLength);
|
||
newRec->setNumDashes(num);
|
||
newRec->setIsScaledToFit(fit);
|
||
for (int i = 0; i < num; i++) {
|
||
CString csText, csStyle;
|
||
double dLen, dScale, dRotaion(0), dX(0), dY(0);
|
||
GetLineDashData(i, csContent, dLen, csText, csStyle, dScale, dRotaion, dX, dY);
|
||
|
||
newRec->setDashLengthAt(i, dLen);
|
||
if (csText != _T("")) {// && fabs(dLen) > 0.0001 sr remove it 2007-3-22 TG_x 不支持
|
||
if (csStyle.Find(_T(".shx")) > 0)
|
||
{
|
||
//2008-11-18 支持形文件
|
||
AcDbObjectId idTextStyle = CreateShxStyle(csStyle);
|
||
newRec->setShapeStyleAt(i, idTextStyle);
|
||
int iShapeNum = _ttoi(csText);
|
||
newRec->setShapeNumberAt(i, iShapeNum);
|
||
newRec->setShapeScaleAt(i, dScale);
|
||
newRec->setShapeRotationAt(i, dRotaion);
|
||
AcGeVector2d vt(-dX, -dY);
|
||
newRec->setShapeOffsetAt(i, vt);
|
||
}
|
||
else
|
||
{
|
||
AcDbObjectId idTextStyle = GetTextStyleId(csStyle);
|
||
newRec->setShapeStyleAt(i, idTextStyle);
|
||
newRec->setTextAt(i, csText);
|
||
newRec->setShapeScaleAt(i, dScale);
|
||
newRec->setShapeRotationAt(i, dRotaion);
|
||
AcGeVector2d vt(-dX, -dY);
|
||
newRec->setShapeOffsetAt(i, vt);
|
||
}
|
||
}
|
||
}
|
||
|
||
pLinetypeTbl->add(newRec);
|
||
newRec->close();
|
||
pLinetypeTbl->close();
|
||
return TRUE;
|
||
}
|
||
|
||
void SetLayerLineType(const TCHAR* szLayer, const TCHAR* szLineType)
|
||
{
|
||
InitLayer(szLayer);
|
||
AcDbObjectId idLayer = GetLayerIdFromString(szLayer);
|
||
if (!idLayer)
|
||
return;
|
||
AcDbObjectId id = GetLinetypeIdFromString2(szLineType);
|
||
|
||
XString xsDbfFile;
|
||
if (!FindFile(_T("linetype.dbf"), xsDbfFile)) {
|
||
AfxMessageBox(_T("对不起,没有发现linetype.dbf文件!"));
|
||
return;
|
||
}
|
||
CodeBase db;
|
||
XDbfTable *pTable = db.Open(xsDbfFile);
|
||
if (!pTable) {
|
||
CString csTmp;
|
||
csTmp.Format(_T("%s文件只读或损坏!"), xsDbfFile);
|
||
AfxMessageBox(csTmp);
|
||
|
||
// AfxMessageBox(_T("TK文件只读或损坏!"));
|
||
return;
|
||
}
|
||
|
||
for (pTable->MoveFirst(); !pTable->IsEOF(); pTable->MoveNext()) {
|
||
CString sName, sComment, sContent, sNum, sFit, sLength;
|
||
GET_FIELD(pTable, _T("Name"), sName);
|
||
if (_tcsicmp(sName, szLineType) == 0) {
|
||
GET_FIELD(pTable, _T("Comment"), sComment);
|
||
GET_FIELD(pTable, _T("Num"), sNum);
|
||
GET_FIELD(pTable, _T("Scale"), sFit);
|
||
GET_FIELD(pTable, _T("Length"), sLength);
|
||
GET_FIELD(pTable, _T("Content"), sContent);
|
||
bool bFit;
|
||
if (sFit == _T("1"))
|
||
bFit = true;
|
||
else
|
||
bFit = false;
|
||
|
||
LoadLineType((const TCHAR*)sName, (const TCHAR*)sComment, _ttoi(sNum), bFit, _tstof(sLength), (const TCHAR*)sContent);
|
||
|
||
id = GetLinetypeIdFromString2((const TCHAR*)sName);
|
||
break;
|
||
}
|
||
|
||
}
|
||
if (id == NULL)
|
||
id = GetLinetypeIdFromString2(_T("CONTINUOUS"));
|
||
|
||
OPENOBJ_BEGIN(idLayer, AcDb::kForWrite, AcDbLayerTableRecord, pLayer);
|
||
if (pLayer) {
|
||
if (id != NULL)
|
||
pLayer->setLinetypeObjectId(id);
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
}
|
||
|
||
void UpdateElevationDim(PickSet &ssPipe)
|
||
{
|
||
RBList rbMark(RTDXF0, _T("ATS_ELEVATION"), NULL);
|
||
PickSet ssDim;
|
||
ssDim.Get(_T("X"), NULL, NULL, rbMark);
|
||
int nDimNum = ssDim.Length();
|
||
if (nDimNum == 0)
|
||
{
|
||
return;
|
||
}
|
||
|
||
std::vector<std::pair<Entity, XPoint> > vecDim;
|
||
for (long j = 0; j < nDimNum; ++j)
|
||
{
|
||
OPENOBJ_BEGIN(ssDim[j], AcDb::kForRead, TDbSymbElevation, pDim);
|
||
if (pDim != NULL)
|
||
{
|
||
vecDim.push_back(std::make_pair(ssDim[j], pDim->GetLocation()));
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
std::vector<std::pair<Entity, XPoint> >::iterator it, itEnd = vecDim.end();
|
||
long nLen = ssPipe.Length();
|
||
AcGePoint3d ptS, ptE, ptLoc;
|
||
AcGeTol tol;
|
||
tol.setEqualPoint(0.001);
|
||
double dMeter = 1;
|
||
if (!DocGetMeterUnitDraw())
|
||
{
|
||
tol.setEqualPoint(1);
|
||
dMeter = 0.001;
|
||
}
|
||
AcGeLine3d line1;
|
||
CString sText;
|
||
for (long i = 0; i < nLen; ++i)
|
||
{
|
||
OPENOBJ_BEGIN(ssPipe[i], AcDb::kForRead, TDbPipe, pPipe);
|
||
if (pPipe != NULL)
|
||
{
|
||
if (pPipe->IsVertical())
|
||
{
|
||
continue;
|
||
}
|
||
ptS = pPipe->StartPoint();
|
||
ptE = pPipe->EndPoint();
|
||
ptS.z = 0.0;
|
||
ptE.z = 0.0;
|
||
line1.set(ptS, ptE);
|
||
for (it = vecDim.begin(); it != itEnd; ++it)
|
||
{
|
||
ptLoc = it->second;
|
||
ptLoc.z = 0.0;
|
||
|
||
// 判断点是否在线上 zxl2013.10.15 modify
|
||
//if (!line1.isOn(ptLoc, tol))
|
||
AcGePointOnCurve3d ptOnCrv;
|
||
line1.getClosestPointTo(ptLoc, ptOnCrv, tol);
|
||
if (ptLoc.distanceTo(ptS) + ptLoc.distanceTo(ptE) - ptS.distanceTo(ptE) > 0.001)
|
||
{
|
||
continue;
|
||
}
|
||
|
||
double dDist = ptLoc.distanceTo(ptS);
|
||
double dLen = ptS.distanceTo(ptE);
|
||
double dEle = (pPipe->EndPoint().z - pPipe->StartPoint().z) * (dDist / dLen) + pPipe->StartPoint().z;
|
||
|
||
OPENOBJ_BEGIN(it->first, AcDb::kForWrite, TDbSymbElevation, pDim);
|
||
if (pDim != NULL)
|
||
{
|
||
sText.Format(_T("%.3f"), dEle * dMeter);
|
||
pDim->SetText(sText);
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
}
|
||
|
||
void UpdateElevationDim(Entity &entPipe)
|
||
{
|
||
PickSet ss(SS_FREE);
|
||
ss += entPipe;
|
||
UpdateElevationDim(ss);
|
||
}
|
||
|
||
void UpdateElevationDim(const AcDbObjectId &idPipe)
|
||
{
|
||
ads_name name;
|
||
acdbGetAdsName(name, idPipe);
|
||
Entity ent(name);
|
||
UpdateElevationDim(ent);
|
||
}
|
||
|
||
int GetLayerColorIdx(const TCHAR *szLayer)
|
||
{
|
||
XString fullFile;
|
||
if (FindFile(_T("layerdef.dat"), fullFile)) {
|
||
FILE *fp = fopen(_AS(fullFile), "r");
|
||
if (!fp)
|
||
return -1;
|
||
while (!feof(fp)) {
|
||
char sBuf[256] = "";
|
||
TCHAR cName[256] = _T(""), eName[256] = _T(""), sColor[256] = _T("");
|
||
fgets(sBuf, 255, fp);
|
||
if (sBuf[0]) {
|
||
CT_strnth(TString(sBuf), 1, cName);
|
||
CT_strnth(TString(sBuf), 2, eName);
|
||
CT_strnth(TString(sBuf), 3, sColor);
|
||
}
|
||
if (_tcscmp(szLayer, eName) == 0) {
|
||
fclose(fp);
|
||
int nColor = _ttoi(sColor);
|
||
return nColor;
|
||
}
|
||
}
|
||
fclose(fp);
|
||
}
|
||
return -1;
|
||
}
|
||
|
||
BOOL GetPipeMaterialList(XStringList &lstMat)
|
||
{
|
||
CodeBase db;
|
||
XString fullFile;
|
||
if (!FindFile(_T("pipe.dbf"), fullFile)) {
|
||
AfxMessageBox(_T("对不起,没有发现pipe.dbf文件!"));
|
||
return FALSE;
|
||
}
|
||
|
||
XDbfTable *pTable = db.Open(fullFile);
|
||
if (!pTable)
|
||
return FALSE;
|
||
CString csMaterial;
|
||
for (pTable->MoveFirst(); !pTable->IsEOF(); pTable->MoveNext()) {
|
||
GET_FIELD(pTable, _T("GC"), csMaterial);
|
||
if (csMaterial != _T("") && lstMat.Index(csMaterial) < 0)
|
||
lstMat.Append(tstrnew(csMaterial));
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
void GetPointList(XCurveSegment seg, int iNum, XPointList &lstPt, int mode)
|
||
{
|
||
double dDist2Wall(0);
|
||
if (mode == 0)
|
||
dDist2Wall = 0.5;
|
||
else if (mode == 1)
|
||
dDist2Wall = 0;
|
||
else if (mode == 2)
|
||
dDist2Wall = 0.25;
|
||
|
||
double dDistEven(0);
|
||
dDistEven = seg.GetLength() / (2 * dDist2Wall + iNum - 1);
|
||
AcGePoint3d ptTmp;
|
||
AcDbCurve *pCurve = seg.AsAcDbCurve();
|
||
if (seg.Is(CURVE_CIRCLE)) {
|
||
XCircle ar = seg.GetCircle();
|
||
pCurve = new AcDbCircle(ar.GetCenterPt(), AcGeVector3d(0, 0, 1), ar.GetRadius());
|
||
}
|
||
if (pCurve == NULL)
|
||
return;
|
||
int n = 0;
|
||
while (n < iNum) {
|
||
//mod liaoy 避免出现除以0的导致dDistEven无效
|
||
double dDist = 0;
|
||
if (mode == 1 && iNum == 1)
|
||
dDist = seg.GetLength() / 2;
|
||
else
|
||
dDist = dDist2Wall * dDistEven + n * dDistEven;
|
||
//double dDist = dDist2Wall*dDistEven+n*dDistEven;
|
||
//mod end
|
||
pCurve->getPointAtDist(dDist, ptTmp);
|
||
lstPt.NewAppend(ptTmp);
|
||
n++;
|
||
}
|
||
delete pCurve;
|
||
return;
|
||
}
|
||
|
||
void GetPointList(XCurveSegment seg, double dDist, XPointList &lstPt)
|
||
{
|
||
double dLen = seg.GetLength();
|
||
AcGePoint3d ptTmp;
|
||
AcDbCurve *pCurve = seg.AsAcDbCurve();
|
||
if (seg.Is(CURVE_CIRCLE)) {
|
||
XCircle ar = seg.GetCircle();
|
||
pCurve = new AcDbCircle(ar.GetCenterPt(), AcGeVector3d(0, 0, 1), ar.GetRadius());
|
||
}
|
||
if (pCurve == NULL)
|
||
return;
|
||
if (dDist < 0) {//反向
|
||
dDist = fabs(dDist);
|
||
double dAllDist = 1;
|
||
int n = 0;
|
||
while (dAllDist > 0) {
|
||
dAllDist = dLen - n * dDist;
|
||
pCurve->getPointAtDist(dAllDist, ptTmp);
|
||
lstPt.NewAppend(ptTmp);
|
||
n++;
|
||
}
|
||
}
|
||
else { //正向
|
||
double dAllDist = 0;
|
||
int n = 0;
|
||
while (dLen > dAllDist) {
|
||
dAllDist = n * dDist;
|
||
pCurve->getPointAtDist(dAllDist, ptTmp);
|
||
lstPt.NewAppend(ptTmp);
|
||
n++;
|
||
}
|
||
}
|
||
delete pCurve;
|
||
return;
|
||
}
|
||
|
||
CString GetPipeLayer(Entity entPipe)
|
||
{
|
||
CString csLay;
|
||
OPENOBJ_BEGIN(entPipe, AcDb::kForRead, TDbPipe, pPipe);
|
||
if (pPipe) {
|
||
csLay = pPipe->GetLayer();
|
||
}
|
||
OPENOBJ_END();
|
||
return csLay;
|
||
}
|
||
|
||
void DoDimPipeSerialNumber(SSearchPipeList *pListAll)
|
||
{
|
||
if (pListAll->m_iType == 0) {
|
||
CString csNum1 = pListAll->m_pPrevious->m_csName;
|
||
if (!pListAll->m_pPrevious->m_pPrevious && csNum1 == _T(""))
|
||
csNum1 = _T("末端");
|
||
int len2 = pListAll->m_lstNode.Length();
|
||
CString csNum2;
|
||
if (len2 > 0)
|
||
csNum2 = pListAll->m_lstNode[0]->m_csName;
|
||
if (csNum1 != _T("") && csNum2 != _T(""))
|
||
pListAll->m_csName = csNum2 + _T("-") + csNum1;
|
||
}
|
||
long len = pListAll->m_lstNode.Length();
|
||
for (long i = 0; i < len; i++) {
|
||
SSearchPipeList *pList = pListAll->m_lstNode[i];
|
||
DoDimPipeSerialNumber(pList);
|
||
}
|
||
}
|
||
|
||
CString GetBlkDesName(const TCHAR* szRecord, const TCHAR* szTKName)
|
||
{
|
||
CString csName;
|
||
CodeBase db;
|
||
db.read_only = 1;
|
||
XDbfTable *pTable = db.Open(szTKName);
|
||
if (!pTable) {
|
||
CString csTmp;
|
||
csTmp.Format(_T("%s无法打开!"), szTKName);
|
||
adsout << (const TCHAR *)csTmp;
|
||
// AfxMessageBox(_T("TK文件只读或损坏!"));
|
||
return CString();
|
||
}
|
||
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, szRecord) == 0) {
|
||
csName = (const TCHAR*)sItem;
|
||
return csName;
|
||
}
|
||
}
|
||
return CString();
|
||
}
|
||
|
||
AcDbObjectId InsertBlock(const TCHAR*szBlkName, AcGePoint3d pt, double XScale, double YScale, double Rotation, const TCHAR* szLayer)
|
||
{
|
||
AcDbObjectId retId;
|
||
CBlock blk(szBlkName, pt, XScale, Rotation, szLayer);
|
||
blk.Insert(TRUE);
|
||
Entity ent;
|
||
ent.GetLast();
|
||
acdbGetObjectId(retId, ent);
|
||
return retId;
|
||
}
|
||
|
||
BOOL InsertBlock(const TCHAR*szBlkName, XPoint pt, double nScale, double Rotation, const TCHAR* szLayer)
|
||
{
|
||
InitBlock(szBlkName);
|
||
AcDbBlockTable *pBlockTable;
|
||
AcDbBlockTableRecord* pRecord;
|
||
acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead);
|
||
if ((pBlockTable->getAt(szBlkName, pRecord, AcDb::kForRead)) != Acad::eOk)
|
||
return FALSE;
|
||
pBlockTable->close();
|
||
AcDbObjectId BlockId;
|
||
BlockId = pRecord->objectId();
|
||
pRecord->close();
|
||
AcDbBlockReference *pBlkRef = new AcDbBlockReference;
|
||
pBlkRef->setBlockTableRecord(BlockId);
|
||
pBlkRef->setRotation(Rotation);
|
||
pBlkRef->setPosition(AcGePoint3d(pt));
|
||
pBlkRef->setScaleFactors(nScale);
|
||
pBlkRef->setLayer(szLayer);
|
||
PostToDb(pBlkRef);
|
||
pBlkRef->close();
|
||
return TRUE;
|
||
}
|
||
|
||
BOOL IsPipeVertical(Entity ent)
|
||
{
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe);
|
||
if (pPipe)
|
||
return pPipe->IsVertical();
|
||
OPENOBJ_END();
|
||
return FALSE;
|
||
}
|
||
|
||
BOOL IsPtOnSegment(XPoint pt, XCurveSegment seg, double nSnap)
|
||
{
|
||
if (seg.Is(CURVE_LINE)) {
|
||
XLine line(1);
|
||
line = seg.GetLine();
|
||
return IsPtOnLine(pt, line, nSnap);
|
||
}
|
||
else if (seg.Is(CURVE_ARC)) {
|
||
XArc arc = seg.GetArc();
|
||
return IsPtOnArc(pt, arc, nSnap);
|
||
}
|
||
else if (seg.Is(CURVE_CIRCLE)) {
|
||
XCircle cir = seg.GetCircle();
|
||
return IsPtOnCircle(pt, cir, nSnap);
|
||
}
|
||
else
|
||
return FALSE;
|
||
}
|
||
|
||
BOOL IsPtOnLine(XPoint pt, XLine line, double nSnap)
|
||
{
|
||
ads_real l1, l2, l12;
|
||
double dd = pt.Distance(&line);
|
||
if (fabs(pt.Distance(&line)) > nSnap) return FALSE;
|
||
l1 = ads_distance(pt, line.StartPoint());
|
||
l2 = ads_distance(pt, line.EndPoint());
|
||
l12 = line.GetLength();
|
||
if (fabs(l1 + l2 - l12) <= nSnap) return TRUE;
|
||
return FALSE;
|
||
}
|
||
|
||
BOOL IsPtOnCircle(XPoint pt, XCircle circle, double nSnap)
|
||
{
|
||
double r = pt.Distance(circle.GetCenterPt()) - circle.GetRadius();
|
||
if (fabs(r) < nSnap)
|
||
return TRUE;
|
||
else
|
||
return FALSE;
|
||
}
|
||
|
||
BOOL IsPtOnArc(XPoint pt, XArc arc, double nSnap)
|
||
{
|
||
double ang = ads_angle(arc.GetCenterPt(), pt);
|
||
double rad = arc.GetRadius();
|
||
double ff = ads_distance(arc.GetCenterPt(), pt);
|
||
if (fabs(ads_distance(arc.GetCenterPt(), pt) - rad) > nSnap)
|
||
return FALSE;
|
||
if (arc.GetStarAngle() < arc.GetEndAngle()) {
|
||
if (ang > arc.GetStarAngle() && ang < arc.GetEndAngle()) return TRUE;
|
||
}
|
||
else {
|
||
if (ang > arc.GetStarAngle() || ang < arc.GetEndAngle()) return TRUE;
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
Acad::ErrorStatus PostToDb(AcDbEntity* ent, BOOL bClose)
|
||
{
|
||
Adesk::Boolean flag;
|
||
if (bClose)
|
||
flag = Adesk::kTrue;
|
||
else
|
||
flag = Adesk::kFalse;
|
||
AcDbObjectId objId = AddToCurrentSpace(ent, flag);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
void GetCurrentViewExtent(XPoint &ptMin, XPoint &ptMax)
|
||
{
|
||
struct resbuf rb = { NULL, RT3DPOINT, 0 };
|
||
acedGetVar(_T("VIEWCTR"), &rb);
|
||
AcGePoint3d ptView = asPnt3d(rb.resval.rpoint);
|
||
acedGetVar(_T("SCREENSIZE"), &rb);
|
||
AcGePoint3d ptSize = asPnt3d(rb.resval.rpoint);
|
||
double dXSize = ptSize.x;
|
||
double dYSize = ptSize.y;
|
||
dXSize = PixelToWcs(dXSize);
|
||
dYSize = PixelToWcs(dYSize);
|
||
ptMin.x = ptView.x - dXSize / 2;
|
||
ptMin.y = ptView.y - dYSize / 2;
|
||
ptMin.z = ptView.z;
|
||
ptMax.x = ptView.x + dXSize / 2;
|
||
ptMax.y = ptView.y + dYSize / 2;
|
||
ptMax.z = ptView.z;
|
||
}
|
||
|
||
void GetUcsExtent(const XPoint &ptLow, const XPoint &ptUp, XPoint &ptNewLow, XPoint &ptNewUp)
|
||
{
|
||
XPoint pt1; // wcs下外包框的左上点
|
||
XPoint pt2; // wcs下外包框的右下点
|
||
pt1.x = ptLow.x;
|
||
pt1.y = ptUp.y;
|
||
pt1.z = ptLow.z;
|
||
pt2.x = ptUp.x;
|
||
pt2.y = ptLow.y;
|
||
pt2.z = ptLow.z;
|
||
|
||
AcDbExtents ext;
|
||
ext.addPoint(Wcs2Ucs(pt1));
|
||
ext.addPoint(Wcs2Ucs(pt2));
|
||
ext.addPoint(Wcs2Ucs(ptLow));
|
||
ext.addPoint(Wcs2Ucs(ptUp));
|
||
ptNewLow = ext.minPoint();
|
||
ptNewUp = ext.maxPoint();
|
||
}
|
||
|
||
Acad::ErrorStatus AssureInCurrentView_New(const XPoint &ptLow, const XPoint &ptUp)
|
||
{
|
||
// 当前视口的左下角点右上角点
|
||
XPoint lowCorner, upCorner;
|
||
GetCurrentViewExtent(lowCorner, upCorner);
|
||
|
||
// 根据ptLow, ptUp获得ucs下外包框的左下角点和右上角点
|
||
XPoint ptUcsLow, ptUcsUp;
|
||
GetUcsExtent(ptLow, ptUp, ptUcsLow, ptUcsUp);
|
||
ptUcsLow.z = ptUcsUp.z = lowCorner.z;
|
||
|
||
// 求最大值点,最小值点
|
||
XPoint ptMin = Min(ptUcsLow, lowCorner);
|
||
XPoint ptMax = Max(ptUcsUp, upCorner);
|
||
|
||
if (ptMin != lowCorner || ptMax != upCorner) //点不在屏幕当前视图之内
|
||
{
|
||
//2004下UCS, AssureInCurrentView运行特别慢 2009-8-12 sr
|
||
BOOL bIsUcs = FALSE;
|
||
XPoint ptUcsLow = Wcs2Ucs(ptLow);
|
||
XPoint ptUcsUp = Wcs2Ucs(ptUp);
|
||
if (ptUcsLow != ptLow && ptUcsUp != ptUp)
|
||
bIsUcs = TRUE;
|
||
double dd = g_nAcadVer;
|
||
if (g_nAcadVer > 15.1 && g_nAcadVer < 16.01 && bIsUcs) // sr 2010-2-26 >15.0001 改为 >15.1 (ACAD2002是15.006)
|
||
SHads_command(RTSTR, _T("ZOOM"), RTSTR, _T("W"), RT3DPOINT, &ptUcsLow, RT3DPOINT, &ptUcsUp, RTNONE);
|
||
else
|
||
AssureInCurrentView(Ucs2Wcs(ptMin), Ucs2Wcs(ptMax));
|
||
}
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
double GetPipeDjByDn(const TCHAR* szMat, int iDnIn)
|
||
{
|
||
double nRet((double)iDnIn / 1000);
|
||
CodeBase db;
|
||
XString fullFile;
|
||
if (!FindFile(_T("pipe.dbf"), fullFile)) {
|
||
AfxMessageBox(_T("对不起,没有发现pipe.dbf文件!"));
|
||
return nRet;
|
||
}
|
||
XDbfTable *pTable = db.Open(fullFile);
|
||
if (!pTable)
|
||
return nRet;
|
||
CString sMaterial;
|
||
int iDn(0);
|
||
double nDj(0);
|
||
for (pTable->MoveFirst(); !pTable->IsEOF(); pTable->MoveNext()) {
|
||
GET_FIELD(pTable, _T("GC"), sMaterial);
|
||
GET_FIELD(pTable, _T("DN"), iDn);
|
||
GET_FIELD(pTable, _T("DJ"), nDj);
|
||
nDj = nDj / 1000;
|
||
if (_tcsicmp((const TCHAR*)sMaterial, szMat) == 0 && iDn == iDnIn)
|
||
return nDj;
|
||
}
|
||
return nRet;
|
||
}
|
||
|
||
double GetPipeOutDByDn(const TCHAR* szMat, int iDnIn)
|
||
{
|
||
double nRet((double)iDnIn / 1000);
|
||
CodeBase db;
|
||
XString fullFile;
|
||
if (!FindFile(_T("pipe.dbf"), fullFile)) {
|
||
AfxMessageBox(_T("对不起,没有发现pipe.dbf文件!"));
|
||
return nRet;
|
||
}
|
||
XDbfTable *pTable = db.Open(fullFile);
|
||
if (!pTable)
|
||
return nRet;
|
||
CString sMaterial;
|
||
int iDn(0);
|
||
double nDj(0);
|
||
for (pTable->MoveFirst(); !pTable->IsEOF(); pTable->MoveNext()) {
|
||
GET_FIELD(pTable, _T("GC"), sMaterial);
|
||
GET_FIELD(pTable, _T("DN"), iDn);
|
||
GET_FIELD(pTable, _T("D"), nDj);
|
||
nDj = nDj / 1000;
|
||
if (_tcsicmp((const TCHAR*)sMaterial, szMat) == 0 && iDn == iDnIn)
|
||
return nDj;
|
||
}
|
||
return nRet;
|
||
}
|
||
|
||
CString GetDimLayBySys(TPipeSys::SysType sys)
|
||
{
|
||
CString csRet;
|
||
if (sys == TPipeSys::kFeedWater || sys == TPipeSys::kFeedWater2 || sys == TPipeSys::kFeedWater3) // cet 2011.12.6 modify 增加中高区
|
||
csRet = LAY_DIM_FEED;
|
||
else if (sys == TPipeSys::kHeatFeedWater || sys == TPipeSys::kHeatFeedWater2 || sys == TPipeSys::kHeatFeedWater3) // cet 2011.12.6 modify 增加中高区
|
||
csRet = LAY_DIM_HEADFEED;
|
||
else if (sys == TPipeSys::kHeatBackWater || sys == TPipeSys::kHeatBackWater2 || sys == TPipeSys::kHeatBackWater3) // cet 2011.12.6 modify 增加中高区
|
||
csRet = LAY_DIM_HEADBACK;
|
||
else if (sys == TPipeSys::kDirtWater)
|
||
csRet = LAY_DIM_DIRT;
|
||
else if (sys == TPipeSys::kUselessWater)
|
||
csRet = LAY_DIM_USELESS;
|
||
else if (sys == TPipeSys::kRainWater)
|
||
csRet = LAY_DIM_RAIN;
|
||
else if (sys == TPipeSys::kUsedWater || sys == TPipeSys::kUsedWater2 || sys == TPipeSys::kUsedWater3) // cet 2011.12.6 modify 增加中高区
|
||
csRet = LAY_DIM_USED;
|
||
else if (sys == TPipeSys::kFireFighting || sys == TPipeSys::kFireFighting2 || sys == TPipeSys::kFireFighting3) // cet 2011.12.6 modify 增加中高区
|
||
csRet = LAY_DIM_HYDRANT;
|
||
else if (sys == TPipeSys::kSprinkle || sys == TPipeSys::kSprinkle2 || sys == TPipeSys::kSprinkle3) // cet 2011.12.6 modify 增加中高区
|
||
csRet = LAY_DIM_SPRINKLE;
|
||
else if (sys == TPipeSys::kCoagulate)
|
||
csRet = LAY_DIM_COAGULATE;
|
||
else if (sys == TPipeSys::kDrink)
|
||
csRet = LAY_DIM_DRINK;
|
||
else if (sys == TPipeSys::kPressDirt)
|
||
csRet = LAY_DIM_PRESSDIRT;
|
||
else if (sys == TPipeSys::kPressUseless)
|
||
csRet = LAY_DIM_PRESSUSELESS;
|
||
else if (sys == TPipeSys::kPressRain)
|
||
csRet = LAY_DIM_PRESSRAIN;
|
||
else if (sys == TPipeSys::kCivilFeed)
|
||
csRet = LAY_DIM_USER1;
|
||
else if (sys == TPipeSys::kCycleFeed)
|
||
csRet = LAY_DIM_USER2;
|
||
else if (sys == TPipeSys::kOther)
|
||
csRet = LAY_DIM_OTHER;
|
||
else if (sys == TPipeSys::kUser3) // cet 2011.12.1 add user3-user8
|
||
csRet = LAY_DIM_USER3;
|
||
else if (sys == TPipeSys::kUser4)
|
||
csRet = LAY_DIM_USER4;
|
||
else if (sys == TPipeSys::kUser5)
|
||
csRet = LAY_DIM_USER5;
|
||
else if (sys == TPipeSys::kUser6)
|
||
csRet = LAY_DIM_USER6;
|
||
else if (sys == TPipeSys::kUser7)
|
||
csRet = LAY_DIM_USER7;
|
||
else if (sys == TPipeSys::kUser8)
|
||
csRet = LAY_DIM_USER8;
|
||
|
||
return csRet;
|
||
}
|
||
|
||
BOOL GetNearestPoint(const AcGePoint3dArray &points, const XPoint &ptWcs, XPoint &ptNearest)
|
||
{
|
||
double nMinDist = 0.0;
|
||
int numPoints = points.length();
|
||
if (numPoints <= 0)
|
||
return FALSE;
|
||
|
||
for (int k = 0; k < numPoints; k++) {
|
||
XPoint ptCur = points[k];
|
||
ptCur.z = ptWcs.z;
|
||
double nDist = ptWcs.Distance(ptCur);
|
||
if (k > 0) {
|
||
if (nDist < nMinDist) {
|
||
nMinDist = nDist;
|
||
ptNearest = ptCur;
|
||
}
|
||
}
|
||
else {
|
||
nMinDist = nDist;
|
||
ptNearest = ptCur;
|
||
}
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
CString GetTextLayBySys(TPipeSys::SysType sys)
|
||
{
|
||
CString csRet;
|
||
if (sys == TPipeSys::kFeedWater || sys == TPipeSys::kFeedWater2 || sys == TPipeSys::kFeedWater3) // cet 2011.12.6 modify 增加中高区
|
||
csRet = LAY_TEXT_FEED;
|
||
else if (sys == TPipeSys::kHeatFeedWater || sys == TPipeSys::kHeatFeedWater2 || sys == TPipeSys::kHeatFeedWater3) // cet 2011.12.6 modify 增加中高区
|
||
csRet = LAY_TEXT_HEADFEED;
|
||
else if (sys == TPipeSys::kHeatBackWater || sys == TPipeSys::kHeatBackWater2 || sys == TPipeSys::kHeatBackWater3) // cet 2011.12.6 modify 增加中高区
|
||
csRet = LAY_TEXT_HEADBACK;
|
||
else if (sys == TPipeSys::kDirtWater)
|
||
csRet = LAY_TEXT_DIRT;
|
||
else if (sys == TPipeSys::kUselessWater)
|
||
csRet = LAY_TEXT_USELESS;
|
||
else if (sys == TPipeSys::kRainWater)
|
||
csRet = LAY_TEXT_RAIN;
|
||
else if (sys == TPipeSys::kUsedWater || sys == TPipeSys::kUsedWater2 || sys == TPipeSys::kUsedWater3) // cet 2011.12.6 modify 增加中高区
|
||
csRet = LAY_TEXT_USED;
|
||
else if (sys == TPipeSys::kFireFighting || sys == TPipeSys::kFireFighting2 || sys == TPipeSys::kFireFighting3) // cet 2011.12.6 modify 增加中高区
|
||
csRet = LAY_TEXT_FIRE;
|
||
else if (sys == TPipeSys::kSprinkle || sys == TPipeSys::kSprinkle2 || sys == TPipeSys::kSprinkle3) // cet 2011.12.6 modify 增加中高区
|
||
csRet = LAY_TEXT_SPRINKLE;
|
||
else if (sys == TPipeSys::kCoagulate)
|
||
csRet = LAY_TEXT_COAGULATE;
|
||
else if (sys == TPipeSys::kDrink)
|
||
csRet = LAY_TEXT_DRINK;
|
||
else if (sys == TPipeSys::kPressDirt)
|
||
csRet = LAY_TEXT_PRESSDIRT;
|
||
else if (sys == TPipeSys::kPressUseless)
|
||
csRet = LAY_TEXT_PRESSUSELESS;
|
||
else if (sys == TPipeSys::kPressRain)
|
||
csRet = LAY_TEXT_PRESSRAIN;
|
||
else if (sys == TPipeSys::kCivilFeed)
|
||
csRet = LAY_TEXT_USER1;
|
||
else if (sys == TPipeSys::kCycleFeed)
|
||
csRet = LAY_TEXT_USER2;
|
||
else if (sys == TPipeSys::kOther)
|
||
csRet = LAY_TEXT_OTHER;
|
||
else if (sys == TPipeSys::kUser3) // cet 2011.12.2 add user3-user8
|
||
csRet = LAY_TEXT_USER3;
|
||
else if (sys == TPipeSys::kUser4)
|
||
csRet = LAY_TEXT_USER4;
|
||
else if (sys == TPipeSys::kUser5)
|
||
csRet = LAY_TEXT_USER5;
|
||
else if (sys == TPipeSys::kUser6)
|
||
csRet = LAY_TEXT_USER6;
|
||
else if (sys == TPipeSys::kUser7)
|
||
csRet = LAY_TEXT_USER7;
|
||
else if (sys == TPipeSys::kUser8)
|
||
csRet = LAY_TEXT_USER8;
|
||
return csRet;
|
||
}
|
||
|
||
BOOL IsEquipment(AcDbObjectId id)
|
||
{
|
||
BOOL ret = FALSE;
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbEquipment, pEquip);
|
||
if(pEquip)
|
||
ret = TRUE;
|
||
OPENOBJ_END();
|
||
return ret;
|
||
}
|
||
|
||
BOOL GetEquipNameById(AcDbObjectId id, CString &csBlkName, CString &csDesName, int &iItem)
|
||
{
|
||
CString sDwbPath = g_sDwbPath;
|
||
csBlkName = _T("");
|
||
if (IsEquipment(id)) {
|
||
OPENOBJ_BEGIN(id, 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();
|
||
csBlkName = szBlkName;
|
||
// if(csBlkName.Find(_T("00000132")) > -1) //sr del 2012-9-19 不记得当初为什么加这个过滤
|
||
// return FALSE;
|
||
if (_tcsicmp(csBlkName, _T("$TwtSys$00000434")) == 0) { // 单消火栓 正方形单一比例
|
||
XString xsTmp7;
|
||
CString csDwb = sDwbPath + _T("Twtsys");
|
||
if (LoadDwbBlock(csDwb, _T("00000427"), xsTmp7) != RTNORM) //标准比例
|
||
return FALSE;
|
||
csBlkName = xsTmp7;
|
||
}
|
||
else if (_tcsicmp(csBlkName, _T("$TwtSys$00000435")) == 0) {// 双消火栓 正方形单一比例
|
||
XString xsTmp7;
|
||
CString csDwb = sDwbPath + _T("Twtsys");
|
||
if (LoadDwbBlock(csDwb, _T("00000421"), xsTmp7) != RTNORM) //标准比例
|
||
return FALSE;
|
||
csBlkName = xsTmp7;
|
||
}
|
||
|
||
CString csTKName, csRocord;
|
||
//以下图块显示系统图块
|
||
if (_tcsicmp(csBlkName, _T("$TwtSys$00000225")) == 0 || // 给水点
|
||
_tcsicmp(csBlkName, _T("$TwtSys$00000172")) == 0 || // 淋浴头
|
||
_tcsicmp(csBlkName, _T("$TwtSys$00000125")) == 0) // 喷淋头
|
||
{
|
||
csBlkName = pEquip->GetSysBlock();
|
||
XString xsTmp;
|
||
if (LoadDwbBlock(csBlkName, xsTmp) != RTNORM)
|
||
return TRUE;
|
||
csBlkName = xsTmp;
|
||
}
|
||
if (_tcsicmp(szBlkName, _T("$TwtSys$00000125")) == 0) {// 喷淋头
|
||
if (pEquip->IsHidePipe()) {
|
||
csDesName = _T("直立型喷头");
|
||
XString xsTmp;
|
||
if (LoadDwbBlock(_T("TwtSys(00000443)"), xsTmp) != RTNORM)
|
||
return TRUE;
|
||
csBlkName = xsTmp;
|
||
}
|
||
else
|
||
csDesName = _T("下垂型喷头");
|
||
iItem = 2;
|
||
return TRUE;
|
||
}
|
||
else if (_tcsicmp(szBlkName, _T("$TwtSys$00000128")) == 0) {
|
||
csDesName = _T("上下喷头");
|
||
XString xsTmp;
|
||
if (LoadDwbBlock(_T("TwtSys(00000444)"), xsTmp) != RTNORM)
|
||
return TRUE;
|
||
csBlkName = xsTmp;
|
||
iItem = 2;
|
||
return TRUE;
|
||
}
|
||
else if (_tcsicmp(szBlkName, _T("$TwtSys$00000529")) == 0) // cet 2014.9.17 add 水喷雾喷头
|
||
{
|
||
csDesName = _T("水喷雾喷头");
|
||
iItem = 2;
|
||
return TRUE;
|
||
}
|
||
else if (_tcsicmp(szBlkName, _T("$TwtSys$00000540")) == 0) // cet 2014.9.17 add 直立型水幕喷头
|
||
{
|
||
csDesName = _T("直立型水幕喷头");
|
||
iItem = 2;
|
||
return TRUE;
|
||
}
|
||
else if (_tcsicmp(szBlkName, _T("$TwtSys$00000541")) == 0) // cet 2014.9.17 add 下垂型水幕喷头
|
||
{
|
||
csDesName = _T("下垂型水幕喷头");
|
||
iItem = 2;
|
||
return TRUE;
|
||
}
|
||
else if (_tcsicmp(szBlkName, _T("$TwtSys$00000129")) == 0) // cet 2014.9.17 add 侧墙喷头
|
||
{
|
||
csDesName = _T("侧墙喷头");
|
||
iItem = 2;
|
||
return TRUE;
|
||
}
|
||
else if (_tcsicmp(szBlkName, _T("$TwtSys$00000131")) == 0) // cet 2014.9.17 add 侧喷喷头
|
||
{
|
||
csDesName = _T("侧喷喷头");
|
||
iItem = 2;
|
||
return TRUE;
|
||
}
|
||
if (csBlkName.Find(_T("$")) > -1) {
|
||
SplitBlkStr(csBlkName, csTKName, csRocord);
|
||
csTKName = sDwbPath + csTKName + _T(".tk");
|
||
csDesName = GetBlkDesName((const TCHAR*)csRocord, (const TCHAR*)csTKName);
|
||
}
|
||
//描述名中有(打断)或-000000283, 不需要给用户提供
|
||
int idx = csDesName.Find(_T("-"));
|
||
if (idx > 0) {
|
||
csDesName = csDesName.Left(idx);
|
||
}
|
||
int idx2 = csDesName.Find(_T("("));
|
||
if (idx2 > 0) {
|
||
csDesName = csDesName.Left(idx2);
|
||
}
|
||
iItem = 2;
|
||
if (csBlkName != _T(""))
|
||
return TRUE;
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
else {
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipeNode, pNode);
|
||
if (pNode) {
|
||
int num = pNode->GetInterfaceNum();
|
||
iItem = 3;
|
||
if (num == 1)
|
||
csDesName = _T("堵头");
|
||
else if (num == 2) {
|
||
TPipeInterface face1;
|
||
pNode->GetInterface(0, face1);
|
||
AcDbObjectId nextPipeId = face1.m_idPipe;
|
||
AcGeVector3d vt1, vt2;
|
||
OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, TDbPipe, pPipe);
|
||
if (pPipe) {
|
||
XPoint ptS = pPipe->StartPoint();
|
||
XPoint ptE = pPipe->EndPoint();
|
||
vt1 = AcGeVector3d(ptE.x - ptS.x, ptE.y - ptS.y, ptE.z - ptS.z);
|
||
|
||
}
|
||
OPENOBJ_END();
|
||
TPipeInterface face2;
|
||
pNode->GetInterface(1, face2);
|
||
nextPipeId = face2.m_idPipe;
|
||
OPENOBJ_BEGIN(nextPipeId, AcDb::kForRead, TDbPipe, pPipe);
|
||
if (pPipe) {
|
||
XPoint ptS = pPipe->StartPoint();
|
||
XPoint ptE = pPipe->EndPoint();
|
||
vt2 = AcGeVector3d(ptE.x - ptS.x, ptE.y - ptS.y, ptE.z - ptS.z);
|
||
}
|
||
OPENOBJ_END();
|
||
if (vt1.isParallelTo(vt2) == Adesk::kTrue)
|
||
csDesName = _T("变径");
|
||
else
|
||
csDesName = _T("弯头");
|
||
}
|
||
else if (num == 3)
|
||
csDesName = _T("三通");
|
||
else if (num == 4)
|
||
csDesName = _T("四通");
|
||
else
|
||
return FALSE;
|
||
return TRUE;
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
BOOL Is2LineOnLine(XLine line1, XLine line2)
|
||
{
|
||
XPoint ptStart, ptEnd;
|
||
ptStart = line1.StartPoint();
|
||
ptEnd = line1.EndPoint();
|
||
double len1 = fabs(ptStart.Distance(&line2));
|
||
double len2 = fabs(ptEnd.Distance(&line2));
|
||
if (fabs(ptStart.Distance(&line2)) < 2.0 && fabs(ptEnd.Distance(&line2)) < 2.0)
|
||
return TRUE;
|
||
else
|
||
return FALSE;
|
||
|
||
}
|
||
|
||
BOOL Is2ArcOnArc(XArc arc1, XArc arc2)
|
||
{
|
||
XPoint ptCen1, ptCen2;
|
||
ptCen1 = arc1.GetCenterPt();
|
||
ptCen2 = arc2.GetCenterPt();
|
||
double nRadius1, nRadius2;
|
||
nRadius1 = arc1.GetRadius();
|
||
nRadius2 = arc2.GetRadius();
|
||
if (ptCen1 == ptCen2 && (fabs(nRadius1 - nRadius2) < 0.1))
|
||
return TRUE;
|
||
else
|
||
return FALSE;
|
||
}
|
||
|
||
void GetWire2Point(Entity ent, XPoint &ptStart, XPoint &ptEnd)
|
||
{
|
||
if (ent.Is(_T("LINE"))) {
|
||
ent.GetData(10, ptStart);
|
||
ent.GetData(11, ptEnd);
|
||
}
|
||
else if (ent.Is(_T("ARC"))) {
|
||
XPoint ptCen;
|
||
double nRadius, rStart, rEnd;
|
||
ent.GetData(10, ptCen);
|
||
ent.GetData(40, &nRadius);
|
||
ent.GetData(50, &rStart);
|
||
ent.GetData(51, &rEnd);
|
||
ads_polar(ptCen, rStart, nRadius, ptStart);
|
||
ads_polar(ptCen, rEnd, nRadius, ptEnd);
|
||
}
|
||
else {
|
||
XPoly2D poly(ent);
|
||
ptStart = *poly[0];
|
||
int len = poly.Length();
|
||
ptEnd = *poly[len - 1];
|
||
}
|
||
return;
|
||
}
|
||
|
||
std::map<CString, BOOL> g_mapShowVPipeDimDn; // 立管标注样式4,立管是否显示管径
|
||
|
||
BOOL IsShowVPipeDimDn(const CString &sPipeLayer)
|
||
{
|
||
std::map<CString, BOOL>::iterator it;
|
||
it = g_mapShowVPipeDimDn.find(sPipeLayer);
|
||
if (it != g_mapShowVPipeDimDn.end())
|
||
{
|
||
return it->second;
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
BOOL SetShowVPipeDimDn(const CString &sPipeLayer, BOOL bShow)
|
||
{
|
||
std::map<CString, BOOL>::iterator it;
|
||
it = g_mapShowVPipeDimDn.find(sPipeLayer);
|
||
if (it != g_mapShowVPipeDimDn.end())
|
||
{
|
||
it->second = bShow;
|
||
return TRUE;
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
void CalcPipeLength(SSearchPipeList *pListAll)
|
||
{
|
||
if (pListAll->m_iType == 0) {
|
||
OPENOBJ_BEGIN(pListAll->m_ID, AcDb::kForRead, TDbPipe, pPipe);
|
||
if (pPipe) {
|
||
pListAll->m_nLength = pPipe->Length();
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
long len = pListAll->m_lstNode.Length();
|
||
for (long i = 0; i < len; i++) {
|
||
SSearchPipeList *pList = pListAll->m_lstNode[i];
|
||
CalcPipeLength(pList);
|
||
}
|
||
return;
|
||
}
|
||
|
||
void CalcPipeLength2(SSearchPipeList *pListAll, SSearchPipeList *pListFront)
|
||
{
|
||
if (pListAll->m_iType == 0) {
|
||
OPENOBJ_BEGIN(pListAll->m_ID, AcDb::kForRead, TDbPipe, pPipe);
|
||
if (pPipe) {
|
||
pListAll->m_nLength = pPipe->Length();
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
if (pListFront)
|
||
pListAll->m_nLength += pListFront->m_nLength;
|
||
long len = pListAll->m_lstNode.Length();
|
||
for (long i = 0; i < len; i++) {
|
||
SSearchPipeList *pList = pListAll->m_lstNode[i];
|
||
pList->m_pPrevious = pListAll;
|
||
CalcPipeLength2(pList, pListAll);
|
||
}
|
||
return;
|
||
}
|
||
|
||
void CreateToolbars() { }
|
||
|
||
void UpdatePipeTextDim(Entity ent, CString csDnType, int nPipeDn)
|
||
{
|
||
//更新管中文字标注
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe);
|
||
if (pPipe) {
|
||
DList<AcDbObjectId> lstAttachment;
|
||
pPipe->GetAttachments(lstAttachment);
|
||
int len = lstAttachment.Length();
|
||
CString csType = pPipe->GetLabel();
|
||
int iDn = (int)pPipe->GetDnDiameter();
|
||
XString xsDim1(_T("%s%d"), csType, iDn);
|
||
XString xsDim2(_T("%s%d"), csDnType, nPipeDn);
|
||
for (int m = 0; m < len; m++) {
|
||
AcDbObjectId id = *lstAttachment[m];
|
||
OPENOBJ_BEGIN(id, AcDb::kForWrite, TDbPipeText, pDim);
|
||
if (pDim) {
|
||
CString csText = pDim->GetText();
|
||
if (csText.Find((const TCHAR*)xsDim2) > -1)
|
||
pDim->SetText((const TCHAR*)xsDim1);
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
void GetFlangeDataByDn(int m_iPn, double m_dRetDn, double &m_nFlangeDn, double &m_nFlangeThick)
|
||
{
|
||
|
||
if(m_iPn == 0){ //0.25MPa
|
||
if(fabs(m_dRetDn - 50) < 0.01){
|
||
m_nFlangeDn = 140;
|
||
m_nFlangeThick = 12;
|
||
}
|
||
else if(fabs(m_dRetDn - 65) < 0.01){
|
||
m_nFlangeDn = 160;
|
||
m_nFlangeThick = 14;
|
||
}
|
||
else if(fabs(m_dRetDn - 80) < 0.01){
|
||
m_nFlangeDn = 190;
|
||
m_nFlangeThick = 14;
|
||
}
|
||
else if(fabs(m_dRetDn - 100) < 0.01){
|
||
m_nFlangeDn = 210;
|
||
m_nFlangeThick = 14;
|
||
}
|
||
else if(fabs(m_dRetDn - 125) < 0.01){
|
||
m_nFlangeDn = 240;
|
||
m_nFlangeThick = 14;
|
||
}
|
||
else if(fabs(m_dRetDn - 150) < 0.01){
|
||
m_nFlangeDn = 265;
|
||
m_nFlangeThick = 16;
|
||
}
|
||
else if(fabs(m_dRetDn - 200) < 0.01){
|
||
m_nFlangeDn = 320;
|
||
m_nFlangeThick = 18;
|
||
}
|
||
else if(fabs(m_dRetDn - 250) < 0.01){
|
||
m_nFlangeDn = 375;
|
||
m_nFlangeThick = 22;
|
||
}
|
||
else if(fabs(m_dRetDn - 300) < 0.01){
|
||
m_nFlangeDn = 440;
|
||
m_nFlangeThick = 22;
|
||
}
|
||
else if(fabs(m_dRetDn - 350) < 0.01){
|
||
m_nFlangeDn = 490;
|
||
m_nFlangeThick = 22;
|
||
}
|
||
else if(fabs(m_dRetDn - 400) < 0.01){
|
||
m_nFlangeDn = 540;
|
||
m_nFlangeThick = 22;
|
||
}
|
||
else if(fabs(m_dRetDn - 450) < 0.01){
|
||
m_nFlangeDn = 595;
|
||
m_nFlangeThick = 24;
|
||
}
|
||
else if(fabs(m_dRetDn - 500) < 0.01){
|
||
m_nFlangeDn = 645;
|
||
m_nFlangeThick = 24;
|
||
}
|
||
else if(fabs(m_dRetDn - 600) < 0.01){
|
||
m_nFlangeDn = 755;
|
||
m_nFlangeThick = 24;
|
||
}
|
||
else if(fabs(m_dRetDn - 700) < 0.01){
|
||
m_nFlangeDn = 860;
|
||
m_nFlangeThick = 26;
|
||
}
|
||
else if(fabs(m_dRetDn - 800) < 0.01){
|
||
m_nFlangeDn = 975;
|
||
m_nFlangeThick = 26;
|
||
}
|
||
else if(fabs(m_dRetDn - 900) < 0.01){
|
||
m_nFlangeDn = 1075;
|
||
m_nFlangeThick = 28;
|
||
}
|
||
else if(fabs(m_dRetDn - 1000) < 0.01){
|
||
m_nFlangeDn = 1175;
|
||
m_nFlangeThick = 30;
|
||
}
|
||
else if(fabs(m_dRetDn - 1200) < 0.01){
|
||
m_nFlangeDn = 1375;
|
||
m_nFlangeThick = 30;
|
||
}
|
||
else if(fabs(m_dRetDn - 1400) < 0.01){
|
||
m_nFlangeDn = 1575;
|
||
m_nFlangeThick = 32;
|
||
}
|
||
else if(fabs(m_dRetDn - 1600) < 0.01){
|
||
m_nFlangeDn = 1790;
|
||
m_nFlangeThick = 32;
|
||
}
|
||
else if(fabs(m_dRetDn - 1800) < 0.01){
|
||
m_nFlangeDn = 1990;
|
||
m_nFlangeThick = 34;
|
||
}
|
||
else if(fabs(m_dRetDn - 2000) < 0.01){
|
||
m_nFlangeDn = 2190;
|
||
m_nFlangeThick = 34;
|
||
}
|
||
}
|
||
else if(m_iPn == 1){//0.6MPa
|
||
if(fabs(m_dRetDn - 50) < 0.01){
|
||
m_nFlangeDn = 140;
|
||
m_nFlangeThick = 16;
|
||
}
|
||
else if(fabs(m_dRetDn - 65) < 0.01){
|
||
m_nFlangeDn = 160;
|
||
m_nFlangeThick = 16;
|
||
}
|
||
else if(fabs(m_dRetDn - 80) < 0.01){
|
||
m_nFlangeDn = 190;
|
||
m_nFlangeThick = 18;
|
||
}
|
||
else if(fabs(m_dRetDn - 100) < 0.01){
|
||
m_nFlangeDn = 210;
|
||
m_nFlangeThick = 18;
|
||
}
|
||
else if(fabs(m_dRetDn - 125) < 0.01){
|
||
m_nFlangeDn = 240;
|
||
m_nFlangeThick = 20;
|
||
}
|
||
else if(fabs(m_dRetDn - 150) < 0.01){
|
||
m_nFlangeDn = 265;
|
||
m_nFlangeThick = 20;
|
||
}
|
||
else if(fabs(m_dRetDn - 200) < 0.01){
|
||
m_nFlangeDn = 320;
|
||
m_nFlangeThick = 22;
|
||
}
|
||
else if(fabs(m_dRetDn - 250) < 0.01){
|
||
m_nFlangeDn = 375;
|
||
m_nFlangeThick = 24;
|
||
}
|
||
else if(fabs(m_dRetDn - 300) < 0.01){
|
||
m_nFlangeDn = 440;
|
||
m_nFlangeThick = 24;
|
||
}
|
||
else if(fabs(m_dRetDn - 350) < 0.01){
|
||
m_nFlangeDn = 490;
|
||
m_nFlangeThick = 26;
|
||
}
|
||
else if(fabs(m_dRetDn - 400) < 0.01){
|
||
m_nFlangeDn = 540;
|
||
m_nFlangeThick = 28;
|
||
}
|
||
else if(fabs(m_dRetDn - 450) < 0.01){
|
||
m_nFlangeDn = 595;
|
||
m_nFlangeThick = 28;
|
||
}
|
||
else if(fabs(m_dRetDn - 500) < 0.01){
|
||
m_nFlangeDn = 645;
|
||
m_nFlangeThick = 30;
|
||
}
|
||
else if(fabs(m_dRetDn - 600) < 0.01){
|
||
m_nFlangeDn = 755;
|
||
m_nFlangeThick = 30;
|
||
}
|
||
else if(fabs(m_dRetDn - 700) < 0.01){
|
||
m_nFlangeDn = 860;
|
||
m_nFlangeThick = 32;
|
||
}
|
||
else if(fabs(m_dRetDn - 800) < 0.01){
|
||
m_nFlangeDn = 975;
|
||
m_nFlangeThick = 32;
|
||
}
|
||
else if(fabs(m_dRetDn - 900) < 0.01){
|
||
m_nFlangeDn = 1075;
|
||
m_nFlangeThick = 34;
|
||
}
|
||
else if(fabs(m_dRetDn - 1000) < 0.01){
|
||
m_nFlangeDn = 1175;
|
||
m_nFlangeThick = 36;
|
||
}
|
||
else if(fabs(m_dRetDn - 1200) < 0.01){
|
||
m_nFlangeDn = 1405;
|
||
m_nFlangeThick = 38;
|
||
}
|
||
else if(fabs(m_dRetDn - 1400) < 0.01){
|
||
m_nFlangeDn = 1630;
|
||
m_nFlangeThick = 44;
|
||
}
|
||
else if(fabs(m_dRetDn - 1600) < 0.01){
|
||
m_nFlangeDn = 1830;
|
||
m_nFlangeThick = 46;
|
||
}
|
||
else if(fabs(m_dRetDn - 1800) < 0.01){
|
||
m_nFlangeDn = 2045;
|
||
m_nFlangeThick = 52;
|
||
}
|
||
else if(fabs(m_dRetDn - 2000) < 0.01){
|
||
m_nFlangeDn = 2265;
|
||
m_nFlangeThick = 54;
|
||
}
|
||
}
|
||
else if(m_iPn == 2){//1.0MPa
|
||
if(fabs(m_dRetDn - 50) < 0.01){
|
||
m_nFlangeDn = 165;
|
||
m_nFlangeThick = 18;
|
||
}
|
||
else if(fabs(m_dRetDn - 65) < 0.01){
|
||
m_nFlangeDn = 185;
|
||
m_nFlangeThick = 20;
|
||
}
|
||
else if(fabs(m_dRetDn - 80) < 0.01){
|
||
m_nFlangeDn = 200;
|
||
m_nFlangeThick = 20;
|
||
}
|
||
else if(fabs(m_dRetDn - 100) < 0.01){
|
||
m_nFlangeDn = 220;
|
||
m_nFlangeThick = 22;
|
||
}
|
||
else if(fabs(m_dRetDn - 125) < 0.01){
|
||
m_nFlangeDn = 250;
|
||
m_nFlangeThick = 24;
|
||
}
|
||
else if(fabs(m_dRetDn - 150) < 0.01){
|
||
m_nFlangeDn = 285;
|
||
m_nFlangeThick = 24;
|
||
}
|
||
else if(fabs(m_dRetDn - 200) < 0.01){
|
||
m_nFlangeDn = 340;
|
||
m_nFlangeThick = 24;
|
||
}
|
||
else if(fabs(m_dRetDn - 250) < 0.01){
|
||
m_nFlangeDn = 395;
|
||
m_nFlangeThick = 26;
|
||
}
|
||
else if(fabs(m_dRetDn - 300) < 0.01){
|
||
m_nFlangeDn = 445;
|
||
m_nFlangeThick = 28;
|
||
}
|
||
else if(fabs(m_dRetDn - 350) < 0.01){
|
||
m_nFlangeDn = 505;
|
||
m_nFlangeThick = 28;
|
||
}
|
||
else if(fabs(m_dRetDn - 400) < 0.01){
|
||
m_nFlangeDn = 565;
|
||
m_nFlangeThick = 30;
|
||
}
|
||
else if(fabs(m_dRetDn - 450) < 0.01){
|
||
m_nFlangeDn = 615;
|
||
m_nFlangeThick = 30;
|
||
}
|
||
else if(fabs(m_dRetDn - 500) < 0.01){
|
||
m_nFlangeDn = 670;
|
||
m_nFlangeThick = 32;
|
||
}
|
||
else if(fabs(m_dRetDn - 600) < 0.01){
|
||
m_nFlangeDn = 780;
|
||
m_nFlangeThick = 36;
|
||
}
|
||
else if(fabs(m_dRetDn - 700) < 0.01){
|
||
m_nFlangeDn = 895;
|
||
m_nFlangeThick = 36;
|
||
}
|
||
else if(fabs(m_dRetDn - 800) < 0.01){
|
||
m_nFlangeDn = 1015;
|
||
m_nFlangeThick = 38;
|
||
}
|
||
else if(fabs(m_dRetDn - 900) < 0.01){
|
||
m_nFlangeDn = 1115;
|
||
m_nFlangeThick = 42;
|
||
}
|
||
else if(fabs(m_dRetDn - 1000) < 0.01){
|
||
m_nFlangeDn = 1230;
|
||
m_nFlangeThick = 44;
|
||
}
|
||
else if(fabs(m_dRetDn - 1200) < 0.01){
|
||
m_nFlangeDn = 1455;
|
||
m_nFlangeThick = 48;
|
||
}
|
||
else if(fabs(m_dRetDn - 1400) < 0.01){
|
||
m_nFlangeDn = 1675;
|
||
m_nFlangeThick = 54;
|
||
}
|
||
else if(fabs(m_dRetDn - 1600) < 0.01){
|
||
m_nFlangeDn = 1915;
|
||
m_nFlangeThick = 62;
|
||
}
|
||
else if(fabs(m_dRetDn - 1800) < 0.01){
|
||
m_nFlangeDn = 2115;
|
||
m_nFlangeThick = 66;
|
||
}
|
||
else if(fabs(m_dRetDn - 2000) < 0.01){
|
||
m_nFlangeDn = 2325;
|
||
m_nFlangeThick = 72;
|
||
}
|
||
}
|
||
else if(m_iPn == 3){//1.6MPa
|
||
if(fabs(m_dRetDn - 50) < 0.01){
|
||
m_nFlangeDn = 165;
|
||
m_nFlangeThick = 22;
|
||
}
|
||
else if(fabs(m_dRetDn - 65) < 0.01){
|
||
m_nFlangeDn = 185;
|
||
m_nFlangeThick = 24;
|
||
}
|
||
else if(fabs(m_dRetDn - 80) < 0.01){
|
||
m_nFlangeDn = 200;
|
||
m_nFlangeThick = 24;
|
||
}
|
||
else if(fabs(m_dRetDn - 100) < 0.01){
|
||
m_nFlangeDn = 220;
|
||
m_nFlangeThick = 26;
|
||
}
|
||
else if(fabs(m_dRetDn - 125) < 0.01){
|
||
m_nFlangeDn = 250;
|
||
m_nFlangeThick = 28;
|
||
}
|
||
else if(fabs(m_dRetDn - 150) < 0.01){
|
||
m_nFlangeDn = 285;
|
||
m_nFlangeThick = 28;
|
||
}
|
||
else if(fabs(m_dRetDn - 200) < 0.01){
|
||
m_nFlangeDn = 340;
|
||
m_nFlangeThick = 30;
|
||
}
|
||
else if(fabs(m_dRetDn - 250) < 0.01){
|
||
m_nFlangeDn = 405;
|
||
m_nFlangeThick = 32;
|
||
}
|
||
else if(fabs(m_dRetDn - 300) < 0.01){
|
||
m_nFlangeDn = 460;
|
||
m_nFlangeThick = 32;
|
||
}
|
||
else if(fabs(m_dRetDn - 350) < 0.01){
|
||
m_nFlangeDn = 520;
|
||
m_nFlangeThick = 34;
|
||
}
|
||
else if(fabs(m_dRetDn - 400) < 0.01){
|
||
m_nFlangeDn = 580;
|
||
m_nFlangeThick = 38;
|
||
}
|
||
else if(fabs(m_dRetDn - 450) < 0.01){
|
||
m_nFlangeDn = 640;
|
||
m_nFlangeThick = 42;
|
||
}
|
||
else if(fabs(m_dRetDn - 500) < 0.01){
|
||
m_nFlangeDn = 715;
|
||
m_nFlangeThick = 48;
|
||
}
|
||
else if(fabs(m_dRetDn - 600) < 0.01){
|
||
m_nFlangeDn = 840;
|
||
m_nFlangeThick = 50;
|
||
}
|
||
////////////////// pn 1。6MPA 没有以下管径,数据按1.0
|
||
else if(fabs(m_dRetDn - 700) < 0.01){
|
||
m_nFlangeDn = 895;
|
||
m_nFlangeThick = 36;
|
||
}
|
||
else if(fabs(m_dRetDn - 800) < 0.01){
|
||
m_nFlangeDn = 1015;
|
||
m_nFlangeThick = 38;
|
||
}
|
||
else if(fabs(m_dRetDn - 900) < 0.01){
|
||
m_nFlangeDn = 1115;
|
||
m_nFlangeThick = 42;
|
||
}
|
||
else if(fabs(m_dRetDn - 1000) < 0.01){
|
||
m_nFlangeDn = 1230;
|
||
m_nFlangeThick = 44;
|
||
}
|
||
else if(fabs(m_dRetDn - 1200) < 0.01){
|
||
m_nFlangeDn = 1450;
|
||
m_nFlangeThick = 48;
|
||
}
|
||
else if(fabs(m_dRetDn - 1400) < 0.01){
|
||
m_nFlangeDn = 1675;
|
||
m_nFlangeThick = 54;
|
||
}
|
||
else if(fabs(m_dRetDn - 1600) < 0.01){
|
||
m_nFlangeDn = 1915;
|
||
m_nFlangeThick = 62;
|
||
}
|
||
else if(fabs(m_dRetDn - 1800) < 0.01){
|
||
m_nFlangeDn = 2115;
|
||
m_nFlangeThick = 66;
|
||
}
|
||
else if(fabs(m_dRetDn - 2000) < 0.01){
|
||
m_nFlangeDn = 2325;
|
||
m_nFlangeThick = 72;
|
||
}
|
||
}
|
||
}
|
||
|
||
void DoDimPipeDn(Entity ent, int iRadius, const TCHAR* szType, double nHeight, BOOL bIsDown, BOOL bModifyPos)
|
||
{
|
||
if (!ent.Is(_T("ATS_PIPE")) && !ent.Is(_T("ATS_DOUBLELINEPIPE")))
|
||
return;
|
||
|
||
CString csType = szType;
|
||
if (csType == _T("φ外径"))
|
||
csType = _T("%%c");
|
||
else if (csType == _T("外径壁厚"))
|
||
csType = _T("%%c");
|
||
else if (csType == _T("外径壁厚2")) //沈睿 2009-12-28添加 支持 中船动力专业的标注样式
|
||
{
|
||
TCHAR szLayer[256];
|
||
ent.GetData(8, szLayer);
|
||
int idx = GetPipeLayerIdxByName(szLayer);
|
||
CString csPipeLable = g_csPipeDim[idx];
|
||
csType = csPipeLable + _T(" %%c");
|
||
}
|
||
|
||
CString csPn = ReadXdata(ent, _T("TG-PIPE-FLANGE-PN"));
|
||
|
||
|
||
OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbDoubleLinePipe, pPipe);
|
||
if (pPipe && iRadius > 0) {
|
||
int iPn = 2;
|
||
if (csPn == _T("0.25MPa"))
|
||
iPn = 0;
|
||
else if (csPn == _T("0.6MPa"))
|
||
iPn = 1;
|
||
else if (csPn == _T("1.0MPa"))
|
||
iPn = 2;
|
||
else if (csPn == _T("1.6MPa"))
|
||
iPn = 3;
|
||
double dFlangeDn(0), dFlangeThick(0);
|
||
GetFlangeDataByDn(iPn, iRadius, dFlangeDn, dFlangeThick);
|
||
pPipe->SetWidth(iRadius);
|
||
pPipe->SetDnDiameter(iRadius);
|
||
pPipe->SetFlangeDn(dFlangeDn);
|
||
pPipe->SetFlangeThick(dFlangeThick);
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
CString csOldType;
|
||
int iDnOld;
|
||
double dPipeThick(0);
|
||
AcDbObjectId idTextStyle = InitTwtTextStyle(g_csPipeDnStyle);
|
||
double nDnDiameter = (double)iRadius;
|
||
OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbPipe, pPipe);
|
||
if (!pPipe)
|
||
return;
|
||
csOldType = pPipe->GetLabel();
|
||
iDnOld = (int)pPipe->GetDnDiameter();
|
||
if (csType.Find(_T("%%c")) > -1)
|
||
{ //用于设备给建筑提条件图,需要标注外径。不推荐用户使用,因为SetDnDiameter实体以为是DN
|
||
int iMaterial = pPipe->GetMaterial();
|
||
CString csMat = GetPipeMaterialByIdx(iMaterial);
|
||
if (iRadius == 0)
|
||
iRadius = (int)pPipe->GetDnDiameter();
|
||
|
||
double nDnOut = GetPipeOutDByDn(csMat, iRadius) * 1000;
|
||
double nDnIn = GetPipeDjByDn(csMat, iRadius) * 1000;
|
||
nDnDiameter = nDnOut;
|
||
dPipeThick = (nDnDiameter - nDnIn) / 2;
|
||
if (_tcsicmp(szType, _T("外径壁厚")) == 0 || _tcsicmp(szType, _T("外径壁厚2")) == 0)
|
||
pPipe->SetPipeThick(dPipeThick);
|
||
else
|
||
pPipe->SetPipeThick(0);
|
||
pPipe->SetDnDiameter(nDnDiameter);
|
||
}
|
||
if (pPipe->IsVertical()) { //立管不标注,但把管径信息写入管
|
||
if (iRadius > 0)
|
||
pPipe->SetDnDiameter(nDnDiameter);
|
||
return;
|
||
}
|
||
|
||
BOOL bIsDrawLable = pPipe->IsDrawLabel();
|
||
if (iRadius > 0)
|
||
pPipe->SetDnDiameter(nDnDiameter);
|
||
|
||
if (!bIsDrawLable || bModifyPos) {
|
||
if (bIsDown)
|
||
pPipe->InitLabelLocation(-g_nDnDimDist2Pipe * DocGetPScale());
|
||
else
|
||
pPipe->InitLabelLocation(g_nDnDimDist2Pipe * DocGetPScale());
|
||
if (nHeight < 2.99)
|
||
{
|
||
if ((DocGetMeterUnitDraw() && pPipe->Length() > 5) || (!DocGetMeterUnitDraw() && pPipe->Length() > DocGetPScale() / 200.0)) //太短,无法标注
|
||
pPipe->EnableDrawLabel(TRUE);
|
||
else
|
||
pPipe->EnableDrawLabel(FALSE);
|
||
}
|
||
else
|
||
{
|
||
if ((DocGetMeterUnitDraw() && pPipe->Length() > 8) || (!DocGetMeterUnitDraw() && pPipe->Length() > DocGetPScale() / 150.0)) //太短,无法标注
|
||
pPipe->EnableDrawLabel(TRUE);
|
||
else
|
||
pPipe->EnableDrawLabel(FALSE);
|
||
}
|
||
}
|
||
if (pPipe->GetSpare() < 0) //室外有时候不希望标注 2009-6-11
|
||
pPipe->EnableDrawLabel(FALSE);
|
||
|
||
|
||
pPipe->SetTextHeight(nHeight);
|
||
double dType = pPipe->GetSpare();
|
||
if (dType < 1)
|
||
pPipe->SetSpare(0);
|
||
if (_tcsicmp(szType, _T("自动")) == 0) {
|
||
int iMaterial = pPipe->GetMaterial();
|
||
CString csMat = GetPipeMaterialByIdx(iMaterial);
|
||
pPipe->SetLabel(GetDnByMat(csMat));
|
||
}
|
||
else
|
||
pPipe->SetLabel(csType);
|
||
pPipe->SetTextStyle(idTextStyle);
|
||
OPENOBJ_END();
|
||
UpdatePipeTextDim(ent, csOldType, iDnOld);
|
||
}
|
||
|
||
BOOL IsAppandEquip(DList<AcDbObjectId> &lstNode, AcDbObjectId id)
|
||
{
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbEquipment, pEquip);
|
||
if(!pEquip){
|
||
return FALSE;
|
||
}
|
||
OPENOBJ_END();
|
||
int len = lstNode.Length();
|
||
int Index = -1;
|
||
for(int j=0;j<len;j++){
|
||
AcDbObjectId idTmp = *lstNode[j];
|
||
if(idTmp == id) {
|
||
Index = j;
|
||
break;
|
||
}
|
||
}
|
||
if(Index < 0){
|
||
lstNode.Append(new AcDbObjectId(id));
|
||
return TRUE;
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
BOOL IsWell(AcDbObjectId id)
|
||
{
|
||
CString csDesName, csBlkName;
|
||
int iItem;
|
||
GetEquipNameById(id, csBlkName, csDesName, iItem);
|
||
if(csDesName.Find(_T("井")) < 0)
|
||
return FALSE;
|
||
AcDbObjectId idBlk = NULL;
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbWell, pEquip);
|
||
if(pEquip){
|
||
CString csName = pEquip->GetWellName();
|
||
if(csName != _T(""))
|
||
return TRUE;
|
||
}
|
||
OPENOBJ_END();
|
||
return FALSE;
|
||
}
|
||
|
||
BOOL DoDimSerialNumber(AcDbObjectId id, int idx)
|
||
{
|
||
InitLayer(LAY_CALC_TEXT);
|
||
InitTwtTextStyle(g_csTwtDimStyle);
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipeNode, pNode);
|
||
if(pNode){
|
||
CString csText;
|
||
csText.Format(_T("%d"), idx);
|
||
XPoint pt = pNode->GetLocation();
|
||
XPoint ptText;
|
||
double nDist = DocGetPScale();
|
||
if(IsWell(id))
|
||
nDist = nDist * g_nWellRadius / 2; //如果标注井,距离就大些
|
||
ads_polar(pt, PI/2, nDist, ptText);
|
||
ads_polar(ptText, 0, nDist, ptText);
|
||
XText text(csText, ptText, g_nTwtDimHeight * DocGetPScale(), g_nDimScale, g_csTwtDimStyle, LAY_CALC_TEXT);
|
||
text.Draw();
|
||
return TRUE;
|
||
}
|
||
OPENOBJ_END();
|
||
return FALSE;
|
||
}
|
||
|
||
int DoSerialNumber2(SSearchPipeList *pListLast, int idx)
|
||
{
|
||
|
||
AcDbObjectId id = NULL;
|
||
id = pListLast->m_ID;
|
||
if (pListLast->m_iType == 2 || pListLast->m_iType == 1 || pListLast->m_iType == -1) {
|
||
if (pListLast->m_csName != _T(""))
|
||
return idx;
|
||
pListLast->m_csName.Format(_T("%d"), idx);
|
||
|
||
if (DoDimSerialNumber(id, idx))
|
||
idx++;
|
||
else
|
||
return idx;
|
||
}
|
||
if (pListLast->m_pPrevious)
|
||
idx = DoSerialNumber2(pListLast->m_pPrevious, idx);
|
||
return idx;
|
||
}
|
||
|
||
int GetAncestorSerial(SSearchPipeList *pListLast)
|
||
{
|
||
int idx(0);
|
||
if(pListLast->m_iType == 2 || pListLast->m_iType == 1){ //1:节点 2:喷头
|
||
if(pListLast->m_csName != _T("")){
|
||
idx = _ttoi(pListLast->m_csName);
|
||
return idx;
|
||
}
|
||
}
|
||
if(pListLast->m_pPrevious)
|
||
idx = GetAncestorSerial(pListLast->m_pPrevious);
|
||
return idx;
|
||
}
|
||
|
||
int GetFirstAncestorSerial(SSearchPipeList *pListLast)
|
||
{
|
||
int idx(0);
|
||
if(pListLast->m_iType == 2 || pListLast->m_iType == 1){ //1:节点 2:喷头
|
||
if(pListLast->m_csName != _T("")){
|
||
idx = _ttoi(pListLast->m_csName);
|
||
if(pListLast->m_nDang == 255)
|
||
return idx;
|
||
}
|
||
}
|
||
if(pListLast->m_pPrevious)
|
||
idx = GetFirstAncestorSerial(pListLast->m_pPrevious);
|
||
return idx;
|
||
}
|
||
|
||
SSearchPipeList *GetNextDimNode2(SSearchPipeList *pListAll, SSearchPipeList *pDisadvantage)
|
||
{
|
||
AcDbObjectId id = NULL;
|
||
id = pListAll->m_ID;
|
||
double nCurPipeLength(0);
|
||
nCurPipeLength = pListAll->m_nLength;
|
||
|
||
if (pListAll->m_csName == _T("") && pListAll->m_iType != 0) {
|
||
int idx = GetFirstAncestorSerial(pListAll);
|
||
if (pDisadvantage) {
|
||
int idx2 = GetFirstAncestorSerial(pDisadvantage);
|
||
if (idx < idx2) { //条件1: 当前节点的祖先编号小于临时节点的祖先编号
|
||
pDisadvantage = pListAll;
|
||
}
|
||
else if (idx == 0) { //条件2:
|
||
if (pDisadvantage && nCurPipeLength > pDisadvantage->m_nLength)
|
||
pDisadvantage = pListAll;
|
||
}
|
||
else if (idx == idx2) {//条件3: 当前节点的祖先编号等于临时节点的祖先编号, 但离起始节点最远
|
||
int iParentIdx1 = GetAncestorSerial(pListAll);
|
||
int iParentIdx2 = GetAncestorSerial(pDisadvantage);
|
||
if (iParentIdx1 == iParentIdx2) {
|
||
if (pDisadvantage && nCurPipeLength > pDisadvantage->m_nLength)
|
||
pDisadvantage = pListAll;
|
||
}
|
||
else if (iParentIdx1 < iParentIdx2 || iParentIdx2 == idx2) {
|
||
pDisadvantage = pListAll;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
pDisadvantage = pListAll; //条件3: 临时节点为空
|
||
}
|
||
|
||
|
||
int len = pListAll->m_lstNode.Length();
|
||
for (long i = 0; i < len; i++) {
|
||
SSearchPipeList *pList = pListAll->m_lstNode[i];
|
||
pDisadvantage = GetNextDimNode2(pList, pDisadvantage);
|
||
}
|
||
return pDisadvantage;
|
||
}
|
||
|
||
void RebindVPipeDim(const AcDbObjectId id)
|
||
{
|
||
AcGePoint3d ptS, ptE;
|
||
AcDbEntity *pEnt = NULL;
|
||
if (acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead) == Acad::eOk)
|
||
{
|
||
TDbVPipeDim *pDim = TDbVPipeDim::cast(pEnt);
|
||
if (pDim != NULL)
|
||
{
|
||
ptS = pDim->GetStartPt();
|
||
ptE = pDim->GetTurnPt();
|
||
}
|
||
pEnt->close();
|
||
}
|
||
|
||
RBList rbMak(RTDXF0, _T("ATS_PIPE"), NULL);
|
||
PickSet ssSel(SS_FREE);
|
||
AcGeVector3d vtDir = AcGeVector3d::kXAxis;
|
||
vtDir.rotateBy(PI / 4, AcGeVector3d::kZAxis);
|
||
XPoint ptET = ptS + vtDir * 3.0 * DocGetPScale();
|
||
XPoint ptSTmp = ptS - vtDir * 3.0 * DocGetPScale();
|
||
// struct resbuf *pointlist = ads_buildlist(RTPOINT, &ptSTmp, RTPOINT, &ptET, NULL);
|
||
ssSel.Get(_T("C"), Wcs2Ucs(ptSTmp), Wcs2Ucs(ptET), rbMak);
|
||
// ads_relrb(pointlist);
|
||
|
||
AcGePoint3d ptST;
|
||
AcDbObjectId idVPipe;
|
||
for (long i = 0; i < ssSel.Length(); ++i)
|
||
{
|
||
OPENOBJ_BEGIN(ssSel[i], AcDb::kForRead, TDbPipe, pPipe);
|
||
if (pPipe && pPipe->IsVertical())
|
||
{
|
||
pPipe->getStartPoint(ptST);
|
||
ptST.z = 0.0;
|
||
ptS.z = 0.0;
|
||
if (ptST.distanceTo(ptS) < 1e-3)
|
||
{
|
||
idVPipe = pPipe->objectId();
|
||
break;
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
if (acdbOpenAcDbEntity(pEnt, id, AcDb::kForWrite) == Acad::eOk)
|
||
{
|
||
TDbVPipeDim *pDim = TDbVPipeDim::cast(pEnt);
|
||
if (pDim != NULL)
|
||
{
|
||
if (!idVPipe.isNull())
|
||
{
|
||
pDim->SetVPipeId(idVPipe);
|
||
}
|
||
else
|
||
{
|
||
pDim->SetVPipeId(idVPipe);
|
||
}
|
||
}
|
||
pEnt->close();
|
||
}
|
||
}
|
||
|
||
CString GetPipeTextLayByEnt(Entity ent)
|
||
{
|
||
CString csLay;
|
||
TPipeSys::SysType sysType;
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe);
|
||
if (pPipe) {
|
||
sysType = pPipe->GetSysType();
|
||
}
|
||
OPENOBJ_END();
|
||
csLay = GetTextLayBySys(sysType);
|
||
return csLay;
|
||
}
|
||
|
||
Entity GetEquipmentByPt(XPoint &pt, int nSnap, const TCHAR* szLayer)
|
||
{
|
||
RBList rbMaskPipe(RTDXF0, _T("ATS_EQUIPMENT"), 8, szLayer, NULL);
|
||
PickSet ss(SS_FREE);
|
||
XPoint ptUcs = Wcs2Ucs(pt);
|
||
GetPointPickSet(ptUcs, ss, rbMaskPipe, nSnap);
|
||
long len = ss.Length();
|
||
if (ss.Length() != 1)
|
||
return Entity();
|
||
Entity entPipe = ss[0L];
|
||
BOOL bFlag = FALSE;
|
||
OPENOBJ_BEGIN(entPipe, AcDb::kForRead, TDbEquipment, pEquip);
|
||
if (pEquip)
|
||
pt = pEquip->GetLocation();
|
||
OPENOBJ_END();
|
||
return entPipe;
|
||
}
|
||
|
||
Entity GetPipeByPt(XPoint pt, double &nElevation, int &iPipeSys)
|
||
{
|
||
RBList rbMaskPipe(RTDXF0, _T("ATS_PIPE"),/* 8, GetLayerNames(_T("管线")),*/ NULL);
|
||
PickSet ss(SS_FREE);
|
||
XPoint ptUcs = Wcs2Ucs(pt);
|
||
GetPointPickSet(ptUcs, ss, rbMaskPipe, (int)(DocGetPScale() / 2));
|
||
double len = ss.Length();
|
||
if (len == 0)
|
||
return Entity();
|
||
else if (len > 1) {
|
||
GetPointPickSet(ptUcs, ss, rbMaskPipe, (int)(DocGetPScale() / 4));
|
||
}
|
||
if (ss.Length() != 1)
|
||
return Entity();
|
||
Entity entPipe = ss[0L];
|
||
OPENOBJ_BEGIN(entPipe, AcDb::kForRead, TDbPipe, pPipe);
|
||
if (pPipe && !pPipe->IsVertical()) {
|
||
nElevation = pPipe->StartPoint().z;
|
||
TPipeSys::SysType sys = pPipe->GetSysType();
|
||
CString csLay = pPipe->GetLayer();
|
||
iPipeSys = GetPipeLayerIdxByName(csLay);
|
||
}
|
||
else
|
||
return Entity();
|
||
OPENOBJ_END();
|
||
|
||
return ss[0L];
|
||
}
|
||
|
||
Entity GetWellByPt(XPoint &pt, int &iPipeIdx)
|
||
{
|
||
RBList rbMaskPipe(RTDXF0, _T("ATS_WELL"), NULL);
|
||
PickSet ss(SS_FREE);
|
||
XPoint ptUcs = Wcs2Ucs(pt);
|
||
|
||
// 设置外包框大小
|
||
int nLen = int(g_nWellRadius * DocGetPScale() / 2);
|
||
if (nLen == 0)
|
||
{
|
||
nLen = 1;
|
||
}
|
||
|
||
GetPointPickSet(ptUcs, ss, rbMaskPipe, nLen);
|
||
|
||
// 过滤多余#
|
||
PickSet ssDel(SS_FREE);
|
||
for (long i = 0; i < ss.Length(); i++)
|
||
{
|
||
Entity ent = ss[i];
|
||
XPoint pt1;
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbWell, pEquip);
|
||
if (pEquip)
|
||
{
|
||
pt1 = pEquip->GetLocation();
|
||
if (pt1.Distance2d(pt) > 1e-3)
|
||
{
|
||
ssDel += ent;
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
ss -= ssDel;
|
||
|
||
if (ss.Length() != 1)
|
||
return Entity();
|
||
|
||
Entity entPipe = ss[0L];
|
||
TCHAR szLay[256];
|
||
entPipe.GetData(8, szLay);
|
||
if (_tcsicmp(szLay, LAY_WELL_RAIN) == 0)
|
||
iPipeIdx = 5;
|
||
else if (_tcsicmp(szLay, LAY_WELL_DIRT) == 0)
|
||
iPipeIdx = 3;
|
||
else if (_tcsicmp(szLay, LAY_WELL_FEED) == 0)
|
||
iPipeIdx = 0;
|
||
else if (_tcsicmp(szLay, LAY_WELL_FIRE) == 0)
|
||
iPipeIdx = 7;
|
||
else if (_tcsicmp(szLay, LAY_WELL_USED) == 0)
|
||
iPipeIdx = 6;
|
||
else if (_tcsicmp(szLay, LAY_WELL_OTHER) == 0)
|
||
iPipeIdx = 14;
|
||
else if (_tcsicmp(szLay, LAY_WELL_USELESS) == 0)
|
||
iPipeIdx = 4;
|
||
BOOL bFlag = FALSE;
|
||
double nRadius(0);
|
||
XPoint ptLoc;
|
||
OPENOBJ_BEGIN(entPipe, AcDb::kForRead, TDbWell, pEquip);
|
||
if (pEquip) {
|
||
ptLoc = pEquip->GetLocation();
|
||
nRadius = pEquip->GetScale() * pEquip->GetPScale();
|
||
if (fabs(ptLoc.z) > 0.001) {
|
||
ptLoc.z = 0;
|
||
if (pEquip->upgradeOpen() == Acad::eOk) {
|
||
pEquip->SetLocation(ptLoc);
|
||
pEquip->downgradeOpen();
|
||
}
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
pt.z = 0;
|
||
double nDist = fabs(ads_distance(pt, ptLoc));
|
||
if (nDist < nRadius)
|
||
pt = ptLoc;
|
||
else
|
||
return Entity();
|
||
return entPipe;
|
||
}
|
||
|
||
XCurveSegment GetSegByPt(XPoly2D poly, XPoint pt, double &dAngle)
|
||
{
|
||
XCurveSegment seg;
|
||
int m = poly.HitTestOnCurve(pt);
|
||
if (m > 0)
|
||
m = m - 2;
|
||
else if (m < 0)
|
||
m = abs(m) - 1;
|
||
else if (m == 0)
|
||
return XCurveSegment();
|
||
if (m < 0)
|
||
m = 0;
|
||
poly.Nth(m, seg);
|
||
|
||
if (seg.Is(CURVE_LINE))
|
||
dAngle = seg.GetLine().Direction();
|
||
else if (seg.Is(CURVE_ARC)) {
|
||
XPoint ptCenter;
|
||
seg.GetArc().Center(ptCenter);
|
||
dAngle = ads_angle(ptCenter, pt) + PI / 2;
|
||
}
|
||
|
||
return seg;
|
||
}
|
||
|
||
TDbPipe * ClonePipe(TDbPipe *pOldPipe)
|
||
{
|
||
TDbPipe *pNewPipe = (TDbPipe *)pOldPipe->clone();
|
||
DList<AcDbObjectId> lstAttachment;
|
||
pNewPipe->GetAttachments(lstAttachment);
|
||
for (int n = 0; n < lstAttachment.Length(); n++) {
|
||
AcDbObjectId idTmp = *lstAttachment[n];
|
||
pNewPipe->RemoveAttachment(idTmp);
|
||
}
|
||
return pNewPipe;
|
||
}
|
||
|
||
typedef struct PtOnCrItem
|
||
{
|
||
AcGePoint3d m_ptGeOld;
|
||
AcGePoint3d m_ptGeOn;
|
||
AcDbCurve * m_pCurve;
|
||
AcDbObjectId m_ID;
|
||
} PTONCRITEM, * PPTONCRITEM;
|
||
|
||
static bool GreaterCoord(PTONCRITEM item1, PTONCRITEM item2)
|
||
{
|
||
AcDbCurve * pCurve = item1.m_pCurve;
|
||
AcGePoint3d ptGe1 = item1.m_ptGeOn;
|
||
AcGePoint3d ptGe2 = item2.m_ptGeOn;
|
||
|
||
double dDis1 = 0.0, dDis2 = 0.0;
|
||
pCurve->getParamAtPoint(ptGe1, dDis1);
|
||
pCurve->getParamAtPoint(ptGe2, dDis2);
|
||
|
||
if (dDis1 - dDis2 > 0.000001)
|
||
{
|
||
return false;//up sort
|
||
}
|
||
return true;//down sort
|
||
}
|
||
|
||
void SortPoints(AcGePoint3dArray& points, AcDbCurve * pCurve, BOOL bModifyArray)
|
||
{
|
||
PTONCRITEM ptOnCrItem;
|
||
typedef std::vector<PTONCRITEM> PtOnCrItemVector;
|
||
|
||
// PtOnCrItemVector::_Tptr p_ptr = (PTONCRITEM *)0;
|
||
// PtOnCrItemVector::_Ctptr p_cptr = (const PTONCRITEM *)0;
|
||
PtOnCrItemVector::reference p_ref = ptOnCrItem;
|
||
PtOnCrItemVector::const_reference p_cref = (const PTONCRITEM&)ptOnCrItem;
|
||
PtOnCrItemVector::value_type * p_val = (PTONCRITEM *)0;
|
||
PtOnCrItemVector::size_type * p_size = (size_t *)0;
|
||
PtOnCrItemVector::difference_type * p_diff = (ptrdiff_t *)0;
|
||
|
||
PtOnCrItemVector vectorItems;
|
||
ptOnCrItem.m_pCurve = pCurve;
|
||
|
||
AcGePoint3d ptGeT;
|
||
int nLength = points.length();
|
||
for (int i = 0; i < nLength; i++)
|
||
{
|
||
ptGeT = points.at(i);
|
||
ptOnCrItem.m_ptGeOld = ptGeT;
|
||
pCurve->getClosestPointTo(ptGeT, ptGeT);
|
||
ptOnCrItem.m_ptGeOn = ptGeT;
|
||
vectorItems.push_back(ptOnCrItem);
|
||
}
|
||
|
||
PtOnCrItemVector::iterator itHead = vectorItems.begin();
|
||
PtOnCrItemVector::iterator itTail = vectorItems.end();
|
||
std::sort(itHead, itTail, GreaterCoord);
|
||
|
||
itHead = vectorItems.begin();
|
||
itTail = vectorItems.end();
|
||
|
||
points.removeSubArray(0, nLength - 1);
|
||
AcGePoint3d ptGe;
|
||
|
||
for (; itHead != itTail; ++itHead)
|
||
{
|
||
if (bModifyArray)
|
||
ptGe = (*itHead).m_ptGeOn;
|
||
else
|
||
ptGe = (*itHead).m_ptGeOld;
|
||
points.append(ptGe);
|
||
}
|
||
}
|
||
|
||
void SetLayerEngName(const TCHAR *szChnLayer, const TCHAR *szEngLayer) //2011-10-17 bsl
|
||
{
|
||
DList<CLayerData> lstLayer;
|
||
XString fullFile;
|
||
if (FindFile(_T("layerdef.dat"), fullFile)) {
|
||
FILE *fp = fopen(_AS(fullFile), "r");
|
||
if (!fp)
|
||
return;
|
||
while (!feof(fp)) {
|
||
char sBuf[256] = "";
|
||
TCHAR cName[256] = _T(""), eName[256] = _T(""), sColor[256] = _T(""), sLineType[256] = _T(""), sDes[256] = _T("");
|
||
|
||
fgets(sBuf, 255, fp);
|
||
if (sBuf[0]) {
|
||
CT_strnth(TString(sBuf), 1, cName);
|
||
CT_strnth(TString(sBuf), 2, eName);
|
||
CT_strnth(TString(sBuf), 3, sColor);
|
||
CT_strnth(TString(sBuf), 4, sLineType);
|
||
CT_strnth(TString(sBuf), 5, sDes);
|
||
}
|
||
if (cName[0] && eName[0]) {
|
||
int nColor = _ttoi(sColor);
|
||
lstLayer.Append(new CLayerData(eName, cName, sLineType, sDes, nColor));
|
||
}
|
||
}
|
||
fclose(fp);
|
||
}
|
||
int len = lstLayer.Length();
|
||
CString csLayerOld;
|
||
for (int i = 0; i < len; i++) {
|
||
if (_tcscmp(lstLayer[i]->m_csCName, szChnLayer) == 0) {
|
||
csLayerOld = lstLayer[i]->m_csEName;
|
||
lstLayer[i]->m_csEName = szEngLayer;
|
||
break;
|
||
}
|
||
}
|
||
|
||
FILE *fp = fopen(_AS(fullFile), "w");
|
||
if (!fp)
|
||
return;
|
||
len = lstLayer.Length();
|
||
for (i = 0; i < len; i++) {
|
||
CString csColor;
|
||
csColor.Format(_T("%d"), lstLayer[i]->m_iColor);
|
||
CString csTmp = lstLayer[i]->m_csCName + _T(" ") + lstLayer[i]->m_csEName + _T(" ") + csColor + _T(" ")
|
||
+ lstLayer[i]->m_csLinetype + _T(" ") + lstLayer[i]->m_csDes + _T("\n");
|
||
fputs(_AS(csTmp), fp);
|
||
}
|
||
fclose(fp);
|
||
|
||
AcDbObjectId idLayer = GetLayerIdFromString(csLayerOld);
|
||
if (!idLayer)
|
||
return;
|
||
OPENOBJ_BEGIN(idLayer, AcDb::kForWrite, AcDbLayerTableRecord, pLayer);
|
||
if (pLayer) {
|
||
pLayer->setName(szEngLayer);
|
||
}
|
||
else {
|
||
AfxMessageBox(_T("层写保护!"));
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
}
|
||
|
||
#if ADS > 22
|
||
static bool SheetHook(MSG* msg)
|
||
#else
|
||
static BOOL SheetHook(MSG* msg)
|
||
#endif
|
||
{
|
||
BOOL bRet=FALSE;
|
||
|
||
switch(msg->message) {
|
||
case WM_KEYDOWN: {
|
||
if(msg->wParam == VK_RETURN){
|
||
g_nKey = VK_RETURN;
|
||
acedPostCommand(_T(" "));
|
||
bRet = TRUE;
|
||
}
|
||
else if(msg->wParam == VK_ESCAPE){
|
||
g_nKey = VK_ESCAPE;
|
||
acedPostCommand(_T(" "));
|
||
bRet = TRUE;
|
||
}
|
||
else if(msg->wParam == VK_RIGHT){
|
||
g_nKey = VK_RIGHT;
|
||
acedPostCommand(_T(" "));
|
||
bRet = TRUE;
|
||
}
|
||
else if(msg->wParam == VK_LEFT){
|
||
g_nKey = VK_LEFT;
|
||
acedPostCommand(_T(" "));
|
||
bRet = TRUE;
|
||
}
|
||
else if(msg->wParam == VK_UP){
|
||
g_nKey = VK_UP;
|
||
acedPostCommand(_T(" "));
|
||
bRet = TRUE;
|
||
}
|
||
else if(msg->wParam == VK_DOWN){
|
||
g_nKey = VK_DOWN;
|
||
acedPostCommand(_T(" "));
|
||
bRet = TRUE;
|
||
}
|
||
break;
|
||
}
|
||
case WM_MOUSEWHEEL:{
|
||
bRet = TRUE;
|
||
break;
|
||
}
|
||
case WM_MBUTTONDOWN:{
|
||
bRet = TRUE;
|
||
break;
|
||
}
|
||
case WM_RBUTTONUP:{
|
||
g_nKey = VK_RBUTTON;
|
||
acedPostCommand(_T(" "));
|
||
bRet = TRUE;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
return bRet;
|
||
}
|
||
|
||
void InitSheetHook(BOOL bTrue)
|
||
{
|
||
static BOOL bMsgHook = FALSE;
|
||
if (bTrue) {
|
||
if (!bMsgHook)
|
||
bMsgHook = acedRegisterFilterWinMsg(SheetHook);
|
||
}
|
||
else {
|
||
if (bMsgHook) {
|
||
acedRemoveFilterWinMsg(SheetHook);
|
||
bMsgHook = FALSE;
|
||
g_nKey = 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
BOOL GetInterPipeLevel(XPoint pt1, XPoint pt2, double nElevation, int &up, int &low)
|
||
{
|
||
pt1 = Wcs2Ucs(pt1);
|
||
pt2 = Wcs2Ucs(pt2);
|
||
|
||
BOOL ret = FALSE;
|
||
up = 256;
|
||
low = 256;
|
||
double nRotate = ads_angle(pt1, pt2);
|
||
ads_polar(pt1, ads_angle(pt1, pt2), 20, pt1);
|
||
ads_polar(pt2, ads_angle(pt2, pt1), 20, pt2);
|
||
RBList rbMaskPipe(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管线")), NULL);
|
||
PickSet ss(SS_FREE);
|
||
struct resbuf *pointlist;
|
||
|
||
pointlist = ads_buildlist(RTPOINT, &pt1, RTPOINT, &pt2, NULL);
|
||
ss.Get(_T("F"), pointlist, NULL, rbMaskPipe);
|
||
ads_relrb(pointlist);
|
||
for(long i=0;i<ss.Length();i++){
|
||
Entity ent = ss[i];
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe);
|
||
if(pPipe && !pPipe->IsVertical()){
|
||
nElevation = pPipe->StartPoint().z;
|
||
if(up < pPipe->GetHideLevel() || up == 256)
|
||
up = pPipe->GetHideLevel();
|
||
if(low > pPipe->GetHideLevel() || low == 256)
|
||
low = pPipe->GetHideLevel();
|
||
ret = TRUE;
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
return ret;
|
||
}
|
||
|
||
AcGeMatrix3d GetExternalEntityTransform(Entity ent)
|
||
{
|
||
AcDbObjectId idTemp;
|
||
acdbGetObjectId(idTemp, ent.name);
|
||
AcGeMatrix3d matRet = AcGeMatrix3d::kIdentity;
|
||
AcDbBlockTable *pTbl = NULL;
|
||
acdbCurDwg()->getBlockTable(pTbl, AcDb::kForRead);
|
||
if (pTbl != NULL)
|
||
{
|
||
bool bFlag = false;
|
||
AcDbBlockTableIterator *it = NULL;
|
||
pTbl->newIterator(it);
|
||
for (it->start(); !it->done() && !bFlag; it->step())
|
||
{
|
||
AcDbBlockTableRecord *pRcd = NULL;
|
||
it->getRecord(pRcd, AcDb::kForRead);
|
||
if (pRcd != NULL && pRcd->isFromExternalReference())
|
||
{
|
||
AcGeMatrix3d mat = AcGeMatrix3d::kIdentity;
|
||
AcDbObjectIdArray arrId;
|
||
pRcd->getBlockReferenceIds(arrId);
|
||
if (arrId.length() != 1)
|
||
{
|
||
pRcd->close();
|
||
continue;
|
||
}
|
||
AcDbBlockReference *pRef = NULL;
|
||
acdbOpenObject(pRef, arrId[0], AcDb::kForRead);
|
||
if (pRef != NULL)
|
||
{
|
||
mat = pRef->blockTransform();
|
||
pRef->close();
|
||
}
|
||
else
|
||
{
|
||
pRcd->close();
|
||
continue;
|
||
}
|
||
AcDbBlockTableRecordIterator *itRec = NULL;
|
||
pRcd->newIterator(itRec);
|
||
for (itRec->start(); !itRec->done() && !bFlag; itRec->step())
|
||
{
|
||
AcDbObjectId id;
|
||
itRec->getEntityId(id);
|
||
if (id = idTemp)
|
||
{
|
||
matRet = mat;
|
||
bFlag = true;
|
||
break;
|
||
}
|
||
}
|
||
delete itRec;
|
||
}
|
||
pRcd->close();
|
||
}
|
||
delete it;
|
||
pTbl->close();
|
||
}
|
||
return matRet;
|
||
}
|
||
|
||
void GetPLineBySeg(AcDbPolyline *pLine, XCurveSegment seg, XPoint ptPick, XPoint ptPick2)
|
||
{
|
||
if(seg.Is(CURVE_LINE)){
|
||
pLine->addVertexAt(0, ptPick);
|
||
pLine->addVertexAt(1, ptPick2);
|
||
}
|
||
else if(seg.Is(CURVE_ARC)){
|
||
//圆弧
|
||
XArc arc = seg.GetArc();
|
||
AcGeVector3d vt1(ptPick2-arc.GetCenterPt());
|
||
AcGeVector3d vt2(ptPick-arc.GetCenterPt());
|
||
double dAngle = vt1.angleTo(vt2);
|
||
double dBulge = tan(0.25 * dAngle);
|
||
// 要确定Bulge的正,负。 如果PLINE起点离弧起点近,Bulge为正
|
||
AcDbCurve *pCurve = seg.AsAcDbCurve();
|
||
double dDist1(0), dDist2(0);
|
||
pCurve->getDistAtPoint(ptPick, dDist1);
|
||
pCurve->getDistAtPoint(ptPick2, dDist2);
|
||
if(dDist1 < dDist2)
|
||
dBulge = fabs(dBulge);
|
||
else
|
||
dBulge = -fabs(dBulge);
|
||
|
||
delete pCurve;
|
||
pLine->addVertexAt(0, ptPick, dBulge);
|
||
pLine->addVertexAt(1, ptPick2);
|
||
}
|
||
}
|
||
|
||
typedef struct {
|
||
XPoint pt;
|
||
double dBulge;
|
||
}XLinePointAndBulge;
|
||
|
||
void MakeSimplePloyLine(XCurveSegment seg1, XCurveSegment seg2, XPoint ptPick, XPoint ptPick2,XLinePointAndBulge &linePt1,XLinePointAndBulge &linePt2,XLinePointAndBulge &linePt3,XPoint ptTurn)
|
||
{
|
||
//判断选中的实体是圆弧还是线
|
||
if(seg1.GetCurveType() == CURVE_LINE && seg2.GetCurveType() == CURVE_LINE){
|
||
|
||
linePt1.pt = ptPick;
|
||
linePt2.pt = ptTurn;
|
||
linePt3.pt = ptPick2;
|
||
|
||
linePt1.dBulge = 0;
|
||
linePt2.dBulge = 0;
|
||
linePt3.dBulge = 0;
|
||
}
|
||
else if(seg1.GetCurveType() == CURVE_LINE && seg2.GetCurveType() == CURVE_ARC){
|
||
XArc arc = seg2.GetArc();
|
||
AcGeVector3d vt1(ptPick2-arc.GetCenterPt());
|
||
AcGeVector3d vt2(ptTurn-arc.GetCenterPt());
|
||
double dAngle = vt1.angleTo(vt2);
|
||
double dBulge = tan(0.25 * dAngle);
|
||
// 要确定Bulge的正,负。 如果ptTurn点是弧起点,Bulge为正
|
||
XPoint ptS, ptE;
|
||
arc.GetStartPoint(ptS);
|
||
arc.GetEndPoint(ptE);
|
||
|
||
// arc.GetPoints(ptS, ptE);
|
||
if(ptTurn == ptS)
|
||
dBulge = fabs(dBulge);
|
||
else
|
||
dBulge = -fabs(dBulge);
|
||
|
||
linePt1.pt = ptPick;
|
||
linePt2.pt = ptTurn;
|
||
linePt3.pt = ptPick2;
|
||
|
||
linePt1.dBulge = 0;
|
||
linePt2.dBulge = dBulge;
|
||
linePt3.dBulge = 0;
|
||
}
|
||
else if(seg2.GetCurveType() == CURVE_LINE && seg1.GetCurveType() == CURVE_ARC){
|
||
XArc arc = seg1.GetArc();
|
||
AcGeVector3d vt1(ptTurn-arc.GetCenterPt());
|
||
AcGeVector3d vt2(ptPick-arc.GetCenterPt());
|
||
double dAngle = vt1.angleTo(vt2);
|
||
double dBulge = tan(0.25 * dAngle);
|
||
XPoint ptS, ptE;
|
||
arc.GetStartPoint(ptS);
|
||
arc.GetEndPoint(ptE);
|
||
|
||
// arc.GetPoints(ptS, ptE);
|
||
if(ptTurn == ptS)
|
||
dBulge = -fabs(dBulge);
|
||
else
|
||
dBulge = fabs(dBulge);
|
||
|
||
linePt1.pt = ptPick;
|
||
linePt2.pt = ptTurn;
|
||
linePt3.pt = ptPick2;
|
||
|
||
linePt1.dBulge = dBulge;
|
||
linePt2.dBulge = 0;
|
||
linePt3.dBulge = 0;
|
||
}
|
||
else if(seg1.GetCurveType() == CURVE_ARC && seg2.GetCurveType() == CURVE_ARC){
|
||
XArc arc = seg1.GetArc();
|
||
AcGeVector3d vt1(ptTurn-arc.GetCenterPt());
|
||
AcGeVector3d vt2(ptPick-arc.GetCenterPt());
|
||
double dAngle1 = vt1.angleTo(vt2);
|
||
double dBulge1 = tan(0.25 * dAngle1);
|
||
XPoint ptS, ptE;
|
||
arc.GetStartPoint(ptS);
|
||
arc.GetEndPoint(ptE);
|
||
|
||
// arc.GetPoints(ptS, ptE);
|
||
if(ptTurn == ptS)
|
||
dBulge1 = -fabs(dBulge1);
|
||
else
|
||
dBulge1 = fabs(dBulge1);
|
||
|
||
XArc arc2 = seg2.GetArc();
|
||
AcGeVector3d vt3(ptPick2-arc2.GetCenterPt());
|
||
AcGeVector3d vt4(ptTurn-arc2.GetCenterPt());
|
||
double dAngle2 = vt3.angleTo(vt4);
|
||
double dBulge2 = tan(0.25 * dAngle2);
|
||
arc2.GetStartPoint(ptS);
|
||
arc2.GetEndPoint(ptE);
|
||
//arc2.GetPoints(ptS, ptE);
|
||
if(ptTurn == ptS)
|
||
dBulge2 = fabs(dBulge2);
|
||
else
|
||
dBulge2 = -fabs(dBulge2);
|
||
|
||
linePt1.pt = ptPick;
|
||
linePt2.pt = ptTurn;
|
||
linePt3.pt = ptPick2;
|
||
|
||
linePt1.dBulge = dBulge1;
|
||
linePt2.dBulge = dBulge2;
|
||
linePt3.dBulge = 0;
|
||
}
|
||
}
|
||
|
||
void MakeSimplePloyLine(Entity ent, Entity ent2, XPoint ptPick, XPoint ptPick2, XLinePointAndBulge &linePt1, XLinePointAndBulge &linePt2, XLinePointAndBulge &linePt3, XPoint ptTurn)
|
||
{
|
||
XCurveSegment seg1(ent);
|
||
XCurveSegment seg2(ent2);
|
||
MakeSimplePloyLine(seg1, seg2, ptPick, ptPick2, linePt1, linePt2, linePt3, ptTurn);
|
||
}
|
||
|
||
BOOL MakeRightPloyLine(AcDbPolyline *pLine,Entity ent, Entity ent2, XPoint ptPick, XPoint ptPick2,XPoint ptFrom)
|
||
{
|
||
XCurveSegment seg(ent);
|
||
XCurveSegment seg2(ent2);
|
||
// cet 2016.7.20 add 支持外部参照
|
||
AcGeMatrix3d mat1 = GetExternalEntityTransform(ent);
|
||
AcGeMatrix3d mat2 = GetExternalEntityTransform(ent2);
|
||
ads_matrix matTemp;
|
||
memcpy(matTemp, &mat1, sizeof(AcGeMatrix3d));
|
||
seg.TransformBy(matTemp);
|
||
memcpy(matTemp, &mat2, sizeof(AcGeMatrix3d));
|
||
seg2.TransformBy(matTemp);
|
||
XLinePointAndBulge linePt1,linePt2,linePt3;//画PLINE线经过的3点
|
||
//存放点的容器
|
||
std::vector<XLinePointAndBulge> vecPt;
|
||
typedef std::vector<XLinePointAndBulge>::iterator iter;
|
||
|
||
|
||
XPoint ptTemp1,ptTemp2;//取两点十字集范围内实体的两个点
|
||
XPoint ptPLineStart, ptPLineEnd, ptPLineTurn;//相邻线的起点 拐点 终点
|
||
ptPLineStart = ptPick;
|
||
Entity entFirst = ent, entNext; //相邻两个实体
|
||
//不断的循环查找下一相邻实体
|
||
//seg变化 seg2不变化
|
||
ptPLineTurn = ptFrom;
|
||
// cet 2016.7.20 add 支持外部参照
|
||
#if ADS > 17
|
||
struct CurveNode
|
||
{
|
||
XCurveSegment seg;
|
||
Entity ent;
|
||
AcGeMatrix3d mat;
|
||
};
|
||
#endif
|
||
std::vector<CurveNode> vecCurve;
|
||
AcDbBlockTable *pTbl = NULL;
|
||
acdbCurDwg()->getBlockTable(pTbl, AcDb::kForRead);
|
||
if (pTbl != NULL)
|
||
{
|
||
AcDbBlockTableIterator *it = NULL;
|
||
pTbl->newIterator(it);
|
||
for (it->start(); !it->done(); it->step())
|
||
{
|
||
AcDbBlockTableRecord *pRcd = NULL;
|
||
it->getRecord(pRcd, AcDb::kForRead);
|
||
if (pRcd != NULL && pRcd->isFromExternalReference())
|
||
{
|
||
AcGeMatrix3d mat = AcGeMatrix3d::kIdentity;
|
||
AcDbObjectIdArray arrId;
|
||
pRcd->getBlockReferenceIds(arrId);
|
||
if (arrId.length() != 1)
|
||
{
|
||
pRcd->close();
|
||
continue;
|
||
}
|
||
AcDbBlockReference *pRef = NULL;
|
||
acdbOpenObject(pRef, arrId[0], AcDb::kForRead);
|
||
if (pRef != NULL)
|
||
{
|
||
mat = pRef->blockTransform();
|
||
pRef->close();
|
||
}
|
||
else
|
||
{
|
||
pRcd->close();
|
||
continue;
|
||
}
|
||
ads_matrix matTemp;
|
||
memcpy(matTemp, &mat, sizeof(AcGeMatrix3d));
|
||
AcDbBlockTableRecordIterator *itRec = NULL;
|
||
pRcd->newIterator(itRec);
|
||
for (itRec->start(); !itRec->done(); itRec->step())
|
||
{
|
||
AcDbEntity *pEnt = NULL;
|
||
itRec->getEntity(pEnt, AcDb::kForRead);
|
||
if (pEnt != NULL)
|
||
{
|
||
if (pEnt->isKindOf(AcDbLine::desc()))
|
||
{
|
||
AcDbLine *pLine = (AcDbLine*)pEnt;
|
||
AcGePoint3d pt1, pt2;
|
||
pLine->getStartPoint(pt1);
|
||
pLine->getEndPoint(pt2);
|
||
XCurveSegment seg;
|
||
seg.SetLine(pt1, pt2);
|
||
seg.TransformBy(matTemp);
|
||
ads_name name;
|
||
acdbGetAdsName(name, pEnt->objectId());
|
||
CurveNode node;
|
||
node.seg = seg;
|
||
node.ent = Entity(name);
|
||
node.mat = mat;
|
||
vecCurve.push_back(node);
|
||
}
|
||
else if (pEnt->isKindOf(AcDbArc::desc()))
|
||
{
|
||
AcDbArc *pArc = (AcDbArc*)pEnt;
|
||
XArc arc(XPoint(pArc->center()), pArc->radius(), pArc->startAngle(), pArc->endAngle());
|
||
arc.TransformBy(matTemp);
|
||
ads_name name;
|
||
acdbGetAdsName(name, pEnt->objectId());
|
||
CurveNode node;
|
||
node.seg = arc;
|
||
node.ent = Entity(name);
|
||
node.mat = mat;
|
||
vecCurve.push_back(node);
|
||
}
|
||
}
|
||
pEnt->close();
|
||
}
|
||
delete itRec;
|
||
}
|
||
pRcd->close();
|
||
}
|
||
delete it;
|
||
// 模型空间中的墙体
|
||
AcDbBlockTableRecord *pRcd = NULL;
|
||
pTbl->getAt(ACDB_MODEL_SPACE, pRcd, AcDb::kForRead);
|
||
if (pTbl != NULL)
|
||
{
|
||
AcGeMatrix3d mat = AcGeMatrix3d::kIdentity;
|
||
ads_matrix matTemp;
|
||
memcpy(matTemp, &mat, sizeof(AcGeMatrix3d));
|
||
AcDbBlockTableRecordIterator *itRec = NULL;
|
||
pRcd->newIterator(itRec);
|
||
for (itRec->start(); !itRec->done(); itRec->step())
|
||
{
|
||
AcDbEntity *pEnt = NULL;
|
||
itRec->getEntity(pEnt, AcDb::kForRead);
|
||
if (pEnt != NULL)
|
||
{
|
||
if (pEnt->isKindOf(AcDbLine::desc()))
|
||
{
|
||
AcDbLine *pLine = (AcDbLine*)pEnt;
|
||
AcGePoint3d pt1, pt2;
|
||
pLine->getStartPoint(pt1);
|
||
pLine->getEndPoint(pt2);
|
||
XCurveSegment seg;
|
||
seg.SetLine(pt1, pt2);
|
||
seg.TransformBy(matTemp);
|
||
ads_name name;
|
||
acdbGetAdsName(name, pEnt->objectId());
|
||
CurveNode node;
|
||
node.seg = seg;
|
||
node.ent = Entity(name);
|
||
node.mat = mat;
|
||
vecCurve.push_back(node);
|
||
}
|
||
else if (pEnt->isKindOf(AcDbArc::desc()))
|
||
{
|
||
AcDbArc *pArc = (AcDbArc*)pEnt;
|
||
XArc arc(XPoint(pArc->center()), pArc->radius(), pArc->startAngle(), pArc->endAngle());
|
||
arc.TransformBy(matTemp);
|
||
ads_name name;
|
||
acdbGetAdsName(name, pEnt->objectId());
|
||
CurveNode node;
|
||
node.seg = arc;
|
||
node.ent = Entity(name);
|
||
node.mat = mat;
|
||
vecCurve.push_back(node);
|
||
}
|
||
}
|
||
pEnt->close();
|
||
}
|
||
delete itRec;
|
||
pRcd->close();
|
||
}
|
||
pTbl->close();
|
||
}
|
||
//两个实体相邻则退出
|
||
while(seg.EndPoint().Distance(seg2.StartPoint()) > 0.001 && seg.StartPoint().Distance(seg2.EndPoint()) > 0.001
|
||
&& seg.EndPoint().Distance(seg2.EndPoint()) > 0.001 && seg.StartPoint().Distance(seg2.StartPoint()) > 0.001)
|
||
{
|
||
// cet 2016.7.20 modify 支持外部参照
|
||
// ptTemp1 = ptPLineTurn;
|
||
// ptTemp2 = ptPLineTurn;
|
||
// ptTemp1.x += 2;
|
||
// ptTemp1.y += 2;
|
||
// ptTemp2.x -= 2;
|
||
// ptTemp2.y -= 2;
|
||
// AssureInCurrentView(ptTemp1, ptTemp2);
|
||
// PickSet ssPoint(SS_FREE);
|
||
// ssPoint.Get(_T("C"),ptTemp1,ptTemp2, RBList(RTDXF0, _T("LINE,ARC"), NULL));
|
||
PickSet ssPoint(SS_FREE);
|
||
for (int i = 0; i < vecCurve.size(); ++i)
|
||
{
|
||
XCurveSegment &segTmp = vecCurve[i].seg;
|
||
XPoint pt;
|
||
ptPLineTurn.Project(&segTmp, pt);
|
||
if (pt.Distance2d(ptPLineTurn) < 0.001)
|
||
{
|
||
ssPoint += vecCurve[i].ent;
|
||
}
|
||
}
|
||
ssPoint -= entFirst;
|
||
if(ssPoint.Length() != 1)
|
||
return FALSE;
|
||
entNext = ssPoint[0L];
|
||
|
||
// if(ssPoint.Length() != 2)
|
||
// return FALSE;
|
||
// //去掉旧的实体 entNext 是循环的下1段线
|
||
// Entity entPointTemp1, entPointTemp2;
|
||
// entPointTemp1 = ssPoint[0L];
|
||
// entPointTemp2 = ssPoint[1L];
|
||
//
|
||
// if(entPointTemp1 == entFirst)
|
||
// entNext = entPointTemp2;
|
||
// else if(entPointTemp2 == entFirst)
|
||
// entNext = entPointTemp1;
|
||
|
||
XCurveSegment segNext(entNext);
|
||
// cet 2016.7.20 add 支持外部参照
|
||
AcGeMatrix3d mat = AcGeMatrix3d::kIdentity;
|
||
for (int i = 0; i < vecCurve.size(); ++i)
|
||
{
|
||
if (vecCurve[i].ent == entNext)
|
||
{
|
||
mat = vecCurve[i].mat;
|
||
break;
|
||
}
|
||
}
|
||
ads_matrix matTemp;
|
||
memcpy(matTemp, &mat, sizeof(AcGeMatrix3d));
|
||
segNext.TransformBy(matTemp);
|
||
seg = segNext; //下一个
|
||
|
||
if(segNext.StartPoint() == seg.StartPoint() || segNext.StartPoint() == seg.EndPoint())
|
||
ptPLineEnd = segNext.EndPoint();
|
||
else if(segNext.EndPoint() == seg.StartPoint() || segNext.EndPoint() == seg.EndPoint())
|
||
ptPLineEnd = segNext.StartPoint();
|
||
else
|
||
return FALSE;//确保前后2段线一定首尾相连
|
||
|
||
MakeSimplePloyLine(entFirst,entNext,ptPLineStart,ptPLineEnd,linePt1,linePt2,linePt3,ptPLineTurn);
|
||
|
||
//取下1段PLINE的拐点
|
||
if (segNext.StartPoint() != ptPLineTurn)
|
||
ptPLineTurn = segNext.StartPoint();
|
||
else
|
||
ptPLineTurn = segNext.EndPoint();
|
||
|
||
entFirst = entNext;
|
||
ptPLineStart = ptPLineEnd;
|
||
|
||
if (entFirst == ent)//找到自己则退出
|
||
return FALSE;
|
||
|
||
vecPt.push_back(linePt1);
|
||
vecPt.push_back(linePt2);
|
||
vecPt.push_back(linePt3);
|
||
}
|
||
MakeSimplePloyLine(entFirst,ent2,ptPLineStart,ptPick2,linePt1,linePt2,linePt3,ptPLineTurn);
|
||
vecPt.push_back(linePt1);
|
||
vecPt.push_back(linePt2);
|
||
vecPt.push_back(linePt3);
|
||
|
||
//生成PLINE线
|
||
for (int it = 0; it < vecPt.size(); ++it)
|
||
{
|
||
pLine->addVertexAt(it,vecPt[it].pt,vecPt[it].dBulge);
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
BOOL MakePolyLineByWall(AcDbPolyline *pLine,Entity ent, Entity ent2, XPoint ptPick, XPoint ptPick2)
|
||
{
|
||
XCurveSegment lCurve, rCurve,firstSeg,secondSeg;
|
||
BOOL bIsLeft = TRUE;
|
||
XPoint ptTurn;
|
||
//得到墙实体1
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbWall, pWall);
|
||
XPoint ptNew1, ptNew2;
|
||
if(pWall) {
|
||
pWall->GetSideCurve(lCurve, rCurve);
|
||
lCurve.ProjectToMe(ptPick, ptNew1);
|
||
rCurve.ProjectToMe(ptPick, ptNew2);
|
||
if(ads_distance(ptPick, ptNew1) < ads_distance(ptPick, ptNew2)){
|
||
firstSeg = lCurve;
|
||
bIsLeft = TRUE;
|
||
ptPick = ptNew1;
|
||
}
|
||
else{
|
||
firstSeg = rCurve;
|
||
bIsLeft = FALSE;
|
||
ptPick = ptNew2;
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
XPoint ptNew3, ptNew4;
|
||
//得到墙实体2
|
||
OPENOBJ_BEGIN(ent2, AcDb::kForRead, TDbWall, pWall2);
|
||
if(pWall2)
|
||
{
|
||
pWall2->GetSideCurve(lCurve, rCurve);
|
||
lCurve.ProjectToMe(ptPick2, ptNew3);
|
||
rCurve.ProjectToMe(ptPick2, ptNew4);
|
||
|
||
//找到相临的CURVE
|
||
if(firstSeg.StartPoint() == lCurve.StartPoint() || firstSeg.StartPoint() == lCurve.EndPoint()||firstSeg.EndPoint() == lCurve.StartPoint() || firstSeg.EndPoint() == lCurve.EndPoint())
|
||
{
|
||
ptPick2 = ptNew3;
|
||
secondSeg = lCurve;
|
||
}
|
||
else
|
||
{
|
||
ptPick2 = ptNew4;
|
||
secondSeg = rCurve;
|
||
}
|
||
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
//得到拐点
|
||
if(firstSeg.StartPoint() == secondSeg.StartPoint() || firstSeg.StartPoint() == secondSeg.EndPoint())
|
||
ptTurn = firstSeg.StartPoint();
|
||
else if(firstSeg.EndPoint() == secondSeg.StartPoint() || firstSeg.EndPoint() == secondSeg.EndPoint())
|
||
ptTurn = firstSeg.EndPoint();
|
||
else
|
||
return FALSE;
|
||
|
||
XLinePointAndBulge linePoint1,linePoint2,linePoint3;
|
||
//得到构成PLINE线的3点
|
||
MakeSimplePloyLine(firstSeg,secondSeg,ptPick,ptPick2,linePoint1,linePoint2,linePoint3,ptTurn);
|
||
|
||
if (pLine != NULL)
|
||
{
|
||
pLine->addVertexAt(0,linePoint1.pt,linePoint1.dBulge);
|
||
pLine->addVertexAt(1,linePoint2.pt,linePoint2.dBulge);
|
||
pLine->addVertexAt(2,linePoint3.pt,linePoint3.dBulge);
|
||
AssureInCurrentView(ptPick2, ptPick2);
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
AcDbPolyline* GetNextPloyLine(Entity ent, Entity ent2, XPoint ptPick, XPoint ptPick2)
|
||
{
|
||
XPoint ptTurn;
|
||
XCurveSegment seg(ent);
|
||
XCurveSegment seg2(ent2);
|
||
// cet 2016.7.20 add 支持外部参照
|
||
AcGeMatrix3d mat1 = GetExternalEntityTransform(ent);
|
||
AcGeMatrix3d mat2 = GetExternalEntityTransform(ent2);
|
||
ads_matrix matTemp;
|
||
memcpy(matTemp, &mat1, sizeof(AcGeMatrix3d));
|
||
seg.TransformBy(matTemp);
|
||
memcpy(matTemp, &mat2, sizeof(AcGeMatrix3d));
|
||
seg2.TransformBy(matTemp);
|
||
//如果是相邻或同一线段求得转折点
|
||
if(seg.StartPoint() == seg2.StartPoint() || seg.StartPoint() == seg2.EndPoint())
|
||
ptTurn = seg.StartPoint();
|
||
else if(seg.EndPoint() == seg2.StartPoint() || seg.EndPoint() == seg2.EndPoint())
|
||
ptTurn = seg.EndPoint();
|
||
|
||
AcDbPolyline *pLine = new AcDbPolyline;
|
||
|
||
if(ent == ent2)
|
||
{ // 如果用户点在本线段
|
||
if(ent.Is(_T("LINE")) || ent.Is(_T("ARC")))
|
||
{
|
||
GetPLineBySeg(pLine, seg, ptPick, ptPick2);
|
||
}
|
||
else if (ent.Is(_T("ATS_WALL")))
|
||
{
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbWall, pWall);
|
||
if(pWall){
|
||
XCurveSegment lCurve, rCurve, seg;
|
||
XPoint ptNew1, ptNew2;
|
||
pWall->GetSideCurve(lCurve, rCurve);
|
||
// cet 2016.7.20 add 支持外部参照
|
||
ads_matrix matTemp;
|
||
memcpy(matTemp, &mat1, sizeof(AcGeMatrix3d));
|
||
lCurve.TransformBy(matTemp);
|
||
rCurve.TransformBy(matTemp);
|
||
lCurve.ProjectToMe(ptPick, ptNew1);
|
||
rCurve.ProjectToMe(ptPick, ptNew2);
|
||
if(ads_distance(ptPick, ptNew1) < ads_distance(ptPick, ptNew2))
|
||
seg = lCurve;
|
||
else
|
||
seg = rCurve;
|
||
GetPLineBySeg(pLine, seg, ptPick, ptPick2);
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
else if (ent.Is(_T("LWPOLYLINE")))
|
||
{
|
||
delete pLine;
|
||
AcDbPolyline *pLine2 = NULL;
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbPolyline, pCurve);
|
||
if(pCurve)
|
||
{
|
||
AcDbCurve *pNewCurve = (AcDbCurve*)pCurve->clone();
|
||
pNewCurve->transformBy(mat1);
|
||
AcDbCurve *pCurve3 = GetCurveBy2Pt(pNewCurve, ptPick, ptPick2);
|
||
if(pCurve3 != NULL)
|
||
pLine2 = AcDbPolyline::cast(pCurve3);
|
||
if(pLine2 == NULL)
|
||
delete pCurve3;
|
||
delete pNewCurve;
|
||
}
|
||
OPENOBJ_END();
|
||
AssureInCurrentView(ptPick2, ptPick2);
|
||
return pLine2;
|
||
}
|
||
else {
|
||
delete pLine;
|
||
return NULL;
|
||
}
|
||
}
|
||
else{ // 如果用户点在不同并且不相邻线段
|
||
//不支持2个相邻的线段,有1个是PLINE
|
||
if (ent.Is(_T("LWPOLYLINE")) || ent2.Is(_T("LWPOLYLINE"))){
|
||
delete pLine;
|
||
return NULL;
|
||
}
|
||
if (ptTurn != seg.StartPoint() && ptTurn != seg.EndPoint())
|
||
{
|
||
//如果是封闭曲线则不画
|
||
BOOL bTrue1 = MakeRightPloyLine(pLine,ent,ent2,ptPick,ptPick2,seg.StartPoint());
|
||
BOOL bTrue2 = MakeRightPloyLine(pLine,ent,ent2,ptPick,ptPick2,seg.EndPoint());
|
||
|
||
if (bTrue1 && bTrue2)
|
||
{
|
||
adsout << _T("所选线段在封闭的环中\n");
|
||
delete pLine;
|
||
return NULL;
|
||
}
|
||
if (!bTrue1 && !bTrue2)
|
||
{
|
||
delete pLine;
|
||
|
||
XPoint ptInter1,ptInter2;
|
||
if (seg.Intersection(seg2,ptInter1,ptInter2) != 1)
|
||
{
|
||
adsout << _T("所选线段与当前线段没有相连\n");
|
||
return NULL;
|
||
}
|
||
else
|
||
{
|
||
//实体相邻且只有一个交点
|
||
pLine = new AcDbPolyline;
|
||
XLinePointAndBulge linePoint1,linePoint2,linePoint3;
|
||
//通过给定的实体和点得到构成PLINE线的3点
|
||
//ent ent2 ptPick ptPick2 为选中的实体和点 ptInter1 为两实体交点
|
||
MakeSimplePloyLine(ent,ent2,ptPick,ptPick2,linePoint1,linePoint2,linePoint3,ptInter1);
|
||
|
||
if (pLine != NULL)
|
||
{
|
||
pLine->addVertexAt(0,linePoint1.pt,linePoint1.dBulge);
|
||
pLine->addVertexAt(1,linePoint2.pt,linePoint2.dBulge);
|
||
pLine->addVertexAt(2,linePoint3.pt,linePoint3.dBulge);
|
||
AssureInCurrentView(ptPick2, ptPick2);
|
||
}
|
||
|
||
return pLine;
|
||
}
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
if (ent.Is(_T("ATS_WALL")) && ent2.Is(_T("ATS_WALL")))
|
||
{
|
||
|
||
if(!MakePolyLineByWall(pLine,ent,ent2,ptPick,ptPick2)){
|
||
delete pLine;
|
||
return NULL;
|
||
}
|
||
return pLine;
|
||
}
|
||
else
|
||
{
|
||
BOOL bTrue3 = MakeRightPloyLine(pLine,ent,ent2,ptPick,ptPick2,ptTurn);
|
||
if (!bTrue3)
|
||
{
|
||
delete pLine;
|
||
return NULL;
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
}
|
||
AssureInCurrentView(ptPick2, ptPick2);
|
||
return pLine;
|
||
}
|
||
|
||
AcDbCurve* GetCurveBy2Pt(AcDbCurve *pCurve, XPoint ptOnCurve1, XPoint ptOnCurve2)
|
||
{
|
||
AcDbVoidPtrArray arSeg;//裁剪后的曲线段
|
||
AcGePoint3dArray arPoint(2);//裁剪的点
|
||
double dDist1, dDist2;
|
||
pCurve->getDistAtPoint(ptOnCurve1, dDist1);
|
||
pCurve->getDistAtPoint(ptOnCurve2, dDist2);
|
||
if(dDist1 < dDist2){
|
||
arPoint.append(ptOnCurve1);
|
||
arPoint.append(ptOnCurve2);
|
||
}
|
||
else{
|
||
arPoint.append(ptOnCurve2);
|
||
arPoint.append(ptOnCurve1);
|
||
}
|
||
|
||
pCurve->getSplitCurves(arPoint,arSeg);//剪切PLINE线
|
||
int nLen = arSeg.length();
|
||
// cet 2014.12.1 modify 当点在曲线起始点时结果错误
|
||
// if(nLen != 3)
|
||
// {
|
||
// ReleaseEntSet(arSeg);
|
||
// return NULL;
|
||
// }
|
||
// AcDbCurve *pCurveRet = NULL;
|
||
// for (int i = 0; i < nLen; ++i)
|
||
// {
|
||
// AcDbCurve *pCurve3 = (AcDbCurve*)arSeg[i];
|
||
// if (pCurve3 != NULL)
|
||
// {
|
||
// if(i == 1)
|
||
// pCurveRet = pCurve3;
|
||
// else
|
||
// delete pCurve3;
|
||
// }
|
||
// }
|
||
AcGePoint3d ptS, ptE;
|
||
AcDbCurve *pCurveRet = NULL;
|
||
for (int i = 0; i < nLen; ++i)
|
||
{
|
||
AcDbCurve *pCurve3 = (AcDbCurve*)arSeg[i];
|
||
if (pCurve3 != NULL)
|
||
{
|
||
pCurve3->getStartPoint(ptS);
|
||
pCurve3->getEndPoint(ptE);
|
||
if (ptS.distanceTo(ptOnCurve1) < 0.001 && ptE.distanceTo(ptOnCurve2) < 0.001
|
||
|| ptS.distanceTo(ptOnCurve2) < 0.001 && ptE.distanceTo(ptOnCurve1) < 0.001)
|
||
{
|
||
arSeg.removeAt(i);
|
||
pCurveRet = pCurve3;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
ReleaseEntSet(arSeg);
|
||
return pCurveRet;
|
||
}
|
||
|
||
XCurveSegment GetBlkPickSegment(Entity entBlk, XPoint ptPick)
|
||
{
|
||
XCurveSegment seg;
|
||
ads_name ename;
|
||
ads_matrix adsmat;
|
||
struct resbuf *insStack;
|
||
|
||
if (acedNEntSelP(NULL, ename, ptPick, TRUE,
|
||
adsmat, &insStack) != RTNORM)
|
||
{
|
||
ads_printf(_T("\nFailure in ads_nentselp"));
|
||
return seg;
|
||
}
|
||
ads_relrb(insStack);
|
||
Entity entTemp = ename;
|
||
if(entTemp.Is(_T("LINE")) || entTemp.Is(_T("ARC"))){
|
||
XCurveSegment seg1(entTemp);
|
||
seg1.TransformBy(adsmat);
|
||
seg = seg1;
|
||
}
|
||
else if(entTemp.Is(_T("LWPOLYLINE"))){
|
||
double dAngle;
|
||
XPoly2D poly(entTemp);
|
||
poly.TransformBy(AsAcGeMatrix3d(adsmat));
|
||
//poly.Make();
|
||
seg = GetSegByPt(poly, ptPick, dAngle);
|
||
}
|
||
else if(entTemp.Is(_T("ATS_WALL"))){
|
||
OPENOBJ_BEGIN(entTemp, AcDb::kForRead, TDbWall, pWall);
|
||
XCurveSegment lCurve, rCurve;
|
||
XPoint ptNew1, ptNew2;
|
||
if(pWall) {
|
||
pWall->GetSideCurve(lCurve, rCurve);
|
||
lCurve.TransformBy(adsmat);
|
||
rCurve.TransformBy(adsmat);
|
||
seg = lCurve;
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
else{
|
||
OPENOBJ_BEGIN(ename, AcDb::kForRead, AcDbEntity, pEnt);
|
||
if(pEnt != NULL){
|
||
ads_printf(_T("\n无法识别: %s"), pEnt->isA()->name());
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
|
||
|
||
return seg;
|
||
|
||
}
|
||
|
||
int get_line_angle(ads_real& line_angle)//得到直线的角度
|
||
{
|
||
int iLineType = 0;
|
||
RBList rbMask = ads_buildlist( -4, _T("<or"),
|
||
-4, _T("<and"), RTDXF0, _T("LINE"), 8, _T("*"), -4, _T("and>"),
|
||
-4, _T("<and"), RTDXF0, _T("LWPOLYLINE"), 8, _T("*"), -4, _T("and>"),
|
||
-4, _T("<and"), RTDXF0, _T("INSERT"), 8, _T("*"), -4, _T("and>"),
|
||
-4, _T("<and"), RTDXF0, _T("ATS_WALL"), -4, _T("and>"),
|
||
-4, _T("or>"), NULL);
|
||
XPoint ptPick;
|
||
Entity entWall;
|
||
if(SelectEntity1(_T("\n从当前图中选取行向线<不选取>:"), entWall, ptPick, rbMask) != RTNORM)
|
||
return RTNORM;
|
||
XCurveSegment lCurve, rCurve, SelCurve;
|
||
BOOL bIsLeft = TRUE;
|
||
if(entWall.Is(_T("INSERT"))){
|
||
SelCurve = GetBlkPickSegment(entWall, ptPick);
|
||
if(!SelCurve)
|
||
return 0;
|
||
iLineType = 0;
|
||
}
|
||
else if(entWall.Is(_T("LWPOLYLINE"))){
|
||
double dAngle;
|
||
XPoint ptWcs = Ucs2Wcs(ptPick);
|
||
SelCurve = GetSegByPt(XPoly2D(entWall), ptWcs, dAngle);
|
||
if(!SelCurve)
|
||
return 0;
|
||
iLineType = 0;
|
||
}
|
||
else if(entWall.Is(_T("ATS_WALL"))){
|
||
OPENOBJ_BEGIN(entWall, AcDb::kForRead, TDbWall, pWall);
|
||
XPoint ptNew1, ptNew2;
|
||
if(pWall) {
|
||
pWall->GetSideCurve(lCurve, rCurve);
|
||
lCurve.ProjectToMe(ptPick, ptNew1);
|
||
rCurve.ProjectToMe(ptPick, ptNew2);
|
||
if(ads_distance(ptPick, ptNew1) < ads_distance(ptPick, ptNew2)){
|
||
SelCurve = lCurve;
|
||
bIsLeft = TRUE;
|
||
}
|
||
else{
|
||
SelCurve = rCurve;
|
||
bIsLeft = FALSE;
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
else
|
||
iLineType = 1;
|
||
|
||
|
||
if(!SelCurve.Is(CURVE_LINE))
|
||
return RTCAN;
|
||
if(iLineType == 0){
|
||
XLine line = SelCurve.GetLine();
|
||
//得到直线的角度
|
||
line_angle=ads_angle(line.StartPoint(),line.EndPoint());
|
||
if(line_angle > PI)
|
||
line_angle = line_angle - PI;
|
||
}
|
||
else if(iLineType == 1){
|
||
XPoint ptStart, ptEnd;
|
||
entWall.GetData(10, ptStart);
|
||
entWall.GetData(11, ptEnd);
|
||
line_angle=ads_angle(ptStart, ptEnd);
|
||
if(line_angle > PI)
|
||
line_angle = line_angle - PI;
|
||
}
|
||
return RTNORM;
|
||
}
|
||
|
||
AcDbCurve* GetOffsetCurve(AcDbCurve *pCurve, double dOffsetDist, XPoint ptPick)
|
||
{
|
||
if(pCurve == NULL)
|
||
return NULL;
|
||
//先OFFSET一根曲线过来
|
||
AcDbVoidPtrArray arCurves;
|
||
pCurve->getOffsetCurves(dOffsetDist, arCurves);
|
||
int len = arCurves.length();
|
||
if(arCurves.length() > 0){
|
||
AcDbCurve *pCurve2;
|
||
pCurve2 = (AcDbCurve *)arCurves.first();
|
||
XPoint ptOnCurve;
|
||
pCurve2->getClosestPointTo(ptPick, ptOnCurve);
|
||
double dDist = ads_distance(ptPick, ptOnCurve);
|
||
|
||
long lNum=arCurves.length();
|
||
for(long j=1L; j<lNum; j++) { //必须全部释放
|
||
AcDbEntity *pEnt=(AcDbEntity *)arCurves[j];
|
||
delete pEnt;
|
||
}
|
||
|
||
if(dDist < 0.001)//通过偏移距离的正负可以得到2根线段,ptPick在哪上就返回哪根
|
||
return pCurve2;
|
||
else{
|
||
delete pCurve2;
|
||
AcDbVoidPtrArray arCurves2;
|
||
pCurve->getOffsetCurves(-dOffsetDist, arCurves2);
|
||
if(arCurves2.length() > 0){
|
||
AcDbCurve *pCurve3;
|
||
pCurve3 = (AcDbCurve *)arCurves2.first();
|
||
long lNum2=arCurves2.length();
|
||
for(j=1L; j<lNum2; j++) {//必须全部释放
|
||
AcDbEntity *pEnt2=(AcDbEntity *)arCurves2[j];
|
||
delete pEnt2;
|
||
}
|
||
|
||
return pCurve3;
|
||
}
|
||
}
|
||
}
|
||
return NULL;
|
||
}
|
||
|
||
BOOL IsHydrant(Entity ent)
|
||
{
|
||
AcDbObjectId idBlk = NULL;
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbEquipment, pEquip);
|
||
if(pEquip)
|
||
idBlk = pEquip->GetBlock2d();
|
||
else
|
||
return FALSE;
|
||
OPENOBJ_END();
|
||
const TCHAR *szBlkName = NULL;
|
||
OPENOBJ_BEGIN(idBlk, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
|
||
if(pRecord){
|
||
pRecord->getName(szBlkName);
|
||
}
|
||
OPENOBJ_END();
|
||
CString csTKName, csRocord;
|
||
SplitBlkStr(szBlkName, csTKName, csRocord);
|
||
CString sDwbPath = g_sDwbPath;
|
||
|
||
csTKName = sDwbPath + csTKName + _T(".tk");
|
||
CString csDesName = GetBlkDesName((const TCHAR*)csRocord, (const TCHAR*)csTKName);
|
||
if(csDesName.Find(_T("消火栓")) > -1)
|
||
return TRUE;
|
||
return FALSE;
|
||
}
|
||
BOOL IsHydrant(AcDbObjectId idNode)
|
||
{
|
||
if(!idNode)
|
||
return FALSE;
|
||
AcDbObjectId idBlk = NULL;
|
||
OPENOBJ_BEGIN(idNode, AcDb::kForRead, TDbEquipment, pEquip);
|
||
if(pEquip)
|
||
idBlk = pEquip->GetBlock2d();
|
||
else
|
||
return FALSE;
|
||
OPENOBJ_END();
|
||
const TCHAR *szBlkName = NULL;
|
||
OPENOBJ_BEGIN(idBlk, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
|
||
if(pRecord){
|
||
pRecord->getName(szBlkName);
|
||
}
|
||
OPENOBJ_END();
|
||
CString csTKName, csRocord;
|
||
SplitBlkStr(szBlkName, csTKName, csRocord);
|
||
CString sDwbPath = g_sDwbPath;
|
||
|
||
csTKName = sDwbPath + csTKName + _T(".tk");
|
||
CString csDesName = GetBlkDesName((const TCHAR*)csRocord, (const TCHAR*)csTKName);
|
||
if(csDesName.Find(_T("系统消火栓")) > -1)
|
||
return FALSE;
|
||
if(csDesName.Find(_T("室外消火栓")) > -1)
|
||
return FALSE;
|
||
if(csDesName.Find(_T("消火栓")) > -1)
|
||
return TRUE;
|
||
return FALSE;
|
||
}
|
||
|
||
|
||
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;
|
||
}
|
||
|
||
BOOL SetDnByMat(const TCHAR* szMat, const TCHAR*szNewDn)
|
||
{
|
||
CodeBase db;
|
||
int Number;
|
||
CString csType, csValue, csRemark;
|
||
XString fullFile;
|
||
if(!FindFile(_T("DataStore.dbf"), fullFile)) {
|
||
Callme(_T("对不起,没有发现DataStore.dbf文件!"));
|
||
return FALSE;
|
||
}
|
||
XDbfTable *pTable = db.Open(fullFile);
|
||
pTable->MoveFirst();
|
||
while(!pTable->IsEOF()) {
|
||
GET_FIELD(pTable, _T("TypeNumber"), Number);
|
||
GET_FIELD(pTable, _T("TypeName"), csType);
|
||
GET_FIELD(pTable, _T("TypeValue"), csValue);
|
||
GET_FIELD(pTable, _T("Remark"), csRemark);
|
||
if(Number == 40 && _tcsicmp((const TCHAR*)csValue, szMat) == 0){
|
||
SET_FIELD(pTable, _T("Remark"), szNewDn);
|
||
return TRUE;
|
||
}
|
||
pTable->MoveNext();
|
||
}
|
||
pTable->AppendBegin();
|
||
SET_FIELD(pTable, _T("TypeNumber"), 40);
|
||
SET_FIELD(pTable, _T("TypeName"), _T("管径标注"));
|
||
SET_FIELD(pTable, _T("TypeValue"), szMat);
|
||
SET_FIELD(pTable, _T("Remark"), szNewDn);
|
||
pTable->AppendEnd();
|
||
return TRUE;
|
||
}
|
||
|
||
BOOL IsLayerOn(const TCHAR*szLayerName)
|
||
{
|
||
// 判断图层是开是关
|
||
AcDbLayerTable *pLayertable;
|
||
AcDbLayerTableRecord *pLayerRec;
|
||
acdbCurDwg()->getLayerTable(pLayertable, AcDb::kForRead);
|
||
if(!pLayertable)
|
||
return FALSE;
|
||
if((pLayertable->getAt(szLayerName, pLayerRec, AcDb::kForRead)) == Acad::eOk) {
|
||
pLayertable->close();
|
||
if (pLayerRec->isOff() == Adesk::kTrue){
|
||
pLayerRec->close();
|
||
return FALSE;
|
||
}
|
||
else{
|
||
pLayerRec->close();
|
||
return TRUE;
|
||
}
|
||
pLayerRec->close();
|
||
}
|
||
else
|
||
pLayertable->close();
|
||
return TRUE;
|
||
}
|
||
BOOL IsExternalBlock(Entity entBlk)
|
||
{
|
||
if(!entBlk.Is(_T("INSERT")))
|
||
return FALSE;
|
||
BOOL bRet = FALSE;
|
||
TCHAR szBlkName[256];
|
||
entBlk.GetData(2, szBlkName);
|
||
|
||
AcDbBlockTable* pBlockTable = NULL;
|
||
AcDbBlockTableRecord *pRecord = NULL;
|
||
acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead);
|
||
if(Acad::eOk != pBlockTable->getAt(szBlkName, pRecord, AcDb::kForRead))
|
||
return FALSE;
|
||
pBlockTable->close();
|
||
if(pRecord->isFromExternalReference() == true){
|
||
bRet = TRUE;
|
||
}
|
||
if(pRecord)
|
||
pRecord->close();
|
||
return bRet;
|
||
}
|
||
|
||
BOOL IsSprinkler(AcDbObjectId idNode)
|
||
{
|
||
if(!idNode)
|
||
return FALSE;
|
||
AcDbObjectId idBlk = NULL;
|
||
OPENOBJ_BEGIN(idNode, AcDb::kForRead, TDbEquipment, pEquip);
|
||
if(pEquip)
|
||
idBlk = pEquip->GetBlock2d();
|
||
else
|
||
return FALSE;
|
||
OPENOBJ_END();
|
||
|
||
CString csTmp1 = _T("$twtsys$00000125");
|
||
CString csTmp2 = _T("$twtsys$00000128");
|
||
CString csTmp3 = _T("$twtsys$00000129");
|
||
CString csTmp4 = _T("$twtsys$00000131");
|
||
CString csTmp5 = _T("$twtsys$00000529");
|
||
CString csTmp6 = _T("$twtsys$00000540"); //CET 2012-1-6 ADD
|
||
CString csTmp7 = _T("$twtsys$00000541");
|
||
|
||
const TCHAR *szBlkName = NULL;
|
||
OPENOBJ_BEGIN(idBlk, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
|
||
if(pRecord){
|
||
pRecord->getName(szBlkName);
|
||
}
|
||
OPENOBJ_END();
|
||
CString csName = szBlkName;
|
||
csName.MakeLower();
|
||
int ret1 = csName.Find(csTmp1);
|
||
int ret2 = csName.Find(csTmp2);
|
||
int ret3 = csName.Find(csTmp3);
|
||
int ret4 = csName.Find(csTmp4);
|
||
int ret5 = csName.Find(csTmp5);
|
||
int ret6 = csName.Find(csTmp6);
|
||
int ret7 = csName.Find(csTmp7);
|
||
if(ret1 > -1 || ret2 > -1 || ret3 > -1 || ret4 > -1 || ret5 > -1 || ret6 > -1 || ret7 > -1)
|
||
return TRUE;
|
||
else
|
||
return FALSE;
|
||
|
||
// if(_tcsicmp(szBlkName, xsTmp2) == 0 || _tcsicmp(szBlkName, xsTmp1) == 0 ||
|
||
// _tcsicmp(szBlkName, xsTmp4) == 0 || _tcsicmp(szBlkName, xsTmp3) == 0) //是喷头
|
||
// return TRUE;
|
||
// else
|
||
// return FALSE;
|
||
}
|
||
|
||
BOOL GetBlkRecordWidth(const TCHAR* szBlkName, double nScaleX, double nScaleY, double &nWidth, double &nHeight)
|
||
{
|
||
AcDbBlockReference *pBlkRef = new AcDbBlockReference();
|
||
AcDbBlockTable* pBlockTable = NULL;
|
||
AcDbObjectId recordId = NULL;
|
||
acdbCurDwg()->getBlockTable(pBlockTable, AcDb::kForRead);
|
||
#if ADS > 24
|
||
if(Acad::eOk != pBlockTable->getAt(szBlkName, recordId)){
|
||
#else
|
||
if(Acad::eOk != pBlockTable->getAt(szBlkName, recordId, AcDb::kForRead)){
|
||
#endif
|
||
pBlockTable->close();
|
||
delete pBlkRef;
|
||
return FALSE;
|
||
}
|
||
XPoint pt;
|
||
pBlockTable->close();
|
||
pBlkRef->setBlockTableRecord(recordId);
|
||
pBlkRef->setPosition(pt);
|
||
pBlkRef->setRotation(0);
|
||
pBlkRef->setScaleFactors(AcGeScale3d(nScaleX, nScaleY, 1));
|
||
AcDbExtents extents;
|
||
pBlkRef->getGeomExtents(extents);
|
||
AcGePoint3d ptMax = extents.maxPoint();
|
||
AcGePoint3d ptMin = extents.minPoint();
|
||
double dWidth = (ptMax.x-ptMin.x)/2;
|
||
double dHeight = (ptMax.y-ptMin.y)/2;
|
||
if(dWidth < dHeight){
|
||
nWidth = dWidth;
|
||
nHeight = dHeight;
|
||
}
|
||
else{
|
||
nWidth = dHeight;
|
||
nHeight = dWidth;
|
||
}
|
||
|
||
delete pBlkRef;
|
||
return TRUE;
|
||
}
|
||
|
||
CString GetSysBlockByAng(const TCHAR* szOld, double angEq, BOOL &bIsBreak)
|
||
{
|
||
if(_tcsicmp(szOld, _T("")) == 0)
|
||
return CString();
|
||
CString csRet, csDesName, csTKName, csAllTk;
|
||
XString xsTKName, xsRocord;
|
||
SplitSlbName(szOld, xsTKName, xsRocord);
|
||
csTKName = xsTKName;
|
||
csAllTk.Format(_T("%s%s.tk"), g_csDwbPath, (const TCHAR*)xsTKName);
|
||
|
||
|
||
csDesName = GetBlkDesName((const TCHAR*)xsRocord, (const TCHAR*)csAllTk);
|
||
if(csDesName.Find(_T("(打断)"), 0) >= 0) // 2008-3-21 沈睿修改,默认都是打断管线
|
||
bIsBreak = TRUE;
|
||
else
|
||
bIsBreak = FALSE;
|
||
if(csDesName.Find(_T("-"), 0) < 0)
|
||
return CString(szOld);
|
||
csDesName = csDesName.Right(8); // 180度
|
||
if(angEq > 2*PI)
|
||
angEq -= 2*PI;
|
||
else if(fabs(angEq - 2*PI) < 0.01)
|
||
angEq = 0;
|
||
if(angEq < (PI/2-0.00001) && (angEq > 0 || fabs(angEq) < 0.01)){ //0
|
||
csDesName = GetBlkDesName((const TCHAR*)csDesName, (const TCHAR*)csAllTk);
|
||
csDesName = csDesName.Right(8);
|
||
csDesName = GetBlkDesName((const TCHAR*)csDesName, (const TCHAR*)csAllTk);
|
||
csDesName = csDesName.Right(8);
|
||
csRet = csDesName;
|
||
}
|
||
else if(angEq < (PI - 0.01) && angEq >= (PI/2-0.00001)){ //90
|
||
csDesName = GetBlkDesName((const TCHAR*)csDesName, (const TCHAR*)csAllTk);
|
||
csDesName = csDesName.Right(8);
|
||
csDesName = GetBlkDesName((const TCHAR*)csDesName, (const TCHAR*)csAllTk);
|
||
csDesName = csDesName.Right(8);
|
||
csDesName = GetBlkDesName((const TCHAR*)csDesName, (const TCHAR*)csAllTk);
|
||
csDesName = csDesName.Right(8);
|
||
csRet = csDesName;
|
||
}
|
||
else if((angEq + 0.01) < PI/2*3 && (angEq > PI || fabs(angEq - PI) < 0.01)){ //180
|
||
csRet = csDesName;
|
||
}
|
||
else if(angEq < PI*2 && (angEq > PI/2*3 || fabs(angEq - PI/2*3) < 0.01)){ //270
|
||
csDesName = GetBlkDesName((const TCHAR*)csDesName, (const TCHAR*)csAllTk);
|
||
csDesName = csDesName.Right(8);
|
||
csRet = csDesName;
|
||
}
|
||
if(csRet != _T(""))
|
||
csRet = csTKName + _T("(") + csRet + _T(")");
|
||
return csRet;
|
||
}
|
||
|
||
void PlanEquip2Sys(AcDbObjectId id, TDbPipe *pPipe, double nRadian, AcGeMatrix3d mat, AcGeScale3d scale)
|
||
{
|
||
if(!pPipe || !id)
|
||
return;
|
||
XPoint ptStart, ptEnd, ptNewS, ptNewE, ptInsert;
|
||
double dX = scale.sx;
|
||
double dY = scale.sy;
|
||
double dZ = scale.sz;
|
||
|
||
if(IsWell(id))
|
||
{
|
||
TDbWell *pNewWell = NULL;
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbWell, pEquip);
|
||
if(pEquip){
|
||
ptStart = pEquip->GetLocation();
|
||
pNewWell = (TDbWell *)pEquip->clone();
|
||
}
|
||
OPENOBJ_END();
|
||
ptStart.TransformBy(mat);
|
||
|
||
ptStart = Wcs2Ucs(ptStart); // sr 2010-1-28 modify 系统生成支持UCS
|
||
ptNewS.x = ptStart.x*dX + cos(nRadian)*ptStart.y*dY;
|
||
ptNewS.y = ptStart.z*dZ + sin(nRadian)*ptStart.y*dY;
|
||
ptNewS = Ucs2Wcs(ptNewS); // sr 2010-1-28 modify 系统生成支持UCS
|
||
|
||
pNewWell->SetLocation(ptNewS);
|
||
pNewWell->SetInsert(ptNewS);
|
||
pNewWell->EnableDrawLabel(FALSE);
|
||
pNewWell->SetHidePipe(TRUE);
|
||
// pNewWell->SetLabelLocation(ptNewS);
|
||
// pNewWell->SetHidePipe(FALSE);
|
||
|
||
AddToCurrentSpace(pNewWell, Adesk::kTrue);
|
||
return;
|
||
}
|
||
// 泵 cet 2017.12.28 add
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPump, pPump);
|
||
if (pPump != NULL)
|
||
{
|
||
XPoint ptLoc = pPump->GetLocation();
|
||
ptLoc.TransformBy(mat);
|
||
ptLoc = Wcs2Ucs(ptLoc); // 系统生成支持UCS
|
||
XPoint pt;
|
||
pt.x = ptLoc.x*dX + cos(nRadian)*ptLoc.y*dY;
|
||
pt.y = ptLoc.z*dZ + sin(nRadian)*ptLoc.y*dY;
|
||
pt = Ucs2Wcs(pt); // 系统生成支持UCS
|
||
if (_tcsicmp(pPump->GetBlockFront(), _T("")) != 0)
|
||
{
|
||
TCHAR *pszLayer = pPump->layer();
|
||
TCHAR szLayer[256];
|
||
_tcscpy(szLayer, pszLayer);
|
||
delete[] pszLayer;
|
||
InsertBlock(pPump->GetBlockFront(), pt, pPump->GetPumpLength() * dX, pPump->GetPumpLength() * dY, Ucs2Wcs(0.0), szLayer);
|
||
}
|
||
return;
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
XString xsTmpSys;
|
||
TDbEquipment *pNewEquip = NULL;
|
||
|
||
BOOL bIsBreak = TRUE;
|
||
AcDbObjectId sysBlkId(NULL);
|
||
|
||
CString csBlkName, csSysBlk, csDesName;
|
||
int iItem;
|
||
GetEquipNameById(id, csBlkName, csDesName, iItem);
|
||
|
||
double angEq(0), nRotateNewEq(0), nPipeLength(0);
|
||
// cet 2012.6.21 add 读取设备管径信息
|
||
ads_name name;
|
||
acdbGetAdsName(name, id);
|
||
Entity ent(name);
|
||
CString sPipeDn;
|
||
sPipeDn = ReadXdata(ent, _T("LINKINGPIPE_DN"));
|
||
if (sPipeDn.IsEmpty())
|
||
{
|
||
sPipeDn = _T("25");
|
||
}
|
||
double dPipeDn = _tstof(sPipeDn);
|
||
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbEquipment, pEquip);
|
||
if(pEquip){
|
||
ptStart = pEquip->GetLocation();
|
||
//ptStart = pEquip->GetInsert();
|
||
ptInsert = ptStart;
|
||
nPipeLength = pEquip->GetPipeLength();
|
||
AcDbObjectId idBlk = pEquip->GetBlock2d();
|
||
csBlkName = GetBlkNameById(idBlk);
|
||
csSysBlk = pEquip->GetSysBlock();
|
||
angEq = pEquip->GetAngle();
|
||
if(csSysBlk == _T("") && _tcsicmp(_T("$TWTSYS$00000320"), csBlkName) == 0)
|
||
return;//对于热水给水点(十字叉), 如果系统图块为空,就不生成了, 由给水生成
|
||
pNewEquip = (TDbEquipment *)pEquip->clone();
|
||
}
|
||
OPENOBJ_END();
|
||
ptStart.TransformBy(mat);
|
||
ptStart = Wcs2Ucs(ptStart); // sr 2010-1-28 modify 系统生成支持UCS
|
||
|
||
csSysBlk = GetSysBlockByAng(csSysBlk, angEq, bIsBreak);
|
||
|
||
if(LoadDwbBlock((const TCHAR*)csSysBlk, xsTmpSys) == RTNORM){
|
||
sysBlkId = GetBlkIdByName((const TCHAR*)xsTmpSys);
|
||
pNewEquip->SetBlock2d(sysBlkId);
|
||
}
|
||
|
||
if(fabs(nPipeLength) > 0.001){
|
||
if(_tcsicmp(_T("$TWTSYS$00000128"), csBlkName) == 0){ //上下喷头
|
||
ptEnd = ptStart;
|
||
ptEnd.z -= nPipeLength;
|
||
ptNewS.x = ptStart.x*dX + cos(nRadian)*ptStart.y*dY;
|
||
ptNewS.y = ptStart.z*dZ + sin(nRadian)*ptStart.y*dY;
|
||
ptNewE.x = ptEnd.x*dX + cos(nRadian)*ptEnd.y*dY;
|
||
ptNewE.y = ptEnd.z*dZ + sin(nRadian)*ptEnd.y*dY;
|
||
ptNewS = Ucs2Wcs(ptNewS); // sr 2010-1-28 modify 系统生成支持UCS
|
||
ptNewE = Ucs2Wcs(ptNewE); // sr 2010-1-28 modify 系统生成支持UCS
|
||
|
||
TDbPipe *pNewPipe = ClonePipe(pPipe);
|
||
pNewPipe->EnableDrawLabel(FALSE);
|
||
// pNewPipe->SetDnDiameter(25); cet 2012.6.21 modify
|
||
pNewPipe->SetDnDiameter(dPipeDn);
|
||
pNewPipe->SetStartPoint(ptNewS);
|
||
pNewPipe->SetEndPoint(ptNewE);
|
||
pNewPipe->SetHideLevel(1);
|
||
pNewPipe->SetModelType(TPipeSys::kSystem);
|
||
AddToCurrentSpace(pNewPipe, Adesk::kTrue);
|
||
TDbEquipment *pNewEquip2 = NULL;
|
||
pNewEquip2 = (TDbEquipment *)pNewEquip->clone();
|
||
ptNewS.x = ptEnd.x*dX + cos(nRadian)*ptEnd.y*dY;
|
||
ptNewS.y = ptEnd.z*dZ + sin(nRadian)*ptEnd.y*dY;
|
||
ptNewS = Ucs2Wcs(ptNewS); // sr 2010-1-28 modify 系统生成支持UCS
|
||
|
||
pNewEquip2->SetSysBlock(_T(""));
|
||
pNewEquip2->SetHidePipe(bIsBreak);
|
||
pNewEquip2->SetAngle(Ucs2Wcs(0.0));// sr 2010-1-28 modify 系统生成支持UCS
|
||
pNewEquip2->SetLocation(ptNewS);
|
||
pNewEquip2->SetInsert(ptNewS);
|
||
AddToCurrentSpace(pNewEquip2, Adesk::kTrue);
|
||
}
|
||
else if(_tcsicmp(_T("$TWTSYS$00000131"), csBlkName) == 0){//侧喷头
|
||
ptEnd = ptStart;
|
||
ptEnd.z += nPipeLength;
|
||
ptNewS.x = ptEnd.x*dX + cos(nRadian)*ptEnd.y*dY;
|
||
ptNewS.y = ptEnd.z*dZ + sin(nRadian)*ptEnd.y*dY;
|
||
ptNewE = ptNewS;
|
||
ptNewE.x -= nPipeLength/2;//往右画
|
||
ptNewS = Ucs2Wcs(ptNewS); // sr 2010-1-28 modify 系统生成支持UCS
|
||
ptNewE = Ucs2Wcs(ptNewE); // sr 2010-1-28 modify 系统生成支持UCS
|
||
|
||
// TDbPipe *pNewPipe3 = (TDbPipe *)pPipe->clone();
|
||
TDbPipe *pNewPipe3 = ClonePipe(pPipe);
|
||
// pNewPipe3->SetDnDiameter(25); cet 2012.6.21 modify
|
||
pNewPipe3->SetDnDiameter(dPipeDn);
|
||
pNewPipe3->EnableDrawLabel(FALSE);
|
||
pNewPipe3->SetStartPoint(ptNewS);
|
||
pNewPipe3->SetEndPoint(ptNewE);
|
||
pNewPipe3->SetHideLevel(1);
|
||
pNewPipe3->SetModelType(TPipeSys::kSystem);
|
||
AddToCurrentSpace(pNewPipe3, Adesk::kTrue);
|
||
nRotateNewEq = PI/2;
|
||
|
||
}
|
||
|
||
ptEnd = ptStart;
|
||
ptEnd.z += nPipeLength;
|
||
ptNewS.x = ptStart.x*dX + cos(nRadian)*ptStart.y*dY;
|
||
ptNewS.y = ptStart.z*dZ + sin(nRadian)*ptStart.y*dY;
|
||
ptNewE.x = ptEnd.x*dX + cos(nRadian)*ptEnd.y*dY;
|
||
ptNewE.y = ptEnd.z*dZ + sin(nRadian)*ptEnd.y*dY;
|
||
|
||
ptNewS = Ucs2Wcs(ptNewS); // sr 2010-1-28 modify 系统生成支持UCS
|
||
ptNewE = Ucs2Wcs(ptNewE); // sr 2010-1-28 modify 系统生成支持UCS
|
||
|
||
TDbPipe *pNewPipe = ClonePipe(pPipe);
|
||
// cet 2012.6.21 modify
|
||
// if(_tcsicmp(_T("TWTSYS(00000283)"), csSysBlk) == 0 || _tcsicmp(_T("TWTSYS(00000126)"), csSysBlk) == 0)
|
||
// pNewPipe->SetDnDiameter(25);
|
||
//283闭式喷头系统图块126开式喷头系统图块530水喷雾130侧喷下喷
|
||
if(_tcsicmp(_T("TWTSYS(00000283)"), csSysBlk) == 0 || _tcsicmp(_T("TWTSYS(00000126)"), csSysBlk) == 0
|
||
|| _tcsicmp(_T("TWTSYS(00000530)"), csSysBlk) == 0 || _tcsicmp(_T("TWTSYS(00000130)"), csSysBlk) == 0
|
||
|| _tcsicmp(_T("TWTSYS(00000542)"), csSysBlk )== 0) // cet 2013.1.6 modify 水幕系统图块542
|
||
|
||
pNewPipe->SetDnDiameter(dPipeDn);
|
||
pNewPipe->EnableDrawLabel(FALSE);
|
||
pNewPipe->SetStartPoint(ptNewS);
|
||
pNewPipe->SetEndPoint(ptNewE);
|
||
pNewPipe->SetHideLevel(1);
|
||
pNewPipe->SetModelType(TPipeSys::kSystem);
|
||
AddToCurrentSpace(pNewPipe, Adesk::kTrue);
|
||
ptStart = ptEnd;
|
||
}
|
||
if(nPipeLength > 0 && (_tcsicmp(_T("TWTSYS(00000283)"), csSysBlk) == 0 || _tcsicmp(_T("TWTSYS(00000126)"), csSysBlk) == 0))
|
||
nRotateNewEq = PI;
|
||
|
||
// cet 2013.1.5 add 直立型水幕系统图块旋转PI
|
||
if(nPipeLength > 0.0 && (_tcsicmp(csBlkName, _T("$TWTSYS$00000540")) == 0) && (_tcsicmp(_T("TWTSYS(00000542)"), csSysBlk) == 0))
|
||
{
|
||
nRotateNewEq = PI;
|
||
}
|
||
|
||
pNewEquip->SetAngle(nRotateNewEq + Ucs2Wcs(0.0));// sr 2010-1-28 modify 系统生成支持UCS
|
||
if(_tcsicmp(_T("$TWTSYS$00000147"), csBlkName) == 0){ //排水点
|
||
pNewEquip->SetScale(1);
|
||
pNewEquip->SetYScale(1);
|
||
}
|
||
|
||
|
||
ptNewS.x = ptStart.x*dX + cos(nRadian)*ptStart.y*dY;
|
||
ptNewS.y = ptStart.z*dZ + sin(nRadian)*ptStart.y*dY;
|
||
ptNewS = Ucs2Wcs(ptNewS); // sr 2010-1-28 modify 系统生成支持UCS
|
||
|
||
ptNewE = ptNewS;
|
||
|
||
if(csDesName.Find(_T("消火栓")) > -1){ //消火栓
|
||
// pNewEquip->SetNumber(_T("CIRCLE-131"));
|
||
pNewEquip->SetScale(1);
|
||
pNewEquip->SetYScale(1);
|
||
pNewEquip->SetZScale(1);
|
||
pNewEquip->SetAutoScale(TRUE); // cet 2017.6.5 add 随比例变化
|
||
bIsBreak = FALSE;
|
||
//消火栓的插入基点要偏移
|
||
if(fabs(nPipeLength) > 0.001)//上接直接往上偏移131
|
||
{
|
||
if(pNewEquip->IsAutoScale())
|
||
ads_polar(ptNewS, PI/2, 131*pNewEquip->GetPScale()/100, ptNewE);
|
||
else
|
||
ads_polar(ptNewS, PI/2, 131, ptNewE);
|
||
}
|
||
else{//平接,要根据接管角度而定
|
||
XPoint ptTmp;
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbEquipment, pEquip);
|
||
if(pEquip){
|
||
int num = pEquip->GetInterfaceNum();
|
||
if(num == 1){
|
||
TPipeInterface face;
|
||
pEquip->GetInterface(0, face);
|
||
AcDbObjectId idPipeTmp = face.m_idPipe;
|
||
OPENOBJ_BEGIN(idPipeTmp, AcDb::kForRead, TDbPipe, pPipeTmp);
|
||
if(pPipeTmp){
|
||
XPoint p1 = pPipeTmp->StartPoint();
|
||
XPoint p2 = pPipeTmp->EndPoint();
|
||
XPoint p11 = p1;
|
||
XPoint P22 = p2;
|
||
p1.TransformBy(mat);
|
||
p2.TransformBy(mat);
|
||
|
||
XPoint p3, p4;
|
||
p3.x = p1.x*dX + cos(nRadian)*p1.y*dY;
|
||
p3.y = p1.z*dZ + sin(nRadian)*p1.y*dY;
|
||
p4.x = p2.x*dX + cos(nRadian)*p2.y*dY;
|
||
p4.y = p2.z*dZ + sin(nRadian)*p2.y*dY;
|
||
|
||
if(p11 == ptInsert)
|
||
ptTmp = p4;
|
||
else if(P22 == ptInsert)
|
||
ptTmp = p3;
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
if(!!ptTmp){//消火栓的插入基点要偏移
|
||
double dAng3 = ads_angle(ptTmp, ptNewS);
|
||
ads_polar(ptNewS, dAng3, 131, ptNewE);
|
||
}
|
||
}
|
||
}
|
||
pNewEquip->SetSysBlock(_T(""));
|
||
pNewEquip->SetHidePipe(bIsBreak);
|
||
if(csBlkName != _T("") && _tcsicmp(_T("$TWTSYS$00000131"), csBlkName) == 0)//侧喷时多画一段小横管
|
||
{
|
||
ptNewS = Wcs2Ucs(ptNewS);
|
||
ptNewS.x -= nPipeLength/2;
|
||
ptNewS = Ucs2Wcs(ptNewS);
|
||
ptNewE = ptNewS;
|
||
}
|
||
pNewEquip->SetLocation(ptNewS);
|
||
pNewEquip->SetInsert(ptNewE);
|
||
|
||
|
||
|
||
AddToCurrentSpace(pNewEquip, Adesk::kTrue);
|
||
}
|
||
|
||
AcDbObjectId PlanLabel2Sys(AcDbObjectId id, TDbPipe *pPipe)
|
||
{
|
||
TDbPipeLabel *pNewLabel = NULL;
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipeLabel, pLabel);
|
||
pNewLabel = (TDbPipeLabel *)pLabel->clone();
|
||
OPENOBJ_END();
|
||
|
||
XPoint ptS, ptE, ptMid;
|
||
ptS = pPipe->StartPoint();
|
||
ptE = pPipe->EndPoint();
|
||
XLine line(ptS, ptE, 1);
|
||
line.MidPoint(ptMid);
|
||
pNewLabel->SetLocation(ptMid);
|
||
AcDbObjectId idNewLabel = AddToCurrentSpace(pNewLabel, Adesk::kTrue);
|
||
return idNewLabel;
|
||
|
||
}
|
||
|
||
BOOL IsValve(AcDbObjectId id)
|
||
{
|
||
BOOL ret = FALSE;
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipeValve, pEquip);
|
||
if (pEquip)
|
||
ret = TRUE;
|
||
OPENOBJ_END();
|
||
return ret;
|
||
}
|
||
|
||
BOOL IsHorAngle(double nAngle)
|
||
{
|
||
//if(nAngle >= PI*2)
|
||
if (fabs(nAngle - PI * 2) < 0.00001 || nAngle > PI * 2)
|
||
nAngle -= PI * 2;
|
||
if (fabs(nAngle) < 0.00001 || fabs(nAngle - PI) < 0.00001)
|
||
return TRUE;
|
||
else
|
||
return FALSE;
|
||
}
|
||
|
||
AcDbObjectId PlanValve2Sys(AcDbObjectId id, TDbPipe *pPipe, double nRadian, AcGeMatrix3d mat, AcGeScale3d scale,int nValveType)
|
||
{
|
||
XPoint ptStart, ptNewS;
|
||
CString csSysBlk, csSysBlk2, csSysBlk3;
|
||
CString csTK, csRecord;
|
||
|
||
double dX = scale.sx;
|
||
double dY = scale.sy;
|
||
double dZ = scale.sz;
|
||
|
||
TDbPipeValve *pNewValve = NULL;
|
||
AcDbObjectId idBlk = NULL;
|
||
double nWidth(0);
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipeValve, pValve);
|
||
pNewValve = (TDbPipeValve *)pValve->clone();
|
||
|
||
|
||
idBlk = pValve->GetBlock2d();
|
||
CString csBlkName = GetBlkNameById(idBlk);
|
||
SplitBlkStr(csBlkName, csTK, csRecord);
|
||
nWidth = pValve->GetWidth();
|
||
csSysBlk = pValve->GetSysBlock();
|
||
ptStart = pValve->GetLocation();
|
||
OPENOBJ_END();
|
||
|
||
ptStart.TransformBy(mat);
|
||
|
||
ptStart = Wcs2Ucs(ptStart); // sr 2010-1-28 modify 系统生成支持UCS
|
||
ptNewS.x = ptStart.x*dX + cos(nRadian)*ptStart.y*dY;
|
||
ptNewS.y = ptStart.z*dZ + sin(nRadian)*ptStart.y*dY;
|
||
ptNewS = Ucs2Wcs(ptNewS); // sr 2010-1-28 modify 系统生成支持UCS
|
||
|
||
pNewValve->SetLocation(ptNewS);
|
||
XPoint pt1 = pPipe->StartPoint();
|
||
XPoint pt2 = pPipe->EndPoint();
|
||
double ang = ads_angle(pt1, pt2) - Ucs2Wcs(0.0);// sr 2010-1-28 modify 系统生成支持UCS
|
||
pNewValve->SetSysBlock(_T(""));
|
||
int idx = csSysBlk.Find(_T("-"));
|
||
int idx2 = csSysBlk.Find(_T("-"), idx+1);
|
||
|
||
csSysBlk3 = csSysBlk.Right(8);
|
||
if(idx2 > -1)//平面阀门和系统阀门完全不一样 2005-5-31
|
||
csSysBlk2 = csSysBlk.Mid(idx+1, 8);
|
||
|
||
|
||
if(!IsHorAngle(ang) && csSysBlk3 != _T("")){
|
||
if(idx < 0){
|
||
pNewValve->SetBlock2d(idBlk);
|
||
pNewValve->SetWidth(nWidth);
|
||
}
|
||
else if(0 == nValveType){//lsd 2014-5-9 判断阀门样式是否为斜向
|
||
XString xsTmpSys;
|
||
CString csDwb = g_csDwbPath + csTK;
|
||
if(LoadDwbBlock(csDwb, (const TCHAR*)csSysBlk3, xsTmpSys) != RTNORM)
|
||
return NULL;
|
||
double nWidth = GetValveWidth(xsTmpSys);
|
||
pNewValve->SetWidth(nWidth);
|
||
AcDbObjectId recordId = GetBlkIdByName((const TCHAR*)xsTmpSys);
|
||
pNewValve->SetBlock2d(recordId);
|
||
}
|
||
}
|
||
else if(IsHorAngle(ang) && csSysBlk2 != _T("")){
|
||
XString xsTmpSys;
|
||
CString csDwb = g_csDwbPath + csTK;
|
||
if(LoadDwbBlock(csDwb, (const TCHAR*)csSysBlk2, xsTmpSys) != RTNORM)
|
||
return NULL;
|
||
double nWidth = GetValveWidth(xsTmpSys);
|
||
pNewValve->SetWidth(nWidth);
|
||
AcDbObjectId recordId = GetBlkIdByName((const TCHAR*)xsTmpSys);
|
||
pNewValve->SetBlock2d(recordId);
|
||
}
|
||
AcDbObjectId idNewValve = AddToCurrentSpace(pNewValve, Adesk::kTrue);
|
||
return idNewValve;
|
||
}
|
||
|
||
BOOL InvokeTkwMan(const TCHAR *pszLib, BOOL bSelOnly, XString &sBlockName)
|
||
{
|
||
if(!AT_loaded(_T("wfB"))) {
|
||
#ifndef ZWCAD
|
||
int nRet=acrxLoadModule(_T("wfB.arx"), Adesk::kTrue, true);
|
||
#else
|
||
int nRet=acrxLoadModule(_T("wfB.zrx"), Adesk::kTrue, true);
|
||
#endif
|
||
if(!nRet)
|
||
return FALSE;
|
||
}
|
||
int nCode=bSelOnly? RTT : RTNIL;
|
||
RBList rbCmd=ads_buildlist(RTSTR, _T("ITkw"), RTSTR, pszLib, nCode,
|
||
RTSTR, (const TCHAR *)sBlockName, NULL);
|
||
resbuf *rbRes=NULL;
|
||
if(ads_invoke(rbCmd, &rbRes)==RTNORM && rbRes) {
|
||
if(rbRes && rbRes->restype==RTSTR)
|
||
sBlockName=rbRes->resval.rstring;
|
||
ads_relrb(rbRes);
|
||
return TRUE;
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
CString GetTgBlkTypeInTk(const TCHAR* szBlkName)
|
||
{
|
||
CString csTk, csRecord, csRet;
|
||
CString sKind, sDrawing;
|
||
SplitBlkStr(szBlkName, csTk, csRecord);
|
||
CodeBase db;
|
||
db.read_only = 1;
|
||
CString csTmpTKName = g_sDwbPath + csTk + _T(".tk");
|
||
XDbfTable *pTable = db.Open(csTmpTKName);
|
||
if(!pTable)
|
||
return csRet;
|
||
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){
|
||
GET_FIELD(pTable, _T("Drawing"), sDrawing);
|
||
GET_FIELD(pTable, _T("kind"), sKind);
|
||
if(sDrawing == (const TCHAR *)csRecord){
|
||
csRet = (const TCHAR *)sKind;
|
||
return csRet;
|
||
}
|
||
}
|
||
return csRet;
|
||
}
|
||
|
||
SSearchPipeList *GetPipeNodeByName(SSearchPipeList *pListAll, CString csName, SSearchPipeList *pNode)
|
||
{
|
||
AcDbObjectId id = NULL;
|
||
id = pListAll->m_ID;
|
||
if(pListAll->m_iType == 0){
|
||
if(pListAll->m_csName == csName)
|
||
return pListAll;
|
||
}
|
||
long len = pListAll->m_lstNode.Length();
|
||
for(long i=0;i<len;i++){
|
||
SSearchPipeList *pList = pListAll->m_lstNode[i];
|
||
pNode = GetPipeNodeByName(pList, csName, pNode);
|
||
}
|
||
return pNode;
|
||
}
|
||
|
||
CString PlusString2(const TCHAR* szRes, int step, BOOL bIsPlus)//给MYSPIN用,他不需要对前面递增递减
|
||
{
|
||
CString csRes = szRes;
|
||
int len = csRes.GetLength();
|
||
int iIdx(0);
|
||
CString csRet = csRes;
|
||
CString csRightTmp = csRes.Right(2);
|
||
CString csChinaDigit[] = {_T("一"),_T("二"),_T("三"),_T("四"),_T("五"),_T("六"),_T("七"),_T("八"),_T("九"),_T("十"),};
|
||
CString csChinaDigit2[] = {_T("零"),_T("贰"),_T("叁"),_T("肆"),_T("伍"),_T("陆"),_T("柒"),_T("捌"),_T("玖"),_T("拾"),};
|
||
CString cs12Digit[] = {_T("Ⅰ"),_T("Ⅱ"),_T("Ⅲ"),_T("Ⅳ"),_T("Ⅴ"),_T("Ⅵ"),_T("Ⅶ"),_T("Ⅷ"),_T("Ⅸ"),_T("Ⅹ"),_T("Ⅺ"),_T("Ⅻ")};
|
||
CString csLetter[] = {_T("a"),_T("b"),_T("c"),_T("d"),_T("e"),_T("f"),_T("g"),_T("h"),_T("i"),_T("j"),_T("k"),_T("l"),_T("m"),_T("n"),_T("o"),_T("p"),_T("q"),_T("r"),_T("s"),_T("t"),_T("u"),_T("v"),_T("w"),_T("x"),_T("y"),_T("z")};
|
||
CString csLetter2[] = {_T("A"),_T("B"),_T("C"),_T("D"),_T("E"),_T("F"),_T("G"),_T("H"),_T("I"),_T("J"),_T("K"),_T("L"),_T("M"),_T("N"),_T("O"),_T("P"),_T("Q"),_T("R"),_T("S"),_T("T"),_T("U"),_T("V"),_T("W"),_T("X"),_T("Y"),_T("Z")};
|
||
for(int m=0;m<10;m++){
|
||
if(csRightTmp == csChinaDigit[m]){
|
||
CString csLeftTmp = csRes.Left(len - 2);
|
||
if(bIsPlus)
|
||
iIdx = m + step;
|
||
else
|
||
iIdx = m - step;
|
||
iIdx = (iIdx+10) % 10;
|
||
csRightTmp = csChinaDigit[iIdx];
|
||
csRet.Format(_T("%s%s"), csLeftTmp, csRightTmp);
|
||
return csRet;
|
||
}
|
||
}
|
||
for(m=0;m<10;m++){
|
||
if(csRightTmp == csChinaDigit2[m]){
|
||
CString csLeftTmp = csRes.Left(len - 2);
|
||
if(bIsPlus)
|
||
iIdx = m + step;
|
||
else
|
||
iIdx = m - step;
|
||
iIdx = (iIdx+10) % 10;
|
||
csRightTmp = csChinaDigit2[iIdx];
|
||
csRet.Format(_T("%s%s"), csLeftTmp, csRightTmp);
|
||
return csRet;
|
||
}
|
||
}
|
||
for(m=0;m<12;m++){
|
||
if(csRightTmp == cs12Digit[m]){
|
||
CString csLeftTmp = csRes.Left(len - 2);
|
||
if(bIsPlus)
|
||
iIdx = m + step;
|
||
else
|
||
iIdx = m - step;
|
||
iIdx = (iIdx+12) % 12;
|
||
csRightTmp = cs12Digit[iIdx];
|
||
csRet.Format(_T("%s%s"), csLeftTmp, csRightTmp);
|
||
return csRet;
|
||
}
|
||
}
|
||
for(m=0;m<26;m++){
|
||
csRightTmp = csRes.Right(1);
|
||
if(csRightTmp == csLetter[m]){
|
||
CString csLeftTmp = csRes.Left(len - 1);
|
||
if(bIsPlus)
|
||
iIdx = m + step;
|
||
else
|
||
iIdx = m - step;
|
||
iIdx = (iIdx+26) % 26;
|
||
csRightTmp = csLetter[iIdx];
|
||
csRet.Format(_T("%s%s"), csLeftTmp, csRightTmp);
|
||
return csRet;
|
||
}
|
||
}
|
||
for(m=0;m<26;m++){
|
||
csRightTmp = csRes.Right(1);
|
||
if(csRightTmp == csLetter2[m]){
|
||
CString csLeftTmp = csRes.Left(len - 1);
|
||
if(bIsPlus)
|
||
iIdx = m + step;
|
||
else
|
||
iIdx = m - step;
|
||
iIdx = (iIdx+26) % 26;
|
||
csRightTmp = csLetter2[iIdx];
|
||
csRet.Format(_T("%s%s"), csLeftTmp, csRightTmp);
|
||
return csRet;
|
||
}
|
||
}
|
||
|
||
for(int i=1;i<=len;i++){
|
||
CString csRight = csRes.Right(i);
|
||
if(i == 1){
|
||
TCHAR c = csRight[0];
|
||
if(!_istdigit(c))
|
||
break;
|
||
}
|
||
BOOL bIsAllZ = TRUE;
|
||
int lenRight = csRight.GetLength();
|
||
for(int j=0;j<lenRight;j++){
|
||
CString csTmp = csRight[j];
|
||
if(csTmp != _T("0")){
|
||
bIsAllZ = FALSE;
|
||
break;
|
||
}
|
||
}
|
||
if(bIsAllZ)
|
||
continue;
|
||
CString csLeft = csRes.Left(len - i);
|
||
int val = _ttoi(csRight);
|
||
if(val <= 0) // SR MODIFY if(val == 0)
|
||
break;
|
||
|
||
if(bIsPlus){
|
||
val += step;
|
||
if(val < 1)
|
||
val = 1;
|
||
}
|
||
else{
|
||
val -= step;
|
||
if(val < 1)
|
||
val = 1;
|
||
}
|
||
csRet.Format(_T("%s%d"), csLeft, val);
|
||
}
|
||
|
||
return csRet;
|
||
}
|
||
|
||
BOOL CalcLstPipeLength(SSearchPipeList *pListAll, SSearchPipeList *pListFront, PickSet &ss)
|
||
{
|
||
BOOL ret = TRUE;
|
||
AcDbObjectId id = NULL;
|
||
id = pListAll->m_ID;
|
||
ads_name ent;
|
||
double nCurPipeLength(0);
|
||
acdbGetAdsName(ent, id);
|
||
if(pListAll->m_iType == 2){
|
||
Entity entTmp = ent;
|
||
int iK = _ttoi(ReadXdata(entTmp, _T("SPRINKLER_K")));
|
||
pListAll->m_iSpare = iK;
|
||
if(entTmp.In(&ss))
|
||
pListAll->m_bNeedCale = TRUE;
|
||
}
|
||
else if(pListAll->m_iType == 0){
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe);
|
||
if(pPipe){
|
||
int iDn = (int)(pPipe->GetDnDiameter());
|
||
pListAll->m_iDn = iDn;
|
||
double nGradient = pPipe->GetPipeGradient();
|
||
pListAll->m_nI = nGradient*1000;
|
||
nCurPipeLength = pPipe->Length();
|
||
pListAll->m_nLength = nCurPipeLength;
|
||
if(pPipe->GetDnDiameter() < 0 && !pPipe->IsVertical())
|
||
return FALSE;
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
if(pListFront)
|
||
pListAll->m_nLength += pListFront->m_nLength;
|
||
|
||
long len = pListAll->m_lstNode.Length();
|
||
for(long i=0;i<len;i++){
|
||
SSearchPipeList *pList = pListAll->m_lstNode[i];
|
||
pList->m_pPrevious = pListAll;
|
||
ret = CalcLstPipeLength(pList, pListAll, ss);
|
||
if(!ret)
|
||
return FALSE;
|
||
}
|
||
return ret;
|
||
}
|
||
|
||
double GetPipeGradient(Entity ent)
|
||
{
|
||
double nGradient(0);
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe);
|
||
if(pPipe && !pPipe->IsVertical()){
|
||
nGradient = pPipe->GetPipeGradient();
|
||
if(nGradient > 10) //sr 2011-1-26 从大于1改为大于10,坡度还是有大于1的,但几乎没有大于10的。GetPipeGradient调的是小圆半径的值
|
||
nGradient = 0;
|
||
}
|
||
OPENOBJ_END();
|
||
return nGradient;
|
||
}
|
||
|
||
double GetInsRotate(XPoint ptIns, XCurveSegment seg)
|
||
{
|
||
if(seg.Is(CURVE_LINE)){
|
||
double ang = ads_angle(seg.StartPoint(), seg.EndPoint());
|
||
if(ang > PI)
|
||
ang -= PI;
|
||
return ang;
|
||
}
|
||
else if(seg.Is(CURVE_ARC)){
|
||
XArc arc = seg.GetArc();
|
||
double angle = ads_angle(ptIns, arc.GetCenterPt());
|
||
angle -= PI/2;
|
||
return angle;
|
||
}
|
||
else if(seg.Is(CURVE_CIRCLE)){
|
||
XCircle cir = seg.GetCircle();
|
||
double angle = ads_angle(ptIns, cir.GetCenterPt());
|
||
angle -= PI/2;
|
||
return angle;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
int GetNextDrawing(const TCHAR *tkName, TCHAR *dwg)
|
||
{
|
||
CodeBase db;
|
||
XDbfTable *pTable = db.Open(tkName);
|
||
if(!pTable)
|
||
{
|
||
CString csTmp;
|
||
csTmp.Format(_T("%s文件只读或损坏!"), tkName);
|
||
AfxMessageBox(csTmp);
|
||
|
||
// AfxMessageBox(_T("TK文件只读或损坏!"));
|
||
return RTERROR;
|
||
}
|
||
Array<CString> recs;
|
||
CString str;
|
||
CString sTemp;
|
||
for (pTable->MoveFirst(0);!pTable->IsEOF();pTable->MoveNext(0))
|
||
{
|
||
GET_FIELD(pTable,_T("Drawing"), sTemp);
|
||
str = sTemp;
|
||
if (IsDigital(str)&&_tcslen(str)==8)
|
||
recs.AddTail(LPCTSTR(str));
|
||
}
|
||
if (recs.GetLength() >= 1)
|
||
{
|
||
CString maxStr = recs[0];
|
||
int i = 1;
|
||
while (i < recs.GetLength())
|
||
{
|
||
if (maxStr<recs[i])
|
||
maxStr = recs[i];
|
||
i++;
|
||
}
|
||
if(maxStr && IsDigital(maxStr))
|
||
{
|
||
int slen = (int)_tcslen(maxStr);
|
||
TCHAR a1=maxStr[slen-1], a2=maxStr[slen-2], a3=maxStr[slen-3],a4 = maxStr[slen-4],a5 = maxStr[slen-5],a6 = maxStr[slen-6];
|
||
if(a1>=_T('0') && a1<_T('9')) a1++;
|
||
else if(a1==_T('9') && a2>=_T('0') && a2<_T('9'))
|
||
{ a1=_T('0'); a2++; }
|
||
else if(a1==_T('9') && a2==_T('9') && a3>=_T('0') && a3<_T('9'))
|
||
{ a1=a2=_T('0'); a3++; }
|
||
else if(a1==_T('9') && a2==_T('9') && a3==_T('9') && a4>=_T('0') &&a4<_T('9'))
|
||
{ a1=a2=a3=_T('0'); a4++; }
|
||
else if(a1==_T('9') && a2==_T('9') && a3==_T('9') && a4==_T('9') && a5>=_T('0')&&a5<_T('9'))
|
||
{ a1=a2=a3=a4=_T('0'); a5++; }
|
||
else if(a1==_T('9') && a2==_T('9') && a3==_T('9') && a4==_T('9') && a5==_T('9')&&a6>=_T('0')&&a6<_T('9'))
|
||
{a1=a2=a3=a4=a5=_T('0'); a6++; }
|
||
maxStr.Delete(slen-6,6);
|
||
maxStr = maxStr + a6;
|
||
maxStr = maxStr + a5;
|
||
maxStr = maxStr + a4;
|
||
maxStr = maxStr + a3;
|
||
maxStr = maxStr + a2;
|
||
maxStr = maxStr + a1;
|
||
_tcscpy(dwg, maxStr);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_tcscpy(dwg, _T("00000001"));
|
||
return RTNORM;
|
||
}
|
||
return RTNORM;
|
||
}
|
||
|
||
CString AddNewDwg2Dwb(const TCHAR* szTKName,
|
||
const TCHAR* szDwgName,
|
||
const TCHAR* szSldName,
|
||
const TCHAR* szType,
|
||
const TCHAR* szDesName)
|
||
{
|
||
|
||
CString csTKName = szTKName;
|
||
CString csDwgName = szDwgName;
|
||
CString csSldName = szSldName;
|
||
CString csType = szType;
|
||
CString csDesName = szDesName;
|
||
|
||
int len = csTKName.GetLength();
|
||
CString csDwbFileName = csTKName.Left(len - 2) + _T("dwb");
|
||
CString csSlbFileName = csTKName.Left(len - 2) + _T("slb");
|
||
XString xsRetStr;
|
||
CString csErr = _T("");
|
||
|
||
CodeBase db;
|
||
XDbfTable *pTable = db.Open(csTKName);
|
||
if (!pTable) {
|
||
CString csTmp;
|
||
csTmp.Format(_T("%s文件只读或损坏!"), csTKName);
|
||
AfxMessageBox(csTmp);
|
||
|
||
// AfxMessageBox(_T("TK文件只读或损坏!"));
|
||
return csErr;
|
||
}
|
||
|
||
if (GetNextDrawing((const TCHAR*)csTKName, xsRetStr) != RTNORM) {
|
||
AfxMessageBox(_T("无法向DWB中增加记录"));
|
||
return csErr;
|
||
}
|
||
|
||
XString xsNewDwgName, xsNewSldName;
|
||
XFilePathName xfpn = (LPCTSTR)csDwgName;
|
||
|
||
xsNewDwgName << (const TCHAR*)xfpn.getDriver()
|
||
<< (const TCHAR*)xfpn.getDir() << (const TCHAR*)xsRetStr << _T(".dwg");
|
||
xsNewSldName << (const TCHAR*)xfpn.getDriver()
|
||
<< (const TCHAR*)xfpn.getDir() << (const TCHAR*)xsRetStr << _T(".sld");
|
||
// xsNewDwgName << (const TCHAR*)xfpn.getDriver()
|
||
// << (const TCHAR*)xfpn.getDir() << _T("\\") << (const TCHAR*)xsRetStr << _T(".dwg");
|
||
// xsNewSldName << (const TCHAR*)xfpn.getDriver()
|
||
// << (const TCHAR*)xfpn.getDir() << _T("\\") << (const TCHAR*)xsRetStr << _T(".sld");
|
||
|
||
XSlideLib slbMan(csSlbFileName);
|
||
if (!slbMan) {
|
||
AfxMessageBox(_T("无法打开Slb文件"));
|
||
return csErr;
|
||
_tremove(csSldName);
|
||
}
|
||
int ret;
|
||
_trename(csSldName, xsNewSldName);
|
||
ret = slbMan.Append(xsNewSldName);
|
||
slbMan.Close();
|
||
_tremove(xsNewSldName);
|
||
|
||
XDrawingLib dwbMan(csDwbFileName);
|
||
if (!dwbMan) {
|
||
AfxMessageBox(_T("无法打开DWB文件"));
|
||
return csErr;
|
||
_tremove(csDwgName);
|
||
}
|
||
_trename(csDwgName, xsNewDwgName);
|
||
|
||
ret = dwbMan.Append(xsNewDwgName);
|
||
|
||
|
||
dwbMan.Close();
|
||
_tremove(xsNewDwgName);
|
||
|
||
|
||
|
||
pTable->AppendBegin();
|
||
SET_FIELD(pTable, _T("kind"), (const TCHAR*)csType);
|
||
SET_FIELD(pTable, _T("item"), (const TCHAR*)csDesName);
|
||
SET_FIELD(pTable, _T("Drawing"), (const TCHAR*)xsRetStr);
|
||
pTable->AppendEnd();
|
||
pTable->Close(); //sr add 11.15
|
||
CString csRet = (const TCHAR*)xsRetStr;
|
||
return csRet;
|
||
|
||
}
|
||
|
||
int GetPipeLayerIdxBySys(TPipeSys::SysType sys)
|
||
{
|
||
int iRet = -1;
|
||
if(sys == TPipeSys::kFeedWater)
|
||
iRet = 0;
|
||
else if(sys == TPipeSys::kHeatFeedWater)
|
||
iRet = 1;
|
||
else if(sys == TPipeSys::kHeatBackWater)
|
||
iRet = 2;
|
||
else if(sys == TPipeSys::kDirtWater)
|
||
iRet = 3;
|
||
else if(sys == TPipeSys::kUselessWater)
|
||
iRet = 4;
|
||
else if(sys == TPipeSys::kRainWater)
|
||
iRet = 5;
|
||
else if(sys == TPipeSys::kUsedWater)
|
||
iRet = 6;
|
||
else if(sys == TPipeSys::kFireFighting)
|
||
iRet = 7;
|
||
else if(sys == TPipeSys::kSprinkle)
|
||
iRet = 8;
|
||
else if(sys == TPipeSys::kCoagulate)
|
||
iRet = 9;
|
||
else if(sys == TPipeSys::kDrink)
|
||
iRet = 10;
|
||
else if(sys == TPipeSys::kPressDirt)
|
||
iRet = 11;
|
||
else if(sys == TPipeSys::kPressUseless)
|
||
iRet = 12;
|
||
else if(sys == TPipeSys::kPressRain)
|
||
iRet = 13;
|
||
else if(sys == TPipeSys::kOther)
|
||
iRet = 14;
|
||
else if(sys == TPipeSys::kCivilFeed)
|
||
iRet = 15;
|
||
else if(sys == TPipeSys::kCycleFeed)
|
||
iRet = 16;
|
||
else if(sys == TPipeSys::kFeedWater2)
|
||
iRet = 17;
|
||
else if(sys == TPipeSys::kFeedWater3)
|
||
iRet = 18;
|
||
else if(sys == TPipeSys::kHeatFeedWater2)
|
||
iRet = 19;
|
||
else if(sys == TPipeSys::kHeatFeedWater3)
|
||
iRet = 20;
|
||
else if(sys == TPipeSys::kHeatBackWater2)
|
||
iRet = 21;
|
||
else if(sys == TPipeSys::kHeatBackWater3)
|
||
iRet = 22;
|
||
else if(sys == TPipeSys::kFireFighting2)
|
||
iRet = 23;
|
||
else if(sys == TPipeSys::kFireFighting3)
|
||
iRet = 24;
|
||
else if(sys == TPipeSys::kSprinkle2)
|
||
iRet = 25;
|
||
else if(sys == TPipeSys::kSprinkle3)
|
||
iRet = 26;
|
||
else if(sys == TPipeSys::kUsedWater2)
|
||
iRet = 27;
|
||
else if(sys == TPipeSys::kUsedWater3)
|
||
iRet = 28;
|
||
else if(sys == TPipeSys::kUser3)
|
||
iRet = 29;
|
||
else if(sys == TPipeSys::kUser4)
|
||
iRet = 30;
|
||
else if(sys == TPipeSys::kUser5)
|
||
iRet = 31;
|
||
else if(sys == TPipeSys::kUser6)
|
||
iRet = 32;
|
||
else if(sys == TPipeSys::kUser7)
|
||
iRet = 33;
|
||
else if(sys == TPipeSys::kUser8)
|
||
iRet = 34;
|
||
return iRet;
|
||
}
|
||
|
||
BOOL GetRelationFromDnToV(DList<CTempStruct> &lstDn)
|
||
{
|
||
|
||
XString fullFile;
|
||
if(!FindFile(_T("datastore.dbf"), fullFile)) {
|
||
AfxMessageBox(_T("对不起,没有发现datastore.dbf文件!"));
|
||
return 0;
|
||
}
|
||
CodeBase db;
|
||
db.read_only = 1;
|
||
XDbfTable *pTable = db.Open(fullFile);
|
||
if(!pTable)
|
||
return 0;
|
||
int nType = 0,nRowCount = 0;
|
||
CString strName = _T(""),strValue = _T("");
|
||
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext())
|
||
{
|
||
GET_FIELD(pTable, _T("typenumber"), nType);
|
||
if (nType == 42)
|
||
{
|
||
GET_FIELD(pTable, _T("typename"), strName);
|
||
GET_FIELD(pTable, _T("typevalue"), strValue);
|
||
int iDn = _ttoi(strName);
|
||
double dValue = _tstof(strValue);
|
||
CTempStruct *pData = new CTempStruct;
|
||
pData->m_iTmp = iDn;
|
||
pData->m_dTmp = dValue;
|
||
lstDn.Append(pData);
|
||
|
||
|
||
|
||
}
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
int GetPipeDnByQ(double nQ, AcDbObjectId id, double &nLost, double &nI, double &nSpeed, BOOL bIsReCalc)
|
||
{
|
||
double nLength(-1);
|
||
int nRet(-1);
|
||
int iMat(-1);
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipe, pPipe);
|
||
if(pPipe){
|
||
iMat = pPipe->GetMaterial();
|
||
nLength = pPipe->Length();
|
||
if(bIsReCalc)
|
||
nRet = (int)pPipe->GetDnDiameter();
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
CString csMat = GetPipeMaterialByIdx(iMat);
|
||
double nCh(0); // 海澄-威廉系数
|
||
if(csMat == _T("镀锌钢管") || csMat == _T("给水铸铁管") || csMat == _T("排水铸铁管") || csMat == _T("焊接钢管") || csMat == _T("无缝钢管"))
|
||
nCh = 100;
|
||
else
|
||
nCh = 140;
|
||
DList<int> lstSpec;
|
||
GetPipeSpecList(lstSpec, csMat);
|
||
// Q = 1/4 * PI * Dj * Dj * V
|
||
nQ = nQ / 1000;
|
||
|
||
if(bIsReCalc) //复算
|
||
{
|
||
|
||
double nRetDj = GetPipeDjByDn(csMat, nRet);
|
||
nSpeed = nQ / (0.25*PI*nRetDj*nRetDj);
|
||
if(nRetDj < 0)
|
||
return nRet;
|
||
nI = 105 * (pow(nRetDj, -4.87)) * (pow(nQ, 1.85)) * (pow(nCh, -1.85)) / 10;
|
||
nLost = nI * nLength;
|
||
}
|
||
else
|
||
{
|
||
DList<CTempStruct> lstDn;
|
||
|
||
GetRelationFromDnToV(lstDn);
|
||
|
||
lstDn.QuickSort(CTempStruct::SortByInt);
|
||
|
||
|
||
// <<建筑给排水规范》2003,P35 表3.6.9
|
||
for(int j=0;j<lstSpec.Length();j++){
|
||
int iDnTmp = *lstSpec[j];
|
||
double nRetDj = GetPipeDjByDn(csMat, iDnTmp);
|
||
nSpeed = nQ / (0.25*PI*nRetDj*nRetDj);
|
||
if(nRetDj < 0)
|
||
continue;
|
||
nI = 105 * (pow(nRetDj, -4.87)) * (pow(nQ, 1.85)) * (pow(nCh, -1.85)) / 10;
|
||
nLost = nI * nLength;
|
||
|
||
int len = lstDn.Length();
|
||
for(int i=0;i<len;i++)
|
||
{
|
||
int iTmp = lstDn[i]->m_iTmp;
|
||
double dTmp = lstDn[i]->m_dTmp;
|
||
dTmp+= 0.001;
|
||
if(iTmp >= iDnTmp || (iTmp == 80 && iDnTmp > 80))//if(iTmp >= iDnTmp) 2009-12-17 sr 修改。王峻发现bug,管线超过80系统就无法处理了
|
||
{
|
||
if(nSpeed < dTmp)
|
||
return iDnTmp;
|
||
break;
|
||
}
|
||
}
|
||
|
||
// if(iDnTmp <= 20 && nSpeed <= 1)
|
||
// return iDnTmp;
|
||
// else if(iDnTmp <= 40 && iDnTmp > 20 && nSpeed <= 1.2)
|
||
// return iDnTmp;
|
||
// else if(iDnTmp < 80 && iDnTmp > 40 && nSpeed <= 1.5)
|
||
// return iDnTmp;
|
||
// else if(iDnTmp >= 80 && nSpeed <= 1.8)
|
||
// return iDnTmp;
|
||
}
|
||
}
|
||
|
||
return nRet;
|
||
}
|
||
|
||
AcDbObjectId LoadTgLineType(const TCHAR* szLineType)
|
||
{
|
||
AcDbObjectId id=GetLinetypeIdFromString2(szLineType);
|
||
if(id != NULL)
|
||
return id;
|
||
|
||
XString xsDbfFile;
|
||
if(!FindFile(_T("linetype.dbf"), xsDbfFile)) {
|
||
AfxMessageBox(_T("对不起,没有发现linetype.dbf文件!"));
|
||
return id;
|
||
}
|
||
CodeBase db;
|
||
XDbfTable *pTable = db.Open(xsDbfFile);
|
||
if(!pTable) {
|
||
CString csTmp;
|
||
csTmp.Format(_T("%s文件只读或损坏!"), xsDbfFile);
|
||
AfxMessageBox(csTmp);
|
||
|
||
// AfxMessageBox(_T("TK文件只读或损坏!"));
|
||
return id;
|
||
}
|
||
|
||
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){
|
||
CString sName, sComment, sContent, sNum, sFit, sLength;
|
||
GET_FIELD(pTable, _T("Name"), sName);
|
||
if(_tcsicmp(sName, szLineType) == 0){
|
||
GET_FIELD(pTable, _T("Comment"), sComment);
|
||
GET_FIELD(pTable, _T("Num"), sNum);
|
||
GET_FIELD(pTable, _T("Scale"), sFit);
|
||
GET_FIELD(pTable, _T("Length"), sLength);
|
||
GET_FIELD(pTable, _T("Content"), sContent);
|
||
bool bFit;
|
||
if(sFit == _T("1"))
|
||
bFit = true;
|
||
else
|
||
bFit = false;
|
||
LoadLineType((const TCHAR*)sName, (const TCHAR*)sComment, _ttoi(sNum), bFit, _tstof(sLength), (const TCHAR*)sContent);
|
||
id=GetLinetypeIdFromString2((const TCHAR*)sName);
|
||
break;
|
||
}
|
||
}
|
||
return id;
|
||
}
|
||
|
||
AcDbObjectId InitDoteLayer(const TCHAR* szLay)
|
||
{
|
||
AcDbObjectId idLay=GetLayerIdFromString(szLay);
|
||
if(!!idLay)
|
||
return idLay;
|
||
|
||
AcDbObjectId id = InitLayer(szLay);
|
||
AddLineType(_T("CENTER2"));
|
||
AcDbLinetypeTable *pLinetypeTbl;
|
||
AcDbObjectId ltId;
|
||
Acad::ErrorStatus es = acdbCurDwg()->getLinetypeTable(pLinetypeTbl, AcDb::kForRead);
|
||
if(es != Acad::eOk) {
|
||
return NULL;
|
||
}
|
||
if((pLinetypeTbl->getAt(_T("CENTER2"), ltId)) != Acad::eOk){
|
||
pLinetypeTbl->close();
|
||
return NULL;
|
||
}
|
||
pLinetypeTbl->close();
|
||
|
||
OPENOBJ_BEGIN(id, AcDb::kForWrite, AcDbLayerTableRecord, pRec);
|
||
if(pRec){
|
||
pRec->setLinetypeObjectId(ltId);
|
||
}
|
||
OPENOBJ_END();
|
||
return id;
|
||
}
|
||
|
||
void GetPipeSpecList(DList<int> &lstSpec, const TCHAR* szMat)
|
||
{
|
||
CodeBase db;
|
||
XString fullFile;
|
||
if(!FindFile(_T("pipe.dbf"), fullFile)) {
|
||
AfxMessageBox(_T("对不起,没有发现pipe.dbf文件!"));
|
||
return;
|
||
}
|
||
XDbfTable *pTable = db.Open(fullFile);
|
||
if(!pTable)
|
||
return;
|
||
CString csMaterial;
|
||
int iDn(0);
|
||
|
||
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){
|
||
GET_FIELD(pTable, _T("GC"), csMaterial);
|
||
GET_FIELD(pTable, _T("DN"), iDn);
|
||
if(_tcsicmp((const TCHAR*)csMaterial, szMat) == 0 ){
|
||
int *iTmp = new int(iDn);
|
||
lstSpec.Append(iTmp);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
BOOL IsSprinkler(Entity ent)
|
||
{
|
||
if(!ent)
|
||
return FALSE;
|
||
AcDbObjectId idBlk = NULL;
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbEquipment, pEquip);
|
||
if(pEquip)
|
||
idBlk = pEquip->GetBlock2d();
|
||
else
|
||
return FALSE;
|
||
OPENOBJ_END();
|
||
|
||
XString xsTmp1 = _T("$twtsys$00000125");
|
||
XString xsTmp2 = _T("$twtsys$00000128");
|
||
XString xsTmp3 = _T("$twtsys$00000129");
|
||
XString xsTmp4 = _T("$twtsys$00000131");
|
||
XString xsTmp5 = _T("$twtsys$00000283");
|
||
XString xsTmp6 = _T("$twtsys$00000126");
|
||
XString xsTmp7 = _T("$twtsys$00000130");
|
||
XString xsTmp8 = _T("$twtsys$00000529");
|
||
|
||
XString xsTmp9 = _T("$twtsys$00000540"); //CET 2012-1-6 ADD
|
||
XString xsTmp10 = _T("$twtsys$00000541");
|
||
XString xsTmp11 = _T("$twtsys$00000542");
|
||
const TCHAR *szBlkName = NULL;
|
||
OPENOBJ_BEGIN(idBlk, AcDb::kForRead, AcDbBlockTableRecord, pRecord);
|
||
if(pRecord){
|
||
pRecord->getName(szBlkName);
|
||
}
|
||
OPENOBJ_END();
|
||
if(_tcsicmp(szBlkName, xsTmp2) == 0 || _tcsicmp(szBlkName, xsTmp1) == 0 ||
|
||
_tcsicmp(szBlkName, xsTmp4) == 0 || _tcsicmp(szBlkName, xsTmp3) == 0||
|
||
_tcsicmp(szBlkName, xsTmp7) == 0 ||_tcsicmp(szBlkName, xsTmp5) == 0 ||
|
||
_tcsicmp(szBlkName, xsTmp9) == 0 ||_tcsicmp(szBlkName, xsTmp10) == 0 ||_tcsicmp(szBlkName, xsTmp11) == 0 ||
|
||
_tcsicmp(szBlkName, xsTmp6) == 0 || _tcsicmp(szBlkName, xsTmp8) == 0) //是喷头
|
||
return TRUE;
|
||
else
|
||
return FALSE;
|
||
}
|
||
|
||
BOOL IsTgBlkExist(const TCHAR* szBlkName)
|
||
{
|
||
CString csTk, csRecord;
|
||
CString sDrawing;
|
||
SplitBlkStr(szBlkName, csTk, csRecord);
|
||
CodeBase db;
|
||
db.read_only = 1;
|
||
CString csTmpTKName = g_sDwbPath + csTk + _T(".tk");
|
||
XDbfTable *pTable = db.Open(csTmpTKName);
|
||
if(!pTable)
|
||
return FALSE;
|
||
for(pTable->MoveFirst();!pTable->IsEOF();pTable->MoveNext()){
|
||
GET_FIELD(pTable, _T("Drawing"), sDrawing);
|
||
if(sDrawing == (const TCHAR *)csRecord){
|
||
return TRUE;
|
||
}
|
||
}
|
||
return FALSE;
|
||
}
|
||
|
||
BOOL SetLayerOnOff(const TCHAR*szLayerName, BOOL bOpen)
|
||
{
|
||
AcDbLayerTable *pLayertable = NULL;
|
||
AcDbLayerTableRecord *pLayerRec = NULL;
|
||
acdbCurDwg()->getLayerTable(pLayertable, AcDb::kForRead);
|
||
if(!pLayertable)
|
||
return FALSE;
|
||
|
||
if((pLayertable->getAt(szLayerName, pLayerRec, AcDb::kForWrite)) == Acad::eOk) {
|
||
if(bOpen)
|
||
pLayerRec->setIsOff(Adesk::kFalse); // 打开
|
||
else
|
||
pLayerRec->setIsOff(Adesk::kTrue); // 关
|
||
pLayerRec->close();
|
||
pLayertable->close();
|
||
}
|
||
else
|
||
pLayertable->close();
|
||
return TRUE;
|
||
}
|
||
|
||
BOOL StringAnalysis(const TCHAR *src, XString &sPrefix, int *num, int *numWidth)
|
||
{
|
||
ASSERT(src && num && numWidth);
|
||
int nLen = (int)_tcslen(src);
|
||
if(!nLen)
|
||
return FALSE;
|
||
int iNumPos=nLen;
|
||
for(int iPos=nLen-1; iPos>=0; iPos--) {
|
||
if(!_istdigit(src[iPos]))
|
||
break;
|
||
else iNumPos=iPos;
|
||
}
|
||
if(iNumPos==nLen) {
|
||
*numWidth=0; //No digit
|
||
} else {
|
||
if(iNumPos>0) {
|
||
XString sTemp;
|
||
sTemp=src;
|
||
StrCpy(sTemp, src, src+iNumPos);
|
||
sPrefix=sTemp;
|
||
} else {
|
||
sPrefix=_T("");
|
||
}
|
||
if(iNumPos==nLen-1) {
|
||
*numWidth=-1;
|
||
} else {
|
||
if(src[iNumPos]==_T('0')) {
|
||
*numWidth=nLen - (int)_tcslen(sPrefix);
|
||
} else {
|
||
*numWidth=-1;
|
||
}
|
||
}
|
||
*num=_ttoi(src+iNumPos);
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
void GetAllVertPipeByPt(PickSet &ss, AcDbObjectId id)
|
||
{
|
||
RBList rbMaskPipe(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管")), NULL);
|
||
XPoint ptPipeStart;
|
||
CString csLayer;
|
||
double nDn(0);
|
||
|
||
XPoint pt;
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipe, pPipe);
|
||
if(pPipe){
|
||
ptPipeStart = pPipe->StartPoint();
|
||
ptPipeStart.z = 0;
|
||
pt = ptPipeStart;
|
||
nDn = pPipe->GetDnDiameter();
|
||
TCHAR *layer;
|
||
layer = pPipe->layer();
|
||
csLayer = layer;
|
||
delete [] layer;
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
XPoint ptUcs = Wcs2Ucs(pt);
|
||
PickSet ssAll(SS_FREE);
|
||
GetPointPickSet(ptUcs, ssAll, rbMaskPipe, 50);
|
||
if(ssAll.Length() == 0)
|
||
GetPointPickSet(ptUcs, ssAll, rbMaskPipe, 100);
|
||
if(ssAll.Length() == 0)
|
||
GetPointPickSet(ptUcs, ssAll, rbMaskPipe, 200);
|
||
if(ssAll.Length() == 0)
|
||
GetPointPickSet(ptUcs, ssAll, rbMaskPipe, 300);
|
||
|
||
|
||
long len = ssAll.Length();
|
||
for(long i=0;i<len;i++){
|
||
Entity ent = ssAll[i];
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe);
|
||
if(pPipe && pPipe->IsVertical()){
|
||
XPoint ptStart = pPipe->StartPoint();
|
||
ptStart.z = 0;
|
||
if(ptStart != ptPipeStart)
|
||
continue;
|
||
double nDn2 = pPipe->GetDnDiameter();
|
||
if(fabs(nDn2 - nDn) > 0.0001)
|
||
continue;
|
||
TCHAR *layer;
|
||
layer = pPipe->layer();
|
||
CString csLayer2 = layer;
|
||
delete [] layer;
|
||
if(csLayer2 == csLayer)
|
||
ss += ent;
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
}
|
||
if(ss.Length() == 0)
|
||
ss += id;
|
||
return;
|
||
}
|
||
BOOL AddLineType(const TCHAR*szLineType)
|
||
{
|
||
BOOL bHasIt;
|
||
AcDbLinetypeTable *pLinetypeTbl;
|
||
acdbCurDwg()->getLinetypeTable(pLinetypeTbl, AcDb::kForRead);
|
||
bHasIt = pLinetypeTbl->has(szLineType);
|
||
pLinetypeTbl->close();
|
||
|
||
CString csSysPath = g_sAppPath;
|
||
csSysPath = csSysPath.Left(csSysPath.GetLength() - 7) + _T("\\sys\\");
|
||
|
||
CString csPath = csSysPath;
|
||
CString csLineFile = csPath + _T("ACAD.lin");
|
||
CString csLineFileISO = csPath + _T("ACADISO.lin");
|
||
if (!bHasIt) {
|
||
if (acdbLoadLineTypeFile(szLineType, csLineFile, acdbCurDwg()) == Acad::eOk)
|
||
bHasIt = TRUE;
|
||
else if (acdbLoadLineTypeFile(szLineType, csLineFileISO, acdbCurDwg()) == Acad::eOk)
|
||
bHasIt = TRUE;
|
||
else
|
||
Callme(_T("加载acad.lin不成功!"));
|
||
}
|
||
|
||
return bHasIt;
|
||
}
|
||
|
||
BOOL AddLineType(CString csText, double nLen, double nDist, double nDist2, double nDist3, double nScale, double nRotate)
|
||
{
|
||
|
||
AcDbObjectId idTextStyle = InitLineTypeTextStyle();
|
||
|
||
|
||
CString csLineTypeName = _T("TG_") + csText;
|
||
if (csText == _T("/") && nDist2 < 0.001)
|
||
csLineTypeName = _T("TG_/明");
|
||
else if (csText == _T("/") && nDist2 > 0.001)
|
||
csLineTypeName = _T("TG_/暗");
|
||
else if (csText == _T("\\"))
|
||
csLineTypeName = _T("TG_\");
|
||
else if (csText == _T("×"))
|
||
idTextStyle = InitLineTypeTextStyle_Thunder();
|
||
|
||
CString csLineTypeDes;
|
||
csLineTypeDes.Format(_T("----%s----%s----"), csText, csText);
|
||
if (csText == _T("/") && nDist2 > 0.001)
|
||
csLineTypeDes.Format(_T("---- %s ---- %s ----"), csText, csText);
|
||
|
||
AcDbLinetypeTable *pLinetypeTbl = NULL;
|
||
acdbCurDwg()->getLinetypeTable(pLinetypeTbl, AcDb::kForWrite);
|
||
BOOL bHasIt = pLinetypeTbl->has((const TCHAR*)csLineTypeName);
|
||
if (bHasIt) {
|
||
pLinetypeTbl->close();
|
||
adsout << _T("\n已经存在同名线型!");
|
||
return FALSE;
|
||
}
|
||
// AcDbObjectId idTextStyle = GetTextStyleId(g_csLineTypeStyle);
|
||
AcDbLinetypeTableRecord* newRec = new AcDbLinetypeTableRecord;
|
||
newRec->setName(csLineTypeName);
|
||
const TCHAR* szName;
|
||
newRec->getName(szName);
|
||
if (_tcsicmp(szName, _T("")) == 0) {
|
||
pLinetypeTbl->close();
|
||
adsout << _T("\n线形名非法,建议使用全角!");
|
||
delete newRec;
|
||
return FALSE;
|
||
}
|
||
newRec->setAsciiDescription(csLineTypeDes);
|
||
newRec->setPatternLength(nLen + nDist2);
|
||
newRec->setNumDashes(3);
|
||
newRec->setIsScaledToFit(FALSE);
|
||
|
||
newRec->setDashLengthAt(0, nLen);
|
||
newRec->setDashLengthAt(1, -nDist2);
|
||
newRec->setDashLengthAt(2, -0.00);
|
||
newRec->setShapeStyleAt(1, idTextStyle);
|
||
newRec->setTextAt(1, csText);
|
||
newRec->setShapeScaleAt(1, nScale);
|
||
newRec->setShapeRotationAt(1, nRotate);
|
||
AcGeVector2d vt(-nDist, -nDist3);
|
||
newRec->setShapeOffsetAt(1, vt);
|
||
|
||
pLinetypeTbl->add(newRec);
|
||
newRec->close();
|
||
pLinetypeTbl->close();
|
||
return TRUE;
|
||
}
|
||
|
||
BOOL GetTypeAllRecord(const TCHAR* szFileName,
|
||
const TCHAR* szBlkType,
|
||
CList<CBlockStruct, CBlockStruct&> &lstBlock,
|
||
BOOL bOnlyCurType)
|
||
{
|
||
CString csFileName = szFileName;
|
||
CString csBlkType = szBlkType;
|
||
|
||
CBlockStruct Blk;
|
||
|
||
if (!bOnlyCurType && csFileName == _T("equip")) { //读高频设备
|
||
int iLastBlkMaxNum = 6;
|
||
XStringList lstLastEq;
|
||
CRegProperty regProp2(GetRegLocation(), _T("TElecConfig"));
|
||
regProp2.SetTopRootKey(HKEY_CURRENT_USER);
|
||
regProp2.GetValue(_T("LastBlkMaxNum"), iLastBlkMaxNum);
|
||
if (iLastBlkMaxNum < 0)
|
||
iLastBlkMaxNum = 6;
|
||
CRegProperty regProp(GetRegLocation(), _T("LastInsEquip"));
|
||
regProp.SetTopRootKey(HKEY_CURRENT_USER);
|
||
for (int i = 0; i < iLastBlkMaxNum; i++) {
|
||
XString sKey(256);
|
||
CString csValue;
|
||
sKey << _T("The recent InsBlk") << (i + 1);
|
||
regProp.GetValue(sKey, csValue);
|
||
if (csValue.IsEmpty() || csValue.GetLength() > 255) continue;
|
||
lstLastEq.Append(tstrnew(csValue));
|
||
}
|
||
for (int j = 0; j < lstLastEq.Length(); j++) {
|
||
CString csTmp = lstLastEq[j];
|
||
if (!IsTgBlkExist((const TCHAR*)csTmp))
|
||
continue;
|
||
CString csTk, csRecord;
|
||
SplitBlkStr(csTmp, csTk, csRecord);
|
||
CString csTmpTKName = g_sDwbPath + csTk + _T(".tk");
|
||
if ((csTk != _T("")) && (csRecord != _T(""))) {
|
||
Blk.m_csTKName = csTmpTKName;
|
||
Blk.m_csDesName = _T("*最近使用图块*");
|
||
Blk.m_csRecord = csRecord;
|
||
lstBlock.InsertAfter(lstBlock.GetTailPosition(), Blk); //在链表尾插入 块 结构
|
||
}
|
||
}
|
||
}
|
||
|
||
CodeBase db;
|
||
db.read_only = 1;
|
||
CString sKind, sItem, sDrawing;
|
||
|
||
CString csUserTKName = g_sDwbPath + csFileName + _T("_U.tk");
|
||
if (FindFile(csUserTKName)) {
|
||
XDbfTable *pTable2 = db.Open(csUserTKName);
|
||
if (!pTable2) return FALSE;
|
||
|
||
pTable2->MoveFirst();
|
||
while (!pTable2->IsEOF()) {
|
||
GET_FIELD(pTable2, _T("kind"), sKind);
|
||
GET_FIELD(pTable2, _T("item"), sItem);
|
||
GET_FIELD(pTable2, _T("Drawing"), sDrawing);
|
||
if ((sKind == (const TCHAR *)csBlkType) && (sDrawing != _T(""))) {
|
||
Blk.m_csTKName = csUserTKName;
|
||
Blk.m_csDesName = sItem;
|
||
Blk.m_csRecord = sDrawing;
|
||
lstBlock.InsertAfter(lstBlock.GetTailPosition(), Blk); //在链表尾插入 块 结构
|
||
}
|
||
pTable2->MoveNext();
|
||
}
|
||
}
|
||
|
||
CString csSysTKName = g_sDwbPath + csFileName + _T(".tk");
|
||
XDbfTable *pTable = db.Open(csSysTKName);
|
||
if (!pTable) return FALSE;
|
||
pTable->MoveFirst();
|
||
while (!pTable->IsEOF()) {
|
||
GET_FIELD(pTable, _T("kind"), sKind);
|
||
GET_FIELD(pTable, _T("item"), sItem);
|
||
GET_FIELD(pTable, _T("Drawing"), sDrawing);
|
||
if ((sKind == (const TCHAR *)csBlkType) && (sDrawing != _T(""))) {
|
||
Blk.m_csTKName = csSysTKName;
|
||
Blk.m_csDesName = sItem;
|
||
Blk.m_csRecord = sDrawing;
|
||
lstBlock.InsertAfter(lstBlock.GetTailPosition(), Blk); //在链表尾插入 块 结构
|
||
}
|
||
pTable->MoveNext();
|
||
}
|
||
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
BOOL IsPipeLabel(AcDbObjectId id)
|
||
{
|
||
BOOL ret = FALSE;
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbPipeLabel, pLabel);
|
||
if (pLabel)
|
||
ret = TRUE;
|
||
OPENOBJ_END();
|
||
return ret;
|
||
}
|
||
|
||
BOOL SetToolbarVisible(BOOL bOpen)
|
||
{
|
||
return FALSE;
|
||
}
|
||
|
||
CString PlusString(const TCHAR* szRes, int step, BOOL bIsPlus)
|
||
{
|
||
if(_tcsicmp(szRes, _T("")) == 0)
|
||
return CString();
|
||
XString xsText;
|
||
int num, numWith;
|
||
StringAnalysis(szRes, xsText, &num, &numWith);
|
||
CString csRes = szRes;
|
||
CString csRet = csRes;
|
||
|
||
if(numWith != 0){
|
||
if(bIsPlus)
|
||
num += step;
|
||
else if(num > 1)
|
||
num -= step;
|
||
if(num < 0)
|
||
num = 0;
|
||
if(numWith == -1)
|
||
csRet.Format(_T("%s%d"), xsText, num);
|
||
else{ //需要补0
|
||
XString sText;
|
||
sText << xsText;
|
||
TCHAR szNext[256]=_T("");
|
||
_itot(num, szNext, 10);
|
||
if(numWith > 0) {
|
||
int iZeroNum = numWith - (int)_tcslen(szNext);
|
||
for(int kk=0; kk<iZeroNum; kk++)
|
||
sText << _T("0");
|
||
}
|
||
sText << szNext;
|
||
csRet = (const TCHAR*)sText;
|
||
}
|
||
}
|
||
|
||
if(csRet != csRes)
|
||
return csRet;
|
||
|
||
CString csChinaDigit[] = {_T("一"),_T("二"),_T("三"),_T("四"),_T("五"),_T("六"),_T("七"),_T("八"),_T("九"),_T("十"),};
|
||
CString csChinaDigit2[] = {_T("零"),_T("贰"),_T("叁"),_T("肆"),_T("伍"),_T("陆"),_T("柒"),_T("捌"),_T("玖"),_T("拾"),};
|
||
CString cs12Digit[] = {_T("Ⅰ"),_T("Ⅱ"),_T("Ⅲ"),_T("Ⅳ"),_T("Ⅴ"),_T("Ⅵ"),_T("Ⅶ"),_T("Ⅷ"),_T("Ⅸ"),_T("Ⅹ"),_T("Ⅺ"),_T("Ⅻ")};
|
||
CString csLetter[] = {_T("a"),_T("b"),_T("c"),_T("d"),_T("e"),_T("f"),_T("g"),_T("h"),_T("i"),_T("j"),_T("k"),_T("l"),_T("m"),_T("n"),_T("o"),_T("p"),_T("q"),_T("r"),_T("s"),_T("t"),_T("u"),_T("v"),_T("w"),_T("x"),_T("y"),_T("z")};
|
||
CString csLetter2[] = {_T("A"),_T("B"),_T("C"),_T("D"),_T("E"),_T("F"),_T("G"),_T("H"),_T("I"),_T("J"),_T("K"),_T("L"),_T("M"),_T("N"),_T("O"),_T("P"),_T("Q"),_T("R"),_T("S"),_T("T"),_T("U"),_T("V"),_T("W"),_T("X"),_T("Y"),_T("Z")};
|
||
|
||
CString csRightTmp2, csLeftTmp2;
|
||
int len = csRes.GetLength();
|
||
int iIdx(0);
|
||
|
||
TCHAR cUnit = csRes[len-1];
|
||
BYTE byte = (BYTE)cUnit;
|
||
CString csUnit = cUnit;
|
||
|
||
#if (ADS<17)
|
||
if(IsDBCSLeadByte(byte)){//如果是半个汉字,就再读下1个字符
|
||
TCHAR cUnit2 = csRes[len-2];
|
||
csUnit.Format(_T("%c%c"),cUnit2, cUnit);
|
||
}
|
||
#endif
|
||
|
||
csRightTmp2 = csUnit;
|
||
|
||
|
||
/////////////////////////////////////////////////////////////////////////
|
||
//对后面特殊字符进行递增
|
||
|
||
int iLen = 1;
|
||
|
||
#if (ADS<17)
|
||
iLen = 2;
|
||
#endif
|
||
|
||
for(int m=0;m<10;m++){
|
||
if(csRightTmp2 == csChinaDigit[m]){
|
||
|
||
CString csLeftTmp = csRes.Left(len - iLen);
|
||
if(bIsPlus)
|
||
iIdx = m + step;
|
||
else
|
||
iIdx = m - step;
|
||
iIdx = (iIdx+10) % 10;
|
||
csRightTmp2 = csChinaDigit[iIdx];
|
||
csRet.Format(_T("%s%s"), csLeftTmp, csRightTmp2);
|
||
return csRet;
|
||
}
|
||
}
|
||
|
||
for(m=0;m<10;m++){
|
||
if(csRightTmp2 == csChinaDigit2[m]){
|
||
CString csLeftTmp = csRes.Left(len - iLen);
|
||
if(bIsPlus)
|
||
iIdx = m + step;
|
||
else
|
||
iIdx = m - step;
|
||
iIdx = (iIdx+10) % 10;
|
||
csRightTmp2 = csChinaDigit2[iIdx];
|
||
csRet.Format(_T("%s%s"), csLeftTmp, csRightTmp2);
|
||
return csRet;
|
||
}
|
||
}
|
||
for(m=0;m<12;m++){
|
||
if(csRightTmp2 == cs12Digit[m]){
|
||
CString csLeftTmp = csRes.Left(len - iLen);
|
||
if(bIsPlus)
|
||
iIdx = m + step;
|
||
else
|
||
iIdx = m - step;
|
||
iIdx = (iIdx+12) % 12;
|
||
csRightTmp2 = cs12Digit[iIdx];
|
||
csRet.Format(_T("%s%s"), csLeftTmp, csRightTmp2);
|
||
return csRet;
|
||
}
|
||
}
|
||
for(m=0;m<26;m++){
|
||
csRightTmp2 = csRes.Right(1);
|
||
if(csRightTmp2 == csLetter[m]){
|
||
CString csLeftTmp = csRes.Left(len - 1);
|
||
if(bIsPlus)
|
||
iIdx = m + step;
|
||
else
|
||
iIdx = m - step;
|
||
iIdx = (iIdx+26) % 26;
|
||
csRightTmp2 = csLetter[iIdx];
|
||
csRet.Format(_T("%s%s"), csLeftTmp, csRightTmp2);
|
||
return csRet;
|
||
}
|
||
}
|
||
for(m=0;m<26;m++){
|
||
csRightTmp2 = csRes.Right(1);
|
||
if(csRightTmp2 == csLetter2[m]){
|
||
CString csLeftTmp = csRes.Left(len - 1);
|
||
if(bIsPlus)
|
||
iIdx = m + step;
|
||
else
|
||
iIdx = m - step;
|
||
iIdx = (iIdx+26) % 26;
|
||
csRightTmp2 = csLetter2[iIdx];
|
||
csRet.Format(_T("%s%s"), csLeftTmp, csRightTmp2);
|
||
return csRet;
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/////////////////////////////////////////////////////////////////////////
|
||
//对前面特殊字符进行递增
|
||
for(m=0;m<10;m++){
|
||
if(csLeftTmp2 == csChinaDigit[m]){
|
||
CString csRightTmp = csRes.Right(len - 2);
|
||
if(bIsPlus)
|
||
iIdx = m + step;
|
||
else
|
||
iIdx = m - step;
|
||
iIdx = (iIdx+10) % 10;
|
||
csLeftTmp2 = csChinaDigit[iIdx];
|
||
csRet.Format(_T("%s%s"), csLeftTmp2, csRightTmp);
|
||
return csRet;
|
||
}
|
||
}
|
||
for(m=0;m<10;m++){
|
||
if(csLeftTmp2 == csChinaDigit2[m]){
|
||
CString csRightTmp = csRes.Right(len - 2);
|
||
if(bIsPlus)
|
||
iIdx = m + step;
|
||
else
|
||
iIdx = m - step;
|
||
iIdx = (iIdx+10) % 10;
|
||
csLeftTmp2 = csChinaDigit2[iIdx];
|
||
csRet.Format(_T("%s%s"), csLeftTmp2, csRightTmp);
|
||
return csRet;
|
||
}
|
||
}
|
||
|
||
for(m=0;m<12;m++){
|
||
if(csLeftTmp2 == cs12Digit[m]){
|
||
CString csRightTmp = csRes.Right(len - 2);
|
||
if(bIsPlus)
|
||
iIdx = m + step;
|
||
else
|
||
iIdx = m - step;
|
||
iIdx = (iIdx+12) % 12;
|
||
csLeftTmp2 = cs12Digit[iIdx];
|
||
csRet.Format(_T("%s%s"), csLeftTmp2, csRightTmp);
|
||
return csRet;
|
||
}
|
||
}
|
||
|
||
for(m=0;m<26;m++){
|
||
csLeftTmp2 = csRes.Left(1);
|
||
if(csLeftTmp2 == csLetter[m]){
|
||
CString csRightTmp = csRes.Right(len - 1);
|
||
if(bIsPlus)
|
||
iIdx = m + step;
|
||
else
|
||
iIdx = m - step;
|
||
iIdx = (iIdx+26) % 26;
|
||
csLeftTmp2 = csLetter[iIdx];
|
||
csRet.Format(_T("%s%s"), csLeftTmp2, csRightTmp);
|
||
return csRet;
|
||
}
|
||
}
|
||
for(m=0;m<26;m++){
|
||
csLeftTmp2 = csRes.Left(1);
|
||
if(csLeftTmp2 == csLetter2[m]){
|
||
CString csRightTmp = csRes.Right(len - 1);
|
||
if(bIsPlus)
|
||
iIdx = m + step;
|
||
else
|
||
iIdx = m - step;
|
||
iIdx = (iIdx+26) % 26;
|
||
csLeftTmp2 = csLetter2[iIdx];
|
||
csRet.Format(_T("%s%s"), csLeftTmp2, csRightTmp);
|
||
return csRet;
|
||
}
|
||
}
|
||
return csRet;
|
||
}
|
||
|
||
CString I2Str(double i)
|
||
{
|
||
CString csText;
|
||
i = i/1000;
|
||
int iTmp = int(i * 1000) * 10;
|
||
int iTmp2 = int(i * 10000);
|
||
if(iTmp == iTmp2){
|
||
iTmp = int(i * 100) * 10;
|
||
iTmp2 = int(i * 1000);
|
||
if(iTmp == iTmp2)
|
||
csText.Format(_T("%.2f"), i);
|
||
else
|
||
csText.Format(_T("%.3f"), i);
|
||
}
|
||
else
|
||
csText.Format(_T("%.4f"), i);
|
||
return csText;
|
||
}
|
||
|
||
CString GetDimLayerNameByPipeLayer(const CString &strLayer)
|
||
{
|
||
CString strVal = LAY_TEXT;
|
||
if (strLayer.Compare(LAY_PIPE_FEED) == 0 || strLayer.Compare(LAY_PIPE_FEED2) == 0 || strLayer.Compare(LAY_PIPE_FEED3) == 0) //给水
|
||
{
|
||
strVal = LAY_DIM_FEED;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_HEADFEED) == 0 || strLayer.Compare(LAY_PIPE_HEADFEED2) == 0 || strLayer.Compare(LAY_PIPE_HEADFEED3) == 0) //热给水
|
||
{
|
||
strVal = LAY_DIM_HEADFEED;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_HEADBACK) == 0 || strLayer.Compare(LAY_PIPE_HEADBACK2) == 0 || strLayer.Compare(LAY_PIPE_HEADBACK3) == 0) //热回水
|
||
{
|
||
strVal = LAY_DIM_HEADBACK;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_DIRT) == 0) //污水
|
||
{
|
||
strVal = LAY_DIM_DIRT;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_USELESS) == 0) //废水
|
||
{
|
||
strVal = LAY_DIM_USELESS;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_RAIN) == 0) //雨水
|
||
{
|
||
strVal = LAY_DIM_RAIN;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_USED) == 0 || strLayer.Compare(LAY_PIPE_USED2) == 0 || strLayer.Compare(LAY_PIPE_USED3) == 0) //中水
|
||
{
|
||
strVal = LAY_DIM_USED;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_FIRE) == 0 || strLayer.Compare(LAY_PIPE_FIRE2) == 0 || strLayer.Compare(LAY_PIPE_FIRE3) == 0) //消防
|
||
{
|
||
strVal = LAY_DIM_HYDRANT;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_SPRINKLE) == 0 || strLayer.Compare(LAY_PIPE_SPRINKLE2) == 0 || strLayer.Compare(LAY_PIPE_SPRINKLE3) == 0) //喷淋
|
||
{
|
||
strVal = LAY_DIM_SPRINKLE;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_COAGULATE) == 0) //凝结水
|
||
{
|
||
strVal = LAY_DIM_COAGULATE;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_DRINK) == 0) //直饮水
|
||
{
|
||
strVal = LAY_DIM_DRINK;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_PRESSDIRT) == 0) //压力污水
|
||
{
|
||
strVal = LAY_DIM_PRESSDIRT;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_PRESSUSELESS) == 0) //压力废水
|
||
{
|
||
strVal = LAY_DIM_PRESSUSELESS;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_PRESSRAIN) == 0) //压力雨水
|
||
{
|
||
strVal = LAY_DIM_PRESSRAIN;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_OTHER) == 0) //其他
|
||
{
|
||
strVal = LAY_DIM_OTHER;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_USER1) == 0) //市政给管
|
||
{
|
||
strVal = LAY_DIM_USER1;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_USER2) == 0) //循环给管
|
||
{
|
||
strVal = LAY_DIM_USER2;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_USER3) == 0) //冷却 cet 2012.1.19 add user3-user8
|
||
{
|
||
strVal = LAY_DIM_USER3;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_USER4) == 0) //气体灭火
|
||
{
|
||
strVal = LAY_DIM_USER4;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_USER5) == 0) //蒸汽
|
||
{
|
||
strVal = LAY_DIM_USER5;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_USER6) == 0) //雨淋
|
||
{
|
||
strVal = LAY_DIM_USER6;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_USER7) == 0) //通气
|
||
{
|
||
strVal = LAY_DIM_USER7;
|
||
}
|
||
else if (strLayer.Compare(LAY_PIPE_USER8) == 0) //水景
|
||
{
|
||
strVal = LAY_DIM_USER8;
|
||
}
|
||
return strVal;
|
||
}
|
||
|
||
CString GetDimPipeLen(double dLen)
|
||
{
|
||
TDbPsConfig *pConfig = GetDwgPsGlobal(AcDb::kForRead);
|
||
int iPre = 2;
|
||
if (pConfig){
|
||
iPre = pConfig->GetPipeLenPrecision();
|
||
pConfig->close();
|
||
}
|
||
CString csLen;
|
||
CString sHead,sFormat;
|
||
sHead.Format(_T("%d"),iPre);
|
||
sFormat = _T("%.") + sHead + _T("f");
|
||
csLen.Format(sFormat, dLen);
|
||
return csLen;
|
||
}
|
||
|
||
void DeleteRepeateWall(AcDbObjectIdArray * pIDWalls)
|
||
{
|
||
AcDbObjectIdArray idWalls;
|
||
AcDbObjectIdArray idErases;
|
||
AcDbObjectId id1,id2;
|
||
AcDbEntity * pEnt1 = NULL;
|
||
AcDbEntity * pEnt2 = NULL;
|
||
double dDis1 = 0.0,dDis2 = 0.0;
|
||
int nLen = pIDWalls->length();
|
||
for(int i = 0;i < nLen;i++)
|
||
{
|
||
id1 = pIDWalls->at(i);
|
||
if (Acad::eOk == acdbOpenAcDbEntity(pEnt1,id1,AcDb::kForRead))
|
||
{
|
||
for(int j = 0;j < nLen;j++)
|
||
{
|
||
id2 = pIDWalls->at(j);
|
||
if (id1 != id2)
|
||
{
|
||
if (Acad::eOk == acdbOpenAcDbEntity(pEnt2,id2,AcDb::kForRead))
|
||
{
|
||
if (pEnt1->isKindOf(pEnt2->desc()))
|
||
{
|
||
AcDbLine * pLine1 = AcDbLine::cast(pEnt1);
|
||
AcDbLine * pLine2 = AcDbLine::cast(pEnt2);
|
||
if (pLine1 != NULL && pLine2 != NULL)
|
||
{
|
||
AcGePoint3d ptGeSta1 = pLine1->startPoint();
|
||
AcGePoint3d ptGeEnd1 = pLine1->endPoint();
|
||
AcGePoint3d ptGeSta2 = pLine2->startPoint();
|
||
AcGePoint3d ptGeEnd2 = pLine2->endPoint();
|
||
AcGeVector3d vc1 = ptGeEnd1 - ptGeSta1;
|
||
AcGeVector3d vc2 = ptGeEnd2 - ptGeSta2;
|
||
if (vc1.isParallelTo(vc2))
|
||
{
|
||
AcDbXline xline;
|
||
xline.setUnitDir(vc1);
|
||
xline.setBasePoint(ptGeEnd1);
|
||
AcGePoint3d ptGe;
|
||
xline.getClosestPointTo(ptGeEnd2,ptGe);
|
||
double dDis1 = ptGe.distanceTo(ptGeEnd2);
|
||
if (dDis1 < E6TOL)
|
||
{
|
||
dDis1 = ptGeEnd1.distanceTo(ptGeSta1);
|
||
dDis2 = ptGeEnd2.distanceTo(ptGeSta2);
|
||
AcGePoint3dArray ptS;
|
||
ptS.append(ptGeSta1);
|
||
ptS.append(ptGeEnd1);
|
||
ptS.append(ptGeSta2);
|
||
ptS.append(ptGeEnd2);
|
||
SortPoints(ptS,&xline,TRUE);
|
||
double dDis3 = ptS.first().distanceTo(ptS.last());
|
||
if (dDis1 + dDis2 - dDis3 > E6TOL)
|
||
{
|
||
if (dDis1 - dDis2 < E6TOL)
|
||
{
|
||
pLine1->upgradeOpen();
|
||
pLine1->erase();
|
||
pLine1->downgradeOpen();
|
||
idErases.append(id1);
|
||
}
|
||
else
|
||
{
|
||
pLine2->upgradeOpen();
|
||
pLine2->erase();
|
||
pLine2->downgradeOpen();
|
||
idErases.append(id2);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
AcDbBlockReference * pBlk1 = AcDbBlockReference::cast(pEnt1);
|
||
AcDbBlockReference * pBlk2 = AcDbBlockReference::cast(pEnt2);
|
||
if (pBlk1 != NULL && pBlk2 != NULL)
|
||
{
|
||
AcGePoint3d ptLoc1 = pBlk1->position();
|
||
AcGePoint3d ptLoc2 = pBlk2->position();
|
||
AcDbObjectId id1 = pBlk1->blockTableRecord();
|
||
AcDbObjectId id2 = pBlk2->blockTableRecord();
|
||
double dDis1 = ptLoc1.distanceTo(ptLoc2);
|
||
if (dDis1 < E6TOL)
|
||
{
|
||
pBlk1->upgradeOpen();
|
||
pBlk1->erase();
|
||
pBlk1->downgradeOpen();
|
||
idErases.append(id1);
|
||
}
|
||
}
|
||
}
|
||
pEnt2->close();
|
||
}
|
||
}
|
||
}
|
||
pEnt1->close();
|
||
}
|
||
}
|
||
|
||
nLen = idErases.length();
|
||
for(i = 0;i < nLen;i++)
|
||
{
|
||
pIDWalls->remove(idErases.at(i));
|
||
}
|
||
}
|
||
void FilletEntity(Entity ent1, Entity ent2, double nRad)
|
||
{
|
||
XPushVar<int> FilletRad(_T("FilletRad"), (int)nRad);
|
||
XLine l1(ent1, 1);
|
||
XLine l2(ent2, 1);
|
||
XPoint ptMid1, ptMid2;
|
||
l1.MidPoint(ptMid1);
|
||
l2.MidPoint(ptMid2);
|
||
ptMid1 = Wcs2Ucs(ptMid1);
|
||
ptMid2 = Wcs2Ucs(ptMid2);
|
||
|
||
SHads_command(RTSTR,_T("FILLET"),
|
||
RTLB,RTENAME,(TLong_ptr *)ent1, RT3DPOINT, &ptMid1, RTLE,
|
||
RTLB,RTENAME,(TLong_ptr *)ent2, RT3DPOINT, &ptMid2, RTLE, RTNONE);
|
||
}
|
||
|
||
AcDbObjectId InitDashLayer(const TCHAR* szLay)
|
||
{
|
||
AcDbObjectId idLay=GetLayerIdFromString(szLay);
|
||
if(!!idLay)
|
||
return idLay;
|
||
|
||
AcDbObjectId id = InitLayer(szLay);
|
||
AddLineType(_T("DASH"));
|
||
AcDbLinetypeTable *pLinetypeTbl;
|
||
AcDbObjectId ltId;
|
||
Acad::ErrorStatus es = acdbCurDwg()->getLinetypeTable(pLinetypeTbl, AcDb::kForRead);
|
||
if(es != Acad::eOk) {
|
||
return NULL;
|
||
}
|
||
if((pLinetypeTbl->getAt(_T("DASH"), ltId)) != Acad::eOk){
|
||
pLinetypeTbl->close();
|
||
return NULL;
|
||
}
|
||
pLinetypeTbl->close();
|
||
|
||
OPENOBJ_BEGIN(id, AcDb::kForWrite, AcDbLayerTableRecord, pRec);
|
||
if(pRec){
|
||
pRec->setLinetypeObjectId(ltId);
|
||
}
|
||
OPENOBJ_END();
|
||
return id;
|
||
}
|
||
|
||
BOOL IsPool(AcDbObjectId idNode)
|
||
{
|
||
if(!idNode)
|
||
return FALSE;
|
||
|
||
AcDbObjectId idBlk = NULL;
|
||
OPENOBJ_BEGIN(idNode, AcDb::kForRead, TDbPool, pEquip);
|
||
if(pEquip)
|
||
return TRUE;
|
||
else
|
||
return FALSE;
|
||
OPENOBJ_END();
|
||
|
||
}
|
||
|
||
XCurveSegment GetExternalBlockSeg(Entity entBlk, XPoint &ptPick)
|
||
{
|
||
XBlock myBlock(entBlk);
|
||
if(!myBlock.m_bInitSuccess)
|
||
return XCurveSegment();
|
||
|
||
XCurveSegment seg;
|
||
ads_point ptResult;
|
||
ads_name ent;
|
||
ads_matrix xformres;
|
||
resbuf* refstkres;
|
||
while (1) {
|
||
refstkres = NULL;
|
||
//直接选择子实体
|
||
int result = acedNEntSelP(_T("\n外部参照!请继续选择外部参照上墙线<退出>: "), ent, ptResult, 0, xformres, &refstkres);
|
||
if (refstkres != NULL)
|
||
acutRelRb(refstkres);
|
||
if (result == RTNORM) {
|
||
Entity entTemp = ent;
|
||
if(entTemp.Is(_T("LINE"))){
|
||
ptPick = ptResult;
|
||
XCurveSegment seg2(entTemp);
|
||
AcGePoint3d ptStart = seg2.StartPoint();
|
||
ptStart = ptStart.transformBy(myBlock.GetMatrix3d());
|
||
AcGePoint3d ptEnd = seg2.EndPoint();
|
||
ptEnd = ptEnd.transformBy(myBlock.GetMatrix3d());
|
||
XLine line(asDblArray(ptStart), asDblArray(ptEnd), 1);
|
||
seg = line;
|
||
return seg;
|
||
}
|
||
else if(entTemp.Is(_T("ATS_WALL"))){
|
||
OPENOBJ_BEGIN(entTemp, AcDb::kForRead, TDbWall, pWall);
|
||
XCurveSegment lCurve, rCurve;
|
||
XPoint ptNew1, ptNew2;
|
||
if(pWall) {
|
||
ptPick = ptResult;
|
||
pWall->GetSideCurve(lCurve, rCurve);
|
||
lCurve.ProjectToMe(ptPick, ptNew1);
|
||
rCurve.ProjectToMe(ptPick, ptNew2);
|
||
if(ads_distance(ptPick, ptNew1) < ads_distance(ptPick, ptNew2))
|
||
seg = lCurve;
|
||
else
|
||
seg = rCurve;
|
||
AcGePoint3d ptStart = seg.StartPoint();
|
||
ptStart = ptStart.transformBy(myBlock.GetMatrix3d());
|
||
AcGePoint3d ptEnd = seg.EndPoint();
|
||
ptEnd = ptEnd.transformBy(myBlock.GetMatrix3d());
|
||
XLine line(asDblArray(ptStart), asDblArray(ptEnd), 1);
|
||
seg = line;
|
||
return seg;
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
}
|
||
else
|
||
break;
|
||
}
|
||
return seg;
|
||
}
|
||
|
||
CString GetWellName(AcDbObjectId id)
|
||
{
|
||
CString csWellName;
|
||
OPENOBJ_BEGIN(id, AcDb::kForRead, TDbWell, pEquip);
|
||
if (pEquip) {
|
||
csWellName = pEquip->GetWellName();
|
||
}
|
||
OPENOBJ_END();
|
||
return csWellName;
|
||
}
|
||
|
||
CString GetWellName(Entity ent)
|
||
{
|
||
CString csWellName;
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbWell, pEquip);
|
||
if (pEquip) {
|
||
csWellName = pEquip->GetWellName();
|
||
}
|
||
OPENOBJ_END();
|
||
return csWellName;
|
||
}
|
||
|
||
CString GetPipeNameBySys(TPipeSys::SysType sys)
|
||
{
|
||
CString sRet;
|
||
if(sys == TPipeSys::kFeedWater)
|
||
sRet = _T("给水");
|
||
else if(sys == TPipeSys::kFeedWater2)
|
||
sRet = _T("给水中");
|
||
else if(sys == TPipeSys::kFeedWater3)
|
||
sRet = _T("给水高");
|
||
else if(sys == TPipeSys::kHeatFeedWater)
|
||
sRet = _T("热给水");
|
||
else if(sys == TPipeSys::kHeatFeedWater2)
|
||
sRet = _T("热给水中");
|
||
else if(sys == TPipeSys::kHeatFeedWater3)
|
||
sRet = _T("热给水高");
|
||
else if(sys == TPipeSys::kHeatBackWater)
|
||
sRet = _T("热回水");
|
||
else if(sys == TPipeSys::kHeatBackWater2)
|
||
sRet = _T("热回水中");
|
||
else if(sys == TPipeSys::kHeatBackWater3)
|
||
sRet = _T("热回水高");
|
||
else if(sys == TPipeSys::kDirtWater)
|
||
sRet = _T("污水");
|
||
else if(sys == TPipeSys::kUselessWater)
|
||
sRet = _T("废水");
|
||
else if(sys == TPipeSys::kRainWater)
|
||
sRet = _T("雨水");
|
||
else if(sys == TPipeSys::kUsedWater)
|
||
sRet = _T("中水");
|
||
else if(sys == TPipeSys::kUsedWater2)
|
||
sRet = _T("中水中");
|
||
else if(sys == TPipeSys::kUsedWater3)
|
||
sRet = _T("中水高");
|
||
else if(sys == TPipeSys::kFireFighting)
|
||
sRet = _T("消防");
|
||
else if(sys == TPipeSys::kFireFighting2)
|
||
sRet = _T("消防中");
|
||
else if(sys == TPipeSys::kFireFighting3)
|
||
sRet = _T("消防高");
|
||
else if(sys == TPipeSys::kSprinkle)
|
||
sRet = _T("喷淋");
|
||
else if(sys == TPipeSys::kSprinkle2)
|
||
sRet = _T("喷淋中");
|
||
else if(sys == TPipeSys::kSprinkle3)
|
||
sRet = _T("喷淋高");
|
||
else if(sys == TPipeSys::kOther)
|
||
sRet = _T("其它管");
|
||
else if(sys == TPipeSys::kCoagulate)
|
||
{
|
||
int nIndex = GetPipeLayerIdxBySys(sys);
|
||
CString sLayer = GetPipeLayerByIdx(nIndex);
|
||
if (!GetLayerReMark(sLayer, sRet))
|
||
{
|
||
sRet = _T("凝结");
|
||
}
|
||
}
|
||
else if(sys == TPipeSys::kDrink)
|
||
{
|
||
int nIndex = GetPipeLayerIdxBySys(sys);
|
||
CString sLayer = GetPipeLayerByIdx(nIndex);
|
||
if (!GetLayerReMark(sLayer, sRet))
|
||
{
|
||
sRet = _T("直饮");
|
||
}
|
||
}
|
||
else if(sys == TPipeSys::kPressDirt)
|
||
{
|
||
int nIndex = GetPipeLayerIdxBySys(sys);
|
||
CString sLayer = GetPipeLayerByIdx(nIndex);
|
||
if (!GetLayerReMark(sLayer, sRet))
|
||
{
|
||
sRet = _T("压力污");
|
||
}
|
||
}
|
||
else if(sys == TPipeSys::kPressUseless)
|
||
{
|
||
int nIndex = GetPipeLayerIdxBySys(sys);
|
||
CString sLayer = GetPipeLayerByIdx(nIndex);
|
||
if (!GetLayerReMark(sLayer, sRet))
|
||
{
|
||
sRet = _T("压力废");
|
||
}
|
||
}
|
||
else if(sys == TPipeSys::kPressRain)
|
||
{
|
||
int nIndex = GetPipeLayerIdxBySys(sys);
|
||
CString sLayer = GetPipeLayerByIdx(nIndex);
|
||
if (!GetLayerReMark(sLayer, sRet))
|
||
{
|
||
sRet = _T("压力雨");
|
||
}
|
||
}
|
||
else if (sys == TPipeSys::kCivilFeed)
|
||
{
|
||
int nIndex = GetPipeLayerIdxBySys(sys);
|
||
CString sLayer = GetPipeLayerByIdx(nIndex);
|
||
if (!GetLayerReMark(sLayer, sRet))
|
||
{
|
||
sRet = _T("用户1管线");
|
||
}
|
||
}
|
||
else if (sys == TPipeSys::kCycleFeed)
|
||
{
|
||
int nIndex = GetPipeLayerIdxBySys(sys);
|
||
CString sLayer = GetPipeLayerByIdx(nIndex);
|
||
if (!GetLayerReMark(sLayer, sRet))
|
||
{
|
||
sRet = _T("用户2管线");
|
||
}
|
||
}
|
||
else if (sys == TPipeSys::kUser3)
|
||
{
|
||
int nIndex = GetPipeLayerIdxBySys(sys);
|
||
CString sLayer = GetPipeLayerByIdx(nIndex);
|
||
if (!GetLayerReMark(sLayer, sRet))
|
||
{
|
||
sRet = _T("用户3管线");
|
||
}
|
||
}
|
||
else if (sys == TPipeSys::kUser4)
|
||
{
|
||
int nIndex = GetPipeLayerIdxBySys(sys);
|
||
CString sLayer = GetPipeLayerByIdx(nIndex);
|
||
if (!GetLayerReMark(sLayer, sRet))
|
||
{
|
||
sRet = _T("用户4管线");
|
||
}
|
||
}
|
||
else if (sys == TPipeSys::kUser5)
|
||
{
|
||
int nIndex = GetPipeLayerIdxBySys(sys);
|
||
CString sLayer = GetPipeLayerByIdx(nIndex);
|
||
if (!GetLayerReMark(sLayer, sRet))
|
||
{
|
||
sRet = _T("用户5管线");
|
||
}
|
||
}
|
||
else if (sys == TPipeSys::kUser6)
|
||
{
|
||
int nIndex = GetPipeLayerIdxBySys(sys);
|
||
CString sLayer = GetPipeLayerByIdx(nIndex);
|
||
if (!GetLayerReMark(sLayer, sRet))
|
||
{
|
||
sRet = _T("用户6管线");
|
||
}
|
||
}
|
||
else if (sys == TPipeSys::kUser7)
|
||
{
|
||
int nIndex = GetPipeLayerIdxBySys(sys);
|
||
CString sLayer = GetPipeLayerByIdx(nIndex);
|
||
if (!GetLayerReMark(sLayer, sRet))
|
||
{
|
||
sRet = _T("用户7管线");
|
||
}
|
||
}
|
||
else if (sys == TPipeSys::kUser8)
|
||
{
|
||
int nIndex = GetPipeLayerIdxBySys(sys);
|
||
CString sLayer = GetPipeLayerByIdx(nIndex);
|
||
if (!GetLayerReMark(sLayer, sRet))
|
||
{
|
||
sRet = _T("用户8管线");
|
||
}
|
||
}
|
||
return sRet;
|
||
}
|
||
|
||
AcDbObjectId GetHitSheet(XPoint ptHit)
|
||
{
|
||
AcDbObjectId id;
|
||
PickSet ss(SS_FREE);
|
||
RBList mask(RTDXF0, _T("ATS_SHEET"), NULL);
|
||
if(GetEntByDxf(ss, _T("ATS_SHEET"))==Acad::eOk) {
|
||
long lCount=ss.Length();
|
||
for(long i=0L; i<lCount; i++) {
|
||
Entity ent=ss[i];
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbSheet, pSheet);
|
||
if(pSheet && pSheet->IsValid()) {
|
||
XPoly2D poly;
|
||
pSheet->GetBorder(poly);
|
||
if((ptHit&poly)==PR_INSIDE) {
|
||
acdbGetObjectId(id, ent.name);
|
||
break;
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
}
|
||
return id;
|
||
}
|
||
|
||
AcDbObjectId InitGridLayer(const TCHAR* szLay)
|
||
{
|
||
AcDbObjectId idLay=GetLayerIdFromString(szLay);
|
||
if(!!idLay)
|
||
return idLay;
|
||
AcDbObjectId id = InitLayer(szLay);
|
||
AddLineType(_T("DOT"));
|
||
AcDbLinetypeTable *pLinetypeTbl;
|
||
AcDbObjectId ltId;
|
||
Acad::ErrorStatus es = acdbCurDwg()->getLinetypeTable(pLinetypeTbl, AcDb::kForRead);
|
||
if(es != Acad::eOk) {
|
||
return NULL;
|
||
}
|
||
if((pLinetypeTbl->getAt(_T("DOT"), ltId)) != Acad::eOk){
|
||
pLinetypeTbl->close();
|
||
return NULL;
|
||
}
|
||
pLinetypeTbl->close();
|
||
|
||
OPENOBJ_BEGIN(id, AcDb::kForWrite, AcDbLayerTableRecord, pRec);
|
||
if(pRec){
|
||
pRec->setLinetypeObjectId(ltId);
|
||
}
|
||
OPENOBJ_END();
|
||
return id;
|
||
}
|
||
|
||
CString GetDimWellDeep(double dDeep)
|
||
{
|
||
TDbPsConfig *pConfig = GetDwgPsGlobal(AcDb::kForRead);
|
||
int iPre = 3;
|
||
if (pConfig){
|
||
iPre = pConfig->GetWellDeepPrecision();
|
||
pConfig->close();
|
||
}
|
||
CString csDeep;
|
||
CString sHead,sFormat;
|
||
sHead.Format(_T("%d"),iPre);
|
||
sFormat = _T("%.") + sHead + _T("f");
|
||
csDeep.Format(sFormat, dDeep);
|
||
return csDeep;
|
||
}
|
||
|
||
namespace
|
||
{
|
||
bool g_bDefault = false;
|
||
bool g_bESC = false;
|
||
bool g_bMouseLeft = false;
|
||
#if ADS > 22
|
||
bool KeyboardMouseHook(MSG* pMsg)
|
||
#else
|
||
BOOL KeyboardMouseHook(MSG* pMsg)
|
||
#endif
|
||
{
|
||
BOOL bRet = FALSE;
|
||
switch (pMsg->message)
|
||
{
|
||
case WM_LBUTTONDOWN:
|
||
{
|
||
g_bMouseLeft = true;
|
||
break;
|
||
}
|
||
case WM_RBUTTONDOWN:
|
||
{
|
||
g_bDefault = true;
|
||
break;
|
||
}
|
||
case WM_KEYDOWN:
|
||
{
|
||
if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_SPACE)
|
||
{
|
||
g_bDefault = true;
|
||
}
|
||
else if (pMsg->wParam == VK_ESCAPE)
|
||
{
|
||
g_bESC = true;
|
||
}
|
||
break;
|
||
}
|
||
default:
|
||
break;
|
||
}
|
||
return bRet;
|
||
}
|
||
}
|
||
|
||
void SetSnapAngByLineCmd()
|
||
{
|
||
// cet 2018.1.25 modify 支持ucs
|
||
// double s_angle(0);
|
||
// adsout << _T("注意:仅单AutoCAD正交设为开状态[F8切换]时起作用!");
|
||
// int err_value=get_line_angle(s_angle);
|
||
// if(err_value == RTNORM){
|
||
// xg_setvar(_T("snapang"), s_angle);
|
||
// }
|
||
// else
|
||
// xg_setvar(_T("snapang"), 0);
|
||
g_bDefault = false;
|
||
g_bESC = false;
|
||
g_bMouseLeft = false;
|
||
double dAngle = 0.0;
|
||
adsout << _T("注意:仅单AutoCAD正交设为开状态[F8切换]时起作用!");
|
||
acedRegisterFilterWinMsg(KeyboardMouseHook);
|
||
int nRet = get_line_angle(dAngle); // 此函数返回值无法很好区分当前操作状态,添加钩子辅助判断
|
||
acedRemoveFilterWinMsg(KeyboardMouseHook);
|
||
if (!g_bESC && // 未按ESC
|
||
!g_bDefault && // 非默认操作
|
||
nRet == RTNORM)
|
||
{
|
||
dAngle = Wcs2Ucs(dAngle);
|
||
xg_setvar(_T("snapang"), dAngle);
|
||
}
|
||
else if (g_bDefault)
|
||
{
|
||
xg_setvar(_T("snapang"), 0);
|
||
}
|
||
}
|
||
|
||
BOOL GetTKType(const TCHAR* szFileName, CStringList &lstType)
|
||
{
|
||
|
||
CodeBase db;
|
||
db.read_only = 1;
|
||
XDbfTable *pTable = db.Open(szFileName);
|
||
if (!pTable) return FALSE;
|
||
CString sKind;
|
||
CBlockStruct Blk;
|
||
pTable->MoveFirst();
|
||
while (!pTable->IsEOF()) {
|
||
GET_FIELD(pTable, _T("kind"), sKind);
|
||
if (sKind != _T("")) {
|
||
POSITION pos;
|
||
pos = lstType.Find((const TCHAR*)sKind);
|
||
if (pos == NULL) {
|
||
pos = lstType.GetTailPosition();
|
||
pos = lstType.InsertAfter(pos, (const TCHAR*)sKind); //在链表尾插入 块 结构
|
||
}
|
||
}
|
||
pTable->MoveNext();
|
||
}
|
||
pTable->Close(); //sr add 11.15
|
||
return TRUE;
|
||
}
|
||
|