Example #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();
            }
        }
Example #2
0
        /// <summary>
        /// Creates or populates Revit elements based on the information contained in this class.
        /// </summary>
        /// <param name="doc">The document.</param>
        protected override void Create(Document doc)
        {
            Transform lcs = (ObjectLocation != null) ? ObjectLocation.TotalTransform : Transform.Identity;

            CreateOneDirection(UAxes, doc, lcs);
            CreateOneDirection(VAxes, doc, lcs);
            CreateOneDirection(WAxes, doc, lcs);

            ISet <ElementId> createdElementIds = new HashSet <ElementId>();

            GetCreatedElementIds(createdElementIds);

            // We want to get the presentation layer from the Grid representation, if any.
            IFCPresentationLayerAssignment defaultLayerAssignment = GetTheFirstPresentationLayerAssignment();
            string defaultLayerAssignmentName    = (defaultLayerAssignment != null) ? defaultLayerAssignment.Name : null;
            bool   hasDefaultLayerAssignmentName = !string.IsNullOrWhiteSpace(defaultLayerAssignmentName);

            foreach (ElementId createdElementId in createdElementIds)
            {
                CreatedElementId = createdElementId;

                SetCurrentPresentationLayerNames(defaultLayerAssignmentName, hasDefaultLayerAssignmentName);
                CreateParameters(doc);
            }

            CreatedElementId = ElementId.InvalidElementId;
        }
        override protected void Process(IFCAnyHandle item)
        {
            base.Process(item);

            LayerAssignment = IFCPresentationLayerAssignment.GetTheLayerAssignment(item);

            List<IFCAnyHandle> styledByItems = IFCAnyHandleUtil.GetAggregateInstanceAttribute<List<IFCAnyHandle>>(item, "StyledByItem");
            if (styledByItems != null && styledByItems.Count > 0)
            {
                // We can only handle one styled item, but we allow the possiblity that there are duplicates.  Do a top-level check.
                foreach (IFCAnyHandle styledByItem in styledByItems)
                {
                    if (!IFCAnyHandleUtil.IsSubTypeOf(styledByItem, IFCEntityType.IfcStyledItem))
                    {
                        Importer.TheLog.LogUnexpectedTypeError(styledByItem, IFCEntityType.IfcStyledItem, false);
                        StyledByItem = null;
                        break;
                    }
                    else
                    {
                        if (StyledByItem == null)
                            StyledByItem = IFCStyledItem.ProcessIFCStyledItem(styledByItem);
                        else
                        {
                            IFCStyledItem compStyledByItem = IFCStyledItem.ProcessIFCStyledItem(styledByItem);
                            if (!StyledByItem.IsEquivalentTo(compStyledByItem))
                            {
                                Importer.TheLog.LogWarning(Id, "Multiple inconsistent styled items found for this item; using first one.", false);
                                break;
                            }
                        }
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Does a top-level check to see if this entity may be equivalent to otherEntity.
        /// </summary>
        /// <param name="otherEntity">The other IFCEntity.</param>
        /// <returns>True if they are equivalent, false if they aren't, null if not enough information.</returns>
        /// <remarks>This isn't intended to be an exhaustive check, and isn't implemented for all types.  This is intended
        /// to be used by derived classes.</remarks>
        public override bool?MaybeEquivalentTo(IFCEntity otherEntity)
        {
            bool?maybeEquivalentTo = base.MaybeEquivalentTo(otherEntity);

            if (maybeEquivalentTo.HasValue)
            {
                return(maybeEquivalentTo.Value);
            }

            if (!(otherEntity is IFCPresentationLayerAssignment))
            {
                return(false);
            }

            IFCPresentationLayerAssignment other = otherEntity as IFCPresentationLayerAssignment;

            if (!IFCNamingUtil.SafeStringsAreEqual(Name, other.Name))
            {
                return(false);
            }

            if (!IFCNamingUtil.SafeStringsAreEqual(Description, other.Description))
            {
                return(false);
            }

            if (!IFCNamingUtil.SafeStringsAreEqual(Identifier, other.Identifier))
            {
                return(false);
            }

            return(null);
        }
 /// <summary>
 /// Deal with missing "LayerAssignments" in IFC2x3 EXP file.
 /// </summary>
 /// <param name="layerAssignment">The layer assignment to add to this representation.</param>
 public void PostProcessLayerAssignment(IFCPresentationLayerAssignment layerAssignment)
 {
     if (LayerAssignment == null)
     {
         LayerAssignment = layerAssignment;
     }
     else
     {
         IFCImportDataUtil.CheckLayerAssignmentConsistency(LayerAssignment, layerAssignment, Id);
     }
 }
        /// <summary>
        /// Check if two IFCPresentationLayerAssignments are equivalent, and warn if they aren't/
        /// </summary>
        /// <param name="originalAssignment">The original layer assignment in this representation.</param>
        /// <param name="layerAssignment">The layer assignment to add to this representation.</param>
        /// <returns>True if the layer assignments are consistent; false otherwise.</returns>
        static public bool CheckLayerAssignmentConsistency(IFCPresentationLayerAssignment originalAssignment, 
            IFCPresentationLayerAssignment layerAssignment, int id)
        {
            if ((originalAssignment != null) && (!originalAssignment.IsEquivalentTo(layerAssignment)))
            {
                Importer.TheLog.LogWarning(id, "Multiple inconsistent layer assignment items found for this item; using first one.", false);
                return false;
            }

            return true;
        }
Example #7
0
        static public void ProcessAllLayerAssignments()
        {
            IList <IFCAnyHandle> layerAssignments = IFCImportFile.TheFile.GetInstances(IFCEntityType.IfcPresentationLayerAssignment, true);

            if (layerAssignments != null)
            {
                foreach (IFCAnyHandle layerAssignment in layerAssignments)
                {
                    IFCPresentationLayerAssignment.ProcessIFCPresentationLayerAssignment(layerAssignment);
                }
            }
        }
Example #8
0
        /// <summary>
        /// Get the one layer assignment associated to this handle, if it is defined.
        /// </summary>
        /// <param name="ifcLayeredItem">The handle assumed to be an IfcRepresentation or IfcRepresentationItem.</param>
        /// <param name="isIFCRepresentation">True if the handle is an IfcRepresentation.  This determines the name of the inverse attribute.</param>
        /// <returns>The associated IfcLayerAssignment.</returns>
        /// <remarks>This deals with the issues that:
        /// 1. the default IFC2x3 EXP file doesn't have this inverse attribute set.
        /// 2. The name changed in IFC4.
        /// 3. The attribute didn't exist before IFC2x3.</remarks>
        static public IFCPresentationLayerAssignment GetTheLayerAssignment(IFCAnyHandle ifcLayeredItem, bool isIFCRepresentation)
        {
            IFCPresentationLayerAssignment theLayerAssignment = null;
            IList <IFCAnyHandle>           layerAssignments   = null;

            if (IFCImportFile.TheFile.Options.AllowUseLayerAssignments)
            {
                // Inverse attribute changed names in IFC4 for IfcRepresentationItem only.
                string layerAssignmentsAttributeName = (isIFCRepresentation || IFCImportFile.TheFile.SchemaVersion < IFCSchemaVersion.IFC4) ? "LayerAssignments" : "LayerAssignment";
                try
                {
                    layerAssignments = IFCAnyHandleUtil.GetAggregateInstanceAttribute
                                       <List <IFCAnyHandle> >(ifcLayeredItem, layerAssignmentsAttributeName);
                }
                catch
                {
                    IFCImportFile.TheFile.Options.AllowUseLayerAssignments = false;
                    layerAssignments = null;
                }
            }

            if (layerAssignments != null && layerAssignments.Count > 0)
            {
                // We can only handle one layer assignment, but we allow the possiblity that there are duplicates.  Do a top-level check.
                foreach (IFCAnyHandle layerAssignment in layerAssignments)
                {
                    if (!IFCAnyHandleUtil.IsSubTypeOf(layerAssignment, IFCEntityType.IfcPresentationLayerAssignment))
                    {
                        Importer.TheLog.LogUnexpectedTypeError(layerAssignment, IFCEntityType.IfcStyledItem, false);
                        theLayerAssignment = null;
                        break;
                    }
                    else
                    {
                        IFCPresentationLayerAssignment compLayerAssignment = IFCPresentationLayerAssignment.ProcessIFCPresentationLayerAssignment(layerAssignment);
                        if (theLayerAssignment == null)
                        {
                            theLayerAssignment = compLayerAssignment;
                            continue;
                        }

                        if (!IFCImportDataUtil.CheckLayerAssignmentConsistency(theLayerAssignment, compLayerAssignment, ifcLayeredItem.StepId))
                        {
                            break;
                        }
                    }
                }
            }

            return(theLayerAssignment);
        }
Example #9
0
        /// <summary>
        /// Get the one layer assignment associated to this handle, if it is defined.
        /// </summary>
        /// <param name="ifcLayeredItem">The handle assumed to be an IfcRepresentation or IfcRepresentationItem.</param>
        /// <returns>The associated IfcLayerAssignment.</returns>
        static public IFCPresentationLayerAssignment GetTheLayerAssignment(IFCAnyHandle ifcLayeredItem)
        {
            IFCAnyHandle layerAssignmentHnd;

            if (!Importer.TheCache.LayerAssignment.TryGetValue(ifcLayeredItem, out layerAssignmentHnd))
            {
                return(null);
            }

            IFCPresentationLayerAssignment layerAssignment =
                ProcessIFCPresentationLayerAssignment(layerAssignmentHnd);

            return(layerAssignment);
        }
        override protected void Process(IFCAnyHandle item)
        {
            base.Process(item);

            LayerAssignment = IFCPresentationLayerAssignment.GetTheLayerAssignment(item);

            // IFC2x has a different representation for styled items which we don't support.
            ICollection <IFCAnyHandle> styledByItems = null;

            if (Importer.TheCache.StyledByItems.TryGetValue(item, out styledByItems))
            {
                if (styledByItems != null && styledByItems.Count > 0)
                {
                    // We can only handle one styled item, but we allow the possiblity that there are duplicates.  Do a top-level check.
                    foreach (IFCAnyHandle styledByItem in styledByItems)
                    {
                        if (!IFCAnyHandleUtil.IsSubTypeOf(styledByItem, IFCEntityType.IfcStyledItem))
                        {
                            Importer.TheLog.LogUnexpectedTypeError(styledByItem, IFCEntityType.IfcStyledItem, false);
                            StyledByItem = null;
                            break;
                        }
                        else
                        {
                            if (StyledByItem == null)
                            {
                                StyledByItem = IFCStyledItem.ProcessIFCStyledItem(styledByItem);
                            }
                            else
                            {
                                IFCStyledItem compStyledByItem = IFCStyledItem.ProcessIFCStyledItem(styledByItem);
                                if (!StyledByItem.IsEquivalentTo(compStyledByItem))
                                {
                                    Importer.TheLog.LogWarning(Id, "Multiple inconsistent styled items found for this item; using first one.", false);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
        override protected void Process(IFCAnyHandle item)
        {
            base.Process(item);

            LayerAssignment = IFCPresentationLayerAssignment.GetTheLayerAssignment(item, false);

            List <IFCAnyHandle> styledByItems = IFCAnyHandleUtil.GetAggregateInstanceAttribute <List <IFCAnyHandle> >(item, "StyledByItem");

            if (styledByItems != null && styledByItems.Count > 0)
            {
                // We can only handle one styled item, but we allow the possiblity that there are duplicates.  Do a top-level check.
                foreach (IFCAnyHandle styledByItem in styledByItems)
                {
                    if (!IFCAnyHandleUtil.IsSubTypeOf(styledByItem, IFCEntityType.IfcStyledItem))
                    {
                        Importer.TheLog.LogUnexpectedTypeError(styledByItem, IFCEntityType.IfcStyledItem, false);
                        StyledByItem = null;
                        break;
                    }
                    else
                    {
                        if (StyledByItem == null)
                        {
                            StyledByItem = IFCStyledItem.ProcessIFCStyledItem(styledByItem);
                        }
                        else
                        {
                            IFCStyledItem compStyledByItem = IFCStyledItem.ProcessIFCStyledItem(styledByItem);
                            if (!StyledByItem.IsEquivalentTo(compStyledByItem))
                            {
                                Importer.TheLog.LogWarning(Id, "Multiple inconsistent styled items found for this item; using first one.", false);
                                break;
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Processes IfcRepresentation attributes.
        /// </summary>
        /// <param name="ifcRepresentation">The IfcRepresentation handle.</param>
        override protected void Process(IFCAnyHandle ifcRepresentation)
        {
            base.Process(ifcRepresentation);

            IFCAnyHandle representationContext = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcRepresentation, "ContextOfItems", false);

            if (representationContext != null)
            {
                Context = IFCRepresentationContext.ProcessIFCRepresentationContext(representationContext);
            }

            string identifier = IFCImportHandleUtil.GetOptionalStringAttribute(ifcRepresentation, "RepresentationIdentifier", null);

            Identifier = GetRepresentationIdentifier(identifier, ifcRepresentation);

            Type = IFCImportHandleUtil.GetOptionalStringAttribute(ifcRepresentation, "RepresentationType", null);

            HashSet <IFCAnyHandle> items =
                IFCAnyHandleUtil.GetAggregateInstanceAttribute <HashSet <IFCAnyHandle> >(ifcRepresentation, "Items");

            LayerAssignment = IFCPresentationLayerAssignment.GetTheLayerAssignment(ifcRepresentation, true);

            foreach (IFCAnyHandle item in items)
            {
                IFCRepresentationItem repItem = null;
                try
                {
                    if (NotAllowedInRepresentation(item))
                    {
                        IFCEntityType entityType = IFCAnyHandleUtil.GetEntityType(item);
                        Importer.TheLog.LogWarning(item.StepId, "Ignoring unhandled representation item of type " + entityType.ToString() + " in " +
                                                   Identifier.ToString() + " representation.", true);
                        continue;
                    }

                    // Special processing for bounding boxes - only IfcBoundingBox allowed.
                    if (IFCAnyHandleUtil.IsSubTypeOf(item, IFCEntityType.IfcBoundingBox))
                    {
                        // Don't read in Box represenation unless options allow it.
                        if (IFCImportFile.TheFile.Options.ProcessBoundingBoxGeometry == IFCProcessBBoxOptions.Never)
                        {
                            Importer.TheLog.LogWarning(item.StepId, "BoundingBox not imported with ProcessBoundingBoxGeometry=Never", false);
                        }
                        else
                        {
                            if (BoundingBox != null)
                            {
                                Importer.TheLog.LogWarning(item.StepId, "Found second IfcBoundingBox representation item, ignoring.", false);
                                continue;
                            }
                            BoundingBox = ProcessBoundingBox(item);
                        }
                    }
                    else
                    {
                        repItem = IFCRepresentationItem.ProcessIFCRepresentationItem(item);
                    }
                }
                catch (Exception ex)
                {
                    Importer.TheLog.LogError(item.StepId, ex.Message, false);
                }
                if (repItem != null)
                {
                    RepresentationItems.Add(repItem);
                }
            }
        }
 /// <summary>
 /// Deal with missing "LayerAssignments" in IFC2x3 EXP file.
 /// </summary>
 /// <param name="layerAssignment">The layer assignment to add to this representation.</param>
 public void PostProcessLayerAssignment(IFCPresentationLayerAssignment layerAssignment)
 {
     if (LayerAssignment == null)
         LayerAssignment = layerAssignment;
     else
         IFCImportDataUtil.CheckLayerAssignmentConsistency(LayerAssignment, layerAssignment, Id);
 }
Example #14
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))
                    {
                        IFCRepresentationContext context = IFCRepresentationContext.ProcessIFCRepresentationContext(geomRepContextHandle);
                        if (TrueNorthDirection == null && context.TrueNorth != null)
                        {
                            // TODO: Verify that we don't have inconsistent true norths.  If we do, warn.
                            TrueNorthDirection = new UV(context.TrueNorth.X, context.TrueNorth.Y);
                        }

                        if (WorldCoordinateSystem == null && context.WorldCoordinateSystem != null && !context.WorldCoordinateSystem.IsIdentity)
                        {
                            WorldCoordinateSystem = context.WorldCoordinateSystem;
                        }
                    }
                }
            }

            // Special read of IfcPresentationLayerAssignment if the INVERSE flag isn't properly set in the EXPRESS file.
            if (IFCImportFile.TheFile.SchemaVersion >= IFCSchemaVersion.IFC2x2)
            {
                IFCPresentationLayerAssignment.ProcessAllLayerAssignments();
            }
        }
            /// <summary>
            /// The constructor.
            /// </summary>
            /// <param name="scope">The associated shape edit scope.</param>
            /// <param name="item">The current styled item.</param>
            public IFCMaterialStack(IFCImportShapeEditScope scope, IFCStyledItem styledItem, IFCPresentationLayerAssignment layerAssignment)
            {
                m_Scope = scope;
                if (styledItem != null)
                    m_MaterialElementId = styledItem.GetMaterialElementId(scope);
                else if (layerAssignment != null)
                    m_MaterialElementId = layerAssignment.GetMaterialElementId(scope);

                if (m_MaterialElementId != ElementId.InvalidElementId)
                    m_Scope.PushMaterialId(m_MaterialElementId);
            }
Example #16
0
        /// <summary>
        /// Processes IfcRepresentation attributes.
        /// </summary>
        /// <param name="ifcRepresentation">The IfcRepresentation handle.</param>
        override protected void Process(IFCAnyHandle ifcRepresentation)
        {
            base.Process(ifcRepresentation);

            IFCAnyHandle representationContext = IFCImportHandleUtil.GetRequiredInstanceAttribute(ifcRepresentation, "ContextOfItems", false);
            if (representationContext != null)
                Context = IFCRepresentationContext.ProcessIFCRepresentationContext(representationContext);

            string identifier = IFCImportHandleUtil.GetOptionalStringAttribute(ifcRepresentation, "RepresentationIdentifier", null);
            Identifier = GetRepresentationIdentifier(identifier, ifcRepresentation);
            
            // Don't read in Box represenation unless options allow it.
            bool isBoundingBox = (Identifier == IFCRepresentationIdentifier.Box);
            if (isBoundingBox && !IFCImportFile.TheFile.Options.ProcessBoundingBoxGeometry)
                throw new InvalidOperationException("BoundingBox not imported with ProcessBoundingBoxGeometry=false");

            Type = IFCImportHandleUtil.GetOptionalStringAttribute(ifcRepresentation, "RepresentationType", null);

            HashSet<IFCAnyHandle> items =
                IFCAnyHandleUtil.GetAggregateInstanceAttribute<HashSet<IFCAnyHandle>>(ifcRepresentation, "Items");

            LayerAssignment = IFCPresentationLayerAssignment.GetTheLayerAssignment(ifcRepresentation);

            foreach (IFCAnyHandle item in items)
            {
                IFCRepresentationItem repItem = null;
                try
                {
                    if (NotAllowedInRepresentation(item))
                    {
                        IFCEntityType entityType = IFCAnyHandleUtil.GetEntityType(item);
                        IFCImportFile.TheLog.LogWarning(item.StepId, "Ignoring unhandled representation item of type " + entityType.ToString() + " in " +
                            Identifier.ToString() + " representation.", true);
                        continue;
                    }

                    // Special processing for bounding boxes - only IfcBoundingBox allowed.
                    if (isBoundingBox)
                    {
                        BoundingBox = ProcessBoundingBox(item);
                        if (BoundingBox != null)
                            break;
                    }
                    else
                        repItem = IFCRepresentationItem.ProcessIFCRepresentationItem(item);
                }
                catch (Exception ex)
                {
                    IFCImportFile.TheLog.LogError(item.StepId, ex.Message, false);
                }
                if (repItem != null)
                    RepresentationItems.Add(repItem);
            }
        }