441 lines
9.3 KiB
C++
441 lines
9.3 KiB
C++
#include "stdafx.h"
|
|
#include "EarThwormDef.h"
|
|
#include "CRJZDlg.h"
|
|
#include "uihistory.h"
|
|
#include "AecDbEarthWorm.h"
|
|
|
|
AcGePoint3d DLLIMPEXP MidPoint(AcGePoint3d& pt1, AcGePoint3d& pt2);
|
|
DLLIMPEXP AcDbPolyline* FormatPolyline(AcGePoint3d* ppPts, int nCount);
|
|
|
|
|
|
namespace
|
|
{
|
|
AcDbCurve* makeOffsetCurveByDir(AcDbPolyline* pCurve
|
|
, const double& dOffset
|
|
, const AcGeVector3d& vtDir)
|
|
{
|
|
if (!pCurve) return NULL;
|
|
int len(pCurve->numVerts());
|
|
if (len < 2) return NULL;
|
|
|
|
AcGeVector3d vt(vtDir);
|
|
vt.normalize();
|
|
|
|
AcGePoint3d ptS;
|
|
pCurve->getStartPoint(ptS);
|
|
|
|
AcDbRay ray;
|
|
ray.setUnitDir(vt);
|
|
ray.setBasePoint(ptS);
|
|
|
|
AcDbVoidPtrArray ar, ar2;
|
|
ar.removeAll();
|
|
pCurve->getOffsetCurves(dOffset, ar);
|
|
pCurve->getOffsetCurves(-dOffset, ar2);
|
|
|
|
// 没有都成功,那么,哪个成功用哪个。
|
|
if (!(!ar2.isEmpty() && !ar.isEmpty()))
|
|
{
|
|
AcDbVoidPtrArray &arr(ar.isEmpty() ? ar2 : ar);
|
|
if (arr.isEmpty()) return NULL;
|
|
AcDbCurve *pNew((AcDbCurve *)((AcDbCurve *)arr.first())->clone());
|
|
deleteArrayVoidPtrs< AcDbEntity>(arr);
|
|
return pNew;
|
|
}
|
|
|
|
AcDbCurve *pFir0 = (AcDbCurve *)ar.first();
|
|
AcDbCurve *pFir1 = (AcDbCurve *)ar2.first();
|
|
|
|
AcGePoint3dArray pts1, pts2;
|
|
pFir0->intersectWith(&ray, AcDb::kOnBothOperands, pts1);
|
|
pFir1->intersectWith(&ray, AcDb::kOnBothOperands, pts2);
|
|
|
|
AcDbPolyline *pNewCurve = NULL;
|
|
if (!pts1.isEmpty())
|
|
{
|
|
pNewCurve = (AcDbPolyline *)pFir0->clone();
|
|
deleteArrayVoidPtrs< AcDbEntity>(ar);
|
|
deleteArrayVoidPtrs< AcDbEntity>(ar2);
|
|
return pNewCurve;
|
|
}
|
|
|
|
if (!pts2.isEmpty())
|
|
{
|
|
pNewCurve = (AcDbPolyline *)pFir1->clone();
|
|
deleteArrayVoidPtrs< AcDbEntity>(ar);
|
|
deleteArrayVoidPtrs< AcDbEntity>(ar2);
|
|
return pNewCurve;
|
|
}
|
|
return pNewCurve;
|
|
}
|
|
|
|
AcDbCurve* makeCurve(AcDbPolyline* pPline, const std::vector<double>& arOffset, const AcGeVector3d& vtDir)
|
|
{
|
|
if (!pPline) return NULL;
|
|
|
|
if (!pPline->isOnlyLines()) return NULL;
|
|
|
|
int nSeg(pPline->numVerts() - 1);
|
|
|
|
if (nSeg > arOffset.size()) return NULL;
|
|
|
|
AcDbVoidPtrArray arCurves;
|
|
std::vector<AcGeLineSeg3d> segs;
|
|
AcGeLineSeg3d seg;
|
|
for (int i(0); i < nSeg; ++i)
|
|
{
|
|
AcDbPolyline* pCurve = (AcDbPolyline*)makeOffsetCurveByDir(pPline, arOffset[i], vtDir);
|
|
// 是第几个 polyline 就把自己的第几段seg取出来
|
|
if (pCurve)
|
|
{
|
|
pCurve->getLineSegAt(i, seg);
|
|
segs.push_back(seg);
|
|
DELETE_PTR(pCurve);
|
|
}
|
|
}
|
|
|
|
if (segs.empty()) return NULL;
|
|
|
|
AcGePoint3dArray arpts, ar;
|
|
AcGeLineSeg3d seg1, seg2;
|
|
AcDbLine line1, line2;
|
|
for (int i(0); i < segs.size() - 1; ++i)
|
|
{
|
|
ar.removeAll();
|
|
line1.setStartPoint(segs[i].startPoint());
|
|
line1.setEndPoint(segs[i].endPoint());
|
|
line2.setStartPoint(segs[i + 1].startPoint());
|
|
line2.setEndPoint(segs[i + 1].endPoint());
|
|
if (line1.intersectWith(&line2, AcDb::kExtendBoth, ar) == Acad::eOk && !ar.isEmpty())
|
|
arpts.append(ar.first());
|
|
}
|
|
|
|
arpts.insertAt(0, segs[0].startPoint());
|
|
arpts.append(segs.rbegin()->endPoint());
|
|
|
|
return FormatPolyline(arpts.asArrayPtr(), arpts.length());
|
|
}
|
|
|
|
AcDbRegion* makeRegByPoly(AcDbPolyline* pPlS
|
|
, AcDbPolyline* pPlE)
|
|
{
|
|
if (!pPlS)
|
|
{
|
|
return NULL;
|
|
}
|
|
if (!pPlE)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
AcGePoint3d pt;
|
|
AcGePoint3dArray ptAr;
|
|
ptAr.removeAll();
|
|
for (int i(0); i < pPlS->numVerts(); ++i)
|
|
{
|
|
pPlS->getPointAt(i, pt);
|
|
ptAr.append(pt);
|
|
}
|
|
|
|
for (int i(pPlS->numVerts() - 1); i >= 0; --i)
|
|
{
|
|
pPlE->getPointAt(i, pt);
|
|
ptAr.append(pt);
|
|
}
|
|
|
|
ptAr.append(ptAr.first());
|
|
|
|
return AecDbEarthWorm::CreatePolygonRegionOnly(ptAr.asArrayPtr(), ptAr.length());
|
|
}
|
|
|
|
AcDbLine* IsPtOnLine(const AcDbVoidPtrArray& arReg, const AcGePoint3d& pt, const double& dLen)
|
|
{
|
|
if (arReg.length() < 1) return NULL;
|
|
|
|
AcDbEntity* pSubEnt(NULL);
|
|
AcDbLine* pLine(NULL);
|
|
double dDist, dLenSE;
|
|
AcGePoint3d ptOnLine, ptS, ptE;
|
|
double dLenGe[6];
|
|
for (int i(0); i < arReg.length(); i++)
|
|
{
|
|
pSubEnt = (AcDbEntity*)arReg.at(i);
|
|
pLine = AcDbLine::cast(pSubEnt);
|
|
pLine->getStartPoint(ptS);
|
|
pLine->getEndPoint(ptE);
|
|
dLenSE = ptS.distanceTo(ptE);
|
|
dLenGe[i] = dLenSE;
|
|
dDist = dLenSE - dLen;
|
|
if (fabs(dLenSE - dLen) < 1e-6)
|
|
{
|
|
return pLine;
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
AcDbLine* ModifyLineLen(AcDbLine* pLine, const AcGePoint3d& ptC, const double& dLen)
|
|
{
|
|
if (!pLine) return NULL;
|
|
|
|
double dLenS, dLenE, dLen1, dLen2;
|
|
AcGePoint3d ptS, ptE, pt;
|
|
AcGeVector3d vecSE;
|
|
|
|
AcDbLine* pNewLine = (AcDbLine*)pLine->clone();
|
|
if (!pNewLine) return NULL;
|
|
|
|
pNewLine->getStartPoint(ptS);
|
|
pNewLine->getEndPoint(ptE);
|
|
|
|
dLen1 = ptS.distanceTo(ptE);
|
|
|
|
dLenS = ptC.distanceTo(ptS);
|
|
dLenE = ptC.distanceTo(ptE);
|
|
|
|
if (dLenS < dLenE)
|
|
{
|
|
pNewLine->setStartPoint(ptC);
|
|
|
|
vecSE = (pt - ptE).normalize();
|
|
pt = ptC - vecSE * dLen;
|
|
pNewLine->setEndPoint(pt);
|
|
}
|
|
else
|
|
{
|
|
pNewLine->setEndPoint(ptC);
|
|
|
|
vecSE = (ptC - ptS).normalize();
|
|
pt = ptC - vecSE * dLen;
|
|
pNewLine->setStartPoint(pt);
|
|
}
|
|
|
|
dLen2 = ptS.distanceTo(ptE);
|
|
|
|
return pNewLine;
|
|
}
|
|
|
|
bool IsLineStaByPt(AcDbLine* pLine, const AcGePoint3d& ptC)
|
|
{
|
|
if (!pLine) return false;
|
|
|
|
AcGePoint3d ptS;
|
|
AcDbLine* pNewLine = (AcDbLine*)pLine->clone();
|
|
pNewLine->getStartPoint(ptS);
|
|
double dDist = ptC.distanceTo(ptS);
|
|
if (fabs(dDist) < 1e-6)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
IMPLEMENT_DYNAMIC(CCRJZDlg, CDialog)
|
|
|
|
CCRJZDlg::CCRJZDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(IDD_CRJZ_DLG, pParent)
|
|
, m_sMaterial(_T("钢筋混凝土"))
|
|
, m_sHatch(HATCH_DEFAULT)
|
|
, m_bAddHatch(TRUE)
|
|
, m_dBomEl(.0)
|
|
, m_dH(3000.0)
|
|
, m_dA(500.0)
|
|
, m_dB(900.0)
|
|
, m_dAW(50.0)
|
|
, m_dBW(150.0)
|
|
, m_pRegCol(NULL)
|
|
{
|
|
GET_CACHE(CCRJZDlg
|
|
, %s%s%d%f%f%f%f%f%f
|
|
, &m_sMaterial
|
|
, &m_sHatch
|
|
, &m_bAddHatch
|
|
, &m_dBomEl
|
|
, &m_dH
|
|
, &m_dA
|
|
, &m_dB
|
|
, &m_dAW
|
|
, &m_dBW);
|
|
}
|
|
|
|
CCRJZDlg::~CCRJZDlg()
|
|
{
|
|
DELETE_PTR(m_pRegCol);
|
|
}
|
|
|
|
void CCRJZDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Text(pDX, IDC_EDIT2, m_sMaterial);
|
|
DDX_Control(pDX, IDC_BTN_FILL, m_wndBtHatch);
|
|
DDX_Check(pDX, IDC_CHECK_HATCH, m_bAddHatch);
|
|
DDX_Text(pDX, IDC_BTN_FILL, m_sHatch);
|
|
DDX_Text(pDX, IDC_EDIT1, m_dBomEl);
|
|
DDX_Text(pDX, IDC_EDIT3, m_dH);
|
|
DDX_Text(pDX, IDC_EDIT4, m_dA);
|
|
DDX_Text(pDX, IDC_EDIT5, m_dB);
|
|
DDX_Text(pDX, IDC_EDIT7, m_dAW);
|
|
DDX_Text(pDX, IDC_EDIT8, m_dBW);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CCRJZDlg, CDialog)
|
|
ON_BN_CLICKED(IDC_BTN_FILL, &CCRJZDlg::OnBnClickedBtnFill)
|
|
ON_BN_CLICKED(IDOK, &CCRJZDlg::OnBnClickedOk)
|
|
END_MESSAGE_MAP()
|
|
|
|
BOOL CCRJZDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
//IDC_STATIC
|
|
// 子类化控件对象
|
|
if (!m_wndViewCtrl.SubclassDlgItem(IDC_STATIC_FRM, this))
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
PreView2d();
|
|
|
|
UpdateData(FALSE);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
extern bool __cdecl acedHatchPalletteDialog(wchar_t const *, bool, wchar_t *&);
|
|
void CCRJZDlg::OnBnClickedBtnFill()
|
|
{
|
|
UpdateData();
|
|
TCHAR *psz = new TCHAR[1024];
|
|
::memset(psz, 0, sizeof(TCHAR) * 1024);
|
|
|
|
CString sHatch(m_sMaterial);
|
|
if (!m_sHatch.IsEmpty())
|
|
sHatch = m_sHatch;
|
|
|
|
if (acedHatchPalletteDialog(sHatch, false, psz))
|
|
{
|
|
m_sHatch = psz;
|
|
m_wndBtHatch.SetWindowText(m_sHatch);
|
|
}
|
|
|
|
delete[] psz;
|
|
}
|
|
|
|
void CCRJZDlg::PreView2d()
|
|
{
|
|
if (!m_pRegCol) return;
|
|
|
|
m_wndViewCtrl.clearAll();
|
|
m_wndViewCtrl.init(true);
|
|
m_wndViewCtrl.SetOrbitFlag(OBF_PAN | OBF_ZOOM | OBF_COTE);
|
|
AcDbExtents ext;
|
|
m_pRegCol->getGeomExtents(ext);
|
|
m_wndViewCtrl.InitFromCurrentView2D(ext, true);
|
|
m_wndViewCtrl.Add(m_pRegCol);
|
|
m_wndViewCtrl.view()->invalidate();
|
|
m_wndViewCtrl.Invalidate();
|
|
m_wndViewCtrl.RedrawWindow();
|
|
}
|
|
|
|
AcDbRegion *CCRJZDlg::makeRegion(const AcGePoint3d &ptInner
|
|
, const AcGePoint3d &ptA
|
|
, const AcGePoint3d &ptB
|
|
, const double &dThickA
|
|
, const double &dThickB
|
|
)
|
|
{
|
|
AcGePoint3d ptGe[3] = {ptA, ptInner, ptB};
|
|
|
|
AcDbPolyline* pPoly = FormatPolyline(ptGe, 3);
|
|
if (!pPoly) return NULL;
|
|
|
|
|
|
AcGeVector3d vtA, vtB, vtAB;
|
|
vtA = (ptGe[1] - ptGe[0]).normalize();
|
|
vtB = (ptGe[1] - ptGe[2]).normalize();
|
|
vtAB = vtA + vtB;
|
|
vtAB.normalize();
|
|
std::vector<double> arDoubles;
|
|
arDoubles.clear();
|
|
arDoubles.push_back(dThickA);
|
|
arDoubles.push_back(dThickB);
|
|
AcDbPolyline *pPolyOff = (AcDbPolyline *)makeCurve(pPoly, arDoubles, vtAB);
|
|
if (pPolyOff)
|
|
{
|
|
AcDbRegion *pReg = makeRegByPoly(pPoly, pPolyOff);
|
|
DELETE_PTR(pPoly);
|
|
DELETE_PTR(pPolyOff);
|
|
|
|
AcGeVector3d vtMove = ptGe[1].asVector();
|
|
vtMove.negate();
|
|
AcGeMatrix3d xform;
|
|
xform.setToTranslation(vtMove);
|
|
pReg->transformBy(xform);
|
|
|
|
return pReg;
|
|
}
|
|
|
|
DELETE_PTR(pPoly);
|
|
return NULL;
|
|
}
|
|
|
|
void CCRJZDlg::OnBnClickedOk()
|
|
{
|
|
UpdateData();
|
|
|
|
SET_CACHE(CCRJZDlg
|
|
, %s%s%d%f%f%f%f%f%f
|
|
, m_sMaterial
|
|
, m_sHatch
|
|
, m_bAddHatch
|
|
, m_dBomEl
|
|
, m_dH
|
|
, m_dA
|
|
, m_dB
|
|
, m_dAW
|
|
, m_dBW);
|
|
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
void CCRJZDlg::GetColumnParam(ColumnParam &ColParam) const
|
|
{
|
|
::memset(&ColParam, 0, sizeof(ColParam));
|
|
//参考 CCRZZDlg.cpp文件
|
|
ColParam.m_nShape = 6;
|
|
//...
|
|
_tcscpy(ColParam.m_sMaterial, m_sMaterial);
|
|
_tcscpy(ColParam.m_sHatch, m_sHatch);
|
|
ColParam.bPtPos = m_bAddHatch;
|
|
ColParam.m_dBomEl = m_dBomEl;
|
|
ColParam.m_dH = m_dH;
|
|
ColParam.m_dSizes[0] = m_dA;
|
|
ColParam.m_dSizes[1] = m_dB;
|
|
ColParam.m_dSizes[2] = m_dAW;
|
|
ColParam.m_dSizes[3] = m_dBW;
|
|
}
|
|
|
|
void CCRJZDlg::SetColumnParam(const ColumnParam& ColParam)
|
|
{
|
|
m_bAddHatch = ColParam.bPtPos;
|
|
m_dBomEl = ColParam.m_dBomEl;
|
|
m_dH = ColParam.m_dH;
|
|
m_dA = ColParam.m_dSizes[0];
|
|
m_dB = ColParam.m_dSizes[1];
|
|
m_dAW = ColParam.m_dSizes[2];
|
|
m_dBW = ColParam.m_dSizes[3];
|
|
}
|
|
|
|
void CCRJZDlg::setColumnReg(AcDbRegion* pRegCol)
|
|
{
|
|
if (!pRegCol) return;
|
|
|
|
DELETE_PTR(m_pRegCol);
|
|
|
|
m_pRegCol = (AcDbRegion*)pRegCol->clone();
|
|
}
|
|
|