예제 #1
0
 public SymbolField()
 {
     this.Text                = new TextBase();
     this.Text.Value          = "~";
     this.Text.Pos            = new Position(0, 0, Orientation_Horiz);
     this.Text.FontSize       = 60;
     this.Text.HorizAlignment = "C";
     this.Text.VertAlignment  = "C";
     this.Text.Italic         = false;
     this.Text.Bold           = false;
     this.Text.Visible        = false;
 }
예제 #2
0
        // for standard fields
        public SymbolField(string value, PointF at, float font_size, bool visible,
                           string orientation, string horizAlignment, string vertAlign, bool italic, bool bold)
        {
            this.Index = 0;

            this.Text                = new TextBase();
            this.Text.Value          = value;
            this.Text.Pos            = new Position(at);
            this.Text.FontSize       = font_size;
            this.Text.Pos.Rotation   = orientation == "H" ? Orientation_Horiz : Orientation_Vert;
            this.Text.HorizAlignment = horizAlignment;
            this.Text.VertAlignment  = vertAlign;
            this.Text.Visible        = visible;
            this.Text.Italic         = italic;
            this.Text.Bold           = bold;
        }
예제 #3
0
        public sym_text(int unit, string Value, float Angle, PointF Pos, float Size, bool Hidden,
                        bool Italic, bool Bold, string HorizAlign, string VertAlign)
        {
            this.Unit = unit;
            this.DeMorganAlternate = 0;

            this.Text                = new TextBase();
            this.Text.Pos            = new Position(Pos.X, Pos.Y, Angle);
            this.Text.FontSize       = Size;
            this.Text.Visible        = !Hidden;
            this.Text.Value          = Value;
            this.Text.Italic         = Italic;
            this.Text.Bold           = Bold;
            this.Text.HorizAlignment = HorizAlign;
            this.Text.VertAlignment  = VertAlign;
        }
예제 #4
0
        //public bool Hidden;
        //public PointF Pos;
        //public float Size;
        //public string TextValue;
        //public bool Italic;
        //public bool Bold;
        //public string HorizAlign;
        //public string VertAlign;

        public sym_text()
        {
            this.Text = new TextBase();
        }
예제 #5
0
        // 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;
        }
예제 #6
0
        private void DrawText(Canvas canvas, TextBase text, Brush brush)
        {
            bool debug = true;

            if (text.Visible)
            {
                Point     sp1   = canvas.ToScreen(text.Pos.At);
                FontStyle style = FontStyle.Regular;

                int FontHeight = canvas.ToScreen(text.FontSize);
                if (text.Italic)
                {
                    style |= FontStyle.Italic;
                }
                if (text.Bold)
                {
                    style |= FontStyle.Bold;
                }

                FontFamily family   = new FontFamily("Arial");
                float      emHeight = FontHeight * family.GetEmHeight(style) / family.GetLineSpacing(style);
                Font       font     = new Font(family, emHeight, GraphicsUnit.Pixel);

                //

                Rectangle srect = new Rectangle();
                SizeF     s     = canvas.g.MeasureString(text.Value, font);

                srect.X      = 0;
                srect.Y      = 0;
                srect.Height = (int)s.Height + 5;
                srect.Width  = (int)s.Width + 5;

                switch (text.HorizAlignment)
                {
                case SymbolField.HorizAlign_Left: break;

                case SymbolField.HorizAlign_Center:
                    srect.X = (int)(-s.Width / 2);
                    break;

                case SymbolField.HorizAlign_Right:
                    srect.X = (int)(-s.Width);
                    break;
                }

                switch (text.VertAlignment)
                {
                case SymbolField.VertAlign_Top:
                    break;

                case SymbolField.VertAlign_Center:
                    srect.Y = (int)(-s.Height / 2);
                    break;

                case SymbolField.VertAlign_Bottom:
                    srect.Y = (int)(-s.Height);
                    break;
                }

                StringFormat strF = new StringFormat();
                strF.Alignment     = StringAlignment.Center;
                strF.LineAlignment = StringAlignment.Center;

                //switch (text.HorizAlignment)
                //{
                //    case symbol_text.HorizAlign_Left:
                //        strF.Alignment = StringAlignment.Near;
                //        break;
                //    case symbol_text.HorizAlign_Center:
                //        strF.Alignment = StringAlignment.Center;
                //        break;
                //    case symbol_text.HorizAlign_Right:
                //        strF.Alignment = StringAlignment.Far;
                //        break;
                //}

                //switch (text.VertAlignment)
                //{
                //    case symbol_text.VertAlign_Top:
                //        strF.LineAlignment = StringAlignment.Far;
                //        break;
                //    case symbol_text.VertAlign_Center:
                //        strF.LineAlignment = StringAlignment.Center;
                //        break;
                //    case symbol_text.VertAlign_Bottom:
                //        strF.LineAlignment = StringAlignment.Near;
                //        break;
                //}


                if (debug)
                {
                    DrawCross(canvas, sp1);
                }

                canvas.g.TranslateTransform(sp1.X, sp1.Y);

                if (text.Pos.Rotation == 90)
                {
                    canvas.g.RotateTransform(-90);
                }

                canvas.g.DrawString(text.Value, font, brush, srect, strF);

                if (debug)
                {
                    // draw bounding box (?)
                    Pen pen = new Pen(Color.Gray, 1);
                    pen.DashStyle = DashStyle.Dot;
                    canvas.g.DrawRectangle(pen, srect.Left, srect.Top, srect.Width, srect.Height);
                }

                canvas.g.ResetTransform();
            }
        }