예제 #1
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);
        }
 public IEnumerator <TOuter> GetEnumerator()
 {
     return(_graph.Cast <TOuter>().GetEnumerator());
 }