Index: src/Deltares.DSoilModel.Forms.Tests/DSoilModelPluginTests.cs =================================================================== diff -u -r434 -r439 --- src/Deltares.DSoilModel.Forms.Tests/DSoilModelPluginTests.cs (.../DSoilModelPluginTests.cs) (revision 434) +++ src/Deltares.DSoilModel.Forms.Tests/DSoilModelPluginTests.cs (.../DSoilModelPluginTests.cs) (revision 439) @@ -280,5 +280,42 @@ Assert.IsTrue(CanDelete(plugin, "CanDeleteBoring", boringUnused)); Assert.IsFalse(CanDelete(plugin, "CanDeleteBoring", boringUsed)); } + + [Test] + public void CanDeleteSoilProfileTest_Segments() + { + var p = new DSoilModelProject(); + plugin.Project = p; + + // segments can take 1D and 2D profiles simultaneously, so we'll test them altogether + + var sp1dUsed = new SoilProfile1D(); + var sp1dUnused = new SoilProfile1D(); + p.SoilProfiles1D.Add(sp1dUsed); + p.SoilProfiles1D.Add(sp1dUnused); + + var sp2dUsed = new SoilProfile2D(); + var sp2dUnused = new SoilProfile2D(); + p.SoilProfiles2D.Add(sp2dUsed); + p.SoilProfiles2D.Add(sp2dUnused); + + var segment1 = new SoilSegment { StochasticSoilModel = new StochasticSoilModel { StochasticSoilProfiles = + { + new StochasticSoilProfile { Profile = sp1dUsed }, + new StochasticSoilProfile { Profile = sp2dUsed } + } } }; + + var segment2 = new SoilSegment { StochasticSoilModel = new StochasticSoilModel() }; + var segment3 = new SoilSegment(); + p.SoilSegments.Add(segment1); + p.SoilSegments.Add(segment2); + p.SoilSegments.Add(segment3); + + Assert.IsTrue(CanDelete(plugin, "CanDeleteSoilProfile", sp1dUnused)); + Assert.IsFalse(CanDelete(plugin, "CanDeleteSoilProfile", sp1dUsed)); + + Assert.IsTrue(CanDelete(plugin, "CanDeleteSoilProfile", sp2dUnused)); + Assert.IsFalse(CanDelete(plugin, "CanDeleteSoilProfile", sp2dUsed)); + } } } Index: src/Deltares.DSoilModel.Forms/DSoilModelPlugin.cs =================================================================== diff -u -r434 -r439 --- src/Deltares.DSoilModel.Forms/DSoilModelPlugin.cs (.../DSoilModelPlugin.cs) (revision 434) +++ src/Deltares.DSoilModel.Forms/DSoilModelPlugin.cs (.../DSoilModelPlugin.cs) (revision 439) @@ -56,6 +56,8 @@ private GridViewControl materialsTable; private GridViewControl cptsTable; private GridViewControl boringsTable; + private GridViewControl soilProfiles1DTable; + private GridViewControl soilProfiles2DTable; private DSoilModelProject project; private bool use1DProfiles = true; @@ -207,6 +209,8 @@ materialsTable.CanDelete = null; cptsTable.CanDelete = null; boringsTable.CanDelete = null; + soilProfiles1DTable.CanDelete = null; + soilProfiles2DTable.CanDelete = null; if (null != GeometryEditor) { @@ -230,9 +234,7 @@ DataEventPublisher.OnChanged -= DataEventPublisherOnChanged; DataEventPublisher.OnSelectionChanged -= DataEventPublisherOnSelectionChanged; } - - public void Configure(MainForm aMainForm) { mainForm = aMainForm; @@ -1022,23 +1024,25 @@ if (Use1DProfiles) { - var soilProfilesTable = new GridViewControl + soilProfiles1DTable = new GridViewControl { CurrentContext = Context.CurrentContext, HideUnusedColumns = true }; - mainForm.RegisterTableControl(typeof(SoilProfile1D), soilProfilesTable, "SoilProfiles1D"); - BindSupport.Bind(projectPanel, soilProfilesTable, x => x.SoilProfiles1D); + soilProfiles1DTable.CanDelete += CanDeleteSoilProfile; + mainForm.RegisterTableControl(typeof(SoilProfile1D), soilProfiles1DTable, "SoilProfiles1D"); + BindSupport.Bind(projectPanel, soilProfiles1DTable, x => x.SoilProfiles1D); } if (Use2DProfiles) { - var soilProfiles2DTable = new GridViewControl + 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); } @@ -1208,6 +1212,27 @@ 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); // TODO: soilProfile must have IName + result = false; + } + } + return result; + } + private void RemoveBarButtonItem(GridViewControl gridViewTable, string buttonName) { var manager = gridViewTable.Toolbar.Manager;