Exemplo n.º 1
0
        /// <summary>
        /// Returns the x-coordinate of the center point for automatic routing.
        /// </summary>
        /// <returns>Returns the x-coordinate of the routing center point.</returns>
        public double GetRoutingCenterX(mxCellState state)
        {
            float f = (state.Style != null) ? mxUtils.GetFloat(state.
                                                               Style, mxConstants.STYLE_ROUTING_CENTER_X) : 0;

            return(state.GetCenterX() + f * state.Width);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the nearest point in the list of absolute points or the center
        /// of the opposite terminal.
        /// </summary>
        /// <param name="edge">State that represents the edge.</param>
        /// <param name="opposite">State that represents the opposite terminal.</param>
        /// <param name="source">Boolean indicating if the next point for the source or target
        /// should be returned.</param>
        public mxPoint GetNextPoint(mxCellState edge, mxCellState opposite, bool source)
        {
            List <mxPoint> pts   = edge.AbsolutePoints;
            mxPoint        point = null;

            if (pts != null && pts.Count >= 2)
            {
                int count = pts.Count;
                int index = (source) ? Math.Min(1, count - 1) : Math.Max(0, count - 2);
                point = pts[index];
            }

            if (point == null && opposite != null)
            {
                point = new mxPoint(opposite.GetCenterX(), opposite.GetCenterY());
            }

            return(point);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Paints the stencil for the given state.
        /// </summary>
        public void PaintShape(mxGdiCanvas gc, mxCellState state)
        {
            mxGdiCanvas2D canvas = CreateCanvas(gc);
            Dictionary<string, object> style = state.Style;

            double rotation = mxUtils.GetDouble(style, mxConstants.STYLE_ROTATION,
                    0);
            String direction = mxUtils.GetString(style,
                    mxConstants.STYLE_DIRECTION, null);

            // Default direction is east (ignored if rotation exists)
            if (direction != null)
            {
                if (direction.Equals("north"))
                {
                    rotation += 270;
                }
                else if (direction.Equals("west"))
                {
                    rotation += 180;
                }
                else if (direction.Equals("south"))
                {
                    rotation += 90;
                }
            }

            // New styles for shape flipping the stencil
            bool flipH = mxUtils.IsTrue(style, mxConstants.STYLE_STENCIL_FLIPH,
                    false);
            bool flipV = mxUtils.IsTrue(style, mxConstants.STYLE_STENCIL_FLIPV,
                    false);

            if (flipH && flipV)
            {
                rotation += 180;
                flipH = false;
                flipV = false;
            }

            // Saves the global state for each cell
            canvas.Save();

            // Adds rotation and horizontal/vertical flipping
            rotation = rotation % 360;

            if (rotation != 0 || flipH || flipV)
            {
                canvas.Rotate(rotation, flipH, flipV, state.GetCenterX(),
                        state.GetCenterY());
            }

            // Note: Overwritten in mxStencil.paintShape (can depend on aspect)
            double scale = state.View.Scale;
            double sw = mxUtils.GetDouble(style, mxConstants.STYLE_STROKEWIDTH, 1)
                    * scale;
            canvas.StrokeWidth = sw;

            double alpha = mxUtils.GetDouble(style, mxConstants.STYLE_OPACITY, 100) / 100;
            String gradientColor = mxUtils.GetString(style,
                    mxConstants.STYLE_GRADIENTCOLOR, null);

            // Converts colors with special keyword none to null
            if (gradientColor != null && gradientColor.Equals(mxConstants.NONE))
            {
                gradientColor = null;
            }

            String fillColor = mxUtils.GetString(style,
                    mxConstants.STYLE_FILLCOLOR, null);

            if (fillColor != null && fillColor.Equals(mxConstants.NONE))
            {
                fillColor = null;
            }

            String strokeColor = mxUtils.GetString(style,
                    mxConstants.STYLE_STROKECOLOR, null);

            if (strokeColor != null && strokeColor.Equals(mxConstants.NONE))
            {
                strokeColor = null;
            }

            // Draws the shadow if the fillColor is not transparent
            if (mxUtils.IsTrue(style, mxConstants.STYLE_SHADOW, false))
            {
                DrawShadow(canvas, state, rotation, flipH, flipV, state, alpha, fillColor != null);
            }

            canvas.Alpha = alpha;

            // Sets the dashed state
            if (mxUtils.IsTrue(style, mxConstants.STYLE_DASHED, false))
            {
                canvas.Dashed = true;
            }

            // Draws background and foreground
            if (strokeColor != null || fillColor != null)
            {
                if (strokeColor != null)
                {
                    canvas.StrokeColor = strokeColor;
                }

                if (fillColor != null)
                {
                    if (gradientColor != null
                            && !gradientColor.Equals("transparent"))
                    {
                        canvas.SetGradient(fillColor, gradientColor, state.X,
                                state.Y, state.Width, state.Height,
                                direction);
                    }
                    else
                    {
                        canvas.FillColor = fillColor;
                    }
                }

                // Draws background and foreground of shape
                DrawShape(canvas, state, state, true);
                DrawShape(canvas, state, state, false);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Paints the stencil for the given state.
        /// </summary>
        public void PaintShape(mxGdiCanvas gc, mxCellState state)
        {
            mxGdiCanvas2D canvas = CreateCanvas(gc);
            Dictionary <string, object> style = state.Style;

            double rotation = mxUtils.GetDouble(style, mxConstants.STYLE_ROTATION,
                                                0);
            String direction = mxUtils.GetString(style,
                                                 mxConstants.STYLE_DIRECTION, null);

            // Default direction is east (ignored if rotation exists)
            if (direction != null)
            {
                if (direction.Equals("north"))
                {
                    rotation += 270;
                }
                else if (direction.Equals("west"))
                {
                    rotation += 180;
                }
                else if (direction.Equals("south"))
                {
                    rotation += 90;
                }
            }

            // New styles for shape flipping the stencil
            bool flipH = mxUtils.IsTrue(style, mxConstants.STYLE_STENCIL_FLIPH,
                                        false);
            bool flipV = mxUtils.IsTrue(style, mxConstants.STYLE_STENCIL_FLIPV,
                                        false);

            if (flipH && flipV)
            {
                rotation += 180;
                flipH     = false;
                flipV     = false;
            }

            // Saves the global state for each cell
            canvas.Save();

            // Adds rotation and horizontal/vertical flipping
            rotation = rotation % 360;

            if (rotation != 0 || flipH || flipV)
            {
                canvas.Rotate(rotation, flipH, flipV, state.GetCenterX(),
                              state.GetCenterY());
            }

            // Note: Overwritten in mxStencil.paintShape (can depend on aspect)
            double scale = state.View.Scale;
            double sw    = mxUtils.GetDouble(style, mxConstants.STYLE_STROKEWIDTH, 1)
                           * scale;

            canvas.StrokeWidth = sw;

            double alpha         = mxUtils.GetDouble(style, mxConstants.STYLE_OPACITY, 100) / 100;
            String gradientColor = mxUtils.GetString(style,
                                                     mxConstants.STYLE_GRADIENTCOLOR, null);

            // Converts colors with special keyword none to null
            if (gradientColor != null && gradientColor.Equals(mxConstants.NONE))
            {
                gradientColor = null;
            }

            String fillColor = mxUtils.GetString(style,
                                                 mxConstants.STYLE_FILLCOLOR, null);

            if (fillColor != null && fillColor.Equals(mxConstants.NONE))
            {
                fillColor = null;
            }

            String strokeColor = mxUtils.GetString(style,
                                                   mxConstants.STYLE_STROKECOLOR, null);

            if (strokeColor != null && strokeColor.Equals(mxConstants.NONE))
            {
                strokeColor = null;
            }

            // Draws the shadow if the fillColor is not transparent
            if (mxUtils.IsTrue(style, mxConstants.STYLE_SHADOW, false))
            {
                DrawShadow(canvas, state, rotation, flipH, flipV, state, alpha, fillColor != null);
            }

            canvas.Alpha = alpha;

            // Sets the dashed state
            if (mxUtils.IsTrue(style, mxConstants.STYLE_DASHED, false))
            {
                canvas.Dashed = true;
            }

            // Draws background and foreground
            if (strokeColor != null || fillColor != null)
            {
                if (strokeColor != null)
                {
                    canvas.StrokeColor = strokeColor;
                }

                if (fillColor != null)
                {
                    if (gradientColor != null &&
                        !gradientColor.Equals("transparent"))
                    {
                        canvas.SetGradient(fillColor, gradientColor, state.X,
                                           state.Y, state.Width, state.Height,
                                           direction, 1, 1);
                    }
                    else
                    {
                        canvas.FillColor = fillColor;
                    }
                }

                // Draws background and foreground of shape
                DrawShape(canvas, state, state, true);
                DrawShape(canvas, state, state, false);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Returns the absolute point on the edge for the given relative
        /// geometry as a point. The edge is represented by the given cell state.
        /// </summary>
        /// <param name="state">Represents the state of the parent edge.</param>
        /// <param name="geometry">Represents the relative location.</param>
        public mxPoint GetPoint(mxCellState state, mxGeometry geometry)
        {
            double x = state.GetCenterX();
            double y = state.GetCenterY();

            if (state.Segments != null && (geometry == null || geometry.Relative))
            {
                double   gx         = (geometry != null) ? geometry.X / 2 : 0;
                int      pointCount = state.AbsolutePoints.Count;
                double   dist       = (gx + 0.5) * state.Length;
                double[] segments   = state.Segments;
                double   segment    = segments[0];
                double   length     = 0;
                int      index      = 1;

                while (dist > length + segment && index < pointCount - 1)
                {
                    length += segment;
                    segment = segments[index++];
                }

                double  factor = (segment == 0) ? 0 : (dist - length) / segment;
                mxPoint p0     = state.AbsolutePoints[index - 1];
                mxPoint pe     = state.AbsolutePoints[index];

                if (p0 != null &&
                    pe != null)
                {
                    double gy      = 0;
                    double offsetX = 0;
                    double offsetY = 0;

                    if (geometry != null)
                    {
                        gy = geometry.Y;
                        mxPoint offset = geometry.Offset;

                        if (offset != null)
                        {
                            offsetX = offset.X;
                            offsetY = offset.Y;
                        }
                    }

                    double dx = pe.X - p0.X;
                    double dy = pe.Y - p0.Y;
                    double nx = (segment == 0) ? 0 : dy / segment;
                    double ny = (segment == 0) ? 0 : dx / segment;

                    x = p0.X + dx * factor + (nx * gy + offsetX) * scale;
                    y = p0.Y + dy * factor - (ny * gy - offsetY) * scale;
                }
            }
            else if (geometry != null)
            {
                mxPoint offset = geometry.Offset;

                if (offset != null)
                {
                    x += offset.X;
                    y += offset.Y;
                }
            }

            return(new mxPoint(x, y));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Returns the x-coordinate of the center point for automatic routing.
        /// </summary>
        /// <returns>Returns the x-coordinate of the routing center point.</returns>
        public double GetRoutingCenterX(mxCellState state)
        {
            float f = (state.Style != null) ? mxUtils.GetFloat(state.
                Style, mxConstants.STYLE_ROUTING_CENTER_X) : 0;

            return state.GetCenterX() + f * state.Width;
        }
Exemplo n.º 7
0
        /// <summary>
        /// Returns the absolute point on the edge for the given relative
        /// geometry as a point. The edge is represented by the given cell state.
        /// </summary>
        /// <param name="state">Represents the state of the parent edge.</param>
        /// <param name="geometry">Represents the relative location.</param>
        public mxPoint GetPoint(mxCellState state, mxGeometry geometry)
        {
            double x = state.GetCenterX();
            double y = state.GetCenterY();

            if (state.Segments != null && (geometry == null || geometry.Relative))
            {
                double gx = (geometry != null) ? geometry.X / 2 : 0;
                int pointCount = state.AbsolutePoints.Count;
                double dist = (gx + 0.5) * state.Length;
                double[] segments = state.Segments;
                double segment = segments[0];
                double length = 0;
                int index = 1;

                while (dist > length + segment && index < pointCount - 1)
                {
                    length += segment;
                    segment = segments[index++];
                }

                double factor = (segment == 0) ? 0 : (dist - length) / segment;
                mxPoint p0 = state.AbsolutePoints[index - 1];
                mxPoint pe = state.AbsolutePoints[index];

                if (p0 != null &&
                    pe != null)
                {
                    double gy = 0;
                    double offsetX = 0;
                    double offsetY = 0;

                    if (geometry != null)
                    {
                        gy = geometry.Y;
                        mxPoint offset = geometry.Offset;

                        if (offset != null)
                        {
                            offsetX = offset.X;
                            offsetY = offset.Y;
                        }
                    }

                    double dx = pe.X - p0.X;
                    double dy = pe.Y - p0.Y;
                    double nx = (segment == 0) ? 0 : dy / segment;
                    double ny = (segment == 0) ? 0 : dx / segment;

                    x = p0.X + dx * factor + (nx * gy + offsetX) * scale;
                    y = p0.Y + dy * factor - (ny * gy - offsetY) * scale;
                }
            }
            else if (geometry != null)
            {
                mxPoint offset = geometry.Offset;

                if (offset != null)
                {
                    x += offset.X;
                    y += offset.Y;
                }
            }

            return new mxPoint(x, y);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns the nearest point in the list of absolute points or the center
        /// of the opposite terminal.
        /// </summary>
        /// <param name="edge">State that represents the edge.</param>
        /// <param name="opposite">State that represents the opposite terminal.</param>
        /// <param name="source">Boolean indicating if the next point for the source or target
        /// should be returned.</param>
        public mxPoint GetNextPoint(mxCellState edge, mxCellState opposite, bool source)
        {
            List<mxPoint> pts = edge.AbsolutePoints;
            mxPoint point = null;

            if (pts != null && (source || pts.Count > 2 || opposite == null))
            {
                int count = pts.Count;
                int index = (source) ? Math.Min(1, count - 1) : Math.Max(0, count - 2);
                point = pts[index];
            }

            if (point == null && opposite != null)
            {
                point = new mxPoint(opposite.GetCenterX(), opposite.GetCenterY());
            }

            return point;
        }