Files
envi-code/SourceCode/Code2026/EarthWormCmd/DGGLDlg.cpp
T

1704 lines
39 KiB
C++
Raw Normal View History

2026-09-28 15:28:50 +08:00
#include "stdafx.h"
#include "DGGLDlg.h"
#include "AecDbEarthWorm.h"
#include "AecDbEarthWormFitting.h"
#include "KTCADUtilityEx.h"
#include "UITools.h"
#include "GLTKDlg.h"
#include "GLBJDlg.h"
#include "AecDbX3dGroup.h"
#include "TJBZJCDlg.h"
#include "TJZJDlg.h"
#include "FZGWDlg.h"
#include "TJDJDlg.h"
#include "TJDHDlg.h"
#include "TJDUDlg.h"
#include "MHQDlg.h"
#include "JPSGDLG.h"
#include "FMHDlg.h"
#include "JKSBDlg.h"
#include "SDFJDlg.h"
#include "WSJCDlg.h"
#include "SectionSettingDlg.h"
#include "AecDbShEarthWorm.h"
#include "GiDrawUtility.h"
#include "CoreTools.h"
#ifndef LAYOUTNAME_HD
#define LAYOUTNAME_HD _T("横断出图")
#endif
extern Acad::ErrorStatus AddToModelSpace(AcDbEntity* pEnt, AcDbObjectId& id, AcDbDatabase* pDb, bool bClose);
IMPLEMENT_DYNAMIC(CDGGLDlg, CBaseDialog)
CDGGLDlg::CDGGLDlg(bool bInsertLibrary, CWnd* pParent)
: CBaseDialog(CDGGLDlg::IDD, _T("DGGL"), IDC_STATIC_FRM, pParent)
, m_bIsInsertLibrary(bInsertLibrary)
, m_dInterH(3600)
, m_dOutT(400)
, m_dIntT(300)
, m_dRoomWAdd(3900)
, m_sCity(_T(""))
, m_sRoad(_T(""))
, m_dYXLen(80.0f)
, m_sRoomName(_T("电力舱"))
, m_dG(0.0)
, m_dt4(400)
, m_dt5(300)
, m_iSectionType(0)
{
SetCrossSectionScr(_T("RECT:2.6x3.0|4.2x3.0|2.4x3.0|0.4x0.3"));
m_bIsYXGLJD = false;
m_bHasGrade = false;
m_dG = 0.0;
m_pGroup = NULL;
m_pGroupRB = NULL;
m_pGLBJXDataMap = NULL;
m_dChamferInter = 150.0f;
m_pGLBZJCDataMap = NULL;
return;
}
CDGGLDlg::~CDGGLDlg()
{
}
void CDGGLDlg::DoDataExchange(CDataExchange* pDX)
{
CBaseDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDITCHARM, m_dChamferInter);
DDX_Text(pDX, IDC_EDITH, m_dInterH);
DDX_Text(pDX, IDC_EDITT1, m_dOutT);
DDX_Text(pDX, IDC_EDITT2, m_dIntT);
DDX_Text(pDX, IDC_EDITROOMW, m_dRoomWAdd);
DDX_CBString(pDX, IDC_COMBO1, m_sCity);
DDX_CBString(pDX, IDC_COMBO2, m_sRoad);
DDX_Text(pDX, IDC_EDITYX, m_dYXLen);
DDX_Text(pDX, IDC_EDIT21, m_dG);
DDX_Control(pDX, IDC_STATICG, m_wndStaticG);
DDX_Control(pDX, IDC_EDIT21, m_wndEditG);
DDX_Control(pDX, IDC_STATICP, m_wndStaticP);
DDX_Control(pDX, IDC_BUTTON1, m_wndRoomReducerBt);
DDX_Control(pDX, IDC_BUTTON4, m_wndBTRainbow);
DDX_Control(pDX, IDC_COMBO4, m_wndCombo4);
DDX_Text(pDX, IDC_EDIT24, m_sRoomName);
DDX_Text(pDX, IDC_EDITT3, m_dt4);
DDX_Text(pDX, IDC_EDITT4, m_dt5);
DDX_Control(pDX, IDC_BTADDROOM2, m_wndButton2);
DDX_Control(pDX, IDC_BTADDROOM4, m_wndButton4);
DDX_Control(pDX, IDC_BTADDROOM3, m_wndButton3);
DDX_Control(pDX, IDC_BTADDROOM5, m_wndButton5);
DDX_Control(pDX, IDC_BTADDROOM6, m_wndButton6);
DDX_Control(pDX, IDC_BTADDROOM9, m_wndButton9);
DDX_Control(pDX, IDC_BTADDROOM8, m_wndButton8);
DDX_Control(pDX, IDC_BTADDROOM10, m_wndButton10);
DDX_Control(pDX, IDC_BTADDROOM7, m_wndButton7);
DDX_Control(pDX, IDC_BTADDROOM11, m_wndButton11);
DDX_Control(pDX, IDC_BUTTON6, m_wndButton12);
DDX_Control(pDX, IDC_BUTTON5, m_wndButton13);
DDX_Control(pDX, IDC_BUTTON3, m_wndButton14);
DDX_Radio(pDX, IDC_RADIO1, m_iSectionType);
DDV_MinMaxInt(pDX, m_iSectionType, 0, 4);
}
BEGIN_MESSAGE_MAP(CDGGLDlg, CBaseDialog)
ON_BN_CLICKED(IDOK, &CDGGLDlg::OnBnClickedOk)
ON_BN_CLICKED(IDC_BTADDROOM, &CDGGLDlg::OnBnClickedBtaddroom)
ON_BN_CLICKED(IDC_BTADDTODB, &CDGGLDlg::OnBnClickedBtaddtodb)
ON_BN_CLICKED(IDC_BTSELFROMDB, &CDGGLDlg::OnBnClickedBtselfromdb)
ON_BN_CLICKED(IDC_BTMODIROOM2, &CDGGLDlg::OnBnClickedBtmodiroom2)
ON_EN_KILLFOCUS(IDC_EDITH, &CDGGLDlg::OnEnChangeEdith)
ON_EN_KILLFOCUS(IDC_EDITT1, &CDGGLDlg::OnEnChangeEditt1)
ON_EN_KILLFOCUS(IDC_EDITT2, &CDGGLDlg::OnEnChangeEditt2)
ON_EN_KILLFOCUS(IDC_EDITCHARM, &CDGGLDlg::OnEnChangeEditcharm)
ON_CBN_SELCHANGE(IDC_COMBO4, &CDGGLDlg::OnCbnSelchangeCombo4)
ON_EN_KILLFOCUS(IDC_EDITROOMW, &CDGGLDlg::OnEnKillfocusEditroomw)
ON_BN_CLICKED(IDC_BUTTON1, &CDGGLDlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON4, &CDGGLDlg::OnBnClickedButton4)
ON_EN_CHANGE(IDC_EDIT24, &CDGGLDlg::OnEnChangeEdit24)
ON_BN_CLICKED(IDC_BUTTON2, &CDGGLDlg::OnBnClickedButton2)
ON_BN_CLICKED(IDC_BTADDROOM2, &CDGGLDlg::OnBnClickedBtaddroom2)
ON_BN_CLICKED(IDC_BTADDROOM3, &CDGGLDlg::OnBnClickedBtaddroom3)
ON_BN_CLICKED(IDC_BTADDROOM4, &CDGGLDlg::OnBnClickedBtaddroom4)
ON_BN_CLICKED(IDC_BTADDROOM5, &CDGGLDlg::OnBnClickedBtaddroom5)
ON_BN_CLICKED(IDC_BTADDROOM6, &CDGGLDlg::OnBnClickedBtaddroom6)
ON_BN_CLICKED(IDC_BTADDROOM7, &CDGGLDlg::OnBnClickedBtaddroom7)
ON_BN_CLICKED(IDC_BTADDROOM9, &CDGGLDlg::OnBnClickedBtaddroom9)
ON_BN_CLICKED(IDC_BTADDROOM8, &CDGGLDlg::OnBnClickedBtaddroom8)
ON_BN_CLICKED(IDC_BTADDROOM10, &CDGGLDlg::OnBnClickedBtaddroom10)
ON_BN_CLICKED(IDC_BTADDROOM11, &CDGGLDlg::OnBnClickedBtaddroom11)
ON_BN_CLICKED(IDC_BUTTON6, &CDGGLDlg::OnBnClickedButton6)
ON_BN_CLICKED(IDC_BUTTON5, &CDGGLDlg::OnBnClickedButton5)
ON_BN_CLICKED(IDC_BUTTON3, &CDGGLDlg::OnBnClickedButton3)
ON_BN_CLICKED(IDC_BUTTON11, &CDGGLDlg::OnBnClickedSetSection)
ON_BN_CLICKED(IDC_BUTTON52, &CDGGLDlg::OnBnClickedSetSection)
ON_BN_CLICKED(IDC_BUTTON53, &CDGGLDlg::OnBnClickedSetSection)
ON_BN_CLICKED(IDC_BUTTON54, &CDGGLDlg::OnBnClickedSetSection)
ON_BN_CLICKED(IDC_BUTTON55, &CDGGLDlg::OnBnClickedHorseshoeSection)
ON_BN_CLICKED(IDC_BUTTON12, &CDGGLDlg::OnBnClickedTest)
ON_BN_CLICKED(IDC_RADIO1, &CDGGLDlg::OnBnClickedRadio)
ON_BN_CLICKED(IDC_RADIO2, &CDGGLDlg::OnBnClickedRadio)
ON_BN_CLICKED(IDC_RADIO14, &CDGGLDlg::OnBnClickedRadio)
ON_BN_CLICKED(IDC_RADIO15, &CDGGLDlg::OnBnClickedRadio)
ON_BN_CLICKED(IDC_RADIO16, &CDGGLDlg::OnBnClickedRadio)
END_MESSAGE_MAP()
BOOL CDGGLDlg::OnInitDialog()
{
m_data.fNodeDef[0] = AS_MUNITF(200);
m_data.fNodeDef[1] = AS_MUNITF(3000);
m_data.fNodeDef[2] = AS_MUNITF(400);
m_data.fNodeDef[3] = AS_MUNITF(300);
m_data.fNodeDef[4] = AS_MUNITF(3000);
m_data.fNodeDef[5] = .0;
m_data.fNodeDef[6] = 80.;
if (!IsInplaceEdit())
{
_tcscpy(m_data.szNodeSpec, _T("RECT:2.6x3.0|4.2x3.0|2.4x3.0|0.4x0.3"));
}
else
{
_tcscpy(m_data.szNodeSpec, m_sCrossSectionScr);
}
CBaseDialog::OnInitDialog();
CBitmap bmp32;
if (!bmp32.LoadBitmap(IDB_BITMAP10))
{
AfxMessageBox(_T("Can't load bitmap: %x\n"), IDB_BITMAP32);
ASSERT(FALSE);
return FALSE;
}
//附属物界面
BITMAP bmpObj32;
bmp32.GetBitmap(&bmpObj32);
UINT nFlags = ILC_COLOR24 | ILC_MASK;
m_Imagelist32.Create(32, bmpObj32.bmHeight, nFlags, 0, 0);
m_Imagelist32.Add(&bmp32, RGB(255, 0, 0));
m_wndButton2.SetIcon(m_Imagelist32.ExtractIcon(0));
m_wndButton3.SetIcon(m_Imagelist32.ExtractIcon(2));
m_wndButton4.SetIcon(m_Imagelist32.ExtractIcon(1));
m_wndButton5.SetIcon(m_Imagelist32.ExtractIcon(3));
m_wndButton6.SetIcon(m_Imagelist32.ExtractIcon(4));
m_wndButton9.SetIcon(m_Imagelist32.ExtractIcon(5));
m_wndButton8.SetIcon(m_Imagelist32.ExtractIcon(6));
m_wndButton10.SetIcon(m_Imagelist32.ExtractIcon(7));
m_wndButton7.SetIcon(m_Imagelist32.ExtractIcon(8));
m_wndButton11.SetIcon(m_Imagelist32.ExtractIcon(9));
m_wndButton12.SetIcon(m_Imagelist32.ExtractIcon(10));
m_wndButton13.SetIcon(m_Imagelist32.ExtractIcon(11));
m_wndButton14.SetIcon(m_Imagelist32.ExtractIcon(12));
m_dChamferInter = AS_M2MM(m_data.fNodeDef[0]);
m_dInterH = AS_M2MM(m_data.fNodeDef[1]);
m_dOutT = AS_M2MM(m_data.fNodeDef[2]);
m_dIntT = AS_M2MM(m_data.fNodeDef[3]);
m_dRoomWAdd = AS_M2MM(m_data.fNodeDef[4]);
m_dG = m_data.fNodeDef[5];
m_dYXLen = m_data.fNodeDef[6];
SetCrossSectionScr(m_data.szNodeSpec);
//写入临时文件
CString sFullPath = FilePath::GetSysDir();
sFullPath.MakeLower();
sFullPath += _T("\\HZGLDlg.map");
if (!IsInplaceEdit())
{
CStdioFile file1;
if (file1.Open(sFullPath, CFile::modeRead))
{
CString sLast, sText;
int nPos = 0;
while (file1.ReadString(sText))
{
sText.TrimRight(_T('\n'));
if (nPos % 2 == 1)
{
m_mapIndexToName.SetAt(sLast, sText);
}
else
{
sLast = sText;
}
nPos += 1;
}
file1.Close();
}
else
{
CString str(_T(""));
GetCrossSectionScr(str);
AecDbEarthWorm ew;
ew.SetCrossSectionScr(m_sCrossSectionScr);
int roomCount = ew.GetRoomCount();
LPCTSTR ar[] = { _T("电力舱"), _T("综合舱"), _T("燃气舱") };
for (int i = 0; i < roomCount; ++i)
{
str.Format(_T("%d"), i);
m_mapIndexToName.SetAt(str, ar[i]);
}
}
}
else
{
}
std::vector<CString> vec(0);
CString type(_T("")), sTemp;
for (int i = 0; i < m_mapIndexToName.GetCount(); ++i)
{
sTemp.Format(_T("%d"), i);
if (!m_mapIndexToName.Lookup(sTemp, type))
type = _T("NONE");
vec.push_back(type);
}
if (!vec.empty())
m_sRoomName = vec[0];
SetRoomFeature(vec);
ShowEarthWorm();
std::vector<CString> strs;
CoreTools::SplitString(m_data.szNodeDefSpec, _T("|"), strs);
if (strs.size() == 2)
{
m_sCity = strs[0];
m_sRoad = strs[1];
}
m_wndRoomReducerBt.ShowWindow(SW_HIDE);
m_wndBTRainbow.ShowWindow(SW_HIDE);
if (!m_bIsYXGLJD)
{
GetDlgItem(IDC_STATIC_YX)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_EDITYX)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STATIC_YXM)->ShowWindow(SW_HIDE);
}
if (!m_bHasGrade)
{
m_wndStaticG.ShowWindow(SW_HIDE);
m_wndEditG.ShowWindow(SW_HIDE);
m_wndStaticP.ShowWindow(SW_HIDE);
}
else
{
m_wndRoomReducerBt.ShowWindow(SW_SHOW);
m_wndBTRainbow.ShowWindow(SW_SHOW);
}
UpdateData(FALSE);
OnBnClickedRadio();
return TRUE;
}
void CDGGLDlg::OnViewLButtonDownMsg()
{
if (m_idxRoom != -1 && m_pRectCell != NULL)
{
UpdateData(TRUE);
AcGePoint2d pt1, pt2, pt3;
m_pRectCell->getPointAt(0, pt1);
m_pRectCell->getPointAt(1, pt2);
m_pRectCell->getPointAt(2, pt3);
m_dRoomWAdd = pt1.distanceTo(pt2) * 1000;
m_dInterH = pt2.distanceTo(pt3) * 1000;
CString sTemp;
sTemp.Format(_T("%d"), m_idxRoom);
m_mapIndexToName.Lookup(sTemp, m_sRoomName);
UpdateData(FALSE);
int nSel = m_wndCombo4.FindString(0, m_sRoomName);
if (nSel != -1)
{
m_wndCombo4.SetCurSel(nSel);
}
}
}
void CDGGLDlg::SetFeatureForEarthworm(AecDbEarthWorm *pEw)
{
if (!pEw) return;
CString sTemp, sName;
for (int ii = 0; ii < m_mapIndexToName.GetCount(); ii++)
{
sTemp.Format(_T("%d"), ii);
if (m_mapIndexToName.Lookup(sTemp, sName))
pEw->GetSpecialtyData()->SetAt(sTemp, sName);
}
return;
}
void CDGGLDlg::SetFeatureForEarthworm(AecDbEarthWormFitting *pEw)
{
if (!pEw) return;
CString sTemp, sName, sTemp2;
for (int ii = 0; ii < m_mapIndexToName.GetCount(); ii++)
{
sTemp.Format(_T("%d"), ii);
sTemp2.Format(_T("room-%d"), ii);
if (m_mapIndexToName.Lookup(sTemp, sName))
pEw->GetSpecialtyData()->SetAt(sTemp2, sName);
}
return;
}
void CDGGLDlg::InitRoomFeature(const AecDbEarthWorm *pEw)
{
if (!pEw) // 新建一段管廊时
{
std::vector<CString> vec(10, _T("NONE"));
SetRoomFeature(vec);
return;
}
CString str(_T("")), feature(_T(""));
for (int i = 0; i < pEw->GetRoomCount(); ++i)
{
str.Format(_T("%d"), i);
const AecDbObjXDataMap *pMap = pEw->GetSpecialtyData();
if (pMap)
{
pMap->GetAt(str, feature);
m_mapIndexToName.SetAt(str, feature);
m_roomTypes.push_back(feature);
}
}
}
void CDGGLDlg::OnBnClickedOk()
{
UpdateData();
CString sText;
if (!m_bIsInsertLibrary)
{
if (m_dInterH < 100.0f)
{
sText = _T("舱室高度太小!");
AfxMessageBox(sText);
return;
}
if (m_dOutT < 10.0f || m_dIntT < 10.0f)
{
sText = _T("管廊外壁厚度或室间厚度太小!");
AfxMessageBox(sText);
return;
}
}
if (m_bIsYXGLJD)
{
if (m_dYXLen < 5.0f)
{
sText = _T("异型管廊节点长度太小,至少大于5米!");
AfxMessageBox(sText);
return;
}
}
m_data.fNodeDef[0] = AS_MUNITF(m_dChamferInter);
m_data.fNodeDef[1] = AS_MUNITF(m_dInterH);
m_data.fNodeDef[2] = AS_MUNITF(m_dOutT);
m_data.fNodeDef[3] = AS_MUNITF(m_dIntT);
m_data.fNodeDef[4] = AS_MUNITF(m_dRoomWAdd);
m_data.fNodeDef[5] = m_dG;
m_data.fNodeDef[6] = m_dYXLen;
if (m_sCrossSectionScr.GetLength() < MAX_PATH)
_tcscpy(m_data.szNodeSpec, m_sCrossSectionScr);
std::vector<CString> strs;
strs.push_back(m_sCity);
strs.push_back(m_sRoad);
CString str = CoreTools::ConnectString(strs, _T("|"));
if (!str.IsEmpty())
_tcscpy(m_data.szNodeDefSpec, str);
AecDbEarthWorm ew;
ew.SetCrossSectionScr(m_sCrossSectionScr);
int roomCount = ew.GetRoomCount();
CString key(_T("")), value(_T(""));
bool bWrong(false);
//本地路径
CString sFullPath = FilePath::GetSysDir();
sFullPath.MakeLower();
sFullPath += _T("\\HZGLDlg.map");
//写入临时文件
CStdioFile file1;
if (file1.Open(sFullPath, CFile::modeWrite | CFile::modeCreate))
{
for (POSITION ps = m_mapIndexToName.GetStartPosition(); ps != NULL;)
{
m_mapIndexToName.GetNextAssoc(ps, key, value);
key += _T("\n");
file1.WriteString(key);
value += _T("\n");
file1.WriteString(value);
}
file1.Close();
}
if (m_mapIndexToName.GetSize() >= roomCount)
{
for (int i = 0; i < roomCount; ++i)
{
key.Format(_T("%d"), i);
if (!m_mapIndexToName.Lookup(key, value))
{
bWrong = true;
break;
}
if (value.CompareNoCase(_T("NONE")) == 0)
{
bWrong = true;
break;
}
}
}
else
{
bWrong = true;
}
if (bWrong && !m_bIsInsertLibrary)
{
AfxMessageBox(_T("请确定为每个舱室设置了功能。"));
return;
}
CBaseDialog::OnOK();
}
void CDGGLDlg::OnBnClickedBtaddroom()
{
UpdateData();
if (m_dRoomWAdd - 100.0 > 1.e-3)
{
//m_sCrossSectionScr = _T("RECT:3.900x3.600|2.900x3.600|0.400x0.300");
AecDbEarthWorm worm;
worm.SetCrossSectionScr(m_sCrossSectionScr);//last
worm.SetChamferInter(m_dChamferInter);
ESection eType = eRect;
AcGePoint2dArray arDatas;
eType = worm.ExtractEarthWormScr(arDatas);
AcGePoint2d ptLastRoom(AS_MUNITF(m_dRoomWAdd), AS_MUNITF(m_dInterH));
for (int i = 0; i < arDatas.length() - 1; i++)
{
AcGePoint2d& ptTemp = arDatas.at(i);
ptTemp.x = AS_MUNITF(m_dInterH);
}
arDatas.insertAt(arDatas.length() - 1, ptLastRoom);
//_T("RECT:3.900x3.600|2.900x3.600|0.400x0.300");
CString sCrossSectionScr = _T("RECT:");
CString sTemp;
for (int i = 0; i < arDatas.length(); i++)
{
sTemp.Format(_T("%gx%g"), arDatas.at(i).x, arDatas.at(i).y);
sCrossSectionScr += sTemp;
if (i < arDatas.length() - 1) sCrossSectionScr += _T("|");
}
m_sCrossSectionScr = sCrossSectionScr;
ShowEarthWorm();
}
else
{
AfxMessageBox(_T("舱的宽度尺寸过小!"));
}
}
void CDGGLDlg::OnBnClickedBtmodiroom()
{
UpdateData();
if (m_dRoomWAdd < AS_MUNIT(10.0))
{
AfxMessageBox(_T("室宽度太小!请重新输入管廊截面内舱舱宽!"));
return;
}
if (m_dInterH < AS_MUNIT(10.0))
{
AfxMessageBox(_T("室高度太小!请重新输入管廊截面内舱高度!"));
return;
}
if (GetIdxOfRoom() != -1)
{
AecDbEarthWorm worm;
worm.SetCrossSectionScr(m_sCrossSectionScr);//last
worm.SetChamferInter(m_dChamferInter);
ESection eType = eRect;
AcGePoint2dArray arDatas;
eType = worm.ExtractEarthWormScr(arDatas);
//修改 W
AcGePoint2d& pt = arDatas.at(GetIdxOfRoom());
pt.x = AS_MUNIT(m_dRoomWAdd);
//修改全部高度,合成文本
CString sCrossSectionScr = _T("RECT:");
CString sTemp;
for (int i = 0; i < arDatas.length(); i++)
{
//W x H
if (i < arDatas.length() - 1)
sTemp.Format(_T("%gx%g"), arDatas.at(i).x, AS_MUNIT(m_dInterH));
else
sTemp.Format(_T("%gx%g"), AS_MUNIT(m_dOutT), AS_MUNIT(m_dIntT));
sCrossSectionScr += sTemp;
if (i < arDatas.length() - 1) sCrossSectionScr += _T("|");
}
CString sExt = _T("|EXT:"), sKey, sExtVal;
for (POSITION ps = m_mapAddtion.GetStartPosition(); ps != NULL;)
{
m_mapAddtion.GetNextAssoc(ps, sKey, sExtVal);
sExt += sExtVal;
}
m_sCrossSectionScr = sCrossSectionScr;
if (sExt.CompareNoCase(_T("|EXT:")) != 0)
{
m_sCrossSectionScr += sExt;
}
worm.SetCrossSectionScr(m_sCrossSectionScr);//last
worm.SetChamferInter(m_dChamferInter);
sTemp.Format(_T("%d"), GetIdxOfRoom());
m_mapIndexToName.SetAt(sTemp, m_sRoomName);
int count = worm.GetRoomCount();
std::vector<CString> vec(0);
CString type(_T(""));
for (int i = 0; i < count; ++i)
{
sTemp.Format(_T("%d"), i);
if (!m_mapIndexToName.Lookup(sTemp, type))
type = _T("NONE");
vec.push_back(type);
}
SetRoomFeature(vec);
ShowEarthWorm();
}
}
void CDGGLDlg::OnBnClickedBtaddtodb()
{
//_T("RECT:3900x3600|2900x3600|400x300|EXT:...");//EXT为扩充字段
OnBnClickedBtmodiroom();
CGLTKDlg dlg(CGLTKDlg::eInput);
dlg.SetCrossSectionScr(m_sCrossSectionScr);
dlg.DoModal();
}
void CDGGLDlg::OnBnClickedBtselfromdb()
{
CGLTKDlg dlg(CGLTKDlg::eSelect);
if (IDOK == dlg.DoModal())
{
CString sScr;
if (dlg.GetCrossSectionScr(sScr))
{
m_sCrossSectionScr = sScr;
ShowEarthWorm();
AecDbEarthWorm worm;
worm.SetCrossSectionScr(m_sCrossSectionScr);
AcGePoint2dArray arDatas;
worm.ExtractEarthWormScr(arDatas);
if (arDatas.length() > 0)
{
m_dInterH = 1000.0 * arDatas.first().y;
m_dOutT = 1000.0 * arDatas.last().x;
m_dIntT = 1000.0 * arDatas.last().y;
UpdateData(FALSE);
}
UpdateWindow();
}
}
}
void CDGGLDlg::OnBnClickedBtmodiroom2()
{
UpdateData();
if (GetIdxOfRoom() != -1)
{
AecDbEarthWorm worm;
worm.SetCrossSectionScr(m_sCrossSectionScr);//last
worm.SetChamferInter(m_dChamferInter);
ESection eType = eRect;
AcGePoint2dArray arDatas;
eType = worm.ExtractEarthWormScr(arDatas);
if (arDatas.length() == 2) return;
arDatas.removeAt(GetIdxOfRoom());
//修改全部高度,合成文本
CString sCrossSectionScr = _T("RECT:");
CString sTemp;
for (int i = 0; i < arDatas.length(); i++)
{
if (i < arDatas.length() - 1)
sTemp.Format(_T("%gx%g"), arDatas.at(i).x, arDatas.at(i).y);
else
sTemp.Format(_T("%gx%g"), AS_MUNIT(m_dOutT), AS_MUNIT(m_dIntT));
sCrossSectionScr += sTemp;
if (i < arDatas.length() - 1)
sCrossSectionScr += _T("|");
}
CString sExt = _T("EXT:"), sKey, sExtVal;
for (POSITION ps = m_mapAddtion.GetStartPosition(); ps != NULL;)
{
m_mapAddtion.GetNextAssoc(ps, sKey, sExtVal);
sExt += sExtVal;
}
m_sCrossSectionScr = sCrossSectionScr;
if (sExt.CompareNoCase(_T("EXT:")) != 0)
{
m_sCrossSectionScr += sExt;
}
ShowEarthWorm();
}
}
void CDGGLDlg::OnEnChangeEdith()
{
OnBnClickedBtmodiroom();
}
void CDGGLDlg::OnEnChangeEditt1()
{
OnBnClickedBtmodiroom();
}
void CDGGLDlg::OnEnChangeEditt2()
{
OnBnClickedBtmodiroom();
}
void CDGGLDlg::OnEnChangeEditcharm()
{
OnBnClickedBtmodiroom();
}
void CDGGLDlg::OnCbnSelchangeCombo4()
{
int nSel = m_wndCombo4.GetCurSel();
if (nSel != -1)
{
m_wndCombo4.GetLBText(nSel, m_sRoomName);
UpdateData(FALSE);
}
OnBnClickedBtmodiroom();
}
void CDGGLDlg::OnEnKillfocusEditroomw()
{
OnBnClickedBtmodiroom();
}
void CDGGLDlg::ReloadGLBJ(AecDbObjXDataMap* pXDataMap)
{
m_pGLBJXDataMap = pXDataMap;
CGLBJDlg dlg;
dlg.m_bIsAddRec = true;
dlg.SetCrossSectionScr(m_sCrossSectionScr, m_dYXLen);
dlg.SetReloadGLBJ(m_pGLBJXDataMap);
dlg.ReloadFromXDataMap();
{
//合成AecX3DSolid 集合,加入FIT
if (m_pGroup != NULL)
DELETE_PTR(m_pGroup);
m_pGroup = NULL;
AcGePoint3d ptOrg(0, 0, 0);
ptOrg.y += 0.5 * m_dYXLen;
dlg.GetX3dSolidRecs(m_pGroup, ptOrg, -AcGeVector3d::kYAxis);
}
}
void CDGGLDlg::ReloadBZJC(AecDbObjXDataMap* pXDataMap)
{
m_pGLBZJCDataMap = pXDataMap;
CTJBZJCDlg dlg;
dlg.SetCrossSectionScr(m_sCrossSectionScr, m_dYXLen);
dlg.SetReloadTJBZJC(m_pGLBZJCDataMap);
dlg.ReloadFromXDataMap();
{
//合成AecX3DSolid 集合,加入FIT
if (m_pGroupRB != NULL)
DELETE_PTR(m_pGroupRB);
m_pGroupRB = NULL;
dlg.GetX3dSolidRecsForYGL(m_pGroupRB);
}
}
//舱室变径
void CDGGLDlg::OnBnClickedButton1()
{
UpdateData();
CGLBJDlg dlg;
dlg.m_bIsAddRec = true;
dlg.SetCrossSectionScr(m_sCrossSectionScr, m_dYXLen);
dlg.SetReloadGLBJ(m_pGLBJXDataMap);
int nRes = dlg.DoModal();
if (nRes == IDOK)
{
//合成AecX3DSolid 集合,加入FIT
if (m_pGroup != NULL)
DELETE_PTR(m_pGroup);
m_pGroup = NULL;
AcGePoint3d ptOrg(0, 0, 0);
ptOrg.y += 0.5 * m_dYXLen;
dlg.GetX3dSolidRecs(m_pGroup, ptOrg, -AcGeVector3d::kYAxis);
}
}
void CDGGLDlg::OnBnClickedButton4()
{
UpdateData();
CTJBZJCDlg dlg;
dlg.SetCrossSectionScr(m_sCrossSectionScr, m_dYXLen);
int nRes = dlg.DoModal();
if (nRes == IDOK)
{
//合成AecX3DSolid 集合,加入FIT
if (m_pGroupRB != NULL)
DELETE_PTR(m_pGroupRB);
m_pGroupRB = NULL;
dlg.GetX3dSolidRecsForYGL(m_pGroupRB);
}
}
int CDGGLDlg::GetX3dSolidRecsRB(AecDbX3dGroup*& pGroup)
{
pGroup = m_pGroupRB;
return m_pGroupRB != NULL ? TRUE : FALSE;
}
int CDGGLDlg::GetX3dSolidRecs(AecDbX3dGroup*& pGroup)
{
if (pGroup != NULL)
{
AcArray<X3dSolidRec> arRecs;
if (m_pGroup != NULL)
{
m_pGroup->GetX3dSolidRecs(arRecs);
for (int i = 0; i < arRecs.length(); i++)
{
X3dSolidRec& rc = arRecs.at(i);
pGroup->AddX3dSolidRec(rc);
}
for (int i = 0; i < 10; i++)
{
AecDbObjXDataMap rcXDataMap;
if (m_pGroup->GetSpecialtyData()->GetAt(_T("CGLBJDlg"), i, rcXDataMap))
{
pGroup->GetSpecialtyData()->SetAt(_T("CGLBJDlg"), i, rcXDataMap);
}
else
{
break;
}
}
}
if (m_pGroupRB != NULL)
{
arRecs.removeAll();
m_pGroupRB->GetX3dSolidRecs(arRecs);
for (int i = 0; i < arRecs.length(); i++)
{
X3dSolidRec& rc = arRecs.at(i);
pGroup->AddX3dSolidRec(rc);
}
AecDbObjXDataMap rcXDataMap;
if (m_pGroupRB->GetSpecialtyData()->GetAt(_T("CTJBZJCDlg"), 0, rcXDataMap))
{
pGroup->GetSpecialtyData()->SetAt(_T("CTJBZJCDlg"), 0, rcXDataMap);
}
}
if (pGroup != NULL || m_pGroupRB != NULL)
{
return TRUE;
}
}
return FALSE;
}
STSection* CDGGLDlg::GetSTSection( )
{
return &m_curSection;
}
void CDGGLDlg::GetRoomNames(CStringArray& arRoomNames)
{
AecDbEarthWorm ew;
ew.SetCrossSectionScr(m_sCrossSectionScr);
CString sKey, sName;
for (int i = 0; i < ew.GetRoomCount(); i++)
{
sKey.Format(_T("%d"), i);
if (m_mapIndexToName.Lookup(sKey, sName))
{
arRoomNames.Add(sName);
}
else
{
break;
}
}
}
void CDGGLDlg::OnEnChangeEdit24()
{
OnBnClickedBtmodiroom();
}
//自定义属性
void CDGGLDlg::OnBnClickedButton2()
{
}
//添加支架
void CDGGLDlg::OnBnClickedBtaddroom2()
{
int nIndex = GetIdxOfRoom();
if (nIndex != -1)
{
CString sKey, sName;
sKey.Format(_T("%d"), GetIdxOfRoom());
m_mapIndexToName.Lookup(sKey, sName);
CString sOffsets;
CTJZJDlg dlg;
dlg.m_data.m_sSpec = sName;
if (IDOK == dlg.DoModal())
{
CString sHolder;
int nPos = dlg.GetScript(sHolder, nIndex,sOffsets);
CString sKey;
sKey.Format(_T("%d-%d-%d-HOLDER"), nIndex, nPos,dlg.m_data.m_nNo);
m_mapAddtion.SetAt(sKey, sHolder);
OnBnClickedBtmodiroom();
}
}
else
{
AfxMessageBox(_T("请选择管廊舱室添加支架!"));
}
}
//添加吊架
void CDGGLDlg::OnBnClickedBtaddroom3()
{
int nIndex = GetIdxOfRoom();
if (nIndex != -1)
{
CString sKey, sName;
sKey.Format(_T("%d"), GetIdxOfRoom());
m_mapIndexToName.Lookup(sKey, sName);
CString sOffsets;
CTJDJDlg dlg;
dlg.m_data.m_sSpec = sName;
if (IDOK == dlg.DoModal())
{
CString sHolder;
int nPos = dlg.GetScript(sHolder, nIndex,sOffsets);
CString sKey;
sKey.Format(_T("%d-%d-HANGER"), nIndex, nPos);
m_mapAddtion.SetAt(sKey, sHolder);
OnBnClickedBtmodiroom();
}
}
else
{
AfxMessageBox(_T("请选择管廊舱室添加吊架!"));
}
}
//预留管位
void CDGGLDlg::OnBnClickedBtaddroom4()
{
int nIndex = GetIdxOfRoom();
if (nIndex != -1)
{
CString sKey, sName;
sKey.Format(_T("%d"), GetIdxOfRoom());
m_mapIndexToName.Lookup(sKey, sName);
CString sOffsets;
CFZGWDlg dlg;
dlg.m_data.m_sSpec = sName;
if (IDOK == dlg.DoModal())
{
CString sBoss;
CString sPos = dlg.GetScript(sBoss, nIndex,sOffsets);
CString sKey;
sKey.Format(_T("%d-%s-BOSS"), nIndex, sPos);
m_mapAddtion.SetAt(sKey, sBoss);
OnBnClickedBtmodiroom();
}
}
else
{
AfxMessageBox(_T("请选择管廊舱室预留管位!"));
}
}
//添加吊环
void CDGGLDlg::OnBnClickedBtaddroom5()
{
int nIndex = GetIdxOfRoom();
if (nIndex != -1)
{
CString sKey, sName;
sKey.Format(_T("%d"), GetIdxOfRoom());
m_mapIndexToName.Lookup(sKey, sName);
CString sOffsets;
CTJDHDlg dlg;
dlg.m_sSpec = _T("吊环");
if (IDOK == dlg.DoModal())
{
CString sRings;
int nPos = dlg.GetScript(sRings, nIndex,sOffsets);
CString sKey;
sKey.Format(_T("%d-%d-RINGS"), nIndex, nPos);
m_mapAddtion.SetAt(sKey, sRings);
OnBnClickedBtmodiroom();
}
}
else
{
AfxMessageBox(_T("请选择管廊舱室添加吊环!"));
}
}
//添加灯具
void CDGGLDlg::OnBnClickedBtaddroom6()
{
int nIndex = GetIdxOfRoom();
if (nIndex != -1)
{
CString sKey, sName;
sKey.Format(_T("%d"), GetIdxOfRoom());
m_mapIndexToName.Lookup(sKey, sName);
CString sOffsets;
CTJDUDlg dlg;
if (IDOK == dlg.DoModal())
{
CString sLamps;
int nPos = dlg.GetScript(sLamps, nIndex,sOffsets);
CString sKey;
sKey.Format(_T("%d-%d-LAMPS"), nIndex, nPos);
m_mapAddtion.SetAt(sKey, sLamps);
OnBnClickedBtmodiroom();
}
}
else
{
AfxMessageBox(_T("请选择管廊舱室添加灯具!"));
}
}
//添加排风
void CDGGLDlg::OnBnClickedBtaddroom7()
{
int nIndex = GetIdxOfRoom();
if (nIndex != -1)
{
//DRAFAN:房间|外径|长度|吊高|间距|风量|功率|机号|名称|型号|厂家
CString sKey, sName;
sKey.Format(_T("%d"), GetIdxOfRoom());
m_mapIndexToName.Lookup(sKey, sName);
CString sOffsets;
CSDFJDlg dlg;
if (IDOK == dlg.DoModal())
{
CString sScript;
int nPos = dlg.GetScript(sScript, nIndex,sOffsets);
CString sKey;
sKey.Format(_T("%d-%d-DRAFAN"), nIndex, nPos);
m_mapAddtion.SetAt(sKey, sScript);
OnBnClickedBtmodiroom();
}
}
else
{
AfxMessageBox(_T("请选择管廊舱室添加风机!"));
}
}
//添加灭火器
void CDGGLDlg::OnBnClickedBtaddroom9()
{
int nIndex = GetIdxOfRoom();
if (nIndex != -1)
{
CString sKey, sName;
sKey.Format(_T("%d"), GetIdxOfRoom());
m_mapIndexToName.Lookup(sKey, sName);
CString sOffsets;
CMHQDlg dlg;
if (IDOK == dlg.DoModal())
{
CString sFireet;
int nPos = dlg.GetScript(sFireet, nIndex,sOffsets);
CString sKey;
sKey.Format(_T("%d-%d-FIREET"), nIndex, nPos);
m_mapAddtion.SetAt(sKey, sFireet);
OnBnClickedBtmodiroom();
}
}
else
{
AfxMessageBox(_T("请选择管廊舱室添加灭火器!"));
}
}
//添加防火门
void CDGGLDlg::OnBnClickedBtaddroom8()
{
int nIndex = GetIdxOfRoom();
if (nIndex != -1)
{
//FIREDOOR:房间|宽|高|型号|厂家
CString sKey, sName;
sKey.Format(_T("%d"), GetIdxOfRoom());
m_mapIndexToName.Lookup(sKey, sName);
CString sOffsets;
CFMHDlg dlg;
if (IDOK == dlg.DoModal())
{
CString sFireet;
int nPos = dlg.GetScript(sFireet, nIndex,sOffsets);
CString sKey;
sKey.Format(_T("%d-%d-FIREDOOR"), nIndex, nPos);
m_mapAddtion.SetAt(sKey, sFireet);
OnBnClickedBtmodiroom();
}
}
else
{
AfxMessageBox(_T("请选择管廊舱室添加防火门!"));
}
}
//添加监控
void CDGGLDlg::OnBnClickedBtaddroom10()
{
int nIndex = GetIdxOfRoom();
if (nIndex != -1)
{
//FIREDOOR:房间|宽|高|型号|厂家
CString sKey, sName;
sKey.Format(_T("%d"), GetIdxOfRoom());
m_mapIndexToName.Lookup(sKey, sName);
CString sOffsets;
CJKSBDlg dlg;
if (IDOK == dlg.DoModal())
{
CString sSecurity;
int nPos = dlg.GetScript(sSecurity, nIndex,sOffsets);
CString sKey;
sKey.Format(_T("%d-%d-SECURITY"), nIndex, nPos);
m_mapAddtion.SetAt(sKey, sSecurity);
OnBnClickedBtmodiroom();
}
}
else
{
AfxMessageBox(_T("请选择管廊舱室添加监控!"));
}
}
//排水沟
void CDGGLDlg::OnBnClickedBtaddroom11()
{
int nIndex = GetIdxOfRoom();
if (nIndex != -1)
{
CString sKey, sName;
sKey.Format(_T("%d"), GetIdxOfRoom());
m_mapIndexToName.Lookup(sKey, sName);
CJPSGDlg gDlg;
if (IDOK == gDlg.DoModal())
{
CString sWater;
int nPos = gDlg.GetScript(sWater, nIndex);
CString sKey;
sKey.Format(_T("%d-%d-GUTTERWAY"), 0, 0);
m_mapAddtion.SetAt(sKey, sWater);
OnBnClickedBtmodiroom();
}
}
else
{
AfxMessageBox(_T("请选择管廊舱室添加排水沟!"));
}
}
//瓦斯报警器
void CDGGLDlg::OnBnClickedButton6()
{
int nIndex = GetIdxOfRoom();
if (nIndex != -1)
{
//GASALARM:房间|位置|高度|长|宽|厚|间距|名称|等级|型号|厂家
CString sKey, sName;
sKey.Format(_T("%d"), GetIdxOfRoom());
m_mapIndexToName.Lookup(sKey, sName);
CString sOffsets;
CWSJCDlg dlg;
if (IDOK == dlg.DoModal())
{
CString sScript;
int nPos = dlg.GetScript(sScript, nIndex,sOffsets);
CString sKey;
sKey.Format(_T("%d-%d-GASALARM"), nIndex, nPos);
m_mapAddtion.SetAt(sKey, sScript);
OnBnClickedBtmodiroom();
}
}
else
{
AfxMessageBox(_T("请选择管廊舱室添加瓦斯报警器!"));
}
}
//分舱
void CDGGLDlg::OnBnClickedButton5()
{
}
//横断出图
extern BOOL OutDrawing(LPCTSTR pszDrawFileSub, AcDbVoidPtrArray& arEntPtrs, const AcGeVector3d& vtDir, bool bIsShowEntPtrs,bool bAddToModelSpace, bool bHasDim = true);
void CDGGLDlg::OnBnClickedButton3()
{
EnableWindow(FALSE);
CWnd* pFrame = acedGetAcadFrame();
pFrame->EnableWindow(TRUE);
ShowWindow(SW_HIDE);
pFrame->SetFocus();
AcDbVoidPtrArray arDrawffer;
GetDrawBuffer(arDrawffer);
AcAxDocLock lock;
/*AcDbObjectId id;
AcDbEntity* pEnt = NULL;
for (int i = 0;i < arDrawffer.length();i++)
{
pEnt = (AcDbEntity*)arDrawffer.at(i);
AddToModelSpace(pEnt,id,NULL,true);
}*/
OutDrawing(LAYOUTNAME_HD, arDrawffer, AcGeVector3d::kXAxis,true,false);
pFrame->EnableWindow(FALSE);
EndDialog(IDCANCLE);
}
void CDGGLDlg::OnBnClickedSetSection()
{
UpdateData(TRUE);
CSectionSettingDlg dlg(m_iSectionType < 2);
if (dlg.DoModal() != IDOK) return;
m_curSection.clear();
if (m_iSectionType == 0 || m_iSectionType == 1)
m_curSection.a = dlg.m_fA;
else
m_curSection.a = dlg.m_fA;
m_curSection.b = dlg.m_fB;
m_curSection.pt = AcGePoint3d::kOrigin;
}
void CDGGLDlg::OnBnClickedHorseshoeSection()
{
// 界面上选取一个闭合曲线,再选一点做为中心点
EnableWindow(FALSE);
CWnd* pFrame = acedGetAcadFrame();
pFrame->EnableWindow(TRUE);
ShowWindow(SW_HIDE);
pFrame->SetFocus();
do
{
ads_point pt;
ads_name ent;
int nRes = acedEntSel(_T("\n请选择一个面域:"), ent, pt);
if (nRes != RTNORM) break;
AcDbObjectId id;
acdbGetObjectId(id, ent);
m_curSection.clear();
nRes = acedGetPoint(pt, _T("\n请选一点做为截面的对齐点:"), pt);
acdbUcs2Wcs(pt, pt, false);
m_curSection.pt = asPnt3d(pt);
OPENOBJ_BEGIN(id, AcDb::kForRead, AcDbRegion, pReg)
if (pReg)
{
m_curSection.pReg = (AcDbRegion*)pReg->clone();
}
OPENOBJ_END()
} while (false);
pFrame->EnableWindow(FALSE);
ShowWindow(SW_SHOW);
EnableWindow(TRUE);
UpdateData(FALSE);
}
namespace
{
void GiDrawPipeTest()
{
AcDbObjectId _id;
AcDbEntity *p(NULL);
ads_name adsEnt;
ads_point adsPt;
int rt;
TCHAR szKey[131] = {};
acedInitGet(RSG_OTHER, _T("1 2 3"));
rt = acedGetKword(_T("\n请选择[通过半径壁厚绘制(1)/通过闭合polyline做为截面绘制(2)/通过region做为截面绘制(3)]<通过半径壁厚绘制(1)>:"), szKey);
if (rt == RTNONE) _tcscpy(szKey, _T("1"));
else if (rt == RTCAN) return;
if (_tcscmp(szKey, _T("1")) == 0)
{
double dR(100), dT(10);
rt = acedGetReal(_T("\n请输入管线半径<100>:"), &dR);
rt = acedGetReal(_T("\n请输入管线厚度<10>:"), &dT);
rt = acedGetPoint(NULL, _T("\n请选择起点:"), adsPt);
ads_point adsPt1;
acdbUcs2Wcs(adsPt, adsPt1, false);
if (rt != RTNORM) return;
AcGePoint3d ptS(asPnt3d(adsPt1));
rt = acedGetPoint(adsPt, _T("\n请选择终点:"), adsPt);
acdbUcs2Wcs(adsPt, adsPt1, false);
if (rt != RTNORM) return;
AcGePoint3d ptE(asPnt3d(adsPt1));
p = GiDrawUtility::DrawPipe(ptS, ptE, dR, dT);
AddToModelSpace(p, _id, NULL, true);
return;
}
rt = acedEntSel(_T("\n选择一段曲线做为管线路径:"), adsEnt, adsPt);
if (rt != RTNORM) return;
AcDbObjectId id;
acdbGetObjectId(id, adsEnt);
OPENOBJ_BEGIN(id, AcDb::kForRead, AcDbCurve, pPath)
if (!pPath)
{
acutPrintf(_T("\n所选实体不是曲线。"));
return;
}
if (_tcscmp(szKey, _T("2")) == 0)
{
rt = acedEntSel(_T("\n请选择一个闭合的曲线做为管线截面:"), adsEnt, adsPt);
if (rt != RTNORM) return;
AcDbObjectId idSection;
acdbGetObjectId(idSection, adsEnt);
OPENOBJ_BEGIN(idSection, AcDb::kForRead, AcDbCurve, pSection)
if (!pSection)
{
acutPrintf(_T("\n所选实体不是polyline。"));
return;
}
if (!pSection->isClosed())
{
acutPrintf(_T("\n请选择一个闭合的曲线。"));
return;
}
AcDbExtents ext;
pSection->getGeomExtents(ext);
AcGePoint3d ptOn((ext.maxPoint().x + ext.minPoint().x) * .5, (ext.maxPoint().y + ext.minPoint().y) * .5, (ext.maxPoint().z + ext.minPoint().z) * .5);
p = GiDrawUtility::DrawPipe(pPath, pSection, ptOn);
if (p) AddToModelSpace(p, _id, NULL, true);
OPENOBJ_END()
}
else
{
rt = acedEntSel(_T("\n请选择一个region做为管线截面:"), adsEnt, adsPt);
if (rt != RTNORM) return;
AcDbObjectId idSection;
acdbGetObjectId(idSection, adsEnt);
OPENOBJ_BEGIN(idSection, AcDb::kForRead, AcDbRegion, pSection)
if (!pSection)
{
acutPrintf(_T("\n所选实体不是region。"));
return;
}
AcDbExtents ext;
pSection->getGeomExtents(ext);
AcGePoint3d ptOn((ext.maxPoint().x + ext.minPoint().x) * .5, (ext.maxPoint().y + ext.minPoint().y) * .5, (ext.maxPoint().z + ext.minPoint().z) * .5);
p = GiDrawUtility::DrawPipe(pPath, pSection, ptOn);
if (p) AddToModelSpace(p, _id, NULL, true);
OPENOBJ_END()
}
OPENOBJ_END()
}
bool createRegion(const AcDbVoidPtrArray& curveSegments, AcDbVoidPtrArray& regions)
{
if (AcDbRegion::createFromCurves(curveSegments, regions) != Acad::eOk)
{
acutPrintf(_T("\n createFromCurves failed."));
return false;
}
if (regions.isEmpty())
{
acutPrintf(_T("\n result is empty."));
return false;
}
return true;
}
AcDbRegion* createRegion(const AcDbVoidPtrArray& curveSegments)
{
if (curveSegments.isEmpty()) return NULL;
AcDbVoidPtrArray regs;
if (!createRegion(curveSegments, regs)) return NULL;
return (AcDbRegion*)regs[0];
}
AcDbRegion* createRegion(AcDbEntity *pEnt)
{
AcDbVoidPtrArray arr, regs;
arr.append(pEnt);
if (!createRegion(arr, regs)) return NULL;
return (AcDbRegion*)regs[0];
}
AcDbRegion* makeRegion(const int &iType, float &dThick, STSection &section)
{
switch (iType)
{
case 0: // 圆
{
if (section.a <= dThick) return NULL;
// 构建两个圆
AcDbCircle cirBig(AcGePoint3d::kOrigin, AcGeVector3d::kZAxis, section.a);
AcDbCircle cirSml(AcGePoint3d::kOrigin, AcGeVector3d::kZAxis, section.a - dThick);
// 构建两个region
AcDbRegion *pRegBig = createRegion(&cirBig);
AcDbRegion *pRegSml = createRegion(&cirSml);
if (!pRegBig || !pRegSml)
{
DELETE_PTR(pRegBig);
DELETE_PTR(pRegSml);
return NULL;
}
if (pRegBig->booleanOper(AcDb::kBoolSubtract, pRegSml) != Acad::eOk)
{
DELETE_PTR(pRegBig);
DELETE_PTR(pRegSml);
return NULL;
}
DELETE_PTR(pRegSml);
return pRegBig;
}
break;
case 1: // 半圆
{
if (section.a <= dThick) return NULL;
AcDbArc ArcBig(AcGePoint3d::kOrigin, AcGeVector3d::kZAxis, section.a, 0., PI);
AcDbLine LineBig(AcGePoint3d(section.a, .0, .0), AcGePoint3d(-1 * section.a, .0, .0));
double delta(section.a - dThick);
AcDbArc ArcSml(AcGePoint3d::kOrigin, AcGeVector3d::kZAxis, delta, 0., PI);
AcDbLine LineSml(AcGePoint3d(delta, .0, .0), AcGePoint3d(-1 * delta, .0, .0));
AcDbVoidPtrArray arBig, arSml;
arBig.append(&ArcBig);
arBig.append(&LineBig);
arSml.append(&ArcSml);
arSml.append(&LineSml);
AcDbRegion *pRegBig = createRegion(arBig);
AcDbRegion *pRegSml = createRegion(arSml);
if (!pRegBig || !pRegSml)
{
DELETE_PTR(pRegBig);
DELETE_PTR(pRegSml);
return NULL;
}
if (pRegBig->booleanOper(AcDb::kBoolSubtract, pRegSml) != Acad::eOk)
{
DELETE_PTR(pRegBig);
DELETE_PTR(pRegSml);
return NULL;
}
DELETE_PTR(pRegSml);
return pRegBig;
}
break;
case 2: // 椭圆
{
if (section.a * .5 <= dThick) return NULL;
if (section.b * .5 <= dThick) return NULL;
// 构建两个椭圆
AcDbEllipse cirBig(AcGePoint3d::kOrigin
, AcGeVector3d::kZAxis
, AcGeVector3d::kXAxis * section.b * .5
, section.a / section.b);
double deltaB(section.b - dThick);
double deltaA(section.a - dThick);
AcDbEllipse cirSml(AcGePoint3d::kOrigin
, AcGeVector3d::kZAxis
, AcGeVector3d::kXAxis * deltaB * .5
, deltaA / deltaB);
// 构建两个region
AcDbRegion *pRegBig = createRegion(&cirBig);
AcDbRegion *pRegSml = createRegion(&cirSml);
if (pRegBig->booleanOper(AcDb::kBoolSubtract, pRegSml) != Acad::eOk)
{
DELETE_PTR(pRegBig);
DELETE_PTR(pRegSml);
}
DELETE_PTR(pRegSml);
return pRegBig;
}
break;
case 3: // 半椭圆
{
if (section.a * .5 <= dThick) return NULL;
if (section.b * .5 <= dThick) return NULL;
AcDbEllipse ArcBig(AcGePoint3d::kOrigin
, AcGeVector3d::kZAxis
, AcGeVector3d::kXAxis * section.b * .5
, section.a / section.b
, 0.
, PI);
AcDbLine LineBig(AcGePoint3d(section.b * .5, .0, .0), AcGePoint3d(-1 * section.b * .5, .0, .0));
double deltaB(section.b - dThick);
double deltaA(section.a - dThick);
AcDbEllipse ArcSml(AcGePoint3d::kOrigin
, AcGeVector3d::kZAxis
, AcGeVector3d::kXAxis * deltaB * .5
, deltaA / deltaB
, 0.
, PI);
AcDbLine LineSml(AcGePoint3d(deltaB * .5, .0, .0), AcGePoint3d(-1 * deltaB * .5, .0, .0));
AcDbVoidPtrArray arBig, arSml;
arBig.append(&ArcBig);
arBig.append(&LineBig);
arSml.append(&ArcSml);
arSml.append(&LineSml);
AcDbRegion *pRegBig = createRegion(arBig);
AcDbRegion *pRegSml = createRegion(arSml);
if (!pRegBig || !pRegSml)
{
DELETE_PTR(pRegBig);
DELETE_PTR(pRegSml);
return NULL;
}
if (pRegBig->booleanOper(AcDb::kBoolSubtract, pRegSml) != Acad::eOk)
{
DELETE_PTR(pRegBig);
DELETE_PTR(pRegSml);
return NULL;
}
DELETE_PTR(pRegSml);
return pRegBig;
}
break;
case 4: // 马蹄
return section.pReg;
default:
return NULL;
}
return NULL;
}
}
void CDGGLDlg::Start()
{
TCHAR szKey[131] = {};
acedInitGet(RSG_OTHER, _T("1 2"));
int nRes = acedGetKword(_T("\n请选择[绘制测试(1)/对话框测试(2)]<对话框测试(2)>:"), szKey);
if (nRes == RTCAN)
return;
if (_tcscmp(szKey, _T("1")) == 0)
{
GiDrawPipeTest();
return;
}
if (_tcscmp(szKey, _T("2")) == 0)
{
CAcModuleResourceOverride myResources;
CDGGLDlg dlg;
dlg.DoModal();
}
}
void CDGGLDlg::OnBnClickedTest()
{
UpdateData(TRUE);
OnBnClickedRadio();
CBaseDialog::OnOK();
AcDbObjectId idPath(AcDbObjectId::kNull);
ads_name adsEnt;
ads_point adsPt;
int rt = acedEntSel(_T("\n选择一段曲线做为管线路径:"), adsEnt, adsPt);
if (rt != RTNORM) return;
acdbGetObjectId(idPath, adsEnt);
OPENOBJ_BEGIN(idPath, AcDb::kForRead, AcDbCurve, pPath)
if (!pPath) return;
float dOut(AS_MUNIT(m_dOutT));
AcDbRegion *pReg = makeRegion(m_iSectionType, dOut, m_curSection);
if (!pReg)
{
acutPrintf(_T("\n生成面域失败。"));
return;
}
AecDbShEarthWorm *pSh = new AecDbShEarthWorm;
pSh->GetSpecialtyData()->SetAt(KEY_2DSTYLE, 2);
pSh->SetSection(pReg, m_curSection.pt);
pSh->SetBaseCurve(pPath);
AcDbObjectId id;
AddToModelSpace(pSh, id, NULL, true);
OPENOBJ_END()
}
void CDGGLDlg::OnBnClickedRadio()
{
UpdateData(TRUE);
CWnd *pCir = GetDlgItem(IDC_BUTTON11);
CWnd *pHalfCir = GetDlgItem(IDC_BUTTON52);
CWnd *pEll = GetDlgItem(IDC_BUTTON53);
CWnd *pHalfEll = GetDlgItem(IDC_BUTTON54);
CWnd *pHorse = GetDlgItem(IDC_BUTTON55);
if (!pCir || !pHalfCir || !pEll || !pHalfEll || !pHorse) return;
pCir->EnableWindow(FALSE);
pHalfCir->EnableWindow(FALSE);
pEll->EnableWindow(FALSE);
pHalfEll->EnableWindow(FALSE);
pHorse->EnableWindow(FALSE);
switch (m_iSectionType)
{
case 0:
pCir->EnableWindow(TRUE);
break;
case 1:
pHalfCir->EnableWindow(TRUE);
break;
case 2:
pEll->EnableWindow(TRUE);
break;
case 3:
pHalfEll->EnableWindow(TRUE);
break;
case 4:
pHorse->EnableWindow(TRUE);
break;
default:
break;
}
}