用SearchAPI来搜索CategoryAttributeManager中的FilterByLogisticsType()、FilterTraversableItems()等方法
This commit is contained in:
parent
e4771663b4
commit
1d28c71cba
@ -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": [
|
||||
|
||||
@ -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]
|
||||
|
||||
|
||||
@ -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>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user