Пример #1
0
        public void OnPointPositionChanged(node_view top)
        {
            textBox1.Text = edge_weight.ToString();
            if (top == from_node)
            {
                Canvas.SetLeft(Line, from_node.RELPos.X + from_node.GRNode.Width / 2);
                Canvas.SetTop(Line, from_node.RELPos.Y + graphNode.Radius / 2);
            }
            ((Line)Line).X2 = to_node.RELPos.X - from_node.RELPos.X;
            ((Line)Line).Y2 = to_node.RELPos.Y - from_node.RELPos.Y;
            Canvas.SetLeft(textBox1, from_node.RELPos.X + from_node.GRNode.Width / 2 + ((Line)Line).X2 / 2 - textBox1.Width / 2);
            Canvas.SetTop(textBox1, from_node.RELPos.Y + ((Line)Line).Y2 / 2 - textBox1.FontSize / 3);

            double u_l = Math.Atan2(((Line)Line).X1 - ((Line)Line).X2, ((Line)Line).Y1 - ((Line)Line).Y2);
            double u   = Math.PI / 33;

            LeftLine.StrokeThickness  = 1;
            RightLine.StrokeThickness = 1;
            LeftLine.X1 = ((Line)Line).X2 + 10 * Math.Sin(u_l);
            LeftLine.Y1 = ((Line)Line).Y2 + 10 * Math.Cos(u_l);
            LeftLine.X2 = ((Line)Line).X2 + 30 * Math.Sin(u_l + 2 * u);
            LeftLine.Y2 = ((Line)Line).Y2 + 30 * Math.Cos(u_l + 2 * u);

            RightLine.X1 = ((Line)Line).X2 + 10 * Math.Sin(u_l);
            RightLine.Y1 = ((Line)Line).Y2 + 10 * Math.Cos(u_l);
            RightLine.X2 = ((Line)Line).X2 + 30 * Math.Sin(u_l - 2 * u);
            RightLine.Y2 = ((Line)Line).Y2 + 30 * Math.Cos(u_l - 2 * u);

            Canvas.SetLeft(LeftLine, from_node.RELPos.X + to_node.GRNode.Width / 2);
            Canvas.SetTop(LeftLine, from_node.RELPos.Y + graphNode.Radius / 2);
            Canvas.SetLeft(RightLine, from_node.RELPos.X + to_node.GRNode.Width / 2);
            Canvas.SetTop(RightLine, from_node.RELPos.Y + graphNode.Radius / 2);
        }
Пример #2
0
        public void AddEdge(int index_from, int index_to, string weight, bool generate)
        {
            node_view from_node = TopList[index_from];
            node_view to_node   = TopList[index_to];
            bool      isExist   = false;

            foreach (edge_view line0 in edgeList)
            {
                if ((line0.From == from_node && line0.To == to_node) || (line0.To == from_node && line0.From == to_node))
                {
                    if (!generate)
                    {
                        MessageBox.Show("Дуга вже існує");
                    }

                    else
                    {
                        line0.Weight = line0.Weight + int.Parse(weight);
                    }
                    isExist = true;
                }
            }
            if (!isExist)
            {
                if (weight == "0")
                {
                    weight = "1";
                }
                edge_view line = new edge_view(this, from_node, to_node, weight);
                edgeList.Add(line);
                FirstTop = null;
                EndAddEdge();
            }
        }
Пример #3
0
 public void AddTop(bool center)
 {
     node_view top = new node_view(this);          
     if (center)
         top.CNTRPosition();
     else
         OnPointPositionChanged(top);
 }
Пример #4
0
 public edge_view(graph_view _graph, node_view from_node, node_view to_node, string weight)
 {
     this._graph = _graph;
     if (from_node != to_node)
     {
         Line                      = new Line();
         Line.MouseEnter          += new MouseEventHandler(Line_MouseEnter);
         Line.MouseLeave          += new MouseEventHandler(Line_MouseLeave);
         Line.MouseLeftButtonDown += new MouseButtonEventHandler(Line_MouseLeftButtonDown);
         Line.Stroke               = Brushes.Black;
         Line.StrokeThickness      = 1;
         ((Line)Line).X1           = 0;
         ((Line)Line).Y1           = 0;
         LeftLine                  = new Line();
         RightLine                 = new Line();
         RightLine.Stroke          = LeftLine.Stroke = Brushes.Black;
         RightLine.StrokeThickness = LeftLine.StrokeThickness = 6;
         _graph.GRCanvas.Children.Add(LeftLine);
         _graph.GRCanvas.Children.Add(RightLine);
         if (Lines == null)
         {
             Lines = new List <Shape>();
             Lines.Add(Line);
             Lines.Add(LeftLine);
             Lines.Add(RightLine);
         }
         textBox1             = new TextBox();
         textBox1.Width       = 50;
         br                   = new SolidColorBrush(Colors.Transparent);
         textBox1.BorderBrush = br;
         textBox1.VerticalContentAlignment   = VerticalAlignment.Center;
         textBox1.HorizontalContentAlignment = HorizontalAlignment.Center;
         textBox1.FontSize = 14;
         TxtBox1_TextChanged(null, null);
         textBox1.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(TxtBox1_PreviewMouseLeftButtonDown);
         textBox1.TextChanged += new TextChangedEventHandler(TxtBox1_TextChanged);
         textBox1.Text         = weight;
         edge_weight           = int.Parse(textBox1.Text);
         opaqueBrush           = new SolidColorBrush(Colors.Black);
         opaqueBrush.Opacity   = 0;
         textBox1.Background   = opaqueBrush;
         _graph.GRCanvas.Children.Add(textBox1);
         _graph.GRCanvas.Children.Add(Line);
         Canvas.SetZIndex(Line, 0);
         Canvas.SetZIndex(textBox1, 2);
         this.from_node = from_node;
         this.to_node   = to_node;
         to_node.pointPositionChange   += new graph_view.PointPositionChanged(OnPointPositionChanged);
         from_node.pointPositionChange += new graph_view.PointPositionChanged(OnPointPositionChanged);
         OnPointPositionChanged(to_node);
         OnPointPositionChanged(from_node);
     }
     else
     {
         MessageBox.Show("Граф задачі має бути ациклічним!");
     }
 }
Пример #5
0
 public edge_view(graph_view _graph, node_view from_node, node_view to_node, string weight)
 {
     this._graph = _graph;
     if (from_node != to_node)
     {
         Line = new Line(); 
         Line.MouseEnter += new MouseEventHandler(Line_MouseEnter);
         Line.MouseLeave += new MouseEventHandler(Line_MouseLeave);
         Line.MouseLeftButtonDown += new MouseButtonEventHandler(Line_MouseLeftButtonDown);
         Line.Stroke = Brushes.Black;
         Line.StrokeThickness = 1;
         ((Line)Line).X1 = 0;
         ((Line)Line).Y1 = 0;
             LeftLine = new Line();
             RightLine = new Line();
             RightLine.Stroke = LeftLine.Stroke = Brushes.Black;
             RightLine.StrokeThickness = LeftLine.StrokeThickness = 6;
             _graph.GRCanvas.Children.Add(LeftLine);
             _graph.GRCanvas.Children.Add(RightLine);
         if (Lines == null)
         {
             Lines = new List<Shape>();
             Lines.Add(Line);
                 Lines.Add(LeftLine);
                 Lines.Add(RightLine);
         }
         textBox1 = new TextBox();
         textBox1.Width = 50;
         br = new SolidColorBrush(Colors.Transparent);
         textBox1.BorderBrush = br;
         textBox1.VerticalContentAlignment = VerticalAlignment.Center;
         textBox1.HorizontalContentAlignment = HorizontalAlignment.Center;
         textBox1.FontSize = 14;
         TxtBox1_TextChanged(null, null);
         textBox1.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(TxtBox1_PreviewMouseLeftButtonDown);
         textBox1.TextChanged += new TextChangedEventHandler(TxtBox1_TextChanged);
         textBox1.Text = weight;
         edge_weight = int.Parse(textBox1.Text);
         opaqueBrush = new SolidColorBrush(Colors.Black);
         opaqueBrush.Opacity = 0;
         textBox1.Background = opaqueBrush;
         _graph.GRCanvas.Children.Add(textBox1);
         _graph.GRCanvas.Children.Add(Line);
         Canvas.SetZIndex(Line, 0);
         Canvas.SetZIndex(textBox1, 2);
         this.from_node = from_node;
         this.to_node = to_node;
         to_node.pointPositionChange += new graph_view.PointPositionChanged(OnPointPositionChanged);
         from_node.pointPositionChange += new graph_view.PointPositionChanged(OnPointPositionChanged);
         OnPointPositionChanged(to_node);
         OnPointPositionChanged(from_node);
     }
     else
         MessageBox.Show("Граф задачі має бути ациклічним!");            
 }
Пример #6
0
 public void DeleteNode(node_view top)
 {
     if (TopList.Contains(top))
     {
         for (int i = edgeList.Count-1; i >=0; i--)
             if (edgeList[i].From == top || edgeList[i].To == top)
                 DeleteEdge(edgeList[i]);
         TopList.Remove(top);
         canvas.Children.Remove(top.View);
     }
 }
Пример #7
0
 public graphNode(node_view parentView)
 {
     InitializeComponent();
     this.parentView = parentView;
     Canvas.SetZIndex(this, 2);
     this.point.Width = this.point.Height = NodeRadius;
     opaqueBrush = new SolidColorBrush(Colors.Black);
     opaqueBrush.Opacity = 0;
     Canvas.SetZIndex(txtWeight_node, 2);
     txtWeight_node.Background = opaqueBrush;
 }
Пример #8
0
        public void AddTop(bool center)
        {
            node_view top = new node_view(this);

            if (center)
            {
                top.CNTRPosition();
            }
            else
            {
                OnPointPositionChanged(top);
            }
        }
Пример #9
0
 public void DeleteNode(node_view top)
 {
     if (TopList.Contains(top))
     {
         for (int i = edgeList.Count - 1; i >= 0; i--)
         {
             if (edgeList[i].From == top || edgeList[i].To == top)
             {
                 DeleteEdge(edgeList[i]);
             }
         }
         TopList.Remove(top);
         canvas.Children.Remove(top.View);
     }
 }
Пример #10
0
        public void AddEdge(node_view from_node, node_view to_node)
        {
            bool isExist = false;

            foreach (edge_view line0 in edgeList)
            {
                if ((line0.From == from_node && line0.To == to_node) || (line0.To == from_node && line0.From == to_node))
                {
                    MessageBox.Show("Дуга вже існує");
                    isExist = true;
                }
            }
            if (!isExist)
            {
                edge_view line = new edge_view(this, from_node, to_node, "1");
                edgeList.Add(line);
                FirstTop = null;
                EndAddEdge();
            }
        }
Пример #11
0
 public void AddEdge(int index_from, int index_to, string weight, bool generate)
 {
     node_view from_node = TopList[index_from];
     node_view to_node = TopList[index_to];
     bool isExist = false;
     foreach (edge_view line0 in edgeList)
     {
         if ((line0.From == from_node && line0.To == to_node) || (line0.To == from_node && line0.From == to_node))
         {
             if (!generate)
                 MessageBox.Show("Дуга вже існує");
                 
             else
                 line0.Weight = line0.Weight + int.Parse(weight);
             isExist = true;
         }
     }
     if (!isExist)
     {
         if (weight == "0")
             weight = "1";
         edge_view line = new edge_view(this, from_node, to_node, weight);
         edgeList.Add(line);
         FirstTop = null;
         EndAddEdge();
     }
 }
Пример #12
0
 public void EndAddEdge()
 {
     edgeAdd = false;
     FirstTop = null;
 }
Пример #13
0
 public void OnPointPositionChanged(node_view top)
 {
     top.UpdPos();
     Canvas.SetLeft(top.GRNode, top.RELPos.X);
     Canvas.SetTop(top.GRNode, top.RELPos.Y);
 }
Пример #14
0
 public void AddEdge(node_view from_node, node_view to_node)
 {
     bool isExist = false;
     foreach (edge_view line0 in edgeList)
         if ((line0.From == from_node && line0.To == to_node) || (line0.To == from_node && line0.From == to_node))
         {
             MessageBox.Show("Дуга вже існує");
             isExist = true;
         }
     if (!isExist)
     {
         edge_view line = new edge_view(this, from_node, to_node, "1");
         edgeList.Add(line);
         FirstTop = null;
         EndAddEdge();
     }
 }
Пример #15
0
 public void AddTop(double X, double Y, string name)
 {
     node_view top = new node_view(this);
     top.GivenPosition(X, Y, name);
 }
Пример #16
0
 public void AddTop(double X, double Y, string id, string weight)
 {
     node_view top = new node_view(this);
     top.GivenPosition(X, Y, id, weight);
 }
Пример #17
0
        public void AddTop(double X, double Y, string name)
        {
            node_view top = new node_view(this);

            top.GivenPosition(X, Y, name);
        }
Пример #18
0
        public void AddTop(double X, double Y, string id, string weight)
        {
            node_view top = new node_view(this);

            top.GivenPosition(X, Y, id, weight);
        }
Пример #19
0
 public void EndAddEdge()
 {
     edgeAdd  = false;
     FirstTop = null;
 }
Пример #20
0
 public void OnPointPositionChanged(node_view top)
 {
     top.UpdPos();
     Canvas.SetLeft(top.GRNode, top.RELPos.X);
     Canvas.SetTop(top.GRNode, top.RELPos.Y);
 }
Пример #21
0
        public void OnPointPositionChanged(node_view top)
        {
            textBox1.Text = edge_weight.ToString();
                if (top == from_node)
                {
                    Canvas.SetLeft(Line, from_node.RELPos.X + from_node.GRNode.Width / 2);
                    Canvas.SetTop(Line, from_node.RELPos.Y + graphNode.Radius / 2);
                }
                ((Line)Line).X2 = to_node.RELPos.X - from_node.RELPos.X;
                ((Line)Line).Y2 = to_node.RELPos.Y - from_node.RELPos.Y;
                Canvas.SetLeft(textBox1, from_node.RELPos.X + from_node.GRNode.Width / 2 + ((Line)Line).X2 / 2 - textBox1.Width/2);
                Canvas.SetTop(textBox1, from_node.RELPos.Y + ((Line)Line).Y2 / 2 - textBox1.FontSize / 3);

                    double u_l = Math.Atan2(((Line)Line).X1 - ((Line)Line).X2, ((Line)Line).Y1 - ((Line)Line).Y2);
                   double u = Math.PI / 33;

                   LeftLine.StrokeThickness = 1;
                   RightLine.StrokeThickness = 1;
                   LeftLine.X1 = ((Line)Line).X2 + 10 * Math.Sin(u_l);
                   LeftLine.Y1 = ((Line)Line).Y2 + 10 * Math.Cos(u_l);
                   LeftLine.X2 = ((Line)Line).X2 + 30 * Math.Sin(u_l + 2 * u);
                   LeftLine.Y2 = ((Line)Line).Y2 + 30 * Math.Cos(u_l + 2 * u);

                   RightLine.X1 = ((Line)Line).X2 + 10 * Math.Sin(u_l);
                   RightLine.Y1 = ((Line)Line).Y2 + 10 * Math.Cos(u_l);
                   RightLine.X2 = ((Line)Line).X2 + 30 * Math.Sin(u_l - 2 * u);
                   RightLine.Y2 = ((Line)Line).Y2 + 30 * Math.Cos(u_l - 2 * u);

                   Canvas.SetLeft(LeftLine, from_node.RELPos.X + to_node.GRNode.Width / 2);
                   Canvas.SetTop(LeftLine, from_node.RELPos.Y + graphNode.Radius / 2);
                   Canvas.SetLeft(RightLine, from_node.RELPos.X + to_node.GRNode.Width / 2);
                   Canvas.SetTop(RightLine, from_node.RELPos.Y + graphNode.Radius / 2);
        }