241 lines
5.3 KiB
C++
241 lines
5.3 KiB
C++
#include "stdafx.h"
|
|
#include "PMSJDlg.h"
|
|
#include "CoreTools.h"
|
|
#include "AddPoolCellDlg.h"
|
|
#include "AecDbPoolCell.h"
|
|
#include "KTEntityDragMgr.h"
|
|
#include "KTCadUtility.h"
|
|
#include "KTCADUtilityEx.h"
|
|
#include "GLTKDlg.h"
|
|
|
|
namespace
|
|
{
|
|
}
|
|
|
|
#define SP_CELL TCHAR(0x19)
|
|
|
|
IMPLEMENT_DYNAMIC(CPMSJDlg, CDialog)
|
|
|
|
CPMSJDlg::CPMSJDlg(CWnd* pParent)
|
|
: CDialog(IDD_DLG_PMSJ, pParent)
|
|
, m_iCircle(0)
|
|
{
|
|
|
|
}
|
|
|
|
CPMSJDlg::~CPMSJDlg() { }
|
|
|
|
void CPMSJDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Radio(pDX, IDC_RADIO1, m_iCircle);
|
|
}
|
|
|
|
BOOL CPMSJDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
return TRUE;
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CPMSJDlg, CDialog)
|
|
ON_BN_CLICKED(IDC_BUTTON1, &CPMSJDlg::OnBnClickedButton1)
|
|
ON_BN_CLICKED(IDC_BUTTON2, &CPMSJDlg::OnBnClickedButton2)
|
|
ON_BN_CLICKED(IDC_BUTTON3, &CPMSJDlg::OnBnClickedButton3)
|
|
ON_MESSAGE(WM_ACAD_KEEPFOCUS, &CPMSJDlg::onAcadKeepFocus)
|
|
ON_BN_CLICKED(IDC_BUTTON4, &CPMSJDlg::OnBnClickedButton4)
|
|
END_MESSAGE_MAP()
|
|
|
|
void CPMSJDlg::OnBnClickedButton1()
|
|
{
|
|
UpdateData(TRUE);
|
|
AcAxDocLock lock;
|
|
CAddPoolCellDlg dlg(m_iCircle == 0 ? false : true, false);
|
|
if (dlg.DoModal() != IDOK) return;
|
|
AecDbPoolCell *pCell = new AecDbPoolCell();
|
|
pCell->SetName(dlg.m_sName);
|
|
pCell->SetH(dlg.m_dH);
|
|
pCell->SetTStyle(dlg.m_sTStyle);
|
|
pCell->SetTH(dlg.m_dTH);
|
|
if (!dlg.m_bCircle) // 方形
|
|
{
|
|
pCell->SetR(.0);
|
|
pCell->SetA(CoreTools::A2R(dlg.m_dA));
|
|
pCell->SetW(dlg.m_dW);
|
|
pCell->SetL(dlg.m_dL);
|
|
}
|
|
else
|
|
{
|
|
pCell->SetR(dlg.m_dR);
|
|
}
|
|
|
|
AcGePoint3d pt(AcGePoint3d::kOrigin);
|
|
if (!dlg.m_bCircle)
|
|
pt = dlg.Center2LeftTop(pt);
|
|
|
|
CKTEntityDragMgr jig(pt, pCell);
|
|
jig.EnableMove(TRUE);
|
|
jig.EnableScale(FALSE);
|
|
jig.EnableRotate(FALSE);
|
|
if (jig.DoDrag())
|
|
{
|
|
pt = jig.GetDragPoint();
|
|
if (!dlg.m_bCircle)
|
|
pt = dlg.LeftTop2Center(pt);
|
|
|
|
pCell->SetPt(pt);
|
|
CoreTools::AddToModelSpace(pCell);
|
|
}
|
|
}
|
|
|
|
void CPMSJDlg::OnBnClickedButton2()
|
|
{
|
|
UpdateData(TRUE);
|
|
AcAxDocLock lock;
|
|
CAddPoolCellDlg dlg(m_iCircle == 0 ? false : true, true);
|
|
if (dlg.DoModal() != IDOK) return;
|
|
|
|
ads_point adsPt;
|
|
if (acedGetPoint(NULL, _T("\n请选择插入点:"), adsPt) != RTNORM) return;
|
|
|
|
AcGePoint3d pt(AcGePoint3d::kOrigin), _pt(AcGePoint3d::kOrigin);
|
|
CoreTools::UCS2WCS(asPnt3d(adsPt), pt);
|
|
pt = dlg.LeftTop2Center(pt);
|
|
_pt = pt;
|
|
|
|
AcGeVector3d vt(dlg.GetDir()), vtN(dlg.GetNormal());
|
|
|
|
double w(dlg.m_bCircle ? 2 * dlg.m_dR : dlg.m_dW), l(dlg.m_bCircle ? 2 * dlg.m_dR : dlg.m_dL);
|
|
|
|
int idx(1);
|
|
for (int r = 0; r < dlg.m_iHorCount; ++r)
|
|
{
|
|
_pt = pt;
|
|
_pt += vt * r * l;
|
|
for (int c = 0; c < dlg.m_iVerCount; ++c)
|
|
{
|
|
AecDbPoolCell *pCell = new AecDbPoolCell();
|
|
pCell->SetName(dlg.m_sName + TypeConvert::i2s(idx++));
|
|
pCell->SetH(dlg.m_dH);
|
|
pCell->SetTStyle(dlg.m_sTStyle);
|
|
pCell->SetTH(dlg.m_dTH);
|
|
if (!dlg.m_bCircle) // 方形
|
|
{
|
|
pCell->SetR(.0);
|
|
pCell->SetA(CoreTools::A2R(dlg.m_dA));
|
|
pCell->SetW(dlg.m_dW);
|
|
pCell->SetL(dlg.m_dL);
|
|
}
|
|
else
|
|
{
|
|
pCell->SetR(dlg.m_dR);
|
|
}
|
|
pCell->SetPt(_pt - vtN * c * w);
|
|
CoreTools::AddToModelSpace(pCell);
|
|
}
|
|
}
|
|
}
|
|
|
|
void CPMSJDlg::OnBnClickedButton3()
|
|
{
|
|
ads_name ss;
|
|
struct resbuf* pRb = acutBuildList(RTDXF0, _T("AEC_DBPOOLCELL"), 0);
|
|
if (CKTCadUtility::SelectEntities(_T("请选择对象:"), ss, pRb) != RTNORM)
|
|
{
|
|
acutRelRb(pRb);
|
|
return ;
|
|
}
|
|
acutRelRb(pRb);
|
|
|
|
ads_point adsPt;
|
|
if (ads_getpoint(NULL, _T("\n选取对齐点:"), adsPt) != RTNORM) return;
|
|
AcGePoint3d pt(asPnt3d(adsPt));
|
|
CoreTools::UCS2WCS(pt, pt);
|
|
|
|
CString str(CoreTools::pointToString(pt, 5));
|
|
|
|
ads_name ent;
|
|
AcDbObjectId id(AcDbObjectId::kNull);
|
|
Adesk::Int32 count(0);
|
|
acedSSLength(ss, &count);
|
|
for (long i = 0; i < count; ++i)
|
|
{
|
|
acedSSName(ss, i, ent);
|
|
if (acdbGetObjectId(id, ent) != Acad::eOk) continue;
|
|
OPENOBJ_BEGIN(id, AcDb::kForRead, AecDbPoolCell, pCell)
|
|
{
|
|
if (!pCell) continue;
|
|
str += SP_CELL;
|
|
str += pCell->ToScript();
|
|
}
|
|
OPENOBJ_END()
|
|
}
|
|
|
|
CGLTKDlg dlg(CGLTKDlg::eInput, _T("poolstandard.db"), _T("poolcell"), CGLTKDlg::drawPoolCell);
|
|
dlg.SetCrossSectionScr(str);
|
|
dlg.DoModal();
|
|
acedSSFree(ss);
|
|
}
|
|
|
|
LONG_PTR CPMSJDlg::onAcadKeepFocus(UINT_PTR, LONG_PTR)
|
|
{
|
|
POINT pt;
|
|
::GetCursorPos(&pt);
|
|
CRect rect;
|
|
GetWindowRect(&rect);
|
|
if (!(rect.PtInRect(pt)))
|
|
{
|
|
return FALSE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void CPMSJDlg::OnBnClickedButton4()
|
|
{
|
|
AcAxDocLock lock;
|
|
CGLTKDlg dlg(CGLTKDlg::eSelect, _T("poolstandard.db"), _T("poolcell"), CGLTKDlg::drawPoolCell);
|
|
if (dlg.DoModal() != IDOK) return;
|
|
|
|
CString script(_T(""));
|
|
dlg.GetCrossSectionScr(script);
|
|
if (script.IsEmpty()) return;
|
|
|
|
AcGePoint3d ptOrg;
|
|
std::vector<AecDbPoolCell*> cells;
|
|
generateCellsByString(script, cells, ptOrg);
|
|
if (cells.empty()) return;
|
|
|
|
ads_point adsPt;
|
|
if (ads_getpoint(NULL, _T(""), adsPt) != RTNORM) return;
|
|
AcGePoint3d ptIns(asPnt3d(adsPt));
|
|
CoreTools::UCS2WCS(ptIns, ptIns);
|
|
|
|
AcGeVector3d vt(ptIns - ptOrg);
|
|
AcGeMatrix3d mat;
|
|
mat.setTranslation(vt);
|
|
|
|
AecDbPoolCell *pCell(NULL);
|
|
for (size_t i = 0; i < cells.size(); ++i)
|
|
{
|
|
pCell = cells[i];
|
|
pCell->transformBy(mat);
|
|
CoreTools::AddToModelSpace(pCell);
|
|
}
|
|
}
|
|
|
|
void CPMSJDlg::generateCellsByString(LPCTSTR psz, std::vector<AecDbPoolCell*> &cells, AcGePoint3d &ptOrg)
|
|
{
|
|
if (!psz) return;
|
|
std::vector<CString> vec(0);
|
|
if (CoreTools::SplitString(psz, SP_CELL, vec) < 2) return;
|
|
|
|
ptOrg = CoreTools::stringToPoint3d(vec[0]);
|
|
|
|
AecDbPoolCell *pCell(NULL);
|
|
for (size_t i = 1; i < vec.size(); ++i)
|
|
{
|
|
pCell = new AecDbPoolCell();
|
|
pCell->FromScript(vec[i]);
|
|
cells.push_back(pCell);
|
|
}
|
|
}
|