396 lines
8.8 KiB
C++
396 lines
8.8 KiB
C++
// CellBlockDlg.cpp : implementation file
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "resource.h"
|
|
#include "CCellBlockDlg.h"
|
|
#include "rxregsvc.h "
|
|
|
|
Adesk::Boolean acedPostCommand(const TCHAR * );
|
|
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
BOOL CCellBlockDlg::m_bAutoSize=TRUE;
|
|
BOOL CCellBlockDlg::m_bUniScale=TRUE;
|
|
BOOL CCellBlockDlg::m_bShowAttr=FALSE;
|
|
BOOL CCellBlockDlg::m_bEqualSide=FALSE;
|
|
|
|
CCellBlockDlg::CCellBlockDlg(CWnd* pParent /*=NULL*/)
|
|
: CModelessDialog(CCellBlockDlg::IDD, pParent)
|
|
, m_PreviewDb(true,true)
|
|
{
|
|
//{{AFX_DATA_INIT(CCellBlockDlg)
|
|
m_strBlockName =_T("");
|
|
//}}AFX_DATA_INIT
|
|
if (pParent)
|
|
{
|
|
m_bModeless = TRUE;
|
|
}
|
|
else
|
|
{
|
|
m_bModeless = FALSE;
|
|
}
|
|
|
|
m_bLibBlk=FALSE;
|
|
m_nFlag=0;
|
|
}
|
|
|
|
void CCellBlockDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CModelessDialog::DoDataExchange(pDX);
|
|
//{{AFX_DATA_MAP(CCellBlockDlg)
|
|
DDX_Check(pDX, IDC_CHECK_AUTOSIZE, m_bAutoSize);
|
|
DDX_Check(pDX,IDC_CHECK_UNISCALE,m_bUniScale);
|
|
DDX_Check(pDX,IDC_CHECK_SHOW_ATTR,m_bShowAttr);
|
|
DDX_Check(pDX,IDC_CHECK_EQUAL_SIDE,m_bEqualSide);
|
|
//}}AFX_DATA_MAP
|
|
}
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(CCellBlockDlg, CModelessDialog)
|
|
//{{AFX_MSG_MAP(CCellBlockDlg)
|
|
ON_BN_CLICKED(IDC_BUTTON_PICK, OnButtonSelect)
|
|
ON_BN_CLICKED(IDC_CHECK_AUTOSIZE, OnButtonCheck)
|
|
ON_BN_CLICKED(IDC_CHECK_UNISCALE,OnButtonCheck)
|
|
ON_BN_CLICKED(IDC_CHECK_INPUT_SCALE,OnButtonCheck)
|
|
ON_BN_CLICKED(IDC_CHECK_SHOW_ATTR,OnButtonCheck)
|
|
ON_BN_CLICKED(IDC_CHECK_EQUAL_SIDE,OnButtonCheck)
|
|
ON_BN_CLICKED(IDC_BUTTON_FROMLIB, OnButtonSelectFromLib)
|
|
|
|
//add by xlc on 090225
|
|
ON_WM_SETCURSOR()
|
|
ON_BN_CLICKED(IDC_PREVIEW, OnButtonSelectFromLib)
|
|
ON_WM_CLOSE()
|
|
//}}AFX_MSG_MAP
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
BOOL CCellBlockDlg::OnInitDialog()
|
|
{
|
|
CModelessDialog::OnInitDialog();
|
|
|
|
SetFlag();
|
|
if (m_bModeless)
|
|
{
|
|
GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
|
|
GetDlgItem(IDCANCEL)->ShowWindow(SW_HIDE);
|
|
}
|
|
if (m_strBlockName!=_T(""))
|
|
{
|
|
m_idOldBlock=GetBlockIdFromString(m_strBlockName);
|
|
}
|
|
|
|
// 预览
|
|
if (!m_PreviewCtrl.SubclassDlgItem(IDC_PREVIEW, this))
|
|
return FALSE;
|
|
|
|
UpdatePreview();
|
|
return TRUE; // return TRUE unless you set the focus to a control
|
|
// EXCEPTION: OCX Property Pages should return FALSE
|
|
}
|
|
|
|
BOOL CCellBlockDlg::DestroyWindow()
|
|
{
|
|
m_PreviewCtrl.clearAll();
|
|
return CModelessDialog::DestroyWindow();
|
|
}
|
|
|
|
// 刷新预览图
|
|
void CCellBlockDlg::UpdatePreview()
|
|
{
|
|
if (m_strBlockName==_T(""))
|
|
{
|
|
m_PreviewCtrl.clearAll();
|
|
m_PreviewCtrl.init(true);
|
|
return;
|
|
}
|
|
|
|
AcDbBlockTable *pBlockTab=NULL;
|
|
VERIFY(m_PreviewDb.getSymbolTable(pBlockTab, AcDb::kForWrite)==Acad::eOk);
|
|
|
|
AcDbObjectId blockId;
|
|
AcDbBlockTableRecord *pMspace = new AcDbBlockTableRecord;
|
|
pMspace->setName(_T("*U"));
|
|
pBlockTab->add(pMspace);
|
|
pBlockTab->close();
|
|
|
|
AcDbBlockReference *pBlockRef = new AcDbBlockReference;
|
|
|
|
pBlockRef->setBlockTableRecord(m_idNewBlock);
|
|
AcDbExtents aext;
|
|
pBlockRef->geomExtentsBestFit(aext);//得到扩展
|
|
AcDbObjectId __id;
|
|
if(pMspace->appendAcDbEntity(__id,pBlockRef) == Acad::eOk)
|
|
pBlockRef->close();
|
|
else
|
|
delete pBlockRef;
|
|
|
|
XPoint ptMax,ptMin;
|
|
XPoint ptCenter;
|
|
double length,width;
|
|
ptMax=aext.maxPoint();
|
|
ptMin=aext.minPoint();
|
|
ptCenter.x=(ptMin.x+ptMax.x)/2;
|
|
ptCenter.y=(ptMin.y+ptMax.y)/2;
|
|
ptCenter.z = (ptMax.z + ptMin.z) / 2;
|
|
length=(ptMax.x-ptMin.x)*1.3;
|
|
width=(ptMax.y-ptMin.y)*1.3;
|
|
|
|
m_PreviewCtrl.clearAll();
|
|
m_PreviewCtrl.init(true);
|
|
AcDbDatabase *pDb=NULL;
|
|
AcGePoint3d position(ptCenter.x,ptCenter.y,ptMax.z+1);
|
|
|
|
m_PreviewCtrl.view()->setView(position, ptCenter,AcGeVector3d(0.0,1.0,0.0),length,width);
|
|
//modify by xlc on 090806 R18移植
|
|
#ifndef ZWCAD
|
|
#if ADS<18
|
|
m_PreviewCtrl.view()->setMode(AcGsView::k2DOptimized);
|
|
#else
|
|
m_PreviewCtrl.view()->setVisualStyle(AcGiVisualStyle::k2DWireframe);
|
|
#endif
|
|
#else
|
|
#if ADS > 24
|
|
m_PreviewCtrl.view()->setVisualStyle(AcGiVisualStyle::k2DWireframe);
|
|
#else
|
|
m_PreviewCtrl.view()->setMode(AcGsView::k2DOptimized);
|
|
#endif
|
|
#endif
|
|
|
|
m_PreviewCtrl.view()->add(pMspace,m_PreviewCtrl.model());
|
|
pMspace->close();
|
|
m_PreviewCtrl.Invalidate();
|
|
}
|
|
//选择图元
|
|
void CCellBlockDlg::OnButtonSelect()
|
|
{
|
|
UpdateData(TRUE);
|
|
|
|
if (m_bModeless)
|
|
{
|
|
acedPostCommand(_T("B "));
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
HideDialog(TRUE);
|
|
Entity entText;
|
|
RBList rbMask2(RTDXF0, _T("INSERT,AEC_BLOCK_INSERT,ATS_MVINSERT"), 8, _T("*"), NULL);
|
|
|
|
{
|
|
if(SelectEntity(_T(":$\n请选择拷贝源图块<退出>:"), entText, rbMask2) != RTNORM)
|
|
{
|
|
HideDialog(FALSE);
|
|
UpdateData(FALSE);
|
|
SetFlag();
|
|
return;
|
|
}
|
|
TCHAR szText[256];
|
|
entText.GetData(2, szText);
|
|
m_strBlockName = szText;
|
|
m_idOldBlock=GetBlockIdFromString(szText);
|
|
}
|
|
|
|
HideDialog(FALSE);
|
|
}
|
|
|
|
UpdateData(FALSE);
|
|
SetFlag();
|
|
|
|
CloneBlockToPreview();
|
|
UpdatePreview();
|
|
}
|
|
|
|
void CCellBlockDlg::CloneBlockToPreview()
|
|
{
|
|
AcDbObjectIdArray list;
|
|
list.append(m_idOldBlock); // 将实体ID存入数组
|
|
AcDbIdMapping idMap;
|
|
Acad::ErrorStatus es=acdbCurDwg()->wblockCloneObjects(list,m_PreviewDb.blockTableId(),idMap,AcDb::kDrcReplace);//复制块到当前打开的文档
|
|
|
|
AcDbIdPair idPair;
|
|
idPair.setKey(m_idOldBlock);
|
|
idMap.compute(idPair);
|
|
m_idNewBlock=idPair.value();
|
|
}
|
|
|
|
void CCellBlockDlg::SelectBlockFromLib()
|
|
{
|
|
AcDbObjectId idBlock;
|
|
XString sLibFile, sBlockName, sBlock;
|
|
CString csDwbPath, csDdblPath;
|
|
csDwbPath = g_sDwbPath;
|
|
csDdblPath = csDwbPath.Left(csDwbPath.GetLength() - 5) + _T("\\ddbl\\二维图库.TKW");
|
|
|
|
//modify by xlc on 090304
|
|
XString sDwbPath, sDdblPath;
|
|
XString path;
|
|
//if(FindFile(_T("二维图库.TKW"),sDdblPath))//modify by xlc on 090429 路径查找错误
|
|
if(FindFile(csDdblPath,sDdblPath))
|
|
|
|
{
|
|
sLibFile << sDdblPath;
|
|
}
|
|
else
|
|
{
|
|
if(FindFile(_T("EWDLib.TKW"),sDwbPath))
|
|
{
|
|
sLibFile << sDwbPath;
|
|
}
|
|
}
|
|
|
|
if(!InvokeBlockMan(sLibFile, TRUE, sBlockName))
|
|
return;
|
|
CString strTmp=sBlockName.cs();
|
|
|
|
//modify by xlc on 090304
|
|
if(strTmp.Find(_T(".tk"))>=0)
|
|
{
|
|
strTmp.Replace(_T(".tk"),_T(".dwb"));
|
|
sBlockName=strTmp;
|
|
}
|
|
else if(strTmp.Find(_T(".TK"))>=0)
|
|
{
|
|
strTmp.Replace(_T(".TK"),_T(".dwb"));
|
|
sBlockName=strTmp;
|
|
}
|
|
|
|
acDocManager->lockDocument(curDoc());
|
|
int ret=LoadDwbBlock(sBlockName, sBlock);
|
|
acDocManager->unlockDocument(curDoc());
|
|
|
|
if (ret!=RTNORM)
|
|
return ;
|
|
idBlock=InitBlock(sBlock,acdbCurDwg());
|
|
if (!idBlock.isValid())
|
|
return;
|
|
m_strBlockName=sBlock;
|
|
m_idOldBlock=idBlock;
|
|
m_bLibBlk=TRUE;
|
|
}
|
|
//隐藏或者显示对话框
|
|
void CCellBlockDlg::HideDialog(BOOL bFlag)
|
|
{
|
|
if (bFlag) {
|
|
GetParent()->EnableWindow(TRUE);
|
|
GetParent()->SetFocus();
|
|
GetParent()->SetActiveWindow();
|
|
ShowWindow(SW_HIDE);
|
|
GetParent()->RedrawWindow();
|
|
}
|
|
else {
|
|
GetParent()->EnableWindow(FALSE);
|
|
EnableWindow(TRUE);
|
|
SetActiveWindow();
|
|
ShowWindow(SW_SHOW);
|
|
GetParent()->EnableWindow(TRUE);
|
|
}
|
|
}
|
|
|
|
void CCellBlockDlg::SetFlag()
|
|
{
|
|
if(m_bAutoSize)
|
|
m_nFlag|=CBF_AUTOSIZE;
|
|
else
|
|
m_nFlag&=~CBF_AUTOSIZE;
|
|
|
|
if(m_bUniScale)
|
|
m_nFlag|=CBF_UNISCALE;
|
|
else
|
|
m_nFlag&=~CBF_UNISCALE;
|
|
|
|
if(m_bShowAttr)
|
|
m_nFlag|=CBF_SHOW_ATTR;
|
|
else
|
|
m_nFlag&=~CBF_SHOW_ATTR;
|
|
|
|
if(m_bEqualSide)
|
|
m_nFlag|=CBF_EQUAL_SIDE;
|
|
else
|
|
m_nFlag&=~CBF_EQUAL_SIDE;
|
|
}
|
|
BOOL CCellBlockDlg::GetAutoSize() const
|
|
{
|
|
return ((m_nFlag&CBF_AUTOSIZE)!=0);
|
|
}
|
|
BOOL CCellBlockDlg::GetUniScale() const
|
|
{
|
|
return ((m_nFlag&CBF_UNISCALE)!=0);
|
|
}
|
|
|
|
BOOL CCellBlockDlg::GetShowAttr() const
|
|
{
|
|
return ((m_nFlag&CBF_SHOW_ATTR)!=0);
|
|
}
|
|
BOOL CCellBlockDlg::GetEqualSide() const
|
|
{
|
|
return ((m_nFlag&CBF_EQUAL_SIDE)!=0);
|
|
}
|
|
|
|
void CCellBlockDlg::OnButtonCheck()
|
|
{
|
|
UpdateData();
|
|
SetFlag();
|
|
}
|
|
void CCellBlockDlg::OnButtonSelectFromLib()
|
|
{
|
|
UpdateData();
|
|
SelectBlockFromLib();
|
|
UpdateData(FALSE);
|
|
SetFlag();
|
|
|
|
CloneBlockToPreview();
|
|
UpdatePreview();
|
|
}
|
|
|
|
//add by xlc on 090225
|
|
BOOL CCellBlockDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
|
|
{
|
|
CWnd *pSlideWnd=GetDlgItem(IDC_PREVIEW);
|
|
if(pWnd && pWnd->m_hWnd==pSlideWnd->m_hWnd)
|
|
{
|
|
CTemporaryResourceOverride vTemp;
|
|
HCURSOR hIcon = AfxGetApp()->LoadCursor( IDC_CUR_PICK );
|
|
SetCursor( hIcon );
|
|
return TRUE;
|
|
}
|
|
return CModelessDialog::OnSetCursor(pWnd, nHitTest, message);
|
|
}
|
|
|
|
// 从图库中选择图块名(另一.arx)
|
|
BOOL CCellBlockDlg::
|
|
InvokeBlockMan(const TCHAR *pszLib, BOOL bSelOnly, XString &sBlockName)
|
|
{
|
|
if(!AT_loaded(_T("wfB"))) {
|
|
#ifndef ZWCAD
|
|
int nRet=acrxLoadModule(_T("wfB.arx"), Adesk::kTrue, true);
|
|
#else
|
|
int nRet=acrxLoadModule(_T("wfB.zrx"), Adesk::kTrue, true);
|
|
#endif
|
|
if(!nRet)
|
|
return FALSE;
|
|
}
|
|
int nCode=bSelOnly? RTT : RTNIL;
|
|
RBList rbCmd=ads_buildlist(RTSTR, _T("Itkwman"), RTSTR, pszLib, nCode,
|
|
RTSTR, (const TCHAR *)sBlockName, NULL);
|
|
resbuf *rbRes=NULL;
|
|
if(ads_invoke(rbCmd, &rbRes)==RTNORM && rbRes) {
|
|
if(rbRes && rbRes->restype==RTSTR)
|
|
sBlockName=rbRes->resval.rstring;
|
|
ads_relrb(rbRes);
|
|
return TRUE;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
void CCellBlockDlg::OnClose()
|
|
{
|
|
if(m_bModeless)
|
|
acedPostCommand(_T("\33"));
|
|
else
|
|
CModelessDialog::OnClose();
|
|
} |