📄 arcinst.java
字号:
/** * Method to set the rotation angle of this ArcInst. * @param angle the rotation angle of this ArcInst (in tenth-degrees). * In general, you should not call this method because the * constructors and modification methods update this correctly. * If, however, you have a zero-length arc and want to explicitly set * its angle, then use this method. */ public void setAngle(int angle) { checkChanging(); ImmutableArcInst oldD = d; lowLevelModify(d.withAngle(angle)); if (parent != null) Constraints.getCurrent().modifyArcInst(this, oldD); } /** * Returns the polygons that describe this ArcInst. * @param polyBuilder Poly builder. * @return an iterator on Poly objects that describes this ArcInst graphically. * These Polys include displayable variables on the ArcInst. */ @Override public Iterator<Poly> getShape(Poly.Builder polyBuilder) { return polyBuilder.getShape(this); } /** * Method to return the bounds of this ArcInst. * TODO: dangerous to give a pointer to our internal field; should make a copy of visBounds * @return the bounds of this ArcInst. */ @Override public Rectangle2D getBounds() { if (topology.validArcBounds) return visBounds; topology.computeArcBounds(); return visBounds; } void computeBounds(BoundsBuilder b, int[] intCoords) { if (b.genBoundsEasy(d, intCoords)) { double x = intCoords[0]; double y = intCoords[1]; double w = intCoords[2] - x; double h = intCoords[3] - y; x = DBMath.gridToLambda(x); y = DBMath.gridToLambda(y); w = DBMath.gridToLambda(w); h = DBMath.gridToLambda(h); if (x == visBounds.getX() && y == visBounds.getY() && w == visBounds.getWidth() && h == visBounds.getHeight()) return; visBounds.setRect(x, y, w, h); parent.setDirty(); } else { b.clear(); b.genShapeOfArc(d); if (b.makeBounds(visBounds)) parent.setDirty(); } } /** * Method to recalculate the Geometric bounds for this NodeInst. */ public void redoGeometric() { if (parent != null) parent.setGeomDirty(); topology.validArcBounds = false; topology.unfreshRTree(); } /** * Method to create a Poly object that describes an ArcInst in lambda units. * The ArcInst is described by its width and style. * @param gridWidth the width of the Poly in grid units. * @param style the style of the ArcInst. * @return a Poly that describes the ArcInst in lambda units. */ public Poly makeLambdaPoly(long gridWidth, Poly.Type style) { Poly.Builder polyBuilder = Poly.threadLocalLambdaBuilder(); polyBuilder.setOnlyTheseLayers(null); polyBuilder.setup(parent); return polyBuilder.makePoly(getD(), gridWidth, style); }// /**// * Method to create a Poly object that describes an ArcInst in grid units.// * The ArcInst is described by its width and style.// * @param gridWidth the width of the Poly in grid units.// * @param style the style of the ArcInst.// * @return a Poly that describes the ArcInst in grid units.// */// public Poly makeGridPoly(long gridWidth, Poly.Type style) {// CellBackup.Memoization m = parent != null ? parent.getMemoization() : null;// return getD().makeGridPoly(m, gridWidth, style);// } /** * Method to fill polygon "poly" with the outline in lambda units of the curved arc in * this ArcInst whose width in grid units is "gridWidth". The style of the polygon is set to "style". * If there is no curvature information in the arc, the routine returns null, * otherwise it returns the curved polygon. */ public Poly curvedArcLambdaOutline(Poly.Type style, long gridWidth, long gridRadius) { Poly.Builder polyBuilder = Poly.threadLocalLambdaBuilder(); polyBuilder.setOnlyTheseLayers(null); polyBuilder.setup(parent); Variable radius = Variable.newInstance(ImmutableArcInst.ARC_RADIUS, new Double(DBMath.gridToLambda(gridRadius)), TextDescriptor.getArcTextDescriptor()); return polyBuilder.makePoly(getD().withVariable(radius), gridWidth, style); }// /**// * Method to return a list of Polys that describes all text on this ArcInst.// * @param hardToSelect is true if considering hard-to-select text.// * @param wnd the window in which the text will be drawn.// * @return an array of Polys that describes the text.// */// public Poly [] getAllText(boolean hardToSelect, EditWindow0 wnd)// {// int dispVars = numDisplayableVariables(false);// int totalText = dispVars;// if (totalText == 0) return null;// Poly [] polys = new Poly[totalText];// addDisplayableVariables(getBounds(), polys, 0, wnd, false);// return polys;// } /** * Method to return the number of displayable Variables on this ArcInst. * A displayable Variable is one that will be shown with its object. * @return the number of displayable Variables on this ArcInst. */ public int numDisplayableVariables(boolean multipleStrings) { return super.numDisplayableVariables(multipleStrings) + (isUsernamed()?1:0); } /** * Method to add all displayable Variables on this Electric object to an array of Poly objects. * @param rect a rectangle describing the bounds of the object 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. * @return the number of Variables that were added. */ public int addDisplayableVariables(Rectangle2D rect, Poly [] polys, int start, EditWindow0 wnd, boolean multipleStrings) { int numVars = 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(); 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, ARC_NAME)); numVars = 1; } return super.addDisplayableVariables(rect, polys, start+numVars, wnd, multipleStrings) + numVars; } /** * Method to get all displayable Variables on this ArcInst to an array of Poly objects. * @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(getBounds(), wnd, true); } /****************************** CONNECTIONS ******************************/ /** * Method to return the Connection on the tail end of this ArcInst. * @return the Connection on the tail end of this ArcInst. */ public TailConnection getTail() { return new TailConnection(this); } /** * Method to return the Connection on the head end of this ArcInst. * @return the Connection on the head end of this ArcInst. */ public HeadConnection getHead() { return new HeadConnection(this); } /** * Method to return the connection at an end of this ArcInst. * @param connIndex TAILEND (0) for the tail of this ArcInst, HEADEND (1) for the head. */ public Connection getConnection(int connIndex) { switch (connIndex) { case ImmutableArcInst.TAILEND: return new TailConnection(this); case ImmutableArcInst.HEADEND: return new HeadConnection(this); default: throw new IllegalArgumentException("Bad end " + connIndex); } } /** * Method to return the PortInst on tail of this ArcInst. * @return the PortInst on tail. */ public PortInst getTailPortInst() { return tailPortInst; } /** * Method to return the PortInst on head of this ArcInst. * @return the PortInst on head. */ public PortInst getHeadPortInst() { return headPortInst; } /** * Method to tell whether this ArcInst is connected directly to another * Geometric object (that is, an arcinst connected to a nodeinst). * The method returns true if they are connected. * @param geom other Geometric object. * @return true if this and other Geometric objects are connected. */ @Override public boolean isConnected(Geometric geom) { return tailPortInst.getNodeInst() == geom || headPortInst.getNodeInst() == geom; } /** * Method to return the PortInst on an end of this ArcInst. * @param connIndex TAILEND (0) for the tail of this ArcInst, HEADEND (1) for the head. * @return the PortInst at an end. */ public PortInst getPortInst(int connIndex) { switch (connIndex) { case ImmutableArcInst.TAILEND: return tailPortInst; case ImmutableArcInst.HEADEND: return headPortInst; default: throw new IllegalArgumentException("Bad end " + connIndex); } } /** * Method to return the Location on tail of this ArcInst. * @return the Location on tail. */ public EPoint getTailLocation() { return d.tailLocation; } /** * Method to return the Location on head of this ArcInst. * @return the Location on head. */ public EPoint getHeadLocation() { return d.headLocation; } /** * Method to return the Location on an end of this ArcInst. * @param connIndex TAILEND (0) for the tail of this ArcInst, HEADEND (1) for the head. * @return the Location on an end. */ public EPoint getLocation(int connIndex) { switch (connIndex) { case ImmutableArcInst.TAILEND: return d.tailLocation; case ImmutableArcInst.HEADEND: return d.headLocation; default: throw new IllegalArgumentException("Bad end " + connIndex); } } /** * Method to tell whether a tail connection on this ArcInst contains a port location. * @param pt the point in question. * @param reduceForArc if true reduce width by width offset of it proto. * @return true if the point is inside of the port. */ public boolean tailStillInPort(Point2D pt, boolean reduceForArc) { return stillInPort(ImmutableArcInst.TAILEND, pt, reduceForArc); } /** * Method to tell whether a head connection on this ArcInst contains a port location. * @param pt the point in question. * @param reduceForArc if true reduce width by width offset of it proto. * @return true if the point is inside of the port. */ public boolean headStillInPort(Point2D pt, boolean reduceForArc) { return stillInPort(ImmutableArcInst.HEADEND, pt, reduceForArc); } /** * Method to tell whether a connection on this ArcInst contains a port location. * @param connIndex TAILEND (0) for the tail of this ArcInst, HEADEND (1) for the head. * @param pt the point in question. * @param reduceForArc if true reduce width by width offset of it proto. * @return true if the point is inside of the port. */ public boolean stillInPort(int connIndex, Point2D pt, boolean reduceForArc) { // determine the area of the nodeinst PortInst pi = getPortInst(connIndex); Poly poly = pi.getPoly(); if (reduceForArc) { double wid = getLambdaBaseWidth(); poly.reducePortPoly(pi, wid, getAngle()); } return stillInPoly(pt, poly);// if (poly.isInside(pt)) return true;// if (poly.polyDistance(pt.getX(), pt.getY()) < MINPORTDISTANCE) return true;//// // no good// return false; } private static boolean stillInPoly(Point2D pt, Poly poly) { return poly.isInside(pt) || poly.polyDistance(pt.getX(), pt.getY()) < MINPORTDISTANCE; } /****************************** TEXT ******************************/ /** * Method to return the name of this ArcInst. * @return the name of this ArcInst. */ public String getName() { return d.name.toString(); } /** * Retruns true if this ArcInst was named by user. * @return true if this ArcInst was named by user. */ public boolean isUsernamed() { return d.isUsernamed(); } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -