Index: src/Deltares.DSoilModel.Forms/DrawingSpecificMechanismPointLocation.cs =================================================================== diff -u -r631 -r684 --- src/Deltares.DSoilModel.Forms/DrawingSpecificMechanismPointLocation.cs (.../DrawingSpecificMechanismPointLocation.cs) (revision 631) +++ src/Deltares.DSoilModel.Forms/DrawingSpecificMechanismPointLocation.cs (.../DrawingSpecificMechanismPointLocation.cs) (revision 684) @@ -39,7 +39,7 @@ /// public class DrawingSpecificMechanismPointLocation : DrawingObject { - private const double PercentageForSpecificMechanismPointLocation = 0.01; + private const double percentageForSpecificMechanismPointLocation = 0.01; private double bottom = -20; private object dataObj; private GeometryPoint insertionPoint = new GeometryPoint(0, 0, 0); @@ -91,9 +91,10 @@ public double TopForDrawing() { if (specificMechanismPointLocation.SoilProfile2D == null || - specificMechanismPointLocation.SoilProfile2D.Geometry == null) + specificMechanismPointLocation.SoilProfile2D.Geometry == null || + specificMechanismPointLocation.SoilProfile2D.Geometry.Points.Count == 0) { - return 0; + return 10; } var diff = GetOffsetFromGeometryHeight(); return specificMechanismPointLocation.SoilProfile2D.Geometry.MaxGeometryPointsZ + 0.05*diff; @@ -105,8 +106,13 @@ public double BottomForDrawing() { if (specificMechanismPointLocation.SoilProfile2D == null || - specificMechanismPointLocation.SoilProfile2D.Geometry == null) + specificMechanismPointLocation.SoilProfile2D.Geometry == null || + specificMechanismPointLocation.SoilProfile2D.Geometry.Points.Count == 0) { + if (specificMechanismPointLocation.SoilProfile2D != null && specificMechanismPointLocation.SoilProfile2D.Geometry != null) + { + return specificMechanismPointLocation.SoilProfile2D.Geometry.Bottom; + } return 0; } var diff = GetOffsetFromGeometryHeight(); @@ -119,9 +125,14 @@ public double WidthForDrawing() { if (specificMechanismPointLocation.SoilProfile2D == null || - specificMechanismPointLocation.SoilProfile2D.Geometry == null) + specificMechanismPointLocation.SoilProfile2D.Geometry == null || + specificMechanismPointLocation.SoilProfile2D.Geometry.Points.Count == 0) { - return 1; + if (specificMechanismPointLocation.SoilProfile2D != null && specificMechanismPointLocation.SoilProfile2D.Geometry != null) + { + return Math.Max(1.0, specificMechanismPointLocation.SoilProfile2D.Geometry.Right - specificMechanismPointLocation.SoilProfile2D.Geometry.Left); + } + return 50.0; } return Math.Abs(specificMechanismPointLocation.SoilProfile2D.Geometry.MaxGeometryPointsX - specificMechanismPointLocation.SoilProfile2D.Geometry.MinGeometryPointsX); } @@ -133,12 +144,13 @@ { dataObj = dataObject; specificMechanismPointLocation = null; - if (dataObject is SpecificMechanismPointLocation) + var location = dataObject as SpecificMechanismPointLocation; + if (location != null) { - specificMechanismPointLocation = (SpecificMechanismPointLocation) dataObject; + specificMechanismPointLocation = location; top = TopForDrawing(); bottom = BottomForDrawing(); - width = WidthForDrawing()*PercentageForSpecificMechanismPointLocation; + width = WidthForDrawing()*percentageForSpecificMechanismPointLocation; insertionPoint = new GeometryPoint(specificMechanismPointLocation.XCoordinate, 0, bottom); ShowAxes = true; } @@ -161,7 +173,7 @@ { if (double.IsNaN(specificMechanismPointLocation.XCoordinate)) { - InitializeInsertionPoint(info); + return; } DrawingSupport.SetIEPDraw3D(info.Graphics); @@ -186,7 +198,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)); } @@ -279,36 +291,6 @@ var diff = specificMechanismPointLocation.SoilProfile2D.Geometry.MaxGeometryPointsZ - specificMechanismPointLocation.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 = specificMechanismPointLocation.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; - } - specificMechanismPointLocation.XCoordinate = insertionPoint.X; - } - - private Point GetScaledPoint(IProjection projection, Point3D aOrginalPoint) - { - return projection.ConvertToScreen(aOrginalPoint.GetPointXZ()); - } + } } } \ No newline at end of file