예제 #1
0
        protected void OnMouseMove(object sender, MouseEventArgs e)
        {
            Point x = e.GetPosition(this);

            Matrix transform = Transform;

            foreach (Circuit.Terminal i in Symbol.Terminals)
            {
                Circuit.Coord tx = layout.MapTerminal(i);
                Point         tp = new Point(tx.x, tx.y);
                tp = transform.Transform(tp);
                if ((tp - x).Length < 5.0)
                {
                    ToolTip = "Terminal '" + i.ToString() + "'";
                    return;
                }
            }

            TextBlock text = new TextBlock();

            Circuit.Component component = Symbol.Component;

            text.Inlines.Add(new Bold(new Run(component.ToString())));

            foreach (PropertyInfo i in component.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public).Where(j =>
                                                                                                                            j.CustomAttribute <Circuit.Serialize>() != null &&
                                                                                                                            (j.CustomAttribute <BrowsableAttribute>() == null || j.CustomAttribute <BrowsableAttribute>().Browsable)))
            {
                object value = i.GetValue(component, null);
                DefaultValueAttribute def = i.CustomAttribute <DefaultValueAttribute>();
                if (def == null || !Equals(def.Value, value))
                {
                    System.ComponentModel.TypeConverter tc = System.ComponentModel.TypeDescriptor.GetConverter(i.PropertyType);
                    text.Inlines.Add(new Run("\n" + i.Name + " = "));
                    text.Inlines.Add(new Bold(new Run(tc.ConvertToString(value))));
                }
            }

            ToolTip = new ToolTip()
            {
                Content = text
            };
        }
예제 #2
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 ?? 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 ?? 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 ?? 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 ?? 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();
        }