📄 circuitchangejobs.java
字号:
continue; } // copy names to a local array String [] localStrings = new String[busWidth]; for(int i=0; i<busWidth; i++) { Network subNet = netList.getNetwork(ai, i); localStrings[i] = subNet.getName(); } double sxw = Schematics.tech().wirePinNode.getDefWidth(); double syw = Schematics.tech().wirePinNode.getDefHeight(); double sxb = Schematics.tech().busPinNode.getDefWidth(); double syb = Schematics.tech().busPinNode.getDefHeight(); ArcProto apW = Schematics.tech().wire_arc; ArcProto apB = Schematics.tech().bus_arc; NodeInst niBLast = null; for(int i=0; i<busWidth; i++) { // make the wire pin NodeInst niw = NodeInst.makeInstance(Schematics.tech().wirePinNode, new Point2D.Double(lowX, lowY), sxw, syw, ai.getParent()); if (niw == null) break; // make the bus pin NodeInst nib = NodeInst.makeInstance(Schematics.tech().busPinNode, new Point2D.Double(lowXBus, lowYBus), sxb, syb, ai.getParent()); if (nib == null) break; // wire them PortInst head = niw.getOnlyPortInst(); PortInst tail = nib.getOnlyPortInst(); ArcInst aiw = ArcInst.makeInstance(apW, head, tail); if (aiw == null) break; aiw.setName(localStrings[i]); // wire to the bus pin if (i == 0) { PortInst first = ai.getPortInst(lowEnd); aiw = ArcInst.makeInstance(apB, first, tail); } else { PortInst first = niBLast.getOnlyPortInst(); aiw = ArcInst.makeInstance(apB, first, tail); } if (aiw == null) break; // advance to the next segment niBLast = nib; lowX += sepX; lowY += sepY; lowXBus += sepX; lowYBus += sepY; } // wire up the last segment PortInst head = niBLast.getOnlyPortInst(); PortInst tail = ai.getPortInst(1-lowEnd); ArcInst aiw = ArcInst.makeInstance(apB, head, tail); if (aiw == null) return false; aiw.setName(netName); // remove original arc ai.kill(); } return true; } } /****************************** DELETE SELECTED OBJECTS ******************************/ public static class DeleteSelected extends Job { private Cell cell; private List<DisplayedText> highlightedText; private List<Geometric> highlighted; private boolean reconstructArcsAndExports; private List<Geometric> thingsToHighlight; public DeleteSelected(Cell cell, List<DisplayedText> highlightedText, List<Geometric> highlighted, boolean reconstructArcsAndExports) { super("Delete selected objects", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.cell = cell; this.highlightedText = highlightedText; this.highlighted = highlighted; this.reconstructArcsAndExports = reconstructArcsAndExports; startJob(); } public boolean doIt() throws JobException { // make sure deletion is allowed if (cantEdit(cell, null, true, false, true) != 0) return false; // delete the text for(DisplayedText dt : highlightedText) { // deleting variable on object Variable.Key key = dt.getVariableKey(); ElectricObject eobj = dt.getElectricObject(); // delete any reference to this Object in SizeListener SizeListener.restorePreviousListener(eobj); if (key == NodeInst.NODE_NAME) { // deleting the name of a node NodeInst ni = (NodeInst)eobj; ni.setName(null); ni.move(0, 0); } else if (key == ArcInst.ARC_NAME) { // deleting the name of an arc ArcInst ai = (ArcInst)eobj; ai.setName(null); ai.modify(0, 0, 0, 0); } else if (key == Export.EXPORT_NAME) { // deleting the name of an export Export pp = (Export)eobj; int errCode = cantEdit(cell, pp.getOriginalPort().getNodeInst(), true, true, true); if (errCode < 0) return false; if (errCode > 0) continue; pp.kill(); } else { // deleting a variable if (eobj.isParam(key)) { if (eobj instanceof Cell) ((Cell)eobj).getCellGroup().delParam((Variable.AttrKey)key); else if (eobj instanceof NodeInst) ((NodeInst)eobj).delParameter(key); } else { eobj.delVar(key); } } } if (cell != null) { thingsToHighlight = new ArrayList<Geometric>(); Set<ElectricObject> stuffToHighlight = new HashSet<ElectricObject>(); eraseObjectsInList(cell, highlighted, reconstructArcsAndExports, stuffToHighlight); for(ElectricObject eObj : stuffToHighlight) { if (eObj instanceof ArcInst) { ArcInst ai = (ArcInst)eObj; thingsToHighlight.add(ai); } else if (eObj instanceof Export) { Export e = (Export)eObj; thingsToHighlight.add(e.getOriginalPort().getNodeInst()); } } fieldVariableChanged("thingsToHighlight"); } return true; } public void terminateOK() { // remove highlighting, show only reconstructed objects UserInterface ui = Job.getUserInterface(); EditWindow_ wnd = ui.getCurrentEditWindow_(); if (wnd != null) { wnd.clearHighlighting(); if (thingsToHighlight != null) { for(Geometric geom: thingsToHighlight) wnd.addElectricObject(geom, cell); } wnd.finishedHighlighting(); } } } public static class DeleteSelectedGeometry extends Job { private Cell cell; private ERectangle bounds; public DeleteSelectedGeometry(Cell cell, Rectangle2D bounds) { super("Delete selected geometry", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.cell = cell; this.bounds = ERectangle.fromLambda(bounds); startJob(); } public boolean doIt() throws JobException { if (cell == null) { System.out.println("No current cell"); return false; } if (bounds == null) { System.out.println("Nothing selected"); return false; } // disallow erasing if lock is on if (cantEdit(cell, null, true, false, true) != 0) return false; if (bounds == null) { System.out.println("Outline an area first"); return false; } // grid the area double lX = Math.floor(bounds.getMinX()); double hX = Math.ceil(bounds.getMaxX()); double lY = Math.floor(bounds.getMinY()); double hY = Math.ceil(bounds.getMaxY()); // crop arcs that cross the area boundary List<ArcInst> arcsInCell = new ArrayList<ArcInst>(); for(Iterator<ArcInst> aIt = cell.getArcs(); aIt.hasNext(); ) arcsInCell.add(aIt.next()); for(ArcInst ai : arcsInCell) { // if an end is inside, ignore Point2D headPt = ai.getHeadLocation(); Point2D tailPt = ai.getTailLocation(); // if length is zero, ignore if (tailPt.getX() == headPt.getX() && tailPt.getY() == headPt.getY()) continue; // if the arc doesn't intersect the area, ignore double halfWidth = ai.getLambdaBaseWidth() / 2; double lXExt = lX - halfWidth; double hXExt = hX + halfWidth; double lYExt = lY - halfWidth; double hYExt = hY + halfWidth; Point2D tailPtAdj = new Point2D.Double(tailPt.getX(), tailPt.getY()); Point2D headPtAdj = new Point2D.Double(headPt.getX(), headPt.getY()); if (DBMath.clipLine(tailPtAdj, headPtAdj, lXExt, hXExt, lYExt, hYExt)) continue; if (tailPtAdj.distance(headPt) + headPtAdj.distance(tailPt) < headPtAdj.distance(headPt) + tailPtAdj.distance(tailPt)) { Point2D swap = headPtAdj; headPtAdj = tailPtAdj; tailPtAdj = swap; } Name name = ai.getNameKey(); String newName = null; if (!name.isTempname()) newName = name.toString(); if (!tailPt.equals(tailPtAdj)) { // create a pin at this point PrimitiveNode pin = ai.getProto().findPinProto(); NodeInst ni = NodeInst.makeInstance(pin, tailPtAdj, pin.getDefWidth(), pin.getDefHeight(), cell); if (ni == null) { System.out.println("Error creating pin for shortening of "+ai); continue; } ArcInst ai1 = ArcInst.makeInstanceBase(ai.getProto(), ai.getLambdaBaseWidth(), ai.getTailPortInst(), ni.getOnlyPortInst(), ai.getTailLocation(), tailPtAdj, newName); if (ai1 == null) { System.out.println("Error shortening "+ai); continue; } newName = null; ai1.copyPropertiesFrom(ai); } if (!headPt.equals(headPtAdj)) { // create a pin at this point PrimitiveNode pin = ai.getProto().findPinProto(); NodeInst ni = NodeInst.makeInstance(pin, headPtAdj, pin.getDefWidth(), pin.getDefHeight(), cell); if (ni == null) { System.out.println("Error creating pin for shortening of "+ai); continue; } ArcInst ai1 = ArcInst.makeInstanceBase(ai.getProto(), ai.getLambdaBaseWidth(), ni.getOnlyPortInst(), ai.getHeadPortInst(), headPtAdj, ai.getHeadLocation(), newName); if (ai1 == null) { System.out.println("Error shortening "+ai); continue; } ai1.copyPropertiesFrom(ai); } // delete any reference to this Object in SizeListener SizeListener.restorePreviousListener(ai); ai.kill(); } // now remove nodes in the area Set<NodeInst> nodesToDelete = new HashSet<NodeInst>(); for(Iterator<NodeInst> nIt = cell.getNodes(); nIt.hasNext(); ) { NodeInst ni = nIt.next(); // special case for nodes with outline information: clip the outline if (!ni.isCellInstance()) { if (ni.getProto().getFunction() == PrimitiveNode.Function.NODE) { // first see if it is completely ignored Rectangle2D pointBounds = ni.getBounds(); if (pointBounds.getMinX() > hX || pointBounds.getMaxX() < lX || pointBounds.getMinY() > hY || pointBounds.getMaxY() < lY) continue; // if it cannot be modified, stop int errorCode = cantEdit(cell, ni, true, false, true); if (errorCode < 0) return false; if (errorCode > 0) continue; // if it is completely covered, delete it if (pointBounds.getMinX() >= lX && pointBounds.getMaxX() <= hX && pointBounds.getMinY() >= lY && pointBounds.getMaxY() <= hY) { nodesToDelete.add(ni); continue; } // crop it against the delete bounds Layer lay = ni.getProto().getTechnology().getLayer(0); PolyMerge merge = new PolyMerge(); PolyBase poly; Point2D [] points = ni.getTrace(); if (points == null) poly = new PolyBase(pointBounds); else { double cX = pointBounds.getCenterX(); double cY = pointBounds.getCenterY(); Point2D [] newPoints = new Point2D[points.length]; for(int i=0; i<points.length; i++) { if (points[i] != null) newPoints[i] = new Point2D.Double(points[i].getX()+cX, points[i].getY()+cY); } poly = new PolyBase(newPoints); poly.transform(ni.rotateOut()); } merge.addPolygon(lay, poly); PolyBase polySub = new PolyBase((lX+hX)/2, (lY+hY)/2, hX-lX, hY-lY); merge.subtract(lay, polySub); List<PolyBase> resultingPolys = merge.getMergedPoints(lay, true); if (resultingPolys != null) { // find the largest polygon PolyBase largest = null; double largestSize = 0; for(PolyBase pb : resultingPolys) { double sz = pb.getArea(); if (sz >= largestSize) { largestSize = sz; largest = pb; } } if (largest != null) ni.setTrace(largest.getPoints()); continue; } } } // if the node is outside of the area, ignore it double cX = ni.getTrueCenterX(); double cY = ni.getTrueCenterY(); if (cX >= hX || cX <= lX || cY >= hY || cY <= lY) continue; // if it cannot be modified, stop int errorCode = cantEdit(cell, ni, true, false, true); if (errorCode < 0) return false; if (errorCode > 0) continue; nodesToDelete.add(ni); // delete any reference to this Object in SizeListener SizeListener.restorePreviousListener(ni); } // delete the nodes cell.killNodes(nodesToDelete); return true; } } public static class DeleteArcs extends Job { private Set<ArcInst> arcsToDelete; public DeleteArcs(Set<ArcInst> arcsToDelete) { super("Delete arcs", User.getUserTool(), Job.Type.CHANGE, null, null, Job.Priority.USER); this.arcsToDelete = arcsToDelete; startJob(); } public boolean doIt() throws JobException { for(ArcInst ai : arcsToDelete) { NodeInst h = ai.getHeadPortInst().getNodeInst(); NodeInst t = ai.getTailPortInst().getNodeInst(); ai.kill(); // also delete freed pin nodes if (h.getProto().getFunction() == PrimitiveNode.Function.PIN && !h.hasConnections() && !h.hasExports()) { h.kill(); } if (t.getProto().getFunction() == PrimitiveNode.Function.PIN && !t.hasConnections() && !t.hasExports()) { t.kill(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -