Exemplo n.º 1
0
    /// <summary>
    /// 实例化SpatialData
    /// </summary>
    /// <param name="s"></param>
    /// <returns></returns>
    private static ISpatialData InstaniateCurSpatial(IIfcSpatialStructureElement s)
    {
        var          go = new GameObject();
        ISpatialData sp;

        if (s is IIfcSite)
        {
            sp = go.AddComponent <SiteData>();
        }
        else if (s is IIfcBuilding)
        {
            sp = go.AddComponent <BuildingData>();
        }
        else if (s is IIfcBuildingStorey)
        {
            sp = go.AddComponent <BuildingStoreyData>();
        }
        else if (s is IIfcSpace)
        {
            sp = go.AddComponent <SpaceData>();
        }
        else
        {
            sp = null;
        }
        if (sp != null)
        {
            sp.Name         = s.Name;
            sp.TheStructure = s;
            go.name         = sp.Name + "[" + sp.TheStructure.GetType().Name + "]" + sp.EntityLabel;
            spatialDatas.Add(sp);
        }
        return(sp);
    }
        protected override Space Mapping(IIfcSpatialStructureElement ifcSpatialElement, Space target)
        {
            var helper = ((IfcToCOBieLiteUkExchanger)Exchanger).Helper;

            target.ExternalEntity = helper.ExternalEntityName(ifcSpatialElement);
            target.ExternalId     = helper.ExternalEntityIdentity(ifcSpatialElement);
            target.AltExternalId  = ifcSpatialElement.GlobalId;
            target.ExternalSystem = helper.ExternalSystemName(ifcSpatialElement);
            target.Name           = ifcSpatialElement.Name;
            target.Categories     = helper.GetCategories(ifcSpatialElement);
            target.Description    = ifcSpatialElement.LongName;
            if (string.IsNullOrWhiteSpace(target.Description))
            {
                target.Description = ifcSpatialElement.Description;
            }
            target.CreatedBy    = helper.GetCreatedBy(ifcSpatialElement);
            target.CreatedOn    = helper.GetCreatedOn(ifcSpatialElement);
            target.RoomTag      = helper.GetCoBieAttribute <StringAttributeValue>("SpaceSignageName", ifcSpatialElement).Value;
            target.UsableHeight = helper.GetCoBieAttribute <DecimalAttributeValue>("SpaceUsableHeightValue", ifcSpatialElement).Value;
            target.GrossArea    = helper.GetCoBieAttribute <DecimalAttributeValue>("SpaceGrossAreaValue", ifcSpatialElement).Value;
            target.NetArea      = helper.GetCoBieAttribute <DecimalAttributeValue>("SpaceNetAreaValue", ifcSpatialElement).Value;

            //Attributes
            target.Attributes = helper.GetAttributes(ifcSpatialElement);

            //Documents
            var docsMappings = Exchanger.GetOrCreateMappings <MappingIfcDocumentSelectToDocument>();

            helper.AddDocuments(docsMappings, target, ifcSpatialElement as IIfcSpace);
            //TODO:
            //Space Issues

            return(target);
        }
    /// <summary>
    /// instantiate spatialData by ifcSpatialStructureElement
    /// </summary>
    /// <param name="s"></param>
    /// <returns></returns>
    public static ISpatialData InstantiateCurSpatial(IIfcSpatialStructureElement s)
    {
        var          go = new GameObject();
        ISpatialData sp;

        switch (s)
        {
        case IIfcSite _:
            sp = go.AddComponent <SiteData>();
            break;

        case IIfcBuilding _:
            sp = go.AddComponent <BuildingData>();
            break;

        case IIfcBuildingStorey _:
            sp = go.AddComponent <BuildingStoreyData>();
            break;

        case IIfcSpace _:
            sp = go.AddComponent <SpaceData>();
            break;

        default:
            sp = null;
            break;
        }

        if (sp != null)
        {
            sp.InitialObject(s);
        }
        return(sp);
    }
Exemplo n.º 4
0
 public ContainedElementsViewModel(IIfcSpatialStructureElement spatialElem, Type type, IXbimViewModel parent)
 {
     _spatialContainer = spatialElem;
     _type             = type;
     Model             = spatialElem.Model;
     CreatingParent    = parent;
 }
Exemplo n.º 5
0
 public SpatialViewModel(IIfcSpatialStructureElement spatialStructure, IXbimViewModel parent)
 {
     if (spatialStructure == null)
     {
         throw new ArgumentNullException("spatialStructure");
     }
     _model            = spatialStructure.Model;
     _spatialStructure = spatialStructure;
     CreatingParent    = parent;
 }
Exemplo n.º 6
0
    private static SpatialData InstantiateCurrentSpatial(IIfcSpatialStructureElement element)
    {
        var go = new GameObject();
        var sp = go.AddComponent <SpatialData>();

        sp.Name = element.Name;
        sp.IFCStructureElement = element;
        go.name = sp.Name + "[" + sp.IFCStructureElement.GetType().Name + "]#" + sp.IFCStructureElement.EntityLabel;
        PublicValue.spatialStructures.Add(sp);
        return(sp);
    }
Exemplo n.º 7
0
        public static IIfcRelContainedInSpatialStructure NewContains(this IModel s, IIfcSpatialStructureElement e)
        {
            switch (s.SchemaVersion)
            {
            case Xbim.Common.Step21.XbimSchemaVersion.Ifc2X3:
                return(s.NewIfc2x3Contains(e as Xbim.Ifc2x3.ProductExtension.IfcSpatialStructureElement));

            case Xbim.Common.Step21.XbimSchemaVersion.Ifc4:
            case Xbim.Common.Step21.XbimSchemaVersion.Ifc4x1:
                return(s.NewIfc4Contains(e as Xbim.Ifc4.ProductExtension.IfcSpatialStructureElement));
            }
            throw new NotImplementedException($"Not implemented schema version ${s.SchemaVersion}");
        }
Exemplo n.º 8
0
        private void DecomposeSpatialStructure(IIfcSpatialStructureElement ifcSpatialStructuralElement,
                                               HashSet <IIfcSpatialStructureElement> allSpatialStructuralElements)
        {
            List <IIfcSpatialStructureElement> spatialElements;

            if (_spatialDecomposition.TryGetValue(ifcSpatialStructuralElement, out spatialElements))
            {
                foreach (var spatialElement in spatialElements)
                {
                    allSpatialStructuralElements.Add(spatialElement);
                    DecomposeSpatialStructure(spatialElement, allSpatialStructuralElements);
                }
            }
        }
Exemplo n.º 9
0
        private List <IIfcObjectDefinition> PrintHierarchy(IIfcObjectDefinition Object, int level)
        {
            var Hierarchy = new List <IIfcObjectDefinition>();

            //var TypeObjects = Model.Instances.Where<IIfcTypeObject>(s=>s.EntityLabel > 0);
            var Spaces = Model.Instances.Where <IIfcSpace>(s => s.EntityLabel > 0);
            //var Zones = Model.Instances.Where<IIfcZone>(s => s.EntityLabel > 0);
            //var Doors = Model.Instances.Where<IIfcDoor>(s => s.EntityLabel > 0);
            //var Windows = Model.Instances.Where<IIfcWindow>(s => s.EntityLabel > 0);
            //var Walls = Model.Instances.Where<IIfcWall>(s => s.EntityLabel > 0);
            //var Roofs = Model.Instances.Where<IIfcRoof>(s => s.EntityLabel > 0);
            //var SlabTypes = Model.Instances.Where<IIfcSlabType>(s => s.EntityLabel > 0);

            var SpaceProps = GetPropsForProduct(Spaces.FirstOrDefault());

            IIfcElement Element = Object as IIfcElement;

            // If we're dealing with an element: Wall, Door, Window..
            // Then we'll have a direct connection to the Spatial Structure that it's contained in
            if (Element != null)
            {
                var Relation          = Element.ContainedInStructure.FirstOrDefault() as IIfcRelContainedInSpatialStructure;
                var RelatingStructure = Relation.RelatingStructure;
                Hierarchy.Add(RelatingStructure);

                Console.WriteLine();
            }



            //only spatial elements can contain building elements
            IIfcSpatialStructureElement SpatialElement = Object as IIfcSpatialStructureElement;

            if (SpatialElement != null)
            {
                //using IfcRelContainedInSpatialElement to get contained elements
                var ContainedElements = SpatialElement.ContainsElements.SelectMany(rel => rel.RelatedElements);
                foreach (var ContainedElement in ContainedElements)
                {
                }
            }

            //using IfcRelAggregares to get spatial decomposition of spatial structure elements
            foreach (var SpatialStructure in Object.IsDecomposedBy.SelectMany(r => r.RelatedObjects))
            {
            }

            return(Hierarchy);
        }
Exemplo n.º 10
0
        /// <summary>
        /// New Model Injector Package.
        /// </summary>
        /// <param name="intoModel">The merge-into model instance</param>
        /// <param name="copyTypes">The type enumeration to copy over</param>
        /// <param name="injectModels">The models to query & copy</param>
        /// <param name="singleton">The container (or null by default indicating to find the first occurance)</param>
        public IfcModelInjectorWorker(IfcStore intoModel, IEnumerable <XName> copyTypes,
                                      IEnumerable <IfcStore> injectModels, IIfcSpatialStructureElement singleton = null)
        {
            Builder         = IfcBuilder.WrapStore(intoModel);
            CopyExpressType = new HashSet <XName>(copyTypes.Select(x => (XName)x.LocalName));
            Models          = injectModels.ToArray();

            if (null == singleton)
            {
                ContainerCandidate = new IIfcSpatialStructureElement[] { intoModel.Instances.OfType <IIfcSpatialStructureElement>().FirstOrDefault() }
            }
            ;
            else
            {
                ContainerCandidate = new IIfcSpatialStructureElement[] { singleton }
            };

            InjectorMode = IfcModelInjectorMode.SingletonContainer;
        }
        private void processSpatialStructureRel()
        {
            string SqlStmt;
            string currStep = string.Empty;

            DBOperation.beginTransaction();

            int    commandStatus   = -1;
            int    currInsertCount = 0;
            string parentGuid      = string.Empty;
            string parentType      = string.Empty;

            OracleCommand command = new OracleCommand(" ", DBOperation.DBConn);

            try
            {
                IEnumerable <IIfcSpatialStructureElement> spatialStructure = _model.Instances.OfType <IIfcSpatialStructureElement>();
                foreach (IIfcSpatialStructureElement sse in spatialStructure)
                {
                    // Insert itself at levelremoved=0
                    int levelRemoved = 0;
                    SqlStmt = "insert into " + DBOperation.formatTabName("BIMRL_SPATIALSTRUCTURE") + "(SPATIALELEMENTID, SPATIALELEMENTTYPE, PARENTID, PARENTTYPE, LEVELREMOVED)"
                              + " values ('" + sse.GlobalId.ToString() + "','" + sse.GetType().Name.ToUpper() + "','"
                              + sse.GlobalId.ToString() + "','" + sse.GetType().Name.ToUpper() + "'," + levelRemoved + ")";
                    command.CommandText = SqlStmt;
                    currStep            = SqlStmt;
                    commandStatus       = command.ExecuteNonQuery();

                    currInsertCount++;

                    levelRemoved = 1;
                    // insert aggregation relationship with the parent
                    IEnumerable <IIfcRelAggregates> decomposes = sse.Decomposes;
                    foreach (IIfcRelAggregates relAgg in decomposes)
                    {
                        IIfcSpatialStructureElement parent = relAgg.RelatingObject as IIfcSpatialStructureElement;
                        if (parent == null)
                        {
                            parentGuid   = string.Empty;
                            parentType   = string.Empty;
                            levelRemoved = 0;
                        }
                        else
                        {
                            parentGuid = parent.GlobalId.ToString();
                            parentType = parent.GetType().Name.ToUpper();
                        }
                        SqlStmt = "insert into " + DBOperation.formatTabName("BIMRL_SPATIALSTRUCTURE") + "(SPATIALELEMENTID, SPATIALELEMENTTYPE, PARENTID, PARENTTYPE, LEVELREMOVED)"
                                  + " values ('" + sse.GlobalId.ToString() + "','" + sse.GetType().Name.ToUpper() + "','"
                                  + parentGuid + "','" + parentType + "'," + levelRemoved + ")";
                        command.CommandText = SqlStmt;
                        currStep            = SqlStmt;
                        commandStatus       = command.ExecuteNonQuery();

                        currInsertCount++;

                        while (parent != null)
                        {
                            levelRemoved++;
                            IEnumerable <IIfcRelAggregates> decomposesGP = parent.Decomposes;
                            if (decomposesGP.Count() == 0)
                            {
                                break;
                            }
                            // The decomposes attribute is a set of [0,1] only
                            IIfcSpatialStructureElement grandparent = decomposesGP.FirstOrDefault().RelatingObject as IIfcSpatialStructureElement;
                            if (grandparent == null)
                            {
                                break; // no ancestor to insert anymore
                            }
                            SqlStmt = "insert into " + DBOperation.formatTabName("BIMRL_SPATIALSTRUCTURE") + "(SPATIALELEMENTID, SPATIALELEMENTTYPE, PARENTID, PARENTTYPE, LEVELREMOVED)"
                                      + " values ('" + sse.GlobalId.ToString() + "','" + sse.GetType().Name.ToUpper() + "','"
                                      + grandparent.GlobalId.ToString() + "','" + grandparent.GetType().Name.ToUpper() + "'," + levelRemoved + ")";
                            command.CommandText = SqlStmt;
                            currStep            = SqlStmt;
                            commandStatus       = command.ExecuteNonQuery();
                            currInsertCount++;
                            parent = grandparent;
                        }

                        if (currInsertCount % DBOperation.commitInterval == 0)
                        {
                            //Do commit at interval but keep the long transaction (reopen)
                            DBOperation.commitTransaction();
                        }
                    }
                }
            }
            catch (OracleException e)
            {
                string excStr = "%%Error - " + e.Message + "\n\t" + currStep;
                _refBIMRLCommon.StackPushError(excStr);
                command.Dispose();
                throw;
            }

            DBOperation.commitTransaction();
            command.Dispose();
        }
Exemplo n.º 12
0
        private List <IIfcObjectDefinition> PrintHierarchy(IIfcObjectDefinition Object, int level)
        {
            var Hierarchy = new List <IIfcObjectDefinition>();


            //var TypeObjects = Model.Instances.Where<IIfcTypeObject>(s=>s.EntityLabel > 0);
            var Spaces = Model.Instances.Where <IIfcSpace>(s => s.EntityLabel > 0);
            var Zones  = Model.Instances.Where <IIfcZone>(s => s.EntityLabel > 0);
            //var Doors = Model.Instances.Where<IIfcDoor>(s => s.EntityLabel > 0);
            //var Windows = Model.Instances.Where<IIfcWindow>(s => s.EntityLabel > 0);
            //var Walls = Model.Instances.Where<IIfcWall>(s => s.EntityLabel > 0);
            //var Roofs = Model.Instances.Where<IIfcRoof>(s => s.EntityLabel > 0);
            //var SlabTypes = Model.Instances.Where<IIfcSlabType>(s => s.EntityLabel > 0);
            IIfcValue DefaultNominalValue = new IfcText("");

            foreach (IIfcSpace Space in Spaces)
            {
                Console.WriteLine($"Space: {Space.LongName}  {Space.Name}");
                Space.ObjectType = new IfcLabel("");

                var Props = GetPropsForProduct(Space);
                foreach (IIfcPropertySingleValue Prop in Props)
                {
                    if (Prop.NominalValue != null && Prop.NominalValue.Value != null)
                    {
                        Console.WriteLine($"{Prop.Name}  {Prop.NominalValue.Value}");
                    }
                }
            }

            foreach (IIfcZone Zone in Zones)
            {
                Console.WriteLine($"Zone: {Zone.LongName}  {Zone.Name}");

                var Props = GetPropsForProduct(Zone);
                foreach (IIfcPropertySingleValue Prop in Props)
                {
                    if (Prop.NominalValue != null && Prop.NominalValue.Value != null)
                    {
                        Console.WriteLine($"{Prop.Name}  {Prop.NominalValue.Value}");
                    }
                }
            }

            IIfcElement Element = Object as IIfcElement;

            // If we're dealing with an element: Wall, Door, Window..
            // Then we'll have a direct connection to the Spatial Structure that it's contained in
            if (Element != null)
            {
                var Relation          = Element.ContainedInStructure.FirstOrDefault() as IIfcRelContainedInSpatialStructure;
                var RelatingStructure = Relation.RelatingStructure;
                Hierarchy.Add(RelatingStructure);

                Console.WriteLine();
            }



            // Only spatial elements can contain building elements
            IIfcSpatialStructureElement SpatialElement = Object as IIfcSpatialStructureElement;

            if (SpatialElement != null)
            {
                //using IfcRelContainedInSpatialElement to get contained elements
                var ContainedElements = SpatialElement.ContainsElements.SelectMany(rel => rel.RelatedElements);
                foreach (var ContainedElement in ContainedElements)
                {
                }
            }

            if (Object != null)
            {
                // ifcRelAggregates to get spatial decomposition of spatial structure elements
                IEnumerable <IIfcObjectDefinition> ifcRelAggregates = Object.IsDecomposedBy.SelectMany(r => r.RelatedObjects);
                if (ifcRelAggregates != null)
                {
                    foreach (var SpatialStructure in ifcRelAggregates)
                    {
                    }
                }
            }

            return(Hierarchy);
        }
        protected override Floor Mapping(IIfcSpatialStructureElement ifcSpatialStructureElement, Floor target)
        {
            var helper = ((IfcToCOBieLiteUkExchanger)Exchanger).Helper;

            target.ExternalEntity = helper.ExternalEntityName(ifcSpatialStructureElement);
            target.ExternalId     = helper.ExternalEntityIdentity(ifcSpatialStructureElement);
            target.AltExternalId  = ifcSpatialStructureElement.GlobalId;
            target.ExternalSystem = helper.ExternalSystemName(ifcSpatialStructureElement);
            target.Name           = ifcSpatialStructureElement.Name;

            //Attributes
            target.Attributes = helper.GetAttributes(ifcSpatialStructureElement);
            if (target.Categories == null)
            {
                target.Categories = new List <Category>();
            }


            IEnumerable <IIfcSpatialStructureElement> spaces = null;
            var site         = ifcSpatialStructureElement as IIfcSite;
            var building     = ifcSpatialStructureElement as IIfcBuilding;
            var storey       = ifcSpatialStructureElement as IIfcBuildingStorey;
            var spaceElement = ifcSpatialStructureElement as IIfcSpace;

            if (site != null)
            {
                target.Categories.Add(new Category()
                {
                    Code = "Site"
                });
                //upgrade code below to use extension method GetSpaces()

                if (site.IsDecomposedBy != null)
                {
                    var decomp = site.IsDecomposedBy;
                    var objs   = decomp.SelectMany(s => s.RelatedObjects);
                    spaces = objs.OfType <IIfcSpace>();
                }
            }
            else if (building != null)
            {
                target.Categories.Add(new Category()
                {
                    Code = "Building"
                });
                spaces = building.Spaces;
            }
            else if (storey != null)
            {
                target.Categories.Add(new Category()
                {
                    Code = "Floor"
                });
                if (storey.Elevation.HasValue)
                {
                    target.Elevation = storey.Elevation.Value;
                }
                spaces = storey.Spaces;
            }
            else if (spaceElement != null)
            {
                target.Categories.Add(new Category()
                {
                    Code = "Space"
                });
                spaces = spaceElement.Spaces;
            }


            target.Description = ifcSpatialStructureElement.Description;
            target.CreatedBy   = helper.GetCreatedBy(ifcSpatialStructureElement);
            target.CreatedOn   = helper.GetCreatedOn(ifcSpatialStructureElement);
            //set the fall backs


            target.Height = helper.GetCoBieAttribute <DecimalAttributeValue>("FloorHeightValue", ifcSpatialStructureElement).Value;

            //Documents
            var docsMappings = Exchanger.GetOrCreateMappings <MappingIfcDocumentSelectToDocument>();

            helper.AddDocuments(docsMappings, target, ifcSpatialStructureElement as IIfcBuildingStorey);

            //Add spaces
            var ifcSpatialStructureElements = spaces.ToList();

            ifcSpatialStructureElements.Add(ifcSpatialStructureElement);

            target.Spaces = new List <Space>(ifcSpatialStructureElements.Count);
            var spaceMappings = Exchanger.GetOrCreateMappings <MappingIfcSpatialStructureElementToSpace>();

            for (var i = 0; i < ifcSpatialStructureElements.Count; i++)
            {
                var space = new Space();
                space = spaceMappings.AddMapping(ifcSpatialStructureElements[i], space);
                target.Spaces.Add(space);
            }


            //Attributes
            target.Attributes = helper.GetAttributes(ifcSpatialStructureElement);

            //TODO:
            //Floor Issues
            return(target);
        }