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

567 lines
12 KiB
C++

#include "stdafx.h"
#include "FindAndInsteadVPipeDimDlg.h"
#include "DbVPipeDim.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//查替立编 zxl 2012.08.28 add
void FindAndInsteadVPipeDim()
{
CTemporaryResourceOverride vTemp;
// 命令执行期间保证只有一个对话框存在
if (CFindAndInsteadVPipeDimDlg::IsCreatedDlg())
{
return;
}
CFindAndInsteadVPipeDimDlg *pDlg = new CFindAndInsteadVPipeDimDlg(acedGetAcadFrame());
pDlg->Create(IDD_FIND_INSTEAD_VPIPEDIM);
pDlg->ClearData();
pDlg->ShowWindow(SW_SHOW);
acedGetAcadDwgView()->SetFocus();
}
bool CFindAndInsteadVPipeDimDlg::m_bCreatedDlg = false;
CFindAndInsteadVPipeDimDlg::CFindAndInsteadVPipeDimDlg(CWnd* pParent /*=NULL*/)
: CModelessDialog(CFindAndInsteadVPipeDimDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFindAndInsteadVPipeDimDlg)
m_sBefore1 = _T("");
m_sBefore2 = _T("");
m_sFloor1 = _T("");
m_sFloor2 = _T("");
m_sNum1 = _T("");
m_sNum2 = _T("");
m_nStyle = 0;
m_nSearch = 0;
m_nInstead = 0;
//}}AFX_DATA_INIT
m_bCreatedDlg = true;
m_bFirstSearch = true;
}
void CFindAndInsteadVPipeDimDlg::DoDataExchange(CDataExchange* pDX)
{
CModelessDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFindAndInsteadVPipeDimDlg)
DDX_Control(pDX, IDC_BTN_SEARCH, m_wndBtnSearch);
DDX_Text(pDX, IDC_EDIT_BEFORE1, m_sBefore1);
DDX_Text(pDX, IDC_EDIT_BEFORE2, m_sBefore2);
DDX_Text(pDX, IDC_EDIT_FLOOR1, m_sFloor1);
DDX_Text(pDX, IDC_EDIT_FLOOR2, m_sFloor2);
DDX_Text(pDX, IDC_EDIT_NUM1, m_sNum1);
DDX_Text(pDX, IDC_EDIT_NUM2, m_sNum2);
DDX_CBIndex(pDX, IDC_COMBO_FIND_STYLE, m_nStyle);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFindAndInsteadVPipeDimDlg, CModelessDialog)
//{{AFX_MSG_MAP(CFindAndInsteadVPipeDimDlg)
ON_BN_CLICKED(IDC_BTN_INSTEAD_ALL, OnBtnInsteadAll)
ON_BN_CLICKED(IDC_BTN_INSTEAD, OnBtnInstead)
ON_BN_CLICKED(IDC_BTN_FIND, OnBtnFindNext)
ON_CBN_SELCHANGE(IDC_COMBO_FIND_STYLE, OnSelchangeComboFindStyle)
ON_BN_CLICKED(IDC_BTN_SEARCH, OnBtnSearch)
ON_WM_CLOSE()
ON_EN_CHANGE(IDC_EDIT_NUM1, OnChangeEditNum1)
ON_EN_CHANGE(IDC_EDIT_FLOOR1, OnChangeEditFloor1)
ON_EN_CHANGE(IDC_EDIT_BEFORE1, OnChangeEditBefore1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CFindAndInsteadVPipeDimDlg::OnInitDialog()
{
CModelessDialog::OnInitDialog();
CBitmap bitmap;
if (bitmap.LoadBitmap(IDB_BITMAP_FIND))
{
m_wndBtnSearch.SetBitmap(bitmap);
bitmap.Detach();
}
InitPickSet();
m_wndToolTip.Create(this);
m_wndToolTip.AddTool( GetDlgItem(IDC_BTN_SEARCH), _T("选取对象"));
m_wndToolTip.SetDelayTime(200);
m_wndToolTip.Activate(TRUE);
return TRUE;
}
void CFindAndInsteadVPipeDimDlg::InitPickSet()
{
RBList rbMask(RTDXF0, _T("ATS_VPIPEDIM"), NULL);
m_ss.Get(_T("X"), NULL, NULL, rbMask);
long len = m_ss.Length();
XStringList lstWellName, lstRepeat;
for(long i=0;i<len;i++)
{
Entity ent = m_ss[i];
CString sFloorNumT;
sFloorNumT = ReadXdata(ent,_T("BUILDING-SERIAL"));
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbVPipeDim, pDim);
if(pDim)
{
CString csHead, csSerial;
pDim->GetDimTypeText(csHead);
CString sSerial;
pDim->GetDimVPipeNum(sSerial);
CString csName,csFloor;
pDim->GetVPipeFloorNum(csFloor);
if (csFloor.IsEmpty())
csName.Format(_T("%s-%s"), csHead, sSerial);
else
csName.Format(_T("%s-%s-%s"), csHead,csFloor, sSerial);
if(lstWellName.Index(csName, 0) < 0)
lstWellName.Append(tstrnew(csName));
else
lstRepeat.Append(tstrnew(csName));
}
OPENOBJ_END();
}
for(int j=0;j<lstRepeat.Length();j++)
{
adsout << XString(_T("\n编号为%s的立管编号有重复。"), lstRepeat[j]);
}
}
void CFindAndInsteadVPipeDimDlg::OnBtnInsteadAll()
{
acDocManager->lockDocument(curDoc(),AcAp::kWrite,NULL,NULL,true);
UpdateData(TRUE);
GetRightDims();
m_nSearch = m_ssRight.Length();
for (long l = 0l; l < m_ssRight.Length(); l++)
{
bool bIsInstead = false;
Entity ent = m_ssRight[l];
OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbVPipeDim, pDim);
if(pDim)
{
if (!m_sNum2.IsEmpty())
{
AcDbObjectId id = pDim->GetVPipeId();
CString sNum;
pDim->GetDimVPipeNum(sNum);
if (sNum.Compare(m_sNum2) != 0)
{
pDim->SetDimVPipeNum(m_sNum2, id);
bIsInstead = true;
}
}
if (!m_sFloor2.IsEmpty())
{
CString sFloor;
pDim->GetVPipeFloorNum(sFloor);
if (sFloor.Compare(m_sFloor2) != 0)
{
pDim->SetVPipeFloorNum(m_sFloor2);
bIsInstead = true;
}
}
if (!m_sBefore2.IsEmpty())
{
CString sHead;
pDim->GetDimTypeText(sHead);
if (sHead.Compare(m_sBefore2) != 0)
{
pDim->SetDimTypeText(m_sBefore2);
bIsInstead = true;
}
}
if (bIsInstead)
{
m_nInstead++;
}
pDim->RenewDimLen();
pDim->Close();
}
OPENOBJ_END();
}
m_ssRight.Free();
AddNot();
acDocManager->unlockDocument(curDoc());
acedGetAcadDwgView()->SetFocus();
SetBtnStyle();
m_bFirstSearch = true;
}
void CFindAndInsteadVPipeDimDlg::OnBtnInstead()
{
acDocManager->lockDocument(curDoc(),AcAp::kWrite,NULL,NULL,true);
UpdateData(TRUE);
AcDbObjectId id;
acdbGetObjectId(id, m_ent);
AcDbEntity *pEnt = NULL;
Acad::ErrorStatus st = acdbOpenAcDbEntity(pEnt, id, AcDb::kForWrite);
if (pEnt == NULL)
{
return;
}
TDbVPipeDim *pDim = NULL;
bool bIsInstead = false;
if (pEnt->isKindOf(TDbVPipeDim::desc()))
{
pDim = (TDbVPipeDim *)pEnt;
if (!m_sNum2.IsEmpty())
{
AcDbObjectId id = pDim->GetVPipeId();
CString sNum;
pDim->GetDimVPipeNum(sNum);
if (sNum.Compare(m_sNum2) != 0)
{
pDim->SetDimVPipeNum(m_sNum2, id);
bIsInstead = true;
}
}
if (!m_sFloor2.IsEmpty())
{
CString sFloor;
pDim->GetVPipeFloorNum(sFloor);
if (sFloor.Compare(m_sFloor2) != 0)
{
pDim->SetVPipeFloorNum(m_sFloor2);
bIsInstead = true;
}
}
if (!m_sBefore2.IsEmpty())
{
CString sHead;
pDim->GetDimTypeText(sHead);
if (sHead.Compare(m_sBefore2) != 0)
{
pDim->SetDimTypeText(m_sBefore2);
bIsInstead = true;
}
}
pDim->RenewDimLen();
pDim->Close();
}
acDocManager->unlockDocument(curDoc());
acedGetAcadDwgView()->SetFocus();
if (bIsInstead)
{
m_nInstead++;
}
if (m_ssRight.Length() < 1)
{
AddNot();
GetRightDims();
}
SetBtnStyle();
}
void CFindAndInsteadVPipeDimDlg::SetBtnStyle()
{
CWnd *pWnd = GetDlgItem(IDC_BTN_INSTEAD);
if (pWnd == NULL)
{
return;
}
if (m_ssRight.Length() > 0)
{
m_ent = m_ssRight[0l];
m_ssRight -= m_ent;
m_nSearch++;
SetSelEntBox();
SetDlgItemText(IDC_BTN_FIND, _T("查找下一个"));
pWnd->EnableWindow(TRUE);
}
else
{
SetDlgItemText(IDC_BTN_FIND, _T("查找"));
pWnd->EnableWindow(FALSE);
Entity ent;
m_ent = ent;
}
}
void CFindAndInsteadVPipeDimDlg::AddNot()
{
CString sSearch, sInstead;
sSearch.Format(_T("\n共找见%d个"), m_nSearch);
sInstead.Format(_T("\n共替换%d个"), m_nInstead);
CString sNot = _T("\n搜索完成:");
sNot += sSearch;
sNot += sInstead;
AfxMessageBox(sNot, MB_OK);
m_nInstead = 0;
m_nSearch = 0;
}
// 获取符合条件的编号
void CFindAndInsteadVPipeDimDlg::GetRightDims()
{
UpdateData(TRUE);
if (m_ss.Length() < 1)
{
InitPickSet();
}
for(long i = 0; i < m_ss.Length(); i++)
{
Entity ent = m_ss[i];
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbVPipeDim, pDim);
if(pDim)
{
CString csHead, csSerial, csFloor;
pDim->GetDimTypeText(csHead);
pDim->GetVPipeFloorNum(csFloor);
pDim->GetDimVPipeNum(csSerial);
CString sFloorNum = m_sFloor1, sHeadNum = m_sBefore1, sNumber = m_sNum1;
if (!(((!sHeadNum.IsEmpty() && csHead.Compare(sHeadNum) != 0))
|| ((!sFloorNum.IsEmpty() && csFloor.Compare(sFloorNum) != 0))
|| ((!sNumber.IsEmpty() && csSerial.Compare(sNumber) != 0) )) && !(sHeadNum.IsEmpty() && sFloorNum.IsEmpty() && sNumber.IsEmpty()))
{
m_ssRight += ent;
}
}
OPENOBJ_END();
}
}
void CFindAndInsteadVPipeDimDlg::OnBtnFindNext()
{
UpdateData(TRUE);
if (m_ssRight.Length() < 1)
{
if (m_bFirstSearch)
{
GetRightDims();
m_bFirstSearch = false;
}
else
{
AddNot();
GetRightDims();
return;
}
}
UpdateData(FALSE);
acedGetAcadDwgView()->SetFocus();
if (m_ssRight.Length() < 1)
{
AddNot();
}
SetBtnStyle();
}
void CFindAndInsteadVPipeDimDlg::SetSelEntBox()// 编号外包框
{
AcDbObjectId id;
acdbGetObjectId(id, m_ent);
AcDbEntity *pEnt = NULL;
acdbOpenAcDbEntity(pEnt, id, AcDb::kForRead);
if (pEnt == NULL)
{
return;
}
TDbVPipeDim *pDim = NULL;
if (pEnt->isKindOf(TDbVPipeDim::desc()))
{
pDim = (TDbVPipeDim *)pEnt;
}
AcDbVoidPtrArray entArry;
pEnt->explode(entArry);
pEnt->close();
TDbText *pText = NULL;
AcDbCircle *pCir = NULL;
AcDbExtents ext;
double dAngle = 0.0;
AcDbEntity *pEntOther = NULL;
for (int j = 0; j < entArry.length(); j++)
{
pEntOther = NULL;
pEntOther = (AcDbEntity *)entArry[j];
if (pEntOther == NULL)
{
continue;
}
if (pEntOther->isKindOf(TDbText::desc()))
{
pText = (TDbText *)pEntOther;
dAngle = pText->GetRotation();
pText->SetRotation(Wcs2Ucs(0.0));
pText->getGeomExtents(ext);
break;
}
else if (pDim->GetDimType() == 1 && pEntOther->isKindOf(AcDbCircle::desc()))// 圆形标注
{
pCir = (AcDbCircle *)pEntOther;
pCir->getGeomExtents(ext);
break;
}
}
AcDbPolyline poly;
AcDbPolyline *pPLine = &poly;
XPoint ptMax, ptMin;
ptMax = ext.maxPoint();
ptMin = ext.minPoint();
ptMax[2] = 0;
ptMin[2] = 0;
XPoint ptMaxLeft(ptMin[0], ptMax[1], 0);
XPoint ptMinRight(ptMax[0], ptMin[1], 0);
arxZoomTo(ptMin, 100*DocGetPScale(), 100*DocGetPScale());
pPLine->addVertexAt(0, ptMin);
pPLine->addVertexAt(1, ptMinRight);
pPLine->addVertexAt(2, ptMax);
pPLine->addVertexAt(3, ptMaxLeft);
pPLine->setClosed(Adesk::kTrue);
if (pText != NULL)
{
AcGeMatrix3d mat;
mat.setToRotation(dAngle - Wcs2Ucs(0.0), AcGeVector3d::kZAxis, pText->GetLocation());
poly.transformBy(mat);
}
ReleaseEntSet(entArry);
AcGePoint3d pt1, pt2, pt3, pt4;
poly.getPointAt(0, pt1);
poly.getPointAt(1, pt2);
poly.getPointAt(2, pt3);
poly.getPointAt(3, pt4);
XPoint pt11 = Wcs2Ucs(pt1), pt12 = Wcs2Ucs(pt2), pt13 = Wcs2Ucs(pt3), pt14 = Wcs2Ucs(pt4);
ads_grdraw(pt11, pt12, 1, 0);
ads_grdraw(pt12, pt13, 1, 0);
ads_grdraw(pt13, pt14, 1, 0);
ads_grdraw(pt11, pt14, 1, 0);
}
void CFindAndInsteadVPipeDimDlg::OnSelchangeComboFindStyle()
{
UpdateData(TRUE);
if (m_nStyle == 1)
{
ShowWindow(SW_HIDE);
if (!GetPickSetByCustom())
{
m_nStyle = 0;
}
UpdateData(FALSE);
}
else
{
ShowWindow(SW_SHOW);
InitPickSet();
}
}
bool CFindAndInsteadVPipeDimDlg::GetPickSetByCustom()
{
m_ss.Free();
m_ssRight.Free();
UpdateData(TRUE);
RBList rbMask(RTDXF0, _T("ATS_VPIPEDIM"), NULL);
if (SelectEntities(_T("\n请选择范围<退出>:"), m_ss, rbMask) != RTNORM)
{
ShowWindow(SW_SHOW);
return false;
}
ShowWindow(SW_SHOW);
return true;
}
void CFindAndInsteadVPipeDimDlg::OnBtnSearch()
{
ShowWindow(SW_HIDE);
if (!GetPickSetByCustom())
{
m_nStyle = 0;
}
else
{
m_nStyle = 1;
}
UpdateData(FALSE);
}
LONG_PTR CFindAndInsteadVPipeDimDlg::onAcadKeepFocus(UINT_PTR, LONG_PTR)
{
return TRUE;
}
void CFindAndInsteadVPipeDimDlg::OnClose()
{
CModelessDialog::OnClose();
DestroyWindow();
delete this;
m_bCreatedDlg = false;
acedPostCommand(_T("\33\33"));
}
void CFindAndInsteadVPipeDimDlg::OnChangeEditNum1()
{
m_ssRight.Free();
m_bFirstSearch = true;
m_nInstead = 0;
m_nSearch = 0;
}
void CFindAndInsteadVPipeDimDlg::OnChangeEditFloor1()
{
m_ssRight.Free();
m_bFirstSearch = true;
m_nInstead = 0;
m_nSearch = 0;
}
void CFindAndInsteadVPipeDimDlg::OnChangeEditBefore1()
{
m_ssRight.Free();
m_bFirstSearch = true;
m_nInstead = 0;
m_nSearch = 0;
}
void CFindAndInsteadVPipeDimDlg::ClearData()
{
m_ss.Free();
m_ssRight.Free();
Entity ent;
m_ent = ent;
}
bool CFindAndInsteadVPipeDimDlg::IsCreatedDlg()
{
return m_bCreatedDlg;
}
void CFindAndInsteadVPipeDimDlg::OnCancel()
{
CModelessDialog::OnCancel();
OnClose();
}
BOOL CFindAndInsteadVPipeDimDlg::PreTranslateMessage(MSG* pMsg)
{
switch(pMsg->message)
{
case WM_MOUSEMOVE:
m_wndToolTip.RelayEvent(pMsg);
}
return CModelessDialog::PreTranslateMessage(pMsg);
}