private void ReadSchemaInHeader(XmlReader input, IStepFileHeader header) { if (!input.IsEmptyElement && input.HasAttributes) { while (input.MoveToNextAttribute()) { if (input.Value == "http://www.iai-tech.org/ifcXML/IFC2x3/FINAL") { header.FileSchema.Schemas.Add("IFC2X3"); break; } if (input.Value == "http://www.buildingsmart-tech.org/ifcXML/MVD4/IFC4" || input.Value == "http://www.buildingsmart-tech.org/ifcXML/IFC4/Add1") { header.FileSchema.Schemas.Add("IFC4"); header.FileSchema.Schemas.Add("IFC4Add1"); break; } if (input.Value == "http://www.buildingsmart-tech.org/ifcXML/IFC4/final") { header.FileSchema.Schemas.Add("IFC4"); break; } } input.MoveToElement(); } }
/// <summary> /// Code to determine model specific workarounds (BIM tool IFC exporter quirks) /// </summary> static public void SetWorkArounds(IStepFileHeader header, XbimModelFactors modelFactors) { //try Revit first string revitPattern = @"- Exporter\s(\d*.\d*.\d*.\d*)"; if (header.FileName == null || string.IsNullOrWhiteSpace(header.FileName.OriginatingSystem)) { return; //nothing to do } var matches = Regex.Matches(header.FileName.OriginatingSystem, revitPattern, RegexOptions.IgnoreCase); if (matches.Count > 0) //looks like Revit { if (matches[0].Groups.Count == 2) //we have the build versions { if (Version.TryParse(matches[0].Groups[1].Value, out Version modelVersion)) { //SurfaceOfLinearExtrusion bug found in version 17.2.0 and earlier var surfaceOfLinearExtrusionVersion = new Version(17, 2, 0, 0); if (modelVersion <= surfaceOfLinearExtrusionVersion) { modelFactors.AddWorkAround("#SurfaceOfLinearExtrusion"); } } } } }
/// <summary> /// This function writes model entities to the defined XML output. /// </summary> /// <param name="model">Model to be used for serialization. If no entities are specified IModel.Instances will be used as a /// source of entities to be serialized.</param> /// <param name="output">Output XML</param> /// <param name="entities">Optional entities enumerable. If you define this enumerable it will be /// used instead of all entities from IModel.Instances. This allows to define different way of entities retrieval /// like volatile instances from persisted DB model</param> public void Write(IModel model, XmlWriter output, IEnumerable <IPersistEntity> entities = null) { _metadata = model.Metadata; try { _written = new HashSet <long>(); output.WriteStartDocument(); output.WriteStartElement("ex", "iso_10303_28", Iso10303Urn); output.WriteAttributeString("version", "2.0"); output.WriteAttributeString("xmlns", "xsi", null, Xsi); output.WriteAttributeString("xmlns", "xlink", null, Xlink); output.WriteAttributeString("xmlns", "ex", null, Iso10303Urn); output.WriteAttributeString("xsi", "schemaLocation", null, string.Format("{0} {1}", Iso10303Urn, ExXsd)); _fileHeader = model.Header; WriteISOHeader(output); //Write out the uos output.WriteStartElement("uos", Namespace); output.WriteAttributeString("id", "uos_1"); output.WriteAttributeString("description", "Xbim IfcXml Export"); output.WriteAttributeString("configuration", "i_ifc2x3"); output.WriteAttributeString("edo", ""); output.WriteAttributeString("xmlns", "ex", null, Iso10303Urn); output.WriteAttributeString("xmlns", "ifc", null, Namespace); output.WriteAttributeString("xsi", "schemaLocation", null, string.Format("{0} {1}", Namespace, IfcXsd)); //use specified entities enumeration or just all instances in the model if (entities != null) { foreach (var entity in entities) { Write(entity, output); } } else { foreach (var entity in model.Instances) { Write(entity, output); } } output.WriteEndElement(); //uos output.WriteEndElement(); //iso_10303_28 output.WriteEndDocument(); } catch (Exception e) { throw new Exception("Failed to write IfcXml file", e); } finally { _written = null; } }
/// <summary> /// This function writes model entities to the defined XML output. /// </summary> /// <param name="model">Model to be used for serialization. If no entities are specified IModel.Instances will be used as a /// source of entities to be serialized.</param> /// <param name="output">Output XML</param> /// <param name="entities">Optional entities enumerable. If you define this enumerable it will be /// used instead of all entities from IModel.Instances. This allows to define different way of entities retrieval /// like volatile instances from persisted DB model</param> public void Write(IModel model, XmlWriter output, IEnumerable <IPersistEntity> entities = null) { _metadata = model.Metadata; try { _written = new HashSet <long>(); output.WriteStartDocument(); output.WriteStartElement(_rootElementName, _ns); //xmlns declarations output.WriteAttributeString("xmlns", "xsi", null, Xsi); output.WriteAttributeString("xmlns", "xlink", null, Xlink); output.WriteAttributeString("xmlns", _nsPrefix, null, _ns); if (!string.IsNullOrWhiteSpace(_nsLocation)) { output.WriteAttributeString("schemaLocation", Xsi, string.Format("{0} {1}", _ns, _nsLocation)); } //root attributes output.WriteAttributeString("id", "uos_1"); if (!string.IsNullOrWhiteSpace(_expressUri)) { output.WriteAttributeString("express", _expressUri); } if (!string.IsNullOrWhiteSpace(_configurationUri)) { output.WriteAttributeString("configuration", _configurationUri); } _fileHeader = model.Header; WriteHeader(output); //use specified entities enumeration or just all instances in the model entities = entities ?? model.Instances; foreach (var entity in entities) { WriteEntity(entity, output, true); } output.WriteEndElement(); //root element output.WriteEndDocument(); } catch (Exception e) { throw new Exception("Failed to write XML file", e); } finally { _written = null; } }
internal void WriteHeader(IStepFileHeader ifcFileHeader) { var ms = new MemoryStream(4096); var bw = new BinaryWriter(ms); ifcFileHeader.Write(bw); if (Api.TryMoveFirst(Sesid, GlobalsTable)) { using (var update = new Update(Sesid, GlobalsTable, JET_prep.Replace)) { Api.SetColumn(Sesid, GlobalsTable, IfcHeaderColumn, ms.ToArray()); update.Save(); } } }
/// <summary> /// Closes the current model and releases all resources and instances /// </summary> public virtual void Close() { var dbName = DatabaseName; ModelFactors = new XbimModelFactors(Math.PI / 180, 1e-3, 1e-5); Header = null; if (_editTransactionEntityCursor != null) { EndTransaction(); } if (_geometryStore != null) { _geometryStore.Dispose(); _geometryStore = null; } InstanceCache.Close(); //dispose any referenced models foreach (var refModel in _referencedModels.Select(r => r.Model).OfType <IDisposable>()) { refModel.Dispose(); } _referencedModels.Clear(); try //try and tidy up if required { if (_deleteOnClose && File.Exists(dbName)) { File.Delete(dbName); // Since Windows 10 Anniverary Edition JET FlushMap files are created for each XBIM // https://docs.microsoft.com/en-us/windows/desktop/extensiblestorageengine/gg294069(v%3Dexchg.10)#flush-map-files var flushMapFile = Path.ChangeExtension(dbName, ".jfm"); if (File.Exists(flushMapFile)) { File.Delete(flushMapFile); } } } catch (Exception) { // ignored } _deleteOnClose = false; }
public MemoryModel(IEntityFactory entityFactory, IStepFileHeader header) : base(entityFactory, 0) { Header = header; }
private ProcessResult ProcessFile(string ifcFile) { RemoveFiles(ifcFile); long geomTime = -1; long parseTime = -1; using (EventTrace eventTrace = LoggerFactory.CreateEventTrace()) { ProcessResult result = new ProcessResult() { Errors = -1 }; try { Stopwatch watch = new Stopwatch(); watch.Start(); using (var model = ParseModelFile(ifcFile, Params.Caching)) { parseTime = watch.ElapsedMilliseconds; string xbimFilename = BuildFileName(ifcFile, ".xbim"); //add geometry Xbim3DModelContext m3d = new Xbim3DModelContext(model); try { m3d.CreateContext(); } catch (Exception ex) { Logger.Error(String.Format("Error compiling geometry: {0} - {1}", ifcFile, ex.Message), ex); } geomTime = watch.ElapsedMilliseconds - parseTime; IStepFileHeader header = model.Header; watch.Stop(); var ohs = model.Instances.OfType <IIfcOwnerHistory>().FirstOrDefault(); result = new ProcessResult() { ParseDuration = parseTime, GeometryDuration = geomTime, SceneDuration = 0, FileName = ifcFile, Entities = model.Instances.Count, IfcSchema = header.FileSchema.Schemas.FirstOrDefault(), IfcDescription = String.Format("{0}, {1}", header.FileDescription.Description.FirstOrDefault(), header.FileDescription.ImplementationLevel), //GeometryEntries = model., IfcLength = ReadFileLength(ifcFile), XbimLength = ReadFileLength(xbimFilename), SceneLength = 0, IfcProductEntries = model.Instances.CountOf <IIfcProduct>(), IfcSolidGeometries = model.Instances.CountOf <IIfcSolidModel>(), IfcMappedGeometries = model.Instances.CountOf <IIfcMappedItem>(), BooleanGeometries = model.Instances.CountOf <IIfcBooleanResult>(), Application = ohs == null ? "Unknown" : ohs.OwningApplication.ToString(), }; } } catch (Exception ex) { Logger.Error(String.Format("Problem converting file: {0}", ifcFile), ex); result.Failed = true; } finally { result.Errors = (from e in eventTrace.Events where (e.EventLevel == EventLevel.ERROR) select e).Count(); result.Warnings = (from e in eventTrace.Events where (e.EventLevel == EventLevel.WARN) select e).Count(); result.FileName = ifcFile; if (eventTrace.Events.Count > 0) { CreateLogFile(ifcFile, eventTrace.Events); } //add last reports pass/fail and save report to report set if (_lastReportSet != null) { result.LastTestFailed = _lastReportSet.Compare(result); //set last test pass/fail result } _thisReportSet.Add(result); } return(result); } }
private ProcessResult ProcessFile(string ifcFile, StreamWriter writer) { RemoveFiles(ifcFile); long geomTime = -1; long parseTime = -1; using (EventTrace eventTrace = LoggerFactory.CreateEventTrace()) { ProcessResult result = new ProcessResult() { Errors = -1 }; try { Stopwatch watch = new Stopwatch(); watch.Start(); using (var model = ParseModelFile(ifcFile, Params.Caching)) { parseTime = watch.ElapsedMilliseconds; string xbimFilename = BuildFileName(ifcFile, ".xbim"); Xbim3DModelContext context = new Xbim3DModelContext(model); context.CreateContext(); //} geomTime = watch.ElapsedMilliseconds - parseTime; //XbimSceneBuilder sb = new XbimSceneBuilder(); //string xbimSceneName = BuildFileName(ifcFile, ".xbimScene"); //sb.BuildGlobalScene(model, xbimSceneName); // sceneTime = watch.ElapsedMilliseconds - geomTime; IStepFileHeader header = model.Header; watch.Stop(); IIfcOwnerHistory ohs = model.Instances.OfType <IIfcOwnerHistory>().FirstOrDefault(); using (var geomReader = model.GeometryStore.BeginRead()) { result = new ProcessResult { ParseDuration = parseTime, GeometryDuration = geomTime, // SceneDuration = sceneTime, FileName = ifcFile.Remove(0, Params.TestFileRoot.Length).TrimStart('\\'), Entities = model.Instances.Count, IfcSchema = header.FileSchema.Schemas.FirstOrDefault(), IfcDescription = String.Format("{0}, {1}", header.FileDescription.Description.FirstOrDefault(), header.FileDescription.ImplementationLevel), GeometryEntries = geomReader.ShapeInstances.Count(), IfcLength = ReadFileLength(ifcFile), XbimLength = ReadFileLength(xbimFilename), SceneLength = 0, IfcProductEntries = model.Instances.OfType <IIfcProduct>().Count(), IfcSolidGeometries = model.Instances.OfType <IIfcSolidModel>().Count(), IfcMappedGeometries = model.Instances.OfType <IIfcMappedItem>().Count(), BooleanGeometries = model.Instances.OfType <IIfcBooleanResult>().Count(), BReps = model.Instances.OfType <IIfcFaceBasedSurfaceModel>().Count() + model.Instances.OfType <IIfcShellBasedSurfaceModel>().Count() + model.Instances.OfType <IIfcManifoldSolidBrep>().Count(), Application = ohs == null ? "Unknown" : ohs.OwningApplication.ToString(), }; } model.Close(); } } catch (Exception ex) { Logger.Error(String.Format("Problem converting file: {0}", ifcFile), ex); result.Failed = true; } finally { result.Errors = (from e in eventTrace.Events where (e.EventLevel == EventLevel.ERROR) select e).Count(); result.Warnings = (from e in eventTrace.Events where (e.EventLevel == EventLevel.WARN) select e).Count(); result.FileName = ifcFile.Remove(0, Params.TestFileRoot.Length).TrimStart('\\'); if (eventTrace.Events.Count > 0) { CreateLogFile(ifcFile, eventTrace.Events); } writer.WriteLine(result.ToCsv()); writer.Flush(); } return(result); } }
/// <summary> /// Writes STEP21 header to the output /// </summary> /// <param name="header">Header</param> /// <param name="output">Writer</param> /// <param name="overridingSchema">Schema to be written to the header instead of the schema defined in the header. /// This is useful if the schema is not defined in the header.</param> public static void WriteHeader(IStepFileHeader header, TextWriter output, string overridingSchema = null) { output.WriteLine("ISO-10303-21;"); output.WriteLine("HEADER;"); //FILE_DESCRIPTION output.Write("FILE_DESCRIPTION (("); var i = 0; if (header.FileDescription.Description.Count == 0) { output.Write(@"''"); } else { foreach (var item in header.FileDescription.Description) { output.Write(@"{0}'{1}'", i == 0 ? "" : ",", item.ToPart21()); i++; } } output.Write(@"), '{0}');", header.FileDescription.ImplementationLevel); output.WriteLine(); //FileName output.Write("FILE_NAME ("); output.Write(@"'{0}'", (header.FileName != null && header.FileName.Name != null) ? header.FileName.Name.ToPart21() : ""); output.Write(@", '{0}'", header.FileName != null ? header.FileName.TimeStamp : ""); output.Write(", ("); i = 0; if (header.FileName != null && header.FileName.AuthorName.Count == 0) { output.Write(@"''"); } else { if (header.FileName != null) { foreach (var item in header.FileName.AuthorName) { output.Write(@"{0}'{1}'", i == 0 ? "" : ",", item.ToPart21()); i++; } } } output.Write("), ("); i = 0; if (header.FileName != null && header.FileName.Organization.Count == 0) { output.Write(@"''"); } else { if (header.FileName != null) { foreach (var item in header.FileName.Organization) { output.Write(@"{0}'{1}'", i == 0 ? "" : ",", item.ToPart21()); i++; } } } if (header.FileName != null) { output.Write(@"), '{0}', '{1}', '{2}');", header.FileName.PreprocessorVersion.ToPart21(), header.FileName.OriginatingSystem.ToPart21(), header.FileName.AuthorizationName.ToPart21()); } output.WriteLine(); //FileSchema output.Write("FILE_SCHEMA (('{0}'));", overridingSchema ?? header.FileSchema.Schemas.FirstOrDefault()); output.WriteLine(); output.WriteLine("ENDSEC;"); output.WriteLine("DATA;"); }
internal void InitialiseHeader(IStepFileHeader header) { _header = header; }