Ejemplo n.º 1
0
        public static void DrawLayout(
            Circuit.SymbolLayout Layout,
            DrawingContext Context, Matrix Tx, 
            Pen Pen, FontFamily FontFamily, FontWeight FontWeight, double FontSize)
        {
            Context.PushGuidelineSet(Guidelines);

            foreach (Circuit.SymbolLayout.Shape i in Layout.Lines)
                Context.DrawLine(
                    Pen != null ? Pen : MapToPen(i.Edge),
                    T(Tx, i.x1),
                    T(Tx, i.x2));
            foreach (Circuit.SymbolLayout.Shape i in Layout.Rectangles)
                Context.DrawRectangle(
                    (i.Fill && Pen == null) ? MapToBrush(i.Edge) : null,
                    Pen != null ? Pen : MapToPen(i.Edge),
                    new Rect(T(Tx, i.x1), T(Tx, i.x2)));
            foreach (Circuit.SymbolLayout.Shape i in Layout.Ellipses)
            {
                Brush brush = (i.Fill && Pen == null) ? MapToBrush(i.Edge) : null;
                Pen pen = Pen != null ? Pen : MapToPen(i.Edge);
                Point p1 = T(Tx, i.x1);
                Point p2 = T(Tx, i.x2);

                Context.DrawEllipse(
                    brush, pen,
                    new Point((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2), (p2.X - p1.X) / 2, (p2.Y - p1.Y) / 2);
            }
            foreach (Circuit.SymbolLayout.Curve i in Layout.Curves)
            {
                IEnumerator<Circuit.Point> e = i.x.AsEnumerable().GetEnumerator();
                if (!e.MoveNext())
                    return;

                Pen pen = Pen != null ? Pen : MapToPen(i.Edge);
                Point x1 = T(Tx, e.Current);
                while (e.MoveNext())
                {
                    Point x2 = T(Tx, e.Current);
                    Context.DrawLine(pen, x1, x2);
                    x1 = x2;
                }
            }

            if (FontFamily != null)
            {
                // Not sure if this matrix has row or column vectors... want the y axis scaling here.
                double scale = Math.Sqrt(Tx.M11 * Tx.M11 + Tx.M21 * Tx.M21);

                foreach (Circuit.SymbolLayout.Text i in Layout.Texts)
                {
                    double size;
                    switch (i.Size)
                    {
                        case Circuit.Size.Small: size = 0.5; break;
                        case Circuit.Size.Large: size = 1.5; break;
                        default: size = 1.0; break;
                    }
                    FormattedText text = new FormattedText(
                        i.String,
                        CultureInfo.CurrentUICulture, FlowDirection.LeftToRight,
                        new Typeface(FontFamily, FontStyles.Normal, FontWeight, FontStretches.Normal), FontSize * scale * size,
                        Brushes.Black);

                    Point p = T(Tx, i.x);
                    Vector p1 = T(Tx, new Circuit.Point(i.x.x - MapAlignment(i.HorizontalAlign), i.x.y + (1 - MapAlignment(i.VerticalAlign)))) - p;
                    Vector p2 = T(Tx, new Circuit.Point(i.x.x - (1 - MapAlignment(i.HorizontalAlign)), i.x.y + MapAlignment(i.VerticalAlign))) - p;

                    p1.X *= text.Width; p2.X *= text.Width;
                    p1.Y *= text.Height; p2.Y *= text.Height;

                    Rect rc = new Rect(
                        Math.Min(p.X + p1.X, p.X - p2.X),
                        Math.Min(p.Y + p1.Y, p.Y - p2.Y),
                        text.Width,
                        text.Height);
                    if (TextOutline != null)
                        Context.DrawRectangle(null, TextOutline, rc);

                    Context.DrawText(text, rc.TopLeft);
                }
            }

            foreach (Circuit.Terminal i in Layout.Terminals)
                DrawTerminal(Context, T(Tx, Layout.MapTerminal(i)), i.ConnectedTo != null);

            Context.Pop();
        }