示例#1
0
        /// <summary>
        /// 删除线
        /// </summary>
        /// <param name="model"></param>
        private void DeleteLine(MDF_ConnectLineModel model)
        {
            if (canvasLine == null)
            {
                return;
            }

            if (model == null)
            {
                return;
            }

            MDF_Line line = canvasLine.Children.FirstOrDefault(p => ((p as FrameworkElement).DataContext as MDF_ConnectLineModel) == model) as MDF_Line;

            if (line == null)
            {
                return;
            }

            if (LineCheck != null && !LineCheck.DeleckLine(model))
            {
                return;
            }

            line.LineSelected -= line_LineSelected;
            canvasLine.Children.Remove(line);

            LineSource.Remove(model);
        }
示例#2
0
        private MDF_Line CreateLine(MDF_ConnectLineModel linemodel)
        {
            if (canvasLine == null)
            {
                return(null);
            }

            if (LineSource == null)
            {
                return(null);
            }

            if (m_dicitem.Where(p => p.Key == linemodel.From).Count() == 0)
            {
                return(null);
            }

            if (m_dicitem.Where(p => p.Key == linemodel.To).Count() == 0)
            {
                return(null);
            }

            ConnectItem from = m_dicitem[linemodel.From];
            ConnectItem to   = m_dicitem[linemodel.To];

            if (from == null || to == null)
            {
                return(null);
            }

            if (LineCheck != null)
            {
                if (!LineCheck.AddLineCheck(from.DataContext as MDF_ConnectItemModel, to.DataContext as MDF_ConnectItemModel))
                {
                    return(null);
                }
            }

            //判断是否已存在,如果存在则执行创建线
            var v = canvasLine.Children.FirstOrDefault(p => ((p as MDF_Line).DataContext as MDF_ConnectLineModel).From == linemodel.From &&
                                                       ((p as MDF_Line).DataContext as MDF_ConnectLineModel).To == linemodel.To);

            if (v != null)
            {
                return(null);
            }

            MDF_Line line = new MDF_Line();

            line.SetBinding(MDF_Line.StyleProperty, new Binding()
            {
                Source = this, Path = new PropertyPath("LineStyle")
            });
            line.DataContext = linemodel;
            canvasLine.Children.Add(line);
            ComputeLineInfo(line);
            line.LineSelected += line_LineSelected;

            return(line);
        }
示例#3
0
        private void SetLineSelected(MDF_ConnectLineModel model, MDF_ConnectLineModel oldvalue)
        {
            if (oldvalue != null)
            {
                MDF_Line oldline = canvasLine.Children.FirstOrDefault(p => ((p as MDF_Line).DataContext as MDF_ConnectLineModel) == oldvalue) as MDF_Line;
                if (oldline != null)
                {
                    oldline.Selected = false;
                }
            }

            if (model == null)
            {
                return;
            }

            if (canvasLine == null)
            {
                return;
            }
            MDF_Line line = canvasLine.Children.FirstOrDefault(p => ((p as MDF_Line).DataContext as MDF_ConnectLineModel) == model) as MDF_Line;

            if (line == null)
            {
                return;
            }

            line.Selected = true;
        }
示例#4
0
        //计算线位置
        private void ComputeLineInfo(MDF_Line line)
        {
            if (line == null)
            {
                return;
            }

            MDF_ConnectLineModel model = line.DataContext as MDF_ConnectLineModel;

            if (model == null)
            {
                return;
            }

            if (gridMain == null || canvasLine == null)
            {
                return;
            }

            if (m_dicitem.Count == 0)
            {
                return;
            }

            if (m_dicitem.Keys.Contains(model.From) && m_dicitem.Keys.Contains(model.To))
            {
                ConnectItem from = m_dicitem[model.From];
                ConnectItem to   = m_dicitem[model.To];
                if (from == null || to == null)
                {
                    return;
                }

                //计算控件坐标点

                if (from.ActualHeight == 0)
                {
                    return;
                }

                if (canvasLine.ActualHeight == 0)
                {
                    return;
                }

                List <Point> pfromlist = SLControlUnity.GetControlPointLeftRight(canvasLine, from);
                List <Point> ptolist   = SLControlUnity.GetControlPointLeftRight(canvasLine, to);

                Tuple <Point, Point> nearpoint = SLControlUnity.ComplateNearPoint(pfromlist, ptolist); //得到最近两个点
                double len   = SLControlUnity.Distance(nearpoint.Item1, nearpoint.Item2);              //得到两点最近距离
                double angle = SLControlUnity.SlopeAngle(nearpoint.Item1, nearpoint.Item2);            //计算两点倾斜角度

                Canvas.SetLeft(line, nearpoint.Item1.X);
                Canvas.SetTop(line, nearpoint.Item1.Y - line.ActualHeight / 2);
                line.Width = len;

                CompositeTransform transform = line.RenderTransform as CompositeTransform;
                if (transform == null)
                {
                    transform            = new CompositeTransform();
                    line.RenderTransform = transform;
                }

                line.RenderTransformOrigin = new Point(0, 0.5);
                //transform.CenterX = 0;
                //transform.CenterY = 0.5;
                transform.Rotation = angle;
            }
        }