Files
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

285 lines
6.6 KiB
C++

#include "stdafx.h"
#include "EquRotateDlg.h"
#include "AecDbEwEquipment.h"
#include "KTCadUtility.h"
IMPLEMENT_DYNAMIC(CEquRotateDlg, CDialog)
CEquRotateDlg::CEquRotateDlg(CWnd* pParent /*=NULL*/)
: CDialog(CEquRotateDlg::IDD, pParent)
, m_dAngle(90)
, m_sAxisDir(_T(""))
{
}
CEquRotateDlg::~CEquRotateDlg()
{
}
void CEquRotateDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDITANG, m_dAngle);
DDX_Control(pDX, IDC_LISTINF, m_wndListInf);
DDX_Text(pDX, IDC_EDITAXISCUR, m_sAxisDir);
}
BEGIN_MESSAGE_MAP(CEquRotateDlg, CDialog)
ON_LBN_SELCHANGE(IDC_LISTINF, &CEquRotateDlg::OnLbnSelchangeListinf)
ON_BN_CLICKED(IDC_BTAPLY, &CEquRotateDlg::OnBnClickedBtaply)
ON_WM_CLOSE()
ON_BN_CLICKED(IDCANCEL, &CEquRotateDlg::OnBnClickedCancel)
ON_MESSAGE( WM_ACAD_KEEPFOCUS, &CEquRotateDlg::onAcadKeepFocus )
ON_BN_CLICKED(IDC_BTCUREQU, &CEquRotateDlg::OnBnClickedBtcurequ)
ON_BN_CLICKED(IDC_BTLINE, &CEquRotateDlg::OnBnClickedBtline)
END_MESSAGE_MAP()
LONG_PTR CEquRotateDlg::onAcadKeepFocus( UINT_PTR, LONG_PTR )
{
POINT pt;
::GetCursorPos(&pt);
CRect rect;
GetWindowRect(&rect);
if(!(rect.PtInRect(pt)))
{
return FALSE;
}
return TRUE;
}
BOOL CEquRotateDlg::OnInitDialog()
{
CDialog::OnInitDialog();
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc);
AcDbEntity* pEnt = NULL;
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,m_idEqu,AcDb::kForRead))
{
AecDbEwEquipment* pWEqu = AecDbEwEquipment::cast(pEnt);
if (pWEqu != NULL)
{
CString sText;
AecInterface inf;
for (int i = 0;i < pWEqu->GetInterfaceCount();i++)
{
pWEqu->GetInterface(i,inf);
m_arInfDirs.append(inf.vtDir);
m_arInfPts.append(inf.ptPos);
sText.Format(_T("接口-%d"),i + 1);
m_wndListInf.InsertString(i,sText);
}
m_wndListInf.InsertString(i++,_T("X"));
m_arInfDirs.append(AcGeVector3d::kXAxis);
m_arInfPts.append(AcGePoint3d::kOrigin);
m_wndListInf.InsertString(i++,_T("Y"));
m_arInfDirs.append(AcGeVector3d::kYAxis);
m_arInfPts.append(AcGePoint3d::kOrigin);
m_wndListInf.InsertString(i++,_T("Z"));
m_arInfDirs.append(AcGeVector3d::kZAxis);
m_arInfPts.append(AcGePoint3d::kOrigin);
}
pEnt->close();
}
acDocManager->unlockDocument(pDoc);
return TRUE;
}
void CEquRotateDlg::SetEquObjectID(AcDbObjectId id)
{
m_idEqu = id;
}
BOOL CEquRotateDlg::OnCommand(WPARAM wParam, LPARAM lParam)
{
switch (LOWORD(wParam))
{
case IDOK:
return TRUE;
default:
break;
}
return CDialog::OnCommand(wParam, lParam);
}
void CEquRotateDlg::OnLbnSelchangeListinf()
{
int nSel = m_wndListInf.GetCurSel();
if (nSel != -1)
{
//显示接口的方向箭头
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc);
AcDbEntity* pEnt = NULL;
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,m_idEqu,AcDb::kForWrite))
{
AecDbEwEquipment* pWEqu = AecDbEwEquipment::cast(pEnt);
if (pWEqu != NULL)
{
if (nSel < pWEqu->GetInterfaceCount() )
{
pWEqu->ActiveInterface(nSel,TRUE);
pWEqu->recordGraphicsModified();
}
}
pEnt->close();
}
acDocManager->unlockDocument(pDoc);
AcGeVector3d vt = m_arInfDirs.at(nSel);
m_sAxisDir.Format(_T("%.1f,%.1f,%.1f"),vt.x,vt.y,vt.z);
UpdateData(FALSE);
}
}
void CEquRotateDlg::OnBnClickedBtaply()
{
UpdateData();
int nSel = m_wndListInf.GetCurSel();
if (nSel != -1)
{
//显示接口的方向箭头
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc);
AcDbEntity* pEnt = NULL;
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,m_idEqu,AcDb::kForWrite))
{
AecDbEwEquipment* pWEqu = AecDbEwEquipment::cast(pEnt);
if (pWEqu != NULL)
{
AcGeVector3d vtAxis = m_arInfDirs.at(nSel);
AcGePoint3d ptPos = m_arInfPts.at(nSel);
AcGePoint3d ptIns;
AcGeVector3d vtDirT;
pWEqu->GetInsert(ptIns,vtDirT);
AcGeMatrix3d xform;
xform.setToRotation(m_dAngle * PI / 180.0,vtAxis);//插入点旋转?
pWEqu->AddTransform(xform);
}
pEnt->close();
}
acDocManager->unlockDocument(pDoc);
}
}
void CEquRotateDlg::OnClose()
{
int nSel = m_wndListInf.GetCurSel();
if (nSel != -1)
{
//显示接口的方向箭头
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc);
AcDbEntity* pEnt = NULL;
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,m_idEqu,AcDb::kForWrite))
{
AecDbEwEquipment* pWEqu = AecDbEwEquipment::cast(pEnt);
if (pWEqu != NULL)
{
pWEqu->ActiveInterface(nSel,FALSE);
pWEqu->recordGraphicsModified();
}
pEnt->close();
}
acDocManager->unlockDocument(pDoc);
}
CDialog::OnClose();
delete this;
}
void CEquRotateDlg::OnBnClickedCancel()
{
OnClose();
}
void CEquRotateDlg::OnBnClickedBtcurequ()
{
TCHAR szBuf[64];
memset(szBuf,0,sizeof(szBuf));
_tcscpy(szBuf, _T("AEC_DBWEQUIPMENT"));
struct resbuf rb;
rb.restype = 0;
rb.resval.rstring = szBuf;
rb.rbnext = NULL;
ads_name ss,ent;
int nRes = acedSSGet(_T("I"),NULL,NULL,&rb,ss);
if (nRes == RTNORM)
{
Adesk::Int32 lLen = 0L;
acedSSLength(ss,&lLen);
if (lLen > 0)
{
//关闭上个设备的箭头
//显示接口的方向箭头
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc);
AcDbEntity* pEnt = NULL;
if ( Acad::eOk == acdbOpenAcDbEntity(pEnt,m_idEqu,AcDb::kForWrite))
{
AecDbEwEquipment* pWEqu = AecDbEwEquipment::cast(pEnt);
if (pWEqu != NULL)
{
pWEqu->ActiveInterface(-1,FALSE);
pWEqu->recordGraphicsModified();
}
pEnt->close();
}
acDocManager->unlockDocument(pDoc);
acedSSName(ss,0,ent);
acedSSFree(ss);
acdbGetObjectId(m_idEqu,ent);
}
}
}
void CEquRotateDlg::OnBnClickedBtline()
{
//显示接口的方向箭头
AcApDocument* pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc);
//选择直线
ads_name ent1;
struct resbuf* pRb = acutBuildList(RTDXF0, _T("LINE"), 0);
int nRes = CKTCadUtility::SelectEntity(_T("\n选择直线方向作为旋转轴方向:"), ent1, pRb);
acutRelRb(pRb);
if (nRes == RTNORM)
{
AcDbObjectId id;
acdbGetObjectId(id,ent1);
AcDbEntity* pEnt = NULL;
if (Acad::eOk == acdbOpenAcDbEntity(pEnt,id,AcDb::kForRead))
{
AcDbLine* pLine = AcDbLine::cast(pEnt);
AcGeVector3d vtDir = pLine->endPoint() - pLine->startPoint();
vtDir.normalize();
int i = m_wndListInf.GetCount();
CString sText;
sText.Format(_T("旋转轴(%.3f,%.3f,%.3f)"),vtDir.x,vtDir.y,vtDir.z);
m_wndListInf.InsertString(i,sText);
m_arInfDirs.append(vtDir);
pEnt->close();
}
}
acDocManager->unlockDocument(pDoc);
}