@shapediver/sdk.sdtf-v1
Version:
Official sdTF SDK for TypeScript
44 lines • 2.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SdtfGrasshopperSdtfBuilder = void 0;
const sdk_sdtf_core_1 = require("@shapediver/sdk.sdtf-core");
class SdtfGrasshopperSdtfBuilder {
constructor(factory) {
this.factory = factory;
this.asset = factory.createAsset();
}
addChunkForListData(parameterId, list, chunkAttributes) {
this.addChunkForTreeData(parameterId, { branches: [list], paths: [[0]] }, chunkAttributes);
}
addChunkForTreeData(parameterId, tree, chunkAttributes) {
const chunk = this.factory.createChunk(parameterId);
this.asset.chunks.push(chunk);
if (chunkAttributes)
chunk.attributes = chunkAttributes;
if (tree.branches.length !== tree.paths.length)
throw new sdk_sdtf_core_1.SdtfError("Invalid tree parameter: 'branches' and 'paths' of the grasshopper structure must have the same number of elements.");
if (!tree.paths.every((path) => (0, sdk_sdtf_core_1.isIntArray)(path)))
throw new sdk_sdtf_core_1.SdtfError("Invalid tree parameter: 'paths' of the grasshopper structure must only consist of integer values.");
if (!tree.branches.every((branch) => branch.every((item) => { var _a; return !!((_a = item.typeHint) === null || _a === void 0 ? void 0 : _a.name); })))
throw new sdk_sdtf_core_1.SdtfError("Invalid tree parameter: All data items in 'tree.branches' must contain a type hint.");
let typeHint;
for (let i = 0; i < tree.branches.length; i++) {
const branch = tree.branches[i], path = tree.paths[i];
const node = this.factory.createNode();
node.name = '[' + path.join(',') + ']';
branch.forEach((item) => {
if (!typeHint)
typeHint = item.typeHint.name;
if (typeHint !== item.typeHint.name)
throw new sdk_sdtf_core_1.SdtfError("Invalid tree parameter: All data items in 'tree.branches' must have the same type hint.");
node.items.push(item);
});
chunk.nodes.push(node);
}
}
build() {
return this.asset;
}
}
exports.SdtfGrasshopperSdtfBuilder = SdtfGrasshopperSdtfBuilder;
//# sourceMappingURL=SdtfGrasshopperSdtfBuilder.js.map