Beispiel #1
0
        void DefineInputsAndOutputs()
        {
            ClearRuntimeMessages();
            string description = _remoteDefinition.GetDescription();

            if (!string.IsNullOrWhiteSpace(description) && !Description.Equals(description))
            {
                Description = description;
            }
            var inputs  = _remoteDefinition.GetInputParams();
            var outputs = _remoteDefinition.GetOutputParams();

            bool buildInputs  = inputs != null;
            bool buildOutputs = outputs != null;

            // check to see if the existing params match
            if (buildInputs && Params.Input.Count == inputs.Count)
            {
                buildInputs = false;
                foreach (var param in Params.Input.ToArray())
                {
                    if (!inputs.ContainsKey(param.Name))
                    {
                        buildInputs = true;
                        break;
                    }
                }
            }
            if (buildOutputs && Params.Output.Count == outputs.Count)
            {
                buildOutputs = false;
                foreach (var param in Params.Output.ToArray())
                {
                    if (!outputs.ContainsKey(param.Name))
                    {
                        buildOutputs = true;
                        break;
                    }
                }
            }

            // Remove all existing inputs and outputs
            if (buildInputs)
            {
                foreach (var param in Params.Input.ToArray())
                {
                    Params.UnregisterInputParameter(param);
                }
            }
            if (buildOutputs)
            {
                foreach (var param in Params.Output.ToArray())
                {
                    Params.UnregisterOutputParameter(param);
                }
            }

            bool recompute = false;

            if (buildInputs && inputs != null)
            {
                bool containsEmptyDefaults = false;
                var  mgr = CreateInputManager();
                foreach (var kv in inputs)
                {
                    string name = kv.Key;
                    var(input, param) = kv.Value;
                    GH_ParamAccess access = GH_ParamAccess.list;
                    if (input.AtLeast == 1 && input.AtMost == 1)
                    {
                        access = GH_ParamAccess.item;
                    }
                    string inputDescription = name;
                    if (!string.IsNullOrWhiteSpace(input.Description))
                    {
                        inputDescription = input.Description;
                    }
                    if (input.Default == null)
                    {
                        containsEmptyDefaults = true;
                    }
                    switch (param)
                    {
                    case Grasshopper.Kernel.Parameters.Param_Arc _:
                        mgr.AddArcParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Boolean _:
                        if (input.Default == null)
                        {
                            mgr.AddBooleanParameter(name, name, inputDescription, access);
                        }
                        else
                        {
                            mgr.AddBooleanParameter(name, name, inputDescription, access, Convert.ToBoolean(input.Default));
                        }
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Box _:
                        mgr.AddBoxParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Brep _:
                        mgr.AddBrepParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Circle _:
                        mgr.AddCircleParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Colour _:
                        mgr.AddColourParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Complex _:
                        mgr.AddComplexNumberParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Culture _:
                        mgr.AddCultureParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Curve _:
                        mgr.AddCurveParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Field _:
                        mgr.AddFieldParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_FilePath _:
                        if (input.Default == null)
                        {
                            mgr.AddTextParameter(name, name, inputDescription, access);
                        }
                        else
                        {
                            mgr.AddTextParameter(name, name, inputDescription, access, input.Default.ToString());
                        }
                        break;

                    case Grasshopper.Kernel.Parameters.Param_GenericObject _:
                        throw new Exception("generic param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Geometry _:
                        mgr.AddGeometryParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Group _:
                        throw new Exception("group param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Guid _:
                        throw new Exception("guid param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Integer _:
                        if (input.Default == null)
                        {
                            mgr.AddIntegerParameter(name, name, inputDescription, access);
                        }
                        else
                        {
                            mgr.AddIntegerParameter(name, name, inputDescription, access, Convert.ToInt32(input.Default));
                        }
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Interval _:
                        mgr.AddIntervalParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Interval2D _:
                        mgr.AddInterval2DParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_LatLonLocation _:
                        throw new Exception("latlonlocation param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Line _:
                        if (input.Default == null)
                        {
                            mgr.AddLineParameter(name, name, inputDescription, access);
                        }
                        else
                        {
                            mgr.AddLineParameter(name, name, inputDescription, access, JsonConvert.DeserializeObject <Line>(input.Default.ToString()));
                        }
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Matrix _:
                        mgr.AddMatrixParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Mesh _:
                        mgr.AddMeshParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_MeshFace _:
                        mgr.AddMeshFaceParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_MeshParameters _:
                        throw new Exception("meshparameters paran not supported");

                    case Grasshopper.Kernel.Parameters.Param_Number _:
                        if (input.Default == null)
                        {
                            mgr.AddNumberParameter(name, name, inputDescription, access);
                        }
                        else
                        {
                            mgr.AddNumberParameter(name, name, inputDescription, access, Convert.ToDouble(input.Default));
                        }
                        break;

                    //case Grasshopper.Kernel.Parameters.Param_OGLShader:
                    case Grasshopper.Kernel.Parameters.Param_Plane _:
                        if (input.Default == null)
                        {
                            mgr.AddPlaneParameter(name, name, inputDescription, access);
                        }
                        else
                        {
                            mgr.AddPlaneParameter(name, name, inputDescription, access, JsonConvert.DeserializeObject <Plane>(input.Default.ToString()));
                        }
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Point _:
                        if (input.Default == null)
                        {
                            mgr.AddPointParameter(name, name, inputDescription, access);
                        }
                        else
                        {
                            mgr.AddPointParameter(name, name, inputDescription, access, JsonConvert.DeserializeObject <Point3d>(input.Default.ToString()));
                        }
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Rectangle _:
                        mgr.AddRectangleParameter(name, name, inputDescription, access);
                        break;

                    //case Grasshopper.Kernel.Parameters.Param_ScriptVariable _:
                    case Grasshopper.Kernel.Parameters.Param_String _:
                        if (input.Default == null)
                        {
                            mgr.AddTextParameter(name, name, inputDescription, access);
                        }
                        else
                        {
                            mgr.AddTextParameter(name, name, inputDescription, access, input.Default.ToString());
                        }
                        break;

                    case Grasshopper.Kernel.Parameters.Param_StructurePath _:
                        mgr.AddPathParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_SubD _:
                        mgr.AddSubDParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Surface _:
                        mgr.AddSurfaceParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Time _:
                        mgr.AddTimeParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Transform _:
                        mgr.AddTransformParameter(name, name, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Vector _:
                        if (input.Default == null)
                        {
                            mgr.AddVectorParameter(name, name, inputDescription, access);
                        }
                        else
                        {
                            mgr.AddVectorParameter(name, name, inputDescription, access, JsonConvert.DeserializeObject <Vector3d>(input.Default.ToString()));
                        }
                        break;

                    case Grasshopper.Kernel.Special.GH_NumberSlider _:
                        mgr.AddNumberParameter(name, name, inputDescription, access);
                        break;
                    }
                }

                if (!containsEmptyDefaults)
                {
                    recompute = true;
                }
            }
            if (buildOutputs && outputs != null)
            {
                var mgr = CreateOutputManager();
                foreach (var kv in outputs)
                {
                    string name  = kv.Key;
                    var    param = kv.Value;
                    switch (param)
                    {
                    case Grasshopper.Kernel.Parameters.Param_Arc _:
                        mgr.AddArcParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Boolean _:
                        mgr.AddBooleanParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Box _:
                        mgr.AddBoxParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Brep _:
                        mgr.AddBrepParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Circle _:
                        mgr.AddCircleParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Colour _:
                        mgr.AddColourParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Complex _:
                        mgr.AddComplexNumberParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Culture _:
                        mgr.AddCultureParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Curve _:
                        mgr.AddCurveParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Field _:
                        mgr.AddFieldParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_FilePath _:
                        mgr.AddTextParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_GenericObject _:
                        throw new Exception("generic param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Geometry _:
                        mgr.AddGeometryParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Group _:
                        throw new Exception("group param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Guid _:
                        throw new Exception("guid param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Integer _:
                        mgr.AddIntegerParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Interval _:
                        mgr.AddIntervalParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Interval2D _:
                        mgr.AddInterval2DParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_LatLonLocation _:
                        throw new Exception("latlonlocation param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Line _:
                        mgr.AddLineParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Matrix _:
                        mgr.AddMatrixParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Mesh _:
                        mgr.AddMeshParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_MeshFace _:
                        mgr.AddMeshFaceParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_MeshParameters _:
                        throw new Exception("meshparameters paran not supported");

                    case Grasshopper.Kernel.Parameters.Param_Number _:
                        mgr.AddNumberParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    //case Grasshopper.Kernel.Parameters.Param_OGLShader:
                    case Grasshopper.Kernel.Parameters.Param_Plane _:
                        mgr.AddPlaneParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Point _:
                        mgr.AddPointParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Rectangle _:
                        mgr.AddRectangleParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    //case Grasshopper.Kernel.Parameters.Param_ScriptVariable _:
                    case Grasshopper.Kernel.Parameters.Param_String _:
                        mgr.AddTextParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_StructurePath _:
                        mgr.AddPathParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_SubD _:
                        mgr.AddSubDParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Surface _:
                        mgr.AddSurfaceParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Time _:
                        mgr.AddTimeParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Transform _:
                        mgr.AddTransformParameter(name, name, name, GH_ParamAccess.item);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Vector _:
                        mgr.AddVectorParameter(name, name, name, GH_ParamAccess.item);
                        break;
                    }
                }
            }

            if (buildInputs || buildOutputs)
            {
                Params.OnParametersChanged();
                Grasshopper.Instances.ActiveCanvas?.Invalidate();

                if (recompute)
                {
                    OnPingDocument().NewSolution(true);
                }
            }
        }
        void DefineInputsAndOutputs()
        {
            ClearRuntimeMessages();
            string description = _remoteDefinition.GetDescription(out System.Drawing.Bitmap customIcon);

            if (!string.IsNullOrWhiteSpace(description) && !Description.Equals(description))
            {
                Description = description;
            }
            var inputs  = _remoteDefinition.GetInputParams();
            var outputs = _remoteDefinition.GetOutputParams();

            bool buildInputs  = inputs != null;
            bool buildOutputs = outputs != null;

            // check to see if the existing params match
            Dictionary <string, List <IGH_Param> > inputSources = new Dictionary <string, List <IGH_Param> >();

            foreach (var param in Params.Input)
            {
                inputSources.Add(param.Name, new List <IGH_Param>(param.Sources));
            }

            if (buildInputs && Params.Input.Count == inputs.Count)
            {
                buildInputs = false;
                foreach (var param in Params.Input.ToArray())
                {
                    if (!inputs.ContainsKey(param.Name))
                    {
                        buildInputs = true;
                        break;
                    }
                    else
                    {
                        // if input param exists, make sure param access is correct
                        var(input, _) = inputs[param.Name];
                        bool itemAccess = input.AtLeast == 1 && input.AtMost == 1;
                        param.Access = itemAccess ? GH_ParamAccess.item : GH_ParamAccess.list;
                    }
                }
            }
            if (buildOutputs && Params.Output.Count == outputs.Count)
            {
                buildOutputs = false;
                foreach (var param in Params.Output.ToArray())
                {
                    if (!outputs.ContainsKey(param.Name))
                    {
                        buildOutputs = true;
                        break;
                    }
                }
            }

            // Remove all existing inputs and outputs
            if (buildInputs)
            {
                foreach (var param in Params.Input.ToArray())
                {
                    Params.UnregisterInputParameter(param);
                }
            }
            if (buildOutputs)
            {
                foreach (var param in Params.Output.ToArray())
                {
                    Params.UnregisterOutputParameter(param);
                }
            }

            bool recompute = false;

            if (buildInputs && inputs != null)
            {
                bool containsEmptyDefaults = false;
                var  mgr = CreateInputManager();
                foreach (var kv in inputs)
                {
                    string name = kv.Key;
                    var(input, param) = kv.Value;
                    GH_ParamAccess access = GH_ParamAccess.list;
                    if (input.AtLeast == 1 && input.AtMost == 1)
                    {
                        access = GH_ParamAccess.item;
                    }
                    string inputDescription = name;
                    if (!string.IsNullOrWhiteSpace(input.Description))
                    {
                        inputDescription = input.Description;
                    }
                    if (input.Default == null)
                    {
                        containsEmptyDefaults = true;
                    }
                    string nickname = name;
                    if (!string.IsNullOrWhiteSpace(input.Nickname))
                    {
                        nickname = input.Nickname;
                    }
                    int paramIndex = -1;
                    switch (param)
                    {
                    case Grasshopper.Kernel.Parameters.Param_Arc _:
                        paramIndex = mgr.AddArcParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Boolean _:
                        if (input.Default == null)
                        {
                            paramIndex = mgr.AddBooleanParameter(name, nickname, inputDescription, access);
                        }
                        else
                        {
                            paramIndex = mgr.AddBooleanParameter(name, nickname, inputDescription, access, Convert.ToBoolean(input.Default));
                        }
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Box _:
                        paramIndex = mgr.AddBoxParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Brep _:
                        paramIndex = mgr.AddBrepParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Circle _:
                        paramIndex = mgr.AddCircleParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Colour _:
                        paramIndex = mgr.AddColourParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Complex _:
                        paramIndex = mgr.AddComplexNumberParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Culture _:
                        paramIndex = mgr.AddCultureParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Curve _:
                        paramIndex = mgr.AddCurveParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Field _:
                        paramIndex = mgr.AddFieldParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_FilePath _:
                        if (input.Default == null)
                        {
                            paramIndex = mgr.AddTextParameter(name, nickname, inputDescription, access);
                        }
                        else
                        {
                            paramIndex = mgr.AddTextParameter(name, nickname, inputDescription, access, input.Default.ToString());
                        }
                        break;

                    case Grasshopper.Kernel.Parameters.Param_GenericObject _:
                        throw new Exception("generic param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Geometry _:
                        paramIndex = mgr.AddGeometryParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Group _:
                        throw new Exception("group param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Guid _:
                        throw new Exception("guid param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Integer _:
                        if (input.Default == null)
                        {
                            paramIndex = mgr.AddIntegerParameter(name, nickname, inputDescription, access);
                        }
                        else
                        {
                            paramIndex = mgr.AddIntegerParameter(name, nickname, inputDescription, access, Convert.ToInt32(input.Default));
                        }
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Interval _:
                        paramIndex = mgr.AddIntervalParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Interval2D _:
                        paramIndex = mgr.AddInterval2DParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_LatLonLocation _:
                        throw new Exception("latlonlocation param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Line _:
                        if (input.Default == null)
                        {
                            paramIndex = mgr.AddLineParameter(name, nickname, inputDescription, access);
                        }
                        else
                        {
                            paramIndex = mgr.AddLineParameter(name, nickname, inputDescription, access, JsonConvert.DeserializeObject <Line>(input.Default.ToString()));
                        }
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Matrix _:
                        paramIndex = mgr.AddMatrixParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Mesh _:
                        paramIndex = mgr.AddMeshParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_MeshFace _:
                        paramIndex = mgr.AddMeshFaceParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_MeshParameters _:
                        throw new Exception("meshparameters paran not supported");

                    case Grasshopper.Kernel.Parameters.Param_Number _:
                        if (input.Default == null)
                        {
                            paramIndex = mgr.AddNumberParameter(name, nickname, inputDescription, access);
                        }
                        else
                        {
                            paramIndex = mgr.AddNumberParameter(name, nickname, inputDescription, access, Convert.ToDouble(input.Default));
                        }
                        break;

                    //case Grasshopper.Kernel.Parameters.Param_OGLShader:
                    case Grasshopper.Kernel.Parameters.Param_Plane _:
                        if (input.Default == null)
                        {
                            paramIndex = mgr.AddPlaneParameter(name, nickname, inputDescription, access);
                        }
                        else
                        {
                            paramIndex = mgr.AddPlaneParameter(name, nickname, inputDescription, access, JsonConvert.DeserializeObject <Plane>(input.Default.ToString()));
                        }
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Point _:
                        if (input.Default == null)
                        {
                            paramIndex = mgr.AddPointParameter(name, nickname, inputDescription, access);
                        }
                        else
                        {
                            paramIndex = mgr.AddPointParameter(name, nickname, inputDescription, access, JsonConvert.DeserializeObject <Point3d>(input.Default.ToString()));
                        }
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Rectangle _:
                        paramIndex = mgr.AddRectangleParameter(name, nickname, inputDescription, access);
                        break;

                    //case Grasshopper.Kernel.Parameters.Param_ScriptVariable _:
                    case Grasshopper.Kernel.Parameters.Param_String _:
                        if (input.Default == null)
                        {
                            paramIndex = mgr.AddTextParameter(name, nickname, inputDescription, access);
                        }
                        else
                        {
                            paramIndex = mgr.AddTextParameter(name, nickname, inputDescription, access, input.Default.ToString());
                        }
                        break;

                    case Grasshopper.Kernel.Parameters.Param_StructurePath _:
                        paramIndex = mgr.AddPathParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_SubD _:
                        paramIndex = mgr.AddSubDParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Surface _:
                        paramIndex = mgr.AddSurfaceParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Time _:
                        paramIndex = mgr.AddTimeParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Transform _:
                        paramIndex = mgr.AddTransformParameter(name, nickname, inputDescription, access);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Vector _:
                        if (input.Default == null)
                        {
                            paramIndex = mgr.AddVectorParameter(name, nickname, inputDescription, access);
                        }
                        else
                        {
                            paramIndex = mgr.AddVectorParameter(name, nickname, inputDescription, access, JsonConvert.DeserializeObject <Vector3d>(input.Default.ToString()));
                        }
                        break;

                    case Grasshopper.Kernel.Special.GH_NumberSlider _:
                        paramIndex = mgr.AddNumberParameter(name, nickname, inputDescription, access);
                        break;
                    }

                    if (paramIndex >= 0 && inputSources.TryGetValue(name, out List <IGH_Param> rehookInputs))
                    {
                        foreach (var rehookInput in rehookInputs)
                        {
                            Params.Input[paramIndex].AddSource(rehookInput);
                        }
                    }
                }

                if (!containsEmptyDefaults)
                {
                    recompute = true;
                }
            }
            if (buildOutputs && outputs != null)
            {
                var mgr = CreateOutputManager();
                foreach (var kv in outputs)
                {
                    string name     = kv.Key;
                    var    param    = kv.Value;
                    string nickname = name;
                    if (!string.IsNullOrWhiteSpace(param.NickName))
                    {
                        nickname = param.NickName;
                    }
                    string outputDescription = name;
                    if (!string.IsNullOrWhiteSpace(param.Description))
                    {
                        outputDescription = param.Description;
                    }
                    switch (param)
                    {
                    case Grasshopper.Kernel.Parameters.Param_Arc _:
                        mgr.AddArcParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Boolean _:
                        mgr.AddBooleanParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Box _:
                        mgr.AddBoxParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Brep _:
                        mgr.AddBrepParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Circle _:
                        mgr.AddCircleParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Colour _:
                        mgr.AddColourParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Complex _:
                        mgr.AddComplexNumberParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Culture _:
                        mgr.AddCultureParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Curve _:
                        mgr.AddCurveParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Field _:
                        mgr.AddFieldParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_FilePath _:
                        mgr.AddTextParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_GenericObject _:
                        throw new Exception("generic param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Geometry _:
                        mgr.AddGeometryParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Group _:
                        throw new Exception("group param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Guid _:
                        throw new Exception("guid param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Integer _:
                        mgr.AddIntegerParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Interval _:
                        mgr.AddIntervalParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Interval2D _:
                        mgr.AddInterval2DParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_LatLonLocation _:
                        throw new Exception("latlonlocation param not supported");

                    case Grasshopper.Kernel.Parameters.Param_Line _:
                        mgr.AddLineParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Matrix _:
                        mgr.AddMatrixParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Mesh _:
                        mgr.AddMeshParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_MeshFace _:
                        mgr.AddMeshFaceParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_MeshParameters _:
                        throw new Exception("meshparameters paran not supported");

                    case Grasshopper.Kernel.Parameters.Param_Number _:
                        mgr.AddNumberParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    //case Grasshopper.Kernel.Parameters.Param_OGLShader:
                    case Grasshopper.Kernel.Parameters.Param_Plane _:
                        mgr.AddPlaneParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Point _:
                        mgr.AddPointParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Rectangle _:
                        mgr.AddRectangleParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    //case Grasshopper.Kernel.Parameters.Param_ScriptVariable _:
                    case Grasshopper.Kernel.Parameters.Param_String _:
                        mgr.AddTextParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_StructurePath _:
                        mgr.AddPathParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_SubD _:
                        mgr.AddSubDParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Surface _:
                        mgr.AddSurfaceParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Time _:
                        mgr.AddTimeParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Transform _:
                        mgr.AddTransformParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;

                    case Grasshopper.Kernel.Parameters.Param_Vector _:
                        mgr.AddVectorParameter(name, nickname, outputDescription, GH_ParamAccess.tree);
                        break;
                    }
                }
            }

            if (customIcon != null)
            {
                // Draw hops icon overlay on custom icon. We can add an option
                // to the data returned from a server to skip this overlay in
                // the future.
                // Create a slightly large image so we can cram the hops overlay
                // deeper into the lower right corner
                //var bmp = new System.Drawing.Bitmap(28, 28);
                //using(var graphics = System.Drawing.Graphics.FromImage(bmp))
                //{
                //    // use fill to debug
                //    //graphics.FillRectangle(System.Drawing.Brushes.PowderBlue, 0, 0, 28, 28);
                //    var rect = new System.Drawing.Rectangle(2, 2, 24, 24);
                //    graphics.DrawImage(customIcon, rect);
                //    rect = new System.Drawing.Rectangle(16, 14, 14, 14);
                //    graphics.DrawImage(Hops24Icon(), rect);

                //}
                SetIconOverride(customIcon);
            }
            if (buildInputs || buildOutputs)
            {
                Params.OnParametersChanged();
                Grasshopper.Instances.ActiveCanvas?.Invalidate();

                if (recompute)
                {
                    var doc = OnPingDocument();
                    if (doc != null)
                    {
                        doc.NewSolution(true);
                    }
                }
            }
        }