@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.
216 lines • 7.76 kB
JavaScript
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 { AcDbEntity } from './AcDbEntity';
/**
* Represents a point entity in AutoCAD.
*
* A point is a 0-dimensional geometric object defined by its position in 3D space.
* Points are fundamental drawing entities that can be used to mark specific
* locations in drawings or as reference points for other entities.
*
* @example
* ```typescript
* // Create a point at the origin
* const point = new AcDbPoint();
* point.position = new AcGePoint3d(0, 0, 0);
*
* // Create a point at a specific location
* const point2 = new AcDbPoint();
* point2.position = new AcGePoint3d(10, 20, 5);
*
* // Access point properties
* console.log(`Point position: ${point.position}`);
* ```
*/
var AcDbPoint = /** @class */ (function (_super) {
__extends(AcDbPoint, _super);
/**
* Creates a new point entity.
*
* This constructor initializes a point object at the origin (0,0,0).
* The position can be set after creation using the position property.
*
* @example
* ```typescript
* const point = new AcDbPoint();
* point.position = new AcGePoint3d(5, 10, 0);
* ```
*/
function AcDbPoint() {
var _this = _super.call(this) || this;
_this._geo = new AcGePoint3d();
return _this;
}
Object.defineProperty(AcDbPoint.prototype, "position", {
/**
* Gets the position of this point in WCS coordinates.
*
* @returns The position as a 3D point
*
* @example
* ```typescript
* const position = point.position;
* console.log(`Point at: ${position.x}, ${position.y}, ${position.z}`);
* ```
*/
get: function () {
return this._geo;
},
/**
* Sets the position of this point in WCS coordinates.
*
* @param value - The new position
*
* @example
* ```typescript
* point.position = new AcGePoint3d(15, 25, 0);
* ```
*/
set: function (value) {
this._geo.set(value.x, value.y, value.z || 0);
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbPoint.prototype, "geometricExtents", {
/**
* Gets the geometric extents (bounding box) of this point.
*
* For a point, the bounding box is a minimal box that contains just the point.
*
* @returns The bounding box that encompasses the point
*
* @example
* ```typescript
* const extents = point.geometricExtents;
* console.log(`Point bounds: ${extents.minPoint} to ${extents.maxPoint}`);
* ```
*/
get: function () {
return new AcGeBox3d().expandByPoint(this._geo);
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbPoint.prototype, "properties", {
/**
* Returns the full property definition for this point 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 point 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: 'positionX',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.position.x; },
set: function (v) {
_this.position.x = v;
}
}
},
{
name: 'positionY',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.position.y; },
set: function (v) {
_this.position.y = v;
}
}
},
{
name: 'positionZ',
type: 'float',
editable: true,
accessor: {
get: function () { return _this.position.z; },
set: function (v) {
_this.position.z = v;
}
}
}
]
}
]
};
},
enumerable: false,
configurable: true
});
/**
* Transforms this point by the specified matrix.
*
* This method applies a geometric transformation to the point, updating
* its position according to the transformation matrix.
*
* @param matrix - The transformation matrix to apply
* @returns This point after transformation
*
* @example
* ```typescript
* const translationMatrix = AcGeMatrix3d.translation(10, 0, 0);
* point.transformBy(translationMatrix);
* // Point is now translated 10 units in the X direction
* ```
*/
AcDbPoint.prototype.transformBy = function (matrix) {
this._geo.applyMatrix4(matrix);
return this;
};
/**
* Draws this point using the specified renderer.
*
* This method renders the point using the point's current style properties,
* including the display mode and size from the database.
*
* @param renderer - The renderer to use for drawing
* @returns The rendered point entity, or undefined if drawing failed
*
* @example
* ```typescript
* const renderedPoint = point.draw(renderer);
* ```
*/
AcDbPoint.prototype.draw = function (renderer) {
return renderer.point(this._geo, {
displayMode: this.database.pdmode,
displaySize: this.database.pdsize,
color: this.rgbColor
});
};
/** The entity type name */
AcDbPoint.typeName = 'Point';
return AcDbPoint;
}(AcDbEntity));
export { AcDbPoint };
//# sourceMappingURL=AcDbPoint.js.map