260
281
EPoint center = new EPoint(7, (yPos-2+lowY)/2);
261
282
PrimitiveNode np = Artwork.tech().boxNode;
262
283
NodeInst ni = NodeInst.makeInstance(np, center, width, height, cell);
284
ni.setName(name.replaceAll("@", "_"));
264
285
TextDescriptor newTD = ni.getTextDescriptor(NodeInst.NODE_NAME).withRelSize(2);
265
286
ni.setTextDescriptor(NodeInst.NODE_NAME, newTD);
268
289
// now make the schematic cells
269
290
for(String name : allCells.keySet())
271
292
SubcktDef sd = allCells.get(name);
272
Cell cell = Cell.makeInstance(lib, name + "{sch}");
273
if (sd.iconCell != null)
275
EPoint center = new EPoint(0, 15);
276
NodeInst.makeInstance(sd.iconCell, center, sd.iconCell.getDefWidth(), sd.iconCell.getDefHeight(), cell);
280
double pPos = 0, nPos = 0;
294
// use the placement tool to situate the objects
295
List<PlacementNode> nodesToPlace = new ArrayList<PlacementNode>();
296
Map<String,PlacementNetwork> allNetworks = new HashMap<String,PlacementNetwork>();
297
List<PlacementExport> exportsToPlace = new ArrayList<PlacementExport>();
299
// make PlacementNodes for the transistors
281
300
for(TransistorDef td : sd.transistors)
283
EPoint center = null;
284
PrimitiveNode.Function func = null;
285
if (td.type.equals("p"))
287
center = new EPoint(pPos, 5);
289
func = PrimitiveNode.Function.TRAPMOS;
292
center = new EPoint(nPos, -5);
294
func = PrimitiveNode.Function.TRANMOS;
303
if (td.type.equals("p")) bits = Schematics.getPrimitiveFunctionBits(PrimitiveNode.Function.TRAPMOS); else
304
bits = Schematics.getPrimitiveFunctionBits(PrimitiveNode.Function.TRANMOS);
296
305
PrimitiveNode np = Schematics.tech().transistorNode;
297
Orientation o = Orientation.R;
298
NodeInst ni = NodeInst.makeInstance(np, center, np.getDefWidth(), np.getDefHeight(),
299
cell, o, "m" + td.name, func);
300
TextDescriptor tdesc = TextDescriptor.newTextDescriptor(MutableTextDescriptor.getNodeTextDescriptor());
301
TextDescriptor.Rotation r = TextDescriptor.Rotation.getRotation(270);
302
ni.setTextDescriptor(NodeInst.NODE_NAME, tdesc.withRotation(r).withPos(TextDescriptor.Position.DOWNLEFT));
303
if (td.width != null)
305
Variable var = ni.newDisplayVar(Schematics.ATTR_WIDTH, td.width);
306
TextDescriptor newTD = var.getTextDescriptor().
307
withRotation(r).withOff(0.5, -0.5).withRelSize(1).withPos(TextDescriptor.Position.DOWN);
308
ni.setTextDescriptor(Schematics.ATTR_WIDTH, newTD);
310
if (td.length != null)
312
Variable var = ni.newDisplayVar(Schematics.ATTR_LENGTH, td.length);
313
TextDescriptor newTD = var.getTextDescriptor().
314
withRotation(r).withOff(-0.5, -0.75).withRelSize(0.5).withPos(TextDescriptor.Position.DOWN);
315
ni.setTextDescriptor(Schematics.ATTR_LENGTH, newTD);
317
PortInst piSource = ni.getTransistorSourcePort();
318
addLead(piSource, 0, -2, cell, td.source, sd.exports, sd.usedExports);
319
PortInst piGate = ni.getTransistorGatePort();
320
addLead(piGate, -2, 0, cell, td.gate, sd.exports, sd.usedExports);
321
PortInst piDrain = ni.getTransistorDrainPort();
322
addLead(piDrain, 0, 2, cell, td.drain, sd.exports, sd.usedExports);
306
NodeInst niDummy = NodeInst.makeDummyInstance(np);
308
List<PlacementPort> ports = new ArrayList<PlacementPort>();
309
PortInst piSource = niDummy.getTransistorSourcePort();
310
ports.add(addPlacementPort(niDummy, piSource, td.source, allNetworks, sd.exports, sd.usedExports, exportsToPlace));
311
PortInst piGate = niDummy.getTransistorGatePort();
312
ports.add(addPlacementPort(niDummy, piGate, td.gate, allNetworks, sd.exports, sd.usedExports, exportsToPlace));
313
PortInst piDrain = niDummy.getTransistorDrainPort();
314
ports.add(addPlacementPort(niDummy, piDrain, td.drain, allNetworks, sd.exports, sd.usedExports, exportsToPlace));
316
PlacementNode plNode = new PlacementNode(np, "m" + td.name, bits, np.getDefWidth(), np.getDefHeight(), ports);
317
nodesToPlace.add(plNode);
318
for(PlacementPort plPort : ports)
319
plPort.setPlacementNode(plNode);
320
plNode.setOrientation(Orientation.IDENT);
321
if (td.width != null) plNode.addVariable(Schematics.ATTR_WIDTH, td.width);
322
if (td.length != null) plNode.addVariable(Schematics.ATTR_LENGTH, td.length);
325
325
// place resistors and capacitors
326
326
for(ResistorDef rd : sd.resistors)
328
EPoint center = new EPoint(pPos, 5);
330
328
PrimitiveNode np = Schematics.tech().resistorNode;
331
NodeInst ni = NodeInst.makeInstance(np, center, np.getDefWidth(), np.getDefHeight(),
332
cell, Orientation.IDENT, "r" + rd.name);
333
if (rd.resistance != null)
335
Variable var = ni.newDisplayVar(Schematics.SCHEM_RESISTANCE, rd.resistance);
336
TextDescriptor newTD = var.getTextDescriptor().
337
withOff(0, 0.5).withPos(TextDescriptor.Position.UP);
338
ni.setTextDescriptor(Schematics.SCHEM_RESISTANCE, newTD);
340
PortInst piSource = ni.getPortInst(0);
341
addLead(piSource, -2, 0, cell, rd.left, sd.exports, sd.usedExports);
342
PortInst piGate = ni.getPortInst(1);
343
addLead(piGate, 2, 0, cell, rd.right, sd.exports, sd.usedExports);
329
NodeInst niDummy = NodeInst.makeDummyInstance(np);
331
List<PlacementPort> ports = new ArrayList<PlacementPort>();
332
PortInst piSource = niDummy.getPortInst(0);
333
ports.add(addPlacementPort(niDummy, piSource, rd.left, allNetworks, sd.exports, sd.usedExports, exportsToPlace));
334
PortInst piGate = niDummy.getPortInst(1);
335
ports.add(addPlacementPort(niDummy, piGate, rd.right, allNetworks, sd.exports, sd.usedExports, exportsToPlace));
337
PlacementNode plNode = new PlacementNode(np, "r" + rd.name, 0, np.getDefWidth(), np.getDefHeight(), ports);
338
nodesToPlace.add(plNode);
339
for(PlacementPort plPort : ports)
340
plPort.setPlacementNode(plNode);
341
plNode.setOrientation(Orientation.IDENT);
342
if (rd.resistance != null) plNode.addVariable(Schematics.SCHEM_RESISTANCE, rd.resistance);
345
344
for(CapacitorDef cd : sd.capacitors)
347
EPoint center = new EPoint(nPos, -5);
349
346
PrimitiveNode np = Schematics.tech().capacitorNode;
350
NodeInst ni = NodeInst.makeInstance(np, center, np.getDefWidth(), np.getDefHeight(),
351
cell, Orientation.IDENT, "c" + cd.name);
352
if (cd.capacitance != null)
353
ni.newDisplayVar(Schematics.SCHEM_CAPACITANCE, cd.capacitance);
354
PortInst piSource = ni.getPortInst(0);
355
addLead(piSource, 0, 2, cell, cd.top, sd.exports, sd.usedExports);
356
PortInst piGate = ni.getPortInst(1);
357
addLead(piGate, 0, -2, cell, cd.bottom, sd.exports, sd.usedExports);
347
NodeInst niDummy = NodeInst.makeDummyInstance(np);
349
List<PlacementPort> ports = new ArrayList<PlacementPort>();
350
PortInst piSource = niDummy.getPortInst(0);
351
ports.add(addPlacementPort(niDummy, piSource, cd.top, allNetworks, sd.exports, sd.usedExports, exportsToPlace));
352
PortInst piGate = niDummy.getPortInst(1);
353
ports.add(addPlacementPort(niDummy, piGate, cd.bottom, allNetworks, sd.exports, sd.usedExports, exportsToPlace));
355
PlacementNode plNode = new PlacementNode(np, "c" + cd.name, 0, np.getDefWidth(), np.getDefHeight(), ports);
356
nodesToPlace.add(plNode);
357
for(PlacementPort plPort : ports)
358
plPort.setPlacementNode(plNode);
359
plNode.setOrientation(Orientation.IDENT);
360
if (cd.capacitance != null) plNode.addVariable(Schematics.SCHEM_CAPACITANCE, cd.capacitance);
360
363
// place instances
362
364
for(InstanceDef id : sd.instances)
364
366
SubcktDef subSD = allCells.get(id.instName);
370
372
Cell np = subSD.iconCell;
371
EPoint center = new EPoint(iPos, -10-np.getDefHeight());
373
NodeInst ni = NodeInst.makeInstance(np, center, np.getDefWidth(), np.getDefHeight(), cell);
374
ni.setName(id.name.replace('@', '_'));
375
TextDescriptor newTD = ni.getTextDescriptor(NodeInst.NODE_NAME).
376
withOff(1, -1).withPos(TextDescriptor.Position.DOWN);
377
ni.setTextDescriptor(NodeInst.NODE_NAME, newTD);
373
NodeInst niDummy = NodeInst.makeDummyInstance(np);
378
374
if (subSD.exports.size() != id.signals.size())
380
376
System.out.println("Error: Subcircuit " + id.instName + " has " + subSD.exports.size() +
381
" exports but instance " + id.name + " of it in cell " + cell.describe(false) +
377
" exports but instance " + id.name + " of it in cell " + name + "{sch}" +
382
378
" has " + id.signals.size() + " signals on it");
381
List<PlacementPort> ports = new ArrayList<PlacementPort>();
385
382
for(int i=0; i<subSD.exports.size(); i++)
387
384
PortProto pp = subSD.iconCell.findPortProto(subSD.exports.get(i));
388
385
if (pp == null) continue;
389
PortInst pi = ni.findPortInstFromProto(pp);
386
PortInst pi = niDummy.findPortInstFromProto(pp);
390
387
String sigName = id.signals.get(i);
391
addLead(pi, -2, 0, cell, sigName, sd.exports, sd.usedExports);
388
ports.add(addPlacementPort(niDummy, pi, sigName, allNetworks, sd.exports, sd.usedExports, exportsToPlace));
391
PlacementNode plNode = new PlacementNode(np, id.name.replace('@', '_'), 0, np.getDefWidth(), np.getDefHeight(), ports);
392
nodesToPlace.add(plNode);
393
for(PlacementPort plPort : ports)
394
plPort.setPlacementNode(plNode);
395
plNode.setOrientation(Orientation.IDENT);
395
398
// add dummy pins for unused exports
396
double dummyPos = 30;
397
399
for(String export : sd.exports)
399
401
if (sd.usedExports.contains(export)) continue;
400
EPoint ctr = new EPoint(dummyPos, 15);
402
402
PrimitiveNode np = Schematics.tech().wirePinNode;
403
NodeInst ni = NodeInst.makeInstance(np, ctr, np.getDefWidth(), np.getDefHeight(), cell);
404
Export.newInstance(cell, ni.getOnlyPortInst(), export, PortCharacteristic.UNKNOWN);
403
NodeInst niDummy = NodeInst.makeDummyInstance(np);
404
List<PlacementPort> ports = new ArrayList<PlacementPort>();
405
PortInst pi = niDummy.getPortInst(0);
406
ports.add(addPlacementPort(niDummy, pi, export, allNetworks, sd.exports, sd.usedExports, exportsToPlace));
408
PlacementNode plNode = new PlacementNode(np, null, 0, np.getDefWidth(), np.getDefHeight(), ports);
409
nodesToPlace.add(plNode);
410
for(PlacementPort plPort : ports)
411
plPort.setPlacementNode(plNode);
412
plNode.setOrientation(Orientation.IDENT);
415
// make a list of PlacementNetworks
416
List<PlacementNetwork> nets = new ArrayList<PlacementNetwork>();
417
for(String netName : allNetworks.keySet())
419
PlacementNetwork net = allNetworks.get(netName);
420
for(PlacementPort port : net.getPortsOnNet())
421
port.setPlacementNetwork(net);
422
if (net.getPortsOnNet() == null || net.getPortsOnNet().size() <= 1) continue;
427
pla.doPlacement(lib, name + "{sch}", nodesToPlace, nets, exportsToPlace, sd.iconCell);
430
// Cell cell = Cell.makeInstance(lib, name + "{sch}");
431
// if (sd.iconCell != null)
433
// EPoint center = new EPoint(0, 15);
434
// NodeInst.makeInstance(sd.iconCell, center, sd.iconCell.getDefWidth(), sd.iconCell.getDefHeight(), cell);
437
// // place transistors
438
// double pPos = 0, nPos = 0;
439
// for(TransistorDef td : sd.transistors)
441
// EPoint center = null;
442
// PrimitiveNode.Function func = null;
443
// if (td.type.equals("p"))
445
// center = new EPoint(pPos, 5);
447
// func = PrimitiveNode.Function.TRAPMOS;
450
// center = new EPoint(nPos, -5);
452
// func = PrimitiveNode.Function.TRANMOS;
454
// PrimitiveNode np = Schematics.tech().transistorNode;
455
// Orientation o = Orientation.R;
456
// NodeInst ni = NodeInst.makeInstance(np, center, np.getDefWidth(), np.getDefHeight(),
457
// cell, o, "m" + td.name, func);
458
// TextDescriptor tdesc = TextDescriptor.newTextDescriptor(MutableTextDescriptor.getNodeTextDescriptor());
459
// TextDescriptor.Rotation r = TextDescriptor.Rotation.getRotation(270);
460
// ni.setTextDescriptor(NodeInst.NODE_NAME, tdesc.withRotation(r).withPos(TextDescriptor.Position.DOWNLEFT));
461
// if (td.width != null)
463
// Variable var = ni.newDisplayVar(Schematics.ATTR_WIDTH, td.width);
464
// TextDescriptor newTD = var.getTextDescriptor().
465
// withRotation(r).withOff(0.5, -0.5).withRelSize(1).withPos(TextDescriptor.Position.DOWN);
466
// ni.setTextDescriptor(Schematics.ATTR_WIDTH, newTD);
468
// if (td.length != null)
470
// Variable var = ni.newDisplayVar(Schematics.ATTR_LENGTH, td.length);
471
// TextDescriptor newTD = var.getTextDescriptor().
472
// withRotation(r).withOff(-0.5, -0.75).withRelSize(0.5).withPos(TextDescriptor.Position.DOWN);
473
// ni.setTextDescriptor(Schematics.ATTR_LENGTH, newTD);
475
// PortInst piSource = ni.getTransistorSourcePort();
476
// addLead(piSource, 0, -2, cell, td.source, sd.exports, sd.usedExports);
477
// PortInst piGate = ni.getTransistorGatePort();
478
// addLead(piGate, -2, 0, cell, td.gate, sd.exports, sd.usedExports);
479
// PortInst piDrain = ni.getTransistorDrainPort();
480
// addLead(piDrain, 0, 2, cell, td.drain, sd.exports, sd.usedExports);
483
// // place resistors and capacitors
484
// for(ResistorDef rd : sd.resistors)
486
// EPoint center = new EPoint(pPos, 5);
488
// PrimitiveNode np = Schematics.tech().resistorNode;
489
// NodeInst ni = NodeInst.makeInstance(np, center, np.getDefWidth(), np.getDefHeight(),
490
// cell, Orientation.IDENT, "r" + rd.name);
491
// if (rd.resistance != null)
493
// Variable var = ni.newDisplayVar(Schematics.SCHEM_RESISTANCE, rd.resistance);
494
// TextDescriptor newTD = var.getTextDescriptor().
495
// withOff(0, 0.5).withPos(TextDescriptor.Position.UP);
496
// ni.setTextDescriptor(Schematics.SCHEM_RESISTANCE, newTD);
498
// PortInst piSource = ni.getPortInst(0);
499
// addLead(piSource, -2, 0, cell, rd.left, sd.exports, sd.usedExports);
500
// PortInst piGate = ni.getPortInst(1);
501
// addLead(piGate, 2, 0, cell, rd.right, sd.exports, sd.usedExports);
503
// for(CapacitorDef cd : sd.capacitors)
505
// EPoint center = new EPoint(nPos, -5);
507
// PrimitiveNode np = Schematics.tech().capacitorNode;
508
// NodeInst ni = NodeInst.makeInstance(np, center, np.getDefWidth(), np.getDefHeight(),
509
// cell, Orientation.IDENT, "c" + cd.name);
510
// if (cd.capacitance != null)
511
// ni.newDisplayVar(Schematics.SCHEM_CAPACITANCE, cd.capacitance);
512
// PortInst piSource = ni.getPortInst(0);
513
// addLead(piSource, 0, 2, cell, cd.top, sd.exports, sd.usedExports);
514
// PortInst piGate = ni.getPortInst(1);
515
// addLead(piGate, 0, -2, cell, cd.bottom, sd.exports, sd.usedExports);
518
// // place instances
520
// for(InstanceDef id : sd.instances)
522
// SubcktDef subSD = allCells.get(id.instName);
523
// if (subSD == null)
525
// System.out.println("Cannot find subcircuit "+id.instName);
528
// Cell np = subSD.iconCell;
529
// EPoint center = new EPoint(iPos, -10-np.getDefHeight());
531
// NodeInst ni = NodeInst.makeInstance(np, center, np.getDefWidth(), np.getDefHeight(), cell);
532
// ni.setName(id.name.replace('@', '_'));
533
// TextDescriptor newTD = ni.getTextDescriptor(NodeInst.NODE_NAME).
534
// withOff(1, -1).withPos(TextDescriptor.Position.DOWN);
535
// ni.setTextDescriptor(NodeInst.NODE_NAME, newTD);
536
// if (subSD.exports.size() != id.signals.size())
538
// System.out.println("Error: Subcircuit " + id.instName + " has " + subSD.exports.size() +
539
// " exports but instance " + id.name + " of it in cell " + cell.describe(false) +
540
// " has " + id.signals.size() + " signals on it");
543
// for(int i=0; i<subSD.exports.size(); i++)
545
// PortProto pp = subSD.iconCell.findPortProto(subSD.exports.get(i));
546
// if (pp == null) continue;
547
// PortInst pi = ni.findPortInstFromProto(pp);
548
// String sigName = id.signals.get(i);
549
// addLead(pi, -2, 0, cell, sigName, sd.exports, sd.usedExports);
553
// // add dummy pins for unused exports
554
// double dummyPos = 30;
555
// for(String export : sd.exports)
557
// if (sd.usedExports.contains(export)) continue;
558
// EPoint ctr = new EPoint(dummyPos, 15);
560
// PrimitiveNode np = Schematics.tech().wirePinNode;
561
// NodeInst ni = NodeInst.makeInstance(np, ctr, np.getDefWidth(), np.getDefHeight(), cell);
562
// Export.newInstance(cell, ni.getOnlyPortInst(), export, PortCharacteristic.UNKNOWN);
409
private void addLead(PortInst pi, double dX, double dY, Cell cell, String name, List<String> exports, Set<String> usedExports)
567
private PlacementPort addPlacementPort(NodeInst ni, PortInst pi, String name, Map<String,PlacementNetwork> allNetworks,
568
List<String> exports, Set<String> usedExports, List<PlacementExport> exportsToPlace)
411
EPoint ctr1 = pi.getCenter();
412
EPoint ctr2 = new EPoint(ctr1.getX()+dX, ctr1.getY()+dY);
414
PrimitiveNode np = Schematics.tech().wirePinNode;
415
NodeInst ni = NodeInst.makeInstance(np, ctr2, np.getDefWidth(), np.getDefHeight(), cell);
416
ArcProto ap = Schematics.tech().wire_arc;
417
PortInst pi2 = ni.getOnlyPortInst();
418
ArcInst ai = ArcInst.makeInstance(ap, pi, pi2);
420
name = name.replace('@', '_');
570
PlacementNetwork net = allNetworks.get(name);
571
if (net == null) allNetworks.put(name, net = new PlacementNetwork(new ArrayList<PlacementPort>()));
572
List<PlacementPort> portsOnNet = net.getPortsOnNet();
574
Poly poly = pi.getPoly();
575
double offX = poly.getCenterX() - ni.getTrueCenterX();
576
double offY = poly.getCenterY() - ni.getTrueCenterY();
577
PlacementPort plPort = new PlacementPort(offX, offY, pi.getPortProto());
578
portsOnNet.add(plPort);
580
// see if this port is exported
421
581
if (exports.contains(name) && !usedExports.contains(name))
423
583
usedExports.add(name);
424
Export.newInstance(cell, pi2, name, PortCharacteristic.UNKNOWN);
428
TextDescriptor.Position p = (dX == 0) ? TextDescriptor.Position.LEFT : TextDescriptor.Position.DOWN;
429
TextDescriptor newTD = ai.getTextDescriptor(ArcInst.ARC_NAME).withPos(p);
430
ai.setTextDescriptor(ArcInst.ARC_NAME, newTD);
584
PlacementExport plExport = new PlacementExport(plPort, name, PortCharacteristic.UNKNOWN);
585
exportsToPlace.add(plExport);
590
// private void addLead(PortInst pi, double dX, double dY, Cell cell, String name, List<String> exports, Set<String> usedExports)
592
// EPoint ctr1 = pi.getCenter();
593
// EPoint ctr2 = new EPoint(ctr1.getX()+dX, ctr1.getY()+dY);
595
// PrimitiveNode np = Schematics.tech().wirePinNode;
596
// NodeInst ni = NodeInst.makeInstance(np, ctr2, np.getDefWidth(), np.getDefHeight(), cell);
597
// ArcProto ap = Schematics.tech().wire_arc;
598
// PortInst pi2 = ni.getOnlyPortInst();
599
// ArcInst ai = ArcInst.makeInstance(ap, pi, pi2);
601
// name = name.replace('@', '_');
602
// if (exports.contains(name) && !usedExports.contains(name))
604
// usedExports.add(name);
605
// Export.newInstance(cell, pi2, name, PortCharacteristic.UNKNOWN);
609
// TextDescriptor.Position p = (dX == 0) ? TextDescriptor.Position.LEFT : TextDescriptor.Position.DOWN;
610
// TextDescriptor newTD = ai.getTextDescriptor(ArcInst.ARC_NAME).withPos(p);
611
// ai.setTextDescriptor(ArcInst.ARC_NAME, newTD);
434
615
private String lastLine = null;
436
617
private String getNextLine()