Exemplo n.º 1
0
            /// <summary>
            /// RENDERING LAYOUT
            /// </summary>
            /// <param name="canvas"></param>
            /// <param name="graphics"></param>
            /// <param name="channel"></param>
            protected override void Render(Grasshopper.GUI.Canvas.GH_Canvas canvas, System.Drawing.Graphics graphics, Grasshopper.GUI.Canvas.GH_CanvasChannel channel)
            {
                base.Render(canvas, graphics, channel);
                if (channel == Grasshopper.GUI.Canvas.GH_CanvasChannel.Objects)
                {
                    button = GH_Capsule.CreateTextCapsule(ButtonBounds, ButtonBounds, GH_Palette.Transparent, "", new int[] { 0, 0, 0, 5 }, 0);
                    button.Render(graphics, Selected, Owner.Locked, false);
                    button.Render(graphics, Color.FromArgb(255, 50, 100, 150));

                    button2 = GH_Capsule.CreateTextCapsule(ButtonBounds2, ButtonBounds2, GH_Palette.Transparent, "", new int[] { 0, 0, 5, 0 }, 0);
                    button2.Render(graphics, Selected, Owner.Locked, false);
                    button2.Render(graphics, Color.FromArgb(255, 230, 200, 10));


                    if (Globals.OpenThisShell[thisIndex2] == true)
                    {
                        System.Drawing.Drawing2D.LinearGradientBrush lgb = new System.Drawing.Drawing2D.LinearGradientBrush(
                            rec0.Location,
                            pythonRect.Location,
                            System.Drawing.Color.FromArgb(255, 0, 200, 0),  // Opaque red
                            System.Drawing.Color.FromArgb(255, 0, 200, 0)); // Opaque blue);
                        System.Drawing.Pen p = new System.Drawing.Pen(Color.Black, 1);
                        p.DashCap   = System.Drawing.Drawing2D.DashCap.Round;
                        p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                        Rectangle r5 = rec0;
                        r5.Inflate(5, 5);
                        // graphics.DrawLine(p, rec0.Location, pythonRect.Location);
                        graphics.DrawPath(p, RoundedRect(r5, 3));
                        //graphics.DrawRectangle(p, rec0);
                    }

                    StringFormat format = new StringFormat();
                    format.Alignment     = StringAlignment.Center;
                    format.LineAlignment = StringAlignment.Center;
                    format.Trimming      = StringTrimming.EllipsisCharacter;


                    Brush gg = new SolidBrush(Color.FromArgb(255, 50, 100, 150));
                    graphics.DrawString(Owner.NickName, GH_FontServer.Standard, gg, new PointF(rec0.Left, rec0.Bottom + 5));

                    button.Dispose();
                }
            }
Exemplo n.º 2
0
        // this function takes care of the drawing routines
        protected override void Render(Grasshopper.GUI.Canvas.GH_Canvas canvas, Graphics graphics,
                                       Grasshopper.GUI.Canvas.GH_CanvasChannel channel)
        {
            if (channel != Grasshopper.GUI.Canvas.GH_CanvasChannel.Objects)
            {
                return;
            }

            // render of original component
            //Bounds = _baseBounds;
            base.Render(canvas, graphics, channel);
            //Bounds = _thisBounds;

            int    width = GH_FontServer.StringWidth(Owner.NickName, GH_FontServer.Standard);
            PointF p     = new PointF(this.Pivot.X + width + 19, this.Pivot.Y - 7);

            List <double> probs = own.probabilities;

            PointF[] pts = getHistoPts(own.probabilities);

            if (own.draw_flag == "s")
            {
                pts = getPts(probs);
            }

            PointF maxPt = new PointF(0, 0);

            float ptY       = pts[0].Y;
            int   index_max = 0;

            for (int i = 0; i < pts.Length; i++)
            {
                if (pts[i].Y < ptY)
                {
                    ptY       = pts[i].Y;
                    index_max = i;
                }
            }

            maxPt = pts[index_max];


            // Create Pens
            System.Drawing.Pen pen2 = new System.Drawing.Pen(Brushes.Red, 2);
            System.Drawing.Pen pen  = new System.Drawing.Pen(Brushes.Black, 2);
            System.Drawing.Pen pen3 = new System.Drawing.Pen(Brushes.GhostWhite, 1);

            // Create Gradient Brush
            System.Drawing.Drawing2D.LinearGradientBrush lb = new System.Drawing.Drawing2D.LinearGradientBrush
                                                                  (new PointF(maxPt.X, maxPt.Y), new PointF(maxPt.X, this.Pivot.Y), Color.FromArgb(255, 0, 0),
                                                                  Color.FromArgb(255, 255, 255));
            System.Drawing.SolidBrush sb = new System.Drawing.SolidBrush(Color.FromArgb(70, 255, 255, 255));

            // Rui
            // render background bins
            RectangleF[] backgroundBins = getBackgroundBins(own.probabilities);
            graphics.DrawRectangles(pen3, backgroundBins);
            graphics.FillRectangles(sb, backgroundBins);

            backgroundBinBounds = backgroundBins;

            //Draw Polygon ouline and fill
            graphics.DrawPolygon(pen, pts);
            graphics.FillPolygon(lb, pts);

            //Owner.NickName = "Variable";

            // Draw probability value
            // string evidence = "Y<5

            string s = "P(MINIMIZE Y)=" + (this.bins((float)Owner.CurrentValue) * 100).ToString() + "%";

            //string s = (Owner.CurrentValue + 1).ToString();
            //double cv = Owner.CurrentValue;
            graphics.DrawString(s, GH_FontServer.Standard, Brushes.Black, pts[1].X + 15, (int)(this.Pivot.Y - 8 - glob.max_ht));
        }