@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.
250 lines • 9.73 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 { AcGeArea2d, AcGeBox3d } from '@mlightcad/geometry-engine';
import { AcDbEntity } from './AcDbEntity';
/**
* Defines the type of hatch pattern.
*/
export var AcDbHatchPatternType;
(function (AcDbHatchPatternType) {
/**
* A user-defined pattern provides a direct method to define a simple hatch pattern using a specified
* hatch entity linetype. The definition data for user-defined hatch pattern include angle, space and
* double. "Angle" specifies an angle for the hatch pattern relative to the X axis of the hatch plane
* in OCS. "Space" defines the vertical distance between two consecutive pattern lines. "Double"
* specifies that a second set of lines is to be drawn at 90 degrees to the original lines. When
* specifying a user-defined hatch pattern, you don't need to set the pattern name. AutoCAD designates
* a default pattern name "U" for all user-defined patterns.
*/
AcDbHatchPatternType[AcDbHatchPatternType["UserDefined"] = 0] = "UserDefined";
/**
* A predefined pattern type allows you to select a hatch pattern from the AutoCAD standard hatch
* pattern file acad.pat in the "support" directory. The file contains many predefined hatch patterns,
* including ANGLE, ANSI31, BRICK, CLAY, etc. When you use a predefined pattern, you can also specify
* a scale and angle in order to modify the hatch's appearance. Solid fill is a new predefined pattern
* type that enables the application to fill in the hatch area with a specified color. The reserved
* name for this new pattern is "SOLID." SOLID does not appear in the file acad.pat because it has no
* definition data. To specify a solid, use the keyword "SOLID".
*/
AcDbHatchPatternType[AcDbHatchPatternType["Predefined"] = 1] = "Predefined";
/**
* A custom-defined pattern type stores the pattern in its own PAT file, in which the name of the
* hatch pattern must match the name of the file. For instance, you must store the TEST hatch pattern
* in a file named test.pat, and the file must be located in the ACAD search path. When you use a
* custom-defined pattern, you can also specify a scale and angle in order to modify the hatch's
* appearance.
*/
AcDbHatchPatternType[AcDbHatchPatternType["Custom"] = 2] = "Custom";
})(AcDbHatchPatternType || (AcDbHatchPatternType = {}));
/**
* Defines the hatch style for determining which areas to hatch.
*/
export var AcDbHatchStyle;
(function (AcDbHatchStyle) {
/**
* Normal hatch style will hatch inward from the outer loop. If it encounters an internal intersection,
* it turns off hatching until it encounters another intersection. Thus, areas separated from the
* outside of the hatched area by an odd number of intersections are hatched, while areas separated by
* an even number of intersections are not.
*/
AcDbHatchStyle[AcDbHatchStyle["Normal"] = 0] = "Normal";
/**
* Outer hatch style will hatch inward from the outer loop. It turns off hatching if it encounters an
* intersection and does not turn it back on. Because this process starts from both ends of each hatch
* line, only the outmost level of the structure is hatched, and the internal structure is left blank.
*/
AcDbHatchStyle[AcDbHatchStyle["Outer"] = 1] = "Outer";
/**
* Ignore hatch style will hatch inward from the outer loop and ignores all internal loops.
*/
AcDbHatchStyle[AcDbHatchStyle["Ignore"] = 2] = "Ignore";
})(AcDbHatchStyle || (AcDbHatchStyle = {}));
/**
* Represents a hatch entity in AutoCAD.
*
* A hatch is a 2D geometric object that fills an area with a pattern of lines, dots, or other shapes.
* Hatches are commonly used to represent materials, textures, or to distinguish different areas in drawings.
*
* @example
* ```typescript
* // Create a hatch entity
* const hatch = new AcDbHatch();
* hatch.patternName = "ANSI31";
* hatch.patternType = AcDbHatchPatternType.Predefined;
* hatch.patternScale = 1.0;
* hatch.patternAngle = 0;
* hatch.hatchStyle = AcDbHatchStyle.Normal;
*
* // Add a loop to define the hatch boundary
* const loop = new AcGeLoop2d();
* loop.add(new AcGePoint2d(0, 0));
* loop.add(new AcGePoint2d(10, 0));
* loop.add(new AcGePoint2d(10, 5));
* loop.add(new AcGePoint2d(0, 5));
* hatch.add(loop);
*
* // Access hatch properties
* console.log(`Pattern name: ${hatch.patternName}`);
* console.log(`Pattern scale: ${hatch.patternScale}`);
* ```
*/
var AcDbHatch = /** @class */ (function (_super) {
__extends(AcDbHatch, _super);
/**
* Creates a new hatch entity.
*
* This constructor initializes a hatch with default values.
* The elevation is 0, pattern type is Predefined, pattern scale is 1,
* pattern angle is 0, and hatch style is Normal.
*
* @example
* ```typescript
* const hatch = new AcDbHatch();
* hatch.patternName = "ANSI31";
* hatch.patternScale = 2.0;
* ```
*/
function AcDbHatch() {
var _this = _super.call(this) || this;
_this._elevation = 0;
_this._geo = new AcGeArea2d();
_this._definitionLines = [];
_this._patternName = '';
_this._patternType = AcDbHatchPatternType.Predefined;
_this._patternAngle = 0;
_this._patternScale = 1;
_this._hatchStyle = AcDbHatchStyle.Normal;
return _this;
}
Object.defineProperty(AcDbHatch.prototype, "definitionLines", {
/**
* Gets the definition lines for the hatch pattern.
*
* @returns Array of hatch pattern lines
*
* @example
* ```typescript
* const definitionLines = hatch.definitionLines;
* console.log(`Number of definition lines: ${definitionLines.length}`);
* ```
*/
get: function () {
return this._definitionLines;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbHatch.prototype, "patternName", {
/**
* The pattern name of this hatch.
*/
get: function () {
return this._patternName;
},
set: function (value) {
this._patternName = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbHatch.prototype, "patternType", {
/**
* The pattern name of this hatch.
*/
get: function () {
return this._patternType;
},
set: function (value) {
this._patternType = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbHatch.prototype, "patternAngle", {
/**
* The pattern angle (in radians) of this hatch.
*/
get: function () {
return this._patternAngle;
},
set: function (value) {
this._patternAngle = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbHatch.prototype, "patternScale", {
/**
* The pattern scale of the hatch entity. It is a non-zero positive number.
*/
get: function () {
return this._patternScale;
},
set: function (value) {
this._patternScale = value;
},
enumerable: false,
configurable: true
});
Object.defineProperty(AcDbHatch.prototype, "hatchStyle", {
/**
* The pattern style of the hatch entity.
*/
get: function () {
return this._hatchStyle;
},
set: function (value) {
this._hatchStyle = value;
},
enumerable: false,
configurable: true
});
/**
* Append one loop to loops of this area. If it is the first loop added, it is the outter loop.
* Otherwise, it is an inner loop.
* @param loop Input the loop to append
*/
AcDbHatch.prototype.add = function (loop) {
this._geo.add(loop);
};
Object.defineProperty(AcDbHatch.prototype, "geometricExtents", {
/**
* @inheritdoc
*/
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
});
/**
* @inheritdoc
*/
AcDbHatch.prototype.draw = function (renderer) {
return renderer.area(this._geo, {
color: this.rgbColor,
solidFill: false,
patternAngle: this.patternAngle,
patternLines: this.definitionLines
});
};
/** The entity type name */
AcDbHatch.typeName = 'Hatch';
return AcDbHatch;
}(AcDbEntity));
export { AcDbHatch };
//# sourceMappingURL=AcDbHatch.js.map