424 lines
9.8 KiB
C++
424 lines
9.8 KiB
C++
#include "stdafx.h"
|
|
#include "resource.h"
|
|
#include "KTLineAxisCreator.h"
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
const double CONCROSS = (100.0);
|
|
const double CONDIST = (1000.0);
|
|
const double CUTDIST = (1500.0);
|
|
|
|
KTLineAxisCreator::KTLineAxisCreator()
|
|
{
|
|
m_bForPreview = FALSE;
|
|
m_dAngle = 0.0;
|
|
m_dTotalXWidth = 0.0;
|
|
m_dTotalYWidth = 0.0;
|
|
}
|
|
|
|
KTLineAxisCreator::~KTLineAxisCreator()
|
|
{
|
|
|
|
}
|
|
|
|
AcGePoint3d KTLineAxisCreator::basePoint()
|
|
{
|
|
return AcGePoint3d::kOrigin;
|
|
}
|
|
|
|
void KTLineAxisCreator::Create(BOOL bForPreview)
|
|
{
|
|
m_bForPreview = bForPreview;
|
|
m_dTotalXWidth = (GetLast(0) > GetLast(1)) ? GetLast(0) : GetLast(1);
|
|
m_dTotalYWidth = (GetLast(2) > GetLast(3)) ? GetLast(2) : GetLast(3);
|
|
if (m_arDist[0].GetSize() != 0 || m_arDist[1].GetSize() != 0)
|
|
{
|
|
CreateXAxis();
|
|
}
|
|
if (m_arDist[2].GetSize() != 0 || m_arDist[3].GetSize() != 0)
|
|
{
|
|
CreateYAxis();
|
|
}
|
|
if (bForPreview)
|
|
{
|
|
CreateInsertMark();
|
|
}
|
|
}
|
|
|
|
void KTLineAxisCreator::SetStartAngle(double dAngle)
|
|
{
|
|
m_dAngle = dAngle;
|
|
while (m_dAngle > 180.0)
|
|
{
|
|
m_dAngle -= 180;
|
|
}
|
|
while (m_dAngle < 0)
|
|
{
|
|
m_dAngle += 180;
|
|
}
|
|
if (m_dAngle < 0.00001 && m_dAngle > -0.00001)
|
|
{
|
|
m_dAngle = 90;
|
|
}
|
|
m_dAngle = m_dAngle / 180 * PI;
|
|
}
|
|
|
|
void KTLineAxisCreator::InsertOffset(int nIndex, double dOffset)
|
|
{
|
|
if (dOffset < 0.00001 && dOffset > -0.00001)
|
|
return;
|
|
m_arDist[nIndex].InsertAt(0, dOffset);
|
|
}
|
|
|
|
void KTLineAxisCreator::SetArrayData(int nIndex, const CStringArray &arSpaceText)
|
|
{
|
|
for (int i = 0; i < arSpaceText.GetSize(); i++)
|
|
{
|
|
PushToArray(nIndex, arSpaceText.GetAt(i));
|
|
}
|
|
}
|
|
|
|
double KTLineAxisCreator::GetLast(int nIndex)
|
|
{
|
|
return (m_arDist[nIndex].GetSize() == 0) ? 0.0 : m_arDist[nIndex].GetAt(m_arDist[nIndex].GetSize() - 1);
|
|
}
|
|
|
|
BOOL KTLineAxisCreator::IsTwoInOne(double dCurLen, int nComIndex)
|
|
{
|
|
BOOL bRet = FALSE;
|
|
for (int i = 0; i < m_arDist[nComIndex].GetSize(); i++)
|
|
{
|
|
if ((dCurLen - m_arDist[nComIndex].GetAt(i)) < 0.00001 &&
|
|
(dCurLen - m_arDist[nComIndex].GetAt(i)) > -0.00001)
|
|
{
|
|
bRet = TRUE;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return bRet;
|
|
}
|
|
|
|
void KTLineAxisCreator::PushToArray(int nIndex, CString strSrc)
|
|
{
|
|
int nSize = 1;
|
|
int nFind = -1;
|
|
double dDist = 0.0;
|
|
double dTotal = 0.0;
|
|
CString strSize;
|
|
CString strData;
|
|
|
|
if ((nFind = strSrc.Find('*', 0)) > -1)
|
|
{
|
|
strData = strSrc.Left(nFind);
|
|
strSize = strSrc.Mid(nFind + 1);
|
|
nSize = _ttoi(strSize);
|
|
dDist = _ttof(strData);
|
|
}
|
|
else
|
|
{
|
|
dDist = _ttof(strSrc);
|
|
}
|
|
dDist = (dDist);
|
|
for (int i = 0; i < nSize; i++)
|
|
{
|
|
dTotal = 0.0;
|
|
dTotal = GetLast(nIndex) + dDist;
|
|
m_arDist[nIndex].Add(dTotal);
|
|
}
|
|
}
|
|
|
|
void KTLineAxisCreator::CreateXAxis()
|
|
{
|
|
int i = 0;
|
|
int upSize = m_arDist[0].GetSize();
|
|
int downSize = m_arDist[1].GetSize();
|
|
if (GetLast(0) > GetLast(1))
|
|
{
|
|
upSize -= 1;
|
|
}
|
|
else
|
|
{
|
|
downSize -= 1;
|
|
}
|
|
|
|
double dTotalLen = 0.0;
|
|
AcGePoint3d ptBaseDown, ptBaseUp, ptStart, ptEnd;
|
|
ptBaseDown = AcGePoint3d::kOrigin - CONDIST * AcGeVector3d::kYAxis;
|
|
if (m_arDist[2].GetSize() == 0 && m_arDist[3].GetSize() == 0)
|
|
{
|
|
double dSingleDist = (m_bForPreview) ? CUTDIST : GetSingleDist();
|
|
dTotalLen = dSingleDist + CONDIST * 2;
|
|
}
|
|
else
|
|
{
|
|
dTotalLen = m_dTotalXWidth / fabs(tan(m_dAngle)) + m_dTotalYWidth / sin(m_dAngle)
|
|
+ CONDIST * 2;
|
|
}
|
|
ptBaseUp = ptBaseDown + dTotalLen * AcGeVector3d::kYAxis;
|
|
//...起始线
|
|
AcDbLine * pLine = NULL;
|
|
pLine = new AcDbLine(ptBaseUp, ptBaseDown);
|
|
m_arEntPtrs.append(pLine);
|
|
// 上开
|
|
double dUpLen = (m_arDist[1].GetSize() == 0) ? dTotalLen : dTotalLen - CUTDIST;
|
|
for (i = 0; i < upSize; i++)
|
|
{
|
|
ptStart = ptBaseUp + m_arDist[0].GetAt(i) * AcGeVector3d::kXAxis;
|
|
if (IsTwoInOne(m_arDist[0].GetAt(i), 1))
|
|
{
|
|
ptEnd = ptStart - dTotalLen * AcGeVector3d::kYAxis;
|
|
}
|
|
else
|
|
{
|
|
ptEnd = ptStart - dUpLen * AcGeVector3d::kYAxis;
|
|
}
|
|
pLine = new AcDbLine(ptStart, ptEnd);
|
|
m_arEntPtrs.append(pLine);
|
|
}
|
|
//...终了线
|
|
ptStart = ptBaseDown + m_dTotalXWidth * AcGeVector3d::kXAxis;
|
|
ptEnd = ptStart + dTotalLen * AcGeVector3d::kYAxis;
|
|
pLine = new AcDbLine(ptStart, ptEnd);
|
|
m_arEntPtrs.append(pLine);
|
|
m_arDirNum[0] = m_arEntPtrs.length();
|
|
// 下开
|
|
double dDownLen = (m_arDist[0].GetSize() == 0) ? dTotalLen : dTotalLen - CUTDIST;
|
|
for (i = 0; i < downSize; i++)
|
|
{
|
|
if (IsTwoInOne(m_arDist[1].GetAt(i), 0))
|
|
{
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
ptStart = ptBaseDown + m_arDist[1].GetAt(i) * AcGeVector3d::kXAxis;
|
|
ptEnd = ptStart + dDownLen * AcGeVector3d::kYAxis;
|
|
pLine = new AcDbLine(ptStart, ptEnd);
|
|
m_arEntPtrs.append(pLine);
|
|
}
|
|
}
|
|
m_arDirNum[1] = m_arEntPtrs.length();
|
|
}
|
|
|
|
void KTLineAxisCreator::CreateYAxis()
|
|
{
|
|
double xVt = sin(m_dAngle);
|
|
double yVt = cos(m_dAngle);
|
|
if (xVt < 0.00001 && xVt > -0.00001) xVt = 0;
|
|
if (yVt < 0.00001 && yVt > -0.00001) yVt = 0;
|
|
AcGeVector3d vtXAxis(xVt, yVt, 0);
|
|
AcGeVector3d vtYAxis(-yVt, xVt, 0);
|
|
|
|
if (m_dAngle > (PI / 2))
|
|
{
|
|
CreateBYAxis(vtXAxis, vtYAxis);
|
|
}
|
|
else
|
|
{
|
|
CreateSYAxis(vtXAxis, vtYAxis);
|
|
}
|
|
}
|
|
|
|
//锐角轴线
|
|
void KTLineAxisCreator::CreateSYAxis(AcGeVector3d vtXAxis, AcGeVector3d vtYAxis)
|
|
{
|
|
int i = 0;
|
|
double dTotalLen = 0.0;
|
|
AcGePoint3d ptBaseLeft, ptBaseRight, ptStart, ptEnd;
|
|
int leftSize = m_arDist[2].GetSize();
|
|
int rightSize = m_arDist[3].GetSize();
|
|
if (GetLast(2) > GetLast(3))
|
|
{
|
|
leftSize -= 1;
|
|
}
|
|
else
|
|
{
|
|
rightSize -= 1;
|
|
}
|
|
|
|
ptBaseLeft = AcGePoint3d::kOrigin - CONDIST * vtXAxis;
|
|
if (m_arDist[0].GetSize() == 0 && m_arDist[1].GetSize() == 0)
|
|
{
|
|
double dSingleDist = (m_bForPreview) ? CUTDIST : GetSingleDist();
|
|
dTotalLen = dSingleDist + CONDIST * 2;
|
|
}
|
|
else
|
|
{
|
|
dTotalLen = m_dTotalXWidth / sin(m_dAngle) + m_dTotalYWidth / fabs(tan(m_dAngle))
|
|
+ CONDIST * 2;
|
|
}
|
|
ptBaseRight = ptBaseLeft + dTotalLen * vtXAxis;
|
|
//...起始线
|
|
AcDbLine *pLine = NULL;
|
|
pLine = new AcDbLine(ptBaseLeft, ptBaseRight);
|
|
m_arEntPtrs.append(pLine);
|
|
//左进
|
|
double dLeftLen = (m_arDist[3].GetSize() == 0) ? dTotalLen : dTotalLen - CUTDIST;
|
|
for (i = 0; i < leftSize; i++)
|
|
{
|
|
ptStart = ptBaseLeft + m_arDist[2].GetAt(i) * vtYAxis;
|
|
if (IsTwoInOne(m_arDist[2].GetAt(i), 3))
|
|
{
|
|
ptEnd = ptStart + dTotalLen * vtXAxis;
|
|
}
|
|
else
|
|
{
|
|
ptEnd = ptStart + dLeftLen * vtXAxis;
|
|
}
|
|
pLine = new AcDbLine(ptStart, ptEnd);
|
|
m_arEntPtrs.append(pLine);
|
|
}
|
|
//终了线
|
|
ptStart = ptBaseLeft + m_dTotalYWidth * vtYAxis;
|
|
ptEnd = ptStart + dTotalLen * vtXAxis;
|
|
pLine = new AcDbLine(ptStart, ptEnd);
|
|
m_arEntPtrs.append(pLine);
|
|
m_arDirNum[2] = m_arEntPtrs.length();
|
|
//右进
|
|
double dRightLen = (m_arDist[2].GetSize() == 0) ? dTotalLen : dTotalLen - CUTDIST;
|
|
for (i = 0; i < rightSize; i++)
|
|
{
|
|
if (IsTwoInOne(m_arDist[3].GetAt(i), 2))
|
|
{
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
ptStart = ptBaseRight + m_arDist[3].GetAt(i) * vtYAxis;
|
|
ptEnd = ptStart - dRightLen * vtXAxis;
|
|
pLine = new AcDbLine(ptStart, ptEnd);
|
|
m_arEntPtrs.append(pLine);
|
|
}
|
|
}
|
|
m_arDirNum[3] = m_arEntPtrs.length();
|
|
}
|
|
|
|
//钝角轴线
|
|
void KTLineAxisCreator::CreateBYAxis(AcGeVector3d vtXAxis, AcGeVector3d vtYAxis)
|
|
{
|
|
int i = 0;
|
|
double dTotalLen = 0.0;
|
|
double dXTotLen = m_dTotalXWidth / fabs(tan(m_dAngle)) + m_dTotalYWidth / sin(m_dAngle);
|
|
AcGePoint3d ptBaseLeft, ptBaseRight, ptStart, ptEnd;
|
|
int leftSize = m_arDist[2].GetSize();
|
|
int rightSize = m_arDist[3].GetSize();
|
|
if (GetLast(2) > GetLast(3))
|
|
{
|
|
leftSize -= 1;
|
|
}
|
|
else
|
|
{
|
|
rightSize -= 1;
|
|
}
|
|
|
|
ptBaseLeft = AcGePoint3d::kOrigin - CONDIST * vtXAxis + dXTotLen * AcGeVector3d::kYAxis;
|
|
if (m_arDist[0].GetSize() == 0 && m_arDist[1].GetSize() == 0)
|
|
{
|
|
double dSingleDist = (m_bForPreview) ? CUTDIST : GetSingleDist();
|
|
dTotalLen = dSingleDist + CONDIST * 2;
|
|
}
|
|
else
|
|
{
|
|
dTotalLen = m_dTotalXWidth / sin(m_dAngle) + m_dTotalYWidth / fabs(tan(m_dAngle))
|
|
+ CONDIST * 2;
|
|
}
|
|
ptBaseRight = ptBaseLeft + dTotalLen * vtXAxis;
|
|
//...起始线
|
|
AcDbLine *pLine = NULL;
|
|
pLine = new AcDbLine(ptBaseLeft, ptBaseRight);
|
|
m_arEntPtrs.append(pLine);
|
|
//左进
|
|
double dLeftLen = (m_arDist[3].GetSize() == 0) ? dTotalLen : dTotalLen - CUTDIST;
|
|
for (i = 0; i < leftSize; i++)
|
|
{
|
|
ptStart = ptBaseLeft - m_arDist[2].GetAt(i) * vtYAxis;
|
|
if (IsTwoInOne(m_arDist[2].GetAt(i), 3))
|
|
{
|
|
ptEnd = ptStart + dTotalLen * vtXAxis;
|
|
}
|
|
else
|
|
{
|
|
ptEnd = ptStart + dLeftLen * vtXAxis;
|
|
}
|
|
pLine = new AcDbLine(ptStart, ptEnd);
|
|
m_arEntPtrs.append(pLine);
|
|
}
|
|
//终了线
|
|
ptStart = ptBaseLeft - m_dTotalYWidth * vtYAxis;
|
|
ptEnd = ptStart + dTotalLen * vtXAxis;
|
|
pLine = new AcDbLine(ptStart, ptEnd);
|
|
m_arEntPtrs.append(pLine);
|
|
m_arDirNum[2] = m_arEntPtrs.length();
|
|
//右进
|
|
double dRightLen = (m_arDist[2].GetSize() == 0) ? dTotalLen : dTotalLen - CUTDIST;
|
|
for (i = 0; i < rightSize; i++)
|
|
{
|
|
if (IsTwoInOne(m_arDist[3].GetAt(i), 2))
|
|
{
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
ptStart = ptBaseRight - m_arDist[3].GetAt(i) * vtYAxis;
|
|
ptEnd = ptStart - dRightLen * vtXAxis;
|
|
pLine = new AcDbLine(ptStart, ptEnd);
|
|
m_arEntPtrs.append(pLine);
|
|
}
|
|
}
|
|
m_arDirNum[3] = m_arEntPtrs.length();
|
|
}
|
|
|
|
void KTLineAxisCreator::CreateInsertMark()
|
|
{
|
|
if (m_arDist[0].GetSize() == 0 && m_arDist[1].GetSize() == 0 &&
|
|
m_arDist[2].GetSize() == 0 && m_arDist[3].GetSize() == 0)
|
|
return;
|
|
|
|
AcGeVector3d vtUL(-1, 1, 0);
|
|
AcGeVector3d vtUR(1, 1, 0);
|
|
AcGePoint3d ptStart, ptEnd;
|
|
AcDbLine *pLine = NULL;
|
|
|
|
ptStart = AcGePoint3d::kOrigin - CONCROSS * vtUR;
|
|
ptEnd = AcGePoint3d::kOrigin + CONCROSS * vtUR;
|
|
pLine = new AcDbLine(ptStart, ptEnd);
|
|
pLine->setThickness(2.0);
|
|
m_arEntPtrs.append(pLine);
|
|
|
|
ptStart = AcGePoint3d::kOrigin - CONCROSS * vtUL;
|
|
ptEnd = AcGePoint3d::kOrigin + CONCROSS * vtUL;
|
|
pLine = new AcDbLine(ptStart, ptEnd);
|
|
pLine->setThickness(2.0);
|
|
m_arEntPtrs.append(pLine);
|
|
}
|
|
|
|
double KTLineAxisCreator::GetSingleDist()
|
|
{
|
|
double dDist = 1500.0;
|
|
if (m_dTotalXWidth < 0.1)
|
|
dDist = m_dTotalYWidth;
|
|
else
|
|
dDist = m_dTotalXWidth;
|
|
|
|
CString strPrompt;
|
|
strPrompt.Format(IDS_AXIS_LENGTH, dDist);
|
|
double dGet = dDist;
|
|
int nRes = acedGetDist(NULL, strPrompt, &dGet);
|
|
if (nRes == RTNORM)
|
|
{
|
|
dDist = dGet;
|
|
}
|
|
return dDist;
|
|
}
|
|
|
|
int KTLineAxisCreator::GetAxisEntities(AcDbVoidPtrArray& arEntPtrs)
|
|
{
|
|
arEntPtrs.append(m_arEntPtrs);
|
|
return m_arEntPtrs.length();
|
|
}
|