// Copyright (C) Stichting Deltares 2016. All rights reserved. // // This file is part of the D-Soil Model application. // // The D-Soil Model application 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; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.IO; using System.Linq; using System.Windows.Forms; using Deltares.DSoilModel.Data; using Deltares.Geographic; using Deltares.Geometry; using Deltares.Geometry.Forms; using Deltares.Geotechnics; using Deltares.Geotechnics.ConePenetrationTest; using Deltares.Geotechnics.Forms; using Deltares.Geotechnics.IO; using Deltares.Geotechnics.Mechanisms; using Deltares.Probabilistic; using Deltares.Standard; using Deltares.Standard.Attributes; using Deltares.Standard.EventPublisher; using Deltares.Standard.Forms; using Deltares.Standard.Forms.DExpress; using Deltares.Standard.Forms.Maps; using Deltares.Standard.Forms.Properties; using Deltares.Standard.IO; using Deltares.Standard.Language; using Deltares.Standard.Logging; using Deltares.Standard.Maps; using Deltares.Standard.Reflection; using Deltares.Standard.Units; using DevExpress.XtraBars; using DevExpress.XtraEditors.Controls; using DevExpress.XtraEditors.Repository; using DotSpatial.Controls; using DotSpatial.Symbology; using FeatureSupport = Deltares.Standard.Maps.FeatureSupport; namespace Deltares.DSoilModel.Forms { /// /// Main Class for D-Soil Model /// public class DSoilModelPlugin : IMainFormPlugin, IVisibleEnabled, IDisposable { private readonly SplitContainer filmStripContainer; private readonly Panel pluginPanel = new Panel(); private readonly Dictionary previouslySelectedProfiles = new Dictionary(); private readonly Panel projectPanel = new Panel(); private SegmentControl segmentControl; private readonly List selectedObjects = new List(); private readonly GeometryEditor extraGeometryEditor = new GeometryEditor(); private FilmStrip filmStrip; private MainForm mainForm; private readonly MapEditor mapControl = new MapEditor(); private GridViewControl materialsTable; private GridViewControl cptsTable; private GridViewControl boringsTable; private GridViewControl soilProfiles1DTable; private GridViewControl soilProfiles2DTable; private DSoilModelProject project; private bool use1DProfiles = true; private bool use2DProfiles = true; private bool useBorings = true; private bool useSoilSegments = true; private bool useSurfaceLines = true; public DSoilModelPlugin() { UndoRedoManager.Instance.Clear(); UndoRedoManager.UseManager = false; ConfigureSoilUserFilters(); GridViewControl.SupportedExportedFileTypes = new[] { ExportFileTypes.csv }; Standard.Forms.Maps.MapEditor.SupportedExportedFileTypes = new[] { ExportFileTypes.png, ExportFileTypes.bmp, ExportFileTypes.jpeg }; // Enable the data source manager DataSourceManager.Active = true; DataSourceManager.StartListening(); DataSourceManager.Redirector = new DSoilModelDataSourceRedirector(); // Further changes from here on are user changes DataSourceManager.CurrentSource = DataSourceSystemType.User; // Create the container for the geometry editor and the film strip filmStripContainer = new SplitContainer { Dock = DockStyle.Fill, Orientation = Orientation.Horizontal, BorderStyle = BorderStyle.FixedSingle, Panel1Collapsed = false, Panel2Collapsed = true }; filmStripContainer.SizeChanged += FilmStripContainer_OnSizeChanged; filmStripContainer.SplitterMoving += FilmStripContainer_OnSplitterMoving; filmStripContainer.SplitterMoved += FilmStripContainer_OnSplitterMoved; } /// /// Gets or sets the D-Soil Model Project. /// /// /// The project. /// public DSoilModelProject Project { get { return project; } set { project = value; Assign(project); } } /// /// The geometry editor for this DSoilModel plugin. /// public DSoilModelGeometryEditor GeometryEditor { get; set; } /// /// The segment geometry editor for this DSoilModel plugin. /// public DSoilModelSegmentGeometryEditor SegmentGeometryEditor { get; set; } /// /// The map editor for this DSoilModel plugin. /// public DSoilModelMapEditor MapEditor { get; set; } /// /// Gets or sets whether Soil Segments are used in the D-Soil Model plugin. /// public bool UseSoilSegments { get { return useSoilSegments; } set { useSoilSegments = value; } } /// /// Gets or sets whether 1D Profiles are used in the D-Soil Model plugin. /// public bool Use1DProfiles { get { return use1DProfiles; } set { use1DProfiles = value; } } /// /// Gets or sets whether 2D Profiles are used in the D-Soil Model plugin. /// public bool Use2DProfiles { get { return use2DProfiles; } set { use2DProfiles = value; } } /// /// Gets or sets whether Surface Lines are used in the D-Soil Model plugin. /// public bool UseSurfaceLines { get { return useSurfaceLines; } set { useSurfaceLines = value; } } /// /// Gets or sets whether Borings are used in the D-Soil Model plugin. /// public bool UseBorings { get { return useBorings; } set { useBorings = value; } } public void InvisibleMethod() { ; // added to hide some toolbarbuttons in the validation table } public void Dispose() { if (materialsTable != null) { materialsTable.CanDelete = null; cptsTable.CanDelete = null; boringsTable.CanDelete = null; soilProfiles1DTable.CanDelete = null; soilProfiles2DTable.CanDelete = null; } if (null != GeometryEditor) { GeometryEditor.Dispose(); } if (null != SegmentGeometryEditor) { SegmentGeometryEditor.Dispose(); } if (null != project) { project.Dispose(); } filmStripContainer.SplitterMoved -= FilmStripContainer_OnSplitterMoved; filmStripContainer.SplitterMoving -= FilmStripContainer_OnSplitterMoving; filmStripContainer.Resize -= FilmStripContainer_OnSizeChanged; DataEventPublisher.OnDataListModified -= DataEventPublisherOnDataListModified; DataEventPublisher.OnAfterChange -= DataEventPublisherOnAfterChange; DataEventPublisher.OnChanged -= DataEventPublisherOnChanged; DataEventPublisher.OnSelectionChanged -= DataEventPublisherOnSelectionChanged; } public void Configure(MainForm aMainForm) { mainForm = aMainForm; mainForm.UseTemplateDialog = true; DataEventPublisher.OnDataListModified += DataEventPublisherOnDataListModified; DataEventPublisher.OnAfterChange += DataEventPublisherOnAfterChange; DataEventPublisher.OnChanged += DataEventPublisherOnChanged; DataEventPublisher.OnSelectionChanged += DataEventPublisherOnSelectionChanged; mainForm.RegisterNewFileHandler(CreateNewFile); mainForm.RegisterOpenFileHandler("soil", "Soilbase files (*.soil)|*.soil", DSoilModelIO.OpenSoilDatabase); mainForm.RegisterSaveFileHandler("soil", "Soilbase files (*.soil)|*.soil", DSoilModelIO.SaveSoilDatabase); mainForm.UseSpatialEditor(); mainForm.UseProperties(); mainForm.UseTables(); mainForm.UseValidation(); mainForm.UseOutput(); mainForm.AddControl(mapControl); extraGeometryEditor.Title = LocalizationManager.GetTranslatedText(typeof(DSoilModelPlugin), "Extra Geometry"); extraGeometryEditor.SpatialEditor.ReadUserValues(); mainForm.AddControl(extraGeometryEditor); var context = new DSoilModelContext { ParameterView = ParameterViewSettings.AllParameters }; Context.CurrentContext = context; segmentControl = new SegmentControl(); ConfigureMenus(); ConfigureGeometryEditor(); ConfigureSegmentGeometryEditor(); ConfigureMapEditor(); ConfigurePropertyGrid(); ConfigureTables(); ReliabilityView.IsReliability = true; // set default probability unit KnownUnits.Units.Probability = ProbabilityUnit.Percentage; UnitsManager.SetUnitTypeUsed(UnitType.Probability, true); mainForm.ProjectIsSaved(""); BindSupport.Assign(pluginPanel, this); SetApplicationIcon(); ConfigureSoilMechanisms(); // by loading the settings dialog here, we can prevent it from showing the units tab page (temporary for WTI) mainForm.CreateSettingsDialog(true, false); // Make sure language stays Dutch (even when "old" settings tell it to be english). if (mainForm.ProgramSettings.Language != LanguageType.Dutch) { // setting the same language again produces side effects mainForm.ProgramSettings.Language = LanguageType.Dutch; } mainForm.ProgramSettings.AllowLanguageSelection = false; mainForm.ProgramSettings.ShowLanguageSelection = false; } public void Assign(object source) { var modelProject = source as DSoilModelProject; if (modelProject != null) { project = modelProject; project.CurrentFailureMechanism = Mechanism.None; StochasticSoilProfile.GetProfiles = project.GetProfiles; ConePenetrationTestPerSegment.GetCpts = project.GetCpts; BoringPerSegment.GetBorings = project.GetBorings; SoilSegment.GetCpts = project.GetCpts; SoilSegment.GetBorings = project.GetBorings; SoilSegment.GetSurfaceLines = project.GetSurfaceLines; SoilSegment.UpdateForNewSoilSurfaceProfiles = UpdateForNewSoilSurfaceProfiles; BindSupport.Assign(projectPanel, project); extraGeometryEditor.Title = LocalizationManager.GetTranslatedText(typeof(DSoilModelPlugin), "Extra Geometry"); extraGeometryEditor.DeselectAllObjects(); extraGeometryEditor.Clear(); MapEditor.Project = project; GeometryEditor.Project = project; SegmentGeometryEditor.Project = project; RealTimeBackgroundValidator.Instance.Register(project); if (!DSoilModelProject.IsAutoValidationEnabled) { RealTimeBackgroundValidator.Instance.Stop(); } // Set correct active table. if (project.Soils.Soils.Count == 0 && project.CPTs.Count > 0) { mainForm.SetAsActiveTable(cptsTable); } else { mainForm.SetAsActiveTable(materialsTable); } // Activate first line in table and set proper property window. project.ActivateFirstData(); } } public bool IsVisible(string property) { switch (property) { case "InvisibleMethod": return false; case "DamDefxImport": // DSB-408: suspending functionality until better times return false; default: return true; } } public bool IsEnabled(string property) { switch (property) { case "SoilProfile1DImport": case "GeometryImport": return true; case "CharacteristicPointsImport": // needs surfacelines return (project != null && project.SurfaceLines.Count > 0); case "SoilSegmentsCsvImport": // needs soilprofiles return (project != null && (project.SoilProfiles1D.Count > 0 || project.SoilProfiles2D.Count > 0)); case "SoilSegmentsShapeImport": // needs soilprofiles + segment csv return (project != null && project.SoilSegments.Count > 0 && (project.SoilProfiles1D.Count > 0 || project.SoilProfiles2D.Count > 0)); default: return true; } } private bool UpdateForNewSoilSurfaceProfiles(List stochasticSoilProfiles) { DataEventPublisher.BeforeChange(project.SoilProfiles2D); foreach (var stochasticSoilProfile in stochasticSoilProfiles) { if (stochasticSoilProfile != null && stochasticSoilProfile.Profile is SoilProfile2D) { var prof = project.SoilProfiles2D.Find(x => x.Name == stochasticSoilProfile.Profile.Name); if (prof != null) { prof = (SoilProfile2D) stochasticSoilProfile.Profile; } else { project.SoilProfiles2D.Add((SoilProfile2D) stochasticSoilProfile.Profile); } } } return true; } private object CreateNewFile() { // NOTE: this method called with disabled DataEventPublisher. Take care of updating controls yourself. LogManager.Clear(); GeometryEditor.Clear(); return new DSoilModelProject(); } private UserColumnFilters? GetSoilUserFilterFromMaterialTable() { var selectedFilterText = materialsTable.SelectedFilter.Text; UserColumnFilters? selectedFilterValue; try { selectedFilterValue = (UserColumnFilters) Enum.Parse(typeof(UserColumnFilters), selectedFilterText); } catch (ArgumentException) { // Filter "All" or not a valid member of the UserColumnFilters enumeration selectedFilterValue = null; } return selectedFilterValue; } private void UpdatePropertyControl() { if (mainForm.DynamicPropertyControl != null && mainForm.DynamicPropertyControl.SelectedObject != null) { DataEventPublisher.AfterChange(mainForm.DynamicPropertyControl.SelectedObject); } } private void SetApplicationIcon() { try { var icon = new System.Drawing.Icon(this.GetType().Assembly.GetManifestResourceStream( "Deltares.DSoilModel.Forms.Resources.D-SoilModel.ico")); this.mainForm.UseIcon(icon); } catch (Exception) { // Kill exception for Windows XP if load fails // Todo: Solve exception; see MWDAM-391 } } private void EnableSoilUserFilterForMaterialTable(bool enable) { materialsTable.AllowUserColumnFilterEdit = enable; } private void SetSoilUserFilterToNearestMatchForMechanism(Mechanism currentMechanism) { var dSoilModelContext = Context.CurrentContext as DSoilModelContext; if (dSoilModelContext != null) { // Set corresponding soiluserfilter switch (currentMechanism) { case Mechanism.Piping : { // In fact you should set the selectedFilter for the materialsTable here too but there is no way to do that now. // (as you can never get a proper value (UserColumnFilterDisplayItem) for that as this is not public. dSoilModelContext.SoilUserFilter = UserColumnFilters.PipingWti; break; } case Mechanism.Stability: { dSoilModelContext.SoilUserFilter = UserColumnFilters.MacrostabilityWti; break; } case Mechanism.FlowSlide: { dSoilModelContext.SoilUserFilter = UserColumnFilters.FlowSlideWti; break; } } } } private void DataEventPublisherOnDataListModified(object sender, PublishEventArgs publishEventArgs) { if (sender is List) { mainForm.DynamicTableControl.GetTable(typeof(SurfaceLine2)).Refresh(); } var args = publishEventArgs as DataListModifiedArgs; if (args != null && args.Action == ListModifyAction.Delete && args.Objects.Any()) { if (sender == Project.Soils.Soils || sender == Project.CPTs || sender == Project.Borings || sender == Project.SoilProfiles1D|| sender == Project.SoilProfiles2D|| sender == Project.SurfaceLines || sender == Project.CurrentSoilSegments) { if ((sender as IList).Count == 0) { // there will be no item to reselect Delayed.Invoke(() => mainForm.DynamicPropertyControl.SelectedObject = null); } } } } private void DataEventPublisherOnChanged(object sender, PublishEventArgs e) { if (UndoRedoManager.UseManager == false) { // note: as the UndoRedoManager is not sending EndAction events the validator can respond to, start it here (see DSB-473) if (DSoilModelProject.IsAutoValidationEnabled) { RealTimeBackgroundValidator.Instance.Start(); } } } private void DataEventPublisherOnAfterChange(object sender, PublishEventArgs publishEventArgs) { var localProject = sender as DSoilModelProject; if (localProject != null && publishEventArgs.Property != null) { if (publishEventArgs.Property.Equals("ParameterView")) { var dSoilModelContext = Context.CurrentContext as DSoilModelContext; if (dSoilModelContext != null) { dSoilModelContext.ParameterView = localProject.ParameterView; } DataEventPublisher.DataListModified(localProject.Soils.Soils); var soilProfile2D = mainForm.DynamicPropertyControl.SelectedObject as SoilProfile2D; if (soilProfile2D != null) { DataEventPublisher.DataListModified(soilProfile2D.PreconsolidationStresses); } UpdatePropertyControl(); } if (publishEventArgs.Property.Equals("CurrentFailureMechanism")) { if (project.CurrentFailureMechanism != Mechanism.None) { SetSoilUserFilterToNearestMatchForMechanism(project.CurrentFailureMechanism); EnableSoilUserFilterForMaterialTable(true); } else { EnableSoilUserFilterForMaterialTable(true); } UpdatePropertyControl(); } if (UndoRedoManager.UseManager == false) { // note: as the UndoRedoManager is not sending EndAction events the validator can respond to, start it here (see DSB-473) if (DSoilModelProject.IsAutoValidationEnabled) { RealTimeBackgroundValidator.Instance.Start(); } } } if (sender == materialsTable) { if (publishEventArgs.Property.Equals("SelectedFilter")) { var dSoilModelContext = Context.CurrentContext as DSoilModelContext; if (dSoilModelContext != null) { dSoilModelContext.SoilUserFilter = GetSoilUserFilterFromMaterialTable(); UpdatePropertyControl(); } } } if (sender == mainForm) { DataEventPublisher.DataListModified(LogManager.Messages); } var layer = sender as SoilLayer1D; if (layer != null && layer.SoilProfile != null && (publishEventArgs.Property == layer.GetMemberName(l => l.TopLevel) || publishEventArgs.Property == layer.GetMemberName(l => l.BottomLevel))) { DataEventPublisher.AfterChange(layer.SoilProfile, publishEventArgs.Property); DataEventPublisher.DataListModified(project.SoilProfiles1D); } var sp1d = sender as SoilProfile1D; if (sp1d != null) { DataEventPublisher.DataListModified(sp1d.Layers); } } private void DataEventPublisherOnSelectionChanged(object sender, PublishEventArgs publishEventArgs) { // keep track of multiple selections for the purpose of saving a subset of soil segment data if (publishEventArgs.Objects == null || publishEventArgs.Objects.Length == 0) { if (sender is IGeographic || sender is IHasGeographic) { selectedObjects.Clear(); selectedObjects.Add(sender); } } else { selectedObjects.Clear(); selectedObjects.AddRange(publishEventArgs.Objects); } HandleStochasticSoilModel(sender); } private void HandleStochasticSoilModel(object sender) { var action = new Action(() => { var soilSegment = sender as SoilSegment; if (soilSegment != null) { HandleSoilSegment(soilSegment); } var stochasticSoilProfile = sender as StochasticSoilProfile; if (stochasticSoilProfile != null) { HandleStochasticSoilProfile(stochasticSoilProfile); } }); UpdateFilmStripLayout(action); } private void ConfigureMenus() { BarManager barManager = mainForm.TemplateBarManager; // alias Bar menuBar = mainForm.MenuBar; // alias try { barManager.BeginUpdate(); // Remove the "Calculation" menu. It is not required for D-Soil Model. int j = 0; while (j < menuBar.ItemLinks.Count) { BarItemLink barItemLink2 = menuBar.ItemLinks[j]; if (barItemLink2.Caption == "Calculation") { menuBar.RemoveLink(barItemLink2); break; } j++; } // Remove the link: Tools->License var licenseItemLink = mainForm.ToolsMenu.ItemLinks.Cast().FirstOrDefault(il => il.Item.Name == "LicenseBarButton"); mainForm.ToolsMenu.ItemLinks.Remove(licenseItemLink); // Add CurrentMechanism dropdown to Toolbar var mechanismComboBox = new RepositoryItemComboBox { TextEditStyle = TextEditStyles.DisableTextEditor, DropDownRows = 10 }; var mechanismBarItem = new BarEditItem { Caption = "MechanismSelector", Width = 100, Edit = mechanismComboBox }; mainForm.ToolBar.AddItem(mechanismBarItem); LocalizationSupport.RegisterAndTranslate(typeof(DSoilModelPlugin), mechanismBarItem); BindSupport.Bind(projectPanel, mechanismBarItem, x => x.CurrentFailureMechanism); // Add ParameterView dropdown to Toolbar var parameterViewComboBox = new RepositoryItemComboBox { TextEditStyle = TextEditStyles.DisableTextEditor, DropDownRows = 3 }; var parameterViewBarItem = new BarEditItem { Caption = "ParameterViewSelector", Width = 150, Edit = parameterViewComboBox }; mainForm.ToolBar.AddItem(parameterViewBarItem); LocalizationSupport.RegisterAndTranslate(typeof(DSoilModelPlugin), parameterViewBarItem); BindSupport.Bind(projectPanel, parameterViewBarItem, x => x.ParameterView); } finally { barManager.EndUpdate(); } AddNewMenuItems(); } private void AddNewMenuItems() { // Save selection as var saveSelectionAsMenuItem = new BarButtonItem { Caption = LocalizationManager.GetTranslatedText(this, "SaveSelectedDataAs"), Name = "SaveSelection", ItemShortcut = new BarShortcut(Keys.F11) }; var beforeLink = mainForm.FileMenu.ItemLinks[4]; mainForm.FileMenu.InsertItem(beforeLink, saveSelectionAsMenuItem); BindSupport.Bind(pluginPanel, saveSelectionAsMenuItem, p => p.SaveSelectedDataAs()); // Soil database importer var importSoilsItemMenuItem = new BarButtonItem { Caption = LocalizationManager.GetTranslatedText(this, "SoilsImport"), Name = "SoilsImportItem" }; mainForm.ImportMenu.AddItems(new BarItem[] { importSoilsItemMenuItem }); BindSupport.Bind(pluginPanel, importSoilsItemMenuItem, p => p.SoilsImport()); // Profile1D file importer (CSV) if (Use1DProfiles) { var importSoilProfile1DItemMenuItem = new BarButtonItem { Caption = LocalizationManager.GetTranslatedText(this, "SoilProfile1DImport"), Name = "SoilProfile1DImportMenu" }; mainForm.ImportMenu.AddItems(new BarItem[] { importSoilProfile1DItemMenuItem }); BindSupport.Bind(pluginPanel, importSoilProfile1DItemMenuItem, p => p.SoilProfile1DImport()); } // Geometry file importer if (use2DProfiles) { var importGeometryItemMenuItem = new BarButtonItem { Caption = LocalizationManager.GetTranslatedText(this, "GeometryImport"), Name = "GeometryImportMenu" }; mainForm.ImportMenu.AddItems(new BarItem[] { importGeometryItemMenuItem }); BindSupport.Bind(pluginPanel, importGeometryItemMenuItem, p => p.GeometryImport()); } // Surface line & characteristic points CSV file importer if (useSurfaceLines) { var importSurfaceLineItemMenuItem = new BarButtonItem { Caption = LocalizationManager.GetTranslatedText(this, "SurfaceLineImport"), Name = "SurfaceLineImportMenu" }; mainForm.ImportMenu.AddItems(new BarItem[] { importSurfaceLineItemMenuItem }); BindSupport.Bind(pluginPanel, importSurfaceLineItemMenuItem, p => p.SurfaceLineImport()); var importCharacteristicPointsItemMenuItem = new BarButtonItem { Caption = LocalizationManager.GetTranslatedText(this, "CharacteristicPointsImport"), Name = "CharacteristicPointsImportMenu" }; mainForm.ImportMenu.AddItems(new BarItem[] { importCharacteristicPointsItemMenuItem }); BindSupport.Bind(pluginPanel, importCharacteristicPointsItemMenuItem, p => p.CharacteristicPointsImport()); } if (useSoilSegments) { // Csv soil segments importer var importSoilSegmentsCsvItemMenuItem = new BarButtonItem { Caption = LocalizationManager.GetTranslatedText(this, "SoilSegmentsCsvImport"), Name = "SoilSegmentsImportCsvMenu" }; mainForm.ImportMenu.AddItems(new BarItem[] { importSoilSegmentsCsvItemMenuItem }); BindSupport.Bind(pluginPanel, importSoilSegmentsCsvItemMenuItem, p => p.SoilSegmentsCsvImport()); // Shape soil segments importer var importSoilSegmentsShapeItemMenuItem = new BarButtonItem { Caption = LocalizationManager.GetTranslatedText(this, "SoilSegmentsShapeImport"), Name = "SoilSegmentsImportShapeMenu" }; mainForm.ImportMenu.AddItems(new BarItem[] { importSoilSegmentsShapeItemMenuItem }); BindSupport.Bind(pluginPanel, importSoilSegmentsShapeItemMenuItem, p => p.SoilSegmentsShapeImport()); } // GEF CPT file importer var importGefCptItemMenuItem = new BarButtonItem { Caption = LocalizationManager.GetTranslatedText(this, "GefCptImport"), Name = "GefCptImportMenu" }; mainForm.ImportMenu.AddItems(new BarItem[] { importGefCptItemMenuItem }); BindSupport.Bind(pluginPanel, importGefCptItemMenuItem, p => p.GefCptImport()); // GEF Boring file importer var importGefBoringItemMenuItem = new BarButtonItem { Caption = LocalizationManager.GetTranslatedText(this, "GefBoringImport"), Name = "GefBoringImportMenu" }; mainForm.ImportMenu.AddItems(new BarItem[] { importGefBoringItemMenuItem }); BindSupport.Bind(pluginPanel, importGefBoringItemMenuItem, p => p.GefBoringImport()); // Old project / DAM defx importer if (use1DProfiles && use2DProfiles && useSoilSegments) { var importDamItemMenuItem = new BarButtonItem { Caption = LocalizationManager.GetTranslatedText(this, "DamDefxImport"), Name = "DamImportMenu" }; mainForm.ImportMenu.AddItems(new BarItem[] { importDamItemMenuItem }); BindSupport.Bind(pluginPanel, importDamItemMenuItem, p => p.DamDefxImport()); var importOldProjectItemMenuItem = new BarButtonItem { Caption = LocalizationManager.GetTranslatedText(this, "OldProjectImport"), Name = "OldProjectImportMenu" }; mainForm.ImportMenu.AddItems(new BarItem[] { importOldProjectItemMenuItem }); BindSupport.Bind(pluginPanel, importOldProjectItemMenuItem, p => p.OldProjectImport()); } } private void FilmStripContainer_OnSizeChanged(object sender, EventArgs e) { const int pixelOffset = 7; var heightForGeometryEditor = filmStripContainer.Height - filmStrip.Height; var newSplitterDistance = heightForGeometryEditor - pixelOffset; // avoid exception setting a negative splitter distance if (newSplitterDistance > 0) { filmStripContainer.SplitterDistance = newSplitterDistance; } } private void FilmStripContainer_OnSplitterMoving(object sender, SplitterCancelEventArgs e) { Cursor.Current = Cursors.HSplit; } private void FilmStripContainer_OnSplitterMoved(object sender, SplitterEventArgs e) { Cursor.Current = Cursors.Default; SizeFilmStripToFilmStripContainer(); } private void ConfigureGeometryEditor() { // Allow renaming the geometry editor LocalizationSupport.Unregister(mainForm.GeometryDockPanel); // Initialize the main Geometry Editor GeometryEditor = new DSoilModelGeometryEditor(mainForm); // Add a container for the film strip control below the main Geometry Editor var parent = mainForm.GeometryEditor.Parent; filmStripContainer.Panel1.Controls.Add(mainForm.GeometryEditor); // Create a film strip control, with a spatial editor based on the main Geometry Editor filmStrip = new FilmStrip(mainForm.GeometryEditor.SpatialEditor); filmStripContainer.Panel2.Controls.Add(filmStrip); parent.Controls.Add(filmStripContainer); filmStripContainer.BringToFront(); } private void ConfigureSegmentGeometryEditor() { // Initialize the Segment Geometry Editor SegmentGeometryEditor = new DSoilModelSegmentGeometryEditor(extraGeometryEditor); // Add a container for the film strip control below the Extra Geometry Editor //var parent = mainForm.ExtraGeometryEditor.Parent; //filmStripContainer.Panel1.Controls.Add(mainForm.ExtraGeometryEditor); // Create a film strip control, with a spatial editor based on the main Geometry Editor //filmStrip = new FilmStrip(mainForm.ExtraGeometryEditor.SpatialEditor); //filmStripContainer.Panel2.Controls.Add(filmStrip); //parent.Controls.Add(filmStripContainer); //filmStripContainer.BringToFront(); } private void ConfigureMapEditor() { MapEditor = new DSoilModelMapEditor(mapControl); mapControl.EnableSelectButton = true; mapControl.EnableZoomToData = true; mapControl.EnableZoomToSelection = true; mapControl.EnableZoomRectangle = true; MapEditor.ConfigureMainMenu(mainForm); // default coordinate system for features generated from lists like CPT, Boring, SoilProfile MapProjectionManager.Instance.SetActiveMapProjection(MapProjection.DutchRD); } private void ConfigurePropertyGrid() { // Todo can be moved to GeotechnicsPlugin later when editors are approved. if (UseSoilSegments) { mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => segmentControl, typeof(SoilSegment)); } // override MaterialEditorDialog which is registered in geotechnics plugin, replace with automatic (factory) control mainForm.DynamicPropertyControl.ClearRegistrationsForType(typeof(Soil)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => PropertyControlFactory.GetPropertyControl(), typeof(Soil)); // override SoilLayerControl which is registered in geotechnics plugin, replace with local SOSSoilLayerControl control mainForm.DynamicPropertyControl.ClearRegistrationsForType(typeof(SoilLayer1D)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new SosSoilLayer1DControl(), typeof(SosSoilLayer1D)); // override SoilProfile1DControl which is registered in geotechnics plugin, replace with local SOSSoilProfile1DControl control mainForm.DynamicPropertyControl.ClearRegistrationsForType(typeof(SoilProfile1D)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new SosSoilProfile1DControl(), typeof(SoilProfile1D), typeof(SosSoilLayer1D)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new SoilProfile1DLookup2DControl(), typeof(SoilProfile1DLookup2D)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new SoilProfile2DControl(), typeof(SoilProfile2D)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new SoilLayer2DControl(), typeof(SoilLayer2D)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new GeometryPointControl(), typeof(GeometryPoint)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new GeometryCurveControl(), typeof(GeometryCurve)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new SpecificMechanismPointLocationControl(), typeof(SpecificMechanismPointLocation)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new SoilSegmentSplitLocationControl(), typeof(SoilSegmentSplitLocation)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new CenterCrestLocationPropertyControl(), typeof(CenterCrestLocation)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlsForType(typeof(ConePenetrationTestData), () => new CPTControl()); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new CPTLookup1DControl(), typeof(ConePenetrationTestLookup1D)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new CPTLookup2DControl(), typeof(ConePenetrationTestLookup2D)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new SosSoilProfile1DControl(), typeof(SoilProfile1DLookup2D)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlsForType(typeof(Boring), () => new BoringControl()); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new BoringLookup2DControl(), typeof(BoringLookup2D)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new BoringLookup1DControl(), typeof(BoringLookup1D)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => PropertyControlFactory.GetPropertyControl(), typeof(BoringLayer)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => PropertyControlFactory.GetPropertyControl(), typeof(SoilSurfaceProfile)); // this should be in the geotechnics plugin, but may impact the MStab and RingToets applications that already have something else hooked up ?! mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => new PreconsolidationStressControl(), typeof(SoilProfile2D)); mainForm.DynamicPropertyControl.BuildDelayedPropertyControlForTypes(() => PropertyControlFactory.GetPropertyControl(), typeof(PreConsolidationStress)); } private void ConfigureTables() { materialsTable = new GridViewControl { Name = "MaterialsGridViewControl", CurrentContext = Context.CurrentContext, AllowedUserColumnFilters = Soil.AllowedUserColumnFilters, AllowInserts = true, HideUnusedColumns = true }; mainForm.RegisterTableControl(typeof(Soil), materialsTable, "Materials"); BindSupport.Bind(projectPanel, materialsTable, typeof(DSoilModelProject), "Soils.Soils"); materialsTable.CanDelete += CanDeleteSoil; cptsTable = new GridViewControl { CurrentContext = Context.CurrentContext, HideUnusedColumns = true, AllowInserts = false, ShowToolbar = true, Name = "CPTsTable", EnableMasterViewMode = false }; cptsTable.CanDelete += CanDeleteCPT; mainForm.RegisterTableControl(typeof(ConePenetrationTestData), cptsTable, "CPTs"); BindSupport.Bind(projectPanel, cptsTable, x => x.CPTs); BarButtonItem cptAddButton = FindBarButtonItem(cptsTable, "AddBarItem"); if (cptAddButton != null) { BindSupport.Unbind(cptAddButton); BindSupport.Bind(pluginPanel, cptAddButton, GetType(), "GefCptImport"); } if (UseBorings) { boringsTable = new GridViewControl { CurrentContext = Context.CurrentContext, HideUnusedColumns = true, AllowInserts = false, Name = "BoringsTable", ShowToolbar = true, EnableMasterViewMode = false }; boringsTable.CanDelete += CanDeleteBoring; mainForm.RegisterTableControl(typeof(Boring), boringsTable, "Borings"); BindSupport.Bind(projectPanel, boringsTable, x => x.Borings); BarButtonItem boringAddButton = FindBarButtonItem(boringsTable, "AddBarItem"); if (boringAddButton != null) { BindSupport.Unbind(boringAddButton); BindSupport.Bind(pluginPanel, boringAddButton, GetType(), "GefBoringImport"); } } if (Use1DProfiles) { soilProfiles1DTable = new GridViewControl { CurrentContext = Context.CurrentContext, HideUnusedColumns = true }; soilProfiles1DTable.CanDelete += CanDeleteSoilProfile; mainForm.RegisterTableControl(typeof(SoilProfile1D), soilProfiles1DTable, "SoilProfiles1D"); BindSupport.Bind(projectPanel, soilProfiles1DTable, x => x.SoilProfiles1D); } if (Use2DProfiles) { soilProfiles2DTable = new GridViewControl { CurrentContext = Context.CurrentContext, HideUnusedColumns = true, Name = "2DProfiles" }; soilProfiles2DTable.CanDelete += CanDeleteSoilProfile; mainForm.RegisterTableControl(typeof(SoilProfile2D), soilProfiles2DTable, "2D Geometries"); BindSupport.Bind(projectPanel, soilProfiles2DTable, x => x.SoilProfiles2D); } if (UseSurfaceLines) { var surfaceLinesTable = new GridViewControl { Name = "SurfaceLinesTable", EnableMasterViewMode = false, CurrentContext = Context.CurrentContext, HideUnusedColumns = true }; mainForm.RegisterTableControl(typeof(SurfaceLine2), surfaceLinesTable, "SurfaceLines"); BindSupport.Bind(projectPanel, surfaceLinesTable, x => x.SurfaceLines); } if (UseSoilSegments) { var segmentsTable = new GridViewControl { CurrentContext = Context.CurrentContext, Name = "SoilSegmentsTable", HideUnusedColumns = true, EnableMasterViewMode = false }; mainForm.RegisterTableControl(typeof(DSoilModelProject), segmentsTable, "SoilSegments"); BindSupport.Bind(projectPanel, segmentsTable, x => x.CurrentSoilSegments); } // validator messages, add repair all button to toolbar var newButton = new BarButtonItem { Glyph = Resources.accept }; var gridView = mainForm.MessagesControl.UserMessagesGridViewControl; gridView.ShowToolbar = true; gridView.Toolbar.LinksPersistInfo.Add(new LinkPersistInfo(newButton)); BindSupport.Bind(pluginPanel, newButton, x => x.RepairAllValidationResults()); // remove buttons not applicable to validation table RemoveBarButtonItem(gridView, "CutBarItem"); RemoveBarButtonItem(gridView, "CopyBarItem"); RemoveBarButtonItem(gridView, "PasteBarItem"); RemoveBarButtonItem(gridView, "EditSelectedCellsBarItem"); RemoveBarButtonItem(gridView, "EditUnitSelectedCellsBarItem"); // toolbar on logmessages so the user can clear them mainForm.DynamicOutputControl.LogMessagesGridViewControl.ShowToolbar = true; } private void LogErrorCannotDelete(IName objToDelete, IName objUses) { var formattedErrorStr = LocalizationManager.GetTranslatedText(this, "CannotDeleteObjectThatInUse"); var msg = string.Format(formattedErrorStr, objToDelete.Name, LocalizationManager.GetTranslatedText(objToDelete, objToDelete.GetType().Name), objUses.Name, LocalizationManager.GetTranslatedText(objUses, objUses.GetType().Name)); LogManager.Add(new LogMessage(LogMessageType.Error, objToDelete, msg)); if (!FormsSupport.IsTreeVisible(mainForm.DynamicOutputControl)) { FormsSupport.MakeTreeVisible(mainForm.DynamicOutputControl); } } private bool CanDeleteSoil(object o) { var soil = o as Soil; if (soil == null) { return true; } var result = true; // soil in borings foreach (var b in Project.Borings) { if (b.BoringLayers.Any(x => x.Soil == soil)) { LogErrorCannotDelete(soil, b); result = false; } } // 1D profiles foreach (var sp1d in Project.SoilProfiles1D) { if (sp1d.Layers.Any(l => l.Soil == soil)) { LogErrorCannotDelete(soil, sp1d); result = false; } } // 2D profiles foreach (var sp2d in Project.SoilProfiles2D) { if (sp2d.Surfaces.Any(s => s.Soil == soil)) { LogErrorCannotDelete(soil, sp2d); result = false; } } // soil in the segments foreach (var sgm in Project.SoilSegments.Where(sgm => sgm.DefaultFillMaterialName == soil)) { LogErrorCannotDelete(soil, sgm); result = false; } return result; } private bool CanDeleteCPT(object o) { var cpt = o as ConePenetrationTestData; if (cpt == null) { return true; } var result = true; // cpt in lookups 1D foreach (var lookup in Project.CptLookup1Ds.Where(lookup => lookup.ConePenetrationTestData == cpt)) { LogErrorCannotDelete(cpt, lookup.SoilProfile1D); result = false; } // cpt in lookups 2D foreach (var lookup in Project.CptLookup2Ds.Where(lookup => lookup.ConePenetrationTestData == cpt)) { LogErrorCannotDelete(cpt, lookup.SoilProfile2D); result = false; } // soil in the segments foreach (var sgm in Project.SoilSegments) { foreach (var c in sgm.Cpts.Where(c => c.ConePenetrationTestData == cpt)) { LogErrorCannotDelete(cpt, sgm); result = false; } } return result; } private bool CanDeleteBoring(object o) { var boring = o as Boring; if (boring == null) { return true; } var result = true; // cpt in lookups 1D foreach (var lookup in Project.BoringLookup1Ds.Where(lookup => lookup.Boring == boring)) { LogErrorCannotDelete(boring, lookup.SoilProfile1D); result = false; } // cpt in lookups 2D foreach (var lookup in Project.BoringLookup2Ds.Where(lookup => lookup.Boring == boring)) { LogErrorCannotDelete(boring, lookup.SoilProfile2D); result = false; } // soil in the segments foreach (var sgm in Project.SoilSegments) { foreach (var c in sgm.Borings.Where(c => c.Boring == boring)) { LogErrorCannotDelete(boring, sgm); result = false; } } return result; } private bool CanDeleteSoilProfile(object o) { var soilProfile = o as SoilProfile; if (soilProfile == null) { return true; } var result = true; // soilprofiles in the segments foreach (var sgm in Project.SoilSegments) { foreach (var sp in sgm.StochasticSoilModel.StochasticSoilProfiles.Where(ssp => ssp.Profile == soilProfile)) { LogErrorCannotDelete(soilProfile, sgm); result = false; } } return result; } private void RemoveBarButtonItem(GridViewControl gridViewTable, string buttonName) { var manager = gridViewTable.Toolbar.Manager; var items = manager.Items; foreach (var barItem in items) { var barButtonItem = barItem as BarButtonItem; if (barButtonItem != null && barButtonItem.Name == buttonName) { // hide button using dummy binding as items.remove() will not work here BindSupport.Unbind(barButtonItem); BindSupport.Bind(pluginPanel, barButtonItem, p => p.InvisibleMethod()); break; } } } private BarButtonItem FindBarButtonItem(GridViewControl gridViewTable, string buttonName) { foreach (var barItem in gridViewTable.Toolbar.Manager.Items) { var barButtonItem = barItem as BarButtonItem; if (barButtonItem != null && barButtonItem.Name == buttonName) { return barButtonItem; } } return null; } private void ConfigureSoilMechanisms() { // The Soil.Mechanisms list is the list of the currently used mechanisme filter(s) and should be updated // with the selected CurrentMechanism of the project. Soil.Mechanisms = new[] { Mechanism.None, Mechanism.Piping, Mechanism.Stability, Mechanism.FlowSlide }; // The MechanismSupport.Mechanisms list is the list of available mechanisme filter(s) for this program and should NEVER // be altered elsewhere in the program. MechanismSupport.Mechanisms = Soil.Mechanisms; } private void ConfigureSoilUserFilters() { Soil.AllowedUserColumnFilters = new[] { UserColumnFilters.MacrostabilityWti, UserColumnFilters.PipingWti, UserColumnFilters.FlowSlideWti }; } private void SaveSelectedDataAs() { if (selectedObjects.Count > 0) { var saveAsProject = PrepareSaveAsProject(); var saveDialog = new SaveFileDialog { Filter = "Soilbase files (*.soil)|*.soil" }; if (saveDialog.ShowDialog() == DialogResult.OK) { var fileName = saveDialog.FileName; DSoilModelIO.SaveSoilDatabase(fileName, saveAsProject); } } } /// /// Prepares the save as project. /// /// public DSoilModelProject PrepareSaveAsProject() { // Copy selected items to a new project var saveAsProject = new DSoilModelProject(); foreach (var item in selectedObjects) { var soil = item as Soil; if (soil != null) { saveAsProject.Soils.Soils.Add(soil); continue; } var soilProfile1D = item as SoilProfile1D; if (soilProfile1D != null) { saveAsProject.SoilProfiles1D.Add(soilProfile1D); continue; } var soilProfile2D = item as SoilProfile2D; if (soilProfile2D != null) { saveAsProject.SoilProfiles2D.Add(soilProfile2D); continue; } var soilSegment = item as SoilSegment; if (soilSegment != null) { saveAsProject.SoilSegments.Add(soilSegment); continue; } var cpt = item as ConePenetrationTestData; if (cpt != null) { saveAsProject.CPTs.Add(cpt); continue; } var boring = item as Boring; if (boring != null) { saveAsProject.Borings.Add(boring); continue; } var surfaceLine = item as SurfaceLine2; if (surfaceLine != null) { saveAsProject.SurfaceLines.Add(surfaceLine); } } // update lists with referenced objects (ie soils used in the selected soilprofile) saveAsProject.UpdateLists(); // items referencing the selected subset foreach (var mpl in project.SpecificMechanismPointLocations) { if (saveAsProject.SoilProfiles2D.Contains(mpl.SoilProfile2D)) { saveAsProject.SpecificMechanismPointLocations.Add(mpl); } } return saveAsProject; } private void SoilProfile1DImport() { int countWarnings = LogManager.Messages.Count(m => m.MessageType > LogMessageType.Info); DataEventPublisher.IsDataEventPublishStopped = true; try { var openDialog = new OpenFileDialog { FileName = "", CheckFileExists = true, CheckPathExists = true, Filter = "CSV file|*.csv" }; openDialog.FileName = "soilprofiles.csv"; openDialog.FilterIndex = 0; openDialog.AutoUpgradeEnabled = false; if (openDialog.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; string msgType = LocalizationManager.GetTranslatedText(this, "SoilProfile1DImport"); string msg = string.Format(LocalizationManager.GetTranslatedText(this, "ImportLogMessageTemplate"), msgType, openDialog.FileName); LogManager.Add(new LogMessage(LogMessageType.Info, project, msg)); project.ReadSoilProfiles1DFromFile(openDialog.FileName); } } catch (Exception ex) { LogManager.Add(new LogMessage(LogMessageType.Error, project, ex.Message)); } finally { Cursor.Current = Cursors.Default; } DataEventPublisher.IsDataEventPublishStopped = false; DataEventPublisher.DataListModified(project.Soils.Soils); DataEventPublisher.DataListModified(project.SoilProfiles1D); BindSupport.UpdateAll(); MapEditor.ZoomData(); CheckLogWarnings(countWarnings); } private void GeometryImport() { int countWarnings = LogManager.Messages.Count(m => m.MessageType > LogMessageType.Info); DataEventPublisher.IsDataEventPublishStopped = true; try { var openDialog = new OpenFileDialog { FileName = "", CheckFileExists = true, CheckPathExists = true, Filter = "2D Profile files|*.sti;*.geo;*.dsx|Stability files (*.sti, *.dsx)|*.sti;*.dsx|Geometry files(*.geo)|*.geo|All files|*.*", FilterIndex = 0, AutoUpgradeEnabled = false, Multiselect = true }; if (openDialog.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; foreach (var fileName in openDialog.FileNames) { string msgType = LocalizationManager.GetTranslatedText(this, "GeometryImport"); string msg = string.Format(LocalizationManager.GetTranslatedText(this, "ImportLogMessageTemplate"), msgType, fileName); LogManager.Add(new LogMessage(LogMessageType.Info, project, msg)); project.ReadGeometryFromFile(fileName); } } } catch (Exception ex) { LogManager.Add(new LogMessage(LogMessageType.Error, project, ex.Message)); } finally { Cursor.Current = Cursors.Default; } DataEventPublisher.IsDataEventPublishStopped = false; DataEventPublisher.DataListModified(project.Soils.Soils); DataEventPublisher.DataListModified(project.SoilProfiles2D); BindSupport.UpdateAll(); MapEditor.ZoomData(); CheckLogWarnings(countWarnings); } private void SoilsImport() { int countWarnings = LogManager.Messages.Count(m => m.MessageType > LogMessageType.Info); DataEventPublisher.IsDataEventPublishStopped = true; try { var openDialog = new OpenFileDialog { FileName = "", CheckFileExists = true, CheckPathExists = true, Filter = "MSoilbase or MGeobase database(*.mdb, *.gdb)|*.mdb;*.gdb" }; openDialog.FileName = "soilmaterials.mdb"; openDialog.FilterIndex = 0; openDialog.AutoUpgradeEnabled = false; if (openDialog.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; string msgType = LocalizationManager.GetTranslatedText(this, "SoilsImport"); string msg = string.Format(LocalizationManager.GetTranslatedText(this, "ImportLogMessageTemplate"), msgType, openDialog.FileName); LogManager.Add(new LogMessage(LogMessageType.Info, project, msg)); project.ReadSoilsFromDatabase(openDialog.FileName); } } catch (Exception ex) { LogManager.Add(new LogMessage(LogMessageType.Error, project, ex.Message)); } finally { Cursor.Current = Cursors.Default; } DataEventPublisher.IsDataEventPublishStopped = false; DataEventPublisher.DataListModified(project.Soils.Soils); BindSupport.UpdateAll(); project.CurrentFailureMechanism = Mechanism.None; Project = project; CheckLogWarnings(countWarnings); } private void DamDefxImport() { int countWarnings = LogManager.Messages.Count(m => m.MessageType > LogMessageType.Info); try { var openDialog = new OpenFileDialog { FileName = "", CheckFileExists = true, CheckPathExists = true, Filter = "Dam data definition(*.defx)|*.defx", FilterIndex = 0, AutoUpgradeEnabled = false }; if (openDialog.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; string msgType = LocalizationManager.GetTranslatedText(this, "DamDefxImport"); string msg = string.Format(LocalizationManager.GetTranslatedText(this, "ImportLogMessageTemplate"), msgType, openDialog.FileName); LogManager.Add(new LogMessage(LogMessageType.Info, project, msg)); string defxFile = openDialog.FileName; string locationsShpFile = ""; DataEventPublisher.InvokeWithoutPublishingEvents(() => { DSoilModelIO.ReadDamDefinitionsFromFileAndAddToProject(defxFile, project, ref locationsShpFile); }); // reset project MapEditor.Project = project; project.CurrentFailureMechanism = Mechanism.None; // add Dam locations as background map if (!string.IsNullOrEmpty(locationsShpFile)) { BackgroundMap backgroundMap = FeatureSupport.GetBackgroundMap(Path.Combine(Path.GetDirectoryName(defxFile), locationsShpFile)); MapEditor.MapEditor.BackgroundMaps.Add(backgroundMap); MapEditor.MapEditor.ShowBackgroundMap(backgroundMap); var layer = MapEditor.MapEditor.MapControl.Layers.FirstOrDefault(l => l.LegendText == backgroundMap.Name) as MapPointLayer; ; if (layer != null) { layer.LegendText = "DAM Locations"; layer.Symbolizer = new PointSymbolizer(Color.DarkRed, PointShape.Ellipse, 12); } } } } catch (Exception ex) { LogManager.Add(new LogMessage(LogMessageType.Error, project, ex.Message)); } finally { Cursor.Current = Cursors.Default; } DataEventPublisher.DataListModified(project.Soils.Soils, project.SoilProfiles1D, project.SoilProfiles2D, project.SoilSegments); BindSupport.UpdateAll(); CheckLogWarnings(countWarnings); } private void OldProjectImport() { int countWarnings = LogManager.Messages.Count(m => m.MessageType > LogMessageType.Info); DataEventPublisher.IsDataEventPublishStopped = true; try { var openDialog = new OpenFileDialog { FileName = "", CheckFileExists = true, CheckPathExists = true, Filter = "Old project database (access)|*.mdb|Old project database (Firebird)|*.gdb", FilterIndex = 0, AutoUpgradeEnabled = false }; if (openDialog.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; string msgType = LocalizationManager.GetTranslatedText(this, "OldProjectImport"); string msg = string.Format(LocalizationManager.GetTranslatedText(this, "ImportLogMessageTemplate"), msgType, openDialog.FileName); LogManager.Add(new LogMessage(LogMessageType.Info, project, msg)); project.ReadOldProjectFromDatabase(openDialog.FileName); } } catch (Exception ex) { LogManager.Add(new LogMessage(LogMessageType.Error, project, ex.Message)); } finally { Cursor.Current = Cursors.Default; } DataEventPublisher.IsDataEventPublishStopped = false; DataEventPublisher.DataListModified(project.Soils.Soils); BindSupport.UpdateAll(); project.CurrentFailureMechanism = Mechanism.None; MapEditor.Project = project; CheckLogWarnings(countWarnings); } private void GefCptImport() { int countWarnings = LogManager.Messages.Count(m => m.MessageType > LogMessageType.Info); DataEventPublisher.IsDataEventPublishStopped = true; var faultyFiles = new List(); try { var openDialog = new OpenFileDialog { FileName = "", CheckFileExists = true, CheckPathExists = true, Filter = "GEF CPT file|*.gef", FilterIndex = 0, Multiselect = true, AutoUpgradeEnabled = false }; if (openDialog.ShowDialog() == DialogResult.OK) { //User can choose several files at once. Cursor.Current = Cursors.WaitCursor; foreach (var filename in openDialog.FileNames) { string msgType = LocalizationManager.GetTranslatedText(this, "GefCptImport"); string msg = string.Format(LocalizationManager.GetTranslatedText(this, "ImportLogMessageTemplate"), msgType, filename); LogManager.Add(new LogMessage(LogMessageType.Info, project, msg)); if (!project.ReadGefCptFromFile(filename)) { faultyFiles.Add(filename); } } if (faultyFiles.Count > 0) { string message = LocalizationManager.GetTranslatedText(this, "ImportFailed"); foreach (var filename in faultyFiles) { message = message + "\n" + filename; } MessageBox.Show(mainForm, message); } } } catch (Exception ex) { LogManager.Add(new LogMessage(LogMessageType.Error, project, ex.Message)); } finally { Cursor.Current = Cursors.Default; } DataEventPublisher.IsDataEventPublishStopped = false; DataEventPublisher.DataListModified(project.CPTs); BindSupport.UpdateAll(); MapEditor.ZoomData(); CheckLogWarnings(countWarnings); } private void GefBoringImport() { int countWarnings = LogManager.Messages.Count(m => m.MessageType > LogMessageType.Info); DataEventPublisher.IsDataEventPublishStopped = true; var faultyFiles = new List(); try { var openDialog = new OpenFileDialog { FileName = "", CheckFileExists = true, CheckPathExists = true, Filter = "GEF Boring file|*.gef", FilterIndex = 0, Multiselect = true, AutoUpgradeEnabled = false }; if (openDialog.ShowDialog() == DialogResult.OK) { //User can choose several files at once. Cursor.Current = Cursors.WaitCursor; foreach (var filename in openDialog.FileNames) { string msgType = LocalizationManager.GetTranslatedText(this, "GefBoringImport"); string msg = string.Format(LocalizationManager.GetTranslatedText(this, "ImportLogMessageTemplate"), msgType, filename); LogManager.Add(new LogMessage(LogMessageType.Info, project, msg)); if (!project.ReadGefBoringFromFile(filename)) { faultyFiles.Add(filename); } } if (faultyFiles.Count > 0) { string message = LocalizationManager.GetTranslatedText(this, "ImportFailed"); foreach (var filename in faultyFiles) { message = message + "\n" + filename; } MessageBox.Show(mainForm, message); } } } catch (Exception ex) { LogManager.Add(new LogMessage(LogMessageType.Error, project, ex.Message)); } finally { Cursor.Current = Cursors.Default; } DataEventPublisher.IsDataEventPublishStopped = false; DataEventPublisher.DataListModified(project.Borings); DataEventPublisher.DataListModified(project.Soils.Soils); BindSupport.UpdateAll(); MapEditor.ZoomData(); CheckLogWarnings(countWarnings); } private void SurfaceLineImport() { int countWarnings = LogManager.Messages.Count(m => m.MessageType > LogMessageType.Info); DataEventPublisher.IsDataEventPublishStopped = true; try { var openDialog = new OpenFileDialog { FileName = "", CheckFileExists = true, CheckPathExists = true, Filter = "Surface line files|*.csv", FilterIndex = 0 }; openDialog.FileName = "surfacelines.csv"; openDialog.Multiselect = true; openDialog.AutoUpgradeEnabled = false; if (openDialog.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; foreach (var fileName in openDialog.FileNames) { string msgType = LocalizationManager.GetTranslatedText(this, "SurfaceLineImport"); string msg = string.Format(LocalizationManager.GetTranslatedText(this, "ImportLogMessageTemplate"), msgType, fileName); LogManager.Add(new LogMessage(LogMessageType.Info, project, msg)); DSoilModelIO.ReadCsvSurfaceLineFromFileAndAddToProject(fileName, project); } } } catch (Exception ex) { LogManager.Add(new LogMessage(LogMessageType.Error, project, ex.Message)); } finally { Cursor.Current = Cursors.Default; } DataEventPublisher.IsDataEventPublishStopped = false; DataEventPublisher.DataListModified(project.SurfaceLines); BindSupport.UpdateAll(); MapEditor.ZoomData(); CheckLogWarnings(countWarnings); } private void CharacteristicPointsImport() { int countWarnings = LogManager.Messages.Count(m => m.MessageType > LogMessageType.Info); DataEventPublisher.IsDataEventPublishStopped = true; try { var openDialog = new OpenFileDialog { FileName = "", CheckFileExists = true, CheckPathExists = true, Filter = "Characteristic point files|*.csv", FilterIndex = 0 }; openDialog.FileName = "characteristicpoints.csv"; openDialog.Multiselect = true; openDialog.AutoUpgradeEnabled = false; if (openDialog.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; foreach (var fileName in openDialog.FileNames) { string msgType = LocalizationManager.GetTranslatedText(this, "CharacteristicPointsImport"); string msg = string.Format(LocalizationManager.GetTranslatedText(this, "ImportLogMessageTemplate"), msgType, fileName); LogManager.Add(new LogMessage(LogMessageType.Info, project, msg)); DSoilModelIO.ReadCsvCharacteristicPointsFromFileAndAddToProject(fileName, project); } } } catch (Exception ex) { LogManager.Add(new LogMessage(LogMessageType.Error, project, ex.Message)); } finally { Cursor.Current = Cursors.Default; } DataEventPublisher.IsDataEventPublishStopped = false; DataEventPublisher.DataListModified(project.SurfaceLines); BindSupport.UpdateAll(); project.CurrentFailureMechanism = Mechanism.None; CheckLogWarnings(countWarnings); } private void SoilSegmentsCsvImport() { int countWarnings = LogManager.Messages.Count(m => m.MessageType > LogMessageType.Info); DataEventPublisher.IsDataEventPublishStopped = true; try { var openDialog = new OpenFileDialog { FileName = "", CheckFileExists = true, CheckPathExists = true }; openDialog.Filter = "CSV|*.csv"; openDialog.FilterIndex = 0; openDialog.FileName = "segments.csv"; openDialog.FilterIndex = 0; openDialog.AutoUpgradeEnabled = false; if (openDialog.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; string msgType = LocalizationManager.GetTranslatedText(this, "SoilSegmentsCsvImport"); string msg = string.Format(LocalizationManager.GetTranslatedText(this, "ImportLogMessageTemplate"), msgType, openDialog.FileName); LogManager.Add(new LogMessage(LogMessageType.Info, project, msg)); string fileName = openDialog.FileName.ToLower(); if (Path.GetExtension(fileName) == ".csv") { DSoilModelIO.ReadCsvSegmentsFromFileAndAddToProject(fileName, project); project.CurrentFailureMechanism = Mechanism.None; } } } catch (Exception ex) { LogManager.Add(new LogMessage(LogMessageType.Error, project, ex.Message)); } finally { Cursor.Current = Cursors.Default; } DataEventPublisher.IsDataEventPublishStopped = false; if (project != null) { DataEventPublisher.DataListModified(project.Soils.Soils); DataEventPublisher.DataListModified(project.SoilProfiles1D); DataEventPublisher.DataListModified(project.SoilProfiles2D); DataEventPublisher.DataListModified(project.SoilSegments); BindSupport.UpdateAll(); project.CurrentFailureMechanism = Mechanism.None; } CheckLogWarnings(countWarnings); } private void SoilSegmentsShapeImport() { int countWarnings = LogManager.Messages.Count(m => m.MessageType > LogMessageType.Info); DataEventPublisher.IsDataEventPublishStopped = true; try { var openDialog = new OpenFileDialog { FileName = "", CheckFileExists = true, CheckPathExists = true }; openDialog.Filter = "Shape(*.shp)|*.shp"; openDialog.FilterIndex = 0; openDialog.FileName = "segments.csv"; openDialog.FilterIndex = 0; openDialog.AutoUpgradeEnabled = false; if (openDialog.ShowDialog() == DialogResult.OK) { Cursor.Current = Cursors.WaitCursor; string msgType = LocalizationManager.GetTranslatedText(this, "SoilSegmentsShapeImport"); string msg = string.Format(LocalizationManager.GetTranslatedText(this, "ImportLogMessageTemplate"), msgType, openDialog.FileName); LogManager.Add(new LogMessage(LogMessageType.Info, project, msg)); string fileName = openDialog.FileName.ToLower(); if (Path.GetExtension(fileName) == ".shp") { var done = false; var fieldName = "SegmentId"; while (!done) { try { // this will fail if field name not correct DSoilModelIO.ReadSegmentShapefileAndAddToProject(fileName, project, fieldName); done = true; } catch (MappingIsNotCorrectException ex) { // prompt the user to select the field var modalList = new ModalListBox { Text = LocalizationManager.GetTranslatedText(typeof(DSoilModelPlugin), "WhichColumnToUseAsSegmentID"), Items = ex.AttributeNames.ToList() }; modalList.ShowDialog(); fieldName = modalList.SelectedItem; done = (fieldName == null); } } long count = project.SoilSegments.Count; long found = project.SoilSegments.Count(s => s.Points != null && s.Points.Count > 0); if (count > found) { msg = string.Format(LocalizationManager.GetTranslatedText(this, "SoilSegmentsImportCounts"), count - found, count); LogManager.Add(new LogMessage(LogMessageType.Warning, Project, msg)); } } } } catch (Exception ex) { LogManager.Add(new LogMessage(LogMessageType.Error, project, LocalizationManager.GetTranslatedText(this, "ImportShapefileFailed"))); } finally { Cursor.Current = Cursors.Default; } DataEventPublisher.IsDataEventPublishStopped = false; if (project != null) { DataEventPublisher.DataListModified(project.Soils.Soils); DataEventPublisher.DataListModified(project.SoilProfiles1D); DataEventPublisher.DataListModified(project.SoilProfiles2D); DataEventPublisher.DataListModified(project.SoilSegments); BindSupport.UpdateAll(); project.CurrentFailureMechanism = Mechanism.None; MapEditor.ZoomData(); } CheckLogWarnings(countWarnings); } [Description("RepairAllValidationResultsDescription")] private void RepairAllValidationResults() { if (RealTimeBackgroundValidator.ValidationResults.Any(vr => vr.Repairer != null)) { var dialogResult = MessageBox.Show(LocalizationManager.GetTranslatedText(this, "RepairAllValidationResultsPrompt"), LocalizationManager.GetTranslatedText(this, "RepairAllValidationResults"), MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (dialogResult == DialogResult.OK) { var cuCursor = Cursor.Current; try { Cursor.Current = Cursors.WaitCursor; project.RepairAllValidationResults(); } finally { Cursor.Current = cuCursor; } } } } private void CheckLogWarnings(int countWarnings) { DataEventPublisher.DataListModified(LogManager.Messages); if (LogManager.Messages.Count(m => m.MessageType > LogMessageType.Info) > countWarnings) { FormsSupport.MakeTreeVisible(mainForm.DynamicOutputControl); MessageBox.Show(LocalizationManager.GetTranslatedText(this, "ImportWarningsCheckOutputWindow")); } } private void HandleSoilSegment(SoilSegment currentSoilSegment) { filmStrip.SelectedStochasticSoilModel = null; if (currentSoilSegment != null) { StochasticSoilProfile selectedSoilProfile = null; var selectedSoilModel = currentSoilSegment.StochasticSoilModel; if (selectedSoilModel != null && selectedSoilModel.StochasticSoilProfiles.Count > 0) { // if in a previous selection of the segment, a specific profile was selected then reselect it if (!previouslySelectedProfiles.TryGetValue(selectedSoilModel, out selectedSoilProfile)) { selectedSoilProfile = selectedSoilModel.StochasticSoilProfiles.FirstOrDefault(); previouslySelectedProfiles.Add(selectedSoilModel, selectedSoilProfile); } // synchronize the selection of the profiles grid on the soil segment control segmentControl.SelectedSoilProfile = selectedSoilProfile; // synchronize the film strip control filmStrip.SelectedStochasticSoilModel = selectedSoilModel; filmStrip.SelectedStochasticSoilProfile = selectedSoilProfile; } GeometryEditor.ShowSoilSegment(currentSoilSegment, selectedSoilProfile); } } private void HandleStochasticSoilProfile(StochasticSoilProfile currentSoilProfile) { filmStrip.SelectedStochasticSoilModel = null; if (currentSoilProfile != null) { var soilSegment = project.SoilSegments.FirstOrDefault(ss => ss.StochasticSoilModel != null && ss.StochasticSoilModel.StochasticSoilProfiles.Contains(currentSoilProfile)); var selectedSoilModel = (soilSegment != null ? soilSegment.StochasticSoilModel : null); if (selectedSoilModel != null && selectedSoilModel.StochasticSoilProfiles.Count > 0) { // if in a previous selection of the segment, a specific profile was selected, overwrite that StochasticSoilProfile previouslySelectedSoilProfile; if (previouslySelectedProfiles.TryGetValue(selectedSoilModel, out previouslySelectedSoilProfile)) { previouslySelectedProfiles.Remove(selectedSoilModel); previouslySelectedProfiles.Add(selectedSoilModel, currentSoilProfile); } // synchronize the film strip control filmStrip.SelectedStochasticSoilModel = selectedSoilModel; filmStrip.SelectedStochasticSoilProfile = currentSoilProfile; } GeometryEditor.ShowSoilSegment(soilSegment, currentSoilProfile); } } private void UpdateFilmStripLayout(Action action) { // reset the film strip before the film strip related action filmStrip.SelectedStochasticSoilModel = null; // perform the action (if defined) if (action != null) { action.Invoke(); } // after the film strip related action, update the film strip layout accordingly if (filmStrip.SelectedStochasticSoilModel != null) { filmStripContainer.Panel2Collapsed = false; SizeFilmStripToFilmStripContainer(); } else { filmStripContainer.Panel2Collapsed = true; } } private void SizeFilmStripToFilmStripContainer() { filmStrip.Width = filmStripContainer.Panel2.Width; filmStrip.Height = filmStripContainer.Panel2.Height; filmStrip.Refresh(false); } } }