|
@@ -1,3 +1,12 @@
|
|
|
|
+/*
|
|
|
|
+ * iGeom by LInE
|
|
|
|
+ * Provides intersetion point to Geometric Objects (GO)
|
|
|
|
+ * www.matematica.br/igeom
|
|
|
|
+ * ./app/components/intersection-component/drawers/intersection-drawer.js
|
|
|
|
+ * @calledby
|
|
|
|
+ * @version 2020/11/02: Implemented Line instersection.
|
|
|
|
+ */
|
|
|
|
+
|
|
import { PointDrawer } from "../../point-component/drawers/point-drawer";
|
|
import { PointDrawer } from "../../point-component/drawers/point-drawer";
|
|
import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
|
|
import { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
|
|
import { Drawer } from "../../../core/drawers/drawer";
|
|
import { Drawer } from "../../../core/drawers/drawer";
|
|
@@ -7,107 +16,104 @@ import { DrawerAggregator } from "../../../core/drawers/drawer-aggregator";
|
|
import { intersectionService } from "../services/intersection-service";
|
|
import { intersectionService } from "../services/intersection-service";
|
|
|
|
|
|
export class IntersectionDrawer extends Drawer {
|
|
export class IntersectionDrawer extends Drawer {
|
|
- static FIRST_OBJECT_STATE() {
|
|
|
|
|
|
+
|
|
|
|
+ static FIRST_OBJECT_STATE () {
|
|
return "FIRST_OBJECT";
|
|
return "FIRST_OBJECT";
|
|
- }
|
|
|
|
- static SECOND_OBJECT_STATE() {
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ static SECOND_OBJECT_STATE () {
|
|
return "SECOND_OBJECTf";
|
|
return "SECOND_OBJECTf";
|
|
- }
|
|
|
|
- constructor() {
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ constructor () {
|
|
super();
|
|
super();
|
|
this.aggregatorA;
|
|
this.aggregatorA;
|
|
this.aggregatorB;
|
|
this.aggregatorB;
|
|
this.label;
|
|
this.label;
|
|
- this.states = [
|
|
|
|
- IntersectionDrawer.FIRST_OBJECT_STATE,
|
|
|
|
- IntersectionDrawer.SECOND_OBJECT_STATE
|
|
|
|
- ];
|
|
|
|
|
|
+ this.states = [ IntersectionDrawer.FIRST_OBJECT_STATE, IntersectionDrawer.SECOND_OBJECT_STATE ];
|
|
this.intersections = [];
|
|
this.intersections = [];
|
|
this.pointDrawer = new PointDrawer();
|
|
this.pointDrawer = new PointDrawer();
|
|
super.setElementClass(ELEMENTS_CLASS.INTERSECTION_POINT);
|
|
super.setElementClass(ELEMENTS_CLASS.INTERSECTION_POINT);
|
|
- }
|
|
|
|
- draw(e) {
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ draw (e) {
|
|
if (e != undefined && e.attrs != undefined) {
|
|
if (e != undefined && e.attrs != undefined) {
|
|
this.aggregatorA = this.getObjectAggregatorByGenericObject(e.attrs.genericObject.r);
|
|
this.aggregatorA = this.getObjectAggregatorByGenericObject(e.attrs.genericObject.r);
|
|
this.aggregatorB = this.getObjectAggregatorByGenericObject(e.attrs.genericObject.s);
|
|
this.aggregatorB = this.getObjectAggregatorByGenericObject(e.attrs.genericObject.s);
|
|
this.drawByIntersectionPoints([e.attrs.genericObject]);
|
|
this.drawByIntersectionPoints([e.attrs.genericObject]);
|
|
return;
|
|
return;
|
|
- }
|
|
|
|
|
|
+ }
|
|
if (e == undefined || !this.isValidObject(e.target)) return;
|
|
if (e == undefined || !this.isValidObject(e.target)) return;
|
|
|
|
|
|
const selectedTool = App.getSelectedTool();
|
|
const selectedTool = App.getSelectedTool();
|
|
- if (
|
|
|
|
- selectedTool != undefined &&
|
|
|
|
- selectedTool.drawer != undefined &&
|
|
|
|
- selectedTool.drawer.elementClass == ELEMENTS_CLASS.INTERSECTION_POINT
|
|
|
|
- ) {
|
|
|
|
- if (
|
|
|
|
- this.state == undefined ||
|
|
|
|
- this.state == IntersectionDrawer.FIRST_OBJECT_STATE
|
|
|
|
- ) {
|
|
|
|
|
|
+ if (selectedTool != undefined &&
|
|
|
|
+ selectedTool.drawer != undefined &&
|
|
|
|
+ selectedTool.drawer.elementClass == ELEMENTS_CLASS.INTERSECTION_POINT
|
|
|
|
+ ) {
|
|
|
|
+ if (this.state == undefined || this.state == IntersectionDrawer.FIRST_OBJECT_STATE) {
|
|
this.setFirstObject(e.target);
|
|
this.setFirstObject(e.target);
|
|
this.setState(IntersectionDrawer.SECOND_OBJECT_STATE);
|
|
this.setState(IntersectionDrawer.SECOND_OBJECT_STATE);
|
|
- } else if (this.state == IntersectionDrawer.SECOND_OBJECT_STATE) {
|
|
|
|
|
|
+ }
|
|
|
|
+ else if (this.state == IntersectionDrawer.SECOND_OBJECT_STATE) {
|
|
this.setSecondObject(e.target);
|
|
this.setSecondObject(e.target);
|
|
this.drawPoint();
|
|
this.drawPoint();
|
|
- this.clear();
|
|
|
|
|
|
+ this.reset();
|
|
|
|
+ // this.clear();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- setFirstObject(konvaObject) {
|
|
|
|
|
|
+
|
|
|
|
+ setFirstObject (konvaObject) {
|
|
const aggregator = this.getObjectAggregator(konvaObject);
|
|
const aggregator = this.getObjectAggregator(konvaObject);
|
|
this.aggregatorA = aggregator;
|
|
this.aggregatorA = aggregator;
|
|
- }
|
|
|
|
- setSecondObject(konvaObject) {
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ setSecondObject (konvaObject) {
|
|
const aggregator = this.getObjectAggregator(konvaObject);
|
|
const aggregator = this.getObjectAggregator(konvaObject);
|
|
this.aggregatorB = aggregator;
|
|
this.aggregatorB = aggregator;
|
|
- }
|
|
|
|
- getObjectAggregator(konvaObject) {
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ getObjectAggregator (konvaObject) {
|
|
return objects.getByKonvaObject(konvaObject)[0];
|
|
return objects.getByKonvaObject(konvaObject)[0];
|
|
- }
|
|
|
|
- getObjectAggregatorByGenericObject(genericObject) {
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ getObjectAggregatorByGenericObject (genericObject) {
|
|
return objects.getByGenericObject(genericObject)[0];
|
|
return objects.getByGenericObject(genericObject)[0];
|
|
- }
|
|
|
|
- drawPoint() {
|
|
|
|
- const intersectionPoints = intersectionService.addIntersections(this.aggregatorA.genericObject.getIntersection(
|
|
|
|
- this.aggregatorB.genericObject
|
|
|
|
- ));
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ drawPoint () {
|
|
|
|
+ const intersectionPoints = intersectionService.addIntersections(
|
|
|
|
+ this.aggregatorA.genericObject.getIntersection(this.aggregatorB.genericObject));
|
|
this.drawByIntersectionPoints(intersectionPoints);
|
|
this.drawByIntersectionPoints(intersectionPoints);
|
|
- }
|
|
|
|
- drawByIntersectionPoints(intersectionPoints) {
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ drawByIntersectionPoints (intersectionPoints) {
|
|
for (let index = 0; index < intersectionPoints.length; index++) {
|
|
for (let index = 0; index < intersectionPoints.length; index++) {
|
|
const intersectionPoint = intersectionPoints[index];
|
|
const intersectionPoint = intersectionPoints[index];
|
|
intersectionPoint.update();
|
|
intersectionPoint.update();
|
|
// if (!intersectionPoint.visible) return;
|
|
// if (!intersectionPoint.visible) return;
|
|
- const point = PointDrawer.drawPoint(
|
|
|
|
- intersectionPoint,
|
|
|
|
- false,
|
|
|
|
- false,
|
|
|
|
- true
|
|
|
|
- );
|
|
|
|
- const aggregator = new DrawerAggregator(
|
|
|
|
- this,
|
|
|
|
- intersectionPoint,
|
|
|
|
- point.konvaObject,
|
|
|
|
- ELEMENTS_CLASS.INTERSECTION_POINT
|
|
|
|
- );
|
|
|
|
|
|
+ const point = PointDrawer.drawPoint(intersectionPoint, true, false, true);
|
|
|
|
+ const aggregator = new DrawerAggregator(this, intersectionPoint, point.konvaObject, ELEMENTS_CLASS.INTERSECTION_POINT);
|
|
super.addAggregator(aggregator);
|
|
super.addAggregator(aggregator);
|
|
this.aggregatorB.addAggregator(aggregator);
|
|
this.aggregatorB.addAggregator(aggregator);
|
|
this.aggregatorA.addAggregator(aggregator);
|
|
this.aggregatorA.addAggregator(aggregator);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
- isValidObject(konvaObject) {
|
|
|
|
|
|
+
|
|
|
|
+ isValidObject (konvaObject) {
|
|
switch (konvaObject.attrs.class) {
|
|
switch (konvaObject.attrs.class) {
|
|
|
|
+ case ELEMENTS_CLASS.LINE:
|
|
|
|
+ return true;
|
|
case ELEMENTS_CLASS.LINE_SEGMENT:
|
|
case ELEMENTS_CLASS.LINE_SEGMENT:
|
|
return true;
|
|
return true;
|
|
case ELEMENTS_CLASS.CIRCUMFERENCE:
|
|
case ELEMENTS_CLASS.CIRCUMFERENCE:
|
|
return true;
|
|
return true;
|
|
default:
|
|
default:
|
|
return false;
|
|
return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
- update(aggregator, e) {
|
|
|
|
|
|
|
|
|
|
+ update (aggregator, e) {
|
|
aggregator.genericObject.update(aggregator, e);
|
|
aggregator.genericObject.update(aggregator, e);
|
|
|
|
|
|
if (!aggregator.genericObject.visible || aggregator.genericObject.posX == Number.MAX_SAFE_INTEGER) {
|
|
if (!aggregator.genericObject.visible || aggregator.genericObject.posX == Number.MAX_SAFE_INTEGER) {
|
|
@@ -117,28 +123,35 @@ export class IntersectionDrawer extends Drawer {
|
|
aggregator.aggregators.forEach(a => {
|
|
aggregator.aggregators.forEach(a => {
|
|
a.visible = false;
|
|
a.visible = false;
|
|
a.konvaObject.hide();
|
|
a.konvaObject.hide();
|
|
- });
|
|
|
|
|
|
+ });
|
|
this.batchDraw();
|
|
this.batchDraw();
|
|
- }
|
|
|
|
|
|
+ }
|
|
aggregator.visible = false;
|
|
aggregator.visible = false;
|
|
return;
|
|
return;
|
|
- }
|
|
|
|
- aggregator.konvaObject.x(aggregator.genericObject.posX);
|
|
|
|
- aggregator.konvaObject.y(aggregator.genericObject.posY);
|
|
|
|
|
|
+ }
|
|
|
|
+ //todo: konva objects
|
|
|
|
+ aggregator.konvaObject.children[0].x(aggregator.genericObject.posX + 10);
|
|
|
|
+ aggregator.konvaObject.children[0].y(aggregator.genericObject.posY - 10);
|
|
|
|
+
|
|
|
|
+ aggregator.konvaObject.children[1].x(aggregator.genericObject.posX);
|
|
|
|
+ aggregator.konvaObject.children[1].y(aggregator.genericObject.posY);
|
|
|
|
+
|
|
if (!aggregator.visible || aggregator.genericObject.posX == Number.MAX_SAFE_INTEGER) {
|
|
if (!aggregator.visible || aggregator.genericObject.posX == Number.MAX_SAFE_INTEGER) {
|
|
aggregator.genericObject.visible = true;
|
|
aggregator.genericObject.visible = true;
|
|
aggregator.konvaObject.show();
|
|
aggregator.konvaObject.show();
|
|
aggregator.aggregators.forEach(a => {
|
|
aggregator.aggregators.forEach(a => {
|
|
a.visible = true;
|
|
a.visible = true;
|
|
a.konvaObject.show();
|
|
a.konvaObject.show();
|
|
- });
|
|
|
|
|
|
+ });
|
|
aggregator.visible = true;
|
|
aggregator.visible = true;
|
|
- }
|
|
|
|
|
|
+ }
|
|
this.batchDraw();
|
|
this.batchDraw();
|
|
- }
|
|
|
|
- reset() {
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ reset () {
|
|
this.aggregatorA = undefined;
|
|
this.aggregatorA = undefined;
|
|
this.aggregatorB = undefined;
|
|
this.aggregatorB = undefined;
|
|
this.setState(undefined);
|
|
this.setState(undefined);
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|