public TransformNode(IIfcProduct prod) { if (prod != null) { _productLabel = prod.EntityLabel; } }
private static void CreateSimpleProperty(IfcStore model, IIfcProduct product) { var ifcPropertySingleValue = model.Instances.New <IfcPropertySingleValue>(psv => { psv.Name = "IfcPropertySingleValue:Time"; psv.Description = ""; psv.NominalValue = new IfcTimeMeasure(150.0); psv.Unit = model.Instances.New <IfcSIUnit>(siu => { siu.UnitType = IfcUnitEnum.TIMEUNIT; siu.Name = IfcSIUnitName.SECOND; }); }); //lets create the IfcElementQuantity var ifcPropertySet = model.Instances.New <IfcPropertySet>(ps => { ps.Name = "Test:IfcPropertySet"; ps.Description = "Property Set"; ps.HasProperties.Add(ifcPropertySingleValue); }); //need to create the relationship model.Instances.New <IfcRelDefinesByProperties>(rdbp => { rdbp.Name = "Property Association"; rdbp.Description = "IfcPropertySet associated to wall"; rdbp.RelatedObjects.Add(product as IfcProduct); rdbp.RelatingPropertyDefinition = ifcPropertySet; }); }
public Dictionary <string, IfcObjectAttributes> GetObjectsOfClass(string classname) { Dictionary <string, IfcObjectAttributes> objs = new Dictionary <string, IfcObjectAttributes>(); foreach (var obj in _model.Instances.Where(x => x.GetType().Name.Equals(classname))) { if (obj is IIfcObject) { IIfcObject ifcObj = (IIfcObject)obj; bool hasGeometry = false; if (obj is IIfcProduct) { IIfcProduct prod = (IIfcProduct)obj; if (prod.Representation != null) { hasGeometry = true; } } objs.Add(ifcObj.GlobalId, new IfcObjectAttributes { Name = ifcObj.Name, Description = ifcObj.Description, GlobalId = ifcObj.GlobalId, Namespace = obj.GetType().Namespace, IfcType = obj.GetType().Name, HasGeometry = hasGeometry }); } } return(objs); }
private static IIfcValue GetArea(IIfcProduct product) { //try to get the value from quantities first var area = //get all relations which can define property and quantity sets product.IsDefinedBy //Search across all property and quantity sets. //You might also want to search in a specific quantity set by name .SelectMany(r => r.RelatingPropertyDefinition.PropertySetDefinitions) //Only consider quantity sets in this case. .OfType <IIfcElementQuantity>() //Get all quantities from all quantity sets .SelectMany(qset => qset.Quantities) //We are only interested in areas .OfType <IIfcQuantityArea>() //We will take the first one. There might obviously be more than one area properties //so you might want to check the name. But we will keep it simple for this example. .FirstOrDefault()? .AreaValue; if (area != null) { return(area); } //try to get the value from properties return(GetProperty(product, "Area")); }
private static IIfcValue GetProperty(IIfcProduct product, string name) { return //get all relations which can define property and quantity sets (product.IsDefinedBy //Search across all property and quantity sets. You might also want to search in a specific property set .SelectMany(r => r.RelatingPropertyDefinition.PropertySetDefinitions) //Only consider property sets in this case. .OfType <IIfcPropertySet>() //Get all properties from all property sets .SelectMany(pset => pset.HasProperties) //lets only consider single value properties. There are also enumerated properties, //table properties, reference properties, complex properties and other .OfType <IIfcPropertySingleValue>() //lets make the name comparison more fuzzy. This might not be the best practise .Where(p => string.Equals(p.Name, name, System.StringComparison.OrdinalIgnoreCase) || p.Name.ToString().ToLower().Contains(name.ToLower())) //only take the first. In reality you should handle this more carefully. .FirstOrDefault()?.NominalValue); }
/// <summary> /// 获取一个ifcproduct的boundingbox /// </summary> /// <param name="product">指定的product</param> /// <returns>XbimRect3D精度为2位的盒子</returns> public XbimRect3D GetAABB(IIfcProduct product) { //Xbim3DModelContext context = new Xbim3DModelContext(model); //context.CreateContext(); XbimRect3D prodBox = XbimRect3D.Empty; if (context.ShapeInstancesOf(product).Count() == 0) { return(prodBox); } foreach (var shp in context.ShapeInstancesOf(product)) { var bb = shp.BoundingBox; bb = XbimRect3D.TransformBy(bb, shp.Transformation); if (prodBox.IsEmpty) { prodBox = bb; } else { prodBox.Union(bb); } } //精度为2位小数 prodBox.Round(2); return(prodBox); //Console.WriteLine(prodBox.ToString()); }
// Creates a new component descriptor private Component CreateComponent(IIfcProduct product, IEnumerable <Classifier> concepts, out int?optParentLabel) { var parent = product.Parent <IIfcProduct>().FirstOrDefault(); var component = new Component { Id = product.GlobalId.ToGlobalUniqueId(), // -1 reserved for roots Parent = parent?.GlobalId.ToGlobalUniqueId(), Name = product.Name ?? "", }; // Add IFC express type by default component.Concepts.Add(CommonExtensions.DefaultXbimEntityQualifier(product).ToClassifier()); // Add additiona user qualifiers foreach (var userProductQualifier in Settings.UserProductQualifier) { component.Concepts.Add(userProductQualifier(product).ToClassifier()); } component.Concepts.AddRange(concepts); component.Children.AddRange(product.Children <IIfcProduct>().Select(p => p.GlobalId.ToGlobalUniqueId())); optParentLabel = parent?.EntityLabel; return(component); }
private static XbimShapeTriangulation GetMeshes(Xbim3DModelContext context, IIfcProduct product) { XbimShapeTriangulation ifcMesh = null;; var productShape = context.ShapeInstancesOf(product) .Where(p => p.RepresentationType != XbimGeometryRepresentationType.OpeningsAndAdditionsExcluded) .Distinct(); if (productShape.Any()) { var shapeInstance = productShape.FirstOrDefault(); var shapeGeometry = context.ShapeGeometry(shapeInstance.ShapeGeometryLabel); byte[] data = ((IXbimShapeGeometryData)shapeGeometry).ShapeData; //If you want to get all the faces and triangulation use this using (var stream = new MemoryStream(data)) { using (var reader = new BinaryReader(stream)) { ifcMesh = reader.ReadShapeTriangulation(); } } } return(ifcMesh); }
//初始化ProductData private static void SetProductData(ProductData pd, IIfcProduct p) { pd.ProductName = p.Name; pd.TypeName = p.GetType().Name; pd.TheGameObject.name = pd.ProductName + "[" + pd.TypeName + "]" + pd.ProductGeometryData.productLabel; pd.TheProduct = p; pd.HaveSpatialStructure = true; }
/// <summary> /// Wrap subsequent product creation by given product into a assembly group. /// </summary> /// <param name="p">The new group product</param> public void NewScope(IIfcProduct p) { if (_ContainerScope.Any(e => e == p)) { throw new ArgumentException($"#{p.EntityLabel} already scoped."); } NewContainer(p); }
public void SetProductData(IIfcProduct iProduct) { ProductName = iProduct.Name; TypeName = iProduct.GetType().Name; //ThisGameObject.name = pd.ProductName + "[" + pd.TypeName + "]#" + pd.ProductGeoData.entityLabel; gameObject.name = ProductName + "[" + TypeName + "]#" + bimProduct.entityLabel; IFCProduct = iProduct;//看需要判断删不删掉 HaveSpatialStructure = true; }
protected XbimMatrix3D PlacementOf(IIfcProduct p) { XbimPlacementTree tree; if (!Placements.TryGetValue(p.Model, out tree)) { tree = new XbimPlacementTree(p.Model, false); Placements.Add(p.Model, tree); } return(XbimPlacementTree.GetTransform(p, tree, Engine)); }
private static IIfcValue GetProperty(IIfcProduct product, string name) { var area = product.IsDefinedBy.SelectMany(r => r.RelatingPropertyDefinition.PropertySetDefinitions) .OfType <IIfcPropertySet>() .SelectMany(pset => pset.HasProperties) .OfType <IIfcPropertySingleValue>() .Where(p => string.Equals(p.Name, name, System.StringComparison.OrdinalIgnoreCase) || p.Name.ToString().ToLower().Contains(name.ToLower())) .FirstOrDefault() .NominalValue; return(area); }
void process_query() { IEnumerator <string> selectenum = select.GetEnumerator(); IEnumerator <string> fromenum = from.GetEnumerator(); IEnumerator <string> whereenum = where.GetEnumerator(); var model = IfcStore.Open(fileName); using (var txn = model.BeginTransaction()) { var requiredProducts = new IIfcProduct[0] .Concat(model.Instances.OfType <IIfcBuildingElement>()) .Concat(model.Instances.OfType <IIfcSpatialElement>()); //.Concat(model.Instances.OfType<IIfcWallStandardCase>()) //.Concat(model.Instances.OfType<IIfcDoor>()) //.Concat(model.Instances.OfType<IIfcWindow>()); foreach (var o in requiredProducts) { var spatialElement = o as IIfcSpatialStructureElement; if (spatialElement != null) { //using IfcRelContainedInSpatialElement to get contained elements var containedElements = spatialElement.ContainsElements.SelectMany(rel => rel.RelatedElements); if (containedElements != null) { foreach (var fromvalue in select) { //foreach (var element2 in containedElements) //output= output+ System.Environment.NewLine + string.Format("{0} ->{1} ", element2.Name, element2.GetType().Name); var requiredelement = from element in containedElements where element.GetType().Name.ToString() == fromvalue.ToString() select element; foreach (var element2 in requiredelement) { output = output + System.Environment.NewLine + string.Format("{0} ->{1} ", element2.GetType().Name, element2.Name); } } } } } txn.Commit(); } }
/// <summary> /// This function centralises the extraction of a product placement, but it needs the support of XbimPlacementTree and an XbimGeometryEngine /// We should probably find a conceptual place for it somewhere in the scene, where these are cached. /// </summary> public static XbimMatrix3D GetTransform(IIfcProduct product, XbimPlacementTree tree, XbimGeometryEngine engine) { XbimMatrix3D placementTransform = XbimMatrix3D.Identity; if (product.ObjectPlacement is IIfcLocalPlacement) { placementTransform = tree[product.ObjectPlacement.EntityLabel]; } else if (product.ObjectPlacement is IIfcGridPlacement) { placementTransform = engine.ToMatrix3D((IIfcGridPlacement)product.ObjectPlacement, null); } return(placementTransform); }
public static DiffuseMaterial GetStyleFromXbimModel(IIfcProduct item, Xbim3DModelContext context, double opacity = 1) { // var context = new Xbim3DModelContext(item.Model); // context.CreateContext(); var productShape = context.ShapeInstancesOf(item) .Where(s => s.RepresentationType != XbimGeometryRepresentationType.OpeningsAndAdditionsExcluded) .ToList(); Material wpfMaterial = GetWpfMaterial(item.Model, productShape.Count > 0 ? productShape[0].StyleLabel : 0); Material newmaterial = wpfMaterial.Clone(); ((DiffuseMaterial)newmaterial).Brush.Opacity = opacity; return(newmaterial as DiffuseMaterial); }
public TransformNode this[IIfcProduct product] { get { var pl = product.ObjectPlacement; if (pl == null) { return(null); } TransformNode node; return(_placementNodes.TryGetValue(pl, out node) ? node : null); } }
private void InitProduct(IIfcProduct product) { var cScope = CurrentScope; if (cScope is IIfcSpatialStructureElement e) { // If spatial container at head, create containment Store.NewContains(e).RelatedElements.Add(product); } else { // Otherwise create an aggregation relation Store.NewDecomposes(cScope).RelatedObjects.Add(product); } }
private static IIfcValue GetVolume(IIfcProduct product) { var volume = product.IsDefinedBy .SelectMany(r => r.RelatingPropertyDefinition.PropertySetDefinitions) .OfType <IIfcElementQuantity>() .SelectMany(qset => qset.Quantities) .OfType <IIfcQuantityVolume>() .FirstOrDefault()?.VolumeValue; if (volume != null) { return(volume); } return(GetProperty(product, "Volume")); }
public static MeshGeometry3D WriteTriangles(IIfcProduct ifcElement, Xbim3DModelContext context, XbimMatrix3D wcsTransformation) { MeshBuilder meshBuilder = new MeshBuilder(false, false); // var allTriangles = new List<Triangles>(); // foreach (XbimShapeInstance instance in context.ShapeInstancesOf(ifcElement).Where(x => x.RepresentationType == XbimGeometryRepresentationType.OpeningsAndAdditionsIncluded)) foreach (XbimShapeInstance instance in context.ShapeInstancesOf(ifcElement).Where(x => x.RepresentationType == XbimGeometryRepresentationType.OpeningsAndAdditionsIncluded)) { XbimShapeGeometry geometry = context.ShapeGeometry(instance); var data = ((IXbimShapeGeometryData)geometry).ShapeData; using (var stream = new MemoryStream(data)) { using (var reader = new BinaryReader(stream)) { XbimShapeTriangulation mesh = reader.ReadShapeTriangulation(); mesh = mesh.Transform(instance.Transformation); // WCS transforms mesh = mesh.Transform(wcsTransformation); foreach (XbimFaceTriangulation face in mesh.Faces) { var j = 0; for (var i = 0; i < face.TriangleCount; i++) { int k = i + j; var point1 = new Point3D { X = mesh.Vertices[face.Indices[k]].X, Y = mesh.Vertices[face.Indices[k]].Y, Z = mesh.Vertices[face.Indices[k]].Z }; j++; k = i + j; var point2 = new Point3D { X = mesh.Vertices[face.Indices[k]].X, Y = mesh.Vertices[face.Indices[k]].Y, Z = mesh.Vertices[face.Indices[k]].Z }; j++; k = i + j; var point3 = new Point3D { X = mesh.Vertices[face.Indices[k]].X, Y = mesh.Vertices[face.Indices[k]].Y, Z = mesh.Vertices[face.Indices[k]].Z }; meshBuilder.AddTriangle(point1, point2, point3); } } } } } return(meshBuilder.ToMesh()); // return allTriangles; }
public static void SelectionWithLinq() { const string ifcFilename = "SampleHouse.ifc"; var model = IfcStore.Open(ifcFilename); var requiredProducts = new IIfcProduct[0] .Concat(model.Instances.OfType <IIfcWallStandardCase>()) .Concat(model.Instances.OfType <IIfcDoor>()) .Concat(model.Instances.OfType <IIfcWindow>()); //This will only iterate over entities you really need (9 in this case) foreach (var product in requiredProducts) { //Do anything you want here... } }
/***************************************************/ /**** 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); }
public string GetProductId(int selectedLabel) { IIfcProduct Product = IFCConverter.Products.Where(p => p.EntityLabel == selectedLabel).FirstOrDefault(); if (Product != null) { string ProductId = Product.Name.Value.Value.ToString().Split(':')[2]; return(ProductId); } else { IIfcRelDefinesByType relType = IFCConverter.ModelTypes.Where(t => t.RelatingType.EntityLabel == selectedLabel).FirstOrDefault(); string typeName = relType.RelatingType.Name.ToString(); return(typeName); } }
private IIfcSpatialStructureElement FindContainer(IIfcProduct injected) { switch (InjectorMode) { case IfcModelInjectorMode.SingletonContainer: return(ContainerCandidate.FirstOrDefault()); case IfcModelInjectorMode.NameMatchingContainer: case IfcModelInjectorMode.CaseSensitiveNameMatchingContainer: case IfcModelInjectorMode.ZValueStoreyMatchingContainer: var msg = $"Missing implementation for {InjectorMode}"; Logger?.LogError(msg); throw new NotImplementedException(msg); } throw new ArgumentException($"Unhandled injector mode {InjectorMode}"); }
public static IEnumerable <IIfcPropertySingleValue> GetProperties(IIfcProduct element) { //get all single-value properties of the door var properties = element.IsDefinedBy .Where(r => r.RelatingPropertyDefinition is IIfcPropertySet) .SelectMany(r => ((IIfcPropertySet)r.RelatingPropertyDefinition).HasProperties) .OfType <IIfcPropertySingleValue>(); var ifcPropertySingleValues = properties as IList <IIfcPropertySingleValue> ?? properties.ToList(); foreach (var property in ifcPropertySingleValues) { Console.WriteLine($"Property: {property.Name}, Value: {property.NominalValue}"); } return(ifcPropertySingleValues); }
private static IIfcValue GetArea(IIfcProduct product) { var area = product.IsDefinedBy.SelectMany(r => r.RelatingPropertyDefinition.PropertySetDefinitions) .OfType <IIfcElementQuantity>() .SelectMany(qset => qset.Quantities) .OfType <IIfcQuantityArea>() .FirstOrDefault() .AreaValue; if (area != null) { return(area); } return(GetProperty(product, "Area")); }
private IXbimViewModel FindUnderContainingSpace(IPersistEntity newVal, IIfcProduct p) { var containingSpace = p.IsContainedIn; if (containingSpace != null) { var containingSpaceView = FindItemBreadthFirst(containingSpace); if (containingSpaceView != null) { var found = FindItemDepthFirst(containingSpaceView, newVal); if (found != null) { return(found); } } } return(null); }
/// <summary> /// New product instance given by type parameter. /// </summary> /// <param name="pName">A type label of the product instance</param> /// <param name="placement">A placement</param> /// <param name="name">An optional name</param> /// <returns>New stored product</returns> public IIfcProduct NewProduct(XName pName, IIfcLocalPlacement placement = null, string name = null) { IIfcProduct product = null; if (Store.SchemaVersion.ToString() != pName.NamespaceName) { throw new ArgumentException($"Wrong schema version of pName. Store is a {Store.SchemaVersion}"); } Wrap(s => { product = IfcProductScope.New(pName.LocalName); product.Name = name; product.ObjectPlacement = placement; InitProduct(product); }); return(product); }
public static IEnumerable <Tuple <string, T[]> > PropertiesSets <T>(this IIfcProduct p) where T : IIfcProperty { return(p.IsDefinedBy.SelectMany(r => { if (r.RelatingPropertyDefinition is IIfcPropertySetDefinition set) { return Enumerable.Repeat(new Tuple <string, T[]>(set.Name, set.Properties <T>().ToArray()), 1); } else if (r.RelatingPropertyDefinition is IfcPropertySetDefinitionSet setOfSet) { return setOfSet.PropertySetDefinitions.Select(s => new Tuple <string, T[]>(s.Name, s.Properties <T>().ToArray())); } else { return Enumerable.Empty <Tuple <string, T[]> >(); } })); }
public static IEnumerable <T> PropertiesAll <T>(this IIfcProduct p) where T : IIfcProperty { return(p.IsDefinedBy.SelectMany(r => { if (r.RelatingPropertyDefinition is IIfcPropertySetDefinition set) { return set.Properties <T>(); } else if (r.RelatingPropertyDefinition is IfcPropertySetDefinitionSet setOfSet) { return setOfSet.PropertySetDefinitions.SelectMany(s => s.Properties <T>()); } else { return Enumerable.Empty <T>(); } })); }