Example #1
0
        /// <summary>
        /// Processes an IfcObjectDefinition object.
        /// </summary>
        /// <param name="ifcObjectDefinition">The IfcObjectDefinition handle.</param>
        /// <returns>The IFCObjectDefinition object.</returns>
        public static IFCObjectDefinition ProcessIFCObjectDefinition(IFCAnyHandle ifcObjectDefinition)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(ifcObjectDefinition))
            {
                IFCImportFile.TheLog.LogNullError(IFCEntityType.IfcObjectDefinition);
                return(null);
            }

            IFCEntity cachedObjectDefinition;

            if (IFCImportFile.TheFile.EntityMap.TryGetValue(ifcObjectDefinition.StepId, out cachedObjectDefinition))
            {
                return(cachedObjectDefinition as IFCObjectDefinition);
            }

            try
            {
                if (IFCAnyHandleUtil.IsSubTypeOf(ifcObjectDefinition, IFCEntityType.IfcObject))
                {
                    return(IFCObject.ProcessIFCObject(ifcObjectDefinition));
                }
            }
            catch (Exception ex)
            {
                if (ex.Message == "Don't Import")
                {
                    return(null);
                }
            }


            IFCImportFile.TheLog.LogUnhandledSubTypeError(ifcObjectDefinition, IFCEntityType.IfcObjectDefinition, false);
            return(null);
        }
Example #2
0
        /// <summary>
        /// Gets the one material associated with this object.
        /// </summary>
        /// <returns>The material, if there is identically one; otherwise, null.</returns>
        public IFCMaterial GetTheMaterial()
        {
            if (!m_TheMaterialIsSet)
            {
                IList <IFCMaterial> materials = GetMaterials();

                m_TheMaterialIsSet = true;
                IFCMaterial theMaterial = null;
                if (materials.Count > 1)
                {
                    return(null);
                }

                if (materials.Count == 1)
                {
                    theMaterial = materials[0];
                }

                if (this is IFCObject)
                {
                    IFCObject asObject = this as IFCObject;
                    foreach (IFCTypeObject typeObject in asObject.TypeObjects)
                    {
                        IList <IFCMaterial> typeMaterials = typeObject.GetMaterials();

                        if (typeMaterials.Count > 1)
                        {
                            return(null);
                        }

                        if (typeMaterials.Count == 1)
                        {
                            if (theMaterial != null && theMaterial.Id != typeMaterials[0].Id)
                            {
                                return(null);
                            }
                            theMaterial = typeMaterials[0];
                        }
                    }
                }

                m_TheMaterial = theMaterial;
            }

            return(m_TheMaterial);
        }
Example #3
0
        /// <summary>
        /// Create one or more elements
        /// </summary>
        /// <param name="doc">The document being populated.</param>
        /// <returns>The primary element associated with the IFCObjectDefinition, or InvalidElementId if it failed.</returns>
        public static ElementId CreateElement(Document doc, IFCObjectDefinition objDef)
        {
            // This would be a good place to check 'objDef.GlobalId'.

            ElementId createdElementId = objDef.CreatedElementId;

            try
            {
                if ((createdElementId == ElementId.InvalidElementId) && objDef.IsValidForCreation)
                {
                    ElementId gstyleId;
                    objDef.CategoryId        = IFCCategoryUtil.GetCategoryIdForEntity(doc, objDef, out gstyleId);
                    objDef.m_GraphicsStyleId = gstyleId;

                    if (objDef is IFCObject)
                    {
                        IFCObject asObject = objDef as IFCObject;
                        foreach (IFCTypeObject typeObject in asObject.TypeObjects)
                        {
                            IFCObjectDefinition.CreateElement(doc, typeObject);
                        }
                    }

                    objDef.Create(doc);
                    objDef.CreateParameters(doc);
                    createdElementId = objDef.CreatedElementId;
                    IFCImportFile.TheLog.AddCreatedEntity(doc, objDef);

                    if (IFCImportFile.CleanEntitiesAfterCreate)
                    {
                        objDef.CleanEntity();
                    }
                }
            }
            catch (Exception ex)
            {
                if (objDef != null)
                {
                    objDef.IsValidForCreation = false;
                    IFCImportFile.TheLog.LogCreationError(objDef, ex.Message, false);
                }
            }
            return(createdElementId);
        }