#include "stdafx.h" #include "JDBJDlg.h" #include "AecDbEarthWorm.h" #include "AecDbX3dGroup.h" #include "KTCADUtilityEx.h" #include "UITools.h" #include "BimInfoDlg.h" extern Acad::ErrorStatus AddToModelSpace(AcDbEntity* pEnt,AcDbDatabase* pDb ,bool bClose ); extern CString IDCreate(); static void FreeBuffer(AcDbVoidPtrArray& arTextPtrs) { AcDbEntity* pEnt = NULL; while (arTextPtrs.length() > 0) { pEnt = (AcDbEntity*)arTextPtrs.first(); arTextPtrs.removeFirst(); DELETE_PTR(pEnt); } } IMPLEMENT_DYNAMIC(CJDBJDlg, CDialog) CJDBJDlg::CJDBJDlg(CWnd* pParent /*=NULL*/) : CDialog(CJDBJDlg::IDD, pParent) , m_dL(15) , m_nPos(0) { UIDataCache::Read(_T("%d%i"), _T("CJDBJDlg"), &m_dL, &m_nPos); } CJDBJDlg::~CJDBJDlg() { } void CJDBJDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Text(pDX, IDC_EDIT1, m_dL); DDX_Radio(pDX, IDC_RADIO1, m_nPos); } BEGIN_MESSAGE_MAP(CJDBJDlg, CDialog) ON_BN_CLICKED(IDOK, &CJDBJDlg::OnBnClickedOk) ON_BN_CLICKED(IDC_BUTTON1, &CJDBJDlg::OnBnClickedButton1) END_MESSAGE_MAP() BOOL CJDBJDlg::OnInitDialog() { CDialog::OnInitDialog(); // 子类化控件对象 if (!m_wndViewCtrl.SubclassDlgItem(IDC_STATIC_EW, this)) { // 错误时,结束对话框 EndDialog(IDCANCEL); return FALSE; } ShowEarthWorm(); AcArray arRoomsM; AcGePoint2d ptSizeM,ptThickM; GetEWSize(m_sCrossSectionScr,ptSizeM,ptThickM,arRoomsM); if (m_dL < ptSizeM.x) { m_dL = 1.0 * ( (int)( ptSizeM.x + 0.5) ); } UpdateData(FALSE); CBimInfoDlg::SetDefaultBimInfo(&m_mapBimData,_T("端部井")); return TRUE; } void CJDBJDlg::ShowEarthWorm() { m_wndViewCtrl.clearAll(); m_wndViewCtrl.init(true); m_wndViewCtrl.SetOrbitFlag(OBF_PAN | OBF_ZOOM | OBF_COTE); AecDbEarthWorm worm; worm.SetCrossSectionScr(m_sCrossSectionScr); worm.SetChamferInter(100.0f); ESection eType = eRect; AcGePoint2dArray arDatas; eType = worm.ExtractEarthWormScr(arDatas); AcGeLineSeg3d ln; AcGePoint3d pt2(1000.0,0,0); ln.set(AcGePoint3d::kOrigin,pt2); AcDbRegion* pEWRegion = worm.CreateSectionRegion(ln,eType,arDatas); if (pEWRegion != NULL) { AcDbExtents exts; pEWRegion->getGeomExtents(exts); AcGeMatrix3d xform; xform.setToScaling(0.95); pEWRegion->transformBy(xform); m_wndViewCtrl.InitFromCurrentView2D(exts,true); AcDbVoidPtrArray arr; int rooms = worm.CreateSectionRoomRegion(ln, eType, arDatas, arr); AcDbEntity* pEnt = NULL; AcDbVoidPtrArray arr2; worm.CreateSectionRoomAddition(ln,eType,arr2); for (int i = 0; i < arr2.length(); i++) { pEnt = (AcDbEntity*)arr2.at(i); m_wndViewCtrl.Add(pEnt); } m_wndViewCtrl.Add(pEWRegion); m_wndViewCtrl.view()->invalidate(); m_wndViewCtrl.Invalidate(); m_wndViewCtrl.RedrawWindow(); } } void CJDBJDlg::GetEWSize(LPCTSTR pszScr,AcGePoint2d& ptSize,AcGePoint2d& ptThick,AcArray& arRooms) { //主管廊尺寸 //_T("RECT:3900x3600|2900x3600|400x300|EXT:...");//EXT为扩充字段 AecDbEarthWorm worm; worm.SetCrossSectionScr(pszScr); worm.SetChamferInter(0.0); ESection eType = eRect; AcGePoint2dArray arDatas; eType = worm.ExtractEarthWormScr(arDatas); //外壁厚,内隔壁厚 double dOutW = 0.0,dIntW = 0.0; if (arDatas.length() > 0) { dOutW = arDatas.last().x; dIntW = arDatas.last().y; } //总高度 double dHeight = arDatas.first().y; dHeight += 2 * arDatas.last().x; //总宽度 double dWidth = 0.0; for (int i = 0;i < arDatas.length()-1;i++) { dWidth += arDatas.at(i).x; } dWidth += (arDatas.length() - 2) * dIntW; dWidth += dOutW * 2.0; ptSize.set(dWidth,dHeight); ptThick.set(dOutW,dIntW); AcGeLineSeg3d ln(AcGePoint3d::kOrigin,AcGePoint3d(10.0,0.0,0)); worm.GetSectionRoomsTo(ln,arRooms,ptThick); } void CJDBJDlg::OnBnClickedOk() { UpdateData(); AcArray arRoomsM; AcGePoint2d ptSizeM,ptThickM; GetEWSize(m_sCrossSectionScr,ptSizeM,ptThickM,arRoomsM); if (m_dL - ptSizeM.x < 1.e-6) { CString sTip; sTip.Format(_T("端部结构长度太小,至少大于管廊宽度 (%.3f)!"),ptSizeM.x); AfxMessageBox(sTip); return; } UIDataCache::Write(_T("%d%i"), _T("CJDBJDlg"), &m_dL, &m_nPos); OnOK(); } int CJDBJDlg::GetX3dSolidRecs(AecDbX3dGroup*& pGroup) { AcGePoint3d ptOrg(0,0,0); AcArray arRoomsM; AcGePoint2d ptSizeM,ptThickM; GetEWSize(m_sCrossSectionScr,ptSizeM,ptThickM,arRoomsM); if (m_nPos > 0) { ptOrg.x += ( m_dEWLen + 0.5 * (m_dL - ptThickM.x) ); } else { ptOrg.x -= 0.5 * (m_dL - ptThickM.x); } AcGeVector3d vtDir = AcGeVector3d::kXAxis; AcDbX3dSolid* pXSolid = new AcDbX3dSolid; pXSolid->CreateEarthWorm(ptOrg,vtDir,m_sCrossSectionScr,(m_dL - ptThickM.x),vtDir,vtDir); if (m_nPos > 0) { ptOrg.x += 0.5 * (m_dL - ptThickM.x); } else { ptOrg.x -= 0.5 * (m_dL - ptThickM.x); } if (pGroup != NULL) { pGroup->RemoveAll3dSolidRec(); } else { pGroup = new AecDbX3dGroup; } X3dSolidRec rec; rec.pXSolid = pXSolid; rec.bType = AcDb::kBoolUnite; _tcscpy(rec.szLockId,IDCreate()); pGroup->AddX3dSolidRec(rec); //封口 double dL = ptSizeM.x; double dW = ptThickM.x; double dH = ptSizeM.y; AcGeVector3d vtZ = AcGeVector3d::kZAxis; if (m_nPos > 0) { ptOrg.x += 0.5 * ptThickM.x; } else { ptOrg.x -= 0.5 * ptThickM.x; } pXSolid = new AcDbX3dSolid; pXSolid->Create(AcDbX3dSolid::kBox,ptOrg,vtZ,3,dW,dL,dH); rec.pXSolid = pXSolid; rec.bType = AcDb::kBoolUnite; _tcscpy(rec.szLockId,IDCreate()); pGroup->AddX3dSolidRec(rec); pGroup->SetOrgPoint( ptOrg ); pGroup->SetAxis(X,AcGeVector3d::kXAxis); pGroup->SetAxis(Y,AcGeVector3d::kYAxis); pGroup->SetAxis(Z,AcGeVector3d::kZAxis); //序列化BIM数据 pGroup->GetSpecialtyData()->SetAt(_T("m_nPos"),m_nPos); pGroup->GetSpecialtyData()->SetAt(_T("m_dL"),m_dL); pGroup->GetSpecialtyData()->SetAt(_T("m_dEWLen"),m_dEWLen); pGroup->GetSpecialtyData()->SetAt(_T("m_sCrossSectionScr"),m_sCrossSectionScr); pGroup->GetSpecialtyData()->SetAt(_T("BIMDATA"),1,m_mapBimData); return TRUE; } void CJDBJDlg::OnBnClickedButton1() { CBimInfoDlg::ShowBimInfo(&m_mapBimData,_T("端部井")); }