📄 nodeinst.java
字号:
// double offX = td.getXOff();// double offY = td.getYOff();// TextDescriptor.Position pos = td.getPos();// Poly.Type style = pos.getPolyType();// Point2D [] pointList = new Point2D.Double[1];// pointList[0] = new Point2D.Double(cX+offX, cY+offY);// polys[start] = new Poly(pointList);// polys[start].setStyle(style);// polys[start].setString(getProto().describe(false));// polys[start].setTextDescriptor(td);// polys[start].setDisplayedText(new DisplayedText(this, NODE_PROTO));// start++;// }//// // add in the exports// if (numExports > 0)// {// AffineTransform unTrans = rotateIn();// for(Iterator<Export> it = getExports(); it.hasNext(); )// {// Export pp = it.next();// polys[start] = pp.getNamePoly();// polys[start].transform(unTrans);// start++;//// // add in variables on the exports// Poly poly = pp.getOriginalPort().getPoly();// int numadded = pp.addDisplayableVariables(poly.getBounds2D(), polys, start, wnd, false);// for(int i=0; i<numadded; i++)// {// polys[start+i].setPort(pp);// polys[start+i].transform(unTrans);// }// start += numadded;// }// }//// // add in the displayable variables// if (dispVars > 0)// {// addDisplayableVariables(getUntransformedBounds(), polys, start, wnd, false);// }// return polys;// } /** * Method to return the bounds of this NodeInst before it is transformed. * @return the bounds of this NodeInst before it is transformed. */ public Rectangle2D getUntransformedBounds() { long lx, hx, ly, hy; if (protoType instanceof PrimitiveNode) { // primitive ERectangle baseRect = getBaseRectangle(); long halfW = d.size.getGridX() >> 1; long halfH = d.size.getGridY() >> 1; lx = -halfW + baseRect.getGridMinX(); hx = +halfW + baseRect.getGridMaxX(); ly = -halfH + baseRect.getGridMinY(); hy = +halfH + baseRect.getGridMaxY(); } else { ERectangle bounds = ((Cell)protoType).getBounds(); lx = bounds.getGridMinX(); hx = bounds.getGridMaxX(); ly = bounds.getGridMinY(); hy = bounds.getGridMaxY(); } EPoint anchor = getAnchorCenter(); return ERectangle.fromGrid(lx + anchor.getGridX(), ly + anchor.getGridY(), hx - lx, hy - ly); } /** * Method to return the Parameter on this NodeInst with the given key. * Overridden in IconNodeInst. * @param key the key of the Parameter * @return null */ public Variable getParameter(Variable.Key key) { return null; } /** * Method to tell if the Variable.Key is a defined parameters of this NodeInst. * Overridden in IconNodeInst. * @param key the key of the parameter * @return false */ public boolean isDefinedParameter(Variable.Key key) { return false; } /** * Method to return an Iterator over all Parameters on this NodeInst. * Overridden in IconNodeInst * @return an empty Iterator */ public Iterator<Variable> getParameters() { return ArrayIterator.emptyIterator(); } /** * Method to return an Iterator over defined Parameters on this Nodable. * Overridden in IconNodeInst * @return an empty Iterator */ public Iterator<Variable> getDefinedParameters() { return ArrayIterator.emptyIterator(); } /** * Method to add a Parameter to this NodeInst. * Overridden in IconNodeInst * @param param the Variable to add. */ public void addParameter(Variable param) { } /** * Method to delete a defined Parameter from this NodeInst. * Overridden in IconNodeInst * @param key the key of the Variable to delete. */ public void delParameter(Variable.Key key) { } /** * Method to update a Parameter on this NodeInst with the specified values. * If the Variable already exists, only the value is changed; the displayable attributes are preserved. * @param key the key of the Variable. * @param value the object to store in the Variable. * @return the Variable that has been updated. */ public Variable updateParam(Variable.Key key, Object value) { return null; } /** * Method to return the number of displayable Variables on this NodeInst and all of its PortInsts. * A displayable Variable is one that will be shown with its object. * Displayable Variables can only sensibly exist on NodeInst, ArcInst, and PortInst objects. * @return the number of displayable Variables on this NodeInst and all of its PortInsts. */ public int numDisplayableVariables(boolean multipleStrings) { int numVarsOnNode = super.numDisplayableVariables(multipleStrings); if (isUsernamed()) numVarsOnNode++; for(Iterator<PortInst> it = getPortInsts(); it.hasNext(); ) { PortInst pi = it.next(); numVarsOnNode += pi.numDisplayableVariables(multipleStrings); } return numVarsOnNode; } /** * Method to add all displayable Variables on this NodeInst and its PortInsts to an array of Poly objects. * @param rect a rectangle describing the bounds of the NodeInst on which the Variables will be displayed. * @param polys an array of Poly objects that will be filled with the displayable Variables. * @param start the starting index in the array of Poly objects to fill with displayable Variables. * @param wnd window in which the Variables will be displayed. * @param multipleStrings true to break multiline text into multiple Polys. * @return the number of Polys that were added. */ public int addDisplayableVariables(Rectangle2D rect, Poly [] polys, int start, EditWindow0 wnd, boolean multipleStrings) { int numAddedVariables = 0; if (isUsernamed()) { double cX = rect.getCenterX(); double cY = rect.getCenterY(); TextDescriptor td = d.nameDescriptor; double offX = td.getXOff(); double offY = td.getYOff(); TextDescriptor.Position pos = td.getPos(); Poly.Type style = pos.getPolyType(); if (offX != 0 || offY != 0) { td = td.withOff(0, 0); style = Poly.rotateType(style, this); } Point2D [] pointList = null; if (style == Poly.Type.TEXTBOX) { pointList = Poly.makePoints(rect); } else { pointList = new Point2D.Double[1]; pointList[0] = new Point2D.Double(cX+offX, cY+offY); } polys[start] = new Poly(pointList); polys[start].setStyle(style); polys[start].setString(getNameKey().toString()); polys[start].setTextDescriptor(td); polys[start].setLayer(null); polys[start].setDisplayedText(new DisplayedText(this, NODE_NAME)); numAddedVariables = 1; } numAddedVariables += super.addDisplayableVariables(rect, polys, start + numAddedVariables, wnd, multipleStrings); for(Iterator<PortInst> it = getPortInsts(); it.hasNext(); ) { PortInst pi = it.next(); int justAdded = pi.addDisplayableVariables(rect, polys, start+numAddedVariables, wnd, multipleStrings); for(int i=0; i<justAdded; i++) polys[start+numAddedVariables+i].setPort(pi.getPortProto()); numAddedVariables += justAdded; } return numAddedVariables; } /** * Method to get all displayable Variables on this NodeInst and its PortInsts to an array of Poly objects. * This Poly were not transformed by Node transform. * @param wnd window in which the Variables will be displayed. * @return an array of Poly objects with displayable variables. */ public Poly[] getDisplayableVariables(EditWindow0 wnd) { return getDisplayableVariables(getUntransformedBounds(), wnd, true); } /** * Method to return a transformation that moves up the hierarchy. * Presuming that this NodeInst is a Cell instance, the * transformation maps points in the Cell's coordinate space * into this NodeInst's parent Cell's coordinate space. * @return a transformation that moves up the hierarchy. */ public AffineTransform transformOut() { return d.orient.rotateAbout(getAnchorCenterX(), getAnchorCenterY(), 0, 0);// // The transform first translates to the position of the// // NodeInst's Anchor point in the parent Cell, and then rotates and// // mirrors about the anchor point.// AffineTransform xform = rotateOut();// xform.concatenate(translateOut());// return xform; } /** * Method to return a transformation that moves up the * hierarchy, combined with a previous transformation. * Presuming that this NodeInst is a Cell instance, the * transformation maps points in the Cell's coordinate space * into this NodeInst's parent Cell's coordinate space. * @param prevTransform the previous transformation to the NodeInst's Cell. * @return a transformation that translates up the hierarchy, * including the previous transformation. */ public AffineTransform transformOut(AffineTransform prevTransform) { AffineTransform transform = transformOut(); transform.preConcatenate(prevTransform); return transform; } /** * Method to return a transformation that moves down the hierarchy. * Presuming that this NodeInst is a Cell instance, the * transformation maps points in the Cell's coordinate space * into this NodeInst's parent Cell's coordinate space. * @return a transformation that moves down the hierarchy. */ public AffineTransform transformIn() { return d.orient.inverse().rotateAbout(0, 0, -getAnchorCenterX(), -getAnchorCenterY());// // The transform first rotates in, and then translates to the position..// AffineTransform xform = rotateIn();// xform.preConcatenate(translateIn());// return xform; } /** * Method to return a transformation that moves down the hierarchy. * Presuming that this NodeInst is a Cell instance, the * transformation maps points in the Cell's coordinate space * into this NodeInst's parent Cell's coordinate space. * @param prevTransform * @return a transformation that moves down the hierarchy, including the previous down transformation */ public AffineTransform transformIn(AffineTransform prevTransform) { AffineTransform transform = transformIn(); transform.concatenate(prevTransform); return transform; } /** * Method to return a transformation that translates down the hierarchy. * Transform out of this node instance, translate outer coordinates to inner * However, it does not account for the rotation of this NodeInst...it only * translates from one space to another. * @return a transformation that translates down the hierarchy. */ public AffineTransform translateIn() { // to transform out of this node instance, translate outer coordinates to inner //Cell lowerCell = (Cell)protoType; double dx = getAnchorCenterX(); double dy = getAnchorCenterY(); AffineTransform transform = new AffineTransform(); transform.translate(-dx, -dy); return transform; } /** * Method to return a transformation that translates down the * hierarchy, combined with a previous transformation. * However, it does not account for the rotation of * this NodeInst...it only translates from one space to another. * @param prevTransform the previous transformation to the NodeInst's Cell. * @return a transformation that translates down the hierarchy, * including the previous transformation. */ public AffineTransform translateIn(AffineTransform prevTransform) { AffineTransform transform = translateIn(); AffineTransform returnTransform = new AffineTransform(prevTransform); returnTransform.concatenate(transform); return returnTransform; } /** * Method to return a transformation that translates up the hierarchy. * Transform out of this node instance, translate inner coordinates to outer. * However, it does not account for the rotation of this NodeInst...it only * translates from one space to another. * @return a transformation that translates up the hierarchy. */ public AffineTransform translateOut() { // to transform out of this node instance, translate inner coordinates to outer //Cell lowerCell = (Cell)protoType; double dx = getAnchorCenterX(); double dy = getAnchorCenterY(); AffineTransform transform = new AffineTransform(); transform.translate(dx, dy); return transform; } /** * Method to return a transformation that translates up the * hierarchy, combined with a previous transformation. Presuming * that this NodeInst is a Cell instance, the transformation goes * from the space o
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -