Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support dot 8.0 and Add propertySets metadata #22

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion xeokit/test/test.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
111 changes: 97 additions & 14 deletions xeokit/xeokit-metadata/MetaModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Xbim.Ifc;
using Xbim.Ifc4.Interfaces;
using Xbim.Ifc4x3.ProductExtension;

namespace XeokitMetadata {
/// <summary>
Expand Down Expand Up @@ -32,6 +35,7 @@ public struct MetaObject {
/// The GlobalId of the parent element if any.
/// </summary>
public string parent;
public List<dynamic> propertySets { get; set; }
}

/// <summary>
Expand Down Expand Up @@ -158,30 +162,107 @@ private static string getAuthor(IList<string> authors){
private static List<MetaObject> extractHierarchy(
IIfcObjectDefinition objectDefinition,
string parentId=null) {
var metaObjects = new List<MetaObject>();

var parentObject = new MetaObject {
id = objectDefinition.GlobalId,
name = objectDefinition.Name,
type = objectDefinition.GetType().Name,
parent = parentId
};

var metaObjects = new List<MetaObject>();
var spatialBuiltElement = objectDefinition as IfcBuiltElement;
if (spatialBuiltElement != null) {
var propertySets = spatialBuiltElement.IsDefinedBy
.Where(r => r.RelatingPropertyDefinition is IIfcPropertySet)
.Select(r => r.RelatingPropertyDefinition as IIfcPropertySet);
var propSetNames = new List<string>();
List<dynamic> retVal = new List<dynamic>();
foreach (var propSet in propertySets)
{
if (propSetNames.Contains(propSet.Name.ToString())) continue;
propSetNames.Add(propSet.Name.ToString());
dynamic pSetDynamic = new System.Dynamic.ExpandoObject();
pSetDynamic.name = propSet.Name.ToString();
pSetDynamic.properties = new List<dynamic>();
foreach (var property in propSet.HasProperties)
{
if (property is IIfcPropertySingleValue propSingleValue)
{
dynamic ppDynamic = new System.Dynamic.ExpandoObject();
{
ppDynamic.name = propSingleValue.Name.Value;
ppDynamic.value = propSingleValue.NominalValue == null
? string.Empty
: propSingleValue.NominalValue.Value.ToString();
}
pSetDynamic.properties.Add(ppDynamic);
}
}
retVal.Add(pSetDynamic);
var mo = new MetaObject {
id = spatialBuiltElement.GlobalId,
name = spatialBuiltElement.Name,
type = spatialBuiltElement.GetType().Name,
parent = parentId,
propertySets = retVal
};

metaObjects.Add(mo);
extractRelatedObjects(
spatialBuiltElement,
ref metaObjects,
mo.id);
}
extractRelatedObjects(
objectDefinition,
ref metaObjects,
spatialBuiltElement.GlobalId);

return metaObjects;
}
var parentObject = new MetaObject {
id = objectDefinition.GlobalId,
name = objectDefinition.Name,
type = objectDefinition.GetType().Name,
parent = parentId
};
metaObjects.Add(parentObject);

var spatialElement = objectDefinition as IIfcSpatialStructureElement;

if (spatialElement != null) {
var containedElements = spatialElement
.ContainsElements
.SelectMany(rel => rel.RelatedElements);

List<dynamic> elements = new List<dynamic>();
foreach (var element in containedElements) {
List<dynamic> retVal = new List<dynamic>();
var propSets = element.IsDefinedBy.Where(r => r.RelatingPropertyDefinition is IIfcPropertySet)
.Select(x => x.RelatingPropertyDefinition)
.Cast<IIfcPropertySet>();
var propSetNames = new List<string>();
foreach (var propSet in propSets)
{
if (propSetNames.Contains(propSet.Name.ToString())) continue;
propSetNames.Add(propSet.Name.ToString());
dynamic pSetDynamic = new System.Dynamic.ExpandoObject();
pSetDynamic.name = propSet.Name.ToString();
pSetDynamic.properties = new List<dynamic>();
foreach (var property in propSet.HasProperties)
{
if (property is IIfcPropertySingleValue propSingleValue)
{
dynamic ppDynamic = new System.Dynamic.ExpandoObject();
{
ppDynamic.name = propSingleValue.Name.Value;
ppDynamic.value = propSingleValue.NominalValue == null
? string.Empty
: propSingleValue.NominalValue.Value.ToString();
}
pSetDynamic.properties.Add(ppDynamic);
}
}
retVal.Add(pSetDynamic);
}

var mo = new MetaObject {
id = element.GlobalId,
name = element.Name,
type = element.GetType().Name,
parent = spatialElement.GlobalId
parent = spatialElement.GlobalId,
propertySets = retVal
};

metaObjects.Add(mo);
Expand All @@ -191,7 +272,6 @@ private static List<MetaObject> extractHierarchy(
mo.id);
}
}

extractRelatedObjects(
objectDefinition,
ref metaObjects,
Expand Down Expand Up @@ -255,8 +335,11 @@ public string serialize(){
Formatting = Formatting.Indented
};

var output = JsonConvert.SerializeObject(this, settings);
// var output = JsonConvert.SerializeObject(this, settings);
var output = JsonConvert.SerializeObject(this, Formatting.None);
return output;
;
}
}

}
4 changes: 2 additions & 2 deletions xeokit/xeokit-metadata/xeokit-metadata.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<PackageVersion>1.0.0</PackageVersion>
<Title>xeokit-metadata</Title>
Expand All @@ -19,7 +19,7 @@

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Xbim.Essentials" Version="5.1.341" />
<PackageReference Include="Xbim.Essentials" Version="6.0.445" />
</ItemGroup>

</Project>