@mlightcad/graphic-interface 1.0.0 → 1.0.2
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 +211 -0
- package/lib/AcGiRenderer.d.ts +1 -1
- package/lib/AcGiRenderer.d.ts.map +1 -1
- package/package.json +3 -2
package/README.md
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# @mlightcad/graphic-interface
|
|
2
|
+
|
|
3
|
+
The graphic-interface package provides the graphics interface for controlling how AutoCAD entities are displayed on screen. This package offers a simplified API compared to AutoCAD ObjectARX's AcGi classes, making it more developer-friendly while maintaining the core functionality needed for rendering CAD entities.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This package provides the graphics interface layer that bridges the gap between the data model and the rendering system. It handles the conversion of AutoCAD entities into drawable objects and provides customization options for how objects are displayed, including colors, layers, visibility, and various rendering styles.
|
|
8
|
+
|
|
9
|
+
## Key Features
|
|
10
|
+
|
|
11
|
+
- **Entity Rendering**: Convert AutoCAD entities to drawable objects
|
|
12
|
+
- **Style Customization**: Control colors, line styles, text styles, and point styles
|
|
13
|
+
- **View Management**: Handle different views and viewports
|
|
14
|
+
- **Arrow and Hatch Support**: Custom arrow types and hatch pattern rendering
|
|
15
|
+
- **Image Rendering**: Support for raster image display
|
|
16
|
+
- **Flexible Rendering**: Extensible rendering system for different output formats
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @mlightcad/graphic-interface
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Key Classes
|
|
25
|
+
|
|
26
|
+
### Core Rendering Classes
|
|
27
|
+
- **AcGiRenderer**: Main interface for rendering entities to drawable objects
|
|
28
|
+
- **AcGiEntity**: Base class for drawable objects that can be rendered
|
|
29
|
+
- **AcGiView**: Represents a view with camera and projection settings
|
|
30
|
+
- **AcGiViewport**: Manages viewport settings and clipping
|
|
31
|
+
|
|
32
|
+
### Style Classes
|
|
33
|
+
- **AcGiArrowType**: Defines different arrow types for dimensions and leaders
|
|
34
|
+
- **AcGiHatchStyle**: Controls hatch pattern rendering and appearance
|
|
35
|
+
- **AcGiImageStyle**: Manages raster image display properties
|
|
36
|
+
- **AcGiLineStyle**: Defines line styles including dash patterns and widths
|
|
37
|
+
- **AcGiPointStyle**: Controls point entity display appearance
|
|
38
|
+
- **AcGiTextStyle**: Manages text rendering properties and formatting
|
|
39
|
+
|
|
40
|
+
## Usage Examples
|
|
41
|
+
|
|
42
|
+
### Basic Entity Rendering
|
|
43
|
+
```typescript
|
|
44
|
+
import { AcGiRenderer, AcGiEntity } from '@mlightcad/graphic-interface';
|
|
45
|
+
import { AcDbLine, AcGePoint3d } from '@mlightcad/data-model';
|
|
46
|
+
|
|
47
|
+
// Create a renderer
|
|
48
|
+
const renderer = new AcGiRenderer();
|
|
49
|
+
|
|
50
|
+
// Create an entity
|
|
51
|
+
const startPoint = new AcGePoint3d(0, 0, 0);
|
|
52
|
+
const endPoint = new AcGePoint3d(10, 10, 0);
|
|
53
|
+
const line = new AcDbLine(startPoint, endPoint);
|
|
54
|
+
|
|
55
|
+
// Render the entity
|
|
56
|
+
const drawableEntity = renderer.renderEntity(line);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Style Configuration
|
|
60
|
+
```typescript
|
|
61
|
+
import {
|
|
62
|
+
AcGiLineStyle,
|
|
63
|
+
AcGiTextStyle,
|
|
64
|
+
AcGiPointStyle,
|
|
65
|
+
AcGiArrowType
|
|
66
|
+
} from '@mlightcad/graphic-interface';
|
|
67
|
+
|
|
68
|
+
// Configure line style
|
|
69
|
+
const lineStyle = new AcGiLineStyle();
|
|
70
|
+
lineStyle.setColor(1); // Red
|
|
71
|
+
lineStyle.setWidth(2.0);
|
|
72
|
+
lineStyle.setDashPattern([10, 5, 5, 5]); // Dashed line
|
|
73
|
+
|
|
74
|
+
// Configure text style
|
|
75
|
+
const textStyle = new AcGiTextStyle();
|
|
76
|
+
textStyle.setFont('Arial');
|
|
77
|
+
textStyle.setHeight(12);
|
|
78
|
+
textStyle.setColor(2); // Yellow
|
|
79
|
+
textStyle.setBold(true);
|
|
80
|
+
|
|
81
|
+
// Configure point style
|
|
82
|
+
const pointStyle = new AcGiPointStyle();
|
|
83
|
+
pointStyle.setSize(5);
|
|
84
|
+
pointStyle.setShape('Circle');
|
|
85
|
+
pointStyle.setColor(3); // Green
|
|
86
|
+
|
|
87
|
+
// Configure arrow style
|
|
88
|
+
const arrowStyle = new AcGiArrowType();
|
|
89
|
+
arrowStyle.setType('ClosedFilled');
|
|
90
|
+
arrowStyle.setSize(3);
|
|
91
|
+
arrowStyle.setColor(1); // Red
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### View and Viewport Management
|
|
95
|
+
```typescript
|
|
96
|
+
import { AcGiView, AcGiViewport, AcGePoint3d } from '@mlightcad/graphic-interface';
|
|
97
|
+
|
|
98
|
+
// Create a view
|
|
99
|
+
const view = new AcGiView();
|
|
100
|
+
view.setEyePoint(new AcGePoint3d(0, 0, 100));
|
|
101
|
+
view.setTargetPoint(new AcGePoint3d(0, 0, 0));
|
|
102
|
+
view.setUpVector(new AcGeVector3d(0, 1, 0));
|
|
103
|
+
|
|
104
|
+
// Create a viewport
|
|
105
|
+
const viewport = new AcGiViewport();
|
|
106
|
+
viewport.setView(view);
|
|
107
|
+
viewport.setWidth(800);
|
|
108
|
+
viewport.setHeight(600);
|
|
109
|
+
viewport.setZoom(1.0);
|
|
110
|
+
|
|
111
|
+
// Set viewport properties
|
|
112
|
+
viewport.setClippingEnabled(true);
|
|
113
|
+
viewport.setClippingBounds(0, 0, 100, 100);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Hatch Pattern Rendering
|
|
117
|
+
```typescript
|
|
118
|
+
import { AcGiHatchStyle } from '@mlightcad/graphic-interface';
|
|
119
|
+
|
|
120
|
+
// Configure hatch style
|
|
121
|
+
const hatchStyle = new AcGiHatchStyle();
|
|
122
|
+
hatchStyle.setPattern('ANSI31'); // Standard AutoCAD pattern
|
|
123
|
+
hatchStyle.setScale(1.0);
|
|
124
|
+
hatchStyle.setAngle(0);
|
|
125
|
+
hatchStyle.setColor(4); // Cyan
|
|
126
|
+
hatchStyle.setTransparency(0.5);
|
|
127
|
+
|
|
128
|
+
// Apply hatch to an entity
|
|
129
|
+
const hatchedEntity = renderer.renderEntityWithHatch(entity, hatchStyle);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Image Rendering
|
|
133
|
+
```typescript
|
|
134
|
+
import { AcGiImageStyle } from '@mlightcad/graphic-interface';
|
|
135
|
+
|
|
136
|
+
// Configure image style
|
|
137
|
+
const imageStyle = new AcGiImageStyle();
|
|
138
|
+
imageStyle.setBrightness(1.0);
|
|
139
|
+
imageStyle.setContrast(1.0);
|
|
140
|
+
imageStyle.setFade(0.0);
|
|
141
|
+
imageStyle.setTransparency(0.0);
|
|
142
|
+
imageStyle.setClippingEnabled(false);
|
|
143
|
+
|
|
144
|
+
// Render image with style
|
|
145
|
+
const imageEntity = renderer.renderImage(imagePath, imageStyle);
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Custom Rendering Pipeline
|
|
149
|
+
```typescript
|
|
150
|
+
import { AcGiRenderer, AcGiEntity } from '@mlightcad/graphic-interface';
|
|
151
|
+
|
|
152
|
+
// Create a custom renderer
|
|
153
|
+
class CustomRenderer extends AcGiRenderer {
|
|
154
|
+
renderEntity(entity: AcDbEntity): AcGiEntity {
|
|
155
|
+
// Custom rendering logic
|
|
156
|
+
const drawable = super.renderEntity(entity);
|
|
157
|
+
|
|
158
|
+
// Apply custom styling
|
|
159
|
+
if (entity.getLayer() === 'HIGHLIGHT') {
|
|
160
|
+
drawable.setHighlighted(true);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return drawable;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
renderToCanvas(canvas: HTMLCanvasElement, entities: AcGiEntity[]) {
|
|
167
|
+
const ctx = canvas.getContext('2d');
|
|
168
|
+
|
|
169
|
+
entities.forEach(entity => {
|
|
170
|
+
// Custom canvas rendering
|
|
171
|
+
this.renderEntityToCanvas(ctx, entity);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Use custom renderer
|
|
177
|
+
const customRenderer = new CustomRenderer();
|
|
178
|
+
const drawableEntities = entities.map(entity => customRenderer.renderEntity(entity));
|
|
179
|
+
customRenderer.renderToCanvas(canvas, drawableEntities);
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Batch Rendering
|
|
183
|
+
```typescript
|
|
184
|
+
import { AcGiRenderer } from '@mlightcad/graphic-interface';
|
|
185
|
+
|
|
186
|
+
// Batch render multiple entities
|
|
187
|
+
const renderer = new AcGiRenderer();
|
|
188
|
+
const entities = [line1, circle1, polyline1, text1];
|
|
189
|
+
|
|
190
|
+
// Render all entities with consistent styling
|
|
191
|
+
const drawableEntities = renderer.renderEntities(entities, {
|
|
192
|
+
defaultColor: 7, // White
|
|
193
|
+
defaultLayer: '0',
|
|
194
|
+
defaultLinetype: 'CONTINUOUS'
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Apply viewport transformations
|
|
198
|
+
viewport.applyTransformations(drawableEntities);
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Dependencies
|
|
202
|
+
|
|
203
|
+
- **@mlightcad/geometry-engine**: For geometric operations (peer dependency)
|
|
204
|
+
|
|
205
|
+
## API Documentation
|
|
206
|
+
|
|
207
|
+
For detailed API documentation, visit the [RealDWG-Web documentation](https://mlight-lee.github.io/realdwg-web/).
|
|
208
|
+
|
|
209
|
+
## Contributing
|
|
210
|
+
|
|
211
|
+
This package is part of the RealDWG-Web monorepo. Please refer to the main project README for contribution guidelines.
|
package/lib/AcGiRenderer.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AcGeArea2d, AcGeCircArc3d, AcGeEllipseArc3d, AcGePoint3d, AcGePoint3dLike } from '@mlightcad/geometry-engine';
|
|
2
|
-
import { AcGiPointStyle } from './AcGiPointStyle';
|
|
3
2
|
import { AcGiEntity } from './AcGiEntity';
|
|
4
3
|
import { AcGiHatchStyle } from './AcGiHatchStyle';
|
|
5
4
|
import { AcGiImageStyle } from './AcGiImageStyle';
|
|
6
5
|
import { AcGiLineStyle } from './AcGiLineStyle';
|
|
6
|
+
import { AcGiPointStyle } from './AcGiPointStyle';
|
|
7
7
|
import { AcGiMTextData, AcGiTextStyle } from './AcGiTextStyle';
|
|
8
8
|
/**
|
|
9
9
|
* Font mappings.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AcGiRenderer.d.ts","sourceRoot":"","sources":["../src/AcGiRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,eAAe,EAChB,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"AcGiRenderer.d.ts","sourceRoot":"","sources":["../src/AcGiRenderer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,eAAe,EAChB,MAAM,4BAA4B,CAAA;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE9D;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAEpD,MAAM,WAAW,YAAY,CAAC,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
@@ -27,7 +28,7 @@
|
|
|
27
28
|
"require": "./dist/graphic-interface.umd.cjs"
|
|
28
29
|
},
|
|
29
30
|
"peerDependencies": {
|
|
30
|
-
"@mlightcad/geometry-engine": "
|
|
31
|
+
"@mlightcad/geometry-engine": "1.0.2"
|
|
31
32
|
},
|
|
32
33
|
"scripts": {
|
|
33
34
|
"clean": "rimraf dist lib tsconfig.tsbuildinfo",
|