public InputGroup(IGH_Param param) { Param = param; _default = GetDefaultValueHelper(param, 0); }
public MedinaMotifOutput(string name, IGH_Param param) { Name = name; Param = param; }
public static ParamDefinition FromParam(IGH_Param param, ParamVisibility relevance) => new ParamDefinition(param, relevance);
public InputGroup(IGH_Param param) { Param = param; }
public Hu_ParamAttribute(IGH_Param Owner, int InnerControlNumber = 0) : base(Owner) { this.AttributeUtil = new Hu_AttributeUtilParam(Owner); this.InnerControlNumber = InnerControlNumber; this.Component = Owner; }
internal ParamDefinition(IGH_Param param, ParamVisibility relevance) { Param = param; Relevance = relevance; }
public SpecialLinkedAttributes(IGH_Param param, IGH_Attributes parent) : base(param, parent) { }
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 bool NicknameSuggestsGeometryOutputParam(IGH_Param param) { try { return((Params.IndexOfOutputParam(param.Name) != 0) && (!param.NickName.Contains("_" + attributes_suffix))); } catch { return(false); } }
public bool NicknameSuggestsAttributesOutputParam(IGH_Param param) { try { return(param.NickName.Contains("_" + attributes_suffix)); } catch { return(false); } }
public void LayoutMenuOutputs(RectangleF componentBox) { GH_SwitcherComponent obj = (GH_SwitcherComponent)base.Owner; float num = 0f; int num2 = 0; foreach (IGH_Param componentOutput in obj.StaticData.GetComponentOutputs()) { int val = 20 * ((List <IGH_StateTag>)componentOutput.StateTags).Count; num2 = Math.Max(num2, val); num = Math.Max(num, GH_FontServer.StringWidth(componentOutput.NickName, StandardFont.font())); } num = Math.Max(num + 6f, 12f); num += (float)num2; float num3 = this.Bounds.Height; for (int i = 0; i < composedCollection.Menus.Count; i++) { float num4 = -1f; float num5 = 0f; bool expanded = composedCollection.Menus[i].Expanded; if (expanded) { num4 = num3 + composedCollection.Menus[i].Height; num5 = Math.Max(composedCollection.Menus[i].Inputs.Count, composedCollection.Menus[i].Outputs.Count) * 20; } else { num4 = num3 + 5f; num5 = 0f; } List <ExtendedPlug> outputs = composedCollection.Menus[i].Outputs; int count = outputs.Count; if (count != 0) { float num6 = num5 / (float)count; for (int j = 0; j < count; j++) { IGH_Param parameter = outputs[j].Parameter; if (parameter.Attributes == null) { parameter.Attributes = (new GH_LinkedParamAttributes(parameter, this)); } float num7 = componentBox.Right + 3f; float num8 = num4 + componentBox.Y + (float)j * num6; float width = num; float height = num6; PointF pivot = new PointF(num7 + 0.5f * num, num8 + 0.5f * num6); parameter.Attributes.Pivot = (pivot); RectangleF rectangleF = new RectangleF(num7, num8, width, height); parameter.Attributes.Bounds = ((RectangleF)GH_Convert.ToRectangle(rectangleF)); } for (int k = 0; k < count; k++) { IGH_Param parameter2 = outputs[k].Parameter; GH_LinkedParamAttributes val2 = (GH_LinkedParamAttributes)parameter2.Attributes; FieldInfo field = typeof(GH_LinkedParamAttributes).GetField("m_renderTags", BindingFlags.Instance | BindingFlags.NonPublic); GH_StateTagList val3 = parameter2.StateTags; if (field != null) { if (((List <IGH_StateTag>)val3).Count == 0) { val3 = null; field.SetValue(val2, val3); } if (val3 != null) { Rectangle rectangle = GH_Convert.ToRectangle(val2.Bounds); rectangle.Width -= num2; val3.Layout(rectangle, GH_StateTagLayoutDirection.Right); rectangle = val3.BoundingBox; if (!rectangle.IsEmpty) { val2.Bounds = (RectangleF.Union(val2.Bounds, rectangle)); } field.SetValue(val2, val3); } } if (!expanded) { val2.Bounds = (new RectangleF(val2.Bounds.X + val2.Bounds.Width - 5f, val2.Bounds.Y, 5f, val2.Bounds.Height)); } } } num3 += composedCollection.Menus[i].TotalHeight; } }
public void LayoutOutputParams2(IGH_Component owner, RectangleF componentBox, int add_offset) { GH_SwitcherComponent gH_SwitcherComponent = (GH_SwitcherComponent)owner; List <IGH_Param> componentOutputSection = gH_SwitcherComponent.StaticData.GetComponentOutputSection(); int count = componentOutputSection.Count; if (count == 0) { return; } int num = 0; int num2 = 0; foreach (IGH_Param componentOutput in gH_SwitcherComponent.StaticData.GetComponentOutputs()) { int val = ((List <IGH_StateTag>)componentOutput.StateTags).Count * 20; num2 = Math.Max(num2, val); num = Math.Max(num, GH_FontServer.StringWidth(componentOutput.NickName, StandardFont.font())); } num = Math.Max(num + 6, 12); num += num2 + add_offset; float num3 = componentBox.Height / (float)count; for (int i = 0; i < count; i++) { IGH_Param val2 = componentOutputSection[i]; if (val2.Attributes == null) { val2.Attributes = (new GH_LinkedParamAttributes(val2, owner.Attributes)); } float num4 = componentBox.Right + 3f; float num5 = componentBox.Y + (float)i * num3; float width = num; float height = num3; PointF pivot = new PointF(num4 + 0.5f * (float)num, num5 + 0.5f * num3); val2.Attributes.Pivot = (pivot); RectangleF rectangleF = new RectangleF(num4, num5, width, height); val2.Attributes.Bounds = ((RectangleF)GH_Convert.ToRectangle(rectangleF)); } bool flag = false; for (int j = 0; j < count; j++) { IGH_Param val3 = componentOutputSection[j]; GH_LinkedParamAttributes val4 = (GH_LinkedParamAttributes)val3.Attributes; FieldInfo field = typeof(GH_LinkedParamAttributes).GetField("m_renderTags", BindingFlags.Instance | BindingFlags.NonPublic); GH_StateTagList val5 = val3.StateTags; if (!(field != null)) { continue; } if (((List <IGH_StateTag>)val5).Count == 0) { val5 = null; field.SetValue(val4, val5); } if (val5 != null) { flag = true; Rectangle rectangle = GH_Convert.ToRectangle(val4.Bounds); rectangle.Width -= num2; val5.Layout(rectangle, GH_StateTagLayoutDirection.Right); rectangle = val5.BoundingBox; if (!rectangle.IsEmpty) { val4.Bounds = (RectangleF.Union(val4.Bounds, rectangle)); } field.SetValue(val4, val5); } } if (flag) { float num6 = float.MinValue; for (int k = 0; k < count; k++) { IGH_Attributes attributes = componentOutputSection[k].Attributes; num6 = Math.Max(num6, attributes.Bounds.Right); } for (int l = 0; l < count; l++) { IGH_Attributes attributes2 = componentOutputSection[l].Attributes; RectangleF bounds = attributes2.Bounds; bounds.Width = num6 - bounds.X; attributes2.Bounds = (bounds); } } }
public DesignSurface(IGH_Param param) { this.Parameter = param; }
private void SolutionCallback(GH_Document doc) { //read file, deserialize json, send variables out of the extracted class string jsonstring = File.ReadAllText(_path); ParamsData paramdata = new ParamsData(); paramdata = JsonConvert.DeserializeObject <ParamsData>(jsonstring); _n = paramdata.NumSliders; _dataIn = paramdata.SliderVals; _pointsdata = paramdata.Points; Random rnd = new Random(); List <IGH_DocumentObject> deletions = new List <IGH_DocumentObject>(); //list of objects to delete from grasshopper document List <OutputParam> outputParams = new List <OutputParam>(); //list of the slider grouping params and their output connections List <IGH_Param> PointRecvParams = new List <IGH_Param>(); //list of what the point param is connected to foreach (IGH_DocumentObject obj in GrasshopperDocument.Objects) { if (obj.NickName.StartsWith(_controlComponentName)) //the point and integer params i've created { deletions.Add(obj); IGH_Param tempParam = obj as IGH_Param; //cast obj into a param to locate sources and recipients if (tempParam.SourceCount > 0) { deletions.AddRange(tempParam.Sources); //add source sliders to deletions list } if (obj.NickName.StartsWith(_controlComponentName + "points")) { foreach (IGH_Param recip in tempParam.Recipients) { PointRecvParams.Add(recip); } } if (obj.NickName.StartsWith(_controlComponentName + "slids")) //the integer params { int ObjectIndex; Int32.TryParse(System.Text.RegularExpressions.Regex.Match(obj.NickName, @"(\d+)\z").Value, out ObjectIndex); //regex to extract index number from end of param name List <IGH_Param> receivingParams = new List <IGH_Param>(); foreach (IGH_Param recip in tempParam.Recipients) { receivingParams.Add(recip); } outputParams.Add(new OutputParam(ObjectIndex, receivingParams)); //put output param index and recipients into an object in a list } } } foreach (IGH_DocumentObject delobj in deletions) //delete the stuff { GrasshopperDocument.RemoveObject(delobj, false); } List <Grasshopper.Kernel.Parameters.Param_Integer> targetParam = new List <Grasshopper.Kernel.Parameters.Param_Integer>(); //holds the new output params as we build them //rename targetParam for (int index = 0; index < _n.Count; index++) //this loop runs once per slider bank //rename index { targetParam.Add(new Grasshopper.Kernel.Parameters.Param_Integer()); //create the new output param targetParam[index].NickName = _controlComponentName + "slids" + index; //assign the name to the output param including the index number GrasshopperDocument.AddObject(targetParam[index], false); if (index == 0) //put param in place { targetParam[index].Attributes.Pivot = new System.Drawing.PointF(Component.Attributes.Pivot.X + 20, Component.Attributes.Pivot.Y + 110); } else { _n[index] = _n[index] + _n[index - 1]; //aggregate list of number of sliders per bank to create slider index breakpoints targetParam[index].Attributes.Pivot = new System.Drawing.PointF(Component.Attributes.Pivot.X + 20, Component.Attributes.Pivot.Y + 110 + _n[index - 1] * 20 + index * 10); } if (outputParams.Exists(opar => opar.outParam == index)) //looks in the list of deleted output params and determines if one has the same index as the param being created { foreach (IGH_Param receivingParam in outputParams.Find(opar => opar.outParam == index).recvParams) { receivingParam.AddSource(targetParam[index]); //connects the new param to the old param stuff } } } Grasshopper.Kernel.Parameters.Param_Point pointsParam = new Grasshopper.Kernel.Parameters.Param_Point(); pointsParam.NickName = _controlComponentName + "points"; GrasshopperDocument.AddObject(pointsParam, false); pointsParam.Attributes.Pivot = new System.Drawing.PointF(Component.Attributes.Pivot.X + 20, Component.Attributes.Pivot.Y + 70); foreach (IGH_Param receivingParam in PointRecvParams) { receivingParam.AddSource(pointsParam); } pointsParam.SetPersistentData(_pointsdata.ToArray()); int Yoffset = -12; int CurrentParam = 0; for (int i = 0; i < _n[_n.Count - 1]; i++) { if (_n.Exists(x => x == i)) { Yoffset = Yoffset + 10; CurrentParam++; } //instantiate new slider Grasshopper.Kernel.Special.GH_NumberSlider slid = new Grasshopper.Kernel.Special.GH_NumberSlider(); slid.CreateAttributes(); //sets up default values, and makes sure your slider doesn't crash rhino //customise slider (position, ranges etc) //targetParam.Attributes.Bounds slid.Attributes.Pivot = new System.Drawing.PointF((float)targetParam[0].Attributes.Pivot.X - slid.Attributes.Bounds.Width - 70, (float)targetParam[0].Attributes.Pivot.Y + i * 20 + Yoffset); slid.Slider.Maximum = 100; slid.Slider.Minimum = 0; slid.Slider.DecimalPlaces = 0; // slid.SetSliderValue((decimal) (rnd.Next(-50, 51))); if (i + 1 > _dataIn.Count) { slid.SetSliderValue(_dataIn[_dataIn.Count - 1]); } else { slid.SetSliderValue(_dataIn[i]); } //Until now, the slider is a hypothetical object. // This command makes it 'real' and adds it to the canvas. GrasshopperDocument.AddObject(slid, false); //Connect the new slider to this component targetParam[CurrentParam].AddSource(slid); } }
public Param(IGH_Param param) { MappedParam = param; }
protected override void RegisterInputParams(GH_InputParamManager pManager) { pManager.AddTextParameter("Name", "N", "Name of the Robot system", GH_ParamAccess.item); pManager.AddPlaneParameter("Base", "P", "Base plane", GH_ParamAccess.item, Plane.WorldXY); parameter = pManager[0]; }
public void ReplaceSource(IGH_Param old_source, IGH_Param new_source) { throw new NotImplementedException(); }
public static void UpStreamObjects(List <IGH_DocumentObject> upComponents, IGH_DocumentObject obj, GH_Document docu) { //Find all the upstream components from a given starting node. IGH_Param param = obj as IGH_Param; if (param != null) { if (!upComponents.Contains(obj)) { upComponents.Add(obj); } IList <IGH_Param> params2 = param.Sources; foreach (IGH_Param p in params2) { Guid id = p.Attributes.GetTopLevel.InstanceGuid; IGH_DocumentObject comp2 = docu.FindObject(id, true); IGH_ActiveObject PA = comp2 as IGH_ActiveObject; UpStreamObjects(upComponents, PA, docu); } } IGH_Component comp = obj as IGH_Component; if (comp != null) { List <IGH_DocumentObject> PreviousComponents = new List <IGH_DocumentObject>(); List <IGH_Param> paramtrs = comp.Params.Input; foreach (IGH_Param pm in paramtrs) { IList <IGH_Param> sources = pm.Sources; foreach (IGH_Param pm2 in sources) { Guid id = pm2.Attributes.GetTopLevel.InstanceGuid; IGH_DocumentObject comp2 = docu.FindObject(id, true); if (comp2 != null) { PreviousComponents.Add(comp2); } } } if (PreviousComponents.Count == 0) { if (!upComponents.Contains(obj)) { upComponents.Add(obj); } } else { if (!upComponents.Contains(obj)) { upComponents.Add(obj); } foreach (IGH_DocumentObject obj3 in PreviousComponents) { UpStreamObjects(upComponents, obj3, docu); } } } }
public void AddSource(IGH_Param source) { throw new NotImplementedException(); }
internal ParamDefinition(IGH_Param param) { Param = param; Relevance = ParamVisibility.Binding; }
public void RegisterInputParam(IGH_Param param, string name, string nickName, string description, GH_ParamAccess access) { RegisterInputParam(param, name, nickName, description, access, null); }
public static ParamDefinition FromParam(IGH_Param param) => new ParamDefinition(param, ParamVisibility.Binding);
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; } } } } }
protected override void SolveInstance(IGH_DataAccess DA) { UpdateMessage(); PythonScript script = PythonScript.Create(); string outDir = ""; try { script.ExecuteScript("import scriptcontext as sc\nV=sc.sticky['NOAH_PROJECT']\nT=sc.sticky['TASK_TICKET']\nG=sc.sticky['NOAH_GENERATOR']\nID=sc.sticky['UUID']"); NOAH_PROJECT = (string)script.GetVariable("V"); TASK_TICKET = (string)script.GetVariable("T"); NOAH_GENERATOR = (string)script.GetVariable("G"); UUID = (string)script.GetVariable("ID"); if (File.Exists(NOAH_PROJECT)) { outDir = Path.Combine(Path.GetDirectoryName(NOAH_PROJECT), ".noah", "tasks", UUID, TASK_TICKET, "out"); ProjectInfo = JObject.Parse(File.ReadAllText(NOAH_PROJECT)); JArray generators = JArray.Parse(ProjectInfo["generators"].ToString()); FindJobjectFromJArray(generators, NOAH_GENERATOR, out Generator, out GeneratorIndex); } } catch (Exception ex) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, ex.Message); } int outIndex = 0; DA.GetData(1, ref outIndex); JArray output = JArray.Parse(Generator["output"].ToString()); if (outIndex >= output.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "定义时未指定此输出端口"); } switch (m_mode) { case ExportMode.None: Message = null; break; case ExportMode.Rhino: string fileName = Convert.ToString(outIndex) + ".3dm"; string filePath = Path.Combine(outDir, fileName); File3dmWriter writer = new File3dmWriter(filePath); List <int> ll = new List <int>(); List <ObjectLayerInfo> layeredObj = new List <ObjectLayerInfo>(); DA.GetDataList(0, layeredObj); layeredObj.ForEach(x => { writer.ChildLayerSolution(x.Name); ll.Add(writer.CreateLayer(x.Name, x.Color)); }); if (layeredObj.Count > 0) { writer.Write(layeredObj, ll); if (!exported) { ProjectInfo["generators"][GeneratorIndex]["output"][outIndex]["value"] = filePath; File.WriteAllText(NOAH_PROJECT, JsonConvert.SerializeObject(ProjectInfo, Formatting.Indented)); exported = true; } } break; case ExportMode.Text: if (!exported) { string outputData = ""; DA.GetData(0, ref outputData); ProjectInfo["generators"][GeneratorIndex]["output"][outIndex]["value"] = outputData; File.WriteAllText(NOAH_PROJECT, JsonConvert.SerializeObject(ProjectInfo, Formatting.Indented)); exported = true; } break; case ExportMode.Data: fileName = Convert.ToString(outIndex) + ".noahdata"; filePath = Path.Combine(outDir, fileName); if (string.IsNullOrWhiteSpace(filePath)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "未指定文件."); return; } GH_LooseChunk val = new GH_LooseChunk("Grasshopper Data"); val.SetGuid("OriginId", base.InstanceGuid); val.SetInt32("Count", base.Params.Input.Count); IGH_Param iGH_Param = base.Params.Input[0]; IGH_Structure volatileData = iGH_Param.VolatileData; GH_IWriter val2 = val.CreateChunk("Block", 0); val2.SetString("Name", iGH_Param.NickName); val2.SetBoolean("Empty", volatileData.IsEmpty); if (!volatileData.IsEmpty) { GH_Structure <IGH_Goo> tree = null; DA.GetDataTree(0, out tree); if (!tree.Write(val2.CreateChunk("Data"))) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"There was a problem writing the {iGH_Param.NickName} data."); } } byte[] bytes = val.Serialize_Binary(); try { File.WriteAllBytes(filePath, bytes); } catch (Exception ex) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, ex.Message); } if (!exported) { ProjectInfo["generators"][GeneratorIndex]["output"][outIndex]["value"] = filePath; File.WriteAllText(NOAH_PROJECT, JsonConvert.SerializeObject(ProjectInfo, Formatting.Indented)); exported = true; } break; case ExportMode.CSV: fileName = Convert.ToString(outIndex) + ".csv"; filePath = Path.Combine(outDir, fileName); List <object> oList = new List <object>(); List <string> sList = new List <string>(); DA.GetDataList(0, oList); oList.ForEach(el => { string tmp = ""; GH_Convert.ToString(el, out tmp, GH_Conversion.Both); sList.Add(tmp); }); File.WriteAllText(filePath, string.Join(Environment.NewLine, sList)); if (!exported) { ProjectInfo["generators"][GeneratorIndex]["output"][outIndex]["value"] = filePath; File.WriteAllText(NOAH_PROJECT, JsonConvert.SerializeObject(ProjectInfo, Formatting.Indented)); exported = true; } break; } }
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); }
private object GetObjectProp(IGH_Param param, object value, Type t) { var convertedValue = ConvertType(t, value, param.Name); return(convertedValue); }
public void RenderMenuParameters(GH_Canvas canvas, Graphics graphics) { if (Math.Max(inputs.Count, outputs.Count) != 0) { int zoomFadeLow = GH_Canvas.ZoomFadeLow; if (zoomFadeLow >= 5) { StringFormat farCenter = GH_TextRenderingConstants.FarCenter; canvas.SetSmartTextRenderingHint(); SolidBrush solidBrush = new SolidBrush(Color.FromArgb(zoomFadeLow, style.Text)); List <ExtendedPlug> .Enumerator enumerator = inputs.GetEnumerator(); try { while (enumerator.MoveNext()) { IGH_Param parameter = enumerator.Current.Parameter; RectangleF bounds = parameter.Attributes.Bounds; if (bounds.Width >= 1f) { graphics.DrawString(parameter.NickName, StandardFont.font(), solidBrush, bounds, farCenter); GH_LinkedParamAttributes obj = (GH_LinkedParamAttributes)parameter.Attributes; FieldInfo field = typeof(GH_LinkedParamAttributes).GetField("m_renderTags", BindingFlags.Instance | BindingFlags.NonPublic); if (field != (FieldInfo)null) { GH_StateTagList value = (GH_StateTagList)field.GetValue(obj); if (value != null) { value.RenderStateTags(graphics); } } } } } finally { ((IDisposable)enumerator).Dispose(); } farCenter = GH_TextRenderingConstants.NearCenter; enumerator = outputs.GetEnumerator(); try { while (enumerator.MoveNext()) { IGH_Param parameter2 = enumerator.Current.Parameter; RectangleF bounds2 = parameter2.Attributes.Bounds; if (bounds2.Width >= 1f) { graphics.DrawString(parameter2.NickName, StandardFont.font(), solidBrush, bounds2, farCenter); GH_LinkedParamAttributes obj2 = (GH_LinkedParamAttributes)parameter2.Attributes; FieldInfo field2 = typeof(GH_LinkedParamAttributes).GetField("m_renderTags", BindingFlags.Instance | BindingFlags.NonPublic); if (field2 != (FieldInfo)null) { GH_StateTagList value2 = (GH_StateTagList)field2.GetValue(obj2); if (value2 != null) { value2.RenderStateTags(graphics); } } } } } finally { ((IDisposable)enumerator).Dispose(); } solidBrush.Dispose(); } } }
object GetDefaultValueHelper(IGH_Param param, int depth) { switch (param) { case Grasshopper.Kernel.IGH_ContextualParameter _: { if (0 == depth && param.Sources.Count == 1) { var sourceParam = param.Sources[0]; return(GetDefaultValueHelper(sourceParam, depth + 1)); } } break; case Grasshopper.Kernel.Parameters.Param_Arc _: break; case Grasshopper.Kernel.Parameters.Param_Boolean paramBool: if (paramBool.PersistentDataCount == 1) { return(paramBool.PersistentData[0][0].Value); } break; case Grasshopper.Kernel.Parameters.Param_Box _: break; case Grasshopper.Kernel.Parameters.Param_Brep _: break; case Grasshopper.Kernel.Parameters.Param_Circle _: break; case Grasshopper.Kernel.Parameters.Param_Colour _: break; case Grasshopper.Kernel.Parameters.Param_Complex _: break; case Grasshopper.Kernel.Parameters.Param_Culture _: break; case Grasshopper.Kernel.Parameters.Param_Curve _: break; case Grasshopper.Kernel.Parameters.Param_Field _: break; case Grasshopper.Kernel.Parameters.Param_FilePath _: break; case Grasshopper.Kernel.Parameters.Param_GenericObject _: break; case Grasshopper.Kernel.Parameters.Param_Geometry _: break; case Grasshopper.Kernel.Parameters.Param_Group _: break; case Grasshopper.Kernel.Parameters.Param_Guid _: break; case Grasshopper.Kernel.Parameters.Param_Integer paramInt: if (paramInt.PersistentDataCount == 1) { return(paramInt.PersistentData[0][0].Value); } break; case Grasshopper.Kernel.Parameters.Param_Interval _: break; case Grasshopper.Kernel.Parameters.Param_Interval2D _: break; case Grasshopper.Kernel.Parameters.Param_LatLonLocation _: break; case Grasshopper.Kernel.Parameters.Param_Line _: break; case Grasshopper.Kernel.Parameters.Param_Matrix _: break; case Grasshopper.Kernel.Parameters.Param_Mesh _: break; case Grasshopper.Kernel.Parameters.Param_MeshFace _: break; case Grasshopper.Kernel.Parameters.Param_MeshParameters _: break; case Grasshopper.Kernel.Parameters.Param_Number paramNumber: if (paramNumber.PersistentDataCount == 1) { return(paramNumber.PersistentData[0][0].Value); } break; //case Grasshopper.Kernel.Parameters.Param_OGLShader: case Grasshopper.Kernel.Parameters.Param_Plane paramPlane: if (paramPlane.PersistentDataCount == 1) { return(paramPlane.PersistentData[0][0].Value); } break; case Grasshopper.Kernel.Parameters.Param_Point paramPoint: if (paramPoint.PersistentDataCount == 1) { return(paramPoint.PersistentData[0][0].Value); } break; case Grasshopper.Kernel.Parameters.Param_Rectangle _: break; //case Grasshopper.Kernel.Parameters.Param_ScriptVariable _: case Grasshopper.Kernel.Parameters.Param_String _: break; case Grasshopper.Kernel.Parameters.Param_StructurePath _: break; case Grasshopper.Kernel.Parameters.Param_SubD _: break; case Grasshopper.Kernel.Parameters.Param_Surface _: break; case Grasshopper.Kernel.Parameters.Param_Time _: break; case Grasshopper.Kernel.Parameters.Param_Transform _: break; case Grasshopper.Kernel.Parameters.Param_Vector paramVector: if (paramVector.PersistentDataCount == 1) { return(paramVector.PersistentData[0][0].Value); } break; case Grasshopper.Kernel.Special.GH_NumberSlider paramSlider: return(paramSlider.CurrentValue); } return(null); }
//public override bool HasOutputGrip => false; public NeuralNetTrainerParamAttributes(IGH_Param parameter, IGH_Attributes parent) : base(parameter, parent) //public CustomAttributes(NeuralNetTrainerComponent component) : base(component) { component = (Boa_TrainerComponent)parent.DocObject; //this.component = component; }
protected void NewRenderIncomingWires(IGH_Param param, GH_Canvas canvas, Graphics graphics) { IEnumerable <IGH_Param> sources = param.Sources; GH_ParamWireDisplay style = param.WireDisplay; if (!param.Attributes.HasInputGrip) { return; } bool flag = false; if (param.Attributes.Selected) { flag = true; } else if (style != 0) { foreach (IGH_Param source in sources) { if (source.Attributes.GetTopLevel.Selected) { flag = true; break; } } } else { flag = true; } int count = sources.Count(); if (count != ParamProxies.Count) { UpdateParamProxy(); } if (flag) { if (CentralSettings.CanvasFancyWires) { for (int i = 0; i < count; i++) { GH_WireType type = GH_Painter.DetermineWireType(sources.ElementAt(i).VolatileData); DrawConnection(param.Attributes.InputGrip, sources.ElementAt(i).Attributes.OutputGrip, GH_WireDirection.left, GH_WireDirection.right, param.Attributes.Selected, sources.ElementAt(i).Attributes.Selected, type, ParamProxies[i].ShowColor, canvas, graphics); } return; } for (int i = 0; i < count; i++) { DrawConnection(param.Attributes.InputGrip, sources.ElementAt(i).Attributes.OutputGrip, GH_WireDirection.left, GH_WireDirection.right, param.Attributes.Selected, sources.ElementAt(i).Attributes.Selected, GH_WireType.generic, ParamProxies[i].ShowColor, canvas, graphics); } return; } switch (style) { case GH_ParamWireDisplay.faint: for (int i = 0; i < count; i++) { DrawConnection(param.Attributes.InputGrip, sources.ElementAt(i).Attributes.OutputGrip, GH_WireDirection.left, GH_WireDirection.right, param.Attributes.Selected, sources.ElementAt(i).Attributes.Selected, GH_WireType.faint, ParamProxies[i].ShowColor, canvas, graphics); } break; case GH_ParamWireDisplay.hidden: { 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 Individual CreateRandomIndividual(ChihuahuaComponent comp) { GH_Document docu = comp.OnPingDocument(); //Change value of sliders List <decimal> genome = new List <decimal>(); List <decimal> Ngenome = new List <decimal>(); IList <IGH_Param> sliders = comp.Params.Input[0].Sources; foreach (IGH_Param param in sliders) { Grasshopper.Kernel.Special.GH_NumberSlider slider = param as Grasshopper.Kernel.Special.GH_NumberSlider; if (slider != null) { decimal N_gene_value = (decimal)random.NextDouble(); decimal gene_value = N_gene_value.Remap(0, 1, slider.Slider.Minimum, slider.Slider.Maximum); slider.SetSliderValue(gene_value); Ngenome.Add(N_gene_value); genome.Add(gene_value); } else { Rhino.RhinoApp.WriteLine("At least one of the input parameters is not a number slider" + Environment.NewLine); throw new System.ArgumentException("At least one of the input parameters is not a number slider", "Genome"); } } // Get a new solution docu.NewSolution(false); //Read new fitness value decimal fitness = 0; if (comp.Params.Input[1].SourceCount != 1) { Rhino.RhinoApp.Write("Fitness input must be a unique value" + Environment.NewLine); throw new System.ArgumentException("Fitness input must be a unique value", "Fitness"); } else { IGH_Param param = comp.Params.Input[1].Sources[0]; GH_Structure <GH_Number> outcome = comp.Params.Input[1].Sources[0].VolatileData as GH_Structure <GH_Number>; if (outcome == null) { Rhino.RhinoApp.WriteLine("Fitness input is not a number" + Environment.NewLine); throw new System.ArgumentException("Fitness input is not a number", "Fitness"); } if (outcome != null) { fitness = (decimal)outcome.Branches[0][0].Value; } } Individual ind = new Individual(fitness, genome, Ngenome); return(ind); }
public void getdatagenInputParams() { // Get the document this component belongs to. this.doc = OnPingDocument(); if (doc == null) { return; } //CSVtype csvinput = this.Params.Input[0].Sources[0] as CSVtype; // Gain access to datgen component that is connected to this component IGH_Param source = this.Params.Input[0].Sources[0]; // Get GUID of the connected datagen component Guid guid = source.Attributes.GetTopLevel.DocObject.InstanceGuid; this.datagencomponent = doc.FindComponent(guid); foreach (GH_String dat in datagencomponent.Params.Input[2].Sources[0].VolatileData.AllData(true)) { this.directory.Add(dat.Value); } //List<PSlider> PSliders = datagencomponent.Params.Input[0].Sources as List<PSlider>; List <PSlider> PSliders = new List <PSlider>(); //List<POutput> POutputs = datagencomponent.Params.Input[1].Sources as List<POutput>; List <POutput> POutputs = new List <POutput>(); //List<Param_Number> outputs = datagencomponent.Params.Input[1].Sources as List<Param_Number>; List <IGH_Param> datagen_input_sources = this.datagencomponent.Params.Input[0].Sources as List <IGH_Param>; List <IGH_Param> datagen_output_sources = this.datagencomponent.Params.Input[1].Sources as List <IGH_Param>; foreach (IGH_Param s in datagen_input_sources) { PSliders.Add(s as PSlider); } foreach (IGH_Param o in datagen_output_sources) { POutputs.Add(o as POutput); } this.PSliders = new List <PSlider>(PSliders); this.POutputs = new List <POutput>(POutputs); // get target names from POutput compnent nicknames and store as targetnames //List<string> targetnames = new List<string>(); string[] targetnames = new string[POutputs.Count]; int index = 0; foreach (POutput POutput in this.POutputs) { string name = POutput.NickName as string; targetnames[index] = name; index++; } this.targets = new List <string>(targetnames); string projfilename = Path.GetFileNameWithoutExtension(this.doc.FilePath); this.csvfilepath = Path.Combine(this.directory[0], projfilename + "_CSVdata.txt"); }