963 lines
19 KiB
C++
963 lines
19 KiB
C++
#include "stdafx.h"
|
|
#include "StdArx.h"
|
|
#include "KTLineAxisGridDlg.h"
|
|
#include "KTLineAxisCreator.h"
|
|
#include "KTSetting.h"
|
|
#include "CoreTools.h"
|
|
#include "KTCADSysVar.h"
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
extern HINSTANCE _hdllInstance;
|
|
|
|
#define WM_ITEMEDITED WM_USER + 0X1004
|
|
|
|
static LPCTSTR 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"),NULL};
|
|
|
|
KTLineAxisGridDlg::KTLineAxisGridDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(KTLineAxisGridDlg::IDD, pParent)
|
|
, m_dEl(0)
|
|
{
|
|
m_nIndex = 0;
|
|
m_dOffset = 0.0;
|
|
m_dAngle = 90.0;
|
|
m_dVDis = 0.0;
|
|
m_dHDis = 0.0;
|
|
|
|
GET_CACHE(KTLineAxisGridDlg
|
|
, %d%f%f%f%f%f
|
|
, &m_nIndex
|
|
, &m_dOffset
|
|
, &m_dAngle
|
|
, &m_dVDis
|
|
, &m_dHDis
|
|
, &m_dEl);
|
|
|
|
//m_dEl 从变量elevation获取 -- 速建三维轴网
|
|
struct resbuf rb;
|
|
acedGetVar(_T("elevation"), &rb);
|
|
m_dEl = rb.resval.rreal;
|
|
|
|
m_idCrossPt.setNull();
|
|
ShowProBasePoint(TRUE);
|
|
}
|
|
|
|
KTLineAxisGridDlg::~KTLineAxisGridDlg()
|
|
{
|
|
ShowProBasePoint(FALSE);
|
|
}
|
|
|
|
void KTLineAxisGridDlg::ShowProBasePoint(BOOL bShow)
|
|
{
|
|
//模型空间的字典中放置
|
|
AcDbDatabase *pDb = acdbCurDwg();
|
|
if (pDb == NULL) return;
|
|
|
|
AcGePoint3d ptBase;
|
|
bool bHasProBasePt = false;
|
|
|
|
AcDbObjectId idSpace = pDb->currentSpaceId();
|
|
AcDbObject *pObj = NULL;
|
|
if (Acad::eOk == acdbOpenObject(pObj, idSpace, AcDb::kForRead))
|
|
{
|
|
AcDbObjectId idDic = pObj->extensionDictionary();
|
|
|
|
AcDbDictionary *pDic = NULL;
|
|
Acad::ErrorStatus es = acdbOpenObject(pDic, idDic, AcDb::kForRead);
|
|
if (es == Acad::eOk)
|
|
{
|
|
//AcDbXFloorFrame handle
|
|
//PRO_NAME - FloorEx Handle - FloorEx Handle- FloorEx Handle- FloorEx Handle...
|
|
AcDbObject *pSubObj = NULL;
|
|
es = pDic->getAt(KEY_NAME, pSubObj, AcDb::kForRead);
|
|
if (es == Acad::eOk)
|
|
{
|
|
AecFloorViewDataRecord *pRec = AecFloorViewDataRecord::cast(pSubObj);
|
|
if (pRec != NULL)
|
|
{
|
|
pRec->GetBasePoint(ptBase);
|
|
bHasProBasePt = true;
|
|
}
|
|
pSubObj->close();
|
|
}
|
|
pDic->close();
|
|
}
|
|
pObj->close();
|
|
}
|
|
|
|
if (bHasProBasePt)
|
|
{
|
|
//绘制+字
|
|
if (bShow)
|
|
{
|
|
//点的样式
|
|
KTCADSysVar<int> var1(_T("pdmode"), 3);
|
|
KTCADSysVar<int> var2(_T("pdsize"), 8);
|
|
AcDbPoint *pPt = new AcDbPoint;
|
|
pPt->setPosition(ptBase);
|
|
m_idCrossPt = CoreTools::AddToModelSpace(pPt);
|
|
}
|
|
else
|
|
{
|
|
AcDbEntity *pEnt = NULL;
|
|
if (Acad::eOk == acdbOpenAcDbEntity(pEnt, m_idCrossPt, AcDb::kForWrite))
|
|
{
|
|
pEnt->erase();
|
|
pEnt->close();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void KTLineAxisGridDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_STATIC_FRAME, m_wndPreview);
|
|
DDX_Control(pDX, IDC_SPIN_ANGLE, m_wndSpinAngle);
|
|
DDX_Control(pDX, IDC_EDITGRID, m_wndAxisGridEdit);
|
|
DDX_Control(pDX, IDC_LISTGRID, m_wndAxisGridListCtrl);
|
|
DDX_Control(pDX, IDC_LISTDIST, m_wndDistListBox);
|
|
|
|
DDX_Radio(pDX, IDC_RADIOUP, m_nIndex);
|
|
DDX_Text(pDX, IDC_EDITOFFSET, m_dOffset);
|
|
DDX_Text(pDX, IDC_EDITANG, m_dAngle);
|
|
DDX_Text(pDX, IDC_EDIT_VDIS, m_dVDis);
|
|
DDX_Text(pDX, IDC_EDIT_HDIS, m_dHDis);
|
|
DDX_Text(pDX, IDC_EDIT1, m_dEl);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(KTLineAxisGridDlg, CDialog)
|
|
//{{AFX_MSG_MAP(KTLineAxisGridDlg)
|
|
ON_BN_CLICKED(IDC_BTEMPTY, OnBtempty)
|
|
ON_BN_CLICKED(IDC_BUTTON_COMEBACK, OnButtonComeback)
|
|
ON_BN_CLICKED(IDC_BTOFFSETLOW, OnBtoffsetlow)
|
|
ON_BN_CLICKED(IDC_BTOFFSETHIG, OnBtoffsethig)
|
|
ON_BN_CLICKED(IDC_RADIOUP, OnRadioup)
|
|
ON_BN_CLICKED(IDC_RADIODOWN, OnRadiodown)
|
|
ON_BN_CLICKED(IDC_RADIOLEFT, OnRadioleft)
|
|
ON_BN_CLICKED(IDC_RADIORIGHT, OnRadioright)
|
|
ON_LBN_SELCHANGE(IDC_LISTDIST, OnSelchangeListdist)
|
|
ON_CONTROL(WM_EDIT_MESSAGE, IDC_EDITGRID,OnMessageEditInput)
|
|
ON_WM_DESTROY()
|
|
ON_EN_CHANGE(IDC_EDITANG, OnChangeEditang)
|
|
ON_BN_CLICKED(IDC_BUTTON1, &KTLineAxisGridDlg::OnBnClickedButton1)
|
|
ON_MESSAGE(WM_ITEMEDITED, &KTLineAxisGridDlg::OnItemEdited)
|
|
END_MESSAGE_MAP()
|
|
|
|
BOOL KTLineAxisGridDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
m_wndSpinAngle.SetBuddy(GetDlgItem(IDC_EDITANG));
|
|
m_wndSpinAngle.SetRange(1, 179);
|
|
|
|
m_ImageList.Create(IDB_ITEMHEIGHTBMP,1,16,ILC_COLOR16);
|
|
m_wndAxisGridListCtrl.SetImageList(&m_ImageList,LVSIL_SMALL);
|
|
m_wndPreview.Init(_hdllInstance,1,1,1);
|
|
|
|
int i = 0;
|
|
while(TRUE)
|
|
{
|
|
if (SZ_SIZES[i] == NULL) break;
|
|
m_wndDistListBox.AddString(SZ_SIZES[i]);
|
|
i += 1;
|
|
}
|
|
|
|
CString sTitle;
|
|
m_wndAxisGridListCtrl.m_nInitFlag = 0;
|
|
sTitle.LoadString(IDS_AXISDIST);
|
|
m_wndAxisGridListCtrl.InsertColumn(0,sTitle,LVCFMT_LEFT,60,60);
|
|
sTitle.LoadString(IDS_NUMBER);
|
|
m_wndAxisGridListCtrl.InsertColumn(1,sTitle,LVCFMT_LEFT,58,60);
|
|
|
|
m_wndAxisGridListCtrl.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
|
|
m_wndAxisGridListCtrl.InsertItem(0,_T(""));
|
|
|
|
UpdateData(FALSE);
|
|
|
|
if (m_idCrossPt.isValid())
|
|
{
|
|
OnButtonComeback();
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
LRESULT KTLineAxisGridDlg::OnItemEdited(WPARAM wparam,LPARAM lparam)
|
|
{
|
|
UpdateSpaceList();
|
|
UpdateSpaceEdit();
|
|
RedrawAxisGrids();
|
|
RefreshTotalDis();
|
|
EnableCtrls();
|
|
return 0;
|
|
}
|
|
|
|
void KTLineAxisGridDlg::OnOK()
|
|
{
|
|
UpdateData(TRUE);
|
|
|
|
UpdateSpaceList();
|
|
InsertOffset();
|
|
ShowListToAxisGrid();
|
|
SaveToTxt();
|
|
|
|
SET_CACHE(KTLineAxisGridDlg
|
|
, %d%f%f%f%f%f
|
|
, m_nIndex
|
|
, m_dOffset
|
|
, m_dAngle
|
|
, m_dVDis
|
|
, m_dHDis
|
|
, m_dEl);
|
|
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
void KTLineAxisGridDlg::OnBtempty()
|
|
{
|
|
m_arSpaceText[m_nIndex].RemoveAll();
|
|
ShowListToAxisGrid();
|
|
UpdateSpaceEdit();
|
|
RedrawAxisGrids();
|
|
RefreshTotalDis();
|
|
EnableCtrls();
|
|
}
|
|
|
|
void KTLineAxisGridDlg::OnButtonComeback()
|
|
{
|
|
ReadFromTxt();
|
|
UpdateData(FALSE);
|
|
ShowListToAxisGrid();
|
|
UpdateSpaceEdit();
|
|
RedrawAxisGrids();
|
|
RefreshTotalDis();
|
|
EnableCtrls();
|
|
}
|
|
|
|
void KTLineAxisGridDlg::OnBtoffsetlow()
|
|
{
|
|
GetDlgItem(IDC_BTOFFSETHIG)->EnableWindow(TRUE);
|
|
int nRelIndex = GetRelatingIndex();
|
|
double dVal = 0.0;
|
|
CArray<double,double> arDists;
|
|
GetSpaceVals(nRelIndex, arDists);
|
|
int nSize = arDists.GetSize();
|
|
|
|
for(int i = nSize; i > -1; i--)
|
|
{
|
|
if (i == 0)
|
|
{
|
|
GetDlgItem(IDC_BTOFFSETLOW)->EnableWindow(FALSE);
|
|
}
|
|
dVal = GetTotalVal(i, arDists);
|
|
if (m_dOffset - dVal > 1.e-10)
|
|
{
|
|
m_dOffset = dVal;
|
|
break;
|
|
}
|
|
}
|
|
if (m_nIndex == 0 || m_nIndex == 1)
|
|
{
|
|
m_dHDis = m_dOffset + GetTotalDis();
|
|
}
|
|
else
|
|
{
|
|
m_dVDis = m_dOffset + GetTotalDis();
|
|
}
|
|
RedrawAxisGrids();
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
void KTLineAxisGridDlg::OnBtoffsethig()
|
|
{
|
|
GetDlgItem(IDC_BTOFFSETLOW)->EnableWindow(TRUE);
|
|
int nRelIndex = GetRelatingIndex();
|
|
double dVal = 0.0;
|
|
CArray<double, double> arDists;
|
|
GetSpaceVals(nRelIndex, arDists);
|
|
int nSize = arDists.GetSize();
|
|
|
|
for(int i = 0; i <= nSize; i++)
|
|
{
|
|
if (i == nSize)
|
|
{
|
|
GetDlgItem(IDC_BTOFFSETHIG)->EnableWindow(FALSE);
|
|
}
|
|
dVal = GetTotalVal(i, arDists);
|
|
if (dVal - m_dOffset > 1.e-10)
|
|
{
|
|
m_dOffset = dVal;
|
|
break;
|
|
}
|
|
}
|
|
if (m_nIndex == 0 || m_nIndex == 1)
|
|
{
|
|
m_dHDis = m_dOffset + GetTotalDis();
|
|
}
|
|
else
|
|
{
|
|
m_dVDis = m_dOffset + GetTotalDis();
|
|
}
|
|
RedrawAxisGrids();
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
void KTLineAxisGridDlg::EnableCtrls()
|
|
{
|
|
int nCurIndex = m_nIndex;
|
|
int nRelIndex = GetRelatingIndex();
|
|
|
|
if (m_arSpaceText[nCurIndex].GetSize() > 0 && m_arSpaceText[nRelIndex].GetSize() > 0)
|
|
{
|
|
GetDlgItem(IDC_EDITOFFSET)->EnableWindow(TRUE);
|
|
GetDlgItem(IDC_BTOFFSETHIG)->EnableWindow(TRUE);
|
|
GetDlgItem(IDC_BTOFFSETLOW)->EnableWindow(FALSE);
|
|
}
|
|
else
|
|
{
|
|
GetDlgItem(IDC_EDITOFFSET)->EnableWindow(FALSE);
|
|
GetDlgItem(IDC_BTOFFSETHIG)->EnableWindow(FALSE);
|
|
GetDlgItem(IDC_BTOFFSETLOW)->EnableWindow(FALSE);
|
|
}
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
void KTLineAxisGridDlg::OnRadioup()
|
|
{
|
|
m_nLastIndex = m_nIndex;
|
|
UpdateSpaceList();
|
|
this->UpdateData(TRUE);
|
|
if (m_nLastIndex != m_nIndex)
|
|
{
|
|
m_dOffset = 0.0;
|
|
}
|
|
if (m_nIndex == 0)
|
|
{
|
|
ShowListToAxisGrid();
|
|
UpdateSpaceEdit();
|
|
RefreshAngle();
|
|
RefreshTotalDis();
|
|
EnableCtrls();
|
|
}
|
|
}
|
|
|
|
void KTLineAxisGridDlg::OnRadiodown()
|
|
{
|
|
m_nLastIndex = m_nIndex;
|
|
UpdateSpaceList();
|
|
this->UpdateData(TRUE);
|
|
if (m_nLastIndex != m_nIndex)
|
|
{
|
|
m_dOffset = 0.0;
|
|
}
|
|
if (m_nIndex == 1)
|
|
{
|
|
ShowListToAxisGrid();
|
|
UpdateSpaceEdit();
|
|
RefreshAngle();
|
|
RefreshTotalDis();
|
|
EnableCtrls();
|
|
}
|
|
}
|
|
|
|
void KTLineAxisGridDlg::OnRadioleft()
|
|
{
|
|
m_nLastIndex = m_nIndex;
|
|
UpdateSpaceList();
|
|
this->UpdateData(TRUE);
|
|
if (m_nLastIndex != m_nIndex)
|
|
{
|
|
m_dOffset = 0.0;
|
|
}
|
|
if (m_nIndex == 2)
|
|
{
|
|
ShowListToAxisGrid();
|
|
UpdateSpaceEdit();
|
|
RefreshAngle();
|
|
RefreshTotalDis();
|
|
EnableCtrls();
|
|
}
|
|
}
|
|
|
|
void KTLineAxisGridDlg::OnRadioright()
|
|
{
|
|
m_nLastIndex = m_nIndex;
|
|
UpdateSpaceList();
|
|
this->UpdateData(TRUE);
|
|
if (m_nLastIndex != m_nIndex)
|
|
{
|
|
m_dOffset = 0.0;
|
|
}
|
|
if (m_nIndex == 3)
|
|
{
|
|
ShowListToAxisGrid();
|
|
UpdateSpaceEdit();
|
|
RefreshAngle();
|
|
RefreshTotalDis();
|
|
EnableCtrls();
|
|
}
|
|
}
|
|
|
|
void KTLineAxisGridDlg::OnSelchangeListdist()
|
|
{
|
|
int nCount = m_wndAxisGridListCtrl.GetItemCount() - 1;
|
|
int nSel = m_wndDistListBox.GetCurSel();
|
|
|
|
if (nSel != -1)
|
|
{
|
|
if (m_nIndex > -1 && m_nIndex < 4)
|
|
{
|
|
CString sText;
|
|
m_wndDistListBox.GetText(nSel,sText);
|
|
int nItem = m_wndAxisGridListCtrl.InsertItem(nCount,sText);
|
|
m_wndAxisGridListCtrl.SetItemText(nItem,1,_T("1"));
|
|
|
|
UpdateSpaceList();
|
|
UpdateSpaceEdit();
|
|
RedrawAxisGrids();
|
|
}
|
|
}
|
|
RefreshTotalDis();
|
|
EnableCtrls();
|
|
}
|
|
|
|
void KTLineAxisGridDlg::UpdateSpaceList()
|
|
{
|
|
if (m_nIndex > -1 && m_nIndex < 4)
|
|
{
|
|
CString sDist,sSize,sTemp;
|
|
int nCount = m_wndAxisGridListCtrl.GetItemCount() - 1;
|
|
|
|
m_arSpaceText[m_nIndex].RemoveAll();
|
|
|
|
for(int i = 0;i < nCount;i++)
|
|
{
|
|
sDist = m_wndAxisGridListCtrl.GetItemText(i,0);
|
|
sSize = m_wndAxisGridListCtrl.GetItemText(i,1);
|
|
|
|
if (_ttoi(sDist) == 0 ||
|
|
_ttoi(sSize) == 0)
|
|
continue;
|
|
|
|
int nSize = _ttoi(sSize);
|
|
if (nSize > 1)
|
|
{
|
|
sTemp.Format(_T("%s*%s"),sDist,sSize);
|
|
}
|
|
else
|
|
{
|
|
sTemp = sDist;
|
|
}
|
|
m_arSpaceText[m_nIndex].Add(sTemp);
|
|
}
|
|
}
|
|
}
|
|
|
|
void KTLineAxisGridDlg::RedrawAxisGrids()
|
|
{
|
|
KTLineAxisCreator creator;
|
|
int nRelIndex = GetRelatingIndex();
|
|
|
|
creator.SetStartAngle(m_dAngle);
|
|
creator.InsertOffset(m_nIndex, m_dOffset);
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
creator.SetArrayData(i, m_arSpaceText[i]);
|
|
}
|
|
creator.Create(TRUE);
|
|
|
|
m_wndPreview.Clear(0);
|
|
FreeBuffer();
|
|
creator.GetAxisEntities(m_arEntPtrsForRedraw);
|
|
|
|
AcDbExtents ext,ext1;
|
|
AcDbEntity *pEnt = NULL;
|
|
for (i = 0; i < m_arEntPtrsForRedraw.length(); i++)
|
|
{
|
|
pEnt = (AcDbEntity*)m_arEntPtrsForRedraw.at(i);
|
|
if (pEnt != NULL)
|
|
{
|
|
pEnt->getGeomExtents(ext1);
|
|
if (i == 0)
|
|
{
|
|
ext = ext1;
|
|
}
|
|
else
|
|
{
|
|
ext.addExt(ext1);
|
|
}
|
|
|
|
if (i < creator.m_arDirNum[0])
|
|
{
|
|
pEnt->setColorIndex(1);
|
|
}
|
|
else if (i < creator.m_arDirNum[1])
|
|
{
|
|
// 只有下开
|
|
if (creator.m_arDirNum[0] == 2)
|
|
pEnt->setColorIndex(1);
|
|
else
|
|
pEnt->setColorIndex(2);
|
|
}
|
|
else if (i < creator.m_arDirNum[2])
|
|
{
|
|
pEnt->setColorIndex(3);
|
|
}
|
|
else if (i < creator.m_arDirNum[3])
|
|
{
|
|
// 只有右进
|
|
if (creator.m_arDirNum[2] == creator.m_arDirNum[1] + 2)
|
|
pEnt->setColorIndex(3);
|
|
else
|
|
pEnt->setColorIndex(4);
|
|
}
|
|
m_wndPreview.Add(pEnt,0);
|
|
}
|
|
}
|
|
m_wndPreview.Redraw(&ext,0);
|
|
}
|
|
|
|
void KTLineAxisGridDlg::UpdateSpaceEdit()
|
|
{
|
|
if (m_nIndex > -1 && m_nIndex < 4)
|
|
{
|
|
m_wndAxisGridEdit.SetWindowText(_T(""));
|
|
|
|
CString sSpaceText = _T(""),sText;
|
|
int nSize = m_arSpaceText[m_nIndex].GetSize();
|
|
for(int i = 0;i < nSize;i++)
|
|
{
|
|
sText = m_arSpaceText[m_nIndex].GetAt(i);
|
|
sSpaceText += (sText + _T(" "));
|
|
}
|
|
m_wndAxisGridEdit.SetWindowText(sSpaceText);
|
|
}
|
|
}
|
|
|
|
void KTLineAxisGridDlg::OnMessageEditInput()
|
|
{
|
|
int nStart, nEnd;
|
|
m_wndAxisGridEdit.GetSel(nStart, nEnd);
|
|
CString strData, strLeft, strRight;
|
|
m_wndAxisGridEdit.GetWindowText(strData);
|
|
if (strData.Mid(nEnd - 1, 1).CompareNoCase(_T("*")) == 0 &&
|
|
nEnd == strData.GetLength())
|
|
{
|
|
return;
|
|
}
|
|
if (strData.Mid(nEnd, 1).CompareNoCase(_T("")) == 0 &&
|
|
strData.Mid(nEnd - 1, 1).CompareNoCase(_T("")) != 0 &&
|
|
strData.Mid(nEnd - 1, 1).CompareNoCase(_T(" ")) != 0)
|
|
{
|
|
strLeft = strData.Left(nEnd);
|
|
strRight = strData.Mid(nEnd);
|
|
strData.Format(_T("%s %s"), strLeft, strRight);
|
|
}
|
|
CString sText;
|
|
sText.LoadString(IDS_INPUT_CORRECT_TIP);
|
|
if (!CorrectString(strData))
|
|
{
|
|
acutPrintf(sText);
|
|
}
|
|
PushToArray(m_nIndex, strData);
|
|
|
|
UpdateSpaceEdit();
|
|
ShowListToAxisGrid();
|
|
UpdateSpaceList();
|
|
RedrawAxisGrids();
|
|
RefreshTotalDis();
|
|
EnableCtrls();
|
|
}
|
|
|
|
void KTLineAxisGridDlg::ShowListToAxisGrid()
|
|
{
|
|
if (m_nIndex > -1 && m_nIndex < 4)
|
|
{
|
|
m_wndAxisGridListCtrl.DeleteAllItems();
|
|
m_wndAxisGridListCtrl.InsertItem(0, _T(""));
|
|
CString sText,sItem,sSize;
|
|
|
|
int nSize = m_arSpaceText[m_nIndex].GetSize();
|
|
for(int i = 0;i < nSize;i++)
|
|
{
|
|
sText = m_arSpaceText[m_nIndex].GetAt(i);
|
|
|
|
int nCount = m_wndAxisGridListCtrl.GetItemCount() - 1;
|
|
int nFind = -1;
|
|
|
|
if ((nFind = sText.Find(_T('*'),0)) > -1)
|
|
{
|
|
sItem = sText.Left(nFind);
|
|
sSize = sText.Mid(nFind + 1);
|
|
|
|
int nItem = m_wndAxisGridListCtrl.InsertItem(nCount,sItem);
|
|
m_wndAxisGridListCtrl.SetItemText(nItem,1,sSize);
|
|
}
|
|
else
|
|
{
|
|
int nItem = m_wndAxisGridListCtrl.InsertItem(nCount,sText);
|
|
m_wndAxisGridListCtrl.SetItemText(nItem,1,_T("1"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void KTLineAxisGridDlg::SaveToTxt()
|
|
{
|
|
UpdateSpaceList();
|
|
UpdateSpaceEdit();
|
|
|
|
int nSizeA = 0;
|
|
for (int ii = 0; ii < 4; ii++)
|
|
{
|
|
nSizeA += m_arSpaceText[ii].GetSize();
|
|
}
|
|
if (nSizeA == 0)
|
|
return;
|
|
|
|
CString sFileName = _T("LAxis.dat");
|
|
CString sPath;
|
|
KTSetting::GetKTPsPath(sPath);
|
|
sPath += sFileName;
|
|
sFileName = sPath;
|
|
|
|
CStdioFile file;
|
|
CString sTip;
|
|
sTip.LoadString(IDS_OPEN_FILE_ERR);
|
|
if( !file.Open( sFileName, CFile::modeCreate | CFile::modeWrite | CFile::typeText ) )
|
|
{
|
|
return;
|
|
}
|
|
|
|
CString strSrc;
|
|
strSrc.Format(_T("%.1f\n"), m_dAngle);
|
|
file.WriteString(strSrc);
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
int j = 0;
|
|
int size = m_arSpaceText[i].GetSize();
|
|
if (size > 0)
|
|
{
|
|
while (j < (size - 1))
|
|
{
|
|
strSrc.Format(_T("%s "), m_arSpaceText[i].GetAt(j));
|
|
file.WriteString(strSrc);
|
|
j++;
|
|
}
|
|
strSrc.Format(_T("%s\n"), m_arSpaceText[i].GetAt(size - 1));
|
|
file.WriteString(strSrc);
|
|
}
|
|
else
|
|
{
|
|
strSrc.Format(_T("%s\n"), _T("NULL"));
|
|
file.WriteString(strSrc);
|
|
}
|
|
}
|
|
|
|
file.Close();
|
|
return;
|
|
}
|
|
|
|
void KTLineAxisGridDlg::ReadFromTxt()
|
|
{
|
|
CString sFileName = _T("LAxis.dat");
|
|
CString sPath;
|
|
|
|
KTSetting::GetKTPsPath(sPath);
|
|
sPath += sFileName;
|
|
sFileName = sPath;
|
|
|
|
CStdioFile file;
|
|
CString sTip;
|
|
sTip.LoadString(IDS_OPEN_FILE_ERR);
|
|
if( !file.Open( sFileName, CFile::modeRead | CFile::typeText ) )
|
|
{
|
|
return;
|
|
}
|
|
|
|
int nFind = -1;
|
|
CString strSrc, strData;
|
|
file.ReadString(strSrc);
|
|
m_dAngle = _ttof(strSrc);
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
m_arSpaceText[i].RemoveAll();
|
|
if (file.ReadString(strSrc) != FALSE)
|
|
{
|
|
PushToArray(i, strSrc);
|
|
}
|
|
}
|
|
|
|
file.Close();
|
|
return;
|
|
}
|
|
|
|
BOOL KTLineAxisGridDlg::CorrectString(CString &strSrc)
|
|
{
|
|
int nFind = -1;
|
|
CString strData = "";
|
|
CString strTemp = strSrc;
|
|
BOOL bRet = TRUE;
|
|
while (strSrc.GetLength() > 0)
|
|
{
|
|
if ((nFind = strSrc.Find(_T(' '), 0)) > -1)
|
|
{
|
|
strTemp = strSrc.Left(nFind);
|
|
strSrc = strSrc.Mid(nFind + 1);
|
|
}
|
|
else
|
|
{
|
|
strTemp = strSrc;
|
|
}
|
|
if (IsAccordant(strTemp))
|
|
{
|
|
strData += strTemp + _T(" ");
|
|
}
|
|
else
|
|
{
|
|
bRet = FALSE;
|
|
}
|
|
}
|
|
strSrc = strData;
|
|
return bRet;
|
|
}
|
|
|
|
BOOL KTLineAxisGridDlg::IsAccordant(CString strSrc)
|
|
{
|
|
CString strCompare = _T("1234567890*");
|
|
CString strChar;
|
|
|
|
for (int i = 0; i < strSrc.GetLength(); i++)
|
|
{
|
|
BOOL bRet = FALSE;
|
|
for (int j = 0; j < strCompare.GetLength(); j++)
|
|
{
|
|
strChar = strSrc.GetAt(i);
|
|
if (strChar.CompareNoCase(strCompare.Mid(j, 1)) == 0)
|
|
{
|
|
bRet = TRUE;
|
|
break;
|
|
}
|
|
}
|
|
if (!bRet) return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void KTLineAxisGridDlg::PushToArray(int nIndex, CString strSrc)
|
|
{
|
|
if (strSrc.CompareNoCase(_T("NULL")) == 0)
|
|
{
|
|
return;
|
|
}
|
|
int nFind = -1;
|
|
CString strData = "";
|
|
CString strTemp = strSrc;
|
|
m_arSpaceText[nIndex].RemoveAll();
|
|
|
|
while (strTemp.GetLength() > 0)
|
|
{
|
|
if ((nFind = strTemp.Find(_T(' '), 0)) > -1)
|
|
{
|
|
strData = strTemp.Left(nFind);
|
|
m_arSpaceText[nIndex].Add(strData);
|
|
strTemp = strTemp.Mid(nFind + 1);
|
|
}
|
|
else
|
|
{
|
|
m_arSpaceText[nIndex].Add(strTemp);
|
|
strTemp.Empty();
|
|
}
|
|
}
|
|
}
|
|
|
|
void KTLineAxisGridDlg::RefreshAngle()
|
|
{
|
|
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;
|
|
}
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
void KTLineAxisGridDlg::RefreshTotalDis()
|
|
{
|
|
UpdateData(TRUE);
|
|
m_dHDis = 0.0;
|
|
m_dVDis = 0.0;
|
|
if (m_nIndex == 0 || m_nIndex == 1)
|
|
{
|
|
m_dHDis = GetTotalDis();
|
|
}
|
|
else
|
|
{
|
|
m_dVDis = GetTotalDis();
|
|
}
|
|
UpdateData(FALSE);
|
|
}
|
|
|
|
double KTLineAxisGridDlg::GetTotalDis()
|
|
{
|
|
int num = 0;
|
|
double dCurDis = 0.0;
|
|
double dTotalDis = 0.0;
|
|
CString strSrc, strDis, strNum;
|
|
int nSize = m_arSpaceText[m_nIndex].GetSize();
|
|
for(int i = 0;i < nSize;i++)
|
|
{
|
|
strSrc = m_arSpaceText[m_nIndex].GetAt(i);
|
|
int nFind = -1;
|
|
|
|
if ((nFind = strSrc.Find(_T('*'),0)) > -1)
|
|
{
|
|
strNum = strSrc.Left(nFind);
|
|
strDis = strSrc.Mid(nFind + 1);
|
|
num = _ttoi(strNum);
|
|
dCurDis = _ttof(strDis);
|
|
}
|
|
else
|
|
{
|
|
num = 1;
|
|
dCurDis = _ttof(strSrc);
|
|
}
|
|
dTotalDis += dCurDis * num;
|
|
}
|
|
|
|
return dTotalDis;
|
|
}
|
|
|
|
void KTLineAxisGridDlg::InsertOffset()
|
|
{
|
|
UpdateData(TRUE);
|
|
if (m_dOffset < 0.00001 && m_dOffset > -0.00001)
|
|
return;
|
|
CString strBuff;
|
|
CStringArray arBuff;
|
|
int nRelIndex = GetRelatingIndex();
|
|
|
|
arBuff.Append(m_arSpaceText[m_nIndex]);
|
|
m_arSpaceText[m_nIndex].RemoveAll();
|
|
strBuff.Format(_T("%.f"), m_dOffset);
|
|
m_arSpaceText[m_nIndex].Add(strBuff);
|
|
m_arSpaceText[m_nIndex].Append(arBuff);
|
|
}
|
|
|
|
void KTLineAxisGridDlg::GetSpaceVals(int nIndex, CArray<double,double>& arDists)
|
|
{
|
|
arDists.RemoveAll();
|
|
for (int i = 0; i < m_arSpaceText[nIndex].GetSize(); i++)
|
|
{
|
|
int nSize = 1;
|
|
int nFind = -1;
|
|
double dDist = 0.0;
|
|
CString strSize;
|
|
CString strData;
|
|
if ((nFind = m_arSpaceText[nIndex].GetAt(i).Find(_T('*'), 0)) > -1)
|
|
{
|
|
strSize = m_arSpaceText[nIndex].GetAt(i).Left(nFind);
|
|
strData = m_arSpaceText[nIndex].GetAt(i).Mid(nFind + 1);
|
|
nSize = _ttoi(strSize);
|
|
dDist = _ttof(strData);
|
|
}
|
|
else
|
|
{
|
|
dDist = _ttof(m_arSpaceText[nIndex].GetAt(i));
|
|
}
|
|
for (int j = 0; j < nSize; j++)
|
|
{
|
|
arDists.Add(dDist);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
double KTLineAxisGridDlg::GetTotalVal(int nIndex, const CArray<double,double>& arDists)
|
|
{
|
|
int nSize = arDists.GetSize();
|
|
if (nIndex > nSize) return 0.0;
|
|
|
|
double dVal = 0.0;
|
|
for(int i = 0; i < nIndex; i++)
|
|
{
|
|
dVal += arDists.GetAt(i);
|
|
}
|
|
return dVal;
|
|
}
|
|
|
|
void KTLineAxisGridDlg::FreeBuffer()
|
|
{
|
|
AcDbEntity *pEnt = NULL;
|
|
int nSize = m_arEntPtrsForRedraw.length();
|
|
while (nSize > 0)
|
|
{
|
|
pEnt = (AcDbEntity*)m_arEntPtrsForRedraw.at(0);
|
|
if (pEnt != NULL)
|
|
{
|
|
delete pEnt;
|
|
pEnt = NULL;
|
|
}
|
|
m_arEntPtrsForRedraw.removeFirst();
|
|
nSize = m_arEntPtrsForRedraw.length();
|
|
}
|
|
m_arEntPtrsForRedraw.setLogicalLength(0);
|
|
}
|
|
|
|
void KTLineAxisGridDlg::OnDestroy()
|
|
{
|
|
CDialog::OnDestroy();
|
|
m_wndPreview.Clear(0);
|
|
FreeBuffer();
|
|
}
|
|
|
|
int KTLineAxisGridDlg::GetRelatingIndex()
|
|
{
|
|
int nRelIndex;
|
|
if (m_nIndex == 0 || m_nIndex == 2)
|
|
nRelIndex = m_nIndex + 1;
|
|
else
|
|
nRelIndex = m_nIndex - 1;
|
|
|
|
return nRelIndex;
|
|
}
|
|
|
|
void KTLineAxisGridDlg::OnChangeEditang()
|
|
{
|
|
CString sText;
|
|
GetDlgItem(IDC_EDITANG)->GetWindowText(sText);
|
|
m_dAngle = _ttof(sText);
|
|
RedrawAxisGrids();
|
|
}
|
|
|
|
void KTLineAxisGridDlg::OnBnClickedButton1()
|
|
{
|
|
POSITION ps = m_wndAxisGridListCtrl.GetFirstSelectedItemPosition();
|
|
if (ps != NULL)
|
|
{
|
|
int nItem = m_wndAxisGridListCtrl.GetNextSelectedItem(ps);
|
|
if (nItem != -1)
|
|
{
|
|
m_wndAxisGridListCtrl.DeleteItem(nItem);
|
|
UpdateSpaceList();
|
|
UpdateSpaceEdit();
|
|
RedrawAxisGrids();
|
|
RefreshTotalDis();
|
|
}
|
|
}
|
|
}
|