-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename DisplayPathHelper.cs to HierarchyHelper.cs
- Renamed the file from "DisplayPathHelper.cs" to "HierarchyHelper.cs" - Updated all references to the renamed file Refactor helper class for generating display paths - Refactored the helper class to extract hierarchical context from Navisworks model items in a single traversal - Changed the method name from "GenerateDisplayPath" to "ExtractContext" - Modified the method signature to return a tuple of strings (Name, Path) - Updated the implementation logic accordingly Improve traversal and extraction logic - Improved the traversal logic by collecting both name and path information while traversing up the tree once - Extracted meaningful name and path information from model items in a more efficient way - Handled cases where model item has no meaningful name or is a geometry node
- Loading branch information
1 parent
5339a52
commit ad1b520
Showing
3 changed files
with
60 additions
and
61 deletions.
There are no files selected for viewing
60 changes: 0 additions & 60 deletions
60
Converters/Navisworks/Speckle.Converters.NavisworksShared/Helpers/DisplayPathHelper.cs
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
Converters/Navisworks/Speckle.Converters.NavisworksShared/Helpers/HierarchyHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
namespace Speckle.Converter.Navisworks.Helpers; | ||
|
||
/// <summary> | ||
/// Helper class for extracting hierarchical context from Navisworks model items in a single traversal. | ||
/// </summary> | ||
public static class HierarchyHelper | ||
{ | ||
private const char PATH_DELIMITER = '>'; | ||
|
||
/// <summary> | ||
/// Extracts the meaningful name and path from a ModelItem in a single traversal. | ||
/// </summary> | ||
public static (string Name, string Path) ExtractContext(NAV.ModelItem modelItem) | ||
{ | ||
if (modelItem == null) | ||
{ | ||
throw new ArgumentNullException(nameof(modelItem)); | ||
} | ||
|
||
var ancestors = new List<string>(); | ||
var meaningfulName = string.Empty; | ||
var current = modelItem; | ||
|
||
// Start with the root document name if available | ||
if (modelItem.HasModel && !string.IsNullOrEmpty(modelItem.Model.FileName)) | ||
{ | ||
ancestors.Add(Path.GetFileNameWithoutExtension(modelItem.Model.FileName)); | ||
} | ||
|
||
// Traverse up the tree once, collecting both name and path information | ||
while (current != null) | ||
{ | ||
if (IsMeaningfulNode(current)) | ||
{ | ||
// First meaningful name we find is our object name (if we haven't found one yet) | ||
if (string.IsNullOrEmpty(meaningfulName)) | ||
{ | ||
meaningfulName = current.DisplayName; | ||
} | ||
// Add to ancestors if it's not a duplicate | ||
else if (ancestors.Count == 0 || ancestors.Last() != current.DisplayName) | ||
{ | ||
ancestors.Add(current.DisplayName); | ||
} | ||
} | ||
current = current.Parent; | ||
} | ||
|
||
// Build path excluding the name we found | ||
ancestors.Reverse(); | ||
|
||
var path = string.Join($" {PATH_DELIMITER} ", ancestors); | ||
|
||
return (meaningfulName, path); | ||
} | ||
|
||
private static bool IsMeaningfulNode(NAV.ModelItem item) => | ||
!string.IsNullOrEmpty(item.DisplayName) && (!item.HasGeometry || !string.IsNullOrEmpty(item.ClassDisplayName)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters