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.

303 lines 11.4 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, AcGeVector3d } from '@mlightcad/geometry-engine'; import { AcDbCurve } from './AcDbCurve'; /** * Represents an xline entity in AutoCAD. * * An xline is a 3D geometric object that extends infinitely in both directions from a base point. * Xlines are commonly used for construction lines, reference lines, and temporary geometry. * Unlike lines, xlines have no end points and extend to infinity in both directions. * * @example * ```typescript * // Create an xline from origin in the positive X direction * const xline = new AcDbXline(); * xline.basePoint = new AcGePoint3d(0, 0, 0); * xline.unitDir = new AcGeVector3d(1, 0, 0); * * // Access xline properties * console.log(`Base point: ${xline.basePoint}`); * console.log(`Unit direction: ${xline.unitDir}`); * ``` */ var AcDbXline = /** @class */ (function (_super) { __extends(AcDbXline, _super); /** * Creates a new xline entity. * * This constructor initializes an xline with default values. * The base point is at the origin and the unit direction is undefined. * * @example * ```typescript * const xline = new AcDbXline(); * xline.basePoint = new AcGePoint3d(5, 10, 0); * xline.unitDir = new AcGeVector3d(0, 1, 0); // Positive Y direction * ``` */ function AcDbXline() { var _this = _super.call(this) || this; _this._basePoint = new AcGePoint3d(); _this._unitDir = new AcGeVector3d(); return _this; } Object.defineProperty(AcDbXline.prototype, "basePoint", { /** * Gets the base point of this xline. * * The base point is the center point from which the xline extends infinitely * in both directions. * * @returns The base point as a 3D point * * @example * ```typescript * const basePoint = xline.basePoint; * console.log(`Xline base point: ${basePoint.x}, ${basePoint.y}, ${basePoint.z}`); * ``` */ get: function () { return this._basePoint; }, /** * Sets the base point of this xline. * * @param value - The new base point * * @example * ```typescript * xline.basePoint = new AcGePoint3d(10, 20, 0); * ``` */ set: function (value) { this._basePoint.copy(value); }, enumerable: false, configurable: true }); Object.defineProperty(AcDbXline.prototype, "unitDir", { /** * Gets the unit direction vector of this xline. * * The unit direction vector defines the direction in which the xline extends * infinitely in both directions from the base point. * * @returns The unit direction vector * * @example * ```typescript * const unitDir = xline.unitDir; * console.log(`Xline direction: ${unitDir.x}, ${unitDir.y}, ${unitDir.z}`); * ``` */ get: function () { return this._unitDir; }, /** * Sets the unit direction vector of this xline. * * @param value - The new unit direction vector * * @example * ```typescript * xline.unitDir = new AcGeVector3d(0, 0, 1); // Positive Z direction * ``` */ set: function (value) { this._unitDir.copy(value); }, enumerable: false, configurable: true }); Object.defineProperty(AcDbXline.prototype, "closed", { /** * Gets whether this xline is closed. * * Xlines are always open entities, so this always returns false. * * @returns Always false for xlines */ get: function () { return false; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbXline.prototype, "geometricExtents", { /** * Gets the geometric extents (bounding box) of this xline. * * Since xlines extend infinitely in both directions, this method returns a * bounding box that encompasses a finite portion of the xline for practical purposes. * * @returns The bounding box that encompasses a portion of the xline * * @example * ```typescript * const extents = xline.geometricExtents; * console.log(`Xline bounds: ${extents.minPoint} to ${extents.maxPoint}`); * ``` */ get: function () { var extents = new AcGeBox3d(); extents.expandByPoint(this._unitDir.clone().multiplyScalar(10).add(this._basePoint)); extents.expandByPoint(this._unitDir.clone().multiplyScalar(-10).add(this._basePoint)); return extents; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbXline.prototype, "properties", { /** * Returns the full property definition for this xline entity, including * general group and geometry group. * * The geometry group exposes editable start/end coordinates via * {@link AcDbPropertyAccessor} so the property palette can update * the xline in real-time. * * Each property is an {@link AcDbEntityRuntimeProperty}. */ get: function () { var _this = this; return { type: this.type, groups: [ this.getGeneralProperties(), { groupName: 'geometry', properties: [ { name: 'basePointX', type: 'float', editable: true, accessor: { get: function () { return _this.basePoint.x; }, set: function (v) { _this.basePoint.x = v; } } }, { name: 'basePointY', type: 'float', editable: true, accessor: { get: function () { return _this.basePoint.y; }, set: function (v) { _this.basePoint.y = v; } } }, { name: 'basePointZ', type: 'float', editable: true, accessor: { get: function () { return _this.basePoint.z; }, set: function (v) { _this.basePoint.z = v; } } }, { name: 'unitDirX', type: 'float', editable: true, accessor: { get: function () { return _this.unitDir.x; }, set: function (v) { _this.unitDir.x = v; } } }, { name: 'unitDirY', type: 'float', editable: true, accessor: { get: function () { return _this.unitDir.y; }, set: function (v) { _this.unitDir.y = v; } } }, { name: 'unitDirZ', type: 'float', editable: true, accessor: { get: function () { return _this.unitDir.z; }, set: function (v) { _this.unitDir.z = v; } } } ] } ] }; }, enumerable: false, configurable: true }); /** * Gets the grip points for this xline. * * Grip points are control points that can be used to modify the xline. * For an xline, the grip point is the base point. * * @returns Array of grip points (base point) * * @example * ```typescript * const gripPoints = xline.subGetGripPoints(); * // gripPoints contains: [basePoint] * ``` */ AcDbXline.prototype.subGetGripPoints = function () { var gripPoints = new Array(); gripPoints.push(this.basePoint); return gripPoints; }; /** * Draws this xline using the specified renderer. * * This method renders the xline as a line segment extending from the base point * in both directions along the unit vector. For practical purposes, the xline is * drawn with a finite length. * * @param renderer - The renderer to use for drawing * @returns The rendered xline entity, or undefined if drawing failed * * @example * ```typescript * const renderedXline = xline.draw(renderer); * ``` */ AcDbXline.prototype.draw = function (renderer) { var points = []; points.push(this._unitDir.clone().multiplyScalar(-1000000).add(this._basePoint)); points.push(this._unitDir.clone().multiplyScalar(1000000).add(this._basePoint)); return renderer.lines(points, this.lineStyle); }; /** The entity type name */ AcDbXline.typeName = 'Xline'; return AcDbXline; }(AcDbCurve)); export { AcDbXline }; //# sourceMappingURL=AcDbXline.js.map