145 lines
3.4 KiB
C++
145 lines
3.4 KiB
C++
// XWindow.cpp: implementation of the XWindow class.
|
|
//
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "XWindow.h"
|
|
#include "tapi.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
// Construction/Destruction
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
XWindow::XWindow(Entity entWin) : XBlock(entWin)
|
|
{
|
|
double xscale, yscale;
|
|
entWin.GetData(41, &xscale);
|
|
entWin.GetData(42, &yscale);
|
|
entWin.GetData(10, m_ptIns);
|
|
entWin.GetData(50, &m_nRotate);
|
|
CString csBlkName;
|
|
TCHAR szBlkName[256];
|
|
entWin.GetData(2, szBlkName);
|
|
csBlkName = szBlkName;
|
|
if(csBlkName.Find(_T('$')) == 0)
|
|
m_bIsDoorTch5 = TRUE;
|
|
else
|
|
m_bIsDoorTch5 = FALSE;
|
|
|
|
|
|
if(fabs(fabs(xscale) - fabs(yscale)) < 0.0001)
|
|
m_bIsDoor = TRUE;
|
|
else
|
|
m_bIsDoor = FALSE;
|
|
RBList rbMask(RTDXF0, _T("LINE"), 8, LAY_WALL, NULL);
|
|
if(m_bIsDoorTch5){
|
|
ads_polar(m_ptIns, m_nRotate, xscale/2, m_ptSideFront);
|
|
ads_polar(m_ptIns, m_nRotate + PI, xscale/2, m_ptSideBack);
|
|
}
|
|
else{
|
|
ads_polar(m_ptIns, m_nRotate + PI, xscale/2, m_ptSideFront);
|
|
ads_polar(m_ptIns, m_nRotate, xscale/2, m_ptSideBack);
|
|
}
|
|
PickSet ssWall(SS_FREE);
|
|
GetPointPickSet(m_ptSideBack, ssWall, rbMask, 200);
|
|
if(ssWall.Length() != 3)
|
|
return;
|
|
m_nWallWidth = -1;
|
|
for(long i=0;i<3;i++){
|
|
Entity ent = ssWall[i];
|
|
XLine line(ent, 1);
|
|
if((m_ptSideBack&line) == PR_INSIDE){
|
|
m_nWallWidth = line.GetLength();
|
|
m_entShortWall = ent;
|
|
}
|
|
else{
|
|
if(!m_entLongWall1)
|
|
m_entLongWall1 = ent;
|
|
else
|
|
m_entLongWall2 = ent;
|
|
}
|
|
}
|
|
}
|
|
|
|
XWindow::~XWindow()
|
|
{
|
|
|
|
}
|
|
|
|
BOOL XWindow::GetInsEquipPt(XPoint &ptPick, double &nRotate, double nDist)
|
|
{
|
|
XLine line(LS_FINITE);
|
|
if(!GetPickOnLine(ptPick, line))
|
|
return FALSE;
|
|
double angle = ads_angle(line.StartPoint(), line.EndPoint());
|
|
angle += PI/2;
|
|
XPoint pt1, pt2;
|
|
ads_polar(ptPick, angle, 800, pt1);
|
|
ads_polar(ptPick, angle, 1, pt2);
|
|
int iInters1=0, iInters2 = 0;
|
|
int len = m_lstLine.Length();
|
|
for(int i=0;i<len;i++){
|
|
XLine l = *m_lstLine[i];
|
|
XPoint ptTemp;
|
|
XLine lineTmp(pt1,pt2,1);
|
|
if(l.Intersection(&lineTmp, ptTemp))
|
|
iInters1 ++;
|
|
}
|
|
ads_polar(ptPick, angle + PI, 800, pt1);
|
|
ads_polar(ptPick, angle + PI, 1, pt2);
|
|
for(i=0;i<len;i++){
|
|
XLine l = *m_lstLine[i];
|
|
XPoint ptTemp;
|
|
XLine lineTmp(pt1,pt2,1);
|
|
if(l.Intersection(&lineTmp, ptTemp))
|
|
iInters2 ++;
|
|
}
|
|
if(iInters2 > iInters1)
|
|
angle -= PI/2;
|
|
else
|
|
angle += PI/2;
|
|
ads_polar(ptPick, angle + PI/2, nDist, ptPick);
|
|
nRotate = angle * 180/ PI;
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL XWindow::GetPickOnLine(XPoint ptPick, XLine &line)
|
|
{
|
|
m_lstLine.Reset();
|
|
AcDbBlockTableRecordIterator *pIterator;
|
|
pIterator = GetIterator();
|
|
BOOL bFlag = FALSE;
|
|
|
|
for(pIterator->start(); !pIterator->done(); pIterator->step()){
|
|
AcDbEntity *pEnt;
|
|
pIterator->getEntity(pEnt, AcDb::kForRead);
|
|
AcDbLine *pll = NULL;
|
|
if(pll = AcDbLine::cast(pEnt)){
|
|
AcGePoint3d ptStart, ptEnd;
|
|
ptStart = pll->startPoint();
|
|
ptEnd = pll->endPoint();
|
|
ptStart = ptStart.transformBy(GetMatrix3d());
|
|
ptEnd = ptEnd.transformBy(GetMatrix3d());
|
|
XLine line2(asDblArray(ptStart), asDblArray(ptEnd), LS_FINITE);
|
|
m_lstLine.Append(new XLine(line2));
|
|
int ret = ptPick&line2;
|
|
if(ret == PR_ONPT1 || ret == PR_ONPT2 || ret == PR_INSIDE){
|
|
bFlag = TRUE;
|
|
line = line2;
|
|
}
|
|
//pll->close();
|
|
}
|
|
pEnt->close();
|
|
}
|
|
return bFlag;
|
|
}
|
|
|