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;
                }
            }
        }
예제 #2
0
 public bool IsConnectedTo(Coord x)
 {
     return(PointOnSegment(x, A, B));
 }
예제 #3
0
 public Wire(Coord A, Coord B) : this()
 {
     a = A;
     b = B;
 }
예제 #4
0
 public static bool PointOnSegment(Coord x, Coord x1, Coord x2)
 {
     return(PointInRect(x, x1, x2) && PointOnLine(x, x1, x2));
 }
예제 #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));
 }
예제 #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)));
 }
예제 #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));
 }
예제 #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));
 }
예제 #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();
 }
예제 #10
0
 public override void Move(Coord dx)
 {
     a += dx;
     b += dx;
     OnLayoutChanged();
 }
예제 #11
0
 public Node NodeAt(Coord x)
 {
     return(NodeAt(x, null));
 }
예제 #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)));
 }