77 */
88import DrawObject from '../../PlotBase/Draw/DrawObject' ;
99import Point from '../../PlotUtilBase/Geometry/Point' ;
10- import { PlotObjectFactory } from '../Shapes/PlotObjectFactory' ;
10+ import { PlotObjectFactory } from '../Shapes/PlotObjectFactory' ;
11+ import { addExtendLayersPlot } from "../../3DPlot/Utils/PlotUtil" ;
1112
1213const _ = require ( 'lodash' ) ;
1314export default class DrawPolyline2D extends DrawObject {
14- constructor ( fabricCanvas , symbol , options ) {
15+ constructor ( plotLayer , symbol , options ) {
1516 super ( ) ;
16- this . m_fabricCanvas = fabricCanvas ;
17+ this . _plotLayer = plotLayer ;
1718 this . m_symbol = symbol ;
18- this . m_coordSys = this . m_fabricCanvas . getCoordSys ( ) ;
19+ this . m_coordSys = this . _plotLayer . getCoordSys ( ) ;
1920 this . m_object = null ;
2021 this . m_coords = [ [ 0 , 0 ] ] ;
2122 this . onMouseUp = this . innerOnMouseUp . bind ( this ) ;
@@ -27,16 +28,17 @@ export default class DrawPolyline2D extends DrawObject {
2728
2829 addHooks ( ) {
2930 super . addHooks ( ) ;
30- this . m_fabricCanvas . on ( 'mouse:move' , this . onMouseMove ) ;
31- this . m_fabricCanvas . on ( 'mouse:up' , this . onMouseUp ) ;
32- this . m_fabricCanvas . interactive = false ;
31+ this . _plotLayer . on ( 'mouse:move' , this . onMouseMove ) ;
32+ this . _plotLayer . on ( 'mouse:up' , this . onMouseUp ) ;
33+ this . _plotLayer . interactive = false ;
3334 }
3435
3536 removeHooks ( ) {
3637 this . m_object = null ;
37- this . m_fabricCanvas . interactive = true ;
38- this . m_fabricCanvas . off ( 'mouse:move' , this . onMouseMove ) ;
39- this . m_fabricCanvas . off ( 'mouse:up' , this . onMouseUp ) ;
38+ this . _plotLayer . interactive = true ;
39+ this . _plotLayer . off ( 'mouse:move' , this . onMouseMove ) ;
40+ this . _plotLayer . off ( 'mouse:up' , this . onMouseUp ) ;
41+ this . _plotLayer . _isDrawing = false ;
4042 super . removeHooks ( ) ;
4143 }
4244
@@ -45,19 +47,20 @@ export default class DrawPolyline2D extends DrawObject {
4547 this . m_coords [ this . m_coords . length - 1 ] = new Point ( pnt [ 0 ] , pnt [ 1 ] ) ;
4648 if ( this . m_coords . length >= 2 && this . m_object ) {
4749 this . m_object . setPnts ( this . m_coords ) ;
48- this . m_fabricCanvas . requestRenderAll ( ) ;
50+ this . _plotLayer . requestRenderAll ( ) ;
4951 }
5052 }
53+
5154 innerOnMouseUp ( event ) {
5255 if ( ! this . m_startDrawing ) this . m_startDrawing = true ;
5356
5457 const pnt = this . m_coordSys . pointToData ( [ event . pointer . x , event . pointer . y ] ) ;
5558 const lastPnt = this . m_coords . length > 2 ? this . m_coords [ this . m_coords . length - 2 ] : null ;
5659
5760 if ( lastPnt && Math . abs ( pnt [ 0 ] - lastPnt . x ) < 1e-4 && Math . abs ( pnt [ 1 ] - lastPnt . y ) < 1e-4 ) {
58- this . fireFinishEvent ( { plotObj2D : this . m_object } ) ;
61+ this . fireFinishEvent ( { plotObj2D : this . m_object } ) ;
5962 this . m_startDrawing = false ;
60- if ( this . _addedPlot ) {
63+ if ( this . _addedPlot ) {
6164 this . _addedPlot ( this . m_object ) ;
6265 }
6366 this . disable ( ) ;
@@ -68,13 +71,15 @@ export default class DrawPolyline2D extends DrawObject {
6871 this . m_symbol . getElement ( ) . then ( ( element ) => {
6972 this . m_object = PlotObjectFactory . createInstance ( this . m_symbol . type , {
7073 element : element ,
71- canvas : this . m_fabricCanvas
74+ canvas : this . _plotLayer
7275 } ) ;
73- this . m_fabricCanvas . add ( this . m_object ) ;
76+ this . _plotLayer . addPlot ( this . m_object ) ;
77+ this . _plotLayer . _isDrawing = true ;
78+ addExtendLayersPlot ( this . _plotLayer . _linkTool , this . m_object ) ;
7479 } ) ;
7580 }
7681 }
7782
78- this . m_fabricCanvas . requestRenderAll ( ) ;
83+ this . _plotLayer . requestRenderAll ( ) ;
7984 }
8085}
0 commit comments