Beispiel #1
0
        /// <summary>
        /// Find the handle from the cache using only the Material Id.
        /// </summary>
        /// <param name="materialId"></param>
        /// <returns></returns>
        public IFCAnyHandle Find(ElementId materialId)
        {
            // If only a Material ElementId is provided, default the constituent name to be the same as the material name
            Material material = ExporterCacheManager.Document.GetElement(materialId) as Material;
            string   catName  = (material != null) ? NamingUtil.GetMaterialName(material) : "<Unnamed>"; // Default name to the Material name if not null or <Unnamed>
            MaterialConstituentInfo constInfo = new MaterialConstituentInfo(catName, materialId);

            return(Find(constInfo));
        }
Beispiel #2
0
 /// <summary>
 /// Delete an element from the cache
 /// </summary>
 /// <param name="consInfo">the Material Constituent Info</param>
 public void Delete(MaterialConstituentInfo constInfo)
 {
     if (m_MaterialConstDictionary.ContainsKey(constInfo))
     {
         IFCAnyHandle handle = m_MaterialConstDictionary[constInfo];
         m_MaterialConstDictionary.Remove(constInfo);
         ExporterCacheManager.HandleToElementCache.Delete(handle);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Adds the handle to the dictionary.
        /// </summary>
        /// <param name="constInfo">The Material Constituent Info</param>
        /// <param name="handle">The handle</param>
        public void Register(MaterialConstituentInfo constInfo, IFCAnyHandle handle)
        {
            if (m_MaterialConstDictionary.ContainsKey(constInfo))
            {
                return;
            }

            m_MaterialConstDictionary[constInfo] = handle;
        }
Beispiel #4
0
        /// <summary>
        /// Register Material Constituent Handle with only Material Id. This is the original behavior
        /// </summary>
        /// <param name="materialId">the material elementId</param>
        /// <param name="handle">the handle</param>
        public void Register(ElementId materialId, IFCAnyHandle handle)
        {
            // If only a Material ElementId is provided, default the constituent name to be the same as the material name
            Material material = ExporterCacheManager.Document.GetElement(materialId) as Material;
            string   catName  = (material != null) ? NamingUtil.GetMaterialName(material) : "<Unnamed>"; // Default name to the Material name if not null or <Unnamed>
            MaterialConstituentInfo constInfo = new MaterialConstituentInfo(catName, materialId);

            if (m_MaterialConstDictionary.ContainsKey(constInfo))
            {
                return;
            }

            m_MaterialConstDictionary[constInfo] = handle;
        }
Beispiel #5
0
        /// <summary>
        /// Get or Create (if not yet exists) a handle for IfcMaterialConstituent. It points to an IfcMaterial
        /// </summary>
        /// <param name="exporterIFC"></param>
        /// <param name="materialId"></param>
        /// <returns>The Handle to IfcMaterialConstituent</returns>
        public static IFCAnyHandle GetOrCreateMaterialConstituent(ExporterIFC exporterIFC, ElementId materialId)
        {
            IFCAnyHandle materialConstituentHandle = ExporterCacheManager.MaterialConstituentCache.Find(materialId);

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(materialConstituentHandle))
            {
                Document     document    = ExporterCacheManager.Document;
                IFCAnyHandle materialHnd = GetOrCreateMaterialHandle(exporterIFC, materialId);

                //Material constituent name will be defaulted to the same as the material name
                Material material                 = document.GetElement(materialId) as Material;
                string   constituentName          = (material != null) ? NamingUtil.GetMaterialName(material) : "<Unnamed>";
                MaterialConstituentInfo constInfo = new MaterialConstituentInfo(constituentName, materialId);

                materialConstituentHandle = GetOrCreateMaterialConstituent(exporterIFC, constInfo);
            }

            return(materialConstituentHandle);
        }
Beispiel #6
0
        /// <summary>
        /// Finds the handle from the dictionary.
        /// </summary>
        /// <param name="constInfo">The Material Constituent Info</param>
        /// <returns>The handle</returns>
        public IFCAnyHandle Find(MaterialConstituentInfo constInfo)
        {
            IFCAnyHandle handle = null;

            if (m_MaterialConstDictionary.TryGetValue(constInfo, out handle))
            {
                // We need to make sure the handle isn't stale.  If it is, remove it.
                try
                {
                    if (!IFCAnyHandleUtil.IsValidHandle(handle))
                    {
                        m_MaterialConstDictionary.Remove(constInfo);
                        handle = null;
                    }
                }
                catch
                {
                    m_MaterialConstDictionary.Remove(constInfo);
                    handle = null;
                }
            }
            return(handle);
        }
Beispiel #7
0
        /// <summary>
        /// Get or Create (if not yet exists) a handle for IfcMaterialConstituent. It points to an IfcMaterial
        /// </summary>
        /// <param name="exporterIFC"></param>
        /// <param name="materialId"></param>
        /// <returns>The Handle to IfcMaterialConstituent</returns>
        public static IFCAnyHandle GetOrCreateMaterialConstituent(ExporterIFC exporterIFC, MaterialConstituentInfo constInfo)
        {
            IFCAnyHandle materialConstituentHandle = ExporterCacheManager.MaterialConstituentCache.Find(constInfo);

            if (IFCAnyHandleUtil.IsNullOrHasNoValue(materialConstituentHandle))
            {
                Document     document    = ExporterCacheManager.Document;
                IFCAnyHandle materialHnd = GetOrCreateMaterialHandle(exporterIFC, constInfo.MaterialId);

                Material material = document.GetElement(constInfo.MaterialId) as Material;
                string   category = (material != null) ? NamingUtil.GetMaterialCategoryName(material) : string.Empty;

                materialConstituentHandle = IFCInstanceExporter.CreateMaterialConstituent(exporterIFC.GetFile(), materialHnd, name: constInfo.ComponentCat, category: category);
                ExporterCacheManager.MaterialConstituentCache.Register(constInfo, materialConstituentHandle);
            }

            return(materialConstituentHandle);
        }