1376 lines
30 KiB
C++
1376 lines
30 KiB
C++
#include "stdafx.h"
|
||
#include "KTCADUtilityEx.h"
|
||
#include "CoreTools.h"
|
||
#include "DTYG_MODIFY.h"
|
||
#include "DBReactorOfDTYG.h"
|
||
#include "AecDbX3dPart.h"
|
||
#include "AcDbX3dSolid.h"
|
||
#include "AecDbWall.h"
|
||
#include "AecDbBDPipeBase.h"
|
||
|
||
namespace
|
||
{
|
||
AcGePoint3d getCenterOfReg(AcDbRegion *pReg)
|
||
{
|
||
if (!pReg) return AcGePoint3d::kOrigin;
|
||
AcDbExtents ext;
|
||
pReg->getGeomExtents(ext);
|
||
return CoreTools::MidPt(ext.maxPoint(), ext.minPoint());
|
||
}
|
||
|
||
bool getRegionData(AcDbObjectId idPoly, CString &sReg, AcGePoint3d &ptCenter, const AcGeMatrix3d &mat)
|
||
{
|
||
OPENOBJ_BEGIN(idPoly, AcDb::kForWrite, AcDbCurve, pCurve)
|
||
{
|
||
if (!pCurve) return false;
|
||
|
||
AcDbPolyline *pPoly(AcDbPolyline::cast(pCurve));
|
||
if (pPoly && !pPoly->isClosed())
|
||
pPoly->setClosed(true);
|
||
|
||
AcDbCurve *pNew = (AcDbCurve*)pCurve->clone();
|
||
AcDbRegion *pReg = CoreTools::createRegion(pNew);
|
||
DELETE_PTR(pNew);
|
||
|
||
if (!pReg) return false;
|
||
|
||
pReg->transformBy(mat);
|
||
|
||
CoreTools::RegionToString(pReg, sReg);
|
||
ptCenter = getCenterOfReg(pReg);
|
||
DELETE_PTR(pReg);
|
||
}
|
||
OPENOBJ_END()
|
||
return true;
|
||
}
|
||
|
||
bool getRegionData(AcDbObjectId idPoly, AcDbRegion *&pReg, AcGePoint3d &ptCenter)
|
||
{
|
||
OPENOBJ_BEGIN(idPoly, AcDb::kForWrite, AcDbCurve, pCurve)
|
||
{
|
||
if (!pCurve) return false;
|
||
|
||
AcDbPolyline *pPoly(AcDbPolyline::cast(pCurve));
|
||
if (pPoly && !pPoly->isClosed())
|
||
pPoly->setClosed(true);
|
||
|
||
AcDbCurve *pNew = (AcDbCurve*)pCurve->clone();
|
||
pReg = CoreTools::createRegion(pNew);
|
||
DELETE_PTR(pNew);
|
||
if (pReg) ptCenter = getCenterOfReg(pReg);
|
||
}
|
||
OPENOBJ_END()
|
||
return pReg == NULL ? false: true;
|
||
}
|
||
|
||
AcDbX3dSolid* getX3DSolid(AecDbBDPipeBase *pBase, LPCTSTR guid, const AcDbX3dSolid::Primitive &type, AecDbX3dPart *&pPart)
|
||
{
|
||
if (!pBase) return NULL;
|
||
if (!guid) return NULL;
|
||
|
||
pPart = pBase->GetX3dPart(guid);
|
||
if (!pPart) return NULL;
|
||
int count = pPart->GetX3dSolidCount();
|
||
if (count < 1) return NULL;
|
||
AcDbX3dSolid *pSolid = pPart->GetX3dSolid(0);
|
||
if (!pSolid) return NULL;
|
||
if (pSolid->GetSolidType() != type) return NULL;
|
||
return pSolid;
|
||
}
|
||
|
||
AcDbX3dSolid* getX3DSolid(AcDbObjectId id, LPCTSTR guid, const AcDbX3dSolid::Primitive &type, AecDbX3dPart *&pPart, AcDb::OpenMode om)
|
||
{
|
||
OPENOBJ_BEGIN(id, om, AecDbBDPipeBase, pEnt)
|
||
{
|
||
if (!pEnt)
|
||
{
|
||
pPart = NULL;
|
||
return NULL;
|
||
}
|
||
|
||
return getX3DSolid(pEnt, guid, type, pPart);
|
||
}
|
||
OPENOBJ_END()
|
||
return NULL;
|
||
}
|
||
|
||
bool initLayers(const bool &bInit)
|
||
{
|
||
std::set<CString> layers;
|
||
|
||
if (bInit)
|
||
{
|
||
LayerTools::getAllLayers(layers);
|
||
if (layers.empty())
|
||
{
|
||
acutPrintf(_T("\n获取所有图层失败!"));
|
||
return false;
|
||
}
|
||
LayerTools::lockLayers(layers, true);
|
||
|
||
if (!LayerTools::createNewLayer(LayerTools::g_sLayerName))
|
||
{
|
||
acutPrintf(_T("\n新建图层失败!"));
|
||
LayerTools::lockLayers(layers, true);
|
||
return false;
|
||
}
|
||
|
||
LayerTools::setCLayer(LayerTools::g_sLayerName);
|
||
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
LayerTools::setCLayer(_T("0"));
|
||
LayerTools::deleteLayer(LayerTools::g_sLayerName);
|
||
|
||
LayerTools::getAllLayers(layers);
|
||
if (layers.empty())
|
||
{
|
||
acutPrintf(_T("\n获取所有图层失败!"));
|
||
return false;
|
||
}
|
||
LayerTools::lockLayers(layers, false);
|
||
}
|
||
return true;
|
||
}
|
||
|
||
void deleteEntity(AcDbObjectId id)
|
||
{
|
||
if (!id.isValid()) return;
|
||
if (id.isErased()) return;
|
||
OPENOBJ_BEGIN(id, AcDb::kForWrite, AcDbEntity, pEnt)
|
||
{
|
||
if (pEnt)
|
||
{
|
||
pEnt->erase();
|
||
}
|
||
}
|
||
OPENOBJ_END()
|
||
}
|
||
|
||
AcDbCurve* String2Polyline(LPCTSTR sReg)
|
||
{
|
||
if (!sReg) return NULL;
|
||
AcDbRegion *pReg = CoreTools::StringToRegion(sReg);
|
||
if (!pReg)
|
||
{
|
||
acutPrintf(_T("\n新region失败!"));
|
||
return NULL;
|
||
}
|
||
AcDbVoidPtrArray ar;
|
||
pReg->explode(ar);
|
||
DELETE_PTR(pReg);
|
||
|
||
if (ar.length() == 1)
|
||
{
|
||
AcDbEntity *pEnt((AcDbEntity*)ar[0]);
|
||
AcDbCircle *pCir = AcDbCircle::cast(pEnt);
|
||
if (pCir) return (AcDbCurve*)pCir->clone();
|
||
}
|
||
|
||
AcDbPolyline *pPoly(NULL);
|
||
std::vector<AcDbPolyline*> polys;
|
||
if (CoreTools::MakePolyline(ar, polys))
|
||
pPoly = polys[0];
|
||
deleteArrayVoidPtrs< AcDbEntity>(ar);
|
||
return pPoly;
|
||
}
|
||
|
||
AcGeMatrix3d getMatrixOfPart(AecDbX3dPart *pPart)
|
||
{
|
||
AcGeMatrix3d mat;
|
||
AcGePoint3d ptOrg;
|
||
AcGeVector3d vtMove, vtX, vtY, vtZ;
|
||
double dX, dY, dZ;
|
||
if (pPart)
|
||
{
|
||
ptOrg = pPart->GetOrgPoint();
|
||
vtMove = pPart->GetMove();
|
||
dX = pPart->GetRotate(0);
|
||
dY = pPart->GetRotate(1);
|
||
dZ = pPart->GetRotate(2);
|
||
pPart->GetAxis(0, vtX);
|
||
pPart->GetAxis(1, vtY);
|
||
pPart->GetAxis(2, vtZ);
|
||
|
||
AcGeMatrix3d _mat;
|
||
|
||
_mat.setToIdentity();
|
||
|
||
if (!vtMove.isZeroLength())
|
||
{
|
||
_mat.setToTranslation(vtMove);
|
||
ptOrg.transformBy(_mat);
|
||
}
|
||
|
||
if (!EQUAL_ZERO(dX))
|
||
{
|
||
_mat.setToIdentity();
|
||
_mat.setToRotation(dX, vtX, ptOrg);
|
||
mat *= _mat;
|
||
}
|
||
|
||
if (!EQUAL_ZERO(dY))
|
||
{
|
||
_mat.setToIdentity();
|
||
_mat.setToRotation(dY, vtY, ptOrg);
|
||
mat *= _mat;
|
||
}
|
||
|
||
if (!EQUAL_ZERO(dZ))
|
||
{
|
||
_mat.setToIdentity();
|
||
_mat.setToRotation(dZ, vtZ, ptOrg);
|
||
mat *= _mat;
|
||
}
|
||
|
||
if (!vtMove.isZeroLength())
|
||
{
|
||
_mat.setToTranslation(vtMove);
|
||
mat *= _mat;
|
||
}
|
||
}
|
||
return mat;
|
||
}
|
||
|
||
void hideEntity(AcDbObjectId &id, const bool &bHide)
|
||
{
|
||
OPENOBJ_BEGIN(id, AcDb::kForWrite, AcDbEntity, pEnt)
|
||
if (pEnt)
|
||
{
|
||
pEnt->setVisibility(bHide ? AcDb::kInvisible : AcDb::kVisible);
|
||
}
|
||
OPENOBJ_END()
|
||
}
|
||
}
|
||
|
||
#pragma region base
|
||
IMPLEMENT_DYNAMIC(CDTYG_XG, CDialog)
|
||
|
||
BEGIN_MESSAGE_MAP(CDTYG_XG, CDialog)
|
||
END_MESSAGE_MAP()
|
||
|
||
CDTYG_XG::CDTYG_XG(const AcDbX3dSolid::Primitive &type, UINT idd, CWnd * pParent)
|
||
: CDialog(idd, pParent)
|
||
, m_type(type)
|
||
, m_idEntity(AcDbObjectId::kNull)
|
||
, m_idReg(AcDbObjectId::kNull)
|
||
, m_idPath(AcDbObjectId::kNull)
|
||
, m_sGUID(_T(""))
|
||
, m_sReg(_T("")) { }
|
||
|
||
CDTYG_XG::~CDTYG_XG() { }
|
||
|
||
bool CDTYG_XG::init(AcDbObjectId & idEntity, LPCTSTR guid, AcDbObjectId &hlid)
|
||
{
|
||
AcAxDocLock lock;
|
||
resetLayersAndOverrules();
|
||
DelIntermediaryObj();
|
||
m_matrix.setToIdentity();
|
||
m_interObjs.clear();
|
||
m_idReg = m_idPath = AcDbObjectId::kNull;
|
||
m_sReg = _T("");
|
||
m_idEntity = idEntity;
|
||
m_sGUID = guid;
|
||
m_idHlight = hlid;
|
||
hideEntity(m_idHlight, true);
|
||
|
||
AecDbX3dPart *pPart(NULL);
|
||
AcDbX3dSolid *pSolid = getX3DSolid(m_idEntity, m_sGUID, m_type, pPart, AcDb::kForRead);
|
||
//if (!pSolid)
|
||
//{
|
||
// acutPrintf(_T("\n获取 AcDbX3dSolid 失败!"));
|
||
// return false;
|
||
//}
|
||
if (pPart)
|
||
m_matrix = getMatrixOfPart(pPart);
|
||
|
||
#ifdef ZWCAD
|
||
acedPostCommand(_T("_SHADEMODE _2D "));
|
||
#else
|
||
acedPostCommand(_T("_vscurrent 2 "));
|
||
#endif
|
||
|
||
return true;
|
||
}
|
||
|
||
void CDTYG_XG::resetLayersAndOverrules()
|
||
{
|
||
CEntityOverrule::delOverrule();
|
||
|
||
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
|
||
pDb->disableUndoRecording(true);
|
||
initLayers(false);
|
||
pDb->disableUndoRecording(false);
|
||
}
|
||
|
||
void CDTYG_XG::AddOverrules()
|
||
{
|
||
std::set<AcDbObjectId> _ids;
|
||
_ids.insert(m_interObjs.begin(), m_interObjs.end());
|
||
CEntityOverrule::addOverrule(_ids);
|
||
}
|
||
|
||
void CDTYG_XG::DelIntermediaryObj()
|
||
{
|
||
AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
|
||
pDb->disableUndoRecording(true);
|
||
for (size_t i = 0; i < m_interObjs.size(); ++i)
|
||
{
|
||
deleteEntity(m_interObjs[i]);
|
||
}
|
||
LayerTools::deleteLayer(LayerTools::g_sLayerName);
|
||
pDb->disableUndoRecording(false);
|
||
}
|
||
|
||
bool CDTYG_XG::getRegionData(AcDbObjectId &idReg, CString & sReg, AcGePoint3d & ptC)
|
||
{
|
||
AcDbRegion *pReg(NULL);
|
||
bool bRel = getRegionData(idReg, pReg, ptC);
|
||
if (pReg)
|
||
bRel = CoreTools::RegionToString(pReg, sReg);
|
||
DELETE_PTR(pReg);
|
||
return bRel;
|
||
}
|
||
|
||
bool CDTYG_XG::getRegionData(AcDbObjectId &idReg, AcDbRegion *& pReg, AcGePoint3d & ptC)
|
||
{
|
||
OPENOBJ_BEGIN(idReg, AcDb::kForWrite, AcDbCurve, pCurve)
|
||
{
|
||
if (!pCurve) return false;
|
||
|
||
AcDbPolyline *pPoly(AcDbPolyline::cast(pCurve));
|
||
if (pPoly && !pPoly->isClosed())
|
||
pPoly->setClosed(true);
|
||
|
||
AcDbCurve *pNew = (AcDbCurve*)pCurve->clone();
|
||
pReg = CoreTools::createRegion(pNew);
|
||
DELETE_PTR(pNew);
|
||
if (pReg)
|
||
{
|
||
pReg->transformBy(m_matrix.inverse());
|
||
ptC = getCenterOfReg(pReg);
|
||
}
|
||
}
|
||
OPENOBJ_END()
|
||
return pReg == NULL ? false : true;
|
||
}
|
||
|
||
void CDTYG_XG::OnOK()
|
||
{
|
||
AcAxDocLock lock;
|
||
resetLayersAndOverrules();
|
||
DelIntermediaryObj();
|
||
//hideEntity(m_idHlight, false);
|
||
//acedPostCommand(_T("r "));
|
||
CDialog::OnOK();
|
||
if (GetParent()) GetParent()->ShowWindow(SW_SHOW);
|
||
if (GetParent()) GetParent()->PostMessage(WM_REFRESH_HLIGHT_ENTITY_MESSAGE);
|
||
}
|
||
|
||
void CDTYG_XG::OnCancel()
|
||
{
|
||
AcAxDocLock lock;
|
||
resetLayersAndOverrules();
|
||
DelIntermediaryObj();
|
||
hideEntity(m_idHlight, false);
|
||
acedPostCommand(_T("r "));
|
||
CDialog::OnCancel();
|
||
if (GetParent()) GetParent()->ShowWindow(SW_SHOW);
|
||
}
|
||
|
||
#pragma endregion
|
||
|
||
#pragma region EXTRUD
|
||
IMPLEMENT_DYNAMIC(CDTYG_XG_EXTRUD, CDTYG_XG)
|
||
|
||
BEGIN_MESSAGE_MAP(CDTYG_XG_EXTRUD, CDTYG_XG)
|
||
ON_BN_CLICKED(IDOK, &CDTYG_XG_EXTRUD::OnBnClickedOk)
|
||
END_MESSAGE_MAP()
|
||
|
||
CDTYG_XG_EXTRUD::CDTYG_XG_EXTRUD(CWnd* pParent)
|
||
: CDTYG_XG(AcDbX3dSolid::kExtrude2, IDD, pParent)
|
||
, m_dHeight(0.)
|
||
, m_ptFr(AcGePoint3d::kOrigin)
|
||
, m_ptTo(AcGePoint3d::kOrigin)
|
||
{ }
|
||
|
||
CDTYG_XG_EXTRUD::~CDTYG_XG_EXTRUD() { }
|
||
|
||
bool CDTYG_XG_EXTRUD::init(AcDbObjectId & idEntity, LPCTSTR guid, AcDbObjectId &hlid)
|
||
{
|
||
if (!CDTYG_XG::init(idEntity, guid, hlid)) return false;
|
||
|
||
AecDbX3dPart *pPart(NULL);
|
||
AcDbX3dSolid *pSolid = getX3DSolid(m_idEntity, guid, m_type, pPart, AcDb::kForRead);
|
||
if (!pSolid)
|
||
{
|
||
acutPrintf(_T("\n获取 AcDbX3dSolid 失败!"));
|
||
return false;
|
||
}
|
||
bool bRel = pSolid->GetExturd2Data(m_sReg, m_ptFr, m_ptTo);
|
||
if (!bRel) return bRel;
|
||
|
||
m_dHeight = m_ptFr.distanceTo(m_ptTo);
|
||
if(GetParent()) GetParent()->ShowWindow(SW_HIDE);
|
||
UpdateData(FALSE);
|
||
drawRegion();
|
||
return bRel;
|
||
}
|
||
|
||
void CDTYG_XG_EXTRUD::DoDataExchange(CDataExchange* pDX)
|
||
{
|
||
CDTYG_XG::DoDataExchange(pDX);
|
||
DDX_Text(pDX, IDC_MODIFY_HEIGHT, m_dHeight);
|
||
}
|
||
|
||
void CDTYG_XG_EXTRUD::drawRegion()
|
||
{
|
||
AcAxDocLock lock;
|
||
|
||
AcDbCurve *pPoly(String2Polyline(m_sReg));
|
||
if (!pPoly)
|
||
{
|
||
acutPrintf(_T("\npolyline生成失败!"));
|
||
return;
|
||
}
|
||
|
||
initLayers(true);
|
||
pPoly->setLayer(LayerTools::g_sLayerName);
|
||
pPoly->transformBy(m_matrix);
|
||
|
||
CoreTools::AddToModelSpace(pPoly, NULL, true, &m_idReg);
|
||
if (!m_idReg.isValid())
|
||
{
|
||
acutPrintf(_T("\n截面曲线插入失败!"));
|
||
initLayers(false);
|
||
return;
|
||
}
|
||
|
||
acedPostCommand(_T("r "));
|
||
|
||
// 锁定实体不允许删除
|
||
m_interObjs.push_back(m_idReg);
|
||
AddOverrules();
|
||
}
|
||
|
||
void CDTYG_XG_EXTRUD::OnBnClickedOk()
|
||
{
|
||
AcAxDocLock lock;
|
||
UpdateData(TRUE);
|
||
|
||
AcGeVector3d vt(m_ptTo - m_ptFr);
|
||
if (m_idReg.isValid() && !getRegionData(m_idReg, m_sReg, m_ptFr))
|
||
{
|
||
acutPrintf(_T("\n 获取截面信息失败。"));
|
||
return;
|
||
}
|
||
vt.normalize();
|
||
m_ptTo = m_ptFr + vt * m_dHeight;
|
||
|
||
// 还原环境
|
||
resetLayersAndOverrules();
|
||
|
||
OPENOBJ_BEGIN(m_idEntity, AcDb::kForWrite, AecDbBDPipeBase, pEnt)
|
||
{
|
||
if (!pEnt) return;
|
||
AecDbX3dPart *pPart(NULL);
|
||
AcDbX3dSolid *pSolid = getX3DSolid(pEnt, m_sGUID, AcDbX3dSolid::kExtrude2, pPart);
|
||
if (!pSolid)
|
||
{
|
||
acutPrintf(_T("\n获取 AcDbX3dSolid 失败!"));
|
||
return;
|
||
}
|
||
pEnt->AssertWriteEnabled();
|
||
pSolid->SetExturd2Data(m_sReg, m_ptFr, m_ptTo);
|
||
pPart->Create();
|
||
}
|
||
OPENOBJ_END()
|
||
CDTYG_XG::OnOK();
|
||
}
|
||
|
||
#pragma endregion
|
||
|
||
#pragma region REVOLVE
|
||
IMPLEMENT_DYNAMIC(CDTYG_XG_REVOLVE, CDTYG_XG)
|
||
|
||
BEGIN_MESSAGE_MAP(CDTYG_XG_REVOLVE, CDTYG_XG)
|
||
ON_BN_CLICKED(IDOK, &CDTYG_XG_REVOLVE::OnBnClickedOk)
|
||
END_MESSAGE_MAP()
|
||
|
||
CDTYG_XG_REVOLVE::CDTYG_XG_REVOLVE(CWnd* pParent)
|
||
: CDTYG_XG(AcDbX3dSolid::kRevolve2, IDD, pParent)
|
||
, m_ptOrg(AcGePoint3d::kOrigin)
|
||
, m_vt(AcGeVector3d::kIdentity)
|
||
, m_dSweepAngle(.0)
|
||
, m_dStartAngle(.0) { }
|
||
|
||
CDTYG_XG_REVOLVE::~CDTYG_XG_REVOLVE() { }
|
||
|
||
bool CDTYG_XG_REVOLVE::init(AcDbObjectId & idEntity, LPCTSTR guid, AcDbObjectId &hlid)
|
||
{
|
||
if (!CDTYG_XG::init(idEntity, guid, hlid)) return false;
|
||
AecDbX3dPart *pPart(NULL);
|
||
AcDbX3dSolid *pSolid = getX3DSolid(m_idEntity, guid, m_type, pPart, AcDb::kForRead);
|
||
if (!pSolid)
|
||
{
|
||
acutPrintf(_T("\n获取 AcDbX3dSolid 失败!"));
|
||
return false;
|
||
}
|
||
bool bRel = pSolid->GetRevolve2Data(m_sReg, m_ptOrg, m_vt, m_dSweepAngle, m_dStartAngle);
|
||
if (!bRel) return bRel;
|
||
|
||
SetWindowText(_T("单体异构-修改旋转体"));
|
||
if (GetDlgItem(IDC_STATIC_TIP))
|
||
{
|
||
GetDlgItem(IDC_STATIC_TIP)->SetWindowText(_T("请直接修改红色截面和黄色旋转轴。"));
|
||
}
|
||
|
||
drawRegion();
|
||
|
||
if(GetParent()) GetParent()->ShowWindow(SW_HIDE);
|
||
|
||
return bRel;
|
||
}
|
||
|
||
void CDTYG_XG_REVOLVE::drawRegion()
|
||
{
|
||
AcAxDocLock lock;
|
||
|
||
AcDbCurve *pPoly(String2Polyline(m_sReg));
|
||
if (!pPoly)
|
||
{
|
||
acutPrintf(_T("\npolyline生成失败!"));
|
||
return;
|
||
}
|
||
|
||
initLayers(true);
|
||
pPoly->setLayer(LayerTools::g_sLayerName);
|
||
pPoly->transformBy(m_matrix);
|
||
|
||
CoreTools::AddToModelSpace(pPoly, NULL, true, &m_idReg);
|
||
if (!m_idReg.isValid())
|
||
{
|
||
acutPrintf(_T("\n截面曲线插入失败!"));
|
||
initLayers(false);
|
||
return;
|
||
}
|
||
|
||
AcDbRay *pRay = new AcDbRay();
|
||
pRay->setBasePoint(m_ptOrg);
|
||
pRay->setUnitDir(m_vt);
|
||
pRay->setColorIndex(2);
|
||
pRay->transformBy(m_matrix);
|
||
CoreTools::AddToModelSpace(pRay, NULL, true, &m_idPath);
|
||
if (!m_idPath.isValid())
|
||
{
|
||
acutPrintf(_T("\n旋转轴插入失败!"));
|
||
initLayers(false);
|
||
return;
|
||
}
|
||
|
||
acedPostCommand(_T("r "));
|
||
|
||
// 锁定实体不允许删除
|
||
m_interObjs.push_back(m_idReg);
|
||
m_interObjs.push_back(m_idPath);
|
||
AddOverrules();
|
||
}
|
||
|
||
void CDTYG_XG_REVOLVE::OnBnClickedOk()
|
||
{
|
||
AcAxDocLock lock;
|
||
if (m_idReg.isValid() && m_idPath.isValid())
|
||
{
|
||
AcGePoint3d pt;
|
||
if (m_idReg.isValid() && !getRegionData(m_idReg, m_sReg, pt))
|
||
{
|
||
acutPrintf(_T("\n 获取截面信息失败。"));
|
||
return;
|
||
}
|
||
|
||
OPENOBJ_BEGIN(m_idPath, AcDb::kForRead, AcDbRay, pRay)
|
||
{
|
||
if (!pRay)
|
||
{
|
||
acutPrintf(_T("\n 获取旋转轴信息失败。"));
|
||
return;
|
||
}
|
||
AcDbRay *pNew = (AcDbRay*)pRay->clone();
|
||
pNew->transformBy(m_matrix.inverse());
|
||
m_ptOrg = pNew->basePoint();
|
||
m_vt = pNew->unitDir();
|
||
DELETE_PTR(pNew);
|
||
}
|
||
OPENOBJ_END()
|
||
|
||
// 还原环境
|
||
resetLayersAndOverrules();
|
||
|
||
OPENOBJ_BEGIN(m_idEntity, AcDb::kForWrite, AecDbBDPipeBase, pEnt)
|
||
{
|
||
if (!pEnt) return;
|
||
AecDbX3dPart *pPart(NULL);
|
||
AcDbX3dSolid *pSolid = getX3DSolid(pEnt, m_sGUID, m_type, pPart);
|
||
if (!pSolid)
|
||
{
|
||
acutPrintf(_T("\n获取 AcDbX3dSolid 失败!"));
|
||
return;
|
||
}
|
||
pEnt->AssertWriteEnabled();
|
||
pSolid->SetRevolve2Data(m_sReg, m_ptOrg, m_vt, m_dSweepAngle, m_dStartAngle);
|
||
pPart->Create();
|
||
}
|
||
OPENOBJ_END()
|
||
}
|
||
CDTYG_XG::OnOK();
|
||
}
|
||
|
||
#pragma endregion
|
||
|
||
#pragma region SWEEP
|
||
IMPLEMENT_DYNAMIC(CDTYG_XG_SWEEP, CDTYG_XG)
|
||
|
||
BEGIN_MESSAGE_MAP(CDTYG_XG_SWEEP, CDTYG_XG)
|
||
ON_BN_CLICKED(IDOK, &CDTYG_XG_SWEEP::OnBnClickedOk)
|
||
END_MESSAGE_MAP()
|
||
|
||
CDTYG_XG_SWEEP::CDTYG_XG_SWEEP(CWnd* pParent /*=nullptr*/)
|
||
: CDTYG_XG(AcDbX3dSolid::kSweep, IDD, pParent)
|
||
, m_pCurve(NULL)
|
||
{ }
|
||
|
||
CDTYG_XG_SWEEP::~CDTYG_XG_SWEEP()
|
||
{
|
||
DELETE_PTR(m_pCurve);
|
||
}
|
||
|
||
bool CDTYG_XG_SWEEP::init(AcDbObjectId & idEntity, LPCTSTR guid, AcDbObjectId &hlid)
|
||
{
|
||
DELETE_PTR(m_pCurve);
|
||
if (!CDTYG_XG::init(idEntity, guid, hlid)) return false;
|
||
|
||
AecDbX3dPart *pPart(NULL);
|
||
AcDbX3dSolid *pSolid = getX3DSolid(m_idEntity, guid, m_type, pPart, AcDb::kForRead);
|
||
if (!pSolid)
|
||
{
|
||
acutPrintf(_T("\n获取 AcDbX3dSolid 失败!"));
|
||
return false;
|
||
}
|
||
DELETE_PTR(m_pCurve);
|
||
bool bRel = pSolid->GetSweepData(m_sReg, m_pCurve);
|
||
if (!bRel) return bRel;
|
||
|
||
SetWindowText(_T("单体异构-修改扫掠体"));
|
||
if (GetDlgItem(IDC_STATIC_TIP))
|
||
{
|
||
GetDlgItem(IDC_STATIC_TIP)->SetWindowText(_T("请直接修改红色截面和黄色路径。\n\n请注意:\n\n如要修改扫掠体位置,请修改红色截面位置。\n\n路径只决定扫掠体走向。"));
|
||
}
|
||
|
||
drawRegion();
|
||
|
||
if(GetParent()) GetParent()->ShowWindow(SW_HIDE);
|
||
return bRel;
|
||
}
|
||
|
||
void CDTYG_XG_SWEEP::drawRegion()
|
||
{
|
||
AcAxDocLock lock;
|
||
|
||
AcDbCurve *pPoly(String2Polyline(m_sReg));
|
||
if (!pPoly)
|
||
{
|
||
acutPrintf(_T("\npolyline生成失败!"));
|
||
return;
|
||
}
|
||
|
||
initLayers(true);
|
||
pPoly->setLayer(LayerTools::g_sLayerName);
|
||
pPoly->transformBy(m_matrix);
|
||
|
||
CoreTools::AddToModelSpace(pPoly, NULL, true, &m_idReg);
|
||
if (!m_idReg.isValid())
|
||
{
|
||
acutPrintf(_T("\n截面曲线插入失败!"));
|
||
initLayers(false);
|
||
return;
|
||
}
|
||
|
||
AcDbPolyline *pPath = (AcDbPolyline*)m_pCurve->clone();
|
||
pPath->setColorIndex(2);
|
||
pPath->setLayer(LayerTools::g_sLayerName);
|
||
pPath->transformBy(m_matrix);
|
||
CoreTools::AddToModelSpace(pPath, NULL, true, &m_idPath);
|
||
if (!m_idPath.isValid())
|
||
{
|
||
acutPrintf(_T("\n旋转轴插入失败!"));
|
||
initLayers(false);
|
||
return;
|
||
}
|
||
|
||
acedPostCommand(_T("r "));
|
||
|
||
// 锁定实体不允许删除
|
||
m_interObjs.push_back(m_idReg);
|
||
m_interObjs.push_back(m_idPath);
|
||
AddOverrules();
|
||
}
|
||
|
||
void CDTYG_XG_SWEEP::OnBnClickedOk()
|
||
{
|
||
AcAxDocLock lock;
|
||
if (m_idReg.isValid() && m_idPath.isValid())
|
||
{
|
||
AcGePoint3d pt;
|
||
if (m_idReg.isValid() && !getRegionData(m_idReg, m_sReg, pt))
|
||
{
|
||
acutPrintf(_T("\n 获取截面信息失败。"));
|
||
return;
|
||
}
|
||
|
||
DELETE_PTR(m_pCurve);
|
||
OPENOBJ_BEGIN(m_idPath, AcDb::kForRead, AcDbCurve, pPoly)
|
||
{
|
||
if (!pPoly)
|
||
{
|
||
acutPrintf(_T("\n 获取旋转轴信息失败。"));
|
||
return;
|
||
}
|
||
m_pCurve = (AcDbCurve*)pPoly->clone();
|
||
m_pCurve->transformBy(m_matrix.inverse());
|
||
}
|
||
OPENOBJ_END()
|
||
|
||
// 还原环境
|
||
resetLayersAndOverrules();
|
||
|
||
OPENOBJ_BEGIN(m_idEntity, AcDb::kForWrite, AecDbBDPipeBase, pEnt)
|
||
{
|
||
if (!pEnt) return;
|
||
AecDbX3dPart *pPart(NULL);
|
||
AcDbX3dSolid *pSolid = getX3DSolid(pEnt, m_sGUID, m_type, pPart);
|
||
if (!pSolid)
|
||
{
|
||
acutPrintf(_T("\n获取 AcDbX3dSolid 失败!"));
|
||
return;
|
||
}
|
||
pEnt->AssertWriteEnabled();
|
||
pSolid->SetSweepData(m_sReg, m_pCurve);
|
||
pPart->Create();
|
||
}
|
||
OPENOBJ_END()
|
||
}
|
||
CDTYG_XG::OnOK();
|
||
}
|
||
|
||
#pragma endregion
|
||
|
||
#pragma region CUT
|
||
IMPLEMENT_DYNAMIC(CDTYG_XG_CUT, CDTYG_XG)
|
||
|
||
BEGIN_MESSAGE_MAP(CDTYG_XG_CUT, CDTYG_XG)
|
||
ON_BN_CLICKED(IDOK, &CDTYG_XG_CUT::OnBnClickedOk)
|
||
END_MESSAGE_MAP()
|
||
|
||
CDTYG_XG_CUT::CDTYG_XG_CUT(CWnd* pParent /*=nullptr*/)
|
||
: CDTYG_XG(AcDbX3dSolid::kExtrude2, IDD, pParent)
|
||
, m_ptFr(AcGePoint3d::kOrigin)
|
||
, m_ptTo(AcGePoint3d::kOrigin)
|
||
, m_dHeight(.0)
|
||
{ }
|
||
|
||
CDTYG_XG_CUT::~CDTYG_XG_CUT() { }
|
||
|
||
bool CDTYG_XG_CUT::init(AcDbObjectId & idEntity, LPCTSTR guid, AcDbObjectId &hlid)
|
||
{
|
||
if (!CDTYG_XG::init(idEntity, guid, hlid)) return false;
|
||
AecDbX3dPart *pPart(NULL);
|
||
AcDbX3dSolid *pSolid = getX3DSolid(m_idEntity, guid, m_type, pPart, AcDb::kForRead);
|
||
if (!pSolid)
|
||
{
|
||
acutPrintf(_T("\n获取 AcDbX3dSolid 失败!"));
|
||
return false;
|
||
}
|
||
bool bRel = pSolid->GetExturd2Data(m_sReg, m_ptFr, m_ptTo);
|
||
if (!bRel) return bRel;
|
||
|
||
m_dHeight = m_ptFr.distanceTo(m_ptTo);
|
||
|
||
SetWindowText(_T("单体异构-修改切割体"));
|
||
if (GetDlgItem(IDC_STATIC_TIP))
|
||
{
|
||
GetDlgItem(IDC_STATIC_TIP)->SetWindowText(_T("请直接修改红色截面。"));
|
||
}
|
||
|
||
drawRegion();
|
||
if(GetParent()) GetParent()->ShowWindow(SW_HIDE);
|
||
|
||
return bRel;
|
||
}
|
||
|
||
void CDTYG_XG_CUT::drawRegion()
|
||
{
|
||
AcAxDocLock lock;
|
||
|
||
AcDbCurve *pPoly(String2Polyline(m_sReg));
|
||
if (!pPoly)
|
||
{
|
||
acutPrintf(_T("\npolyline生成失败!"));
|
||
return;
|
||
}
|
||
|
||
initLayers(true);
|
||
pPoly->setLayer(LayerTools::g_sLayerName);
|
||
pPoly->transformBy(m_matrix);
|
||
|
||
CoreTools::AddToModelSpace(pPoly, NULL, true, &m_idReg);
|
||
if (!m_idReg.isValid())
|
||
{
|
||
acutPrintf(_T("\n截面曲线插入失败!"));
|
||
initLayers(false);
|
||
return;
|
||
}
|
||
|
||
acedPostCommand(_T("r "));
|
||
|
||
// 锁定实体不允许删除
|
||
m_interObjs.push_back(m_idReg);
|
||
AddOverrules();
|
||
|
||
}
|
||
|
||
void CDTYG_XG_CUT::OnBnClickedOk()
|
||
{
|
||
AcAxDocLock lock;
|
||
UpdateData(TRUE);
|
||
|
||
AcGeVector3d vt(m_ptTo - m_ptFr);
|
||
if (m_idReg.isValid() && !getRegionData(m_idReg, m_sReg, m_ptFr))
|
||
{
|
||
acutPrintf(_T("\n 获取截面信息失败。"));
|
||
return;
|
||
}
|
||
vt.normalize();
|
||
m_ptTo = m_ptFr + vt * m_dHeight;
|
||
|
||
// 还原环境
|
||
resetLayersAndOverrules();
|
||
|
||
OPENOBJ_BEGIN(m_idEntity, AcDb::kForWrite, AecDbBDPipeBase, pEnt)
|
||
{
|
||
if (!pEnt) return;
|
||
AecDbX3dPart *pPart(NULL);
|
||
AcDbX3dSolid *pSolid = getX3DSolid(pEnt, m_sGUID, AcDbX3dSolid::kExtrude2, pPart);
|
||
if (!pSolid)
|
||
{
|
||
acutPrintf(_T("\n获取 AcDbX3dSolid 失败!"));
|
||
return;
|
||
}
|
||
pEnt->AssertWriteEnabled();
|
||
pSolid->SetExturd2Data(m_sReg, m_ptFr, m_ptTo);
|
||
pPart->Create();
|
||
}
|
||
OPENOBJ_END()
|
||
|
||
CDTYG_XG::OnOK();
|
||
}
|
||
|
||
#pragma endregion
|
||
|
||
#pragma region LOFT
|
||
IMPLEMENT_DYNAMIC(CDTYG_XG_LOFT, CDTYG_XG)
|
||
|
||
BEGIN_MESSAGE_MAP(CDTYG_XG_LOFT, CDTYG_XG)
|
||
ON_BN_CLICKED(IDOK, &CDTYG_XG_LOFT::OnBnClickedOk)
|
||
ON_REGISTERED_MESSAGE(WM_XLISTCTRL_EDIT_END, &CDTYG_XG_LOFT::OnEditEnd)
|
||
ON_BN_CLICKED(IDC_CHECK1, &CDTYG_XG_LOFT::OnBnClickedCheck1)
|
||
ON_NOTIFY(NM_CLICK, IDC_LIST, &CDTYG_XG_LOFT::OnNMClickList)
|
||
END_MESSAGE_MAP()
|
||
|
||
CDTYG_XG_LOFT::CDTYG_XG_LOFT(CWnd* pParent /*=nullptr*/)
|
||
: CDTYG_XG(AcDbX3dSolid::kLoft, IDD, pParent)
|
||
, m_heights(0)
|
||
, m_regs(0)
|
||
, m_bUseTbl(TRUE)
|
||
{ }
|
||
|
||
CDTYG_XG_LOFT::~CDTYG_XG_LOFT() { }
|
||
|
||
void CDTYG_XG_LOFT::DoDataExchange(CDataExchange * pDX)
|
||
{
|
||
CDTYG_XG::DoDataExchange(pDX);
|
||
DDX_Control(pDX, IDC_LIST, m_lstCtrl);
|
||
DDX_Check(pDX, IDC_CHECK1, m_bUseTbl);
|
||
}
|
||
|
||
BOOL CDTYG_XG_LOFT::OnInitDialog()
|
||
{
|
||
CDTYG_XG::OnInitDialog();
|
||
|
||
m_lstCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_SINGLEROW);
|
||
m_lstCtrl.InsertColumn(0, _T("层号"), LVCFMT_LEFT, 125);
|
||
m_lstCtrl.InsertColumn(1, _T("层高"), LVCFMT_LEFT, 125);
|
||
|
||
UpdateData(FALSE);
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
bool CDTYG_XG_LOFT::init(AcDbObjectId & idEntity, LPCTSTR guid, AcDbObjectId &hlid)
|
||
{
|
||
m_regs.clear();
|
||
m_heights.clear();
|
||
m_bUseTbl = TRUE;
|
||
if (!CDTYG_XG::init(idEntity, guid, hlid)) return false;
|
||
AecDbX3dPart *pPart(NULL);
|
||
AcDbX3dSolid *pSolid = getX3DSolid(m_idEntity, guid, m_type, pPart, AcDb::kForRead);
|
||
if (!pSolid)
|
||
{
|
||
acutPrintf(_T("\n获取 AcDbX3dSolid 失败!"));
|
||
return false;
|
||
}
|
||
bool bRel = pSolid->GetLoftData(m_regs);
|
||
if (!bRel) return bRel;
|
||
|
||
// 分析截面找到层高
|
||
if (m_regs.size() < 2)
|
||
{
|
||
acutPrintf(_T("\nloft截面小于2!"));
|
||
return false;
|
||
}
|
||
|
||
std::vector<AcDbRegion*> regs;
|
||
|
||
AcGePlane plan;
|
||
AcGeVector3d vt, vtN;
|
||
double dH(.0);
|
||
AcGePoint3d ptM(AcGePoint3d::kOrigin), ptNear(AcGePoint3d::kOrigin);
|
||
for (size_t i = 0; i < m_regs.size() - 1; ++i)
|
||
{
|
||
AcDbRegion *pReg1 = CoreTools::StringToRegion(m_regs[i]);
|
||
AcDbRegion *pReg2 = CoreTools::StringToRegion(m_regs[i+1]);
|
||
if (!pReg1 || !pReg2) continue;
|
||
|
||
regs.push_back(pReg1);
|
||
regs.push_back(pReg2);
|
||
|
||
pReg1->getPlane(plan);
|
||
vtN = plan.normal();
|
||
|
||
ptM = getCenterOfReg(pReg2);
|
||
ptNear = plan.closestPointTo(ptM);
|
||
|
||
dH = ptNear.distanceTo(ptM);
|
||
vt = ptM - ptNear;
|
||
|
||
if (!vt.isCodirectionalTo(vtN))
|
||
dH *= -1;
|
||
|
||
m_heights.push_back(dH);
|
||
}
|
||
|
||
deleteContainerOfStd(regs);
|
||
|
||
m_lstCtrl.DeleteAllItems();
|
||
CString s(_T(""));
|
||
for (size_t i = 0; i < m_heights.size(); ++i)
|
||
{
|
||
s.Format(_T("%d层"), i + 1);
|
||
m_lstCtrl.InsertItem(i, s);
|
||
s.Format(_T("%.1f"), m_heights[i]);
|
||
m_lstCtrl.SetItemText(i, 1, s);
|
||
m_lstCtrl.SetEdit(i, 1);
|
||
}
|
||
|
||
// 直接显示各截面
|
||
drawRegion();
|
||
|
||
UpdateData(FALSE);
|
||
|
||
if (GetParent()) GetParent()->ShowWindow(SW_HIDE);
|
||
|
||
return bRel;
|
||
}
|
||
|
||
void CDTYG_XG_LOFT::drawRegion()
|
||
{
|
||
AcAxDocLock lock;
|
||
AcDbObjectId id;
|
||
initLayers(true);
|
||
for (size_t i = 0; i < m_regs.size(); ++i)
|
||
{
|
||
AcDbCurve *pPoly(String2Polyline(m_regs[i]));
|
||
if (!pPoly) continue;
|
||
pPoly->setLayer(LayerTools::g_sLayerName);
|
||
pPoly->transformBy(m_matrix);
|
||
CoreTools::AddToModelSpace(pPoly, NULL, true, &id);
|
||
if (id.isValid())
|
||
{
|
||
m_interObjs.push_back(id);
|
||
}
|
||
}
|
||
|
||
acedPostCommand(_T("r "));
|
||
|
||
// 锁定实体不允许删除
|
||
AddOverrules();
|
||
}
|
||
|
||
void CDTYG_XG_LOFT::OnBnClickedOk()
|
||
{
|
||
AcAxDocLock lock;
|
||
UpdateData(TRUE);
|
||
|
||
resetLayersAndOverrules();
|
||
|
||
AcGePoint3d ptM(AcGePoint3d::kOrigin);
|
||
std::vector<std::pair<AcDbRegion*, AcGePoint3d>> mp;
|
||
for (size_t i = 0; i < m_interObjs.size(); ++i)
|
||
{
|
||
AcDbRegion *pReg(NULL);
|
||
if (!getRegionData(m_interObjs[i], pReg, ptM)) continue;
|
||
mp.push_back(std::make_pair(pReg, ptM));
|
||
}
|
||
|
||
if (m_bUseTbl) // 根据数据调整截面
|
||
{
|
||
m_heights.clear();
|
||
CString sV(_T(""));
|
||
for (int i = 0; i < m_lstCtrl.GetItemCount(); i++)
|
||
{
|
||
sV = m_lstCtrl.GetItemText(i, 1);
|
||
m_heights.push_back(TypeConvert::s2f(sV));
|
||
}
|
||
|
||
if (m_heights.size() == mp.size() - 1)
|
||
{
|
||
AcGeVector3d vtN;
|
||
AcGePlane plan;
|
||
AcGeMatrix3d mat;
|
||
AcGePoint3d ptM1, ptM2;
|
||
|
||
mp[0].first->getPlane(plan);
|
||
vtN = plan.normal();
|
||
ptM1 = mp[0].second;
|
||
|
||
double dH(0.);
|
||
for (size_t i(1); i < mp.size(); ++i)
|
||
{
|
||
dH += m_heights[i - 1];
|
||
vtN = plan.normal();
|
||
mat.setToIdentity();
|
||
// 先把所有平面都放到第一层
|
||
AcDbRegion *pReg = mp[i].first;
|
||
ptM2 = mp[i].second;
|
||
double deltaZ(ptM1.z - ptM2.z);
|
||
vtN *= deltaZ;
|
||
mat.setToTranslation(vtN);
|
||
pReg->transformBy(mat);
|
||
|
||
vtN = plan.normal();
|
||
vtN *= dH;
|
||
mat.setToIdentity();
|
||
mat.setToTranslation(vtN);
|
||
pReg->transformBy(mat);
|
||
}
|
||
}
|
||
}
|
||
|
||
m_regs.clear();
|
||
for (size_t i = 0; i < mp.size(); ++i)
|
||
{
|
||
m_sReg.Empty();
|
||
if (CoreTools::RegionToString(mp[i].first, m_sReg))
|
||
m_regs.push_back(m_sReg);
|
||
DELETE_PTR(mp[i].first);
|
||
}
|
||
|
||
OPENOBJ_BEGIN(m_idEntity, AcDb::kForWrite, AecDbBDPipeBase, pEnt)
|
||
{
|
||
if (!pEnt) return;
|
||
AecDbX3dPart *pPart(NULL);
|
||
AcDbX3dSolid *pSolid = getX3DSolid(pEnt, m_sGUID, AcDbX3dSolid::kLoft, pPart);
|
||
if (!pSolid)
|
||
{
|
||
acutPrintf(_T("\n获取 AcDbX3dSolid 失败!"));
|
||
return;
|
||
}
|
||
pEnt->AssertWriteEnabled();
|
||
pSolid->SetLoftData(m_regs);
|
||
pPart->Create();
|
||
}
|
||
OPENOBJ_END()
|
||
|
||
CDTYG_XG::OnOK();
|
||
}
|
||
|
||
LRESULT CDTYG_XG_LOFT::OnEditEnd(WPARAM nItem, LPARAM nSubItem)
|
||
{
|
||
CString sValue = m_lstCtrl.GetItemText(nItem, nSubItem);
|
||
|
||
if (!CoreTools::isDigitString<double>(sValue) && !CoreTools::isDigitString<int>(sValue))
|
||
{
|
||
m_lstCtrl.SetItemText(nItem, nSubItem, _T("100.0"));
|
||
AfxMessageBox(_T("请输入数字!"));
|
||
return 0;
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
void CDTYG_XG_LOFT::OnBnClickedCheck1()
|
||
{
|
||
UpdateData(TRUE);
|
||
//m_bUseTbl = !m_bUseTbl;
|
||
if (m_bUseTbl)
|
||
{
|
||
m_lstCtrl.EnableWindow(true);
|
||
}
|
||
else
|
||
{
|
||
m_lstCtrl.EnableWindow(false);
|
||
}
|
||
|
||
}
|
||
|
||
void CDTYG_XG_LOFT::OnNMClickList(NMHDR *pNMHDR, LRESULT *pResult)
|
||
{
|
||
AcAxDocLock lock;
|
||
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
|
||
*pResult = 0;
|
||
|
||
// 先全部还原颜色
|
||
for (size_t i = 0; i < m_interObjs.size(); ++i)
|
||
{
|
||
OPENOBJ_BEGIN(m_interObjs[i], AcDb::kForWrite, AcDbEntity, pEnt)
|
||
{
|
||
if (!pEnt) return;
|
||
pEnt->setColorIndex(256);
|
||
}
|
||
OPENOBJ_END()
|
||
}
|
||
|
||
int nItem = pNMItemActivate->iItem;
|
||
if (nItem < m_heights.size() || nItem >= 0)
|
||
{
|
||
if (m_interObjs.empty()) return;
|
||
|
||
int nFr(nItem), nEd(nItem + 1);
|
||
|
||
if ((nFr < 0 || nFr >= m_interObjs.size())
|
||
|| (nEd < 0 || nEd >= m_interObjs.size()))
|
||
return;
|
||
|
||
AcDbObjectId idFr(m_interObjs[nFr]), idEd(m_interObjs[nEd]);
|
||
OPENOBJ_BEGIN(idFr, AcDb::kForWrite, AcDbEntity, pEnt1)
|
||
{
|
||
OPENOBJ_BEGIN(idEd, AcDb::kForWrite, AcDbEntity, pEnt2)
|
||
{
|
||
if (!pEnt1 || !pEnt2) return;
|
||
pEnt1->setColorIndex(2);
|
||
pEnt2->setColorIndex(2);
|
||
}
|
||
OPENOBJ_END()
|
||
}
|
||
OPENOBJ_END()
|
||
}
|
||
|
||
acedPostCommand(_T("r "));
|
||
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma region XWall
|
||
IMPLEMENT_DYNAMIC(CDTYG_XG_BDPipeBase, CDTYG_XG)
|
||
|
||
BEGIN_MESSAGE_MAP(CDTYG_XG_BDPipeBase, CDTYG_XG)
|
||
ON_BN_CLICKED(IDOK, &CDTYG_XG_BDPipeBase::OnBnClickedOk)
|
||
END_MESSAGE_MAP()
|
||
|
||
CDTYG_XG_BDPipeBase::CDTYG_XG_BDPipeBase(CWnd* pParent /*=nullptr*/)
|
||
: CDTYG_XG(AcDbX3dSolid::kSweep, IDD, pParent) { }
|
||
|
||
CDTYG_XG_BDPipeBase::~CDTYG_XG_BDPipeBase()
|
||
{
|
||
}
|
||
|
||
bool CDTYG_XG_BDPipeBase::init(AcDbObjectId & idEntity, LPCTSTR guid, AcDbObjectId &hlid)
|
||
{
|
||
if (!CDTYG_XG::init(idEntity, guid, hlid)) return false;
|
||
|
||
SetWindowText(_T("修改异形墙体"));
|
||
if (GetDlgItem(IDC_STATIC_TIP))
|
||
{
|
||
GetDlgItem(IDC_STATIC_TIP)->SetWindowText(_T("请直接修改红色截面和黄色路径。"));
|
||
}
|
||
|
||
drawRegion();
|
||
|
||
return true;
|
||
}
|
||
|
||
DLLIMPEXP void transfromRegion(AcDbRegion *pRegion, const AcGePoint3d &ptOnRegion, const AcGeVector3d &vtNormal, const AcGePoint3d &ptOnPlan);
|
||
DLLIMPEXP void invertTransfromRegion(AcDbRegion *pRegion, const AcGePoint3d &ptOnRegion, const AcGeVector3d &vtNormal, const AcGePoint3d &ptOnPlan);
|
||
|
||
void CDTYG_XG_BDPipeBase::drawRegion()
|
||
{
|
||
AcAxDocLock lock;
|
||
|
||
OPENOBJ_BEGIN(m_idEntity, AcDb::kForRead, AecDbBDPipeBase, pWall)
|
||
if (pWall)
|
||
{
|
||
initLayers(true);
|
||
|
||
// 提取路径
|
||
AcDbCurve *pCurve = pWall->GetBaseCurve();
|
||
if (!pCurve)
|
||
{
|
||
initLayers(false);
|
||
return;
|
||
}
|
||
pCurve->setColorIndex(2);
|
||
pCurve->setLayer(LayerTools::g_sLayerName);
|
||
|
||
CoreTools::AddToModelSpace(pCurve, NULL, true, &m_idPath);
|
||
|
||
if (!m_idPath.isValid())
|
||
{
|
||
acutPrintf(_T("\n旋转轴插入失败!"));
|
||
initLayers(false);
|
||
return;
|
||
}
|
||
|
||
AcGePoint3d ptOnRegion;
|
||
pWall->GetSpecialtyData(AcDb::kForRead)->GetAt(KEY_SECCEN, ptOnRegion);
|
||
|
||
double dSta = 0.0;
|
||
pCurve->getStartParam(dSta);
|
||
|
||
AcGeVector3d vtDir;
|
||
pCurve->getFirstDeriv(dSta, vtDir);
|
||
|
||
AcGePoint3d ptOnPlan;
|
||
pCurve->getStartPoint(ptOnPlan);
|
||
m_ptOldStartPoint = ptOnPlan;
|
||
|
||
AcDbRegion *pReg = pWall->GetSection();
|
||
if (!pReg) return;
|
||
|
||
transfromRegion(pReg, ptOnRegion, vtDir, ptOnPlan);
|
||
|
||
AcDbVoidPtrArray ar;
|
||
if (Acad::eOk != pReg->explode(ar))
|
||
{
|
||
deleteArrayVoidPtrs< AcDbEntity>(ar);
|
||
initLayers(false);
|
||
return;
|
||
}
|
||
|
||
// 再将ar合成pline
|
||
std::vector<AcDbPolyline*> pls;
|
||
CoreTools::MakePolyline(ar, pls);
|
||
if (pls.empty())
|
||
{
|
||
deleteArrayVoidPtrs< AcDbEntity>(ar);
|
||
initLayers(false);
|
||
return;
|
||
}
|
||
|
||
AcDbPolyline *pSection = (AcDbPolyline*)pls[0]->clone();
|
||
pSection->setLayer(LayerTools::g_sLayerName);
|
||
deleteContainerOfStd(pls);
|
||
|
||
CoreTools::AddToModelSpace(pSection, NULL, true, &m_idReg);
|
||
if (!m_idReg.isValid())
|
||
{
|
||
acutPrintf(_T("\n截面曲线插入失败!"));
|
||
initLayers(false);
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
return;
|
||
OPENOBJ_END()
|
||
|
||
acedPostCommand(_T("r "));
|
||
|
||
// 锁定实体不允许删除
|
||
m_interObjs.push_back(m_idReg);
|
||
m_interObjs.push_back(m_idPath);
|
||
AddOverrules();
|
||
}
|
||
|
||
void CDTYG_XG_BDPipeBase::OnBnClickedOk()
|
||
{
|
||
AcAxDocLock lock;
|
||
resetLayersAndOverrules();
|
||
do
|
||
{
|
||
if (m_idReg.isValid() && m_idPath.isValid())
|
||
{
|
||
// 还原环境
|
||
AcDbPolyline *pSection(NULL);
|
||
OPENOBJ_BEGIN(m_idReg, AcDb::kForRead, AcDbPolyline, pReg)
|
||
if (pReg)
|
||
pSection = (AcDbPolyline*)pReg->clone();
|
||
OPENOBJ_END()
|
||
|
||
AcDbCurve *pCurve(NULL);
|
||
OPENOBJ_BEGIN(m_idPath, AcDb::kForRead, AcDbCurve, pC)
|
||
if (pC)
|
||
pCurve = (AcDbCurve*)pC->clone();
|
||
OPENOBJ_END()
|
||
|
||
if (!pSection) break;
|
||
if (!pCurve) break;
|
||
|
||
AcDbEntity *pEnt(NULL);
|
||
Acad::ErrorStatus es = acdbOpenAcDbEntity(pEnt, m_idEntity, AcDb::kForWrite);
|
||
if (pEnt)
|
||
pEnt->close();
|
||
|
||
OPENOBJ_BEGIN(m_idEntity, AcDb::kForWrite, AecDbBDPipeBase, pWall)
|
||
{
|
||
if (!pWall) break;
|
||
|
||
AcGePoint3d ptOnXOY;
|
||
pWall->GetSpecialtyData(AcDb::kForRead)->GetAt(KEY_SECCEN, ptOnXOY);
|
||
|
||
// 先把截面移动到路径起点
|
||
AcGePoint3d ptNewStartPoint;
|
||
pCurve->getStartPoint(ptNewStartPoint);
|
||
|
||
AcGeVector3d vtDir;
|
||
pCurve->getFirstDeriv(ptNewStartPoint, vtDir);
|
||
|
||
AcGeMatrix3d mat;
|
||
mat.setToTranslation(ptNewStartPoint - m_ptOldStartPoint);
|
||
pSection->transformBy(mat);
|
||
|
||
AcDbRegion *pReg = CoreTools::createRegion(pSection);
|
||
if (!pReg) break;
|
||
|
||
invertTransfromRegion(pReg, ptOnXOY, vtDir, ptNewStartPoint);
|
||
|
||
pWall->SetSection(pReg, ptOnXOY);
|
||
|
||
pWall->SetBaseCurve(pCurve);
|
||
|
||
DELETE_PTR(pCurve);
|
||
|
||
DELETE_PTR(pSection);
|
||
|
||
//TEST
|
||
//CoreTools::AddToModelSpace(pReg);
|
||
|
||
DELETE_PTR(pReg);
|
||
}
|
||
OPENOBJ_END()
|
||
}
|
||
} while (false);
|
||
|
||
CDTYG_XG::OnOK();
|
||
}
|
||
#pragma endregion
|
||
|