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

📄 electricobject.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	 * @param value the object to store in the Variable.	 * @return the Variable that has been updated.	 */	public Variable updateVar(Variable.Key key, Object value)	{		Variable var = getVar(key);		if (var == null) return newVar(key, value);		addVar(var.withObject(value));		return getVar(key);	}	/**	 * Method to update a text Variable on this ElectricObject with the specified values.	 * If the Variable already exists, only the value is changed;     * the displayable attributes and Code are preserved.	 * @param key the key of the Variable.	 * @param text the text to store in the Variable.	 * @return the Variable that has been updated.	 */	public Variable updateVarText(Variable.Key key, String text)	{		Variable var = getVar(key);		if (var == null) return newVar(key, text);		addVar(var.withText(text));		return getVar(key);	}	/**	 * Method to update a Variable on this ElectricObject with the specified code.	 * If the Variable already exists, only the code is changed;     * the displayable attributes and value are preserved.	 * @param key the key of the Variable.	 * @param code the new code of the Variable.	 * @return the Variable that has been updated.	 */	public Variable updateVarCode(Variable.Key key, CodeExpression.Code code)	{		Variable var = getVar(key);		if (var == null) return null;        addVar(var.withCode(code));		return getVar(key);	}	/**	 * Updates the TextDescriptor on this ElectricObject selected by varKey.	 * The varKey may be a key of variable on this ElectricObject or one of the	 * special keys:	 * NodeInst.NODE_NAME	 * NodeInst.NODE_PROTO	 * ArcInst.ARC_NAME	 * Export.EXPORT_NAME	 * If varKey doesn't select any text descriptor, no action is performed.	 * The TextDescriptor gives information for displaying the Variable.	 * @param varKey key of variable or special key.	 * @param td new value TextDescriptor	 */	public void setTextDescriptor(Variable.Key varKey, TextDescriptor td) {		Variable var = getVar(varKey);		if (var == null) return;        td = td.withParam(false);		addVar(var.withTextDescriptor(td));	}	/**	 * Method to set the X and Y offsets of the text in the TextDescriptor selected by key of	 * variable or special key.	 * The values are scaled by 4, so a value of 3 indicates a shift of 0.75 and a value of 4 shifts by 1.	 * @param varKey key of variable or special key.	 * @param xd the X offset of the text in the TextDescriptor.	 * @param yd the Y offset of the text in the TextDescriptor.	 * @see #setTextDescriptor(com.sun.electric.database.variable.Variable.Key,com.sun.electric.database.variable.TextDescriptor)	 * @see com.sun.electric.database.variable.Variable#withOff(double,double)	 */	public synchronized void setOff(Variable.Key varKey, double xd, double yd) {		TextDescriptor td = getTextDescriptor(varKey);		if (td != null) setTextDescriptor(varKey, td.withOff(xd, yd));	}	/**	 * Method to copy text descriptor from another ElectricObject to this ElectricObject.	 * @param other the other ElectricObject from which to copy Variables.	 * @param varKey selector of textdescriptor	 */	public void copyTextDescriptorFrom(ElectricObject other, Variable.Key varKey)	{		TextDescriptor td = other.getTextDescriptor(varKey);		if (td == null) return;		setTextDescriptor(varKey, td);	}	/**	 * Rename a Variable. Note that this creates a new variable of	 * the new name and copies all values from the old variable, and	 * then deletes the old variable.	 * @param name the name of the var to rename	 * @param newName the new name of the variable	 * @return the new renamed variable	 */	public Variable renameVar(String name, String newName) {		return renameVar(Variable.findKey(name), newName);	}	/**	 * Rename a Variable. Note that this creates a new variable of	 * the new name and copies all values from the old variable, and	 * then deletes the old variable.	 * @param key the name key of the var to rename	 * @param newName the new name of the variable	 * @return the new renamed variable, or null on error (no action taken)	 */	public Variable renameVar(Variable.Key key, String newName) {		// see if newName exists already		Variable.Key newKey = Variable.newKey(newName);		Variable var = getVar(newKey);		if (var != null) return null;            // name already exists		// get current Variable		Variable oldvar = getVar(key);		if (oldvar == null) return null;		// create new var		Variable newVar = newVar(newKey, oldvar.getObject(), oldvar.getTextDescriptor());		if (newVar == null) return null;		// copy settings from old var to new var//        newVar.setTextDescriptor();//        newVar.copyFlags(oldvar);		// delete old var		delVar(oldvar.getKey());		return newVar;	}	/**	 * Method to delete a Variable from this ElectricObject.	 * @param key the key of the Variable to delete.	 */	public abstract void delVar(Variable.Key key);	/**	 * Method to copy all variables from another ElectricObject to this ElectricObject.	 * @param other the other ElectricObject from which to copy Variables.	 */	public void copyVarsFrom(ElectricObject other)	{		checkChanging();		for (Iterator<Variable> it = other.getVariables(); it.hasNext(); )            addVar(it.next());	}	private static class ArrayName	{		private String baseName;		private String indexPart;	}	/**	 * Method to return a unique object name in a Cell.	 * @param name the original name that is not unique.	 * @param cell the Cell in which this name resides.	 * @param cls the class of the object on which this name resides.	 * @param leaveIndexValues true to leave the index values untouched	 * (i.e. "m[17]" will become "m_1[17]" instead of "m[18]").	 * @return a unique name for that class in that Cell.	 */	public static String uniqueObjectName(String name, Cell cell, Class cls, boolean leaveIndexValues) {		String newName = name;		for (int i = 0; !cell.isUniqueName(newName, cls, null); i++) {			newName = uniqueObjectNameLow(newName, cell, cls, null, null, leaveIndexValues);			if (i > 100) {				System.out.println("Can't create unique object name in " + cell + " from original " + name + " attempted " + newName);				return null;			}		}		return newName;	}	/**	 * Method to return a unique object name in a Cell.	 * @param name the original name that is not unique.	 * @param cell the Cell in which this name resides.	 * @param cls the class of the object on which this name resides.	 * @param already a Set of names already in use (lower case).	 * @param leaveIndexValues true to leave the index values untouches	 * (i.e. "m[17]" will become "m_1[17]" instead of "m[18]").	 * @return a unique name for that class in that Cell.	 */	public static String uniqueObjectName(String name, Cell cell, Class cls,		Set already, Map<String,GenMath.MutableInteger> nextPlainIndex, boolean leaveIndexValues)	{		String newName = name;		String lcName = TextUtils.canonicString(newName);		for (int i = 0; already.contains(lcName); i++)		{			newName = uniqueObjectNameLow(newName, cell, cls, already, nextPlainIndex, leaveIndexValues);			if (i > 100)			{				System.out.println("Can't create unique object name in " + cell + " from original " + name + " attempted " + newName);				return null;			}			lcName = TextUtils.canonicString(newName);		}		return newName;	}	private static String uniqueObjectNameLow(String name, Cell cell, Class cls,		Set already, Map<String,GenMath.MutableInteger> nextPlainIndex, boolean leaveIndexValues)	{		// first see if the name is unique		if (already != null)		{			if (!already.contains(TextUtils.canonicString(name))) return name;		} else		{			if (cell.isUniqueName(name, cls, null)) return name;		}		// see if there is a "++" anywhere to tell us what to increment		int plusPlusPos = name.indexOf("++");		if (plusPlusPos >= 0)		{			int numStart = plusPlusPos;			while (numStart > 0 && TextUtils.isDigit(name.charAt(numStart-1))) numStart--;			if (numStart < plusPlusPos)			{				int nextIndex = TextUtils.atoi(name.substring(numStart)) + 1;				for( ; ; nextIndex++)				{					String newname = name.substring(0, numStart) + nextIndex + name.substring(plusPlusPos);					if (already != null)					{						if (!already.contains(TextUtils.canonicString(newname))) return newname;					} else					{						if (cell.isUniqueName(newname, cls, null)) return newname;					}				}			}		}		// see if there is a "--" anywhere to tell us what to decrement		int minusMinusPos = name.indexOf("--");		if (minusMinusPos >= 0)		{			int numStart = minusMinusPos;			while (numStart > 0 && TextUtils.isDigit(name.charAt(numStart-1))) numStart--;			if (numStart < minusMinusPos)			{				int nextIndex = TextUtils.atoi(name.substring(numStart)) - 1;				for( ; nextIndex >= 0; nextIndex--)				{					String newname = name.substring(0, numStart) + nextIndex + name.substring(minusMinusPos);					if (already != null)					{						if (!already.contains(TextUtils.canonicString(newname))) return newname;					} else					{						if (cell.isUniqueName(newname, cls, null)) return newname;					}				}			}		}		// break the string into a list of ArrayName objects		List<ArrayName> names = new ArrayList<ArrayName>();		boolean inBracket = false;		int len = name.length();		int startOfBase = 0;		int startOfIndex = -1;		for(int i=0; i<len; i++)		{			char ch = name.charAt(i);			if (ch == '[')			{				if (startOfIndex < 0) startOfIndex = i;				inBracket = true;			}			if (ch == ']') inBracket = false;			if ((ch == ',' && !inBracket) || i == len-1)			{				// remember this arrayname				if (i == len-1) i++;				ArrayName an = new ArrayName();				int endOfBase = startOfIndex;				if (endOfBase < 0) endOfBase = i;				an.baseName = name.substring(startOfBase, endOfBase);				if (startOfIndex >= 0) an.indexPart = name.substring(startOfIndex, i);				names.add(an);				startOfBase = i+1;				startOfIndex = -1;			}		}		char separateChar = '_';		for(ArrayName an : names)		{			// adjust the index part if possible			boolean indexAdjusted = false;			String index = an.indexPart;			if (index != null && !leaveIndexValues)			{				int possibleEnd = 0;				int nameLen = index.length();				// see if the index part can be incremented				int possibleStart = -1;				int endPos = nameLen-1;				for(;;)				{					// find the range of characters in square brackets					int startPos = index.lastIndexOf('[', endPos);					if (startPos < 0) break;					// see if there is a comma in the bracketed expression					int i = index.indexOf(',', startPos);					if (i >= 0 && i < endPos)					{						// this bracketed expression cannot be incremented: move on						if (startPos > 0 && index.charAt(startPos-1) == ']')						{							endPos = startPos-1;							continue;						}						break;					}					// see if there is a colon in the bracketed expression					i = index.indexOf(':', startPos);					if (i >= 0 && i < endPos)					{						// colon: make sure there are two numbers						String firstIndex = index.substring(startPos+1, i);						String secondIndex = index.substring(i+1, endPos);						if (TextUtils.isANumber(firstIndex) && TextUtils.isANumber(secondIndex))						{							int startIndex = TextUtils.atoi(firstIndex);							int endIndex = TextUtils.atoi(secondIndex);							int spacing = Math.abs(endIndex - startIndex) + 1;							for(int nextIndex = 1; ; nextIndex++)							{								String newIndex = index.substring(0, startPos) + "[" + (startIndex+spacing*nextIndex) +									":" + (endIndex+spacing*nextIndex) + index.substring(endPos);								boolean unique;								if (already != null)								{									unique = !already.contains(TextUtils.canonicString(an.baseName + newIndex));								} else								{									unique = cell.isUniqueName(an.baseName + newIndex, cls, null);								}								if (unique)								{									indexAdjusted = true;									an.indexPart = newIndex;

⌨️ 快捷键说明

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