📄 export.java
字号:
* @param newPi the new PortInst on which to base this Export. * @return true on error. */ public boolean move(PortInst newPi) { checkChanging(); NodeInst newno = newPi.getNodeInst(); PortProto newsubpt = newPi.getPortProto(); // error checks if (newno.getParent() != parent) return true; if (newsubpt.getParent() != newno.getProto()) return true; if (doesntConnect(newsubpt.getBasePort())) return true; // remember old state ImmutableExport oldD = d; // change the port origin lowLevelModify(d.withOriginalPort(newno.getD().nodeId, newsubpt.getId())); // handle change control, constraint, and broadcast Constraints.getCurrent().modifyExport(this, oldD); // update all port characteristics exported from this one changeallports(); return false; } /****************************** LOW-LEVEL IMPLEMENTATION ******************************/ /** * Method to change the origin of this Export to another place in the Cell. * @param d the new PortInst in the cell that will hold this Export. */ public void lowLevelModify(ImmutableExport d) { assert isLinked(); boolean renamed = getNameKey() != d.name; boolean moved = this.d.originalNodeId != d.originalNodeId || this.d.originalPortId != d.originalPortId; // remove the old linkage if (moved) { NodeInst origNode = getOriginalPort().getNodeInst(); origNode.redoGeometric(); } if (renamed) parent.moveExport(portIndex, d.name.toString()); setD(d, false); // create the new linkage if (moved) { originalPort = parent.getPortInst(d.originalNodeId, d.originalPortId); originalPort.getNodeInst().redoGeometric(); } } /** * Method to set an index of this Export in Cell ports. * This is a zero-based index of ports on the Cell. * @param portIndex an index of this Export in Cell ports. */ void setPortIndex(int portIndex) { this.portIndex = portIndex; } /** * Method to copy state bits from other Export. * State bits are alowaysDrawn, bodyOnly and characteristic. * @param other Export from which to take state bits. */ public void copyStateBits(Export other) { setAlwaysDrawn(other.isAlwaysDrawn()); setBodyOnly(other.isBodyOnly()); setCharacteristic(other.getCharacteristic()); } /****************************** GRAPHICS ******************************/ /** * Method to return a Poly that describes this Export name. * @return a Poly that describes this Export's name. */ public Poly getNamePoly() { Poly poly = getOriginalPort().getPoly(); double cX = poly.getCenterX(); double cY = poly.getCenterY(); TextDescriptor td = getTextDescriptor(EXPORT_NAME); double offX = td.getXOff(); double offY = td.getYOff(); TextDescriptor.Position pos = td.getPos(); Poly.Type style = pos.getPolyType(); Point2D [] pointList = new Point2D.Double[1]; // must untransform the node to apply the offset NodeInst ni = getOriginalPort().getNodeInst(); if (!ni.getOrient().equals(Orientation.IDENT)) { pointList[0] = new Point2D.Double(cX, cY); AffineTransform trans = ni.rotateIn(); trans.transform(pointList[0], pointList[0]); pointList[0].setLocation(pointList[0].getX() + offX, pointList[0].getY() + offY); trans = ni.rotateOut(); trans.transform(pointList[0], pointList[0]); } else { pointList[0] = new Point2D.Double(cX + offX, cY + offY); } poly = new Poly(pointList); poly.setStyle(style); poly.setPort(this); poly.setString(getName()); poly.setTextDescriptor(td); poly.setDisplayedText(new DisplayedText(this, EXPORT_NAME)); return poly; } /****************************** TEXT ******************************/ /** * 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 parent; }; /** * Returns persistent data of this Export. * @return persistent data of this Export. */ @Override public ImmutableExport getD() { return d; } /** * Modifies persistend data of this Export. * @param newD new persistent data. * @param notify true to notify Undo system. * @return true if persistent data was modified. */ boolean setD(ImmutableExport newD, boolean notify) { checkChanging(); ImmutableExport oldD = d; if (newD == oldD) return false; if (parent != null) { parent.setContentsModified(); d = newD; if (notify) Constraints.getCurrent().modifyExport(this, oldD); } else { d = newD; } return true; } /** * Modifies persistent data of this Export. * @param newD new persistent data. */ void setDInUndo(ImmutableExport newD) { checkUndoing(); if (newD == d) return; d = newD; if (originalPort.getNodeInst().getD().nodeId != d.originalNodeId || originalPort.getPortProto().getId() != d.originalPortId) { originalPort = parent.getPortInst(d.originalNodeId, d.originalPortId); } } /** * Method to add a Variable on this Export. * It may add repaired copy of this Variable in some cases. * @param var Variable to add. */ public void addVar(Variable var) { setD(d.withVariable(var), true); } /** * Method to delete a Variable from this Export. * @param key the key of the Variable to delete. */ public void delVar(Variable.Key key) { setD(d.withoutVariable(key), true); } /** * Method to copy all variables from another Export to this Export. * @param other the other Export from which to copy Variables. */ public void copyVarsFrom(ElectricObject other) { super.copyVarsFrom(other); // delete the Bus parameterization in icons if (getParent().isIcon()) { for(Iterator<Variable> it = getVariables(); it.hasNext(); ) { Variable var = it.next(); if (var.getKey() == BusParameters.EXPORT_BUS_TEMPLATE) { delVar(var.getKey()); break; } } } } /** Method to return PortProtoId of this Export. * PortProtoId identifies Export independently of threads. * @return PortProtoId of this Export. */ public ExportId getId() { return d.exportId; } /** * Method to return the parent NodeProto of this Export. * @return the parent NodeProto of this Export. */ public Cell getParent() { return parent; } /** * Method to return chronological index of this Export in parent. * @return chronological index of this Export in parent. */ public int getChronIndex() { return d.exportId.chronIndex; } /** * Method to get the index of this Export. * This is a zero-based index of ports on the Cell. * @return the index of this Export. */ public int getPortIndex() { return portIndex; } /** * Returns the TextDescriptor on this Export selected by variable key. * This key may be a key of variable on this Export or * the special key <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 Export. */ public TextDescriptor getTextDescriptor(Variable.Key varKey) { if (varKey == EXPORT_NAME) return d.nameDescriptor; return super.getTextDescriptor(varKey); } /** * Updates the TextDescriptor on this Export selected by varName. * The varKey may be a key of variable on this ElectricObject or * the special key 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 name. * @param td new value TextDescriptor */ @Override public void setTextDescriptor(Variable.Key varKey, TextDescriptor td) { if (varKey == EXPORT_NAME) { setD(d.withNameDescriptor(td), true); return; } super.setTextDescriptor(varKey, td); } /** * Method to determine whether a variable key on Export 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 == EXPORT_NAME) return true; return super.isDeprecatedVariable(key); } /** * Method chooses TextDescriptor with "smart text placement" * of Export on specified origianl port. * @param originalPort original port for the Export * @return Immutable text descriptor with smart text placement */ private static TextDescriptor smartPlacement(PortInst originalPort) { // handle smart text placement relative to attached object int smartVertical = User.getSmartVerticalPlacementExport(); int smartHorizontal = User.getSmartHorizontalPlacementExport(); if (smartVertical == 0 && smartHorizontal == 0) return TextDescriptor.getExportTextDescriptor(); // figure out location of object relative to environment double dx = 0, dy = 0; NodeInst ni = originalPort.getNodeInst(); Rectangle2D nodeBounds = ni.getBounds(); for(Iterator<Connection> it = originalPort.getConnections(); it.hasNext(); ) { Connection con = it.next(); ArcInst ai = con.getArc(); Rectangle2D arcBounds = ai.getBounds(); dx = arcBounds.getCenterX() - nodeBounds.getCenterX(); dy = arcBounds.getCenterY() - nodeBounds.getCenterY(); } // first move placement horizontally if (smartHorizontal == 2) // place label outside (away from center) dx = -dx; else if (smartHorizontal != 1) // place label inside (towards center) dx = 0; // next move placement vertically if (smartVertical == 2) // place label outside (away from center) dy = -dy; else if (smartVertical != 1) // place label inside (towards center) dy = 0; TextDescriptor td = TextDescriptor.getExportTextDescriptor(); return td.withPos(td.getPos().align(Double.compare(dx, 0), Double.compare(dy, 0)));// MutableTextDescriptor td = MutableTextDescriptor.getExportTextDescriptor();// td.setPos(td.getPos().align(Double.compare(dx, 0), Double.compare(dy, 0)));// return ImmutableTextDescriptor.newTextDescriptor(td); } /** * Method to return the name key of this Export. * @return the Name key of this Export. */ public Name getNameKey() { return d.name; } /** * Method to return the name of this Export. * @return the name of this Export. */ public String getName() { return d.name.toString(); } /** * Method to return the short name of this PortProto. * The short name is everything up to the first nonalphabetic character. * @return the short name of this PortProto. */ public String getShortName() { return getShortName(getNameKey().toString()); } /** * Method to convert name of export to short name. * The short name is everything up to the first nonalphabetic character. * @param name long name * @return the short name of this PortProto. */ public static String getShortName(String name) { int len = name.length(); for(int i=0; i<len; i++) { char ch = name.charAt(i); if (TextUtils.isLetterOrDigit(ch)) continue; return name.substring(0, i); } return name; } /** * Repairs export name true if string is a valid Export name with cirtain width. * @param parent parent Cell * @param name string to test. * @return true if string is a valid Export name with cirtain width. */ private static String repairExportName(Cell parent, String name) { String newName = null; int oldBusWidth = Name.findName(name).busWidth(); if (!parent.busNamesAllowed()) oldBusWidth = 1; int openIndex = name.indexOf('['); if (openIndex >= 0) { int afterOpenIndex = openIndex + 1; while (afterOpenIndex < name.length() && name.charAt(afterOpenIndex) == '[') afterOpenIndex++; int closeIndex = name.lastIndexOf(']'); if (closeIndex < 0) { int lastOpenIndex = name.lastIndexOf('['); if (lastOpenIndex > afterOpenIndex) closeIndex = lastOpenIndex; } if (afterOpenIndex < closeIndex) newName = name.substring(0, openIndex) + name.substring(closeIndex + 1) + "[" + name.substring(afterOpenIndex, closeIndex) + "]"; } if (validExportName(newName, oldBusWidth)) { newName = ElectricObject.uniqueObjectName(newName, parent, PortProto.class, false); if (validExportName(newName, oldBusWidth)) return newName; } StringBuilder sb = new StringBuilder();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -