Beispiel #1
0
 private void Canvas_LeftButtonCircuit(object sender, MouseButtonEventArgs e)
 {
     if (HitList.Count > 0)
     {
         var selected = HitList.Where(b => b is StationIconElement);
         if (selected.Count() > 0)
         {
             if (e.ChangedButton == MouseButton.Left)
             {
                 StationIconElement station = (StationIconElement)selected.First();
                 EllipseGeometry    ellipse = (EllipseGeometry)station.Icon;
                 line.EndPoint = ellipse.Center;
                 Thickness start = GetThickness(line.StartPoint, NoneList);
                 Thickness end   = GetThickness(line.EndPoint, NoneList);
                 if (start.Left < end.Left)
                 {
                     if (start.Top < end.Top)
                     {
                         var vpl = YesList.Where(a => (a.Left >= start.Left) && (a.Left <= end.Left) &&
                                                 (a.Top >= start.Top) && (a.Top <= end.Top));
                         NoneListCirc.AddRange(vpl);
                         YesList.RemoveAll(x => vpl.Contains(x));
                     }
                     else
                     {
                         var vpl = YesList.Where(a => (a.Left >= start.Left) && (a.Left <= end.Left) &&
                                                 (a.Top <= start.Top) && (a.Top >= end.Top));
                         NoneListCirc.AddRange(vpl);
                         YesList.RemoveAll(x => vpl.Contains(x));
                     }
                 }
                 else
                 {
                     if (start.Top < end.Top)
                     {
                         var vpl = YesList.Where(a => (a.Left <= start.Left) && (a.Left >= end.Left) &&
                                                 (a.Top >= start.Top) && (a.Top <= end.Top));
                         NoneListCirc.AddRange(vpl);
                         YesList.RemoveAll(x => vpl.Contains(x));
                     }
                     else
                     {
                         var vpl = YesList.Where(a => (a.Left <= start.Left) && (a.Left >= end.Left) &&
                                                 (a.Top <= start.Top) && (a.Top >= end.Top));
                         NoneListCirc.AddRange(vpl);
                         YesList.RemoveAll(x => vpl.Contains(x));
                     }
                 }
                 Canvas.MouseMove           += Canvas_MouseMove;
                 Canvas.MouseMove           -= Canvas_MoveLine;
                 path.Opacity                = 1.0;
                 Canvas.MouseLeftButtonDown -= Canvas_LeftButtonCircuit;
             }
         }
     }
 }
Beispiel #2
0
        private void Cmd_DeleteStation(object sender, ExecutedRoutedEventArgs e)
        {
            StationIconElement arriver  = (StationIconElement)e.OriginalSource;
            EllipseGeometry    geometry = (EllipseGeometry)arriver.Icon;
            Point     pos  = geometry.Center;
            Thickness ness = GetThickness(pos, NoneList);

            YesList.Add(ness);
            NoneList.Remove(ness);
            Canvas.Children.Remove(arriver);
            ContextMenuClosed = true;
        }
Beispiel #3
0
        private void Cmd_ConnectStation(object sender, ExecutedRoutedEventArgs e)
        {
            CircuitIconElement circuitIconElement = new CircuitIconElement();

            line = new LineGeometry();
            circuitIconElement.Icon = line;
            StationIconElement arriver  = (StationIconElement)e.OriginalSource;
            EllipseGeometry    geometry = (EllipseGeometry)arriver.Icon;
            Point     pos  = geometry.Center;
            Thickness ness = GetThickness(pos, NoneList);

            line.StartPoint          = new Point(ness.Left + Step / 2 - 0.25, ness.Top + Step / 2 - 0.25);
            circuitIconElement.Style = (Style)Application.Current.FindResource("CircuitStyle");
            Canvas.Children.Add(circuitIconElement);
            Canvas.SetZIndex(circuitIconElement, 1);
            Canvas.MouseMove           -= Canvas_MouseMove;
            Canvas.MouseMove           += Canvas_MoveLine;
            Canvas.MouseLeftButtonDown += Canvas_LeftButtonCircuit;
            path.Opacity = 0.0;
        }
Beispiel #4
0
        private void Cmd_CreateStation(object sender, ExecutedRoutedEventArgs e)
        {
            StationIconElement iconElement = new StationIconElement();
            EllipseGeometry    ellipse     = new EllipseGeometry();

            ellipse.RadiusX = 7.5;
            ellipse.RadiusY = 7.5;
            Path            arriver  = (Path)e.OriginalSource;
            EllipseGeometry geometry = (EllipseGeometry)arriver.Data;
            Point           pos      = geometry.Center;
            var             str      = YesList.Where(n => ((n.Left < pos.X) && (n.Right > pos.X) && (n.Top < pos.Y) && (n.Bottom > pos.Y)));
            Thickness       ness     = str.FirstOrDefault();

            ellipse.Center = new Point(ness.Left + Step / 2 - 0.25, ness.Top + Step / 2 - 0.25);
            YesList.Remove(ness);
            NoneList.Add(ness);
            iconElement.Icon  = ellipse;
            iconElement.Style = (Style)Application.Current.FindResource("IconStyle");
            //DragInCanvasBehavior dragInCanvas = new DragInCanvasBehavior();
            //Interaction.GetBehaviors(iconElement).Add(dragInCanvas);
            Canvas.Children.Add(iconElement);
            Canvas.SetZIndex(iconElement, 2);
        }