/// <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"); } } } } }
public StepModel(EntityFactoryResolverDelegate factoryResolver, ILogger logger = null, int labelFrom = 0) { Logger = logger ?? XbimLogging.CreateLogger <StepModel>(); _factoryResolver = factoryResolver; _instances = new EntityCollection(this, labelFrom); IsTransactional = true; Header = new StepFileHeader(StepFileHeader.HeaderCreationMode.LeaveEmpty, this); ModelFactors = new XbimModelFactors(Math.PI / 180, 1e-3, 1e-5); }
public StepModel(IEntityFactory entityFactory, int labelFrom) { Logger = Logger ?? XbimLogging.CreateLogger<StepModel>(); InitFromEntityFactory(entityFactory); _instances = new EntityCollection(this, labelFrom); IsTransactional = true; ModelFactors = new XbimModelFactors(Math.PI / 180, 1e-3, 1e-5); Header = new StepFileHeader(StepFileHeader.HeaderCreationMode.InitWithXbimDefaults, this); foreach (var schemasId in EntityFactory.SchemasIds) Header.FileSchema.Schemas.Add(schemasId); }
/// <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, int labelFrom = 0) { if (entityFactory == null) { throw new ArgumentNullException("entityFactory"); } _entityFactory = entityFactory; _instances = new EntityCollection(this, labelFrom); Header = new StepFileHeader(StepFileHeader.HeaderCreationMode.InitWithXbimDefaults); foreach (var schemasId in _instances.Factory.SchemasIds) { Header.FileSchema.Schemas.Add(schemasId); } ModelFactors = new XbimModelFactors(Math.PI / 180, 1e-3, 1e-5); Metadata = ExpressMetaData.GetMetadata(entityFactory.GetType().Module); IsTransactional = true; }
private void GetModelFactors() { double angleToRadiansConversionFactor = 1; //assume radians double lengthToMetresConversionFactor = 1; //assume metres var instOfType = Instances.OfType <IfcUnitAssignment>(); var ua = instOfType.FirstOrDefault(); if (ua != null) { foreach (var unit in ua.Units) { var value = 1.0; var cbUnit = unit as IfcConversionBasedUnit; var siUnit = unit as IfcSIUnit; if (cbUnit != null) { var mu = cbUnit.ConversionFactor; var component = mu.UnitComponent as IfcSIUnit; if (component != null) { siUnit = component; } var et = ((IExpressValueType)mu.ValueComponent); if (et.UnderlyingSystemType == typeof(double)) { value *= (double)et.Value; } else if (et.UnderlyingSystemType == typeof(int)) { value *= (int)et.Value; } else if (et.UnderlyingSystemType == typeof(long)) { value *= (long)et.Value; } } if (siUnit == null) { continue; } value *= siUnit.Power; switch (siUnit.UnitType) { case IfcUnitEnum.LENGTHUNIT: lengthToMetresConversionFactor = value; break; case IfcUnitEnum.PLANEANGLEUNIT: angleToRadiansConversionFactor = value; //need to guarantee precision to avoid errors in boolean operations if (Math.Abs(angleToRadiansConversionFactor - (Math.PI / 180)) < 1e-9) { angleToRadiansConversionFactor = Math.PI / 180; } break; } } } var gcs = Instances.OfType <IfcGeometricRepresentationContext>(); double defaultPrecision = 1e-5; //get the Model precision if it is correctly defined foreach (var gc in gcs.Where(g => !(g is IfcGeometricRepresentationSubContext))) { if (!gc.ContextType.HasValue || string.Compare(gc.ContextType.Value, "model", true) != 0) { continue; } if (!gc.Precision.HasValue) { continue; } defaultPrecision = gc.Precision.Value; break; } //get the world coordinate system var context = Instances.OfType <IfcGeometricRepresentationContext>().FirstOrDefault(c => c.GetType() == typeof(IfcGeometricRepresentationContext) && string.Compare(c.ContextType, "model", true) == 0 || string.Compare(c.ContextType, "design", true) == 0); //allow for incorrect older models if (context != null) { WorldCoordinateSystem = context.WorldCoordinateSystem; XbimMatrix3D?wcs = WorldCoordinateSystem.ToMatrix3D(); if (!wcs.Value.IsIdentity) { wcs.Value.Invert(); } } //check if angle units are incorrectly defined, this happens in some old models if (Math.Abs(angleToRadiansConversionFactor - 1) < 1e-10) { foreach (var trimmedCurve in Instances.Where <IfcTrimmedCurve>(trimmedCurve => trimmedCurve.MasterRepresentation == IfcTrimmingPreference.PARAMETER && trimmedCurve.BasisCurve is IfcConic)) { if ( !trimmedCurve.Trim1.Concat(trimmedCurve.Trim2) .OfType <IfcParameterValue>() .Select(trim => (double)trim.Value) .Any(val => val > Math.PI * 2)) { continue; } angleToRadiansConversionFactor = Math.PI / 180; break; } } ModelFactors = new XbimModelFactors(angleToRadiansConversionFactor, lengthToMetresConversionFactor, defaultPrecision); }
public IXbimGeometryModel Combine(IXbimGeometryModel toCombine, XbimModelFactors modelFactors) { return(this); }
public IXbimPolyhedron ToPolyhedron(XbimModelFactors modelFactors) { return(this); }
public IXbimGeometryModel Intersection(IXbimGeometryModel toIntersect, XbimModelFactors modelFactors) { return(this); }
public IXbimGeometryModel Union(IXbimGeometryModel toUnion, XbimModelFactors modelFactors) { return(this); }
public IXbimGeometryModel Cut(IXbimGeometryModel openingGeom, XbimModelFactors modelFactors) { return(this); }
public bool Write(string fileName, XbimModelFactors modelFactors) { return(false); }
public String WriteAsString(XbimModelFactors modelFactors) { return("EMPTY"); }