⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 electricobject.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* -*- tab-width: 4 -*- * * Electric(tm) VLSI Design System * * File: ElectricObject.java * * Copyright (c) 2003 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.database.variable;import com.sun.electric.database.ImmutableElectricObject;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.EDatabase;import com.sun.electric.database.hierarchy.Export;import com.sun.electric.database.id.TechId;import com.sun.electric.database.text.Name;import com.sun.electric.database.text.TextUtils;import com.sun.electric.database.topology.ArcInst;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.technology.TechPool;import com.sun.electric.technology.Technology;import com.sun.electric.technology.technologies.Artwork;import com.sun.electric.technology.technologies.Generic;import com.sun.electric.technology.technologies.Schematics;import com.sun.electric.tool.user.ActivityLogger;import com.sun.electric.tool.user.User;import java.awt.geom.AffineTransform;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.io.Serializable;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;/** * This class is the base class of all Electric objects that can be extended with "Variables". * <P> * This class should be thread-safe. */public abstract class ElectricObject implements Serializable{	// ------------------------ private data ------------------------------------	// ------------------------ private and protected methods -------------------	/**	 * The protected constructor.	 */	protected ElectricObject() {}	/**	 * Returns persistent data of this ElectricObject with Variables.	 * @return persistent data of this ElectricObject.	 */	public abstract ImmutableElectricObject getD();	// ------------------------ public methods -------------------	/**	 * Returns true if object is linked into database	 */	public abstract boolean isLinked();	/**	 * Method to return the value of the the Variable on this ElectricObject with a given key and type.	 * @param key the key of the Variable.	 * @param type the required type of the Variable.	 * @return the value Variable with that key and type, or null if there is no such Variable     * @throws NullPointerException if key is null	 */	public <T> T getVarValue(Variable.Key key, Class<T> type) {        return getVarValue(key, type, null);	}	/**	 * Method to return the value of the the Variable on this ElectricObject with a given key and type.	 * @param key the key of the Variable.	 * @param type the required type of the Variable.     * @param defaultValue default value	 * @return the value Variable with that key and type, or defaultValue if there is no such Variable     * @throws NullPointerException if key or type is null	 */	public <T> T getVarValue(Variable.Key key, Class<T> type, T defaultValue) {		Variable var = getVar(key);        if (var != null) {            Object value = var.getObject();            if (type.isInstance(value))                return (T)value;        }		return defaultValue; // null type means any type	}	/**	 * Method to return the Variable on this ElectricObject with a given name.	 * @param name the name of the Variable.	 * @return the Variable with that name, or null if there is no such Variable.     * @throws NullPointerException if name is null	 */	public Variable getVar(String name) {		Variable.Key key = Variable.findKey(name);		return key != null ? getVar(key) : null;	}	/**	 * Method to return the Variable on this ElectricObject with a given key.	 * @param key the key of the Variable.	 * @return the Variable with that key, or null if there is no such Variable.     * @throws NullPointerException if key is null	 */	public Variable getVar(Variable.Key key) {        checkExamine();		return getD().getVar(key);	}	/**	 * Method to return the Parameter or Variable on this ElectricObject with a given name.	 * @param name the name of the Parameter or Variable.	 * @return the Parameter or Variable with that key, or null if there is no such Parameter or Variable Variable.     * @throws NullPointerException if key is null	 */	public Variable getParameterOrVariable(String name) {		Variable.Key key = Variable.findKey(name);        return key != null ? getParameterOrVariable(key) : null;	}	/**	 * Method to return the Parameter or Variable on this ElectricObject with a given key.	 * @param key the key of the Parameter or Variable.	 * @return the Parameter or Variable with that key, or null if there is no such Parameter or Variable Variable.     * @throws NullPointerException if key is null	 */	public Variable getParameterOrVariable(Variable.Key key) {        checkExamine();		return getD().getVar(key);	}	/**	 * Returns the TextDescriptor on this ElectricObject selected by variable key.	 * This key may be a key of variable on this ElectricObject or one of the	 * special keys:	 * <code>NodeInst.NODE_NAME</code>	 * <code>NodeInst.NODE_PROTO</code>	 * <code>ArcInst.ARC_NAME</code>	 * <code>Export.EXPORT_NAME</code>	 * The TextDescriptor gives information for displaying the Variable.	 * @param varKey key of variable or special key.	 * @return the TextDescriptor on this ElectricObject.	 */	public TextDescriptor getTextDescriptor(Variable.Key varKey)	{		Variable var = getParameterOrVariable(varKey);		if (var == null) return null;		return var.getTextDescriptor();	} 	/**	 * Returns the TextDescriptor on this ElectricObject selected by variable key.	 * This key may be a key of variable on this ElectricObject or one of the	 * special keys:	 * <code>NodeInst.NODE_NAME</code>	 * <code>NodeInst.NODE_PROTO</code>	 * <code>ArcInst.ARC_NAME</code>	 * <code>Export.EXPORT_NAME</code>	 * The TextDescriptor gives information for displaying the Variable.	 * @param varKey key of variable or special key.	 * @return the TextDescriptor on this ElectricObject.	 */	public MutableTextDescriptor getMutableTextDescriptor(Variable.Key varKey)	{		TextDescriptor td = getTextDescriptor(varKey);		if (td == null) return null;		return new MutableTextDescriptor(td);	}	/**	 * Returns the Code on this ElectricObject selected by variable key.	 * This key may be a key of variable on this ElectricObject or one of the	 * special keys:	 * <code>NodeInst.NODE_NAME</code>	 * <code>NodeInst.NODE_PROTO</code>	 * <code>ArcInst.ARC_NAME</code>	 * <code>Export.EXPORT_NAME</code>	 * The Code gives information for displaying the Variable.	 * @param varKey key of variable or special key.	 * @return the Code on this ElectricObject.	 */	public CodeExpression.Code getCode(Variable.Key varKey)	{		Variable var = getParameterOrVariable(varKey);        return var != null ? var.getCode() : CodeExpression.Code.NONE;	}	/**	 * Method to return true if the Variable on this ElectricObject with given key is a parameter.	 * Parameters are those Variables that have values on instances which are	 * passed down the hierarchy into the contents.	 * Parameters can only exist on Cell and NodeInst objects.	 * @param varKey key to test	 * @return true if the Variable with given key is a parameter.	 */	public boolean isParam(Variable.Key varKey) { return false; }	/**	 * Method to return the number of displayable Variables on this ElectricObject.	 * A displayable Variable is one that will be shown with its object.	 * Displayable Variables can only sensibly exist on NodeInst and ArcInst objects.	 * @return the number of displayable Variables on this ElectricObject.	 */	public int numDisplayableVariables(boolean multipleStrings)	{        //checkExamine();		int numVars = 0;		for (Iterator<Variable> it = getParametersAndVariables(); it.hasNext(); )		{			Variable var = it.next();			if (var.isDisplay())			{				int len = var.getLength();				if (len > 1 && var.getTextDescriptor().getDispPart() == TextDescriptor.DispPos.NAMEVALUE) len++;				if (!multipleStrings) len = 1;				numVars += len;			}		}		return numVars;	}	/**	 * Method to add all displayable Variables on this Electric object to an array of Poly objects.	 * @param rect a rectangle describing the bounds of the object on which the Variables will be displayed.	 * @param polys an array of Poly objects that will be filled with the displayable Variables.	 * @param start the starting index in the array of Poly objects to fill with displayable Variables.	 * @param wnd window in which the Variables will be displayed.	 * @param multipleStrings true to break multiline text into multiple Polys.	 * @return the number of Polys that were added.	 */	public int addDisplayableVariables(Rectangle2D rect, Poly [] polys, int start, EditWindow0 wnd, boolean multipleStrings)	{		checkExamine();		int numAddedVariables = 0;		double cX = rect.getCenterX();		double cY = rect.getCenterY();		for (Iterator<Variable> it = getParametersAndVariables(); it.hasNext(); )		{			Variable var = it.next();			if (!var.isDisplay()) continue;			Poly [] polyList = getPolyList(var, cX, cY, wnd, multipleStrings);			for(int i=0; i<polyList.length; i++)			{				int index = start + numAddedVariables;				polys[index] = polyList[i];				polys[index].setStyle(Poly.rotateType(polys[index].getStyle(), this));				numAddedVariables++;			}		}		return numAddedVariables;	}	/**	 * Method to get all displayable Variables on this ElectricObject and its PortInsts to an array of Poly objects.	 * @param rect a rectangle describing the bounds of the object on which the Variables will be displayed.	 * @param wnd window in which the Variables will be displayed.	 * @param multipleStrings true to break multiline text into multiple Polys.	 * @return an array of Poly objects with displayable variables.	 */	public Poly[] getDisplayableVariables(Rectangle2D rect, EditWindow0 wnd, boolean multipleStrings) {        int numVars = numDisplayableVariables(multipleStrings);        if (numVars == 0) return Poly.NULL_ARRAY;        Poly[] polys = new Poly[numVars];        addDisplayableVariables(rect, polys, 0, wnd, multipleStrings);        return polys;    }	/**	 * Method to compute a Poly that describes text.	 * The text can be described by an ElectricObject (Exports or cell instance names).	 * The text can be described by a node or arc name.	 * The text can be described by a variable on an ElectricObject.	 * @param wnd the EditWindow0 in which the text will be drawn.	 * @param varKey the Variable.Key on the ElectricObject (may be null).	 * @return a Poly that covers the text completely.	 * Even though the Poly is scaled for a particular EditWindow,	 * its coordinates are in object space, not screen space.	 */	public Poly computeTextPoly(EditWindow0 wnd, Variable.Key varKey)	{		checkExamine();		Poly poly = null;		if (varKey != null)		{			if (this instanceof Export)			{				Export pp = (Export)this;				if (varKey == Export.EXPORT_NAME)				{					poly = pp.getNamePoly();				} else				{//					PortInst pi = pp.getOriginalPort();					Rectangle2D bounds = pp.getNamePoly().getBounds2D();//					TextDescriptor td = pp.getTextDescriptor(Export.EXPORT_NAME);					Poly [] polys = pp.getPolyList(pp.getVar(varKey), bounds.getCenterX(), bounds.getCenterY(), wnd, false);					if (polys.length > 0)					{						poly = polys[0];					}				}			} else if (this instanceof PortInst)			{				PortInst pi = (PortInst)this;				Rectangle2D bounds = pi.getPoly().getBounds2D();				Poly [] polys = pi.getPolyList(pi.getVar(varKey), bounds.getCenterX(), bounds.getCenterY(), wnd, false);				if (polys.length > 0)				{					poly = polys[0];					poly.transform(pi.getNodeInst().rotateOut());				}			} else if (this instanceof Geometric)			{				Geometric geom = (Geometric)this;				if (varKey == NodeInst.NODE_NAME || varKey == ArcInst.ARC_NAME)				{					TextDescriptor td = geom.getTextDescriptor(varKey);					Poly.Type style = td.getPos().getPolyType();					Point2D [] pointList = null;					if (style == Poly.Type.TEXTBOX)					{						pointList = Poly.makePoints(geom.getBounds());					} else					{						pointList = new Point2D.Double[1];						pointList[0] = new Point2D.Double(geom.getTrueCenterX()+td.getXOff(), geom.getTrueCenterY()+td.getYOff());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -