248 lines
5.5 KiB
C++
248 lines
5.5 KiB
C++
#include "stdafx.h"
|
|
#include "globalfunc.h"
|
|
#include "XBlock.h"
|
|
#include "GeRectAngle.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
XBlock::XBlock()
|
|
{
|
|
m_pIterator = NULL;
|
|
m_pRecord = NULL;
|
|
m_pBlockTable = NULL;
|
|
m_pBlkRef = NULL;
|
|
}
|
|
|
|
|
|
BOOL XBlock::IsBlockExist(const TCHAR* szBlkName, BOOL bLoadIt)
|
|
{
|
|
m_pRecord = NULL;
|
|
m_pIterator = NULL;
|
|
m_pBlockTable = NULL;
|
|
m_pBlkRef = NULL;
|
|
|
|
AcDbObjectId recordId;
|
|
acdbCurDwg()->getBlockTable(m_pBlockTable, AcDb::kForRead);
|
|
#if ARX > 24
|
|
if(Acad::eOk != m_pBlockTable->getAt(szBlkName, recordId)){
|
|
#else
|
|
if(Acad::eOk != m_pBlockTable->getAt(szBlkName, recordId, AcDb::kForRead)){
|
|
#endif
|
|
m_pBlockTable->close();
|
|
if(bLoadIt){
|
|
SHads_command(RTSTR, _T(".INSERT"), RTSTR, szBlkName, RTNONE);
|
|
SHads_command(RTNONE);
|
|
return TRUE;
|
|
}
|
|
else
|
|
return FALSE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
XBlock::XBlock(Entity entBlk)
|
|
{
|
|
m_pRecord = NULL;
|
|
m_pIterator = NULL;
|
|
m_pBlockTable = NULL;
|
|
m_pBlkRef = NULL;
|
|
m_entBlk = entBlk;
|
|
m_entBlk.GetData(2, m_szBlkName);
|
|
|
|
m_bInitSuccess = InitBlock();
|
|
}
|
|
|
|
XBlock::~XBlock()
|
|
{
|
|
if(m_pIterator)
|
|
delete m_pIterator;
|
|
if(m_pRecord)
|
|
m_pRecord->close();
|
|
if(m_pBlockTable)
|
|
m_pBlockTable->close();
|
|
if(m_pBlkRef)
|
|
m_pBlkRef->close();
|
|
}
|
|
|
|
|
|
BOOL XBlock::InitBlock()
|
|
{
|
|
acdbGetObjectId(m_eId, m_entBlk);
|
|
acdbOpenObject(m_pBlkRef, m_eId, AcDb::kForRead);
|
|
if(!m_pBlkRef)
|
|
return FALSE;
|
|
|
|
m_matrix = m_pBlkRef->blockTransform();
|
|
acdbCurDwg()->getBlockTable(m_pBlockTable, AcDb::kForRead);
|
|
if(Acad::eOk != m_pBlockTable->getAt(m_szBlkName, m_pRecord, AcDb::kForRead))
|
|
return FALSE;
|
|
|
|
if(!m_pRecord)
|
|
return FALSE;
|
|
m_pRecord->newIterator(m_pIterator);
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
|
|
void XBlock::GetBlkExtents(AcGePoint3d &pMax, AcGePoint3d &pMin)
|
|
{
|
|
AcDbExtents extents;
|
|
m_pBlkRef->getGeomExtents(extents);
|
|
pMax = extents.maxPoint();
|
|
pMin = extents.minPoint();
|
|
}
|
|
|
|
double XBlock::GetEntBlkLength()
|
|
{
|
|
AcGePoint3d pMax, pMin;
|
|
GetBlkExtents(pMax, pMin);
|
|
double nBlkLength = fabs(pMax[0] - pMin[0]);
|
|
return nBlkLength;
|
|
}
|
|
|
|
double XBlock::GetEntBlkHeight()
|
|
{
|
|
AcGePoint3d pMax, pMin;
|
|
GetBlkExtents(pMax, pMin);
|
|
double nBlkHeight = fabs(pMax[1] - pMin[1]);
|
|
return nBlkHeight;
|
|
}
|
|
|
|
void XBlock::TransformBy(const AcGeMatrix3d& xform)
|
|
{
|
|
m_pBlkRef->close();
|
|
AcDbBlockReference *pBlkRef = NULL;
|
|
acdbOpenObject(m_pBlkRef, m_eId, AcDb::kForWrite);
|
|
if(!m_pBlkRef)
|
|
return;
|
|
m_pBlkRef->transformBy(xform);
|
|
m_pBlkRef->close();
|
|
acdbOpenObject(m_pBlkRef, m_eId, AcDb::kForRead);
|
|
}
|
|
|
|
|
|
|
|
|
|
// pt3 1 pt1
|
|
// |-----------------------|
|
|
// | 2 4 |
|
|
// |-----------------------|
|
|
// pt2 3 pt4
|
|
|
|
|
|
void XBlock::GetBlkBreakByLine(XLine l, double nBreLen, XPoint &ptBr1, XPoint &ptBr2)
|
|
{
|
|
XPoint ptMax, ptMin, pt1, pt2, pt3, pt4;
|
|
GetBlkExtents(ptMax, ptMin);
|
|
ads_polar(ptMax, (PI * 0.25), nBreLen / 2, pt1);
|
|
ads_polar(ptMin, (PI * 1.25), nBreLen / 2, pt2);
|
|
XRectAngle rect(pt1, pt2);
|
|
int ret = rect.Intersection(l,ptBr1, ptBr2);
|
|
if(ret == 2 || ret == 0)
|
|
return;
|
|
if(l.StartPoint().x > rect.lowLeft.x && l.StartPoint().x < rect.upRight.x
|
|
&& l.StartPoint().y > rect.lowLeft.y && l.StartPoint().y > rect.upRight.y )
|
|
ptBr2 = l.StartPoint();
|
|
else
|
|
ptBr2 = l.EndPoint();
|
|
|
|
}
|
|
|
|
void XBlock::GetBlkBreakByArc(XArc xarc, double nBreLen, XPoint &ptBr1, XPoint &ptBr2)
|
|
{
|
|
XPoint ptMax, ptMin, pt1, pt2, pt3, pt4;
|
|
GetBlkExtents(ptMax, ptMin);
|
|
ads_polar(ptMax, (PI * 0.25), nBreLen / 2, pt1);
|
|
ads_polar(ptMin, (PI * 1.25), nBreLen / 2, pt2);
|
|
|
|
pt3.x = pt2.x;
|
|
pt3.y = pt1.y;
|
|
pt4.x = pt1.x;
|
|
pt4.y = pt2.y;
|
|
|
|
XLine l1(pt1, pt3, LS_FINITE);
|
|
XLine l2(pt3, pt2, LS_FINITE);
|
|
XLine l3(pt2, pt4, LS_FINITE);
|
|
XLine l4(pt4, pt1, LS_FINITE);
|
|
if(xarc.Intersection(&l1, ptBr1, ptBr2) == 1){
|
|
if(xarc.Intersection(&l2, ptBr2, ptBr1) == 1)
|
|
return;
|
|
if(xarc.Intersection(&l3, ptBr2, ptBr1) == 1)
|
|
return;
|
|
if(xarc.Intersection(&l4, ptBr2, ptBr1) == 1)
|
|
return;
|
|
}
|
|
if(xarc.Intersection(&l2, ptBr1, ptBr2) == 1){
|
|
if(xarc.Intersection(&l1, ptBr2, ptBr1) == 1)
|
|
return;
|
|
if(xarc.Intersection(&l3, ptBr2, ptBr1) == 1)
|
|
return;
|
|
if(xarc.Intersection(&l4, ptBr2, ptBr1) == 1)
|
|
return;
|
|
}
|
|
if(xarc.Intersection(&l3, ptBr1, ptBr2) == 1){
|
|
if(xarc.Intersection(&l1, ptBr2, ptBr1) == 1)
|
|
return;
|
|
if(xarc.Intersection(&l2, ptBr2, ptBr1) == 1)
|
|
return;
|
|
if(xarc.Intersection(&l4, ptBr2, ptBr1) == 1)
|
|
return;
|
|
}
|
|
if(xarc.Intersection(&l4, ptBr1, ptBr2) == 1){
|
|
if(xarc.Intersection(&l1, ptBr2, ptBr1) == 1)
|
|
return;
|
|
if(xarc.Intersection(&l2, ptBr2, ptBr1) == 1)
|
|
return;
|
|
if(xarc.Intersection(&l3, ptBr2, ptBr1) == 1)
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
void XBlock::GetBlkBreakPt(Entity entBreak, double nBreLen, XPoint &ptBr1, XPoint &ptBr2)
|
|
{
|
|
if(entBreak.Is(_T("LINE"))){
|
|
XPoint ptStart, ptEnd;
|
|
GlobalFunc::GetWire2Point(entBreak, ptStart, ptEnd);
|
|
XLine l(ptStart, ptEnd, LS_FINITE);
|
|
GetBlkBreakByLine(l, nBreLen, ptBr1, ptBr2);
|
|
}
|
|
else if(entBreak.Is(_T("ARC"))){
|
|
XArc xarc(entBreak);
|
|
GetBlkBreakByArc(xarc, nBreLen, ptBr1, ptBr2);
|
|
}
|
|
else if(entBreak.Is(_T("LWPOLYLINE"))){
|
|
XPoly2D xpoly(entBreak);
|
|
for(int n=0; n<xpoly.TotalSegments(); n++) {
|
|
XCurveSegment seg;
|
|
xpoly.Nth(n, seg);
|
|
XPoint ptInters, ptInters2, ptBreak1, ptBreak2;
|
|
if(seg.Is(CURVE_LINE)){
|
|
GetBlkBreakByLine(seg.GetLine(), nBreLen, ptBr1, ptBr2);
|
|
}
|
|
else if(seg.Is(CURVE_ARC)){
|
|
GetBlkBreakByArc(seg.GetArc(), nBreLen, ptBr1, ptBr2);
|
|
}
|
|
if(!!ptBr1 && !!ptBr2)
|
|
return;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|