Exemplo n.º 1
0
        /// <summary>
        /// Get the parent object for the ifcRelDecomposes object
        /// </summary>
        /// <param name="parentName">Math the Name property with this string</param>
        /// <returns>IfcObjectDefinition </returns>
        private IfcObjectDefinition GetParentObject(string parentName)
        {
            string name = parentName.ToLower().Trim();
            IfcObjectDefinition RelatingObject = IfcElements.Where(obj => obj.Name.ToString().ToLower().Trim() == name).FirstOrDefault();

            if (RelatingObject == null) //try IfcTypeObjects
            {
                RelatingObject = IfcTypeObjects.Where(obj => obj.Name.ToString().ToLower().Trim() == name).FirstOrDefault();
            }
            return(RelatingObject);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add the properties to the row object
        /// </summary>
        /// <param name="row">COBieAttributeRow holding the data</param>
        private void AddAttribute(COBieAttributeRow row)
        {
            //need a sheet and a row to be able to attach property to an object
            if ((ValidateString(row.RowName)) && (ValidateString(row.SheetName)))
            {
                switch (row.SheetName.ToLower())
                {
                case "facility":
                    //set list if first time
                    if (IfcBuildings == null)
                    {
                        IfcBuildings = Model.Instances.OfType <IfcBuilding>();
                    }
                    if (!((CurrentObject is IfcBuilding) && (CurrentObject.Name == row.RowName)))
                    {
                        CurrentObject = IfcBuildings.Where(b => b.Name.ToString().ToLower() == row.RowName.ToLower()).FirstOrDefault();
                    }
                    break;

                case "floor":
                    if (IfcBuildingStoreys == null)
                    {
                        IfcBuildingStoreys = Model.Instances.OfType <IfcBuildingStorey>();
                    }
                    if (!((CurrentObject is IfcBuildingStorey) && (CurrentObject.Name == row.RowName)))
                    {
                        CurrentObject = IfcBuildingStoreys.Where(b => b.Name.ToString().ToLower() == row.RowName.ToLower()).FirstOrDefault();
                    }
                    break;

                case "space":
                    if (IfcSpaces == null)
                    {
                        IfcSpaces = Model.Instances.OfType <IfcSpace>();
                    }
                    if (!((CurrentObject is IfcSpace) && (CurrentObject.Name == row.RowName)))
                    {
                        CurrentObject = IfcSpaces.Where(b => b.Name.ToString().ToLower() == row.RowName.ToLower()).FirstOrDefault();
                    }
                    break;

                case "type":
                    if (IfcTypeObjects == null)
                    {
                        IfcTypeObjects = Model.Instances.OfType <IfcTypeObject>();
                    }
                    if (!((CurrentObject is IfcTypeObject) && (CurrentObject.Name == row.RowName)))
                    {
                        CurrentObject = IfcTypeObjects.Where(b => b.Name.ToString().ToLower() == row.RowName.ToLower()).FirstOrDefault();
                    }
                    break;

                case "spare":
                    if (IfcConstructionProductResources == null)
                    {
                        IfcConstructionProductResources = Model.Instances.OfType <IfcConstructionProductResource>();
                    }
                    if (!((CurrentObject is IfcConstructionProductResource) && (CurrentObject.Name == row.RowName)))
                    {
                        CurrentObject = IfcConstructionProductResources.Where(b => b.Name.ToString().ToLower() == row.RowName.ToLower()).FirstOrDefault();
                    }
                    break;

                case "component":
                    if (IfcElements == null)
                    {
                        IfcElements = Model.Instances.OfType <IfcElement>();
                    }
                    if (!((CurrentObject is IfcElement) && (CurrentObject.Name == row.RowName)))
                    {
                        CurrentObject = IfcElements.Where(b => b.Name.ToString().ToLower() == row.RowName.ToLower()).FirstOrDefault();
                    }
                    break;

                case "zone":
                    if (IfcZones == null)
                    {
                        IfcZones = Model.Instances.OfType <IfcZone>();
                    }
                    if (!((CurrentObject is IfcZone) && (CurrentObject.Name == row.RowName)))
                    {
                        CurrentObject = IfcZones.Where(b => b.Name.ToString().ToLower() == row.RowName.ToLower()).FirstOrDefault();
                    }
                    break;

                default:
                    CurrentObject = null;
                    break;
                }

                if (CurrentObject != null)
                {
                    if (ValidateString(row.Name))
                    {
                        IfcPropertySet ifcPropertySet = CheckIfExistOnMerge(row.ExtObject, row.ExtIdentifier);

                        if (ifcPropertySet == null)
                        {
                            return;
                        }

                        //Set Description
                        string description = "";
                        if (ValidateString(row.Description))
                        {
                            description = row.Description;
                        }


                        if ((ValidateString(row.Value)) &&
                            row.Value.Contains(":") &&
                            row.Value.Contains("(") &&
                            row.Value.Contains(")")
                            )//only if we have a IfcPropertyTableValue defined by COBieDataAttributeBuilder
                        {
                            AddPropertyTableValue(ifcPropertySet, row.Name, description, row.Value, row.AllowedValues, row.Unit);
                        }
                        else if ((ValidateString(row.AllowedValues)) &&
                                 //row.Value.Contains(":") && can be single value
                                 (row.AllowedValues.Contains(":") ||
                                  row.AllowedValues.Contains(",")
                                 )
                                 )//have a IfcPropertyEnumeratedValue
                        {
                            IfcValue[] ifcValues     = GetValueArray(row.Value);
                            IfcValue[] ifcValueEnums = GetValueArray(row.AllowedValues);
                            IfcUnit    ifcUnit       = GetIfcUnit(row.Unit);
                            AddPropertyEnumeratedValue(ifcPropertySet, row.Name, description, ifcValues, ifcValueEnums, ifcUnit);
                        }
                        else
                        {
                            IfcValue ifcValue;
                            double   number;
                            if (double.TryParse(row.Value, out number))
                            {
                                ifcValue = new IfcReal((double)number);
                            }
                            else if (ValidateString(row.Value))
                            {
                                ifcValue = new IfcLabel(row.Value);
                            }
                            else
                            {
                                ifcValue = new IfcLabel("");
                            }
                            IfcUnit ifcUnit = GetIfcUnit(row.Unit);
                            AddPropertySingleValue(ifcPropertySet, row.Name, description, ifcValue, ifcUnit);
                        }

                        //Add Category****
                        if (ValidateString(row.Category))
                        {
                            SetCategory(ifcPropertySet, row.Category);
                        }

                        //****************Note need this as last call Add OwnerHistory*************
                        if (ifcPropertySet != null)
                        {
                            //Add Created By, Created On and ExtSystem to Owner History.
                            SetUserHistory(ifcPropertySet, row.ExtSystem, row.CreatedBy, row.CreatedOn);
                        }
                        //****************Note need SetOwnerHistory above to be last call, as XBim changes to default on any property set or changed, cannot use edit context as property set used more than once per row******
                    }
                    else
                    {
 #if DEBUG
                        Console.WriteLine("Failed to create attribute. No name : {0} value {1}", row.Name, row.ExtObject);
#endif
                    }
                }
                else
                {
#if DEBUG
                    Console.WriteLine("Failed to create attribute. No object found to add too {0} value {1}", row.Name, row.ExtObject);
#endif
                }
            }
            else
            {
#if DEBUG
                Console.WriteLine("Failed to create attribute. No sheet or row name {0} value {1}", row.Name, row.ExtObject);
#endif
            }
        }