The root page TOOLS:Tutorial could not be found in space Delta Shell.
1. Add a new folder to the project named "Commands"
2. Create a new class named "AddDemoDataToVolumeModelCommand" [TODO: Image]
3. Add the following contents to this class:
using System.Collections.Generic; using System.Drawing; using System.Linq; using DelftTools.Shell.Gui; using DeltaShell.Plugin.DemoApp.Importers; using DeltaShell.Plugin.DemoApp.Models; using DeltaShell.Plugins.NetworkEditor.Import; using SharpMap.Api; using SharpMap.Data.Providers; namespace DeltaShell.Plugin.DemoApp.Commands { internal class AddDemoDataToVolumeModelCommand : IGuiCommand { public string Name { get { return "Add demo data"; } } public bool Enabled { get { return Gui != null && Gui.SelectedModel is VolumeModel; } } public Image Image { get; set; } public bool Checked { get; set; } public IGui Gui { get; set; } public void Execute(params object[] arguments) { // Obtain the selected volume model var volumeModel = (VolumeModel) Gui.SelectedModel; // Create a WaterML2 time series importer var waterMl2TimeSeriesImporter = new WaterML2TimeSeriesImporter(); // Import a WaterML2 file to the precipitation time series of the volume model waterMl2TimeSeriesImporter.ImportItem(@"..\..\precipitation_waterml.XML", volumeModel.Precipitation); // Create a catchment importer var catchmentsImporter = new CatchmentFromGisImporter { FileBasedFeatureProviders = new List<IFileBasedFeatureProvider> { new ShapeFile() } }; // Configure the catchment importer var catchmentImporterSettings = catchmentsImporter.FeatureFromGisImporterSettings; catchmentImporterSettings.Path = @"D:\deltashell\Workshop\SoftwareDaysNov2013\Gemeenten.shp"; catchmentImporterSettings.PropertiesMapping.First(property => property.PropertyName == "Name").MappingColumn.ColumnName = "GM_NAAM"; // Import a shape file to the basin of the volume model catchmentsImporter.ImportItem(null, volumeModel.Basin); } public void Unexecute() { } } }
4. Create a new WPF user control named "DemoAppRibbon" [TODO: Image]
5. Add the following xaml code:
<UserControl x:Class="DeltaShell.Plugin.DemoApp.DemoAppRibbon" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:fluent="clr-namespace:Fluent;assembly=Fluent" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <!--Create a ribbon control--> <fluent:Ribbon Name="DemoAppRibbonControl" x:FieldModifier="private"> <!--Create a ribbon tab--> <fluent:RibbonTabItem Header="Volume model" fluent:KeyTip.Keys="E"> <!--Create a ribbon group box--> <fluent:RibbonGroupBox Header="Demo"> <!--Create a ribbon button--> <fluent:Button x:Name="ButtonAddDemoDataToVolumeModel" Header="Add demo data" ToolTip="Add demo data to the selected volume model" Click="ButtonAddDemoDataToVolumeModel_OnClick" Size="Middle" SizeDefinition="Middle,Small,Small"/> </fluent:RibbonGroupBox> </fluent:RibbonTabItem> </fluent:Ribbon> </UserControl>
6. Additionally, add the following interaction logic in DemoAppRibbon.xaml.cs:
using System.Collections.Generic; using System.Windows; using DelftTools.Controls; using DelftTools.Shell.Gui; using DelftTools.Shell.Gui.Forms; using DeltaShell.Plugin.DemoApp.Commands; namespace DeltaShell.Plugin.DemoApp { /// <summary> /// Interaction logic for DemoAppRibbon.xaml /// </summary> public partial class DemoAppRibbon : IRibbonCommandHandler { private readonly IGuiCommand addDemoDataCommand = new AddDemoDataToVolumeModelCommand(); public DemoAppRibbon() { InitializeComponent(); } public object GetRibbonControl() { return DemoAppRibbonControl; } public void ValidateItems() { ButtonAddDemoDataToVolumeModel.IsEnabled = addDemoDataCommand.Enabled; } public bool IsConextualTabVisible(string tabGroupName, string tabName) { return false; } public IEnumerable<ICommand> Commands { get { yield return addDemoDataCommand; } } private void ButtonAddDemoDataToVolumeModel_OnClick(object sender, RoutedEventArgs e) { addDemoDataCommand.Execute(); } } }
7. Run the application, create a volume model and click the newly created Ribbon button: ensure input data is added correctly to the volume model by opening the data views or by running the model [TODO: Image]