Skip to content

Commit

Permalink
Apply transformations, if required, when generating clashes from Navi…
Browse files Browse the repository at this point in the history
…sworks to bounding boxes
  • Loading branch information
GeorgDangl committed Aug 25, 2024
1 parent 21bde6f commit 0359c4c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ private class ClashTestWrapper
{
var viewpoint = _doc.CurrentViewpoint.Value;
NavisUtils.GetGunits(_doc);
var v = GetViewpointFromNavisworksViewpoint(viewpoint, generateLargeViewpoints: true);
var v = GetViewpointFromNavisworksViewpoint(viewpoint, generateLargeViewpoints: true, centerForBoundingBox: null);
return v;
}

private BcfViewpoint GetViewpointFromNavisworksViewpoint(Viewpoint viewpoint,
bool generateLargeViewpoints,
Point3D centerForBoundingBox,
List<ModelItem> selectedItems = null)
{
var v = new BcfViewpoint();
Expand Down Expand Up @@ -147,6 +148,38 @@ private BcfViewpoint GetViewpointFromNavisworksViewpoint(Viewpoint viewpoint,
var commonBoundingBox = new BoundingBox3D(new Point3D(minX, minY, minZ),
new Point3D(maxX, maxY, maxZ));

if (centerForBoundingBox != null)
{
// This means we want to move the bounding box to the center of the actual clash,
// since there were issues where the camera coordinates were correct but the element
// bounding boxes did not work properly
// We're using the center of the clash as the center of the bounding box
var elementBoundingBoxDeltaX = maxX - minX;
var elementBoundingBoxDeltaY = maxY - minY;
var elementBoundingBoxDeltaZ = maxZ - minZ;
var clashBoundingBoxMinPoint = new Point3D(centerForBoundingBox.X - 20d.ToInternal(),
centerForBoundingBox.Y - 20d.ToInternal(),
centerForBoundingBox.Z - 20d.ToInternal());
var clashBoundingBoxMaxPoint = new Point3D(centerForBoundingBox.X + 20d.ToInternal(),
centerForBoundingBox.Y + 20d.ToInternal(),
centerForBoundingBox.Z + 20d.ToInternal());

commonBoundingBox = new BoundingBox3D(clashBoundingBoxMinPoint, clashBoundingBoxMaxPoint);

try
{
var translation = _doc.Models.FirstOrDefault().Transform.Translation?.Negate();
if (translation != null)
{
commonBoundingBox = commonBoundingBox.Translate(translation);
}
}
catch
{
// Ignoring errors here, that means there's no translation
}
}

var clippingPlanes = TransformBoundingBoxToClippingPlanes(commonBoundingBox);

v.ClippingPlanes ??= new List<BcfViewpointClippingPlane>();
Expand Down Expand Up @@ -197,6 +230,7 @@ public List<BcfTopic> CreateClashIssues(NavisworksClashCreationData clashCreatio
Action checkForNavisworksClashCancellation,
CancellationToken cancellationToken)
{
var shouldMoveBoundingBox = clashCreationData.ShouldMoveBoundingBoxToCenterOfClash;
var bcfTopics = new List<BcfTopic>();
NavisUtils.GetGunits(_doc);

Expand Down Expand Up @@ -313,7 +347,7 @@ public List<BcfTopic> CreateClashIssues(NavisworksClashCreationData clashCreatio
// Prevent redraw for every test and item
doc.ActiveView.RequestDelayedRedraw(ViewRedrawRequests.All);

var bcfViewpoint = GetViewpointFromNavisworksViewpoint(viewpoint, generateLargeViewpoints, selectedItems);
var bcfViewpoint = GetViewpointFromNavisworksViewpoint(viewpoint, generateLargeViewpoints, shouldMoveBoundingBox ? result.Center : null, selectedItems);
bcfViewpoint.Id = result.Guid;
bcfTopics.Add(new BcfTopic
{
Expand Down Expand Up @@ -404,7 +438,7 @@ public List<BcfTopic> CreateClashIssues(NavisworksClashCreationData clashCreatio
// Prevent redraw for every test and item
doc.ActiveView.RequestDelayedRedraw(ViewRedrawRequests.All);

var bcfViewpoint = GetViewpointFromNavisworksViewpoint(viewpoint, generateLargeViewpoints, selectedItems);
var bcfViewpoint = GetViewpointFromNavisworksViewpoint(viewpoint, generateLargeViewpoints, shouldMoveBoundingBox ? resultGroup.Center : null, selectedItems);
bcfViewpoint.Id = resultGroup.Guid;
bcfTopics.Add(new BcfTopic
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ private void ApplyClippingPlanes(UIDocument uiDocument, View3D view, BcfViewpoin

if (!boundingBox.Equals(AxisAlignedBoundingBox.Infinite))
{
view.SetSectionBox(ToRevitSectionBox(boundingBox));
var revitSectionBox = ToRevitSectionBox(boundingBox);
view.SetSectionBox(revitSectionBox);
view.IsSectionBoxActive = true;
}
else
Expand Down
2 changes: 2 additions & 0 deletions src/IPA.Bcfier/Models/Clashes/NavisworksClashCreationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public class NavisworksClashCreationData
public string? Status { get; set; }

public List<Guid> ExcludedClashIds { get; set; } = new List<Guid>();

public bool ShouldMoveBoundingBoxToCenterOfClash { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ export class BcfFileComponent {
clashId: selection.clashId,
excludedClashIds: existingIds,
status: selection.statusType,
shouldMoveBoundingBoxToCenterOfClash: true,
})
.subscribe({
next: (createdTopics) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,7 @@ export interface NavisworksClashCreationData {
clashId?: string;
status?: string | null;
excludedClashIds?: string[];
shouldMoveBoundingBoxToCenterOfClash?: boolean;
}

export interface FileResponse {
Expand Down

0 comments on commit 0359c4c

Please sign in to comment.