Example #1
0
        /// <summary>
        /// Get list of child object names from relatedObjects property of a ifcProduct asset and join with a " : " delimiter
        /// </summary>
        /// <returns>List of strings fixed to a string limit per string entry</returns>
        private ChildNamesList ConCatChildNamesList(ChildNamesList childNamesUnique, int fieldLength)
        {
            ChildNamesList childNames     = new ChildNamesList();
            int            strCount       = 0;
            List <string>  fieldValueList = new List <string>();

            //build field length strings
            foreach (string str in childNamesUnique)
            {
                if (fieldValueList.Count == 0)
                {
                    strCount += str.Length;
                }
                else
                {
                    strCount += str.Length + 3;     //add 3 fro the " : "
                }
                if (strCount <= fieldLength)
                {
                    fieldValueList.Add(str);
                }
                else
                {
                    childNames.Add(COBieXBim.JoinStrings(':', fieldValueList));
                    strCount = str.Length;     //reset strCount to the current value length
                    fieldValueList.Clear();
                    fieldValueList.Add(str);
                }
            }
            if (fieldValueList.Count > 0)
            {
                childNames.Add(COBieXBim.JoinStrings(':', fieldValueList));
            }
            return(childNames);
        }
Example #2
0
        /// <summary>
        /// get all names from the IfcRelDecomposes RelatedObjects
        /// </summary>
        /// <param name="ifcMaterialLayers">IfcRelDecomposes Object</param>
        /// <returns>list of strings as ChildNamesList class</returns>
        private ChildNamesList ExtractChildNames(List <IfcMaterialLayer> ifcMaterialLayers)
        {
            ChildNamesList childNamesFilter = new ChildNamesList();

            foreach (IfcMaterialLayer ifcMaterialLayer in ifcMaterialLayers)
            {
                if ((ifcMaterialLayer.Material != null) &&
                    (!string.IsNullOrEmpty(ifcMaterialLayer.Material.Name))
                    )
                {
                    string name  = ifcMaterialLayer.Material.Name;
                    double?thick = ifcMaterialLayer.LayerThickness;
                    if (thick != null)
                    {
                        name += " (" + ((double)thick).ToString() + ")";
                    }
                    childNamesFilter.Add(name);
                }
            }
            return(childNamesFilter);
        }
Example #3
0
        /// <summary>
        /// get all names from the IfcRelDecomposes RelatedObjects
        /// </summary>
        /// <param name="ra">IfcRelDecomposes Object</param>
        /// <returns>list of strings as ChildNamesList class</returns>
        private ChildNamesList ExtractChildNames(IfcRelDecomposes ra)
        {
            ChildNamesList childNamesFilter = new ChildNamesList();

            foreach (IfcObjectDefinition obj in ra.RelatedObjects)
            {
                //filter on type filters used for component and type sheet
                if (Context.Exclude.ObjectType.Component.Contains(obj.GetType()))
                {
                    break;
                }
                if (Context.Exclude.ObjectType.Types.Contains(obj.GetType()))
                {
                    break;
                }

                if (!string.IsNullOrEmpty(obj.Name))
                {
                    //if (!childNamesFilter.Contains(obj.Name))//removed the filter as we should recode all elements of the assembly
                    childNamesFilter.Add(obj.Name);
                }
            }
            return(childNamesFilter);
        }
        /// <summary>
        /// Fill sheet rows for Type sheet
        /// </summary>
        /// <returns>COBieSheet</returns>
        public override COBieSheet <COBieTypeRow> Fill()
        {
#if DEBUG
            Stopwatch timer = new Stopwatch();
            timer.Start();
#endif
            ProgressIndicator.ReportMessage("Starting Types...");

            var ifcProject = Model.Instances.FirstOrDefault <IIfcProject>();
            Debug.Assert(ifcProject != null);

            // Create new Sheet
            COBieSheet <COBieTypeRow> types = new COBieSheet <COBieTypeRow>(Constants.WORKSHEET_TYPE);

            //group the types by name as we need to filter duplicate items in for each loop
            IEnumerable <IfcTypeObject> ifcTypeObjects = Model.FederatedInstances.OfType <IfcTypeObject>()
                                                         .Select(type => type)
                                                         .Where(type => !Context.Exclude.ObjectType.Types.Contains(type.GetType()))
                                                         .GroupBy(type => type.Name).SelectMany(g => g);//.Distinct()



            //set up property set helper class
            COBieDataPropertySetValues allPropertyValues = new COBieDataPropertySetValues(); //properties helper class
            COBieDataAttributeBuilder  attributeBuilder  = new COBieDataAttributeBuilder(Context, allPropertyValues);
            attributeBuilder.InitialiseAttributes(ref _attributes);
            attributeBuilder.ExcludeAttributePropertyNames.AddRange(Context.Exclude.Types.AttributesEqualTo);         //we do not want for the attribute sheet so filter them out
            attributeBuilder.ExcludeAttributePropertyNamesWildcard.AddRange(Context.Exclude.Types.AttributesContain); //we do not want for the attribute sheet so filter them out
            attributeBuilder.ExcludeAttributePropertySetNames.AddRange(Context.Exclude.Types.PropertySetsEqualTo);    //exclude the property set from selection of values
            attributeBuilder.RowParameters["Sheet"] = "Type";

            ProgressIndicator.Initialise("Creating Types", ifcTypeObjects.Count());
            //COBieTypeRow lastRow = null;
            foreach (IfcTypeObject type in ifcTypeObjects)
            {
                ProgressIndicator.IncrementAndUpdate();


                COBieTypeRow typeRow = new COBieTypeRow(types);

                // TODO: Investigate centralising this common code.
                string name = type.Name;
                if (string.IsNullOrEmpty(type.Name))
                {
                    name = "Name Unknown " + UnknownCount.ToString();
                    UnknownCount++;
                }

                //set allPropertyValues to this element
                allPropertyValues.SetAllPropertyValues(type); //set the internal filtered IfcPropertySingleValues List in allPropertyValues

                typeRow.Name = name;
                string create_By = allPropertyValues.GetPropertySingleValueValue("COBieTypeCreatedBy", false);  //support for COBie Toolkit for Autodesk Revit
                typeRow.CreatedBy = ValidateString(create_By) ? create_By : GetTelecomEmailAddress(type.OwnerHistory);
                string created_On = allPropertyValues.GetPropertySingleValueValue("COBieTypeCreatedOn", false); //support for COBie Toolkit for Autodesk Revit
                typeRow.CreatedOn = ValidateString(created_On) ? created_On : GetCreatedOnDateAsFmtString(type.OwnerHistory);
                typeRow.Category  = GetCategory(allPropertyValues);
                string description = allPropertyValues.GetPropertySingleValueValue("COBieDescription", false);//support for COBie Toolkit for Autodesk Revit
                typeRow.Description = ValidateString(description) ? description : GetTypeObjDescription(type);

                string ext_System = allPropertyValues.GetPropertySingleValueValue("COBieTypeExtSystem", false);//support for COBie Toolkit for Autodesk Revit
                typeRow.ExtSystem     = ValidateString(ext_System) ? ext_System : GetExternalSystem(type);
                typeRow.ExtObject     = type.GetType().Name;
                typeRow.ExtIdentifier = type.GlobalId;



                FillPropertySetsValues(allPropertyValues, type, typeRow);
                //not duplicate so add to sheet
                //if (CheckForDuplicateRow(lastRow, typeRow))
                //{
                string rowhash = typeRow.RowHashValue;
                if (RowHashs.ContainsKey(rowhash))
                {
                    continue;
                }
                else
                {
                    types.AddRow(typeRow);
                    RowHashs.Add(rowhash, true);
                }

                //lastRow = typeRow; //save this row to test on next loop
                //}
                // Provide Attribute sheet with our context
                //fill in the attribute information
                attributeBuilder.RowParameters["Name"]      = typeRow.Name;
                attributeBuilder.RowParameters["CreatedBy"] = typeRow.CreatedBy;
                attributeBuilder.RowParameters["CreatedOn"] = typeRow.CreatedOn;
                attributeBuilder.RowParameters["ExtSystem"] = typeRow.ExtSystem;
                attributeBuilder.PopulateAttributesRows(type); //fill attribute sheet rows
            }
            ProgressIndicator.Finalise();
            //--------------Loop all IfcMaterialLayerSet-----------------------------
            ProgressIndicator.ReportMessage("Starting MaterialLayerSets...");
            IEnumerable <IfcMaterialLayerSet> ifcMaterialLayerSets = Model.FederatedInstances.OfType <IfcMaterialLayerSet>();
            ChildNamesList rowHolderChildNames      = new ChildNamesList();
            ChildNamesList rowHolderLayerChildNames = new ChildNamesList();

            string createdBy = DEFAULT_STRING, createdOn = DEFAULT_STRING, extSystem = DEFAULT_STRING;
            ProgressIndicator.Initialise("Creating MaterialLayerSets", ifcMaterialLayerSets.Count());

            foreach (IfcMaterialLayerSet ifcMaterialLayerSet in ifcMaterialLayerSets)
            {
                ProgressIndicator.IncrementAndUpdate();
                //Material layer has no owner history, so lets take the owner history from IfcRelAssociatesMaterial.RelatingMaterial -> (IfcMaterialLayerSetUsage.ForLayerSet -> IfcMaterialLayerSet) || IfcMaterialLayerSet || IfcMaterialLayer as it is a IfcMaterialSelect
                IfcOwnerHistory ifcOwnerHistory = GetMaterialOwnerHistory(ifcMaterialLayerSet);
                if (ifcOwnerHistory != null)
                {
                    createdBy = GetTelecomEmailAddress(ifcOwnerHistory);
                    createdOn = GetCreatedOnDateAsFmtString(ifcOwnerHistory);
                    extSystem = GetExternalSystem(ifcOwnerHistory);
                }
                else //default to the project as we failed to find a IfcRoot object to extract it from
                {
                    createdBy = GetTelecomEmailAddress(ifcProject.OwnerHistory);
                    createdOn = GetCreatedOnDateAsFmtString(ifcProject.OwnerHistory);
                    extSystem = GetExternalSystem(ifcProject.OwnerHistory);
                }
                //add materialLayerSet name to rows
                COBieTypeRow matSetRow = new COBieTypeRow(types);
                matSetRow.Name      = (string.IsNullOrEmpty(ifcMaterialLayerSet.LayerSetName)) ? DEFAULT_STRING : ifcMaterialLayerSet.LayerSetName.ToString();
                matSetRow.CreatedBy = createdBy;
                matSetRow.CreatedOn = createdOn;
                matSetRow.ExtSystem = extSystem;
                matSetRow.ExtObject = ifcMaterialLayerSet.GetType().Name;
                matSetRow.AssetType = "Fixed";
                types.AddRow(matSetRow);

                //loop the materials within the material layer set
                foreach (IfcMaterialLayer ifcMaterialLayer in ifcMaterialLayerSet.MaterialLayers)
                {
                    if ((ifcMaterialLayer.Material != null) &&
                        (!string.IsNullOrEmpty(ifcMaterialLayer.Material.Name))
                        )
                    {
                        string name      = ifcMaterialLayer.Material.Name.ToString().Trim();
                        double thickness = ifcMaterialLayer.LayerThickness;
                        string keyName   = name + " (" + thickness.ToString(CultureInfo.InvariantCulture) + ")";
                        if (!rowHolderLayerChildNames.Contains(keyName.ToLower())) //check we do not already have it
                        {
                            COBieTypeRow matRow = new COBieTypeRow(types);

                            matRow.Name         = keyName;
                            matRow.CreatedBy    = createdBy;
                            matRow.CreatedOn    = createdOn;
                            matRow.ExtSystem    = extSystem;
                            matRow.ExtObject    = ifcMaterialLayer.GetType().Name;
                            matRow.AssetType    = "Fixed";
                            matRow.NominalWidth = thickness.ToString();

                            rowHolderLayerChildNames.Add(keyName.ToLower());

                            //we also don't want to repeat on the IfcMaterial loop below
                            if (!rowHolderChildNames.Contains(name.ToLower()))
                            {
                                rowHolderChildNames.Add(name.ToLower());
                            }

                            types.AddRow(matRow);
                        }
                    }
                }
            }
            ProgressIndicator.Finalise();
            //--------Loop Materials in case they are not in a layer Set-----
            ProgressIndicator.ReportMessage("Starting Materials...");

            IEnumerable <IfcMaterial> ifcMaterials = Model.FederatedInstances.OfType <IfcMaterial>();
            ProgressIndicator.Initialise("Creating Materials", ifcMaterials.Count());
            foreach (IfcMaterial ifcMaterial in ifcMaterials)
            {
                ProgressIndicator.IncrementAndUpdate();
                string name = ifcMaterial.Name.ToString().Trim();
                if (!string.IsNullOrEmpty(ifcMaterial.Name))
                {
                    if (!rowHolderChildNames.Contains(name.ToLower())) //check we do not already have it
                    {
                        COBieTypeRow matRow = new COBieTypeRow(types);

                        matRow.Name      = name;
                        matRow.CreatedBy = createdBy; //no way of extraction on material, if no material layer set, so use last found in Layer Set loop
                        matRow.CreatedOn = createdOn; //ditto
                        matRow.ExtSystem = extSystem; //ditto
                        matRow.ExtObject = ifcMaterial.GetType().Name;
                        matRow.AssetType = "Fixed";

                        types.AddRow(matRow);
                    }

                    rowHolderChildNames.Add(name.ToLower());
                }
            }

            types.OrderBy(s => s.Name);

            ProgressIndicator.Finalise();

#if DEBUG
            timer.Stop();
            Console.WriteLine(String.Format("Time to generate Type data = {0} seconds", timer.Elapsed.TotalSeconds.ToString("F3")));
#endif
            return(types);
        }
Example #5
0
        /// <summary>
        /// Fill sheet rows for Assembly sheet
        /// </summary>
        /// <returns>COBieSheet</returns>
        public override COBieSheet <COBieAssemblyRow> Fill()
        {
            ProgressIndicator.ReportMessage("Starting Assemblies...");
            //Create new sheet

            var ifcProject = Model.Instances.FirstOrDefault <IIfcProject>();

            Debug.Assert(ifcProject != null);

            COBieSheet <COBieAssemblyRow> assemblies = new COBieSheet <COBieAssemblyRow>(Constants.WORKSHEET_ASSEMBLY);

            // get ifcRelAggregates objects from IFC file what are not in the excludedTypes type list
            IEnumerable <IfcRelAggregates> ifcRelAggregates = Model.FederatedInstances.OfType <IfcRelAggregates>();
            IEnumerable <IfcRelNests>      ifcRelNests      = Model.FederatedInstances.OfType <IfcRelNests>();


            IEnumerable <IfcRelDecomposes> relAll = (from ra in ifcRelAggregates
                                                     where ((ra.RelatingObject is IfcProduct) || (ra.RelatingObject is IfcTypeObject)) && !Context.Exclude.ObjectType.Assembly.Contains(ra.RelatingObject.GetType())
                                                     select ra as IfcRelDecomposes).Union
                                                        (from rn in ifcRelNests
                                                        where ((rn.RelatingObject is IfcProduct) || (rn.RelatingObject is IfcTypeObject)) && !Context.Exclude.ObjectType.Assembly.Contains(rn.RelatingObject.GetType())
                                                        select rn as IfcRelDecomposes);

            ProgressIndicator.Initialise("Creating Assemblies", relAll.Count());

            int childColumnLength = 255; //default vale, reassigned below

            foreach (IfcRelDecomposes ra in relAll)
            {
                ProgressIndicator.IncrementAndUpdate();
                COBieAssemblyRow assembly = new COBieAssemblyRow(assemblies);
                if (string.IsNullOrEmpty(ra.Name))
                {
                    if (!string.IsNullOrEmpty(ra.RelatingObject.Name))
                    {
                        assembly.Name = (string.IsNullOrEmpty(ra.RelatingObject.Name)) ? DEFAULT_STRING : ra.RelatingObject.Name.ToString();
                    }
                    else
                    {
                        assembly.Name = DEFAULT_STRING;
                    }
                }
                else
                {
                    assembly.Name = ra.Name.ToString();
                }

                assembly.CreatedBy  = GetTelecomEmailAddress(ra.OwnerHistory);
                assembly.CreatedOn  = GetCreatedOnDateAsFmtString(ra.OwnerHistory);
                assembly.SheetName  = GetSheetByObjectType(ra.RelatingObject.GetType());
                assembly.ParentName = ra.RelatingObject.Name;

                assembly.AssemblyType = "Fixed"; //as Responsibility matrix instruction
                assembly.ExtSystem    = GetExternalSystem(ra);
                assembly.ExtObject    = ra.GetType().Name;
                if (!string.IsNullOrEmpty(ra.GlobalId))
                {
                    assembly.ExtIdentifier = ra.GlobalId.ToString();
                }

                assembly.Description = GetAssemblyDescription(ra);

                //get the assembly child names of objects that make up assembly
                ChildNamesList childNamesUnique = ExtractChildNames(ra);
                if (childColumnLength == 0)
                {
                    childColumnLength = assembly["ChildNames"].COBieColumn.ColumnLength;
                }
                ChildNamesList childNames = ConCatChildNamesList(childNamesUnique, childColumnLength);
                if (childNames.Count > 0)
                {
                    AddChildRows(assemblies, assembly, childNames);
                }
            }

            //--------------Loop all IfcMaterialLayerSet-----------------------------
            IEnumerable <IfcMaterialLayerSet> ifcMaterialLayerSets = Model.FederatedInstances.OfType <IfcMaterialLayerSet>();
            char setNamePostFix = 'A';

            foreach (IfcMaterialLayerSet ifcMaterialLayerSet in ifcMaterialLayerSets)
            {
                COBieAssemblyRow assembly = new COBieAssemblyRow(assemblies);
                if (string.IsNullOrEmpty(ifcMaterialLayerSet.LayerSetName))
                {
                    assembly.Name = "Material Layer Set " + setNamePostFix;
                    setNamePostFix++;
                }
                else
                {
                    assembly.Name = ifcMaterialLayerSet.LayerSetName.ToString();
                }

                //Material layer has no owner history, so lets take the owner history from IfcRelAssociatesMaterial.RelatingMaterial -> (IfcMaterialLayerSetUsage.ForLayerSet -> IfcMaterialLayerSet) || IfcMaterialLayerSet || IfcMaterialLayer as it is a IfcMaterialSelect
                IfcOwnerHistory ifcOwnerHistory = GetMaterialOwnerHistory(ifcMaterialLayerSet);

                if (ifcOwnerHistory != null)
                {
                    assembly.CreatedBy = GetTelecomEmailAddress(ifcOwnerHistory);
                    assembly.CreatedOn = GetCreatedOnDateAsFmtString(ifcOwnerHistory);
                    assembly.ExtSystem = GetExternalSystem(ifcOwnerHistory);
                }
                else //default to the project as we failed to find a IfcRoot object to extract it from
                {
                    assembly.CreatedBy = GetTelecomEmailAddress(ifcProject.OwnerHistory);
                    assembly.CreatedOn = GetCreatedOnDateAsFmtString(ifcProject.OwnerHistory);
                    assembly.ExtSystem = GetExternalSystem(ifcProject.OwnerHistory);
                }

                assembly.SheetName    = Constants.WORKSHEET_TYPE; //any material objects should be in the TYPE sheet
                assembly.Description  = GetMaterialSetDescription(ifcMaterialLayerSet.MaterialLayers.ToList());
                assembly.ParentName   = (!string.IsNullOrEmpty(ifcMaterialLayerSet.LayerSetName)) ? ifcMaterialLayerSet.LayerSetName : new IfcLabel(DEFAULT_STRING);
                assembly.AssemblyType = "Layer";
                assembly.ExtObject    = ifcMaterialLayerSet.GetType().Name;

                //Loop Material names
                ChildNamesList childNamesUnique = ExtractChildNames(ifcMaterialLayerSet.MaterialLayers.ToList());
                ChildNamesList childNames       = ConCatChildNamesList(childNamesUnique, childColumnLength); //childColumnLength is max number of chars for the ChildNames cell
                if (childNames.Count > 0)
                {
                    AddChildRows(assemblies, assembly, childNames);
                }
            }

            assemblies.OrderBy(s => s.Name);

            ProgressIndicator.Finalise();

            return(assemblies);
        }
Example #6
0
        /// <summary>
        /// Add the child row and overflow rows
        /// </summary>
        /// <param name="assemblies">COBieSheet to add rows too</param>
        /// <param name="assembly">COBieAssemblyRow object to copy data from</param>
        /// <param name="childNames">ChildNamesList object holing the names to add to the rows</param>
        private void AddChildRows(COBieSheet <COBieAssemblyRow> assemblies, COBieAssemblyRow assembly, ChildNamesList childNames)
        {
            COBieAssemblyRow assemblyCont = null;
            int index = 0;

            foreach (string childStr in childNames)
            {
                if (index == 0)
                {
                    assembly.ChildNames = childStr;
                    assemblies.AddRow(assembly);
                }
                else
                {
                    assemblyCont               = new COBieAssemblyRow(assemblies);
                    assemblyCont.Name          = assembly.Name + " : continued " + index.ToString();
                    assemblyCont.CreatedBy     = assembly.CreatedBy;
                    assemblyCont.CreatedOn     = assembly.CreatedOn;
                    assemblyCont.SheetName     = assembly.SheetName;
                    assemblyCont.ParentName    = assembly.ParentName;
                    assemblyCont.AssemblyType  = assembly.AssemblyType;
                    assemblyCont.ExtSystem     = assembly.ExtSystem;
                    assemblyCont.ExtObject     = assembly.ExtObject;
                    assemblyCont.ExtIdentifier = assembly.ExtIdentifier;
                    assemblyCont.Description   = assembly.Description;
                    assemblyCont.ChildNames    = childStr;
                    assemblies.AddRow(assemblyCont);
                }
                index = ++index;
            }
        }