/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { object elem = null; object contentElem = null; int showDelay = 500; int duration = 2000; if (!DA.GetData <object>("Elements to Attach to", ref elem)) { return; } if (!DA.GetData <object>("Tooltip Content", ref contentElem)) { return; } DA.GetData <int>("Show Delay", ref showDelay); DA.GetData <int>("Duration", ref duration); FrameworkElement f = HUI_Util.GetUIElement <FrameworkElement>(elem); FrameworkElement contentElement = HUI_Util.GetUIElement <FrameworkElement>(contentElem); if (contentElement != null) { f.ToolTip = contentElement; } else { f.ToolTip = contentElem; } ToolTipService.SetShowDuration(f, duration); ToolTipService.SetInitialShowDelay(f, showDelay); ToolTipService.SetBetweenShowDelay(f, showDelay); }
/// <summary> /// Initializes a new instance of the <see cref="_3DViewModel"/> class with colors for each mesh /// </summary> /// <param name="meshes">The meshes.</param> /// <param name="colors">The colors.</param> public _3DViewModel(List <Mesh> meshes, List <System.Drawing.Color> colors) { List <Material> mats = new List <Material>(); for (int i = 0; i < meshes.Count; i++) { mats.Add(MaterialHelper.CreateMaterial(HUI_Util.ToMediaColor(colors[i % colors.Count]))); } setupModel(meshes, mats, false); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { bool restore = false; string setName = ""; StateSet_Goo states = null; if (!DA.GetData <StateSet_Goo>("Saved States", ref states)) { return; } if (!DA.GetData <string>("State Name to restore", ref setName)) { return; } DA.GetData <bool>("Restore", ref restore); if (!restore) { return; } State stateToRestore = states.states[setName]; //restore state foreach (KeyValuePair <UIElement_Goo, object> elementState in stateToRestore.stateDict) { // AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, string.Format("Setting element {0} to {1}", HUI_Util.extractBaseElement(elementState.Key.element).ToString(), elementState.Value)); UIElement element = elementState.Key.element; var parent = System.Windows.Media.VisualTreeHelper.GetParent(element); // AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "Parent is: "+parent.ToString()); if (parent == null) { Guid id = elementState.Key.instanceGuid; int index = elementState.Key.index; UIElement_Goo newGoo = Components.UI_Main.SaveElementState_Component.getElementGoo(this.OnPingDocument(), id, index); element = newGoo.element; } HUI_Util.TrySetElementValue(HUI_Util.extractBaseElement(element), elementState.Value); } }
public static HUI_Gradient FromGHGradient(GH_Gradient g) { List <Color> cols = new List <Color>(); List <double> ts = new List <double>(); var gType = typeof(GH_Gradient); var Flags = BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.SetProperty | BindingFlags.GetField | BindingFlags.SetField | BindingFlags.NonPublic; var fields = gType.GetFields(Flags); var gripsField = fields.Where(f => f.Name == "m_grips").FirstOrDefault(); var grips = gripsField.GetValue(g) as List <GH_Grip>; foreach (var grip in grips) { cols.Add(HUI_Util.ToMediaColor(grip.ColourLeft)); ts.Add(grip.Parameter); } return(new HUI_Gradient(ts, cols)); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { if (DA.Iteration > 0) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "It looks like you're trying to do something with data trees here that doesn't make sense."); return; } List <List <UIElement_Goo> > tabList = new List <List <UIElement_Goo> >(); double fontSize = 26; List <string> tabNames = new List <string>(); DA.GetDataList <string>("Tab Names", tabNames); //get the data from the variable input params for (int i = 2; i < Params.Input.Count; i++) { List <UIElement_Goo> currentTab = new List <UIElement_Goo>(); DA.GetDataList <UIElement_Goo>(i, currentTab); tabList.Add(currentTab); } //validate that there's a tab name for every variable input if (tabList.Count != tabNames.Count) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "You don't have the same number of specified tab names and tab inputs."); } //create the tab control TabControl tabControl = new TabControl(); //TabControlHelper.SetIsUnderlined(tabControl, true); bool setSize = DA.GetData <double>("Tab Text Size", ref fontSize); //for each tab, int tabIndex = 0; foreach (List <UIElement_Goo> oneTab in tabList) { //create a tabItem TabItem tabItem = new TabItem(); if (setSize) { ControlsHelper.SetHeaderFontSize(tabItem, fontSize); } string tabName = "New Tab"; if (tabIndex < tabNames.Count) { tabName = tabNames[tabIndex]; } tabItem.Header = tabName; //create a stackpanel StackPanel sp = new StackPanel(); sp.Name = "GH_TabItem"; sp.Orientation = Orientation.Vertical; foreach (UIElement_Goo u in oneTab) { HUI_Util.removeParent(u.element); sp.Children.Add(u.element); } tabItem.Content = sp; tabControl.Items.Add(tabItem); tabIndex++; } DA.SetData("Tabs", new UIElement_Goo(tabControl, String.Format("Tab Control with {0} tabs", tabList.Count), InstanceGuid, DA.Iteration)); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <object> elementObjects = new List <object>(); List <KeyValuePair <string, UIElement_Goo> > allElements = new List <KeyValuePair <string, UIElement_Goo> >(); List <string> elementFilters = new List <string>(); if (!DA.GetDataList <object>("Elements", elementObjects)) { return; } DA.GetDataList <string>("Name Filter(s)", elementFilters); //the elements to listen to List <UIElement> filteredElements = new List <UIElement>(); //decide whether to populate the dictionary, or just populate filteredElements directly. foreach (object o in elementObjects) { UIElement elem = null; switch (o.GetType().ToString()) { case "HumanUI.UIElement_Goo": UIElement_Goo goo = o as UIElement_Goo; elem = goo.element as UIElement; filteredElements.Add(elem); break; case "Grasshopper.Kernel.Types.GH_ObjectWrapper": GH_ObjectWrapper wrapper = o as GH_ObjectWrapper; KeyValuePair <string, UIElement_Goo> kvp = (KeyValuePair <string, UIElement_Goo>)wrapper.Value; allElements.Add(kvp); break; default: break; } } if (allElements.Count > 0) //if we've been getting keyvaluepairs and need to filter { //create a dictionary for filtering Dictionary <string, UIElement_Goo> elementDict = allElements.ToDictionary(pair => pair.Key, pair => pair.Value); //filter the dictionary foreach (string fil in elementFilters) { filteredElements.Add(elementDict[fil].element); } //if there are no filters, include all values. if (elementFilters.Count == 0) { foreach (UIElement_Goo u in elementDict.Values) { filteredElements.Add(u.element); } } } //remove all events from previously "evented" elements foreach (UIElement u in eventedElements) { RemoveEvents(u); } eventedElements.Clear(); //extract base elements List <UIElement> elementsToListen = new List <UIElement>(); HUI_Util.extractBaseElements(filteredElements, elementsToListen); //retrieve element values GH_Structure <IGH_Goo> values = new GH_Structure <IGH_Goo>(); GH_Structure <GH_Integer> indsOut = new GH_Structure <GH_Integer>(); int i = 0; foreach (UIElement u in elementsToListen) { object value = HUI_Util.GetElementValue(u); object indices = HUI_Util.GetElementIndex(u); IEnumerable list = null; if ((value as string) == null) { list = value as IEnumerable; } IEnumerable indList = indices as IEnumerable; if (list != null) { foreach (object thing in list) { values.Append(HUI_Util.GetRightType(thing), new GH_Path(i)); } } else { values.Append(HUI_Util.GetRightType(value), new GH_Path(i)); } if (indList != null) { foreach (int index in indList) { indsOut.Append(new GH_Integer(index), new GH_Path(i)); } } else { indsOut.Append(new GH_Integer((int)indices), new GH_Path(i)); } //add listener events to elements if (AddEventsEnabled) { eventedElements.Add(u); AddEvents(u); } i++; } DA.SetDataTree(0, values); DA.SetDataTree(1, indsOut); }
static public object GetElementValue(UIElement u) { switch (u.GetType().ToString()) { case "System.Windows.Controls.Slider": Slider s = u as Slider; return(s.Value); case "System.Windows.Controls.Button": Button b = u as Button; return((System.Windows.Input.Mouse.LeftButton == System.Windows.Input.MouseButtonState.Pressed) && b.IsMouseOver); case "HumanUI.TrueOnlyButton": TrueOnlyButton tob = u as TrueOnlyButton; return((System.Windows.Input.Mouse.LeftButton == System.Windows.Input.MouseButtonState.Pressed) && tob.IsMouseOver); case "HumanUI.HUI_RhPickButton": HUI_RhPickButton rpb = u as HUI_RhPickButton; return(rpb.objIDs); case "System.Windows.Controls.Label": Label l = u as Label; return(l.Content); case "System.Windows.Controls.ListBox": ListBox lb = u as ListBox; TextBlock lab = lb.SelectedItem as TextBlock; if (lab != null) { return(lab.Text); } else { return(null); } case "System.Windows.Controls.ScrollViewer": ScrollViewer sv = u as ScrollViewer; ItemsControl ic = sv.Content as ItemsControl; List <bool> checkeds = new List <bool>(); var cbs = from cbx in ic.Items.OfType <CheckBox>() select cbx; foreach (CheckBox chex in cbs) { checkeds.Add(chex.IsChecked == true); } return(checkeds); case "System.Windows.Controls.TextBox": TextBox tb = u as TextBox; return(tb.Text); case "System.Windows.Controls.ComboBox": ComboBox cb = u as ComboBox; TextBlock cbi = cb.SelectedItem as TextBlock; if (cbi != null) { return(cbi.Text); } else { return(null); } case "Xceed.Wpf.Toolkit.ColorPicker": ColorPicker colP = u as ColorPicker; //return cbi.Content; return(HUI_Util.ToSysColor(colP.SelectedColor)); case "System.Windows.Controls.ListView": ListView v = u as ListView; var cbxs = from cbx in v.Items.OfType <CheckBox>() select cbx; List <string> checkedVals = new List <string>(); foreach (CheckBox chex in cbxs) { if (chex.IsChecked == true) { checkedVals.Add(chex.Content.ToString()); } } return(String.Join(",", checkedVals)); case "System.Windows.Controls.CheckBox": CheckBox chb = u as CheckBox; return(chb.IsChecked); case "System.Windows.Controls.RadioButton": RadioButton rb = u as RadioButton; return(rb.IsChecked); case "System.Windows.Controls.Image": Image img = u as Image; return(img.Source.ToString()); case "System.Windows.Controls.Expander": Expander exp = u as Expander; return(exp.IsExpanded); case "System.Windows.Controls.TabControl": TabControl tc = u as TabControl; TabItem ti = tc.SelectedItem as TabItem; if (ti == null) { ti = tc.Items[0] as TabItem; } return(ti.Header.ToString()); case "MahApps.Metro.Controls.ToggleSwitch": ToggleSwitch ts = u as ToggleSwitch; return(ts.IsChecked); case "MahApps.Metro.Controls.RangeSlider": RangeSlider rs = u as RangeSlider; return(new Interval(rs.LowerValue, rs.UpperValue)); case "De.TorstenMandelkow.MetroChart.ChartBase": case "De.TorstenMandelkow.MetroChart.PieChart": case "De.TorstenMandelkow.MetroChart.ClusteredBarChart": case "De.TorstenMandelkow.MetroChart.ClusteredColumnChart": case "De.TorstenMandelkow.MetroChart.DoughnutChart": case "De.TorstenMandelkow.MetroChart.RadialGaugeChart": case "De.TorstenMandelkow.MetroChart.StackedBarChart": case "De.TorstenMandelkow.MetroChart.StackedColumnChart": ChartBase chart = u as ChartBase; ChartItem selectedItem = chart.SelectedItem as ChartItem; if (selectedItem != null) { string response = ""; if (!String.IsNullOrEmpty(selectedItem.ClusterCategory)) { response += selectedItem.ClusterCategory + ": "; } response += selectedItem.Category; return(response); } else { return(null); } case "System.Windows.Controls.DataGrid": DataGrid datagrid = u as DataGrid; var SelectedItem = datagrid.SelectedItem; //System.Data.DataView dv = datagrid.ItemsSource as System.Data.DataView; List <string> result = new List <string>(); try { System.Data.DataRowView drv = SelectedItem as System.Data.DataRowView; result = drv.Row.ItemArray.Cast <string>().ToList(); result.RemoveAt(0); } catch { } return(result); case "HumanUI.MDSliderElement": MDSliderElement mds = u as MDSliderElement; return(mds.SliderPoint); case "HumanUI.GraphMapperElement": GraphMapperElement gme = u as GraphMapperElement; return(gme.GetCurve().ToNurbsCurve()); case "HumanUI.HUI_GradientEditor": HUI_GradientEditor hge = u as HUI_GradientEditor; return(hge.Gradient.ToString()); case "HumanUI.FilePicker": FilePicker fp = u as FilePicker; return(fp.Path); case "HumanUI.ClickableShapeGrid": ClickableShapeGrid csg = u as ClickableShapeGrid; return(csg.SelectedStates); default: return(null); } }
static public void TrySetElementValue(UIElement u, object o) { try { switch (u.GetType().ToString()) { case "System.Windows.Controls.Slider": Slider s = u as Slider; //System.Windows.Forms.MessageBox.Show(o.GetType().ToString()); s.Value = (double)o; return; case "System.Windows.Controls.ListBox": ListBox lb = u as ListBox; lb.SelectedIndex = getSelectedItemIndex(lb, (string)o); return; case "System.Windows.Controls.TextBox": TextBox tb = u as TextBox; tb.Text = (string)o; return; case "System.Windows.Controls.ComboBox": ComboBox cb = u as ComboBox; cb.SelectedIndex = getSelectedItemIndex(cb, (string)o); return; case "Xceed.Wpf.Toolkit.ColorPicker": ColorPicker colP = u as ColorPicker; System.Drawing.Color sysCol = (System.Drawing.Color)o; colP.SelectedColor = HUI_Util.ToMediaColor(sysCol); return; case "System.Windows.Controls.ScrollViewer": //it's a checklist ScrollViewer sv = u as ScrollViewer; List <bool> valueList = (List <bool>)o; ItemsControl ic = sv.Content as ItemsControl; var cbs = from cbx in ic.Items.OfType <CheckBox>() select cbx; int i = 0; foreach (CheckBox chex in cbs) { chex.IsChecked = valueList[i]; i++; } return; case "System.Windows.Controls.CheckBox": CheckBox chb = u as CheckBox; chb.IsChecked = (bool)o; return; case "MahApps.Metro.Controls.ToggleSwitch": ToggleSwitch ts = u as ToggleSwitch; ts.IsChecked = (bool)o; return; case "MahApps.Metro.Controls.RangeSlider": RangeSlider rs = u as RangeSlider; var valueRange = (Interval)o; rs.UpperValue = valueRange.Max; rs.LowerValue = valueRange.Min; return; case "System.Windows.Controls.RadioButton": RadioButton rb = u as RadioButton; rb.IsChecked = (bool)o; return; case "System.Windows.Controls.DataGrid": DataGrid datagrid = u as DataGrid; List <string> selectedRowContents = (List <string>)o; try { DataView dv = datagrid.ItemsSource as DataView; foreach (DataRowView drv in dv) { var items = drv.Row.ItemArray.Cast <string>().ToList(); items.RemoveAt(0); //get rid of hidden index column bool selectRow = true; for (int counter = 0; counter < items.Count; counter++) { if (selectedRowContents[counter] != items[counter]) { selectRow = false; break; } } if (selectRow) { datagrid.SelectedItem = drv; } } } catch { } return; case "HumanUI.MDSliderElement": MDSliderElement mds = u as MDSliderElement; mds.SliderPoint = (Rhino.Geometry.Point3d)o; return; case "HumanUI.GraphMapperElement": GraphMapperElement gme = u as GraphMapperElement; gme.SetByCurve((Rhino.Geometry.NurbsCurve)o); return; case "HumanUI.HUI_GradientEditor": HUI_GradientEditor hge = u as HUI_GradientEditor; HUI_Gradient gradient = HUI_Gradient.FromString((string)o); hge.Gradient = gradient; return; case "HumanUI.FilePicker": FilePicker fp = u as FilePicker; fp.Path = (string)o; return; default: return; } } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.ToString()); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <KeyValuePair <string, UIElement_Goo> > allElements = new List <KeyValuePair <string, UIElement_Goo> >(); List <string> filters = new List <string>(); Dictionary <string, UIElement_Goo> resultDict = new Dictionary <string, UIElement_Goo>(); if (!DA.GetDataList <KeyValuePair <string, UIElement_Goo> >("Elements", allElements)) { return; } if (!DA.GetDataList <string>("Name Filter(s)", filters)) { return; } //filter out objects in the dictionary Dictionary <string, UIElement_Goo> elementDict = allElements.ToDictionary(pair => pair.Key, pair => pair.Value); Dictionary <string, UIElement_Goo> results = new Dictionary <string, UIElement_Goo>(); foreach (string fil in filters) { results.Add(fil, elementDict[fil]); } List <UIElement_Goo> childElements = new List <UIElement_Goo>(); int i = 0; //the parent element index foreach (UIElement_Goo ListObject in results.Values.ToList <UIElement_Goo>()) { int j = 0; // //get the container object UIElement container = HUI_Util.GetUIElement <UIElement>(ListObject); switch (container.GetType().ToString()) { case "System.Windows.Controls.StackPanel": StackPanel sp = container as StackPanel; foreach (UIElement elem in sp.Children) { childElements.Add(new UIElement_Goo(elem, String.Format("StackPanel {0}/{2} {1}", i, j, HUI_Util.elemType(elem)), InstanceGuid, DA.Iteration)); j++; } break; case "System.Windows.Controls.TabControl": TabControl tc = container as TabControl; foreach (object o in tc.Items) //foreach tab { if (o is TabItem) { TabItem ti = o as TabItem; StackPanel spInside = ti.Content as StackPanel; int k = 0; //the item it is in the tab foreach (UIElement elem in spInside.Children) { childElements.Add(new UIElement_Goo(elem, String.Format("Tab Control {0}/{1}/{2} {3}", i, ti.Header.ToString(), HUI_Util.elemType(elem), k), InstanceGuid, DA.Iteration)); k++; } j++; } else if (o is UIElement) { UIElement elem = o as UIElement; childElements.Add(new UIElement_Goo(elem, String.Format("Tab Control {0}/{1}", i, HUI_Util.elemType(elem)), InstanceGuid, DA.Iteration)); } } break; default: AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "One or more of the elements is not a valid container."); break; } i++; } //get its children elements //output filtered child elements foreach (UIElement_Goo u in childElements) { HUI_Util.AddToDict(u, resultDict); } DA.SetDataList("Child Elements", resultDict); DA.SetDataList("Element Names", resultDict.Keys); }