Skip to content

Commit

Permalink
Refactor NavisworksRootObjectBuilder.cs for improved context extraction
Browse files Browse the repository at this point in the history
- Extracted the GetContext method to retrieve the name and path of a model item
- Replaced calls to GetDisplayPath with calls to GetContext for consistency
- Updated CreateNavisworksObject and ConvertBase methods to use the extracted context information instead of finding meaningful ancestor names
- Updated the "path" property in the returned NavisworksObject instances with the extracted path
  • Loading branch information
jsdbroughton committed Jan 16, 2025
1 parent ad1b520 commit 8bc681e
Showing 1 changed file with 8 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,24 +205,11 @@ HashSet<string> processedPaths
}
}

private (NAV.ModelItem modelItem, string displayPath) GetDisplayPath(string applicationId)
private (string name, string path) GetContext(string applicationId)
{
var modelItem = elementSelectionService.GetModelItemFromPath(applicationId);
return (modelItem, DisplayPathHelper.GenerateDisplayPath(modelItem));
}

private static string FindMeaningfulAncestorName(NAV.ModelItem modelItem)
{
var current = modelItem;
while (current != null)
{
if (!string.IsNullOrEmpty(current.DisplayName) && !current.HasGeometry)
{
return current.DisplayName;
}
current = current.Parent;
}
return string.Empty;
var context = HierarchyHelper.ExtractContext(modelItem);
return (context.Name, context.Path);
}

/// <summary>
Expand All @@ -234,8 +221,7 @@ private static string FindMeaningfulAncestorName(NAV.ModelItem modelItem)
/// </remarks>
private NavisworksObject CreateNavisworksObject(string groupKey, List<Base> siblingBases)
{
(NAV.ModelItem modelItem, string displayPath) = GetDisplayPath(groupKey);
var name = FindMeaningfulAncestorName(modelItem);
(string name, string path) = GetContext(groupKey);

return new NavisworksObject
{
Expand All @@ -244,7 +230,7 @@ private NavisworksObject CreateNavisworksObject(string groupKey, List<Base> sibl
properties = siblingBases.First()["properties"] as Dictionary<string, object?> ?? [],
units = converterSettings.Current.Derived.SpeckleUnits,
applicationId = groupKey,
["path"] = displayPath
["path"] = path
};
}

Expand All @@ -260,16 +246,16 @@ private NavisworksObject CreateNavisworksObject(string groupKey, List<Base> sibl
return null;
}

(_, string displayPath) = GetDisplayPath(convertedBase.applicationId);
(string name, string path) = GetContext(convertedBase.applicationId);

return new NavisworksObject
{
name = convertedBase["name"] as string ?? string.Empty,
name = name,
displayValue = convertedBase["displayValue"] as List<Base> ?? [],
properties = convertedBase["properties"] as Dictionary<string, object?> ?? [],
units = converterSettings.Current.Derived.SpeckleUnits,
applicationId = convertedBase.applicationId,
["path"] = displayPath
["path"] = path
};
}

Expand Down

0 comments on commit 8bc681e

Please sign in to comment.