📄 highlight2.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: Highlight2.java * * Copyright (c) 2006 Sun Microsystems and Static Free Software * * Electric(tm) is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * Electric(tm) is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Electric(tm); see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, Mass 02111-1307, USA. */package com.sun.electric.tool.user;import com.sun.electric.database.geometry.DBMath;import com.sun.electric.database.geometry.GenMath;import com.sun.electric.database.geometry.Poly;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.Export;import com.sun.electric.database.hierarchy.Nodable;import com.sun.electric.database.network.Netlist;import com.sun.electric.database.network.Network;import com.sun.electric.database.network.NetworkTool;import com.sun.electric.database.prototype.PortProto;import com.sun.electric.database.text.Name;import com.sun.electric.database.topology.ArcInst;import com.sun.electric.database.topology.Connection;import com.sun.electric.database.topology.Geometric;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.topology.PortInst;import com.sun.electric.database.variable.DisplayedText;import com.sun.electric.database.variable.ElectricObject;import com.sun.electric.database.variable.Variable;import com.sun.electric.technology.PrimitiveNode;import com.sun.electric.technology.Technology;import com.sun.electric.technology.technologies.Artwork;import com.sun.electric.tool.Job;import com.sun.electric.tool.user.ui.EditWindow;import com.sun.electric.tool.user.ui.ToolBar;import java.awt.BasicStroke;import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.Point;import java.awt.Stroke;import java.awt.font.GlyphVector;import java.awt.geom.AffineTransform;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Set;/** * Super class for all types of highlighting. */public abstract class Highlight2 implements Cloneable{ /** for drawing solid lines */ public static final BasicStroke solidLine = new BasicStroke(0); /** for drawing dotted lines */ public static final BasicStroke dottedLine = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] {1}, 0); /** for drawing dashed lines */ public static final BasicStroke dashedLine = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10, new float[] {10}, 0); /** for drawing dashed lines */ public static final BasicStroke boldLine = new BasicStroke(3); /** The Cell containing the selection. */ protected Cell cell; private static final int CROSSSIZE = 3; Highlight2(Cell c) { this.cell = c; } public Cell getCell() { return cell; } boolean isValid() { if (cell != null) if (!cell.isLinked()) return false; return true; } // creating so HighlightEOBJ is not a public class public boolean isHighlightEOBJ() { return false; } // creating so HighlightText is not a public class public boolean isHighlightText() { return false; } public Object getObject() { return null; } public Variable.Key getVarKey() { return null; } // point variable, only useful for HighlightEOBJ? public void setPoint(int p) {;} public int getPoint() { return -1; } public Object clone() { try { return super.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } return null; } /** * Method to tell whether two Highlights are the same. * @param obj the Highlight to compare to this one. * @return true if the two refer to the same thing. */ boolean sameThing(Highlight2 obj) { return false; } /** * 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() { return false; } /** * Method to display this Highlight in a window. * @param wnd the window in which to draw this highlight. * @param g the Graphics associated with the window. */ public void showHighlight(EditWindow wnd, Graphics g, int highOffX, int highOffY, boolean onlyHighlight, Color mainColor, Stroke primaryStroke, boolean setConnected) { if (!isValid()) return; g.setColor(mainColor); Graphics2D g2 = (Graphics2D)g; g2.setStroke(primaryStroke); showInternalHighlight(wnd, g, highOffX, highOffY, onlyHighlight, setConnected); } abstract void showInternalHighlight(EditWindow wnd, Graphics g, int highOffX, int highOffY, boolean onlyHighlight, boolean setConnected); /** * Method to populate a List of all highlighted Geometrics. * @param list the list to populate * @param wantNodes true if NodeInsts should be included in the list. * @param wantArcs true if ArcInsts should be included in the list. */ void getHighlightedEObjs(Highlighter highlighter, List<Geometric> list, boolean wantNodes, boolean wantArcs) {;} static void getHighlightedEObjsInternal(Geometric geom, List<Geometric> list, boolean wantNodes, boolean wantArcs) { if (geom == null) return; if (!wantNodes && geom instanceof NodeInst) return; if (!wantArcs && geom instanceof ArcInst) return; if (list.contains(geom)) return; list.add(geom); } /** * Method to return the Geometric object that is in this Highlight. * If the highlight is a PortInst, an Export, or annotation text, its base NodeInst is returned. * @return the Geometric object that is in this Highlight. * Returns null if this Highlight is not on a Geometric. */ public Geometric getGeometric() { return null; } /** * Method to return a List of all highlighted NodeInsts. * Return a list with the highlighted NodeInsts. */ void getHighlightedNodes(Highlighter highlighter, List<NodeInst> list) {;} static void getHighlightedNodesInternal(Geometric geom, List<NodeInst> list) { if (geom == null || !(geom instanceof NodeInst)) return; NodeInst ni = (NodeInst)geom; if (list.contains(ni)) return; list.add(ni); } /** * Method to return a List of all highlighted ArcInsts. * Return a list with the highlighted ArcInsts. */ void getHighlightedArcs(Highlighter highlighter, List<ArcInst> list) {;} static void getHighlightedArcsInternal(Geometric geom, List<ArcInst> list) { if (geom == null || !(geom instanceof ArcInst)) return; ArcInst ai = (ArcInst)geom; if (list.contains(ai)) return; list.add(ai); } /** * Method to return a set of the currently selected networks. * Return a set of the currently selected networks. * If there are no selected networks, the list is empty. */ void getHighlightedNetworks(Set<Network> nets, Netlist netlist) {;} /** * Method to return a List of all highlighted text. * @param list list to populate. * @param unique true to request that the text objects be unique, * and not attached to another object that is highlighted. * For example, if a node and an export on that node are selected, * the export text will not be included if "unique" is true. * Return a list with the Highlight objects that point to text. */ void getHighlightedText(List<DisplayedText> list, boolean unique, List<Highlight2> getHighlights) {;} /** * Method to return the bounds of the highlighted objects. * @param wnd the window in which to get bounds. * @return the bounds of the highlighted objects (null if nothing is highlighted). */ Rectangle2D getHighlightedArea(EditWindow wnd) { return null; } /** * Method to return the ElectricObject associated with this Highlight object. * @return the ElectricObject associated with this Highlight object. */ public ElectricObject getElectricObject() { return null; } /** * Method to tell whether a point is over this Highlight. * @param wnd the window being examined. * @param x the X screen coordinate of the point. * @param y the Y screen coordinate of the point. * @return true if the point is over this Highlight. */ boolean overHighlighted(EditWindow wnd, int x, int y, Highlighter highlighter) { return false; } public String getInfo() { return null;} /** * Method to load an array of counts with the number of highlighted objects in a list. * arc = 0, node = 1, export = 2, text = 3, graphics = 4 * @param list the list of highlighted objects. * @param counts the array of counts to set. * @return a NodeInst, if it is in the list. */ public static NodeInst getInfoCommand(List<Highlight2> list, int[] counts) { // information about the selected items NodeInst theNode = null; for(Highlight2 h : list) { ElectricObject eobj = h.getElectricObject(); if (h.isHighlightEOBJ()) { if (eobj instanceof NodeInst || eobj instanceof PortInst) { counts[1]++; if (eobj instanceof NodeInst) theNode = (NodeInst)eobj; else theNode = ((PortInst)eobj).getNodeInst(); } else if (eobj instanceof ArcInst) { counts[0]++; } } else if (h.isHighlightText()) { if (h.getVarKey() == Export.EXPORT_NAME) counts[2]++; else { if (h.getElectricObject() instanceof NodeInst) theNode = (NodeInst)h.getElectricObject(); counts[3]++; } } else if (h instanceof HighlightArea) { counts[4]++; } else if (h instanceof HighlightLine) { counts[4]++; } } return theNode; } /** * Method to draw an array of points as highlighting. * @param wnd the window in which drawing is happening. @param g the Graphics for the window. @param points the array of points being drawn. @param offX the X offset of the drawing. @param offY the Y offset of the drawing. @param opened true if the points are drawn "opened". @param thickLine */ public static void drawOutlineFromPoints(EditWindow wnd, Graphics g, Point2D[] points, int offX, int offY, boolean opened, boolean thickLine) {// Dimension screen = wnd.getScreenSize(); boolean onePoint = true; if (points.length <= 0) return; Point firstP = wnd.databaseToScreen(points[0].getX(), points[0].getY()); for(int i=1; i<points.length; i++) { Point p = wnd.databaseToScreen(points[i].getX(), points[i].getY()); if (DBMath.doublesEqual(p.getX(), firstP.getX()) && DBMath.doublesEqual(p.getY(), firstP.getY())) continue; onePoint = false; break; } if (onePoint) { drawLine(g, wnd, firstP.x + offX-CROSSSIZE, firstP.y + offY, firstP.x + offX+CROSSSIZE, firstP.y + offY); drawLine(g, wnd, firstP.x + offX, firstP.y + offY-CROSSSIZE, firstP.x + offX, firstP.y + offY+CROSSSIZE); return; } // find the center int cX = 0, cY = 0;// if (thickCenter != null)// {// Point lp = wnd.databaseToScreen(thickCenter.getX(), thickCenter.getY());// cX = lp.x;// cY = lp.y;// } for(int i=0; i<points.length; i++) { int lastI = i-1; if (lastI < 0) { if (opened) continue; lastI = points.length - 1; } Point lp = wnd.databaseToScreen(points[lastI].getX(), points[lastI].getY()); Point p = wnd.databaseToScreen(points[i].getX(), points[i].getY()); int fX = lp.x + offX; int fY = lp.y + offY; int tX = p.x + offX; int tY = p.y + offY; drawLine(g, wnd, fX, fY, tX, tY); if (thickLine) { if (fX < cX) fX--; else fX++; if (fY < cY) fY--; else fY++; if (tX < cX) tX--; else tX++; if (tY < cY) tY--; else tY++; drawLine(g, wnd, fX, fY, tX, tY); } } } void internalDescribe(StringBuffer desc) {;} /** * Describe the Highlight * @return a string describing the highlight */ public String describe() { StringBuffer desc = new StringBuffer(); desc.append(this.getClass().getName()); if (cell != null) { desc.append(" in "); desc.append(cell); } desc.append(": "); internalDescribe(desc); return desc.toString(); } /** * Gets a poly that describes the Highlight for the NodeInst. * @param ni the nodeinst to get a poly that will be used to highlight it * @return a poly outlining the nodeInst. */ public static Poly getNodeInstOutline(NodeInst ni) { AffineTransform trans = ni.rotateOutAboutTrueCenter(); Poly poly = null; if (!ni.isCellInstance()) { PrimitiveNode pn = (PrimitiveNode)ni.getProto(); // special case for outline nodes if (pn.isHoldsOutline()) { Point2D [] outline = ni.getTrace(); if (outline != null) { int numPoints = outline.length; boolean whole = true; if (Technology.HANDLEBROKENOUTLINES) { for(int i=1; i<numPoints; i++) { if (outline[i] == null) { whole = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -