/// <summary>
 /// 选择元素(可多选)
 /// </summary>
 /// <param name="item"></param>
 protected virtual void SelectItem(DiagramItem item)
 {
     if (Keyboard.Modifiers == ModifierKeys.Control)
     {
         if (item != null)
         {
             if (primaryItem != item && allItem.Contains(item))
             {
                 RemoveSelection(item);
             }
             else
             {
                 AddSelection(item);
             }
         }
     }
     else if (Keyboard.Modifiers == ModifierKeys.Shift)
     {
         if (item != null)
         {
             AddSelection(item);
         }
     }
     else
     {
         if (item != null)
         {
             SetRange(new DiagramItem[] { item });
         }
         else
         {
             DoClear();
         }
     }
 }
 /// <summary>
 /// 选择元素(可多选)
 /// </summary>
 /// <param name="item"></param>
 protected virtual void SelectItem(DiagramItem item)
 {
     //var sel = View.Selection;
     //if (Keyboard.Modifiers == ModifierKeys.Control)
     //{
     //    if (item != null && item.CanSelect)
     //    {
     //        if (item.IsSelected)
     //            sel.Remove(item);
     //        else
     //            sel.Add(item);
     //    }
     //}
     //else if (Keyboard.Modifiers == ModifierKeys.Shift)
     //{
     //    if (item != null && item.CanSelect)
     //        sel.Add(item);
     //}
     //else
     //{
     //    if (item != null && item.CanSelect)
     //        sel.Set(item);
     //    else
     //        sel.Clear();
     //}
 }
 /// <summary>
 /// 移除一个节点
 /// </summary>
 /// <param name="item"></param>
 public void RemoveSelection(DiagramItem item)
 {
     if (allItem.Contains(item))
     {
         allItem.Remove(item);
     }
 }
 public ControlAdorner(DiagramItem item, Control control)
     : base(item)
 {
     this.control        = control;
     control.DataContext = item;
     visuals             = new VisualCollection(this);
     visuals.Add(control);
 }
        /// <summary>
        /// 当鼠标按下时没修改按下元素和按下位置
        /// </summary>
        /// <param name="e"></param>
        public void OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            IInputElement element = sender as IInputElement;

            MouseDownItem  = (e.OriginalSource as DependencyObject).FindParent <DiagramItem>();
            MouseDownPoint = e.GetPosition(element);
            e.Handled      = true;
        }
 /// <summary>
 /// 清除所有选择(内部方法)
 /// </summary>
 private void DoClear()
 {
     foreach (DiagramItem item in allItem)
     {
         item.AllFeature.DoFeatureEvent("DeselectItem");
     }
     allItem.Clear();
     primaryItem = null;
 }
 /// <summary>
 /// 添加一个节点
 /// </summary>
 /// <param name="item"></param>
 public void AddSelection(DiagramItem item)
 {
     if (!allItem.Contains(item))
     {
         bool isPrimary = Count == 0;
         allItem.Add(item);
         if (isPrimary)
         {
             primaryItem = item;
         }
     }
 }
 /// <summary>
 /// 当鼠标移动时触发
 /// 如果选中元素,执行拖动方法
 /// 如果没有选中元素。创建一个选择框
 /// </summary>
 /// <param name="e"></param>
 public void OnMouseMove(object sender, MouseEventArgs e)
 {
     if (e.LeftButton == MouseButtonState.Pressed && MouseDownPoint.HasValue)
     {
         if (MouseDownItem == null)
         {
             (view.AllFeature["AddAdorner"] as AddAdornerFeature).SetPublicAdorner("Drag", CreateRubberbandAdorner((view as DiagramView)));
         }
         MouseDownItem  = null;
         MouseDownPoint = null;
     }
     e.Handled = true;
 }
Beispiel #9
0
        void CreateNode(string elementType, Point p)
        {
            Console.WriteLine("CreateNode");

            string        TestNodeName = allNodes.Count.ToString();
            NodeModelBase nodeModel    = NodeModelBase.GetNodeModel(TestNodeName, elementType);
            DiagramItem   node         = NodeViewModelBase.GetNodeViewModel(nodeModel).GetCompleteNode();

            node.Width  = 100;
            node.Height = 50;
            node.SetValue(Canvas.LeftProperty, p.X - 50);
            node.SetValue(Canvas.TopProperty, p.Y - 25);
            AddNode(TestNodeName, node);
        }
 /// <summary>
 /// 当鼠标移动时触发
 /// 如果选中元素,执行拖动方法
 /// 如果没有选中元素。创建一个选择框
 /// </summary>
 /// <param name="e"></param>
 public virtual void OnMouseMove(MouseEventArgs e)
 {
     if (e.LeftButton == MouseButtonState.Pressed && MouseDownPoint.HasValue)
     {
         if (MouseDownItem != null)
         {
             View.DragTool.BeginDrag(MouseDownPoint.Value, MouseDownItem, DragThumbKinds.Center);
         }
         else
         {
             View.Selection.Clear();
             (View.AllFeature["AddAdorner"] as AddAdornerFeature).SetPublicAdorner("Drag", CreateRubberbandAdorner());
         }
         MouseDownItem  = null;
         MouseDownPoint = null;
     }
     e.Handled = true;
 }
Beispiel #11
0
 /// <summary>
 /// 开始拖拽
 /// </summary>
 /// <param name="start"></param>
 /// <param name="item"></param>
 /// <param name="kind"></param>
 public virtual void BeginDrag(Point start, DiagramItem item, DragThumbKinds kind)
 {
     //this.start = start;
     //DragKind = kind;
     //if (kind == DragThumbKinds.Center)
     //{
     //    if (!item.CanMove || !IsMovable(item))
     //        return;
     //    if (!view.Selection.Contains(item))
     //        view.Selection.Set(item);
     //    DragItems = view.Selection.Where(p => p.CanMove && IsMovable(p)).ToArray();
     //}
     //else
     //{
     //    DragItems = new DiagramItem[] { item };
     //}
     //InitialBounds = DragItems.Select(p => p.Bounds).ToArray();
     //view..DragAdorner = CreateAdorner();
 }
        /// <summary>
        /// 选中事件,可以选中一个或多个
        /// </summary>
        /// <param name="items"></param>
        public void SetRange(IEnumerable <DiagramItem> items)
        {
            DoClear();             //清除所有
            bool isPrimary = true; //第一个节点是主要节点

            foreach (var item in items)
            {
                allItem.Add(item); //将节点添加到字典中;//设为被选中
                if (isPrimary)     //是否为主节点
                {
                    primaryItem = item;
                    item.AllFeature.DoFeatureEvent("SelectedItem", true);
                    isPrimary = false;
                }
                else
                {
                    item.AllFeature.DoFeatureEvent("SelectedItem");
                }
            }
        }
 /// <summary>
 /// 开始拖拽
 /// </summary>
 /// <param name="start"></param>
 /// <param name="item"></param>
 /// <param name="kind"></param>
 public virtual void BeginDrag(Point start, DiagramItem item, DragThumbKinds kind)
 {
     Start    = start;
     DragKind = kind;
     if (kind == DragThumbKinds.Center)
     {
         if (!IsMovable(item))
         {
             return;
         }
         if (!View.Selection.Contains(item))
         {
             View.Selection.Set(item);
         }
         //DragItems = View.Selection.Where(p => p.CanMove && IsMovable(p)).ToArray();
     }
     else
     {
         DragItems = new DiagramItem[] { item };
     }
     InitialBounds = DragItems.Select(p => p.Bounds).ToArray();
     //View.DragAdorner = CreateAdorner();
 }
 /// <summary>
 /// 是否包含某个节点
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 public bool Contains(DiagramItem item)
 {
     return(allItem.Contains(item));
 }
Beispiel #15
0
 public void AddNode(string itemName, DiagramItem item)
 {
     allNodes.Add(itemName, item);
     (view as Canvas).Children.Add(item);
 }
 /// <summary>
 /// 返回对应的元素是否允许拖动
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 protected bool IsMovable(DiagramItem item)
 {
     return(!(item is LinkBase));
 }
 /// <summary>
 /// 当鼠标按下时没修改按下元素和按下位置
 /// </summary>
 /// <param name="e"></param>
 public virtual void OnMouseDown(MouseButtonEventArgs e)
 {
     MouseDownItem  = (e.OriginalSource as DependencyObject).FindParent <DiagramItem>();
     MouseDownPoint = e.GetPosition(View);
     e.Handled      = true;
 }