コード例 #1
0
ファイル: Transform.cs プロジェクト: HoareLea/SAM_Revit
        public static ICurve3D Transform(this Transform transform, ICurve3D curve3D)
        {
            if (transform == null || curve3D == null)
                return null;

            return Transform(transform, curve3D as dynamic);
        }
コード例 #2
0
        public static Edge ToTopologic(this ICurve3D curve3D)
        {
            if (curve3D == null)
            {
                return(null);
            }

            Point3D point3D_1 = curve3D.GetStart();

            if (point3D_1 == null)
            {
                return(null);
            }

            Point3D point3D_2 = curve3D.GetEnd();

            if (point3D_2 == null)
            {
                return(null);
            }

            if (point3D_1 == point3D_2)
            {
                return(null);
            }

            return(Edge.ByStartVertexEndVertex(ToTopologic(point3D_1), ToTopologic(point3D_2)));
        }
コード例 #3
0
        public static List <ISegmentable3D> ExtremeSegmentable3Ds(this IEnumerable <ISegmentable3D> segmentable3Ds, IEnumerable <ISegmentable3D> segmentable3Ds_Auxiliary, double tolerance = Core.Tolerance.Distance)
        {
            if (segmentable3Ds == null || segmentable3Ds_Auxiliary == null)
            {
                return(null);
            }

            List <ISegmentable3D> result = new List <ISegmentable3D>();

            Dictionary <ISegmentable3D, List <Vector3D> > dictionary = new Dictionary <ISegmentable3D, List <Vector3D> >();

            foreach (ISegmentable3D segmentable3D in segmentable3Ds)
            {
                ICurve3D curve3D = segmentable3D as ICurve3D;
                if (curve3D == null)
                {
                    continue;
                }

                foreach (Point3D point3D in new Point3D[] { curve3D.GetStart(), curve3D.GetEnd() })
                {
                    List <Point3D> point3Ds_Intersection = segmentable3D.Intersections(segmentable3Ds_Auxiliary, tolerance);
                    Point3D        point3D_Closest       = point3Ds_Intersection.Closest(point3D);

                    ISegmentable3D segmentable3D_Closest = null;
                    foreach (ISegmentable3D segmentable3D_Temp in segmentable3Ds_Auxiliary)
                    {
                        if (segmentable3D_Temp.On(point3D_Closest, tolerance))
                        {
                            segmentable3D_Closest = segmentable3D_Temp;
                            break;
                        }
                    }

                    if (segmentable3D_Closest != null)
                    {
                        if (!dictionary.TryGetValue(segmentable3D_Closest, out List <Vector3D> vector3Ds))
                        {
                            vector3Ds = new List <Vector3D>();
                            dictionary[segmentable3D_Closest] = vector3Ds;
                        }

                        Vector3D vector3D = new Vector3D(point3D_Closest, point3D);

                        if (vector3Ds.Find(x => x.AlmostEqual(vector3D, tolerance)) == null)
                        {
                            vector3Ds.Add(vector3D);

                            ISegmentable3D segmentable3D_Moved = segmentable3D_Closest.GetMoved(vector3D) as ISegmentable3D;

                            result.Add(segmentable3D_Moved);
                        }
                    }
                }
            }

            return(result);
        }
コード例 #4
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="dataAccess">
        /// The DA object is used to retrieve from inputs and store in outputs.
        /// </param>
        protected override void SolveInstance(IGH_DataAccess dataAccess)
        {
            ISAMGeometry sAMGeometry = null;

            if (!dataAccess.GetData(0, ref sAMGeometry) || sAMGeometry == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Invalid data");
                return;
            }

            Point3D point3D = sAMGeometry as Point3D;

            if (point3D != null)
            {
                dataAccess.SetData(0, Geometry.Topologic.Convert.ToTopologic(point3D));
                return;
            }

            ICurve3D curve3D = sAMGeometry as ICurve3D;

            if (curve3D != null)
            {
                dataAccess.SetData(0, Geometry.Topologic.Convert.ToTopologic(curve3D));
                return;
            }

            Polygon3D polygon3D = sAMGeometry as Polygon3D;

            if (polygon3D != null)
            {
                dataAccess.SetData(0, Geometry.Topologic.Convert.ToTopologic(polygon3D));
                return;
            }

            Face3D face3D = sAMGeometry as Face3D;

            if (face3D != null)
            {
                dataAccess.SetData(0, Geometry.Topologic.Convert.ToTopologic(face3D));
                return;
            }

            Shell shell = sAMGeometry as Shell;

            if (shell != null)
            {
                Brep brep = Rhino.Convert.ToRhino(shell);
                if (brep != null)
                {
                    dataAccess.SetData(0, brep.ToTopologic(Core.Tolerance.MacroDistance));
                    return;
                }
            }

            AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Cannot convert geometry");
        }
コード例 #5
0
        public static Polygon3D ToSAM_Polygon3D(this CurveLoop curveLoop, double tolerance = Core.Tolerance.Distance)
        {
            List <Segment3D> segment3Ds = new List <Segment3D>();

            foreach (Curve curve in curveLoop)
            {
                ICurve3D curve3D = curve.ToSAM();
                if (curve3D is ISegmentable3D)
                {
                    List <Segment3D> segment3Ds_Temp = ((ISegmentable3D)curve3D).GetSegments();
                    if (segment3Ds_Temp == null || segment3Ds_Temp.Count == 0)
                    {
                        continue;
                    }

                    segment3Ds.AddRange(segment3Ds_Temp);
                }
            }

            if (segment3Ds.Count < 3)
            {
                return(null);
            }

            int count = segment3Ds.Count;

            segment3Ds.Add(segment3Ds[0]);

            bool oriented = true;

            for (int i = 0; i < count; i++)
            {
                if (segment3Ds[i][1].Distance(segment3Ds[i + 1][0]) > tolerance)
                {
                    oriented = false;
                    break;
                }
            }

            segment3Ds.RemoveAt(count);

            if (oriented)
            {
                return(Spatial.Create.Polygon3D(segment3Ds.ConvertAll(x => x.GetStart())));
            }

            List <Point3D> point3Ds = new List <Point3D>();

            foreach (Segment3D segment3D in segment3Ds)
            {
                Spatial.Modify.Add(point3Ds, segment3D.GetStart(), tolerance);
                Spatial.Modify.Add(point3Ds, segment3D.GetEnd(), tolerance);
            }

            if (point3Ds == null || point3Ds.Count < 3)
            {
                return(null);
            }

            Spatial.Plane plane = Spatial.Create.Plane(point3Ds, tolerance);
            if (plane == null)
            {
                return(null);
            }

            List <Planar.Segment2D> segment2Ds = segment3Ds.ConvertAll(x => plane.Convert(plane.Project(x)));

            if (segment2Ds == null || segment2Ds.Count < 3)
            {
                return(null);
            }

            List <Planar.Polygon2D> polygon2Ds = Planar.Create.Polygon2Ds(segment2Ds, tolerance);

            if (polygon2Ds == null || polygon2Ds.Count == 0)
            {
                //Extra case for situation where segment2Ds does not are not properly sorted
                List <Planar.Point2D>   point2Ds        = new List <Planar.Point2D>();
                List <Planar.Segment2D> segment2Ds_Temp = new List <Planar.Segment2D>(segment2Ds);
                point2Ds.Add(segment2Ds_Temp[0][0]);
                point2Ds.Add(segment2Ds_Temp[0][1]);
                segment2Ds_Temp.RemoveAt(0);
                while (segment2Ds_Temp.Count > 0)
                {
                    Point2D point2D = point2Ds.Last();
                    segment2Ds_Temp.SortByDistance(point2D);
                    Segment2D segment2D = segment2Ds_Temp[0];
                    if (segment2D[0].Distance(point2D) > segment2D[1].Distance(point2D))
                    {
                        point2Ds.Add(segment2D[0]);
                    }
                    else
                    {
                        point2Ds.Add(segment2D[1]);
                    }
                    segment2Ds_Temp.RemoveAt(0);
                }
                return(plane.Convert(new Polygon2D(point2Ds)));
            }

            if (polygon2Ds.Count > 1)
            {
                polygon2Ds.Sort((x, y) => y.GetArea().CompareTo(x.GetArea()));
            }

            return(plane.Convert(polygon2Ds[0]));
        }
コード例 #6
0
        public static Aperture ToSAM_Aperture(this FamilyInstance familyInstance, Core.Revit.ConvertSettings convertSettings)
        {
            if (familyInstance == null)
            {
                return(null);
            }

            Aperture result = convertSettings?.GetObject <Aperture>(familyInstance.Id);

            if (result != null)
            {
                return(result);
            }

            if (Core.Revit.Query.Simplified(familyInstance))
            {
                result = Core.Revit.Query.IJSAMObject <Aperture>(familyInstance);
                if (result != null)
                {
                    convertSettings?.Add(familyInstance.Id, result);
                    return(result);
                }
            }

            Point3D point3D_Location = Geometry.Revit.Query.Location(familyInstance);

            if (point3D_Location == null)
            {
                return(null);
            }

            PanelType       panelType_Host       = PanelType.Undefined;
            BuiltInCategory builtInCategory_Host = BuiltInCategory.INVALID;

            if (familyInstance.Host != null)
            {
                HostObject hostObject = familyInstance.Host as HostObject;
                if (hostObject != null)
                {
                    builtInCategory_Host = (BuiltInCategory)hostObject.Category.Id.IntegerValue;

                    List <Face3D> face3Ds_Temp = hostObject.Profiles();
                    if (face3Ds_Temp != null && face3Ds_Temp.Count != 0)
                    {
                        Geometry.Spatial.Plane plane_Host = face3Ds_Temp.Closest(point3D_Location)?.GetPlane();
                        if (plane_Host != null)
                        {
                            point3D_Location = plane_Host.Project(point3D_Location);
                        }
                    }

                    HostObjAttributes hostObjAttributes = familyInstance.Document.GetElement(hostObject.GetTypeId()) as HostObjAttributes;
                    if (hostObjAttributes != null)
                    {
                        panelType_Host = hostObjAttributes.PanelType();
                    }

                    if (panelType_Host == PanelType.Undefined)
                    {
                        panelType_Host = hostObject.PanelType();
                    }
                }
            }

            ApertureConstruction apertureConstruction = ToSAM_ApertureConstruction(familyInstance, convertSettings);

            if (apertureConstruction == null && panelType_Host != PanelType.Undefined)
            {
                apertureConstruction = Analytical.Query.DefaultApertureConstruction(panelType_Host, familyInstance.ApertureType()); //Default Aperture Construction
            }
            Vector3D axisX  = null;
            Vector3D normal = null;
            Vector3D axisY  = null;

            if (builtInCategory_Host == BuiltInCategory.OST_Roofs)
            {
                axisX  = familyInstance.HandOrientation.ToSAM_Vector3D(false);
                axisY  = familyInstance.FacingOrientation.ToSAM_Vector3D(false);
                normal = Geometry.Spatial.Query.AxisY(axisY, axisX);
            }
            else
            {
                axisX  = familyInstance.HandOrientation.ToSAM_Vector3D(false);
                normal = familyInstance.FacingOrientation.ToSAM_Vector3D(false);
                axisY  = Geometry.Spatial.Query.AxisY(normal, axisX);
            }


            Geometry.Spatial.Plane plane = Geometry.Spatial.Create.Plane(point3D_Location, axisX, axisY);
            if (!plane.Normal.SameHalf(normal))
            {
                plane.FlipZ(false);
            }

            List <Face3D> face3Ds = Geometry.Revit.Convert.ToSAM_Face3Ds(familyInstance);

            if (face3Ds == null || face3Ds.Count == 0)
            {
                return(null);
            }

            List <Point2D> point2Ds = new List <Point2D>();

            foreach (Face3D face3D_Temp in face3Ds)
            {
                IClosedPlanar3D closedPlanar3D = face3D_Temp.GetExternalEdge3D();
                if (closedPlanar3D is ICurvable3D)
                {
                    List <ICurve3D> curve3Ds = ((ICurvable3D)closedPlanar3D).GetCurves();
                    foreach (ICurve3D curve3D in curve3Ds)
                    {
                        ICurve3D curve3D_Temp = plane.Project(curve3D);
                        point2Ds.Add(plane.Convert(curve3D_Temp.GetStart()));
                    }
                }
            }

            if (point2Ds == null || point2Ds.Count == 0)
            {
                return(null);
            }

            //TODO: Working on SAM Families (requested by Michal)

            string parameterName_Height = Core.Revit.Query.Name(ActiveSetting.Setting, typeof(Aperture), typeof(FamilyInstance), "GetHeight");
            string parameterName_Width  = Core.Revit.Query.Name(ActiveSetting.Setting, typeof(Aperture), typeof(FamilyInstance), "GetWidth");

            if (!string.IsNullOrWhiteSpace(parameterName_Height) && !string.IsNullOrWhiteSpace(parameterName_Width))
            {
                Parameter parameter_Height = familyInstance.LookupParameter(parameterName_Height);
                Parameter parameter_Width  = familyInstance.LookupParameter(parameterName_Width);
                if (parameter_Height != null && parameter_Width != null && parameter_Height.HasValue && parameter_Width.HasValue && parameter_Height.StorageType == StorageType.Double && parameter_Width.StorageType == StorageType.Double)
                {
                    double height = UnitUtils.ConvertFromInternalUnits(parameter_Height.AsDouble(), DisplayUnitType.DUT_METERS);
                    double width  = UnitUtils.ConvertFromInternalUnits(parameter_Width.AsDouble(), DisplayUnitType.DUT_METERS);

                    BoundingBox2D boundingBox2D = new BoundingBox2D(point2Ds);
                    double        factor_Height = height / boundingBox2D.Height;
                    double        factor_Width  = width / boundingBox2D.Width;

                    point2Ds = point2Ds.ConvertAll(x => new Point2D(x.X * factor_Width, x.Y * factor_Height));
                }
            }

            Rectangle2D rectangle2D = Geometry.Planar.Create.Rectangle2D(point2Ds);

            result = new Aperture(apertureConstruction, new Face3D(plane, rectangle2D));
            result.UpdateParameterSets(familyInstance, ActiveSetting.Setting.GetValue <Core.TypeMap>(Core.Revit.ActiveSetting.Name.ParameterMap));

            convertSettings?.Add(familyInstance.Id, result);

            return(result);
        }
コード例 #7
0
ファイル: ISAMGeometries.cs プロジェクト: HoareLea/SAM_Revit
        public static List <T> ToSAM <T>(this GeometryElement geometryElement, Transform transform = null) where T : ISAMGeometry
        {
            if (geometryElement == null)
            {
                return(null);
            }

            List <T> result = new List <T>();

            foreach (GeometryObject geometryObject in geometryElement)
            {
                if (geometryObject is GeometryInstance)
                {
                    GeometryInstance geometryInstance = (GeometryInstance)geometryObject;

                    Transform geometryTransform = geometryInstance.Transform;
                    if (transform != null)
                    {
                        geometryTransform = geometryTransform.Multiply(transform.Inverse);
                    }

                    GeometryElement geometryElement_Temp = geometryInstance.GetInstanceGeometry(geometryTransform);
                    if (geometryElement_Temp == null)
                    {
                        continue;
                    }

                    List <T> sAMGeometries = ToSAM <T>(geometryElement_Temp);
                    if (sAMGeometries != null && sAMGeometries.Count > 0)
                    {
                        result.AddRange(sAMGeometries);
                    }
                }
                else if (geometryObject is Solid)
                {
                    if (typeof(T).IsAssignableFrom(typeof(Shell)))
                    {
                        Shell shell = ((Solid)geometryObject).ToSAM();
                        if (shell != null)
                        {
                            result.Add((T)(ISAMGeometry)shell);
                        }
                    }
                    else if (typeof(T).IsAssignableFrom(typeof(Face3D)))
                    {
                        List <Face3D> face3Ds = ((Solid)geometryObject).ToSAM_Face3Ds();
                        if (face3Ds != null)
                        {
                            foreach (Face3D face3D in face3Ds)
                            {
                                result.Add((T)(ISAMGeometry)face3D);
                            }
                        }
                    }
                }
                else if (geometryObject is Line)
                {
                    if (typeof(T).IsAssignableFrom(typeof(ISegmentable3D)))
                    {
                        Segment3D segment3D = ((Line)geometryObject).ToSAM();
                        if (segment3D != null)
                        {
                            result.Add((T)(ISAMGeometry)segment3D);
                        }
                    }
                }
                else if (geometryObject is Curve)
                {
                    if (typeof(T).IsAssignableFrom(typeof(ICurve3D)))
                    {
                        ICurve3D curve3D = ((Curve)geometryObject).ToSAM();
                        if (curve3D != null)
                        {
                            result.Add((T)curve3D);
                        }
                    }
                }
            }
            return(result);
        }
コード例 #8
0
ファイル: Opening.cs プロジェクト: HoareLea/SAM_Revit
        public static IOpening ToSAM_Opening(this FamilyInstance familyInstance, ConvertSettings convertSettings)
        {
            if (familyInstance == null)
            {
                return(null);
            }

            IOpening result = convertSettings?.GetObject <IOpening>(familyInstance.Id);

            if (result != null)
            {
                return(result);
            }

            if (Core.Revit.Query.Simplified(familyInstance))
            {
                result = Core.Revit.Query.IJSAMObjects <IOpening>(familyInstance)?.FirstOrDefault();
                if (result != null)
                {
                    convertSettings?.Add(familyInstance.Id, result);
                    return(result);
                }
            }

            Point3D point3D_Location = Geometry.Revit.Query.LocationPoint3D(familyInstance);

            if (point3D_Location == null)
            {
                List <Solid> solids = Core.Revit.Query.Solids(familyInstance, new Options());
                solids?.RemoveAll(x => x.Volume == 0);
                if (solids == null || solids.Count == 0)
                {
                    return(null);
                }

                if (solids.Count > 1)
                {
                    solids.Sort((x, y) => y.Volume.CompareTo(x.Volume));
                }

                point3D_Location = solids[0].ComputeCentroid()?.ToSAM();
            }

            if (point3D_Location == null)
            {
                return(null);
            }

            OpeningType openingType = ToSAM_OpeningType(familyInstance.Symbol, convertSettings);

            if (openingType == null)
            {
                return(null);
            }

            BuiltInCategory builtInCategory_Host = BuiltInCategory.INVALID;

            HostObject hostObject = familyInstance.Host as HostObject;

            if (hostObject != null)
            {
                builtInCategory_Host = (BuiltInCategory)hostObject.Category.Id.IntegerValue;
            }

            Vector3D axisX  = null;
            Vector3D normal = null;
            Vector3D axisY  = null;

            if (builtInCategory_Host == BuiltInCategory.OST_Roofs)
            {
                axisX  = familyInstance.HandOrientation.ToSAM_Vector3D(false);
                axisY  = familyInstance.FacingOrientation.ToSAM_Vector3D(false);
                normal = Geometry.Spatial.Query.AxisY(axisY, axisX);
            }
            else
            {
                axisX  = familyInstance.HandOrientation.ToSAM_Vector3D(false);
                normal = familyInstance.FacingOrientation.ToSAM_Vector3D(false);
                axisY  = Geometry.Spatial.Query.AxisY(normal, axisX);
            }


            Geometry.Spatial.Plane plane = Geometry.Spatial.Create.Plane(point3D_Location, axisX, axisY);
            if (!plane.Normal.SameHalf(normal))
            {
                plane.FlipZ(false);
            }

            List <Face3D> face3Ds = Geometry.Revit.Convert.ToSAM_Geometries <Face3D>(familyInstance);

            if (face3Ds == null || face3Ds.Count == 0)
            {
                return(null);
            }

            List <Point2D> point2Ds = new List <Point2D>();

            foreach (Face3D face3D_Temp in face3Ds)
            {
                IClosedPlanar3D closedPlanar3D = face3D_Temp.GetExternalEdge3D();
                if (closedPlanar3D is ICurvable3D)
                {
                    List <ICurve3D> curve3Ds = ((ICurvable3D)closedPlanar3D).GetCurves();
                    foreach (ICurve3D curve3D in curve3Ds)
                    {
                        ICurve3D curve3D_Temp = plane.Project(curve3D);
                        point2Ds.Add(plane.Convert(curve3D_Temp.GetStart()));
                    }
                }
            }

            if (point2Ds == null || point2Ds.Count == 0)
            {
                return(null);
            }

            Rectangle2D rectangle2D = Geometry.Planar.Create.Rectangle2D(point2Ds);

            result = Analytical.Create.Opening(openingType, new Face3D(plane, rectangle2D));
            result.UpdateParameterSets(familyInstance);

            convertSettings?.Add(familyInstance.Id, result);

            return(result);
        }
コード例 #9
0
        private static List <Face3D> Profiles_FromLocation(this Wall wall, double tolerance_Angle = Core.Tolerance.Angle, double tolerance_Distance = Core.Tolerance.Distance)
        {
            BoundingBoxXYZ boundingBoxXYZ = wall.get_BoundingBox(null);

            if (boundingBoxXYZ == null)
            {
                return(null);
            }

            LocationCurve locationCurve = wall.Location as LocationCurve;

            if (locationCurve == null)
            {
                return(null);
            }

            ICurve3D curve3D_Location = Convert.ToSAM(locationCurve);

            IEnumerable <ICurve3D> curves = null;

            if (curve3D_Location is ISegmentable3D)
            {
                curves = ((ISegmentable3D)curve3D_Location).GetSegments().Cast <ICurve3D>();
            }
            else
            {
                curves = new List <ICurve3D>()
                {
                    curve3D_Location
                }
            };

            Vector3D direction = Vector3D.WorldZ;

#if Revit2017 || Revit2018 || Revit2019 || Revit2020
            double max = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Max.Z, DisplayUnitType.DUT_METERS);
#else
            double max = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Max.Z, UnitTypeId.Meters);
#endif

            Spatial.Plane plane_max = new Spatial.Plane(new Point3D(0, 0, max), direction);

#if Revit2017 || Revit2018 || Revit2019 || Revit2020
            double min = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Min.Z, DisplayUnitType.DUT_METERS);
#else
            double min = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Min.Z, UnitTypeId.Meters);
#endif
            Spatial.Plane plane_min = new Spatial.Plane(new Point3D(0, 0, min), direction);

            double height = max - min;

            Document document = wall.Document;

            //List<Face3D> face3Ds_Cutting = new List<Face3D>();

            //Dictionary<ElementId, List<Face3D>> dictionary = GeneratingElementIdDictionary(wall);
            //foreach (KeyValuePair<ElementId, List<Face3D>> keyValuePair in dictionary)
            //{
            //    if (keyValuePair.Value == null || keyValuePair.Value.Count == 0)
            //    {
            //        continue;
            //    }

            //    HostObject hostObject_Cutting = document.GetElement(keyValuePair.Key) as HostObject;
            //    if (hostObject_Cutting == null)
            //    {
            //        continue;
            //    }

            //    if (hostObject_Cutting is Floor || hostObject_Cutting is RoofBase)
            //    {
            //        List<Face3D> face3Ds_Temp = hostObject_Cutting.Profiles();
            //        if (face3Ds_Temp != null && face3Ds_Temp.Count != 0)
            //        {
            //            face3Ds_Cutting.AddRange(face3Ds_Temp);
            //        }
            //    }
            //}

            List <Face3D> result = new List <Face3D>();
            foreach (ICurve3D curve3D in curves)
            {
                if (curve3D == null)
                {
                    continue;
                }

                ICurve3D maxCurve = Spatial.Query.Project(plane_max, curve3D);
                ICurve3D minCurve = Spatial.Query.Project(plane_min, curve3D);

                Point3D point3D_1 = minCurve.GetEnd();
                Point3D point3D_2 = maxCurve.GetStart();
                Point3D point3D_3 = maxCurve.GetEnd();
                Point3D point3D_4 = minCurve.GetStart();
                if (point3D_1.Distance(point3D_3) < point3D_1.Distance(point3D_2))
                {
                    Point3D point_Temp = point3D_2;

                    maxCurve.Reverse();
                    point3D_2 = point3D_3;
                    point3D_3 = point_Temp;
                }

                List <Point3D> point3Ds = new List <Point3D>()
                {
                    point3D_4, point3D_3, point3D_2, point3D_1
                };
                if (wall.Flipped)
                {
                    point3Ds.Reverse();
                }

                Face3D face3D = new Face3D(new Polygon3D(point3Ds, tolerance_Distance));
                result.Add(face3D);

                //Spatial.Plane plane = Spatial.Create.Plane(point3Ds, tolerance_Distance);
                //if (plane == null)
                //{
                //    continue;
                //}

                //Vector3D vector3D = new Vector3D(point3D_4, point3D_3);

                //Segment2D segment2D = plane.Convert(new Segment3D(point3D_4, point3D_1));

                //List<Segment2D> segment2Ds_Intersection = new List<Segment2D>();
                //foreach (Face3D face3D_Cutting in face3Ds_Cutting)
                //{
                //    PlanarIntersectionResult planarIntersectionResult = Spatial.Create.PlanarIntersectionResult(plane, face3D_Cutting, tolerance_Angle, tolerance_Distance);
                //    if (planarIntersectionResult == null || !planarIntersectionResult.Intersecting)
                //    {
                //        continue;
                //    }

                //    List<Segment2D> segment2Ds_Intersection_Temp = planarIntersectionResult.GetGeometry2Ds<Segment2D>();
                //    if (segment2Ds_Intersection_Temp != null && segment2Ds_Intersection_Temp.Count > 0)
                //    {
                //        segment2Ds_Intersection.AddRange(segment2Ds_Intersection_Temp);
                //    }
                //}

                //List<Face2D> face2Ds = Profiles_From2D(segment2D, plane.Convert(vector3D), segment2Ds_Intersection, tolerance_Distance);
                //if (face2Ds != null && face2Ds.Count > 0)
                //{
                //    result.AddRange(face2Ds.ConvertAll(x => plane.Convert(x)));
                //}
            }

            if (result != null && result.Count > 0)
            {
                return(result);
            }

            return(result);
        }
コード例 #10
0
        public static List <Face3D> Profiles_Wall(this Wall wall)
        {
            if (wall == null)
            {
                return(null);
            }

            List <Face3D> result = Profiles_FromSketch(wall, !wall.Flipped);

            if (result != null && result.Count > 0)
            {
                return(result);
            }

            BoundingBoxXYZ boundingBoxXYZ = wall.get_BoundingBox(null);

            if (boundingBoxXYZ != null)
            {
                LocationCurve locationCurve = wall.Location as LocationCurve;
                if (locationCurve != null)
                {
                    ICurve3D curve3D_Location = Convert.ToSAM(locationCurve);

                    IEnumerable <ICurve3D> curves = null;
                    if (curve3D_Location is ISegmentable3D)
                    {
                        curves = ((ISegmentable3D)curve3D_Location).GetSegments().Cast <ICurve3D>();
                    }
                    else
                    {
                        curves = new List <ICurve3D>()
                        {
                            curve3D_Location
                        }
                    };

                    double        max       = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Max.Z, DisplayUnitType.DUT_METERS);
                    Spatial.Plane plane_max = new Spatial.Plane(new Point3D(0, 0, max), new Vector3D(0, 0, 1));

                    double        min       = UnitUtils.ConvertFromInternalUnits(boundingBoxXYZ.Min.Z, DisplayUnitType.DUT_METERS);
                    Spatial.Plane plane_min = new Spatial.Plane(new Point3D(0, 0, min), new Vector3D(0, 0, 1));

                    result = new List <Face3D>();
                    foreach (ICurve3D curve3D in curves)
                    {
                        if (curve3D == null)
                        {
                            continue;
                        }

                        ICurve3D maxCurve = plane_max.Project(curve3D);
                        ICurve3D minCurve = plane_min.Project(curve3D);

                        Point3D point3D_1 = minCurve.GetEnd();
                        Point3D point3D_2 = maxCurve.GetStart();
                        Point3D point3D_3 = maxCurve.GetEnd();
                        if (point3D_1.Distance(point3D_3) < point3D_1.Distance(point3D_2))
                        {
                            Point3D point_Temp = point3D_2;

                            maxCurve.Reverse();
                            point3D_2 = point3D_3;
                            point3D_3 = point_Temp;
                        }

                        List <Point3D> point3Ds = new List <Point3D>()
                        {
                            minCurve.GetStart(), point3D_3, point3D_2, point3D_1
                        };
                        if (wall.Flipped)
                        {
                            point3Ds.Reverse();
                        }

                        result.Add(new Face3D(new Polygon3D(point3Ds)));
                    }

                    if (result != null && result.Count > 0)
                    {
                        return(result);
                    }
                }
            }

            if (!ExporterIFCUtils.HasElevationProfile(wall))
            {
                return(null);
            }

            IList <CurveLoop> curveLoops = ExporterIFCUtils.GetElevationProfile(wall);

            if (curveLoops == null)
            {
                return(null);
            }

            result = new List <Face3D>();
            foreach (CurveLoop curveLoop in curveLoops)
            {
                Polygon3D polygon3D = curveLoop.ToSAM_Polygon3D();
                if (polygon3D != null)
                {
                    result.Add(new Face3D(polygon3D));
                }
            }

            return(result);
        }
コード例 #11
0
ファイル: Line.cs プロジェクト: HoareLea/SAM_Revit
 public static Line ToRevit_Line(this ICurve3D curve3D)
 {
     return(Line.CreateBound(curve3D.GetStart().ToRevit(), curve3D.GetEnd().ToRevit()));
 }