370 lines
10 KiB
C++
370 lines
10 KiB
C++
#include "stdafx.h"
|
||
#include "OpeningValidation.h"
|
||
#include "Resource.h"
|
||
#include "OpeningValidateDlg.h"
|
||
#include "OpeningLabelData.h"
|
||
|
||
TOpeningValidation::TOpeningValidation()
|
||
{
|
||
m_nFlag=0;
|
||
m_nWidth=0;
|
||
m_nHeight=0;
|
||
}
|
||
|
||
BOOL TOpeningValidation::ValidateLabel(const TDbOpening *pOpening)
|
||
{
|
||
if (m_nFlag)
|
||
return FALSE;
|
||
|
||
// sg modify 110228,根据8.5需求,将类别改成类型
|
||
// if (_tcsicmp(m_sKind, pOpening->GetKindString())!=0)
|
||
if (_tcsicmp(m_sKind, pOpening->GetSubKind())!=0)
|
||
return FALSE;
|
||
|
||
if (fabs(m_nWidth-pOpening->GetWidth())>_DIST_SNAP ||
|
||
fabs(m_nHeight-pOpening->GetHeight())>_DIST_SNAP)
|
||
return FALSE;
|
||
|
||
XString sDwb2d, sDwg2d, sDwb3d, sDwg3d;
|
||
pOpening->GetStyle2dName(sDwb2d, sDwg2d);
|
||
pOpening->GetStyle3dName(sDwb3d, sDwg3d);
|
||
|
||
XString sStyle2d, sStyle3d;
|
||
if (!sDwb2d || !sDwg2d)
|
||
sStyle2d=_T("");
|
||
else
|
||
sStyle2d = XString(_T("%s(%s)"), (const TCHAR *)sDwb2d, (const TCHAR *)sDwg2d);
|
||
if (!sDwb3d || !sDwg3d)
|
||
sStyle3d=_T("");
|
||
else
|
||
sStyle3d = XString(_T("%s(%s)"), (const TCHAR *)sDwb3d, (const TCHAR *)sDwg3d);
|
||
|
||
if (_tcsicmp(m_sStyle2d, sStyle2d)!=0 ||
|
||
_tcsicmp(m_sStyle3d, sStyle3d)!=0)
|
||
return FALSE;
|
||
return TRUE;
|
||
}
|
||
|
||
// 必须是驻留DWG
|
||
void TOpeningValidation::Validate(const TDbOpening *pOpening)
|
||
{
|
||
AcDbObjectId id = pOpening->objectId();
|
||
if (!id)
|
||
return;
|
||
|
||
if (m_idArray.isEmpty())
|
||
{
|
||
m_nFlag=0;
|
||
m_sLabel=pOpening->GetLabel();
|
||
// sg modify 110228,根据8.5需求,将类别改成类型
|
||
// m_sKind=pOpening->GetKindString();
|
||
m_sKind=pOpening->GetSubKind();
|
||
m_opKind=pOpening->GetKind();
|
||
m_nWidth=pOpening->GetWidth();
|
||
m_nHeight=pOpening->GetHeight();
|
||
XString sDwb2d, sDwg2d, sDwb3d, sDwg3d;
|
||
pOpening->GetStyle2dName(sDwb2d, sDwg2d);
|
||
pOpening->GetStyle3dName(sDwb3d, sDwg3d);
|
||
if (!sDwb2d || !sDwg2d)
|
||
m_sStyle2d=_T("");
|
||
else
|
||
m_sStyle2d = XString(_T("%s(%s)"), (const TCHAR *)sDwb2d, (const TCHAR *)sDwg2d);
|
||
if (!sDwb3d || !sDwg3d)
|
||
m_sStyle3d=_T("");
|
||
else
|
||
m_sStyle3d = XString(_T("%s(%s)"), (const TCHAR *)sDwb3d, (const TCHAR *)sDwg3d);
|
||
}
|
||
else
|
||
{
|
||
if (_tcsicmp(m_sLabel, pOpening->GetLabel())!=0)
|
||
return;
|
||
// sg modify 110228,根据8.5需求,将类别改成类型
|
||
//if (_tcsicmp(m_sKind, pOpening->GetKindString())!=0) {
|
||
if (_tcsicmp(m_sKind, pOpening->GetSubKind())!=0) {
|
||
m_nFlag |= OVF_KIND;
|
||
m_sKind=_T("<冲突>");
|
||
}
|
||
if (fabs(m_nWidth-pOpening->GetWidth())>_DIST_SNAP)
|
||
m_nFlag |= OVF_WIDTH;
|
||
if (fabs(m_nHeight-pOpening->GetHeight())>_DIST_SNAP)
|
||
m_nFlag |= OVF_HEIGHT;
|
||
XString sDwb2d, sDwg2d, sDwb3d, sDwg3d;
|
||
pOpening->GetStyle2dName(sDwb2d, sDwg2d);
|
||
pOpening->GetStyle3dName(sDwb3d, sDwg3d);
|
||
|
||
XString sStyle2d, sStyle3d;
|
||
if (!sDwb2d || !sDwg2d)
|
||
sStyle2d=_T("");
|
||
else
|
||
sStyle2d = XString(_T("%s(%s)"), (const TCHAR *)sDwb2d, (const TCHAR *)sDwg2d);
|
||
if (!sDwb3d || !sDwg3d)
|
||
sStyle3d=_T("");
|
||
else
|
||
sStyle3d = XString(_T("%s(%s)"), (const TCHAR *)sDwb3d, (const TCHAR *)sDwg3d);
|
||
|
||
if (_tcsicmp(m_sStyle2d, sStyle2d)!=0) {
|
||
m_nFlag |= OVF_STYLE2D;
|
||
m_sStyle2d=_T("<冲突>");
|
||
}
|
||
if (_tcsicmp(m_sStyle3d, sStyle3d)!=0) {
|
||
m_nFlag |= OVF_STYLE3D;
|
||
m_sStyle3d=_T("<冲突>");
|
||
}
|
||
}
|
||
m_idArray.append(id);
|
||
}
|
||
|
||
int TOpeningValidation::CompareForFindByCode(const TOpeningValidation *p1, const void *pv2)
|
||
{
|
||
const TCHAR *p2=(const TCHAR *)pv2;
|
||
return _tcsicmp(p1->m_sLabel, p2);
|
||
}
|
||
|
||
static const TCHAR *g_szOpKind[]={_T("子母门"), _T("门"), _T("门连窗"), _T("弧窗"), _T("转角窗"), _T("窗")};//modified by fxj 090622 门联窗-》门连窗
|
||
|
||
// 从OpeningLabel.ini文件中,得到所有门窗的标注,并按顺序返回
|
||
static void GetAllOpeningLabelInIniFile(CStringArray &arLabels)
|
||
{
|
||
TOpeningLabelData data;
|
||
|
||
CString csSection;
|
||
CStringArray arSectionName, arTempLabels;
|
||
data.GetLabelArray(arSectionName); // 获得所有标签名
|
||
|
||
int nSize = arSectionName.GetSize(),
|
||
nLabelSize = 0;
|
||
for (int i=0; i<nSize; i++)
|
||
{
|
||
csSection = arSectionName[i];
|
||
data.GetSubType(csSection, arTempLabels); // 获得类型
|
||
|
||
nLabelSize = arTempLabels.GetSize();
|
||
for (int j=0; j<nLabelSize; j++)
|
||
{
|
||
csSection = arTempLabels[j];
|
||
arLabels.InsertAt(0, csSection);
|
||
|
||
arTempLabels.RemoveAt(0);
|
||
nLabelSize--;
|
||
j--;
|
||
}
|
||
}
|
||
}
|
||
|
||
// sg modify 110228,根据8.5需求,将类别改成类型
|
||
static int GetSeqCode(const TCHAR *szKind)
|
||
{
|
||
// int nSeqCode=-1;
|
||
// for(int i=0;i<ELEMENTS(g_szOpKind);i++)
|
||
//{
|
||
// if (_tcscmp(szKind, g_szOpKind[i])==0) {
|
||
// nSeqCode=i;
|
||
// break;
|
||
// }
|
||
// }
|
||
// return nSeqCode;
|
||
|
||
CStringArray arLabels;
|
||
GetAllOpeningLabelInIniFile(arLabels);
|
||
|
||
int nSeqCode = -1,
|
||
nSize = arLabels.GetSize();
|
||
for (int i=0; i<nSize; i++)
|
||
{
|
||
if (_tcscmp(szKind, arLabels[i]) == 0)
|
||
{
|
||
nSeqCode = i;
|
||
break;
|
||
}
|
||
}
|
||
return nSeqCode;
|
||
}
|
||
|
||
int TOpeningValidation::CompareForSort(const TOpeningValidation *p1, const TOpeningValidation *p2)
|
||
{
|
||
int nSeqCode1=GetSeqCode(p1->m_sKind);
|
||
int nSeqCode2=GetSeqCode(p2->m_sKind);
|
||
if (nSeqCode1>nSeqCode2)
|
||
return -1;
|
||
else if (nSeqCode1<nSeqCode2)
|
||
return 1;
|
||
return _tcsicmp(p1->m_sLabel, p2->m_sLabel);
|
||
}
|
||
|
||
|
||
void TOpeningValidateTable::GetValidLabels(TOpeningData::OpeningKind opKind, XStringList &lstLabels) const
|
||
{
|
||
lstLabels.Reset();
|
||
int nLen=Length();
|
||
for(int i=0; i<nLen; i++) {
|
||
const TOpeningValidation &entry=(*this)[i];
|
||
if (entry.m_opKind==opKind && entry.m_nFlag==0 && !!entry.m_sLabel)
|
||
lstLabels.Append(tstrnew(entry.m_sLabel));
|
||
}
|
||
}
|
||
|
||
void TOpeningValidateTable::Validate(const TDbOpening *pOpening)
|
||
{
|
||
const TCHAR *pszLabel=pOpening->GetLabel();
|
||
TOpeningValidation *pEntry=FindNode(pszLabel, TOpeningValidation::CompareForFindByCode);
|
||
if (!pEntry) {
|
||
pEntry=new TOpeningValidation;
|
||
Append(pEntry);
|
||
}
|
||
pEntry->Validate(pOpening);
|
||
}
|
||
|
||
|
||
BOOL TOpeningValidateTable::ValidateLabel(const TDbOpening *pOpening)
|
||
{
|
||
const TCHAR *pszLabel=pOpening->GetLabel();
|
||
TOpeningValidation *pEntry=FindNode(pszLabel, TOpeningValidation::CompareForFindByCode);
|
||
if (!pEntry) {
|
||
return TRUE;
|
||
}
|
||
if (pEntry->m_nFlag)
|
||
return FALSE;
|
||
return pEntry->ValidateLabel(pOpening);
|
||
}
|
||
|
||
extern void GetOpeningIdList(DList<AcDbDatabase> &dbList, DList<AcDbObjectId> &idList) ;
|
||
|
||
|
||
// sg delete 110224,8.5起改用新命令,命令函数体移植到OpeningCheck.cpp中
|
||
////忽略转角窗,电梯门,隔断门
|
||
//void ValidateOpening()
|
||
//{
|
||
// /*
|
||
// PickSet ss(SS_FREE);
|
||
// RBList mask(RTDXF0, _T("TCH_OPENING"), NULL);
|
||
// if (ss.Get(_T("X"), NULL, NULL, mask)!=RTNORM)
|
||
// return;
|
||
// */
|
||
// DList<AcDbDatabase> dbList;
|
||
// DList<AcDbObjectId> ss;
|
||
// GetOpeningIdList(dbList, ss);
|
||
// if (!ss)
|
||
// return;
|
||
//
|
||
// TOpeningValidateTable opTable;
|
||
// int lCount=ss.Length();
|
||
// for(int i=0; i<lCount; i++) {
|
||
// AcDbObjectId &ent=*ss[i];
|
||
// OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbOpening, pOpening);
|
||
// if (pOpening && pOpening->GetKind()!=TOpeningData::OP_CORNWIN &&
|
||
// //pOpening->GetKind()!=TOpeningData::OP_HOLE &&
|
||
// !(pOpening->m_nOpStyle&OPS_LIFTDOOR) && !(pOpening->m_nOpStyle&OPS_LVTRY))
|
||
// opTable.Validate(pOpening);
|
||
// OPENOBJ_END();
|
||
// }
|
||
// opTable.QuickSort(TOpeningValidation::CompareForSort);
|
||
//
|
||
// //modify by xlc on 080918
|
||
// //COpeningValidateDlg dlg(&opTable, acedGetAcadFrame());
|
||
// COpeningValidateNewDlg dlg(&opTable, acedGetAcadFrame());
|
||
// {
|
||
// CAcModuleResourceOverride vTemp;
|
||
// dlg.DoModal();
|
||
// }
|
||
//}
|
||
|
||
//批量改名
|
||
void BatNameOpening()
|
||
{
|
||
Entity ent;
|
||
if (SelectEntity(_T("\n选择已经编号的参考门窗<退出>:"),ent,RBList(RTDXF0,_T("TCH_OPENING"),NULL))!=RTNORM)
|
||
return;
|
||
|
||
DList<AcDbDatabase> dbList;
|
||
DList<AcDbObjectId> ss;
|
||
GetOpeningIdList(dbList, ss);
|
||
if (!ss)
|
||
return;
|
||
|
||
TOpeningValidation group;
|
||
XString sLabel;
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbOpening, pOpening);
|
||
if (pOpening!=NULL)
|
||
{
|
||
group.Validate(pOpening);
|
||
sLabel=pOpening->GetLabel();
|
||
}
|
||
OPENOBJ_END();
|
||
|
||
int lCount=ss.Length();
|
||
int count=0;
|
||
for(int i=0; i<lCount; i++)
|
||
{
|
||
AcDbObjectId &ent=*ss[i];
|
||
OPENOBJ_BEGIN(ent, AcDb::kForWrite, TDbOpening, pOpening);
|
||
if (group.ValidateLabel(pOpening))//同类门窗
|
||
{
|
||
pOpening->assertWriteEnabled();
|
||
if (sLabel!=pOpening->GetLabel())
|
||
{
|
||
count++;
|
||
pOpening->SetLabel(sLabel);
|
||
}
|
||
}
|
||
OPENOBJ_END();
|
||
}
|
||
if (count>0)
|
||
adsout<<_T("共有")<<count<<_T("个与参照门窗尺寸、样式相同的门窗被编号为")<<sLabel;
|
||
else
|
||
adsout<<_T("未找到与参照门窗尺寸、样式相同且编号不同的门窗");
|
||
}
|
||
|
||
BOOL ValidateLabel(TDbOpening &op)
|
||
{
|
||
const TCHAR *szLabel=op.GetLabel();
|
||
if (!szLabel || !szLabel[0])
|
||
return TRUE;
|
||
/*
|
||
PickSet ss(SS_FREE);
|
||
RBList mask(RTDXF0, _T("TCH_OPENING"), NULL);
|
||
if (ss.Get(_T("X"), NULL, NULL, mask)!=RTNORM)
|
||
return TRUE;
|
||
*/
|
||
DList<AcDbDatabase> dbList;
|
||
DList<AcDbObjectId> ss;
|
||
GetOpeningIdList(dbList, ss);
|
||
if (!ss)
|
||
return TRUE;
|
||
TOpeningValidateTable opTable;
|
||
int lCount=ss.Length();
|
||
for(int i=0; i<lCount; i++) {
|
||
AcDbObjectId &ent=*ss[i];
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbOpening, pOpening);
|
||
//if (pOpening && pOpening->GetKind()!=TOpeningData::OP_CORNWIN &&
|
||
//pOpening->GetKind()!=TOpeningData::OP_HOLE &&
|
||
// !(pOpening->m_nOpStyle&OPS_LIFTDOOR) && !(pOpening->m_nOpStyle&OPS_LVTRY))
|
||
if (pOpening)
|
||
opTable.Validate(pOpening);
|
||
OPENOBJ_END();
|
||
}
|
||
return opTable.ValidateLabel(&op);
|
||
}
|
||
BOOL ValidateLabelInCurDwg(TDbOpening &op)
|
||
{
|
||
const TCHAR *szLabel=op.GetLabel();
|
||
if (!szLabel || !szLabel[0])
|
||
return TRUE;
|
||
|
||
DList<AcDbObjectId> ss;
|
||
GetEntFromBlockByDxf(ss, _T("TCH_OPENING"));
|
||
|
||
TOpeningValidateTable opTable;
|
||
int lCount=ss.Length();
|
||
for(int i=0; i<lCount; i++) {
|
||
AcDbObjectId &ent=*ss[i];
|
||
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbOpening, pOpening);
|
||
//if (pOpening && pOpening->GetKind()!=TOpeningData::OP_CORNWIN &&
|
||
//pOpening->GetKind()!=TOpeningData::OP_HOLE &&
|
||
// !(pOpening->m_nOpStyle&OPS_LIFTDOOR) && !(pOpening->m_nOpStyle&OPS_LVTRY))
|
||
if (pOpening)
|
||
opTable.Validate(pOpening);
|
||
OPENOBJ_END();
|
||
}
|
||
return opTable.ValidateLabel(&op);
|
||
}
|