Beispiel #1
0
        /*******************************************/

        public virtual void VariableParameterMaintenance()
        {
            foreach (IGH_Param param in Params.Input)
            {
                Param_Variable paramScript = param as Param_Variable;
                if (paramScript != null)
                {
                    paramScript.PossibleHints = Helpers.AvailableHints;
                }
            }
        }
Beispiel #2
0
        /*************************************/

        public virtual IGH_Param CreateParameter(GH_ParameterSide side, int index)
        {
            string         name  = GH_ComponentParamServer.InventUniqueNickname("xyzuvw", this.Params.Input);
            Param_Variable param = new Param_Variable
            {
                NickName      = name,
                Name          = name,
                SelectedHint  = new GH_NullHint(),
                PossibleHints = Helpers.AvailableHints,
            };

            // Updating the caller with the parameter that Grasshopper just added
            Caller.AddInput(index, param.NickName, param.Type());
            return(param);
        }
        /*************************************/

        public List <T> GetDataList <T>(int index)
        {
            if (GH_Accessor == null)
            {
                return(new List <T>());
            }

            IGH_TypeHint   hint        = null;
            Param_Variable scriptParam = Inputs[index] as Param_Variable;

            if (scriptParam != null)
            {
                hint = scriptParam.SelectedHint;
            }

            List <IGH_Goo> goo = new List <IGH_Goo>();

            GH_Accessor.GetDataList <IGH_Goo>(index, goo);
            return(goo.Select(x => Helpers.IFromGoo <T>(x, hint)).ToList());
        }
        /*************************************/
        /**** Input Getter Methods        ****/
        /*************************************/

        public T GetDataItem <T>(int index)
        {
            if (GH_Accessor == null)
            {
                return(default(T));
            }

            IGH_Goo goo = null;

            GH_Accessor.GetData(index, ref goo);

            IGH_TypeHint   hint        = null;
            Param_Variable scriptParam = Inputs[index] as Param_Variable;

            if (scriptParam != null)
            {
                hint = scriptParam.SelectedHint;
            }

            return(Helpers.IFromGoo <T>(goo, hint));
        }
        /*************************************/

        public List <List <T> > GetDataTree <T>(int index)
        {
            if (GH_Accessor == null || Inputs.Count <= index)
            {
                return(new List <List <T> >());
            }

            IGH_TypeHint   hint        = null;
            Param_Variable scriptParam = Inputs[index] as Param_Variable;

            if (scriptParam != null)
            {
                hint = scriptParam.SelectedHint;
            }

            IGH_Param param = Inputs[index];

            return(param.VolatileData.StructureProxy.Select(x => x.Cast <IGH_Goo>().Select(y => Helpers.IFromGoo <T>(y, hint)).ToList()).ToList());

            // This shows that using the GetDataTree method from GH is actually giving the exact same result with the exact same problem of collecting the entire data instead of a subtree

            /*IGH_Structure goo = Activator.CreateInstance(typeof(GH_Structure<>).GetGenericTypeDefinition().MakeGenericType(new Type[] { param.Type })) as IGH_Structure;
             * return ConvertDataTree(goo as dynamic, index, new List<List<T>>());*/
        }
Beispiel #6
0
        /*************************************/
        /**** Public Methods              ****/
        /*************************************/

        public static IGH_Param ToGH_Param(this ParamInfo info)
        {
            UnderlyingType subType = info.DataType.UnderlyingType();
            IGH_Param      param;

            switch (subType.Type.FullName)
            {
            case "System.Boolean":
                param = new Param_Boolean();
                break;

            case "System.Drawing.Color":
                param = new Param_Colour();
                break;

            case "System.DateTime":
                param = new Param_Time();
                break;

            case "System.Double":
                param = new Param_Number();
                break;

            case "System.Guid":
                param = new Param_Guid();
                break;

            case "System.Int16":
            case "System.Int32":
                param = new Param_Integer();
                break;

            case "System.Int64":
                param = new Param_Time();
                break;

            case "System.String":
                param = new Param_String();
                break;

            case "System.Type":
                param = new Param_Type();
                break;

            default:
                Type type = subType.Type;
                if (typeof(IGeometry).IsAssignableFrom(type))
                {
                    param = new Param_BHoMGeometry();
                }
                else if (typeof(IBHoMObject).IsAssignableFrom(type))
                {
                    param = new Param_BHoMObject();
                }
                else if (typeof(IObject).IsAssignableFrom(type))
                {
                    param = new Param_IObject();
                }
                else if (typeof(Enum).IsAssignableFrom(type))
                {
                    param = new Param_Enum();
                }
                else if (typeof(IDictionary).IsAssignableFrom(type))
                {
                    param = new Param_Dictionary();
                }
                else if (typeof(BHoMAdapter).IsAssignableFrom(type))
                {
                    param = new Param_BHoMAdapter();
                }
                else
                {
                    param = new Param_Variable
                    {
                        SelectedHint  = new GH_NullHint(),
                        PossibleHints = Helpers.AvailableHints,
                    };
                }

                break;
            }

            param.Access      = (GH_ParamAccess)subType.Depth;
            param.Description = info.Description;
            param.Name        = info.Name;
            param.NickName    = info.Name;
            param.Optional    = !info.IsRequired;

            //TODO: Is it necessary to react to param.AttributesChanged ?

            if (param is IBHoMParam)
            {
                ((IBHoMParam)param).ObjectType = subType.Type;
            }

            try
            {
                if (info.HasDefaultValue && !info.IsRequired)
                {
                    var data = Helpers.IToGoo(info.DefaultValue as dynamic);
                    SetPersistentData(param as dynamic, data as dynamic);
                }
            }
            catch { }

            return(param);
        }