UNPKG

@mlightcad/data-model

Version:

The data-model package provides the core classes for interacting with AutoCAD's database and entities. This package mimics AutoCAD ObjectARX's AcDb (Database) classes and implements the drawing database structure that AutoCAD developers are familiar with.

358 lines 12.2 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { AcGeBox3d, AcGePoint3d, AcGeSpline3d } from '@mlightcad/geometry-engine'; import { AcDbCurve } from './AcDbCurve'; /** * Defines the annotation type for leader entities. */ export var AcDbLeaderAnnotationType; (function (AcDbLeaderAnnotationType) { /** Multiline text annotation */ AcDbLeaderAnnotationType[AcDbLeaderAnnotationType["MText"] = 0] = "MText"; /** Feature control frame annotation */ AcDbLeaderAnnotationType[AcDbLeaderAnnotationType["Fcf"] = 1] = "Fcf"; /** Block reference annotation */ AcDbLeaderAnnotationType[AcDbLeaderAnnotationType["BlockReference"] = 2] = "BlockReference"; /** No annotation */ AcDbLeaderAnnotationType[AcDbLeaderAnnotationType["NoAnnotation"] = 3] = "NoAnnotation"; })(AcDbLeaderAnnotationType || (AcDbLeaderAnnotationType = {})); /** * Represents a leader entity in AutoCAD. * * A leader is a dimension-like entity that consists of a line or spline with an arrowhead * pointing to a specific object or location, and an annotation (text, block, or feature * control frame) at the other end. Leaders are controlled by dimension variable settings * and dimension styles. * * @example * ```typescript * // Create a leader entity * const leader = new AcDbLeader(); * leader.appendVertex(new AcGePoint3d(0, 0, 0)); * leader.appendVertex(new AcGePoint3d(5, 5, 0)); * leader.appendVertex(new AcGePoint3d(10, 5, 0)); * leader.hasArrowHead = true; * leader.hasHookLine = true; * leader.annoType = AcDbLeaderAnnotationType.MText; * * // Access leader properties * console.log(`Number of vertices: ${leader.numVertices}`); * console.log(`Has arrow head: ${leader.hasArrowHead}`); * console.log(`Has hook line: ${leader.hasHookLine}`); * ``` */ var AcDbLeader = /** @class */ (function (_super) { __extends(AcDbLeader, _super); /** * Creates a new leader entity. * * This constructor initializes a leader with default values. * The leader is not spline-fit, has no arrowhead, no hook line, * and no annotation type. * * @example * ```typescript * const leader = new AcDbLeader(); * leader.appendVertex(new AcGePoint3d(0, 0, 0)); * leader.appendVertex(new AcGePoint3d(5, 5, 0)); * ``` */ function AcDbLeader() { var _this = _super.call(this) || this; _this._isSplined = false; _this._updated = false; _this._hasArrowHead = false; _this._vertices = []; _this._dimensionStyle = ''; _this._hasHookLine = false; _this._annoType = AcDbLeaderAnnotationType.NoAnnotation; return _this; } Object.defineProperty(AcDbLeader.prototype, "isSplined", { /** * Gets whether this leader is spline-fit. * * @returns True if the leader is spline-fit, false otherwise * * @example * ```typescript * const isSplined = leader.isSplined; * console.log(`Leader is spline-fit: ${isSplined}`); * ``` */ get: function () { return this._isSplined; }, /** * Sets whether this leader is spline-fit. * * @param value - True to make the leader spline-fit, false otherwise * * @example * ```typescript * leader.isSplined = true; * ``` */ set: function (value) { this._isSplined = value; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbLeader.prototype, "hasArrowHead", { /** * Gets whether this leader has an arrowhead. * * @returns True if the leader has an arrowhead, false otherwise * * @example * ```typescript * const hasArrowHead = leader.hasArrowHead; * console.log(`Leader has arrowhead: ${hasArrowHead}`); * ``` */ get: function () { return this._hasArrowHead; }, /** * Sets whether this leader has an arrowhead. * * @param value - True to enable arrowhead, false to disable * * @example * ```typescript * leader.hasArrowHead = true; * ``` */ set: function (value) { this._hasArrowHead = value; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbLeader.prototype, "hasHookLine", { /** * Gets whether this leader has a hook line. * * The "hookline" is the small horizontal line at the end of the leader line * just before the annotation. * * @returns True if the leader has a hook line, false otherwise * * @example * ```typescript * const hasHookLine = leader.hasHookLine; * console.log(`Leader has hook line: ${hasHookLine}`); * ``` */ get: function () { return this._hasHookLine; }, /** * Sets whether this leader has a hook line. * * @param value - True to enable hook line, false to disable * * @example * ```typescript * leader.hasHookLine = true; * ``` */ set: function (value) { this._hasHookLine = value; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbLeader.prototype, "numVertices", { /** * Gets the number of vertices in the leader's vertex list. * * @returns The number of vertices * * @example * ```typescript * const numVertices = leader.numVertices; * console.log(`Number of vertices: ${numVertices}`); * ``` */ get: function () { return this._vertices.length; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbLeader.prototype, "dimensionStyle", { /** * Gets the dimension style applied to this leader. * * @returns The dimension style name * * @example * ```typescript * const dimensionStyle = leader.dimensionStyle; * console.log(`Dimension style: ${dimensionStyle}`); * ``` */ get: function () { return this._dimensionStyle; }, /** * Sets the dimension style applied to this leader. * * @param value - The new dimension style name * * @example * ```typescript * leader.dimensionStyle = "Standard"; * ``` */ set: function (value) { this._dimensionStyle = value; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbLeader.prototype, "annoType", { /** * Gets the leader's annotation type. * * @returns The annotation type * * @example * ```typescript * const annoType = leader.annoType; * console.log(`Annotation type: ${annoType}`); * ``` */ get: function () { return this._annoType; }, /** * Sets the leader's annotation type. * * @param value - The new annotation type * * @example * ```typescript * leader.annoType = AcDbLeaderAnnotationType.MText; * ``` */ set: function (value) { this._annoType = value; }, enumerable: false, configurable: true }); /** * Appends vertex to the end of the vertex list for this leader. If vertex is not in the plane of the * leader, then it will be projected parallel the leader's normal onto the leader's plane and the * projection will be appended to the leader's vertex list. If the new vertex is too close to the one * next to it (that is, within 1.e-10 for X, Y, and Z), the new vertex will not be appended. * @param point Input point (in WCS coordinates) to add to the vertex list */ AcDbLeader.prototype.appendVertex = function (point) { this._vertices.push(new AcGePoint3d().copy(point)); this._updated = true; }; /** * Reset the vertex at index to the point point projected (along the plane normal) onto the plane * containing the leader. It doesn't reset the vertex if that would cause one of the segments to * become zero length (within 1e-10). * @param index Input index number (0 based) of the vertex to change * @param point Input new point value (in WCS) to use */ AcDbLeader.prototype.setVertexAt = function (index, point) { if (index < 0 || index >= this._vertices.length) { // TODO: Project the point onto the plane containing the leader this._vertices[index].copy(point); this._updated = true; } throw new Error('The vertex index is out of range!'); }; /** * Get the point that is the vertex at the location index (0 based) in this leader's vertex array. * @param index Input index number (0 based) of the vertex desired */ AcDbLeader.prototype.vertexAt = function (index) { if (index < 0 || index >= this._vertices.length) { this._vertices[index]; } throw new Error('The vertex index is out of range!'); }; Object.defineProperty(AcDbLeader.prototype, "geometricExtents", { /** * @inheritdoc */ get: function () { if (this._isSplined && this.splineGeo) { return this.splineGeo.calculateBoundingBox(); } else { var box = new AcGeBox3d(); return box.setFromPoints(this._vertices); } }, enumerable: false, configurable: true }); Object.defineProperty(AcDbLeader.prototype, "closed", { /** * @inheritdoc */ get: function () { return false; }, set: function (_value) { // TODO: Not sure whether the leader really support setting value of property 'closed' }, enumerable: false, configurable: true }); /** * @inheritdoc */ AcDbLeader.prototype.draw = function (renderer) { if (this.isSplined && this.splineGeo) { var points = this.splineGeo.getPoints(100); return renderer.lines(points, this.lineStyle); } else { return renderer.lines(this._vertices, this.lineStyle); } }; Object.defineProperty(AcDbLeader.prototype, "splineGeo", { get: function () { this.createSplineIfNeeded(); return this._splineGeo; }, enumerable: false, configurable: true }); AcDbLeader.prototype.createSplineIfNeeded = function () { if (this.isSplined && this.numVertices >= 2 && (this._splineGeo == null || this._updated)) { this._splineGeo = new AcGeSpline3d(this._vertices, 'Uniform'); this._updated = false; } }; /** The entity type name */ AcDbLeader.typeName = 'Leader'; return AcDbLeader; }(AcDbCurve)); export { AcDbLeader }; //# sourceMappingURL=AcDbLeader.js.map