private void SchematicDisplay_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            SchematicCanvas.Children.Clear();

            Schematic schematic = (DataContext as Schematic);

            if (schematic != null)
            {
                double minX = double.MaxValue;
                double minY = double.MaxValue;
                double maxX = 0;
                double maxY = 0;

                // Find the bounds of the schematic
                foreach (Element element in schematic.Elements)
                {
                    minX = Math.Min(element.LowerBound.x, minX);
                    maxX = Math.Max(element.UpperBound.x, maxX);
                    minY = Math.Min(element.LowerBound.y, minY);
                    maxY = Math.Max(element.UpperBound.y, maxY);
                }

                SchematicCanvas.Width  = (Math.Abs(minX) + Math.Abs(maxX)) * 1.2;
                SchematicCanvas.Height = (Math.Abs(minY) + Math.Abs(maxY)) * 1.2;

                UpdateScale();

                // Offset the origin by the center of the used region to center the schematic
                Circuit.Coord origin = new Circuit.Coord((int)((SchematicCanvas.Width / 2) - ((minX + maxX) / 2)), (int)((SchematicCanvas.Height / 2) - ((minY + maxY) / 2)));

                foreach (Element element in schematic.Elements)
                {
                    ElementControl control = ElementControl.New(element);

                    SchematicCanvas.Children.Add(control);

                    Circuit.Coord lb = element.LowerBound;
                    Circuit.Coord ub = element.UpperBound;

                    Canvas.SetLeft(control, lb.x + origin.x);
                    Canvas.SetTop(control, lb.y + origin.y);

                    control.Width  = ub.x - lb.x;
                    control.Height = ub.y - lb.y;
                }
            }
        }
Beispiel #2
0
 public bool IsConnectedTo(Coord x)
 {
     return(PointOnSegment(x, A, B));
 }
Beispiel #3
0
 public Wire(Coord A, Coord B) : this()
 {
     a = A;
     b = B;
 }
Beispiel #4
0
 public static bool PointOnSegment(Coord x, Coord x1, Coord x2)
 {
     return(PointInRect(x, x1, x2) && PointOnLine(x, x1, x2));
 }
Beispiel #5
0
 public static bool PointOnLine(Coord x, Coord x1, Coord x2)
 {
     return((x2.x - x1.x) * (x.y - x1.y) == (x.x - x1.x) * (x2.y - x1.y));
 }
Beispiel #6
0
 private static bool PointInRect(Coord A, Coord x1, Coord x2)
 {
     return(((x1.x <= A.x && A.x <= x2.x) || (x2.x <= A.x && A.x <= x1.x)) &&
            ((x1.y <= A.y && A.y <= x2.y) || (x2.y <= A.y && A.y <= x1.y)));
 }
Beispiel #7
0
 public static bool SegmentsIntersect(Coord A, Coord B, Coord C, Coord D)
 {
     return(Ccw(A, C, D) != Ccw(B, C, D) && Ccw(A, B, C) != Ccw(A, B, D));
 }
Beispiel #8
0
 // http://www.bryceboe.com/2006/10/23/line-segment-intersection-algorithm/
 private static bool Ccw(Coord A, Coord B, Coord C)
 {
     return((C.y - A.y) * (B.x - A.x) >= (B.y - A.y) * (C.x - A.x));
 }
Beispiel #9
0
 public override void RotateAround(int dt, Point at)
 {
     a = (Coord)Point.Round(RotateAround(a, dt, at));
     b = (Coord)Point.Round(RotateAround(b, dt, at));
     OnLayoutChanged();
 }
Beispiel #10
0
 public override void Move(Coord dx)
 {
     a += dx;
     b += dx;
     OnLayoutChanged();
 }
Beispiel #11
0
 public Node NodeAt(Coord x)
 {
     return(NodeAt(x, null));
 }
Beispiel #12
0
 /// <summary>
 /// Get the terminals located at x.
 /// </summary>
 /// <param name="x"></param>
 /// <returns></returns>
 public IEnumerable <Terminal> TerminalsAt(Coord x)
 {
     return(elements.SelectMany(i => i.Terminals.Where(j => i.MapTerminal(j) == x)));
 }