Пример #1
0
        void Initialize()
        {
            var su  = MatStream.GetFlowsheet().FlowsheetOptions.SelectedUnitSystem;
            var nf  = MatStream.GetFlowsheet().FlowsheetOptions.NumberFormat;
            var nff = MatStream.GetFlowsheet().FlowsheetOptions.FractionNumberFormat;

            s.CreateAndAddLabelRow(container, "Material Stream Property Editor");

            s.CreateAndAddDescriptionRow(container, "Except for compound amounts, property values are updated/stored as they are changed/edited.");

            s.CreateAndAddLabelRow(container, "Material Stream Details");

            s.CreateAndAddTwoLabelsRow(container, "Status", MatStream.GraphicObject.Active ? "Active" : "Inactive");

            s.CreateAndAddStringEditorRow(container, "Name", MatStream.GraphicObject.Tag, (TextBox arg3, EventArgs ev) =>
            {
                MatStream.GraphicObject.Tag = arg3.Text;
            }, () => CallSolverIfNeeded());

            s.CreateAndAddDropDownRow(container, "Compound Amount Basis",
                                      new List <string>()
            {
                "Molar Fractions", "Mass Fractions", "Volumetric Fractions", "Molar Flows", "Mass Flows", "Volumetric Flows", "Default"
            },
                                      (int)MatStream.FloatingTableAmountBasis, (sender, e) =>
            {
                MatStream.FloatingTableAmountBasis = (DWSIM.Interfaces.Enums.CompositionBasis)sender.SelectedIndex;
            });
            s.CreateAndAddDescriptionRow(container, "Select the basis to display compound amounts in floating tables, if enabled.");

            s.CreateAndAddLabelRow(container, "Property Package");

            var proppacks = MatStream.GetFlowsheet().PropertyPackages.Values.Select((x) => x.Tag).ToList();

            if (proppacks.Count == 0)
            {
                MatStream.GetFlowsheet().ShowMessage("Error: please add at least one Property Package before continuing.", IFlowsheet.MessageType.GeneralError);
            }
            else
            {
                var selectedpp = MatStream.PropertyPackage.Tag;
                s.CreateAndAddDropDownRow(container, "Property Package", proppacks, proppacks.IndexOf(selectedpp), (DropDown arg1, EventArgs ev) =>
                {
                    MatStream.PropertyPackage = (PropertyPackage)MatStream.GetFlowsheet().PropertyPackages.Values.Where((x) => x.Tag == proppacks[arg1.SelectedIndex]).FirstOrDefault();
                }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                           {
                               ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                           }
                    });
            }

            var flashalgos = MatStream.GetFlowsheet().FlowsheetOptions.FlashAlgorithms.Select(x => x.Tag).ToList();

            flashalgos.Insert(0, "Default");

            var cbFlashAlg = s.CreateAndAddDropDownRow(container, "Flash Algorithm", flashalgos, 0, null);

            if (!string.IsNullOrEmpty(MatStream.PreferredFlashAlgorithmTag))
            {
                cbFlashAlg.SelectedIndex = Array.IndexOf(flashalgos.ToArray(), MatStream.PreferredFlashAlgorithmTag);
            }
            else
            {
                cbFlashAlg.SelectedIndex = 0;
            }

            cbFlashAlg.SelectedIndexChanged += (sender, e) =>
            {
                MatStream.PreferredFlashAlgorithmTag = cbFlashAlg.SelectedValue.ToString();
                if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                {
                    ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                }
            };

            s.CreateAndAddLabelRow(container, "Properties");

            switch (MatStream.GraphicObject.ObjectType)
            {
            case ObjectType.MaterialStream:
                var    ms       = MatStream;
                int    position = 0;
                Double val;
                switch (ms.SpecType)
                {
                case StreamSpec.Temperature_and_Pressure:
                    position = 0;
                    break;

                case StreamSpec.Temperature_and_VaporFraction:
                    position = 1;
                    break;

                case StreamSpec.Pressure_and_VaporFraction:
                    position = 2;
                    break;

                case StreamSpec.Pressure_and_Enthalpy:
                    position = 3;
                    break;

                case StreamSpec.Pressure_and_Entropy:
                    position = 4;
                    break;
                }
                if (ms.GraphicObject.InputConnectors[0].IsAttached &&
                    ms.GraphicObject.InputConnectors[0].AttachedConnector.AttachedFrom.ObjectType != ObjectType.OT_Recycle)
                {
                    s.CreateAndAddDescriptionRow(container, "This Material Stream is connected to another object through its inlet port and cannot be edited.");
                }
                else
                {
                    s.CreateAndAddDropDownRow(container, "Flash Specification", StringResources.flash_spec().ToList(), position, (DropDown arg3, EventArgs ev) =>
                    {
                        switch (arg3.SelectedIndex)
                        {
                        case 0:
                            ms.SpecType = StreamSpec.Temperature_and_Pressure;
                            break;

                        case 1:
                            ms.SpecType = StreamSpec.Temperature_and_VaporFraction;
                            break;

                        case 2:
                            ms.SpecType = StreamSpec.Pressure_and_VaporFraction;
                            break;

                        case 3:
                            ms.SpecType = StreamSpec.Pressure_and_Enthalpy;
                            break;

                        case 4:
                            ms.SpecType = StreamSpec.Pressure_and_Entropy;
                            break;
                        }
                    });
                    s.CreateAndAddDescriptionRow(container, ms.GetPropertyDescription("Flash Specification"));
                    s.CreateAndAddTextBoxRow(container, nf, "Temperature (" + su.temperature + ")", cv.ConvertFromSI(su.temperature, ms.Phases[0].Properties.temperature.GetValueOrDefault()),
                                             (TextBox arg3, EventArgs ev) =>
                    {
                        if (arg3.Text.IsValidDoubleExpression())
                        {
                            arg3.TextColor = (SystemColors.ControlText);
                            ms.Phases[0].Properties.temperature = cv.ConvertToSI(su.temperature, arg3.Text.ToString().ParseExpressionToDouble());
                        }
                        else
                        {
                            arg3.TextColor = (Colors.Red);
                        }
                    }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                               {
                                   ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                               }
                        });
                    s.CreateAndAddDescriptionRow(container, ms.GetPropertyDescription("Temperature"));
                    s.CreateAndAddTextBoxRow(container, nf, "Pressure (" + su.pressure + ")", cv.ConvertFromSI(su.pressure, ms.Phases[0].Properties.pressure.GetValueOrDefault()),
                                             (TextBox arg3, EventArgs ev) =>
                    {
                        if (arg3.Text.IsValidDoubleExpression())
                        {
                            arg3.TextColor = (SystemColors.ControlText);
                            ms.Phases[0].Properties.pressure = cv.ConvertToSI(su.pressure, arg3.Text.ToString().ParseExpressionToDouble());
                        }
                        else
                        {
                            arg3.TextColor = (Colors.Red);
                        }
                    }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                               {
                                   ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                               }
                        });
                    s.CreateAndAddDescriptionRow(container, ms.GetPropertyDescription("Pressure"));
                    var txtW = s.CreateAndAddTextBoxRow(container, nf, "Mass Flow (" + su.massflow + ")", cv.ConvertFromSI(su.massflow, ms.Phases[0].Properties.massflow.GetValueOrDefault()),
                                                        (TextBox arg3, EventArgs ev) =>
                    {
                        if (arg3.Text.IsValidDoubleExpression())
                        {
                            arg3.TextColor = (SystemColors.ControlText);
                            ms.Phases[0].Properties.volumetric_flow = null;
                            ms.Phases[0].Properties.molarflow       = null;
                            ms.Phases[0].Properties.massflow        = cv.ConvertToSI(su.massflow, arg3.Text.ToString().ParseExpressionToDouble());
                        }
                        else
                        {
                            arg3.TextColor = (Colors.Red);
                        }
                    }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                               {
                                   ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                               }
                        });
                    s.CreateAndAddDescriptionRow(container, ms.GetPropertyDescription("Mass Flow"));
                    var txtQ = s.CreateAndAddTextBoxRow(container, nf, "Molar Flow (" + su.molarflow + ")", cv.ConvertFromSI(su.molarflow, ms.Phases[0].Properties.molarflow.GetValueOrDefault()),
                                                        (TextBox arg3, EventArgs ev) =>
                    {
                        if (arg3.Text.IsValidDoubleExpression())
                        {
                            arg3.TextColor = (SystemColors.ControlText);
                            ms.Phases[0].Properties.massflow        = null;
                            ms.Phases[0].Properties.volumetric_flow = null;
                            ms.Phases[0].Properties.molarflow       = cv.ConvertToSI(su.molarflow, arg3.Text.ToString().ParseExpressionToDouble());
                        }
                        else
                        {
                            arg3.TextColor = (Colors.Red);
                        }
                    }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                               {
                                   ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                               }
                        });
                    s.CreateAndAddDescriptionRow(container, ms.GetPropertyDescription("Molar Flow"));
                    s.CreateAndAddTextBoxRow(container, nf, "Volumetric Flow (" + su.volumetricFlow + ")", cv.ConvertFromSI(su.volumetricFlow, ms.Phases[0].Properties.volumetric_flow.GetValueOrDefault()),
                                             (TextBox arg3, EventArgs ev) =>
                    {
                        if (arg3.Text.IsValidDoubleExpression())
                        {
                            arg3.TextColor = (SystemColors.ControlText);
                            ms.Phases[0].Properties.massflow        = null;
                            ms.Phases[0].Properties.molarflow       = null;
                            ms.Phases[0].Properties.volumetric_flow = cv.ConvertToSI(su.volumetricFlow, arg3.Text.ToString().ParseExpressionToDouble());
                        }
                        else
                        {
                            arg3.TextColor = (Colors.Red);
                        }
                    }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                               {
                                   ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                               }
                        });
                    s.CreateAndAddDescriptionRow(container, ms.GetPropertyDescription("Volumetric Flow"));
                    s.CreateAndAddTextBoxRow(container, nf, "Vapor Phase Mole Fraction (spec)", ms.Phases[2].Properties.molarfraction.GetValueOrDefault(),
                                             (TextBox arg3, EventArgs ev) =>
                    {
                        if (arg3.Text.IsValidDoubleExpression())
                        {
                            arg3.TextColor = (SystemColors.ControlText);
                            ms.Phases[2].Properties.molarfraction = arg3.Text.ToString().ParseExpressionToDouble();
                        }
                        else
                        {
                            arg3.TextColor = (Colors.Red);
                        }
                    }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                               {
                                   ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                               }
                        });

                    s.CreateAndAddDescriptionRow(container, ms.GetPropertyDescription("Vapor Phase Mole Fraction (spec)"));
                    s.CreateAndAddTextBoxRow(container, nf, "Specific Enthalpy (" + su.enthalpy + ")", cv.ConvertFromSI(su.enthalpy, ms.Phases[0].Properties.enthalpy.GetValueOrDefault()),
                                             (TextBox arg3, EventArgs ev) =>
                    {
                        if (arg3.Text.IsValidDoubleExpression())
                        {
                            arg3.TextColor = (SystemColors.ControlText);
                            ms.Phases[0].Properties.enthalpy = cv.ConvertToSI(su.enthalpy, arg3.Text.ToString().ParseExpressionToDouble());
                        }
                        else
                        {
                            arg3.TextColor = (Colors.Red);
                        }
                    }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                               {
                                   ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                               }
                        });
                    s.CreateAndAddDescriptionRow(container, ms.GetPropertyDescription("Specific Enthalpy"));
                    s.CreateAndAddTextBoxRow(container, nf, "Specific Entropy (" + su.entropy + ")", cv.ConvertFromSI(su.entropy, ms.Phases[0].Properties.entropy.GetValueOrDefault()),
                                             (TextBox arg3, EventArgs ev) =>
                    {
                        if (arg3.Text.IsValidDoubleExpression())
                        {
                            arg3.TextColor = (SystemColors.ControlText);
                            ms.Phases[0].Properties.entropy = cv.ConvertToSI(su.entropy, arg3.Text.ToString().ParseExpressionToDouble());
                        }
                        else
                        {
                            arg3.TextColor = (Colors.Red);
                        }
                    }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                               {
                                   ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                               }
                        });
                    s.CreateAndAddDescriptionRow(container, ms.GetPropertyDescription("Specific Entropy"));

                    s.CreateAndAddLabelRow(container, "Mixture Composition");

                    s.CreateAndAddDescriptionRow(container, "Composition changes will only be committed after clicking on the 'Accept' button.");

                    DropDown spinner1 = s.CreateAndAddDropDownRow(container, "Amount Basis", StringResources.mscompinputtype().ToList(), 0, null);

                    var tblist = new List <TextBox>();

                    foreach (var comp in ms.Phases[0].Compounds)
                    {
                        var tbox = s.CreateAndAddTextBoxRow(container, nf, comp.Key, comp.Value.MoleFraction.GetValueOrDefault(),
                                                            (TextBox arg3, EventArgs ev) => { });
                        tbox.Tag = comp.Key;
                        tblist.Add(tbox);
                    }

                    spinner1.SelectedIndexChanged += (sender, e) =>
                    {
                        var W = ms.Phases[0].Properties.massflow.GetValueOrDefault();
                        var Q = ms.Phases[0].Properties.molarflow.GetValueOrDefault();
                        switch (spinner1.SelectedIndex)
                        {
                        case 0:
                            foreach (var etext in tblist)
                            {
                                etext.Text = ms.Phases[0].Compounds[(String)etext.Tag].MoleFraction.GetValueOrDefault().ToString(nff);
                            }
                            break;

                        case 1:
                            foreach (var etext in tblist)
                            {
                                etext.Text = ms.Phases[0].Compounds[(String)etext.Tag].MassFraction.GetValueOrDefault().ToString(nff);
                            }
                            break;

                        case 2:
                            foreach (var etext in tblist)
                            {
                                etext.Text = (ms.Phases[0].Compounds[(String)etext.Tag].MoleFraction.GetValueOrDefault() * Q).ToString(nff);
                            }
                            break;

                        case 3:
                            foreach (var etext in tblist)
                            {
                                etext.Text = (ms.Phases[0].Compounds[(String)etext.Tag].MassFraction.GetValueOrDefault() * W).ToString(nff);
                            }
                            break;
                        }
                    };

                    Double total = 0.0f;

                    var btnNormalize = s.CreateAndAddButtonRow(container, "Normalize", null, null);
                    btnNormalize.Font = new Font(SystemFont.Default, s.GetEditorFontSize());

                    btnNormalize.Click += (sender, e) =>
                    {
                        total = 0.0f;
                        foreach (var etext in tblist)
                        {
                            if (Double.TryParse(etext.Text.ToString(), out val))
                            {
                                etext.TextColor = (SystemColors.ControlText);
                                total          += Double.Parse(etext.Text.ToString());
                            }
                            else
                            {
                                etext.TextColor = (Colors.Red);
                                //Toast.MakeText(this.Context, "Error parsing '" + etext.Text + "' for " + (String)etext.Tag + ", not a valid number. Please input a valid number and try again.", ToastLength.Short).Show();
                            }
                        }
                        foreach (var etext in tblist)
                        {
                            if (Double.TryParse(etext.Text.ToString(), out val))
                            {
                                etext.Text = (Double.Parse(etext.Text.ToString()) / total).ToString(nff);
                            }
                        }
                    };

                    var btnEqualize = s.CreateAndAddButtonRow(container, "Equalize", null, null);
                    btnEqualize.Font = new Font(SystemFont.Default, s.GetEditorFontSize());

                    btnEqualize.Click += (sender, e) =>
                    {
                        foreach (var etext in tblist)
                        {
                            etext.Text = (1.0 / tblist.Count).ToString(nff);
                        }
                    };

                    var btnClear = s.CreateAndAddButtonRow(container, "Clear", null, null);
                    btnClear.Font = new Font(SystemFont.Default, s.GetEditorFontSize());

                    btnClear.Click += (sender, e) =>
                    {
                        foreach (var etext in tblist)
                        {
                            etext.Text = 0.0f.ToString(nff);
                        }
                    };

                    var btnAccept = s.CreateAndAddButtonRow(container, "Accept/Update", null, null);
                    btnAccept.Font = new Font(SystemFont.Default, s.GetEditorFontSize());

                    btnAccept.Click += (sender, e) =>
                    {
                        Double W, Q, mtotal = 0.0f, mmtotal = 0.0f;

                        total = 0.0f;

                        switch (spinner1.SelectedIndex)
                        {
                        case 0:

                            btnNormalize.PerformClick();
                            foreach (var etext in tblist)
                            {
                                if (Double.TryParse(etext.Text.ToString(), out val))
                                {
                                    MatStream.Phases[0].Compounds[(String)etext.Tag].MoleFraction = Double.Parse(etext.Text.ToString());
                                }
                                else
                                {
                                    //Toast.MakeText(this.Context, "Error parsing '" + etext.Text + "' for " + (String)etext.Tag + ", not a valid number. Please input a valid number and try again.", ToastLength.Short).Show();
                                }
                            }

                            foreach (var comp in MatStream.Phases[0].Compounds.Values)
                            {
                                mtotal += comp.MoleFraction.GetValueOrDefault() * comp.ConstantProperties.Molar_Weight;
                            }

                            foreach (var comp in MatStream.Phases[0].Compounds.Values)
                            {
                                comp.MassFraction = comp.MoleFraction.GetValueOrDefault() * comp.ConstantProperties.Molar_Weight / mtotal;
                            }

                            break;

                        case 1:

                            btnNormalize.PerformClick();
                            foreach (var etext in tblist)
                            {
                                if (Double.TryParse(etext.Text.ToString(), out val))
                                {
                                    MatStream.Phases[0].Compounds[(String)etext.Tag].MassFraction = Double.Parse(etext.Text.ToString());
                                }
                                else
                                {
                                    //Toast.MakeText(this.Context, "Error parsing '" + etext.Text + "' for " + (String)etext.Tag + ", not a valid number. Please input a valid number and try again.", ToastLength.Short).Show();
                                }
                            }

                            foreach (var comp in MatStream.Phases[0].Compounds.Values)
                            {
                                mmtotal += comp.MassFraction.GetValueOrDefault() / comp.ConstantProperties.Molar_Weight;
                            }

                            foreach (var comp in MatStream.Phases[0].Compounds.Values)
                            {
                                comp.MoleFraction = comp.MassFraction.GetValueOrDefault() / comp.ConstantProperties.Molar_Weight / mmtotal;
                            }

                            break;

                        case 2:

                            total = 0;
                            foreach (var etext in tblist)
                            {
                                if (Double.TryParse(etext.Text.ToString(), out val))
                                {
                                    total += Double.Parse(etext.Text.ToString());
                                }
                                else
                                {
                                    //Toast.MakeText(this.Context, "Error parsing '" + etext.Text + "' for " + (String)etext.Tag + ", not a valid number. Please input a valid number and try again.", ToastLength.Short).Show();
                                }
                            }

                            Q = cv.ConvertToSI(su.molarflow, total);
                            foreach (var etext in tblist)
                            {
                                MatStream.Phases[0].Compounds[(String)etext.Tag].MoleFraction = Double.Parse(etext.Text.ToString()) / total;
                            }

                            foreach (var comp in MatStream.Phases[0].Compounds.Values)
                            {
                                mtotal += comp.MoleFraction.GetValueOrDefault() * comp.ConstantProperties.Molar_Weight;
                            }

                            W = 0;
                            foreach (var comp in MatStream.Phases[0].Compounds.Values)
                            {
                                comp.MassFraction = comp.MoleFraction.GetValueOrDefault() * comp.ConstantProperties.Molar_Weight / mtotal;
                                W += comp.MoleFraction.GetValueOrDefault() * comp.ConstantProperties.Molar_Weight / 1000 * Q;
                            }

                            MatStream.Phases[0].Properties.molarflow = Q;
                            MatStream.Phases[0].Properties.massflow  = W;

                            txtQ.Text = cv.ConvertFromSI(su.molarflow, Q).ToString(nf);

                            break;

                        case 3:

                            total = 0;
                            foreach (var etext in tblist)
                            {
                                if (Double.TryParse(etext.Text.ToString(), out val))
                                {
                                    total += Double.Parse(etext.Text.ToString());
                                }
                                else
                                {
                                    //Toast.MakeText(this.Context, "Error parsing '" + etext.Text + "' for " + (String)etext.Tag + ", not a valid number. Please input a valid number and try again.", ToastLength.Short).Show();
                                }
                            }

                            W = cv.ConvertToSI(su.massflow, total);
                            foreach (var etext in tblist)
                            {
                                MatStream.Phases[0].Compounds[(String)etext.Tag].MassFraction = Double.Parse(etext.Text.ToString()) / total;
                            }

                            foreach (var comp in MatStream.Phases[0].Compounds.Values)
                            {
                                mmtotal += comp.MassFraction.GetValueOrDefault() / comp.ConstantProperties.Molar_Weight;
                            }

                            Q = 0;
                            foreach (var comp in MatStream.Phases[0].Compounds.Values)
                            {
                                comp.MoleFraction = comp.MassFraction.GetValueOrDefault() / comp.ConstantProperties.Molar_Weight / mmtotal;
                                Q += comp.MassFraction.GetValueOrDefault() * W / comp.ConstantProperties.Molar_Weight * 1000;
                            }

                            MatStream.Phases[0].Properties.molarflow = Q;
                            MatStream.Phases[0].Properties.massflow  = W;

                            txtW.Text = cv.ConvertFromSI(su.massflow, W).ToString(nf);

                            break;
                        }

                        if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                        {
                            ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                        }
                    };

                    s.CreateAndAddEmptySpace(container);
                    s.CreateAndAddEmptySpace(container);
                    s.CreateAndAddEmptySpace(container);
                    s.CreateAndAddEmptySpace(container);
                }
                break;
            }
        }
Пример #2
0
        void Initialize()
        {
            var su  = column.GetFlowsheet().FlowsheetOptions.SelectedUnitSystem;
            var nf  = column.GetFlowsheet().FlowsheetOptions.NumberFormat;
            var nff = column.GetFlowsheet().FlowsheetOptions.FractionNumberFormat;

            s.CreateAndAddLabelRow(container, "Object Details");

            s.CreateAndAddTwoLabelsRow(container, "Type", column.GetDisplayName());

            s.CreateAndAddTwoLabelsRow(container, "Status", column.GraphicObject.Active ? "Active" : "Inactive");

            s.CreateAndAddStringEditorRow(container, "Name", column.GraphicObject.Tag, (TextBox arg3, EventArgs ev) =>
            {
                column.GraphicObject.Tag = arg3.Text;
            }, () => CallSolverIfNeeded());

            s.CreateAndAddLabelRow(container, "Property Package");

            var proppacks = column.GetFlowsheet().PropertyPackages.Values.Select((x) => x.Tag).ToList();

            if (proppacks.Count == 0)
            {
                column.GetFlowsheet().ShowMessage("Error: please add at least one Property Package before continuing.", IFlowsheet.MessageType.GeneralError);
            }
            else
            {
                var    pp         = column.PropertyPackage;
                string selectedpp = "";
                if (pp != null)
                {
                    selectedpp = pp.Tag;
                }
                s.CreateAndAddDropDownRow(container, "Property Package", proppacks, proppacks.IndexOf(selectedpp), (DropDown arg1, EventArgs ev) =>
                {
                    column.PropertyPackage = (IPropertyPackage)column.GetFlowsheet().PropertyPackages.Values.Where((x) => x.Tag == proppacks[arg1.SelectedIndex]).FirstOrDefault();
                }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                           {
                               ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                           }
                    });
            }

            var flashalgos = column.GetFlowsheet().FlowsheetOptions.FlashAlgorithms.Select(x => x.Tag).ToList();

            flashalgos.Insert(0, "Default");

            var cbFlashAlg = s.CreateAndAddDropDownRow(container, "Flash Algorithm", flashalgos, 0, null);

            if (!string.IsNullOrEmpty(column.PreferredFlashAlgorithmTag))
            {
                cbFlashAlg.SelectedIndex = Array.IndexOf(flashalgos.ToArray(), column.PreferredFlashAlgorithmTag);
            }
            else
            {
                cbFlashAlg.SelectedIndex = 0;
            }

            cbFlashAlg.SelectedIndexChanged += (sender, e) =>
            {
                column.PreferredFlashAlgorithmTag = cbFlashAlg.SelectedValue.ToString();
                if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                {
                    ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                }
            };

            s.CreateAndAddLabelRow(container, "Object Properties");

            s.CreateAndAddButtonRow(container, "Define Number of Stages", null, (arg1, e) =>
            {
                var np                  = new Eto.Forms.NumericStepper();
                np.MinValue             = 3;
                np.MaxValue             = 100;
                np.MaximumDecimalPlaces = 0;
                np.Value                = column.NumberOfStages;
                np.ValueChanged        += (sender, e2) =>
                {
                    var refval            = (int)np.Value;
                    column.NumberOfStages = refval;
                    int ne, nep, dif, i;
                    ne  = refval;
                    nep = column.Stages.Count;
                    dif = ne - nep;
                    if (dif != 0)
                    {
                        if (dif < 0)
                        {
                            column.Stages.RemoveRange(ne - 1, -dif);
                        }
                        else if (dif > 0)
                        {
                            for (i = 0; i <= dif; i++)
                            {
                                column.Stages.Insert(column.Stages.Count - 1, new Stage(Guid.NewGuid().ToString())
                                {
                                    P = 101325, Efficiency = 1.0f
                                });
                                column.Stages[column.Stages.Count - 2].Name = "Stage " + (column.Stages.Count - 2).ToString();
                            }
                        }
                    }
                };

                s.CreateDialog(np, "Set Number of Stages").ShowModal(container);
            });

            s.CreateAndAddButtonRow(container, "Edit Stages", null, (arg1, e) =>
            {
                var sview = DWSIM.UI.Shared.Common.GetDefaultContainer();

                s.CreateAndAddLabelRow(sview, "Edit Stages");
                s.CreateAndAddLabelRow(sview, "Number / Name / Pressure");
                var tlist = new List <TextBox>();
                foreach (var stage in column.Stages)
                {
                    tlist.Add(s.CreateAndAddDoubleTextBoxRow(sview, nf, (column.Stages.IndexOf(stage) + 1).ToString(), stage.Name, cv.ConvertFromSI(su.pressure, stage.P),
                                                             (arg10, arg20) =>
                    {
                        stage.Name = arg10.Text;
                    }, (arg11, arg22) =>
                    {
                        if (s.IsValidDouble(arg11.Text))
                        {
                            stage.P = cv.ConvertToSI(su.pressure, Double.Parse(arg11.Text));
                        }
                    }));
                }
                s.CreateAndAddLabelAndButtonRow(sview, "Interpolate Pressures", "Interpolate", null, (sender2, e2) => {
                    var first = tlist[0].Text.ToDoubleFromCurrent();
                    var last  = tlist[tlist.Count - 1].Text.ToDoubleFromCurrent();
                    var n     = tlist.Count;
                    int i     = 1;
                    for (i = 1; i < n - 1; i++)
                    {
                        tlist[i].Text = (first + (last - first) * i / (n - 1)).ToString(nf);
                    }
                });
                s.CreateAndAddDescriptionRow(sview, "Calculate inner pressures using end stage defined values.");

                var scroll     = new Eto.Forms.Scrollable();
                scroll.Content = sview;

                s.CreateDialog(scroll, "Edit Stages", 400, 600).ShowModal(container);
            });

            var istrs   = column.GraphicObject.InputConnectors.Where((x) => x.IsAttached && x.ConnectorName.Contains("Feed")).Select((x2) => x2.AttachedConnector.AttachedFrom.Name).ToList();
            var ostrs   = column.GraphicObject.OutputConnectors.Where((x) => x.IsAttached && x.ConnectorName.Contains("Side")).Select((x2) => x2.AttachedConnector.AttachedTo.Name).ToList();
            var dist    = column.GraphicObject.OutputConnectors.Where((x) => x.IsAttached && x.ConnectorName.Contains("Distillate")).Select((x2) => x2.AttachedConnector.AttachedTo.Name).ToList();
            var ov      = column.GraphicObject.OutputConnectors.Where((x) => x.IsAttached && x.ConnectorName.Contains("Overhead")).Select((x2) => x2.AttachedConnector.AttachedTo.Name).ToList();
            var bottoms = column.GraphicObject.OutputConnectors.Where((x) => x.IsAttached && x.ConnectorName.Contains("Bottoms")).Select((x2) => x2.AttachedConnector.AttachedTo.Name).ToList();
            var rduty   = column.GraphicObject.InputConnectors.Where((x) => x.IsAttached && x.ConnectorName.Contains("Reboiler")).Select((x2) => x2.AttachedConnector.AttachedFrom.Name).ToList();
            var cduty   = column.GraphicObject.OutputConnectors.Where((x) => x.IsAttached && x.ConnectorName.Contains("Condenser")).Select((x2) => x2.AttachedConnector.AttachedTo.Name).ToList();

            foreach (var id in istrs)
            {
                if (column.MaterialStreams.Values.Where(x => x.StreamID == id).Count() == 0)
                {
                    column.MaterialStreams.Add(id, new StreamInformation()
                    {
                        StreamID       = id,
                        ID             = id,
                        StreamType     = StreamInformation.Type.Material,
                        StreamBehavior = StreamInformation.Behavior.Feed
                    });
                }
            }
            foreach (var id in ostrs)
            {
                if (column.MaterialStreams.Values.Where(x => x.StreamID == id).Count() == 0)
                {
                    column.MaterialStreams.Add(id, new StreamInformation()
                    {
                        StreamID       = id,
                        ID             = id,
                        StreamType     = StreamInformation.Type.Material,
                        StreamBehavior = StreamInformation.Behavior.Sidedraw
                    });
                }
            }
            foreach (var id in dist)
            {
                if (column.MaterialStreams.Values.Where(x => x.StreamID == id).Count() == 0)
                {
                    column.MaterialStreams.Add(id, new StreamInformation()
                    {
                        StreamID       = id,
                        ID             = id,
                        StreamType     = StreamInformation.Type.Material,
                        StreamBehavior = StreamInformation.Behavior.Distillate
                    });
                }
            }
            foreach (var id in ov)
            {
                if (column.MaterialStreams.Values.Where(x => x.StreamID == id).Count() == 0)
                {
                    column.MaterialStreams.Add(id, new StreamInformation()
                    {
                        StreamID       = id,
                        ID             = id,
                        StreamType     = StreamInformation.Type.Material,
                        StreamBehavior = StreamInformation.Behavior.OverheadVapor
                    });
                }
            }
            foreach (var id in bottoms)
            {
                if (column.MaterialStreams.Values.Where(x => x.StreamID == id).Count() == 0)
                {
                    column.MaterialStreams.Add(id, new StreamInformation()
                    {
                        StreamID       = id,
                        ID             = id,
                        StreamType     = StreamInformation.Type.Material,
                        StreamBehavior = StreamInformation.Behavior.BottomsLiquid
                    });
                }
            }
            List <string> remove = new List <string>();

            foreach (var si in column.MaterialStreams.Values)
            {
                if (!istrs.Contains(si.StreamID) && !ostrs.Contains(si.StreamID) && !ov.Contains(si.StreamID) && !dist.Contains(si.StreamID) && !bottoms.Contains(si.StreamID))
                {
                    remove.Add(si.ID);
                }
                if (!column.GetFlowsheet().SimulationObjects.ContainsKey(si.StreamID))
                {
                    remove.Add(si.ID);
                }
            }
            foreach (var id in remove)
            {
                if (column.MaterialStreams.ContainsKey(id))
                {
                    column.MaterialStreams.Remove(id);
                }
            }

            foreach (var id in cduty)
            {
                if (column.EnergyStreams.Values.Where(x => x.StreamID == id).Count() == 0)
                {
                    column.EnergyStreams.Add(id, new StreamInformation()
                    {
                        StreamID       = id,
                        ID             = id,
                        StreamType     = StreamInformation.Type.Energy,
                        StreamBehavior = StreamInformation.Behavior.Distillate
                    });
                }
            }
            foreach (var id in rduty)
            {
                if (column.EnergyStreams.Values.Where(x => x.StreamID == id).Count() == 0)
                {
                    column.EnergyStreams.Add(id, new StreamInformation()
                    {
                        StreamID       = id,
                        ID             = id,
                        StreamType     = StreamInformation.Type.Energy,
                        StreamBehavior = StreamInformation.Behavior.BottomsLiquid
                    });
                }
            }
            List <string> remove2 = new List <string>();

            foreach (var si in column.EnergyStreams.Values)
            {
                if (!rduty.Contains(si.StreamID) && !cduty.Contains(si.StreamID))
                {
                    remove2.Add(si.ID);
                }
                if (!column.GetFlowsheet().SimulationObjects.ContainsKey(si.StreamID))
                {
                    remove2.Add(si.ID);
                }
            }
            foreach (var id in remove2)
            {
                if (column.EnergyStreams.ContainsKey(id))
                {
                    column.EnergyStreams.Remove(id);
                }
            }

            var stageNames = column.Stages.Select((x) => x.Name).ToList();

            stageNames.Insert(0, "");
            var stageIDs = column.Stages.Select((x) => x.ID).ToList();

            stageIDs.Insert(0, "");

            s.CreateAndAddLabelRow(container, "Streams");

            foreach (var si in column.MaterialStreams.Values)
            {
                if (si.StreamBehavior == StreamInformation.Behavior.Feed)
                {
                    s.CreateAndAddDropDownRow(container, "[FEED] " + column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag,
                                              stageNames, stageIDs.IndexOf(si.AssociatedStage), (arg1, arg2) =>
                    {
                        si.AssociatedStage = stageIDs[arg1.SelectedIndex];
                    });
                }
                else if (si.StreamBehavior == StreamInformation.Behavior.Sidedraw)
                {
                    s.CreateAndAddDropDownRow(container, "[SIDEDRAW] " + column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag,
                                              stageNames, stageIDs.IndexOf(si.AssociatedStage), (arg1, arg2) =>
                    {
                        si.AssociatedStage = stageIDs[arg1.SelectedIndex];
                    });
                }
                else if (si.StreamBehavior == StreamInformation.Behavior.OverheadVapor)
                {
                    s.CreateAndAddDropDownRow(container, "[OVH_VAPOR] " + column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag,
                                              stageNames, stageIDs.IndexOf(si.AssociatedStage), (arg1, arg2) =>
                    {
                        si.AssociatedStage = stageIDs[arg1.SelectedIndex];
                    });
                }
                else if (si.StreamBehavior == StreamInformation.Behavior.Distillate)
                {
                    s.CreateAndAddDropDownRow(container, "[DISTILLATE] " + column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag,
                                              stageNames, stageIDs.IndexOf(si.AssociatedStage), (arg1, arg2) =>
                    {
                        si.AssociatedStage = stageIDs[arg1.SelectedIndex];
                    });
                }
                else if (si.StreamBehavior == StreamInformation.Behavior.BottomsLiquid)
                {
                    s.CreateAndAddDropDownRow(container, "[BOTTOMS] " + column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag,
                                              stageNames, stageIDs.IndexOf(si.AssociatedStage), (arg1, arg2) =>
                    {
                        si.AssociatedStage = stageIDs[arg1.SelectedIndex];
                    });
                }
            }
            foreach (var si in column.EnergyStreams.Values)
            {
                if (si.StreamBehavior == StreamInformation.Behavior.Distillate)
                {
                    s.CreateAndAddDropDownRow(container, "[COND. DUTY] " + column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag,
                                              stageNames, stageIDs.IndexOf(si.AssociatedStage), (arg1, arg2) =>
                    {
                        si.AssociatedStage = stageIDs[arg1.SelectedIndex];
                    });
                }
                else if (si.StreamBehavior == StreamInformation.Behavior.BottomsLiquid)
                {
                    s.CreateAndAddDropDownRow(container, "[REB. DUTY] " + column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag,
                                              stageNames, stageIDs.IndexOf(si.AssociatedStage), (arg1, arg2) =>
                    {
                        si.AssociatedStage = stageIDs[arg1.SelectedIndex];
                    });
                }
            }

            s.CreateAndAddLabelRow(container, "Side Draw Specs");
            var sdphases = new List <string>()
            {
                "L", "V"
            };

            foreach (var si in column.MaterialStreams.Values)
            {
                string sp = "L";
                switch (si.StreamPhase)
                {
                case StreamInformation.Phase.L:
                    sp = "L";
                    break;

                case StreamInformation.Phase.V:
                    sp = "V";
                    break;
                }
                if (si.StreamBehavior == StreamInformation.Behavior.Sidedraw)
                {
                    s.CreateAndAddDropDownRow(container, column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag + " / Draw Phase",
                                              sdphases, sdphases.IndexOf(sp), (arg1, arg2) =>
                    {
                        switch (arg1.SelectedIndex)
                        {
                        case 0:
                            si.StreamPhase = StreamInformation.Phase.L;
                            break;

                        case 1:
                            si.StreamPhase = StreamInformation.Phase.V;
                            break;
                        }
                    });
                    s.CreateAndAddTextBoxRow(container, nf, column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag + " / Molar Flow (" + su.molarflow + ")",
                                             cv.ConvertFromSI(su.molarflow, si.FlowRate.Value), (arg1, arg2) =>
                    {
                        if (s.IsValidDouble(arg1.Text))
                        {
                            si.FlowRate.Value = cv.ConvertToSI(su.molarflow, Double.Parse(arg1.Text));
                        }
                    });
                }
            }

            var compounds = column.GetFlowsheet().SelectedCompounds.Keys.ToList();

            compounds.Insert(0, "");
            var specs = StringResources.columnspec();
            var units = su.GetUnitSet(Interfaces.Enums.UnitOfMeasure.molarflow);

            units.AddRange(su.GetUnitSet(Interfaces.Enums.UnitOfMeasure.massflow));
            units.AddRange(su.GetUnitSet(Interfaces.Enums.UnitOfMeasure.heatflow));
            units.AddRange(su.GetUnitSet(Interfaces.Enums.UnitOfMeasure.temperature));
            units.AddRange(new[] { "% M/M", "% W/W", "M", "We" });
            units.Insert(0, "");
            int cspec = 0, rspec = 0;

            switch (column.Specs["C"].SType)
            {
            case ColumnSpec.SpecType.Product_Molar_Flow_Rate:
                cspec = 0;
                break;

            case ColumnSpec.SpecType.Product_Mass_Flow_Rate:
                cspec = 1;
                break;

            case ColumnSpec.SpecType.Stream_Ratio:
                cspec = 2;
                break;

            case ColumnSpec.SpecType.Heat_Duty:
                cspec = 3;
                break;

            case ColumnSpec.SpecType.Component_Mass_Flow_Rate:
                cspec = 4;
                break;

            case ColumnSpec.SpecType.Component_Molar_Flow_Rate:
                cspec = 5;
                break;

            case ColumnSpec.SpecType.Component_Recovery:
                cspec = 6;
                break;

            case ColumnSpec.SpecType.Component_Fraction:
                cspec = 7;
                break;

            case ColumnSpec.SpecType.Temperature:
                cspec = 8;
                break;
            }

            switch (column.Specs["R"].SType)
            {
            case ColumnSpec.SpecType.Product_Molar_Flow_Rate:
                rspec = 0;
                break;

            case ColumnSpec.SpecType.Product_Mass_Flow_Rate:
                rspec = 1;
                break;

            case ColumnSpec.SpecType.Stream_Ratio:
                rspec = 2;
                break;

            case ColumnSpec.SpecType.Heat_Duty:
                rspec = 3;
                break;

            case ColumnSpec.SpecType.Component_Mass_Flow_Rate:
                rspec = 4;
                break;

            case ColumnSpec.SpecType.Component_Molar_Flow_Rate:
                rspec = 5;
                break;

            case ColumnSpec.SpecType.Component_Recovery:
                rspec = 6;
                break;

            case ColumnSpec.SpecType.Component_Fraction:
                rspec = 7;
                break;

            case ColumnSpec.SpecType.Temperature:
                rspec = 8;
                break;
            }

            s.CreateAndAddLabelRow(container, "Condenser Specification");
            s.CreateAndAddDropDownRow(container, "Specification", specs.ToList(), cspec, (arg1, arg2) =>
            {
                switch (arg1.SelectedIndex)
                {
                case 0:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Product_Molar_Flow_Rate;
                    break;

                case 1:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Product_Mass_Flow_Rate;
                    break;

                case 2:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Stream_Ratio;
                    break;

                case 3:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Heat_Duty;
                    break;

                case 4:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Component_Mass_Flow_Rate;
                    break;

                case 5:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Component_Molar_Flow_Rate;
                    break;

                case 6:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Component_Recovery;
                    break;

                case 7:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Component_Fraction;
                    break;

                case 8:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Temperature;
                    break;
                }
            });
            var cid = 0;

            if (compounds.Contains(column.Specs["C"].ComponentID))
            {
                cid = compounds.IndexOf(column.Specs["C"].ComponentID);
            }
            s.CreateAndAddDropDownRow(container, "Compound", compounds, cid, (arg3, e) =>
            {
                column.Specs["C"].ComponentID = compounds[arg3.SelectedIndex];
            });
            s.CreateAndAddTextBoxRow(container, nf, "Value", column.Specs["C"].SpecValue, (arg1, arg2) =>
            {
                if (s.IsValidDouble(arg1.Text))
                {
                    column.Specs["C"].SpecValue = Double.Parse(arg1.Text);
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });
            s.CreateAndAddDropDownRow(container, "Units", units, units.IndexOf(column.Specs["C"].SpecUnit),
                                      (arg1, arg2) =>
            {
                column.Specs["C"].SpecUnit = units[arg1.SelectedIndex];
            });

            s.CreateAndAddLabelRow(container, "Reboiler Specification");
            s.CreateAndAddDropDownRow(container, "Specification", specs.ToList(), rspec, (arg1, arg2) =>
            {
                switch (arg1.SelectedIndex)
                {
                case 0:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Product_Molar_Flow_Rate;
                    break;

                case 1:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Product_Mass_Flow_Rate;
                    break;

                case 2:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Stream_Ratio;
                    break;

                case 3:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Heat_Duty;
                    break;

                case 4:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Component_Mass_Flow_Rate;
                    break;

                case 5:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Component_Molar_Flow_Rate;
                    break;

                case 6:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Component_Recovery;
                    break;

                case 7:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Component_Fraction;
                    break;

                case 8:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Temperature;
                    break;
                }
            });
            var cid2 = 0;

            if (compounds.Contains(column.Specs["R"].ComponentID))
            {
                cid2 = compounds.IndexOf(column.Specs["R"].ComponentID);
            }
            s.CreateAndAddDropDownRow(container, "Compound", compounds, cid2, (arg3, e) =>
            {
                column.Specs["R"].ComponentID = compounds[arg3.SelectedIndex];
            });
            s.CreateAndAddTextBoxRow(container, nf, "Value", column.Specs["R"].SpecValue, (arg1, arg2) =>
            {
                if (s.IsValidDouble(arg1.Text))
                {
                    column.Specs["R"].SpecValue = Double.Parse(arg1.Text);
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });
            s.CreateAndAddDropDownRow(container, "Units", units, units.IndexOf(column.Specs["R"].SpecUnit),
                                      (arg1, arg2) =>
            {
                column.Specs["R"].SpecUnit = units[arg1.SelectedIndex];
            });

            s.CreateAndAddLabelRow(container, "Column Solver Selection");

            var methods    = new string[] { "Wang-Henke (Bubble Point)", "Naphtali-Sandholm (Newton)", "Russell (Inside-Out)", "Burningham-Otto (Sum Rates) (Absorber Only)" };
            var strategies = new string[] { "Ideal K first, then Rigorous", "Ideal H first, then Rigorous", "Ideal K+H first, then Rigorous", "Direct Rigorous" };

            s.CreateAndAddDropDownRow(container, "Solving Method", methods.ToList(), (int)column.SolvingMethod, (sender, e) =>
            {
                column.SolvingMethod = sender.SelectedIndex;
            });

            s.CreateAndAddDropDownRow(container, "Solving Scheme", strategies.ToList(), (int)column.SolverScheme, (sender, e) =>
            {
                column.SolverScheme = (UnitOperations.UnitOperations.Column.SolvingScheme)sender.SelectedIndex;
            });

            s.CreateAndAddTextBoxRow(container, "N0", "Maximum Iterations", column.MaxIterations,
                                     (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    column.MaxIterations = (int)sender.Text.ToDoubleFromCurrent();
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });

            s.CreateAndAddTextBoxRow(container, nf, "Convergence Tolerance (External Loop)", column.ExternalLoopTolerance,
                                     (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    column.ExternalLoopTolerance = sender.Text.ToDoubleFromCurrent();
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });

            s.CreateAndAddTextBoxRow(container, nf, "Convergence Tolerance (Internal Loop)", column.InternalLoopTolerance,
                                     (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    column.InternalLoopTolerance = sender.Text.ToDoubleFromCurrent();
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });

            s.CreateAndAddTextBoxRow(container, nf, "Maximum Temperature Change Step (" + su.deltaT + ")", cv.ConvertFromSI(su.deltaT, column.MaximumTemperatureStep),
                                     (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    column.MaximumTemperatureStep = cv.ConvertToSI(su.deltaT, sender.Text.ToDoubleFromCurrent());
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });

            s.CreateAndAddLabelRow(container, "Bubble Point Solver Settings");

            s.CreateAndAddTextBoxRow(container, "N0", "Stop at iteration number", column.StopAtIterationNumber,
                                     (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    column.StopAtIterationNumber = (int)sender.Text.ToDoubleFromCurrent();
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });

            s.CreateAndAddLabelRow(container, "Newton Solver Settings");

            var solvers = new List <string>()
            {
                "Limited Memory BGFS", "Truncated Newton", "Simplex", "IPOPT", "Particle Swarm", "Local Unimodal Sampling", "Gradient Descent", "Differential Evolution", "Particle Swarm Optimization", "Many Optimizing Liaisons", "Mesh"
            };

            s.CreateAndAddDropDownRow(container, "Non-Linear Solver", solvers, (int)column.NS_Solver, (sender, e) => column.NS_Solver = (DWSIM.Interfaces.Enums.OptimizationMethod)sender.SelectedIndex);

            s.CreateAndAddTextBoxRow(container, nf, "Iteration Variables: Lower Bound", column.NS_LowerBound, (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    column.NS_LowerBound = (int)sender.Text.ToDoubleFromCurrent();
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });

            s.CreateAndAddTextBoxRow(container, nf, "Iteration Variables: Upper Bound", column.NS_UpperBound, (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    column.NS_UpperBound = (int)sender.Text.ToDoubleFromCurrent();
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });

            s.CreateAndAddTextBoxRow(container, nf, "Iteration Variables: Derivative Perturbation", column.SC_NumericalDerivativeStep, (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    column.SC_NumericalDerivativeStep = (int)sender.Text.ToDoubleFromCurrent();
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });

            s.CreateAndAddCheckBoxRow(container, "Iteration Variables: Simplex Preconditioning", column.NS_SimplexPreconditioning, (sender, e) => column.NS_SimplexPreconditioning = sender.Checked.GetValueOrDefault(), () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                                                                                                                                                                                                                                 {
                                                                                                                                                                                                                                     ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                                                                                                                                                                                                                                 }
                                      });

            s.CreateAndAddLabelRow(container, "Inside-Out Solver Settings");

            s.CreateAndAddDropDownRow(container, "Non-Linear Solver", solvers, (int)column.IO_Solver, (sender, e) => column.IO_Solver = (DWSIM.Interfaces.Enums.OptimizationMethod)sender.SelectedIndex);

            s.CreateAndAddTextBoxRow(container, nf, "Iteration Variables: Lower Bound", column.IO_LowerBound, (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    column.IO_LowerBound = (int)sender.Text.ToDoubleFromCurrent();
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });

            s.CreateAndAddTextBoxRow(container, nf, "Iteration Variables: Upper Bound", column.IO_UpperBound, (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    column.IO_UpperBound = (int)sender.Text.ToDoubleFromCurrent();
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });

            s.CreateAndAddTextBoxRow(container, nf, "Iteration Variables: Derivative Perturbation", column.IO_NumericalDerivativeStep, (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    column.IO_NumericalDerivativeStep = (int)sender.Text.ToDoubleFromCurrent();
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });

            s.CreateAndAddCheckBoxRow(container, "Adjust Sb Scaling Factor", column.AdjustSb, (sender, e) => column.AdjustSb = sender.Checked.GetValueOrDefault(), () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                                                                                                                                                                           {
                                                                                                                                                                               ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                                                                                                                                                                           }
                                      });

            s.CreateAndAddCheckBoxRow(container, "Calculate Kb by Weighted Average", column.KbjWeightedAverage, (sender, e) => column.KbjWeightedAverage = sender.Checked.GetValueOrDefault(), () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                                                                                                                                                                                                       {
                                                                                                                                                                                                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                                                                                                                                                                                                       }
                                      });

            s.CreateAndAddEmptySpace(container);
            s.CreateAndAddEmptySpace(container);
            s.CreateAndAddEmptySpace(container);
        }
Пример #3
0
        void Initialize()
        {
            var su  = MatStream.GetFlowsheet().FlowsheetOptions.SelectedUnitSystem;
            var nf  = MatStream.GetFlowsheet().FlowsheetOptions.NumberFormat;
            var nff = MatStream.GetFlowsheet().FlowsheetOptions.FractionNumberFormat;

            var container2 = new DynamicLayout();

            s.CreateAndAddLabelRow(container, "Material Stream Property Editor");

            s.CreateAndAddDescriptionRow(container, "Except for compound amounts, property values are updated/stored as they are changed/edited.");

            if ((Host.Items.Where(x => x.Name.Contains(MatStream.GraphicObject.Tag)).Count() > 0))
            {
                var ctn = new DynamicLayout();
                ctn.BackgroundColor = Colors.LightGrey;
                s.CreateAndAddLabelRow(ctn, "Inspector Reports");
                s.CreateAndAddLabelAndButtonRow(ctn, "An Inspector Report is ready for viewing.", "View Report", null, (btn, e) =>
                {
                    var f = s.GetDefaultEditorForm("Inspector Report for '" + MatStream.GraphicObject.Tag + "'", 1024, 768, Window2_Eto.GetInspectorWindow(MatStream), false);
                    f.Show();
                });
                container.Add(ctn);
            }

            s.CreateAndAddLabelRow(container, "Material Stream Details");

            s.CreateAndAddTwoLabelsRow(container, "Status", MatStream.GraphicObject.Active ? "Active" : "Inactive");

            s.CreateAndAddStringEditorRow(container, "Name", MatStream.GraphicObject.Tag, (TextBox arg3, EventArgs ev) =>
            {
                MatStream.GraphicObject.Tag = arg3.Text;
                MatStream.GetFlowsheet().UpdateInterface();
            }, () => {
                MatStream.GetFlowsheet().UpdateOpenEditForms();
            });

            s.CreateAndAddDropDownRow(container, "Compound Amount Basis",
                                      new List <string>()
            {
                "Molar Fractions", "Mass Fractions", "Volumetric Fractions", "Molar Flows", "Mass Flows", "Volumetric Flows", "Default"
            },
                                      (int)MatStream.FloatingTableAmountBasis, (sender, e) =>
            {
                MatStream.FloatingTableAmountBasis = (DWSIM.Interfaces.Enums.CompositionBasis)sender.SelectedIndex;
            });
            s.CreateAndAddDescriptionRow(container, "Select the basis to display compound amounts in floating tables, if enabled.");

            s.CreateAndAddLabelRow(container, "Property Package");

            var proppacks = MatStream.GetFlowsheet().PropertyPackages.Values.Select((x) => x.Tag).ToList();

            if (proppacks.Count == 0)
            {
                MatStream.GetFlowsheet().ShowMessage("Error: please add at least one Property Package before continuing.", IFlowsheet.MessageType.GeneralError);
            }
            else
            {
                var selectedpp = MatStream.PropertyPackage.Tag;
                s.CreateAndAddDropDownRow(container, "Property Package", proppacks, proppacks.IndexOf(selectedpp), (DropDown arg1, EventArgs ev) =>
                {
                    if (proppacks.Count > 0)
                    {
                        MatStream.PropertyPackage = (PropertyPackage)MatStream.GetFlowsheet().PropertyPackages.Values.Where((x) => x.Tag == proppacks[arg1.SelectedIndex]).FirstOrDefault();
                    }
                }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                           {
                               ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                           }
                    });
            }

            container.Add(container2);

            s.CreateAndAddLabelRow(container2, "State Specification");

            switch (MatStream.GraphicObject.ObjectType)
            {
            case ObjectType.MaterialStream:
                var    ms       = MatStream;
                int    position = 0;
                Double val;
                switch (ms.SpecType)
                {
                case StreamSpec.Temperature_and_Pressure:
                    position = 0;
                    break;

                case StreamSpec.Temperature_and_VaporFraction:
                    position = 1;
                    break;

                case StreamSpec.Pressure_and_VaporFraction:
                    position = 2;
                    break;

                case StreamSpec.Pressure_and_Enthalpy:
                    position = 3;
                    break;

                case StreamSpec.Pressure_and_Entropy:
                    position = 4;
                    break;
                }

                s.CreateAndAddDropDownRow(container2, "Specified Variables", StringResources.flash_spec().ToList(), position, (DropDown arg3, EventArgs ev) =>
                {
                    switch (arg3.SelectedIndex)
                    {
                    case 0:
                        ms.SpecType = StreamSpec.Temperature_and_Pressure;
                        break;

                    case 1:
                        ms.SpecType = StreamSpec.Temperature_and_VaporFraction;
                        break;

                    case 2:
                        ms.SpecType = StreamSpec.Pressure_and_VaporFraction;
                        break;

                    case 3:
                        ms.SpecType = StreamSpec.Pressure_and_Enthalpy;
                        break;

                    case 4:
                        ms.SpecType = StreamSpec.Pressure_and_Entropy;
                        break;
                    }
                });
                s.CreateAndAddDescriptionRow(container2, ms.GetPropertyDescription("Flash Specification"));
                s.CreateAndAddTextBoxRow(container2, nf, "Temperature (" + su.temperature + ")", cv.ConvertFromSI(su.temperature, ms.Phases[0].Properties.temperature.GetValueOrDefault()),
                                         (TextBox arg3, EventArgs ev) =>
                {
                    if (arg3.Text.IsValidDoubleExpression())
                    {
                        arg3.TextColor = (SystemColors.ControlText);
                        ms.Phases[0].Properties.temperature = cv.ConvertToSI(su.temperature, arg3.Text.ToString().ParseExpressionToDouble());
                    }
                    else
                    {
                        arg3.TextColor = (Colors.Red);
                    }
                }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                           {
                               ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                           }
                    });
                s.CreateAndAddDescriptionRow(container2, ms.GetPropertyDescription("Temperature"));
                var txtP = s.CreateAndAddTextBoxRow(container2, nf, "Pressure (" + su.pressure + ")", cv.ConvertFromSI(su.pressure, ms.Phases[0].Properties.pressure.GetValueOrDefault()),
                                                    (TextBox arg3, EventArgs ev) =>
                {
                    if (arg3.Text.IsValidDoubleExpression())
                    {
                        arg3.TextColor = (SystemColors.ControlText);
                        ms.Phases[0].Properties.pressure = cv.ConvertToSI(su.pressure, arg3.Text.ToString().ParseExpressionToDouble());
                    }
                    else
                    {
                        arg3.TextColor = (Colors.Red);
                    }
                }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                           {
                               ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                           }
                    });
                s.CreateAndAddDescriptionRow(container2, ms.GetPropertyDescription("Pressure"));
                s.CreateAndAddTextBoxRow(container2, nf, "Specific Enthalpy (" + su.enthalpy + ")", cv.ConvertFromSI(su.enthalpy, ms.Phases[0].Properties.enthalpy.GetValueOrDefault()),
                                         (TextBox arg3, EventArgs ev) =>
                {
                    if (arg3.Text.IsValidDoubleExpression())
                    {
                        arg3.TextColor = (SystemColors.ControlText);
                        ms.Phases[0].Properties.enthalpy = cv.ConvertToSI(su.enthalpy, arg3.Text.ToString().ParseExpressionToDouble());
                    }
                    else
                    {
                        arg3.TextColor = (Colors.Red);
                    }
                }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                           {
                               ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                           }
                    });
                s.CreateAndAddDescriptionRow(container2, ms.GetPropertyDescription("Specific Enthalpy"));
                s.CreateAndAddTextBoxRow(container2, nf, "Specific Entropy (" + su.entropy + ")", cv.ConvertFromSI(su.entropy, ms.Phases[0].Properties.entropy.GetValueOrDefault()),
                                         (TextBox arg3, EventArgs ev) =>
                {
                    if (arg3.Text.IsValidDoubleExpression())
                    {
                        arg3.TextColor = (SystemColors.ControlText);
                        ms.Phases[0].Properties.entropy = cv.ConvertToSI(su.entropy, arg3.Text.ToString().ParseExpressionToDouble());
                    }
                    else
                    {
                        arg3.TextColor = (Colors.Red);
                    }
                }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                           {
                               ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                           }
                    });
                s.CreateAndAddDescriptionRow(container2, ms.GetPropertyDescription("Specific Entropy"));

                s.CreateAndAddTextBoxRow(container2, nf, "Vapor Mole Frac (spec)", ms.Phases[2].Properties.molarfraction.GetValueOrDefault(),
                                         (TextBox arg3, EventArgs ev) =>
                {
                    if (arg3.Text.IsValidDoubleExpression())
                    {
                        arg3.TextColor = (SystemColors.ControlText);
                        ms.Phases[2].Properties.molarfraction = arg3.Text.ToString().ParseExpressionToDouble();
                    }
                    else
                    {
                        arg3.TextColor = (Colors.Red);
                    }
                }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                           {
                               ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                           }
                    });

                s.CreateAndAddDescriptionRow(container2, ms.GetPropertyDescription("Vapor Phase Mole Fraction (spec)"));


                int fp = 0;
                switch (MatStream.ForcePhase)
                {
                case Interfaces.Enums.ForcedPhase.GlobalDef:
                    fp = 0;
                    break;

                case Interfaces.Enums.ForcedPhase.Vapor:
                    fp = 1;
                    break;

                case Interfaces.Enums.ForcedPhase.Liquid:
                    fp = 2;
                    break;

                case Interfaces.Enums.ForcedPhase.Solid:
                    fp = 3;
                    break;
                }

                s.CreateAndAddDropDownRow(container2, "Force Phase",
                                          new System.Collections.Generic.List <string> {
                    "Global Definition", "Vapor", "Liquid", "Solid"
                }, fp, (dd, e) => {
                    switch (dd.SelectedIndex)
                    {
                    case 0:
                        MatStream.ForcePhase = Interfaces.Enums.ForcedPhase.GlobalDef;
                        break;

                    case 1:
                        MatStream.ForcePhase = Interfaces.Enums.ForcedPhase.Vapor;
                        break;

                    case 2:
                        MatStream.ForcePhase = Interfaces.Enums.ForcedPhase.Liquid;
                        break;

                    case 3:
                        MatStream.ForcePhase = Interfaces.Enums.ForcedPhase.Solid;
                        break;
                    }
                });

                s.CreateAndAddDescriptionRow(container2, "Forces the fluid in this Material Stream to stay in the specified phase.");

                s.CreateAndAddLabelRow(container2, "Flow Specification");

                var txtW = s.CreateAndAddTextBoxRow(container2, nf, "Mass Flow (" + su.massflow + ")", cv.ConvertFromSI(su.massflow, ms.Phases[0].Properties.massflow.GetValueOrDefault()),
                                                    (TextBox arg3, EventArgs ev) =>
                {
                    if (arg3.Text.IsValidDoubleExpression())
                    {
                        arg3.TextColor = (SystemColors.ControlText);
                        ms.Phases[0].Properties.volumetric_flow = null;
                        ms.Phases[0].Properties.molarflow       = null;
                        ms.Phases[0].Properties.massflow        = cv.ConvertToSI(su.massflow, arg3.Text.ToString().ParseExpressionToDouble());
                        ms.DefinedFlow = FlowSpec.Mass;
                    }
                    else
                    {
                        arg3.TextColor = (Colors.Red);
                    }
                }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                           {
                               ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                           }
                    });
                s.CreateAndAddDescriptionRow(container2, ms.GetPropertyDescription("Mass Flow"));
                var txtQ = s.CreateAndAddTextBoxRow(container2, nf, "Molar Flow (" + su.molarflow + ")", cv.ConvertFromSI(su.molarflow, ms.Phases[0].Properties.molarflow.GetValueOrDefault()),
                                                    (TextBox arg3, EventArgs ev) =>
                {
                    if (arg3.Text.IsValidDoubleExpression())
                    {
                        arg3.TextColor = (SystemColors.ControlText);
                        ms.Phases[0].Properties.massflow        = null;
                        ms.Phases[0].Properties.volumetric_flow = null;
                        ms.Phases[0].Properties.molarflow       = cv.ConvertToSI(su.molarflow, arg3.Text.ToString().ParseExpressionToDouble());
                        ms.DefinedFlow = FlowSpec.Mole;
                    }
                    else
                    {
                        arg3.TextColor = (Colors.Red);
                    }
                }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                           {
                               ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                           }
                    });
                s.CreateAndAddDescriptionRow(container2, ms.GetPropertyDescription("Molar Flow"));
                var txtV = s.CreateAndAddTextBoxRow(container2, nf, "Volumetric Flow (" + su.volumetricFlow + ")", cv.ConvertFromSI(su.volumetricFlow, ms.Phases[0].Properties.volumetric_flow.GetValueOrDefault()),
                                                    (TextBox arg3, EventArgs ev) =>
                {
                    if (arg3.Text.IsValidDoubleExpression())
                    {
                        arg3.TextColor = (SystemColors.ControlText);
                        ms.Phases[0].Properties.massflow        = null;
                        ms.Phases[0].Properties.molarflow       = null;
                        ms.Phases[0].Properties.volumetric_flow = cv.ConvertToSI(su.volumetricFlow, arg3.Text.ToString().ParseExpressionToDouble());
                        ms.DefinedFlow = FlowSpec.Volumetric;
                    }
                    else
                    {
                        arg3.TextColor = (Colors.Red);
                    }
                }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                           {
                               ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                           }
                    });
                s.CreateAndAddDescriptionRow(container2, ms.GetPropertyDescription("Volumetric Flow"));

                switch (MatStream.DefinedFlow)
                {
                case FlowSpec.Mass:
                    txtW.BackgroundColor = Colors.LightBlue;
                    txtW.ToolTip         = "Defined by the user";
                    txtQ.ToolTip         = "Calculated";
                    txtV.ToolTip         = "Calculated";
                    break;

                case FlowSpec.Mole:
                    txtQ.BackgroundColor = Colors.LightBlue;
                    txtW.ToolTip         = "Calculated";
                    txtQ.ToolTip         = "Defined by the user";
                    txtV.ToolTip         = "Calculated";
                    break;

                case FlowSpec.Volumetric:
                    txtV.BackgroundColor = Colors.LightBlue;
                    txtW.ToolTip         = "Calculated";
                    txtQ.ToolTip         = "Calculated";
                    txtV.ToolTip         = "Defined by the user";
                    break;
                }

                s.CreateAndAddLabelRow(container2, "Mixture Composition");

                s.CreateAndAddDescriptionRow(container2, "Composition changes will only be committed after clicking on the 'Accept' button.");

                DropDown spinner1 = s.CreateAndAddDropDownRow(container2, "Amount Basis", StringResources.mscompinputtype().ToList(), 0, null);

                var tblist = new List <TextBox>();

                foreach (var comp0 in ms.GetFlowsheet().SelectedCompounds.Values)
                {
                    var comp = ms.Phases[0].Compounds[comp0.Name];
                    var tbox = s.CreateAndAddTextBoxRow(container2, nf, comp.Name, comp.MoleFraction.GetValueOrDefault(),
                                                        (TextBox arg3, EventArgs ev) => { });
                    tbox.Tag = comp.Name;
                    tblist.Add(tbox);
                }

                spinner1.SelectedIndexChanged += (sender, e) =>
                {
                    var W = ms.Phases[0].Properties.massflow.GetValueOrDefault();
                    var Q = ms.Phases[0].Properties.molarflow.GetValueOrDefault();
                    switch (spinner1.SelectedIndex)
                    {
                    case 0:
                        foreach (var etext in tblist)
                        {
                            etext.Text = ms.Phases[0].Compounds[(String)etext.Tag].MoleFraction.GetValueOrDefault().ToString(nff);
                        }
                        break;

                    case 1:
                        foreach (var etext in tblist)
                        {
                            etext.Text = ms.Phases[0].Compounds[(String)etext.Tag].MassFraction.GetValueOrDefault().ToString(nff);
                        }
                        break;

                    case 2:
                        foreach (var etext in tblist)
                        {
                            etext.Text = (ms.Phases[0].Compounds[(String)etext.Tag].MoleFraction.GetValueOrDefault() * Q).ConvertFromSI(su.molarflow).ToString(nff);
                        }
                        break;

                    case 3:
                        foreach (var etext in tblist)
                        {
                            etext.Text = (ms.Phases[0].Compounds[(String)etext.Tag].MassFraction.GetValueOrDefault() * W).ConvertFromSI(su.massflow).ToString(nff);
                        }
                        break;
                    }
                };

                Double total = 0.0f;

                var btnNormalize = new Button {
                    Text = "Normalize"
                };
                btnNormalize.Font = new Font(SystemFont.Default, s.GetEditorFontSize());

                btnNormalize.Click += (sender, e) =>
                {
                    total = 0.0f;
                    foreach (var etext in tblist)
                    {
                        if (Double.TryParse(etext.Text.ToString(), out val))
                        {
                            etext.TextColor = (SystemColors.ControlText);
                            total          += Double.Parse(etext.Text.ToString());
                        }
                        else
                        {
                            etext.TextColor = (Colors.Red);
                            //Toast.MakeText(this.Context, "Error parsing '" + etext.Text + "' for " + (String)etext.Tag + ", not a valid number. Please input a valid number and try again.", ToastLength.Short).Show();
                        }
                    }
                    foreach (var etext in tblist)
                    {
                        if (Double.TryParse(etext.Text.ToString(), out val))
                        {
                            etext.Text = (Double.Parse(etext.Text.ToString()) / total).ToString(nff);
                        }
                    }
                };

                var btnEqualize = new Button {
                    Text = "Equalize"
                };
                btnEqualize.Font = new Font(SystemFont.Default, s.GetEditorFontSize());

                btnEqualize.Click += (sender, e) =>
                {
                    foreach (var etext in tblist)
                    {
                        etext.Text = (1.0 / tblist.Count).ToString(nff);
                    }
                };

                var btnClear = new Button {
                    Text = "Clear"
                };
                btnClear.Font = new Font(SystemFont.Default, s.GetEditorFontSize());

                btnClear.Click += (sender, e) =>
                {
                    foreach (var etext in tblist)
                    {
                        etext.Text = 0.0f.ToString(nff);
                    }
                };

                var btnAccept = new Button {
                    Text = "Accept/Update"
                };
                btnAccept.Font = new Font(SystemFont.Default, s.GetEditorFontSize());

                btnAccept.Click += (sender, e) =>
                {
                    Double W, Q, mtotal = 0.0f, mmtotal = 0.0f;

                    total = 0.0f;

                    switch (spinner1.SelectedIndex)
                    {
                    case 0:

                        btnNormalize.PerformClick();
                        foreach (var etext in tblist)
                        {
                            if (Double.TryParse(etext.Text.ToString(), out val))
                            {
                                MatStream.Phases[0].Compounds[(String)etext.Tag].MoleFraction = Double.Parse(etext.Text.ToString());
                            }
                            else
                            {
                                //Toast.MakeText(this.Context, "Error parsing '" + etext.Text + "' for " + (String)etext.Tag + ", not a valid number. Please input a valid number and try again.", ToastLength.Short).Show();
                            }
                        }

                        foreach (var comp in MatStream.Phases[0].Compounds.Values)
                        {
                            mtotal += comp.MoleFraction.GetValueOrDefault() * comp.ConstantProperties.Molar_Weight;
                        }

                        foreach (var comp in MatStream.Phases[0].Compounds.Values)
                        {
                            comp.MassFraction = comp.MoleFraction.GetValueOrDefault() * comp.ConstantProperties.Molar_Weight / mtotal;
                        }

                        break;

                    case 1:

                        btnNormalize.PerformClick();
                        foreach (var etext in tblist)
                        {
                            if (Double.TryParse(etext.Text.ToString(), out val))
                            {
                                MatStream.Phases[0].Compounds[(String)etext.Tag].MassFraction = Double.Parse(etext.Text.ToString());
                            }
                            else
                            {
                                //Toast.MakeText(this.Context, "Error parsing '" + etext.Text + "' for " + (String)etext.Tag + ", not a valid number. Please input a valid number and try again.", ToastLength.Short).Show();
                            }
                        }

                        foreach (var comp in MatStream.Phases[0].Compounds.Values)
                        {
                            mmtotal += comp.MassFraction.GetValueOrDefault() / comp.ConstantProperties.Molar_Weight;
                        }

                        foreach (var comp in MatStream.Phases[0].Compounds.Values)
                        {
                            comp.MoleFraction = comp.MassFraction.GetValueOrDefault() / comp.ConstantProperties.Molar_Weight / mmtotal;
                        }

                        break;

                    case 2:

                        total = 0;
                        foreach (var etext in tblist)
                        {
                            if (Double.TryParse(etext.Text.ToString(), out val))
                            {
                                total += Double.Parse(etext.Text.ToString());
                            }
                            else
                            {
                                //Toast.MakeText(this.Context, "Error parsing '" + etext.Text + "' for " + (String)etext.Tag + ", not a valid number. Please input a valid number and try again.", ToastLength.Short).Show();
                            }
                        }

                        Q = cv.ConvertToSI(su.molarflow, total);
                        foreach (var etext in tblist)
                        {
                            MatStream.Phases[0].Compounds[(String)etext.Tag].MoleFraction = Double.Parse(etext.Text.ToString()) / total;
                        }

                        foreach (var comp in MatStream.Phases[0].Compounds.Values)
                        {
                            mtotal += comp.MoleFraction.GetValueOrDefault() * comp.ConstantProperties.Molar_Weight;
                        }

                        W = 0;
                        foreach (var comp in MatStream.Phases[0].Compounds.Values)
                        {
                            comp.MassFraction = comp.MoleFraction.GetValueOrDefault() * comp.ConstantProperties.Molar_Weight / mtotal;
                            W += comp.MoleFraction.GetValueOrDefault() * comp.ConstantProperties.Molar_Weight / 1000 * Q;
                        }

                        MatStream.Phases[0].Properties.molarflow = Q;
                        MatStream.Phases[0].Properties.massflow  = W;

                        txtQ.Text = cv.ConvertFromSI(su.molarflow, Q).ToString(nf);

                        break;

                    case 3:

                        total = 0;
                        foreach (var etext in tblist)
                        {
                            if (Double.TryParse(etext.Text.ToString(), out val))
                            {
                                total += Double.Parse(etext.Text.ToString());
                            }
                            else
                            {
                                //Toast.MakeText(this.Context, "Error parsing '" + etext.Text + "' for " + (String)etext.Tag + ", not a valid number. Please input a valid number and try again.", ToastLength.Short).Show();
                            }
                        }

                        W = cv.ConvertToSI(su.massflow, total);
                        foreach (var etext in tblist)
                        {
                            MatStream.Phases[0].Compounds[(String)etext.Tag].MassFraction = Double.Parse(etext.Text.ToString()) / total;
                        }

                        foreach (var comp in MatStream.Phases[0].Compounds.Values)
                        {
                            mmtotal += comp.MassFraction.GetValueOrDefault() / comp.ConstantProperties.Molar_Weight;
                        }

                        Q = 0;
                        foreach (var comp in MatStream.Phases[0].Compounds.Values)
                        {
                            comp.MoleFraction = comp.MassFraction.GetValueOrDefault() / comp.ConstantProperties.Molar_Weight / mmtotal;
                            Q += comp.MassFraction.GetValueOrDefault() * W / comp.ConstantProperties.Molar_Weight * 1000;
                        }

                        MatStream.Phases[0].Properties.molarflow = Q;
                        MatStream.Phases[0].Properties.massflow  = W;

                        txtW.Text = cv.ConvertFromSI(su.massflow, W).ToString(nf);

                        break;
                    }

                    if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                    {
                        ((Shared.Flowsheet)MatStream.GetFlowsheet()).HighLevelSolve.Invoke();
                    }
                };

                s.CreateAndAddLabelAndTwoButtonsRow(container2, "Copy/Paste", "Copy Data", null, "Paste Data", null,
                                                    (btn1, e1) =>
                {
                    string data = "";
                    foreach (var tb in tblist)
                    {
                        data += tb.Tag.ToString() + "\t" + tb.Text + "\n";
                    }
                    Clipboard.Instance.Text = data;
                },
                                                    (btn2, e2) =>
                {
                    if (Clipboard.Instance.ContainsText)
                    {
                        var textdata = Clipboard.Instance.Text;
                        var data     = textdata.Split(new[] { '\n', '\t', ' ' });
                        int i        = 0;
                        foreach (var line in data)
                        {
                            if (line != " " && line != "\t" && line != "\n" && i < tblist.Count)
                            {
                                tblist[i].Text = line.Trim();
                                i += 1;
                            }
                        }
                    }
                });

                s.CreateAndAddControlRow(container2, btnAccept);
                s.CreateAndAddControlRow(container2, btnNormalize);
                s.CreateAndAddControlRow(container2, btnEqualize);
                s.CreateAndAddControlRow(container2, btnClear);

                s.CreateAndAddEmptySpace(container2);
                s.CreateAndAddEmptySpace(container2);
                s.CreateAndAddEmptySpace(container2);
                s.CreateAndAddEmptySpace(container2);

                if (ms.GraphicObject.InputConnectors[0].IsAttached &&
                    ms.GraphicObject.InputConnectors[0].AttachedConnector.AttachedFrom.ObjectType != ObjectType.OT_Recycle)
                {
                    if (!ms.GetFlowsheet().DynamicMode)
                    {
                        container2.Enabled = false;
                    }
                }
                break;
            }
        }
Пример #4
0
        void Initialize()
        {
            var su  = column.GetFlowsheet().FlowsheetOptions.SelectedUnitSystem;
            var nf  = column.GetFlowsheet().FlowsheetOptions.NumberFormat;
            var nff = column.GetFlowsheet().FlowsheetOptions.FractionNumberFormat;

            s.CreateAndAddLabelRow(container, "Distillation Column Editor");

            s.CreateAndAddDescriptionRow(container, "Property values are updated/stored as they are changed/edited. There's no need to press ENTER to commit the changes.");

            if ((Inspector.Host.Items.Where(x => x.Name.Contains(column.GraphicObject.Tag)).Count() > 0))
            {
                var ctn = new DynamicLayout();
                ctn.BackgroundColor = Colors.LightGrey;
                s.CreateAndAddLabelRow(ctn, "Inspector Reports");
                s.CreateAndAddLabelAndButtonRow(ctn, "An Inspector Report is ready for viewing.", "View Report", null, (btn, e) => {
                    var f = s.GetDefaultEditorForm("Inspector Report for '" + column.GraphicObject.Tag + "'", 1024, 768, Inspector.Window2_Eto.GetInspectorWindow(column), false);
                    f.Show();
                });
                container.Add(ctn);
            }

            s.CreateAndAddLabelRow(container, "Column Details");

            s.CreateAndAddTwoLabelsRow(container, "Type", column.GetDisplayName());

            s.CreateAndAddTwoLabelsRow(container, "Status", column.GraphicObject.Active ? "Active" : "Inactive");

            s.CreateAndAddStringEditorRow(container, "Name", column.GraphicObject.Tag, (TextBox arg3, EventArgs ev) =>
            {
                column.GraphicObject.Tag = arg3.Text;
                column.GetFlowsheet().UpdateInterface();
            }, () => {
                column.GetFlowsheet().UpdateOpenEditForms();
            });

            s.CreateAndAddLabelRow(container, "Property Package");

            var proppacks = column.GetFlowsheet().PropertyPackages.Values.Select((x) => x.Tag).ToList();

            if (proppacks.Count == 0)
            {
                column.GetFlowsheet().ShowMessage("Error: please add at least one Property Package before continuing.", IFlowsheet.MessageType.GeneralError);
            }
            else
            {
                var    pp         = column.PropertyPackage;
                string selectedpp = "";
                if (pp != null)
                {
                    selectedpp = pp.Tag;
                }
                s.CreateAndAddDropDownRow(container, "Property Package", proppacks, proppacks.IndexOf(selectedpp), (DropDown arg1, EventArgs ev) =>
                {
                    if (proppacks.Count > 0)
                    {
                        column.PropertyPackage = (IPropertyPackage)column.GetFlowsheet().PropertyPackages.Values.Where((x) => x.Tag == proppacks[arg1.SelectedIndex]).FirstOrDefault();
                    }
                }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                           {
                               ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                           }
                    });
            }

            s.CreateAndAddLabelRow(container, "Object Properties");

            s.CreateAndAddButtonRow(container, "Define Number of Stages", null, (arg1, e) =>
            {
                var np                  = new Eto.Forms.NumericStepper();
                np.MinValue             = 3;
                np.MaxValue             = 100;
                np.MaximumDecimalPlaces = 0;
                np.Value                = column.NumberOfStages;
                np.ValueChanged        += (sender, e2) =>
                {
                    var refval            = (int)np.Value;
                    column.NumberOfStages = refval;
                    int ne, nep, dif, i;
                    ne  = refval;
                    nep = column.Stages.Count;
                    dif = ne - nep;
                    if (dif != 0)
                    {
                        if (dif < 0)
                        {
                            column.Stages.RemoveRange(ne - 1, -dif);
                        }
                        else if (dif > 0)
                        {
                            for (i = 0; i <= dif; i++)
                            {
                                column.Stages.Insert(column.Stages.Count - 1, new Stage(Guid.NewGuid().ToString())
                                {
                                    P = 101325, Efficiency = 1.0f
                                });
                                column.Stages[column.Stages.Count - 2].Name = "Stage " + (column.Stages.Count - 2).ToString();
                            }
                        }
                    }
                };

                s.CreateDialog(np, "Set Number of Stages").ShowModal(container);
            });

            s.CreateAndAddButtonRow(container, "Edit Stages", null, (arg1, e) =>
            {
                var sview = DWSIM.UI.Shared.Common.GetDefaultContainer();

                s.CreateAndAddLabelRow(sview, "Edit Stages");
                s.CreateAndAddLabelRow(sview, "Number / Name / Pressure");
                var tlist = new List <TextBox>();
                foreach (var stage in column.Stages)
                {
                    tlist.Add(s.CreateAndAddDoubleTextBoxRow(sview, nf, (column.Stages.IndexOf(stage) + 1).ToString(), stage.Name, cv.ConvertFromSI(su.pressure, stage.P),
                                                             (arg10, arg20) =>
                    {
                        stage.Name = arg10.Text;
                    }, (arg11, arg22) =>
                    {
                        if (s.IsValidDouble(arg11.Text))
                        {
                            stage.P = cv.ConvertToSI(su.pressure, Double.Parse(arg11.Text));
                            if (column.Stages.IndexOf(stage) == 0)
                            {
                                column.CondenserPressure = stage.P;
                            }
                            else if (column.Stages.IndexOf(stage) == column.Stages.Count - 1)
                            {
                                column.ReboilerPressure = stage.P;
                            }
                        }
                    }));
                }
                s.CreateAndAddLabelAndButtonRow(sview, "Interpolate Pressures", "Interpolate", null, (sender2, e2) => {
                    var first = tlist[0].Text.ToDoubleFromCurrent();
                    var last  = tlist[tlist.Count - 1].Text.ToDoubleFromCurrent();
                    var n     = tlist.Count;
                    int i     = 1;
                    for (i = 1; i < n - 1; i++)
                    {
                        tlist[i].Text = (first + (last - first) * i / (n - 1)).ToString(nf);
                    }
                });
                s.CreateAndAddDescriptionRow(sview, "Calculate inner pressures using end stage defined values.");

                var scroll     = new Eto.Forms.Scrollable();
                scroll.Content = sview;

                s.CreateDialog(scroll, "Edit Stages", 600, 600).ShowModal(container);
            });

            var istrs   = column.GraphicObject.InputConnectors.Where((x) => x.IsAttached && x.ConnectorName.Contains("Feed")).Select((x2) => x2.AttachedConnector.AttachedFrom.Name).ToList();
            var ostrs   = column.GraphicObject.OutputConnectors.Where((x) => x.IsAttached && x.ConnectorName.Contains("Side")).Select((x2) => x2.AttachedConnector.AttachedTo.Name).ToList();
            var dist    = column.GraphicObject.OutputConnectors.Where((x) => x.IsAttached && x.ConnectorName.Contains("Distillate")).Select((x2) => x2.AttachedConnector.AttachedTo.Name).ToList();
            var ov      = column.GraphicObject.OutputConnectors.Where((x) => x.IsAttached && x.ConnectorName.Contains("Overhead")).Select((x2) => x2.AttachedConnector.AttachedTo.Name).ToList();
            var bottoms = column.GraphicObject.OutputConnectors.Where((x) => x.IsAttached && x.ConnectorName.Contains("Bottoms")).Select((x2) => x2.AttachedConnector.AttachedTo.Name).ToList();
            var rduty   = column.GraphicObject.InputConnectors.Where((x) => x.IsAttached && x.ConnectorName.Contains("Reboiler")).Select((x2) => x2.AttachedConnector.AttachedFrom.Name).ToList();
            var cduty   = column.GraphicObject.OutputConnectors.Where((x) => x.IsAttached && x.ConnectorName.Contains("Condenser")).Select((x2) => x2.AttachedConnector.AttachedTo.Name).ToList();

            foreach (var id in istrs)
            {
                if (column.MaterialStreams.Values.Where(x => x.StreamID == id).Count() == 0)
                {
                    column.MaterialStreams.Add(id, new StreamInformation()
                    {
                        StreamID       = id,
                        ID             = id,
                        StreamType     = StreamInformation.Type.Material,
                        StreamBehavior = StreamInformation.Behavior.Feed
                    });
                }
            }
            foreach (var id in ostrs)
            {
                if (column.MaterialStreams.Values.Where(x => x.StreamID == id).Count() == 0)
                {
                    column.MaterialStreams.Add(id, new StreamInformation()
                    {
                        StreamID       = id,
                        ID             = id,
                        StreamType     = StreamInformation.Type.Material,
                        StreamBehavior = StreamInformation.Behavior.Sidedraw
                    });
                }
            }
            foreach (var id in dist)
            {
                if (column.MaterialStreams.Values.Where(x => x.StreamID == id).Count() == 0)
                {
                    column.MaterialStreams.Add(id, new StreamInformation()
                    {
                        StreamID       = id,
                        ID             = id,
                        StreamType     = StreamInformation.Type.Material,
                        StreamBehavior = StreamInformation.Behavior.Distillate
                    });
                }
            }
            foreach (var id in ov)
            {
                if (column.MaterialStreams.Values.Where(x => x.StreamID == id).Count() == 0)
                {
                    column.MaterialStreams.Add(id, new StreamInformation()
                    {
                        StreamID       = id,
                        ID             = id,
                        StreamType     = StreamInformation.Type.Material,
                        StreamBehavior = StreamInformation.Behavior.OverheadVapor
                    });
                }
            }
            foreach (var id in bottoms)
            {
                if (column.MaterialStreams.Values.Where(x => x.StreamID == id).Count() == 0)
                {
                    column.MaterialStreams.Add(id, new StreamInformation()
                    {
                        StreamID       = id,
                        ID             = id,
                        StreamType     = StreamInformation.Type.Material,
                        StreamBehavior = StreamInformation.Behavior.BottomsLiquid
                    });
                }
            }
            List <string> remove = new List <string>();

            foreach (var si in column.MaterialStreams.Values)
            {
                if (!istrs.Contains(si.StreamID) && !ostrs.Contains(si.StreamID) && !ov.Contains(si.StreamID) && !dist.Contains(si.StreamID) && !bottoms.Contains(si.StreamID))
                {
                    remove.Add(si.ID);
                }
                if (!column.GetFlowsheet().SimulationObjects.ContainsKey(si.StreamID))
                {
                    remove.Add(si.ID);
                }
            }
            foreach (var id in remove)
            {
                if (column.MaterialStreams.ContainsKey(id))
                {
                    column.MaterialStreams.Remove(id);
                }
            }

            foreach (var id in cduty)
            {
                if (column.EnergyStreams.Values.Where(x => x.StreamID == id).Count() == 0)
                {
                    column.EnergyStreams.Add(id, new StreamInformation()
                    {
                        StreamID       = id,
                        ID             = id,
                        StreamType     = StreamInformation.Type.Energy,
                        StreamBehavior = StreamInformation.Behavior.Distillate
                    });
                }
            }
            foreach (var id in rduty)
            {
                if (column.EnergyStreams.Values.Where(x => x.StreamID == id).Count() == 0)
                {
                    column.EnergyStreams.Add(id, new StreamInformation()
                    {
                        StreamID       = id,
                        ID             = id,
                        StreamType     = StreamInformation.Type.Energy,
                        StreamBehavior = StreamInformation.Behavior.BottomsLiquid
                    });
                }
            }
            List <string> remove2 = new List <string>();

            foreach (var si in column.EnergyStreams.Values)
            {
                if (!rduty.Contains(si.StreamID) && !cduty.Contains(si.StreamID))
                {
                    remove2.Add(si.ID);
                }
                if (!column.GetFlowsheet().SimulationObjects.ContainsKey(si.StreamID))
                {
                    remove2.Add(si.ID);
                }
            }
            foreach (var id in remove2)
            {
                if (column.EnergyStreams.ContainsKey(id))
                {
                    column.EnergyStreams.Remove(id);
                }
            }

            var stageNames = column.Stages.Select((x) => x.Name).ToList();

            stageNames.Insert(0, "");
            var stageIDs = column.Stages.Select((x) => x.ID).ToList();

            stageIDs.Insert(0, "");

            s.CreateAndAddLabelRow(container, "Streams");

            foreach (var si in column.MaterialStreams.Values)
            {
                if (si.StreamBehavior == StreamInformation.Behavior.Feed)
                {
                    s.CreateAndAddDropDownRow(container, "[FEED] " + column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag,
                                              stageNames, stageIDs.IndexOf(si.AssociatedStage), (arg1, arg2) =>
                    {
                        si.AssociatedStage = stageIDs[arg1.SelectedIndex];
                    });
                }
                else if (si.StreamBehavior == StreamInformation.Behavior.Sidedraw)
                {
                    s.CreateAndAddDropDownRow(container, "[SIDEDRAW] " + column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag,
                                              stageNames, stageIDs.IndexOf(si.AssociatedStage), (arg1, arg2) =>
                    {
                        si.AssociatedStage = stageIDs[arg1.SelectedIndex];
                    });
                }
                else if (si.StreamBehavior == StreamInformation.Behavior.OverheadVapor)
                {
                    s.CreateAndAddDropDownRow(container, "[OVH_VAPOR] " + column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag,
                                              stageNames, stageIDs.IndexOf(si.AssociatedStage), (arg1, arg2) =>
                    {
                        si.AssociatedStage = stageIDs[arg1.SelectedIndex];
                    });
                }
                else if (si.StreamBehavior == StreamInformation.Behavior.Distillate)
                {
                    s.CreateAndAddDropDownRow(container, "[DISTILLATE] " + column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag,
                                              stageNames, stageIDs.IndexOf(si.AssociatedStage), (arg1, arg2) =>
                    {
                        si.AssociatedStage = stageIDs[arg1.SelectedIndex];
                    });
                }
                else if (si.StreamBehavior == StreamInformation.Behavior.BottomsLiquid)
                {
                    s.CreateAndAddDropDownRow(container, "[BOTTOMS] " + column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag,
                                              stageNames, stageIDs.IndexOf(si.AssociatedStage), (arg1, arg2) =>
                    {
                        si.AssociatedStage = stageIDs[arg1.SelectedIndex];
                    });
                }
            }
            foreach (var si in column.EnergyStreams.Values)
            {
                if (si.StreamBehavior == StreamInformation.Behavior.Distillate)
                {
                    s.CreateAndAddDropDownRow(container, "[COND. DUTY] " + column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag,
                                              stageNames, stageIDs.IndexOf(si.AssociatedStage), (arg1, arg2) =>
                    {
                        si.AssociatedStage = stageIDs[arg1.SelectedIndex];
                    });
                }
                else if (si.StreamBehavior == StreamInformation.Behavior.BottomsLiquid)
                {
                    s.CreateAndAddDropDownRow(container, "[REB. DUTY] " + column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag,
                                              stageNames, stageIDs.IndexOf(si.AssociatedStage), (arg1, arg2) =>
                    {
                        si.AssociatedStage = stageIDs[arg1.SelectedIndex];
                    });
                }
            }

            s.CreateAndAddLabelRow(container, "Side Draw Specs");
            var sdphases = new List <string>()
            {
                "L", "V"
            };

            foreach (var si in column.MaterialStreams.Values)
            {
                string sp = "L";
                switch (si.StreamPhase)
                {
                case StreamInformation.Phase.L:
                    sp = "L";
                    break;

                case StreamInformation.Phase.V:
                    sp = "V";
                    break;

                case StreamInformation.Phase.B:
                case StreamInformation.Phase.None:
                    sp = "L";
                    break;
                }
                if (si.StreamBehavior == StreamInformation.Behavior.Sidedraw)
                {
                    s.CreateAndAddDropDownRow(container, column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag + " / Draw Phase",
                                              sdphases, sdphases.IndexOf(sp), (arg1, arg2) =>
                    {
                        switch (arg1.SelectedIndex)
                        {
                        case 0:
                            si.StreamPhase = StreamInformation.Phase.L;
                            break;

                        case 1:
                            si.StreamPhase = StreamInformation.Phase.V;
                            break;
                        }
                    });
                    s.CreateAndAddTextBoxRow(container, nf, column.GetFlowsheet().SimulationObjects[si.StreamID].GraphicObject.Tag + " / Molar Flow (" + su.molarflow + ")",
                                             cv.ConvertFromSI(su.molarflow, si.FlowRate.Value), (arg1, arg2) =>
                    {
                        if (s.IsValidDouble(arg1.Text))
                        {
                            si.FlowRate.Value = cv.ConvertToSI(su.molarflow, Double.Parse(arg1.Text));
                        }
                    });
                }
            }

            var compounds = column.GetFlowsheet().SelectedCompounds.Keys.ToList();

            compounds.Insert(0, "");
            var specs = StringResources.columnspec();
            var units = su.GetUnitSet(Interfaces.Enums.UnitOfMeasure.molarflow);

            units.AddRange(su.GetUnitSet(Interfaces.Enums.UnitOfMeasure.massflow));
            units.AddRange(su.GetUnitSet(Interfaces.Enums.UnitOfMeasure.heatflow));
            units.AddRange(su.GetUnitSet(Interfaces.Enums.UnitOfMeasure.temperature));
            units.AddRange(new[] { "% M/M", "% W/W", "M", "We" });
            units.Insert(0, "");
            int cspec = 0, rspec = 0;

            switch (column.Specs["C"].SType)
            {
            case ColumnSpec.SpecType.Product_Molar_Flow_Rate:
                cspec = 0;
                break;

            case ColumnSpec.SpecType.Product_Mass_Flow_Rate:
                cspec = 1;
                break;

            case ColumnSpec.SpecType.Stream_Ratio:
                cspec = 2;
                break;

            case ColumnSpec.SpecType.Heat_Duty:
                cspec = 3;
                break;

            case ColumnSpec.SpecType.Component_Mass_Flow_Rate:
                cspec = 4;
                break;

            case ColumnSpec.SpecType.Component_Molar_Flow_Rate:
                cspec = 5;
                break;

            case ColumnSpec.SpecType.Component_Recovery:
                cspec = 6;
                break;

            case ColumnSpec.SpecType.Component_Fraction:
                cspec = 7;
                break;

            case ColumnSpec.SpecType.Temperature:
                cspec = 8;
                break;
            }

            switch (column.Specs["R"].SType)
            {
            case ColumnSpec.SpecType.Product_Molar_Flow_Rate:
                rspec = 0;
                break;

            case ColumnSpec.SpecType.Product_Mass_Flow_Rate:
                rspec = 1;
                break;

            case ColumnSpec.SpecType.Stream_Ratio:
                rspec = 2;
                break;

            case ColumnSpec.SpecType.Heat_Duty:
                rspec = 3;
                break;

            case ColumnSpec.SpecType.Component_Mass_Flow_Rate:
                rspec = 4;
                break;

            case ColumnSpec.SpecType.Component_Molar_Flow_Rate:
                rspec = 5;
                break;

            case ColumnSpec.SpecType.Component_Recovery:
                rspec = 6;
                break;

            case ColumnSpec.SpecType.Component_Fraction:
                rspec = 7;
                break;

            case ColumnSpec.SpecType.Temperature:
                rspec = 8;
                break;
            }

            s.CreateAndAddLabelRow(container, "Condenser Specification");
            s.CreateAndAddDropDownRow(container, "Specification", specs.ToList(), cspec, (arg1, arg2) =>
            {
                switch (arg1.SelectedIndex)
                {
                case 0:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Product_Molar_Flow_Rate;
                    break;

                case 1:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Product_Mass_Flow_Rate;
                    break;

                case 2:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Stream_Ratio;
                    break;

                case 3:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Heat_Duty;
                    break;

                case 4:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Component_Mass_Flow_Rate;
                    break;

                case 5:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Component_Molar_Flow_Rate;
                    break;

                case 6:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Component_Recovery;
                    break;

                case 7:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Component_Fraction;
                    break;

                case 8:
                    column.Specs["C"].SType = ColumnSpec.SpecType.Temperature;
                    break;
                }
            });
            var cid = 0;

            if (compounds.Contains(column.Specs["C"].ComponentID))
            {
                cid = compounds.IndexOf(column.Specs["C"].ComponentID);
            }
            s.CreateAndAddDropDownRow(container, "Compound", compounds, cid, (arg3, e) =>
            {
                column.Specs["C"].ComponentID = compounds[arg3.SelectedIndex];
            });
            s.CreateAndAddTextBoxRow(container, nf, "Value", column.Specs["C"].SpecValue, (arg1, arg2) =>
            {
                if (s.IsValidDouble(arg1.Text))
                {
                    column.Specs["C"].SpecValue = Double.Parse(arg1.Text);
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });
            s.CreateAndAddDropDownRow(container, "Units", units, units.IndexOf(column.Specs["C"].SpecUnit),
                                      (arg1, arg2) =>
            {
                column.Specs["C"].SpecUnit = units[arg1.SelectedIndex];
            });

            s.CreateAndAddLabelRow(container, "Reboiler Specification");
            s.CreateAndAddDropDownRow(container, "Specification", specs.ToList(), rspec, (arg1, arg2) =>
            {
                switch (arg1.SelectedIndex)
                {
                case 0:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Product_Molar_Flow_Rate;
                    break;

                case 1:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Product_Mass_Flow_Rate;
                    break;

                case 2:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Stream_Ratio;
                    break;

                case 3:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Heat_Duty;
                    break;

                case 4:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Component_Mass_Flow_Rate;
                    break;

                case 5:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Component_Molar_Flow_Rate;
                    break;

                case 6:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Component_Recovery;
                    break;

                case 7:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Component_Fraction;
                    break;

                case 8:
                    column.Specs["R"].SType = ColumnSpec.SpecType.Temperature;
                    break;
                }
            });
            var cid2 = 0;

            if (compounds.Contains(column.Specs["R"].ComponentID))
            {
                cid2 = compounds.IndexOf(column.Specs["R"].ComponentID);
            }
            s.CreateAndAddDropDownRow(container, "Compound", compounds, cid2, (arg3, e) =>
            {
                column.Specs["R"].ComponentID = compounds[arg3.SelectedIndex];
            });
            s.CreateAndAddTextBoxRow(container, nf, "Value", column.Specs["R"].SpecValue, (arg1, arg2) =>
            {
                if (s.IsValidDouble(arg1.Text))
                {
                    column.Specs["R"].SpecValue = Double.Parse(arg1.Text);
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });
            s.CreateAndAddDropDownRow(container, "Units", units, units.IndexOf(column.Specs["R"].SpecUnit),
                                      (arg1, arg2) =>
            {
                column.Specs["R"].SpecUnit = units[arg1.SelectedIndex];
            });

            s.CreateAndAddTextBoxRow(container, "N0", "Maximum Iterations", column.MaxIterations,
                                     (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    column.MaxIterations = (int)sender.Text.ToDoubleFromCurrent();
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });

            s.CreateAndAddTextBoxRow(container, nf, "Convergence Tolerance (External Loop)", column.ExternalLoopTolerance,
                                     (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    column.ExternalLoopTolerance = sender.Text.ToDoubleFromCurrent();
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });

            s.CreateAndAddTextBoxRow(container, nf, "Convergence Tolerance (Internal Loop)", column.InternalLoopTolerance,
                                     (sender, e) =>
            {
                if (sender.Text.IsValidDouble())
                {
                    column.InternalLoopTolerance = sender.Text.ToDoubleFromCurrent();
                }
            }, () => { if (GlobalSettings.Settings.CallSolverOnEditorPropertyChanged)
                       {
                           ((Shared.Flowsheet)column.GetFlowsheet()).HighLevelSolve.Invoke();
                       }
                });

            s.CreateAndAddEmptySpace(container);
            s.CreateAndAddEmptySpace(container);
            s.CreateAndAddEmptySpace(container);
        }