Files
envi-code/SourceCode/Code2026/Pool3dCmd/KTAxisCmdGroup.cpp
T
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

1553 lines
37 KiB
C++

#include "stdafx.h"
#include "resource.h"
#include "KTAxisCmdGroup.h"
#include "KTLineAxisGridDlg.h"
#include "KTLineAxisCreator.h"
#include "KTAxisGridJig.h"
#include "KTTempTol.h"
#include "KTCADUtilityEx.h"
#include "KTCADSysVar.h"
#include "KTAxisDimLabelDlg.h"
#include "KTSetting.h"
#include "KTCadUtility.h"
#include "KTModelLayoutXData.h"
#include <vector>
#include <algorithm>
#include "EarThwormDef.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
static void FreeBuffer(int n, AcDbVoidPtrArray &arEntPtrs)
{
AcDbEntity *pEnt = NULL;
while (arEntPtrs.length() > n)
{
pEnt = (AcDbEntity *)arEntPtrs.last();
pEnt->erase();
pEnt->close();
DELETE_PTR(pEnt);
arEntPtrs.removeLast();
}
}
KTAxisCmdGroup::KTAxisCmdGroup()
{
}
KTAxisCmdGroup::~KTAxisCmdGroup()
{
}
int KTAxisCmdGroup::MakeLineAxis()
{
CAcModuleResourceOverride myResources;
KTLineAxisGridDlg wndAxisGridDlg;
int nRes = wndAxisGridDlg.DoModal();
if (nRes == IDOK)
{
CString sLay,sNameFr;
AcDbObjectId idLayer = KTSetting::InitLayer(_T("LAY_AXIS"));
KTSetting::GetLayerName(_T("LAY_AXIS"),sLay,sNameFr);
KTLineAxisCreator creator;
creator.SetStartAngle(wndAxisGridDlg.m_dAngle);
for (int i = 0; i < 4; i++)
{
creator.SetArrayData(i, wndAxisGridDlg.m_arSpaceText[i]);
}
creator.Create();
AcDbVoidPtrArray arEntPtrs;
creator.GetAxisEntities(arEntPtrs);
int iIndex = arEntPtrs.length();
if (iIndex <= 0)
return FALSE;
AcDbEntity * pEnt = NULL;
while ((--iIndex) >= 0)
{
pEnt = (AcDbEntity *)arEntPtrs.at(iIndex);
pEnt->setLayer(sLay);
}
iIndex = arEntPtrs.length();
KTAxisGridJig axisGridJig;
axisGridJig.SetEntitiesPtrs(arEntPtrs);
if (axisGridJig.Doit())
{
while ((--iIndex) >= 0)
{
pEnt = (AcDbEntity *)arEntPtrs.at(iIndex);
ASSERT(NULL != pEnt);
pEnt->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(pEnt);
pEnt->close();
}
}
else
{
// jig不成功, 删除创建的对象,释放内存
while ((--iIndex) >= 0)
{
pEnt = (AcDbEntity*)arEntPtrs.at(iIndex);
ASSERT(NULL != pEnt);
delete pEnt;
}
}
}
return 0;
}
static void GetFencePickSet(AcDbObjectIdArray& ids, AcDbObjectId& cv, struct resbuf* pResbuf)
{
AcDbCurve* pCurve = NULL;
if (Acad::eOk == acdbOpenAcDbEntity((AcDbEntity*&)pCurve,cv,AcDb::kForRead))
{
AcGePoint3d pt1,pt2;
pCurve->getStartPoint(pt1);
pCurve->getEndPoint(pt2);
ads_point pt11,pt22;
pt11[X] = pt1.x;
pt11[Y] = pt1.y;
pt11[Z] = pt1.z;
pt22[X] = pt2.x;
pt22[Y] = pt2.y;
pt22[Z] = pt2.z;
acdbWcs2Ucs(pt11,pt11,false);
acdbWcs2Ucs(pt22,pt22,false);
pCurve->close();
CKTCadUtility::ZoomInCurrentView(pt1,pt2);
ads_name ss,ent;
acedSSGet(_T("F"),NULL,NULL,pResbuf,ss);
AcDbObjectId id;
Adesk::Int32 lLen = 0;
acedSSLength(ss,&lLen);
for (int i = 0;i < lLen;i++)
{
acedSSName(ss,i,ent);
acdbGetObjectId(id,ent);
ids.append(id);
}
acedSSFree(ss);
}
}
int KTAxisCmdGroup::LineAxisDim()
{
AecDbObjXDataMap xDataMap;
if (!KTModelLayoutXData::ReadModelXData(KT_PIPEINIT,xDataMap))
{
acedAlert(_T("\n系统未初始化!"));
return 0;
}
CAcModuleResourceOverride myResources;
KTTempTol TempTol(1e-3);
ads_name entCross, entFirst, entFinal;
ads_point ptPick1, ptPick2;
CString sText;
sText = _T("\n请选择起始轴线<退出>:");
CString sLayer,sTemp;
KTSetting::InitLayer(_T("LAY_AXIS"));
KTSetting::GetLayerName(_T("LAY_AXIS"),sLayer,sTemp);
struct resbuf* pResbuf = acutBuildList(RTDXF0, _T("LINE"), 8, sLayer, 0); ;
if (RTNORM != CKTCadUtility::SelectEntity1(sText,entCross,pResbuf,ptPick1))
{
acutRelRb(pResbuf);
return 0;
}
sText = _T("\n请选择终止轴线<退出>:");
int iRet = CKTCadUtility::SelectEntity1(sText,entFinal,pResbuf,ptPick2);
if (iRet != RTNORM)
{
acutRelRb(pResbuf);
return 0;
}
acdbUcs2Wcs(ptPick1,ptPick1,false);
acdbUcs2Wcs(ptPick2,ptPick2,false);
// 作为横断轴线, 取出与横断线相交的起始和终止轴线
BOOL bCross = (iRet == RTNONE);
if (bCross)
{
if (!KTCADUtilityEx::FindMaxBoundAxis(entCross, entFirst, entFinal, ptPick1, ptPick2))
{
acutRelRb(pResbuf);
return 0;
}
}
else
{
ads_name_set(entCross,entFirst);
}
// 单轴标注
if(ads_name_equal(entFirst,entFinal))
{
OnDimSingleAxisCurve(asPnt3d(ptPick1), entFirst, TRUE);
acutRelRb(pResbuf);
return 0;
}
int iType = KTCADUtilityEx::GetAxisRelationShip(entFirst, entFinal);
AcDbObjectId idFir,idFin;
acdbGetObjectId(idFir,entFirst);
acdbGetObjectId(idFin,entFinal);
if (idFir == idFin)
{
acutPrintf(_T("\n选择的轴线是同一条轴线!无法轴网标注"));
return 0;
}
AcDbObjectIdArray ids;
GetPalsFrom2Curve(ids,idFir, idFin);
ads_name ent;
for (int i = 0;i < ids.length();i++)
{
acdbGetAdsName(ent,ids.at(i));
acedRedraw(ent,3);
}
acedUpdateDisplay();
for (i = 0;i < ids.length();i++)
{
acdbGetAdsName(ent,ids.at(i));
acedRedraw(ent,4);
}
AcDbObjectId identCur, identOth;
BOOL bOutSide = FALSE;
BOOL bRadiator = FALSE;
BOOL bCirAngular = FALSE;
m_sStartLabel = _T("1");
switch (iType)
{
case 1: // 平行线轴网
KTCADUtilityEx::SortParallelAxisLine(ids);
OPENOBJ_BEGIN(idFir, AcDb::kForRead, AcDbLine, pLine);
if (pLine != NULL)
{
double dAngle = acutAngle( asDblArray(CKTCadUtility::Wcs2Ucs(pLine->startPoint())),
asDblArray(CKTCadUtility::Wcs2Ucs(pLine->endPoint())));
if(dAngle < 0.25 * PI || dAngle > 1.75 * PI || (dAngle > 0.75 * PI && dAngle < 1.25 * PI))
m_sStartLabel = _T("A");
}
OPENOBJ_END();
m_bUpside = KTCADUtilityEx::GetParallelAxisLineInitParam(asPnt3d(ptPick1), ids.first(),ids.last(),
bCross, m_ptCurStart, m_ptCurEnd, m_ptOthStart, m_ptOthEnd, m_vecCur, m_vecOth);
//求边界曲线
{
AcDbObjectIdArray idsFirs,idsFinal;
GetFencePickSet(idsFirs, idFir, pResbuf);
GetFencePickSet(idsFinal, idFin, pResbuf);
idsFirs.remove(idFir);
idsFinal.remove(idFin);
//
typedef KTCADUtilityEx::CSortPair<double, AcDbObjectId, KTCADUtilityEx::DoubleCompare> CEntSortPair;
AcArray<CEntSortPair> arEntSort;
CEntSortPair data;
//
AcDbXline xline;
xline.setBasePoint(m_ptCurStart);
xline.setUnitDir(m_ptOthStart - m_ptCurStart);
AcGePoint3d ptNear;
AcGePoint3dArray arpt;
long lPos = idsFirs.length();
int nF = -1;
while ((--lPos) >=0)
{
if (!idsFinal.find(idsFirs[lPos],nF))
continue;
arpt.setLogicalLength(0);
OPENOBJ_BEGIN(idsFirs[lPos], AcDb::kForRead, AcDbCurve, pCurve);
if (pCurve != NULL && Acad::eOk == xline.intersectWith(pCurve, AcDb::kExtendArg, arpt) &&
!arpt.isEmpty())
{
xline.getClosestPointTo(arpt[0], ptNear);
xline.getParamAtPoint(ptNear, data.compare);
data.value = idsFirs[lPos];
arEntSort.append(data);
}
OPENOBJ_END();
}
lPos = arEntSort.length();
if (lPos > 1)
{
QuickSort(arEntSort.asArrayPtr(), lPos);
xline.getClosestPointTo(m_ptCurStart, ptNear);
xline.getParamAtPoint(ptNear, data.compare);
if (fabs(arEntSort[0].compare - data.compare) < fabs(arEntSort[lPos-1].compare - data.compare))
{
identCur = arEntSort[0].value;
identOth = arEntSort[lPos-1].value;
}
else
{
identCur = arEntSort[lPos-1].value;
identOth = arEntSort[0].value;
}
}
}
break;
default:
{
acutRelRb(pResbuf);
return 0;
}
}
for (i = 0;i < ids.length();i++)
{
acdbGetAdsName(ent,ids.at(i));
acedRedraw(ent,3);
}
acedUpdateDisplay();
KTAxisDimLabelDlg dlg;
dlg.m_bPrevLabel = FALSE;
dlg.m_sStartLabel = m_sStartLabel;
dlg.m_iDimType = 2;
dlg.m_iLabelType = 2;
if (dlg.DoModal() != IDOK)
{
for (i = 0;i < ids.length();i++)
{
acdbGetAdsName(ent,ids.at(i));
acedRedraw(ent,4);
}
acutRelRb(pResbuf);
return 0;
}
for (i = 0;i < ids.length();i++)
{
acdbGetAdsName(ent,ids.at(i));
acedRedraw(ent,4);
}
m_iLabelType = dlg.m_iLabelType;
m_iDimType = dlg.m_iDimType;
m_sStartLabel = dlg.m_sStartLabel;
acutRelRb(pResbuf);
if (dlg.m_bPrevLabel)
{
AcGePoint3d ptPrev;
sText = _T("\n点取前接轴号<退出>:");
ads_name entPrev;
ads_point ptT;
pResbuf = acutBuildList(RTDXF0, _T("INSERT"), 8, sLayer, 2, _T("_axiso*"), 0);
if (RTNORM != CKTCadUtility::SelectEntity1(sText,entPrev,pResbuf,ptT))
{
acutRelRb(pResbuf);
return 0;
}
acutRelRb(pResbuf);
AcDbObjectId idPrev;
acdbGetObjectId(idPrev,entPrev);
OPENOBJ_BEGIN(idPrev, AcDb::kForRead, AcDbBlockReference, pBlkRef);
if (pBlkRef == NULL)
{
return 0;
}
AcDbObjectIterator* pIT = pBlkRef->attributeIterator();
if (pIT == NULL)
return 0;
pIT->start();
AcDbObjectId idAttr = pIT->objectId();
delete pIT;
if (!idAttr.isValid())
return 0;
AcDbAttribute* pAttr = NULL;
pBlkRef->openAttribute(pAttr, idAttr, AcDb::kForRead);
if (pAttr == NULL)
return 0;
LPTSTR pszText = pAttr->textString();
m_sStartLabel = pszText;
acutDelString(pszText);
pAttr->close();
ptPrev = pBlkRef->position();
OPENOBJ_END();
if(iType == 1)
{
if(!(m_ptCurStart-m_ptCurEnd).isParallelTo(CKTCadUtility::GetUcsYAxis()) )
{
m_bUpside = ptPick1[X] < ptPrev[X];
}
else
{
m_bUpside = ptPick1[Y] < ptPrev[Y];
}
if(m_bUpside)
{
AcGePoint3d pt;
pt = m_ptCurStart;
m_ptCurStart = m_ptCurEnd;
m_ptCurEnd = pt;
pt = m_ptOthStart;
m_ptOthStart = m_ptOthEnd;
m_ptOthEnd = pt;
}
}
m_sStartLabel = KTCADUtilityEx::GetNewAxisLabel(m_sStartLabel, TRUE);
}
ads_name entCur, entOth;
acdbGetAdsName(entCur,identCur);
acdbGetAdsName(entOth,identOth);
OnDimParallelAxisLine(ids, entCur, entOth);
return 1;
}
int KTAxisCmdGroup::SingleAxisDim()
{
AecDbObjXDataMap xDataMap;
if (!KTModelLayoutXData::ReadModelXData(KT_PIPEINIT, xDataMap))
{
acedAlert(_T("\n系统未初始化!"));
return 0;
}
CAcModuleResourceOverride myResources;
KTTempTol TempTol(1e-3);
ads_name entCross, entFirst, entFinal;
ads_point ptPick1, ptPick2;
CString sText;
sText = _T("\n请选择轴线<退出>:");
CString sLayer, sTemp;
KTSetting::InitLayer(_T("LAY_AXIS"));
KTSetting::GetLayerName(_T("LAY_AXIS"), sLayer, sTemp);
struct resbuf *pResbuf = acutBuildList(RTDXF0, _T("LINE"), 8, sLayer, 0); ;
if (RTNORM != CKTCadUtility::SelectEntity1(sText, entCross, pResbuf, ptPick1))
{
acutRelRb(pResbuf);
return 0;
}
acdbUcs2Wcs(ptPick1, ptPick1, false);
ads_name_set(entCross, entFirst);
OnDimSingleAxisCurve(asPnt3d(ptPick1), entFirst, TRUE);
acutRelRb(pResbuf);
return 1;
}
BOOL KTAxisCmdGroup::IsLineIsAxisLine(AcDbLine* pLn, AcDbVoidPtrArray& arEntPtrs, AcGePoint3d &ptOn, AcGePoint3d& ptBase)
{
AcGePoint3d ptS = pLn->startPoint();
AcGePoint3d ptE = pLn->endPoint();
AcDbEntity *pEnt = NULL;
for (int i = 0;i < arEntPtrs.length();i++)
{
pEnt = (AcDbEntity *)arEntPtrs.at(i);
AcDbCircle *pCir = AcDbCircle::cast(pEnt);
if (pCir != NULL)
{
if (fabs(ptS.distanceTo(pCir->center()) - pCir->radius()) < 1.e-1)
{
ptOn = ptS;
ptBase = ptE;
return TRUE;
}
if (fabs(ptE.distanceTo(pCir->center()) - pCir->radius()) < 1.e-1)
{
ptOn = ptE;
ptBase = ptS;
return TRUE;
}
}
}
return FALSE;
}
BOOL KTAxisCmdGroup::GetAxisDimBasePoint(AcDbObjectId& id, AcDbObjectId& idLn,AcGePoint3d& ptOn,AcGePoint3d& ptBase)
{
AcDbVoidPtrArray arEntPtrs;
AcDbExtents ext;
AcDbEntity *pEnt = NULL;
if (Acad::eOk == acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead))
{
pEnt->getGeomExtents(ext);
pEnt->explode(arEntPtrs);
pEnt->close();
}
pEnt = NULL;
//得到参考位置点
CString sLayer, sTemp;
KTSetting::InitLayer(_T("LAY_DIMAX"));
KTSetting::GetLayerName(_T("LAY_DIMAX"), sLayer, sTemp);
AcGePoint3d ptMin = ext.minPoint();
AcGePoint3d ptMax = ext.maxPoint();
ptMin.z = 0; ptMax.z = 0;
AcGeVector3d vtM = ptMax - ptMin;
vtM.normalize(); vtM *= 1.2; ptMin -= vtM; ptMax += vtM;
ads_point ptbox1, ptBox2;
acdbWcs2Ucs(asDblArray(ptMin), ptbox1, false);
acdbWcs2Ucs(asDblArray(ptMax), ptBox2, false);
struct resbuf *pResbuf = acutBuildList(RTDXF0, _T("LINE"), 8, sLayer, 0);
ads_name ss,ent;
acedSSGet(_T("C"), ptbox1, ptBox2, pResbuf, ss);
acutRelRb(pResbuf);
Adesk::Int32 nLen = 0;
acedSSLength(ss, &nLen);
BOOL bSuccess = FALSE;
AcDbObjectId idT;
for (Adesk::Int32 i = 0;i < nLen;i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(idT, ent);
if (Acad::eOk == acdbOpenAcDbEntity(pEnt, idT, AcDb::kForRead))
{
AcDbLine *pLn = AcDbLine::cast(pEnt);
if (pLn != NULL)
{
//判断直线端点落在轴号上
if ( IsLineIsAxisLine(pLn, arEntPtrs,ptOn,ptBase) )
{
idLn = idT;
bSuccess = TRUE;
pEnt->close();
break;
}
}
pEnt->close();
}
}
acedSSFree(ss);
FreeBuffer(0,arEntPtrs);
return bSuccess;
}
BOOL KTAxisCmdGroup::GetDimLable(AcDbObjectId&idPrev, TCHAR* pszDim)
{
BOOL bGet = FALSE;
OPENOBJ_BEGIN(idPrev, AcDb::kForRead, AcDbBlockReference, pBlkRef);
if (pBlkRef == NULL)
{
return bGet;
}
AcDbObjectIterator *pIT = pBlkRef->attributeIterator();
if (pIT == NULL)
return 0;
pIT->start();
AcDbObjectId idAttr = pIT->objectId();
delete pIT;
if (!idAttr.isValid())
return 0;
AcDbAttribute *pAttr = NULL;
pBlkRef->openAttribute(pAttr, idAttr, AcDb::kForRead);
if (pAttr == NULL)
return 0;
LPTSTR pszText = pAttr->textString();
_tcscpy(pszDim,pszText);
acutDelString(pszText);
bGet = TRUE;
pAttr->close();
OPENOBJ_END();
return bGet;
}
bool UnguardedSortAdimbs(ADimBs& abs1, ADimBs& abs2)
{
if (_ttoi(abs1.szDim) < _ttoi(abs2.szDim))
return true;
return false;
}
void KTAxisCmdGroup::SortADimBs(AcArray<ADimBs> &arDb1)
{
std::vector< ADimBs> vtDb1;
for (int i = 0;i < arDb1.length();i++)
{
ADimBs &abs = arDb1.at(i);
vtDb1.push_back(abs);
}
std::sort(vtDb1.begin(),vtDb1.end(), UnguardedSortAdimbs);
arDb1.removeAll();
for (int i = 0;i < vtDb1.size();i++)
{
arDb1.append(vtDb1.at(i));
}
}
static bool IsStepOntheLine(ADimBs &abs1, ADimBs &abs2)
{
AcGeLine3d ln(abs1.ptOn, abs1.ptBase);
AcGePoint3d pt2 = ln.closestPointTo(abs2.ptOn);
//共线,并且同轴号
if ( pt2.distanceTo(abs2.ptOn) < 1.e-2 &&
_tcscmp(abs1.szDim,abs2.szDim) == 0)
{
return true;
}
return false;
}
//对应 arDb1 的 arDb2
void KTAxisCmdGroup::PairAdimBs(AcArray<ADimBs> &arDb1, AcArray<ADimBs> &arDb2)
{
AcArray<ADimBs> arDb22;
for (int i = 0; i < arDb1.length(); i++)
{
ADimBs &abs = arDb1.at(i);
//acutPrintf(_T("\nabs1.dim = %s"),abs.szDim);
for (int j = 0;j < arDb2.length();j++)
{
ADimBs &abs2 = arDb2.at(j);
//共线
if (IsStepOntheLine(abs,abs2))
{
//acutPrintf(_T("\nabs2.dim = %s"), abs2.szDim);
arDb22.append(abs2);
}
}
}
arDb2.removeAll();
arDb2.append(arDb22);
}
BOOL KTAxisCmdGroup::Get2SideAxisDim(AcArray<ADimBs> &arDb1, AcArray<ADimBs> &arDb2, AcGePoint3d &ptOn, AcGePoint3d &ptBase)
{
CString sLayEn, sLayCn;
KTSetting::InitLayer(_T("LAY_DIMAX"));
KTSetting::GetLayerName(_T("LAY_DIMAX"), sLayEn, sLayCn);
KTCADSysVar<LPCTSTR, TRUE> clayer(_T("CLAYER"), sLayEn);
struct resbuf *pResbuf = acutBuildList(RTDXF0, _T("INSERT"), 8, sLayEn, 0); ;
ads_name ss, ent;
acedSSGet(_T("X"), NULL, NULL, pResbuf, ss);
AcDbObjectIdArray arId;
Adesk::Int32 nLen = 0;
acedSSLength(ss, &nLen);
AcDbObjectId id2,idLn;
for (Adesk::Int32 i = 0; i < nLen; i++)
{
acedSSName(ss, i, ent);
acdbGetObjectId(id2, ent);
arId.append(id2);
}
acedSSFree(ss);
acutRelRb(pResbuf);
AcGeLineSeg3d lnSeg0(ptOn,ptBase);
AcGeLine3d ln3d;
AcGeVector3d vtL,vtL0;
vtL0 = ptBase - ptOn;
ADimBs adbs;
AcGePoint3d ptOn1, ptBase1,ptM, ptInt;
for (int i = 0;i < arId.length();i++)
{
id2 = arId.at(i);
if (GetAxisDimBasePoint(id2,idLn, ptOn1, ptBase1))
{
adbs.id = id2;
adbs.idLn = idLn;
adbs.ptBase = ptBase1;
adbs.ptOn = ptOn1;
GetDimLable(id2, adbs.szDim);
//分集
Midpoint(ptOn1, ptBase1, ptM);
vtL = ptBase1 - ptOn1;
vtL.rotateBy(PI / 2.0, AcGeVector3d::kZAxis);
ln3d.set(ptM, vtL);
if (ln3d.intersectWith(lnSeg0, ptInt))
{
arDb1.append(adbs);
}
else
{
vtL = ptBase1 - ptOn1;
if (vtL.isParallelTo(vtL0))//平行
{
arDb2.append(adbs);
}
}
}
}
SortADimBs(arDb1);
//对应 arDb1 的 arDb2
PairAdimBs(arDb1, arDb2);
return TRUE;
}
BOOL KTAxisCmdGroup::InsertAxisLable(ADimBs &adbs1, AcGeMatrix3d &vtM)
{
AcDbEntity *pEnt1 = NULL, *pEnt2 = NULL;
if (Acad::eOk == acdbOpenAcDbEntity(pEnt1, adbs1.id, AcDb::kForRead))
{
AcDbEntity *pEnt11 = (AcDbEntity *)pEnt1->clone();
if (pEnt11 != NULL)
{
pEnt11->transformBy(vtM);
AcDbBlockReference *pBlkRef = AcDbBlockReference::cast(pEnt11);
AcDbObjectIterator *pIT = pBlkRef->attributeIterator();
if (pIT == NULL)
return 0;
for (pIT->start(); !pIT->done(); pIT->step())
{
AcDbEntity *pAttrEnt = pIT->entity();
AcDbAttribute *pAttr = AcDbAttribute::cast(pAttrEnt);
if (pAttr != NULL)
{
LPTSTR pszText = pAttr->textString();
CString sTxt;
sTxt.Format(_T("%d"), _ttoi(pszText) + 1);
pAttr->setTextString(sTxt);
acutDelString(pszText);
pAttrEnt->close();
break;
}
pAttrEnt->close();
}
delete pIT;
AcGePoint3d ptBase = adbs1.ptBase;
ptBase.transformBy(vtM);
AcGePoint3d ptOn = adbs1.ptOn;
ptOn.transformBy(vtM);
AcDbLine *pLine = new AcDbLine(ptOn, ptBase);
pLine->setLayer(pEnt1->layerId());
AcDbObjectId idTmp;
CKTCadUtility::AddToBlockTableRecord(idTmp, pLine);
pLine->close();
CKTCadUtility::AddToBlockTableRecord(idTmp, pBlkRef);
pBlkRef->close();
}
pEnt1->close();
}
return TRUE;
}
BOOL KTAxisCmdGroup::EraseAxisLable(ADimBs &adbs1)
{
AcDbEntity *pEnt1 = NULL, *pEnt2 = NULL;
if (Acad::eOk == acdbOpenAcDbEntity(pEnt1, adbs1.id, AcDb::kForWrite))
{
pEnt1->erase();
pEnt1->close();
}
if (Acad::eOk == acdbOpenAcDbEntity(pEnt1, adbs1.idLn, AcDb::kForWrite))
{
pEnt1->erase();
pEnt1->close();
}
return TRUE;
}
//后续轴号增加 2
BOOL KTAxisCmdGroup::NextLableIncrease(AcArray<ADimBs>& arDb1, int nNext, int nAddNo)
{
for (int i = nNext;i < arDb1.length();i++)
{
ADimBs &adbs1 = arDb1.at(i);
OPENOBJ_BEGIN(adbs1.id, AcDb::kForWrite, AcDbBlockReference, pBlkRef);
if (pBlkRef == NULL)
{
return 0;
}
AcDbObjectIterator *pIT = pBlkRef->attributeIterator();
if (pIT == NULL)
return 0;
pIT->start();
AcDbObjectId idAttr = pIT->objectId();
delete pIT;
if (!idAttr.isValid())
return 0;
AcDbAttribute *pAttr = NULL;
pBlkRef->openAttribute(pAttr, idAttr, AcDb::kForWrite);
if (pAttr == NULL)
return 0;
LPTSTR pszText = pAttr->textString();
CString sTxt;
sTxt.Format(_T("%d"), _ttoi(pszText) + nAddNo);
pAttr->setTextString(sTxt);
acutDelString(pszText);
pAttr->close();
OPENOBJ_END();
}
return TRUE;
}
int KTAxisCmdGroup::AddAxisLabel()
{
CString sLayEn, sLayCn;
KTSetting::InitLayer(_T("LAY_DIMAX"));
KTSetting::GetLayerName(_T("LAY_DIMAX"), sLayEn, sLayCn);
KTCADSysVar<LPCTSTR, TRUE> clayer(_T("CLAYER"), sLayEn);
double dScale = 100.0;
GetDocScale(dScale);
struct resbuf *pResbuf = acutBuildList(RTDXF0, _T("INSERT"), 8, sLayEn, 0); ;
CString sText;
sText = _T("\n请选择添补在它之后的轴号<退出>:");
ads_name entAxis;
ads_point pt;
if (RTNORM != CKTCadUtility::SelectEntity1(sText, entAxis, pResbuf, pt))
{
acutRelRb(pResbuf);
return 0;
}
AcDbObjectId id,idLn;
acdbGetObjectId(id, entAxis);
//获取轴号的参考位置
AcGePoint3d ptOn,ptBase;
if (!GetAxisDimBasePoint(id, idLn, ptOn,ptBase))
{
acutRelRb(pResbuf);
acutPrintf(_T("\n没有找到轴号的直线基点!"));
return 0;
}
//获取双侧排序的轴号
AcArray<ADimBs> arDb1, arDb2;
Get2SideAxisDim(arDb1, arDb2, ptOn, ptBase);
ads_point pt1, pt2,pt22;
acdbWcs2Ucs(asDblArray(ptBase), pt1,false);
if (RTNORM == acedGetPoint(pt1, _T("\n请点取新轴号的位置:"), pt2))
{
//复制一对轴标,然后改数值,后续依次加1
for(int i = 0;i < arDb1.length();i++)
{
if (arDb1.at(i).id == id)
{
acdbUcs2Wcs(pt2, pt22, false);
AcGeVector3d vtN = ptOn - ptBase;
AcGeVector3d vtM = asPnt3d(pt22) - ptBase;
vtM = vtM.orthoProject(vtN);
AcGeMatrix3d xM; xM.setToTranslation(vtM);
if (i < arDb2.length() )
{
InsertAxisLable(arDb1.at(i), xM);
// arDb1和arDb2数量可能不等,保护
if (i < arDb2.length())
InsertAxisLable(arDb2.at(i), xM);
//后续轴号增加 2
NextLableIncrease(arDb1,i + 1,1);
NextLableIncrease(arDb2,i + 1,1);
}
break;
}
}
}
acutRelRb(pResbuf);
return 1;
}
int KTAxisCmdGroup::DelAxisLabel()
{
CString sLayEn, sLayCn;
KTSetting::InitLayer(_T("LAY_DIMAX"));
KTSetting::GetLayerName(_T("LAY_DIMAX"), sLayEn, sLayCn);
KTCADSysVar<LPCTSTR, TRUE> clayer(_T("CLAYER"), sLayEn);
double dScale = 100.0;
GetDocScale(dScale);
struct resbuf *pResbuf = acutBuildList(RTDXF0, _T("INSERT"), 8, sLayEn, 0); ;
CString sText;
sText = _T("\n请选择要删除的轴号<退出>:");
ads_name entAxis;
ads_point pt;
if (RTNORM != CKTCadUtility::SelectEntity1(sText, entAxis, pResbuf, pt))
{
acutRelRb(pResbuf);
return 0;
}
AcDbObjectId id,idLn;
acdbGetObjectId(id, entAxis);
//获取轴号的参考位置
AcGePoint3d ptOn, ptBase;
if (!GetAxisDimBasePoint(id, idLn,ptOn, ptBase))
{
acutRelRb(pResbuf);
acutPrintf(_T("\n没有找到轴号的直线基点!"));
return 0;
}
//获取双侧排序的轴号
AcArray<ADimBs> arDb1, arDb2;
Get2SideAxisDim(arDb1, arDb2, ptOn, ptBase);
for (int i = 0; i < arDb1.length(); i++)
{
if (arDb1.at(i).id == id)
{
EraseAxisLable(arDb1.at(i));
// arDb1和arDb2数量可能不等,保护
if (i < arDb2.length())
EraseAxisLable(arDb2.at(i));
//后续轴号减去 1
NextLableIncrease(arDb1, i + 1, -1);
NextLableIncrease(arDb2, i + 1, -1);
break;
}
}
return 1;
}
BOOL KTAxisCmdGroup::OnDimSingleAxisCurve(AcGePoint3d& ptPick, ads_name ent, BOOL bDouble)
{
AcGePoint3d ptCur, ptOth;
AcGeVector3d vecCur, vecOth;
AcDbObjectId idEnt;
acdbGetObjectId(idEnt,ent);
OPENOBJ_BEGIN(idEnt, AcDb::kForRead, AcDbCurve, pCurve);
if (pCurve == NULL)
return FALSE;
if (pCurve->isKindOf(AcDbLine::desc()))
{
AcGePoint3d ptStart, ptEnd;
pCurve->getStartPoint(ptStart);
pCurve->getEndPoint(ptEnd);
ptPick.z = ptEnd.z;
if (ptPick.distanceTo(ptEnd) > ptPick.distanceTo(ptStart))
{
ptCur = ptStart;
ptOth = ptEnd;
}
else
{
ptCur = ptEnd;
ptOth = ptStart;
}
vecCur = ptCur - ptOth;
vecCur.normalize();
vecOth = -vecCur;
}
else
return FALSE;
OPENOBJ_END();
CString sLabel;
CString sText;
TCHAR szResult[MAX_PATH];
sText = _T("\n请输入轴号<空号>:");
switch(acedGetString(TRUE, sText, szResult))
{
case RTNORM:
sLabel = szResult;
break;
case RTNONE:
break;
default:
return FALSE;
}
AcDbObjectId idBlk = KTCADUtilityEx::InsertBlock(_T("_AXISO.DWG"));
if (!idBlk.isValid())
return FALSE;
CString sLayEn, sLayCn;
KTSetting::InitLayer(_T("LAY_DIMAX"));
KTSetting::GetLayerName(_T("LAY_DIMAX"),sLayEn,sLayCn);
KTCADSysVar<LPCTSTR,TRUE> clayer(_T("CLAYER"), sLayEn);
double dScale = 100.0;
GetDocScale(dScale);
double dHeight = 4.0 * dScale;
AcGeScale3d scScale(dHeight * 2.0);
AcGeVector3d vecCurLeader = vecCur * 40.0 * dScale;
AcGeVector3d vecOthLeader = vecOth * 40.0 * dScale;
AcGeVector3d vecCurLabel = vecCurLeader + vecCur * dHeight;
AcGeVector3d vecOthLabel = vecOthLeader + vecOth * dHeight;
AcDbObjectIdArray aridLabel;
AcDbObjectId idTemp;
// 当前侧轴标
AcDbLine* pLine = new AcDbLine(ptCur, ptCur + vecCurLeader);
ASSERT(pLine != NULL);
pLine->setLayer(sLayEn);
CKTCadUtility::AddToBlockTableRecord(idTemp,pLine);
pLine->close();
aridLabel.append(idTemp);
AcDbBlockReference* pRef = new AcDbBlockReference(ptCur + vecCurLabel, idBlk);
ASSERT(pRef != NULL);
pRef->setRotation(-CKTCadUtility::Wcs2Ucs(0.0));
pRef->setLayer(sLayEn);
pRef->setScaleFactors(scScale);
CKTCadUtility::AddToBlockTableRecord(idTemp,pRef);
aridLabel.append(idTemp);
KTCADUtilityEx::AppendAttribute(pRef, _T("A"), sLabel);
pRef->close();
// 另一侧轴标
if (bDouble)
{
pLine = new AcDbLine(ptOth, ptOth + vecOthLeader);
ASSERT(pLine != NULL);
pLine->setLayer(sLayEn);
CKTCadUtility::AddToBlockTableRecord(pLine);
pLine->close();
pRef = new AcDbBlockReference(ptOth + vecOthLabel, idBlk);
ASSERT(pRef != NULL);
pRef->setRotation(-CKTCadUtility::Wcs2Ucs(0.0));
pRef->setScaleFactors(scScale);
pRef->setLayer(sLayEn);
CKTCadUtility::AddToBlockTableRecord(pRef);
KTCADUtilityEx::AppendAttribute(pRef, _T("A"), sLabel);
pRef->close();
}
return TRUE;
}
BOOL KTAxisCmdGroup::GetPalsFrom2Curve(AcDbObjectIdArray& arId,const AcDbObjectId& idFr,const AcDbObjectId& idTo)
{
AcDbExtents ext1,ext2;
AcDbEntity* pEnt1 = NULL,*pEnt2 = NULL;
AcGeVector3d vt1,vt2;
if (Acad::eOk == acdbOpenAcDbEntity(pEnt1,idFr,AcDb::kForRead))
{
pEnt1->getGeomExtents(ext1);
AcDbLine* pLine1 = AcDbLine::cast(pEnt1);
if (pLine1 != NULL)
{
vt1 = pLine1->endPoint() - pLine1->startPoint();
}
pEnt1->close();
}
if (Acad::eOk == acdbOpenAcDbEntity(pEnt2,idTo,AcDb::kForRead))
{
pEnt2->getGeomExtents(ext2);
AcDbLine* pLine2 = AcDbLine::cast(pEnt2);
if (pLine2 != NULL)
{
vt2 = pLine2->endPoint() - pLine2->startPoint();
}
pEnt2->close();
}
ext1.addExt(ext2);
AcGePoint3d ptMin,ptMax;
ptMin = ext1.minPoint();
ptMax = ext1.maxPoint();
ads_point pt1,pt2,pt11,pt22;
pt1[X] = ptMin.x - 10.0;pt1[Y] = ptMin.y - 10.0;pt1[Z] = __max(ptMin.z,ptMax.z);
pt2[X] = ptMax.x + 10.0;pt2[Y] = ptMax.y + 10.0;pt2[Z] = __max(ptMax.z,ptMin.z);
acdbWcs2Ucs(pt1, pt11,false);
acdbWcs2Ucs(pt2, pt22,false);
CKTCadUtility::ZoomInCurrentView(ptMin,ptMax);
CString sLayEn, sLayCn;
KTSetting::InitLayer(_T("LAY_AXIS"));
KTSetting::GetLayerName(_T("LAY_AXIS"),sLayEn,sLayCn);
// 创建过滤条件
KTTempTol TempTol(0.001);
struct resbuf * pResbuf = NULL;
pResbuf = acutBuildList(RTDXF0, _T("LINE"), 8, sLayEn, 0);
ads_name ss;
acedSSGet(_T("C"),pt11, pt22,pResbuf,ss);
AcDbObjectId id;
Adesk::Int32 lLen = 0;
acedSSLength(ss,&lLen);
ads_name ent;
AcGeVector3d vt3;
for (int i = 0;i < lLen;i++)
{
acedSSName(ss,i,ent);
if (Acad::eOk == acdbGetObjectId(id,ent))
{
if (Acad::eOk == acdbOpenAcDbEntity(pEnt1,id,AcDb::kForRead))
{
AcDbLine* pLine3 = AcDbLine::cast(pEnt1);
if (pLine3 != NULL)
{
vt3 = pLine3->endPoint() - pLine3->startPoint();
if (vt1.isParallelTo(vt3))
{
arId.append(id);
}
}
pEnt1->close();
}
}
}
return arId.length() > 0;
}
BOOL KTAxisCmdGroup::GetDocScale(double& dPScale)
{
//获取初始化数据
AecDbObjXDataMap xDataMap;
KTModelLayoutXData::ReSet(xDataMap);
if (!KTModelLayoutXData::ReadModelXData(KT_PIPEINIT,xDataMap))
{
acedAlert(_T("\n系统未初始化!"));
return 0;
}
CString sDocScale = "";
xDataMap.GetAt(_T("Scale"),sDocScale);
int nIndex = sDocScale.Find(':',0);
dPScale = 1.0;
if (nIndex != -1)
{
dPScale = _ttof(sDocScale.Mid(nIndex + 1)) / _ttof(sDocScale.Mid(0,nIndex));
}
return TRUE;
}
BOOL KTAxisCmdGroup::OnDimParallelAxisLine(AcDbObjectIdArray& ssSet, ads_name entCurEdge,ads_name entOthEdge)
{
AcDbObjectId identCurEdge,identOthEdge;
acdbGetObjectId(identCurEdge,entCurEdge);
acdbGetObjectId(identOthEdge,entOthEdge);
AcDbObjectId idBlk = KTCADUtilityEx::InsertBlock(_T("_AXISO.DWG"));
if (!idBlk.isValid())
{
return FALSE;
}
CString sLay,sNameFr;
AcDbObjectId idLayer = KTSetting::InitLayer(_T("LAY_DIMAX"));
KTSetting::GetLayerName(_T("LAY_DIMAX"),sLay,sNameFr);
KTCADSysVar<LPCTSTR,TRUE> clayer(_T("CLAYER"), sLay);
AcDbObjectId idLineStyle = KTSetting::InitDimStyle(_T("DS_LINEAR"));
double dScale = 1.0;
GetDocScale(dScale);
double dHeight = 4.0 * dScale;
AcGeScale3d scScale(dHeight * 2.0);
// 标注开始点
AcGePoint3d ptCurPos = m_ptCurStart;
AcGePoint3d ptOthPos = m_ptOthStart;
// 标注方向
AcGeVector3d vecCurDir = m_ptCurEnd - m_ptCurStart;
vecCurDir.normalize();
AcGeVector3d vecOthDir = m_ptOthEnd - m_ptOthStart;
vecOthDir.normalize();
// 标号引线方向长度
AcGeVector3d vecCurLeader = m_vecCur * 40.0 * dScale;
AcGeVector3d vecOthLeader = m_vecOth * 40.0 * dScale;
// 标号位置方向长度
AcGeVector3d vecCurLabel = vecCurLeader + m_vecCur * dHeight;
AcGeVector3d vecOthLabel = vecOthLeader + m_vecOth * dHeight;
// 尺寸标注位置方向长度
AcGeVector3d vecCurDimPos = m_vecCur * 25.0 * dScale;
AcGeVector3d vecOthDimPos = m_vecOth * 25.0 * dScale;
// 当前尺寸标注起点和终点
AcGePoint3d ptCurDimStart = m_ptCurStart;
AcGePoint3d ptCurDimEnd = m_ptCurStart;
AcGePoint3d ptOthDimStart = m_ptOthStart;
AcGePoint3d ptOthDimEnd = m_ptOthStart;
// 标注旋转角度
double dCurAngle = acutAngle(asDblArray(m_ptCurStart), asDblArray(m_ptCurEnd));
double dOthAngle = acutAngle(asDblArray(m_ptOthStart), asDblArray(m_ptOthEnd));
// 当前标号
CString sLabel = m_sStartLabel;
// 当前轴线是否标注标号和尺寸
BOOL bCurExtOut = TRUE;
BOOL bOthExtOut = TRUE;
// 标注实体Id组
AcDbObjectIdArray aridCurLabel;
AcDbObjectIdArray aridOthLabel;
AcDbObjectIdArray aridCurDim;
AcDbObjectIdArray aridOthDim;
double dInterval;
//
AcGePoint3d ptTemp;
AcDbObjectId idTemp;
//
AcDbLine* pLine;
AcDbDimension* pDim;
AcDbBlockReference* pRef;
// 起始和终止循环
long l, lStep, lPrev;
long lLen = ssSet.length() - 1l;
if (m_bUpside)
{
l = lLen;
lStep = -1l;
}
else
{
l = 0l;
lStep = 1l;
}
CString sCurLabel, sOthLabel;
AcGePoint3d ptCurLabel, ptCur1, ptCur2, ptOthLabel, ptOth1, ptOth2;
BOOL bDrawCur = TRUE, bDrawOth = TRUE;
// 当前侧轴标
if (bDrawCur && IsLabelCurrent())
{
pLine = new AcDbLine(ptCurPos, ptCurPos + vecCurLeader);
ASSERT(pLine != NULL);
pLine->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(idTemp,pLine);
pLine->close();
aridCurLabel.append(idTemp);
pRef = new AcDbBlockReference(ptCurPos + vecCurLabel, idBlk);
ASSERT(pRef != NULL);
pRef->setRotation(-CKTCadUtility::Wcs2Ucs(0.0));
pRef->setLayer(sLay);
pRef->setScaleFactors(scScale);
CKTCadUtility::AddToBlockTableRecord(idTemp,pRef);
aridCurLabel.append(idTemp);
KTCADUtilityEx::AppendAttribute(pRef, _T("A"), sLabel);
pRef->close();
}
// 另一侧轴标
if (bDrawOth && IsLabelAnother())
{
pLine = new AcDbLine(ptOthPos, ptOthPos + vecOthLeader);
ASSERT(pLine != NULL);
pLine->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(idTemp,pLine);
pLine->close();
aridOthLabel.append(idTemp);
pRef = new AcDbBlockReference(ptOthPos + vecOthLabel, idBlk);
ASSERT(pRef != NULL);
pRef->setRotation(-CKTCadUtility::Wcs2Ucs(0.0));
pRef->setScaleFactors(scScale);
pRef->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(idTemp,pRef);
aridOthLabel.append(idTemp);
KTCADUtilityEx::AppendAttribute(pRef, _T("A"), sLabel);
pRef->close();
}
AcGePoint3dArray arpt;
for (lPrev = l, l += lStep; l > 0l && l < lLen; l += lStep, lPrev += lStep)
{
// 偏移
dInterval = KTCADUtilityEx::GetParallelAxisLineInterval(ssSet[lPrev], ssSet[l]);
sLabel = KTCADUtilityEx::GetNewAxisLabel(sLabel, TRUE);
ptCurPos += vecCurDir * dInterval;
ptOthPos += vecOthDir * dInterval;
ptCurDimEnd = ptCurPos;
ptOthDimEnd = ptOthPos;
bCurExtOut = KTCADUtilityEx::IsLinesIntersect(ptCurPos, vecCurDir, ssSet[l]);
bOthExtOut = KTCADUtilityEx::IsLinesIntersect(ptOthPos, vecOthDir, ssSet[l]);
OPENOBJ_BEGIN(ssSet[l], AcDb::kForRead, AcDbCurve, pCurve);
if (pCurve != NULL)
{
arpt.setLogicalLength(0);
OPENOBJ_BEGIN(identCurEdge, AcDb::kForRead, AcDbCurve, pEdge);
if (pEdge != NULL)
bCurExtOut = (pCurve->intersectWith(pEdge, AcDb::kOnBothOperands, arpt) == Acad::eOk && !arpt.isEmpty());
OPENOBJ_END();
arpt.setLogicalLength(0);
OPENOBJ_BEGIN(identOthEdge, AcDb::kForRead, AcDbCurve, pEdge);
if (pEdge != NULL)
bOthExtOut = (pCurve->intersectWith(pEdge, AcDb::kOnBothOperands, arpt) == Acad::eOk && !arpt.isEmpty());
OPENOBJ_END();
}
OPENOBJ_END();
// 当前侧尺寸
if (IsDimCurrent() && bCurExtOut)
{
ptTemp = KTCADUtilityEx::GetCenterPoint(ptCurDimStart, ptCurDimEnd) + vecCurDimPos;
pDim = new AcDbRotatedDimension(dCurAngle, ptCurDimStart, ptCurDimEnd, ptTemp, NULL, idLineStyle);
pDim->setElevation(ptTemp.z);
ASSERT(pDim != NULL);
pDim->setHorizontalRotation(-CKTCadUtility::Ucs2Wcs(0.0));
pDim->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(idTemp,pDim);
pDim->close();
aridCurDim.append(idTemp);
ptCurDimStart = ptCurDimEnd;
}
// 另一侧尺寸
if (IsDimAnother() && bOthExtOut)
{
ptTemp = KTCADUtilityEx::GetCenterPoint(ptOthDimStart, ptOthDimEnd) + vecOthDimPos;
pDim = new AcDbRotatedDimension(dOthAngle, ptOthDimStart, ptOthDimEnd, ptTemp, NULL, idLineStyle);
pDim->setElevation(ptTemp.z);
ASSERT(pDim != NULL);
pDim->setHorizontalRotation(-CKTCadUtility::Ucs2Wcs(0.0));
pDim->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(idTemp,pDim);
pDim->close();
aridOthDim.append(idTemp);
ptOthDimStart = ptOthDimEnd;
}
// 当前侧轴标
if (IsLabelCurrent() && bCurExtOut)
{
pLine = new AcDbLine(ptCurPos, ptCurPos + vecCurLeader);
ASSERT(pLine != NULL);
pLine->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(idTemp,pLine);
pLine->close();
aridCurLabel.append(idTemp);
pRef = new AcDbBlockReference(ptCurPos + vecCurLabel, idBlk);
ASSERT(pRef != NULL);
pRef->setRotation(-CKTCadUtility::Wcs2Ucs(0.0));
pRef->setLayer(sLay);
pRef->setScaleFactors(scScale);
CKTCadUtility::AddToBlockTableRecord(idTemp,pRef);
aridCurLabel.append(idTemp);
KTCADUtilityEx::AppendAttribute(pRef, _T("A"), sLabel);
pRef->close();
}
// 另一侧轴标
if (IsLabelAnother() && bOthExtOut)
{
pLine = new AcDbLine(ptOthPos, ptOthPos + vecOthLeader);
ASSERT(pLine != NULL);
pLine->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(idTemp,pLine);
pLine->close();
aridOthLabel.append(idTemp);
pRef = new AcDbBlockReference(ptOthPos + vecOthLabel, idBlk);
ASSERT(pRef != NULL);
pRef->setRotation(-CKTCadUtility::Wcs2Ucs(0.0));
pRef->setScaleFactors(scScale);
pRef->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(idTemp,pRef);
aridOthLabel.append(idTemp);
KTCADUtilityEx::AppendAttribute(pRef, _T("A"), sLabel);
pRef->close();
}
}
// 偏移
if (l < 0) l = ssSet.length() - 1;
dInterval = KTCADUtilityEx::GetParallelAxisLineInterval(ssSet[lPrev], ssSet[l]);
sLabel = KTCADUtilityEx::GetNewAxisLabel(sLabel, TRUE);
ptCurPos += vecCurDir * dInterval;
ptOthPos += vecOthDir * dInterval;
ptCurDimEnd = ptCurPos;
ptOthDimEnd = ptOthPos;
// 当前侧尺寸
if (IsDimCurrent())
{
ptTemp = KTCADUtilityEx::GetCenterPoint(ptCurDimStart, ptCurDimEnd) + vecCurDimPos;
pDim = new AcDbRotatedDimension(dCurAngle, ptCurDimStart, ptCurDimEnd, ptTemp, NULL, idLineStyle);
pDim->setElevation(ptTemp.z);
ASSERT(pDim != NULL);
pDim->setHorizontalRotation(-CKTCadUtility::Ucs2Wcs(0.0));
pDim->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(idTemp,pDim);
pDim->close();
aridCurDim.append(idTemp);
ptCurDimStart = ptCurDimEnd;
}
// 另一侧尺寸
if (IsDimAnother())
{
ptTemp = KTCADUtilityEx::GetCenterPoint(ptOthDimStart, ptOthDimEnd) + vecOthDimPos;
pDim = new AcDbRotatedDimension(dOthAngle, ptOthDimStart, ptOthDimEnd, ptTemp, NULL, idLineStyle);
pDim->setElevation(ptTemp.z);
ASSERT(pDim != NULL);
pDim->setHorizontalRotation(-CKTCadUtility::Ucs2Wcs(0.0));
pDim->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(idTemp,pDim);
pDim->close();
aridOthDim.append(idTemp);
ptOthDimStart = ptOthDimEnd;
}
// 当前侧轴标
if (IsLabelCurrent())
{
pLine = new AcDbLine(ptCurPos, ptCurPos + vecCurLeader);
ASSERT(pLine != NULL);
pLine->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(idTemp,pLine);
pLine->close();
aridCurLabel.append(idTemp);
pRef = new AcDbBlockReference(ptCurPos + vecCurLabel, idBlk);
ASSERT(pRef != NULL);
pRef->setRotation(-CKTCadUtility::Wcs2Ucs(0.0));
pRef->setLayer(sLay);
pRef->setScaleFactors(scScale);
CKTCadUtility::AddToBlockTableRecord(idTemp,pRef);
aridCurLabel.append(idTemp);
KTCADUtilityEx::AppendAttribute(pRef, _T("A"), sLabel);
pRef->close();
}
// 另一侧轴标
if (IsLabelAnother())
{
pLine = new AcDbLine(ptOthPos, ptOthPos + vecOthLeader);
ASSERT(pLine != NULL);
pLine->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(idTemp,pLine);
pLine->close();
aridOthLabel.append(idTemp);
pRef = new AcDbBlockReference(ptOthPos + vecOthLabel, idBlk);
ASSERT(pRef != NULL);
pRef->setRotation(-CKTCadUtility::Wcs2Ucs(0.0));
pRef->setScaleFactors(scScale);
pRef->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(idTemp,pRef);
aridOthLabel.append(idTemp);
KTCADUtilityEx::AppendAttribute(pRef, _T("A"), sLabel);
pRef->close();
}
// 当前侧总尺寸
if (IsDimCurrent())
{
ptTemp = KTCADUtilityEx::GetCenterPoint(m_ptCurStart, m_ptCurEnd) + vecCurDimPos + vecCurDimPos.normal() * 8.0 * dScale;
pDim = new AcDbRotatedDimension(dCurAngle, m_ptCurStart, m_ptCurEnd, ptTemp, NULL, idLineStyle);
pDim->setElevation(ptTemp.z);
ASSERT(pDim != NULL);
pDim->setHorizontalRotation(-CKTCadUtility::Ucs2Wcs(0.0));
pDim->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(idTemp,pDim);
pDim->close();
aridCurDim.append(idTemp);
}
// 另一侧总尺寸
if (IsDimAnother())
{
ptTemp = KTCADUtilityEx::GetCenterPoint(m_ptOthStart, m_ptOthEnd) + vecOthDimPos + vecOthDimPos.normal() * 8.0 * dScale;
pDim = new AcDbRotatedDimension(dOthAngle, m_ptOthStart, m_ptOthEnd, ptTemp, NULL, idLineStyle);
pDim->setElevation(ptTemp.z);
ASSERT(pDim != NULL);
pDim->setHorizontalRotation(-CKTCadUtility::Ucs2Wcs(0.0));
pDim->setLayer(sLay);
CKTCadUtility::AddToBlockTableRecord(idTemp,pDim);
pDim->close();
aridOthDim.append(idTemp);
}
return TRUE;
}