From 32c98d4855b6178554c787103dc956d161e152b3 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期五, 19 十二月 2025 19:45:30 +0800
Subject: [PATCH] 增加了异形分析逻辑
---
src/zhangaiwu/AddDikuai.java | 519 ++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 457 insertions(+), 62 deletions(-)
diff --git a/src/zhangaiwu/AddDikuai.java b/src/zhangaiwu/AddDikuai.java
index eff3e45..c7cb4bd 100644
--- a/src/zhangaiwu/AddDikuai.java
+++ b/src/zhangaiwu/AddDikuai.java
@@ -33,6 +33,7 @@
import zhuye.Shouye;
import zhuye.Coordinate;
import zhuye.buttonset;
+import gecaoji.Device;
/**
* 鏂板鍦板潡瀵硅瘽妗� - 澶氭楠よ〃鍗曡璁�
@@ -65,7 +66,10 @@
private JTextField landNumberField;
private JTextField areaNameField;
private JComboBox<String> mowingPatternCombo;
- private JSpinner mowingWidthSpinner;
+ private JTextField mowingWidthField; // 鍓茶崏鏈哄壊鍒�瀹藉害
+ private JTextField overlapDistanceField; // 鐩搁偦琛岄噸鍙犺窛绂�
+ private JTextField mowingSafetyDistanceField; // 鍓茶崏瀹夊叏璺濈
+ private JLabel calculatedMowingWidthLabel; // 璁$畻鍚庣殑鍓茶崏瀹藉害鏄剧ず
private JPanel previewPanel;
private Map<String, JPanel> drawingOptionPanels = new HashMap<>();
@@ -292,10 +296,6 @@
formGroup.add(areaNameField);
formGroup.add(Box.createRigidArea(new Dimension(0, 8)));
formGroup.add(hintLabel);
-
- formGroup.add(Box.createRigidArea(new Dimension(0, 20)));
- JPanel obstacleSection = createObstacleSummarySection();
- formGroup.add(obstacleSection);
stepPanel.add(formGroup);
stepPanel.add(Box.createVerticalGlue());
@@ -772,7 +772,7 @@
return false;
}
if (userTriggered && "handheld".equalsIgnoreCase(type) && !hasConfiguredHandheldMarker()) {
- JOptionPane.showMessageDialog(this, "璇峰厛娣诲姞渚挎惡鎵撶偣鍣ㄧ紪鍙�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ JOptionPane.showMessageDialog(this, "璇峰厛鍘荤郴缁熻缃坊鍔犱究鎼烘墦鐐瑰櫒缂栧彿", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
return false;
}
@@ -902,7 +902,7 @@
settingsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
// 鍓茶崏妯″紡閫夋嫨
- JPanel patternPanel = createFormGroup("鍓茶崏妯″紡", "閫夋嫨鍓茶崏璺緞鐨勭敓鎴愭ā寮�");
+ JPanel patternPanel = createFormGroupWithoutHint("鍓茶崏妯″紡");
mowingPatternCombo = new JComboBox<>(new String[]{"骞宠绾�", "铻烘棆寮�"});
mowingPatternCombo.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 16));
mowingPatternCombo.setMaximumSize(new Dimension(Integer.MAX_VALUE, 48));
@@ -934,29 +934,27 @@
patternPanel.add(mowingPatternCombo);
settingsPanel.add(patternPanel);
- settingsPanel.add(Box.createRigidArea(new Dimension(0, 20)));
+ settingsPanel.add(Box.createRigidArea(new Dimension(0, 10)));
- // 鍓茶崏瀹藉害璁剧疆
- JPanel widthPanel = createFormGroup("鍓茶崏瀹藉害", "璁剧疆鍓茶崏鏈哄崟娆″壊鑽夌殑瀹藉害");
+ // 鍓茶崏鏈哄壊鍒�瀹藉害璁剧疆
+ JPanel widthPanel = createFormGroupWithoutHint("鍓茶崏鏈哄壊鍒�瀹藉害");
JPanel widthInputPanel = new JPanel(new BorderLayout());
widthInputPanel.setBackground(WHITE);
widthInputPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 48));
widthInputPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
- SpinnerNumberModel widthModel = new SpinnerNumberModel(40, 20, 60, 1);
- mowingWidthSpinner = new JSpinner(widthModel);
- mowingWidthSpinner.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 16));
- JSpinner.DefaultEditor editor = (JSpinner.DefaultEditor) mowingWidthSpinner.getEditor();
- editor.getTextField().setBorder(BorderFactory.createCompoundBorder(
+ mowingWidthField = new JTextField("0.40");
+ mowingWidthField.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 16));
+ mowingWidthField.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(BORDER_COLOR, 2),
BorderFactory.createEmptyBorder(10, 12, 10, 12)
));
- // 娣诲姞寰皟鍣ㄧ劍鐐规晥鏋�
- mowingWidthSpinner.addFocusListener(new FocusAdapter() {
+ // 娣诲姞鏂囨湰妗嗙劍鐐规晥鏋滃拰鍙樺寲鐩戝惉
+ mowingWidthField.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
- editor.getTextField().setBorder(BorderFactory.createCompoundBorder(
+ mowingWidthField.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(PRIMARY_COLOR, 2),
BorderFactory.createEmptyBorder(10, 12, 10, 12)
));
@@ -964,27 +962,156 @@
@Override
public void focusLost(FocusEvent e) {
- editor.getTextField().setBorder(BorderFactory.createCompoundBorder(
+ mowingWidthField.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createLineBorder(BORDER_COLOR, 2),
+ BorderFactory.createEmptyBorder(10, 12, 10, 12)
+ ));
+ updateCalculatedMowingWidth();
+ }
+ });
+
+ JLabel unitLabel = new JLabel("绫�");
+ unitLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+ unitLabel.setForeground(LIGHT_TEXT);
+ unitLabel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
+
+ widthInputPanel.add(mowingWidthField, BorderLayout.CENTER);
+ widthInputPanel.add(unitLabel, BorderLayout.EAST);
+
+ widthPanel.add(widthInputPanel);
+ settingsPanel.add(widthPanel);
+ settingsPanel.add(Box.createRigidArea(new Dimension(0, 10)));
+
+ // 鐩搁偦琛岄噸鍙犺窛绂昏缃�
+ JPanel overlapPanel = createFormGroupWithoutHint("鐩搁偦琛岄噸鍙犺窛绂�");
+ JPanel overlapInputPanel = new JPanel(new BorderLayout());
+ overlapInputPanel.setBackground(WHITE);
+ overlapInputPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 48));
+ overlapInputPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
+
+ overlapDistanceField = new JTextField("0.06");
+ overlapDistanceField.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 16));
+ overlapDistanceField.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createLineBorder(BORDER_COLOR, 2),
+ BorderFactory.createEmptyBorder(10, 12, 10, 12)
+ ));
+
+ // 娣诲姞鏂囨湰妗嗙劍鐐规晥鏋滃拰鍙樺寲鐩戝惉
+ overlapDistanceField.addFocusListener(new FocusAdapter() {
+ @Override
+ public void focusGained(FocusEvent e) {
+ overlapDistanceField.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createLineBorder(PRIMARY_COLOR, 2),
+ BorderFactory.createEmptyBorder(10, 12, 10, 12)
+ ));
+ }
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ overlapDistanceField.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createLineBorder(BORDER_COLOR, 2),
+ BorderFactory.createEmptyBorder(10, 12, 10, 12)
+ ));
+ updateCalculatedMowingWidth();
+ }
+ });
+
+ JLabel overlapUnitLabel = new JLabel("绫�");
+ overlapUnitLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+ overlapUnitLabel.setForeground(LIGHT_TEXT);
+ overlapUnitLabel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
+
+ overlapInputPanel.add(overlapDistanceField, BorderLayout.CENTER);
+ overlapInputPanel.add(overlapUnitLabel, BorderLayout.EAST);
+
+ overlapPanel.add(overlapInputPanel);
+ settingsPanel.add(overlapPanel);
+ settingsPanel.add(Box.createRigidArea(new Dimension(0, 10)));
+
+ // 鍓茶崏瀹藉害鏄剧ず锛堣嚜鍔ㄨ绠楋紝涓嶅彲淇敼锛�
+ JPanel calculatedWidthPanel = createFormGroup("鍓茶崏瀹藉害", "鍓茶崏瀹藉害 = 鍓茶崏鏈哄壊鍒�瀹藉害 - 閲嶅彔璺濈锛堣嚜鍔ㄨ绠楋級");
+ JPanel calculatedWidthDisplayPanel = new JPanel(new BorderLayout());
+ calculatedWidthDisplayPanel.setBackground(LIGHT_GRAY);
+ calculatedWidthDisplayPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 48));
+ calculatedWidthDisplayPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
+ calculatedWidthDisplayPanel.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createLineBorder(BORDER_COLOR, 2),
+ BorderFactory.createEmptyBorder(10, 12, 10, 12)
+ ));
+
+ calculatedMowingWidthLabel = new JLabel("0.00 绫�");
+ calculatedMowingWidthLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 16));
+ calculatedMowingWidthLabel.setForeground(TEXT_COLOR);
+ calculatedWidthDisplayPanel.add(calculatedMowingWidthLabel, BorderLayout.CENTER);
+
+ calculatedWidthPanel.add(calculatedWidthDisplayPanel);
+ settingsPanel.add(calculatedWidthPanel);
+ settingsPanel.add(Box.createRigidArea(new Dimension(0, 10)));
+
+ // 鍓茶崏瀹夊叏璺濈
+ JPanel safetyDistancePanel = createFormGroupWithoutHint("鍓茶崏瀹夊叏璺濈");
+ JPanel safetyDistanceInputPanel = new JPanel(new BorderLayout());
+ safetyDistanceInputPanel.setBackground(WHITE);
+ safetyDistanceInputPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 48));
+ safetyDistanceInputPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
+
+ // 鑾峰彇榛樿鍊�
+ String defaultSafetyDistance = "0.5"; // 榛樿鍊�
+ try {
+ Device device = Device.getGecaoji();
+ if (device != null) {
+ String safetyDistance = device.getMowingSafetyDistance();
+ if (safetyDistance != null && !safetyDistance.trim().isEmpty() && !"-1".equals(safetyDistance.trim())) {
+ defaultSafetyDistance = safetyDistance.trim();
+ }
+ }
+ } catch (Exception e) {
+ // 濡傛灉鑾峰彇澶辫触锛屼娇鐢ㄩ粯璁ゅ��
+ }
+
+ mowingSafetyDistanceField = new JTextField(defaultSafetyDistance);
+ mowingSafetyDistanceField.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 16));
+ mowingSafetyDistanceField.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createLineBorder(BORDER_COLOR, 2),
+ BorderFactory.createEmptyBorder(10, 12, 10, 12)
+ ));
+
+ // 娣诲姞鏂囨湰妗嗙劍鐐规晥鏋�
+ mowingSafetyDistanceField.addFocusListener(new FocusAdapter() {
+ @Override
+ public void focusGained(FocusEvent e) {
+ mowingSafetyDistanceField.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createLineBorder(PRIMARY_COLOR, 2),
+ BorderFactory.createEmptyBorder(10, 12, 10, 12)
+ ));
+ }
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ mowingSafetyDistanceField.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(BORDER_COLOR, 2),
BorderFactory.createEmptyBorder(10, 12, 10, 12)
));
}
});
- JLabel unitLabel = new JLabel("鍘樼背");
- unitLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
- unitLabel.setForeground(LIGHT_TEXT);
- unitLabel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
+ JLabel safetyDistanceUnitLabel = new JLabel("绫�");
+ safetyDistanceUnitLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+ safetyDistanceUnitLabel.setForeground(LIGHT_TEXT);
+ safetyDistanceUnitLabel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
- widthInputPanel.add(mowingWidthSpinner, BorderLayout.CENTER);
- widthInputPanel.add(unitLabel, BorderLayout.EAST);
+ safetyDistanceInputPanel.add(mowingSafetyDistanceField, BorderLayout.CENTER);
+ safetyDistanceInputPanel.add(safetyDistanceUnitLabel, BorderLayout.EAST);
- widthPanel.add(widthInputPanel);
- settingsPanel.add(widthPanel);
+ safetyDistancePanel.add(safetyDistanceInputPanel);
+ settingsPanel.add(safetyDistancePanel);
settingsPanel.add(Box.createRigidArea(new Dimension(0, 25)));
stepPanel.add(settingsPanel);
+ // 鍒濆鍖栬绠楀悗鐨勫壊鑽夊搴�
+ updateCalculatedMowingWidth();
+
JButton generatePathButton = createPrimaryButton("鐢熸垚鍓茶崏璺緞", 16);
generatePathButton.setAlignmentX(Component.LEFT_ALIGNMENT);
generatePathButton.setMaximumSize(new Dimension(Integer.MAX_VALUE, 55));
@@ -1020,6 +1147,41 @@
return stepPanel;
}
+ /**
+ * 鏇存柊璁$畻鍚庣殑鍓茶崏瀹藉害鏄剧ず
+ */
+ private void updateCalculatedMowingWidth() {
+ if (calculatedMowingWidthLabel == null || mowingWidthField == null || overlapDistanceField == null) {
+ return;
+ }
+
+ try {
+ String widthText = mowingWidthField.getText().trim();
+ String overlapText = overlapDistanceField.getText().trim();
+
+ if (widthText.isEmpty() || overlapText.isEmpty()) {
+ calculatedMowingWidthLabel.setText("0.00 绫�");
+ return;
+ }
+
+ double bladeWidthMeters = Double.parseDouble(widthText);
+ double overlapMeters = Double.parseDouble(overlapText);
+ double calculatedWidthMeters = bladeWidthMeters - overlapMeters;
+
+ if (calculatedWidthMeters <= 0) {
+ calculatedMowingWidthLabel.setText("鏃犳晥锛堝壊鍒�瀹藉害闇�澶т簬閲嶅彔璺濈锛�");
+ calculatedMowingWidthLabel.setForeground(ERROR_COLOR);
+ } else {
+ calculatedMowingWidthLabel.setText(String.format(Locale.US, "%.2f 绫�", calculatedWidthMeters));
+ calculatedMowingWidthLabel.setForeground(TEXT_COLOR);
+ }
+ } catch (NumberFormatException e) {
+ calculatedMowingWidthLabel.setText("0.00 绫�");
+ } catch (Exception e) {
+ calculatedMowingWidthLabel.setText("0.00 绫�");
+ }
+ }
+
private JPanel createInstructionPanel(String text) {
JPanel instructionPanel = new JPanel(new BorderLayout());
instructionPanel.setBackground(PRIMARY_LIGHT);
@@ -1070,6 +1232,23 @@
return formGroup;
}
+
+ private JPanel createFormGroupWithoutHint(String label) {
+ JPanel formGroup = new JPanel();
+ formGroup.setLayout(new BoxLayout(formGroup, BoxLayout.Y_AXIS));
+ formGroup.setBackground(WHITE);
+ formGroup.setAlignmentX(Component.LEFT_ALIGNMENT);
+
+ JLabel nameLabel = new JLabel(label);
+ nameLabel.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 16));
+ nameLabel.setForeground(TEXT_COLOR);
+ nameLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
+
+ formGroup.add(nameLabel);
+ formGroup.add(Box.createRigidArea(new Dimension(0, 8)));
+
+ return formGroup;
+ }
private void generateMowingPath() {
if (!dikuaiData.containsKey("boundaryDrawn")) {
@@ -1108,25 +1287,79 @@
String patternDisplay = (String) mowingPatternCombo.getSelectedItem();
dikuaiData.put("mowingPattern", patternDisplay);
- Object widthObj = mowingWidthSpinner.getValue();
- if (!(widthObj instanceof Number)) {
- JOptionPane.showMessageDialog(this, "鍓茶崏瀹藉害杈撳叆鏃犳晥", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ String widthText = mowingWidthField.getText().trim();
+ if (widthText.isEmpty()) {
+ JOptionPane.showMessageDialog(this, "鍓茶崏鏈哄壊鍒�瀹藉害涓嶈兘涓虹┖", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
dikuaiData.remove("plannedPath");
- showPathGenerationMessage("鍓茶崏瀹藉害杈撳叆鏃犳晥锛岃閲嶆柊杈撳叆銆�", false);
+ showPathGenerationMessage("鍓茶崏鏈哄壊鍒�瀹藉害涓嶈兘涓虹┖锛岃閲嶆柊杈撳叆銆�", false);
setPathAvailability(false);
return;
}
- double widthCm = ((Number) widthObj).doubleValue();
- if (widthCm <= 0) {
- JOptionPane.showMessageDialog(this, "鍓茶崏瀹藉害蹇呴』澶т簬0", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ double bladeWidthMeters;
+ try {
+ bladeWidthMeters = Double.parseDouble(widthText);
+ } catch (NumberFormatException e) {
+ JOptionPane.showMessageDialog(this, "鍓茶崏鏈哄壊鍒�瀹藉害杈撳叆鏃犳晥", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
dikuaiData.remove("plannedPath");
- showPathGenerationMessage("鍓茶崏瀹藉害蹇呴』澶т簬0锛岃閲嶆柊璁剧疆銆�", false);
+ showPathGenerationMessage("鍓茶崏鏈哄壊鍒�瀹藉害杈撳叆鏃犳晥锛岃閲嶆柊杈撳叆銆�", false);
setPathAvailability(false);
return;
}
- dikuaiData.put("mowingWidth", widthObj.toString());
+ if (bladeWidthMeters <= 0) {
+ JOptionPane.showMessageDialog(this, "鍓茶崏鏈哄壊鍒�瀹藉害蹇呴』澶т簬0", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ dikuaiData.remove("plannedPath");
+ showPathGenerationMessage("鍓茶崏鏈哄壊鍒�瀹藉害蹇呴』澶т簬0锛岃閲嶆柊璁剧疆銆�", false);
+ setPathAvailability(false);
+ return;
+ }
+ // 淇濆瓨鍓茶崏鏈哄壊鍒�瀹藉害锛堢背锛�
+ dikuaiData.put("mowingBladeWidth", String.format(Locale.US, "%.2f", bladeWidthMeters));
+
+ // 鑾峰彇閲嶅彔璺濈
+ String overlapText = overlapDistanceField.getText().trim();
+ if (overlapText.isEmpty()) {
+ JOptionPane.showMessageDialog(this, "鐩搁偦琛岄噸鍙犺窛绂讳笉鑳戒负绌�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ dikuaiData.remove("plannedPath");
+ showPathGenerationMessage("鐩搁偦琛岄噸鍙犺窛绂讳笉鑳戒负绌猴紝璇烽噸鏂拌緭鍏ャ��", false);
+ setPathAvailability(false);
+ return;
+ }
+ double overlapMeters;
+ try {
+ overlapMeters = Double.parseDouble(overlapText);
+ } catch (NumberFormatException e) {
+ JOptionPane.showMessageDialog(this, "鐩搁偦琛岄噸鍙犺窛绂昏緭鍏ユ棤鏁�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ dikuaiData.remove("plannedPath");
+ showPathGenerationMessage("鐩搁偦琛岄噸鍙犺窛绂昏緭鍏ユ棤鏁堬紝璇烽噸鏂拌緭鍏ャ��", false);
+ setPathAvailability(false);
+ return;
+ }
+ if (overlapMeters < 0) {
+ JOptionPane.showMessageDialog(this, "鐩搁偦琛岄噸鍙犺窛绂讳笉鑳戒负璐熸暟", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ dikuaiData.remove("plannedPath");
+ showPathGenerationMessage("鐩搁偦琛岄噸鍙犺窛绂讳笉鑳戒负璐熸暟锛岃閲嶆柊璁剧疆銆�", false);
+ setPathAvailability(false);
+ return;
+ }
+
+ // 淇濆瓨閲嶅彔璺濈鍒板湴鍧楁暟鎹�
+ dikuaiData.put("mowingOverlapDistance", String.format(Locale.US, "%.2f", overlapMeters));
+
+ // 璁$畻瀹為檯浣跨敤鐨勫壊鑽夊搴︼紙鍓插垁瀹藉害 - 閲嶅彔璺濈锛�
+ double calculatedWidthMeters = bladeWidthMeters - overlapMeters;
+ if (calculatedWidthMeters <= 0) {
+ JOptionPane.showMessageDialog(this, "璁$畻鍚庣殑鍓茶崏瀹藉害蹇呴』澶т簬0锛堝壊鍒�瀹藉害蹇呴』澶т簬閲嶅彔璺濈锛�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ dikuaiData.remove("plannedPath");
+ showPathGenerationMessage("璁$畻鍚庣殑鍓茶崏瀹藉害蹇呴』澶т簬0锛岃璋冩暣鍓插垁瀹藉害鎴栭噸鍙犺窛绂汇��", false);
+ setPathAvailability(false);
+ return;
+ }
- String widthMeters = String.format(Locale.US, "%.2f", widthCm / 100.0);
+ // 淇濆瓨鍓茶崏瀹藉害锛堣绠楀悗鐨勫�硷紝杞崲涓哄帢绫冲瓨鍌紝淇濇寔涓庡師鏈夋暟鎹牸寮忓吋瀹癸級
+ double calculatedWidthCm = calculatedWidthMeters * 100.0;
+ dikuaiData.put("mowingWidth", String.format(Locale.US, "%.0f", calculatedWidthCm));
+
+ String widthMeters = String.format(Locale.US, "%.2f", calculatedWidthMeters);
String plannerMode = resolvePlannerMode(patternDisplay);
try {
@@ -1249,13 +1482,51 @@
}
}
- if (mowingWidthSpinner != null) {
- Object widthValue = mowingWidthSpinner.getValue();
- if (widthValue instanceof Number) {
- int widthInt = ((Number) widthValue).intValue();
- dikuaiData.put("mowingWidth", Integer.toString(widthInt));
- } else if (widthValue != null) {
- dikuaiData.put("mowingWidth", widthValue.toString());
+ // 淇濆瓨鍓茶崏鏈哄壊鍒�瀹藉害
+ if (mowingWidthField != null) {
+ String bladeWidthText = mowingWidthField.getText().trim();
+ if (!bladeWidthText.isEmpty()) {
+ try {
+ double bladeWidthMeters = Double.parseDouble(bladeWidthText);
+ dikuaiData.put("mowingBladeWidth", String.format(Locale.US, "%.2f", bladeWidthMeters));
+ } catch (NumberFormatException e) {
+ // 濡傛灉瑙f瀽澶辫触锛岀洿鎺ヤ繚瀛樻枃鏈�
+ dikuaiData.put("mowingBladeWidth", bladeWidthText);
+ }
+ }
+ }
+
+ // 淇濆瓨鐩搁偦琛岄噸鍙犺窛绂�
+ if (overlapDistanceField != null) {
+ String overlapText = overlapDistanceField.getText().trim();
+ if (!overlapText.isEmpty()) {
+ try {
+ double overlapMeters = Double.parseDouble(overlapText);
+ dikuaiData.put("mowingOverlapDistance", String.format(Locale.US, "%.2f", overlapMeters));
+ } catch (NumberFormatException e) {
+ // 濡傛灉瑙f瀽澶辫触锛岀洿鎺ヤ繚瀛樻枃鏈�
+ dikuaiData.put("mowingOverlapDistance", overlapText);
+ }
+ }
+ }
+
+ // 璁$畻骞朵繚瀛樺壊鑽夊搴︼紙鍓插垁瀹藉害 - 閲嶅彔璺濈锛�
+ if (mowingWidthField != null && overlapDistanceField != null) {
+ try {
+ String bladeWidthText = mowingWidthField.getText().trim();
+ String overlapText = overlapDistanceField.getText().trim();
+ if (!bladeWidthText.isEmpty() && !overlapText.isEmpty()) {
+ double bladeWidthMeters = Double.parseDouble(bladeWidthText);
+ double overlapMeters = Double.parseDouble(overlapText);
+ double calculatedWidthMeters = bladeWidthMeters - overlapMeters;
+ if (calculatedWidthMeters > 0) {
+ // 杞崲涓哄帢绫冲瓨鍌紝淇濇寔涓庡師鏈夋暟鎹牸寮忓吋瀹�
+ int widthCm = (int) Math.round(calculatedWidthMeters * 100.0);
+ dikuaiData.put("mowingWidth", Integer.toString(widthCm));
+ }
+ }
+ } catch (NumberFormatException e) {
+ // 濡傛灉璁$畻澶辫触锛屼笉淇濆瓨鍓茶崏瀹藉害
}
}
}
@@ -1658,10 +1929,6 @@
private void showStep(int step) {
currentStep = step;
cardLayout.show(stepsPanel, "step" + step);
-
- if (step == 1) {
- updateObstacleSummary();
- }
// 鏇存柊鎸夐挳鐘舵��
updateButtonState(step);
@@ -1732,7 +1999,53 @@
case 3:
dikuaiData.put("mowingPattern", (String) mowingPatternCombo.getSelectedItem());
- dikuaiData.put("mowingWidth", mowingWidthSpinner.getValue().toString());
+
+ // 淇濆瓨鍓茶崏鏈哄壊鍒�瀹藉害
+ if (mowingWidthField != null) {
+ String bladeWidthText = mowingWidthField.getText().trim();
+ if (!bladeWidthText.isEmpty()) {
+ try {
+ double bladeWidthMeters = Double.parseDouble(bladeWidthText);
+ dikuaiData.put("mowingBladeWidth", String.format(Locale.US, "%.2f", bladeWidthMeters));
+ } catch (NumberFormatException e) {
+ dikuaiData.put("mowingBladeWidth", bladeWidthText);
+ }
+ }
+ }
+
+ // 淇濆瓨鐩搁偦琛岄噸鍙犺窛绂�
+ if (overlapDistanceField != null) {
+ String overlapText = overlapDistanceField.getText().trim();
+ if (!overlapText.isEmpty()) {
+ try {
+ double overlapMeters = Double.parseDouble(overlapText);
+ dikuaiData.put("mowingOverlapDistance", String.format(Locale.US, "%.2f", overlapMeters));
+ } catch (NumberFormatException e) {
+ dikuaiData.put("mowingOverlapDistance", overlapText);
+ }
+ }
+ }
+
+ // 璁$畻骞朵繚瀛樺壊鑽夊搴︼紙鍓插垁瀹藉害 - 閲嶅彔璺濈锛�
+ if (mowingWidthField != null && overlapDistanceField != null) {
+ try {
+ String bladeWidthText = mowingWidthField.getText().trim();
+ String overlapText = overlapDistanceField.getText().trim();
+ if (!bladeWidthText.isEmpty() && !overlapText.isEmpty()) {
+ double bladeWidthMeters = Double.parseDouble(bladeWidthText);
+ double overlapMeters = Double.parseDouble(overlapText);
+ double calculatedWidthMeters = bladeWidthMeters - overlapMeters;
+ if (calculatedWidthMeters > 0) {
+ // 杞崲涓哄帢绫冲瓨鍌紝淇濇寔涓庡師鏈夋暟鎹牸寮忓吋瀹�
+ int widthCm = (int) Math.round(calculatedWidthMeters * 100.0);
+ dikuaiData.put("mowingWidth", Integer.toString(widthCm));
+ }
+ }
+ } catch (NumberFormatException e) {
+ // 濡傛灉璁$畻澶辫触锛屼笉淇濆瓨鍓茶崏瀹藉害
+ }
+ }
+
if (!hasGeneratedPath()) {
JOptionPane.showMessageDialog(this, "璇峰厛鐢熸垚鍓茶崏璺緞", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
return false;
@@ -2013,21 +2326,51 @@
}
}
- if (mowingWidthSpinner != null) {
- String width = data.get("mowingWidth");
- if (isMeaningfulValue(width)) {
+ // 鎭㈠鍓茶崏鏈哄壊鍒�瀹藉害锛堜紭鍏堜粠mowingBladeWidth鑾峰彇锛�
+ if (mowingWidthField != null) {
+ String bladeWidth = data.get("mowingBladeWidth");
+ if (isMeaningfulValue(bladeWidth)) {
try {
- double parsed = Double.parseDouble(width.trim());
- SpinnerNumberModel model = (SpinnerNumberModel) mowingWidthSpinner.getModel();
- int min = ((Number) model.getMinimum()).intValue();
- int max = ((Number) model.getMaximum()).intValue();
- int rounded = (int) Math.round(parsed);
- if (rounded < min) {
- rounded = min;
- } else if (rounded > max) {
- rounded = max;
+ double bladeWidthMeters = Double.parseDouble(bladeWidth.trim());
+ mowingWidthField.setText(String.format(Locale.US, "%.2f", bladeWidthMeters));
+ } catch (NumberFormatException ignored) {
+ // 濡傛灉mowingBladeWidth涓嶅瓨鍦ㄦ垨瑙f瀽澶辫触锛屽皾璇曚粠mowingWidth鎭㈠
+ String width = data.get("mowingWidth");
+ if (isMeaningfulValue(width)) {
+ try {
+ // 濡傛灉瀛樺偍鐨勬槸鍘樼背锛岃浆鎹负绫虫樉绀�
+ double parsed = Double.parseDouble(width.trim());
+ // 鍋囪濡傛灉鍊煎ぇ浜�10锛屽垯鏄帢绫筹紝闇�瑕佽浆鎹负绫筹紱鍚﹀垯宸茬粡鏄背
+ double widthMeters = parsed > 10 ? parsed / 100.0 : parsed;
+ mowingWidthField.setText(String.format(Locale.US, "%.2f", widthMeters));
+ } catch (NumberFormatException ignored2) {
+ // 淇濇寔褰撳墠鍊�
+ }
}
- mowingWidthSpinner.setValue(rounded);
+ }
+ } else {
+ // 濡傛灉mowingBladeWidth涓嶅瓨鍦紝灏濊瘯浠巑owingWidth鎭㈠
+ String width = data.get("mowingWidth");
+ if (isMeaningfulValue(width)) {
+ try {
+ // 濡傛灉瀛樺偍鐨勬槸鍘樼背锛岃浆鎹负绫虫樉绀�
+ double parsed = Double.parseDouble(width.trim());
+ // 鍋囪濡傛灉鍊煎ぇ浜�10锛屽垯鏄帢绫筹紝闇�瑕佽浆鎹负绫筹紱鍚﹀垯宸茬粡鏄背
+ double widthMeters = parsed > 10 ? parsed / 100.0 : parsed;
+ mowingWidthField.setText(String.format(Locale.US, "%.2f", widthMeters));
+ } catch (NumberFormatException ignored) {
+ // 淇濇寔褰撳墠鍊�
+ }
+ }
+ }
+ }
+
+ if (overlapDistanceField != null) {
+ String overlap = data.get("mowingOverlapDistance");
+ if (isMeaningfulValue(overlap)) {
+ try {
+ double overlapMeters = Double.parseDouble(overlap.trim());
+ overlapDistanceField.setText(String.format(Locale.US, "%.2f", overlapMeters));
} catch (NumberFormatException ignored) {
// 淇濇寔褰撳墠鍊�
}
@@ -2136,8 +2479,60 @@
if (dikuaiData.containsKey("mowingPattern")) {
dikuai.setMowingPattern(dikuaiData.get("mowingPattern"));
}
+
+ // 淇濆瓨鍓茶崏鏈哄壊鍒�瀹藉害锛堜紭鍏堜粠dikuaiData鑾峰彇锛屽惁鍒欎粠TextField鑾峰彇锛�
+ if (dikuaiData.containsKey("mowingBladeWidth")) {
+ dikuai.setMowingBladeWidth(dikuaiData.get("mowingBladeWidth"));
+ } else if (mowingWidthField != null) {
+ String bladeWidthText = mowingWidthField.getText().trim();
+ if (!bladeWidthText.isEmpty()) {
+ try {
+ double bladeWidthMeters = Double.parseDouble(bladeWidthText);
+ dikuai.setMowingBladeWidth(String.format(Locale.US, "%.2f", bladeWidthMeters));
+ } catch (NumberFormatException e) {
+ dikuai.setMowingBladeWidth(bladeWidthText);
+ }
+ }
+ }
+
+ // 淇濆瓨鐩搁偦琛岄噸鍙犺窛绂伙紙浼樺厛浠巇ikuaiData鑾峰彇锛屽惁鍒欎粠TextField鑾峰彇锛�
+ if (dikuaiData.containsKey("mowingOverlapDistance")) {
+ dikuai.setMowingOverlapDistance(dikuaiData.get("mowingOverlapDistance"));
+ } else if (overlapDistanceField != null) {
+ String overlapText = overlapDistanceField.getText().trim();
+ if (!overlapText.isEmpty()) {
+ try {
+ double overlapMeters = Double.parseDouble(overlapText);
+ dikuai.setMowingOverlapDistance(String.format(Locale.US, "%.2f", overlapMeters));
+ } catch (NumberFormatException e) {
+ dikuai.setMowingOverlapDistance(overlapText);
+ }
+ }
+ }
+
+ // 淇濆瓨鍓茶崏瀹藉害锛堣绠楀悗鐨勫�硷紝浼樺厛浠巇ikuaiData鑾峰彇锛�
if (dikuaiData.containsKey("mowingWidth")) {
dikuai.setMowingWidth(dikuaiData.get("mowingWidth"));
+ } else {
+ // 濡傛灉娌℃湁鍦╠ikuaiData涓紝鍒欎粠TextField璁$畻
+ if (mowingWidthField != null && overlapDistanceField != null) {
+ try {
+ String bladeWidthText = mowingWidthField.getText().trim();
+ String overlapText = overlapDistanceField.getText().trim();
+ if (!bladeWidthText.isEmpty() && !overlapText.isEmpty()) {
+ double bladeWidthMeters = Double.parseDouble(bladeWidthText);
+ double overlapMeters = Double.parseDouble(overlapText);
+ double calculatedWidthMeters = bladeWidthMeters - overlapMeters;
+ if (calculatedWidthMeters > 0) {
+ // 杞崲涓哄帢绫冲瓨鍌紝淇濇寔涓庡師鏈夋暟鎹牸寮忓吋瀹�
+ int widthCm = (int) Math.round(calculatedWidthMeters * 100.0);
+ dikuai.setMowingWidth(Integer.toString(widthCm));
+ }
+ }
+ } catch (NumberFormatException e) {
+ // 濡傛灉璁$畻澶辫触锛屼繚鎸佸師鏈夊�兼垨浣跨敤榛樿鍊�
+ }
+ }
}
String plannedPath = dikuaiData.get("plannedPath");
--
Gitblit v1.10.0