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.

295 lines 12.6 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 } from '@mlightcad/geometry-engine'; import { AcGiViewport } from '@mlightcad/graphic-interface'; import { AcDbEntity } from './AcDbEntity'; /** * Represents a viewport entity in AutoCAD drawings. * * A viewport is a rectangular window that displays a portion of the drawing model space * within paper space layouts. Viewports allow users to create multiple views of the same * drawing at different scales and orientations on a single sheet. * * Key characteristics: * - Viewports exist primarily in paper space layouts * - Each viewport has a unique ID number (except the default system viewport with ID 1) * - Viewports can be active or inactive * - The viewport entity itself is drawn as a rectangular border in paper space * * @example * ```typescript * const viewport = new AcDbViewport(); * viewport.centerPoint = new AcGePoint3d(0, 0, 0); * viewport.width = 10; * viewport.height = 8; * viewport.number = 2; * ``` */ var AcDbViewport = /** @class */ (function (_super) { __extends(AcDbViewport, _super); /** * Creates a new AcDbViewport instance. * * Initializes all properties with default values: * - centerPoint: origin (0,0,0) * - height: 0 * - width: 0 * - viewCenter: origin (0,0,0) * - viewHeight: 0 * - number: -1 (indicating inactive viewport) */ function AcDbViewport() { var _this = _super.call(this) || this; _this._centerPoint = new AcGePoint3d(); _this._height = 0; _this._width = 0; _this._viewCenter = new AcGePoint3d(); _this._viewHeight = 0; _this._number = -1; return _this; } Object.defineProperty(AcDbViewport.prototype, "number", { /** * Gets or sets the viewport ID number. * * This is the number that is reported by the AutoCAD CVPORT system variable * when the viewport is the current viewport in the AutoCAD editor. If the viewport is inactive, -1 * is returned. * * Important notes: * - This value is not saved with the drawing, and changes each time the drawing is opened * - Viewport ID 1 is reserved for the system-defined default viewport in paper space * - Active viewports have IDs greater than 1 * - Inactive viewports return -1 * * @returns The viewport ID number */ get: function () { return this._number; }, set: function (value) { this._number = value; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbViewport.prototype, "centerPoint", { /** * Gets or sets the center point of the viewport entity in WCS coordinates (within Paper Space). * * This point represents the geometric center of the viewport's rectangular boundary * in paper space coordinates, not the center of the model space view within the viewport. * * @returns The center point of the viewport entity */ get: function () { return this._centerPoint; }, set: function (value) { this._centerPoint = value; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbViewport.prototype, "height", { /** * Gets or sets the height of the viewport entity's window in drawing units. * * This represents the height of the viewport's rectangular boundary in paper space, * measured in the current drawing units. It defines the vertical extent of the * viewport border, not the height of the model space view within it. * * @returns The height of the viewport entity in drawing units */ get: function () { return this._height; }, set: function (value) { this._height = value; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbViewport.prototype, "width", { /** * Gets or sets the width of the viewport entity's window in drawing units. * * This represents the width of the viewport's rectangular boundary in paper space, * measured in the current drawing units. It defines the horizontal extent of the * viewport border, not the width of the model space view within the viewport. * * Note: This is the width in Paper Space of the viewport itself, not the width * of the Model Space view within the viewport. * * @returns The width of the viewport entity in drawing units */ get: function () { return this._width; }, set: function (value) { this._width = value; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbViewport.prototype, "viewCenter", { /** * Gets or sets the view center in display coordinate system coordinates. * * This point represents the center of the model space view that is displayed * within the viewport. It is specified in the display coordinate system and * determines what portion of the model space drawing is visible in the viewport. * * @returns The center point of the model space view within the viewport */ get: function () { return this._viewCenter; }, set: function (value) { this._viewCenter = value; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbViewport.prototype, "viewHeight", { /** * Gets or sets the height of the Model Space view within the viewport. * * This value represents the height of the model space view that is displayed * within the viewport, specified in display coordinate system coordinates. * * Zoom behavior: * - Zooming the view out within the viewport increases this value * - Zooming the view in within the viewport decreases this value * * @returns The height of the model space view in display coordinates */ get: function () { return this._viewHeight; }, set: function (value) { this._viewHeight = value; }, enumerable: false, configurable: true }); Object.defineProperty(AcDbViewport.prototype, "geometricExtents", { /** * Gets the geometric extents of the viewport entity. * * This method returns a bounding box that encompasses the entire viewport entity * in world coordinate system (WCS) coordinates. * * @returns A bounding box containing the viewport entity * @inheritdoc */ get: function () { // TODO: Implement it correctly return new AcGeBox3d(); }, enumerable: false, configurable: true }); /** * Renders the viewport entity using the specified renderer. * * The viewport is drawn as a rectangular border when the following conditions are met: * - The viewport entity is not in model space (i.e., it's in paper space) * - The viewport ID number is greater than 1 (not the default system viewport) * * In paper space layouts, there is always a system-defined "default" viewport that exists as * the bottom-most item. This viewport doesn't show any entities and is mainly for internal * AutoCAD purposes. The viewport ID number of this system-defined "default" viewport is 1. * * @param renderer - The renderer to use for drawing the viewport * @returns A render group containing the viewport border lines, or undefined if not drawn * @inheritdoc */ AcDbViewport.prototype.draw = function (renderer) { // Draw a rectangle if meeting the following conditions: // - viewport entity isn't in model space // - viewport id number is greater than 1 // // In paper space layouts, there is always a system-defined "default" viewport that exists as // the bottom-most item. This viewport doesn't show any entities and is mainly for internal // AutoCAD purposes. The viewport id number of this system-defined "default" viewport is 1. if (this._number > 1 && this.ownerId != this.database.tables.blockTable.modelSpace.objectId) { var viewport = this.toGiViewport(); var group = renderer.group(this.createViewportRect(viewport, renderer)); this.attachEntityInfo(group); return group; } return undefined; }; /** * Converts this AcDbViewport to an AcGiViewport for rendering purposes. * * This method creates a graphic interface viewport object that contains all the * necessary properties for rendering the viewport in the graphics system. * * @returns An AcGiViewport instance with all viewport properties copied */ AcDbViewport.prototype.toGiViewport = function () { var viewport = new AcGiViewport(); viewport.id = this.objectId; viewport.groupId = this.ownerId; viewport.number = this.number; viewport.centerPoint = this.centerPoint; viewport.width = this.width; viewport.height = this.height; viewport.viewHeight = this.viewHeight; viewport.viewCenter = this.viewCenter; return viewport; }; /** * Creates the rectangular border lines for the viewport. * * This private method generates four line entities that form a rectangle representing * the viewport's boundary. The rectangle is centered on the viewport's center point * and has dimensions specified by the viewport's width and height. * * @param viewport - The graphic interface viewport containing rendering properties * @param renderer - The renderer to use for creating the line entities * @returns An array of line entities forming the viewport border * @private */ AcDbViewport.prototype.createViewportRect = function (viewport, renderer) { var lines = []; lines.push(renderer.lines([ new AcGePoint3d(viewport.centerPoint.x - viewport.width / 2, viewport.centerPoint.y - viewport.height / 2, 0), new AcGePoint3d(viewport.centerPoint.x + viewport.width / 2, viewport.centerPoint.y - viewport.height / 2, 0) ], this.lineStyle)); lines.push(renderer.lines([ new AcGePoint3d(viewport.centerPoint.x + viewport.width / 2, viewport.centerPoint.y - viewport.height / 2, 0), new AcGePoint3d(viewport.centerPoint.x + viewport.width / 2, viewport.centerPoint.y + viewport.height / 2, 0) ], this.lineStyle)); lines.push(renderer.lines([ new AcGePoint3d(viewport.centerPoint.x + viewport.width / 2, viewport.centerPoint.y + viewport.height / 2, 0), new AcGePoint3d(viewport.centerPoint.x - viewport.width / 2, viewport.centerPoint.y + viewport.height / 2, 0) ], this.lineStyle)); lines.push(renderer.lines([ new AcGePoint3d(viewport.centerPoint.x - viewport.width / 2, viewport.centerPoint.y + viewport.height / 2, 0), new AcGePoint3d(viewport.centerPoint.x - viewport.width / 2, viewport.centerPoint.y - viewport.height / 2, 0) ], this.lineStyle)); return lines; }; /** The entity type name */ AcDbViewport.typeName = 'Viewport'; return AcDbViewport; }(AcDbEntity)); export { AcDbViewport }; //# sourceMappingURL=AcDbViewport.js.map