508 lines
9.7 KiB
C++
508 lines
9.7 KiB
C++
#include "stdafx.h"
|
|
#include "JMSJDlg.h"
|
|
#include "CoreTools.h"
|
|
#include "JUXCDlg.h"
|
|
#include "GLTKDlg.h"
|
|
#include "BYCDlg.h"
|
|
#include "UXCDlg.h"
|
|
#include "KTCADUtilityEx.h"
|
|
#include "KTCadUtility.h"
|
|
|
|
static void FreeBuffer(AcDbVoidPtrArray& arTextPtrs)
|
|
{
|
|
AcDbEntity* pEnt = NULL;
|
|
while (arTextPtrs.length() > 0)
|
|
{
|
|
pEnt = (AcDbEntity*)arTextPtrs.first();
|
|
arTextPtrs.removeFirst();
|
|
DELETE_PTR(pEnt);
|
|
}
|
|
}
|
|
|
|
IMPLEMENT_DYNAMIC(CJMSJDlg, CDialog)
|
|
|
|
CJMSJDlg::CJMSJDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CJMSJDlg::IDD, pParent)
|
|
{
|
|
}
|
|
|
|
CJMSJDlg::~CJMSJDlg(void)
|
|
{
|
|
DELETE_PTR(m_curSection.pReg);
|
|
}
|
|
|
|
void CJMSJDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CJMSJDlg, CDialog)
|
|
ON_BN_CLICKED(IDC_BTADDTODB, &CJMSJDlg::OnBnClickedBtaddtodb)
|
|
ON_BN_CLICKED(IDC_BUTTON2, &CJMSJDlg::OnBnClickedButton2)
|
|
ON_BN_CLICKED(IDC_BUTTON3, &CJMSJDlg::OnBnClickedButton3)
|
|
ON_BN_CLICKED(IDC_BUTTON7, &CJMSJDlg::OnBnClickedButton7)
|
|
ON_BN_CLICKED(IDC_BUTTON1, &CJMSJDlg::OnBnClickedButton1)
|
|
ON_BN_CLICKED(IDC_BTSELFROMDB, &CJMSJDlg::OnBnClickedBtselfromdb)
|
|
ON_MESSAGE(WM_ACAD_KEEPFOCUS, &CJMSJDlg::onAcadKeepFocus)
|
|
ON_BN_CLICKED(IDCANCEL, &CJMSJDlg::OnCancle)
|
|
ON_BN_CLICKED(IDOK, &CJMSJDlg::OnBnClickedOk)
|
|
ON_WM_DESTROY()
|
|
ON_WM_CLOSE()
|
|
ON_BN_CLICKED(IDC_BUTTON4, &CJMSJDlg::OnBnClickedButton4)
|
|
END_MESSAGE_MAP()
|
|
|
|
BOOL CJMSJDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
// 子类化控件对象
|
|
if (!m_wndViewCtrl.SubclassDlgItem(IDC_STATIC_FRM, this))
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
if ( m_curSection.pReg == NULL)
|
|
{
|
|
ShowLastSection();
|
|
}
|
|
else
|
|
{
|
|
ShowCurSection();
|
|
}
|
|
|
|
UpdateData(FALSE);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CJMSJDlg::ShowLastSection()
|
|
{
|
|
//1.截面
|
|
CString sFullPath = FilePath::getSystemTemporaryFolder();
|
|
sFullPath.MakeLower();
|
|
sFullPath += _T("\\JMSJ.sat");
|
|
|
|
AcDbVoidPtrArray arBodyPtrs;
|
|
if ( Acad::eOk == AcDbBody::acisIn(sFullPath,arBodyPtrs) )
|
|
{
|
|
if (arBodyPtrs.length() > 0)//==1
|
|
{
|
|
AcDbEntity* pEnt = (AcDbEntity*)arBodyPtrs.first();
|
|
|
|
AcDbRegion* pRegion = AcDbRegion::cast(pEnt);
|
|
if (pRegion != NULL)
|
|
{
|
|
m_curSection.pReg = pRegion;
|
|
}
|
|
|
|
if (m_curSection.pReg != NULL)
|
|
{
|
|
ShowCurSection();
|
|
}
|
|
}
|
|
}
|
|
|
|
UpdateData(FALSE);
|
|
UpdateWindow();
|
|
}
|
|
|
|
void CJMSJDlg::ShowCurSection()
|
|
{
|
|
if (m_curSection.pReg != NULL)
|
|
{
|
|
m_arDrawBuffer.removeAll();
|
|
m_wndViewCtrl.clearAll();
|
|
m_wndViewCtrl.init(true);
|
|
m_wndViewCtrl.SetOrbitFlag(OBF_PAN | OBF_ZOOM | OBF_COTE);
|
|
|
|
AcDbExtents exts;
|
|
m_curSection.pReg->getGeomExtents(exts);
|
|
m_wndViewCtrl.InitFromCurrentView2D(exts,true);
|
|
|
|
m_wndViewCtrl.Add(m_curSection.pReg);
|
|
m_arDrawBuffer.append(m_curSection.pReg);
|
|
|
|
m_wndViewCtrl.view()->invalidate();
|
|
m_wndViewCtrl.Invalidate();
|
|
m_wndViewCtrl.RedrawWindow();
|
|
}
|
|
}
|
|
|
|
void CJMSJDlg::OnBnClickedOk()
|
|
{
|
|
EndDialog(TRUE);
|
|
}
|
|
|
|
//入库
|
|
void CJMSJDlg::OnBnClickedBtaddtodb()
|
|
{
|
|
UpdateData(TRUE);
|
|
|
|
if (!m_curSection.pReg) return;
|
|
CString sFullPath = FilePath::getSystemTemporaryFolder() + _T("\\JMSJ.sat");
|
|
|
|
CString sRegionScrp = _T("");
|
|
CString sLine;
|
|
AcDbVoidPtrArray arBodyPtrs;
|
|
arBodyPtrs.append(m_curSection.pReg);
|
|
|
|
if (Acad::eOk == AcDbBody::acisOut(sFullPath, arBodyPtrs))
|
|
{
|
|
CFile file;
|
|
if (file.Open(sFullPath, CFile::modeRead))
|
|
{
|
|
ULONGLONG dwFileLength = file.GetLength();
|
|
char* pszTxt = new char[dwFileLength];
|
|
|
|
file.Read(pszTxt, dwFileLength);
|
|
|
|
sRegionScrp = pszTxt;
|
|
DELETE_ARR_(pszTxt);
|
|
|
|
file.Close();
|
|
}
|
|
}
|
|
|
|
CAcModuleResourceOverride myResources;
|
|
CGLTKDlg dlg(CGLTKDlg::eInput, _T("poolstandard.db"), _T("standard"), CGLTKDlg::drawRegion);
|
|
dlg.SetCrossSectionScr(sRegionScrp);
|
|
dlg.DoModal();
|
|
}
|
|
|
|
//矩形槽
|
|
void CJMSJDlg::OnBnClickedButton2()
|
|
{
|
|
CJUXCDlg dlg;
|
|
if (IDOK == dlg.DoModal() )
|
|
{
|
|
//以底面中心
|
|
AcGePoint3d pt[9];
|
|
pt[0].set(0,0,0);
|
|
pt[0].x -= 0.5 * dlg.m_dL;
|
|
|
|
pt[1] = pt[0];
|
|
pt[1].y += dlg.m_dH;
|
|
|
|
pt[2] = pt[1];
|
|
pt[2].x += dlg.m_dt;
|
|
|
|
pt[3] = pt[2];
|
|
pt[3].y -= (dlg.m_dH - dlg.m_dt);
|
|
|
|
pt[4] = pt[3];
|
|
pt[4].x += (dlg.m_dL - 2.0 * dlg.m_dt);
|
|
|
|
pt[5] = pt[2];
|
|
pt[5].x += (dlg.m_dL - 2.0 * dlg.m_dt);
|
|
|
|
pt[6] = pt[5];
|
|
pt[6].x += dlg.m_dt;
|
|
|
|
pt[7] = pt[0];
|
|
pt[7].x += dlg.m_dL;
|
|
|
|
pt[8] = pt[0];
|
|
|
|
AcDbLine* pLn = NULL;
|
|
AcDbVoidPtrArray arLnPtrs;
|
|
|
|
for (int i = 0;i < 8;i++)
|
|
{
|
|
pLn = new AcDbLine;
|
|
pLn->setStartPoint(pt[i]);
|
|
pLn->setEndPoint(pt[i+1]);
|
|
|
|
arLnPtrs.append(pLn);
|
|
}
|
|
|
|
AcDbVoidPtrArray arRegPtrs;
|
|
AcDbRegion::createFromCurves(arLnPtrs,arRegPtrs);
|
|
|
|
FreeBuffer(arLnPtrs);
|
|
|
|
if (arRegPtrs.length() == 1)
|
|
{
|
|
AcDbRegion* pReg = (AcDbRegion*)arRegPtrs.first();
|
|
|
|
m_curSection.pt.set(0,0,0);
|
|
m_curSection.pReg = pReg;
|
|
|
|
ShowCurSection();
|
|
}
|
|
}
|
|
}
|
|
|
|
//半圆槽
|
|
void CJMSJDlg::OnBnClickedButton3()
|
|
{
|
|
CBYCDlg dlg;
|
|
if (dlg.DoModal() != IDOK) return;
|
|
|
|
double R(dlg.m_dR), r(dlg.m_dR - dlg.m_dT);
|
|
AcGeVector2d vtX(AcGeVector2d::kXAxis), vtY(AcGeVector2d::kYAxis);
|
|
AcGePoint2d ptO(AcGePoint2d::kOrigin + vtY * r);
|
|
|
|
AcDbPolyline poly;
|
|
poly.addVertexAt(0, ptO - vtX * r);
|
|
poly.addVertexAt(1, ptO - vtX * R, 1);
|
|
poly.addVertexAt(2, ptO + vtX * R);
|
|
poly.addVertexAt(3, ptO + vtX * r, -1);
|
|
poly.setClosed(true);
|
|
|
|
AcDbRegion *pReg = CoreTools::createRegion(&poly);
|
|
if (!pReg) return;
|
|
|
|
m_curSection.pt.set(0, 0, 0);
|
|
if (m_curSection.pReg)
|
|
DELETE_PTR(m_curSection.pReg);
|
|
m_curSection.pReg = pReg;
|
|
|
|
ShowCurSection();
|
|
}
|
|
|
|
//V型槽
|
|
void CJMSJDlg::OnBnClickedButton7()
|
|
{
|
|
|
|
CUXCDlg dlg;
|
|
if (dlg.DoModal() != IDOK) return;
|
|
|
|
AcGeVector2d vtX(AcGeVector2d::kXAxis), vtY(AcGeVector2d::kYAxis);
|
|
AcGePoint2d pt(AcGePoint2d::kOrigin);
|
|
|
|
// 内小径,内大径
|
|
double inn_R(dlg.m_dUp * .5), inn_r(dlg.m_dBom * .5);
|
|
// 高,壁厚
|
|
double h(dlg.m_dH), t(dlg.m_dT);
|
|
// 总高
|
|
double H(h + t);
|
|
|
|
double alpha = atan((inn_R - inn_r) / h);
|
|
|
|
// 外大径
|
|
double out_R(inn_R + t / cos(alpha));
|
|
|
|
// 外小径
|
|
double out_r(out_R - H * tan(alpha));
|
|
|
|
AcDbPolyline poly;
|
|
|
|
pt += vtY * h;
|
|
pt -= vtX * out_R;
|
|
poly.addVertexAt(0, pt);
|
|
|
|
pt -= vtY * H;
|
|
pt += vtX * (out_R - out_r);
|
|
poly.addVertexAt(1, pt);
|
|
|
|
pt += vtX * 2 * out_r;
|
|
poly.addVertexAt(2, pt);
|
|
|
|
pt += vtY * H;
|
|
pt += vtX * (out_R - out_r);
|
|
poly.addVertexAt(3, pt);
|
|
|
|
pt -= vtX * (out_R - inn_R);
|
|
poly.addVertexAt(4, pt);
|
|
|
|
pt -= vtY * h;
|
|
pt -= vtX * (inn_R - inn_r);
|
|
poly.addVertexAt(5, pt);
|
|
|
|
pt -= vtX * 2 * inn_r;
|
|
poly.addVertexAt(6, pt);
|
|
|
|
pt += vtY * h;
|
|
pt -= vtX * (inn_R - inn_r);
|
|
poly.addVertexAt(7, pt);
|
|
|
|
poly.setClosed(true);
|
|
|
|
AcDbRegion *pReg = CoreTools::createRegion(&poly);
|
|
if (!pReg) return;
|
|
|
|
m_curSection.pt.set(0, 0, 0);
|
|
if (m_curSection.pReg)
|
|
DELETE_PTR(m_curSection.pReg);
|
|
m_curSection.pReg = pReg;
|
|
|
|
ShowCurSection();
|
|
}
|
|
|
|
//自定义槽
|
|
void CJMSJDlg::OnBnClickedButton1()
|
|
{
|
|
ShowWindow(SW_HIDE);
|
|
|
|
do
|
|
{
|
|
// 选PLine线
|
|
ads_name ent;
|
|
ads_point adsPt;
|
|
if (acedEntSel(_T("\n请选择在XOY面上的闭合多段线或面域:"), ent, adsPt) != RTNORM) break;
|
|
|
|
AcDbObjectId idPoly(AcDbObjectId::kNull);
|
|
acdbGetObjectId(idPoly, ent);
|
|
if (!idPoly.isValid()) break;
|
|
|
|
if (acedGetPoint(NULL, _T("\n请选择内底面基线对齐点:"), adsPt) != RTNORM) break;
|
|
|
|
AcGePoint3d ptO(asPnt3d(adsPt));
|
|
CoreTools::UCS2WCS(ptO, ptO);
|
|
|
|
AcDbEntity* pEnt = NULL;
|
|
AcDbPolyline *pPoly(NULL);
|
|
AcDbRegion *pReg = NULL;
|
|
|
|
if ( Acad::eOk == acdbOpenAcDbEntity(pEnt,idPoly,AcDb::kForRead))
|
|
{
|
|
pPoly = AcDbPolyline::cast(pEnt);
|
|
if (pPoly != NULL)
|
|
{
|
|
pPoly = (AcDbPolyline*)pEnt->clone();
|
|
}
|
|
|
|
pReg = AcDbRegion::cast(pEnt);
|
|
if (pReg != NULL)
|
|
{
|
|
pReg = (AcDbRegion *)pReg->clone();
|
|
}
|
|
|
|
pEnt->close();
|
|
}
|
|
|
|
if (pPoly == NULL && pReg == NULL)
|
|
{
|
|
acutPrintf(_T("\n请选择多一段闭合多段线或面域!"));
|
|
break;
|
|
}
|
|
|
|
if (pPoly != NULL)
|
|
{
|
|
|
|
pPoly->setClosed(true);
|
|
pReg = CoreTools::createRegion(pPoly);
|
|
if (!pReg)
|
|
{
|
|
AfxMessageBox(_T("多段线生成面域失败,请检查所选择的多段线!"));
|
|
break;
|
|
}
|
|
}
|
|
|
|
//AcGePoint3d::kOrigin - ptO;
|
|
AcGeVector3d vt = ptO.asVector();
|
|
vt.negate();
|
|
AcGeMatrix3d xform;
|
|
xform.setToTranslation(vt);
|
|
pReg->transformBy(xform);
|
|
|
|
m_curSection.pt.set(0, 0, 0);
|
|
if (m_curSection.pReg)
|
|
DELETE_PTR(m_curSection.pReg);
|
|
m_curSection.pReg = pReg;
|
|
|
|
break;
|
|
|
|
} while (false);
|
|
|
|
ShowCurSection();
|
|
ShowWindow(SW_SHOW);
|
|
}
|
|
|
|
//从标准库选择
|
|
void CJMSJDlg::OnBnClickedBtselfromdb()
|
|
{
|
|
|
|
CAcModuleResourceOverride myResources;
|
|
//
|
|
CGLTKDlg dlg(CGLTKDlg::eSelect, _T("poolstandard.db"), _T("standard"), CGLTKDlg::drawRegion);
|
|
if ( IDOK == dlg.DoModal() )
|
|
{
|
|
CString sScr,sScrT;
|
|
if (dlg.GetCrossSectionScr(sScr))
|
|
{
|
|
CString sFullPath = FilePath::getSystemTemporaryFolder();
|
|
sFullPath.MakeLower();
|
|
sFullPath += _T("\\JMSJ.sat");
|
|
|
|
CStdioFile file;
|
|
if (file.Open(sFullPath,CFile::modeCreate |CFile::modeWrite ))
|
|
{
|
|
file.WriteString(sScr);
|
|
file.Close();
|
|
}
|
|
|
|
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)
|
|
{
|
|
m_curSection.pReg = pRegion;
|
|
}
|
|
|
|
if (m_curSection.pReg != NULL)
|
|
{
|
|
ShowCurSection();
|
|
}
|
|
}
|
|
}
|
|
UpdateData(FALSE);
|
|
UpdateWindow();
|
|
}
|
|
}
|
|
}
|
|
|
|
LONG_PTR CJMSJDlg::onAcadKeepFocus(UINT_PTR, LONG_PTR)
|
|
{
|
|
POINT pt;
|
|
::GetCursorPos(&pt);
|
|
CRect rect;
|
|
GetWindowRect(&rect);
|
|
if (!(rect.PtInRect(pt)))
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
//如果当前有命令在执行中,提示
|
|
struct resbuf rb;
|
|
acedGetVar(_T("CMDNAMES"), &rb);
|
|
|
|
if (rb.restype == RTSTR && rb.resval.rstring != NULL)
|
|
{
|
|
if (_tcslen(rb.resval.rstring) > 0)
|
|
{
|
|
acedPostCommand(_T("\x03"));
|
|
}
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CJMSJDlg::OnClose()
|
|
{
|
|
EndDialog(TRUE);
|
|
}
|
|
|
|
void CJMSJDlg::OnCancle()
|
|
{
|
|
EndDialog(TRUE);
|
|
}
|
|
|
|
void CJMSJDlg::OnBnClickedButton4()
|
|
{
|
|
if (m_curSection.pReg != NULL)
|
|
{
|
|
AcAxDocLock lock;
|
|
AcDbRegion* pRegCln = (AcDbRegion*)m_curSection.pReg->clone();
|
|
if (pRegCln != NULL)
|
|
{
|
|
CKTCadUtility::AddToBlockTableRecord(pRegCln);
|
|
pRegCln->close();
|
|
}
|
|
}
|
|
}
|