Skip to content

Conversation

@abrahamwolk
Copy link
Collaborator

This pull request fixes a bug in the Linear Meter: before this pull request, the Linear Meter would only be redrawn when the indicator position had changed at least one pixel. In particular, an update to the range or to the alarm limits in the connected PV did not force a redrawing of the Linear Meter widget.

I have tested the bugfix manually using a soft IOC.

Copy link
Contributor

@jacomago jacomago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions on how I might refactor.

}

private void drawNewValue(double newValue) {
private void drawNewValue(double newValue, boolean forceRedraw) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this method be renamed now?

Copy link
Collaborator Author

@abrahamwolk abrahamwolk Nov 17, 2025

Choose a reason for hiding this comment

The 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": drawNewValue() only actually drew a new value if it determined that the indicator had moved at least one pixel, which didn't account for the case where the range or the alarm limits had changed.

private double valueWaitingToBeDrawn = Double.NaN;
/** @param newValue Current value */
public void setCurrentValue(double newValue)
public void setCurrentValue(double newValue, boolean forceRedraw)
Copy link
Contributor

Choose a reason for hiding this comment

The 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 {
ForceRedraw
Draw
NoRender
}

or something like this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 true and false and the parameter name of meter.setCurrentValue() describes the meaning well, I prefer to use a boolean.

&& controlRange.getMaximum() - controlRange.getMinimum() > 0.0) {
if (meter.linearMeterScale.getValueRange().getLow() != controlRange.getMinimum() || meter.linearMeterScale.getValueRange().getHigh() != controlRange.getMaximum() || !meter.getValidRange()) {
meter.setRange(controlRange.getMinimum(), controlRange.getMaximum(), true);
linearMeterScaleHasChanged = true;
Copy link
Contributor

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()

Copy link
Collaborator Author

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, linearMeterScaleHasChanged is passed to meter.setCurrentValue() on line 386: https://github.com/ControlSystemStudio/phoebus/pull/3649/files/c37e695e063c8014201fceb374da86198dbf2aa3#diff-99f66c9c7631b64fc8906945f212e452266b923ac7c5a7214eb7f604df210cbfR386

@abrahamwolk abrahamwolk merged commit 7ae4d87 into master Nov 17, 2025
3 checks passed
@abrahamwolk abrahamwolk deleted the CSSTUDIO-3538 branch November 17, 2025 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants