Files
envi-code/SourceCode/Code2026/tg_shs/shs_TwtAnotate/DimPipeSerialDlg.cpp
T
2026-09-28 15:28:50 +08:00

1163 lines
27 KiB
C++

// DimPipeSerialDlg.cpp : implementation file
//
#include "stdafx.h"
#include "DimPipeSerialDlg.h"
#include "jig.h"
#include "DbVPipeDim.h"
#include <algorithm>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int DoubleCmp(const double *i, const double *j)
{
if (*i < *j)
return -1;
else if (*i > *j)
return 1;
else
return 0;
}
//***************************************************************************************************
// 入户排序
//***************************************************************************************************
void PipeSerialSort()
{
g_ssPickFirst.Free();
BOOL bFirst = TRUE;
DList<SPipeSerial> lstDataAll;
while(1)
{
PickSet ss(SS_FREE);
CString csPrompt = _T("\n请选择入户管号标注:<退出>");
if(!bFirst){
csPrompt = _T("\n请继续选择入户管号标注,序号会继续排列:<退出>");
}
bFirst = FALSE;
RBList rbMask(RTDXF0, _T("ATS_DRAWINGINDEX"), NULL);
if(SelectEntities(csPrompt, ss, rbMask) != RTNORM)
return;
int iMode = 1;
ads_getint(_T("\n请选择自动编号方案:{自左至右[1]/自右至左[2]/自上至下[3]/自下至上[4]}<1>:"), &iMode);
long len = ss.Length();
DList<SPipeSerial> lstData;
for(long i=0;i<len;i++){
Entity ent = ss[i];
XPoint pt;
CString csName, csSerial;
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbSymbDrawingIndex, pIdx);
if(pIdx){
pt = pIdx->GetCenter();
csName = pIdx->GetIndexLabel();
csSerial = pIdx->GetDrawingLabel();
}
OPENOBJ_END();
AcDbObjectId id;
acdbGetObjectId(id, ent);
SPipeSerial *pNew = new SPipeSerial();
pNew->m_csName = csName;
pNew->m_csSerial = csSerial;
pNew->m_iSerial = 0;
pNew->m_pt = pt;
pNew->m_ID = id;
lstData.Append(pNew);
}
if(iMode == 1)
lstData.QuickSort(SPipeSerial::SortByItem);
else if(iMode == 2)
lstData.QuickSort(SPipeSerial::SortByItem1);
else if(iMode == 3)
lstData.QuickSort(SPipeSerial::SortByItem2);
else if(iMode == 4)
lstData.QuickSort(SPipeSerial::SortByItem3);
len = lstData.Length();
if(len < 1)
return;
for(i=0;i<len;i++){
SPipeSerial *data = lstData[i];
CString csSerial = data->m_csSerial;
CString csName = data->m_csName;
int iSerial = data->m_iSerial;
if(iSerial < 1){
//先判断上次有没有历史记录
BOOL bHasHistory = FALSE;
for(int m=0;m<lstDataAll.Length();m++){
SPipeSerial *data3 = lstDataAll[m];
CString csName3 = data3->m_csName;
if(csName == csName3){
iSerial = data3->m_iSerial;
bHasHistory = TRUE;
break;
}
}
// 没有历史记录,第一次,要求输入
if(iSerial < 1){
CString csPrompt;
int iFirst = _ttoi(csSerial);
csPrompt.Format(_T("\n请输入%s起始编号:<%d>:"), csName, iFirst);
ads_getint(csPrompt, &iFirst);
data->m_iSerial = iFirst;
iSerial=iFirst;
}
for(int j=i;j<len;j++){
SPipeSerial *data2 = lstData[j];
CString csName2 = data2->m_csName;
if(csName == csName2){
data2->m_iSerial = iSerial;
OPENOBJ_BEGIN(data2->m_ID, AcDb::kForWrite, TDbSymbDrawingIndex, pIdx);
if(pIdx){
pIdx->SetDrawingLabel(XString(_T("%d"), iSerial));
}
OPENOBJ_END();
iSerial++;
}
}
if(!bHasHistory){//第一次,存入全局,进行保留
SPipeSerial *pNew = new SPipeSerial();
pNew->m_csName = csName;
pNew->m_iSerial = iSerial;
lstDataAll.Append(pNew);
}
else{//不是首次,修改全局
for(int m=0;m<lstDataAll.Length();m++){
SPipeSerial *data3 = lstDataAll[m];
CString csName3 = data3->m_csName;
if(csName == csName3){
data3->m_iSerial = iSerial;
break;
}
}
}
}
}
}
return;
}
//***************************************************************************************************
// 立管编号排序
//***************************************************************************************************
// 选出图层为立管图层的管线 zxl 2012.04.12 add
bool CheckVPipeLayer(const CString sLayer)
{
CString sLayerNames, sCurLayer;
sLayerNames = GetLayerNames(_T("立管"));
sCurLayer = _T(",") + sLayer + _T(",");
int iRet = sLayerNames.Find(sCurLayer);
if (iRet < 0)
{
return false;
}
return true;
}
// 检查编号是否符合要求 zxl 2012.10.10 add
bool CheckSerialByWords(CString &csTmp)
{
if (csTmp.IsEmpty())
{
return false;
}
for (int i = 0; i < csTmp.GetLength(); i++)
{
char czTmp = csTmp.GetAt(i);
if (!((czTmp >= _T('A') && czTmp <= _T('Z')) || (czTmp >= _T('a') && czTmp <= _T('z'))))
{
return false;
}
}
return true;
}
bool CheckSerialByNum(CString &csTmp)
{
if (csTmp.IsEmpty())
{
return false;
}
for (int i = 0; i < csTmp.GetLength(); i++)
{
char czTmp = csTmp.GetAt(i);
if (!(czTmp >= _T('0') && czTmp <= _T('9')))
{
return false;
}
}
return true;
}
// 号码加1
void ModifySerial(CString &sTmp)
{
char czTmp = sTmp.GetAt(0);
if (czTmp >= _T('0') && czTmp <= _T('9'))
{
int iFirst = _ttoi(sTmp);
iFirst++;
sTmp = (const TCHAR*)(XString(_T("%d"), iFirst));
}
else
{
int i = sTmp.GetLength() - 1;
czTmp = sTmp.GetAt(i);
while ((czTmp == _T('z') || czTmp == _T('Z')) && i >= 0)
{
sTmp.SetAt(i--, czTmp - 25);
if (i >= 0)
{
czTmp = sTmp.GetAt(i);
}
}
if (i < 0)// 全是"z"的情况
{
czTmp -= 25;
CString sNum = czTmp;
sTmp = sNum + sTmp;
}
else
{
czTmp += 1;
sTmp.SetAt(i, czTmp);
}
}
}
void VPipeSerialSort()
{
long len2 = g_ssPickFirst.Length();
if(len2 == 1)
g_ssPickFirst.Free();
PickSet ss(SS_FREE);
RBList rbMask(RTDXF0, _T("ATS_PIPE"), 8, GetLayerNames(_T("管")), NULL);
if(SelectEntities(_T("\n请选择立管:<退出>"), ss, rbMask) != RTNORM)
return;
long len = ss.Length();
int iMode = 1, iRet = 0;
iRet = ads_getint(_T("\n请选择自动编号方案:{自左至右[1]/自右至左[2]/自上至下[3]/自下至上[4]}<1>:"), &iMode);
if (iRet < 0)
{
return;
}
DList<SPipeSerial> lstData;
CString csName;
for(long i=0;i<len;i++){
Entity ent = ss[i];
CString csSerial = ReadXdata(ent, _T("PIPE-SERIAL"));
XPoint pt;
CString csLayer;
OPENOBJ_BEGIN(ent, AcDb::kForRead, TDbPipe, pPipe);
if(pPipe){
if(!pPipe->IsVertical())
continue;
pt = pPipe->StartPoint();
TCHAR *szLay = pPipe->layer();
csLayer = szLay;
delete [] szLay;
//zxl 2012.04.12 modify 对所有可识别管线图层的立管排序
//if(csLayer.Find(_T("VPIPE")) < 0) //sr add 2010-1-6 扣弯图层改为管线图层,不是立管图层,不做排序
// continue;
if (!CheckVPipeLayer(csLayer))
{
continue;
}
}
OPENOBJ_END();
int idx = GetPipeLayerIdxByName(csLayer);
CString csDim = g_csPipeDim[idx];
AcDbObjectId id;
acdbGetObjectId(id, ent);
SPipeSerial *pNew = new SPipeSerial();
pNew->m_csName = csDim;
pNew->m_csSerial = csSerial;
pNew->m_pt = pt;
pNew->m_ID = id;
lstData.Append(pNew);
}
if(iMode == 1)
lstData.QuickSort(SPipeSerial::SortByItem);
else if(iMode == 2)
lstData.QuickSort(SPipeSerial::SortByItem1);
else if(iMode == 3)
lstData.QuickSort(SPipeSerial::SortByItem2);
else if(iMode == 4)
lstData.QuickSort(SPipeSerial::SortByItem3);
len = lstData.Length();
if(len < 1)
return;
// int iFirst = _ttoi(lstData[0]->m_csSerial);
int iRet1 = 0, iRet2 = 0;
CString csPrompt;
csPrompt.Format(_T("\n请输入起始编号(全整数或全字符)<%s>:"), lstData[0]->m_csSerial);
// iRet1 = ads_getint(csPrompt, &iFirst);
// 获取一个全数字或全字符的编号 zxl 2012.10.10 modify
CString csSerial;
TCHAR szSerial[200];
while (!(CheckSerialByWords(csSerial) || CheckSerialByNum(csSerial)))
{
iRet1 = ads_getstring(0, csPrompt, szSerial);
if (iRet1 < 0)
{
return;
}
csSerial = szSerial;
if (csSerial.IsEmpty())
{
csSerial = lstData[0]->m_csSerial;
}
}
TCHAR szHouse[200];
csPrompt.Format(_T("请输入立管所属楼号:"));
iRet2 = ads_getstring(0, csPrompt, szHouse);
if (iRet2 < 0)
{
return;
}
//CString csFirsrtSerial = (const TCHAR*)(XString(_T("%d"), iFirst));
CString csFirsrtSerial = csSerial;
DList<SPipeSerial> lstData2;//考虑多系统立管编号
for(i=0;i<len;i++){
SPipeSerial data = *lstData[i];
CString csSerial2 = csFirsrtSerial;
CString csName2 = data.m_csName;
XPoint pt1 = data.m_pt;
pt1.z = 0;
//int idx(-1);
CString sReal;
int len2 = lstData2.Length();
BOOL bFlag = FALSE;
for(int j=0;j<len2;j++){
SPipeSerial *data2;
data2 = lstData2[j];
CString csName3 = data2->m_csName;
CString csSerial3 = data2->m_csSerial;
XPoint pt2 = data2->m_pt;
pt2.z = 0;
if(csName3 == csName2){
//idx = _ttoi(csSerial3);
if(pt1 != pt2)
ModifySerial(csSerial3);
data2->m_csSerial = csSerial3;
sReal = csSerial3;
// idx ++;
//CString csNew = XString(_T("%d"), idx);
//data2->m_csSerial = csNew;
data2->m_pt = pt1;
bFlag = TRUE;
break;
}
}
if(!bFlag){
SPipeSerial *pNew = new SPipeSerial();
pNew->m_csName = csName2;
pNew->m_csSerial = csSerial2;
pNew->m_pt = pt1;
//idx = _ttoi(csSerial2);
sReal = csSerial2;
lstData2.Append(pNew);
}
ads_name entPipe;
acdbGetAdsName(entPipe, data.m_ID);
// WriteXdata(entPipe, _T("PIPE-SERIAL"), (const TCHAR*)(XString(_T("%d"), idx)));
WriteXdata(entPipe, _T("PIPE-SERIAL"), sReal);
WriteXdata(entPipe,_T("BUILDING-SERIAL"),szHouse);
// UpdateSerialDim(entPipe, csSerial2, idx);
}
//更新标注
PickSet ssAll(SS_FREE);
RBList rbMaskVPipe(RTDXF0, _T("ATS_VPIPEDIM"),NULL);
ssAll.Get(_T("A"),NULL,NULL,rbMaskVPipe);
long lLen = ssAll.Length();
PickSet ssRenew(SS_FREE);
for (long m = 0; m < lLen; ++m)
{
OPENOBJ_BEGIN(ssAll[m], AcDb::kForWrite, TDbVPipeDim, pDim);
if (pDim != NULL)
{
AcDbObjectId idDim = pDim->GetVPipeId();
ads_name name;
acdbGetAdsName(name,idDim);
Entity ent(name);
if (ss.IsInclude(ent))
{
ssRenew += ssAll[m];
pDim->RenewDimLen();
pDim->SaveCurText();
}
}
OPENOBJ_END();
}
UpdateGraphic(ssRenew);
}
//***************************************************************************************************
// 入户管号
//***************************************************************************************************
extern BOOL GetLayerReMark(const TCHAR *szLayer, CString &sRemark);
// cet 2010.11.22 add
typedef struct
{
Entity ent; //
XPoint pt; //
}ENTINFO;
// cet 2010.11.22 add
typedef struct
{
CString strPipeName; //管名
std::vector<ENTINFO> vec; //管
int nNum; //编号
}PIPEINFO;
// cet 2010.11.22 add
// 按管类型存储管
void ClassifyPipe(PickSet &ss, std::vector<PIPEINFO> &data)
{
PIPEINFO info;
info.nNum = 1;
info.strPipeName = _T("给水管");
data.push_back(info);
info.strPipeName = _T("热给水管");
data.push_back(info);
info.strPipeName = _T("热回水管");
data.push_back(info);
info.strPipeName = _T("污水管");
data.push_back(info);
info.strPipeName = _T("废水管");
data.push_back(info);
info.strPipeName = _T("雨水管");
data.push_back(info);
info.strPipeName = _T("中水管");
data.push_back(info);
info.strPipeName = _T("消防管");
data.push_back(info);
info.strPipeName = _T("喷淋管");
data.push_back(info);
// info.strPipeName = _T("凝结水管");
// data.push_back(info);
// info.strPipeName = _T("直饮水管");
// data.push_back(info);
// info.strPipeName = _T("压力污水管");
// data.push_back(info);
// info.strPipeName = _T("压力废水管");
// data.push_back(info);
// info.strPipeName = _T("压力雨水管");
// zxl 2012.04.10 modify
CString sName;
GetLayerReMark(LAY_PIPE_COAGULATE, sName);
if (sName.IsEmpty())
{
sName = _T("凝结水管");
}
else
{
sName += _T("水管");
}
info.strPipeName = sName;
data.push_back(info);
GetLayerReMark(LAY_PIPE_DRINK, sName);
if (sName.IsEmpty())
{
sName = _T("直饮水管");
}
else
{
sName += _T("水管");
}
info.strPipeName = sName;
data.push_back(info);
GetLayerReMark(LAY_PIPE_PRESSDIRT, sName);
if (sName.IsEmpty())
{
sName = _T("压力污水管");
}
else
{
sName += _T("水管");
}
info.strPipeName = sName;
data.push_back(info);
GetLayerReMark(LAY_PIPE_PRESSUSELESS, sName);
if (sName.IsEmpty())
{
sName = _T("压力废水管");
}
else
{
sName += _T("水管");
}
info.strPipeName = sName;
data.push_back(info);
GetLayerReMark(LAY_PIPE_PRESSRAIN, sName);
if (sName.IsEmpty())
{
sName = _T("压力雨水管");
}
else
{
sName += _T("水管");
}
info.strPipeName = sName;
data.push_back(info);
info.strPipeName = _T("其他管");
data.push_back(info);
GetLayerReMark(LAY_PIPE_USER1, sName);
if (sName.IsEmpty())
{
sName = _T("用户1管线");
}
else
{
sName += _T("管");
}
info.strPipeName = sName;
data.push_back(info);
GetLayerReMark(LAY_PIPE_USER2, sName);
if (sName.IsEmpty())
{
sName = _T("用户2管线");
}
else
{
sName += _T("管");
}
info.strPipeName = sName;
data.push_back(info);
GetLayerReMark(LAY_PIPE_USER3, sName);
if (sName.IsEmpty())
{
sName = _T("用户3管线");
}
else
{
sName += _T("管");
}
info.strPipeName = sName;
data.push_back(info);
GetLayerReMark(LAY_PIPE_USER4, sName);
if (sName.IsEmpty())
{
sName = _T("用户4管线");
}
else
{
sName += _T("管");
}
info.strPipeName = sName;
data.push_back(info);
GetLayerReMark(LAY_PIPE_USER5, sName);
if (sName.IsEmpty())
{
sName = _T("用户5管线");
}
else
{
sName += _T("管");
}
info.strPipeName = sName;
data.push_back(info);
GetLayerReMark(LAY_PIPE_USER6, sName);
if (sName.IsEmpty())
{
sName = _T("用户6管线");
}
else
{
sName += _T("管");
}
info.strPipeName = sName;
data.push_back(info);
GetLayerReMark(LAY_PIPE_USER7, sName);
if (sName.IsEmpty())
{
sName = _T("用户7管线");
}
else
{
sName += _T("管");
}
info.strPipeName = sName;
data.push_back(info);
GetLayerReMark(LAY_PIPE_USER8, sName);
if (sName.IsEmpty())
{
sName = _T("用户8管线");
}
else
{
sName += _T("管");
}
info.strPipeName = sName;
data.push_back(info);
for(long i = 0; i < ss.Length(); i++)
{
CString strLayer = GetPipeLayer(ss[i]);
ENTINFO info;
info.ent = ss[i];
if (strLayer.Compare(LAY_PIPE_FEED) == 0 || strLayer.Compare(LAY_PIPE_FEED2) == 0 || strLayer.Compare(LAY_PIPE_FEED3) == 0) //给水
{
data[0].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_HEADFEED) == 0 || strLayer.Compare(LAY_PIPE_HEADFEED2) == 0 || strLayer.Compare(LAY_PIPE_HEADFEED3) == 0) //热给水
{
data[1].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_HEADBACK) == 0 || strLayer.Compare(LAY_PIPE_HEADBACK2) == 0 || strLayer.Compare(LAY_PIPE_HEADBACK3) == 0) //热回水
{
data[2].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_DIRT) == 0) //污水
{
data[3].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_USELESS) == 0) //废水
{
data[4].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_RAIN) == 0) //雨水
{
data[5].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_USED) == 0 || strLayer.Compare(LAY_PIPE_USED2) == 0 || strLayer.Compare(LAY_PIPE_USED3) == 0) //中水
{
data[6].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_FIRE) == 0 || strLayer.Compare(LAY_PIPE_FIRE2) == 0 || strLayer.Compare(LAY_PIPE_FIRE3) == 0) //消防
{
data[7].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_SPRINKLE) == 0 || strLayer.Compare(LAY_PIPE_SPRINKLE2) == 0 || strLayer.Compare(LAY_PIPE_SPRINKLE3) == 0) //喷淋
{
data[8].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_COAGULATE) == 0) //凝结水
{
data[9].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_DRINK) == 0) //直饮水
{
data[10].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_PRESSDIRT) == 0) //压力污水
{
data[11].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_PRESSUSELESS) == 0) //压力废水
{
data[12].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_PRESSRAIN) == 0) //压力雨水
{
data[13].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_OTHER) == 0) //其他
{
data[14].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_USER1) == 0) //市政给管
{
data[15].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_USER2) == 0) //循环给管
{
data[16].vec.push_back(info);
}//zxl 2012.04.10 add
else if (strLayer.Compare(LAY_PIPE_USER3) == 0)
{
data[17].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_USER4) == 0)
{
data[18].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_USER5) == 0)
{
data[19].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_USER6) == 0)
{
data[20].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_USER7) == 0)
{
data[21].vec.push_back(info);
}
else if (strLayer.Compare(LAY_PIPE_USER8) == 0)
{
data[22].vec.push_back(info);
}
}
}
// cet 2010.11.22 add 比较点的大小关系
bool Less(ENTINFO &info1, ENTINFO &info2)
{
bool bVal = false;
XPoint pt1 = info1.pt, pt2 = info2.pt;
if (pt1.x < pt2.x)
{
bVal = true;
}
else if (fabs(pt1.x - pt2.x) < 1e-3 && pt1.y > pt2.y)
{
bVal = true;
}
return bVal;
}
// cet 2010.11.22 add
void SortDim(std::vector<PIPEINFO> &data)
{
std::vector<PIPEINFO>::iterator it;
for(it = data.begin(); it != data.end(); it++)
{
std::sort((*it).vec.begin(), (*it).vec.end(), ::Less);
}
}
void DimPipeSerial()
{
CDimPipeSerialDlg dlg(acedGetAcadFrame());
{
CTemporaryResourceOverride vTemp;
dlg.Create(IDD_DIM_PIPE_SERIAL, acedGetAcadFrame());
}
dlg.ShowWindow(SW_SHOW);
acedGetAcadDwgView()->SetFocus();
RBList rbMask(RTDXF0, _T("ATS_PIPE"), NULL);
PickSet ss(SS_FREE);
if(SelectEntities(_T("\n请选择出户管:<自由绘制>"), ss, rbMask) == RTNORM)
{
long len = ss.Length();
if(len < 1)
{
dlg.DestroyWindow();
return;
}
CWnd *pWnd1 = dlg.GetDlgItem(IDC_COMBO_X);
CWnd *pWnd2 = dlg.GetDlgItem(IDC_COMBO_Y);
pWnd1->EnableWindow(FALSE);
pWnd2->EnableWindow(FALSE);
Entity ent = ss[0L];
XPoint ptStart, ptEnd , ptMid;
GetPipePoint(ent, ptStart, ptEnd, ptMid);
XPushVar<int> vOrthoMode(_T("ORTHOMODE"), 1);
XPoint ptUcs = Wcs2Ucs(ptMid);
if(ads_getpoint(ptUcs, _T("\n选择位置点<退出>"), ptStart) != RTNORM)
{
dlg.DestroyWindow();
return;
}
ptStart = Ucs2Wcs(ptStart);
AcGeVector3d vt(ptStart - ptMid);
vt.rotateBy(PI/2, AcGeVector3d::kZAxis);
ptEnd = ptStart + vt;
XLine line(ptStart, ptEnd);
//cet 2010.11.22 add
std::vector<PIPEINFO> data;
ClassifyPipe(ss, data);
std::vector<PIPEINFO>::iterator it;
for (it = data.begin(); it != data.end(); it++)
{
if (!(*it).vec.empty())
{
CString strTip;
strTip = _T("\n请输入") + (*it).strPipeName + _T("起始编号:<1>");
int nNum = 0;
if (acedGetInt(strTip, &nNum) == RTNORM)
{
(*it).nNum = nNum;
}
}
}
dlg.UpdateData(TRUE);
for(long i=0;i<len;i++)
{
ent = ss[i];
XPoint ptStart2, ptEnd2, ptInt;
GetPipePoint(ent, ptStart2, ptEnd2);
XLine line2(ptStart2, ptEnd2);
int ret = line.Intersection(&line2, ptInt);
if(ret < 1)
continue;
// cet 2010.11.22 del 按顺序标注
// CString csLay = GetPipeLayer(ent);
// int idx = GetPipeLayerIdxByName(csLay);
// CString csX = g_csPipeDim[idx];
//
// CString csTextStyle;
// if(dlg.m_iStyle > -1)
// dlg.m_comboStyle.GetLBText(dlg.m_iStyle, csTextStyle);
// else
// csTextStyle = g_csCircleTextStyle;
//
// TDbSymbDrawingIndex *pIndex = new TDbSymbDrawingIndex;
// pIndex->SetTextStyleId(InitTwtTextStyle(csTextStyle));
// pIndex->SetIndexLabel(csX);
// pIndex->SetOldStyle(TRUE);
// pIndex->SetDrawingLabel(_T("1"));
// pIndex->SetRadius(dlg.m_nRadius);
// pIndex->SetLineWidth(dlg.m_nWidth);
// pIndex->SetTextLayerId(InitLayer(LAY_TEXT));
// pIndex->SetCenter(ptInt);
// pIndex->SetLayoutRotation(Ucs2Wcs(0.0));//modified by whl
// pIndex->AddToCSpace(Adesk::kTrue);
// cet 2010.11.22 add 保存标注点
std::vector<ENTINFO>::iterator it2;
for(it = data.begin(); it != data.end(); it++)
{
for ( it2 = (*it).vec.begin(); it2 != (*it).vec.end(); it2++)
{
if ((*it2).ent == ent)
{
(*it2).pt = ptInt;
break;
}
}
}
}
// cet 2013.3.14 add
int nType = dlg.GetTextType();
double dTextHeight = dlg.GetTextHeightCoefficient();
// cet 2010.11.22 add 排序
SortDim(data);
std::vector<ENTINFO>::iterator it2;
for(it = data.begin(); it != data.end(); it++)
{
int nNum = (*it).nNum;
for ( it2 = (*it).vec.begin(); it2 != (*it).vec.end(); it2++)
{
CString csLay = GetPipeLayer((*it2).ent);
int idx = GetPipeLayerIdxByName(csLay);
CString csX = g_csPipeDim[idx];
CString csTextStyle;
if(dlg.m_iStyle > -1)
dlg.m_comboStyle.GetLBText(dlg.m_iStyle, csTextStyle);
else
csTextStyle = g_csCircleTextStyle;
TDbSymbDrawingIndex *pIndex = new TDbSymbDrawingIndex;
pIndex->SetTextStyleId(InitTwtTextStyle(csTextStyle));
pIndex->SetIndexLabel(csX);
pIndex->SetOldStyle(FALSE);
CString strNum;
strNum.Format(_T("%d"), nNum);
nNum++;
CString strLayer = GetDimLayerNameByPipeLayer(GetPipeLayer((*it2).ent));
InitLayer(strLayer);
pIndex->SetDrawingLabel(strNum);
pIndex->SetRadius(dlg.m_nRadius);
pIndex->SetLineWidth(dlg.m_nWidth);
pIndex->SetCenter((*it2).pt);
pIndex->SetLayoutRotation(Ucs2Wcs(0.0));
// cet 2013.3.14 add 设置“出圈文字样式”和字高系数
pIndex->SetOldStyle(nType);
if (nType == 0 || nType == 3)
{
pIndex->SetTextRatio(dTextHeight);
}
AcDbObjectId idDim = pIndex->AddToCSpace(Adesk::kTrue);
OPENOBJ_BEGIN(idDim, AcDb::kForWrite, TDbEntity, pEnt)
if(pEnt != NULL)
{
pEnt->setLayer(strLayer);
}
OPENOBJ_END()
}
}
}
else
{
while(1){
TDbSymbDrawingIndex *pIndex = new TDbSymbDrawingIndex;
pIndex->SetTextStyleId(InitTwtTextStyle(g_csCircleTextStyle));
pIndex->SetIndexLabel(_T("x"));
pIndex->SetDrawingLabel(_T("y"));
pIndex->SetRadius(10);
pIndex->SetLineWidth(0.35);
pIndex->SetOldStyle(FALSE);
pIndex->SetTextLayerId(InitLayer(LAY_TEXT));
pIndex->SetLayoutRotation(Ucs2Wcs(0.0));//modified by whl
XPoint ptLoc;
xg_getvar(_T("VIEWCTR"), ptLoc);
pIndex->SetCenter(Ucs2Wcs(ptLoc));
TDrawingIdxEdJig jig(pIndex, &dlg);
jig.SetPrompt(_T("\n请给出标注位置<退出>:"));
if(jig.DoIt()==RTNORM) {
pIndex->AddToCSpace(Adesk::kTrue);
dlg.m_csY = PlusString(dlg.m_csY, 1, TRUE);
dlg.UpdateData(FALSE);
continue;
}
delete pIndex;
break;
}
}
dlg.DestroyWindow();
return;
}
extern bool ReadRegData(const CString &sRegName, const CString &strKey, double &dVal);
extern bool WriteRegData(const CString &sRegName, const CString &strKey, double dVal);
CString CDimPipeSerialDlg::m_csX = _T("G");
int CDimPipeSerialDlg::m_nTextType = 0;
double CDimPipeSerialDlg::m_dTextHeight = 0.6;
IMPLEMENT_DYNAMIC(CDimPipeSerialDlg, CModelessDialog)
CDimPipeSerialDlg::CDimPipeSerialDlg(CWnd* pParent /*=NULL*/)
: CModelessDialog(CDimPipeSerialDlg::IDD, pParent), m_spinCir(1), m_spinWidth(0.05)
{
//{{AFX_DATA_INIT(CDimPipeSerialDlg)
m_iStyle = 0;
m_csY = _T("1");
m_nRadius = 5;
m_nWidth = 0.25;
//}}AFX_DATA_INIT
}
void CDimPipeSerialDlg::DoDataExchange(CDataExchange* pDX)
{
CModelessDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDimPipeSerialDlg)
DDX_Control(pDX, IDC_SPIN_WIDTH, m_spinWidth);
DDX_Control(pDX, IDC_SPIN_CIRCLE, m_spinCir);
DDX_Control(pDX, IDC_COMBO_TEXTSTYLE, m_comboStyle);
DDX_CBIndex(pDX, IDC_COMBO_TEXTSTYLE, m_iStyle);
DDX_CBIndex(pDX, IDC_COMBO_TEXT, m_nTextType);
DDX_CBString(pDX, IDC_COMBO_Y, m_csY);
DDX_CBString(pDX, IDC_COMBO_X, m_csX);
DDX_Text(pDX, IDC_EDIT_CIRCLE, m_nRadius);
DDX_Text(pDX, IDC_EDIT_WIDTH, m_nWidth);
DDX_Text(pDX, IDC_EDIT_HEIGHT, m_dTextHeight);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDimPipeSerialDlg, CModelessDialog)
//{{AFX_MSG_MAP(CDimPipeSerialDlg)
ON_WM_CLOSE()
ON_WM_PAINT()
ON_WM_DESTROY()
ON_CBN_SELCHANGE(IDC_COMBO_TEXT, OnSelChangeComboText)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDimPipeSerialDlg message handlers
BOOL CDimPipeSerialDlg::OnInitDialog()
{
CModelessDialog::OnInitDialog();
m_spinCir.SetRange(1, 20);
m_spinWidth.SetRange(0, 10);
InitTwtTextStyle(g_csCircleTextStyle);
XSymbolList lstStyle(_T("STYLE"));
for (int m =0; m < lstStyle.Length(); m++) {
m_comboStyle.AddString(lstStyle[m]);
if(_tcsicmp(g_csCircleTextStyle, lstStyle[m]) == 0){
m_iStyle = m;
}
}
// cet 2010.11.23 add
CRegProperty regProp(GetRegLocation(), _T("DimPipeSerial"));
regProp.SetTopRootKey(HKEY_CURRENT_USER);
bool bVal = regProp.GetValue(_T("X"), m_csX);
m_csX.TrimLeft(_T(" "));
if ((bVal && m_csX.IsEmpty()) || !bVal)
{
m_csX = _T("G");
}
CString strData;
bVal = regProp.GetValue(_T("XData"), strData);
strData.TrimLeft(_T(" "));
if ((bVal&& strData.IsEmpty()) || !bVal)
{
strData = _T("G@W@R@P@Y@Z@X@H");
}
CComboBox *pBox = (CComboBox*)GetDlgItem(IDC_COMBO_X);
while(true)
{
int nIndex = strData.Find(_T("@"));
if (nIndex != -1)
{
CString strX = strData.Left(nIndex);
strData = strData.Right(strData.GetLength() - nIndex - 1);
if (pBox != NULL)
{
pBox->AddString(strX);
}
}
else
{
if (!strData.IsEmpty() && pBox != NULL)
{
pBox->AddString(strData);
}
break;
}
}
// zxl 2012.04.23 add
ReadRegData(_T("TWTConfig"), _T("PipeDimRadius"), m_nRadius);
ReadRegData(_T("TWTConfig"), _T("PipeDimWidth"), m_nWidth);
UpdateData(FALSE);
// cet 2013.3.14 add 根据当前“出圈文字样式”,设置文字字高系数
OnSelChangeComboText();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDimPipeSerialDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
CWnd *pWnd = GetDlgItem(IDC_PREVIEW);
DrawSlide(_T("TWT(DIM)"), pWnd);
}
void CDimPipeSerialDlg::OnClose()
{
CModelessDialog::OnClose();
acedPostCommand(_T("\33\33"));
}
void CDimPipeSerialDlg::PostNcDestroy()
{
CModelessDialog::PostNcDestroy();
}
void CDimPipeSerialDlg::OnDestroy()
{
CModelessDialog::OnDestroy();
// cet 2010.11.23 add
CRegProperty regProp(GetRegLocation(), _T("DimPipeSerial"));
regProp.SetTopRootKey(HKEY_CURRENT_USER);
regProp.SetValue(_T("X"), m_csX);
CComboBox *pBox = (CComboBox*)GetDlgItem(IDC_COMBO_X);
CString strData;
bool bExist = false;
if (pBox != NULL)
{
int nCount = pBox->GetCount();
for (int i = 0; i < nCount; i++)
{
CString strTemp;
pBox->GetLBText(i, strTemp);
if (strData.IsEmpty())
{
strData += strTemp;
}
else
{
strData += _T("@") + strTemp;
}
if (strTemp.Compare(m_csX) == 0)
{
bExist = true;
}
}
if (!bExist)
{
strData += _T("@") + m_csX;
}
}
regProp.SetValue(_T("XData"), strData);
// zxl 2012.04.23 add
WriteRegData(_T("TWTConfig"), _T("PipeDimRadius"), m_nRadius);
WriteRegData(_T("TWTConfig"), _T("PipeDimWidth"), m_nWidth);
}
int CDimPipeSerialDlg::GetTextType() const
{
return m_nTextType;
}
double CDimPipeSerialDlg::GetTextHeightCoefficient() const
{
return m_dTextHeight;
}
void CDimPipeSerialDlg::OnSelChangeComboText()
{
UpdateData(TRUE);
CWnd *pWnd = GetDlgItem(IDC_EDIT_HEIGHT);
if (pWnd == NULL)
{
return;
}
if (m_nTextType == 0 || m_nTextType == 3)
{
pWnd->EnableWindow(TRUE);
}
else
{
pWnd->EnableWindow(FALSE);
}
}