254 lines
5.0 KiB
C++
254 lines
5.0 KiB
C++
#include "stdafx.h"
|
|
#include "stdarx.h"
|
|
#include "CYXKKDlg.h"
|
|
|
|
#include "AecDbECFitting.h"
|
|
#include "AecDbECableTray.h"
|
|
#include "AcGiViewDraw.h"
|
|
#include "KTCadUtility.h"
|
|
|
|
static AcGePoint3d MidPoint(const AcGePoint3d &pt1, const AcGePoint3d &pt2)
|
|
{
|
|
return AcGePoint3d((pt1.x + pt2.x) / 2.0, (pt1.y + pt2.y) / 2.0, (pt1.z + pt2.z) / 2.0);
|
|
}
|
|
|
|
|
|
IMPLEMENT_DYNAMIC(CYXKKDlg, CDialog)
|
|
|
|
CYXKKDlg::CYXKKDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CYXKKDlg::IDD, pParent)
|
|
, m_dLen(300)
|
|
, m_sSys(_T("动力低压(0.6-1kv)"))
|
|
, m_dL(0)
|
|
, m_dW(0)
|
|
, m_bRectOk(FALSE)
|
|
, m_pOwner(NULL) { }
|
|
|
|
CYXKKDlg::~CYXKKDlg()
|
|
{
|
|
if (m_pOwner != NULL)
|
|
{
|
|
delete m_pOwner;
|
|
}
|
|
}
|
|
|
|
void CYXKKDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Text(pDX, IDC_EDIT3, m_dLen);
|
|
DDX_CBString(pDX, IDC_COMBO1, m_sSys);
|
|
DDX_Text(pDX, IDC_EDIT4, m_dL);
|
|
DDX_Text(pDX, IDC_EDIT5, m_dW);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CYXKKDlg, CDialog)
|
|
ON_BN_CLICKED(IDOK, &CYXKKDlg::OnBnClickedOk)
|
|
ON_BN_CLICKED(IDC_BUTTON1, &CYXKKDlg::OnBnClickedButton1)
|
|
ON_BN_CLICKED(IDC_BUTTON2, &CYXKKDlg::OnBnClickedButton2)
|
|
|
|
ON_WM_CTLCOLOR()
|
|
END_MESSAGE_MAP()
|
|
|
|
BOOL CYXKKDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
CRect rc;
|
|
GetDlgItem(IDC_STATIC_VIEW)->GetWindowRect(rc);
|
|
GetDlgItem(IDC_STATIC_VIEW)->ShowWindow(SW_HIDE);
|
|
ScreenToClient(rc);
|
|
|
|
m_wndPreview.Create(rc, this, IDC_STATIC_VIEW);
|
|
m_wndPreview.Init(1, 1, -1, NULL);
|
|
|
|
AcDbEntity *pEnt = NULL;
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt, m_id, AcDb::kForRead))
|
|
{
|
|
m_pOwner = (AcDbEntity*)pEnt->clone();
|
|
|
|
AcGiViewDraw dc(NULL, NULL);
|
|
AecDbEcFitting *pFit = AecDbEcFitting::cast(m_pOwner);
|
|
if (pFit != NULL)
|
|
{
|
|
pFit->Draw3d(dc);
|
|
}
|
|
|
|
AecDbECableTray* pTray = AecDbECableTray::cast(m_pOwner);
|
|
if (pTray != NULL)
|
|
{
|
|
pTray->Draw3d(dc);
|
|
}
|
|
pEnt->close();
|
|
}
|
|
|
|
CString sName = _T("桥架");
|
|
if (m_pOwner != NULL)
|
|
{
|
|
m_wndPreview.InitSingleCtrlFor3D(m_pOwner, sName, FALSE);
|
|
}
|
|
m_wndPreview.Redraw();
|
|
|
|
UpdateData(FALSE);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CYXKKDlg::OnBnClickedOk()
|
|
{
|
|
UpdateData();
|
|
if (!m_bRectOk)
|
|
{
|
|
AfxMessageBox(_T("没有选择矩形引出开口!"));
|
|
return;
|
|
}
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
BOOL CYXKKDlg::GetUserInf(AecUserInterface &inf)
|
|
{
|
|
memcpy(inf.ptGe, m_ptGe, sizeof(AcGePoint3d) * 4);
|
|
inf.nPoints = 4;
|
|
|
|
AcGeVector3d vt1 = m_ptGe[1] - m_ptGe[0];
|
|
AcGeVector3d vt2 = m_ptGe[3] - m_ptGe[0];
|
|
inf.vtDir = vt1.crossProduct(vt2);
|
|
inf.vtDir.normalize();
|
|
inf.vtDir *= m_dLen;
|
|
_tcscpy(inf.szSys, (LPCTSTR)m_sSys);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
//选择截面
|
|
void CYXKKDlg::OnBnClickedButton1()
|
|
{
|
|
UpdateData(TRUE);
|
|
acedGetAcadFrame()->EnableWindow(TRUE);
|
|
ShowWindow(SW_HIDE);
|
|
acedGetAcadFrame()->SetFocus();
|
|
|
|
struct resbuf *pRb = acutBuildList(RTDXF0, _T("LWPOLYLINE"), 0);
|
|
|
|
ads_name ent1;
|
|
int nRes = CKTCadUtility::SelectEntity(_T("\n请选择矩形开口:"), ent1, pRb);
|
|
if (nRes == RTNORM)
|
|
{
|
|
AcDbObjectId id;
|
|
acdbGetObjectId(id, ent1);
|
|
|
|
AcDbEntity *pEnt = NULL;
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead))
|
|
{
|
|
AcDbPolyline *pPl = AcDbPolyline::cast(pEnt);
|
|
if (pPl != NULL)
|
|
{
|
|
//投影到当前平面平视面
|
|
AcGeMatrix3d mat;
|
|
acedGetCurrentUCS(mat);
|
|
|
|
AcGePlane plan = AcGePlane::kXYPlane;
|
|
plan.transformBy(mat);
|
|
|
|
//确认是矩形开口
|
|
ads_point pt;
|
|
int nPts = pPl->numVerts();
|
|
if (nPts <= 5 && pPl->isClosed())
|
|
{
|
|
for (int i = 0;i < 4;i++)
|
|
{
|
|
pPl->getPointAt(i, m_ptGe[i]);
|
|
m_ptGe[i] = m_ptGe[i].orthoProject(plan);
|
|
}
|
|
|
|
m_dL = m_ptGe[1].distanceTo(m_ptGe[0]);
|
|
m_dW = m_ptGe[3].distanceTo(m_ptGe[0]);
|
|
m_bRectOk = TRUE;
|
|
|
|
//显示方向
|
|
ShowUserInf();
|
|
|
|
}
|
|
else
|
|
{
|
|
acedAlert(_T("选择的PL线不是闭合的矩形线!"));
|
|
}
|
|
}
|
|
|
|
pEnt->close();
|
|
}
|
|
}
|
|
|
|
ShowWindow(SW_SHOW);
|
|
SetFocus();
|
|
acedGetAcadFrame()->EnableWindow(FALSE);
|
|
EnableWindow(TRUE);
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
void CYXKKDlg::OnBnClickedButton2()
|
|
{
|
|
if (!m_bRectOk)
|
|
{
|
|
AfxMessageBox(_T("请先选择开口的截面曲线!"));
|
|
return;
|
|
}
|
|
AcGePoint3d pt;
|
|
for (int i = 0;i < 2;i++)
|
|
{
|
|
pt = m_ptGe[3 - i];
|
|
m_ptGe[3 - i] = m_ptGe[i];
|
|
m_ptGe[i] = pt;
|
|
}
|
|
ShowUserInf();
|
|
}
|
|
|
|
void CYXKKDlg::ShowUserInf()
|
|
{
|
|
AecUserInterface inf;
|
|
GetUserInf(inf);
|
|
|
|
m_wndPreview.Clear();
|
|
delete m_pOwner;
|
|
|
|
AcDbEntity *pEnt = NULL;
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt, m_id, AcDb::kForRead))
|
|
{
|
|
m_pOwner = (AcDbEntity *)pEnt->clone();
|
|
pEnt->close();
|
|
}
|
|
|
|
CString sName = _T("桥架");
|
|
AcGiViewDraw dc(NULL, NULL);
|
|
AecDbEcFitting *pFit = AecDbEcFitting::cast(m_pOwner);
|
|
if (pFit != NULL)
|
|
{
|
|
pFit->RemoveUserInterface(0);
|
|
pFit->AddUserInterface(inf);
|
|
pFit->Draw3d(dc);
|
|
}
|
|
|
|
AecDbECableTray *pTray = AecDbECableTray::cast(m_pOwner);
|
|
if (pTray != NULL)
|
|
{
|
|
pTray->RemoveUserInterface(0);
|
|
pTray->AddUserInterface(inf);
|
|
pTray->Draw3d(dc);
|
|
}
|
|
|
|
m_wndPreview.InitSingleCtrlFor3D(m_pOwner, sName, FALSE);
|
|
}
|
|
|
|
HBRUSH CYXKKDlg::OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor)
|
|
{
|
|
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
|
|
if (nCtlColor == CTLCOLOR_STATIC)
|
|
{
|
|
if (pWnd != NULL && pWnd->GetDlgCtrlID() == IDC_STATIC_TIP)
|
|
{
|
|
COLORREF crColor = RGB(255, 0, 0);
|
|
pDC->SetTextColor(crColor);
|
|
}
|
|
}
|
|
return hbr;
|
|
}
|