1
0
Fork 0

feat: Added plugin-export-dxf

This commit is contained in:
Joost De Cock 2020-04-18 11:35:28 +02:00
parent 3204273717
commit e134e940e7
11 changed files with 818 additions and 60 deletions

View file

@ -1,62 +1,63 @@
aaron: "A FreeSewing pattern for a A-shirt or tank top"
benjamin: "A FreeSewing pattern for a bow tie"
bent: "A FreeSewing pattern for a menswear body block with a two-part sleeve"
breanna: "A FreeSewing pattern for a basic body block for womenswear"
brian: "A FreeSewing pattern for a basic body block for menswear"
bruce: "A FreeSewing pattern for boxer briefs"
carlita: "A FreeSewing pattern for Sherlock Holmes cosplay; Or just a nice long coat"
carlton: "A FreeSewing pattern for Sherlock Holmes cosplay; Or just a nice long coat"
cathrin: "A FreeSewing pattern for a underbust corset / waist trainer"
components: "A collection of React components for FreeSewing web UIs"
core: "A library for creating made-to-measure sewing patterns"
create-freesewing-pattern: "Initializer package for FreeSewing patterns: npm init FreeSewing-pattern"
css-theme: "A CSS theme for FreeSewing web UIs"
diana: "A FreeSewing pattern for a top with a draped neck"
examples: "A FreeSewing pattern holding examples for our documentation"
florent: "A FreeSewing pattern for a flat cap"
fu: "A FreeSewing pattern for a face mask"
gatsby-remark-jargon: "A gatsby-transformer-remark sub-plugin for jargon terms"
holmes: "A FreeSewing pattern for a Sherlock Holmes hat"
huey: "A FreeSewing pattern for a zip-up hoodie"
hugo: "A FreeSewing pattern for a hooded jumper with raglan sleeves"
i18n: "Translations for the FreeSewing project"
jaeger: "A FreeSewing pattern for a sport coat style jacket"
models: "Body measurements data for a range of default sizes"
mui-theme: "A Material-UI theme for FreeSewing web UIs"
pattern-info: "Information about available freesewing patterns"
penelope: "A FreeSewing pattern for a pencil skirt"
plugin-banner: "A FreeSewing plugin to repeat text on a path"
plugin-bundle: "An umbrella package of 8 essential FreeSewing build-time plugins"
plugin-bust: "A FreeSewing plugin that helps with bust-adjusting menswear patterns"
plugin-buttons: "A FreeSewing plugin that provides button and buttonhole snippets"
plugin-cutonfold: "A FreeSewing plugin to add cut-on-fold indicators on your patterns"
plugin-debug: "A FreeSewing plugin to log debug info to your browser console"
plugin-designer: "A FreeSewing plugin to facilitate pattern design"
plugin-dimension: "A FreeSewing plugin to add dimensions to your (paperless) pattern"
plugin-flip: "A FreeSewing plugin to flip parts horizontally"
plugin-gore: "A FreeSewing plugin to generate gores for a semi-sphere or dome"
plugin-grainline: "A FreeSewing plugin to add grainline indicators on your patterns"
plugin-i18n: "A FreeSewing plugin for pattern translation"
plugin-logo: "A FreeSewing plugin to add our logo to your patterns"
plugin-round: "A FreeSewing plugin to round corners"
plugin-scalebox: "A FreeSewing plugin to add a scalebox to your pattern"
plugin-sprinkle: "A FreeSewing plugin to bulk-add snippets to your pattern"
plugin-svgattr: "A FreeSewing plugin to set SVG attributes"
plugin-theme: "A FreeSewing plugin that provides a default theme"
plugin-title: "A FreeSewing plugin to add a title to your pattern parts"
plugin-validate: "A FreeSewing plugin that validates aspects of your code"
aaron: 'A FreeSewing pattern for a A-shirt or tank top'
benjamin: 'A FreeSewing pattern for a bow tie'
bent: 'A FreeSewing pattern for a menswear body block with a two-part sleeve'
breanna: 'A FreeSewing pattern for a basic body block for womenswear'
brian: 'A FreeSewing pattern for a basic body block for menswear'
bruce: 'A FreeSewing pattern for boxer briefs'
carlita: 'A FreeSewing pattern for Sherlock Holmes cosplay; Or just a nice long coat'
carlton: 'A FreeSewing pattern for Sherlock Holmes cosplay; Or just a nice long coat'
cathrin: 'A FreeSewing pattern for a underbust corset / waist trainer'
components: 'A collection of React components for FreeSewing web UIs'
core: 'A library for creating made-to-measure sewing patterns'
create-freesewing-pattern: 'Initializer package for FreeSewing patterns: npm init FreeSewing-pattern'
css-theme: 'A CSS theme for FreeSewing web UIs'
diana: 'A FreeSewing pattern for a top with a draped neck'
examples: 'A FreeSewing pattern holding examples for our documentation'
florent: 'A FreeSewing pattern for a flat cap'
fu: 'A FreeSewing pattern for a face mask'
gatsby-remark-jargon: 'A gatsby-transformer-remark sub-plugin for jargon terms'
holmes: 'A FreeSewing pattern for a Sherlock Holmes hat'
huey: 'A FreeSewing pattern for a zip-up hoodie'
hugo: 'A FreeSewing pattern for a hooded jumper with raglan sleeves'
i18n: 'Translations for the FreeSewing project'
jaeger: 'A FreeSewing pattern for a sport coat style jacket'
models: 'Body measurements data for a range of default sizes'
mui-theme: 'A Material-UI theme for FreeSewing web UIs'
pattern-info: 'Information about available freesewing patterns'
penelope: 'A FreeSewing pattern for a pencil skirt'
plugin-banner: 'A FreeSewing plugin to repeat text on a path'
plugin-bundle: 'An umbrella package of 8 essential FreeSewing build-time plugins'
plugin-bust: 'A FreeSewing plugin that helps with bust-adjusting menswear patterns'
plugin-buttons: 'A FreeSewing plugin that provides button and buttonhole snippets'
plugin-cutonfold: 'A FreeSewing plugin to add cut-on-fold indicators on your patterns'
plugin-debug: 'A FreeSewing plugin to log debug info to your browser console'
plugin-designer: 'A FreeSewing plugin to facilitate pattern design'
plugin-dimension: 'A FreeSewing plugin to add dimensions to your (paperless) pattern'
plugin-export-dxf: 'A FreeSewing plugin to export your pattern as DXF-ASTM'
plugin-flip: 'A FreeSewing plugin to flip parts horizontally'
plugin-gore: 'A FreeSewing plugin to generate gores for a semi-sphere or dome'
plugin-grainline: 'A FreeSewing plugin to add grainline indicators on your patterns'
plugin-i18n: 'A FreeSewing plugin for pattern translation'
plugin-logo: 'A FreeSewing plugin to add our logo to your patterns'
plugin-round: 'A FreeSewing plugin to round corners'
plugin-scalebox: 'A FreeSewing plugin to add a scalebox to your pattern'
plugin-sprinkle: 'A FreeSewing plugin to bulk-add snippets to your pattern'
plugin-svgattr: 'A FreeSewing plugin to set SVG attributes'
plugin-theme: 'A FreeSewing plugin that provides a default theme'
plugin-title: 'A FreeSewing plugin to add a title to your pattern parts'
plugin-validate: 'A FreeSewing plugin that validates aspects of your code'
prettier-config: "FreeSewing's shared configuration for prettier"
remark-jargon: "A Remark plugin for jargon terms"
rendertest: "A FreeSewing pattern to test (y)our render engine our CSS"
sandy: "A FreeSewing pattern for a circle skirt"
shin: "A FreeSewing pattern for swim trunks"
simon: "A FreeSewing pattern for a button down shirt"
simone: "A FreeSewing pattern for a button down shirt (Simone = Simon for people with breasts)"
sven: "A FreeSewing pattern for a straightforward sweater"
tamiko: "A FreeSewing pattern for a zero-waste top"
theo: "A FreeSewing pattern for classic trousers"
trayvon: "A FreeSewing pattern for a tie"
remark-jargon: 'A Remark plugin for jargon terms'
rendertest: 'A FreeSewing pattern to test (y)our render engine our CSS'
sandy: 'A FreeSewing pattern for a circle skirt'
shin: 'A FreeSewing pattern for swim trunks'
simon: 'A FreeSewing pattern for a button down shirt'
simone: 'A FreeSewing pattern for a button down shirt (Simone = Simon for people with breasts)'
sven: 'A FreeSewing pattern for a straightforward sweater'
tamiko: 'A FreeSewing pattern for a zero-waste top'
theo: 'A FreeSewing pattern for classic trousers'
trayvon: 'A FreeSewing pattern for a tie'
tutorial: "A FreeSewing pattern for a baby bib that's used in our tutorial"
utils: "A collection of utilities shared across freesewing frontend projects"
wahid: "A FreeSewing pattern for a classic fitted waistcoat"
waralee: "A FreeSewing pattern for wrap pants"
utils: 'A collection of utilities shared across freesewing frontend projects'
wahid: 'A FreeSewing pattern for a classic fitted waistcoat'
waralee: 'A FreeSewing pattern for wrap pants'

View file

@ -0,0 +1,108 @@
# Change log for: @freesewing/plugin-export-dxf
## Unreleased
**Note:** Version bump only for package plugin-export-dxf
## 2.5.0 (2020-04-05)
**Note:** Version bump only for package plugin-export-dxf
## 2.4.6 (2020-03-23)
**Note:** Version bump only for package plugin-export-dxf
## 2.4.5 (2020-03-19)
**Note:** Version bump only for package plugin-export-dxf
## 2.4.4 (2020-03-15)
**Note:** Version bump only for package plugin-export-dxf
## 2.4.3 (2020-03-12)
**Note:** Version bump only for package plugin-export-dxf
## 2.4.2 (2020-03-08)
**Note:** Version bump only for package plugin-export-dxf
## 2.4.1 (2020-03-04)
**Note:** Version bump only for package plugin-export-dxf
## 2.4.0 (2020-02-29)
**Note:** Version bump only for package plugin-export-dxf
## 2.3.0 (2020-02-23)
**Note:** Version bump only for package plugin-export-dxf
## 2.2.0 (2020-02-22)
**Note:** Version bump only for package plugin-export-dxf
## 2.1.9 (2020-01-18)
**Note:** Version bump only for package plugin-export-dxf
## 2.1.8 (2019-12-16)
**Note:** Version bump only for package plugin-export-dxf
## 2.1.7 (2019-12-15)
**Note:** Version bump only for package plugin-export-dxf
## 2.1.6 (2019-11-24)
**Note:** Version bump only for package plugin-export-dxf
## 2.1.5 (2019-11-19)
**Note:** Version bump only for package plugin-export-dxf
## 2.1.4 (2019-11-01)
**Note:** Version bump only for package plugin-export-dxf
## 2.1.3 (2019-10-18)
**Note:** Version bump only for package plugin-export-dxf
## 2.1.2 (2019-10-14)
**Note:** Version bump only for package plugin-export-dxf
## 2.1.1 (2019-10-13)
**Note:** Version bump only for package plugin-export-dxf
## 2.1.0 (2019-10-06)
**Note:** Version bump only for package plugin-export-dxf
## 2.0.4 (2019-09-27)
**Note:** Version bump only for package plugin-export-dxf
## 2.0.3 (2019-09-15)
**Note:** Version bump only for package plugin-export-dxf
## 2.0.2 (2019-09-06)
**Note:** Version bump only for package plugin-export-dxf
## 2.0.1 (2019-09-01)
**Note:** Version bump only for package plugin-export-dxf
## 2.0.0 (2019-08-25)
This is the **initial release**, and the start of this change log.
Prior to version 2, FreeSewing was not a JavaScript project.
As such, that history is out of scope for this change log.

View file

@ -0,0 +1,185 @@
![FreeSewing](https://freesewing.org/banner.jpg)
<p align='center'><a
href="https://www.npmjs.com/package/@freesewing/plugin-export-dxf"
title="@freesewing/plugin-export-dxf on NPM"
><img src="https://img.shields.io/npm/v/@freesewing/plugin-export-dxf.svg"
alt="@freesewing/plugin-export-dxf on NPM"/>
</a><a
href="https://opensource.org/licenses/MIT"
title="License: MIT"
><img src="https://img.shields.io/npm/l/@freesewing/plugin-export-dxf.svg?label=License"
alt="License: MIT"/>
</a><a
href="https://deepscan.io/dashboard#view=project&tid=2114&pid=2993&bid=23256"
title="Code quality on DeepScan"
><img src="https://deepscan.io/api/teams/2114/projects/2993/branches/23256/badge/grade.svg"
alt="Code quality on DeepScan"/>
</a><a
href="https://github.com/freesewing/freesewing/issues?q=is%3Aissue+is%3Aopen+label%3Apkg%3Aplugin-export-dxf"
title="Open issues tagged pkg:plugin-export-dxf"
><img src="https://img.shields.io/github/issues/freesewing/freesewing/pkg:plugin-export-dxf.svg?label=Issues"
alt="Open issues tagged pkg:plugin-export-dxf"/>
</a></p><p align='center'><a
href="https://twitter.com/freesewing_org"
title="Follow @freesewing_org on Twitter"
><img src="https://img.shields.io/badge/%F3%A0%80%A0-Follow%20us-blue.svg?logo=twitter&logoColor=white&logoWidth=15"
alt="Follow @freesewing_org on Twitter"/>
</a><a
href="https://gitter.im/freesewing/chat"
title="Chat with us on Gitter"
><img src="https://img.shields.io/badge/%F3%A0%80%A0-Chat%20with%20us-CA0547.svg?logo=gitter&logoColor=white&logoWidth=15"
alt="Chat with us on Gitter"/>
</a><a
href="https://freesewing.org/patrons/join"
title="Become a FreeSewing Patron"
><img src="https://img.shields.io/badge/%F3%A0%80%A0-Support%20us-blueviolet.svg?logo=cash-app&logoColor=white&logoWidth=15"
alt="Become a FreeSewing Patron"/>
</a><a
href="https://instagram.com/freesewing_org"
title="Follow @freesewing_org on Twitter"
><img src="https://img.shields.io/badge/%F3%A0%80%A0-Follow%20us-E4405F.svg?logo=instagram&logoColor=white&logoWidth=15"
alt="Follow @freesewing_org on Twitter"/>
</a></p>
## What am I looking at? 🤔
This repository is our _monorepo_ holding [all our NPM packages](https://www.npmjs.com/search?q=keywords:freesewing).
This folder holds **@freesewing/plugin-export-dxf**
A FreeSewing plugin to export your pattern as DXF-ASTM
## About
This plugin adds the ability to export patterns to DXF-ASTM.
DXF (Drawing interchange format) is a file format developed by Autodesk
(of AutoCAD® fame).
The DXF-ASTM variety is a subset of the format, specifically targetted
at the garment industry.
ASTM is the _American Society for Testing and Materials_ — a standards body —
that published the format.
DXF-ASTM is the successor of DXF-AAMA which was developed by the _American
Apparel Manufacturers Association_ which reveals the origins of the file format.
## Usage
Instantiate your pattern, and use the plugin.
It will add the `exportDxf()` method to the pattern object.
This method will return the DXF-ASTM output.
```js
const models import '@freesewing/models'
const Aaron import '@freesewing/aaron'
const exportDxfPlugin = import '@freesewing/plugin-export-dxf'
const settings = {
// Make sure to set complete to false
complete: false,
measurements: models.withoutBreasts.size42
}
let dxf = new Aaron(settings)
.use(exportDxfPlugin)
.draft()
.exportDxf()
```
## Configuration
This plugin takes a configuration object as a second parameter to the
`pattern.use()` method.
### Precision
The precision property determines the length of the line segments used
to approximate curves. The generated DXF-ASTM output will only contain
straight lines, so curves will be approximated wiht lines segments.
The `precision` sets the length of those segments in mm.
In the example below, the `precision` is set to `25` resulting in
the use of line segments 25mm (1 inch) to approximate the curve.
```js
let config = {
precision: 25
}
let dxf = new Aaron(settings).use(exportDxfPlugin, config)
```
The default `precision` is `1`, giving you 1mm long line segments
to approximate curves.
## Reasons to use this plugin
This plugin can export your pattern to DXF-ASTM so you can import it to
your 3D software of choice.
## Reasons to not use this plugin
### Because DXF is inferior to SVG in every way
DXF (and DXF-AAMA and DXF-ASTM with it) are rooted in the world of industrial
manufacturing. And it shows.
Nowadays, it's easy to think of the DXF file format as a bit of an embarassment.
But it is deliberatly kept dumb so that old industrial CNC milling machines,
plotters, laster cutters and whatnot, can handle the format.
### Because this plugin does not implement all of DXF
This plugin does the minimum to allow export of FreeSewing patterns into
3D garment tools. It expexts the input pattern to only include the outlines.
That means, no seam allowance, or titles, no notches, and so on.
## About FreeSewing 💀
Where the world of makers and developers collide, that's where you'll find FreeSewing.
Our [core library](https://freesewing.dev/reference/api/) is a _batteries-included_ toolbox
for parametric design of sewing patterns. It's a modular system (check our list
of [plugins](https://freesewing.dev/reference/plugins/) and getting started is as simple as:
```bash
npm init freesewing-pattern
```
The [getting started](https://freesewing.dev/guides/getting-started/) section on [freesewing.dev](https://freesewing.dev/) is a good
entrypoint to our documentation, but you'll find a lot more there, including
our [API reference](https://freesewing.dev/reference/api/),
as well as [our turorial](https://freesewing.dev/tutorials/pattern-design/),
and [howtos](https://freesewing.dev/howtos/).
If you're a maker, checkout [freesewing.org](https://freesewing/) where you can generate
our sewing patterns adapted to your measurements.
## Support FreeSewing: Become a patron 🥰
FreeSewing is an open source project run by a community,
and financially supported by our patrons.
If you feel what we do is worthwhile, you too
should [become a patron](https://freesewing.org/patrons/join).
## Links 👩‍💻
- 💻 Makers website: [freesewing.org](https://freesewing.org)
- 💻 Developers website: [freesewing.dev](https://freesewing.dev)
- 💬 Chat: [gitter.im/freesewing](https://gitter.im/freesewing/chat)
- 🐦 Twitter: [@freesewing_org](https://twitter.com/freesewing_org)
- 📷 Instagram: [@freesewing_org](https://instagram.com/freesewing_org)
## License: MIT 🤓
© [Joost De Cock](https://github.com/joostdecock).
See [the license file](https://github.com/freesewing/freesewing/blob/develop/LICENSE) for details.
## Where to get help 🤯
Our [chatroom on Gitter](https://gitter.im/freesewing/chat) is the best place to ask questions,
share your feedback, or just hang out.
If you want to report a problem, please [create an issue](https://github.com/freesewing/freesewing/issues/new).

View file

@ -0,0 +1,85 @@
## About
This plugin adds the ability to export patterns to DXF-ASTM.
DXF (Drawing interchange format) is a file format developed by Autodesk
(of AutoCAD® fame).
The DXF-ASTM variety is a subset of the format, specifically targetted
at the garment industry.
ASTM is the _American Society for Testing and Materials_ — a standards body —
that published the format.
DXF-ASTM is the successor of DXF-AAMA which was developed by the _American
Apparel Manufacturers Association_ which reveals the origins of the file format.
## Usage
Instantiate your pattern, and use the plugin.
It will add the `exportDxf()` method to the pattern object.
This method will return the DXF-ASTM output.
```js
const models import '@freesewing/models'
const Aaron import '@freesewing/aaron'
const exportDxfPlugin = import '@freesewing/plugin-export-dxf'
const settings = {
// Make sure to set complete to false
complete: false,
measurements: models.withoutBreasts.size42
}
let dxf = new Aaron(settings)
.use(exportDxfPlugin)
.draft()
.exportDxf()
```
## Configuration
This plugin takes a configuration object as a second parameter to the
`pattern.use()` method.
### Precision
The precision property determines the length of the line segments used
to approximate curves. The generated DXF-ASTM output will only contain
straight lines, so curves will be approximated wiht lines segments.
The `precision` sets the length of those segments in mm.
In the example below, the `precision` is set to `25` resulting in
the use of line segments 25mm (1 inch) to approximate the curve.
```js
let config = {
precision: 25
}
let dxf = new Aaron(settings).use(exportDxfPlugin, config)
```
The default `precision` is `1`, giving you 1mm long line segments
to approximate curves.
## Reasons to use this plugin
This plugin can export your pattern to DXF-ASTM so you can import it to
your 3D software of choice.
## Reasons to not use this plugin
### Because DXF is inferior to SVG in every way
DXF (and DXF-AAMA and DXF-ASTM with it) are rooted in the world of industrial
manufacturing. And it shows.
Nowadays, it's easy to think of the DXF file format as a bit of an embarassment.
But it is deliberatly kept dumb so that old industrial CNC milling machines,
plotters, laster cutters and whatnot, can handle the format.
### Because this plugin does not implement all of DXF
This plugin does the minimum to allow export of FreeSewing patterns into
3D garment tools. It expexts the input pattern to only include the outlines.
That means, no seam allowance, or titles, no notches, and so on.

View file

@ -0,0 +1,52 @@
{
"name": "@freesewing/plugin-export-dxf",
"version": "2.5.0",
"description": "A FreeSewing plugin to export your pattern as DXF-ASTM",
"author": "Joost De Cock <joost@decock.org> (https://github.com/joostdecock)",
"homepage": "https://freesewing.org/",
"repository": "github:freesewing/freesewing",
"license": "MIT",
"bugs": {
"url": "https://github.com/freesewing/freesewing/issues"
},
"keywords": [
"freesewing",
"plugin",
"sewing pattern",
"sewing",
"design",
"parametric design",
"made to measure",
"diy",
"fashion"
],
"main": "dist/index.js",
"module": "dist/index.mjs",
"scripts": {
"clean": "rimraf dist",
"build": "npm run clean && rollup -c",
"test": "echo \"plugin-export-dxf: No tests configured. Perhaps you'd like to do this?\" && exit 0",
"pubtest": "npm publish --registry http://localhost:6662",
"pubforce": "npm publish",
"symlink": "mkdir -p ./node_modules/@freesewing && cd ./node_modules/@freesewing && ln -s -f ../../../* . && cd -",
"start": "rollup -c -w"
},
"peerDependencies": {
"@freesewing/core": "^2.5.0"
},
"dependencies": {},
"devDependencies": {},
"files": [
"dist/*",
"README.md",
"package.json"
],
"publishConfig": {
"access": "public",
"tag": "latest"
},
"engines": {
"node": ">=8.0.0",
"npm": ">=5"
}
}

View file

@ -0,0 +1,41 @@
import babel from 'rollup-plugin-babel'
import resolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import json from 'rollup-plugin-json'
import minify from 'rollup-plugin-babel-minify'
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
import { name, version, description, author, license, main, module } from './package.json'
const output = [
{
file: main,
format: 'cjs',
sourcemap: true
}
]
if (typeof module !== 'undefined')
output.push({
file: module,
format: 'es',
sourcemap: true
})
export default {
input: 'src/index.js',
output,
plugins: [
peerDepsExternal(),
resolve({ modulesOnly: true }),
commonjs(),
json(),
babel({
exclude: 'node_modules/**',
plugins: ['@babel/plugin-proposal-object-rest-spread']
}),
minify({
comments: false,
sourceMap: true,
banner: `/**\n * ${name} | v${version}\n * ${description}\n * (c) ${new Date().getFullYear()} ${author}\n * @license ${license}\n */`
})
]
}

View file

@ -0,0 +1,243 @@
import { name, version, description, author, license } from '../package.json'
function Dxf(config) {
this.config = config
}
// Round to 2 decimals because DXF is stupid
Dxf.prototype.round = function (val) {
return Math.round(val * 100) / 100
}
/** Returns DXF code for optional banner */
Dxf.prototype.banner = function (pattern) {
return `999
${name.slice(1)} | v${version}
999
${description}
999
(c) ${new Date().getFullYear()} ${author}
999
License: ${license}
999
Pattern: ${pattern.config.name} | v${pattern.config.version}
999
Export date: ${new Date().toISOString()}`
}
/** Returns DXF code for tables */
Dxf.prototype.tables = function (tables) {
let dxf = `
0
SECTION
2
TABLES`
for (let lineType of tables.lineTypes)
dxf += `
0
TABLE
2
LTYPE
0
LTYPE
2
${lineType.name}
3
${lineType.description}
72
65
73
0
40
0.00
0
ENDTAB`
for (let layer of tables.layers)
dxf += `
0
TABLE
2
LAYER
0
LAYER
2
${layer.name}
62
${layer.color}
6
${layer.lineType}
0
ENDTAB`
dxf += `
0
ENDSEC`
return dxf
}
/** Returns DXF code to close/end a DXF file */
Dxf.prototype.footer = function () {
return `
0
EOF
`
}
/** Returns DXF code for a line */
Dxf.prototype.line = function (to, layer) {
return `
0
VERTEX
8
${layer}
10
${this.round(to.x)}
20
${this.round(to.y)}`
}
/** Returns DXF code for a curve */
Dxf.prototype.curve = function (from, cp1, cp2, to, layer, part) {
let { Path } = part.shorthand()
let path = new Path().move(from).curve(cp1, cp2, to)
let steps = Math.floor(path.length() / this.config.precision)
let dxf, current
for (let i = 1; i <= steps; i++) {
current = path.shiftAlong(i * this.config.precision)
dxf += this.line(current, layer)
}
if (current.dist(to) > 0.1) dxf += this.line(to, layer)
return dxf
}
/** Returns DXF code for a Path object */
Dxf.prototype.path = function (path, layer, part) {
let dxf = `
0
POLYLINE
8
${layer}
70
1`
let current, start
for (let op of path.ops) {
switch (op.type) {
case 'move':
start = op.to
dxf += this.line(op.to, layer)
break
case 'line':
dxf += this.line(op.to, layer)
break
case 'curve':
dxf += this.curve(current, op.cp1, op.cp2, op.to, layer, part)
break
case 'close':
dxf += this.line(start, layer)
break
default:
throw new Error(`Unsupported path operation: ${op.type}`)
}
current = op.to
}
dxf += `
0
SEQEND`
return dxf
}
/** Returns blocs portion of the DXF code for a Part object */
Dxf.prototype.partBlocks = function (part, name, layer = 1) {
let dxf = `
0
BLOCK
8
${layer}
2
${name}
70
0
10
0.00
20
0.00`
for (let key in part.paths) {
let path = part.paths[key]
if (path.render) dxf += this.path(path, layer, part)
}
dxf += `
0
ENDBLK`
return dxf
}
/** Returns entities portion of the DXF code for a Part object */
Dxf.prototype.partEntities = function (part, name, layer = 1) {
return `
0
INSERT
8
${layer}
2
${name}
10
0.00
20
0.00`
}
/** Exports (drafted) pattern as DXF-ASTM */
Dxf.prototype.render = function (pattern) {
// Ensure pattern layout
pattern.pack()
// Tables structure
let tables = {
lineTypes: [
{
name: 'CONTINUOUS',
description: 'SOLIDLINE'
}
],
layers: [
{
name: 1,
color: 7,
lineType: 'CONTINIOUS'
}
]
}
let dxf = ''
dxf += this.banner(pattern)
dxf += this.tables(tables)
dxf += `
0
SECTION
2
BLOCKS`
for (let partId in pattern.parts) {
if (pattern.parts[partId].render) dxf += this.partBlocks(pattern.parts[partId], partId)
}
dxf += `
0
ENDSEC
0
SECTION
2
ENTITIES`
for (let partId in pattern.parts) {
if (pattern.parts[partId].render) dxf += this.partEntities(pattern.parts[partId], partId)
}
dxf += `
0
ENDSEC`
dxf += this.footer()
return dxf
}
export default Dxf

View file

@ -0,0 +1,5 @@
const footer = `
0
EOF
`
export default footer

View file

@ -0,0 +1,13 @@
import { name, version, description, author, license } from '../package.json'
const header = `999
${name.slice(1)} | v${version}
999
${description}
999
(c) ${new Date().getFullYear()} ${author}
999
License: ${license}
999`
export default header

View file

@ -0,0 +1,13 @@
import { name, version } from '../package.json'
import Dxf from './dxf'
export default {
name: name,
version: version,
hooks: {
postDraft: (pattern, config = { precision: 1 }) => {
pattern.exportDxf = () => new Dxf(config).render(pattern)
}
}
}

View file

@ -0,0 +1,12 @@
import freesewing from 'freesewing'
import { version } from '../package.json'
let chai = require('chai')
let expect = chai.expect
chai.use(require('chai-string'))
let plugin = require('../dist/index.js')
it('Should set the plugin name:version attribute', () => {
let pattern = new freesewing.Pattern()
pattern.use(plugin).draft().render()
expect(pattern.svg.attributes.get('freesewing:plugin-buttons')).to.equal(version)
})