예제 #1
0
 /// <summary>
 /// Creates a wire that's unattched to a model.
 /// </summary>
 public Wire(Terminal startTerminal, double x1, double y1)
 {
     X2 = startTerminal.Model.X;
     Y2 = startTerminal.Model.Y;
     BannedDirectionForEnd   = DirectionHelpers.OppositeDirection(startTerminal.Model.Direction);
     BannedDirectionForStart = Direction.None;
     X1 = x1;
     Y1 = y1;
     _wirePathingAlgorithum.FallbackSourceTerminal = startTerminal.Model.Kind == TerminalKind.Input ? startTerminal : null;
     _wirePathingAlgorithum.FallbackSinkTerminal   = startTerminal.Model.Kind == TerminalKind.Output ? startTerminal : null;
     LineColorBrush = new SolidColorBrush(Colors.White);
 }
예제 #2
0
        public Point[] GetWirePoints(WireModel model, double x1, double y1, double x2, double y2, Direction bannedDirectionForStart, Direction bannedDirectionForEnd)
        {
            _wireModel = model;
            var start = new Point(x1, y1);
            var end   = new Point(x2, y2);

            var stubStart = TranslatePointInDirection(start, DirectionHelpers.OppositeDirection(bannedDirectionForStart), WireDistanceOutOfTerminal);
            var stubEnd   = TranslatePointInDirection(end, DirectionHelpers.OppositeDirection(bannedDirectionForEnd), WireDistanceOutOfTerminal);

            if (_wireModel != null)
            {
                bannedDirectionForStart = DirectionHelpers.OppositeDirection(_wireModel.SinkTerminal.Direction);
                bannedDirectionForEnd   = DirectionHelpers.OppositeDirection(_wireModel.SourceTerminal.Direction);
                stubStart = TranslatePointInDirection(start, _wireModel.SinkTerminal.Direction, WireDistanceOutOfTerminal);
                stubEnd   = TranslatePointInDirection(end, _wireModel.SourceTerminal.Direction, WireDistanceOutOfTerminal);
            }
            if (StubsAreTooCloseTogether(stubStart, stubEnd))
            {
                return(new Point[] { start, stubStart, stubEnd, end });
            }

            _uTurned = false;
            var backwardPoints = new List <Point> {
                end
            };

            WireTwoPoints(stubEnd, stubStart, bannedDirectionForEnd, bannedDirectionForStart, backwardPoints, 2, true);
            if (_uTurned)
            {
                bannedDirectionForEnd = GetBannedDirectionFromPoints(backwardPoints[1], backwardPoints[2]);
                stubEnd = backwardPoints[2];
            }

            var points = new List <Point> {
                start
            };

            WireTwoPoints(stubStart, stubEnd, bannedDirectionForStart, bannedDirectionForEnd, points);

            if (_uTurned)
            {
                points.Add(backwardPoints[1]);
            }
            points.Add(end);
            return(points.ToArray());
        }