// Copyright (C) Stichting Deltares 2018. All rights reserved.
//
// This file is part of the application DAM - UI.
//
// DAM - UI is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Deltares.Dam.Data;
using Deltares.Dam.Data.DamEngineIo;
using Deltares.Dam.Data.DataPlugins;
using Deltares.Dam.Data.DataPlugins.Configuration;
using Deltares.Dam.Data.IO;
using Deltares.Dam.Data.License;
using Deltares.Dam.Data.Sensors;
using Deltares.Dam.Data.UISupport;
using Deltares.DamEngine.Interface;
using Deltares.DamEngine.Io;
using Deltares.DamEngine.Io.XmlInput;
using Deltares.Geotechnics.Mechanisms;
using Deltares.Geotechnics.SurfaceLines;
using Deltares.Standard;
using Deltares.Standard.Attributes;
using Deltares.Standard.Calculate;
using Deltares.Standard.EventPublisher;
using Deltares.Standard.EventPublisher.Enum;
using Deltares.Standard.Forms;
using Deltares.Standard.Forms.DExpress;
using Deltares.Standard.Forms.Maps;
using Deltares.Standard.IO.Xml;
using Deltares.Standard.Language;
using Deltares.Standard.Logging;
using DevExpress.XtraBars;
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraEditors.Repository;
using Location = Deltares.Dam.Data.Location;
using Soil = Deltares.Geotechnics.Soils.Soil;
namespace Deltares.Dam.Forms
{
public class DamPlugin : IMainFormPlugin, IVisibleEnabled, IVisibleEnabledProvider, IDisposable
{
private MainForm mainForm = null;
private SpatialEditor spatialEditor;
private readonly DamProject damProject = new DamProject();
private TreeViewControl damNavigator = null;
private readonly LocationJobSymbol locationJobSymbol = new LocationJobSymbol();
private DamMapEditor mapEditor = null;
private DamGeometryEditor geometryEditor = null;
private readonly Panel panel = new Panel();
private readonly Panel projectPanel = new Panel();
private readonly Panel materialPanel = new Panel();
private readonly Panel locationJobPanel = new Panel();
private readonly Panel locationJobSymbolPanel = new Panel();
private readonly Panel calculationSpecificationPanel = new Panel();
private readonly Panel stabilityKernelTypeSpecificationPanel = new Panel();
private readonly Panel sensorPanel = new Panel();
private ProgressDelegate progressDelegate = null;
private bool initial = true;
private DAMNewProjectData damNewProjectData = null;
private RWScenarioProfileResult lastAssesmentResult = null;
private CsvExportData lastDesignResult = null;
private LocationResult lastLocationResult = null;
private LocationJob currentLocationJob = null;
private readonly GridViewControl locationsControl = new GridViewControl
{
Name = "Locations", ShowToolbar = true, HideUnusedColumns = true
};
private readonly GridViewControl calculationsControl = new GridViewControl
{
Name = "Calculations", ShowToolbar = true, HideUnusedColumns = true
};
private readonly LocationChart locationChart = new LocationChart();
private readonly GridViewControl designCalculationsControl = new GridViewControl
{
Name = "DesignCalculations",
ShowToolbar = true,
HideUnusedColumns = true,
SendSelectionChanged = true
};
private readonly GridViewControl sensorControl = new GridViewControl
{
Name = "Sensors",
ShowToolbar = true,
HideUnusedColumns = true,
SendSelectionChanged = false // Set to true when custom property editor is ready
};
private readonly GridViewControl sensorGroupControl = new GridViewControl
{
Name = "SensorGroups",
ShowToolbar = true,
HideUnusedColumns = true,
SendSelectionChanged = false // Set to true when custom property editor is ready
};
private readonly GridViewControl sensorProfileControl = new GridViewControl
{
Name = "SensorLocations",
ShowToolbar = true,
HideUnusedColumns = true,
SendSelectionChanged = true // To add/activate custom property editor when ready, see DataEventPublisher_OnSelectionChanged
};
private readonly DesignCalculationPropertyControl designCalculationPropertyControl = new DesignCalculationPropertyControl();
private readonly ScenarioCalculationPropertyControl assessmentCalculationPropertyControl = new ScenarioCalculationPropertyControl();
private readonly LocationPropertyControl locationPropertyControl = new LocationPropertyControl();
private readonly AssessmentCalculationSpecificationPropertyControl assessmentCalculationSpecificationPropertyControl = new AssessmentCalculationSpecificationPropertyControl();
private readonly DamProjectCalculationSpecificationPropertyControl damProjectCalculationSpecificationPropertyControl = new DamProjectCalculationSpecificationPropertyControl();
private readonly WaterBoardPropertyControl waterBoardPropertyControl = new WaterBoardPropertyControl();
private readonly BarButtonItem showCalculationOptionsItem = new BarButtonItem();
private readonly MapEditor mapControl = new MapEditor();
public int MaxCalculationCores
{
get
{
if (mainForm == null)
return 1;
if (damProject != null && damProject.DamProjectData != null)
{
damProject.DamProjectData.MaxCalculationCores = mainForm.MaxCalculationCores;
}
return mainForm.MaxCalculationCores;
}
set
{
if (damProject != null && damProject.DamProjectData != null)
{
damProject.DamProjectData.MaxCalculationCores = value;
}
if (mainForm != null)
{
mainForm.MaxCalculationCores = value;
}
}
}
public void Configure(MainForm mainForm)
{
ConfigureSoilUserFilters();
this.mainForm = mainForm;
spatialEditor = mainForm.GeometryEditor.SpatialEditor;
mainForm.UseTemplateDialog = true;
mainForm.AllowMultiCoreSelection = true;
DamProject.ProjectWorkingPathLocation = ProjectPathLocation.InProjectMap;
RegisterFileHandlers();
RegisterUsedControls();
SetApplicationIcon();
ConfigureControls();
RegisterCalculation();
ConfigureMenu();
BindSupport.Assign(this.panel, this);
BindSupport.Assign(this.locationJobSymbolPanel, this.locationJobSymbol);
DataEventPublisher.OnAfterChange += DataEventPublisher_OnAfterChange;
DataEventPublisher.OnSelectionChanged += DataEventPublisher_OnSelectionChanged;
LocalizationManager.CultureChanged += (sender, args) => UpdateNavigatorTopItem();
// for backward compatibility
XmlHandler.RegisterObjectHandler(new FailureMechanismeParamatersMStabXmlHandler());
}
///
/// Make sure that the top item of the Navigator ("Waterschap") after translation is displayed properly.
///
private void UpdateNavigatorTopItem()
{
var node = damNavigator.TreeList.Nodes.FirstNode;
if (node == null) return;
var wb = TreeViewControl.GetInnerDataObject(node.Tag) as WaterBoardJob;
if (null != wb)
{
node.SetValue(0, wb.Name);
}
}
private void SetApplicationIcon()
{
try
{
var icon = new Icon(typeof(DamPlugin).Assembly.GetManifestResourceStream(
"Deltares.Dam.Forms.Resources.DAM_icon.ico"));
this.mainForm.UseIcon(icon);
}
catch (Exception)
{
// Kill exception for Windows XP if load fails
// Todo: Solve exception; see MWDAM-391
}
}
private void RegisterUsedControls()
{
mainForm.UseNavigation();
mainForm.UseSpatialEditor();
mainForm.UseProperties();
mainForm.UseOutput();
mainForm.UseImage();
mainForm.UseTables();
mainForm.UseCharts();
mainForm.UseValidation();
mainForm.AddControl(mapControl);
// mainForm.UseReport(); For now, do not use report [MWDAM-412].
}
private void ConfigureControls()
{
this.mapEditor = new DamMapEditor(mapControl, this.locationJobSymbol);
this.geometryEditor = new DamGeometryEditor(mainForm.GeometryEditor);
this.ConfigureNavigation();
this.ConfigurePropertyGrid();
this.ConfigureChart();
this.ConfigureTable();
ConfigureSoilMechanisms();
}
private void RegisterCalculation()
{
CalculationManager.Instance.Register("DAM", this.ExecuteCalculation);
}
private void RegisterFileHandlers()
{
mainForm.RegisterNewFileHandler(this.NewProject);
mainForm.RegisterOpenFileHandler("damx", "DAMX Files (*.damx)|*.damx", this.damProject.OpenXMLProject);
mainForm.RegisterSaveFileHandler("damx", "DAMX Files (*.damx)|*.damx", this.damProject.SaveXMLProject);
}
private void ConfigurePropertyGrid()
{
var dpc = this.mainForm.DynamicPropertyControl;
// deregister the ugly property control provided by the Geotechnics plugin
mainForm.DynamicPropertyControl.ClearRegistrationsForType(typeof(Soil));
mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => PropertyControlFactory.GetPropertyControl(), typeof(Soil));
dpc.BuildPropertyControlTabForTypes(locationPropertyControl, typeof(Location), typeof(LocationJob), typeof(RWScenarioProfileResult));
dpc.BuildPropertyControlTabForTypes(new LocationScenariosControl(), typeof(Location), typeof(LocationJob));
this.progressDelegate = waterBoardPropertyControl.DoProgress;
dpc.BuildPropertyControlTabForTypes(waterBoardPropertyControl,
typeof(WaterBoard), typeof(WaterBoardJob), typeof(DamProjectData));
dpc.BuildPropertyControlTabForTypes(new DikePropertyControl(), typeof(Dike), typeof(DikeJob));
var schematizationFactorPropertyControl = new SchematizationFactorPropertyControl();
dpc.BuildPropertyControlTabForTypes(schematizationFactorPropertyControl, typeof(DamProjectData));
dpc.BuildPropertyControlTabForTypes(damProjectCalculationSpecificationPropertyControl, typeof(DamProjectData));
dpc.BuildPropertyControlTabForTypes(assessmentCalculationPropertyControl, typeof(RWScenarioProfileResult), typeof(LocationJob));
dpc.BuildPropertyControlTabForTypes(designCalculationPropertyControl, typeof(CsvExportData), typeof(LocationJob));
dpc.BuildPropertyControlTabForTypes(assessmentCalculationSpecificationPropertyControl, typeof(DamProjectData));
}
private void ConfigureTable()
{
var materialsTable = new GridViewControl
{
AllowedUserColumnFilters = Soil.AllowedUserColumnFilters,
HideUnusedColumns = true
};
mainForm.RegisterTableControl(typeof(Soil), materialsTable, "Materials");
BindSupport.Bind(materialPanel, materialsTable, typeof(Dike), "SoilList.Soils");
BindSupport.Bind(materialPanel, materialsTable.Parent, typeof(Dike), "SoilList.Soils", BindingType.Visibility);
this.mainForm.DynamicTableControl.RegisterTable(typeof(Location), locationsControl, "Locations");
BindSupport.Bind(this.projectPanel, locationsControl, p => p.Locations);
this.mainForm.DynamicTableControl.RegisterTable(typeof(RWScenarioProfileResult),
calculationsControl, "Assessment calculations");
BindSupport.Bind(this.projectPanel, calculationsControl, p => p.Calculations);
BindSupport.Bind(this.projectPanel, calculationsControl.Parent, p => p.Calculations);
var schematizationFactorsControl = new GridViewControl
{
Name = "SchematizationFactors", ShowToolbar = true, HideUnusedColumns = true
};
this.mainForm.DynamicTableControl.RegisterTable(typeof(RWScenarioProfileResult),
schematizationFactorsControl, "SchematizationFactors");
BindSupport.Bind(this.projectPanel,
schematizationFactorsControl, p => p.SchematizationFactors);
BindSupport.Bind(this.projectPanel,
schematizationFactorsControl.Parent, p => p.SchematizationFactors);
this.mainForm.DynamicTableControl.RegisterTable(typeof(CsvExportData), designCalculationsControl, "Design calculations");
BindSupport.Bind(this.projectPanel,
designCalculationsControl, p => p.DesignCalculations);
BindSupport.Bind(this.projectPanel,
designCalculationsControl.Parent, p => p.DesignCalculations);
this.mainForm.DynamicTableControl.RegisterTable(typeof(Sensor), sensorControl, "Sensor Configuration");
BindSupport.Bind(this.sensorControl, sensorControl, p => p.Sensors);
BindSupport.Bind(this.sensorPanel, sensorControl, p => p.SensorData, BindingType.Assign);
BindSupport.Bind(this.sensorPanel, sensorControl.Parent, p => p.SensorData, BindingType.Visibility);
this.mainForm.DynamicTableControl.RegisterTable(typeof(Group), sensorGroupControl, "Sensor Group Configuration");
BindSupport.Bind(this.sensorGroupControl, sensorGroupControl, p => p.SensorGroups);
BindSupport.Bind(this.sensorPanel, sensorGroupControl, p => p.SensorData, BindingType.Assign);
BindSupport.Bind(this.sensorPanel, sensorGroupControl.Parent, p => p.SensorData, BindingType.Visibility);
this.mainForm.DynamicTableControl.RegisterTable(typeof(SensorLocation), sensorProfileControl, "Sensor Location Data");
BindSupport.Bind(this.sensorProfileControl, sensorProfileControl, p => p.SensorLocations);
BindSupport.Bind(this.sensorPanel, sensorProfileControl, p => p.SensorData, BindingType.Assign);
BindSupport.Bind(this.sensorPanel, sensorProfileControl.Parent, p => p.SensorData, BindingType.Visibility);
}
private void ConfigureSoilUserFilters()
{
Soil.AllowedUserColumnFilters = new[]
{
UserColumnFilters.DGeoStability,
UserColumnFilters.DGeoStabilityCPhiModel,
UserColumnFilters.DGeoStabilitySuCalculated,
UserColumnFilters.DGeoStabilitySuMeasured,
UserColumnFilters.DGeoStabilitySuGradient,
UserColumnFilters.ShearStrengthParameters,
UserColumnFilters.ShearStrengthInput,
UserColumnFilters.ShearStrengthModel,
UserColumnFilters.Piping,
UserColumnFilters.UnitWeightFilter
};
}
private void ConfigureSoilMechanisms()
{
Soil.Mechanisms = new[]
{
Mechanism.DAM,
Mechanism.Piping,
Mechanism.PipingUpliftGradient,
Mechanism.Stability
};
}
private void ConfigureChart()
{
//locationChart = new LocationChart();
this.mainForm.DynamicChartControl.RegisterChart(typeof(TimeSerie), locationChart, "Time Series");
BindSupport.Bind(this.locationJobPanel, locationChart.Parent, typeof(LocationJob), "WaterLevelTimeSerie", BindingType.Visibility);
var locationScenarioChart = new LocationScenarioChart(this.locationJobSymbol);
this.mainForm.DynamicChartControl.RegisterChart(typeof(Location), locationScenarioChart, "Scenarios");
BindSupport.Bind(this.locationJobPanel, locationScenarioChart.Parent, typeof(LocationJob), "RWScenarioResults", BindingType.Visibility);
// Bind the main tab "Chart" to be able to show it only when needed.
BindSupport.Bind(this.panel, locationScenarioChart.Parent.Parent.Parent.Parent.Parent, typeof(DamPlugin), "IsChartVisible", BindingType.Visibility);
}
///
/// Gets or sets a value indicating whether this instance is chart visible.
/// Only needed as a place holder to be able to switch the visibility of the main chart tab.
/// The actual value itself is never (to be) used.
///
///
/// true if this instance is chart visible; otherwise, false.
///
public bool IsChartVisible { get; set; }
public void Assign(object source)
{
var projectData = source as DamProjectData;
if (projectData == null) return;
initial = false;
var args = Environment.GetCommandLineArgs();
foreach (string arg in args)
{
if (arg.ToLower().Equals("-wti"))
{
projectData.DamProjectCalculationSpecification.VisibleEnabledProvider = this;
StabilityKernelTypeSpecificationsVisible = true;
ConfigurationManager.Wti = true;
}
}
Context.CurrentContext = new DamContext
{
Wti = StabilityKernelTypeSpecificationsVisible
};
// get data
lastAssesmentResult = null;
lastDesignResult = null;
lastLocationResult = null;
currentLocationJob = null;
DataSourceManager.DataSources = projectData.DataSources;
DataSourceManager.Active = true;
DataSourceManager.CurrentSource = DataSourceSystemType.User;
DataSourceManager.StartListening();
BindSupport.Assign(damNavigator, projectData);
BindSupport.Assign(this.projectPanel, projectData);
var sd = projectData.WaterBoard.SelectedDike;
projectData.WaterBoard.SelectedDike = sd;
BindSupport.Assign(this.materialPanel, projectData.WaterBoard.SelectedDike);
BindSupport.Assign(this.sensorPanel, projectData);
BindSupport.Assign(this.calculationSpecificationPanel, projectData.DamProjectCalculationSpecification);
BindSupport.Assign(this.locationJobPanel, currentLocationJob);
if (projectData.SensorData != null)
{
SensorLocation.GetGroups = projectData.SensorData.GetGroups;
}
// TODO This seems awkward: what is the purpose of assigning DamProjectData to locationJobSymbol, all it uses projectdata for is to fire events...
this.locationJobSymbol.DamProjectData = projectData;
this.damProject.DamProjectData = projectData;
this.mapEditor.Project = projectData;
// Force update for Log
DataEventPublisher.DataListModified(LogManager.Messages);
RealTimeBackgroundValidator.Instance.Register(projectData);
lastAssesmentResult = null;
lastDesignResult = null;
lastLocationResult = null;
// Read the Waterlevel Timeseries
this.damProject.ImportWaterLevelTimeSeries();
this.locationJobSymbol.Update(projectData.LocationJobs);
if (projectData.DamProjectType == DamProjectType.DamLiveConfiguration)
{
if (projectData.SensorData != null)
{
projectData.SensorData.UpdatePickSensorsForGroups();
}
}
}
[Browsable(false)]
public bool StabilityKernelTypeSpecificationsVisible { get; set; }
///
/// Adds the menus and their bind support.
///
private void ConfigureMenu()
{
var clearResultsMenuItem = new BarButtonItem
{
Caption = "Clear Results", Name = "ClearResultsMenuItem"
};
var trackBar = new RepositoryItemTrackBar
{
Maximum = 100, TickFrequency = 10
};
var sliderBarItem = new BarEditItem
{
Width = 300, Edit = trackBar
};
var dateEdit = new RepositoryItemDateEdit();
var dateBarItem = new BarEditItem
{
Edit = dateEdit, Width = 80
};
var timeEdit = new RepositoryItemTimeEdit();
var timeBarItem = new BarEditItem
{
Edit = timeEdit, Width = 100
};
var projectTypeComboBox = new RepositoryItemComboBox
{
TextEditStyle = TextEditStyles.DisableTextEditor
};
var projectTypeBarItem = new BarEditItem
{
Width = 100, Edit = projectTypeComboBox, PaintStyle = BarItemPaintStyle.Caption
};
var scenarioComboBox = new RepositoryItemComboBox
{
TextEditStyle = TextEditStyles.DisableTextEditor, DropDownRows = 16
};
var scenarioBarItem = new BarEditItem
{
Width = 100, Edit = scenarioComboBox, PaintStyle = BarItemPaintStyle.Caption
};
var designAnalysisComboBox = new RepositoryItemComboBox
{
TextEditStyle = TextEditStyles.DisableTextEditor
};
var designAnalysisBarItem = new BarEditItem
{
Width = 100, Edit = designAnalysisComboBox, PaintStyle = BarItemPaintStyle.Caption
};
this.mainForm.CalculationMenu.AddItem(clearResultsMenuItem);
this.mainForm.CalculationMenu.AddItem(showCalculationOptionsItem);
this.mainForm.ToolBar.AddItems(new BarItem[]
{
projectTypeBarItem,
sliderBarItem,
dateBarItem,
timeBarItem,
scenarioBarItem,
designAnalysisBarItem
});
var scenarioExportItem = new BarButtonItem()
{
Caption = "Scenarios",
Hint = "Export scenario's to ShapeFiles",
Name = "exportBarItem"
};
this.mainForm.ExportMenu.AddItem(scenarioExportItem);
this.mainForm.ExportMenu.Enabled = true;
var surfacelineExportItem = new BarButtonItem()
{
Caption = "Surfacelines",
Hint = "Export surfacelines's to CSV files",
Name = "exportSurfaceLineBarItem"
};
this.mainForm.ExportMenu.AddItem(surfacelineExportItem);
this.mainForm.ExportMenu.Enabled = true;
var saveCalculationItem = new BarButtonItem();
this.mainForm.ExportMenu.AddItem(saveCalculationItem);
var saveImageItem = new BarButtonItem();
this.mainForm.ExportMenu.AddItem(saveImageItem);
// Remove the link: Tools->License
var licenseItemLink = mainForm.ToolsMenu.ItemLinks.Cast().Where(il => il.Item.Name.Equals("LicenseBarButton")).ToList().FirstOrDefault();
mainForm.ToolsMenu.ItemLinks.Remove(licenseItemLink);
BindSupport.Bind(this.panel, scenarioExportItem, x => x.ExecuteScenarioExport());
BindSupport.Bind(this.panel, surfacelineExportItem, x => x.ExecuteSurfacelinesExport());
BindSupport.Bind(this.panel, clearResultsMenuItem, x => x.ClearResults());
BindSupport.Bind(this.panel, saveCalculationItem, x => x.SaveCalculation());
BindSupport.Bind(this.panel, saveImageItem, x => x.SaveImage());
BindSupport.Bind(this.panel, showCalculationOptionsItem, dp => dp.ShowCalculationOptions());
BindSupport.Bind(this.projectPanel, projectTypeBarItem, x => x.DamProjectType, BindingType.LabelAndValue);
BindSupport.Bind(this.calculationSpecificationPanel, designAnalysisBarItem, x => DamProjectCalculationSpecification.SelectedAnalysisType, BindingType.LabelAndValue);
BindSupport.Bind(this.locationJobSymbolPanel, sliderBarItem, x => x.CurrentView);
BindSupport.Bind(this.locationJobSymbolPanel, dateBarItem, x => x.CurrentDateTime);
BindSupport.Bind(this.locationJobSymbolPanel, timeBarItem, x => x.CurrentDateTime);
BindSupport.Bind(this.locationJobSymbolPanel, scenarioBarItem, x => x.CurrentScenarioType, BindingType.LabelAndValue);
}
///
/// Export the scenario results to shapefiles
///
[Label("Scenarios")]
private void ExecuteScenarioExport()
{
this.mapEditor.ExportScenarios();
}
///
/// Export the redesigned surfacelines to a user selected folder
///
[Label("Surfacelines")]
private void ExecuteSurfacelinesExport()
{
FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
folderBrowserDialog.SelectedPath = Path.GetDirectoryName(this.damProject.ProjectFileName);
if (String.IsNullOrEmpty(folderBrowserDialog.SelectedPath))
{
folderBrowserDialog.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
}
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
ExportRedesignedSurfacelines(folderBrowserDialog.SelectedPath);
}
}
///
/// Dummy calculation to generate values for the stability factors
///
private void ExecuteCalculationDummy()
{
// This is a dummy calculation;
// Should be replaced with real calculation
var random = new Random();
foreach (DikeJob dikeJob in (this.damProject.DamProjectData.WaterBoardJob as WaterBoardJob).Jobs)
{
foreach (LocationJob locationJob in dikeJob.Jobs)
{
var stabilityTimeSerie = new TimeSerie();
stabilityTimeSerie.MissVal = this.damProject.DamProjectData.MissValStabilitySafetyFactor;
foreach (TimeSerieEntry timeSerieEntry in locationJob.WaterLevelTimeSerie.Entries)
{
if (locationJob.Run.Value)
{
var lran = random.NextDouble();
if (lran <= 0.1)
stabilityTimeSerie.Entries.Add(new TimeSerieEntry(timeSerieEntry.DateTime,
stabilityTimeSerie.MissVal));
else
stabilityTimeSerie.Entries.Add(new TimeSerieEntry(timeSerieEntry.DateTime, random.NextDouble() + 0.5));
}
}
locationJob.LocationResult.StabilityTimeSerie = stabilityTimeSerie;
}
}
}
[Label("Run")]
private void ExecuteCalculation()
{
if (DamLicense.DamLicenseType == DamLicenseType.None)
{
LocalizedMessageBox.ShowError(this, "NoLicenseGranted");
return;
}
DataEventPublisher.InvokeWithoutPublishingEvents(() =>
{
LogManager.Clear();
damProject.DamProjectData.ClearResults();
});
try
{
Input input = FillXmlInputFromDamUi.CreateInput(damProject.DamProjectData);
#if DEBUG
const string inputFilename = "InputFile.xml";
DamXmlSerialization.SaveInputAsXmlFile(inputFilename, input);
#endif
string inputXml = DamXmlSerialization.SaveInputAsXmlString(input);
var damEnginInterface = new EngineInterface(inputXml);
string validationMessages = damEnginInterface.Validate();
// now the validation messages should be deserialized. If any, they should be passed on to the Validator
// and checked for errors. IF errors are found, then no calculation. When no messages or only warnings then
// do calculate. For now, just check length
if (string.IsNullOrEmpty(validationMessages))
{
// only if validation is ok, then
string outputXml = damEnginInterface.Run();
var output = DamXmlSerialization.LoadOutputFromXmlString(outputXml);
FillDamUiFromXmlOutput.AddOutputToDamProjectData(damProject.DamProjectData, output);
#if DEBUG
const string outputFilename = "OutputFile.xml";
DamXmlSerialization.SaveOutputAsXmlFile(outputFilename, output);
#endif
}
}
catch (Exception e)
{
LogManager.Add(new LogMessage(LogMessageType.FatalError, typeof(EngineInterface), string.Format("{0}", e.Message)));
string openingMessage = LocalizationManager.GetTranslatedText(this, "CalculationFailed");
string paragraphSepatator = Environment.NewLine + Environment.NewLine;
LocalizedMessageBox.ShowTranslatedText(openingMessage + paragraphSepatator + e.Message);
}
SetProperControlsAfterCalculation();
}
private void SetProperControlsAfterCalculation()
{
if (damProject.DamProjectData.CalculationMessages != null && damProject.DamProjectData.CalculationMessages.Count > 0)
{
LogManager.Messages.AddRange(damProject.DamProjectData.CalculationMessages);
mainForm.Invoke(new PublisherDelegate(DataEventPublisher.DataListModified), LogManager.Messages, null);
}
switch (damProject.DamProjectData.DamProjectType)
{
case DamProjectType.Calamity:
{
SetProperControlsAfterCalamityCalculation();
break;
}
case DamProjectType.Design:
{
SetProperControlsAfterDesignCalculation();
break;
}
case DamProjectType.Assessment:
{
SetProperControlsAfterAssessmentCalculation();
break;
}
}
}
private void SetProperControlsAfterAssessmentCalculation()
{
if (damProject.DamProjectData.GetFirstLocationJobWithAssesmentResults() != null)
{
var res =
damProject.DamProjectData.GetFirstLocationJobWithAssesmentResults().RWScenarioResults.FirstOrDefault
();
if (res != null)
{
mainForm.SetAsActiveTable(calculationsControl);
if (res.SafetyFactor > 0 && res.SafetyFactor < DamGlobalConstants.NoRunValue)
{
mainForm.SetAsActiveTabOnMainPanel(mainForm.DynamicImageControl);
}
// Selecting the result sets the correct line and that the correct property editor is displayed
mainForm.Invoke(new TaskDelegate(DataEventPublisher.SelectionChanged),
res.RWScenarioProfileResults[0]);
mainForm.SetAsActivePropertyEditor(assessmentCalculationPropertyControl);
}
}
}
private void SetProperControlsAfterDesignCalculation()
{
var locationJob = damProject.DamProjectData.GetFirstLocationJobWithDesignResults();
if (locationJob != null)
{
var res = locationJob.GetFirstDesignResult();
if (res != null)
{
mainForm.SetAsActiveTable(designCalculationsControl);
// Make sure that the Image is only selected in case of stability
if (res.SafetyFactor > 0 && res.SafetyFactor < DamGlobalConstants.NoRunValue &&
(res.DamFailureMechanismeCalculation.FailureMechanismSystemType == FailureMechanismSystemType.StabilityInside ||
res.DamFailureMechanismeCalculation.FailureMechanismSystemType == FailureMechanismSystemType.StabilityOutside))
{
mainForm.SetAsActiveTabOnMainPanel(mainForm.DynamicImageControl);
}
// Selecting the result sets the correct property editor as well as the correct line in the table.
try
{
mainForm.Invoke(new TaskDelegate(DataEventPublisher.SelectionChanged), res);
}
catch (Exception)
{
// when all calculations failed but some old result lingers (which it probably shouldnt't) you trigger
// and event for a non existing designCalculationsControl. For now just ignore this error until it is clear
// how DAM should handle "old" results.
}
}
}
}
private void SetProperControlsAfterCalamityCalculation()
{
if (damProject.DamProjectData.GetFirstLocationJobWithCalamityResults() != null)
{
mainForm.SetAsActiveTable(locationsControl);
var res =
damProject.DamProjectData.GetFirstLocationJobWithCalamityResults().
GetFirstLocationResultWithStabilityTimeSerie();
if (res != null &&
res.StabilityTimeSerie.GetNearestBasisFileName(locationJobSymbol.CurrentDateTime) != "")
{
// Make sure the image tab is activated to show the resulting wmf-file (if any)
mainForm.Invoke(new TaskDelegate(DataEventPublisher.SelectionChanged), res.StabilityTimeSerie);
mainForm.SetAsActiveTabOnMainPanel(mainForm.DynamicImageControl);
// Selecting the LocationJob makes sure of proper selected location
mainForm.Invoke(new TaskDelegate(DataEventPublisher.SelectionChanged),
damProject.DamProjectData.GetFirstLocationJobWithCalamityResults());
// Set chart as active tab as this is the only control that actually displays the results next to the wmf-pictures diplayed on the image tab
mainForm.SetAsActiveChart(locationChart);
}
}
}
[Label("Clear Results")]
private void ClearResults()
{
DialogResult dialogResult = LocalizedMessageBox.Show(this, "ClearResultsQuestion", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dialogResult == DialogResult.Yes)
{
if ((this.damProject != null) && (this.damProject.DamProjectData != null))
{
DataEventPublisher.InvokeWithoutPublishingEvents(() =>
{
try
{
damProject.DeleteResults();
lastAssesmentResult = null;
lastDesignResult = null;
lastLocationResult = null;
}
catch (Exception exception)
{
mainForm.Invoke(new ExceptionDelegate(this.ShowErrorMessageBox), exception);
}
finally
{
UpdateForDamApplicationType();
SetProperControlsAfterClearResults();
}
});
}
}
}
private void SetProperControlsAfterClearResults()
{
// update logmessages
mainForm.Invoke(new PublisherDelegate(DataEventPublisher.DataListModified), LogManager.Messages, null);
// update the data
mainForm.Invoke(new TaskDelegate(DataEventPublisher.SelectionChanged), damProject.DamProjectData.LocationJobs.FirstOrDefault());
mainForm.Invoke(new PublisherDelegate(DataEventPublisher.DataListModified), damProject.DamProjectData.LocationJobs, null);
mainForm.Invoke(new TaskDelegate(DataEventPublisher.SelectionChanged), damProject.DamProjectData.WaterBoard.Locations.FirstOrDefault());
// For design, extra action is needed to get rid of the calculation property window
if (damProject.DamProjectData.DamProjectType == DamProjectType.Design)
{
SetProperControlsAfterClearDesignResults();
}
// Set map for main window
mainForm.SetAsActiveTabOnMainPanel(mapControl);
// Set the locations table
mainForm.SetAsActiveTable(locationsControl);
}
private void SetProperControlsAfterClearDesignResults()
{
mainForm.Invoke(new PublisherDelegate(DataEventPublisher.AfterChange), damProject.DamProjectData.LocationJobs.FirstOrDefault(), null);
}
private void ConfigureNavigation()
{
this.damNavigator = new WaterBoardTreeView();
mainForm.NavigatorControl.RegisterResource(typeof(WaterBoard), damNavigator, "Waterboard");
BindSupport.Bind(this.projectPanel, this.damNavigator, typeof(DamProjectData), "WaterBoardJob");
}
private void DataEventPublisher_OnAfterChange(object sender, PublishEventArgs e)
{
if (sender == this.locationJobSymbol)
{
if (e.Property != null && e.Property.Equals("CurrentScenarioType"))
{
DataEventPublisher.AfterChange(this);
}
if (e.Property != null && e.Property.Equals("CurrentDateTime"))
{
if (lastLocationResult != null)
{
ShowLocationImage(lastLocationResult.StabilityTimeSerie, locationJobSymbol.CurrentDateTime);
}
}
}
else if (sender == this.damProject.DamProjectData)
{
if (e.Property != null && e.Property.Equals("DamProjectType"))
{
if (this.damProject.DamProjectData.WaterBoard != null)
{
DataEventPublisher.AfterChange(this.damProject.DamProjectData.WaterBoard);
DataEventPublisher.DataListModified(this.damProject.DamProjectData.Locations);
}
}
}
else if (sender == this.damProject.DamProjectData.WaterBoard)
{
this.damProject.ImportWaterLevelTimeSeries();
this.locationJobSymbol.Update(this.damProject.DamProjectData.LocationJobs);
}
else if (sender == currentLocationJob && sender != null)
{
DataEventPublisher.AfterChange(this, "CurrentLocationJob");
}
}
private void SelectWaterBoardJob(WaterBoardJob job)
{
DataEventPublisher.SelectionChanged(this.damProject.DamProjectData);
}
private void SelectLocationJob(LocationJob locationJob)
{
var location = locationJob.Location;
DataEventPublisher.SelectionChanged(location, PropertyEditorReactionType.Ignore);
if (damProject.DamProjectData.DamProjectType == DamProjectType.Calamity)
{
lastLocationResult = locationJob.GetLocationResultWithStabilityTimeSerie(location.Name);
if (lastLocationResult == null)
{
lastLocationResult = locationJob.GetFirstLocationResultWithStabilityTimeSerie();
}
if (lastLocationResult != null)
{
ShowLocationImage(lastLocationResult.StabilityTimeSerie, locationJobSymbol.CurrentDateTime);
}
else
{
ShowLocationImage(null, locationJobSymbol.CurrentDateTime);
}
}
var resultSelected = false;
if (lastAssesmentResult == null || lastAssesmentResult.Location != location)
{
if (damProject.DamProjectData.DamProjectType == DamProjectType.Assessment)
{
lastAssesmentResult = locationJob.GetRWScenarioResultWithLowestSafetyFactor(this.locationJobSymbol.CurrentScenarioType);
if (lastAssesmentResult != null)
{
ShowAssesmentImage(lastAssesmentResult);
resultSelected = true;
DataEventPublisher.SelectionChanged(lastAssesmentResult, PropertyEditorReactionType.Update);
}
}
}
if (damProject.DamProjectData.DamProjectType == DamProjectType.Design)
{
var designLocation = location;
if (lastDesignResult != null)
{
designLocation = this.damProject.DamProjectData.Locations.Find(x => x.Name == lastDesignResult.LocationName);
}
if (lastDesignResult == null || designLocation != location)
{
lastDesignResult = locationJob.GetFirstDesignResult();
ShowDesignImage(lastDesignResult);
DataEventPublisher.SelectionChanged(lastDesignResult, PropertyEditorReactionType.Ignore);
}
}
var firstProfileResult = damProject.DamProjectData.Calculations.FirstOrDefault(
r => r.Location == location
&& r.ScenarioType == locationJobSymbol.CurrentScenarioType);
if (firstProfileResult != null && !resultSelected)
{
DataEventPublisher.SelectionChanged(firstProfileResult, PropertyEditorReactionType.Ignore);
}
if (resultSelected)
{
DataEventPublisher.SelectionChanged(lastAssesmentResult, PropertyEditorReactionType.Ignore);
}
var firstSchematizationResult = damProject.DamProjectData.SchematizationFactors.FirstOrDefault(
r => r.Location == location
&& r.DecisiveScenarioName == locationJobSymbol.CurrentScenarioType);
if (firstSchematizationResult != null)
{
DataEventPublisher.SelectionChanged(firstSchematizationResult, PropertyEditorReactionType.Ignore);
}
DataEventPublisher.AfterChange(this);
}
private LocationJob FirstMatchingLocationJob(Location location)
{
// get the first matching location job, if any
return damProject.DamProjectData.LocationJobs
.FirstOrDefault(job => job.Location == location);
}
private void SelectFirstMatchingLocationJobIfAny(Location location)
{
var locationJob = FirstMatchingLocationJob(location);
if (locationJob != null)
{
DataEventPublisher.SelectionChanged(locationJob);
}
}
private void SelectLocation(Location location)
{
SelectFirstMatchingLocationJobIfAny(location);
}
private void SelectRWScenarioProfileResult(RWScenarioProfileResult result)
{
lastAssesmentResult = result;
ShowAssesmentImage(lastAssesmentResult);
this.locationJobSymbol.CurrentScenarioType = lastAssesmentResult.ScenarioType;
this.locationJobSymbol.CurrentProfileName = lastAssesmentResult.SoilProfileName;
SelectFirstMatchingLocationJobIfAny(lastAssesmentResult.Location);
DataEventPublisher.AfterChange(this);
}
private void SelectDesignResult(CsvExportData result)
{
lastDesignResult = result;
ShowDesignImage(lastDesignResult);
this.locationJobSymbol.CurrentProfileName = result.ProfileName;
this.locationJobSymbol.CurrentScenarioName = result.ScenarioName;
this.locationJobSymbol.CurrentCalculation = result.StabilityModel.ToString();
var location = damProject.DamProjectData.Locations.Find(x => x.Name == lastDesignResult.LocationName);
if (location != null)
{
SelectFirstMatchingLocationJobIfAny(location);
}
DataEventPublisher.AfterChange(this);
}
private void SelectRWSchematizationFactorResult(RWSchematizationFactorResult result)
{
this.locationJobSymbol.CurrentScenarioType = result.DecisiveScenarioName;
this.locationJobSymbol.CurrentProfileName = result.OriginalDecisiveSoilProfileName;
SelectFirstMatchingLocationJobIfAny(result.Location);
DataEventPublisher.AfterChange(this);
}
private void DataEventPublisher_OnSelectionChanged(object sender, PublishEventArgs e)
{
var type = sender == null ? null : sender.GetType();
if (((SelectionEventArgs)e).PropertyEditorReactionType != PropertyEditorReactionType.Ignore)
{
if (sender is WaterBoardJob)
{
SelectWaterBoardJob((WaterBoardJob)sender);
}
else if (sender is LocationJob)
{
currentLocationJob = (LocationJob)sender;
SelectLocationJob(currentLocationJob);
BindSupport.Assign(this.locationJobPanel, currentLocationJob);
DataEventPublisher.AfterChange(this, "CurrentLocationJob");
}
else if (sender is Location)
{
SelectLocation((Location)sender);
}
else if (sender is SensorLocation)
{
var senderLocation = (SensorLocation)sender;
SelectLocation(senderLocation.Location);
// Activate any custom property editor for SensorLocation here.
}
else if (sender is RWScenarioProfileResult)
{
SelectRWScenarioProfileResult((RWScenarioProfileResult)sender);
}
else if (sender is RWSchematizationFactorResult)
{
SelectRWSchematizationFactorResult((RWSchematizationFactorResult)sender);
}
else if (sender is CsvExportData)
{
SelectDesignResult((CsvExportData)sender);
}
}
}
private void ShowImage(string file)
{
if (!String.IsNullOrEmpty(file))
{
this.mainForm.DynamicImageControl.ZoomablePictureBox.Image
= File.Exists(file) ? Image.FromFile(file) : null;
}
else
{
this.mainForm.DynamicImageControl.ZoomablePictureBox.Image = null;
}
}
private void ShowLocationImage(TimeSerie result, DateTime currentTime)
{
if (result != null)
{
var path = DamProject.ProjectWorkingPath + result.Entries.First().RelativeCalculationPathName;
var file = result.GetNearestBasisFileName(currentTime);
file = path + file + ".wmf";
ShowImage(file);
}
else
{
this.mainForm.DynamicImageControl.ZoomablePictureBox.Image = null;
}
}
private void ShowAssesmentImage(RWScenarioProfileResult result)
{
if (result != null)
{
ShowImage(result.ResultFile);
}
else
{
this.mainForm.DynamicImageControl.ZoomablePictureBox.Image = null;
}
}
private void ShowDesignImage(CsvExportData result)
{
if (result != null)
{
ShowImage(result.ResultFile);
}
else
{
this.mainForm.DynamicImageControl.ZoomablePictureBox.Image = null;
}
}
private void UpdateForDamApplicationType()
{
Assign(this.damProject.DamProjectData);
}
private object NewProject()
{
if (initial)
{
initial = false;
return new DamProjectData();
}
damNewProjectData = new DAMNewProjectData
{
DamProjectType = DamProjectType.Assessment,
DamDataSourceFileName = this.damProject.DamProjectData.DamDataSourceFileName,
DamType = DamType.Regional
};
var dlg = new DamNewProjectDialog { DamNewProjectData = damNewProjectData };
dlg.Visible = false;
if (dlg.ShowDialog() == DialogResult.OK)
{
damProject.ClearProject();
this.damProject.ProjectFileName = dlg.DamNewProjectData.DamProjectFileName;
this.damProject.DamProjectData.DataSourceEsriProjection = dlg.DamNewProjectData.DataSourceEsriProjection;
CalculationManager.Instance.RunCalculation(this.Import);
this.mainForm.FileName = this.damProject.ProjectFileName;
this.mainForm.SetMainWindowCaption(this.damProject.ProjectFileName);
}
return this.damProject;
}
private void SetProperControlsAfterNewProject()
{
// Clear image (if any was there) and set Mapeditor
ShowImage("");
mainForm.SetAsActiveTabOnMainPanel(mapControl);
// Update data lists
//mainForm.Invoke(new PublisherDelegate(DataEventPublisher.DataListModified), damProject.DamProjectData.LocationJobs, null);
// Set Location as active table and property screen, make sure first location is selected.
// update logmessages
//mainForm.Invoke(new PublisherDelegate(DataEventPublisher.DataListModified), LogManager.Messages, null);
// update the data
// Set the locations table
mainForm.SetAsActiveTable(locationsControl);
mainForm.Invoke(new TaskDelegate(DataEventPublisher.SelectionChanged), damProject.DamProjectData.WaterBoard.Locations.FirstOrDefault());
mainForm.Invoke(new TaskDelegate(DataEventPublisher.SelectionChanged), damProject.DamProjectData.LocationJobs.FirstOrDefault());
mainForm.SetAsActivePropertyEditor(locationPropertyControl);
}
private void Import()
{
LogManager.Clear();
this.mainForm.Invoke(new TaskDelegate(DataEventPublisher.SelectionChanged), this.damProject.DamProjectData.WaterBoard);
this.progressDelegate(0);
Application.UseWaitCursor = true;
try
{
LogManager.Clear();
var projectType = this.damNewProjectData.DamProjectType;
var fileName = this.damNewProjectData.DamDataSourceFileName;
DataSourceContainer dataSourceContainer = DataSourceContainer.Deserialize(fileName);
string damProjectFolder = Path.GetDirectoryName(fileName);
dataSourceContainer.DataSourceEsriProjection = dataSourceContainer.DataSourceEsriProjection ?? this.damNewProjectData.DataSourceEsriProjection;
DataEventPublisher.ThreadPublisher = new ThreadPublisher();
// ATTENTION: Do not stop DataEventPublisher because it is needed to determine the source of the data with DataSourceManager
DataSourceManager.StartListening();
this.damProject.Import(damProjectFolder, dataSourceContainer, this.damNewProjectData.SelectedDikeRingIds, this.damNewProjectData.DamType,
this.damNewProjectData.DamProjectType, this.progressDelegate);
// Importing data creates a new DamProjectData object so the values set in the dialog have to be reset.
damProject.DamProjectData.DamProjectType = projectType;
damProject.DamProjectData.DamDataSourceFileName = fileName;
if (dataSourceContainer.MapSoilProfile2D != null)
{
// Make sure the 2D-geometrie map is assigned
damProject.AssignGeometry2DMapnameIfNotAssigned(Path.Combine(damProjectFolder, dataSourceContainer.MapSoilProfile2D));
}
// If profiles are defined as relative profiles, new absolute profiles will be generated for each location
if (dataSourceContainer.IsImportAsRelativeProfiles)
{
WaterBoardPostProcessRelativeProfiles.CreateAbsoluteProfiles(damProject.DamProjectData.WaterBoard, dataSourceContainer.SoilProfileCharacteristicPointReference);
}
this.damProject.DamProjectData.DataSources = DataSourceManager.DataSources;
// Read sensor data if DamLive Configuration project
if (this.damNewProjectData.DamProjectType == DamProjectType.DamLiveConfiguration)
{
if (this.damProject.DamProjectData.WaterBoard.Dikes.Count != 1)
{
throw new DataPluginImporterException(String.Format("DamLive Configuration must have exactly 1 dike; this project has {0} dikes", this.damProject.DamProjectData.WaterBoard.Dikes.Count));
}
var dike = this.damProject.DamProjectData.WaterBoard.Dikes.First();
var sensorConfigurationFilename = Path.GetFullPath(this.damNewProjectData.SensorConfigurationFileName);
if (File.Exists(sensorConfigurationFilename))
{
SensorImportFromExcelSheet.ReadSensorDataFromExcel(sensorConfigurationFilename, dike);
damProject.DamProjectData.FillOverallSensorData();
}
}
// Save the data
this.damProject.SaveXMLProject(this.damProject.ProjectFileName, this.damProject);
this.progressDelegate(1);
mainForm.Invoke(new EmptyDelegate(this.UpdateForDamApplicationType));
mainForm.Invoke(new TaskDelegate(DataEventPublisher.SelectionChanged), damProject.DamProjectData.LocationJobs.FirstOrDefault());
DataEventPublisher.TransferBindingsToDefaultPublisher();
}
catch (Exception e)
{
Application.UseWaitCursor = false;
mainForm.Invoke(new ExceptionDelegate(this.ShowImportErrorMessage), e);
}
finally
{
Application.UseWaitCursor = false;
}
}
///
/// General error message
///
///
///
private void ShowErrorMessageBox(Exception e)
{
var msg = e.Message + Environment.NewLine;
var exception = e.InnerException;
while (exception != null)
{
msg += exception.Message + Environment.NewLine;
exception = exception.InnerException;
}
var args = new object[]
{
msg
};
LocalizedMessageBox.ShowError(this, "ErrorMessage", args);
}
///
/// Show import error messages
///
///
private void ShowImportErrorMessage(Exception e)
{
var msg = e.Message + Environment.NewLine;
var exception = e.InnerException;
while (exception != null)
{
msg += exception.Message + Environment.NewLine;
exception = exception.InnerException;
}
var args = new object[]
{
Environment.NewLine,
this.damNewProjectData.DamDataSourceFileName,
Environment.NewLine + Environment.NewLine,
Environment.NewLine,
msg
};
LocalizedMessageBox.ShowError(this, "ErrorImportingDataSourceFile", args);
}
[Label("Options")]
public void ShowCalculationOptions()
{
DataEventPublisher.SelectionChanged(damProject.DamProjectData.WaterBoardJob);
if (damProject.DamProjectData.DamProjectType == DamProjectType.Calamity ||
damProject.DamProjectData.DamProjectType == DamProjectType.Design)
{
FormsSupport.MakeTreeVisible(damProjectCalculationSpecificationPropertyControl);
}
else if (damProject.DamProjectData.DamProjectType == DamProjectType.Assessment)
{
FormsSupport.MakeTreeVisible(assessmentCalculationSpecificationPropertyControl);
}
}
[Label("Calculation file")]
public void SaveCalculation()
{
SaveFile("MStab files (*.sti)|*.sti");
}
[Label("Calculation image")]
public void SaveImage()
{
SaveFile("*.wmf|*.sti");
}
private void SaveFile(string filter)
{
var filenameRes = "";
if (damProject.DamProjectData.DamProjectType != DamProjectType.Design)
{
if (lastAssesmentResult == null || !File.Exists(lastAssesmentResult.ResultFile)) return;
filenameRes = lastAssesmentResult.ResultFile;
}
else
{
if (lastDesignResult == null || !File.Exists(lastDesignResult.ResultFile)) return;
filenameRes = lastDesignResult.ResultFile;
}
var saveFileDialog = new SaveFileDialog { Filter = filter };
var fileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
+ Path.DirectorySeparatorChar
+ Path.GetFileName(filenameRes);
saveFileDialog.FileName = fileName;
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
File.Copy(filenameRes, saveFileDialog.FileName);
}
}
public bool IsVisible(string property)
{
switch (property)
{
case "IsChartVisible":
return damProject.DamProjectData.DamProjectType != DamProjectType.Design;
}
return true;
}
public bool IsEnabled(string property)
{
switch (property)
{
case "SaveCalculation": return (lastAssesmentResult != null) || (lastDesignResult != null);
case "SaveImage": return lastAssesmentResult != null;
case "ExecuteSurfacelinesExport":
return this.damProject != null && this.damProject.DamProjectData != null &&
this.damProject.DamProjectData.DamProjectType == DamProjectType.Design && this.damProject.DamProjectData.LocationJobs != null &&
this.damProject.DamProjectData.LocationJobs.Count > 0;
case "ExecuteScenarioExport":
return this.damProject != null && this.damProject.DamProjectData != null &&
this.damProject.DamProjectData.DamProjectType == DamProjectType.Assessment && this.damProject.DamProjectData.LocationJobs != null &&
this.damProject.DamProjectData.LocationJobs.Count > 0;
case "ClearResults":
return this.damProject != null && this.damProject.DamProjectData != null &&
this.damProject.DamProjectData.HasResults();
case "ShowCalculationOptions":
return this.damProject != null &&
this.damProject.DamProjectData != null &&
this.damProject.DamProjectData.LocationJobs != null &&
(this.damProject.DamProjectData.DamProjectType == DamProjectType.Assessment ||
this.damProject.DamProjectData.DamProjectType == DamProjectType.Calamity ||
this.damProject.DamProjectData.DamProjectType == DamProjectType.Design) &&
this.damProject.DamProjectData.LocationJobs.Count > 0;
default: return true;
}
}
///
/// Export the redesigned surfacelines
///
///
void ExportRedesignedSurfacelines(string path)
{
DataEventPublisher.InvokeWithoutPublishingEvents(() =>
{
string baseFilename = Path.Combine(path,
Path.GetFileNameWithoutExtension(this.damProject.ProjectFileName));
List exportListCharacteristicPoints;
List exportListSurfaceLines;
// Build list (for piping) of redesigsurfacelines and list of surfacelines with charateristic points and write them
exportListCharacteristicPoints = new List();
exportListSurfaceLines = new List();
var newlyCreatedSurfaceLines = new List();
foreach (CsvExportData designResult in this.damProject.DamProjectData.DesignCalculations)
{
var redesignedSurfaceLinePipingGlobal = designResult.CreateRedesignedSurfaceLineGlobal();
if (redesignedSurfaceLinePipingGlobal != null)
{
newlyCreatedSurfaceLines.Add(redesignedSurfaceLinePipingGlobal);
// Identifiers
var csvExportSurfaceLineIdentifiers = CreateCsvExportSurfaceLineIdentifiers(designResult);
// Characteristic points
exportListCharacteristicPoints.Add(new CsvExportCharacteristicPoints(csvExportSurfaceLineIdentifiers, redesignedSurfaceLinePipingGlobal));
// Surfaceline
exportListSurfaceLines.Add(new CsvExportSurfaceLine(csvExportSurfaceLineIdentifiers, redesignedSurfaceLinePipingGlobal));
}
}
if (exportListCharacteristicPoints.Count > 0)
{
WriteSurfacelines(baseFilename + "_Piping", exportListSurfaceLines, exportListCharacteristicPoints);
}
foreach (var newlyCreatedGlobalSurfaceLine in newlyCreatedSurfaceLines)
{
newlyCreatedGlobalSurfaceLine.Dispose();
}
newlyCreatedSurfaceLines.Clear();
// Build list (for stability) of redesigsurfacelines and list of surfacelines with charateristic points and write them
exportListCharacteristicPoints = new List();
exportListSurfaceLines = new List();
foreach (CsvExportData designResult in this.damProject.DamProjectData.DesignCalculations)
{
var globalRedesignedSurfaceLine = designResult.CreateRedesignedSurfaceLineGlobal();
if (globalRedesignedSurfaceLine != null)
{
newlyCreatedSurfaceLines.Add(globalRedesignedSurfaceLine);
// Identifiers
var csvExportSurfaceLineIdentifiers = CreateCsvExportSurfaceLineIdentifiers(designResult);
// Characteristic points
exportListCharacteristicPoints.Add(new CsvExportCharacteristicPoints(csvExportSurfaceLineIdentifiers, globalRedesignedSurfaceLine));
// Surfaceline
exportListSurfaceLines.Add(new CsvExportSurfaceLine(csvExportSurfaceLineIdentifiers, globalRedesignedSurfaceLine));
}
}
if (exportListCharacteristicPoints.Count > 0)
{
WriteSurfacelines(baseFilename + "_Stability", exportListSurfaceLines, exportListCharacteristicPoints);
}
foreach (var newlyCreatedGlobalSurfaceLine in newlyCreatedSurfaceLines)
{
newlyCreatedGlobalSurfaceLine.Dispose();
}
newlyCreatedSurfaceLines.Clear();
});
}
///
/// Creates the CSV export surfaceline identifiers, based on the designresult.
///
/// The design result.
///
private static CsvExportSurfaceLineIdentifiers CreateCsvExportSurfaceLineIdentifiers(CsvExportData designResult)
{
var csvExportSurfaceLineIdentifiers = new CsvExportSurfaceLineIdentifiers
{
LocationId = designResult.LocationName,
SoilProfileId = designResult.ProfileName,
Scenario = designResult.LocationScenarioId,
CalculationMechanism = designResult.DamFailureMechanismeCalculation.FailureMechanismSystemType.ToString(),
CalculationModel = ""
};
switch (designResult.DamFailureMechanismeCalculation.FailureMechanismSystemType)
{
case FailureMechanismSystemType.StabilityOutside:
csvExportSurfaceLineIdentifiers.CalculationModel =
designResult.DamFailureMechanismeCalculation.StabilityModelType.ToString();
break;
case FailureMechanismSystemType.StabilityInside:
csvExportSurfaceLineIdentifiers.CalculationModel =
designResult.DamFailureMechanismeCalculation.StabilityModelType.ToString();
break;
case FailureMechanismSystemType.Piping:
csvExportSurfaceLineIdentifiers.CalculationModel =
designResult.DamFailureMechanismeCalculation.PipingModelType.ToString();
break;
case FailureMechanismSystemType.HorizontalBalance:
break;
}
return csvExportSurfaceLineIdentifiers;
}
///
/// Writes the surfacelines.
///
/// The base filename.
/// The export list of surface lines.
/// The export list of characteristic points of the surface lines.
private void WriteSurfacelines(string baseFilename, List exportListSurfaceLines, List exportListCharacteristicPoints)
{
// Export lines with characteristic points
string fileNameCharacteristicPoints = baseFilename + "_CharacteristicPoints.csv";
var characteristicPointCsvExporter = new CsvExporter(
Path.Combine(baseFilename, fileNameCharacteristicPoints), exportListCharacteristicPoints)
{
WriteHeaderInFirstLine = true
};
characteristicPointCsvExporter.WriteFile();
// Export surfacelines
string fileNameSurfaceline = baseFilename + "_Surfacelines.csv";
var surfacelineCsvExporter = new CsvExporter(Path.Combine(
baseFilename, fileNameSurfaceline), exportListSurfaceLines)
{
WriteHeaderInFirstLine = true
};
surfacelineCsvExporter.WriteFile();
}
public bool IsVisible(object source, string property)
{
if (source is WaterBoard)
{
switch (property)
{
case "SelectedDike":
return StabilityKernelTypeSpecificationsVisible;
default:
return true;
}
}
return true;
}
public bool IsEnabled(object source, string property)
{
return true;
}
public void Dispose()
{
damProject.Dispose();
}
}
}