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

883 lines
23 KiB
C++

// GridFormView.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "GridView.h"
#include "GridFormView.h"
#include "GridDocument.h"
//#include "FormSetDlg.h"
#include "GridFrameWnd.h"
#include "dbgroup.h"
#include "TgAs.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static const TCHAR *sMsgPrompt[]={
#include "GridFormView.hpp"
};
class XDbContentRec {
public:
XString m_sTableName, m_sFieldName, m_sFieldDesc;
public:
XDbContentRec(const TCHAR *tn, const TCHAR *fn, const TCHAR *fd):
m_sTableName(tn), m_sFieldName(fn), m_sFieldDesc(fd)
{}
XDbContentRec() {}
};
class XDbContentTable: public DList<XDbContentRec> {
public:
XDbContentTable();
XDbContentRec * LookUp(const TCHAR *tn, const TCHAR *fn);
};
XDbContentTable::XDbContentTable()
{
XString sFile;
if (!FindFile(_T("dbconten.dbf"), sFile))
return;
CodeBase db;
XDbfTable *pTable=db.Open(sFile);
if (!pTable)
return;
for(pTable->MoveFirst(); !pTable->IsEOF(); pTable->MoveNext())
{
// sg modify 100825,解决64位移植后的BUG,强制转换后,数据为空
CString sTableName, sFieldName, sFieldDesc;
XDbContentRec *pRec = new XDbContentRec;
// Zyu modify on 100721,添加强制转换
//GET_FIELD(pTable, _T("tablename"), pRec->m_sTableName);
//GET_FIELD(pTable, _T("fieldname"), pRec->m_sFieldName);
//GET_FIELD(pTable, _T("fielddesc"), pRec->m_sFieldDesc);
GET_FIELD(pTable, _T("tablename"), sTableName);
GET_FIELD(pTable, _T("fieldname"), sFieldName);
GET_FIELD(pTable, _T("fielddesc"), sFieldDesc);
sTableName = pRec->m_sTableName;
sFieldName = pRec->m_sFieldName;
sFieldDesc = pRec->m_sFieldDesc;
Append(pRec);
}
}
XDbContentRec * XDbContentTable::LookUp(const TCHAR *tn, const TCHAR *fn)
{
for(int i=0; i<Length(); i++) {
XDbContentRec *pRec=(*this)[i];
if (_tcsicmp(pRec->m_sTableName, tn)==0 &&
_tcsicmp(pRec->m_sFieldName, fn)==0)
return pRec;
}
return NULL;
}
// modify by xlc on 090902 消除tg5lib影响
//#if ADS<18
#if 0
/////////////////////////////////////////////////////////////////////////////
// CGridFormView
IMPLEMENT_DYNCREATE(CGridFormView, CGridView)
CGridFormView::CGridFormView()
: CGridView(CGridFormView::IDD)
{
m_bEnable=TRUE;
m_pFormSetDlg=NULL;
m_ColorSelect=RGB(0,0,255);
double nSize=3.5; //GetTextSize(DS_CHINA);
m_nHeadTxtSize=m_nConTxtSize=nSize;
m_nTitTxtSize=1.5*nSize;
m_nHeadRowHeight=m_nConRowHeight=2*nSize;
m_sTitleName=_T("");
//{{AFX_DATA_INIT(CGridFormView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
CGridFormView::~CGridFormView()
{
}
void CGridFormView::DoDataExchange(CDataExchange* pDX)
{
CGridView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CGridFormView)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CGridFormView, CGridView)
//{{AFX_MSG_MAP(CGridFormView)
ON_WM_SIZE()
ON_COMMAND(IDM_INSERTDBF, OnInsertdbf)
ON_UPDATE_COMMAND_UI(IDM_INSERTDBF, OnUpdateInsertdbf)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGridFormView diagnostics
#ifdef _DEBUG
void CGridFormView::AssertValid() const
{
CGridView::AssertValid();
}
void CGridFormView::Dump(CDumpContext& dc) const
{
CGridView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGridFormView message handlers
XDbfTable *CGridFormView::OpenDbfTable() // override member from CGridView
{
XString sFileSp(256);
CGridDocument *pDoc=(CGridDocument *)GetDocument();
ASSERT(pDoc);
XDbfTable *pData=m_db.Open(pDoc->GetPathName());
if (!pData)
return NULL;
XString sTableKey;
pDoc->GetDbfTableKey(sTableKey);
XDbContentTable contentTab;
FieldInfo *pFieldArray = pData->GetFieldInfo();
int nColumn = pData->GetFieldNum();
m_lstHeadInfo.Reset();
for(int i=0; i<nColumn; i++) {
XString sFieldDesc;
sFieldDesc=pFieldArray[i].name;
if (!!sTableKey) {
XDbContentRec *pRec = contentTab.LookUp(sTableKey, sFieldDesc);
if (pRec) sFieldDesc=pRec->m_sFieldDesc;
}
int nWidthOfHead=max(pFieldArray[i].len, _tcslen(sFieldDesc));
m_lstHeadInfo.Append(new CFieldHead(TString(pFieldArray[i].name),
sFieldDesc, min(100, max(30, short(5*nWidthOfHead)))));
m_lstAlignMode.Append(new int(dbgLeft));
m_lstIsSelect.Append(new int(0));
m_lstColumnWidth.Append(new double(0));
}
FieldInfo::ReleaseArray(pFieldArray);
return pData;
}
void CGridFormView::OnInitialUpdate()
{
CGridView::OnInitialUpdate();
UpdateColumnWidth();
}
void CGridFormView::OnSize(UINT nType, int cx, int cy)
{
CGridView::OnSize(nType, cx, cy);
if ( ::IsWindow(m_grid.m_hWnd) )
m_grid.SetWindowPos( NULL, 0, 0, cx, cy,SWP_SHOWWINDOW);
}
void CGridFormView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
GetBookmarks(TRUE);
m_grid.ReBind();
}
BEGIN_EVENTSINK_MAP(CGridFormView, CGridView)
//{{AFX_EVENTSINK_MAP(CGridFormView)
ON_EVENT(CGridFormView, IDC_GRID, -603 /* KeyPress */, OnKeyPressGrid, VTS_PI2)
ON_EVENT(CGridFormView, IDC_GRID, 10 /* HeadClick */, OnHeadClickGrid, VTS_I2)
ON_EVENT(CGridFormView, IDC_GRID, 9 /* ColResize */, OnColResizeGrid, VTS_I2 VTS_PI2)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CGridFormView::OnKeyPressGrid(short FAR* KeyAscii)
{
if (*KeyAscii == VK_RETURN) {
m_grid.Update();
} else if (*KeyAscii==VK_DELETE) {
}
}
void CGridFormView::OnHeadClickGrid(short ColIndex)
{
//本事件功能: 单击列头时,若该列的背景色是蓝色,则背景色切换成白色,
//前景色切换成黑色; 否则背景色切换成蓝色,前景色切换成白色
short Cret=GetKeyState(VK_CONTROL);
short Sret=GetKeyState(VK_SHIFT);
if (Cret==(short)0xff81 || Cret==(short)0xff80) { //CTRL+Left Mouse
CColumn Coli=m_grid.GetColumns().GetItem(ColIndex);
if (m_ColorSelect==Coli.GetBackColor()) {
Coli.SetBackColor(RGB(255,255,255));
Coli.SetForeColor(RGB(0,0,0));
*m_lstIsSelect[ColIndex]=0;
}
else {
Coli.SetBackColor(m_ColorSelect);
Coli.SetForeColor(RGB(255,255,255));
*m_lstIsSelect[ColIndex]=1;
}
double nMinWidth=0,nTotalWidth=0;
CalculateWidth(nMinWidth,nTotalWidth);
/*
if (m_pFormSetDlg) {
int nAlignMode=GetAlignMode();
CFormSetDlg* pFormSetDlg=(CFormSetDlg*)m_pFormSetDlg;
pFormSetDlg->UpdateDisplay(nMinWidth,nTotalWidth);
pFormSetDlg->UpdateAlignMode(nAlignMode);
}*/
}
else if (Sret==(short)0xff81 || Sret==(short)0xff80) { //SHIFT+Left Mouse
int& AlignMode=*m_lstAlignMode[ColIndex];
switch (AlignMode) {
case dbgLeft:
AlignMode=dbgCenter;
break;
case dbgCenter:
AlignMode=dbgRight;
break;
case dbgRight:
AlignMode=dbgLeft;
break;
}
CColumn Coli=m_grid.GetColumns().GetItem(ColIndex);
Coli.SetAlignment(AlignMode);
Coli.SetHeadAlignment(dbgCenter);
/*
if (m_pFormSetDlg) {
int nAlignMode=GetAlignMode();
CFormSetDlg* pFormSetDlg=(CFormSetDlg*)m_pFormSetDlg;
pFormSetDlg->UpdateAlignMode(nAlignMode);
}*/
}
else
CGridView::OnHeadClickMatgrid(ColIndex);
}
void CGridFormView::OnColResizeGrid(short ColIndex, short FAR* Cancel)
{
UpdateColumnWidth();
if (!m_bEnable) {
double nMinWidth=0,nTotalWidth=0;
CalculateWidth(nMinWidth,nTotalWidth);
/*
if (m_pFormSetDlg) {
CFormSetDlg* pFormSetDlg=(CFormSetDlg*)m_pFormSetDlg;
pFormSetDlg->UpdateDisplay(nMinWidth,nTotalWidth);
}*/
}
}
BOOL CGridFormView::PreTranslateMessage(MSG* pMsg)
{
if (m_grid.IsSpecialKey(pMsg))
return TRUE;
else if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_DELETE) {
BOOL bRet=FALSE;
{
CTrueDBGrid50_SelBookmarks bmks = m_grid.GetSelBookmarks();
int nCount=bmks.GetCount();
if (nCount>1) {
for( int i=0; i<nCount; i++ ) {
COleVariant vBmk = bmks.GetItem(i);
ASSERT( V_VT(&vBmk) == VT_I4 );
OnUnboundDeleteRowMatgrid(&vBmk);
}
bRet=TRUE;
}
}
if (bRet) {
if ( m_lstBookmarks.Length()>0 ) {
m_grid.SetBookmark( COleVariant(*m_lstBookmarks[0]) );
} else {
COleVariant vNull;
vNull.ChangeType( VT_NULL );
m_grid.SetBookmark( vNull );
}
m_grid.ReBind();
return bRet;
}
}
return CGridView::PreTranslateMessage(pMsg);
}
//extern int ReadDbfAndDraw(const TCHAR *szFile, BOOL bSort, int nSortField, BOOL bAscend);
// 在当前图中绘制
void CGridFormView::UpdateAlignMode(int nAlignMode)
{
BOOL bIsSelect=IsSelect();
int len=m_lstHeadInfo.Length();
for(int i=0;i<len;i++) {
if (*m_lstIsSelect[i] || !bIsSelect) {
CColumn column=m_grid.GetColumns().GetItem(i);
*m_lstAlignMode[i]=nAlignMode;
column.SetAlignment(nAlignMode);
column.SetHeadAlignment(dbgCenter);
}
}
}
void CGridFormView::UpdateColumnWidth()
{
int len=m_lstHeadInfo.Length();
for(int i=0;i<len;i++) {
CColumn column = m_grid.GetColumns().GetItem(i);
float nw=column.GetWidth();
BOOL bVis=column.GetVisible();
if (nw<=5.0 || !bVis) nw=0;
*m_lstColumnWidth[i]=nw;
}
}
BOOL CGridFormView::IsSelect()
{
BOOL bIsSelect=FALSE;
int len=m_lstIsSelect.Length();
for(int i=0;i<len;i++) {
if (*m_lstIsSelect[i]) {
bIsSelect=TRUE;
break;
}
}
return bIsSelect;
}
int CGridFormView::GetAlignMode()
{
int nAlignMode=0;
BOOL bIsSelect=IsSelect();
int len=m_lstAlignMode.Length();
for(int i=0,j=0;i<len;i++) {
if (*m_lstIsSelect[i] || !bIsSelect) {
if (!j) {
nAlignMode=*m_lstAlignMode[i];
j++;
}
if (nAlignMode != *m_lstAlignMode[i]) {
nAlignMode=-1;
break;
}
}
}
return nAlignMode;
}
void CGridFormView::CalculateTextWidth(int nColumnIndex,double& nMaxLen,double& nHeadLen)
{
nMaxLen=nHeadLen=0;
double nHeight,nWidth;
int len=m_lstBookmarks.Length();
AcDbObjectId textId=InitTextStyle(TS_STANDARD);
ASSERT(nColumnIndex<m_lstHeadInfo.Length());
for(int i=0;i<len+1;i++) {
XString sContent;
AcDbMText mText;
if (i<len) {
long bookMark=(*m_lstBookmarks[i]);
m_pTable->MoveTo(bookMark);
GET_FIELD(m_pTable, m_lstHeadInfo[nColumnIndex]->m_sName, sContent);
nHeight=m_nConTxtSize;
}
else {
sContent=m_lstHeadInfo[nColumnIndex]->m_sDesc;
nHeight=m_nHeadTxtSize;
}
mText.setTextStyle(textId);
mText.setTextHeight(nHeight);
mText.setContents(sContent);
nWidth=mText.actualWidth()+0.4*nHeight;
if (i==len) nHeadLen=nWidth;
if (nMaxLen<nWidth) nMaxLen=nWidth;
}
}
void CGridFormView::CalculateWidth(double& nMinWidth,double& nTotalWidth)
{
double nHeight,nWidth;
nMinWidth=nTotalWidth=0;
BOOL bIsSelect=IsSelect();
int len=m_lstHeadInfo.Length();
for(int i=0;i<len;i++) {
if (*m_lstIsSelect[i] || !bIsSelect) {
double nMaxLen=0,nHeadLen=0;
double nw=*m_lstColumnWidth[i];
if (nw>1) {
CalculateTextWidth(i,nMaxLen,nHeadLen);
nMinWidth+=nMaxLen;
if (fabs(nMaxLen-nHeadLen)<1.0E-6) nHeight=m_nHeadTxtSize;
else nHeight=m_nConTxtSize;
nWidth=nMaxLen > nw*nHeight/9.0 ? nMaxLen : nw*nHeight/9.0;
nTotalWidth+=nWidth;
}
}
}
}
void CGridFormView::CalculateWidth(DList<double>& lstColumnSize,DList<int>& lstAlignMode,
DList<CFieldHead>& lstHeadInfo,double& nMinWidth,
double& nTotalWidth)
{
double nHeight,nWidth;
nMinWidth=nTotalWidth=0;
BOOL bIsSelect=IsSelect();
int len=m_lstHeadInfo.Length();
if (lstColumnSize.Length()) lstColumnSize.Reset();
if (lstAlignMode.Length()) lstAlignMode.Reset();
if (lstHeadInfo.Length()) lstHeadInfo.Reset();
for(int i=0;i<len;i++) {
if (*m_lstIsSelect[i] || !bIsSelect) {
double nMaxLen=0,nHeadLen=0;
double nw=*m_lstColumnWidth[i];
lstAlignMode.Append(new int(*m_lstAlignMode[i]));
lstHeadInfo.Append(new CFieldHead(*m_lstHeadInfo[i]));
if (nw>1) {
CalculateTextWidth(i,nMaxLen,nHeadLen);
nMinWidth+=nMaxLen;
if (fabs(nMaxLen-nHeadLen)<1.0E-6) nHeight=m_nHeadTxtSize;
else nHeight=m_nConTxtSize;
nWidth=nMaxLen > nw*nHeight/9.0 ? nMaxLen : nw*nHeight/9.0;
nTotalWidth+=nWidth;
}
else nWidth=nw;
lstColumnSize.Append(new double(nWidth));
}
}
}
void CGridFormView::ArrangeWidth(DList<double>& lstColumnSize,double nMinWidth,
double& nTotalWidth,double nTotal)
{
if (fabs(nTotal-nTotalWidth) > 1.0E-6) {
BOOL bNext=FALSE;
BOOL bIsSelect=IsSelect();
double nFactor=nTotal/nTotalWidth;
int len=m_lstHeadInfo.Length();
int lenc=lstColumnSize.Length();
for(int i=0,j=0;i<len;i++) {
if (*m_lstIsSelect[i] || !bIsSelect) {
ASSERT(j<lenc);
double nMaxLen=0,nHeadLen=0;
double nSize=*lstColumnSize[j++]; //
if (nSize>1) {
CalculateTextWidth(i,nMaxLen,nHeadLen);
if (nSize*nFactor < nMaxLen) { //
bNext=TRUE;
break;
}
}
}
}
if (bNext) nFactor=nTotal/nMinWidth;
for(i=0,j=0;i<len;i++) {
if (*m_lstIsSelect[i] || !bIsSelect) {
ASSERT(j<lenc);
double& nSize=*lstColumnSize[j++]; //
if (bNext) {
double nMaxLen=0,nHeadLen=0;
if (nSize>1) {
CalculateTextWidth(i,nMaxLen,nHeadLen); //
nSize=nFactor*nMaxLen;
}
}
else nSize*=nFactor;
}
}
nTotalWidth=nTotal;
}
}
void CGridFormView::OnInsertdbf()
{
acedPostCommand(_T("InsertDbf\n"));
}
AcDbObjectId CGridFormView::AddToModelSpace(AcDbEntity *pEntity)
{
AcDbObjectId nId=AcDbObjectId::kNull;
XDbBlockTableRec mspace(ACDB_MODEL_SPACE, AcDb::kForWrite);
if (!!mspace) {
AcDbBlockTableRecord &rec=mspace;
rec.appendAcDbEntity(nId,pEntity);
pEntity->close();
}
return nId;
}
AcDbObjectId CGridFormView::AddTextToModelSpace(XString sDesc,AcDbObjectId nTextId,double nHeight,
AcDb::TextHorzMode nHorzMode,AcGePoint3d pt,
AcDbTextStyleTableRecord* pTextStyle)
{
AcDbText* pText = new AcDbText;
pText->setTextString(sDesc);
pText->setTextStyle(nTextId);
pText->setHeight(nHeight);
pText->setPosition(pt);
pText->setHorizontalMode(nHorzMode);
pText->setAlignmentPoint(pt);
if (pTextStyle) {
pText->setWidthFactor(pTextStyle->xScale());
pText->setOblique(pTextStyle->obliquingAngle());
}
return AddToModelSpace(pText);
}
void CGridFormView::AddToGroupDict(const TCHAR* sGroupName,AcDbObjectIdArray idArray)
{
AcDbObjectId nID;
int nCount=0,iMax=0;
CString MaxItem,pName;
int nNum=_tcslen(sGroupName);
AcDbDictionary* pGroupDict=NULL;
acdbCurDwg()->getGroupDictionary(pGroupDict, AcDb::kForWrite);
AcDbDictionaryIterator* pDictIter = pGroupDict->newIterator();
for(; !pDictIter->done(); pDictIter->next()) {
pName = pDictIter->name();
if (!pName.Find(sGroupName) && _ttoi(pName.Right(pName.GetLength()-nNum))) {
if (MaxItem < pName) MaxItem = pName;
}
}
delete pDictIter;
if (pName.GetLength() == (nNum + 1)) iMax = _ttoi(pName.Right(1))*10;
else if (!pName.IsEmpty()) iMax = _ttoi(pName.Right(pName.GetLength()-nNum));
pName.Format(_T("%d"),++iMax);
pName = sGroupName + pName;
AcDbGroup* pGroup=new AcDbGroup;
pGroupDict->setAt(pName,pGroup,nID);
pGroupDict->close();
int len=idArray.length();
for(int i=0;i<len;i++) pGroup->append(idArray[i]);
pGroup->setSelectable(Adesk::kTrue);
pGroup->close();
}
void CGridFormView::EnableOtherGridFrame(BOOL bEnable /*=TRUE*/)
{
CWnd* pWnd=NULL;
CMDIFrameWnd* pFrame=acedGetAcadFrame();
CWnd* pClient=CWnd::FromHandle(pFrame->m_hWndMDIClient);
pWnd=pClient->GetWindow(GW_CHILD);
while(pWnd->GetSafeHwnd()) {
if (pWnd->IsKindOf(RUNTIME_CLASS(CGridFrameWnd))) {
if (pWnd->GetSafeHwnd()!=this->GetParentFrame()->GetSafeHwnd())
pWnd->EnableWindow(bEnable);
}
pWnd=pWnd->GetWindow(GW_HWNDNEXT);
}
}
int CGridFormView::ArrangeWindow()
{
CRect rect;
double nTotalLen=0;
int nColLen,nType,nPos;
nColLen=m_lstColumnWidth.Length();
for(int i=0;i<nColLen;i++) nTotalLen+=*m_lstColumnWidth[i];
CMDIFrameWnd* pFrameWnd=acedGetAcadFrame();
CWnd* pClient=CWnd::FromHandle(pFrameWnd->m_hWndMDIClient);
pClient->GetWindowRect(rect);
if (nTotalLen>0.8*rect.Width()) {
nPos=1;
nType=MDITILE_HORIZONTAL;
}
else {
nPos=0;
nType=MDITILE_VERTICAL;
}
pFrameWnd->MDITile(nType|MDITILE_SKIPDISABLED);
CView *pView=acedGetAcadDwgView();
CFrameWnd *pDwgFrame=pView->GetParentFrame();
pDwgFrame->ActivateFrame();
return nType;
}
void CGridFormView::Insertdbf()
{
#if 0
EnableOtherGridFrame(FALSE);
int nPos=ArrangeWindow();
TCHAR ch[2];
ch[0]=(TCHAR)'\x1B';
ch[1]=(TCHAR)'\0';
int nRowNum,nColNum,nOutColNum,nAlignMode,i,j;
XPoint ptPick,pt,pt1,pt2;
nRowNum=m_lstBookmarks.Length();
nColNum=m_lstHeadInfo.Length();
double nMinWidth=0,nTotalWidth=0,nTotalHeight=0,nHeight,w,scale=1;
AcDbObjectId textId=InitTextStyle(TS_STANDARD);
XDbObject objTextStyle(textId, AcDb::kForRead);
AcDbTextStyleTableRecord *pTextStyle = AcDbTextStyleTableRecord::cast(objTextStyle.m_pObject);
DList<int> lstAlignMode;
DList<double> lstColumnSize;
DList<CFieldHead> lstHeadInfo;
CalculateWidth(lstColumnSize,lstAlignMode,lstHeadInfo,nMinWidth,nTotalWidth);
nOutColNum=lstHeadInfo.Length();
for(i=0;i<nOutColNum;i++) {
if (!i) nAlignMode=*lstAlignMode[i];
if (nAlignMode != *lstAlignMode[i]) {
nAlignMode=-1;
break;
}
}
CFormSetDlg FormSetDlg(nAlignMode,nPos,m_nTitTxtSize,m_nHeadTxtSize,m_nHeadRowHeight,
m_nConTxtSize,m_nConRowHeight,nMinWidth,nTotalWidth,this);
FormSetDlg.Create(FormSetDlg.IDD,this);
m_pFormSetDlg=&FormSetDlg;
m_bEnable=FALSE; //禁止重复执行本命令
while(1) {
int ret=XGetPoint(NULL,_T("\n请指定表格的左上角"),ptPick);
if (ret==RTNORM) break;
else if (ret==RTNONE) {
if (m_pFormSetDlg) {
m_bEnable=TRUE;
FormSetDlg.DestroyWindow();
m_pFormSetDlg=NULL;
acedPostCommand(ch);
EnableOtherGridFrame();
}
return;
}
}
m_bEnable=TRUE;
FormSetDlg.UpdateFromDialog(m_nTitTxtSize,m_nHeadTxtSize,m_nHeadRowHeight,m_nConTxtSize,
m_nConRowHeight,nTotalWidth,m_sTitleName);
FormSetDlg.DestroyWindow();
m_pFormSetDlg=NULL;
lstHeadInfo.Reset();
lstAlignMode.Reset();
lstColumnSize.Reset();
double nTotalWd=nTotalWidth;
CalculateWidth(lstColumnSize,lstAlignMode,lstHeadInfo,nMinWidth,nTotalWidth);
nOutColNum=lstHeadInfo.Length();
nTotalHeight=m_nConRowHeight*nRowNum+m_nHeadRowHeight;
ArrangeWidth(lstColumnSize,nMinWidth,nTotalWidth,nTotalWd); // 处理用户自定义表格总宽
//开始画表格
//画表格线
pt1=ptPick;pt2=ptPick;
pt2.y-=nTotalHeight;
AcDbObjectIdArray idArray;
idArray.append(AddToModelSpace(new AcDbLine(pt1, pt2)));
for(i=0;i<nOutColNum;i++) {//列数
w=*lstColumnSize[i];
if (w<_DIST_SNAP)
continue;
pt1.x+=w;
pt2.x+=w;
idArray.append(AddToModelSpace(new AcDbLine(pt1, pt2)));
}
pt1=ptPick;pt2=ptPick;
pt2.x+=nTotalWidth;
idArray.append(AddToModelSpace(new AcDbLine(pt1, pt2)));
for(i=0;i<nRowNum+1;i++) {//行数
if (!i) nHeight=m_nHeadRowHeight;
else nHeight=m_nConRowHeight;
pt1.y-=nHeight;
pt2.y-=nHeight;
idArray.append(AddToModelSpace(new AcDbLine(pt1, pt2)));
}
//写文字
pt.x=ptPick.x+nTotalWidth/2; //标题居中显示
pt.y+=ptPick.y+m_nTitTxtSize;
idArray.append(AddTextToModelSpace(m_sTitleName,textId,m_nTitTxtSize,AcDb::kTextCenter,
(AcGePoint3d)pt,pTextStyle));
pt.x=ptPick.x; //表头居中显示
pt.y=ptPick.y-m_nHeadRowHeight*0.5-m_nHeadTxtSize*0.5;
for(i=0;i<nOutColNum;i++) {
pt.x+=*lstColumnSize[i]/2;
if (*lstColumnSize[i]<_DIST_SNAP)
continue;
idArray.append(AddTextToModelSpace(lstHeadInfo[i]->m_sDesc,textId,m_nHeadTxtSize,AcDb::kTextCenter,
(AcGePoint3d)pt,pTextStyle));
pt.x+=*lstColumnSize[i]/2;
}
double nSpace=0.2*m_nConTxtSize;
for(i=0;i<nRowNum;i++) {//行数
pt.x=ptPick.x;
pt.y=ptPick.y-m_nHeadRowHeight-m_nConRowHeight*(i+0.5)-m_nConTxtSize*0.5;
long bookMark=(*m_lstBookmarks[i]);
m_pTable->MoveTo(bookMark);
for(j=0;j<nOutColNum;j++) {//列数
AcDb::TextHorzMode hMode;
if (*lstColumnSize[j]<_DIST_SNAP)
continue;
switch (*lstAlignMode[j]) {
case dbgLeft:
pt.x+=nSpace;
hMode=AcDb::kTextLeft;
break;
case dbgCenter:
pt.x+=*lstColumnSize[j]/2;
hMode=AcDb::kTextCenter;
break;
case dbgRight:
pt.x+=*lstColumnSize[j];
pt.x-=nSpace;
hMode=AcDb::kTextRight;
break;
}
XString sContent;
GET_FIELD(m_pTable, lstHeadInfo[j]->m_sName, sContent);
idArray.append(AddTextToModelSpace(sContent,textId,m_nConTxtSize,hMode,(AcGePoint3d)pt,pTextStyle));
switch (*lstAlignMode[j]) {
case dbgLeft:
pt.x-=nSpace;
pt.x+=*lstColumnSize[j];
break;
case dbgCenter:
pt.x+=*lstColumnSize[j]/2;
break;
case dbgRight:
pt.x+=nSpace;
break;
}
}
}
AddToGroupDict(_T("FORM"),idArray);
acedPostCommand(ch);
EnableOtherGridFrame();
#endif
}
void CGridFormView::OnUpdateInsertdbf(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bEnable);
}
void CGridFormView::OnDestroy()
{
if (m_pFormSetDlg->GetSafeHwnd()) {
m_pFormSetDlg->DestroyWindow();
m_pFormSetDlg=NULL;
EnableOtherGridFrame();
}
if (!m_bEnable) acedPostCommand(_T("\n")); //终止本命令
CGridView::OnDestroy();
}
//extern CUIntArray g_tempFileIndexArray;
void CGridFormView::PostNcDestroy()
{
CGridDocument *pDoc=(CGridDocument*)GetDocument();
ASSERT(pDoc);
CString szFileName, szFilePath;
szFilePath = pDoc->GetPathName();
int nEnd = szFilePath.ReverseFind('\\');
if (nEnd != -1) szFileName = szFilePath.Right(szFilePath.GetLength() - nEnd - 1);
else szFileName = szFilePath;
if (szFileName.Find('~') != -1 && szFileName.Find('$') != -1) {
if (FindFile(szFilePath)) {
m_pTable->Close();
_tremove(szFilePath);
/* CString szString = szFileName.Right(7);
int nCurIndex = _ttoi(szString.Left(4)) - 2000;
int nSize = g_tempFileIndexArray.GetSize();
if (nSize >= 1) {
if (nSize > 1) g_tempFileIndexArray.InsertAt(nSize - 1, nCurIndex);
else {
int nMaxIndex = g_tempFileIndexArray[0];
if (nCurIndex <= nMaxIndex - 1) {
if (nCurIndex == nMaxIndex - 1 && nMaxIndex > 1) g_tempFileIndexArray[0]--;
else g_tempFileIndexArray.InsertAt(0, nCurIndex);
}
}
}
nSize = g_tempFileIndexArray.GetSize();
for (int i = 0, k ; i < nSize ; i++) {
k = i;
for (int j = i + 1 ; j < nSize ; j++) {
if (g_tempFileIndexArray[k] > g_tempFileIndexArray[j]) k = j;
}
if (k != i) {
int temp = g_tempFileIndexArray[k];
g_tempFileIndexArray[k] = g_tempFileIndexArray[i];
g_tempFileIndexArray[i] = temp;
}
}
if (nSize > 1 && nSize == int(g_tempFileIndexArray[nSize - 1])) {
g_tempFileIndexArray.SetSize(1);
g_tempFileIndexArray[0] = 1;
}*/
}
}
CGridView::PostNcDestroy();
}
#endif
void InsertDbf()
{
CWnd* pWnd=NULL;
CMDIFrameWnd* pFrame=acedGetAcadFrame();
CWnd* pClient=CWnd::FromHandle(pFrame->m_hWndMDIClient);
pWnd=pClient->GetWindow(GW_CHILD);
if (pWnd->IsKindOf(RUNTIME_CLASS(CGridFrameWnd))) {
pWnd=pWnd->GetWindow(GW_CHILD);
}
else {
while(pWnd=pWnd->GetWindow(GW_HWNDNEXT)) {
if (pWnd->IsKindOf(RUNTIME_CLASS(CGridFrameWnd))) {
pWnd=pWnd->GetWindow(GW_CHILD);
break;
}
}
}
// modify by xlc on 090902 消除tg5lib影响
//#if ADS<18
#if 0
if (pWnd && pWnd->IsKindOf(RUNTIME_CLASS(CGridFormView))) {
CGridFormView* pFormView=(CGridFormView*)pWnd;
pFormView->Insertdbf();
}
#else
AfxMessageBox(_T("此处有问题,InsertDbf"));
#endif
}