1692 lines
39 KiB
C++
1692 lines
39 KiB
C++
// // DrawingList.cpp : 实现文件
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "tchar.h"// [12/27/2007 nsh]
|
|
#include "wchar.h"// [12/27/2007 nsh]
|
|
#include "rxregsvc.h"
|
|
#include "drawingList.h"
|
|
|
|
#define ID_NEW 1
|
|
#define ID_DEL 2
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
TARCH_IMPEXP bool FindRT_MANIFEST();
|
|
#define MM2PIXEL 3.0
|
|
|
|
|
|
const int NAME_NUM = 2;
|
|
const TCHAR *DRAWING_NAME[] = {_T("图名"), _T("图纸名称")};
|
|
BOOL GetDwgFilesDia(XStringList &lstFiles, CWnd *pParent, const TCHAR *pszDir, const TCHAR *pszTitle);
|
|
// extern TARCH_IMPEXP int DragMovePickSet(PickSet &ss, const TCHAR *pszPrompt, const XPoint &ptBase, XPoint &ptFinal);
|
|
void GetFrameSize(AcDbBlockReference*pEnt,CString &sSize);
|
|
extern TARCH_IMPEXP TProject g_project;
|
|
|
|
|
|
// 图纸目录命令
|
|
void DrawingList()
|
|
{
|
|
CAcModuleResourceOverride vTemp;
|
|
CDrawingList dlg;
|
|
dlg.DoModal();
|
|
}
|
|
|
|
// 获得某路径下所有扩展名为ext的文件
|
|
void GetPathFilesByExt(const TCHAR* path, const TCHAR* ext, CStringArray& files)
|
|
{
|
|
_tfinddata_t findRes;
|
|
// Zyu modify on 100722,支持64位
|
|
//long FindFirstRet = 0;
|
|
intptr_t FindFirstRet = 0;
|
|
int FindNextRet = 0;
|
|
CString sFilter;
|
|
sFilter.Format(_T("%s%s"), path, ext);
|
|
FindFirstRet = _tfindfirst(sFilter, &findRes);
|
|
if (FindFirstRet != -1)
|
|
files.Add(findRes.name);
|
|
while(1)
|
|
{
|
|
FindNextRet = _tfindnext(FindFirstRet,&findRes);
|
|
if (FindNextRet == 0)
|
|
files.Add(findRes.name);
|
|
else
|
|
{
|
|
_findclose(FindFirstRet);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 由文件路径名获得文件名
|
|
void GetFileNameByPath(const TCHAR* pathName, CString &filePath, CString &fileName)
|
|
{
|
|
TCHAR drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]=_T("");
|
|
_tsplitpath(pathName, drive, dir, fname, ext);
|
|
filePath.Format(_T("%s%s"), drive, dir);
|
|
fileName.Format(_T("%s%s"), fname, ext);
|
|
}
|
|
|
|
CString ChangeCharToNum(CString szChar)
|
|
{
|
|
CString szNum = szChar;
|
|
TCHAR *NUMBER[] = {_T("零"), _T("一"), _T("二"), _T("三"), _T("四"), _T("五"), _T("六"), _T("七"), _T("八"), _T("九")};
|
|
|
|
int ilen = szNum.GetLength();
|
|
for(int i=0; i<10; i++)
|
|
{
|
|
TCHAR str[16];
|
|
_stprintf(str, _T("%d"), i);
|
|
szNum.Replace(NUMBER[i], str);
|
|
return szNum;
|
|
}
|
|
return szNum;
|
|
}
|
|
|
|
// TDrawingGrid
|
|
|
|
void DrawingListWDGrid::Compositor()
|
|
{
|
|
if (colList.GetDataNum() <= 0)
|
|
return;
|
|
|
|
long lCur;
|
|
TCHAR str[32];
|
|
for(rowList.MoveToFirst(); !rowList.IsOut(); rowList.MoveToNext())
|
|
{
|
|
lCur = rowList.GetCur();
|
|
_stprintf(str, _T("%d"), lCur+1);
|
|
WDGridRow &row = *rowList.GetCurData();
|
|
row[0].SetText(str);
|
|
}
|
|
}
|
|
|
|
void DrawingListWDGrid::OnDataChanged()
|
|
{
|
|
WDGrid::OnDataChanged();
|
|
Compositor();
|
|
}
|
|
|
|
/////////////////////////////////////////////////////
|
|
// CDrawingList 对话框
|
|
IMPLEMENT_DYNAMIC(CDrawingList, CAcUiDialog)
|
|
CDrawingList::CDrawingList(CWnd* pParent /*=NULL*/)
|
|
: CAcUiDialog(CDrawingList::IDD, pParent)
|
|
{
|
|
m_bModel = TRUE;
|
|
m_bPaper = TRUE;
|
|
}
|
|
|
|
CDrawingList::~CDrawingList()
|
|
{
|
|
}
|
|
|
|
void CDrawingList::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CAcUiDialog::DoDataExchange(pDX);
|
|
DDX_Check(pDX, IDC_CHECK_MODEL, m_bModel);
|
|
DDX_Check(pDX, IDC_CHECK_PAPER, m_bPaper);
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CDrawingList, CAcUiDialog)
|
|
ON_BN_CLICKED(IDC_ADD_FILE, OnBnClickedAddFile)
|
|
ON_BN_CLICKED(IDC_DELETE_FILE, OnBnClickedDeleteFile)
|
|
ON_BN_CLICKED(IDC_CHECK_MODEL, OnBnClickedCheckModel)
|
|
ON_BN_CLICKED(IDC_CHECK_PAPER, OnBnClickedCheckPaper)
|
|
ON_BN_CLICKED(IDC_BUTTON_SHEET, OnBnClickedButtonSheetName)
|
|
|
|
ON_BN_CLICKED(IDC_PREVIEW, OnBnClickedButtonSheetName)
|
|
|
|
ON_WM_PAINT()
|
|
ON_WM_SIZE()
|
|
|
|
//add by xlc on 090224
|
|
ON_WM_SETCURSOR()
|
|
END_MESSAGE_MAP()
|
|
|
|
// CDrawingList 消息处理程序
|
|
BOOL CDrawingList::OnInitDialog()
|
|
{
|
|
CAcUiDialog::OnInitDialog();
|
|
InitGrid();
|
|
|
|
ReadParamFromRegistry();
|
|
UpdatePreview();
|
|
return TRUE;
|
|
}
|
|
|
|
void CDrawingList::InitGrid()
|
|
{
|
|
m_grid.Clear();
|
|
m_grid.AppendCol(_T("文件名"), 240);
|
|
m_grid.AppendCol(_T("图纸数"));
|
|
m_grid.GetCol(0).SetReadOnly();
|
|
m_grid.GetCol(1).SetReadOnly();
|
|
m_grid.SetColPosFix();
|
|
m_grid.SetRowPosFix();
|
|
m_grid.SetColFixLength();
|
|
m_grid.SetNoPaste();
|
|
m_grid.Create(this, IDC_LIST);
|
|
m_grid.FitLastCol();
|
|
|
|
TProjectGroupItem* pCurGroup = g_project.GetGroup(_T("图纸"));
|
|
if (pCurGroup == NULL)
|
|
return;
|
|
|
|
GroupToGrid(pCurGroup);
|
|
}
|
|
|
|
void CDrawingList::GroupToGrid(TProjectGroupItem *pGroup)
|
|
{
|
|
if (pGroup == NULL)
|
|
return;
|
|
|
|
if (pGroup->IsGroup())
|
|
{
|
|
for(pGroup->MoveToFirst(); !pGroup->IsOut(); pGroup->MoveToNext())
|
|
{
|
|
TProjectGroupItem *pChildGroup = (TProjectGroupItem *)pGroup->GetCurData();
|
|
GroupToGrid(pChildGroup);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CString szFileName = pGroup->GetName();
|
|
if (szFileName == _T(""))
|
|
return;
|
|
|
|
CString szFullName = g_project.GetDwgFullName(szFileName);
|
|
TRowXData *pRowXD = new TRowXData;
|
|
GetRowXData(szFullName, pRowXD);
|
|
if (pRowXD->m_lstPapers.IsEmpty()&&pRowXD->m_lstModels.IsEmpty())
|
|
{
|
|
delete pRowXD;
|
|
return;
|
|
}
|
|
m_grid.AppendRow();
|
|
UpdateRow(m_grid.GetRowNum()-1, szFileName, pRowXD);
|
|
}
|
|
}
|
|
|
|
//
|
|
//void CDrawingList::InitGrid()
|
|
//{
|
|
// m_grid.Clear();
|
|
// m_grid.AppendCol(_T("文件名"), 240);
|
|
// m_grid.AppendCol(_T("图纸数"));
|
|
// m_grid.GetCol(0).SetReadOnly();
|
|
// m_grid.GetCol(1).SetReadOnly();
|
|
// m_grid.SetColPosFix();
|
|
// m_grid.SetColFixLength();
|
|
// m_grid.SetNoPaste();
|
|
// m_grid.Create(this, IDC_LIST);
|
|
// m_grid.FitLastCol();
|
|
//
|
|
// TRowXData *pRowXD = new TRowXData;
|
|
// CString szFileName = curDoc()->fileName();
|
|
// GetRowXData(szFileName, pRowXD);
|
|
// if (pRowXD->m_lstPapers.IsEmpty()&&pRowXD->m_lstModels.IsEmpty())
|
|
// delete pRowXD;
|
|
// else
|
|
// {
|
|
// m_grid.SetRowNum(1);
|
|
// int c=szFileName.ReverseFind(_T('\\'));
|
|
// if (c>=0)
|
|
// szFileName=szFileName.Right(szFileName.GetLength()-c-1);
|
|
// szFileName.TrimRight(_T(".dwg"));
|
|
// UpdateRow(0, szFileName, pRowXD);
|
|
// }
|
|
// pRowXD = NULL;
|
|
//}
|
|
|
|
void CDrawingList::OnBnClickedAddFile()
|
|
{
|
|
XStringList lstFiles;
|
|
XString sFolder;
|
|
xg_getvar(_T("DWGPREFIX"), sFolder);
|
|
if (!GetDwgFilesDia(lstFiles, this, sFolder, _T("选择文件")))
|
|
return;
|
|
|
|
long i, j;
|
|
for(i=lstFiles.Length()-1; i>=0; i--)
|
|
{
|
|
CString sNewFile = lstFiles[i];
|
|
for(j=0; j<m_grid.GetRowNum(); j++)
|
|
{
|
|
CString sOldFile = ((TRowXData*)m_grid.GetRow(j).GetExtendData())->m_sFilePath;
|
|
|
|
//modify by xlc on 081117
|
|
//if (sOldFile == sNewFile)
|
|
if (sOldFile.CompareNoCase(sNewFile)==0)
|
|
{
|
|
acutPrintf(_T("\n文件'%s'已经存在!\n"), sNewFile);
|
|
lstFiles.Remove(i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
int iCount = lstFiles.Length();
|
|
long lPos = m_grid.GetCurRowIndex();
|
|
if (lPos >= 0)
|
|
{
|
|
for(i=0; i<iCount; i++)
|
|
m_grid.InsertRow(lPos);
|
|
}
|
|
else
|
|
{
|
|
lPos = m_grid.GetRowNum();
|
|
for(i=0; i<iCount; i++)
|
|
m_grid.AppendRow();
|
|
}
|
|
|
|
acedSetStatusBarProgressMeter(_T("搜索文件中..."), 0, iCount);
|
|
acedSetStatusBarProgressMeterPos(0);
|
|
CString szFileName, szPathName;
|
|
for(i=0; i<iCount; i++)
|
|
{
|
|
TRowXData *pXD = new TRowXData;
|
|
szPathName = lstFiles[i];
|
|
CString filePath, fileName;
|
|
GetFileNameByPath(szPathName, filePath, fileName);
|
|
if (_tcscmp(filePath, sFolder) == 0)
|
|
szFileName = fileName;
|
|
else
|
|
szFileName = szPathName;
|
|
|
|
szFileName.TrimRight(_T(".dwg"));
|
|
GetRowXData(szPathName, pXD);
|
|
UpdateRow(lPos + i, szFileName, pXD);
|
|
pXD = NULL;
|
|
acedSetStatusBarProgressMeterPos(i+1);
|
|
}
|
|
acedRestoreStatusBar();
|
|
}
|
|
|
|
void CDrawingList::OnBnClickedDeleteFile()
|
|
{
|
|
if (!m_grid.IsRowSelected())
|
|
MessageBox(_T("请先选定行!"));
|
|
m_grid.DoDelete();
|
|
}
|
|
|
|
void CDrawingList::OnBnClickedCheckModel()
|
|
{
|
|
CDataExchange dx(this, TRUE);
|
|
DDX_Check(&dx, IDC_CHECK_MODEL, m_bModel);
|
|
if (!m_bModel)
|
|
{
|
|
m_bPaper = TRUE;
|
|
CDataExchange dxp(this, FALSE);
|
|
DDX_Check(&dxp, IDC_CHECK_PAPER, m_bPaper);
|
|
}
|
|
UpdateSpace();
|
|
}
|
|
|
|
void CDrawingList::OnBnClickedCheckPaper()
|
|
{
|
|
CDataExchange dx(this, TRUE);
|
|
DDX_Check(&dx, IDC_CHECK_PAPER, m_bPaper);
|
|
if (!m_bPaper)
|
|
{
|
|
m_bModel = TRUE;
|
|
CDataExchange dxm(this, FALSE);
|
|
DDX_Check(&dxm, IDC_CHECK_MODEL, m_bModel);
|
|
}
|
|
UpdateSpace();
|
|
}
|
|
|
|
void CDrawingList::UpdateRow(int iRow, CString &szFileName, TRowXData *pXD)
|
|
{
|
|
if (pXD == NULL)
|
|
return;
|
|
|
|
int iModel = pXD->m_iModel;
|
|
int iPaper = pXD->m_iPaper;
|
|
CString szNumber = GetNumberString(iModel, iPaper);
|
|
|
|
if (iRow < m_grid.GetRowNum())
|
|
{
|
|
m_grid.GetCell(iRow, 0).SetText(szFileName);
|
|
m_grid.GetCell(iRow, 1).SetText(szNumber);
|
|
m_grid.GetRow(iRow).SetExtendData(pXD);
|
|
m_grid.Refresh();
|
|
}
|
|
}
|
|
|
|
void CDrawingList::UpdateSpace()
|
|
{
|
|
for(long i=0; i<m_grid.GetRowNum(); i++)
|
|
{
|
|
TRowXData *pXD = (TRowXData*)m_grid.GetRow(i).GetExtendData();
|
|
if (pXD == NULL)
|
|
continue;
|
|
CString sNumber = GetNumberString(pXD->m_iModel, pXD->m_iPaper);
|
|
m_grid.GetCell(i, 1).SetText(sNumber);
|
|
}
|
|
m_grid.Refresh();
|
|
}
|
|
|
|
void CDrawingList::GetRowXData(const TCHAR *fpath, TRowXData *&pXD)
|
|
{
|
|
if (pXD == NULL)
|
|
return;
|
|
|
|
PDList<TDrawing> lstModels, lstPapers;
|
|
GetOneDwgData(fpath, lstModels, lstPapers);
|
|
pXD->m_sFilePath = fpath;
|
|
pXD->m_iModel = lstModels.GetDataNum();
|
|
pXD->m_iPaper = lstPapers.GetDataNum();
|
|
pXD->m_lstModels.Conbine(lstModels);
|
|
pXD->m_lstPapers.Conbine(lstPapers);
|
|
}
|
|
|
|
void CDrawingList::GetOneDwgData(const TCHAR* fname, PDList<TDrawing> &lstModels, PDList<TDrawing> &lstPapers)
|
|
{
|
|
AcDbDatabase *pDb = new AcDbDatabase(Adesk::kFalse);
|
|
#if ADS < 21
|
|
if (pDb->readDwgFile(fname, _SH_DENYNO, FALSE) != Acad::eOk)
|
|
#else
|
|
if (pDb->readDwgFile(fname, AcDbDatabase::kForReadAndAllShare, FALSE) != Acad::eOk)
|
|
#endif
|
|
{
|
|
delete pDb;
|
|
return;
|
|
}
|
|
|
|
AcDbBlockTable *pTable = NULL;
|
|
if (pDb->getSymbolTable(pTable, AcDb::kForRead) != Acad::eOk)
|
|
{
|
|
delete pDb;
|
|
return;
|
|
}
|
|
|
|
AcDbBlockTableIterator *pBlockTableIter = NULL;
|
|
pTable->newIterator(pBlockTableIter);
|
|
pTable->close();
|
|
for(pBlockTableIter->start(); !pBlockTableIter->done(); pBlockTableIter->step())
|
|
{
|
|
AcDbBlockTableRecord *pRecord = NULL;
|
|
pBlockTableIter->getRecord(pRecord, AcDb::kForRead);
|
|
TCHAR *str = NULL;
|
|
pRecord->getName(str);
|
|
CString szRecordName = str;
|
|
szRecordName.MakeUpper();
|
|
if (_tcscmp(szRecordName, _T("*MODEL_SPACE")) == 0)
|
|
{
|
|
GetOneRecordData(pRecord, lstModels);
|
|
}
|
|
else if (szRecordName.Find(_T("*PAPER_SPACE")) >= 0)
|
|
{
|
|
GetOneRecordData(pRecord, lstPapers);
|
|
}
|
|
pRecord->close();
|
|
}
|
|
|
|
delete pBlockTableIter;
|
|
delete pDb;
|
|
}
|
|
|
|
BOOL CDrawingList::GetOneRecordData(AcDbBlockTableRecord *pRecord, PDList<TDrawing> &lstSpace)
|
|
{
|
|
AcDbBlockTableRecordIterator *pIterator = NULL;
|
|
if (pRecord->newIterator(pIterator) != Acad::eOk)
|
|
{
|
|
return FALSE;
|
|
}
|
|
|
|
for(pIterator->start(); !pIterator->done(); pIterator->step())
|
|
{
|
|
AcDbEntity *pEnt = NULL;
|
|
if (pIterator->getEntity(pEnt, AcDb::kForRead) != Acad::eOk)
|
|
continue;
|
|
|
|
if (pEnt->isKindOf(AcDbBlockReference::desc()))
|
|
{
|
|
AcDbBlockReference *pRef = (AcDbBlockReference *)pEnt;
|
|
if (pRef == NULL)
|
|
continue;
|
|
if (_tcsicmp(pRef->layer(), LAY_BORDER) != 0)
|
|
continue;
|
|
|
|
TDrawing *pDrawing = new TDrawing;
|
|
if (pDrawing == NULL)
|
|
continue;
|
|
if (GetBlockAttribute(pRef, pDrawing))
|
|
{
|
|
CString szSize;
|
|
GetFrameSize(pRef, szSize);
|
|
pDrawing->m_sPageSize = szSize;
|
|
lstSpace.AddTail(pDrawing);
|
|
}
|
|
else
|
|
delete pDrawing;
|
|
}
|
|
pEnt->close();
|
|
}
|
|
delete pIterator;
|
|
return TRUE;
|
|
}
|
|
// [12/26/2007 nsh]
|
|
//---------------------------------------begin-------------------------------
|
|
long GetNumberFromString(const CString sTemp)
|
|
{//传入字符串,并返回字符串中的数字,转化的数字是通过long类型传出
|
|
CString sNum;
|
|
for(int j=0;j<sTemp.GetLength();j++)
|
|
{
|
|
if (sTemp[j]>=_T('0') && sTemp[j]<= _T('9'))
|
|
sNum+=sTemp[j];
|
|
}
|
|
|
|
long lTemp=_ttoi(sNum);
|
|
return lTemp;
|
|
}
|
|
//----------------------------------------end--------------------------------
|
|
// 得到属性定义
|
|
BOOL CDrawingList::GetBlockAttribute(AcDbBlockReference *pRef, TDrawing *&pDrawing)
|
|
{
|
|
int i;
|
|
AcDbObjectIterator *pAttIter = NULL;
|
|
pAttIter = pRef->attributeIterator();
|
|
if (pAttIter == NULL)
|
|
return FALSE;
|
|
|
|
BOOL bFlag = FALSE;
|
|
CString szName;
|
|
CStringArray szArTag, szArName;
|
|
for(pAttIter->start(); !pAttIter->done(); pAttIter->step())
|
|
{
|
|
AcDbEntity *pEnt = NULL;
|
|
AcDbObjectId eId = pAttIter->objectId();
|
|
if (acdbOpenAcDbEntity(pEnt, eId, AcDb::kForRead) != Acad::eOk)
|
|
continue;
|
|
AcDbAttribute *pAtt = AcDbAttribute::cast(pEnt);
|
|
if (pAtt == NULL)
|
|
continue;
|
|
|
|
CString szTag = pAtt->tag();
|
|
if (szTag == _T("图号"))
|
|
{
|
|
bFlag = TRUE;
|
|
pDrawing->m_sNo = pAtt->textString();
|
|
}
|
|
else
|
|
{
|
|
for(i=0; i<NAME_NUM; i++)
|
|
{
|
|
if (szTag == DRAWING_NAME[i])
|
|
{
|
|
szName = pAtt->textString();
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
if (szTag.Find(DRAWING_NAME[i]) != -1)
|
|
{
|
|
szArTag.Add(szTag);
|
|
szArName.Add(pAtt->textString());
|
|
break;
|
|
}
|
|
// [12/26/2007 nsh]
|
|
//---------------------begin---------------------
|
|
else
|
|
{
|
|
if (szTag.Find(_T("图"))!=-1 && szTag.Find(_T("名"))!=-1)
|
|
{
|
|
szArTag.Add(szTag);
|
|
szArName.Add(pAtt->textString());
|
|
break;
|
|
}
|
|
}
|
|
//----------------------end----------------------
|
|
}
|
|
}
|
|
}
|
|
pEnt->close();
|
|
}
|
|
delete pAttIter;
|
|
|
|
if (bFlag)
|
|
{
|
|
// Zyu modify on 100722,支持64位
|
|
//int ilen = szArName.GetSize();
|
|
INT_PTR ilen = szArName.GetSize();
|
|
for(int i=0; i<ilen; i++)
|
|
{
|
|
for(int j=0; j<ilen-1-i; j++)
|
|
{
|
|
CString t1 = szArTag[j];
|
|
CString t2 = szArTag[j+1];
|
|
// [12/26/2007 nsh]
|
|
//--------------begin---------------
|
|
t1.Replace(_T(" "),_T(""));
|
|
t2.Replace(_T(" "),_T(""));
|
|
//---------------end----------------
|
|
int t3 = CmpLabel(t1, t2);
|
|
//if (CmpLabel(ChangeCharToNum(szArTag[j]), ChangeCharToNum(szArTag[j+1])) > 0)// [12/26/2007 nsh]
|
|
if (GetNumberFromString(t1)-GetNumberFromString(t2)>0)// add by nsh on 12 26 2007
|
|
{
|
|
CString szTempTag = szArTag[j];
|
|
szArTag[j] = szArTag[j+1];
|
|
szArTag[j+1] = szTempTag;
|
|
CString szTempName = szArName[j];
|
|
szArName[j] = szArName[j+1];
|
|
szArName[j+1] = szTempName;
|
|
}
|
|
}
|
|
}
|
|
|
|
for(int k=0; k<ilen; k++)
|
|
{
|
|
if (szName == _T(""))
|
|
szName = szArName[k];
|
|
else if (szArName[k] != _T(""))
|
|
szName = szName + _T(";") + szArName[k];
|
|
}
|
|
pDrawing->m_sName = szName;
|
|
}
|
|
szArTag.RemoveAll();
|
|
szArName.RemoveAll();
|
|
return bFlag;
|
|
}
|
|
|
|
CString CDrawingList::GetNumberString(int iModel, int iPaper)
|
|
{
|
|
CString sCell;
|
|
if (m_bModel)
|
|
{
|
|
if (m_bPaper && iPaper>0)
|
|
sCell.Format(_T("%d+%d"), iModel, iPaper);
|
|
else
|
|
sCell.Format(_T("%d"), iModel);
|
|
}
|
|
else
|
|
{
|
|
if (m_bPaper && iPaper>0)
|
|
sCell.Format(_T("%d"), iPaper);
|
|
else
|
|
sCell.Format(_T("%d"), 0);
|
|
}
|
|
return sCell;
|
|
}
|
|
|
|
BOOL CDrawingList::GetLastDrawingList()
|
|
{
|
|
BOOL bFlag = FALSE;
|
|
for(long i=0; i<m_grid.GetRowNum(); i++)
|
|
{
|
|
TRowXData *pDX = (TRowXData*)m_grid.GetRow(i).GetExtendData();
|
|
if (pDX == NULL)
|
|
continue;
|
|
|
|
if (m_bModel)
|
|
pDX->m_lstSpaces.Conbine(pDX->m_lstModels);
|
|
if (m_bPaper)
|
|
pDX->m_lstSpaces.Conbine(pDX->m_lstPapers);
|
|
pDX->m_lstSpaces.Arrange();
|
|
if (!pDX->m_lstSpaces.IsEmpty())
|
|
{
|
|
bFlag = TRUE;
|
|
}
|
|
}
|
|
return bFlag;
|
|
}
|
|
//从指定构件库中加载构件,外部释放
|
|
AcDbEntity* LoadGJKEntity(XString sBlockName)
|
|
{
|
|
AcDbEntity *pEntRes=NULL;
|
|
|
|
XString sBlockName1;
|
|
if (LoadDwbBlock(sBlockName,sBlockName1) == RTNORM)
|
|
{
|
|
AcDbDatabase *pDatabase = acdbHostApplicationServices()->workingDatabase();
|
|
AcDbBlockTable *pBlkTable = NULL;
|
|
pDatabase->getBlockTable(pBlkTable,AcDb::kForRead);
|
|
if (pBlkTable!=NULL)
|
|
{
|
|
AcDbBlockTableRecord *pBlkTableRec = NULL;
|
|
pBlkTable->getAt(sBlockName1,pBlkTableRec,AcDb::kForRead);
|
|
pBlkTable->close();
|
|
|
|
if (pBlkTableRec!=NULL)
|
|
{
|
|
AcDbBlockTableRecordIterator *pBlkTableRecIte = NULL;
|
|
pBlkTableRec->newIterator(pBlkTableRecIte);
|
|
if (pBlkTableRecIte!=NULL)
|
|
{
|
|
for (pBlkTableRecIte->start();!pBlkTableRecIte->done();pBlkTableRecIte->step())
|
|
{
|
|
AcDbEntity *pEnt = NULL;
|
|
pBlkTableRecIte->getEntity(pEnt,AcDb::kForRead);
|
|
if (pEnt != NULL)
|
|
{
|
|
pEntRes=(AcDbEntity*)pEnt->clone();
|
|
pEnt->close();
|
|
break;
|
|
}
|
|
}
|
|
delete pBlkTableRecIte;
|
|
}
|
|
|
|
if (pBlkTableRec->upgradeOpen() == Acad::eOk)
|
|
pBlkTableRec->erase();
|
|
|
|
pBlkTableRec->close();
|
|
}
|
|
}
|
|
}
|
|
|
|
TEntityBase *pTEnt=TEntityBase::Cast(pEntRes);
|
|
if (pTEnt!=NULL)
|
|
pTEnt->SetPScale(DocGetPScale());//设为当前比例,071024
|
|
return pEntRes;
|
|
}
|
|
void CDrawingList::OnOK()
|
|
{
|
|
GetParent()->EnableWindow(TRUE);
|
|
GetParent()->SetFocus();
|
|
GetParent()->SetActiveWindow();
|
|
ShowWindow(SW_HIDE);
|
|
GetLastDrawingList();
|
|
|
|
//modify by xlc on 080901
|
|
/*
|
|
CAcModuleResourceOverride vTemp;
|
|
CDrawingListNext dlg(m_grid, acedGetAcadFrame());
|
|
int nRet = dlg.DoModal();
|
|
if (nRet == 1000)
|
|
{
|
|
GetParent()->EnableWindow(FALSE);
|
|
EnableWindow(TRUE);
|
|
SetActiveWindow();
|
|
ShowWindow(SW_SHOW);
|
|
}
|
|
else
|
|
{
|
|
CAcUiDialog::OnOK();
|
|
}
|
|
*/
|
|
AcDbEntity *pEnt=NULL;
|
|
XString sLibFile;
|
|
sLibFile << g_sDwbPath << _T("Sheet.TKW");
|
|
pEnt=LoadGJKEntity(m_strBlockName);
|
|
|
|
TDbSheet *pSheet=NULL;
|
|
if (pEnt!=NULL)
|
|
{
|
|
if (pEnt->isKindOf(TDbSheet::desc()))
|
|
{
|
|
pSheet=TDbSheet::cast(pEnt);
|
|
}
|
|
else
|
|
{
|
|
AfxMessageBox(_T("表格块错误!"));
|
|
delete pEnt;
|
|
CDialog::OnOK();
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
AfxMessageBox(_T("表格块错误!"));
|
|
CDialog::OnOK();
|
|
return;
|
|
}
|
|
|
|
long lCount = m_grid.GetRowNum(); //目录文件数
|
|
long colCount=pSheet->GetColumnNum(); //表格列数
|
|
long rowCount=pSheet->GetRowNum(); //原始表格行数
|
|
long lRow = rowCount-1;
|
|
//--------确定添加项---------------------------
|
|
if (rowCount<2)//表格没有台头或没有单元项
|
|
{
|
|
AfxMessageBox(_T("表格错误!"));
|
|
delete pSheet;
|
|
CAcUiDialog::OnOK();
|
|
return;
|
|
}
|
|
int nCount=0; //记录匹配字段数
|
|
int nNum(-1),nNo(-1),nName(-1),nPageSize(-1);//记录序号,图号,图纸名称,图幅的列位置,-1表示不存在该列
|
|
for(int j=0;j<colCount;j++)
|
|
{
|
|
TGridCell *pCell=(*pSheet)(lRow-1, j);
|
|
CString ss=pCell->GetText();
|
|
if ((ss.Find(_T("(序号)"))!=-1)||ss.Find(_T("(序号)"))!=-1)
|
|
{
|
|
if (nNum==-1)
|
|
{
|
|
nNum=j;
|
|
nCount++;
|
|
}
|
|
}
|
|
else if ((ss.Find(_T("(图号)"))!=-1)||(ss.Find(_T("(图号)"))!=-1))
|
|
{
|
|
if (nNo==-1)
|
|
{
|
|
nNo=j;
|
|
nCount++;
|
|
}
|
|
}
|
|
else if ((ss.Find(_T("(图纸名称)"))!=-1)||(ss.Find(_T("(图纸名称)"))!=-1))
|
|
{
|
|
if (nName==-1)
|
|
{
|
|
nName=j;
|
|
nCount++;
|
|
}
|
|
}
|
|
else if ((ss.Find(_T("(图幅)"))!=-1)||(ss.Find(_T("(图幅)"))!=-1))
|
|
{
|
|
if (nPageSize==-1)
|
|
{
|
|
nPageSize=j;
|
|
nCount++;
|
|
}
|
|
}
|
|
else if ((ss.Find(_T("序"))!=-1)&&(ss.Find(_T("号"))!=-1))
|
|
{
|
|
if (nNum==-1)
|
|
{
|
|
nNum=j;
|
|
nCount++;
|
|
}
|
|
}
|
|
else if ((ss.Find(_T("图"))!=-1)&&(ss.Find(_T("号"))!=-1))
|
|
{
|
|
if (nNo==-1)
|
|
{
|
|
nNo=j;
|
|
nCount++;
|
|
}
|
|
}
|
|
else if ((ss.Find(_T("图"))!=-1)&&(ss.Find(_T("纸"))!=-1)&&(ss.Find(_T("名"))!=-1)&&(ss.Find(_T("称"))!=-1))
|
|
{
|
|
if (nName==-1)
|
|
{
|
|
nName=j;
|
|
nCount++;
|
|
}
|
|
}
|
|
else if ((ss.Find(_T("图"))!=-1)&&(ss.Find(_T("幅"))!=-1))
|
|
{
|
|
if (nPageSize==-1)
|
|
{
|
|
nPageSize=j;
|
|
nCount++;
|
|
}
|
|
}
|
|
}
|
|
if (nCount<2)
|
|
{
|
|
AfxMessageBox(_T("表格错误,至少匹配两个字段!"));
|
|
delete pSheet;
|
|
CAcUiDialog::OnOK();
|
|
return;
|
|
}
|
|
for(j=0;j<rowCount;j++)
|
|
{
|
|
for(int k=0;k<colCount;k++)
|
|
{
|
|
TGridCell *pCell=(*pSheet)(j, k);
|
|
CString ss=pCell->GetText();
|
|
CString str(_T(""));
|
|
|
|
//modify by xlc on 090206 解决表格出现乱码的问题
|
|
// if (ss.Find(_T("(序号)"))!=-1)
|
|
// {
|
|
// str=ss.Left(ss.GetLength()-4);
|
|
// pCell->SetText(str);
|
|
// }
|
|
// else if ((ss.Find(_T("(图号)"))!=-1))
|
|
// {
|
|
// str=ss.Left(ss.GetLength()-4);
|
|
// pCell->SetText(str);
|
|
// }
|
|
// else if ((ss.Find(_T("(图纸名称)"))!=-1))
|
|
// {
|
|
// str=ss.Left(ss.GetLength()-6);
|
|
// pCell->SetText(str);
|
|
// }
|
|
// else if ((ss.Find(_T("(图幅)"))!=-1))
|
|
// {
|
|
// str=ss.Left(ss.GetLength()-4);
|
|
// pCell->SetText(str);
|
|
// }
|
|
if (ss.Find(_T("(序号)"))!=-1)
|
|
{
|
|
CString s1=_T("(序号)");
|
|
str=ss.Left(ss.GetLength()-s1.GetLength());
|
|
pCell->SetText(str);
|
|
}
|
|
else if (ss.Find(_T("(序号)"))!=-1)
|
|
{
|
|
CString s1=_T("(序号)");
|
|
str=ss.Left(ss.GetLength()-s1.GetLength());
|
|
pCell->SetText(str);
|
|
}
|
|
else if ((ss.Find(_T("(图号)"))!=-1))
|
|
{
|
|
CString s1=_T("(图号)");
|
|
str=ss.Left(ss.GetLength()-s1.GetLength());
|
|
pCell->SetText(str);
|
|
}
|
|
else if (ss.Find(_T("((图号)"))!=-1)
|
|
{
|
|
CString s1=_T("((图号)");
|
|
str=ss.Left(ss.GetLength()-s1.GetLength());
|
|
pCell->SetText(str);
|
|
}
|
|
else if ((ss.Find(_T("(图纸名称)"))!=-1))
|
|
{
|
|
CString s1=_T("(图纸名称)");
|
|
str=ss.Left(ss.GetLength()-s1.GetLength());
|
|
pCell->SetText(str);
|
|
}
|
|
else if (ss.Find(_T("(图纸名称)"))!=-1)
|
|
{
|
|
CString s1=_T("(图纸名称)");
|
|
str=ss.Left(ss.GetLength()-s1.GetLength());
|
|
pCell->SetText(str);
|
|
}
|
|
else if ((ss.Find(_T("(图幅)"))!=-1))
|
|
{
|
|
CString s1=_T("(图幅)");
|
|
str=ss.Left(ss.GetLength()-s1.GetLength());
|
|
pCell->SetText(str);
|
|
}
|
|
else if (ss.Find(_T("(图幅)"))!=-1)
|
|
{
|
|
CString s1=_T("(图幅)");
|
|
str=ss.Left(ss.GetLength()-s1.GetLength());
|
|
pCell->SetText(str);
|
|
}
|
|
}
|
|
}
|
|
DList<TDrawing> lstDrawing;
|
|
for(long i=0; i<lCount; i++)
|
|
{
|
|
TRowXData *pXD = (TRowXData*)m_grid.GetRow(i).GetExtendData();
|
|
CString szFileName = m_grid.GetCell(i, 0);
|
|
if (pXD == NULL)
|
|
continue;
|
|
|
|
long lDataNum = pXD->m_lstSpaces.GetDataNum();
|
|
|
|
for(int n = 0; n<lDataNum; n++)
|
|
{
|
|
TDrawing *pDrawing = pXD->m_lstSpaces[n];
|
|
if (pDrawing == NULL)
|
|
continue;
|
|
TDrawing *pDraw=new TDrawing;
|
|
pDraw->m_sName=pDrawing->m_sName;
|
|
pDraw->m_sNo=pDrawing->m_sNo;
|
|
pDraw->m_sPageSize=pDrawing->m_sPageSize;
|
|
lstDrawing.Append(pDraw);
|
|
}
|
|
}
|
|
lstDrawing.QuickSort(TDrawing::SortByNo);
|
|
|
|
//填表格数据
|
|
for(i=0; i<lstDrawing.Length(); i++)
|
|
{
|
|
// TRowXData *pXD = (TRowXData*)m_grid.GetRow(i).GetExtendData();
|
|
// CString szFileName = m_grid.GetCell(i, 0);
|
|
// if (pXD == NULL)
|
|
// continue;
|
|
//
|
|
// long lDataNum = pXD->m_lstSpaces.GetDataNum();
|
|
|
|
// for(int n = 0; n<lDataNum; n++)
|
|
{
|
|
// TDrawing *pDrawing = pXD->m_lstSpaces[n];
|
|
// if (pDrawing == NULL)
|
|
// continue;
|
|
|
|
(*pSheet).AddRowAt(lRow+1);
|
|
(*pSheet).CopyRow(lRow,lRow+1);
|
|
TGridCell *pCell=NULL;
|
|
if (nNum!=-1)
|
|
{
|
|
CString szNumber;
|
|
szNumber.Format(_T("%d"), lRow-rowCount+2);
|
|
pCell=(*pSheet)(lRow, nNum);
|
|
pCell->SetText(szNumber);
|
|
}
|
|
if (nNo!=-1)
|
|
{
|
|
pCell=(*pSheet)(lRow, nNo);
|
|
//pCell->SetText(pDrawing->m_sNo);
|
|
pCell->SetText(lstDrawing[i]->m_sNo);
|
|
}
|
|
if (nName!=-1)
|
|
{
|
|
pCell=(*pSheet)(lRow, nName);
|
|
//pCell->SetText(pDrawing->m_sName);
|
|
pCell->SetText(lstDrawing[i]->m_sName);
|
|
}
|
|
if (nPageSize!=-1)
|
|
{
|
|
pCell=(*pSheet)(lRow, nPageSize);
|
|
//pCell->SetText(pDrawing->m_sPageSize);
|
|
CString ss=lstDrawing[i]->m_sPageSize;
|
|
pCell->SetText(lstDrawing[i]->m_sPageSize);
|
|
}
|
|
//pDrawing = NULL;
|
|
lRow++;
|
|
}
|
|
|
|
//pXD = NULL;
|
|
}
|
|
pSheet->RemoveRow(lRow);
|
|
|
|
//绘图
|
|
if (pSheet->IsValid())
|
|
{
|
|
// CAcModuleResourceOverride vTemp;
|
|
// CGridSheetDlg dlg(pSheet,acedGetAcadFrame());
|
|
// dlg.m_nRowNum=rowCount-1;//表头行数
|
|
// if (dlg.DoModal()==IDOK)
|
|
{
|
|
XPoint ptLoc;
|
|
PickSet ss(SS_FREE);
|
|
ss.IncludeBegin();
|
|
|
|
//modify by xlc on 090108解决用户坐标的问题
|
|
//pSheet->SetLocation(ptLoc);
|
|
pSheet->SetLocation(Ucs2Wcs(ptLoc));
|
|
pSheet->SetRotation(Ucs2Wcs(0.0));
|
|
|
|
pSheet->AddToCSpace(Adesk::kTrue);
|
|
pSheet = NULL;
|
|
ss.IncludeEnd();
|
|
|
|
int nRet = DragMovePickSet(ss, _T("\n请点取图纸目录插入位置<返回>: "), XPoint(), XPoint());
|
|
if (nRet != RTNORM)
|
|
{
|
|
ss.Delete();
|
|
}
|
|
CAcUiDialog::OnOK();
|
|
WriteParamToRegistry();
|
|
return;
|
|
}
|
|
// else
|
|
// {
|
|
// delete pSheet;
|
|
// GetParent()->EnableWindow(FALSE);
|
|
// EnableWindow(TRUE);
|
|
// SetActiveWindow();
|
|
// ShowWindow(SW_SHOW);
|
|
// }
|
|
}
|
|
else
|
|
{
|
|
delete pSheet;
|
|
CAcUiDialog::OnOK();
|
|
}
|
|
}
|
|
|
|
//add by xlc on 080908
|
|
void CDrawingList::OnPaint()
|
|
{
|
|
CPaintDC dc(this);
|
|
|
|
CWnd *pImageBox = GetDlgItem(IDC_PREVIEW);
|
|
ASSERT(pImageBox);
|
|
CDC *pDC = pImageBox->GetDC();
|
|
m_image.SetDC(pDC);
|
|
m_image.Redraw();
|
|
m_image.SetDC(NULL);
|
|
pImageBox->ReleaseDC(pDC);
|
|
}
|
|
|
|
// 刷新预览图
|
|
void CDrawingList::UpdatePreview()
|
|
{
|
|
CWnd *pImageBox = GetDlgItem(IDC_PREVIEW);
|
|
ASSERT(pImageBox);
|
|
CRect rect;
|
|
pImageBox->GetClientRect(rect);
|
|
CDC *pDC = pImageBox->GetDC();
|
|
m_image.InitDC(pDC, rect, GetAcadBackColor());
|
|
XString sFullSlide(256);
|
|
sFullSlide << g_sDwbPath << m_strBlockName;
|
|
m_image.PaintSlide(sFullSlide);
|
|
m_image.SetDC(NULL);
|
|
pImageBox->ReleaseDC(pDC);
|
|
}
|
|
|
|
//add by xlc on 090224
|
|
BOOL CDrawingList::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
|
|
{
|
|
CWnd *pSlideWnd=GetDlgItem(IDC_PREVIEW);
|
|
if (pWnd && pWnd->m_hWnd==pSlideWnd->m_hWnd)
|
|
{
|
|
CAcModuleResourceOverride vTemp;
|
|
HCURSOR hIcon = AfxGetApp()->LoadCursor( IDC_CUR_PICK );
|
|
SetCursor( hIcon );
|
|
return TRUE;
|
|
}
|
|
return CAcUiDialog::OnSetCursor(pWnd, nHitTest, message);
|
|
}
|
|
|
|
BOOL InvokeGJKMan(const TCHAR *pszLib, BOOL bSelOnly, XString &sBlockName)
|
|
{
|
|
if (!AT_loaded(_T("tch_blklib"))) {
|
|
int nRet=acrxLoadModule(_T("tch_blklib.arx"), Adesk::kTrue, true);
|
|
if (!nRet)
|
|
return NULL;
|
|
}
|
|
|
|
int nCode=RTT;
|
|
RBList rbCmd=ads_buildlist(RTSTR, _T("IGKW"), RTSTR, pszLib, nCode,
|
|
RTSTR, (const TCHAR *)sBlockName, NULL);
|
|
resbuf *rbRes=NULL;
|
|
AcDbEntity *pEntRes=NULL;
|
|
if (ads_invoke(rbCmd, &rbRes)==RTNORM && rbRes)
|
|
{
|
|
if (rbRes && rbRes->restype==RTSTR)
|
|
sBlockName=rbRes->resval.rstring;
|
|
ads_relrb(rbRes);
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
// 获得块名
|
|
BOOL CDrawingList::GetBlockName(XString &sBlockName)
|
|
{
|
|
BeginEditorCommand();
|
|
XString sLibFile;
|
|
CString path = g_sDwbPath;
|
|
sLibFile << path << _T("sheet.TKW");
|
|
if (!InvokeGJKMan(sLibFile, TRUE, sBlockName)) {
|
|
CompleteEditorCommand();
|
|
|
|
UpdateData(FALSE);
|
|
return FALSE;
|
|
}
|
|
|
|
CompleteEditorCommand();
|
|
return TRUE;
|
|
}
|
|
|
|
void CDrawingList::OnBnClickedButtonSheetName()
|
|
{
|
|
GetBlockName(m_strBlockName);
|
|
UpdatePreview();
|
|
}
|
|
// 关键注册位置,
|
|
BOOL CDrawingList::GetRegLocation(XString &sRegLoc) const
|
|
{
|
|
sRegLoc=_T("Sheet");
|
|
return TRUE;
|
|
}
|
|
// 从注册表读入参数
|
|
BOOL CDrawingList::ReadParamFromRegistry()
|
|
{
|
|
XString sRegSubLoc, sRegLoc(1024);
|
|
BOOL bOk=GetRegLocation(sRegSubLoc);
|
|
if (!bOk)
|
|
return FALSE;
|
|
sRegLoc << ::GetRegLocation() << _T("\\Settings") ;
|
|
CRegProperty regProp(sRegLoc, sRegSubLoc);
|
|
regProp.SetTopRootKey(HKEY_CURRENT_USER);
|
|
|
|
CString sBlockName;
|
|
if (!regProp.GetValue(_T("TitleList"), sBlockName))
|
|
{
|
|
sBlockName=_T("Sheet(00000001)");
|
|
}
|
|
m_strBlockName=sBlockName;
|
|
|
|
return TRUE;
|
|
}
|
|
// 把最近的参数写入注册表
|
|
BOOL CDrawingList::WriteParamToRegistry()
|
|
{
|
|
XString sRegSubLoc, sRegLoc(1024);
|
|
BOOL bOk=GetRegLocation(sRegSubLoc);
|
|
if (!bOk)
|
|
return FALSE;
|
|
sRegLoc << ::GetRegLocation() << _T("\\Settings") ;
|
|
CRegProperty regProp(sRegLoc, sRegSubLoc);
|
|
regProp.SetTopRootKey(HKEY_CURRENT_USER);
|
|
regProp.SetValue(_T("TitleList"), m_strBlockName);
|
|
return TRUE;
|
|
}
|
|
|
|
////////////////////////////////////////////////////
|
|
// CDrawingListNext 对话框
|
|
|
|
IMPLEMENT_DYNAMIC(CDrawingListNext, CAcUiDialog)
|
|
CDrawingListNext::CDrawingListNext(WDGrid &grid, CWnd* pParent)
|
|
: CAcUiDialog(CDrawingListNext::IDD, pParent)
|
|
{
|
|
InitGrid();
|
|
long lRow = 0;
|
|
long lCount = grid.GetRowNum();
|
|
for(long i=0; i<lCount; i++)
|
|
{
|
|
TRowXData *pXD = (TRowXData*)grid.GetRow(i).GetExtendData();
|
|
CString szFileName = grid.GetCell(i, 0);
|
|
if (pXD == NULL)
|
|
continue;
|
|
|
|
long lDataNum = pXD->m_lstSpaces.GetDataNum();
|
|
for(long j=0; j<lDataNum; j++)
|
|
{
|
|
m_grid.AppendRow();
|
|
TDrawing *pDrawing = pXD->m_lstSpaces[j];
|
|
if (pDrawing == NULL)
|
|
continue;
|
|
|
|
CString szNumber;
|
|
szNumber.Format(_T("%d"), lRow+1);
|
|
m_grid.GetCell(lRow, 0).SetText(szNumber);
|
|
m_grid.GetCell(lRow, 1).SetText(pDrawing->m_sNo);
|
|
m_grid.GetCell(lRow, 2).SetText(pDrawing->m_sName);
|
|
m_grid.GetCell(lRow, 3).SetText(pDrawing->m_sPageSize);
|
|
m_grid.GetCell(lRow, 4).SetText(szFileName);
|
|
pDrawing = NULL;
|
|
lRow++;
|
|
}
|
|
pXD = NULL;
|
|
}
|
|
m_bInit = FALSE;
|
|
m_cxOldSize = 800;
|
|
m_cyOldSize = 600;
|
|
m_bCompositor = FALSE;
|
|
}
|
|
|
|
CDrawingListNext::~CDrawingListNext()
|
|
{
|
|
}
|
|
|
|
void CDrawingListNext::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CAcUiDialog::DoDataExchange(pDX);
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CDrawingListNext, CAcUiDialog)
|
|
ON_BN_CLICKED(IDC_RETURN, OnBnClickedReturn)
|
|
ON_WM_SIZE()
|
|
ON_WM_CREATE()
|
|
ON_BN_CLICKED(IDC_COMPOSITOR, OnBnClickedCompositor)
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
// CDrawingListNext 消息处理程序
|
|
BOOL CDrawingListNext::OnInitDialog()
|
|
{
|
|
CAcUiDialog::OnInitDialog();
|
|
m_grid.Create(this, IDC_DLIST);
|
|
m_grid.FitLastCol();
|
|
|
|
m_bInit = TRUE;
|
|
CRect rect;
|
|
GetClientRect(rect);
|
|
m_size.cx = rect.Width();
|
|
m_size.cy = rect.Height();
|
|
ResetSize(m_cxOldSize, m_cyOldSize);
|
|
return TRUE;
|
|
}
|
|
|
|
void CDrawingListNext::InitGrid()
|
|
{
|
|
m_grid.Clear();
|
|
m_grid.AppendCol(_T("序号"), 30);
|
|
m_grid.AppendCol(_T("图号"), 60);
|
|
m_grid.AppendCol(_T("图纸名称"), 270);
|
|
m_grid.AppendCol(_T("图幅"), 60);
|
|
m_grid.AppendCol(_T("所在文件"), 100);
|
|
m_grid.AppendCol(_T("备注"), 120);
|
|
m_grid.GetCol(0).SetReadOnly();
|
|
m_grid.GetCol(4).SetReadOnly();
|
|
m_grid.SetColPosFix();
|
|
m_grid.SetColFixLength();
|
|
m_grid.SetLabelSort();
|
|
}
|
|
|
|
void CDrawingListNext::ResetSize(int cxOld, int cyOld)
|
|
{
|
|
CRect rGrid, rRet, rCom, rOk, rCan;
|
|
m_grid.GetWindowRect(rGrid);
|
|
ScreenToClient(rGrid);
|
|
|
|
CWnd *pRet = GetDlgItem(IDC_RETURN);
|
|
pRet->GetWindowRect(rRet);
|
|
ScreenToClient(rRet);
|
|
|
|
CWnd *pCom = GetDlgItem(IDC_COMPOSITOR);
|
|
pCom->GetWindowRect(rCom);
|
|
ScreenToClient(rCom);
|
|
|
|
CWnd *pOk = GetDlgItem(IDOK);
|
|
pOk->GetWindowRect(rOk);
|
|
ScreenToClient(rOk);
|
|
|
|
CWnd *pCan = GetDlgItem(IDCANCEL);
|
|
pCan->GetWindowRect(rCan);
|
|
ScreenToClient(rCan);
|
|
|
|
long nIncX = m_size.cx - cxOld;
|
|
long nIncY = m_size.cy - cyOld;
|
|
m_grid.MoveWindow(rGrid.left, rGrid.top,
|
|
rGrid.Width() + nIncX, rGrid.Height() + nIncY);
|
|
m_grid.FitLastCol();
|
|
|
|
CRect rect;
|
|
GetClientRect(rect);
|
|
int iCenter = rect.left + m_size.cx/2;
|
|
int iButWid = rOk.Width();
|
|
pRet->MoveWindow(iCenter - int(2.75 * iButWid), rRet.top + nIncY,
|
|
rRet.Width(), rRet.Height());
|
|
pCom->MoveWindow(iCenter - int(1.25 * iButWid), rCom.top + nIncY,
|
|
rCom.Width(), rCom.Height());
|
|
pOk->MoveWindow(iCenter + int(0.25 * iButWid), rOk.top + nIncY,
|
|
rOk.Width(), rOk.Height());
|
|
pCan->MoveWindow(iCenter + int(1.75 * iButWid), rCan.top + nIncY,
|
|
rCan.Width(), rCan.Height());
|
|
}
|
|
|
|
void CDrawingListNext::OnSize(UINT nType, int cx, int cy)
|
|
{
|
|
if (m_bInit && (!nType || nType == SIZE_MAXIMIZED))
|
|
{
|
|
CSize sizeOld = m_size;
|
|
m_size.cx = cx;
|
|
m_size.cy = cy;
|
|
ResetSize(sizeOld.cx, sizeOld.cy);
|
|
}
|
|
}
|
|
|
|
int CDrawingListNext::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
|
{
|
|
if (CAcUiDialog::OnCreate(lpCreateStruct) == -1)
|
|
return -1;
|
|
|
|
CRect rect;
|
|
GetClientRect(rect);
|
|
m_cxOldSize = rect.Width();
|
|
m_cyOldSize = rect.Height();
|
|
|
|
return 0;
|
|
}
|
|
|
|
BOOL CDrawingListNext::GetSheet(TDbSheet *&pSheet)
|
|
{
|
|
AcDbObjectId idTextStyle = InitTextStyle(TS_STANDARD);
|
|
if (!idTextStyle)
|
|
{
|
|
acutPrintf(_T("\n初始化文字样式失败!"));
|
|
return FALSE;
|
|
}
|
|
|
|
pSheet->SetRotation(Ucs2Wcs(0.0));
|
|
const int iRow = m_grid.GetRowNum() + 1;
|
|
const int iCol = 5;
|
|
const double dColWidArray[iCol] = {15, 20, 90, 15, 40};
|
|
const TCHAR *svHeadArray[iCol] = {_T("序号"), _T("图号"), _T("图纸名称"), _T("图幅"), _T("备注")};
|
|
pSheet->InitSheet(iRow, iCol, 7.0, 14.0);
|
|
|
|
// 设置标题
|
|
TSheetTitle &title = pSheet->GetTitle();
|
|
title.SetHeight(7.0);
|
|
TGridStyle &gridStyleTitle = title.GetGridStyle();
|
|
gridStyleTitle.SetFlagBit(OF_TEXTHEIGHT);
|
|
gridStyleTitle.SetTextHeight(4.0);
|
|
TDividerStyle &dStyle = title.GetDividerStyle();
|
|
dStyle.SetDividerFlag(TDividerStyle::kLocal);
|
|
pSheet->SetTitleText(_T("图纸目录"));
|
|
|
|
// 设置项目名
|
|
TSheetColumn column;
|
|
int i, j;
|
|
for(i=0; i<iCol; i++)
|
|
{
|
|
column.SetWidth(dColWidArray[i]);
|
|
pSheet->SetColumnAt(i, column);
|
|
TGridCell *pCell = (*pSheet)(0, i);
|
|
pCell->SetText(svHeadArray[i]);
|
|
TGridStyle &gridStyleName = pCell->GetGridStyle();
|
|
gridStyleName.SetFlagBit(OF_TEXTHEIGHT);
|
|
gridStyleName.SetTextHeight(4.0);
|
|
}
|
|
|
|
// 添加内容
|
|
TGridStyle gridStyle;
|
|
gridStyle.SetOverrideAll(TRUE);
|
|
gridStyle.SetTextWrap(TRUE);
|
|
gridStyle.SetHorMode(AcDb::kTextCenter);
|
|
gridStyle.SetVerMode(AcDb::kTextVertMid);
|
|
gridStyle.SetFlagBit(OF_LINESPACE, TRUE);
|
|
gridStyle.SetLineSpaceFactor(0.5);
|
|
gridStyle.SetTextHeight(3.5);
|
|
gridStyle.SetTextStyleId(idTextStyle);
|
|
pSheet->SetGridStyle(gridStyle);
|
|
pSheet->SetRowHeightStyle(TSheetRow::kAutomatic);
|
|
|
|
for(i=1; i<iRow; i++)
|
|
{
|
|
pSheet->GetRow(i)->SetRowHeightStyle(TSheetRow::kAutomatic);
|
|
for(j=0; j<iCol; j++)
|
|
{
|
|
CString szText;
|
|
if (j <4)
|
|
szText = m_grid.GetCell(i-1, j).GetText();
|
|
else
|
|
szText = m_grid.GetCell(i-1, j+1).GetText();
|
|
|
|
if (j == 2)
|
|
szText.Replace(_T(";"), _T("\n"));
|
|
|
|
TGridCell *pCell = (*pSheet)(i, j);
|
|
if (pCell != NULL)
|
|
pCell->SetText(szText);
|
|
}
|
|
}
|
|
pSheet->CalculateRowHeight(0, pSheet->GetRowNum()-1);
|
|
return TRUE;
|
|
}
|
|
|
|
void CDrawingListNext::OnBnClickedReturn()
|
|
{
|
|
EndDialog(1000);
|
|
}
|
|
|
|
void CDrawingListNext::OnBnClickedCompositor()
|
|
{
|
|
long i;
|
|
long lRow = m_grid.GetRowNum();
|
|
m_grid.SelectCol(1);
|
|
m_grid.Arrange();
|
|
m_grid.SelectCol(1, false);
|
|
for(i=0; i<lRow; i++)
|
|
{
|
|
CString szCell = m_grid.GetCell(i, 0).GetText();
|
|
m_szArNo.Add(szCell);
|
|
TCHAR str[32];
|
|
_stprintf(str, _T("%d"), i+1);
|
|
m_grid.GetCell(i, 0).SetText(str);
|
|
}
|
|
}
|
|
|
|
void CDrawingListNext::OnOK()
|
|
{
|
|
BeginEditorCommand();
|
|
|
|
TDbSheet *pSheet = new TDbSheet;
|
|
GetSheet(pSheet);
|
|
if (!pSheet->IsValid())
|
|
{
|
|
delete pSheet;
|
|
acutPrintf(_T("\n不能生成图纸目录!"));
|
|
return;
|
|
}
|
|
|
|
XPoint ptLoc;
|
|
PickSet ss(SS_FREE);
|
|
ss.IncludeBegin();
|
|
pSheet->SetLocation(ptLoc);
|
|
pSheet->AddToCSpace(Adesk::kTrue);
|
|
pSheet = NULL;
|
|
ss.IncludeEnd();
|
|
|
|
int nRet = DragMovePickSet(ss, _T("\n请点取插入位置<返回>: "), XPoint(), XPoint());
|
|
if (nRet == RTNORM)
|
|
{
|
|
CAcUiDialog::OnOK();
|
|
}
|
|
else if (nRet == RTNONE)
|
|
{
|
|
ss.Delete();
|
|
CompleteEditorCommand();
|
|
}
|
|
else
|
|
{
|
|
ss.Delete();
|
|
CancelEditorCommand();
|
|
}
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
bool TSheetGrid::OnBeforeInsertRow(long i,WDGridRow*&pNewRow)
|
|
{
|
|
if (i>=m_nRowNum)
|
|
m_pSheet->AddRowAt(i);
|
|
else
|
|
return false;
|
|
return true;
|
|
}
|
|
bool TSheetGrid::OnBeforeDeleteRow()
|
|
{
|
|
for(long i=GetRowSelNum()-1;i>=0;i--)
|
|
{
|
|
long index=GetSelRow(i).GetIndex();
|
|
if (index<m_pSheet->GetRowNum()&&index>m_nRowNum)
|
|
m_pSheet->RemoveRow(index);
|
|
else
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void TSheetGrid::Read(TDbSheet*pSheet)
|
|
{
|
|
m_pSheet=pSheet;
|
|
|
|
Clear();
|
|
while(GetColNum()>0)
|
|
DelCol(0);
|
|
|
|
int nColumn=m_pSheet->GetColumnNum();
|
|
for(int i=0; i<nColumn; i++)
|
|
AppendCol(_T(""),AS_INT(m_pSheet->GetColumn(i)->GetWidth()*MM2PIXEL));
|
|
|
|
SetRowNum(m_pSheet->GetRowNum());
|
|
|
|
for(i=0;i<m_pSheet->GetRowNum();i++)
|
|
for(int j=0;j<m_pSheet->GetColumnNum();j++)
|
|
GetCell(i,j).SetText((*m_pSheet)(i,j)->GetText());
|
|
}
|
|
void TSheetGrid::Save()
|
|
{
|
|
m_pSheet->assertWriteEnabled();
|
|
if (m_pSheet->GetRowNum()<GetRowNum())
|
|
{
|
|
while(m_pSheet->GetRowNum()<GetRowNum())
|
|
m_pSheet->AddRowAt(m_pSheet->GetRowNum());
|
|
|
|
}
|
|
else
|
|
{
|
|
while(m_pSheet->GetRowNum()>GetRowNum())
|
|
m_pSheet->RemoveRow(m_pSheet->GetRowNum()-1);
|
|
}
|
|
|
|
if (m_pSheet->GetColumnNum()<GetColNum())
|
|
{
|
|
while(m_pSheet->GetColumnNum()<GetColNum())
|
|
m_pSheet->AddColumnAt(m_pSheet->GetColumnNum());
|
|
|
|
}
|
|
else
|
|
{
|
|
while(m_pSheet->GetColumnNum()>GetColNum())
|
|
m_pSheet->RemoveColumn(m_pSheet->GetColumnNum()-1);
|
|
}
|
|
|
|
for(long i=0;i<GetRowNum();i++)
|
|
for(long j=0;j<GetColNum();j++)
|
|
{
|
|
TGridCell*pCell=(*m_pSheet)(i,j);
|
|
pCell->SetText(GetCell(i,j).GetText());
|
|
}
|
|
}
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CGridSheetDlg dialog
|
|
IMPLEMENT_DYNAMIC(CGridSheetDlg, CAcUiDialog)
|
|
|
|
CGridSheetDlg::CGridSheetDlg(TDbSheet *pSheet, CWnd* pParent /*=NULL*/)
|
|
: CAcUiDialog(CGridSheetDlg::IDD, pParent)
|
|
{
|
|
m_pSheet=pSheet;
|
|
m_bInit=FALSE;
|
|
m_nOldSizeX=520;
|
|
m_nOldSizeY=380;
|
|
m_nRowNum=0;
|
|
}
|
|
|
|
void CGridSheetDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CAcUiDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CGridSheetDlg)
|
|
DDX_Control(pDX, IDC_GRID, m_grid);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CGridSheetDlg, CAcUiDialog)
|
|
//{{AFX_MSG_MAP(CGridSheetDlg)
|
|
ON_WM_SIZE()
|
|
ON_WM_CREATE()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
// CGridSheetDlg message handlers
|
|
//布置Grid的界面
|
|
void CGridSheetDlg::ConfigGrid()
|
|
{
|
|
if (!m_pSheet) return;
|
|
m_grid.m_nRowNum=m_nRowNum;
|
|
m_grid.Read(m_pSheet);
|
|
m_grid.SetColPosFix();
|
|
m_grid.SetColFixLength();
|
|
m_grid.SetNoPaste();
|
|
m_grid.SetModify(false);
|
|
}
|
|
|
|
BOOL CGridSheetDlg::PreTranslateMessage(MSG* pMsg)
|
|
{
|
|
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
|
|
{
|
|
OnOK();
|
|
return TRUE;
|
|
}
|
|
return CAcUiDialog::PreTranslateMessage(pMsg);
|
|
}
|
|
|
|
int intcmp(const int *i, const int *j)
|
|
{
|
|
if (*i < *j)
|
|
return -1;
|
|
else if (*i > *j)
|
|
return 1;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
|
|
void CGridSheetDlg::ResetSize()
|
|
{
|
|
CRect rectGrid, rectCancel, rectOk,rectNewStyle,rectOldStyle;
|
|
m_grid.GetWindowRect(rectGrid);
|
|
ScreenToClient(rectGrid);
|
|
CWnd *pCancel = GetDlgItem(IDCANCEL);
|
|
CWnd *pOk = GetDlgItem(IDOK);
|
|
pCancel->GetWindowRect(rectCancel);
|
|
ScreenToClient(rectCancel);
|
|
pOk->GetWindowRect(rectOk);
|
|
ScreenToClient(rectOk);
|
|
|
|
long nIncY = sizeDlg.cy - m_nOldSizeY; //380; // 对话框绝对尺寸
|
|
long nIncX = sizeDlg.cx - m_nOldSizeX; //520;
|
|
|
|
m_grid.MoveWindow(rectGrid.left, rectGrid.top,
|
|
rectGrid.Width() + nIncX, rectGrid.Height() + nIncY);
|
|
|
|
pCancel->MoveWindow(rectCancel.left, rectCancel.top + nIncY,
|
|
rectCancel.Width(), rectCancel.Height());
|
|
pOk->MoveWindow(rectOk.left, rectOk.top + nIncY,
|
|
rectOk.Width(), rectOk.Height());
|
|
}
|
|
|
|
void CGridSheetDlg::OnSize(UINT nType, int cx, int cy)
|
|
{
|
|
if (m_bInit && (!nType || nType==SIZE_MAXIMIZED)) {
|
|
CRect rectGrid;
|
|
m_grid.GetWindowRect(rectGrid);
|
|
ScreenToClient(rectGrid);
|
|
CSize sizeOld = sizeDlg;
|
|
sizeDlg.cx = cx;
|
|
sizeDlg.cy = cy;
|
|
|
|
CRect rectCancel, rectOk;
|
|
CWnd *pCancel = GetDlgItem(IDCANCEL);
|
|
CWnd *pOk = GetDlgItem(IDOK);
|
|
pCancel->GetWindowRect(rectCancel);
|
|
ScreenToClient(rectCancel);
|
|
pOk->GetWindowRect(rectOk);
|
|
ScreenToClient(rectOk);
|
|
|
|
long nIncY = sizeDlg.cy-sizeOld.cy;
|
|
long nIncX = sizeDlg.cx-sizeOld.cx;
|
|
m_grid.MoveWindow(rectGrid.left, rectGrid.top,
|
|
rectGrid.Width()+nIncX, rectGrid.Height()+nIncY);
|
|
|
|
pCancel->MoveWindow(rectCancel.left, rectCancel.top + nIncY,
|
|
rectCancel.Width(), rectCancel.Height());
|
|
pOk->MoveWindow(rectOk.left, rectOk.top + nIncY,
|
|
rectOk.Width(), rectOk.Height());
|
|
}
|
|
|
|
}
|
|
|
|
void CGridSheetDlg::OnOK()
|
|
{
|
|
if (m_grid.IsModified())
|
|
m_grid.Save();
|
|
|
|
CAcUiDialog::OnOK();
|
|
}
|
|
|
|
extern BOOL StringAnalysis(const TCHAR *src, XString &sPrefix, int *num, int *numWidth);
|
|
|
|
|
|
int CGridSheetDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
|
{
|
|
if (CAcUiDialog::OnCreate(lpCreateStruct) == -1)
|
|
return -1;
|
|
|
|
CRect rect;
|
|
GetClientRect(rect);
|
|
m_nOldSizeX=rect.Width();
|
|
m_nOldSizeY=rect.Height();
|
|
return 0;
|
|
}
|
|
|
|
BOOL CGridSheetDlg::OnInitDialog() //modified by whl
|
|
{
|
|
CAcUiDialog::OnInitDialog();
|
|
|
|
m_grid.Create(this,IDC_GRID);
|
|
|
|
m_bInit=TRUE;
|
|
CRect rectDlg;
|
|
GetClientRect(rectDlg);
|
|
sizeDlg.cx = rectDlg.Width();
|
|
sizeDlg.cy = rectDlg.Height();
|
|
ResetSize();
|
|
if (m_pSheet)
|
|
ConfigGrid();
|
|
return TRUE;
|
|
}
|