Exemplo n.º 1
0
 public override void UpdateEdge(bool updateLabel = true)
 {
     if (!ShowArrows)
     {
         if (EdgePointerForTarget != null)
         {
             EdgePointerForTarget?.Hide();
             EdgePointerForTarget = null;
         }
         if (EdgePointerForSource != null)
         {
             EdgePointerForSource?.Hide();
             EdgePointerForSource = null;
         }
     }
     base.UpdateEdge(updateLabel);
     if (((VisualEdge)Edge).Edge.Weight == null)
     {
         EdgeLabelControl?.Hide();
     }
     else
     {
         EdgeLabelControl?.Show();
     }
 }
Exemplo n.º 2
0
        public override void Clean()
        {
            Source   = null;
            Target   = null;
            Edge     = null;
            RootArea = null;
            HighlightBehaviour.SetIsHighlightEnabled(this, false);
            DragBehaviour.SetIsDragEnabled(this, false);
            Linegeometry      = null;
            LinePathObject    = null;
            SelfLoopIndicator = null;
            EdgeLabelControls.ForEach(l => l.Dispose());
            EdgeLabelControls.Clear();

            if (EdgePointerForSource != null)
            {
                EdgePointerForSource.Dispose();
                EdgePointerForSource = null;
            }
            if (EdgePointerForTarget != null)
            {
                EdgePointerForTarget.Dispose();
                EdgePointerForTarget = null;
            }
            EventOptions?.Clean();
        }
        public override void Clean()
        {
            //TODO rename to _sourceWatcher _targetWatcher
            if (_sourceWatcher != null)
            {
                _sourceWatcher.Dispose();
            }
            if (_targetWatcher != null)
            {
                _targetWatcher.Dispose();
            }
            if (Source != null)
            {
                Source.PositionChanged -= source_PositionChanged;
            }
            if (Target != null)
            {
                Target.PositionChanged -= source_PositionChanged;
            }
            _oldSource = _oldTarget = null;
            Source     = null;
            Target     = null;
            Edge       = null;
            RootArea   = null;
            HighlightBehaviour.SetIsHighlightEnabled(this, false);
            DragBehaviour.SetIsDragEnabled(this, false);
            _linegeometry     = null;
            LinePathObject    = null;
            SelfLoopIndicator = null;
            if (EdgeLabelControl != null)
            {
                EdgeLabelControl.Dispose();
                EdgeLabelControl = null;
            }

            if (EdgePointerForSource != null)
            {
                EdgePointerForSource.Dispose();
                EdgePointerForSource = null;
            }
            if (EdgePointerForTarget != null)
            {
                EdgePointerForTarget.Dispose();
                EdgePointerForTarget = null;
            }
            if (EventOptions != null)
            {
                EventOptions.Clean();
            }
        }
Exemplo n.º 4
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            if (!ShowArrows)
            {
                // Hide arrow
                EdgePointerForSource?.Hide();
                EdgePointerForTarget?.Hide();

                // Force line length to connect source/target
                _linegeometry = new PathGeometry(new[]
                {
                    new PathFigure(Source.GetCenterPosition(), new [] {
                        new LineSegment(Target.GetCenterPosition(), isStroked: true)
                    }, closed: false)
                });

                LinePathObject.Data = _linegeometry;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="updateLabel"></param>
        public override void UpdateEdge(bool updateLabel = true)
        {
            // TODO Need to let the styling come through for the paths!

            base.UpdateEdge(updateLabel);

            // Template not loaded yet?
            if (path == null)
            {
                return;
            }

            var bezier   = new BezierSegment();
            var geometry = new PathGeometry();
            var figure   = new PathFigure();

            figure.Segments.Add(bezier);
            geometry.Figures.Add(figure);

            // Find the output slot
            DependencyObject slot = null;

            if (SourceSlot != null)
            {
                if (((NodeVertexControl)Source).Connectors.TryGetValue(SourceSlot, out slot))
                {
                    var container = (UIElement)VisualTreeHelper.GetChild(Source, 0);
                    var offset    = ((UIElement)slot).TransformToAncestor(container).Transform(new Point(0, 0));
                    var location  = Source.GetPosition() + (Vector)offset;
                    var halfsize  = new Vector((double)slot.GetValue(FrameworkElement.WidthProperty) * 0.8,
                                               (double)slot.GetValue(FrameworkElement.HeightProperty) / 2.0);

                    figure.SetCurrentValue(PathFigure.StartPointProperty, location + halfsize);
                    //figure.StartPoint = location + halfsize;
                }
                else
                {
                    // Somehow the slot is not loaded yet
                    // Let's wait for a change in the Connectors collection and trigger UpdateEdge() again
                    ((NodeVertexControl)Source).Connectors.CollectionChanged -= UpdateSourceConnectors;
                    ((NodeVertexControl)Source).Connectors.CollectionChanged += UpdateSourceConnectors;
                    Visibility = Visibility.Collapsed;
                    return;
                }
            }

            // Find input slot
            if (TargetSlot != null)
            {
                if (((NodeVertexControl)Target).Connectors.TryGetValue(TargetSlot, out slot))
                {
                    var container = (UIElement)VisualTreeHelper.GetChild(Target, 0);
                    var offset    = ((UIElement)slot).TransformToAncestor(container).Transform(new Point(0, 0));
                    var location  = Target.GetPosition() + (Vector)offset;

                    //
                    var halfsize = new Vector((double)slot.GetValue(FrameworkElement.WidthProperty) * 0.2,
                                              (double)slot.GetValue(FrameworkElement.HeightProperty) / 2.0);

                    bezier.SetCurrentValue(BezierSegment.Point3Property, location + halfsize);
                    //bezier.Point3 = location + halfsize;
                }
                else
                {
                    ((NodeVertexControl)Target).Connectors.CollectionChanged -= UpdateTargetConnectors;
                    ((NodeVertexControl)Target).Connectors.CollectionChanged += UpdateTargetConnectors;
                    Visibility = Visibility.Collapsed;
                    return;
                }
            }

            // Make sure that even if link is going backward, it still goes out of the block in the proper direction
            var length    = Math.Max(Math.Abs(bezier.Point3.X - figure.StartPoint.X), 120.0f);
            var curvature = length * 0.4;

            bezier.SetCurrentValue(BezierSegment.Point1Property, new Point(figure.StartPoint.X + curvature, figure.StartPoint.Y));
            //bezier.Point1 = new Point(figure.StartPoint.X + curvature, figure.StartPoint.Y);
            bezier.SetCurrentValue(BezierSegment.Point2Property, new Point(bezier.Point3.X - curvature, bezier.Point3.Y));
            //bezier.Point2 = new Point(bezier.Point3.X - curvature, bezier.Point3.Y);

            //
            path.Data = geometry;
            var direction = bezier.Point3 - bezier.Point2;

            if (direction.Length > MathUtil.ZeroToleranceDouble)
            {
                direction.Normalize();
            }
            else
            {
                direction = new Vector(0, 0);
            }
            EdgePointerForTarget?.Update(bezier.Point3, direction, EdgePointerForTarget.NeedRotation ? (-MathHelper.GetAngleBetweenPoints(bezier.Point3, bezier.Point2).ToDegrees()) : 0);
            //arrow.Data = new PathGeometry { Figures = { GeometryHelper.GenerateOldArrow(bezier.Point2, bezier.Point3) } };

            // TODO Should I be doing this here??? should I be uing setcurrentvalue??
            Visibility = Visibility.Visible;
        }