Files
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

307 lines
7.4 KiB
C++

#include "stdafx.h"
#include "JXFZDlg.h"
#include "AecDbEarthWorm.h"
#include "KTCADUtilityEx.h"
#include "AcDbX3dSolid.h"
#include "AecDbX3dPart.h"
#include "UITools.h"
#include "BimInfoDlg.h"
#include "AecDbShEarthWorm.h"
#include "AecDb3dRoadAxisLine.h"
extern void SplitStrintToArray(LPCTSTR pszDescr,CStringArray& arInfo,TCHAR tcSpace);
IMPLEMENT_DYNAMIC(CJXFZDlg, CDialog)
CJXFZDlg::CJXFZDlg(CWnd* pParent /*=NULL*/)
: CDialog(CJXFZDlg::IDD, pParent)
, m_dH(3.0)
, m_dW(10.0)
, m_dL(12.0)
, m_dT(0.36)
, m_dX(5.0)
, m_bLWHIsRoom(FALSE)
{
m_ptPick.set(0,0,0);
UIDataCache::Read(_T("%d%d%d%d%s%d%p"), _T("CJXFZDlg")
, &m_dH , &m_dW , &m_dL , &m_dT
, &m_sCrossSectionScr
, &m_dX
, &m_ptPick);
}
CJXFZDlg::~CJXFZDlg()
{
}
void CJXFZDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, m_dH);
DDX_Text(pDX, IDC_EDIT2, m_dW);
DDX_Text(pDX, IDC_EDIT10, m_dL);
DDX_Text(pDX, IDC_EDIT34, m_dT);
DDX_Text(pDX, IDC_EDIT36, m_dX);
DDX_Check(pDX, IDC_CHECK1, m_bLWHIsRoom);
}
BEGIN_MESSAGE_MAP(CJXFZDlg, CDialog)
ON_BN_CLICKED(IDOK, &CJXFZDlg::OnBnClickedOk)
ON_BN_CLICKED(IDC_BUTTON1, &CJXFZDlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &CJXFZDlg::OnBnClickedButton2)
END_MESSAGE_MAP()
BOOL CJXFZDlg::OnInitDialog()
{
CDialog::OnInitDialog();
UpdateData(FALSE);
CBimInfoDlg::SetDefaultBimInfo(&m_mapBimData,_T("房子"));
return TRUE;
}
void CJXFZDlg::OnBnClickedOk()
{
UpdateData();
if (m_dH < 1.0 || m_dW < 0.1 || m_dL < 0.1)
{
AfxMessageBox(_T("房子尺寸太小!请重新输入参数!"));
}
UIDataCache::Write(_T("%d%d%d%d%s%d%p"), _T("CJXFZDlg")
, &m_dH , &m_dW , &m_dL , &m_dT
, &m_sCrossSectionScr
, &m_dX
, &m_ptPick);
OnOK();
}
void GetEarthWormHeightWidthAndThick(LPCTSTR pszCrossSectionScr,AcGePoint2d& ptHW,AcGePoint2d& ptOIW)
{
double dHeight = 0.0,dWidth = 0.0;
double dOutW = 0.0,dIntW = 0.0;
CString m_sCrossSectionScr = pszCrossSectionScr;
if (m_sCrossSectionScr.Find(_T("RECT:")) != -1)
{
//_T("RECT:3900x3600|2900x3600|400x300|EXT:...");//EXT为扩充字段
AecDbEarthWorm worm;
worm.SetCrossSectionScr(m_sCrossSectionScr);
worm.SetChamferInter(100.0);
ESection eType = eRect;
AcGePoint2dArray arDatas;
eType = worm.ExtractEarthWormScr(arDatas);
//外壁厚,内隔壁厚
if (arDatas.length() > 0)
{
dOutW = arDatas.last().x;
dIntW = arDatas.last().y;
}
//总高度
dHeight = arDatas.first().y;
dHeight += 2 * arDatas.last().x;
//总宽度
for (int i = 0;i < arDatas.length()-1;i++)
{
dWidth += arDatas.at(i).x;
}
dWidth += (arDatas.length() - 2) * dIntW;
dWidth += dOutW * 2.0;
}
else
{
CString sFullPath = FilePath::GetSysDir();
sFullPath.MakeLower();
sFullPath += _T("\\DGJM.sat");
STSection* pSection = new STSection;
pSection->pt.set(0,0,0);
CStdioFile file;
if (file.Open(sFullPath,CFile::modeCreate |CFile::modeWrite ))
{
CString sScr = m_sCrossSectionScr;
int nPos = m_sCrossSectionScr.Find(_T("<ELAGN:") );
if (nPos != -1)
{
sScr = m_sCrossSectionScr.Mid(0,nPos);
}
file.WriteString(sScr);
file.Close();
CString sX,sY;
CString sPt = m_sCrossSectionScr.Mid(nPos);
sPt.TrimLeft(_T("<ELAGN:"));
sPt.TrimRight(_T(">"));
nPos = sPt.Find(_T(','));
if (nPos != -1)
{
CStringArray arInfo;
SplitStrintToArray(sPt,arInfo,_T(','));
if (arInfo.GetSize() >= 2)
{
sX = arInfo.GetAt(0);
sY = arInfo.GetAt(1);
pSection->pt.set(_ttof(sX),_ttof(sY),0.0);
if (arInfo.GetSize() >= 6)
{
pSection->dThick[0] = _ttof(arInfo.GetAt(2));
pSection->dThick[1] = _ttof(arInfo.GetAt(3));
pSection->dThick[2] = _ttof(arInfo.GetAt(4));
pSection->dThick[3] = _ttof(arInfo.GetAt(5));
}
}
}
}
pSection->pReg = NULL;
AcDbVoidPtrArray arBodyPtrs;
if ( Acad::eOk == AcDbBody::acisIn(sFullPath,arBodyPtrs) )
{
if (arBodyPtrs.length() > 0)
{
AcDbEntity* pEnt = (AcDbEntity*)arBodyPtrs.first();
AcDbRegion* pRegion = AcDbRegion::cast(pEnt);
if (pRegion != NULL)
{
pSection->pReg = pRegion;
}
if (pSection->pReg != NULL)
{
AecDbShEarthWorm dbEW;
AcGePoint3d ptEnd(100,0,0);
AcDbLine ln(AcGePoint3d(0,0,0),ptEnd);
AecDb3dRoadAxisLine* pRoadLn = new AecDb3dRoadAxisLine;
pRoadLn->AppendCurveSeg(&ln);
dbEW.GetSpecialtyData()->SetAt(KEY_2DSTYLE, 2);
dbEW.SetSection(pSection->pReg, pSection->pt);
dbEW.SetBaseCurve(pRoadLn);
dbEW.GetSpecialtyData()->SetAt(KEY_THICKT1,AS_MUNIT(pSection->dThick[0]));
dbEW.GetSpecialtyData()->SetAt(KEY_THICKT2,AS_MUNIT(pSection->dThick[1]));
dbEW.GetSpecialtyData()->SetAt(KEY_THICKT4,AS_MUNIT(pSection->dThick[2]));
dbEW.GetSpecialtyData()->SetAt(KEY_THICKT5,AS_MUNIT(pSection->dThick[3]));
AcGePoint2d ptrODtTop,ptrODtBom;
dbEW.GetODAndID(ptrODtTop,ptrODtBom);
dHeight = ptrODtTop.x;
dWidth = ptrODtTop.x;
dOutW = pSection->dThick[0];
dIntW = pSection->dThick[1];
delete pSection->pReg;
delete pRoadLn;
}
}
}
}
ptHW.set(dHeight,dWidth);
ptOIW.set(dOutW,dIntW);
}
int CJXFZDlg::GetX3dPart(AecDbX3dPart*& pPart)
{
AcGePoint2d ptHW,ptOIW;
GetEarthWormHeightWidthAndThick(m_sCrossSectionScr,ptHW,ptOIW);
double dHeight = ptHW.x;
double dWidth = ptHW.y;
double dOutW = ptOIW.x;
double dIntW = ptOIW.y;
if (pPart != NULL)
{
pPart->RemoveAll3dSolidRec();
}
else
{
pPart = new AecDbX3dPart;
}
double dH = m_dH + (m_bLWHIsRoom ? m_dT : 0.0);
double dW = m_dW + (m_bLWHIsRoom ? 2.0 * m_dT : 0.0);
double dL = m_dL + (m_bLWHIsRoom ? 2.0 * m_dT : 0.0);
AcGePoint3d ptOrg,ptOrgOld;
ptOrg.set(m_dX,0,dHeight * 0.5);
ptOrgOld = ptOrg;
AcGeVector3d vtZ = AcGeVector3d::kZAxis;
ptOrg.z += dH * 0.5;
AcDbX3dSolid* pXSolid = new AcDbX3dSolid;
pXSolid->Create(AcDbX3dSolid::kBox,ptOrg,vtZ,3,dL,dW,dH);
pPart->AddX3dSolid(pXSolid,AcDb::kBoolUnite);
ptOrg.set(m_dX,0,dHeight * 0.5);
ptOrg.z += (dH - m_dT) * 0.5;
pXSolid = new AcDbX3dSolid;
pXSolid->Create(AcDbX3dSolid::kBox,ptOrg,vtZ,3,dL - 2 * m_dT,dW - 2 * m_dT,dH - m_dT);
pPart->AddX3dSolid(pXSolid,AcDb::kBoolSubtract);
if (m_ptPick != AcGePoint3d::kOrigin)
{
AcGeVector3d vtMove = m_ptPick - ptOrgOld;
pPart->AddMove(AcGeVector3d(vtMove.x,0,0));
pPart->AddMove(AcGeVector3d(0,vtMove.y,0));
pPart->AddMove(AcGeVector3d(0,0,vtMove.z));
}
pPart->SetOrgPoint( ptOrg );
pPart->SetAxis(X,AcGeVector3d::kXAxis);
pPart->SetAxis(Y,AcGeVector3d::kYAxis);
pPart->SetAxis(Z,AcGeVector3d::kZAxis);
//序列化BIM数据
pPart->GetSpecialtyData()->SetAt(_T("m_dH"),m_dH);
pPart->GetSpecialtyData()->SetAt(_T("m_dW"),m_dW);
pPart->GetSpecialtyData()->SetAt(_T("m_dL"),m_dL);
pPart->GetSpecialtyData()->SetAt(_T("m_dT"),m_dT);
pPart->GetSpecialtyData()->SetAt(_T("m_dX"),m_dX);
pPart->GetSpecialtyData()->SetAt(_T("m_sCrossSectionScr"),m_sCrossSectionScr);
pPart->GetSpecialtyData()->SetAt(_T("m_bLWHIsRoom"),m_bLWHIsRoom);
pPart->GetSpecialtyData()->SetAt(_T("BIMDATA"),1,m_mapBimData);
return TRUE;
}
void CJXFZDlg::OnBnClickedButton1()
{
EnableWindow(FALSE);
CWnd* pFrame = acedGetAcadFrame();
pFrame->EnableWindow(TRUE);
ShowWindow(SW_HIDE);
pFrame->SetFocus();
ads_point pt;
int nRes = acedGetPoint(NULL,_T("\n选择捕捉定位点:"),pt);
if (nRes == RTNORM)
{
m_ptPick = asPnt3d(pt);
}
pFrame->EnableWindow(FALSE);
ShowWindow(SW_SHOW);
EnableWindow(TRUE);
}
void CJXFZDlg::OnBnClickedButton2()
{
CBimInfoDlg::ShowBimInfo(&m_mapBimData,_T("房子"));
}