Ejemplo n.º 1
0
        /// <summary>
        /// Checks if the handle is a sub-type of a particular type.
        /// </summary>
        /// <param name="handle">The handle.</param>
        /// <param name="type">The type.</param>
        /// <returns>True if the handle is exactly of the specified type.</returns>
        public static bool IsSubTypeOf(IFCAnyHandle handle, IFCEntityType type)
        {
            if (IsNullOrHasNoValue(handle))
            {
                return(false);
            }
            IFCEntityType subType;
            bool          val;

            if (ExporterCacheManager.HandleTypeCache.TryGetValue(handle, out subType))
            {
                if (subType == type)
                {
                    return(true);
                }
                KeyValuePair <IFCEntityType, IFCEntityType> subTypeToTypeEntry = new KeyValuePair <IFCEntityType, IFCEntityType>(subType, type);
                if (ExporterCacheManager.HandleIsSubTypeOfCache.TryGetValue(subTypeToTypeEntry, out val))
                {
                    return(val);
                }
                val = handle.IsSubTypeOf(type.ToString());
                ExporterCacheManager.HandleIsSubTypeOfCache[subTypeToTypeEntry] = val;
            }
            else
            {
                val = handle.IsSubTypeOf(type.ToString());
            }

            return(val);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Identifies if the input handle matches the object type only to which this description applies.
        /// </summary>
        /// <param name="handle">
        /// The handle.
        /// </param>
        /// <returns>
        /// True if it matches, false otherwise.
        /// </returns>
        public bool IsAppropriateObjectType(IFCAnyHandle handle)
        {
            if (handle == null)
            {
                return(false);
            }
            if (ObjectType == "")
            {
                return(true);
            }

            // ObjectType information comes from PSD's Applicable Type. This may be a comma separated list of applicable type
            //string objectType = IFCAnyHandleUtil.GetObjectType(handle);
            IFCEntityType hndEntity = IFCAnyHandleUtil.GetEntityType(handle);

            if (ObjectType.IndexOf(hndEntity.ToString(), StringComparison.InvariantCultureIgnoreCase) < 0)
            {
                return(false);
            }
            else
            {
                return(true);
            }
            //return (NamingUtil.IsEqualIgnoringCaseAndSpaces(ObjectType, objectType));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a custom sub-category name for an entity.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns>The category name.</returns>
        /// <remarks>This will also be used to populate the IfcExportAs parameter.</remarks>
        public static string GetCustomCategoryName(IFCObjectDefinition entity)
        {
            IFCEntityType entityType = entity.EntityType;
            string        shapeType  = entity.ShapeType;

            IFCEntityType?typeEntityType = null;
            string        typeShapeType  = null;

            GetAssociatedTypeEntityInfo(entity, out typeEntityType, out typeShapeType);

            if (typeEntityType.HasValue)
            {
                entityType = typeEntityType.Value;
            }
            if (string.IsNullOrWhiteSpace(shapeType) && !string.IsNullOrWhiteSpace(typeShapeType))
            {
                shapeType = typeShapeType;
            }

            string categoryName = entityType.ToString();

            if (!string.IsNullOrWhiteSpace(shapeType))
            {
                categoryName += "." + shapeType;
            }
            return(categoryName);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create a DirectShape, and set its options accordingly.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="categoryId">The category of the DirectShape.</param>
        /// <param name="dataGUID">The GUID of the data creating the DirectShape.</param>
        /// <param name="geomObjs">The list of geometries to add to the DirectShape.</param>
        /// <param name="id">The id of the IFCEntity object creating the DirectShape.</param>
        /// <returns>The DirectShape.</returns>
        static public DirectShape CreateElement(Document doc, ElementId categoryId, string dataGUID, IList <GeometryObject> geomObjs, int id, IFCEntityType entityType)
        {
            string      appGUID     = Importer.ImportAppGUID();
            DirectShape directShape = DirectShape.CreateElement(doc, GetDSValidCategoryId(doc, categoryId, id));

            directShape.ApplicationId     = appGUID;
            directShape.ApplicationDataId = dataGUID;

            // Note: we use the standard options for the DirectShape that is created.  This includes but is not limited to:
            // Referenceable: true.
            // Room Bounding: if applicable, user settable.

            if (IFCImportFile.TheFile.Options.UseStreamlinedOptions)
            {
                // Disable referencing for performance purposes.
                DirectShapeOptions options = directShape.GetOptions();
                options.ReferencingOption = DirectShapeReferencingOption.NotReferenceable;
                directShape.SetOptions(options);
            }

            // This is used in some places to create something not related to an IFCEntity
            if (!Importer.TheProcessor.CreateOrUpdateElement(id, dataGUID, entityType.ToString(),
                                                             categoryId.IntegerValue, geomObjs))
            {
                if (geomObjs != null)
                {
                    directShape?.SetShape(geomObjs);
                }
            }

            return(directShape);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Generates IFC GUID from an IFC entity type and a string unique to this project.
        /// </summary>
        /// <param name="type">The ifc entity type.</param>
        /// <param name="uniqueKey">The key unique to this project.</param>
        /// <returns>String in IFC GUID format. Uniqueness is highly likely, but not guaranteed even
        /// if input string is unique.</returns>
        public static string GenerateProjectIFCGuidFrom(IFCEntityType type, string uniqueKey)
        {
            string guidString = ExporterUtil.GetGlobalId(ExporterCacheManager.ProjectHandle) +
                                type.ToString() + ":" + uniqueKey;

            return(GenerateIFCGuidFrom(guidString));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Add an error message to the log file indicating an incorrect type.
 /// </summary>
 /// <param name="handle">The unhandled entity handle.</param>
 /// <param name="expectedType">The expected base type of the handle.</param>
 /// <param name="throwError">throw an InvalidOperationException if true.</param>
 public void LogUnexpectedTypeError(IFCAnyHandle handle, IFCEntityType expectedType, bool throwError)
 {
     if (LoggingEnabled && m_LogFile != null)
     {
         LogError(handle.StepId, "Expected handle of type " + expectedType.ToString() + ", found: " + IFCAnyHandleUtil.GetEntityType(handle).ToString(), throwError);
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Add an error message to the log file indicating a missing handle of an expected type.
 /// </summary>
 /// <param name="expectedType">The expected type of the handle.</param>
 public void LogNullError(IFCEntityType expectedType)
 {
     if (LoggingEnabled && m_LogFile != null)
     {
         WriteLine("ERROR: " + expectedType.ToString() + " is null or has no value.");
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Generates IFC GUID from an IFC entity type and a collection of handles.
        /// </summary>
        /// <param name="type">The ifc entity type.</param>
        /// <param name="handle">The primary handle.</param>
        /// <param name="relatedHandles">A collection of handles related to the primary handle.</param>
        /// <returns>String in IFC GUID format. Uniqueness is highly likely, but not guaranteed even
        /// if input string is unique.</returns>
        public static string GenerateIFCGuidFrom(IFCEntityType type, IFCAnyHandle firstHandle,
                                                 IFCAnyHandle secondHandle)
        {
            string guidString = type.ToString() + ":" + ExporterUtil.GetGlobalId(firstHandle) +
                                ExporterUtil.GetGlobalId(secondHandle);

            return(GenerateIFCGuidFrom(guidString));
        }
Ejemplo n.º 9
0
        // Check valid entity and type set according to the MVD used in the export
        // Also check and correct older standardcase entities and change it without StandardCase for IFC4 and onward
        void CheckValidEntity()
        {
            IFCCertifiedEntitiesAndPSets certEntAndPset = ExporterCacheManager.CertifiedEntitiesAndPsetsCache;

            // Special handling for *StandardCase entities that are not used anymore in IFC4
            if (!ExporterCacheManager.ExportOptionsCache.ExportAsOlderThanIFC4)
            {
                if (m_ExportInstance.ToString().EndsWith("StandardCase", StringComparison.InvariantCultureIgnoreCase))
                {
                    string newInstanceName = m_ExportInstance.ToString().Remove(m_ExportInstance.ToString().Length - 12);

                    // Special handling for IfcOpeningStandardCase to turn it to IfcOpeningElement
                    if (newInstanceName.Equals("IfcOpening", StringComparison.InvariantCultureIgnoreCase))
                    {
                        newInstanceName = newInstanceName + "Element";
                    }

                    IFCEntityType newInst;
                    if (Enum.TryParse <IFCEntityType>(newInstanceName, true, out newInst))
                    {
                        //m_ExportInstance = newInst;
                        SetValueWithPair(newInst);
                    }
                }
                else if (m_ExportInstance.ToString().EndsWith("ElementedCase", StringComparison.InvariantCultureIgnoreCase))
                {
                    string        newInstanceName = m_ExportInstance.ToString().Remove(m_ExportInstance.ToString().Length - 13);
                    IFCEntityType newInst;
                    if (Enum.TryParse <IFCEntityType>(newInstanceName, true, out newInst))
                    {
                        SetValueWithPair(newInst);
                    }
                }
            }

            if (!certEntAndPset.IsValidEntityInCurrentMVD(m_ExportType.ToString()))
            {
                m_ExportType = IFCEntityType.UnKnown;
            }

            if (!certEntAndPset.IsValidEntityInCurrentMVD(m_ExportInstance.ToString()))
            {
                m_ExportInstance = IFCEntityType.UnKnown;
            }

            // IfcProxy is deprecated, we will change it to IfcBuildingElementProxy
            if (m_ExportInstance == IFCEntityType.IfcProxy && !ExporterCacheManager.ExportOptionsCache.ExportAsOlderThanIFC4)
            {
                m_ExportInstance = IFCEntityType.IfcBuildingElementProxy;
                m_ExportType     = IFCEntityType.IfcBuildingElementProxyType;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Create a DirectShapeType.
        /// </summary>
        /// <param name="doc">The document.</param>
        /// <param name="name">The name of the DirectShapeType.</param>
        /// <param name="categoryId">The category of the DirectShape.</param>
        /// <param name="id">The id of the IFCEntity object creating the DirectShape.</param>
        /// <param name="guid">The guid of the IFCEntity object creating the DirectShape.</param>
        /// <returns>The DirectShape.</returns>
        static public DirectShapeType CreateElementType(Document doc, string name, ElementId categoryId, int id, string guid, IFCEntityType entityType)
        {
            DirectShapeTypeOptions options = new DirectShapeTypeOptions();

            options.AllowDuplicateNames = true;
            ElementId       validCategoryId = IFCElementUtil.GetDSValidCategoryId(doc, categoryId, id);
            DirectShapeType directShapeType = DirectShapeType.Create(doc, name, validCategoryId, options);

            Importer.TheCache.CreatedDirectShapeTypes[id] = directShapeType.Id;

            Importer.TheProcessor.CreateElementType(id, guid, entityType.ToString(), validCategoryId.IntegerValue);

            return(directShapeType);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Checks if the handle is of a particular type.
        /// </summary>
        /// <param name="handle">The handle.</param>
        /// <param name="type">The type.</param>
        /// <returns>True if the handle is exactly of the specified type.</returns>
        public static bool IsTypeOf(IFCAnyHandle handle, IFCEntityType type)
        {
            if (IsNullOrHasNoValue(handle))
            {
                return(false);
            }
            IFCEntityType compareType;

            if (ExporterCacheManager.HandleTypeCache.TryGetValue(handle, out compareType))
            {
                return(compareType == type);
            }
            return(handle.IsTypeOf(type.ToString()));
        }
Ejemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="handle"></param>
        /// <returns></returns>
        public bool IsSubTypeOfEntityTypes(IFCEntityType ifcEntityType)
        {
            var ifcEntitySchemaTree = IfcSchemaEntityTree.GetEntityDictFor(ExporterCacheManager.ExportOptionsCache.FileVersion);

            if (ifcEntitySchemaTree == null || ifcEntitySchemaTree.Count == 0)
            {
                return(false);
            }

            // Note that although EntityTypes is represented as a set, we still need to go through each item in the last to check for subtypes.
            foreach (IFCEntityType entityType in EntityTypes)
            {
                if (IfcSchemaEntityTree.IsSubTypeOf(ifcEntityType.ToString(), entityType.ToString(), strict: false))
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Identifies if the input handle matches the object type only to which this description applies.
        /// </summary>
        /// <param name="handle">
        /// The handle.
        /// </param>
        /// <returns>
        /// True if it matches, false otherwise.
        /// </returns>
        public bool IsAppropriateObjectType(IFCAnyHandle handle)
        {
            if (handle == null)
            {
                return(false);
            }
            //if (ObjectType == "")
            //   return true;

            // ObjectType information comes from PSD's Applicable Type. This may be a comma separated list of applicable type
            IFCEntityType hndEntity = IFCAnyHandleUtil.GetEntityType(handle);

            if (ObjectType.IndexOf(hndEntity.ToString(), StringComparison.InvariantCultureIgnoreCase) < 0)
            {
                // The use of ObjectType in the PSD is confusing at best. The purpose and its consistency is questionable.
                // If the entity is not found in this ObjectType, try the "old" way to compare the ObjectType attribute value
                string objectType = IFCAnyHandleUtil.GetObjectType(handle);
                if (!string.IsNullOrEmpty(objectType))
                {
                    if (ObjectType.IndexOf(objectType, StringComparison.InvariantCultureIgnoreCase) < 0)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                return(false);
            }
            else
            {
                return(true);
            }
            //return (NamingUtil.IsEqualIgnoringCaseAndSpaces(ObjectType, objectType));
        }
      /// <summary>
      /// Creation of Generic IFC object, mainly used for MEP Objects as most of MEP objects are identical
      /// </summary>
      /// <param name="entityToCreate">The specific Entity (Enum) to create</param>
      /// <param name="file">The IFC file</param>
      /// <param name="guid">GUID</param>
      /// <param name="ownerHistory">Owner History</param>
      /// <param name="name">Name attribute</param>
      /// <param name="description">Description</param>
      /// <param name="objectType">ObjectType attribute</param>
      /// <param name="objectPlacement">Placement</param>
      /// <param name="representation">Geometry representation</param>
      /// <param name="elementTag">Element Tag attribue</param>
      /// <returns></returns>
      public static IFCAnyHandle CreateGenericIFCEntity(IFCEntityType entityToCreate, IFCFile file, string guid, IFCAnyHandle ownerHistory, string name,
           string description, string objectType, IFCAnyHandle objectPlacement, IFCAnyHandle representation,
           string elementTag)
      {
         ValidateElement(guid, ownerHistory, name, description, objectType, objectPlacement, representation, elementTag);

         IFCAnyHandle genericIFCEntity;

         if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
         {
            genericIFCEntity = CreateInstance(file, entityToCreate);
            SetElement(genericIFCEntity, guid, ownerHistory, name, description, objectType, objectPlacement, representation,
                elementTag);
         }
         else
         {
            // check for valid IFC2x- entity type
            Revit.IFC.Common.Enums.IFC2x.IFCEntityType IFC2xValidTypeEnum;
            if (!Enum.TryParse(entityToCreate.ToString(), true, out IFC2xValidTypeEnum))
            {
               IFCEntityType actualEntity;
               if (IFCCompatibilityType.checkCompatibleType(entityToCreate, out actualEntity))
               {
                  genericIFCEntity = CreateInstance(file, actualEntity);
                  SetElement(genericIFCEntity, guid, ownerHistory, name, description, objectType, objectPlacement, representation,
                      elementTag);
                  return genericIFCEntity;
               }
               else
               {
                  // compatible type not found and it is not a valid 2x- entity type, create proxy
                  genericIFCEntity = CreateInstance(file, IFCEntityType.IfcBuildingElementProxy);
                  SetElement(genericIFCEntity, guid, ownerHistory, name, description, objectType, objectPlacement, representation,
                    elementTag);
               }
            }
            else
            {
               // valid 2x- entity
               genericIFCEntity = CreateInstance(file, entityToCreate);
               SetElement(genericIFCEntity, guid, ownerHistory, name, description, objectType, objectPlacement, representation,
                   elementTag);
            }
         }

         return genericIFCEntity;
      }
      /// <summary>
      /// This is a generic create method for all IFC Type Objects, mainly for MEP objects
      /// </summary>
      /// <param name="typeEntityToCreate">Type entity to create</param>
      /// <param name="file">The IFC file</param>
      /// <param name="guid">GUID</param>
      /// <param name="ownerHistory">Owner History</param>
      /// <param name="name">name attribute</param>
      /// <param name="description">Description</param>
      /// <param name="applicableOccurrence">Applicable Occurence attribute</param>
      /// <param name="propertySets">Preperty Sets</param>
      /// <param name="representationMaps">RepresentationMap for geometry</param>
      /// <param name="elementTag">Element Tag</param>
      /// <param name="elementType">Element Type</param>
      /// <param name="predefinedType">preDefinedType</param>
      /// <returns></returns>
      public static IFCAnyHandle CreateGenericIFCType(IFCEntityType typeEntityToCreate, IFCFile file, string guid, IFCAnyHandle ownerHistory, string name,
          string description, string applicableOccurrence, HashSet<IFCAnyHandle> propertySets,
          IList<IFCAnyHandle> representationMaps, string elementTag, string elementType, string predefinedType)
      {
         ValidateElementType(guid, ownerHistory, name, description, applicableOccurrence, propertySets,
             representationMaps, elementTag, elementType);

         if (ExporterCacheManager.ExportOptionsCache.ExportAs4)
         {
            Revit.IFC.Common.Enums.IFC4.IFCEntityType IFC4ValidTypeEnum;
            // check existence of the entity in IFC4
            if (Enum.TryParse(typeEntityToCreate.ToString(), true, out IFC4ValidTypeEnum))
            {
               IFCAnyHandle genericIFCType = CreateInstance(file, typeEntityToCreate);

               IFCAnyHandleUtil.SetAttribute(genericIFCType, "PredefinedType", predefinedType, true);
               SetElementType(genericIFCType, guid, ownerHistory, name, description, applicableOccurrence, propertySets,
                   representationMaps, elementTag, elementType);
               return genericIFCType;
            }
         }
         else
         {
            Revit.IFC.Common.Enums.IFC2x.IFCEntityType IFC2xValidTypeEnum;
            // check existence of the entity in IFC2x-
            if (Enum.TryParse(typeEntityToCreate.ToString(), true, out IFC2xValidTypeEnum))
            {
               // Special IFC2x2 checks to avoid creating a completely new enum.
               if (ExporterCacheManager.ExportOptionsCache.ExportAs2x2)
               {
                  // Not supported: IfcBuildingElementProxyType in IFC2x2.
                  if (typeEntityToCreate == IFCEntityType.IfcBuildingElementProxyType)
                     return null;
               }

               IFCAnyHandle genericMEPType = CreateInstance(file, typeEntityToCreate);

               IFCAnyHandleUtil.SetAttribute(genericMEPType, "PredefinedType", predefinedType, true);
               SetElementType(genericMEPType, guid, ownerHistory, name, description, applicableOccurrence, propertySets,
                   representationMaps, elementTag, elementType);
               return genericMEPType;
            }
         }
         return null;    //type is unknown in both IFC4 and prior to IFC4
      }
Ejemplo n.º 16
0
 /// <summary>
 /// Generates IFC GUID from an IFC entity type and a handle.
 /// </summary>
 /// <param name="type">The IFC entity type.</param>
 /// <param name="handle">The primary handle.</param>
 /// <returns>String in IFC GUID format. Uniqueness is highly likely, but not guaranteed even
 /// if input string is unique.</returns>
 public static string GenerateIFCGuidFrom(IFCEntityType type, IFCAnyHandle handle)
 {
     return(GenerateIFCGuidFrom(type.ToString() + ":" + ExporterUtil.GetGlobalId(handle)));
 }
Ejemplo n.º 17
0
 /// <summary>
 /// To check whether a specified IFC Entity is listed in the Exclude Filter (from configuration)
 /// </summary>
 /// <param name="entity">IFCEntityType enumeration representing the IFC entity concerned</param>
 /// <returns>true if the entity found in the set</returns>
 public bool IsElementInExcludeList(IFCEntityType entity)
 {
     return(ExcludeElementSet.Contains(entity.ToString()));
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Set the pair information using only either the entity or the type
 /// </summary>
 /// <param name="entityType">the entity or type</param>
 /// <param name="predefineType">predefinedtype string</param>
 public void SetValueWithPair(IFCEntityType entityType, string predefineType = null)
 {
     SetValueWithPair(entityType.ToString(), predefineType);
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Add an error message to the log file indicating a missing handle of an expected type.
 /// </summary>
 /// <param name="expectedType">The expected type of the handle.</param>
 public void LogNullError(IFCEntityType expectedType)
 {
    WriteLine("ERROR: " + expectedType.ToString() + " is null or has no value.");
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Initialize the class with the entity and the type
        /// </summary>
        /// <param name="instance">the entity</param>
        /// <param name="type">the type</param>
        public IFCExportInfoPair(IFCEntityType instance, IFCEntityType type, string predefinedType)
        {
            instance       = ElementFilteringUtil.GetValidIFCEntityType(instance);
            ExportInstance = instance;

            type       = ElementFilteringUtil.GetValidIFCEntityType(type);
            ExportType = type;

            if (!string.IsNullOrEmpty(predefinedType))
            {
                ValidatedPredefinedType = IFCValidateEntry.GetValidIFCPredefinedTypeType(predefinedType, null, ExportInstance.ToString());
                if (string.IsNullOrEmpty(ValidatedPredefinedType))
                {
                    ValidatedPredefinedType = IFCValidateEntry.GetValidIFCPredefinedTypeType(predefinedType, "NOTDEFINED", ExportType.ToString());
                }
            }
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Add an error message to the log file indicating an unhandled subtype of a known type.
 /// </summary>
 /// <param name="handle">The unhandled entity handle.</param>
 /// <param name="mainType">The base type of the handle.</param>
 /// <param name="throwError">throw an InvalidOperationException if true.</param>
 public void LogUnhandledSubTypeError(IFCAnyHandle handle, IFCEntityType mainType, bool throwError)
 {
    LogUnhandledSubTypeErrorBase(handle, mainType.ToString(), throwError);
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Check whether an entity is a subtype of another entity
 /// </summary>
 /// <param name="subTypeName">candidate of the subtype entity</param>
 /// <param name="superTypeName">candidate of the supertype entity</param>
 /// <returns>true: if the the subTypeName is the subtype of supertTypeName</returns>
 static public bool IsSubTypeOf(IFCVersion ifcVersion, IFCEntityType subType, IFCEntityType superType, bool strict = true)
 {
     return(IsSubTypeOf(ifcVersion, subType.ToString(), superType.ToString(), strict));
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Set the pair information using only either the entity or the type
        /// </summary>
        /// <param name="entityType">the entity or type</param>
        public void SetValueWithPair(IFCEntityType entityType)
        {
            string entityTypeStr = entityType.ToString();
            bool   isType        = entityTypeStr.Substring(entityTypeStr.Length - 4, 4).Equals("Type", StringComparison.CurrentCultureIgnoreCase);

            if (isType)
            {
                // Get the instance
                string instName          = entityTypeStr.Substring(0, entityTypeStr.Length - 4);
                IfcSchemaEntityNode node = IfcSchemaEntityTree.Find(instName);
                if (node != null && !node.isAbstract)
                {
                    IFCEntityType instType = IFCEntityType.UnKnown;
                    if (IFCEntityType.TryParse(instName, out instType))
                    {
                        ExportInstance = instType;
                    }
                }
                // If not found, try non-abstract supertype derived from the type
                node = IfcSchemaEntityTree.FindNonAbsInstanceSuperType(instName);
                if (node != null)
                {
                    IFCEntityType instType = IFCEntityType.UnKnown;
                    if (IFCEntityType.TryParse(node.Name, out instType))
                    {
                        ExportInstance = instType;
                    }
                }

                // set the type
                entityType = ElementFilteringUtil.GetValidIFCEntityType(entityType);
                if (entityType != IFCEntityType.UnKnown)
                {
                    ExportType = entityType;
                }
                else
                {
                    node = IfcSchemaEntityTree.FindNonAbsInstanceSuperType(entityTypeStr);
                    if (node != null)
                    {
                        IFCEntityType instType = IFCEntityType.UnKnown;
                        if (IFCEntityType.TryParse(node.Name, out instType))
                        {
                            ExportType = instType;
                        }
                    }
                }
            }
            else
            {
                // set the instance
                entityType = ElementFilteringUtil.GetValidIFCEntityType(entityType);
                if (entityType != IFCEntityType.UnKnown)
                {
                    ExportInstance = entityType;
                }
                else
                {
                    // If not found, try non-abstract supertype derived from the type
                    IfcSchemaEntityNode node = IfcSchemaEntityTree.FindNonAbsInstanceSuperType(entityTypeStr);
                    if (node != null)
                    {
                        IFCEntityType instType = IFCEntityType.UnKnown;
                        if (IFCEntityType.TryParse(node.Name, out instType))
                        {
                            ExportInstance = instType;
                        }
                    }
                }

                // set the type pair
                string typeName = entityType.ToString() + "Type";
                entityType = ElementFilteringUtil.GetValidIFCEntityType(typeName);
                if (entityType != IFCEntityType.UnKnown)
                {
                    ExportType = entityType;
                }
                else
                {
                    IfcSchemaEntityNode node = IfcSchemaEntityTree.FindNonAbsInstanceSuperType(typeName);
                    if (node != null)
                    {
                        IFCEntityType instType = IFCEntityType.UnKnown;
                        if (IFCEntityType.TryParse(node.Name, out instType))
                        {
                            ExportType = instType;
                        }
                    }
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Get the top-level Built-in category id for an IFC entity.
        /// </summary>
        /// <param name="doc">The doument.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="gstyleId">The graphics style, if the returned category is not top level.  This allows shapes to have their visibility controlled by the sub-category.</param>
        /// <returns>The element id for the built-in category.</returns>
        public static ElementId GetCategoryIdForEntity(Document doc, IFCObjectDefinition entity, out ElementId gstyleId)
        {
            gstyleId = ElementId.InvalidElementId;

            IFCEntityType entityType = entity.EntityType;

            IFCEntityType?typeEntityType = null;
            string        typeShapeType  = null;

            GetAssociatedTypeEntityInfo(entity, out typeEntityType, out typeShapeType);

            // Use the IfcTypeObject shape type if the IfcElement shape type is either null, empty, white space, or not defined.
            string shapeType = entity.ShapeType;

            if ((string.IsNullOrWhiteSpace(shapeType) || (string.Compare(shapeType, "NOTDEFINED", true) == 0)) &&
                !string.IsNullOrWhiteSpace(typeShapeType))
            {
                shapeType = typeShapeType;
            }

            // Set "special" shape types
            switch (entityType)
            {
            case IFCEntityType.IfcColumn:
            case IFCEntityType.IfcColumnType:
                if (IsColumnLoadBearing(entity))
                {
                    shapeType = "[LoadBearing]";
                }
                break;
            }

            ElementId catElemId = GetCategoryElementId(entityType, shapeType);

            // If we didn't find a category, or if we found the generic model category, try again with the IfcTypeObject, if there is one.
            if (catElemId == ElementId.InvalidElementId || catElemId.IntegerValue == (int)BuiltInCategory.OST_GenericModel)
            {
                if (typeEntityType.HasValue)
                {
                    catElemId = GetCategoryElementId(typeEntityType.Value, shapeType);
                }
            }

            Category subCategory = null;

            if (catElemId.IntegerValue == (int)BuiltInCategory.OST_GenericModel)
            {
                string subCategoryName = GetCustomCategoryName(entity);
                if (!string.IsNullOrWhiteSpace(subCategoryName))
                {
                    IDictionary <string, Category> createdSubcategories = Importer.TheCache.CreatedSubcategories;
                    if (!createdSubcategories.TryGetValue(subCategoryName, out subCategory))
                    {
                        // Category may have been created by a previous action (probably a previous import).  Look first.
                        try
                        {
                            CategoryNameMap subCategories = Importer.TheCache.GenericModelsCategory.SubCategories;
                            subCategory = subCategories.get_Item(subCategoryName);
                        }
                        catch
                        {
                            subCategory = null;
                        }

                        if (subCategory == null)
                        {
                            subCategory = Importer.TheCache.DocumentCategories.NewSubcategory(Importer.TheCache.GenericModelsCategory, subCategoryName);
                            SetMaterialForSpacesAndOpenings(doc, entity.Id, subCategory, subCategoryName);
                        }

                        createdSubcategories[subCategoryName] = subCategory;
                    }

                    GraphicsStyle graphicsStyle = subCategory.GetGraphicsStyle(GraphicsStyleType.Projection);
                    if (graphicsStyle != null)
                    {
                        gstyleId = graphicsStyle.Id;
                    }
                }
            }
            else if (catElemId == ElementId.InvalidElementId)
            {
                catElemId = new ElementId(BuiltInCategory.OST_GenericModel);

                // Top level entities that are OK to be here.
                if (entityType != IFCEntityType.IfcProject &&
                    entityType != IFCEntityType.IfcBuilding &&
                    entityType != IFCEntityType.IfcBuildingStorey &&
                    entityType != IFCEntityType.IfcElementAssembly)
                {
                    string msg = "Setting IFC entity ";
                    if (string.IsNullOrWhiteSpace(shapeType))
                    {
                        msg = entityType.ToString();
                    }
                    else
                    {
                        msg = entityType.ToString() + "." + shapeType;
                    }

                    if (typeEntityType.HasValue)
                    {
                        msg += " (" + typeEntityType.Value.ToString() + ")";
                    }

                    msg += " to Generic Models.";
                    IFCImportFile.TheLog.LogWarning(entity.Id, msg, true);
                }
            }

            Category categoryToCheck = null;

            if (catElemId.IntegerValue < 0)
            {
                categoryToCheck = Importer.TheCache.DocumentCategories.get_Item((BuiltInCategory)catElemId.IntegerValue);
            }
            else
            {
                categoryToCheck = subCategory;
            }

            if (categoryToCheck != null)
            {
                // We'll assume that a negative value means a built-in category.  It may still be a sub-category, in which case we need to get the parent category and assign the gstyle.
                // We could optimize this, but this is safer.
                Category parentCategory = categoryToCheck.Parent;
                if (parentCategory != null)
                {
                    catElemId = parentCategory.Id;
                }

                // Not already set by subcategory.
                if (gstyleId == ElementId.InvalidElementId)
                {
                    GraphicsStyle graphicsStyle = categoryToCheck.GetGraphicsStyle(GraphicsStyleType.Projection);
                    if (graphicsStyle != null)
                    {
                        gstyleId = graphicsStyle.Id;
                    }
                }
            }

            return(catElemId);
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Add an error message to the log file indicating a missing handle of an expected type.
 /// </summary>
 /// <param name="expectedType">The expected type of the handle.</param>
 public void LogNullError(IFCEntityType expectedType)
 {
     if (LoggingEnabled && m_LogFile != null)
         WriteLine("ERROR: " + expectedType.ToString() + " is null or has no value.");
 }
        /// <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);
                }
            }
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Get valid IFC entity type by using the official IFC schema (using the XML schema). It checks the non-abstract valid entity.
 /// If it is found to be abstract, it will try to find its supertype until it finds a non-abstract type.
 /// </summary>
 /// <param name="entityType">the IFC Entity type enum</param>
 /// <returns>return the appropriate entity type or Unknown</returns>
 public static IFCEntityType GetValidIFCEntityType(IFCEntityType entityType)
 {
     return(GetValidIFCEntityType(entityType.ToString()));
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Returns a string value corresponding to an handle based on its entity type.
        /// </summary>
        /// <param name="handle">The entity handle that contains information to relate to the user in string format.</param>
        /// <returns>The approximate representation of the data as a string.</returns>
        static public string ToString(IFCAnyHandle handle)
        {
            if (IFCAnyHandleUtil.IsNullOrHasNoValue(handle))
            {
                return(null);
            }

            string valueAsString = null;

            IFCEntityType handleType = IFCAnyHandleUtil.GetEntityType(handle);

            switch (handleType)
            {
            case IFCEntityType.IfcMaterial:
                valueAsString = MaterialToString(handle);
                break;

            case IFCEntityType.IfcPerson:
                valueAsString = PersonToString(handle);
                break;

            case IFCEntityType.IfcDateAndTime:
                valueAsString = DateAndTimeToString(handle);
                break;

            case IFCEntityType.IfcMaterialList:
                valueAsString = MaterialListToString(handle);
                break;

            case IFCEntityType.IfcOrganization:
                valueAsString = OrganizationToString(handle);
                break;

            case IFCEntityType.IfcCalendarDate:
                valueAsString = CalendarDateToString(handle);
                break;

            case IFCEntityType.IfcLocalTime:
                valueAsString = LocalTimeToString(handle);
                break;

            case IFCEntityType.IfcPersonAndOrganization:
                valueAsString = PersonAndOrganizationToString(handle);
                break;

            case IFCEntityType.IfcLibraryReference:
            case IFCEntityType.IfcClassificationReference:
            case IFCEntityType.IfcDocumentReference:
                valueAsString = ExternalReferenceToString(handle);
                break;

            case IFCEntityType.IfcPostalAddress:
                valueAsString = PostalAddressToString(handle);
                break;

            case IFCEntityType.IfcTelecomAddress:
                valueAsString = TelecomAddressToString(handle);
                break;

            default:
                // TODO: Support IfcMaterialLayer, IfcTimeSeries, IfcAppliedValue.
                // IfcTimeSeries and IfcAppliedValue are abstract supertypes.
                IFCImportFile.TheLog.LogWarning(handle.StepId, "Unhandled sub-type of IFCObjectReferenceSelect: " + handleType.ToString(), true);
                break;
            }

            return(valueAsString);
        }
Ejemplo n.º 29
0
        private void LogUnhandledSubTypeErrorBase(IFCAnyHandle handle, string mainTypeAsString, bool throwError)
        {
            IFCEntityType subType = IFCAnyHandleUtil.GetEntityType(handle);

            if (!m_LogUnhandledSubtypeErrors.Contains(subType))
            {
                m_LogUnhandledSubtypeErrors.Add(subType);
                LogError(handle.StepId, "Unhandled subtype of " + mainTypeAsString + ": " + subType.ToString() + " (This message will only appear once.)", throwError);
            }
        }
Ejemplo n.º 30
0
 /// <summary>
 /// Add an error message to the log file indicating an incorrect type.
 /// </summary>
 /// <param name="handle">The unhandled entity handle.</param>
 /// <param name="expectedType">The expected base type of the handle.</param>
 /// <param name="throwError">throw an InvalidOperationException if true.</param>
 public void LogUnexpectedTypeError(IFCAnyHandle handle, IFCEntityType expectedType, bool throwError)
 {
    LogError(handle.StepId, "Expected handle of type " + expectedType.ToString() + ", found: " + IFCAnyHandleUtil.GetEntityType(handle).ToString(), throwError);
 }
Ejemplo n.º 31
0
 /// <summary>
 /// Add an error message to the log file indicating a missing handle of an expected type.
 /// </summary>
 /// <param name="expectedType">The expected type of the handle.</param>
 public void LogNullError(IFCEntityType expectedType)
 {
     WriteLine("ERROR: " + expectedType.ToString() + " is null or has no value.");
 }
Ejemplo n.º 32
0
        /// <summary>
        /// Initialize the class with the entity and the type
        /// </summary>
        /// <param name="instance">the entity</param>
        /// <param name="type">the type</param>
        public IFCExportInfoPair(IFCEntityType instance, IFCEntityType type, string predefinedType)
        {
            instance       = ElementFilteringUtil.GetValidIFCEntityType(instance);
            ExportInstance = instance;

            type       = ElementFilteringUtil.GetValidIFCEntityType(type);
            ExportType = type;

            if (!string.IsNullOrEmpty(predefinedType))
            {
                string newValidatedPredefinedType = IFCValidateEntry.GetValidIFCPredefinedTypeType(predefinedType, ValidatedPredefinedType, ExportInstance.ToString());
                if (ExporterUtil.IsNotDefined(newValidatedPredefinedType))
                {
                    newValidatedPredefinedType = IFCValidateEntry.GetValidIFCPredefinedTypeType(predefinedType, ValidatedPredefinedType, ExportType.ToString());
                }
                ValidatedPredefinedType = newValidatedPredefinedType;
            }
            else
            {
                ValidatedPredefinedType = IFCValidateEntry.GetValidIFCPredefinedTypeType("NOTDEFINED", ValidatedPredefinedType, ExportType.ToString());
            }
        }
Ejemplo n.º 33
0
 /// <summary>
 /// Add an error message to the log file indicating an unhandled subtype of a known type.
 /// </summary>
 /// <param name="handle">The unhandled entity handle.</param>
 /// <param name="mainType">The base type of the handle.</param>
 /// <param name="throwError">throw an InvalidOperationException if true.</param>
 public void LogUnhandledSubTypeError(IFCAnyHandle handle, IFCEntityType mainType, bool throwError)
 {
     LogUnhandledSubTypeErrorBase(handle, mainType.ToString(), throwError);
 }
Ejemplo n.º 34
0
        /////////////////////////////////////////////////////////////////
        // SetXXX method is to set base entities' attributes.
        // Every SetXXX method has a corresponding ValidateXXX method.
        // ValidateXXX is to validate the parameters for the attributes.
        // ValidateXXX should not be called in SetXXX. It must be called in CreateXXX method.
        // This is to make sure all arguments are valid BEFORE create an instance.
        // So we have below layout for these methods:
        //   ValidateABCBaseEntity(...) { ... }
        //   SetABCBaseEntity(...) { ... }
        //   CreateABCEntity(...)
        //      {
        //         //Code to validate ABC entity's own parameters goes here.
        //         ValidateABCBaseEntity(...);
        //         //Code to create ABC instance goes here.
        //         //Code to set ABC entity's own attributes goes here.
        //         SetABCBaseEntity(...);
        //      }
        ///////////////////////////////////////////////////////////////

        private static IFCAnyHandle CreateInstance(IFCFile file, IFCEntityType type)
        {
            IFCAnyHandle hnd = file.CreateInstance(type.ToString());
            ExporterCacheManager.HandleTypeCache[hnd] = type;
            return hnd;
        }