Exemple #1
0
        //void IBindingList.AddIndex(PropertyDescriptor property)
        //{
        //    throw new NotImplementedException();
        //}

        public virtual object AddNew()
        {
            // darf auch keine base Funktionalität geben!!!
            //throw new NotImplementedException();

            T instance = Activator.CreateInstance <T>() as T;

            ((Ifc4.Interfaces.IBaseObjects <T>) this).Add(instance);
            instance.Parent = this;
            Ifc4.Document document = this.GetParent <Ifc4.Document>();
            if (document != null)
            {
                Entity entity = instance as Entity;
                if (entity != null)
                {
                    entity.Id = document.GetNextSid();
                    document.IfcXmlDocument.Items.Add(entity);
                }
                IfcRoot ifcRoot = instance as IfcRoot;
                if (ifcRoot != null)
                {
                    ifcRoot.GlobalId = document.GetNewGlobalId();
                }

                return(instance);
            }
            return(null);
        }
Exemple #2
0
        public T AddNewFacility(CcFacility cloneFacility = null, bool oneToOneCopy = false)
        {
            EventType enabledEventTypes = BaseObject.EventsEnabled;

            BaseObject.EventsEnabled = EventType.None;
            try
            {
                T facility = (T)AddNew();
                // ------------------------------------------------------------------------------
                // Annahme Anlage = IfcBuildingElementProxy
                IfcBuildingElementProxy ifcBuildingElementProxy = new IfcBuildingElementProxy();

                facility.IfcObjectDefinition   = ifcBuildingElementProxy;
                ifcBuildingElementProxy.Parent = this;

                Ifc4.Document document = this.GetParent <Ifc4.Document>();
                if (document != null)
                {
                    Entity entity = ifcBuildingElementProxy as Entity;
                    if (entity != null)
                    {
                        entity.Id = document.GetNextSid();
                        document.IfcXmlDocument.Items.Add(entity);
                    }
                    IfcRoot ifcRoot = ifcBuildingElementProxy as IfcRoot;
                    if (ifcRoot != null)
                    {
                        ifcRoot.GlobalId = document.GetNewGlobalId();
                    }
                }
                // ------------------------------------------------------------------------------
                if (this.Parent.GetType() == typeof(Ifc4.IfcProject))
                {
                    IEnumerable <IfcRelAggregates> ifcRelAggregatesCollection = this.Document.IfcXmlDocument.Items.OfType <IfcRelAggregates>()
                                                                                .Where(item => item.RelatingObject != null && item.RelatingObject.Ref == ((Ifc4.IfcProject) this.Parent).Id).ToList();
                    if (ifcRelAggregatesCollection.Any())
                    {
                        foreach (IfcRelAggregates ifcRelAggregates in ifcRelAggregatesCollection)
                        {
                            var relatedObject = ifcRelAggregates.RelatedObjects.Items.FirstOrDefault(item => item.Ref == ifcBuildingElementProxy.Id);
                            if (relatedObject == null)
                            {
                                ifcRelAggregates.RelatedObjects.Items.Add(ifcBuildingElementProxy.RefInstance());
                            }
                        }
                    }
                    else
                    {
                        IfcRelAggregates relAggregatesProject = new IfcRelAggregates()
                        {
                            GlobalId = Document.GetNewGlobalId(),
                            // kann aktuell nur IfcProject sein
                            RelatingObject = new Ifc4.IfcProject()
                            {
                                Ref = ((Ifc4.IfcProject) this.Parent).Id
                            }
                        };
                        relAggregatesProject.RelatedObjects = new IfcRelAggregatesRelatedObjects();
                        relAggregatesProject.RelatedObjects.Items.Add(ifcBuildingElementProxy.RefInstance());
                        this.Document.IfcXmlDocument.Items.Add(relAggregatesProject);
                    }
                }
                // ------------------------------------------------------------------------------
                if (this.Parent.GetType() == typeof(Ifc4.CcFacility))
                {
                    if (((Ifc4.CcFacility) this.Parent).IfcObjectDefinition != null)
                    {
                        Ifc4.IfcRelAggregates ifcRelAggregates = ((Ifc4.CcFacility) this.Parent).GetIfcRelAggregates();
                        ifcRelAggregates.RelatedObjects.Items.Add(ifcBuildingElementProxy.RefInstance());
                    }
                    else if (((Ifc4.CcFacility) this.Parent).IfcSystem != null)
                    {
                        Ifc4.IfcRelAssignsToGroup ifcRelAssignsToGroup = ((Ifc4.CcFacility) this.Parent).GetIfcRelAssignsToGroup();
                        ifcRelAssignsToGroup.RelatedObjects.Items.Add(ifcBuildingElementProxy.RefInstance());
                    }
                }
                // ------------------------------------------------------------------------------
                // assign facility properties from clipboard facility
                facility.AssignPropertiesFromFacility(cloneFacility, oneToOneCopy);
                // ------------------------------------------------------------------------------

                return(facility);
            }
            catch (Exception exc)
            {
                return(default(T));
            }
            finally
            {
                BaseObject.EventsEnabled = enabledEventTypes;
            }
        }