public new static sym_text Parse(List <Token> tokens) { sym_text result = new sym_text(); result.Text.Pos = new Position(tokens[2].IntValue, tokens[3].IntValue, (float)tokens[1].GetValueAsDouble() / 10.0f); result.Text.FontSize = (float)tokens[4].GetValueAsDouble(); result.Text.Visible = tokens[5].Value != "1"; result.Unit = tokens[6].IntValue; result.DeMorganAlternate = tokens[7].IntValue; result.Text.Value = tokens[8].Value; result.Text.Italic = tokens[9].Value == "Italic"; result.Text.Bold = tokens[10].Value == "1"; result.Text.HorizAlignment = tokens[11].Value; result.Text.VertAlignment = tokens[12].Value; return(result); }
// drawing functions public void Render(Canvas canvas) { canvas.Ydir = -1; // +ve Y is up the page canvas.Initialise(); // Pen pen = new Pen(canvas.color_symbol_drawing, 2); Brush brush = new SolidBrush(canvas.color_symbol_drawing); Brush brush_text = new SolidBrush(canvas.color_symbol_text); // pen.Width = 2; pen.EndCap = System.Drawing.Drawing2D.LineCap.Round; pen.StartCap = System.Drawing.Drawing2D.LineCap.Round; pen.Alignment = System.Drawing.Drawing2D.PenAlignment.Center; // DrawText(canvas, fValue.Text, brush_text); DrawText(canvas, fReference.Text, brush_text); SolidBrush fill_brush = new SolidBrush(canvas.color_symbol_drawing); // draw background fills foreach (sym_drawing_base node in this.Drawings) { if (node.Fill == FillTypes.PenColor) { fill_brush.Color = canvas.color_symbol_drawing; } else { fill_brush.Color = canvas.color_symbol_background; } if (node is sym_rectangle) { sym_rectangle gr_rect = node as sym_rectangle; Point sp1 = canvas.ToScreen(gr_rect.P1); Point sp2 = canvas.ToScreen(gr_rect.P2); if (gr_rect.Fill != FillTypes.None) { canvas.g.FillRectangle(fill_brush, new Rectangle(Math.Min(sp1.X, sp2.X), Math.Min(sp1.Y, sp2.Y), Math.Abs(sp2.X - sp1.X), Math.Abs(sp2.Y - sp1.Y))); } } else if (node is sym_polygon) { sym_polygon gr_poly = node as sym_polygon; if (node.Fill != FillTypes.None) { Point[] points = new Point[gr_poly.NumVertex]; for (int i = 0; i < gr_poly.NumVertex; i++) { points[i] = canvas.ToScreen(gr_poly.Vertex[i]); } canvas.g.FillPolygon(fill_brush, points); } } else if (node is sym_arc) { } else if (node is sym_circle) { } } Console.WriteLine("sym {0}", Name); // draw foreground items foreach (sym_drawing_base node in this.Drawings) { if (node.PenSize == 0) { pen.Width = canvas.ToScreen(5f); } else { pen.Width = canvas.ToScreen(node.PenSize); } if (node.Fill == FillTypes.PenColor) { fill_brush.Color = canvas.color_symbol_drawing; } else { fill_brush.Color = canvas.color_symbol_background; } if (node is sym_rectangle) { sym_rectangle gr_rect = node as sym_rectangle; Point sp1 = canvas.ToScreen(gr_rect.P1); Point sp2 = canvas.ToScreen(gr_rect.P2); if ((sp2.X - sp1.X == 0) || (sp2.Y - sp1.Y == 0)) { canvas.g.DrawLine(pen, sp1, sp2); } else { canvas.g.DrawRectangle(pen, new Rectangle(Math.Min(sp1.X, sp2.X), Math.Min(sp1.Y, sp2.Y), Math.Abs(sp2.X - sp1.X), Math.Abs(sp2.Y - sp1.Y))); } } else if (node is sym_arc) { sym_arc arc = node as sym_arc; Point sp1 = canvas.ToScreen(arc.Position); int radius = canvas.ToScreen(arc.Radius); #if Method1 float start, end; start = NormalizeAnglePos(arc.ArcStart); end = NormalizeAnglePos(arc.ArcEnd); float angle = end - start; float a_start = CalcAngle(arc.Position, arc.Start); float a_end = CalcAngle(arc.Position, arc.End); Console.WriteLine("arc {0:f1} {1:f1} {2:f1}", arc.ArcStart, arc.ArcEnd, arc.ArcEnd - arc.ArcStart); Console.WriteLine("arc norm {0:f1} {1:f1} {2:f1}", start, end, angle); Console.WriteLine("arc calc {0:f1} {1:f1} ", a_start, a_end); if (Math.Abs(angle) < 180) { if (angle != 0) { g.DrawArc(pen, new Rectangle(sp1.X - radius, sp1.Y - radius, radius * 2, radius * 2), -a_end, angle); } } else { if (angle > 180) { angle -= 180; } g.DrawArc(pen, new Rectangle(sp1.X - radius, sp1.Y - radius, radius * 2, radius * 2), -a_start, angle); } #endif // #if Method2 float start, end; start = NormalizeAnglePos(arc.ArcStart); end = NormalizeAnglePos(arc.ArcEnd); bool swap = MapAngles(ref start, ref end); PointF pos1 = arc.Start; PointF pos2 = arc.End; if (swap) { pos1 = arc.End; pos2 = arc.Start; } //float angle = NormalizeAnglePos(end - start); float angle = end - start; //start = CalcAngle(arc.Position, pos1); Console.WriteLine("arc {0:f1} {1:f1} {2:f1}", arc.ArcStart, arc.ArcEnd, arc.ArcEnd - arc.ArcStart); Console.WriteLine("arc norm {0:f1} {1:f1} {2:f1} {3}", start, end, angle, swap); //Console.WriteLine("arc calc {0:f1} {1:f1} ", a_start, a_end); if (angle != 0) { g.DrawArc(pen, new Rectangle(sp1.X - radius, sp1.Y - radius, radius * 2, radius * 2), -end, angle); } #endif //#if Method3 float a_start = CalcAngle(arc.Position, arc.Start); float a_end = CalcAngle(arc.Position, arc.End); float start, end; start = NormalizeAnglePos(a_start); end = NormalizeAnglePos(a_end); float angle = end - start; if (angle < 0) { angle += 360; } // float test_angle = NormalizeAnglePos(arc.ArcEnd) - NormalizeAnglePos(arc.ArcStart); test_angle = NormalizeAnglePos(test_angle); if (angle != 0) { if ((test_angle < 180)) { canvas.g.DrawArc(pen, new Rectangle(sp1.X - radius, sp1.Y - radius, radius * 2, radius * 2), -end, angle); } else { canvas.g.DrawArc(pen, new Rectangle(sp1.X - radius, sp1.Y - radius, radius * 2, radius * 2), -start, 360.0f - angle); } } //#endif // if (false) { Pen tpen = new Pen(Color.Green); tpen.Width = 3; canvas.g.DrawLine(tpen, sp1, canvas.ToScreen(arc.Start)); tpen.Color = Color.Blue; canvas.g.DrawLine(tpen, sp1, canvas.ToScreen(arc.End)); } } else if (node is sym_circle) { sym_circle circle = node as sym_circle; Point sp1 = canvas.ToScreen(circle.Position); int radius = canvas.ToScreen(circle.Radius); canvas.g.DrawEllipse(pen, new Rectangle(sp1.X - radius, sp1.Y - radius, radius * 2, radius * 2)); } else if (node is sym_bezier) { } else if (node is sym_polygon) { sym_polygon gr_poly = node as sym_polygon; if (node.Fill == FillTypes.PenColor) { Point[] points = new Point[gr_poly.NumVertex]; for (int i = 0; i < gr_poly.NumVertex; i++) { points[i] = canvas.ToScreen(gr_poly.Vertex[i]); } canvas.g.FillPolygon(fill_brush, points); } for (int i = 0; i < gr_poly.NumVertex - 1; i++) { Point sp1 = canvas.ToScreen(gr_poly.Vertex[i]); Point sp2 = canvas.ToScreen(gr_poly.Vertex[i + 1]); canvas.g.DrawLine(pen, sp1, sp2); } if ((node.Fill != FillTypes.None) && (gr_poly.NumVertex > 2)) { Point sp1 = canvas.ToScreen(gr_poly.Vertex[0]); Point sp2 = canvas.ToScreen(gr_poly.Vertex[gr_poly.NumVertex - 1]); canvas.g.DrawLine(pen, sp1, sp2); } } else if (node is sym_pin) { sym_pin pin = node as sym_pin; if (pin.Visible) { Point sp1 = canvas.ToScreen(pin.Pos); int radius = canvas.ToScreen(10f); PointF offset = new PointF(0, 0); switch (pin.Orientation) { case "L": offset.X = -pin.Length; break; case "R": offset.X = pin.Length; break; case "U": offset.Y = pin.Length; break; case "D": offset.Y = -pin.Length; break; } Point sp2 = canvas.ToScreen(new PointF(pin.Pos.X + offset.X, pin.Pos.Y + offset.Y)); if (pin.PenSize == 0) { pen.Width = canvas.ToScreen(5f); } else { pen.Width = canvas.ToScreen(pin.PenSize); } canvas.g.DrawLine(pen, sp1, sp2); pen.Width = 2; canvas.g.DrawEllipse(pen, new Rectangle(sp1.X - radius, sp1.Y - radius, radius * 2, radius * 2)); // int FontHeight = canvas.ToScreen(pin.SizeName); Font font = new Font("Arial", FontHeight, FontStyle.Regular, GraphicsUnit.Pixel); TextBase text = new TextBase(); // horiz if ((pin.Orientation == "L") || (pin.Orientation == "R")) { if ((this.ShowPinName) && (pin.Name != "~")) { // inside? if (this.Offset != 0) { if (pin.Orientation == "R") { text.Pos = new Position(pin.Pos.X + offset.X + this.Offset, pin.Pos.Y); text.HorizAlignment = SymbolField.HorizAlign_Left; text.VertAlignment = SymbolField.VertAlign_Center; } else { text.Pos = new Position(pin.Pos.X + offset.X - this.Offset, pin.Pos.Y); text.HorizAlignment = SymbolField.HorizAlign_Right; text.VertAlignment = SymbolField.VertAlign_Center; } } else { if (pin.Orientation == "R") { text.Pos = new Position(pin.Pos.X + pin.Length / 2, pin.Pos.Y); text.HorizAlignment = SymbolField.HorizAlign_Center; text.VertAlignment = SymbolField.VertAlign_Bottom; } else { text.Pos = new Position(pin.Pos.X - pin.Length / 2, pin.Pos.Y); text.HorizAlignment = SymbolField.HorizAlign_Center; text.VertAlignment = SymbolField.VertAlign_Bottom; } } text.FontSize = pin.SizeName; text.Value = pin.Name; DrawText(canvas, text, brush_text); } if (this.ShowPinNumber) { if (pin.Orientation == "L") { text.Pos = new Position(pin.Pos.X - pin.Length / 2, pin.Pos.Y); } else { text.Pos = new Position(pin.Pos.X + pin.Length / 2, pin.Pos.Y); } text.HorizAlignment = SymbolField.HorizAlign_Center; if (this.Offset == 0) { text.VertAlignment = SymbolField.VertAlign_Top; } else { text.VertAlignment = SymbolField.VertAlign_Bottom; } text.FontSize = pin.SizeName; text.Value = pin.PinNumber; DrawText(canvas, text, brush); } } else // vertical { if ((this.ShowPinName) && (pin.Name != "~")) { if (pin.Orientation == "U") { text.Pos = new Position(pin.Pos.X, pin.Pos.Y + offset.Y + this.Offset); text.HorizAlignment = SymbolField.HorizAlign_Left; } else { text.Pos = new Position(pin.Pos.X, pin.Pos.Y + offset.Y - this.Offset); text.HorizAlignment = SymbolField.HorizAlign_Right; } text.VertAlignment = SymbolField.VertAlign_Center; text.FontSize = pin.SizeName; text.Value = pin.Name; text.Pos.Rotation = 90; DrawText(canvas, text, brush_text); } if (this.ShowPinNumber) { if (pin.Orientation == "D") { text.Pos = new Position(pin.Pos.X, pin.Pos.Y - pin.Length / 2); } else { text.Pos = new Position(pin.Pos.X, pin.Pos.Y + pin.Length / 2); } text.HorizAlignment = SymbolField.HorizAlign_Center; text.VertAlignment = SymbolField.VertAlign_Bottom; text.FontSize = pin.SizeName; text.Value = pin.PinNumber; text.Pos.Rotation = 90; DrawText(canvas, text, brush); } } } } else if (node is sym_text) { sym_text text = node as sym_text; DrawText(canvas, text.Text, brush); } } //return bm; }