Example #1
0
        /// <summary>
        /// Add the parent objects to the IfcRelDecomposes
        /// </summary>
        /// <param name="ifcRelDecomposes">Either a IfcRelAggregates or IfcRelNests object</param>
        /// <param name="parentName">IfcObjectDefinition.Name value to search for, NOT case sensitive</param>
        /// <returns></returns>
        private bool AddParentObject(IfcRelDecomposes ifcRelDecomposes, string parentName)
        {
            IfcObjectDefinition relatingObject = GetParentObject(parentName);

            if (relatingObject != null)
            {
                ifcRelDecomposes.RelatingObject = relatingObject;
                return(true);
            }
            return(false);
        }
Example #2
0
        private void SetDefaults(IfcRoot entity)
        {
            Name     = entity.CreateFriendlyName();
            EntityId = entity.EntityLabel;

            if (entity is IfcObjectDefinition)
            {
                IfcType = entity.GetType().Name;
            }
            else if (entity is IfcRelDecomposes)
            {
                IfcRelDecomposes rel = entity as IfcRelDecomposes;
                IfcType = rel.RelatingObject.GetType().Name;
            }
        }
 protected void AddRelatedObjects(IfcRelDecomposes rel, CompositionNode treeItem)
 {
     foreach (IfcObjectDefinition child in rel.RelatedObjects)
     {
         if (child.EntityLabel == treeItem.EntityId)
         {
             continue;
         }                                               //prevent any infinite looping
         CompositionNode childItem;
         if (!NodeMap.TryGetValue(child, out childItem)) //already written
         {
             childItem = new CompositionNode(child);
             NodeMap.Add(child, childItem);
         }
         treeItem.Children.Add(childItem);
     }
 }
Example #4
0
 /// <summary>
 /// Get Description
 /// </summary>
 /// <param name="ra">IfcRelDecomposes object</param>
 /// <returns>string holding description if found</returns>
 private string GetAssemblyDescription(IfcRelDecomposes ra)
 {
     if (ra != null)
     {
         if (!string.IsNullOrEmpty(ra.Description))
         {
             return(ra.Description);
         }
         else if (!string.IsNullOrEmpty(ra.Name))
         {
             return(ra.Name);
         }
         else if (!string.IsNullOrEmpty(ra.RelatingObject.Name))
         {
             return(ra.RelatingObject.Name);
         }
     }
     return(Constants.DEFAULT_STRING);
 }
Example #5
0
        private static String BuildName(IfcRoot ifcObject)
        {
            String name;

            if (ifcObject is IfcRelDecomposes)
            {
                IfcRelDecomposes rel = ifcObject as IfcRelDecomposes;
                name = BuildName(rel.RelatingObject);
            }
            else
            {
                name = ifcObject.Name;
            }

            if (String.IsNullOrEmpty(name))
            {
                name = ifcObject.ToString();
            }

            return(name);
        }
Example #6
0
        /// <summary>
        /// Add the child objects to the IfcRelDecomposes
        /// </summary>
        /// <param name="ifcRelDecomposes">Either a IfcRelAggregates or IfcRelNests object</param>
        /// <param name="sheetName">SheetName the children come from</param>
        /// <param name="childNames">list of child object names separated by " : ", NOT case sensitive</param>
        private bool AddChildObjects(IfcRelDecomposes ifcRelDecomposes, string sheetName, string childNames)
        {
            bool returnValue = false;
            IEnumerable <IfcObjectDefinition> childObjs = GetSheetObjectList(sheetName);
            //check that the name is not a single element, also gets over single entries with : in them
            string test = childNames.ToLower().Trim();
            IfcObjectDefinition RelatedObject = childObjs.Where(obj => obj.Name.ToString().ToLower().Trim() == test).FirstOrDefault();

            if (RelatedObject != null)
            {
                //check we have not already added as this can be a merge
                if (!ifcRelDecomposes.RelatedObjects.Contains(RelatedObject))
                {
                    ifcRelDecomposes.RelatedObjects.Add(RelatedObject);
                }
                returnValue = true;
            }
            else //ok nothing found for the full string so assume delimited string
            {
                char          splitChar       = GetSplitChar(childNames);
                List <string> splitChildNames = SplitString(childNames, splitChar);

                foreach (string item in splitChildNames)
                {
                    string name = item.ToLower().Trim();
                    RelatedObject = childObjs.Where(obj => obj.Name.ToString().ToLower().Trim() == name).FirstOrDefault();
                    if (RelatedObject != null)
                    {
                        //check we have not already added as this can be a merge
                        if (!ifcRelDecomposes.RelatedObjects.Contains(RelatedObject))
                        {
                            ifcRelDecomposes.RelatedObjects.Add(RelatedObject);
                        }
                        returnValue = true;
                    }
                }
            }
            return(returnValue);
        }
Example #7
0
        public override string WhereRule()
        {
            string baseErr = base.WhereRule();

            if (Decomposes.Count() != 1)
            {
                baseErr +=
                    "WR41 SpatialStructureElement: All spatial structure elements shall be associated with another spatial structure element, or with a Project\n";
            }
            IfcRelDecomposes rel = Decomposes.FirstOrDefault();

            if (!(rel is IfcRelAggregates))
            {
                baseErr +=
                    "WR41 SpatialStructureElement: All spatial structure elements shall be associated using the RelAggregates relationship.\n";
            }
            if (rel != null && !(rel.RelatingObject is IfcProject || rel.RelatingObject is IfcSpatialStructureElement))
            {
                baseErr +=
                    "WR41 SpatialStructureElement: All spatial structure elements shall be associated with another spatial structure element, or with a Project\n";
            }
            return(baseErr);
        }
Example #8
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);
        }
Example #9
0
        /// <summary>
        /// Add the data to the IfcRelDecomposes object
        /// </summary>
        /// <param name="row">COBieAssemblyRow holding the data</param>
        private void AddAssembly(COBieAssemblyRow row)
        {
            //check we have a chance of creating the IfcRelDecomposes object
            if ((ValidateString(row.ParentName)) && (ValidateString(row.ChildNames)))
            {
                IfcRelDecomposes ifcRelDecomposes = null;

                if ((LastIfcRelDecomposes != null) && IsContinuedAssemblyRow(row)) //this row line is a continuation of objects from the line above
                {
                    ifcRelDecomposes = LastIfcRelDecomposes;
                }
                else
                {
                    IfcObjectDefinition relatingObject = GetParentObject(row.ParentName);
                    //check on merge we have not already created using name and parent object as check
                    if (ValidateString(row.Name))
                    {
                        string testName = row.Name.ToLower().Trim();
                        ifcRelDecomposes = Model.FederatedInstances.Where <IfcRelDecomposes>(rc => (rc.Name.ToString().ToLower().Trim() == testName) && (rc.RelatingObject == relatingObject)).FirstOrDefault();
                    }

                    if ((ifcRelDecomposes == null) && (relatingObject != null))
                    {
                        if (row.ExtObject.ToLower().Trim() == "ifcrelnests")
                        {
                            ifcRelDecomposes = Model.Instances.New <IfcRelNests>();
                        }
                        else
                        {
                            ifcRelDecomposes = Model.Instances.New <IfcRelAggregates>();
                        }


                        //Add Created By, Created On and ExtSystem to Owner History.
                        SetUserHistory(ifcRelDecomposes, row.ExtSystem, row.CreatedBy, row.CreatedOn);
                    }
                    if (relatingObject == null)
                    {
                        Console.WriteLine(string.Format("Failed to find ifcRelDecomposes parent object in AddAssembly() for {0}", row.Name.ToString()));
                        return;
                    }
                }



                //using statement will set the Model.OwnerHistoryAddObject to IfcConstructionProductResource.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, ifcRelDecomposes.OwnerHistory))
                {
                    if (ValidateString(row.Name))
                    {
                        ifcRelDecomposes.Name = row.Name;
                    }
                    if (ValidateString(row.Description))
                    {
                        ifcRelDecomposes.Description = row.Description;
                    }

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

                    if (!(AddParentObject(ifcRelDecomposes, row.ParentName) &&
                          AddChildObjects(ifcRelDecomposes, row.SheetName, row.ChildNames)
                          )
                        )
                    {
                        //failed to add parent or child so remove as not a valid IfcRelDecomposes object
                        try
                        {
                            Model.Delete(ifcRelDecomposes);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(string.Format("Failed to delete ifcRelDecomposes in AddAssembly() - {0}", ex.Message));
                        }
                        ifcRelDecomposes = null;
                    }
                }
                //save for next row, might be a continuation line
                LastIfcRelDecomposes = ifcRelDecomposes;
            }
        }
Example #10
0
        // todo: bonghi: this one is too slow on Architettonico_def.xBIM, so I'm patching it for a specific hierarchy, but it needs serious redesign for efficiency
        private void Select(IPersistIfcEntity newVal, bool tryOptimise = true)
        {
            if (this.ViewDefinition == XbimViewType.SpatialStructure && tryOptimise)
            {
                /*
                 * We know that the structure in this case looks like:
                 *
                 * XbimModelViewModel
                 *  model.project.GetSpatialStructuralElements (into SpatialViewModel)
                 *  model.RefencedModels (into XbimRefModelViewModel)
                 *      model.project.GetSpatialStructuralElements (into SpatialViewModel)
                 *
                 * SpatialViewModel
                 *  SpatialViewModel
                 *  ContainedElementsViewModel
                 *      IfcProductModelView
                 *          IfcProductModelView
                 *
                 * If a model is a product then find its space with breadth first then expand to it with depth first.
                 * todo: bonghi: this is still not optimal, because it can only point to simple IPersistIfcEntity and not intermediate IXbimViewModels.
                 *
                 */
                IfcProduct p = newVal as IfcProduct;
                if (p != null)
                {
                    var found = FindUnderContainingSpace(newVal, p);  // direct search
                    if (found == null)
                    {
                        // search for composed object
                        IfcRelDecomposes decomp = p.Decomposes.FirstOrDefault();

                        if (decomp != null && decomp.RelatingObject is IfcProduct)                         //
                        {
                            found = FindUnderContainingSpace(newVal, (IfcProduct)(decomp.RelatingObject)); // direct search of parent through containing space
                            if (found != null)
                            {
                                found = FindItemDepthFirst(found, newVal); // then search for the child
                            }
                        }
                        else
                        {
                            // do basic search
                            this.Select(newVal, false);
                        }
                    }
                    if (found != null)
                    {
                        Highlight(found);
                        return;
                    }
                }
                // if optimised search fails revert to brute force expansion
                this.Select(newVal, false);
            }
            else
            {
                foreach (var item in HierarchySource.OfType <IXbimViewModel>())
                {
                    IXbimViewModel toSelect = FindItemDepthFirst(item, newVal);
                    if (toSelect != null)
                    {
                        Highlight(toSelect);
                        return;
                    }
                }
            }
        }