public void Add(StandardValue value, bool shouldUpdateListBoxItems) { if (!string.IsNullOrEmpty(value.DisplayText)) { this.values.Add(value); if (shouldUpdateListBoxItems) { this.UpdateFilteredListboxItems(); } } }
public override string ToString() { bool hasStd = StandardValue.CompareTo(0) != 0; bool hasInf = InfinityValue != 0; if (hasInf && hasStd) { return($"{InfinityValue}M + {StandardValue}"); } if (hasInf) { return($"{InfinityValue}M"); } return($"{StandardValue}"); }
public StandardValuesDropDown(IWindowsFormsEditorService editorService, ICollection values) { InitializeComponent(); this.editorService = editorService; UpdateSearchTextBoxState(); foreach (var value in values) { var standardValue = value as StandardValue; if (standardValue == null) standardValue = new StandardValue(GetDisplayTextFromValue(value), value); this.Add(standardValue, false); } this.values = this.values.OrderBy(value => value.DisplayText).ToList(); this.UpdateFilteredListboxItems(); }
public StandardValuesDropDown(IWindowsFormsEditorService editorService, ICollection values) { InitializeComponent(); this.editorService = editorService; UpdateSearchTextBoxState(); foreach (var value in values) { var standardValue = value as StandardValue; if (standardValue == null) { standardValue = new StandardValue(GetDisplayTextFromValue(value), value); } this.Add(standardValue, false); } this.values = this.values.OrderBy(value => value.DisplayText).ToList(); this.UpdateFilteredListboxItems(); }
public void Add(StandardValue value) { this.Add(value, true); }
public bool Equals(SimplexNumber other) { return(StandardValue.Equals(other.StandardValue) && InfinityValue == other.InfinityValue); }
public void SetData(ITypeDescriptorContext context, IWindowsFormsEditorService editorService, object value) { Debug.Assert(editorService != null); Debug.Assert(context.PropertyDescriptor != null); Debug.Assert(editorService != null); m_editorService = editorService; m_context = context; m_Value = value; m_bFlag = (context.PropertyDescriptor.PropertyType.GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0); listViewSvc.Items.Clear( ); listViewSvc.CheckBoxes = m_bFlag; TypeConverter tc = context.PropertyDescriptor.Converter; Debug.Assert(tc.GetStandardValuesSupported(context)); Debug.Assert((tc.CanConvertTo(context, typeof(StandardValue))), "To use this editor, TypeConverter must be able to convert to StandardValue"); TypeConverter.StandardValuesCollection svc = tc.GetStandardValues(context); // create list view items for the visible Enum items foreach (object obj in svc) { ListViewItem lvi = new ListViewItem( ); StandardValue sv = tc.ConvertTo(context, Thread.CurrentThread.CurrentUICulture, obj, typeof(StandardValue)) as StandardValue; if (sv != null && sv.Visible) { lvi.Text = sv.DisplayName; lvi.ForeColor = (sv.Enabled == true ? lvi.ForeColor : Color.FromKnownColor(KnownColor.GrayText)); lvi.Tag = new TagItem(sv); listViewSvc.Items.Add(lvi); } } UpdateCheckState( ); // make initial selection if (m_context.PropertyDescriptor.PropertyType.IsEnum && m_bFlag) { // select the first checked one foreach (ListViewItem lvi in listViewSvc.CheckedItems) { lvi.Selected = true; lvi.EnsureVisible( ); listViewSvc.FocusedItem = lvi; break; } } else { foreach (ListViewItem lvi in listViewSvc.Items) { TagItem ti = lvi.Tag as TagItem; if (ti.Item.Value.Equals(m_Value)) { lvi.Selected = true; lvi.EnsureVisible( ); listViewSvc.FocusedItem = lvi; break; } } } }
public TagItem(StandardValue item) { Item = item; }
public void Add(StandardValue value, bool shouldUpdateListBoxItems) { if (!string.IsNullOrEmpty(value.DisplayText)) { this.values.Add(value); if (shouldUpdateListBoxItems) this.UpdateFilteredListboxItems(); } }
public void UnitsAndValues_Test() { Value length = new Value(10.25, Units.m); StandardValue stdLength = length.ToStandardValue(); Assert.AreEqual(length.Magnitude, stdLength.Magnitude * Math.Pow(10, stdLength.StandardPower)); Assert.AreEqual(length.Unit, stdLength.Unit); Value revertedLength = stdLength.ToValue(); Assert.AreEqual(length.Magnitude, revertedLength.Magnitude); Assert.AreEqual(length.Unit, revertedLength.Unit); CompoundUnit KgPERm3 = new CompoundUnit(new Tuple <Units, int>(Units.Kg, 1), new Tuple <Units, int>(Units.m, -3)); Value density = new Value(1.0 / 8.0, KgPERm3); Value volume = new Value(8, Units.m, 3); Value mass = density * volume; Assert.AreEqual(1, mass.Magnitude); CompoundUnit massUnit = new CompoundUnit(new Tuple <Units, int>(Units.Kg, 1)); Assert.AreEqual(true, massUnit == (CompoundUnit)mass.Unit); Value dist1 = new Value(2, Units.m); Value dist2 = new Value(1, Units.m); Value ratio = dist1 / dist2; Assert.AreEqual(2, ratio.Magnitude); CompoundUnit ratioUnit = new CompoundUnit(new Tuple <Units, int>(Units.NoUnit, 0)); Assert.AreEqual(true, ratioUnit == (CompoundUnit)ratio.Unit); Value velocity = new Value(2, new CompoundUnit(new Tuple <Units, int>(Units.m, 1), new Tuple <Units, int>(Units.s, -1))); Value time = new Value(1, Units.s); StandardValue acc = (velocity / time).ToStandardValue(); Assert.AreEqual(2, acc.Magnitude); CompoundUnit accUnit = new CompoundUnit(new Tuple <Units, int>(Units.m, 1), new Tuple <Units, int>(Units.s, -2)); Assert.AreEqual(true, accUnit == (CompoundUnit)acc.Unit); Print(velocity + " / " + time + " = " + acc); Assert.AreEqual("2 m s\u02C9\u00B9 / 1 s = 2 m s\u02C9\u00B2", velocity + " / " + time + " = " + acc); StandardValue sValue = new StandardValue(10.23, new CompoundUnit(new Tuple <Units, int>(Units.km, 1), new Tuple <Units, int>(Units.h, -1)), 2); Print(sValue); Assert.AreEqual("1.023 x 10\u00B3 km h\u02C9\u00B9", sValue.ToString()); Value r_1 = new Value(10, Units.m); Value r2_1 = r_1 ^ 2; Print(r2_1); StandardValue r_2 = new StandardValue(10, Units.m); StandardValue r2_2 = r_2 ^ 2; Print(r2_2); Value testConversion1 = new Value(1000, new Unit(Units.g)); Value gInKg = (Value)testConversion1.As(Units.Kg); Print(gInKg.ToString() + " in " + testConversion1.ToString()); Assert.AreEqual(1, gInKg.Magnitude); Value testConversion2 = new Value(1, new Unit(Units.g)); StandardValue oxInGrams = ((Value)testConversion2.As(Units.oz)).ToStandardValue(); Print(oxInGrams.ToString() + " in " + testConversion2.ToString()); Assert.AreEqual(Math.Round(0.0352739619495804, 6, MidpointRounding.AwayFromZero), Math.Round(oxInGrams.GetMagnitude(), 6, MidpointRounding.AwayFromZero)); StandardValue testConversion3 = new StandardValue(1, new CompoundUnit(new Unit(Units.m), new Unit(Units.km))); StandardValue m2Inmkm = ((Value)testConversion3.As(Units.m.Pow(2))).ToStandardValue(); Print(m2Inmkm.ToString() + " in " + testConversion3.ToString()); Assert.AreEqual(1000, m2Inmkm.GetMagnitude()); StandardValue testConversion4 = new StandardValue(1, new CompoundUnit((Unit)Units.Kg, (Unit)Units.m, Units.s.Pow(-1))); StandardValue noncenceConversion = ((Value)testConversion4.As(new CompoundUnit((Unit)Units.lb, (Unit)Units.m, Units.s.Pow(-1)))).ToStandardValue(); Print(noncenceConversion.Round(5).ToString() + " in " + testConversion4.ToString()); Print(new Value(16, Units.oz) + " in " + new Value(16, Units.oz).As((Unit)Units.lb)); }