920 lines
24 KiB
C++
920 lines
24 KiB
C++
#include "StdAfx.h"
|
||
#include "AecDbDrawingName.h"
|
||
#include "globalFunc.h"
|
||
#include "PushProperty.h"
|
||
#include "GePoly2D.h"
|
||
#include "aecdbtext.h"
|
||
|
||
AcDbObjectId InitLayer(const TCHAR *szLayer, AcDbDatabase *pDb = NULL);
|
||
AcDbObjectId InitTextStyle(TTextStyle ts, AcDbDatabase *pDb = NULL);
|
||
Adesk::Int16 AecXDbDrawingName::g_nVersion = 3;
|
||
|
||
ACRX_DXF_DEFINE_MEMBERS(AecXDbDrawingName, AecXDbEntityBaseEx, AcDb::kDHL_CURRENT,
|
||
AcDb::kMReleaseCurrent, 1, AEC_TUMINGBIAOZHU,
|
||
"AEC_TUMINGBIAOZHU|缺乏上华解释器, 请下载上华软件|网址: www.shanghuasoft.com");
|
||
|
||
#define DRAWINGNAME_REGIONPL _T("DNREGION")
|
||
|
||
// Constructor / Destructor
|
||
AecXDbDrawingName::AecXDbDrawingName()
|
||
{
|
||
m_dRotation = 0.0;
|
||
m_dNameHeight = 7.0;
|
||
m_dScaleHeight = 5.0;
|
||
m_dLineWidth = 0.7;
|
||
// m_dMultiple = 1.0;
|
||
m_dMultiple = 0.6; // modified by whl on 020613
|
||
// sg modify 120106,给“TS_DRAWINGNAME”独立出来一个文字样式
|
||
//m_idNameStyle = InitTextStyle(TS_STANDARD);
|
||
//m_idScaleStyle = InitTextStyle(TS_STANDARD);
|
||
m_idNameStyle = InitTextStyle(TS_DRAWINGNAME);
|
||
m_idScaleStyle = InitTextStyle(TS_DRAWINGNAME);
|
||
m_bShowScale = TRUE;
|
||
m_iDrawStyle = 1;
|
||
m_colorText = 7;
|
||
m_bShowRegion = FALSE;
|
||
}
|
||
|
||
//Acad::ErrorStatus
|
||
//AecXDbDrawingName::subGetClassID(CLSID* pClsid) const
|
||
//{
|
||
// *pClsid = CLSID_ComDrawingName;
|
||
// return Acad::eOk;
|
||
//}
|
||
|
||
Acad::ErrorStatus
|
||
AecXDbDrawingName::dwgInFields(AcDbDwgFiler* filer)
|
||
{
|
||
AssertWriteEnabled();
|
||
Acad::ErrorStatus es;
|
||
if ((es = AecXDbEntityBaseEx::dwgInFields(filer)) != Acad::eOk)
|
||
return es;
|
||
|
||
Adesk::Int16 version;
|
||
filer->readItem(&version);
|
||
if (version > g_nVersion)
|
||
return Acad::eMakeMeProxy;
|
||
|
||
AcGePoint3d ptLoc; // sg modify 090112
|
||
filer->readItem(&ptLoc);
|
||
m_ptLocation = ptLoc;
|
||
GlobalFunc::ReadString(filer, m_szNameText);
|
||
GlobalFunc::ReadString(filer, m_szScaleText);
|
||
filer->readItem(&m_dRotation);
|
||
filer->readItem(&m_dNameHeight);
|
||
filer->readItem(&m_dScaleHeight);
|
||
filer->readItem(&m_dLineWidth);
|
||
filer->readItem(&m_dMultiple);
|
||
filer->readItem(&m_idNameStyle);
|
||
filer->readItem(&m_idScaleStyle);
|
||
filer->readItem(&m_bShowScale);
|
||
filer->readItem(&m_iDrawStyle);
|
||
filer->readItem(&m_colorText);
|
||
|
||
if (version > 1) // sg add 090112,8.0起
|
||
{
|
||
filer->readItem((AcGePoint3d *)&m_ptMidLoc);
|
||
if (version == 2) // sg add 090325,处理8.0的Beta1版本
|
||
{
|
||
GetCenterPtIncludeScale(); // 转化为Beta2中的包括比例部分的居中对齐点
|
||
// sg add 090325,8.0的BETA2起,将“文字转角”并入“布局转角”
|
||
m_nLayoutRotation = m_nLayoutRotation + m_dRotation;
|
||
m_dRotation = 0;
|
||
}
|
||
}
|
||
else // 处理8.0以前版本
|
||
{
|
||
GetBottomCenterPt(); // 将7.5中的m_ptLocation点转化为m_ptMidLoc
|
||
// sg add 090320,8.0的BETA2起,将“文字转角”并入“布局转角”
|
||
m_nLayoutRotation = m_nLayoutRotation + m_dRotation;
|
||
m_dRotation = 0;
|
||
}
|
||
return filer->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
AecXDbDrawingName::dwgOutFields(AcDbDwgFiler* filer) const
|
||
{
|
||
assertReadEnabled();
|
||
if (!IsValid())
|
||
return Acad::eNotApplicable;
|
||
|
||
Acad::ErrorStatus es;
|
||
if ((es = AecXDbEntityBaseEx::dwgOutFields(filer)) != Acad::eOk)
|
||
return es;
|
||
|
||
Adesk::Int16 version = g_nVersion;
|
||
filer->writeItem(g_nVersion);
|
||
|
||
filer->writeItem(m_ptLocation.AsAcGePoint3d());
|
||
filer->writeItem(m_szNameText);
|
||
filer->writeItem(m_szScaleText);
|
||
filer->writeItem(m_dRotation);
|
||
filer->writeItem(m_dNameHeight);
|
||
filer->writeItem(m_dScaleHeight);
|
||
filer->writeItem(m_dLineWidth);
|
||
filer->writeItem(m_dMultiple);
|
||
filer->writeItem(m_idNameStyle);
|
||
filer->writeItem(m_idScaleStyle);
|
||
filer->writeItem(m_bShowScale);
|
||
filer->writeItem(m_iDrawStyle);
|
||
filer->writeItem(m_colorText);
|
||
|
||
filer->writeItem(m_ptMidLoc.AsAcGePoint3d());
|
||
return filer->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
AecXDbDrawingName::dxfInFields(AcDbDxfFiler* filer)
|
||
{
|
||
return AecXDbEntityBaseEx::dxfInFields(filer);
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
AecXDbDrawingName::dxfOutFields(AcDbDxfFiler* filer) const
|
||
{
|
||
return AecXDbEntityBaseEx::dxfOutFields(filer);
|
||
}
|
||
|
||
Acad::ErrorStatus AecXDbDrawingName::GetGripText(int idx, CString &cs) const
|
||
{
|
||
assertReadEnabled();
|
||
Acad::ErrorStatus es = Acad::eOk;
|
||
switch (idx) {
|
||
case 0:
|
||
cs = _T("移动图名标注");
|
||
break;
|
||
case 1:
|
||
cs = _T("移动比例位置");
|
||
break;
|
||
default:
|
||
es = Acad::eInvalidIndex;
|
||
break;
|
||
}
|
||
return es;
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
AecXDbDrawingName::subGetGripPoints(AcGePoint3dArray& gripPoints,
|
||
AcDbIntArray& osnapModes,
|
||
AcDbIntArray& geomIds) const
|
||
{
|
||
assertReadEnabled();
|
||
// gripPoints.append(m_ptLocation); // sg modify 090112,改为居中对齐点
|
||
gripPoints.append(m_ptMidLoc);
|
||
if (m_bShowScale) // 显示比例
|
||
{
|
||
ADSGePoint3d ptScaleLoc = GetScaleLocation();
|
||
gripPoints.append(ptScaleLoc);
|
||
}
|
||
|
||
// add by hh 2013-10-15 增加区域线条夹点
|
||
GePoly2D poly;
|
||
if (GetRegionPoly(&poly))
|
||
{
|
||
for (int i = 0; i < poly.Length(); i++)
|
||
{
|
||
gripPoints.append(*(poly[i]));
|
||
}
|
||
}
|
||
// add end
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecXDbDrawingName::subGetGripPoints(AcDbGripDataPtrArray & grips, const double curViewUnitSize, const int gripSize, const AcGeVector3d & curViewDir, const int bitflags) const
|
||
{
|
||
return Acad::eNotImplementedYet;
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
AecXDbDrawingName::subGetOsnapPoints(AcDb::OsnapMode osnapMode,
|
||
INT_PTR gsSelectionMark,
|
||
const AcGePoint3d& pickPoint,
|
||
const AcGePoint3d& lastPoint,
|
||
const AcGeMatrix3d& viewXform,
|
||
AcGePoint3dArray& snapPoints,
|
||
AcDbIntArray& geomIds) const
|
||
{
|
||
assertReadEnabled();
|
||
Acad::ErrorStatus es = Acad::eNotApplicable;
|
||
switch (osnapMode) {
|
||
case AcDb::kOsModeIns:
|
||
{
|
||
// snapPoints.append(m_ptLocation); // sg modify 090112,改为居中对齐点
|
||
snapPoints.append(m_ptMidLoc);
|
||
if (m_bShowScale) // 显示比例
|
||
{
|
||
ADSGePoint3d ptScaleLoc = GetScaleLocation();
|
||
snapPoints.append(ptScaleLoc);
|
||
}
|
||
es = Acad::eOk;
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return es;
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
AecXDbDrawingName::subMoveGripPointsAt(const AcDbIntArray& indices,
|
||
const AcGeVector3d& offset)
|
||
{
|
||
if (indices.length() == 0 || offset.isZeroLength())
|
||
return Acad::eOk;
|
||
|
||
AssertWriteEnabled();
|
||
|
||
AecDbObjXDataMap* pXData = __GetSpecialtyData();
|
||
AcGePoint3dArray arPts;
|
||
pXData->GetAt(DRAWINGNAME_REGIONPL, arPts);
|
||
|
||
for (int i = 0; i < indices.length(); i++)
|
||
{
|
||
int idx = indices[i];
|
||
switch (idx) {
|
||
case 0:
|
||
// m_ptLocation += offset; // sg modify 090112,改为居中对齐点
|
||
m_ptMidLoc += offset;
|
||
break;
|
||
case 1:
|
||
{
|
||
if (m_bShowScale) // 显示比例
|
||
{
|
||
AcGeVector3d vtUnit(AcGeVector3d::kXAxis);
|
||
// sg modify 090320,8.0起将文字转角并入布局转角
|
||
// vtUnit.rotateBy(m_dRotation + GetLayoutRotation(), AcGeVector3d::kZAxis);
|
||
vtUnit.rotateBy(GetLayoutRotation(), AcGeVector3d::kZAxis);
|
||
|
||
double dAngle = vtUnit.angleTo(offset); // 将变化量投影到布局转角方向
|
||
m_dMultiple += offset.length() * cos(dAngle) / GetPScale() / m_dNameHeight;
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
// add by hh 2013-10-15 增加区域夹点的处理
|
||
if (0 != arPts.length())
|
||
{
|
||
if (m_bShowScale)
|
||
idx -= 2;
|
||
else
|
||
idx -= 1;
|
||
if (0 <= idx && idx < arPts.length())
|
||
{
|
||
arPts[idx] += offset;
|
||
SetRegionPoly(arPts);
|
||
}
|
||
}
|
||
// add end
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
AecXDbDrawingName::subTransformBy(const AcGeMatrix3d& xform)
|
||
{
|
||
AssertWriteEnabled();
|
||
Acad::ErrorStatus es;
|
||
if ((es = AecXDbEntityBaseEx::subTransformBy(xform)) != Acad::eOk)
|
||
return es;
|
||
|
||
// m_ptLocation.TransformBy(xform); // sg modify 090112,改为居中对齐点
|
||
m_ptMidLoc.TransformBy(xform);
|
||
|
||
// add by hh 2013-10-15 区域PL
|
||
AecDbObjXDataMap* pXData = __GetSpecialtyData();
|
||
if (NULL != pXData)
|
||
{
|
||
AcGePoint3dArray arPts;
|
||
if (pXData->GetAt(DRAWINGNAME_REGIONPL, arPts))
|
||
{
|
||
int nLen = arPts.length();
|
||
for (int i = 0; i < nLen; i++)
|
||
{
|
||
arPts[i].transformBy(xform);
|
||
}
|
||
SetRegionPoly(arPts);
|
||
}
|
||
}
|
||
// add end
|
||
|
||
// sg delete 090325,图名的位置点调整到整个符号的居中对齐,镜像时,不再需要调整
|
||
// AcGeVector3d vtRotation = GetVector();
|
||
// vtRotation.transformBy(xform);
|
||
// if (IsMirrorMatrix(xform))
|
||
// {
|
||
// AcGeVector3d vec = vtRotation;
|
||
// vec.rotateBy(Wcs2Ucs(0.0), AcGeVector3d::kZAxis);
|
||
// if (vec.x < 0.0)
|
||
// {
|
||
// m_ptLocation += vtRotation;
|
||
// vtRotation.negate();
|
||
// }
|
||
// else
|
||
// m_ptLocation -= m_dNameHeight * GetPScale() * vtRotation.perpVector();
|
||
// }
|
||
|
||
// modified by whl on 060707,只改变布局转角
|
||
// double dAngle = vtRotation.angleTo(AcGeVector3d::kXAxis);
|
||
// if (vtRotation.y < 0.0)
|
||
// dAngle = 2 * PI - dAngle;
|
||
// m_dRotation = dAngle - GetLayoutRotation();
|
||
return Acad::eOk;
|
||
}
|
||
|
||
// sg add 090327,获取整个符号长度/线长(沿布局转角方向)
|
||
double AecXDbDrawingName::GetTotalLen() const
|
||
{
|
||
assertReadEnabled();
|
||
AecXDbText text;
|
||
text.SetPScale(GetPScale());
|
||
text.setPropertiesFrom(this);
|
||
text.SetRotation(0.0);
|
||
text.SetAlignment(AcGiDraw::kBottomLeft);
|
||
text.SetHeight(m_dNameHeight);
|
||
text.SetStyleId(m_idNameStyle);
|
||
text.SetText(m_szNameText); // 图名文字
|
||
text.SetLocation(ADSGePoint3d());
|
||
|
||
double dNameX(0.0), dNameY(0.0);
|
||
text.GetExtents(&dNameX, &dNameY);
|
||
|
||
double dRet = dNameX;
|
||
if (m_bShowScale) // 显示比例
|
||
{
|
||
text.SetHeight(m_dScaleHeight);
|
||
text.SetStyleId(m_idScaleStyle);
|
||
text.SetText(m_szScaleText); // 比例文字
|
||
text.SetLocation(ADSGePoint3d());
|
||
|
||
double dScaleX(0.0), dScaleY(0.0);
|
||
text.GetExtents(&dScaleX, &dScaleY);
|
||
dRet += m_dMultiple * m_dNameHeight * GetPScale() + dScaleX;
|
||
if (m_iDrawStyle == 0) // 传统样式
|
||
dRet += 0.2 * m_dScaleHeight * GetPScale();
|
||
}
|
||
else // 不显示比例
|
||
dRet += 0.2 * m_dNameHeight * GetPScale();
|
||
return dRet;
|
||
}
|
||
|
||
double AecXDbDrawingName::GetLineLen() const
|
||
{
|
||
assertReadEnabled();
|
||
AecXDbText text;
|
||
text.SetPScale(GetPScale());
|
||
text.setPropertiesFrom(this);
|
||
text.SetRotation(0.0);
|
||
text.SetAlignment(AcGiDraw::kBottomLeft);
|
||
text.SetHeight(m_dNameHeight);
|
||
text.SetStyleId(m_idNameStyle);
|
||
text.SetText(m_szNameText); // 图名文字
|
||
text.SetLocation(ADSGePoint3d());
|
||
|
||
double dNameX(0.0), dNameY(0.0);
|
||
text.GetExtents(&dNameX, &dNameY);
|
||
|
||
double dRet = dNameX;
|
||
if (m_bShowScale && m_iDrawStyle == 0) // 传统样式,显示比例
|
||
{
|
||
text.SetHeight(m_dScaleHeight);
|
||
text.SetStyleId(m_idScaleStyle);
|
||
text.SetText(m_szScaleText); // 比例文字
|
||
text.SetLocation(ADSGePoint3d());
|
||
|
||
double dScaleX(0.0), dScaleY(0.0);
|
||
text.GetExtents(&dScaleX, &dScaleY);
|
||
dRet += m_dMultiple * m_dNameHeight * GetPScale() + dScaleX;
|
||
dRet += 0.2 * m_dScaleHeight * GetPScale();
|
||
}
|
||
else // 不显示比例
|
||
dRet += 0.2 * m_dNameHeight * GetPScale();
|
||
return dRet;
|
||
}
|
||
|
||
// 根据m_ptMidLoc点,计算“图名”、“比例”绘制点
|
||
ADSGePoint3d AecXDbDrawingName::GetNameDrawPt() const // sg add 090325,图名绘制点
|
||
{
|
||
assertReadEnabled();
|
||
AcGeVector3d vtUnit(AcGeVector3d::kXAxis);
|
||
// 8.0起,文字转角并入布局转角
|
||
vtUnit.rotateBy(GetLayoutRotation(), AcGeVector3d::kZAxis);
|
||
|
||
ADSGePoint3d ptRet;
|
||
double dDist = GetTotalLen() * 0.5;
|
||
ptRet = m_ptMidLoc - dDist * vtUnit;
|
||
return ptRet;
|
||
}
|
||
|
||
ADSGePoint3d AecXDbDrawingName::GetScaleLocation() const // 比例绘制点
|
||
{
|
||
assertReadEnabled();
|
||
AcGeVector3d vtUnit(AcGeVector3d::kXAxis);
|
||
// sg modify 090320,8.0起将文字转角并入布局转角
|
||
// vtUnit.rotateBy(m_dRotation+GetLayoutRotation(), AcGeVector3d::kZAxis);
|
||
vtUnit.rotateBy(GetLayoutRotation(), AcGeVector3d::kZAxis);
|
||
|
||
AecXDbText text;
|
||
text.SetPScale(GetPScale());
|
||
text.setPropertiesFrom(this);
|
||
text.SetRotation(0.0);
|
||
text.SetAlignment(AcGiDraw::kBottomLeft);
|
||
text.SetHeight(m_dNameHeight);
|
||
text.SetStyleId(m_idNameStyle);
|
||
text.SetText(m_szNameText); // 图名
|
||
text.SetLocation(ADSGePoint3d());
|
||
|
||
double dNameX(0.0), dNameY(0.0);
|
||
text.GetExtents(&dNameX, &dNameY);
|
||
|
||
// sg delete 090327,调用GetTotalLen函数处理
|
||
// text.SetAlignment(AcGiDraw::kBottomLeft);
|
||
// text.SetHeight(m_dScaleHeight);
|
||
// text.SetStyleId(m_idScaleStyle);
|
||
// text.SetText(m_szScaleText); // 比例
|
||
// text.SetLocation(ADSGePoint3d());
|
||
// double dScaleX(0.0), dScaleY(0.0);
|
||
// text.GetExtents(&dScaleX, &dScaleY);
|
||
|
||
ADSGePoint3d ptRet;
|
||
double dDist = GetTotalLen() * 0.5; // sg add 090327
|
||
// ptRet = m_ptLocation + (dNameX + m_dMultiple * dNameY) * vtUnit; // sg modify 090112
|
||
ptRet = m_ptMidLoc + (dNameX + m_dMultiple * dNameY - dDist) * vtUnit;
|
||
return ptRet;
|
||
}
|
||
|
||
|
||
// 8.0的Beta2起,该函数未使用,原设计意图是处理镜像时,整个符号的位置点
|
||
AcGeVector3d AecXDbDrawingName::GetVector() const
|
||
{
|
||
AcGeVector3d vtUnit(AcGeVector3d::kXAxis);
|
||
// sg modify 090320,8.0起将文字转角并入布局转角
|
||
// vtUnit.rotateBy(m_dRotation+GetLayoutRotation(), AcGeVector3d::kZAxis);
|
||
vtUnit.rotateBy(GetLayoutRotation(), AcGeVector3d::kZAxis);
|
||
|
||
AecXDbText text;
|
||
text.SetPScale(GetPScale());
|
||
text.setPropertiesFrom(this);
|
||
text.SetRotation(0.0);
|
||
text.SetAlignment(AcGiDraw::kBottomLeft);
|
||
text.SetHeight(m_dNameHeight);
|
||
text.SetStyleId(m_idNameStyle);
|
||
text.SetText(m_szNameText); // 图名
|
||
ADSGePoint3d ptNameLoc;
|
||
text.SetLocation(ptNameLoc);
|
||
|
||
double dNameX(0.0), dNameY(0.0);
|
||
text.GetExtents(&dNameX, &dNameY);
|
||
// vtRotation = dNameX * vtUnit; // sg delete 090113
|
||
|
||
AcGeVector3d vtRotation;
|
||
double dScaleX(0.0), dScaleY(0.0);
|
||
if (m_bShowScale) // 比例
|
||
{
|
||
ADSGePoint3d ptScaleLoc;
|
||
ptScaleLoc.x = ptNameLoc.x + (dNameX * 0.5 + m_dMultiple * dNameY);
|
||
ptScaleLoc.y = ptNameLoc.y;
|
||
text.SetHeight(m_dScaleHeight);
|
||
text.SetStyleId(m_idScaleStyle);
|
||
text.SetText(m_szScaleText);
|
||
text.SetLocation(ptScaleLoc);
|
||
text.SetAlignment(AcGiDraw::kBottomLeft); // sg add 090112
|
||
text.GetExtents(&dScaleX, &dScaleY);
|
||
// vtRotation += (m_dMultiple * dNameY + dScaleX) * vtUnit;
|
||
vtRotation = (m_dMultiple * dNameY + dScaleX) * vtUnit; // sg modify 090113
|
||
}
|
||
return vtRotation;
|
||
}
|
||
|
||
double AecXDbDrawingName::GetOffset() const // ExplodeOrDraw2d函数中调用
|
||
{
|
||
AecXDbText text;
|
||
text.SetPScale(GetPScale());
|
||
text.setPropertiesFrom(this);
|
||
text.SetLayoutRotation(0);
|
||
text.SetRotation(0.0);
|
||
text.SetAlignment(AcGiDraw::kBottomLeft);
|
||
text.SetHeight(m_dNameHeight);
|
||
text.SetStyleId(m_idNameStyle);
|
||
text.SetText(m_szNameText);
|
||
text.SetLocation(ADSGePoint3d());
|
||
AcGiViewDraw dc;
|
||
text.Draw2d(dc);
|
||
const AcDbVoidPtrArray &ar = text.Get2DBuffer();
|
||
AcDbExtents ext, extall;
|
||
for (int i = 0; i < ar.length(); ++i)
|
||
{
|
||
const AcDbEntity *p((AcDbEntity*)ar[i]);
|
||
if (p->getGeomExtents(ext) == Acad::eOk)
|
||
extall.addExt(ext);
|
||
}
|
||
|
||
ADSGePoint3d ptLow, ptUp;
|
||
ptLow = extall.minPoint();
|
||
ptUp = extall.maxPoint();
|
||
//text.GetExtents2d(ptLow, ptUp);
|
||
return -ptLow.y;
|
||
}
|
||
|
||
|
||
// sg add 090112,将7.5中的m_ptLocation点转化为m_ptMidLoc
|
||
void AecXDbDrawingName::GetBottomCenterPt()
|
||
{
|
||
AssertWriteEnabled();
|
||
AcGeVector3d vtUnit(AcGeVector3d::kXAxis);
|
||
// sg modify 090320,8.0起将文字转角并入布局转角
|
||
// vtUnit.rotateBy(m_dRotation+GetLayoutRotation(), AcGeVector3d::kZAxis);
|
||
vtUnit.rotateBy(GetLayoutRotation(), AcGeVector3d::kZAxis);
|
||
|
||
double dDist = GetTotalLen() * 0.5; // sg modify 090327
|
||
m_ptMidLoc = m_ptLocation + dDist * vtUnit;
|
||
}
|
||
|
||
ADSGePoint3d AecXDbDrawingName::GetBottomLeftPt() const
|
||
{
|
||
AcGeVector3d vtUnit(AcGeVector3d::kXAxis);
|
||
// sg modify 090320,8.0起将文字转角并入布局转角
|
||
// vtUnit.rotateBy(m_dRotation+GetLayoutRotation(), AcGeVector3d::kZAxis);
|
||
vtUnit.rotateBy(GetLayoutRotation(), AcGeVector3d::kZAxis);
|
||
|
||
double dDist = GetTotalLen() * 0.5; // sg modify 090327
|
||
ADSGePoint3d ptRet = m_ptMidLoc - dDist * vtUnit;
|
||
return ptRet;
|
||
}
|
||
|
||
// sg add 090325,根据Beta1中的图名居中对齐点,得到Beta2中的包括比例部分的居中对齐点
|
||
void AecXDbDrawingName::GetCenterPtIncludeScale()
|
||
{
|
||
AssertWriteEnabled();
|
||
AcGeVector3d vtUnit(AcGeVector3d::kXAxis);
|
||
vtUnit.rotateBy(GetLayoutRotation(), AcGeVector3d::kZAxis);
|
||
|
||
AecXDbText text;
|
||
text.SetPScale(GetPScale());
|
||
text.setPropertiesFrom(this);
|
||
text.SetRotation(0.0);
|
||
text.SetAlignment(AcGiDraw::kBottomLeft);
|
||
text.SetHeight(m_dNameHeight);
|
||
text.SetStyleId(m_idNameStyle);
|
||
text.SetText(m_szNameText);
|
||
text.SetLocation(ADSGePoint3d());
|
||
|
||
double dNameX(0.0), dNameY(0.0);
|
||
text.GetExtents(&dNameX, &dNameY);
|
||
double dDist = (GetTotalLen() - dNameX) * 0.5;
|
||
m_ptMidLoc = m_ptMidLoc + dDist * vtUnit;
|
||
}
|
||
|
||
///////////////////////////////////////////////////////
|
||
Acad::ErrorStatus
|
||
AecXDbDrawingName::Draw2d(AcGiDraw &dc) const
|
||
{
|
||
assertReadEnabled();
|
||
GlobalFunc::_LoadConfig();
|
||
if (!IsValid())
|
||
return Acad::eNotApplicable;
|
||
|
||
if (Has2DBuffer() && !m_bInJig)
|
||
{
|
||
dc.SetColor(colorIndex());
|
||
dc.SetLayer(layerId());
|
||
BaseEx::_Draw2DBuffers(dc, true);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
AcGeVector3d vtUnit(AcGeVector3d::kXAxis);
|
||
double layRotation = GetLayoutRotation();
|
||
// sg modify 090320,8.0起将文字转角并入布局转角
|
||
// vtUnit.rotateBy(m_dRotation + layRotation, AcGeVector3d::kZAxis);
|
||
vtUnit.rotateBy(layRotation, AcGeVector3d::kZAxis);
|
||
|
||
AecXDbText text; // 文字
|
||
text.setPropertiesFrom(this);
|
||
text.SetPScale(GetPScale());
|
||
// sg add 120313,分解出来的文字的图层和颜色要随“高级选项”中的设置来处理
|
||
//if (dc.IsExportTch4() && g_nSymbTextT3Layer == 1)
|
||
//{
|
||
// text.setLayer(::InitLayer(LAY_TEXT, database()));
|
||
//}
|
||
//else
|
||
text.setColorIndex(m_colorText); // sg add 090608,文字和标注放在同一层,文字的颜色为白色
|
||
text.SetAlignment(AcGiDraw::kBottomLeft);
|
||
text.SetHeight(m_dNameHeight);
|
||
text.SetStyleId(m_idNameStyle);
|
||
text.SetText(m_szNameText); // 图名
|
||
|
||
// ADSGePoint3d ptNameLoc = m_ptLocation; // sg modify 090112
|
||
ADSGePoint3d ptNameLoc = GetNameDrawPt();
|
||
text.SetLocation(ptNameLoc);
|
||
// sg delete 090320,8.0起将文字转角并入布局转角
|
||
// text.SetRotation(m_dRotation);
|
||
double dNameX = 0, dNameY = 0;
|
||
text.GetExtents(&dNameX, &dNameY);
|
||
//if (dc.IsFullExplode())
|
||
//{
|
||
// TPushProperty vProp(&text, dc);
|
||
// text.ExplodeOrDraw2d(dc);
|
||
//}
|
||
//else
|
||
//dc.DrawEntity(text);
|
||
DrawBaseEx(dc, text);
|
||
|
||
double dScaleX = 0, dScaleY = 0;
|
||
if (m_bShowScale) // 显示比例
|
||
{
|
||
// sg modify 090112
|
||
// ADSGePoint3d ptScaleLoc = m_ptLocation + (dNameX + m_dMultiple * m_dNameHeight * GetPScale()) * vtUnit;
|
||
ADSGePoint3d ptScaleLoc = GetScaleLocation();
|
||
text.SetHeight(m_dScaleHeight);
|
||
text.SetStyleId(m_idScaleStyle);
|
||
text.SetText(m_szScaleText);
|
||
text.SetLocation(ptScaleLoc);
|
||
text.GetExtents(&dScaleX, &dScaleY);
|
||
//if (dc.IsFullExplode())
|
||
//{
|
||
// TPushProperty vProp(&text, dc);
|
||
// text.ExplodeOrDraw2d(dc);
|
||
//}
|
||
//else
|
||
//dc.DrawEntity(text);
|
||
DrawBaseEx(dc, text);
|
||
}
|
||
|
||
// add by whl on 060313
|
||
if (dNameX < 1E-5)
|
||
dNameX = 100;
|
||
if (dScaleX < 1E-5)
|
||
dScaleX = 100;
|
||
|
||
// 下画线
|
||
// ADSGePoint3d ptLeft = m_ptLocation; // sg modify 090112
|
||
// ADSGePoint3d ptRight = m_ptLocation;
|
||
// double dScale = 1.0/5.0 * GetPScale();
|
||
// if (m_bShowScale && m_iDrawStyle==0) // 传统样式
|
||
// ptRight += (dTotalLen*0.5 + m_dScaleHeight*dScale) * vtUnit;
|
||
// else
|
||
// ptRight += (dTotalLen*0.5 + m_dNameHeight*dScale) * vtUnit;
|
||
|
||
ADSGePoint3d ptLeft = ptNameLoc; // sg modify 090327,整个图名符号长度
|
||
ADSGePoint3d ptRight = ptNameLoc + GetLineLen() * vtUnit;
|
||
GeLine ln(ptLeft, ptRight);
|
||
ln.SetElevation(0.0);
|
||
ln = ln.Offset(GetOffset());
|
||
AcDbPolyline pline;
|
||
pline.setPropertiesFrom(this);
|
||
double dOffset = 2 * m_dLineWidth * GetPScale();
|
||
|
||
GeLine lnThick = ln.Offset(dOffset); // 粗线
|
||
pline.addVertexAt(0, lnThick.StartPoint());
|
||
pline.addVertexAt(1, lnThick.EndPoint());
|
||
pline.setConstantWidth(m_dLineWidth * GetPScale());
|
||
DrawPline(dc, pline);
|
||
//dc.DrawEntity(pline);
|
||
|
||
if (m_iDrawStyle == 0) // 传统样式
|
||
{
|
||
GeLine lnThin = ln.Offset(2 * dOffset); // 细线
|
||
pline.reset(Adesk::kFalse, 0);
|
||
pline.addVertexAt(0, lnThin.StartPoint());
|
||
pline.addVertexAt(1, lnThin.EndPoint());
|
||
pline.setConstantWidth(0.0);
|
||
DrawPline(dc, pline);
|
||
//dc.DrawEntity(pline);
|
||
}
|
||
|
||
// add by hh 2013-10-15 实体被选中时,绘制其轮廓区域
|
||
AcDbObjectId idMe = objectId();
|
||
BOOL bHighlight = !idMe;
|
||
if (bHighlight || IsShowRegion())
|
||
{
|
||
GePoly2D poly;
|
||
if (GetRegionPoly(&poly))
|
||
{
|
||
//dc.DrawXPoly(poly);
|
||
DrawPoly2D(dc, poly);
|
||
}
|
||
}
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
// sg add 110301,支持统一标高
|
||
bool AecXDbDrawingName::UnifyElevation(double dElevation)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_ptMidLoc.z = dElevation;
|
||
m_ptLocation.z = dElevation;
|
||
return true;
|
||
}
|
||
|
||
BOOL AecXDbDrawingName::IsValid() const
|
||
{
|
||
return TRUE;
|
||
}
|
||
|
||
// 提供对格式刷的支持
|
||
void AecXDbDrawingName::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
|
||
{
|
||
AssertWriteEnabled();
|
||
AecXDbEntityBaseEx::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
|
||
AecXDbDrawingName *pSrc = AecXDbDrawingName::cast(pSrcEntity);
|
||
if (pSrc)
|
||
{
|
||
m_dRotation = pSrc->m_dRotation;
|
||
m_dNameHeight = pSrc->m_dNameHeight;
|
||
m_dScaleHeight = pSrc->m_dScaleHeight;
|
||
m_dLineWidth = pSrc->m_dLineWidth;
|
||
m_dMultiple = pSrc->m_dMultiple;
|
||
if (database() == NULL || pSrcEntity->database() == NULL ||
|
||
database() == pSrcEntity->database()) // add by whl on 060317
|
||
{
|
||
m_idNameStyle = pSrc->m_idNameStyle;
|
||
m_idScaleStyle = pSrc->m_idScaleStyle;
|
||
}
|
||
m_bShowScale = pSrc->m_bShowScale;
|
||
m_iDrawStyle = pSrc->m_iDrawStyle;
|
||
m_colorText = pSrc->m_colorText;
|
||
}
|
||
}
|
||
|
||
void AecXDbDrawingName::GetTips(PtrList<ObjInfoUnit> &lstInfo) const
|
||
{
|
||
lstInfo.Append(new ObjInfoUnit(_T("对象类型"), _T("图名标注")));
|
||
lstInfo.Append(new ObjInfoUnit(_T("图名内容"), m_szNameText));
|
||
lstInfo.Append(new ObjInfoUnit(_T("图名样式"), GlobalFunc::GetSymbolName(m_idNameStyle)));
|
||
lstInfo.Append(new ObjInfoUnit(_T("图名高度"), TCString(_T("%.1fP"), m_dNameHeight)));
|
||
lstInfo.Append(new ObjInfoUnit(_T("比例内容"), m_szScaleText));
|
||
lstInfo.Append(new ObjInfoUnit(_T("比例样式"), GlobalFunc::GetSymbolName(m_idScaleStyle)));
|
||
lstInfo.Append(new ObjInfoUnit(_T("比例高度"), TCString(_T("%.1fP"), m_dScaleHeight)));
|
||
// sg delete 090320,8.0起将文字转角并入布局转角
|
||
// lstInfo.Append(new ObjInfoUnit(_T("旋转角度"), TCString(_T("%.0f"), m_dRotation*180/PI)));
|
||
}
|
||
|
||
const TCHAR *AecXDbDrawingName::GetDefaultLayer() const
|
||
{
|
||
//::InitLayer(LAY_OTHER_DIM);
|
||
//return LAY_OTHER_DIM;
|
||
extern TCHAR* LAY_DRAWINGNAME_DIM;
|
||
::InitLayer(LAY_DRAWINGNAME_DIM);
|
||
return LAY_DRAWINGNAME_DIM;
|
||
}
|
||
|
||
|
||
int AecXDbDrawingName::ConvertText(TConvertTextPtr ptr, void *pData)
|
||
{
|
||
TCString sText;
|
||
int nRet = ptr(m_szNameText, sText, pData);
|
||
if (nRet == RTNORM)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_szNameText = sText;
|
||
}
|
||
return nRet;
|
||
}
|
||
|
||
BOOL AecXDbDrawingName::GetText(int i, AecXDbText&text)const
|
||
{
|
||
if ((m_bShowScale && i >= 2) || (!m_bShowScale && i >= 1))
|
||
return FALSE;
|
||
|
||
SubText* pSubText = GetSubText(i);
|
||
if (pSubText == NULL)
|
||
return FALSE;
|
||
|
||
if (pSubText->GetTextEntity() == NULL)
|
||
{
|
||
delete pSubText;
|
||
return FALSE;
|
||
}
|
||
|
||
text.copyFrom(pSubText->GetTextEntity());
|
||
delete pSubText;
|
||
return TRUE;
|
||
}
|
||
|
||
// 返回发现的位置,同时posStart往前移动(以便继续找下一个使用),
|
||
TextPosition
|
||
AecXDbDrawingName::FindSubText(const TCHAR *sSubText, TextPosition &posStart, TextRange *pRange) const
|
||
{
|
||
TextPosition pos;
|
||
if (!sSubText || !sSubText[0])
|
||
return pos;
|
||
|
||
TextPosition posNext = posStart;
|
||
while (1)
|
||
{
|
||
AecXDbText text;
|
||
text.SetPScale(GetPScale());
|
||
if (!GetText(posNext.m_nCookies, text))
|
||
break;
|
||
|
||
TextPosition posFind = text.FindSubText(sSubText, posNext, pRange);
|
||
if (!posFind)
|
||
{
|
||
posNext.m_nCookies++;
|
||
posNext.m_nTextPos = 0;
|
||
}
|
||
else
|
||
{
|
||
posStart = posNext;
|
||
if (!posStart)
|
||
{
|
||
posStart.m_nCookies++;
|
||
posStart.m_nTextPos = 0;
|
||
}
|
||
posFind.m_nCookies = posNext.m_nCookies;
|
||
pos = posFind;
|
||
break;
|
||
}
|
||
}
|
||
return pos;
|
||
}
|
||
|
||
// 返回下一次查找的开始位置
|
||
TextPosition
|
||
AecXDbDrawingName::ReplaceSubText(const TextPosition &posRep, const TCHAR *sRepText, TextRange *pRange)
|
||
{
|
||
AssertWriteEnabled();
|
||
TextPosition posNext;
|
||
AecXDbText text;
|
||
text.SetPScale(GetPScale());
|
||
if (!GetText(posRep.m_nCookies, text))
|
||
return posNext;
|
||
posNext = text.ReplaceSubText(posRep, sRepText, pRange);
|
||
|
||
int cookies = posRep.m_nCookies;
|
||
if (cookies == 0)
|
||
{
|
||
m_szNameText = text.GetText();
|
||
}
|
||
else if (cookies == 1)
|
||
{
|
||
m_szScaleText = text.GetText();
|
||
}
|
||
|
||
if (!posNext)
|
||
{
|
||
if (posNext.m_nCookies < (Adesk::UInt32)(GetSubTextNum() - 1))
|
||
{
|
||
posNext.m_nCookies = posRep.m_nCookies + 1;
|
||
posNext.m_nTextPos = 0;
|
||
}
|
||
}
|
||
return posNext;
|
||
}
|
||
|
||
void AecXDbDrawingName::SetSubText(long i, CString sText)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (i == 0)
|
||
m_szNameText = sText;
|
||
else
|
||
m_szScaleText = sText;
|
||
}
|
||
|
||
// 设置区域轮廓
|
||
void AecXDbDrawingName::SetRegionPoly(const AcGePoint3dArray& arPts)
|
||
{
|
||
AssertWriteEnabled();
|
||
// 将数据保存到AecDbObjXDataMap中
|
||
AecDbObjXDataMap* pXData = __GetSpecialtyData();
|
||
if (NULL != pXData)
|
||
{
|
||
pXData->RemoveAt(DRAWINGNAME_REGIONPL);
|
||
pXData->SetAt(DRAWINGNAME_REGIONPL, arPts);
|
||
}
|
||
}
|
||
|
||
// 取得区域Poly
|
||
BOOL AecXDbDrawingName::GetRegionPoly(GePoly2D* pPoly) const
|
||
{
|
||
assertReadEnabled();
|
||
AecDbObjXDataMap* pXData = __GetSpecialtyDataReadOnly();
|
||
if (NULL == pXData)
|
||
return FALSE;
|
||
|
||
AcGePoint3dArray arPts;
|
||
if (!pXData->GetAt(DRAWINGNAME_REGIONPL, arPts))
|
||
return FALSE;
|
||
|
||
int nLen = arPts.length();
|
||
if (2 >= nLen)
|
||
return FALSE;
|
||
|
||
if (NULL != pPoly)
|
||
{
|
||
pPoly->Reset();
|
||
for (int i = 0; i < arPts.length(); i++)
|
||
{
|
||
pPoly->AppendNode(arPts[i]);
|
||
}
|
||
pPoly->SetFlag(1); // 闭合
|
||
}
|
||
|
||
return TRUE;
|
||
}
|