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.

394 lines 14.3 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 { AcGeLine3d, AcGePoint3d } from '@mlightcad/geometry-engine'; import { AcDbOsnapMode } from '../misc/AcDbOsnapMode'; import { AcDbCurve } from './AcDbCurve'; /** * Represents a line entity in AutoCAD. * * A line is a 3D geometric object defined by its start point and end point. * Lines are fundamental drawing entities that can be used to create straight * line segments in 2D or 3D space. * * @example * ```typescript * // Create a line from point (0,0,0) to point (10,10,0) * const line = new AcDbLine( * new AcGePoint3d(0, 0, 0), * new AcGePoint3d(10, 10, 0) * ); * * // Access line properties * console.log(`Start point: ${line.startPoint}`); * console.log(`End point: ${line.endPoint}`); * console.log(`Mid point: ${line.midPoint}`); * ``` */ var AcDbLine = /** @class */ (function (_super) { __extends(AcDbLine, _super); /** * Creates a new line entity. * * This constructor initializes the line object with the specified start and end points. * Both points must be in World Coordinate System (WCS) coordinates. * * @param start - The starting point of the line in WCS coordinates * @param end - The ending point of the line in WCS coordinates * * @example * ```typescript * const line = new AcDbLine( * new AcGePoint3d(0, 0, 0), * new AcGePoint3d(100, 50, 0) * ); * ``` */ function AcDbLine(start, end) { var _this = _super.call(this) || this; _this._geo = new AcGeLine3d(start, end); return _this; } Object.defineProperty(AcDbLine.prototype, "startPoint", { /** * Gets the starting point of this line. * * @returns The starting point as a 3D point * * @example * ```typescript * const startPoint = line.startPoint; * console.log(`Line starts at: ${startPoint.x}, ${startPoint.y}, ${startPoint.z}`); * ``` */ get: function () { return this._geo.startPoint; }, /** * Sets the starting point of this line. * * @param value - The new starting point * * @example * ```typescript * line.startPoint = new AcGePoint3d(5, 5, 0); * ``` */ set: function (value) { this._geo.startPoint = value; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbLine.prototype, "endPoint", { /** * Gets the ending point of this line. * * @returns The ending point as a 3D point * * @example * ```typescript * const endPoint = line.endPoint; * console.log(`Line ends at: ${endPoint.x}, ${endPoint.y}, ${endPoint.z}`); * ``` */ get: function () { return this._geo.endPoint; }, /** * Sets the ending point of this line. * * @param value - The new ending point * * @example * ```typescript * line.endPoint = new AcGePoint3d(15, 15, 0); * ``` */ set: function (value) { this._geo.endPoint = value; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbLine.prototype, "midPoint", { /** * Gets the middle point of this line. * * The middle point is calculated as the midpoint between the start and end points. * * @returns The middle point as a 3D point * * @example * ```typescript * const midPoint = line.midPoint; * console.log(`Line midpoint: ${midPoint.x}, ${midPoint.y}, ${midPoint.z}`); * ``` */ get: function () { return this._geo.midPoint; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbLine.prototype, "geometricExtents", { /** * Gets the geometric extents (bounding box) of this line. * * @returns The bounding box that encompasses the entire line * * @example * ```typescript * const extents = line.geometricExtents; * console.log(`Line bounds: ${extents.minPoint} to ${extents.maxPoint}`); * ``` */ get: function () { return this._geo.box; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbLine.prototype, "closed", { /** * Gets whether this line is closed. * * Lines are always open entities, so this always returns false. * * @returns Always false for lines */ get: function () { return false; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbLine.prototype, "properties", { /** * Returns the full property definition for this line 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 line in real-time. * * Each property is an {@link AcDbEntityRuntimeProperty}. */ get: function () { var _this = this; return { type: this.type, groups: [ this.getGeneralProperties(), { groupName: 'geometry', properties: [ // --- Start Point --- { name: 'startX', type: 'float', editable: true, accessor: { get: function () { return _this.startPoint.x; }, set: function (v) { _this.startPoint.x = v; } } }, { name: 'startY', type: 'float', editable: true, accessor: { get: function () { return _this.startPoint.y; }, set: function (v) { _this.startPoint.y = v; } } }, { name: 'startZ', type: 'float', editable: true, accessor: { get: function () { return _this.startPoint.z; }, set: function (v) { _this.startPoint.z = v; } } }, { name: 'endX', type: 'float', editable: true, accessor: { get: function () { return _this.endPoint.x; }, set: function (v) { _this.endPoint.x = v; } } }, { name: 'endY', type: 'float', editable: true, accessor: { get: function () { return _this.endPoint.y; }, set: function (v) { _this.endPoint.y = v; } } }, { name: 'endZ', type: 'float', editable: true, accessor: { get: function () { return _this.endPoint.z; }, set: function (v) { _this.endPoint.z = v; } } } ] } ] }; }, enumerable: false, configurable: true }); /** * Gets the grip points for this line. * * Grip points are control points that can be used to modify the line. * For a line, the grip points are the midpoint, start point, and end point. * * @returns Array of grip points (midpoint, start point, end point) * * @example * ```typescript * const gripPoints = line.subGetGripPoints(); * // gripPoints contains: [midPoint, startPoint, endPoint] * ``` */ AcDbLine.prototype.subGetGripPoints = function () { var gripPoints = new Array(); gripPoints.push(this.midPoint); gripPoints.push(this.startPoint); gripPoints.push(this.endPoint); return gripPoints; }; /** * Gets the object snap points for this line. * * Object snap points are precise points that can be used for positioning * when drawing or editing. This method provides snap points based on the * specified snap mode. * * @param osnapMode - The object snap mode (Endpoint, Midpoint, Nearest, Perpendicular, Tangent) * @param pickPoint - The point where the user picked * @param _lastPoint - The last point (unused) * @param snapPoints - Array to populate with snap points * * @example * ```typescript * const snapPoints: AcGePoint3d[] = []; * line.subGetOsnapPoints(AcDbOsnapMode.EndPoint, 0, pickPoint, lastPoint, snapPoints); * // snapPoints now contains the start and end points * ``` */ AcDbLine.prototype.subGetOsnapPoints = function (osnapMode, pickPoint, _lastPoint, snapPoints) { var startPoint = this.startPoint; var endPoint = this.endPoint; switch (osnapMode) { case AcDbOsnapMode.EndPoint: snapPoints.push(startPoint); snapPoints.push(endPoint); break; case AcDbOsnapMode.MidPoint: snapPoints.push(this.midPoint); break; case AcDbOsnapMode.Nearest: // Nearest snap: project the pick point onto the line and return that point { var projectedPoint = this._geo.project(pickPoint); snapPoints.push(projectedPoint); } break; case AcDbOsnapMode.Perpendicular: // Perpendicular snap: find a perpendicular point from the pick point to the line { var perpPoint = this._geo.perpPoint(pickPoint); snapPoints.push(perpPoint); } break; case AcDbOsnapMode.Tangent: // Tangent snap: simply return an endpoint (depends on the geometry being connected) snapPoints.push(startPoint); // Example: return the start point as a tangent point break; default: break; } }; /** * Transforms this line by the specified matrix. * * This method applies a geometric transformation to the line, updating * both the start and end points according to the transformation matrix. * * @param matrix - The transformation matrix to apply * @returns This line after transformation * * @example * ```typescript * const translationMatrix = AcGeMatrix3d.translation(10, 0, 0); * line.transformBy(translationMatrix); * // Line is now translated 10 units in the X direction * ``` */ AcDbLine.prototype.transformBy = function (matrix) { this._geo.transform(matrix); return this; }; /** * Draws this line using the specified renderer. * * This method renders the line as a series of connected line segments * using the line's current style properties. * * @param renderer - The renderer to use for drawing * @returns The rendered line entity, or undefined if drawing failed * * @example * ```typescript * const renderedLine = line.draw(renderer); * ``` */ AcDbLine.prototype.draw = function (renderer) { var start = this.startPoint; var end = this.endPoint; var points = [ new AcGePoint3d(start.x, start.y, 0), new AcGePoint3d(end.x, end.y, 0) ]; return renderer.lines(points, this.lineStyle); }; /** The entity type name */ AcDbLine.typeName = 'Line'; return AcDbLine; }(AcDbCurve)); export { AcDbLine }; //# sourceMappingURL=AcDbLine.js.map