Skip to content
This repository has been archived by the owner on Jul 31, 2022. It is now read-only.

Commit

Permalink
Support property sets in XKT and metadata #31
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Aug 19, 2021
1 parent 85776bd commit 0ecc9f8
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 19 deletions.
19 changes: 5 additions & 14 deletions src/XKTModel/XKTMetaObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ class XKTMetaObject {
* @param propertySetId
* @param metaObjectType
* @param metaObjectName
* @param metaObjectIndex
* @param parentMetaObjectId
*/
constructor(metaObjectId, propertySetId, metaObjectType, metaObjectName, metaObjectIndex, parentMetaObjectId) {
constructor(metaObjectId, propertySetId, metaObjectType, metaObjectName, parentMetaObjectId) {

/**
* Unique ID of this ````XKTMetaObject```` in {@link XKTModel#metaObjects}.
Expand All @@ -43,14 +42,13 @@ class XKTMetaObject {
this.metaObjectId = metaObjectId;

/**
* Unique ID of an external property set for this ````XKTMetaObject````.
*
* We only store basic structural metadata in the XKT, and store object property sets externally,
* because they tend to be large and application-specific and would bloat the XKT file.
* Unique ID of a property set that contains additional metadata about this
* {@link XKTMetaObject}. The property can be stored in an external system, or
* within the {@link XKTModel}, as a {@link XKTPropertySet} within {@link XKTModel#propertySets}.
*
* @type {String}
*/
this.propertySetId = null;
this.propertySetId = propertySetId;

/**
* Indicates the XKTMetaObject meta object type.
Expand All @@ -70,13 +68,6 @@ class XKTMetaObject {
*/
this.metaObjectName = metaObjectName;

/**
* Index of this ````XKTMetaObject```` in {@link XKTModel#metaObjectsList}.
*
* @type {Number}
*/
this.metaObjectIndex = metaObjectIndex;

/**
* The parent XKTMetaObject, if any.
*
Expand Down
79 changes: 74 additions & 5 deletions src/XKTModel/XKTModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {XKTEntity} from './XKTEntity.js';
import {XKTTile} from './XKTTile.js';
import {KDNode} from "./KDNode.js";
import {XKTMetaObject} from "./XKTMetaObject.js";
import {XKTPropertySet} from "./XKTPropertySet.js";
import {mergeVertices} from "../lib/mergeVertices.js";

const tempVec4a = math.vec4([0, 0, 0, 1]);
Expand Down Expand Up @@ -122,6 +123,26 @@ class XKTModel {
*/
this.edgeThreshold = cfg.edgeThreshold || 10;

/**
* Map of {@link XKTPropertySet}s within this XKTModel, each mapped to {@link XKTPropertySet#propertySetId}.
*
* Created by {@link XKTModel#createPropertySet}.
*
* @type {{String:XKTPropertySet}}
*/
this.propertySets = {};

/**
* {@link XKTPropertySet}s within this XKTModel.
*
* Each XKTPropertySet holds its position in this list in {@link XKTPropertySet#propertySetIndex}.
*
* Created by {@link XKTModel#finalize}.
*
* @type {XKTPropertySet[]}
*/
this.propertySetsList = [];

/**
* Map of {@link XKTMetaObject}s within this XKTModel, each mapped to {@link XKTMetaObject#metaObjectId}.
*
Expand Down Expand Up @@ -241,16 +262,65 @@ class XKTModel {
this.finalized = false;
}

/**
* Creates an {@link XKTPropertySet} within this XKTModel.
*
* Logs error and does nothing if this XKTModel has been finalized (see {@link XKTModel#finalized}).
*
* @param {*} params Method parameters.
* @param {String} params.propertySetId Unique ID for the {@link XKTPropertySet}.
* @param {String} [params.propertySetType="default"] A meta type for the {@link XKTPropertySet}.
* @param {String} [params.propertySetName] Human-readable name for the {@link XKTPropertySet}. Defaults to the ````propertySetId```` parameter.
* @param {String[]} params.properties Properties for the {@link XKTPropertySet}.
* @returns {XKTPropertySet} The new {@link XKTPropertySet}.
*/
createPropertySet(params) {

if (!params) {
throw "Parameters expected: params";
}

if (params.propertySetId === null || params.propertySetId === undefined) {
throw "Parameter expected: params.propertySetId";
}

if (params.properties === null || params.properties === undefined) {
throw "Parameter expected: params.properties";
}

if (this.finalized) {
console.error("XKTModel has been finalized, can't add more property sets");
return;
}

if (this.propertySets[params.propertySetId]) {
// console.error("XKTPropertySet already exists with this ID: " + params.propertySetId);
return;
}

const propertySetId = params.propertySetId;
const propertySetType = params.propertySetType || "Default";
const propertySetName = params.propertySetName || params.propertySetId;
const properties = params.properties || [];

const propertySet = new XKTPropertySet(propertySetId, propertySetType, propertySetName, properties);

this.propertySets[propertySetId] = propertySet;
this.propertySetsList.push(propertySet);

return propertySet;
}

/**
* Creates an {@link XKTMetaObject} within this XKTModel.
*
* Logs error and does nothing if this XKTModel has been finalized (see {@link XKTModel#finalized}).
*
* @param {*} params Method parameters.
* @param {String} params.metaObjectId Unique ID for the {@link XKTMetaObject}.
* @param {String} params.propertySetId ID of externally-stored property set data. We only store basic structural
* metadata in the XKT, and store object property sets externally, because they tend to be large and
* application-specific and would bloat the XKT file.
* @param {String} params.propertySetId ID of a property set that contains additional metadata about
* this {@link XKTMetaObject}. The property set could be stored externally (ie not managed at all by the XKT file),
* or could be a {@link XKTPropertySet} within {@link XKTModel#propertySets}.
* @param {String} [params.metaObjectType="default"] A meta type for the {@link XKTMetaObject}. Can be anything,
* but is usually an IFC type, such as "IfcSite" or "IfcWall".
* @param {String} [params.metaObjectName] Human-readable name for the {@link XKTMetaObject}. Defaults to the ````metaObjectId```` parameter.
Expand Down Expand Up @@ -281,10 +351,9 @@ class XKTModel {
const propertySetId = params.propertySetId;
const metaObjectType = params.metaObjectType || "Default";
const metaObjectName = params.metaObjectName || params.metaObjectId;
const metaObjectIndex = this.metaObjectsList.length;
const parentMetaObjectId = params.parentMetaObjectId;

const metaObject = new XKTMetaObject(metaObjectId, propertySetId, metaObjectType, metaObjectName, metaObjectIndex, parentMetaObjectId);
const metaObject = new XKTMetaObject(metaObjectId, propertySetId, metaObjectType, metaObjectName, parentMetaObjectId);

this.metaObjects[metaObjectId] = metaObject;
this.metaObjectsList.push(metaObject);
Expand Down
53 changes: 53 additions & 0 deletions src/XKTModel/XKTPropertySet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* A property set within an {@link XKTModel}.
*
* These are shared among {@link XKTMetaObject}s.
*
* * Created by {@link XKTModel#createPropertySet}
* * Stored in {@link XKTModel#propertySets} and {@link XKTModel#propertySetsList}
* * Has an ID, a type, and a human-readable name
*
* @class XKTPropertySet
*/
class XKTPropertySet {

/**
* @private
*/
constructor(propertySetId, propertySetType, propertySetName, properties) {

/**
* Unique ID of this ````XKTPropertySet```` in {@link XKTModel#propertySets}.
*
* @type {String}
*/
this.propertySetId = propertySetId;

/**
* Indicates the ````XKTPropertySet````'s type.
*
* This defaults to "default".
*
* @type {string}
*/
this.propertySetType = propertySetType;

/**
* Indicates the XKTPropertySet meta object name.
*
* This defaults to {@link XKTPropertySet#propertySetId}.
*
* @type {string}
*/
this.propertySetName = propertySetName;

/**
* The properties within this ````XKTPropertySet````.
*
* @type {*[]}
*/
this.properties = properties;
}
}

export {XKTPropertySet};
21 changes: 21 additions & 0 deletions src/XKTModel/writeXKTModelToArrayBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ function getModelData(xktModel) {
// Allocate data
//------------------------------------------------------------------------------------------------------------------

const propertySetsList = xktModel.propertySetsList;
const metaObjectsList = xktModel.metaObjectsList;
const geometriesList = xktModel.geometriesList;
const meshesList = xktModel.meshesList;
const entitiesList = xktModel.entitiesList;
const tilesList = xktModel.tilesList;

const numPropertySets = propertySetsList.length;
const numMetaObjects = metaObjectsList.length;
const numGeometries = geometriesList.length;
const numMeshes = meshesList.length;
Expand Down Expand Up @@ -147,9 +149,24 @@ function getModelData(xktModel) {
creatingApplication: xktModel.creatingApplication,
schema: xktModel.schema,

propertySets: [],
metaObjects: []
};

for (let propertySetsIndex = 0; propertySetsIndex < numPropertySets; propertySetsIndex++) {

const propertySet = propertySetsList[propertySetsIndex];

const propertySetJSON = {
id: "" + propertySet.propertySetId,
name: propertySet.propertySetName,
type: propertySet.propertySetType,
properties: propertySet.properties
};

data.metadata.propertySets.push(propertySetJSON);
}

for (let metaObjectsIndex = 0; metaObjectsIndex < numMetaObjects; metaObjectsIndex++) {

const metaObject = metaObjectsList[metaObjectsIndex];
Expand All @@ -164,6 +181,10 @@ function getModelData(xktModel) {
metaObjectJSON.parent = "" + metaObject.parentMetaObjectId;
}

if (metaObject.propertySetId !== undefined && metaObject.propertySetId !== null && metaObject.propertySetId !== "") {
metaObjectJSON.propertySetId = "" + metaObject.propertySetId;
}

data.metadata.metaObjects.push(metaObjectJSON);
}

Expand Down

0 comments on commit 0ecc9f8

Please sign in to comment.