Index: src/Deltares.DSoilModel.Forms/DrawingCenterCrestLocation.cs =================================================================== diff -u -r631 -r638 --- src/Deltares.DSoilModel.Forms/DrawingCenterCrestLocation.cs (.../DrawingCenterCrestLocation.cs) (revision 631) +++ src/Deltares.DSoilModel.Forms/DrawingCenterCrestLocation.cs (.../DrawingCenterCrestLocation.cs) (revision 638) @@ -20,15 +20,12 @@ // All rights reserved. using System; -using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; -using System.Text; using Deltares.DSoilModel.Data; using Deltares.Geometry; using Deltares.Geometry.Forms; -using Deltares.Geotechnics; using Deltares.Mathematics; using Deltares.Standard.EventPublisher; using Deltares.Standard.Forms; @@ -90,12 +87,13 @@ public double TopForDrawing() { if (centerDikeCrestLocation.SoilProfile2D == null || - centerDikeCrestLocation.SoilProfile2D.Geometry == null) + centerDikeCrestLocation.SoilProfile2D.Geometry == null || + centerDikeCrestLocation.SoilProfile2D.Geometry.Points.Count == 0) { - return 0; + return 10; } var diff = GetOffsetFromGeometryHeight(); - return centerDikeCrestLocation.SoilProfile2D.Geometry.MaxGeometryPointsZ + 0.08 * diff; + return centerDikeCrestLocation.SoilProfile2D.Geometry.MaxGeometryPointsZ + 0.08*diff; } /// @@ -104,12 +102,17 @@ public double BottomForDrawing() { if (centerDikeCrestLocation.SoilProfile2D == null || - centerDikeCrestLocation.SoilProfile2D.Geometry == null) + centerDikeCrestLocation.SoilProfile2D.Geometry == null || + centerDikeCrestLocation.SoilProfile2D.Geometry.Points.Count == 0) { + if (centerDikeCrestLocation.SoilProfile2D != null && centerDikeCrestLocation.SoilProfile2D.Geometry != null) + { + return centerDikeCrestLocation.SoilProfile2D.Geometry.Bottom; + } return 0; } var diff = GetOffsetFromGeometryHeight(); - return centerDikeCrestLocation.SoilProfile2D.Geometry.MinGeometryPointsZ + 0.05 * diff; + return centerDikeCrestLocation.SoilProfile2D.Geometry.MinGeometryPointsZ + 0.05*diff; } /// @@ -118,9 +121,14 @@ public double WidthForDrawing() { if (centerDikeCrestLocation.SoilProfile2D == null || - centerDikeCrestLocation.SoilProfile2D.Geometry == null) + centerDikeCrestLocation.SoilProfile2D.Geometry == null || + centerDikeCrestLocation.SoilProfile2D.Geometry.Points.Count == 0) { - return 1; + if (centerDikeCrestLocation.SoilProfile2D != null && centerDikeCrestLocation.SoilProfile2D.Geometry != null) + { + return Math.Max(1.0, centerDikeCrestLocation.SoilProfile2D.Geometry.Right - centerDikeCrestLocation.SoilProfile2D.Geometry.Left); + } + return 50.0; } return Math.Abs(centerDikeCrestLocation.SoilProfile2D.Geometry.MaxGeometryPointsX - centerDikeCrestLocation.SoilProfile2D.Geometry.MinGeometryPointsX); } @@ -132,9 +140,10 @@ { dataObj = dataObject; centerDikeCrestLocation = null; - if (dataObject is CenterCrestLocation) + var location = dataObject as CenterCrestLocation; + if (location != null) { - centerDikeCrestLocation = (CenterCrestLocation)dataObject; + centerDikeCrestLocation = location; top = TopForDrawing(); bottom = BottomForDrawing(); width = WidthForDrawing() * percentageOfWidthGeometry; @@ -160,7 +169,7 @@ { if (double.IsNaN(centerDikeCrestLocation.Location)) { - InitializeInsertionPoint(info); + return; } DrawingSupport.SetIEPDraw3D(info.Graphics); @@ -185,7 +194,7 @@ info.Graphics.DrawRectangle(new Pen(penColor, 1), clipRect); } } - catch (System.Exception ex) + catch (Exception ex) { LogManager.Add(new LogMessage(LogMessageType.Error, ex, ex.Message)); } @@ -278,36 +287,6 @@ var diff = centerDikeCrestLocation.SoilProfile2D.Geometry.MaxGeometryPointsZ - centerDikeCrestLocation.SoilProfile2D.Geometry.MinGeometryPointsZ; return diff; - } - - private void InitializeInsertionPoint(GraphicsInfo info) - { - // Todo: Should take mouse position from before the context menu item was clicked - // or the x coordinate of the left border of the context menu, but for now we - // use the current mouse position. - var worldCoordinatesX = info.Projection.ConvertToWorld(info.MousePosition).X; - var soilProfile2D = centerDikeCrestLocation.SoilProfile2D; - - // CHekc whether mouse position is within the bounds of the soil profile - if (soilProfile2D.Geometry.Left < worldCoordinatesX && worldCoordinatesX < soilProfile2D.Geometry.Right) - { - // If the mouse position is within bounds, insert the - // Specific Mechanism Point Location near that X coordinate - insertionPoint.X = Math.Floor(worldCoordinatesX); - } - else - { - // If the mouse position is outside the soil profile, insert the - // Specific Mechanism Point Location in the middle of the soil profile - var midLength = Math.Abs(soilProfile2D.Geometry.Right - soilProfile2D.Geometry.Left) * 0.5; - insertionPoint.X = soilProfile2D.Geometry.Left + midLength; - } - centerDikeCrestLocation.Location = insertionPoint.X; - } - - private Point GetScaledPoint(IProjection projection, Point3D aOrginalPoint) - { - return projection.ConvertToScreen(aOrginalPoint.GetPointXZ()); - } + } } } Index: src/Deltares.DSoilModel.Forms/DSoilModelGeometryEditor.cs =================================================================== diff -u -r631 -r638 --- src/Deltares.DSoilModel.Forms/DSoilModelGeometryEditor.cs (.../DSoilModelGeometryEditor.cs) (revision 631) +++ src/Deltares.DSoilModel.Forms/DSoilModelGeometryEditor.cs (.../DSoilModelGeometryEditor.cs) (revision 638) @@ -492,7 +492,8 @@ if (sender is CenterCrestLocation) { var ccl = sender as CenterCrestLocation; - if (ccl.SoilProfile2D.CenterCrestLocation != ccl.Location) + if (ccl.SoilProfile2D.CenterCrestLocation != ccl.Location && !(double.IsNaN(ccl.SoilProfile2D.CenterCrestLocation) + && double.IsNaN(ccl.Location))) { ccl.SoilProfile2D.CenterCrestLocation = ccl.Location; }; @@ -512,7 +513,8 @@ } if (localCenterCrestLocation != null && Object.ReferenceEquals(localCenterCrestLocation.SoilProfile2D, soilProfile2D) && - Math.Abs(localCenterCrestLocation.Location - soilProfile2D.CenterCrestLocation) > double.Epsilon) + (Math.Abs(localCenterCrestLocation.Location - soilProfile2D.CenterCrestLocation) > double.Epsilon) || + double.IsNaN(localCenterCrestLocation.Location) || double.IsNaN(soilProfile2D.CenterCrestLocation)) { localCenterCrestLocation.Location = soilProfile2D.CenterCrestLocation; DataEventPublisherOnSelectionChanged(localCenterCrestLocation, null); @@ -536,7 +538,7 @@ } foreach (var shape in shapesToRemove) { - spatialEditor.Remove(shape); + spatialEditor.Remove(shape); // #BKA: very strange code (by Jay)! why do this!? Have to fix failmechloc same as centercrestloc. This to be removed!? spatialEditor.AddShape(shape); } } @@ -958,11 +960,19 @@ // set the proper localCenterCrestLocation if (!double.IsNaN(soilProfile.CenterCrestLocation)) { - localCenterCrestLocation = new CenterCrestLocation + var selectedCenterCrestLocation = spatialEditor.GetSelectedShapes().ToArray().FirstOrDefault(s => s.DataObject is CenterCrestLocation); + if (selectedCenterCrestLocation != null) { - SoilProfile2D = soilProfile, - Location = soilProfile.CenterCrestLocation - }; + localCenterCrestLocation = (CenterCrestLocation)selectedCenterCrestLocation.DataObject; + } + else + { + localCenterCrestLocation = new CenterCrestLocation + { + SoilProfile2D = soilProfile, + Location = soilProfile.CenterCrestLocation + }; + } } spatialEditor.AddObject(localCenterCrestLocation); @@ -1110,9 +1120,12 @@ UndoRedoManager.Instance.BeginAction(); DataEventPublisher.BeforeChange(soilProfile2D); DataEventPublisher.BeforeChange(project.SoilProfiles2D); - soilProfile2D.CenterCrestLocation = (soilProfile2D.Geometry.Right - soilProfile2D.Geometry.Left) * 0.5; - localCenterCrestLocation.SoilProfile2D = soilProfile2D; - localCenterCrestLocation.Location = soilProfile2D.CenterCrestLocation; + DataEventPublisher.InvokeWithoutPublishingEvents(() => + { + soilProfile2D.CenterCrestLocation = (soilProfile2D.Geometry.Right - soilProfile2D.Geometry.Left) * 0.5; + localCenterCrestLocation.SoilProfile2D = soilProfile2D; + localCenterCrestLocation.Location = soilProfile2D.CenterCrestLocation; + }); DataEventPublisher.DataListModified(project.SoilProfiles2D); DataEventPublisher.SelectionChanged(localCenterCrestLocation); UndoRedoManager.Instance.EndAction();