用SearchAPI来搜索CategoryAttributeManager中的FilterByLogisticsType()、FilterTraversableItems()等方法

This commit is contained in:
tian 2025-09-04 13:54:24 +08:00
parent e4771663b4
commit 1d28c71cba
3 changed files with 125 additions and 26 deletions

View File

@ -54,7 +54,11 @@
"Bash(git add:*)",
"Bash(git commit:*)",
"Read(/C:\\Users\\Tellme\\apps\\NavisworksTransport\\src\\Utils/**)",
"Read(/C:\\Users\\Tellme\\apps\\NavisworksTransport\\src\\Core/**)"
"Read(/C:\\Users\\Tellme\\apps\\NavisworksTransport\\src\\Core/**)",
"Read(/C:\\Users\\Tellme\\apps\\NavisworksTransport\\doc\\design\\2026/**)",
"Read(/C:\\Users\\Tellme\\apps\\NavisworksTransport\\doc\\design\\2026/**)",
"Read(/C:\\Users\\Tellme\\apps\\NavisworksTransport\\doc\\navisworks_api\\NET\\examples\\PlugIns\\SearchComparisonPlugIn/**)",
"Read(/C:\\Users\\Tellme\\apps\\NavisworksTransport\\doc\\navisworks_api/**)"
],
"deny": [],
"additionalDirectories": [

View File

@ -14,7 +14,7 @@
3. [x] 性能优化增加直接采用包围盒的2.5D自动寻路算法,代替空间索引+高度扫描算法。
4. [x] BUG自动规划有时成功过滤3个通道找到26个障碍物有时失败过滤2个通道,只找到2个障碍物连续自动规划有时会崩溃。
5. [ ] BUG还有厚度为0的障碍物不一定是bug
6. [ ] (性能优化) 用SearchAPI来搜索CategoryAttributeManager中的FilterByLogisticsType()、FilterTraversableItems()等方法
6. [x] (性能优化) 用SearchAPI来搜索CategoryAttributeManager中的FilterByLogisticsType()、FilterTraversableItems()等方法
### [2025/08/31]

View File

@ -289,18 +289,45 @@ namespace NavisworksTransport
/// <returns>匹配条件的模型项集合</returns>
public static ModelItemCollection FilterByLogisticsType(ModelItemCollection items, LogisticsElementType elementType)
{
ModelItemCollection filteredItems = new ModelItemCollection();
foreach (ModelItem item in items)
try
{
string typeValue = GetLogisticsPropertyValue(item, LogisticsProperties.TYPE);
if (typeValue == elementType.ToString())
// 使用SearchAPI优化直接搜索具有指定类型值的物流项目
using (var search = new Search())
{
filteredItems.Add(item);
// 将输入的ModelItemCollection转换为搜索选择
search.Selection.CopyFrom(items);
search.Locations = SearchLocations.DescendantsAndSelf;
var searchConditions = search.SearchConditions;
searchConditions.Clear();
// 搜索条件:必须有物流分类
searchConditions.Add(SearchCondition.HasCategoryByDisplayName(LogisticsCategories.LOGISTICS));
// 搜索条件:类型属性等于指定值
searchConditions.Add(
SearchCondition.HasPropertyByDisplayName(LogisticsCategories.LOGISTICS, LogisticsProperties.TYPE)
.EqualValue(VariantData.FromDisplayString(elementType.ToString())));
return search.FindAll(Application.ActiveDocument, false);
}
}
return filteredItems;
catch (Exception ex)
{
LogManager.Error($"按物流类型过滤失败: {ex.Message}");
// 如果SearchAPI失败回退到原始实现
ModelItemCollection filteredItems = new ModelItemCollection();
foreach (ModelItem item in items)
{
string typeValue = GetLogisticsPropertyValue(item, LogisticsProperties.TYPE);
if (typeValue == elementType.ToString())
{
filteredItems.Add(item);
}
}
return filteredItems;
}
}
/// <summary>
@ -310,18 +337,45 @@ namespace NavisworksTransport
/// <returns>可通行的模型项集合</returns>
public static ModelItemCollection FilterTraversableItems(ModelItemCollection items)
{
ModelItemCollection filteredItems = new ModelItemCollection();
foreach (ModelItem item in items)
try
{
string traversableValue = GetLogisticsPropertyValue(item, LogisticsProperties.TRAVERSABLE);
if (traversableValue == "是")
// 使用SearchAPI优化直接搜索可通行的物流项目
using (var search = new Search())
{
filteredItems.Add(item);
// 将输入的ModelItemCollection转换为搜索选择
search.Selection.CopyFrom(items);
search.Locations = SearchLocations.DescendantsAndSelf;
var searchConditions = search.SearchConditions;
searchConditions.Clear();
// 搜索条件:必须有物流分类
searchConditions.Add(SearchCondition.HasCategoryByDisplayName(LogisticsCategories.LOGISTICS));
// 搜索条件:可通行属性等于"是"
searchConditions.Add(
SearchCondition.HasPropertyByDisplayName(LogisticsCategories.LOGISTICS, LogisticsProperties.TRAVERSABLE)
.EqualValue(VariantData.FromDisplayString("是")));
return search.FindAll(Application.ActiveDocument, false);
}
}
return filteredItems;
catch (Exception ex)
{
LogManager.Error($"过滤可通行物流项目失败: {ex.Message}");
// 如果SearchAPI失败回退到原始实现
ModelItemCollection filteredItems = new ModelItemCollection();
foreach (ModelItem item in items)
{
string traversableValue = GetLogisticsPropertyValue(item, LogisticsProperties.TRAVERSABLE);
if (traversableValue == "是")
{
filteredItems.Add(item);
}
}
return filteredItems;
}
}
/// <summary>
@ -369,18 +423,59 @@ namespace NavisworksTransport
/// <returns>适用的通道集合</returns>
public static ModelItemCollection FilterByVehicleSize(ModelItemCollection items, string vehicleSize)
{
ModelItemCollection filteredItems = new ModelItemCollection();
foreach (ModelItem item in items)
try
{
string sizeValue = GetLogisticsPropertyValue(item, LogisticsProperties.VEHICLE_SIZE);
if (sizeValue == vehicleSize || sizeValue == "标准" || string.IsNullOrEmpty(sizeValue))
// 对于车辆尺寸过滤,由于需要处理"标准"和空值的特殊逻辑,
// SearchAPI的复杂条件组合比较困难所以采用混合方式
// 1. 使用SearchAPI快速获取有物流属性的项目
// 2. 再进行车辆尺寸过滤
ModelItemCollection logisticsItems;
using (var search = new Search())
{
filteredItems.Add(item);
// 将输入的ModelItemCollection转换为搜索选择
search.Selection.CopyFrom(items);
search.Locations = SearchLocations.DescendantsAndSelf;
var searchConditions = search.SearchConditions;
searchConditions.Clear();
// 搜索条件:必须有物流分类
searchConditions.Add(SearchCondition.HasCategoryByDisplayName(LogisticsCategories.LOGISTICS));
logisticsItems = search.FindAll(Application.ActiveDocument, false);
}
// 对获取到的物流项目进行车辆尺寸过滤
ModelItemCollection filteredItems = new ModelItemCollection();
foreach (ModelItem item in logisticsItems)
{
string sizeValue = GetLogisticsPropertyValue(item, LogisticsProperties.VEHICLE_SIZE);
if (sizeValue == vehicleSize || sizeValue == "标准" || string.IsNullOrEmpty(sizeValue))
{
filteredItems.Add(item);
}
}
return filteredItems;
}
catch (Exception ex)
{
LogManager.Error($"按车辆尺寸过滤失败: {ex.Message}");
// 如果SearchAPI失败回退到完全原始实现
ModelItemCollection filteredItems = new ModelItemCollection();
foreach (ModelItem item in items)
{
string sizeValue = GetLogisticsPropertyValue(item, LogisticsProperties.VEHICLE_SIZE);
if (sizeValue == vehicleSize || sizeValue == "标准" || string.IsNullOrEmpty(sizeValue))
{
filteredItems.Add(item);
}
}
return filteredItems;
}
return filteredItems;
}
/// <summary>