Ejemplo n.º 1
0
        /// <summary>
        /// Get or creates a new model store from file and logger instance.
        /// </summary>
        /// <param name="fileName">File name to load</param>
        /// <param name="logger">The logger instance</param>
        /// <param name="tessellationPrefs">Tessellation preferences</param>
        /// <returns>This instance</returns>
        public static IfcModel ByIfcModelFile(string fileName, Logger logger, IfcTessellationPrefs tessellationPrefs)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            InitLogging(logger);

            var qualifier = ProgressingModelTask <IfcModel> .BuildQualifierByFilePathName(fileName);

            IfcModel ifcModel;

            if (!ModelCache.Instance.TryGetOrCreateModel(qualifier, q => new IfcModel(new IfcStore(logger), qualifier), out ifcModel))
            {
                ifcModel.Store.Producer = () => LoadFromFile(ifcModel, tessellationPrefs, fileName);
                tessellationPrefs?.ApplyToModel(ifcModel);
            }

            return(ifcModel);
        }
Ejemplo n.º 2
0
        private static IModel LoadFromFile(IfcModel theModel, IfcTessellationPrefs prefs, string filePathName)
        {
            var logger = theModel.Store.Logger;

            logger?.LogInfo("Start loading file '{0}'.", filePathName);
            try
            {
                var model = Xbim.Ifc.IfcStore.Open(filePathName, null, null, theModel.NotifyLoadProgressChanged, Xbim.IO.XbimDBAccess.Read);
                prefs?.ApplyTo(model);
                theModel.NotifyOnProgressEnded(LogReason.Loaded, false, false);
                logger?.LogInfo("File '{0}' has been loaded successfully.", filePathName);
                theModel.Store.TimeStamp = File.GetCreationTime(filePathName);

                return(model);
            }
            catch (Exception e)
            {
                logger?.LogError(e, "Exception while loading '{0}'.", filePathName);
                theModel.NotifyOnProgressEnded(LogReason.Loaded, false, true);
            }
            return(null);
        }