Ejemplo n.º 1
0
        public static Panel Transform(this Panel panel, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            Panel result = panel.ShallowClone();

            result.ExternalEdges = result.ExternalEdges.Select(x => x.Transform(transform, tolerance)).ToList();
            result.Openings      = result.Openings.Select(x => x.Transform(transform, tolerance)).ToList();

            Basis orientation = panel.LocalOrientation()?.Transform(transform);

            if (orientation != null)
            {
                result.OrientationAngle = orientation.Z.OrientationAngleAreaElement(orientation.X);
            }
            else
            {
                BH.Engine.Reflection.Compute.RecordWarning("Local orientation of the panel could not be transformed. Please note that the orientation of the resultant panel may be incorrect.");
            }

            return(result);
        }
Ejemplo n.º 2
0
        /***************************************************/

        private static IElement0D Transform(this IElement0D element0D, TransformMatrix transform, double tolerance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return null;
            }

            return element0D.ISetGeometry(Geometry.Modify.Transform(element0D.IGeometry(), transform));
        }
Ejemplo n.º 3
0
        /***************************************************/
        /**** Public Methods - Solid                    ****/
        /***************************************************/

        public static BoundaryRepresentation Transform(this BoundaryRepresentation solid, TransformMatrix transform)
        {
            double volume = solid.Volume;

            if (transform.IsRigidTransformation())
            {
                Reflection.Compute.RecordWarning("Transformation is not rigid. Therefore stored BoundaryRepresentation Volume will be invalidated and reset to NaN (not a number)");
                volume = double.NaN;
            }

            return(new BoundaryRepresentation(solid.Surfaces.Select(x => x.ITransform(transform)), volume));
        }
Ejemplo n.º 4
0
        public static oM.Physical.Elements.ISurface Transform(this oM.Physical.Elements.ISurface panel, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            oM.Physical.Elements.ISurface result = panel.ShallowClone();
            result.Location = result.Location?.ITransform(transform);
            result.Openings = result.Openings?.Select(x => x?.Transform(transform, tolerance)).ToList();
            return(result);
        }
Ejemplo n.º 5
0
        public static IOpening Transform(this IOpening opening, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            IOpening result = opening.ShallowClone();

            result.Location = result.Location?.ITransform(transform);
            return(result);
        }
Ejemplo n.º 6
0
        public static Opening Transform(this Opening opening, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            Opening result = opening.ShallowClone();

            result.Edges = result.Edges.Select(x => x.Transform(transform, tolerance)).ToList();
            return(result);
        }
Ejemplo n.º 7
0
        public static Edge Transform(this Edge edge, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            Edge result = edge.ShallowClone();

            result.Curve = result.Curve.ITransform(transform);
            return(result);
        }
Ejemplo n.º 8
0
        public static Vertex Transform(this Vertex vertex, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            Vertex result = vertex.DeepClone();

            result.Point = result.Point.Transform(transform);
            return(result);
        }
Ejemplo n.º 9
0
        public static CeilingTile Transform(this CeilingTile tile, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            CeilingTile result = tile.ShallowClone();

            result.Perimeter = result.Perimeter.ITransform(transform);
            return(result);
        }
Ejemplo n.º 10
0
        public static RigidLink Transform(this RigidLink link, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            RigidLink result = link.ShallowClone();

            result.PrimaryNode    = result.PrimaryNode.Transform(transform, tolerance);
            result.SecondaryNodes = result.SecondaryNodes.Select(x => x.Transform(transform, tolerance)).ToList();
            return(result);
        }
Ejemplo n.º 11
0
        public static RenderMesh Transform(this RenderMesh renderMesh, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            RenderMesh result = renderMesh.DeepClone();

            result.Vertices = result.Vertices.Select(x => x.Transform(transform, tolerance)).ToList();

            return(result);
        }
Ejemplo n.º 12
0
        public static CameraDevice Transform(this CameraDevice camera, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            CameraDevice result = camera.ShallowClone();

            result.EyePosition    = result.EyePosition.Transform(transform);
            result.TargetPosition = result.TargetPosition.Transform(transform);
            return(result);
        }
Ejemplo n.º 13
0
        public static Luminaire Transform(this Luminaire luminaire, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            Luminaire result = luminaire.ShallowClone();

            result.Position  = result.Position.Transform(transform);
            result.Direction = result.Direction.Transform(transform);
            return(result);
        }
Ejemplo n.º 14
0
        public static IInstance Transform(this IInstance instance, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            IInstance result = instance.GetShallowClone() as IInstance;

            result.Location    = result.Location?.ITransform(transform);
            result.Orientation = result.Orientation?.Transform(transform);
            return(result);
        }
Ejemplo n.º 15
0
        public static CurtainWall Transform(this CurtainWall wall, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            CurtainWall result = wall.ShallowClone();

            result.ExternalEdges = result.ExternalEdges.Select(x => x.Transform(transform, tolerance)).ToList();
            result.Openings      = result.Openings.Select(x => x.Transform(transform, tolerance)).ToList();

            return(result);
        }
Ejemplo n.º 16
0
        /***************************************************/

        public static ICurve Transform(this Circle curve, TransformMatrix transform)
        {
            if (transform.IsRigidTransformation() || transform.IsUniformScaling())
            {
                return new Circle
                       {
                           Centre = curve.Centre.Transform(transform),
                           Radius = (curve.StartPoint() - curve.Centre).Transform(transform).Length(),
                           Normal = curve.Normal.Transform(transform)
                       }
            }
            ;
            else
            {
                Reflection.Compute.RecordNote("Transformation is not rigid or uniform. Converting into NurbsCurve. Change in shape may occur.");

                return(curve.ToNurbsCurve().Transform(transform));
            }
        }
Ejemplo n.º 17
0
        /***************************************************/
        /**** Public Methods - Curves                   ****/
        /***************************************************/

        public static ICurve Transform(this Arc curve, TransformMatrix transform)
        {
            if (transform.IsRigidTransformation() || transform.IsUniformScaling())
            {
                return new Arc
                       {
                           Radius           = (curve.StartPoint() - curve.CoordinateSystem.Origin).Transform(transform).Length(),
                           StartAngle       = curve.StartAngle,
                           EndAngle         = curve.EndAngle,
                           CoordinateSystem = curve.CoordinateSystem.Transform(transform)
                       }
            }
            ;
            else
            {
                Reflection.Compute.RecordNote("Transformation is not rigid or uniform. Converting into NurbsCurve. Change in shape may occur.");

                return(curve.ToNurbsCurve().Transform(transform));
            }
        }
Ejemplo n.º 18
0
        /***************************************************/

        public static ICurve Transform(this Ellipse curve, TransformMatrix transform)
        {
            if (transform.IsRigidTransformation() || transform.IsUniformScaling())
            {
                return new Ellipse
                       {
                           Centre  = curve.Centre.Transform(transform),
                           Axis1   = curve.Axis1.Transform(transform),
                           Axis2   = curve.Axis2.Transform(transform),
                           Radius1 = (curve.Axis1.Normalise() * curve.Radius1).Transform(transform).Length(),
                           Radius2 = (curve.Axis2.Normalise() * curve.Radius2).Transform(transform).Length(),
                       }
            }
            ;
            else
            {
                Reflection.Compute.RecordNote("Transformation is not rigid or uniform. Converting into NurbsCurve. Change in shape may occur.");

                return(curve.ToNurbsCurve().Transform(transform));
            }
        }
Ejemplo n.º 19
0
        public static FEMesh Transform(this FEMesh mesh, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            FEMesh result = mesh.ShallowClone();

            result.Nodes = result.Nodes.Select(x => x.Transform(transform, tolerance)).ToList();

            List <Basis> orientationsBefore = mesh.LocalOrientations();

            result.Faces = new List <FEMeshFace>(mesh.Faces);
            for (int i = 0; i < orientationsBefore.Count; i++)
            {
                result.Faces[i] = result.Faces[i].SetLocalOrientation(result, orientationsBefore[i].Transform(transform).X);
            }

            return(result);
        }
Ejemplo n.º 20
0
        public static FrameEdge Transform(this FrameEdge edge, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            FrameEdge result = edge.ShallowClone();

            result.Curve = result.Curve.ITransform(transform);

            if (edge.FrameEdgeProperty != null)
            {
                if (edge.Curve is Line)
                {
                    Line lineBefore = (Line)edge.Curve;
                    Line lineAfter  = (Line)result.Curve;

                    List <ConstantFramingProperty> newProperties = new List <ConstantFramingProperty>();
                    foreach (ConstantFramingProperty property in edge.FrameEdgeProperty.SectionProperties)
                    {
                        ConstantFramingProperty newProperty = property.ShallowClone();
                        Vector normalBefore = lineBefore.ElementNormal(property.OrientationAngle);
                        Vector normalAfter  = normalBefore.Transform(transform);
                        newProperty.OrientationAngle = normalAfter.OrientationAngleLinear(lineAfter);
                        newProperties.Add(newProperty);
                    }

                    edge.FrameEdgeProperty.SectionProperties = newProperties;
                }
                else if (!edge.Curve.IIsPlanar(tolerance))
                {
                    BH.Engine.Reflection.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}");
                }
            }

            return(result);
        }
Ejemplo n.º 21
0
        /***************************************************/
        /**** Private Methods - IElements               ****/
        /***************************************************/

        private static IElement2D Transform(this IElement2D element2D, TransformMatrix transform, double tolerance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return null;
            }

            List<IElement1D> newOutline = new List<IElement1D>();
            foreach (IElement1D element1D in element2D.IOutlineElements1D())
            {
                newOutline.Add(element1D.Transform(transform, tolerance));
            }
            IElement2D result = element2D.ISetOutlineElements1D(newOutline);

            List<IElement2D> newInternalOutlines = new List<IElement2D>();
            foreach (IElement2D internalElement2D in result.IInternalElements2D())
            {
                newInternalOutlines.Add(internalElement2D.Transform(transform, tolerance));
            }
            result = result.ISetInternalElements2D(newInternalOutlines);
            return result;
        }
Ejemplo n.º 22
0
        public static Duct Transform(this Duct duct, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            Duct result = duct.ShallowClone();

            result.StartPoint = result.StartPoint.Transform(transform);
            result.EndPoint   = result.EndPoint.Transform(transform);

            Vector normalBefore = new Line {
                Start = duct.StartPoint, End = duct.EndPoint
            }.ElementNormal(duct.OrientationAngle);
            Vector normalAfter = normalBefore.Transform(transform);

            result.OrientationAngle = normalAfter.OrientationAngleLinear(new Line {
                Start = result.StartPoint, End = result.EndPoint
            });

            return(result);
        }
Ejemplo n.º 23
0
        public static Bar Transform(this Bar bar, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            Bar result = bar.ShallowClone();

            result.StartNode = result.StartNode.Transform(transform, tolerance);
            result.EndNode   = result.EndNode.Transform(transform, tolerance);

            Vector normalBefore = new Line {
                Start = bar.StartNode.Position, End = bar.EndNode.Position
            }.ElementNormal(bar.OrientationAngle);
            Vector normalAfter = normalBefore.Transform(transform);

            result.OrientationAngle = normalAfter.OrientationAngleLinear(new Line {
                Start = result.StartNode.Position, End = result.EndNode.Position
            });

            return(result);
        }
Ejemplo n.º 24
0
        public static IFramingElement Transform(this IFramingElement framingElement, TransformMatrix transform, double tolerance = Tolerance.Distance)
        {
            if (!transform.IsRigidTransformation(tolerance))
            {
                BH.Engine.Reflection.Compute.RecordError("Transformation failed: only rigid body transformations are currently supported.");
                return(null);
            }

            IFramingElement result = framingElement.ShallowClone();

            result.Location = result.Location.ITransform(transform);

            ConstantFramingProperty property = result.Property as ConstantFramingProperty;

            if (property == null)
            {
                BH.Engine.Reflection.Compute.RecordWarning($"Orientation angle of the IFramingElement has not been transformed because its property is not ConstantFramingProperty. BHoM_Guid: {framingElement.BHoM_Guid}");
            }
            else
            {
                if (framingElement.Location is Line)
                {
                    ConstantFramingProperty newProperty = property.ShallowClone();
                    Vector normalBefore = ((Line)framingElement.Location).ElementNormal(property.OrientationAngle);
                    Vector normalAfter  = normalBefore.Transform(transform);
                    newProperty.OrientationAngle = normalAfter.OrientationAngleLinear((Line)result.Location);
                    result.Property = newProperty;
                }
                else if (!framingElement.Location.IIsPlanar(tolerance))
                {
                    BH.Engine.Reflection.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: {framingElement.BHoM_Guid}");
                }
            }

            return(result);
        }