316 lines
7.4 KiB
C++
316 lines
7.4 KiB
C++
#include "stdafx.h"
|
|
#include "resource.h"
|
|
#include "XSXLDlg.h"
|
|
#include "UITools.h"
|
|
#include "XSXL_TJXLDlg.h"
|
|
#include "AecDbEarthWorm.h"
|
|
#include "AecCableTool.h"
|
|
#include "KTCADUtilityEx.h"
|
|
|
|
|
|
static const Adesk::UInt16 kColorByBlock = 0;
|
|
static const Adesk::UInt16 kRed = 1;
|
|
static const Adesk::UInt16 kYellow = 2;
|
|
static const Adesk::UInt16 kGreen = 3;
|
|
static const Adesk::UInt16 kCyan = 4;
|
|
static const Adesk::UInt16 kBlue = 5;
|
|
static const Adesk::UInt16 kMagenta = 6;
|
|
static const Adesk::UInt16 kWhite = 7;
|
|
static const Adesk::UInt16 kColorByLayer = 256;
|
|
static void FreeBuffer(AcDbVoidPtrArray& arEntPtrs)
|
|
{
|
|
AcDbEntity* pEnt = NULL;
|
|
while (arEntPtrs.length() > 0 )
|
|
{
|
|
pEnt = (AcDbEntity*)arEntPtrs.last();
|
|
DELETE_PTR(pEnt);
|
|
arEntPtrs.removeLast();
|
|
}
|
|
}
|
|
|
|
#define DB_PATH _T("\\Plumbing.db")
|
|
|
|
IMPLEMENT_DYNAMIC(CXSXLDlg, CDialog)
|
|
|
|
CXSXLDlg::CXSXLDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(IDD_XSXL_DLG, pParent)
|
|
, m_linetypeID(AcDbObjectId::kNull)
|
|
, m_bFree(false)
|
|
{
|
|
UIDataCache::Read(_T("%i%d%i"), _T("CXSXLDlg"), &m_data.m_nCount, &m_data.m_dSpace, &m_data.m_nClr);
|
|
}
|
|
|
|
CXSXLDlg::~CXSXLDlg() { }
|
|
|
|
void CXSXLDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_LIST1, m_wndList);
|
|
DDX_Text(pDX, IDC_EDIT1, m_data.m_nFloor);
|
|
//DDV_MinMaxInt(pDX, m_data.m_nFloor, 1, 99);
|
|
DDX_Text(pDX, IDC_EDIT3, m_data.m_nCount);
|
|
DDV_MinMaxInt(pDX, m_data.m_nCount, 1, 99);
|
|
DDX_Control(pDX, IDC_COMBO1, m_wndLineTypeBox);
|
|
DDX_CBString(pDX, IDC_COMBO1, m_data.m_linetype);
|
|
DDX_Text(pDX, IDC_EDIT4, m_data.m_dSpace);
|
|
DDV_MinMaxDouble(pDX, m_data.m_dSpace, 0, 9999);
|
|
DDX_Control(pDX, IDC_EDIT3, m_ctrlCount);
|
|
DDX_Control(pDX, IDC_EDIT4, m_ctrlSpace);
|
|
}
|
|
|
|
BOOL CXSXLDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
CString path = FilePath::GetSysDir() + DB_PATH;
|
|
if (!m_dbSQLite.InitADOServer(path))
|
|
{
|
|
AfxMessageBox(CString(_T("数据库初始化失败,请检查 sys")) + DB_PATH + _T("文件是否存在."));
|
|
return FALSE;
|
|
}
|
|
|
|
if (m_wndLineTypeBox.GetCount())
|
|
m_wndLineTypeBox.SetCurSel(0);
|
|
|
|
initList();
|
|
|
|
if (m_bFree)
|
|
{
|
|
m_ctrlCount.EnableWindow(false);
|
|
m_ctrlSpace.EnableWindow(false);
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CXSXLDlg::initList()
|
|
{
|
|
m_wndList.SetExtendedStyle(LVS_EX_FULLROWSELECT);
|
|
m_wndList.InsertColumn(0, _T("型号"), LVCFMT_LEFT, 240);
|
|
m_wndList.InsertColumn(1, _T("外径(mm)"), LVCFMT_LEFT, 100);
|
|
m_wndList.InsertColumn(2, _T("弯曲半径与外径比值(mm)"), LVCFMT_LEFT, 100);
|
|
m_wndList.InsertColumn(3, _T("厂家"), LVCFMT_LEFT, 240);
|
|
refreshList();
|
|
m_wndList.SetItemState(0, LVIS_SELECTED, LVIS_SELECTED);
|
|
m_wndList.SetSelectionMark(0);
|
|
}
|
|
|
|
void CXSXLDlg::refreshList()
|
|
{
|
|
m_wndList.DeleteAllItems();
|
|
|
|
CString sSQL, sText;
|
|
sSQL = _T("select [型号],[外径],[弯曲半径与外径比值],[厂家] from AecCable order by [型号]");
|
|
|
|
CUIIValueTable table;
|
|
m_dbSQLite.GetSelData(sSQL, table);
|
|
table.ShowToListCtrl(&m_wndList);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CXSXLDlg, CDialog)
|
|
ON_BN_CLICKED(IDC_BUTTON1, &CXSXLDlg::OnBnClickedButton1)
|
|
ON_BN_CLICKED(IDC_BUTTON4, &CXSXLDlg::OnBnClickedButton4)
|
|
ON_STN_CLICKED(IDC_STATIC_COLOR, &CXSXLDlg::OnStnClickedStaticColor)
|
|
ON_WM_CTLCOLOR()
|
|
ON_BN_CLICKED(IDOK, &CXSXLDlg::OnBnClickedOk)
|
|
ON_BN_CLICKED(IDC_BUTTON52, &CXSXLDlg::OnBnClickedButton52)
|
|
END_MESSAGE_MAP()
|
|
|
|
void CXSXLDlg::OnBnClickedButton1()
|
|
{ //add
|
|
CString sModel(_T("")), sFactory(_T(""));
|
|
double dDn(.0), dRatio(.0);
|
|
int nItem = -1;
|
|
POSITION ps = m_wndList.GetFirstSelectedItemPosition();
|
|
if (ps != NULL)
|
|
nItem = m_wndList.GetNextSelectedItem(ps);
|
|
if (nItem != -1)
|
|
{
|
|
sModel = m_wndList.GetItemText(nItem, 0);
|
|
dDn = _ttof(m_wndList.GetItemText(nItem, 1));
|
|
dRatio = _ttof(m_wndList.GetItemText(nItem, 2));
|
|
sFactory = m_wndList.GetItemText(nItem, 3);
|
|
}
|
|
|
|
CXSXL_TJXLDlg dlg(sModel, sFactory, dDn, dRatio);
|
|
if (dlg.DoModal() != IDOK) return;
|
|
|
|
sModel = dlg.m_sModel;
|
|
sFactory = dlg.m_sFactory;
|
|
dDn = dlg.m_dDn;
|
|
dRatio = dlg.m_dRatio;
|
|
|
|
CString sql(_T(""));
|
|
sql.Format(_T("insert into [aeccable] values ('%s', '%d', '%d', '%s')")
|
|
, sModel, (int)(dDn+0.5), (int)(dRatio+0.5), sFactory);
|
|
|
|
m_dbSQLite.ExecuteSQL(sql);
|
|
|
|
refreshList();
|
|
}
|
|
|
|
void CXSXLDlg::OnBnClickedButton4()
|
|
{ //del
|
|
CString sModel(_T(""));
|
|
int nItem = -1;
|
|
POSITION ps = m_wndList.GetFirstSelectedItemPosition();
|
|
if (ps != NULL)
|
|
nItem = m_wndList.GetNextSelectedItem(ps);
|
|
if (nItem == -1)
|
|
{
|
|
AfxMessageBox(_T("请选择一行数据。"));
|
|
return;
|
|
}
|
|
|
|
sModel = m_wndList.GetItemText(nItem, 0);
|
|
|
|
CString sql(_T(""));
|
|
sql.Format(_T("delete from [aeccable] where [型号]='%s'"), sModel);
|
|
m_dbSQLite.ExecuteSQL(sql);
|
|
|
|
refreshList();
|
|
}
|
|
|
|
void CXSXLDlg::OnStnClickedStaticColor()
|
|
{
|
|
acedSetColorDialog(m_data.m_nClr, Adesk::kFalse, m_data.m_nClr);
|
|
Invalidate();
|
|
}
|
|
|
|
HBRUSH CXSXLDlg::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_COLOR)
|
|
{
|
|
COLORREF crColor = RGB(255, 255, 255);
|
|
if (m_data.m_nClr == kColorByLayer)
|
|
crColor = RGB(255, 255, 255);
|
|
else
|
|
crColor = acedGetRGB(m_data.m_nClr);
|
|
|
|
CRect rc;
|
|
pWnd->GetClientRect(rc);
|
|
pDC->FillSolidRect(rc, crColor);
|
|
}
|
|
}
|
|
return hbr;
|
|
}
|
|
|
|
int CXSXLDlg::GetPathPoints(AcGePoint3dArray& arPts) const
|
|
{
|
|
if (!m_arPtsPath.isEmpty())
|
|
{
|
|
arPts.append(m_arPtsPath);
|
|
}
|
|
return m_arPtsPath.length();
|
|
}
|
|
|
|
void CXSXLDlg::start()
|
|
{
|
|
}
|
|
|
|
void CXSXLDlg::OnBnClickedOk()
|
|
{
|
|
UpdateData(TRUE);
|
|
int nItem = -1;
|
|
POSITION ps = m_wndList.GetFirstSelectedItemPosition();
|
|
if (ps != NULL)
|
|
nItem = m_wndList.GetNextSelectedItem(ps);
|
|
if (nItem != -1)
|
|
{
|
|
m_data.m_sModel = m_wndList.GetItemText(nItem, 0);
|
|
m_data.m_dD = _ttof(m_wndList.GetItemText(nItem, 1));
|
|
m_data.m_dDn = _ttof(m_wndList.GetItemText(nItem, 2));
|
|
m_data.m_sFactory = m_wndList.GetItemText(nItem, 3);
|
|
}
|
|
else
|
|
{
|
|
AfxMessageBox(_T("请选择一行数据。"));
|
|
return;
|
|
}
|
|
|
|
m_data.m_bValid = true;
|
|
|
|
UIDataCache::Write(_T("%i%d%i"), _T("CXSXLDlg"), &m_data.m_nCount, &m_data.m_dSpace, &m_data.m_nClr);
|
|
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
|
|
void CXSXLDlg::OnBnClickedButton52()
|
|
{
|
|
// 选择pline线
|
|
UpdateData();
|
|
|
|
EnableWindow(FALSE);
|
|
CWnd* pFrame = acedGetAcadFrame();
|
|
pFrame->EnableWindow(TRUE);
|
|
ShowWindow(SW_HIDE);
|
|
pFrame->SetFocus();
|
|
|
|
m_arPtsPath.removeAll();
|
|
AcAxDocLock lock;
|
|
ads_point pt;
|
|
ads_name ent;
|
|
int nRes = acedEntSel(_T("\n请选择路径pline或3dpline线:"),ent,pt);
|
|
if (nRes == RTNORM)
|
|
{
|
|
AcDbObjectId id;
|
|
acdbGetObjectId(id,ent);
|
|
|
|
CString sText;
|
|
AcDbEntity* pEnt = NULL;
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,id,AcDb::kForRead))
|
|
{
|
|
AcDbPolyline* pPl = AcDbPolyline::cast(pEnt);
|
|
AcDb3dPolyline* pPl3d = AcDb3dPolyline::cast(pEnt);
|
|
AcGePoint3d ptGe;
|
|
|
|
if (pPl != NULL)
|
|
{
|
|
int nNum = pPl->numVerts();
|
|
for (int i = 0;i < nNum;i++)
|
|
{
|
|
pPl->getPointAt(i,ptGe);
|
|
m_arPtsPath.append(ptGe);
|
|
}
|
|
}
|
|
else if (pPl3d != NULL)
|
|
{
|
|
AcDbObjectIterator* pIt = pPl3d->vertexIterator();
|
|
if (pIt != NULL)
|
|
{
|
|
int nFoundAt = -1;
|
|
for (pIt->start(); !pIt->done(); pIt->step())
|
|
{
|
|
AcDb3dPolylineVertex* pVertx = NULL;
|
|
if (Acad::eOk == pPl3d->openVertex(pVertx, pIt->objectId(), AcDb::kForRead))
|
|
{
|
|
ptGe = pVertx->position();
|
|
if (!m_arPtsPath.find(ptGe, nFoundAt))
|
|
{
|
|
m_arPtsPath.append(ptGe);
|
|
}
|
|
pVertx->close();
|
|
}
|
|
}
|
|
DELETE_PTR(pIt);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
acutPrintf(_T("\n选择的曲线不是pline或3dpline线!"));
|
|
}
|
|
pEnt->close();
|
|
}
|
|
}
|
|
|
|
pFrame->EnableWindow(FALSE);
|
|
ShowWindow(SW_SHOW);
|
|
EnableWindow(TRUE);
|
|
|
|
UpdateData(FALSE);
|
|
}
|