📄 electricobject.java
字号:
} poly = new Poly(pointList); poly.setStyle(style); if (geom instanceof NodeInst) { poly.transform(((NodeInst)geom).rotateOutAboutTrueCenter()); } poly.setTextDescriptor(td); if (varKey == NodeInst.NODE_NAME) poly.setString(((NodeInst)geom).getName()); else poly.setString(((ArcInst)geom).getName()); } else if (varKey == NodeInst.NODE_PROTO) { if (!(geom instanceof NodeInst)) return null; NodeInst ni = (NodeInst)this; TextDescriptor td = ni.getTextDescriptor(NodeInst.NODE_PROTO); Poly.Type style = td.getPos().getPolyType(); Point2D [] pointList = null; if (style == Poly.Type.TEXTBOX) { pointList = Poly.makePoints(ni.getBounds()); } else { pointList = new Point2D.Double[1]; pointList[0] = new Point2D.Double(ni.getTrueCenterX()+td.getXOff(), ni.getTrueCenterY()+td.getYOff()); } poly = new Poly(pointList); poly.setStyle(style); poly.setTextDescriptor(td); poly.setString(ni.getProto().describe(false)); } else { double x = geom.getTrueCenterX(); double y = geom.getTrueCenterY(); if (geom instanceof NodeInst) { NodeInst ni = (NodeInst)geom; Rectangle2D uBounds = ni.getUntransformedBounds(); x = uBounds.getCenterX(); y = uBounds.getCenterY(); } Poly [] polys = geom.getPolyList(geom.getParameterOrVariable(varKey), x, y, wnd, false); if (polys.length > 0) { poly = polys[0]; if (geom instanceof NodeInst) { NodeInst ni = (NodeInst)geom; poly.transform(ni.rotateOut()); } } } } else if (this instanceof Cell) { Cell cell = (Cell)this; Poly [] polys = cell.getPolyList(cell.getParameterOrVariable(varKey), 0, 0, wnd, false); if (polys.length > 0) poly = polys[0]; } } if (poly != null) poly.setExactTextBounds(wnd, this); return poly; } /** * Method to return the bounds of this ElectricObject in an EditWindow. * @param wnd the EditWindow0 in which the object is being displayed. * @return the bounds of the text (does not include the bounds of the object). */ public Rectangle2D getTextBounds(EditWindow0 wnd) { Rectangle2D bounds = null; for(Iterator<Variable> vIt = getParametersAndVariables(); vIt.hasNext(); ) { Variable var = vIt.next(); if (!var.isDisplay()) continue; Poly poly = computeTextPoly(wnd, var.getKey()); if (poly == null) continue; Rectangle2D polyBound = poly.getBounds2D(); if (bounds == null) bounds = polyBound; else Rectangle2D.union(bounds, polyBound, bounds); } if (this instanceof ArcInst) { ArcInst ai = (ArcInst)this; Name name = ai.getNameKey(); if (!name.isTempname()) { Poly poly = computeTextPoly(wnd, ArcInst.ARC_NAME); if (poly != null) { Rectangle2D polyBound = poly.getBounds2D(); if (bounds == null) bounds = polyBound; else Rectangle2D.union(bounds, polyBound, bounds); } } } if (this instanceof NodeInst) { NodeInst ni = (NodeInst)this; Name name = ni.getNameKey(); if (!name.isTempname()) { Poly poly = computeTextPoly(wnd, NodeInst.NODE_NAME); if (poly != null) { Rectangle2D polyBound = poly.getBounds2D(); if (bounds == null) bounds = polyBound; else Rectangle2D.union(bounds, polyBound, bounds); } } for(Iterator<Export> it = ni.getExports(); it.hasNext(); ) { Export pp = it.next(); Poly poly = pp.computeTextPoly(wnd, Export.EXPORT_NAME); if (poly != null) { Rectangle2D polyBound = poly.getBounds2D(); if (bounds == null) bounds = polyBound; else Rectangle2D.union(bounds, polyBound, bounds); } } } return bounds; } /** * Method to create an array of Poly objects that describes a displayable Variable on this Electric object. * @param var the Variable on this ElectricObject to describe. * @param cX the center X coordinate of the ElectricObject. * @param cY the center Y coordinate of the ElectricObject. * @param wnd window in which the Variable will be displayed. * @param multipleStrings true to break multiline text into multiple Polys. * @return an array of Poly objects that describe the Variable. May return zero length array. */ public Poly [] getPolyList(Variable var, double cX, double cY, EditWindow0 wnd, boolean multipleStrings) { if (var == null) return new Poly[0]; double offX = var.getXOff(); double offY = var.getYOff(); int varLength = var.getLength(); double lineOffX = 0, lineOffY = 0; AffineTransform trans = null; Poly.Type style = var.getPos().getPolyType(); TextDescriptor td = var.getTextDescriptor(); if (this instanceof NodeInst && (offX != 0 || offY != 0)) { td = td.withOff(0, 0); } boolean headerString = false; double fontHeight = 1; double scale = 1; if (wnd != null) { fontHeight = td.getTrueSize(wnd); scale = wnd.getScale(); fontHeight *= wnd.getGlobalTextScale(); } if (varLength > 1) { // compute text height double lineDist = fontHeight / scale; int rotQuadrant = td.getRotation().getIndex(); switch (rotQuadrant) { case 0: lineOffY = lineDist; break; // 0 degrees rotation case 1: lineOffX = -lineDist; break; // 90 degrees rotation case 2: lineOffY = -lineDist; break; // 180 degrees rotation case 3: lineOffX = lineDist; break; // 270 degrees rotation } // multiline text on rotated nodes must compensate for node rotation Poly.Type rotStyle = style; if (this instanceof NodeInst) { NodeInst ni = (NodeInst)this; if (style != Poly.Type.TEXTCENT && style != Poly.Type.TEXTBOX) { trans = ni.rotateIn(); int origAngle = style.getTextAngle(); if (ni.isMirroredAboutXAxis() != ni.isMirroredAboutYAxis() && ((origAngle%1800) == 0 || (origAngle%1800) == 1350)) origAngle += 1800; int angle = (origAngle - ni.getAngle() + 3600) % 3600; style = Poly.Type.getTextTypeFromAngle(angle); } } if (td.getDispPart() == TextDescriptor.DispPos.NAMEVALUE) { headerString = true; varLength++; } if (multipleStrings) { if (rotStyle == Poly.Type.TEXTCENT || rotStyle == Poly.Type.TEXTBOX || rotStyle == Poly.Type.TEXTLEFT || rotStyle == Poly.Type.TEXTRIGHT) { cX += lineOffX * (varLength-1) / 2; cY += lineOffY * (varLength-1) / 2; } if (rotStyle == Poly.Type.TEXTBOT || rotStyle == Poly.Type.TEXTBOTLEFT || rotStyle == Poly.Type.TEXTBOTRIGHT) { cX += lineOffX * (varLength-1); cY += lineOffY * (varLength-1); } } else { if (rotStyle == Poly.Type.TEXTCENT || rotStyle == Poly.Type.TEXTBOX || rotStyle == Poly.Type.TEXTLEFT || rotStyle == Poly.Type.TEXTRIGHT) { cX -= lineOffX * (varLength-1) / 2; cY -= lineOffY * (varLength-1) / 2; } if (rotStyle == Poly.Type.TEXTTOP || rotStyle == Poly.Type.TEXTTOPLEFT || rotStyle == Poly.Type.TEXTTOPRIGHT) { cX -= lineOffX * (varLength-1); cY -= lineOffY * (varLength-1); } varLength = 1; headerString = false; } } VarContext context = null; if (wnd != null) context = wnd.getVarContext(); Poly [] polys = new Poly[varLength]; for(int i=0; i<varLength; i++) { String message = null; TextDescriptor entryTD = td; if (varLength > 1 && headerString) { if (i == 0) { message = var.getTrueName()+ "[" + (varLength-1) + "]:"; entryTD = entryTD.withUnderline(true); } else { message = var.describe(i-1, context, this); } } else { message = var.describe(i, context, this); } Point2D [] pointList = null; if (style == Poly.Type.TEXTBOX && this instanceof Geometric) { Geometric geom = (Geometric)this; Rectangle2D bounds = geom.getBounds(); pointList = Poly.makePoints(bounds); } else { pointList = new Point2D.Double[1]; pointList[0] = new Point2D.Double(cX+offX, cY+offY); if (trans != null) trans.transform(pointList[0], pointList[0]); } polys[i] = new Poly(pointList); polys[i].setString(message); polys[i].setStyle(style); polys[i].setTextDescriptor(entryTD); polys[i].setDisplayedText(new DisplayedText(this, var.getKey())); polys[i].setLayer(null); cX -= lineOffX; cY -= lineOffY; } return polys; } /** * Method to create a non-displayable Variable on this ElectricObject with the specified values. * @param name the name of the Variable. * @param value the object to store in the Variable. * @return the Variable that has been created. */ public Variable newVar(String name, Object value) { return newVar(Variable.newKey(name, this), value); } /** * Method to create a displayable Variable on this ElectricObject with the specified values. * @param key the key of the Variable. * @param value the object to store in the Variable. * @return the Variable that has been created. */ public Variable newDisplayVar(Variable.Key key, Object value) { return newVar(key, value, true); } /** * Method to create a non-displayable Variable on this ElectricObject with the specified values. * Notify to observers as well. * @param key the key of the Variable. * @param value the object to store in the Variable. * @return the Variable that has been created. */ public Variable newVar(Variable.Key key, Object value) { return newVar(key, value, false); } /** * Method to create a Variable on this ElectricObject with the specified values. * @param key the key of the Variable. * @param value the object to store in the Variable. * @param display true if the Variale is displayable. * @return the Variable that has been created. */ public Variable newVar(Variable.Key key, Object value, boolean display) { TextDescriptor td = null; if (this instanceof Cell) td = TextDescriptor.cacheCellDescriptor.newTextDescriptor(display); else if (this instanceof Export) td = TextDescriptor.cacheExportDescriptor.newTextDescriptor(display); else if (this instanceof NodeInst) td = TextDescriptor.cacheNodeDescriptor.newTextDescriptor(display); else if (this instanceof ArcInst) td = TextDescriptor.cacheArcDescriptor.newTextDescriptor(display); else td = TextDescriptor.cacheAnnotationDescriptor.newTextDescriptor(display); return newVar(key, value, td); } /** * Method to create a Variable on this ElectricObject with the specified values. * @param key the key of the Variable. * @param value the object to store in the Variable. * @param td text descriptor of the Variable * @return the Variable that has been created. */ public Variable newVar(Variable.Key key, Object value, TextDescriptor td) { if (value == null) return null; if (isDeprecatedVariable(key)) { System.out.println("Deprecated variable " + key + " on " + this); } Variable var = null; try { var = Variable.newInstance(key, value, td); } catch (IllegalArgumentException e) { ActivityLogger.logException(e); return null; } addVar(var); return getVar(key);// setChanged();// notifyObservers(v);// clearChanged(); } /** * Method to add a Variable on this ElectricObject. * It may add a repaired copy of this Variable in some cases. * @param var Variable to add. */ public abstract void addVar(Variable var); /** * Method to update a Variable on this ElectricObject 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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -