UNPKG

gs-json

Version:

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

223 lines (200 loc) 7.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Ent = 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 _attrib_cast = require("./attrib_cast"); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Class Ent. * An abstrcat class that is the superclass for all geometric entities, both Point and Obj. * An entity may be part of a group and may have attributes. */ var Ent = exports.Ent = function () { /** * Creates an instance of one of the subclasses of Ent. * The entity must already exists in the geometry. * Do not use this constructor if you want to add a new entity to the geometry. * For that, you should use one of the 'add' methods in the geometry class. * @param geom The Geom object to which the point belongs. * @param id The ID of the entity. This ID must already exist in the geometry. * @return The Ent object. */ function Ent(kernel, id) { _classCallCheck(this, Ent); this._kernel = kernel; this._id = id; } /** * Get the Model object that this entity belongs to. * @return A Model object. */ _createClass(Ent, [{ 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 Entity -------------------------------------------------------------------------------- /** * Get the ID number of this entity. * @return The entity ID number. */ }, { key: "getID", value: function getID() { return this._id; } /** * Check if this entity exists in the model. (i.e has it been deleted?) * @return The entity ID number. */ }, { key: "exists", value: function exists() { // Do not implement this method. throw new Error("Method to be overridden by subclass."); } /** * Get the geometry type for this entity. * This method must be overridden by the sub-classes. * @return The geometry type. */ }, { key: "getGeomType", value: function getGeomType() { // Do not implement this method. throw new Error("Method to be overridden by subclass."); } /** * Get the label for this entity. * This method must be overridden by the sub-classes. * @return The geometry type. */ }, { key: "getLabel", value: function getLabel() { // Do not implement this method. throw new Error("Method to be overridden by subclass."); } /** * Get the label centroid for this entity. * This method must be overridden by the sub-classes. * @return The geometry type. */ }, { key: "getLabelCentroid", value: function getLabelCentroid() { // Do not implement this method. throw new Error("Method to be overridden by subclass."); } /** * Make a copy of this entity. * This method must be overridden by the sub-classes. * @return The geometry type. */ }, { key: "copy", value: function copy(copy_attribs) { // Do not implement this method. throw new Error("Method to be overridden by subclass."); } /** * Transform points. * This method must be overridden by the sub-classes. * @param matrix The xform matrix. */ }, { key: "xform", value: function xform(matrix) { // Do not implement this method. throw new Error("Method to be overridden by subclass."); } // Attributes --------------------------------------------------------------------------------- /** * Get the attribute names for this entity. * @return The array of attribute names. */ }, { key: "getAttribs", value: function getAttribs() { var geom_type = this.getGeomType(); var names = this._kernel.attribGetNames(geom_type); return (0, _attrib_cast._castToAttribTypes)(this._kernel, geom_type, names); } /** * Get an attribute value for this entity. * @param attrib The attribute. * @return The attribute value. */ }, { key: "getAttribValue", value: function getAttribValue(attrib) { if (attrib.getGeomType() !== this.getGeomType()) { return null; } return this._kernel.entAttribGetValue(attrib.getName(), attrib.getGeomType(), this._id); } /** * Set an attribute value for this entity. * @param attrib The attribute. * @param value The new attribute value. * @return The old attribute value. */ }, { key: "setAttribValue", value: function setAttribValue(attrib, value) { if (attrib.getGeomType() !== this.getGeomType()) { return null; } return this._kernel.entAttribSetValue(attrib.getName(), attrib.getGeomType(), this._id, value); } // Groups ------------------------------------------------------------------------------------- /** * Get the groups for all the groups for which this entity is a member. * This method must be overridden by the sub-classes. * @return The array of group names. */ }, { key: "getGroups", value: function getGroups() { // Do not implement this method. throw new Error("Method to be overridden by subclass."); } /** * Add this object to a group. * This method must be overridden by the sub-classes. * @param group The group. * @return True if the entity was added, False is the object was already in the group. */ }, { key: "addToGroup", value: function addToGroup(group) { // Do not implement this method. throw new Error("Method to be overridden by subclass."); } // toString ------------------------------------------------------------------------------------- /** * Create s string representation of this object. * This method must be overridden by the sub-classes. * @return Strig */ }, { key: "toString", value: function toString() { // Do not implement this method. throw new Error("Method to be overridden by subclass."); } }]); return Ent; }(); //# sourceMappingURL=entity.js.map