Ejemplo n.º 1
0
            /// <summary>
            /// Draw the edge on the specified surface.
            /// </summary>
            /// <param name="surface">Surface to draw on.</param>
            internal void Draw(DrawingSurface2D surface)
            {
                var previous = Spline[0];
                int width    = this.Style == Style.Bold ? 3 : 1;
                Pen pen      = new Pen(this.Color);

                pen.Width = width;
                for (int i = 1; i < Spline.Count; i++)
                {
                    Point2D point = Spline[i];
                    if (i == Spline.Count - 1)
                    {
                        // adjust for arrow size at the end of the edge.
                        const double absoluteArrowSize = 0.15;
                        double       dx  = point.X - previous.X;
                        double       dy  = point.Y - previous.Y;
                        double       len = Math.Sqrt(dx * dx + dy * dy);
                        double       adx = absoluteArrowSize * dx / len;
                        double       ady = absoluteArrowSize * dy / len;

                        point = new Point2D(point.X + adx, point.Y + ady);
                        //pen.EndCap = LineCap.ArrowAnchor;
                        AdjustableArrowCap cap = new AdjustableArrowCap(4, 6);
                        pen.CustomEndCap = cap;
                    }
                    surface.DrawLine(pen, previous, point, false);
                    previous = point;
                }
            }
Ejemplo n.º 2
0
 /// <summary>
 /// Draw the graph on the specified surface.
 /// </summary>
 /// <param name="surface">Surface to draw graph on.</param>
 public void Draw(DrawingSurface2D surface)
 {
     foreach (GraphNode n in this.nodes)
     {
         n.Draw(surface);
     }
     foreach (GraphEdge e in this.edges)
     {
         e.Draw(surface);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Draw a one-line string to fit in the specified rectangle.
        /// </summary>
        /// <param name="text">Text to draw.</param>
        /// <param name="baseFont">Start from this font, but resize it.</param>
        /// <param name="brush">Brush to use for drawing.</param>
        /// <param name="place">Where to draw it.</param>
        public void DrawTextInRectangle(string text, Brush brush, Font baseFont, Rectangle2D place)
        {
            Rectangle dest = this.Scale(place);
            Font      font = DrawingSurface2D.ChooseFont(this.grph, baseFont, dest.Size, text);

            if (font == null || font.Size < 3)
            {
                // too small anyway
                return;
            }
            SizeF actualSize = this.grph.MeasureString(text, font);
            int   adjustX    = (int)(dest.Width - actualSize.Width) / 2;
            int   adjustY    = dest.Height / 2;

            this.DrawRightJustifiedTextAbsoluteCoordinates(text, font, brush, dest.Right - adjustX, dest.Top + adjustY);
        }
Ejemplo n.º 4
0
            /// <summary>
            /// Draw the node on a panel surface.
            /// </summary>
            /// <param name="surface">Surface to draw on.</param>
            internal void Draw(DrawingSurface2D surface)
            {
                if (this.Position.Width > 0)
                {
                    // Fill colors in bands from left to right
                    double offset = 0;
                    foreach (Tuple <double, Color> band in this.FillColors)
                    {
                        if (band.Item1 <= 0)
                        {
                            continue;
                        }

                        Color c     = band.Item2;
                        var   brush = new SolidBrush(c);

                        Point2D left = new Point2D(this.Position.Corner1.X + offset * this.Position.Width, this.Position.Corner1.Y);
                        offset += band.Item1;
                        Point2D right = new Point2D(this.Position.Corner1.X + offset * this.Position.Width, this.Position.Corner2.Y);
                        surface.FillRectangle(brush, new Rectangle2D(left, right));
                    }

                    Font font = new Font("Arial", 12, FontStyle.Regular);
                    // let's shrink the position for the text to leave some border

                    if (this.Label != null)
                    {
                        const double borderFraction = 8; // reserve 1/8 of the rectangle for border
                        Rectangle2D  box            = new Rectangle2D(
                            this.Position.Corner1.Translate(this.Position.Width / borderFraction, this.Position.Height / borderFraction),
                            this.Position.Corner2.Translate(-this.Position.Width / borderFraction, -this.Position.Height / borderFraction));
                        surface.DrawTextInRectangle(this.Label, Brushes.Black, font, box);
                    }
                }

                Pen pen = this.Selected ? thickBlackPen : blackPen;

                switch (this.Shape)
                {
                default:
                case NodeShape.Box:
                    surface.DrawRectangle(this.Position, pen);
                    break;

                case NodeShape.Ellipse:
                    surface.DrawEllipse(this.LineColor, this.Position, pen, false);
                    break;

                case NodeShape.Invhouse:
                {
                    Point2D[] points = new Point2D[5];
                    points[0] = new Point2D(this.Position.Corner1.X, this.Position.Corner1.Y + this.Position.Height / 3);
                    points[1] = new Point2D(this.Position.Corner1.X, this.Position.Corner2.Y - this.Position.Height / 8);
                    points[2] = new Point2D(this.Position.Corner2.X, this.Position.Corner2.Y - this.Position.Height / 8);
                    points[3] = new Point2D(this.Position.Corner2.X, this.Position.Corner1.Y + this.Position.Height / 3);
                    points[4] = new Point2D(this.Position.Corner1.X + this.Position.Width / 2, this.Position.Corner1.Y);
                    surface.DrawPolygon(this.LineColor, points, pen, false);
                    break;
                }
                }
            }
Ejemplo n.º 5
0
 /// <summary>
 /// Draw the graph on the specified surface.
 /// </summary>
 /// <param name="surface">Surface to draw graph on.</param>
 public void Draw(DrawingSurface2D surface)
 {            
     foreach (GraphNode n in this.nodes)
         n.Draw(surface);
     foreach (GraphEdge e in this.edges)
         e.Draw(surface);
 }
Ejemplo n.º 6
0
            /// <summary>
            /// Draw the edge on the specified surface.
            /// </summary>
            /// <param name="surface">Surface to draw on.</param>
            internal void Draw(DrawingSurface2D surface)
            {
                var previous = Spline[0];
                int width = this.Style == Style.Bold ? 3 : 1;
                Pen pen = new Pen(this.Color);
                pen.Width = width;
                for (int i = 1; i < Spline.Count; i++)
                {
                    Point2D point = Spline[i];
                    if (i == Spline.Count - 1)
                    {
                        // adjust for arrow size at the end of the edge.
                        const double absoluteArrowSize = 0.15;
                        double dx = point.X - previous.X;
                        double dy = point.Y - previous.Y;
                        double len = Math.Sqrt(dx * dx + dy * dy);
                        double adx = absoluteArrowSize * dx / len;
                        double ady = absoluteArrowSize * dy / len;

                        point = new Point2D(point.X + adx, point.Y + ady);
                        //pen.EndCap = LineCap.ArrowAnchor;
                        AdjustableArrowCap cap = new AdjustableArrowCap(4, 6);
                        pen.CustomEndCap = cap;
                    }
                    surface.DrawLine(pen, previous, point, false);
                    previous = point;
                }
            }
Ejemplo n.º 7
0
            /// <summary>
            /// Draw the node on a panel surface.
            /// </summary>
            /// <param name="surface">Surface to draw on.</param>
            internal void Draw(DrawingSurface2D surface)
            {
                if (this.Position.Width > 0)
                {
                    // Fill colors in bands from left to right
                    double offset = 0;
                    foreach (Tuple<double, Color> band in this.FillColors)
                    {
                        if (band.Item1 <= 0)
                            continue;

                        Color c = band.Item2;
                        var brush = new SolidBrush(c);

                        Point2D left = new Point2D(this.Position.Corner1.X + offset * this.Position.Width, this.Position.Corner1.Y);
                        offset += band.Item1;
                        Point2D right = new Point2D(this.Position.Corner1.X + offset * this.Position.Width, this.Position.Corner2.Y);
                        surface.FillRectangle(brush, new Rectangle2D(left, right));
                    }

                    Font font = new Font("Arial", 12, FontStyle.Regular);
                    // let's shrink the position for the text to leave some border

                    if (this.Label != null)
                    {
                        const double borderFraction = 8; // reserve 1/8 of the rectangle for border
                        Rectangle2D box = new Rectangle2D(
                            this.Position.Corner1.Translate(this.Position.Width / borderFraction, this.Position.Height / borderFraction),
                            this.Position.Corner2.Translate(-this.Position.Width / borderFraction, -this.Position.Height / borderFraction));
                        surface.DrawTextInRectangle(this.Label, Brushes.Black, font, box);
                    }
                }

                Pen pen = this.Selected ? thickBlackPen : blackPen;
                switch (this.Shape)
                {
                    default:
                    case NodeShape.Box:
                        surface.DrawRectangle(this.Position, pen);
                        break;
                    case NodeShape.Ellipse:
                        surface.DrawEllipse(this.LineColor, this.Position, pen, false);
                        break;
                    case NodeShape.Invhouse:
                        {
                            Point2D[] points = new Point2D[5];
                            points[0] = new Point2D(this.Position.Corner1.X, this.Position.Corner1.Y + this.Position.Height / 3);
                            points[1] = new Point2D(this.Position.Corner1.X, this.Position.Corner2.Y - this.Position.Height / 8);
                            points[2] = new Point2D(this.Position.Corner2.X, this.Position.Corner2.Y - this.Position.Height / 8);
                            points[3] = new Point2D(this.Position.Corner2.X, this.Position.Corner1.Y + this.Position.Height / 3);
                            points[4] = new Point2D(this.Position.Corner1.X + this.Position.Width / 2, this.Position.Corner1.Y);
                            surface.DrawPolygon(this.LineColor, points, pen, false);
                            break;
                        }
                }
            }
Ejemplo n.º 8
0
        /// <summary>
        /// Draw the plan.
        /// </summary>
        /// <param name="drawingSurface2D">Surface where the plan is to be drawn.</param>
        /// <param name="colorToUse">Function deciding the color to use for each vertex.</param>
        public void Draw(DrawingSurface2D drawingSurface2D, Func<ExecutedVertexInstance, Color> colorToUse)
        {
            foreach (var vertex in this.vertices)
            {
                DateTime start = vertex.Start;
                string machine = vertex.Machine;
                if (string.IsNullOrEmpty(machine) || start == DateTime.MinValue)
                    continue;

                TimeSpan runningTime = vertex.RunningTime;
                // This can happen if there is nothing known about this vertex at the point when the schedule is drawn.
                if (runningTime == TimeSpan.MinValue)
                    continue;

                DateTime end = start + runningTime;
                int index = this.utilization.SortedIndex(machine);
                double y = spacing * index;
                double left = (start - this.startTime).TotalSeconds;
                double right = (end - this.startTime).TotalSeconds;
                Color color = colorToUse(vertex);
                Pen pen = new Pen(color, 2);

                drawingSurface2D.DrawLine(pen, new Point2D(left, y), new Point2D(right, y), false);
            }
        }