|
@@ -1,17 +1,16 @@
|
|
|
import { app as App } from "../app";
|
|
|
-import { menu as Menu } from "../core/components/menu";
|
|
|
+import { menu as Menu } from "../core/application/menu";
|
|
|
import { point as Point } from "./point";
|
|
|
-import { selector as Selector } from "../core/components/selector";
|
|
|
+import { selector as Selector } from "../core/application/selector";
|
|
|
import { ELEMENTS_CLASS } from "../core/enums/elements-class-enum";
|
|
|
export class LineSegment {
|
|
|
-
|
|
|
- static get STATE_PRIMEIRO_PONTO () {
|
|
|
+ static get STATE_PRIMEIRO_PONTO() {
|
|
|
return "primeiro_ponto";
|
|
|
}
|
|
|
- static get STATE_SEGUNDO_PONTO () {
|
|
|
+ static get STATE_SEGUNDO_PONTO() {
|
|
|
return "segundo_ponto";
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
constructor() {
|
|
|
this._state = undefined;
|
|
|
this._points = new Set();
|
|
@@ -27,24 +26,22 @@ export class LineSegment {
|
|
|
this.bootstrap();
|
|
|
}
|
|
|
|
|
|
- draw (event) {
|
|
|
- console.log("chamou o método draw()");
|
|
|
- console.log("evento: ", event);
|
|
|
+ draw(event) {
|
|
|
let _this = this;
|
|
|
- if(event != null) {
|
|
|
+ if (event != null) {
|
|
|
_this = event;
|
|
|
}
|
|
|
- if(_this._state == null) {
|
|
|
+ if (_this._state == null) {
|
|
|
_this._state = LineSegment.STATE_PRIMEIRO_PONTO;
|
|
|
_this._points.clear();
|
|
|
App.setStatus("Selecione o primeiro ponto no canvas");
|
|
|
} else if (_this._state === LineSegment.STATE_PRIMEIRO_PONTO) {
|
|
|
const pos = App.pos();
|
|
|
- _this._points.add({x: pos.x, y: pos.y});
|
|
|
+ _this._points.add({ x: pos.x, y: pos.y });
|
|
|
_this._state = LineSegment.STATE_SEGUNDO_PONTO;
|
|
|
} else if (_this._state === LineSegment.STATE_SEGUNDO_PONTO) {
|
|
|
const pos = App.pos();
|
|
|
- _this._points.add({x: pos.x, y: pos.y});
|
|
|
+ _this._points.add({ x: pos.x, y: pos.y });
|
|
|
_this.drawPoint(_this._points);
|
|
|
_this._points.clear();
|
|
|
_this._state = LineSegment.STATE_PRIMEIRO_PONTO;
|
|
@@ -72,13 +69,14 @@ export class LineSegment {
|
|
|
}
|
|
|
|
|
|
click(e) {
|
|
|
- console.log("chamou o método click()");
|
|
|
let _this = e;
|
|
|
if (e == undefined) {
|
|
|
_this = this;
|
|
|
}
|
|
|
- if (_this._state == LineSegment.STATE_PRIMEIRO_PONTO ||
|
|
|
- _this._state == LineSegment.STATE_SEGUNDO_PONTO) {
|
|
|
+ if (
|
|
|
+ _this._state == LineSegment.STATE_PRIMEIRO_PONTO ||
|
|
|
+ _this._state == LineSegment.STATE_SEGUNDO_PONTO
|
|
|
+ ) {
|
|
|
App.clearSelectedTool();
|
|
|
_this.clearState();
|
|
|
return;
|
|
@@ -91,7 +89,10 @@ export class LineSegment {
|
|
|
) {
|
|
|
const layer = App.currentLayer();
|
|
|
const point_groups = new Set(objects.map(object => object.parent));
|
|
|
- const points_xy = objects.reduce((prev, next) => prev.concat([next.x(), next.y()]), []);
|
|
|
+ const points_xy = objects.reduce(
|
|
|
+ (prev, next) => prev.concat([next.x(), next.y()]),
|
|
|
+ []
|
|
|
+ );
|
|
|
let ln = _this.createLine(points_xy);
|
|
|
_this.attachPoints(ln, point_groups);
|
|
|
layer.add(ln);
|
|
@@ -110,25 +111,26 @@ export class LineSegment {
|
|
|
this._points.clear();
|
|
|
}
|
|
|
|
|
|
- drawPoint (p) {
|
|
|
+ drawPoint(p) {
|
|
|
const points = Array.from(p).map(xy => {
|
|
|
return Point.drawPoint(xy.x, xy.y, true);
|
|
|
});
|
|
|
- const points_xy = points.map( group => this.getPoint(group))
|
|
|
+ const points_xy = points
|
|
|
+ .map(group => this.getPoint(group))
|
|
|
.reduce((prev, next) => prev.concat([next.x(), next.y()]), []);
|
|
|
let ln = this.createLine(points_xy);
|
|
|
let layer = App.currentLayer();
|
|
|
this.attachPoints(ln, points);
|
|
|
layer.add(ln);
|
|
|
App.stage.draw();
|
|
|
-
|
|
|
+
|
|
|
//this.clearState();
|
|
|
//App.clearSelectedTool();
|
|
|
//App.setStatus("");
|
|
|
return ln;
|
|
|
}
|
|
|
|
|
|
- createLine (points) {
|
|
|
+ createLine(points) {
|
|
|
return new Konva.Line({
|
|
|
points: points,
|
|
|
stroke: "grey",
|
|
@@ -141,31 +143,31 @@ export class LineSegment {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- getPoint (group) {
|
|
|
+ getPoint(group) {
|
|
|
const point_collection = group.find(node => {
|
|
|
- return node.getClassName() === 'Circle';
|
|
|
+ return node.getClassName() === "Circle";
|
|
|
});
|
|
|
return point_collection.toArray()[0];
|
|
|
}
|
|
|
|
|
|
- attachPoints (line, points) {
|
|
|
- line._parents = []
|
|
|
- points.forEach( (p, idx)=> {
|
|
|
+ attachPoints(line, points) {
|
|
|
+ line._parents = [];
|
|
|
+ points.forEach((p, idx) => {
|
|
|
line._parents.push(p);
|
|
|
const point = this.getPoint(p);
|
|
|
point._name = idx;
|
|
|
- if(!p._parents) {
|
|
|
+ if (!p._parents) {
|
|
|
p._children = [];
|
|
|
}
|
|
|
p._children.push(line);
|
|
|
- p.on('dragmove', () => {
|
|
|
+ p.on("dragmove", () => {
|
|
|
App.clearSelectedTool();
|
|
|
this.clearState();
|
|
|
const current_points = line.points();
|
|
|
const new_point = this.getPoint(p);
|
|
|
const new_x = new_point.x() + p.x();
|
|
|
const new_y = new_point.y() + p.y();
|
|
|
- if(new_point._name == 0) {
|
|
|
+ if (new_point._name == 0) {
|
|
|
// pos 0 ,1
|
|
|
current_points[0] = new_x;
|
|
|
current_points[1] = new_y;
|
|
@@ -176,7 +178,7 @@ export class LineSegment {
|
|
|
line.points(current_points);
|
|
|
//App.stage.draw();
|
|
|
});
|
|
|
- })
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
bootstrap() {
|