static string ParamTypeName(IGH_Param param) { Type t = param.GetType(); // TODO: Figure out why the GetGeometryParameter throws exceptions when calling TypeName if (t.Name.Equals("GetGeometryParameter")) { return("Geometry"); } return(param.TypeName); }
static string ParamTypeName(IGH_Param param) { Type t = param.GetType(); // TODO: Figure out why the GetGeometryParameter throws exceptions when calling TypeName if (t.Name.Equals("GetGeometryParameter")) { return("Geometry"); } if (param is GH_NumberSlider) { return("Slider"); // differentiate from "Number" } return(param.TypeName); }
public void RegisterInputParam(IGH_Param param, string name, string nickName, string description, GH_ParamAccess access, IGH_Goo defaultValue) { param.Name = name; param.NickName = nickName; param.Description = description; param.Access = access; try { if (defaultValue != null && typeof(IGH_Goo).IsAssignableFrom(param.GetType())) { //Type genericType = GetGenericType(typeof(GH_PersistentParam), ((object)param).GetType()); Type genericType = GetGenericType(typeof(GH_PersistentParam <>), ((object)param).GetType()); if (genericType != null) { Type[] genericArguments = genericType.GetGenericArguments(); if (genericArguments.Length != 0) { Type type = genericArguments[0]; genericType.GetMethod("SetPersistentData", BindingFlags.Instance | BindingFlags.Public, null, new Type[1] { genericArguments[0] }, null).Invoke(param, new object[1] { defaultValue }); } } } } catch (Exception) { } ExtendedPlug extendedPlug = new ExtendedPlug(param); extendedPlug.Unit = this; inputs.Add(extendedPlug); }
public static void Menu_AppendConnect(this IGH_Param param, System.Windows.Forms.ToolStripDropDown menu, EventHandler eventHandler) { if ((param.Kind == GH_ParamKind.floating || param.Kind == GH_ParamKind.output) && param.Recipients.Count == 0) { var components = new List <IGH_Component>(); var paramType = param.Type; foreach (var proxy in Grasshopper.Instances.ComponentServer.ObjectProxies.Where(x => !x.Obsolete && x.Exposure != GH_Exposure.hidden && x.Exposure < GH_Exposure.tertiary)) { if (typeof(IGH_Component).IsAssignableFrom(proxy.Type)) { var obj = proxy.CreateInstance() as IGH_Component; foreach (var input in obj.Params.Input.Where(i => typeof(GH.Types.IGH_ElementId).IsAssignableFrom(i.Type))) { if (input.GetType() == param.GetType() || input.Type.IsAssignableFrom(paramType)) { components.Add(obj); break; } } } } GH_DocumentObject.Menu_AppendSeparator(menu); var connect = GH_DocumentObject.Menu_AppendItem(menu, "Connect") as System.Windows.Forms.ToolStripMenuItem; var panedComponentId = new Guid("{59E0B89A-E487-49f8-BAB8-B5BAB16BE14C}"); var panel = GH_DocumentObject.Menu_AppendItem(connect.DropDown, "Panel", eventHandler, Grasshopper.Instances.ComponentServer.EmitObjectIcon(panedComponentId)); panel.Tag = panedComponentId; var picker = GH_DocumentObject.Menu_AppendItem(connect.DropDown, "Value Set Picker", eventHandler, Grasshopper.Instances.ComponentServer.EmitObjectIcon(GH.Parameters.ValueSetPicker.ComponentClassGuid)); picker.Tag = GH.Parameters.ValueSetPicker.ComponentClassGuid; if (components.Count > 0) { GH_DocumentObject.Menu_AppendSeparator(connect.DropDown); var maxComponents = Grasshopper.CentralSettings.CanvasMaxSearchResults; maxComponents = Math.Min(maxComponents, 30); maxComponents = Math.Max(maxComponents, 3); int count = 0; foreach (var componentGroup in components.GroupBy(x => x.Exposure).OrderBy(x => x.Key)) { foreach (var component in componentGroup.OrderBy(x => x.Category).OrderBy(x => x.SubCategory).OrderBy(x => x.Name)) { var item = GH_DocumentObject.Menu_AppendItem(connect.DropDown, component.Name, eventHandler, component.Icon_24x24); item.Tag = component.ComponentGuid; if (count >= maxComponents) { break; } } if (count >= maxComponents) { break; } } } } }
public static IGH_DocumentObject ConnectNewObject(this IGH_Param self, Guid componentGuid) { var document = self.OnPingDocument(); if (document is null) { return(null); } var obj = Grasshopper.Instances.ComponentServer.EmitObject(componentGuid) as IGH_ActiveObject; if (obj is null) { return(null); } obj.CreateAttributes(); if (Grasshopper.CentralSettings.CanvasFullNames) { var atts = new List <IGH_Attributes>(); obj.Attributes.AppendToAttributeTree(atts); foreach (var att in atts) { att.DocObject.NickName = att.DocObject.Name; } } obj.NewInstanceGuid(); obj.Attributes.Pivot = new System.Drawing.PointF(); obj.Attributes.PerformLayout(); if (obj is IGH_Param) { obj.Attributes.Pivot = new System.Drawing.PointF(self.Attributes.Pivot.X + 120, self.Attributes.Pivot.Y - obj.Attributes.Bounds.Height / 2); } else if (obj is IGH_Component) { obj.Attributes.Pivot = new System.Drawing.PointF(self.Attributes.Pivot.X + 120, self.Attributes.Pivot.Y); } obj.Attributes.ExpireLayout(); document.AddObject(obj, false); document.UndoUtil.RecordAddObjectEvent($"Add {obj.Name}", obj); if (obj is IGH_Param param) { param.AddSource(self); } else if (obj is IGH_Component component) { var selfType = self.Type; foreach (var input in component.Params.Input.Where(i => typeof(GH.Types.IGH_ElementId).IsAssignableFrom(i.Type))) { if (input.GetType() == self.GetType() || input.Type.IsAssignableFrom(selfType)) { input.AddSource(self); break; } } } return(obj); }
public static bool ConnectNewObject(this IGH_Param param, IGH_DocumentObject obj) { if (obj is null) { return(false); } if (param.Kind == GH_ParamKind.unknown) { return(false); } var document = param.OnPingDocument(); if (document is null) { return(false); } obj.CreateAttributes(); if (CentralSettings.CanvasFullNames) { var atts = new List <IGH_Attributes>(); obj.Attributes.AppendToAttributeTree(atts); foreach (var att in atts) { att.DocObject.NickName = att.DocObject.Name; } } obj.NewInstanceGuid(); obj.Attributes.Pivot = default; obj.Attributes.PerformLayout(); float offsetX = param.Kind == GH_ParamKind.input ? -(obj.Attributes.Bounds.X + obj.Attributes.Bounds.Width) - 94 : -(obj.Attributes.Bounds.X) + 100.0f; if (obj is IGH_Param) { obj.Attributes.Pivot = new System.Drawing.PointF(param.Attributes.Pivot.X + offsetX, param.Attributes.Pivot.Y - obj.Attributes.Bounds.Height / 2); } else if (obj is IGH_Component) { obj.Attributes.Pivot = new System.Drawing.PointF(param.Attributes.Pivot.X + offsetX, param.Attributes.Pivot.Y); } obj.Attributes.ExpireLayout(); document.AddObject(obj, false); document.UndoUtil.RecordAddObjectEvent($"Add {obj.Name}", obj); if (param.Kind == GH_ParamKind.input) { if (obj is IGH_Param parameter) { param.AddSource(parameter); } else if (obj is IGH_Component component) { var selfType = param.Type; foreach (var output in component.Params.Output) { if (output.GetType() == param.GetType() || output.Type.IsAssignableFrom(selfType)) { param.AddSource(output); break; } } } } else { if (obj is IGH_Param parameter) { parameter.AddSource(param); } else if (obj is IGH_Component component) { var selfType = param.Type; foreach (var input in component.Params.Input) { if (input.GetType() == param.GetType() || input.Type.IsAssignableFrom(selfType)) { input.AddSource(param); break; } } } } return(true); }
public static void Menu_AppendConnect(this IGH_Param param, ToolStripDropDown menu, EventHandler eventHandler) { if ((param.Kind == GH_ParamKind.floating || param.Kind == GH_ParamKind.output) && param.Recipients.Count == 0) { var components = new List <IGH_Component>(); var paramType = param.Type; foreach (var proxy in Instances.ComponentServer.ObjectProxies.Where(x => !x.Obsolete && x.Kind == GH_ObjectType.CompiledObject && x.Exposure != GH_Exposure.hidden && x.Exposure < GH_Exposure.tertiary)) { if (typeof(IGH_Component).IsAssignableFrom(proxy.Type)) { try { if (proxy.CreateInstance() is IGH_Component compoennt) { foreach (var input in compoennt.Params.Input) { if (input.Type == typeof(IGH_Goo) || input.Type == typeof(IGH_GeometricGoo)) { continue; } if (input.GetType() == param.GetType() || input.Type.IsAssignableFrom(paramType)) { components.Add(compoennt); break; } } } } catch { } } } var connect = GH_DocumentObject.Menu_AppendItem(menu, "Connect") as ToolStripMenuItem; var panedComponentId = new Guid("{59E0B89A-E487-49f8-BAB8-B5BAB16BE14C}"); var panel = GH_DocumentObject.Menu_AppendItem(connect.DropDown, "Panel", eventHandler, Instances.ComponentServer.EmitObjectIcon(panedComponentId)); panel.Tag = panedComponentId; var valueSetComponentId = new Guid("{AFB12752-3ACB-4ACF-8102-16982A69CDAE}"); var picker = GH_DocumentObject.Menu_AppendItem(connect.DropDown, "Value Set Picker", eventHandler, Instances.ComponentServer.EmitObjectIcon(valueSetComponentId)); picker.Tag = valueSetComponentId; if (components.Count > 0) { GH_DocumentObject.Menu_AppendSeparator(connect.DropDown); var maxComponents = CentralSettings.CanvasMaxSearchResults; maxComponents = Math.Min(maxComponents, 30); maxComponents = Math.Max(maxComponents, 3); int count = 0; foreach (var componentGroup in components.GroupBy(x => x.Exposure).OrderBy(x => x.Key)) { foreach (var component in componentGroup.OrderBy(x => x.Category).OrderBy(x => x.SubCategory).OrderBy(x => x.Name)) { var item = GH_DocumentObject.Menu_AppendItem(connect.DropDown, component.Name, eventHandler, component.Icon_24x24); item.Tag = component.ComponentGuid; if (count >= maxComponents) { break; } } if (count >= maxComponents) { break; } } } } }
public override void AddSource(IGH_Param source, int index) { Console.WriteLine("AddSource2 Called:" + source.GetType().FullName); base.AddSource(source, index); }
public override void AddSource(IGH_Param source) { Console.WriteLine("AddSource Called:" + source.GetType().FullName); base.AddSource(source); }