Exemple #1
0
 // метод, добавляющий связанные с окном стрелки в массив
 public void addLinkingArrowsInList(MyArrow line)
 {
     if (Math.Abs(line.getPoint2().X - (this.border.Margin.Left + this.border.Width / 2)) < Config.getRadius() && Math.Abs(line.getPoint2().Y - this.border.Margin.Top) < Config.getRadius())
     {
         linkArrows.Add(new LinkArrow(false, line, 'T'));
     }
     else if (Math.Abs(line.getPoint2().X - (border.Margin.Left + border.Width / 2)) < Config.getRadius() && Math.Abs(line.getPoint2().Y - (border.Margin.Top + border.Height)) < Config.getRadius())
     {
         linkArrows.Add(new LinkArrow(false, line, 'B'));
     }
     else if (Math.Abs(line.getPoint1().X - (border.Margin.Left + border.Width / 2)) < Config.getRadius() && Math.Abs(line.getPoint1().Y - border.Margin.Top) < Config.getRadius())
     {
         linkArrows.Add(new LinkArrow(true, line, 'T'));
     }
     else if (Math.Abs(line.getPoint1().X - (border.Margin.Left + border.Width / 2)) < Config.getRadius() && Math.Abs(line.getPoint1().Y - (border.Margin.Top + border.Height)) < Config.getRadius())
     {
         linkArrows.Add(new LinkArrow(true, line, 'B'));
     }
     else if (Math.Abs(line.getPoint1().X - border.Margin.Left) < Config.getRadius() && Math.Abs(line.getPoint1().Y - (border.Margin.Top + border.Height / 2)) < Config.getRadius())
     {
         linkArrows.Add(new LinkArrow(true, line, 'L'));
     }
     else if (Math.Abs(line.getPoint1().X - (border.Margin.Left + border.Width)) < Config.getRadius() && Math.Abs(line.getPoint1().Y - (border.Margin.Top + border.Height / 2)) < Config.getRadius())
     {
         linkArrows.Add(new LinkArrow(true, line, 'R'));
     }
     else if (Math.Abs(line.getPoint2().X - border.Margin.Left) < Config.getRadius() && Math.Abs(line.getPoint2().Y - (border.Margin.Top + border.Height / 2)) < Config.getRadius())
     {
         linkArrows.Add(new LinkArrow(false, line, 'L'));
     }
     else if (Math.Abs(line.getPoint2().X - (border.Margin.Left + border.Width)) < Config.getRadius() && Math.Abs(line.getPoint2().Y - (border.Margin.Top + border.Height / 2)) < Config.getRadius())
     {
         linkArrows.Add(new LinkArrow(false, line, 'R'));
     }
 }
Exemple #2
0
        // статический метод, соединяющий две стрелки
        public static bool concateLines(MyArrow firstLine, MyArrow secondLine)
        {
            bool result = false;

            if (Math.Abs(firstLine.getPoint2().X - secondLine.getPoint2().X) < Config.getRadius() && Math.Abs(firstLine.getPoint2().Y - secondLine.getPoint2().Y) < Config.getRadius())
            {
                firstLine.setPoint2(secondLine.getPoint2().X + Config.getMarginLeftPanel(), secondLine.getPoint2().Y + Config.getMarginTopPanel());
                result = true;
            }
            else if (Math.Abs(firstLine.getPoint2().X - secondLine.getPoint1().X) < Config.getRadius() && Math.Abs(firstLine.getPoint2().Y - secondLine.getPoint1().Y) < Config.getRadius())
            {
                firstLine.setPoint2(secondLine.getPoint1().X + Config.getMarginLeftPanel(), secondLine.getPoint1().Y + Config.getMarginTopPanel());
                result = true;
            }
            else if (Math.Abs(firstLine.getPoint1().X - secondLine.getPoint1().X) < Config.getRadius() && Math.Abs(firstLine.getPoint1().Y - secondLine.getPoint1().Y) < Config.getRadius())
            {
                firstLine.setPoint1(secondLine.getPoint1().X + Config.getMarginLeftPanel(), secondLine.getPoint1().Y + Config.getMarginTopPanel());
                result = true;
            }
            else if (Math.Abs(firstLine.getPoint1().X - secondLine.getPoint2().X) < Config.getRadius() && Math.Abs(firstLine.getPoint1().Y - secondLine.getPoint2().Y) < Config.getRadius())
            {
                firstLine.setPoint1(secondLine.getPoint2().X + Config.getMarginLeftPanel(), secondLine.getPoint2().Y + Config.getMarginTopPanel());
                result = true;
            }
            return(result);
        }
        // Событие при котором отпустили кнопку мыши на поле для рисования
        private void drawPanel_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (indexCurrentArrow != -1)
            {
                // Если по близости с линией, которую только что перетаскивали есть
                // другие линии, то соединяем их
                foreach (MyArrow line in myArrows)
                {
                    if (!line.equalName(myArrows[indexCurrentArrow].name()))
                    {
                        MyArrow.concateLines(myArrows[indexCurrentArrow], line);
                    }
                }

                int count = 0;
                // Если по близости с линией, которую только что перетаскивали есть
                // окна, то соединяем их
                foreach (MyWindow window in myWindows)
                {
                    if (window.concateWindowWithLine(myArrows[indexCurrentArrow]))
                    {
                        ++count;
                    }

                    if (count >= 2)
                    {
                        break;
                    }
                }
            }
        }
Exemple #4
0
        // метод, соединяющий окно с линией
        public bool concateWindowWithLine(MyArrow line)
        {
            bool result = false;

            if (Math.Abs(line.getPoint2().X - (this.border.Margin.Left + this.border.Width / 2)) < Config.getRadius() && Math.Abs(line.getPoint2().Y - this.border.Margin.Top) < Config.getRadius())
            {
                line.setPoint2(this.border.Margin.Left + this.border.Width / 2 + Config.getMarginLeftPanel(), this.border.Margin.Top + Config.getMarginTopPanel());
                result = true;
            }
            else if (Math.Abs(line.getPoint2().X - (border.Margin.Left + border.Width / 2)) < Config.getRadius() && Math.Abs(line.getPoint2().Y - (border.Margin.Top + border.Height)) < Config.getRadius())
            {
                line.setPoint2(this.border.Margin.Left + this.border.Width / 2 + Config.getMarginLeftPanel(), this.border.Margin.Top + this.border.Height + Config.getMarginTopPanel());
                result = true;
            }
            else if (Math.Abs(line.getPoint1().X - (border.Margin.Left + border.Width / 2)) < Config.getRadius() && Math.Abs(line.getPoint1().Y - border.Margin.Top) < Config.getRadius())
            {
                line.setPoint1(this.border.Margin.Left + this.border.Width / 2 + Config.getMarginLeftPanel(), this.border.Margin.Top + Config.getMarginTopPanel());
                result = true;
            }
            else if (Math.Abs(line.getPoint1().X - (border.Margin.Left + border.Width / 2)) < Config.getRadius() && Math.Abs(line.getPoint1().Y - (border.Margin.Top + border.Height)) < Config.getRadius())
            {
                line.setPoint1(this.border.Margin.Left + border.Width / 2 + Config.getMarginLeftPanel(), this.border.Margin.Top + border.Height + Config.getMarginTopPanel());
                result = true;
            }
            else if (Math.Abs(line.getPoint1().X - border.Margin.Left) < Config.getRadius() && Math.Abs(line.getPoint1().Y - (border.Margin.Top + border.Height / 2)) < Config.getRadius())
            {
                line.setPoint1(this.border.Margin.Left + Config.getMarginLeftPanel(), this.border.Margin.Top + border.Height / 2 + Config.getMarginTopPanel());
                result = true;
            }
            else if (Math.Abs(line.getPoint1().X - (border.Margin.Left + border.Width)) < Config.getRadius() && Math.Abs(line.getPoint1().Y - (border.Margin.Top + border.Height / 2)) < Config.getRadius())
            {
                line.setPoint1(this.border.Margin.Left + border.Width + Config.getMarginLeftPanel(), this.border.Margin.Top + border.Height / 2 + Config.getMarginTopPanel());
                result = true;
            }
            else if (Math.Abs(line.getPoint2().X - border.Margin.Left) < Config.getRadius() && Math.Abs(line.getPoint2().Y - (border.Margin.Top + border.Height / 2)) < Config.getRadius())
            {
                line.setPoint2(this.border.Margin.Left + Config.getMarginLeftPanel(), this.border.Margin.Top + border.Height / 2 + Config.getMarginTopPanel());
                result = true;
            }
            else if (Math.Abs(line.getPoint2().X - (border.Margin.Left + border.Width)) < Config.getRadius() && Math.Abs(line.getPoint2().Y - (border.Margin.Top + border.Height / 2)) < Config.getRadius())
            {
                line.setPoint2(this.border.Margin.Left + border.Width + Config.getMarginLeftPanel(), this.border.Margin.Top + border.Height / 2 + Config.getMarginTopPanel());
                result = true;
            }

            return(result);
        }
Exemple #5
0
 // конструктор класса
 public LinkArrow(bool indexSide, MyArrow line, char location)
 {
     this.indexSide = indexSide;
     this.line      = line;
     this.location  = location;
 }
        // Событие DragAndDrop (когда отпускают кнопку мыши при перетаскивании объекта)
        private void drawPanel_Drop(object sender, DragEventArgs e)
        {
            string[] str = (string[])e.Data.GetFormats();
            // Если перетаскивали стрелку
            if (str[0] == "System.Windows.Shapes.Line")
            {
                Line   line   = (Line)e.Data.GetData("System.Windows.Shapes.Line");
                Canvas canvas = (Canvas)line.Parent;

                Line newLine             = MyArrow.copyLine(line, nameArrow + myArrows.Count, e.GetPosition(this));
                Line newEndDistantLine   = MyArrow.patternEndDistantLine(newLine);
                Line newBeginDistantLine = MyArrow.patternBeginDistantLine(newLine);

                // Если стрелка первого типа, создаем её шаблон
                if (line.Name == "Arrow_type_1")
                {
                    Line newEndNearLine   = MyArrow.patternEndNearLine(newLine);
                    Line newBeginNearLine = MyArrow.patternBeginNearLine(newLine);
                    myArrows.Add(new MyArrowType1(newLine, newEndDistantLine, newBeginDistantLine, newEndNearLine, newBeginNearLine));
                    drawPanel.Children.Add(newEndNearLine);
                    drawPanel.Children.Add(newBeginNearLine);
                    Canvas.SetZIndex(newEndNearLine, 0);
                    Canvas.SetZIndex(newBeginNearLine, 0);
                }
                // Если стрелка второго типа, создаем её шаблон
                else if (line.Name == "Arrow_type_2")
                {
                    Polyline newPolyline      = MyArrow.patternEndPolyline(newLine);
                    Line     newBeginNearLine = MyArrow.patternBeginNearLine(newLine);
                    myArrows.Add(new MyArrowType2(newLine, newEndDistantLine, newBeginDistantLine, newBeginNearLine, newPolyline));
                    drawPanel.Children.Add(newPolyline);
                    drawPanel.Children.Add(newBeginNearLine);
                    Canvas.SetZIndex(newPolyline, 0);
                    Canvas.SetZIndex(newBeginNearLine, 0);
                }
                // Если стрелка третьего типа, создаем её шаблон
                else if (line.Name == "Arrow_type_3")
                {
                    Polyline newEndPolyline   = MyArrow.patternEndPolyline(newLine);
                    Polyline newBeginPolyline = MyArrow.patternBeginPolyline(newLine);
                    myArrows.Add(new MyArrowType3(newLine, newEndDistantLine, newBeginDistantLine, newEndPolyline, newBeginPolyline));
                    drawPanel.Children.Add(newEndPolyline);
                    drawPanel.Children.Add(newBeginPolyline);
                    Canvas.SetZIndex(newEndPolyline, 0);
                    Canvas.SetZIndex(newBeginPolyline, 0);
                }

                drawPanel.Children.Add(newLine);
                drawPanel.Children.Add(newEndDistantLine);
                drawPanel.Children.Add(newBeginDistantLine);
                Canvas.SetZIndex(newLine, 0);
                Canvas.SetZIndex(newEndDistantLine, 0);
                Canvas.SetZIndex(newBeginDistantLine, 0);
            }
            // Если перетаскивали окно, создаем его шаблон
            else if (str[0] == "System.Windows.Controls.Border")
            {
                Border border    = (Border)e.Data.GetData("System.Windows.Controls.Border");
                Border newBorder = copyBorder(border, e.GetPosition(this));
                myWindows.Add(new MyWindow(newBorder));
                drawPanel.Children.Add(newBorder);
                Canvas.SetZIndex(newBorder, 3);
                Canvas.SetZIndex(newBorder.Child, 2);
            }
        }