@@ -37,51 +37,77 @@ export class View extends draw2d.Canvas {
3737 onDrop ( droppedDomNode , x , y , shiftKey , ctrlKey ) {
3838 var type = $ ( droppedDomNode ) . data ( "shape" ) ;
3939 this . addShapeToSchem ( type , x , y ) ;
40- }
40+ }
4141
4242 addShapeToSchem ( type , x , y ) {
43+
44+ var MyInputPortLocator = draw2d . layout . locator . PortLocator . extend ( {
45+ init :function ( x , y ) {
46+ this . _super ( ) ;
47+ this . x = x ;
48+ this . y = y ;
49+ } ,
50+ relocate :function ( index , figure ) {
51+ this . applyConsiderRotation ( figure , this . x , this . y ) ;
52+ }
53+ } ) ;
54+
55+
56+ console . log ( x , y )
57+ x = 16 * Math . round ( x / 16 ) ;
58+ y = 16 * Math . round ( y / 16 ) ;
59+ console . log ( x , y )
4360 if ( type == "res" ) {
44- var e = new shapeRes ( { x : x , y : y } ) ;
61+ var e = new shapeRes ( { x : x , y : y } ) ;
4562 var inputLocator = new draw2d . layout . locator . InputPortLocator ( ) ;
4663 var outputLocator = new draw2d . layout . locator . OutputPortLocator ( ) ;
4764 e . createPort ( "hybrid" , inputLocator ) ;
4865 e . createPort ( "hybrid" , outputLocator ) ;
4966 e . id = `R${ this . rCounter } ` ;
67+ e . add ( new draw2d . shape . basic . Text ( { text :e . id , stroke :0 } ) , new draw2d . layout . locator . TopLocator ( ) ) ;
5068 this . rCounter = this . rCounter + 1 ;
5169 } else if ( type == "cap" ) {
5270 var e = new shapeCap ( { x : x , y : y } ) ;
53- var inputLocator = new draw2d . layout . locator . InputPortLocator ( ) ;
54- var outputLocator = new draw2d . layout . locator . OutputPortLocator ( ) ;
71+ var inputLocator = new MyInputPortLocator ( 16 , 0 ) ;
72+ var outputLocator = new MyInputPortLocator ( 16 , 48 ) ;
5573 e . createPort ( "hybrid" , inputLocator ) ;
5674 e . createPort ( "hybrid" , outputLocator ) ;
5775 e . id = `C${ this . cCounter } ` ;
76+ e . add ( new draw2d . shape . basic . Text ( { text :e . id , stroke :0 } ) , new draw2d . layout . locator . RightLocator ( ) ) ;
5877 this . cCounter = this . cCounter + 1 ;
59- } else if ( type == "vin" ) {
78+ } else if ( type == "ind" ) {
79+ var e = new shapeInductor ( { x : x , y : y } ) ;
80+ var inputLocator = new MyInputPortLocator ( 0 , 16 ) ;
81+ var outputLocator = new MyInputPortLocator ( 64 , 16 ) ;
82+ e . createPort ( "hybrid" , inputLocator ) ;
83+ e . createPort ( "hybrid" , outputLocator ) ;
84+ e . id = `L${ this . rCounter } ` ;
85+ e . add ( new draw2d . shape . basic . Text ( { text :e . id , stroke :0 } ) , new draw2d . layout . locator . TopLocator ( ) ) ;
86+ this . lCounter = this . lCounter + 1 ; } else if ( type == "vin" ) {
6087 var e = new shapeVin ( { x : x , y : y } ) ;
61- var inputLocator = new draw2d . layout . locator . InputPortLocator ( ) ;
62- var outputLocator = new draw2d . layout . locator . OutputPortLocator ( ) ;
63- // e.createPort("hybrid",inputLocator);
88+ var outputLocator = new MyInputPortLocator ( 16 , 0 ) ;
6489 e . createPort ( "hybrid" , outputLocator ) ;
6590 e . id = `vin` ;
6691 } else if ( type == "gnd" ) {
6792 var e = new shapeGnd ( { x : x , y : y } ) ;
6893 // var inputLocator = new draw2d.layout.locator.InputPortLocator();
69- var outputLocator = new draw2d . layout . locator . OutputPortLocator ( ) ;
94+ var outputLocator = new MyInputPortLocator ( 16 , 0 ) ;
7095 // e.createPort("hybrid",inputLocator);
7196 e . createPort ( "hybrid" , outputLocator ) ;
7297 e . id = `gnd` ;
7398 } else if ( type == "vout" ) {
7499 var e = new shapeVout ( { x : x , y : y } ) ;
75- var inputLocator = new draw2d . layout . locator . InputPortLocator ( ) ;
100+ var inputLocator = new MyInputPortLocator ( 0 , 16 ) ;
76101 e . createPort ( "hybrid" , inputLocator ) ;
77102 // e.createPort("hybrid",outputLocator);
78103 e . id = `vout` ;
79104 } else exit ( 'You gave a bad type: ' , type )
80105
81106 this . dropCb ( e . id ) ;
82107
83- // e.resizeable = false;
84- e . keepAspectRatio = true ;
108+ e . resizeable = false ;
109+ // e.keepAspectRatio = true;
110+ console . log ( e ) ;
85111 // e.width = 50;
86112
87113 var command = new draw2d . command . CommandAdd ( this , e , x , y ) ;
0 commit comments