4432 lines
122 KiB
C++
4432 lines
122 KiB
C++
#include "stdafx.h"
|
||
#include "PushProperty.h"
|
||
#include "AecDbDimension.h"
|
||
#include "AecDbDimension_old.h"
|
||
#include "AecDbText.h"
|
||
#include "globalFunc.h"
|
||
#include "AcDbObjectPtr.h"
|
||
#include "superlist.h"
|
||
#include "gecurveinline.h"
|
||
#include "ADSgepointdir2d.h"
|
||
#include "SortedVertexList.h"
|
||
#include "PushMemVar.h"
|
||
#include "DimTextPos.h"
|
||
#include "DimTextContent.h"
|
||
|
||
extern AcDbObjectId InitDimStyle(TDimStyle ds);
|
||
|
||
#pragma region XDimAutoAdjust
|
||
class XDimAutoAdjust
|
||
{
|
||
public:
|
||
XDimAutoAdjust() {}
|
||
|
||
protected:
|
||
typedef struct dimTextInfo
|
||
{
|
||
// 文字测量值
|
||
double dDimText;
|
||
// Y方向文字位置,0外偏;1、2、3...原位、上调;-1、-2、-3...下调
|
||
int nYLoc;
|
||
// X方向文字包围盒位置,全部投影到尺寸标注中的GetDimCurve上
|
||
double dSLoc;
|
||
double dELoc;
|
||
// 文字包围框的X值大小
|
||
double dX;
|
||
}SDimInfo;
|
||
|
||
typedef struct rowInfo
|
||
{
|
||
// 当前排号,1、2、3...原位、上调;-1、-2、-3...下调
|
||
int nY;
|
||
// 当前排号下,最后一个编号
|
||
int nIndex;
|
||
}SRow;
|
||
|
||
public:
|
||
// 设置标注的基本通用信息
|
||
void SetDimParam(GeCurveSegment seg, AcDbObjectId idStyle, double dHeight, double dLayoutRotation);
|
||
|
||
// 向数组中添加标注信息段
|
||
void AppendDim(const TCHAR* pszDimText, const TCHAR* pszText, ADSGePoint3d pt);
|
||
|
||
// 进行自动调整
|
||
void AutoAdjust(BOOL bUp, BOOL bAllowExt);
|
||
|
||
// 获得某一段最后Y方向的偏移位置
|
||
int GetYLoc(int nIndex) const;
|
||
// 获得文字包围盒的X方向大小
|
||
double GetXDist(int nIndex) const;
|
||
|
||
//默认是一个文字宽度1.0
|
||
void SetDispSnap(double dScale = 1.0);
|
||
|
||
protected:
|
||
// 单独处理第1段和最后一段的外偏情况
|
||
void DealFirstAndLastDim(BOOL bAllowExt);
|
||
int RecursionUpDownAdjust(int nIndex, BOOL bUp, BOOL bAllowExt);
|
||
|
||
void GetDimPathDist(ADSGePoint3d pt, ADSGePointDir2d &ptDir) const;
|
||
double ChangeToNormalViewAngle(double dAngWcs) const;
|
||
|
||
int GetRowMaxIndex(int nY) const;
|
||
void AppendRow(int nY, int nIndexNum);
|
||
|
||
protected:
|
||
// 将每一个尺寸标注对象拆分保存成一个一个SDimInfo
|
||
CArray<SDimInfo, SDimInfo&> m_arDimInfo;
|
||
// 将每排的情况列到一个数组中
|
||
CArray<SRow, SRow&> m_arRows;
|
||
|
||
private:
|
||
GeCurveSegment m_segDim;
|
||
AcDbObjectId m_idTextStyle;
|
||
double m_dTextHeight;
|
||
double m_dLayoutRotation;
|
||
double m_d_DIST_SNAP;//判断文字重合间隙
|
||
};
|
||
|
||
void XDimAutoAdjust::SetDimParam(GeCurveSegment seg, AcDbObjectId idStyle, double dHeight, double dLayoutRotation)
|
||
{
|
||
m_segDim = seg;
|
||
m_idTextStyle = idStyle;
|
||
m_dTextHeight = dHeight;
|
||
m_dLayoutRotation = dLayoutRotation;
|
||
}
|
||
|
||
void XDimAutoAdjust::SetDispSnap(double dSnap)
|
||
{
|
||
AecXDbText text;
|
||
text.SetText(_T("5"));
|
||
text.SetStyleId(m_idTextStyle);
|
||
text.SetHeight(m_dTextHeight, FALSE);
|
||
text.SetAlignment(AcGiDraw::kBottomLeft);
|
||
|
||
ADSGePoint3d ptTextExt = text.GetExtents(); // 文字轮廓
|
||
m_d_DIST_SNAP = ptTextExt.x * dSnap;
|
||
}
|
||
|
||
int XDimAutoAdjust::GetYLoc(int nIndex) const
|
||
{
|
||
return m_arDimInfo[nIndex].nYLoc;
|
||
}
|
||
|
||
double XDimAutoAdjust::GetXDist(int nIndex) const
|
||
{
|
||
return m_arDimInfo[nIndex].dX;
|
||
}
|
||
|
||
void XDimAutoAdjust::AppendDim(const TCHAR* pszDimText, const TCHAR* pszText, ADSGePoint3d pt)
|
||
{
|
||
SDimInfo dim;
|
||
dim.nYLoc = 1;
|
||
dim.dDimText = _tstof(pszDimText);
|
||
|
||
ADSGePointDir2d ptDir;
|
||
GetDimPathDist(pt, ptDir);
|
||
|
||
AecXDbText text;
|
||
text.SetText(pszText);
|
||
text.SetStyleId(m_idTextStyle);
|
||
text.SetHeight(m_dTextHeight, FALSE);
|
||
text.SetAlignment(AcGiDraw::kBottomLeft);
|
||
|
||
ADSGePoint3d ptTextExt = text.GetExtents(), // 文字轮廓
|
||
pt1, pt2;
|
||
double dTextRot = ChangeToNormalViewAngle(ptDir.nDirection); // 文字角度
|
||
ads_polar(pt, dTextRot, ptTextExt.x / 2, pt1);
|
||
ads_polar(pt1, dTextRot + PI, ptTextExt.x, pt2);
|
||
|
||
double dDist1 = m_segDim.PathDistance(pt1, 1), // 都是相对m_segDim的起点的
|
||
dDist2 = m_segDim.PathDistance(pt2, 1);
|
||
dim.dSLoc = (dDist1 > dDist2 + g_Option::instance()._DIST_SNAP) ? dDist2 : dDist1; // 较小的作为起点
|
||
dim.dELoc = (dDist1 > dDist2 + g_Option::instance()._DIST_SNAP) ? dDist1 : dDist2; // 较大的作为终点
|
||
dim.dX = ptTextExt.x;
|
||
|
||
m_arDimInfo.Add(dim);
|
||
}
|
||
|
||
int XDimAutoAdjust::GetRowMaxIndex(int nY) const
|
||
{
|
||
int nRows = (int)m_arRows.GetSize();
|
||
for (int i = 0; i < nRows; i++)
|
||
{
|
||
if (m_arRows[i].nY == nY)
|
||
return m_arRows[i].nIndex;
|
||
}
|
||
return -1;
|
||
}
|
||
|
||
void XDimAutoAdjust::AppendRow(int nY, int nIndexNum)
|
||
{
|
||
int nRows = (int)m_arRows.GetSize();
|
||
for (int i = 0; i < nRows; i++)
|
||
{
|
||
if (m_arRows[i].nY == nY)
|
||
{
|
||
m_arRows[i].nIndex = nIndexNum;
|
||
return;
|
||
}
|
||
}
|
||
|
||
SRow row;
|
||
row.nIndex = nIndexNum;
|
||
row.nY = nY;
|
||
m_arRows.Add(row);
|
||
}
|
||
|
||
int XDimAutoAdjust::RecursionUpDownAdjust(int nIndex, BOOL bUp, BOOL bAllowExt)
|
||
{
|
||
int nCurY = m_arDimInfo[nIndex].nYLoc,
|
||
nMax(0), nPrev(0), nNextY(0);
|
||
while (1) // 将nIndex从1排开始,一排一排比较后,上移或者下移,尝试确定位置
|
||
{
|
||
nMax = GetRowMaxIndex(nCurY); // 得到“当前排”最大的一个索引号
|
||
nPrev = (nMax == -1) ? (nIndex - 1) : nMax;
|
||
|
||
if (nPrev < 0 || nPrev == nIndex || m_arDimInfo[nPrev].nYLoc != nCurY)
|
||
{
|
||
AppendRow(nCurY, nIndex);
|
||
return -1; // 没有引起其他段变化
|
||
}
|
||
|
||
if (nPrev > nIndex)
|
||
break;
|
||
|
||
if (m_arDimInfo[nIndex].dSLoc < m_arDimInfo[nPrev].dELoc + m_d_DIST_SNAP) // 有重合,要调整文字
|
||
{
|
||
nNextY = bUp ? (nCurY + 1) : (nCurY - 1);
|
||
nNextY = (nNextY == 0) ? -1 : nNextY;
|
||
|
||
if (m_arDimInfo[nIndex].dDimText > m_arDimInfo[nPrev].dDimText + m_d_DIST_SNAP) // 当前数字大于前一个数字
|
||
{
|
||
if (nIndex == 0 && bAllowExt) // 允许外偏
|
||
break;
|
||
|
||
m_arDimInfo[nPrev].nYLoc = nNextY;
|
||
AppendRow(nCurY, nIndex);
|
||
break;
|
||
}
|
||
else // 当前数字小于、等于前一个数字
|
||
{
|
||
if (nPrev == 0 && bAllowExt) // 允许外偏
|
||
{
|
||
AppendRow(nCurY, nIndex);
|
||
break;
|
||
}
|
||
|
||
m_arDimInfo[nIndex].nYLoc = nNextY;
|
||
nCurY = nNextY;
|
||
continue;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
AppendRow(nCurY, nIndex);
|
||
return -1;
|
||
}
|
||
}
|
||
return nPrev;
|
||
}
|
||
|
||
void XDimAutoAdjust::AutoAdjust(BOOL bUp, BOOL bAllowExt)
|
||
{
|
||
int nSize = (int)m_arDimInfo.GetSize(),
|
||
nCur(0), nMax(0), nPrev(0), nInd(0), nCurY(0), nNextY(0), i(0);
|
||
|
||
int nUpY = 2, nDownY = -1;
|
||
nNextY = bUp ? nUpY : nDownY;
|
||
int nBackNextY = bUp ? nDownY : nUpY;
|
||
|
||
for (nCur = 2; nCur < nSize - 1; nCur++)
|
||
{
|
||
double dtttt = m_arDimInfo[nCur].dDimText;
|
||
double ddist = m_arDimInfo[nCur].dX;
|
||
|
||
nCurY = m_arDimInfo[nCur].nYLoc;
|
||
|
||
for (i = nCur - 1; i > 0; i--)
|
||
{
|
||
if (m_arDimInfo[nCur].nYLoc == m_arDimInfo[i].nYLoc)
|
||
{
|
||
nPrev = i;
|
||
break;
|
||
}
|
||
}
|
||
double ds = m_arDimInfo[nCur].dSLoc;
|
||
double de = m_arDimInfo[nPrev].dELoc;
|
||
if (m_arDimInfo[nCur].dSLoc < m_arDimInfo[nPrev].dELoc + m_d_DIST_SNAP) // 有重合,要调整文字
|
||
{
|
||
|
||
if (m_arDimInfo[nCur + 1].dSLoc < m_arDimInfo[nCur].dELoc + m_d_DIST_SNAP)
|
||
{//当前与前一个和后一个都重叠
|
||
|
||
|
||
if (nCur == nPrev + 1)
|
||
{
|
||
m_arDimInfo[nCur].nYLoc = nNextY;
|
||
}
|
||
else
|
||
{
|
||
m_arDimInfo[nCur].nYLoc = nBackNextY;
|
||
}
|
||
continue;
|
||
}
|
||
if (m_arDimInfo[nCur].dDimText > m_arDimInfo[nPrev].dDimText + m_d_DIST_SNAP) // 当前数字大于前一个数字
|
||
{
|
||
if (nCur == nPrev + 1)
|
||
{//相邻的两个文字作比较
|
||
m_arDimInfo[nPrev].nYLoc = nNextY;
|
||
if (m_arDimInfo[nPrev - 1].nYLoc == nNextY)
|
||
{//前一个文字上移时,先检查前一个的前一个是否也上移了。
|
||
if (m_arDimInfo[nPrev].dSLoc < m_arDimInfo[nPrev - 1].dELoc + m_d_DIST_SNAP)
|
||
{
|
||
//文字有交叉,直接放到对面位置上
|
||
m_arDimInfo[nPrev].nYLoc = nBackNextY;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{//非相邻做比较,说明相邻的已经move过位置了
|
||
m_arDimInfo[nPrev].nYLoc = nBackNextY;
|
||
}
|
||
|
||
}
|
||
else // 当前数字小于、等于前一个数字
|
||
{
|
||
if (nCur == nPrev + 1)
|
||
{
|
||
m_arDimInfo[nCur].nYLoc = nNextY;
|
||
if (m_arDimInfo[nPrev].nYLoc == nNextY)
|
||
{
|
||
if (m_arDimInfo[nCur].dSLoc < m_arDimInfo[nPrev].dELoc + m_d_DIST_SNAP)
|
||
{
|
||
//文字有交叉,直接放到对面位置上
|
||
m_arDimInfo[nCur].nYLoc = nBackNextY;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
m_arDimInfo[nCur].nYLoc = nBackNextY;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
DealFirstAndLastDim(bAllowExt);
|
||
}
|
||
|
||
// 单独处理第1段和最后一段的外偏情况
|
||
void XDimAutoAdjust::DealFirstAndLastDim(BOOL bAllowExt)
|
||
{
|
||
if (!bAllowExt) // 如果允许外偏,还要额外判断一下,是否查过了尺寸界线
|
||
{
|
||
return;
|
||
}
|
||
|
||
double ddd = m_arDimInfo[0].dSLoc;
|
||
double dsss = m_arDimInfo[0].dDimText;
|
||
|
||
if (m_arDimInfo[0].dSLoc < 1)
|
||
{
|
||
m_arDimInfo[0].nYLoc = 0;
|
||
}
|
||
|
||
int nSize = (int)m_arDimInfo.GetSize();
|
||
if (nSize > 1) // 有1段以上
|
||
{
|
||
if (m_arDimInfo[1].dSLoc < m_arDimInfo[0].dELoc)
|
||
{//如果第二个与第一个重合,则优先考虑侧移第一个
|
||
if (m_arDimInfo[1].nYLoc == m_arDimInfo[0].nYLoc)
|
||
{
|
||
m_arDimInfo[0].nYLoc = 0;
|
||
}
|
||
|
||
}
|
||
|
||
double ddde = m_arDimInfo[nSize - 1].dELoc;
|
||
double ddds = m_arDimInfo[nSize - 1].dSLoc;
|
||
double dsss = m_arDimInfo[nSize - 1].dDimText;
|
||
double dssss = m_segDim.GetLength();
|
||
if (m_arDimInfo[nSize - 1].dELoc > m_segDim.GetLength())
|
||
{
|
||
m_arDimInfo[nSize - 1].nYLoc = 0;
|
||
}
|
||
if (m_arDimInfo[nSize - 1].dSLoc < m_arDimInfo[nSize - 2].dELoc)
|
||
{//如果最后一个与倒数第二个重合,则优先考虑侧移最后一个
|
||
if (m_arDimInfo[nSize - 1].nYLoc == m_arDimInfo[nSize - 2].nYLoc)
|
||
{
|
||
m_arDimInfo[nSize - 1].nYLoc = 0;
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
double XDimAutoAdjust::ChangeToNormalViewAngle(double dAngWcs) const
|
||
{
|
||
double dAng = GlobalFunc::AngleRangeTo2PI(dAngWcs - m_dLayoutRotation),
|
||
dSnap = 1.0E-1,
|
||
dAng1 = GlobalFunc::AngleRangeTo2PI(dAng);//double dSnap = 1.0E-9, 9.0beta1
|
||
if (GlobalFunc::GreatThan(dAng1, PI / 2.0, dSnap) && GlobalFunc::LessThan(dAng1, PI, dSnap))
|
||
{
|
||
dAng1 += PI;
|
||
}
|
||
else if (GlobalFunc::GreatEqual(dAng1, PI, dSnap) && GlobalFunc::LessEqual(dAng1, PI * 1.5, dSnap))
|
||
{
|
||
dAng1 -= PI;
|
||
}
|
||
dAng = dAng1;
|
||
dAng = GlobalFunc::AngleRangeTo2PI(m_dLayoutRotation + dAng);
|
||
return dAng;
|
||
}
|
||
|
||
void XDimAutoAdjust::GetDimPathDist(ADSGePoint3d pt, ADSGePointDir2d &ptDir) const
|
||
{
|
||
double dPathDist = m_segDim.PathDistance(pt);
|
||
m_segDim.Polar(dPathDist, ptDir);
|
||
}
|
||
|
||
#pragma endregion
|
||
|
||
#pragma region AecDbDimension
|
||
/////////////////////////////////////////////////////////////
|
||
// 新尺寸对象类
|
||
/////////////////////////////////////////////////////////////
|
||
//TArch7-1,
|
||
const Adesk::UInt8 AecDbDimension::g_nVersion = 1;
|
||
|
||
|
||
ACRX_DXF_DEFINE_MEMBERS(AecDbDimension, AecXDbCurveBaseEx, AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
|
||
1, AEC_CHICUNBIAOZHU, "AEC_CHICUNBIAOZHU|缺乏上华解释器, 请下载上华软件|网址: www.shanghuasoft.com");
|
||
|
||
IMPLEMENT_EDITFUNC(AecDbDimension);
|
||
|
||
AecDbDimension::AecDbDimension()
|
||
{
|
||
m_nRotation = 0; //旋转角度
|
||
m_nDist2DimLine = 0; //定位点到尺寸线的距离, 可以为负值
|
||
m_nDimRadius = 0; //夹角,可以为负
|
||
m_nObjRadius = 0;
|
||
m_nDimFlag = g_Option::instance().g_bDynDim ? DF_ASSOCIATE : 0;
|
||
}
|
||
|
||
|
||
AecDbDimension::~AecDbDimension()
|
||
{
|
||
}
|
||
|
||
BOOL AecDbDimension::IsValid() const
|
||
{
|
||
//BOOL bRet = TDbCurveEntity::IsValid();
|
||
//if (!bRet)
|
||
// return bRet;
|
||
|
||
BOOL bRet = m_lstSegment.Length() >= 1;
|
||
return bRet;
|
||
}
|
||
|
||
BOOL AecDbDimension::IsValidSegment(double nVal, BOOL bDist) const
|
||
{
|
||
double nPrec = IsAngular() ? g_DimOption::instance()._angSnap : g_Option::instance()._DIST_SNAP;
|
||
if (IsAngular() && bDist) {
|
||
ASSERT(m_nDimRadius > g_Option::instance()._DIST_SNAP);
|
||
nVal = nVal / m_nDimRadius;
|
||
}
|
||
return (nVal > nPrec);
|
||
}
|
||
|
||
void AecDbDimension::CopyPropertiesFrom(AcDbEntity *pSrcEntity, unsigned gMatchFlag)
|
||
{
|
||
AssertWriteEnabled();
|
||
double nOldScale = GetPScale();
|
||
double nDimDist = GetDist2DimLine(FALSE);
|
||
AecXDbCurveBaseEx::CopyPropertiesFrom(pSrcEntity, gMatchFlag);
|
||
AecDbDimension *pSrc = AecDbDimension::cast(pSrcEntity);
|
||
if (pSrc) {
|
||
if (database() == NULL ||
|
||
pSrcEntity->database() == NULL ||
|
||
database() == pSrcEntity->database())//add by whl on 060317
|
||
{
|
||
m_idDimStyle = pSrc->m_idDimStyle; //尺寸标注类型
|
||
}
|
||
UseDimStyleScale(pSrc->IsUseDimStyleScale());
|
||
}
|
||
double nNewScale = GetPScale();
|
||
if (fabs(nNewScale - nOldScale) > 1.0E-3 && IsAngular()) {
|
||
SetDist2DimLine(nDimDist, FALSE);
|
||
}
|
||
}
|
||
//Acad::ErrorStatus
|
||
//AecDbDimension::subGetClassID(CLSID* pClsid) const
|
||
//{
|
||
// *pClsid = CLSID_ComDimension;
|
||
// return Acad::eOk;
|
||
//}
|
||
|
||
namespace
|
||
{
|
||
void drawProxyEntity(const AcDbVoidPtrArray *pAr, AcGiWorldDraw *pWd)
|
||
{
|
||
if (!pAr) return;
|
||
Adesk::UInt16 clr = pWd->subEntityTraits().color();
|
||
AcDbObjectId layerID = pWd->subEntityTraits().layerId();
|
||
for (int i = 0; i < pAr->length(); ++i)
|
||
{
|
||
AcDbEntity *pEnt((AcDbEntity *)pAr->at(i));
|
||
if (pEnt->isKindOf(AcDbDimension::desc()))
|
||
{
|
||
int a = 0;
|
||
}
|
||
pWd->subEntityTraits().setColor(pEnt->colorIndex());
|
||
pWd->subEntityTraits().setLayer(pEnt->layerId());
|
||
pEnt->worldDraw(pWd);
|
||
}
|
||
pWd->subEntityTraits().setColor(clr);
|
||
pWd->subEntityTraits().setLayer(layerID);
|
||
}
|
||
}
|
||
|
||
// 从DWG读入数据:
|
||
Acad::ErrorStatus AecDbDimension::dwgInFields(AcDbDwgFiler* pFiler)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
Acad::ErrorStatus es = AecXDbCurveBaseEx::dwgInFields(pFiler);
|
||
if (es != Acad::eOk) return es;
|
||
Adesk::UInt8 nVer;
|
||
pFiler->readItem(&nVer);
|
||
if (nVer > g_nVersion) {// Version is too new
|
||
return Acad::eMakeMeProxy;
|
||
}
|
||
|
||
pFiler->readItem((AcGePoint3d *)&m_ptLocation); //定位点--即不动点
|
||
m_ptLocation.z = 0; //必须是二维
|
||
pFiler->readItem(&m_nRotation); //旋转角度
|
||
pFiler->readItem(&m_nDist2DimLine); //定位点到尺寸线的距离, 可以为负值
|
||
pFiler->readItem(&m_idDimStyle); //尺寸标注类型
|
||
m_lstSegment.Reset();
|
||
Adesk::UInt16 nSeg = 0;
|
||
pFiler->readItem(&nSeg);
|
||
for (Adesk::UInt16 i = 0; i < nSeg; i++) {
|
||
double nVal = 0;
|
||
pFiler->readItem(&nVal);
|
||
m_lstSegment.Append(new double(nVal));
|
||
}
|
||
|
||
pFiler->readItem(&m_nDimFlag);
|
||
|
||
|
||
m_lstTextPos.Reset();
|
||
if (m_nDimFlag & DF_POSITION) {
|
||
m_lstTextPos.Reset();
|
||
Adesk::UInt16 nTextSeg = 0;
|
||
pFiler->readItem(&nTextSeg);
|
||
for (i = 0; i < nTextSeg; i++) {
|
||
AcGePoint2d ptPos;
|
||
Adesk::UInt16 nIndex;
|
||
pFiler->readItem(&nIndex);
|
||
pFiler->readItem(&ptPos);
|
||
m_lstTextPos.Append(new DimTextPos(nIndex, ADSGePoint3d(ptPos[0], ptPos[1])));
|
||
}
|
||
}
|
||
|
||
m_lstTextContent.Reset();
|
||
if (m_nDimFlag & DF_TEXT) {
|
||
Adesk::UInt16 nTextSeg = 0;
|
||
pFiler->readItem(&nTextSeg);
|
||
for (i = 0; i < nTextSeg; i++) {
|
||
TCString sText;
|
||
Adesk::UInt16 nIndex;
|
||
pFiler->readItem(&nIndex);
|
||
GlobalFunc::ReadString(pFiler, sText);
|
||
m_lstTextContent.Append(new DimTextContent(nIndex, sText));
|
||
}
|
||
}
|
||
if (m_nDimFlag & DF_BIND)
|
||
pFiler->readItem(&m_idBind);
|
||
|
||
if (IsAngular()) {
|
||
pFiler->readItem(&m_nDimRadius);
|
||
pFiler->readItem(&m_nObjRadius);
|
||
}
|
||
|
||
m_lstOffset.Reset();
|
||
if (m_nDimFlag & DF_ASSOCIATE)
|
||
{
|
||
Adesk::UInt16 nSeg = 0;
|
||
pFiler->readItem(&nSeg);
|
||
for (Adesk::UInt16 i = 0; i < nSeg; i++)
|
||
{
|
||
double nVal = 0;
|
||
pFiler->readItem(&nVal);
|
||
m_lstOffset.Append(new double(nVal));
|
||
}
|
||
}
|
||
return pFiler->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbDimension::dwgOutFields(AcDbDwgFiler* pFiler) const
|
||
{
|
||
assertReadEnabled();
|
||
Acad::ErrorStatus es = AecXDbCurveBaseEx::dwgOutFields(pFiler);
|
||
if (es != Acad::eOk) return es;
|
||
|
||
pFiler->writeItem(g_nVersion);
|
||
|
||
pFiler->writeItem((const AcGePoint3d &)m_ptLocation); //定位点--即不动点
|
||
pFiler->writeItem(m_nRotation); //旋转角度
|
||
pFiler->writeItem(m_nDist2DimLine); //定位点到尺寸线的距离, 可以为负值
|
||
pFiler->writeItem(m_idDimStyle); //尺寸标注类型
|
||
Adesk::UInt16 nSeg = m_lstSegment.Length();
|
||
pFiler->writeItem(nSeg);
|
||
for (Adesk::UInt16 i = 0; i < nSeg; i++) {
|
||
double nVal = m_lstSegment[i];
|
||
pFiler->writeItem(nVal);
|
||
}
|
||
|
||
pFiler->writeItem(m_nDimFlag);
|
||
if (m_nDimFlag & DF_POSITION) {
|
||
Adesk::UInt16 nTextSeg = m_lstTextPos.Length();
|
||
pFiler->writeItem(nTextSeg);
|
||
for (i = 0; i < nTextSeg; i++) {
|
||
const DimTextPos &pTextPos = m_lstTextPos[i];
|
||
pFiler->writeItem(pTextPos.nIndex);
|
||
pFiler->writeItem((const AcGePoint2d &)pTextPos.ptPos);
|
||
}
|
||
}
|
||
if (m_nDimFlag & DF_TEXT) {
|
||
Adesk::UInt16 nTextSeg = m_lstTextContent.Length();
|
||
pFiler->writeItem(nTextSeg);
|
||
for (i = 0; i < nTextSeg; i++) {
|
||
const DimTextContent &text = m_lstTextContent[i];
|
||
pFiler->writeItem(text.nIndex);
|
||
pFiler->writeString(text.sText);
|
||
}
|
||
}
|
||
if (IsBind()) {
|
||
pFiler->writeItem(m_idBind);
|
||
}
|
||
|
||
if (IsAngular()) {
|
||
pFiler->writeItem(m_nDimRadius); //夹角,可以为负
|
||
pFiler->writeItem(m_nObjRadius);
|
||
}
|
||
|
||
if (IsAssociate())
|
||
{
|
||
Adesk::UInt16 nSeg = m_lstOffset.Length();
|
||
pFiler->writeItem(nSeg);
|
||
for (Adesk::UInt16 i = 0; i < nSeg; i++)
|
||
{
|
||
double nVal = m_lstOffset[i];
|
||
pFiler->writeItem(nVal);
|
||
}
|
||
}
|
||
|
||
return pFiler->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbDimension::dxfInFields(AcDbDxfFiler* pFiler)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
Acad::ErrorStatus es = AecXDbCurveBaseEx::dxfInFields(pFiler);
|
||
if (es != Acad::eOk)
|
||
return es;
|
||
|
||
if (!pFiler->atSubclassData(_T("AecDbDimension"))) {
|
||
return Acad::eBadDxfSequence;
|
||
}
|
||
|
||
return pFiler->filerStatus();
|
||
|
||
// 不读入任何数据
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbDimension::dxfOutFields(AcDbDxfFiler* pFiler) const
|
||
{
|
||
assertReadEnabled();
|
||
Acad::ErrorStatus es = AecXDbCurveBaseEx::dxfOutFields(pFiler);
|
||
assert(es == Acad::eOk);
|
||
|
||
es = pFiler->writeItem(AcDb::kDxfSubclass, _T("AecDbDimension"));
|
||
assert(es == Acad::eOk);
|
||
|
||
|
||
return es;
|
||
}
|
||
|
||
|
||
|
||
// -----------------------------------------------------------------------
|
||
|
||
Acad::ErrorStatus
|
||
AecDbDimension::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::eOk;
|
||
|
||
switch (osnapMode) {
|
||
case AcDb::kOsModeNode:
|
||
case AcDb::kOsModeIns: {
|
||
double nOffDist = m_nDist2DimLine * GetPScale();
|
||
GeCurveSegment cv = GetDimCurve();
|
||
GeCurveSegment cvFix = cv.Offset(nOffDist, LS_FINITE);
|
||
GePoly2D poly;
|
||
GetPolySegOnDimLine(poly);
|
||
|
||
if (osnapMode == AcDb::kOsModeNode) {
|
||
int nVertNum = poly.Length();
|
||
for (int i = 0; i < nVertNum; i++) {
|
||
ADSGePoint3d ptFix;
|
||
cvFix.ProjectToMe(*poly[i], ptFix);
|
||
snapPoints.append(*poly[i]);
|
||
snapPoints.append(ptFix);
|
||
}
|
||
}
|
||
else {
|
||
int nSeg = poly.TotalSegments();
|
||
for (int i = 0; i < nSeg; i++) {
|
||
ADSGePoint3d ptText = GetTextPos(i);
|
||
snapPoints.append(ptText);
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
default: {
|
||
//PushMemVar<BOOL> vTemp(g_bExplAcadDim, FALSE);
|
||
AecXDbCurveBaseEx::subGetOsnapPoints(osnapMode
|
||
, gsSelectionMark
|
||
, pickPoint
|
||
, lastPoint
|
||
, viewXform
|
||
, snapPoints
|
||
, geomIds);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
return es;
|
||
}
|
||
|
||
// Overriden functions for edit
|
||
// to do:
|
||
// 允许通过夹点改变边界
|
||
Acad::ErrorStatus AecDbDimension::subGetGripPoints(AcGePoint3dArray& gripPoints,
|
||
AcDbIntArray& osnapModes,
|
||
AcDbIntArray& geomIds) const
|
||
{
|
||
assertReadEnabled();
|
||
double nOffDist = m_nDist2DimLine * GetPScale();
|
||
GeCurveSegment cv = GetDimCurve();
|
||
GeCurveSegment cvFix = cv.Offset(nOffDist, LS_FINITE);
|
||
GeCurveSegment cvObj;
|
||
if (IsAngular()) {
|
||
double nDist2Obj = cv.GetArc().GetRadius() - m_nObjRadius;
|
||
cvObj = cv.Offset(-nDist2Obj, LS_FINITE);
|
||
}
|
||
GePoly2D poly;
|
||
GetPolySegOnDimLine(poly);
|
||
|
||
int nVertNum = poly.Length();
|
||
gripPoints.append(*poly.Head()); //0
|
||
gripPoints.append(*poly.Tail()); //1
|
||
|
||
for (int i = 0; i < nVertNum; i++)
|
||
{
|
||
ADSGePoint3d ptFix;
|
||
if (IsAngular() && (IsDimChord() || IsDimArcLen()))
|
||
cvObj.ProjectToMe(*poly[i], ptFix);
|
||
else cvFix.ProjectToMe(*poly[i], ptFix);
|
||
gripPoints.append(ptFix);
|
||
}
|
||
|
||
|
||
int nSeg = poly.TotalSegments();
|
||
BOOL bIsDef = false;
|
||
for (i = 0; i < nSeg; i++)
|
||
{
|
||
ADSGePoint3d ptText = GetTextPos(i);
|
||
gripPoints.append(ptText);
|
||
}
|
||
|
||
|
||
if (IsAngular() && (IsDimChord() || IsDimArcLen()))
|
||
gripPoints.append(m_ptLocation);
|
||
else if (!IsAngular() && IsAssociate())
|
||
{
|
||
GeCurveSegment curve = GetDimCurve();
|
||
if (m_nDist2DimLine > 0)
|
||
curve = curve.Offset((m_nDist2DimLine + GetMaxScope()) * GetPScale(), 0);
|
||
else
|
||
curve = curve.Offset((m_nDist2DimLine - GetMaxScope()) * GetPScale(), 0);
|
||
|
||
gripPoints.append(curve.StartPoint());
|
||
gripPoints.append(curve.MidPoint());
|
||
gripPoints.append(curve.EndPoint());
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbDimension::subGetGripPoints(AcDbGripDataPtrArray & grips, const double curViewUnitSize, const int gripSize, const AcGeVector3d & curViewDir, const int bitflags) const
|
||
{
|
||
return Acad::eNotImplementedYet;
|
||
}
|
||
|
||
// stretch points is diffrent from grep points, with no midpoint included
|
||
Acad::ErrorStatus AecDbDimension::subGetStretchPoints(AcGePoint3dArray & stretchPoints) const
|
||
{
|
||
assertReadEnabled();
|
||
AcDbIntArray osnapModes;
|
||
AcDbIntArray geomIds;
|
||
|
||
return subGetGripPoints(stretchPoints, osnapModes, geomIds);
|
||
}
|
||
|
||
|
||
void AecDbDimension::UnionScale(double nScale)
|
||
{
|
||
AssertWriteEnabled();
|
||
AcGeMatrix3d mat;
|
||
mat.setToScaling(nScale);
|
||
m_ptLocation.TransformBy(mat);
|
||
for (int i = 0; i < m_lstTextPos.Length(); i++)
|
||
m_lstTextPos[i]->ptPos.TransformBy(mat);
|
||
|
||
for (i = 0; i < m_lstSegment.Length(); i++)
|
||
(*m_lstSegment[i]) *= nScale;
|
||
m_nDimRadius *= nScale;
|
||
m_nObjRadius *= nScale;
|
||
for (i = 0; i < m_lstOffset.Length(); i++)
|
||
(*m_lstOffset[i]) *= nScale;
|
||
}
|
||
// Active when being rotated, scaled, moved, etc.
|
||
// Scale is disabled here
|
||
Acad::ErrorStatus AecDbDimension::subTransformBy(const AcGeMatrix3d& xform)
|
||
{
|
||
AssertWriteEnabled();
|
||
AecXDbCurveBaseEx::subTransformBy(xform);
|
||
ads_matrix mat;
|
||
GlobalFunc::AsAdsMatrix(xform, mat);
|
||
for (int i = 0; i < m_lstTextPos.Length(); i++) {
|
||
m_lstTextPos[i]->ptPos.TransformBy(mat);
|
||
}
|
||
|
||
if (IsAngular()) {
|
||
GeCurveSegment cv = GetDimCurve();
|
||
cv.TransformBy(mat);
|
||
m_nRotation = cv.IDirection(0);
|
||
ads_polar(cv.StartPoint(), m_nRotation - PI / 2, GetDist2DimLine(FALSE), m_ptLocation);
|
||
if (GlobalFunc::IsMirrorMatrix(mat)) {
|
||
m_lstTextPos.Reverse();
|
||
m_lstTextContent.Reverse();
|
||
m_lstSegment.Reverse();
|
||
}
|
||
}
|
||
else {
|
||
m_ptLocation.TransformBy(mat);
|
||
m_ptLocation.z = 0;
|
||
Vector3D vt(cos(m_nRotation), sin(m_nRotation));
|
||
((AcGeVector3d &)vt).transformBy(xform);
|
||
m_nRotation = ads_angle(ADSGePoint3d(), vt);
|
||
|
||
if (GlobalFunc::IsMirrorMatrix(mat)) {
|
||
m_nDist2DimLine = -m_nDist2DimLine;
|
||
}
|
||
}
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
//设置尺寸线位置
|
||
BOOL AecDbDimension::SetDimLinePos(ADSGePoint3d pt)
|
||
{
|
||
AssertWriteEnabled();
|
||
BOOL bRet = FALSE;
|
||
GeCurveSegment seg = GetDimCurve();
|
||
ADSGePoint3d ptOnSeg;
|
||
if (seg.ProjectToMe(pt, ptOnSeg) == RTNORM) {
|
||
double nDistMove = pt.Distance2d(ptOnSeg);
|
||
int nSideLoc = seg.OnWhichSide(GetLocation());
|
||
int nSide = seg.OnWhichSide(pt);
|
||
double nDist2Dim = GetDist2DimLine(FALSE);
|
||
|
||
if (fabs(nDist2Dim) > 1.0E-6) {
|
||
double nFactor = nDist2Dim / fabs(nDist2Dim);
|
||
if (nSide != nSideLoc)
|
||
nDistMove *= nFactor;
|
||
else
|
||
nDistMove *= -nFactor;
|
||
}
|
||
else {
|
||
if (nSideLoc = OFFSET_LEFT) nDistMove = -nDistMove;
|
||
}
|
||
if (IsAngular()) {
|
||
nDist2Dim += nDistMove;
|
||
double nDistRad = GetDimRadius();
|
||
nDistRad -= nDistMove;
|
||
if (nDistRad > g_Option::instance()._DIST_SNAP) {
|
||
SetDimRadius(nDistRad);
|
||
SetDist2DimLine(nDist2Dim, FALSE);
|
||
}
|
||
}
|
||
else {
|
||
nDist2Dim += nDistMove;
|
||
SetDist2DimLine(nDist2Dim, FALSE);
|
||
}
|
||
bRet = TRUE;
|
||
}
|
||
|
||
return bRet;
|
||
}
|
||
|
||
//设置标注固定线位置
|
||
BOOL AecDbDimension::SetFixLinePos(ADSGePoint3d pt)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
GeCurveSegment seg = GetDimCurve();
|
||
double nOffDist = m_nDist2DimLine * GetPScale();
|
||
GeCurveSegment cvFix = seg.Offset(nOffDist, LS_FINITE);
|
||
double nDist = cvFix.GetDist2Me(pt);
|
||
|
||
GeCurveSegment cvNewFix = cvFix.Offset(nDist, LS_FINITE);
|
||
if (!cvNewFix)
|
||
return FALSE;
|
||
ADSGePoint3d ptNew = cvNewFix.NearPoint(m_ptLocation);
|
||
|
||
m_nDist2DimLine = (nOffDist + nDist) / GetPScale();
|
||
m_ptLocation = ptNew;
|
||
return TRUE;
|
||
|
||
}
|
||
|
||
// 功能: 夹点操作, 还没有完全考虑圆弧类型
|
||
Acad::ErrorStatus AecDbDimension::MoveGripPointsAt1(
|
||
const AcDbIntArray& indices,
|
||
const AcGeVector3d& offset)
|
||
{
|
||
AssertWriteEnabled();
|
||
AcGePoint3dArray gripPoints;
|
||
AcDbIntArray ar;
|
||
subGetGripPoints(gripPoints, ar, ar);
|
||
AcGeVector3d vtLocal(offset[0], offset[1], 0.0);
|
||
for (int i = 0; i < indices.length(); i++) {
|
||
int idx = indices[i];
|
||
gripPoints[idx] += vtLocal;
|
||
}
|
||
|
||
int nVertNum = m_lstSegment.Length() + 1;
|
||
GeCurveSegment cv = GetDimCurve();
|
||
cv.SetPoints(ADSGePoint3d(gripPoints[0]), ADSGePoint3d(gripPoints[1]));
|
||
ADSGePoint3d ptS, ptE;
|
||
ADSGePoint3d ptS1 = gripPoints[2], ptE1 = gripPoints[2 + nVertNum - 1];
|
||
if (cv.ProjectToMe(ptS1, ptS) == RTNORM &&
|
||
cv.ProjectToMe(ptE1, ptE) == RTNORM)
|
||
cv.SetPoints(ptS, ptE);
|
||
|
||
if (cv.GetLength() < g_Option::instance()._DIST_SNAP)
|
||
return Acad::eInvalidInput;
|
||
SortedVertexList lstVert(cv);
|
||
for (i = 1; i < nVertNum - 1; i++) {
|
||
ADSGePoint3d ptFix = gripPoints[2 + i];
|
||
ADSGePoint3d ptOnDim;
|
||
if (cv.ProjectToMe(ptFix, ptOnDim) == RTNORM) {
|
||
lstVert.Insert(ptOnDim);
|
||
}
|
||
}
|
||
GePoly2D poly;
|
||
lstVert.AsPoly2D(poly);
|
||
|
||
m_lstSegment.Reset();
|
||
int nSeg = poly.TotalSegments();
|
||
for (i = 0; i < nSeg; i++) {
|
||
GeCurveSegment seg;
|
||
poly.Nth(i, seg);
|
||
double nVal = seg.GetLength();
|
||
if (IsValidSegment(nVal))
|
||
AppendSegment(nVal);
|
||
}
|
||
|
||
if (IsAngular() && (IsDimChord() || IsDimArcLen())) {
|
||
m_nObjRadius = cv.GetArc().GetCenterPt().Distance2d(gripPoints[2]);
|
||
// Location???
|
||
GeLine ln(cv.StartPoint(), cv.IDirection(0) + PI / 2);
|
||
ADSGePoint3d ptNewLoc = m_ptLocation + ADSGePoint3d(offset[0], offset[1]);
|
||
ptNewLoc.Project(&ln, m_ptLocation);
|
||
m_ptLocation.z = 0;
|
||
}
|
||
else SetLocation(gripPoints[2]);
|
||
|
||
SetRotation(cv.IDirection(0));
|
||
double nDist2DimLine = m_ptLocation.Distance2d(cv.StartPoint());
|
||
int nSide = cv.OnWhichSide(m_ptLocation);
|
||
SetDist2DimLine(nSide == OFFSET_RIGHT ? nDist2DimLine : -nDist2DimLine, FALSE);
|
||
|
||
|
||
if (nSeg == nVertNum - 1) { //区间数目没有变化
|
||
for (i = 0; i < nSeg; i++) {
|
||
int nGripIndex = i + nVertNum + 2;
|
||
if (indices.contains(nGripIndex) && m_lstTextPos.FindNode(&i, DimTextPos::CompareByIndexForFind))
|
||
SetTextPos(i, gripPoints[nGripIndex]);
|
||
}
|
||
}
|
||
else {
|
||
m_lstTextPos.Reset();
|
||
m_lstTextContent.Reset();
|
||
}
|
||
AutoSetFlag();
|
||
|
||
return Acad::eOk;
|
||
}
|
||
|
||
|
||
// 功能: 夹点操作
|
||
// Modify on 2002/8/8 解决调用getGripPoints效率很低
|
||
Acad::ErrorStatus AecDbDimension::subMoveGripPointsAt(
|
||
const AcDbIntArray& indices,
|
||
const AcGeVector3d& offset)
|
||
{
|
||
if (indices.length() > 1)
|
||
return MoveGripPointsAt1(indices, offset);
|
||
|
||
AssertWriteEnabled();
|
||
|
||
ADSGePoint3d vtOffset = *(ADSGePoint3d *)&offset;
|
||
vtOffset.z = 0;
|
||
GePoly2D poly, polyNew;
|
||
GetPolySegOnDimLine(poly);
|
||
polyNew = poly;
|
||
GeCurveSegment cv = GetDimCurve();
|
||
double nOffDist = m_nDist2DimLine * GetPScale();
|
||
GeCurveSegment cvFix = cv.Offset(nOffDist, LS_FINITE);
|
||
GeCurveSegment cvObj;
|
||
if (IsAngular())
|
||
{
|
||
double nDist2Obj = cv.GetArc().GetRadius() - m_nObjRadius;
|
||
cvObj = cv.Offset(-nDist2Obj, LS_FINITE);
|
||
}
|
||
|
||
for (int i = 0; i < indices.length(); i++)
|
||
{
|
||
int idx = indices[i];
|
||
if (idx <= 1)
|
||
{ //改变尺寸线位置
|
||
ADSGePoint3d ptVert = idx == 0 ? *poly.Head() : *poly.Tail();
|
||
double nExtDir = idx == 0 ? cv.IDirection(0) : cv.IDirection(1);
|
||
GeLine lnExt(ptVert, nExtDir + PI / 2);
|
||
ADSGePoint3d ptOnExt = ptVert + vtOffset;
|
||
ADSGePoint3d(ptOnExt).Project(&lnExt, ptOnExt);
|
||
|
||
int nSide = cv.OnWhichSide(ptOnExt);
|
||
double nDistMove = ptVert.Distance2d(ptOnExt);
|
||
|
||
double nOldDist2DimLine = m_nDist2DimLine, nOldDimRadius = m_nDimRadius;
|
||
int nSideLoc = cv.OnWhichSide(m_ptLocation);
|
||
if (fabs(m_nDist2DimLine) > g_Option::instance()._DIST_SNAP / GetPScale())
|
||
{
|
||
double nFactor = m_nDist2DimLine / fabs(m_nDist2DimLine);
|
||
if (nSide != nSideLoc)
|
||
m_nDist2DimLine += nFactor * nDistMove / GetPScale();
|
||
else
|
||
m_nDist2DimLine -= nFactor * nDistMove / GetPScale();
|
||
}
|
||
else
|
||
{
|
||
if (nSideLoc == OFFSET_LEFT)
|
||
m_nDist2DimLine = -nDistMove / GetPScale();
|
||
}
|
||
if (IsAngular())
|
||
{
|
||
if (nSide == OFFSET_RIGHT)
|
||
m_nDimRadius += nDistMove;
|
||
else
|
||
m_nDimRadius -= nDistMove;
|
||
if (m_nDimRadius < g_Option::instance()._DIST_SNAP)
|
||
{
|
||
m_nDist2DimLine = nOldDist2DimLine;
|
||
m_nDimRadius = nOldDimRadius;
|
||
}
|
||
}
|
||
}
|
||
else if (idx < poly.Length() + 2)
|
||
{ //改变定位点或区间
|
||
int ndx = idx - 2;
|
||
ADSGePoint3d ptGrip, ptGrip0;
|
||
if (IsAngular() && (IsDimChord() || IsDimArcLen()))
|
||
cvObj.ProjectToMe(*poly[ndx], ptGrip);
|
||
else
|
||
cvFix.ProjectToMe(*poly[ndx], ptGrip);
|
||
|
||
int vtIdx = idx - 2;
|
||
ptGrip0 = ptGrip;
|
||
ptGrip += vtOffset;
|
||
if (!g_Option::instance().g_bStetchEntity && GetCtrlToggle())
|
||
{
|
||
if (!AddSegment(ptGrip) && GetSegmentNum() > 1)
|
||
FindAndRemoveSegment(ptGrip0);
|
||
}
|
||
else
|
||
{
|
||
ADSGePoint3d ptOnDim;
|
||
BOOL bGreatPrev = FALSE, bLessNext = FALSE;
|
||
if (cv.ProjectToMe(ptGrip, ptOnDim) == RTNORM)
|
||
{
|
||
if (vtIdx > 0)
|
||
{
|
||
double nPathDist = cv.PathDistance(ptOnDim); //小于0时,为圆弧标注
|
||
if (IsAngular() && nPathDist < -g_Option::instance()._DIST_SNAP)
|
||
{
|
||
if (vtIdx == polyNew.Length() - 1)
|
||
nPathDist = cv.GetArc().GeCircle::GetLength() + nPathDist;
|
||
}
|
||
double nPathDistPrev = cv.PathDistance(*polyNew[vtIdx - 1]);
|
||
bGreatPrev = (nPathDist - nPathDistPrev) > -g_Option::instance()._DIST_SNAP;
|
||
}
|
||
else
|
||
bGreatPrev = TRUE;
|
||
if (vtIdx < polyNew.Length() - 1)
|
||
bLessNext = (cv.PathDistance(ptOnDim) - cv.PathDistance(*polyNew[vtIdx + 1])) < g_Option::instance()._DIST_SNAP;
|
||
else bLessNext = TRUE;
|
||
if (bGreatPrev && bLessNext)
|
||
{
|
||
if (vtIdx == 0)
|
||
{
|
||
GeCurveSegment seg;
|
||
polyNew.Nth(0, seg);
|
||
seg.SetPoints(ptOnDim, seg.EndPoint());
|
||
if (IsAngular() && (IsDimChord() || IsDimArcLen()))
|
||
{
|
||
GeArc ar = seg.GetArc();
|
||
GeCircle cir(ar.GetCenterPt(), ads_distance(ar.GetCenterPt(), m_ptLocation));
|
||
ADSGePoint3d ptabc = m_ptLocation + vtOffset;
|
||
ptabc.Project(&cir, m_ptLocation);
|
||
m_nObjRadius = cir.GetCenterPt().Distance2d(ptGrip);
|
||
}
|
||
else
|
||
m_ptLocation += vtOffset;
|
||
|
||
if (IsValidSegment(seg.GetLength()))
|
||
{
|
||
m_nRotation = seg.IDirection(0);
|
||
SetSegment(0, seg.GetLength());
|
||
double nFactor = cv.OnWhichSide(m_ptLocation) == OFFSET_LEFT ? -1.0 : 1.0;
|
||
if (!(IsAngular() && (IsDimChord() || IsDimArcLen())))
|
||
SetDist2DimLine(m_ptLocation.Distance2d(ptOnDim) * nFactor, FALSE);
|
||
}
|
||
else
|
||
{
|
||
if (m_lstSegment.Length() > 1)
|
||
{
|
||
RemoveSegment(0);
|
||
polyNew.Nth(1, seg);
|
||
m_nRotation = seg.IDirection(0);
|
||
double nFactor = cv.OnWhichSide(m_ptLocation) == OFFSET_LEFT ? -1.0 : 1.0;
|
||
if (!(IsAngular() && (IsDimChord() || IsDimArcLen())))
|
||
SetDist2DimLine(m_ptLocation.Distance2d(ptOnDim) * nFactor, FALSE);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
BOOL bLast = (vtIdx == polyNew.Length() - 1);
|
||
GeCurveSegment seg, segPrev;
|
||
if (!bLast) polyNew.Nth(vtIdx, seg);
|
||
polyNew.Nth(vtIdx - 1, segPrev);
|
||
if (!bLast)
|
||
ASSERT(IsValidSegment(seg.GetLength()));
|
||
ASSERT(IsValidSegment(segPrev.GetLength()));
|
||
if (!bLast) seg.SetPoints(ptOnDim, ADSGePoint3d(seg.EndPoint()));
|
||
segPrev.SetPoints(ADSGePoint3d(segPrev.StartPoint()), ptOnDim);
|
||
if (!bLast)
|
||
{
|
||
if (!IsValidSegment(seg.GetLength()))
|
||
RemoveSegment(vtIdx);
|
||
else
|
||
SetSegment(vtIdx, seg.GetLength());
|
||
}
|
||
else
|
||
{
|
||
double nFactor = cv.OnWhichSide(ptGrip) == OFFSET_LEFT ? -1.0 : 1.0;
|
||
if (!(IsAngular() && (IsDimChord() || IsDimArcLen())))
|
||
SetDist2DimLine(ptGrip.Distance2d(ptOnDim) * nFactor, FALSE);
|
||
ads_polar(cv.StartPoint(), m_nRotation - PI / 2, GetDist2DimLine(FALSE), m_ptLocation);
|
||
if (IsAngular() && (IsDimChord() || IsDimArcLen()))
|
||
{
|
||
//改标注半径
|
||
GeArc arDim = cv.GetArc();
|
||
arDim.SetRadius(m_nObjRadius);
|
||
GeCurveSegment cvObj;
|
||
cvObj = arDim;
|
||
ADSGePoint3d ptGrip = cvObj.EndPoint();
|
||
ptGrip += vtOffset;
|
||
m_nObjRadius = ptGrip.Distance2d(arDim.GetCenterPt());
|
||
}
|
||
}
|
||
if (!IsValidSegment(segPrev.GetLength()))
|
||
{
|
||
if (m_lstSegment.Length() > 1)
|
||
RemoveSegment(vtIdx - 1);
|
||
}
|
||
else
|
||
SetSegment(vtIdx - 1, segPrev.GetLength());
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
int nSeg = idx - poly.Length() - 2;
|
||
if (nSeg < poly.TotalSegments())
|
||
{
|
||
ADSGePoint3d ptText = GetTextPos(nSeg);
|
||
ptText += vtOffset;
|
||
SetTextPos(nSeg, ptText);
|
||
}
|
||
else
|
||
{
|
||
if (IsAngular() && (IsDimChord() || IsDimArcLen()))
|
||
{
|
||
GeLine ln(cv.StartPoint(), cv.IDirection(0) + PI / 2);
|
||
ADSGePoint3d ptNewLoc = m_ptLocation + vtOffset;
|
||
ptNewLoc.Project(&ln, m_ptLocation);
|
||
int nSide = cv.OnWhichSide(ptNewLoc);
|
||
double nFactor = cv.OnWhichSide(ptNewLoc) == OFFSET_LEFT ? -1.0 : 1.0;
|
||
SetDist2DimLine(ptNewLoc.Distance2d(cv.StartPoint()) * nFactor, FALSE);
|
||
}
|
||
else if (!IsAngular() && IsAssociate())
|
||
{
|
||
ADSGePoint3d ptEnd;
|
||
ads_polar(m_ptLocation, m_nRotation, 1, ptEnd);
|
||
GeCurveSegment curve(m_ptLocation, ptEnd, 0);
|
||
|
||
ADSGePoint3d ptVert, pt;
|
||
AcGePoint3dArray grips;
|
||
AcDbIntArray osnapModes, geomIds;
|
||
subGetGripPoints(grips, osnapModes, geomIds);
|
||
pt = grips[indices[0]];
|
||
pt += vtOffset;
|
||
|
||
if (curve.ProjectToMe(pt, ptVert) == RTNORM)
|
||
{
|
||
double dist = ptVert.Distance2d(pt);
|
||
double nValue = dist / GetPScale();
|
||
if (nValue < 0.1)
|
||
return Acad::eInvalidInput;
|
||
|
||
if (m_lstOffset.Length() < 1)
|
||
m_lstOffset.Append(new double(nValue));
|
||
else
|
||
*m_lstOffset[0] = nValue;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//RemoveZeroSegment(); //把长度为0的区间移除
|
||
AutoSetFlag();
|
||
Acad::ErrorStatus es = Acad::eOk;
|
||
return es;
|
||
}
|
||
|
||
|
||
// 功能: 夹点操作
|
||
Acad::ErrorStatus AecDbDimension::subMoveStretchPointsAt(
|
||
const AcDbIntArray& indices,
|
||
const AcGeVector3d& offset)
|
||
{
|
||
int nCount = indices.length();
|
||
PushMemVar<BOOL> vTemp(g_Option::instance().g_bStetchEntity, TRUE);
|
||
return subMoveGripPointsAt(indices, offset);
|
||
}
|
||
|
||
// 取得夹点说明
|
||
Acad::ErrorStatus AecDbDimension::GetGripText(int i, CString &cs) const
|
||
{
|
||
Acad::ErrorStatus es = Acad::eOk;
|
||
GePoly2D poly;
|
||
GetPolySegOnDimLine(poly);
|
||
|
||
if (i <= 1)
|
||
cs = _T("移动尺寸线");
|
||
else if (i < poly.Length() + 2)
|
||
{
|
||
if (!GetCtrlToggle())
|
||
{
|
||
if (i == 2 || i == poly.Length() + 1)
|
||
{
|
||
if (IsAngular() && (IsDimChord() || IsDimArcLen()))
|
||
cs = _T("更改标注半径和开间(Ctrl-增补合并尺寸开间)");
|
||
else
|
||
cs = _T("移动定位点和更改开间(Ctrl-增补合并尺寸开间)");
|
||
}
|
||
else
|
||
cs = _T("更改合并尺寸开间(Ctrl-增补合并尺寸开间)");
|
||
}
|
||
else
|
||
{
|
||
if (i == 2 || i == poly.Length() + 1)
|
||
{
|
||
if (IsAngular() && (IsDimChord() || IsDimArcLen()))
|
||
cs = _T("增补合并尺寸开间(Ctrl-更改标注半径和开间)");
|
||
else
|
||
cs = _T("增补合并尺寸开间(Ctrl-移动定位点和更改开间)");
|
||
}
|
||
else
|
||
cs = _T("增补合并尺寸开间(Ctrl-更改合并尺寸开间)");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
int iVert = i - 2 - poly.Length();
|
||
if (iVert < poly.TotalSegments())
|
||
cs = _T("移动尺寸文本");
|
||
else
|
||
{
|
||
if (IsAngular() && (IsDimChord() || IsDimArcLen()))
|
||
cs = _T("改尺寸界线");
|
||
else if (!IsAngular() && IsAssociate())
|
||
{
|
||
cs = _T("改尺寸关联范围");
|
||
}
|
||
}
|
||
}
|
||
|
||
return es;
|
||
}
|
||
|
||
int AecDbDimension::ConvertText(TConvertTextPtr ptr, void *pData)
|
||
{
|
||
AssertWriteEnabled();
|
||
int nLen = m_lstTextContent.Length();
|
||
int nCode = RTNONE;
|
||
for (int i = 0; i < nLen; i++) {
|
||
DimTextContent *pContent = m_lstTextContent[i];
|
||
TCString sText;
|
||
int nRet = ptr(pContent->sText, sText, pData);
|
||
if (nRet == RTERROR)
|
||
nCode = nRet;
|
||
else if (nRet == RTNORM)
|
||
pContent->sText = sText;
|
||
}
|
||
return nCode;
|
||
}
|
||
|
||
|
||
// 返回发现的位置,同时posStart往前移动(以便继续找下一个使用),
|
||
TextPosition
|
||
AecDbDimension::FindSubText(const TCHAR *sSubText, TextPosition &posStart, TextRange *pRange) const
|
||
{
|
||
assertReadEnabled();
|
||
TextPosition pos;
|
||
if (!sSubText || !sSubText[0])
|
||
return pos;
|
||
|
||
AcDbObjectId idTextStyle;
|
||
double dimtxt = 3.0;
|
||
OPENOBJ_BEGIN(m_idDimStyle, AcDb::kForRead, AcDbDimStyleTableRecord, pStyle);
|
||
if (pStyle) {
|
||
idTextStyle = pStyle->dimtxsty();
|
||
dimtxt = pStyle->dimtxt();
|
||
}
|
||
OPENOBJ_END();
|
||
if (!idTextStyle)
|
||
return pos;
|
||
|
||
int nLen = GetSegmentNum(); //m_lstTextContent.Length();
|
||
int nCode = RTNONE;
|
||
TextPosition posNext = posStart;
|
||
for (int i = posStart.m_nCookies; i < nLen; i++) {
|
||
//DimTextContent content=m_lstTextContent[i];
|
||
TCString sTextDim = GetText(i);
|
||
AecXDbText dimText;
|
||
dimText.SetPScale(GetPScale());
|
||
dimText.setPropertiesFrom(this);
|
||
dimText.SetAlignment(AcGiDraw::kMiddleCenter);
|
||
dimText.SetHeight(dimtxt);
|
||
dimText.SetStyleId(idTextStyle);
|
||
dimText.SetText(sTextDim);
|
||
dimText.SetLocation(GetTextPos(i));
|
||
posNext.m_nCookies = i;
|
||
|
||
TextPosition posRet = dimText.FindSubText(sSubText, posNext, pRange);
|
||
if (!posRet) {
|
||
posNext.m_nTextPos = 0;
|
||
}
|
||
else {
|
||
posStart = posNext;
|
||
if (!posStart && (int)posStart.m_nCookies < nLen - 1) {
|
||
posStart.m_nCookies++;
|
||
posStart.m_nTextPos = 0;
|
||
}
|
||
posRet.m_nCookies = i;
|
||
return posRet;
|
||
}
|
||
}
|
||
return pos;
|
||
}
|
||
|
||
// 返回下一次查找的开始位置
|
||
TextPosition
|
||
AecDbDimension::ReplaceSubText(const TextPosition &posRep, const TCHAR *sRepText, TextRange *pRange)
|
||
{
|
||
AssertWriteEnabled();
|
||
TextPosition pos;
|
||
pos.m_nBufLen = _tcslen(sRepText);
|
||
pos.m_nCookies = posRep.m_nCookies;
|
||
if (!posRep || (int)posRep.m_nCookies >= GetSegmentNum())
|
||
return pos;
|
||
|
||
AcDbObjectId idTextStyle;
|
||
double dimtxt = 3.0;
|
||
OPENOBJ_BEGIN(m_idDimStyle, AcDb::kForRead, AcDbDimStyleTableRecord, pStyle);
|
||
if (pStyle) {
|
||
idTextStyle = pStyle->dimtxsty();
|
||
dimtxt = pStyle->dimtxt();
|
||
}
|
||
OPENOBJ_END();
|
||
if (!idTextStyle)
|
||
return pos;
|
||
|
||
//DimTextContent *pContent=m_lstTextContent[posRep.m_nCookies];
|
||
TCString sTextDim = GetText(posRep.m_nCookies);
|
||
AecXDbText dimText;
|
||
dimText.SetPScale(GetPScale());
|
||
dimText.setPropertiesFrom(this);
|
||
dimText.SetAlignment(AcGiDraw::kMiddleCenter);
|
||
dimText.SetHeight(dimtxt);
|
||
dimText.SetStyleId(idTextStyle);
|
||
dimText.SetText(sTextDim);
|
||
dimText.SetLocation(GetTextPos(posRep.m_nCookies));
|
||
|
||
TextPosition posRet = dimText.ReplaceSubText(posRep, sRepText, pRange);
|
||
SetTextContent(posRep.m_nCookies, dimText.GetText());
|
||
if (!posRet) {
|
||
if ((int)posRet.m_nCookies < GetSegmentNum() - 1) {
|
||
posRet.m_nCookies = posRep.m_nCookies + 1;
|
||
posRet.m_nTextPos = 0;
|
||
}
|
||
}
|
||
return posRet;
|
||
}
|
||
|
||
Adesk::UInt32
|
||
AecDbDimension::subSetAttributes(AcGiDrawableTraits * traits)
|
||
{
|
||
Adesk::UInt32 nRet = AecXDbCurveBaseEx::subSetAttributes(traits);
|
||
//if(g_nAcadVer<15.0001)
|
||
// nRet |= kDrawableIsCompoundObject;
|
||
return nRet;
|
||
}
|
||
SubText* AecDbDimension::GetSubText(long iText)const
|
||
{
|
||
PushMemVar<BOOL> bExpl(g_Option::instance().g_bSelfDrawDim, TRUE);
|
||
SubText*pSubText = AecXDbCurveBaseEx::GetSubText(iText);
|
||
if (pSubText != NULL)
|
||
pSubText->SetMenuType(6);
|
||
return pSubText;
|
||
}
|
||
SubText* AecDbDimension::HitTestText(ADSGePoint3d pt)const
|
||
{
|
||
PushMemVar<BOOL> bExpl(g_Option::instance().g_bSelfDrawDim, TRUE);
|
||
SubText*pSubText = AecXDbCurveBaseEx::HitTestText(pt);
|
||
if (pSubText != NULL)
|
||
pSubText->SetMenuType(6);
|
||
return pSubText;
|
||
}
|
||
Acad::ErrorStatus AecDbDimension::GetExtents2d(ADSGePoint3d &ptLow, ADSGePoint3d &ptUp) const
|
||
{
|
||
AcDbExtents ext;
|
||
Acad::ErrorStatus es = getGeomExtents(ext);
|
||
ptLow = ext.minPoint();
|
||
ptUp = ext.maxPoint();
|
||
return es;
|
||
}
|
||
Acad::ErrorStatus AecDbDimension::Draw2d(AcGiDraw &dc) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
//if (Has2DBuffer() && !dc.IsDragging())
|
||
if (Has2DBuffer() && !m_bInJig)
|
||
{
|
||
dc.SetColor(colorIndex());
|
||
dc.SetLayer(layerId());
|
||
BaseEx::_Draw2DBuffers(dc, true);
|
||
//Draw2DBuffers(dc);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
BOOL bIsDefText;
|
||
// modify by xlc on 101209 效率低,减少执行次数,解决多视口图纸切换运行慢的问题
|
||
GePoly2D poly;
|
||
GetPolySegOnDimLine(poly);
|
||
|
||
// 绘制标注点,不打印
|
||
//if (_tcscmp(dc.Desc(), XAcGiViewDraw::Descriptor()) == 0 && !dc.IsPlotGeneration())
|
||
if (true)
|
||
{
|
||
AcGePoint3dArray gripPoints;
|
||
double nOffDist = m_nDist2DimLine * GetPScale();
|
||
GeCurveSegment cv = GetDimCurve();
|
||
GeCurveSegment cvFix = cv.Offset(nOffDist, LS_FINITE);
|
||
GeCurveSegment cvObj;
|
||
if (IsAngular())
|
||
{
|
||
double nDist2Obj = cv.GetArc().GetRadius() - m_nObjRadius;
|
||
cvObj = cv.Offset(-nDist2Obj, LS_FINITE);
|
||
}
|
||
|
||
// modify by xlc on 101209 移到外边了
|
||
//GePoly2D poly;
|
||
//GetPolySegOnDimLine(poly);
|
||
|
||
int nVertNum = poly.Length();
|
||
for (int i = 0; i < nVertNum; i++)
|
||
{
|
||
ADSGePoint3d ptFix;
|
||
if (IsAngular() && (IsDimChord() || IsDimArcLen()))
|
||
cvObj.ProjectToMe(*poly[i], ptFix);
|
||
else cvFix.ProjectToMe(*poly[i], ptFix);
|
||
DrawLine(dc, ptFix, ptFix);
|
||
//dc << GeLine(ptFix, ptFix);
|
||
}
|
||
}
|
||
|
||
// modified by whl on 060223
|
||
// BOOL bCheckDim=GlobalFunc::DocGetCheckDim();
|
||
BOOL bCheckDim = GlobalFunc::DocGetCheckDim() && !g_Option::instance().g_bExplodeSubText;
|
||
|
||
double nPScale = GetPScale();
|
||
if (!IsValid())
|
||
return Acad::eInvalidInput;
|
||
|
||
int nColorOld = dc.GetColor();
|
||
double nOffDist = m_nDist2DimLine * GetPScale();
|
||
//BOOL bDraw = (_tcscmp(dc.Desc(), XAcGiViewDraw::Descriptor()) == 0 || g_Option::instance().g_bSelfDrawDim);
|
||
BOOL bDraw = TRUE;
|
||
BOOL bQuickMode = (bDraw && !ownerId() && m_lstSegment.Length() >= g_Option::instance().g_nDimNumGripTip);
|
||
if (g_Option::instance().g_bDisableQuickMode)
|
||
bQuickMode = FALSE;
|
||
|
||
// modify by xlc on 101209 提前了
|
||
// GePoly2D poly;
|
||
// GetPolySegOnDimLine(poly);
|
||
|
||
BOOL bAngular = IsAngular();
|
||
BOOL bSelfDraw = (g_Option::instance().g_bOsnapExpl || bDraw || //g_bExpOtherDb ||
|
||
(IsAngular() && (IsDimChord() || IsDimArcLen()))
|
||
);
|
||
if (bSelfDraw || bCheckDim)
|
||
{
|
||
//dc.SetAlignment(XExplodeDraw::kMiddleCenter);
|
||
|
||
TCString sDimPrefix, sDimSuffix;
|
||
double dimgap = 0, dimtxt = 0, dimexe = 0, dimexo = 0;
|
||
double dimscale = 1.0, dimasz = 1.0, dimdle = 0.0;
|
||
int dimclre = 0, dimclrd = 0, dimclrt = 0;
|
||
int dimdec = 0, dimadec = 0;
|
||
double nArrowThick = 6.0 * nPScale;
|
||
double dimlfac = 1.0; // 标注显示的单位换算系数
|
||
AcDbObjectId dimblk;
|
||
AcDbObjectId idTextStyle;
|
||
// sg add 20120413,增加对“标注文字从默认位置(由标注样式定义的位置)移动时标注文字的位置”设置的支持
|
||
int nDimTextMovePos = 2;
|
||
|
||
OPENOBJ_BEGIN(m_idDimStyle, AcDb::kForRead, AcDbDimStyleTableRecord, pDimStyle);
|
||
if (pDimStyle != NULL)
|
||
{
|
||
dimdec = pDimStyle->dimdec();
|
||
dimadec = pDimStyle->dimadec();
|
||
dimgap = pDimStyle->dimgap();
|
||
dimtxt = pDimStyle->dimtxt();
|
||
dimblk = pDimStyle->dimblk();
|
||
dimlfac = pDimStyle->dimlfac();
|
||
dimscale = nPScale; //pDimStyle->dimscale();
|
||
dimdle = pDimStyle->dimdle();
|
||
dimasz = pDimStyle->dimasz();
|
||
idTextStyle = pDimStyle->dimtxsty();
|
||
dimexe = pDimStyle->dimexe();
|
||
dimexo = pDimStyle->dimexo();
|
||
dimclre = pDimStyle->dimclre().colorIndex();
|
||
dimclrd = pDimStyle->dimclrd().colorIndex();
|
||
dimclrt = pDimStyle->dimclrt().colorIndex();
|
||
|
||
// sg add 20120413,增加对“标注文字从默认位置(由标注样式定义的位置)移动时标注文字的位置”设置的支持
|
||
nDimTextMovePos = pDimStyle->dimtmove();
|
||
|
||
const TCHAR *dimpost = pDimStyle->dimpost();
|
||
const TCHAR *pStr = NULL;
|
||
if (dimpost)
|
||
pStr = _tcsstr(dimpost, _T("<>"));
|
||
if (pStr)
|
||
{
|
||
GlobalFunc::StrCpy(sDimPrefix, dimpost, pStr);
|
||
GlobalFunc::StrCpy(sDimSuffix, pStr + 2, NULL);
|
||
}
|
||
else if (dimpost)
|
||
{
|
||
_tcscpy(sDimSuffix, dimpost);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return Acad::eInvalidInput;
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
GeCurveSegment cv = GetDimCurve();
|
||
BOOL bDimArcLen = (IsAngular() && IsDimArcLen());
|
||
if (bDimArcLen) // 弧长标注
|
||
{
|
||
int numSeg = poly.TotalSegments();
|
||
for (int i = 0; i < numSeg; i++)
|
||
{
|
||
GeCurveSegment segDim, segFix, segObj;
|
||
poly.Nth(i, segDim);
|
||
|
||
segFix = segDim.Offset(OFFSET_LEFT, -GetDist2DimLine(FALSE), LS_FINITE);
|
||
double nOffDist0 = segDim.GetArc().GetRadius() - m_nObjRadius;
|
||
segObj = segDim.Offset(OFFSET_LEFT, nOffDist0, LS_FINITE);
|
||
|
||
ADSGePoint3d ptAr1, ptAr2; // 弧长两端的标注点
|
||
double nChorldDir = segObj.GeLine::Direction();
|
||
GeLine ln1(segObj.GetStartPoint(), nChorldDir + PI / 2.0),
|
||
ln2(segObj.GetEndPoint(), nChorldDir + PI / 2.0);
|
||
ADSGePoint3d ptInt[2];
|
||
segDim.SetLineFlag(LS_INFINITE);
|
||
ln1.SetLineFlag(LS_INFINITE);
|
||
|
||
int nIntNum = segDim.Intersection(ln1, ptInt[0], ptInt[1]);
|
||
if (nIntNum == 0)
|
||
continue;
|
||
else if (nIntNum == 1)
|
||
ptAr1 = ptInt[0];
|
||
else
|
||
ptAr1 = GeLine(ptInt[0], ptInt[1]).NearPoint(segDim.StartPoint());
|
||
|
||
nIntNum = segDim.Intersection(ln2, ptInt[0], ptInt[1]);
|
||
if (nIntNum == 0)
|
||
continue;
|
||
else if (nIntNum == 1)
|
||
ptAr2 = ptInt[0];
|
||
else
|
||
ptAr2 = GeLine(ptInt[0], ptInt[1]).NearPoint(segDim.StartPoint());
|
||
|
||
// sg add 120412,根据9.0需求,增加设置弧长标注样式的设置
|
||
int nDimType = GlobalFunc::DocGetArcLenDimType();
|
||
if (nDimType == 1) // 旧样式才修改标注样式点
|
||
{
|
||
segDim.SetPoints(ptAr1, ptAr2);
|
||
}
|
||
|
||
// 绘制尺寸线
|
||
if (dimclrd)
|
||
dc.SetColor(dimclrd);
|
||
DrawSegment(dc, segDim);
|
||
//dc << segDim;
|
||
|
||
// 绘制尺寸界线
|
||
if (dimclre)
|
||
dc.SetColor(dimclre);
|
||
if (bQuickMode)
|
||
;
|
||
else if (!g_Option::instance().g_bOsnapExpl)
|
||
{
|
||
if (!dimblk) // 尺寸箭头
|
||
{
|
||
// sg modify 120412,解决“实心闭合”样式,不支持设置“箭头大小”的问题
|
||
double dXSize = 1.0 * dimscale * dimasz,
|
||
dYSize = 0.33 * dimscale * dimasz;
|
||
|
||
int nDealOldDimArrowSize = GlobalFunc::DocGetDealOldDimArrowSize();
|
||
if (nDealOldDimArrowSize == 0 && fabs(dimasz - 1.0) < 1.0E-3) // 旧版本的“实心闭合”样式
|
||
{
|
||
dXSize *= 2;
|
||
dYSize *= 2;
|
||
}
|
||
|
||
ADSGePointDir2d pt1, pt2;
|
||
//segDim.Polar(2.0*dimscale, pt1);
|
||
//segDim.Polar(2.0*dimscale, pt2, FALSE);
|
||
segDim.Polar(dXSize, pt1);
|
||
segDim.Polar(dXSize, pt2, FALSE);
|
||
|
||
AcDbPolyline plArrow1;
|
||
plArrow1.setPropertiesFrom(this);
|
||
plArrow1.addVertexAt(0, segDim.StartPoint());
|
||
//plArrow1.setWidthsAt(0, 0.0, 0.66*dimscale);
|
||
plArrow1.setWidthsAt(0, 0.0, dYSize);
|
||
plArrow1.addVertexAt(1, pt1);
|
||
//plArrow1.setWidthsAt(1, 0.66*dimscale, 0.0);
|
||
plArrow1.setWidthsAt(1, dYSize, 0.0);
|
||
DrawPline(dc, plArrow1);
|
||
//dc.Polyline(plArrow1);
|
||
|
||
AcDbPolyline plArrow2;
|
||
plArrow2.setPropertiesFrom(this);
|
||
plArrow2.addVertexAt(0, pt2);
|
||
//plArrow2.setWidthsAt(0, dYSize, 0.0);
|
||
plArrow2.setWidthsAt(0, dYSize, 0.0);
|
||
plArrow2.addVertexAt(1, segDim.EndPoint());
|
||
plArrow2.setWidthsAt(1, 0.0, 0.0);
|
||
DrawPline(dc, plArrow2);
|
||
//dc.Polyline(plArrow2);
|
||
}
|
||
else
|
||
{
|
||
// 打印时,不能使用新方法
|
||
//BOOL bNewMethod = (g_nAcadVer > 15.0001 && g_bMakeBlock);
|
||
|
||
// sg add 091105,强制打印时,不使用新方法
|
||
//if (_tcscmp(dc.Desc(), XAcGiViewDraw::Descriptor()) == 0 && dc.IsPlotGeneration())
|
||
// bNewMethod = FALSE;
|
||
AcGeScale3d scale(dimscale * dimasz, dimscale * dimasz, dimscale * dimasz);
|
||
DrawBlock(dc, dimblk, segDim.EndPoint(), scale, segDim.IDirection(1) + PI);
|
||
DrawBlock(dc, dimblk, segDim.StartPoint(), scale, segDim.IDirection(0));
|
||
|
||
//OPENOBJ_BEGIN(dimblk, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
|
||
//if (pBlock)
|
||
//{
|
||
// dc.DrawBlock(*pBlock, segDim.EndPoint(), AcGeScale3d(dimscale * dimasz, dimscale * dimasz, dimscale * dimasz),
|
||
// segDim.IDirection(1) + PI, bNewMethod);
|
||
// dc.DrawBlock(*pBlock, segDim.StartPoint(), AcGeScale3d(dimscale * dimasz, dimscale * dimasz, dimscale * dimasz),
|
||
// segDim.IDirection(0), bNewMethod);
|
||
//}
|
||
//OPENOBJ_END();
|
||
}
|
||
}
|
||
|
||
// 尺寸界限
|
||
ADSGePoint3d pt1, pt2;
|
||
double nFactor = fabs(nOffDist) > g_Option::instance()._DIST_SNAP ? nOffDist / fabs(nOffDist) : 1.0;
|
||
// sg add 120412,根据9.0需求,增加设置弧长标注样式的设置
|
||
if (nDimType == 0) // 新样式
|
||
{
|
||
double dStartDir = ads_angle(segDim.StartPoint(), segObj.StartPoint());
|
||
ads_polar(segDim.StartPoint(), dStartDir, fabs(nOffDist) - dimexo * dimscale, pt1);
|
||
ads_polar(segDim.StartPoint(), dStartDir, -dimexe * dimscale, pt2);
|
||
}
|
||
else // 旧样式
|
||
{
|
||
ads_polar(segDim.StartPoint(), nChorldDir - nFactor * PI / 2, fabs(nOffDist) - dimexo * dimscale, pt1);
|
||
ads_polar(segDim.StartPoint(), nChorldDir + nFactor * PI / 2, dimexe * dimscale, pt2);
|
||
}
|
||
DrawLine(dc, pt1, pt2);
|
||
//dc << GeLine(pt1, pt2);
|
||
|
||
// sg add 120412,根据9.0需求,增加设置弧长标注样式的设置
|
||
if (nDimType == 0) // 新样式
|
||
{
|
||
double dEndDir = ads_angle(segDim.EndPoint(), segObj.EndPoint());
|
||
ads_polar(segDim.EndPoint(), dEndDir, fabs(nOffDist) - dimexo * dimscale, pt1);
|
||
ads_polar(segDim.EndPoint(), dEndDir, -dimexe * dimscale, pt2);
|
||
}
|
||
else // 旧样式
|
||
{
|
||
ads_polar(segDim.EndPoint(), nChorldDir - nFactor * PI / 2, fabs(nOffDist) - dimexo * dimscale, pt1);
|
||
ads_polar(segDim.EndPoint(), nChorldDir + nFactor * PI / 2, dimexe * dimscale, pt2);
|
||
}
|
||
DrawLine(dc, pt1, pt2);
|
||
//dc << GeLine(pt1, pt2);
|
||
dc.SetColor(nColorOld);
|
||
|
||
// 尺寸文字
|
||
if (bQuickMode)
|
||
;
|
||
else if (!g_Option::instance().g_bOsnapExpl)
|
||
{
|
||
AecXDbText dimText;
|
||
dimText.SetPScale(GetPScale());
|
||
dimText.setPropertiesFrom(this);
|
||
dimText.SetAlignment(AcGiDraw::kMiddleCenter);
|
||
dimText.SetHeight(dimtxt);
|
||
dimText.SetStyleId(idTextStyle);
|
||
dimText.setColorIndex(dimclrt);
|
||
|
||
int numSeg = poly.TotalSegments();
|
||
BOOL bIsDefPos = TRUE;
|
||
|
||
// modify by xlc on 101209 解决速度慢问题
|
||
//ADSGePoint3d ptText=GetTextPos(i, &bIsDefPos);
|
||
ADSGePoint3d ptText = GetTextPos(i, poly, &bIsDefPos);
|
||
ADSGePoint3d ptTemp;
|
||
ADSGePointDir2d ptTempDir;
|
||
cv.ProjectToMe(ptText, ptTemp);
|
||
double nDist = cv.PathDistance(ptTemp);
|
||
cv.Polar(nDist, ptTempDir);
|
||
|
||
// sg modify 120410,使用新增加的接口,代替基类中的NormalViewAngle函数,主要解决精确度是1度的问题
|
||
// double nTextRot=NormalViewAngle(ptTempDir.nDirection);
|
||
double nTextRot = ChangeToNormalViewAngle(ptTempDir.nDirection);
|
||
|
||
bIsDefText = TRUE;
|
||
|
||
// modify by xlc on 101209 解决速度慢问题
|
||
//TCString sText0=GetText(i, &bIsDefText);
|
||
TCString sText0 = GetText(i, poly, &bIsDefText);
|
||
|
||
TCString sText;
|
||
if (bIsDefText)
|
||
sText << sDimPrefix << sText0 << sDimSuffix;
|
||
else
|
||
sText << sText0;
|
||
dimText.SetRotation(Wcs2Layout(nTextRot));
|
||
dimText.SetLocation(ptText);
|
||
if (bSelfDraw)
|
||
{
|
||
PushProperty vProp(&dimText, dc);
|
||
dimText.SetText(sText);
|
||
DrawBaseEx(dc, dimText);
|
||
//if (dc.IsFullExplode())
|
||
// dimText.ExplodeOrDraw2d(dc);
|
||
//else
|
||
// dc.DrawEntity(dimText);
|
||
|
||
ADSGePoint3d ext = dimText.GetExtents();
|
||
ADSGePoint3d ptMid, ptS, ptE;
|
||
ads_polar(ptText, nTextRot + PI / 2, ext.y, ptMid);
|
||
ads_polar(ptText, nTextRot - PI, ext.x / 2, ptS);
|
||
ads_polar(ptText, nTextRot, ext.x / 2, ptE);
|
||
ads_polar(ADSGePoint3d(ptS), nTextRot + PI / 2, ext.y / 2, ptS);
|
||
ads_polar(ADSGePoint3d(ptE), nTextRot + PI / 2, ext.y / 2, ptE);
|
||
DrawArc(dc, ptS, ptMid, ptE, dimText.colorIndex());
|
||
//dc << GeArc(ptS, ptMid, ptE);
|
||
}
|
||
|
||
// sg add 120413,增加文字不在默认位置时候的引线
|
||
if (nDimTextMovePos != 2 && !bIsDefPos) // 在线旁和有引线,暂时都用通一种表示方法
|
||
{
|
||
cv.ProjectToMe(ptText, ptTemp);
|
||
double dDistance = ptText.Distance2d(ptTemp),
|
||
dMixLeaderDis = nPScale * (dimgap + dimtxt * 0.5 + dimexe);
|
||
if (dDistance > dMixLeaderDis + g_Option::instance()._DIST_SNAP)
|
||
{
|
||
if (dimclrd) // 使用尺寸线的颜色
|
||
dc.SetColor(dimclrd);
|
||
|
||
ADSGePoint3d ptLeader1 = segDim.MidPoint(), // 引线起点
|
||
ptLeaderS, ptLeaderE; // 引线文字基线两个端点
|
||
// sg modify 120706,解决有布局转角的尺寸标注的文字引线角度不正确的问题
|
||
//double dLineDir = Wcs2Layout(nTextRot); // 引线文字基线方向
|
||
double dLineDir = nTextRot; // 引线文字基线方向
|
||
ads_polar(ptText, dLineDir - PI / 2, nPScale * (dimgap + dimtxt * 0.5), ptLeaderS);
|
||
ads_polar(ptText, dLineDir - PI / 2, nPScale * (dimgap + dimtxt * 0.5), ptLeaderE);
|
||
|
||
ADSGePoint3d ptExt = dimText.GetExtents();
|
||
|
||
double dTextXLen = ptExt.x;
|
||
dTextXLen *= 0.6; // 1.2*0.5,引线长默认是文字的1.2倍吧
|
||
ads_polar(ptLeaderS, dLineDir, -dTextXLen, ptLeaderS);
|
||
ads_polar(ptLeaderE, dLineDir, dTextXLen, ptLeaderE);
|
||
|
||
ADSGePoint3d ptLeader2 = GeLine(ptLeaderS, ptLeaderE).NearPoint(ptLeader1);
|
||
DrawLine(dc, ptLeader1, ptLeader2);
|
||
DrawLine(dc, ptLeaderS, ptLeaderE);
|
||
//dc << GeLine(ptLeader1, ptLeader2);
|
||
//dc << GeLine(ptLeaderS, ptLeaderE);
|
||
}
|
||
}
|
||
|
||
if (bCheckDim && !bIsDefText)
|
||
{
|
||
TCString sCheckText(256);
|
||
// modify by xlc on 101209 解决速度慢问题
|
||
// sCheckText << _T("(") << sDimPrefix << GetDefaultText(i) << sDimSuffix << _T(")");
|
||
sCheckText << _T("(") << sDimPrefix << GetDefaultText(i, poly) << sDimSuffix << _T(")");
|
||
|
||
ADSGePoint3d ptCheckText;
|
||
if (bIsDefPos)
|
||
{
|
||
ADSGePoint3d ptOnSeg;
|
||
if (segDim.ProjectToMe(ptText, ptOnSeg) == RTNORM)
|
||
{
|
||
ptOnSeg.Mirror(ptText, ptCheckText);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
int nSideText = segDim.OnWhichSide(ptText);
|
||
if (nSideText == OFFSET_RIGHT)
|
||
ads_polar(ptText, ptTempDir.nDirection - PI / 2, nPScale * (dimgap + dimtxt), ptCheckText);
|
||
else
|
||
ads_polar(ptText, ptTempDir.nDirection + PI / 2, nPScale * (dimgap + dimtxt), ptCheckText);
|
||
}
|
||
dimText.setColorIndex(1);
|
||
dimText.SetLocation(ptCheckText);
|
||
dimText.SetText(sCheckText);
|
||
{
|
||
PushProperty vProp(&dimText, dc);
|
||
DrawBaseEx(dc, dimText);
|
||
//if (dc.IsFullExplode())
|
||
// dimText.ExplodeOrDraw2d(dc);
|
||
//else
|
||
// dc.DrawEntity(dimText);
|
||
}
|
||
dimText.setColorIndex(dimclrt);
|
||
} // bCheckDim
|
||
dc.SetColor(nColorOld);
|
||
} // g_bExplOsnap
|
||
} // End for
|
||
}
|
||
else if (IsAngular() && IsDimChord()) // 弦长标注
|
||
{
|
||
PushMemVar<BOOL> tVar1(g_Option::instance().g_bDisableQuickMode, TRUE);
|
||
int numSeg = poly.TotalSegments();
|
||
for (int i = 0; i < numSeg; i++)
|
||
{
|
||
GeCurveSegment segDim, segFix, segObj;
|
||
poly.Nth(i, segDim);
|
||
segFix = segDim.Offset(OFFSET_LEFT, -GetDist2DimLine(FALSE), LS_FINITE);
|
||
double nOffDist0 = segDim.GetArc().GetRadius() - m_nObjRadius;
|
||
segObj = segDim.Offset(OFFSET_LEFT, nOffDist0, LS_FINITE);
|
||
double nRot = segObj.GeLine::Direction();
|
||
ADSGePoint3d ptFix;
|
||
double nObj2Fix = segFix.GetArc().GetRadius() - segObj.GetArc().GetRadius();
|
||
ads_polar(segObj.StartPoint(), nRot - PI / 2, nObj2Fix, ptFix);
|
||
|
||
AecDbDimension objDim;
|
||
objDim.m_bInJig = this->m_bInJig;
|
||
objDim.setPropertiesFrom(this);
|
||
objDim.SetLocation(ptFix);
|
||
objDim.SetRotation(nRot);
|
||
objDim.SetDist2DimLine(GetDist2DimLine());
|
||
objDim.AppendSegment(segObj.GetArc().ChordLength());
|
||
objDim.SetStyleId(GetStyleId());
|
||
|
||
DimTextPos *pNode1 = ((AecDbDimension *)this)->m_lstTextPos.FindNode(&i, DimTextPos::CompareByIndexForFind);
|
||
if (pNode1)
|
||
objDim.SetTextPos(0, pNode1->ptPos);
|
||
|
||
DimTextContent *pNode = ((AecDbDimension *)this)->m_lstTextContent.FindNode(&i, DimTextContent::CompareByIndexForFind);
|
||
if (pNode)
|
||
objDim.SetTextContent(0, pNode->sText);
|
||
DrawBaseEx(dc, objDim);
|
||
//objDim.ExplodeOrDraw2d(dc);
|
||
}
|
||
}
|
||
else // 直线标注或角度标注
|
||
{
|
||
if (bSelfDraw)
|
||
{
|
||
if (dimclrd) // 尺寸线颜色
|
||
dc.SetColor(dimclrd);
|
||
|
||
if (IsAngular())
|
||
DrawPoly2D(dc, poly);
|
||
//dc << poly;
|
||
else
|
||
{
|
||
ADSGePoint3d ptStart, ptEnd;
|
||
ads_polar(*poly[0], m_nRotation + PI, dimdle * dimscale, ptStart);
|
||
DrawLine(dc, ptStart, *poly[0]);
|
||
//dc << GeLine(ptStart, *poly[0]);
|
||
|
||
ads_polar(*poly[poly.Length() - 1], m_nRotation, dimdle * dimscale, ptEnd);
|
||
DrawLine(dc, *poly[poly.Length() - 1], ptEnd);
|
||
//dc << GeLine(*poly[poly.Length() - 1], ptEnd);
|
||
|
||
DrawPoly2D(dc, poly);
|
||
//dc << poly;
|
||
}
|
||
// dc << cv;
|
||
|
||
if (dimclre) // 尺寸界线颜色
|
||
dc.SetColor(dimclre);
|
||
|
||
int numVert = poly.Length();
|
||
for (int i = 0; i < numVert; i++)
|
||
{
|
||
ADSGePoint3d ptVert = *poly[i];
|
||
double nPathDist = cv.PathDistance(ptVert);
|
||
ADSGePointDir2d ptVertDir;
|
||
cv.Polar(nPathDist, ptVertDir);
|
||
|
||
if (bQuickMode)
|
||
;
|
||
else if (!g_Option::instance().g_bOsnapExpl)
|
||
{
|
||
if (!dimblk) // 尺寸箭头,对AutoDesk强烈抗议,为什么只有“实心闭合”不是块呢
|
||
{
|
||
// sg modify 120412,解决“实心闭合”样式,不支持设置“箭头大小”的问题
|
||
double dXSize = 1.0 * dimscale * dimasz,
|
||
dYSize = 0.33 * dimscale * dimasz;
|
||
|
||
int nDealOldDimArrowSize = GlobalFunc::DocGetDealOldDimArrowSize();
|
||
if (nDealOldDimArrowSize == 0 && fabs(dimasz - 1.0) < 1.0E-3) // 旧版本的“实心闭合”样式
|
||
{
|
||
dXSize *= 2;
|
||
dYSize *= 2;
|
||
}
|
||
|
||
ADSGePointDir2d pt1, pt2;
|
||
//cv.Polar(nPathDist+2.0*dimscale, pt1);
|
||
//cv.Polar(nPathDist-2.0*dimscale, pt2);
|
||
cv.Polar(nPathDist + dXSize, pt1);
|
||
cv.Polar(nPathDist - dXSize, pt2);
|
||
|
||
AcDbPolyline plArrow;
|
||
plArrow.setPropertiesFrom(this);
|
||
int iVert = 0;
|
||
if (i > 0)
|
||
{
|
||
plArrow.addVertexAt(iVert, pt2);
|
||
//plArrow.setWidthsAt(iVert, 0.66*dimscale, 0.0);
|
||
plArrow.setWidthsAt(iVert, dYSize, 0.0);
|
||
iVert++;
|
||
}
|
||
|
||
plArrow.addVertexAt(iVert, ptVert);
|
||
//plArrow.setWidthsAt(iVert, 0.0, 0.66*dimscale);
|
||
plArrow.setWidthsAt(iVert, 0.0, dYSize);
|
||
iVert++;
|
||
|
||
if (i < numVert - 1)
|
||
{
|
||
plArrow.addVertexAt(iVert, pt1);
|
||
iVert++;
|
||
}
|
||
DrawPline(dc, plArrow);
|
||
//dc.Polyline(plArrow);
|
||
}
|
||
else
|
||
{
|
||
// 打印时,不能使用新方法
|
||
//BOOL bNewMethod = (g_nAcadVer > 15.0001 && g_bMakeBlock);
|
||
|
||
//// sg add 091105,强制打印时,不使用新方法
|
||
//if (_tcscmp(dc.Desc(), XAcGiViewDraw::Descriptor()) == 0 && dc.IsPlotGeneration())
|
||
// bNewMethod = FALSE;
|
||
AcGeScale3d scale(dimscale * dimasz, dimscale * dimasz, dimscale * dimasz);
|
||
DrawBlock(dc, dimblk, ptVert, scale, ChangeToNormalViewAngle(ptVertDir.nDirection));
|
||
|
||
//OPENOBJ_BEGIN(dimblk, AcDb::kForRead, AcDbBlockTableRecord, pBlock);
|
||
//if (pBlock)
|
||
//{
|
||
// // sg modify 120410,使用新增加的接口,代替基类中的NormalViewAngle函数,主要解决精确度是1度的问题
|
||
// //dc.DrawBlock(*pBlock, ptVert, AcGeScale3d(dimscale*dimasz, dimscale*dimasz, dimscale*dimasz),
|
||
// // NormalViewAngle(ptVertDir.nDirection), bNewMethod);
|
||
// dc.DrawBlock(*pBlock, ptVert, AcGeScale3d(dimscale * dimasz, dimscale * dimasz, dimscale * dimasz),
|
||
// ChangeToNormalViewAngle(ptVertDir.nDirection), bNewMethod);
|
||
//}
|
||
//OPENOBJ_END();
|
||
}
|
||
}
|
||
|
||
// 尺寸界限
|
||
ADSGePoint3d pt1, pt2;
|
||
double nFactor = fabs(nOffDist) > g_Option::instance()._DIST_SNAP ? nOffDist / fabs(nOffDist) : 1.0;
|
||
ads_polar(ptVert, ptVertDir.nDirection - nFactor * PI / 2, fabs(nOffDist) - dimexo * dimscale, pt1);
|
||
ads_polar(ptVert, ptVertDir.nDirection + nFactor * PI / 2, dimexe * dimscale, pt2);
|
||
|
||
DrawLine(dc, pt1, pt2);
|
||
//dc << GeLine(pt1, pt2);
|
||
}
|
||
}
|
||
|
||
dc.SetColor(nColorOld);
|
||
if (bQuickMode)
|
||
;
|
||
else if (!g_Option::instance().g_bOsnapExpl)
|
||
{
|
||
AecXDbText dimText;
|
||
dimText.SetPScale(GetPScale());
|
||
dimText.setPropertiesFrom(this);
|
||
dimText.SetAlignment(AcGiDraw::kMiddleCenter);
|
||
dimText.SetHeight(dimtxt);
|
||
dimText.SetStyleId(idTextStyle);
|
||
dimText.setColorIndex(dimclrt); // 文字颜色
|
||
int numSeg = poly.TotalSegments();
|
||
for (int i = 0; i < numSeg; i++)
|
||
{
|
||
GeCurveSegment seg;
|
||
poly.Nth(i, seg);
|
||
|
||
BOOL bIsDefPos = TRUE;
|
||
// modify by xlc on 101209 解决速度慢问题
|
||
// ADSGePoint3d ptText=GetTextPos(i, &bIsDefPos);
|
||
ADSGePoint3d ptText = GetTextPos(i, poly, &bIsDefPos);
|
||
|
||
ADSGePoint3d ptTemp;
|
||
ADSGePointDir2d ptTempDir;
|
||
cv.ProjectToMe(ptText, ptTemp);
|
||
double nDist = cv.PathDistance(ptTemp);
|
||
cv.Polar(nDist, ptTempDir);
|
||
|
||
// sg modify 120410,使用新增加的接口,代替基类中的NormalViewAngle函数,主要解决精确度是1度的问题
|
||
// double nTextRot=NormalViewAngle(ptTempDir.nDirection);
|
||
double nTextRot = ChangeToNormalViewAngle(ptTempDir.nDirection);
|
||
|
||
BOOL bIsDefText = TRUE;
|
||
// modify by xlc on 101209 解决速度慢问题
|
||
//TCString sText0=GetText(i, &bIsDefText);
|
||
TCString sText0 = GetText(i, poly, &bIsDefText);
|
||
TCString sText;
|
||
if (bIsDefText && !IsAngular())
|
||
sText << sDimPrefix << sText0 << sDimSuffix;
|
||
else
|
||
sText << sText0;
|
||
|
||
dimText.SetText(sText);
|
||
dimText.SetRotation(Wcs2Layout(nTextRot));
|
||
|
||
ADSGePoint3d ptLeader1 = seg.MidPoint(), ptLeader2; // 引线起点
|
||
ADSGePoint3d ptDimPos = ptText, ptLeaderS, ptLeaderE;
|
||
|
||
// sg add 120413,增加文字不在默认位置时候的引线
|
||
if (nDimTextMovePos != 2 && !bIsDefPos) // 在线旁和有引线,暂时都用通一种表示方法
|
||
{
|
||
ADSGePoint3d ptExt = dimText.GetExtents();
|
||
double ddimgap = nPScale * (dimgap + dimtxt * 0.5);
|
||
|
||
cv.ProjectToMe(ptDimPos, ptTemp);
|
||
double dDistance = ptDimPos.Distance2d(ptTemp);
|
||
double dMixLeaderDis = ddimgap + nPScale * dimexe;
|
||
if (dDistance + g_Option::instance()._DIST_SNAP > dMixLeaderDis)
|
||
{
|
||
ads_polar(ptDimPos, nTextRot + PI / 2, ddimgap, ptDimPos);
|
||
ADSGePoint3d ptDim1, ptDim2;
|
||
ads_polar(ptDimPos, nTextRot, -ptExt.x * 0.5, ptDim1);
|
||
ads_polar(ptDimPos, nTextRot, ptExt.x * 0.5, ptDim2);
|
||
|
||
double dAngle = acutAngle(seg.StartPoint(), seg.EndPoint());
|
||
AcGeVector3d vtSeg = seg.StartPoint() - seg.EndPoint();
|
||
if (dAngle > PI / 2 && dAngle <= PI)
|
||
{
|
||
vtSeg *= -1;
|
||
}
|
||
if (dAngle > PI && dAngle <= 1.5 * PI)
|
||
{
|
||
vtSeg *= -1;
|
||
}
|
||
ADSGePoint3d ptOnline;
|
||
seg.ProjectToMe(ptText, ptOnline);
|
||
|
||
AcGeVector3d vtTxt = ptOnline - ptLeader1;
|
||
|
||
if (vtTxt.isCodirectionalTo(vtSeg))
|
||
{
|
||
ads_polar(ptDimPos, nTextRot, -ptExt.x * 0.5, ptDimPos);
|
||
}
|
||
else
|
||
{
|
||
ads_polar(ptDimPos, nTextRot, ptExt.x * 0.5, ptDimPos);
|
||
}
|
||
|
||
//ptDimPos = GeLine(ptDim1, ptDim2).NearPoint(ptText);
|
||
//ads_polar(ptDimPos, nTextRot, ptExt.x * 0.5, ptText);
|
||
//ptText = ptDimPos;
|
||
|
||
// sg modify 120706,解决有布局转角的尺寸标注的文字引线角度不正确的问题
|
||
//double dLineDir = Wcs2Layout(nTextRot); // 引线文字基线方向
|
||
double dLineDir = nTextRot; // 引线文字基线方向
|
||
ads_polar(ptDimPos, dLineDir - PI / 2, ddimgap, ptLeaderS);
|
||
ptLeaderE = ptLeaderS;
|
||
|
||
double dTextXLen = ptExt.x;
|
||
dTextXLen *= 0.6; // 1.2*0.5,引线长默认是文字的1.2倍吧
|
||
ads_polar(ptLeaderS, dLineDir, -dTextXLen, ptLeaderS);
|
||
ads_polar(ptLeaderE, dLineDir, dTextXLen, ptLeaderE);
|
||
|
||
ptLeader2 = GeLine(ptLeaderS, ptLeaderE).NearPoint(ptLeader1);
|
||
|
||
// wlw add 12.9.7角度引线的修改
|
||
if (IsAngular())
|
||
{
|
||
dimText.SetRotation(0.0);
|
||
AcGeCircArc3d cir(seg.StartPoint(), seg.MidPoint(), seg.EndPoint());
|
||
vtSeg = acdbCurDwg()->ucsxdir();
|
||
if (cir.center().distanceTo(ptText.AsAcGePoint3d()) > cir.radius())
|
||
{
|
||
vtSeg *= -1;
|
||
}
|
||
ptLeaderE = ptText + vtSeg * (ptExt.x * 0.5 + dimgap * nPScale);
|
||
ptLeaderS = ptLeaderE + vtSeg * nPScale;
|
||
ptDimPos = ptText;
|
||
ptLeader2 = ptLeaderS;
|
||
}
|
||
|
||
DrawLine(dc, ptLeader1, ptLeader2);
|
||
DrawLine(dc, ptLeaderS, ptLeaderE);
|
||
|
||
//dc << GeLine(ptLeader1, ptLeader2);
|
||
//dc << GeLine(ptLeaderS, ptLeaderE);
|
||
}
|
||
}
|
||
dimText.SetLocation(ptDimPos);
|
||
|
||
if (bSelfDraw)
|
||
{
|
||
PushProperty vProp(&dimText, dc);
|
||
DrawBaseEx(dc, dimText);
|
||
//if (dc.IsFullExplode())
|
||
// dimText.ExplodeOrDraw2d(dc);
|
||
//else
|
||
// dc.DrawEntity(dimText);
|
||
}
|
||
|
||
|
||
if (bCheckDim && !bIsDefText) // 尺寸检查
|
||
{
|
||
TCString sCheckText(256);
|
||
sCheckText << _T("(");
|
||
if (!IsAngular())
|
||
sCheckText << sDimPrefix;
|
||
|
||
// modify by xlc on 101209 解决速度慢问题
|
||
// sCheckText << GetDefaultText(i);
|
||
sCheckText << GetDefaultText(i, poly);
|
||
|
||
if (!IsAngular())
|
||
sCheckText << sDimSuffix;
|
||
sCheckText << _T(")");
|
||
|
||
ADSGePoint3d ptCheckText;
|
||
if (bIsDefPos)
|
||
{
|
||
ADSGePoint3d ptOnSeg;
|
||
if (seg.ProjectToMe(ptText, ptOnSeg) == RTNORM)
|
||
{
|
||
ptOnSeg.Mirror(ptText, ptCheckText);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
int nSideText = seg.OnWhichSide(ptText);
|
||
if (nSideText == OFFSET_RIGHT)
|
||
ads_polar(ptText, ptTempDir.nDirection - PI / 2, nPScale * (dimgap + dimtxt), ptCheckText);
|
||
else
|
||
ads_polar(ptText, ptTempDir.nDirection + PI / 2, nPScale * (dimgap + dimtxt), ptCheckText);
|
||
}
|
||
|
||
dimText.setColorIndex(1);
|
||
dimText.SetLocation(ptCheckText);
|
||
dimText.SetText(sCheckText);
|
||
{
|
||
PushProperty vProp(&dimText, dc);
|
||
DrawBaseEx(dc, dimText);
|
||
//if (dc.IsFullExplode())
|
||
// dimText.ExplodeOrDraw2d(dc);
|
||
//else
|
||
// dc.DrawEntity(dimText);
|
||
}
|
||
dimText.setColorIndex(dimclrt);
|
||
} // bCheckDim && !bIsDefText
|
||
} // for
|
||
|
||
dc.SetColor(nColorOld);
|
||
} // !g_Option::instance().g_bOsnapExpl
|
||
} // 直线标注或角度标注
|
||
} // bSelfDraw || bCheckDim
|
||
|
||
if (!bSelfDraw)
|
||
{
|
||
//BOOL bDraw = (_tcscmp(dc.Desc(), XAcGiViewDraw::Descriptor()) == 0);
|
||
//BOOL bExplode = (_tcscmp(dc.Desc(), XExplodeStream::Descriptor()) == 0);
|
||
|
||
double dTxtHeight = 0.0, dtxtw = 0.0;
|
||
double dPScale = GetPScale();
|
||
|
||
AcDbObjectId idDimStyle = GlobalFunc::DimStyleTch2Acad(m_idDimStyle, dPScale, IsAngular(), database(), dTxtHeight);
|
||
|
||
int nSeg = poly.TotalSegments();
|
||
for (int i = 0; i < nSeg; i++)
|
||
{
|
||
GeCurveSegment seg;
|
||
poly.Nth(i, seg);
|
||
ASSERT(!!seg);
|
||
|
||
GeCurveSegment segOnFix = seg.Offset(OFFSET_RIGHT, nOffDist, LS_FINITE);
|
||
AcDbDimension *pDim = NULL;
|
||
ADSGePoint3d ptText = seg.MidPoint();
|
||
|
||
if (!bAngular)
|
||
{
|
||
ADSGePoint3d pt1 = segOnFix.StartPoint(),
|
||
pt2 = segOnFix.EndPoint();
|
||
// sg modify 120410,使用新增加的接口,代替基类中的NormalViewAngle函数,主要解决精确度是1度的问题
|
||
// double nAng = NormalViewAngle(ads_angle(pt1, pt2));
|
||
double nAng = ChangeToNormalViewAngle(ads_angle(pt1, pt2));
|
||
if (!IsExactSameDrt(nAng, ads_angle(pt1, pt2), g_DimOption::instance()._angSnap))
|
||
GlobalFunc::Exchange(pt1, pt2);
|
||
pDim = new AcDbAlignedDimension(pt1, pt2, ptText);
|
||
}
|
||
else
|
||
{
|
||
ADSGePoint3d ptCen = seg.GetArc().GetCenterPt();
|
||
pDim = new AcDb3PointAngularDimension(ptCen, segOnFix.StartPoint(), segOnFix.EndPoint(), ptText);
|
||
}
|
||
bool bModifyGap = false; // 标记是否需要单独修改“文字偏移”
|
||
DimTextPos *pNode = ((AecDbDimension *)this)->m_lstTextPos.FindNode(&i, DimTextPos::CompareByIndexForFind);
|
||
if (pNode)
|
||
{
|
||
// sg add 120718,用来标记是否是角度标注,并且带引线的样式,文字不在默认位置,此情况下,导出的时候需要特殊处理布局转角
|
||
int nDimTextMovePos(2);
|
||
double dimgap(0),
|
||
dimtxt(0),
|
||
dimexe(0);
|
||
AcDbObjectId idTextStyle;
|
||
TCString sDimPrefix, sDimSuffix;
|
||
OPENOBJ_BEGIN(m_idDimStyle, AcDb::kForRead, AcDbDimStyleTableRecord, pDimStyle);
|
||
if (pDimStyle != NULL)
|
||
{
|
||
nDimTextMovePos = pDimStyle->dimtmove();
|
||
dimgap = pDimStyle->dimgap();
|
||
dimtxt = pDimStyle->dimtxt();
|
||
dimexe = pDimStyle->dimexe();
|
||
idTextStyle = pDimStyle->dimtxsty();
|
||
|
||
const TCHAR *dimpost = pDimStyle->dimpost();
|
||
const TCHAR *pStr = NULL;
|
||
if (dimpost)
|
||
pStr = _tcsstr(dimpost, _T("<>"));
|
||
if (pStr)
|
||
{
|
||
GlobalFunc::StrCpy(sDimPrefix, dimpost, pStr);
|
||
GlobalFunc::StrCpy(sDimSuffix, pStr + 2, NULL);
|
||
}
|
||
else if (dimpost)
|
||
{
|
||
_tcscpy(sDimSuffix, dimpost);
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
/*wlw 12.9.7
|
||
ADSGePoint3d ptDimPos = pNode->ptPos,
|
||
ptTempPos;
|
||
GeCurveSegment cvDim = GetDimCurve();
|
||
cvDim.ProjectToMe(pNode->ptPos, ptTempPos);
|
||
|
||
ADSGePointDir2d ptTempDir;
|
||
double dDistNonDefPt = cvDim.PathDistance(ptTempPos);
|
||
cvDim.Polar(dDistNonDefPt, ptTempDir);
|
||
|
||
double dTextRot = ChangeToNormalViewAngle(ptTempDir.nDirection);
|
||
|
||
if (!bAngular && nDimTextMovePos!=2)
|
||
{
|
||
double dDistance = ptDimPos.Distance2d(ptTempPos),
|
||
dMixLeaderDis = nPScale*(dimgap + dimtxt*0.5 + dimexe);
|
||
ads_polar(ptDimPos, dTextRot-PI/2, nPScale*(dimgap + dimtxt*0.5), ptDimPos);
|
||
|
||
if (dDistance > dMixLeaderDis + g_Option::instance()._DIST_SNAP) // 有引线
|
||
{
|
||
AecXDbText dimText;
|
||
dimText.setPropertiesFrom(this);
|
||
dimText.SetAlignment(XExplodeDraw::kMiddleCenter);
|
||
dimText.SetHeight(dimtxt);
|
||
dimText.SetStyleId(idTextStyle);
|
||
dimText.SetRotation(Wcs2Layout(dTextRot));
|
||
dimText.SetLocation(pNode->ptPos);
|
||
|
||
BOOL bIsDefText = TRUE;
|
||
TCString sText0 = GetText(i, poly, &bIsDefText),
|
||
sText;
|
||
if (bIsDefText && !IsAngular())
|
||
sText << sDimPrefix << sText0 << sDimSuffix;
|
||
else
|
||
sText << sText0;
|
||
dimText.SetText(sText);
|
||
|
||
ADSGePoint3d ptExt = dimText.GetExtents();
|
||
|
||
ADSGePoint3d ptDim1, ptDim2;
|
||
ads_polar(ptDimPos, dTextRot, -ptExt.x*0.5, ptDim1);
|
||
ads_polar(ptDimPos, dTextRot, ptExt.x*0.5, ptDim2);
|
||
ptDimPos = GeLine(ptDim1, ptDim2).NearPoint(ptText);
|
||
}
|
||
}
|
||
if (bAngular && nDimTextMovePos!=2)
|
||
{
|
||
//pDim->setTextRotation(dTextRot);
|
||
}
|
||
*/
|
||
ADSGePoint3d ptDimPos = pNode->ptPos, ptTempPos;
|
||
ADSGePointDir2d ptTempDir;
|
||
GeCurveSegment cvDim = GetDimCurve();
|
||
cvDim.ProjectToMe(pNode->ptPos, ptTempPos);
|
||
double dDistNonDefPt = cvDim.PathDistance(ptTempPos);
|
||
cvDim.Polar(dDistNonDefPt, ptTempDir);
|
||
double dTextRot = ChangeToNormalViewAngle(ptTempDir.nDirection);
|
||
|
||
pDim->setTextPosition(pNode->ptPos);
|
||
if (nDimTextMovePos == 1)
|
||
{
|
||
//wlw add 12.09.17带引线的标注,如果小于cad引线范围内,人为修改文字位置,否则导t3文字移位
|
||
double ddimgapX = nPScale * (dimgap + dimtxt * 0.5);
|
||
if (ptDimPos.Distance2d(ptTempPos) + g_Option::instance()._DIST_SNAP < ddimgapX + nPScale * dimexe)
|
||
{
|
||
ads_polar(ptDimPos, dTextRot - PI / 2, ddimgapX, ptDimPos);
|
||
pDim->setTextPosition(ptDimPos);
|
||
}
|
||
}
|
||
|
||
pDim->useSetTextPosition();
|
||
|
||
}
|
||
// sg modify 120315,解决如果单独设置过天正的布局转角,图形导出T3或者炸开后,文字位置错误的问题
|
||
// 主要是CAD的对象没有布局转角的概念,需要额外处理一下
|
||
else if (fabs(m_nLayoutRotation) > g_DimOption::instance()._angSnap)
|
||
{
|
||
ADSGePoint3d ptDefText = GetDefaultTextPos(i, poly);
|
||
pDim->setTextPosition(ptDefText); // 固定文字位置
|
||
pDim->useSetTextPosition();
|
||
|
||
double dTextAngle = ads_angle(ptText, ptDefText); // 重新计算标注的角度,0位置表示的是与Y轴正向间的夹角
|
||
dTextAngle -= PI / 2;
|
||
pDim->setTextRotation(dTextAngle);
|
||
|
||
// 需要单独修改扩展数据来设置对象内的“文字偏移”
|
||
bModifyGap = true;
|
||
}
|
||
|
||
// DimTextContent *pNode1 = ((AecDbDimension *)this)->m_lstTextContent.FindNode(&i, DimTextContent::CompareByIndexForFind);
|
||
TCString sTextdim = GetText(i, poly, &bIsDefText);
|
||
//wlw mod 130929导出T3保持文字不变
|
||
if (bIsDefText)
|
||
{
|
||
pDim->setDimensionText(_T(""));
|
||
}
|
||
else
|
||
{
|
||
pDim->setDimensionText(sTextdim);
|
||
}
|
||
pDim->setDimensionStyle(idDimStyle);
|
||
pDim->setDimstyleData(idDimStyle);
|
||
pDim->setPropertiesFrom(this);
|
||
#if (ARX != 17)
|
||
if (bModifyGap) // 标记为真的适合,表示需要单独修改“文字偏移”量,天正的尺寸标注对象,不支持遮挡效果,所以直接设置为0即可
|
||
{
|
||
pDim->setDimgap(0);
|
||
}
|
||
#endif
|
||
//((XExplodeStream &)dc).Append(pDim, FALSE);
|
||
}
|
||
}
|
||
dc.SetColor(nColorOld);
|
||
return Acad::eOk;
|
||
}
|
||
|
||
const TCHAR *AecDbDimension::GetDefaultLayer() const
|
||
{
|
||
extern TCHAR* LAY_DIM;
|
||
return LAY_DIM;
|
||
}
|
||
|
||
DrawModeType AecDbDimension::GetDrawType() const
|
||
{
|
||
return k2DOnly;
|
||
}
|
||
|
||
/* * * * * * * * * * 取 动 态 属 性 显 示 数 据 的 函 数 * * * * * * * * * */
|
||
void AecDbDimension::GetTips(PtrList<ObjInfoUnit> &lstInfo) const
|
||
{
|
||
lstInfo.Append(new ObjInfoUnit(_T("对象类型"), _T("连续标注")));
|
||
const TCHAR *pSubType;
|
||
if (!IsAngular()) pSubType = _T("线性标注");
|
||
else if (IsDimChord()) pSubType = _T("弦长标注");
|
||
else if (IsDimArcLen()) pSubType = _T("弧长标注");
|
||
else pSubType = _T("角度标注");
|
||
lstInfo.Append(new ObjInfoUnit(_T("子类型"), pSubType));
|
||
lstInfo.Append(new ObjInfoUnit(_T("标注样式"), GlobalFunc::GetSymbolName(m_idDimStyle)));
|
||
TCString sDist;
|
||
GlobalFunc::ftoa(fabs(m_nDist2DimLine), 1, sDist);
|
||
sDist << _T("P");
|
||
lstInfo.Append(new ObjInfoUnit(_T("尺寸线偏移"), sDist));
|
||
if (!IsAngular()) {
|
||
lstInfo.Append(new ObjInfoUnit(_T("旋转角度"), GlobalFunc::Angle2Str(m_nRotation * 180 / PI)));
|
||
}
|
||
else if (IsDimChord() || IsDimArcLen()) {
|
||
lstInfo.Append(new ObjInfoUnit(_T("所注半径"), GlobalFunc::Dist2Str(m_nObjRadius)));
|
||
}
|
||
}
|
||
|
||
//尺寸文字位置的自动调整
|
||
// 返回最后一个的调整结果
|
||
// 0--缺省, 1--上调, 2--下调, 3--侧调
|
||
// nFromUp--开始调整的状态,bAllowExt--是否允许外调,bAutoReset--无需调整的是否自动复位
|
||
int AecDbDimension::AdjustDim(BOOL bFromUp, BOOL bAllowExt, BOOL bAutoReset)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (!IsValid())
|
||
return 0;
|
||
|
||
double nPScale = GetPScale();
|
||
|
||
double dimgap = 0,
|
||
dimtxt = 0,
|
||
dimexe = 0,
|
||
dimexo = 0;
|
||
double dimscale = 1.0,
|
||
dimasz = 1.0;
|
||
int dimdec = 0, dimadec = 0, nDimTextMovePos;
|
||
double dimlfac = 1.0;
|
||
double nArrowThick = 6.0 * nPScale;
|
||
|
||
AcDbObjectId dimblk;
|
||
AcDbObjectId dimtxsty;
|
||
OPENOBJ_BEGIN(m_idDimStyle, AcDb::kForRead, AcDbDimStyleTableRecord, pDimStyle);
|
||
if (!pDimStyle)
|
||
return 0;
|
||
|
||
dimlfac = pDimStyle->dimlfac(); // 比例因子
|
||
dimdec = pDimStyle->dimdec(); // 线型标注显示的小数位数(精度)
|
||
dimadec = pDimStyle->dimadec(); // 角度标注显示的小数位数(精度)
|
||
dimgap = pDimStyle->dimgap(); // 从尺寸线偏移
|
||
dimtxt = pDimStyle->dimtxt(); // 指定标注文字的高
|
||
dimblk = pDimStyle->dimblk(); // 箭头块名称
|
||
//dimscale = pDimStyle->dimscale();
|
||
dimscale = nPScale; // 全局比例因子
|
||
dimasz = pDimStyle->dimasz(); // 箭头大小
|
||
dimtxsty = pDimStyle->dimtxsty(); // 文字样式
|
||
dimexe = pDimStyle->dimexe(); // 尺寸界线上超尺寸线的距离
|
||
dimexo = pDimStyle->dimexo(); // 尺寸界线偏离原点的距离
|
||
|
||
// wlw add 20120913,增加对“标注文字从默认位置(由标注样式定义的位置)移动时标注文字的位置”设置的支持,引线
|
||
nDimTextMovePos = pDimStyle->dimtmove();
|
||
OPENOBJ_END();
|
||
|
||
if (!dimtxsty)
|
||
return 0;
|
||
|
||
int nRetCode = 0;
|
||
if (bAutoReset)
|
||
m_lstTextPos.Reset();
|
||
|
||
GeCurveSegment cv = GetDimCurve();
|
||
GePoly2D poly;
|
||
GetPolySegOnDimLine(poly);
|
||
|
||
if (IsAngular() && IsDimChord()) //弦长标注
|
||
{
|
||
int numSeg = poly.TotalSegments();
|
||
int nCode = 0;
|
||
for (int i = 0; i < numSeg; i++)
|
||
{
|
||
if (!bAutoReset && m_lstTextPos.FindNode(&i, DimTextPos::CompareByIndexForFind))
|
||
continue;
|
||
|
||
GeCurveSegment segDim, segFix, segObj;
|
||
poly.Nth(i, segDim);
|
||
segFix = segDim.Offset(OFFSET_LEFT, -GetDist2DimLine(FALSE), LS_FINITE);
|
||
double nOffDist = segDim.GetArc().GetRadius() - m_nObjRadius;
|
||
segObj = segDim.Offset(OFFSET_LEFT, nOffDist, LS_FINITE);
|
||
double nRot = segObj.GeLine::Direction();
|
||
ADSGePoint3d ptFix;
|
||
double nObj2Fix = segFix.GetArc().GetRadius() - segObj.GetArc().GetRadius();
|
||
ads_polar(segObj.StartPoint(), nRot - PI / 2, nObj2Fix, ptFix);
|
||
AecDbDimension objDim;
|
||
objDim.setPropertiesFrom(this);
|
||
objDim.SetLocation(ptFix);
|
||
objDim.SetRotation(nRot);
|
||
objDim.SetDist2DimLine(GetDist2DimLine());
|
||
objDim.AppendSegment(segObj.GetArc().ChordLength());
|
||
objDim.SetStyleId(GetStyleId());
|
||
DimTextContent *pNode = ((AecDbDimension *)this)->m_lstTextContent.FindNode(&i, DimTextContent::CompareByIndexForFind);
|
||
if (pNode) objDim.SetTextContent(0, pNode->sText);
|
||
|
||
BOOL bUpAdj = bFromUp;
|
||
if (!nCode)
|
||
nCode = objDim.AdjustDim(bUpAdj, (i == 0 || i == numSeg));
|
||
BOOL bDef = TRUE;
|
||
ADSGePoint3d ptTextPos = objDim.GetTextPos(0, &bDef);
|
||
if (!bDef)
|
||
SetTextPos(i, ptTextPos);
|
||
}
|
||
}
|
||
else // 直线标注或角度标注
|
||
{
|
||
double dTextHeight = dimtxt * dimscale, // 文字字高
|
||
dTextRot(0.0);
|
||
|
||
XDimAutoAdjust dimAdjust;
|
||
dimAdjust.SetDimParam(cv, dimtxsty, dTextHeight, m_nLayoutRotation);
|
||
//wlw add 120912设置文字间隙
|
||
dimAdjust.SetDispSnap(0.6);
|
||
|
||
int nSegNums = poly.TotalSegments(),
|
||
nCur(0);
|
||
for (nCur = 0; nCur < nSegNums; nCur++)
|
||
{
|
||
ADSGePoint3d ptText = GetDefaultTextPos(nCur); // 文字默认位置点
|
||
TCString sDefaultText = GetDefaultText(nCur), // 文字默认内容
|
||
sText = GetText(nCur); // 文字实际注写的内容
|
||
dimAdjust.AppendDim(sDefaultText, sText, ptText);
|
||
}
|
||
|
||
dimAdjust.AutoAdjust(bFromUp, bAllowExt); // 处理自动调整的情况
|
||
|
||
ADSGePoint3d ptTextPos;
|
||
ADSGePointDir2d ptVertDir;
|
||
for (nCur = 0; nCur < nSegNums; nCur++)
|
||
{
|
||
if (!bAutoReset && m_lstTextPos.FindNode(&nCur, DimTextPos::CompareByIndexForFind)) // 不允许尺寸自调
|
||
continue;
|
||
|
||
int nLoc = dimAdjust.GetYLoc(nCur);
|
||
if (nLoc == 1)
|
||
continue;
|
||
|
||
if (nLoc == 0) // 外偏
|
||
{
|
||
cv.Polar(-(dimAdjust.GetXDist(nCur) / 2 + dimgap * nPScale), ptVertDir, nCur == 0);
|
||
dTextRot = ChangeToNormalViewAngle(ptVertDir.nDirection) + PI / 2;
|
||
ads_polar(ptVertDir, dTextRot, (dimgap + dimtxt * 0.5) * nPScale, ptTextPos);
|
||
SetTextPos(nCur, ptTextPos);
|
||
continue;
|
||
}
|
||
|
||
GeCurveSegment seg;
|
||
poly.Nth(nCur, seg);
|
||
|
||
seg.Polar(seg.GetLength() / 2, ptVertDir);
|
||
dTextRot = ChangeToNormalViewAngle(ptVertDir.nDirection);
|
||
|
||
double dDimLen = dimgap + dimtxt / 2 + (dimtxt + dimgap / 2) * (abs(nLoc) - 1);
|
||
if (nDimTextMovePos == 1)
|
||
{//带引线//wlw mod 12.09.15
|
||
dDimLen = dimgap + dimexe + dimtxt / 2;
|
||
}
|
||
if (nLoc > 1) // 尺寸线方向上调 wlw add 120918向下调一点,避开上面的尺寸线(dDimLen - 0.5)
|
||
{
|
||
ads_polar(ptVertDir, dTextRot + PI / 2, (dDimLen - 0.5) * nPScale, ptTextPos);
|
||
}
|
||
else
|
||
{// 尺寸线方向下调
|
||
ads_polar(ptVertDir, dTextRot - PI / 2, dDimLen * nPScale, ptTextPos);
|
||
}
|
||
|
||
SetTextPos(nCur, ptTextPos);
|
||
}
|
||
}
|
||
return nRetCode;
|
||
}
|
||
|
||
//取得尺寸线
|
||
GeCurveSegment
|
||
AecDbDimension::GetDimCurve() const
|
||
{
|
||
assertReadEnabled();
|
||
//ASSERT(IsValid());
|
||
ADSGePoint3d ptStart, ptEnd;
|
||
double nDist = m_nDist2DimLine * GetPScale();
|
||
ads_polar(m_ptLocation, m_nRotation + PI / 2, nDist, ptStart);
|
||
double nSweepAngle = 0.0;
|
||
if (IsAngular()) {
|
||
ADSGePoint3d ptCen;
|
||
ads_polar(ptStart, m_nRotation + PI / 2, m_nDimRadius, ptCen);
|
||
nSweepAngle = GetTotalSegValue();
|
||
if (fabs(nSweepAngle - 2.0 * PI) < g_DimOption::instance()._angSnap)
|
||
nSweepAngle -= 2.0 * g_DimOption::instance()._angSnap;
|
||
|
||
//add by whl on 060110
|
||
if (fabs(nSweepAngle) < 1E-6)
|
||
nSweepAngle = PI;
|
||
|
||
double nEndAng = ads_angle(ptCen, ptStart) + nSweepAngle;
|
||
ads_polar(ptCen, nEndAng, m_nDimRadius, ptEnd);
|
||
}
|
||
else {
|
||
double nTotalDist = GetTotalSegValue();
|
||
|
||
//add by whl on 060110
|
||
if (fabs(nTotalDist) < 1E-6)
|
||
nTotalDist = 1;
|
||
|
||
ads_polar(ptStart, m_nRotation, nTotalDist, ptEnd);
|
||
}
|
||
return GeCurveSegment(ptStart, ptEnd, nSweepAngle);
|
||
}
|
||
|
||
void AecDbDimension::GetPolySegOnDimLine(GePoly2D &poly) const
|
||
{
|
||
assertReadEnabled();
|
||
|
||
GeCurveSegment cv = GetDimCurve();
|
||
SortedVertexList lstVert(cv);
|
||
int nSeg = m_lstSegment.Length();
|
||
double nDist = 0.0;
|
||
for (int i = 0; i < nSeg - 1; i++) {
|
||
ADSGePointDir2d ptVert;
|
||
double nVal = GetSegment(i);
|
||
nDist += nVal;
|
||
cv.Polar(nDist, ptVert);
|
||
lstVert.Insert(ptVert);
|
||
}
|
||
|
||
lstVert.AsPoly2D(poly);
|
||
}
|
||
AcDbCurve* AecDbDimension::GetBaseCurve()const
|
||
{
|
||
assertReadEnabled();
|
||
GePoly2D poly;
|
||
GetPolySegOnDimLine(poly);
|
||
return poly.AsAcDbCurve();
|
||
}
|
||
Acad::ErrorStatus AecDbDimension::SetBaseCurve(AcDbCurve*pCurve)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
GePoly2D poly;
|
||
if (poly.SetAcDbCurve(pCurve) && poly.Length() > 1)
|
||
{
|
||
ADSGePoint3d ptFirst = *poly.Head(), ptLast = *poly.Tail();
|
||
GeCurveSegment cvOld = GetDimCurve();
|
||
GePoly2D polyOld;
|
||
GetPolySegOnDimLine(polyOld);
|
||
bool bChangeFirst = ptFirst != cvOld.StartPoint();
|
||
bool bChangeLast = ptLast != cvOld.EndPoint();
|
||
if (bChangeFirst && bChangeLast)//首尾都变
|
||
{
|
||
m_lstSegment.Reset();
|
||
for (long i = 1; i < poly.Length(); i++)
|
||
m_lstSegment.Append(new double(poly[i]->Distance2d(*poly[i - 1])));
|
||
|
||
GeCurveSegment cv;
|
||
poly.Nth(0, cv);
|
||
cv = cv.Offset(m_nDist2DimLine * GetPScale(), 1);
|
||
m_ptLocation = cv.StartPoint();
|
||
|
||
m_lstTextPos.Reset();
|
||
m_lstTextContent.Reset();
|
||
}
|
||
else if (bChangeFirst)//首变
|
||
{
|
||
FindAndRemoveSegment(cvOld.StartPoint());
|
||
double dist = cvOld.PathDistance(ptFirst, FALSE);
|
||
for (long i = 1; i < polyOld.Length(); i++)
|
||
{
|
||
if ((cvOld.PathDistance(*polyOld[i], FALSE) - dist) > g_Option::instance()._DIST_SNAP)//在新起点之前
|
||
FindAndRemoveSegment(*polyOld[i]);
|
||
else
|
||
break;
|
||
}
|
||
AddSegment(ptFirst);
|
||
}
|
||
else if (bChangeLast)//尾变
|
||
{
|
||
FindAndRemoveSegment(cvOld.EndPoint());
|
||
double dist = cvOld.PathDistance(ptLast, TRUE);
|
||
for (long i = polyOld.Length() - 2; i >= 0; i--)
|
||
{
|
||
if ((cvOld.PathDistance(*polyOld[i], TRUE) - dist) > g_Option::instance()._DIST_SNAP)//在新终点之后
|
||
FindAndRemoveSegment(*polyOld[i]);
|
||
else
|
||
break;
|
||
}
|
||
AddSegment(ptLast);
|
||
}
|
||
|
||
return Acad::eOk;
|
||
}
|
||
else
|
||
return Acad::eInvalidInput;
|
||
}
|
||
int AecDbDimension::HitTestOnDimSeg(ADSGePoint3d pt) const
|
||
{
|
||
GeCurveSegment cv = GetDimCurve();
|
||
ADSGePoint3d ptOnDim;
|
||
if (cv.ProjectToMe(pt, ptOnDim) != RTNORM)
|
||
return -1;
|
||
GePoly2D poly;
|
||
GetPolySegOnDimLine(poly);
|
||
int nSeg = poly.TotalSegments();
|
||
for (int i = 0; i < nSeg; i++) {
|
||
GeCurveSegment seg;
|
||
poly.Nth(i, seg);
|
||
if ((ptOnDim & seg) == PR_INSIDE)
|
||
return i;
|
||
}
|
||
return -1;
|
||
}
|
||
|
||
int AecDbDimension::HitTestOnText(ADSGePoint3d pt) const
|
||
{
|
||
int nSeg = m_lstSegment.Length();
|
||
int nRet = -1;
|
||
double nDistMin = 0.0;
|
||
for (int i = 0; i < nSeg; i++) {
|
||
ADSGePoint3d ptPos = GetTextPos(i);
|
||
if (nRet < 0) {
|
||
nRet = i;
|
||
nDistMin = ptPos.Distance2d(pt);
|
||
}
|
||
else {
|
||
double nDist = ptPos.Distance2d(pt);;
|
||
if (nDist < nDistMin) {
|
||
nDistMin = nDist;
|
||
nRet = i;
|
||
}
|
||
}
|
||
}
|
||
return nRet;
|
||
}
|
||
//add by whl on 041020
|
||
//返回节点索引,输入为近似节点,输出为准确节点,以系统拾取框大小为距离精度。
|
||
int AecDbDimension::HitTestOnPoint(ADSGePoint3d&pt)const
|
||
{
|
||
GeCurveSegment cv = GetDimCurve();
|
||
ADSGePoint3d ptOnDim;
|
||
if (cv.ProjectToMe(pt, ptOnDim) != RTNORM)
|
||
return -1;
|
||
double nMaxDist = GlobalFunc::GetApertureWcs() / 2;
|
||
GePoly2D poly;
|
||
GetPolySegOnDimLine(poly);
|
||
for (long i = 0; i < poly.Length(); i++)
|
||
if (ptOnDim.Distance2d(*poly[i]) <= nMaxDist)
|
||
{
|
||
pt = *poly[i];
|
||
return i;
|
||
}
|
||
return -1;
|
||
}
|
||
|
||
// 角度-弦长-弧长
|
||
void AecDbDimension::SwitchDimChord()
|
||
{
|
||
if (!IsAngular())
|
||
return;
|
||
BOOL bChord = IsDimChord();
|
||
BOOL bArcLen = IsDimArcLen();
|
||
if (!bChord && !bArcLen) { //角度
|
||
GeCurveSegment cv = GetDimCurve();
|
||
GeArc arDim = cv.GetArc();
|
||
double nObjRadius = GetObjRadius();
|
||
if (arDim.GetRadius() < nObjRadius) { //自动反向
|
||
double nDiff = nObjRadius - arDim.GetRadius();
|
||
arDim.SetRadius(arDim.GetRadius() + 2 * nDiff);
|
||
SetDimRadius(arDim.GetRadius());
|
||
cv = arDim;
|
||
arDim.SetRadius(nObjRadius);
|
||
|
||
GeCurveSegment segObj;
|
||
segObj = arDim;
|
||
ADSGePoint3d ptNewLoc;
|
||
segObj.StartPoint().Mirror(GetLocation(), ptNewLoc);
|
||
double nDist = ptNewLoc.Distance2d(cv.StartPoint());
|
||
int nSide = cv.OnWhichSide(ptNewLoc);
|
||
if (nSide == OFFSET_LEFT)
|
||
nDist = -nDist;
|
||
SetDist2DimLine(nDist, FALSE);
|
||
SetLocation(ptNewLoc);
|
||
for (int i = 0; i < m_lstTextPos.Length(); i++) {
|
||
DimTextPos *pText = m_lstTextPos[i];
|
||
ADSGePoint3d ptOnObj;
|
||
segObj.ProjectToMe(pText->ptPos, ptOnObj);
|
||
ptOnObj.Mirror(ADSGePoint3d(pText->ptPos), pText->ptPos);
|
||
}
|
||
}
|
||
SetStyleId(InitDimStyle(DS_LINEAR));
|
||
SetDimChord(TRUE);
|
||
SetDimArcLen(FALSE);
|
||
}
|
||
else if (bChord) {
|
||
SetStyleId(InitDimStyle(DS_ANGLE));
|
||
SetDimChord(FALSE);
|
||
SetDimArcLen(TRUE);
|
||
}
|
||
else {
|
||
SetStyleId(InitDimStyle(DS_ANGLE));
|
||
SetDimChord(FALSE);
|
||
SetDimArcLen(FALSE);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
void AecDbDimension::RemoveZeroSegment()
|
||
{
|
||
AssertWriteEnabled();
|
||
int nSeg = m_lstSegment.Length();
|
||
double nPrec = IsAngular() ? g_DimOption::instance()._angSnap : g_Option::instance()._DIST_SNAP;
|
||
for (int i = 0; i < nSeg; i++) {
|
||
if (*m_lstSegment[i] < nPrec) {
|
||
RemoveSegment(i);
|
||
i--;
|
||
nSeg--;
|
||
}
|
||
}
|
||
}
|
||
|
||
void AecDbDimension::RemoveSegment(int iSeg)
|
||
{
|
||
AssertWriteEnabled();
|
||
int nSeg = m_lstSegment.Length();
|
||
ASSERT(iSeg >= 0 && iSeg < nSeg);
|
||
m_lstSegment.Remove(iSeg);
|
||
|
||
if (m_lstTextPos.FindNode(&iSeg, DimTextPos::CompareByIndexForFind))
|
||
m_lstTextPos.Remove();
|
||
int nTextSeg = m_lstTextPos.Length();
|
||
for (int i = 0; i < nTextSeg; i++) {
|
||
DimTextPos *pNode = m_lstTextPos[i];
|
||
if (pNode->nIndex > iSeg)
|
||
pNode->nIndex--;
|
||
}
|
||
|
||
if (m_lstTextContent.FindNode(&iSeg, DimTextContent::CompareByIndexForFind))
|
||
m_lstTextContent.Remove();
|
||
nTextSeg = m_lstTextContent.Length();
|
||
for (i = 0; i < nTextSeg; i++) {
|
||
DimTextContent *pNode = m_lstTextContent[i];
|
||
if (pNode->nIndex > iSeg)
|
||
pNode->nIndex--;
|
||
}
|
||
|
||
AutoSetFlag();
|
||
}
|
||
|
||
void
|
||
AecDbDimension::InsertSegmentAt(int n, double nVal, BOOL bDist)
|
||
{
|
||
AssertWriteEnabled();
|
||
ASSERT(IsValidSegment(nVal, bDist));
|
||
if (n >= 0 && n < m_lstSegment.Length()) {
|
||
if (IsAngular() && bDist)
|
||
nVal = nVal / m_nDimRadius;
|
||
m_lstSegment[n];
|
||
m_lstSegment.Insert(new double(nVal));
|
||
int nTextSeg = m_lstTextPos.Length();
|
||
for (int i = 0; i < nTextSeg; i++) {
|
||
DimTextPos *pNode = m_lstTextPos[i];
|
||
if (pNode->nIndex >= n)
|
||
pNode->nIndex++;
|
||
}
|
||
|
||
nTextSeg = m_lstTextContent.Length();
|
||
for (i = 0; i < nTextSeg; i++) {
|
||
DimTextContent *pNode = m_lstTextContent[i];
|
||
if (pNode->nIndex >= n)
|
||
pNode->nIndex++;
|
||
}
|
||
|
||
}
|
||
else if (n >= m_lstSegment.Length()) {
|
||
AppendSegment(nVal, bDist);
|
||
}
|
||
|
||
AutoSetFlag();
|
||
}
|
||
|
||
void
|
||
AecDbDimension::SetSegment(int n, double nVal, BOOL bDist)
|
||
{
|
||
AssertWriteEnabled();
|
||
ASSERT(IsValidSegment(nVal, bDist));
|
||
if (n >= 0 && n < m_lstSegment.Length()) {
|
||
if (IsAngular() && bDist)
|
||
nVal = nVal / m_nDimRadius;
|
||
*m_lstSegment[n] = nVal;
|
||
}
|
||
}
|
||
|
||
|
||
// 在指定的位置加入一区间
|
||
BOOL AecDbDimension::AddSegment(ADSGePoint3d ptAdd)
|
||
{
|
||
AssertWriteEnabled();
|
||
GeCurveSegment cv = GetDimCurve();
|
||
ADSGePoint3d ptOnDim;
|
||
if (cv.ProjectToMe(ptAdd, ptOnDim) != RTNORM)
|
||
return FALSE;
|
||
int nPrFlag = (ptOnDim & cv);
|
||
if (nPrFlag == PR_ONPT1 && nPrFlag == PR_ONPT2)
|
||
return FALSE;
|
||
|
||
BOOL bRet = FALSE;
|
||
if (nPrFlag == PR_INSIDE) {
|
||
if (GetSegmentNum() > 0)
|
||
{
|
||
GePoly2D poly;
|
||
GetPolySegOnDimLine(poly);
|
||
int nSeg = poly.TotalSegments();
|
||
for (int n = 0; n < nSeg; n++) {
|
||
GeCurveSegment seg;
|
||
poly.Nth(n, seg);
|
||
if ((ptOnDim & seg) == PR_INSIDE) {
|
||
double nVal = fabs(seg.PathDistance(ptOnDim));
|
||
double nVal1 = fabs(seg.PathDistance(ptOnDim, FALSE)); //距离终点的距离
|
||
if (IsValidSegment(nVal) && IsValidSegment(nVal1)) {
|
||
DimTextPos *pNode = m_lstTextPos.FindNode(&n, DimTextPos::CompareByIndexForFind);
|
||
if (pNode) m_lstTextPos.Remove();
|
||
SetSegment(n, nVal1);
|
||
InsertSegmentAt(n, nVal);
|
||
bRet = TRUE;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
double nVal = fabs(cv.PathDistance(ptOnDim, TRUE));
|
||
if (IsValidSegment(nVal)) {
|
||
AppendSegment(nVal);
|
||
bRet = TRUE;
|
||
}
|
||
}
|
||
}
|
||
else if (ptOnDim.Distance2d(cv.EndPoint()) < ptOnDim.Distance2d(cv.StartPoint())) {
|
||
if (GetSegmentNum() > 0)
|
||
{
|
||
double nVal = fabs(cv.PathDistance(ptOnDim, FALSE));
|
||
if (IsValidSegment(nVal)) {
|
||
AppendSegment(nVal);
|
||
bRet = TRUE;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
double nVal = fabs(cv.PathDistance(ptOnDim, TRUE));
|
||
if (IsValidSegment(nVal)) {
|
||
AppendSegment(nVal);
|
||
bRet = TRUE;
|
||
}
|
||
}
|
||
}
|
||
else {
|
||
double nVal = fabs(cv.PathDistance(ptOnDim, TRUE));
|
||
if (IsValidSegment(nVal)) {
|
||
cv.SetPoints(ptOnDim, ADSGePoint3d(cv.EndPoint()));
|
||
InsertSegmentAt(0, nVal);
|
||
m_nRotation = cv.IDirection(0);
|
||
ads_polar(cv.StartPoint(), m_nRotation - PI / 2, m_nDist2DimLine * GetPScale(), m_ptLocation);
|
||
bRet = TRUE;
|
||
}
|
||
}
|
||
|
||
if (bRet)
|
||
AutoSetFlag();
|
||
return bRet;
|
||
}
|
||
//add by whl on 040810
|
||
BOOL AecDbDimension::FindAndRemoveSegment(ADSGePoint3d pt)
|
||
{
|
||
if (GetSegmentNum() < 1)
|
||
return FALSE;
|
||
|
||
GeCurveSegment seg = GetDimCurve();
|
||
ADSGePoint3d ptOnSeg;
|
||
seg.ProjectToMe(pt, ptOnSeg);
|
||
double value = seg.PathDistance(ptOnSeg);
|
||
long i = -1;
|
||
if (value > g_Option::instance()._DIST_SNAP)
|
||
{
|
||
double curValue = 0;
|
||
for (i = 0; i < GetSegmentNum(); i++)
|
||
{
|
||
curValue += GetSegment(i);
|
||
if (fabs(curValue - value) < g_Option::instance()._DIST_SNAP)
|
||
break;
|
||
}
|
||
}
|
||
if (i >= GetSegmentNum())
|
||
return FALSE;//useful
|
||
|
||
if (i >= 0)
|
||
{
|
||
double temp = GetSegment(i);
|
||
if (i < GetSegmentNum() - 1)//是中间段
|
||
SetSegment(i + 1, temp + GetSegment(i + 1));//后一段合并之
|
||
RemoveSegment(i);
|
||
}
|
||
else//第一个标注段的起点特殊处理,弧段不对!
|
||
{
|
||
double temp = GetSegment(0);
|
||
RemoveSegment(0);
|
||
Vector3D vt = seg.EndPoint() - seg.StartPoint();
|
||
vt.Scale(temp / vt.Length());
|
||
SetLocation(GetLocation() + vt);
|
||
}
|
||
return TRUE;
|
||
}
|
||
BOOL AecDbDimension::FindPoint(ADSGePoint3d pt)const
|
||
{
|
||
GeCurveSegment cv = GetDimCurve();
|
||
ADSGePoint3d ptOnDim;
|
||
if (cv.ProjectToMe(pt, ptOnDim) != RTNORM)
|
||
return FALSE;
|
||
|
||
double nMaxDist = 1E-3;
|
||
GePoly2D poly;
|
||
GetPolySegOnDimLine(poly);
|
||
for (long i = 0; i < poly.Length(); i++)
|
||
{
|
||
double nDist = ptOnDim.Distance2d(*poly[i]);
|
||
if (nDist <= nMaxDist)
|
||
return TRUE;
|
||
}
|
||
|
||
return FALSE;
|
||
}
|
||
double AecDbDimension::GetMaxScope()const
|
||
{
|
||
if (m_lstOffset.Length() > 0)
|
||
return m_lstOffset[0];
|
||
else
|
||
return 20;
|
||
}
|
||
BOOL AecDbDimension::UpdateFrom(ADSGePoint3d ptNew0, ADSGePoint3d ptNew1, ADSGePoint3d ptOld0, ADSGePoint3d ptOld1, bool bErased)
|
||
{
|
||
ptNew0.z = 0;
|
||
ptNew1.z = 0;
|
||
ptOld0.z = 0;
|
||
ptOld1.z = 0;
|
||
AcGeVector2d vtDim(cos(m_nRotation), sin(m_nRotation));
|
||
AcGeVector2d vtNew(ptNew1.x - ptNew0.x, ptNew1.y - ptNew0.y);
|
||
AcGeVector2d vtOld(ptOld1.x - ptOld0.x, ptOld1.y - ptOld0.y);
|
||
vtNew.normalize();
|
||
vtOld.normalize();
|
||
|
||
if (vtNew.isZeroLength() || vtOld.isZeroLength())
|
||
return FALSE;
|
||
if (!vtOld.isParallelTo(vtDim) || !vtNew.isParallelTo(vtDim))
|
||
return FALSE;
|
||
|
||
if (!FindPoint(ptOld0) || !FindPoint(ptOld1))
|
||
return FALSE;
|
||
|
||
GeCurveSegment curve1 = GetDimCurve();
|
||
GeCurveSegment curve2;
|
||
if (m_nDist2DimLine > 0)
|
||
curve2 = curve1.Offset((m_nDist2DimLine + GetMaxScope()) * GetPScale(), 0);
|
||
else
|
||
curve2 = curve1.Offset((m_nDist2DimLine - GetMaxScope()) * GetPScale(), 0);
|
||
GePoly2D poly(1);
|
||
poly.AppendNode(curve1.StartPoint());
|
||
poly.AppendNode(curve1.EndPoint());
|
||
poly.AppendNode(curve2.EndPoint());
|
||
poly.AppendNode(curve2.StartPoint());
|
||
if ((ptOld0 & poly) == PR_OUTSIDE ||
|
||
(ptOld1 & poly) == PR_OUTSIDE)
|
||
return FALSE;
|
||
|
||
if (upgradeOpen() != Acad::eOk)
|
||
return FALSE;
|
||
|
||
if (bErased)
|
||
{
|
||
FindAndRemoveSegment(ptOld0);
|
||
FindAndRemoveSegment(ptOld1);
|
||
}
|
||
else
|
||
{
|
||
long oldSegNum = GetSegmentNum();
|
||
|
||
if (ptOld0 != ptNew0 && ptOld0 != ptNew1)
|
||
FindAndRemoveSegment(ptOld0);
|
||
|
||
if (ptOld1 != ptNew0 && ptOld1 != ptNew1)
|
||
FindAndRemoveSegment(ptOld1);
|
||
|
||
if (GetSegmentNum() < oldSegNum)
|
||
{
|
||
if (GetSegmentNum() > 0)
|
||
{
|
||
AddSegment(ptNew0);
|
||
AddSegment(ptNew1);
|
||
}
|
||
else
|
||
{
|
||
ADSGePoint3d ptLocation0 = m_ptLocation;
|
||
AddSegment(ptNew0);
|
||
AddSegment(ptNew1);
|
||
if (GetSegmentNum() > oldSegNum)
|
||
FindAndRemoveSegment(ptLocation0);
|
||
}
|
||
}
|
||
}
|
||
return TRUE;
|
||
}
|
||
BOOL AecDbDimension::MergeDim(const AecDbDimension *pDim)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (!IsUseDefaultText())
|
||
return FALSE;
|
||
|
||
GeCurveSegment cv = GetDimCurve();
|
||
SortedVertexList lstVert(cv);
|
||
int nSeg = m_lstSegment.Length();
|
||
double nDist = 0.0;
|
||
for (int i = 0; i < nSeg - 1; i++) {
|
||
ADSGePointDir2d ptVert;
|
||
double nVal = GetSegment(i);
|
||
nDist += nVal;
|
||
cv.Polar(nDist, ptVert);
|
||
lstVert.Insert(ptVert);
|
||
}
|
||
|
||
GePoly2D poly;
|
||
pDim->GetPolySegOnDimLine(poly);
|
||
for (i = 0; i < poly.Length(); i++) {
|
||
ADSGePoint3d ptVert;
|
||
if (cv.ProjectToMe(*poly[i], ptVert) == RTNORM)
|
||
lstVert.Insert(ptVert, TRUE);
|
||
}
|
||
|
||
m_lstTextPos.Reset();
|
||
m_lstSegment.Reset();
|
||
GePoly2D polyNew;
|
||
lstVert.AsPoly2D(polyNew);
|
||
nSeg = polyNew.TotalSegments();
|
||
for (i = 0; i < nSeg; i++) {
|
||
GeCurveSegment seg;
|
||
polyNew.Nth(i, seg);
|
||
double nVal = seg.GetLength();
|
||
ASSERT(nVal > g_Option::instance()._DIST_SNAP);
|
||
if (IsValidSegment(nVal))
|
||
AppendSegment(nVal);
|
||
if (i == 0) {
|
||
m_nRotation = seg.IDirection(0);
|
||
ads_polar(seg.StartPoint(), m_nRotation - PI / 2, m_nDist2DimLine * GetPScale(), m_ptLocation);
|
||
}
|
||
}
|
||
AutoSetFlag();
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
BOOL AecDbDimension::ConvertFrom(const AcDbDimension *pDim)
|
||
{
|
||
AssertWriteEnabled();
|
||
|
||
double nScale = 100.0;
|
||
AcDbObjectId idStyle = GlobalFunc::DimStyleAcad2Tch(pDim->dimensionStyle(), nScale);
|
||
SetPScale(nScale);
|
||
//double val;
|
||
//VERIFY(pDim->measurement(val)==Acad::eOk);
|
||
TCString sText;
|
||
sText = pDim->dimensionText();
|
||
double dotVec = pDim->normal().dotProduct(AcGeVector3d(0, 0, 1));
|
||
if (fabs(dotVec - 1.0) > 1.0E-6 || !idStyle)
|
||
return FALSE;
|
||
|
||
setPropertiesFrom(pDim);
|
||
m_idDimStyle = idStyle;
|
||
m_lstTextPos.Reset();
|
||
if (!pDim->isUsingDefaultTextPosition()) {
|
||
m_lstTextPos.Append(new DimTextPos(0, ADSGePoint3d(pDim->textPosition())));
|
||
}
|
||
m_lstTextContent.Reset();
|
||
if (!!sText)
|
||
m_lstTextContent.Append(new DimTextContent(0, sText));
|
||
|
||
|
||
BOOL bRet = FALSE;
|
||
if (pDim->isKindOf(AcDb2LineAngularDimension::desc()) ||
|
||
pDim->isKindOf(AcDb3PointAngularDimension::desc())) {
|
||
AcDb3PointAngularDimension *pDim1 = AcDb3PointAngularDimension::cast(pDim);
|
||
AcDb2LineAngularDimension *pDim2 = AcDb2LineAngularDimension::cast(pDim);
|
||
ADSGePoint3d pt1, pt2, ptDim, ptCen;
|
||
if (pDim1) {
|
||
pt1 = pDim1->xLine1Point();
|
||
pt2 = pDim1->xLine2Point();
|
||
ptDim = pDim1->arcPoint();
|
||
ptCen = pDim1->centerPoint();
|
||
}
|
||
else {
|
||
pt1 = pDim2->xLine1Start();
|
||
pt2 = pDim2->xLine2Start();
|
||
ptDim = pDim2->arcPoint();
|
||
ADSGePoint3d qt1 = pDim2->xLine1End(),
|
||
qt2 = pDim2->xLine2End();
|
||
GeLine _l(pt2, qt2);
|
||
GeLine(pt1, qt1).Intersection(&_l, ptCen);
|
||
}
|
||
m_nDimRadius = ptCen.Distance2d(ptDim);
|
||
SetAngular(TRUE);
|
||
SetDimChord(FALSE);
|
||
m_ptLocation = pt1;
|
||
m_ptLocation.z = 0;
|
||
m_nRotation = ads_angle(ptCen, pt1) + PI / 2;
|
||
GeArc arDim(ptCen, m_nDimRadius, ads_angle(ptCen, pt1), ads_angle(ptCen, pt2));
|
||
GeCurveSegment segDim;
|
||
segDim = arDim;
|
||
//ADSGePoint3d ptOnDim1;
|
||
//pt1.Project(arDim, ptOnDim1);
|
||
double nDist2DimLine = fabs(m_nDimRadius - ptCen.Distance2d(pt1));
|
||
int nSide = segDim.OnWhichSide(m_ptLocation);
|
||
if (nSide == OFFSET_LEFT)
|
||
nDist2DimLine = -nDist2DimLine;
|
||
m_nObjRadius = m_nDimRadius + nDist2DimLine;
|
||
SetDist2DimLine(nDist2DimLine, FALSE);
|
||
m_lstSegment.Reset();
|
||
if (IsValidSegment(arDim.Bulge(), FALSE)) {
|
||
AppendSegment(arDim.Bulge(), FALSE);
|
||
bRet = TRUE;
|
||
}
|
||
}
|
||
else if (pDim->isKindOf(AcDbAlignedDimension::desc()) ||
|
||
pDim->isKindOf(AcDbRotatedDimension::desc())) {
|
||
AcDbAlignedDimension *pDim1 = AcDbAlignedDimension::cast(pDim);
|
||
AcDbRotatedDimension *pDim2 = AcDbRotatedDimension::cast(pDim);
|
||
ASSERT(pDim1 || pDim2);
|
||
ADSGePoint3d pt1, pt2, ptDim;
|
||
if (pDim1) {
|
||
pt1 = pDim1->xLine1Point();
|
||
pt2 = pDim1->xLine2Point();
|
||
ptDim = pDim1->dimLinePoint();
|
||
}
|
||
else {
|
||
pt1 = pDim2->xLine1Point();
|
||
pt2 = pDim2->xLine2Point();
|
||
ptDim = pDim2->dimLinePoint();
|
||
if (!IsSameDrt(ads_angle(pt1, pt2), pDim2->rotation(), g_DimOption::instance()._angSnap))
|
||
return FALSE;
|
||
}
|
||
m_nDimRadius = m_nObjRadius = 0;
|
||
SetAngular(FALSE);
|
||
SetDimChord(FALSE);
|
||
m_ptLocation = pt1;
|
||
m_ptLocation.z = 0;
|
||
m_nRotation = ads_angle(pt1, pt2);
|
||
ADSGePoint3d ptOnDim1, ptOnDim2;
|
||
GeLine ll(ptDim, m_nRotation);
|
||
pt1.Project(&ll, ptOnDim1);
|
||
pt2.Project(&ll, ptOnDim2);
|
||
int nSide = GeLine(ptDim, m_nRotation).OnWhichSide(m_ptLocation);
|
||
m_nDist2DimLine = pt1.Distance2d(ptOnDim1) / GetPScale();
|
||
if (nSide == OFFSET_LEFT)
|
||
m_nDist2DimLine = -m_nDist2DimLine;
|
||
m_lstSegment.Reset();
|
||
double nVal = ptOnDim1.Distance2d(ptOnDim2);
|
||
if (IsValidSegment(nVal)) {
|
||
AppendSegment(nVal);
|
||
bRet = TRUE;
|
||
}
|
||
}
|
||
if (bRet)
|
||
AutoSetFlag();
|
||
return bRet;
|
||
}
|
||
|
||
BOOL AecDbDimension::ConvertFrom(const AecXDbDimension_Old *pDim)
|
||
{
|
||
AssertWriteEnabled();
|
||
AecDbDimension::CopyPropertiesFrom((AcDbEntity*)pDim, 0xFFFFFFFF);
|
||
m_ptLocation = pDim->m_ptLocation;
|
||
m_nRotation = pDim->m_nRotation;
|
||
m_nDist2DimLine = pDim->m_nDist2DimLine;
|
||
m_nDimRadius = pDim->m_nDimRadius;
|
||
m_nObjRadius = pDim->m_nObjRadius;
|
||
m_idDimStyle = pDim->m_idDimStyle;
|
||
m_lstSegment.Reset();
|
||
for (long i = 0; i < pDim->m_lstSegment.Length(); i++)
|
||
m_lstSegment.Append(new double(pDim->m_lstSegment[i]));
|
||
|
||
m_lstTextPos.Reset();
|
||
for (i = 0; i < pDim->m_lstTextPos.Length(); i++)
|
||
{
|
||
DimTextPos *pNew = new DimTextPos;
|
||
pNew->nIndex = pDim->m_lstTextPos[i].nIndex;
|
||
pNew->ptPos = pDim->m_lstTextPos[i].ptPos;
|
||
m_lstTextPos.Append(pNew);
|
||
}
|
||
|
||
m_nDimFlag = pDim->m_nDimFlag;
|
||
|
||
m_lstTextContent.Reset();
|
||
for (i = 0; i < pDim->m_lstTextContent.Length(); i++)
|
||
{
|
||
DimTextContent *pNew = new DimTextContent;
|
||
pNew->nIndex = pDim->m_lstTextContent[i].nIndex;
|
||
pNew->sText = pDim->m_lstTextContent[i].sText;
|
||
m_lstTextContent.Append(pNew);
|
||
}
|
||
return TRUE;
|
||
}
|
||
//Acad::ErrorStatus AecDbDimension::DownGradeSave(int nDrawMode, AcDbVoidPtrArray &entSet, BOOL *bErase)
|
||
//{
|
||
// Acad::ErrorStatus es = Acad::eOk;
|
||
// if (g_nSaveTArchVer >= GetFirstVersion())
|
||
// {
|
||
// if (bErase)
|
||
// *bErase = FALSE;
|
||
// }
|
||
// else if (IsValid())
|
||
// {
|
||
// AecXDbDimension_Old* pDim = new AecXDbDimension_Old;
|
||
// pDim->CopyPropertiesFrom(this, 0xFFFFFFFF);
|
||
//
|
||
// pDim->m_ptLocation = m_ptLocation;
|
||
// pDim->m_nRotation = m_nRotation;
|
||
// pDim->m_nDist2DimLine = m_nDist2DimLine;
|
||
// pDim->m_nDimRadius = m_nDimRadius;
|
||
// pDim->m_nObjRadius = m_nObjRadius;
|
||
// pDim->m_idDimStyle = m_idDimStyle;
|
||
//
|
||
// pDim->m_lstSegment.Reset();
|
||
// for (long i = 0; i < m_lstSegment.Length(); i++)
|
||
// pDim->m_lstSegment.Append(new double(*m_lstSegment[i]));
|
||
//
|
||
// pDim->m_lstTextPos.Reset();
|
||
// for (i = 0; i < m_lstTextPos.Length(); i++)
|
||
// {
|
||
// DimTextPos *pNew = new DimTextPos;
|
||
// pNew->nIndex = m_lstTextPos[i]->nIndex;
|
||
// pNew->ptPos = m_lstTextPos[i]->ptPos;
|
||
// pDim->m_lstTextPos.Append(pNew);
|
||
// }
|
||
//
|
||
// pDim->m_nDimFlag = m_nDimFlag;
|
||
//
|
||
// pDim->m_lstTextContent.Reset();
|
||
// for (i = 0; i < m_lstTextContent.Length(); i++)
|
||
// {
|
||
// DimTextContent *pNew = new DimTextContent;
|
||
// pNew->nIndex = m_lstTextContent[i]->nIndex;
|
||
// pNew->sText = m_lstTextContent[i]->sText;
|
||
// pDim->m_lstTextContent.Append(pNew);
|
||
// }
|
||
//
|
||
// entSet.append(pDim);
|
||
// if (bErase)
|
||
// *bErase = TRUE;
|
||
// }
|
||
// return es;
|
||
//}
|
||
|
||
// Properties
|
||
|
||
double AecDbDimension::GetSegment(int n, BOOL bDist) const
|
||
{
|
||
ASSERT(n >= 0 && n < m_lstSegment.Length());
|
||
double nVal = m_lstSegment[n];
|
||
if (IsAngular() && bDist) {
|
||
ASSERT(m_nDimRadius > g_Option::instance()._DIST_SNAP);
|
||
nVal *= m_nDimRadius;
|
||
}
|
||
return nVal;
|
||
}
|
||
|
||
double
|
||
AecDbDimension::GetTotalSegValue() const
|
||
{
|
||
double nVal = 0.0;
|
||
int nCount = m_lstSegment.Length();
|
||
for (int i = 0; i < nCount; i++)
|
||
nVal += m_lstSegment[i];
|
||
return nVal;
|
||
}
|
||
|
||
BOOL
|
||
AecDbDimension::IsAngular() const
|
||
{
|
||
return ((m_nDimFlag & DF_ANGULAR) != 0);
|
||
//return (m_nDimRadius>g_DimOption::instance()._angSnap);
|
||
}
|
||
BOOL
|
||
AecDbDimension::IsAssociate() const
|
||
{
|
||
return ((m_nDimFlag & DF_ASSOCIATE) != 0);
|
||
}
|
||
void
|
||
AecDbDimension::SetAssociate(BOOL bTrue)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (bTrue)
|
||
m_nDimFlag |= DF_ASSOCIATE;
|
||
else
|
||
m_nDimFlag &= ~DF_ASSOCIATE;
|
||
}
|
||
|
||
int AecDbDimension::GetSegmentNum() const
|
||
{
|
||
return m_lstSegment.Length();
|
||
}
|
||
|
||
double
|
||
AecDbDimension::GetObjRadius() const
|
||
{
|
||
return m_nObjRadius;
|
||
}
|
||
|
||
BOOL
|
||
AecDbDimension::IsDimChord() const
|
||
{
|
||
return ((m_nDimFlag & DF_CHORD));
|
||
}
|
||
|
||
BOOL
|
||
AecDbDimension::IsDimArcLen() const
|
||
{
|
||
return ((m_nDimFlag & DF_ARCLEN));
|
||
}
|
||
|
||
ADSGePoint3d
|
||
AecDbDimension::GetLocation() const
|
||
{
|
||
return m_ptLocation;
|
||
}
|
||
|
||
double
|
||
AecDbDimension::GetRotation() const
|
||
{
|
||
return m_nRotation;
|
||
}
|
||
|
||
double
|
||
AecDbDimension::GetDist2DimLine(BOOL bAsPaperUnit) const
|
||
{
|
||
double val = m_nDist2DimLine;
|
||
if (!bAsPaperUnit)
|
||
val *= GetPScale();
|
||
return val;
|
||
}
|
||
|
||
double
|
||
AecDbDimension::GetDimRadius() const
|
||
{
|
||
return m_nDimRadius;
|
||
}
|
||
|
||
AcDbObjectId
|
||
AecDbDimension::GetStyleId() const
|
||
{
|
||
return m_idDimStyle;
|
||
}
|
||
|
||
|
||
// Modify on 2002/02/05, 考虑dimlfac进行单位换算
|
||
TCString
|
||
AecDbDimension::GetDefaultText(int nIndex) const
|
||
{
|
||
ASSERT(nIndex < m_lstSegment.Length() && nIndex >= 0);
|
||
GePoly2D poly;
|
||
GetPolySegOnDimLine(poly);
|
||
GeCurveSegment seg;
|
||
poly.Nth(nIndex, seg);
|
||
|
||
int dimdec, dimadec;
|
||
double dimlfac = 1.0;
|
||
int dimaunit = 0;
|
||
int dimzin = 0;
|
||
int dimazin = 0;
|
||
double dimrnd = 0;
|
||
OPENOBJ_BEGIN(m_idDimStyle, AcDb::kForRead, AcDbDimStyleTableRecord, pDimStyle);
|
||
ASSERT(pDimStyle);
|
||
dimdec = pDimStyle->dimdec();
|
||
dimadec = pDimStyle->dimadec();
|
||
dimlfac = pDimStyle->dimlfac();
|
||
dimaunit = pDimStyle->dimaunit();
|
||
dimzin = pDimStyle->dimzin();
|
||
dimazin = pDimStyle->dimazin();
|
||
dimrnd = pDimStyle->dimrnd();
|
||
if (dimaunit > 1)
|
||
dimaunit = 1;
|
||
OPENOBJ_END();
|
||
|
||
TCString sText;
|
||
if (IsAngular())
|
||
{
|
||
if (IsDimChord())
|
||
{
|
||
ASSERT(0); //永远也不会执行这儿
|
||
GlobalFunc::ftoa(seg.GeLine::GetLength() * dimlfac, dimdec, sText);
|
||
}
|
||
else if (IsDimArcLen())
|
||
{
|
||
GeArc ar = seg.GetArc();
|
||
ar.SetRadius(m_nObjRadius);
|
||
GlobalFunc::ftoa(ar.GetLength() * dimlfac, dimdec, sText);
|
||
}
|
||
else
|
||
{
|
||
TCString sTemp;
|
||
ads_angtos(fabs(seg.GetBulge()), dimaunit, dimadec, sTemp);
|
||
const TCHAR *pd = _tcschr(sTemp, _T('d'));
|
||
if (pd) {
|
||
GlobalFunc::StrCpy(sText, sTemp, pd);
|
||
sText << _T("%%d");
|
||
sText << (pd + 1);
|
||
}
|
||
else if (dimaunit == 0) {
|
||
if (dimazin & 0x02)
|
||
GlobalFunc::DelSuffixZero(sTemp);
|
||
sText << sTemp << _T("%%d");
|
||
}
|
||
else {
|
||
sText << sTemp;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
TCString sDimrnd;
|
||
GlobalFunc::ftoa(seg.GetLength() * dimlfac, dimdec, sText);
|
||
//////// 处理 标注样式中舍入的问题zzg 090515
|
||
double dTemLen(0), dTemrnd(0);
|
||
GlobalFunc::ftoa(dimrnd, dimdec, sDimrnd);
|
||
dTemLen = _tstof(sText);
|
||
dTemrnd = _tstof(sDimrnd);
|
||
if (!GlobalFunc::Equal(dTemrnd, 0, 0.00000001))
|
||
{
|
||
double dT = dTemLen / dTemrnd;
|
||
TCString sT;
|
||
GlobalFunc::ftoa(dT, 0, sT);
|
||
dT = _tstof(sT);
|
||
int nt = (int)dT;
|
||
double dDimNum = dTemrnd * nt;
|
||
GlobalFunc::ftoa(dDimNum, dimdec, sText);
|
||
}
|
||
//////zzg090515//////////////
|
||
if ((dimzin & 0x08) != 0) {
|
||
GlobalFunc::DelSuffixZero(sText);
|
||
}
|
||
}
|
||
return sText;
|
||
}
|
||
|
||
TCString
|
||
AecDbDimension::GetText(int nIndex, BOOL *bIsDefault) const
|
||
{
|
||
TCString sText;
|
||
DimTextContent *pNode = ((AecDbDimension *)this)->m_lstTextContent.FindNode(&nIndex, DimTextContent::CompareByIndexForFind);
|
||
if (pNode) {
|
||
sText = pNode->sText;
|
||
if (bIsDefault) *bIsDefault = FALSE;
|
||
}
|
||
else {
|
||
if (bIsDefault) *bIsDefault = TRUE;
|
||
sText = GetDefaultText(nIndex);
|
||
}
|
||
return sText;
|
||
}
|
||
|
||
ADSGePoint3d
|
||
AecDbDimension::GetTextPos(int nIndex, BOOL *bIsDefault) const
|
||
{
|
||
ASSERT(nIndex < m_lstSegment.Length() && nIndex >= 0);
|
||
DimTextPos *pNode = ((AecDbDimension *)this)->m_lstTextPos.FindNode(&nIndex, DimTextPos::CompareByIndexForFind);
|
||
if (pNode) {
|
||
if (bIsDefault) *bIsDefault = FALSE;
|
||
return pNode->ptPos;
|
||
}
|
||
|
||
if (bIsDefault)
|
||
*bIsDefault = TRUE;
|
||
ADSGePoint3d ptText = GetDefaultTextPos(nIndex);
|
||
return ptText;
|
||
}
|
||
|
||
ADSGePoint3d
|
||
AecDbDimension::GetDefaultTextPos(int nIndex) const
|
||
{
|
||
ASSERT(nIndex < m_lstSegment.Length() && nIndex >= 0);
|
||
GePoly2D poly;
|
||
GetPolySegOnDimLine(poly);
|
||
double nOffDist = m_nDist2DimLine * GetPScale();
|
||
|
||
BOOL bAngular = IsAngular();
|
||
int nSeg = poly.TotalSegments();
|
||
GeCurveSegment seg;
|
||
poly.Nth(nIndex, seg);
|
||
ASSERT(!!seg);
|
||
ADSGePointDir2d ptTextPos;
|
||
seg.Polar(seg.GetLength() / 2.0, ptTextPos);
|
||
ADSGePoint3d ptText = ptTextPos;
|
||
double nDist2Dim = 0.0;
|
||
OPENOBJ_BEGIN(m_idDimStyle, AcDb::kForRead, AcDbDimStyleTableRecord, pDimStyle);
|
||
if (pDimStyle)
|
||
nDist2Dim = (pDimStyle->dimgap() + pDimStyle->dimtxt() / 2) * GetPScale(); //pDimStyle->dimscale();
|
||
else
|
||
nDist2Dim = 3.0 * GetPScale();
|
||
OPENOBJ_END();
|
||
ADSGePoint3d ptBase;
|
||
if (IsAngular() && IsDimChord()) {
|
||
Midpoint(seg.StartPoint(), seg.EndPoint(), ptBase);
|
||
}
|
||
else {
|
||
ptBase = ptTextPos;
|
||
}
|
||
// sg modify 120410,使用新增加的接口,代替基类中的NormalViewAngle函数,主要解决精确度是1度的问题
|
||
// ads_polar(ptBase, NormalViewAngle(ptTextPos.nDirection)+PI/2.0, nDist2Dim, ptText);
|
||
ads_polar(ptBase, ChangeToNormalViewAngle(ptTextPos.nDirection) + PI / 2.0, nDist2Dim, ptText);
|
||
return ptText;
|
||
}
|
||
|
||
//add by xlc on 101209 解决多视口图纸切换速度慢的问题
|
||
TCString
|
||
AecDbDimension::GetDefaultText(int nIndex, GePoly2D poly) const
|
||
{
|
||
ASSERT(nIndex < m_lstSegment.Length() && nIndex >= 0);
|
||
// GePoly2D poly;
|
||
// GetPolySegOnDimLine(poly);
|
||
GeCurveSegment seg;
|
||
poly.Nth(nIndex, seg);
|
||
|
||
int dimdec, dimadec;
|
||
double dimlfac = 1.0;
|
||
int dimaunit = 0;
|
||
int dimzin = 0;
|
||
int dimazin = 0;
|
||
double dimrnd = 0;
|
||
OPENOBJ_BEGIN(m_idDimStyle, AcDb::kForRead, AcDbDimStyleTableRecord, pDimStyle);
|
||
ASSERT(pDimStyle);
|
||
dimdec = pDimStyle->dimdec();
|
||
dimadec = pDimStyle->dimadec();
|
||
dimlfac = pDimStyle->dimlfac();
|
||
dimaunit = pDimStyle->dimaunit();
|
||
dimzin = pDimStyle->dimzin();
|
||
dimazin = pDimStyle->dimazin();
|
||
dimrnd = pDimStyle->dimrnd();
|
||
if (dimaunit > 1)
|
||
dimaunit = 1;
|
||
OPENOBJ_END();
|
||
|
||
TCString sText;
|
||
if (IsAngular())
|
||
{
|
||
if (IsDimChord())
|
||
{
|
||
ASSERT(0); //永远也不会执行这儿
|
||
GlobalFunc::ftoa(seg.GeLine::GetLength() * dimlfac, dimdec, sText);
|
||
}
|
||
else if (IsDimArcLen())
|
||
{
|
||
GeArc ar = seg.GetArc();
|
||
ar.SetRadius(m_nObjRadius);
|
||
GlobalFunc::ftoa(ar.GetLength() * dimlfac, dimdec, sText);
|
||
}
|
||
else
|
||
{
|
||
TCString sTemp;
|
||
ads_angtos(fabs(seg.GetBulge()), dimaunit, dimadec, sTemp);
|
||
const TCHAR *pd = _tcschr(sTemp, _T('d'));
|
||
if (pd) {
|
||
GlobalFunc::StrCpy(sText, sTemp, pd);
|
||
sText << _T("%%d");
|
||
sText << (pd + 1);
|
||
}
|
||
else if (dimaunit == 0) {
|
||
if (dimazin & 0x02)
|
||
GlobalFunc::DelSuffixZero(sTemp);
|
||
sText << sTemp << _T("%%d");
|
||
}
|
||
else {
|
||
sText << sTemp;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
TCString sDimrnd;
|
||
GlobalFunc::ftoa(seg.GetLength() * dimlfac, dimdec, sText);
|
||
//////// 处理 标注样式中舍入的问题zzg 090515
|
||
double dTemLen(0), dTemrnd(0);
|
||
GlobalFunc::ftoa(dimrnd, dimdec, sDimrnd);
|
||
dTemLen = _tstof(sText);
|
||
dTemrnd = _tstof(sDimrnd);
|
||
if (!GlobalFunc::Equal(dTemrnd, 0, 0.00000001))
|
||
{
|
||
double dT = dTemLen / dTemrnd;
|
||
TCString sT;
|
||
GlobalFunc::ftoa(dT, 0, sT);
|
||
dT = _tstof(sT);
|
||
int nt = (int)dT;
|
||
double dDimNum = dTemrnd * nt;
|
||
GlobalFunc::ftoa(dDimNum, dimdec, sText);
|
||
}
|
||
//////zzg090515//////////////
|
||
if ((dimzin & 0x08) != 0) {
|
||
GlobalFunc::DelSuffixZero(sText);
|
||
}
|
||
}
|
||
return sText;
|
||
}
|
||
|
||
TCString
|
||
AecDbDimension::GetText(int nIndex, GePoly2D poly, BOOL *bIsDefault) const
|
||
{
|
||
TCString sText;
|
||
DimTextContent *pNode = ((AecDbDimension *)this)->m_lstTextContent.FindNode(&nIndex, DimTextContent::CompareByIndexForFind);
|
||
if (pNode) {
|
||
sText = pNode->sText;
|
||
if (bIsDefault) *bIsDefault = FALSE;
|
||
}
|
||
else {
|
||
if (bIsDefault) *bIsDefault = TRUE;
|
||
sText = GetDefaultText(nIndex, poly);
|
||
}
|
||
return sText;
|
||
}
|
||
|
||
ADSGePoint3d
|
||
AecDbDimension::GetTextPos(int nIndex, GePoly2D poly, BOOL *bIsDefault) const
|
||
{
|
||
ASSERT(nIndex < m_lstSegment.Length() && nIndex >= 0);
|
||
DimTextPos *pNode = ((AecDbDimension *)this)->m_lstTextPos.FindNode(&nIndex, DimTextPos::CompareByIndexForFind);
|
||
if (pNode) {
|
||
if (bIsDefault) *bIsDefault = FALSE;
|
||
return pNode->ptPos;
|
||
}
|
||
|
||
if (bIsDefault)
|
||
*bIsDefault = TRUE;
|
||
ADSGePoint3d ptText = GetDefaultTextPos(nIndex, poly);
|
||
return ptText;
|
||
}
|
||
|
||
ADSGePoint3d
|
||
AecDbDimension::GetDefaultTextPos(int nIndex, GePoly2D poly) const
|
||
{
|
||
ASSERT(nIndex < m_lstSegment.Length() && nIndex >= 0);
|
||
// GePoly2D poly;
|
||
// GetPolySegOnDimLine(poly);
|
||
double nOffDist = m_nDist2DimLine * GetPScale();
|
||
|
||
BOOL bAngular = IsAngular();
|
||
int nSeg = poly.TotalSegments();
|
||
GeCurveSegment seg;
|
||
poly.Nth(nIndex, seg);
|
||
ASSERT(!!seg);
|
||
ADSGePointDir2d ptTextPos;
|
||
seg.Polar(seg.GetLength() / 2.0, ptTextPos);
|
||
ADSGePoint3d ptText = ptTextPos;
|
||
double nDist2Dim = 0.0;
|
||
OPENOBJ_BEGIN(m_idDimStyle, AcDb::kForRead, AcDbDimStyleTableRecord, pDimStyle);
|
||
if (pDimStyle)
|
||
nDist2Dim = (pDimStyle->dimgap() + pDimStyle->dimtxt() / 2) * GetPScale(); //pDimStyle->dimscale();
|
||
else
|
||
nDist2Dim = 3.0 * GetPScale();
|
||
OPENOBJ_END();
|
||
ADSGePoint3d ptBase;
|
||
if (IsAngular() && IsDimChord()) {
|
||
Midpoint(seg.StartPoint(), seg.EndPoint(), ptBase);
|
||
}
|
||
else {
|
||
ptBase = ptTextPos;
|
||
}
|
||
|
||
// sg modify 120410,使用新增加的接口,代替基类中的NormalViewAngle函数,主要解决精确度是1度的问题
|
||
//ads_polar(ptBase, NormalViewAngle(ptTextPos.nDirection)+PI/2.0, nDist2Dim, ptText);
|
||
ads_polar(ptBase, ChangeToNormalViewAngle(ptTextPos.nDirection) + PI / 2.0, nDist2Dim, ptText);
|
||
return ptText;
|
||
}
|
||
|
||
// sg add 120410,增加一个新的接口,代替基类中的NormalViewAngle函数,主要解决TchPrivate::ChangeAngleTo1_4精确度是1度的问题
|
||
// 在布局时正常观察的WCS角度
|
||
double AecDbDimension::ChangeToNormalViewAngle(double nAngWcs) const
|
||
{
|
||
double dAng = Wcs2Layout(nAngWcs);
|
||
// 下面这段代码,用于替换TchPrivate::ChangeAngleTo1_4里的精确度,其实功能是一样的
|
||
{
|
||
double dSnap = 1.0E-3,
|
||
dAng1 = GlobalFunc::AngleRangeTo2PI(dAng); //double dSnap = 1.0E-9, 9.0beta1
|
||
|
||
if (GlobalFunc::GreatThan(dAng1, PI / 2.0, dSnap) && GlobalFunc::LessThan(dAng1, PI, dSnap))
|
||
{
|
||
dAng1 += PI;
|
||
}
|
||
else if (GlobalFunc::GreatEqual(dAng1, PI, dSnap) && GlobalFunc::LessEqual(dAng1, PI * 1.5, dSnap))
|
||
{
|
||
dAng1 -= PI;
|
||
}
|
||
|
||
dAng = dAng1;
|
||
}
|
||
|
||
dAng = GlobalFunc::AngleRangeTo2PI(m_nLayoutRotation + dAng);
|
||
return dAng;
|
||
}
|
||
|
||
AcDbObjectId
|
||
AecDbDimension::GetBindId() const
|
||
{
|
||
return m_idBind;
|
||
}
|
||
|
||
|
||
void
|
||
AecDbDimension::SetLocation(ADSGePoint3d pt)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_ptLocation = pt;
|
||
m_ptLocation.z = 0;
|
||
}
|
||
|
||
void
|
||
AecDbDimension::SetRotation(double nAng)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_nRotation = nAng;
|
||
}
|
||
|
||
void
|
||
AecDbDimension::SetDist2DimLine(double nVal, BOOL bAsPaperUnit)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_nDist2DimLine = nVal;
|
||
if (!bAsPaperUnit)
|
||
m_nDist2DimLine /= GetPScale();
|
||
}
|
||
|
||
|
||
void
|
||
AecDbDimension::SetAngular(BOOL bTrue)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (bTrue) m_nDimFlag |= DF_ANGULAR;
|
||
else m_nDimFlag &= ~DF_ANGULAR;
|
||
}
|
||
|
||
void
|
||
AecDbDimension::SetDimChord(BOOL bTrue)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (bTrue) m_nDimFlag |= DF_CHORD;
|
||
else m_nDimFlag &= ~DF_CHORD;
|
||
}
|
||
|
||
void
|
||
AecDbDimension::SetDimArcLen(BOOL bTrue)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (bTrue) m_nDimFlag |= DF_ARCLEN;
|
||
else m_nDimFlag &= ~DF_ARCLEN;
|
||
}
|
||
|
||
void
|
||
AecDbDimension::SetObjRadius(double nVal)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_nObjRadius = nVal;
|
||
}
|
||
|
||
|
||
void
|
||
AecDbDimension::SetDimRadius(double nAng)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_nDimRadius = nAng;
|
||
}
|
||
|
||
void
|
||
AecDbDimension::SetStyleId(AcDbObjectId idStyle)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_idDimStyle = idStyle;
|
||
}
|
||
|
||
void AecDbDimension::SetTextPos(int nIndex, ADSGePoint3d ptPos)
|
||
{
|
||
AssertWriteEnabled();
|
||
ASSERT(nIndex < m_lstSegment.Length() && nIndex >= 0);
|
||
DimTextPos *pNode = m_lstTextPos.FindNode(&nIndex, DimTextPos::CompareByIndexForFind);
|
||
if (!pNode) {
|
||
ADSGePoint3d ptOld = GetTextPos(nIndex);
|
||
if (ptOld.Distance2d(ptPos) > g_Option::instance()._DIST_SNAP)
|
||
m_lstTextPos.Append(new DimTextPos(nIndex, ptPos));
|
||
}
|
||
else {
|
||
int nPos = m_lstTextPos.CurPosition();
|
||
ADSGePoint3d ptDefault = GetDefaultTextPos(nIndex);
|
||
if (ptDefault.Distance2d(ptPos) < g_Option::instance()._DIST_SNAP)
|
||
m_lstTextPos.Remove(nPos);
|
||
else
|
||
m_lstTextPos[nPos]->ptPos = ptPos;
|
||
}
|
||
AutoSetFlag();
|
||
}
|
||
|
||
void AecDbDimension::SetTextContent(int n, const TCHAR *pszChar)
|
||
{
|
||
AssertWriteEnabled();
|
||
ASSERT(n < m_lstSegment.Length() && n >= 0);
|
||
|
||
//wlw add 13.06.22 增加对等式的智能判断
|
||
TCString scharok = pszChar;
|
||
double dDis = GetSegment(n);
|
||
double dPrec = 1E-4;
|
||
CString sExpression(pszChar);
|
||
CString sLeft1, sLeft2, sRight;
|
||
int nstar = sExpression.Find(_T("X"));
|
||
int nstar1 = sExpression.Find(_T("="));
|
||
if (nstar < 0)
|
||
{
|
||
nstar = sExpression.Find(_T("x"));
|
||
}
|
||
if (nstar > 0 && nstar1 > 0)
|
||
{
|
||
|
||
sLeft1 = sExpression.Left(nstar);
|
||
sLeft2 = sExpression.Mid(nstar + 1, nstar1 - nstar - 1);
|
||
sRight = sExpression.Right(sExpression.GetLength() - nstar1 - 1);
|
||
double dRight = _tstof(sRight);
|
||
//看看哪些数字改变过
|
||
CString sOld = (LPCTSTR)GetText(n);
|
||
CString soldLeft1, soldLeft2, soldRight;
|
||
nstar = sOld.Find(_T("X"));
|
||
nstar1 = sOld.Find(_T("="));
|
||
if (nstar < 0)
|
||
{
|
||
nstar = sOld.Find(_T("x"));
|
||
}
|
||
if (nstar > 0 && nstar1 > 0)
|
||
{
|
||
soldLeft1 = sOld.Left(nstar);
|
||
soldLeft2 = sOld.Mid(nstar + 1, nstar1 - nstar - 1);
|
||
soldRight = sOld.Right(sOld.GetLength() - nstar1 - 1);
|
||
double d1, d2;
|
||
double doldRight = _tstof(soldRight);
|
||
d1 = _tstof(sLeft2);
|
||
d2 = _tstof(soldLeft2);
|
||
|
||
if (RealEqual(dRight, doldRight, dPrec))
|
||
{//总长度没变,改前面任意一个
|
||
if (d1 < 1E-10)
|
||
{
|
||
return;
|
||
}
|
||
if (RealEqual(d1, d2, dPrec))
|
||
{//第二个数没变,按照第一数进行计算
|
||
d1 = _tstof(sLeft1);
|
||
if (d1 < 1E-10)
|
||
return;
|
||
d2 = doldRight / d1;
|
||
}
|
||
else
|
||
{//第二个数变,按照第二数进行计算
|
||
d2 = _tstof(sLeft2);
|
||
if (d2 < 1E-10)
|
||
return;
|
||
d1 = doldRight / d2;
|
||
}
|
||
|
||
}
|
||
else
|
||
{//总长度变化了,按照乘数不变的原则改第一个数
|
||
d2 = _tstof(sLeft2);
|
||
if (d2 < 1E-10)
|
||
{
|
||
return;
|
||
}
|
||
d1 = dRight / d2;
|
||
}
|
||
|
||
int nd1 = d1;
|
||
int nd2 = d2;
|
||
if (d2 != nd2)
|
||
{
|
||
if (d1 != nd1)
|
||
{
|
||
sExpression.Format(_T("%.1fX%.1f=%.0f"), d1, d2, dRight);
|
||
}
|
||
else
|
||
{
|
||
sExpression.Format(_T("%.0fX%.1f=%.0f"), d1, d2, dRight);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (d1 != nd1)
|
||
{
|
||
sExpression.Format(_T("%.1fX%.0f=%.0f"), d1, d2, dRight);
|
||
}
|
||
else
|
||
{
|
||
sExpression.Format(_T("%.0fX%.0f=%.0f"), d1, d2, dRight);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
scharok = sExpression;
|
||
|
||
|
||
DimTextContent *pNode = m_lstTextContent.FindNode(&n, DimTextContent::CompareByIndexForFind);
|
||
if (!pNode) {
|
||
if (pszChar && pszChar[0])
|
||
m_lstTextContent.Append(new DimTextContent(n, scharok));
|
||
}
|
||
else {
|
||
if (!pszChar || !pszChar[0])
|
||
m_lstTextContent.Remove();
|
||
else
|
||
pNode->sText = scharok;
|
||
}
|
||
AutoSetFlag();
|
||
}
|
||
|
||
void AecDbDimension::SetBindId(AcDbObjectId id)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_idBind = id;
|
||
AutoSetFlag();
|
||
}
|
||
|
||
void
|
||
AecDbDimension::AppendSegment(double nVal, BOOL bDist)
|
||
{
|
||
AssertWriteEnabled();
|
||
ASSERT(IsValidSegment(nVal, bDist));
|
||
if (IsAngular() && bDist)
|
||
nVal = nVal / m_nDimRadius;
|
||
m_lstSegment.Append(new double(nVal));
|
||
}
|
||
|
||
void
|
||
AecDbDimension::ResetTextPos()
|
||
{
|
||
AssertWriteEnabled();
|
||
m_lstTextPos.Reset();
|
||
AutoSetFlag();
|
||
}
|
||
|
||
void
|
||
AecDbDimension::ResetTextContent()
|
||
{
|
||
AssertWriteEnabled();
|
||
m_lstTextContent.Reset();
|
||
AutoSetFlag();
|
||
}
|
||
|
||
|
||
BOOL
|
||
AecDbDimension::IsTextMoved() const
|
||
{
|
||
return ((m_nDimFlag & DF_POSITION) != 0 && m_lstTextPos.Length());
|
||
}
|
||
|
||
BOOL
|
||
AecDbDimension::IsUseDefaultText() const
|
||
{
|
||
return ((m_nDimFlag & DF_TEXT) == 0 || m_lstTextContent.Length() == 0);
|
||
}
|
||
|
||
BOOL
|
||
AecDbDimension::IsBind() const
|
||
{
|
||
return ((m_nDimFlag & DF_BIND) != 0 && !!m_idBind);
|
||
}
|
||
|
||
BOOL
|
||
AecDbDimension::IsUseDimStyleScale() const
|
||
{
|
||
return ((m_nDimFlag & DF_DSSCALE) != 0);
|
||
}
|
||
|
||
void
|
||
AecDbDimension::UseDimStyleScale(BOOL bTrue)
|
||
{
|
||
AssertWriteEnabled();
|
||
if (bTrue)
|
||
m_nDimFlag |= DF_DSSCALE;
|
||
else
|
||
m_nDimFlag &= ~DF_DSSCALE;
|
||
}
|
||
|
||
void AecDbDimension::AutoSetFlag()
|
||
{
|
||
AssertWriteEnabled();
|
||
if (!!m_idBind)
|
||
m_nDimFlag |= DF_BIND;
|
||
else
|
||
m_nDimFlag &= ~DF_BIND;
|
||
|
||
if (m_lstTextPos.Length())
|
||
m_nDimFlag |= DF_POSITION;
|
||
else
|
||
m_nDimFlag &= ~DF_POSITION;
|
||
|
||
if (m_lstTextContent.Length())
|
||
m_nDimFlag |= DF_TEXT;
|
||
else
|
||
m_nDimFlag &= ~DF_TEXT;
|
||
|
||
}
|
||
|
||
// sg add 101116,支持统一标高
|
||
bool AecDbDimension::UnifyElevation(double dElevation)
|
||
{
|
||
AssertWriteEnabled();
|
||
m_ptLocation.z = dElevation;
|
||
|
||
for (int i = 0; i < m_lstTextPos.Length(); i++)
|
||
{
|
||
m_lstTextPos[i]->ptPos.z = dElevation;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbDimension::getSplitCurves(const AcGeDoubleArray& params,
|
||
AcDbVoidPtrArray& curveSegments) const
|
||
{
|
||
assertReadEnabled();
|
||
if (IsAngular() || IsDimArcLen())
|
||
{
|
||
AcGePoint3dArray points;
|
||
for (int i = 0; i < params.length(); i++)
|
||
{
|
||
AcGePoint3d pt;
|
||
|
||
getPointAtParam(params[i], pt);
|
||
points.append(pt);
|
||
|
||
}
|
||
|
||
return getSplitCurves(points, curveSegments);
|
||
}
|
||
else
|
||
{
|
||
return AecXDbCurveBaseEx::getSplitCurves(params, curveSegments);
|
||
}
|
||
}
|
||
Acad::ErrorStatus AecDbDimension::getSplitCurves(const AcGePoint3dArray& points,
|
||
AcDbVoidPtrArray& curveSegments) const
|
||
{
|
||
assertReadEnabled();
|
||
if (IsAngular() || IsDimArcLen())
|
||
{
|
||
int nlen = points.length();
|
||
ADSGePoint3d ptOnDim;
|
||
ADSGePoint3d ptPick, ptPick2;
|
||
AecDbDimension *pDimClone = (AecDbDimension *)clone();
|
||
getClosestPointTo(points[0], ptPick);
|
||
pDimClone->AddSegment(ptPick);
|
||
if (nlen > 1)
|
||
{
|
||
getClosestPointTo(points[1], ptPick2);
|
||
pDimClone->AddSegment(ptPick2);
|
||
}
|
||
|
||
GePoly2D poly;
|
||
pDimClone->GetPolySegOnDimLine(poly);
|
||
int nSeg = -1;
|
||
int nSeg2 = -1;
|
||
for (int i = 0; i < poly.TotalSegments(); i++)
|
||
{
|
||
GeCurveSegment seg;
|
||
poly.Nth(i, seg);
|
||
if ((ptPick & seg) == PR_ONPT1 || (ptPick & seg) == PR_ONPT2)
|
||
{
|
||
nSeg = i;
|
||
break;
|
||
}
|
||
}
|
||
if (nlen > 1)
|
||
{
|
||
for (i = 0; i < poly.TotalSegments(); i++)
|
||
{
|
||
GeCurveSegment seg;
|
||
poly.Nth(i, seg);
|
||
if ((ptPick2 & seg) == PR_ONPT1 || (ptPick2 & seg) == PR_ONPT2)
|
||
{
|
||
nSeg2 = i;
|
||
break;
|
||
}
|
||
}
|
||
|
||
int nTmp;
|
||
if (nSeg > nSeg2)
|
||
{
|
||
nTmp = nSeg;
|
||
nSeg = nSeg2;
|
||
nSeg2 = nTmp;
|
||
}
|
||
}
|
||
|
||
|
||
GeDirectionCurve seg;
|
||
ADSGePoint3d ptLoc;
|
||
AecDbDimension *pDimNew2 = (AecDbDimension *)pDimClone->clone();
|
||
int nTotalSeg = poly.TotalSegments();
|
||
int nSeg1 = nSeg + 1;
|
||
|
||
for (i = nSeg1; i < nTotalSeg; i++)
|
||
pDimNew2->RemoveSegment(nSeg1);
|
||
curveSegments.append(pDimNew2);
|
||
|
||
|
||
if (nlen > 1)
|
||
{
|
||
AecDbDimension *pDimNew3 = (AecDbDimension *)pDimClone->clone();
|
||
curveSegments.append(pDimNew3);
|
||
poly.Nth(nSeg2 + 1, seg);
|
||
}
|
||
else
|
||
{
|
||
poly.Nth(nSeg1, seg);
|
||
}
|
||
|
||
double nRot = seg.IDirection(0);
|
||
ads_polar(seg.StartPoint(), nRot - PI / 2.0, pDimClone->GetDist2DimLine(FALSE), ptLoc);
|
||
|
||
AecDbDimension *pDimNew = (AecDbDimension *)pDimClone->clone();
|
||
if (nlen > 1)
|
||
{
|
||
for (i = 0; i < nSeg2 + 1; i++)
|
||
pDimNew->RemoveSegment(0);
|
||
}
|
||
else
|
||
{
|
||
for (i = 0; i < nSeg1; i++)
|
||
pDimNew->RemoveSegment(0);
|
||
}
|
||
|
||
pDimNew->SetLocation(ptLoc);
|
||
pDimNew->SetRotation(nRot);
|
||
curveSegments.append(pDimNew);
|
||
|
||
delete pDimClone;
|
||
return Acad::eOk;
|
||
|
||
}
|
||
else
|
||
{
|
||
return AecXDbCurveBaseEx::getSplitCurves(points, curveSegments);
|
||
}
|
||
}
|
||
|
||
Acad::ErrorStatus AecDbDimension::subExplode(AcDbVoidPtrArray &entitySet) const
|
||
{
|
||
double dTxtHeight = 0.0, dtxtw = 0.0;
|
||
double dPScale = GetPScale();
|
||
|
||
AcDbObjectId idDimStyle = GlobalFunc::DimStyleTch2Acad(m_idDimStyle, dPScale, IsAngular(), database(), dTxtHeight);
|
||
|
||
double nOffDist = m_nDist2DimLine*GetPScale();
|
||
BOOL bIsDefText(FALSE);
|
||
|
||
XPoly2D poly;
|
||
GetPolySegOnDimLine(poly);
|
||
|
||
int nSeg = poly.TotalSegments();
|
||
for (int i = 0; i<nSeg; i++)
|
||
{
|
||
XCurveSegment seg;
|
||
poly.Nth(i, seg);
|
||
ASSERT(!!seg);
|
||
|
||
XCurveSegment segOnFix = seg.Offset(OFFSET_RIGHT, nOffDist, LS_FINITE);
|
||
AcDbDimension *pDim = NULL;
|
||
XPoint ptText = seg.MidPoint();
|
||
|
||
if (!IsAngular())
|
||
{
|
||
XPoint pt1 = segOnFix.StartPoint(),
|
||
pt2 = segOnFix.EndPoint();
|
||
// sg modify 120410,使用新增加的接口,代替基类中的NormalViewAngle函数,主要解决精确度是1度的问题
|
||
// double nAng = NormalViewAngle(ads_angle(pt1, pt2));
|
||
double nAng = ChangeToNormalViewAngle(ads_angle(pt1, pt2));
|
||
if (!IsExactSameDrt(nAng, ads_angle(pt1, pt2), g_DimOption::instance()._angSnap))
|
||
GlobalFunc::Exchange(pt1, pt2);
|
||
pDim = new AcDbAlignedDimension(pt1, pt2, ptText);
|
||
}
|
||
else
|
||
{
|
||
XPoint ptCen = seg.GetArc().GetCenterPt();
|
||
pDim = new AcDb3PointAngularDimension(ptCen, segOnFix.StartPoint(), segOnFix.EndPoint(), ptText);
|
||
}
|
||
bool bModifyGap = false; // 标记是否需要单独修改“文字偏移”
|
||
DimTextPos *pNode = ((AecDbDimension *)this)->m_lstTextPos.FindNode(&i, DimTextPos::CompareByIndexForFind);
|
||
if (pNode)
|
||
{
|
||
// sg add 120718,用来标记是否是角度标注,并且带引线的样式,文字不在默认位置,此情况下,导出的时候需要特殊处理布局转角
|
||
int nDimTextMovePos(2);
|
||
double dimgap(0),
|
||
dimtxt(0),
|
||
dimexe(0);
|
||
AcDbObjectId idTextStyle;
|
||
XString sDimPrefix, sDimSuffix;
|
||
OPENOBJ_BEGIN(m_idDimStyle, AcDb::kForRead, AcDbDimStyleTableRecord, pDimStyle);
|
||
if (pDimStyle != NULL)
|
||
{
|
||
nDimTextMovePos = pDimStyle->dimtmove();
|
||
dimgap = pDimStyle->dimgap();
|
||
dimtxt = pDimStyle->dimtxt();
|
||
dimexe = pDimStyle->dimexe();
|
||
idTextStyle = pDimStyle->dimtxsty();
|
||
|
||
const TCHAR *dimpost = pDimStyle->dimpost();
|
||
const TCHAR *pStr = NULL;
|
||
if (dimpost)
|
||
pStr = _tcsstr(dimpost, _T("<>"));
|
||
if (pStr)
|
||
{
|
||
GlobalFunc::StrCpy(sDimPrefix, dimpost, pStr);
|
||
GlobalFunc::StrCpy(sDimSuffix, pStr+2, NULL);
|
||
}
|
||
else if (dimpost)
|
||
{
|
||
_tcscpy(sDimSuffix, dimpost);
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
XPoint ptDimPos = pNode->ptPos, ptTempPos;
|
||
XPointDir2d ptTempDir;
|
||
XCurveSegment cvDim = GetDimCurve();
|
||
cvDim.ProjectToMe(pNode->ptPos, ptTempPos);
|
||
double dDistNonDefPt = cvDim.PathDistance(ptTempPos);
|
||
cvDim.Polar(dDistNonDefPt, ptTempDir);
|
||
double dTextRot = ChangeToNormalViewAngle(ptTempDir.nDirection);
|
||
|
||
pDim->setTextPosition(pNode->ptPos);
|
||
if (nDimTextMovePos == 1)
|
||
{
|
||
//wlw add 12.09.17带引线的标注,如果小于cad引线范围内,人为修改文字位置,否则导t3文字移位
|
||
double ddimgapX = dPScale*(dimgap + dimtxt*0.5);
|
||
if (ptDimPos.Distance2d(ptTempPos) + g_Option::instance()._DIST_SNAP < ddimgapX + dPScale * dimexe)
|
||
{
|
||
ads_polar(ptDimPos, dTextRot-PI/2, ddimgapX, ptDimPos);
|
||
pDim->setTextPosition(ptDimPos);
|
||
}
|
||
}
|
||
|
||
pDim->useSetTextPosition();
|
||
|
||
}
|
||
// sg modify 120315,解决如果单独设置过天正的布局转角,图形导出T3或者炸开后,文字位置错误的问题
|
||
// 主要是CAD的对象没有布局转角的概念,需要额外处理一下
|
||
else if (fabs(m_nLayoutRotation) > g_DimOption::instance()._angSnap)
|
||
{
|
||
XPoint ptDefText = GetDefaultTextPos(i, poly);
|
||
pDim->setTextPosition(ptDefText); // 固定文字位置
|
||
pDim->useSetTextPosition();
|
||
|
||
double dTextAngle = ads_angle(ptText, ptDefText); // 重新计算标注的角度,0位置表示的是与Y轴正向间的夹角
|
||
dTextAngle -= PI/2;
|
||
pDim->setTextRotation(dTextAngle);
|
||
|
||
// 需要单独修改扩展数据来设置对象内的“文字偏移”
|
||
bModifyGap = true;
|
||
}
|
||
|
||
// TDimTextContent *pNode1 = ((TDbDimension2 *)this)->m_lstTextContent.FindNode(&i, TDimTextContent::CompareByIndexForFind);
|
||
XString sTextdim = GetText(i, poly, &bIsDefText);
|
||
//wlw mod 130929导出T3保持文字不变
|
||
if (bIsDefText)
|
||
{
|
||
pDim->setDimensionText(_T(""));
|
||
}
|
||
else
|
||
{
|
||
pDim->setDimensionText(sTextdim);
|
||
}
|
||
pDim->setDimensionStyle(idDimStyle);
|
||
pDim->setDimstyleData(idDimStyle);
|
||
pDim->setPropertiesFrom(this);
|
||
#if (ADS != 17)
|
||
if (bModifyGap) // 标记为真的适合,表示需要单独修改“文字偏移”量,天正的尺寸标注对象,不支持遮挡效果,所以直接设置为0即可
|
||
{
|
||
pDim->setDimgap(0);
|
||
}
|
||
#endif
|
||
entitySet.append(pDim);
|
||
}
|
||
return Acad::eOk;
|
||
}
|
||
|
||
#pragma endregion
|