3103 lines
71 KiB
C++
3103 lines
71 KiB
C++
// AxisGridSheet.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "AxisGridSheet.h"
|
|
#include "float.h"
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
// command
|
|
void AxisGrid()
|
|
{
|
|
CTemporaryResourceOverride vTmp;
|
|
CAxisGridSheet sheet(acedGetAcadFrame());
|
|
sheet.DoModal();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////
|
|
// Data And Funtion
|
|
//extern GEOAPI int DragPickSet(PickSet &ss, XPoint &ptBase);
|
|
extern TARCH_IMPEXP int g_nRunMode;
|
|
extern TARCH_IMPEXP double g_dBaseDist;
|
|
|
|
const TCHAR* SZ_SIZES[] =
|
|
{_T("1500"), _T("1800"), _T("2100"), _T("2400"), _T("2700"), _T("3000"), _T("3300"), _T("3600"), _T("3900")
|
|
, _T("4200"), _T("4500"), _T("4800"), _T("5400"), _T("6000"), _T("6600"), _T("7500"), _T("8000"), _T("9000")};
|
|
const TCHAR* SZ_ANGLES[] =
|
|
{_T("10"), _T("15"), _T("20"), _T("25"), _T("30"), _T("35"), _T("40"), _T("45"), _T("60"), _T("90"), _T("120"), _T("150")};
|
|
|
|
int CmpAxisGridPoint(const XPoint *pt1, const XPoint *pt2)
|
|
{
|
|
if(fabs(pt1->y - pt2->y) < 1E-6)
|
|
{
|
|
if(pt1->x < pt2->x)
|
|
return -1;
|
|
else
|
|
return 1;
|
|
}
|
|
else if(pt1->y < pt2->y)
|
|
return -1;
|
|
else
|
|
return 1;
|
|
}
|
|
|
|
static void Disperse(double nDistBeg, PDList<TCountAndSize> &vtOne, PDList<double> &vtDistSize)
|
|
{
|
|
for(int i=0; i<vtOne.GetDataNum(); i++)
|
|
{
|
|
TCountAndSize &rec = *vtOne[i];
|
|
for(int j=0; j<rec.m_nCount; j++)
|
|
{
|
|
nDistBeg += rec.m_dSize;
|
|
vtDistSize.AddTail(new double(nDistBeg));
|
|
}
|
|
}
|
|
}
|
|
|
|
/////////////////////////////////
|
|
// TAxisGrid
|
|
|
|
BEGIN_MESSAGE_MAP(TAxisGrid, WDGrid)
|
|
ON_WM_RBUTTONUP()
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
|
|
void TAxisGrid::OnCellComboString(WDGridCell&cell,CComboBox&combo)
|
|
{
|
|
if(cell.GetColIndex() == 0)
|
|
{
|
|
CWnd *pWnd = GetParent();
|
|
if(pWnd->IsKindOf(RUNTIME_CLASS(CArcAxisPage)))
|
|
{
|
|
CArcAxisPage *pArc = (CArcAxisPage*)pWnd;
|
|
if(pArc->m_nCenter == 0)
|
|
{
|
|
for(int i=0; i<ELEMENTS(SZ_ANGLES); i++)
|
|
combo.AddString(SZ_ANGLES[i]);
|
|
}
|
|
else
|
|
{
|
|
for(int i=0; i<ELEMENTS(SZ_SIZES); i++)
|
|
combo.AddString(SZ_SIZES[i]);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for(int i=0; i<ELEMENTS(SZ_SIZES); i++)
|
|
combo.AddString(SZ_SIZES[i]);
|
|
}
|
|
}
|
|
else if(cell.GetColIndex() == 1)
|
|
{
|
|
for(int i=0; i<18; i++)
|
|
{
|
|
CString str;
|
|
str.Format(_T("%d"), i+1);
|
|
combo.AddString(str);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool TAxisGrid::OnModified(WDGridCell &cell, CString &text)
|
|
{
|
|
CWnd *pWnd = GetParent();
|
|
if(pWnd->IsKindOf(RUNTIME_CLASS(CArcAxisPage)))
|
|
{
|
|
CArcAxisPage *pArc = (CArcAxisPage*)pWnd;
|
|
if(pArc->m_nCenter == 0)
|
|
{
|
|
double dTotal = 0.0;
|
|
for(long i=0; i<GetRowNum(); i++)
|
|
{
|
|
if(i != cell.GetRowIndex())
|
|
dTotal += _tstof(GetCell(i, 0).GetText()) * _ttoi(GetCell(i, 1).GetText());
|
|
else
|
|
{
|
|
if(cell.GetColIndex() == 0)
|
|
dTotal += _tstof(text) * _ttoi(GetCell(i, 1).GetText());
|
|
else
|
|
dTotal += _tstof(GetCell(i, 0).GetText()) * _ttoi(text);
|
|
}
|
|
}
|
|
if(dTotal - 360 > AXIS_PEC)
|
|
{
|
|
MessageBox(_T("总角度不能超过360度!"));
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool TAxisGrid::OnBeforePaste(long i)
|
|
{
|
|
CWnd *pWnd = GetParent();
|
|
if(pWnd->IsKindOf(RUNTIME_CLASS(CArcAxisPage)))
|
|
{
|
|
CArcAxisPage *pArc = (CArcAxisPage*)pWnd;
|
|
if(pArc->m_nCenter == 0)
|
|
{
|
|
int i;
|
|
double dTotal = 0.0;
|
|
for(i=0; i<GetRowNum(); i++)
|
|
dTotal += _tstof(GetCell(i, 0).GetText()) * _ttoi(GetCell(i, 1).GetText());
|
|
|
|
for(i=0; i<pasteList.GetDataNum(); i++)
|
|
{
|
|
WDGridRow *pRow = pasteList.GetAt(i);
|
|
dTotal += _tstof((*pRow)[0].GetText()) * _ttoi((*pRow)[1].GetText());
|
|
}
|
|
if(dTotal - 360 > AXIS_PEC)
|
|
{
|
|
MessageBox(_T("总角度不能超过360度!"));
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void TAxisGrid::OnDataChanged()
|
|
{
|
|
WDGrid::OnDataChanged();
|
|
|
|
GetParent()->PostMessage(WM_GRID_MESSAGE, 0, 0);
|
|
}
|
|
|
|
void TAxisGrid::OnInsertRow(WDGridRow&row)
|
|
{
|
|
if(GetColNum() > 1)
|
|
row[1].SetText(_T("1"));
|
|
OnDataChanged();
|
|
}
|
|
|
|
////////////////////////////////////////////////////////
|
|
// TAxisDistAndKind
|
|
|
|
int TAxisDistAndKind::CompareForSort(const TAxisDistAndKind *p1, const TAxisDistAndKind *p2)
|
|
{
|
|
double nR1=p1->nDist;
|
|
double nR2 = p2->nDist;
|
|
double nDiff=nR1-nR2;
|
|
if(nDiff > 1.0E-9)
|
|
return 1;
|
|
else if(nDiff<-1.0E-9)
|
|
return -1;
|
|
return 0;
|
|
}
|
|
|
|
int TAxisDistAndKind::CompareReal(const TAxisDistAndKind *r1, const void *r2)
|
|
{
|
|
double nR1=r1->nDist;
|
|
double nR2 = *(const double *)r2;
|
|
double nDiff=nR1-nR2;
|
|
if(nDiff > 1.0E-9)
|
|
return 1;
|
|
else if(nDiff<-1.0E-9)
|
|
return -1;
|
|
return 0;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CAxisBasePage property page
|
|
|
|
|
|
IMPLEMENT_DYNAMIC(CAxisBasePage, CAcUiTabChildDialog)
|
|
|
|
CAxisBasePage::CAxisBasePage() : CAcUiTabChildDialog()
|
|
, m_PreviewDb(true, true)
|
|
, m_bPreview(true)
|
|
, m_bEditInput(FALSE)
|
|
, m_dDisX(0)
|
|
, m_dDisY(0)
|
|
, m_dAngle(0)
|
|
{
|
|
}
|
|
|
|
void CAxisBasePage::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CAcUiTabChildDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_LIST_CONST, m_list);
|
|
DDX_Control(pDX, IDC_EDIT_INPUT, m_editInput);
|
|
DDX_Control(pDX, IDC_EDIT_ANGLE, m_editAngle);
|
|
DDX_Control(pDX, IDC_SPIN_ANGLE, m_spinAngle);
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CAxisBasePage, CAcUiTabChildDialog)
|
|
ON_LBN_SELCHANGE(IDC_LIST_CONST, OnLbnSelchangeList)
|
|
ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnBnClickedButtonClear)
|
|
ON_EN_KILLFOCUS(IDC_EDIT_INPUT, OnEnKillfocusEditInput)
|
|
ON_CONTROL(WM_EDIT_MESSAGE, IDC_EDIT_INPUT, OnMessageEditInput)
|
|
ON_MESSAGE(WM_GRID_MESSAGE, OnGridMessage)
|
|
ON_WM_DESTROY()
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CAxisBasePage message handlers
|
|
|
|
BOOL CAxisBasePage::OnInitDialog()
|
|
{
|
|
CAcUiTabChildDialog::OnInitDialog();
|
|
|
|
InitList();
|
|
InitGrid();
|
|
if(!InitPreview())
|
|
return FALSE;
|
|
|
|
UpdateEditDis();
|
|
UpdateEditAngle();
|
|
return TRUE;
|
|
}
|
|
|
|
void CAxisBasePage::OnLbnSelchangeList()
|
|
{
|
|
CString szStr;
|
|
int nSel = m_list.GetCurSel();
|
|
m_list.GetText(nSel, szStr);
|
|
|
|
if(!AddToCList(_tstof(szStr), 1))
|
|
return;
|
|
|
|
UpdateEditDis();
|
|
UpdateGrid();
|
|
UpdatePreview();
|
|
UpdateEditInput();
|
|
m_grid.SetFocus();
|
|
}
|
|
|
|
void CAxisBasePage::OnBnClickedButtonClear()
|
|
{
|
|
GetSizeDesc().Clear();
|
|
UpdateEditDis();
|
|
UpdatePreview();
|
|
UpdateGrid();
|
|
UpdateEditInput();
|
|
}
|
|
|
|
void CAxisBasePage::OnEnKillfocusEditInput()
|
|
{
|
|
if(m_bEditInput)
|
|
{
|
|
m_bEditInput = FALSE;
|
|
return;
|
|
}
|
|
OnMessageEditInput();
|
|
}
|
|
|
|
void CAxisBasePage::OnMessageEditInput()
|
|
{
|
|
m_bEditInput = TRUE;
|
|
CString szData;
|
|
m_editInput.GetWindowText(szData);
|
|
PDList<TCountAndSize> &vtSize = GetSizeDesc();
|
|
for(vtSize.MoveToFirst(); !vtSize.IsOut(); vtSize.MoveToNext())
|
|
{
|
|
if(vtSize.GetCurData()->m_nPosition != -1)
|
|
vtSize.DelCur();
|
|
}
|
|
|
|
TCHAR szWord[1024]=_T("");
|
|
int iWord=1;
|
|
while(CT_strnth(szData, iWord, szWord))
|
|
{
|
|
int nCount=1;
|
|
double dSize=0.0;
|
|
TCHAR *pPlus=_tcschr(szWord, _T('*'));
|
|
if(!pPlus) dSize=_tstof(szWord);
|
|
else {
|
|
dSize=_tstof(&pPlus[1]);
|
|
*pPlus=EOS;
|
|
nCount=_ttoi(szWord);
|
|
}
|
|
if(nCount<1 || dSize<_DIST_SNAP)
|
|
{
|
|
MessageBox(_T("请正确键入!"));
|
|
break;
|
|
}
|
|
if(!AddToCList(dSize, nCount))
|
|
{
|
|
UpdateEditInput();
|
|
return;
|
|
}
|
|
iWord++;
|
|
}
|
|
|
|
UpdateEditDis();
|
|
UpdateGrid();
|
|
UpdateEditInput();
|
|
UpdatePreview();
|
|
}
|
|
LRESULT CAxisBasePage::OnGridMessage(WPARAM wParam, LPARAM lParam)
|
|
{
|
|
PDList<TCountAndSize> &vtCurrent = GetSizeDesc();
|
|
for(vtCurrent.MoveToFirst(); !vtCurrent.IsOut(); vtCurrent.MoveToNext())
|
|
{
|
|
if(vtCurrent.GetCurData()->m_nPosition != -1)
|
|
vtCurrent.DelCur();
|
|
}
|
|
for(long i=0; i<m_grid.GetRowNum(); i++)
|
|
{
|
|
double dSize = _tstof(m_grid[i][0].GetText());
|
|
int nCount = _ttoi(m_grid[i][1].GetText());
|
|
if(fabs(dSize) < AXIS_PEC || nCount <= 0)
|
|
continue;
|
|
if(!AddToCList(dSize, nCount))
|
|
return 0;
|
|
}
|
|
|
|
UpdateEditDis();
|
|
UpdatePreview();
|
|
UpdateEditInput();
|
|
return 1;
|
|
}
|
|
|
|
void CAxisBasePage::OnDestroy()
|
|
{
|
|
m_PreviewCtrl.clearAll();
|
|
CAcUiTabChildDialog::OnDestroy();
|
|
}
|
|
|
|
void CAxisBasePage::InitGrid()
|
|
{
|
|
m_grid.Clear();
|
|
m_grid.AppendCol(_T("轴间距"), 60);
|
|
m_grid.AppendCol(_T("个数"), 52);
|
|
m_grid.GetCol(0).SetComboEdit();
|
|
m_grid.GetCol(1).SetComboEdit();
|
|
m_grid.SetColPosFix();
|
|
m_grid.SetColFixLength();
|
|
m_grid.Create(this, IDC_LIST_INPUT);
|
|
m_grid.FitLastCol();
|
|
}
|
|
|
|
BOOL CAxisBasePage::InitPreview()
|
|
{
|
|
if(!m_PreviewCtrl.SubclassDlgItem(IDC_PREVIEW, this))
|
|
return FALSE;
|
|
|
|
m_PreviewCtrl.init(true);
|
|
return TRUE;
|
|
}
|
|
|
|
void CAxisBasePage::UpdateGrid()
|
|
{
|
|
m_grid.Clear();
|
|
PDList<TCountAndSize> &lstCurrent = GetSizeDesc();
|
|
for(int i=0; i<lstCurrent.GetDataNum(); i++)
|
|
{
|
|
TCountAndSize *pCAS = lstCurrent[i];
|
|
if(pCAS != NULL && pCAS->m_nPosition == 0)
|
|
{
|
|
WDGridRow *pRow = new WDGridRow(m_grid);
|
|
(*pRow)[0].SetText(XString(_T("%.0f"), pCAS->m_dSize));
|
|
(*pRow)[1].SetText(XString(_T("%d"), pCAS->m_nCount));
|
|
m_grid.AppendRow(pRow);
|
|
}
|
|
}
|
|
}
|
|
|
|
void CAxisBasePage::UpdatePreview()
|
|
{
|
|
m_bPreview = TRUE;
|
|
m_PreviewCtrl.clearAll();
|
|
m_PreviewCtrl.init(true);
|
|
AcDbBlockTable *pBlockTab = NULL;
|
|
if(m_PreviewDb.getSymbolTable(pBlockTab, AcDb::kForWrite)!=Acad::eOk)
|
|
return;
|
|
|
|
AcDbBlockTableRecord *pBlockTableRecord = new AcDbBlockTableRecord;
|
|
pBlockTableRecord->setName(_T("*U"));
|
|
pBlockTab->add(pBlockTableRecord);
|
|
pBlockTab->close();
|
|
|
|
if(!DrawEntity(pBlockTableRecord))
|
|
{
|
|
pBlockTableRecord->close();
|
|
m_PreviewCtrl.Invalidate();
|
|
return;
|
|
}
|
|
|
|
AcDbExtents extents;
|
|
GetRecordExtents(pBlockTableRecord, extents);
|
|
double dWidth = extents.maxPoint().x - extents.minPoint().x;
|
|
double dHigh = extents.maxPoint().y - extents.minPoint().y;
|
|
DrawBasePoint(0.03 * dHigh, pBlockTableRecord);
|
|
|
|
AcGePoint3d ptCenter;
|
|
ptCenter.x = extents.minPoint().x + 0.5 * dWidth;
|
|
ptCenter.y = extents.minPoint().y + 0.5 * dHigh;
|
|
AcGePoint3d ptEye(ptCenter.x, ptCenter.y, 1);
|
|
AcGsView *pView = m_PreviewCtrl.view();
|
|
pView->setView(ptEye, ptCenter, AcGeVector3d(0, 1, 0), 1.1*dWidth, 1.1*dHigh);
|
|
pView->add(pBlockTableRecord, m_PreviewCtrl.model());
|
|
pBlockTableRecord->close();
|
|
m_PreviewCtrl.Invalidate();
|
|
|
|
UpdateVisible();
|
|
}
|
|
|
|
void CAxisBasePage::UpdateEditInput()
|
|
{
|
|
XString szData(2048);
|
|
for(long i=0; i<m_grid.GetRowNum(); i++)
|
|
{
|
|
CString szSize = m_grid[i][0].GetText().cs();
|
|
CString szCount = m_grid[i][1].GetText().cs();
|
|
if(szSize == _T("") || szCount == _T(""))
|
|
continue;
|
|
|
|
double dSize = _tstof(szSize);
|
|
int nCount = _ttoi(szCount);
|
|
if(nCount>1)
|
|
szData << nCount << _T("*");
|
|
szData << dSize << _T(" ");
|
|
}
|
|
m_editInput.SetWindowText(szData);
|
|
}
|
|
|
|
void CAxisBasePage::UpdateEditDis()
|
|
{
|
|
GetEditDisValue();
|
|
CString szDisX, szDisY;
|
|
szDisX.Format(_T("%.1f"), m_dDisX);
|
|
szDisX.TrimRight(_T("0"));
|
|
szDisX.TrimRight(_T("."));
|
|
szDisY.Format(_T("%.1f"), m_dDisY);
|
|
szDisY.TrimRight(_T("0"));
|
|
szDisY.TrimRight(_T("."));
|
|
|
|
CAxisGridSheet *pSheet = (CAxisGridSheet*)GetParent();
|
|
if(pSheet != NULL)
|
|
pSheet->UpdateSize(szDisX, szDisY);
|
|
}
|
|
|
|
void CAxisBasePage::GetRecordExtents(AcDbBlockTableRecord *pBlockTabRecord, AcDbExtents &extents)
|
|
{
|
|
AcDbBlockTableRecordIterator *pIterator = NULL;
|
|
if(Acad::eOk != pBlockTabRecord->newIterator(pIterator))
|
|
return;
|
|
|
|
BOOL bInit = TRUE;
|
|
AcGePoint3d ptMin, ptMax;
|
|
for(pIterator->start(); !pIterator->done(); pIterator->step())
|
|
{
|
|
AcDbEntity *pEnt = NULL;
|
|
if(Acad::eOk != pIterator->getEntity(pEnt, AcDb::kForRead))
|
|
continue;
|
|
|
|
AcDbExtents ext;
|
|
if(Acad::eOk == pEnt->getGeomExtents(ext))
|
|
{
|
|
if(bInit)
|
|
{
|
|
ptMin = ext.minPoint();
|
|
ptMax = ext.maxPoint();
|
|
bInit = FALSE;
|
|
}
|
|
else
|
|
{
|
|
ptMin.x = min(ptMin.x, ext.minPoint().x);
|
|
ptMin.y = min(ptMin.y, ext.minPoint().y);
|
|
ptMax.x = max(ptMax.x, ext.maxPoint().x);
|
|
ptMax.y = max(ptMax.y, ext.maxPoint().y);
|
|
}
|
|
}
|
|
pEnt->close();
|
|
}
|
|
delete pIterator;
|
|
extents.set(ptMin, ptMax);
|
|
}
|
|
|
|
void CAxisBasePage::CopyPDList(PDList<TCountAndSize> &source, PDList<TCountAndSize> &dest)
|
|
{
|
|
for(source.MoveToFirst(); !source.IsOut(); source.MoveToNext())
|
|
{
|
|
TCountAndSize* pNew = new TCountAndSize(*source.GetCurData());
|
|
if(pNew != NULL)
|
|
dest.AddTail(pNew);
|
|
}
|
|
}
|
|
|
|
double CAxisBasePage::TotalDistance(PDList<TCountAndSize> &lstDesc)
|
|
{
|
|
double nRes=0.0;
|
|
for(int i=0; i<lstDesc.GetDataNum(); i++)
|
|
nRes += lstDesc[i]->m_nCount * lstDesc[i]->m_dSize;
|
|
return nRes;
|
|
}
|
|
|
|
void CAxisBasePage::DrawBasePoint(const double dLength, AcDbBlockTableRecord *&pBlockTabRecord)
|
|
{
|
|
XPoint ptSta1 = m_ptIns + XPoint(dLength, dLength, 0);
|
|
XPoint ptEnd1 = m_ptIns + XPoint(-dLength, -dLength, 0);
|
|
AcDbLine *pline1 = new AcDbLine(ptSta1, ptEnd1);
|
|
pBlockTabRecord->appendAcDbEntity(pline1);
|
|
pline1->close();
|
|
|
|
XPoint ptSta2 = m_ptIns + XPoint(-dLength, dLength, 0);
|
|
XPoint ptEnd2 = m_ptIns + XPoint(dLength, -dLength, 0);
|
|
AcDbLine *pline2 = new AcDbLine(ptSta2, ptEnd2);
|
|
pBlockTabRecord->appendAcDbEntity(pline2);
|
|
pline2->close();
|
|
|
|
}
|
|
|
|
// add by zyc [2012/04/20] 将拾取的标注数据添加到键入编辑框
|
|
void CAxisBasePage::AddDataToInputEdit(CArray<double, double&>& arData)
|
|
{
|
|
CString sAllData;
|
|
CString sData;
|
|
for (int i=0; i<arData.GetSize(); i++)
|
|
{
|
|
sData.Format(_T("%lf"), arData[i]);
|
|
sData.TrimRight('0');
|
|
sData.TrimRight('.');
|
|
sAllData += sData;
|
|
if (i != arData.GetSize()-1)
|
|
{
|
|
sAllData += ' ';
|
|
}
|
|
}
|
|
|
|
int iPosStart, iPosEnd;
|
|
m_editInput.GetSel(iPosStart, iPosEnd);
|
|
CString sOldText;
|
|
m_editInput.GetWindowText(sOldText);
|
|
if (iPosStart==iPosEnd)
|
|
{
|
|
// 未选中文本,添加到末尾
|
|
sOldText += sAllData;
|
|
m_editInput.SetWindowText(sOldText);
|
|
m_bEditInput = FALSE;
|
|
return;
|
|
}
|
|
|
|
CString sText;
|
|
m_editInput.GetWindowText(sText);
|
|
// 使选中的文本左端包含完整的数据项
|
|
TCHAR* pStart = (TCHAR*)(LPCTSTR)sText + iPosStart;
|
|
while (*pStart != ' ' &&
|
|
pStart != (TCHAR*)(LPCTSTR)sText)
|
|
{
|
|
pStart--;
|
|
iPosStart--;
|
|
}
|
|
if (*pStart == ' ')
|
|
{
|
|
iPosStart++;
|
|
}
|
|
|
|
// 使选中的文本右端包含完整的数据项
|
|
TCHAR* pEnd = (TCHAR*)(LPCTSTR)sText + iPosEnd;
|
|
while (*pEnd != ' ' &&
|
|
*pEnd != '\0')
|
|
{
|
|
pEnd++;
|
|
iPosEnd++;
|
|
}
|
|
if (*pEnd == '\0')
|
|
{
|
|
iPosEnd = -1;
|
|
}
|
|
|
|
// 设置新的选择范围
|
|
m_editInput.SetSel(iPosStart, iPosEnd);
|
|
|
|
// 替换选中的文本
|
|
m_editInput.ReplaceSel(sAllData);
|
|
m_bEditInput = FALSE;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CRectAxisPage property page
|
|
const TCHAR *CRectAxisPage::s_szFileTitle = _T("TArch RAXIS Data File 1.0");
|
|
|
|
IMPLEMENT_DYNCREATE(CRectAxisPage, CAxisBasePage)
|
|
|
|
CRectAxisPage::CRectAxisPage() : CAxisBasePage()
|
|
, m_nRadio(1)
|
|
, m_dOffset(0)
|
|
{
|
|
}
|
|
|
|
void CRectAxisPage::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CAxisBasePage::DoDataExchange(pDX);
|
|
DDX_Radio(pDX, IDC_RADIO_UP, m_nRadio);
|
|
DDX_Control(pDX, IDC_BUTTON_BACK, m_buttonBack);
|
|
DDX_Control(pDX, IDC_BUTTON_FORWARD, m_buttonForward);
|
|
DDX_Control(pDX, IDC_EDIT_OFFSET, m_editOffset);
|
|
DDX_Text(pDX, IDC_EDIT_OFFSET, m_dOffset);
|
|
DDV_MinMaxDouble(pDX, m_dOffset, 0, DBL_MAX);
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CRectAxisPage, CAxisBasePage)
|
|
ON_BN_CLICKED(IDC_RADIO_UP, OnBnClickedRadio)
|
|
ON_BN_CLICKED(IDC_RADIO_DOWN, OnBnClickedRadio)
|
|
ON_BN_CLICKED(IDC_RADIO_LEFT, OnBnClickedRadio)
|
|
ON_BN_CLICKED(IDC_RADIO_RIGHT, OnBnClickedRadio)
|
|
ON_BN_CLICKED(IDC_BUTTON_BACK, OnBnClickedButtonBack)
|
|
ON_BN_CLICKED(IDC_BUTTON_FORWARD, OnBnClickedButtonForward)
|
|
ON_EN_CHANGE(IDC_EDIT_OFFSET, OnEnChangeEditOffset)
|
|
ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnBnClickedButtonClear)
|
|
ON_EN_KILLFOCUS(IDC_EDIT_ANGLE, OnEnKillfocusEditAngle)
|
|
ON_CONTROL(WM_EDIT_MESSAGE, IDC_EDIT_ANGLE, OnMessageEditAngle)
|
|
ON_EN_CHANGE(IDC_EDIT_ANGLE, OnEnChangeEditAngle)
|
|
ON_WM_CTLCOLOR()
|
|
ON_BN_CLICKED(IDC_BUTTON_PICK, OnBnClickedButtonPick)
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CRectAxisPage message handlers
|
|
|
|
BOOL CRectAxisPage::OnInitDialog()
|
|
{
|
|
CAxisBasePage::OnInitDialog();
|
|
|
|
m_spinAngle.SetBuddy(&m_editAngle);
|
|
m_spinAngle.SetRange(1, 179);
|
|
UpdateVisible();
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
//HBRUSH CRectAxisPage::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
|
//{
|
|
// HBRUSH hbr = CAxisBasePage::OnCtlColor(pDC, pWnd, nCtlColor);
|
|
//
|
|
// int nID = pWnd->GetDlgCtrlID();
|
|
// if(nID == IDC_RADIO_UP)
|
|
// pDC->SetTextColor(acdbGetRGB(2));
|
|
// else if(nID == IDC_RADIO_DOWN)
|
|
// pDC->SetTextColor(acdbGetRGB(1));
|
|
// else if(nID == IDC_RADIO_LEFT)
|
|
// pDC->SetTextColor(acdbGetRGB(4));
|
|
// else if(nID == IDC_RADIO_RIGHT)
|
|
// pDC->SetTextColor(acdbGetRGB(3));
|
|
//
|
|
// return hbr;
|
|
//}
|
|
|
|
void CRectAxisPage::OnBnClickedRadio()
|
|
{
|
|
CDataExchange dx(this, true);
|
|
DDX_Radio(&dx, IDC_RADIO_UP, m_nRadio);
|
|
|
|
PDList<TCountAndSize> &lstCorre = GetCorreDesc();
|
|
ReplaceOffset(lstCorre);
|
|
|
|
m_editOffset.SetWindowText(_T("0"));
|
|
UpdateVisible();
|
|
UpdateGrid();
|
|
UpdateEditInput();
|
|
}
|
|
|
|
void CRectAxisPage::OnBnClickedButtonBack()
|
|
{
|
|
int nIns;
|
|
double dOffset;
|
|
GetOffset(GetSizeDesc(), nIns, dOffset);
|
|
GetSizeDesc().Del(nIns);
|
|
|
|
UpdateEditOffset();
|
|
UpdateVisible();
|
|
}
|
|
|
|
void CRectAxisPage::OnBnClickedButtonForward()
|
|
{
|
|
int nIns;
|
|
double dOffset;
|
|
GetOffset(GetSizeDesc(), nIns, dOffset);
|
|
|
|
PDList<TCountAndSize> &lstCorre = GetCorreDesc();
|
|
double dDesc = 0.0;
|
|
for(int i=0; i<lstCorre.GetDataNum(); i++)
|
|
{
|
|
TCountAndSize *pSize = lstCorre[i];
|
|
for(int j=0; j<pSize->m_nCount; j++)
|
|
{
|
|
dDesc += pSize->m_dSize;
|
|
double dDif = dDesc - dOffset;
|
|
if(dDif > AXIS_PEC)
|
|
{
|
|
if(pSize->m_dSize - dDif > AXIS_PEC)
|
|
GetSizeDesc().Del(nIns);
|
|
|
|
GetSizeDesc().Insert(nIns+1, new TCountAndSize(pSize->m_dSize, 1, -1));
|
|
UpdateEditOffset();
|
|
UpdateVisible();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void CRectAxisPage::OnEnChangeEditOffset()
|
|
{
|
|
double dOffset = 0.0;
|
|
CDataExchange dx(this, true);
|
|
DDX_Text(&dx, IDC_EDIT_OFFSET, dOffset);
|
|
|
|
PDList<TCountAndSize> &lstSize = GetSizeDesc();
|
|
for(lstSize.MoveToFirst(); !lstSize.IsOut(); lstSize.MoveToNext())
|
|
{
|
|
if(lstSize.GetCurData()->m_nPosition == -1)
|
|
lstSize.DelCur();
|
|
}
|
|
|
|
PDList<TCountAndSize> &lstCorre = GetCorreDesc();
|
|
int nPos = 0;
|
|
for(int i=0; i<lstCorre.GetDataNum(); i++)
|
|
{
|
|
TCountAndSize *pSize = lstCorre[i];
|
|
BOOL bBreak = FALSE;
|
|
for(int j=0; j<pSize->m_nCount; j++)
|
|
{
|
|
double dDesc = dOffset - pSize->m_dSize;
|
|
if(dDesc > AXIS_PEC)
|
|
{
|
|
lstSize.Insert(nPos, new TCountAndSize(pSize->m_dSize, 1, -1));
|
|
dOffset -= pSize->m_dSize;
|
|
nPos++;
|
|
}
|
|
else
|
|
{
|
|
bBreak = TRUE;
|
|
break;
|
|
}
|
|
}
|
|
if(bBreak)
|
|
break;
|
|
}
|
|
if(dOffset > AXIS_PEC)
|
|
lstSize.Insert(nPos, new TCountAndSize(dOffset, 1, -1));
|
|
|
|
UpdateVisible();
|
|
UpdateEditDis();
|
|
UpdatePreview();
|
|
}
|
|
|
|
void CRectAxisPage::OnBnClickedButtonClear()
|
|
{
|
|
m_editOffset.SetWindowText(_T("0"));
|
|
CAxisBasePage::OnBnClickedButtonClear();
|
|
UpdateVisible();
|
|
}
|
|
|
|
void CRectAxisPage::OnEnKillfocusEditAngle()
|
|
{
|
|
OnMessageEditAngle();
|
|
}
|
|
|
|
void CRectAxisPage::OnMessageEditAngle()
|
|
{
|
|
CString szAngle;
|
|
m_editAngle.GetWindowText(szAngle);
|
|
|
|
double dAngle = PI/2 - _tstof(szAngle)*PI/180;
|
|
dAngle = atan(tan(dAngle));
|
|
if(fabs(fabs(dAngle) - PI/2) > AXIS_PEC)
|
|
m_dAngle = dAngle;
|
|
|
|
UpdateEditAngle();
|
|
}
|
|
|
|
void CRectAxisPage::OnEnChangeEditAngle()
|
|
{
|
|
CString szAngle;
|
|
m_editAngle.GetWindowText(szAngle);
|
|
|
|
double dAngle = PI/2 - _tstof(szAngle)*PI/180;
|
|
dAngle = atan(tan(dAngle));
|
|
if(fabs(fabs(dAngle) - PI/2) > AXIS_PEC)
|
|
m_dAngle = dAngle;
|
|
|
|
UpdatePreview();
|
|
}
|
|
|
|
void CRectAxisPage::OnBnClickedButtonPick()
|
|
{
|
|
// 拾取尺寸对象,获取尺寸数据
|
|
CAxisGridSheet* pSheet = (CAxisGridSheet*)GetParent();
|
|
CArray<double, double&> arData;
|
|
pSheet->PickDimensions(kRect, arData);
|
|
|
|
// 将数据添加到编辑框
|
|
AddDataToInputEdit(arData);
|
|
|
|
// 更新
|
|
OnEnKillfocusEditInput();
|
|
}
|
|
|
|
void CRectAxisPage::InitList()
|
|
{
|
|
m_list.ResetContent();
|
|
for(int i=0; i<ELEMENTS(SZ_SIZES); i++)
|
|
m_list.AddString(SZ_SIZES[i]);
|
|
}
|
|
|
|
void CRectAxisPage::UpdateEditAngle()
|
|
{
|
|
CString szAngle;
|
|
szAngle.Format(_T("%.3f"), 90-m_dAngle*180/PI);
|
|
szAngle.TrimRight(_T("0"));
|
|
szAngle.TrimRight(_T("."));
|
|
|
|
m_editAngle.SetWindowText(szAngle);
|
|
}
|
|
|
|
void CRectAxisPage::UpdateEditOffset()
|
|
{
|
|
int nPos;
|
|
double dOffset;
|
|
GetOffset(GetSizeDesc(), nPos, dOffset);
|
|
|
|
CDataExchange dx(this, FALSE);
|
|
DDX_Text(&dx, IDC_EDIT_OFFSET, dOffset);
|
|
}
|
|
|
|
void CRectAxisPage::UpdateVisible()
|
|
{
|
|
if(GetCorreDesc().IsEmpty()||GetCurrentDesc().IsEmpty())
|
|
{
|
|
m_buttonBack.EnableWindow(FALSE);
|
|
m_buttonForward.EnableWindow(FALSE);
|
|
m_editOffset.EnableWindow(FALSE);
|
|
return;
|
|
}
|
|
|
|
BOOL bForward = FALSE;
|
|
BOOL bBack = FALSE;
|
|
PDList<TCountAndSize> &lstSize = GetSizeDesc();
|
|
if(!lstSize.IsEmpty() && lstSize[0]->m_nPosition == -1)
|
|
bBack = TRUE;
|
|
else
|
|
bBack = FALSE;
|
|
|
|
int nPos;
|
|
double dOffset;
|
|
GetOffset(lstSize, nPos, dOffset);
|
|
|
|
double dDesc = 0.0;
|
|
PDList<TCountAndSize> &lstCorre = GetCorreDesc();
|
|
for(lstCorre.MoveToFirst(); !lstCorre.IsOut(); lstCorre.MoveToNext())
|
|
dDesc += lstCorre.GetCurData()->m_dSize * lstCorre.GetCurData()->m_nCount;
|
|
|
|
if(dOffset - dDesc < -AXIS_PEC)
|
|
bForward = TRUE;
|
|
else
|
|
bForward = FALSE;
|
|
|
|
m_buttonForward.EnableWindow(bForward);
|
|
m_buttonBack.EnableWindow(bBack);
|
|
m_editOffset.EnableWindow(bForward || bBack);
|
|
}
|
|
|
|
void CRectAxisPage::ComeBack()
|
|
{
|
|
ImportFromFile();
|
|
|
|
UpdateEditDis();
|
|
UpdateGrid();
|
|
UpdatePreview();
|
|
UpdateEditInput();
|
|
UpdateEditAngle();
|
|
|
|
UpdateEditOffset();
|
|
UpdateVisible();
|
|
}
|
|
|
|
PDList<TCountAndSize> &CRectAxisPage::GetCorreDesc()
|
|
{
|
|
if(m_nRadio==0)
|
|
return m_lstDown;
|
|
else if(m_nRadio==1)
|
|
return m_lstUp;
|
|
else if(m_nRadio==2)
|
|
return m_lstRight;
|
|
else
|
|
return m_lstLeft;
|
|
}
|
|
PDList<TCountAndSize> &CRectAxisPage::GetCurrentDesc()
|
|
{
|
|
if(m_nRadio==1)
|
|
return m_lstDown;
|
|
else if(m_nRadio==0)
|
|
return m_lstUp;
|
|
else if(m_nRadio==3)
|
|
return m_lstRight;
|
|
else
|
|
return m_lstLeft;
|
|
}
|
|
|
|
|
|
void CRectAxisPage::GetOffset(PDList<TCountAndSize> &lstSize, int &nPos, double &dOffset)
|
|
{
|
|
nPos = -1;
|
|
dOffset = 0.0;
|
|
for(int i=0; i<lstSize.GetDataNum(); i++)
|
|
{
|
|
TCountAndSize *pSize = lstSize[i];
|
|
if(pSize->m_nPosition == 0)
|
|
break;
|
|
|
|
nPos = i;
|
|
dOffset += pSize->m_dSize * pSize->m_nCount;
|
|
}
|
|
|
|
}
|
|
|
|
void CRectAxisPage::ReplaceOffset(PDList<TCountAndSize> &lstSize)
|
|
{
|
|
double dSize = 0.0;
|
|
for(lstSize.MoveToFirst(); !lstSize.IsOut(); lstSize.MoveToNext())
|
|
{
|
|
TCountAndSize *pSize = lstSize.GetCurData();
|
|
if(pSize->m_nPosition == -1)
|
|
{
|
|
dSize += pSize->m_dSize;
|
|
lstSize.DelCur();
|
|
}
|
|
}
|
|
if(dSize > AXIS_PEC)
|
|
lstSize.InsertHead(new TCountAndSize(dSize, 1, 0));
|
|
}
|
|
|
|
void CRectAxisPage::GetEditDisValue()
|
|
{
|
|
m_dDisX = max(TotalDistance(m_lstDown), TotalDistance(m_lstUp));
|
|
m_dDisY = max(TotalDistance(m_lstLeft), TotalDistance(m_lstRight));
|
|
}
|
|
|
|
int CRectAxisPage::InsertToCSpace()
|
|
{
|
|
m_bPreview = FALSE;
|
|
int iTileMode=0;
|
|
VERIFY(xg_getvar(_T("TILEMODE"), &iTileMode)==RTNORM);
|
|
|
|
// add by xlc on 071226
|
|
int cvport=0;
|
|
VERIFY(xg_getvar(_T("CVPORT"), &cvport)==RTNORM);
|
|
|
|
PickSet ss(SS_FREE);
|
|
ss.IncludeBegin();
|
|
AcDbBlockTable *pTable = NULL;
|
|
acdbHostApplicationServices()->workingDatabase()
|
|
->getSymbolTable(pTable, AcDb::kForRead);
|
|
AcDbBlockTableRecord *pBlockTableRecord = NULL;
|
|
|
|
// modify by xlc on 071226
|
|
//pTable->getAt((iTileMode==0)?ACDB_PAPER_SPACE:ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
|
|
pTable->getAt((iTileMode==0 && cvport==1)?ACDB_PAPER_SPACE:ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
|
|
|
|
pTable->close();
|
|
|
|
DrawEntity(pBlockTableRecord);
|
|
pBlockTableRecord->close();
|
|
ss.IncludeEnd();
|
|
|
|
int nRet = DragPickSet(ss, m_ptIns);
|
|
if(nRet != RTNORM)
|
|
ss.Delete();
|
|
else
|
|
ExportToFile();
|
|
|
|
return nRet;
|
|
}
|
|
|
|
BOOL CRectAxisPage::DrawEntity(AcDbBlockTableRecord *&pBlockTableRecord)
|
|
{
|
|
BOOL bRetX = DrawAxis(pBlockTableRecord, 0);
|
|
BOOL bRetY = DrawAxis(pBlockTableRecord, 1);
|
|
if(!bRetX && !bRetY)
|
|
return FALSE;
|
|
else
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CRectAxisPage::DrawAxis(AcDbBlockTableRecord *&pBlockTableRecord, int nDir)
|
|
{
|
|
PDList<TCountAndSize> lstOne, lstAnother;
|
|
double dDrt, dAxisDir, dAxisLen;
|
|
double dBaseDist = g_dBaseDist;
|
|
if(nDir==0)
|
|
{
|
|
CopyPDList(m_lstLeft, lstOne);
|
|
CopyPDList(m_lstRight, lstAnother);
|
|
if(lstOne.IsEmpty() && lstAnother.IsEmpty())
|
|
return FALSE;
|
|
|
|
dAxisLen = GetAxisLenX();
|
|
dAxisDir = m_dAngle;
|
|
dDrt = CT_std_angle(dAxisDir+PI/2);
|
|
if(m_dAngle < 0)
|
|
dBaseDist += m_dDisY * fabs(tan(m_dAngle));
|
|
}
|
|
else
|
|
{
|
|
CopyPDList(m_lstDown, lstOne);
|
|
CopyPDList(m_lstUp, lstAnother);
|
|
if(lstOne.IsEmpty() && lstAnother.IsEmpty())
|
|
return FALSE;
|
|
|
|
dAxisLen=GetAxisLenY();
|
|
dAxisDir = PI/2.0;
|
|
dDrt=CT_std_angle(dAxisDir-PI/2.0);
|
|
if(m_dAngle < 0)
|
|
dBaseDist += m_dDisX * fabs(tan(m_dAngle));
|
|
}
|
|
ReplaceOffset(lstOne);
|
|
ReplaceOffset(lstAnother);
|
|
|
|
int nFrontColor=1;
|
|
if(m_bPreview)
|
|
nFrontColor = (nDir==1) ? 1 : 3;
|
|
|
|
XPoint pt1, pt2;
|
|
XPoint ptBase = m_ptIns;
|
|
ads_polar(ptBase, dAxisDir + PI, dBaseDist, pt1);
|
|
ads_polar(pt1, dAxisDir, dAxisLen, pt2);
|
|
ptBase = pt1;
|
|
|
|
AcDbLine *pline = new AcDbLine;
|
|
if(m_bPreview)
|
|
{
|
|
pline->setStartPoint(pt1.AsAcGePoint3d());
|
|
pline->setEndPoint(pt2.AsAcGePoint3d());
|
|
pline->setColorIndex(nFrontColor);
|
|
}
|
|
else
|
|
{
|
|
pline->setStartPoint(Ucs2Wcs(pt1).AsAcGePoint3d());
|
|
pline->setEndPoint(Ucs2Wcs(pt2).AsAcGePoint3d());
|
|
pline->setLayer(InitLayer(LAY_AXIS));
|
|
}
|
|
|
|
if(pBlockTableRecord->appendAcDbEntity(pline) == Acad::eOk)
|
|
pline->close();
|
|
else
|
|
delete pline;
|
|
|
|
PDList<double> lstDistSize;
|
|
// 下开间
|
|
double nDistBeg=0;
|
|
Disperse(nDistBeg, lstOne, lstDistSize);
|
|
int nK = (lstAnother.IsEmpty()) ? 3:1;
|
|
DList<TAxisDistAndKind> lstDistAndKind;
|
|
for(int n=0; n<lstDistSize.GetDataNum(); n++)
|
|
lstDistAndKind.Append(new TAxisDistAndKind(lstDistSize(n), nK));
|
|
|
|
double nOffset=1.5;
|
|
if(g_nRunMode)
|
|
nOffset = m_bPreview? 1.5 : 0.5;
|
|
|
|
// 上开间
|
|
nDistBeg=0;
|
|
lstDistSize.Clear();
|
|
Disperse(nDistBeg, lstAnother, lstDistSize);
|
|
|
|
nK = (lstOne.IsEmpty()) ? 3:2;
|
|
for(n=0; n<lstDistSize.GetDataNum(); n++)
|
|
{
|
|
TAxisDistAndKind *pCur=lstDistAndKind.FindNode(lstDistSize[n], TAxisDistAndKind::CompareReal);
|
|
if(pCur) pCur->nKind += nK;
|
|
else lstDistAndKind.Append(new TAxisDistAndKind(lstDistSize(n), nK));
|
|
}
|
|
|
|
lstDistAndKind.QuickSort(TAxisDistAndKind::CompareForSort);
|
|
if(!lstDistAndKind)
|
|
return FALSE;
|
|
lstDistAndKind.Tail()->nKind = 3; //最后一根轴线, 自动贯通
|
|
for(n=0; n<lstDistAndKind.Length(); n++)
|
|
{
|
|
TAxisDistAndKind &cur = *lstDistAndKind[n];
|
|
XPoint ptTemp1, ptTemp2;
|
|
ads_polar(ptBase, dDrt, cur.nDist, ptTemp1);
|
|
ads_polar(ptTemp1, dAxisDir, dAxisLen, ptTemp2);
|
|
pt1=ptTemp1; pt2=ptTemp2;
|
|
int iColor = 1;
|
|
if(cur.nKind==1) {
|
|
ads_polar(ptTemp2, dAxisDir+PI, g_dBaseDist*nOffset, pt2);
|
|
if(m_bPreview) iColor = nFrontColor;
|
|
} else if(cur.nKind==2) {
|
|
ads_polar(ptTemp1, dAxisDir, g_dBaseDist*nOffset, pt1);
|
|
if(m_bPreview) iColor = nFrontColor+1;
|
|
} else {
|
|
if(m_bPreview) iColor = nFrontColor;
|
|
}
|
|
|
|
AcDbLine *pline = new AcDbLine;
|
|
if(m_bPreview)
|
|
{
|
|
pline->setStartPoint(pt1.AsAcGePoint3d());
|
|
pline->setEndPoint(pt2.AsAcGePoint3d());
|
|
pline->setColorIndex(iColor);
|
|
}
|
|
else
|
|
{
|
|
pline->setStartPoint(Ucs2Wcs(pt1).AsAcGePoint3d());
|
|
pline->setEndPoint(Ucs2Wcs(pt2).AsAcGePoint3d());
|
|
pline->setLayer(InitLayer(LAY_AXIS));
|
|
}
|
|
|
|
if(pBlockTableRecord->appendAcDbEntity(pline) == Acad::eOk)
|
|
pline->close();
|
|
else
|
|
delete pline;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
// X方向的轴线
|
|
double CRectAxisPage::GetAxisLenX()
|
|
{
|
|
double dDisX = (m_dDisX < AXIS_PEC) ? m_dDisY : m_dDisX;
|
|
double dDisY = (m_dDisY < AXIS_PEC) ? m_dDisX : m_dDisY;
|
|
double nDistMe = dDisY / cos(m_dAngle) + dDisX * fabs(tan(m_dAngle));
|
|
if(m_lstDown.IsEmpty() && m_lstUp.IsEmpty())
|
|
{
|
|
if(!m_bPreview)
|
|
GetDist(_T("\n单向轴线长度"), nDistMe, RSG_NONEG|RSG_NOZERO);
|
|
}
|
|
else
|
|
nDistMe = dDisX / cos(m_dAngle) + dDisY * fabs(tan(m_dAngle));
|
|
|
|
nDistMe += g_dBaseDist*2;
|
|
return nDistMe;
|
|
}
|
|
|
|
// Y方向的轴线
|
|
double CRectAxisPage::GetAxisLenY()
|
|
{
|
|
double dDisX = (m_dDisX < AXIS_PEC) ? m_dDisY : m_dDisX;
|
|
double dDisY = (m_dDisY < AXIS_PEC) ? m_dDisX : m_dDisY;
|
|
double nDistMe = dDisX / cos(m_dAngle) + dDisY * fabs(tan(m_dAngle));
|
|
if(m_lstLeft.IsEmpty() && m_lstRight.IsEmpty())
|
|
{
|
|
if(!m_bPreview)
|
|
GetDist(_T("\n单向轴线长度"), nDistMe, RSG_NONEG|RSG_NOZERO);
|
|
}
|
|
else
|
|
nDistMe = dDisY / cos(m_dAngle) + dDisX * fabs(tan(m_dAngle));
|
|
|
|
nDistMe += g_dBaseDist*2;
|
|
return nDistMe;
|
|
}
|
|
|
|
BOOL CRectAxisPage::AddToCList(double dSize, int nCount)
|
|
{
|
|
TCountAndSize *pCas = new TCountAndSize(dSize, nCount);
|
|
|
|
GetSizeDesc().AddTail(pCas);
|
|
return TRUE;
|
|
}
|
|
|
|
PDList<TCountAndSize> & CRectAxisPage::GetSizeDesc()
|
|
{
|
|
return GetSizeDesc(m_nRadio);
|
|
}
|
|
|
|
PDList<TCountAndSize> & CRectAxisPage::GetSizeDesc(int n)
|
|
{
|
|
if(n==0)
|
|
return m_lstUp;
|
|
else if(n==1)
|
|
return m_lstDown;
|
|
else if(n==2)
|
|
return m_lstLeft;
|
|
else
|
|
return m_lstRight;
|
|
}
|
|
|
|
void CRectAxisPage::ImportFromFile()
|
|
{
|
|
XString sFileName(256);
|
|
GetTempPath(255, sFileName);
|
|
sFileName << _T("tch.rax");
|
|
|
|
#if (ADS>15)
|
|
std::
|
|
#endif
|
|
ifstream in(sFileName);
|
|
if(!in)
|
|
return;
|
|
|
|
char szTit[256]="";
|
|
in.getline(szTit, 255);
|
|
if(strcmp(szTit, _AS(s_szFileTitle))!=0)
|
|
return;
|
|
|
|
m_lstLeft.Clear(); m_lstRight.Clear();
|
|
m_lstUp.Clear(); m_lstDown.Clear();
|
|
|
|
CString sName;
|
|
while(!(!in))
|
|
{
|
|
char buf[256]="";
|
|
in >> buf;
|
|
XString sContent((LPCTSTR)TString((const char*)buf));
|
|
if(!sContent || sContent[0]==_T('['))
|
|
{
|
|
sName = sContent;
|
|
continue;
|
|
}
|
|
if(sName == _T("[Up]"))
|
|
{
|
|
int nCount;
|
|
double dSize;
|
|
if(_stscanf(sContent, _T("%d*%lf"), &nCount, &dSize) != 2)
|
|
return;
|
|
|
|
m_lstUp.AddTail(new TCountAndSize(dSize, nCount));
|
|
}
|
|
else if(sName == _T("[Down]"))
|
|
{
|
|
int nCount;
|
|
double dSize;
|
|
if(_stscanf(sContent, _T("%d*%lf"), &nCount, &dSize) != 2)
|
|
return;
|
|
|
|
m_lstDown.AddTail(new TCountAndSize(dSize, nCount));
|
|
}
|
|
else if(sName == _T("[Left]"))
|
|
{
|
|
int nCount;
|
|
double dSize;
|
|
if(_stscanf(sContent, _T("%d*%lf"), &nCount, &dSize) != 2)
|
|
return;
|
|
|
|
m_lstLeft.AddTail(new TCountAndSize(dSize, nCount));
|
|
}
|
|
else if(sName == _T("[Right]"))
|
|
{
|
|
int nCount;
|
|
double dSize;
|
|
if(_stscanf(sContent, _T("%d*%lf"), &nCount, &dSize) != 2)
|
|
return;
|
|
|
|
m_lstRight.AddTail(new TCountAndSize(dSize, nCount));
|
|
}
|
|
else if(sName == _T("[Angle]"))
|
|
{
|
|
if(_stscanf(sContent, _T("%lf"), &m_dAngle) != 1)
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void CRectAxisPage::ExportToFile()
|
|
{
|
|
ReplaceOffset(GetSizeDesc());
|
|
|
|
XString sFileName(256);
|
|
GetTempPath(255, sFileName);
|
|
sFileName << _T("tch.rax");
|
|
|
|
#if (ADS>15)
|
|
std::
|
|
#endif
|
|
ofstream out(sFileName);
|
|
if(!out) {
|
|
return;
|
|
}
|
|
|
|
out << _AS(s_szFileTitle) << "\n";
|
|
// 下开间
|
|
out << "[Down]\n";
|
|
for(int i=0; i<m_lstDown.GetDataNum(); i++) {
|
|
TCountAndSize &rec=*m_lstDown[i];
|
|
out << rec.m_nCount << "*" << rec.m_dSize <<"\n";
|
|
}
|
|
|
|
// 左进深
|
|
out << "[Left]\n";
|
|
for(i=0; i<m_lstLeft.GetDataNum(); i++) {
|
|
TCountAndSize &rec=*m_lstLeft[i];
|
|
out << rec.m_nCount << "*" << rec.m_dSize << "\n";
|
|
}
|
|
|
|
// 上开间
|
|
out << "[Up]\n";
|
|
for(i=0; i<m_lstUp.GetDataNum(); i++) {
|
|
TCountAndSize &rec=*m_lstUp[i];
|
|
out << rec.m_nCount << "*" << rec.m_dSize << "\n";
|
|
}
|
|
|
|
// 右进深
|
|
out << "[Right]\n";
|
|
for(i=0; i<m_lstRight.GetDataNum(); i++) {
|
|
TCountAndSize &rec=*m_lstRight[i];
|
|
out << rec.m_nCount << "*" << rec.m_dSize << "\n";
|
|
}
|
|
|
|
// 夹角
|
|
out << "[Angle]\n";
|
|
out << m_dAngle << "\n";
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CArcAxisPage dialog
|
|
const TCHAR *CArcAxisPage::s_szFileTitle = _T("TArch AAXIS Data File 1.0");
|
|
|
|
IMPLEMENT_DYNCREATE(CArcAxisPage, CAxisBasePage)
|
|
|
|
CArcAxisPage::CArcAxisPage() : CAxisBasePage()
|
|
, m_nCenter(0)
|
|
, m_nClockWise(0)
|
|
, m_bComAxis(FALSE)
|
|
, m_dInRadius(3300)
|
|
, m_nPtInsert(0)
|
|
{
|
|
}
|
|
|
|
void CArcAxisPage::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CAxisBasePage::DoDataExchange(pDX);
|
|
DDX_Radio(pDX, IDC_RADIO_CENTERANGLE, m_nCenter);
|
|
DDX_Radio(pDX, IDC_RADIO_ANTICLOCKWISE, m_nClockWise);
|
|
DDX_Text(pDX, IDC_EDIT_RADIUS, m_dInRadius);
|
|
DDV_MinMaxDouble(pDX, m_dInRadius, 0, DBL_MAX);
|
|
DDX_Control(pDX, IDC_EDIT_RADIUS, m_editRadius);
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CArcAxisPage, CAxisBasePage)
|
|
ON_BN_CLICKED(IDC_RADIO_CENTERANGLE, OnBnClickedRadioCenterangle)
|
|
ON_BN_CLICKED(IDC_RADIO_ENTERDIS, OnBnClickedRadioCenterangle)
|
|
ON_BN_CLICKED(IDC_RADIO_ANTICLOCKWISE, OnBnClickedRadioClockwise)
|
|
ON_BN_CLICKED(IDC_RADIO_CLOCKWISE, OnBnClickedRadioClockwise)
|
|
ON_EN_KILLFOCUS(IDC_EDIT_ANGLE, OnEnKillfocusEditAngle)
|
|
ON_CONTROL(WM_EDIT_MESSAGE, IDC_EDIT_ANGLE, OnMessageEditAngle)
|
|
ON_EN_CHANGE(IDC_EDIT_ANGLE, OnEnChangeEditAngle)
|
|
ON_BN_CLICKED(IDC_BUTTON_RADIUS, OnBnClickedButtonRadius)
|
|
ON_EN_CHANGE(IDC_EDIT_RADIUS, OnEnChangeEditRadius)
|
|
ON_EN_KILLFOCUS(IDC_EDIT_RADIUS, OnEnKFEditRadius)
|
|
ON_BN_CLICKED(IDC_BUTTON_INSERT, OnBnClickedButtonInsert)
|
|
ON_BN_CLICKED(IDC_BUTTON_COMMON, OnBnClickedButtonCommon)
|
|
ON_BN_CLICKED(IDC_BUTTON_PICK, OnBnClickedButtonPick)
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CArcAxisPage message handlers
|
|
|
|
BOOL CArcAxisPage::OnInitDialog()
|
|
{
|
|
CAxisBasePage::OnInitDialog();
|
|
|
|
m_spinAngle.SetBuddy(&m_editAngle);
|
|
m_spinAngle.SetRange(UD_MINVAL, UD_MAXVAL);
|
|
UDACCEL accel;
|
|
accel.nSec = 0;
|
|
accel.nInc = 5;
|
|
m_spinAngle.SetAccel((short)1, &accel);
|
|
|
|
if(m_nCenter == 0)
|
|
m_grid.GetCol(0).SetName(_T("轴夹角"));
|
|
else
|
|
m_grid.GetCol(0).SetName(_T("轴间距"));
|
|
|
|
UpdateEditDis();
|
|
UpdateGrid();
|
|
UpdateEditInput();
|
|
UpdatePreview();
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void CArcAxisPage::OnBnClickedRadioCenterangle()
|
|
{
|
|
CDataExchange dx(this, true);
|
|
DDX_Radio(&dx, IDC_RADIO_CENTERANGLE, m_nCenter);
|
|
|
|
if(m_nCenter == 0)
|
|
m_grid.GetCol(0).SetName(_T("轴夹角"));
|
|
else
|
|
m_grid.GetCol(0).SetName(_T("轴间距"));
|
|
|
|
UpdateList();
|
|
UpdateGrid();
|
|
UpdateEditInput();
|
|
}
|
|
|
|
void CArcAxisPage::OnBnClickedRadioClockwise()
|
|
{
|
|
CDataExchange dx(this, true);
|
|
DDX_Radio(&dx, IDC_RADIO_ANTICLOCKWISE, m_nClockWise);
|
|
|
|
UpdatePreview();
|
|
}
|
|
|
|
void CArcAxisPage::OnEnKillfocusEditAngle()
|
|
{
|
|
OnMessageEditAngle();
|
|
}
|
|
|
|
void CArcAxisPage::OnMessageEditAngle()
|
|
{
|
|
CString szAngle;
|
|
m_editAngle.GetWindowText(szAngle);
|
|
m_dAngle = _tstof(szAngle);
|
|
|
|
UpdateEditAngle();
|
|
}
|
|
|
|
void CArcAxisPage::OnEnChangeEditAngle()
|
|
{
|
|
CString szAngle;
|
|
m_editAngle.GetWindowText(szAngle);
|
|
m_dAngle = _tstof(szAngle);
|
|
|
|
UpdatePreview();
|
|
}
|
|
// [12/11/2007 nsh]
|
|
//-------------------------------------------------------begin-----------------------------------------------------
|
|
BOOL IsFloat(CString strTemp)
|
|
{
|
|
bool bNumFlag = true;
|
|
bool bFloatFlag = false;
|
|
CString str = strTemp;
|
|
|
|
for(int i=0;i<str.GetLength();i++)
|
|
{
|
|
if(((int)str.GetAt(i)>=48&&(int)str.GetAt(i)<=57))//0~9之间,
|
|
continue;
|
|
else if(str.GetAt(i)=='.')
|
|
{
|
|
if(bFloatFlag)
|
|
{
|
|
bNumFlag = false;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
bFloatFlag = true;
|
|
continue;
|
|
}
|
|
}
|
|
else //发现任意其他非法字符出现
|
|
{
|
|
bNumFlag = false;
|
|
break;
|
|
}
|
|
}
|
|
return bNumFlag;
|
|
|
|
}
|
|
void CArcAxisPage::OnEnChangeEditRadius()
|
|
{
|
|
// [12/6/2007 nsh]
|
|
CString sRadius;
|
|
this->GetDlgItemText(IDC_EDIT_RADIUS, sRadius);
|
|
|
|
//modify by xlc on 090602 为空时失去焦点后提示(输入过程允许为空)
|
|
//if(sRadius == "")
|
|
//{
|
|
// ::AfxMessageBox(_T("请输入一个数值!"));
|
|
// this->UpdateData(FALSE);
|
|
//}
|
|
|
|
// add by xly on 100811 解决输入的第一位是小数点的时候崩溃
|
|
sRadius.TrimLeft();
|
|
sRadius.TrimRight();
|
|
if (sRadius.GetLength() > 0)
|
|
{
|
|
// 第一位是小数点
|
|
if (sRadius.GetAt(0) == _T('.'))
|
|
{
|
|
MessageBox(_T("内弧半径请输入一个数值!"));
|
|
sRadius.Remove( _T('.'));
|
|
|
|
// 更新编辑框
|
|
m_editRadius.Clear();
|
|
UpdateData(FALSE);
|
|
}
|
|
}
|
|
|
|
|
|
if (sRadius!=_T("") && IsFloat(sRadius))
|
|
{
|
|
// delete by xly on 100810 内弧半径不能为零的修改,取消这个判断
|
|
// modify by xlc on 090525圆弧轴网半径为00时崩溃
|
|
/*if (_tstof(sRadius)<_DIST_SNAP)
|
|
{
|
|
return;
|
|
}*/
|
|
|
|
CDataExchange dx(this, TRUE);
|
|
DDX_Text(&dx, IDC_EDIT_RADIUS, m_dInRadius);
|
|
UpdatePreview();
|
|
}
|
|
//else
|
|
//{
|
|
// CString ss="3300";
|
|
// this->SetDlgItemText(IDC_EDIT_RADIUS,(LPTSTR)(LPCTSTR)ss);
|
|
//}
|
|
//
|
|
}
|
|
void CArcAxisPage::OnEnKFEditRadius()
|
|
{
|
|
if (GetDlgItem(IDCANCEL) != GetFocus())
|
|
{
|
|
CString sRadius;
|
|
this->GetDlgItemText(IDC_EDIT_RADIUS,sRadius);
|
|
|
|
// modify by xly on 100811 解决输入负数软件死掉的问题
|
|
sRadius.TrimRight();
|
|
sRadius.TrimLeft();
|
|
// if(sRadius =="")
|
|
if (sRadius ==_T("") || !IsFloat(sRadius))
|
|
{
|
|
// ::AfxMessageBox(_T("请输入一个数值!"));
|
|
MessageBox(_T("内弧半径请输入一个数值!"));
|
|
UpdateData(FALSE);
|
|
SetFocus();
|
|
}
|
|
}
|
|
}
|
|
//-----------------------------------------------------end---------------------------------------------------------
|
|
|
|
void CArcAxisPage::OnBnClickedButtonInsert()
|
|
{
|
|
int nlimit = 4;
|
|
if(fabs(m_dDisY) < AXIS_PEC)
|
|
nlimit = 2;
|
|
|
|
if(m_nPtInsert >= nlimit)
|
|
m_nPtInsert = 0;
|
|
else
|
|
m_nPtInsert++;
|
|
|
|
GetCenterPoint();
|
|
UpdatePreview();
|
|
}
|
|
|
|
void CArcAxisPage::OnBnClickedButtonRadius()
|
|
{
|
|
double dRadius = 0;
|
|
CString szInRadius;
|
|
m_editRadius.GetWindowText(szInRadius);
|
|
|
|
CAxisGridSheet *pSheet = (CAxisGridSheet*)GetParent();
|
|
if(pSheet == NULL)
|
|
return;
|
|
|
|
if(pSheet->GetInRadius(szInRadius, dRadius));
|
|
{
|
|
m_dInRadius = dRadius;
|
|
UpdateInRadius();
|
|
}
|
|
}
|
|
|
|
void CArcAxisPage::OnBnClickedButtonCommon()
|
|
{
|
|
if(m_bComAxis)
|
|
{
|
|
UpdateComonAxis( FALSE );
|
|
return;
|
|
}
|
|
|
|
CAxisGridSheet *pSheet = (CAxisGridSheet*)GetParent();
|
|
if(pSheet == NULL || !pSheet->GetComAxisLine())
|
|
{
|
|
UpdateComonAxis( FALSE );
|
|
return;
|
|
}
|
|
|
|
|
|
m_nPtInsert = 1;
|
|
CDataExchange dx(this, FALSE);
|
|
DDX_Radio(&dx, IDC_RADIO_ANTICLOCKWISE, m_nClockWise);
|
|
|
|
if(m_nCenter == 1)
|
|
{
|
|
UpdateGrid();
|
|
UpdateEditInput();
|
|
}
|
|
|
|
UpdateComonAxis( TRUE );
|
|
UpdateEditDis();
|
|
UpdateEditAngle();
|
|
UpdatePreview();
|
|
}
|
|
|
|
void CArcAxisPage::OnBnClickedButtonPick()
|
|
{
|
|
// 拾取尺寸对象,获取尺寸数据
|
|
CAxisGridSheet* pSheet = (CAxisGridSheet*)GetParent();
|
|
CArray<double, double&> arData;
|
|
if (m_nCenter == 0) // 拾取角度
|
|
{
|
|
pSheet->PickDimensions(kArc, arData);
|
|
}
|
|
else // 拾取长度
|
|
{
|
|
pSheet->PickDimensions(kRect, arData);
|
|
}
|
|
|
|
// 将数据添加到编辑框
|
|
AddDataToInputEdit(arData);
|
|
|
|
// 更新
|
|
OnEnKillfocusEditInput();
|
|
}
|
|
|
|
void CArcAxisPage::InitList()
|
|
{
|
|
UpdateList();
|
|
}
|
|
|
|
void CArcAxisPage::UpdateList()
|
|
{
|
|
m_list.ResetContent();
|
|
if(m_nCenter == 0)
|
|
{
|
|
for(int i=0; i<ELEMENTS(SZ_ANGLES); i++)
|
|
m_list.AddString(SZ_ANGLES[i]);
|
|
}
|
|
else
|
|
{
|
|
for(int i=0; i<ELEMENTS(SZ_SIZES); i++)
|
|
m_list.AddString(SZ_SIZES[i]);
|
|
}
|
|
}
|
|
|
|
void CArcAxisPage::UpdateInRadius()
|
|
{
|
|
CString szRadius;
|
|
szRadius.Format(_T("%.1f"), m_dInRadius);
|
|
szRadius.TrimRight(_T("0"));
|
|
szRadius.TrimRight(_T("."));
|
|
|
|
m_editRadius.SetWindowText(szRadius);
|
|
}
|
|
|
|
void CArcAxisPage::UpdateClockWise()
|
|
{
|
|
CDataExchange dx(this, FALSE);
|
|
DDX_Radio(&dx, IDC_RADIO_ANTICLOCKWISE, m_nClockWise);
|
|
}
|
|
|
|
void CArcAxisPage::UpdateEditAngle()
|
|
{
|
|
CString szAngle;
|
|
szAngle.Format(_T("%.3f"), m_dAngle);
|
|
szAngle.TrimRight(_T("0"));
|
|
szAngle.TrimRight(_T("."));
|
|
|
|
m_editAngle.SetWindowText(szAngle);
|
|
}
|
|
|
|
void CArcAxisPage::UpdateComonAxis( BOOL bComAxis )
|
|
{
|
|
m_bComAxis = bComAxis;
|
|
((CButton*)GetDlgItem(IDC_BUTTON_COMMON))->SetCheck(bComAxis);
|
|
GetDlgItem(IDC_EDIT_ANGLE)->EnableWindow(!bComAxis);
|
|
GetDlgItem(IDC_SPIN_ANGLE)->EnableWindow(!bComAxis);
|
|
GetDlgItem(IDC_BUTTON_INSERT)->EnableWindow(!bComAxis);
|
|
}
|
|
|
|
void CArcAxisPage::ComeBack()
|
|
{
|
|
ImportFromFile();
|
|
|
|
UpdateEditDis();
|
|
UpdateGrid();
|
|
UpdatePreview();
|
|
UpdateEditInput();
|
|
UpdateEditAngle();
|
|
UpdateInRadius();
|
|
UpdateClockWise();
|
|
}
|
|
|
|
void CArcAxisPage::GetEditDisValue()
|
|
{
|
|
m_dDisX = TotalDistance(m_lstArc);
|
|
m_dDisY = TotalDistance(m_lstRadius);
|
|
}
|
|
|
|
BOOL CArcAxisPage::AddToCList(double dSize, int nCount)
|
|
{
|
|
PDList<TCountAndSize> &lstCur = GetSizeDesc();
|
|
if(m_nCenter == 0 )
|
|
{
|
|
double dTotal = TotalDistance(lstCur);
|
|
dTotal += dSize * nCount;
|
|
if(dTotal -360 > AXIS_PEC)
|
|
{
|
|
MessageBox(_T("总角度不能超过360度!"));
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
TCountAndSize *pCas = new TCountAndSize(dSize, nCount);
|
|
GetSizeDesc().AddTail(pCas);
|
|
return TRUE;
|
|
}
|
|
|
|
PDList<TCountAndSize> & CArcAxisPage::GetSizeDesc()
|
|
{
|
|
return GetSizeDesc(m_nCenter);
|
|
}
|
|
|
|
PDList<TCountAndSize> & CArcAxisPage::GetSizeDesc(int n)
|
|
{
|
|
if(n==0)
|
|
return m_lstArc;
|
|
else
|
|
return m_lstRadius;
|
|
}
|
|
|
|
void CArcAxisPage::CopyPropertiesFrom(CArcAxisPage *pSource)
|
|
{
|
|
m_dDisX = pSource->m_dDisX;
|
|
m_dDisY = pSource->m_dDisY;
|
|
m_dAngle = pSource->m_dAngle;
|
|
m_nClockWise = pSource->m_nClockWise;
|
|
m_ptIns = pSource->m_ptIns;
|
|
m_dInRadius = pSource->m_dInRadius;
|
|
|
|
m_lstArc.Clear();
|
|
m_lstRadius.Clear();
|
|
CopyPDList(pSource->m_lstArc, m_lstArc);
|
|
CopyPDList(pSource->m_lstRadius, m_lstRadius);
|
|
}
|
|
|
|
int CArcAxisPage::InsertToCSpace()
|
|
{
|
|
m_bPreview = FALSE;
|
|
int iTileMode=0;
|
|
VERIFY(xg_getvar(_T("TILEMODE"), &iTileMode)==RTNORM);
|
|
|
|
// add by xlc on 090410 图纸空间激活窗口绘制圆弧轴网
|
|
int cvport=0;
|
|
VERIFY(xg_getvar(_T("CVPORT"), &cvport)==RTNORM);
|
|
|
|
PickSet ss(SS_FREE);
|
|
ss.IncludeBegin();
|
|
AcDbBlockTable *pTable = NULL;
|
|
acdbHostApplicationServices()->workingDatabase()
|
|
->getSymbolTable(pTable, AcDb::kForRead);
|
|
AcDbBlockTableRecord *pBlockTableRecord = NULL;
|
|
|
|
// modify by xlc on 090410
|
|
//pTable->getAt((iTileMode==0)?ACDB_PAPER_SPACE:ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
|
|
pTable->getAt((iTileMode==0 && cvport==1)?ACDB_PAPER_SPACE:ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
|
|
|
|
pTable->close();
|
|
|
|
DrawEntity(pBlockTableRecord);
|
|
pBlockTableRecord->close();
|
|
ss.IncludeEnd();
|
|
|
|
int nRet = RTNORM;
|
|
if(!m_bComAxis)
|
|
{
|
|
TADSGePoint3d pt(Wcs2Ucs(m_ptIns));
|
|
nRet = DragPickSet(ss, pt);
|
|
if(nRet != RTNORM)
|
|
ss.Delete();
|
|
else
|
|
ExportToFile();
|
|
}
|
|
else
|
|
{
|
|
m_bComAxis = FALSE;
|
|
ExportToFile();
|
|
}
|
|
|
|
return nRet;
|
|
}
|
|
|
|
BOOL CArcAxisPage::DrawEntity(AcDbBlockTableRecord *&pBlockTabRecord)
|
|
{
|
|
GetCenterPoint();
|
|
BOOL bArc = DrawAxisArc(pBlockTabRecord);
|
|
BOOL bLine = DrawAxisLine(pBlockTabRecord);
|
|
if(m_bPreview)
|
|
DrawCircleCenter(pBlockTabRecord);
|
|
|
|
if(!bArc && !bLine)
|
|
return FALSE;
|
|
else
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CArcAxisPage::DrawAxisArc(AcDbBlockTableRecord *&pBlockTabRecord)
|
|
{
|
|
if(m_lstArc.IsEmpty())
|
|
return FALSE;
|
|
|
|
double dTotalAngle = m_dDisX;
|
|
double dStartAng, dEndAng;
|
|
if(m_nClockWise == 1) {
|
|
dStartAng=CT_std_angle((m_dAngle-dTotalAngle)*PI/180.0);
|
|
dEndAng = m_dAngle*PI/180.0;
|
|
} else {
|
|
dStartAng = m_dAngle*PI/180.0;
|
|
dEndAng = CT_std_angle((m_dAngle+dTotalAngle)*PI/180.0);
|
|
}
|
|
// [1/14/2008 nsh]
|
|
//dStartAng=CT_std_angle(dStartAng-1E-15);
|
|
//dEndAng=CT_std_angle(dEndAng+1E-15);
|
|
// [2010-4-19 wubo] 圆弧出头长度变为原来的十分之一
|
|
//dStartAng=CT_std_angle(dStartAng-_DIST_SNAP/m_dInRadius);
|
|
//dEndAng=CT_std_angle(dEndAng+_DIST_SNAP/m_dInRadius);
|
|
|
|
// modify by xly on 100810 内弧半径为零时发生崩溃,因为这个计算分母不能为:0_DIST_SNAP/m_dInRadius/10
|
|
// 增加一个为零的判断
|
|
// dStartAng=CT_std_angle(dStartAng-_DIST_SNAP/m_dInRadius/10);
|
|
// dEndAng=CT_std_angle(dEndAng+_DIST_SNAP/m_dInRadius/10);
|
|
if (fabs(m_dInRadius) < _DIST_SNAP) // 半径为0
|
|
{
|
|
dStartAng=CT_std_angle(dStartAng);
|
|
dEndAng=CT_std_angle(dEndAng);
|
|
}
|
|
else // 半径不为0
|
|
{
|
|
dStartAng=CT_std_angle(dStartAng-_DIST_SNAP/m_dInRadius/10);
|
|
dEndAng=CT_std_angle(dEndAng+_DIST_SNAP/m_dInRadius/10);
|
|
}
|
|
|
|
if(!m_bPreview)
|
|
{
|
|
dStartAng += Ucs2Wcs(0);
|
|
dEndAng += Ucs2Wcs(0);
|
|
}
|
|
|
|
int nColor = 3;
|
|
AcDbObjectId idLayer = InitLayer(LAY_AXIS);
|
|
BOOL bCircle = (fabs(TotalDistance(m_lstArc)-360) < AXIS_PEC);
|
|
|
|
// 绘制起始弧线
|
|
if(m_dInRadius>_DIST_SNAP)
|
|
{
|
|
if(bCircle)
|
|
{
|
|
AcDbCircle *pCircle = new AcDbCircle(m_ptCenter, AcGeVector3d::kZAxis, m_dInRadius);
|
|
if(m_bPreview)
|
|
pCircle->setColorIndex(nColor);
|
|
else
|
|
pCircle->setLayer(idLayer);
|
|
pBlockTabRecord->appendAcDbEntity(pCircle);
|
|
pCircle->close();
|
|
}
|
|
else
|
|
{
|
|
AcDbArc *pArc = new AcDbArc(m_ptCenter, AcGeVector3d::kZAxis, m_dInRadius, dStartAng, dEndAng);
|
|
if(m_bPreview)
|
|
pArc->setColorIndex(nColor);
|
|
else
|
|
pArc->setLayer(idLayer);
|
|
pBlockTabRecord->appendAcDbEntity(pArc);
|
|
pArc->close();
|
|
}
|
|
}
|
|
PDList<double> lstSizes;
|
|
Disperse(m_dInRadius, m_lstRadius, lstSizes);
|
|
for(int i=0; i<lstSizes.GetDataNum(); i++)
|
|
{
|
|
if(bCircle)
|
|
{
|
|
AcDbCircle *pCircle = new AcDbCircle(m_ptCenter, AcGeVector3d::kZAxis, *lstSizes[i]);
|
|
if(m_bPreview)
|
|
pCircle->setColorIndex(nColor);
|
|
else
|
|
pCircle->setLayer(idLayer);
|
|
pBlockTabRecord->appendAcDbEntity(pCircle);
|
|
pCircle->close();
|
|
}
|
|
else
|
|
{
|
|
AcDbArc *pArc = new AcDbArc(m_ptCenter, AcGeVector3d::kZAxis, *lstSizes[i], dStartAng, dEndAng);
|
|
if(m_bPreview)
|
|
pArc->setColorIndex(nColor);
|
|
else
|
|
pArc->setLayer(idLayer);
|
|
pBlockTabRecord->appendAcDbEntity(pArc);
|
|
pArc->close();
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CArcAxisPage::DrawAxisLine(AcDbBlockTableRecord *&pBlockTabRecord)
|
|
{
|
|
if(m_lstArc.IsEmpty())
|
|
return FALSE;
|
|
|
|
double dTotalRadius=1000.0;
|
|
if(m_lstRadius.IsEmpty())
|
|
{
|
|
if(!m_bPreview)
|
|
GetDist(_T("\n单向轴线长度"), dTotalRadius, RSG_NONEG|RSG_NOZERO);
|
|
else
|
|
dTotalRadius = 1000.0;
|
|
}
|
|
else
|
|
dTotalRadius = TotalDistance(m_lstRadius);
|
|
|
|
int nColor = 1;
|
|
AcDbObjectId idLayer = InitLayer(LAY_AXIS);
|
|
BOOL bCircle = (fabs(TotalDistance(m_lstArc)-360) < AXIS_PEC);
|
|
|
|
double dStartRadius = m_dInRadius - g_dBaseDist;
|
|
if(dStartRadius < AXIS_PEC)
|
|
dStartRadius=100;
|
|
|
|
double dEndRadius = m_dInRadius + dTotalRadius + g_dBaseDist;
|
|
|
|
// 绘制起始线
|
|
XPoint pt1, pt2;
|
|
double dStartAng=m_dAngle*PI/180.0;
|
|
if(!m_bPreview)
|
|
dStartAng += Ucs2Wcs(0);
|
|
|
|
if(m_bPreview || !m_bComAxis || bCircle)
|
|
{
|
|
ads_polar(m_ptCenter, dStartAng, dStartRadius, pt1);
|
|
ads_polar(m_ptCenter, dStartAng, dEndRadius, pt2);
|
|
AcDbLine *pline = new AcDbLine(pt1, pt2);
|
|
if(m_bPreview)
|
|
pline->setColorIndex(nColor);
|
|
else
|
|
pline->setLayer(idLayer);
|
|
|
|
pBlockTabRecord->appendAcDbEntity(pline);
|
|
pline->close();
|
|
}
|
|
|
|
PDList<double> lstAngles;
|
|
Disperse(0, m_lstArc, lstAngles);
|
|
int len=lstAngles.GetDataNum();
|
|
if(bCircle)
|
|
len--;
|
|
|
|
for(int i=0; i<len; i++)
|
|
{
|
|
double nDrt = dStartAng;
|
|
if(m_nClockWise == 1)
|
|
nDrt = CT_std_angle(nDrt-(*lstAngles[i])*PI/180.0);
|
|
else
|
|
nDrt = CT_std_angle(nDrt+(*lstAngles[i])*PI/180.0);
|
|
|
|
ads_polar(m_ptCenter, nDrt, dStartRadius, pt1);
|
|
ads_polar(m_ptCenter, nDrt, dEndRadius, pt2);
|
|
AcDbLine *pline = new AcDbLine(pt1, pt2);
|
|
if(m_bPreview)
|
|
pline->setColorIndex(nColor);
|
|
else
|
|
pline->setLayer(idLayer);
|
|
|
|
pBlockTabRecord->appendAcDbEntity(pline);
|
|
pline->close();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CArcAxisPage::DrawCircleCenter(AcDbBlockTableRecord *&pBlockTabRecord)
|
|
{
|
|
double dWidth = 0.05 * (m_dInRadius + m_dDisY);
|
|
XPoint ptSta1 = m_ptCenter + XPoint(dWidth, 0, 0);
|
|
XPoint ptEnd1 = m_ptCenter + XPoint(-dWidth, 0, 0);
|
|
AcDbLine *pline1 = new AcDbLine(ptSta1, ptEnd1);
|
|
pline1->setColorIndex(3);
|
|
pBlockTabRecord->appendAcDbEntity(pline1);
|
|
pline1->close();
|
|
|
|
XPoint ptSta2 = m_ptCenter + XPoint(0, dWidth, 0);
|
|
XPoint ptEnd2 = m_ptCenter + XPoint(0, -dWidth, 0);
|
|
AcDbLine *pline2 = new AcDbLine(ptSta2, ptEnd2);
|
|
pline2->setColorIndex(3);
|
|
pBlockTabRecord->appendAcDbEntity(pline2);
|
|
pline2->close();
|
|
return TRUE;
|
|
}
|
|
|
|
XPoint CArcAxisPage::GetCenterPoint()
|
|
{
|
|
double dTotalAngle = m_dDisX;
|
|
double dStartAng, dEndAng;
|
|
if(m_nClockWise == 1)
|
|
{
|
|
dStartAng = m_dAngle*PI/180.0;
|
|
dEndAng = CT_std_angle((m_dAngle-dTotalAngle)*PI/180.0);
|
|
}
|
|
else
|
|
{
|
|
dStartAng = m_dAngle*PI/180.0;
|
|
dEndAng = CT_std_angle((m_dAngle+dTotalAngle)*PI/180.0);
|
|
}
|
|
|
|
dStartAng=CT_std_angle(dStartAng-1E-15);
|
|
dEndAng=CT_std_angle(dEndAng+1E-15);
|
|
if(!m_bPreview)
|
|
{
|
|
dStartAng += Ucs2Wcs(0);
|
|
dEndAng += Ucs2Wcs(0);
|
|
}
|
|
|
|
switch(m_nPtInsert)
|
|
{
|
|
case 0:
|
|
m_ptCenter = m_ptIns;
|
|
break;
|
|
case 1:
|
|
ads_polar(m_ptIns, dStartAng, -m_dInRadius, m_ptCenter);
|
|
break;
|
|
case 2:
|
|
{
|
|
if(fabs(m_dDisY) > AXIS_PEC)
|
|
ads_polar(m_ptIns, dStartAng, -(m_dInRadius+m_dDisY), m_ptCenter);
|
|
else
|
|
ads_polar(m_ptIns, dEndAng, -m_dInRadius, m_ptCenter);
|
|
}
|
|
break;
|
|
case 3:
|
|
ads_polar(m_ptIns, dEndAng, -(m_dInRadius+m_dDisY), m_ptCenter);
|
|
break;
|
|
case 4:
|
|
ads_polar(m_ptIns, dEndAng, -m_dInRadius, m_ptCenter);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return m_ptCenter;
|
|
}
|
|
|
|
void CArcAxisPage::ImportFromFile()
|
|
{
|
|
XString sFileName(256);
|
|
GetTempPath(255, sFileName);
|
|
sFileName << _T("tch.aax");
|
|
|
|
#if (ADS>15)
|
|
std::
|
|
#endif
|
|
ifstream in(sFileName);
|
|
if(!in) {
|
|
return;
|
|
}
|
|
|
|
char szTit[256]="";
|
|
in.getline(szTit, 255);
|
|
if(strcmp(szTit, _AS(s_szFileTitle))!=0) {
|
|
return;
|
|
}
|
|
|
|
m_lstArc.Clear(); m_lstRadius.Clear();
|
|
in >> m_dInRadius;
|
|
in >> m_dAngle;
|
|
in >> m_nClockWise;
|
|
in >> m_nPtInsert;
|
|
|
|
// 下开间
|
|
int i=0;
|
|
char buf[256]="";
|
|
in >> buf;
|
|
XString sSectionTitle((LPCTSTR)TString((const char*)buf));
|
|
if(sSectionTitle!=_T("[Arc]")) {
|
|
return;
|
|
}
|
|
|
|
for(i=0; i<2; i++) {
|
|
PDList<TCountAndSize> &lstDesc=GetSizeDesc(i);
|
|
while(!(!in)) {
|
|
char buf1[256]="";
|
|
in >> buf1;
|
|
XString sContent((LPCTSTR)TString((const char*)buf1));
|
|
if(!sContent || sContent[0]==_T('[')) break;
|
|
int nCount;
|
|
double dSize;
|
|
if(_stscanf(sContent, _T("%d*%lf"), &nCount, &dSize)!=2) {
|
|
return;
|
|
}
|
|
lstDesc.AddTail(new TCountAndSize(dSize, nCount));
|
|
}
|
|
}
|
|
}
|
|
|
|
void CArcAxisPage::ExportToFile()
|
|
{
|
|
XString sFileName(256);
|
|
GetTempPath(255, sFileName);
|
|
sFileName << _T("tch.aax");
|
|
|
|
#if (ADS>15)
|
|
std::
|
|
#endif
|
|
ofstream out(sFileName);
|
|
if(!out)
|
|
return;
|
|
|
|
out << _AS(s_szFileTitle) << "\n";
|
|
|
|
out << m_dInRadius << "\n";
|
|
out << m_dAngle << "\n";
|
|
out << m_nClockWise << "\n";
|
|
out << m_nPtInsert << "\n";
|
|
|
|
// 开间
|
|
out << "[Arc]\n";
|
|
for(int i=0; i<m_lstArc.GetDataNum(); i++) {
|
|
TCountAndSize &rec=*m_lstArc[i];
|
|
out << rec.m_nCount << "*" << rec.m_dSize << "\n";
|
|
}
|
|
|
|
// 左进深
|
|
out << "[Radius]\n";
|
|
for(i=0; i<m_lstRadius.GetDataNum(); i++) {
|
|
TCountAndSize &rec=*m_lstRadius[i];
|
|
out << rec.m_nCount << "*" << rec.m_dSize <<"\n";
|
|
}
|
|
}
|
|
|
|
// [2010-4-2 wubo] 重载虚函数,使表格中的轴夹角列默认为7个数的宽度
|
|
void CArcAxisPage::InitGrid()
|
|
{
|
|
m_grid.Clear();
|
|
m_grid.AppendCol(_T("轴间距"), 68);
|
|
m_grid.AppendCol(_T("个数"), 44);
|
|
m_grid.GetCol(0).SetComboEdit();
|
|
m_grid.GetCol(1).SetComboEdit();
|
|
m_grid.SetColPosFix();
|
|
m_grid.SetColFixLength();
|
|
m_grid.Create(this, IDC_LIST_INPUT);
|
|
m_grid.FitLastCol();
|
|
}
|
|
|
|
// [2010-4-2 wubo] 重载虚函数,使轴夹角可为小数,总位数为7
|
|
void CArcAxisPage::UpdateGrid()
|
|
{
|
|
if(m_nCenter == 0)
|
|
{
|
|
m_grid.Clear();
|
|
PDList<TCountAndSize> &lstCurrent = GetSizeDesc();
|
|
for(int i=0; i<lstCurrent.GetDataNum(); i++)
|
|
{
|
|
TCountAndSize *pCAS = lstCurrent[i];
|
|
if(pCAS != NULL && pCAS->m_nPosition == 0)
|
|
{
|
|
WDGridRow *pRow = new WDGridRow(m_grid);
|
|
CString sText;
|
|
// 总位数为7
|
|
sText.Format(_T("%.0f"), pCAS->m_dSize);
|
|
int iIntPartLen = sText.GetLength();
|
|
int iDecPartLen = (6 - iIntPartLen >= 0) ? 6 - iIntPartLen : 0;
|
|
sText.Format(_T("%.*f"), iDecPartLen, pCAS->m_dSize);
|
|
sText.TrimRight(_T("0"));
|
|
sText.TrimRight(_T("."));
|
|
(*pRow)[0].SetText(sText);
|
|
(*pRow)[1].SetText(XString(_T("%d"), pCAS->m_nCount));
|
|
m_grid.AppendRow(pRow);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CAxisBasePage::UpdateGrid();
|
|
}
|
|
}
|
|
|
|
// [2010-4-2 wubo] 重载虚函数,使总长度显示3位小数
|
|
void CArcAxisPage::UpdateEditDis()
|
|
{
|
|
GetEditDisValue();
|
|
CString szDisX, szDisY;
|
|
szDisX.Format(_T("%.3f"), m_dDisX);
|
|
szDisX.TrimRight(_T("0"));
|
|
szDisX.TrimRight(_T("."));
|
|
szDisY.Format(_T("%.1f"), m_dDisY);
|
|
szDisY.TrimRight(_T("0"));
|
|
szDisY.TrimRight(_T("."));
|
|
|
|
CAxisGridSheet *pSheet = (CAxisGridSheet*)GetParent();
|
|
if(pSheet != NULL)
|
|
pSheet->UpdateSize(szDisX, szDisY);
|
|
}
|
|
|
|
// [2010-4-2 wubo] 重载虚函数,使轴夹角可为小数,总位数为7
|
|
void CArcAxisPage::UpdateEditInput()
|
|
{
|
|
CString sText = _T("");
|
|
|
|
CString sTemp = _T("");
|
|
for(long i=0; i<m_grid.GetRowNum(); i++)
|
|
{
|
|
CString szSize = m_grid[i][0].GetText().cs();
|
|
CString szCount = m_grid[i][1].GetText().cs();
|
|
if(szSize == _T("") || szCount == _T(""))
|
|
continue;
|
|
|
|
double dSize = _tstof(szSize);
|
|
int nCount = _ttoi(szCount);
|
|
sTemp.Format(_T("%.0f"), dSize);
|
|
int iIntPartLen = sTemp.GetLength();
|
|
int iDecPartLen = (6 - iIntPartLen >= 0) ? 6 - iIntPartLen : 0;
|
|
sTemp = sText;
|
|
if(nCount>1)
|
|
{
|
|
sText.Format(_T("%s%d*"), sTemp, nCount);
|
|
}
|
|
sTemp = sText;
|
|
sText.Format(_T("%s%.*f"), sTemp, iDecPartLen, dSize);
|
|
sText.TrimRight(_T("0"));
|
|
sText.TrimRight(_T("."));
|
|
sText += _T(" ");
|
|
}
|
|
m_editInput.SetWindowText(sText);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CAxisGridSheet
|
|
int CAxisGridSheet::s_nPage = 0;
|
|
|
|
IMPLEMENT_DYNAMIC(CAxisGridSheet, CAcUiTabMainDialog)
|
|
|
|
CAxisGridSheet::CAxisGridSheet(CWnd* parent)
|
|
:CAcUiTabMainDialog(CAxisGridSheet::IDD, parent)
|
|
{
|
|
}
|
|
|
|
void CAxisGridSheet::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CAcUiTabMainDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_TAB, m_tab);
|
|
DDX_Control(pDX, IDC_STATIC_X, m_staticX);
|
|
DDX_Control(pDX, IDC_STATIC_Y, m_staticY);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CAxisGridSheet, CAcUiTabMainDialog)
|
|
ON_WM_DESTROY()
|
|
ON_BN_CLICKED(IDC_BUTTON_COMEBACK, OnBnClickedButtonComeback)
|
|
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnTcnSelchangeTab)
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CAxisGridSheet message handlers
|
|
|
|
BOOL CAxisGridSheet::OnInitDialog()
|
|
{
|
|
BOOL bResult = CAcUiTabMainDialog::OnInitDialog();
|
|
|
|
SetAcadTabPointer(&m_tab);
|
|
AddTab(0, _T("直线轴网"), CRectAxisPage::IDD, &m_pageRectAxis);
|
|
AddTab(1, _T("圆弧轴网"), CArcAxisPage::IDD, &m_pageArcAxis);
|
|
m_tab.SetActiveTab(s_nPage);
|
|
|
|
if(m_tab.GetActiveTab() == 0)
|
|
{
|
|
m_staticX.SetWindowText(_T("总开间:"));
|
|
m_pageRectAxis.UpdateEditDis();
|
|
}
|
|
else
|
|
{
|
|
m_staticX.SetWindowText(_T("总夹角:"));
|
|
m_pageArcAxis.UpdateEditDis();
|
|
}
|
|
|
|
return bResult;
|
|
}
|
|
|
|
void CAxisGridSheet::OnTcnSelchangeTab(NMHDR *pNMHDR, LRESULT *pResult)
|
|
{
|
|
if(m_tab.GetActiveTab() == 0)
|
|
{
|
|
m_staticX.SetWindowText(_T("总开间:"));
|
|
m_pageRectAxis.UpdateEditDis();
|
|
}
|
|
else
|
|
{
|
|
m_staticX.SetWindowText(_T("总夹角:"));
|
|
m_pageArcAxis.UpdateEditDis();
|
|
}
|
|
|
|
*pResult = 0;
|
|
}
|
|
|
|
void CAxisGridSheet::OnBnClickedButtonComeback()
|
|
{
|
|
if(m_tab.GetActiveTab() == 0)
|
|
m_pageRectAxis.ComeBack();
|
|
else
|
|
m_pageArcAxis.ComeBack();
|
|
}
|
|
|
|
void CAxisGridSheet::OnDestroy()
|
|
{
|
|
CAcUiTabMainDialog::OnDestroy();
|
|
s_nPage = m_tab.GetActiveTab();
|
|
}
|
|
|
|
void CAxisGridSheet::OnOK()
|
|
{
|
|
BeginEditorCommand();
|
|
|
|
int nRet;
|
|
if(m_tab.GetActiveTab() == 0)
|
|
nRet = m_pageRectAxis.InsertToCSpace();
|
|
else
|
|
nRet = m_pageArcAxis.InsertToCSpace();
|
|
|
|
if(nRet == RTCAN)
|
|
CancelEditorCommand();
|
|
else if(nRet==RTNONE)
|
|
CompleteEditorCommand();
|
|
else
|
|
CAcUiTabMainDialog::OnOK();
|
|
}
|
|
|
|
void CAxisGridSheet::UpdateSize(CString szDisX, CString szDisY)
|
|
{
|
|
CDataExchange dx(this, FALSE);
|
|
DDX_Text(&dx, IDC_EDIT_HDIS, szDisX);
|
|
DDX_Text(&dx, IDC_EDIT_VDIS, szDisY);
|
|
}
|
|
|
|
BOOL CAxisGridSheet::GetInRadius(const CString &szInRadius, double &dRadius)
|
|
{
|
|
BeginEditorCommand();
|
|
int nRet = acedGetDist(NULL, XString(_T("\n请输入内弧半径<%s>"), szInRadius), &dRadius);
|
|
CompleteEditorCommand();
|
|
|
|
if(nRet == RTNORM)
|
|
return TRUE;
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
BOOL CAxisGridSheet::GetComAxisLine()
|
|
{
|
|
BeginEditorCommand();
|
|
|
|
if(!SelectAxisGrid())
|
|
{
|
|
CompleteEditorCommand();
|
|
return FALSE;
|
|
}
|
|
|
|
CArcAxisPage *pArc = new CArcAxisPage;
|
|
pArc->CopyPropertiesFrom(&m_pageArcAxis);
|
|
pArc->m_bPreview = FALSE;
|
|
pArc->m_nPtInsert = 1;
|
|
if(pArc->m_lstArc.GetDataNum() == 0)
|
|
{
|
|
pArc->m_lstArc.AddTail(new TCountAndSize(30, 3));
|
|
pArc->UpdateEditDis();
|
|
}
|
|
|
|
XLine line(*m_lstPoint.Head(), *m_lstPoint.Tail());
|
|
XPoint ptMid;
|
|
ptMid = line.MidPoint();
|
|
ptMid = Wcs2Ucs(ptMid);
|
|
double dRotate = line.Direction();
|
|
dRotate += Wcs2Ucs(0);
|
|
|
|
m_nQuadrant = 0;
|
|
PickSet ss(SS_FREE);
|
|
|
|
// add by xlc on 090423 图纸空间弧形轴网共用轴线时无预览
|
|
int cvport=0;
|
|
VERIFY(xg_getvar(_T("CVPORT"), &cvport)==RTNORM);
|
|
|
|
while(1)
|
|
{
|
|
int type = 0;
|
|
resbuf result;
|
|
if (acedGrRead(13, &type, &result) != RTNORM)
|
|
{
|
|
ss.Erase();
|
|
delete pArc;
|
|
CompleteEditorCommand();
|
|
return FALSE;
|
|
}
|
|
if (type != 5)
|
|
{
|
|
ss.Erase();
|
|
m_pageArcAxis.CopyPropertiesFrom(pArc);
|
|
m_pageArcAxis.UpdateGrid();
|
|
m_pageArcAxis.UpdateEditInput();
|
|
break;
|
|
}
|
|
|
|
XPoint ptCur = result.resval.rpoint;
|
|
if(GetQuadrant( ptCur, line, ptMid, dRotate, pArc ))
|
|
{
|
|
ss.Erase();
|
|
ss.IncludeBegin();
|
|
int iTileMode=0;
|
|
VERIFY(xg_getvar(_T("TILEMODE"), &iTileMode)==RTNORM);
|
|
AcDbBlockTable *pTable = NULL;
|
|
acdbHostApplicationServices()->workingDatabase()
|
|
->getSymbolTable(pTable, AcDb::kForRead);
|
|
AcDbBlockTableRecord *pBlockTableRecord = NULL;
|
|
pTable->getAt((iTileMode==0&&cvport==1)?ACDB_PAPER_SPACE:ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
|
|
pTable->close();
|
|
pArc->DrawEntity(pBlockTableRecord);
|
|
pBlockTableRecord->close();
|
|
ss.IncludeEnd();
|
|
}
|
|
}
|
|
delete pArc;
|
|
|
|
CompleteEditorCommand();
|
|
return TRUE;
|
|
}
|
|
|
|
BOOL CAxisGridSheet::SelectAxisGrid()
|
|
{
|
|
Entity ent;
|
|
RBList rb(RTDXF0, _T("LINE"), 8, LAY_AXIS, NULL);
|
|
if(ent.FilterSelect(_T("\n请拾取要共用的边界轴线 <返回>:"), rb) != RTNORM)
|
|
return FALSE;
|
|
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbLine, pAxis);
|
|
if(!pAxis)
|
|
return FALSE;
|
|
|
|
PickSet ss(SS_FREE);
|
|
ss.Get(_T("X"), NULL, NULL, RBList(8, LAY_AXIS, NULL));
|
|
|
|
m_lstPoint.Reset();
|
|
for(long i=0; i<ss.Length(); i++)
|
|
{
|
|
AcGePoint3dArray points;
|
|
OPENOBJ_BEGIN(ss[i], AcDb::kForRead, AcDbEntity, pEnt);
|
|
if(!pEnt)
|
|
continue;
|
|
|
|
pEnt->intersectWith(pAxis, AcDb::kOnBothOperands, points);
|
|
OPENOBJ_END();
|
|
|
|
if(points.length() > 0)
|
|
m_lstPoint.Append(new XPoint(points[0]));
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
if(m_lstPoint.Length() < 2)
|
|
return FALSE;
|
|
|
|
m_lstPoint.QuickSort(CmpAxisGridPoint);
|
|
return TRUE;
|
|
}
|
|
|
|
int CAxisGridSheet::GetVectorPos( AcGeVector2d vec )
|
|
{
|
|
int nPos = -1;
|
|
vec = vec.normal();
|
|
double dAngle = vec.angle() * 180 / PI;
|
|
if( dAngle > 0 && dAngle < 90 )
|
|
nPos = 1;
|
|
else if( dAngle > 90 && dAngle < 180 )
|
|
nPos = 2;
|
|
else if( dAngle > 180 && dAngle < 270 )
|
|
nPos = 3;
|
|
else if( dAngle > 270 && dAngle < 360 )
|
|
nPos = 4;
|
|
return nPos;
|
|
}
|
|
|
|
BOOL CAxisGridSheet::GetQuadrant(const XPoint &point, const XLine &line, const XPoint &ptMid, double dRotate, CArcAxisPage *pArc)
|
|
{
|
|
if(pArc == NULL)
|
|
return FALSE;
|
|
|
|
AcGeVector2d vec = point.AsAcGePoint2d() - ptMid.AsAcGePoint2d();
|
|
vec.rotateBy(PI/2 - dRotate);
|
|
int nPos = GetVectorPos( vec );
|
|
if( nPos == 1 || nPos == 2 )
|
|
{
|
|
if( m_nQuadrant != 1 && m_nQuadrant != 2 )
|
|
{
|
|
pArc->m_lstRadius.Clear();
|
|
for(int i=0; i<m_lstPoint.Length()-1; i++)
|
|
{
|
|
double dDis = m_lstPoint[i]->Distance2d(*m_lstPoint[i+1]);
|
|
pArc->m_lstRadius.AddTail(new TCountAndSize(dDis, 1));
|
|
}
|
|
pArc->m_lstRadius.ReverseList();
|
|
pArc->m_ptIns = line.EndPoint();
|
|
pArc->m_dAngle = dRotate*180/PI + 180;
|
|
}
|
|
pArc->m_nClockWise = (nPos == 1) ? 0 : 1;
|
|
m_nQuadrant = nPos;
|
|
}
|
|
else if( nPos == 3 || nPos == 4 )
|
|
{
|
|
if( m_nQuadrant != 3 && m_nQuadrant != 4 )
|
|
{
|
|
pArc->m_lstRadius.Clear();
|
|
for(int i=0; i<m_lstPoint.Length()-1; i++)
|
|
{
|
|
double dDis = m_lstPoint[i]->Distance2d(*m_lstPoint[i+1]);
|
|
pArc->m_lstRadius.AddTail(new TCountAndSize(dDis, 1));
|
|
}
|
|
pArc->m_ptIns = line.StartPoint();
|
|
pArc->m_dAngle = dRotate*180/PI;
|
|
}
|
|
pArc->m_nClockWise = (nPos == 3) ? 0 : 1;
|
|
m_nQuadrant = nPos + 2;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
// add by zyc 20120419 拾取标注对象并获得标注数据
|
|
int CAxisGridSheet::PickDimensions(CAxisBasePage::EDimType eType, CArray<double, double&>& arData)
|
|
{
|
|
BeginEditorCommand();
|
|
|
|
// 清空初始选择集
|
|
g_ssPickFirst.Free();
|
|
|
|
// 拾取对象
|
|
TPickEntSet set;
|
|
TRBList mask(RTDXF0, _T("ATS_DIMENSION2,DIMENSION"), NULL);
|
|
int iRet = RTNORM;
|
|
|
|
while(1)
|
|
{
|
|
iRet = SelectEntities(_T("\n请选择表示轴网尺寸的标注<返回>:"), set, mask);
|
|
if (RTNORM != iRet)
|
|
{
|
|
CompleteEditorCommand();
|
|
return iRet;
|
|
}
|
|
|
|
// 将选择集保存到链表
|
|
AcDbObjectIdArray arObjId;
|
|
set.AsIdArray(arObjId);
|
|
|
|
std::vector<AcDbObjectId> lstOjbId;
|
|
for (int i=0; i<arObjId.length(); i++)
|
|
{
|
|
lstOjbId.push_back(arObjId[i]);
|
|
}
|
|
|
|
// 过滤
|
|
FilterDimensions(eType, lstOjbId);
|
|
if (0 == lstOjbId.size())
|
|
{
|
|
break;
|
|
}
|
|
|
|
// 检查是否共线
|
|
if (!IsCollinear(eType, lstOjbId))
|
|
{
|
|
set.Free();
|
|
acutPrintf(_T("\n拾取的尺寸标注不共线,请重新选择!"));
|
|
continue;
|
|
}
|
|
|
|
// 排序,并提取数据
|
|
SortDimensions(eType, lstOjbId, arData);
|
|
break;
|
|
}
|
|
set.Free();
|
|
|
|
CompleteEditorCommand();
|
|
return iRet;
|
|
}
|
|
|
|
// add by zyc 20120419 过滤标注对象,第一个参数表示需要保留的标注类型
|
|
BOOL CAxisGridSheet::FilterDimensions(CArcAxisPage::EDimType eType, std::vector<AcDbObjectId>& lstObjId)
|
|
{
|
|
std::vector<AcDbObjectId>::iterator iter;
|
|
std::vector<AcDbObjectId> lstTemp;
|
|
lstTemp.assign(lstObjId.begin(), lstObjId.end());
|
|
lstObjId.clear();
|
|
for (iter = lstTemp.begin(); iter != lstTemp.end(); iter++)
|
|
{
|
|
OPENOBJ_BEGIN(*iter, AcDb::kForRead, AcDbEntity, pDim);
|
|
if (pDim)
|
|
{
|
|
// cad角度标注
|
|
if (pDim->isKindOf(AcDb3PointAngularDimension::desc()) ||
|
|
pDim->isKindOf(AcDb2LineAngularDimension::desc())) // add by zyc 120611 cad角度标注
|
|
{
|
|
if (CArcAxisPage::kRect == eType)
|
|
{
|
|
continue;
|
|
}
|
|
lstObjId.push_back(*iter);
|
|
continue;
|
|
}
|
|
|
|
// cad对齐标注、转角标注
|
|
if (pDim->isKindOf(AcDbAlignedDimension::desc()) ||
|
|
pDim->isKindOf(AcDbRotatedDimension::desc()))
|
|
{
|
|
if (CArcAxisPage::kArc == eType)
|
|
{
|
|
continue;
|
|
}
|
|
lstObjId.push_back(*iter);
|
|
continue;
|
|
}
|
|
|
|
// 上华连续标注
|
|
if (pDim->isKindOf(TDbDimension2::desc()))
|
|
{
|
|
TDbDimension2* pTDim = (TDbDimension2*)pDim;
|
|
if (NULL != pTDim)
|
|
{
|
|
if (pTDim->IsAngular() &&
|
|
!pTDim->IsDimArcLen() &&
|
|
!pTDim->IsDimChord() &&
|
|
CArcAxisPage::kRect==eType)
|
|
{
|
|
continue;
|
|
}
|
|
else if(!pTDim->IsAngular() &&
|
|
CArcAxisPage::kArc==eType)
|
|
{
|
|
continue;
|
|
}
|
|
}
|
|
if (!pTDim->IsDimArcLen() && !pTDim->IsDimChord())
|
|
{
|
|
lstObjId.push_back(*iter);
|
|
}
|
|
continue;
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
// add by zyc 20120419 检查标注对象是否共线
|
|
BOOL CAxisGridSheet::IsCollinear(CArcAxisPage::EDimType eType, std::vector<AcDbObjectId>& vtObjId)
|
|
{
|
|
AcGeLine3d lineBase;
|
|
if (CArcAxisPage::kRect == eType)
|
|
{
|
|
// 对线性标注进行共线检查
|
|
// 获取第一个标注对象尺寸线所在的直线
|
|
OPENOBJ_BEGIN(vtObjId.front(), AcDb::kForRead, AcDbEntity, pDim);
|
|
if (pDim)
|
|
{
|
|
if (pDim->isKindOf(TDbDimension2::desc()))
|
|
{
|
|
TDbDimension2* pTDim = (TDbDimension2*)pDim;
|
|
TGGeCurveSegment seg = pTDim->GetDimCurve();
|
|
TGGeLine line = seg.GetLine();
|
|
lineBase.set((AcGePoint3d)line.StartPoint(), (AcGePoint3d)line.EndPoint());
|
|
}
|
|
else if(pDim->isKindOf(AcDbAlignedDimension::desc()))
|
|
{
|
|
AcDbAlignedDimension* pDimAligned = (AcDbAlignedDimension*)pDim;
|
|
AcGePoint3d pt1 = pDimAligned->xLine1Point();
|
|
AcGePoint3d pt2 = pDimAligned->xLine2Point();
|
|
lineBase = AcGeLine3d(pDimAligned->dimLinePoint(),
|
|
AcGeVector3d(pt1.x-pt2.x, pt1.y-pt2.y, pt1.z-pt2.z));
|
|
}
|
|
else if(pDim->isKindOf(AcDbRotatedDimension::desc()))
|
|
{
|
|
AcDbRotatedDimension* pDimRotate = (AcDbRotatedDimension*)pDim;
|
|
// 获取标注的旋转角
|
|
double dAngle = pDimRotate->rotation();
|
|
if (dAngle >= PI)
|
|
{
|
|
dAngle -= PI;
|
|
}
|
|
// 直线的方向向量
|
|
AcGeVector3d vtDir;
|
|
if (dAngle == PI/2)
|
|
{
|
|
vtDir.set(0, 1, 0);
|
|
}
|
|
else
|
|
{
|
|
vtDir.set(1, tan(dAngle), 0);
|
|
}
|
|
lineBase = AcGeLine3d(pDimRotate->dimLinePoint(), vtDir);
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
// 依次判断之后的标注对象是否在先前的直线上
|
|
std::vector<AcDbObjectId>::iterator iter = vtObjId.begin();
|
|
iter++;
|
|
AcGeLine3d line;
|
|
for (;iter!=vtObjId.end(); iter++)
|
|
{
|
|
OPENOBJ_BEGIN(*iter, AcDb::kForRead, AcDbEntity, pDim);
|
|
if (pDim)
|
|
{
|
|
if (pDim->isKindOf(TDbDimension2::desc()))
|
|
{
|
|
TDbDimension2* pTDim = (TDbDimension2*)pDim;
|
|
// 获取尺寸线所在直线
|
|
TGGeCurveSegment seg = pTDim->GetDimCurve();
|
|
TGGeLine lineTemp = seg.GetLine();
|
|
line.set((AcGePoint3d)lineTemp.StartPoint(), (AcGePoint3d)lineTemp.EndPoint());
|
|
// 获取尺寸线上的点
|
|
XPoly2D poly;
|
|
pTDim->GetPolySegOnDimLine(poly);
|
|
if (Adesk::kTrue != lineBase.isOn((AcGePoint3d)(*poly[0])) ||
|
|
Adesk::kTrue != lineBase.isColinearTo(line))
|
|
{
|
|
return FALSE;
|
|
}
|
|
}
|
|
else if(pDim->isKindOf(AcDbAlignedDimension::desc()))
|
|
{
|
|
AcDbAlignedDimension* pDimAligned = (AcDbAlignedDimension*)pDim;
|
|
// 获取尺寸线所在的直线
|
|
AcGePoint3d pt1 = pDimAligned->xLine1Point();
|
|
AcGePoint3d pt2 = pDimAligned->xLine2Point();
|
|
line = AcGeLine3d(pDimAligned->dimLinePoint(),
|
|
AcGeVector3d(pt1.x-pt2.x, pt1.y-pt2.y, pt1.z-pt2.z));
|
|
if (Adesk::kTrue != lineBase.isOn(pDimAligned->dimLinePoint()) ||
|
|
Adesk::kTrue != lineBase.isColinearTo(line))
|
|
{
|
|
return FALSE;
|
|
}
|
|
}
|
|
else if(pDim->isKindOf(AcDbRotatedDimension::desc()))
|
|
{
|
|
AcDbRotatedDimension* pDimRotate = (AcDbRotatedDimension*)pDim;
|
|
// 获取尺寸线所在的直线
|
|
// 获取标注的旋转角
|
|
double dAngle = pDimRotate->rotation();
|
|
if (dAngle >= PI)
|
|
{
|
|
dAngle -= PI;
|
|
}
|
|
// 直线的方向向量
|
|
AcGeVector3d vtDir;
|
|
if (dAngle == PI/2)
|
|
{
|
|
vtDir.set(0, 1, 0);
|
|
}
|
|
else
|
|
{
|
|
vtDir.set(1, tan(dAngle), 0);
|
|
}
|
|
line = AcGeLine3d(pDimRotate->dimLinePoint(), vtDir);
|
|
|
|
if (Adesk::kTrue != lineBase.isOn(pDimRotate->dimLinePoint()) ||
|
|
Adesk::kTrue != lineBase.isColinearTo(line))
|
|
{
|
|
return FALSE;
|
|
}
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 对角度标注进行共线检查
|
|
// 获取第一个标注对象的圆心和半径
|
|
AcGePoint3d ptCenter;
|
|
double dRadius = 0;
|
|
OPENOBJ_BEGIN(vtObjId.front(), AcDb::kForRead, AcDbEntity, pDim);
|
|
if (pDim)
|
|
{
|
|
if (pDim->isKindOf(TDbDimension2::desc()))
|
|
{
|
|
TDbDimension2* pTDim = (TDbDimension2*)pDim;
|
|
XCurveSegment seg = pTDim->GetDimCurve();
|
|
TGGeArc arc = seg.GetArc();
|
|
ads_point pt;
|
|
arc.Center(pt);
|
|
ptCenter = asPnt3d(pt);
|
|
dRadius = pTDim->GetDimRadius();
|
|
}
|
|
else if(pDim->isKindOf(AcDb3PointAngularDimension::desc()))
|
|
{
|
|
AcDb3PointAngularDimension* pDimAngular = (AcDb3PointAngularDimension*)pDim;
|
|
ptCenter = pDimAngular->centerPoint();
|
|
dRadius = ptCenter.distanceTo(pDimAngular->arcPoint());
|
|
}
|
|
// add by zyc 120611 另一种cad角度标注
|
|
else if (pDim->isKindOf(AcDb2LineAngularDimension::desc()))
|
|
{
|
|
AcDb2LineAngularDimension* pDimAngular = (AcDb2LineAngularDimension*)pDim;
|
|
AcGeLine3d line1(pDimAngular->xLine1Start(), pDimAngular->xLine1End());
|
|
AcGeLine3d line2(pDimAngular->xLine2Start(), pDimAngular->xLine2End());
|
|
if (line1.intersectWith(line2, ptCenter) == Adesk::kTrue)
|
|
{
|
|
dRadius = ptCenter.distanceTo(pDimAngular->arcPoint());
|
|
}
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
|
|
// 依次检查后面的标注对象圆心和半径是否匹配
|
|
std::vector<AcDbObjectId>::iterator iter = vtObjId.begin();
|
|
iter++;
|
|
for (;iter!=vtObjId.end(); iter++)
|
|
{
|
|
OPENOBJ_BEGIN(*iter, AcDb::kForRead, AcDbEntity, pDim);
|
|
if (pDim)
|
|
{
|
|
if (pDim->isKindOf(TDbDimension2::desc()))
|
|
{
|
|
TDbDimension2* pTDim = (TDbDimension2*)pDim;
|
|
XCurveSegment seg = pTDim->GetDimCurve();
|
|
TGGeArc arc = seg.GetArc();
|
|
ads_point pt;
|
|
arc.Center(pt);
|
|
// modify by zyc 120612 浮点与0比较,忘记加fabs取绝对值
|
|
if (ptCenter != asPnt3d(pt) ||
|
|
fabs(dRadius-pTDim->GetDimRadius()) > _DIST_SNAP
|
|
/*dRadius-pTDim->GetDimRadius() > _DIST_SNAP*/)
|
|
{
|
|
return FALSE;
|
|
}
|
|
}
|
|
else if(pDim->isKindOf(AcDb3PointAngularDimension::desc()))
|
|
{
|
|
AcDb3PointAngularDimension* pDimAngular = (AcDb3PointAngularDimension*)pDim;
|
|
AcGePoint3d pt = pDimAngular->centerPoint();
|
|
// modify by zyc 120612 浮点与0比较,忘记加fabs取绝对值
|
|
if (ptCenter != pt ||
|
|
fabs(dRadius - pt.distanceTo(pDimAngular->arcPoint())) > _DIST_SNAP
|
|
/*dRadius - pt.distanceTo(pDimAngular->arcPoint()) > _DIST_SNAP*/)
|
|
{
|
|
return FALSE;
|
|
}
|
|
}
|
|
// add by zyc 120611 另一种cad角度标注
|
|
else if (pDim->isKindOf(AcDb2LineAngularDimension::desc()))
|
|
{
|
|
AcDb2LineAngularDimension* pDimAngular = (AcDb2LineAngularDimension*)pDim;
|
|
AcGeLine3d line1(pDimAngular->xLine1Start(), pDimAngular->xLine1End());
|
|
AcGeLine3d line2(pDimAngular->xLine2Start(), pDimAngular->xLine2End());
|
|
AcGePoint3d pt;
|
|
double d = 0;
|
|
line1.intersectWith(line2, pt);
|
|
AcGePoint3d ptptt = pDimAngular->arcPoint();
|
|
double addf = dRadius - pt.distanceTo(pDimAngular->arcPoint());
|
|
// modify by zyc 120612 浮点与0比较,忘记加fabs取绝对值
|
|
if (ptCenter != pt ||
|
|
fabs(dRadius - pt.distanceTo(pDimAngular->arcPoint())) > _DIST_SNAP
|
|
/*dRadius - pt.distanceTo(pDimAngular->arcPoint()) > _DIST_SNAP*/)
|
|
{
|
|
return FALSE;
|
|
}
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
// add by zyc 20120419 根据标注对象所在的位置进行排序,并提取标注对象的数据
|
|
BOOL CAxisGridSheet::SortDimensions(CArcAxisPage::EDimType eType,
|
|
std::vector<AcDbObjectId>& vtObjId,
|
|
CArray<double, double&>& arData)
|
|
{
|
|
// 排序
|
|
if (vtObjId.size() >= 2)
|
|
{
|
|
if (CArcAxisPage::kRect == eType)
|
|
{
|
|
std::sort(vtObjId.begin(), vtObjId.end(), SortDimRect);
|
|
}
|
|
else
|
|
{
|
|
std::sort(vtObjId.begin(), vtObjId.end(), SortDimArc);
|
|
}
|
|
}
|
|
|
|
// 提取数据
|
|
double dDimData = 0;
|
|
CString sText;
|
|
std::vector<AcDbObjectId>::iterator iter;
|
|
for (iter=vtObjId.begin(); iter!=vtObjId.end(); iter++)
|
|
{
|
|
OPENOBJ_BEGIN(*iter, AcDb::kForRead, AcDbEntity, pDim);
|
|
if (pDim)
|
|
{
|
|
if (pDim->isKindOf(TDbDimension2::desc()))
|
|
{
|
|
TDbDimension2* pTDim = (TDbDimension2*)pDim;
|
|
double dRotation = pTDim->GetRotation();
|
|
bool bInvert = false;
|
|
// 使标注尺寸总是从左往右,从下往上输出
|
|
if (dRotation>PI/2 && dRotation<=PI*3/2)
|
|
{
|
|
bInvert = true;
|
|
}
|
|
TSubText* pText = NULL;
|
|
int index;
|
|
for (int i=0; i<pTDim->GetSegmentNum(); i++)
|
|
{
|
|
if (bInvert)
|
|
{
|
|
index = pTDim->GetSegmentNum() - i - 1;
|
|
}
|
|
else
|
|
{
|
|
index = i;
|
|
}
|
|
pText = pTDim->GetSubText(index);
|
|
sText = pText->GetText();
|
|
dDimData = _tstof((LPCTSTR)sText);
|
|
arData.Add(dDimData);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AcDbDimension* pDimCad = (AcDbDimension*)pDim;
|
|
sText = pDimCad->dimensionText();
|
|
if (sText.IsEmpty())
|
|
{
|
|
pDimCad->measurement(dDimData);
|
|
if (CArcAxisPage::kArc == eType)
|
|
{
|
|
dDimData = dDimData * 180.0f / PI;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dDimData = _tstof((LPCTSTR)sText);
|
|
}
|
|
arData.Add(dDimData);
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
// add by zyc 20120420 排序函数
|
|
bool CAxisGridSheet::SortDimArc(const AcDbObjectId& element1,
|
|
const AcDbObjectId& element2)
|
|
{
|
|
// 获取角度
|
|
double dEleAngle1,dEleAngle2;
|
|
double* pdAngle;
|
|
const AcDbObjectId* pElement;
|
|
for (int i=0; i<2; i++)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
pdAngle = &dEleAngle1;
|
|
pElement = &element1;
|
|
}
|
|
else
|
|
{
|
|
pdAngle = &dEleAngle2;
|
|
pElement = &element2;
|
|
}
|
|
|
|
OPENOBJ_BEGIN(*pElement, AcDb::kForRead, AcDbEntity, pDim);
|
|
if (!pDim)
|
|
{
|
|
return true;
|
|
}
|
|
if (pDim->isKindOf(TDbDimension2::desc()))
|
|
{
|
|
*pdAngle = ((TDbDimension2*)pDim)->GetRotation();
|
|
}
|
|
else if (pDim->isKindOf(AcDb3PointAngularDimension::desc()))
|
|
{
|
|
AcGePoint3d ptArc = ((AcDb3PointAngularDimension*)pDim)->arcPoint();
|
|
AcGePoint3d ptCenter = ((AcDb3PointAngularDimension*)pDim)->centerPoint();
|
|
AcGeVector2d vtRadius(ptArc.x-ptCenter.x,
|
|
ptArc.y-ptCenter.y);
|
|
*pdAngle = vtRadius.angle();
|
|
}
|
|
// add by zyc 120611 另一种cad角度标注
|
|
else if (pDim->isKindOf(AcDb2LineAngularDimension::desc()))
|
|
{
|
|
AcDb2LineAngularDimension* pDimAngular = (AcDb2LineAngularDimension*)pDim;
|
|
AcGePoint3d ptArc = pDimAngular->arcPoint();
|
|
AcGePoint3d ptCenter;
|
|
AcGeLine3d line1(pDimAngular->xLine1Start(), pDimAngular->xLine1End());
|
|
AcGeLine3d line2(pDimAngular->xLine2Start(), pDimAngular->xLine2End());
|
|
line1.intersectWith(line2, ptCenter);
|
|
AcGeVector2d vtRadius(ptArc.x-ptCenter.x,
|
|
ptArc.y-ptCenter.y);
|
|
*pdAngle = vtRadius.angle();
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
// 比较
|
|
if (dEleAngle1 > dEleAngle2)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// add by zyc 20120420 排序函数
|
|
bool CAxisGridSheet::SortDimRect(const AcDbObjectId& element1,
|
|
const AcDbObjectId& element2)
|
|
{
|
|
// 获取尺寸线上的点
|
|
AcGePoint3d ptElement1, ptElement2;
|
|
AcGePoint3d* ptElement;
|
|
const AcDbObjectId* pElement;
|
|
for (int i=0; i<2; i++)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
ptElement = &ptElement1;
|
|
pElement = &element1;
|
|
}
|
|
else
|
|
{
|
|
ptElement = &ptElement2;
|
|
pElement = &element2;
|
|
}
|
|
OPENOBJ_BEGIN(*pElement, AcDb::kForRead, AcDbEntity, pDim);
|
|
if (!pDim)
|
|
{
|
|
return true;
|
|
}
|
|
if (pDim->isKindOf(TDbDimension2::desc()))
|
|
{
|
|
TDbDimension2* pTDim = (TDbDimension2*)pDim;
|
|
*ptElement = (AcGePoint3d)pTDim->GetLocation();
|
|
}
|
|
else if(pDim->isKindOf(AcDbAlignedDimension::desc()))
|
|
{
|
|
AcDbAlignedDimension* pDimAligned = (AcDbAlignedDimension*)pDim;
|
|
*ptElement = pDimAligned->dimLinePoint();
|
|
}
|
|
else if(pDim->isKindOf(AcDbRotatedDimension::desc()))
|
|
{
|
|
AcDbRotatedDimension* pDimRotate = (AcDbRotatedDimension*)pDim;
|
|
*ptElement = pDimRotate->dimLinePoint();
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
// 比较
|
|
if (ptElement1.x < ptElement2.x)
|
|
{
|
|
return true;
|
|
}
|
|
else if (ptElement1.x > ptElement2.x)
|
|
{
|
|
return false;
|
|
}
|
|
else if (ptElement1.y < ptElement2.y)
|
|
{
|
|
return true;
|
|
}
|
|
else if (ptElement1.y > ptElement2.y)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|