public void AddingItemShouldSetChildrenAndParent() { TestBase.Invoke(() => { var layout = new DynamicLayout(); var items = new Control[] { new Label { ID = "label" }, new Button(), new TextBox() }; foreach (var item in items) { layout.Add(item); } CollectionAssert.AreEqual(items, layout.Children, "#1. Items do not match"); foreach (var item in items) { Assert.AreEqual(layout, item.Parent, "#2. Items should have parent set to dynamic layout"); } Assert.AreSame(layout.FindChild <Label>("label"), items[0], "#3. FindChild should work without loading the dynamic layout"); layout.Clear(); foreach (var item in items) { Assert.IsNull(item.Parent, "#4. Items should have parent removed when removed from dynamic layout"); } }); }
public void AddingItemMultipleLevelsDeepShouldSetChildrenAndParent() { TestBase.Invoke(() => { var layout = new DynamicLayout(); var items = new List <Control>(); layout.BeginHorizontal(); Control ctl = new Button(); items.Add(ctl); layout.Add(ctl); layout.BeginVertical(); ctl = new Label(); items.Add(ctl); layout.Add(ctl); layout.EndVertical(); layout.EndHorizontal(); ctl = new TextBox(); items.Add(ctl); layout.Add(ctl); CollectionAssert.AreEqual(items, layout.Children, "#1. Items do not match"); foreach (var item in items) { Assert.AreEqual(layout, item.Parent, "#2. Items should have parent set to dynamic layout"); } layout.Clear(); foreach (var item in items) { Assert.IsNull(item.Parent, "#3. Items should have parent removed when removed from dynamic layout"); } }); }
private void CreateReactionsList() { rxcontainer.RemoveAll(); rxcontainer.Clear(); foreach (var rx in flowsheet.Reactions.Values) { string rname = ""; switch (rx.ReactionType) { case Interfaces.Enums.ReactionType.Conversion: rname = "[CON] " + rx.Name; break; case Interfaces.Enums.ReactionType.Equilibrium: rname = "[EQL] " + rx.Name; break; case Interfaces.Enums.ReactionType.Kinetic: rname = "[KIN] " + rx.Name; break; case Interfaces.Enums.ReactionType.Heterogeneous_Catalytic: rname = "[HET] " + rx.Name; break; } rxcontainer.CreateAndAddLabelAndTwoButtonsRow(rname, "Edit", null, "Remove", null, (sender, e) => { switch (rx.ReactionType) { case Interfaces.Enums.ReactionType.Conversion: var myview = s.GetDefaultContainer(); var cre = new ConversionReaction(flowsheet, rx, myview); Form alert = null; myview.CreateAndAddTwoButtonsRow("Cancel", null, "Update", null, (sender2, e2) => alert.Close(), (sender2, e2) => { flowsheet.Reactions[cre.rx.ID] = (IReaction)cre.rx; CreateReactionsList(); alert.Close(); }); alert = s.GetDefaultEditorForm("Edit Conversion Reaction", 500, 400, myview); alert.Shown += (s1, e1) => { myview.Invalidate(); alert.Height = myview.Height + 40; }; alert.Topmost = true; alert.Show(); break; case Interfaces.Enums.ReactionType.Equilibrium: var myview2 = s.GetDefaultContainer(); var cre2 = new EquilibriumReaction(flowsheet, rx, myview2); Form alert2 = null; myview2.CreateAndAddTwoButtonsRow("Cancel", null, "Update", null, (sender2, e2) => alert2.Close(), (sender2, e2) => { flowsheet.Reactions[cre2.rx.ID] = (IReaction)cre2.rx; CreateReactionsList(); alert2.Close(); }); alert2 = s.GetDefaultEditorForm("Edit Equilibrium Reaction", 500, 400, myview2); alert2.Shown += (s1, e1) => { myview2.Invalidate(); alert2.Height = myview2.Height + 40; }; alert2.Topmost = true; alert2.Show(); break; case Interfaces.Enums.ReactionType.Kinetic: var myview3 = s.GetDefaultContainer(); var cre3 = new KineticReaction(flowsheet, rx, myview3); Form alert3 = null; myview3.CreateAndAddTwoButtonsRow("Cancel", null, "Update", null, (sender2, e2) => alert3.Close(), (sender2, e2) => { flowsheet.Reactions[cre3.rx.ID] = (IReaction)cre3.rx; CreateReactionsList(); alert3.Close(); }); alert3 = s.GetDefaultEditorForm("Edit Kinetic Reaction", 850, 760, myview3); alert3.Shown += (s1, e1) => { myview3.Invalidate(); alert3.Height = myview3.Height + 40; }; alert3.Topmost = true; alert3.Show(); break; case Interfaces.Enums.ReactionType.Heterogeneous_Catalytic: var myview4 = s.GetDefaultContainer(); var cre4 = new HetCatReaction(flowsheet, rx, myview4); Form alert4 = null; myview4.CreateAndAddTwoButtonsRow("Cancel", null, "Update", null, (sender2, e2) => alert4.Close(), (sender2, e2) => { flowsheet.Reactions[cre4.rx.ID] = (IReaction)cre4.rx; CreateReactionsList(); alert4.Close(); }); alert4 = s.GetDefaultEditorForm("Edit Heterogeneous Reaction", 850, 680, myview4); alert4.Shown += (s1, e1) => { myview4.Invalidate(); alert4.Height = myview4.Height + 40; }; alert4.Topmost = true; alert4.Show(); break; } }, (sender, e) => { if (MessageBox.Show("Are you sure you want to remove this reaction from the flowsheet?", "Remove selected reaction", MessageBoxButtons.YesNo, MessageBoxType.Question, MessageBoxDefaultButton.No) == DialogResult.Yes) { flowsheet.Reactions.Remove(rx.ID); flowsheet.ReactionSets["DefaultSet"].Reactions.Remove(rx.ID); CreateReactionsList(); } }); } rxcontainer.Create(); }
private void GenMaterialLayersPanel(DynamicLayout layout, Action <int, string> actionAfterChanged) { _layersPanel.Clear(); var index = 0; foreach (var item in _layers) { var id = Guid.NewGuid(); var dropin = GenDropInArea(index, item, actionAfterChanged, (i) => { _layers.RemoveAt(i); ////ctrls.Detach(); //ctrls.Clear(); GenMaterialLayersPanel(layout, actionAfterChanged); //foreach (var c in newPanel.Controls) //{ // ctrlsLayers.AddRow(c); //} //ctrls.AddRow(new TextBox()); _layersPanel.Create(); CalRValue(_hbObj, _showIP); }); _layersPanel.AddRow(dropin); index++; } //return ctrls; //GenItems(); ////return ctrls; //void GenItems() //{ // _layersPanel.Clear(); // var index = 0; // foreach (var item in _layers) // { // var id = Guid.NewGuid(); // var dropin = GenDropInArea(index, item, actionAfterChanged, // (i) => { // _layers.RemoveAt(i); // ////ctrls.Detach(); // //ctrls.Clear(); // GenMaterialLayersPanel(layout, actionAfterChanged); // //foreach (var c in newPanel.Controls) // //{ // // ctrlsLayers.AddRow(c); // //} // //ctrls.AddRow(new TextBox()); // ctrls.Create(); // }); // ctrls.AddRow(dropin); // index++; // } // //return ctrls; //} //ctrls.EndGroup(); }
void Initialize() { s.CreateAndAddLabelRow(container, "General"); s.CreateAndAddStringEditorRow(container, "Simulation Name", flowsheet.FlowsheetOptions.SimulationName, (sender, e) => flowsheet.FlowsheetOptions.SimulationName = sender.Text); s.CreateAndAddDescriptionRow(container, "The simulation name will be used for report identification and file name during saving."); var avunits = flowsheet.AvailableSystemsOfUnits.Select((x) => x.Name).ToList(); s.CreateAndAddLabelRow(container, "System of Units"); Button btnEdit = null; DropDown uselector = null; uselector = s.CreateAndAddDropDownRow(container, "System of Units", avunits, avunits.IndexOf(flowsheet.FlowsheetOptions.SelectedUnitSystem.Name), (sender, e) => { flowsheet.FlowsheetOptions.SelectedUnitSystem = flowsheet.AvailableSystemsOfUnits.Where((x) => x.Name == avunits[sender.SelectedIndex]).FirstOrDefault(); btnEdit.Enabled = !new string[] { "SI", "CGS", "ENG" }.Contains(uselector.SelectedValue.ToString()); }); s.CreateAndAddDescriptionRow(container, "Select the System of Units to be used on this simulation"); btnEdit = s.CreateAndAddLabelAndButtonRow(container, "Edit System of Units", "Edit Selected", null, (sender, e) => { var editcontainer = new Editors.UnitSetEditorView((DWSIM.SharedClasses.SystemsOfUnits.Units)flowsheet.FlowsheetOptions.SelectedUnitSystem); var form = s.GetDefaultEditorForm("Edit System of Units", 400, 600, editcontainer); form.Closed += (sender2, e2) => { container.RemoveAll(); container.Clear(); Initialize(); container.Create(); }; form.Show(); }); s.CreateAndAddLabelAndButtonRow(container, "Create New System of Units", "Create New", null, (sender, e) => { var newsystem = new DWSIM.SharedClasses.SystemsOfUnits.SI { Name = "NewUnitSet" }; flowsheet.AvailableSystemsOfUnits.Add(newsystem); flowsheet.FlowsheetOptions.SelectedUnitSystem = newsystem; var editcontainer = new Editors.UnitSetEditorView(newsystem); var form = s.GetDefaultEditorForm("Create New System of Units", 400, 600, editcontainer); form.Closed += (sender2, e2) => { container.RemoveAll(); container.Clear(); Initialize(); container.Create(); }; form.Show(); }); btnEdit.Enabled = !new string[] { "SI", "CGS", "ENG" }.Contains(uselector.SelectedValue.ToString()); var nformats = new[] { "F", "G", "G2", "G4", "G6", "G8", "G10", "N", "N2", "N4", "N6", "R", "E", "E1", "E2", "E3", "E4", "E6" }; s.CreateAndAddLabelRow(container, "Mass and Energy Balances"); s.CreateAndAddDropDownRow(container, "Flowsheet object mass balance check", new List <string>() { "Ignore", "Show Warning", "Throw Exception" }, (int)flowsheet.FlowsheetOptions.MassBalanceCheck, (sender, e) => { flowsheet.FlowsheetOptions.MassBalanceCheck = (DWSIM.Interfaces.Enums.WarningType)sender.SelectedIndex; }); s.CreateAndAddTextBoxRow(container, "G", "Mass balance relative tolerance", flowsheet.FlowsheetOptions.MassBalanceRelativeTolerance, (sender, e) => { if (sender.Text.IsValidDouble()) { flowsheet.FlowsheetOptions.MassBalanceRelativeTolerance = sender.Text.ToDoubleFromCurrent(); } }); s.CreateAndAddDropDownRow(container, "Flowsheet object energy balance check", new List <string>() { "Ignore", "Show Warning", "Throw Exception" }, (int)flowsheet.FlowsheetOptions.EnergyBalanceCheck, (sender, e) => { flowsheet.FlowsheetOptions.EnergyBalanceCheck = (DWSIM.Interfaces.Enums.WarningType)sender.SelectedIndex; }); s.CreateAndAddTextBoxRow(container, "G", "Energy balance relative tolerance", flowsheet.FlowsheetOptions.EnergyBalanceRelativeTolerance, (sender, e) => { if (sender.Text.IsValidDouble()) { flowsheet.FlowsheetOptions.EnergyBalanceRelativeTolerance = sender.Text.ToDoubleFromCurrent(); } }); s.CreateAndAddLabelRow(container, "Number Formats"); s.CreateAndAddDropDownRow(container, "General", nformats.ToList(), nformats.ToList().IndexOf(flowsheet.FlowsheetOptions.NumberFormat), (sender, e) => { flowsheet.FlowsheetOptions.NumberFormat = sender.SelectedValue.ToString(); }); s.CreateAndAddDescriptionRow(container, "Select the formatting scheme for general numbers."); s.CreateAndAddDropDownRow(container, "Compound Amounts", nformats.ToList(), nformats.ToList().IndexOf(flowsheet.FlowsheetOptions.FractionNumberFormat), (sender, e) => { flowsheet.FlowsheetOptions.FractionNumberFormat = sender.SelectedValue.ToString(); }); s.CreateAndAddDescriptionRow(container, "Select the formatting scheme for compound amounts in Material Stream reports."); s.CreateAndAddLabelRow(container, "Floating Tables and Anchored Property Lists"); s.CreateAndAddCheckBoxRow(container, "Display Floating Tables", flowsheet.FlowsheetOptions.DisplayFloatingPropertyTables, (sender, e) => { flowsheet.FlowsheetOptions.DisplayFloatingPropertyTables = sender.Checked.GetValueOrDefault(); var surface = (DWSIM.Drawing.SkiaSharp.GraphicsSurface)(flowsheet.GetSurface()); surface.DrawFloatingTable = flowsheet.FlowsheetOptions.DisplayFloatingPropertyTables; }); s.CreateAndAddCheckBoxRow(container, "Display Compound Amount Floating Tables for Material Streams", flowsheet.FlowsheetOptions.DisplayFloatingTableCompoundAmounts, (sender, e) => { flowsheet.Options.DisplayFloatingTableCompoundAmounts = sender.Checked.GetValueOrDefault(); }); s.CreateAndAddDropDownRow(container, "Compound Amount Default Basis", new List <string>() { "Molar Fractions", "Mass Fractions", "Volumetric Fractions", "Molar Flows", "Mass Flows", "Volumetric Flows" }, (int)flowsheet.FlowsheetOptions.DefaultFloatingTableCompoundAmountBasis, (sender, e) => { flowsheet.FlowsheetOptions.DefaultFloatingTableCompoundAmountBasis = (DWSIM.Interfaces.Enums.CompositionBasis)sender.SelectedIndex; }); s.CreateAndAddCheckBoxRow(container, "Display Anchored Property Lists", flowsheet.FlowsheetOptions.DisplayCornerPropertyList, (sender, e) => { flowsheet.FlowsheetOptions.DisplayCornerPropertyList = sender.Checked.GetValueOrDefault(); var surface = (DWSIM.Drawing.SkiaSharp.GraphicsSurface)(flowsheet.GetSurface()); surface.DrawPropertyList = flowsheet.FlowsheetOptions.DisplayCornerPropertyList; }); s.CreateAndAddLabelRow(container, "Anchored Property List Settings"); var fonts = Eto.Drawing.Fonts.AvailableFontFamilies.Select((x) => x.Name.ToLower()).ToList(); if (!fonts.Contains(flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontName.ToLower())) { flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontName = Eto.Drawing.FontFamilies.MonospaceFamilyName; } var fp = new FontPicker(new Eto.Drawing.Font(flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontName, flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontSize)); fp.ValueChanged += (sender, e) => { if (fp.Value != null) { flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontName = fp.Value.FamilyName; flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontSize = (int)fp.Value.Size; } }; s.CreateAndAddLabelAndControlRow(container, "Font Name and Size", fp); var colors = new SkiaSharp.SKColors(); var fontcolors = colors.GetType().GetFields().Select((x) => x.Name).ToList(); s.CreateAndAddDropDownRow(container, "Font Color", fontcolors, fontcolors.IndexOf(flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontColor), (sender, e) => { flowsheet.FlowsheetOptions.DisplayCornerPropertyListFontColor = fontcolors[sender.SelectedIndex]; }); var paddings = new List <string>() { "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }; s.CreateAndAddDropDownRow(container, "Line Padding", paddings, paddings.IndexOf(flowsheet.FlowsheetOptions.DisplayCornerPropertyListPadding.ToString()), (sender, e) => { flowsheet.FlowsheetOptions.DisplayCornerPropertyListPadding = int.Parse(paddings[sender.SelectedIndex]); }); }