UNPKG

gs-json

Version:

gs-JSON is a domain agnostic unifying 3D file format for geometric and semantic modelling (hence the 'gs').

495 lines (445 loc) 15.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Group = undefined; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _enums = require("./enums"); var _topo_sub = require("./topo_sub"); var _entity_point = require("./entity_point"); var _entity_obj_cast = require("./entity_obj_cast"); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Group class. */ var Group = exports.Group = function () { /** * Creates an instance of the Group class. * The group data must already exists in the model. * Do not use this constructor if you want to add a new group to the model. * Instead, you should use the "addGroup()" methdod in the model class. * @param model The Model object in which this attribute will be created. * @param data The attribute data in the model. * @return The Group object. */ function Group(kernel, name) { _classCallCheck(this, Group); this._kernel = kernel; this._name = name; } /** * Check if this group exists * @return The model */ _createClass(Group, [{ key: "exists", value: function exists() { return this._kernel.modelGetGroup(this._name) === undefined; } /** * Get the model to which this group belongs. * @return The model */ }, { key: "getModel", value: function getModel() { return this._kernel.getModel(); } /** * Get the Geom object * @return The Model object */ }, { key: "getGeom", value: function getGeom() { return this._kernel.getGeom(); } // This group --------------------------------------------------------------------------------- /** * Get the group name, which is its main identifier. Kust be unque. * @param * @return */ }, { key: "getName", value: function getName() { return this._name; } /** * Rename the group. * @param * @return */ }, { key: "setName", value: function setName(name) { var old_name = this._name; this._kernel.groupSetName(old_name, name); this._name = name; return old_name; } /** * Ge the parent group of this group. Each group can only have one parent. * @param * @return */ }, { key: "getParentGroup", value: function getParentGroup() { var name = this._kernel.groupGetParent(this._name); return new Group(this._kernel, name); } /** * Set teh parent groupof this group. * @param * @return */ }, { key: "setParentGroup", value: function setParentGroup(group) { var name = this._kernel.groupSetParent(this._name, group.getName()); return new Group(this._kernel, name); } /** * Remove the parent group of this group. This will result in this group having no parent. * A group with no parent is a top level group * @param * @return */ }, { key: "removeParentGroup", value: function removeParentGroup() { var name = this._kernel.groupSetParent(this._name, null); return new Group(this._kernel, name); } /** * Get the children groups of this group. * Each group can have multiple chilren groups. * @param * @return */ }, { key: "getChildGroups", value: function getChildGroups() { var _this = this; return this._kernel.groupGetChildren(this._name).map(function (v) { return new Group(_this._kernel, v); }); } // Objs --------------------------------------------------------------------------------------- /** * Get the number of objs in this group. * @param * @return */ }, { key: "getNumObjs", value: function getNumObjs(obj_type) { return this._kernel.groupGetNumObjs(this._name, obj_type); } /** * Get the object in this group. * @param * @return */ }, { key: "getObjs", value: function getObjs(obj_type) { var _this2 = this; return this._kernel.groupGetObjIDs(this._name, obj_type).map(function (id) { return (0, _entity_obj_cast._castToObjType)(_this2._kernel, id); }); } /** * Add an object to this group. * @param * @return */ }, { key: "addObj", value: function addObj(obj) { return this._kernel.groupAddObj(this._name, obj.getID()); } /** * Add multiple object to this group. * * @param * @return Returns true if all obj IDs were added, false otherwise. */ }, { key: "addObjs", value: function addObjs(objs) { return this._kernel.groupAddObjs(this._name, objs.map(function (v) { return v.getID(); })); } /** * Remove an object from this group. * @param * @return */ }, { key: "removeObj", value: function removeObj(obj) { return this._kernel.groupRemoveObj(this._name, obj.getID()); } /** * Remove multiple objects from this group. * @param * @return */ }, { key: "removeObjs", value: function removeObjs(objs) { return this._kernel.groupRemoveObjs(this._name, objs.map(function (v) { return v.getID(); })); } /** * Check if an object is in this group. * @param * @return */ }, { key: "hasObj", value: function hasObj(obj) { return this._kernel.groupHasObj(this._name, obj.getID()); } // Topos -------------------------------------------------------------------------------------- /** * Get the number of topos in this group. * @param * @return */ }, { key: "getNumTopos", value: function getNumTopos(geom_type) { return this._kernel.groupGetNumTopos(this._name, geom_type); } /** * Get the topos in this group. (Vertices, edges, wires, faces.) * @param * @return */ }, { key: "getTopos", value: function getTopos(geom_type) { var paths = this._kernel.groupGetTopos(this._name, geom_type); var topos = []; var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = paths[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var path = _step.value; var path_tt = _enums.mapTTPathIndexToGeomType.get(path.tt); var path_st = _enums.mapSTPathIndexToGeomType.get(path.st); switch (path_st) { case _enums.EGeomType.vertices: topos.push(new _topo_sub.Vertex(this._kernel, path)); break; case _enums.EGeomType.edges: topos.push(new _topo_sub.Edge(this._kernel, path)); break; default: switch (path_tt) { case _enums.EGeomType.wires: topos.push(new _topo_sub.Wire(this._kernel, path)); break; case _enums.EGeomType.faces: topos.push(new _topo_sub.Face(this._kernel, path)); break; } break; } } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } return topos; } /** * Add a topo to this group. (Vertices, edges, wires, faces.) * @param * @return */ }, { key: "addTopo", value: function addTopo(topo) { var path = topo.getTopoPath(); // TODO return this._kernel.groupAddTopo(this._name, path); } /** * Add multiple topos to this group. (Vertices, edges, wires, faces.) * @param * @return */ }, { key: "addTopos", value: function addTopos(topos) { var paths = topos.map(function (p) { return p.getTopoPath(); }); // TODO return this._kernel.groupAddTopos(this._name, paths); } /** * Remove a topo from this group. (Vertices, edges, wires, faces.) * @param * @return */ }, { key: "removeTopo", value: function removeTopo(topo) { var path = topo.getTopoPath(); // TODO return this._kernel.groupRemoveTopo(this._name, path); } /** * Remove multiple topos from this group. (Vertices, edges, wires, faces.) * @param * @return */ }, { key: "removeTopos", value: function removeTopos(topos) { var paths = topos.map(function (p) { return p.getTopoPath(); }); // TODO return this._kernel.groupRemoveTopos(this._name, paths); } /** * Check if a topo is in this group. (Vertices, edges, wires, faces.) * @param * @return */ }, { key: "hasTopo", value: function hasTopo(topo) { var path = topo.getTopoPath(); // TODO return this._kernel.groupHasTopo(this._name, path); } // Points in this group ----------------------------------------------------------------------- /** * Get the number of points in this group. * @param * @return */ }, { key: "getNumPoints", value: function getNumPoints() { return this._kernel.groupGetNumPoints(this._name); } /** * Get the points in this group. * @param * @return */ }, { key: "getPoints", value: function getPoints() { var _this3 = this; return this._kernel.groupGetPointIDs(this._name).map(function (v) { return new _entity_point.Point(_this3._kernel, v); }); } /** * Add a point to this group. * @param * @return */ }, { key: "addPoint", value: function addPoint(point) { return this._kernel.groupAddPoint(this._name, point.getID()); } /** * Add multiple points to this group. * @param * @return */ }, { key: "addPoints", value: function addPoints(points) { return this._kernel.groupAddPoints(this._name, points.map(function (v) { return v.getID(); })); } /** * Remove a point from this group. * @param * @return */ }, { key: "removePoint", value: function removePoint(point) { return this._kernel.groupRemovePoint(this._name, point.getID()); } /** * Remove multiple points from this group. * @param * @return */ }, { key: "removePoints", value: function removePoints(points) { return this._kernel.groupRemovePoints(this._name, points.map(function (v) { return v.getID(); })); } /** * Check if a point is in this group. * @param * @return */ }, { key: "hasPoint", value: function hasPoint(point) { return this._kernel.groupHasPoint(this._name, point.getID()); } // Properties --------------------------------------------------------------------------------- /** * Get the properties of this group. This returns an array of key: value pairs. * @param * @return */ // Map<string, any> { // TODO }, { key: "getProps", value: function getProps() { return this._kernel.groupGetProps(this._name); } /** * Set the properties of this group. The value must be an array of key: value pairs. * @param * @return */ // Map<string, any>): Map<string, any> { // TODO }, { key: "setProps", value: function setProps(props) { return this._kernel.groupSetProps(this._name, props); } // toString ------------------------------------------------------------------------------------- /** * Create s string representation of this point. * @return String */ }, { key: "toString", value: function toString() { return "Group('" + this.getName() + "', parent: " + this.getParentGroup().getName() + ", num objs: " + this.getNumObjs() + ", num faces: " + this.getNumTopos(_enums.EGeomType.faces) + ", num wires: " + this.getNumTopos(_enums.EGeomType.faces) + ", num edges: " + this.getNumTopos(_enums.EGeomType.faces) + ", num vertices: " + this.getNumTopos(_enums.EGeomType.faces) + ", num points: " + this.getNumPoints() + ")"; } }]); return Group; }(); //# sourceMappingURL=groups.js.map