public static IfcSettings DefaultIfNull(this IfcSettings settings) { if (settings == null) { settings = new IfcSettings(); BH.Engine.Reflection.Compute.RecordNote("Settings have not been specified, default settings are used."); } return(settings); }
public IfcAdapter(string targetLocation, IfcSettings settings = null, bool active = false) { if (active) { if (Init(targetLocation)) { IFCSettings = settings; } } }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ public static Floor FloorFromIfc(this IIfcSlab element, IfcSettings settings) { if (element == null) { BH.Engine.Reflection.Compute.RecordError("The IFC element could not be converted because it was null."); return(null); } settings = settings.DefaultIfNull(); //TODO: refine this! return(new Floor { Name = element.Name }); }
/***************************************************/ /**** Public Methods ****/ /***************************************************/ protected override IEnumerable <IBHoMObject> Read(IRequest request, ActionConfig actionConfig = null) { if (request == null) { BH.Engine.Reflection.Compute.RecordError("The request is null, pull failed."); return(new List <IBHoMObject>()); } // Get the toolkit-specific PullConfig IfcPullConfig config = actionConfig as IfcPullConfig; if (config == null) { config = new IfcPullConfig(); BH.Engine.Reflection.Compute.RecordNote("Config has not been specified, default config is used."); } // Get the settings IfcSettings settings = this.IFCSettings.DefaultIfNull(); // Get the discipline coming from the request/PullConfig Discipline?requestDiscipline = request.Discipline(config.Discipline); if (requestDiscipline == null) { BH.Engine.Reflection.Compute.RecordError("Conflicting disciplines have been detected."); return(new List <IBHoMObject>()); } Discipline discipline = requestDiscipline.Value; // If instructed to pull mesh representations, the below variable will be assigned List <XbimShapeInstance> shapeInstances = null; if (config.PullMeshes) { if (m_3DContext == null) { m_3DContext = new Xbim3DModelContext(m_LoadedModel); m_3DContext.CreateContext(); } shapeInstances = m_3DContext.ShapeInstances().ToList(); } List <IBHoMObject> result = new List <IBHoMObject>(); foreach (var entity in m_LoadedModel.IIfcEntities(request)) { IIfcProduct element = entity as IIfcProduct; if (element == null) { continue; } IEnumerable <IBHoMObject> converted = element.IFromIfc(discipline, settings); // Pull mesh representations if requested in PullConfig if (shapeInstances != null) { List <Mesh> meshes = shapeInstances.Where(x => x.IfcProductLabel == element.EntityLabel).SelectMany(x => x.Meshes(m_3DContext)).ToList(); IfcRepresentation representation = new IfcRepresentation(meshes); foreach (IBHoMObject obj in converted) { obj.Fragments.Add(representation); } } result.AddRange(converted); } return(result); }
/***************************************************/ public static IEnumerable <IBHoMObject> FromIfc(this IIfcSpace element, Discipline discipline, IfcSettings settings) { switch (discipline) { default: return(new List <IBHoMObject> { element.SpaceFromIfc(settings) }); } }
/***************************************************/ /**** Interface Methods ****/ /***************************************************/ public static IEnumerable <IBHoMObject> IFromIfc(this IIfcProduct element, Discipline discipline, IfcSettings settings = null) { IEnumerable <IBHoMObject> result = FromIfc(element as dynamic, discipline, settings); if (result == null) { BH.Engine.Reflection.Compute.RecordError($"IFC element conversion to BHoM failed for discipline {discipline}. A CustomObject is returned instead."); return(new List <IBHoMObject> { new CustomObject { Name = element.Name } }); } return(result); }