Farmbot-Web-App/frontend/farmware/weed_detector/config.tsx

109 lines
3.3 KiB
TypeScript
Raw Normal View History

2017-06-29 12:54:02 -06:00
import * as React from "react";
import {
BlurableInput,
Row, Col,
FBSelect, NULL_CHOICE, DropDownItem
} from "../../ui/index";
2017-06-29 12:54:02 -06:00
import { SettingsMenuProps } from "./interfaces";
import {
SPECIAL_VALUE_DDI, CALIBRATION_DROPDOWNS, ORIGIN_DROPDOWNS
} from "./constants";
2017-06-29 12:54:02 -06:00
import { WD_ENV } from "./remote_env/interfaces";
import { envGet } from "./remote_env/selectors";
import { SPECIAL_VALUES } from "./remote_env/constants";
2019-02-04 07:32:26 -07:00
import { isNumber } from "lodash";
2019-04-02 13:59:37 -06:00
import { t } from "../../i18next_wrapper";
2017-06-29 12:54:02 -06:00
2018-02-20 17:40:37 -07:00
export class WeedDetectorConfig extends React.Component<SettingsMenuProps, {}> {
NumberBox = ({ conf, label }: {
2017-06-29 12:54:02 -06:00
conf: keyof WD_ENV;
label: string;
}) => {
return <div>
<label htmlFor={conf}>
{label}
</label>
<BlurableInput type="number"
id={conf}
2018-02-20 17:40:37 -07:00
value={"" + envGet(conf, this.props.values)}
2019-09-23 12:56:35 -06:00
onCommit={e =>
this.props.onChange(conf, parseFloat(e.currentTarget.value))}
2017-06-29 12:54:02 -06:00
placeholder={label} />
</div>;
2017-06-29 12:54:02 -06:00
};
2018-02-20 17:40:37 -07:00
setDDI = (k: keyof WD_ENV) => (d: DropDownItem) => {
2019-02-04 07:32:26 -07:00
if (isNumber(d.value)) {
2018-02-20 17:40:37 -07:00
this.props.onChange(k, d.value);
2017-06-29 12:54:02 -06:00
} else {
throw new Error("Weed detector got a non-numeric value");
}
};
2017-06-29 12:54:02 -06:00
2018-02-20 17:40:37 -07:00
find = (needle: keyof WD_ENV): DropDownItem => {
const wow = envGet(needle, this.props.values);
2017-08-28 05:49:13 -06:00
const ok = SPECIAL_VALUE_DDI[wow];
2017-06-29 12:54:02 -06:00
return ok || NULL_CHOICE;
};
2017-06-29 12:54:02 -06:00
2018-02-20 17:40:37 -07:00
render() {
return <div>
<label htmlFor="invert_hue_selection">
{t("Invert Hue Range Selection")}
</label>
<div>
<input
type="checkbox"
id="invert_hue_selection"
2019-09-23 12:56:35 -06:00
checked={!!envGet("CAMERA_CALIBRATION_invert_hue_selection",
this.props.values)}
onChange={e =>
this.props.onChange("CAMERA_CALIBRATION_invert_hue_selection",
e.currentTarget.checked ?
SPECIAL_VALUES.TRUE : SPECIAL_VALUES.FALSE)} />
2018-02-20 17:40:37 -07:00
</div>
<this.NumberBox
conf={"CAMERA_CALIBRATION_calibration_object_separation"}
label={t(`Calibration Object Separation`)} />
<label>
{t(`Calibration Object Separation along axis`)}
</label>
<FBSelect
onChange={this.setDDI("CAMERA_CALIBRATION_calibration_along_axis")}
selectedItem={this.find("CAMERA_CALIBRATION_calibration_along_axis")}
2019-04-26 10:34:36 -06:00
list={CALIBRATION_DROPDOWNS} />
2018-02-20 17:40:37 -07:00
<Row>
<Col xs={6}>
<this.NumberBox
conf={"CAMERA_CALIBRATION_camera_offset_x"}
label={t(`Camera Offset X`)} />
</Col>
<Col xs={6}>
<this.NumberBox
conf={"CAMERA_CALIBRATION_camera_offset_y"}
label={t(`Camera Offset Y`)} />
</Col>
</Row>
<label htmlFor="image_bot_origin_location">
{t(`Origin Location in Image`)}
</label>
<FBSelect
list={ORIGIN_DROPDOWNS}
onChange={this.setDDI("CAMERA_CALIBRATION_image_bot_origin_location")}
2019-04-26 10:34:36 -06:00
selectedItem={this.find("CAMERA_CALIBRATION_image_bot_origin_location")} />
2018-02-20 17:40:37 -07:00
<Row>
<Col xs={6}>
<this.NumberBox
conf={"CAMERA_CALIBRATION_coord_scale"}
label={t(`Pixel coordinate scale`)} />
</Col>
<Col xs={6}>
<this.NumberBox
conf={"CAMERA_CALIBRATION_total_rotation_angle"}
label={t(`Camera rotation`)} />
</Col>
</Row>
</div>;
}
}