コード例 #1
0
        /// <summary>
        /// Select nearby conenctions
        /// </summary>
        /// <param name="e"></param>
        private bool SelectNearLine(MouseButtonEventArgs e)
        {
            var paths = VisualHelper.FindVisualChildren <Path>(this);
            var mouseNeighbourhood = Helper.CreateCenteredRect(e.GetPosition(CanvasItemContainer), new Size(10, 10));

            foreach (Path path in paths)
            {
                if (path.Name == "ConnectionPath")
                {
                    ElementsConnectionViewModel viewModel = path.DataContext as ElementsConnectionViewModel;
                    if (viewModel != null)
                    {
                        List <Rect> rects = Helper.GetPathRects(viewModel);
                        foreach (Rect rect in rects)
                        {
                            if (mouseNeighbourhood.IntersectsWith(rect))
                            {
                                if (e.ChangedButton == MouseButton.Left)
                                {
                                    viewModel.Select();
                                }
                                else if (e.ChangedButton == MouseButton.Right)
                                {
                                    viewModel.IsContextMenuOpened = true;
                                }
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }
コード例 #2
0
        public Hook(Point start, Point end, ElementsConnectionViewModel parent)
        {
            double x = (start.X + end.X) / 2;
            double y = (start.Y + end.Y) / 2;

            _parent = parent;

            OriginalStartPoint = start;
            OriginalEndPoint   = end;

            StartPoint  = start;
            EndPoint    = end;
            HookPoint   = new Point(x, y);
            Orientation = GetOrientation(start, end);
        }
コード例 #3
0
        public static List <Rect> GetPathRects(ElementsConnectionViewModel connection)
        {
            var          rects  = new List <Rect>();
            List <Point> points = new List <Point>()
            {
                connection.StartPoint
            };

            points.AddRange(connection.Points);
            points.Add(connection.EndPoint);
            for (int i = 1; i < points.Count; i++)
            {
                var  startPoint = points[i - 1];
                var  endPoint   = points[i];
                Rect lineRect   = new Rect(startPoint, endPoint);
                rects.Add(lineRect);
            }
            return(rects);
        }
コード例 #4
0
ファイル: ModelHelper.cs プロジェクト: jablko359/BpmnEditor
 public static void AddModelConnection(ElementsConnectionViewModel connection)
 {
     try
     {
         PoolElementViewModel startElementViewModel = connection.From as PoolElementViewModel;
         PoolViewModel        poolElementViewModel  = startElementViewModel.Pool;
         PoolElement          pool = null;
         if (poolElementViewModel != null)
         {
             pool = startElementViewModel.Pool.BaseElement as PoolElement;
         }
         else
         {
             pool = startElementViewModel.Document.Document.MainPoolElement;
         }
         pool.Connections.Add(connection.Model);
     }
     catch (NullReferenceException exception)
     {
         throw new ArgumentException("Error while creating connection. Model not found", exception);
     }
 }