Ejemplo n.º 1
0
        /// <summary>
        /// Processes IfcProject attributes.
        /// </summary>
        /// <param name="ifcProjectHandle">The IfcProject handle.</param>
        protected override void Process(IFCAnyHandle ifcProjectHandle)
        {
            IFCAnyHandle unitsInContext = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcProjectHandle, "UnitsInContext", false);

            if (!IFCAnyHandleUtil.IsNullOrHasNoValue(unitsInContext))
            {
                IList <IFCAnyHandle> units = IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(unitsInContext, "Units");

                if (units != null)
                {
                    m_UnitsInContext = new HashSet <IFCUnit>();

                    foreach (IFCAnyHandle unit in units)
                    {
                        IFCUnit ifcUnit = IFCImportFile.TheFile.IFCUnits.ProcessIFCProjectUnit(unit);
                        if (!IFCUnit.IsNullOrInvalid(ifcUnit))
                        {
                            m_UnitsInContext.Add(ifcUnit);
                        }
                    }
                }
                else
                {
                    Importer.TheLog.LogMissingRequiredAttributeError(unitsInContext, "Units", false);
                }
            }

            // We need to process the units before we process the rest of the file, since we will scale values as we go along.
            base.Process(ifcProjectHandle);

            // process true north - take the first valid representation context that has a true north value.
            HashSet <IFCAnyHandle> repContexts = IFCAnyHandleUtil.GetAggregateInstanceAttribute <HashSet <IFCAnyHandle> >(ifcProjectHandle, "RepresentationContexts");

            if (repContexts != null)
            {
                foreach (IFCAnyHandle geomRepContextHandle in repContexts)
                {
                    if (!IFCAnyHandleUtil.IsNullOrHasNoValue(geomRepContextHandle) &&
                        IFCAnyHandleUtil.IsSubTypeOf(geomRepContextHandle, IFCEntityType.IfcGeometricRepresentationContext))
                    {
                        IFCAnyHandle trueNorthHandle = IFCAnyHandleUtil.GetInstanceAttribute(geomRepContextHandle, "TrueNorth");
                        if (!IFCAnyHandleUtil.IsNullOrHasNoValue(trueNorthHandle))
                        {
                            List <double> trueNorthDir = IFCAnyHandleUtil.GetAggregateDoubleAttribute <List <double> >(trueNorthHandle, "DirectionRatios");
                            if (trueNorthDir != null && trueNorthDir.Count >= 2)
                            {
                                m_TrueNorthDirection = trueNorthDir;
                                break;
                            }
                        }
                    }
                }
            }

            // Special read of IfcPresentationLayerAssignment if the INVERSE flag isn't properly set in the EXPRESS file.
            if (IFCImportFile.TheFile.SchemaVersion >= IFCSchemaVersion.IFC2x2)
            {
                IFCPresentationLayerAssignment.ProcessAllLayerAssignments();
            }
        }
Ejemplo n.º 2
0
        protected override void Process(IFCAnyHandle ifcCurve)
        {
            base.Process(ifcCurve);
            KnotMultiplicities = IFCAnyHandleUtil.GetAggregateIntAttribute <List <int> >(ifcCurve, "KnotMultiplicities");
            Knots = IFCAnyHandleUtil.GetAggregateDoubleAttribute <List <double> >(ifcCurve, "Knots");

            if (KnotMultiplicities == null || Knots == null)
            {
                Importer.TheLog.LogError(ifcCurve.StepId, "Cannot find the KnotMultiplicities or Knots attribute of this IfcBSplineCurveWithKnots", true);
            }

            if (KnotMultiplicities.Count != Knots.Count)
            {
                Importer.TheLog.LogError(ifcCurve.StepId, "The number of knots and knot multiplicities are not the same", true);
            }

            IList <double> revitKnots = IFCGeometryUtil.ConvertIFCKnotsToRevitKnots(KnotMultiplicities, Knots);

            Curve nurbsSpline = NurbSpline.CreateCurve(Degree, revitKnots, ControlPointsList);

            SetCurve(nurbsSpline);

            if (nurbsSpline == null)
            {
                Importer.TheLog.LogWarning(ifcCurve.StepId, "Cannot get the curve representation of this IfcCurve", false);
            }
        }
        protected override void Process(IFCAnyHandle ifcMaterialLayerWithOffsets)
        {
            base.Process(ifcMaterialLayerWithOffsets);

            OffsetValues    = IFCAnyHandleUtil.GetAggregateDoubleAttribute <List <double> >(ifcMaterialLayerWithOffsets, "OffsetValues");
            OffsetDirection = (IFCLayerSetDirection)Enum.Parse(typeof(IFCLayerSetDirection), IFCAnyHandleUtil.GetEnumerationAttribute(ifcMaterialLayerWithOffsets, "OffsetDirection"));
        }
Ejemplo n.º 4
0
        private static XYZ ProcessIFCDirectionBase(IFCAnyHandle direction, bool normalize, bool reportAndThrowOnError)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(direction))
            {
                Importer.TheLog.LogNullError(IFCEntityType.IfcDirection);
                return(null);
            }

            if (!IFCAnyHandleUtil.IsValidSubTypeOf(direction, IFCEntityType.IfcDirection))
            {
                Importer.TheLog.LogUnexpectedTypeError(direction, IFCEntityType.IfcDirection, false);
                return(null);
            }

            XYZ xyz    = null;
            int stepId = direction.StepId;

            if (normalize)
            {
                if (IFCImportFile.TheFile.NormalizedXYZMap.TryGetValue(stepId, out xyz))
                {
                    return(xyz);
                }
            }
            else
            {
                if (IFCImportFile.TheFile.XYZMap.TryGetValue(stepId, out xyz))
                {
                    return(xyz);
                }
            }

            List <double> directionRatios = IFCAnyHandleUtil.GetAggregateDoubleAttribute <List <double> >(direction, "DirectionRatios");

            xyz = ListToXYZ(directionRatios);
            XYZ normalizedXYZ = null;

            if (xyz != null)
            {
                if (normalize)
                {
                    normalizedXYZ = xyz.Normalize();
                    if (normalizedXYZ.IsZeroLength())
                    {
                        if (reportAndThrowOnError)
                        {
                            Importer.TheLog.LogError(stepId, "Local transform contains 0 length vectors.", true);
                        }
                        else
                        {
                            return(XYZ.Zero);
                        }
                    }
                    IFCImportFile.TheFile.NormalizedXYZMap[direction.StepId] = normalizedXYZ;
                }
                AddToCaches(stepId, IFCEntityType.IfcDirection, xyz);
            }
            return(normalize ? normalizedXYZ : xyz);
        }
 protected override void Process(IFCAnyHandle ifcSurface)
 {
     base.Process(ifcSurface);
     UMultiplicities = IFCAnyHandleUtil.GetAggregateIntAttribute <List <int> >(ifcSurface, "UMultiplicities");
     VMultiplicities = IFCAnyHandleUtil.GetAggregateIntAttribute <List <int> >(ifcSurface, "VMultiplicities");
     UKnots          = IFCAnyHandleUtil.GetAggregateDoubleAttribute <List <double> >(ifcSurface, "UKnots");
     VKnots          = IFCAnyHandleUtil.GetAggregateDoubleAttribute <List <double> >(ifcSurface, "VKnots");
 }
Ejemplo n.º 6
0
        private static XYZ ProcessIFCDirectionBase(IFCAnyHandle direction, bool normalize)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(direction))
            {
                IFCImportFile.TheLog.LogNullError(IFCEntityType.IfcDirection);
                return(null);
            }

            if (!IFCAnyHandleUtil.IsSubTypeOf(direction, IFCEntityType.IfcDirection))
            {
                IFCImportFile.TheLog.LogUnexpectedTypeError(direction, IFCEntityType.IfcDirection, false);
                return(null);
            }

            XYZ xyz    = null;
            int stepId = direction.StepId;

            if (normalize)
            {
                if (IFCImportFile.TheFile.NormalizedXYZMap.TryGetValue(stepId, out xyz))
                {
                    return(xyz);
                }
            }
            else
            {
                if (IFCImportFile.TheFile.XYZMap.TryGetValue(stepId, out xyz))
                {
                    return(xyz);
                }
            }

            List <double> directionRatios = IFCAnyHandleUtil.GetAggregateDoubleAttribute <List <double> >(direction, "DirectionRatios");

            xyz = ListToXYZ(directionRatios);
            XYZ normalizedXYZ = null;

            if (xyz != null)
            {
                AddToCaches(stepId, IFCEntityType.IfcDirection, xyz);
                if (normalize)
                {
                    normalizedXYZ = xyz.Normalize();
                    IFCImportFile.TheFile.NormalizedXYZMap[direction.StepId] = normalizedXYZ;
                }
            }
            return(normalize ? normalizedXYZ : xyz);
        }
Ejemplo n.º 7
0
        protected override void Process(IFCAnyHandle ifcVirtualGridIntersection)
        {
            base.Process(ifcVirtualGridIntersection);

            IList <IFCAnyHandle> intersectingAxes = IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(ifcVirtualGridIntersection, "IntersectingAxes");

            if (intersectingAxes == null ||
                intersectingAxes.Count != 2 ||
                IFCAnyHandleUtil.IsNullOrHasNoValue(intersectingAxes[0]) ||
                IFCAnyHandleUtil.IsNullOrHasNoValue(intersectingAxes[1]))
            {
                Importer.TheLog.LogError(ifcVirtualGridIntersection.StepId, "Missing or invalid intersecting axes.", false);
                return;
            }

            IFCGridAxis firstAxis = IFCGridAxis.ProcessIFCGridAxis(intersectingAxes[0]);

            if (firstAxis == null)
            {
                return;
            }

            IFCGridAxis secondAxis = IFCGridAxis.ProcessIFCGridAxis(intersectingAxes[1]);

            if (secondAxis == null)
            {
                return;
            }

            OffsetDistances = IFCAnyHandleUtil.GetAggregateDoubleAttribute <List <double> >(ifcVirtualGridIntersection, "OffsetDistances");
            double[] offsetDistances     = new double[3];
            int      offsetDistanceCount = (OffsetDistances != null) ? OffsetDistances.Count : 0;

            for (int ii = 0; ii < 3; ii++)
            {
                offsetDistances[ii] = (offsetDistanceCount > ii) ? OffsetDistances[ii] : 0;
            }

            Curve firstCurve = firstAxis.GetAxisCurveForGridPlacement();

            if (firstCurve == null)
            {
                return;
            }

            Curve secondCurve = secondAxis.GetAxisCurveForGridPlacement();

            if (secondCurve == null)
            {
                return;
            }

            // We need to figure out the reference vector to do the offset, but we can't get
            // the reference vector without getting the tangent at the intersection point.
            // We will use a heuristic in GetReferenceVector to guess based on the curve types.
            XYZ   referenceVector  = GetReferenceVector(firstCurve);
            Curve firstOffsetCurve = (!MathUtil.IsAlmostZero(offsetDistances[0])) ?
                                     firstCurve.CreateOffset(offsetDistances[0], referenceVector) : firstCurve;
            Curve secondOffsetCurve = (!MathUtil.IsAlmostZero(offsetDistances[1])) ?
                                      secondCurve.CreateOffset(offsetDistances[1], referenceVector) : secondCurve;

            IntersectionResultArray resultArray;
            SetComparisonResult     result = firstOffsetCurve.Intersect(secondOffsetCurve, out resultArray);

            if (result != SetComparisonResult.Overlap || resultArray == null || resultArray.Size == 0)
            {
                return;
            }

            IntersectionResult intersectionPoint = resultArray.get_Item(0);
            XYZ       origin      = intersectionPoint.XYZPoint + offsetDistances[2] * referenceVector;
            Transform derivatives = firstCurve.ComputeDerivatives(intersectionPoint.UVPoint.U, false);

            LocalCoordinateSystem        = Transform.CreateTranslation(origin);
            LocalCoordinateSystem.BasisX = derivatives.BasisX;
            LocalCoordinateSystem.BasisY = referenceVector.CrossProduct(derivatives.BasisX);
            LocalCoordinateSystem.BasisZ = referenceVector;
        }
Ejemplo n.º 8
0
        protected override void Process(IFCAnyHandle ifcMaterialProfileWithOffsets)
        {
            base.Process(ifcMaterialProfileWithOffsets);

            OffsetValues = IFCAnyHandleUtil.GetAggregateDoubleAttribute <List <double> >(ifcMaterialProfileWithOffsets, "OffsetValues");
        }