1
0
Fork 0

feat(plugin-cutlist): New plugin to manage cutlist

This also removed the cutlist-related functionality that was added to
core as an early v3 feature.
This commit is contained in:
Joost De Cock 2022-09-07 21:16:44 +02:00
parent ef4a70c8f3
commit 55e5dc3d0c
11 changed files with 664 additions and 182 deletions

View file

@ -354,62 +354,6 @@ Part.prototype.generateTransform = function(transforms) {
}
}
/** Chainable way to add the cut info */
Part.prototype.addCut = function (cut=2, material='fabric', identical=false) {
if (cut === false) {
if (this.cut.materials[material]) delete this.cut.materials[material]
else this.context.raise.warning(`Tried to remove a material that is not set`)
return this
}
if (typeof this.cut.materials[material] === 'undefined') this.cut.materials[material] = {}
if (!(Number.isInteger(cut) && cut > -1)) {
this.context.raise.error(`Tried to set cut to a value that is not a positive integer`)
return this
}
if (typeof material !== 'string') {
this.context.raise.warning(`Tried to set material to a value that is not a string`)
return this
}
this.cut.materials[material].cut = cut
this.cut.materials[material].identical = identical
return this
}
/** Chainable way to remove (some) cut info */
Part.prototype.removeCut = function (material=false) {
return this.addCut(false, material)
}
/** Chainable way to add the grain info */
Part.prototype.setGrain = function (grain=false) {
if (grain === false) {
this.cut.grain = false
return this
}
if (typeof grain !== 'number') {
this.context.raise.error('Called part.setGrain() with a value that is not a number')
return this
}
this.cut.grain = grain
return this
}
/** Chainable way to add the cutOnFold info */
Part.prototype.setCutOnFold = function (p1, p2) {
if (p1 === false && typeof p2 === 'undefined') {
delete this.cut.cutOnFold
return this
}
if (p1 instanceof Point && p2 instanceof Point) {
this.cut.cutOnFold = [p1, p2]
}
else this.context.raise.error('Called part.setCutOnFold() but at least one parameter is not a Point instance')
return this
}
Part.prototype.isEmpty = function() {
if (Object.keys(this.snippets).length > 0) return false

View file

@ -276,132 +276,6 @@ describe('Part', () => {
expect(part.attributes.list.transform[0]).to.equal('translate(10 20)')
});
it("Should add the part cut", () => {
let pattern = new Pattern();
let part = new pattern.Part();
part.addCut(4, 'fabric', true)
expect(part.cut.materials.fabric.cut).to.equal(4)
expect(part.cut.materials.fabric.identical).to.equal(true)
part.addCut()
expect(part.cut.materials.fabric.cut).to.equal(2)
expect(part.cut.materials.fabric.identical).to.equal(false)
});
it("Should generate an error if cut is not a number", () => {
let pattern = new Pattern();
let part = new pattern.Part();
part.addCut('a', 'fabric', true)
expect(pattern.events.error.length).to.equal(1)
expect(pattern.events.error[0]).to.equal('Tried to set cut to a value that is not a positive integer')
});
it("Should generate an warning if material is not a string", () => {
let pattern = new Pattern();
let part = new pattern.Part();
part.addCut(3, 4)
expect(pattern.events.warning.length).to.equal(1)
expect(pattern.events.warning[0]).to.equal('Tried to set material to a value that is not a string')
});
it("Should generate an error when removing a material that is not set (through addCut)", () => {
let pattern = new Pattern();
let part = new pattern.Part();
part.addCut(4, 'fabric', true)
part.addCut(false, 'lining')
expect(pattern.events.warning.length).to.equal(1)
expect(pattern.events.warning[0]).to.equal('Tried to remove a material that is not set')
});
it("Should remove the part cut through addCut", () => {
let pattern = new Pattern();
let part = new pattern.Part();
part.addCut(4, 'fabric', true)
part.addCut(false, 'fabric')
expect(typeof part.cut.materials.fabric).to.equal('undefined')
});
it("Should remove the part cut through removeCut", () => {
let pattern = new Pattern();
let part = new pattern.Part();
part.addCut(4, 'fabric', true)
part.removeCut('fabric')
expect(typeof part.cut.materials.fabric).to.equal('undefined')
});
it("Should generate an error when removing a material that is not set (through removeCut)", () => {
let pattern = new Pattern();
let part = new pattern.Part();
part.addCut(4, 'fabric', true)
part.removeCut('lining')
expect(pattern.events.warning.length).to.equal(1)
expect(pattern.events.warning[0]).to.equal('Tried to remove a material that is not set')
});
it("Should generate an error when removing a material that is not a string (through removeCut)", () => {
let pattern = new Pattern();
let part = new pattern.Part();
part.addCut(4, 'fabric', true)
part.removeCut(23)
expect(pattern.events.warning.length).to.equal(1)
expect(pattern.events.warning[0]).to.equal('Tried to remove a material that is not set')
});
it("Should generate a warning when calling removeCut without parameters", () => {
let pattern = new Pattern();
let part = new pattern.Part();
part.addCut(4, 'fabric', true)
part.removeCut()
expect(pattern.events.warning.length).to.equal(1)
expect(pattern.events.warning[0]).to.equal('Tried to remove a material that is not set')
});
it("Should set the part grainline", () => {
let pattern = new Pattern();
let part = new pattern.Part();
expect(part.cut.grain).to.equal(90)
part.setGrain(123)
expect(part.cut.grain).to.equal(123)
});
it("Should raise a warning when calling part.setGrain() without any parameters", () => {
let pattern = new Pattern();
let part = new pattern.Part();
part.setGrain()
expect(part.cut.grain).to.equal(false)
});
it("Should raise an error when calling part.setGrain() with a value that is not a number", () => {
let pattern = new Pattern();
let part = new pattern.Part();
part.setGrain('a')
expect(part.cut.grain).to.equal(90)
expect(pattern.events.error.length).to.equal(1)
expect(pattern.events.error[0]).to.equal('Called part.setGrain() with a value that is not a number')
});
it("Should set and then remove the cutOnFold", () => {
let pattern = new Pattern();
let part = new pattern.Part();
const { Point } = part.shorthand()
part.setCutOnFold(new Point(2,3), new Point(100,200))
expect(part.cut.cutOnFold[0].x).to.equal(2)
expect(part.cut.cutOnFold[0].y).to.equal(3)
expect(part.cut.cutOnFold[1].x).to.equal(100)
expect(part.cut.cutOnFold[1].y).to.equal(200)
part.setCutOnFold(false)
expect(typeof part.cut.cutOnFold).to.equal('undefined')
});
it("Should raise an error when setting the cutOnFold with a non-Point value", () => {
let pattern = new Pattern();
let part = new pattern.Part();
const { Point } = part.shorthand()
part.setCutOnFold(new Point(2,3), 12)
expect(pattern.events.error.length).to.equal(1)
expect(pattern.events.error[0]).to.equal('Called part.setCutOnFold() but at least one parameter is not a Point instance')
});
describe('isEmpty', () => {
it("Should return true if the part has no paths or snippets", () => {
let pattern = new Pattern();