11import { state } from './main.js'
2+ import { SelectionMenuPolicy } from './wdk_draw2d.js'
23
34export class View extends draw2d . Canvas {
45
@@ -10,7 +11,7 @@ export class View extends draw2d.Canvas {
1011 parseFloat ( wrapperComputedStyle . paddingLeft ) +
1112 parseFloat ( wrapperComputedStyle . paddingRight )
1213 // console.log("height, width", canvasHolder.offsetHeight, wrapperWidth)
13- super ( id , wrapperWidth - 2 , canvasHolder . offsetHeight - 2 ) ;
14+ super ( id , wrapperWidth - 2 , canvasHolder . offsetHeight - 2 ) ;
1415 this . rCounter = 0 ;
1516 this . cCounter = 0 ;
1617 this . lCounter = 0 ;
@@ -37,7 +38,7 @@ export class View extends draw2d.Canvas {
3738 onDrop ( droppedDomNode , x , y , shiftKey , ctrlKey ) {
3839 var type = $ ( droppedDomNode ) . data ( "shape" ) ;
3940 this . addShapeToSchem ( type , x , y ) ;
40- }
41+ }
4142
4243 addToSchematic ( e ) {
4344 var command = new draw2d . command . CommandAdd ( this , e , this . x , this . y ) ;
@@ -48,74 +49,88 @@ export class View extends draw2d.Canvas {
4849 // console.log(type, x, y)
4950
5051 var MyInputPortLocator = draw2d . layout . locator . PortLocator . extend ( {
51- init :function ( x , y ) {
52+ init : function ( x , y ) {
5253 this . _super ( ) ;
5354 this . x = x ;
5455 this . y = y ;
5556 } ,
56- relocate :function ( index , figure ) {
57- this . applyConsiderRotation ( figure , this . x , this . y ) ;
57+ relocate : function ( index , figure ) {
58+ var parent = figure . getParent ( ) ;
59+ var rotAngle = parent . getRotationAngle ( ) ;
60+
61+ if ( rotAngle > 0 ) {
62+ // var newX =
63+ figure . setPosition ( this . y , this . x ) ;
64+ } else {
65+ figure . setPosition ( this . x , this . y ) ;
66+ }
67+ // this.applyConsiderRotation(figure, this.x, this.y);
5868 }
5969 } ) ;
6070
6171
6272 // console.log(x, y)
63- x = 16 * Math . round ( x / 16 ) ;
64- y = 16 * Math . round ( y / 16 ) ;
73+ x = 16 * Math . round ( x / 16 ) ;
74+ y = 16 * Math . round ( y / 16 ) ;
75+ var locator ;
6576 // console.log(x, y)
6677 if ( type == "res" ) {
67- var e = new shapeRes ( { x : x , y : y } ) ;
68- var inputLocator = new draw2d . layout . locator . InputPortLocator ( ) ;
69- var outputLocator = new draw2d . layout . locator . OutputPortLocator ( ) ;
78+ var e = new shapeRes ( { x : x , y : y } ) ;
79+ var inputLocator = new MyInputPortLocator ( 0 , 16 ) ;
80+ var outputLocator = new MyInputPortLocator ( 48 , 16 ) ;
7081 e . createPort ( "hybrid" , inputLocator ) ;
7182 e . createPort ( "hybrid" , outputLocator ) ;
7283 e . id = `R${ this . rCounter } ` ;
73- e . add ( new draw2d . shape . basic . Text ( { text :e . id , stroke :0 } ) , new draw2d . layout . locator . TopLocator ( ) ) ;
84+ e . add ( new draw2d . shape . basic . Text ( { text : e . id , stroke : 0 } ) , new draw2d . layout . locator . TopLocator ( ) ) ;
7485 this . rCounter = this . rCounter + 1 ;
86+ e . installEditPolicy ( new SelectionMenuPolicy ( ) ) ;
7587 } else if ( type == "cap" ) {
7688 var e = new shapeCap ( { x : x , y : y } ) ;
77- var inputLocator = new MyInputPortLocator ( 16 , 0 ) ;
78- var outputLocator = new MyInputPortLocator ( 16 , 48 ) ;
89+ var inputLocator = new MyInputPortLocator ( 16 , 0 ) ;
90+ var outputLocator = new MyInputPortLocator ( 16 , 48 ) ;
7991 e . createPort ( "hybrid" , inputLocator ) ;
8092 e . createPort ( "hybrid" , outputLocator ) ;
8193 e . id = `C${ this . cCounter } ` ;
82- e . add ( new draw2d . shape . basic . Text ( { text :e . id , stroke :0 } ) , new draw2d . layout . locator . RightLocator ( ) ) ;
94+ e . add ( new draw2d . shape . basic . Text ( { text : e . id , stroke : 0 } ) , new draw2d . layout . locator . RightLocator ( ) ) ;
8395 this . cCounter = this . cCounter + 1 ;
96+ e . installEditPolicy ( new SelectionMenuPolicy ( ) ) ;
8497 } else if ( type == "ind" ) {
85- var e = new shapeInductor ( { x : x , y : y } ) ;
86- var inputLocator = new MyInputPortLocator ( 0 , 16 ) ;
87- var outputLocator = new MyInputPortLocator ( 64 , 16 ) ;
98+ var e = new shapeInductor ( { x : x , y : y } ) ;
99+ var inputLocator = new MyInputPortLocator ( - 1 , 16 ) ;
100+ var outputLocator = new MyInputPortLocator ( 65 , 16 ) ;
88101 e . createPort ( "hybrid" , inputLocator ) ;
89102 e . createPort ( "hybrid" , outputLocator ) ;
90103 e . id = `L${ this . lCounter } ` ;
91- e . add ( new draw2d . shape . basic . Text ( { text :e . id , stroke :0 } ) , new draw2d . layout . locator . TopLocator ( ) ) ;
92- this . lCounter = this . lCounter + 1 ; } else if ( type == "vin" ) {
104+ e . add ( new draw2d . shape . basic . Text ( { text : e . id , stroke : 0 } ) , new draw2d . layout . locator . TopLocator ( ) ) ;
105+ this . lCounter = this . lCounter + 1 ;
106+ e . installEditPolicy ( new SelectionMenuPolicy ( ) ) ;
107+ } else if ( type == "vin" ) {
93108 var e = new shapeVin ( { x : x , y : y } ) ;
94- var outputLocator = new MyInputPortLocator ( 16 , 0 ) ;
109+ var outputLocator = new MyInputPortLocator ( 16 , 0 ) ;
95110 e . createPort ( "hybrid" , outputLocator ) ;
96111 e . id = `vin` ;
97112 } else if ( type == "gnd" ) {
98113 var e = new shapeGnd ( { x : x , y : y } ) ;
99114 // var inputLocator = new draw2d.layout.locator.InputPortLocator();
100- var outputLocator = new MyInputPortLocator ( 16 , 0 ) ;
115+ var outputLocator = new MyInputPortLocator ( 16 , 0 ) ;
101116 // e.createPort("hybrid",inputLocator);
102117 e . createPort ( "hybrid" , outputLocator ) ;
103118 e . id = `gnd` ;
104119 } else if ( type == "vout" ) {
105120 var e = new shapeVout ( { x : x , y : y } ) ;
106- var inputLocator = new MyInputPortLocator ( 0 , 16 ) ;
121+ var inputLocator = new MyInputPortLocator ( 0 , 16 ) ;
107122 e . createPort ( "hybrid" , inputLocator ) ;
108123 // e.createPort("hybrid",outputLocator);
109124 e . id = `vout` ;
110125 } else if ( type == "op" ) {
111126 var e = new shapeOpamp ( { x : x , y : y } ) ;
112- var inputALocator = new MyInputPortLocator ( 0 , 32 ) ;
113- var inputBLocator = new MyInputPortLocator ( 0 , 64 ) ;
114- var outputLocator = new MyInputPortLocator ( 64 , 48 ) ;
127+ var inputALocator = new MyInputPortLocator ( 0 , 32 ) ;
128+ var inputBLocator = new MyInputPortLocator ( 0 , 64 ) ;
129+ var outputLocator = new MyInputPortLocator ( 64 , 48 ) ;
115130 e . createPort ( "hybrid" , inputALocator ) ;
116131 e . createPort ( "hybrid" , inputBLocator ) ;
117132 e . createPort ( "hybrid" , outputLocator ) ;
118- e . id = `op ` ;
133+ e . id = `op0 ` ;
119134 } else exit ( 'You gave a bad type: ' , type )
120135
121136 this . x = x ;
0 commit comments