public static void ConvertDpowToCobie(Stream input, CloudBlockBlob outputCobieBlob) { var temp = Path.GetTempFileName(); try { var dpow = PlanOfWork.Open(input); var facility = new FacilityType(); var exchanger = new XbimExchanger.DPoWToCOBieLite.DpoWtoCoBieLiteExchanger(dpow, facility); exchanger.Convert(); using (var tw = File.CreateText(temp)) { CoBieLiteHelper.WriteJson(tw, facility); tw.Close(); } outputCobieBlob.UploadFromFile(temp, FileMode.Open); } finally { //tidy up if (File.Exists(temp)) { File.Delete(temp); } } }
public void ConvertCoBieLiteToXml() { using (var m = new XbimModel()) { var IfcTestFile = "2012-03-23-Duplex-Handover.ifc"; // var IfcTestFile = @"D:\Users\steve\xBIM\Test Models\BimAlliance BillEast\Model 1 Duplex Apartment\Duplex_MEP_20110907.ifc"; var xbimTestFile = Path.ChangeExtension(IfcTestFile, "xbim"); m.CreateFrom(IfcTestFile, xbimTestFile, null, true, true); var helper = new CoBieLiteHelper(m, "UniClass"); var facilities = helper.GetFacilities(); var i = 1; foreach (var facilityType in facilities) { Assert.IsTrue(facilityType.FacilityDefaultLinearUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultAreaUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultVolumeUnitSpecified); var outName = string.Format("Facility{0}.xml", i++); var f = new FileInfo(outName); Debug.WriteLine("Writing to " + f.FullName); using (TextWriter writer = File.CreateText(outName)) { CoBieLiteHelper.WriteXml(writer, facilityType); } CoBieLiteHelper.WriteXml(Console.Out, facilityType); } } }
private static string CreateJsonBIM(XbimModel model, string fileName) { try { var cobieFileName = Path.ChangeExtension(fileName, "json");//"semantics.json"; using (var cobieFile = new FileStream(cobieFileName, FileMode.Create)) { var helper = new CoBieLiteHelper(model, "UniClass"); var facility = helper.GetFacilities().FirstOrDefault(); if (facility != null) { using (var writer = new StreamWriter(cobieFile)) { CoBieLiteHelper.WriteJson(writer, facility); writer.Close(); } } } return(cobieFileName); } catch (Exception ex) { Log.Error("转换Cobie文件失败:" + ex.Message, ex); throw; } }
public void ConvertCoBieLiteToBson() { const string ifcTestFile = "2012-03-23-Duplex-Handover.ifc"; using (var m = IfcStore.Open(ifcTestFile)) { // IfcTestFile = @"C:\Data\dev\XbimTeam\XbimExchange\Tests\TestFiles\Standard_Classroom_CIC_6_Project_mod2.ifc"; var helper = new CoBieLiteHelper(m, "UniClass"); var facilities = helper.GetFacilities(); foreach (var facilityType in facilities) { Assert.IsTrue(facilityType.FacilityDefaultLinearUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultAreaUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultVolumeUnitSpecified); using (var sw = new FileStream("facility.bson", FileMode.Create)) { using (var bw = new BinaryWriter(sw)) { CoBieLiteHelper.WriteBson(bw, facilityType); } } } } }
public void ConvertCoBieLiteToBson() { using (var m = new XbimModel()) { var IfcTestFile = "2012-03-23-Duplex-Handover.ifc"; // IfcTestFile = @"C:\Data\dev\XbimTeam\XbimExchange\Tests\TestFiles\Standard_Classroom_CIC_6_Project_mod2.ifc"; var XbimTestFile = Path.ChangeExtension(IfcTestFile, "xbim"); m.CreateFrom(IfcTestFile, XbimTestFile, null, true, true); var helper = new CoBieLiteHelper(m, "UniClass"); var facilities = helper.GetFacilities(); foreach (var facilityType in facilities) { Assert.IsTrue(facilityType.FacilityDefaultLinearUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultAreaUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultVolumeUnitSpecified); using (var sw = new FileStream("facility.bson", FileMode.Create)) { using (var bw = new BinaryWriter(sw)) { CoBieLiteHelper.WriteBson(bw, facilityType); } } } } }
public void ConvertCoBieLiteToJson() { using (var m = new XbimModel()) { var IfcTestFile = "2012-03-23-Duplex-Handover.ifc"; //IfcTestFile = @"D:\Users\steve\My Documents\DPoW\001 NBS Lakeside Restaurant 2014.ifc"; var XbimTestFile = Path.ChangeExtension(IfcTestFile, "xbim"); var JsonFile = Path.ChangeExtension(IfcTestFile, "json"); m.CreateFrom(IfcTestFile, XbimTestFile, null, true, true); var helper = new CoBieLiteHelper(m,"UniClass"); var facilities = helper.GetFacilities(); foreach (var facilityType in facilities) { Assert.IsTrue(facilityType.FacilityDefaultLinearUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultAreaUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultVolumeUnitSpecified); using (var fs = new StreamWriter(JsonFile)) { CoBieLiteHelper.WriteJson(fs, facilityType); fs.Close(); } } } }
public void CanOpenTemporaryModel() { var model = XbimModel.CreateTemporaryModel(); model.Initialise(); var helper = new CoBieLiteHelper(model, "UniClass"); helper.GetFacilities(); }
public void ConvertCoBieLiteToXml() { const string ifcTestFile = "2012-03-23-Duplex-Handover.ifc"; using (var m = IfcStore.Open(ifcTestFile)) { var xbimTestFile = Path.ChangeExtension(ifcTestFile, "xbim"); var helper = new CoBieLiteHelper(m, "UniClass"); var facilities = helper.GetFacilities(); var i = 1; foreach (var facilityType in facilities) { Assert.IsTrue(facilityType.FacilityDefaultLinearUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultAreaUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultVolumeUnitSpecified); var outName = string.Format("Facility{0}.xml", i++); using (TextWriter writer = File.CreateText(outName)) { CoBieLiteHelper.WriteXml(writer, facilityType); } CoBieLiteHelper.WriteXml(Console.Out, facilityType); // attempt reading CoBieLiteHelper.ReadXml(outName); } } }
private void ConvertOrganisation(IfcOrganization ifcOrganization, CoBieLiteHelper helper) { if (ifcOrganization.Addresses != null) { var telecom = ifcOrganization.Addresses.OfType<IfcTelecomAddress>(); var postal = ifcOrganization.Addresses.OfType<IfcPostalAddress>(); var ifcTelecomAddresses = telecom as IfcTelecomAddress[] ?? telecom.ToArray(); if (ifcTelecomAddresses.Any()) { var emailAddresses = string.Join(";",ifcTelecomAddresses.SelectMany(t => t.ElectronicMailAddresses)); if (!string.IsNullOrWhiteSpace(emailAddresses)) ContactEmail = emailAddresses; var phoneNums = string.Join(";", ifcTelecomAddresses.SelectMany(t => t.TelephoneNumbers)); if (!string.IsNullOrWhiteSpace(phoneNums)) ContactPhoneNumber = phoneNums; var url = string.Join(";", ifcTelecomAddresses.Where(p => p.WWWHomePageURL.HasValue).SelectMany(p => p.WWWHomePageURL.ToString())); if (!string.IsNullOrWhiteSpace(url)) ContactURL = url; } var ifcPostalAddresses = postal as IfcPostalAddress[] ?? postal.ToArray(); if (ifcPostalAddresses.Any()) { var deptNames = string.Join(";",ifcPostalAddresses.Where(p=>p.InternalLocation.HasValue).SelectMany(p => p.InternalLocation.ToString())); if (!string.IsNullOrWhiteSpace(deptNames)) ContactDepartmentName = deptNames; var streetNames = string.Join(";",ifcPostalAddresses.Where(p=>p.AddressLines!=null).SelectMany(p => p.AddressLines.ToString())); if (!string.IsNullOrWhiteSpace(streetNames)) ContactStreet = streetNames; var postalBox = string.Join(";", ifcPostalAddresses.Where(p => p.PostalBox.HasValue).SelectMany(p => p.PostalBox.ToString())); if (!string.IsNullOrWhiteSpace(postalBox)) ContactPostalBoxNumber = postalBox; var town = string.Join(";", ifcPostalAddresses.Where(p => p.Town.HasValue).SelectMany(p => p.Town.ToString())); if (!string.IsNullOrWhiteSpace(town)) ContactTownName = town; var region = string.Join(";", ifcPostalAddresses.Where(p => p.Region.HasValue).SelectMany(p => p.Region.ToString())); if (!string.IsNullOrWhiteSpace(region)) ContactRegionCode = region; var postalCode = string.Join(";", ifcPostalAddresses.Where(p => p.PostalCode.HasValue).SelectMany(p => p.PostalCode.ToString())); if (!string.IsNullOrWhiteSpace(postalCode)) ContactPostalCode = postalCode; } } if (ifcOrganization.Roles != null) { var roles = string.Join(";",ifcOrganization.Roles.Select(r => r.RoleString)); //deals with User defined roles if (!string.IsNullOrWhiteSpace(roles)) ContactCategory = roles; } ContactCompanyName = ifcOrganization.Name; }
public SiteType(IfcSite ifcSite, CoBieLiteHelper helper) : this() { // _ifcSite = ifcSite; externalEntityName = helper.ExternalEntityName(ifcSite); externalID = helper.ExternalEntityIdentity(ifcSite); externalSystemName = helper.ExternalSystemName(ifcSite); SiteName = ifcSite.LongName; SiteDescription = ifcSite.Description; }
public void CanOpenTemporaryModel() { var model = IfcStore.Create(new XbimEditorCredentials(), XbimSchemaVersion.Ifc2X3, XbimStoreType.InMemoryModel); var helper = new CoBieLiteHelper(model, "UniClass"); foreach (var facilityType in helper.GetFacilities()) { } }
public AssetInfoType(IfcElement ifcElement, CoBieLiteHelper helper) : this() { externalEntityName = helper.ExternalEntityName(ifcElement); externalID = helper.ExternalEntityIdentity(ifcElement); externalSystemName = helper.ExternalSystemName(ifcElement); AssetName = ifcElement.Name; AssetDescription = ifcElement.Description; AssetSerialNumber = helper.GetCoBieProperty("AssetSerialNumber", ifcElement); AssetInstallationDate = helper.GetCoBieProperty<DateTime>("AssetInstallationDate", ifcElement); AssetInstallationDateSpecified = AssetInstallationDate != default(DateTime); AssetInstalledModelNumber = helper.GetCoBieProperty("AssetInstalledModelNumber", ifcElement); AssetWarrantyStartDate = helper.GetCoBieProperty<DateTime>("AssetWarrantyStartDate", ifcElement); AssetWarrantyStartDateSpecified = AssetWarrantyStartDate != default(DateTime); AssetStartDate = helper.GetCoBieProperty("AssetStartDate", ifcElement); //why isn't this a date in the schema? AssetTagNumber = helper.GetCoBieProperty("AssetTagNumber", ifcElement); AssetBarCode = helper.GetCoBieProperty("AssetBarCode", ifcElement); AssetIdentifier = helper.GetCoBieProperty("AssetIdentifier", ifcElement); AssetLocationDescription = helper.GetCoBieProperty("AssetLocationDescription", ifcElement); //Attributes var ifcAttributes = helper.GetAttributes(ifcElement); if (ifcAttributes != null && ifcAttributes.Any()) AssetAttributes = new AttributeCollectionType { Attribute = ifcAttributes }; //System Assignments List<IfcSystem> systems; if (helper.SystemLookup.TryGetValue(ifcElement, out systems)) { AssetSystemAssignments = new SystemAssignmentCollectionType { SystemAssignment = new List<SystemKeyType>(systems.Count) }; for (int i = 0; i < systems.Count; i++) { AssetSystemAssignments.SystemAssignment.Add(new SystemKeyType(systems[i], helper)); } } //Space Assignments List<IfcSpace> spaces; if (helper.SpaceAssetLookup.TryGetValue(ifcElement, out spaces)) { AssetSpaceAssignments = new SpaceAssignmentCollectionType { SpaceAssignment = new List<SpaceKeyType>(spaces.Count) }; for (int i = 0; i < spaces.Count; i++) { AssetSpaceAssignments.SpaceAssignment.Add(new SpaceKeyType(spaces[i], helper)); } } //Issues //Documents }
//[System.Xml.Serialization.XmlIgnoreAttribute()] //private IfcBuildingStorey _ifcBuildingStorey; public FloorType(IfcBuildingStorey ifcBuildingStorey, CoBieLiteHelper helper) : this() { // _ifcBuildingStorey = ifcBuildingStorey; externalEntityName = helper.ExternalEntityName(ifcBuildingStorey); externalID = helper.ExternalEntityIdentity(ifcBuildingStorey); externalSystemName = helper.ExternalSystemName(ifcBuildingStorey); FloorName = ifcBuildingStorey.Name; FloorCategory = helper.GetClassification(ifcBuildingStorey); FloorDescription = ifcBuildingStorey.Description; //set the fall backs if (ifcBuildingStorey.Elevation.HasValue) { FloorElevationValue = new DecimalValueType { DecimalValue = ifcBuildingStorey.Elevation.Value, DecimalValueSpecified = true }; //TODO: work out if the units can change //FloorElevationValue.UnitName = } FloorHeightValue = helper.GetCoBieAttribute<DecimalValueType>("FloorHeightValue", ifcBuildingStorey); //var heightProperty = ifcBuildingStorey.GetTotalHeightProperty(); //if (heightProperty != null) //{ // FloorHeightValue = new DecimalValueType // { // DecimalValue = heightProperty.LengthValue, // DecimalValueSpecified = true, // UnitName = heightProperty.Unit.GetName() // }; //} var spaces = ifcBuildingStorey.GetSpaces(); var ifcSpaces = spaces as IList<IfcSpace> ?? spaces.ToList(); if (ifcSpaces.Any()) { Spaces = new SpaceCollectionType {Space = new List<SpaceType>(ifcSpaces.Count)}; for (var i = 0; i < ifcSpaces.Count; i++) { Spaces.Add(new SpaceType(ifcSpaces[i], helper)); } } //Attributes var ifcAttributes = helper.GetAttributes(ifcBuildingStorey); if (ifcAttributes != null && ifcAttributes.Any()) FloorAttributes = new AttributeCollectionType { Attribute = ifcAttributes }; //TODO: //Space Issues //Space Documents }
public ProjectType(IfcProject ifcProject, CoBieLiteHelper helper) : this() { // _ifcProject = ifcProject; externalEntityName = helper.ExternalEntityName(ifcProject); externalID = helper.ExternalEntityIdentity(ifcProject); externalSystemName = helper.ExternalSystemName(ifcProject); ProjectName = ifcProject.Name; ProjectDescription = ifcProject.Description; }
public void ConvertCoBieLiteToIfc() { using (var m = new XbimModel()) { m.CreateFrom("2012-03-23-Duplex-Handover.ifc", "2012-03-23-Duplex-Handover.xbim", null, true, true); var helper = new CoBieLiteHelper(m, "UniClass"); var facilities = helper.GetFacilities(); foreach (var facilityType in facilities) { using (var sw = new FileStream("facility.bson", FileMode.Create)) { helper.WriteIfc(Console.Out, facilityType); } } } }
public void CanReadSerialisedXml() { try { CoBieLiteHelper.ReadXml(@"Facility1.xml"); } catch (Exception ex) { while (ex.InnerException != null) { Debug.WriteLine(ex.Message); ex = ex.InnerException; } Debug.WriteLine(ex.Message); throw; } }
public ZoneType(IfcZone ifcZone, CoBieLiteHelper helper) : this() { externalEntityName = helper.ExternalEntityName(ifcZone); externalID = helper.ExternalEntityIdentity(ifcZone); externalSystemName = helper.ExternalSystemName(ifcZone); ZoneDescription = ifcZone.Description; ZoneCategory = helper.GetClassification(ifcZone); ZoneName = ifcZone.Name; //Attributes var ifcAttributes = helper.GetAttributes(ifcZone); if (ifcAttributes != null && ifcAttributes.Any()) ZoneAttributes = new AttributeCollectionType { Attribute = ifcAttributes }; //TODO: //Space Issues //Space Documents }
public SystemType(IfcSystem ifcSystem, CoBieLiteHelper helper) : this() { externalEntityName = helper.ExternalEntityName(ifcSystem); externalID = helper.ExternalEntityIdentity(ifcSystem); externalSystemName = helper.ExternalSystemName(ifcSystem); SystemName = ifcSystem.Name; SystemDescription = ifcSystem.Description; SystemCategory = helper.GetClassification(ifcSystem); //Attributes var ifcAttributes = helper.GetAttributes(ifcSystem); if (ifcAttributes != null && ifcAttributes.Any()) SystemAttributes = new AttributeCollectionType { Attribute = ifcAttributes }; //TODO: //System Issues //System Documents }
public void ConvertCoBieLiteToJson() { using (var m = new XbimModel()) { var IfcTestFile = "2012-03-23-Duplex-Handover.ifc"; // IfcTestFile = @"D:\Users\steve\xBIM\Test Models\Autodesk\002ALakesiderestaurant.ifc"; var XbimTestFile = Path.ChangeExtension(IfcTestFile, "xbim"); m.CreateFrom(IfcTestFile, XbimTestFile, null, true, true); var helper = new CoBieLiteHelper(m, "UniClass"); var facilities = helper.GetFacilities(); foreach (var facilityType in facilities) { Assert.IsTrue(facilityType.FacilityDefaultLinearUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultAreaUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultVolumeUnitSpecified); CoBieLiteHelper.WriteJson(Console.Out, facilityType); } } }
//private IfcSpace _ifcSpace; public SpaceType(IfcSpace ifcSpace, CoBieLiteHelper helper) : this() { // _ifcSpace = ifcSpace; externalEntityName = helper.ExternalEntityName(ifcSpace); externalID = helper.ExternalEntityIdentity(ifcSpace); externalSystemName = helper.ExternalSystemName(ifcSpace); SpaceName = ifcSpace.Name; SpaceCategory = helper.GetClassification(ifcSpace); SpaceDescription = ifcSpace.Description; SpaceSignageName = helper.GetCoBieAttribute<StringValueType>("SpaceSignageName", ifcSpace).StringValue; SpaceUsableHeightValue = helper.GetCoBieAttribute<DecimalValueType>("SpaceUsableHeightValue", ifcSpace); SpaceGrossAreaValue = helper.GetCoBieAttribute<DecimalValueType>("SpaceGrossAreaValue", ifcSpace); SpaceNetAreaValue = helper.GetCoBieAttribute<DecimalValueType>("SpaceNetAreaValue", ifcSpace); //Zone Assignment var zones = helper.GetZones(ifcSpace); if (zones != null) { var ifcZones = zones.ToArray(); SpaceZoneAssignments = new ZoneAssignmentCollectionType { ZoneAssignment = new List<ZoneKeyType>(ifcZones.Length) }; for (int i = 0; i < ifcZones.Length; i++) { var zoneAssignment = new ZoneKeyType(); zoneAssignment.ZoneCategory = helper.GetClassification(ifcZones[i]); zoneAssignment.ZoneName = ifcZones[i].Name; zoneAssignment.externalIDReference = helper.ExternalEntityIdentity(ifcZones[i]); SpaceZoneAssignments.Add(zoneAssignment); } } //Attributes var ifcAttributes = helper.GetAttributes(ifcSpace); if (ifcAttributes != null && ifcAttributes.Any()) SpaceAttributes = new AttributeCollectionType { Attribute = ifcAttributes }; //TODO: //Space Issues //Space Documents }
static void Main(string[] args) { const string filename = "20200404CV.01.ifc"; using (var model = IfcStore.Open(filename)) { var context = new Xbim3DModelContext(model); context.CreateContext(); var wexBimFilename = Path.ChangeExtension(filename, "wexBim"); using (var wexBimfile = File.Create(wexBimFilename)) { using (var wexBimBinaryWriter = new BinaryWriter(wexBimfile)) { model.SaveAsWexBim(wexBimBinaryWriter); wexBimBinaryWriter.Close(); } wexBimfile.Close(); } string cobieFileName = Path.ChangeExtension(filename, "json"); using (var cobieFile = new FileStream(cobieFileName, FileMode.Create)) { var helper = new CoBieLiteHelper(model, "UniClass"); var fac = helper.GetFacilities().FirstOrDefault(); if (fac != null) { using (var writer = new StreamWriter(cobieFile)) { CoBieLiteHelper.WriteJson(writer, fac); writer.Close(); } } } model.Close(); } }
/// <summary> /// Writes out a contact, /// </summary> /// <param name="actor"></param> /// <param name="helper"></param> public ContactType(IfcActorSelect actor, CoBieLiteHelper helper) : this() { var personAndOrganization = actor as IfcPersonAndOrganization; var person = actor as IfcPerson; var organisation = actor as IfcOrganization; if (personAndOrganization != null) { ConvertOrganisation(personAndOrganization.TheOrganization, helper); ConvertPerson(personAndOrganization.ThePerson, helper); } else if(person!=null) ConvertPerson(person, helper); else if(organisation!=null) ConvertOrganisation(organisation, helper); ////Attributes //AttributeType[] ifcAttributes = helper.GetAttributes(actor); //if (ifcAttributes != null && ifcAttributes.Length > 0) // ContactAttributes = new AttributeCollectionType { Attribute = ifcAttributes }; }
public void ConvertCoBieLiteToJson() { var IfcTestFile = "2012-03-23-Duplex-Handover.ifc"; using (var m = IfcStore.Open(IfcTestFile)) { //IfcTestFile = @"D:\Users\steve\My Documents\DPoW\001 NBS Lakeside Restaurant 2014.ifc"; var xbimTestFile = Path.ChangeExtension(IfcTestFile, "xbim"); var jsonFile = Path.ChangeExtension(IfcTestFile, "json"); var helper = new CoBieLiteHelper(m, "UniClass"); var facilities = helper.GetFacilities(); foreach (var facilityType in facilities) { Assert.IsTrue(facilityType.FacilityDefaultLinearUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultAreaUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultVolumeUnitSpecified); using (var fs = new StreamWriter(jsonFile)) { CoBieLiteHelper.WriteJson(fs, facilityType); fs.Close(); } } } }
public SpaceKeyType(IfcSpace ifcSpace, CoBieLiteHelper helper) : this() { FloorName = helper.SpaceFloorLookup[ifcSpace].Name; SpaceName = ifcSpace.Name; }
public void ConvertCoBieLiteToXml() { using (var m = new XbimModel()) { const string ifcTestFile = "2012-03-23-Duplex-Handover.ifc"; // var IfcTestFile = @"D:\Users\steve\xBIM\Test Models\BimAlliance BillEast\Model 1 Duplex Apartment\Duplex_MEP_20110907.ifc"; var xbimTestFile = Path.ChangeExtension(ifcTestFile, "xbim"); m.CreateFrom(ifcTestFile, xbimTestFile, null, true, true); var helper = new CoBieLiteHelper(m, "UniClass"); var facilities = helper.GetFacilities(); var i = 1; foreach (var facilityType in facilities) { Assert.IsTrue(facilityType.FacilityDefaultLinearUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultAreaUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultVolumeUnitSpecified); var outName = string.Format("Facility{0}.xml", i++); using (TextWriter writer = File.CreateText(outName)) { CoBieLiteHelper.WriteXml(writer, facilityType); } CoBieLiteHelper.WriteXml(Console.Out, facilityType); // attempt reading CoBieLiteHelper.ReadXml(outName); } } }
private static List<IfcTypeObject> AllAssetTypesInThisFacility(IfcBuilding ifcBuilding, HashSet<IfcElement> allAssetsinThisFacility, CoBieLiteHelper helper) { var allAssetTypes = helper.DefiningTypeObjectMap; var allAssetTypesInThisFacility = new List<IfcTypeObject>(allAssetTypes.Count); foreach (var assetTypeKeyValue in allAssetTypes) { //if any defining type has an object in this building/facility then we need to include it if (assetTypeKeyValue.Value.Any(allAssetsinThisFacility.Contains)) allAssetTypesInThisFacility.Add(assetTypeKeyValue.Key); } return allAssetTypesInThisFacility; }
public static string ConvertToWexbim(string fileName, int roomId, bool createJson = false) { var wexBimFilename = Path.ChangeExtension(fileName, "wexbim"); byte[] temp; using (ISelect select = new QQContext()) { temp = select.GetRoomModel ( roomId ); } if (temp == null) { return(null); } File.WriteAllBytes ( fileName, temp ); using (var model = IfcStore.Open(fileName)) { var context = new Xbim3DModelContext(model); context.CreateContext(); using (var wexBiMfile = File.Create(wexBimFilename)) { using (var wexBimBinaryWriter = new BinaryWriter(wexBiMfile)) { model.SaveAsWexBim(wexBimBinaryWriter); wexBimBinaryWriter.Close(); } wexBiMfile.Close(); } if (createJson) { var cobieFileName = Path.ChangeExtension ( fileName, "json" ); using (var cobieFile = new FileStream ( cobieFileName, FileMode.Create )) { var helper = new CoBieLiteHelper ( model, "UniClass" ); var facility = helper.GetFacilities() .FirstOrDefault(); if (facility != null) { using (var writer = new StreamWriter ( cobieFile )) { CoBieLiteHelper.WriteJson ( writer, facility ); writer.Close(); } } } } } File.Delete(fileName); return(wexBimFilename); }
public void ConvertCoBieLiteToIfc() { using (var m = new XbimModel()) { m.CreateFrom("2012-03-23-Duplex-Handover.ifc", "2012-03-23-Duplex-Handover.xbim", null, true, true); var helper = new CoBieLiteHelper(m, "UniClass"); var facilities = helper.GetFacilities(); foreach (var facilityType in facilities) { using (new FileStream("facility.bson", FileMode.Create)) { helper.WriteIfc(Console.Out, facilityType); } } } }
private IEnumerable<IfcZone> GetAllZones(IEnumerable<IfcSpace> allSpaces, CoBieLiteHelper helper) { var allZones = new HashSet<IfcZone>(); foreach (var space in allSpaces) foreach (var zone in helper.GetZones(space)) allZones.Add(zone); return allZones; }
private void SetDefaultUnits(CoBieLiteHelper helper) { if ((FacilityDefaultAreaUnitSpecified = helper.HasAreaUnit) == true) facilityDefaultAreaUnitField = helper.ModelAreaUnit; if ((FacilityDefaultLinearUnitSpecified = helper.HasLinearUnit) == true) facilityDefaultLinearUnitField = helper.ModelLinearUnit; if ((FacilityDefaultVolumeUnitSpecified = helper.HasVolumeUnit) == true) facilityDefaultVolumeUnitField = helper.ModelVolumeUnit; if ((FacilityDefaultCurrencyUnitSpecified = helper.HasCurrencyUnit) == true) facilityDefaultCurrencyUnitField = helper.ModelCurrencyUnit; }
public FacilityType(IfcBuilding ifcBuilding, CoBieLiteHelper helper) : this() { // _ifcBuilding = ifcBuilding; var model = ifcBuilding.ModelOf; externalEntityName = helper.ExternalEntityName(ifcBuilding); externalID = helper.ExternalEntityIdentity(ifcBuilding); externalSystemName = helper.ExternalSystemName(ifcBuilding); FacilityName = ifcBuilding.Name; FacilityDescription = ifcBuilding.Description; FacilityCategory = helper.GetClassification(ifcBuilding); var ifcProject = model.Instances.OfType<IfcProject>().FirstOrDefault(); if (ifcProject != null) { ProjectAssignment = new ProjectType(ifcProject, helper); var ifcSite = ifcProject.GetSpatialStructuralElements().FirstOrDefault(p => p is IfcSite) as IfcSite; if (ifcSite != null) SiteAssignment = new SiteType(ifcSite, helper); SetDefaultUnits(helper); FacilityDeliverablePhaseName = ifcProject.Phase; var storeys = ifcBuilding.GetBuildingStoreys(true); var ifcBuildingStories = storeys as IList<IfcBuildingStorey> ?? storeys.ToList(); if (ifcBuildingStories.Any()) { Floors = new FloorCollectionType {Floor = new List<FloorType>(ifcBuildingStories.Count)}; for (int i = 0; i < ifcBuildingStories.Count; i++) { Floors.Add(new FloorType(ifcBuildingStories[i], helper)); } } } //Attributes var ifcAttributes = helper.GetAttributes(ifcBuilding); if (ifcAttributes != null && ifcAttributes.Any()) FacilityAttributes = new AttributeCollectionType {Attribute = ifcAttributes}; //Zones var allSpaces = GetAllSpaces(ifcBuilding); var allZones = GetAllZones(allSpaces, helper); var ifcZones = allZones.ToArray(); if (ifcZones.Any()) { Zones = new ZoneCollectionType {Zone = new List<ZoneType>(ifcZones.Length)}; for (int i = 0; i < ifcZones.Length; i++) { Zones.Add(new ZoneType(ifcZones[i], helper)); } } //Assets var allAssetsinThisFacility = new HashSet<IfcElement>(helper.GetAllAssets(ifcBuilding)); //AssetTypes //Get all assets that are in this facility/building var allAssetTypesInThisFacility = AllAssetTypesInThisFacility(ifcBuilding, allAssetsinThisFacility, helper); if (allAssetTypesInThisFacility.Any()) { AssetTypes = new AssetTypeCollectionType { AssetType = new List<AssetTypeInfoType>(allAssetTypesInThisFacility.Count) }; for (int i = 0; i < allAssetTypesInThisFacility.Count; i++) { AssetTypes.Add(new AssetTypeInfoType(allAssetTypesInThisFacility[i], helper)); } } //Systems var allSystemsInThisFacility = helper.SystemAssignment .Where(v => v.Value.Any(allAssetsinThisFacility.Contains)) .Select(k => k.Key).ToArray(); if (allSystemsInThisFacility.Any()) { Systems = new SystemCollectionType { System = new List<SystemType>(allSystemsInThisFacility.Length) }; for (int i = 0; i < allSystemsInThisFacility.Length; i++) { Systems.Add(new SystemType(allSystemsInThisFacility[i], helper)); } } //Contacts var contacts = helper.GetContacts(); var ifcActors = contacts as IfcActorSelect[] ?? contacts.ToArray(); if (ifcActors.Any()) { Contacts = new ContactCollectionType { Contact = new List<ContactType>(ifcActors.Length) }; for (int i = 0; i < ifcActors.Length; i++) { Contacts.Add(new ContactType(ifcActors[i], helper)); } } }
public static void ConvertIfcToWexbimAndCobie(Stream input, CloudBlockBlob outputWexbimBlob, CloudBlockBlob outputCobieBlob, string inputExtension) { //temp files var fileName = Path.GetTempPath() + Guid.NewGuid() + inputExtension; var xbimFileName = Path.ChangeExtension(fileName, ".xBIM"); var wexBimFileName = Path.ChangeExtension(fileName, ".wexBIM"); var cobieFileName = Path.ChangeExtension(fileName, ".json"); try { using (var fileStream = File.OpenWrite(fileName)) { input.CopyTo(fileStream); fileStream.Flush(); fileStream.Close(); //open the model and import using (var model = new XbimModel()) { model.CreateFrom(fileName, null, null, true); var m3DModelContext = new Xbim3DModelContext(model); using (var wexBimFile = new FileStream(wexBimFileName, FileMode.Create)) { using (var bw = new BinaryWriter(wexBimFile)) { m3DModelContext.CreateContext(XbimGeometryType.PolyhedronBinary); m3DModelContext.Write(bw); bw.Close(); wexBimFile.Close(); outputWexbimBlob.UploadFromFile(wexBimFileName, FileMode.Open); } } using (var cobieFile = new FileStream(cobieFileName, FileMode.Create)) { var helper = new CoBieLiteHelper(model, "UniClass"); var facility = helper.GetFacilities().FirstOrDefault(); if (facility != null) { using (var writer = new StreamWriter(cobieFile)) { CoBieLiteHelper.WriteJson(writer, facility); writer.Close(); outputCobieBlob.UploadFromFile(cobieFileName, FileMode.Open); } } } model.Close(); } } } finally { //tidy up if (File.Exists(fileName)) { File.Delete(fileName); } if (File.Exists(xbimFileName)) { File.Delete(xbimFileName); } if (File.Exists(wexBimFileName)) { File.Delete(wexBimFileName); } if (File.Exists(cobieFileName)) { File.Delete(cobieFileName); } } }
public AssetTypeInfoType(IfcTypeObject ifcTypeObject, CoBieLiteHelper helper) : this() { externalEntityName = helper.ExternalEntityName(ifcTypeObject); externalID = helper.ExternalEntityIdentity(ifcTypeObject); externalSystemName = helper.ExternalSystemName(ifcTypeObject); AssetTypeName = ifcTypeObject.Name; AssetTypeCategory = helper.GetClassification(ifcTypeObject); string accCategoryString = helper.GetCoBieProperty("AssetTypeAccountingCategory", ifcTypeObject); AssetPortabilitySimpleType accCategoryEnum; if (Enum.TryParse(accCategoryString, true, out accCategoryEnum)) AssetTypeAccountingCategory = accCategoryEnum; else { CoBieLiteHelper.Logger.WarnFormat("AssetTypeAccountingCategory: An illegal value of [{0}] has been passed for the category of #{1}={2}. It has been replaced with a value of 'Item'", accCategoryString, ifcTypeObject.EntityLabel, ifcTypeObject.GetType().Name); AssetTypeAccountingCategory = AssetPortabilitySimpleType.Item; } if (string.IsNullOrWhiteSpace(AssetTypeCategory)) //try the asset assignment { IfcAsset ifcAsset; if(helper.AssetAsignments.TryGetValue(ifcTypeObject, out ifcAsset)) AssetTypeCategory = helper.GetCoBieAttribute<StringValueType>("AssetTypeAccountingCategory", ifcAsset).StringValue; } AssetTypeDescription = ifcTypeObject.Description; AssetTypeModelNumber = helper.GetCoBieProperty("AssetTypeModelNumber", ifcTypeObject); AssetTypeReplacementCostValue = helper.GetCoBieAttribute<DecimalValueType>("AssetTypeReplacementCostValue", ifcTypeObject); AssetTypeExpectedLifeValue = helper.GetCoBieAttribute<IntegerValueType>("AssetTypeExpectedLifeValue", ifcTypeObject); AssetTypeNominalLength = helper.GetCoBieAttribute<DecimalValueType>("AssetTypeNominalLength", ifcTypeObject); AssetTypeNominalWidth = helper.GetCoBieAttribute<DecimalValueType>("AssetTypeNominalWidth", ifcTypeObject); AssetTypeNominalHeight = helper.GetCoBieAttribute<DecimalValueType>("AssetTypeNominalHeight", ifcTypeObject); AssetTypeAccessibilityText = helper.GetCoBieProperty("AssetTypeAccessibilityText", ifcTypeObject); AssetTypeColorCode = helper.GetCoBieProperty("AssetTypeColorCode", ifcTypeObject); AssetTypeConstituentsDescription = helper.GetCoBieProperty("AssetTypeConstituentsDescription", ifcTypeObject); AssetTypeFeaturesDescription = helper.GetCoBieProperty("AssetTypeFeaturesDescription", ifcTypeObject); AssetTypeGradeDescription = helper.GetCoBieProperty("AssetTypeGradeDescription", ifcTypeObject); AssetTypeMaterialDescription = helper.GetCoBieProperty("AssetTypeMaterialDescription", ifcTypeObject); AssetTypeShapeDescription = helper.GetCoBieProperty("AssetTypeShapeDescription", ifcTypeObject); AssetTypeSizeDescription = helper.GetCoBieProperty("AssetTypeSizeDescription", ifcTypeObject); AssetTypeSustainabilityPerformanceDescription = helper.GetCoBieProperty("AssetTypeSustainabilityPerformanceDescription", ifcTypeObject); //The Assets List<IfcElement> allAssetsofThisType; if (helper.DefiningTypeObjectMap.TryGetValue(ifcTypeObject, out allAssetsofThisType)) //should always work { Assets = new AssetCollectionType { Asset = new List<AssetInfoType>(allAssetsofThisType.Count)}; foreach (IfcElement t in allAssetsofThisType) { Assets.Add(new AssetInfoType(t, helper)); } } else { //just in case we have a problem CoBieLiteHelper.Logger.ErrorFormat("Asset Type: Failed to locate Asset Type #{0}={1}", ifcTypeObject.EntityLabel,ifcTypeObject.GetType().Name); } //Attributes var ifcAttributes = helper.GetAttributes(ifcTypeObject); if (ifcAttributes != null && ifcAttributes.Any()) AssetTypeAttributes = new AttributeCollectionType { Attribute = ifcAttributes }; }
private void ConvertPerson(IfcPerson ifcPerson, CoBieLiteHelper helper) { ContactFamilyName = ifcPerson.FamilyName; ContactGivenName = ifcPerson.GivenName; if (ifcPerson.Addresses != null) { var telecom = ifcPerson.Addresses.OfType<IfcTelecomAddress>(); var postal = ifcPerson.Addresses.OfType<IfcPostalAddress>(); var ifcTelecomAddresses = telecom as IfcTelecomAddress[] ?? telecom.ToArray(); if (ifcTelecomAddresses.Any()) { var emailAddresses = string.Join(";", ifcTelecomAddresses.Where(t => t.ElectronicMailAddresses!=null).SelectMany(t => t.ElectronicMailAddresses)); if (!string.IsNullOrWhiteSpace(emailAddresses)) ContactEmail = string.Join(";", emailAddresses, ContactEmail ?? ""); var phoneNums = string.Join(";", ifcTelecomAddresses.Where(t => t.TelephoneNumbers!=null).SelectMany(t => t.TelephoneNumbers)); if (!string.IsNullOrWhiteSpace(phoneNums)) ContactPhoneNumber = string.Join(";", phoneNums, ContactPhoneNumber ?? ""); var url = string.Join(";", ifcTelecomAddresses.Where(p => p.WWWHomePageURL.HasValue).SelectMany(p => p.WWWHomePageURL.ToString())); if (!string.IsNullOrWhiteSpace(url)) ContactURL = string.Join(";", url, ContactURL ?? ""); ; } var ifcPostalAddresses = postal as IfcPostalAddress[] ?? postal.ToArray(); if (ifcPostalAddresses.Any()) { var deptNames = string.Join(";", ifcPostalAddresses.Where(p => p.InternalLocation.HasValue).SelectMany(p => p.InternalLocation.ToString())); if (!string.IsNullOrWhiteSpace(deptNames)) ContactDepartmentName = string.Join(";", deptNames,ContactDepartmentName??""); var streetNames = string.Join(";", ifcPostalAddresses.Where(p => p.AddressLines != null).SelectMany(p => p.AddressLines.ToString())); if (!string.IsNullOrWhiteSpace(streetNames)) ContactStreet = string.Join(";", streetNames, ContactStreet ?? ""); var postalBox = string.Join(";", ifcPostalAddresses.Where(p => p.PostalBox.HasValue).SelectMany(p => p.PostalBox.ToString())); if (!string.IsNullOrWhiteSpace(postalBox)) ContactPostalBoxNumber = string.Join(";", postalBox, ContactPostalBoxNumber ?? ""); var town = string.Join(";", ifcPostalAddresses.Where(p => p.Town.HasValue).SelectMany(p => p.Town.ToString())); if (!string.IsNullOrWhiteSpace(town)) ContactTownName = string.Join(";", town, ContactTownName ?? ""); var region = string.Join(";", ifcPostalAddresses.Where(p => p.Region.HasValue).SelectMany(p => p.Region.ToString())); if (!string.IsNullOrWhiteSpace(region)) ContactRegionCode = string.Join(";", region, ContactRegionCode ?? ""); var postalCode = string.Join(";", ifcPostalAddresses.Where(p => p.PostalCode.HasValue).SelectMany(p => p.PostalCode.ToString())); if (!string.IsNullOrWhiteSpace(postalCode)) ContactPostalCode = string.Join(";", postalCode, ContactPostalCode ?? ""); } } if (ifcPerson.Roles != null) { var roles = string.Join(";", ifcPerson.Roles.SelectMany(r => r.RoleString)); //deals with User defined roles if (!string.IsNullOrWhiteSpace(roles)) ContactCategory = string.Join(";", roles, ContactCategory ?? ""); } }
public SystemKeyType(IfcSystem ifcSystem, CoBieLiteHelper helper) { SystemCategory = helper.GetClassification(ifcSystem); SystemName = ifcSystem.Name; externalIDReference = helper.ExternalEntityIdentity(ifcSystem); }
public void ConvertCoBieLiteToBson() { using (var m = new XbimModel()) { const string ifcTestFile = "2012-03-23-Duplex-Handover.ifc"; // IfcTestFile = @"C:\Data\dev\XbimTeam\XbimExchange\Tests\TestFiles\Standard_Classroom_CIC_6_Project_mod2.ifc"; var xbimTestFile = Path.ChangeExtension(ifcTestFile, "xbim"); m.CreateFrom(ifcTestFile, xbimTestFile, null, true, true); var helper = new CoBieLiteHelper(m, "UniClass"); var facilities = helper.GetFacilities(); foreach (var facilityType in facilities) { Assert.IsTrue(facilityType.FacilityDefaultLinearUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultAreaUnitSpecified); Assert.IsTrue(facilityType.FacilityDefaultVolumeUnitSpecified); using (var sw = new FileStream("facility.bson",FileMode.Create)) { using (var bw = new BinaryWriter(sw)) { CoBieLiteHelper.WriteBson(bw, facilityType); } } } } }