-
Notifications
You must be signed in to change notification settings - Fork 116
CSSTUDIO-3538 Bugfix: Redraw Linear Meter widget when the range or alarm limits are updated #3649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -735,7 +735,7 @@ public void setShowWarnings(boolean showWarnings) { | |
| private boolean isValueWaitingToBeDrawn = false; | ||
| private double valueWaitingToBeDrawn = Double.NaN; | ||
| /** @param newValue Current value */ | ||
| public void setCurrentValue(double newValue) | ||
| public void setCurrentValue(double newValue, boolean forceRedraw) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of boolean flags, I would write an enum enum DrawAction { or something like this.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An enum could be used, but since the data is still essentially only |
||
| { | ||
| withWriteLock(() -> { | ||
| valueWaitingToBeDrawn = newValue; | ||
|
|
@@ -746,7 +746,7 @@ public void setCurrentValue(double newValue) | |
| else { | ||
| isValueWaitingToBeDrawn = true; | ||
|
|
||
| drawNewValue(valueWaitingToBeDrawn); | ||
| drawNewValue(valueWaitingToBeDrawn, forceRedraw); | ||
| isValueWaitingToBeDrawn = false; | ||
| lag = false; | ||
| } | ||
|
|
@@ -777,7 +777,7 @@ private Optional<Integer> computeIndicatorPosition(double value) { | |
| }); | ||
| } | ||
|
|
||
| private void drawNewValue(double newValue) { | ||
| private void drawNewValue(double newValue, boolean forceRedraw) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this method be renamed now?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No: the method draws a new value. Before this pull request, it was "optimized too much": |
||
| withWriteLock(() -> { | ||
| WARNING oldWarning = determineWarning(); | ||
| AtomicReference<Double> newValueAtomicReference = new AtomicReference<>(newValue); // Workaround, since captured variables need to be effectively final in Java. | ||
|
|
@@ -795,15 +795,15 @@ private void drawNewValue(double newValue) { | |
| WARNING newWarning = determineWarning(); | ||
| logNewWarningIfDifferent(oldWarning, newWarning); | ||
|
|
||
| if (oldValue != newValueAtomicReference.get()) { | ||
| if (!Double.isNaN(newValueAtomicReference.get())){ | ||
| if (forceRedraw || oldValue != newValueAtomicReference.get()) { | ||
| if (forceRedraw || !Double.isNaN(newValueAtomicReference.get())){ | ||
| Optional<Integer> maybeNewIndicatorPosition = computeIndicatorPosition(newValue); | ||
| boolean indicatorPositionHasChanged = maybeNewIndicatorPosition.isPresent() != maybeOldIndicatorPosition.isPresent() || maybeOldIndicatorPosition.isPresent() && maybeNewIndicatorPosition.isPresent() && maybeOldIndicatorPosition.get() != maybeNewIndicatorPosition.get(); | ||
| if (indicatorPositionHasChanged || determineWarning() != newWarning) { | ||
| if (forceRedraw || indicatorPositionHasChanged || determineWarning() != newWarning) { | ||
| redrawIndicator(newValueAtomicReference.get(), newWarning); | ||
| } | ||
| } | ||
| else if (!Double.isNaN(oldValue)) { | ||
| else if (forceRedraw || !Double.isNaN(oldValue)) { | ||
| redrawIndicator(newValueAtomicReference.get(), newWarning); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me feel like this should be a property of the linearmeter, so this should be something like:
meter.setScaleUpdated()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree: I prefer explicit passing of values (in contrast to implicit passing of values through update of state). In particular,
linearMeterScaleHasChangedis passed tometer.setCurrentValue()on line 386: https://github.com/ControlSystemStudio/phoebus/pull/3649/files/c37e695e063c8014201fceb374da86198dbf2aa3#diff-99f66c9c7631b64fc8906945f212e452266b923ac7c5a7214eb7f604df210cbfR386