@mlightcad/data-model 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +226 -0
- package/package.json +5 -5
package/README.md
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
# @mlightcad/data-model
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package contains the core classes for defining and manipulating AutoCAD entities (e.g., lines, circles, blocks), handling entity attributes and geometric data, and storing and retrieving data from the drawing database. It uses the same drawing database structure as AutoCAD ObjectARX, making it easier for AutoCAD developers to build applications based on this SDK.
|
|
8
|
+
|
|
9
|
+
## Key Features
|
|
10
|
+
|
|
11
|
+
- **Database Management**: Complete AutoCAD database structure with tables and records
|
|
12
|
+
- **Entity Support**: All major AutoCAD entity types (lines, circles, polylines, blocks, etc.)
|
|
13
|
+
- **File Conversion**: Support for reading DXF and DWG files with extensible converter system
|
|
14
|
+
- **Symbol Tables**: Layer, linetype, text style, and dimension style management
|
|
15
|
+
- **Block Management**: Block table and block reference handling
|
|
16
|
+
- **Dimension Support**: Comprehensive dimension entity types
|
|
17
|
+
- **Layout Management**: Paper space and model space layout handling
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @mlightcad/data-model
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Key Classes
|
|
26
|
+
|
|
27
|
+
### Database and Base Classes
|
|
28
|
+
- **AcDbDatabase**: Main database class that contains all drawing data
|
|
29
|
+
- **AcDbObject**: Base class for all database-resident objects
|
|
30
|
+
- **AcDbHostApplicationServices**: Services provided by the host application
|
|
31
|
+
|
|
32
|
+
### Symbol Tables
|
|
33
|
+
- **AcDbSymbolTable**: Base class for symbol tables
|
|
34
|
+
- **AcDbSymbolTableRecord**: Base class for symbol table records
|
|
35
|
+
- **AcDbLayerTable, AcDbLayerTableRecord**: Layer management
|
|
36
|
+
- **AcDbLinetypeTable, AcDbLinetypeTableRecord**: Linetype management
|
|
37
|
+
- **AcDbTextStyleTable, AcDbTextStyleTableRecord**: Text style management
|
|
38
|
+
- **AcDbDimStyleTable, AcDbDimStyleTableRecord**: Dimension style management
|
|
39
|
+
- **AcDbBlockTable, AcDbBlockTableRecord**: Block management
|
|
40
|
+
- **AcDbViewportTable, AcDbViewportTableRecord**: Viewport management
|
|
41
|
+
|
|
42
|
+
### Entities
|
|
43
|
+
- **AcDbEntity**: Base class for all drawable objects
|
|
44
|
+
- **AcDbLine**: Line entity
|
|
45
|
+
- **AcDbCircle**: Circle entity
|
|
46
|
+
- **AcDbArc**: Arc entity
|
|
47
|
+
- **AcDbPolyline**: Polyline entity
|
|
48
|
+
- **AcDbText, AcDbMText**: Text and multiline text entities
|
|
49
|
+
- **AcDbBlockReference**: Block reference entity
|
|
50
|
+
- **AcDbPoint**: Point entity
|
|
51
|
+
- **AcDbEllipse**: Ellipse entity
|
|
52
|
+
- **AcDbSpline**: Spline curve entity
|
|
53
|
+
- **AcDbHatch**: Hatch pattern entity
|
|
54
|
+
- **AcDbTable**: Table entity
|
|
55
|
+
- **AcDbRasterImage**: Raster image entity
|
|
56
|
+
- **AcDbLeader**: Leader entity
|
|
57
|
+
- **AcDbRay, AcDbXline**: Construction line entities
|
|
58
|
+
- **AcDbTrace, AcDbWipeout**: Filled area entities
|
|
59
|
+
|
|
60
|
+
### Dimension Entities
|
|
61
|
+
- **AcDbDimension**: Base class for dimension entities
|
|
62
|
+
- **AcDbAlignedDimension**: Aligned dimension
|
|
63
|
+
- **AcDbRadialDimension**: Radial dimension
|
|
64
|
+
- **AcDbDiametricDimension**: Diametric dimension
|
|
65
|
+
- **AcDb3PointAngularDimension**: 3-point angular dimension
|
|
66
|
+
- **AcDbArcDimension**: Arc dimension
|
|
67
|
+
- **AcDbOrdinateDimension**: Ordinate dimension
|
|
68
|
+
|
|
69
|
+
### Objects and Layouts
|
|
70
|
+
- **AcDbDictionary**: Dictionary object for storing key-value pairs
|
|
71
|
+
- **AcDbRasterImageDef**: Raster image definition
|
|
72
|
+
- **AcDbLayout**: Layout object for paper space
|
|
73
|
+
- **AcDbLayoutDictionary**: Layout dictionary management
|
|
74
|
+
- **AcDbLayoutManager**: Layout manager for switching between layouts
|
|
75
|
+
|
|
76
|
+
### File Conversion
|
|
77
|
+
- **AcDbDatabaseConverter**: Base class for file format converters
|
|
78
|
+
- **AcDbDatabaseConverterManager**: Manages registered file converters
|
|
79
|
+
- **AcDbDxfConverter**: DXF file converter
|
|
80
|
+
- **AcDbBatchProcessing**: Batch processing utilities
|
|
81
|
+
- **AcDbObjectConverter**: Object conversion utilities
|
|
82
|
+
|
|
83
|
+
### Utilities
|
|
84
|
+
- **AcDbConstants**: Database constants
|
|
85
|
+
- **AcDbObjectIterator**: Iterator for database objects
|
|
86
|
+
- **AcDbAngleUnits**: Angle unit utilities
|
|
87
|
+
- **AcDbUnitsValue**: Unit value handling
|
|
88
|
+
- **AcDbOsnapMode**: Object snap modes
|
|
89
|
+
- **AcDbRenderingCache**: Rendering cache management
|
|
90
|
+
|
|
91
|
+
## Usage Examples
|
|
92
|
+
|
|
93
|
+
### Database Operations
|
|
94
|
+
```typescript
|
|
95
|
+
import { AcDbDatabase } from '@mlightcad/data-model';
|
|
96
|
+
|
|
97
|
+
// Create a new database
|
|
98
|
+
const database = new AcDbDatabase();
|
|
99
|
+
|
|
100
|
+
// Get symbol tables
|
|
101
|
+
const layerTable = database.getLayerTable();
|
|
102
|
+
const blockTable = database.getBlockTable();
|
|
103
|
+
const linetypeTable = database.getLinetypeTable();
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Entity Creation
|
|
107
|
+
```typescript
|
|
108
|
+
import { AcDbLine, AcDbCircle, AcGePoint3d } from '@mlightcad/data-model';
|
|
109
|
+
|
|
110
|
+
// Create a line entity
|
|
111
|
+
const startPoint = new AcGePoint3d(0, 0, 0);
|
|
112
|
+
const endPoint = new AcGePoint3d(10, 10, 0);
|
|
113
|
+
const line = new AcDbLine(startPoint, endPoint);
|
|
114
|
+
|
|
115
|
+
// Create a circle entity
|
|
116
|
+
const center = new AcGePoint3d(0, 0, 0);
|
|
117
|
+
const radius = 5;
|
|
118
|
+
const circle = new AcDbCircle(center, radius);
|
|
119
|
+
|
|
120
|
+
// Set entity properties
|
|
121
|
+
line.setColor(1); // Red
|
|
122
|
+
line.setLayer('0');
|
|
123
|
+
circle.setLinetype('CONTINUOUS');
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Layer Management
|
|
127
|
+
```typescript
|
|
128
|
+
import { AcDbLayerTableRecord } from '@mlightcad/data-model';
|
|
129
|
+
|
|
130
|
+
// Create a new layer
|
|
131
|
+
const layerRecord = new AcDbLayerTableRecord();
|
|
132
|
+
layerRecord.setName('MyLayer');
|
|
133
|
+
layerRecord.setColor(2); // Yellow
|
|
134
|
+
layerRecord.setLinetype('DASHED');
|
|
135
|
+
|
|
136
|
+
// Add layer to database
|
|
137
|
+
const layerTable = database.getLayerTable();
|
|
138
|
+
layerTable.add(layerRecord);
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Block Operations
|
|
142
|
+
```typescript
|
|
143
|
+
import { AcDbBlockReference, AcGePoint3d } from '@mlightcad/data-model';
|
|
144
|
+
|
|
145
|
+
// Create a block reference
|
|
146
|
+
const insertionPoint = new AcGePoint3d(0, 0, 0);
|
|
147
|
+
const blockRef = new AcDbBlockReference(insertionPoint, 'MyBlock');
|
|
148
|
+
|
|
149
|
+
// Set block properties
|
|
150
|
+
blockRef.setScale(2.0);
|
|
151
|
+
blockRef.setRotation(Math.PI / 4);
|
|
152
|
+
|
|
153
|
+
// Add to model space
|
|
154
|
+
const modelSpace = database.getModelSpace();
|
|
155
|
+
modelSpace.appendEntity(blockRef);
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### File Conversion
|
|
159
|
+
```typescript
|
|
160
|
+
import { AcDbDatabaseConverterManager, AcDbFileType } from '@mlightcad/data-model';
|
|
161
|
+
|
|
162
|
+
// Get the DXF converter
|
|
163
|
+
const converter = AcDbDatabaseConverterManager.instance.get(AcDbFileType.DXF);
|
|
164
|
+
|
|
165
|
+
// Read a DXF file
|
|
166
|
+
const database = await converter.read('drawing.dxf');
|
|
167
|
+
|
|
168
|
+
// Register a custom converter
|
|
169
|
+
class MyDwgConverter extends AcDbDatabaseConverter {
|
|
170
|
+
async read(filePath: string): Promise<AcDbDatabase> {
|
|
171
|
+
// Custom DWG reading logic
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
AcDbDatabaseConverterManager.instance.register(AcDbFileType.DWG, new MyDwgConverter());
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Dimension Creation
|
|
179
|
+
```typescript
|
|
180
|
+
import { AcDbAlignedDimension, AcGePoint3d } from '@mlightcad/data-model';
|
|
181
|
+
|
|
182
|
+
// Create an aligned dimension
|
|
183
|
+
const defPoint1 = new AcGePoint3d(0, 0, 0);
|
|
184
|
+
const defPoint2 = new AcGePoint3d(10, 0, 0);
|
|
185
|
+
const textPosition = new AcGePoint3d(5, 5, 0);
|
|
186
|
+
|
|
187
|
+
const dimension = new AcDbAlignedDimension(defPoint1, defPoint2, textPosition);
|
|
188
|
+
dimension.setDimensionText('10.0');
|
|
189
|
+
dimension.setDimensionStyle('Standard');
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### Layout Management
|
|
193
|
+
```typescript
|
|
194
|
+
import { AcDbLayoutManager } from '@mlightcad/data-model';
|
|
195
|
+
|
|
196
|
+
// Get layout manager
|
|
197
|
+
const layoutManager = database.getLayoutManager();
|
|
198
|
+
|
|
199
|
+
// Get current layout
|
|
200
|
+
const currentLayout = layoutManager.getCurrentLayout();
|
|
201
|
+
|
|
202
|
+
// Switch to model space
|
|
203
|
+
layoutManager.setCurrentLayout('Model');
|
|
204
|
+
|
|
205
|
+
// Create a new layout
|
|
206
|
+
const newLayout = layoutManager.createLayout('MyLayout');
|
|
207
|
+
newLayout.setPlotType('Extents');
|
|
208
|
+
newLayout.setPlotCentered(true);
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Dependencies
|
|
212
|
+
|
|
213
|
+
- **@mlightcad/dxf-json**: For DXF file parsing
|
|
214
|
+
- **@mlightcad/common**: For common utilities (peer dependency)
|
|
215
|
+
- **@mlightcad/geometry-engine**: For geometric operations (peer dependency)
|
|
216
|
+
- **@mlightcad/graphic-interface**: For graphics interface (peer dependency)
|
|
217
|
+
- **lodash-es**: For utility functions (peer dependency)
|
|
218
|
+
- **uid**: For unique ID generation
|
|
219
|
+
|
|
220
|
+
## API Documentation
|
|
221
|
+
|
|
222
|
+
For detailed API documentation, visit the [RealDWG-Web documentation](https://mlight-lee.github.io/realdwg-web/).
|
|
223
|
+
|
|
224
|
+
## Contributing
|
|
225
|
+
|
|
226
|
+
This package is part of the RealDWG-Web monorepo. Please refer to the main project README for contribution guidelines.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlightcad/data-model",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"@types/lodash-es": "^4.17.12"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"
|
|
40
|
-
"@mlightcad/
|
|
41
|
-
"@mlightcad/
|
|
42
|
-
"
|
|
39
|
+
"lodash-es": "*",
|
|
40
|
+
"@mlightcad/common": "1.0.2",
|
|
41
|
+
"@mlightcad/geometry-engine": "1.0.2",
|
|
42
|
+
"@mlightcad/graphic-interface": "1.0.2"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"clean": "rimraf dist lib tsconfig.tsbuildinfo",
|