355 lines
8.7 KiB
C++
355 lines
8.7 KiB
C++
#include "stdafx.h"
|
|
#include "TDbParkingSpace.h"
|
|
#include "dbproxy.h"
|
|
#include "TDbParking.h"
|
|
|
|
extern int CutStrToPreAndnum(CString &strSerialNum, CString &strPrefix, CString &strNum, int* nNum);
|
|
|
|
ACRX_DXF_DEFINE_MEMBERS(TDbParkingSpace, ATSEntity, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
|
AcDbProxyEntity::kNoOperation, ATS_PARKINGSPACE, "ATS_PARKINGSPACE缺乏解释器图形看不见, 请下载上华软件|网址: www.shanghuasoft.com");
|
|
|
|
IMPLEMENT_TENTBASE(TDbParkingSpace);
|
|
|
|
int g_nSerialNum;
|
|
TDbParkingSpace::TDbParkingSpace():TDbEntity (),
|
|
m_ptStart(AcGePoint3d(0,0,0)),
|
|
m_iWidth(0),
|
|
m_iHeight(0),
|
|
m_iAngle(0),
|
|
m_iRow(0),
|
|
m_iStyle(3),
|
|
m_iNum(0),
|
|
m_iQMode(0),
|
|
m_VectorOffet(AcGeVector3d(0,0,0)),
|
|
m_sName(_T("")),
|
|
m_ptCur(AcGePoint3d(0,0,0))
|
|
{
|
|
|
|
}
|
|
|
|
TDbParkingSpace::~TDbParkingSpace()
|
|
{
|
|
}
|
|
|
|
void AddSerialNum(XExplodeDraw &dc, ATSParking &dbPark, CString &strSerialNum, CString &strTextStyle, double dTextHeight, AcGeVector3d &VectorOffet, int iAngle, double dWidth, double dHeight)
|
|
{
|
|
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;
|
|
text.SetText(strSerialNum);
|
|
text.SetHeight(dTextHeight);
|
|
|
|
if(bXYFlag)
|
|
{
|
|
if ((dIncludedAngle < 0.5 * PI)||(dIncludedAngle > 1.5*PI))
|
|
{
|
|
if (dWidth > dHeight)
|
|
{
|
|
text.SetRotation(dbPark.GetRotAngle());
|
|
}
|
|
else
|
|
{
|
|
text.SetRotation(dbPark.GetRotAngle() + (90 - iAngle)*PI/180);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (dWidth > dHeight)
|
|
{
|
|
text.SetRotation(dbPark.GetRotAngle() + PI);
|
|
}
|
|
else
|
|
{
|
|
text.SetRotation(dbPark.GetRotAngle() + PI + (90 - iAngle)*PI/180);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if ((dIncludedAngle < 0.5 * PI)||(dIncludedAngle > 1.5*PI))
|
|
{
|
|
if (dWidth > dHeight)
|
|
{
|
|
text.SetRotation(dbPark.GetRotAngle() + PI);
|
|
}
|
|
else
|
|
{
|
|
text.SetRotation(dbPark.GetRotAngle() + PI + (90 - iAngle)*PI/180);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (dWidth > dHeight)
|
|
{
|
|
text.SetRotation(dbPark.GetRotAngle());
|
|
}
|
|
else
|
|
{
|
|
text.SetRotation(dbPark.GetRotAngle() + (90 - iAngle)*PI/180);
|
|
}
|
|
}
|
|
}
|
|
text.SetLocation(dbPark.GetPtText());
|
|
AcDbObjectId idTextStyle = GetTextStyleId(strTextStyle);
|
|
if (idTextStyle.isValid())
|
|
text.SetStyleId(idTextStyle);
|
|
else
|
|
text.SetStyleId(acdbCurDwg()->textstyle());
|
|
text.setLayer(::InitLayer(LAY_PKNG_SING));
|
|
text.SetAlignment(XExplodeDraw::kMiddleCenter);
|
|
dc.DrawEntity(text);
|
|
}
|
|
Acad::ErrorStatus TDbParkingSpace::ExplodeOrDraw2d(XExplodeDraw &dc) const
|
|
{
|
|
assertReadEnabled();
|
|
BOOL bIsFirst = m_bIsFirst;
|
|
int nNum = m_nNum, nNumLength = m_nNumLength, nTasksNum;
|
|
if (bIsFirst)
|
|
{
|
|
nTasksNum = m_nNum + 2 * m_iNum;
|
|
}
|
|
else
|
|
{
|
|
nTasksNum = m_nNum + 2 * m_iNum + 1;
|
|
}
|
|
CString strPrefix = m_strPrefix, strPostfix = m_strPostfix, strNum;
|
|
|
|
for (int i =0;i<m_iNum;i++)
|
|
{
|
|
//单排
|
|
if (m_iRow == 0)
|
|
{
|
|
ATSParking dbPark(m_sName);
|
|
dbPark.SetTextOffset(m_dOffset);
|
|
dbPark.Fill((m_ptStart+m_VectorOffet*i),m_VectorOffet,m_iAngle,m_iWidth,m_iHeight,1,m_iStyle,m_iQMode);
|
|
dc.DrawEntity(dbPark);
|
|
if (m_bIsDrawNum)
|
|
{
|
|
CString strText;
|
|
if (bIsFirst)
|
|
{
|
|
if (nNum)
|
|
strText.Format(_T("%s%d%s"), m_strPrefix, nNum, m_strPostfix);
|
|
else
|
|
strText.Format(_T("%s%s"), m_strPrefix, m_strPostfix);
|
|
bIsFirst = FALSE;
|
|
}
|
|
else
|
|
{
|
|
strNum.Format(_T("%d"), ++nNum);
|
|
if (nNumLength == 0)
|
|
{
|
|
nNumLength = strNum.GetLength();
|
|
}
|
|
if ((strNum.GetLength() > nNumLength))
|
|
{
|
|
nNumLength = strNum.GetLength();
|
|
if (strPrefix.GetAt(strPrefix.GetLength() - 1) == '0')
|
|
{
|
|
strPrefix = strPrefix.Left(strPrefix.GetLength() - 1);
|
|
}
|
|
}
|
|
strText.Format(_T("%s%s%s"), strPrefix, strNum, strPostfix);
|
|
}
|
|
AcGeVector3d vec = m_VectorOffet;
|
|
CString strStyle = m_strTextStyle;
|
|
AddSerialNum(dc, dbPark, strText, strStyle, m_dTextHeight, vec, m_iAngle, m_iWidth, m_iHeight);
|
|
}
|
|
}
|
|
//双排
|
|
else if (m_iRow == 1)
|
|
{
|
|
int iQmode1 = 0;
|
|
int iQmode2 = 0;
|
|
if (m_iQMode == 0)
|
|
{
|
|
iQmode1 = 0;
|
|
iQmode2 = 1;
|
|
}
|
|
else if (m_iQMode == 1)
|
|
{
|
|
iQmode1 = 3;
|
|
iQmode2 = 1;
|
|
}
|
|
else if (m_iQMode == 2)
|
|
{
|
|
iQmode1 = 0;
|
|
iQmode2 = 2;
|
|
}
|
|
else if (m_iQMode == 3)
|
|
{
|
|
iQmode1 = 3;
|
|
iQmode2 = 2;
|
|
}
|
|
|
|
ATSParking dbPark1(m_sName);
|
|
dbPark1.SetTextOffset(m_dOffset);
|
|
dbPark1.Fill((m_ptStart+m_VectorOffet*i),m_VectorOffet,m_iAngle,m_iWidth,m_iHeight,1,m_iStyle,iQmode1);
|
|
dc.DrawEntity(dbPark1);
|
|
CString strText;
|
|
AcGeVector3d vec;
|
|
if (m_bIsDrawNum)
|
|
{
|
|
if (bIsFirst)
|
|
{
|
|
if (nNum)
|
|
strText.Format(_T("%s%d%s"), m_strPrefix, nNum, m_strPostfix);
|
|
else
|
|
strText.Format(_T("%s%s"), m_strPrefix, m_strPostfix);
|
|
bIsFirst = FALSE;
|
|
}
|
|
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);
|
|
}
|
|
|
|
vec = m_VectorOffet;
|
|
CString strStyle = m_strTextStyle;
|
|
AddSerialNum(dc, dbPark1, strText, strStyle, m_dTextHeight, vec, m_iAngle, m_iWidth, m_iHeight);
|
|
}
|
|
ATSParking dbPark2(m_sName);
|
|
dbPark2.SetTextOffset(m_dOffset);
|
|
dbPark2.Fill((m_ptStart+m_VectorOffet*i),m_VectorOffet,m_iAngle,m_iWidth,m_iHeight,1,m_iStyle,iQmode2);
|
|
dc.DrawEntity(dbPark2);
|
|
if (m_bIsDrawNum)
|
|
{
|
|
strNum.Format(_T("%d"), --nTasksNum);
|
|
CString strTemp = strPrefix;
|
|
if ((strNum.GetLength() > nNumLength))
|
|
{
|
|
if (strTemp.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);
|
|
CString strStyle = m_strTextStyle;
|
|
AddSerialNum(dc, dbPark2, strText, strStyle, m_dTextHeight, vec, m_iAngle, m_iWidth, m_iHeight);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
//文字提示
|
|
TDbText text;
|
|
XString sValue(256);
|
|
if (m_iRow == 0)
|
|
{
|
|
sValue<<XString(_T("%d"),m_iNum);
|
|
}
|
|
else if (m_iRow == 1)
|
|
{
|
|
sValue<<XString(_T("%d"),2*m_iNum);
|
|
}
|
|
text.SetText(sValue);
|
|
text.SetHeight(m_dTextHeight);
|
|
text.SetLayoutRotation(Ucs2Wcs(0));
|
|
AcDbObjectId idTextStyle = GetTextStyleId(m_strTextStyle);
|
|
if (idTextStyle.isValid())
|
|
text.SetStyleId(idTextStyle);
|
|
else
|
|
text.SetStyleId(acdbCurDwg()->textstyle());
|
|
AcGePoint3d ptCur = m_ptCur;
|
|
if (m_iQMode==0 || m_iQMode == 3)
|
|
{
|
|
text.SetLocation((ptCur-AcGeVector3d(_AS_SYS_UNIT(5*DocGetPScale()),_AS_SYS_UNIT(-5*DocGetPScale()),0)));
|
|
text.SetAlignment(XExplodeDraw::kBottomRight);
|
|
}
|
|
else
|
|
{
|
|
text.SetLocation((ptCur-AcGeVector3d(_AS_SYS_UNIT(5*DocGetPScale()),_AS_SYS_UNIT(5*DocGetPScale()),0)));
|
|
text.SetAlignment(XExplodeDraw::kTopRight);
|
|
}
|
|
dc.DrawEntity(text);
|
|
|
|
return Acad::eOk;
|
|
}
|
|
|
|
|
|
void TDbParkingSpace::SetStartPt(const TADSGePoint3d &ptStart)
|
|
{
|
|
m_ptStart = ptStart;
|
|
}
|
|
|
|
TADSGePoint3d TDbParkingSpace::GetStartPt()
|
|
{
|
|
return m_ptStart;
|
|
}
|
|
|
|
void TDbParkingSpace::Update(AcGePoint3d &ptCur,AcGeVector3d &vec,double iWidth,double iHeight, double dTextHeight, int angle, CString &strSerialNum, CString &strTextStyle, BOOL bIsDrawNum, BOOL bIsFirst, double dOffset, int iRow,int iStyle,int iNum)
|
|
{
|
|
m_ptCur = ptCur;
|
|
m_VectorOffet = vec;
|
|
m_iWidth = iWidth;
|
|
m_iHeight = iHeight;
|
|
m_iAngle = angle;
|
|
m_iRow = iRow;
|
|
m_iStyle = iStyle;
|
|
m_iNum = iNum;
|
|
m_bIsFirst = bIsFirst;
|
|
m_dOffset = dOffset;
|
|
m_bIsDrawNum = bIsDrawNum;
|
|
m_strTextStyle = strTextStyle;
|
|
m_dTextHeight = dTextHeight;
|
|
m_nNumLength = CutStrToPreAndnum(strSerialNum, m_strPrefix, m_strPostfix, &m_nNum);
|
|
}
|
|
|
|
void TDbParkingSpace::QMode()
|
|
{
|
|
m_iQMode++;
|
|
m_iQMode = m_iQMode%4;
|
|
}
|
|
|
|
int TDbParkingSpace::Num()
|
|
{
|
|
return m_iNum;
|
|
}
|
|
|
|
void TDbParkingSpace::SetBlockName(XString &sName)
|
|
{
|
|
m_sName = sName;
|
|
} |