Skip to content

Commit

Permalink
Merge branch 'master' into pvws_backend
Browse files Browse the repository at this point in the history
  • Loading branch information
rjwills28 committed May 29, 2024
2 parents 6cf424a + 67b6ff0 commit c64434e
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 3 deletions.
72 changes: 72 additions & 0 deletions src/ui/widgets/EmbeddedDisplay/bobParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,76 @@ describe("opi widget parser", (): void => {
// Is this correct?
expect(display.x).toEqual(undefined);
});

const readbackDefaults = `
<display version="2.0.0">
<x>0</x>
<y>0</y>
<width>300</width>
<height>300</height>
<widget type="textupdate" version="2.0.0">
<name>Text Update</name>
<pv_name>abc</pv_name>
<x>12</x>
<y>62</y>
<width>140</width>
<height>50</height>
<border_alarm_sensitive>false</border_alarm_sensitive>
</widget>
</display>`;
it("parses defaults", (): void => {
const widget = parseBob(readbackDefaults, "xxx", PREFIX)
.children?.[0] as WidgetDescription;
expect(widget.precisionFromPv).toEqual(true);
expect(widget.showUnits).toEqual(true);
});

const readbackPrecisionUnits = `
<display version="2.0.0">
<x>0</x>
<y>0</y>
<width>300</width>
<height>300</height>
<widget type="textupdate" version="2.0.0">
<name>Text Update</name>
<pv_name>abc</pv_name>
<x>12</x>
<y>62</y>
<width>140</width>
<height>50</height>
<border_alarm_sensitive>false</border_alarm_sensitive>
<precision>2</precision>
<show_units>false</show_units>
</widget>
</display>`;
it("parses precision and units", (): void => {
const widget = parseBob(readbackPrecisionUnits, "xxx", PREFIX)
.children?.[0] as WidgetDescription;
expect(widget.precisionFromPv).toEqual(undefined);
expect(widget.precision).toEqual(2);
expect(widget.showUnits).toEqual(false);
});

const readbackStringFormat = `
<display version="2.0.0">
<x>0</x>
<y>0</y>
<width>300</width>
<height>300</height>
<widget type="textupdate" version="2.0.0">
<name>Text Update</name>
<pv_name>abc</pv_name>
<x>12</x>
<y>62</y>
<width>140</width>
<height>50</height>
<border_alarm_sensitive>false</border_alarm_sensitive>
<format>6</format>
</widget>
</display>`;
it("parses string format", (): void => {
const widget = parseBob(readbackStringFormat, "xxx", PREFIX)
.children?.[0] as WidgetDescription;
expect(widget.formatType).toEqual("string");
});
});
13 changes: 12 additions & 1 deletion src/ui/widgets/EmbeddedDisplay/bobParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ function bobParsePosition(props: any): Position {
);
}

function bobParseFormatType(jsonProp: ElementCompact): string {
const formats: { [key: number]: string } = {
0: "default",
1: "decimal",
2: "exponential",
6: "string"
};
return formats[bobParseNumber(jsonProp) ?? 0];
}

export function bobParseFont(jsonProp: ElementCompact): Font {
const opiStyles: { [key: number]: FontStyle } = {
0: FontStyle.Regular,
Expand Down Expand Up @@ -248,7 +258,8 @@ export function parseBob(
imageFile: ["file", opiParseString],
points: ["points", bobParsePoints],
resize: ["resize", bobParseResizing],
squareLed: ["square", opiParseBoolean]
squareLed: ["square", opiParseBoolean],
formatType: ["format", bobParseFormatType]
};

const complexParsers = {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/widgets/EmbeddedDisplay/opiParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ describe("opi widget parser", (): void => {
<width>20</width>
<widget typeId="org.csstudio.opibuilder.widgets.TextInput" version="2.0.0">
<text />
<show_units>not-a-bool</show_units>
<enabled>not-a-bool</enabled>
</widget>
</display>`;
it("doesn't parse an invalid bool", (): void => {
// Reduce logging when expecting error.
log.setLevel("error");
const widget = parseOpi(invalidBool, "ca", PREFIX)
.children?.[0] as WidgetDescription;
expect(widget.showUnits).toBeUndefined();
expect(widget.enabled).toBeUndefined();
log.setLevel("info");
});
const xygraphString = `
Expand Down
12 changes: 12 additions & 0 deletions src/ui/widgets/EmbeddedDisplay/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,17 @@ export function parseWidget(
filepath
);
});

// Default to true if precision is not defined.
// Applicable to BOB files.
if (widgetDescription.precision === undefined) {
widgetDescription.precisionFromPv = true;
}
// Default to true if showUnits is not defined.
// Applicable to BOB files.
if (widgetDescription.showUnits === undefined) {
widgetDescription.showUnits = true;
}

return widgetDescription;
}
9 changes: 9 additions & 0 deletions src/ui/widgets/Readback/readback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ export const ReadbackComponent = (
} else {
displayedValue = DType.coerceString(value);
}
} else if (value.getArrayValue() !== undefined && prec !== undefined) {
displayedValue = "";
const array = Array.prototype.slice.call(value.getArrayValue());
for (let i = 0; i < array.length; i++) {
displayedValue = displayedValue.concat(array[i].toFixed(prec));
if (i < array.length - 1) {
displayedValue = displayedValue.concat(", ");
}
}
} else {
displayedValue = DType.coerceString(value);
}
Expand Down

0 comments on commit c64434e

Please sign in to comment.