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);
            }
        }
예제 #2
0
 //
 // Compare two structures for equality.
 //
 internal bool isStructureTheSame(IGH_Structure struct1, IGH_Structure struct2)
 {
     // m_owner.attr.Panel.Message(m_owner.NickName + ": Compare:");
     if (struct1 == null ^ struct2 == null)
     {
         //m_owner.attr.Panel.Message("    One of the structures is null");
         return(false);
     }
     if (struct1.IsEmpty ^ struct2.IsEmpty)
     {
         //m_owner.attr.Panel.Message("    One of the structures is empty");
         return(false);
     }
     if (struct1 != null && struct2 != null)
     {
         int pc = Math.Min(struct1.Paths.Count, struct2.Paths.Count);
         for (int i = 0; i < pc; i++)
         {
             IList b1 = struct1.get_Branch(struct1.Paths[i]);
             IList b2 = struct2.get_Branch(struct2.Paths[i]);
             int   bc = Math.Min(b1.Count, b2.Count);
             for (int j = 0; j < bc; j++)
             {
                 if (b1[j] is GH_Integer && b2[j] is GH_Integer)
                 {
                     GH_Integer n1 = (GH_Integer)b1[j];
                     GH_Integer n2 = (GH_Integer)b2[j];
                     if (n1.Value != n2.Value)
                     {
                         return(false);
                     }
                 }
                 else if (b1[j] is GH_Number && b2[j] is GH_Number)
                 {
                     GH_Number n1 = (GH_Number)b1[j];
                     GH_Number n2 = (GH_Number)b2[j];
                     if (Math.Round(n1.Value, 8) != Math.Round(n2.Value, 8))
                     {
                         return(false);
                     }
                 }
             }
         }
     }
     return(true);
 }
예제 #3
0
 //
 // Check if a structure is null.
 //
 internal bool isNull(IGH_Structure s)
 {
     if (!s.IsEmpty)
     {
         foreach (GH_Path p in s.Paths)
         {
             foreach (IGH_Goo item in s.get_Branch(p))
             {
                 if (item != null)
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
예제 #4
0
 internal bool isInLoop(IGH_Structure s)
 {
     foreach (GH_Path p in s.Paths)
     {
         foreach (IGH_Goo item in s.get_Branch(p))
         {
             if (item is GH_Boolean && !((GH_Boolean)item).Value)
             {
                 return(false);
             }
             else if (item is GH_Number && m_owner.CStep >= ((GH_Number)item).Value)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
예제 #5
0
        //
        // Duplicate a structure.
        //
        internal GH_Structure <IGH_Goo> duplicateStructure(IGH_Structure source)
        {
            GH_Structure <IGH_Goo> copy = new GH_Structure <IGH_Goo>();

            foreach (GH_Path p in source.Paths)
            {
                List <IGH_Goo> l = new List <IGH_Goo>();
                foreach (IGH_Goo item in source.get_Branch(p))
                {
                    if (item == null)
                    {
                        l.Add(null);
                    }
                    else
                    {
                        l.Add(item.Duplicate());
                    }
                }
                copy.AppendRange(l, p);
            }
            return(copy);
        }
예제 #6
0
        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);
예제 #7
0
 //test if all branches have exactly the same length. Assumes A and B have the same number of branches
 bool sameBranchLengths(IGH_Structure A, IGH_Structure B)
 {
     bool results = true;
     for (int i = 0; i < A.PathCount; i++)
     {
         if (A.get_Branch(i).Count != B.get_Branch(i).Count) results = false;
     }
     return results;
 }
예제 #8
0
 //test if all branches have 1 item
 bool oneItemPerBranch(IGH_Structure g)
 {
     bool results = true;
     for (int i = 0; i < g.PathCount;i++ )
     {
         if (g.get_Branch(i).Count != 1) results = false;
     }
     return results;
 }
예제 #9
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();
            }
        }