@linkiez/dxf-renew 5.3.1
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/.eslintignore +17 -0
- package/.eslintrc.json +61 -0
- package/.gitattributes +4 -0
- package/.github/instructions/project-en_US.instructions.md +352 -0
- package/.github/workflows/release.yml +110 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +1 -0
- package/.prettierignore +1 -0
- package/.prettierrc.json +6 -0
- package/.releaserc.json +76 -0
- package/.travis.yml +6 -0
- package/.yarn/install-state.gz +0 -0
- package/.yarnrc.yml +1 -0
- package/CHANGELOG.md +134 -0
- package/CONTRIBUTING.md +271 -0
- package/LICENSE +21 -0
- package/PLAN.md +517 -0
- package/README.md +306 -0
- package/build.mjs +66 -0
- package/commitlint.config.js +25 -0
- package/dist/dxf.js +7234 -0
- package/docs/CODE_PATTERNS.md +182 -0
- package/docs/DIMENSION_SUMMARY.md +248 -0
- package/docs/DIMENSION_SUMMARY.pt-BR.md +248 -0
- package/docs/IMPLEMENTED-2D-ENTITIES.md +54 -0
- package/docs/IMPLEMENTED-2D-ENTITIES.pt-BR.md +54 -0
- package/docs/TEXT-MTEXT-DIMENSION-SUPPORT.md +241 -0
- package/docs/TEXT-MTEXT-DIMENSION-SUPPORT.pt-BR.md +169 -0
- package/docs/autocad_2012_pdf_dxf-reference_enu.md +8272 -0
- package/examples/dxf.html +36 -0
- package/examples/example.es5.js +30 -0
- package/examples/example.es6.js +30 -0
- package/examples/text-dimension-viewer.html +133 -0
- package/lib/Helper.cjs +89 -0
- package/lib/Helper.cjs.map +7 -0
- package/lib/Helper.js +59 -0
- package/lib/Helper.js.map +7 -0
- package/lib/applyTransforms.cjs +59 -0
- package/lib/applyTransforms.cjs.map +7 -0
- package/lib/applyTransforms.js +39 -0
- package/lib/applyTransforms.js.map +7 -0
- package/lib/cli.cjs +53 -0
- package/lib/cli.cjs.map +7 -0
- package/lib/cli.js +29 -0
- package/lib/cli.js.map +7 -0
- package/lib/config.cjs +30 -0
- package/lib/config.cjs.map +7 -0
- package/lib/config.js +10 -0
- package/lib/config.js.map +7 -0
- package/lib/constants.cjs +39 -0
- package/lib/constants.cjs.map +7 -0
- package/lib/constants.js +15 -0
- package/lib/constants.js.map +7 -0
- package/lib/denormalise.cjs +148 -0
- package/lib/denormalise.cjs.map +7 -0
- package/lib/denormalise.js +118 -0
- package/lib/denormalise.js.map +7 -0
- package/lib/dimensionToSVG.cjs +307 -0
- package/lib/dimensionToSVG.cjs.map +7 -0
- package/lib/dimensionToSVG.js +273 -0
- package/lib/dimensionToSVG.js.map +7 -0
- package/lib/entityToPolyline.cjs +248 -0
- package/lib/entityToPolyline.cjs.map +7 -0
- package/lib/entityToPolyline.js +213 -0
- package/lib/entityToPolyline.js.map +7 -0
- package/lib/getRGBForEntity.cjs +53 -0
- package/lib/getRGBForEntity.cjs.map +7 -0
- package/lib/getRGBForEntity.js +23 -0
- package/lib/getRGBForEntity.js.map +7 -0
- package/lib/groupEntitiesByLayer.cjs +34 -0
- package/lib/groupEntitiesByLayer.cjs.map +7 -0
- package/lib/groupEntitiesByLayer.js +14 -0
- package/lib/groupEntitiesByLayer.js.map +7 -0
- package/lib/handlers/blocks.cjs +93 -0
- package/lib/handlers/blocks.cjs.map +7 -0
- package/lib/handlers/blocks.js +63 -0
- package/lib/handlers/blocks.js.map +7 -0
- package/lib/handlers/entities.cjs +118 -0
- package/lib/handlers/entities.cjs.map +7 -0
- package/lib/handlers/entities.js +88 -0
- package/lib/handlers/entities.js.map +7 -0
- package/lib/handlers/entity/arc.cjs +82 -0
- package/lib/handlers/entity/arc.cjs.map +7 -0
- package/lib/handlers/entity/arc.js +47 -0
- package/lib/handlers/entity/arc.js.map +7 -0
- package/lib/handlers/entity/attdef.cjs +318 -0
- package/lib/handlers/entity/attdef.cjs.map +7 -0
- package/lib/handlers/entity/attdef.js +282 -0
- package/lib/handlers/entity/attdef.js.map +7 -0
- package/lib/handlers/entity/attrib.cjs +52 -0
- package/lib/handlers/entity/attrib.cjs.map +7 -0
- package/lib/handlers/entity/attrib.js +27 -0
- package/lib/handlers/entity/attrib.js.map +7 -0
- package/lib/handlers/entity/circle.cjs +73 -0
- package/lib/handlers/entity/circle.cjs.map +7 -0
- package/lib/handlers/entity/circle.js +38 -0
- package/lib/handlers/entity/circle.js.map +7 -0
- package/lib/handlers/entity/common.cjs +83 -0
- package/lib/handlers/entity/common.cjs.map +7 -0
- package/lib/handlers/entity/common.js +63 -0
- package/lib/handlers/entity/common.js.map +7 -0
- package/lib/handlers/entity/dimension.cjs +203 -0
- package/lib/handlers/entity/dimension.cjs.map +7 -0
- package/lib/handlers/entity/dimension.js +168 -0
- package/lib/handlers/entity/dimension.js.map +7 -0
- package/lib/handlers/entity/ellipse.cjs +88 -0
- package/lib/handlers/entity/ellipse.cjs.map +7 -0
- package/lib/handlers/entity/ellipse.js +53 -0
- package/lib/handlers/entity/ellipse.js.map +7 -0
- package/lib/handlers/entity/hatch.cjs +470 -0
- package/lib/handlers/entity/hatch.cjs.map +7 -0
- package/lib/handlers/entity/hatch.js +435 -0
- package/lib/handlers/entity/hatch.js.map +7 -0
- package/lib/handlers/entity/insert.cjs +106 -0
- package/lib/handlers/entity/insert.cjs.map +7 -0
- package/lib/handlers/entity/insert.js +71 -0
- package/lib/handlers/entity/insert.js.map +7 -0
- package/lib/handlers/entity/line.cjs +84 -0
- package/lib/handlers/entity/line.cjs.map +7 -0
- package/lib/handlers/entity/line.js +49 -0
- package/lib/handlers/entity/line.js.map +7 -0
- package/lib/handlers/entity/lwpolyline.cjs +82 -0
- package/lib/handlers/entity/lwpolyline.cjs.map +7 -0
- package/lib/handlers/entity/lwpolyline.js +47 -0
- package/lib/handlers/entity/lwpolyline.js.map +7 -0
- package/lib/handlers/entity/mtext.cjs +121 -0
- package/lib/handlers/entity/mtext.cjs.map +7 -0
- package/lib/handlers/entity/mtext.js +85 -0
- package/lib/handlers/entity/mtext.js.map +7 -0
- package/lib/handlers/entity/ole2Frame.cjs +98 -0
- package/lib/handlers/entity/ole2Frame.cjs.map +7 -0
- package/lib/handlers/entity/ole2Frame.js +63 -0
- package/lib/handlers/entity/ole2Frame.js.map +7 -0
- package/lib/handlers/entity/point.cjs +73 -0
- package/lib/handlers/entity/point.cjs.map +7 -0
- package/lib/handlers/entity/point.js +38 -0
- package/lib/handlers/entity/point.js.map +7 -0
- package/lib/handlers/entity/polyline.cjs +70 -0
- package/lib/handlers/entity/polyline.cjs.map +7 -0
- package/lib/handlers/entity/polyline.js +35 -0
- package/lib/handlers/entity/polyline.js.map +7 -0
- package/lib/handlers/entity/solid.cjs +101 -0
- package/lib/handlers/entity/solid.cjs.map +7 -0
- package/lib/handlers/entity/solid.js +66 -0
- package/lib/handlers/entity/solid.js.map +7 -0
- package/lib/handlers/entity/spline.cjs +109 -0
- package/lib/handlers/entity/spline.cjs.map +7 -0
- package/lib/handlers/entity/spline.js +74 -0
- package/lib/handlers/entity/spline.js.map +7 -0
- package/lib/handlers/entity/text.cjs +85 -0
- package/lib/handlers/entity/text.cjs.map +7 -0
- package/lib/handlers/entity/text.js +49 -0
- package/lib/handlers/entity/text.js.map +7 -0
- package/lib/handlers/entity/threeDFace.cjs +98 -0
- package/lib/handlers/entity/threeDFace.cjs.map +7 -0
- package/lib/handlers/entity/threeDFace.js +63 -0
- package/lib/handlers/entity/threeDFace.js.map +7 -0
- package/lib/handlers/entity/vertex.cjs +78 -0
- package/lib/handlers/entity/vertex.cjs.map +7 -0
- package/lib/handlers/entity/vertex.js +53 -0
- package/lib/handlers/entity/vertex.js.map +7 -0
- package/lib/handlers/entity/viewport.cjs +153 -0
- package/lib/handlers/entity/viewport.cjs.map +7 -0
- package/lib/handlers/entity/viewport.js +118 -0
- package/lib/handlers/entity/viewport.js.map +7 -0
- package/lib/handlers/header.cjs +92 -0
- package/lib/handlers/header.cjs.map +7 -0
- package/lib/handlers/header.js +72 -0
- package/lib/handlers/header.js.map +7 -0
- package/lib/handlers/objects.cjs +170 -0
- package/lib/handlers/objects.cjs.map +7 -0
- package/lib/handlers/objects.js +150 -0
- package/lib/handlers/objects.js.map +7 -0
- package/lib/handlers/tables.cjs +587 -0
- package/lib/handlers/tables.cjs.map +7 -0
- package/lib/handlers/tables.js +557 -0
- package/lib/handlers/tables.js.map +7 -0
- package/lib/index.cjs +60 -0
- package/lib/index.cjs.map +7 -0
- package/lib/index.js +19 -0
- package/lib/index.js.map +7 -0
- package/lib/parseString.cjs +118 -0
- package/lib/parseString.cjs.map +7 -0
- package/lib/parseString.js +88 -0
- package/lib/parseString.js.map +7 -0
- package/lib/toPolylines.cjs +69 -0
- package/lib/toPolylines.cjs.map +7 -0
- package/lib/toPolylines.js +39 -0
- package/lib/toPolylines.js.map +7 -0
- package/lib/toSVG.cjs +395 -0
- package/lib/toSVG.cjs.map +7 -0
- package/lib/toSVG.js +361 -0
- package/lib/toSVG.js.map +7 -0
- package/lib/types/arc-entity.cjs +17 -0
- package/lib/types/arc-entity.cjs.map +7 -0
- package/lib/types/arc-entity.js +1 -0
- package/lib/types/arc-entity.js.map +7 -0
- package/lib/types/base-entity.cjs +17 -0
- package/lib/types/base-entity.cjs.map +7 -0
- package/lib/types/base-entity.js +1 -0
- package/lib/types/base-entity.js.map +7 -0
- package/lib/types/circle-entity.cjs +17 -0
- package/lib/types/circle-entity.cjs.map +7 -0
- package/lib/types/circle-entity.js +1 -0
- package/lib/types/circle-entity.js.map +7 -0
- package/lib/types/common.cjs +17 -0
- package/lib/types/common.cjs.map +7 -0
- package/lib/types/common.js +1 -0
- package/lib/types/common.js.map +7 -0
- package/lib/types/dimension-entity.cjs +17 -0
- package/lib/types/dimension-entity.cjs.map +7 -0
- package/lib/types/dimension-entity.js +1 -0
- package/lib/types/dimension-entity.js.map +7 -0
- package/lib/types/dxf.cjs +17 -0
- package/lib/types/dxf.cjs.map +7 -0
- package/lib/types/dxf.js +1 -0
- package/lib/types/dxf.js.map +7 -0
- package/lib/types/ellipse-entity.cjs +17 -0
- package/lib/types/ellipse-entity.cjs.map +7 -0
- package/lib/types/ellipse-entity.js +1 -0
- package/lib/types/ellipse-entity.js.map +7 -0
- package/lib/types/entity.cjs +17 -0
- package/lib/types/entity.cjs.map +7 -0
- package/lib/types/entity.js +1 -0
- package/lib/types/entity.js.map +7 -0
- package/lib/types/handler-internal.cjs +17 -0
- package/lib/types/handler-internal.cjs.map +7 -0
- package/lib/types/handler-internal.js +1 -0
- package/lib/types/handler-internal.js.map +7 -0
- package/lib/types/handler.cjs +17 -0
- package/lib/types/handler.cjs.map +7 -0
- package/lib/types/handler.js +1 -0
- package/lib/types/handler.js.map +7 -0
- package/lib/types/hatch-entity.cjs +17 -0
- package/lib/types/hatch-entity.cjs.map +7 -0
- package/lib/types/hatch-entity.js +1 -0
- package/lib/types/hatch-entity.js.map +7 -0
- package/lib/types/helper.cjs +17 -0
- package/lib/types/helper.cjs.map +7 -0
- package/lib/types/helper.js +1 -0
- package/lib/types/helper.js.map +7 -0
- package/lib/types/index.cjs +77 -0
- package/lib/types/index.cjs.map +7 -0
- package/lib/types/index.js +29 -0
- package/lib/types/index.js.map +7 -0
- package/lib/types/insert-entity.cjs +17 -0
- package/lib/types/insert-entity.cjs.map +7 -0
- package/lib/types/insert-entity.js +1 -0
- package/lib/types/insert-entity.js.map +7 -0
- package/lib/types/layer-groups.cjs +17 -0
- package/lib/types/layer-groups.cjs.map +7 -0
- package/lib/types/layer-groups.js +1 -0
- package/lib/types/layer-groups.js.map +7 -0
- package/lib/types/line-entity.cjs +17 -0
- package/lib/types/line-entity.cjs.map +7 -0
- package/lib/types/line-entity.js +1 -0
- package/lib/types/line-entity.js.map +7 -0
- package/lib/types/mtext-entity.cjs +17 -0
- package/lib/types/mtext-entity.cjs.map +7 -0
- package/lib/types/mtext-entity.js +1 -0
- package/lib/types/mtext-entity.js.map +7 -0
- package/lib/types/ole2frame-entity.cjs +17 -0
- package/lib/types/ole2frame-entity.cjs.map +7 -0
- package/lib/types/ole2frame-entity.js +1 -0
- package/lib/types/ole2frame-entity.js.map +7 -0
- package/lib/types/options.cjs +17 -0
- package/lib/types/options.cjs.map +7 -0
- package/lib/types/options.js +1 -0
- package/lib/types/options.js.map +7 -0
- package/lib/types/point-entity.cjs +17 -0
- package/lib/types/point-entity.cjs.map +7 -0
- package/lib/types/point-entity.js +1 -0
- package/lib/types/point-entity.js.map +7 -0
- package/lib/types/polyline-entity.cjs +17 -0
- package/lib/types/polyline-entity.cjs.map +7 -0
- package/lib/types/polyline-entity.js +1 -0
- package/lib/types/polyline-entity.js.map +7 -0
- package/lib/types/polylines.cjs +17 -0
- package/lib/types/polylines.cjs.map +7 -0
- package/lib/types/polylines.js +1 -0
- package/lib/types/polylines.js.map +7 -0
- package/lib/types/solid-entity.cjs +17 -0
- package/lib/types/solid-entity.cjs.map +7 -0
- package/lib/types/solid-entity.js +1 -0
- package/lib/types/solid-entity.js.map +7 -0
- package/lib/types/spline-entity.cjs +17 -0
- package/lib/types/spline-entity.cjs.map +7 -0
- package/lib/types/spline-entity.js +1 -0
- package/lib/types/spline-entity.js.map +7 -0
- package/lib/types/svg.cjs +17 -0
- package/lib/types/svg.cjs.map +7 -0
- package/lib/types/svg.js +1 -0
- package/lib/types/svg.js.map +7 -0
- package/lib/types/tables.cjs +17 -0
- package/lib/types/tables.cjs.map +7 -0
- package/lib/types/tables.js +1 -0
- package/lib/types/tables.js.map +7 -0
- package/lib/types/text-entity.cjs +17 -0
- package/lib/types/text-entity.cjs.map +7 -0
- package/lib/types/text-entity.js +1 -0
- package/lib/types/text-entity.js.map +7 -0
- package/lib/types/util-types.cjs +17 -0
- package/lib/types/util-types.cjs.map +7 -0
- package/lib/types/util-types.js +1 -0
- package/lib/types/util-types.js.map +7 -0
- package/lib/types/vecks.d.cjs +2 -0
- package/lib/types/vecks.d.cjs.map +7 -0
- package/lib/types/vecks.d.js +1 -0
- package/lib/types/vecks.d.js.map +7 -0
- package/lib/types/viewport-entity.cjs +17 -0
- package/lib/types/viewport-entity.cjs.map +7 -0
- package/lib/types/viewport-entity.js +1 -0
- package/lib/types/viewport-entity.js.map +7 -0
- package/lib/types.cjs +23 -0
- package/lib/types.cjs.map +7 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +7 -0
- package/lib/util/bSpline.cjs +95 -0
- package/lib/util/bSpline.cjs.map +7 -0
- package/lib/util/bSpline.js +65 -0
- package/lib/util/bSpline.js.map +7 -0
- package/lib/util/colors.cjs +283 -0
- package/lib/util/colors.cjs.map +7 -0
- package/lib/util/colors.js +263 -0
- package/lib/util/colors.js.map +7 -0
- package/lib/util/createArcForLWPolyline.cjs +84 -0
- package/lib/util/createArcForLWPolyline.cjs.map +7 -0
- package/lib/util/createArcForLWPolyline.js +64 -0
- package/lib/util/createArcForLWPolyline.js.map +7 -0
- package/lib/util/dxfColorToRGB.cjs +115 -0
- package/lib/util/dxfColorToRGB.cjs.map +7 -0
- package/lib/util/dxfColorToRGB.js +90 -0
- package/lib/util/dxfColorToRGB.js.map +7 -0
- package/lib/util/insertKnot.cjs +77 -0
- package/lib/util/insertKnot.cjs.map +7 -0
- package/lib/util/insertKnot.js +57 -0
- package/lib/util/insertKnot.js.map +7 -0
- package/lib/util/logger.cjs +53 -0
- package/lib/util/logger.cjs.map +7 -0
- package/lib/util/logger.js +23 -0
- package/lib/util/logger.js.map +7 -0
- package/lib/util/rgbToColorAttribute.cjs +32 -0
- package/lib/util/rgbToColorAttribute.cjs.map +7 -0
- package/lib/util/rgbToColorAttribute.js +12 -0
- package/lib/util/rgbToColorAttribute.js.map +7 -0
- package/lib/util/rotate.cjs +30 -0
- package/lib/util/rotate.cjs.map +7 -0
- package/lib/util/rotate.js +10 -0
- package/lib/util/rotate.js.map +7 -0
- package/lib/util/round10.cjs +38 -0
- package/lib/util/round10.cjs.map +7 -0
- package/lib/util/round10.js +18 -0
- package/lib/util/round10.js.map +7 -0
- package/lib/util/toPiecewiseBezier.cjs +90 -0
- package/lib/util/toPiecewiseBezier.cjs.map +7 -0
- package/lib/util/toPiecewiseBezier.js +54 -0
- package/lib/util/toPiecewiseBezier.js.map +7 -0
- package/lib/util/transformBoundingBoxAndElement.cjs +80 -0
- package/lib/util/transformBoundingBoxAndElement.cjs.map +7 -0
- package/lib/util/transformBoundingBoxAndElement.js +60 -0
- package/lib/util/transformBoundingBoxAndElement.js.map +7 -0
- package/package.json +127 -0
- package/src/Helper.ts +71 -0
- package/src/applyTransforms.ts +54 -0
- package/src/cli.ts +41 -0
- package/src/config.ts +10 -0
- package/src/constants.ts +14 -0
- package/src/denormalise.ts +153 -0
- package/src/dimensionToSVG.ts +427 -0
- package/src/entityToPolyline.ts +338 -0
- package/src/getRGBForEntity.ts +28 -0
- package/src/groupEntitiesByLayer.ts +14 -0
- package/src/handlers/blocks.ts +65 -0
- package/src/handlers/entities.ts +111 -0
- package/src/handlers/entity/arc.ts +61 -0
- package/src/handlers/entity/attdef.ts +284 -0
- package/src/handlers/entity/attrib.ts +29 -0
- package/src/handlers/entity/circle.ts +47 -0
- package/src/handlers/entity/common.ts +79 -0
- package/src/handlers/entity/dimension.ts +217 -0
- package/src/handlers/entity/ellipse.ts +55 -0
- package/src/handlers/entity/hatch.ts +471 -0
- package/src/handlers/entity/insert.ts +73 -0
- package/src/handlers/entity/line.ts +56 -0
- package/src/handlers/entity/lwpolyline.ts +54 -0
- package/src/handlers/entity/mtext.ts +150 -0
- package/src/handlers/entity/ole2Frame.ts +64 -0
- package/src/handlers/entity/point.ts +47 -0
- package/src/handlers/entity/polyline.ts +49 -0
- package/src/handlers/entity/solid.ts +73 -0
- package/src/handlers/entity/spline.ts +103 -0
- package/src/handlers/entity/text.ts +83 -0
- package/src/handlers/entity/threeDFace.ts +69 -0
- package/src/handlers/entity/vertex.ts +55 -0
- package/src/handlers/entity/viewport.ts +119 -0
- package/src/handlers/header.ts +73 -0
- package/src/handlers/objects.ts +152 -0
- package/src/handlers/tables.ts +581 -0
- package/src/index.ts +19 -0
- package/src/parseString.ts +97 -0
- package/src/toPolylines.ts +47 -0
- package/src/toSVG.ts +518 -0
- package/src/types/README.md +91 -0
- package/src/types/arc-entity.ts +10 -0
- package/src/types/base-entity.ts +25 -0
- package/src/types/circle-entity.ts +8 -0
- package/src/types/common.ts +37 -0
- package/src/types/dimension-entity.ts +23 -0
- package/src/types/dxf.ts +64 -0
- package/src/types/ellipse-entity.ts +13 -0
- package/src/types/entity.ts +32 -0
- package/src/types/handler-internal.ts +51 -0
- package/src/types/handler.ts +10 -0
- package/src/types/hatch-entity.ts +127 -0
- package/src/types/helper.ts +12 -0
- package/src/types/index.ts +53 -0
- package/src/types/insert-entity.ts +19 -0
- package/src/types/layer-groups.ts +8 -0
- package/src/types/line-entity.ts +10 -0
- package/src/types/mtext-entity.ts +35 -0
- package/src/types/ole2frame-entity.ts +35 -0
- package/src/types/options.ts +17 -0
- package/src/types/point-entity.ts +7 -0
- package/src/types/polyline-entity.ts +20 -0
- package/src/types/polylines.ts +22 -0
- package/src/types/solid-entity.ts +9 -0
- package/src/types/spline-entity.ts +12 -0
- package/src/types/svg.ts +31 -0
- package/src/types/tables.ts +414 -0
- package/src/types/text-entity.ts +23 -0
- package/src/types/util-types.ts +27 -0
- package/src/types/vecks.d.ts +29 -0
- package/src/types/viewport-entity.ts +81 -0
- package/src/types.ts +5 -0
- package/src/util/bSpline.ts +97 -0
- package/src/util/colors.ts +266 -0
- package/src/util/createArcForLWPolyline.ts +93 -0
- package/src/util/diagram.png +0 -0
- package/src/util/dxfColorToRGB.ts +106 -0
- package/src/util/insertKnot.ts +69 -0
- package/src/util/logger.ts +23 -0
- package/src/util/rgbToColorAttribute.ts +14 -0
- package/src/util/rotate.ts +14 -0
- package/src/util/round10.ts +24 -0
- package/src/util/toPiecewiseBezier.ts +70 -0
- package/src/util/transformBoundingBoxAndElement.ts +74 -0
- package/tsconfig.json +34 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import bSpline from './util/bSpline'
|
|
2
|
+
import createArcForLWPolyine from './util/createArcForLWPolyline'
|
|
3
|
+
import logger from './util/logger'
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
ArcEntity,
|
|
7
|
+
CircleEntity,
|
|
8
|
+
ControlPoint,
|
|
9
|
+
EllipseEntity,
|
|
10
|
+
EntityToPolylineOptions,
|
|
11
|
+
HandlerVertex,
|
|
12
|
+
LineEntity,
|
|
13
|
+
SplineEntity,
|
|
14
|
+
} from './types'
|
|
15
|
+
import type { PointTuple } from './types/common'
|
|
16
|
+
|
|
17
|
+
// Re-export types for backward compatibility
|
|
18
|
+
export type { ControlPoint, EntityToPolylineOptions } from './types'
|
|
19
|
+
|
|
20
|
+
type Point = PointTuple
|
|
21
|
+
|
|
22
|
+
// Local vertex type with required coordinates for runtime processing
|
|
23
|
+
interface LocalVertex extends HandlerVertex {
|
|
24
|
+
faces?: number[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Local polyline type that uses our vertex with required coordinates
|
|
28
|
+
interface LocalPolylineEntity {
|
|
29
|
+
type: string
|
|
30
|
+
vertices: LocalVertex[]
|
|
31
|
+
closed?: boolean
|
|
32
|
+
polyfaceMesh?: boolean
|
|
33
|
+
polygonMesh?: boolean
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type Entity =
|
|
37
|
+
| LineEntity
|
|
38
|
+
| (LocalPolylineEntity & { type: 'LWPOLYLINE' | 'POLYLINE' })
|
|
39
|
+
| CircleEntity
|
|
40
|
+
| EllipseEntity
|
|
41
|
+
| ArcEntity
|
|
42
|
+
| SplineEntity
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Rotate a set of points.
|
|
46
|
+
*
|
|
47
|
+
* @param points the points
|
|
48
|
+
* @param angle the rotation angle
|
|
49
|
+
*/
|
|
50
|
+
const rotate = (points: Point[], angle: number): Point[] => {
|
|
51
|
+
return points.map(function (p) {
|
|
52
|
+
return [
|
|
53
|
+
p[0] * Math.cos(angle) - p[1] * Math.sin(angle),
|
|
54
|
+
p[1] * Math.cos(angle) + p[0] * Math.sin(angle),
|
|
55
|
+
]
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Interpolate an ellipse
|
|
61
|
+
* @param cx center X
|
|
62
|
+
* @param cy center Y
|
|
63
|
+
* @param rx radius X
|
|
64
|
+
* @param ry radius Y
|
|
65
|
+
* @param start start angle in radians
|
|
66
|
+
* @param start end angle in radians
|
|
67
|
+
*/
|
|
68
|
+
const interpolateEllipse = (
|
|
69
|
+
cx: number,
|
|
70
|
+
cy: number,
|
|
71
|
+
rx: number,
|
|
72
|
+
ry: number,
|
|
73
|
+
start: number,
|
|
74
|
+
end: number,
|
|
75
|
+
rotationAngle?: number
|
|
76
|
+
): Point[] => {
|
|
77
|
+
if (end < start) {
|
|
78
|
+
end += Math.PI * 2
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// ----- Relative points -----
|
|
82
|
+
|
|
83
|
+
// Start point
|
|
84
|
+
let points: Point[] = []
|
|
85
|
+
const dTheta = (Math.PI * 2) / 72
|
|
86
|
+
const EPS = 1e-6
|
|
87
|
+
for (let theta = start; theta < end - EPS; theta += dTheta) {
|
|
88
|
+
points.push([Math.cos(theta) * rx, Math.sin(theta) * ry])
|
|
89
|
+
}
|
|
90
|
+
points.push([Math.cos(end) * rx, Math.sin(end) * ry])
|
|
91
|
+
|
|
92
|
+
// ----- Rotate -----
|
|
93
|
+
if (rotationAngle) {
|
|
94
|
+
points = rotate(points, rotationAngle)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ----- Offset center -----
|
|
98
|
+
points = points.map(function (p): Point {
|
|
99
|
+
return [cx + p[0], cy + p[1]]
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
return points
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Interpolate a b-spline. The algorithm examins the knot vector
|
|
107
|
+
* to create segments for interpolation. The parameterisation value
|
|
108
|
+
* is re-normalised back to [0,1] as that is what the lib expects (
|
|
109
|
+
* and t i de-normalised in the b-spline library)
|
|
110
|
+
*
|
|
111
|
+
* @param controlPoints the control points
|
|
112
|
+
* @param degree the b-spline degree
|
|
113
|
+
* @param knots the knot vector
|
|
114
|
+
* @returns the polyline
|
|
115
|
+
*/
|
|
116
|
+
export const interpolateBSpline = (
|
|
117
|
+
controlPoints: ControlPoint[],
|
|
118
|
+
degree: number,
|
|
119
|
+
knots: number[],
|
|
120
|
+
interpolationsPerSplineSegment?: number,
|
|
121
|
+
weights?: number[]
|
|
122
|
+
): Point[] => {
|
|
123
|
+
const polyline: Point[] = []
|
|
124
|
+
const controlPointsForLib = controlPoints.map(function (p): Point {
|
|
125
|
+
return [p.x, p.y]
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
const segmentTs = [knots[degree]]
|
|
129
|
+
const domain: Point = [knots[degree], knots[knots.length - 1 - degree]]
|
|
130
|
+
|
|
131
|
+
for (let k = degree + 1; k < knots.length - degree; ++k) {
|
|
132
|
+
if (segmentTs[segmentTs.length - 1] !== knots[k]) {
|
|
133
|
+
segmentTs.push(knots[k])
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
interpolationsPerSplineSegment = interpolationsPerSplineSegment || 25
|
|
138
|
+
for (let i = 1; i < segmentTs.length; ++i) {
|
|
139
|
+
const uMin = segmentTs[i - 1]
|
|
140
|
+
const uMax = segmentTs[i]
|
|
141
|
+
for (let k = 0; k <= interpolationsPerSplineSegment; ++k) {
|
|
142
|
+
const u = (k / interpolationsPerSplineSegment) * (uMax - uMin) + uMin
|
|
143
|
+
// Clamp t to 0, 1 to handle numerical precision issues
|
|
144
|
+
let t = (u - domain[0]) / (domain[1] - domain[0])
|
|
145
|
+
t = Math.max(t, 0)
|
|
146
|
+
t = Math.min(t, 1)
|
|
147
|
+
const p = bSpline(t, degree, controlPointsForLib, knots, weights)
|
|
148
|
+
polyline.push([p[0], p[1]])
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return polyline
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export const polyfaceOutline = (entity: LocalPolylineEntity): Point[][] => {
|
|
155
|
+
const vertices: Array<{ x: number; y: number }> = []
|
|
156
|
+
const faces: Array<{ indices: number[]; hiddens: boolean[] }> = []
|
|
157
|
+
|
|
158
|
+
for (const v of entity.vertices) {
|
|
159
|
+
if (v.faces) {
|
|
160
|
+
const face: { indices: number[]; hiddens: boolean[] } = {
|
|
161
|
+
indices: [],
|
|
162
|
+
hiddens: [],
|
|
163
|
+
}
|
|
164
|
+
for (const i of v.faces) {
|
|
165
|
+
if (i === 0) {
|
|
166
|
+
break
|
|
167
|
+
}
|
|
168
|
+
// Negative indices signify hidden edges
|
|
169
|
+
face.indices.push(i < 0 ? -i - 1 : i - 1)
|
|
170
|
+
face.hiddens.push(i < 0)
|
|
171
|
+
}
|
|
172
|
+
if ([3, 4].includes(face.indices.length)) faces.push(face)
|
|
173
|
+
} else {
|
|
174
|
+
vertices.push({ x: v.x, y: v.y })
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// If a segment starts at the end of a previous line, continue it
|
|
179
|
+
const polylines: number[][] = []
|
|
180
|
+
const segment = (a: number, b: number): void => {
|
|
181
|
+
for (const prev of polylines) {
|
|
182
|
+
if (prev.slice(-1)[0] === a) {
|
|
183
|
+
prev.push(b)
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
polylines.push([a, b])
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
for (const face of faces) {
|
|
191
|
+
for (let beg = 0; beg < face.indices.length; beg++) {
|
|
192
|
+
if (face.hiddens[beg]) {
|
|
193
|
+
continue
|
|
194
|
+
}
|
|
195
|
+
const end = (beg + 1) % face.indices.length
|
|
196
|
+
segment(face.indices[beg], face.indices[end])
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Sometimes segments are not sequential, in that case
|
|
201
|
+
// we need to find if they can mend gaps between others
|
|
202
|
+
for (const a of polylines) {
|
|
203
|
+
for (const b of polylines) {
|
|
204
|
+
if (a !== b && a[0] === b.slice(-1)[0]) {
|
|
205
|
+
b.push(...a.slice(1))
|
|
206
|
+
a.splice(0, a.length)
|
|
207
|
+
break
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return polylines
|
|
213
|
+
.filter((l) => l.length)
|
|
214
|
+
.map((l) => l.map((i) => vertices[i]).map((v) => [v.x, v.y]))
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Convert a parsed DXF entity to a polyline. These can be used to render the
|
|
219
|
+
* the DXF in SVG, Canvas, WebGL etc., without depending on native support
|
|
220
|
+
* of primitive objects (ellispe, spline etc.)
|
|
221
|
+
*/
|
|
222
|
+
export default function entityToPolyline(
|
|
223
|
+
entity: Entity,
|
|
224
|
+
options?: EntityToPolylineOptions,
|
|
225
|
+
): Point[] {
|
|
226
|
+
options = options || {}
|
|
227
|
+
let polyline: Point[] | undefined
|
|
228
|
+
|
|
229
|
+
if (entity.type === 'LINE') {
|
|
230
|
+
polyline = [
|
|
231
|
+
[entity.start.x, entity.start.y],
|
|
232
|
+
[entity.end.x, entity.end.y],
|
|
233
|
+
]
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (entity.type === 'LWPOLYLINE' || entity.type === 'POLYLINE') {
|
|
237
|
+
polyline = []
|
|
238
|
+
if (entity.polyfaceMesh) {
|
|
239
|
+
// Only return the first polyline because we can't return many
|
|
240
|
+
polyline.push(...polyfaceOutline(entity)[0])
|
|
241
|
+
} else if (entity.polygonMesh) {
|
|
242
|
+
// Do not attempt to render polygon meshes
|
|
243
|
+
} else if (entity.vertices.length) {
|
|
244
|
+
if (entity.closed) {
|
|
245
|
+
entity.vertices = entity.vertices.concat(entity.vertices[0])
|
|
246
|
+
}
|
|
247
|
+
for (let i = 0, il = entity.vertices.length; i < il - 1; ++i) {
|
|
248
|
+
const from: Point = [entity.vertices[i].x, entity.vertices[i].y]
|
|
249
|
+
const to: Point = [entity.vertices[i + 1].x, entity.vertices[i + 1].y]
|
|
250
|
+
polyline.push(from)
|
|
251
|
+
if (entity.vertices[i].bulge) {
|
|
252
|
+
polyline = polyline.concat(
|
|
253
|
+
createArcForLWPolyine(from, to, entity.vertices[i].bulge!),
|
|
254
|
+
)
|
|
255
|
+
}
|
|
256
|
+
// The last iteration of the for loop
|
|
257
|
+
if (i === il - 2) {
|
|
258
|
+
polyline.push(to)
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
} else {
|
|
262
|
+
logger.warn('Polyline entity with no vertices')
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (entity.type === 'CIRCLE') {
|
|
267
|
+
polyline = interpolateEllipse(
|
|
268
|
+
entity.x,
|
|
269
|
+
entity.y,
|
|
270
|
+
entity.r,
|
|
271
|
+
entity.r,
|
|
272
|
+
0,
|
|
273
|
+
Math.PI * 2,
|
|
274
|
+
)
|
|
275
|
+
if (entity.extrusionZ === -1) {
|
|
276
|
+
polyline = polyline.map(function (p): Point {
|
|
277
|
+
return [-p[0], p[1]]
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (entity.type === 'ELLIPSE') {
|
|
283
|
+
const rx = Math.hypot(entity.majorX, entity.majorY)
|
|
284
|
+
const ry = entity.axisRatio * rx
|
|
285
|
+
const majorAxisRotation = -Math.atan2(-entity.majorY, entity.majorX)
|
|
286
|
+
polyline = interpolateEllipse(
|
|
287
|
+
entity.x,
|
|
288
|
+
entity.y,
|
|
289
|
+
rx,
|
|
290
|
+
ry,
|
|
291
|
+
entity.startAngle,
|
|
292
|
+
entity.endAngle,
|
|
293
|
+
majorAxisRotation,
|
|
294
|
+
)
|
|
295
|
+
if (entity.extrusionZ === -1) {
|
|
296
|
+
polyline = polyline.map(function (p): Point {
|
|
297
|
+
return [-p[0], p[1]]
|
|
298
|
+
})
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (entity.type === 'ARC') {
|
|
303
|
+
// Why on earth DXF has degree start & end angles for arc,
|
|
304
|
+
// and radian start & end angles for ellipses is a mystery
|
|
305
|
+
polyline = interpolateEllipse(
|
|
306
|
+
entity.x,
|
|
307
|
+
entity.y,
|
|
308
|
+
entity.r,
|
|
309
|
+
entity.r,
|
|
310
|
+
entity.startAngle,
|
|
311
|
+
entity.endAngle,
|
|
312
|
+
)
|
|
313
|
+
|
|
314
|
+
// I kid you not, ARCs and ELLIPSEs handle this differently,
|
|
315
|
+
// as evidenced by how AutoCAD actually renders these entities
|
|
316
|
+
if (entity.extrusionZ === -1) {
|
|
317
|
+
polyline = polyline.map(function (p): Point {
|
|
318
|
+
return [-p[0], p[1]]
|
|
319
|
+
})
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (entity.type === 'SPLINE') {
|
|
324
|
+
polyline = interpolateBSpline(
|
|
325
|
+
entity.controlPoints,
|
|
326
|
+
entity.degree,
|
|
327
|
+
entity.knots,
|
|
328
|
+
options.interpolationsPerSplineSegment,
|
|
329
|
+
entity.weights,
|
|
330
|
+
)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (!polyline) {
|
|
334
|
+
logger.warn('unsupported entity for converting to polyline:', entity.type)
|
|
335
|
+
return []
|
|
336
|
+
}
|
|
337
|
+
return polyline
|
|
338
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import colors from './util/colors'
|
|
2
|
+
import logger from './util/logger'
|
|
3
|
+
|
|
4
|
+
import type { ColorRGB, Entity, LayerTable } from './types'
|
|
5
|
+
|
|
6
|
+
export default function getRGBForEntity(
|
|
7
|
+
layers: { [layerName: string]: LayerTable },
|
|
8
|
+
entity: Entity,
|
|
9
|
+
): ColorRGB {
|
|
10
|
+
const layerTable = layers[entity.layer ?? '0']
|
|
11
|
+
if (layerTable) {
|
|
12
|
+
const colorDefinedInEntity =
|
|
13
|
+
'colorNumber' in entity && entity.colorNumber !== 256
|
|
14
|
+
const colorNumber = colorDefinedInEntity
|
|
15
|
+
? entity.colorNumber
|
|
16
|
+
: layerTable.colorNumber
|
|
17
|
+
const rgb = colors[colorNumber ?? 0]
|
|
18
|
+
if (rgb) {
|
|
19
|
+
return rgb
|
|
20
|
+
} else {
|
|
21
|
+
logger.warn('Color index', colorNumber, 'invalid, defaulting to black')
|
|
22
|
+
return [0, 0, 0]
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
logger.warn('no layer table for layer:' + entity.layer)
|
|
26
|
+
return [0, 0, 0]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Entity, LayerGroups } from './types'
|
|
2
|
+
|
|
3
|
+
export default function groupEntitiesByLayer(
|
|
4
|
+
entities: Entity[],
|
|
5
|
+
): LayerGroups {
|
|
6
|
+
return entities.reduce((acc: LayerGroups, entity) => {
|
|
7
|
+
const layer = entity.layer ?? '0'
|
|
8
|
+
if (!acc[layer]) {
|
|
9
|
+
acc[layer] = []
|
|
10
|
+
}
|
|
11
|
+
acc[layer].push(entity)
|
|
12
|
+
return acc
|
|
13
|
+
}, {})
|
|
14
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { BlockInternal, DXFTuple } from '../types'
|
|
2
|
+
|
|
3
|
+
import entitiesHandler from './entities'
|
|
4
|
+
|
|
5
|
+
export default function parseBlocks(tuples: DXFTuple[]): any[] {
|
|
6
|
+
let state: 'block' | 'entities' | undefined
|
|
7
|
+
const blocks: BlockInternal[] = []
|
|
8
|
+
let block: BlockInternal | undefined
|
|
9
|
+
let entitiesTuples: DXFTuple[] | undefined = []
|
|
10
|
+
|
|
11
|
+
for (const tuple of tuples) {
|
|
12
|
+
const type = tuple[0]
|
|
13
|
+
const value = tuple[1]
|
|
14
|
+
|
|
15
|
+
if (value === 'BLOCK') {
|
|
16
|
+
state = 'block'
|
|
17
|
+
block = {}
|
|
18
|
+
entitiesTuples = []
|
|
19
|
+
blocks.push(block)
|
|
20
|
+
} else if (value === 'ENDBLK') {
|
|
21
|
+
if (block) {
|
|
22
|
+
if (state === 'entities' && entitiesTuples) {
|
|
23
|
+
block.entities = entitiesHandler(entitiesTuples)
|
|
24
|
+
} else {
|
|
25
|
+
block.entities = []
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
entitiesTuples = undefined
|
|
29
|
+
state = undefined
|
|
30
|
+
} else if (state === 'block' && type !== 0 && block) {
|
|
31
|
+
switch (type) {
|
|
32
|
+
case 1:
|
|
33
|
+
block.xref = value
|
|
34
|
+
break
|
|
35
|
+
case 2:
|
|
36
|
+
block.name = value
|
|
37
|
+
break
|
|
38
|
+
case 10:
|
|
39
|
+
block.x = value
|
|
40
|
+
break
|
|
41
|
+
case 20:
|
|
42
|
+
block.y = value
|
|
43
|
+
break
|
|
44
|
+
case 30:
|
|
45
|
+
block.z = value
|
|
46
|
+
break
|
|
47
|
+
case 67:
|
|
48
|
+
if (value !== 0) block.paperSpace = value
|
|
49
|
+
break
|
|
50
|
+
case 410:
|
|
51
|
+
block.layout = value
|
|
52
|
+
break
|
|
53
|
+
default:
|
|
54
|
+
break
|
|
55
|
+
}
|
|
56
|
+
} else if (state === 'block' && type === 0) {
|
|
57
|
+
state = 'entities'
|
|
58
|
+
if (entitiesTuples) entitiesTuples.push(tuple)
|
|
59
|
+
} else if (state === 'entities') {
|
|
60
|
+
if (entitiesTuples) entitiesTuples.push(tuple)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return blocks
|
|
65
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import type { DXFTuple } from '../types/dxf'
|
|
2
|
+
import type { Entity } from '../types/entity'
|
|
3
|
+
import type { PolylineEntity } from '../types/polyline-entity'
|
|
4
|
+
|
|
5
|
+
import logger from '../util/logger'
|
|
6
|
+
import arc from './entity/arc'
|
|
7
|
+
import attdef from './entity/attdef'
|
|
8
|
+
import attrib from './entity/attrib'
|
|
9
|
+
import circle from './entity/circle'
|
|
10
|
+
import dimension from './entity/dimension'
|
|
11
|
+
import ellipse from './entity/ellipse'
|
|
12
|
+
import hatch from './entity/hatch'
|
|
13
|
+
import insert from './entity/insert'
|
|
14
|
+
import line from './entity/line'
|
|
15
|
+
import lwpolyline from './entity/lwpolyline'
|
|
16
|
+
import mtext from './entity/mtext'
|
|
17
|
+
import ole2Frame from './entity/ole2Frame'
|
|
18
|
+
import point from './entity/point'
|
|
19
|
+
import polyline from './entity/polyline'
|
|
20
|
+
import solid from './entity/solid'
|
|
21
|
+
import spline from './entity/spline'
|
|
22
|
+
import text from './entity/text'
|
|
23
|
+
import threeDFace from './entity/threeDFace'
|
|
24
|
+
import vertex from './entity/vertex'
|
|
25
|
+
import viewport from './entity/viewport'
|
|
26
|
+
|
|
27
|
+
interface EntityHandler {
|
|
28
|
+
TYPE: string
|
|
29
|
+
process: (tuples: DXFTuple[]) => Entity
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const handlers: Record<string, EntityHandler> = [
|
|
33
|
+
point,
|
|
34
|
+
line,
|
|
35
|
+
lwpolyline,
|
|
36
|
+
polyline,
|
|
37
|
+
vertex,
|
|
38
|
+
circle,
|
|
39
|
+
arc,
|
|
40
|
+
ellipse,
|
|
41
|
+
spline,
|
|
42
|
+
solid,
|
|
43
|
+
hatch,
|
|
44
|
+
mtext,
|
|
45
|
+
attdef,
|
|
46
|
+
attrib,
|
|
47
|
+
text,
|
|
48
|
+
insert,
|
|
49
|
+
dimension,
|
|
50
|
+
threeDFace,
|
|
51
|
+
viewport,
|
|
52
|
+
ole2Frame,
|
|
53
|
+
].reduce((acc, mod) => {
|
|
54
|
+
acc[mod.TYPE] = mod
|
|
55
|
+
return acc
|
|
56
|
+
}, {} as Record<string, EntityHandler>)
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Parses entities from DXF tuples
|
|
60
|
+
*
|
|
61
|
+
* @param tuples - Array of DXF tuples representing entities
|
|
62
|
+
* @returns Array of parsed entities
|
|
63
|
+
*/
|
|
64
|
+
export default function parseEntities(tuples: DXFTuple[]): Entity[] {
|
|
65
|
+
const entities: Entity[] = []
|
|
66
|
+
const entityGroups: DXFTuple[][] = []
|
|
67
|
+
let currentEntityTuples: DXFTuple[] = []
|
|
68
|
+
|
|
69
|
+
// First group them together for easy processing
|
|
70
|
+
for (const tuple of tuples) {
|
|
71
|
+
const type = tuple[0]
|
|
72
|
+
if (type === 0) {
|
|
73
|
+
currentEntityTuples = []
|
|
74
|
+
entityGroups.push(currentEntityTuples)
|
|
75
|
+
}
|
|
76
|
+
currentEntityTuples.push(tuple)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let currentPolyline: PolylineEntity | undefined
|
|
80
|
+
for (const tuples of entityGroups) {
|
|
81
|
+
const entityType = tuples[0][1]
|
|
82
|
+
const contentTuples = tuples.slice(1)
|
|
83
|
+
|
|
84
|
+
if (entityType in handlers) {
|
|
85
|
+
const e = handlers[entityType].process(contentTuples)
|
|
86
|
+
// "POLYLINE" cannot be parsed in isolation, it is followed by
|
|
87
|
+
// N "VERTEX" entities and ended with a "SEQEND" entity.
|
|
88
|
+
// Essentially we convert POLYLINE to LWPOLYLINE - the extra
|
|
89
|
+
// vertex flags are not supported
|
|
90
|
+
if (entityType === 'POLYLINE') {
|
|
91
|
+
currentPolyline = e as PolylineEntity
|
|
92
|
+
entities.push(e)
|
|
93
|
+
} else if (entityType === 'VERTEX') {
|
|
94
|
+
if (currentPolyline) {
|
|
95
|
+
currentPolyline.vertices.push(e as any)
|
|
96
|
+
} else {
|
|
97
|
+
logger.error('ignoring invalid VERTEX entity')
|
|
98
|
+
}
|
|
99
|
+
} else if (entityType === 'SEQEND') {
|
|
100
|
+
currentPolyline = undefined
|
|
101
|
+
} else {
|
|
102
|
+
// All other entities
|
|
103
|
+
entities.push(e)
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
logger.warn('unsupported type in ENTITIES section:', entityType)
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return entities
|
|
111
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { DXFTuple } from '../../types/dxf'
|
|
2
|
+
|
|
3
|
+
import common from './common'
|
|
4
|
+
|
|
5
|
+
export const TYPE = 'ARC'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
interface ArcEntity {
|
|
9
|
+
type: typeof TYPE
|
|
10
|
+
x?: number
|
|
11
|
+
y?: number
|
|
12
|
+
z?: number
|
|
13
|
+
thickness?: number
|
|
14
|
+
r?: number
|
|
15
|
+
startAngle?: number
|
|
16
|
+
endAngle?: number
|
|
17
|
+
[key: string]: unknown
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const process = (tuples: DXFTuple[]): ArcEntity => {
|
|
21
|
+
return tuples.reduce(
|
|
22
|
+
(entity, tuple) => {
|
|
23
|
+
const type = tuple[0]
|
|
24
|
+
const value = tuple[1]
|
|
25
|
+
switch (type) {
|
|
26
|
+
case 10:
|
|
27
|
+
entity.x = value as number
|
|
28
|
+
break
|
|
29
|
+
case 20:
|
|
30
|
+
entity.y = value as number
|
|
31
|
+
break
|
|
32
|
+
case 30:
|
|
33
|
+
entity.z = value as number
|
|
34
|
+
break
|
|
35
|
+
case 39:
|
|
36
|
+
entity.thickness = value as number
|
|
37
|
+
break
|
|
38
|
+
case 40:
|
|
39
|
+
entity.r = value as number
|
|
40
|
+
break
|
|
41
|
+
case 50:
|
|
42
|
+
// *Someone* decided that ELLIPSE angles are in radians but
|
|
43
|
+
// ARC angles are in degrees
|
|
44
|
+
entity.startAngle = ((value as number) / 180) * Math.PI
|
|
45
|
+
break
|
|
46
|
+
case 51:
|
|
47
|
+
entity.endAngle = ((value as number) / 180) * Math.PI
|
|
48
|
+
break
|
|
49
|
+
default:
|
|
50
|
+
Object.assign(entity, common(type, value))
|
|
51
|
+
break
|
|
52
|
+
}
|
|
53
|
+
return entity
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
type: TYPE,
|
|
57
|
+
} as ArcEntity,
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default { TYPE, process }
|