private DynamicLayout GenLoadsPanel(bool lockedMode)
        {
            var layout = new DynamicLayout()
            {
                Height = 500
            };


            //layout.DefaultPadding = new Padding(4);
            layout.BeginScrollable(BorderType.None);

            var container = new DynamicLayout()
            {
                Enabled = !lockedMode
            };

            container.DefaultSpacing = new Size(4, 4);

            //Get lighting
            container.AddRow(GenLightingPanel());

            //Get People
            container.AddRow(GenPplPanel());

            //Get ElecEquipment
            container.AddRow(GenElecEqpPanel());


            //Get gas Equipment
            container.AddRow(GenGasEqpPanel());

            //Get Ventilation
            container.AddRow(GenVentPanel());

            //Get Infiltration
            container.AddRow(GenInfPanel());

            //Get Setpoint
            container.AddRow(GenStpPanel());

            //Get ServiceHotWater
            container.AddRow(GenSHWPanel());


            layout.AddRow(container);
            layout.AddRow(null);

            layout.EndScrollable();
            return(layout);
        }
Example #2
0
        //private ModelEnergyProperties ModelEnergyProperties { get; set; }
        public Dialog_OpsHVACs(ref HoneybeeSchema.ModelEnergyProperties libSource, HoneybeeSchema.Energy.IHvac hvac = default, bool lockedMode = false)
        {
            this.Padding = new Padding(10);
            Title        = $"From OpenStudio HVAC library - {DialogHelper.PluginName}";
            WindowStyle  = WindowStyle.Default;
            Width        = 450;
            this.Icon    = DialogHelper.HoneybeeIcon;

            if (hvac == null) // add a new system
            {
                _vm = new OpsHVACsViewModel(libSource, this);
            }
            else  // edit existing system
            {
                _vm = new OpsHVACsViewModel(libSource, hvac, this);
            }

            var layout = new DynamicLayout()
            {
                DataContext = _vm
            };

            layout.DefaultSpacing = new Size(5, 5);
            layout.DefaultPadding = new Padding(5);


            // add a new system from lib
            if (hvac == null)
            {
                // UI for system groups
                var hvacGroups     = new DropDown();
                var hvacTypes      = new DropDown();
                var hvacEquipments = new DropDown();

                hvacGroups.BindDataContext(c => c.DataStore, (OpsHVACsViewModel m) => m.HvacGroups);
                hvacGroups.SelectedKeyBinding.BindDataContext((OpsHVACsViewModel m) => m.HvacGroup);

                hvacTypes.BindDataContext(c => c.DataStore, (OpsHVACsViewModel m) => m.HvacTypes);
                hvacTypes.ItemTextBinding = Binding.Delegate <Type, string>(t => _vm.HVACTypesDic[t]);
                hvacTypes.SelectedValueBinding.BindDataContext((OpsHVACsViewModel m) => m.HvacType);

                hvacEquipments.BindDataContext(c => c.DataStore, (OpsHVACsViewModel m) => m.HvacEquipmentTypes);
                hvacEquipments.ItemTextBinding = Binding.Delegate <string, string>(t => _vm.HVACsDic[t]);
                hvacEquipments.SelectedKeyBinding.BindDataContext((OpsHVACsViewModel m) => m.HvacEquipmentType);

                layout.AddRow("HVAC Groups:");
                layout.AddRow(hvacGroups);
                layout.AddRow("HVAC Types:");
                layout.AddRow(hvacTypes);
                layout.AddRow("HVAC Equipment Types:");
                layout.AddRow(hvacEquipments);
                layout.AddRow(null);
            }



            var year       = new DropDown();
            var nameText   = new TextBox();
            var economizer = new DropDown();
            var sensible   = new NumericStepper()
            {
                MinValue = 0, MaxValue = 1, MaximumDecimalPlaces = 2, Increment = 0.1
            };
            var latent = new NumericStepper()
            {
                MinValue = 0, MaxValue = 1, MaximumDecimalPlaces = 2, Increment = 0.1
            };


            nameText.TextBinding.BindDataContext((OpsHVACsViewModel m) => m.Name);

            year.BindDataContext(c => c.DataStore, (OpsHVACsViewModel m) => m.Vintages);
            year.SelectedKeyBinding.BindDataContext((OpsHVACsViewModel m) => m.Vintage);

            var economizerTitle = new Label()
            {
                Text = "Economizer:"
            };

            economizer.BindDataContext(c => c.DataStore, (OpsHVACsViewModel m) => m.Economizers);
            economizer.SelectedKeyBinding.BindDataContext((OpsHVACsViewModel m) => m.Economizer);
            economizer.BindDataContext(c => c.Enabled, (OpsHVACsViewModel m) => m.EconomizerVisable);
            economizer.BindDataContext(c => c.Visible, (OpsHVACsViewModel m) => m.EconomizerVisable);
            economizerTitle.BindDataContext(c => c.Visible, (OpsHVACsViewModel m) => m.EconomizerVisable);

            var sensibleTitle = new Label()
            {
                Text = "Sensible Heat Recovery:"
            };

            sensible.BindDataContext(c => c.Value, (OpsHVACsViewModel m) => m.SensibleHR);
            sensible.BindDataContext(c => c.Visible, (OpsHVACsViewModel m) => m.SensibleHRVisable);
            sensibleTitle.BindDataContext(c => c.Visible, (OpsHVACsViewModel m) => m.SensibleHRVisable);


            var latentTitle = new Label()
            {
                Text = "Latent Heat Recovery:"
            };

            latent.BindDataContext(c => c.Value, (OpsHVACsViewModel m) => m.LatentHR);
            latent.BindDataContext(c => c.Visible, (OpsHVACsViewModel m) => m.LatentHRVisable);
            latentTitle.BindDataContext(c => c.Visible, (OpsHVACsViewModel m) => m.LatentHRVisable);

            var dcv = new CheckBox()
            {
                Text = "Demand Control Ventilation"
            };

            dcv.Bind(_ => _.Checked, _vm, _ => _.DcvChecked);
            dcv.Bind(c => c.Visible, _vm, _ => _.DcvVisable);

            var availabilityTitle = new Label()
            {
                Text = "DOAS Availability Schedule:"
            };

            availabilityTitle.Bind(c => c.Visible, _vm, _ => _.AvaliabilityVisable);
            var availability = new OptionalButton();

            availability.Bind(c => c.Visible, _vm, _ => _.AvaliabilityVisable);
            availability.TextBinding.Bind(_vm, _ => _.AvaliabilitySchedule.BtnName);
            availability.Bind(_ => _.Command, _vm, _ => _.AvaliabilityCommand);
            availability.Bind(_ => _.RemoveCommand, _vm, _ => _.RemoveAvaliabilityCommand);
            availability.Bind(_ => _.IsRemoveVisable, _vm, _ => _.AvaliabilitySchedule.IsRemoveVisable);

            var radSettings = GenRadSettingsPanel();

            var gp = new GroupBox()
            {
                Text = "HVAC System settings"
            };
            var gpLayout = new DynamicLayout();

            gpLayout.DefaultPadding = new Padding(5);

            // fix the height of layout in case of creating a new system, otherwise, autosize height
            if (hvac == null)
            {
                gpLayout.Height = 250;
                gpLayout.BeginScrollable(BorderType.None);
            }

            var gpGeneralLayout = new DynamicLayout();

            //gpLayout.BeginGroup("HVAC System settings", new Padding(5), new Size(5, 0));
            gpGeneralLayout.Spacing = new Size(5, 2);


            gpGeneralLayout.AddRow("Name:");
            gpGeneralLayout.AddRow(nameText);
            gpGeneralLayout.AddRow("Vintage:");
            gpGeneralLayout.AddRow(year);
            gpGeneralLayout.AddRow(economizerTitle);
            gpGeneralLayout.AddRow(economizer);
            gpGeneralLayout.AddRow(sensibleTitle);
            gpGeneralLayout.AddRow(sensible);
            gpGeneralLayout.AddRow(latentTitle);
            gpGeneralLayout.AddRow(latent);

            gpGeneralLayout.AddRow(availabilityTitle);
            gpGeneralLayout.AddRow(availability);
            gpGeneralLayout.AddRow(dcv);

            gpLayout.AddRow(gpGeneralLayout);
            gpLayout.AddRow(radSettings);
            //gpLayout.EndGroup();
            gp.Content = gpLayout;

            layout.AddRow(gp);

            var locked = new CheckBox()
            {
                Text = "Locked", Enabled = false
            };

            locked.Checked = lockedMode;

            var OKButton = new Button {
                Text = "OK", Enabled = !lockedMode
            };

            OKButton.Click += (sender, e) =>
            {
                var obj = _vm.GreateHvac(hvac);
                OkCommand.Execute(obj);
            };

            AbortButton = new Button {
                Text = "Cancel"
            };
            AbortButton.Click += (sender, e) => Close();

            layout.AddSeparateRow(locked, null, OKButton, this.AbortButton, null, null);
            //layout.AddRow(null);
            Content = layout;
        }
Example #3
0
        private Panel GenParmPanel(HB.ModifierBase modifier)
        {
            var hbObj = modifier;

            var panel = new DynamicLayout();

            panel.DefaultSpacing = new Size(5, 5);
            panel.DefaultPadding = new Padding(5);

            var properties = hbObj.GetType().GetProperties().Where(_ => _.CanWrite);

            if (properties.Count() > 15)
            {
                panel.Height = 360;
                panel.BeginScrollable();
            }

            var name = new TextBox();

            hbObj.DisplayName = hbObj.DisplayName ?? hbObj.Identifier;
            name.TextBinding.Bind(() => hbObj.DisplayName, (v) => hbObj.DisplayName = v);

            panel.AddRow("Name", name);

            foreach (var item in properties)
            {
                if (item.Name == "Identifier" || item.Name == "Type" || item.Name == "DisplayName")
                {
                    continue;
                }

                var value = item.GetValue(hbObj);
                var type  = item.PropertyType;
                if (value is string stringvalue)
                {
                    var textBox = new TextBox();
                    //textBox.Text = stringvalue;
                    textBox.TextBinding.Bind(() => stringvalue, (v) => item.SetValue(hbObj, v));
                    panel.AddRow(item.Name, textBox);
                }
                else if (value is double numberValue)
                {
                    var numberTB = new MaskedTextBox();
                    numberTB.Provider = new NumericMaskedTextProvider()
                    {
                        AllowDecimal = true
                    };
                    numberTB.TextBinding.Bind(() => numberValue.ToString(), (v) => item.SetValue(hbObj, Convert.ChangeType(v, type)));
                    panel.AddRow(item.Name, numberTB);
                }
                else if (value is int intValue)
                {
                    var numberTB = new NumericStepper();
                    numberTB.DecimalPlaces = 0;
                    numberTB.Value         = intValue;
                    panel.AddRow(item.Name, numberTB);
                }
                else if (Nullable.GetUnderlyingType(type) != null)
                {
                    var enumType = Nullable.GetUnderlyingType(type);
                    if (!enumType.IsEnum)
                    {
                        continue;
                    }
                    var values        = Enum.GetNames(enumType).ToList();
                    var dropdown      = new DropDown();
                    var dropDownItems = values.Select(_ => new ListItem()
                    {
                        Text = _, Key = _
                    });
                    dropdown.Items.AddRange(dropDownItems);

                    var currentValue = item.GetValue(hbObj, null).ToString();
                    dropdown.SelectedKeyBinding.Bind(
                        () => currentValue,
                        (v) => item.SetValue(hbObj, Enum.Parse(enumType, v))
                        );

                    panel.AddRow(item.Name, dropdown);
                }
                else if (type.IsEnum)
                {
                    var values        = Enum.GetNames(type).ToList();
                    var dropdown      = new DropDown();
                    var dropDownItems = values.Select(_ => new ListItem()
                    {
                        Text = _, Key = _
                    });
                    dropdown.Items.AddRange(dropDownItems);

                    var currentValue = item.GetValue(hbObj, null).ToString();
                    dropdown.SelectedKeyBinding.Bind(
                        () => currentValue,
                        (v) => item.SetValue(hbObj, Enum.Parse(type, v))
                        );

                    panel.AddRow(item.Name, dropdown);
                }
            }
            panel.AddRow(null, null);
            return(panel);
        }
Example #4
0
        public DragDropSection()
        {
            // drag data object

            showDragOverEvents = new CheckBox {
                Text = "Show DragOver Events"
            };
            var includeImageCheck = new CheckBox {
                Text = "Include Image"
            };

            descriptionTextBox = new TextBox {
                PlaceholderText = "Format", ToolTip = "Add {0} to insert inner text into the description, e.g. 'Move to {0}'"
            };
            innerTextBox = new TextBox {
                PlaceholderText = "Inner", ToolTip = "Highlighted text to insert into description"
            };
            var textBox = new TextBox {
                Text = "Some text"
            };

            allowedEffectDropDown = new EnumDropDown <DragEffects> {
                SelectedValue = DragEffects.All
            };
            dragEnterEffect = new EnumDropDown <DragEffects?> {
                SelectedValue = DragEffects.Copy
            };
            dragOverEffect = new EnumDropDown <DragEffects?> {
                SelectedValue = null
            };
            writeDataCheckBox = new CheckBox {
                Text = "Write data to log"
            };
            useDragImage = new CheckBox {
                Text = "Use custom drag image"
            };
            imageOffset = new PointEntry {
                Value = new Point(80, 80)
            };
            imageOffset.Bind(c => c.Enabled, useDragImage, c => c.Checked);

            var htmlTextArea = new TextArea {
                Height = 24
            };
            var selectFilesButton = new Button {
                Text = "Select Files"
            };

            Uri[] fileUris = null;
            selectFilesButton.Click += (sender, e) =>
            {
                var ofd = new OpenFileDialog();
                ofd.MultiSelect = true;
                ofd.ShowDialog(this);
                fileUris = ofd.Filenames.Select(r => new Uri(r)).ToArray();
                if (fileUris.Length == 0)
                {
                    fileUris = null;
                }
            };

            var urlTextBox = new TextBox();

            DataObject CreateDataObject()
            {
                var data = new DataObject();

                if (!string.IsNullOrEmpty(textBox.Text))
                {
                    data.Text = textBox.Text;
                }
                var uris = new List <Uri>();

                if (fileUris != null)
                {
                    uris.AddRange(fileUris);
                }
                if (Uri.TryCreate(urlTextBox.Text, UriKind.Absolute, out var uri))
                {
                    uris.Add(uri);
                }
                if (uris.Count > 0)
                {
                    data.Uris = uris.ToArray();
                }
                if (!string.IsNullOrEmpty(htmlTextArea.Text))
                {
                    data.Html = htmlTextArea.Text;
                }
                if (includeImageCheck.Checked == true)
                {
                    data.Image = TestIcons.Logo;
                }

                return(data);
            }

            // sources

            var buttonSource = new Button {
                Text = "Source"
            };

            buttonSource.MouseDown += (sender, e) =>
            {
                if (e.Buttons != MouseButtons.None)
                {
                    DoDragDrop(buttonSource, CreateDataObject());
                    e.Handled = true;
                }
            };

            var panelSource = new Panel {
                BackgroundColor = Colors.Red, Size = new Size(50, 50)
            };

            panelSource.MouseMove += (sender, e) =>
            {
                if (e.Buttons != MouseButtons.None)
                {
                    DoDragDrop(panelSource, CreateDataObject());
                    e.Handled = true;
                }
            };

            var treeSource = new TreeGridView {
                Size = new Size(200, 200)
            };

            treeSource.SelectedItemsChanged += (sender, e) => Log.Write(treeSource, $"TreeGridView.SelectedItemsChanged (source) Rows: {string.Join(", ", treeSource.SelectedRows.Select(r => r.ToString()))}");
            treeSource.DataStore             = CreateTreeData();
            SetupTreeColumns(treeSource);
            treeSource.MouseMove += (sender, e) =>
            {
                if (e.Buttons == MouseButtons.Primary && !treeSource.IsEditing)
                {
                    var cell = treeSource.GetCellAt(e.Location);
                    if (cell.Item == null || cell.ColumnIndex == -1)
                    {
                        return;
                    }
                    var data     = CreateDataObject();
                    var selected = treeSource.SelectedItems.OfType <TreeGridItem>().Select(r => (string)r.Values[0]);
                    data.SetString(string.Join(";", selected), "my.tree.data");

                    DoDragDrop(treeSource, data);
                    e.Handled = true;
                }
            };

            var gridSource = new GridView {
            };

            gridSource.SelectedRowsChanged += (sender, e) => Log.Write(gridSource, $"GridView.SelectedItemsChanged (source): {string.Join(", ", gridSource.SelectedRows.Select(r => r.ToString()))}");
            SetupGridColumns(gridSource);
            gridSource.DataStore  = CreateGridData();
            gridSource.MouseMove += (sender, e) =>
            {
                if (e.Buttons == MouseButtons.Primary && !gridSource.IsEditing)
                {
                    var cell = gridSource.GetCellAt(e.Location);
                    if (cell.RowIndex == -1 || cell.ColumnIndex == -1)
                    {
                        return;
                    }
                    var data     = CreateDataObject();
                    var selected = gridSource.SelectedItems.OfType <GridItem>().Select(r => (string)r.Values[0]);
                    data.SetString(string.Join(";", selected), "my.grid.data");

                    DoDragDrop(gridSource, data);
                    e.Handled = true;
                }
            };


            // destinations

            var buttonDestination = new Button {
                Text = "Drop here!", AllowDrop = true
            };

            buttonDestination.DragEnter += (sender, e) => buttonDestination.Text = "Now, drop it!";
            buttonDestination.DragLeave += (sender, e) => buttonDestination.Text = "Drop here!";
            LogEvents(buttonDestination);

            var drawableDest = new Drawable {
                BackgroundColor = Colors.Blue, AllowDrop = true, Size = new Size(50, 50)
            };

            LogEvents(drawableDest);
            drawableDest.DragEnter += (sender, e) =>
            {
                if (e.Effects != DragEffects.None)
                {
                    drawableDest.BackgroundColor = Colors.Green;
                }
            };
            drawableDest.DragLeave += (sender, e) =>
            {
                if (e.Effects != DragEffects.None)
                {
                    drawableDest.BackgroundColor = Colors.Blue;
                }
            };
            drawableDest.DragDrop += (sender, e) =>
            {
                if (e.Effects != DragEffects.None)
                {
                    drawableDest.BackgroundColor = Colors.Blue;
                }
            };

            var dragMode = new RadioButtonList
            {
                Orientation = Orientation.Vertical,
                Items       =
                {
                    new ListItem {
                        Text = "No Restriction", Key = ""
                    },
                    new ListItem {
                        Text = "RestrictToOver", Key = "over"
                    },
                    new ListItem {
                        Text = "RestrictToInsert", Key = "insert"
                    },
                    new ListItem {
                        Text = "RestrictToNode", Key = "node"
                    },
                    new ListItem {
                        Text = "No Node", Key = "none"
                    }
                },
                SelectedIndex = 0
            };
            var treeDest = new TreeGridView {
                AllowDrop = true, Size = new Size(200, 200)
            };
            var treeDestData = CreateTreeData();

            treeDest.DataStore = treeDestData;
            treeDest.DragOver += (sender, e) =>
            {
                var info = treeDest.GetDragInfo(e);
                if (info == null)
                {
                    return;                     // not supported
                }
                switch (dragMode.SelectedKey)
                {
                case "over":
                    info.RestrictToOver();
                    break;

                case "insert":
                    info.RestrictToInsert();
                    break;

                case "node":
                    info.RestrictToNode(treeDestData[2]);
                    break;

                case "none":
                    info.Item = info.Parent = null;
                    break;
                }
            };
            SetupTreeColumns(treeDest);
            LogEvents(treeDest);

            var gridDest = new GridView {
                AllowDrop = true
            };
            var gridDestData = CreateGridData();

            gridDest.DataStore = gridDestData;
            gridDest.DragOver += (sender, e) =>
            {
                var info = gridDest.GetDragInfo(e);
                if (info == null)
                {
                    return;                     // not supported
                }
                switch (dragMode.SelectedKey)
                {
                case "over":
                    info.RestrictToOver();
                    break;

                case "insert":
                    info.RestrictToInsert();
                    break;

                case "node":
                    info.Index    = 2;
                    info.Position = GridDragPosition.Over;
                    break;

                case "none":
                    info.Index = -1;
                    break;
                }
            };
            SetupGridColumns(gridDest);
            LogEvents(gridDest);



            // layout

            var layout = new DynamicLayout {
                Padding = 10, DefaultSpacing = new Size(4, 4)
            };

            layout.BeginHorizontal();

            layout.BeginScrollable(BorderType.None);
            layout.BeginCentered();

            layout.AddSeparateRow(showDragOverEvents);
            layout.AddSeparateRow("AllowedEffect", allowedEffectDropDown, null);
            layout.BeginVertical();
            layout.AddRow("DropDescription", descriptionTextBox);
            layout.AddRow(new Panel(), innerTextBox);
            layout.EndVertical();
            layout.AddSeparateRow("DragEnter Effect", dragEnterEffect, null);
            layout.AddSeparateRow("DragOver Effect", dragOverEffect, null);
            layout.AddSeparateRow(useDragImage);
            layout.AddSeparateRow("Image offset:", imageOffset);
            layout.AddSeparateRow(writeDataCheckBox);

            layout.BeginGroup("DataObject", 10);
            layout.AddRow("Text", textBox);
            layout.AddRow("Html", htmlTextArea);
            layout.AddRow("Url", urlTextBox);
            layout.BeginHorizontal();
            layout.AddSpace();
            layout.BeginVertical();
            layout.AddCentered(includeImageCheck);
            layout.AddCentered(selectFilesButton);
            layout.EndVertical();
            layout.EndGroup();
            layout.Add(dragMode);
            layout.AddSpace();

            layout.EndCentered();
            layout.EndScrollable();

            layout.BeginVertical(xscale: true);
            layout.AddRange("Drag sources:", buttonSource, panelSource);
            layout.Add(treeSource, yscale: true);
            layout.Add(gridSource, yscale: true);
            layout.EndVertical();

            layout.BeginVertical(xscale: true);
            layout.AddRange("Drag destinations:", buttonDestination, drawableDest);
            layout.Add(treeDest, yscale: true);
            layout.Add(gridDest, yscale: true);
            layout.EndVertical();

            layout.EndHorizontal();

            Content = layout;
        }
        private Panel GenParmPanel(HB.Energy.IMaterial material)
        {
            var hbObj = material;

            var panel = new DynamicLayout();

            panel.DefaultSpacing = new Size(5, 5);
            panel.DefaultPadding = new Padding(5);

            var properties = hbObj.GetType().GetProperties().Where(_ => _.CanWrite);

            if (properties.Count() > 15)
            {
                panel.Height = 300;
                panel.BeginScrollable();
            }

            var name = new TextBox();

            hbObj.DisplayName = hbObj.DisplayName ?? hbObj.Identifier;
            name.TextBinding.Bind(() => hbObj.DisplayName, (v) => hbObj.DisplayName = v);

            panel.AddRow("Name", name);

            _r_label = new Label()
            {
                Text = _r_si
            };
            _u_label = new Label()
            {
                Text = _u_si
            };

            _r_value = new TextBox()
            {
                Enabled = false, PlaceholderText = "Not available"
            };
            _u_value = new TextBox()
            {
                Enabled = false, PlaceholderText = "Not available"
            };
            panel.AddRow(_r_label, _r_value);
            panel.AddRow(_u_label, _u_value);
            CalRValue(hbObj, false);

            foreach (var item in properties)
            {
                if (item.Name == "Identifier" || item.Name == "Type" || item.Name == "DisplayName")
                {
                    continue;
                }

                var value = item.GetValue(hbObj);
                var type  = item.PropertyType;
                if (value is string stringvalue)
                {
                    var textBox = new TextBox();
                    //textBox.Text = stringvalue;
                    textBox.TextBinding.Bind(() => stringvalue, (v) => item.SetValue(hbObj, v));
                    panel.AddRow(item.Name, textBox);
                }
                else if (value is double numberValue)
                {
                    var numberTB = new MaskedTextBox();
                    numberTB.Provider = new NumericMaskedTextProvider()
                    {
                        AllowDecimal = true
                    };
                    var hasUnits = _propertyUnits.TryGetValue(item.Name, out var units);
                    if (hasUnits)
                    {
                        var baseUnit    = units.baseUnit.ToUnitsNetEnum();
                        var displayUnit = units.displayUnit.ToUnitsNetEnum();

                        numberTB.TextBinding.Bind(
                            () => {
                            var displayValue = Units.ConvertValueWithUnits(numberValue, baseUnit, displayUnit);
                            return(displayValue.ToString());
                        },
                            (v) => {
                            Utility.TryParse(v, out var numValue);
                            var baseValue = Units.ConvertValueWithUnits(numValue, displayUnit, baseUnit);
                            item.SetValue(hbObj, baseValue);
                            CalRValue(hbObj, _showIP);
                        }
                            );
                        var abb          = displayUnit.GetAbbreviation();
                        var nameWithUnit = $"{item.Name} [{abb}]";
                        panel.AddRow(nameWithUnit, numberTB);
                    }
                    else // unitless property
                    {
                        numberTB.TextBinding.Bind(
                            () => numberValue.ToString(),
                            (v) => {
                            Utility.TryParse(v, out var numValue);
                            item.SetValue(hbObj, numValue);
                            CalRValue(hbObj, _showIP);
                        }
                            );
                        panel.AddRow(item.Name, numberTB);
                    }
                }
                else if (value is int intValue)
                {
                    var numberTB = new NumericStepper();
                    numberTB.DecimalPlaces = 0;
                    numberTB.ValueBinding.Bind(
                        () => intValue,
                        (v) => {
                        item.SetValue(hbObj, v);
                        CalRValue(hbObj, _showIP);
                    }
                        );
                    panel.AddRow(item.Name, numberTB);
                }
                else if (Nullable.GetUnderlyingType(type) != null)
                {
                    var enumType = Nullable.GetUnderlyingType(type);
                    if (!enumType.IsEnum)
                    {
                        continue;
                    }
                    var values        = Enum.GetNames(enumType).ToList();
                    var dropdown      = new DropDown();
                    var dropDownItems = values.Select(_ => new ListItem()
                    {
                        Text = _, Key = _
                    });
                    dropdown.Items.AddRange(dropDownItems);

                    var currentValue = item.GetValue(hbObj, null).ToString();
                    dropdown.SelectedKeyBinding.Bind(
                        () => currentValue,
                        (v) => item.SetValue(hbObj, Enum.Parse(enumType, v))
                        );

                    panel.AddRow(item.Name, dropdown);
                }
                else if (type.IsEnum)
                {
                    var values        = Enum.GetNames(type).ToList();
                    var dropdown      = new DropDown();
                    var dropDownItems = values.Select(_ => new ListItem()
                    {
                        Text = _, Key = _
                    });
                    dropdown.Items.AddRange(dropDownItems);

                    var currentValue = item.GetValue(hbObj, null).ToString();
                    dropdown.SelectedKeyBinding.Bind(
                        () => currentValue,
                        (v) => item.SetValue(hbObj, Enum.Parse(type, v))
                        );

                    panel.AddRow(item.Name, dropdown);
                }
            }


            panel.AddRow(null, null);
            return(panel);
        }
        public Dialog_ProgramType(ref HB.ModelProperties libSource, HB.ProgramTypeAbridged programType, bool lockedMode = false)
        {
            try
            {
                libSource.FillNulls();

                _vm = new ProgramTypeViewModel(this, ref libSource, programType);

                Title       = $"Program Type - {DialogHelper.PluginName}";
                WindowStyle = WindowStyle.Default;
                Width       = 450;
                this.Icon   = DialogHelper.HoneybeeIcon;


                //Generate ProgramType Panel

                var nameTbx = new TextBox();
                nameTbx.TextBinding.Bind(_vm, c => c.Name);

                var loadGroup = GenLoadsPanel(lockedMode);


                var locked = new CheckBox()
                {
                    Text = "Locked", Enabled = false
                };
                locked.Checked = lockedMode;

                var OkButton = new Button {
                    Text = "OK", Enabled = !lockedMode
                };
                OkButton.Click += (sender, e) => {
                    try
                    {
                        OkCommand.Execute(_vm.GetHBObject());
                    }
                    catch (Exception er)
                    {
                        MessageBox.Show(er.Message);
                        //throw;
                    }
                };

                AbortButton = new Button {
                    Text = "Cancel"
                };
                AbortButton.Click += (sender, e) => Close();

                // Json Data
                var hbData = new Button {
                    Text = "Schema Data"
                };
                hbData.Command = _vm.HBDataBtnClick;

                //Create layout
                var layout = new DynamicLayout()
                {
                    DefaultPadding = new Padding(5), DefaultSpacing = new Size(5, 5)
                };
                layout.BeginScrollable(BorderType.None);

                layout.AddRow("Name");
                layout.AddRow(nameTbx);
                layout.AddRow(loadGroup);
                layout.AddRow(null);
                layout.EndScrollable();
                layout.AddSeparateRow(locked, null, OkButton, AbortButton, null, hbData);
                layout.Add(null);
                //Create layout
                Content = layout;
            }
            catch (Exception e)
            {
                //throw e;
                Dialog_Message.Show(e.ToString());
            }
        }
        public Dialog_ConstructionSet(ref HB.ModelEnergyProperties libSource, HB.ConstructionSetAbridged constructionSet, bool lockedMode = false)
        {
            try
            {
                _vm = new ConstructionSetViewModel(this, ref libSource, constructionSet);

                Padding     = new Padding(5);
                Resizable   = true;
                Title       = $"Construction Set - {DialogHelper.PluginName}";
                WindowStyle = WindowStyle.Default;
                MinimumSize = new Size(450, 600);
                this.Icon   = DialogHelper.HoneybeeIcon;


                var nameTbx = new TextBox()
                {
                    Enabled = !lockedMode
                };
                nameTbx.TextBinding.Bind(_vm, _ => _.Name);

                var wallGroup     = GenWallSetPanel(lockedMode);
                var floorGroup    = GenFloorSetPanel(lockedMode);
                var roofGroup     = GenRoofSetPanel(lockedMode);
                var apertureGroup = GenApertureSetPanel(lockedMode);
                var doorGroup     = GenDoorSetPanel(lockedMode);
                var shadeGroup    = GenShadeSetPanel(lockedMode);
                var airBdGroup    = GenAirBoundarySetPanel(lockedMode);


                //Left panel
                var panelLeft = new DynamicLayout();
                panelLeft.DefaultSpacing = new Size(0, 5);

                panelLeft.BeginScrollable(BorderType.None);
                panelLeft.Height = 600;


                panelLeft.AddRow("Name");
                panelLeft.AddRow(nameTbx);
                panelLeft.AddRow(wallGroup);
                panelLeft.AddRow(floorGroup);
                panelLeft.AddRow(roofGroup);
                panelLeft.AddRow(apertureGroup);
                panelLeft.AddRow(doorGroup);
                panelLeft.AddRow(shadeGroup);
                panelLeft.AddRow(airBdGroup);

                var locked = new CheckBox()
                {
                    Text = "Locked", Enabled = false
                };
                locked.Checked = lockedMode;

                var OkButton = new Button {
                    Text = "OK", Enabled = !lockedMode
                };
                OkButton.Click += (sender, e) =>
                {
                    var obj = _vm.GetHBObject();
                    OkCommand.Execute(obj);
                };

                AbortButton = new Button {
                    Text = "Cancel"
                };
                AbortButton.Click += (sender, e) => Close();

                var hbData = new Button {
                    Text = "Schema Data"
                };
                hbData.Command = _vm.HBDataBtnClick;

                var buttons = new TableLayout
                {
                    Padding = new Padding(5, 10, 5, 5),
                    Spacing = new Size(10, 10),
                    Rows    = { new TableRow(locked, null, OkButton, this.AbortButton, null, hbData) }
                };


                //Create layout
                Content = new TableLayout()
                {
                    Padding = new Padding(10),
                    Spacing = new Size(5, 5),
                    Rows    =
                    {
                        panelLeft,
                        new TableRow(buttons),
                        null
                    }
                };
            }
            catch (Exception e)
            {
                Dialog_Message.Show(e.ToString());
                //throw e;
            }
        }
        public LevelPropertiesWindow(IEditor <CampaignFile> editor, CampaignLevel level)
        {
            this.editor = editor;

            Data = level.CloneObject()
                   ?? new CampaignLevel()
            {
                Guid = Guid.NewGuid().ToString()
            };

            Title   = $"{(Equals(level, null) ? "Add" : "Edit")} level";
            Size    = MinimumSize = new Size(600, 400);
            Padding = new Padding(8);

            Resizable = true;

            Content = new StackLayout()
            {
                Style   = "vertical",
                Spacing = 8,

                Items =
                {
                    new StackLayoutItem(tabs = new ExtendedTabControl(),           true),
                    new StackLayoutItem(new StackLayout()
                    {
                        Style   = "horizontal",
                        Spacing =                                  8,
                        Padding = new Padding(0,                          8,0, 0),

                        Items                =
                        {
                            null,
                            (DefaultButton   = new Button(OnConfirm)
                            {
                                Text         = "OK",
                                Image        = Resources.GetIcon("CheckGreen.ico",     16)
                            }),
                            (AbortButton     = new Button(OnCancel)
                            {
                                Text         = "Cancel",
                                Image        = Resources.GetIcon("CloseRed.ico", 16)
                            })
                        }
                    }, false)
                }
            };

            #region General Tab
            tabs.AddPage("General", generalProperties = new DynamicLayout());

            generalProperties.BeginScrollable(BorderType.None);
            generalProperties.BeginVertical();

            generalProperties.AddRow("Unique ID", propLevelGuid  = new GuidLabel());
            generalProperties.AddRow("Level file", propLevelFile = new ResourceSelector(editor, ResourceType.Level));
            generalProperties.AddRow("Level name", propLevelName = new TextBox());

            generalProperties.EndVertical();
            generalProperties.AddSpace();
            generalProperties.EndScrollable();
            #endregion

            //tabs.AddPage("Gameplay", gameplayProperties = new DynamicLayout());

            #region Loading Screen Tab
            tabs.AddPage("Loading screen", loadingScreenProperties = new DynamicLayout());

            loadingScreenProperties.BeginScrollable(BorderType.None);
            loadingScreenProperties.BeginVertical();

            loadingScreenProperties.AddRow("Background image", propLoadingBackground = new ResourceSelector(editor, ResourceType.Texture));

            loadingScreenProperties.AddRow(string.Empty, new StackLayout()
            {
                Style = "no-padding horizontal",

                Items =
                {
                    (propLoadingBackgroundPreview = new StretchedImageBox()
                    {
                        Width                     =160,
                        Height                    = 90
                    }),
                    null
                }
            });

            loadingScreenProperties.AddRow("Overwrite loading text", propLoadingOverwriteText = new BooleanSelector());
            loadingScreenProperties.AddRow("Loading text", propLoadingText = new TextBox());
            loadingScreenProperties.AddRow("Progress indicator icon", propLoadingBackgroundIcon = new ResourceSelector(editor, ResourceType.Texture));
            loadingScreenProperties.AddRow(string.Empty, new StackLayout()
            {
                Style = "no-padding horizontal",

                Items =
                {
                    (propLoadingBackgroundIconPreview = new StretchedImageBox()
                    {
                        Width                         =64,
                        Height                        = 64
                    }),
                    null
                }
            });

            loadingScreenProperties.EndVertical();
            loadingScreenProperties.AddSpace();
            loadingScreenProperties.EndScrollable();
            #endregion

            #region Intro Sequence Tab
            tabs.AddPage("Intro sequence", introSequenceProperties = new DynamicLayout());

            introSequenceProperties.BeginScrollable(BorderType.None);
            introSequenceProperties.BeginVertical();

            // Set whether or not to show the intro, the intro style and text values

            introSequenceProperties.AddRow("Intro type", propIntroType   = new EnumDropDown <LevelTransitionType>());
            introSequenceProperties.AddRow("First line", propIntroLine1  = new TextBox());
            introSequenceProperties.AddRow("Second line", propIntroLine2 = new TextBox());

            introSequenceProperties.EndVertical();
            introSequenceProperties.AddSpace();
            introSequenceProperties.EndScrollable();
            #endregion

            #region Event Subscribing
            propLoadingOverwriteText.ValueChanged      += OnOverwriteLoadingTextChanged;
            propIntroType.SelectedValueChanged         += OnTransitionTypeChanged;
            propLoadingBackground.ResourceSelected     += OnBackgroundSelected;
            propLoadingBackgroundIcon.ResourceSelected += OnLoadingIconSelected;
            #endregion

            LoadData(Data);
        }