Skip to content

Commit

Permalink
Merge pull request #79 from buildingsmart-community/fix-use-of-IfcPro…
Browse files Browse the repository at this point in the history
…pertyEnumeratedValue

Fix use of ifc property enumerated value
  • Loading branch information
Rien777 authored May 14, 2024
2 parents dbfd9ed + b8b9cd0 commit 750ff04
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 115 deletions.
67 changes: 61 additions & 6 deletions BsddRevitPlugin.Logic/IfcJson/IfcJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,31 +138,70 @@ public class IfcPropertySet
public string Name { get; set; }

[JsonProperty("hasProperties")]
public List<IfcPropertySingleValue> HasProperties { get; set; }
public List<IfcProperty> HasProperties { get; set; }
}

/// <summary>
/// Represents an IFC property with a single value.
/// IfcProperty is an abstract generalization for all types of properties that can be associated with IFC objects through the property set mechanism.
/// </summary>
public class IfcPropertySingleValue
public class IfcProperty
{
[JsonProperty("type")]
public string Type { get; set; }
public virtual string Type { get; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("specification")]
public string Specification { get; set; }

public IfcProperty()
{
Type = "IfcProperty";
}
}

/// <summary>
/// The property with a single value IfcPropertySingleValue defines a property object which has a single (numeric or descriptive) value assigned.
/// </summary>
public class IfcPropertySingleValue : IfcProperty
{
[JsonProperty("type")]
public override string Type { get; }

[JsonProperty("nominalValue")]
public NominalValue NominalValue { get; set; }
public IfcValue NominalValue { get; set; }

public IfcPropertySingleValue() : base()
{
Type = "IfcPropertySingleValue";
}
}

/// <summary>
/// A property with an enumerated value, IfcPropertyEnumeratedValue, defines a property object which has a value assigned that is chosen from an enumeration.
/// </summary>
public class IfcPropertyEnumeratedValue : IfcProperty
{
[JsonProperty("type")]
public override string Type { get; }

[JsonProperty("enumerationValues")]
public List<IfcValue> EnumerationValues { get; set; }

[JsonProperty("enumerationReference")]
public IfcPropertyEnumeration EnumerationReference { get; set; }

public IfcPropertyEnumeratedValue() : base()
{
Type = "IfcPropertyEnumeratedValue";
}
}

/// <summary>
/// Represents the nominal value of an IFC property.
/// </summary>
public class NominalValue
public class IfcValue
{
[JsonProperty("type")]
public string Type { get; set; }
Expand All @@ -171,5 +210,21 @@ public class NominalValue
public object Value { get; set; }
}

public class IfcPropertyEnumeration
{
[JsonProperty("type")]
public string Type { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("enumerationValues")]
public HashSet<IfcValue> EnumerationValues { get; set; }

public IfcPropertyEnumeration()
{
Type = "IfcPropertyEnumeration";
}
}

}
22 changes: 17 additions & 5 deletions BsddRevitPlugin.Logic/IfcJson/IfcJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,30 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
}
}
}

if (jsonObject["isDefinedBy"] != null)
{
ifcData.IsDefinedBy = new List<IfcPropertySet>();
foreach (JObject item in jsonObject["isDefinedBy"])
{
switch (item["type"].ToString())
IfcPropertySet propertySet = item.ToObject<IfcPropertySet>();
if (item["hasProperties"] != null)
{
case "IfcPropertySet":
ifcData.IsDefinedBy.Add(item.ToObject<IfcPropertySet>());
break;
propertySet.HasProperties = new List<IfcProperty>();
foreach (JObject propertyItem in item["hasProperties"])
{
switch (propertyItem["type"].ToString())
{
case "IfcPropertySingleValue":
propertySet.HasProperties.Add(propertyItem.ToObject<IfcPropertySingleValue>());
break;
case "IfcPropertyEnumeratedValue":
propertySet.HasProperties.Add(propertyItem.ToObject<IfcPropertyEnumeratedValue>());
break;
}
}
}
ifcData.IsDefinedBy.Add(propertySet);
}
}

Expand Down
Loading

0 comments on commit 750ff04

Please sign in to comment.