| 
					
				 | 
			
			
				@@ -17,15 +17,15 @@ 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; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -34,60 +34,83 @@ export class IntersectionDrawer extends Drawer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     this.intersections = []; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     this.pointDrawer = new PointDrawer(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     super.setElementClass(ELEMENTS_CLASS.INTERSECTION_POINT); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  draw(e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // @calledby ./app/core/drawers/stage.js! draw (e): this.drawer.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 (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) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         this.setSecondObject(e.target); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         this.drawPoint(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         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]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // Avoid to create intersection between lines/segments when some defining point is the intersection 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // Return true <=> need a new point 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  alreadyHasIntersection (og1, og2, str_a1, str_a2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if ((og1.elementClass==ELEMENTS_CLASS.LINE || og1.elementClass==ELEMENTS_CLASS.LINE_SEGMENT) && 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        (og2.elementClass==ELEMENTS_CLASS.LINE || og2.elementClass==ELEMENTS_CLASS.LINE_SEGMENT)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      // Try to avoid redundant point 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      //D var aux = " ELEMENTS_CLASS.LINE=" + ELEMENTS_CLASS.LINE + ", "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      if (og1.pointA==og2.pointA || og1.pointA==og2.pointB || og1.pointB==og2.pointA || og1.pointB==og2.pointB) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        var aux2 = " "+og1.pointA+","+og1.pointB+";"+og2.pointA+","+og2.pointB+" "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        console.log("intersection-drawer.js!alreadyHasIntersection(): existing intersection, nothing to be done: " + str_a1 + " , " + str_a2 + ", " + aux2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //TODO need to become visible? "og1.visible = true;" or "og2.visible = true;" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  drawPoint() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    const intersectionPoints = intersectionService.addIntersections( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      this.aggregatorA.genericObject.getIntersection(this.aggregatorB.genericObject)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  // Used to create new intersection point 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  //@calledby this.draw() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  drawPoint () { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const og1 = this.aggregatorA.genericObject, og2 = this.aggregatorB.genericObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const str_a1 = "og1=(" + og1.elementClass + ",id=" + og1.id + ")"; //D genericObject 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const str_a2 = "og2=(" + og2.elementClass + ",id=" + og2.id + ")"; //D 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (this.alreadyHasIntersection(og1,og2,str_a1,str_a2)) return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    console.log("intersection-drawer.js!drawPoint(): create intersection between " + str_a1 + " , " + str_a2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const intersectionOg1Og2 = og1.getIntersection(og2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    const intersectionPoints = intersectionService.addIntersections(intersectionOg1Og2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     this.drawByIntersectionPoints(intersectionPoints); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  drawByIntersectionPoints(intersectionPoints) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  drawByIntersectionPoints (intersectionPoints) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     for (let index = 0; index < intersectionPoints.length; index++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       const intersectionPoint = intersectionPoints[index]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       intersectionPoint.update(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -97,10 +120,10 @@ export class IntersectionDrawer extends Drawer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       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; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -112,25 +135,24 @@ export class IntersectionDrawer extends Drawer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           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) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       if (aggregator.visible) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         aggregator.konvaObject.hide(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         aggregator.aggregators.forEach(a => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           a.visible = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           a.konvaObject.hide(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         this.batchDraw(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       aggregator.visible = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //todo: konva objects 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     aggregator.konvaObject.children[0].x(aggregator.genericObject.posX + 10); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     aggregator.konvaObject.children[0].y(aggregator.genericObject.posY - 10); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -144,16 +166,16 @@ export class IntersectionDrawer extends Drawer { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } // export class IntersectionDrawer extends Drawer 
			 |