示例#1
0
        private object ChooseActiveTarget(GraphHitRecord <TNode, TEdge, TEdgeRoute> hitRecord)
        {
            if (hitRecord.SubItem == null)
            {
                return(hitRecord.Item);
            }

            if (m_editableGraphContainer != null)
            {
                foreach (var itemInPath in hitRecord.HitPathInversed)
                {
                    if (m_editableGraphContainer.CanMove(itemInPath, m_draggingNodes))
                    {
                        // favor subitem when it is expanded
                        return(itemInPath);
                    }
                }
            }
            return(hitRecord.Item);
        }
示例#2
0
        /// <summary>
        /// Finds node and/or edge hit by the given point</summary>
        /// <param name="graph">Graph to test</param>
        /// <param name="priorityEdge">Graph edge to test before others</param>
        /// <param name="p">Point to test</param>
        /// <param name="g">Graphics object</param>
        /// <returns>Hit record containing node and/or edge hit by the given point</returns>
        public override GraphHitRecord <TElement, TWire, TPin> Pick(
            IGraph <TElement, TWire, TPin> graph, TWire priorityEdge, PointF p, D2dGraphics g)
        {
            var hitRecord = base.Pick(graph, priorityEdge, p, g);

            if (hitRecord.Node != null || hitRecord.Edge != null || hitRecord.Part != null)
            {
                return(hitRecord);
            }

            // check whether hits virtual parts of group pin
            var group = graph.Cast <ICircuitGroupType <TElement, TWire, TPin> >();

            foreach (var pin in group.Inputs.Concat(group.Info.HiddenInputPins))
            {
                var grpPin = pin.Cast <ICircuitGroupPin <TElement> >();
                // check whether hit the thumbtack of a floating pin
                var pinRect = GetThumbtackRect(grpPin, true);
                if (pinRect.Contains(p))
                {
                    var pinPart = new DiagramPin(pinRect);
                    return(new GraphHitRecord <TElement, TWire, TPin>((TPin)grpPin, pinPart));
                }

                // check whether hit the visibility check(eye icon)
                var eyeRect = GetVisibilityCheckRect(grpPin, true);
                if (eyeRect.Contains(p))
                {
                    var eyePart = new DiagramVisibilityCheck(eyeRect);
                    return(new GraphHitRecord <TElement, TWire, TPin>((TPin)grpPin, eyePart));
                }


                // check whether hit the floating pin label-part
                PointF     grpPos      = GetGroupPinLocation(grpPin, true);
                RectangleF bounds      = new RectangleF(grpPos.X, grpPos.Y, CircuitGroupPinInfo.FloatingPinBoxWidth, CircuitGroupPinInfo.FloatingPinBoxHeight);
                SizeF      nameSize    = g.MeasureText(grpPin.Name, Theme.TextFormat);
                RectangleF labelBounds = new RectangleF(bounds.Left, bounds.Bottom + Theme.PinMargin, (int)nameSize.Width, Theme.RowSpacing);
                //labelBounds = GdiUtil.Transform(g.Transform, labelBounds);
                var labelPart = new DiagramLabel(
                    new Rectangle((int)labelBounds.Left, (int)labelBounds.Top, (int)labelBounds.Width, (int)labelBounds.Height),
                    TextFormatFlags.SingleLine | TextFormatFlags.Left);

                if (labelBounds.Contains(p))
                {
                    return(new GraphHitRecord <TElement, TWire, TPin>((TPin)grpPin, labelPart));
                }

                // check whether hit the floating pin node
                if (bounds.Contains(p))
                {
                    var result = new GraphHitRecord <TElement, TWire, TPin>((TPin)grpPin, null);
                    result.DefaultPart = labelPart;
                    return(result);
                }
            }

            foreach (var pin in group.Outputs.Concat(group.Info.HiddenOutputPins))
            {
                var grpPin = pin.Cast <ICircuitGroupPin <TElement> >();
                // check whether hit the thumbtack of a floating pin
                var pinRect = GetThumbtackRect(grpPin, false);
                if (pinRect.Contains(p))
                {
                    var pinPart = new DiagramPin(pinRect);
                    return(new GraphHitRecord <TElement, TWire, TPin>((TPin)grpPin, pinPart));
                }

                // check whether hit the visibility check(eye icon)
                var eyeRect = GetVisibilityCheckRect(grpPin, false);
                if (eyeRect.Contains(p))
                {
                    var eyePart = new DiagramVisibilityCheck(eyeRect);
                    return(new GraphHitRecord <TElement, TWire, TPin>((TPin)grpPin, eyePart));
                }

                // check whether hit the floating pin label-part
                PointF     grpPos      = GetGroupPinLocation(grpPin, false);
                RectangleF bounds      = new RectangleF(grpPos.X, grpPos.Y, CircuitGroupPinInfo.FloatingPinBoxWidth, CircuitGroupPinInfo.FloatingPinBoxHeight);
                SizeF      nameSize    = g.MeasureText(grpPin.Name, Theme.TextFormat);
                RectangleF labelBounds = new RectangleF(bounds.Right - (int)nameSize.Width, bounds.Bottom + Theme.PinMargin, (int)nameSize.Width, Theme.RowSpacing);
                //labelBounds = GdiUtil.Transform(g.Transform, labelBounds);
                var labelPart = new DiagramLabel(
                    new Rectangle((int)labelBounds.Left, (int)labelBounds.Top, (int)labelBounds.Width, (int)labelBounds.Height),
                    TextFormatFlags.SingleLine | TextFormatFlags.Right);

                if (labelBounds.Contains(p))
                {
                    return(new GraphHitRecord <TElement, TWire, TPin>((TPin)grpPin, labelPart));
                }

                // check whether hit the floating pin node
                if (bounds.Contains(p))
                {
                    var result = new GraphHitRecord <TElement, TWire, TPin>((TPin)grpPin, null);
                    result.DefaultPart = labelPart;
                    return(result);
                }
            }

            return(hitRecord);
        }
示例#3
0
        /// <summary>
        /// Finds node and/or edge hit by the given point</summary>
        /// <param name="graph">Graph to test</param>
        /// <param name="priorityEdge">Graph edge to test before others</param>
        /// <param name="p">Point to test in graph space</param>
        /// <param name="g">D2dGraphics object</param>
        /// <returns>Hit record containing node and/or edge hit by the given point</returns>
        public override GraphHitRecord <TNode, TEdge, NumberedRoute> Pick(
            IGraph <TNode, TEdge, NumberedRoute> graph,
            TEdge priorityEdge,
            PointF p,
            D2dGraphics g)
        {
            TNode         pickedNode = null;
            TEdge         pickedEdge = null;
            NumberedRoute fromRoute  = null;
            NumberedRoute toRoute    = null;

            Vec2F v = new Vec2F(p.X, p.Y);

            if (priorityEdge != null &&
                Pick(priorityEdge, v))
            {
                pickedEdge = priorityEdge;
            }
            else
            {
                foreach (TEdge edge in graph.Edges.Reverse())
                {
                    if (Pick(edge, v))
                    {
                        pickedEdge = edge;
                        break;
                    }
                }
            }

            foreach (TNode node in graph.Nodes.Reverse())
            {
                if (Pick(node, p))
                {
                    pickedNode = node;

                    CircleF boundary = GetBoundary(node);
                    boundary.Radius -= m_theme.PickTolerance;
                    bool onEdge = !boundary.Contains(v);

                    if (pickedEdge == null)
                    {
                        if (onEdge)
                        {
                            // edge of node can be source or destination
                            fromRoute = new NumberedRoute();
                            toRoute   = new NumberedRoute();
                        }
                    }
                    else // hit on edge and node
                    {
                        if (onEdge)
                        {
                            if (pickedEdge.FromNode == pickedNode)
                            {
                                fromRoute = new NumberedRoute();
                            }
                            else if (pickedEdge.ToNode == pickedNode)
                            {
                                toRoute = new NumberedRoute();
                            }
                        }
                    }
                    break;
                }
            }

            var result = new GraphHitRecord <TNode, TEdge, NumberedRoute>(pickedNode, pickedEdge, fromRoute, toRoute);

            PointF clientP = Matrix3x2F.TransformPoint(g.Transform, p);

            if (fromRoute != null)
            {
                result.FromRoutePos = clientP;
            }
            if (toRoute != null)
            {
                result.ToRoutePos = clientP;
            }

            if (pickedNode != null && pickedEdge == null)
            {
                // label is centered in entire node
                RectangleF labelBounds = GetBounds(pickedNode, g);
                float      dHeight     = labelBounds.Height - m_theme.TextFormat.FontHeight;
                labelBounds = new RectangleF(
                    labelBounds.X, labelBounds.Y + dHeight / 2, labelBounds.Width, labelBounds.Height - dHeight);

                if (labelBounds.Contains(p))
                {
                    DiagramLabel label = new DiagramLabel(
                        Rectangle.Truncate(labelBounds),
                        TextFormatFlags.SingleLine |
                        TextFormatFlags.HorizontalCenter);

                    return
                        (new GraphHitRecord <TNode, TEdge, NumberedRoute>(pickedNode, label));
                }
            }
            else if (pickedEdge != null)
            {
                RectangleF   labelBounds = GetLabelBounds(pickedEdge, g);
                DiagramLabel label       = new DiagramLabel(
                    Rectangle.Truncate(labelBounds),
                    TextFormatFlags.SingleLine |
                    TextFormatFlags.HorizontalCenter);

                if (labelBounds.Contains(p))
                {
                    return
                        (new GraphHitRecord <TNode, TEdge, NumberedRoute>(pickedEdge, label));
                }
            }

            return(result);
        }