395 lines
9.0 KiB
C++
395 lines
9.0 KiB
C++
#include "stdafx.h"
|
||
#include "DbPsConfig.h"
|
||
|
||
ACRX_DXF_DEFINE_MEMBERS(ATSPsConfig, AcDbObject,AcDb::kDHL_CURRENT,
|
||
AcDb::kMReleaseCurrent,1, ATS_PSCONFIG,"ATS_PSCONFIG图形无法解析, 请下载上华软件|网址: www.shanghuasoft.com");
|
||
const Adesk::UInt8 TDbPsConfig::g_nVersion = 2;
|
||
|
||
Acad::ErrorStatus
|
||
TDbPsConfig::dwgInFields (AcDbDwgFiler* pFiler)
|
||
{
|
||
assertWriteEnabled();
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
es = AcDbObject::dwgInFields(pFiler);
|
||
if(es != Acad::eOk)
|
||
return es;
|
||
|
||
Adesk::UInt8 nVer=0;
|
||
pFiler->readItem(&nVer);
|
||
if(nVer>g_nVersion) {// Version is too new
|
||
return Acad::eMakeMeProxy;
|
||
}
|
||
|
||
pFiler->readItem(&m_dPipeTextDis);
|
||
pFiler->readItem(&m_dBreakWidth);
|
||
pFiler->readItem(&m_nLineWeight);
|
||
pFiler->readItem(&m_bBreakPipe);
|
||
pFiler->readItem(&m_nPipeOsnap);
|
||
pFiler->readItem(&m_nShowFlag);
|
||
pFiler->readItem(&m_nSysShowFlag1);
|
||
pFiler->readItem(&m_nSysShowFlag2);
|
||
|
||
// 备用数据
|
||
pFiler->readItem(&m_dSpare1);
|
||
pFiler->readItem(&m_dSpare2);
|
||
pFiler->readItem(&m_nSpare1);
|
||
pFiler->readItem(&m_nSpare2);
|
||
pFiler->readItem(&m_nSpare3);
|
||
pFiler->readItem(&m_nSpare4);
|
||
pFiler->readItem(&m_nSpare5);
|
||
|
||
// cet 2015.8.06 add 自定义管线系统
|
||
if (nVer > 1)
|
||
{
|
||
Adesk::UInt8 nSize = 0;
|
||
pFiler->readUInt8(&nSize);
|
||
XString sName;
|
||
bool bShow = true;
|
||
for (int i = 0; i < nSize; ++i)
|
||
{
|
||
ReadString(pFiler, sName);
|
||
pFiler->readBool(&bShow);
|
||
m_mapSystem.insert(std::make_pair(CString(sName), bShow));
|
||
}
|
||
}
|
||
return pFiler->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
TDbPsConfig::dwgOutFields(AcDbDwgFiler* pFiler) const
|
||
{
|
||
assertReadEnabled();
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
es = AcDbObject::dwgOutFields(pFiler);
|
||
if(es != Acad::eOk)
|
||
return es;
|
||
|
||
if (g_nSaveTArchVer <= 10)
|
||
{
|
||
pFiler->writeItem((Adesk::UInt8)1);
|
||
}
|
||
else
|
||
{
|
||
pFiler->writeItem(g_nVersion);
|
||
}
|
||
pFiler->writeItem(m_dPipeTextDis);
|
||
pFiler->writeItem(m_dBreakWidth);
|
||
pFiler->writeItem(m_nLineWeight);
|
||
pFiler->writeItem(m_bBreakPipe);
|
||
pFiler->writeItem(m_nPipeOsnap);
|
||
pFiler->writeItem(m_nShowFlag);
|
||
pFiler->writeItem(m_nSysShowFlag1);
|
||
pFiler->writeItem(m_nSysShowFlag2);
|
||
|
||
// 备用数据
|
||
pFiler->writeItem(m_dSpare1);
|
||
pFiler->writeItem(m_dSpare2);
|
||
pFiler->writeItem(m_nSpare1);
|
||
pFiler->writeItem(m_nSpare2);
|
||
pFiler->writeItem(m_nSpare3);
|
||
pFiler->writeItem(m_nSpare4);
|
||
pFiler->writeItem(m_nSpare5);
|
||
|
||
// cet 2015.8.06 add 自定义管线系统
|
||
if (g_nSaveTArchVer > 10)
|
||
{
|
||
Adesk::UInt8 nSize = m_mapSystem.size();
|
||
pFiler->writeUInt8(nSize);
|
||
std::map<CString,bool>::const_iterator it, itEnd = m_mapSystem.end();
|
||
for (it = m_mapSystem.begin(); it != itEnd; ++it)
|
||
{
|
||
pFiler->writeItem((const TCHAR *)it->first);
|
||
pFiler->writeBool(it->second);
|
||
}
|
||
}
|
||
return pFiler->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
TDbPsConfig::dxfInFields (AcDbDxfFiler* pFiler)
|
||
{
|
||
assertWriteEnabled();
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
es = AcDbObject::dxfInFields(pFiler);
|
||
if(es!=Acad::eOk)
|
||
return es;
|
||
|
||
if (!pFiler->atSubclassData(_T("TDbPsConfig"))) {
|
||
return Acad::eBadDxfSequence;
|
||
}
|
||
|
||
return pFiler->filerStatus();
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
TDbPsConfig::dxfOutFields(AcDbDxfFiler* pFiler) const
|
||
{
|
||
assertReadEnabled();
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
es = AcDbObject::dxfOutFields(pFiler);
|
||
assert(es == Acad::eOk);
|
||
es = pFiler->writeItem(AcDb::kDxfSubclass,_T("TDbPsConfig"));
|
||
assert(es == Acad::eOk);
|
||
|
||
return es;
|
||
}
|
||
|
||
Acad::ErrorStatus
|
||
TDbPsConfig::subWblockClone(AcRxObject* pOwner,
|
||
AcDbObject*& pClonedObject,
|
||
AcDbIdMapping& idMap,
|
||
Adesk::Boolean isPrimary) const
|
||
{
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
es = AcDbObject::wblockClone(pOwner, pClonedObject, idMap, isPrimary);
|
||
// cet 2015.7.24 modify 需要返回eok,否则该函数被调用时会崩溃
|
||
// 基类返回状态值为“未实现该函数”,重载后不可返回该值
|
||
// if(es!=Acad::eOk)
|
||
// return es;
|
||
//
|
||
// //待写...
|
||
//
|
||
// return es;
|
||
return Acad::eOk;
|
||
}
|
||
|
||
BOOL TDbPsConfig::IsSystemShow(TPipeSys::SysType sysType) const
|
||
{
|
||
int nSysType = (int)sysType;
|
||
Adesk::UInt32 nShowFlag = nSysType<32 ? m_nSysShowFlag1 : m_nSysShowFlag2;//Adesk::UInt32 &nShowFlag sr 2009-11-2取消&,VC9上编译不通过
|
||
nSysType = nSysType%32;
|
||
Adesk::UInt32 nBit = (Adesk::UInt32)pow(2.0,nSysType);
|
||
return !(nShowFlag&nBit)!=0;
|
||
}
|
||
|
||
void TDbPsConfig::ShowSystem(TPipeSys::SysType sysType,BOOL bFlag)
|
||
{
|
||
assertWriteEnabled();
|
||
int nSysType = (int)sysType;
|
||
Adesk::UInt32 &nShowFlag = nSysType<32 ? m_nSysShowFlag1 : m_nSysShowFlag2;
|
||
nSysType = nSysType%32;
|
||
Adesk::UInt32 nBit = (Adesk::UInt32)pow(2.0,nSysType);
|
||
if(!bFlag)
|
||
nShowFlag |= nBit;
|
||
else
|
||
nShowFlag &= ~nBit;
|
||
}
|
||
|
||
// 管线加粗
|
||
void TDbPsConfig::SetLineWeight(BOOL bFlag)
|
||
{
|
||
assertWriteEnabled();
|
||
if(bFlag)
|
||
m_nLineWeight |= WEIGHT_PIPE;
|
||
else
|
||
m_nLineWeight &= ~WEIGHT_PIPE;
|
||
}
|
||
|
||
// 散热器加粗
|
||
void TDbPsConfig::SetRadiatorWeight(BOOL bFlag)
|
||
{
|
||
assertWriteEnabled();
|
||
if(bFlag)
|
||
m_nLineWeight |= WEIGHT_RADIATOR;
|
||
else
|
||
m_nLineWeight &= ~WEIGHT_RADIATOR;
|
||
}
|
||
|
||
// 盘管加粗
|
||
void TDbPsConfig::SetFloorWeight(BOOL bWeight)
|
||
{
|
||
assertWriteEnabled();
|
||
// cet 2016.8.16 modify 此变量多处使用,按位设置标识
|
||
// m_nSpare3 = bWeight;
|
||
if (bWeight)
|
||
{
|
||
m_nSpare3 |= 0x0004;
|
||
}
|
||
else
|
||
{
|
||
m_nSpare3 &= ~0x0004;
|
||
}
|
||
}
|
||
|
||
void TDbPsConfig::ShowPipeFlowDir(BOOL bFlag)
|
||
{
|
||
assertWriteEnabled();
|
||
if(bFlag)
|
||
m_nShowFlag |= SHOW_PIPEDIR;
|
||
else
|
||
m_nShowFlag &= ~SHOW_PIPEDIR;
|
||
}
|
||
|
||
BOOL TDbPsConfig::IsShowPipeCanalMidLine() const
|
||
{
|
||
bool bRet =((m_nSpare3 & 0x0001) > 0) ? false : true;
|
||
return bRet;
|
||
}
|
||
|
||
void TDbPsConfig::ShowPipeCanalMinLine( BOOL bShow )
|
||
{
|
||
assertWriteEnabled();
|
||
if (!bShow)
|
||
{
|
||
m_nSpare3 |= 0x0001;
|
||
}
|
||
else
|
||
{
|
||
m_nSpare3 &= ~0x0001;
|
||
}
|
||
}
|
||
|
||
BOOL TDbPsConfig::IsRelatePipeLineTypeToCurPScale() const
|
||
{
|
||
bool bRet =((m_nSpare3 & 0x0002) > 0) ? false : true;
|
||
return bRet;
|
||
}
|
||
|
||
void TDbPsConfig::RelatePipeLineTypeToCurPScale( bool bReated )
|
||
{
|
||
assertWriteEnabled();
|
||
if (!bReated)
|
||
{
|
||
m_nSpare3 |= 0x0002;
|
||
}
|
||
else
|
||
{
|
||
m_nSpare3 &= ~0x0002;
|
||
}
|
||
}
|
||
|
||
void TDbPsConfig::ShowCustomPipeSystem(const CString &sSysName, bool bShow)
|
||
{
|
||
m_mapSystem[sSysName] = bShow;
|
||
}
|
||
|
||
void TDbPsConfig::CleanAllCustomPipeSystem()
|
||
{
|
||
m_mapSystem.clear();
|
||
}
|
||
|
||
bool TDbPsConfig::IsShowCustomPipeSystem(const CString &sSysName)
|
||
{
|
||
if (m_mapSystem.find(sSysName) == m_mapSystem.end())
|
||
{
|
||
return true;
|
||
}
|
||
return m_mapSystem[sSysName];
|
||
}
|
||
|
||
bool TDbPsConfig::IsShowPipeCanalLineWeight() const
|
||
{
|
||
return (m_nLineWeight & WEIGHT_CANAL) != 0;
|
||
}
|
||
|
||
void TDbPsConfig::ShowPipeCanalLineWeight(bool bShow)
|
||
{
|
||
assertWriteEnabled();
|
||
if(bShow)
|
||
m_nLineWeight |= WEIGHT_CANAL;
|
||
else
|
||
m_nLineWeight &= ~WEIGHT_CANAL;
|
||
}
|
||
|
||
bool TDbPsConfig::IsClosePipeCancalPointEnd() const
|
||
{
|
||
return (m_nLineWeight & CLOSE_CANAL_POINTEND) != 0;
|
||
}
|
||
|
||
void TDbPsConfig::ClosePipeCanalPointEnd(bool bClose)
|
||
{
|
||
assertWriteEnabled();
|
||
if(bClose)
|
||
m_nLineWeight |= CLOSE_CANAL_POINTEND;
|
||
else
|
||
m_nLineWeight &= ~CLOSE_CANAL_POINTEND;
|
||
}
|
||
|
||
void InitDbPsConfig(BOOL bTrue)
|
||
{
|
||
if(bTrue) {
|
||
TDbPsConfig::rxInit();
|
||
} else {
|
||
deleteAcRxClass(TDbPsConfig::desc());
|
||
}
|
||
}
|
||
|
||
// 初始化全局变量
|
||
void InitDbPsConfig()
|
||
{
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
|
||
AcDbDatabase *pDb = curDoc()->database();
|
||
if(pDb==NULL) return;
|
||
//assert(pDb!=NULL);
|
||
|
||
AcDbDictionary* pRootDict=NULL;
|
||
es=pDb->getNamedObjectsDictionary(pRootDict,AcDb::kForRead);
|
||
assert(es==Acad::eOk);
|
||
|
||
AcDbObject* pObj;
|
||
es=pRootDict->getAt(g_sDbPsConfig,pObj,AcDb::kForRead);
|
||
if (es==Acad::eOk) {
|
||
pObj->close();
|
||
} else {//当前数据库未初始化全局变量
|
||
if (pRootDict->upgradeOpen() == Acad::eOk) {
|
||
pRootDict->assertWriteEnabled();
|
||
TDbPsConfig *pConfig = new TDbPsConfig;
|
||
if (pConfig!=NULL) {
|
||
AcDbObjectId idConfig;
|
||
es=pRootDict->setAt(g_sDbPsConfig,pConfig,idConfig);
|
||
//assert(es==Acad::eOk);
|
||
if (es==Acad::eOk) {
|
||
pConfig->close();
|
||
} else {
|
||
delete pConfig;
|
||
}
|
||
}
|
||
pRootDict->downgradeOpen();
|
||
}
|
||
}
|
||
pRootDict->close();
|
||
}
|
||
|
||
// 保存DWG全局变量的指针
|
||
TDbPsConfig * GetDwgPsGlobal(AcDb::OpenMode opMode, AcDbDatabase *pDb/*=NULL*/)
|
||
{
|
||
TDbPsConfig *pConfig=NULL;
|
||
|
||
if (pDb==NULL) //当前数据库
|
||
pDb = curDoc()->database();
|
||
|
||
if (pDb!=NULL) {
|
||
Acad::ErrorStatus es=Acad::eOk;
|
||
AcDbDictionary* pRootDict=NULL;
|
||
es=pDb->getNamedObjectsDictionary(pRootDict,AcDb::kForRead);
|
||
if (es==Acad::eOk) {
|
||
AcDbObjectId idExist;
|
||
es=pRootDict->getAt(g_sDbPsConfig, idExist);
|
||
if (es==Acad::eOk && !!idExist) {
|
||
es=acdbOpenObject(pConfig, idExist, opMode);
|
||
// cet 2015.8.03 add 某用户反馈的问题,有张dwg图无法打开对象进行操作,故删除该对象以给予重新创建改对象并赋值的机会
|
||
if (es == Acad::eNotThatKindOfClass && pRootDict->upgradeOpen() == Acad::eOk)
|
||
{
|
||
es = pRootDict->remove(g_sDbPsConfig);
|
||
pRootDict->downgradeOpen();
|
||
}
|
||
}
|
||
else if(opMode==AcDb::kForWrite) {
|
||
if ((es = pRootDict->upgradeOpen()) == Acad::eOk) {
|
||
pRootDict->assertWriteEnabled();
|
||
pConfig = new TDbPsConfig;
|
||
if (pConfig!=NULL) {
|
||
AcDbObjectId idConfig;
|
||
es=pRootDict->setAt(g_sDbPsConfig,pConfig,idConfig);
|
||
ASSERT(es==Acad::eOk);
|
||
}
|
||
pRootDict->downgradeOpen();
|
||
}
|
||
}
|
||
pRootDict->close();
|
||
}
|
||
}
|
||
return pConfig;
|
||
}
|