881 lines
23 KiB
C++
881 lines
23 KiB
C++
#include "stdafx.h"
|
|
#include "KTCADUtilityEx.h"
|
|
#include "PipeSystemSetting.h"
|
|
#include "ListEditCtrl.h"
|
|
#include "coretools.h"
|
|
#include "AecDbEwPipe.h"
|
|
#include "shJson.h"
|
|
#include "KTModelLayoutXData.h"
|
|
#include "AecDbEwFitting.h"
|
|
|
|
#ifndef ZWCAD
|
|
extern bool __cdecl acedLinetypeDialog(AcDbObjectId old_linetypeId
|
|
, bool IncludeByBlockByLayer
|
|
, TCHAR *&new_linetypeName
|
|
, AcDbObjectId &new_linetypeId);
|
|
|
|
extern bool __cdecl acedLineWeightDialog(AcDb::LineWeight oldLw, bool, AcDb::LineWeight &lw);
|
|
#else
|
|
extern bool __cdecl zcedLinetypeDialog(AcDbObjectId old_linetypeId
|
|
, bool IncludeByBlockByLayer
|
|
, TCHAR *&new_linetypeName
|
|
, AcDbObjectId &new_linetypeId);
|
|
|
|
extern bool __cdecl zcedLineWeightDialog(AcDb::LineWeight oldLw, bool, AcDb::LineWeight &lw);
|
|
#define acedLinetypeDialog zcedLinetypeDialog
|
|
#define acedLineWeightDialog zcedLinetypeDialog
|
|
#endif
|
|
|
|
namespace
|
|
{
|
|
void getLineTypeString(std::map<AcDbObjectId, CString> &lines)
|
|
{
|
|
AcDbDatabase *pDb = acdbCurDwg();
|
|
if (!pDb) return;
|
|
|
|
AcDbLinetypeTable *pTable(NULL);
|
|
pDb->getLinetypeTable(pTable, AcDb::kForRead);
|
|
ACHAR *psz(NULL);
|
|
if (pTable)
|
|
{
|
|
AcDbLinetypeTableIterator *pItLt = NULL;
|
|
pTable->newIterator(pItLt);
|
|
if (pItLt)
|
|
{
|
|
AcDbLinetypeTableRecord *pRcdLt = NULL;
|
|
LPCTSTR szLtName = NULL;
|
|
|
|
for (; !pItLt->done(); pItLt->step())
|
|
{
|
|
if (pItLt->getRecord(pRcdLt, AcDb::kForRead) == Acad::eOk)
|
|
{
|
|
|
|
pRcdLt->comments(psz);
|
|
if (psz)
|
|
{
|
|
if (!CString(psz).IsEmpty())
|
|
lines.insert(std::make_pair(pRcdLt->objectId(), psz));
|
|
acutDelString(psz);
|
|
}
|
|
pRcdLt->close();
|
|
}
|
|
}
|
|
|
|
DELETE_PTR(pItLt);
|
|
}
|
|
pTable->close();
|
|
}
|
|
}
|
|
|
|
AcDbObjectId getLineType(LPCTSTR name)
|
|
{
|
|
AcDbObjectId id(AcDbObjectId::kNull);
|
|
AcDbDatabase *pDb = acdbCurDwg();
|
|
if (!pDb) return id;
|
|
|
|
AcDbLinetypeTable *pTable(NULL);
|
|
pDb->getLinetypeTable(pTable, AcDb::kForRead);
|
|
ACHAR *psz(NULL);
|
|
if (pTable)
|
|
{
|
|
pTable->getAt(name, id);
|
|
pTable->close();
|
|
}
|
|
|
|
return id;
|
|
}
|
|
|
|
CString getLineType(const AcDbObjectId &id)
|
|
{
|
|
AcDbDatabase *pDb = acdbCurDwg();
|
|
if (!pDb) return _T("Continuous");
|
|
|
|
OPENOBJ_BEGIN(id, AcDb::kForRead, AcDbLinetypeTableRecord, pEnt)
|
|
if (pEnt)
|
|
{
|
|
AcString s;
|
|
if (pEnt->getName(s) == Acad::eOk)
|
|
return s.constPtr();
|
|
}
|
|
OPENOBJ_END()
|
|
return _T("Continuous");
|
|
}
|
|
|
|
typedef CPipeSystemSettingDlg::RECORD RECORD;
|
|
|
|
void updateEntity(const std::map<CString, RECORD> &rcs)
|
|
{
|
|
if (rcs.empty()) return;
|
|
|
|
std::map<CString, RECORD>::const_iterator it(rcs.begin());
|
|
for (; it != rcs.end(); ++it)
|
|
{
|
|
CoreTools::getLyByPipeSys(it->first, true, true);
|
|
CoreTools::getLyByPipeSys(it->first, false, true);
|
|
CoreTools::getLyForPipe(it->first, true);
|
|
}
|
|
|
|
ads_name ss, ent;
|
|
struct resbuf *pRb = acutBuildList(RTDXF0, _T("AEC_EWPIPE,AEC_DBEWFIT"), 0);
|
|
int nRes = acedSSGet(_T("A"), NULL, NULL, pRb, ss);
|
|
if (nRes != RTNORM) return;
|
|
|
|
CString sys;
|
|
AcDbObjectId id, idOutLy, idInnLy;
|
|
Adesk::Int32 lLen = 0L;
|
|
double dOutW(.0), dInnW(.0);
|
|
acedSSLength(ss, &lLen);
|
|
for (long i = 0; i < lLen; i++)
|
|
{
|
|
if (acedSSName(ss, i, ent) != RTNORM) continue;
|
|
if (acdbGetObjectId(id, ent) != Acad::eOk) continue;
|
|
|
|
OPENOBJ_BEGIN(id, AcDb::kForWrite, AcDbEntity, pEnt)
|
|
if (pEnt)
|
|
{
|
|
AecDbEwPipe *pPipe(AecDbEwPipe::cast(pEnt));
|
|
AecDbEwFitting *pFit(AecDbEwFitting::cast(pEnt));
|
|
if (pPipe && pPipe->GetSpecialtyData()->GetAt(PIPE_SYS, sys))
|
|
{
|
|
std::map<CString, RECORD>::const_iterator it = rcs.find(sys);
|
|
if (it == rcs.end()) continue;
|
|
|
|
if (sys != it->second.newSys)
|
|
{ // 需要更新系统名称
|
|
pPipe->GetSpecialtyData()->SetAt(PIPE_SYS, it->second.newSys);
|
|
}
|
|
|
|
idOutLy = CoreTools::getLyByPipeSys(sys, false);
|
|
idInnLy = CoreTools::getLyByPipeSys(sys, true);
|
|
dOutW = CoreTools::getLwByPipeSys(sys, false);
|
|
dInnW = CoreTools::getLwByPipeSys(sys, true);
|
|
|
|
pPipe->UpdatePipeSystem(it->second.outClr
|
|
, it->second.outLt
|
|
, dOutW
|
|
, idOutLy
|
|
, it->second.innClr
|
|
, it->second.innLt
|
|
, dInnW
|
|
, idInnLy );
|
|
}
|
|
if (pFit && pFit->GetSpecialtyData()->GetAt(PIPE_SYS, sys))
|
|
{
|
|
std::map<CString, RECORD>::const_iterator it = rcs.find(sys);
|
|
if (it == rcs.end()) continue;
|
|
if (sys != it->second.newSys)
|
|
{ // 需要更新系统名称
|
|
pFit->GetSpecialtyData()->SetAt(PIPE_SYS, it->second.newSys);
|
|
}
|
|
idOutLy = CoreTools::getLyByPipeSys(sys, false);
|
|
idInnLy = CoreTools::getLyByPipeSys(sys, true);
|
|
dOutW = CoreTools::getLwByPipeSys(sys, false);
|
|
dInnW = CoreTools::getLwByPipeSys(sys, true);
|
|
pFit->UpdatePipeSystem(it->second.outClr
|
|
, it->second.outLt
|
|
, dOutW
|
|
, idOutLy
|
|
, it->second.innClr
|
|
, it->second.innLt
|
|
, dInnW
|
|
, idInnLy );
|
|
}
|
|
}
|
|
OPENOBJ_END()
|
|
}
|
|
acedSSFree(ss);
|
|
}
|
|
|
|
void updateSystemForEntity(const RECORD &rcs)
|
|
{
|
|
std::map<CString, RECORD> mp;
|
|
mp.insert(std::make_pair(rcs.oldSys, rcs));
|
|
updateEntity(mp);
|
|
}
|
|
|
|
bool hasEntityBySystem(LPCTSTR pszSys)
|
|
{
|
|
ads_name ss, ent;
|
|
struct resbuf *pRb = acutBuildList(RTDXF0, _T("AEC_EWPIPE"), 0);
|
|
int nRes = acedSSGet(_T("A"), NULL, NULL, pRb, ss);
|
|
if (nRes != RTNORM) return false;
|
|
|
|
CString sys;
|
|
AcDbObjectId id;
|
|
Adesk::Int32 lLen = 0L;
|
|
acedSSLength(ss, &lLen);
|
|
for (long i = 0; i < lLen; i++)
|
|
{
|
|
if (acedSSName(ss, i, ent) != RTNORM) continue;
|
|
if (acdbGetObjectId(id, ent) != Acad::eOk) continue;
|
|
OPENOBJ_BEGIN(id, AcDb::kForRead, AecDbEwPipe, pEnt)
|
|
if (pEnt)
|
|
{
|
|
if (pEnt->GetSpecialtyData()->GetAt(PIPE_SYS, sys))
|
|
{
|
|
if (sys == pszSys)
|
|
return true;
|
|
}
|
|
}
|
|
OPENOBJ_END()
|
|
}
|
|
acedSSFree(ss);
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// CPipeSystemSettingDlg dialog
|
|
|
|
IMPLEMENT_DYNAMIC(CPipeSystemSettingDlg, CDialog)
|
|
|
|
CPipeSystemSettingDlg::CPipeSystemSettingDlg(CWnd* pParent /*=NULL*/)
|
|
: CDialog(CPipeSystemSettingDlg::IDD, pParent)
|
|
, m_bUpdateAllEntity(false)
|
|
, m_bUseOutClrFor3D(true)
|
|
{
|
|
m_pListCtrl = new CPipeSysSettingList();
|
|
}
|
|
|
|
CPipeSystemSettingDlg::~CPipeSystemSettingDlg()
|
|
{
|
|
DELETE_PTR(m_pListCtrl);
|
|
}
|
|
|
|
void CPipeSystemSettingDlg::DoDataExchange(CDataExchange* pDX)
|
|
{
|
|
CDialog::DoDataExchange(pDX);
|
|
DDX_Control(pDX, IDC_STATIC_POS, m_ctrlPos);
|
|
DDX_Check(pDX, IDC_CHECK_UPDATE, m_bUpdateAllEntity);
|
|
DDX_Check(pDX, IDC_CHECK_USE_OUTER_CLR, m_bUseOutClrFor3D);
|
|
}
|
|
|
|
BOOL CPipeSystemSettingDlg::OnInitDialog()
|
|
{
|
|
CDialog::OnInitDialog();
|
|
|
|
CRect rect;
|
|
m_ctrlPos.GetWindowRect(rect);
|
|
ScreenToClient(rect);
|
|
|
|
m_pListCtrl->Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP, rect, this, IDC_LIST);
|
|
m_pListCtrl->Initialize();
|
|
|
|
if (!m_db.InitADOServer(FilePath::GetSysDir() + _T("\\Plumbing.db")))
|
|
{
|
|
AfxMessageBox(_T("打开数据库Plumbing.db失败!"));
|
|
EndDialog(FALSE);
|
|
return 0;
|
|
}
|
|
|
|
refreshListCtrl();
|
|
|
|
m_bUseOutClrFor3D = CoreTools::IsUsePipeOutClrFor3DRender() == false ? FALSE : TRUE;
|
|
|
|
UpdateData(FALSE);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void CPipeSystemSettingDlg::OnBntClickAdd()
|
|
{
|
|
CString sName(_T(""));
|
|
if (!CoreTools::getNameByDialog(_T("输入新系统名称"), _T("系统名称"), sName)) return;
|
|
|
|
int count = m_pListCtrl->GetRootCount();
|
|
for (int i(0); i < count; ++i)
|
|
{
|
|
CTreeItem *pItem = m_pListCtrl->GetRootItem(i);
|
|
if (!pItem) continue;
|
|
CItemInfo *pInfo = m_pListCtrl->GetData(pItem);
|
|
if (!pInfo) continue;
|
|
if (pInfo->GetItemText() == sName)
|
|
{
|
|
AfxMessageBox(_T("系统名称已经存在!"));
|
|
return;
|
|
}
|
|
}
|
|
|
|
CString clrCenter(_T("255")), clrOutline(_T("1"))
|
|
, lineTypeCenter(_T("CENTER")), lineTypeOutline(_T("Continuous"))
|
|
, layerCenter(sName + _T("中心线")), layerOutline(sName + _T("外边线"))
|
|
, pipeSysCenter(_T("管线中心线")), pipeSysOutline(_T("管线外边线"))
|
|
, sTable(CoreTools::getCurrentPipeSysTblName())
|
|
, linewidth(_T("0.00"))
|
|
, sys(sName);
|
|
|
|
|
|
CString sql;
|
|
sql.Format(_T("INSERT INTO %s \
|
|
([COLOR],[LINETYPE],[LINEWIDTH],[LAYNAME],[SYSTEM],[PIPESYS])\
|
|
VALUES ('%s','%s','%s','%s','%s','%s')")
|
|
, sTable, clrCenter, lineTypeCenter, linewidth, layerCenter, sys, pipeSysCenter);
|
|
if (!m_db.ExecuteSQL(sql))
|
|
{
|
|
AfxMessageBox(_T("数据插入失败!"));
|
|
return;
|
|
}
|
|
|
|
sql.Format(_T("INSERT INTO %s \
|
|
([COLOR],[LINETYPE],[LINEWIDTH],[LAYNAME],[SYSTEM],[PIPESYS])\
|
|
VALUES ('%s','%s','%s','%s','%s','%s')")
|
|
, sTable , clrOutline, lineTypeOutline, linewidth, layerOutline, sys, pipeSysOutline);
|
|
|
|
if (!m_db.ExecuteSQL(sql))
|
|
{
|
|
// 删掉刚才插入的
|
|
sql.Format(_T("DELETE FROM %s WHERE [SYSTEM]='%s'"), sTable, sys);
|
|
m_db.ExecuteSQL(sql);
|
|
AfxMessageBox(_T("数据插入失败!"));
|
|
return;
|
|
}
|
|
|
|
CTreeItem *pRoot = addRootRecord(sName);
|
|
addChildRecord(pRoot, pipeSysCenter, clrCenter, lineTypeCenter, linewidth, layerCenter);
|
|
addChildRecord(pRoot, pipeSysOutline, clrOutline, lineTypeOutline, linewidth, layerOutline);
|
|
|
|
}
|
|
|
|
void CPipeSystemSettingDlg::OnBntClickDel()
|
|
{
|
|
int iItem = m_pListCtrl->GetSelectedItem();
|
|
if (iItem == -1) return;
|
|
|
|
CTreeItem *pItem = m_pListCtrl->GetTreeItem(iItem);
|
|
if (!pItem) return;
|
|
|
|
if (!m_pListCtrl->IsRoot(pItem))
|
|
{
|
|
AfxMessageBox(_T("请选择一个系统节点!"));
|
|
return;
|
|
}
|
|
|
|
CString sys = m_pListCtrl->GetItemText(pItem->m_nIndex, 0);
|
|
|
|
if (hasEntityBySystem(sys))
|
|
{
|
|
CString s;
|
|
s.Format(_T("名为“%s”的管线系统正在被使用,请删除使用此系统的管线实体,然后再尝试删除!"), sys);
|
|
AfxMessageBox(s);
|
|
return;
|
|
}
|
|
|
|
if (AfxMessageBox(_T("此操作不可恢复,确定删除?"), MB_YESNO) != IDYES) return;
|
|
|
|
CString sTable(CoreTools::getCurrentPipeSysTblName());
|
|
CString sql;
|
|
sql.Format(_T("DELETE FROM %s WHERE [SYSTEM]='%s'"), sTable, sys);
|
|
|
|
if (!m_db.ExecuteSQL(sql))
|
|
{
|
|
AfxMessageBox(_T("删除失败!"));
|
|
return;
|
|
}
|
|
|
|
m_pListCtrl->DeleteItemEx(pItem, iItem);
|
|
|
|
}
|
|
|
|
void CPipeSystemSettingDlg::OnBntClickExport()
|
|
{
|
|
using namespace SHJson;
|
|
|
|
CFileDialog dlg(FALSE
|
|
, _T("*.json")
|
|
, NULL
|
|
, OFN_HIDEREADONLY
|
|
, _T("导出数据 (*.json)|*.json||")
|
|
, acedGetAcadFrame());
|
|
if (dlg.DoModal() != IDOK) return;
|
|
|
|
WValue root;
|
|
root.SetArray();
|
|
CString sys, pipesys, clr, linetype, lineweight, layer, sql, sCount;
|
|
|
|
MAP_RECORD recs;
|
|
m_pListCtrl->getRecords(recs, true);
|
|
MAP_RECORD::const_iterator it(recs.begin());
|
|
for (; it != recs.end(); ++it)
|
|
{
|
|
WValue vRec;
|
|
addMember(vRec, _T("SYSTEM"), it->first);
|
|
addMember(vRec, _T("PIPESYS"), _T("管线中心线"));
|
|
addMember(vRec, _T("COLOR"), TypeConvert::i2s(it->second.innClr));
|
|
addMember(vRec, _T("LINETYPE"), getLineType(it->second.innLt));
|
|
addMember(vRec, _T("LINEWIDTH"), it->second.innLw);
|
|
addMember(vRec, _T("LAYNAME"), it->second.innLy);
|
|
pushBack(root, vRec);
|
|
vRec.SetObject();
|
|
addMember(vRec, _T("SYSTEM"), it->first);
|
|
addMember(vRec, _T("PIPESYS"), _T("管线外边线"));
|
|
addMember(vRec, _T("COLOR"), TypeConvert::i2s(it->second.outClr));
|
|
addMember(vRec, _T("LINETYPE"), getLineType(it->second.outLt));
|
|
addMember(vRec, _T("LINEWIDTH"), it->second.outLw);
|
|
addMember(vRec, _T("LAYNAME"), it->second.outLy);
|
|
pushBack(root, vRec);
|
|
}
|
|
|
|
json2File(dlg.GetPathName(), root, true);
|
|
}
|
|
|
|
void CPipeSystemSettingDlg::OnBntClickImport()
|
|
{
|
|
using namespace SHJson;
|
|
CFileDialog dlg(TRUE
|
|
, _T("*.json")
|
|
, NULL
|
|
, OFN_HIDEREADONLY
|
|
, _T("导入数据(*.json)|*.json||")
|
|
, acedGetAcadFrame());
|
|
if (dlg.DoModal() != IDOK) return;
|
|
|
|
WDocument doc;
|
|
if (!file2Json(dlg.GetPathName(), doc)) return;
|
|
if (!doc.IsArray()) return;
|
|
|
|
CString sTable(CoreTools::getCurrentPipeSysTblName());
|
|
CString sys, pipesys, clr, lt, ly, sql;
|
|
double lw;
|
|
for (VCIt _it = doc.Begin(); _it != doc.End(); ++_it)
|
|
{
|
|
WCValue &va(*_it);
|
|
if (!va.IsObject()) continue;
|
|
|
|
MCIt it = va.FindMember(_T("SYSTEM"));
|
|
if (it == va.MemberEnd()) continue;
|
|
sys = it->value.GetString();
|
|
|
|
it = va.FindMember(_T("PIPESYS"));
|
|
if (it == va.MemberEnd()) continue;
|
|
pipesys = it->value.GetString();
|
|
|
|
it = va.FindMember(_T("COLOR"));
|
|
if (it == va.MemberEnd()) continue;
|
|
clr = it->value.GetString();
|
|
|
|
it = va.FindMember(_T("LINETYPE"));
|
|
if (it == va.MemberEnd()) continue;
|
|
lt = it->value.GetString();
|
|
|
|
it = va.FindMember(_T("LINEWIDTH"));
|
|
if (it == va.MemberEnd()) continue;
|
|
lw = it->value.GetDouble();
|
|
|
|
it = va.FindMember(_T("LAYNAME"));
|
|
if (it == va.MemberEnd()) continue;
|
|
ly = it->value.GetString();
|
|
|
|
sql.Format(_T("SELECT COUNT(*) FROM %s WHERE [SYSTEM]='%s' AND [PIPESYS]='%s'")
|
|
, sTable, sys, pipesys);
|
|
if (!m_db.GetSelData(sql, sql)) continue;
|
|
|
|
if (_ttoi(sql) != 0)
|
|
sql.Format(_T("UPDATE %s\
|
|
SET [COLOR]='%s'\
|
|
,[LINETYPE]='%s'\
|
|
,[LINEWIDTH]='%.2f'\
|
|
,[LAYNAME]='%s'\
|
|
WHERE [SYSTEM]='%s' AND [PIPESYS]='%s'")
|
|
, sTable, clr, lt, lw, ly, sys, pipesys);
|
|
else
|
|
sql.Format(_T("INSERT INTO %s \
|
|
([COLOR],[LINETYPE],[LINEWIDTH],[LAYNAME],[SYSTEM],[PIPESYS])\
|
|
VALUES ('%s','%s','%.2f','%s','%s','%s')"), sTable, clr, lt, lw, ly, sys, pipesys);
|
|
|
|
m_db.ExecuteSQL(sql);
|
|
}
|
|
refreshListCtrl();
|
|
}
|
|
|
|
void CPipeSystemSettingDlg::OnOK()
|
|
{
|
|
UpdateData(TRUE);
|
|
|
|
BOOL oldValue = CoreTools::IsUsePipeOutClrFor3DRender();
|
|
if (oldValue != m_bUseOutClrFor3D)
|
|
{
|
|
CoreTools::SetUsePipeOutClrFor3DRender(m_bUseOutClrFor3D);
|
|
m_bUpdateAllEntity = true;
|
|
}
|
|
|
|
if (!m_bUpdateAllEntity && m_pListCtrl->m_setOfModify.empty())
|
|
{
|
|
EndDialog(FALSE);
|
|
return;
|
|
}
|
|
|
|
CString sys, pipesys, clr, linetype, lineweight, layer, sql;
|
|
CString sTable(CoreTools::getCurrentPipeSysTblName());
|
|
|
|
int rootCount = m_pListCtrl->GetRootCount();
|
|
m_db.BeginTrans();
|
|
|
|
MAP_RECORD recs;
|
|
m_pListCtrl->getRecords(recs, m_bUpdateAllEntity == FALSE ? false : true);
|
|
MAP_RECORD::const_iterator it(recs.begin());
|
|
for (; it != recs.end(); ++it)
|
|
{
|
|
const RECORD &rec(it->second);
|
|
sql.Format(_T("UPDATE %s\
|
|
SET [COLOR]='%d'\
|
|
,[LINETYPE]='%s'\
|
|
,[LINEWIDTH]='%.2f'\
|
|
,[LAYNAME]='%s'\
|
|
,[SYSTEM]='%s'\
|
|
WHERE [SYSTEM]='%s' AND [PIPESYS]='%s'")
|
|
, sTable , rec.innClr, getLineType(rec.innLt)
|
|
, rec.innLw, rec.innLy, it->first, rec.oldSys, _T("管线中心线"));
|
|
m_db.ExecuteSQL(sql);
|
|
sql.Format(_T("UPDATE %s\
|
|
SET [COLOR]='%d'\
|
|
,[LINETYPE]='%s'\
|
|
,[LINEWIDTH]='%.2f'\
|
|
,[LAYNAME]='%s'\
|
|
,[SYSTEM]='%s'\
|
|
WHERE [SYSTEM]='%s' AND [PIPESYS]='%s'")
|
|
, sTable , rec.outClr, getLineType(rec.outLt)
|
|
, rec.outLw, rec.outLy, it->first, rec.oldSys, _T("管线外边线"));
|
|
m_db.ExecuteSQL(sql);
|
|
|
|
// 系统名称有变化,更新旧系统的实体
|
|
if (rec.newSys != rec.oldSys)
|
|
{
|
|
updateSystemForEntity(it->second);
|
|
}
|
|
}
|
|
m_db.CommitTrans();
|
|
|
|
if (!recs.empty())
|
|
updateEntity(recs);
|
|
|
|
CDialog::OnOK();
|
|
}
|
|
|
|
void CPipeSystemSettingDlg::refreshListCtrl()
|
|
{
|
|
// Plumbing.db库 WConfig_CN表
|
|
m_pListCtrl->DeleteAll();
|
|
|
|
CString sTable(CoreTools::getCurrentPipeSysTblName());
|
|
CString sql(_T("SELECT DISTINCT [SYSTEM] FROM ") + sTable);
|
|
std::vector<CString> arSys;
|
|
std::vector<std::vector<CString>> arData;
|
|
m_db.GetSelData(sql, arSys);
|
|
for (int i(0); i < arSys.size(); ++i)
|
|
{
|
|
CString &sys(arSys[i]);
|
|
|
|
CTreeItem *pRoot = addRootRecord(sys);
|
|
|
|
sql.Format(_T("SELECT * from %s WHERE [SYSTEM]='%s'"), sTable, sys);
|
|
arData.clear();
|
|
m_db.GetSelDataEx(sql, arData);
|
|
for (int j(0); j < arData.size(); ++j)
|
|
{
|
|
std::vector<CString> &ss(arData[j]);
|
|
// 0-[ID] 1-[LAYKEY] 2-[LAYNAME](图层) 3-[PIPESYS](中心线//外边线) 4-[SYSTEM](管线系统)
|
|
// 5-[COLOR](颜色) 6-[LINETYPE](线形) 7-[LINEWIDTH](线宽) 8-[DIMKEY](标注) 9-[MATERIAL]
|
|
if (ss.size() < 8) continue;
|
|
addChildRecord(pRoot, ss[3], ss[5], ss[6], ss[7], ss[2]);
|
|
}
|
|
}
|
|
}
|
|
|
|
CTreeItem* CPipeSystemSettingDlg::addRootRecord(LPCTSTR title)
|
|
{
|
|
CItemInfo *pInfo = new CItemInfo();
|
|
pInfo->SetItemText(title);
|
|
return m_pListCtrl->InsertRootItem(pInfo);
|
|
}
|
|
|
|
void CPipeSystemSettingDlg::addChildRecord(CTreeItem *pTree
|
|
, LPCTSTR title
|
|
, LPCTSTR clr
|
|
, LPCTSTR linetype
|
|
, LPCTSTR lineweight
|
|
, LPCTSTR layer)
|
|
{
|
|
CItemInfo *pInfo = new CItemInfo();
|
|
pInfo->SetItemText(title);
|
|
pInfo->SetSubItemText(0, clr, acedGetRGB(_ttoi(clr)));
|
|
|
|
pInfo->SetSubItemText(1, linetype);
|
|
|
|
pInfo->SetSubItemText(2, lineweight);
|
|
pInfo->SetControlType(CItemInfo::edit, 2);
|
|
|
|
pInfo->SetSubItemText(3, layer);
|
|
pInfo->SetControlType(CItemInfo::edit, 3);
|
|
m_pListCtrl->InsertItem(pTree, pInfo);
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP(CPipeSystemSettingDlg, CDialog)
|
|
ON_BN_CLICKED(IDOK, &CPipeSystemSettingDlg::OnOK)
|
|
ON_BN_CLICKED(IDC_BTN_ADD, &CPipeSystemSettingDlg::OnBntClickAdd)
|
|
ON_BN_CLICKED(IDC_BTN_DEL, &CPipeSystemSettingDlg::OnBntClickDel)
|
|
ON_BN_CLICKED(IDC_BTN_EXPORT, &CPipeSystemSettingDlg::OnBntClickExport)
|
|
ON_BN_CLICKED(IDC_BTN_IMPORT, &CPipeSystemSettingDlg::OnBntClickImport)
|
|
END_MESSAGE_MAP()
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////
|
|
//CPipeSysSettingList
|
|
BEGIN_MESSAGE_MAP(CPipeSysSettingList, CSuperGridCtrl)
|
|
ON_WM_CREATE()
|
|
ON_NOTIFY_REFLECT_EX(LVN_ENDLABELEDIT, OnEndlabeledit)
|
|
END_MESSAGE_MAP()
|
|
|
|
CPipeSysSettingList::CPipeSysSettingList() { }
|
|
|
|
CPipeSysSettingList::~CPipeSysSettingList() { }
|
|
|
|
void CPipeSysSettingList::Initialize()
|
|
{
|
|
|
|
setCellRGB(RGB(192, 0, 0));
|
|
|
|
SetExtendedStyle(LVS_EX_GRIDLINES);
|
|
|
|
LV_COLUMN lvColumn;
|
|
lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
|
|
lvColumn.fmt = LVCFMT_LEFT;
|
|
|
|
lvColumn.cx = 150;
|
|
lvColumn.pszText = const_cast<LPTSTR>(_T("管道系统"));
|
|
InsertColumn(0, &lvColumn);
|
|
|
|
lvColumn.cx = 80;
|
|
lvColumn.pszText = const_cast<LPTSTR>(_T("颜色"));
|
|
InsertColumn(1, &lvColumn);
|
|
|
|
lvColumn.cx = 150;
|
|
lvColumn.pszText = const_cast<LPTSTR>(_T("线形"));
|
|
InsertColumn(2, &lvColumn);
|
|
|
|
lvColumn.cx = 80;
|
|
lvColumn.pszText = const_cast<LPTSTR>(_T("打印线宽(mm)"));
|
|
InsertColumn(3, &lvColumn);
|
|
|
|
lvColumn.cx = 150;
|
|
lvColumn.pszText = const_cast<LPTSTR>(_T("图层"));
|
|
InsertColumn(4, &lvColumn);
|
|
|
|
ModifyStyleEx(0, WS_EX_CLIENTEDGE);
|
|
}
|
|
|
|
bool CPipeSysSettingList::hasModify(LPCTSTR sys)
|
|
{
|
|
// 先判断 m_mapOfSysModify 里面有没有值,如果有,说明修改了系统名称
|
|
//if (!m_mapOfSysModify.empty()) return true;
|
|
|
|
return m_setOfModify.find(sys) != m_setOfModify.end();
|
|
}
|
|
|
|
void CPipeSysSettingList::getRecords(MAP_RECORD &rcs, bool bAll)
|
|
{
|
|
CString newSys, pipesys, clr, linetype, linewidth, layer, sql;
|
|
int rootCount = GetRootCount();
|
|
for (int i(0); i < rootCount; ++i)
|
|
{
|
|
CTreeItem *pTree = GetRootItem(i);
|
|
if (!pTree) continue;
|
|
|
|
newSys = GetItemText(pTree->m_nIndex, 0);
|
|
|
|
// 不是全部收集,判断是否有修改
|
|
if (!bAll)
|
|
{
|
|
// 如果没有修改,走
|
|
if (!hasModify(newSys))
|
|
continue;
|
|
}
|
|
|
|
RECORD rc; // 变化的记录
|
|
POSITION pos = pTree->m_listChild.GetHeadPosition();
|
|
while (pos != NULL)
|
|
{
|
|
CTreeItem *pChild = (CTreeItem *)pTree->m_listChild.GetNext(pos);
|
|
if (pChild && pChild->m_lpNodeInfo)
|
|
{
|
|
pipesys = pChild->m_lpNodeInfo->GetItemText();
|
|
clr = pChild->m_lpNodeInfo->GetSubItem(0);
|
|
linetype = pChild->m_lpNodeInfo->GetSubItem(1);
|
|
linewidth = pChild->m_lpNodeInfo->GetSubItem(2);
|
|
layer = pChild->m_lpNodeInfo->GetSubItem(3);
|
|
double lw = _ttof(linewidth);
|
|
|
|
if (pipesys == _T("管线中心线"))
|
|
{
|
|
rc.innClr = _ttoi(clr);
|
|
rc.innLt = getLineType(linetype);
|
|
rc.innLw = lw;
|
|
rc.innLy = layer;
|
|
}
|
|
else
|
|
{
|
|
rc.outClr = _ttoi(clr);
|
|
rc.outLt = getLineType(linetype);
|
|
rc.outLw = lw;
|
|
rc.outLy = layer;
|
|
}
|
|
|
|
std::map<CString, CString>::const_iterator it(m_mapOfSysModify.find(newSys));
|
|
if (it != m_mapOfSysModify.end())
|
|
rc.oldSys = it->second;
|
|
else
|
|
rc.oldSys = newSys;
|
|
rc.newSys = newSys;
|
|
}
|
|
}
|
|
rcs.insert(std::make_pair(newSys, rc));
|
|
}
|
|
|
|
}
|
|
|
|
BOOL CPipeSysSettingList::PreTranslateMessage(MSG *pMsg)
|
|
{
|
|
do
|
|
{
|
|
if (pMsg->message != WM_LBUTTONDBLCLK) break;
|
|
if (GetFocus() != this) break;
|
|
int iItem = GetSelectedItem();
|
|
if (iItem == -1) break;
|
|
|
|
CTreeItem *pItem = GetTreeItem(iItem);
|
|
//if (pItem && IsRoot(pItem))
|
|
// break;
|
|
|
|
if (!pItem) break;
|
|
|
|
if (IsRoot(pItem))
|
|
{
|
|
if (m_CurSubItem == 0)
|
|
{
|
|
EditLabelEx(pItem->m_nIndex, m_CurSubItem);
|
|
return 1;
|
|
}
|
|
else break;
|
|
}
|
|
|
|
CString sys = GetItemText(GetParentItem(pItem)->m_nIndex, 0);
|
|
CString pipesys = GetItemText(iItem, 0);
|
|
|
|
if (m_CurSubItem == 1) // 颜色
|
|
{
|
|
int nClr(0);
|
|
CString sClr = GetItemText(iItem, m_CurSubItem);
|
|
if (Adesk::kTrue == acedSetColorDialog(nClr, TRUE, _ttoi(sClr)))
|
|
{
|
|
sClr.Format(_T("%d"), nClr);
|
|
CItemInfo *lp = GetData(pItem);
|
|
lp->SetSubItemText(m_CurSubItem - 1, sClr, acedGetRGB(nClr));
|
|
UpdateData(pItem, lp);
|
|
SetItemText(iItem, m_CurSubItem, sClr);
|
|
m_setOfModify.insert(sys);
|
|
return 1;
|
|
}
|
|
break;
|
|
}
|
|
else if (m_CurSubItem == 2) // 线形
|
|
{
|
|
AcDbObjectId id;
|
|
TCHAR *pszlinetypename = NULL;
|
|
if (acedLinetypeDialog(NULL, false, pszlinetypename, id))
|
|
{
|
|
CItemInfo *lp = GetData(pItem);
|
|
lp->SetSubItemText(m_CurSubItem - 1, pszlinetypename);
|
|
UpdateData(pItem, lp);
|
|
SetItemText(iItem, m_CurSubItem, pszlinetypename);
|
|
acutDelString(pszlinetypename);
|
|
m_setOfModify.insert(sys);
|
|
return 1;
|
|
}
|
|
break;
|
|
}
|
|
//else if (m_CurSubItem == 3)
|
|
//{
|
|
// CString sLw = GetItemText(iItem, m_CurSubItem);
|
|
// AcDb::LineWeight oldLw = CoreTools::String2LineWeight(sLw), lw;
|
|
// if (acedLineWeightDialog(oldLw, false, lw))
|
|
// {
|
|
// sLw = CoreTools::LineWeight2String(lw);
|
|
// CItemInfo *lp = GetData(pItem);
|
|
// lp->SetSubItemText(m_CurSubItem - 1, sLw);
|
|
// UpdateData(pItem, lp);
|
|
// SetItemText(iItem, m_CurSubItem, sLw);
|
|
// m_setOfModify.insert(sys);
|
|
// return 1;
|
|
// }
|
|
//}
|
|
else if (m_CurSubItem == 5 || m_CurSubItem == 3 || m_CurSubItem == 4)
|
|
{
|
|
EditLabelEx(iItem, m_CurSubItem);
|
|
m_setOfModify.insert(sys);
|
|
return 1;
|
|
}
|
|
else
|
|
break;
|
|
|
|
} while (false);
|
|
|
|
return CSuperGridCtrl::PreTranslateMessage(pMsg);
|
|
}
|
|
|
|
int CPipeSysSettingList::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
|
{
|
|
if (CSuperGridCtrl::OnCreate(lpCreateStruct) == -1)
|
|
return -1;
|
|
if (!m_image.Create(IDB_PIPE_SETTING_IMG, 16, 1, RGB(0, 255, 255)))
|
|
return -1;
|
|
|
|
SetImageList(&m_image, LVSIL_SMALL);
|
|
CImageList *pImageList = GetImageList(LVSIL_SMALL);
|
|
if (pImageList)
|
|
ImageList_GetIconSize(pImageList->m_hImageList, &m_cxImage, &m_cyImage);
|
|
else
|
|
return -1;
|
|
return 0;
|
|
}
|
|
|
|
BOOL CPipeSysSettingList::OnEndlabeledit(NMHDR *pNMHDR, LRESULT *pResult)
|
|
{
|
|
LV_DISPINFO *plvDispInfo = (LV_DISPINFO *)pNMHDR;
|
|
LV_ITEM *plvItem = &plvDispInfo->item;
|
|
|
|
CString oldSys = GetItemText(plvItem->iItem, 0);
|
|
|
|
// 得到改名前所有系统名称
|
|
std::set<CString> names;
|
|
int count = GetRootCount();
|
|
for (int i(0); i < count; ++i)
|
|
{
|
|
CTreeItem *pItem = GetRootItem(i);
|
|
if (!pItem) continue;
|
|
CItemInfo *pInfo = GetData(pItem);
|
|
if (!pInfo) continue;
|
|
names.insert(pInfo->GetItemText());
|
|
}
|
|
|
|
BOOL bRel = CSuperGridCtrl::OnEndlabeledit(pNMHDR, pResult);
|
|
|
|
CString newSys = GetItemText(plvItem->iItem, 0);
|
|
|
|
if (oldSys != newSys)
|
|
{
|
|
// 新系统名称存在
|
|
if (names.find(newSys) != names.end())
|
|
{
|
|
AfxMessageBox(_T("系统名称已经存在!"));
|
|
SetItemText(plvItem->iItem, 0, oldSys);
|
|
return TRUE;
|
|
}
|
|
m_mapOfSysModify.insert(std::make_pair(newSys, oldSys));
|
|
m_setOfModify.insert(newSys);
|
|
}
|
|
|
|
|
|
return bRel;
|
|
|
|
}
|
|
|