Exemplo n.º 1
0
        public static void AddBuildingElement(
            IIfcObjectDefinition site,
            IIfcObjectDefinition building)
        {
            IEnumerable <IIfcRelAggregates> decomposition = site.IsDecomposedBy;

            if (decomposition.Count() == 0) //none defined create the relationship
            {
                IIfcRelAggregates relSub = site.Model.Instances.New <IfcRelAggregates>();
                relSub.RelatingObject = site;
                relSub.RelatedObjects.Add(building);
            }
            else
            {
                decomposition.First().RelatedObjects.Add(building);
            }
        }
        protected override Assembly Mapping(IIfcRelAggregates source, Assembly target)
        {
            var helper = ((IfcToCOBieLiteUkExchanger)Exchanger).Helper;

            target.ExternalEntity = helper.ExternalEntityName(source);
            target.ExternalId     = helper.ExternalEntityIdentity(source);
            target.AltExternalId  = source.GlobalId;
            target.ExternalSystem = helper.ExternalSystemName(source);
            target.Description    = source.Description;
            target.Categories     = CoBieLiteUkHelper.UnknownCategory;
            target.CreatedBy      = helper.GetCreatedBy(source);
            target.CreatedOn      = helper.GetCreatedOn(source);
            target.Name           = source.Name;

            if (source.RelatedObjects.Any())
            {
                List <IIfcObjectDefinition> children = source.RelatedObjects.ToList();

                List <EntityKey> entityKeys = new List <EntityKey>();
                foreach (IIfcObjectDefinition child in children)
                {
                    EntityKey entityKey = new EntityKey();
                    entityKey.KeyType = EntityType;

                    if (EntityType.AssetType == EntityType && helper.TypeEntityKeyLookup.ContainsKey(child))
                    {
                        entityKey.Name = helper.TypeEntityKeyLookup[child];
                    }
                    else
                    {
                        entityKey.Name = child.Name;
                    }
                    entityKeys.Add(entityKey);
                }

                target.ChildAssetsOrTypes = entityKeys;
            }

            return(target);
        }
        private void processSpatialStructureData()
        {
            string currStep = string.Empty;

            DBOperation.beginTransaction();
            string container       = string.Empty;
            int    commandStatus   = -1;
            int    currInsertCount = 0;

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

            try
            {
                IEnumerable <IIfcSpatialStructureElement> spatialStructure = _model.Instances.OfType <IIfcSpatialStructureElement>();
                foreach (IIfcSpatialStructureElement sse in spatialStructure)
                {
                    string SqlStmt;

                    // do something
                    string guid      = sse.GlobalId.ToString();
                    int    IfcLineNo = sse.EntityLabel;

                    string elementtype = sse.GetType().Name.ToUpper();
                    string typeID      = String.Empty;
                    int    typeLineNo  = 0;
                    IEnumerable <IIfcRelDefinesByType> relTyp = sse.IsTypedBy;
                    if (relTyp != null || relTyp.Count() > 0)
                    {
                        IIfcRelDefinesByType typ = relTyp.FirstOrDefault();
                        if (typ != null)
                        {
                            typeID     = typ.RelatingType.GlobalId.ToString();
                            typeLineNo = typ.RelatingType.EntityLabel;
                        }
                    }
                    //if (sse.GetDefiningType() != null)
                    //  {
                    //      typeID = sse.GetDefiningType().GlobalId;
                    //      typeLineNo = sse.GetDefiningType().EntityLabel;
                    //  }
                    string            sseName        = BIMRLUtils.checkSingleQuote(sse.Name);
                    string            sseDescription = BIMRLUtils.checkSingleQuote(sse.Description);
                    string            sseObjectType  = BIMRLUtils.checkSingleQuote(sse.ObjectType);
                    string            sseLongName    = BIMRLUtils.checkSingleQuote(sse.LongName);
                    IIfcRelAggregates relContainer   = sse.Decomposes.FirstOrDefault();
                    if (relContainer == null)
                    {
                        container = string.Empty;
                    }
                    else
                    {
                        container = relContainer.RelatingObject.GlobalId.ToString();
                    }

                    // Keep a mapping between IFC guid used as a key in BIMRL and the IFC line no of the entity
                    _refBIMRLCommon.guidLineNoMappingAdd(BIMRLProcessModel.currModelID, IfcLineNo, guid);

                    SqlStmt = "Insert into " + DBOperation.formatTabName("BIMRL_Element") + "(Elementid, LineNo, ElementType, ModelID, Name, LongName, Description, ObjectType, Container, TypeID) Values ('"
                              + guid + "'," + IfcLineNo + ", '" + elementtype + "', " + BIMRLProcessModel.currModelID.ToString() + ", '" + sseName + "', '" + sseLongName + "','" + sseDescription + "', '" + sseObjectType
                              + "', '" + container + "', '" + typeID + "')";
                    // status = DBOperation.insertRow(SqlStmt);
                    command.CommandText = SqlStmt;
                    currStep            = SqlStmt;
                    commandStatus       = command.ExecuteNonQuery();

                    // Add intormation of the product label (LineNo into a List for the use later to update the Geometry
                    _refBIMRLCommon.insEntityLabelListAdd(Math.Abs(IfcLineNo));
                    currInsertCount++;

                    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.º 4
0
        protected override Asset Mapping(IIfcElement ifcElement, Asset target)
        {
            var helper = ((IfcToCOBieLiteUkExchanger)Exchanger).Helper;

            target.ExternalEntity  = helper.ExternalEntityName(ifcElement);
            target.ExternalId      = helper.ExternalEntityIdentity(ifcElement);
            target.AltExternalId   = ifcElement.GlobalId;
            target.ExternalSystem  = helper.ExternalSystemName(ifcElement);
            target.Name            = ifcElement.Name;
            target.CreatedBy       = helper.GetCreatedBy(ifcElement);
            target.CreatedOn       = helper.GetCreatedOn(ifcElement);
            target.Categories      = helper.GetCategories(ifcElement);
            target.AssetIdentifier = helper.GetCoBieProperty("AssetIdentifier", ifcElement);
            target.BarCode         = helper.GetCoBieProperty("AssetBarCode", ifcElement);
            if (!string.IsNullOrWhiteSpace(ifcElement.Description))
            {
                target.Description = ifcElement.Description;
            }
            else
            {
                target.Description = helper.GetCoBieProperty("AssetSerialNumber", ifcElement);
            }
            target.InstallationDate  = helper.GetCoBieProperty <DateTime>("AssetInstallationDate", ifcElement);
            target.SerialNumber      = helper.GetCoBieProperty("AssetSerialNumber", ifcElement);
            target.TagNumber         = helper.GetCoBieProperty("AssetTagNumber", ifcElement);
            target.WarrantyStartDate = helper.GetCoBieProperty <DateTime>("AssetWarrantyStartDate", ifcElement);



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

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

            helper.AddDocuments(docsMappings, target, ifcElement);

            //System Assignments

            //Space Assignments
            var spatialElements = helper.GetSpaces(ifcElement);

            var ifcSpatialStructureElements = spatialElements.ToList();

            target.Spaces = new List <SpaceKey>();
            if (ifcSpatialStructureElements.Any())
            {
                foreach (var spatialElement in ifcSpatialStructureElements)
                {
                    var space = new SpaceKey {
                        Name = spatialElement.Name
                    };
                    target.Spaces.Add(space);
                }
            }
            //else //it is in nowhere land, assign it to a special space all Default External
            //{
            //    var space = new SpaceKey();
            //    space.Name = "Default External";
            //    space.KeyType = EntityType.Space;
            //    target.Spaces.Add(space);
            //}
            else // if it is part of an aggregated element, add spaces of the aggregated element
            {
                var assemblyParts = ifcElement.Model.Instances.OfType <IIfcRelAggregates>().Where(b => b.RelatedObjects.Contains(ifcElement)).FirstOrDefault();
                if (assemblyParts != null)
                {
                    ifcSpatialStructureElements = helper.GetSpaces((IIfcElement)assemblyParts.RelatingObject).ToList();
                    target.Spaces = new List <SpaceKey>();
                    if (ifcSpatialStructureElements.Any())
                    {
                        foreach (var spatialElement in ifcSpatialStructureElements)
                        {
                            var Fspace = new SpaceKey {
                                Name = spatialElement.Name
                            };
                            target.Spaces.Add(Fspace);
                        }
                    }
                }
            }

            // Assemblies
            var assemblyMapping = Exchanger.GetOrCreateMappings <MappingIfcRelAggregatesToAssembly>();

            assemblyMapping.EntityType = EntityType.Asset;

            bool hasAttributes = helper.AssemblyLookup.ContainsKey(ifcElement);

            if (hasAttributes)
            {
                IIfcRelAggregates ifcRelAggregates = helper.AssemblyLookup[ifcElement];
                target.AssemblyOf = assemblyMapping.AddMapping(ifcRelAggregates, new Assembly());
            }

            //Issues


            return(target);
        }
Exemplo n.º 5
0
        protected override AssetType Mapping(XbimIfcProxyTypeObject proxyIfcTypeObject, AssetType target)
        {
            var helper = ((IfcToCOBieLiteUkExchanger)Exchanger).Helper;

            target.ExternalEntity = proxyIfcTypeObject.ExternalEntity;
            target.ExternalId     = proxyIfcTypeObject.ExternalId;
            target.ExternalSystem = proxyIfcTypeObject.ExternalSystemName;
            target.Name           = proxyIfcTypeObject.Name;
            target.Categories     = proxyIfcTypeObject.Categories;
            var cat = target.Categories.FirstOrDefault();

            HasCategory          = ((cat != null) && ((cat.Code != "unknown") || target.Categories.Count > 1)); //assume if more than 1 we have a category
            target.AssetTypeEnum = proxyIfcTypeObject.AccountingCategory;
            target.CreatedBy     = proxyIfcTypeObject.GetCreatedBy();
            target.CreatedOn     = proxyIfcTypeObject.GetCreatedOn();
            target.Description   = proxyIfcTypeObject.Description;
            var ifcTypeObject = proxyIfcTypeObject.IfcTypeObject;
            List <IIfcElement> allAssetsofThisType;

            helper.DefiningTypeObjectMap.TryGetValue(proxyIfcTypeObject, out allAssetsofThisType);

            target.Warranty = new Warranty {
                GuarantorLabor = new ContactKey {
                    Email = helper.XbimCreatedBy.Email
                }
            };
            target.Warranty.GuarantorParts = target.Warranty.GuarantorLabor;
            if (ifcTypeObject != null)
            {
                string manuf = helper.GetCoBieProperty("AssetTypeManufacturer", ifcTypeObject);
                if (string.IsNullOrWhiteSpace(manuf) && allAssetsofThisType != null) //disagrrement between COBie and IFC where this value resides, look in assets
                {
                    foreach (var element in allAssetsofThisType)
                    {
                        var prop = helper.GetCoBieProperty("AssetTypeManufacturer", element);
                        if (!string.IsNullOrWhiteSpace(prop))
                        {
                            manuf = prop;
                            break;
                        }
                    }
                }
                target.Manufacturer = helper.GetOrCreateContactKey(manuf);

                target.ModelNumber     = helper.GetCoBieProperty("AssetTypeModelNumber", ifcTypeObject);
                target.ModelReference  = helper.GetCoBieProperty("AssetTypeModelReference", ifcTypeObject);
                target.ReplacementCost =
                    helper.GetCoBieAttribute <DecimalAttributeValue>("AssetTypeReplacementCostValue",
                                                                     ifcTypeObject).Value;
                target.ExpectedLife =
                    helper.GetCoBieAttribute <IntegerAttributeValue>("AssetTypeExpectedLifeValue", ifcTypeObject)
                    .Value;
                target.NominalLength =
                    helper.GetCoBieAttribute <DecimalAttributeValue>("AssetTypeNominalLength", ifcTypeObject).Value;
                target.NominalWidth =
                    helper.GetCoBieAttribute <DecimalAttributeValue>("AssetTypeNominalWidth", ifcTypeObject).Value;
                target.NominalHeight =
                    helper.GetCoBieAttribute <DecimalAttributeValue>("AssetTypeNominalHeight", ifcTypeObject).Value;
                target.AccessibilityPerformance = helper.GetCoBieProperty("AssetTypeAccessibilityText",
                                                                          ifcTypeObject);
                target.Color        = helper.GetCoBieProperty("AssetTypeColorCode", ifcTypeObject);
                target.Constituents = helper.GetCoBieProperty("AssetTypeConstituentsDescription", ifcTypeObject);
                DurationUnit unit;
                if (Enum.TryParse(helper.GetCoBieProperty("AssetTypeDurationUnit", ifcTypeObject), true,
                                  out unit))
                {
                    target.DurationUnit = unit;
                }
                target.Features = helper.GetCoBieProperty("AssetTypeFeaturesDescription", ifcTypeObject);
                target.Grade    = helper.GetCoBieProperty("AssetTypeGradeDescription", ifcTypeObject);
                target.Material = helper.GetCoBieProperty("AssetTypeMaterialDescription", ifcTypeObject);
                target.Shape    = helper.GetCoBieProperty("AssetTypeShapeDescription", ifcTypeObject);
                target.Size     = helper.GetCoBieProperty("AssetTypeSizeDescription", ifcTypeObject);
                target.SustainabilityPerformance =
                    helper.GetCoBieProperty("AssetTypeSustainabilityPerformanceDescription", ifcTypeObject);
                target.CodePerformance = helper.GetCoBieProperty("AssetTypeCodePerformance", ifcTypeObject);
                target.Finish          = helper.GetCoBieProperty("AssetTypeFinishDescription", ifcTypeObject);


                target.Warranty.Description   = helper.GetCoBieProperty("AssetTypeWarrantyDescription", ifcTypeObject);
                target.Warranty.DurationLabor = helper.GetCoBieAttribute <DecimalAttributeValue>("AssetTypeWarrantyDurationLabor", ifcTypeObject).Value;
                target.Warranty.DurationParts = helper.GetCoBieAttribute <DecimalAttributeValue>("AssetTypeWarrantyDurationParts", ifcTypeObject).Value;


                if (Enum.TryParse(helper.GetCoBieProperty("AssetTypeWarrantyDurationUnit", ifcTypeObject), true,
                                  out unit))
                {
                    target.Warranty.DurationUnit = unit;
                }
                var laborContact = helper.GetCoBieProperty("AssetTypeWarrantyGuarantorLabor", ifcTypeObject);
                if (!string.IsNullOrWhiteSpace(laborContact))
                {
                    target.Warranty.GuarantorLabor = helper.GetOrCreateContactKey(laborContact);
                }
                var partsContact = helper.GetCoBieProperty("AssetTypeWarrantyGuarantorParts", ifcTypeObject);
                if (!string.IsNullOrWhiteSpace(partsContact))
                {
                    target.Warranty.GuarantorParts = helper.GetOrCreateContactKey(partsContact);
                }
                //Attributes
                target.Attributes = helper.GetAttributes(ifcTypeObject);

                //Documents
                var docsMappings = Exchanger.GetOrCreateMappings <MappingIfcDocumentSelectToDocument>();
                helper.AddDocuments(docsMappings, target, ifcTypeObject);

                //Spare
                var spareMapping = Exchanger.GetOrCreateMappings <MappingIfcConstructionProductResourceToSpare>();
                spareMapping.ParentObject = ifcTypeObject; //set parent object
                if (helper.SpareLookup.ContainsKey(ifcTypeObject))
                {
                    foreach (var item in helper.SpareLookup[ifcTypeObject])
                    {
                        if (target.Spares == null)
                        {
                            target.Spares = new List <Spare>();
                        }
                        target.Spares.Add(spareMapping.AddMapping(item, new Spare()));
                    }
                }

                // Assemblies
                var assemblyMapping = Exchanger.GetOrCreateMappings <MappingIfcRelAggregatesToAssembly>();
                assemblyMapping.EntityType = EntityType.AssetType;

                bool hasAttributes = helper.AssemblyLookup.ContainsKey(ifcTypeObject);
                if (hasAttributes)
                {
                    IIfcRelAggregates ifcRelAggregates = helper.AssemblyLookup[ifcTypeObject];
                    target.AssemblyOf = assemblyMapping.AddMapping(ifcRelAggregates, new Assembly());
                }
            }

            //The Assets

            var assetMappings = Exchanger.GetOrCreateMappings <MappingIfcElementToAsset>();

            if (allAssetsofThisType != null && allAssetsofThisType.Any())
            {
                target.Assets = new List <Asset>();

                foreach (IIfcElement element in allAssetsofThisType)
                {
                    var asset = new Asset();
                    asset = assetMappings.AddMapping(element, asset);
                    //pass categories over from Asset to AssetType, if none set
                    if (!HasCategory)
                    {
                        var assetcat = asset.Categories.FirstOrDefault();
                        if ((assetcat != null) && (assetcat.Code != "unknown"))
                        {
                            target.Categories = asset.Categories;
                            HasCategory       = true;
                        }
                    }
                    target.Assets.Add(asset);
                }
            }

            return(target);
        }