/// <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); }
#pragma warning restore CS1591 /// <summary> /// Applies the preferences to an IFC model instance. /// </summary> /// <param name="ifcModel">The IFC model</param> /// <returns>Modified IFC model</returns> public IfcModel ApplyToModel(IfcModel ifcModel) { if (null == ifcModel) { throw new ArgumentException("No ifcModel"); } ApplyTo(ifcModel.Store.XbimModel); return(ifcModel); }
/// <summary> /// Extracts the <c>IfcMetadata</c> by repositories change history. /// </summary> /// <param name="ifcModel">The repository</param> /// <returns>A sorted list with most recent at top</returns> public static IfcAuthorMetadata[] OwnerHistory(IfcModel ifcModel) { if (null != ifcModel && !ifcModel.IsCanceled) { return(new IfcMetadataHistory(ifcModel.XbimModel).Chronically.Select(d => new IfcAuthorMetadata(d)).ToArray()); } else { return new IfcAuthorMetadata[] { } }; }
/// <summary> /// Returns the model internal defaults. /// </summary> /// <param name="ifcModel">The IFC model</param> /// <returns>Current tesselation preferences</returns> public static IfcTessellationPrefs ByModelDefaults(IfcModel ifcModel) { var internalModel = ifcModel?.XbimModel; if (null == internalModel) { throw new ArgumentNullException("ifcModel"); } return(FromModelFactors(internalModel.ModelFactors)); }
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); }
/// <summary> /// Cancels all tasks in progress. /// </summary> /// <param name="ifcModel">The model</param> /// <returns>Model with cancelled task mark</returns> public static IfcModel MarkAsCancelled(IfcModel ifcModel) { ifcModel.CancelAll(); return(ifcModel); }