public override void DoWork(Action <string, double> ReportProgress, Action Done)
        {
            Parent.Message = "Extending...";
            var path = new GH_Path(iteration);

            if (valueTree.PathExists(path))
            {
                var values = valueTree.get_Branch(path) as List <IGH_Goo>;
                // Input is a list of values. Assign them directly
                if (keys.Count != values?.Count)
                {
                    Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Key and Value lists are not the same length.");
                    Done();
                }

                AssignToObject(@base, keys, values);
            }
            else if (valueTree.Branches.Count == 1)
            {
                var values = valueTree.Branches[0];
                if (keys.Count != values.Count)
                {
                    Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Key and Value lists are not the same length.");
                    Done();
                }

                // Input is just one list, so use it.
                AssignToObject(@base, keys, values);
            }
            else
            {
                // Input is a tree, meaning it's values are either lists or trees.
                var subTree = Utilities.GetSubTree(valueTree, path);
                var index   = 0;
                keys.ForEach(key =>
                {
                    var subPath = new GH_Path(index);
                    if (subTree.PathExists(subPath))
                    {
                        // Value is a list, convert and assign.
                        var list = subTree.get_Branch(subPath) as List <IGH_Goo>;
                        if (list?.Count > 0)
                        {
                            @base[key] = list.Select(goo => Utilities.TryConvertItemToSpeckle(goo, Converter)).ToList();
                        }
                        ;
                    }
                    else
                    {
                        // TODO: Handle tree conversions
                        Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Cannot handle trees yet");
                    }

                    index++;
                });
            }

            Done();
        }
Beispiel #2
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Initialize local variables
            var valueTree = new GH_Structure <IGH_Goo>();
            var keys      = new List <string>();

            // Get data from inputs
            if (!DA.GetDataList(0, keys))
            {
                return;
            }
            if (!DA.GetDataTree(1, out valueTree))
            {
                return;
            }

            // Create a path from the current iteration
            var searchPath = new GH_Path(DA.Iteration);

            // Grab the corresponding subtree from the value input tree.
            var  subTree    = Utilities.GetSubTree(valueTree, searchPath);
            Base speckleObj = new Base();

            // Find the list or subtree belonging to that path
            if (valueTree.PathExists(searchPath) || valueTree.Paths.Count == 1)
            {
                var list = valueTree.Paths.Count == 1 ? valueTree.Branches[0] : valueTree.get_Branch(searchPath);
                // We got a list of values
                var ind = 0;
                keys.ForEach(key =>
                {
                    if (ind < list.Count)
                    {
                        speckleObj[key] = Utilities.TryConvertItemToSpeckle(list[ind], Converter);
                    }
                    ind++;
                });
            }
            else
            {
                // We got a tree of values

                // Create the speckle object with the specified keys
                var index = 0;
                keys.ForEach(key =>
                {
                    var itemPath = new GH_Path(index);
                    //TODO: Grab conversion methods and implement branch handling.
                    var branch = subTree.get_Branch(itemPath);
                    if (branch != null)
                    {
                        List <object> objs = new List <object>();
                        foreach (var goo in branch)
                        {
                            objs.Add(Utilities.TryConvertItemToSpeckle(goo, Converter));
                        }

                        if (objs.Count > 0)
                        {
                            speckleObj[key] = objs;
                        }
                    }

                    index++;
                });
            }

            // Set output
            DA.SetData(0, new GH_SpeckleBase {
                Value = speckleObj
            });
        }
        public Base DoWork(Base @base, List <string> keys, GH_Structure <IGH_Goo> valueTree)
        {
            try
            {
                // 👉 Checking for cancellation!
                if (CancelToken.IsCancellationRequested)
                {
                    return(null);
                }

                // Create a path from the current iteration
                var searchPath = new GH_Path(RunCount - 1);

                // Grab the corresponding subtree from the value input tree.
                var subTree = Utilities.GetSubTree(valueTree, searchPath);
                // Find the list or subtree belonging to that path
                if (valueTree.PathExists(searchPath) || valueTree.Paths.Count == 1)
                {
                    var list = valueTree.Paths.Count == 1 ? valueTree.Branches[0] : valueTree.get_Branch(searchPath);
                    // We got a list of values
                    var ind       = 0;
                    var hasErrors = false;
                    keys.ForEach(key =>
                    {
                        if (ind < list.Count)
                        {
                            try
                            {
                                if (Converter != null)
                                {
                                    @base[key] = Utilities.TryConvertItemToSpeckle(list[ind], Converter);
                                }
                                else
                                {
                                    @base[key] = list[ind];
                                }
                            }
                            catch (Exception e)
                            {
                                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
                                hasErrors = true;
                            }
                        }

                        ind++;
                    });
                    if (hasErrors)
                    {
                        @base = null;
                    }
                }
                else
                {
                    // We got a tree of values

                    // Create the speckle object with the specified keys
                    var index     = 0;
                    var hasErrors = false;
                    keys.ForEach(key =>
                    {
                        var itemPath = new GH_Path(index);

                        var branch = subTree.get_Branch(itemPath);
                        if (branch != null)
                        {
                            var objs = new List <object>();
                            foreach (var goo in branch)
                            {
                                if (Converter != null)
                                {
                                    objs.Add(Utilities.TryConvertItemToSpeckle(goo, Converter));
                                }
                                else
                                {
                                    objs.Add(goo);
                                }
                            }

                            if (objs.Count > 0)
                            {
                                try
                                {
                                    @base[key] = objs;
                                }
                                catch (Exception e)
                                {
                                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
                                    hasErrors = true;
                                }
                            }
                        }

                        index++;
                    });

                    if (hasErrors)
                    {
                        @base = null;
                    }
                }

                return(@base);
            }
            catch (Exception e)
            {
                // If we reach this, something happened that we weren't expecting...
                Log.CaptureException(e);
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Something went terribly wrong... " + e.Message);
                return(null);
            }
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Init local variables
            GH_SpeckleBase ghBase = null;
            var            keys   = new List <string>();

            // Grab data from input
            if (!DA.GetData(0, ref ghBase))
            {
                return;
            }
            if (!DA.GetDataList(1, keys))
            {
                return;
            }
            if (!DA.GetDataTree(2, out GH_Structure <IGH_Goo> valueTree))
            {
                return;
            }

            // TODO: Handle data validation
            var b = ghBase.Value.ShallowCopy();

            CleanDeletedKeys(b, keys);
            // Search for the path coinciding with the current iteration.
            var path = new GH_Path(DA.Iteration);

            if (valueTree.PathExists(path))
            {
                var values = valueTree.get_Branch(path) as List <IGH_Goo>;
                // Input is a list of values. Assign them directly
                if (keys.Count != values?.Count)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Key and Value lists are not the same length.");
                    return;
                }
                AssignToObject(b, keys, values);
            }
            else if (valueTree.Branches.Count == 1)
            {
                var values = valueTree.Branches[0];
                if (keys.Count != values.Count)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Key and Value lists are not the same length.");
                    return;
                }
                // Input is just one list, so use it.
                AssignToObject(b, keys, values);
            }
            else
            {
                // Input is a tree, meaning it's values are either lists or trees.
                var subTree = Utilities.GetSubTree(valueTree, path);
                int index   = 0;
                keys.ForEach(key =>
                {
                    var subPath = new GH_Path(index);
                    if (subTree.PathExists(subPath))
                    {
                        // Value is a list, convert and assign.
                        var list = subTree.get_Branch(subPath) as List <IGH_Goo>;
                        if (list?.Count > 0)
                        {
                            var converted = list.Select(goo => Utilities.TryConvertItemToSpeckle(goo, Converter)).ToList();
                            b[key]        = converted;
                        }
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Cannot handle trees yet");
                    }
                    index++;
                });
            }

            lastSolutionKeys = keys;
            DA.SetData(0, new GH_SpeckleBase {
                Value = b
            });
        }
Beispiel #5
0
        public override void DoWork(Action <string, double> ReportProgress, Action Done)
        {
            // 👉 Checking for cancellation!
            if (CancellationToken.IsCancellationRequested)
            {
                return;
            }
            Parent.Message = "Creating...";
            // Create a path from the current iteration
            var searchPath = new GH_Path(iteration);

            // Grab the corresponding subtree from the value input tree.
            var subTree = Utilities.GetSubTree(valueTree, searchPath);

            speckleObj = new Base();
            // Find the list or subtree belonging to that path
            if (valueTree.PathExists(searchPath) || valueTree.Paths.Count == 1)
            {
                var list = valueTree.Paths.Count == 1 ? valueTree.Branches[0] : valueTree.get_Branch(searchPath);
                // We got a list of values
                var ind = 0;
                keys.ForEach(key =>
                {
                    if (ind < list.Count)
                    {
                        speckleObj[key] = Utilities.TryConvertItemToSpeckle(list[ind], Converter);
                    }
                    ind++;
                });
            }
            else
            {
                // We got a tree of values

                // Create the speckle object with the specified keys
                var index = 0;
                keys.ForEach(key =>
                {
                    var itemPath = new GH_Path(index);

                    var branch = subTree.get_Branch(itemPath);
                    if (branch != null)
                    {
                        var objs = new List <object>();
                        foreach (var goo in branch)
                        {
                            objs.Add(Utilities.TryConvertItemToSpeckle(goo, Converter));
                        }

                        if (objs.Count > 0)
                        {
                            speckleObj[key] = objs;
                        }
                    }

                    index++;
                });
            }
            // --> Report progress if necessary
            // ReportProgress(Id, percentage);

            // Call Done() to signal it's finished.
            Done();
        }
Beispiel #6
0
        public override void DoWork(Action <string, double> ReportProgress, Action Done)
        {
            try
            {
                // 👉 Checking for cancellation!
                if (CancellationToken.IsCancellationRequested)
                {
                    return;
                }
                Parent.Message = "Creating...";
                // Create a path from the current iteration
                var searchPath = new GH_Path(iteration);

                // Grab the corresponding subtree from the value input tree.
                var subTree = Utilities.GetSubTree(valueTree, searchPath);
                speckleObj = new Base();
                // Find the list or subtree belonging to that path
                if (valueTree.PathExists(searchPath) || valueTree.Paths.Count == 1)
                {
                    var list = valueTree.Paths.Count == 1 ? valueTree.Branches[0] : valueTree.get_Branch(searchPath);
                    // We got a list of values
                    var ind       = 0;
                    var hasErrors = false;
                    keys.ForEach(key =>
                    {
                        if (ind < list.Count)
                        {
                            try
                            {
                                speckleObj[key] = Utilities.TryConvertItemToSpeckle(list[ind], Converter);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                                Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
                                Parent.Message = "Error";
                                hasErrors      = true;
                            }
                        }

                        ind++;
                    });
                    if (hasErrors)
                    {
                        return;
                    }
                }
                else
                {
                    // We got a tree of values

                    // Create the speckle object with the specified keys
                    var index = 0;
                    keys.ForEach(key =>
                    {
                        var itemPath = new GH_Path(index);

                        var branch = subTree.get_Branch(itemPath);
                        if (branch != null)
                        {
                            var objs = new List <object>();
                            foreach (var goo in branch)
                            {
                                objs.Add(Utilities.TryConvertItemToSpeckle(goo, Converter));
                            }

                            if (objs.Count > 0)
                            {
                                try
                                {
                                    speckleObj[key] = objs;
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                    Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.Message);
                                    return;
                                }
                            }
                        }

                        index++;
                    });
                }
                // --> Report progress if necessary
                // ReportProgress(Id, percentage);

                // Call Done() to signal it's finished.
                Done();
            }
            catch (Exception e)
            {
                // If we reach this, something happened that we weren't expecting...
                Log.CaptureException(e);
                Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Something went terribly wrong... " + e.Message);
                Parent.Message = "Error";
            }
        }
        public override void DoWork(Action <string, double> ReportProgress, Action Done)
        {
            try
            {
                Parent.Message = "Extending...";
                var path = new GH_Path(iteration);
                if (valueTree.PathExists(path))
                {
                    var values = valueTree.get_Branch(path) as List <IGH_Goo>;
                    // Input is a list of values. Assign them directly
                    if (keys.Count != values?.Count)
                    {
                        Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Key and Value lists are not the same length.");
                        Parent.Message = "Error";
                        return;
                    }

                    AssignToObject(@base, keys, values);
                }
                else if (valueTree.Branches.Count == 1)
                {
                    var values = valueTree.Branches[0];
                    if (keys.Count != values.Count)
                    {
                        Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Key and Value lists are not the same length.");
                        Parent.Message = "Error";
                        return;
                    }

                    // Input is just one list, so use it.
                    AssignToObject(@base, keys, values);
                }
                else
                {
                    // Input is a tree, meaning it's values are either lists or trees.
                    var subTree   = Utilities.GetSubTree(valueTree, path);
                    var index     = 0;
                    var foundTree = false;
                    keys.ForEach(key =>
                    {
                        var subPath = new GH_Path(index);
                        if (subTree.PathExists(subPath))
                        {
                            // Value is a list, convert and assign.
                            var list = subTree.get_Branch(subPath) as List <IGH_Goo>;
                            if (list?.Count > 0)
                            {
                                try
                                {
                                    @base[key] = list.Select(goo => Utilities.TryConvertItemToSpeckle(goo, Converter)).ToList();
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                }
                            }
                            ;
                        }
                        else
                        {
                            foundTree = true;
                        }

                        index++;
                    });

                    if (foundTree)
                    {
                        // TODO: Handle tree conversions
                        Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Cannot handle trees yet");
                        Parent.Message = "Error";
                    }
                }

                Done();
            }
            catch (Exception e)
            {
                // If we reach this, something happened that we weren't expecting...
                Log.CaptureException(e);
                Parent.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Something went terribly wrong... " + e.Message);
                Parent.Message = "Error";
            }
        }