Example #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);
        }
        // TODO: this function should be moved to IFCBoundingBox.cs now that they are fully supported.
        static private BoundingBoxXYZ ProcessBoundingBox(IFCAnyHandle boundingBoxHnd)
        {
            IFCAnyHandle lowerLeftHnd = IFCAnyHandleUtil.GetInstanceAttribute(boundingBoxHnd, "Corner");
            XYZ          minXYZ       = IFCPoint.ProcessScaledLengthIFCCartesianPoint(lowerLeftHnd);

            bool   found = false;
            double xDim  = IFCImportHandleUtil.GetRequiredScaledLengthAttribute(boundingBoxHnd, "XDim", out found);

            if (!found)
            {
                return(null);
            }

            double yDim = IFCImportHandleUtil.GetRequiredScaledLengthAttribute(boundingBoxHnd, "YDim", out found);

            if (!found)
            {
                return(null);
            }

            double zDim = IFCImportHandleUtil.GetRequiredScaledLengthAttribute(boundingBoxHnd, "ZDim", out found);

            if (!found)
            {
                return(null);
            }

            XYZ            maxXYZ      = new XYZ(minXYZ.X + xDim, minXYZ.Y + yDim, minXYZ.Z + zDim);
            BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();

            boundingBox.set_Bounds(0, minXYZ);
            boundingBox.set_Bounds(1, maxXYZ);
            return(boundingBox);
        }
Example #3
0
        protected override void Process(IFCAnyHandle ifcCurve)
        {
            base.Process(ifcCurve);
            IFCAnyHandle pnt = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcCurve, "Pnt", false);

            if (pnt == null)
            {
                return;
            }

            IFCAnyHandle dir = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcCurve, "Dir", false);

            if (dir == null)
            {
                return;
            }

            XYZ pntXYZ = IFCPoint.ProcessScaledLengthIFCCartesianPoint(pnt);
            XYZ dirXYZ = IFCUnitUtil.ScaleLength(IFCPoint.ProcessIFCVector(dir));

            ParametericScaling = dirXYZ.GetLength();
            if (MathUtil.IsAlmostZero(ParametericScaling))
            {
                Importer.TheLog.LogWarning(ifcCurve.StepId, "Line has zero length, ignoring.", false);
                return;
            }

            Curve = Line.CreateUnbound(pntXYZ, dirXYZ / ParametericScaling);
        }
Example #4
0
        private double?GetTrimParameter(IFCData trim, IFCCurve basisCurve, IFCTrimmingPreference trimPreference, bool secondAttempt)
        {
            bool preferParam = !(trimPreference == IFCTrimmingPreference.Cartesian);

            if (secondAttempt)
            {
                preferParam = !preferParam;
            }
            double vertexEps = MathUtil.VertexEps;

            IFCAggregate trimAggregate = trim.AsAggregate();

            foreach (IFCData trimParam in trimAggregate)
            {
                if (!preferParam && (trimParam.PrimitiveType == IFCDataPrimitiveType.Instance))
                {
                    IFCAnyHandle trimParamInstance = trimParam.AsInstance();
                    XYZ          trimParamPt       = IFCPoint.ProcessScaledLengthIFCCartesianPoint(trimParamInstance);
                    if (trimParamPt == null)
                    {
                        IFCImportFile.TheLog.LogWarning(basisCurve.Id, "Invalid trim point for basis curve.", false);
                        continue;
                    }

                    try
                    {
                        IntersectionResult result = basisCurve.Curve.Project(trimParamPt);
                        if (result.Distance < vertexEps)
                        {
                            return(result.Parameter);
                        }

                        IFCImportFile.TheLog.LogWarning(basisCurve.Id, "Cartesian value for trim point not on the basis curve.", false);
                    }
                    catch
                    {
                        IFCImportFile.TheLog.LogWarning(basisCurve.Id, "Cartesian value for trim point not on the basis curve.", false);
                    }
                }
                else if (preferParam && (trimParam.PrimitiveType == IFCDataPrimitiveType.Double))
                {
                    double trimParamDouble = trimParam.AsDouble();
                    if (basisCurve.Curve.IsCyclic)
                    {
                        trimParamDouble = IFCUnitUtil.ScaleAngle(trimParamDouble);
                    }
                    return(trimParamDouble);
                }
            }

            // Try again with opposite preference.
            if (!secondAttempt)
            {
                return(GetTrimParameter(trim, basisCurve, trimPreference, true));
            }

            return(null);
        }
Example #5
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]);
                }
            }
        }
Example #6
0
        static Transform ProcessPlacementBase(IFCAnyHandle placement)
        {
            IFCAnyHandle location = IFCAnyHandleUtil.GetInstanceAttribute(placement, "Location");
            XYZ          origin   = IFCPoint.ProcessScaledLengthIFCCartesianPoint(location);

            if (origin == null)
            {
                Importer.TheLog.LogError(placement.StepId, "Missing or invalid location attribute.", false);
                origin = XYZ.Zero;
            }
            return(Transform.CreateTranslation(origin));
        }
Example #7
0
        static private BoundingBoxXYZ ProcessBoundingBox(IFCAnyHandle boundingBoxHnd)
        {
            IFCAnyHandle lowerLeftHnd = IFCAnyHandleUtil.GetInstanceAttribute(boundingBoxHnd, "Corner");
            XYZ          minXYZ       = IFCPoint.ProcessScaledLengthIFCCartesianPoint(lowerLeftHnd);

            double xDim = IFCAnyHandleUtil.GetDoubleAttribute(boundingBoxHnd, "XDim").Value;
            double yDim = IFCAnyHandleUtil.GetDoubleAttribute(boundingBoxHnd, "YDim").Value;
            double zDim = IFCAnyHandleUtil.GetDoubleAttribute(boundingBoxHnd, "ZDim").Value;

            XYZ            maxXYZ      = new XYZ(minXYZ.X + xDim, minXYZ.Y + yDim, minXYZ.Z + zDim);
            BoundingBoxXYZ boundingBox = new BoundingBoxXYZ();

            boundingBox.set_Bounds(0, minXYZ);
            boundingBox.set_Bounds(1, maxXYZ);
            return(boundingBox);
        }
Example #8
0
        static Transform ProcessPlacementBase(IFCAnyHandle placement)
        {
            IFCAnyHandle location = IFCAnyHandleUtil.GetInstanceAttribute(placement, "Location");
            XYZ          origin   = IFCPoint.ProcessScaledLengthIFCCartesianPoint(location);

            if (origin == null)
            {
                Importer.TheLog.LogError(placement.StepId, "Missing or invalid location attribute.", false);
                origin = XYZ.Zero;
            }
            else if (FixFarawayLocationOrigin && !XYZ.IsWithinLengthLimits(origin))
            {
                Importer.TheLog.LogError(placement.StepId, "The local placement has an origin that is outside of Revit's creation limits.  Moving to the internal origin.", false);
                origin = XYZ.Zero;
            }
            return(Transform.CreateTranslation(origin));
        }
        protected override void Process(IFCAnyHandle ifcCurve)
        {
            base.Process(ifcCurve);

            bool foundDegree = false;

            Degree = IFCImportHandleUtil.GetRequiredIntegerAttribute(ifcCurve, "Degree", out foundDegree);
            if (!foundDegree)
            {
                Importer.TheLog.LogError(ifcCurve.StepId, "Cannot find the degree of this curve", true);
            }

            IList <IFCAnyHandle> controlPoints = IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(ifcCurve, "ControlPointsList");

            if (controlPoints == null || controlPoints.Count == 0)
            {
                Importer.TheLog.LogError(ifcCurve.StepId, "This curve has invalid number of control points", true);
            }

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

            foreach (IFCAnyHandle point in controlPoints)
            {
                XYZ pointXYZ = IFCPoint.ProcessScaledLengthIFCCartesianPoint(point);
                controlPointLists.Add(pointXYZ);
            }
            ControlPointsList = controlPointLists;

            bool       foundClosedCurve = false;
            IFCLogical closedCurve      = IFCImportHandleUtil.GetOptionalLogicalAttribute(ifcCurve, "ClosedCurve", out foundClosedCurve);

            if (!foundClosedCurve)
            {
                Importer.TheLog.LogWarning(ifcCurve.StepId, "Cannot find the ClosedCurve property of this curve, ignoring", false);
                ClosedCurve = null;
            }
            else
            {
                ClosedCurve = (closedCurve == IFCLogical.True);
            }
        }
Example #10
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);
        }
        override protected void Process(IFCAnyHandle item)
        {
            base.Process(item);

            IFCAnyHandle localOrigin = IFCImportHandleUtil.GetRequiredInstanceAttribute(item, "LocalOrigin", false);
            XYZ          origin      = null;

            if (localOrigin != null)
            {
                origin = IFCPoint.ProcessScaledLengthIFCCartesianPoint(localOrigin);
            }
            else
            {
                origin = XYZ.Zero;
            }

            IFCAnyHandle axis1 = IFCImportHandleUtil.GetOptionalInstanceAttribute(item, "Axis1");
            XYZ          xAxis = null;

            if (axis1 != null)
            {
                xAxis = IFCPoint.ProcessNormalizedIFCDirection(axis1);
            }

            IFCAnyHandle axis2 = IFCImportHandleUtil.GetOptionalInstanceAttribute(item, "Axis2");
            XYZ          yAxis = null;

            if (axis2 != null)
            {
                yAxis = IFCPoint.ProcessNormalizedIFCDirection(axis2);
            }

            Scale = IFCImportHandleUtil.GetOptionalRealAttribute(item, "Scale", 1.0);

            XYZ zAxis = null;

            // Assume that the dimensionality of the IfcCartesianTransformationOperator is 2, unless determined otherwise below.
            int dim = 2;

            if (IFCAnyHandleUtil.IsSubTypeOf(item, IFCEntityType.IfcCartesianTransformationOperator2DnonUniform))
            {
                ScaleY = IFCImportHandleUtil.GetOptionalRealAttribute(item, "Scale2", Scale);
            }
            else if (IFCAnyHandleUtil.IsSubTypeOf(item, IFCEntityType.IfcCartesianTransformationOperator3D))
            {
                dim = 3;

                IFCAnyHandle axis3 = IFCImportHandleUtil.GetOptionalInstanceAttribute(item, "Axis3");
                if (axis3 != null)
                {
                    zAxis = IFCPoint.ProcessNormalizedIFCDirection(axis3);
                }
                if (IFCAnyHandleUtil.IsSubTypeOf(item, IFCEntityType.IfcCartesianTransformationOperator3DnonUniform))
                {
                    ScaleY = IFCImportHandleUtil.GetOptionalRealAttribute(item, "Scale2", Scale);
                    ScaleZ = IFCImportHandleUtil.GetOptionalRealAttribute(item, "Scale3", Scale);
                }
            }

            // Set the axes based on what is specified.
            Transform = CreateTransformUsingIfcBaseAxisCalculation(xAxis, yAxis, zAxis, origin, dim, Id);
        }
Example #12
0
        static Transform ProcessPlacementBase(IFCAnyHandle placement)
        {
            IFCAnyHandle location = IFCAnyHandleUtil.GetInstanceAttribute(placement, "Location");

            return(Transform.CreateTranslation(IFCPoint.ProcessScaledLengthIFCCartesianPoint(location)));
        }
Example #13
0
        override protected void Process(IFCAnyHandle item)
        {
            base.Process(item);

            IFCAnyHandle localOrigin = IFCImportHandleUtil.GetRequiredInstanceAttribute(item, "LocalOrigin", false);
            XYZ          origin      = null;

            if (localOrigin != null)
            {
                origin = IFCPoint.ProcessScaledLengthIFCCartesianPoint(localOrigin);
            }
            else
            {
                origin = XYZ.Zero;
            }

            IFCAnyHandle axis1 = IFCImportHandleUtil.GetOptionalInstanceAttribute(item, "Axis1");
            XYZ          xAxis = null;

            if (axis1 != null)
            {
                xAxis = IFCPoint.ProcessNormalizedIFCDirection(axis1);
            }

            IFCAnyHandle axis2 = IFCImportHandleUtil.GetOptionalInstanceAttribute(item, "Axis2");
            XYZ          yAxis = null;

            if (axis2 != null)
            {
                yAxis = IFCPoint.ProcessNormalizedIFCDirection(axis2);
            }

            Scale = IFCImportHandleUtil.GetOptionalRealAttribute(item, "Scale", 1.0);

            XYZ zAxis = null;

            if (IFCAnyHandleUtil.IsSubTypeOf(item, IFCEntityType.IfcCartesianTransformationOperator2DnonUniform))
            {
                ScaleY = IFCImportHandleUtil.GetOptionalRealAttribute(item, "Scale2", Scale);
            }
            else if (IFCAnyHandleUtil.IsSubTypeOf(item, IFCEntityType.IfcCartesianTransformationOperator3D))
            {
                IFCAnyHandle axis3 = IFCImportHandleUtil.GetOptionalInstanceAttribute(item, "Axis3");
                if (axis3 != null)
                {
                    zAxis = IFCPoint.ProcessNormalizedIFCDirection(axis3);
                }
                if (IFCAnyHandleUtil.IsSubTypeOf(item, IFCEntityType.IfcCartesianTransformationOperator3DnonUniform))
                {
                    ScaleY = IFCImportHandleUtil.GetOptionalRealAttribute(item, "Scale2", Scale);
                    ScaleZ = IFCImportHandleUtil.GetOptionalRealAttribute(item, "Scale3", Scale);
                }
            }

            // Set the axes based on what is specified.
            // If all three axes are set, ensure they are truly orthogonal.
            // If two axes are set, ensure they are orthogonal and set the 3rd axis to be the cross product.
            // If one axis is set, arbitrarily set the next axis to be the basis vector which
            // If no axes are set, use identity transform.
            if (xAxis == null)
            {
                if (yAxis == null)
                {
                    if (zAxis == null)
                    {
                        xAxis = XYZ.BasisX;
                        yAxis = XYZ.BasisY;
                        zAxis = XYZ.BasisZ;
                    }
                }
                else if (zAxis == null)
                {
                    // Special case - Y axis is in XY plane.
                    if (MathUtil.IsAlmostZero(yAxis[2]))
                    {
                        xAxis = new XYZ(yAxis[1], -yAxis[0], 0.0);
                        zAxis = XYZ.BasisZ;
                    }
                    else
                    {
                        throw new InvalidOperationException("#" + item.StepId + ": IfcCartesianTransformOperator has only y axis defined, ignoring.");
                    }
                }
                else
                {
                    xAxis = yAxis.CrossProduct(zAxis);
                }
            }
            else if (yAxis == null)
            {
                if (zAxis == null)
                {
                    // Special case - X axis is in XY plane.
                    if (MathUtil.IsAlmostZero(xAxis[2]))
                    {
                        yAxis = new XYZ(xAxis[1], -xAxis[0], 0.0);
                        zAxis = XYZ.BasisZ;
                    }
                    else
                    {
                        throw new InvalidOperationException("#" + item.StepId + ": IfcCartesianTransformOperator has only x axis defined, ignoring.");
                    }
                }
                else
                {
                    yAxis = zAxis.CrossProduct(xAxis);
                }
            }
            else if (zAxis == null)
            {
                zAxis = xAxis.CrossProduct(yAxis);
            }

            // Make sure that the axes are really orthogonal.
            if (!MathUtil.IsAlmostZero(xAxis.DotProduct(zAxis)))
            {
                zAxis = xAxis.CrossProduct(yAxis);
            }
            if (!MathUtil.IsAlmostZero(xAxis.DotProduct(yAxis)))
            {
                yAxis = zAxis.CrossProduct(xAxis);
            }

            Transform = Transform.CreateTranslation(origin);
            Transform.set_Basis(0, xAxis);
            Transform.set_Basis(1, yAxis);
            Transform.set_Basis(2, zAxis);
        }