You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.4 KiB
C++
69 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include "Xy.h"
|
|
#include "unordered_dense.h"
|
|
|
|
/**
|
|
* 根据路径和子层条件过滤图层,并提供包含检查功能
|
|
*/
|
|
class LayerHelper
|
|
{
|
|
public:
|
|
LayerHelper(const CXy& xy, const CString& layerName, bool includeSubLayer)
|
|
{
|
|
CString fullName = CLayerName(layerName).GetFullPathNameA();
|
|
fullName.MakeLower();
|
|
|
|
CClassList* pClassList = const_cast<CXy&>(xy).GetClassList();
|
|
POSITION classPos = pClassList->GetHeadPosition();
|
|
while (classPos != nullptr)
|
|
{
|
|
CLayerList* pLayerList = pClassList->GetNext(classPos);
|
|
assert(pLayerList != nullptr);
|
|
|
|
POSITION layerPos = pLayerList->GetHeadPosition();
|
|
while (layerPos != nullptr)
|
|
{
|
|
CLayer* pLayer = pLayerList->GetNext(layerPos);
|
|
assert(pLayer != nullptr);
|
|
|
|
if (CheckLayerPath(pLayer, fullName, includeSubLayer))
|
|
{
|
|
m_set.insert(pLayer);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
bool IsIncluedLayer(CLayer* pLayer) const
|
|
{
|
|
return m_set.find(pLayer) != m_set.end();
|
|
}
|
|
|
|
private:
|
|
bool CheckLayerPath(CLayer* pLayer, const CString& fullName, bool includeSubLayer) const
|
|
{
|
|
CString layerFullName = pLayer->GetPathName();
|
|
layerFullName.MakeLower();
|
|
|
|
if (!StartsWith(layerFullName, fullName))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (layerFullName.GetLength() == fullName.GetLength())
|
|
{
|
|
return true;
|
|
}
|
|
|
|
if (!includeSubLayer)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return (layerFullName.GetLength() > fullName.GetLength() && layerFullName[fullName.GetLength()] == '\\');
|
|
}
|
|
|
|
ankerl::unordered_dense::set<CLayer*> m_set;
|
|
};
|