Beispiel #1
0
        protected override void Process(IFCAnyHandle ifcCurve)
        {
            base.Process(ifcCurve);

            IList <IFCAnyHandle> points = IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(ifcCurve, "Points");
            int numPoints = points.Count;

            if (numPoints < 2)
            {
                string msg = "IfcPolyLine had " + numPoints + ", expected at least 2, ignoring";
                Importer.TheLog.LogError(Id, msg, false);
                return;
            }

            IList <XYZ> pointXYZs = new List <XYZ>();

            foreach (IFCAnyHandle point in points)
            {
                XYZ pointXYZ = IFCPoint.ProcessScaledLengthIFCCartesianPoint(point);
                pointXYZs.Add(pointXYZ);
            }

            if (pointXYZs.Count != numPoints)
            {
                Importer.TheLog.LogError(Id, "Some of the IFC points cannot be converted to Revit points", true);
            }

            CurveLoop = IFCGeometryUtil.CreatePolyCurveLoop(pointXYZs, points, Id, false);
            Curve     = IFCGeometryUtil.CreateCurveFromPolyCurveLoop(CurveLoop, pointXYZs);
        }
Beispiel #2
0
        protected override void Process(IFCAnyHandle ifcCurve)
        {
            base.Process(ifcCurve);

            IList <IFCAnyHandle> points = IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(ifcCurve, "Points");
            int numPoints = points.Count;

            if (numPoints < 2)
            {
                string msg = "IfcPolyLine had " + numPoints + ", expected at least 2, ignoring";
                Importer.TheLog.LogError(Id, msg, false);
                return;
            }

            IList <XYZ> pointXYZs = new List <XYZ>();

            foreach (IFCAnyHandle point in points)
            {
                XYZ pointXYZ = IFCPoint.ProcessScaledLengthIFCCartesianPoint(point);
                pointXYZs.Add(pointXYZ);
            }
            if (pointXYZs.Count != numPoints)
            {
                Importer.TheLog.LogError(Id, "Some of the IFC points cannot be converted to Revit points", true);
            }

            CurveLoop = IFCGeometryUtil.CreatePolyCurveLoop(pointXYZs, points, Id, false);
            if (pointXYZs.Count == 2)
            {
                Curve = Line.CreateBound(pointXYZs[0], pointXYZs[1]);
            }
            else
            {
                // if we go here we are sure that the number of point must be at least 3
                XYZ firstPoint   = pointXYZs[0];
                XYZ secondPoint  = pointXYZs[1];
                XYZ vectorToTest = (secondPoint - firstPoint).Normalize();

                bool allAreCollinear = true;
                for (int ii = 2; ii < numPoints; ii++)
                {
                    XYZ vectorTmp = (pointXYZs[ii] - firstPoint).Normalize();
                    if (!vectorTmp.IsAlmostEqualTo(vectorToTest))
                    {
                        allAreCollinear = false;
                        break;
                    }
                }
                if (allAreCollinear)
                {
                    Curve = Line.CreateBound(firstPoint, pointXYZs[numPoints - 1]);
                }
            }
        }
Beispiel #3
0
        override protected CurveLoop GenerateLoop()
        {
            IList <XYZ> polygon = Polygon;

            if (polygon == null)
            {
                throw new InvalidOperationException("#" + Id + ": missing polygon, ignoring.");
            }

            int numVertices = Polygon.Count;

            if (numVertices < 3)
            {
                throw new InvalidOperationException("#" + Id + ": Polygon attribute has only " + numVertices + " vertices, 3 expected.");
            }

            return(IFCGeometryUtil.CreatePolyCurveLoop(polygon, null, Id, true));
        }
Beispiel #4
0
        protected override void Process(IFCAnyHandle ifcCurve)
        {
            base.Process(ifcCurve);

            IFCAnyHandle points = IFCAnyHandleUtil.GetInstanceAttribute(ifcCurve, "Points");

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(points))
            {
                Importer.TheLog.LogMissingRequiredAttributeError(ifcCurve, "Points", true);
                return;
            }

            IFCCartesianPointList pointList = IFCCartesianPointList.ProcessIFCCartesianPointList(points);
            IList <XYZ>           pointXYZs = pointList.CoordList;

            int numPoints = pointXYZs.Count;

            SetCurveLoop(IFCGeometryUtil.CreatePolyCurveLoop(pointXYZs, null, Id, false), pointXYZs);
        }
Beispiel #5
0
        override protected CurveLoop GenerateLoop()
        {
            IList <XYZ> polygon = Polygon;

            if (polygon == null)
            {
                // This used to throw an error.  However, we found files that threw this error
                // thousands of times, causing incredibly slow links.  Instead, null out the
                // data and log an error.
                Importer.TheLog.LogError(Id, "missing polygon, ignoring.", false);
            }

            int numVertices = Polygon.Count;

            if (numVertices < 3)
            {
                throw new InvalidOperationException("#" + Id + ": Polygon attribute has only " + numVertices + " vertices, 3 expected.");
            }

            return(IFCGeometryUtil.CreatePolyCurveLoop(polygon, null, Id, true));
        }
Beispiel #6
0
        private void ProcessIFCPolyline(IFCAnyHandle ifcCurve)
        {
            IList <IFCAnyHandle> points = IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(ifcCurve, "Points");
            int numPoints = points.Count;

            if (numPoints < 2)
            {
                string msg = "IfcPolyLine had " + numPoints + ", expected at least 2, ignoring";
                IFCImportFile.TheLog.LogError(Id, msg, false);
                return;
            }

            IList <XYZ> pointXYZs = new List <XYZ>();

            foreach (IFCAnyHandle point in points)
            {
                XYZ pointXYZ = IFCPoint.ProcessScaledLengthIFCCartesianPoint(point);
                pointXYZs.Add(pointXYZ);
            }

            CurveLoop = IFCGeometryUtil.CreatePolyCurveLoop(pointXYZs, points, Id, false);
        }
Beispiel #7
0
        protected override void Process(IFCAnyHandle ifcCurve)
        {
            base.Process(ifcCurve);

            IFCAnyHandle points = IFCAnyHandleUtil.GetInstanceAttribute(ifcCurve, "Points");

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(points))
            {
                Importer.TheLog.LogMissingRequiredAttributeError(ifcCurve, "Points", true);
                return;
            }

            IList <IFCData> segments = null;

            try
            {
                // The Segments attribute is new to IFC4 Add1, and we don't know that we may have a
                // vanilla IFC4 file.  If we can't find the attribute, we will assume the points represent
                // the vertices of a polyline.
                segments = IFCAnyHandleUtil.GetAggregateAttribute <List <IFCData> >(ifcCurve, "Segments");
            }
            catch (Exception ex)
            {
                if (IFCImportFile.HasUndefinedAttribute(ex))
                {
                    IFCImportFile.TheFile.DowngradeIFC4SchemaTo(IFCSchemaVersion.IFC4);
                }
                else
                {
                    throw ex;
                }
            }

            IFCCartesianPointList pointList     = IFCCartesianPointList.ProcessIFCCartesianPointList(points);
            IList <XYZ>           pointListXYZs = pointList.CoordList;
            int numPoints = pointListXYZs.Count;

            CurveLoop   curveLoop = null;
            IList <XYZ> pointXYZs = null;

            if (segments == null)
            {
                // Simple case: no segment information, just treat the curve as a polyline.
                pointXYZs = pointListXYZs;
                curveLoop = IFCGeometryUtil.CreatePolyCurveLoop(pointXYZs, null, Id, false);
            }
            else
            {
                curveLoop = new CurveLoop();

                // Assure that we don't add the same point twice for a polyline segment.  This could
                // happen by error, or, e.g., there are two IfcLineIndex segments in a row (although
                // this could also be considered an error condition.)
                int lastIndex = -1;

                // The list of all of the points, in the order that they are added.  This can be
                // used as a backup representation.
                pointXYZs = new List <XYZ>();

                IList <XYZ> currentLineSegmentPoints = new List <XYZ>();
                foreach (IFCData segment in segments)
                {
                    string indexType = ValidateSegment(segment);
                    if (indexType == null)
                    {
                        Importer.TheLog.LogError(Id, "Unknown segment type in IfcIndexedPolyCurve.", false);
                        continue;
                    }

                    IFCAggregate segmentInfo = segment.AsAggregate();

                    if (indexType.Equals("IfcLineIndex", StringComparison.OrdinalIgnoreCase))
                    {
                        foreach (IFCData segmentInfoIndex in segmentInfo)
                        {
                            int?currentIndex = GetValidIndex(segmentInfoIndex, numPoints);
                            if (currentIndex == null)
                            {
                                continue;
                            }

                            int validCurrentIndex = currentIndex.Value;
                            if (lastIndex != validCurrentIndex)
                            {
                                pointXYZs.Add(pointListXYZs[validCurrentIndex]);
                                currentLineSegmentPoints.Add(pointListXYZs[validCurrentIndex]);
                                lastIndex = validCurrentIndex;
                            }
                        }
                    }
                    else if (indexType.Equals("IfcArcIndex", StringComparison.OrdinalIgnoreCase))
                    {
                        // Create any line segments that haven't been already created.
                        CreateLineSegments(curveLoop, currentLineSegmentPoints);

                        if (segmentInfo.Count != 3)
                        {
                            Importer.TheLog.LogError(Id, "Invalid IfcArcIndex in IfcIndexedPolyCurve.", false);
                            continue;
                        }

                        int?startIndex = GetValidIndex(segmentInfo[0], numPoints);
                        int?pointIndex = GetValidIndex(segmentInfo[1], numPoints);
                        int?endIndex   = GetValidIndex(segmentInfo[2], numPoints);

                        if (startIndex == null || pointIndex == null || endIndex == null)
                        {
                            continue;
                        }

                        Arc arcSegment = null;
                        XYZ startPoint = pointListXYZs[startIndex.Value];
                        XYZ pointOnArc = pointListXYZs[pointIndex.Value];
                        XYZ endPoint   = pointListXYZs[endIndex.Value];
                        try
                        {
                            arcSegment = Arc.Create(startPoint, pointOnArc, endPoint);
                            if (arcSegment != null)
                            {
                                curveLoop.Append(arcSegment);
                            }
                        }
                        catch
                        {
                            // We won't do anything here; it may be that the arc is very small, and can
                            // be repaired as a gap in the curve loop.  If it can't, this will fail later.
                            // We will monitor usage to see if anything more needs to be done here.
                        }

                        if (lastIndex != startIndex.Value)
                        {
                            pointXYZs.Add(startPoint);
                        }
                        pointXYZs.Add(pointOnArc);
                        pointXYZs.Add(endPoint);
                        lastIndex = endIndex.Value;
                    }
                    else
                    {
                        Importer.TheLog.LogError(Id, "Unsupported segment type in IfcIndexedPolyCurve.", false);
                        continue;
                    }
                }

                // Create any line segments that haven't been already created.
                CreateLineSegments(curveLoop, currentLineSegmentPoints);
            }

            SetCurveLoop(curveLoop, pointXYZs);
        }