예제 #1
0
 public JsonIfcContextElement(IfcContext ifcElement) : base(ifcElement)
 {
     if (ifcElement.ObjectType != null)
     {
         userData.objectType = ifcElement.ObjectType;
     }
     if (ifcElement.Name != null)
     {
         userData.name = ifcElement.Name;
     }
     if (ifcElement.StepClassName != null)
     {
         userData.type = ifcElement.StepClassName;
     }
 }
예제 #2
0
        public override void Parse(int propIndex, IPropertyValue value, int[] nestedIndex)
        {
            switch (propIndex)
            {
            case 0:
            case 1:
            case 2:
            case 3:
                base.Parse(propIndex, value, nestedIndex);
                return;

            case 4:
                _relatingContext = (IfcContext)(value.EntityVal);
                return;

            case 5:
                _relatedDefinitions.InternalAdd((IfcDefinitionSelect)value.EntityVal);
                return;

            default:
                throw new XbimParserException(string.Format("Attribute index {0} is out of range for {1}", propIndex + 1, GetType().Name.ToUpper()));
            }
        }
예제 #3
0
 public XmlElementIfc(XmlHeader header, IfcContext context)
     : this(header)
 {
     base.Add(context);
 }
예제 #4
0
        /// <summary>
        /// Load user-defined Property set
        /// Format:
        ///    PropertSet: <Pset_name> I[nstance]/T[ype] <IFC entity list separated by ','>
        ///              Property_name   Data_type   Revit_Parameter
        ///              ...
        /// Datatype supported: Text, Integer, Real, Boolean
        /// Line divider between Property Mapping and User defined property sets:
        ///     #! UserDefinedPset
        /// </summary>
        /// <returns>List of property set definitions</returns>
        public static IEnumerable <IfcPropertySetTemplate> LoadUserDefinedPset()
        {
            List <IfcPropertySetTemplate> userDefinedPsets = new List <IfcPropertySetTemplate>();

            try
            {
                string filename = ExporterCacheManager.ExportOptionsCache.PropertySetOptions.ExportUserDefinedPsetsFileName;
                if (!File.Exists(filename))
                {
                    // This allows for the original behavior of looking in the directory of the export DLL to look for the default file name.
                    filename = GetUserDefPsetFilename();
                }
                if (!File.Exists(filename))
                {
                    return(userDefinedPsets);
                }

                string extension = Path.GetExtension(filename);
                if (string.Compare(extension, ".ifcxml", true) == 0 || string.Compare(extension, ".ifcjson", true) == 0 || string.Compare(extension, ".ifc", true) == 0)
                {
                    DatabaseIfc db      = new DatabaseIfc(filename);
                    IfcContext  context = db.Context;
                    if (context == null)
                    {
                        return(userDefinedPsets);
                    }
                    foreach (IfcRelDeclares relDeclares in context.Declares)
                    {
                        userDefinedPsets.AddRange(relDeclares.RelatedDefinitions.OfType <IfcPropertySetTemplate>());
                    }
                }
                else
                {
                    using (StreamReader sr = new StreamReader(filename))
                    {
                        string line;

                        DatabaseIfc            db = new DatabaseIfc(false, ReleaseVersion.IFC4);
                        IfcPropertySetTemplate userDefinedPset = null;
                        while ((line = sr.ReadLine()) != null)
                        {
                            line.TrimStart(' ', '\t');

                            if (String.IsNullOrEmpty(line))
                            {
                                continue;
                            }
                            if (line[0] != '#')
                            {
                                // Format: PropertSet: <Pset_name> I[nstance]/T[ype] <IFC entity list separated by ','>
                                //              Property_name   Data_type   Revit_Parameter
                                // ** For now it only works for simple property with single value (datatype supported: Text, Integer, Real and Boolean)

                                string[] split = line.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
                                if (string.Compare(split[0], "PropertySet:", true) == 0)
                                {
                                    userDefinedPset = new IfcPropertySetTemplate(db, split.Length > 2 ? split[1] : "Unknown");
                                    if (split.Count() >= 4) // Any entry with less than 3 par is malformed
                                    {
                                        switch (split[2][0])
                                        {
                                        case 'T':
                                            userDefinedPset.TemplateType = IfcPropertySetTemplateTypeEnum.PSET_TYPEDRIVENONLY;
                                            break;

                                        case 'I':
                                            userDefinedPset.TemplateType = IfcPropertySetTemplateTypeEnum.PSET_OCCURRENCEDRIVEN;
                                            break;

                                        default:
                                            userDefinedPset.TemplateType = IfcPropertySetTemplateTypeEnum.PSET_OCCURRENCEDRIVEN;
                                            break;
                                        }
                                        userDefinedPset.ApplicableEntity = string.Join(",", split[3].Split(new char[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries));
                                        userDefinedPsets.Add(userDefinedPset);
                                    }
                                }
                                else
                                {
                                    if (split.Count() >= 2)
                                    {
                                        string propertyTemplateName = split[0];
                                        IfcSimplePropertyTemplate propertyDefUnit = userDefinedPset[propertyTemplateName] as IfcSimplePropertyTemplate;
                                        if (propertyDefUnit == null)
                                        {
                                            userDefinedPset.AddPropertyTemplate(propertyDefUnit = new IfcSimplePropertyTemplate(db, split[0]));
                                        }
                                        if (split.Count() >= 3 && !string.IsNullOrEmpty(split[2]))
                                        {
                                            new IfcRelAssociatesClassification(new IfcClassificationReference(db)
                                            {
                                                Identification = split[2]
                                            }, propertyDefUnit);
                                        }
                                        if (!string.IsNullOrEmpty(split[1]))
                                        {
                                            propertyDefUnit.PrimaryMeasureType = "Ifc" + split[1];
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }

            return(userDefinedPsets);
        }