📄 vectorcache.java
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: VectorCache.java * * Copyright (c) 2005 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.redisplay;import com.sun.electric.database.CellBackup;import com.sun.electric.database.CellRevision;import com.sun.electric.database.ImmutableArcInst;import com.sun.electric.database.ImmutableExport;import com.sun.electric.database.ImmutableIconInst;import com.sun.electric.database.ImmutableNodeInst;import com.sun.electric.database.Snapshot;import com.sun.electric.database.geometry.DBMath;import com.sun.electric.database.geometry.EGraphics;import com.sun.electric.database.geometry.ERectangle;import com.sun.electric.database.geometry.GenMath;import com.sun.electric.database.geometry.Orientation;import com.sun.electric.database.geometry.Poly;import com.sun.electric.database.hierarchy.Cell;import com.sun.electric.database.hierarchy.EDatabase;import com.sun.electric.database.hierarchy.Export;import com.sun.electric.database.id.CellId;import com.sun.electric.database.id.CellUsage;import com.sun.electric.database.id.PrimitivePortId;import com.sun.electric.database.prototype.NodeProto;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.ArcInst;import com.sun.electric.database.topology.Connection;import com.sun.electric.database.topology.NodeInst;import com.sun.electric.database.topology.PortInst;import com.sun.electric.database.variable.EditWindow0;import com.sun.electric.database.variable.TextDescriptor;import com.sun.electric.database.variable.VarContext;import com.sun.electric.database.variable.Variable;import com.sun.electric.technology.ArcProto;import com.sun.electric.technology.Layer;import com.sun.electric.technology.PrimitiveNode;import com.sun.electric.technology.PrimitivePort;import com.sun.electric.technology.Technology;import com.sun.electric.technology.technologies.Generic;import com.sun.electric.technology.technologies.Schematics;import com.sun.electric.tool.user.User;import java.awt.Color;import java.awt.Point;import java.awt.Rectangle;import java.awt.geom.AffineTransform;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.util.ArrayList;import java.util.BitSet;import java.util.Collections;import java.util.Comparator;import java.util.HashMap;import java.util.HashSet;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;/** * Class to hold scalable representation of circuit displays. */public class VectorCache { public static boolean DEBUG = false; public static final VectorCache theCache = new VectorCache(EDatabase.clientDatabase()); /** database to work. */ public final EDatabase database; /** list of cell expansions. */ private final ArrayList<VectorCellGroup> cachedCells = new ArrayList<VectorCellGroup>(); /** list of polygons to include in cells */ private final Map<CellId,List<VectorBase>> addPolyToCell = new HashMap<CellId,List<VectorBase>>(); /** list of instances to include in cells */ private final Map<CellId,List<VectorLine>> addInstToCell = new HashMap<CellId,List<VectorLine>>(); /** List of VectorManhattanBuilders */ private final ArrayList<VectorManhattanBuilder>boxBuilders = new ArrayList<VectorManhattanBuilder>(); /** List of VectorManhattanBiilders for pure ndoes. */ private final ArrayList<VectorManhattanBuilder>pureBoxBuilders = new ArrayList<VectorManhattanBuilder>(); /** Current VarContext. */ private VarContext varContext; /** Current scale. */ private double curScale; /** True to clear fade images. */ private boolean clearFadeImages; /** True to clear cache. */ private boolean clearCache; /** zero rectangle */ private final Rectangle2D CENTERRECT = new Rectangle2D.Double(0, 0, 0, 0); private EGraphics instanceGraphics = new EGraphics(false, false, null, 0, 0,0,0, 1.0,true, new int[] {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}); private final EditWindow0 dummyWnd = new EditWindow0() { public VarContext getVarContext() { return varContext; } public double getScale() { return curScale; } public double getGlobalTextScale() { return User.getGlobalTextScale(); } }; /** * Class which defines the common information for all cached displayable objects */ public static abstract class VectorBase { Layer layer; EGraphics graphics; VectorBase(Layer layer, EGraphics graphics) { this.layer = layer; this.graphics = graphics; } /** * Return true if this is a filled primitive. */ boolean isFilled() { return false; } } /** * Class which defines a cached Manhattan rectangle. */ static class VectorManhattan extends VectorBase { /** coordinates of boxes: 1X, 1Y, hX, hY */ int[] coords; boolean pureLayer; VectorManhattan(int[] coords, Layer layer, EGraphics graphics, boolean pureLayer) { super(layer, graphics); this.coords = coords; this.pureLayer = pureLayer; } VectorManhattan(double c1X, double c1Y, double c2X, double c2Y, Layer layer, EGraphics graphics, boolean pureLayer) { this(new int[] { databaseToGrid(c1X), databaseToGrid(c1Y), databaseToGrid(c2X), databaseToGrid(c2Y) }, layer, graphics, pureLayer); } @Override boolean isFilled() { return true; } } /** * Class which collects boxes for VectorManhattan. */ static class VectorManhattanBuilder { /** Number of boxes. */ int size; // number of boxes /** Coordiantes of boxes. */ int[] coords = new int[4]; private void add(double lX, double lY, double hX, double hY) { if (size*4 >= coords.length) { int[] newCoords = new int[coords.length*2]; System.arraycopy(coords, 0, newCoords, 0, coords.length); coords = newCoords; } int i = size*4; coords[i] = databaseToGrid(lX); coords[i + 1] = databaseToGrid(lY); coords[i + 2] = databaseToGrid(hX); coords[i + 3] = databaseToGrid(hY); size++; } int[] toArray() { int[] a = new int[size*4]; System.arraycopy(coords, 0, a, 0, a.length); return a; } private void clear() { size = 0; } } /** * Class which defines a cached polygon (nonmanhattan). */ static class VectorPolygon extends VectorBase { Point[] points; VectorPolygon(Point2D [] points, Layer layer, EGraphics graphics) { super(layer, graphics); this.points = new Point[points.length]; for (int i = 0; i < points.length; i++) { Point2D p = points[i]; this.points[i] = new Point(databaseToGrid(p.getX()), databaseToGrid(p.getY())); } } @Override boolean isFilled() { return true; } } /** * Class which defines a cached line. */ static class VectorLine extends VectorBase { int fX, fY, tX, tY; int texture; VectorLine(double fX, double fY, double tX, double tY, int texture, Layer layer, EGraphics graphics) { super(layer, graphics); this.fX = databaseToGrid(fX); this.fY = databaseToGrid(fY); this.tX = databaseToGrid(tX); this.tY = databaseToGrid(tY); this.texture = texture; } } /** * Class which defines a cached circle (filled, opened, or thick). */ static class VectorCircle extends VectorBase { int cX, cY, eX, eY; int nature; VectorCircle(double cX, double cY, double eX, double eY, int nature, Layer layer, EGraphics graphics) { super(layer, graphics); this.cX = databaseToGrid(cX); this.cY = databaseToGrid(cY); this.eX = databaseToGrid(eX); this.eY = databaseToGrid(eY); this.nature = nature; } @Override boolean isFilled() { // true for disc nature return nature == 2; } } /** * Class which defines a cached arc of a circle (normal or thick). */ static class VectorCircleArc extends VectorBase { int cX, cY, eX1, eY1, eX2, eY2; boolean thick; VectorCircleArc(double cX, double cY, double eX1, double eY1, double eX2, double eY2, boolean thick, Layer layer, EGraphics graphics) { super(layer, graphics); this.cX = databaseToGrid(cX); this.cY = databaseToGrid(cY); this.eX1 = databaseToGrid(eX1); this.eY1 = databaseToGrid(eY1); this.eX2 = databaseToGrid(eX2); this.eY2 = databaseToGrid(eY2); this.thick = thick; } } /** * Class which defines cached text. */ static class VectorText extends VectorBase { /** text is on a Cell */ static final int TEXTTYPECELL = 1; /** text is on an Export */ static final int TEXTTYPEEXPORT = 2; /** text is on a Node */ static final int TEXTTYPENODE = 3; /** text is on an Arc */ static final int TEXTTYPEARC = 4; /** text is on an Annotations */ static final int TEXTTYPEANNOTATION = 5; /** text is on an Instances */ static final int TEXTTYPEINSTANCE = 6; /** the text location */ Rectangle bounds; /** the text style */ Poly.Type style; /** the descriptor of the text */ TextDescriptor descript; /** the text to draw */ String str; /** the text height (in display units) */ float height; /** the type of text (CELL, EXPORT, etc.) */ int textType; /** valid for export text */ PrimitivePort basePort; VectorText(Rectangle2D bounds, Poly.Type style, TextDescriptor descript, String str, int textType, Export e, Layer layer, EGraphics graphics) { super(layer, graphics); this.bounds = new Rectangle(databaseToGrid(bounds.getX()), databaseToGrid(bounds.getY()), databaseToGrid(bounds.getWidth()), databaseToGrid(bounds.getHeight())); this.style = style; this.descript = descript; this.str = str; this.textType = textType; if (e != null) basePort = e.getBasePort(); height = 1; if (descript != null) { TextDescriptor.Size tds = descript.getSize(); if (!tds.isAbsolute()) height = (float)tds.getSize(); } } } /** * Class which defines a cached cross (a dot, large or small). */ static class VectorCross extends VectorBase { int x, y; boolean small; VectorCross(double x, double y, boolean small, Layer layer, EGraphics graphics) { super(layer, graphics); this.x = databaseToGrid(x); this.y = databaseToGrid(y); this.small = small; } } /** * Class which defines a cached subcell reference. */ static class VectorSubCell { ImmutableNodeInst n; CellId subCellId; int offsetX, offsetY; BitSet shownPorts = new BitSet(); VectorSubCell(NodeInst ni, Point2D offset) { n = ni.getD(); Cell subCell = (Cell)ni.getProto(); subCellId = subCell.getId(); offsetX = databaseToGrid(offset.getX()); offsetY = databaseToGrid(offset.getY()); } } /** * Class which holds the cell caches for a given cell. * Since each cell is cached many times, once for every orientation on the screen, * this object can hold many cell caches. */ class VectorCellGroup { CellId cellId; ERectangle bounds; float cellArea; float cellMinSize; CellBackup cellBackup; boolean isParameterized;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -