public override object ReadJson(Newtonsoft.Json.JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
		{
			object instance;
			JContainer container;
			if (reader.TokenType == JsonToken.Null)
			{
				return null;
			}
			container = JObject.Load(reader);
			if (container["$type"] == null)
			{
				instance = new StackLayoutItem();
				serializer.Populate(container.CreateReader(), instance);
			}
			else
			{
				var type = Type.GetType((string)container["$type"]);
				if (!typeof(StackLayoutItem).IsAssignableFrom(type))
				{
					var item = new StackLayoutItem();
					item.Control = serializer.Deserialize(container.CreateReader()) as Control;
					instance = item;
				}
				else
				{
					instance = serializer.Deserialize(container.CreateReader());
				}
			}
			return instance;
		}
示例#2
0
 public void Add(StackLayoutItem item) => this.Items.Add(item);
示例#3
0
        public void Add(Control control)
        {
            var item = new StackLayoutItem(control);

            this.Items.Add(item);
        }
示例#4
0
        public void AddControl(Control ctrl, bool expand = false)
        {
            var newItem = new StackLayoutItem(ctrl, expand);

            base.Items.Add(newItem);
        }
示例#5
0
        void Initialize()
        {
            var profile = (PipeProfile)((Pipe)SimObject).Profile;

            profile.Status = PipeEditorStatus.OK;

            var flowsheet = SimObject.GetFlowsheet();

            var su = flowsheet.FlowsheetOptions.SelectedUnitSystem;
            var nf = flowsheet.FlowsheetOptions.NumberFormat;

            var sectioncontainer = new StackLayout {
                Orientation = Orientation.Horizontal, Padding = new Eto.Drawing.Padding(10), Spacing = 10
            };

            s.CreateAndAddButtonRow(container, "Add Segment", null, (arg1, arg2) =>
            {
                var ps = new PipeSection()
                {
                    Indice = profile.Sections.Count + 1, Incrementos = 10, Comprimento = 1, Quantidade = 1
                };
                profile.Sections.Add(ps.Indice, ps);
                var pscontainer             = new DynamicLayout();
                var slcontainer             = new StackLayoutItem(pscontainer);
                pscontainer.BackgroundColor = Eto.Drawing.Colors.White;
                var editor       = new PipeSectionEditor(flowsheet, profile.Sections[ps.Indice], pscontainer);
                var btnRemove    = s.CreateAndAddButtonRow(pscontainer, "Remove Segment", null, null);
                btnRemove.Click += (sender, e) =>
                {
                    if (MessageBox.Show("Remove segment?", MessageBoxButtons.YesNo, MessageBoxType.Question, MessageBoxDefaultButton.No) == DialogResult.Yes)
                    {
                        profile.Sections.Remove(ps.Indice);
                        sectioncontainer.Items.Remove(slcontainer);
                    }
                    ;
                };
                sectioncontainer.Items.Add(slcontainer);
            });

            s.CreateAndAddButtonRow(container, "Remove All Segments", null, (arg1, arg2) =>
            {
                if (MessageBox.Show("Remove all segments?", MessageBoxButtons.YesNo, MessageBoxType.Question, MessageBoxDefaultButton.No) == DialogResult.Yes)
                {
                    profile.Sections.Clear();
                    sectioncontainer.RemoveAll();
                    sectioncontainer.Items.Clear();
                }
                ;
            });

            container.Add(new Scrollable {
                Border = BorderType.None, Content = sectioncontainer
            });

            foreach (var section in profile.Sections.Values)
            {
                var pscontainer = new DynamicLayout();
                var slcontainer = new StackLayoutItem(pscontainer);
                pscontainer.BackgroundColor = Eto.Drawing.Colors.White;
                var editor    = new PipeSectionEditor(flowsheet, section, pscontainer);
                var btnRemove = s.CreateAndAddButtonRow(pscontainer, "Remove Segment", null, null);
                btnRemove.Click += (sender, e) =>
                {
                    if (MessageBox.Show("Remove segment?", MessageBoxButtons.YesNo, MessageBoxType.Question, MessageBoxDefaultButton.No) == DialogResult.Yes)
                    {
                        profile.Sections.Remove(section.Indice);
                        sectioncontainer.Items.Remove(slcontainer);
                    }
                    ;
                };
                sectioncontainer.Items.Add(slcontainer);
            }
        }
示例#6
0
        void AddVariable(DWSIM.SharedClasses.Flowsheet.Optimization.OPTVariable newiv, StackLayout ivcontainer, List <string> objs)
        {
            Flowsheet fsheet = (Flowsheet)flowsheet;

            var su = flowsheet.FlowsheetOptions.SelectedUnitSystem;
            var nf = flowsheet.FlowsheetOptions.NumberFormat;

            List <string> proplist  = new List <string>();
            List <string> proplist2 = new List <string>();

            proplist.Add("");
            proplist2.Add("");

            var container = new DynamicLayout {
                Padding = new Padding(5), Width = 300
            };

            //container.BackgroundColor = Eto.Drawing.Colors.White;
            container.Tag = new Random().Next() + mycase.variables.Count + 1;

            var slcontainer = new StackLayoutItem(container);

            s.CreateAndAddLabelRow(container, "Optimization Variable #" + (ivcontainer.Items.Count + 1).ToString());

            var btnremove = s.CreateAndAddButtonRow(container, "Remove Variable", null, (arg1a, arg2a) =>
            {
                mycase.variables.Remove(newiv.id);
                ivcontainer.Items.Remove(slcontainer);
            });

            s.CreateAndAddLabelRow(container, "Definitions");

            s.CreateAndAddStringEditorRow(container, "Name", newiv.name, (arg3b, arg2b) =>
            {
                newiv.name = arg3b.Text;
            });

            s.CreateAndAddDropDownRow(container, "Type", new[] { "DEP", "IND", "AUX", "CON" }.ToList(), (int)newiv.type, (arg3, arg2) => { newiv.type = (DWSIM.SharedClasses.Flowsheet.Optimization.OPTVariableType)arg3.SelectedIndex; });

            DropDown spinprop = null;

            int idx = 0;

            if (flowsheet.SimulationObjects.ContainsKey(newiv.objectID))
            {
                idx = objs.IndexOf(flowsheet.SimulationObjects[newiv.objectID].GraphicObject.Tag);
            }

            s.CreateAndAddLabelRow(container, "Flowsheet Object Property Link");

            s.CreateAndAddDropDownRow(container, "Object", objs, idx, (arg3c, arg2c) =>
            {
                if (arg3c.SelectedIndex > 0)
                {
                    var obj        = flowsheet.GetFlowsheetSimulationObject(objs[arg3c.SelectedIndex]);
                    newiv.objectID = obj.Name;
                    if (newiv.type == DWSIM.SharedClasses.Flowsheet.Optimization.OPTVariableType.Independent)
                    {
                        proplist = obj.GetProperties(PropertyType.WR).ToList();
                    }
                    else
                    {
                        proplist = obj.GetProperties(PropertyType.ALL).ToList();
                    }
                    proplist.Insert(0, "");
                    proplist2 = proplist.Select(x => flowsheet.GetTranslatedString(x)).ToList();

                    spinprop.Items.Clear();
                    spinprop.Items.AddRange(proplist2.Select((x) => new ListItem {
                        Key = x, Text = x
                    }));
                }
            });

            int idx2 = 0;

            if (flowsheet.SimulationObjects.ContainsKey(newiv.objectID))
            {
                var obj = flowsheet.SimulationObjects[newiv.objectID];
                if (newiv.type == DWSIM.SharedClasses.Flowsheet.Optimization.OPTVariableType.Independent)
                {
                    proplist = obj.GetProperties(PropertyType.WR).ToList();
                }
                else
                {
                    proplist = obj.GetProperties(PropertyType.ALL).ToList();
                }
                proplist.Insert(0, "");
                proplist2 = proplist.Select(x => flowsheet.GetTranslatedString(x)).ToList();
                idx2      = proplist.IndexOf(newiv.propID);
            }

            TextBox tviv = null;

            spinprop = s.CreateAndAddDropDownRow(container, "Property", proplist2, idx2, (arg3c, arg2c) =>
            {
                if (spinprop.SelectedIndex > 0)
                {
                    newiv.propID       = proplist[arg3c.SelectedIndex];
                    newiv.unit         = fsheet.SimulationObjects[newiv.objectID].GetPropertyUnit(newiv.propID, su);
                    newiv.initialvalue = (double)fsheet.SimulationObjects[newiv.objectID].GetPropertyValue(newiv.propID, su);
                    tviv.Text          = newiv.initialvalue.ToString(nf);
                }
            });

            s.CreateAndAddLabelRow(container, "Variable Bounds");
            s.CreateAndAddDescriptionRow(container, "Bounds will be taken into account only if you use a bounded solver.");
            s.CreateAndAddTextBoxRow(container, nf, "Lower Bound", newiv.lowerlimit.GetValueOrDefault(), (arg3, arg2) => { newiv.lowerlimit = arg3.Text.ToDoubleFromCurrent(); });
            s.CreateAndAddTextBoxRow(container, nf, "Upper Bound", newiv.upperlimit.GetValueOrDefault(), (arg3, arg2) => { newiv.upperlimit = arg3.Text.ToDoubleFromCurrent(); });

            s.CreateAndAddLabelRow(container, "Initial Value");
            s.CreateAndAddDescriptionRow(container, "Set the initial value of the variable (IND only, other variable types will have their values read from the flowsheet).");
            tviv = s.CreateAndAddTextBoxRow(container, nf, "Initial Value", newiv.initialvalue, (arg3, arg2) => { newiv.initialvalue = arg3.Text.ToDoubleFromCurrent(); });

            ivcontainer.Items.Add(slcontainer);
        }
示例#7
0
        public static Dialog Create(PropertyEditorModel <string> model)
        {
            var xt   = model.Property?.XenType;
            var chks = new List <CheckBox>();

            var dialog = new ConnectedDialog
            {
                Title   = "Edit Enumeration",
                Padding = AppStyles.WindowPadding,
                Width   = 275,
                Height  = 225
            };

            var footer = new TableLayout(3, 1)
            {
                Spacing = new Size(5, 0)
            };

            var layout = new TableLayout(1, 2)
            {
                Spacing = new Size(0, 10)
            };

            var chkStack = new StackLayout
            {
                Padding         = AppStyles.PanelPadding,
                BackgroundColor = Colors.White,
                Spacing         = 5,
                Orientation     = Orientation.Vertical
            };

            // add checkboxes to stack.
            if (xt?.PossibleValues.Length > 0)
            {
                foreach (var pv in xt.PossibleValues)
                {
                    var chkd  = false;
                    var value = (string)model.ToolboxValue;

                    var split = value.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                    if (split.Any(s => s != null && s.Trim() == pv))
                    {
                        chkd = true;
                    }

                    var chk = new CheckBox
                    {
                        Tag     = pv,
                        Checked = chkd,
                        Text    = pv
                    };

                    // expand the width of the checkboxes so they're easier to click.
                    var item = new StackLayoutItem
                    {
                        Control             = chk,
                        HorizontalAlignment = HorizontalAlignment.Stretch
                    };

                    chkStack.Items.Add(item);

                    // make the checkboxes easier to access in the OkClicked event.
                    chks.Add(chk);
                }
            }
            else
            {
                ToolboxApp.Log.Warn($"No flags found for {model.DisplayName}.");
            }

            var scroll = new Scrollable
            {
                Border  = BorderType.Bezel,
                Content = chkStack
            };

            var ok = new Button {
                Text = CommonResource.Ok
            };
            var cancel = new Button {
                Text = CommonResource.Cancel
            };

            footer.Add(null, 0, 0, true, false);
            footer.Add(ok, 1, 0, false, false);
            footer.Add(cancel, 2, 0, false, false);

            layout.Add(scroll, 0, 0, true, true);
            layout.Add(footer, 0, 1, true, false);

            dialog.Content = layout;

            ok.Click += (s, e) =>
            {
                var value = string.Empty;

                // build the toolbox value
                foreach (var chk in chks)
                {
                    // only include checked flags.
                    if (chk.Checked == true)
                    {
                        var tag = (string)chk.Tag;

                        // first flag
                        if (string.IsNullOrWhiteSpace(value))
                        {
                            value = tag;
                        }
                        else
                        {
                            // other flags; note the spacing
                            value += $" | {tag}";
                        }
                    }
                }

                model.ToolboxValue = value;
                dialog.Close();
            };

            // discard changes
            cancel.Click += (s, e) => { dialog.Close(); };

            dialog.AbortButton   = cancel;
            dialog.DefaultButton = ok;

            return(dialog);
        }