public static BuildcraftCore.B5D.IfcRoot CreateRootObject(string ifcGuid, B5dObject b5dObject)
 {
     BuildcraftCore.B5D.IfcRoot b5dIfcObject = new BuildcraftCore.B5D.IfcRoot()
     {
         ExternalIfcGlobalId = ifcGuid,
         B5dObject           = b5dObject
     };
     return(b5dIfcObject);
 }
Ejemplo n.º 2
0
        public static List <B5dProperty> ConvertProperties(IIfcObject ifcObject, B5dObject b5dObject)
        {
            var ifcProperties = GetProperties(ifcObject);
            var b5dProperties = new List <B5dProperty>();

            foreach (var prop in ifcProperties)
            {
                var b5dProperty = PropertyConverter.ConvertProperty(prop, b5dObject);
                b5dProperties.Add(b5dProperty);
            }

            return(b5dProperties);
        }
Ejemplo n.º 3
0
        public B5dProjectNode BuildTree(B5dObject b5dParent, IIfcObjectDefinition ifcParent, IIfcObjectDefinition ifcChild)
        {
            B5dProjectNode b5dChild = IfcObjectConverter.Convert(ifcChild);

            if (ifcChild is IIfcProject)
            {
                currentProject = b5dChild;
            }
            else
            {
                GltfRef.TryCreatingGltfRef(ifcChild.GlobalId.ToString(), currentProject, b5dChild);
            }


            if (b5dParent != null)
            {
                B5dProjectNodeChild ChildRelationship = B5dProjectNodeChild.CreateNodeChildRelation(b5dParent, b5dChild);
            }

            if (ifcChild is IIfcObject ifcObject)
            {
                // Use containsElements to recursively create nodes for Window, Door, Slab, Wall etc
                foreach (var ifcSpatialElement in RelContainedInSpatialStructure.GetElementsIn(ifcObject))
                {
                    BuildTree(b5dChild, ifcChild, ifcSpatialElement);
                }

                // Use isDecomposedy to recursively create nodes for Project, Site, Building, Story and Space
                foreach (var ifcSpatialStructure in RelAggregates.GetSpatialStructuresIn(ifcObject))
                {
                    BuildTree(b5dChild, ifcChild, ifcSpatialStructure);
                }

                // Use isDefinedBy to convert all of the ifcProperties
                PropertyConverter.ConvertProperties(ifcObject, b5dChild);
            }

            return(b5dChild);
        }
Ejemplo n.º 4
0
        public static B5dProperty ConvertProperty(IIfcPropertySingleValue ifcPropValue, B5dObject propOwner)
        {
            if (ifcPropValue.NominalValue == null)
            {
                return(null);
            }

            var propName  = ifcPropValue.Name.Value.ToString();
            var propValue = ifcPropValue.NominalValue.Value;
            var propType  = ifcPropValue.NominalValue.UnderlyingSystemType.Name;

            switch (propType)
            {
            case "Boolean":
                if (propValue is bool boolValue)
                {
                    return(new B5dBoolean()
                    {
                        Name = propName, Value = boolValue, BelongsTo = propOwner
                    });
                }
                break;

            case "Double":
                if (propValue is double doubleValue)
                {
                    return(new B5dDouble()
                    {
                        Name = propName, Value = doubleValue, BelongsTo = propOwner
                    });
                }
                break;

            case "Int64":
                if (propValue is Int64 int64Value)
                {
                    return(new B5dInteger()
                    {
                        Name = propName, Value = int64Value, BelongsTo = propOwner
                    });
                }
                break;

            case "Int32":
                if (propValue is Int32 int32Value)
                {
                    return(new B5dInteger()
                    {
                        Name = propName, Value = int32Value, BelongsTo = propOwner
                    });
                }
                break;

            case "String":
                if (propValue is string stringValue)
                {
                    return(new B5dString()
                    {
                        Name = propName, Value = stringValue, BelongsTo = propOwner
                    });
                }
                break;

            default:
                return(null);
            }

            return(null);
        }
Ejemplo n.º 5
0
        public static GltfRef TryCreatingGltfRef(string ifcObjectGuid, B5dProjectNode project, B5dObject b5dObject)
        {
            var existingRef = DbLinq.Objects <GltfRef>().FirstOrDefault(o => o.BelongsTo == b5dObject);

            if (existingRef != null)
            {
                return(existingRef);
            }

            string documentsDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
            string conversionPath     = $"{documentsDirectory}\\Conversions";

            var projectName   = project.Name;
            var b5dObjectType = b5dObject.TypeSpecifier.ToLower();

            b5dObjectType = b5dObjectType.Replace("ifc", "");
            // The ifcTo3DTiles conversion renames WallStandardCase to Wall
            b5dObjectType = b5dObjectType.Replace("wallstandardcase", "wall");

            var ifcDirectory = $"{conversionPath}\\Conversion_{projectName}\\IFCs";
            var files        = Directory.GetFiles(ifcDirectory);
            var ifcFiles     = files.Where(f => f.ToLower().Contains(b5dObjectType));

            if (ifcFiles.Count() == 0)
            {
                return(null);
            }

            foreach (string ifcFilePath in ifcFiles)
            {
                var ifcModel  = IfcStore.Open(ifcFilePath);
                var ifcObject = ifcModel.Instances.FirstOrDefault() as IIfcObject;
                if (ifcObject.GlobalId == ifcObjectGuid)
                {
                    var        gltfFilepath = ifcFilePath.Replace("IFCs", "GLTFs").Replace(".ifc", ".gltf");
                    FileStream gltfFile     = File.Open(gltfFilepath, FileMode.Open);
                    var        filename     = Path.GetFileName(gltfFilepath);

                    if (ifcObject != null && gltfFile != null)
                    {
                        var fileRef = new GltfRef()
                        {
                            BelongsTo = b5dObject,
                            Extension = "gltf",
                            FileId    = ifcObjectGuid,
                            FileName  = filename,
                            MimeType  = "model/gltf+json",
                            FileSize  = gltfFilepath.Length,
                        };
                        return(fileRef);
                    }
                    break;
                }
            }

            return(null);
        }