🚧 Moved shorthand to part and improved debug
This commit is contained in:
parent
a357586344
commit
f990e1890a
2 changed files with 45 additions and 27 deletions
50
src/part.js
50
src/part.js
|
@ -1,10 +1,9 @@
|
||||||
import { macroName } from "./utils";
|
import { macroName, units } from "./utils";
|
||||||
import Point from "./point";
|
import Point from "./point";
|
||||||
import Path from "./path";
|
import Path from "./path";
|
||||||
import Snippet from "./snippet";
|
import Snippet from "./snippet";
|
||||||
import Attributes from "./attributes";
|
import Attributes from "./attributes";
|
||||||
import * as hooklib from "hooks";
|
import * as hooklib from "hooks";
|
||||||
import { units } from "./utils";
|
|
||||||
import { round } from "./round";
|
import { round } from "./round";
|
||||||
|
|
||||||
function Part() {
|
function Part() {
|
||||||
|
@ -36,7 +35,7 @@ function Part() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Part.prototype.macroRunner = function(args) {
|
Part.prototype.macroClosure = function(args) {
|
||||||
let self = this;
|
let self = this;
|
||||||
let data = args;
|
let data = args;
|
||||||
let method = function(key, data) {
|
let method = function(key, data) {
|
||||||
|
@ -51,6 +50,15 @@ Part.prototype.macroRunner = function(args) {
|
||||||
return method;
|
return method;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Part.prototype.debugClosure = function() {
|
||||||
|
let self = this;
|
||||||
|
let method = function(d, e, b, u, g) {
|
||||||
|
self.debug(d, e, b, u, g);
|
||||||
|
};
|
||||||
|
|
||||||
|
return method;
|
||||||
|
};
|
||||||
|
|
||||||
/** Debug method, exposes debug hook */
|
/** Debug method, exposes debug hook */
|
||||||
Part.prototype.debug = function(data) {};
|
Part.prototype.debug = function(data) {};
|
||||||
|
|
||||||
|
@ -62,8 +70,13 @@ Part.prototype.getUid = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Returns a value formatted for units provided in settings */
|
/** Returns a value formatted for units provided in settings */
|
||||||
Part.prototype.units = function(value) {
|
Part.prototype.unitsClosure = function(value) {
|
||||||
return units(value, this.context.settings.units);
|
let self = this;
|
||||||
|
let method = function(value) {
|
||||||
|
return units(value, self.context.settings.units);
|
||||||
|
};
|
||||||
|
|
||||||
|
return method;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Calculates the part's bounding box and sets it */
|
/** Calculates the part's bounding box and sets it */
|
||||||
|
@ -125,4 +138,31 @@ Part.prototype.copy = function(orig) {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Part.prototype.units = function(input) {
|
||||||
|
return units(input, this.context.settings.units);
|
||||||
|
};
|
||||||
|
|
||||||
|
/** Returns an object with shorthand access for pattern design */
|
||||||
|
Part.prototype.shorthand = function() {
|
||||||
|
let final = this.context.settings.mode === "draft" ? true : false;
|
||||||
|
let paperless = this.context.settings.paperless === true ? true : false;
|
||||||
|
return {
|
||||||
|
sa: this.context.settings.sa || 0,
|
||||||
|
measurements: this.context.settings.measurements || {},
|
||||||
|
options: this.context.options || {},
|
||||||
|
store: this.context.store,
|
||||||
|
points: this.points || {},
|
||||||
|
paths: this.paths || {},
|
||||||
|
snippets: this.snippets || {},
|
||||||
|
macro: this.macroClosure(),
|
||||||
|
units: this.unitsClosure(),
|
||||||
|
Point: this.Point,
|
||||||
|
Path: this.Path,
|
||||||
|
Snippet: this.Snippet,
|
||||||
|
final,
|
||||||
|
paperless,
|
||||||
|
debug: this.debugClosure()
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export default Part;
|
export default Part;
|
||||||
|
|
22
src/utils.js
22
src/utils.js
|
@ -66,28 +66,6 @@ export function beamCrossesY(from, to, y) {
|
||||||
return beamsCross(from, to, left, right);
|
return beamsCross(from, to, left, right);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns an object with shorthand access for pattern design */
|
|
||||||
export function shorthand(part) {
|
|
||||||
let final = part.context.settings.mode === "draft" ? true : false;
|
|
||||||
let paperless = part.context.settings.paperless === true ? true : false;
|
|
||||||
return {
|
|
||||||
sa: part.context.settings.sa || 0,
|
|
||||||
measurements: part.context.settings.measurements || {},
|
|
||||||
options: part.context.options || {},
|
|
||||||
store: part.context.store,
|
|
||||||
points: part.points || {},
|
|
||||||
paths: part.paths || {},
|
|
||||||
snippets: part.snippets || {},
|
|
||||||
macro: part.macroRunner(),
|
|
||||||
Point: part.Point,
|
|
||||||
Path: part.Path,
|
|
||||||
Snippet: part.Snippet,
|
|
||||||
final,
|
|
||||||
paperless,
|
|
||||||
debug: part.debug
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Convert value in mm to cm or imperial units */
|
/** Convert value in mm to cm or imperial units */
|
||||||
export function units(value, to = "metric") {
|
export function units(value, to = "metric") {
|
||||||
if (to === "imperial") return round(value / 25.4) + '"';
|
if (to === "imperial") return round(value / 25.4) + '"';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue