Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed crashing case for XbimPlacementTree ctor #476

Open
wants to merge 1 commit into
base: feature/netcore
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Xbim.ModelGeometry.Scene/Xbim3DModelContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,7 @@ internal bool Initialise(bool adjustWcs, bool generateFullGeometry = false)
{
try
{

PlacementTree = new XbimPlacementTree(Model, adjustWcs);
PlacementTree = new XbimPlacementTree(Model, adjustWcs, _modelContext._logger);
GeometryShapeLookup = new ConcurrentDictionary<int, int>();
MapGeometryReferences = new ConcurrentDictionary<int, List<GeometryReference>>();
MapTransforms = new ConcurrentDictionary<int, XbimMatrix3D>();
Expand Down
19 changes: 15 additions & 4 deletions Xbim.ModelGeometry.Scene/XbimPlacementTree.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#region Directives

using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Xbim.Common;
using Xbim.Common.Geometry;
Expand Down Expand Up @@ -36,7 +38,8 @@ public static XbimMatrix3D GetTransform(IIfcProduct product, XbimPlacementTree t
/// If there is a single root displacement, this is removed from the tree and added to the World
/// Coordinate System. Useful for models where the site has been located into a geographical context
/// </param>
public XbimPlacementTree(IModel model, bool adjustWcs = true)
/// <param name="logger">optional logging target</param>
public XbimPlacementTree(IModel model, bool adjustWcs = true, ILogger logger = null)
{
var rootNodes = new List<XbimPlacementNode>();
var localPlacements = model.Instances.OfType<IIfcLocalPlacement>(true).ToList();
Expand All @@ -48,9 +51,17 @@ public XbimPlacementTree(IModel model, bool adjustWcs = true)
if (localPlacement.PlacementRelTo != null) //resolve parent
{
var xbimPlacement = Nodes[localPlacement.EntityLabel];
var xbimPlacementParent = Nodes[localPlacement.PlacementRelTo.EntityLabel];
xbimPlacement.Parent = xbimPlacementParent;
xbimPlacementParent.Children.Add(xbimPlacement);
if (Nodes.TryGetValue(localPlacement.PlacementRelTo.EntityLabel, out var relTo))
{
var xbimPlacementParent = relTo;
xbimPlacement.Parent = xbimPlacementParent;
xbimPlacementParent.Children.Add(xbimPlacement);
}
else
{
logger?.LogError("PlacementRelTo entity #{RelToEntityLabel} not found; adding #{PlacedEntity} as root node.", localPlacement.PlacementRelTo.EntityLabel, localPlacement.EntityLabel);
rootNodes.Add(Nodes[localPlacement.EntityLabel]);
}
}
else
rootNodes.Add(Nodes[localPlacement.EntityLabel]);
Expand Down