예제 #1
0
        public void Update(string name)
        {
            Head           head     = directory.GetHead();
            Commit         target   = head.GetTarget();
            BranchMetadata metadata = new BranchMetadata();
            Branch         branch   = new Branch(target, metadata, name);

            directory.CreateBranch(branch);
        }
예제 #2
0
        public Branch GetBranch(DirectoryStructure directory)
        {
            if (TargetHash == null)
            {
                throw new FormatException("TargetHash should not be null");
            }
            Commit target = directory.GetCommit(TargetHash);

            if (Metadata == null)
            {
                throw new FormatException("Metadata should not be null");
            }
            BranchMetadata metadata = Metadata.GetMetadata();

            if (Name == null)
            {
                throw new FormatException("Name should not be null");
            }
            return(new Branch(target, metadata, Name));
        }
예제 #3
0
 public static Guid?GetId(this IBranch b)
 {
     return(BranchMetadata.ForBranch(b).Id);
 }
예제 #4
0
 public static IBranch SetId(this IBranch b, Guid?id)
 {
     BranchMetadata.ForBranch(b).Id = id;
     return(b);
 }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Grasshopper.Kernel.Data.GH_Structure <IGH_Goo> elementsToAdd = new Grasshopper.Kernel.Data.GH_Structure <IGH_Goo>();
            double        width          = 0;
            double        height         = 0;
            List <string> rowDefinitions = new List <string>();
            List <string> colDefinitions = new List <string>();
            List <int>    memberships    = new List <int>();


            if (!DA.GetDataTree <IGH_Goo>(0, out elementsToAdd))
            {
                return;
            }
            bool hasMemberships = DA.GetDataList <int>("Grid Membership", memberships);
            bool hasWidth       = DA.GetData <double>("Width", ref width);
            bool hasHeight      = DA.GetData <double>("Height", ref height);

            bool hasRowDefs = DA.GetDataList <string>("Row Definitions", rowDefinitions);
            bool hasColDefs = DA.GetDataList <string>("Column Definitions", colDefinitions);

            if (hasMemberships)
            {
                if (memberships.Count != elementsToAdd.Branches.Count)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Grid Membership list length must equal the number of Elements branches.");
                    return;
                }
            }
            else
            {
                // Create a default list of a single branch grouping to apply to all trees
                memberships = new List <int>()
                {
                    0
                };
            }

            int[] defaultMembership = { 0 };

            // Create an array of the membership values
            int[] membershipArray = hasMemberships ? memberships.ToArray() : defaultMembership;

            // Create empty list of branch metadata and populate with values
            List <BranchMetadata> branchMetaData = new List <BranchMetadata>();

            for (int i = 0; i < elementsToAdd.Branches.Count(); i++)
            {
                int myMembership = hasMemberships ? membershipArray[i] : 0;

                BranchMetadata bm = new BranchMetadata(i, myMembership);
                branchMetaData.Add(bm);
            }

            // Sort and group the metadata
            var branchGroupings = branchMetaData
                                  .OrderBy(b => b.membershipIndex)
                                  .GroupBy(b => b.membershipIndex);


            // create an empty List of grids and populate

            List <Grid> grids = new List <Grid>();

            foreach (var group in branchGroupings)
            {
                //initialize a grid
                Grid grid = new Grid();
                grid.HorizontalAlignment = HorizontalAlignment.Left;
                grid.VerticalAlignment   = VerticalAlignment.Top;
                grid.Name = "GH_Grid";
                if (hasWidth)
                {
                    grid.Width = width;
                }
                else
                {
                    grid.HorizontalAlignment = HorizontalAlignment.Stretch;
                }
                if (hasHeight)
                {
                    grid.Height = height;
                }
                else
                {
                    grid.VerticalAlignment = VerticalAlignment.Stretch;
                }

                // Add grid to List
                grids.Add(grid);
            }

            // Populate the Grids (should this be done before adding the grids to the List?)

            foreach (var group in branchGroupings)
            {
                // Count the number of branches in this array
                int currentBranchCount = group.Count();

                //set up a "GridLengthConverter" to handle parsing our strings.
                GridLengthConverter gridLengthConverter = new GridLengthConverter();

                //set up rows and columns if present
                if (hasColDefs)
                {
                    for (int i = 0; i < currentBranchCount; i++)
                    {
                        ColumnDefinition cd = new ColumnDefinition();
                        cd.Width = (GridLength)gridLengthConverter.ConvertFromString(colDefinitions[i % colDefinitions.Count]);  // use repeating pattern of supplied list
                        // Note: group.Key is the index of the group/grid
                        grids[group.Key].ColumnDefinitions.Add(cd);
                    }
                }

                if (hasRowDefs)
                {
                    int maxCount = 0;

                    // Find the count of the longest list
                    foreach (BranchMetadata md in group)
                    {
                        // get the count of data from the branch
                        var myCount = elementsToAdd.get_Branch(elementsToAdd.get_Path(md.branchIndex)).Count;

                        if (myCount > maxCount)
                        {
                            maxCount = myCount;
                        }
                    }

                    // Build up the row heights based on a repeating pattern
                    for (int i = 0; i < maxCount; i++)
                    {
                        RowDefinition rd = new RowDefinition();
                        rd.Height = (GridLength)gridLengthConverter.ConvertFromString(rowDefinitions[i % rowDefinitions.Count]);  // use repeating pattern of supplied list
                        // Note: group.Key is the index of the group/grid
                        grids[group.Key].RowDefinitions.Add(rd);
                    }
                }

                // Set up a counter for iterating through the appropriate number of columns
                int currentColumn = 0;

                // Populate the Grids with Elements
                foreach (BranchMetadata md in group)
                {
                    // Get each branch referenced in the metadata
                    var branch = elementsToAdd.get_Branch(elementsToAdd.get_Path(md.branchIndex));


                    //for all the elements in each branch
                    for (int j = 0; j < branch.Count; j++)
                    {
                        UIElement_Goo u = branch[j] as UIElement_Goo;
                        //make sure it doesn't already have a parent
                        HUI_Util.removeParent(u.element);
                        FrameworkElement fe = u.element as FrameworkElement;
                        if (fe != null)
                        {
                            // set its alignment to stretch
                            // this will allow elements like sliders, pulldowns, and separators to fill the cell
                            fe.HorizontalAlignment = HorizontalAlignment.Stretch;
                            fe.VerticalAlignment   = VerticalAlignment.Stretch;

                            //set up row and column positioning
                            Grid.SetColumn(fe, currentColumn);
                            Grid.SetRow(fe, j);
                        }

                        //add it to the grid
                        grids[group.Key].Children.Add(u.element);
                    }

                    // Increment the column index
                    currentColumn++;
                }
            }

            // Create the list of Elements and add each grid
            List <UIElement_Goo> output = new List <UIElement_Goo>();

            foreach (Grid g in grids)
            {
                output.Add(new UIElement_Goo(g, "Simple Grid", InstanceGuid, DA.Iteration));
            }

            //pass the grids out
            DA.SetDataList("Simple Grid", output);
        }
예제 #6
0
 public BranchMetadataJSON(BranchMetadata metadata)
 {
     Hash = metadata.Hash;
 }