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.

220 lines 8.02 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, AcGePolyline2d } from '@mlightcad/geometry-engine'; import { AcDbCurve } from './AcDbCurve'; /** * Represents the curve/spline-fit type for one 2d polyline. */ export var AcDbPoly2dType; (function (AcDbPoly2dType) { /** * A standard polyline with no curve/spline fitting. */ AcDbPoly2dType[AcDbPoly2dType["SimplePoly"] = 0] = "SimplePoly"; /** * A polyline that has been curve fit. */ AcDbPoly2dType[AcDbPoly2dType["FitCurvePoly"] = 1] = "FitCurvePoly"; /** * A spline-fit polyline that has a Quadratic B-spline path. */ AcDbPoly2dType[AcDbPoly2dType["QuadSplinePoly"] = 2] = "QuadSplinePoly"; /** * A spline-fit polyline that has a Cubic B-spline path. */ AcDbPoly2dType[AcDbPoly2dType["CubicSplinePoly"] = 3] = "CubicSplinePoly"; })(AcDbPoly2dType || (AcDbPoly2dType = {})); /** * Represents a 2d polyline entity in AutoCAD. This is the older class used to * represent 2D polylines in the legacy (DXF/DWG R12 and before) format. * * Characteristics * - Represents 2D polyline entities, typically planar (all vertices lie in a single plane). * - Each vertex is an instance of AcDb2dVertex. * - Supports bulge values (for arcs between vertices). * - Can represent fit curves or spline-fit polylines (via the polyline type flag). * - Each vertex can have flags like curve-fit vertex, spline vertex, etc. * - Geometry is stored as a linked list of vertex entities (not a single compact structure). * * Typical use case * - Used mainly for backward compatibility and import/export of old drawings. */ var AcDb2dPolyline = /** @class */ (function (_super) { __extends(AcDb2dPolyline, _super); /** * Creates a new empty 2d polyline entity. */ function AcDb2dPolyline(type, vertices, elevation, closed, _startWidth, _endWidth, bulges) { if (elevation === void 0) { elevation = 0; } if (closed === void 0) { closed = false; } if (_startWidth === void 0) { _startWidth = 0; } if (_endWidth === void 0) { _endWidth = 0; } if (bulges === void 0) { bulges = null; } var _this = _super.call(this) || this; _this._polyType = type; _this._elevation = elevation; var hasBulge = bulges && (bulges === null || bulges === void 0 ? void 0 : bulges.length) === vertices.length; var polylineVertices = vertices.map(function (vertex, index) { return { x: vertex.x, y: vertex.y, bulge: hasBulge ? bulges[index] : undefined }; }); _this._geo = new AcGePolyline2d(polylineVertices, closed); return _this; } Object.defineProperty(AcDb2dPolyline.prototype, "polyType", { /** * Gets the curve/spline-fit type for this 2d polyline. * * @returns The curve/spline-fit type for this 2d polyline. */ get: function () { return this._polyType; }, /** * Sets the curve/spline-fit type for this 2d polyline. * * @param value - The curve/spline-fit type for this 2d polyline. */ set: function (value) { this._polyType = value; }, enumerable: false, configurable: true }); Object.defineProperty(AcDb2dPolyline.prototype, "elevation", { /** * Gets the elevation of this polyline. * * The elevation is the distance of the polyline's plane from the WCS origin * along the Z-axis. * * @returns The elevation value * * @example * ```typescript * const elevation = polyline.elevation; * console.log(`Polyline elevation: ${elevation}`); * ``` */ get: function () { return this._elevation; }, /** * Sets the elevation of this polyline. * * @param value - The new elevation value * * @example * ```typescript * polyline.elevation = 10; * ``` */ set: function (value) { this._elevation = value; }, enumerable: false, configurable: true }); Object.defineProperty(AcDb2dPolyline.prototype, "closed", { /** * Gets whether this polyline is closed. * * A closed polyline has a segment drawn from the last vertex to the first vertex, * forming a complete loop. * * @returns True if the polyline is closed, false otherwise * * @example * ```typescript * const isClosed = polyline.closed; * console.log(`Polyline is closed: ${isClosed}`); * ``` */ get: function () { return this._geo.closed; }, /** * Sets whether this polyline is closed. * * @param value - True to close the polyline, false to open it * * @example * ```typescript * polyline.closed = true; // Close the polyline * ``` */ set: function (value) { this._geo.closed = value; }, enumerable: false, configurable: true }); Object.defineProperty(AcDb2dPolyline.prototype, "geometricExtents", { /** * Gets the geometric extents (bounding box) of this polyline. * * @returns The bounding box that encompasses the entire polyline * * @example * ```typescript * const extents = polyline.geometricExtents; * console.log(`Polyline bounds: ${extents.minPoint} to ${extents.maxPoint}`); * ``` */ get: function () { var box = this._geo.box; return new AcGeBox3d({ x: box.min.x, y: box.min.y, z: this._elevation }, { x: box.max.x, y: box.max.y, z: this._elevation }); }, enumerable: false, configurable: true }); /** * Gets the grip points for this polyline. * * Grip points are control points that can be used to modify the polyline. * For a polyline, the grip points are all the vertices. * * @returns Array of grip points (all vertices) */ AcDb2dPolyline.prototype.subGetGripPoints = function () { var gripPoints = new Array(); // TODO: Finish logic to get grip points return gripPoints; }; /** * Draws this polyline using the specified renderer. * * @param renderer - The renderer to use for drawing * @returns The rendered polyline entity, or undefined if drawing failed */ AcDb2dPolyline.prototype.draw = function (renderer) { var _this = this; var points = []; var tmp = this._geo.getPoints(100); tmp.forEach(function (point) { return points.push(new AcGePoint3d().set(point.x, point.y, _this.elevation)); }); return renderer.lines(points, this.lineStyle); }; /** The entity type name */ AcDb2dPolyline.typeName = '2dPolyline'; return AcDb2dPolyline; }(AcDbCurve)); export { AcDb2dPolyline }; //# sourceMappingURL=AcDb2dPolyline.js.map