📄 nodeinst.java
字号:
{ System.out.println("No port on new node has same name and location as old node port: " + pp.getOriginalPort().getPortProto().getName()); newNi.kill(); return null; } PortInst opi = oldAssoc[index].assn; // ensure that all arcs connected at exports still connect if (pp.doesntConnect(opi.getPortProto().getBasePort())) { newNi.kill(); return null; } } // now replace all of the arcs Set<ArcInst> arcList = new HashSet<ArcInst>(); for(Iterator<Connection> it = getConnections(); it.hasNext(); ) arcList.add(it.next().getArc()); for(ArcInst ai : arcList) { PortInst [] newPortInst = new PortInst[2]; Point2D [] newPoint = new Point2D[2]; int otherEnd = 0; for(int e=0; e<2; e++) { PortInst pi = ai.getPortInst(e); if (pi.getNodeInst() != this) { // end of arc connected elsewhere: keep the information newPortInst[e] = pi; newPoint[e] = ai.getLocation(e); otherEnd = e; } else { // end of arc connected to replaced node: translate to new node int index = 0; for( ; index<oldAssoc.length; index++) if (oldAssoc[index].portInst == pi) break; if (index >= oldAssoc.length || oldAssoc[index].assn == null) { if (allowMissingPorts) continue; System.out.println("No port on new node has same name and location as old node port: " + pi.getPortProto().getName()); newNi.kill(); return null; } // make sure the arc can connect to this type of port PortInst opi = oldAssoc[index].assn; if (opi == null) { if (!allowMissingPorts) System.out.println("Cannot re-connect " + ai); else { ai.kill(); } continue; } newPortInst[e] = opi; Poly poly = opi.getPoly(); EPoint newLoc = ai.getLocation(e); newPoint[e] = poly.isInside(newLoc) ? newLoc : new EPoint(poly.getCenterX(), poly.getCenterY()); } } if (newPortInst[ArcInst.TAILEND] == null || newPortInst[ArcInst.HEADEND] == null) continue; // see if a bend must be made in the wire boolean zigzag = false; if (ai.isFixedAngle()) { if (newPoint[0].getX() != newPoint[1].getX() || newPoint[0].getY() != newPoint[1].getY()) { int ii = DBMath.figureAngle(newPoint[0], newPoint[1]); int ang = ai.getAngle(); if ((ii%1800) != (ang%1800)) zigzag = true; } } // see if a bend can be a straight by some simple manipulations if (zigzag && !ai.isRigid() && (ai.getAngle() % 900) == 0) { // find the node at the other end NodeInst adjustThisNode = ai.getPortInst(otherEnd).getNodeInst(); if (!adjustThisNode.hasExports()) { // other end not exported, see if all arcs can be adjusted boolean adjustable = true; for(Iterator<Connection> oIt = adjustThisNode.getConnections(); oIt.hasNext(); ) { Connection otherCon = oIt.next(); ArcInst otherArc = otherCon.getArc(); if (otherArc == ai) continue; if (otherArc.isRigid()) { adjustable = false; break; } if (otherArc.getAngle() % 900 != 0) { adjustable = false; break; } if (((ai.getAngle() / 900) & 1) == ((otherArc.getAngle() / 900) & 1)) { adjustable = false; break; } } if (adjustable) { double dX = 0, dY = 0; if ((ai.getAngle() % 1800) == 0) { // horizontal arc: move the other node vertically dY = newPoint[1-otherEnd].getY() - newPoint[otherEnd].getY(); newPoint[otherEnd] = new Point2D.Double(newPoint[otherEnd].getX(), newPoint[1-otherEnd].getY()); } else { // vertical arc: move the other node horizontaly dX = newPoint[1-otherEnd].getX() - newPoint[otherEnd].getX(); newPoint[otherEnd] = new Point2D.Double(newPoint[1-otherEnd].getX(), newPoint[otherEnd].getY()); } // special case where the old arc must be deleted first so that the other node can move ai.kill(); adjustThisNode.move(dX, dY); ArcInst newAi = ArcInst.newInstanceBase(ai.getProto(), ai.getLambdaBaseWidth(), newPortInst[ArcInst.HEADEND], newPortInst[ArcInst.TAILEND], newPoint[ArcInst.HEADEND], newPoint[ArcInst.TAILEND], ai.getName(), 0); if (newAi == null) { newNi.kill(); return null; } newAi.copyPropertiesFrom(ai); continue; } } } ArcInst newAi; if (zigzag) { // make that two wires double cX = newPoint[0].getX(); double cY = newPoint[1].getY(); NodeProto pinNp = ai.getProto().findOverridablePinProto(); double psx = pinNp.getDefWidth(); double psy = pinNp.getDefHeight(); NodeInst pinNi = NodeInst.newInstance(pinNp, new Point2D.Double(cX, cY), psx, psy, getParent()); PortInst pinPi = pinNi.getOnlyPortInst(); newAi = ArcInst.newInstanceBase(ai.getProto(), ai.getLambdaBaseWidth(), newPortInst[ArcInst.HEADEND], pinPi, newPoint[ArcInst.HEADEND], new Point2D.Double(cX, cY), null, 0); if (newAi == null) return null; newAi.copyPropertiesFrom(ai); ArcInst newAi2 = ArcInst.newInstanceBase(ai.getProto(), ai.getLambdaBaseWidth(), pinPi, newPortInst[ArcInst.TAILEND], new Point2D.Double(cX, cY), newPoint[ArcInst.TAILEND], null, 0); if (newAi2 == null) return null; newAi2.copyConstraintsFrom(ai); if (newPortInst[ArcInst.TAILEND].getNodeInst() == this) { ArcInst aiSwap = newAi; newAi = newAi2; newAi2 = aiSwap; } } else { // replace the arc with another arc newAi = ArcInst.newInstanceBase(ai.getProto(), ai.getLambdaBaseWidth(), newPortInst[ArcInst.HEADEND], newPortInst[ArcInst.TAILEND], newPoint[ArcInst.HEADEND], newPoint[ArcInst.TAILEND], null, 0); if (newAi == null) { newNi.kill(); return null; } newAi.copyPropertiesFrom(ai); } ai.kill(); newAi.setName(ai.getName()); } // now replace all of the exports List<Export> exportList = new ArrayList<Export>(); for(Iterator<Export> it = getExports(); it.hasNext(); ) { exportList.add(it.next()); } for(Export pp : exportList) { int index = 0; for( ; index<oldAssoc.length; index++) if (oldAssoc[index].portInst == pp.getOriginalPort()) break; if (index >= oldAssoc.length || oldAssoc[index].assn == null) continue; PortInst newPi = oldAssoc[index].assn; pp.move(newPi); } // copy all variables on the nodeinst newNi.copyVarsFrom(this); newNi.copyTextDescriptorFrom(this, NodeInst.NODE_NAME); newNi.copyTextDescriptorFrom(this, NodeInst.NODE_PROTO); newNi.copyStateBits(this); if (!getNameKey().isTempname()) { String savedName = getName(); String tempName = ElectricObject.uniqueObjectName(savedName, parent, NodeInst.class, true); setName(tempName); newNi.setName(savedName); } // now delete the original nodeinst kill(); return newNi; } /****************************** LOW-LEVEL IMPLEMENTATION ******************************/ /** * Returns persistent data of this NodeInst. * @return persistent data of this NodeInst. */ @Override public ImmutableNodeInst getD() { return d; } /** * Modifies persistend data of this NodeInst. * @param newD new persistent data. * @param notify true to notify Undo system. * @return true if persistent data was modified. */ public boolean setD(ImmutableNodeInst newD, boolean notify) { checkChanging(); ImmutableNodeInst oldD = d; if (newD == oldD) return false; if (parent != null) { parent.setContentsModified(); d = newD; if (notify) Constraints.getCurrent().modifyNodeInst(this, oldD); } else { d = newD; } return true; } public void setDInUndo(ImmutableNodeInst newD) { checkUndoing(); d = newD; validVisBounds = false; } /** * Method to add a Variable on this NodeInst. * It may add repaired copy of this Variable in some cases. * This methood is overriden in IconNodeInst * @param var Variable to add. */ public void addVar(Variable var) { if (setD(d.withVariable(var), true)) // check for side-effects of the change checkPossibleVariableEffects(var.getKey()); } /** * Package-private method to add a Variable on PortInst of this NodeInst. * It may add repaired copy of this Variable in some cases. * @param portProtoId PortProtoId of the PortInst. * @param var Variable to add. */ void addVar(PortProtoId portProtoId, Variable var) { setD(d.withPortInst(portProtoId, d.getPortInst(portProtoId).withVariable(var)), true); } /** * Method to delete a Variable from this NodeInst. * @param key the key of the Variable to delete. */ public void delVar(Variable.Key key) { if (setD(d.withoutVariable(key), true)) // check for side-effects of the change checkPossibleVariableEffects(key); } /** * Package-private method to delete a Variable from PortInst of this NodeInst. * @param portProtoId PortProtoId of the PortInst. * @param key the key of the Variable to delete. */ void delVar(PortProtoId portProtoId, Variable.Key key) { setD(d.withPortInst(portProtoId, d.getPortInst(portProtoId).withoutVariable(key)), true); } /** * Package-private method to delete all Variables from PortInst of this NodeInst. * @param portProtoId PortProtoId of the PortInst. */ void delVars(PortProtoId portProtoId) { setD(d.withPortInst(portProtoId, ImmutablePortInst.EMPTY), true); } /** * Method to adjust this NodeInst by the specified deltas. * This method does not go through change control, and so should not be used unless you know what you are doing. * New persistent data may differ from old one only by anchor, size and orientation * @param d the new persistent data of this NodeInst. */ public void lowLevelModify(ImmutableNodeInst d) { if (parent != null) { checkChanging(); boolean renamed = this.d.name != d.name; if (renamed) parent.removeNodeName(this); // make the change setD(d, false); if (renamed) parent.addNodeName(this); // fill in the Geometric fields redoGeometric(); } else { this.d = d; redoGeometric(); } } /** * Method to tell whether this NodeInst is an icon of its parent. * Electric does not allow recursive circuit hierarchies (instances of Cells inside of themselves). * However, it does allow one exception: a schematic may contain its own icon for documentation purposes. * This method determines whether this NodeInst is such an icon. * @return true if this NodeInst is an icon of its parent. */ public boolean isIconOfParent() { return (protoType instanceof Cell) && ((Cell)protoType).isIconOf(parent); } /** * Method to set an index of this NodeInst in Cell nodes. * This is a zero-based index of nodes on the Cell. * @param nodeIndex an index of this NodeInst in Cell nodes. */ public void setNodeIndex(int nodeIndex) { this.nodeIndex = nodeIndex; } /** * Method to get the index of this NodeInst. * This is a zero-based index of nodes on the Cell. * @return the index of this NodeInst. */ public final int getNodeIndex() { return nodeIndex; } /** * Method tells if this NodeInst is linked to parent Cell. * @return true if this NodeInst is linked to parent Cell. */ public boolean isLinked() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -