From 13d032241e1a2938a8be4f64c9171e1240e9ea1e Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期一, 22 十二月 2025 18:50:42 +0800
Subject: [PATCH] 新增了边界管理页面和首页边界虚线功能
---
src/zhangaiwu/AddDikuai.java | 588 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 529 insertions(+), 59 deletions(-)
diff --git a/src/zhangaiwu/AddDikuai.java b/src/zhangaiwu/AddDikuai.java
index 02ac96d..8f53100 100644
--- a/src/zhangaiwu/AddDikuai.java
+++ b/src/zhangaiwu/AddDikuai.java
@@ -27,12 +27,13 @@
import dikuai.Dikuaiguanli;
import bianjie.bianjieguihua2;
import lujing.Lunjingguihua;
+import publicway.buttonset;
import set.Setsys;
import ui.UIConfig;
import zhuye.MowerLocationData;
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<>();
@@ -99,6 +103,7 @@
final boolean success;
final String errorMessage;
final String originalBoundary;
+ final String originalBoundaryXY;
final String optimizedBoundary;
final String areaSqMeters;
final String baseStationCoordinates;
@@ -107,6 +112,7 @@
private BoundarySnapshotResult(boolean success,
String errorMessage,
String originalBoundary,
+ String originalBoundaryXY,
String optimizedBoundary,
String areaSqMeters,
String baseStationCoordinates,
@@ -114,18 +120,19 @@
this.success = success;
this.errorMessage = errorMessage;
this.originalBoundary = originalBoundary;
+ this.originalBoundaryXY = originalBoundaryXY;
this.optimizedBoundary = optimizedBoundary;
this.areaSqMeters = areaSqMeters;
this.baseStationCoordinates = baseStationCoordinates;
this.messageType = messageType;
}
- static BoundarySnapshotResult success(String original, String optimized, String area, String baseStation) {
- return new BoundarySnapshotResult(true, null, original, optimized, area, baseStation, JOptionPane.INFORMATION_MESSAGE);
+ static BoundarySnapshotResult success(String original, String originalXY, String optimized, String area, String baseStation) {
+ return new BoundarySnapshotResult(true, null, original, originalXY, optimized, area, baseStation, JOptionPane.INFORMATION_MESSAGE);
}
static BoundarySnapshotResult failure(String message, int messageType) {
- return new BoundarySnapshotResult(false, message, null, null, null, null, messageType);
+ return new BoundarySnapshotResult(false, message, null, null, null, null, null, messageType);
}
}
@@ -768,7 +775,7 @@
return false;
}
if (userTriggered && "handheld".equalsIgnoreCase(type) && !hasConfiguredHandheldMarker()) {
- JOptionPane.showMessageDialog(this, "璇峰厛娣诲姞渚挎惡鎵撶偣鍣ㄧ紪鍙�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ JOptionPane.showMessageDialog(this, "璇峰厛鍘荤郴缁熻缃坊鍔犱究鎼烘墦鐐瑰櫒缂栧彿", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
return false;
}
@@ -898,7 +905,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));
@@ -930,29 +937,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)
));
@@ -960,27 +965,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));
@@ -1016,6 +1150,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);
@@ -1066,6 +1235,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")) {
@@ -1104,25 +1290,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 {
@@ -1245,13 +1485,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) {
+ // 濡傛灉璁$畻澶辫触锛屼笉淇濆瓨鍓茶崏瀹藉害
}
}
}
@@ -1400,6 +1678,7 @@
Dikuai dikuai = getOrCreatePendingDikuai();
if (dikuai != null) {
dikuai.setBoundaryOriginalCoordinates(snapshot.originalBoundary);
+ dikuai.setBoundaryOriginalXY(snapshot.originalBoundaryXY);
dikuai.setBoundaryCoordinates(snapshot.optimizedBoundary);
dikuai.setLandArea(snapshot.areaSqMeters);
dikuai.setBaseStationCoordinates(snapshot.baseStationCoordinates);
@@ -1408,11 +1687,13 @@
}
dikuaiData.put("boundaryOriginalCoordinates", snapshot.originalBoundary);
+ dikuaiData.put("boundaryOriginalXY", snapshot.originalBoundaryXY);
dikuaiData.put("boundaryCoordinates", snapshot.optimizedBoundary);
dikuaiData.put("landArea", snapshot.areaSqMeters);
dikuaiData.put("baseStationCoordinates", snapshot.baseStationCoordinates);
if (activeSession != null) {
activeSession.data.put("boundaryOriginalCoordinates", snapshot.originalBoundary);
+ activeSession.data.put("boundaryOriginalXY", snapshot.originalBoundaryXY);
activeSession.data.put("boundaryCoordinates", snapshot.optimizedBoundary);
activeSession.data.put("landArea", snapshot.areaSqMeters);
activeSession.data.put("baseStationCoordinates", snapshot.baseStationCoordinates);
@@ -1468,6 +1749,47 @@
}
return sb.toString();
}
+
+ /**
+ * 鏋勫缓鍘熷杈圭晫XY鍧愭爣瀛楃涓诧紙鐩稿浜庡熀鍑嗙珯鐨刋Y鍧愭爣锛�
+ */
+ private static String buildOriginalBoundaryXYString(List<Coordinate> coordinates, String baseStationCoordinates) {
+ if (coordinates == null || coordinates.isEmpty()) {
+ return "-1";
+ }
+ if (baseStationCoordinates == null || baseStationCoordinates.trim().isEmpty() || "-1".equals(baseStationCoordinates.trim())) {
+ return "-1";
+ }
+
+ try {
+ // 瑙f瀽鍩哄噯绔欏潗鏍�
+ String[] baseParts = baseStationCoordinates.split(",");
+ if (baseParts.length < 4) {
+ return "-1";
+ }
+ double baseLat = publicway.Gpstoxuzuobiao.parseDMToDecimal(baseParts[0], baseParts[1]);
+ double baseLon = publicway.Gpstoxuzuobiao.parseDMToDecimal(baseParts[2], baseParts[3]);
+
+ StringBuilder sb = new StringBuilder();
+ DecimalFormat xyFormat = new DecimalFormat("0.00");
+ for (Coordinate coord : coordinates) {
+ double lat = convertToDecimalDegree(coord.getLatitude(), coord.getLatDirection());
+ double lon = convertToDecimalDegree(coord.getLongitude(), coord.getLonDirection());
+
+ // 杞崲涓篨Y鍧愭爣
+ double[] xy = publicway.Gpstoxuzuobiao.convertLatLonToLocal(lat, lon, baseLat, baseLon);
+
+ if (sb.length() > 0) {
+ sb.append(";");
+ }
+ sb.append(xyFormat.format(xy[0])).append(",").append(xyFormat.format(xy[1]));
+ }
+ return sb.toString();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "-1";
+ }
+ }
private static double convertToDecimalDegree(String dmm, String direction) {
if (dmm == null || dmm.isEmpty()) {
@@ -1590,10 +1912,11 @@
}
String originalBoundary = buildOriginalBoundaryString(uniqueCoordinates);
+ String originalBoundaryXY = buildOriginalBoundaryXYString(uniqueCoordinates, baseStationCoordinates);
DecimalFormat areaFormat = new DecimalFormat("0.00");
String areaString = areaFormat.format(area);
- return BoundarySnapshotResult.success(originalBoundary, optimizedBoundary, areaString, baseStationCoordinates);
+ return BoundarySnapshotResult.success(originalBoundary, originalBoundaryXY, optimizedBoundary, areaString, baseStationCoordinates);
}
private String resolvePlannerMode(String patternDisplay) {
@@ -1724,7 +2047,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;
@@ -2005,21 +2374,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) {
// 淇濇寔褰撳墠鍊�
}
@@ -2056,6 +2455,7 @@
BoundarySnapshotResult snapshot = computeBoundarySnapshot();
if (snapshot.success && activeSession != null) {
activeSession.data.put("boundaryOriginalCoordinates", snapshot.originalBoundary);
+ activeSession.data.put("boundaryOriginalXY", snapshot.originalBoundaryXY);
activeSession.data.put("boundaryCoordinates", snapshot.optimizedBoundary);
activeSession.data.put("landArea", snapshot.areaSqMeters);
activeSession.data.put("baseStationCoordinates", snapshot.baseStationCoordinates);
@@ -2115,6 +2515,9 @@
if (dikuaiData.containsKey("boundaryOriginalCoordinates")) {
dikuai.setBoundaryOriginalCoordinates(dikuaiData.get("boundaryOriginalCoordinates"));
}
+ if (dikuaiData.containsKey("boundaryOriginalXY")) {
+ dikuai.setBoundaryOriginalXY(dikuaiData.get("boundaryOriginalXY"));
+ }
if (dikuaiData.containsKey("boundaryCoordinates")) {
dikuai.setBoundaryCoordinates(dikuaiData.get("boundaryCoordinates"));
}
@@ -2128,14 +2531,81 @@
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");
if (isMeaningfulValue(plannedPath)) {
dikuai.setPlannedPath(plannedPath);
}
+
+ // 淇濆瓨鍓茶崏瀹夊叏璺濈锛堜紭鍏堜粠dikuaiData鑾峰彇锛屽惁鍒欎粠TextField鑾峰彇锛�
+ if (dikuaiData.containsKey("mowingSafetyDistance")) {
+ dikuai.setMowingSafetyDistance(dikuaiData.get("mowingSafetyDistance"));
+ } else if (mowingSafetyDistanceField != null) {
+ String safetyDistanceText = mowingSafetyDistanceField.getText().trim();
+ if (!safetyDistanceText.isEmpty()) {
+ try {
+ double safetyDistanceMeters = Double.parseDouble(safetyDistanceText);
+ dikuai.setMowingSafetyDistance(String.format(Locale.US, "%.2f", safetyDistanceMeters));
+ } catch (NumberFormatException e) {
+ dikuai.setMowingSafetyDistance(safetyDistanceText);
+ }
+ }
+ }
Dikuai.putDikuai(landNumber, dikuai);
Dikuai.saveToProperties();
--
Gitblit v1.10.0