/// <summary> /// A new IFC model generated by transformation delegate. /// </summary> /// <param name="source">The source model</param> /// <param name="transform">A transform expecting an <see cref="IModel"/> and a <see cref="IfcModel"/> to associate the result to.</param> /// <param name="canoncialName">The canonical fragment</param> /// <returns>A new <see cref="IfcModel"/> with transform delegate</returns> internal static IfcModel ByTransform(IfcModel source, Func <IModel, IfcModel, IModel> transform, string canoncialName) { IfcModel ifcModel; if (string.IsNullOrWhiteSpace(canoncialName)) { canoncialName = DateTime.Now.Ticks.ToString(); } var qualifier = ProgressingModelTask <IfcModel> .BuildCanonicalQualifier(source.Qualifier, canoncialName); if (!ModelCache.Instance.TryGetOrCreateModel(qualifier, q => new IfcModel(new IfcStore(source.Store.Logger), qualifier), out ifcModel)) { ifcModel.Store.Producer = () => { if (source.IsCanceled) { ifcModel.CancelAll(); ifcModel.Logger.LogWarning("Transform of '{0}' to '{1}' has been canceled.", source.CanonicalName(), ifcModel.CanonicalName()); return(null); } else { return(transform?.Invoke(source.XbimModel, ifcModel)); } }; } return(ifcModel); }
/// <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); }