示例#1
0
        /// <summary>
        /// Creates a new bend at the given location. If this bend is on the first or last segment,
        /// a second bend is created and placed at a location that ensures that the newly create
        /// inner segment is orthogonal.
        /// </summary>
        public int CreateBend(IInputModeContext context, IGraph graph, IEdge edge, PointD location)
        {
            var edgePoints     = GetEdgePoints(edge);
            var closestSegment = DetermineBendSegmentIndex(edgePoints, location);

            int firstSegment = 0;
            int lastSegment  = edge.Bends.Count;

            // if bend wasn't created in first or last segment, call default action
            if (closestSegment != firstSegment && closestSegment != lastSegment)
            {
                return((new DefaultBendCreator()).CreateBend(context, graph, edge, location));
            }

            // add created bend and another one to make the edge stay orthogonal
            if (closestSegment == -1 || context == null || !(context.ParentInputMode is CreateBendInputMode))
            {
                return(-1);
            }
            var editingContext = context.Lookup <OrthogonalEdgeEditingContext>();

            if (editingContext == null)
            {
                return(-1);
            }
            if (closestSegment == firstSegment)
            {
                IPoint nextPoint = edgePoints[1];
                // get orientation of next edge segment to determine second bend location
                SegmentOrientation orientation = editingContext.GetSegmentOrientation(edge, 1);
                graph.AddBend(edge, location, 0);
                if (orientation == SegmentOrientation.Horizontal)
                {
                    graph.AddBend(edge, new PointD(nextPoint.X, location.Y), 1);
                }
                else if (orientation == SegmentOrientation.Vertical)
                {
                    graph.AddBend(edge, new PointD(location.X, nextPoint.Y), 1);
                }
                return(0);
            }
            if (closestSegment == lastSegment)
            {
                IPoint prevPoint = edgePoints[edge.Bends.Count];
                // get orientation of next edge segment to determine second bend location
                SegmentOrientation orientation = editingContext.GetSegmentOrientation(edge, edge.Bends.Count - 1);
                graph.AddBend(edge, location, edge.Bends.Count);
                if (orientation == SegmentOrientation.Horizontal)
                {
                    graph.AddBend(edge, new PointD(prevPoint.X, location.Y), edge.Bends.Count - 1);
                }
                else if (orientation == SegmentOrientation.Vertical)
                {
                    graph.AddBend(edge, new PointD(location.X, prevPoint.Y), edge.Bends.Count - 1);
                }
                return(edge.Bends.Count - 1);
            }
            return(-1);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DigitalBar"/> class.
        /// </summary>
        /// <param name="orientation">The orientation.</param>
        public DigitalBar(SegmentOrientation orientation)
        {
            Color          = Color.Black;
            OpacityWhenOff = 0.1d;
            IsOn           = true;
            m_orientation  = orientation;
            Corners        = SegmentCorners.None;
            Padding        = 0;

            m_redrawRegion = new Region();
            CalculatePaths(new RectangleF());
        }
示例#3
0
        public DigitalBar(SegmentOrientation orientation)
        {
            Color = Color.Black;
            OpacityWhenOff = 0.1d;
            IsOn = true;
            m_orientation = orientation;
            Corners = SegmentCorners.None;
            Padding = 0;

            m_redrawRegion = new Region();
            CalculatePaths(new RectangleF());
        }