gs-json
Version:
gs-JSON is a domain agnostic unifying 3D file format for geometric and semantic modelling (hence the 'gs').
225 lines (198 loc) • 7.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Topo = 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 _groups = require("./groups");
var _attrib_topoattrib = require("./attrib_topoattrib");
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"); } }
/**
* Topo class.
* An abstrcat class that is the superclass for all topo components:
* vertices, edges, wires, and faces.
*/
var Topo = exports.Topo = function () {
/**
* Creates an instance of one of the subclasses of Topo.
* The entity must already exists in the geometry.
* You should not create new topo components using this constructor.
* Topology will be created for you when you create geometric objects, such as polylines and polymeshes.
* @param geom The Geom object to which the topo belongs.
* @param path The path of the entity. This path must already exist in the geometry.
* @return The Topo object.
*/
function Topo(kernel, path) {
_classCallCheck(this, Topo);
this._kernel = kernel;
this._path = path;
}
/**
* Check if this entity exists in the model. (i.e has it been deleted?)
* @return The entity ID number.
*/
_createClass(Topo, [{
key: "exists",
value: function exists() {
return this._kernel.geomHasTopo(this._path);
}
/**
* 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 topo ----------------------------------------------------------------------------------
/**
* Get the ID of the object to which this topo component belongs.
* @return The object ID number.
*/
}, {
key: "getObjID",
value: function getObjID() {
return this._path.id;
}
/**
* Get the ID of the object to which this topo component belongs.
* @return The object ID number.
*/
}, {
key: "getObj",
value: function getObj() {
return (0, _entity_obj_cast._castToObjType)(this._kernel, this._path.id);
}
/**
* Get the geometry type for this topo component.
* This method mst 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 geometry path for this topo component.
* @return The geometry path.
*/
}, {
key: "getTopoPath",
value: function getTopoPath() {
return this._path;
}
/**
* Get a compact string representation of the geometry path for this topo component.
* @return The geometry path str.
*/
}, {
key: "getTopoPathStr",
value: function getTopoPathStr() {
// Do not implement this method.
throw new Error("Method to be overridden by subclass.");
}
/**
* Get the label of this topo.
* @return The xyz of the centroid.
*/
}, {
key: "getLabel",
value: function getLabel() {
return this.getTopoPathStr();
}
/**
* Get the label centroid of this topo.
* This is calculated as the average of the point positions for all points in the topo.
* @return The xyz of the centroid.
*/
}, {
key: "getLabelCentroid",
value: function getLabelCentroid() {
// Do not implement this method.
throw new Error("Method to be overridden by subclass.");
}
// Attributes ---------------------------------------------------------------------------------
/**
* Get the attributes for this topo component.
* @return The array of attribute names.
*/
}, {
key: "getAttribs",
value: function getAttribs() {
var _this = this;
var geom_type = this.getGeomType();
var names = this._kernel.attribGetNames(this.getGeomType());
return names.map(function (name) {
return new _attrib_topoattrib.TopoAttrib(_this._kernel, name, geom_type);
});
}
/**
* Get an attribute value for this topo component.
* @param attrib The topo attribute.
* @return The attribute value.
*/
}, {
key: "getAttribValue",
value: function getAttribValue(attrib) {
if (attrib.getGeomType() !== this.getGeomType()) {
return null;
}
return this._kernel.topoAttribGetValue(attrib.getName(), attrib.getGeomType(), this._path);
}
/**
* Set an attribute value for this topo component.
* @param attrib The topo 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.topoAttribSetValue(attrib.getName(), attrib.getGeomType(), this._path, value);
}
// Groups -------------------------------------------------------------------------------------
/**
* Get the groups for which this topo component is a member.
* @return The array of groups.
*/
}, {
key: "getGroups",
value: function getGroups() {
var _this2 = this;
var names = this._kernel.topoGetGroups(this._path);
return names.map(function (name) {
return new _groups.Group(_this2._kernel, name);
});
}
/**
* Add this topo to a group.
* @param group The group.
* @return True if the topo was added, False is the topo was already in the group.
*/
}, {
key: "addToGroup",
value: function addToGroup(group) {
// return this._kernel.groupAddTopo(group.getName(), this._path);
// TODO
throw new Error("Method not implemented");
}
}]);
return Topo;
}();
//# sourceMappingURL=topo.js.map