@jscad/dxf-deserializer 2.3.27 → 3.0.1-alpha.0
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/CHANGELOG.md +14 -201
- package/LICENSE +1 -1
- package/README.md +3 -1
- package/dist/jscad-dxf-deserializer.es.js +7 -0
- package/dist/jscad-dxf-deserializer.min.js +7 -0
- package/package.json +21 -11
- package/rollup.config.js +27 -0
- package/src/DxfReader.js +241 -0
- package/{autocad.js → src/autocad.js} +4 -17
- package/{colorindex2014.js → src/colorindex2014.js} +1 -3
- package/{colorindex2017.js → src/colorindex2017.js} +1 -3
- package/{helpers.js → src/helpers.js} +4 -19
- package/{index.js → src/index.js} +69 -77
- package/{instantiate.js → src/instantiate.js} +54 -67
- package/{translate.js → src/translate.js} +50 -70
- package/tests/test-2d-entities.js +39 -38
- package/tests/test-2d-translation.js +17 -17
- package/tests/test-3d-entities.js +18 -18
- package/tests/test-3d-translation.js +6 -6
- package/tests/test-DxfReader.js +8 -7
- package/tests/test-dxf-versions.js +12 -11
- package/tests/test-dxf.js +6 -5
- package/DxfReader.js +0 -250
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
## License
|
|
1
|
+
import { poly3, vec2, vec3 } from '@jscad/modeling'
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
import { instantiatePolygon, instantiateVector } from './instantiate.js'
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
const { maths, geometries } = require('@jscad/modeling')
|
|
10
|
-
|
|
11
|
-
const { instantiatePolygon, instantiateVector } = require('./instantiate')
|
|
12
|
-
|
|
13
|
-
const { findLayer, getColor, getColorNumber } = require('./helpers')
|
|
5
|
+
import { findLayer, getColor, getColorNumber } from './helpers.js'
|
|
14
6
|
|
|
15
7
|
//
|
|
16
8
|
// translate the give 2D vector to JSCAD script
|
|
@@ -32,7 +24,7 @@ const translateVector3D = (vector) => {
|
|
|
32
24
|
// translate the given polygon into JSCAD script
|
|
33
25
|
//
|
|
34
26
|
const translatePolygon = (polygon) => {
|
|
35
|
-
const vertices =
|
|
27
|
+
const vertices = poly3.toVertices(polygon)
|
|
36
28
|
let script = 'createPolygon(['
|
|
37
29
|
vertices.forEach((vertice) => {
|
|
38
30
|
script += `[${translateVector3D(vertice)}],`
|
|
@@ -64,16 +56,16 @@ const translateLine = (obj, layers, options) => {
|
|
|
64
56
|
|
|
65
57
|
let script = ''
|
|
66
58
|
if (!obj.pptz || (obj.pptz === obj.sptz && obj.pptz === 0)) {
|
|
67
|
-
const p1 =
|
|
68
|
-
const p2 =
|
|
69
|
-
script = ` let ${name} =
|
|
59
|
+
const p1 = vec2.fromValues(obj.pptx, obj.ppty)
|
|
60
|
+
const p2 = vec2.fromValues(obj.sptx, obj.spty)
|
|
61
|
+
script = ` let ${name} = line([[${translateVector2D(p1)}],[${translateVector2D(p2)}]])\n`
|
|
70
62
|
} else {
|
|
71
|
-
const p1 =
|
|
72
|
-
const p2 =
|
|
73
|
-
script = ` let ${name} =
|
|
63
|
+
const p1 = vec3.fromValues(obj.pptx, obj.ppty, obj.pptz)
|
|
64
|
+
const p2 = vec3.fromValues(obj.sptx, obj.spty, obj.sptz)
|
|
65
|
+
script = ` let ${name} = line([[${translateVector3D(p1)}],[${translateVector3D(p2)}]])\n`
|
|
74
66
|
}
|
|
75
67
|
if (color) {
|
|
76
|
-
script += ` ${name} =
|
|
68
|
+
script += ` ${name} = colorize([${color[0]}, ${color[1]}, ${color[2]}, 1], ${name})\n`
|
|
77
69
|
}
|
|
78
70
|
obj.script = script
|
|
79
71
|
addToLayer(obj, layers)
|
|
@@ -86,21 +78,21 @@ const translateSection = (name, x1, y1, bulg, px, py) => {
|
|
|
86
78
|
// console.log('translateSection',x1,y1,bulg,px,py)
|
|
87
79
|
if (bulg === 0) {
|
|
88
80
|
// add straight line to the end of the path
|
|
89
|
-
return `
|
|
81
|
+
return `path2.appendPoints([[${x1},${y1}]], ${name})
|
|
90
82
|
`
|
|
91
83
|
}
|
|
92
84
|
|
|
93
85
|
// add arc to the end of the path
|
|
94
|
-
const prev =
|
|
95
|
-
const curr =
|
|
96
|
-
const u =
|
|
86
|
+
const prev = vec2.fromValues(px, py)
|
|
87
|
+
const curr = vec2.fromValues(x1, y1)
|
|
88
|
+
const u = vec2.distance(prev, curr)
|
|
97
89
|
const r = u * ((1 + Math.pow(bulg, 2)) / (4 * bulg))
|
|
98
90
|
const clockwise = (bulg < 0)
|
|
99
91
|
const large = false // FIXME how to determine?
|
|
100
92
|
const d = Math.atan(bulg) * 4
|
|
101
93
|
// FIXME need to determine segments from object/layer/variables
|
|
102
94
|
const res = 16
|
|
103
|
-
return `
|
|
95
|
+
return `path2.appendArc({endpoint: [${x1},${y1}],radius: [${r},${r}],xaxisrotation: ${d},clockwise: ${clockwise},large: ${large},segments: ${res}}, ${name})
|
|
104
96
|
`
|
|
105
97
|
}
|
|
106
98
|
|
|
@@ -122,11 +114,11 @@ const translatePath2D = (obj, layers, options) => {
|
|
|
122
114
|
const color = getColor(cn, options.colorindex)
|
|
123
115
|
|
|
124
116
|
// translation
|
|
125
|
-
let script = ` let ${name} =
|
|
117
|
+
let script = ` let ${name} = path2.create()\n`
|
|
126
118
|
const isclosed = ((flags & closed) === closed)
|
|
127
119
|
if (vlen === pptxs.length && vlen === pptys.length && vlen === bulgs.length) {
|
|
128
120
|
// add initial point
|
|
129
|
-
script += ` ${name} =
|
|
121
|
+
script += ` ${name} = path2.appendPoints([[${pptxs[0]}, ${pptys[0]}]], ${name})\n`
|
|
130
122
|
// add sections
|
|
131
123
|
for (let i = 0; i < pptxs.length; i++) {
|
|
132
124
|
const j = (i + 1) % pptxs.length
|
|
@@ -149,12 +141,12 @@ const translatePath2D = (obj, layers, options) => {
|
|
|
149
141
|
return
|
|
150
142
|
}
|
|
151
143
|
if (isclosed) {
|
|
152
|
-
script += ` ${name} =
|
|
144
|
+
script += ` ${name} = path2.close(${name})\n`
|
|
153
145
|
} else {
|
|
154
146
|
script += '\n'
|
|
155
147
|
}
|
|
156
148
|
if (color) {
|
|
157
|
-
script += ` ${name} =
|
|
149
|
+
script += ` ${name} = colorize([${color[0]}, ${color[1]}, ${color[2]}, 1], ${name})\n`
|
|
158
150
|
}
|
|
159
151
|
obj.script = script
|
|
160
152
|
addToLayer(obj, layers)
|
|
@@ -186,18 +178,18 @@ const translateArc = (obj, layers, options) => {
|
|
|
186
178
|
|
|
187
179
|
// convert to 2D object
|
|
188
180
|
if (lthk === 0.0) {
|
|
189
|
-
let script = ` let ${name} =
|
|
181
|
+
let script = ` let ${name} = arc({center: [${pptx}, ${ppty}], radius: ${swid}, startAngle: ${ang0}, endAngle: ${ang1}, segements: ${res}})\n`
|
|
190
182
|
if (color) {
|
|
191
|
-
script += ` ${name} =
|
|
183
|
+
script += ` ${name} = colorize([${color[0]}, ${color[1]}, ${color[2]}, 1], ${name})\n`
|
|
192
184
|
}
|
|
193
185
|
obj.script = script
|
|
194
186
|
addToLayer(obj, layers)
|
|
195
187
|
return
|
|
196
188
|
}
|
|
197
189
|
// FIXME how to represent 3D arc?
|
|
198
|
-
let script = ` let ${name} =
|
|
190
|
+
let script = ` let ${name} = arc({center: [${pptx}, ${ppty}], radius: ${swid}, startAngle: ${ang0}, endAngle: ${ang1}, segements: ${res}})\n`
|
|
199
191
|
if (color) {
|
|
200
|
-
script += ` ${name} =
|
|
192
|
+
script += ` ${name} = colorize([${color[0]}, ${color[1]}, ${color[2]}, 1], ${name})\n`
|
|
201
193
|
}
|
|
202
194
|
obj.script = script
|
|
203
195
|
addToLayer(obj, layers)
|
|
@@ -223,9 +215,9 @@ const translateCircle = (obj, layers, options) => {
|
|
|
223
215
|
|
|
224
216
|
// convert to 2D object
|
|
225
217
|
if (lthk === 0.0) {
|
|
226
|
-
let script = ` let ${name} =
|
|
218
|
+
let script = ` let ${name} = circle({center: [${pptx}, ${ppty}], radius: ${swid}, segments: ${res}})\n`
|
|
227
219
|
if (color) {
|
|
228
|
-
script += ` ${name} =
|
|
220
|
+
script += ` ${name} = colorize([${color[0]}, ${color[1]}, ${color[2]}, 1], ${name})\n`
|
|
229
221
|
}
|
|
230
222
|
obj.script = script
|
|
231
223
|
addToLayer(obj, layers)
|
|
@@ -233,9 +225,9 @@ const translateCircle = (obj, layers, options) => {
|
|
|
233
225
|
}
|
|
234
226
|
|
|
235
227
|
// convert to 3D object
|
|
236
|
-
let script = ` let ${name} =
|
|
228
|
+
let script = ` let ${name} = circle({center: [${pptx}, ${ppty}], radius: ${swid}, segments: ${res}}).extrude({offset: [0,0,${lthk}]}))\n`
|
|
237
229
|
if (color) {
|
|
238
|
-
script += ` ${name} =
|
|
230
|
+
script += ` ${name} = colorize([${color[0]}, ${color[1]}, ${color[2]}, 1], ${name})\n`
|
|
239
231
|
}
|
|
240
232
|
|
|
241
233
|
// FIXME need to use 210/220/230 for direction of rotation
|
|
@@ -265,19 +257,19 @@ const translateEllipse = (obj, layers, options) => {
|
|
|
265
257
|
|
|
266
258
|
// convert to 2D object
|
|
267
259
|
if (pptz === 0.0 && sptz === 0.0) {
|
|
268
|
-
const center =
|
|
269
|
-
const mjaxis =
|
|
270
|
-
const rx =
|
|
260
|
+
const center = vec2.fromValues(0, 0)
|
|
261
|
+
const mjaxis = vec2.fromValues(sptx, spty)
|
|
262
|
+
const rx = vec2.distance(center, mjaxis)
|
|
271
263
|
const ry = rx * swid
|
|
272
264
|
const angle = Math.atan2(spty, sptx) // * 180 / Math.PI
|
|
273
265
|
// FIXME add start and end angle when supported
|
|
274
266
|
|
|
275
|
-
let script = ` let ${name} =
|
|
276
|
-
let ${name}matrix =
|
|
277
|
-
${name} =
|
|
267
|
+
let script = ` let ${name} = ellipse({center: [0, 0, 0], radius: [${rx}, ${ry}], segments: ${res}})
|
|
268
|
+
let ${name}matrix = mat4.multiply(mat4.create(), mat4.fromTranslation(mat4.create(), [${pptx}, ${ppty}, 0]), mat4.fromZRotation(mat4.create(), ${angle}))
|
|
269
|
+
${name} = geom2.transform(${name}matrix, ${name})
|
|
278
270
|
`
|
|
279
271
|
if (color) {
|
|
280
|
-
script += ` ${name} =
|
|
272
|
+
script += ` ${name} = colorize([${color[0]}, ${color[1]}, ${color[2]}, 1], ${name})\n`
|
|
281
273
|
}
|
|
282
274
|
obj.script = script
|
|
283
275
|
addToLayer(obj, layers)
|
|
@@ -345,7 +337,7 @@ const translateMesh = (obj, layers, options) => {
|
|
|
345
337
|
let vi = 0
|
|
346
338
|
while (vi < face.length) {
|
|
347
339
|
const pi = face[vi]
|
|
348
|
-
const vector =
|
|
340
|
+
const vector = vec3.clone(points[pi])
|
|
349
341
|
vertices.push(vector)
|
|
350
342
|
vi++
|
|
351
343
|
}
|
|
@@ -354,7 +346,7 @@ const translateMesh = (obj, layers, options) => {
|
|
|
354
346
|
}
|
|
355
347
|
// FIXME how to correct bad normals?
|
|
356
348
|
|
|
357
|
-
const poly =
|
|
349
|
+
const poly = poly3.create(vertices)
|
|
358
350
|
if (color) poly.color = color
|
|
359
351
|
polygons.push(poly)
|
|
360
352
|
|
|
@@ -374,7 +366,7 @@ const translateMesh = (obj, layers, options) => {
|
|
|
374
366
|
script += ' ' + translatePolygon(polygon) + ',\n'
|
|
375
367
|
}
|
|
376
368
|
script += ` ]
|
|
377
|
-
let ${name} =
|
|
369
|
+
let ${name} = geom3.create(${name}_polygons)
|
|
378
370
|
`
|
|
379
371
|
obj.script = script
|
|
380
372
|
addToLayer(obj, layers)
|
|
@@ -497,8 +489,8 @@ const instantiateFacets = (meshM, meshN, parts, color, options) => {
|
|
|
497
489
|
if (options.dxf.angdir === 1) {
|
|
498
490
|
facet = facet.reverse()
|
|
499
491
|
}
|
|
500
|
-
const polygon =
|
|
501
|
-
const plane =
|
|
492
|
+
const polygon = poly3.create(facet)
|
|
493
|
+
const plane = poly3.plane(polygon)
|
|
502
494
|
if (Number.isFinite(plane[3])) {
|
|
503
495
|
if (color) polygon.color = color
|
|
504
496
|
facets.push(polygon)
|
|
@@ -556,7 +548,7 @@ const instantiatePolyFaces = (meshM, meshN, parts, color, options) => {
|
|
|
556
548
|
if (options.dxf.angdir === 1) {
|
|
557
549
|
vertices = vertices.reverse()
|
|
558
550
|
}
|
|
559
|
-
const polygon =
|
|
551
|
+
const polygon = poly3.create(vertices)
|
|
560
552
|
faces.push(polygon)
|
|
561
553
|
}
|
|
562
554
|
i++
|
|
@@ -640,7 +632,7 @@ const translateCurrent = (obj, layers, parts, options) => {
|
|
|
640
632
|
script += ' ' + translatePolygon(polygon) + ',\n'
|
|
641
633
|
}
|
|
642
634
|
script += ` ]
|
|
643
|
-
let ${name} =
|
|
635
|
+
let ${name} = geom3.create(${name}_polygons)
|
|
644
636
|
`
|
|
645
637
|
if (color) {
|
|
646
638
|
script += ` ${name}.color = [${color}]
|
|
@@ -657,7 +649,7 @@ const translateCurrent = (obj, layers, parts, options) => {
|
|
|
657
649
|
const translateLayer = (layer) => {
|
|
658
650
|
const name = layer.lnam || 'Unknown'
|
|
659
651
|
|
|
660
|
-
let script = `
|
|
652
|
+
let script = `const ${name} = () => {
|
|
661
653
|
`
|
|
662
654
|
for (const object of layer.objects) {
|
|
663
655
|
script += object.script
|
|
@@ -685,7 +677,7 @@ const saveVariable = (obj, options) => {
|
|
|
685
677
|
}
|
|
686
678
|
}
|
|
687
679
|
|
|
688
|
-
const translateAsciiDxf = (reader, options) => {
|
|
680
|
+
export const translateAsciiDxf = (reader, options) => {
|
|
689
681
|
// console.log('**************************************************')
|
|
690
682
|
// console.log(JSON.stringify(reader.objstack))
|
|
691
683
|
// console.log('**************************************************')
|
|
@@ -815,28 +807,23 @@ const translateAsciiDxf = (reader, options) => {
|
|
|
815
807
|
break
|
|
816
808
|
}
|
|
817
809
|
// accumlate polygons if necessary
|
|
818
|
-
if (
|
|
819
|
-
// console.log('##### push Polygon')
|
|
810
|
+
if (poly3.isA(p)) {
|
|
820
811
|
parts.push(p)
|
|
821
812
|
}
|
|
822
813
|
// accumlate vectors if necessary
|
|
823
814
|
if (p && 'vec' in p && p.vec.length === 3) {
|
|
824
|
-
// console.log('##### push vec3')
|
|
825
815
|
parts.push(p)
|
|
826
816
|
}
|
|
827
817
|
if (p && 'vec' in p && p.vec.length === 2) {
|
|
828
|
-
// console.log('##### push vec2')
|
|
829
818
|
parts.push(p)
|
|
830
819
|
}
|
|
831
820
|
}
|
|
832
821
|
// translate the last object if necessary
|
|
833
822
|
current = translateCurrent(current, layers, parts, options)
|
|
834
823
|
|
|
835
|
-
|
|
836
|
-
// console.log('**************************************************')
|
|
837
|
-
let script = `const {colors, geometries, maths, primitives, transforms} = require('@jscad/modeling')
|
|
824
|
+
let script = `import * from '@jscad/modeling'
|
|
838
825
|
|
|
839
|
-
const main = () => {
|
|
826
|
+
export const main = () => {
|
|
840
827
|
let layers = []
|
|
841
828
|
return layers.concat(`
|
|
842
829
|
|
|
@@ -849,10 +836,9 @@ const main = () => {
|
|
|
849
836
|
// add helper functions for polygons and lines
|
|
850
837
|
script +=
|
|
851
838
|
`
|
|
852
|
-
|
|
853
|
-
let polygon =
|
|
854
|
-
|
|
855
|
-
return polygon
|
|
839
|
+
const createPolygon = (listofpoints, color) => {
|
|
840
|
+
let polygon = poly3.create(listofpoints)
|
|
841
|
+
return colorize(color, polygon)
|
|
856
842
|
}
|
|
857
843
|
`
|
|
858
844
|
|
|
@@ -860,11 +846,5 @@ function createPolygon(listofpoints, color) {
|
|
|
860
846
|
script += translateLayer(layer)
|
|
861
847
|
})
|
|
862
848
|
|
|
863
|
-
script += 'module.exports = {main}\n'
|
|
864
|
-
|
|
865
|
-
// console.log(script)
|
|
866
|
-
// console.log('**************************************************')
|
|
867
849
|
return script
|
|
868
850
|
}
|
|
869
|
-
|
|
870
|
-
module.exports = translateAsciiDxf
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const test = require('ava')
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
import test from 'ava'
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
import { geom2, path2 } from '@jscad/modeling'
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
import { deserialize } from '../src/index.js'
|
|
9
|
+
|
|
10
|
+
const samplesPath = '../../../node_modules/@jscad/sample-files'
|
|
10
11
|
|
|
11
12
|
//
|
|
12
13
|
// Test suite for DXF deserialization (import)
|
|
@@ -21,7 +22,7 @@ test('ASCII DXF 2D Entities from JSCAD to Object Conversion', (t) => {
|
|
|
21
22
|
// expect one layer, containing 1 objects (path2)
|
|
22
23
|
t.true(Array.isArray(objs))
|
|
23
24
|
t.is(objs.length, 1)
|
|
24
|
-
t.true(
|
|
25
|
+
t.true(path2.isA(objs[0]))
|
|
25
26
|
t.true(objs[0].isClosed)
|
|
26
27
|
|
|
27
28
|
dxfPath = path.resolve(samplesPath, 'dxf/jscad/circle10.dxf')
|
|
@@ -33,9 +34,9 @@ test('ASCII DXF 2D Entities from JSCAD to Object Conversion', (t) => {
|
|
|
33
34
|
// expect one layer, containing 1 objects (path2)
|
|
34
35
|
t.true(Array.isArray(objs))
|
|
35
36
|
t.is(objs.length, 1)
|
|
36
|
-
t.true(
|
|
37
|
+
t.true(path2.isA(objs[0]))
|
|
37
38
|
t.true(objs[0].isClosed)
|
|
38
|
-
t.is(
|
|
39
|
+
t.is(path2.toPoints(objs[0]).length, 32) // path
|
|
39
40
|
})
|
|
40
41
|
|
|
41
42
|
test('ASCII DXF 2D Lines from Autocad 2017 to Object Conversion', (t) => {
|
|
@@ -49,12 +50,12 @@ test('ASCII DXF 2D Lines from Autocad 2017 to Object Conversion', (t) => {
|
|
|
49
50
|
t.true(Array.isArray(objs))
|
|
50
51
|
t.is(objs.length, 23)
|
|
51
52
|
// NOTE: the extra objects are from the page layout
|
|
52
|
-
t.true(
|
|
53
|
-
t.is(
|
|
54
|
-
t.true(
|
|
55
|
-
t.is(
|
|
56
|
-
t.true(
|
|
57
|
-
t.is(
|
|
53
|
+
t.true(path2.isA(objs[20]))
|
|
54
|
+
t.is(path2.toPoints(objs[20]).length, 2) // line
|
|
55
|
+
t.true(path2.isA(objs[21]))
|
|
56
|
+
t.is(path2.toPoints(objs[21]).length, 2) // line
|
|
57
|
+
t.true(path2.isA(objs[22]))
|
|
58
|
+
t.is(path2.toPoints(objs[22]).length, 2) // line
|
|
58
59
|
})
|
|
59
60
|
|
|
60
61
|
test('ASCII DXF 2D Circles from Autocad 2017 to Object Conversion', (t) => {
|
|
@@ -68,11 +69,11 @@ test('ASCII DXF 2D Circles from Autocad 2017 to Object Conversion', (t) => {
|
|
|
68
69
|
t.true(Array.isArray(objs))
|
|
69
70
|
t.is(objs.length, 23)
|
|
70
71
|
// NOTE: the extra objects are from the page layout
|
|
71
|
-
t.true(
|
|
72
|
-
t.true(
|
|
73
|
-
t.is(
|
|
74
|
-
t.true(
|
|
75
|
-
t.is(
|
|
72
|
+
t.true(path2.isA(objs[20]))
|
|
73
|
+
t.true(geom2.isA(objs[21]))
|
|
74
|
+
t.is(geom2.toPoints(objs[21]).length, 16) // circle
|
|
75
|
+
t.true(geom2.isA(objs[22]))
|
|
76
|
+
t.is(geom2.toPoints(objs[22]).length, 16) // circle
|
|
76
77
|
})
|
|
77
78
|
|
|
78
79
|
test('ASCII DXF 2D Rectangles from Autocad 2017 to Object Conversion', (t) => {
|
|
@@ -87,14 +88,14 @@ test('ASCII DXF 2D Rectangles from Autocad 2017 to Object Conversion', (t) => {
|
|
|
87
88
|
t.is(objs.length, 23)
|
|
88
89
|
// NOTE: the extra objects are from the page layout
|
|
89
90
|
let obj = objs[20]
|
|
90
|
-
t.true(
|
|
91
|
-
t.is(
|
|
91
|
+
t.true(path2.isA(obj))
|
|
92
|
+
t.is(path2.toPoints(obj).length, 4) // rectangle
|
|
92
93
|
obj = objs[21]
|
|
93
|
-
t.true(
|
|
94
|
-
t.is(
|
|
94
|
+
t.true(path2.isA(obj))
|
|
95
|
+
t.is(path2.toPoints(obj).length, 4) // rectangle
|
|
95
96
|
obj = objs[22]
|
|
96
|
-
t.true(
|
|
97
|
-
t.is(
|
|
97
|
+
t.true(path2.isA(obj))
|
|
98
|
+
t.is(path2.toPoints(obj).length, 4) // rectangle
|
|
98
99
|
})
|
|
99
100
|
|
|
100
101
|
test('ASCII DXF 2D Donuts from Autocad 2017 to Object Conversion', (t) => {
|
|
@@ -108,12 +109,12 @@ test('ASCII DXF 2D Donuts from Autocad 2017 to Object Conversion', (t) => {
|
|
|
108
109
|
t.true(Array.isArray(objs))
|
|
109
110
|
t.is(objs.length, 23)
|
|
110
111
|
// NOTE: the extra ojbects are from the page layout
|
|
111
|
-
t.true(
|
|
112
|
-
t.is(
|
|
113
|
-
t.true(
|
|
114
|
-
t.is(
|
|
115
|
-
t.true(
|
|
116
|
-
t.is(
|
|
112
|
+
t.true(path2.isA(objs[20]))
|
|
113
|
+
t.is(path2.toPoints(objs[20]).length, 18) // line
|
|
114
|
+
t.true(path2.isA(objs[21]))
|
|
115
|
+
t.is(path2.toPoints(objs[21]).length, 18) // line
|
|
116
|
+
t.true(path2.isA(objs[22]))
|
|
117
|
+
t.is(path2.toPoints(objs[22]).length, 18) // arc
|
|
117
118
|
})
|
|
118
119
|
|
|
119
120
|
test('ASCII DXF 2D Ellipses from Autocad 2017 to Object Conversion', (t) => {
|
|
@@ -127,9 +128,9 @@ test('ASCII DXF 2D Ellipses from Autocad 2017 to Object Conversion', (t) => {
|
|
|
127
128
|
t.true(Array.isArray(objs))
|
|
128
129
|
t.is(objs.length, 23)
|
|
129
130
|
// NOTE: the extra ojbects are from the page layout
|
|
130
|
-
t.true(
|
|
131
|
-
t.true(
|
|
132
|
-
t.true(
|
|
131
|
+
t.true(geom2.isA(objs[20]))
|
|
132
|
+
t.true(geom2.isA(objs[21]))
|
|
133
|
+
t.true(geom2.isA(objs[22]))
|
|
133
134
|
})
|
|
134
135
|
|
|
135
136
|
test('ASCII DXF 2D Arcs from Autocad 2017 to Object Conversion', (t) => {
|
|
@@ -143,9 +144,9 @@ test('ASCII DXF 2D Arcs from Autocad 2017 to Object Conversion', (t) => {
|
|
|
143
144
|
t.true(Array.isArray(objs))
|
|
144
145
|
t.is(objs.length, 23)
|
|
145
146
|
// NOTE: the extra ojbects are from the page layout
|
|
146
|
-
t.true(
|
|
147
|
-
t.true(
|
|
148
|
-
t.true(
|
|
147
|
+
t.true(path2.isA(objs[20]))
|
|
148
|
+
t.true(path2.isA(objs[21]))
|
|
149
|
+
t.true(path2.isA(objs[22]))
|
|
149
150
|
})
|
|
150
151
|
|
|
151
152
|
// HATCH as what ?
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import test from 'ava'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { deserialize } from '../src/index.js'
|
|
4
4
|
|
|
5
5
|
//
|
|
6
6
|
// Test suite for DXF deserialization (import)
|
|
@@ -10,9 +10,9 @@ test('ASCII DXF 2D Entities translated to JSCAD Scripts', (t) => {
|
|
|
10
10
|
const dxf1 = ''
|
|
11
11
|
const src1 = deserialize({ filename: 'dxf1 test', output: 'script' }, dxf1)
|
|
12
12
|
const ss1 = src1.split('\n')
|
|
13
|
-
t.is(ss1.length,
|
|
13
|
+
t.is(ss1.length, 14)
|
|
14
14
|
t.true(src1.indexOf('main = ()') > 0)
|
|
15
|
-
t.true(src1.indexOf('createPolygon(') > 0)
|
|
15
|
+
t.true(src1.indexOf('createPolygon = (') > 0)
|
|
16
16
|
|
|
17
17
|
// DXF CIRCLE, translates to script with a 'circle' function
|
|
18
18
|
const dxf2 = `0
|
|
@@ -37,10 +37,10 @@ CIRCLE
|
|
|
37
37
|
ENDSEC`
|
|
38
38
|
const src2 = deserialize({ filename: 'dxf2 test', output: 'script' }, dxf2)
|
|
39
39
|
const ss2 = src2.split('\n')
|
|
40
|
-
t.is(ss2.length,
|
|
40
|
+
t.is(ss2.length, 19)
|
|
41
41
|
t.true(src2.indexOf('main = ()') > 0)
|
|
42
42
|
t.true(src2.indexOf('circle(') > 0)
|
|
43
|
-
t.true(src2.indexOf('
|
|
43
|
+
t.true(src2.indexOf('colorize(') > 0)
|
|
44
44
|
|
|
45
45
|
// DXF LINE, translates to script with a 'line' created from points
|
|
46
46
|
const dxf3 = `0
|
|
@@ -65,7 +65,7 @@ LINE
|
|
|
65
65
|
ENDSEC`
|
|
66
66
|
const src3 = deserialize({ filename: 'dxf3-test', output: 'script' }, dxf3)
|
|
67
67
|
const ss3 = src3.split('\n')
|
|
68
|
-
t.is(ss3.length,
|
|
68
|
+
t.is(ss3.length, 18)
|
|
69
69
|
t.true(src3.indexOf('main = ()') > 0)
|
|
70
70
|
t.true(src3.indexOf('line(') > 0)
|
|
71
71
|
|
|
@@ -102,7 +102,7 @@ AcDbArc
|
|
|
102
102
|
ENDSEC`
|
|
103
103
|
const src4 = deserialize({ filename: 'dxf4-test', output: 'script' }, dxf4)
|
|
104
104
|
const ss4 = src4.split('\n')
|
|
105
|
-
t.is(ss4.length,
|
|
105
|
+
t.is(ss4.length, 18)
|
|
106
106
|
t.true(src4.indexOf('main = ()') > 0)
|
|
107
107
|
t.true(src4.indexOf('arc(') > 0)
|
|
108
108
|
|
|
@@ -139,7 +139,7 @@ LWPOLYLINE
|
|
|
139
139
|
ENDSEC`
|
|
140
140
|
const src5 = deserialize({ filename: 'dxf5-test', output: 'script' }, dxf5)
|
|
141
141
|
const ss5 = src5.split('\n')
|
|
142
|
-
t.is(ss5.length,
|
|
142
|
+
t.is(ss5.length, 23)
|
|
143
143
|
t.true(src5.indexOf('main = ()') > 0)
|
|
144
144
|
t.true(src5.indexOf('path2.create(') > 0)
|
|
145
145
|
t.true(src5.indexOf('path2.appendPoints(') > 0)
|
|
@@ -186,13 +186,13 @@ LWPOLYLINE
|
|
|
186
186
|
ENDSEC`
|
|
187
187
|
const src6 = deserialize({ filename: 'dxf6-test', output: 'script' }, dxf6)
|
|
188
188
|
const ss6 = src6.split('\n')
|
|
189
|
-
t.is(ss6.length,
|
|
189
|
+
t.is(ss6.length, 24)
|
|
190
190
|
t.true(src6.indexOf('main = ()') > 0)
|
|
191
191
|
t.true(src6.indexOf('path2.create(') > 0)
|
|
192
192
|
t.true(src6.indexOf('path2.appendPoints(') > 0)
|
|
193
193
|
t.true(src6.indexOf('path2.appendArc(') > 0)
|
|
194
194
|
t.true(src6.indexOf('path2.close(') > 0)
|
|
195
|
-
t.true(src6.indexOf('
|
|
195
|
+
t.true(src6.indexOf('poly3.create(') > 0)
|
|
196
196
|
|
|
197
197
|
// DXF ELLIPSE, translates to script with a 'ellipse' function
|
|
198
198
|
const dxf7 = `0
|
|
@@ -231,7 +231,7 @@ ELLIPSE
|
|
|
231
231
|
ENDSEC`
|
|
232
232
|
const src7 = deserialize({ filename: 'dxf7-test', output: 'script' }, dxf7)
|
|
233
233
|
const ss7 = src7.split('\n')
|
|
234
|
-
t.is(ss7.length,
|
|
234
|
+
t.is(ss7.length, 20)
|
|
235
235
|
t.true(src7.indexOf('main = ()') > 0)
|
|
236
236
|
t.true(src7.indexOf('ellipse(') > 0)
|
|
237
237
|
})
|
|
@@ -290,7 +290,7 @@ SEQEND
|
|
|
290
290
|
ENDSEC`
|
|
291
291
|
const src1 = deserialize({ filename: 'dxf1-test', output: 'script' }, dxf1)
|
|
292
292
|
const ss1 = src1.split('\n')
|
|
293
|
-
t.is(ss1.length,
|
|
293
|
+
t.is(ss1.length, 21)
|
|
294
294
|
t.true(src1.indexOf('path2.create(') > 0)
|
|
295
295
|
t.true(src1.indexOf('appendPoints(') > 0)
|
|
296
296
|
|
|
@@ -337,7 +337,7 @@ SEQEND
|
|
|
337
337
|
ENDSEC`
|
|
338
338
|
const src2 = deserialize({ filename: 'dxf2-test', output: 'script' }, dxf2)
|
|
339
339
|
const ss2 = src2.split('\n')
|
|
340
|
-
t.is(ss2.length,
|
|
340
|
+
t.is(ss2.length, 22)
|
|
341
341
|
t.true(src2.indexOf('path2.create(') > 0)
|
|
342
342
|
t.true(src2.indexOf('appendPoints(') > 0)
|
|
343
343
|
t.true(src2.indexOf('appendArc(') > 0)
|
|
@@ -389,8 +389,8 @@ SEQEND
|
|
|
389
389
|
ENDSEC`
|
|
390
390
|
const src3 = deserialize({ filename: 'dxf3-test', output: 'script' }, dxf3)
|
|
391
391
|
const ss3 = src3.split('\n')
|
|
392
|
-
t.is(ss3.length,
|
|
393
|
-
t.true(src3.indexOf('
|
|
394
|
-
t.true(src3.indexOf('
|
|
392
|
+
t.is(ss3.length, 21)
|
|
393
|
+
t.true(src3.indexOf('const layer0 = (') > 0)
|
|
394
|
+
t.true(src3.indexOf('const layer1 = (') > 0)
|
|
395
395
|
t.true(src3.indexOf('circle(') > 0)
|
|
396
396
|
})
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import test from 'ava'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import { geom3, path2 } from '@jscad/modeling'
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
import { deserialize } from '../src/index.js'
|
|
8
8
|
|
|
9
|
-
const samplesPath =
|
|
9
|
+
const samplesPath = '../../../node_modules/@jscad/sample-files'
|
|
10
10
|
|
|
11
11
|
//
|
|
12
12
|
// Test suite for DXF deserialization (import)
|
|
@@ -21,7 +21,7 @@ test('ASCII DXF from Bourke 3D Entities to Object Conversion', (t) => {
|
|
|
21
21
|
// expect one layer, containing 2 objects (geom3 and line3)
|
|
22
22
|
t.true(Array.isArray(objs))
|
|
23
23
|
t.is(objs.length, 2)
|
|
24
|
-
t.true(
|
|
24
|
+
t.true(geom3.isA(objs[0]))
|
|
25
25
|
// t.true(objs[1] instanceof CSG.Line3D)
|
|
26
26
|
})
|
|
27
27
|
|
|
@@ -37,7 +37,7 @@ test('ASCII DXF from JSCAD 3D Shapes to Object Conversion', (t) => {
|
|
|
37
37
|
t.true(Array.isArray(objs))
|
|
38
38
|
t.is(objs.length, 1)
|
|
39
39
|
let csg = objs[0]
|
|
40
|
-
t.true(
|
|
40
|
+
t.true(geom3.isA(csg))
|
|
41
41
|
|
|
42
42
|
// instantiate from a simple shape
|
|
43
43
|
dxfPath = path.resolve(samplesPath, 'dxf/jscad/cube.dxf')
|
|
@@ -50,7 +50,7 @@ test('ASCII DXF from JSCAD 3D Shapes to Object Conversion', (t) => {
|
|
|
50
50
|
t.true(Array.isArray(objs))
|
|
51
51
|
t.is(objs.length, 1)
|
|
52
52
|
csg = objs[0]
|
|
53
|
-
t.true(
|
|
53
|
+
t.true(geom3.isA(csg))
|
|
54
54
|
|
|
55
55
|
// instantiate from a simple shape
|
|
56
56
|
dxfPath = path.resolve(samplesPath, 'dxf/jscad/sphere.dxf')
|
|
@@ -63,7 +63,7 @@ test('ASCII DXF from JSCAD 3D Shapes to Object Conversion', (t) => {
|
|
|
63
63
|
t.true(Array.isArray(objs))
|
|
64
64
|
t.is(objs.length, 1)
|
|
65
65
|
csg = objs[0]
|
|
66
|
-
t.true(
|
|
66
|
+
t.true(geom3.isA(csg))
|
|
67
67
|
|
|
68
68
|
// instantiate from a simple shape
|
|
69
69
|
dxfPath = path.resolve(samplesPath, 'dxf/jscad/cylinder.dxf')
|
|
@@ -76,7 +76,7 @@ test('ASCII DXF from JSCAD 3D Shapes to Object Conversion', (t) => {
|
|
|
76
76
|
t.true(Array.isArray(objs))
|
|
77
77
|
t.is(objs.length, 1)
|
|
78
78
|
csg = objs[0]
|
|
79
|
-
t.true(
|
|
79
|
+
t.true(geom3.isA(csg))
|
|
80
80
|
})
|
|
81
81
|
|
|
82
82
|
test('ASCII DXF from Autocad2017 3D Lines to Object Conversion', (t) => {
|
|
@@ -91,11 +91,11 @@ test('ASCII DXF from Autocad2017 3D Lines to Object Conversion', (t) => {
|
|
|
91
91
|
t.is(objs.length, 3)
|
|
92
92
|
|
|
93
93
|
let obj = objs[0]
|
|
94
|
-
t.true(
|
|
94
|
+
t.true(path2.isA(obj))
|
|
95
95
|
obj = objs[1]
|
|
96
|
-
t.true(
|
|
96
|
+
t.true(path2.isA(obj))
|
|
97
97
|
obj = objs[2]
|
|
98
|
-
t.true(
|
|
98
|
+
t.true(path2.isA(obj)) // FYI the DXF is incorrect
|
|
99
99
|
})
|
|
100
100
|
|
|
101
101
|
test('ASCII DXF from Autocad2017 3D Boxes to Object Conversion', (t) => {
|
|
@@ -134,8 +134,8 @@ test('ASCII DXF from exdxf 3D Mesh to Object Conversion', (t) => {
|
|
|
134
134
|
t.is(objs.length, 5)
|
|
135
135
|
|
|
136
136
|
const obj4 = objs[4]
|
|
137
|
-
t.true(
|
|
138
|
-
t.is(
|
|
137
|
+
t.true(geom3.isA(obj4))
|
|
138
|
+
t.is(geom3.toPolygons(obj4).length, 6)
|
|
139
139
|
})
|
|
140
140
|
|
|
141
141
|
test('ASCII DXF from Autocad2017 3D Mesh to Object Conversion', (t) => {
|
|
@@ -150,8 +150,8 @@ test('ASCII DXF from Autocad2017 3D Mesh to Object Conversion', (t) => {
|
|
|
150
150
|
t.is(objs.length, 2)
|
|
151
151
|
|
|
152
152
|
const obj0 = objs[0]
|
|
153
|
-
t.is(
|
|
153
|
+
t.is(geom3.toPolygons(obj0).length, 54)
|
|
154
154
|
|
|
155
155
|
const obj1 = objs[1]
|
|
156
|
-
t.is(
|
|
156
|
+
t.is(geom3.toPolygons(obj1).length, 54)
|
|
157
157
|
})
|