54
59
* @return persistent data of this IconNodeInst.
57
public ImmutableIconInst getD() { return (ImmutableIconInst)super.getD(); }
60
* Method to add a Variable on this IconNodeInst.
61
* It may add a repaired copy of this Variable in some cases.
62
* @param var Variable to add.
65
public void addVar(Variable var) {
66
if (isParam(var.getKey()))
62
public ImmutableIconInst getD() {
63
return (ImmutableIconInst) super.getD();
67
* Modifies persistend data of this NodeInst.
68
* @param newD new persistent data.
69
* @param notify true to notify Undo system.
70
* @return true if persistent data was modified.
73
public boolean setD(ImmutableNodeInst newD, boolean notify) {
74
ImmutableIconInst oldD = getD();
75
if (newD.name != oldD.name) {
78
return super.setD(newD, notify);
82
public void setDInUndo(ImmutableNodeInst newD) {
83
ImmutableIconInst oldD = getD();
84
if (newD.name != oldD.name) {
87
super.setDInUndo(newD);
91
* Method to return the prototype of this IconNodeInst.
92
* @return the prototype of this IconNodeInst.
95
public Cell getProto() {
96
return (Cell) super.getProto();
100
* Method to add a Variable on this IconNodeInst.
101
* It may add a repaired copy of this Variable in some cases.
102
* @param var Variable to add.
105
public void addVar(Variable var) {
106
if (isParam(var.getKey())) {
67
107
throw new IllegalArgumentException(this + " already has a variable with name " + var);
68
109
super.addVar(var.withParam(false).withInherit(false));
72
* Method to return the Variable on this ElectricObject with a given key.
73
* @param key the key of the Variable.
74
* @return the Variable with that key and type, or null if there is no such Variable
75
* or default Variable value.
113
* Method to return the Variable on this ElectricObject with a given key.
114
* @param key the key of the Variable.
115
* @return the Variable with that key and type, or null if there is no such Variable
116
* or default Variable value.
76
117
* @throws NullPointerException if key is null
79
public Variable getVar(Variable.Key key)
120
public Variable getVar(Variable.Key key) {
82
122
if (key.isAttribute()) {
84
Variable param = getParameter((Variable.AttrKey)key);
124
Variable param = getParameter((Variable.AttrKey) key);
88
return getD().getVar(key);
129
return getD().getVar(key);
92
* Method to return the Parameter or Variable on this ElectricObject with a given key.
93
* @param key the key of the Parameter or Variable.
94
* @return the Parameter or Variable with that key, or null if there is no such Parameter or Variable Variable.
133
* Method to return the Parameter or Variable on this ElectricObject with a given key.
134
* @param key the key of the Parameter or Variable.
135
* @return the Parameter or Variable with that key, or null if there is no such Parameter or Variable Variable.
95
136
* @throws NullPointerException if key is null
98
public Variable getParameterOrVariable(Variable.Key key) {
139
public Variable getParameterOrVariable(Variable.Key key) {
100
141
if (key.isAttribute()) {
101
Variable param = getParameter((Variable.AttrKey)key);
142
Variable param = getParameter((Variable.AttrKey) key);
105
return getD().getVar(key);
147
return getD().getVar(key);
109
* Method to return an Iterator over all Parameters and Variables on this ElectricObject.
110
* @return an Iterator over all Parameters and Variables on this ElectricObject.
151
* Method to return an Iterator over all Parameters and Variables on this ElectricObject.
152
* @return an Iterator over all Parameters and Variables on this ElectricObject.
113
public Iterator<Variable> getParametersAndVariables() {
114
if (getD().getNumDefinedParameters() == 0)
155
public Iterator<Variable> getParametersAndVariables() {
156
if (getD().getNumDefinedParameters() == 0) {
115
157
return getVariables();
117
160
ArrayList<Variable> vars = new ArrayList<Variable>();
118
for (Iterator<Variable> it = getDefinedParameters(); it.hasNext(); )
161
for (Iterator<Variable> it = getDefinedParameters(); it.hasNext();) {
119
162
vars.add(it.next());
120
for (Iterator<Variable> it = getVariables(); it.hasNext(); ) {
164
for (Iterator<Variable> it = getVariables(); it.hasNext();) {
121
165
vars.add(it.next());
123
167
return vars.iterator();
212
262
public void delParameter(Variable.Key key) {
213
if (key instanceof Variable.AttrKey && setD(getD().withoutParam((Variable.AttrKey)key), true))
214
// check for side-effects of the change
263
if (key instanceof Variable.AttrKey && setD(getD().withoutParam((Variable.AttrKey) key), true)) // check for side-effects of the change
215
265
checkPossibleVariableEffects(key);
219
* Method to return true if the Variable on this NodeInst with given key is a parameter.
220
* Parameters are those Variables that have values on instances which are
221
* passed down the hierarchy into the contents.
270
* Method to return true if the Variable on this NodeInst with given key is a parameter.
271
* Parameters are those Variables that have values on instances which are
272
* passed down the hierarchy into the contents.
222
273
* @param varKey key to test
223
* @return true if the Variable with given key is a parameter.
274
* @return true if the Variable with given key is a parameter.
226
277
public boolean isParam(Variable.Key varKey) {
227
Cell icon = (Cell)getProto();
278
Cell icon = (Cell) getProto();
228
279
return icon.isParam(varKey);
232
* Updates the TextDescriptor on this NodeInst selected by varKey.
233
* The varKey may be a key of variable on this NodeInst or one of the
236
* NodeInst.NODE_PROTO
237
* If varKey doesn't select any text descriptor, no action is performed.
238
* The TextDescriptor gives information for displaying the Variable.
239
* @param varKey key of variable or special key.
240
* @param td new value TextDescriptor
283
* Updates the TextDescriptor on this NodeInst selected by varKey.
284
* The varKey may be a key of variable on this NodeInst or one of the
287
* NodeInst.NODE_PROTO
288
* If varKey doesn't select any text descriptor, no action is performed.
289
* The TextDescriptor gives information for displaying the Variable.
290
* @param varKey key of variable or special key.
291
* @param td new value TextDescriptor
243
public void setTextDescriptor(Variable.Key varKey, TextDescriptor td)
294
public void setTextDescriptor(Variable.Key varKey, TextDescriptor td) {
245
295
Variable param = getParameter(varKey);
246
296
if (param != null) {
247
297
td = td.withParam(true).withInherit(false).withUnit(param.getUnit());
251
301
super.setTextDescriptor(varKey, td);
255
* Method to create a Variable on this ElectricObject with the specified values.
256
* @param key the key of the Variable.
257
* @param value the object to store in the Variable.
258
* @param td text descriptor of the Variable
259
* @return the Variable that has been created.
305
* Method to create a Variable on this ElectricObject with the specified values.
306
* @param key the key of the Variable.
307
* @param value the object to store in the Variable.
308
* @param td text descriptor of the Variable
309
* @return the Variable that has been created.
262
public Variable newVar(Variable.Key key, Object value, TextDescriptor td)
312
public Variable newVar(Variable.Key key, Object value, TextDescriptor td) {
264
313
if (isParam(key)) {
265
314
addParameter(getParameter(key).withObject(value).withTextDescriptor(td));
266
315
return getParameter(key);
268
return super.newVar(key, value, td);
272
* Method to update a Variable on this ElectricObject with the specified values.
273
* If the Variable already exists, only the value is changed; the displayable attributes are preserved.
274
* @param key the key of the Variable.
275
* @param value the object to store in the Variable.
276
* @return the Variable that has been updated.
279
public Variable updateVar(Variable.Key key, Object value)
282
Variable param = getParameter(key);
283
addParameter(getParameter(key).withObject(value));
284
return getParameter(key);
286
return super.updateVar(key, value);
290
* Method to update a Parameter on this ElectricObject with the specified values.
291
* If the Variable already exists, only the value is changed; the displayable attributes are preserved.
292
* @param key the key of the Variable.
293
* @param value the object to store in the Variable.
294
* @return the Variable that has been updated.
297
public Variable updateParam(Variable.Key key, Object value)
300
Variable param = getParameter(key);
301
addParameter(getParameter(key).withObject(value));
302
return getParameter(key);
304
return super.updateVar(key, value);
308
* Method to update a text Variable on this ElectricObject with the specified values.
309
* If the Variable already exists, only the value is changed;
317
return super.newVar(key, value, td);
321
* Method to update a Variable on this ElectricObject with the specified values.
322
* If the Variable already exists, only the value is changed; the displayable attributes are preserved.
323
* @param key the key of the Variable.
324
* @param value the object to store in the Variable.
325
* @return the Variable that has been updated.
328
public Variable updateVar(Variable.Key key, Object value) {
330
Variable param = getParameter(key);
331
addParameter(getParameter(key).withObject(value));
332
return getParameter(key);
334
return super.updateVar(key, value);
338
* Method to update a Parameter on this ElectricObject with the specified values.
339
* If the Variable already exists, only the value is changed; the displayable attributes are preserved.
340
* @param key the key of the Variable.
341
* @param value the object to store in the Variable.
342
* @return the Variable that has been updated.
345
public Variable updateParam(Variable.Key key, Object value) {
347
Variable param = getParameter(key);
348
addParameter(getParameter(key).withObject(value));
349
return getParameter(key);
351
return super.updateVar(key, value);
355
* Method to update a text Variable on this ElectricObject with the specified values.
356
* If the Variable already exists, only the value is changed;
310
357
* the displayable attributes and Code are preserved.
311
* @param key the key of the Variable.
312
* @param text the text to store in the Variable.
313
* @return the Variable that has been updated.
358
* @param key the key of the Variable.
359
* @param text the text to store in the Variable.
360
* @return the Variable that has been updated.
316
public Variable updateVarText(Variable.Key key, String text)
363
public Variable updateVarText(Variable.Key key, String text) {
318
364
if (isParam(key)) {
319
Variable param = getParameter(key);
365
Variable param = getParameter(key);
320
366
addParameter(getParameter(key).withText(text));
321
367
return getParameter(key);
323
return super.updateVarText(key, text);
369
return super.updateVarText(key, text);
327
* Method to update a Variable on this ElectricObject with the specified code.
328
* If the Variable already exists, only the code is changed;
373
* Method to update a Variable on this ElectricObject with the specified code.
374
* If the Variable already exists, only the code is changed;
329
375
* the displayable attributes and value are preserved.
330
* @param key the key of the Variable.
331
* @param code the new code of the Variable.
332
* @return the Variable that has been updated.
376
* @param key the key of the Variable.
377
* @param code the new code of the Variable.
378
* @return the Variable that has been updated.
335
public Variable updateVarCode(Variable.Key key, CodeExpression.Code code)
381
public Variable updateVarCode(Variable.Key key, CodeExpression.Code code) {
337
382
if (isParam(key)) {
338
Variable param = getParameter(key);
383
Variable param = getParameter(key);
339
384
addParameter(getParameter(key).withCode(code));
340
385
return getParameter(key);
342
return super.updateVarCode(key, code);
387
return super.updateVarCode(key, code);
346
* Method to copy all variables from another ElectricObject to this ElectricObject.
347
* @param other the other ElectricObject from which to copy Variables.
391
* Method to copy all variables from another ElectricObject to this ElectricObject.
392
* @param other the other ElectricObject from which to copy Variables.
350
public void copyVarsFrom(ElectricObject other)
353
for (Iterator<Variable> it = other.getParametersAndVariables(); it.hasNext(); ) {
395
public void copyVarsFrom(ElectricObject other) {
397
for (Iterator<Variable> it = other.getParametersAndVariables(); it.hasNext();) {
354
398
Variable var = it.next();
355
if (isParam(var.getKey()))
399
if (isParam(var.getKey())) {
356
400
addParameter(var.withParam(true));
358
402
addVar(var.withParam(false));
362
407
// public void addParam(Variable var) {
363
408
// assert var.getTextDescriptor().isParam() && var.isInherit();
374
419
private static Variable composeInstParam(Variable iconParam, Variable instVar) {
375
420
boolean display = !iconParam.isInterior();
421
if (instVar != null) {
377
422
return instVar.withParam(true).withInherit(false).withInterior(false).withDisplay(display).withUnit(iconParam.getUnit());
378
424
return iconParam.withInherit(false).withInterior(false).withDisplay(display);
428
* Get Nodable by array index.
429
* @param arrayIndex the Nodable index.
430
* @return the desired Nodable.
433
public Nodable getNodable(int arrayIndex) {
434
if (nodables == null) {
435
nodables = new IconNodable[getNameKey().busWidth()];
436
for (int i = 0; i < nodables.length; i++) {
437
nodables[i] = new IconNodable(i);
440
return nodables[arrayIndex];
443
private class IconNodable implements Nodable {
447
IconNodable(int arrayIndex) {
448
this.arrayIndex = arrayIndex;
452
* Method to return the prototype of this Nodable.
453
* @return the prototype of this Nodable.
455
public NodeProto getProto() {
456
Cell iconCell = IconNodeInst.this.getProto();
457
Cell mainSchematics = iconCell.getCellGroup().getMainSchematics();
458
return mainSchematics != null ? mainSchematics : iconCell;
462
* Method to tell whether this is a cell instance.
463
* @return true becaue NetSchem objects are always cell instances.
465
public boolean isCellInstance() {
470
* Method to return the Cell that contains this Nodable.
471
* @return the Cell that contains this Nodable.
473
public Cell getParent() {
474
return IconNodeInst.this.getParent();
478
* Method to return the name of this Nodable.
479
* @return the name of this Nodable.
481
public String getName() {
482
return getNameKey().toString();
486
* Method to return the name key of this Nodable.
487
* @return the name key of this Nodable.
489
public Name getNameKey() {
490
return IconNodeInst.this.getNameKey().subname(arrayIndex);
494
* Method to return the Variable on this ElectricObject with a given key.
495
* @param key the key of the Variable.
496
* @return the Variable with that key, or null if there is no such Variable.
498
public Variable getVar(Variable.Key key) {
499
return IconNodeInst.this.getVar(key);
503
* Method to return the Parameter on this Nodable with the given key.
504
* If the parameter is not found on this Nodable, it
505
* is also searched for on the default var owner.
506
* @param key the key of the parameter
507
* @return the Parameter with that key, that may exist either on this Nodable
508
* or the default owner. Returns null if none found.
510
public Variable getParameter(Variable.Key key) {
511
return IconNodeInst.this.getParameter(key);
515
* Method to return the Parameter or Variable on this Nodable with a given key.
516
* @param key the key of the Parameter or Variable.
517
* @return the Parameter or Variable with that key, or null if there is no such Parameter or Variable Variable.
518
* @throws NullPointerException if key is null
520
public Variable getParameterOrVariable(Variable.Key key) {
521
return IconNodeInst.this.getParameterOrVariable(key);
525
* Method to tell if the Variable.Key is a defined parameters of this Nodable.
526
* Parameters which are not defined on Nodable take default values from Icon Cell.
527
* @param key the key of the parameter
528
* @return true if the key is a definded parameter of this Nodable
530
public boolean isDefinedParameter(Variable.Key key) {
531
return IconNodeInst.this.isDefinedParameter(key);
535
* Method to return an Iterator over all Parameters on this Nodable.
536
* This may also include any Parameters on the defaultVarOwner object that are not on this Nodable.
537
* @return an Iterator over all Parameters on this Nodable.
539
public Iterator<Variable> getParameters() {
540
return IconNodeInst.this.getParameters();
544
* Method to return an Iterator over defined Parameters on this Nodable.
545
* This doesn't include any Parameters on the defaultVarOwner object that are not on this Nodable.
546
* @return an Iterator over defined Parameters on this Nodable.
548
public Iterator<Variable> getDefinedParameters() {
549
return IconNodeInst.this.getDefinedParameters();
553
* Returns a printable version of this Nodable.
554
* @return a printable version of this Nodable.
557
public String toString() {
558
return "IconNodable " + getName();
561
// JKG: trying this out
562
public boolean contains(NodeInst ni, int arrayIndex) {
563
if (IconNodeInst.this == ni && this.arrayIndex == arrayIndex) {
569
public NodeInst getNodeInst() {
570
return IconNodeInst.this;
574
* Get array index of this Nodable
575
* @return the array index of this Nodable
577
public int getNodableArrayIndex() {