📄 vectorcache.java
字号:
} VectorCell findVectorCell(CellId cellId, Orientation orient) { VectorCellGroup vcg = findCellGroup(cellId); orient = orient.canonic(); VectorCell vc = vcg.orientations.get(orient); if (vc == null) { vc = new VectorCell(vcg, orient); vcg.orientations.put(orient, vc); } return vc; } VectorCell drawCell(CellId cellId, Orientation prevTrans, VarContext context, double scale) { VectorCell vc = findVectorCell(cellId, prevTrans); if (vc.vcg.isParameterized || !vc.valid) { varContext = vc.vcg.isParameterized ? context : null; curScale = scale; // Fix it later. Multiple Strings positioning shouldn't use scale. vc.init(database.getCell(cellId)); } return vc; } public static VectorBase[] drawNode(NodeInst ni) { VectorCache cache = new VectorCache(EDatabase.clientDatabase()); VectorCell vc = cache.newDummyVectorCell(); cache.drawNode(ni, GenMath.MATID, vc); ArrayList<VectorBase> allShapes = new ArrayList<VectorBase>(); allShapes.addAll(vc.filledShapes); allShapes.addAll(vc.shapes);// allShapes.addAll(vc.topOnlyShapes); Collections.sort(allShapes, shapeByLayer); return allShapes.toArray(new VectorBase[allShapes.size()]); } public static VectorBase[] drawPolys(Poly[] polys) { VectorCache cache = new VectorCache(EDatabase.clientDatabase()); VectorCell vc = cache.newDummyVectorCell(); cache.drawPolys(polys, GenMath.MATID, vc, false, VectorText.TEXTTYPEARC, false); ArrayList<VectorBase> allShapes = new ArrayList<VectorBase>(); allShapes.addAll(vc.filledShapes); allShapes.addAll(vc.shapes);// allShapes.addAll(vc.topOnlyShapes); Collections.sort(allShapes, shapeByLayer); return allShapes.toArray(new VectorBase[allShapes.size()]); } private VectorCell newDummyVectorCell() { return new VectorCell(); } /** * Method to insert a manhattan rectangle into the vector cache for a Cell. * @param lX the low X of the manhattan rectangle. * @param lY the low Y of the manhattan rectangle. * @param hX the high X of the manhattan rectangle. * @param hY the high Y of the manhattan rectangle. * @param layer the layer on which to draw the rectangle. * @param cellId the Cell in which to insert the rectangle. */ public void addBoxToCell(double lX, double lY, double hX, double hY, Layer layer, CellId cellId) { List<VectorBase> addToThisCell = addPolyToCell.get(cellId); if (addToThisCell == null) { addToThisCell = new ArrayList<VectorBase>(); addPolyToCell.put(cellId, addToThisCell); } EGraphics graphics = null; if (layer != null) graphics = layer.getGraphics(); VectorManhattan vm = new VectorManhattan(lX, lY, hX, hY, layer, graphics, false); addToThisCell.add(vm); } /** * Method to insert a manhattan rectangle into the vector cache for a Cell. * @param lX the low X of the manhattan rectangle. * @param lY the low Y of the manhattan rectangle. * @param hX the high X of the manhattan rectangle. * @param hY the high Y of the manhattan rectangle. * @param cellId the Cell in which to insert the rectangle. */ public void addInstanceToCell(double lX, double lY, double hX, double hY, CellId cellId) { List<VectorLine> addToThisCell = addInstToCell.get(cellId); if (addToThisCell == null) { addToThisCell = new ArrayList<VectorLine>(); addInstToCell.put(cellId, addToThisCell); } // store the subcell addToThisCell.add(new VectorLine(lX, lY, hX, lY, 0, null, instanceGraphics)); addToThisCell.add(new VectorLine(hX, lY, hX, hY, 0, null, instanceGraphics)); addToThisCell.add(new VectorLine(hX, hY, lX, hY, 0, null, instanceGraphics)); addToThisCell.add(new VectorLine(lX, hY, lX, lY, 0, null, instanceGraphics)); } private static final PrimitivePortId busPinPortId = Schematics.tech().busPinNode.getPort(0).getId(); /** * Method to tell whether a Cell is parameterized. * Code is taken from tool.drc.Quick.checkEnumerateProtos * Could also use the code in tool.io.output.Spice.checkIfParameterized * @param cellRevision the Cell to examine * @return true if the cell has parameters */ private static boolean isCellParameterized(CellRevision cellRevision) { if (cellRevision.d.getNumParameters() > 0) return true; // look for any Java coded stuff (Logical Effort calls) for (ImmutableNodeInst n: cellRevision.nodes) { if (n instanceof ImmutableIconInst) { for(Iterator<Variable> vIt = ((ImmutableIconInst)n).getDefinedParameters(); vIt.hasNext(); ) { Variable var = vIt.next(); if (var.isCode()) return true; } } for(Iterator<Variable> vIt = n.getVariables(); vIt.hasNext(); ) { Variable var = vIt.next(); if (var.isCode()) return true; } } for (ImmutableArcInst a: cellRevision.arcs) { for(Iterator<Variable> vIt = a.getVariables(); vIt.hasNext(); ) { Variable var = vIt.next(); if (var.isCode()) return true; } } // bus pin appearance depends on parent Cell for (ImmutableExport e: cellRevision.exports) { if (e.originalPortId == busPinPortId) return true; } return false; } public Set<CellId> forceRedrawAfterChange(Set<CellId> topCells) { BitSet visibleCells = new BitSet(); for (CellId cellId: topCells) { if (database.getCell(cellId) == null) continue; markDown(cellId, visibleCells); } // deleted cells for (int cellIndex = 0; cellIndex < cachedCells.size(); cellIndex++) { if (cachedCells.get(cellIndex) != null && !visibleCells.get(cellIndex)) cachedCells.set(cellIndex, null); } // changed cells Snapshot snapshot = database.backup();// BitSet changedCells = new BitSet(); BitSet changedExports = new BitSet(); BitSet changedBounds = new BitSet(); BitSet changedParams = new BitSet(); Set<CellId> changedVisibility = new HashSet<CellId>(); for (CellId cellId: snapshot.getCellsDownTop()) { int cellIndex = cellId.cellIndex; if (!visibleCells.get(cellIndex)) continue; while (cellIndex >= cachedCells.size()) cachedCells.add(null); VectorCellGroup vcg = cachedCells.get(cellIndex); boolean changedVis = false; if (vcg == null) { vcg = new VectorCellGroup(cellId);// changedCells.set(cellIndex); changedExports.set(cellIndex); changedBounds.set(cellIndex); if (cellId.isIcon()) changedParams.set(cellIndex); changedVis = true; } else if (vcg.cellBackup != snapshot.getCell(cellId)) { if (vcg.changedExports()) changedExports.set(cellIndex); if (vcg.updateBounds(snapshot)) changedBounds.set(cellIndex); if (cellId.isIcon()) changedParams.set(cellIndex); vcg.init();// changedCells.set(cellIndex); changedVis = true; } else { CellRevision cellRevision = snapshot.getCell(cellId).cellRevision; int[] instCounts = cellRevision.getInstCounts(); boolean subExportsChanged = false; boolean subParamsChanged = false; for (int i = 0; i < instCounts.length; i++){ if (instCounts[i] == 0) continue; int subCellIndex = cellId.getUsageIn(i).protoId.cellIndex; if (changedExports.get(subCellIndex)) subExportsChanged = true; if (changedParams.get(subCellIndex)) subParamsChanged = true; } if (vcg.updateBounds(snapshot)) { changedBounds.set(cellIndex); changedVis = true; } if (subExportsChanged && vcg.changedExports()) { changedExports.set(cellIndex); vcg.updateExports(); changedVis = true; } if (subParamsChanged) vcg.clear(); if (!changedVis) { Cell cell = database.getCell(cellId); for (ImmutableNodeInst n: cellRevision.nodes) { if (!(n.protoId instanceof CellId)) continue; CellId subCellId = (CellId)n.protoId; int subCellIndex = subCellId.cellIndex; if (cell.isExpanded(n.nodeId)) { if (changedVisibility.contains(subCellId)) { changedVis = true; break; } } else if (changedBounds.get(subCellIndex) || changedExports.get(subCellIndex)) { changedVis = true; break; } } } } if (changedVis) changedVisibility.add(cellId); } return changedVisibility; } private void markDown(CellId cellId, BitSet visibleCells) { if (visibleCells.get(cellId.cellIndex)) return; visibleCells.set(cellId.cellIndex); Cell cell = database.getCell(cellId); for (Iterator<CellUsage> it = cell.getUsagesIn(); it.hasNext(); ) { CellUsage cu = it.next(); markDown(cu.protoId, visibleCells); } } void forceRedraw() { boolean clearCache, clearFadeImages; synchronized (this) { clearCache = this.clearCache; this.clearCache = false; clearFadeImages = this.clearFadeImages; this.clearFadeImages = false; } Snapshot snapshot = database.backup(); for (int cellIndex = 0, size = cachedCells.size(); cellIndex < size; cellIndex++) { VectorCellGroup vcg = cachedCells.get(cellIndex); if (vcg == null) continue; if (clearCache) vcg.clear(); if (clearFadeImages) { for(VectorCell vc : vcg.orientations.values()) { vc.fadeImageColors = null; vc.fadeImage = false; } } assert vcg.bounds == snapshot.getCellBounds(cellIndex);// vcg.updateBounds(snapshot);// if (!changedCells.contains(vcg.cellId) && vcg.cellBackup == snapshot.getCell(cellIndex)) continue;// cellChanged(vcg.cellId); } }// /**// * Method called when a cell changes: removes any cached displays of that cell// * @param cell the cell that changed// */// private void cellChanged(CellId cellId)// {// VectorCellGroup vcg = null;// if (cellId.cellIndex < cachedCells.size())// vcg = cachedCells.get(cellId.cellIndex);// Cell cell = database.getCell(cellId);// if (cell != null)// {// // cell still valid: see if it changed from last cache// if (vcg != null)// {// // queue parent cells for recaching if the bounds or exports changed// if (vcg.changedExports())// {// vcg.updateExports();// for(Iterator<CellUsage> it = cell.getUsagesOf(); it.hasNext(); )// {// CellUsage u = it.next();// cellChanged(u.parentId);// }// }// }// }////System.out.println("REMOVING CACHE FOR CELL "+cell);// if (vcg != null)// vcg.clear();// } /** * Method called when it is necessary to clear cache. */ public synchronized void clearCache() { clearCache = true; } /** * Method called when visible layers have changed. * Removes all "greeked images" from cached cells. */ public synchronized void clearFadeImages() { clearFadeImages = true; } private static int databaseToGrid(double lambdaValue) { return (int)DBMath.lambdaToGrid(lambdaValue); } private void addBoxesFromBuilder(VectorCell vc, Technology tech, ArrayList<VectorManhattanBuilder> boxBuilders, boolean pureArray) { for (int layerIndex = 0; layerIndex < boxBuilders.size(); layerIndex++) { VectorManhattanBuilder b = boxBuilders.get(layerIndex); if (b.size == 0) continue; Layer layer = tech.getLayer(layerIndex); VectorManhattan vm = new VectorManhattan(b.toArray(), layer, layer.getGraphics(), pureArray); vc.filledShapes.add(vm); } } /** * Comparator class for sorting VectorBase objects by their layer depth. */ public static Comparator<VectorBase> shapeByLayer = new Comparator<VectorBase>() { /** * Method to sort Objects by their string name. */ public int compare(VectorBase vb1, VectorBase vb2) { int level1 = 1000, level2 = 1000; boolean isContact1 = false; boolean isContact2 = false; if (vb1.layer != null) { Layer.Function fun = vb1.layer.getFunction(); level1 = fun.getLevel(); isContact1 = fun.isContact(); } if (vb2.layer != null) { Layer.Function fun = vb2.layer.getFunction(); level2 = fun.getLevel(); isContact2 = fun.isContact(); } if (isContact1 != isContact2) return isContact1 ? -1 : 1; return level1 - level2; } }; /** * Method to cache a NodeInst. * @param ni the NodeInst to cache. * @param trans the transformation of the NodeInst to the parent Cell.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -