Ejemplo n.º 1
0
        /// <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 mdSliderObject = null;
            var    newPoint       = new Point3d();

            if (!DA.GetData("UI MD Slider", ref mdSliderObject))
            {
                return;
            }
            var hasValue = DA.GetData("Point", ref newPoint);


            if (newPoint.X > 1.0 || newPoint.Y > 1.0 || newPoint.X < 0 || newPoint.Y < 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Point is out of bounds");
            }


            var mdSlider = HUI_Util.GetUIElement <MDSliderElement>(mdSliderObject);

            if (mdSlider != null && hasValue)
            {
                mdSlider.SliderPoint = newPoint;
            }
        }
Ejemplo n.º 2
0
        //    int sliderIndex = 0;

        /// <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   SliderObject = null;
            Interval range        = Interval.Unset;
            double   newValue     = double.NaN;

            if (!DA.GetData("UI Slider", ref SliderObject))
            {
                return;
            }
            var hasRange = DA.GetData("Range", ref range);
            var hasValue = DA.GetData("Value", ref newValue);

            DockPanel dp = HUI_Util.GetUIElement <DockPanel>(SliderObject);

            var slider = dp.Children.OfType <Grid>().First().Children.OfType <Slider>().First();

            if (hasRange)
            {
                slider.Minimum = range.Min;
                slider.Maximum = range.Max;
            }
            if (hasValue)
            {
                slider.Value = newValue;
            }
        }
Ejemplo n.º 3
0
        /// <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 <UIElement_Goo> elementsToAdd = new List <UIElement_Goo>();
            bool horiz = true;

            if (!DA.GetDataList <UIElement_Goo>("UI Elements", elementsToAdd))
            {
                return;
            }
            DA.GetData <bool>("Horizontal", ref horiz);

            //initialize the WrapPanel panel container
            WrapPanel sp = new WrapPanel();

            sp.Name        = "GH_WrapPanel";
            sp.Orientation = horiz ? Orientation.Horizontal : Orientation.Vertical;
            foreach (UIElement_Goo u in elementsToAdd)
            {
                //Make sure it's not in some other container or window
                HUI_Util.removeParent(u.element);
                sp.Children.Add(u.element);
            }
            //pass out the WrapPanel panel
            DA.SetData("WrapPanel", new UIElement_Goo(sp, "WrapPanel", InstanceGuid, DA.Iteration));
        }
Ejemplo n.º 4
0
        /// <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 CheckBoxObject = null;
            bool   isSelected     = false;

            string newLabelContents = "";
            bool   SetLabel         = DA.GetData <string>("New Check Box Label", ref newLabelContents);

            if (!DA.GetData <object>("Check Box to modify", ref CheckBoxObject))
            {
                return;
            }
            bool SetChecked = DA.GetData <bool>("New Value", ref isSelected);
            // Since HUI textboxes are actually stackpanels with textboxes inside (since they may or may not also contain a button)
            // we have to grab the stackpanel first and then find the textbox inside it.
            //Panel sp = HUI_Util.GetUIElement<Panel>(TextBlockObject);
            //TextBox tb = HUI_Util.findTextBox(sp);
            CheckBox cb = HUI_Util.GetUIElement <CheckBox>(CheckBoxObject);

            //

            if (cb != null)
            {
                //set the text of the textbox.
                if (SetLabel)
                {
                    cb.Content = newLabelContents;
                }
                if (SetChecked)
                {
                    cb.IsChecked = isSelected;
                }
            }
        }
Ejemplo n.º 5
0
        /// <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   show     = true;
            bool   collapse = true;
            object elem     = null;
            bool   disable  = false;

            if (!DA.GetData <bool>("Show", ref show))
            {
                return;
            }
            DA.GetData <bool>("Collapse", ref collapse);
            bool hasDisable = DA.GetData <bool>("Disable", ref disable);


            if (!DA.GetData <object>("Element to Hide/Show", ref elem))
            {
                return;
            }

            //Get the "FrameworkElement" (basic UI element) from an object
            FrameworkElement f = HUI_Util.GetUIElement <FrameworkElement>(elem);

            if (hasDisable)
            {
                f.IsEnabled = !disable;
            }

            f.Visibility = show ? Visibility.Visible : (collapse ? Visibility.Collapsed : Visibility.Hidden);
        }
Ejemplo n.º 6
0
        /// <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)
        {
            System.Drawing.Color        defaultCol    = System.Drawing.Color.Transparent;
            List <System.Drawing.Color> availableCols = new List <System.Drawing.Color>();

            //initialize the picker with default settings
            ColorPicker picker = new ColorPicker();


            //If the user specified a default color, set the picker's selected color.
            if (DA.GetData <System.Drawing.Color>("Default Color", ref defaultCol))
            {
                picker.SelectedColor = HUI_Util.ToMediaColor(defaultCol);
            }


            //if the user specified a list of allowed colors, replace the picker's availableColors list and disable standard colors.
            if (DA.GetDataList <System.Drawing.Color>("Available Colors", availableCols))
            {
                ObservableCollection <ColorItem> cols = new ObservableCollection <ColorItem>();
                foreach (System.Drawing.Color cw in availableCols)
                {
                    Color c = HUI_Util.ToMediaColor(cw);
                    cols.Add(new ColorItem(c, String.Format("{0},{1},{2}", c.R, c.B, c.G)));
                    picker.AvailableColors    = cols;
                    picker.ShowStandardColors = false;
                }
            }


            DA.SetData("Color Picker", new UIElement_Goo(picker, "Color Picker", InstanceGuid, DA.Iteration));
        }
Ejemplo n.º 7
0
        /// <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 ButtonObject = null;

            string newButtonName  = "";
            string newButtonImage = "";

            if (!DA.GetData <object>("Button to modify", ref ButtonObject))
            {
                return;
            }
            bool hasText = DA.GetData <string>("Button Name", ref newButtonName);
            bool hasIcon = DA.GetData <string>("Image Path", ref newButtonImage);

            Button btn = HUI_Util.GetUIElement <Button>(ButtonObject);

            if (btn == null)
            {
                return;
            }

            if (!hasText && !hasIcon)
            {
                return;
            }

            //Initialize the button
            //Button btn = new Button();

            //make button not focusable
            //btn.Focusable = false;

            UpdateButton(newButtonName, newButtonImage, hasText, hasIcon, btn);
        }
        /// <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        tabContainer = null;
            List <string> tabNames     = new List <string>();
            List <bool>   hideTabs     = new List <bool>();

            if (!DA.GetData("Tabbed View", ref tabContainer))
            {
                return;
            }
            bool       hasNames    = DA.GetDataList("Tab Names", tabNames);
            bool       hasHideTabs = DA.GetDataList("Show Tabs", hideTabs);
            TabControl tabControl  = HUI_Util.GetUIElement <TabControl>(tabContainer);

            for (int i = 0; i < tabControl.Items.Count; i++)
            {
                var item    = tabControl.Items[i];
                var tabItem = item as TabItem;
                if (hasNames && tabNames.Count > i)
                {
                    tabItem.Header = tabNames[i];
                }
                if (hasHideTabs && hideTabs.Count > i)
                {
                    tabItem.Visibility = hideTabs[i]
                        ? System.Windows.Visibility.Visible
                        : System.Windows.Visibility.Collapsed;
                    if (!hideTabs[i] && tabControl.SelectedIndex == i)
                    {
                        tabControl.SelectedIndex = (i + 1) % tabControl.Items.Count;
                    }
                }
            }
        }
Ejemplo n.º 9
0
        /// <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   open   = true;
            string header = "";

            DA.GetData <bool>("Open", ref open);
            DA.GetData <string>("Header", ref header);
            List <UIElement_Goo> elementsToAdd = new List <UIElement_Goo>();

            if (!DA.GetDataList <UIElement_Goo>("UI Elements", elementsToAdd))
            {
                return;
            }

            Expander   e  = new Expander();
            StackPanel sp = new StackPanel();

            sp.Name = "GH_Stack";

            foreach (UIElement_Goo u in elementsToAdd)
            {
                //Make sure it's not in some other container or window
                HUI_Util.removeParent(u.element);
                sp.Children.Add(u.element);
            }

            e.IsExpanded = open;
            e.Content    = sp;
            e.Header     = header;
            DA.SetData("Expander", new UIElement_Goo(e, "Expander", InstanceGuid, DA.Iteration));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Write all required data for deserialization to an IO archive.
        /// </summary>
        /// <param name="writer">Object to write with.</param>
        /// <returns>
        /// True on success, false on failure.
        /// </returns>
        public override bool Write(GH_IWriter writer)
        {
            //serialize the states

            GH_IWriter stateSetChunk = writer.CreateChunk("stateSetChunk");

            stateSetChunk.SetInt32("StateCount", savedStates.states.Count);
            int i = 0; //the state

            //for each state in saved states
            foreach (KeyValuePair <string, State> statePair in savedStates.states)
            {
                string     stateName  = statePair.Key;
                GH_IWriter StateChunk = stateSetChunk.CreateChunk("State", i);
                StateChunk.SetString("stateName", stateName);

                State state = statePair.Value;
                StateChunk.SetInt32("itemCount", state.stateDict.Count);
                int j = 0;
                //Custom serialization logic
                //for each element in the state
                foreach (KeyValuePair <UIElement_Goo, object> stateItem in state.stateDict)
                {
                    //get element and value
                    UIElement_Goo element = stateItem.Key;
                    object        value   = stateItem.Value;

                    GH_IWriter stateItemChunk = StateChunk.CreateChunk("stateItem", j);
                    //this info is used to retrieve the dynamic UI element on reserialization, by grabbing the component with matching instance guid
                    //and getting the output item at the matching index.
                    stateItemChunk.SetString("ElementID", element.instanceGuid.ToString());
                    stateItemChunk.SetInt32("ElementIndex", element.index);

                    string stringValue = value.ToString();
                    string typeString  = value.GetType().ToString();
                    //special case for lists of bool - all other element "states" are single items. This only applies to a checklist object.
                    if (value is List <bool> )
                    {
                        typeString  = "LIST OF BOOL";
                        stringValue = HUI_Util.stringFromBools((List <bool>)value);
                    }

                    if (value is List <string> )
                    {
                        typeString  = "LIST OF STRING";
                        stringValue = HUI_Util.stringFromStrings((List <string>)value);
                    }

                    //store the value and a hint as to its type
                    stateItemChunk.SetString("ElementValue", stringValue);
                    stateItemChunk.SetString("ElementValueType", typeString);

                    j++;     //counting up elements in state
                }


                i++; //counting up states
            }
            return(base.Write(writer));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the value of a serialized object from a string and the saved type.
        /// </summary>
        /// <param name="value">The string value.</param>
        /// <param name="valueType">Data type of the value.</param>
        /// <returns></returns>
        object getValue(string value, string valueType)
        {
            switch (valueType)
            {
            case "System.Double":
                double dbl;
                Double.TryParse(value, out dbl);
                return(dbl);

            case "System.Boolean":
                bool bl;
                Boolean.TryParse(value, out bl);
                return(bl);

            case "LIST OF BOOL":
                return(HUI_Util.boolsFromString(value));

            case "LIST OF STRING":
                return(HUI_Util.stringsFromString(value));

            case "System.Drawing.Color":
                string[] res = value.Split("=,]".ToCharArray());
                int      A, R, G, B;
                Int32.TryParse(res[1], out A);
                Int32.TryParse(res[3], out R);
                Int32.TryParse(res[5], out G);
                Int32.TryParse(res[7], out B);
                return(System.Drawing.Color.FromArgb(A, R, G, B));

            default:
                return(value);
            }
        }
        /// <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 there's an output param, pass out the value of restore.
            if (Params.Output.Count > 0)
            {
                DA.SetData(0, restore);
            }

            if (!restore)
            {
                return;
            }

            //retrieve the appropriate state from the state set dictionary
            State stateToRestore = states.states[setName];

            //restore state
            foreach (KeyValuePair <UIElement_Goo, object> elementState in stateToRestore.stateDict)
            {
                UIElement element = elementState.Key.element;

                //if it has a parent, it's a real element that exists - if the parent is null we are in a new document session and the original element
                //may not really exist any longer.
                var parent = System.Windows.Media.VisualTreeHelper.GetParent(element);

                //This is the situation when opening a definition fresh - we have to retrtieve the element based on the saved state's
                //component instance guid and output data index. Because there's no way to serialize a  UIElement we have to retrieve it
                // from the component actively creating it (or more precisely a new but identical instance of it)

                if (parent == null)
                {
                    Guid id    = elementState.Key.instanceGuid;
                    int  index = elementState.Key.index;

                    UIElement_Goo newGoo = SaveElementState_Component.getElementGoo(this.OnPingDocument(), id, index);
                    element = newGoo.element;
                }
                //Once we've got the element, try to set its value.
                HUI_Util.TrySetElementValue(HUI_Util.extractBaseElement(element), elementState.Value);
            }
        }
Ejemplo n.º 13
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            object elem     = null;
            string propName = "";
            object val      = null;



            if (!DA.GetData("UI Element", ref elem))
            {
                return;
            }
            if (!DA.GetData("Property Name", ref propName))
            {
                return;
            }
            if (!DA.GetData("Value to set", ref val))
            {
                return;
            }

            object unwrappedElem = HUI_Util.GetUIElement <UIElement>(elem);

            if (val is GH_ObjectWrapper)
            {
                val = (val as GH_ObjectWrapper).Value;
            }
            else if (val is IGH_Goo)
            {
                try
                {
                    val = val.GetType().GetProperty("Value").GetValue(val);
                }
                catch
                {
                }
            }

            var type = unwrappedElem.GetType();
            var prop = type.GetProperty(propName);

            if (prop == null)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Object type {type} does not contain a property called {propName}");
                return;
            }
            try
            {
                prop.SetValue(unwrappedElem, val);
            }
            catch (Exception e)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, $"Something went wrong setting the property:\n{e.Message}");
            }
        }
Ejemplo n.º 14
0
        /// <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 <Curve> shapeCrvs = new List <Curve>();

            System.Drawing.Color fillCol = System.Drawing.Color.Transparent;
            double strokeWeight          = 0.0;

            System.Drawing.Color strokeCol = System.Drawing.Color.Transparent;
            double scale  = 1.0;
            int    width  = 0;
            int    height = 0;

            if (!DA.GetDataList <Curve>("Shape", shapeCrvs))
            {
                return;
            }
            //initialize path object
            Path path = new Path();

            DA.GetData <double>("Scale", ref scale);

            //set path data to geometry from curve list
            path.Data = pathGeomFromCrvs(shapeCrvs, scale, false);
            if (DA.GetData <System.Drawing.Color>("Fill Color", ref fillCol))
            {
                path.Fill = new SolidColorBrush(HUI_Util.ToMediaColor(fillCol));
            }

            if (DA.GetData <double>("Stroke Weight", ref strokeWeight))
            {
                path.StrokeThickness = strokeWeight;
            }

            if (DA.GetData <System.Drawing.Color>("Stroke Color", ref strokeCol))
            {
                path.Stroke = new SolidColorBrush(HUI_Util.ToMediaColor(strokeCol));
            }

            //initialize a grid to contain the shapes
            Grid G = new Grid();

            if (DA.GetData <int>("Width", ref width))
            {
                G.Width = width;
            }
            if (DA.GetData <int>("Height", ref height))
            {
                G.Height = height;
            }
            G.Children.Add(path);

            //pass out the grid containing the shape
            DA.SetData("Shape", new UIElement_Goo(G, "Shape", InstanceGuid, DA.Iteration));
        }
Ejemplo n.º 15
0
        /// <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        ChartObject  = null;
            List <double> listContents = new List <double>();
            List <string> names        = new List <string>();
            bool          Legend       = true;
            bool          Title        = true;

            List <System.Drawing.Color> Col = new List <System.Drawing.Color>();

            System.Drawing.Color fgCol = System.Drawing.Color.Transparent;

            //Get the Chart object and assign it
            if (!DA.GetData <object>("Chart to modify", ref ChartObject))
            {
                return;
            }
            var ChartElem = HUI_Util.GetUIElement <ChartBase>(ChartObject);

            bool hasLegend = DA.GetData <bool>("Legend", ref Legend);
            bool hasTitle  = DA.GetData <bool>("Title", ref Title);
            bool hasColors = DA.GetDataList <System.Drawing.Color>("Colors", Col);

            if (hasColors)
            {
                ResourceDictionaryCollection Palette = new ResourceDictionaryCollection();
                Palette = createResourceDictionary(Col);

                System.Windows.Media.Brush BorderBrush = new SolidColorBrush(HUI_Util.ToMediaColor(Col[0]));
                ChartElem.BorderBrush = BorderBrush;
                ChartElem.Palette     = Palette;
            }

            if (hasLegend)
            {
                Visibility LegendVis = Visibility.Hidden;
                if (Legend)
                {
                    LegendVis = Visibility.Visible;
                }
                ChartElem.ChartLegendVisibility = LegendVis;
            }
            if (hasTitle)
            {
                Visibility TitleVis = Visibility.Hidden;
                if (Title)
                {
                    TitleVis = Visibility.Visible;
                }
                ChartElem.ChartTitleVisibility = TitleVis;
            }
        }
Ejemplo n.º 16
0
        /// <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)
        {
            //set up the variables for GetData
            MainWindow           mw            = null;
            List <UIElement_Goo> elementsToAdd = new List <UIElement_Goo>();

            Dictionary <string, UIElement_Goo> resultDict = new Dictionary <string, UIElement_Goo>();

            //Get data from component
            if (!DA.GetData <MainWindow>("Window", ref mw))
            {
                return;
            }
            if (!DA.GetDataList <UIElement_Goo>("Elements", elementsToAdd))
            {
                return;
            }

            //clear out any old elements
            mw.clearElements();

            if (DoVLChecking)
            {
                //check for any value listener connected to the same window
                var ActiveObjects        = OnPingDocument().ActiveObjects();
                var AllSources           = HUI_Util.SourcesRecursive(Params.Input[1], ActiveObjects);
                var ValueListenerSources = AllSources.OfType <ValueListener_Component>();
                if (ValueListenerSources.Count() != 0)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, VALUE_LISTENER_WARNING);
                }
            }
            //for all the elements, remove its parent, add it to the window, and add it to our tracking dictionary
            foreach (UIElement_Goo u in elementsToAdd)
            {
                if (u == null)
                {
                    continue;
                }
                HUI_Util.removeParent(u.element);
                mw.AddElement(u.element);
                HUI_Util.AddToDict(u, resultDict);
            }

            //Pass out the added elements and their names. This is no longer so necessary now that listeners attach to elements directly.
            DA.SetDataList("Added Elements", resultDict);
            DA.SetDataList("Element Names", resultDict.Keys);
        }
Ejemplo n.º 17
0
        /// <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      o = null;
            List <Mesh> m = new List <Mesh>();
            List <System.Drawing.Color> cols = new List <System.Drawing.Color>();

            if (!DA.GetData <object>("3D View", ref o))
            {
                return;
            }
            DA.GetDataList <Mesh>("Mesh to display", m);

            //Get the 3d viewport object out of the input object
            HelixViewport3D vp3 = HUI_Util.GetUIElement <HelixViewport3D>(o);

            ModelVisual3D        mv3  = GetModelVisual3D(vp3);
            List <ModelVisual3D> mv3s = GetModels(vp3);
            List <Material>      mats = new List <Material>();

            vp3.Children.Clear();
            vp3.Children.Add(new SunLight());

            if (!DA.GetDataList <System.Drawing.Color>("Mesh Colors", cols))
            {
                foreach (ModelVisual3D mv30 in mv3s)
                {
                    Model3DGroup model = mv30.Content as Model3DGroup;
                    foreach (Model3D mod in model.Children)
                    {
                        if (mod is GeometryModel3D)
                        {
                            GeometryModel3D geom = mod as GeometryModel3D;
                            mats.Add(geom.Material);
                        }
                    }
                }
                mv3.Content = new _3DViewModel(m, mats).Model;
            }
            else
            {
                mv3.Content = new _3DViewModel(m, cols).Model;
            }



            vp3.Children.Add(mv3);
        }
Ejemplo n.º 18
0
        /// <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        ListObject   = null;
            List <string> listContents = new List <string>();
            List <bool>   isSelected   = new List <bool>();

            if (!DA.GetData <object>("Checklist to modify", ref ListObject))
            {
                return;
            }
            if (!DA.GetDataList <string>("New checklist contents", listContents))
            {
                return;
            }

            //Get the scroll viewer
            ScrollViewer sv = HUI_Util.GetUIElement <ScrollViewer>(ListObject);
            //Get the itemsControl inside the scrollviewer
            ItemsControl ic = sv.Content as ItemsControl;

            if (!DA.GetDataList <bool>("Selected", isSelected))
            {
            }

            //clear the items in there now
            ic.Items.Clear();

            //set the new items
            for (int i = 0; i < listContents.Count; i++)
            {
                string item = listContents[i];

                CheckBox cb = new CheckBox();
                cb.Margin  = new System.Windows.Thickness(2);
                cb.Content = item;
                if (isSelected.Count > 0)
                {
                    // this is a cheap shortcut - but allows an approximation of "shortest list" behavior for cases of N and 1. If only one true is
                    // passed, all boxes true, if a list is passed, will behave as expected. Only list-length mismatches will behave differently - and if
                    // you're doing that, we have bigger problems anyway.
                    bool isSel = isSelected[i % isSelected.Count];
                    cb.IsChecked = isSel;
                }
                ic.Items.Add(cb);
            }
        }
        /// <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 <UIElement_Goo> elementsToAdd = new List <UIElement_Goo>();
            double width  = 0;
            double height = 0;

            if (!DA.GetDataList <UIElement_Goo>("UI Elements", elementsToAdd))
            {
                return;
            }
            if (!DA.GetData <double>("Width", ref width))
            {
                return;
            }
            if (!DA.GetData <double>("Height", ref height))
            {
                return;
            }

            //initialize the grid
            Grid grid = new Grid();

            grid.HorizontalAlignment = HorizontalAlignment.Left;
            grid.VerticalAlignment   = VerticalAlignment.Top;
            grid.Name   = "GH_Grid";
            grid.Width  = width;
            grid.Height = height;
            //for all the elements to add
            foreach (UIElement_Goo u in elementsToAdd)
            {
                //make sure it doesn't already have a parent
                HUI_Util.removeParent(u.element);
                FrameworkElement fe = u.element as FrameworkElement;
                if (fe != null)
                {
                    //set its alignment to be relative to upper left - this makes margin-based positioning easy
                    fe.HorizontalAlignment = HorizontalAlignment.Left;
                    fe.VerticalAlignment   = VerticalAlignment.Top;
                }
                //add it to the grid
                grid.Children.Add(u.element);
            }
            //pass the grid out
            DA.SetData("Grid", new UIElement_Goo(grid, "Grid", InstanceGuid, DA.Iteration));
        }
Ejemplo n.º 20
0
        /// <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 obj     = null;
            bool   forward = false;
            bool   back    = false;
            bool   refresh = false;
            string URL     = "";

            if (!DA.GetData <object>("Browser", ref obj))
            {
                return;
            }
            //get the web browser object
            WebBrowser wb = HUI_Util.GetUIElement <WebBrowser>(obj);

            //Back
            if (DA.GetData <bool>("Back", ref back))
            {
                if (wb.CanGoBack && back)
                {
                    wb.GoBack();
                }
            }
            //Forward
            if (DA.GetData <bool>("Forward", ref forward))
            {
                if (wb.CanGoForward && forward)
                {
                    wb.GoForward();
                }
            }
            //Refresh
            if (DA.GetData <bool>("Refresh", ref refresh))
            {
                if (refresh)
                {
                    wb.Refresh();
                }
            }
            //URL
            if (DA.GetData <string>("URL", ref URL))
            {
                wb.Source = new Uri(URL);
            }
        }
Ejemplo n.º 21
0
        /// <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        tabContainer = null;
            List <string> tabNames     = new List <string>();
            List <bool>   hideTabs     = new List <bool>();
            int           selectIndex  = -1;

            if (!DA.GetData("Tabbed View", ref tabContainer))
            {
                return;
            }
            bool       hasNames    = DA.GetDataList("Tab Names", tabNames);
            bool       hasHideTabs = DA.GetDataList("Show Tabs", hideTabs);
            bool       hasIndex    = DA.GetData(3, ref selectIndex);
            TabControl tabControl  = HUI_Util.GetUIElement <TabControl>(tabContainer);

            for (int i = 0; i < tabControl.Items.Count; i++)
            {
                var item    = tabControl.Items[i];
                var tabItem = item as TabItem;
                if (hasNames && tabNames.Count > i)
                {
                    tabItem.Header = tabNames[i];
                }
                if (hasHideTabs && hideTabs.Count > i)
                {
                    tabItem.Visibility = hideTabs[i]
                        ? System.Windows.Visibility.Visible
                        : System.Windows.Visibility.Collapsed;
                    if (!hideTabs[i] && tabControl.SelectedIndex == i)
                    {
                        tabControl.SelectedIndex = (i + 1) % tabControl.Items.Count;
                    }
                }
            }
            if (hasIndex)
            {
                tabControl.SelectedIndex = selectIndex;

                // In order to register the tab state properly, you must pull the tabControl into focus.
                // Otherwise, the next time you click on the contents it will revert to the last index position properly registered.
                tabControl.Focus();
            }
        }
Ejemplo n.º 22
0
        /// <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        ListObject    = null;
            List <string> listContents  = new List <string>();
            int           selectedIndex = -1;

            if (!DA.GetData <object>("List to modify", ref ListObject))
            {
                return;
            }
            if (!DA.GetDataList <string>("New list contents", listContents))
            {
                return;
            }



            //the selector parent class includes both ListBoxes and ComboBoxes
            Selector sel = HUI_Util.GetUIElement <Selector>(ListObject);

            if (sel == null)
            {
                var listPanel = HUI_Util.GetUIElement <DockPanel>(ListObject);
                sel = listPanel.Children.OfType <Selector>().FirstOrDefault();
            }

            if (!DA.GetData <int>("Selected Index", ref selectedIndex))
            {
                selectedIndex = sel.SelectedIndex;
            }

            //clear out the existing list
            sel.Items.Clear();

            //add all items in the input list as TextBlocks
            foreach (string item in listContents)
            {
                TextBlock textbox = new TextBlock();
                textbox.Text = item;
                sel.Items.Add(textbox);
            }
            //set selected index
            sel.SelectedIndex = selectedIndex;
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            object elem = null;



            if (!DA.GetData("UI Element", ref elem))
            {
                return;
            }

            object unwrappedElem = HUI_Util.GetUIElement <UIElement>(elem);


            var type  = unwrappedElem.GetType();
            var props = type.GetProperties();

            DA.SetDataList("Property Names", props.Select(p => p.Name));
            DA.SetDataList("Property Types", props.Select(p => p.PropertyType.ToString()));
        }
Ejemplo n.º 24
0
        /// <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 ImageObject  = null;
            string newImagePath = "";

            if (!DA.GetData <string>("New Image Path", ref newImagePath))
            {
                return;
            }
            if (!DA.GetData <object>("Image to modify", ref ImageObject))
            {
                return;
            }
            Image l = HUI_Util.GetUIElement <Image>(ImageObject);

            if (l != null)
            {
                HUI_Util.SetImageSource(newImagePath, l);
            }
        }
Ejemplo n.º 25
0
        /// <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 <UIElement_Goo> elementsToAdd = new List <UIElement_Goo>();
            double width  = 0;
            double height = 0;

            if (!DA.GetDataList <UIElement_Goo>("UI Elements", elementsToAdd))
            {
                return;
            }
            if (!DA.GetData <double>("Width", ref width))
            {
                return;
            }
            if (!DA.GetData <double>("Height", ref height))
            {
                return;
            }
            //intitalize the viewbox
            Viewbox vb = new Viewbox();

            vb.Width   = width;
            vb.Height  = height;
            vb.Stretch = Stretch.Uniform;

            //create a stackpanel to contain elements
            StackPanel sp = new StackPanel();

            foreach (UIElement_Goo u in elementsToAdd)
            {
                //make sure elements don't already have a parent and add them to the stackpanel
                HUI_Util.removeParent(u.element);
                sp.Children.Add(u.element);
            }
            //place the stackpanel inside the viewbox
            vb.Child = sp;


            //pass out the viewbox object
            DA.SetData("ViewBox", new UIElement_Goo(vb, "ViewBox", InstanceGuid, DA.Iteration));
        }
Ejemplo n.º 26
0
        /// <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 LabelObject      = null;
            string newLabelContents = "";

            if (!DA.GetData <string>("New Label contents", ref newLabelContents))
            {
                return;
            }
            if (!DA.GetData <object>("Label to modify", ref LabelObject))
            {
                return;
            }
            Label l = HUI_Util.GetUIElement <Label>(LabelObject);

            //set label content
            if (l != null)
            {
                l.Content = newLabelContents;
            }
        }
Ejemplo n.º 27
0
        /// <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 TextBlockObject      = null;
            string newTextBlockContents = "";

            if (!DA.GetData <string>("New Text Block contents", ref newTextBlockContents))
            {
                return;
            }
            if (!DA.GetData <object>("Text Block to modify", ref TextBlockObject))
            {
                return;
            }
            //extract the TextBlock object from the generic object
            TextBlock l = HUI_Util.GetUIElement <TextBlock>(TextBlockObject);

            if (l != null)
            {
                //set its contents
                l.Text = newTextBlockContents;
            }
        }
Ejemplo n.º 28
0
        /// <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)
        {
            UIElement_Goo elementToAdd = null;
            double        thickness    = 5;
            Color         color        = Color.Black;
            double        radius       = 0;

            if (!DA.GetData <UIElement_Goo>("UI Element", ref elementToAdd))
            {
                return;
            }
            if (!DA.GetData("Border Thickness", ref thickness))
            {
                return;
            }
            if (!DA.GetData("Border Color", ref color))
            {
                return;
            }
            if (!DA.GetData("Corner Radius", ref radius))
            {
                return;
            }
            //intitalize the Border
            Border border = new Border
            {
                BorderThickness = new Thickness(thickness),
                BorderBrush     = new SolidColorBrush(HUI_Util.ToMediaColor(color)),
                CornerRadius    = new CornerRadius(radius)
            };

            HUI_Util.removeParent(elementToAdd.element);
            border.Child = elementToAdd.element;


            //pass out the Border object
            DA.SetData("Border", new UIElement_Goo(border, "Border", InstanceGuid, DA.Iteration));
        }
Ejemplo n.º 29
0
        /// <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 TextBlockObject  = null;
            string newLabelContents = "";

            if (!DA.GetData <string>("New Text Box contents", ref newLabelContents))
            {
                return;
            }
            if (!DA.GetData <object>("Text Box to modify", ref TextBlockObject))
            {
                return;
            }
            // Since HUI textboxes are actually stackpanels with textboxes inside (since they may or may not also contain a button)
            // we have to grab the stackpanel first and then find the textbox inside it.
            Panel   sp = HUI_Util.GetUIElement <Panel>(TextBlockObject);
            TextBox tb = HUI_Util.findTextBox(sp);

            if (tb != null)
            {
                //set the text of the textbox.
                tb.Text = newLabelContents;
            }
        }
Ejemplo n.º 30
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            object expanderElement = null;
            string newName         = "";
            bool   expanded        = false;

            if (!DA.GetData("Expander", ref expanderElement))
            {
                return;
            }
            bool hasName     = DA.GetData("Name", ref newName);
            bool hasExpanded = DA.GetData("Expanded Open", ref expanded);

            Expander e = HUI_Util.GetUIElement <Expander>(expanderElement);

            if (hasName)
            {
                e.Header = newName;
            }
            if (hasExpanded)
            {
                e.IsExpanded = expanded;
            }
        }