|
@@ -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 { ELEMENTS_CLASS } from "../../../core/enums/elements-class-enum";
|
|
|
import { Drawer } from "../../../core/drawers/drawer";
|
|
@@ -7,107 +16,104 @@ import { DrawerAggregator } from "../../../core/drawers/drawer-aggregator";
|
|
|
import { intersectionService } from "../services/intersection-service";
|
|
|
|
|
|
export class IntersectionDrawer extends Drawer {
|
|
|
- static FIRST_OBJECT_STATE() {
|
|
|
+
|
|
|
+ static FIRST_OBJECT_STATE () {
|
|
|
return "FIRST_OBJECT";
|
|
|
- }
|
|
|
- static SECOND_OBJECT_STATE() {
|
|
|
+ }
|
|
|
+
|
|
|
+ static SECOND_OBJECT_STATE () {
|
|
|
return "SECOND_OBJECTf";
|
|
|
- }
|
|
|
- constructor() {
|
|
|
+ }
|
|
|
+
|
|
|
+ constructor () {
|
|
|
super();
|
|
|
this.aggregatorA;
|
|
|
this.aggregatorB;
|
|
|
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.pointDrawer = new PointDrawer();
|
|
|
super.setElementClass(ELEMENTS_CLASS.INTERSECTION_POINT);
|
|
|
- }
|
|
|
- draw(e) {
|
|
|
+ }
|
|
|
+
|
|
|
+ draw (e) {
|
|
|
if (e != undefined && e.attrs != undefined) {
|
|
|
this.aggregatorA = this.getObjectAggregatorByGenericObject(e.attrs.genericObject.r);
|
|
|
this.aggregatorB = this.getObjectAggregatorByGenericObject(e.attrs.genericObject.s);
|
|
|
this.drawByIntersectionPoints([e.attrs.genericObject]);
|
|
|
return;
|
|
|
- }
|
|
|
+ }
|
|
|
if (e == undefined || !this.isValidObject(e.target)) return;
|
|
|
|
|
|
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.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.drawPoint();
|
|
|
- this.clear();
|
|
|
+ this.reset();
|
|
|
+ // this.clear();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- setFirstObject(konvaObject) {
|
|
|
+
|
|
|
+ setFirstObject (konvaObject) {
|
|
|
const aggregator = this.getObjectAggregator(konvaObject);
|
|
|
this.aggregatorA = aggregator;
|
|
|
- }
|
|
|
- setSecondObject(konvaObject) {
|
|
|
+ }
|
|
|
+
|
|
|
+ setSecondObject (konvaObject) {
|
|
|
const aggregator = this.getObjectAggregator(konvaObject);
|
|
|
this.aggregatorB = aggregator;
|
|
|
- }
|
|
|
- getObjectAggregator(konvaObject) {
|
|
|
+ }
|
|
|
+
|
|
|
+ getObjectAggregator (konvaObject) {
|
|
|
return objects.getByKonvaObject(konvaObject)[0];
|
|
|
- }
|
|
|
- getObjectAggregatorByGenericObject(genericObject) {
|
|
|
+ }
|
|
|
+
|
|
|
+ getObjectAggregatorByGenericObject (genericObject) {
|
|
|
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);
|
|
|
- }
|
|
|
- drawByIntersectionPoints(intersectionPoints) {
|
|
|
+ }
|
|
|
+
|
|
|
+ drawByIntersectionPoints (intersectionPoints) {
|
|
|
for (let index = 0; index < intersectionPoints.length; index++) {
|
|
|
const intersectionPoint = intersectionPoints[index];
|
|
|
intersectionPoint.update();
|
|
|
// 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);
|
|
|
this.aggregatorB.addAggregator(aggregator);
|
|
|
this.aggregatorA.addAggregator(aggregator);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- isValidObject(konvaObject) {
|
|
|
+
|
|
|
+ isValidObject (konvaObject) {
|
|
|
switch (konvaObject.attrs.class) {
|
|
|
+ case ELEMENTS_CLASS.LINE:
|
|
|
+ return true;
|
|
|
case ELEMENTS_CLASS.LINE_SEGMENT:
|
|
|
return true;
|
|
|
case ELEMENTS_CLASS.CIRCUMFERENCE:
|
|
|
return true;
|
|
|
default:
|
|
|
return false;
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- update(aggregator, e) {
|
|
|
|
|
|
+ update (aggregator, e) {
|
|
|
aggregator.genericObject.update(aggregator, e);
|
|
|
|
|
|
if (!aggregator.genericObject.visible || aggregator.genericObject.posX == Number.MAX_SAFE_INTEGER) {
|
|
@@ -117,28 +123,35 @@ export class IntersectionDrawer extends Drawer {
|
|
|
aggregator.aggregators.forEach(a => {
|
|
|
a.visible = false;
|
|
|
a.konvaObject.hide();
|
|
|
- });
|
|
|
+ });
|
|
|
this.batchDraw();
|
|
|
- }
|
|
|
+ }
|
|
|
aggregator.visible = false;
|
|
|
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) {
|
|
|
aggregator.genericObject.visible = true;
|
|
|
aggregator.konvaObject.show();
|
|
|
aggregator.aggregators.forEach(a => {
|
|
|
a.visible = true;
|
|
|
a.konvaObject.show();
|
|
|
- });
|
|
|
+ });
|
|
|
aggregator.visible = true;
|
|
|
- }
|
|
|
+ }
|
|
|
this.batchDraw();
|
|
|
- }
|
|
|
- reset() {
|
|
|
+ }
|
|
|
+
|
|
|
+ reset () {
|
|
|
this.aggregatorA = undefined;
|
|
|
this.aggregatorB = undefined;
|
|
|
this.setState(undefined);
|
|
|
- }
|
|
|
-}
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|