📄 artwork.java
字号:
int pts = (int)(endangle * ELLIPSEPOINTS / (Math.PI * 2.0)); if (pts < 3) pts = 3; if (closed) pts++; Point2D [] points = new Point2D.Double[pts]; // compute the length of the semi-major and semi-minor axes double a = sX / 2; double b = sY / 2; if (closed) { // more efficient algorithm used for full ellipse drawing double p = 2.0 * Math.PI / (ELLIPSEPOINTS-1); double c2 = Math.cos(p); double s2 = Math.sin(p); double c3 = 1.0; double s3 = 0.0; for(int m=0; m<ELLIPSEPOINTS; m++) { points[m] = new Point2D.Double(center.getX() + a * c3, center.getY() + b * s3); double t1 = c3*c2 - s3*s2; s3 = s3*c2 + c3*s2; c3 = t1; } } else { // less efficient algorithm for partial ellipse drawing for(int m=0; m<pts; m++) { double p = startoffset + m * endangle / (pts-1); double c2 = Math.cos(p); double s2 = Math.sin(p); points[m] = new Point2D.Double(center.getX() + a * c2, center.getY() + b * s2); } } return points; } /** * Method to extract an X coordinate from an array. * @param tracePoints the array of coordinate values. * @param index the entry in the array to retrieve. * @param cX an offset value to add to the retrieved value. * @return the X coordinate value. */ private double getTracePointX(Point2D [] tracePoints, int index, double cX) { double v = tracePoints[index].getX(); return v + cX; } /** * Method to extract an Y coordinate from an array. * @param tracePoints the array of coordinate values. * @param index the entry in the array to retrieve. * @param cY an offset value to add to the retrieved value. * @return the Y coordinate value. */ private double getTracePointY(Point2D [] tracePoints, int index, double cY) { double v = tracePoints[index].getY(); return v + cY; } /** * Method to set default outline information on a NodeInst. * Very few primitives have default outline information (usually just in the Artwork Technology). * This method overrides the one in Technology. * @param ni the NodeInst to load with default outline information. */ public void setDefaultOutline(NodeInst ni) { if (ni.isCellInstance()) return; PrimitiveNode np = (PrimitiveNode)ni.getProto(); double x = ni.getAnchorCenterX(); double y = ni.getAnchorCenterY(); if (np == openedPolygonNode || np == openedDottedPolygonNode || np == openedDashedPolygonNode || np == openedThickerPolygonNode || np == splineNode) { EPoint [] outline = new EPoint[4]; outline[0] = new EPoint(x-3, y-3); outline[1] = new EPoint(x-1, y+3); outline[2] = new EPoint(x+1, y-3); outline[3] = new EPoint(x+3, y+3); ni.setTrace(outline); } if (np == closedPolygonNode || np == filledPolygonNode) { Point2D [] outline = new EPoint[4]; outline[0] = new EPoint(x+0, y-3); outline[1] = new EPoint(x-3, y+0); outline[2] = new EPoint(x+0, y+3); outline[3] = new EPoint(x+3, y-3); ni.setTrace(outline); } } /** * Method to convert the given spline control points into a spline curve. * @param cX the center X coordinate of the spline. * @param cY the center Y coordinate of the spline. * @param tracePoints the array of control point values, alternating X/Y/X/Y. * @return an array of points that describes the spline. */ public Point2D [] fillSpline(double cX, double cY, Point2D [] tracePoints) { int steps = SPLINEGRAIN; int count = tracePoints.length; int outPoints = (count - 1) * steps + 1; Point2D [] points = new Point2D.Double[outPoints]; int out = 0; double splineStep = 1.0 / steps; double x2 = getTracePointX(tracePoints, 0, cX)*2 - getTracePointX(tracePoints, 1, cX); double y2 = getTracePointY(tracePoints, 0, cY)*2 - getTracePointY(tracePoints, 1, cY); double x3 = getTracePointX(tracePoints, 0, cX); double y3 = getTracePointY(tracePoints, 0, cY); double x4 = getTracePointX(tracePoints, 1, cX); double y4 = getTracePointY(tracePoints, 1, cY); for(int k = 2; k <= count; k++) { double x1 = x2; x2 = x3; x3 = x4; double y1 = y2; y2 = y3; y3 = y4; if (k == count) { x4 = getTracePointX(tracePoints, k-1, cX)*2 - getTracePointX(tracePoints, k-2, cX); y4 = getTracePointY(tracePoints, k-1, cY)*2 - getTracePointY(tracePoints, k-2, cY); } else { x4 = getTracePointX(tracePoints, k, cX); y4 = getTracePointY(tracePoints, k, cY); } int i=0; for(double t=0.0; i<steps; i++, t+= splineStep) { double tsq = t * t; double t4 = tsq * t; double t3 = -3.0*t4 + 3.0*tsq + 3.0*t + 1.0; double t2 = 3.0*t4 - 6.0*tsq + 4.0; double t1 = -t4 + 3.0*tsq - 3.0*t + 1.0; double x = (x1*t1 + x2*t2 + x3*t3 + x4*t4) / 6.0; double y = (y1*t1 + y2*t2 + y3*t3 + y4*t4) / 6.0; points[out++] = new Point2D.Double(x, y); } } // close the spline points[out++] = new Point2D.Double(getTracePointX(tracePoints, count-1, cX), getTracePointY(tracePoints, count-1, cY)); return points; } /** * Method to return the Layer to use for an Artwork ImmutableElectricObject. * If there are individualized color and pattern Variables on the ImmutableElectricObject, * they are used to construct a new Layer (with a new EGraphics that captures * the color and pattern). * @param d the ImmutableElectricObject with individualized color and pattern information. * @return a Layer that has the color and pattern. */ private Layer getProperLayer(ImmutableElectricObject d) { EGraphics graphics = makeGraphics(d); if (graphics == null) { int col = User.getColor(User.ColorPrefType.ARTWORK) & 0xFFFFFF; EGraphics eg = defaultLayer.getGraphics(); if (eg.getRGB() != col) eg.setColorIndex(EGraphics.makeIndex(new Color(col))); return defaultLayer; } Layer thisLayer = Layer.newInstanceFree(this, "Graphics", graphics); return thisLayer; } /** * Method to create an EGraphics for an ElectricObject with color and pattern Variables. * @param eObj the ElectricObject with graphics specifications. * @return a new EGraphics that has the color and pattern. */ public static EGraphics makeGraphics(ElectricObject eObj) { return makeGraphics(eObj.getD()); } /** * Method to create an EGraphics for an ImmutableElectricObject with color and pattern Variables. * @param d the ImmutableElectricObject with graphics specifications. * @return a new EGraphics that has the color and pattern. */ private static EGraphics makeGraphics(ImmutableElectricObject d) { // get the color and pattern information Integer color = d.getVarValue(ART_COLOR, Integer.class); Variable patternVar = d.getVar(ART_PATTERN); if (color == null && patternVar == null) return null; // make a fake layer with graphics EGraphics graphics = new EGraphics(false, false, null, 0, 0,0,0, 0.8,true, new int[] {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}); // set the color if specified if (color != null) graphics.setColorIndex(color.intValue()); // autoboxing // set the stipple pattern if specified if (patternVar != null) { int len = patternVar.getLength(); if (len != 8 && len != 16 && len != 17) { System.out.println("'ART_pattern' length is incorrect"); return null; } graphics.setPatternedOnDisplay(true); graphics.setPatternedOnPrinter(true); graphics.setOutlined(null); int [] pattern = graphics.getPattern(); Object obj = patternVar.getObject(); if (obj instanceof Integer[]) { Integer [] pat = (Integer [])obj; if (len == 17) { // the last entry specifies the outline texture int outlineIndex = pat[16].intValue(); // autoboxing graphics.setOutlined(EGraphics.Outline.findOutline(outlineIndex)); len = 16; } for(int i=0; i<len; i++) pattern[i] = pat[i].intValue(); // autoboxing } else if (obj instanceof Short[]) { Short [] pat = (Short [])obj; for(int i=0; i<len; i++) pattern[i] = pat[i].shortValue(); graphics.setOutlined(EGraphics.Outline.PAT_S); } if (len == 8) { for(int i=0; i<8; i++) pattern[i+8] = pattern[i]; } } return graphics; }// /**// * Method to set Variables on an ElectricObject to capture information in an EGraphics.// * @param graphics the EGraphics to store on the ElectricObject.// * @param eObj the ElectricObject that will have new graphics information.// */// public static void setGraphics(EGraphics graphics, ElectricObject eObj)// {// // see what is already on the object// Variable colorVar = eObj.getVar(ART_COLOR, Integer.class);// Variable patternVar = eObj.getVar(ART_PATTERN);//// // set the color if specified// int transparent = graphics.getTransparentLayer();// Color newColor = graphics.getColor();// if (transparent == 0 && newColor == Color.BLACK)// {// if (colorVar != null) eObj.delVar(ART_COLOR);// } else// {// int index = 0;// if (transparent > 0) index = EGraphics.makeIndex(transparent); else// index = EGraphics.makeIndex(newColor);// eObj.newVar(ART_COLOR, new Integer(index));// }//// // set the stipple pattern if specified// if (graphics.isPatternedOnDisplay())// {// // set the pattern// int [] pattern = graphics.getPattern();// Integer [] pat = new Integer[17];// for(int i=0; i<16; i++)// pat[i] = new Integer(pattern[i]);// pat[16] = new Integer(graphics.getOutlined().getIndex());// eObj.newVar(ART_PATTERN, pat);// } else// {// if (patternVar != null) eObj.delVar(ART_PATTERN);// }// }//// /**// * Method to convert old primitive names to their proper NodeProtos.// * @param name the name of the old primitive.// * @return the proper PrimitiveNode to use (or null if none can be determined).// */// public PrimitiveNode convertOldNodeName(String name)// {// if (name.equals("Message") || name.equals("Centered-Message") ||// name.equals("Left-Message") || name.equals("Right-Message"))// return Generic.tech.invisiblePinNode;// if (name.equals("Opened-FarDotted-Polygon")) return openedThickerPolygonNode;// return null;// }//// /**// * Method to convert old primitive names to their proper ArcProtos.// * @param name the name of the old primitive.// * @return the proper ArcProto to use (or null if none can be determined).// */// public ArcProto convertOldArcName(String name)// {// if (name.equals("Dash-1")) return dottedArc;// if (name.equals("Dash-2")) return dashedArc;// if (name.equals("Dash-3")) return thickerArc;// return null;// } /** * Method to determ if ArcProto is an Artwork primitive arc * @param p ArcProto reference * @return true if primitive belongs to the Artwork technology */ public static boolean isArtworkArc(ArcProto p) { return (p == Artwork.tech().solidArc || p == Artwork.tech().dottedArc || p == Artwork.tech().dashedArc || p == Artwork.tech().thickerArc); } /******************** OPTIONS ********************/ private Pref cacheFillArrows = Pref.makeBooleanPref("ArtworkFillArrows", getTechnologyPreferences(), false); /** * Method to tell whether arrow heads are filled-in. * @return true if arrow heads are filled-in. */ public boolean isFilledArrowHeads() { return cacheFillArrows.getBoolean(); } /** * Method to set whether arrow heads are filled-in. * @param f true if arrow heads are filled-in. */ public void setFilledArrowHeads(boolean f) { cacheFillArrows.setBoolean(f); } /** * Method to tell whether arrow heads are filled-in, by default. * @return true if arrow heads are filled-in, by default. */ public boolean isFactoryFilledArrowHeads() { return cacheFillArrows.getBooleanFactoryValue(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -