📄 electricobject.java
字号:
break; } } if (indexAdjusted) break; } // this bracketed expression cannot be incremented: move on if (startPos > 0 && index.charAt(startPos-1) == ']') { endPos = startPos-1; continue; } break; } // see if this bracketed expression is a pure number String bracketedExpression = index.substring(startPos+1, endPos); if (TextUtils.isANumber(bracketedExpression)) { int nextIndex = TextUtils.atoi(bracketedExpression) + 1; for(; ; nextIndex++) { String newIndex = index.substring(0, startPos) + "[" + 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; break; } } if (indexAdjusted) break; } // remember the first index that could be incremented in a pinch if (possibleStart < 0) { possibleStart = startPos; possibleEnd = endPos; } // this bracketed expression cannot be incremented: move on if (startPos > 0 && index.charAt(startPos-1) == ']') { endPos = startPos-1; continue; } break; } // if there was a possible place to increment, do it if (!indexAdjusted && possibleStart >= 0) { // nothing simple, but this one can be incremented int i; for(i=possibleEnd-1; i>possibleStart; i--) if (!TextUtils.isDigit(index.charAt(i))) break; int nextIndex = TextUtils.atoi(index.substring(i+1)) + 1; int startPos = i+1; if (index.charAt(startPos-1) == separateChar) startPos--; for(; ; nextIndex++) { String newIndex = index.substring(0, startPos) + separateChar + nextIndex + index.substring(possibleEnd); 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; break; } } } } // if the index was not adjusted, adjust the base part if (!indexAdjusted) { // array contents cannot be incremented: increment base name String base = an.baseName; int startPos = base.length(); int endPos = base.length(); // if there is a numeric part at the end, increment that String localSepString = String.valueOf(separateChar); while (startPos > 0 && TextUtils.isDigit(base.charAt(startPos-1))) startPos--; int nextIndex = 1; if (startPos >= endPos) { if (startPos > 0 && base.charAt(startPos-1) == separateChar) startPos--; } else { nextIndex = TextUtils.atoi(base.substring(startPos)) + 1; localSepString = ""; } // find the unique index to use String prefix = base.substring(0, startPos) + localSepString; if (nextPlainIndex != null) { GenMath.MutableInteger nxt = nextPlainIndex.get(prefix); if (nxt == null) { nxt = new GenMath.MutableInteger(cell.getUniqueNameIndex(prefix, cls, nextIndex)); nextPlainIndex.put(prefix, nxt); } nextIndex = nxt.intValue(); nxt.increment(); } else { nextIndex = cell.getUniqueNameIndex(prefix, cls, nextIndex); } an.baseName = prefix + nextIndex + base.substring(endPos); } } StringBuffer result = new StringBuffer(); boolean first = true; for(ArrayName an : names) { if (first) first = false; else result.append(","); result.append(an.baseName); if (an.indexPart != null) result.append(an.indexPart); } return result.toString(); } /** * Method to determine whether a Variable key on this object is deprecated. * Deprecated Variable keys are those that were used in old versions of Electric, * but are no longer valid. * @param key the key of the Variable. * @return true if the Variable key is deprecated. */ public boolean isDeprecatedVariable(Variable.Key key) { String name = key.toString(); if (name.length() == 0) return true; if (name.length() == 1) { char chr = name.charAt(0); if (!Character.isLetter(chr)) return true; } return false; } /** * Method to return an Iterator over all Variables on this ElectricObject. * @return an Iterator over all Variables on this ElectricObject. */ public synchronized Iterator<Variable> getVariables() { return getD().getVariables(); } /** * Method to return the number of Variables on this ElectricObject. * @return the number of Variables on this ElectricObject. */ public synchronized int getNumVariables() { return getD().getNumVariables(); } /** * Method to return an Iterator over all Parameters and Variables on this ElectricObject. * @return an Iterator over all Parameters and Variables on this ElectricObject. */ public Iterator<Variable> getParametersAndVariables() { return getVariables(); } /** * Routing to check whether changing of this cell allowed or not. * By default checks whole database change. Overriden in subclasses. */ public void checkChanging() { EDatabase database = getDatabase(); if (database != null) database.checkChanging(); } /** * Routing to check whether undoing of this cell allowed or not. * By default checks whole database undo. Overriden in subclasses. */ public void checkUndoing() { getDatabase().checkUndoing(); } /** * Method to make sure that this object can be examined. * Ensures that an examine job is running. */ public void checkExamine() { EDatabase database = getDatabase(); if (database != null) database.checkExamine(); } /** * Returns database to which this ElectricObject belongs. * Some objects are not in database, for example Geometrics in PaletteFrame. * Method returns null for non-database objects. * @return database to which this ElectricObject belongs. */ public abstract EDatabase getDatabase(); /** Returns TechPool of this database */ public TechPool getTechPool() { return getDatabase().getTechPool(); } /** * Get Technology by TechId * TechId must belong to same IdManager as TechPool * @param techId TechId to find * @return Technology b giben TechId or null * @throws IllegalArgumentException of TechId is not from this IdManager */ public Technology getTech(TechId techId) { return getTechPool().getTech(techId); } /** Returns Artwork technology in this database */ public Artwork getArtwork() { return getTechPool().getArtwork(); } /** Returns Generic technology in this database */ public Generic getGeneric() { return getTechPool().getGeneric(); } /** Returns Schematics technology in this database */ public Schematics getSchematics() { return getTechPool().getSchematics(); } /** * Method which indicates that this object is in database. * Some objects are not in database, for example Geometrics in PaletteFrame. * @return true if this object is in database, false if it is not a database object, * or if it is a dummy database object (considered not to be in the database). */ protected boolean isDatabaseObject() { return true; } /** * Method to determine the appropriate Cell associated with this ElectricObject. * @return the appropriate Cell associated with this ElectricObject. * Returns null if no Cell can be found. */ public Cell whichCell() { return null; } /** * Method to write a description of this ElectricObject (lists all Variables). * Displays the description in the Messages Window. */ public void getInfo() { checkExamine(); boolean firstvar = true; for(Iterator<Variable> it = getParametersAndVariables(); it.hasNext() ;) { Variable val = it.next(); Variable.Key key = val.getKey(); if (val == null) continue; if (firstvar) System.out.println("Variables:"); firstvar = false; Object addr = val.getObject(); String par = isParam(key) ? "(param)" : "";// String par = val.isParam() ? "(param)" : ""; if (addr instanceof Object[]) { Object[] ary = (Object[]) addr; System.out.print(" " + key.getName() + "(" + ary.length + ") = ["); for (int i = 0; i < ary.length; i++) { if (i > 4) { System.out.print("..."); break; } if (ary[i] instanceof String) System.out.print("\""); System.out.print(ary[i]); if (ary[i] instanceof String) System.out.print("\""); if (i < ary.length-1) System.out.print(", "); } System.out.println("] "+par); } else { System.out.println(" " + key.getName() + "= " + addr + " "+par); } } } /** * Returns a printable version of this ElectricObject. * @return a printable version of this ElectricObject. */ public String toString() { return getClass().getName(); }// /**// * Observer method to update variables in Icon instance if cell master changes// * @param o// * @param arg// */// public void update(Observable o, Object arg)// {// System.out.println("Entering update");// // New// if (arg instanceof Variable)// {// Variable var = (Variable)arg;// // You can't call newVar(var.getKey(), var.getObject()) to avoid infinite loop// newVar(var.getD());// }// else if (arg instanceof Object[])// {// Object[] array = (Object[])arg;//// if (!(array[0] instanceof String))// {// System.out.println("Error in ElectricObject.update");// return;// }// String function = (String)array[0];// if (function.startsWith("setTextDescriptor"))// {// Variable.Key varKey = (Variable.Key)array[1];// TextDescriptor td = (TextDescriptor)array[2];// // setTextDescriptor(String varName, TextDescriptor td)// setTextDescriptor(varKey, td);// }// else if (function.startsWith("delVar"))// {// Variable.Key key = (Variable.Key)array[1];// delVarNoObserver(key);// }//// else if (array[0] instanceof Variable.Key)//// {//// // Variable updateVar(String name, Object value)//// Variable.Key key = (Variable.Key)array[0];//// updateVar(key, array[1]);//// }// }// } /** * Method to check invariants in this ElectricObject. * @exception AssertionError if invariants are not valid */ protected void check() {}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -