Esempio n. 1
0
        public void AddNewProduct(string currentFilename, string siteGuid, string classificationCode, CcManufacturerProduct product, string system)
        {
            if (Current.Documents.ContainsKey(currentFilename))
            {
                Ifc4.CcFacility newSystem = Current.Documents[currentFilename].Project.Facilities.Where(x => x.IfcSystem.Name == product.Code &&
                                                                                                        x.IfcSystem.Description == system)
                                            .FirstOrDefault();
                if (newSystem == null)
                {
                    newSystem = Current.Documents[currentFilename].Project.Facilities.AddNewSystem(Current.Documents[currentFilename].Project);
                    newSystem.IfcSystem.GlobalId    = Ifc4.GlobalId.ConvertToIfcGuid(Guid.NewGuid());
                    newSystem.IfcSystem.Name        = product.Code;
                    newSystem.IfcSystem.Description = system;
                }
                CcFacility newFacility = newSystem.Facilities.AddNewFacility();
                newFacility.ObjectTypeId             = m_filteredIfcClassificationReference.Id; // z.B "i2139"
                newFacility.Number                   = product.Name;
                newFacility.IfcObjectDefinition.Name = product.Code;
                newFacility.Description              = product.Description;

                var propertyDescriptors = from propertyDescriptor in System.ComponentModel.TypeDescriptor.GetProperties(newFacility).Cast <System.ComponentModel.PropertyDescriptor>().OfType <Ifc4.CustomModel.CustomPropertyDescriptor>()
                                          select propertyDescriptor;

                foreach (CcManufacturerProductDetail attribute in product.Attributes)
                {
                    foreach (var propertyDescriptor in propertyDescriptors)
                    {
                        if (propertyDescriptor.IsReadOnly)
                        {
                            continue;
                        }

                        if (propertyDescriptor.Converter == null)
                        {
                            continue;
                        }

                        if (propertyDescriptor.IfcPropertyName == attribute.AttributeCcName)
                        {
                            newFacility.SetValue(propertyDescriptor, attribute.AttributeValue);
                            continue;
                        }
                    }
                }
            }
        }
Esempio n. 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;
            }
        }