Beispiel #1
0
        /// <summary>
        /// Gets Description of an IfcProductDefinitionShape handle.
        /// </summary>
        /// <param name="representation">The IfcProductDefinitionShape.</param>
        /// <returns>The Description string.</returns>
        public static string GetProductDefinitionShapeDescription(IFCAnyHandle productDefinitionShape)
        {
            if (productDefinitionShape == null)
            {
                throw new ArgumentNullException("productDefinitionShape");
            }

            if (!productDefinitionShape.HasValue)
            {
                throw new ArgumentException("Invalid handle.");
            }

            if (!IsSubTypeOf(productDefinitionShape, IFCEntityType.IfcProductDefinitionShape))
            {
                throw new ArgumentException("The operation is not valid for this handle.");
            }

            IFCData ifcData = productDefinitionShape.GetAttribute("Description");

            if (ifcData.PrimitiveType == IFCDataPrimitiveType.String)
            {
                return(ifcData.AsString());
            }

            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Gets the object type of a handle.
        /// </summary>
        /// <param name="handle">The handle.</param>
        /// <returns>The object type.</returns>
        public static string GetObjectType(IFCAnyHandle handle)
        {
            if (handle == null)
            {
                throw new ArgumentNullException("handle");
            }

            if (!handle.HasValue)
            {
                throw new ArgumentException("Invalid handle.");
            }

            if (!IsSubTypeOf(handle, IFCEntityType.IfcObject))
            {
                throw new ArgumentException("Not an IfcObject handle.");
            }

            IFCData ifcData = handle.GetAttribute("ObjectType");

            if (ifcData.PrimitiveType == IFCDataPrimitiveType.String)
            {
                return(ifcData.AsString());
            }

            throw new InvalidOperationException("Failed to get object type.");
        }
Beispiel #3
0
        /// <summary>
        /// Gets RepresentationType of a representation handle.
        /// </summary>
        /// <param name="representation">The representation.</param>
        /// <returns>The RepresentationType string.</returns>
        public static string GetRepresentationType(IFCAnyHandle representation)
        {
            if (representation == null)
            {
                throw new ArgumentNullException("representation");
            }

            if (!representation.HasValue)
            {
                throw new ArgumentException("Invalid handle.");
            }

            if (!IsSubTypeOf(representation, IFCEntityType.IfcRepresentation))
            {
                throw new ArgumentException("The operation is not valid for this handle.");
            }

            IFCData ifcData = representation.GetAttribute("RepresentationType");

            if (ifcData.PrimitiveType == IFCDataPrimitiveType.String)
            {
                return(ifcData.AsString());
            }

            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Gets an arbitrary enumeration attribute.
        /// </summary>
        /// <remarks>
        /// This function returns the string value of the enumeration.  It must be then manually
        /// converted to the appropriate enum value by the called.
        /// </remarks>
        /// <param name="name">The handle.</param>
        /// <param name="name">The attribute name.</param>
        /// <returns>The string.</returns>
        public static string GetEnumerationAttribute(IFCAnyHandle hnd, string name)
        {
            if (hnd == null)
            {
                throw new ArgumentNullException("hnd");
            }

            if (!hnd.HasValue)
            {
                throw new ArgumentException("Invalid handle.");
            }

            IFCData ifcData = hnd.GetAttribute(name);

            if (ifcData.PrimitiveType == IFCDataPrimitiveType.Enumeration)
            {
                return(ifcData.AsString());
            }

            return(null);
        }
Beispiel #5
0
        private string UsablePropertyName(IFCAnyHandle propHnd, IDictionary <string, IFCAnyHandle> propertiesByName)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(propHnd))
            {
                return(null);
            }

            string currPropertyName = IFCAnyHandleUtil.GetStringAttribute(propHnd, "Name");

            if (string.IsNullOrWhiteSpace(currPropertyName))
            {
                return(null); // This shouldn't be posssible.
            }
            // Don't override if the new value is empty.
            if (propertiesByName.ContainsKey(currPropertyName))
            {
                try
                {
                    // Only IfcSimplePropertyValue has the NominalValue attribute; any other type of property will throw.
                    IFCData currPropertyValue = propHnd.GetAttribute("NominalValue");
                    if (currPropertyValue.PrimitiveType == IFCDataPrimitiveType.String && string.IsNullOrWhiteSpace(currPropertyValue.AsString()))
                    {
                        return(null);
                    }
                }
                catch
                {
                    // Not an IfcSimplePropertyValue - no need to verify.
                }
            }

            return(currPropertyName);
        }