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

Structure_Engine: flipping of bars fixed to take release into account #3447

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
136 changes: 135 additions & 1 deletion Structure_Engine/Modify/Flip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@
using BH.oM.Quantities.Attributes;
using System.ComponentModel;
using BH.Engine.Base;
using BH.oM.Structure.Constraints;
using System;
using BH.oM.Structure.SectionProperties;
using BH.oM.Spatial.ShapeProfiles;
using BH.oM.Spatial.ShapeProfiles.CellularOpenings;
using BH.oM.Structure.MaterialFragments;
using System.Collections.Generic;
using System.Linq;
using BH.Engine.Spatial;
using System.Data;


namespace BH.Engine.Structure
Expand All @@ -40,17 +50,64 @@
[Description("Flips the StartNode and EndNode of the Bar, i.e. the StartNode is set to the EndNode and vice versa. No modification is being made to releases, orientation angle, offsets etc.")]
[Input("bar", "The Bar to flip.")]
[Output("bar", "The Bar with flipped end Nodes.")]
public static Bar Flip(this Bar bar)

Check warning on line 53 in Structure_Engine/Modify/Flip.cs

View check run for this annotation

BHoMBot-CI / code-compliance

Structure_Engine/Modify/Flip.cs#L53

Modify methods should return void, or their return type should be different to the input type of their first parameter - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/ModifyReturnsDifferentType
{
if (bar.IsNull())
return null;

Bar flipped = bar.ShallowClone();

// Flip Nodes
Node tempNode = flipped.Start;
flipped.Start = flipped.End;
flipped.End = tempNode;

// Flip orientation angle
if (bar.IsVertical())
flipped.OrientationAngle = -bar.OrientationAngle + Math.PI;
else
flipped.OrientationAngle = -bar.OrientationAngle;

// Flip Offsets
if (bar.Offset != null)
{
Vector tempV = bar.Offset.Start;
flipped.Offset.Start = bar.Offset.End;
flipped.Offset.End = tempV;

if (bar.Offset.Start != null)
flipped.Offset.Start.X *= -1;

if (bar.Offset.End != null)
flipped.Offset.End.X *= -1;

if (!bar.IsVertical())
{
if (bar.Offset.Start != null)
flipped.Offset.Start.Y *= -1;

if (bar.Offset.End != null)
flipped.Offset.End.Y *= -1;
}
}

// Flip releases
BarRelease flippedRelease = bar.Release?.ShallowClone();
if (flippedRelease != null)
{
Constraint6DOF tempRelease = flippedRelease.StartRelease;
flippedRelease.StartRelease = flippedRelease.EndRelease;
flippedRelease.EndRelease = tempRelease;
flipped.Release = flippedRelease;
}

// Flip section property
if (bar.SectionProperty != null)
{
ISectionProperty flippedSectionProperty = FlipSection(bar.SectionProperty);
flipped.SectionProperty = flippedSectionProperty;
}

return flipped;
}

Expand All @@ -59,7 +116,7 @@
[Description("Flips the location curve of the Edge, i.e. the start becomes the end and vice versa.")]
[Input("edge", "The Edge to flip.")]
[Output("edge", "The Edge with a flipped location curve.")]
public static Edge Flip(this Edge edge)

Check warning on line 119 in Structure_Engine/Modify/Flip.cs

View check run for this annotation

BHoMBot-CI / code-compliance

Structure_Engine/Modify/Flip.cs#L119

Modify methods should return void, or their return type should be different to the input type of their first parameter - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/ModifyReturnsDifferentType
{
if (edge.IsNull())
return null;
Expand All @@ -73,11 +130,11 @@
[Description("Flips the normal of the Stem.")]
[Input("stem", "The Stem to flip.")]
[Output("stem", "The Stem with flipped Normal.")]
public static Stem Flip(this Stem stem)

Check warning on line 133 in Structure_Engine/Modify/Flip.cs

View check run for this annotation

BHoMBot-CI / code-compliance

Structure_Engine/Modify/Flip.cs#L133

Modify methods should return void, or their return type should be different to the input type of their first parameter - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/ModifyReturnsDifferentType
{
if (stem.IsNull())
return null;
if (stem.Normal.IsNull("The Normal of the Stem is null and could not be flipped.","Flip"))
if (stem.Normal.IsNull("The Normal of the Stem is null and could not be flipped.", "Flip"))
return null;

Stem flipped = stem.ShallowClone();
Expand All @@ -86,6 +143,83 @@

return flipped;
}

public static ISectionProperty FlipSection(ISectionProperty section)

Check warning on line 147 in Structure_Engine/Modify/Flip.cs

View check run for this annotation

BHoMBot-CI / documentation-compliance

Structure_Engine/Modify/Flip.cs#L147

Input parameter requires a matching Input attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsInputAttributePresent Method must contain an Output or MultiOutput attribute - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/HasOutputAttribute

Check failure on line 147 in Structure_Engine/Modify/Flip.cs

View check run for this annotation

BHoMBot-CI / code-compliance

Structure_Engine/Modify/Flip.cs#L147

Method must be an extension method - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/IsExtensionMethod Modify methods should return void, or their return type should be different to the input type of their first parameter - For more information see https://bhom.xyz/documentation/DevOps/Code%20Compliance%20and%20CI/Compliance%20Checks/ModifyReturnsDifferentType
{
if (section is IGeometricalSection geometricalSection)
{
ISectionProperty tempSection = null;
IProfile profile = geometricalSection.SectionProfile;
IProfile tempProfile = IFlipProfile(profile);
IMaterialFragment material = section.Material;

tempProfile.Name = profile.Name;
tempProfile.Fragments = profile.Fragments;
tempSection = Create.GenericSectionFromProfile(tempProfile, material, section.Name);
return tempSection;
}
else
{
Base.Compute.RecordError("The given shape profile is not an IGeometricalSection.");
return null;
}
}

private static IProfile IFlipProfile(IProfile profile)
{
if (profile is BoxProfile || profile is ICellularOpening || profile is CircleProfile || profile is FabricatedBoxProfile ||
profile is FabricatedISectionProfile || profile is GeneralisedFabricatedBoxProfile || profile is ISectionProfile || profile is KiteProfile
|| profile is RectangleProfile || profile is TaperFlangeISectionProfile || profile is TSectionProfile ||
profile is TubeProfile || profile is VoidedISectionProfile)
{
return profile;
}
else
{
return FlipProfile(profile as dynamic);
}
}
private static IProfile FlipProfile(AngleProfile oldProfile)
{
return Spatial.Create.AngleProfile(oldProfile.Height, oldProfile.Width, oldProfile.WebThickness, oldProfile.FlangeThickness, oldProfile.RootRadius,
oldProfile.ToeRadius, !oldProfile.MirrorAboutLocalZ, oldProfile.MirrorAboutLocalY);
}

private static IProfile FlipProfile(ChannelProfile oldProfile)
{
return Spatial.Create.ChannelProfile(oldProfile.Height, oldProfile.FlangeWidth, oldProfile.WebThickness, oldProfile.FlangeThickness,
oldProfile.RootRadius, oldProfile.ToeRadius, !oldProfile.MirrorAboutLocalZ);
}
private static IProfile FlipProfile(FreeFormProfile oldProfile)
{
List<ICurve> curves = oldProfile.Edges.ToList();
return Spatial.Create.FreeFormProfile(curves.Select(x => x.IMirror(Geometry.Create.Plane(new Point(), Vector.XAxis))));
}
private static IProfile FlipProfile(GeneralisedTSectionProfile oldProfile)
{
return Spatial.Create.GeneralisedTSectionProfile(oldProfile.Height, oldProfile.WebThickness, oldProfile.RightOutstandWidth, oldProfile.RightOutstandThickness,
oldProfile.LeftOutstandWidth, oldProfile.LeftOutstandThickness, oldProfile.MirrorAboutLocalY);
}
private static IProfile FlipProfile(TaperedProfile oldProfile)
{
List<IProfile> newProfiles = new List<IProfile>();
foreach (IProfile profile in oldProfile.Profiles.Values.Reverse())
{
newProfiles.Add(IFlipProfile(profile as dynamic));
}

return Spatial.Create.TaperedProfile(oldProfile.Profiles.Keys.ToList(), newProfiles, oldProfile.InterpolationOrder);
}
private static IProfile FlipProfile(TaperFlangeChannelProfile oldProfile)
{
return Spatial.Create.TaperFlangeChannelProfile(oldProfile.Height, oldProfile.FlangeWidth, oldProfile.WebThickness, oldProfile.FlangeThickness, oldProfile.FlangeSlope,
oldProfile.RootRadius, oldProfile.ToeRadius, !oldProfile.MirrorAboutLocalZ);
}
private static IProfile FlipProfile(IProfile oldProfile)
{
Base.Compute.RecordError("The given shape profile does not have a FlipProfile method implemented.");
return null;
}
}
}

Expand Down