Skip to content

Spatial_Engine: Add Orient method for IElements #2924

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

Merged
merged 11 commits into from
Oct 11, 2022
Merged
1 change: 1 addition & 0 deletions .ci/Datasets/Spatial_Engine/Modify/Orient.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Facade_Engine/Modify/Transform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static FrameEdge Transform(this FrameEdge edge, TransformMatrix transform
Line lineBefore = (Line)edge.Curve;
Line lineAfter = (Line)result.Curve;

result.FrameEdgeProperty = edge.FrameEdgeProperty.ShallowClone();
List<ConstantFramingProperty> newProperties = new List<ConstantFramingProperty>();
foreach (ConstantFramingProperty property in edge.FrameEdgeProperty.SectionProperties)
{
Expand All @@ -72,7 +73,7 @@ public static FrameEdge Transform(this FrameEdge edge, TransformMatrix transform
newProperties.Add(newProperty);
}

edge.FrameEdgeProperty.SectionProperties = newProperties;
result.FrameEdgeProperty.SectionProperties = newProperties;
}
else if (!edge.Curve.IIsPlanar(tolerance))
BH.Engine.Base.Compute.RecordWarning($"The element's location is a nonlinear, nonplanar curve. Correctness of orientation angle after transform could not be ensured in 100%. BHoM_Guid: {edge.BHoM_Guid}");
Expand Down
73 changes: 73 additions & 0 deletions Spatial_Engine/Modify/Orient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* This file is part of the Buildings and Habitats object Model (BHoM)
* Copyright (c) 2015 - 2022, the respective contributors. All rights reserved.
*
* Each contributor holds copyright over their respective contributions.
* The project versioning (Git) records all such contribution source information.
*
*
* The BHoM is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3.0 of the License, or
* (at your option) any later version.
*
* The BHoM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
*/

using BH.oM.Base;
using BH.oM.Base.Attributes;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using BH.oM.Dimensional;
using BH.oM.Geometry;
using BH.oM.Geometry.CoordinateSystem;


namespace BH.Engine.Spatial
{
public static partial class Modify
{
/***************************************************/
/**** Public Methods ****/
/***************************************************/

[Description("Orients the element from one coordinate system to another.")]
[Input("element", "The element to orient.")]
[Input("from", "The cartesian coordinate system to orient from.")]
[Input("to", "The cartesian coordinate system to orient to.")]
[Output("element", "The reoriented element.")]
public static IElement Orient(this IElement element, Cartesian from, Cartesian to)
{
if (element == null)
{
Base.Compute.RecordError("Cannot Orient a null element.");
return null;
}

if (from == null)
{
Base.Compute.RecordError($"The {nameof(from)} coordinate system is null. Unable to orient the element. Null returned.");
return null;
}

if (to == null)
{
Base.Compute.RecordError($"The {nameof(to)} coordinate system is null. Unable to orient the element. Null returned.");
return null;
}

TransformMatrix transformMatrix = Geometry.Create.OrientationMatrix(from, to);
return element.ITransform(transformMatrix);
}

/***************************************************/
}
}