예제 #1
0
        public static bool TrySetDataList <T>(this GH_ComponentParamServer parameters, IGH_DataAccess DA, string name, Func <IEnumerable <T?> > list)
            where T : struct
        {
            var index = parameters.Output.IndexOf(name, out var _);

            return(index >= 0 && DA.SetDataList(index, list().Select(x => x.HasValue ? (object)x.Value : null)));
        }
        public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
        {
            DA.DisableGapLogic();
            Params.Input.ForEach(ighParam =>
            {
                var param      = ighParam as GenericAccessParam;
                var index      = Params.IndexOfInputParam(param.Name);
                var detachable = param.Detachable;
                var key        = detachable ? "@" + param.NickName : param.NickName;

                switch (param.Access)
                {
                case GH_ParamAccess.item:
                    object value = null;
                    DA.GetData(index, ref value);
                    inputData[key] = value;
                    break;

                case GH_ParamAccess.list:
                    var values = new List <object>();
                    DA.GetDataList(index, values);
                    inputData[key] = values;
                    break;

                case GH_ParamAccess.tree:
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            });
        }
예제 #3
0
        public static bool TryGetDataList <T>(this GH_ComponentParamServer parameters, IGH_DataAccess DA, string name, out T?[] values)
            where T : struct
        {
            var index = parameters.Input.IndexOf(name, out var param);

            if (param?.DataType > GH_ParamData.@void)
            {
                var     goos = Activator.CreateInstance(typeof(List <>).MakeGenericType(param.Type)) as ICollection;
                dynamic da   = DA;
                if (da.GetDataList(index, goos))
                {
                    values = new T?[goos.Count];

                    int i = 0;
                    foreach (var goo in goos.Cast <IGH_Goo>())
                    {
                        if (goo is object && goo.CastTo <T>(out var data))
                        {
                            values[i] = data;
                        }

                        i++;
                    }

                    return(true);
                }
            }

            values = default;
            return(false);
        }
예제 #4
0
        public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
        {
            if (CancellationToken.IsCancellationRequested)
            {
                return;
            }

            Point3d _location   = Point3d.Unset;
            double? _contour    = null;
            double? _denoise    = null;
            double? _generalize = null;
            string  _apiKey     = string.Empty;
            bool    _run        = false;

            DA.GetData(0, ref _location);
            DA.GetData(1, ref _contour);
            DA.GetData(2, ref _denoise);
            DA.GetData(3, ref _generalize);
            DA.GetData(4, ref _apiKey);
            DA.GetData(5, ref _run);

            Location   = _location;
            Contour    = _contour;
            Denoise    = _denoise;
            Generalize = _generalize;
            ApiKey     = _apiKey;
            Run        = _run;
        }
예제 #5
0
파일: Package.cs 프로젝트: KaivnD/npkg
        public IGH_Param CreateParameter(GH_ParameterSide side, int index)
        {
            switch (side)
            {
            case GH_ParameterSide.Input:
            {
                return(new Param_ScriptVariable
                    {
                        NickName = GH_ComponentParamServer.InventUniqueNickname("xyzuvwst", Params.Input),
                        Name = NickName,
                        Description = "Ghblock variable " + NickName,
                    });
            }

            case GH_ParameterSide.Output:
            {
                return(new Param_GenericObject
                    {
                        NickName = GH_ComponentParamServer.InventUniqueNickname("abcdefghijklmn", Params.Output),
                        Name = NickName,
                        Description = "Ghblock variable " + NickName,
                    });
            }

            default:
            {
                return(null);
            }
            }
        }
        public override void GetData(IGH_DataAccess da, GH_ComponentParamServer ghParams)
        {
            if (CancellationToken.IsCancellationRequested)
            {
                return;
            }

            // As per ExampleComponent.cs
            da.GetData(0, ref plane);
            da.GetData(1, ref radius0);
            da.GetData(2, ref radius1);
            da.GetData(3, ref turns);

            // As per Sample_UslessCyclesComponent
            int maxIterations = 100;

            da.GetData(4, ref maxIterations);
            if (maxIterations > 1000)
            {
                maxIterations = 1000;
            }
            if (maxIterations < 10)
            {
                maxIterations = 10;
            }
            MaxIterations = maxIterations;
        }
        public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
        {
            if (CancellationToken.IsCancellationRequested)
            {
                return;
            }

            GH_Structure <GH_String> _objects;

            DA.GetDataTree(0, out _objects);

            int branchIndex = 0;

            foreach (var list in _objects.Branches)
            {
                var path = _objects.Paths[branchIndex];
                foreach (var item in list)
                {
                    if (item.IsValid)
                    {
                        Objects.Append(item, path);
                    }
                    else
                    {
                        RuntimeMessages.Add((GH_RuntimeMessageLevel.Warning, $"Item at path {path}[{list.IndexOf(item)}][{list.IndexOf(item)}] is not valid."));
                    }
                }
                branchIndex++;
            }
        }
예제 #8
0
파일: Yelp.cs 프로젝트: blueherongis/Heron
        public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
        {
            if (CancellationToken.IsCancellationRequested)
            {
                return;
            }

            string _term     = string.Empty;
            string _location = string.Empty;
            double?_lat      = null;
            double?_lon      = null;
            int    _returns  = 0;
            string _apiKey   = string.Empty;

            DA.GetData(0, ref _term);
            DA.GetData(1, ref _location);
            DA.GetData(2, ref _lat);
            DA.GetData(3, ref _lon);
            DA.GetData(4, ref _returns);
            DA.GetData(5, ref _apiKey);

            Term     = _term;
            Location = _location;
            Lat      = _lat;
            Lon      = _lon;
            Returns  = _returns;
            ApiKey   = _apiKey;
        }
예제 #9
0
            public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
            {
                GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();

                if (DA.GetData(0, ref gh_typ))
                {
                    if (gh_typ.Value is GH_String)
                    {
                        string tempfile = "";
                        if (GH_Convert.ToString(gh_typ, out tempfile, GH_Conversion.Both))
                        {
                            if (!tempfile.EndsWith(".gwb"))
                            {
                                tempfile = tempfile + ".gwb";
                            }
                            GsaModel.FileName = tempfile;
                        }
                    }
                    else if (gh_typ.Value is GsaAPI.Model)
                    {
                        GsaAPI.Model model = new Model();
                        gh_typ.CastTo(ref model);
                        GsaModel.Model = model;
                    }
                }
            }
 public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
 {
     // Use DA.GetData as usual...
     DA.GetDataList(0, keys);
     DA.GetDataTree(1, out valueTree);
     iteration = DA.Iteration;
 }
 public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
 {
     DA.GetDataTree(0, out speckleObjects);
     speckleObjects.Graft(GH_GraftMode.GraftAll);
     this.Params = Params;
     (Parent as ExpandSpeckleObjectAsync).outputList = GetOutputList();
 }
        internal string NextUnusedName()
        {
            var unusedNames = GetUnusedNames();

            return(unusedNames.Count == 0
                ? defaultNickName + GH_ComponentParamServer.InventUniqueNickname(numbers, StrippedParamNames())
                : unusedNames[0]);
        }
예제 #13
0
 public IGH_Param CreateInputParam(GH_ParameterSide side, int index)
 {
     return(new Param_ScriptVariable
     {
         NickName = GH_ComponentParamServer.InventUniqueNickname("xyzuvwst", this.Params.Input),
         Name = NickName,
         Description = "Script variable " + NickName,
     });
 }
예제 #14
0
        public static T Input <T>(this GH_ComponentParamServer parameters, string name)
            where T : class, IGH_Param
        {
            if (IndexOf(parameters.Input, name, out var value) >= 0)
            {
                return(value as T);
            }

            return(default);
예제 #15
0
        public static void RemoveAllOutputs(this GH_ComponentParamServer Params)
        {
            int count = Params.Output.Count;

            for (int i = 0; i < count; ++i)
            {
                Params.UnregisterOutputParameter(Params.Output[0]);
            }
        }
예제 #16
0
        public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
        {
            var speckleObj = new GH_SpeckleBase();

            DA.GetData(0, ref speckleObj);
            DA.GetData(1, ref key);

            @base = speckleObj?.Value;
        }
        public IGH_Param CreateParameter(GH_ParameterSide side, int index)
        {
            Param_Number param = new Param_Number();

            param.Name        = param.NickName = GH_ComponentParamServer.InventUniqueNickname("list " + index.ToString(), Params.Input);
            param.Description = "Additional Parameters No." + (Params.Input.Count + 1).ToString();
            param.SetPersistentData(0.0);

            return(param);
        }
 public void VariableParameterMaintenance()
 {
     for (int i = 0; i < Params.Input.Count; i++)
     {
         if (string.IsNullOrEmpty(Params.Input[i].NickName))
         {
             Params.Input[i].NickName = GH_ComponentParamServer.InventUniqueNickname("params", Params.Input);
         }
     }
 }
예제 #19
0
        IGH_Param IGH_VariableParameterComponent.CreateParameter(GH_ParameterSide side, int index)
        {
            Param_GenericObject param = new Param_GenericObject();

            param.Name        = GH_ComponentParamServer.InventUniqueNickname("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Params.Input);
            param.NickName    = param.Name;
            param.Description = "Param" + (Params.Input.Count + 1);

            return(param);
        }
예제 #20
0
        public override void GetData(IGH_DataAccess DA, GH_ComponentParamServer Params)
        {
            Parent.ClearRuntimeMessages();
            DA.GetDataTree(0, out speckleObjects);
            speckleObjects.Graft(GH_GraftMode.GraftAll);
            var names = Params.Output.Select(p => p.Name);

            Console.WriteLine("Previous names:{0}", string.Join(", ", names));
            this.Params = Params;
        }
예제 #21
0
        public IGH_Param CreateParameter(GH_ParameterSide side, int index, bool is_twin)
        {
            switch (side)
            {
            case GH_ParameterSide.Input:
                return(new Param_ScriptVariable
                {
                    NickName = GH_ComponentParamServer.InventUniqueNickname("xyzuvwst", this.Params.Input),
                    Name = NickName,
                    Description = "Script variable " + NickName,
                    Access = GH_ParamAccess.item,
                    AllowTreeAccess = false,
                });

            case GH_ParameterSide.Output:
                IGH_Param p;
                if (!is_twin)
                {
                    if (used_script_variable_names == null)
                    {
                        used_script_variable_names = new List <string>();
                        script_variables_in_use    = new List <string>();
                    }
                    string script_variable = GH_ComponentParamServer.InventUniqueNickname("abcdefghijklmn", used_script_variable_names);
                    used_script_variable_names.Add(script_variable);

                    Param_GenericObject geom = new Param_GenericObject();
                    geom.NickName    = script_variable;
                    geom.Name        = NickName;
                    geom.Description = "Contains the translated geometry found in outie " + script_variable;
                    p = geom;
                }
                else
                {
                    if (Params.Output.Count <= 1)
                    {
                        return(null);
                    }
                    string nickname = AttNicknameFromGeomNickname(Params.Output[index - 1].NickName);
                    //Param_String prop = new Param_String();
                    GHParam_Decodes_Attributes prop = new GHParam_Decodes_Attributes();
                    prop.NickName        = nickname;
                    prop.Name            = nickname;
                    prop.Description     = "Contains the non-geometric properties of the geometry found in the parameter above";
                    prop.MutableNickName = false;
                    p = prop;
                }
                return(p);

            default: {
                return(null);
            }
            }
        }
예제 #22
0
        public void VariableParameterMaintenance()
        {
            var dynamicParams = Params.Input.ToList();
            var emptyParams   = dynamicParams.Where(p => p.NickName == String.Empty);

            foreach (var param in emptyParams)
            {
                var paramKey = GH_ComponentParamServer.InventUniqueNickname(numbers, StrippedParamNames());
                param.NickName = defaultNickName + paramKey;
            }
        }
예제 #23
0
        IGH_Param IGH_VariableParameterComponent.CreateParameter(GH_ParameterSide side, int index)
        {
            Param_Number param = new Param_Number();

            param.Name        = GH_ComponentParamServer.InventUniqueNickname("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Params.Input);
            param.NickName    = param.Name;
            param.Description = "Param" + (Params.Output.Count + 1);
            param.SetPersistentData(0.0);

            return(param);
        }
예제 #24
0
        public IGH_Param CreateParameter(GH_ParameterSide side, int index)
        {
            Param_GenericObject param = new Param_GenericObject();

            param.Name        = GH_ComponentParamServer.InventUniqueNickname("NewComponentMagicalName", Params.Input);
            param.NickName    = param.Name;
            param.Description = "Param" + (Params.Input.Count + 1);
            param.Access      = GH_ParamAccess.item;

            return(param);
        }
예제 #25
0
        IGH_Param IGH_VariableParameterComponent.CreateParameter(GH_ParameterSide side, int index)
        {
            Param_Number param = new Param_Number();

            param.Name        = "被乘数";
            param.NickName    = GH_ComponentParamServer.InventUniqueNickname("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Params.Input);
            param.Description = "参与乘法计算的数字";
            param.Access      = GH_ParamAccess.item;
            param.SetPersistentData(1);
            return(param);
        }
 public void VariableParameterMaintenance()
 {
     for (int i = 1; i < Params.Input.Count; i++)
     {
         IGH_Param param = Params.Input[i];
         param.Name        = GH_ComponentParamServer.InventUniqueNickname("Distance" + (i + 1), Params.Input);
         param.NickName    = "D" + (i + 1);
         param.Description = "Optional list of distances";
         param.Access      = GH_ParamAccess.list;
         param.Optional    = true;
     }
 }
        public IGH_Param CreateParameter(GH_ParameterSide side, int index)
        {
            var myParam = new GenericAccessParam
            {
                Name            = GH_ComponentParamServer.InventUniqueNickname("ABCD", Params.Input),
                MutableNickName = true,
                Optional        = true,
            };

            myParam.NickName = myParam.Name;
            return(myParam);
        }
예제 #28
0
        public IGH_Param CreateParameter(GH_ParameterSide side, int index)
        {
            Param_GenericObject param = new Param_GenericObject();

            param.Name        = String.Format("Chart{0}", index);
            param.NickName    = GH_ComponentParamServer.InventUniqueNickname("BCDEFGHIJKLMNOPQRSTUVWXYZ", Params.Input);
            param.Description = String.Format("Chart {0}", index);
            param.Access      = GH_ParamAccess.item;
            Params.RegisterInputParam(param, index);

            return(param);
        }
예제 #29
0
파일: 公共点.cs 프로젝트: zohozer/Vipers
        IGH_Param IGH_VariableParameterComponent.CreateParameter(GH_ParameterSide side, int index)
        {
            Param_Point param = new Param_Point();

            param.NickName    = GH_ComponentParamServer.InventUniqueNickname("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Params.Input);
            param.Name        = "列表" + param.NickName;
            param.Description = "一组点";
            param.Access      = GH_ParamAccess.list;
            param.SetPersistentData(Point3d.Unset);
            param.Hidden = true;
            return(param);
        }
예제 #30
0
        public IGH_Param CreateParameter(GH_ParameterSide side, int index)
        {
            Grasshopper.Kernel.Parameters.Param_GenericObject param = new Param_GenericObject();

            param.Name        = GH_ComponentParamServer.InventUniqueNickname("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Params.Input);
            param.NickName    = param.Name;
            param.Description = "Property Name";
            param.Optional    = true;
            param.Access      = GH_ParamAccess.item;

            param.ObjectChanged += (sender, e) => Debouncer.Start();

            return(param);
        }