|
@@ -4,23 +4,28 @@ import { label as Label } from "../../../component-registry/label";
|
|
|
import { DrawerAggregator } from "../../../core/drawers/drawer-aggregator";
|
|
|
import { selector as Selector } from "../../../core/application/selector";
|
|
|
import { LineSegmentModel } from "../models/line-segment-model";
|
|
|
+import { PointDrawer } from "../../point-component/drawers/point-drawer";
|
|
|
+import { objects as Objects } from "../../../core/application/objects";
|
|
|
export class LineSegmentDrawer extends Drawer {
|
|
|
- static FIRST_POINT() {
|
|
|
+ static FIRST_POINT_STATE() {
|
|
|
return "FIRST_POINT";
|
|
|
}
|
|
|
- static SECOND_POINT() {
|
|
|
+ static SECOND_POINT_STATE() {
|
|
|
return "SECOND_POINT";
|
|
|
}
|
|
|
constructor() {
|
|
|
super();
|
|
|
this.pointA;
|
|
|
this.pointB;
|
|
|
+ this.aggregatorA;
|
|
|
+ this.aggregatorB;
|
|
|
this.label;
|
|
|
this.states = [
|
|
|
- LineSegmentDrawer.FIRST_POINT,
|
|
|
- LineSegmentDrawer.SECOND_POINT
|
|
|
+ LineSegmentDrawer.FIRST_POINT_STATE,
|
|
|
+ LineSegmentDrawer.SECOND_POINT_STATE
|
|
|
];
|
|
|
this.lineSegment;
|
|
|
+ this.pointDrawer = new PointDrawer();
|
|
|
}
|
|
|
setPointA(point) {
|
|
|
this.pointA = point;
|
|
@@ -28,12 +33,54 @@ export class LineSegmentDrawer extends Drawer {
|
|
|
setPointB(point) {
|
|
|
this.pointB = point;
|
|
|
}
|
|
|
+ setAggregatorA(aggregator) {
|
|
|
+ this.aggregatorA = aggregator;
|
|
|
+ this.setPointA(aggregator.genericObject);
|
|
|
+ }
|
|
|
+ setAggregatorB(aggregator) {
|
|
|
+ this.aggregatorB = aggregator;
|
|
|
+ this.setPointB(aggregator.genericObject);
|
|
|
+ }
|
|
|
draw() {
|
|
|
+ console.info("objects", Objects.get());
|
|
|
const points = Selector.getSelectedPoints();
|
|
|
- const aggregators = Selector.getSelectedPointsAggregators();
|
|
|
+ if (points == undefined || points.length < 1) {
|
|
|
+ this.drawByState();
|
|
|
+ }
|
|
|
+ this.drawByPoints(points);
|
|
|
+ }
|
|
|
+ drawByState() {
|
|
|
+ if (this.state == undefined) {
|
|
|
+ super.setState(LineSegmentDrawer.FIRST_POINT_STATE);
|
|
|
+ } else if (this.state == LineSegmentDrawer.FIRST_POINT_STATE) {
|
|
|
+ const aggregator = this.pointDrawer.drawPoint();
|
|
|
+ this.setAggregatorA(aggregator);
|
|
|
+ super.setState(LineSegmentDrawer.SECOND_POINT_STATE);
|
|
|
+ } else if (this.state == LineSegmentDrawer.SECOND_POINT_STATE) {
|
|
|
+ const aggregator = this.pointDrawer.drawPoint();
|
|
|
+ this.setAggregatorB(aggregator);
|
|
|
+ this.drawByPoints(
|
|
|
+ [this.pointA, this.pointB],
|
|
|
+ [this.aggregatorA, this.aggregatorB]
|
|
|
+ );
|
|
|
+ super.setState(undefined);
|
|
|
+ } else {
|
|
|
+ super.setState(undefined);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ drawByPoints(points, aggregators) {
|
|
|
if (points == undefined || points.length < 1) return;
|
|
|
this.setPointA(points[0]);
|
|
|
this.setPointB(points[1]);
|
|
|
+ if (aggregators == undefined)
|
|
|
+ aggregators = Selector.getSelectedPointsAggregators();
|
|
|
+ else {
|
|
|
+ aggregators = [
|
|
|
+ Objects.getByGenericObject(this.pointA)[0],
|
|
|
+ Objects.getByGenericObject(this.pointB)[0]
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
this.label = Label.draw();
|
|
|
this.lineSegment = new LineSegmentModel(
|
|
|
this.pointA,
|
|
@@ -73,7 +120,7 @@ export class LineSegmentDrawer extends Drawer {
|
|
|
|
|
|
static getKonvaLine(pointA, pointB, useLabel) {
|
|
|
const points = [pointA.posX, pointA.posY, pointB.posX, pointB.posY];
|
|
|
- const line = new Konva.Line({
|
|
|
+ return new Konva.Line({
|
|
|
points: points,
|
|
|
stroke: "grey",
|
|
|
strokeWidth: 2,
|
|
@@ -82,9 +129,10 @@ export class LineSegmentDrawer extends Drawer {
|
|
|
strokeScaleEnabled: false,
|
|
|
class: ELEMENTS_CLASS.LINE_SEGMENT,
|
|
|
connections: [],
|
|
|
- index: 0
|
|
|
+ index: 0,
|
|
|
+ selectable: false,
|
|
|
+ draggable: false
|
|
|
});
|
|
|
- return line;
|
|
|
}
|
|
|
|
|
|
static drawKonvaLine(pointA, pointB) {
|