while displaying dimensions in the viewport i need to show no of decimal points according to user's wish how to do that?

75 views Asked by At

in eyeshot wpf while displaying the dimensions in the viewport i have to show the decimal digits of dimension according to the decimal points which user entered in the text box of viewport. for ex: if num = 1.345 if he enters 1 then it should show 1.3 similarly for 1.234 if he enters 2 it should show 1.23 i tried the coding in drafting demo sample and this is my code

my code :

in dimensioning.cs class:

private void DrawInteractiveOrdinateDim()
{
    if (points.Count < 1)
        return;

    List<Point3D> pts = new List<Point3D>();
    Point3D leaderEndPoint;
    Segment3D[] segments = OrdinateDim.Preview(Plane.XY, points[0], current, drawingOrdinateDimVertical, dimTextHeight * 3, dimTextHeight, 0.625, 3.0, 0.625, out leaderEndPoint);            

    foreach (var segment3D in segments)
    {
        pts.Add(WorldToScreen(segment3D.P0));
        pts.Add(WorldToScreen(segment3D.P1));
    }
    renderContext.DrawLines(pts.ToArray());
    renderContext.EnableXOR(false);

    double distance = drawingOrdinateDimVertical ? Math.Abs(Plane.XY.Origin.X - points[0].X) : Math.Abs(Plane.XY.Origin.Y - points[0].Y);
    distance = Math.Round(distance, Roundoffno);
    string dimText = "D " + distance;
    DrawText(mouseLocation.X, (int)Size.Height - mouseLocation.Y + 10, dimText,
        new Font("Tahoma", 8.25f), DrawingColor, ContentAlignment.BottomLeft);
}

in snapping.cs class(to display final output)

else if (entity is Dimension)
{
    
    Dimension dim = (Dimension)entity;
    dim.LayerName = layerName;
    dim.WidthFactor = 0.9;

    dim.LineWeightMethod = colorMethodType.byEntity;

    double d1 = dim.Distance;
    double newDistance = Math.Round(d1, Roundoffno);

    dim.Text = "D " + newDistance.ToString();


    Entities.Add(dim);
}

what i'm expecting is while showing the dimension in the viewport i'm able to show the no.of decimal points according to user wish properly in the interactive way but in the final output it is getting back to original number there is mistake in the snapping.cs class. please help me in solving that

1

There are 1 answers

3
Akash Kansara On

You can do:

dim.Text = "D " + newDistance.ToString($"F{Roundoffno}");