Exemplo 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;
            }
        }
        /// <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;
                    }
                }
            }
        }
Exemplo n.º 3
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;
            }
        }
Exemplo 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;
                }
            }
        }
Exemplo 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);
        }
Exemplo 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)
        {
            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);
        }
Exemplo n.º 7
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}");
            }
        }
Exemplo n.º 8
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;
            }
        }
Exemplo 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)
        {
            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);
        }
Exemplo n.º 10
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);
            }
        }
Exemplo n.º 11
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);
            }
        }
Exemplo n.º 12
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;
        }
Exemplo n.º 13
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();
            }
        }
        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()));
        }
Exemplo 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 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);
            }
        }
Exemplo 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)
        {
            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;
            }
        }
Exemplo 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 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;
            }
        }
Exemplo 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 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;
            }
        }
Exemplo n.º 19
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)
        {
            //Create a basic object to hold the UI Element prior to type conversion
            object myUIElement = null;

            System.Drawing.Color        defaultCol    = System.Drawing.Color.Transparent;
            List <System.Drawing.Color> availableCols = new List <System.Drawing.Color>();

            if (!DA.GetData <object>(0, ref myUIElement))
            {
                return;
            }

            ColorPicker picker = HUI_Util.GetUIElement <ColorPicker>(myUIElement);


            //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;
                }
            }
        }
Exemplo n.º 20
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;
            }
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            object  o                 = null;
            bool    showViewCube      = true;
            bool    allowPan          = true;
            bool    allowZoom         = true;
            bool    allowMove         = true;
            bool    allowRotation     = true;
            bool    isParallel        = true;
            Point3d camLoc            = Point3d.Unset;
            Point3d camTarget         = Point3d.Unset;
            double  camTransitionTime = 0;


            if (!DA.GetData <object>("3D View", ref o))
            {
                return;
            }
            var hasShowViewCube      = DA.GetData("Show View Cube", ref showViewCube);
            var hasAllowPan          = DA.GetData("Allow Pan", ref allowPan);
            var hasAllowZoom         = DA.GetData("Allow Zoom", ref allowZoom);
            var hasAllowMove         = DA.GetData("Allow Move", ref allowMove);
            var hasAllowRotation     = DA.GetData("Allow Rotation", ref allowRotation);
            var hasIsParallel        = DA.GetData("Perspective/Parallel", ref isParallel);
            var hasCamLoc            = DA.GetData("Camera Location", ref camLoc);
            var hasCamTarget         = DA.GetData("Camera Target", ref camTarget);
            var hasCamTransitionTime = DA.GetData("Camera Transition Time", ref camTransitionTime);


            HelixViewport3D vp3 = HUI_Util.GetUIElement <HelixViewport3D>(o);

            if (hasShowViewCube)
            {
                vp3.ShowViewCube = showViewCube;
            }
            if (hasAllowPan)
            {
                vp3.IsPanEnabled = allowPan;
            }
            if (hasAllowZoom)
            {
                vp3.IsZoomEnabled = allowZoom;
            }
            if (hasAllowMove)
            {
                vp3.IsMoveEnabled = allowMove;
            }
            if (hasAllowRotation)
            {
                vp3.IsRotationEnabled = allowRotation;
            }
            if (hasIsParallel)
            {
                vp3.Orthographic = isParallel;
            }
            if (hasCamLoc && hasCamTarget)
            {
                var lookDir = camTarget - camLoc;
                vp3.SetView(new Point3D(camLoc.X, camLoc.Y, camLoc.Z), new Vector3D(lookDir.X, lookDir.Y, lookDir.Z), new Vector3D(0, 0, 1), hasCamTransitionTime ? camTransitionTime : 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   absolute   = false;
            object elem       = null;
            string margin     = "0";
            double width      = 0;
            double height     = 0;
            int    horizAlign = 0;
            int    vertAlign  = 0;

            if (!DA.GetData <object>("Elements to adjust", ref elem))
            {
                return;
            }

            DA.GetData <bool>("Absolute Positioning", ref absolute);

            //This is the element we are adjusting
            FrameworkElement f = HUI_Util.GetUIElement <FrameworkElement>(elem);

            //if user has supplied margin, set margin
            if (DA.GetData <string>("Margin", ref margin))
            {
                f.Margin = thicknessFromString(margin);
            }

            //get the window the element belongs to
            MainWindow m = Window.GetWindow(f) as MainWindow;

            //if user specified width and/or height, set them
            if (DA.GetData <double>("Width", ref width))
            {
                f.Width = width;
            }
            if (DA.GetData <double>("Height", ref height))
            {
                f.Height = height;
            }

            //if user specified vertical and/or horizontal alignment, set it
            if (DA.GetData <int>("Vertical Alignment", ref vertAlign))
            {
                VerticalAlignment alignment = f.VerticalAlignment;
                switch (vertAlign)
                {
                case 0:
                    alignment = VerticalAlignment.Bottom;
                    break;

                case 1:
                    alignment = VerticalAlignment.Center;
                    break;

                case 2:
                    alignment = VerticalAlignment.Top;
                    break;

                case 3:
                    alignment = VerticalAlignment.Stretch;
                    break;

                default:
                    break;
                }
                f.VerticalAlignment = alignment;
            }
            if (DA.GetData <int>("Horizontal Alignment", ref horizAlign))
            {
                HorizontalAlignment alignment = f.HorizontalAlignment;
                switch (horizAlign)
                {
                case 0:
                    alignment = HorizontalAlignment.Left;
                    break;

                case 1:
                    alignment = HorizontalAlignment.Center;
                    break;

                case 2:
                    alignment = HorizontalAlignment.Right;
                    break;

                case 3:
                    alignment = HorizontalAlignment.Stretch;
                    break;

                default:
                    break;
                }
                f.HorizontalAlignment = alignment;
            }

            // The absolute positioning setting is essentially just placing the items as the child of the window Grid, which is the parent of the Master Stack
            // Panel everything usually sits in.
            if (absolute)
            {
                try
                {
                    m.MoveFromStackToGrid(f);
                }
                catch
                {
                }
            }
            else
            {
                try
                {
                    m.MoveFromGridToStack(f);
                }
                catch { }
            }
        }
Exemplo n.º 23
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)
        {
            //placeholder variable to hold the generic element object
            object ShapeObject = null;


            if (!DA.GetData <object>("Shape to Modify", ref ShapeObject))
            {
                return;
            }

            //Get grid container out of generic object
            ClickableShapeGrid G         = HUI_Util.GetUIElement <ClickableShapeGrid>(ShapeObject);
            List <bool>        oldStates = new List <bool>(G.SelectedStates.ToArray());

            //change the shape
            if (G != null)
            {
                List <Curve> shapeCrvs = new List <Curve>();
                List <System.Drawing.Color> fillCol   = new List <System.Drawing.Color>();
                List <double> strokeWeights           = new List <double>();
                List <System.Drawing.Color> strokeCol = new List <System.Drawing.Color>();
                double scale   = 1.0;
                int    width   = 0;
                int    height  = 0;
                Path   oldpath = getPath(G.Children);


                bool hasWeight    = false;
                bool hasStrokeCol = false;
                bool hasFill      = false;

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

                //Populate variables and store boolean results for later use.
                hasFill      = DA.GetDataList <System.Drawing.Color>("Fill Colors", fillCol);
                hasWeight    = DA.GetDataList <double>("Stroke Weights", strokeWeights);
                hasStrokeCol = DA.GetDataList <System.Drawing.Color>("Stroke Colors", strokeCol);

                //If the user has specified new shapes:
                if (DA.GetDataList <Curve>("Shape Curves", shapeCrvs))
                {
                    //G.Children.Clear();

                    //remove all shape children
                    var itemsToRemove = G.Children.OfType <FrameworkElement>()
                                        .Where(c => (c is Shape)).ToList();

                    itemsToRemove
                    .ForEach(g => G.Children.Remove(g));

                    int i = 0;
                    //for all the curves
                    foreach (Curve c in shapeCrvs)
                    {
                        Path         path    = new Path();
                        List <Curve> crvList = new List <Curve>();
                        //We're passing a single curve as a list so that the multiple curves are not interpreted as "composite" -
                        //and therefore would be unable to be styled separately.
                        crvList.Add(c);

                        // Get Geometry from rhino curve objects. Note that "rebase" is set to false - so that relative position of
                        // multiple curves is preserved. This is the primary difference with the setShape component (as well as list access)
                        path.Data = Components.UI_Elements.CreateShape_Component.pathGeomFromCrvs(crvList, scale, false);
                        if (hasFill)
                        {
                            path.Fill = new SolidColorBrush(HUI_Util.ToMediaColor(fillCol[i % fillCol.Count])); //hacky fix to approximate longest list matching
                        }
                        else
                        {
                            path.Fill = oldpath.Fill;
                        }

                        if (hasWeight)
                        {
                            path.StrokeThickness = strokeWeights[i % strokeWeights.Count]; //hacky fix to approximate longest list matching
                        }
                        else
                        {
                            path.StrokeThickness = oldpath.StrokeThickness;
                        }
                        if (hasStrokeCol)
                        {
                            path.Stroke = new SolidColorBrush(HUI_Util.ToMediaColor(strokeCol[i % strokeCol.Count])); //hacky fix to approximate longest list matching
                        }
                        else
                        {
                            path.Stroke = oldpath.Stroke;
                        }

                        i++;
                        //Add the new path to the Grid
                        G.Children.Add(path);
                    }
                }



                //If the user has specified new dimensions for the container, update its dimensions, otherwise use the old ones.
                if (DA.GetData <int>("Width", ref width))
                {
                    G.Width = width;
                }
                else
                {
                    G.Width = oldpath.Width;
                }
                if (DA.GetData <int>("Height", ref height))
                {
                    G.Height = height;
                }
                else
                {
                    G.Height = oldpath.Height;
                }
            }

            if (G.Children.Count == oldStates.Count && G.clickMode == ClickableShapeGrid.ClickMode.ToggleMode)
            {
                G.SelectedStates = oldStates;
                G.UpdateAppearance();
            }
        }
Exemplo 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 ShapeObject = null;

            if (!DA.GetData <object>("Shape to Modify", ref ShapeObject))
            {
                return;
            }
            Grid G = HUI_Util.GetUIElement <Grid>(ShapeObject);

            //change the shape
            if (G != null)
            {
                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;

                //Extract the path from the container grid
                Path path = getPath(G.Children);
                //save the old path
                Path oldpath = path;
                //if the user has supplied new shapes
                if (DA.GetDataList <Curve>("Shape Curve", shapeCrvs))
                {
                    Path newPath = new Path();
                    DA.GetData <double>("Scale", ref scale);
                    //use the method from the orig. component to translate curves into Geometry
                    newPath.Data = Components.UI_Elements.CreateShape_Component.pathGeomFromCrvs(shapeCrvs, scale, true);
                    //remove old path from Grid
                    G.Children.Remove(path);

                    path = newPath;
                    G.Children.Add(path);
                }
                //if the user specified a new fill color
                if (DA.GetData <System.Drawing.Color>("Fill Color", ref fillCol))
                {
                    //set fill
                    path.Fill = new SolidColorBrush(HUI_Util.ToMediaColor(fillCol));
                }
                else
                {
                    //otherwise use the old fill color
                    path.Fill = oldpath.Fill;
                }
                //if user supplied stroke weight
                if (DA.GetData <double>("Stroke Weight", ref strokeWeight))
                {
                    //set the stroke weight
                    path.StrokeThickness = strokeWeight;
                }
                else
                {
                    //otherwise use the old stroke weight
                    path.StrokeThickness = oldpath.StrokeThickness;
                }
                //if the user specified a stroke color
                if (DA.GetData <System.Drawing.Color>("Stroke Color", ref strokeCol))
                {
                    //set the stroke color
                    path.Stroke = new SolidColorBrush(HUI_Util.ToMediaColor(strokeCol));
                }
                else
                {
                    //otherwise use the old stroke color
                    path.Stroke = oldpath.Stroke;
                }

                //if the user specified a new object width
                if (DA.GetData <int>("Width", ref width))
                {
                    //set the grid width
                    G.Width = width;
                }
                else
                {
                    //otherwise use the old grid width
                    G.Width = oldpath.Width;
                }
                //if the user specified a new height
                if (DA.GetData <int>("Height", ref height))
                {
                    //set the height
                    G.Height = height;
                }
                else
                {
                    //otherwise use the old height
                    G.Height = oldpath.Height;
                }
            }
        }
Exemplo 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)
        {
            object        o                  = null;
            List <Mesh>   m                  = new List <Mesh>();
            List <string> texBitmap          = new List <string>();
            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);

            bool hasTexture = DA.GetDataList <string>("Mesh Texture", texBitmap);
            bool hasColor   = DA.GetDataList <System.Drawing.Color>("Mesh Colors", cols);


            HelixViewport3D      vp3  = HUI_Util.GetUIElement <HelixViewport3D>(o);
            ModelVisual3D        mv3  = GetModelVisual3D(vp3);
            List <ModelVisual3D> mv3s = GetModels(vp3);
            List <Material>      mats = new List <Material>();


            //empty out the helixviewport
            vp3.Children.Clear();
            vp3.Children.Add(new SunLight());

            if (!hasColor && !hasTexture) //if user has not specified either color or texture
            {
                //for all the models
                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;
                            //extract the current material settings
                            mats.Add(geom.Material);
                        }
                    }
                }
                //pass in the new mesh with the existing materials
                mv3.Content = new _3DViewModel(m, mats).Model;
            }
            else if (!hasTexture)
            {
                //pass in the new mesh with new colors
                mv3.Content = new _3DViewModel(m, cols).Model;
            }
            else
            {
                //pass in the new mesh with new textures
                mv3.Content = new _3DViewModel(m, texBitmap).Model;
            }



            //add the model back into the viewport
            vp3.Children.Add(mv3);
        }
Exemplo 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        ChartObject  = null;
            List <double> listContents = new List <double>();
            List <string> names        = new List <string>();
            string        Title        = null;
            string        SubTitle     = null;

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


            //set new title and subtitle or get old ones
            if (DA.GetData <string>("Title", ref Title))
            {
                ChartElem.ChartTitleVisibility = System.Windows.Visibility.Visible;
                ChartElem.ChartTitle           = Title;
            }
            if (DA.GetData <string>("SubTitle", ref SubTitle))
            {
                ChartElem.ChartSubTitle = SubTitle;
            }

            chartModel = ChartElem.DataContext as SeriesModel;

            if (chartModel == null)
            {
                chartModel = new SeriesModel();
            }

            bool valuesSupplied = DA.GetDataList <double>("New Chart Values", listContents);

            bool namesSupplied = DA.GetDataList <string>("New Chart Names", names);


            //make sure there are the same number of names and values
            if (valuesSupplied && namesSupplied && (names.Count != listContents.Count))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Different number of names and values supplied.");
                return;
            }


            //if the data isnt supplied modify it
            if (valuesSupplied)
            {
                //replace the ones already in there
                for (int i = 0; i < chartModel.Chart.Count; i++)
                {
                    if (listContents.Count > i)
                    {
                        chartModel.Chart[i].Number = (float)listContents[i];
                    }
                }
                //add any on the end
                if (listContents.Count > chartModel.Chart.Count)
                {
                    for (int i = chartModel.Chart.Count; i < listContents.Count; i++)
                    {
                        chartModel.Chart.Add(new ChartItem()
                        {
                            Number = (float)listContents[i], Category = "UNSET"
                        });
                    }
                }

                //subtract any off the end
                if (listContents.Count < chartModel.Chart.Count)
                {
                    for (int i = chartModel.Chart.Count - 1; i >= listContents.Count; i--)
                    {
                        chartModel.Chart.RemoveAt(i);
                    }
                }
            }

            //check if the names array is different. We don't want to fire a full update unless we absolutely have to.

            bool hasChanged = false;

            var alreadyNames = chartModel.Chart.Select(item => item.Category).ToArray();

            //if the length of names is different, we know it's changed
            if (alreadyNames.Length != names.Count())
            {
                hasChanged = true;
            }
            else //if the length is the same, check each item
            {
                for (int i = 0; i < alreadyNames.Count(); i++)
                {
                    if (alreadyNames[i] != names[i])
                    {
                        hasChanged = true;
                        break;
                    }
                }
            }



            //if the data is supplied and different than what's in the chart, modify it
            if (namesSupplied && hasChanged)
            {
                //replace the ones already in there
                for (int i = 0; i < chartModel.Chart.Count; i++)
                {
                    if (names.Count > i)
                    {
                        chartModel.Chart[i].Category = names[i];
                    }
                }
                //add any on the end
                if (names.Count > chartModel.Chart.Count)
                {
                    for (int i = chartModel.Chart.Count; i < names.Count; i++)
                    {
                        chartModel.Chart.Add(new ChartItem()
                        {
                            Category = names[i], Number = float.NaN
                        });
                    }
                }

                //subtract any off the end
                if (names.Count < chartModel.Chart.Count)
                {
                    for (int i = chartModel.Chart.Count - 1; i >= names.Count; i--)
                    {
                        chartModel.Chart.RemoveAt(i);
                    }
                }

                //refresh display - the binding works when the values change but not when categories do.
                var Values = chartModel.Chart.ToArray();

                chartModel.Chart.Clear();

                foreach (var item in Values)
                {
                    chartModel.Chart.Add(item);
                }
            }
        }
Exemplo 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 dataTableObj = null;

            if (!DA.GetData <object>(0, ref dataTableObj))
            {
                return;
            }
            GH_Structure <GH_String> data;
            List <string>            columnHeadings = new List <string>();

            bool hasData           = DA.GetDataTree("Data", out data);
            bool hasColumnHeadings = DA.GetDataList("Column Headings", columnHeadings);


            DataGrid dg = HUI_Util.GetUIElement <DataGrid>(dataTableObj);


            List <List <string> > dataToConvert = new List <List <string> >();

            //check for rectangular data:



            for (int i = 0; i < data.Branches.Count; i++)
            {
                for (int j = 0; j < data.Branches[i].Count; j++)
                {
                    try
                    {
                        dataToConvert[j].Add(data.Branches[i][j].Value);
                    }
                    catch
                    {
                        dataToConvert.Add(new List <string>());
                        dataToConvert[j].Add(data.Branches[i][j].Value);
                    }
                }
            }
            if (!hasColumnHeadings)
            {
                DataView      v        = dg.ItemsSource as DataView;
                List <string> headings = new List <string>();
                foreach (DataColumn col in v[0].Row.Table.Columns)
                {
                    if (col.ColumnName != "HUI_Index")
                    {
                        headings.Add(col.ColumnName);
                    }
                }
                columnHeadings = headings;
            }
            if (columnHeadings.Count != data.Branches.Count)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Column Heading Count doesn't match the data");
                return;
            }
            if (columnHeadings.Distinct().Count() != columnHeadings.Count)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Column headings must be unique.");
                return;
            }

            DataTable dt = CreateDataTable_Component.ConvertListToDataTable(dataToConvert, columnHeadings);


            dg.ItemsSource = dt.AsDataView();
        }
Exemplo 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)
        {
            object ChartObject = null;
            GH_Structure <GH_Number> NewValueTree = new GH_Structure <GH_Number>();
            List <string>            names        = new List <string>();
            string        Title        = "";
            string        SubTitle     = "";
            List <string> Clustertitle = new List <string>();

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


            //set new title and subtitle or get old ones
            if (DA.GetData <string>("Title", ref Title))
            {
                ChartElem.ChartTitleVisibility = System.Windows.Visibility.Visible;
                ChartElem.ChartTitle           = Title;
            }
            if (DA.GetData <string>("SubTitle", ref SubTitle))
            {
                ChartElem.ChartSubTitle = SubTitle;
            }

            bool ClusterTitleSupplied = DA.GetDataList <string>("ClusterTitle", Clustertitle);

            bool valuesSupplied = DA.GetDataTree <GH_Number>("New Chart Values", out NewValueTree);

            bool namesSupplied = DA.GetDataList <string>("New Chart Names", names);


            //   MultiChartModel mcm = ChartElem.DataContext as MultiChartModel;

            //check if the cluster titles have changed to avoid unnecessary full redraws.
            bool clusterTitleChanged = false;

            if (ClusterTitleSupplied)
            {
                var alreadyClusterTitles = ChartElem.Series.Select(s => s.SeriesTitle).ToArray();
                if (Clustertitle.Count() != alreadyClusterTitles.Length)
                {
                    clusterTitleChanged = true;
                }
                else
                {
                    for (int i = 0; i < alreadyClusterTitles.Length; i++)
                    {
                        if (alreadyClusterTitles[i] != Clustertitle[i])
                        {
                            clusterTitleChanged = true;
                            break;
                        }
                    }
                }
            }


            //check if the names array is different. We don't want to fire a full update unless we absolutely have to.
            bool haveNamesChanged = false;
            var  firstModel       = ChartElem.Series[0].DataContext as SeriesModel;
            var  alreadyNames     = firstModel.Chart.Select(item => item.Category).ToArray();

            if (namesSupplied)
            {
                //if the length of names is different, we know it's changed
                if (alreadyNames.Length != names.Count())
                {
                    haveNamesChanged = true;
                }
                else //if the length is the same, check each item
                {
                    for (int i = 0; i < alreadyNames.Count(); i++)
                    {
                        if (alreadyNames[i] != names[i])
                        {
                            haveNamesChanged = true;
                            break;
                        }
                    }
                }
            }
            else
            {
                names = alreadyNames.ToList();
            }

            bool removedCharts = false;

            //Remove extra data
            if (NewValueTree.Branches.Count < ChartElem.Series.Count())
            {
                removedCharts = true;
                for (int k = ChartElem.Series.Count() - 1; k >= NewValueTree.Branches.Count; k--)
                {
                    ChartElem.Series.RemoveAt(k);
                }
            }

            bool addedCharts = false;


            for (int j = 0; j < NewValueTree.Branches.Count; j++)
            {
                List <Double> valueList = NewValueTree.Branches[j].Select(n => n.Value).ToList();

                //modify existing series
                if (ChartElem.Series.Count > j)
                {
                    var ChartSeries = ChartElem.Series[j];
                    var model       = ChartSeries.DataContext as SeriesModel;

                    if (ClusterTitleSupplied)
                    {
                        ChartSeries.SeriesTitle = Clustertitle[j];
                    }


                    //make sure there are the same number of names and values
                    if (valuesSupplied && namesSupplied && (names.Count != valueList.Count))
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Different number of names and values supplied.");
                        return;
                    }

                    //if the data isnt supplied modify it
                    if (valuesSupplied)
                    {
                        //replace the ones already in there
                        for (int i = 0; i < model.Chart.Count; i++)
                        {
                            if (valueList.Count > i)
                            {
                                model.Chart[i].Number = (float)valueList[i];
                            }
                        }
                        //add any on the end
                        if (valueList.Count > model.Chart.Count)
                        {
                            for (int i = model.Chart.Count; i < valueList.Count; i++)
                            {
                                model.Chart.Add(new ChartItem()
                                {
                                    Number = (float)valueList[i], Category = "UNSET"
                                });
                            }
                        }

                        //subtract any off the end
                        if (valueList.Count < model.Chart.Count)
                        {
                            for (int i = model.Chart.Count - 1; i >= valueList.Count; i--)
                            {
                                model.Chart.RemoveAt(i);
                            }
                        }
                    }


                    //if the data is supplied and different than what's in the chart, modify it
                    if (namesSupplied && haveNamesChanged)
                    {
                        //replace the ones already in there
                        for (int i = 0; i < model.Chart.Count; i++)
                        {
                            if (names.Count > i)
                            {
                                model.Chart[i].Category = names[i];
                            }
                        }
                        //add any on the end
                        if (names.Count > model.Chart.Count)
                        {
                            for (int i = model.Chart.Count; i < names.Count; i++)
                            {
                                model.Chart.Add(new ChartItem()
                                {
                                    Category = names[i], Number = float.NaN
                                });
                            }
                        }

                        //subtract any off the end
                        if (names.Count < model.Chart.Count)
                        {
                            for (int i = model.Chart.Count - 1; i >= names.Count; i--)
                            {
                                model.Chart.RemoveAt(i);
                            }
                        }
                    }
                    if (haveNamesChanged || clusterTitleChanged)
                    {
                        //refresh display - the binding works when the values change but not when categories do.
                        var Values = model.Chart.ToArray();

                        model.Chart.Clear();

                        foreach (var item in Values)
                        {
                            model.Chart.Add(item);
                        }
                    }
                }
                else
                {
                    addedCharts = true;
                    //Add new series
                    SeriesModel vm = new SeriesModel(names.ToList(), valueList);



                    ChartSeries series = new ChartSeries();
                    //We have to set the series data context rather than the whole chart
                    series.DataContext = vm;

                    series.SeriesTitle   = Clustertitle[j];
                    series.DisplayMember = "Category";
                    series.ValueMember   = "Number";

                    Binding seriesBinding = new Binding();
                    seriesBinding.Source = vm;
                    seriesBinding.Path   = new PropertyPath("Chart");
                    BindingOperations.SetBinding(series, ChartSeries.ItemsSourceProperty, seriesBinding);

                    ChartElem.Series.Add(series);
                }
            }



            if (addedCharts || removedCharts)
            {
                var oldSeries = ChartElem.Series;
                ChartElem.SeriesSource = null;
                //  ChartElem.Series.Clear();
                ChartElem.SeriesSource = oldSeries;
            }
        }
        /// <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?fgCol = null;
            System.Drawing.Color?bgCol = null;
            double fontSize            = -1;
            object elem = null;

            if (!DA.GetData("Elements to Adjust", ref elem))
            {
                return;
            }

            var hasfgCol    = DA.GetData("Foreground", ref fgCol);
            var hasbgCol    = DA.GetData("Background", ref bgCol);
            var hasFontSize = DA.GetData("Font Size", ref fontSize);


            //Get the "FrameworkElement" (basic UI element) from an object
            FrameworkElement f        = HUI_Util.GetUIElement <FrameworkElement>(elem);
            Selector         selector = f as Selector;
            ScrollViewer     sv       = f as ScrollViewer;
            ChartBase        cb       = f as ChartBase;


            if (f is Expander exp)
            {
                if (hasfgCol)
                {
                    exp.Foreground = new SolidColorBrush(HUI_Util.ToMediaColor(fgCol.Value));
                }
                if (hasbgCol)
                {
                    exp.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol.Value));
                }
                if (!hasFontSize)
                {
                    return;
                }
                var       header   = exp.Header;
                TextBlock myHeader = null;
                if (header is string headString)
                {
                    myHeader      = new TextBlock();
                    myHeader.Text = headString;
                }
                else
                {
                    myHeader = exp.Header as TextBlock;
                }
                myHeader.FontSize = fontSize;
                exp.Header        = myHeader;
                return;
            }


            // var ChartElem = HUI_Util.GetUIElement<ChartBase>(ChartObject);
            if (f is Grid g)
            {
                foreach (UIElement child in g.Children)
                {
                    ColorTextElement(child, fgCol, bgCol, fontSize);
                }
                if (hasbgCol)
                {
                    g.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol.Value));
                }
            }

            //if it's a panel color its children
            if (f is Panel panel)
            {
                foreach (UIElement child in panel.Children)
                {
                    ColorTextElement(child, fgCol, bgCol, fontSize);
                }
                if (hasbgCol)
                {
                    panel.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol.Value));
                }
            }

            if (f is TabControl tabControl)
            {
                if (hasbgCol)
                {
                    tabControl.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol.Value));
                }
            }

            //if it's a selector, color its items
            else if (selector != null)
            {
                foreach (UIElement child in selector.Items)
                {
                    ColorTextElement(child, fgCol, bgCol, fontSize);
                }
            }

            //if it's an itemscontrol, color its items
            else if (sv != null)
            {
                if (sv.Content is ItemsControl ic)
                {
                    foreach (var item in ic.Items)
                    {
                        if (item is UIElement uie)
                        {
                            ColorTextElement(uie, fgCol, bgCol, fontSize);
                        }
                    }
                }
            }

            //otherwise assume it's just a root level element
            else
            {
                ColorTextElement(f, fgCol, bgCol, fontSize);
            }
        }
Exemplo n.º 30
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 fgCol = System.Drawing.Color.Transparent;
            System.Drawing.Color bgCol = System.Drawing.Color.Transparent;
            double fontSize            = -1;
            object elem = null;

            if (!DA.GetData <object>("Elements to Adjust", ref elem))
            {
                return;
            }

            var hasfgCol    = DA.GetData <System.Drawing.Color>("Foreground", ref fgCol);
            var hasbgCol    = DA.GetData <System.Drawing.Color>("Background", ref bgCol);
            var hasFontSize = DA.GetData <double>("Font Size", ref fontSize);


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

            //try a few casts to see if it's a container
            Grid         g        = f as Grid;
            Panel        panel    = f as Panel;
            Selector     selector = f as Selector;
            ScrollViewer sv       = f as ScrollViewer;
            ChartBase    cb       = f as ChartBase;
            Expander     exp      = f as Expander;


            if (exp != null)
            {
                if (hasfgCol)
                {
                    exp.Foreground = new SolidColorBrush(HUI_Util.ToMediaColor(fgCol));
                }
                if (hasbgCol)
                {
                    exp.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol));
                }
                if (!hasFontSize)
                {
                    return;
                }
                var       header   = exp.Header;
                TextBlock myHeader = null;
                if (header is string)
                {
                    myHeader      = new TextBlock();
                    myHeader.Text = header as string;
                }
                else
                {
                    myHeader = exp.Header as TextBlock;
                }
                myHeader.FontSize = fontSize;
                exp.Header        = myHeader;
                return;
            }

            // var ChartElem = HUI_Util.GetUIElement<ChartBase>(ChartObject);
            if (g != null)
            {
                foreach (UIElement child in g.Children)
                {
                    ColorTextElement(child, fgCol, bgCol, fontSize);
                }
                g.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol));
            }



            //if it's a panel color its children
            if (panel != null)
            {
                foreach (UIElement child in panel.Children)
                {
                    ColorTextElement(child, fgCol, bgCol, fontSize);
                }
                panel.Background = new SolidColorBrush(HUI_Util.ToMediaColor(bgCol));
            }
            //if it's a selector, color its items
            else if (selector != null)
            {
                foreach (UIElement child in selector.Items)
                {
                    ColorTextElement(child, fgCol, bgCol, fontSize);
                }
            }
            //if it's an itemscontrol, color its items
            else if (sv != null)
            {
                ItemsControl ic = sv.Content as ItemsControl;
                if (ic != null)
                {
                    foreach (var item in ic.Items)
                    {
                        UIElement uie = item as UIElement;
                        if (uie != null)
                        {
                            ColorTextElement(uie, fgCol, bgCol, fontSize);
                        }
                    }
                }
            }
            else //otherwise assume it's just a root level element
            {
                ColorTextElement(f, fgCol, bgCol, fontSize);
            }
        }