Skip to content

Commit 9342c58

Browse files
authored
Merge pull request #39 from DiamondLightSource/2_add-zoom-control
Add component for zoom control
2 parents 84c64bb + 675e353 commit 9342c58

File tree

3 files changed

+51
-16
lines changed

3 files changed

+51
-16
lines changed

src/components/SelectionControl.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ type SelectionProps = PvDescription & {
88
id: string;
99
plan_name: string;
1010
choices: string[];
11-
transformValue?: Transformer;
1211
};
1312

1413
/** Custom component for a dropdown selection which runs a plan unpon every change event
1514
* For now to be used for backlight and zoom control
1615
*/
17-
export function SelectAndRunPlan(props: SelectionProps) {
16+
export function SelectionWithPlanRunner(props: SelectionProps) {
1817
const currentValue = String(
1918
useParsedPvConnection({
2019
pv: props.pv,
@@ -23,20 +22,20 @@ export function SelectAndRunPlan(props: SelectionProps) {
2322
})
2423
);
2524
console.log(`${props.id} current value: ${currentValue}`);
26-
const [val, updateVal] = React.useState<string>(currentValue.toString());
25+
const [_, updateVal] = React.useState<string>(currentValue.toString());
2726

2827
const handleChange = (newValue: typeof currentValue) => {
2928
updateVal(newValue);
3029
submitAndRunPlanImmediately(props.plan_name, { position: newValue });
3130
};
3231

3332
return (
34-
<FormControl size="small" style={{ width: 150 }}>
33+
<FormControl size="small" style={{ width: 200 }}>
3534
<InputLabel id={props.label}>{props.id}</InputLabel>
3635
<Select
3736
labelId={props.label}
3837
id={props.id}
39-
value={val}
38+
value={currentValue}
4039
label={props.label}
4140
onChange={(e) => handleChange(String(e.target.value))}
4241
>

src/pv/enumPvValues.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export const BacklightPositions = [
2+
"Out",
3+
"In",
4+
"LoadCheck",
5+
"OAV2",
6+
"Diode",
7+
"White In",
8+
];
9+
10+
export const ZoomLevels = [
11+
"1.0",
12+
"2.0",
13+
"3.0",
14+
"4.0",
15+
"5.0",
16+
"6.0",
17+
"8.0",
18+
"10.0",
19+
"11.0",
20+
];

src/screens/OavMover.tsx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,8 @@ import React from "react";
1212
import { submitAndRunPlanImmediately } from "../blueapi/blueapi";
1313
import { CoordNumberInput } from "../components/CoordNumberInput";
1414
import { PvDescription } from "../pv/PvComponent";
15-
import { SelectAndRunPlan } from "../components/SelectionControl";
16-
17-
const BacklightPositions = [
18-
"Out",
19-
"In",
20-
"LoadCheck",
21-
"OAV2",
22-
"Diode",
23-
"White In",
24-
];
15+
import { SelectionWithPlanRunner } from "../components/SelectionControl";
16+
import { BacklightPositions, ZoomLevels } from "../pv/enumPvValues";
2517

2618
function BacklightControl(props: PvDescription) {
2719
const theme = useTheme();
@@ -32,7 +24,7 @@ function BacklightControl(props: PvDescription) {
3224
paddingTop={1}
3325
paddingBottom={1}
3426
>
35-
<SelectAndRunPlan
27+
<SelectionWithPlanRunner
3628
pv={props.pv}
3729
label={props.label}
3830
id="Backlight"
@@ -43,6 +35,26 @@ function BacklightControl(props: PvDescription) {
4335
);
4436
}
4537

38+
function ZoomControl(props: PvDescription) {
39+
const theme = useTheme();
40+
return (
41+
<Box
42+
bgcolor={theme.palette.background.paper}
43+
borderRadius={5}
44+
paddingTop={1}
45+
paddingBottom={1}
46+
>
47+
<SelectionWithPlanRunner
48+
pv={props.pv}
49+
label={props.label}
50+
id="ZoomControl"
51+
plan_name="gui_set_zoom_level"
52+
choices={ZoomLevels}
53+
/>
54+
</Box>
55+
);
56+
}
57+
4658
export function MoveArrows() {
4759
const theme = useTheme();
4860
return (
@@ -210,6 +222,10 @@ export function OavMover() {
210222
label="backlight-pos"
211223
pv="ca://BL24I-MO-BL-01:MP:SELECT"
212224
/>
225+
<ZoomControl
226+
label="zoom-level"
227+
pv="ca://BL24I-EA-OAV-01:FZOOM:MP:SELECT"
228+
/>
213229
</Grid2>
214230
</Grid2>
215231
</div>

0 commit comments

Comments
 (0)