@@ -21,6 +21,7 @@ export class View extends draw2d.Canvas {
2121 this . rCounter = 0 ;
2222 this . cCounter = 0 ;
2323 this . lCounter = 0 ;
24+ this . iprbCounter = 0 ;
2425 this . elements = [ ] ;
2526 this . dropCb = dropCB ;
2627 this . getElements = getElements ;
@@ -58,7 +59,7 @@ export class View extends draw2d.Canvas {
5859 } else return name ;
5960 }
6061
61- addShapeToSchem ( type , x , y ) {
62+ addShapeToSchem ( type , x , y , id ) {
6263 // console.log(type, x, y)
6364 // console.log(this.getElements());
6465
@@ -82,6 +83,17 @@ export class View extends draw2d.Canvas {
8283 } ,
8384 } ) ;
8485
86+ if ( id ) {
87+ if ( ( type == "res" ) || ( type == "cap" ) || ( type == "ind" ) || ( type == "iprobe" ) || ( type == "op" ) ) {
88+ var newCount = parseInt ( id . slice ( 1 ) )
89+ if ( type == "res" ) this . rCounter = Math . max ( this . rCounter , newCount ) ;
90+ if ( type == "cap" ) this . cCounter = Math . max ( this . cCounter , newCount ) ;
91+ if ( type == "ind" ) this . lCounter = Math . max ( this . lCounter , newCount ) ;
92+ if ( type == "iprobe" ) this . iprbCounter = Math . max ( this . iprbCounter , newCount ) ;
93+ if ( type == "op" ) this . opCounter = Math . max ( this . opCounter , newCount ) ;
94+ }
95+ }
96+
8597 // console.log(x, y)
8698 x = 16 * Math . round ( x / 16 ) ;
8799 y = 16 * Math . round ( y / 16 ) ;
@@ -92,7 +104,8 @@ export class View extends draw2d.Canvas {
92104 var outputLocator = new MyInputPortLocator ( 48 , 16 ) ;
93105 e . createPort ( "hybrid" , inputLocator ) ;
94106 e . createPort ( "hybrid" , outputLocator ) ;
95- e . id = `R${ this . rCounter } ` ;
107+ if ( id ) e . id = id ;
108+ else e . id = `R${ this . rCounter } ` ;
96109 e . add ( new draw2d . shape . basic . Text ( { text : this . getName ( e . id , this . getElements ( ) ) , stroke : 0 } ) , new draw2d . layout . locator . TopLocator ( ) ) ;
97110 this . rCounter = this . rCounter + 1 ;
98111 e . installEditPolicy ( new SelectionMenuPolicy ( ) ) ;
@@ -102,7 +115,8 @@ export class View extends draw2d.Canvas {
102115 var outputLocator = new MyInputPortLocator ( 16 , 48 ) ;
103116 e . createPort ( "hybrid" , inputLocator ) ;
104117 e . createPort ( "hybrid" , outputLocator ) ;
105- e . id = `C${ this . cCounter } ` ;
118+ if ( id ) e . id = id ;
119+ else e . id = `C${ this . cCounter } ` ;
106120 e . add ( new draw2d . shape . basic . Text ( { text : this . getName ( e . id , this . getElements ( ) ) , stroke : 0 } ) , new draw2d . layout . locator . RightLocator ( ) ) ;
107121 this . cCounter = this . cCounter + 1 ;
108122 e . installEditPolicy ( new SelectionMenuPolicy ( ) ) ;
@@ -112,7 +126,8 @@ export class View extends draw2d.Canvas {
112126 var outputLocator = new MyInputPortLocator ( 65 , 16 ) ;
113127 e . createPort ( "hybrid" , inputLocator ) ;
114128 e . createPort ( "hybrid" , outputLocator ) ;
115- e . id = `L${ this . lCounter } ` ;
129+ if ( id ) e . id = id ;
130+ else e . id = `L${ this . lCounter } ` ;
116131 e . add ( new draw2d . shape . basic . Text ( { text : this . getName ( e . id , this . getElements ( ) ) , stroke : 0 } ) , new draw2d . layout . locator . TopLocator ( ) ) ;
117132 this . lCounter = this . lCounter + 1 ;
118133 e . installEditPolicy ( new SelectionMenuPolicy ( ) ) ;
@@ -139,6 +154,17 @@ export class View extends draw2d.Canvas {
139154 e . createPort ( "hybrid" , inputLocator ) ;
140155 // e.createPort("hybrid",outputLocator);
141156 e . id = `xvout` ;
157+ } else if ( type == "iprobe" ) {
158+ var e = new shapeIprobe ( { x : x , y : y } ) ;
159+ var inputLocator = new MyInputPortLocator ( 0 , 32 ) ;
160+ e . createPort ( "hybrid" , inputLocator ) ;
161+ e . createPort ( "hybrid" , new MyInputPortLocator ( 64 , 32 ) ) ;
162+ // e.createPort("hybrid",outputLocator);
163+ if ( id ) e . id = id ;
164+ else e . id = `Y${ this . iprbCounter } ` ;
165+ e . add ( new draw2d . shape . basic . Text ( { text : this . getName ( `iPrb${ this . iprbCounter } ` , this . getElements ( ) ) , stroke : 0 } ) , new draw2d . layout . locator . TopLocator ( ) ) ;
166+ this . iprbCounter = this . iprbCounter + 1 ;
167+
142168 } else if ( type == "op" ) {
143169 var e = new shapeOpamp ( { x : x , y : y } ) ;
144170 var inputALocator = new MyInputPortLocator ( 0 , 32 ) ;
@@ -147,16 +173,17 @@ export class View extends draw2d.Canvas {
147173 e . createPort ( "hybrid" , inputALocator ) ;
148174 e . createPort ( "hybrid" , inputBLocator ) ;
149175 e . createPort ( "hybrid" , outputLocator ) ;
150- e . id = `op${ this . opCounter } ` ;
176+ if ( id ) e . id = id ;
177+ else e . id = `op${ this . opCounter } ` ;
151178 this . opCounter = this . opCounter + 1 ;
152179 } else console . log ( "ERROR: You gave a bad type: " , type ) ;
153180
154181 this . x = x ;
155182 this . y = y ;
156183 e . resizeable = false ;
184+ // console.log('add', add);
157185 var add = this . dropCb ( e , ( a ) => this . addToSchematic ( a ) ) ;
158186 // add = true;
159- // console.log('add', add);
160187
161188 // if (add) {
162189 // e.resizeable = false;
@@ -175,6 +202,7 @@ export class View extends draw2d.Canvas {
175202 this . cCounter = 0 ;
176203 this . lCounter = 0 ;
177204 this . opCounter = 0 ;
205+ this . iprbCounter = 0 ;
178206 console . log ( "cleared, now adding this" , startupSchematic ) ;
179207
180208 var connections = [ ] ;
@@ -188,18 +216,22 @@ export class View extends draw2d.Canvas {
188216 connections . push ( newConn ) ;
189217 id = id + 1 ;
190218 } else {
219+ // console.log(item)
191220 var type ;
192- var firstLetter = item . firstLetter ;
221+ var firstLetter = Array . from ( item . id ) [ 0 ] ;
222+
223+ // var firstLetter = item.firstLetter;
193224 if ( firstLetter == "R" ) type = "res" ;
194225 else if ( firstLetter == "C" ) type = "cap" ;
195226 else if ( firstLetter == "L" ) type = "ind" ;
196227 else if ( firstLetter == "g" ) type = "gnd" ;
197228 else if ( firstLetter == "v" ) type = "vin" ;
198229 else if ( firstLetter == "i" ) type = "iin" ;
199230 else if ( firstLetter == "x" ) type = "xvout" ;
231+ else if ( firstLetter == "Y" ) type = "iprobe" ;
200232 // console.log(item, type)
201233
202- this . addShapeToSchem ( type , item . x , item . y ) ;
234+ this . addShapeToSchem ( type , item . x , item . y , item . id ) ;
203235 }
204236 } ) ;
205237
0 commit comments