|
| 1 | +// @flow |
| 2 | +import { Checkbox, Col, Collapse, Form, Icon, Input, Row, Tooltip, Table, Button } from "antd"; |
| 3 | +import * as React from "react"; |
| 4 | +import _ from "lodash"; |
| 5 | + |
| 6 | +import type { DatasetConfiguration, UserConfiguration } from "oxalis/store"; |
| 7 | +import { jsonEditStyle } from "dashboard/dataset/helper_components"; |
| 8 | +import { jsonStringify } from "libs/utils"; |
| 9 | +import { settings } from "messages"; |
| 10 | +import { validateUserSettingsJSON } from "dashboard/dataset/validation"; |
| 11 | + |
| 12 | +const FormItem = Form.Item; |
| 13 | +const { Panel } = Collapse; |
| 14 | + |
| 15 | +const recommendedConfigByCategory = { |
| 16 | + orthogonal: { |
| 17 | + clippingDistance: 80, |
| 18 | + moveValue: 500, |
| 19 | + displayScalebars: false, |
| 20 | + newNodeNewTree: false, |
| 21 | + tdViewDisplayPlanes: false, |
| 22 | + }, |
| 23 | + all: { |
| 24 | + dynamicSpaceDirection: true, |
| 25 | + highlightCommentedNodes: false, |
| 26 | + overrideNodeRadius: true, |
| 27 | + particleSize: 5, |
| 28 | + keyboardDelay: 0, |
| 29 | + displayCrosshair: true, |
| 30 | + }, |
| 31 | + dataset: { |
| 32 | + fourBit: false, |
| 33 | + interpolation: true, |
| 34 | + quality: 0, |
| 35 | + segmentationOpacity: 0, |
| 36 | + highlightHoveredCellId: false, |
| 37 | + zoom: 0.8, |
| 38 | + renderMissingDataBlack: false, |
| 39 | + }, |
| 40 | + flight: { |
| 41 | + clippingDistanceArbitrary: 60, |
| 42 | + moveValue3d: 600, |
| 43 | + mouseRotateValue: 0.001, |
| 44 | + rotateValue: 0.01, |
| 45 | + sphericalCapRadius: 500, |
| 46 | + }, |
| 47 | +}; |
| 48 | + |
| 49 | +export const DEFAULT_RECOMMENDED_CONFIGURATION: $Shape<{| |
| 50 | + ...UserConfiguration, |
| 51 | + ...DatasetConfiguration, |
| 52 | +|}> = { |
| 53 | + ...recommendedConfigByCategory.orthogonal, |
| 54 | + ...recommendedConfigByCategory.all, |
| 55 | + ...recommendedConfigByCategory.dataset, |
| 56 | + ...recommendedConfigByCategory.flight, |
| 57 | +}; |
| 58 | + |
| 59 | +export const settingComments = { |
| 60 | + clippingDistance: "orthogonal mode", |
| 61 | + moveValue: "orthogonal mode", |
| 62 | + quality: "0 (high), 1 (medium), 2 (low)", |
| 63 | + clippingDistanceArbitrary: "flight/oblique mode", |
| 64 | + moveValue3d: "flight/oblique mode", |
| 65 | +}; |
| 66 | + |
| 67 | +const errorIcon = ( |
| 68 | + <Tooltip title="The recommended user settings JSON has errors."> |
| 69 | + <Icon type="exclamation-circle" style={{ color: "#f5222d", marginLeft: 4 }} /> |
| 70 | + </Tooltip> |
| 71 | +); |
| 72 | + |
| 73 | +const columns = [ |
| 74 | + { |
| 75 | + title: "Display Name", |
| 76 | + dataIndex: "name", |
| 77 | + }, |
| 78 | + { |
| 79 | + title: "Key", |
| 80 | + dataIndex: "key", |
| 81 | + }, |
| 82 | + { |
| 83 | + title: "Default Value", |
| 84 | + dataIndex: "value", |
| 85 | + }, |
| 86 | + { |
| 87 | + title: "Comment", |
| 88 | + dataIndex: "comment", |
| 89 | + }, |
| 90 | +]; |
| 91 | + |
| 92 | +const removeSettings = (form, settingsKey: string) => { |
| 93 | + const settingsString = form.getFieldValue("recommendedConfiguration"); |
| 94 | + try { |
| 95 | + const settingsObject = JSON.parse(settingsString); |
| 96 | + const newSettings = _.omit( |
| 97 | + settingsObject, |
| 98 | + Object.keys(recommendedConfigByCategory[settingsKey]), |
| 99 | + ); |
| 100 | + form.setFieldsValue({ recommendedConfiguration: jsonStringify(newSettings) }); |
| 101 | + } catch (e) { |
| 102 | + console.error(e); |
| 103 | + } |
| 104 | +}; |
| 105 | + |
| 106 | +export default function RecommendedConfigurationView({ |
| 107 | + form, |
| 108 | + enabled, |
| 109 | + onChangeEnabled, |
| 110 | +}: { |
| 111 | + form: Object, |
| 112 | + enabled: boolean, |
| 113 | + onChangeEnabled: boolean => void, |
| 114 | +}) { |
| 115 | + return ( |
| 116 | + <Collapse |
| 117 | + onChange={openedPanels => onChangeEnabled(openedPanels.length === 1)} |
| 118 | + activeKey={enabled ? "config" : null} |
| 119 | + > |
| 120 | + <Panel |
| 121 | + key="config" |
| 122 | + header={ |
| 123 | + <React.Fragment> |
| 124 | + <Checkbox checked={enabled} style={{ marginRight: 10 }} /> Add Recommended User Settings |
| 125 | + {enabled && form.getFieldError("recommendedConfiguration") && errorIcon} |
| 126 | + </React.Fragment> |
| 127 | + } |
| 128 | + showArrow={false} |
| 129 | + > |
| 130 | + <Row gutter={32}> |
| 131 | + <Col span={12}> |
| 132 | + <FormItem> |
| 133 | + The recommended configuration will be displayed to users when starting to trace a task |
| 134 | + with this task type. The user is able to accept or decline this recommendation. |
| 135 | + <br /> |
| 136 | + <br /> |
| 137 | + {form.getFieldDecorator("recommendedConfiguration", { |
| 138 | + rules: [ |
| 139 | + { |
| 140 | + validator: validateUserSettingsJSON, |
| 141 | + }, |
| 142 | + ], |
| 143 | + })( |
| 144 | + <Input.TextArea |
| 145 | + spellCheck={false} |
| 146 | + autosize={{ minRows: 20 }} |
| 147 | + style={jsonEditStyle} |
| 148 | + />, |
| 149 | + )} |
| 150 | + </FormItem> |
| 151 | + <Button style={{ marginRight: 10 }} onClick={() => removeSettings(form, "orthogonal")}> |
| 152 | + Remove Orthogonal-only Settings |
| 153 | + </Button> |
| 154 | + <Button onClick={() => removeSettings(form, "flight")}> |
| 155 | + Remove Flight/Oblique-only Settings |
| 156 | + </Button> |
| 157 | + </Col> |
| 158 | + <Col span={12}> |
| 159 | + Valid settings and their default values: <br /> |
| 160 | + <br /> |
| 161 | + <Table |
| 162 | + columns={columns} |
| 163 | + dataSource={_.map(DEFAULT_RECOMMENDED_CONFIGURATION, (value, key) => ({ |
| 164 | + name: settings[key], |
| 165 | + key, |
| 166 | + value: value.toString(), |
| 167 | + comment: settingComments[key] || "", |
| 168 | + }))} |
| 169 | + size="small" |
| 170 | + pagination={false} |
| 171 | + /> |
| 172 | + </Col> |
| 173 | + </Row> |
| 174 | + </Panel> |
| 175 | + </Collapse> |
| 176 | + ); |
| 177 | +} |
0 commit comments