/// <summary> /// Opens an IFC file, Ifcxml, IfcZip, xbim from a file path /// </summary> /// <param name="path">the file name of the ifc, ifczip, ifcxml or xbim file to be opened</param> /// <param name="editorDetails">This is only required if the store is opened for editing</param> /// <param name="ifcDatabaseSizeThreshHold">Expressed in MB. If not defined the DefaultIfcDatabaseSizeThreshHold is used, /// IFC files below this size will be opened in memory, above this size a database will be created. If -1 is specified an in memory model will be /// created for all IFC files that are opened. Xbim files are always opened as databases</param> /// <param name="progDelegate"></param> /// <param name="accessMode"></param> /// <param name="codePageOverride"> /// A CodePage that will be used to read implicitly encoded one-byte-char strings. If -1 is specified the default ISO8859-1 /// encoding will be used accoring to the Ifc specification. </param> public static IfcStore Open(string path, XbimEditorCredentials editorDetails = null, double?ifcDatabaseSizeThreshHold = null, ReportProgressDelegate progDelegate = null, XbimDBAccess accessMode = XbimDBAccess.Read, int codePageOverride = -1) { path = Path.GetFullPath(path); if (!Directory.Exists(Path.GetDirectoryName(path) ?? "")) { throw new DirectoryNotFoundException(Path.GetDirectoryName(path) + " directory was not found"); } if (!File.Exists(path)) { throw new FileNotFoundException(path + " file was not found"); } var newStore = new IfcStore(); // we need an instance var ifcVersion = newStore.ModelProvider.GetXbimSchemaVersion(path); if (ifcVersion == XbimSchemaVersion.Unsupported) { throw new FileLoadException(path + " is not a valid IFC file format, ifc, ifcxml, ifczip and xBIM are supported."); } var model = newStore.ModelProvider.Open(path, ifcVersion, ifcDatabaseSizeThreshHold, progDelegate, accessMode, codePageOverride); newStore.AssignModel(model, editorDetails, ifcVersion); return(newStore); }
/// <summary> /// Creates and opens a new Xbim Database /// </summary> /// <param name="dbFileName">Name of the Xbim file</param> /// <param name="access"></param> /// <returns></returns> public static XbimModel CreateModel(string dbFileName, XbimDBAccess access = XbimDBAccess.ReadWrite) { try { if (string.IsNullOrWhiteSpace(Path.GetExtension(dbFileName))) { dbFileName += ".xBIM"; } var model = new XbimModel(); model.CreateDatabase(dbFileName); model.Open(dbFileName, access); model.Header = new StepFileHeader(StepFileHeader.HeaderCreationMode.InitWithXbimDefaults) { FileName = { Name = dbFileName } }; foreach (var schemasId in model.Factory.SchemasIds) { model.Header.FileSchema.Schemas.Add(schemasId); } return(model); } catch (Exception e) { throw new XbimException("Failed to create and open xBIM file \'" + dbFileName + "\'\n" + e.Message, e); } }
/// <summary> /// You can use this function to open IFC model from a <see cref="Stream"/>. /// You need to know file type (IFC, IFCZIP, IFCXML) and schema type (IFC2x3 or IFC4) to be able to use this function. /// If you don't know, you should the overloaded <see cref="Open(string, XbimEditorCredentials, double?, ReportProgressDelegate, XbimDBAccess, int)"/> /// method which takes file paths as an argument, and can automatically detect schema and file type. /// If are opening an *.xbim file you should also use the path-based overload because Esent database needs to operate /// on the file and this function will have to create temporal file if it is not a file stream. /// If the input is a FileStream, be aware this method may call <see cref="Stream.Close"/> on it to keep exclusive access. /// </summary> /// <param name="stream">Stream of data</param> /// <param name="dataType">Type of data (*.ifc, *.ifcxml, *.ifczip)</param> /// <param name="schema">IFC schema (IFC2x3, IFC4). Other schemas are not supported by this class.</param> /// <param name="modelType">Type of model to be used. You can choose between EsentModel and MemoryModel</param> /// <param name="editorDetails">Optional details. You should always pass these if you are going to change the data.</param> /// <param name="accessMode">Access mode to the stream. This is only important if you choose EsentModel. MemoryModel is completely in memory so this is not relevant</param> /// <param name="progDelegate">Progress reporting delegate</param> /// <param name="codePageOverride"> /// A CodePage that will be used to read implicitly encoded one-byte-char strings. If -1 is specified the default ISO8859-1 /// encoding will be used accoring to the Ifc specification. </param> /// <returns></returns> public static IfcStore Open(Stream stream, StorageType dataType, XbimSchemaVersion schema, XbimModelType modelType, XbimEditorCredentials editorDetails = null, XbimDBAccess accessMode = XbimDBAccess.Read, ReportProgressDelegate progDelegate = null, int codePageOverride = -1) { var newStore = new IfcStore(); var model = newStore.ModelProvider.Open(stream, dataType, schema, modelType, accessMode, progDelegate, codePageOverride); newStore.AssignModel(model, editorDetails, schema); return(newStore); }
protected override void OnStartup(StartupEventArgs e) { var mainView = new XplorerMainWindow(); mainView.Show(); bool bOneModelLoaded = false; for (int i = 0; i < e.Args.Length; i++) { string thisArg = e.Args[i]; if (string.Compare("/AccessMode", thisArg, true) == 0) { string StringMode = e.Args[++i]; XbimDBAccess mode = (XbimDBAccess)System.Enum.Parse(typeof(XbimDBAccess), StringMode); if (System.Enum.TryParse(StringMode, out mode)) { mainView.FileAccessMode = mode; } } else if (string.Compare("/plugin", thisArg, true) == 0) { string PluginName = e.Args[++i]; mainView.LoadPlugin(PluginName); } else if (string.Compare("/select", thisArg, true) == 0) { string SelLabel = e.Args[++i]; System.Diagnostics.Debug.Write("Select " + SelLabel + "... "); mainView.LoadingComplete += delegate(object s, RunWorkerCompletedEventArgs args) { int iSel; if (!int.TryParse(SelLabel, out iSel)) { return; } if (mainView.Model == null) { return; } if (mainView.Model.Instances[iSel] == null) { return; } mainView.SelectedItem = mainView.Model.Instances[iSel]; }; } else if (File.Exists(thisArg) && bOneModelLoaded == false) { // does not support the load of two models bOneModelLoaded = true; mainView.LoadAnyModel(thisArg); } } }
/// <summary> /// Opens a model from the provided path, inferring model implementation based on format and model size /// </summary> /// <param name="path">Path to the model file, in any support IFC or XBIM format</param> /// <param name="schemaVersion"></param> /// <param name="ifcDatabaseSizeThreshHold"></param> /// <param name="progDelegate"></param> /// <param name="accessMode"></param> /// <param name="codePageOverride"></param> /// <returns></returns> public override IModel Open(string path, XbimSchemaVersion schemaVersion, double?ifcDatabaseSizeThreshHold = null, ReportProgressDelegate progDelegate = null, XbimDBAccess accessMode = XbimDBAccess.Read, int codePageOverride = -1) { var storageType = path.StorageType(); if (storageType == StorageType.Xbim) //open the XbimFile { var model = CreateEsentModel(schemaVersion, codePageOverride); model.Open(path, accessMode, progDelegate); return(model); } else //it will be an IFC file if we are at this point { var fInfo = new FileInfo(path); double ifcMaxLength = (ifcDatabaseSizeThreshHold ?? DefaultIfcDatabaseSizeThreshHoldMb) * 1024 * 1024; // we need to make an Esent database, if ifcMaxLength<0 we use in memory if (ifcMaxLength >= 0 && fInfo.Length > ifcMaxLength) { var tmpFileName = Path.GetTempFileName(); var model = CreateEsentModel(schemaVersion, codePageOverride); // We delete the XBIM on close as the consumer is not controlling the generation of the XBIM file if (model.CreateFrom(path, tmpFileName, progDelegate, keepOpen: true, deleteOnClose: true)) { return(model); } throw new FileLoadException(path + " file was not a valid IFC format"); } else //we can use a memory model { var model = CreateMemoryModel(schemaVersion); if (storageType.HasFlag(StorageType.IfcZip) || storageType.HasFlag(StorageType.Zip) || storageType.HasFlag(StorageType.StpZip)) { model.LoadZip(path, progDelegate); } else if (storageType.HasFlag(StorageType.Ifc) || storageType.HasFlag(StorageType.Stp)) { model.LoadStep21(path, progDelegate); } else if (storageType.HasFlag(StorageType.IfcXml)) { model.LoadXml(path, progDelegate); } // if we are looking at a memory model loaded from a file it might be safe to fix the file name in the // header with the actual file loaded FileInfo f = new FileInfo(path); model.Header.FileName.Name = f.FullName; return(model); } } }
/// <summary> /// Opens an Xbim model only, to open Ifc, IfcZip and IfcXML files use the CreateFrom method /// </summary> /// <param name="fileName"></param> /// <param name="accessMode"></param> /// <param name="progDelegate"></param> /// <returns>True if successful</returns> public virtual bool Open(string fileName, XbimDBAccess accessMode = XbimDBAccess.Read, ReportProgressDelegate progDelegate = null) { try { Close(); InstanceCache.Open(fileName, accessMode); //opens the database return(true); } catch (Exception e) { throw new XbimException(string.Format("Error opening file {0}\n{1}", fileName, e.Message), e); } }
public override bool Open(string fileName, XbimDBAccess accessMode = XbimDBAccess.Read, ReportProgressDelegate progDelegate = null) { try { var result = base.Open(fileName, accessMode, progDelegate); GetModelFactors(); LoadReferenceModels(); return(result); } catch (Exception e) { throw new XbimException(string.Format("Error opening file {0}\n{1}", fileName, e.Message), e); } }
private void OpenXbimFile(object s, DoWorkEventArgs args) { var worker = s as BackgroundWorker; var fileName = args.Argument as string; var model = new XbimModel(); try { const XbimDBAccess dbAccessMode = XbimDBAccess.Read; if (worker != null) { model.Open(fileName, dbAccessMode, worker.ReportProgress); //load entities into the model if (model.IsFederation) { // needs to open the federation in rw mode model.Close(); model.Open(fileName, XbimDBAccess.ReadWrite, worker.ReportProgress); // federations need to be opened in read/write for the editor to work // sets a convenient integer to all children for model identification // this is used by the federated model selection mechanisms. // var i = 0; foreach (var item in model.AllModels) { item.Tag = i++; } } } args.Result = model; } catch (Exception ex) { var sb = new StringBuilder(); sb.AppendLine("Error reading " + fileName); var indent = "\t"; while (ex != null) { sb.AppendLine(indent + ex.Message); ex = ex.InnerException; indent += "\t"; } args.Result = new Exception(sb.ToString()); } }
public override IModel Open(Stream stream, StorageType dataType, XbimSchemaVersion schema, XbimModelType modelType, XbimDBAccess accessMode = XbimDBAccess.Read, ReportProgressDelegate progDelegate = null, int codePageOverride = -1) { if (modelType != XbimModelType.MemoryModel) { throw new ArgumentOutOfRangeException(nameof(modelType), "MemoryModelProvider only supports MemoryModel"); } switch (dataType) { case StorageType.Xbim: throw new NotSupportedException("MemoryModelProvider cannot support opening XBIM Streams"); case StorageType.IfcXml: { var model = CreateMemoryModel(schema); model.LoadXml(stream, stream.Length, progDelegate); return(model); } case StorageType.Stp: case StorageType.Ifc: { var model = CreateMemoryModel(schema); model.LoadStep21(stream, stream.Length, progDelegate); return(model); } case StorageType.IfcZip: case StorageType.StpZip: case StorageType.Zip: { var model = CreateMemoryModel(schema); model.LoadZip(stream, progDelegate); return(model); } default: throw new ArgumentOutOfRangeException("dataType"); } }
/// <summary> /// Opens a model from the provided stream /// </summary> /// <param name="stream"></param> /// <param name="dataType"></param> /// <param name="schema"></param> /// <param name="modelType"></param> /// <param name="accessMode"></param> /// <param name="progDelegate"></param> /// <param name="codePageOverride"></param> /// <returns></returns> public override IModel Open(Stream stream, StorageType dataType, XbimSchemaVersion schema, XbimModelType modelType, XbimDBAccess accessMode = XbimDBAccess.Read, ReportProgressDelegate progDelegate = null, int codePageOverride = -1) { //any Esent model needs to run from the file so we need to create a temporal one var xbimFilePath = Path.GetTempFileName(); xbimFilePath = Path.ChangeExtension(xbimFilePath, ".xbim"); switch (dataType) { case StorageType.Xbim: //xBIM file has to be opened from the file so we need to create temporary file if it is not a local file stream var localFile = false; var fileStream = stream as FileStream; if (fileStream != null) { var name = fileStream.Name; //if it is an existing local file, just use it if (File.Exists(name)) { xbimFilePath = name; //close the stream from argument to have an exclusive access to the file stream.Close(); localFile = true; } } if (!localFile) { using (var tempFile = File.Create(xbimFilePath)) { stream.CopyTo(tempFile); tempFile.Close(); } } // Scope to avoid name clashes { var model = CreateEsentModel(schema, codePageOverride); model.Open(xbimFilePath, accessMode, progDelegate); return(model); } case StorageType.IfcXml: if (modelType == XbimModelType.EsentModel) { var model = CreateEsentModel(schema, codePageOverride); if (model.CreateFrom(stream, stream.Length, dataType, xbimFilePath, progDelegate, keepOpen: true, cacheEntities: true)) { return(model); } else { throw new XbimException("Failed to create Esent model"); } } if (modelType == XbimModelType.MemoryModel) { var model = CreateMemoryModel(schema); model.LoadXml(stream, stream.Length, progDelegate); return(model); } throw new ArgumentOutOfRangeException("HeuristicModelProvider only supports EsentModel and MemoryModel"); case StorageType.Stp: case StorageType.Ifc: if (modelType == XbimModelType.EsentModel) { var model = CreateEsentModel(schema, codePageOverride); if (model.CreateFrom(stream, stream.Length, dataType, xbimFilePath, progDelegate, keepOpen: true, cacheEntities: true)) { return(model); } else { throw new XbimException("Failed to create Esent model"); } } if (modelType == XbimModelType.MemoryModel) { var model = CreateMemoryModel(schema); model.LoadStep21(stream, stream.Length, progDelegate); return(model); } throw new ArgumentOutOfRangeException("HeuristicModelProvider only supports EsentModel and MemoryModel"); case StorageType.IfcZip: case StorageType.StpZip: case StorageType.Zip: if (modelType == XbimModelType.EsentModel) { var model = CreateEsentModel(schema, codePageOverride); if (model.CreateFrom(stream, stream.Length, dataType, xbimFilePath, progDelegate, true, true)) { return(model); } else { throw new XbimException("Failed to create Esent model"); } } if (modelType == XbimModelType.MemoryModel) { var model = CreateMemoryModel(schema); model.LoadZip(stream, progDelegate); return(model); } throw new ArgumentOutOfRangeException("HeuristicModelProvider only supports EsentModel and MemoryModel"); default: throw new ArgumentOutOfRangeException("dataType"); } }
public override IModel Open(string path, XbimSchemaVersion schemaVersion, double?ifcDatabaseSizeThreshHold = null, ReportProgressDelegate progDelegate = null, XbimDBAccess accessMode = XbimDBAccess.Read, int codePageOverride = -1) { var storageType = path.StorageType(); if (storageType == StorageType.Xbim) //open the XbimFile { var model = CreateEsentModel(schemaVersion, codePageOverride); model.Open(path, accessMode, progDelegate); return(model); } else //it will be an IFC file if we are at this point { var fInfo = new FileInfo(path); var tmpFileName = Path.GetTempFileName(); var model = CreateEsentModel(schemaVersion, codePageOverride); // We delete the XBIM on close as the consumer is not controlling the generation of the XBIM file if (model.CreateFrom(path, tmpFileName, progDelegate, keepOpen: true, deleteOnClose: true)) { return(model); } throw new FileLoadException(path + " file was not a valid IFC format"); } }
public override IModel Open(string path, XbimSchemaVersion schemaVersion, double?ifcDatabaseSizeThreshHold = null, ReportProgressDelegate progDelegate = null, XbimDBAccess accessMode = XbimDBAccess.Read, int codePageOverride = -1) { var storageType = path.StorageType(); if (storageType == StorageType.Xbim) //open the XbimFile { throw new NotSupportedException("The MemoryModelProvider does not support loading of XBIM files."); } else //it will be an IFC file if we are at this point { { var model = CreateMemoryModel(schemaVersion); if (storageType.HasFlag(StorageType.IfcZip) || storageType.HasFlag(StorageType.Zip) || storageType.HasFlag(StorageType.StpZip)) { model.LoadZip(path, progDelegate); } else if (storageType.HasFlag(StorageType.Ifc) || storageType.HasFlag(StorageType.Stp)) { model.LoadStep21(path, progDelegate); } else if (storageType.HasFlag(StorageType.IfcXml)) { model.LoadXml(path, progDelegate); } FileInfo f = new FileInfo(path); model.Header.FileName.Name = f.FullName; return(model); } } }
public abstract IModel Open(string path, XbimSchemaVersion schema, double?ifcDatabaseSizeThreshHold = null, ReportProgressDelegate progDelegate = null, XbimDBAccess accessMode = XbimDBAccess.Read, int codePageOverride = -1);
public abstract IModel Open(Stream data, StorageType dataType, XbimSchemaVersion schema, XbimModelType modelType, XbimDBAccess accessMode = XbimDBAccess.Read, ReportProgressDelegate progDelegate = null, int codePageOverride = -1);
static void Main(string[] args) { //Geting path to the IFC file string[] lines = System.IO.File.ReadAllLines(@AppDomain.CurrentDomain.BaseDirectory + "path.txt"); string fileName = lines[0]; Console.WriteLine("Editing: " + fileName); //Geting material information string data = System.IO.File.ReadAllText(@AppDomain.CurrentDomain.BaseDirectory + "layers_data_write.json"); dynamic json = JArray.Parse(data); //Editor credentials and access mode var editor = new XbimEditorCredentials { //Maybe add sth later }; Console.WriteLine("Editor: "); XbimDBAccess accessmode = XbimDBAccess.Exclusive; using (var model = IfcStore.Open(fileName, editor, null, null, accessmode)) { using (var txn = model.BeginTransaction("Widnows modification")) { foreach (dynamic element in json) { //Read data: string id = element.id; Console.WriteLine(element.id); string glazing_material = element.glazing_material; string lining_material = element.lining_material; double lining_thickness = element.lining_thickness; int lining_partitioning = element.lining_partitioning; double framing_thickness = element.framing_thickness; double framing_mulion_thickness = element.framing_mulion_thickness; double framing_transom_thickness = element.framing_transom_thickness; //Units consideration: var units = model.Instances.FirstOrDefault <IfcSIUnit>(u => u.UnitType == IfcUnitEnum.LENGTHUNIT); Console.WriteLine(units.FullName); lining_thickness = lining_thickness / 1000; framing_thickness = framing_thickness / 1000; framing_mulion_thickness = framing_mulion_thickness / 1000; framing_transom_thickness = framing_transom_thickness / 1000; // Get window for material editing var window = model.Instances.FirstOrDefault <IfcWindow>(w => w.GlobalId == id); // Materials var ifcWindowType = GetIfcWindowType(window); var ifcMaterialConstituentSet = GetIfcMaterialConstituentSet(ifcWindowType); ClearMaterialConstituents(ifcMaterialConstituentSet); var ifcMaterial_lining = model.Instances.New <IfcMaterial>(); ifcMaterial_lining.Name = lining_material; var ifcMaterialConstituent_lining = model.Instances.New <IfcMaterialConstituent>(); ifcMaterialConstituent_lining.Material = ifcMaterial_lining; ifcMaterialConstituentSet.MaterialConstituents.Add(ifcMaterialConstituent_lining); ifcMaterialConstituent_lining.Name = "Lining"; var ifcMaterial_glazing = model.Instances.New <IfcMaterial>(); ifcMaterial_glazing.Name = glazing_material; var ifcMaterialConstituent_glazing = model.Instances.New <IfcMaterialConstituent>(); ifcMaterialConstituent_glazing.Material = ifcMaterial_glazing; ifcMaterialConstituentSet.MaterialConstituents.Add(ifcMaterialConstituent_glazing); ifcMaterialConstituent_glazing.Name = "Glazing"; //IfcWindowLiningProperties var ifcWindowLiningProperties = GetIfcWindowLiningProperties(ifcWindowType); ifcWindowLiningProperties.LiningThickness = lining_thickness; //ifcWindowLiningProperties.MullionThickness = framing_mulion_thickness; ifcWindowLiningProperties.TransomThickness = framing_transom_thickness; ifcWindowType.PartitioningType = (IfcWindowTypePartitioningEnum)lining_partitioning; //IfcWindowPanelProperties ClearPanelProperties(ifcWindowType); if (lining_partitioning == 0) { NewWindowPanelProperty(ifcWindowType, "MIDDLE", framing_thickness); } if (lining_partitioning == 1) { NewWindowPanelProperty(ifcWindowType, "BOTTOM", framing_thickness); NewWindowPanelProperty(ifcWindowType, "TOP", framing_thickness); } if (lining_partitioning == 2) { NewWindowPanelProperty(ifcWindowType, "LEFT", framing_thickness); NewWindowPanelProperty(ifcWindowType, "RIGHT", framing_thickness); } if (lining_partitioning == 3) { NewWindowPanelProperty(ifcWindowType, "LEFT", framing_thickness); NewWindowPanelProperty(ifcWindowType, "MIDDLE", framing_thickness); NewWindowPanelProperty(ifcWindowType, "RIGHT", framing_thickness); } if (lining_partitioning == 8) { NewWindowPanelProperty(ifcWindowType, "BOTTOM", framing_thickness); NewWindowPanelProperty(ifcWindowType, "MIDDLE", framing_thickness); NewWindowPanelProperty(ifcWindowType, "TOP", framing_thickness); } //IfcWindow Pset_WindowCommon var GlazingAreaFraction = window.GetPropertySingleValue("Pset_WindowCommon", "GlazingAreaFraction"); if (GlazingAreaFraction == null) { var ifcPropertySet = model.Instances.New <Xbim.Ifc4.Kernel.IfcPropertySet>(); ifcPropertySet.Name = "Pset_WindowCommon"; GlazingAreaFraction = model.Instances.New <IfcPropertySingleValue>(); GlazingAreaFraction.Name = "GlazingAreaFraction"; ifcPropertySet.HasProperties.Add((IfcProperty)GlazingAreaFraction); } GlazingAreaFraction.NominalValue = CalculateGlazingAreaFraction(window, lining_partitioning, framing_transom_thickness, framing_mulion_thickness, framing_thickness, lining_thickness); //Manual IFC sample model ifcWindowLiningProperties.LiningDepth = 0.02; ifcWindowLiningProperties.FirstTransomOffset = window.OverallHeight / 2; var ifcMaterialConstituent_framing = model.Instances.New <IfcMaterialConstituent>(); ifcMaterialConstituent_framing.Material = ifcMaterial_lining; ifcMaterialConstituentSet.MaterialConstituents.Add(ifcMaterialConstituent_framing); ifcMaterialConstituent_framing.Name = "Framing"; var Pset_DoorWindowGlazingType = model.Instances.New <Xbim.Ifc4.Kernel.IfcPropertySet>(); Pset_DoorWindowGlazingType.Name = " Pset_DoorWindowGlazingType"; var GlassLayers = model.Instances.New <IfcPropertySingleValue>(); GlassLayers.Name = "GlassLayers"; Pset_DoorWindowGlazingType.HasProperties.Add(GlassLayers); var GlassThickness1 = model.Instances.New <IfcPropertySingleValue>(); GlassThickness1.Name = "GlassThickness1"; Pset_DoorWindowGlazingType.HasProperties.Add(GlassThickness1); IfcPositiveLengthMeasure ifcPositiveLengthMeasure0 = 0.002; GlassThickness1.NominalValue = ifcPositiveLengthMeasure0; var GlassThickness2 = model.Instances.New <IfcPropertySingleValue>(); GlassThickness2.Name = "GlassThickness2"; Pset_DoorWindowGlazingType.HasProperties.Add(GlassThickness2); IfcPositiveLengthMeasure ifcPositiveLengthMeasure1 = 0.002; GlassThickness2.NominalValue = ifcPositiveLengthMeasure1; var FillGas = model.Instances.New <IfcPropertySingleValue>(); FillGas.Name = "FillGas"; IfcLabel gass = "Argon"; FillGas.NominalValue = gass; Pset_DoorWindowGlazingType.HasProperties.Add(FillGas); var glass_layers = model.Instances.New <IfcPropertySingleValue>(); glass_layers.Name = "GlassLayers"; IfcCountMeasure two = 2; GlassLayers.NominalValue = two; } txn.Commit(); model.SaveAs(fileName); } IfcMaterialConstituentSet GetIfcMaterialConstituentSet(IfcWindowType type) { IfcMaterialConstituentSet ifcMaterialConstituentSet; var ifcRelAssociateMaterial = model.Instances.FirstOrDefault <IfcRelAssociatesMaterial>(r => r.RelatedObjects.First() == type); if (ifcRelAssociateMaterial == null) { Console.WriteLine("New ifcRelAssociateMaterial and ifcMaterialConstituentSet"); ifcRelAssociateMaterial = model.Instances.New <IfcRelAssociatesMaterial>(); ifcMaterialConstituentSet = model.Instances.New <IfcMaterialConstituentSet>(); RelatesMaterialToWindowType(type, ifcMaterialConstituentSet, ifcRelAssociateMaterial); return(ifcMaterialConstituentSet); } else { ifcMaterialConstituentSet = model.Instances.FirstOrDefault <IfcMaterialConstituentSet>(m => m == ifcRelAssociateMaterial.RelatingMaterial); if (ifcMaterialConstituentSet == null) { Console.WriteLine("New ifcMaterialConstituentSet"); ifcMaterialConstituentSet = model.Instances.New <IfcMaterialConstituentSet>(); RelatesMaterialToWindowType(type, ifcMaterialConstituentSet, ifcRelAssociateMaterial); return(ifcMaterialConstituentSet); } else { Console.WriteLine("Reused ifcMaterialConstituentSet"); return(ifcMaterialConstituentSet); } } } IfcWindowType GetIfcWindowType(IfcObject element) { IfcWindowType ifcWindowType; var ifcRelDefinesByType = model.Instances.FirstOrDefault <IfcRelDefinesByType>(r => r.RelatedObjects.FirstOrDefault() == element); if (ifcRelDefinesByType == null) { ifcWindowType = model.Instances.New <IfcWindowType>(); RelatesWindowToWindowType((IfcWindow)element, ifcWindowType); return(ifcWindowType); } else { ifcWindowType = model.Instances.FirstOrDefault <IfcWindowType>(w => w == ifcRelDefinesByType.RelatingType); if (ifcWindowType == null) { ifcWindowType = model.Instances.New <IfcWindowType>(); ifcRelDefinesByType.RelatingType = ifcWindowType; return(ifcWindowType); } else { return(ifcWindowType); } } } IfcRelDefinesByType GetIfcRelDefinesByType(IfcObject element) { IfcRelDefinesByType ifcRelDefinesByType; ifcRelDefinesByType = model.Instances.FirstOrDefault <IfcRelDefinesByType>(r => r.RelatedObjects == element); if (ifcRelDefinesByType == null) { ifcRelDefinesByType = model.Instances.New <IfcRelDefinesByType>(); ifcRelDefinesByType.RelatedObjects.Add(element); return(ifcRelDefinesByType); } else { return(ifcRelDefinesByType); } } void RelatesMaterialToWindowType(IfcWindowType type, IfcMaterialConstituentSet material, IfcRelAssociatesMaterial associates) { associates.RelatingMaterial = material; associates.RelatedObjects.Add(type); } void RelatesWindowToWindowType(IfcWindow window, IfcWindowType type) { var ifcRelDefinesByType = GetIfcRelDefinesByType(window); ifcRelDefinesByType.RelatingType = type; } Xbim.Ifc4.Kernel.IfcPropertySet GetPset_DoorWindowGlazingType(IfcObject element) { Xbim.Ifc4.Kernel.IfcPropertySet Pset; var ifcRelDefinesByProperties = model.Instances.FirstOrDefault <IfcRelDefinesByProperties>(r => r.RelatedObjects == element); if (ifcRelDefinesByProperties == null) { Pset = model.Instances.New <Xbim.Ifc4.Kernel.IfcPropertySet>(); Pset.Name = "Pset_DoorWindowGlazingType"; ifcRelDefinesByProperties = model.Instances.New <IfcRelDefinesByProperties>(); ifcRelDefinesByProperties.RelatedObjects.Add(element); ifcRelDefinesByProperties.RelatingPropertyDefinition = Pset; return(Pset); } else { Pset = model.Instances.FirstOrDefault <Xbim.Ifc4.Kernel.IfcPropertySet>(p => p.Name == "Pset_DoorWindowGlazingType"); } if (Pset == null) { Pset = model.Instances.New <Xbim.Ifc4.Kernel.IfcPropertySet>(); Pset.Name = "Pset_DoorWindowGlazingType"; ifcRelDefinesByProperties.RelatingPropertyDefinition = Pset; return(Pset); } else { return(Pset); } } void ClearMaterialConstituents(IfcMaterialConstituentSet set) { int number = set.MaterialConstituents.Count; for (int i = 0; i < number; i++) { model.Delete(set.MaterialConstituents.First().Material); model.Delete(set.MaterialConstituents.First()); } } void ClearPset_DoorWindowGlazingType(Xbim.Ifc4.Kernel.IfcPropertySet Pset) { for (int i = 0; i < Pset.HasProperties.Count; i++) { model.Delete(Pset.HasProperties.First()); } } IfcWindowLiningProperties GetIfcWindowLiningProperties(IfcWindowType type) { IfcWindowLiningProperties ifcWindowLiningProperties; ifcWindowLiningProperties = model.Instances.FirstOrDefault <IfcWindowLiningProperties>(w => w.DefinesType.FirstOrDefault() == type); if (ifcWindowLiningProperties == null) { Console.WriteLine("Create new IfcWindowLiningProperties"); ifcWindowLiningProperties = model.Instances.New <IfcWindowLiningProperties>(); type.HasPropertySets.Add(ifcWindowLiningProperties); return(ifcWindowLiningProperties); } else { Console.WriteLine("Reuse IfcWindowLiningProperties"); return(ifcWindowLiningProperties); } } void NewWindowPanelProperty(IfcWindowType type, string position, double frame_thickness) { var ifcWindowPanelProperties = model.Instances.New <IfcWindowPanelProperties>(); type.HasPropertySets.Add(ifcWindowPanelProperties); ifcWindowPanelProperties.FrameThickness = frame_thickness; if (position == "LEFT") { ifcWindowPanelProperties.PanelPosition = Xbim.Ifc4.Interfaces.IfcWindowPanelPositionEnum.LEFT; } if (position == "MIDDLE") { ifcWindowPanelProperties.PanelPosition = Xbim.Ifc4.Interfaces.IfcWindowPanelPositionEnum.MIDDLE; } if (position == "RIGHT") { ifcWindowPanelProperties.PanelPosition = Xbim.Ifc4.Interfaces.IfcWindowPanelPositionEnum.RIGHT; } if (position == "BOTTOM") { ifcWindowPanelProperties.PanelPosition = Xbim.Ifc4.Interfaces.IfcWindowPanelPositionEnum.BOTTOM; } if (position == "TOP") { ifcWindowPanelProperties.PanelPosition = Xbim.Ifc4.Interfaces.IfcWindowPanelPositionEnum.TOP; } //Manual sample IFC window model ifcWindowPanelProperties.FrameDepth = 0.05; // Console.WriteLine(ifcWindowPanelProperties + " " + ifcWindowPanelProperties.PanelPosition); } void ClearPanelProperties(IfcWindowType type) { var allproperties = model.Instances.OfType <IfcWindowPanelProperties>(); Console.WriteLine(model.Instances.OfType <IfcWindowPanelProperties>().Count()); for (int i = 0; i < model.Instances.OfType <IfcWindowPanelProperties>().Count(); i++) { if (allproperties.ElementAt(i).DefinesType.FirstOrDefault() == type) { Console.WriteLine(allproperties.ElementAt(i)); model.Delete(allproperties.ElementAt(i)); i--; } } } IfcPositiveRatioMeasure CalculateGlazingAreaFraction(IfcWindow window, double lining_partitioning, double framing_transom_thickness, double framing_mulion_thickness, double framing_thickness, double lining_thickness) { double height = window.OverallHeight.Value; double width = window.OverallWidth.Value; double non_glazing_area = 0; double non_glazing_area_single_panel = 2 * (lining_thickness + framing_thickness) * (height + width - 2 * (lining_thickness + framing_thickness)); switch (lining_partitioning) { case 0: non_glazing_area = non_glazing_area_single_panel; break; case 1: non_glazing_area = non_glazing_area_single_panel + (height - 2 * (lining_thickness + framing_thickness)) * (framing_transom_thickness + 2 * framing_thickness); break; case 2: non_glazing_area = non_glazing_area_single_panel + (width - 2 * (lining_thickness + framing_thickness)) * (framing_mulion_thickness + 2 * framing_thickness); break; case 3: non_glazing_area = non_glazing_area_single_panel + 2 * (height - 2 * (lining_thickness + framing_thickness)) * (framing_transom_thickness + 2 * framing_thickness); break; case 8: non_glazing_area = non_glazing_area_single_panel + 2 * (width - 2 * (lining_thickness + framing_thickness)) * (framing_mulion_thickness + 2 * framing_thickness); break; default: Console.WriteLine("Default case"); break; } double GlazingAreaFraction_double = (height * width - non_glazing_area) / (height * width); Console.WriteLine(GlazingAreaFraction_double); IfcPositiveRatioMeasure GlazingAreaFraction_value = GlazingAreaFraction_double; return(GlazingAreaFraction_value); } } }
private void InitFromSettings() { _fileAccessMode = Settings.Default.FileAccessMode; OnPropertyChanged("DeveloperVisible"); }
private void InitFromSettings() { _fileAccessMode = Settings.Default.FileAccessMode; }
protected void Open(string fileName, XbimDBAccess accessMode, bool deleteOnClose) { Open(fileName, accessMode); _deleteOnClose = deleteOnClose; }