Index: src/Common/DelftTools.Utils/PropertyBag/Dynamic/DynamicPropertyBag.cs
===================================================================
diff -u -rc5c796f26bff6a1d0e3d4e1242d59e234dc73f6a -r9cd3db94455d7ac8ec96d2504f46ca66a203a724
--- src/Common/DelftTools.Utils/PropertyBag/Dynamic/DynamicPropertyBag.cs (.../DynamicPropertyBag.cs) (revision c5c796f26bff6a1d0e3d4e1242d59e234dc73f6a)
+++ src/Common/DelftTools.Utils/PropertyBag/Dynamic/DynamicPropertyBag.cs (.../DynamicPropertyBag.cs) (revision 9cd3db94455d7ac8ec96d2504f46ca66a203a724)
@@ -21,6 +21,14 @@
Initialize(propertyObject, customPropertyInfos ?? propertyObject.GetType().GetProperties());
}
+ public object WrappedObject
+ {
+ get
+ {
+ return propertyObject;
+ }
+ }
+
public Type GetContentType()
{
return propertyObject.GetType();
Index: src/Plugins/Wti/Wti.Data/PipingSurfaceLine.cs
===================================================================
diff -u -rc42d0c47753135357002db6026ebbefc3603a62b -r9cd3db94455d7ac8ec96d2504f46ca66a203a724
--- src/Plugins/Wti/Wti.Data/PipingSurfaceLine.cs (.../PipingSurfaceLine.cs) (revision c42d0c47753135357002db6026ebbefc3603a62b)
+++ src/Plugins/Wti/Wti.Data/PipingSurfaceLine.cs (.../PipingSurfaceLine.cs) (revision 9cd3db94455d7ac8ec96d2504f46ca66a203a724)
@@ -52,5 +52,10 @@
EndingWorldPoint = point3Ds[point3Ds.Length - 1];
}
}
+
+ public override string ToString()
+ {
+ return Name;
+ }
}
}
\ No newline at end of file
Index: src/Plugins/Wti/Wti.Forms/PropertyClasses/PipingCalculationInputsProperties.cs
===================================================================
diff -u -rf65154bc499025f9f5b37b9de0ebdf8026336020 -r9cd3db94455d7ac8ec96d2504f46ca66a203a724
--- src/Plugins/Wti/Wti.Forms/PropertyClasses/PipingCalculationInputsProperties.cs (.../PipingCalculationInputsProperties.cs) (revision f65154bc499025f9f5b37b9de0ebdf8026336020)
+++ src/Plugins/Wti/Wti.Forms/PropertyClasses/PipingCalculationInputsProperties.cs (.../PipingCalculationInputsProperties.cs) (revision 9cd3db94455d7ac8ec96d2504f46ca66a203a724)
@@ -1,9 +1,14 @@
-using DelftTools.Shell.Gui;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Drawing.Design;
+
+using DelftTools.Shell.Gui;
using DelftTools.Utils;
using Wti.Data;
using Wti.Forms.PresentationObjects;
using Wti.Forms.Properties;
+using Wti.Forms.UITypeEditors;
namespace Wti.Forms.PropertyClasses
{
@@ -346,6 +351,7 @@
}
}
+ [Editor(typeof(PipingCalculationInputsSurfaceLineSelectionEditor), typeof(UITypeEditor))]
[ResourcesCategory(typeof(Resources), "Categories_General")]
[ResourcesDisplayName(typeof(Resources), "PipingDataSurfaceLineDisplayName")]
[ResourcesDescription(typeof(Resources), "PipingDataSurfaceLineDescription")]
@@ -355,6 +361,19 @@
{
return data.PipingData.SurfaceLine;
}
+ set
+ {
+ data.PipingData.SurfaceLine = value;
+ data.PipingData.NotifyObservers();
+ }
}
+
+ ///
+ /// Gets the available surface lines on .
+ ///
+ public IEnumerable GetAvailableSurfaceLines()
+ {
+ return data.AvailablePipingSurfaceLines;
+ }
}
}
\ No newline at end of file
Index: src/Plugins/Wti/Wti.Forms/UITypeEditors/PipingCalculationInputsSurfaceLineSelectionEditor.cs
===================================================================
diff -u
--- src/Plugins/Wti/Wti.Forms/UITypeEditors/PipingCalculationInputsSurfaceLineSelectionEditor.cs (revision 0)
+++ src/Plugins/Wti/Wti.Forms/UITypeEditors/PipingCalculationInputsSurfaceLineSelectionEditor.cs (revision 9cd3db94455d7ac8ec96d2504f46ca66a203a724)
@@ -0,0 +1,70 @@
+using System;
+using System.ComponentModel;
+using System.Drawing.Design;
+using System.Windows.Forms;
+using System.Windows.Forms.Design;
+
+using DelftTools.Utils.PropertyBag.Dynamic;
+using DelftTools.Utils.Reflection;
+
+using Wti.Data;
+using Wti.Forms.PropertyClasses;
+
+namespace Wti.Forms.UITypeEditors
+{
+ ///
+ /// This class defines a drop down list edit-control from which the user can select a
+ /// from a collection.
+ ///
+ public class PipingCalculationInputsSurfaceLineSelectionEditor : UITypeEditor
+ {
+ private IWindowsFormsEditorService editorService;
+
+ public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
+ {
+ return UITypeEditorEditStyle.DropDown;
+ }
+
+ public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
+ {
+ if (provider != null)
+ {
+ editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
+ }
+
+ if (editorService != null)
+ {
+ // Create editor:
+ var listBox = CreateSurfaceLinesSelectionControl(context);
+
+ // Open editor for user to select an item:
+ editorService.DropDownControl(listBox);
+
+ // Return user selected object, or original value if user did not select anything:
+ return listBox.SelectedItem ?? value;
+ }
+ return base.EditValue(context, provider, value);
+ }
+
+ private ListBox CreateSurfaceLinesSelectionControl(ITypeDescriptorContext context)
+ {
+ var listBox = new ListBox
+ {
+ SelectionMode = SelectionMode.One,
+ DisplayMember = TypeUtils.GetMemberName(sl => sl.Name)
+ };
+ listBox.SelectedValueChanged += (sender, eventArgs) => editorService.CloseDropDown();
+
+ var properties = (PipingCalculationInputsProperties)((DynamicPropertyBag)context.Instance).WrappedObject;
+ foreach (var surfaceLine in properties.GetAvailableSurfaceLines())
+ {
+ int index = listBox.Items.Add(surfaceLine);
+ if (ReferenceEquals(properties.SurfaceLine, surfaceLine))
+ {
+ listBox.SelectedIndex = index;
+ }
+ }
+ return listBox;
+ }
+ }
+}
\ No newline at end of file
Index: src/Plugins/Wti/Wti.Forms/Wti.Forms.csproj
===================================================================
diff -u -rf65154bc499025f9f5b37b9de0ebdf8026336020 -r9cd3db94455d7ac8ec96d2504f46ca66a203a724
--- src/Plugins/Wti/Wti.Forms/Wti.Forms.csproj (.../Wti.Forms.csproj) (revision f65154bc499025f9f5b37b9de0ebdf8026336020)
+++ src/Plugins/Wti/Wti.Forms/Wti.Forms.csproj (.../Wti.Forms.csproj) (revision 9cd3db94455d7ac8ec96d2504f46ca66a203a724)
@@ -73,6 +73,7 @@
+
Index: test/Plugins/Wti/Wti.Data.Test/PipingSurfaceLineTest.cs
===================================================================
diff -u -rab8c3b732c3aaadc8e55be98e132bdaf41110169 -r9cd3db94455d7ac8ec96d2504f46ca66a203a724
--- test/Plugins/Wti/Wti.Data.Test/PipingSurfaceLineTest.cs (.../PipingSurfaceLineTest.cs) (revision ab8c3b732c3aaadc8e55be98e132bdaf41110169)
+++ test/Plugins/Wti/Wti.Data.Test/PipingSurfaceLineTest.cs (.../PipingSurfaceLineTest.cs) (revision 9cd3db94455d7ac8ec96d2504f46ca66a203a724)
@@ -61,5 +61,22 @@
Assert.AreSame(sourceData[0], surfaceLine.StartingWorldPoint);
Assert.AreSame(sourceData[0], surfaceLine.EndingWorldPoint);
}
+
+ [Test]
+ public void ToString_ReturnName()
+ {
+ // Setup
+ const string niceName = "Nice name";
+ var surfaceLine = new PipingSurfaceLine
+ {
+ Name = niceName
+ };
+
+ // Call
+ var text = surfaceLine.ToString();
+
+ // Assert
+ Assert.AreEqual(niceName, text);
+ }
}
}
\ No newline at end of file
Index: test/Plugins/Wti/Wti.Forms.Test/UITypeEditors/PipingCalculationInputsSurfaceLineSelectionEditorTest.cs
===================================================================
diff -u
--- test/Plugins/Wti/Wti.Forms.Test/UITypeEditors/PipingCalculationInputsSurfaceLineSelectionEditorTest.cs (revision 0)
+++ test/Plugins/Wti/Wti.Forms.Test/UITypeEditors/PipingCalculationInputsSurfaceLineSelectionEditorTest.cs (revision 9cd3db94455d7ac8ec96d2504f46ca66a203a724)
@@ -0,0 +1,35 @@
+using System.Drawing.Design;
+
+using NUnit.Framework;
+
+using Wti.Forms.UITypeEditors;
+
+namespace Wti.Forms.Test.UITypeEditors
+{
+ [TestFixture]
+ public class PipingCalculationInputsSurfaceLineSelectionEditorTest
+ {
+ [Test]
+ public void DefaultConstructor_ExpectedValues()
+ {
+ // Call
+ var editor = new PipingCalculationInputsSurfaceLineSelectionEditor();
+
+ // Assert
+ Assert.IsInstanceOf(editor);
+ }
+
+ [Test]
+ public void GetEditStyle_Always_ReturnDropDown()
+ {
+ // Setup
+ var editor = new PipingCalculationInputsSurfaceLineSelectionEditor();
+
+ // Call
+ var editStyle = editor.GetEditStyle();
+
+ // Assert
+ Assert.AreEqual(UITypeEditorEditStyle.DropDown, editStyle);
+ }
+ }
+}
\ No newline at end of file
Index: test/Plugins/Wti/Wti.Forms.Test/Wti.Forms.Test.csproj
===================================================================
diff -u -rf65154bc499025f9f5b37b9de0ebdf8026336020 -r9cd3db94455d7ac8ec96d2504f46ca66a203a724
--- test/Plugins/Wti/Wti.Forms.Test/Wti.Forms.Test.csproj (.../Wti.Forms.Test.csproj) (revision f65154bc499025f9f5b37b9de0ebdf8026336020)
+++ test/Plugins/Wti/Wti.Forms.Test/Wti.Forms.Test.csproj (.../Wti.Forms.Test.csproj) (revision 9cd3db94455d7ac8ec96d2504f46ca66a203a724)
@@ -62,6 +62,7 @@
+