Beispiel #1
0
        override protected void Process(IFCAnyHandle item)
        {
            base.Process(item);

            string surfaceSideAsString = IFCAnyHandleUtil.GetEnumerationAttribute(item, "Side");

            if (surfaceSideAsString == null)
            {
                SurfaceSide = IFCSurfaceSide.Both;
                IFCImportFile.TheLog.LogWarning(item.StepId, "No surface side defined, defaulting to Both.", false);
            }
            else
            {
                SurfaceSide = (IFCSurfaceSide)Enum.Parse(typeof(IFCSurfaceSide), surfaceSideAsString, true);
            }

            HashSet <IFCAnyHandle> styles = IFCAnyHandleUtil.GetAggregateInstanceAttribute <HashSet <IFCAnyHandle> >(item, "Styles");

            if (styles == null || styles.Count == 0)
            {
                IFCImportFile.TheLog.LogError(item.StepId, "No style information found, ignoring.", true);
            }

            foreach (IFCAnyHandle style in styles)
            {
                try
                {
                    if (IFCAnyHandleUtil.IsSubTypeOf(style, IFCEntityType.IfcSurfaceStyleShading))
                    {
                        if (ShadingStyle == null)
                        {
                            ShadingStyle = IFCSurfaceStyleShading.ProcessIFCSurfaceStyleShading(style);
                        }
                        else
                        {
                            IFCImportFile.TheLog.LogWarning(item.StepId, "Duplicate IfcSurfaceStyleShading, ignoring.", false);
                        }
                    }
                    else
                    {
                        IFCImportFile.TheLog.LogUnhandledSubTypeError(style, "IfcSurfaceStyleElementSelect", false);
                    }
                }
                catch (Exception ex)
                {
                    IFCImportFile.TheLog.LogError(style.StepId, ex.Message, false);
                }
            }
        }
        /// <summary>
        /// Processes an IfcSurfaceStyleShading entity handle.
        /// </summary>
        /// <param name="ifcSurfaceStyleShading">The IfcSurfaceStyleShading handle.</param>
        /// <returns>The IFCSurfaceStyleShading object.</returns>
        public static IFCSurfaceStyleShading ProcessIFCSurfaceStyleShading(IFCAnyHandle ifcSurfaceStyleShading)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(ifcSurfaceStyleShading))
            {
                Importer.TheLog.LogNullError(IFCEntityType.IfcSurfaceStyleShading);
                return(null);
            }

            IFCEntity surfaceStyleShading;

            if (!IFCImportFile.TheFile.EntityMap.TryGetValue(ifcSurfaceStyleShading.StepId, out surfaceStyleShading))
            {
                surfaceStyleShading = new IFCSurfaceStyleShading(ifcSurfaceStyleShading);
            }
            return(surfaceStyleShading as IFCSurfaceStyleShading);
        }
        override protected void Process(IFCAnyHandle item)
        {
            base.Process(item);

            SurfaceSide = IFCEnums.GetSafeEnumerationAttribute <IFCSurfaceSide>(item, "Side", IFCSurfaceSide.Both);

            HashSet <IFCAnyHandle> styles = IFCAnyHandleUtil.GetAggregateInstanceAttribute <HashSet <IFCAnyHandle> >(item, "Styles");

            if (styles == null || styles.Count == 0)
            {
                Importer.TheLog.LogError(item.StepId, "No style information found, ignoring.", true);
            }

            foreach (IFCAnyHandle style in styles)
            {
                try
                {
                    if (IFCAnyHandleUtil.IsSubTypeOf(style, IFCEntityType.IfcSurfaceStyleShading))
                    {
                        if (ShadingStyle == null)
                        {
                            ShadingStyle = IFCSurfaceStyleShading.ProcessIFCSurfaceStyleShading(style);
                        }
                        else
                        {
                            Importer.TheLog.LogWarning(item.StepId, "Duplicate IfcSurfaceStyleShading, ignoring.", false);
                        }
                    }
                    else
                    {
                        Importer.TheLog.LogUnhandledSubTypeError(style, "IfcSurfaceStyleElementSelect", false);
                    }
                }
                catch (Exception ex)
                {
                    Importer.TheLog.LogError(style.StepId, ex.Message, false);
                }
            }
        }
        /// <summary>
        /// Create the material associated to the element, and return the id.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="forcedName">An optional name that sets the name of the material created, regardless of surface style name.</param>
        /// <param name="suggestedName">An optional name that suggests the name of the material created, if the surface style name is null.</param>
        /// <param name="idOverride">The id of the parent item, used if forcedName is used.</param>
        /// <returns>The material id.</returns>
        /// <remarks>If forcedName is not null, this will not store the created element id in this class.</remarks>
        public ElementId Create(Document doc, string forcedName, string suggestedName, int idOverride)
        {
            try
            {
                bool overrideName = (forcedName != null) && (string.Compare(forcedName, Name) != 0);
                if (!overrideName && m_CreatedElementId != ElementId.InvalidElementId)
                {
                    return(m_CreatedElementId);
                }

                string name = overrideName ? forcedName : Name;
                if (string.IsNullOrEmpty(name))
                {
                    if (!string.IsNullOrEmpty(suggestedName))
                    {
                        name = suggestedName;
                    }
                    else
                    {
                        name = "IFC Surface Style";
                    }
                }
                int id = overrideName ? idOverride : Id;

                if (IsValidForCreation)
                {
                    Color color        = null;
                    int?  transparency = null;
                    int?  shininess    = null;
                    int?  smoothness   = null;

                    IFCSurfaceStyleShading shading = ShadingStyle;
                    if (shading != null)
                    {
                        color        = shading.GetSurfaceColor();
                        transparency = (int)(shading.Transparency * 100 + 0.5);
                        shininess    = shading.GetShininess();
                        smoothness   = shading.GetSmoothness();
                    }

                    IFCMaterialInfo materialInfo =
                        IFCMaterialInfo.Create(color, transparency, shininess, smoothness, ElementId.InvalidElementId);
                    ElementId createdElementId = IFCMaterial.CreateMaterialElem(doc, id, name, materialInfo);
                    if (!overrideName)
                    {
                        m_CreatedElementId = createdElementId;
                    }
                    return(createdElementId);
                }
                else
                {
                    IsValidForCreation = false;
                }
            }
            catch (Exception ex)
            {
                IsValidForCreation = false;
                Importer.TheLog.LogCreationError(this, ex.Message, false);
            }

            return(ElementId.InvalidElementId);
        }
        /// <summary>
        /// Processes an IfcSurfaceStyleShading entity handle.
        /// </summary>
        /// <param name="ifcSurfaceStyleShading">The IfcSurfaceStyleShading handle.</param>
        /// <returns>The IFCSurfaceStyleShading object.</returns>
        public static IFCSurfaceStyleShading ProcessIFCSurfaceStyleShading(IFCAnyHandle ifcSurfaceStyleShading)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(ifcSurfaceStyleShading))
            {
                IFCImportFile.TheLog.LogNullError(IFCEntityType.IfcSurfaceStyleShading);
                return null;
            }

            IFCEntity surfaceStyleShading;
            if (!IFCImportFile.TheFile.EntityMap.TryGetValue(ifcSurfaceStyleShading.StepId, out surfaceStyleShading))
                surfaceStyleShading = new IFCSurfaceStyleShading(ifcSurfaceStyleShading);
            return (surfaceStyleShading as IFCSurfaceStyleShading);
        }