Files
envi-code/SourceCode/Code2026/tg_shs/shs_siteplan/ParkingSpaceCmd.cpp
T
2026-09-28 15:28:50 +08:00

2046 lines
54 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "stdafx.h"
#include "ParkingSpaceDlg.h"
#include "TDbParkingSpace.h"
#include "TDbParking.h"
#include "TGAs.h"
#include "rxregsvc.h"
extern AcDbObjectIdArray GetAllEntityId(const TCHAR* layername);
extern double GetOneParkingArcLength(XArc &arc, double dWidth, double dDept, BOOL bIsInside);
extern int is_digit(WCHAR *str);
static double g_dOffsetDistance = 0.0;
namespace
{
//根据点取点离着最近的多段线的边,判断点取的点在多段线的哪侧
int PointSizeToPolyLine(AcDbPolyline* pEntBase, AcGePoint3d ptSize)
{
int iSize = -1;
XPoly2D polyParking;
PolyConvert(*pEntBase, polyParking);
AcGePoint3d ptSizeOnLine;
pEntBase->getClosestPointTo(ptSize, ptSizeOnLine);
int nRet = polyParking.HitTestOnCurve(ptSizeOnLine);
g_dOffsetDistance = ptSize.distanceTo(ptSizeOnLine);
if (nRet == 0)//nRet=0表示不在线上
{
return 1;
}
if (nRet > 0)//nRet>0时表示的是输入点在第几个顶点上
{
nRet = nRet - 2;
}
if (nRet < 0)//nRet<0时|nRet|表示的是输入点在第几条边上
{
nRet = nRet + 1;
}
AcDbPolyline::SegType type = pEntBase->segType(abs(nRet));
if (type == AcDbPolyline::kLine)
{
AcGeLineSeg3d curSelsegline;
pEntBase->getLineSegAt(abs(nRet),curSelsegline);
XLine line((XPoint)curSelsegline.startPoint(), (XPoint)curSelsegline.endPoint());
if (line.OnWhichSide(ptSize))//// 0--Left, 1--Right, 2--Other
iSize = -1; //右侧
else
iSize = 1; //左侧
}
else
{
AcGeCircArc3d geArc;
pEntBase->getArcSegAt(abs(nRet),geArc);
double dBugle = 0;
pEntBase->getBulgeAt(abs(nRet), dBugle);
if (ptSize.distanceTo(geArc.center()) < geArc.radius() && dBugle < 0)
iSize = -1;
else if (ptSize.distanceTo(geArc.center()) < geArc.radius() && dBugle > 0)
iSize = 1;
else if (ptSize.distanceTo(geArc.center()) > geArc.radius() && dBugle < 0)
iSize = 1;
else if (ptSize.distanceTo(geArc.center()) > geArc.radius() && dBugle > 0)
iSize = -1;
}
return iSize;
}
//圆弧的真实偏移
// 路径偏移,各顶点计算偏移,再求顶点的圆心角(弧段),构成偏移线
int GetSizeOfArc(const AcGeCircArc3d &geArc, int iSize, double dBugle,int i, const XPoly2D &polyParking)
{
int iRetSize = 1;
TGGePoly2D destPoly;
if (iSize == 1)
{
polyParking.QuickOffset(-g_dOffsetDistance, destPoly);
}
else
polyParking.QuickOffset(g_dOffsetDistance, destPoly);
TADSGePoint3d* ptCurPoint =new TADSGePoint3d;
ptCurPoint = destPoly.GetPointListAt(i);
AcGePoint3d ptPoint(ptCurPoint->x, ptCurPoint->y, ptCurPoint->z);
if (ptPoint.distanceTo(geArc.center()) < geArc.radius() )
{
iRetSize = 1;
}
else
{
iRetSize = -1;
}
return iRetSize;
}
}
class THook
{
public:
THook(TCHAR *pszKeyWord = NULL);
~THook();
int GetValue();
CString GetKeyWord();
public:
enum
{
eLBUTTONDOWN = 0,
eRBUTTONDOWN = 1,
eESC = 2,
eKeyWord = 3
};
protected:
#if ADS > 22
static bool ListenMsg(MSG* pMsg);
#else
static BOOL ListenMsg(MSG* pMsg);
#endif
private:
static int s_iValue; //0:左键,1:空格、回车、右键,2:ESC键,3:关键字
static CString s_sKeyRet; //返回的关键字(单个)
static CString s_sKeyWord; //关键字串
};
int THook::s_iValue = -1;
CString THook::s_sKeyRet = _T("");
CString THook::s_sKeyWord = _T("");
THook::THook(TCHAR *pszKeyWord)
{
s_sKeyWord = _T("");
s_sKeyWord = pszKeyWord;
acedRegisterFilterWinMsg(ListenMsg);
}
THook::~THook()
{
acedRemoveFilterWinMsg(ListenMsg);
}
int THook::GetValue()
{
int iRe = s_iValue;
s_iValue = -1;
return iRe;
}
CString THook::GetKeyWord()
{
CString sz = s_sKeyRet;
s_sKeyRet = _T("");
return sz;
}
#if ADS > 22
bool THook::ListenMsg(MSG* pMsg)
#else
BOOL THook::ListenMsg(MSG* pMsg)
#endif
{
switch (pMsg->message)
{
case WM_RBUTTONDOWN:
{
s_iValue = 1;
}
break;
case WM_LBUTTONDOWN:
{
s_iValue = 0;
}
break;
case WM_KEYDOWN:
{
if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_SPACE)
{
s_iValue = 1;
}
else if (pMsg->wParam == VK_ESCAPE)
{
s_iValue = 2;
}
else
{
for (int i = 0; i < s_sKeyWord.GetLength(); i++)
{
if (pMsg->wParam == s_sKeyWord[i])//关键字
{
ads_printf(CString(s_sKeyWord[i]));
s_sKeyRet.Format(_T("%c"),(TCHAR)pMsg->wParam);
pMsg->wParam = VK_RETURN;
s_iValue = 3;
break;
}
}
}
}
break;
default:
break;
}
return(false);//消息继续传递下去
}
void AddSerialNumForArc(XPoint &ptCenter, ATSParking &dbPark, const CString &strSerialNum, CParkingSpaceDlg *pDlg)
{
XPoint ptText = dbPark.GetPtText();
double angle = ads_angle(XPoint(ptCenter), XPoint(ptText));
//add tyj 20160830:可以按当前坐标系确定文字的翻转方向
ptText = Wcs2Ucs(ptText);
ptCenter = Wcs2Ucs(ptCenter);
if (ptText.y < ptCenter.y)
angle += 0.5 * PI;
else
angle -= 0.5 * PI;
TDbText* text = new TDbText;
text->SetText(strSerialNum);
text->SetHeight(pDlg->GetTextHeigh());
text->SetRotation(angle);
text->SetLocation(dbPark.GetPtText());
AcDbObjectId idTextStyle = GetTextStyleId(pDlg->GetTextStyle());
if (idTextStyle.isValid())
text->SetStyleId(idTextStyle);
else
text->SetStyleId(acdbCurDwg()->textstyle());
text->setLayer(::InitLayer(LAY_PKNG_SING));
text->SetAlignment(XExplodeDraw::kMiddleCenter);
AddToCurrentSpace(text, Adesk::kTrue);
}
void AddSerialNum(ATSParking &dbPark, const CString &strSerialNum, AcGeVector3d &VectorOffet, CParkingSpaceDlg *pDlg, int nSize = 1)
{
//修改 tyj 20160830:可以按当前坐标系确定文字的翻转方向
bool bXYFlag = true;//表示在UCS下,Y轴与X轴的夹角为90度还是270度。true 表示夹角为90度
AcGeVector3d vtXAxisUCS = Ucs2Wcs(AcGeVector3d::kXAxis, true);
AcGeVector3d vtYAxisUCS = Ucs2Wcs(AcGeVector3d::kYAxis, true);
//Ucs的X轴在Wcs下X轴方向的角度
double dRotX = acutAngle(asDblArray(AcGePoint3d::kOrigin), asDblArray(vtXAxisUCS));
//Ucs的Y轴在Wcs下X轴方向的角度
double dRotY = acutAngle(asDblArray(AcGePoint3d::kOrigin), asDblArray(vtYAxisUCS));
double dXYAngle = dRotY - dRotX;
if((dXYAngle > PI)||((dXYAngle > -0.6*PI)&&(dXYAngle < -0.4*PI)))//判断UCS坐标系下,X Y夹角是否为270
{
bXYFlag = false;
}
AcGeVector2d VectorOffet2d;
VectorOffet2d.x = VectorOffet.x;
VectorOffet2d.y = VectorOffet.y;
double dIncludedAngle = VectorOffet2d.angle();//文字书写方向与WCSX轴的夹角
dIncludedAngle -= dRotX;//文字书写方向与UCSX轴的夹角
if (dIncludedAngle < 0)
{
dIncludedAngle += 2*PI;
}
TDbText* text = new TDbText;
text->SetText(strSerialNum);
text->SetHeight(pDlg->GetTextHeigh());
int nAngle = pDlg->GetAngle();
if (pDlg->GetWidth() > pDlg->GetHeight())
{
if(bXYFlag)//Y轴与X轴的夹角为90度
{
if ((dIncludedAngle > 0.5 * PI)&&(dIncludedAngle < 1.5*PI))
{
if (nSize == -1)
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle());
}
else
{
text->SetRotation(dbPark.GetRotAngle() + PI);
}
}
else
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle() + PI);
}
else
{
text->SetRotation(dbPark.GetRotAngle() + PI);
}
}
}
else
{
if (nSize == -1)
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle() + PI);
}
else
{
text->SetRotation(dbPark.GetRotAngle());
}
}
else
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle());
}
else
{
text->SetRotation(dbPark.GetRotAngle());
}
}
}
}
else//Y轴与X轴的夹角为270度
{
if ((dIncludedAngle < 0.5 * PI)||(dIncludedAngle > 1.5*PI))
{
if (nSize == -1)
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle());
}
else
{
text->SetRotation(dbPark.GetRotAngle() + PI);
}
}
else
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle() + PI);
}
else
{
text->SetRotation(dbPark.GetRotAngle() + PI);
}
}
}
else
{
if (nSize == -1)
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle() + PI);
}
else
{
text->SetRotation(dbPark.GetRotAngle());
}
}
else
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle());
}
else
{
text->SetRotation(dbPark.GetRotAngle());
}
}
}
}
}
else
{
if(bXYFlag)//Y轴与X轴的夹角为90度
{
if ((dIncludedAngle > 0.5 * PI)&&(dIncludedAngle < 1.5*PI))
{
if (nSize == -1)
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle());
}
else
{
text->SetRotation(dbPark.GetRotAngle() - (90 - nAngle)*PI/180);
}
}
else
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle() + PI);
}
else
{
text->SetRotation(dbPark.GetRotAngle() + PI + (90 - nAngle)*PI/180);
}
}
}
else
{
if (nSize == -1)
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle() + PI);
}
else
{
text->SetRotation(dbPark.GetRotAngle() + PI - (90 - nAngle)*PI/180);
}
}
else
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle());
}
else
{
text->SetRotation(dbPark.GetRotAngle() + (90 - nAngle)*PI/180);
}
}
}
}
else//Y轴与X轴的夹角为270度
{
if ((dIncludedAngle < 0.5 * PI)||(dIncludedAngle > 1.5*PI))
{
if (nSize == -1)
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle());
}
else
{
text->SetRotation(dbPark.GetRotAngle() - (90 - nAngle)*PI/180);
}
}
else
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle() + PI);
}
else
{
text->SetRotation(dbPark.GetRotAngle() + PI + (90 - nAngle)*PI/180);
}
}
}
else
{
if (nSize == -1)
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle() + PI);
}
else
{
text->SetRotation(dbPark.GetRotAngle() + PI - (90 - nAngle)*PI/180);
}
}
else
{
if (nAngle == 90)
{
text->SetRotation(dbPark.GetRotAngle());
}
else
{
text->SetRotation(dbPark.GetRotAngle() + (90 - nAngle)*PI/180);
}
}
}
}
}
text->SetLocation(dbPark.GetPtText());
AcDbObjectId idTextStyle = GetTextStyleId(pDlg->GetTextStyle());
if (idTextStyle.isValid())
text->SetStyleId(idTextStyle);
else
text->SetStyleId(acdbCurDwg()->textstyle());
text->setLayer(::InitLayer(LAY_PKNG_SING));
text->SetAlignment(XExplodeDraw::kMiddleCenter);
AddToCurrentSpace(text, Adesk::kTrue);
}
//////////////////////////////////////////////////////////////////////////
//outVector 输出变量:基向量
//ioutNum 输出变量:个数
//doutAngl 输出变量:弦所对的圆周角,对于AcDbLine始终为0
//pEnt 输入变量:实体
//angle 输入变量:角度,对于AcDbArc或AcDbPolyline弧部分始终为0
//iWidth 输入变量:宽度
//iHeight 输入变量:深度
//iSize 输入变量:曲线那一边 -1 1
//iIndex 输入变量:多线段的哪一段,对于AcDbLine、AcDbArc始终为0
void GetParkInfo(AcGeVector3d &outVector,int &ioutNum,double &doutAngl,
AcDbEntity *pEnt,int angle, double iWidth, double iHeight,int iSize,int iIndex)
{
AcGeVector3d vec(0,0,0);
double dRoateAngle = 0;
int iNum = 0;
if (!pEnt)
{
return ;
}
//直线
if (pEnt->isKindOf(AcDbLine::desc()))
{
AcDbLine *pLine = AcDbLine::cast(pEnt);
if (pLine)
{
TADSGePoint3d ptStart;
ptStart = pLine->startPoint();
TADSGePoint3d ptEnd;
ptEnd = pLine->endPoint();
XLine lineBase(ptStart,ptEnd);
ads_real rAngBase = lineBase.Direction();
ads_point ptads4;
acutPolar(ptStart,(rAngBase + angle*PI/180),iHeight,ptads4);
TADSGePoint3d ptVertex4 = ptads4;
TADSGePoint3d ptVertex2;
ads_point pt20;
ads_point pt30;
XLine line14(ptStart,ptVertex4);
ads_real rAng14 = line14.Direction();
acutPolar(ptStart,(rAng14-0.5 * PI),iWidth,pt20);
acutPolar(ptVertex4,(rAng14-0.5 * PI),iWidth,pt30);
XLine line23(pt20,pt30);
ads_point pt2;
acutPolar(ptStart,(rAngBase),100,pt2);
XLine line2(ptStart,pt2);
line23.Intersection(&line2,ptVertex2);
vec = ptVertex2 - ptStart;
iNum = (ptStart.AsAcGePoint3d().distanceTo(ptEnd))/vec.length();
}
}
//圆弧
else if (pEnt->isKindOf(AcDbArc::desc()))
{
AcDbArc *pArc = AcDbArc::cast(pEnt);
if (pArc)
{
//圆弧外侧
if (iSize == -1)
{
TADSGePoint3d ptVertex1;
pArc->getStartPoint(ptVertex1);
TADSGePoint3d ptVertex2;
pArc->getPointAtDist(iWidth,ptVertex2);
vec = ptVertex2 - ptVertex1;
TADSGePoint3d ptEnd;
pArc->getEndPoint(ptEnd);
AcGeVector3d v1 = ptVertex1 - pArc->center();
AcGeVector3d v2 = ptVertex2 - pArc->center();
AcGeVector3d v3 = ptEnd - pArc->center();
dRoateAngle = v1.angleTo(v2);
iNum = v1.angleTo(v3)/dRoateAngle;
}
//圆弧内侧
else if (iSize == 1)
{
TADSGePoint3d ptStart;
pArc->getStartPoint(ptStart);
TADSGePoint3d ptEnd;
pArc->getEndPoint(ptEnd);
double dMax = ptStart.AsAcGePoint3d().distanceTo(ptEnd);
TADSGePoint3d ptCenter = pArc->center();
TADSGePoint3d ptVertex1 = ptStart;
TADSGePoint3d ptVertex2;
TADSGePoint3d ptVertex3;
TADSGePoint3d ptVertex4;
for (int i=iWidth; i<(int)dMax; i++)
{
pArc->getPointAtDist(i,ptVertex2);
XLine lineBase(ptVertex1,ptVertex2);
ads_real rAng = lineBase.Direction();
ads_point pt1;
ads_point pt2;
acutPolar(ptVertex1,(rAng+iSize*0.5*PI),iHeight,pt1);
acutPolar(ptVertex2,(rAng+iSize*0.5*PI),iHeight,pt2);
XLine line1(pt1,pt2);
XLine line3(ptCenter,ptVertex2);
XLine line4(ptCenter,ptVertex1);
line1.Intersection(&line3,ptVertex3);
line1.Intersection(&line4,ptVertex4);
//离散计算
if (fabs(ptVertex3.AsAcGePoint3d().distanceTo(ptVertex4) - iWidth) < 1 )
{
vec = ptVertex2 - ptVertex1;
AcGeVector3d v1 = ptVertex1 - pArc->center();
AcGeVector3d v2 = ptVertex2 - pArc->center();
AcGeVector3d v3 = ptEnd - pArc->center();
dRoateAngle = v1.angleTo(v2);
iNum = v1.angleTo(v3)/dRoateAngle;
break;
}
}
}
}
}
//多段线中的某一段
else if (pEnt->isKindOf(AcDbPolyline::desc()))
{
AcDbPolyline *pPolyline = AcDbPolyline::cast(pEnt);
if (pPolyline)
{
AcDbPolyline::SegType eStyle = pPolyline->segType(iIndex);
//直线
if (eStyle== AcDbPolyline::kLine)
{
AcGeLineSeg2d line;
pPolyline->getLineSegAt(iIndex,line);
TADSGePoint3d ptStart;
ptStart = line.startPoint();
TADSGePoint3d ptEnd;
ptEnd = line.endPoint();
XLine lineBase(ptStart,ptEnd);
ads_real rAngBase = lineBase.Direction();
ads_point ptads4;
acutPolar(ptStart,(rAngBase + angle*PI/180),iHeight,ptads4);
TADSGePoint3d ptVertex4 = ptads4;
TADSGePoint3d ptVertex2;
ads_point pt20;
ads_point pt30;
XLine line14(ptStart,ptVertex4);
ads_real rAng14 = line14.Direction();
acutPolar(ptStart,(rAng14-0.5 * PI),iWidth,pt20);
acutPolar(ptVertex4,(rAng14-0.5 * PI),iWidth,pt30);
XLine line23(pt20,pt30);
ads_point pt2;
acutPolar(ptStart,(rAngBase),100,pt2);
XLine line2(ptStart,pt2);
line23.Intersection(&line2,ptVertex2);
vec = ptVertex2 - ptStart;
iNum = (ptStart.AsAcGePoint3d().distanceTo(ptEnd))/vec.length();
}
//圆弧
else if (eStyle == AcDbPolyline::kArc)
{
AcGeCircArc2d geArc;
pPolyline->getArcSegAt(iIndex,geArc);
double dBugle;
pPolyline->getBulgeAt(iIndex,dBugle);
//构造Db圆弧
AcDbArc dbArc(AcGePoint3d(geArc.center().x,geArc.center().y,0),geArc.radius(),geArc.startAng(),geArc.endAng());
//圆弧外侧
if (iSize == -1)
{
TADSGePoint3d ptDbArc1;
TADSGePoint3d ptDbArc2;
dbArc.getStartPoint(ptDbArc1);
dbArc.getPointAtDist(iWidth,ptDbArc2);
AcGeVector3d v1 = ptDbArc1 - dbArc.center();
AcGeVector3d v2 = ptDbArc2 - dbArc.center();
dRoateAngle = v1.angleTo(v2); //弦所对的圆周角
TADSGePoint3d ptVertex1;
ptVertex1.x = geArc.startPoint().x;
ptVertex1.y = geArc.startPoint().y;
AcGePoint3d ptVertex2 = ptVertex1;
ptVertex2.rotateBy((dBugle/fabs(dBugle))*dRoateAngle,AcGeVector3d(0,0,1),AcGePoint3d(geArc.center().x,geArc.center().y,0));
vec = ptVertex2 - ptVertex1.AsAcGePoint3d();
AcGeVector3d v11 = ptVertex1 - geArc.center();
AcGeVector3d v22 = AcGePoint3d(geArc.endPoint().x,geArc.endPoint().y,0) - geArc.center();
iNum = v11.angleTo(v22)/dRoateAngle;
}
//圆弧内侧
else if (iSize == 1)
{
TADSGePoint3d ptStart;
dbArc.getStartPoint(ptStart);
TADSGePoint3d ptEnd;
dbArc.getEndPoint(ptEnd);
double dMax = ptStart.AsAcGePoint3d().distanceTo(ptEnd);
TADSGePoint3d ptCenter = dbArc.center();
TADSGePoint3d ptVertex1 = ptStart;
AcGePoint3d ptVertex2;
TADSGePoint3d ptVertex3;
TADSGePoint3d ptVertex4;
for (int i=iWidth; i<(int)dMax; i++)
{
dbArc.getPointAtDist(i,ptVertex2);
XLine lineBase(ptVertex1,asDblArray(ptVertex2));
ads_real rAng = lineBase.Direction();
ads_point pt1;
ads_point pt2;
acutPolar(ptVertex1,(rAng+iSize*0.5*PI),iHeight,pt1);
acutPolar(asDblArray(ptVertex2),(rAng+iSize*0.5*PI),iHeight,pt2);
XLine line1(pt1,pt2);
XLine line3(ptCenter,asDblArray(ptVertex2));
XLine line4(ptCenter,ptVertex1);
line1.Intersection(&line3,ptVertex3);
line1.Intersection(&line4,ptVertex4);
//离散计算
if (fabs(ptVertex3.AsAcGePoint3d().distanceTo(ptVertex4) - iWidth) < 1 )
{
AcGeVector3d v1 = ptVertex1 - dbArc.center();
AcGeVector3d v2 = ptVertex2 - dbArc.center();
dRoateAngle = v1.angleTo(v2); //弦所对的圆周角
break;
}
}
ptVertex1.x = geArc.startPoint().x;
ptVertex1.y = geArc.startPoint().y;
ptVertex2 = ptVertex1;
ptVertex2.rotateBy((dBugle/fabs(dBugle))*dRoateAngle,AcGeVector3d(0,0,1),AcGePoint3d(geArc.center().x,geArc.center().y,0));
vec = ptVertex2 - ptVertex1.AsAcGePoint3d();
AcGeVector3d v1 = ptVertex1 - geArc.center();
AcGeVector3d v2 = AcGePoint3d(geArc.endPoint().x,geArc.endPoint().y,0) - geArc.center();
if (dRoateAngle == 0)
iNum = 0;
else
iNum = v1.angleTo(v2)/dRoateAngle;
}
}
}
}
outVector = vec;
ioutNum = iNum;
doutAngl = dRoateAngle;
}
//////////////////////////////////////////////////////////////////////////
//pEnt :实体
//pt :块插入图面位置
//idlayer:图层
//////////////////////////////////////////////////////////////////////////
AcDbObjectId FormBlock(AcDbEntity* pEnt,XPoint &pt,AcDbObjectId &idlayer)
{
AcDbObjectId id(NULL);
// Acad::ErrorStatus eReturn;
// AcDbBlockTable *pBlockTable = NULL;
// //获取块表指针
// eReturn = acdbCurDwg()->getBlockTable(pBlockTable,AcDb::kForWrite);
// if (eReturn!=Acad::eOk)
// {
// return id;
// }
//
// AcDbBlockTableRecord *pBlockTableRecord = NULL;
// pBlockTableRecord = new AcDbBlockTableRecord;
// eReturn = pBlockTable->add(id,pBlockTableRecord);
// pBlockTable->close();
// if (eReturn!=Acad::eOk)
// {
// delete pBlockTableRecord;
// return id;
// }
// //设置块基点
// pBlockTableRecord->setOrigin(pt);
//炸开,加入块中
AcDbVoidPtrArray entitySet;
if(pEnt->explode(entitySet) == Acad::eOk)
{
for (int i=0;i<entitySet.length();i++)
{
AcDbEntity *pSun = (AcDbEntity*)entitySet[i];
pSun->setLayer(idlayer);
// eReturn=pBlockTableRecord->appendAcDbEntity(pSun);
// pSun->close();
AcDbObjectId id = AddToModelSpace(pSun);
}
}
// pBlockTableRecord->close();
//块引用,加入模型空间
// AcDbBlockReference *pBlockReference = NULL;
// pBlockReference = new AcDbBlockReference(pt,id);
// pBlockReference->setLayer(idlayer);
// AddToModelSpace(pBlockReference);
if (pEnt)
{
delete pEnt;
}
return id;
}
//单排布置车位时的编号
CString GetTextForSingle(CString &strPrefix, CString &strPostfix, BOOL bIsFirst, int &nNum, int &nNumLength)
{
CString strText, strNum;
if (bIsFirst)
{
if (nNum)
strText.Format(_T("%s%d%s"), strPrefix, nNum, strPostfix);
else
strText.Format(_T("%s%s"), strPrefix, strPostfix);
}
else
{
strNum.Format(_T("%d"), ++nNum);
if (nNumLength == 0)
{
nNumLength = strNum.GetLength();
}
if ((strNum.GetLength() > nNumLength))
{
nNumLength = strNum.GetLength();
if (strPrefix.GetLength() > 0)
{
if (strPrefix.GetAt(strPrefix.GetLength() - 1) == '0')
{
strPrefix = strPrefix.Left(strPrefix.GetLength() - 1);
}
}
}
strText.Format(_T("%s%s%s"), strPrefix, strNum, strPostfix);
}
return strText;
}
//双排时布置车位的编号
CString GetTextForDouble(CString &strPrefix, CString &strPostfix, int &nTasksNum, int nNumLength)
{
CString strNum, strText;
strNum.Format(_T("%d"), nTasksNum--);
CString strTemp = strPrefix;
if ((strNum.GetLength() > nNumLength))
{
if (strNum.GetLength() > 0)
{
for (int i = 0; i < strNum.GetLength() - nNumLength; ++i)
{
if (strTemp.GetAt(strTemp.GetLength() - 1) == '0')
{
strTemp = strTemp.Left(strTemp.GetLength() - 1);
}
}
}
}
strText.Format(_T("%s%s%s"), strTemp, strNum, strPostfix);
return strText;
}
//加载图块
XString InitCarBlock()
{
XString sName;
//文件路径
XString sFilePath;
if (!FindFile(_T("车.TK"),sFilePath))
{
CString sTip;
sTip.Format(_T("对不起,没有发现[%s]文件!"),_T("车.TK"));
AfxMessageBox(sTip);
return sName;
}
//打开文件
CodeBase db;
XDbfTable *pTable = db.Open(sFilePath);
if (pTable == NULL)
{
acutPrintf(_T("\n打开文件%s失败!\n"), sFilePath);
return sName;
}
//读取数据
CString sKind;
CString sItem;
CString sDrawing;
while(!pTable->IsEOF())
{
GET_FIELD(pTable, _T("Kind"), sKind);
GET_FIELD(pTable, _T("Item"), sItem);
GET_FIELD(pTable, _T("Drawing"), sDrawing);
if (pTable->IsDeleted())
{
pTable->MoveNext();
continue;
}
pTable->MoveNext();
}
pTable->Close();
//初始化块
CString sBlockName0;
sBlockName0.Format(_T("车(%s)"),sDrawing);
XString sBlockName(sBlockName0);
CString szFileName = (const TCHAR *)(XPathParser(sBlockName).m_sFileName);
CString sLibFile = g_sDwbPath;
CString csPath = sLibFile + szFileName;
AcApDocument *pDoc = acDocManager->curDocument();
acDocManager->lockDocument(pDoc);
int nRet = LoadDwbBlock(csPath,sBlockName);
sName<<sBlockName;
acDocManager->unlockDocument(pDoc);
return sName;
}
//JIG
class TDbParkingSpaceJig:public AcEdJig
{
public:
TDbParkingSpaceJig(TDbParkingSpace *pEnt,CParkingSpaceDlg *pDlg,TCHAR *pszPormat, const TCHAR* szKeyword, CString &strSerialNum, BOOL bIsFirst);
~TDbParkingSpaceJig();
virtual AcEdJig::DragStatus sampler();
virtual Adesk::Boolean update();
virtual AcDbEntity* entity() const;
AcEdJig::DragStatus doIt();
private:
TDbParkingSpace *m_pParkingSpace;
CParkingSpaceDlg *m_pDlg;
AcGePoint3d m_ptCur; //鼠标当前坐标
AcGePoint3d m_ptLast;
TCHAR *m_pszPormat; //提示语
XPoint m_ptStart; //
CString m_strSerialNum;
BOOL m_bIsFirst;
XString m_sKeyword;
};
TDbParkingSpaceJig::TDbParkingSpaceJig(TDbParkingSpace *pEnt,CParkingSpaceDlg *pDlg,TCHAR *pszPormat, const TCHAR* szKeyword, CString &strSerialNum, BOOL bIsFirst):
m_pParkingSpace(pEnt),
m_pDlg(pDlg),
m_ptCur(0,0,0),
m_ptLast(0,0,0),
m_pszPormat(pszPormat),
m_ptStart(pEnt->GetStartPt().AsAcGePoint3d()),
m_strSerialNum(strSerialNum),
m_bIsFirst(bIsFirst),
m_sKeyword(szKeyword)
{
}
TDbParkingSpaceJig::~TDbParkingSpaceJig()
{
}
AcEdJig::DragStatus TDbParkingSpaceJig::doIt()
{
AcEdJig::DragStatus status =AcEdJig::kNull;
setDispPrompt(m_pszPormat);
if(m_sKeyword) {
INITGET_BEG(-1, m_sKeyword);
try {
status = drag();
} catch(...) {
status=AcEdJig::kCancel;
}
INITGET_END();
} else {
try {
status = drag();
} catch(...) {
status =AcEdJig::kCancel;
}
}
return status;
}
AcEdJig::DragStatus TDbParkingSpaceJig::sampler()
{
setUserInputControls((UserInputControls)(AcEdJig::kAccept3dCoordinates|
AcEdJig::kNullResponseAccepted));
AcEdJig::DragStatus status =AcEdJig::kCancel;
if (m_sKeyword) setKeywordList(m_sKeyword);
status = acquirePoint(m_ptCur,m_ptStart);//提供起点是为解决不支持正交问题
if (status == AcEdJig::kNormal)
{
if (m_ptCur.isEqualTo(m_ptLast))
{
return AcEdJig::kNoChange;
}
}
m_ptLast = Ucs2Wcs(m_ptLast);
m_ptLast = m_ptCur;
return status;
}
Adesk::Boolean TDbParkingSpaceJig::update()
{
m_pDlg->UpdateEx();
AcGeVector3d baseVector(AcGeVector3d(0,0,0));
int iNum = 0;
double dAngl = 0;;
int angle = m_pDlg->GetAngle();
double iWidth = m_pDlg->GetWidth();
double iHeight = m_pDlg->GetHeight();
int iStyle = m_pDlg->GetStyle();
CString strTextStyle = m_pDlg->GetTextStyle();
double dTextHeight = m_pDlg->GetTextHeigh();
double dOffset;
switch (m_pDlg->GetParkingLoc())
{
case CParkingSpaceDlg::eOutSide:
dOffset = /*iHeight + */0.8 * m_pDlg->GetTextHeigh() * DocGetPScale();
break;
case CParkingSpaceDlg::eInSide:
dOffset = /*iHeight*/ - 0.8 * m_pDlg->GetTextHeigh() * DocGetPScale();
break;
case CParkingSpaceDlg::eMid:
dOffset = -0.5 * iHeight;
break;
}
int iRow = m_pDlg->GetRowFlag();
AcDbLine line(m_pParkingSpace->GetStartPt(),m_ptCur);
GetParkInfo(baseVector,iNum,dAngl,&line,angle,iWidth,iHeight,1,0);
CString ss(m_pDlg->GetTextStyle());
m_pParkingSpace->Update(m_ptCur,baseVector,iWidth,iHeight, dTextHeight, angle, m_strSerialNum, ss, m_pDlg->GetCarNum(), m_bIsFirst, dOffset, iRow,iStyle,iNum);
return Adesk::kTrue;
}
AcDbEntity *TDbParkingSpaceJig::entity() const
{
return (m_pParkingSpace);
}
//////////////////////////////////////////////////////////////
//
// 命令函数:车位布置
//
//////////////////////////////////////////////////////////////
//拆分编号得到前后缀字母及数字
int CutStrToPreAndnum(CString &strSerialNum, CString &strPrefix, CString &strPostFix, int* nNum)
{
CString strNum, strTemp = strSerialNum;
int nNumPos = 0, nCharPos = 0, nNotZero = 0;
for (int i =strTemp.GetLength() - 1; i >= 0; --i)
{
if ((strTemp.GetAt(i) >= '0') && (strTemp.GetAt(i) <= '9'))
{
nNumPos = i;
break;
}
}
strPostFix = strTemp.Right(strTemp.GetLength() - nNumPos - 1);
strTemp = strTemp.Left(nNumPos + 1);
for (int i =strTemp.GetLength() - 1; i >= 0; --i)
{
if ((strTemp.GetAt(i) < '0') || (strTemp.GetAt(i) > '9'))
{
nCharPos = i;
break;
}
}
if (nCharPos)
strNum = strTemp.Right(strTemp.GetLength() - nCharPos - 1);
else
strNum = strTemp.Right(strTemp.GetLength() - nCharPos);
nNotZero = strNum.GetLength();
for (int i =0; i < strNum.GetLength(); ++i)
{
if ((strNum.GetAt(i) >= '1') && (strNum.GetAt(i) <= '9'))
{
nNotZero = i;
break;
}
}
if (nCharPos)
strPrefix = strTemp.Left(nCharPos + nNotZero + 1);
else
strPrefix = strTemp.Left(nNotZero);
strNum = strNum.Right(strNum.GetLength() - nNotZero);
if (strNum.IsEmpty())
{
*nNum = 0;
}
else
{
*nNum = _ttof(strNum);
}
return strNum.GetLength();
}
CString GetMaxSerialNum()
{
CString strMaxNum = _T("");
AcDbObjectIdArray allEntIds = GetAllEntityId(LAY_PKNG_SING);
if (allEntIds.length() > 0)
{
for(int i=0; i < allEntIds.length(); ++i)
{
OPENOBJ_BEGIN(allEntIds[i], AcDb::kForRead, TDbText, pText);
CString strlay = pText->layer();
CString strText = pText->GetText();
if (strText.Find(_T("辆")) == -1)
{
if (strlay.CompareNoCase(LAY_PKNG_SING) == 0)
{
CString strTemp = pText->GetText();
WCHAR *wch = (WCHAR*)strTemp.GetBuffer(strTemp.GetLength());
strTemp.ReleaseBuffer();
WCHAR *wchMax = (WCHAR*)strMaxNum.GetBuffer(strMaxNum.GetLength());
strMaxNum.ReleaseBuffer();
if (is_digit(wch) == 0)
{
if (is_digit(wchMax) == 0)
{
if (_ttof(strTemp) > _ttof(strMaxNum))
{
strMaxNum = strTemp;
}
}
else
{
strMaxNum = strTemp;
}
}
else
{
if (strMaxNum.GetLength() > 0)
{
if (is_digit(wchMax) == -1)
{
if (strTemp > strMaxNum)
{
strMaxNum = strTemp;
}
}
}
else
{
strMaxNum = strTemp;
}
}
}
}
OPENOBJ_END();
}
}
return strMaxNum;
}
//更正双排布置车位时编号的次序
int ParkingPolyDouble(XPoly2D &polyParking, CParkingSpaceDlg *pDlg, XString &sName, AcDbObjectId &idLayer, BOOL bIsLeft)
{
AcDbPolyline polyEntBase;
PolyConvert(polyParking, polyEntBase);
BOOL bIsDrawText = pDlg->GetCarNum();
int nTotalParkingSpaceNum = 0;
/*if (!bIsLeft)
{
XPoly2D poly1;
for (int i = polyParking.TotalSegments() - 1; i>= 0; --i)
{
TGGeCurveSegment seg;
XPoint ptStart;
polyParking.Nth(i, seg);
if (abs(polyParking.GetBulge(i)) > 1.0E-6)
{
if (polyParking.GetBulge(i) > 0)
{
ptStart = seg.GetEndPoint();
double dAngl = seg.GetBulge();
seg.SetEndPoint(seg.GetStartPoint());
seg.SetStartPoint(ptStart);
seg.SetBulge(-dAngl);
}
}
else
{
ptStart = seg.GetEndPoint();
seg.SetEndPoint(seg.GetStartPoint());
seg.SetStartPoint(ptStart);
}
if (i == 0)
poly1.AppendSegment(seg, 0, 1);
else
poly1.AppendSegment(seg, 0, 0);
}
polyParking = poly1;
PolyConvert(polyParking, polyEntBase);
}*/
static CString strSerialNum, strPrefix, strPostfix, strNum, strTemp;
static BOOL bIsFirst = FALSE;
static int nSerialNum, nNumLength = 0;
AcGeVector3d baseVector(AcGeVector3d(0,0,0));
int iNum = 0;
double dAngl = 0;;
int angle = pDlg->GetAngle();
double iWidth = pDlg->GetWidth();
double iHeight = pDlg->GetHeight();
int style = pDlg->GetStyle();
if (bIsLeft)
{
strSerialNum = GetMaxSerialNum();
strTemp = pDlg->GetStartNum();
if (strSerialNum.IsEmpty())
{
strSerialNum = strTemp;
bIsFirst = TRUE;
if (strTemp != strSerialNum)
{
strSerialNum = strTemp;
}
}
else
{
bIsFirst = FALSE;
if (strTemp != strSerialNum)
{
bIsFirst = TRUE;//add tyj 20160830:修正当界面有车位编号时,改变编号形式,沿多段线布置双排车位,起始编号与设置编号不同的问题
strSerialNum = strTemp;
}
}
nNumLength = CutStrToPreAndnum(strSerialNum, strPrefix, strPostfix, &nSerialNum);
}
double dOffset = 0;
switch (pDlg->GetParkingLoc())
{
case CParkingSpaceDlg::eOutSide:
dOffset = /*iHeight + */0.8 * pDlg->GetTextHeigh() * DocGetPScale();
break;
case CParkingSpaceDlg::eInSide:
dOffset = /*iHeight*/ - 0.8 * pDlg->GetTextHeigh() * DocGetPScale();
break;
case CParkingSpaceDlg::eMid:
dOffset = - 0.5 * iHeight;
break;
}
int iSegNum = polyEntBase.numVerts();
if (bIsLeft)
{
for (int i =0;i<iSegNum;i++)
{
AcDbPolyline::SegType type = polyEntBase.segType(i);
if (type == AcDbPolyline::kLine)
{
AcGeLineSeg3d segline;
polyEntBase.getLineSegAt(i,segline);
AcGePoint3d ptStart;
ptStart = segline.startPoint();
GetParkInfo(baseVector,iNum,dAngl,&polyEntBase,angle,iWidth,iHeight,1,i);
nTotalParkingSpaceNum += iNum;
if (!bIsLeft)
{
XPoint ptEnd;
ptEnd = segline.endPoint();
XLine lineBase((XPoint)ptStart, ptEnd);
AcGeVector3d vec = ptEnd - ptStart;
ptStart = ptStart + (lineBase.GetLength() - iNum * iWidth / sin(angle * PI / 180)) * vec / vec.length();
}
for(int i=0;i<iNum;i++)
{
if (bIsLeft)
{
ATSParking *pParking = new ATSParking(sName);
pParking->SetTextOffset(dOffset);
TADSGePoint3d tt((ptStart+i*baseVector));
pParking->Fill(tt,baseVector,angle,iWidth,iHeight,1,style,0);
XPoint pt = pParking->GetBasePt();
if (bIsDrawText)
{
CString ss = GetTextForSingle(strPrefix, strPostfix, bIsFirst, nSerialNum, nNumLength);
AddSerialNum(*pParking, ss, baseVector, pDlg, 1);
bIsFirst = FALSE;
}
AcDbObjectId id = FormBlock(pParking,pt,idLayer);
}
}
}
else if (type == AcDbPolyline::kArc)
{
double Angle = polyParking.GetBulge(i);
AcGeCircArc3d geArc;
polyEntBase.getArcSegAt(i,geArc);
double dBugle = 0;
polyEntBase.getBulgeAt(i,dBugle);
AcGePoint3d ptStart;
if (bIsLeft)
{
ptStart = geArc.startPoint();
//左侧
if (Angle < 0)
GetParkInfo(baseVector,iNum,dAngl,&polyEntBase,angle,iWidth,iHeight,-1,i);
else
GetParkInfo(baseVector,iNum,dAngl,&polyEntBase,angle,iWidth,iHeight,1,i);
nTotalParkingSpaceNum += iNum;
for (int j=0;j<iNum;j++)
{
ATSParking *pParking = new ATSParking(sName);
pParking->SetTextOffset(dOffset);
if (Angle < 0)
pParking->Fill(XPoint(geArc.center()),TADSGePoint3d(ptStart),baseVector,iWidth,iHeight,(-dBugle/fabs(dBugle)),style);
else
pParking->Fill(XPoint(geArc.center()),TADSGePoint3d(ptStart),baseVector,iWidth,iHeight,(dBugle/fabs(dBugle)),style);
ptStart+=baseVector;
if (bIsDrawText)
{
XPoint xp(geArc.center());
AddSerialNumForArc(xp, *pParking, GetTextForSingle(strPrefix, strPostfix, bIsFirst, nSerialNum, nNumLength), pDlg);
bIsFirst = FALSE;
}
baseVector.rotateBy((dBugle/fabs(dBugle))*dAngl,AcGeVector3d(0,0,1));
XPoint pt = pParking->GetBasePt();
AcDbObjectId id = FormBlock(pParking,pt,idLayer);
}
}
}
}
}
else
{
for (int i =iSegNum - 1;i >= 0; --i)
{
AcDbPolyline::SegType type = polyEntBase.segType(i);
if (type == AcDbPolyline::kLine)
{
AcGeLineSeg3d segline;
polyEntBase.getLineSegAt(i,segline);
AcGePoint3d ptStart;
ptStart = segline.startPoint();
GetParkInfo(baseVector,iNum,dAngl,&polyEntBase,angle,iWidth,iHeight,1,i);
nTotalParkingSpaceNum += iNum;
nSerialNum = nSerialNum + iNum;
int nEndNum = nSerialNum;
for(int i=0;i<iNum;i++)
{
ATSParking *pParking1 = new ATSParking(sName);
pParking1->SetTextOffset(dOffset);
pParking1->Fill(TADSGePoint3d((ptStart+i*baseVector)),baseVector,angle,iWidth,iHeight,1,style,1);
XPoint pt1 = pParking1->GetBasePt();
if (bIsDrawText)
{
AddSerialNum(*pParking1, GetTextForDouble(strPrefix, strPostfix, nEndNum, nNumLength), baseVector, pDlg, 1);
}
AcDbObjectId id1 = FormBlock(pParking1,pt1,idLayer);
}
}
else if (type == AcDbPolyline::kArc)
{
//右侧
XPoint ptStart;
double Angle = polyParking.GetBulge(i);
AcGeCircArc3d geArc;
polyEntBase.getArcSegAt(i,geArc);
bIsFirst = TRUE;
ptStart = geArc.startPoint();
if (Angle < 0)
GetParkInfo(baseVector,iNum,dAngl,&polyEntBase,angle,iWidth,iHeight,1,i);
else
GetParkInfo(baseVector,iNum,dAngl,&polyEntBase,angle,iWidth,iHeight,-1,i);
//GetParkInfo(baseVector,iNum,dAngl,&polyEntBase,angle,iWidth,iHeight,-1,i);
nTotalParkingSpaceNum += iNum;
if (Angle < 0)
{
dAngl = -dAngl;
}
nSerialNum = nSerialNum + iNum;
int nEndNum = nSerialNum;
for (int j=0;j<iNum;j++)
{
ATSParking *pParking = new ATSParking(sName);
pParking->SetTextOffset(dOffset);
//pParking->Fill(XPoint(geArc.center()),TADSGePoint3d(ptStart),baseVector,iWidth,iHeight,-1,style);
if (Angle < 0)
pParking->Fill(XPoint(geArc.center()),TADSGePoint3d(ptStart),baseVector,iWidth,iHeight,(Angle/fabs(Angle)),style);
else
pParking->Fill(XPoint(geArc.center()),TADSGePoint3d(ptStart),baseVector,iWidth,iHeight,(-Angle/fabs(Angle)),style);
ptStart+=baseVector;
if (bIsDrawText)
{
CString strTemp = strPrefix;
XPoint xp(geArc.center());
AddSerialNumForArc(xp, *pParking, GetTextForDouble(strTemp, strPostfix, nEndNum, nNumLength), pDlg);
bIsFirst = FALSE;
}
baseVector.rotateBy(dAngl,AcGeVector3d(0,0,1));
XPoint pt = pParking->GetBasePt();
AcDbObjectId id = FormBlock(pParking,pt,idLayer);
}
}
}
}
return nTotalParkingSpaceNum;
}
CString GetSerialNumForNext()
{
CString strSerialNum, strPrefix, strPostfix, strNum;
int nNumLength, nNum;
strSerialNum = GetMaxSerialNum();
if (strSerialNum.GetLength() > 0)
{
nNumLength = CutStrToPreAndnum(strSerialNum, strPrefix, strPostfix, &nNum);
strSerialNum = GetTextForSingle(strPrefix, strPostfix, FALSE, nNum, nNumLength);
}
return strSerialNum;
}
void ParkingSpaceCmd()
{
//资源管理
CAcModuleResourceOverride myResources;
AcDbObjectId idTextStyle = InitTextStyle(TS_PKNGTSRP);
//初始化图层和车块
AcDbObjectId idLayer = InitLayer(LAY_PKNG_TSRP);
XString sName = InitCarBlock();
if (!sName)
{
AfxMessageBox(_T("初始化车块失败!"));
return;
}
//非模态对话框
CParkingSpaceDlg* pDlg = new CParkingSpaceDlg(acedGetAcadFrame());
pDlg->Create(IDD_DLG_PARKINGSPACE);
pDlg->ShowWindow(SW_SHOW);
//命令退出标识
bool bExit = false;
int iRet = RTERROR;
AcGePoint3d ptStart;
AcGePoint3d ptEnd;
AcGePoint3d ptMarkerPos;
BOOL bIsFirst = FALSE;
CString strSerialNum, strTemp;
BOOL bIsSelectConsult = FALSE;
XPoint ptRef;
while (true)
{
if (bIsSelectConsult)
{
INITGET_BEG(0, _T("R A"));
iRet = ads_getpoint(ptRef, _T("\n请点取车位起点或[参考点(R)/沿曲线布置(A)]<退出>:"), asDblArray(ptStart));
INITGET_END();
bIsSelectConsult = FALSE;
}
else
{
INITGET_BEG(0, _T("R A"));
iRet = ads_getpoint(NULL, _T("\n请点取车位起点或[参考点(R)/沿曲线布置(A)]<退出>:"), asDblArray(ptStart));
INITGET_END();
}
if (iRet == RTNORM)//已选择起点
{
TDbParkingSpace *pEnt = new TDbParkingSpace;
ptStart = Ucs2Wcs(ptStart);
pEnt->SetStartPt(TADSGePoint3d(ptStart));
pEnt->SetBlockName(sName);
strSerialNum = pDlg->GetStartNum();
const TCHAR *kword=_T("Q");
TDbParkingSpaceJig jig(pEnt,pDlg,(LPTSTR)_T("\n请点取车位终点或[切换车位布置方向(Q)]<退出>:"), kword, strSerialNum, TRUE);
while (true)
{
int ista = jig.doIt();
if (ista == AcEdJig::kKW1)
{
pEnt->QMode();
continue;
}
else if(ista == AcEdJig::kNormal)
{
int iNum = pEnt->Num();
//炸开
AcDbVoidPtrArray entitySet;
if(pEnt->explode(entitySet) == Acad::eOk)
{
for (int i=0;i<entitySet.length();i++)
{
AcDbEntity *pEntity =(AcDbEntity*)entitySet[i];
if (pEntity->isKindOf(TDbText::desc()))
{
CString strlay = pEntity->layer();
if (strlay.CompareNoCase(LAY_PKNG_SING))
{
pEntity->erase();
continue;
}
else
{
pEntity->setLayer(InitLayer(LAY_PKNG_SING));
AcDbObjectId id = AddToCurrentSpace(pEntity, Adesk::kTrue);
continue;
}
}
ATSParking *pParking = (ATSParking*)entitySet[i];
XPoint pt = pParking->GetBasePt();
AcDbObjectId id = FormBlock(pParking,pt,idLayer);
}
}
//是否选了标注车位
pDlg->UpdateEx();
if (pDlg->IsCheck())
{
iRet = acedGetPoint(NULL,_T("\n请点取标注位置<退出>:"),asDblArray(ptMarkerPos));
if (iRet == RTNORM)//标注车位量数
{
ptMarkerPos = Ucs2Wcs(ptMarkerPos);
if(pDlg->GetRowFlag() == 1)
{
iNum*=2;
}
TDbText *pText = new TDbText;
XString sValue(256);
sValue<<XString(_T("%d辆"),iNum);
pText->SetText(sValue);
pText->SetHeight(pDlg->GetTextHeigh());
pText->SetRotation(Ucs2Wcs(0));
pText->SetLocation(ptMarkerPos);
AcDbObjectId idTextStyle = GetTextStyleId(pDlg->GetTextStyle());
if (idTextStyle.isValid())
pText->SetStyleId(idTextStyle);
else
pText->SetStyleId(acdbCurDwg()->textstyle());
pText->setLayer(InitLayer(LAY_PKNG_SING));
pText->SetAlignment(XExplodeDraw::kBottomCenter);
AddToCurrentSpace(pText, Adesk::kTrue);
}
}
CString strSerial = GetSerialNumForNext();
if (!strSerial.IsEmpty())
{
pDlg->UpdataSerialNum(strSerial);
}
break;
}
else
{
bExit = true;
break;
}
}//end if true(JIG)
if (bExit)
{
if (pEnt)
{
delete pEnt;
}
break;//退出命令
}
}
else if (iRet == RTKWORD)
{
TCHAR szKey[132];
if (acedGetInput(szKey) != RTNORM)
{
continue;
}
if (szKey[0]==_T('R')) // 批量标注,add by lgy 20120330,9.0新增功能
{
bIsSelectConsult = TRUE;
while (1)
{
int nRetCode = ads_getpoint(NULL, _T("\n参考点<退出>:"), ptRef);
if (nRetCode == RTNORM)
{
ptRef = Ucs2Wcs(ptRef);
break;
}
else if(nRetCode == RTCAN || nRetCode == RTNONE)
{
bIsSelectConsult = FALSE;
break;
}
}
}
else
{
while (true)
{
Entity entBase;
RBList mask(RTDXF0, _T("LINE,LWPOLYLINE,ARC"), NULL);
int istats = entBase.FilterSelect1(0,_T("\n请选择曲线(直线、圆弧、多段线)<返回>:"), mask, NULL);
if (istats == RTNORM)
{
//获取对话框最新数据
pDlg->UpdateEx();
//高亮
entBase.Redraw(3);
iRet = RTNORM;
AcGePoint3d ptSize;
CString strSerialNum, strPrefix, strPostfix, strNum;
int nNumLength, nNum;
if(pDlg->GetRowFlag() == 0)
{
iRet = acedGetPoint(NULL,_T("\n请点取车位所在一侧<返回>:"),asDblArray(ptSize));
ptSize = Ucs2Wcs(ptSize);
}
int iNum = 0;
if (iRet == RTNORM)
{
AcGeVector3d baseVector(AcGeVector3d(0,0,0));
iNum = 0;
double dAngl = 0;;
int angle = pDlg->GetAngle();
double iWidth = pDlg->GetWidth();
double iHeight = pDlg->GetHeight();
int style = pDlg->GetStyle();
strSerialNum = pDlg->GetStartNum();
bIsFirst = TRUE;
BOOL bIsDrawText = pDlg->GetCarNum();
nNumLength = CutStrToPreAndnum(strSerialNum, strPrefix, strPostfix, &nNum);
double dOffset = 0;
switch (pDlg->GetParkingLoc())
{
case CParkingSpaceDlg::eOutSide:
dOffset = /*iHeight + */0.8 * pDlg->GetTextHeigh() * DocGetPScale();
break;
case CParkingSpaceDlg::eInSide:
dOffset = /*iHeight*/ - 0.8 * pDlg->GetTextHeigh() * DocGetPScale();
break;
case CParkingSpaceDlg::eMid:
dOffset = -0.5 * iHeight;
break;
}
//布置车位
//直线段
if (entBase.Is(_T("LINE")))
{
OPENOBJ_BEGIN(entBase,AcDb::kForRead,AcDbLine,pEntBase);
if (pEntBase)
{
//直线段单排
if(pDlg->GetRowFlag() == 0)
{
AcGePoint3d ptStart, ptend;
ptStart = pEntBase->startPoint();
ptend = pEntBase->endPoint();
XLine line((XPoint)ptStart, (XPoint)ptend);
GetParkInfo(baseVector,iNum,dAngl,pEntBase,angle,iWidth,iHeight,1,0);
//哪一侧
int iSize = 1;// -1 --右侧, 1--左侧
AcGeVector3d vec0 = baseVector;
AcGeVector3d vec1 = ptSize - pEntBase->startPoint();
double dangle = vec0.angleTo(vec1);
vec0.rotateBy(dangle,AcGeVector3d(0,0,1));
if (line.OnWhichSide(ptSize))
{
iSize = -1;
}
for(int i=0;i<iNum;i++)
{
ATSParking *pParking = new ATSParking(sName);
pParking->SetTextOffset(dOffset);
pParking->Fill(TADSGePoint3d((ptStart+i*baseVector)),baseVector,angle,iWidth,iHeight,iSize,style,0);
XPoint pt = pParking->GetBasePt();
if (bIsDrawText)
{
AddSerialNum(*pParking, GetTextForSingle(strPrefix, strPostfix, bIsFirst, nNum, nNumLength), baseVector, pDlg, iSize);
bIsFirst = FALSE;
}
AcDbObjectId id = FormBlock(pParking,pt,idLayer);
}
}
//直线段双排
else if (pDlg->GetRowFlag() == 1)
{
int nTotalParkingSpaceNum(0);
AcGePoint3d ptStart;
ptStart = pEntBase->startPoint();
GetParkInfo(baseVector,iNum,dAngl,pEntBase,angle,iWidth,iHeight,1,0);
nTotalParkingSpaceNum = iNum * 2;
int nTasksNum(0);
if (bIsFirst)
{
nTasksNum = nNum + 2 * iNum - 1;
}
else
{
nTasksNum = nNum + 2 * iNum;
}
for(int i=0;i<iNum;i++)
{
ATSParking *pParking = new ATSParking(sName);
pParking->SetTextOffset(dOffset);
pParking->Fill(TADSGePoint3d((ptStart+i*baseVector)),baseVector,angle,iWidth,iHeight,1,style,0);
XPoint pt = pParking->GetBasePt();
if (bIsDrawText)
{
AddSerialNum(*pParking, GetTextForSingle(strPrefix, strPostfix, bIsFirst, nNum, nNumLength), baseVector, pDlg);
bIsFirst = FALSE;
}
AcDbObjectId id = FormBlock(pParking,pt,idLayer);
ATSParking *pParking1 = new ATSParking(sName);
pParking1->SetTextOffset(dOffset);
pParking1->Fill(TADSGePoint3d((ptStart+i*baseVector)),baseVector,angle,iWidth,iHeight,1,style,1);
XPoint pt1 = pParking1->GetBasePt();
if (bIsDrawText)
{
CString strTemp = strPrefix;
AddSerialNum(*pParking1, GetTextForDouble(strTemp, strPostfix, nTasksNum, nNumLength), baseVector, pDlg);
}
AcDbObjectId id1 = FormBlock(pParking1,pt1,idLayer);
}
iNum = nTotalParkingSpaceNum;
}
}
OPENOBJ_END();
//修改 tyj 20160830:防止当不标注车位编号时,起始编号被置空
CString strSerial = GetSerialNumForNext();
if (!strSerial.IsEmpty())
{
pDlg->UpdataSerialNum(strSerial);
}
//pDlg->UpdataSerialNum(GetSerialNumForNext());
}
//弧
else if (entBase.Is(_T("ARC")))
{
XPoly2D poly(entBase);
OPENOBJ_BEGIN(entBase,AcDb::kForRead,AcDbArc,pEntBase);
if (pEntBase)
{
//弧单排
if(pDlg->GetRowFlag() == 0)
{
int iSize = -1;
if (ptSize.distanceTo(pEntBase->center()) < pEntBase->radius())
{
iSize = 1;
}
AcGePoint3d ptStart;
pEntBase->getStartPoint(ptStart);
GetParkInfo(baseVector,iNum,dAngl,pEntBase,angle,iWidth,iHeight,iSize,0);
for (int i=0;i<iNum;i++)
{
ATSParking *pParking = new ATSParking(sName);
pParking->SetTextOffset(dOffset);
pParking->Fill(XPoint(pEntBase->center()),TADSGePoint3d(ptStart),baseVector,iWidth,iHeight,iSize,style);
ptStart+=baseVector;
if (bIsDrawText)
{
XPoint xp(pEntBase->center());
AddSerialNumForArc(xp, *pParking, GetTextForSingle(strPrefix, strPostfix, bIsFirst, nNum, nNumLength), pDlg);
bIsFirst = FALSE;
}
baseVector.rotateBy(dAngl,AcGeVector3d(0,0,1));
XPoint pt = pParking->GetBasePt();
AcDbObjectId id = FormBlock(pParking,pt,idLayer);
}
}
//弧双排
else if (pDlg->GetRowFlag() == 1)
{
int nTotalParkingSpaceNum(0);
AcGePoint3d ptStart;
int nTasksNum(0);
pEntBase->getStartPoint(ptStart);
GetParkInfo(baseVector,iNum,dAngl,pEntBase,angle,iWidth,iHeight,1,0);
nTotalParkingSpaceNum += iNum;
nTasksNum = iNum + nNum;
for (int i=0;i<iNum;i++)
{
ATSParking *pParking = new ATSParking(sName);
pParking->SetTextOffset(dOffset);
pParking->Fill(XPoint(pEntBase->center()),TADSGePoint3d(ptStart),baseVector,iWidth,iHeight,1,style);
ptStart+=baseVector;
if (bIsDrawText)
{
XPoint xp(pEntBase->center());
AddSerialNumForArc(xp, *pParking, GetTextForSingle(strPrefix, strPostfix, bIsFirst, nNum, nNumLength), pDlg);
bIsFirst = FALSE;
}
baseVector.rotateBy(dAngl,AcGeVector3d(0,0,1));
XPoint pt = pParking->GetBasePt();
AcDbObjectId id = FormBlock(pParking,pt,idLayer);
}
bIsFirst = TRUE;
pEntBase->getStartPoint(ptStart);
GetParkInfo(baseVector,iNum,dAngl,pEntBase,angle,iWidth,iHeight,-1,0);
nTotalParkingSpaceNum += iNum;
nTasksNum = nTasksNum + iNum - 1;
for (int j=0;j<iNum;j++)
{
ATSParking *pParking = new ATSParking(sName);
pParking->SetTextOffset(dOffset);
pParking->Fill(XPoint(pEntBase->center()),TADSGePoint3d(ptStart),baseVector,iWidth,iHeight,-1,style);
ptStart+=baseVector;
if (bIsDrawText)
{
CString strTemp = strPrefix;
XPoint xp(pEntBase->center());
AddSerialNumForArc(xp, *pParking, GetTextForDouble(strTemp, strPostfix, nTasksNum, nNumLength), pDlg);
bIsFirst = FALSE;
}
baseVector.rotateBy(dAngl,AcGeVector3d(0,0,1));
XPoint pt = pParking->GetBasePt();
AcDbObjectId id = FormBlock(pParking,pt,idLayer);
}
iNum = nTotalParkingSpaceNum;
}
}
OPENOBJ_END();
CString strSerial = GetSerialNumForNext();
if (!strSerial.IsEmpty())
{
pDlg->UpdataSerialNum(strSerial);
}
}
//多线段
else if (entBase.Is(_T("LWPOLYLINE")))
{
OPENOBJ_BEGIN(entBase,AcDb::kForRead,AcDbPolyline,pEntBase);
if (pEntBase)
{
int iSegNum = pEntBase->numVerts();
//多线段单排
if(pDlg->GetRowFlag() == 0)
{
//多段断线的那一侧
int iSize = -1;// -1 -- 右侧, 1 -- 左侧
strTemp = pDlg->GetStartNum();
bIsFirst = TRUE;
int nTotalParpingSpaceNum = 0;
nNumLength = CutStrToPreAndnum(strSerialNum, strPrefix, strPostfix, &nNum);
for (int i =0;i<iSegNum;i++)
{
AcDbPolyline::SegType type = pEntBase->segType(i);
if (type == AcDbPolyline::kLine)
{
AcGeLineSeg3d segline;
pEntBase->getLineSegAt(i,segline);
AcGePoint3d ptStart;
ptStart = segline.startPoint();
GetParkInfo(baseVector,iNum,dAngl,pEntBase,angle,iWidth,iHeight,1,i);
nTotalParpingSpaceNum += iNum;
if (i == 0)
{
iSize = PointSizeToPolyLine(pEntBase, ptSize);
}
for(int i=0;i<iNum;i++)
{
ATSParking *pParking = new ATSParking(sName);
pParking->SetTextOffset(dOffset);
pParking->Fill(TADSGePoint3d((ptStart+i*baseVector)),baseVector,angle,iWidth,iHeight,iSize,style,0);
XPoint pt = pParking->GetBasePt();
if (bIsDrawText)
{
AddSerialNum(*pParking, GetTextForSingle(strPrefix, strPostfix, bIsFirst, nNum, nNumLength), baseVector, pDlg, iSize);
bIsFirst = FALSE;
}
AcDbObjectId id = FormBlock(pParking,pt,idLayer);
}
}
else if (type == AcDbPolyline::kArc)
{
XPoly2D polyParking;
PolyConvert(*pEntBase, polyParking);
AcGeCircArc3d geArc;
pEntBase->getArcSegAt(i,geArc);
if (i ==0)
{
iSize = PointSizeToPolyLine(pEntBase, ptSize);
}
AcGePoint3d ptStart;
ptStart = geArc.startPoint();
double dBugle = 0;
pEntBase->getBulgeAt(i,dBugle);
int iTest = GetSizeOfArc(geArc, iSize,dBugle, i, polyParking);
GetParkInfo(baseVector,iNum,dAngl,pEntBase,angle,iWidth,iHeight, iTest,i);
int nArcSize = 1;
if (iTest == 1 && dBugle < 0)
nArcSize = -1;
else if (iTest == 1 && dBugle > 0)
nArcSize = 1;
else if (iTest == -1 && dBugle < 0)
nArcSize = 1;
if (iTest == -1 && dBugle > 0)
nArcSize = -1;
for (int i=0;i<iNum;i++)
{
ATSParking *pParking = new ATSParking(sName);
pParking->SetTextOffset(dOffset);
pParking->Fill(XPoint(geArc.center()),TADSGePoint3d(ptStart),baseVector,iWidth,iHeight,nArcSize,style);
ptStart+=baseVector;
baseVector.rotateBy((dBugle/fabs(dBugle))*dAngl,AcGeVector3d(0,0,1));
XPoint pt = pParking->GetBasePt();
if (bIsDrawText)
{
XPoint xp(geArc.center());
AddSerialNumForArc(xp, *pParking, GetTextForSingle(strPrefix, strPostfix, bIsFirst, nNum, nNumLength), pDlg);
bIsFirst = FALSE;
}
AcDbObjectId id = FormBlock(pParking,pt,idLayer);
}
nTotalParpingSpaceNum += iNum;
}
}
CString strSerial = GetSerialNumForNext();
if (!strSerial.IsEmpty())
{
pDlg->UpdataSerialNum(strSerial);
}
iNum = nTotalParpingSpaceNum;//统计停车位个数
}
//多线段双排
else if (pDlg->GetRowFlag() == 1)
{
XPoly2D polyParking;
PolyConvert(*pEntBase, polyParking);
iNum = ParkingPolyDouble(polyParking, pDlg, sName, idLayer, TRUE);
iNum += ParkingPolyDouble(polyParking, pDlg, sName, idLayer, FALSE);
CString strSerial = GetSerialNumForNext();
if (!strSerial.IsEmpty())
{
pDlg->UpdataSerialNum(strSerial);
}
}
}
OPENOBJ_END();
}
}
//标注车位
//是否选了标注车位
pDlg->UpdateEx();
if (pDlg->IsCheck())
{
iRet = acedGetPoint(NULL,_T("\n请点取标注位置<退出>:"),asDblArray(ptMarkerPos));
if (iRet == RTNORM)//标注车位量数
{
ptMarkerPos = Ucs2Wcs(ptMarkerPos);
/*if(pDlg->GetRowFlag() == 1)
{
iNum*=2;
}*/
TDbText *pText = new TDbText;
XString sValue(256);
sValue<<XString(_T("%d辆"),iNum);
pText->SetText(sValue);
pText->SetHeight(pDlg->GetTextHeigh());
pText->SetRotation(Ucs2Wcs(0));
pText->SetLocation(ptMarkerPos);
AcDbObjectId idTextStyle = GetTextStyleId(pDlg->GetTextStyle());
if (idTextStyle.isValid())
pText->SetStyleId(idTextStyle);
else
pText->SetStyleId(acdbCurDwg()->textstyle());
pText->setLayer(InitLayer(LAY_PKNG_SING));
pText->SetAlignment(XExplodeDraw::kBottomCenter);
AddToCurrentSpace(pText, Adesk::kTrue);
}
}
//取消高亮
entBase.Redraw(4);
}
else if(istats == RTCAN)
{
bExit = TRUE;
break;//退出命令
}
else if (istats == RTNONE)
{
break;//返回拖动绘制
}
}
}
if (bExit)
{
break;//退出命令
}
}
else if(iRet = RTCAN)
{
break;
}
}
if (pDlg)
{
pDlg->DestroyWindow();
delete pDlg;
}
}