/// <summary>
        /// Return the Description for the passed IfcTypeObject object
        /// </summary>
        /// <param name="type">IfcTypeObject</param>
        /// <returns>Description for Type Object</returns>
        private string GetTypeObjDescription(IfcTypeObject type)
        {
            if (type != null)
            {
                if (!string.IsNullOrEmpty(type.Description))
                {
                    return(type.Description);
                }
                else if (!string.IsNullOrEmpty(type.Name))
                {
                    return(type.Name);
                }

                //if supports PredefinedType and no description or name then use the predefined type or ElementType if they exist
                IEnumerable <PropertyInfo> pInfo = type.GetType().GetProperties(); //get properties
                var predefinedType = pInfo.Where(p => p.Name == "PredefinedType").FirstOrDefault();
                if (predefinedType != null)
                {
                    string temp = predefinedType.GetValue(type, null).ToString(); //get predefindtype as description

                    if (!string.IsNullOrEmpty(temp))
                    {
                        if (temp == "USERDEFINED")
                        {
                            //if used defined then the type description should be in ElementType, so see if property exists
                            var elementType = pInfo.Where(p => p.Name == "ElementType").FirstOrDefault();
                            if (elementType != null)
                            {
                                temp = elementType.GetValue(type, null).ToString(); //get ElementType
                                if (!string.IsNullOrEmpty(temp))
                                {
                                    return(temp);
                                }
                            }
                        }
                        if (temp == "NOTDEFINED") //if not defined then give up and return default
                        {
                            return(DEFAULT_STRING);
                        }

                        return(temp);
                    }
                }
            }
            return(DEFAULT_STRING);
        }
示例#2
0
        public AssetTypeInfoType(IfcTypeObject ifcTypeObject, CoBieLiteHelper helper)
            : this()
        {
            externalEntityName = helper.ExternalEntityName(ifcTypeObject);
            externalID         = helper.ExternalEntityIdentity(ifcTypeObject);
            externalSystemName = helper.ExternalSystemName(ifcTypeObject);
            AssetTypeName      = ifcTypeObject.Name;
            AssetTypeCategory  = helper.GetClassification(ifcTypeObject);
            string accCategoryString = helper.GetCoBieProperty("AssetTypeAccountingCategory", ifcTypeObject);
            AssetPortabilitySimpleType accCategoryEnum;

            if (Enum.TryParse(accCategoryString, true, out accCategoryEnum))
            {
                AssetTypeAccountingCategory = accCategoryEnum;
            }
            else
            {
                CoBieLiteHelper.Logger.WarnFormat("AssetTypeAccountingCategory: An illegal value of [{0}] has been passed for the category of #{1}={2}. It has been replaced with a value of 'Item'", accCategoryString, ifcTypeObject.EntityLabel, ifcTypeObject.GetType().Name);
                AssetTypeAccountingCategory = AssetPortabilitySimpleType.Item;
            }
            if (string.IsNullOrWhiteSpace(AssetTypeCategory)) //try the asset assignment
            {
                IfcAsset ifcAsset;
                if (helper.AssetAsignments.TryGetValue(ifcTypeObject, out ifcAsset))
                {
                    AssetTypeCategory = helper.GetCoBieAttribute <StringValueType>("AssetTypeAccountingCategory", ifcAsset).StringValue;
                }
            }
            AssetTypeDescription             = ifcTypeObject.Description;
            AssetTypeModelNumber             = helper.GetCoBieProperty("AssetTypeModelNumber", ifcTypeObject);
            AssetTypeReplacementCostValue    = helper.GetCoBieAttribute <DecimalValueType>("AssetTypeReplacementCostValue", ifcTypeObject);
            AssetTypeExpectedLifeValue       = helper.GetCoBieAttribute <IntegerValueType>("AssetTypeExpectedLifeValue", ifcTypeObject);
            AssetTypeNominalLength           = helper.GetCoBieAttribute <DecimalValueType>("AssetTypeNominalLength", ifcTypeObject);
            AssetTypeNominalWidth            = helper.GetCoBieAttribute <DecimalValueType>("AssetTypeNominalWidth", ifcTypeObject);
            AssetTypeNominalHeight           = helper.GetCoBieAttribute <DecimalValueType>("AssetTypeNominalHeight", ifcTypeObject);
            AssetTypeAccessibilityText       = helper.GetCoBieProperty("AssetTypeAccessibilityText", ifcTypeObject);
            AssetTypeColorCode               = helper.GetCoBieProperty("AssetTypeColorCode", ifcTypeObject);
            AssetTypeConstituentsDescription = helper.GetCoBieProperty("AssetTypeConstituentsDescription", ifcTypeObject);
            AssetTypeFeaturesDescription     = helper.GetCoBieProperty("AssetTypeFeaturesDescription", ifcTypeObject);
            AssetTypeGradeDescription        = helper.GetCoBieProperty("AssetTypeGradeDescription", ifcTypeObject);
            AssetTypeMaterialDescription     = helper.GetCoBieProperty("AssetTypeMaterialDescription", ifcTypeObject);
            AssetTypeShapeDescription        = helper.GetCoBieProperty("AssetTypeShapeDescription", ifcTypeObject);
            AssetTypeSizeDescription         = helper.GetCoBieProperty("AssetTypeSizeDescription", ifcTypeObject);
            AssetTypeSustainabilityPerformanceDescription = helper.GetCoBieProperty("AssetTypeSustainabilityPerformanceDescription", ifcTypeObject);

            //The Assets
            List <IfcElement> allAssetsofThisType;

            if (helper.DefiningTypeObjectMap.TryGetValue(ifcTypeObject, out allAssetsofThisType)) //should always work
            {
                Assets = new AssetCollectionType {
                    Asset = new AssetInfoType[allAssetsofThisType.Count]
                };
                for (int i = 0; i < allAssetsofThisType.Count; i++)
                {
                    Assets.Asset[i] = new AssetInfoType(allAssetsofThisType[i], helper);;
                }
            }
            else
            {
                //just in case we have a problem
                CoBieLiteHelper.Logger.ErrorFormat("Asset Type: Failed to locate Asset Type #{0}={1}", ifcTypeObject.EntityLabel, ifcTypeObject.GetType().Name);
            }

            //Attributes
            AttributeType[] ifcAttributes = helper.GetAttributes(ifcTypeObject);
            if (ifcAttributes != null && ifcAttributes.Length > 0)
            {
                AssetTypeAttributes = new AttributeCollectionType {
                    Attribute = ifcAttributes
                }
            }
            ;
        }
    }
示例#3
0
        /// <summary>
        /// Add the Impact and fill with data from COBieComponentRow
        /// </summary>
        /// <param name="row">COBieImpactRow holding the data</param>
        private void AddImpact(COBieImpactRow row)
        {
            string pSetName    = "Pset_EnvironmentalImpactValues";
            string description = Constants.DEFAULT_STRING;

            if (ValidateString(row.Description))
            {
                description = row.Description;
            }

            IfcPropertySet ifcPropertySet = null;

            if (row.SheetName.ToLower().Trim() == "type")
            {
                if (IfcTypeObjects == null)
                {
                    IfcTypeObjects = Model.Instances.OfType <IfcTypeObject>();
                }
                IfcTypeObject ifcTypeObject = IfcTypeObjects.Where(to => to.Name.ToString().ToLower() == row.RowName.ToLower()).FirstOrDefault();
                if (ifcTypeObject != null)
                {
                    if (XBimContext.IsMerge)
                    {
                        ifcPropertySet = ifcTypeObject.GetPropertySet(pSetName);
                        if (ifcPropertySet != null) //Property set Pset_EnvironmentalImpactValues already set so assume exists so skip
                        {
#if DEBUG
                            Console.WriteLine("{0} Pset_EnvironmentalImpactValues Property set so skip on merge", ifcTypeObject.GetType().Name);
#endif
                            return;
                        }
                    }

                    ifcPropertySet = AddPropertySet(ifcTypeObject, pSetName, description);
                }
            }
            else
            {
                if (IfcProducts == null)
                {
                    IfcProducts = Model.Instances.OfType <IfcProduct>();
                }
                IfcProduct ifcProduct = IfcProducts.Where(to => to.Name.ToString().ToLower() == row.RowName.ToLower()).FirstOrDefault();
                if (ifcProduct != null)
                {
                    if (XBimContext.IsMerge)
                    {
                        ifcPropertySet = ifcProduct.GetPropertySet(pSetName);
                        if (ifcPropertySet != null)//Property set Pset_EnvironmentalImpactValues already set so assume exists so skip
                        {
#if DEBUG
                            Console.WriteLine("{0} Pset_EnvironmentalImpactValues Property set so skip on merge", ifcProduct.GetType().Name);
#endif
                            return;
                        }
                    }

                    ifcPropertySet = AddPropertySet(ifcProduct, pSetName, description);
                }
            }

            //check we have a property set from the found SheetName/RowName object
            if (ifcPropertySet != null)
            {
                //Add Created By, Created On and ExtSystem to Owner History.
                SetUserHistory(ifcPropertySet, row.ExtSystem, row.CreatedBy, row.CreatedOn);
                //using statement will set the Model.OwnerHistoryAddObject to ifcPropertySet.OwnerHistory as OwnerHistoryAddObject is used upon any property changes,
                //then swaps the original OwnerHistoryAddObject back in the dispose, so set any properties within the using statement
                using (COBieXBimEditScope context = new COBieXBimEditScope(Model, ifcPropertySet.OwnerHistory))
                {
                    if (ValidateString(row.Name))
                    {
                        AddPropertySingleValue(ifcPropertySet, "ImpactName", "Impact Name", new IfcText(row.Name), null);
                    }

                    if (ValidateString(row.ImpactType))
                    {
                        AddPropertySingleValue(ifcPropertySet, "ImpactType", "Impact Type", new IfcText(row.ImpactType), null);
                    }

                    if (ValidateString(row.ImpactStage))
                    {
                        AddPropertySingleValue(ifcPropertySet, "ImpactStage", "Impact Stage", new IfcText(row.ImpactStage), null);
                    }

                    if (ValidateString(row.Value))
                    {
                        IfcValue ifcValue = SetValue(row.Value);

                        IfcUnit ifcUnit = null;
                        if (ValidateString(row.ImpactUnit))
                        {
                            ifcUnit = GetDurationUnit(row.ImpactUnit); //see if time unit
                            //see if we can convert to a IfcSIUnit
                            if (ifcUnit == null)
                            {
                                ifcUnit = GetSIUnit(row.ImpactUnit);
                            }
                            //OK set as a user defined
                            if (ifcUnit == null)
                            {
                                ifcUnit = SetContextDependentUnit(row.ImpactUnit);
                            }
                        }
                        AddPropertySingleValue(ifcPropertySet, "Value", "Value", ifcValue, ifcUnit);
                    }

                    if (ValidateString(row.LeadInTime))
                    {
                        IfcValue ifcValue = SetValue(row.LeadInTime);
                        AddPropertySingleValue(ifcPropertySet, "LeadInTime", "Lead In Time", ifcValue, null);
                    }

                    if (ValidateString(row.Duration))
                    {
                        IfcValue ifcValue = SetValue(row.Duration);
                        AddPropertySingleValue(ifcPropertySet, "Duration", "Duration", ifcValue, null);
                    }

                    if (ValidateString(row.LeadOutTime))
                    {
                        IfcValue ifcValue = SetValue(row.LeadOutTime);
                        AddPropertySingleValue(ifcPropertySet, "LeadOutTime", "Lead Out Time", ifcValue, null);
                    }

                    //Add GlobalId
                    AddGlobalId(row.ExtIdentifier, ifcPropertySet);

                    //row.Description done above on property set
                }
            }
        }