public static void AddVolatileDataTree <T1, T2>(this IGH_Param param, IGH_Structure structure, Converter <T1, T2> converter)
            where T1 : IGH_Goo
            where T2 : IGH_Goo
        {
            for (int p = 0; p < structure.PathCount; ++p)
            {
                var path      = structure.get_Path(p);
                var srcBranch = structure.get_Branch(path);

                var data = srcBranch.As <T1>().Select(x => x == null ? default : converter(x));
                param.AddVolatileDataList(path, data);
            }
        }
        public static GH_Structure <T> DuplicateAs <T>(this IGH_Structure structure, bool shallowCopy)
            where T : IGH_Goo
        {
            // GH_Structure<T> constructor is a bit faster if shallowCopy is true because
            // it doesn't need to cast on each item.
            if (structure is GH_Structure <T> structureT)
            {
                return(new GH_Structure <T>(structureT, shallowCopy));
            }

            var result = new GH_Structure <T>();

            for (int p = 0; p < structure.PathCount; ++p)
            {
                var path      = structure.get_Path(p);
                var srcBranch = structure.get_Branch(path);

                var destBranch = result.EnsurePath(path);
                destBranch.Capacity = srcBranch.Count;

                var data = srcBranch.As <T>();
                if (!shallowCopy)
                {
                    data = data.Select(x => x?.Duplicate() is T t ? t : default);
示例#3
0
        protected override void Render(GH_Canvas canvas, Graphics graphics, GH_CanvasChannel channel)
        {
            if (channel == GH_CanvasChannel.Wires)
            {
                RenderIncomingWires(canvas.Painter, Owner.Sources, Owner.WireDisplay);
            }


            if (channel == GH_CanvasChannel.Objects)
            {
                base.Render(canvas, graphics, channel);

                GH_Palette palette = GH_Palette.Normal;

                switch (Owner.RuntimeMessageLevel)
                {
                case GH_RuntimeMessageLevel.Warning:
                    palette = GH_Palette.Warning;
                    break;

                case GH_RuntimeMessageLevel.Error:
                    palette = GH_Palette.Error;
                    break;
                }

                GH_Capsule capsule = GH_Capsule.CreateCapsule(Bounds, palette);
                capsule.AddInputGrip(InputGrip.Y);
                capsule.Render(graphics, Selected, Owner.Locked, true);

                capsule.Dispose();

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

                RectangleF textRectangle = Bounds;
                textRectangle.Height = 20;

                graphics.DrawString(Owner.NickName, GH_FontServer.Standard, Brushes.Black, textRectangle, format);



                int displayWidth  = (int)(Bounds.Width - padding * 2);
                int displayHeight = (int)(Bounds.Height - padding * 4);

                System.Drawing.Point position         = new System.Drawing.Point((int)(Bounds.X + padding), (int)(Bounds.Y + padding * 3));
                Rectangle            PatternRectangle = new Rectangle(position.X, position.Y, displayWidth, displayHeight);
                graphics.DrawRectangle(new Pen(Color.White), PatternRectangle);

                IGH_Structure data = Owner.VolatileData;
                if (data.PathCount != 0)
                {
                    GH_Path          path   = data.get_Path(0);
                    List <GH_Number> branch = data.get_Branch(path) as List <GH_Number>;

                    int   patternSize = branch.Count;
                    float width       = (float)Math.Ceiling(Math.Sqrt((double)patternSize));

                    if (displayWidth > displayHeight)
                    {
                        displaySize = displayHeight;
                    }
                    else
                    {
                        displaySize = displayWidth;
                    }

                    float rectSize = (float)(displaySize / width);

                    RectangleF[] rectangles = new RectangleF[patternSize];

                    for (int i = 0; i < patternSize; i++)
                    {
                        PointF pos = new PointF((float)(Bounds.X + padding), (float)(Bounds.Y + padding * 3));
                        pos = new PointF(pos.X + rectSize * (float)Math.Floor(i % width), pos.Y + rectSize * (float)Math.Floor(i / width));
                        RectangleF content = new RectangleF(pos.X, pos.Y, rectSize, rectSize);
                        rectangles[i] = content;
                        SolidBrush brush;

                        if ((int)branch[i].Value == 0)
                        {
                            brush = new SolidBrush(Color.White);
                        }
                        else if ((int)branch[i].Value == 1)
                        {
                            brush = new SolidBrush(Color.Black);
                        }
                        else
                        {
                            brush = new SolidBrush(Color.Orange);
                        }

                        graphics.FillRectangle(brush, rectangles[i]);
                    }
                }

                format.Dispose();
            }
        }