📄 highlight2.java
字号:
// boolean added = false;// for(Iterator<Connection> aIt = pi.getNodeInst().getConnections(); aIt.hasNext(); )// {// Connection con = aIt.next();// ArcInst ai = con.getArc();// int wid = netlist.getBusWidth(ai);// for(int i=0; i<wid; i++)// {// Network net = netlist.getNetwork(ai, i);// if (net != null)// {// added = true;// nets.add(net);// }// }// }// if (!added)// {// Network net = netlist.getNetwork(pi);// if (net != null) nets.add(net);// } } else if (eObj instanceof ArcInst) { ArcInst ai = (ArcInst)eObj; int width = netlist.getBusWidth(ai); for(int i=0; i<width; i++) { Network net = netlist.getNetwork((ArcInst)eObj, i); if (net != null) nets.add(net); } } } Rectangle2D getHighlightedArea(EditWindow wnd) { ElectricObject eObj = eobj; if (eObj instanceof PortInst) eObj = ((PortInst)eObj).getNodeInst(); if (eObj instanceof Geometric) { Geometric geom = (Geometric)eObj; return geom.getBounds(); } return null; } public Geometric getGeometric() { Geometric retVal = null; if (eobj instanceof PortInst) retVal = ((PortInst)eobj).getNodeInst(); else if (eobj instanceof Geometric) retVal = (Geometric)eobj; return retVal; } boolean overHighlighted(EditWindow wnd, int x, int y, Highlighter highlighter) { Point2D slop = wnd.deltaScreenToDatabase(Highlighter.EXACTSELECTDISTANCE*2, Highlighter.EXACTSELECTDISTANCE*2); double directHitDist = slop.getX(); Point2D start = wnd.screenToDatabase(x, y); Rectangle2D searchArea = new Rectangle2D.Double(start.getX(), start.getY(), 0, 0); ElectricObject eobj = this.eobj; if (eobj instanceof PortInst) eobj = ((PortInst)eobj).getNodeInst(); if (eobj instanceof Geometric) { boolean specialSelect = ToolBar.isSelectSpecial(); Highlight2 got = Highlighter.checkOutObject((Geometric)eobj, true, false, specialSelect, searchArea, wnd, directHitDist, false); if (got == null) return false; if (!(got instanceof HighlightEOBJ)) System.out.println("Error?"); ElectricObject hObj = got.getElectricObject(); ElectricObject hReal = hObj; if (hReal instanceof PortInst) hReal = ((PortInst)hReal).getNodeInst(); for(Highlight2 alreadyDone : highlighter.getHighlights()) { if (!(alreadyDone instanceof HighlightEOBJ)) continue; HighlightEOBJ alreadyHighlighted = (HighlightEOBJ)alreadyDone; ElectricObject aHObj = alreadyHighlighted.getElectricObject(); ElectricObject aHReal = aHObj; if (aHReal instanceof PortInst) aHReal = ((PortInst)aHReal).getNodeInst(); if (hReal == aHReal) { // found it: adjust the port/point if (hObj != aHObj || alreadyHighlighted.point != ((HighlightEOBJ)got).point) { alreadyHighlighted.eobj = got.getElectricObject(); alreadyHighlighted.point = ((HighlightEOBJ)got).point; synchronized(highlighter) { highlighter.setChanged(true); } } break; } } return true; } return false; } public String getInfo() { String description = ""; ElectricObject realObj = eobj; if (realObj instanceof PortInst) realObj = ((PortInst)realObj).getNodeInst(); if (realObj instanceof NodeInst) { NodeInst ni = (NodeInst)realObj; description = "Node " + ni.describe(true); } else if (realObj instanceof ArcInst) { ArcInst ai = (ArcInst)eobj; description = "Arc " + ai.describe(true); } return description; }}class HighlightText extends Highlight2{ /** The highlighted object. */ protected final ElectricObject eobj; /** The highlighted variable. */ protected final Variable.Key varKey; public HighlightText(ElectricObject e, Cell c, Variable.Key key) { super(c); this.eobj = e; this.varKey = key; Class cls = null; if (key == NodeInst.NODE_NAME || key == NodeInst.NODE_PROTO) cls = NodeInst.class; else if (key == ArcInst.ARC_NAME) cls = ArcInst.class; else if (key == Export.EXPORT_NAME) cls = Export.class; if (cls != null && !cls.isInstance(e)) throw new IllegalArgumentException(key + " in " + e); } void internalDescribe(StringBuffer desc) { if (varKey != null) { if (varKey == NodeInst.NODE_NAME) { desc.append(", name: "); desc.append(((NodeInst)eobj).getName()); } else if (varKey == NodeInst.NODE_PROTO) { desc.append(", instance: "); desc.append(((NodeInst)eobj).getProto().getName()); } else if (varKey == ArcInst.ARC_NAME) { desc.append(", name: "); desc.append(((ArcInst)eobj).getName()); } else if (varKey == Export.EXPORT_NAME) { desc.append(", export: "); desc.append(((Export)eobj).getName()); } else { desc.append(", var: "); desc.append(eobj.getParameterOrVariable(varKey).describe(-1)); } } } public ElectricObject getElectricObject() { return eobj; } // creating so HighlightText is not a public class public boolean isHighlightText() { return true; } public Variable.Key getVarKey() { return varKey; } boolean isValid() { if (!super.isValid()) return false; if (eobj == null || varKey == null) return false; if (!eobj.isLinked()) return false; if (varKey == NodeInst.NODE_NAME || varKey == ArcInst.ARC_NAME || varKey == NodeInst.NODE_PROTO || varKey == Export.EXPORT_NAME) return true; return eobj.getParameterOrVariable(varKey) != null; } boolean sameThing(Highlight2 obj) { if (this == obj) return (true); // Consider already obj==null if (obj == null || getClass() != obj.getClass()) return (false); HighlightText other = (HighlightText)obj; if (eobj != other.eobj) return false; if (cell != other.cell) return false; if (varKey != other.varKey) return false; return true; } public void showInternalHighlight(EditWindow wnd, Graphics g, int highOffX, int highOffY, boolean onlyHighlight, boolean setConnected) { Graphics2D g2 = (Graphics2D)g; Point2D [] points = Highlighter.describeHighlightText(wnd, eobj, varKey); if (points == null) return; Point2D [] linePoints = new Point2D[2]; for(int i=0; i<points.length; i += 2) { linePoints[0] = points[i]; linePoints[1] = points[i+1]; drawOutlineFromPoints(wnd, g, linePoints, highOffX, highOffY, false, false); } if (onlyHighlight) { // this is the only thing highlighted: show the attached object ElectricObject eObj = eobj; if (eObj != null && eObj instanceof Geometric) { Geometric geom = (Geometric)eObj; if (geom instanceof ArcInst || !((NodeInst)geom).isInvisiblePinWithText()) { Point c = wnd.databaseToScreen(geom.getTrueCenter()); int lowX = Integer.MAX_VALUE, highX = Integer.MIN_VALUE; int lowY = Integer.MAX_VALUE, highY = Integer.MIN_VALUE; for(int i=0; i<points.length; i++) { Point a = wnd.databaseToScreen(points[i]); if (a.x < lowX) lowX = a.x; if (a.x > highX) highX = a.x; if (a.y < lowY) lowY = a.y; if (a.y > highY) highY = a.y; } int cX = (lowX+highX)/2; int cY = (lowY+highY)/2; if (Math.abs(cX - c.x) > 4 || Math.abs(cY - c.y) > 4) { g.fillOval(c.x-4, c.y-4, 8, 8); g2.setStroke(dottedLine); drawLine(g, wnd, c.x, c.y, cX, cY); g2.setStroke(solidLine); } } } } }// /**// * Method to tell whether this Highlight is text that stays with its node.// * The two possibilities are (1) text on invisible pins// * (2) export names, when the option to move exports with their labels is requested.// * @return true if this Highlight is text that should move with its node.// */// public boolean nodeMovesWithText()// {// if (varKey != null)// {// // moving variable text// if (!(eobj instanceof NodeInst)) return false;// NodeInst ni = (NodeInst)eobj;// if (ni.isInvisiblePinWithText()) return true;// } else// {// // moving export text// if (!(eobj instanceof Export)) return false;// Export pp = (Export)eobj;// if (pp.getOriginalPort().getNodeInst().getProto() == Generic.tech.invisiblePinNode) return true;// if (User.isMoveNodeWithExport()) return true;// }// return false;// } public Geometric getGeometric() { if (DisplayedText.objectMovesWithText(eobj, varKey)) { if (eobj instanceof Export) return ((Export)eobj).getOriginalPort().getNodeInst(); if (eobj instanceof Geometric) return (Geometric)eobj; } return null; } void getHighlightedEObjs(Highlighter highlighter, List<Geometric> list, boolean wantNodes, boolean wantArcs) { getHighlightedEObjsInternal(getGeometric(), list, wantNodes, wantArcs); } void getHighlightedNodes(Highlighter highlighter, List<NodeInst> list) { getHighlightedNodesInternal(getGeometric(), list); } void getHighlightedArcs(Highlighter highlighter, List<ArcInst> list) { getHighlightedArcsInternal(getGeometric(), list); } void getHighlightedNetworks(Set<Network> nets, Netlist netlist) { if (/*varKey == null &&*/ eobj instanceof Export) { Export pp = (Export)eobj; int width = netlist.getBusWidth(pp); for(int i=0; i<width; i++) { Network net = netlist.getNetwork(pp, i); if (net != null) nets.add(net); } } } DisplayedText makeDisplayedText() { if (varKey != null) return new DisplayedText(eobj, varKey); return null; } void getHighlightedText(List<DisplayedText> list, boolean unique, List<Highlight2> getHighlights) { DisplayedText dt = makeDisplayedText(); if (dt == null) return; if (list.contains(dt)) return; // if this text is on a selected object, don't include the text if (unique) { ElectricObject onObj = null; if (varKey != null) { if (eobj instanceof Export) { onObj = ((Export)eobj).getOriginalPort().getNodeInst(); } else if (eobj instanceof PortInst) { onObj = ((PortInst)eobj).getNodeInst(); } else if (eobj instanceof Geometric) { onObj = eobj; } } // now see if the object is in the list if (eobj != null) { boolean found = false; for(Highlight2 oH : getHighlights) { if (!(oH instanceof HighlightEOBJ)) continue; ElectricObject fobj = ((HighlightEOBJ)oH).eobj; if (fobj instanceof PortInst) fobj = ((PortInst)fobj).getNodeInst(); if (fobj == onObj) { found = true; break; } } if (found) return; } } // add this text list.add(dt); } Rectangle2D getHighlightedArea(EditWindow wnd) { if (wnd != null) { Poly poly = eobj.computeTextPoly(wnd, varKey); if (poly != null) return poly.getBounds2D(); } return null; } boolean overHighlighted(EditWindow wnd, int x, int y, Highlighter highlighter) { Point2D start = wnd.screenToDatabase(x, y); Poly poly = eobj.computeTextPoly(wnd, varKey); if (poly != null) if (poly.isInside(start)) return true; return false; } public String describe() { String description = "Unknown"; if (varKey != null && eobj != null) { if (varKey == NodeInst.NODE_NAME) { description = "Node name for " + ((NodeInst)eobj).describe(true); } else if (varKey == ArcInst.ARC_NAME) { description = "Arc name for " + ((ArcInst)eobj).describe(true); } else if (varKey == Export.EXPORT_NAME) { description = "Export '" + ((Export)eobj).getName() + "'"; } else if (varKey == NodeInst.NODE_PROTO) { description = "Cell instance name " + ((NodeInst)eobj).describe(true); } else { description = eobj.getParameterOrVariable(varKey).getFullDescription(eobj); } } return description; } public String getInfo() { return "Text: " + describe(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -