| | |
| | | contentPanel.add(createTextAreaSection(obstacleTitle, obstacleArea)); |
| | | |
| | | // 割草宽度 |
| | | widthField = createInfoTextField(widthValue != null ? widthValue : "", true); |
| | | contentPanel.add(createTextFieldSection("割草宽度 (cm)", widthField)); |
| | | String displayWidth = ""; |
| | | if (widthValue != null && !widthValue.trim().isEmpty() && !"-1".equals(widthValue.trim())) { |
| | | try { |
| | | double val = Double.parseDouble(widthValue.trim()); |
| | | // 简单的启发式转换:如果值大于5,假设是厘米,转换为米 |
| | | if (val > 5) { |
| | | val = val / 100.0; |
| | | } |
| | | displayWidth = String.format(Locale.US, "%.2f", val); |
| | | } catch (NumberFormatException e) { |
| | | displayWidth = widthValue; |
| | | } |
| | | } |
| | | widthField = createInfoTextField(displayWidth, true); |
| | | contentPanel.add(createTextFieldSection("割草宽度 (m)", widthField)); |
| | | |
| | | // 割草安全距离(只读显示) |
| | | // 优先从Dikuai对象获取,如果Dikuai中没有,再从Device获取 |
| | |
| | | String sanitizedWidth = sanitizeWidthString(widthField.getText()); |
| | | if (sanitizedWidth != null) { |
| | | try { |
| | | double widthCm = Double.parseDouble(sanitizedWidth); |
| | | widthField.setText(formatWidthForStorage(widthCm)); |
| | | sanitizedWidth = formatWidthForStorage(widthCm); |
| | | double widthMeters = Double.parseDouble(sanitizedWidth); |
| | | widthField.setText(formatWidthForStorage(widthMeters)); |
| | | sanitizedWidth = formatWidthForStorage(widthMeters); |
| | | } catch (NumberFormatException ex) { |
| | | widthField.setText(sanitizedWidth); |
| | | } |
| | |
| | | String rawWidthInput = widthField.getText() != null ? widthField.getText().trim() : ""; |
| | | String widthSanitized = sanitizeWidthString(widthField.getText()); |
| | | if (widthSanitized == null) { |
| | | String message = rawWidthInput.isEmpty() ? "请先设置割草宽度(cm)" : "割草宽度格式不正确"; |
| | | String message = rawWidthInput.isEmpty() ? "请先设置割草宽度(m)" : "割草宽度格式不正确"; |
| | | JOptionPane.showMessageDialog(this, message, "提示", JOptionPane.WARNING_MESSAGE); |
| | | return; |
| | | } |
| | | |
| | | double widthCm; |
| | | double widthMeters; |
| | | try { |
| | | widthCm = Double.parseDouble(widthSanitized); |
| | | widthMeters = Double.parseDouble(widthSanitized); |
| | | } catch (NumberFormatException ex) { |
| | | JOptionPane.showMessageDialog(this, "割草宽度格式不正确", "提示", JOptionPane.WARNING_MESSAGE); |
| | | return; |
| | | } |
| | | |
| | | if (widthCm <= 0) { |
| | | if (widthMeters <= 0) { |
| | | JOptionPane.showMessageDialog(this, "割草宽度必须大于0", "提示", JOptionPane.WARNING_MESSAGE); |
| | | return; |
| | | } |
| | | |
| | | String widthNormalized = formatWidthForStorage(widthCm); |
| | | String widthNormalized = formatWidthForStorage(widthMeters); |
| | | widthField.setText(widthNormalized); |
| | | |
| | | String pathNormalized = normalizeCoordinateInput(pathArea.getText()); |
| | |
| | | String widthStr = sanitizeWidthString(widthCmInput); |
| | | if (widthStr == null) { |
| | | if (showMessages) { |
| | | String message = rawWidth.isEmpty() ? "请先设置割草宽度(cm)" : "割草宽度格式不正确"; |
| | | String message = rawWidth.isEmpty() ? "请先设置割草宽度(m)" : "割草宽度格式不正确"; |
| | | JOptionPane.showMessageDialog(parentComponent, message, "提示", JOptionPane.WARNING_MESSAGE); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | double widthCm; |
| | | double widthVal; |
| | | try { |
| | | widthCm = Double.parseDouble(widthStr); |
| | | widthVal = Double.parseDouble(widthStr); |
| | | } catch (NumberFormatException ex) { |
| | | if (showMessages) { |
| | | JOptionPane.showMessageDialog(parentComponent, "割草宽度格式不正确", |
| | |
| | | return null; |
| | | } |
| | | |
| | | if (widthCm <= 0) { |
| | | if (widthVal <= 0) { |
| | | if (showMessages) { |
| | | JOptionPane.showMessageDialog(parentComponent, "割草宽度必须大于0", |
| | | "提示", JOptionPane.WARNING_MESSAGE); |
| | |
| | | return null; |
| | | } |
| | | |
| | | double widthMeters = widthCm / 100.0d; |
| | | double widthMeters = widthVal; |
| | | String plannerWidth = BigDecimal.valueOf(widthMeters) |
| | | .setScale(3, RoundingMode.HALF_UP) |
| | | .stripTrailingZeros() |
| | |
| | | return cleaned.isEmpty() ? null : cleaned; |
| | | } |
| | | |
| | | private String formatWidthForStorage(double widthCm) { |
| | | return BigDecimal.valueOf(widthCm) |
| | | .setScale(2, RoundingMode.HALF_UP) |
| | | .stripTrailingZeros() |
| | | .toPlainString(); |
| | | private String formatWidthForStorage(double widthVal) { |
| | | return String.format(Locale.US, "%.2f", widthVal); |
| | | } |
| | | |
| | | private String formatMowingPatternForDialog(String patternValue) { |