-
Notifications
You must be signed in to change notification settings - Fork 13
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
base: develop
Are you sure you want to change the base?
Changes from all commits
7893070
bfdb4e3
17ac2a8
136c9cf
589d361
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,17 @@ | |
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; | ||
using Mono.Reflection; | ||
|
||
|
||
namespace BH.Engine.Structure | ||
|
@@ -40,17 +51,40 @@ | |
[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 54 in Structure_Engine/Modify/Flip.cs
|
||
{ | ||
if (bar.IsNull()) | ||
return null; | ||
|
||
Bar flipped = bar.ShallowClone(); | ||
|
||
// Flip Nodes | ||
Node tempNode = flipped.Start; | ||
flipped.Start = flipped.End; | ||
flipped.End = tempNode; | ||
|
||
if (bar.IsVertical()) | ||
flipped.OrientationAngle = -bar.OrientationAngle + Math.PI; | ||
else | ||
flipped.OrientationAngle = -bar.OrientationAngle; | ||
|
||
// 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 = Flip(bar.SectionProperty); | ||
flipped.SectionProperty = flippedSectionProperty; | ||
} | ||
|
||
return flipped; | ||
} | ||
|
||
|
@@ -59,7 +93,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 96 in Structure_Engine/Modify/Flip.cs
|
||
{ | ||
if (edge.IsNull()) | ||
return null; | ||
|
@@ -73,11 +107,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 110 in Structure_Engine/Modify/Flip.cs
|
||
{ | ||
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(); | ||
|
@@ -86,6 +120,87 @@ | |
|
||
return flipped; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need method separator lines between all methods |
||
private static ISectionProperty Flip(this ISectionProperty section) | ||
{ | ||
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(KiteProfile oldProfile) | ||
{ | ||
return oldProfile; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is problematic, might be good to add a warning about it, or let it fallback to the other method |
||
} | ||
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; | ||
Comment on lines
+201
to
+202
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would change this to a warning and return the old profile. |
||
} | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think the offset also need to be handled here.