private GroupBox GenSHWPanel()
        {
            var vm = this._vm;

            var layout = new DynamicLayout();

            layout.Bind((t) => t.Visible, vm, v => v.ServiceHotWater.IsPanelEnabled);


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

            var wPerArea = new DoubleText();

            wPerArea.Width        = 250;
            wPerArea.ReservedText = ReservedText.Varies;
            wPerArea.SetDefault(_vm.ServiceHotWater.Default.FlowPerArea);
            wPerArea.TextBinding.Bind(vm, _ => _.ServiceHotWater.FlowPerArea.NumberText);
            layout.AddRow("Flow/Area:");
            var unit = new Label();

            unit.TextBinding.Bind(vm, _ => _.ServiceHotWater.FlowPerArea.DisplayUnitAbbreviation);
            layout.AddSeparateRow(wPerArea, unit);

            var sch = new Button();

            sch.TextBinding.Bind(vm, _ => _.ServiceHotWater.Schedule.BtnName);
            sch.Bind(_ => _.Command, vm, _ => _.ServiceHotWater.ScheduleCommand);
            layout.AddRow("Schedule:");
            layout.AddRow(sch);

            var airFraction = new DoubleText()
            {
                Width = 250
            };

            airFraction.ReservedText = ReservedText.Varies;
            airFraction.SetDefault(_vm.ServiceHotWater.Default.TargetTemperature);
            airFraction.TextBinding.Bind(vm, _ => _.ServiceHotWater.TargetTemperature.NumberText);
            layout.AddRow("Target Temperature:");
            var unit2 = new Label();

            unit2.TextBinding.Bind(vm, _ => _.ServiceHotWater.TargetTemperature.DisplayUnitAbbreviation);
            layout.AddSeparateRow(airFraction, unit2);

            var radFraction = new DoubleText();

            radFraction.ReservedText = ReservedText.Varies;
            radFraction.SetDefault(_vm.ServiceHotWater.Default.SensibleFraction);
            radFraction.TextBinding.Bind(vm, _ => _.ServiceHotWater.SensibleFraction.NumberText);
            layout.AddRow("Sensible Fraction:");
            layout.AddRow(radFraction);

            var visFraction = new DoubleText();

            visFraction.ReservedText = ReservedText.Varies;
            visFraction.SetDefault(_vm.ServiceHotWater.Default.LatentFraction);
            visFraction.TextBinding.Bind(vm, _ => _.ServiceHotWater.LatentFraction.NumberText);
            layout.AddRow("Latent Fraction:");
            layout.AddRow(visFraction);


            layout.AddRow(null);


            var ltnByProgram = new CheckBox()
            {
                Text = ReservedText.Noload
            };

            ltnByProgram.CheckedBinding.Bind(vm, _ => _.ServiceHotWater.IsCheckboxChecked);

            var gp = new GroupBox()
            {
                Text = "Service Hot Water"
            };

            gp.Content = new StackLayout(ltnByProgram, layout)
            {
                Spacing = 4, Padding = new Padding(4)
            };

            return(gp);
        }
        private GroupBox GenVentPanel()
        {
            var vm = this._vm;

            var layout = new DynamicLayout();

            layout.Bind((t) => t.Visible, vm, v => v.Ventilation.IsPanelEnabled);


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

            var wPerArea = new DoubleText();

            wPerArea.Width        = 250;
            wPerArea.ReservedText = ReservedText.Varies;
            wPerArea.SetDefault(_vm.Ventilation.Default.FlowPerArea);
            wPerArea.TextBinding.Bind(vm, _ => _.Ventilation.FlowPerArea.NumberText);
            layout.AddRow("Flow/Area:");
            var unit = new Label();

            unit.TextBinding.Bind(vm, _ => _.Ventilation.FlowPerArea.DisplayUnitAbbreviation);
            layout.AddSeparateRow(wPerArea, unit);

            var sch = new OptionalButton();

            sch.TextBinding.Bind(vm, _ => _.Ventilation.Schedule.BtnName);
            sch.Bind(_ => _.Command, vm, _ => _.Ventilation.ScheduleCommand);
            sch.Bind(_ => _.RemoveCommand, vm, _ => _.Ventilation.RemoveScheduleCommand);
            sch.Bind(_ => _.IsRemoveVisable, vm, _ => _.Ventilation.Schedule.IsRemoveVisable);
            layout.AddRow("Schedule:");
            layout.AddRow(sch);

            var radFraction = new DoubleText()
            {
                Width = 250
            };

            radFraction.ReservedText = ReservedText.Varies;
            radFraction.SetDefault(_vm.Ventilation.Default.FlowPerPerson);
            radFraction.TextBinding.Bind(vm, _ => _.Ventilation.FlowPerPerson.NumberText);
            layout.AddRow("Flow/Person:");
            var unit2 = new Label();

            unit2.TextBinding.Bind(vm, _ => _.Ventilation.FlowPerPerson.DisplayUnitAbbreviation);
            layout.AddSeparateRow(radFraction, unit2);

            var visFraction = new DoubleText()
            {
                Width = 250
            };

            visFraction.ReservedText = ReservedText.Varies;
            visFraction.SetDefault(_vm.Ventilation.Default.FlowPerZone);
            visFraction.TextBinding.Bind(vm, _ => _.Ventilation.FlowPerZone.NumberText);
            layout.AddRow("Flow/Zone:");
            var unit3 = new Label();

            unit3.TextBinding.Bind(vm, _ => _.Ventilation.FlowPerZone.DisplayUnitAbbreviation);
            layout.AddSeparateRow(visFraction, unit3);

            var airFraction = new DoubleText()
            {
                Width = 250
            };

            airFraction.ReservedText = ReservedText.Varies;
            airFraction.SetDefault(_vm.Ventilation.Default.AirChangesPerHour);
            airFraction.TextBinding.Bind(vm, _ => _.Ventilation.AirChangesPerHour.NumberText);
            layout.AddRow("AirChanges/Hour:");
            var unit4 = new Label();

            unit4.TextBinding.Bind(vm, _ => _.Ventilation.AirChangesPerHour.DisplayUnitAbbreviation);
            layout.AddSeparateRow(airFraction, unit4);

            layout.AddRow(null);


            var ltnByProgram = new CheckBox()
            {
                Text = ReservedText.Noload
            };

            ltnByProgram.CheckedBinding.Bind(vm, _ => _.Ventilation.IsCheckboxChecked);

            var gp = new GroupBox()
            {
                Text = "Ventilation"
            };

            gp.Content = new StackLayout(ltnByProgram, layout)
            {
                Spacing = 4, Padding = new Padding(4)
            };

            return(gp);
        }
        private GroupBox GenInfPanel()
        {
            var vm = this._vm;

            var layout = new DynamicLayout();

            layout.Bind((t) => t.Visible, vm, v => v.Infiltration.IsPanelEnabled);

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

            var wPerArea = new DoubleText();

            wPerArea.Width        = 250;
            wPerArea.ReservedText = ReservedText.Varies;
            wPerArea.SetDefault(_vm.Infiltration.Default.FlowPerExteriorArea);
            wPerArea.TextBinding.Bind(vm, _ => _.Infiltration.FlowPerExteriorArea.NumberText);
            layout.AddRow("Flow/Area (exterior area):");
            var unit = new Label();

            unit.TextBinding.Bind(vm, _ => _.Infiltration.FlowPerExteriorArea.DisplayUnitAbbreviation);
            layout.AddSeparateRow(wPerArea, unit);

            var sch = new Button();

            sch.TextBinding.Bind(vm, _ => _.Infiltration.Schedule.BtnName);
            sch.Bind(_ => _.Command, vm, _ => _.Infiltration.ScheduleCommand);
            layout.AddRow("Schedule:");
            layout.AddRow(sch);

            var radFraction = new DoubleText();

            radFraction.ReservedText = ReservedText.Varies;
            radFraction.SetDefault(_vm.Infiltration.Default.ConstantCoefficient);
            radFraction.TextBinding.Bind(vm, _ => _.Infiltration.ConstantCoefficient.NumberText);
            layout.AddRow("Constant Coefficient:");
            layout.AddRow(radFraction);

            var visFraction = new DoubleText();

            visFraction.ReservedText = ReservedText.Varies;
            visFraction.SetDefault(_vm.Infiltration.Default.TemperatureCoefficient);
            visFraction.TextBinding.Bind(vm, _ => _.Infiltration.TemperatureCoefficient.NumberText);
            layout.AddRow("Temperature Coefficient:");
            layout.AddRow(visFraction);

            var airFraction = new DoubleText();

            airFraction.ReservedText = ReservedText.Varies;
            airFraction.SetDefault(_vm.Infiltration.Default.VelocityCoefficient);
            airFraction.TextBinding.Bind(vm, _ => _.Infiltration.VelocityCoefficient.NumberText);
            layout.AddRow("Velocity Coefficient:");
            layout.AddRow(airFraction);

            layout.AddRow(null);


            var ltnByProgram = new CheckBox()
            {
                Text = ReservedText.Noload
            };

            ltnByProgram.CheckedBinding.Bind(vm, _ => _.Infiltration.IsCheckboxChecked);

            var gp = new GroupBox()
            {
                Text = "Infiltration"
            };

            gp.Content = new StackLayout(ltnByProgram, layout)
            {
                Spacing = 4, Padding = new Padding(4)
            };

            return(gp);
        }
        private GroupBox GenPplPanel()
        {
            var vm = this._vm;

            var layout = new DynamicLayout();

            layout.Bind((t) => t.Visible, vm, v => v.People.IsPanelEnabled);

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

            var wPerArea = new DoubleText();

            wPerArea.Width        = 250;
            wPerArea.ReservedText = ReservedText.Varies;
            wPerArea.SetDefault(_vm.People.Default.PeoplePerArea);
            wPerArea.TextBinding.Bind(vm, _ => _.People.PeoplePerArea.NumberText);
            layout.AddRow("People/Area:");
            var unit = new Label();

            unit.TextBinding.Bind(vm, _ => _.People.PeoplePerArea.DisplayUnitAbbreviation);
            layout.AddSeparateRow(wPerArea, unit);

            var sch = new Button();

            sch.TextBinding.Bind(vm, _ => _.People.OccupancySchedule.BtnName);
            sch.Bind(_ => _.Command, vm, _ => _.People.ScheduleCommand);
            layout.AddRow("Occupancy Schedule:");
            layout.AddRow(sch);

            var sch2 = new OptionalButton();

            sch2.TextBinding.Bind(vm, _ => _.People.ActivitySchedule.BtnName);
            sch2.Bind(_ => _.Command, vm, _ => _.People.ActivityScheduleCommand);
            sch2.Bind(_ => _.RemoveCommand, vm, _ => _.People.RemoveActivityScheduleCommand);
            sch2.Bind(_ => _.IsRemoveVisable, vm, _ => _.People.ActivitySchedule.IsRemoveVisable);
            layout.AddRow("Activity Schedule:");
            layout.AddRow(sch2);

            var radFraction = new DoubleText();

            radFraction.ReservedText = ReservedText.Varies;
            radFraction.SetDefault(_vm.People.Default.RadiantFraction);
            radFraction.TextBinding.Bind(vm, _ => _.People.RadiantFraction.NumberText);
            layout.AddRow("Radiant Fraction:");
            layout.AddRow(radFraction);

            var visFraction = new DoubleText();

            visFraction.ReservedText = ReservedText.Varies;
            visFraction.SetDefault(_vm.People.Default.LatentFraction);
            visFraction.TextBinding.Bind(vm, _ => _.People.LatentFraction.NumberText);
            visFraction.Bind(_ => _.Enabled, vm, _ => _.People.IsLatenFractionInputEnabled);
            var autosize = new CheckBox()
            {
                Text = "Autocalculate"
            };

            autosize.Bind(_ => _.Checked, vm, _ => _.People.IsLatentFractionAutocalculate);
            layout.AddRow("Latent Fraction:");
            layout.AddRow(autosize);
            layout.AddRow(visFraction);

            layout.AddRow(null);



            var ltnByProgram = new CheckBox()
            {
                Text = ReservedText.Noload
            };

            ltnByProgram.CheckedBinding.Bind(vm, _ => _.People.IsCheckboxChecked);

            var gp = new GroupBox()
            {
                Text = "People"
            };

            gp.Content = new StackLayout(ltnByProgram, layout)
            {
                Spacing = 4, Padding = new Padding(4)
            };

            return(gp);
        }
        private GroupBox GenGasEqpPanel()
        {
            var vm = this._vm;

            var layout = new DynamicLayout();

            layout.Bind((t) => t.Visible, vm, v => v.Gas.IsPanelEnabled);


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

            var wPerArea = new DoubleText();

            wPerArea.Width        = 250;
            wPerArea.ReservedText = ReservedText.Varies;
            wPerArea.SetDefault(_vm.Gas.Default.WattsPerArea);
            wPerArea.TextBinding.Bind(vm, _ => _.Gas.WattsPerArea.NumberText);
            layout.AddRow("Watts/Area:");
            var unit = new Label();

            unit.TextBinding.Bind(vm, _ => _.Gas.WattsPerArea.DisplayUnitAbbreviation);
            layout.AddSeparateRow(wPerArea, unit);

            var sch = new Button();

            sch.TextBinding.Bind(vm, _ => _.Gas.Schedule.BtnName);
            sch.Bind(_ => _.Command, vm, _ => _.Gas.ScheduleCommand);
            layout.AddRow("Schedule:");
            layout.AddRow(sch);

            var radFraction = new DoubleText();

            radFraction.ReservedText = ReservedText.Varies;
            radFraction.SetDefault(_vm.Gas.Default.RadiantFraction);
            radFraction.TextBinding.Bind(vm, _ => _.Gas.RadiantFraction.NumberText);
            layout.AddRow("Radiant Fraction:");
            layout.AddRow(radFraction);

            var visFraction = new DoubleText();

            visFraction.ReservedText = ReservedText.Varies;
            visFraction.SetDefault(_vm.Gas.Default.LatentFraction);
            visFraction.TextBinding.Bind(vm, _ => _.Gas.LatentFraction.NumberText);
            layout.AddRow("Latent Fraction:");
            layout.AddRow(visFraction);

            var airFraction = new DoubleText();

            airFraction.ReservedText = ReservedText.Varies;
            airFraction.SetDefault(_vm.Gas.Default.LostFraction);
            airFraction.TextBinding.Bind(vm, _ => _.Gas.LostFraction.NumberText);
            layout.AddRow("Lost Fraction:");
            layout.AddRow(airFraction);

            layout.AddRow(null);


            var ltnByProgram = new CheckBox()
            {
                Text = ReservedText.Noload
            };

            ltnByProgram.CheckedBinding.Bind(vm, _ => _.Gas.IsCheckboxChecked);

            var gp = new GroupBox()
            {
                Text = "Gas Equipment"
            };

            gp.Content = new StackLayout(ltnByProgram, layout)
            {
                Spacing = 4, Padding = new Padding(4)
            };

            return(gp);
        }
        //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;
        }