Esempio n. 1
0
        /// <summary>
        /// Add products to system group and fill with data from COBieSystemRow
        /// </summary>
        /// <param name="row">COBieSystemRow holding the data</param>
        private void AddProducts(COBieSystemRow row)
        {
            string componentNames = row.ComponentNames;

            using (COBieXBimEditScope context = new COBieXBimEditScope(Model, IfcSystemObj.OwnerHistory))
            {
                List <IfcProduct> ifcProductList = new List <IfcProduct>();

                //check to see is the component name is a single component
                List <string> compNames    = new List <string>();
                string        testCompName = componentNames.ToLower().Trim();
                IfcProduct    ifcProduct   = Model.FederatedInstances.OfType <IfcProduct>().Where(p => p.Name.ToString().ToLower().Trim() == testCompName).FirstOrDefault();
                if (ifcProduct != null)
                {
                    compNames.Add(componentNames);
                }
                else
                {
                    compNames = SplitTheString(componentNames); //multiple components in string
                }
                foreach (string componentName in compNames)
                {
                    ifcProduct = null;
                    if (ValidateString(componentName))
                    {
                        string compName = componentName.ToLower().Trim();
                        ifcProduct = Model.FederatedInstances.OfType <IfcProduct>().Where(p => p.Name.ToString().ToLower().Trim() == compName).FirstOrDefault();
                        if (ifcProduct != null)
                        {
                            ifcProductList.Add(ifcProduct);
                        }
                    }
                    if (ifcProduct == null)
                    {
                        string elementTypeName = GetPrefixType(componentName);
                        if (string.IsNullOrEmpty(elementTypeName))
                        {
                            elementTypeName = "IfcDistributionElement";
                        }
                        ifcProduct = COBieXBimComponent.GetElementInstance(elementTypeName, Model);
                        if (ifcProduct != null)
                        {
                            if (string.IsNullOrEmpty(componentName) || (componentName == Constants.DEFAULT_STRING))
                            {
                                ifcProduct.Name = ""; //row.Name + " " + SystemProdutIndex.ToString();
                                SystemProdutIndex++;
                            }
                            else
                            {
                                ifcProduct.Name = componentName;
                            }
                            ifcProduct.Description = "Created to maintain relationship with System object from COBie information";
                            ifcProductList.Add(ifcProduct);
                        }
                    }
                }
                if (ifcProductList.Count == 0) //no products created so create an IfcDistributionElement as place holder
                {
                    ifcProduct = COBieXBimComponent.GetElementInstance("IfcDistributionElement", Model);
                    if (ifcProduct != null)
                    {
                        ifcProduct.Name        = ""; // row.Name + " " + SystemProdutIndex.ToString(); ;
                        ifcProduct.Description = "Created to maintain relationship with System object from COBie information";
                        ifcProductList.Add(ifcProduct);
                    }
                }

                //if we have found product then add to the IfcSystem group
                foreach (IfcProduct ifcProd in ifcProductList)
                {
                    if (IfcSystemObj.IsGroupedBy != null)                               //if we already have a IfcRelAssignsToGroup assigned to IsGroupedBy
                    {
                        if (!IfcSystemObj.IsGroupedBy.RelatedObjects.Contains(ifcProd)) //check to see if product already exists in group
                        {
                            IfcSystemObj.AddObjectToGroup(ifcProd);                     //if not add
                        }
                    }
                    else
                    {
                        IfcSystemObj.AddObjectToGroup(ifcProd);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Add the object the document relates too
        /// </summary>
        /// <param name="row">COBieDocumentRow holding row data</param>
        private IfcRoot GetObjectRelationship(COBieDocumentRow row)
        {
            IfcRoot ifcRoot = null;

            if ((ValidateString(row.SheetName)) && (ValidateString(row.RowName)))
            {
                string sheetName = row.SheetName.ToLower().Trim();
                sheetName = char.ToUpper(sheetName[0]) + sheetName.Substring(1);

                string rowName = row.RowName.ToLower().Trim();

                string extObject = string.Empty;
                if (ValidateString(row.ExtObject)) //if valid change to correct type
                {
                    extObject = row.ExtObject.Trim().ToUpper();
                }

                switch (sheetName)
                {
                case Constants.WORKSHEET_TYPE:
                    //get all types, one time only
                    if (IfcTypeObjects == null)
                    {
                        IfcTypeObjects = Model.FederatedInstances.OfType <IfcTypeObject>();
                    }
                    ifcRoot = IfcTypeObjects.Where(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                    if (ifcRoot == null)
                    {
                        string typeName = string.Empty;
                        if (ValidateString(extObject))
                        {
                            typeName = extObject;
                        }
                        else
                        {
                            typeName = "IFCBUILDINGELEMENTPROXYTYPE";
                        }
                        ifcRoot             = COBieXBimType.GetTypeInstance(typeName, Model);
                        ifcRoot.Name        = row.RowName;
                        ifcRoot.Description = "Created to maintain relationship with document object from COBie information";
                    }
                    break;

                case Constants.WORKSHEET_COMPONENT:
                    //get all types, one time only
                    if (IfcElements == null)
                    {
                        IfcElements = Model.FederatedInstances.OfType <IfcElement>();
                    }
                    ifcRoot = IfcElements.Where(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                    string elementTypeName = "IFCVIRTUALELEMENT";
                    if (ifcRoot == null)
                    {
                        if (ValidateString(extObject))     //if valid change to correct type
                        {
                            elementTypeName = extObject;
                        }

                        ifcRoot             = COBieXBimComponent.GetElementInstance(elementTypeName, Model);
                        ifcRoot.Name        = row.RowName;
                        ifcRoot.Description = "Created to maintain relationship with document object from COBie information";
                    }
                    else if ((ifcRoot.GetType().Name.ToUpper() == elementTypeName) && //check type, if IFCVIRTUALELEMENT and
                             (ValidateString(extObject)) &&
                             (extObject != elementTypeName) &&                        //not IFCVIRTUALELEMENT then delete virtual, and add correct type
                             (ValidateString(ifcRoot.Description)) &&                 //ensure we set to maintain relationship on another sheet
                             (ifcRoot.Description.ToString().Contains("COBie information"))
                             )
                    {
                        try
                        {
                            Model.Delete(ifcRoot);     //remove IFCVIRTUALELEMENT, probably added by system sheet
                            elementTypeName     = extObject;
                            ifcRoot             = COBieXBimComponent.GetElementInstance(elementTypeName, Model);
                            ifcRoot.Name        = row.RowName;
                            ifcRoot.Description = "Created to maintain relationship with document object from COBie information";
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(string.Format("Failed to delete ifcRelDecomposes in AddObjectRelationship() - {0}", ex.Message));
                        }
                    }
                    break;

                case Constants.WORKSHEET_JOB:
                    ifcRoot = Model.FederatedInstances.Where <IfcProcess>(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                    break;

                case Constants.WORKSHEET_ASSEMBLY:
                    ifcRoot = Model.FederatedInstances.Where <IfcRelDecomposes>(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                    break;

                case Constants.WORKSHEET_CONNECTION:
                    ifcRoot = Model.FederatedInstances.Where <IfcRelConnects>(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                    break;

                case Constants.WORKSHEET_FACILITY:
                    ifcRoot = Model.FederatedInstances.Where <IfcBuilding>(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                    if (ifcRoot == null)
                    {
                        ifcRoot = Model.FederatedInstances.Where <IfcSite>(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                    }
                    if (ifcRoot == null)
                    {
                        ifcRoot = Model.FederatedInstances.Where <IfcProject>(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                    }
                    break;

                case Constants.WORKSHEET_FLOOR:
                    ifcRoot = Model.FederatedInstances.Where <IfcBuildingStorey>(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                    break;

                case Constants.WORKSHEET_RESOURCE:
                    ifcRoot = Model.FederatedInstances.Where <IfcConstructionEquipmentResource>(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                    break;

                case Constants.WORKSHEET_SPACE:
                    ifcRoot = Model.FederatedInstances.Where <IfcSpace>(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                    break;

                case Constants.WORKSHEET_SPARE:
                    ifcRoot = Model.FederatedInstances.Where <IfcConstructionProductResource>(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                    break;

                case Constants.WORKSHEET_SYSTEM:
                    ifcRoot = Model.FederatedInstances.Where <IfcGroup>(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                    break;

                case Constants.WORKSHEET_ZONE:
                    ifcRoot = Model.FederatedInstances.Where <IfcZone>(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                    break;

                //case "document": //not derived from IfcRoot
                //    ifcRoot = Model.FederatedInstances.Where<IfcDocumentInformation>(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                //    break;
                //case "contact": //not derived from IfcRoot
                //    ifcRoot = Model.FederatedInstances.Where<IfcPersonAndOrganization>(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                //    break;
                //case "issue": //not derived from IfcRoot
                //    ifcRoot = Model.FederatedInstances.Where<IfcApproval>(to => to.Name.ToString().ToLower().Trim() == rowName).FirstOrDefault();
                //    break;
                default:
                    break;
                }
            }
            return(ifcRoot);
        }