/// <summary>
        /// Finds contained elements.
        /// </summary>
        /// <param name="ifcRelHandle">The relation handle.</param>
        void ProcessIFCRelContainedInSpatialStructure(IFCAnyHandle ifcRelHandle)
        {
            HashSet <IFCAnyHandle> elemSet = IFCAnyHandleUtil.GetAggregateInstanceAttribute <HashSet <IFCAnyHandle> >(ifcRelHandle, "RelatedElements");

            if (elemSet == null)
            {
                Importer.TheLog.LogMissingRequiredAttributeError(ifcRelHandle, "RelatedElements", false);
                return;
            }

            foreach (IFCAnyHandle elem in elemSet)
            {
                try
                {
                    IFCProduct product = IFCProduct.ProcessIFCProduct(elem);
                    if (product != null)
                    {
                        product.ContainingStructure = this;
                        m_IFCProducts.Add(product);
                    }
                }
                catch (Exception ex)
                {
                    Importer.TheLog.LogError(elem.StepId, ex.Message, false);
                }
            }
        }
예제 #2
0
            public static void CheckObjectPlacementIsRelativeToSite(IFCProduct productEntity, int productStepId, int objectPlacementStepId)
            {
                IFCLocation productEntityLocation = productEntity.ObjectLocation;

                if (ActiveSite != null && productEntityLocation != null && productEntityLocation.RelativeToSite == false)
                {
                    if (!(productEntity is IFCSite))
                    {
                        IFCLocation activeSiteLocation = ActiveSite.ObjectLocation;
                        if (activeSiteLocation != null)
                        {
                            Importer.TheLog.LogWarning(productStepId, "The local placement (#" + objectPlacementStepId + ") of this entity was not relative to the IfcSite's local placement, patching.", false);
                            Transform siteTransform = activeSiteLocation.TotalTransform;
                            if (siteTransform != null)
                            {
                                Transform siteTransformInverse   = siteTransform.Inverse;
                                Transform originalTotalTransform = productEntityLocation.TotalTransform;
                                if (originalTotalTransform == null)
                                {
                                    productEntityLocation.RelativeTransform = siteTransformInverse;
                                }
                                else
                                {
                                    productEntityLocation.RelativeTransform = originalTotalTransform.Multiply(siteTransformInverse);
                                }
                            }

                            productEntityLocation.RelativeTo = activeSiteLocation;
                        }
                    }
                    productEntityLocation.RelativeToSite = true;
                }
            }
예제 #3
0
        /// <summary>
        /// Processes IfcObject handle.
        /// </summary>
        /// <param name="ifcObject">The IfcObject handle.</param>
        /// <returns>The IfcObject object.</returns>
        public static IFCObject ProcessIFCObject(IFCAnyHandle ifcObject)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(ifcObject))
            {
                IFCImportFile.TheLog.LogNullError(IFCEntityType.IfcObject);
                return(null);
            }

            IFCEntity cachedObject;

            if (IFCImportFile.TheFile.EntityMap.TryGetValue(ifcObject.StepId, out cachedObject))
            {
                return(cachedObject as IFCObject);
            }

            if (IFCAnyHandleUtil.IsSubTypeOf(ifcObject, IFCEntityType.IfcProduct))
            {
                return(IFCProduct.ProcessIFCProduct(ifcObject));
            }
            else if (IFCAnyHandleUtil.IsSubTypeOf(ifcObject, IFCEntityType.IfcProject))
            {
                return(IFCProject.ProcessIFCProject(ifcObject));
            }

            IFCImportFile.TheLog.LogUnhandledSubTypeError(ifcObject, IFCEntityType.IfcObject, true);
            return(null);
        }
예제 #4
0
        // TODO: handle SiteAddress.

        /// <summary>
        /// Check if an object placement is relative to the site's placement, and fix it if necessary.
        /// </summary>
        /// <param name="productEntity">The entity being checked.</param>
        /// <param name="productStepId">The id of the entity being checked.</param>
        /// <param name="objectPlacement">The object placement handle.</param>
        public static void CheckObjectPlacementIsRelativeToSite(IFCProduct productEntity, int productStepId,
                                                                IFCAnyHandle objectPlacement)
        {
            if (BaseSiteOffset == null)
            {
                return;
            }

            IFCLocation productEntityLocation = productEntity.ObjectLocation;

            if (productEntityLocation != null && productEntityLocation.RelativeToSite == false)
            {
                if (!(productEntity is IFCSite))
                {
                    if (!IFCAnyHandleUtil.IsSubTypeOf(objectPlacement, IFCEntityType.IfcGridPlacement))
                    {
                        Importer.TheLog.LogWarning(productStepId, "The local placement (#" + objectPlacement.StepId + ") of this entity was not relative to the IfcSite's local placement, patching.", false);
                    }

                    if (productEntityLocation.RelativeTransform == null)
                    {
                        productEntityLocation.RelativeTransform = Transform.CreateTranslation(-BaseSiteOffset);
                    }
                    else
                    {
                        productEntityLocation.RelativeTransform.Origin -= BaseSiteOffset;
                    }
                }
                productEntityLocation.RelativeToSite = true;
            }
        }
예제 #5
0
        /// <summary>
        /// Create a copying of the geometry of an entity with a different graphics style.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="original">The IFCProduct we are partially copying.</param>
        /// <param name="parentEntity">The IFCObjectDefinition we are going to add the geometry to.</param>
        /// <param name="cloneParentMaterial">Determine whether to use the one material of the parent entity, if it exists and is unique.</param>
        /// <returns>The list of geometries created with a new category and possibly material.</returns>
        public static IList <IFCSolidInfo> CloneElementGeometry(Document doc, IFCProduct original, IFCObjectDefinition parentEntity, bool cloneParentMaterial)
        {
            using (TemporaryDisableLogging disableLogging = new TemporaryDisableLogging())
            {
                IFCElement clone = new IFCElement();

                // Note that the GlobalId is left to null here; this allows us to later decide not to create a DirectShape for the result.

                // Get the ObjectLocation and ProductRepresentation from the original entity, which is all we need to create geometry.
                clone.ObjectLocation        = original.ObjectLocation;
                clone.ProductRepresentation = original.ProductRepresentation;
                clone.MaterialSelect        = original.MaterialSelect;

                // Get the EntityType and PredefinedType from the parent to ensure that it "matches" the category and graphics style of the parent.
                clone.EntityType     = parentEntity.EntityType;
                clone.PredefinedType = parentEntity.PredefinedType;

                if (cloneParentMaterial)
                {
                    // This will only work if the parent entity has one material.
                    IFCMaterial parentMaterial = parentEntity.GetTheMaterial();
                    if (parentMaterial != null)
                    {
                        clone.MaterialSelect = parentMaterial;
                    }
                }

                IList <GeometryObject> geomObjs = new List <GeometryObject>();
                CreateElement(doc, clone);
                return(clone.Solids);
            }
        }
예제 #6
0
        public static void WarnIfFaraway(IFCProduct product)
        {
            XYZ origin = product?.ObjectLocation?.TotalTransform?.Origin;

            if (origin != null && !XYZ.IsWithinLengthLimits(origin))
            {
                Importer.TheLog.LogWarning(product.Id, "This entity has an origin that is outside of Revit's creation limits.  This could result in bad graphical display of geometry.", false);
            }
        }
예제 #7
0
        /// <summary>
        /// Get the curve from the Axis representation of the given IfcProduct, transformed to the current local coordinate system.
        /// </summary>
        /// <param name="creator">The IfcProduct that may or may not contain a valid axis curve.</param>
        /// <param name="lcs">The local coordinate system.</param>
        /// <returns>The axis curve, if found, and valid.</returns>
        /// <remarks>In this case, we only allow bounded curves to be valid axis curves.
        /// The Curve may be contained as either a single Curve in the IFCCurve representation item,
        /// or it could be an open CurveLoop that could be represented as a single curve.</remarks>
        private Curve GetAxisCurve(IFCProduct creator, Transform lcs)
        {
            // We need an axis curve to clip the extrusion profiles; if we can't get one, fail
            IFCProductRepresentation productRepresentation = creator.ProductRepresentation;

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

            IList <IFCRepresentation> representations = productRepresentation.Representations;

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

            foreach (IFCRepresentation representation in representations)
            {
                // Go through the list of representations for this product, to find the Axis representation.
                if (representation == null || representation.Identifier != IFCRepresentationIdentifier.Axis)
                {
                    continue;
                }

                IList <IFCRepresentationItem> items = representation.RepresentationItems;
                if (items == null)
                {
                    continue;
                }

                // Go through the list of representation items in the Axis representation, to look for the IfcCurve.
                foreach (IFCRepresentationItem item in items)
                {
                    if (item is IFCCurve)
                    {
                        // We will accept a bounded curve, or an open CurveLoop that can be represented
                        // as one curve.
                        IFCCurve ifcCurve  = item as IFCCurve;
                        Curve    axisCurve = ifcCurve.Curve;
                        if (axisCurve == null)
                        {
                            axisCurve = ifcCurve.ConvertCurveLoopIntoSingleCurve();
                        }

                        if (axisCurve != null)
                        {
                            return(axisCurve.CreateTransformed(lcs));
                        }
                    }
                }
            }

            return(null);
        }
예제 #8
0
 public static void CheckObjectPlacementIsRelativeToSite(IFCProduct productEntity, int productStepId, int objectPlacementStepId)
 {
     if (IFCSite.ActiveSiteSetter.ActiveSite != null && productEntity.ObjectLocation.RelativeToSite == false)
     {
         if (productEntity is IFCSite)
         {
             productEntity.ObjectLocation.RelativeToSite = true;
         }
         else
         {
             Importer.TheLog.LogWarning(productStepId, "The local placement (#" + objectPlacementStepId + ") of this entity is not relative to the IfcSite's local placement.", false);
             IFCSite.ActiveSiteSetter.ActiveSite.CanRemoveSiteLocalPlacement = false;
         }
     }
 }
예제 #9
0
        /// <summary>
        /// Creates a Revit material based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        public void Create(IFCImportShapeEditScope shapeEditScope)
        {
            // TODO: support cut pattern id and cut pattern color.
            if (m_CreatedElementId != ElementId.InvalidElementId || !IsValidForCreation)
            {
                return;
            }

            try
            {
                // If the styled item or the surface style has a name, use it.
                IFCSurfaceStyle surfaceStyle = GetSurfaceStyle();
                if (surfaceStyle == null)
                {
                    // We only handle surface styles at the moment; log file should already reflect any other unhandled styles.
                    IsValidForCreation = true;
                    return;
                }

                string forcedName = surfaceStyle.Name;
                if (string.IsNullOrWhiteSpace(forcedName))
                {
                    forcedName = Name;
                }

                string suggestedName = null;
                if (Item != null)
                {
                    IFCProduct creator = shapeEditScope.Creator;
                    suggestedName = creator.GetTheMaterialName();
                }

                m_CreatedElementId = surfaceStyle.Create(shapeEditScope.Document, forcedName, suggestedName, Id);
            }
            catch (Exception ex)
            {
                IsValidForCreation = false;
                Importer.TheLog.LogCreationError(this, ex.Message, false);
            }
        }
예제 #10
0
 /// <summary>
 /// The constructor.
 /// </summary>
 public IFCLocationChecker(IFCProduct product)
 {
     LastFixFarawayLocationOrigin = FixFarawayLocationOrigin;
     FixFarawayLocationOrigin     = (product != null) &&
                                    ((product is IFCBuilding) || (product is IFCBuildingStorey));
 }
        protected IFCImportShapeEditScope(Document doc, IFCProduct creator)
        {
            Document = doc;
            Creator = creator;

            SetIFCFuzzyXYZEpsilon();
        }
      /// <summary>
      /// Get the curve from the Axis representation of the given IfcProduct, transformed to the current local coordinate system.
      /// </summary>
      /// <param name="creator">The IfcProduct that may or may not contain a valid axis curve.</param>
      /// <param name="lcs">The local coordinate system.</param>
      /// <returns>The axis curve, if found, and valid.</returns>
      /// <remarks>In this case, we only allow bounded lines and arcs to be valid axis curves, as per IFC2x3 convention.
      /// The Curve may be contained as either a single Curve in the IFCCurve representation item, or it could be an
      /// open CurveLoop with one item.</remarks>
      private Curve GetAxisCurve(IFCProduct creator, Transform lcs)
      {
         // We need an axis curve to clip the extrusion profiles; if we can't get one, fail
         IFCProductRepresentation productRepresentation = creator.ProductRepresentation;
         if (productRepresentation == null)
            return null;

         IList<IFCRepresentation> representations = productRepresentation.Representations;
         if (representations == null)
            return null;

         foreach (IFCRepresentation representation in representations)
         {
            // Go through the list of representations for this product, to find the Axis representation.
            if (representation == null || representation.Identifier != IFCRepresentationIdentifier.Axis)
               continue;

            IList<IFCRepresentationItem> items = representation.RepresentationItems;
            if (items == null)
               continue;

            // Go through the list of representation items in the Axis representation, to look for the IfcCurve.
            foreach (IFCRepresentationItem item in items)
            {
               if (item is IFCCurve)
               {
                  // We will accept either a bounded Curve of type Line or Arc, 
                  // or an open CurveLoop with one curve that satisfies the same condition.
                  IFCCurve ifcCurve = item as IFCCurve;
                  Curve axisCurve = ifcCurve.Curve;
                  if (axisCurve == null)
                  {
                     CurveLoop axisCurveLoop = ifcCurve.CurveLoop;
                     if (axisCurveLoop != null && axisCurveLoop.IsOpen() && axisCurveLoop.Count() == 1)
                     {
                        axisCurve = axisCurveLoop.First();
                        if (!(axisCurve is Line || axisCurve is Arc))
                           axisCurve = null;
                     }
                  }

                  if (axisCurve != null)
                     return axisCurve.CreateTransformed(lcs);
               }
            }
         }

         return null;
      }
예제 #13
0
        // End temporary classes for holding BRep information.

        protected IFCImportShapeEditScope(Document doc, IFCProduct creator)
        {
            Document = doc;
            Creator = creator;

            // Note that this tolerance is larger than required for meshes, and slightly larger than
            // required for BReps, as it is a cube instead of a sphere of equivalence.  However, we are
            // generally trying to create Solids over Meshes, and as such we try for Solid tolerances.
            IFCFuzzyXYZEpsilon = IFCImportFile.TheFile.Document.Application.ShortCurveTolerance;
        }
예제 #14
0
      /// <summary>
      /// Create a copying of the geometry of an entity with a different graphics style.
      /// </summary>
      /// <param name="doc">The document.</param>
      /// <param name="original">The IFCProduct we are partially copying.</param>
      /// <param name="parentEntity">The IFCObjectDefinition we are going to add the geometry to.</param>
      /// <param name="cloneParentMaterial">Determine whether to use the one material of the parent entity, if it exists and is unique.</param>
      /// <returns>The list of geometries created with a new category and possibly material.</returns>
      public static IList<IFCSolidInfo> CloneElementGeometry(Document doc, IFCProduct original, IFCObjectDefinition parentEntity, bool cloneParentMaterial)
      {
         using (TemporaryDisableLogging disableLogging = new TemporaryDisableLogging())
         {
            IFCElement clone = new IFCElement();

            // Note that the GlobalId is left to null here; this allows us to later decide not to create a DirectShape for the result.

            // Get the ObjectLocation and ProductRepresentation from the original entity, which is all we need to create geometry.
            clone.ObjectLocation = original.ObjectLocation;
            clone.ProductRepresentation = original.ProductRepresentation;
            clone.MaterialSelect = original.MaterialSelect;

            // Get the EntityType and PredefinedType from the parent to ensure that it "matches" the category and graphics style of the parent.
            clone.EntityType = parentEntity.EntityType;
            clone.PredefinedType = parentEntity.PredefinedType;

            if (cloneParentMaterial)
            {
               // This will only work if the parent entity has one material.
               IFCMaterial parentMaterial = parentEntity.GetTheMaterial();
               if (parentMaterial != null)
                  clone.MaterialSelect = parentMaterial;
            }

            IList<GeometryObject> geomObjs = new List<GeometryObject>();
            CreateElement(doc, clone);
            return clone.Solids;
         }
      }
        /// <summary>
        /// Get the curve from the Axis representation of the given IfcProduct, transformed to the current local coordinate system.
        /// </summary>
        /// <param name="creator">The IfcProduct that may or may not contain a valid axis curve.</param>
        /// <param name="lcs">The local coordinate system.</param>
        /// <returns>The axis curve, if found, and valid.</returns>
        /// <remarks>In this case, we only allow bounded lines and arcs to be valid axis curves, as per IFC2x3 convention.
        /// The Curve may be contained as either a single Curve in the IFCCurve representation item, or it could be an
        /// open CurveLoop with one item.</remarks>
        private Curve GetAxisCurve(IFCProduct creator, Transform lcs)
        {
            // We need an axis curve to clip the extrusion profiles; if we can't get one, fail
            IFCProductRepresentation productRepresentation = creator.ProductRepresentation;

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

            IList <IFCRepresentation> representations = productRepresentation.Representations;

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

            foreach (IFCRepresentation representation in representations)
            {
                // Go through the list of representations for this product, to find the Axis representation.
                if (representation == null || representation.Identifier != IFCRepresentationIdentifier.Axis)
                {
                    continue;
                }

                IList <IFCRepresentationItem> items = representation.RepresentationItems;
                if (items == null)
                {
                    continue;
                }

                // Go through the list of representation items in the Axis representation, to look for the IfcCurve.
                foreach (IFCRepresentationItem item in items)
                {
                    if (item is IFCCurve)
                    {
                        // We will accept either a bounded Curve of type Line or Arc,
                        // or an open CurveLoop with one curve that satisfies the same condition.
                        IFCCurve ifcCurve  = item as IFCCurve;
                        Curve    axisCurve = ifcCurve.Curve;
                        if (axisCurve == null)
                        {
                            CurveLoop axisCurveLoop = ifcCurve.CurveLoop;
                            if (axisCurveLoop != null && axisCurveLoop.IsOpen() && axisCurveLoop.Count() == 1)
                            {
                                axisCurve = axisCurveLoop.First();
                                if (!(axisCurve is Line || axisCurve is Arc))
                                {
                                    axisCurve = null;
                                }
                            }
                        }

                        if (axisCurve != null)
                        {
                            return(axisCurve.CreateTransformed(lcs));
                        }
                    }
                }
            }

            return(null);
        }
        // This routine may return null geometry for one of three reasons:
        // 1. Invalid input.
        // 2. No IfcMaterialLayerUsage.
        // 3. The IfcMaterialLayerUsage isn't handled.
        // If the reason is #1 or #3, we want to warn the user.  If it is #2, we don't.  Pass back shouldWarn to let the caller know.
        private IList <GeometryObject> CreateGeometryFromMaterialLayerUsage(IFCImportShapeEditScope shapeEditScope, Transform extrusionPosition,
                                                                            IList <CurveLoop> loops, XYZ extrusionDirection, double currDepth, out ElementId materialId, out bool shouldWarn)
        {
            IList <GeometryObject> extrusionSolids = null;

            materialId = ElementId.InvalidElementId;

            try
            {
                shouldWarn = true; // Invalid input.

                // Check for valid input.
                if (shapeEditScope == null ||
                    extrusionPosition == null ||
                    loops == null ||
                    loops.Count() == 0 ||
                    extrusionDirection == null ||
                    !Application.IsValidThickness(currDepth))
                {
                    return(null);
                }

                IFCProduct creator = shapeEditScope.Creator;
                if (creator == null)
                {
                    return(null);
                }

                shouldWarn = false; // Missing, empty, or optimized out IfcMaterialLayerSetUsage - valid reason to stop.

                IIFCMaterialSelect materialSelect = creator.MaterialSelect;
                if (materialSelect == null)
                {
                    return(null);
                }

                IFCMaterialLayerSetUsage materialLayerSetUsage = materialSelect as IFCMaterialLayerSetUsage;
                if (materialLayerSetUsage == null)
                {
                    return(null);
                }

                IFCMaterialLayerSet materialLayerSet = materialLayerSetUsage.MaterialLayerSet;
                if (materialLayerSet == null)
                {
                    return(null);
                }

                IList <IFCMaterialLayer> materialLayers = materialLayerSet.MaterialLayers;
                if (materialLayers == null || materialLayers.Count == 0)
                {
                    return(null);
                }

                // Optimization: if there is only one layer, use the standard method, with possibly an overloaded material.
                ElementId baseMaterialId = GetMaterialElementId(shapeEditScope);
                if (materialLayers.Count == 1)
                {
                    IFCMaterial oneMaterial = materialLayers[0].Material;
                    if (oneMaterial == null)
                    {
                        return(null);
                    }

                    materialId = oneMaterial.GetMaterialElementId();
                    if (materialId != ElementId.InvalidElementId)
                    {
                        // We will not override the material of the element if the layer material has no color.
                        if (Importer.TheCache.MaterialsWithNoColor.Contains(materialId))
                        {
                            materialId = ElementId.InvalidElementId;
                        }
                    }

                    return(null);
                }

                // Anything below here is something we should report to the user, with the exception of the total thickness
                // not matching the extrusion thickness.  This would require more analysis to determine that it is actually
                // an error condition.
                shouldWarn = true;

                IList <IFCMaterialLayer> realMaterialLayers = new List <IFCMaterialLayer>();
                double totalThickness = 0.0;
                foreach (IFCMaterialLayer materialLayer in materialLayers)
                {
                    double depth = materialLayer.LayerThickness;
                    if (MathUtil.IsAlmostZero(depth))
                    {
                        continue;
                    }

                    if (depth < 0.0)
                    {
                        return(null);
                    }

                    realMaterialLayers.Add(materialLayer);
                    totalThickness += depth;
                }

                // Axis3 means that the material layers are stacked in the Z direction.  This is common for floor slabs.
                bool isAxis3 = (materialLayerSetUsage.Direction == IFCLayerSetDirection.Axis3);

                // For elements extruded in the Z direction, if the extrusion layers don't have the same thickness as the extrusion,
                // this could be one of two reasons:
                // 1. There is a discrepancy between the extrusion depth and the material layer set usage calculated depth.
                // 2. There are multiple extrusions in the body definition.
                // In either case, we will use the extrusion geometry over the calculated material layer set usage geometry.
                // In the future, we may decide to allow for case #1 by passing in a flag to allow for this.
                if (isAxis3 && !MathUtil.IsAlmostEqual(totalThickness, currDepth))
                {
                    shouldWarn = false;
                    return(null);
                }

                int numLayers = realMaterialLayers.Count();
                if (numLayers == 0)
                {
                    return(null);
                }
                // We'll use this initial value for the Axis2 case, so read it here.
                double baseOffsetForLayer = materialLayerSetUsage.Offset;

                // Needed for Axis2 case only.  The axisCurve is the curve defined in the product representation representing
                // a base curve (an axis) for the footprint of the element.
                Curve axisCurve = null;

                // The oriented cuve list represents the 4 curves of supported Axis2 footprint in the following order:
                // 1. curve along length of object closest to the first material layer with the orientation of the axis curve
                // 2. connecting end curve
                // 3. curve along length of object closest to the last material layer with the orientation opposite of the axis curve
                // 4. connecting end curve.
                IList <Curve> orientedCurveList = null;

                if (!isAxis3)
                {
                    // Axis2 means that the material layers are stacked inthe Y direction.  This is by definition for IfcWallStandardCase,
                    // which has a local coordinate system whose Y direction is orthogonal to the length of the wall.
                    if (materialLayerSetUsage.Direction == IFCLayerSetDirection.Axis2)
                    {
                        axisCurve = GetAxisCurve(creator, extrusionPosition);
                        if (axisCurve == null)
                        {
                            return(null);
                        }

                        orientedCurveList = GetOrientedCurveList(loops, axisCurve, extrusionPosition.BasisZ, baseOffsetForLayer, totalThickness);
                        if (orientedCurveList == null)
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null); // Not handled.
                    }
                }

                extrusionSolids = new List <GeometryObject>();

                bool positiveOrientation = (materialLayerSetUsage.DirectionSense == IFCDirectionSense.Positive);

                // Always extrude in the positive direction for Axis2.
                XYZ materialExtrusionDirection = (positiveOrientation || !isAxis3) ? extrusionDirection : -extrusionDirection;

                // Axis2 repeated values.
                // The IFC concept of offset direction is reversed from Revit's.
                XYZ    normalDirectionForAxis2 = positiveOrientation ? -extrusionPosition.BasisZ : extrusionPosition.BasisZ;
                bool   axisIsCyclic            = (axisCurve == null) ? false : axisCurve.IsCyclic;
                double axisCurvePeriod         = axisIsCyclic ? axisCurve.Period : 0.0;

                Transform curveLoopTransform = Transform.Identity;

                IList <CurveLoop> currLoops  = null;
                double            depthSoFar = 0.0;

                for (int ii = 0; ii < numLayers; ii++)
                {
                    IFCMaterialLayer materialLayer = materialLayers[ii];

                    // Ignore 0 thickness layers.  No need to warn.
                    double depth = materialLayer.LayerThickness;
                    if (MathUtil.IsAlmostZero(depth))
                    {
                        continue;
                    }

                    // If the thickness is non-zero but invalid, fail.
                    if (!Application.IsValidThickness(depth))
                    {
                        return(null);
                    }

                    double extrusionDistance = 0.0;
                    if (isAxis3)
                    {
                        // Offset the curve loops if necessary, using the base extrusionDirection, regardless of the direction sense
                        // of the MaterialLayerSetUsage.
                        double offsetForLayer = positiveOrientation ? baseOffsetForLayer + depthSoFar : baseOffsetForLayer - depthSoFar;
                        if (!MathUtil.IsAlmostZero(offsetForLayer))
                        {
                            curveLoopTransform.Origin = offsetForLayer * extrusionDirection;

                            currLoops = new List <CurveLoop>();
                            foreach (CurveLoop loop in loops)
                            {
                                CurveLoop newLoop = CurveLoop.CreateViaTransform(loop, curveLoopTransform);
                                if (newLoop == null)
                                {
                                    return(null);
                                }

                                currLoops.Add(newLoop);
                            }
                        }
                        else
                        {
                            currLoops = loops;
                        }

                        extrusionDistance = depth;
                    }
                    else
                    {
                        // startClipCurve, firstEndCapCurve, endClipCurve, secondEndCapCurve.
                        Curve[]    outline       = new Curve[4];
                        double[][] endParameters = new double[4][];

                        double startClip = depthSoFar;
                        double endClip   = depthSoFar + depth;

                        outline[0] = orientedCurveList[0].CreateOffset(startClip, normalDirectionForAxis2);
                        outline[1] = orientedCurveList[1].Clone();
                        outline[2] = orientedCurveList[2].CreateOffset(totalThickness - endClip, normalDirectionForAxis2);
                        outline[3] = orientedCurveList[3].Clone();

                        for (int jj = 0; jj < 4; jj++)
                        {
                            outline[jj].MakeUnbound();
                            endParameters[jj]    = new double[2];
                            endParameters[jj][0] = 0.0;
                            endParameters[jj][1] = 0.0;
                        }

                        // Trim/Extend the curves so that they make a closed loop.
                        for (int jj = 0; jj < 4; jj++)
                        {
                            IntersectionResultArray resultArray = null;
                            outline[jj].Intersect(outline[(jj + 1) % 4], out resultArray);
                            if (resultArray == null || resultArray.Size == 0)
                            {
                                return(null);
                            }

                            int numResults = resultArray.Size;
                            if ((numResults > 1 && !axisIsCyclic) || (numResults > 2))
                            {
                                return(null);
                            }

                            UV intersectionPoint = resultArray.get_Item(0).UVPoint;
                            endParameters[jj][1]           = intersectionPoint.U;
                            endParameters[(jj + 1) % 4][0] = intersectionPoint.V;

                            if (numResults == 2)
                            {
                                // If the current result is closer to the end of the curve, keep it.
                                UV newIntersectionPoint = resultArray.get_Item(1).UVPoint;

                                int    endParamIndex   = (jj % 2);
                                double newParamToCheck = newIntersectionPoint[endParamIndex];
                                double oldParamToCheck = (endParamIndex == 0) ? endParameters[jj][1] : endParameters[(jj + 1) % 4][0];
                                double currentEndPoint = (endParamIndex == 0) ?
                                                         orientedCurveList[jj].GetEndParameter(1) : orientedCurveList[(jj + 1) % 4].GetEndParameter(0);

                                // Put in range of [-Period/2, Period/2].
                                double newDist = (currentEndPoint - newParamToCheck) % axisCurvePeriod;
                                if (newDist < -axisCurvePeriod / 2.0)
                                {
                                    newDist += axisCurvePeriod;
                                }
                                if (newDist > axisCurvePeriod / 2.0)
                                {
                                    newDist -= axisCurvePeriod;
                                }

                                double oldDist = (currentEndPoint - oldParamToCheck) % axisCurvePeriod;
                                if (oldDist < -axisCurvePeriod / 2.0)
                                {
                                    oldDist += axisCurvePeriod;
                                }
                                if (oldDist > axisCurvePeriod / 2.0)
                                {
                                    oldDist -= axisCurvePeriod;
                                }

                                if (Math.Abs(newDist) < Math.Abs(oldDist))
                                {
                                    endParameters[jj][1]           = newIntersectionPoint.U;
                                    endParameters[(jj + 1) % 4][0] = newIntersectionPoint.V;
                                }
                            }
                        }

                        CurveLoop newCurveLoop = new CurveLoop();
                        for (int jj = 0; jj < 4; jj++)
                        {
                            if (endParameters[jj][1] < endParameters[jj][0])
                            {
                                if (!outline[jj].IsCyclic)
                                {
                                    return(null);
                                }
                                endParameters[jj][1] += Math.Floor(endParameters[jj][0] / axisCurvePeriod + 1.0) * axisCurvePeriod;
                            }

                            outline[jj].MakeBound(endParameters[jj][0], endParameters[jj][1]);
                            newCurveLoop.Append(outline[jj]);
                        }

                        currLoops = new List <CurveLoop>();
                        currLoops.Add(newCurveLoop);

                        extrusionDistance = currDepth;
                    }

                    // Determine the material id.
                    IFCMaterial material        = materialLayer.Material;
                    ElementId   layerMaterialId = (material == null) ? ElementId.InvalidElementId : material.GetMaterialElementId();

                    // The second option here is really for Referencing.  Without a UI (yet) to determine whether to show the base
                    // extusion or the layers for objects with material layer sets, we've chosen to display the base material if the layer material
                    // has no color information.  This means that the layer is assigned the "wrong" material, but looks better on screen.
                    // We will reexamine this decision (1) for the Open case, (2) if there is UI to toggle between layers and base extrusion, or
                    // (3) based on user feedback.
                    if (layerMaterialId == ElementId.InvalidElementId || Importer.TheCache.MaterialsWithNoColor.Contains(layerMaterialId))
                    {
                        layerMaterialId = baseMaterialId;
                    }

                    SolidOptions solidOptions = new SolidOptions(layerMaterialId, shapeEditScope.GraphicsStyleId);

                    // Create the extrusion for the material layer.
                    GeometryObject extrusionSolid = GeometryCreationUtilities.CreateExtrusionGeometry(
                        currLoops, materialExtrusionDirection, extrusionDistance, solidOptions);
                    if (extrusionSolid == null)
                    {
                        return(null);
                    }

                    extrusionSolids.Add(extrusionSolid);
                    depthSoFar += depth;
                }
            }
            catch
            {
                // Ignore the specific exception, but let the user know there was a problem processing the IfcMaterialLayerSetUsage.
                shouldWarn = true;
                return(null);
            }

            return(extrusionSolids);
        }
 /// <summary>
 /// Create a new edit scope.  Intended to be used with the "using" keyword.
 /// </summary>
 /// <param name="doc">The import document.</param>
 /// <param name="action">The name of the current action.</param>
 /// <param name="creator">The entity being processed.</param>
 /// <returns>The new edit scope.</returns>
 static public IFCImportShapeEditScope Create(Document doc, IFCProduct creator)
 {
     return new IFCImportShapeEditScope(doc, creator);
 }