private void ShowSHWDialog(HB.SHWSystem system, Action <SHWSystem> doneAction = default)
        {
            this._control.Visible = false;
            var dialog = new Dialog_SHW(system, roomIDPicker: AmbientCoffConditionRoomPicker);

            System.Action <SHWSystem> f = (SHWSystem s) =>
            {
                if (s != null)
                {
                    if (doneAction != default)
                    {
                        doneAction(s); //edit object
                    }
                    else
                    {
                        AddUserData(s); // add/duplicate object
                    }
                    ResetDataCollection();
                }
                this._control.Visible = true;
            };


            dialog.ShowModal(_control, f);
        }
        public SHWViewData(HB.SHWSystem c)
        {
            this.Name  = c.DisplayName ?? c.Identifier;
            this.EType = c.EquipmentType.ToString();
            if (c.HeaterEfficiency?.Obj is Autocalculate)
            {
                this.HeaterEfficiency = "Autocalculate";
            }
            else
            {
                this.HeaterEfficiency = c.HeaterEfficiency?.Obj?.ToString();
            }

            this.Condition = c.AmbientCondition?.Obj?.ToString();
            this.LossCoeff = c.AmbientLossCoefficient.ToString();
            this.System    = c;

            this.SearchableText = $"{this.Name}_{this.EType}_{HeaterEfficiency}_{Condition}_{LossCoeff}";

            //check if system library
            this.Locked = LockedLibraryIds.Contains(c.Identifier);

            if (LBTLibraryIds.Contains(c.Identifier))
            {
                this.Source = "LBT";
            }
            //else if (NRELLibraryIds.Contains(this.Name)) this.Source = "DoE NREL";
        }
        private void ReplaceUserData(SHWViewData oldObj, HB.SHWSystem newObj)
        {
            var newItem = CheckObjName(newObj, oldObj.Name);
            var index   = _userData.IndexOf(oldObj);

            _userData.RemoveAt(index);
            _userData.Insert(index, new SHWViewData(newItem));
            this._allData = _userData.Concat(_systemData).Distinct(_viewDataComparer).ToList();
        }
        private void AddUserData(HB.SHWSystem item)
        {
            var newItem     = CheckObjName(item);
            var newDataView = new SHWViewData(newItem);

            if (!this._userData.Contains(newDataView))
            {
                // user selected an item from system library, now add it to model EnergyProperties
                this._modelEnergyProperties.AddSHW(newDataView.System);
            }
            this._userData.Insert(0, newDataView);
            this._allData = _userData.Concat(_systemData).Distinct(_viewDataComparer).ToList();
        }
        //private ModelEnergyProperties ModelEnergyProperties { get; set; }
        public Dialog_SHW(HoneybeeSchema.SHWSystem shw = default, bool lockedMode = false, Func <string> roomIDPicker = default)
        {
            var sys = shw ?? new SHWSystem($"SHWSystem_{Guid.NewGuid().ToString().Substring(0, 8)}");
            var vm  = new SHWViewModel(sys, this);

            vm.SetAmbientCoffConditionRoomPicker(roomIDPicker);

            //Padding = new Padding(4);
            Title       = $"Service Hot Water - {DialogHelper.PluginName}";
            WindowStyle = WindowStyle.Default;
            Width       = 450;
            this.Icon   = DialogHelper.HoneybeeIcon;

            var layout = new DynamicLayout();

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


            //string identifier,
            //string displayName = null,
            //object userData = null,
            //SHWEquipmentType equipmentType = SHWEquipmentType.Gas_WaterHeater,
            //AnyOf<double, Autocalculate> heaterEfficiency = null,
            //AnyOf< double, string> ambientCondition = null,
            //double ambientLossCoefficient = 6.0

            var nameText = new TextBox();

            var eqpType       = new EnumDropDown <SHWEquipmentType>();
            var heaterEffAuto = new RadioButton()
            {
                Text = "Autocalculate"
            };
            var heaterEffNumber = new RadioButton();
            var heaterEff       = new NumericStepper();

            // ambientCoffCondition
            var ambientLayout = new DynamicLayout();

            ambientLayout.DefaultSpacing = new Size(5, 5);

            var ambientCoffConditionNumber = new RadioButton();
            var ambientCoffConditionRoom   = new RadioButton()
            {
                Text = "Room ID"
            };

            var ambientCoffCondition = new DoubleText()
            {
                Width = 370
            };
            var ambientCoffConditionRoomLayout = new DynamicLayout();
            var ambientCoffConditionRoomID     = new TextBox();
            var ambientCoffConditionRoomID_btn = new Button();

            ambientCoffConditionRoomLayout.AddRow(ambientCoffConditionRoomID);
            ambientCoffConditionRoomLayout.AddRow(ambientCoffConditionRoomID_btn);

            var ambientCoffConditionUnit = new Label();

            ambientCoffConditionUnit.TextBinding.Bind(vm, _ => _.AmbientCoffConditionNumber.DisplayUnitAbbreviation);

            ambientLayout.AddSeparateRow("Ambient Condition:");
            ambientLayout.AddSeparateRow(ambientCoffConditionNumber, ambientCoffCondition, ambientCoffConditionUnit);
            ambientLayout.AddSeparateRow(ambientCoffConditionRoom, ambientCoffConditionRoomLayout);
            ambientLayout.Bind(_ => _.Enabled, vm, _ => _.AmbientCoffConditionEnabled);


            var ambientLossCoefficient = new NumericStepper()
            {
                MaximumDecimalPlaces = 2
            };

            nameText.Bind(_ => _.Text, vm, _ => _.Name);
            eqpType.Bind(_ => _.SelectedValue, vm, _ => _.EquipType);


            heaterEffAuto.Bind(c => c.Checked, vm, _ => _.HeaterEffAuto);
            heaterEffNumber.Bind(c => c.Checked, vm, _ => _.HeaterEffEnabled);
            heaterEff.Bind(c => c.Value, vm, _ => _.HeaterEff);
            heaterEff.Bind(c => c.Enabled, vm, _ => _.HeaterEffEnabled);

            ambientCoffConditionNumber.Bind(c => c.Checked, vm, _ => _.AmbientCoffConditionNumberEnabled);
            ambientCoffConditionRoom.Bind(c => c.Checked, vm, _ => _.AmbientCoffConditionRoomIDEnabled);
            //ambientCoffCondition.Bind(c => c.Value, vm, _ => _.AmbientCoffConditionNumber);
            ambientCoffCondition.Bind(c => c.Enabled, vm, _ => _.AmbientCoffConditionNumberEnabled);
            ambientCoffConditionRoomLayout.Bind(c => c.Enabled, vm, _ => _.AmbientCoffConditionRoomIDEnabled);

            ambientCoffConditionRoomID.Bind(c => c.Text, vm, _ => _.AmbientCoffConditionRoomID);
            ambientCoffConditionRoomID.Bind(_ => _.Visible, vm, _ => _.VisibleAmbientCoffConditionRoomInput);
            ambientCoffConditionRoomID_btn.Bind(_ => _.Text, vm, _ => _.AmbientCoffConditionRoomID);
            ambientCoffConditionRoomID_btn.Bind(_ => _.Visible, vm, _ => _.VisibleAmbientCoffConditionRoomPicker);
            ambientCoffConditionRoomID_btn.Command = vm.AmbientCoffConditionRoomPickerCommand;

            ambientCoffCondition.ReservedText = ReservedText.Varies;
            ambientCoffCondition.SetDefault(22);
            ambientCoffCondition.TextBinding.Bind(vm, _ => _.AmbientCoffConditionNumber.NumberText);


            ambientLossCoefficient.Bind(_ => _.Value, vm, _ => _.AmbientLostCoff);

            layout.AddRow("Name:");
            layout.AddRow(nameText);
            layout.AddRow("Equipment Type:");
            layout.AddRow(eqpType);

            layout.AddRow("Heater Efficiency:");
            layout.AddRow(heaterEffAuto);
            layout.AddSeparateRow(heaterEffNumber, heaterEff);

            layout.AddRow(ambientLayout);

            layout.AddRow("Ambient Loss Coefficient [W/K]");
            layout.AddRow(ambientLossCoefficient);

            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.GreateSys(shw));
                }
                catch (Exception er)
                {
                    MessageBox.Show(this, er.Message);
                    //throw;
                }
            };

            var abortButton = new Button {
                Text = "Cancel"
            };

            abortButton.Click += (sender, e) => Close();

            var hbData = new Button {
                Text = "Data"
            };

            hbData.Click += (sender, e) => Dialog_Message.Show(this, vm.GreateSys(shw).ToJson(true), "Schema Data");

            layout.AddSeparateRow(locked, null, OKButton, abortButton, null, hbData);
            layout.AddRow(null);
            Content = layout;
        }