📄 routeelementarc.java
字号:
if (head.getX() == tail.getX()) return true; return false; } /** * Return true if the new arc is a horizontal arc, false otherwise */ public boolean isArcHorizontal() { Point2D head = headConnPoint; Point2D tail = tailConnPoint; if (head == null) head = headRE.getLocation(); if (tail == null) tail = tailRE.getLocation(); if ((head == null) || (tail == null)) return false; if (head.getY() == tail.getY()) return true; return false; } /** * Used to update end points of new arc if they change * Only valid if called on newArcs, does nothing otherwise. * @return true if either (a) this arc does not use oldEnd, or * (b) this arc replaced oldEnd with newEnd, and no longer uses oldEnd at all. */ public boolean replaceArcEnd(RouteElementPort oldEnd, RouteElementPort newEnd) { if (getAction() == RouteElementAction.newArc) { Poly poly = newEnd.getConnectingSite(); if (headRE == oldEnd) { if (poly != null && poly.contains(headConnPoint)) { headRE = newEnd; // update book-keeping oldEnd.removeConnectingNewArc(this); newEnd.addConnectingNewArc(this); } } if (tailRE == oldEnd) { if (poly != null && poly.contains(tailConnPoint)) { tailRE = newEnd; // update book-keeping oldEnd.removeConnectingNewArc(this); newEnd.addConnectingNewArc(this); } } } if (headRE == oldEnd || tailRE == oldEnd) return false; return true; } /** * Perform the action specified by RouteElementAction <i>action</i>. * Note that this method performs database editing, and should only * be called from within a Job. * @return the object created, or null if deleted or nothing done. */ public ElectricObject doAction() { EDatabase.serverDatabase().checkChanging(); if (isDone()) return null; if (getAction() == RouteElementAction.newArc) { PortInst headPi = headRE.getPortInst(); PortInst tailPi = tailRE.getPortInst(); Point2D headPoint = headConnPoint; Point2D tailPoint = tailConnPoint; // special case when routing to expandable gate (and, or, mux, etc.) Poly headPoly = headPi.getPoly(); if (!headPoly.isInside(headPoint)) { NodeInst headNi = headPi.getNodeInst(); if (!headNi.isCellInstance()) { PrimitiveNode pNp = (PrimitiveNode)headNi.getProto(); Dimension2D autoGrowth = pNp.getAutoGrowth(); if (autoGrowth != null) { // grow the node to allow expandable port to fit headNi.resize(autoGrowth.getWidth(), autoGrowth.getHeight());// headNi.modifyInstance(0, 0, autoGrowth.getLambdaFullWidth(), autoGrowth.getHeight(), 0); } } } headPoly = headPi.getPoly(); if (!headPoly.isInside(headPoint)) { // can't connect Rectangle2D headBounds = headPi.getBounds(); System.out.println("Arc head (" + headPoint.getX() + "," + headPoint.getY() + ") not inside " + headPi + " which is "+ headBounds.getMinX() + "<=X<=" + headBounds.getMaxX() + " and " + headBounds.getMinY() + "<=Y<=" + headBounds.getMaxY()); System.out.println(" Arc ran from " + headPi.getNodeInst() + ", port " + headPi.getPortProto().getName() + " to " + tailPi.getNodeInst() + ", port " + tailPi.getPortProto().getName()); headPoly = headPi.getPoly(); return null; } Poly tailPoly = tailPi.getPoly(); if (!tailPoly.isInside(tailPoint)) { NodeInst tailNi = tailPi.getNodeInst(); if (!tailNi.isCellInstance()) { PrimitiveNode pNp = (PrimitiveNode)tailNi.getProto(); Dimension2D autoGrowth = pNp.getAutoGrowth(); if (autoGrowth != null) { // grow the node to allow expandable port to fit tailNi.resize(autoGrowth.getWidth(), autoGrowth.getHeight());// tailNi.modifyInstance(0, 0, autoGrowth.getLambdaFullWidth(), autoGrowth.getHeight(), 0); } } } tailPoly = tailPi.getPoly(); if (!tailPoly.isInside(tailPoint)) { // can't connect Rectangle2D tailBounds = tailPi.getBounds(); System.out.println("Arc tail (" + tailPoint.getX() + "," + tailPoint.getY() + ") not inside " + headPi + " which is "+ tailBounds.getMinX() + "<=X<=" + tailBounds.getMaxX() + " and " + tailBounds.getMinY() + "<=Y<=" + tailBounds.getMaxY()); System.out.println(" Arc ran from " + headPi.getNodeInst() + ", port " + headPi.getPortProto().getName() + " to " + tailPi.getNodeInst() + ", port " + tailPi.getPortProto().getName()); return null; } // now run the arc double thisWidth = arcBaseWidth; // The arc is zero length so better if arc width is min default width to avoid DRC errors if head/tail extended // The arc is zero length so better if arc width is zero to avoid DRC errors if head/tail is not extended if (headPoint.equals(tailPoint)) { if (extendArcHead || extendArcTail) thisWidth = arcProto.getDefaultLambdaBaseWidth(); // Sept 4 2008. Force to be a flat arc else thisWidth = 0; // Sept 4 2008. Force to be a single point } ArcInst newAi = ArcInst.makeInstanceBase(arcProto, thisWidth, headPi, tailPi, headPoint, tailPoint, arcName); if (newAi == null) return null; // for zero-length arcs, ensure that the angle is sensible if (headPoint.getX() == tailPoint.getX() && headPoint.getY() == tailPoint.getY() && arcAngle == 0) { Rectangle2D headRect = headPi.getNodeInst().getBounds(); Rectangle2D tailRect = tailPi.getNodeInst().getBounds(); if (Math.abs(headRect.getCenterX() - tailRect.getCenterX()) < Math.abs(headRect.getCenterY() - tailRect.getCenterY())) arcAngle = 900; } if (arcAngle != 0) newAi.setAngle(arcAngle); if ((arcName != null) && (arcNameDescriptor != null)) { newAi.setTextDescriptor(ArcInst.ARC_NAME, arcNameDescriptor); } setDone(); arcInst = newAi; arcInst.copyPropertiesFrom(inheritFrom); if (inheritFrom == null) { arcInst.setHeadExtended(extendArcHead); arcInst.setTailExtended(extendArcTail); } return newAi; } if (getAction() == RouteElementAction.deleteArc) { // delete existing arc if (arcInst.isLinked()) arcInst.kill(); setDone(); } return null; } /** * Adds RouteElement to highlights */ public void addHighlightArea(Highlighter highlighter) { if (!isShowHighlight()) return; if (getAction() == RouteElementAction.newArc) { // figure out highlight area based on arc width and start and end locations Point2D headPoint = headConnPoint; Point2D tailPoint = tailConnPoint; double offset = 0.5*getArcBaseWidth(); Cell cell = getCell(); // if they are the same point, the two nodes are in top of each other int angle = (headPoint.equals(tailPoint)) ? 0 : GenMath.figureAngle(tailPoint, headPoint); double length = headPoint.distance(tailPoint); Poly poly = Poly.makeEndPointPoly(length, getArcBaseWidth(), angle, headPoint, offset, tailPoint, offset, Poly.Type.FILLED); Point2D [] points = poly.getPoints(); for(int i=0; i<points.length; i++) { int last = i-1; if (last < 0) last = points.length - 1; highlighter.addLine(points[last], points[i], cell); } // double offsetX, offsetY;// boolean endsExtend = arcProto.isExtended();// double offsetEnds = endsExtend ? offset : 0;// Point2D head1, head2, tail1, tail2;// if (headPoint.getX() == tailPoint.getX()) {// // vertical arc// if (headPoint.getY() > tailPoint.getY()) {// offsetX = offset;// offsetY = offsetEnds;// } else {// offsetX = offset;// offsetY = -offsetEnds;// }// head1 = new Point2D.Double(headPoint.getX()+offsetX, headPoint.getY()+offsetY);// head2 = new Point2D.Double(headPoint.getX()-offsetX, headPoint.getY()+offsetY);// tail1 = new Point2D.Double(tailPoint.getX()+offsetX, tailPoint.getY()-offsetY);// tail2 = new Point2D.Double(tailPoint.getX()-offsetX, tailPoint.getY()-offsetY);// } else {// //assert(headPoint.getY() == tailPoint.getY());// if (headPoint.getX() > tailPoint.getX()) {// offsetX = offsetEnds;// offsetY = offset;// } else {// offsetX = -offsetEnds;// offsetY = offset;// }// head1 = new Point2D.Double(headPoint.getX()+offsetX, headPoint.getY()+offsetY);// head2 = new Point2D.Double(headPoint.getX()+offsetX, headPoint.getY()-offsetY);// tail1 = new Point2D.Double(tailPoint.getX()-offsetX, tailPoint.getY()+offsetY);// tail2 = new Point2D.Double(tailPoint.getX()-offsetX, tailPoint.getY()-offsetY);// }// highlighter.addLine(head1, tail1, cell);// //Highlight.addLine(headPoint, tailPoint, cell);// highlighter.addLine(head2, tail2, cell);// highlighter.addLine(head1, head2, cell);// highlighter.addLine(tail1, tail2, cell); } if (getAction() == RouteElementAction.deleteArc) { highlighter.addElectricObject(arcInst, getCell()); } } /** Return string decribing the RouteElement */ public String toString() { if (getAction() == RouteElementAction.newArc) { return "RouteElementArc-new "+arcProto+" width="+arcBaseWidth+",\n head: "+headRE+"\n tail: "+tailRE; } else if (getAction() == RouteElementAction.deleteArc) { return "RouteElementArc-delete "+arcInst; } return "RouteElement bad action"; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -