@mlightcad/graphic-interface 3.3.14 → 3.3.15
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/LICENSE +21 -21
- package/README.md +210 -210
- package/dist/graphic-interface.js +0 -45
- package/lib/AcGiRenderer.d.ts +0 -15
- package/lib/AcGiRenderer.d.ts.map +1 -1
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 mlight-lee
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 mlight-lee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,211 +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
|
-
|
|
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
211
|
This package is part of the RealDWG-Web monorepo. Please refer to the main project README for contribution guidelines.
|
|
@@ -4,64 +4,42 @@ class h {
|
|
|
4
4
|
constructor() {
|
|
5
5
|
this._number = -1, this._id = "", this._groupId = "", this._centerPoint = new t(), this._height = 0, this._width = 0, this._viewCenter = new t(), this._viewHeight = 0;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
8
|
-
* The viewport ID number. If the viewport is inactive, -1 is returned.
|
|
9
|
-
*/
|
|
10
7
|
get number() {
|
|
11
8
|
return this._number;
|
|
12
9
|
}
|
|
13
10
|
set number(s) {
|
|
14
11
|
this._number = s;
|
|
15
12
|
}
|
|
16
|
-
/**
|
|
17
|
-
* The id of the viewport.
|
|
18
|
-
*/
|
|
19
13
|
get id() {
|
|
20
14
|
return this._id;
|
|
21
15
|
}
|
|
22
16
|
set id(s) {
|
|
23
17
|
this._id = s;
|
|
24
18
|
}
|
|
25
|
-
/**
|
|
26
|
-
* The id of the group which this viewport belongs to.
|
|
27
|
-
*/
|
|
28
19
|
get groupId() {
|
|
29
20
|
return this._groupId;
|
|
30
21
|
}
|
|
31
22
|
set groupId(s) {
|
|
32
23
|
this._groupId = s;
|
|
33
24
|
}
|
|
34
|
-
/**
|
|
35
|
-
* The center point of the viewport entity in WCS coordinates (within Paper Space).
|
|
36
|
-
*/
|
|
37
25
|
get centerPoint() {
|
|
38
26
|
return this._centerPoint;
|
|
39
27
|
}
|
|
40
28
|
set centerPoint(s) {
|
|
41
29
|
this._centerPoint.copy(s);
|
|
42
30
|
}
|
|
43
|
-
/**
|
|
44
|
-
* The height of the viewport entity's window in drawing units.
|
|
45
|
-
*/
|
|
46
31
|
get height() {
|
|
47
32
|
return this._height;
|
|
48
33
|
}
|
|
49
34
|
set height(s) {
|
|
50
35
|
this._height = s;
|
|
51
36
|
}
|
|
52
|
-
/**
|
|
53
|
-
* The width of the viewport entity's window in drawing units. This is the width in Paper Space
|
|
54
|
-
* of the viewport itself, not the width of the Model Space view within the viewport.
|
|
55
|
-
*/
|
|
56
37
|
get width() {
|
|
57
38
|
return this._width;
|
|
58
39
|
}
|
|
59
40
|
set width(s) {
|
|
60
41
|
this._width = s;
|
|
61
42
|
}
|
|
62
|
-
/**
|
|
63
|
-
* The bounding box (in world coordinate system coordinates) of the viewport.
|
|
64
|
-
*/
|
|
65
43
|
get box() {
|
|
66
44
|
const s = new I();
|
|
67
45
|
return s.setFromCenterAndSize(this.centerPoint, {
|
|
@@ -69,35 +47,21 @@ class h {
|
|
|
69
47
|
y: this.height
|
|
70
48
|
}), s;
|
|
71
49
|
}
|
|
72
|
-
/**
|
|
73
|
-
* The view center (in display coordinate system coordinates) of the view in the viewport.
|
|
74
|
-
*/
|
|
75
50
|
get viewCenter() {
|
|
76
51
|
return this._viewCenter;
|
|
77
52
|
}
|
|
78
53
|
set viewCenter(s) {
|
|
79
54
|
this._viewCenter.copy(s);
|
|
80
55
|
}
|
|
81
|
-
/**
|
|
82
|
-
* The height (in display coordinate system coordinates) of the Model Space view within the viewport.
|
|
83
|
-
* Zooming the view out within the viewport increases this value and zooming in decreases this value.
|
|
84
|
-
*/
|
|
85
56
|
get viewHeight() {
|
|
86
57
|
return this._viewHeight;
|
|
87
58
|
}
|
|
88
59
|
set viewHeight(s) {
|
|
89
60
|
this._viewHeight = s;
|
|
90
61
|
}
|
|
91
|
-
/**
|
|
92
|
-
* The width (in display coordinate system coordinates) of the Model Space view within the viewport.
|
|
93
|
-
* This is one computed property based on 'viewHeight' and viewport ratio of width and height.
|
|
94
|
-
*/
|
|
95
62
|
get viewWidth() {
|
|
96
63
|
return this.viewHeight * (this.width / this.height);
|
|
97
64
|
}
|
|
98
|
-
/**
|
|
99
|
-
* The bounding box (in display coordinate system coordinates) of the Model Space view within the viewport.
|
|
100
|
-
*/
|
|
101
65
|
get viewBox() {
|
|
102
66
|
const s = new I();
|
|
103
67
|
return s.setFromCenterAndSize(this.viewCenter, {
|
|
@@ -105,19 +69,10 @@ class h {
|
|
|
105
69
|
y: this.viewHeight
|
|
106
70
|
}), s;
|
|
107
71
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Clone this viewport
|
|
110
|
-
* @returns Return the cloned instance of this viewport
|
|
111
|
-
*/
|
|
112
72
|
clone() {
|
|
113
73
|
const s = new h();
|
|
114
74
|
return s.id = this.id, s.groupId = this.groupId, s.number = this.number, s.centerPoint.copy(this.centerPoint), s.height = this.height, s.width = this.width, s.viewCenter.copy(this.viewCenter), s.viewHeight = this.viewHeight, s;
|
|
115
75
|
}
|
|
116
|
-
/**
|
|
117
|
-
* Copy the property values of the passed viewport to this viewport.
|
|
118
|
-
* @param viewport Input one viewport instance
|
|
119
|
-
* @returns Return this viewport
|
|
120
|
-
*/
|
|
121
76
|
copy(s) {
|
|
122
77
|
return this.id = s.id, this.groupId = s.groupId, this.number = s.number, this.centerPoint.copy(s.centerPoint), this.height = s.height, this.width = s.width, this.viewCenter.copy(s.viewCenter), this.viewHeight = s.viewHeight, this;
|
|
123
78
|
}
|
package/lib/AcGiRenderer.d.ts
CHANGED
|
@@ -11,21 +11,6 @@ import { AcGiMTextData, AcGiTextStyle } from './AcGiTextStyle';
|
|
|
11
11
|
*/
|
|
12
12
|
export type AcGiFontMapping = Record<string, string>;
|
|
13
13
|
export interface AcGiRenderer<T extends AcGiEntity = AcGiEntity> {
|
|
14
|
-
/**
|
|
15
|
-
* JavaScript (and WebGL) use 64‑bit floating point numbers for CPU-side calculations,
|
|
16
|
-
* but GPU shaders typically use 32‑bit floats. A 32-bit float has ~7.2 decimal digits
|
|
17
|
-
* of precision. If passing 64-bit floating vertices data to GPU directly, it will
|
|
18
|
-
* destroy number preciesion.
|
|
19
|
-
*
|
|
20
|
-
* So we adopt a simpler but effective version of the "origin-shift" idea. Recompute
|
|
21
|
-
* geometry using re-centered coordinates and apply offset to its position. The base
|
|
22
|
-
* point is extractly offset value.
|
|
23
|
-
*
|
|
24
|
-
* Get the rendering base point.
|
|
25
|
-
* @returns Return the rendering base point.
|
|
26
|
-
*/
|
|
27
|
-
get basePoint(): AcGePoint3d | undefined;
|
|
28
|
-
set basePoint(value: AcGePoint3d | undefined);
|
|
29
14
|
/**
|
|
30
15
|
* The entity traits object gives the user control of, and access to, the attribute
|
|
31
16
|
* (color, layer, linetype, etc.) settings of the current geometry.
|
|
@@ -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;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,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,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,CAAC,SAAS,UAAU,GAAG,UAAU;IAC7D
|
|
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,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAC3D,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,CAAC,SAAS,UAAU,GAAG,UAAU;IAC7D;;;OAGG;IACH,IAAI,eAAe,IAAI,mBAAmB,CAAA;IAE1C;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,CAAC,EAAE,GAAG,CAAC,CAAA;IAEvB;;;;;OAKG;IACH,KAAK,CAAC,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,cAAc,GAAG,CAAC,CAAA;IAEnD;;;;OAIG;IACH,WAAW,CAAC,GAAG,EAAE,aAAa,GAAG,CAAC,CAAA;IAElC;;;;OAIG;IACH,aAAa,CAAC,UAAU,EAAE,gBAAgB,GAAG,CAAC,CAAA;IAE9C;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,eAAe,EAAE,GAAG,CAAC,CAAA;IAEnC;;;;;;;;;OASG;IACH,YAAY,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,GAAG,CAAC,CAAA;IAE5E;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,CAAC,CAAA;IAEzB;;;;;;;;OAQG;IACH,KAAK,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,CAAC,CAAA;IAErE;;;;;OAKG;IACH,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,cAAc,GAAG,CAAC,CAAA;IAE3C;;;OAGG;IACH,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAAA;CAC/C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mlightcad/graphic-interface",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.15",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"require": "./dist/graphic-interface.umd.cjs"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@mlightcad/common": "1.4.
|
|
36
|
-
"@mlightcad/geometry-engine": "3.2.
|
|
35
|
+
"@mlightcad/common": "1.4.15",
|
|
36
|
+
"@mlightcad/geometry-engine": "3.2.15"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"clean": "rimraf dist lib tsconfig.tsbuildinfo",
|