Issue #2265 - fixed infinite loop and display issues.

Change-Id: I48a2989de3cdee090355f46ed8f878ec440f93f4

Former-commit-id: 8878c50686 [formerly 7f49d34c36] [formerly 69a33641e1] [formerly 8878c50686 [formerly 7f49d34c36] [formerly 69a33641e1] [formerly e0e3b86267 [formerly 69a33641e1 [formerly 56beb5a4d0d0dce78994209f355afdf259f79dfb]]]]
Former-commit-id: e0e3b86267
Former-commit-id: 467f9808a5 [formerly 3ef75ebcd6] [formerly 7de08d38af3c84d0b13816cb14cfdbf70583e7d4 [formerly a57281a345]]
Former-commit-id: 22d941fed09eca1e667145fedf83a01b295c51a7 [formerly edc641e9bc]
Former-commit-id: bd31d85d0e
This commit is contained in:
Lee Venable 2013-08-21 16:29:23 -05:00
parent 06c82e1912
commit 590f870373

View file

@ -28,6 +28,7 @@ import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
@ -45,6 +46,10 @@ import org.eclipse.swt.widgets.Composite;
* 18 JUN 2008 1119 lvenable Updated to draw the Wind Rose diagram.
* 19 AUG 2008 1454 lvenable Fix saving wind rose image.
* 09 MAR 2012 14530 zhao Revised wind rose plot to match AWIPS-1
* 21 Aug 2265 #2265 lvenable Fixed infinite loop issue that will hang CAVE. Put a
* message on the display to show data is not available
* and changed the formatting of the data to not display
* nulls and NaNs when data is not available.
*
* </pre>
*
@ -309,16 +314,29 @@ public class WindRoseCanvasComp extends Composite {
double ringPercent = 0.02; // start with 2%
int radiusPix = 0;
for (;;) {
/*
* This code was ported over from AWIPS I (see software history). We
* need to verify that pixPerUnit is not zero or NaN and
* variableRingPercent is not NaN. This is to prevent an infinite loop
* from occurring because the break is not getting called under certain
* instances.
*/
if ((!Double.isNaN(pixPerUnit) || pixPerUnit != 0.0)
&& !Double.isNaN(variableRingPercent)) {
radiusPix = (int) Math.round( pixPerUnit * Math.sqrt( ringPercent + variableRingPercent*variableRingPercent ) );
if ( radiusPix >= maxCircleRadius ) {
break;
}
gc.drawOval(centerX - radiusPix, circleCenterY - radiusPix, radiusPix * 2, radiusPix * 2);
while (radiusPix < maxCircleRadius) {
radiusPix = (int) Math.round(pixPerUnit
* Math.sqrt(ringPercent + variableRingPercent
* variableRingPercent));
percentLbl = String.format(format, Math.round(ringPercent*100));
gc.drawText(percentLbl, centerX - (percentLbl.length() * fontAveWidth / 2), circleCenterY + radiusPix + 3, true);
gc.drawOval(centerX - radiusPix, circleCenterY - radiusPix,
radiusPix * 2, radiusPix * 2);
percentLbl = String.format(format,
Math.round(ringPercent * 100));
gc.drawText(percentLbl, centerX
- (percentLbl.length() * fontAveWidth / 2),
circleCenterY + radiusPix + 3, true);
if (ringPercent < 0.09) {
ringPercent += 0.02;
@ -328,6 +346,13 @@ public class WindRoseCanvasComp extends Composite {
ringPercent += 0.1;
}
}
} else {
String tmpStr = "NO DATA AVAILABLE FOR: " + windRoseHeader;
gc.setFont(canvasFontLrg);
Point strExt = gc.stringExtent(tmpStr);
gc.drawText(tmpStr, CANVAS_WIDTH / 2 - strExt.x / 2,
CANVAS_HEIGHT / 2, true);
}
// -------------------------------
// Draw the Wind Rose header
@ -383,9 +408,19 @@ public class WindRoseCanvasComp extends Composite {
gc.fillRectangle(aboveRect);
gc.drawRectangle(aboveRect);
String tmpStr = String.format("%4S+ kt: %4.1f%%",
String tmpStr = null;
if (Double.isNaN(knotPercents[5])) {
tmpStr = String.format("%4S+ kt:", windRoseConfigData.getVar3Max());
gc.drawString(tmpStr, rectStartX + rectWidth + 5, aboveRect.y, true);
} else {
tmpStr = String.format("%4S+ kt: %4.1f%%",
windRoseConfigData.getVar3Max(), knotPercents[5]);
gc.drawString(tmpStr, rectStartX + rectWidth + 5, aboveRect.y, true);
}
// tmpStr = String.format("%4S+ kt: %4.1f%%",
// windRoseConfigData.getVar3Max(), knotPercents[5]);
// gc.drawString(tmpStr, rectStartX + rectWidth + 5, aboveRect.y, true);
// --------------------------------------------
// Draw Wind speed var 3 information
@ -400,8 +435,16 @@ public class WindRoseCanvasComp extends Composite {
String tmpKt = String.format("%S-%S", windRoseConfigData.getVar2Max(),
windRoseConfigData.getVar3Max());
if (Double.isNaN(knotPercents[4])) {
tmpStr = String.format("%5S kt:", tmpKt);
gc.drawString(tmpStr, rectStartX + rectWidth + 5, windVar3Rect.y,
true);
} else {
tmpStr = String.format("%5S kt: %4.1f%%", tmpKt, knotPercents[4]);
gc.drawString(tmpStr, rectStartX + rectWidth + 5, windVar3Rect.y, true);
gc.drawString(tmpStr, rectStartX + rectWidth + 5, windVar3Rect.y,
true);
}
// --------------------------------------------
// Draw Wind speed var 2 information
@ -416,8 +459,16 @@ public class WindRoseCanvasComp extends Composite {
tmpKt = String.format("%S-%S", windRoseConfigData.getVar1Max(),
windRoseConfigData.getVar2Max());
if (Double.isNaN(knotPercents[3])) {
tmpStr = String.format("%5S kt:", tmpKt);
gc.drawString(tmpStr, rectStartX + rectWidth + 5, windVar2Rect.y,
true);
} else {
tmpStr = String.format("%5S kt: %4.1f%%", tmpKt, knotPercents[3]);
gc.drawString(tmpStr, rectStartX + rectWidth + 5, windVar2Rect.y, true);
gc.drawString(tmpStr, rectStartX + rectWidth + 5, windVar2Rect.y,
true);
}
// --------------------------------------------
// Draw Wind speed var 1 information
@ -431,8 +482,16 @@ public class WindRoseCanvasComp extends Composite {
gc.drawRectangle(windVar1Rect);
tmpKt = String.format("%S-%S", "0", windRoseConfigData.getVar1Max());
if (Double.isNaN(knotPercents[2])) {
tmpStr = String.format("%5S kt:", tmpKt);
gc.drawString(tmpStr, rectStartX + rectWidth + 5, windVar1Rect.y,
true);
} else {
tmpStr = String.format("%5S kt: %4.1f%%", tmpKt, knotPercents[2]);
gc.drawString(tmpStr, rectStartX + rectWidth + 5, windVar1Rect.y, true);
gc.drawString(tmpStr, rectStartX + rectWidth + 5, windVar1Rect.y,
true);
}
// --------------------------------------------
// Draw variable information
@ -445,8 +504,14 @@ public class WindRoseCanvasComp extends Composite {
gc.fillRectangle(variableRect);
gc.drawRectangle(variableRect);
if (Double.isNaN(knotPercents[1])) {
gc.drawString("variable: ", rectStartX + rectWidth + 5,
variableRect.y, true);
} else {
tmpStr = String.format("variable: %4.1f%%", knotPercents[1]);
gc.drawString(tmpStr, rectStartX + rectWidth + 5, variableRect.y, true);
gc.drawString(tmpStr, rectStartX + rectWidth + 5, variableRect.y,
true);
}
// --------------------------------------------
// Draw calm information
@ -459,16 +524,30 @@ public class WindRoseCanvasComp extends Composite {
gc.fillRectangle(calmRect);
gc.drawRectangle(calmRect);
if (Double.isNaN(knotPercents[1])) {
gc.drawString(" calm:", rectStartX + rectWidth + 5, calmRect.y,
true);
} else {
tmpStr = String.format(" calm: %4.1f%%", knotPercents[0]);
gc.drawString(tmpStr, rectStartX + rectWidth + 5, calmRect.y, true);
}
// --------------------------------------------
// Draw years & hours information
// --------------------------------------------
tmpStr = String.format("Years: %9S", windRoseDataMgr.getYears());
if (windRoseDataMgr.getYears() != null) {
tmpStr = String.format("Years: %S", windRoseDataMgr.getYears());
} else {
tmpStr = "Years:";
}
gc.drawString(tmpStr, 425, variableRect.y, true);
tmpStr = String.format("Total Hours: %S", windRoseDataMgr.getHours());
if (windRoseDataMgr.getHours() != null) {
tmpStr = String.format("Total Hours: %S",
windRoseDataMgr.getHours());
} else {
tmpStr = "Total Hours:";
}
gc.drawString(tmpStr, 425, calmRect.y, true);
tmpColor.dispose();
@ -549,11 +628,10 @@ public class WindRoseCanvasComp extends Composite {
// Determine how many wind directions will be drawn on the
// Wind Rose diagram.
/**
* DR14530:
* Angle of wind direction is measured clockwise with North (12 o'clock) = 0 degree,
* whereas, angle in GC.fillAra() and GC.drawArc() is measured counter-clockwise,
* with East (3 o'clock) = 0 degree
* [zhao, 3/2/2012]
* DR14530: Angle of wind direction is measured clockwise with
* North (12 o'clock) = 0 degree, whereas, angle in GC.fillAra()
* and GC.drawArc() is measured counter-clockwise, with East (3
* o'clock) = 0 degree [zhao, 3/2/2012]
*/
if (directions == 8) {
// Draw a filled arc for the current knot range.
@ -704,8 +782,7 @@ public class WindRoseCanvasComp extends Composite {
windRoseConfigData.getVariableRgb());
gc.setBackground(tmpColor);
int variablePix = (int) Math
.round(variableRingPercent * pixPerUnit);
int variablePix = (int) Math.round(variableRingPercent * pixPerUnit);
gc.fillOval(centerX - variablePix, circleCenterY - variablePix,
variablePix * 2, variablePix * 2);
@ -762,7 +839,8 @@ public class WindRoseCanvasComp extends Composite {
sum += knotsData[j];
}
pixelVals[i] = (int) Math.round( Math.sqrt( (calmAve + variableAve + sum)/totalWindValue )
pixelVals[i] = (int) Math.round(Math
.sqrt((calmAve + variableAve + sum) / totalWindValue)
* pixPerUnit);
}
@ -779,7 +857,8 @@ public class WindRoseCanvasComp extends Composite {
double calmValue = windRoseDataMgr.getCalmValue();
double variableValue = windRoseDataMgr.getVariableValue();
calmRingPercent = Math.sqrt(calmValue / totalValue / numWindDirections);
variableRingPercent = Math.sqrt((calmValue+variableValue)/totalValue/numWindDirections);
variableRingPercent = Math.sqrt((calmValue + variableValue)
/ totalValue / numWindDirections);
double highestPercent = Math.sqrt(windRoseDataMgr
.getLargestWindDirectionPercent()) * 100;