コード例 #1
0
        /// <summary>
        /// Add element relationship to a parent object
        /// </summary>
        /// <param name="ifcElement">IfcElement object</param>
        /// <param name="spaceNames">Name used as key to find parent object</param>
        private void AddElementRelationship(IfcElement ifcElement, string spaceNames)
        {
            spaceNames = spaceNames.ToLower().Trim();
            IfcSpace          ifcSpace          = null;
            IfcBuildingStorey ifcBuildingStorey = null;

            //see if the full name is in spaces
            ifcSpace = IfcSpaces.Where(space => space.Name.ToString().ToLower().Trim() == spaceNames).FirstOrDefault();
            if (ifcSpace != null)
            {
                ifcSpace.AddElement(ifcElement);
            }
            else //not in spaces so try Floors
            {
                ifcBuildingStorey = IfcBuildingStoreys.Where(bs => bs.Name.ToString().ToLower().Trim() == spaceNames).FirstOrDefault();
                if (ifcBuildingStorey != null)
                {
                    ifcBuildingStorey.AddElement(ifcElement);
                }
                else //not in floors so see if the space names is a delimited list
                {
                    var splitKey   = GetSplitChar(spaceNames);
                    var spaceArray = spaceNames.Split(splitKey);
                    if (spaceArray.Count() > 1) //if one we have already tried above, if more than one then try each item
                    {
                        foreach (var spaceitem in spaceArray)
                        {
                            var spaceName = spaceitem.Trim();
                            ifcSpace = IfcSpaces.Where(space => space.Name.ToString().ToLower().Trim() == spaceName).FirstOrDefault();
                            if (ifcSpace != null)
                            {
                                ifcSpace.AddElement(ifcElement);
                            }
                            else
                            {
                                ifcBuildingStorey = IfcBuildingStoreys.Where(bs => bs.Name.ToString().ToLower().Trim() == spaceName).FirstOrDefault();
                                if (ifcBuildingStorey != null)
                                {
                                    ifcBuildingStorey.AddElement(ifcElement);
                                }
                                else
                                {
                                    GetBuilding().AddElement(ifcElement); //default to building, probably give incorrect bounding box as we do not know what the element parent was
                                }
                            }
                        }
                    }
                    else
                    {
                        GetBuilding().AddElement(ifcElement); //default to building, probably give incorrect bounding box as we do not know what the element parent was
                    }
                }
            }
        }
コード例 #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
            }
        }