1330 lines
35 KiB
C++
1330 lines
35 KiB
C++
#include "StdAfx.h"
|
|
#include <acly.h>
|
|
#include "TDocCreateLayer.h"
|
|
#import "msxml6.dll"
|
|
#include "utility.h"
|
|
|
|
using namespace MSXML2;
|
|
|
|
namespace
|
|
{
|
|
//int CompareString( const CString& strFirst, const CString& strSecond )
|
|
//{
|
|
// int nRet = CompareString(GetThreadLocale(),
|
|
// NORM_IGNOREWIDTH|SORT_STRINGSORT, strFirst,strFirst.GetLength(), strSecond, strSecond.GetLength()/*, NULL, NULL, 0*/);
|
|
// if(nRet == CSTR_LESS_THAN) //升序
|
|
// return -1;
|
|
// else if(nRet == CSTR_GREATER_THAN)
|
|
// return 1;
|
|
// else
|
|
// return 0;
|
|
//}
|
|
|
|
bool JudgeDocIsNewOrExist()
|
|
{
|
|
CString sDwgName = curDoc()->fileName();
|
|
int iIndex = sDwgName.Find(_T(":"));
|
|
if (iIndex < 0)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
MSXML2::IXMLDOMDocument2Ptr LoadXMLFile( LPCTSTR path)
|
|
{
|
|
do{
|
|
::CoInitialize(NULL);
|
|
MSXML2::IXMLDOMDocument2Ptr pXMLDoc;
|
|
HRESULT hr = pXMLDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60));
|
|
if (!SUCCEEDED(hr)) break;
|
|
pXMLDoc->async = false;
|
|
pXMLDoc->validateOnParse = true;
|
|
if (pXMLDoc->load(_bstr_t(path)) != VARIANT_TRUE) break;
|
|
return pXMLDoc;
|
|
}while(false);
|
|
return NULL;
|
|
}
|
|
|
|
void AddLayerNameToFilterGroup(CString sLayerNameVec, SLayerGrpRecord *pGrpRecord)
|
|
{
|
|
int iIndex(0);
|
|
CString sLayerName(_T(""));
|
|
iIndex = sLayerNameVec.Find(_T('*'));
|
|
if(iIndex < 0)
|
|
{
|
|
pGrpRecord->arContainLayerName.push_back(sLayerNameVec);
|
|
}
|
|
else
|
|
{
|
|
sLayerName = sLayerNameVec.Left(iIndex);
|
|
pGrpRecord->arContainLayerName.push_back(sLayerName);
|
|
sLayerNameVec = sLayerNameVec.Right(sLayerNameVec.GetLength() - iIndex - 1);
|
|
if (sLayerNameVec.GetLength() != 0)
|
|
{
|
|
AddLayerNameToFilterGroup(sLayerNameVec, pGrpRecord);
|
|
}
|
|
}
|
|
}
|
|
|
|
void ReadXMLFileToGetChildNode(SLayerGrpRecord *pParent, MSXML2::IXMLDOMNodeListPtr pGrps)
|
|
{
|
|
MSXML2::IXMLDOMNodePtr pGrp = pGrps->nextNode();
|
|
CString strNodeName(_T(""));
|
|
CString sLayerName(_T(""));
|
|
MSXML2::IXMLDOMNodePtr pNodePtrValue(NULL);
|
|
MSXML2::IXMLDOMNamedNodeMapPtr pMap(NULL);
|
|
MSXML2::IXMLDOMNodeListPtr pChildListNode(NULL);
|
|
while (pGrp)
|
|
{
|
|
pMap = pGrp->Getattributes();
|
|
if(!pMap)
|
|
continue;
|
|
pNodePtrValue = pMap->getNamedItem((LPCTSTR)TARCH_LAYER_GROUP_NODE_VALUE_CSTRING);
|
|
if(!pNodePtrValue)
|
|
continue;
|
|
strNodeName = pNodePtrValue->GetnodeValue();
|
|
SLayerGrpRecord *pChild = new SLayerGrpRecord(strNodeName, pParent);
|
|
pParent->arLayerGrpChild.push_back(pChild);
|
|
pNodePtrValue = pMap->getNamedItem((LPCTSTR)TARCH_LAYER_GROUP_NODE_LAYERNAME_CSTRING);
|
|
if(pNodePtrValue)
|
|
{
|
|
strNodeName = pNodePtrValue->GetnodeValue();
|
|
if (strNodeName.GetLength() != 0)
|
|
{
|
|
AddLayerNameToFilterGroup(strNodeName, pChild);
|
|
}
|
|
}
|
|
pChildListNode = pGrp->GetchildNodes();
|
|
ReadXMLFileToGetChildNode(pChild, pChildListNode);
|
|
pGrp = pGrps->nextNode();
|
|
}
|
|
}
|
|
|
|
void ReadXMLFileToGetGrpFilterSort(MSXML2::IXMLDOMNodeListPtr pGrps, int& iSort)
|
|
{
|
|
MSXML2::IXMLDOMNodePtr pGrp = pGrps->nextNode();
|
|
CString strNodeName(_T(""));
|
|
MSXML2::IXMLDOMNodePtr pNodePtrValue(NULL);
|
|
MSXML2::IXMLDOMNamedNodeMapPtr pMap(NULL);
|
|
MSXML2::IXMLDOMNodeListPtr pChildListNode(NULL);
|
|
while (pGrp)
|
|
{
|
|
pMap = pGrp->Getattributes();
|
|
if(!pMap)
|
|
continue;
|
|
pNodePtrValue = pMap->getNamedItem((LPCTSTR)TARCH_LAYER_GROUP_NODE_VALUE_CSTRING);
|
|
if(!pNodePtrValue)
|
|
continue;
|
|
strNodeName = pNodePtrValue->GetnodeValue();
|
|
if (!strNodeName.IsEmpty())
|
|
{
|
|
iSort = _ttoi(strNodeName);
|
|
break;
|
|
}
|
|
pGrp = pGrps->nextNode();
|
|
}
|
|
}
|
|
|
|
int SetNumberOfSliderControl(int iNumber)
|
|
{
|
|
double dSwap(0.000);
|
|
int iSwap(0);
|
|
dSwap = (double)(255 * 20 - 20 * iNumber) / 51.000;
|
|
iSwap = (int)dSwap;
|
|
return iSwap;
|
|
}
|
|
|
|
bool CompareStringSort(const CString& strFirst, const CString& strSecond)
|
|
{
|
|
int rel = utility::CompareString(strFirst, strSecond);
|
|
if (rel >= 0)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
|
|
bool CompareColorByString(CString sColorL, CString sColorR, bool bAscending, CString sNameL, CString sNameR)
|
|
{
|
|
int iColorL(0), iColorR(0);
|
|
if (sColorL.Find(_T(',')) >= 0 && sColorR.Find(_T(',')) >= 0)
|
|
{
|
|
int iIndexL = sColorL.Find(_T(','));
|
|
int iIndexR = sColorR.Find(_T(','));
|
|
CString sAL(sColorL.Left(iIndexL)), sAR(sColorR.Left(iIndexR));
|
|
if (sAL.CompareNoCase(sAR))
|
|
{
|
|
iColorL = _ttoi(sAL);
|
|
iColorR = _ttoi(sAR);
|
|
if (bAscending)
|
|
return iColorL < iColorR;
|
|
else
|
|
return iColorL > iColorR;
|
|
}
|
|
else
|
|
{
|
|
sColorL = sColorL.Right(sColorL.GetLength() - iIndexL - 1);
|
|
sColorR = sColorR.Right(sColorR.GetLength() - iIndexR - 1);
|
|
iIndexL = sColorL.Find(_T(','));
|
|
iIndexR = sColorR.Find(_T(','));
|
|
sAL = sColorL.Left(iIndexL);
|
|
sAR = sColorR.Left(iIndexR);
|
|
if (sAL.CompareNoCase(sAR))
|
|
{
|
|
iColorL = _ttoi(sAL);
|
|
iColorR = _ttoi(sAR);
|
|
if (bAscending)
|
|
return iColorL < iColorR;
|
|
else
|
|
return iColorL > iColorR;
|
|
}
|
|
else
|
|
{
|
|
sAL = sColorL.Right(sColorL.GetLength() - iIndexL - 1);
|
|
sAR = sColorR.Right(sColorR.GetLength() - iIndexR - 1);
|
|
if (sAL.CompareNoCase(sAR))
|
|
{
|
|
iColorL = _ttoi(sAL);
|
|
iColorR = _ttoi(sAR);
|
|
if (bAscending)
|
|
return iColorL < iColorR;
|
|
else
|
|
return iColorL > iColorR;
|
|
}
|
|
else
|
|
{
|
|
if (bAscending)
|
|
return sNameL > sNameR;
|
|
else
|
|
return sNameL < sNameR;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if(sColorL.Find(_T(',')) >= 0 && sColorR.Find(_T(',')) < 0)
|
|
{
|
|
if (bAscending)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
else if (sColorL.Find(_T(',')) < 0 && sColorR.Find(_T(',')) >= 0)
|
|
{
|
|
if (bAscending)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
if(sColorL == _T("红"))
|
|
iColorL = 1;
|
|
else if(sColorL == _T("黄"))
|
|
iColorL = 2;
|
|
else if(sColorL == _T("绿"))
|
|
iColorL = 3;
|
|
else if(sColorL == _T("青"))
|
|
iColorL = 4;
|
|
else if(sColorL == _T("蓝"))
|
|
iColorL = 5;
|
|
else if(sColorL == _T("洋红"))
|
|
iColorL = 6;
|
|
else if(sColorL == _T("白") || sColorL == _T("黑"))
|
|
iColorL = 7;
|
|
else
|
|
iColorL = _ttoi(sColorL);
|
|
|
|
if(sColorR == _T("红"))
|
|
iColorR = 1;
|
|
else if(sColorR == _T("黄"))
|
|
iColorR = 2;
|
|
else if(sColorR == _T("绿"))
|
|
iColorR = 3;
|
|
else if(sColorR == _T("青"))
|
|
iColorR = 4;
|
|
else if(sColorR == _T("蓝"))
|
|
iColorR = 5;
|
|
else if(sColorR == _T("洋红"))
|
|
iColorR = 6;
|
|
else if(sColorR == _T("白") || sColorR == _T("黑"))
|
|
iColorR = 7;
|
|
else
|
|
iColorR = _ttoi(sColorR);
|
|
|
|
if (iColorL == iColorR)
|
|
{
|
|
if (bAscending)
|
|
return sNameL > sNameR;
|
|
else
|
|
return sNameL < sNameR;
|
|
}
|
|
else
|
|
{
|
|
if (bAscending)
|
|
return iColorL < iColorR;
|
|
else
|
|
return iColorL > iColorR;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool IsColorByIndex(AcCmColor &cmclr)
|
|
{
|
|
return cmclr.isByACI();
|
|
}
|
|
|
|
bool IsColorByRGB(AcCmColor &cmclr)
|
|
{
|
|
if (!cmclr.isByColor()) return false;
|
|
const TCHAR *psz = cmclr.colorName();
|
|
if (!psz) return true;
|
|
CString str(psz);
|
|
return str.IsEmpty() ? true : false;
|
|
}
|
|
|
|
bool IsColorByPeise(AcCmColor &cmclr) // 配色
|
|
{
|
|
if (!cmclr.isByColor()) return false;
|
|
const TCHAR *psz = cmclr.colorName(); // 只有 colorName() 得到的指针可能为空 详见ARX文档
|
|
if (!psz) return false;
|
|
CString str1(psz), str2(cmclr.colorNameForDisplay());
|
|
if (str1.CompareNoCase(str2) == 0 && !str1.IsEmpty())
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
bool sort_by_peise(AcCmColor& obj1, AcCmColor& obj2, bool bAscending, CString sLayerNameL, CString sLayerNameR)
|
|
{
|
|
CString sColorL(obj1.colorNameForDisplay()), sColorR(obj2.colorNameForDisplay());
|
|
if (sColorL.CompareNoCase(sColorR))
|
|
{
|
|
if(utility::CompareString(sColorL, sColorR) == -1)
|
|
{
|
|
if (bAscending)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
if (bAscending)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (utility::CompareString(sLayerNameL, sLayerNameR) == -1)
|
|
{
|
|
if (bAscending)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
if (bAscending)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool sort_by_index(const AcCmColor& obj1, const AcCmColor& obj2, bool bAscending, CString sLayerNameL, CString sLayerNameR)
|
|
{
|
|
if (obj1.colorIndex() != obj2.colorIndex())
|
|
{
|
|
if(bAscending)
|
|
return obj1.colorIndex() < obj2.colorIndex();
|
|
else
|
|
return obj1.colorIndex() > obj2.colorIndex();
|
|
}
|
|
else
|
|
{
|
|
if (utility::CompareString(sLayerNameL, sLayerNameR) == -1)
|
|
{
|
|
if (bAscending)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
if (bAscending)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool sort_by_rgb(AcCmColor& obj1, AcCmColor& obj2, bool bAscending, CString sLayerNameL, CString sLayerNameR)
|
|
{
|
|
CString sColorL(obj1.colorNameForDisplay()), sColorR(obj2.colorNameForDisplay());
|
|
int iColorL(0), iColorR(0);
|
|
int iIndexL = sColorL.Find(_T(','));
|
|
int iIndexR = sColorR.Find(_T(','));
|
|
CString sAL(sColorL.Left(iIndexL)), sAR(sColorR.Left(iIndexR));
|
|
if (sAL.CompareNoCase(sAR))
|
|
{
|
|
iColorL = _ttoi(sAL);
|
|
iColorR = _ttoi(sAR);
|
|
if (bAscending)
|
|
return iColorL < iColorR;
|
|
else
|
|
return iColorL > iColorR;
|
|
}
|
|
else
|
|
{
|
|
sColorL = sColorL.Right(sColorL.GetLength() - iIndexL - 1);
|
|
sColorR = sColorR.Right(sColorR.GetLength() - iIndexR - 1);
|
|
iIndexL = sColorL.Find(_T(','));
|
|
iIndexR = sColorR.Find(_T(','));
|
|
sAL = sColorL.Left(iIndexL);
|
|
sAR = sColorR.Left(iIndexR);
|
|
if (sAL.CompareNoCase(sAR))
|
|
{
|
|
iColorL = _ttoi(sAL);
|
|
iColorR = _ttoi(sAR);
|
|
if (bAscending)
|
|
return iColorL < iColorR;
|
|
else
|
|
return iColorL > iColorR;
|
|
}
|
|
else
|
|
{
|
|
sAL = sColorL.Right(sColorL.GetLength() - iIndexL - 1);
|
|
sAR = sColorR.Right(sColorR.GetLength() - iIndexR - 1);
|
|
if (sAL.CompareNoCase(sAR))
|
|
{
|
|
iColorL = _ttoi(sAL);
|
|
iColorR = _ttoi(sAR);
|
|
if (bAscending)
|
|
return iColorL < iColorR;
|
|
else
|
|
return iColorL > iColorR;
|
|
}
|
|
else
|
|
{
|
|
if (utility::CompareString(sLayerNameL, sLayerNameR) == -1)
|
|
{
|
|
if (bAscending)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
if (bAscending)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool CompareColorSort(SLayerRecord *pLayerL, SLayerRecord *pLayerR, bool bAscending)
|
|
{
|
|
if (IsColorByIndex(pLayerL->cmColor) && !IsColorByIndex(pLayerR->cmColor))
|
|
{
|
|
if (bAscending)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
else if (IsColorByIndex(pLayerL->cmColor) && IsColorByIndex(pLayerR->cmColor))
|
|
return sort_by_index(pLayerL->cmColor, pLayerR->cmColor, bAscending, pLayerL->sLayerName, pLayerR->sLayerName);
|
|
else if (IsColorByRGB(pLayerL->cmColor) && IsColorByIndex(pLayerR->cmColor))
|
|
{
|
|
if (bAscending)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
else if (IsColorByRGB(pLayerL->cmColor) && IsColorByRGB(pLayerR->cmColor))
|
|
return sort_by_rgb(pLayerL->cmColor, pLayerR->cmColor, bAscending, pLayerL->sLayerName, pLayerR->sLayerName);
|
|
else if (IsColorByRGB(pLayerL->cmColor) && IsColorByPeise(pLayerR->cmColor))
|
|
{
|
|
if (bAscending)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
else if (IsColorByPeise(pLayerL->cmColor) && !IsColorByPeise(pLayerR->cmColor))
|
|
{
|
|
if (bAscending)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
else if (IsColorByPeise(pLayerL->cmColor) && IsColorByPeise(pLayerR->cmColor))
|
|
return sort_by_peise(pLayerL->cmColor, pLayerR->cmColor, bAscending, pLayerL->sLayerName, pLayerR->sLayerName);
|
|
}
|
|
}
|
|
|
|
void CreateLayerForNewDoc(AcDbDatabase* pCurDocData)
|
|
{
|
|
if (JudgeDocIsNewOrExist())
|
|
{
|
|
TDocCreateLayer docLay(pCurDocData);
|
|
docLay.DoCreateDocLayer();
|
|
}
|
|
}
|
|
|
|
TDocCreateLayer::TDocCreateLayer(AcDbDatabase* pDatabase)
|
|
{
|
|
m_bWhetherCreatStandardLayer = false;
|
|
m_pDatabase = pDatabase;
|
|
m_sInstallDirectory = utility::GetInstallDir();
|
|
m_bRegistryIsExist = true;
|
|
m_bTarchLayIsExist = true;
|
|
m_bFilterIsExist = true;
|
|
m_bNotCreatLayer = true;
|
|
m_bValidModify = true;
|
|
m_iGrpFilterSort = 0;
|
|
|
|
m_arStandardLayerRecord.clear();
|
|
m_arSystemGrpFilter.clear();
|
|
m_arNotCreatStandardLayer.clear();
|
|
m_pCurLayerRecordHeader.clear();
|
|
m_arAllDocLayerRecordParamNumHeader.clear();
|
|
}
|
|
TDocCreateLayer::~TDocCreateLayer()
|
|
{
|
|
|
|
}
|
|
|
|
void TDocCreateLayer::InitJudgeRegistryIsWhole()
|
|
{
|
|
m_sInstallDirectory = utility::GetInstallDir();
|
|
if (m_sInstallDirectory.IsEmpty())
|
|
{
|
|
m_bRegistryIsExist = false;
|
|
return;
|
|
}
|
|
m_bRegistryIsExist = true;
|
|
}
|
|
|
|
void TDocCreateLayer::InitarSystemGrpFilter()
|
|
{
|
|
AcLyLayerFilterManager *pAclyMager = aclyGetLayerFilterManager(m_pDatabase);
|
|
if (!pAclyMager)
|
|
{
|
|
return;
|
|
}
|
|
AcLyLayerFilter *pFilterRoot(NULL);
|
|
AcLyLayerFilter *pFilterCur(NULL);
|
|
Acad::ErrorStatus bOk(Acad::eOk);
|
|
bOk = pAclyMager->getFilters(pFilterRoot, pFilterCur);
|
|
if (bOk != Acad::eOk)
|
|
{
|
|
return;
|
|
}
|
|
if(!pFilterRoot)
|
|
{
|
|
return;
|
|
}
|
|
InitarSystemGrpFilterImplementationDetails(pFilterRoot);
|
|
|
|
}
|
|
void TDocCreateLayer::GetCurFilterGrpNameByCAD()
|
|
{
|
|
AcLyLayerFilterManager *pAclyMager = aclyGetLayerFilterManager(m_pDatabase);
|
|
if (!pAclyMager)
|
|
{
|
|
return;
|
|
}
|
|
Acad::ErrorStatus bError(Acad::eOk);
|
|
AcLyLayerFilter *pFilterRoot(NULL);
|
|
AcLyLayerFilter *pFilterCurRoot(NULL);
|
|
bError = pAclyMager->getFilters(pFilterRoot, pFilterCurRoot);
|
|
if (bError != Acad::eOk)
|
|
{
|
|
return;
|
|
}
|
|
if (pFilterCurRoot)
|
|
{
|
|
m_sCurFilterGrpName = pFilterCurRoot->name();
|
|
}
|
|
else
|
|
{
|
|
m_sCurFilterGrpName = _T("");
|
|
}
|
|
}
|
|
void TDocCreateLayer::InitFirstSetGrpFilter()
|
|
{
|
|
TDocAutoLock lock;
|
|
AcLyLayerFilterManager *pAclyMager = aclyGetLayerFilterManager(m_pDatabase);
|
|
if (!pAclyMager)
|
|
{
|
|
return;
|
|
}
|
|
Acad::ErrorStatus bError(Acad::eOk);
|
|
AcLyLayerFilter *pFilterRoot(NULL);
|
|
AcLyLayerFilter *pFilterCurRoot(NULL);
|
|
bError = pAclyMager->getFilters(pFilterRoot, pFilterCurRoot);
|
|
if (bError != Acad::eOk)
|
|
{
|
|
return;
|
|
}
|
|
bError = pAclyMager->setFilters(pFilterRoot, pFilterRoot);
|
|
m_sCurFilterGrpName = pFilterRoot->name();
|
|
}
|
|
|
|
void TDocCreateLayer::InitarSystemGrpFilterImplementationDetails(AcLyLayerFilter *pFilter)
|
|
{
|
|
AcArray<AcLyLayerFilter*> arRootFilters = pFilter->getNestedFilters();
|
|
CString sName(_T(""));
|
|
for (int i = 0; i < arRootFilters.length(); ++i)
|
|
{
|
|
sName = arRootFilters[i]->name();
|
|
if (sName.CompareNoCase(_T("所有使用的图层")))
|
|
{
|
|
m_arSystemGrpFilter.push_back(sName);
|
|
}
|
|
InitarSystemGrpFilterImplementationDetails(arRootFilters[i]);
|
|
}
|
|
}
|
|
|
|
void TDocCreateLayer::InitWhetherCreatStandard()
|
|
{
|
|
CString sNotCreatStandardLayerPath = m_sInstallDirectory + TARCH_INSTALL_DIRECTORY_INCLUDE_SYS + TARCH_LAYER_NOT_CAEAT_STANDARD_LAYER;
|
|
CFileFind finder;
|
|
BOOL bIsExist = finder.FindFile(sNotCreatStandardLayerPath);
|
|
if (!bIsExist)
|
|
{
|
|
CString str = sNotCreatStandardLayerPath;
|
|
str += _T("文件不存在");
|
|
AfxMessageBox(str);
|
|
m_bNotCreatLayer = false;
|
|
m_bWhetherCreatStandardLayer= true;
|
|
return;
|
|
}
|
|
setlocale(0,"chs");
|
|
CStdioFile *fp(NULL);
|
|
fp = new CStdioFile(sNotCreatStandardLayerPath, CFile::modeRead);
|
|
CString sReadWords(_T(""));
|
|
fp->ReadString(sReadWords);
|
|
if (!sReadWords.CompareNoCase(_T("是否需要生成图层_No")))
|
|
{
|
|
m_bWhetherCreatStandardLayer = false;
|
|
}
|
|
else
|
|
{
|
|
m_bWhetherCreatStandardLayer = true;
|
|
}
|
|
fp->Close();
|
|
deletePtr(fp);
|
|
}
|
|
|
|
void TDocCreateLayer::InitStandardGrpRoot()
|
|
{
|
|
MSXML2::IXMLDOMDocumentPtr pDoc;
|
|
HRESULT hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument60));
|
|
if(!SUCCEEDED(hr))
|
|
{
|
|
CString str(_T("无法创建DOMDocument对象,请检查是否安装了MS XML Parser 运行库!"));
|
|
AfxMessageBox(str);
|
|
//GlwLayerWarnMessageBox WndDlgLayerNotDeleteWarn(str, acedGetAcadFrame());
|
|
//WndDlgLayerNotDeleteWarn.DoModal(WS_POPUP | WS_CAPTION
|
|
// | WS_SYSMENU, NULL, acedGetAcadFrame());
|
|
return;
|
|
}
|
|
CString sLayerGrpXml = m_sInstallDirectory + TARCH_INSTALL_DIRECTORY_INCLUDE_SYS + TARCH_LAYER_GROUP_FILE_NAME_XML;
|
|
CFileFind finder;
|
|
BOOL bIsExist = finder.FindFile(sLayerGrpXml); //查看安装路径下的图层标准文件是否存在
|
|
if (!bIsExist)
|
|
{
|
|
CString str = sLayerGrpXml;
|
|
str += _T("文件不存在");
|
|
AfxMessageBox(str);
|
|
/*GlwLayerWarnMessageBox WndDlgLayerNotDeleteWarn(str, acedGetAcadFrame());
|
|
WndDlgLayerNotDeleteWarn.DoModal(WS_POPUP | WS_CAPTION
|
|
| WS_SYSMENU, NULL, acedGetAcadFrame());
|
|
m_bFilterIsExist = false;*/
|
|
return;
|
|
}
|
|
m_pLayerGrpRoot = new SLayerGrpRecord(_T("全部"), NULL);
|
|
if(!ReadLayerGrpFromXMLFile(m_pLayerGrpRoot, sLayerGrpXml))
|
|
{
|
|
CString str(_T("读取LayerGroup.XML文件失败"));
|
|
AfxMessageBox(str);
|
|
/*GlwLayerWarnMessageBox WndDlgLayerNotDeleteWarn(str, acedGetAcadFrame());
|
|
WndDlgLayerNotDeleteWarn.DoModal(WS_POPUP | WS_CAPTION
|
|
| WS_SYSMENU, NULL, acedGetAcadFrame());*/
|
|
}
|
|
}
|
|
|
|
bool TDocCreateLayer::ReadLayerGrpFromXMLFile(SLayerGrpRecord *pRoot, CString sGrpXml, bool bIsSort)
|
|
{
|
|
MSXML2::IXMLDOMDocument2Ptr pXMLDoc = LoadXMLFile(sGrpXml);
|
|
if(!pXMLDoc)
|
|
{
|
|
return false;
|
|
}
|
|
MSXML2::IXMLDOMElementPtr pXMLEl = pXMLDoc->GetdocumentElement();
|
|
if (!pXMLEl)
|
|
return false;
|
|
if (bIsSort)
|
|
{
|
|
MSXML2::IXMLDOMNodeListPtr pGrps = pXMLEl->selectNodes(TARCH_LAYER_GROUP_NODE_SORT_CSTRING);
|
|
if(!pGrps)
|
|
return false;
|
|
MSXML2::IXMLDOMNodePtr pGrp = pGrps->nextNode();
|
|
if(!pGrp)
|
|
return false;
|
|
//因为之前做判断调用过nextNode()方法,跳过第一个结点了,所以再重新赋值一次
|
|
pGrps = pXMLEl->selectNodes(TARCH_LAYER_GROUP_NODE_SORT_CSTRING);
|
|
ReadXMLFileToGetGrpFilterSort(pGrps, m_iGrpFilterSort);
|
|
}
|
|
else
|
|
{
|
|
MSXML2::IXMLDOMNodeListPtr pGrps = pXMLEl->selectNodes(TARCH_LAYER_GROUP_NODE_NAME_CSTRING);
|
|
if(!pGrps)
|
|
return false;
|
|
MSXML2::IXMLDOMNodePtr pGrp = pGrps->nextNode();
|
|
if(!pGrp)
|
|
return false;
|
|
//因为之前做判断调用过nextNode()方法,跳过第一个结点了,所以再重新赋值一次
|
|
pGrps = pXMLEl->selectNodes(TARCH_LAYER_GROUP_NODE_NAME_CSTRING);
|
|
ReadXMLFileToGetChildNode(pRoot, pGrps);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void TDocCreateLayer::InitDocLayerRecordParamNumMap()
|
|
{
|
|
if (JudgeDocIsNewOrExist())
|
|
{
|
|
CreatNewDwgToInitLayerAndGroup();
|
|
}
|
|
ChangeDocToChangeLayerRecordParamNum();
|
|
}
|
|
|
|
void TDocCreateLayer::ChangeDocToChangeLayerRecordParamNum()
|
|
{
|
|
CString sName = utility::GetCurFileName(m_pDatabase);
|
|
std::map<CString, LayerRecordParamNum*>::iterator itrParamNum = m_arAllDocLayerRecordParamNumHeader.begin();
|
|
itrParamNum = m_arAllDocLayerRecordParamNumHeader.find(sName);
|
|
if (itrParamNum != m_arAllDocLayerRecordParamNumHeader.end())
|
|
{
|
|
m_pCurLayerRecordParamNumHeader = itrParamNum->second;
|
|
}
|
|
else
|
|
{
|
|
UpdateLayerInUseStateByCAD();
|
|
LayerRecordParamNum *m_pCurHeader = new LayerRecordParamNum;
|
|
AcDbLayerTable *pLayerTable = NULL;
|
|
Acad::ErrorStatus bError = m_pDatabase->getSymbolTable(pLayerTable, AcDb::kForRead);
|
|
if (bError != Acad::eOk)
|
|
return;
|
|
AcDbLayerTableIterator *pItor = NULL;
|
|
bError = pLayerTable->newIterator(pItor);
|
|
bError = pLayerTable->close();
|
|
if (!pItor)
|
|
return;
|
|
AcDbLayerTableRecord *pLayerTableRecord = NULL;
|
|
for (pItor->start();!pItor->done(); pItor->step())
|
|
{
|
|
pLayerTableRecord = NULL;
|
|
bError = pItor->getRecord(pLayerTableRecord, AcDb::kForRead);
|
|
if (bError != Acad::eOk)
|
|
continue;
|
|
else
|
|
{
|
|
m_pCurHeader->iLayerFreezonNum += pLayerTableRecord->isFrozen() ? 1 : 0;
|
|
m_pCurHeader->iLayerLockNum += pLayerTableRecord->isLocked() ? 1 : 0;
|
|
m_pCurHeader->iLayerOffNum += pLayerTableRecord->isOff() ? 1 : 0;
|
|
bError = pLayerTableRecord->close();
|
|
}
|
|
}
|
|
delete pItor;
|
|
m_arAllDocLayerRecordParamNumHeader.insert(std::make_pair(sName, m_pCurHeader));
|
|
m_pCurLayerRecordParamNumHeader = m_pCurHeader;
|
|
}
|
|
}
|
|
|
|
void TDocCreateLayer::DoCreateDocLayer()
|
|
{
|
|
InitJudgeRegistryIsWhole();
|
|
|
|
if (m_bRegistryIsExist)
|
|
{
|
|
InitWhetherCreatStandard();
|
|
InitFirstSetGrpFilter();
|
|
InitarSystemGrpFilter();
|
|
InitNotCreatStandardLayer();
|
|
UpdateStandardLayer();
|
|
|
|
InitStandardGrpRoot();
|
|
InitDocLayerRecordParamNumMap();
|
|
InitCurLayerRecordHeader();
|
|
|
|
GetCurFilterGrpNameByCAD();
|
|
}
|
|
}
|
|
|
|
void TDocCreateLayer::UpdateStandardLayer()
|
|
{
|
|
std::vector<SLayStandardRecord*>::iterator itr = m_arStandardLayerRecord.begin();
|
|
for (; itr != m_arStandardLayerRecord.end(); ++itr)
|
|
{
|
|
deletePtr(*itr);
|
|
}
|
|
m_arStandardLayerRecord.clear();
|
|
InitStandardLayerData();
|
|
}
|
|
|
|
void TDocCreateLayer::InitStandardLayerData()
|
|
{
|
|
m_arStandardLayerRecord.clear();
|
|
CString sTitle(_T(""));
|
|
sTitle.Format(_T("%s"),LAY_STD);
|
|
sTitle += _T(".lay");
|
|
CString sStandardLayerPath = m_sInstallDirectory + TARCH_INSTALL_DIRECTORY_INCLUDE_SYS + sTitle;
|
|
CFileFind finder;
|
|
BOOL bIsExist = finder.FindFile(sStandardLayerPath);
|
|
if (!bIsExist)
|
|
{
|
|
CString str(sStandardLayerPath + _T("图层标准文件不存在"));
|
|
AfxMessageBox(str);
|
|
//GlwLayerWarnMessageBox WndDlgLayerNotDeleteWarn(str, acedGetAcadFrame());
|
|
//WndDlgLayerNotDeleteWarn.DoModal(WS_POPUP | WS_CAPTION
|
|
// | WS_SYSMENU, NULL, acedGetAcadFrame());
|
|
m_bTarchLayIsExist = false;
|
|
return;
|
|
}
|
|
CString sStandardLayerPathDATFile = m_sInstallDirectory + TARCH_INSTALL_DIRECTORY_INCLUDE_SYS + TARCH_CURRENT_LAYER_STANDARD_FILE_NAME;
|
|
bIsExist = finder.FindFile(sStandardLayerPathDATFile);
|
|
if (!bIsExist)
|
|
{
|
|
CString str = sStandardLayerPathDATFile;
|
|
str += _T("文件不存在");
|
|
AfxMessageBox(str);
|
|
//GlwLayerWarnMessageBox WndDlgLayerNotDeleteWarn(str, acedGetAcadFrame());
|
|
//WndDlgLayerNotDeleteWarn.DoModal(WS_POPUP | WS_CAPTION
|
|
// | WS_SYSMENU, NULL, acedGetAcadFrame());
|
|
m_bTarchLayIsExist = false;
|
|
return;
|
|
}
|
|
setlocale(0,"chs");
|
|
CStdioFile *fp(NULL);
|
|
fp = new CStdioFile(sStandardLayerPathDATFile, CFile::modeRead);
|
|
ReadLayerFromTextFile(fp, &m_arStandardLayerRecord);
|
|
fp->Close();
|
|
deletePtr(fp);
|
|
}
|
|
|
|
void TDocCreateLayer::InitCurLayerRecordHeader()
|
|
{
|
|
UpdateLayerInUseStateByCAD();
|
|
Acad::ErrorStatus bError(Acad::eOk);
|
|
AcDbLayerTable *pLayerTable = NULL;
|
|
bError = m_pDatabase->getSymbolTable(pLayerTable, AcDb::kForRead);
|
|
if (bError != Acad::eOk)
|
|
return;
|
|
AcDbLayerTableIterator *pItor = NULL;
|
|
bError = pLayerTable->newIterator(pItor);
|
|
bError = pLayerTable->close();
|
|
if (!pItor)
|
|
return;
|
|
|
|
if (m_pCurLayerRecordHeader.size() > 0)
|
|
{
|
|
std::list<SLayerRecord*>::iterator itr = m_pCurLayerRecordHeader.begin();
|
|
for(; itr != m_pCurLayerRecordHeader.end(); ++itr)
|
|
{
|
|
deletePtr(*itr);
|
|
}
|
|
}
|
|
m_pCurLayerRecordHeader.clear();
|
|
|
|
AcDbLayerTableRecord *pLayerTableRecord(NULL);
|
|
CString sName(_T("")), strLineType(_T(""));
|
|
TCHAR *pStr = NULL;
|
|
AcDbObjectId idLayer(AcDbObjectId::kNull);
|
|
AcDbLinetypeTableRecord* pLinetypeTblRcd(NULL);
|
|
for (pItor->start();!pItor->done(); pItor->step())
|
|
{
|
|
pLayerTableRecord = NULL;
|
|
bError = pItor->getRecord(pLayerTableRecord, AcDb::kForRead);
|
|
if ( bError != Acad::eOk)
|
|
continue;
|
|
bError = pItor->getRecordId(idLayer);
|
|
pLayerTableRecord->getName(pStr);
|
|
sName = pStr;
|
|
acutDelString(pStr);
|
|
bError = acdbOpenObject(pLinetypeTblRcd, pLayerTableRecord->linetypeObjectId(),AcDb::kForRead);
|
|
if (bError == Acad::eOk)
|
|
{
|
|
TCHAR *linetypeName = NULL;
|
|
bError = pLinetypeTblRcd->getName(linetypeName);
|
|
strLineType = linetypeName;
|
|
acutDelString(linetypeName);
|
|
pLinetypeTblRcd->close();
|
|
}
|
|
SLayerRecord *pLayerRecord = new SLayerRecord;
|
|
int iState = pLayerTableRecord->objectId() == m_pDatabase->clayer() ? 0 : (pLayerTableRecord->isInUse() ? 1 : 2);
|
|
pLayerRecord->idLayerObject = idLayer;
|
|
pLayerRecord->iLayerState = iState;
|
|
pLayerRecord->sLayerName = sName;
|
|
pLayerRecord->bLayerOff = pLayerTableRecord->isOff();
|
|
pLayerRecord->bLayerFreeze = pLayerTableRecord->isFrozen();
|
|
pLayerRecord->bLayerLock = pLayerTableRecord->isLocked();
|
|
pLayerRecord->cmColor = pLayerTableRecord->color();
|
|
pLayerRecord->sLTypeName = strLineType;
|
|
pLayerRecord->iLayerLineWidth = pLayerTableRecord->lineWeight();
|
|
pLayerRecord->bLayerPlottable = pLayerTableRecord->isPlottable();
|
|
pLayerRecord->bLayerNewFreeze = pLayerTableRecord->VPDFLT();
|
|
pLayerRecord->sLayerDescription = pLayerTableRecord->description();
|
|
bError = pLayerTableRecord->close();
|
|
m_pCurLayerRecordHeader.push_back(pLayerRecord);
|
|
}
|
|
delete pItor;
|
|
}
|
|
|
|
void TDocCreateLayer::ReadLayerFromTextFile(CStdioFile *fp, std::vector<SLayStandardRecord*>* pLayerStandard)
|
|
{
|
|
CString sReadWords(_T(""));
|
|
CString StandardLayer[5];
|
|
int i(0), j(0), m(0); //i记录读出来的字符串的字符,j记录每行有几个词组,m记录每个词组的字符
|
|
bool bJudge(false);
|
|
while(fp->ReadString(sReadWords))
|
|
{
|
|
for (i = 0; i < 5; ++i)
|
|
{
|
|
StandardLayer[i].Format(_T(""));
|
|
}
|
|
if (!sReadWords.IsEmpty())
|
|
{
|
|
i = 0;
|
|
j = 0;
|
|
m = 0;
|
|
bJudge = false;
|
|
while(sReadWords[i] != _T('\0'))
|
|
{
|
|
if (sReadWords[i] == _T(' '))
|
|
{
|
|
if (bJudge)
|
|
{
|
|
j++;
|
|
bJudge = false;
|
|
}
|
|
i++;
|
|
m = 0;
|
|
}
|
|
else
|
|
{
|
|
StandardLayer[j].Insert(m, sReadWords[i]);
|
|
i++;
|
|
m++;
|
|
bJudge = true;
|
|
}
|
|
}
|
|
if (j >= 2)
|
|
{
|
|
bool bIsIn(false);
|
|
if (m_bNotCreatLayer)
|
|
{
|
|
std::vector<CString>::iterator itrNot = m_arNotCreatStandardLayer.begin();
|
|
for (; itrNot != m_arNotCreatStandardLayer.end(); ++itrNot)
|
|
{
|
|
if (*itrNot == StandardLayer[0])
|
|
{
|
|
bIsIn = true;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (bIsIn)
|
|
{
|
|
continue;
|
|
}
|
|
if(StandardLayer[2].IsEmpty())
|
|
StandardLayer[2] = _T("7");
|
|
if(StandardLayer[3].IsEmpty())
|
|
StandardLayer[3] = _T("CONTINUOUS");
|
|
SLayStandardRecord *pStandardLayerRecord = new SLayStandardRecord;
|
|
pStandardLayerRecord->sLayerKeyword = StandardLayer[0];
|
|
pStandardLayerRecord->sLayerName = StandardLayer[1];
|
|
pStandardLayerRecord->sColor = StandardLayer[2];
|
|
pStandardLayerRecord->sLineType = StandardLayer[3];
|
|
pStandardLayerRecord->sDescription = StandardLayer[4];
|
|
pLayerStandard->push_back(pStandardLayerRecord);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TDocCreateLayer::UpdateLayerInUseStateByCAD()
|
|
{
|
|
TDocAutoLock lock;
|
|
AcDbLayerTable *pLayerTableRead = NULL;
|
|
Acad::ErrorStatus bError = m_pDatabase->getSymbolTable(pLayerTableRead, AcDb::kForRead);
|
|
if (bError == Acad::eOk)
|
|
{
|
|
m_bValidModify = false;
|
|
pLayerTableRead->generateUsageData();
|
|
pLayerTableRead->close();
|
|
m_bValidModify = true;
|
|
}
|
|
else
|
|
{
|
|
Acad::ErrorStatus bError = m_pDatabase->getSymbolTable(pLayerTableRead, AcDb::kForWrite);
|
|
if (bError == Acad::eOk)
|
|
{
|
|
m_bValidModify = false;
|
|
pLayerTableRead->generateUsageData();
|
|
pLayerTableRead->close();
|
|
m_bValidModify = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
void TDocCreateLayer::InitNotCreatStandardLayer()
|
|
{
|
|
m_arNotCreatStandardLayer.clear();
|
|
CString sNotCreatStandardLayerPath = m_sInstallDirectory + TARCH_INSTALL_DIRECTORY_INCLUDE_SYS + TARCH_LAYER_NOT_CAEAT_STANDARD_LAYER;
|
|
CFileFind finder;
|
|
BOOL bIsExist = finder.FindFile(sNotCreatStandardLayerPath);
|
|
if (!bIsExist)
|
|
{
|
|
CString str = sNotCreatStandardLayerPath;
|
|
str += _T("文件不存在");
|
|
/*GlwLayerWarnMessageBox WndDlgLayerNotDeleteWarn(str, acedGetAcadFrame());
|
|
WndDlgLayerNotDeleteWarn.DoModal(WS_POPUP | WS_CAPTION
|
|
| WS_SYSMENU, NULL, acedGetAcadFrame());*/
|
|
m_bNotCreatLayer = false;
|
|
AfxMessageBox(str);
|
|
return;
|
|
}
|
|
setlocale(0,"chs");
|
|
CStdioFile *fp(NULL);
|
|
fp = new CStdioFile(sNotCreatStandardLayerPath, CFile::modeRead);
|
|
CString sReadWords(_T(""));
|
|
while(fp->ReadString(sReadWords))
|
|
{
|
|
bool bAllIsBlank(false);
|
|
if (sReadWords.GetLength() > 0)
|
|
{
|
|
int i(0);
|
|
for (; i < sReadWords.GetLength(); ++i)
|
|
{
|
|
if (sReadWords.GetAt(i) != _T(' '))
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
if(i == sReadWords.GetLength())
|
|
{
|
|
bAllIsBlank = true; //不能全部为空格,必须含有一个字符
|
|
}
|
|
}
|
|
if (sReadWords.IsEmpty() || bAllIsBlank)
|
|
{
|
|
continue;
|
|
}
|
|
m_arNotCreatStandardLayer.push_back(sReadWords);
|
|
}
|
|
fp->Close();
|
|
deletePtr(fp);
|
|
}
|
|
|
|
|
|
void TDocCreateLayer::InitNewDocToCreatStandardLayer()
|
|
{
|
|
UpdateLayerInUseStateByCAD();
|
|
TDocAutoLock lock;
|
|
std::vector<SLayStandardRecord*>::iterator itrStandard;
|
|
Acad::ErrorStatus bError(Acad::eOk);
|
|
bool bIsIn(false);
|
|
AcDbLayerTable *pLayerTbl = NULL;
|
|
AcDbObjectId layerid(AcDbObjectId::kNull);
|
|
AcCmColor color;
|
|
wchar_t buf[255];
|
|
AcDbLayerTableRecord *pLayerTableRecord(NULL);
|
|
bool bIsInUse(false);
|
|
for (itrStandard = m_arStandardLayerRecord.begin(); itrStandard != m_arStandardLayerRecord.end(); ++itrStandard)
|
|
{
|
|
bError = m_pDatabase->getSymbolTable(pLayerTbl, AcDb::kForWrite);
|
|
if (bError != Acad::eOk)
|
|
{
|
|
return;
|
|
}
|
|
bIsIn = false;
|
|
bError = pLayerTbl->getAt((*itrStandard)->sLayerName, pLayerTableRecord, AcDb::kForRead);
|
|
if (bError == Acad::eOk)
|
|
{
|
|
bIsIn = true;
|
|
pLayerTableRecord->close();
|
|
}
|
|
if (bIsIn)
|
|
{
|
|
bError = pLayerTbl->close();
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
AcDbLayerTableRecord *pLayerTblRcd = new AcDbLayerTableRecord;
|
|
bError = pLayerTbl->add(layerid, pLayerTblRcd);
|
|
bError = pLayerTbl->close();
|
|
bError = pLayerTblRcd->setName((*itrStandard)->sLayerName); //设定图层名
|
|
utility::GetAccmColorByString((*itrStandard)->sColor, color);
|
|
pLayerTblRcd->setColor(color); //设定图层颜色
|
|
pLayerTblRcd->setLinetypeObjectId(utility::GetIdByName((*itrStandard)->sLineType));
|
|
wcscpy_s(buf, 255, (*itrStandard)->sDescription);
|
|
bError = pLayerTblRcd->setDescription(buf);
|
|
bError = pLayerTblRcd->setLineWeight(AcDb::LineWeight(AcDb::kLnWtByLwDefault)); //设定图层线宽
|
|
bError = pLayerTblRcd->setIsFrozen(false); //设定图层解冻
|
|
pLayerTblRcd->setIsOff(false); //设定图层打开
|
|
if (!bIsInUse)
|
|
{
|
|
bIsInUse = pLayerTblRcd->isInUse();
|
|
}
|
|
pLayerTblRcd->setIsLocked(false); //设定图层解锁
|
|
bError = pLayerTblRcd->setIsPlottable(true); //设定图层可以打印
|
|
pLayerTblRcd->setVPDFLT(false); //设定图层新视口打开
|
|
bError = pLayerTblRcd->close();
|
|
}
|
|
}
|
|
}
|
|
|
|
void TDocCreateLayer::InitNewDocToCreatLayerGroup()
|
|
{
|
|
TDocAutoLock lock;
|
|
AcLyLayerFilterManager *pAclyMager = aclyGetLayerFilterManager(m_pDatabase);
|
|
if (!pAclyMager)
|
|
{
|
|
return;
|
|
}
|
|
Acad::ErrorStatus bOk(Acad::eOk);
|
|
AcLyLayerFilter *pFilterRoot(NULL);
|
|
AcLyLayerFilter *pFilterCur(NULL);
|
|
bOk = pAclyMager->getFilters(pFilterRoot, pFilterCur);
|
|
if (bOk != Acad::eOk)
|
|
{
|
|
return;
|
|
}
|
|
AddLayerFilterGroupNode(pFilterRoot, m_pLayerGrpRoot, pAclyMager, pFilterRoot, pFilterCur);
|
|
if (pFilterCur)
|
|
{
|
|
bOk = pAclyMager->setFilters(pFilterRoot, pFilterCur);
|
|
m_sCurFilterGrpName = pFilterCur->name();
|
|
}
|
|
else
|
|
{
|
|
bOk = pAclyMager->setFilters(pFilterRoot, pFilterRoot);
|
|
m_sCurFilterGrpName = pFilterRoot->name();
|
|
}
|
|
}
|
|
|
|
void TDocCreateLayer::GetCADAcLyLayerFilterByName(CString sGrpName, AcLyLayerFilter* &pFilter, AcLyLayerFilter* &pFilterRoot, AcLyLayerFilter* &pCurRoot, bool bIsXref)
|
|
{
|
|
bool bOk(false);
|
|
AcLyLayerFilterManager *pAclyMager = aclyGetLayerFilterManager(m_pDatabase);
|
|
if (!pAclyMager)
|
|
{
|
|
return;
|
|
}
|
|
Acad::ErrorStatus bError(Acad::eOk);
|
|
bError = pAclyMager->getFilters(pFilterRoot, pCurRoot);
|
|
if (bError != Acad::eOk)
|
|
{
|
|
return;
|
|
}
|
|
bool bHaveXref(false);
|
|
RecursionGetCADGrpFilter(sGrpName, pFilterRoot, bOk, pFilter, bIsXref, bHaveXref);
|
|
}
|
|
|
|
void TDocCreateLayer::RecursionGetCADGrpFilter(CString sGrpName, AcLyLayerFilter* pFilter, bool &bOk, AcLyLayerFilter* &pGetFilter, bool bIsXref, bool &bHaveXref)
|
|
{
|
|
if (bOk) return;
|
|
if (!pFilter) return;
|
|
|
|
CString sName = pFilter->name();
|
|
if (!sName.CompareNoCase(_T("外部参照")) && !pFilter->allowRename())
|
|
{
|
|
bHaveXref = true;
|
|
}
|
|
if (!sGrpName.CompareNoCase(sName))
|
|
{
|
|
if (bIsXref)
|
|
{
|
|
if (bHaveXref)
|
|
{
|
|
bOk = true;
|
|
pGetFilter = pFilter;
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bOk = true;
|
|
pGetFilter = pFilter;
|
|
return;
|
|
}
|
|
}
|
|
AcArray<AcLyLayerFilter*> arRootFilters = pFilter->getNestedFilters();
|
|
for (int i = 0; i < arRootFilters.length(); ++i)
|
|
{
|
|
RecursionGetCADGrpFilter(sGrpName, arRootFilters[i], bOk, pGetFilter, bIsXref, bHaveXref);
|
|
}
|
|
}
|
|
|
|
void TDocCreateLayer::AddLayerFilterGroupNode(AcLyLayerFilter *pFilterGroup, SLayerGrpRecord *pParent, AcLyLayerFilterManager *&pAclyMager, AcLyLayerFilter *&pFilterRoot, AcLyLayerFilter *&pCurRoot, bool bOk)
|
|
{
|
|
std::vector<SLayerGrpRecord*>::iterator itrGrpRecord = pParent->arLayerGrpChild.begin();
|
|
Acad::ErrorStatus bError(Acad::eOk);
|
|
for (; itrGrpRecord!= pParent->arLayerGrpChild.end(); itrGrpRecord++)
|
|
{
|
|
AcLyLayerFilter *pGrpFilterRoot(NULL);
|
|
AcLyLayerFilter *pGrpFilterCur(NULL);
|
|
AcLyLayerFilter *pGrpCur(NULL);
|
|
GetCADAcLyLayerFilterByName((*itrGrpRecord)->sGrpName, pGrpFilterCur, pGrpFilterRoot, pGrpCur,true);
|
|
if (!pGrpFilterCur)
|
|
{
|
|
GetCADAcLyLayerFilterByName((*itrGrpRecord)->sGrpName, pGrpFilterCur, pGrpFilterRoot, pGrpCur, false);
|
|
if (!pGrpFilterCur)
|
|
{
|
|
AcLyLayerGroup* pNewChild = new AcLyLayerGroup;
|
|
bError = pFilterGroup->addNested(pNewChild);
|
|
bError = pNewChild->setName((*itrGrpRecord)->sGrpName);
|
|
if(bOk)
|
|
{
|
|
if (pCurRoot)
|
|
{
|
|
bError = pAclyMager->setFilters(pFilterRoot, pCurRoot);
|
|
m_sCurFilterGrpName = pCurRoot->name();
|
|
}
|
|
else
|
|
{
|
|
bError = pAclyMager->setFilters(pFilterRoot, pFilterRoot);
|
|
m_sCurFilterGrpName = pFilterRoot->name();
|
|
}
|
|
}
|
|
AddLayerFilterGroupNode((AcLyLayerFilter*)pNewChild, (*itrGrpRecord), pAclyMager, pFilterRoot, pCurRoot, bOk);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TDocCreateLayer::InitClassifyStandardLayerToGroup()
|
|
{
|
|
TDocAutoLock lock;
|
|
AcLyLayerFilterManager *pAclyMager = aclyGetLayerFilterManager(acdbCurDwg());
|
|
if (!pAclyMager)
|
|
{
|
|
return;
|
|
}
|
|
AcLyLayerFilter *pFilterRoot(NULL);
|
|
AcLyLayerFilter *pFilterCur(NULL);
|
|
Acad::ErrorStatus bOk(Acad::eOk);
|
|
bOk = pAclyMager->getFilters(pFilterRoot, pFilterCur);
|
|
if (bOk != Acad::eOk)
|
|
{
|
|
return;
|
|
}
|
|
if(!pFilterRoot)
|
|
{
|
|
return;
|
|
}
|
|
CString sName = pFilterRoot->name();
|
|
if (!sName.CompareNoCase(m_pLayerGrpRoot->sGrpName))
|
|
{
|
|
InitClassifyStandardLayerToGroupImplementationDetails(pFilterRoot, m_pLayerGrpRoot);
|
|
}
|
|
|
|
if (pFilterCur)
|
|
{
|
|
bOk = pAclyMager->setFilters(pFilterRoot, pFilterCur);
|
|
m_sCurFilterGrpName = pFilterCur->name();
|
|
}
|
|
else
|
|
{
|
|
bOk = pAclyMager->setFilters(pFilterRoot, pFilterRoot);
|
|
m_sCurFilterGrpName = pFilterRoot->name();
|
|
}
|
|
}
|
|
|
|
void TDocCreateLayer::GetLayerObjectIDByLayerKeyWord( AcDbObjectId &layerId, CString sKeyWord )
|
|
{
|
|
Acad::ErrorStatus bError(Acad::eOk);
|
|
AcDbLayerTable *pLayerTable(NULL);
|
|
AcDbLayerTableRecord *pLayerTableRecord(NULL);
|
|
bError = acdbCurDwg()->getSymbolTable(pLayerTable, AcDb::kForRead);
|
|
if (bError != Acad::eOk)
|
|
{
|
|
layerId = AcDbObjectId::kNull;
|
|
return;
|
|
}
|
|
CString sLayerName(_T("||||"));
|
|
std::vector<SLayStandardRecord*>::iterator itr = m_arStandardLayerRecord.begin();
|
|
for (; itr != m_arStandardLayerRecord.end(); ++itr)
|
|
{
|
|
if (!(*itr)->sLayerKeyword.CompareNoCase(sKeyWord))
|
|
{
|
|
sLayerName = (*itr)->sLayerName;
|
|
break;
|
|
}
|
|
}
|
|
bError = pLayerTable->getAt(sLayerName, pLayerTableRecord, AcDb::kForRead);
|
|
pLayerTable->close();
|
|
if (bError == Acad::eOk)
|
|
{
|
|
layerId = pLayerTableRecord->objectId();
|
|
pLayerTableRecord->close();
|
|
}
|
|
else
|
|
{
|
|
layerId = AcDbObjectId::kNull;
|
|
}
|
|
}
|
|
|
|
void TDocCreateLayer::InitClassifyStandardLayerToGroupImplementationDetails(AcLyLayerFilter *pFilterGroup, SLayerGrpRecord *pGrpRecord)
|
|
{
|
|
std::vector<CString>::iterator itrLayer = pGrpRecord->arContainLayerName.begin();
|
|
Acad::ErrorStatus bError(Acad::eOk);
|
|
AcDbObjectId IdLayer(AcDbObjectId::kNull);
|
|
for(; itrLayer != pGrpRecord->arContainLayerName.end(); itrLayer++)
|
|
{
|
|
GetLayerObjectIDByLayerKeyWord(IdLayer, *itrLayer);
|
|
if (IdLayer != AcDbObjectId::kNull)
|
|
{
|
|
if (pFilterGroup->isKindOf(AcLyLayerGroup::desc()))
|
|
{
|
|
AcDbObjectIdArray ArrIdLayer = ((AcLyLayerGroup*)pFilterGroup)->layerIds();
|
|
if(ArrIdLayer.find(IdLayer) < 0)
|
|
{
|
|
bError = ((AcLyLayerGroup*)pFilterGroup)->addLayerId(IdLayer);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
AcArray<AcLyLayerFilter*> arRootFilters = pFilterGroup->getNestedFilters();
|
|
CString sName(_T(""));
|
|
for (int i = 0; i < arRootFilters.length(); ++i)
|
|
{
|
|
std::vector<SLayerGrpRecord*>::iterator itrGrpRecord = pGrpRecord->arLayerGrpChild.begin();
|
|
for (; itrGrpRecord!= pGrpRecord->arLayerGrpChild.end(); itrGrpRecord++)
|
|
{
|
|
sName = arRootFilters[i]->name();
|
|
if(!sName.CompareNoCase((*itrGrpRecord)->sGrpName))
|
|
{
|
|
InitClassifyStandardLayerToGroupImplementationDetails((AcLyLayerFilter*)arRootFilters[i], *itrGrpRecord);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TDocCreateLayer::CreatNewDwgToInitLayerAndGroup()
|
|
{
|
|
if (m_bRegistryIsExist && m_bTarchLayIsExist && m_bWhetherCreatStandardLayer)
|
|
InitNewDocToCreatStandardLayer();
|
|
if (m_bRegistryIsExist && m_bFilterIsExist)
|
|
InitNewDocToCreatLayerGroup();
|
|
|
|
InitClassifyStandardLayerToGroup();
|
|
} |