Exemplo n.º 1
0
 private StartedLineState(GraphVisual graphVisual, NumEllipse startingEllipse, Line workingLine, double weight)
     : base(graphVisual)
 {
     StartingEllipse = startingEllipse;
     WorkingLine     = workingLine;
     Weight          = weight;
 }
Exemplo n.º 2
0
        public static void DrawEuler(GraphVisual graph, Canvas canvas)
        {
            Point[] vertPositions = graph.vertPositions;

            // Draws indexes in and Euler cycle
            var eulerIdxArray = graph.FindEulerPath();

            if (graph.IsEuler())
            {
                for (int i = 0; i < eulerIdxArray.Count - 1; i++)
                {
                    Label labelEuler = new Label
                    {
#if _ONE_NUMBERING
                        Content = i + 1,
#else
                        Content = i,
#endif
                        Foreground = Brushes.Red
                    };

                    int    nextIdx = i + 1 < eulerIdxArray.Count ? i + 1 : 0;
                    double posX    = (vertPositions[eulerIdxArray[i]].X + vertPositions[eulerIdxArray[nextIdx]].X) / 2;
                    double posY    = (vertPositions[eulerIdxArray[i]].Y + vertPositions[eulerIdxArray[nextIdx]].Y) / 2;
                    Canvas.SetLeft(labelEuler, posX * canvas.ActualWidth - 12);
                    Canvas.SetTop(labelEuler, posY * canvas.ActualHeight - 12);

                    canvas.Children.Add(labelEuler);
                }
            }
        }
Exemplo n.º 3
0
        public override StateController LeftMouseDownAt(Point point, int times)
        {
            var(closestEllipse, distanceEllipse) = GraphVisual.ClosestEllipseFrom(point);
            var(closestLine, distanceLine)       = GraphVisual.ClosestLineFrom(point);

            var minDistance = Math.Min(distanceLine, distanceEllipse);

            var valueRange = new Range(GraphVisual.NodeWidth / 2.0, GraphVisual.CanvasWidth - GraphVisual.NodeWidth / 2.0);

            if (valueRange.Contains(point.X) && valueRange.Contains(point.Y))
            {
                if (times == 2 && minDistance > GraphVisual.NodeWidth)
                {
                    var nodeValue = Enumerable.Range(1, int.MaxValue).First(x => !GraphVisual.Nodes.ContainsKey(x));
                    GraphVisual.AddNode(nodeValue, point);
                    return(this);
                }
            }

            if (times == 1 && distanceEllipse < GraphVisual.NodeWidth)
            {
                return(StartedLineState.Create(GraphVisual, closestEllipse, point));
            }

            return(this);
        }
Exemplo n.º 4
0
        private void SetGraph(GraphEmbedding graphEmbedding)
        {
            PauseButton_Click(null, null);
            this.RunAlgorithmButton.IsEnabled = true;
            this.StaticGraphCanvas.Children.Clear();
            this.GraphVisual = GraphVisual.Create(StaticGraphCanvas, NodeBrush, NumBrush, LineBrush, PenLineCap);
            foreach (var node in graphEmbedding.Graph.Nodes)
            {
                GraphVisual.AddNode(node, graphEmbedding.Embedding[node]);
            }
            foreach (var edge in graphEmbedding.Graph.Edges)
            {
                GraphVisual.AddEdge(edge);
            }
            var scaleViewStackPanel = new StackPanel();

            this.ScaleViewViewer.Content = scaleViewStackPanel;
            WeightsHandler.Create(scaleViewStackPanel, NodeBrush, LineBrush, GraphVisual.NodeWidth,
                                  GraphVisual.MinLineThickness,
                                  GraphVisual.MaxLineThickness, GraphVisual.MinWeight, GraphVisual.MaxWeight);
            var edges = EdgesHandler.Create(this.WeightsViewer);

            foreach (var edge in graphEmbedding.Graph.Edges)
            {
                edges.AddEdge(edge, active: false);
            }
        }
Exemplo n.º 5
0
        public static StartedLineState Create(GraphVisual graphVisual, NumEllipse startingEllipse, Point currentPoint)
        {
            var ellipseCenter = startingEllipse.Ellipse.GetCanvasCenter();
            var weight        = (graphVisual.MinWeight + graphVisual.MaxWeight) / 2.0;
            var thickness     = (graphVisual.MinLineThickness + graphVisual.MaxLineThickness) / 2.0;
            var line          = LineUtils.CreateLine(ellipseCenter, currentPoint, graphVisual.LineBrush, thickness, graphVisual.PenLineCap);

            graphVisual.Canvas.Children.Add(line);
            return(new StartedLineState(graphVisual, startingEllipse, line, weight));
        }
Exemplo n.º 6
0
        /// <summary>Получает визуальный элемент для этого элемента карты</summary>
        public GraphVisual GetVisual(IProjector <TX, TY> Projector)
        {
            var res = new GraphVisual(this, ZIndex);

            using (DrawingContext dc = res.RenderOpen())
            {
                Draw(dc, Projector);
            }
            return(res);
        }
Exemplo n.º 7
0
        public override StateController RightMouseDownAt(Point point, int times)
        {
            if (times == 2)
            {
                var(closestEllipse, distanceEllipse) = GraphVisual.ClosestEllipseFrom(point);
                if (distanceEllipse < GraphVisual.NodeWidth / 2)
                {
                    GraphVisual.RemoveNode(GraphVisual.Nodes.GetKeyOf(closestEllipse, ReferenceEquals));
                }
            }

            return(this);
        }
Exemplo n.º 8
0
        public static void DrawGraph(GraphVisual graph, Canvas canvas, Brush vertBrush, Brush lineBrush, int shapeSize = 25, int lineWidth = 5)
        {
            canvas.Children.Clear();

            Point[] vertPositions = graph.vertPositions;

            // Draws edges
            foreach ((int, int)e in graph.Edges())
            {
                Line line = new Line
                {
                    X1     = vertPositions[e.Item1].X * canvas.ActualWidth,
                    Y1     = vertPositions[e.Item1].Y * canvas.ActualHeight,
                    X2     = vertPositions[e.Item2].X * canvas.ActualWidth,
                    Y2     = vertPositions[e.Item2].Y * canvas.ActualHeight,
                    Stroke = lineBrush
                };

                canvas.Children.Add(line);
            }

            // Draws text
            foreach (Point p in vertPositions)
            {
                Ellipse ellipse = new Ellipse
                {
                    Height = shapeSize,
                    Width  = shapeSize,
                    Fill   = vertBrush
                };

                Canvas.SetLeft(ellipse, p.X * canvas.ActualWidth - shapeSize / 2);
                Canvas.SetTop(ellipse, p.Y * canvas.ActualHeight - shapeSize / 2);

                canvas.Children.Add(ellipse);

                // Draws point indexes in matrix
                // It's ugly, but that's only for tests
                Label labeldx = new Label
                {
#if _ONE_NUMBERING
                    Content = Array.IndexOf(vertPositions, p) + 1
#endif
                };

                Canvas.SetLeft(labeldx, p.X * canvas.ActualWidth - shapeSize / 2);
                Canvas.SetTop(labeldx, p.Y * canvas.ActualHeight - shapeSize / 2);

                canvas.Children.Add(labeldx);
            }
        }
Exemplo n.º 9
0
        /// <summary>Добавляет визуальный элемент на карту</summary>
        /// <param name="v">Визуальный элемент</param>
        protected void AddVisual(GraphVisual v)
        {
            int index;

            for (index = 0; index < _visuals.Count; index++)
            {
                if (((GraphVisual)_visuals[index]).ZIndex > v.ZIndex)
                {
                    break;
                }
            }

            _visuals.Insert(index, v);
        }
Exemplo n.º 10
0
 public override StateController LeftMouseUpAt(Point point)
 {
     GraphVisual.Canvas.Children.Remove(WorkingLine);
     var(closestEllipse, distance) = GraphVisual.ClosestEllipseFrom(point);
     if (distance < GraphVisual.NodeWidth && closestEllipse != StartingEllipse)
     {
         var startingNode = GraphVisual.Nodes.GetKeyOf(StartingEllipse, ReferenceEquals);
         var endingNode   = GraphVisual.Nodes.GetKeyOf(closestEllipse, ReferenceEquals);
         var edge         = Edge.Create(startingNode, endingNode, Weight);
         if (!GraphVisual.Edges.ContainsKey(edge))
         {
             GraphVisual.AddEdge(edge);
         }
     }
     return(new IdleState(GraphVisual));
 }
Exemplo n.º 11
0
 public GraphCreatorWindow(Action <string> graphPathChosen, Brush nodeBrush, Brush numBrush, Brush lineBrush, PenLineCap penLineCap)
 {
     InitializeComponent();
     this.MinWidth                       = this.MaxWidth = this.Width;
     this.MinHeight                      = this.MaxHeight = this.Height;
     GraphPathChosen                     = graphPathChosen;
     this.GraphVisual                    = GraphVisual.Create(GraphCanvas, nodeBrush, numBrush, lineBrush, penLineCap);
     this.EdgeHandler                    = EdgesHandler.Create(EdgesScrollViewer, GraphVisual.UpdateWeight, _ => GraphUpdated());
     GraphVisual.EdgeAddedEvent         += (sender, args) => EdgeHandler.AddEdge(args.AddedEdge);
     GraphVisual.EdgeRemovedEvent       += (sender, args) => EdgeHandler.RemoveEdge(args.RemovedEdge);
     GraphVisual.EdgeAddedEvent         += (sender, args) => this.GraphUpdated();
     GraphVisual.EdgeRemovedEvent       += (sender, args) => this.GraphUpdated();
     GraphVisual.NodeAmountChangedEvent += (sender, args) => this.GraphUpdated();
     this.StateController                = new IdleState(GraphVisual);
     this.WeightsHandler                 = WeightsHandler.Create(this.ThicknessDictionaryStackPanel,
                                                                 nodeBrush, lineBrush, GraphVisual.NodeWidth, GraphVisual.MinLineThickness, GraphVisual.MaxLineThickness, 0.0, 2.0);
 }
Exemplo n.º 12
0
        public MainViewModel()
        {
            GenerateGraphCommand = new RelayCommand(
                delegate
            {
                EulerPathString = "";

                if (UInt32.TryParse(VertCount, out uint vertCount))
                {
                    graph = new GraphVisual(vertCount, (float)EdgeChance, (10, 10), 50);
                }

                NMatrix = graph.NMatrix;

                DrawGraph();
                SetGraphStateMessage();
                if (graph.IsEuler())
                {
                    SetEulerPathString();
                }
            },
Exemplo n.º 13
0
        public MainWindow()
        {
            initLanguage();
            InitializeComponent();
            mainWindow          = this;
            KeyPreview          = true;
            this.DoubleBuffered = true;
            canvas      = new WFCanvas(plot);
            graph       = new Graph();
            graphVisual = new GraphVisual(canvas, graph);
            graphAlgo   = new GraphAlgo(graph);
            history     = new List <Dictionary <int, Dictionary <int, double> > >();

            subscribe();
            handleAppState();
            if (Properties.Settings.Default.CreateFileAtStartup)
            {
                newFile();
            }
            evalSubtasks();
            // DEBUG_openFile(@"C:\Users\rp-re\OneDrive\Desktop\сова\tsplib\berlin52.tsp");
        }
Exemplo n.º 14
0
 protected StateController(GraphVisual graphVisual)
 {
     GraphVisual = graphVisual;
 }
Exemplo n.º 15
0
 public IdleState(GraphVisual graphVisual) : base(graphVisual)
 {
 }
Exemplo n.º 16
0
 private IMouseEventReceiver SafeGetMouseEventReceiver(GraphVisual Visual)
 {
     return(Visual != null ? Visual.MouseEventReceiver : null);
 }
Exemplo n.º 17
0
 /// <summary>Удаляет визуальный элемент с карты</summary>
 /// <param name="v"></param>
 protected void DeleteVisual(GraphVisual v)
 {
     _visuals.Remove(v);
 }
Exemplo n.º 18
0
 private UIElement PartitionCanvas(GraphPartitionSolution solution, GraphVisual originalGraphVisual, Brush canvasBackground, Dictionary <PartitionType, (Brush, Brush)> lineEdgeBrush, Brush defaultLineBrush)