📄 arcinst.java
字号:
* Method to return the name key of this ArcInst. * @return the name key of this ArcInst, null if there is no name. */ public Name getNameKey() { return d.name; } /** * Method to rename this ArcInst. * This ArcInst must be linked to database. * @param name new name of this geometric. * @return true on error */ public boolean setName(String name) { assert isLinked(); Name key; boolean doSmart = false; if (name != null && name.length() > 0) { if (name.equals(getName())) return false; if (!isUsernamed()) doSmart = true; key = Name.findName(name); } else { if (!isUsernamed()) return false; key = topology.getArcAutoname(); } if (checkNameKey(key, topology)) return true; ImmutableArcInst oldD = d; lowLevelModify(d.withName(key)); if (doSmart) { TextDescriptor td = TextDescriptor.getArcTextDescriptor(); TextDescriptor smartDescriptor = getSmartTextDescriptor(getAngle(), getLambdaBaseWidth(), td); setTextDescriptor(ARC_NAME, smartDescriptor); } // apply constraints Constraints.getCurrent().modifyArcInst(this, oldD); return false; } /** * Method to return a "smart" text descriptor for an arc. * @param angle the angle of the arc (in tenths of a degree). * @param width the width of the arc. * @param prev the former text descriptor of the arc. * @return a new text descriptor that handles smart placement. */ private static TextDescriptor getSmartTextDescriptor(int angle, double width, TextDescriptor prev) { // assigning valid name: do smart text placement if ((angle%1800) == 0) { // horizontal arc int smart = User.getSmartHorizontalPlacementArc(); if (smart == 1) { // arc text above return prev.withPos(TextDescriptor.Position.UP).withOff(0, width/2); } else if (smart == 2) { // arc text below return prev.withPos(TextDescriptor.Position.DOWN).withOff(0, -width/2); } } else if ((angle%1800) == 900) { // vertical arc int smart = User.getSmartVerticalPlacementArc(); if (smart == 1) { // arc text to the left return prev.withPos(TextDescriptor.Position.LEFT).withOff(-width/2, 0); } else if (smart == 2) { // arc text to the right return prev.withPos(TextDescriptor.Position.RIGHT).withOff(width/2, 0); } } return prev; } /** * Method to check the new name key of an ArcInst. * @param name new name key of this ArcInst. * @param parent parent Cell used for error message * @return true on error. */ private static boolean checkNameKey(Name name, Topology topology) { Cell parent = topology.cell; if (!name.isValid()) { System.out.println(parent + ": Invalid name \""+name+"\" wasn't assigned to arc" + " :" + Name.checkName(name.toString())); return true; } if (name.isTempname() && name.getBasename() != ImmutableArcInst.BASENAME) { System.out.println(parent + ": Temporary arc name \""+name+"\" must have prefix net@"); return true; } if (name.hasEmptySubnames()) { if (name.isBus()) System.out.println(parent + ": Name \""+name+"\" with empty subnames wasn't assigned to arc"); else System.out.println(parent + ": Cannot assign empty name \""+name+"\" to arc"); return true; } if (topology.hasTempArcName(name)) { System.out.println(parent + " already has ArcInst with temporary name \""+name+"\""); return true; } return false; } /** * Returns the TextDescriptor on this ArcInst selected by variable key. * This key may be a key of variable on this ArcInst or the * special keys: * <code>ArcInst.ARC_NAME</code> * The TextDescriptor gives information for displaying the Variable. * @param varKey key of variable or special key. * @return the TextDescriptor on this ArcInst. */ public TextDescriptor getTextDescriptor(Variable.Key varKey) { if (varKey == ARC_NAME) return d.nameDescriptor; return super.getTextDescriptor(varKey); } /** * Updates the TextDescriptor on this ArcInst selected by varKey. * The varKey may be a key of variable on this ArcInst or * the special key ArcInst.ARC_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 */ @Override public void setTextDescriptor(Variable.Key varKey, TextDescriptor td) { if (varKey == ARC_NAME) { setD(d.withNameDescriptor(td), true); return; } super.setTextDescriptor(varKey, td); } /** * Method to determine whether a variable key on ArcInst 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) { if (key == ARC_NAME) return true; return super.isDeprecatedVariable(key); } /** * Method to describe this ArcInst as a string. * @param withQuotes to wrap description between quotes * @return a description of this ArcInst. */ public String describe(boolean withQuotes) { String description = getProto().describe(); String name = (withQuotes) ? "'"+getName()+"'" : getName(); if (name != null) description += "[" + name + "]"; return description; } /** * Compares ArcInsts by their Cells and names. * @param that the other ArcInst. * @return a comparison between the ArcInsts. */ public int compareTo(ArcInst that) { int cmp; if (this.parent != that.parent) { cmp = this.parent.compareTo(that.parent); if (cmp != 0) return cmp; } cmp = this.getName().compareTo(that.getName()); if (cmp != 0) return cmp; return this.d.arcId - that.d.arcId; } /** * Returns a printable version of this ArcInst. * @return a printable version of this ArcInst. */ public String toString() { return "arc " + describe(true); } /****************************** CONSTRAINTS ******************************/ private void setFlag(ImmutableArcInst.Flag flag, boolean state) { checkChanging(); if (setD(d.withFlag(flag, state), true)) redoGeometric(); } /** * Method to set this ArcInst to be rigid. * Rigid arcs cannot change length or the angle of their connection to a NodeInst. * @param state */ public void setRigid(boolean state) { setFlag(ImmutableArcInst.RIGID, state); } /** * Method to tell whether this ArcInst is rigid. * Rigid arcs cannot change length or the angle of their connection to a NodeInst. * @return true if this ArcInst is rigid. */ public boolean isRigid() { return d.isRigid(); } /** * Method to set this ArcInst to be fixed-angle. * Fixed-angle arcs cannot change their angle, so if one end moves, * the other may also adjust to keep the arc angle constant. * @param state */ public void setFixedAngle(boolean state) { setFlag(ImmutableArcInst.FIXED_ANGLE, state); } /** * Method to tell whether this ArcInst is fixed-angle. * Fixed-angle arcs cannot change their angle, so if one end moves, * the other may also adjust to keep the arc angle constant. * @return true if this ArcInst is fixed-angle. */ public boolean isFixedAngle() { return d.isFixedAngle(); } /** * Method to set this ArcInst to be slidable. * Arcs that slide will not move their connected NodeInsts if the arc's end is still within the port area. * Arcs that cannot slide will force their NodeInsts to move by the same amount as the arc. * Rigid arcs cannot slide but nonrigid arcs use this state to make a decision. * @param state */ public void setSlidable(boolean state) { setFlag(ImmutableArcInst.SLIDABLE, state); } /** * Method to tell whether this ArcInst is slidable. * Arcs that slide will not move their connected NodeInsts if the arc's end is still within the port area. * Arcs that cannot slide will force their NodeInsts to move by the same amount as the arc. * Rigid arcs cannot slide but nonrigid arcs use this state to make a decision. * @return true if this ArcInst is slidable. */ public boolean isSlidable() { return d.isSlidable(); } /****************************** PROPERTIES ******************************/ /** * Method to determine whether this ArcInst is directional, with an arrow on one end. * Directional arcs have an arrow drawn on them to indicate flow. * It is only for documentation purposes and does not affect the circuit. * @param connIndex TAILEND (0) for the tail of this ArcInst, HEADEND (1) for the head. * @return true if that end has a directional arrow on it. */ public boolean isArrowed(int connIndex) { return d.isArrowed(connIndex); } /** * Method to determine whether this ArcInst is directional, with an arrow on the tail. * Directional arcs have an arrow drawn on them to indicate flow. * It is only for documentation purposes and does not affect the circuit. * @return true if the arc's tail has a directional arrow on it. */ public boolean isTailArrowed() { return d.isTailArrowed(); } /** * Method to determine whether this ArcInst is directional, with an arrow on the head. * Directional arcs have an arrow drawn on them to indicate flow. * It is only for documentation purposes and does not affect the circuit. * @return true if the arc's head has a directional arrow on it. */ public boolean isHeadArrowed() { return d.isHeadArrowed(); } /** * Method to determine whether this ArcInst is directional, with an arrow line drawn down the center. * Directional arcs have an arrow drawn on them to indicate flow. * It is only for documentation purposes and does not affect the circuit. * The body is typically drawn when one of the ends has an arrow on it, but it may be * drawin without an arrow head in order to continue an attached arc that has an arrow. * @return true if the arc's tail has an arrow line on it. */ public boolean isBodyArrowed() { return d.isBodyArrowed(); } /** * Method to set this ArcInst to be directional, with an arrow on one end. * Directional arcs have an arrow drawn on them to indicate flow. * It is only for documentation purposes and does not affect the circuit. * @param connIndex TAILEND (0) for the tail of this ArcInst, HEADEND (1) for the head. * @param state true to show a directional arrow on the specified end. */ public void setArrowed(int connIndex, boolean state) { switch (connIndex) { case ImmutableArcInst.TAILEND: setTailArrowed(state); break; case ImmutableArcInst.HEADEND: setHeadArrowed(state); break; default: throw new IllegalArgumentException("Bad end " + connIndex); } } /** * Method to set this ArcInst to be directional, with an arrow on the tail. * Directional arcs have an arrow drawn on them to indicate flow. * It is only for documentation purposes and does not affect the circuit. * @param state true to show a directional arrow on the tail. */ public void setTailArrowed(boolean state) { setFlag(ImmutableArcInst.TAIL_ARROWED, state); } /** * Method to set this ArcInst to be directional, with an arrow on the head. * Directional arcs have an arrow drawn on them to indicate flow. * It is only for documentation purposes and does not affect the circuit. * @param state true to show a directional arrow on the head. */ public void setHeadArrowed(boolean state) { setFlag(ImmutableArcInst.HEAD_ARROWED, state); } /** * Method to set this ArcInst to be directional, with an arrow line drawn down the center. * Directional arcs have an arrow drawn on them to indicate flow. * It is only for documentation purposes and does not affect the circuit. * The body is typically drawn when one of the ends has an arrow on it, but it may be * drawin without an arrow head in order to continue an attached arc that has an arrow. * @param state true to show a directional line on this arc.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -