Skip to content

Commit

Permalink
Circle tab fixes, almost complete now
Browse files Browse the repository at this point in the history
  • Loading branch information
rjones0 committed Feb 21, 2017
1 parent d27b1b6 commit 5b5874b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 17 deletions.
Expand Up @@ -129,6 +129,7 @@ public TimeUnits TimeUnit
RaisePropertyChanged(() => TimeUnit);
RaisePropertyChanged(() => TravelRateString);
RaisePropertyChanged(() => TravelTimeString);
RaisePropertyChanged(() => LineDistanceType);
}
}

Expand Down Expand Up @@ -258,6 +259,7 @@ public double TravelTime
RaisePropertyChanged(() => TimeUnit);
RaisePropertyChanged(() => TravelRateString);
RaisePropertyChanged(() => TravelTimeString);
RaisePropertyChanged(() => LineDistanceType);
}
}

Expand Down Expand Up @@ -347,6 +349,7 @@ public double TravelRate
RaisePropertyChanged(() => TravelTimeString);
RaisePropertyChanged(() => RateTimeUnit);
RaisePropertyChanged(() => TimeUnit);
RaisePropertyChanged(() => LineDistanceType);
}
}

Expand Down Expand Up @@ -436,8 +439,10 @@ public RateTimeTypes RateTimeUnit

// Trigger validation to clear error messages as necessary
RaisePropertyChanged(() => RateTimeUnit);
RaisePropertyChanged(() => TimeUnit);
RaisePropertyChanged(() => TravelTimeString);
RaisePropertyChanged(() => TravelRateString);
RaisePropertyChanged(() => LineDistanceType);
}
}

Expand Down Expand Up @@ -726,24 +731,30 @@ private IGeometry CreateCircle()
//Get centroid of polygon
var area = newPoly as IArea;


string unitLabel = "";
int roundingFactor = 0;
// If Distance Calculator is in use, use the unit from the Rate combobox
// to label the circle
if (IsDistanceCalcExpanded)
{
// Select appropriate label and number of decimal places
int roundingFactor = 0;
switch (RateUnit)
{
case DistanceTypes.Feet:
case DistanceTypes.Kilometers:
case DistanceTypes.Meters:
case DistanceTypes.Miles:
case DistanceTypes.Yards:
unitLabel = RateUnit.ToString();
roundingFactor = 2;
break;
case DistanceTypes.Miles:
case DistanceTypes.Kilometers:
unitLabel = RateUnit.ToString();
roundingFactor = 6;
break;
case DistanceTypes.NauticalMile:
unitLabel = "Nautical Miles";
roundingFactor = 6;
break;
default:
break;
Expand All @@ -753,6 +764,28 @@ private IGeometry CreateCircle()
// to label the circle
else
{
// Select appropriate number of decimal places
switch (LineDistanceType)
{
case DistanceTypes.Feet:
case DistanceTypes.Meters:
case DistanceTypes.Yards:
unitLabel = RateUnit.ToString();
roundingFactor = 1;
break;
case DistanceTypes.Miles:
case DistanceTypes.Kilometers:
unitLabel = RateUnit.ToString();
roundingFactor = 4;
break;
case DistanceTypes.NauticalMile:
unitLabel = "Nautical Miles";
roundingFactor = 4;
break;
default:
break;
}

DistanceTypes dtVal = (DistanceTypes)LineDistanceType;
unitLabel = dtVal.ToString();
}
Expand All @@ -765,7 +798,17 @@ private IGeometry CreateCircle()
convertedDistance *= 2;
}

string distanceLabel = (TrimPrecision(convertedDistance)).ToString("N2");
string distanceLabel ="";
// Use the unit from Rate combobox if Distance Calculator is expanded
if (IsDistanceCalcExpanded)
{
convertedDistance = ConvertFromTo(LineDistanceType, RateUnit, convertedDistance);
distanceLabel = (TrimPrecision(convertedDistance, RateUnit, true)).ToString("N"+roundingFactor.ToString());
}
else
{
distanceLabel = (TrimPrecision(convertedDistance, LineDistanceType, false)).ToString("N" + roundingFactor.ToString());
}

//Add text using centroid point
//Use circleType to ensure our label contains either Radius or Diameter dependent on mode
Expand Down
Expand Up @@ -109,21 +109,21 @@ public double MinorAxisDistance
{
// Despite being too large we still need to set this in order that we can
// avoid drawing preview if necessary when minorAxisDistance is varied
minorAxisDistance = TrimPrecision(value);
minorAxisDistance = TrimPrecision(value, false);
ClearTempGraphics();
throw new ArgumentException(DistanceAndDirectionLibrary.Properties.Resources.AEInvalidInput);
}
if (majorAxisDistance > MajorAxisLimit)
{
// Despite being too large we still need to set this in order that we can
// avoid drawing preview if necessary when minorAxisDistance is varied
minorAxisDistance = TrimPrecision(value);
minorAxisDistance = TrimPrecision(value, false);
ClearTempGraphics();
return;
}


minorAxisDistance = TrimPrecision(value);
minorAxisDistance = TrimPrecision(value, false);

UpdateFeedbackWithEllipse();

Expand Down Expand Up @@ -186,12 +186,12 @@ public double MajorAxisDistance
{
// Despite being too large we still need to set this in order that we can
// avoid drawing preview if necessary when minorAxisDistance is varied
majorAxisDistance = TrimPrecision(value);
majorAxisDistance = TrimPrecision(value, false);
ClearTempGraphics();
throw new ArgumentException(DistanceAndDirectionLibrary.Properties.Resources.AEInvalidInput);
}

majorAxisDistance = TrimPrecision(value);
majorAxisDistance = TrimPrecision(value, false);

Point2 = UpdateFeedback(Point1, MajorAxisDistance);

Expand Down
Expand Up @@ -109,7 +109,7 @@ public override double Distance
if (value < 0.0)
throw new ArgumentException(DistanceAndDirectionLibrary.Properties.Resources.AEMustBePositive);

distance = TrimPrecision(value);
distance = TrimPrecision(value, false);
RaisePropertyChanged(() => Distance);

if(LineFromType == LineFromTypes.BearingAndDistance)
Expand Down
Expand Up @@ -1239,14 +1239,26 @@ internal double ConvertFromTo(DistanceTypes fromType, DistanceTypes toType, doub
}

// Overload for calling from another class where lineDistanceType is not available
protected double TrimPrecision(double inputDistance)
protected double TrimPrecision(double inputDistance, bool lax)
{
return TrimPrecision(inputDistance, lineDistanceType);
return TrimPrecision(inputDistance, lineDistanceType, lax);
}

// Remove superfluous precision with
protected double TrimPrecision(double inputDistance, DistanceTypes lineDistanceType_param)
// Remove superfluous precision
protected double TrimPrecision(double inputDistance, DistanceTypes lineDistanceType_param, bool lax)
{
int largeUnitRoundingFactor = 4;
int smallUnitRoundingFactor = 1;

// We have a less strict mode for trimming precision for the case that the user
// has Distance Calculator expanded and thus might have a large unit selected
// - otherwise we can trim label down to e.g. 0.00 Miles
if (lax)
{
largeUnitRoundingFactor = 6;
smallUnitRoundingFactor = 2;
}

double returnDistance = 0;
// For smaller units assume a tenth is sufficient
// For larger units provide ten thousandth i.e. 4 decimal places, probably more than sufficient
Expand All @@ -1255,12 +1267,12 @@ protected double TrimPrecision(double inputDistance, DistanceTypes lineDistanceT
case DistanceTypes.Kilometers:
case DistanceTypes.Miles:
case DistanceTypes.NauticalMile:
returnDistance = Math.Round(inputDistance, 4);
returnDistance = Math.Round(inputDistance, largeUnitRoundingFactor);
break;
case DistanceTypes.Meters:
case DistanceTypes.Feet:
case DistanceTypes.Yards:
returnDistance = Math.Round(inputDistance, 1);
returnDistance = Math.Round(inputDistance, smallUnitRoundingFactor);
break;
default:
break;
Expand Down Expand Up @@ -1353,7 +1365,7 @@ internal void UpdateDistance(IGeometry geometry)

double rawDistance = GetGeodeticLengthFromPolyline(polyline);
// Round the superfluous precision appropriately to unit
Distance = TrimPrecision(rawDistance, lineDistanceType);
Distance = TrimPrecision(rawDistance, lineDistanceType, false);
}

/// <summary>
Expand Down

0 comments on commit 5b5874b

Please sign in to comment.