From b272034a1fdbfe32b355fc6c264a4c45df107190 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期二, 23 十二月 2025 14:55:03 +0800
Subject: [PATCH] 优化了新增地块功能
---
src/zhangaiwu/AddDikuai.java | 913 +++++++++++++++++++++++++-------------------------------
1 files changed, 413 insertions(+), 500 deletions(-)
diff --git a/src/zhangaiwu/AddDikuai.java b/src/zhangaiwu/AddDikuai.java
index 8f53100..07d238c 100644
--- a/src/zhangaiwu/AddDikuai.java
+++ b/src/zhangaiwu/AddDikuai.java
@@ -1,7 +1,5 @@
package zhangaiwu;
-
import javax.swing.*;
-
import java.awt.*;
import java.awt.event.*;
import java.io.File;
@@ -9,10 +7,8 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.text.DecimalFormat;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -20,20 +16,20 @@
import java.util.Map;
import java.util.Comparator;
import java.awt.geom.Point2D;
-
import baseStation.BaseStation;
import bianjie.jisuanmianjie;
import dikuai.Dikuai;
import dikuai.Dikuaiguanli;
-import bianjie.bianjieguihua2;
+import dikuai.Gecaokuanjisuan;
+import dikuai.Gecaoanquanjuli;
+import bianjie.Bianjieyouhuatoxy;
import lujing.Lunjingguihua;
-import publicway.buttonset;
import set.Setsys;
import ui.UIConfig;
import zhuye.MowerLocationData;
import zhuye.Shouye;
import zhuye.Coordinate;
-import gecaoji.Device;
+import publicway.buttonset;
/**
* 鏂板鍦板潡瀵硅瘽妗� - 澶氭楠よ〃鍗曡璁�
@@ -66,10 +62,9 @@
private JTextField landNumberField;
private JTextField areaNameField;
private JComboBox<String> mowingPatternCombo;
- private JTextField mowingWidthField; // 鍓茶崏鏈哄壊鍒�瀹藉害
- private JTextField overlapDistanceField; // 鐩搁偦琛岄噸鍙犺窛绂�
- private JTextField mowingSafetyDistanceField; // 鍓茶崏瀹夊叏璺濈
- private JLabel calculatedMowingWidthLabel; // 璁$畻鍚庣殑鍓茶崏瀹藉害鏄剧ず
+ private JTextField bladeWidthField; // 鍓茶崏鏈哄壊鍒�瀹藉害锛坢锛�
+ private JTextField mowingWidthField; // 鍓茶崏瀹藉害锛坢锛屽彲缂栬緫锛�
+ private JTextField safetyDistanceField; // 鍓茶崏瀹夊叏璺濈锛坢锛屽彲缂栬緫锛�
private JPanel previewPanel;
private Map<String, JPanel> drawingOptionPanels = new HashMap<>();
@@ -81,6 +76,8 @@
private JButton previewButton;
private Component previewButtonSpacer;
private JLabel boundaryCountLabel;
+ private JTextArea boundaryXYTextArea; // 鏄剧ず杈圭晫XY鍧愭爣鐨勬枃鏈煙
+ private JScrollPane boundaryXYScrollPane; // 杈圭晫XY鍧愭爣鏂囨湰鍩熺殑婊氬姩闈㈡澘
private JPanel obstacleListContainer;
private JTextArea pathGenerationMessageArea;
private JPanel pathMessageWrapper;
@@ -103,7 +100,6 @@
final boolean success;
final String errorMessage;
final String originalBoundary;
- final String originalBoundaryXY;
final String optimizedBoundary;
final String areaSqMeters;
final String baseStationCoordinates;
@@ -112,7 +108,6 @@
private BoundarySnapshotResult(boolean success,
String errorMessage,
String originalBoundary,
- String originalBoundaryXY,
String optimizedBoundary,
String areaSqMeters,
String baseStationCoordinates,
@@ -120,19 +115,18 @@
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 originalXY, String optimized, String area, String baseStation) {
- return new BoundarySnapshotResult(true, null, original, originalXY, optimized, area, baseStation, JOptionPane.INFORMATION_MESSAGE);
+ 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 failure(String message, int messageType) {
- return new BoundarySnapshotResult(false, message, null, null, null, null, null, messageType);
+ return new BoundarySnapshotResult(false, message, null, null, null, null, messageType);
}
}
@@ -299,6 +293,10 @@
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());
@@ -660,6 +658,34 @@
startEndDrawingBtn.addActionListener(e -> toggleDrawing());
stepPanel.add(startEndDrawingBtn);
+
+ // 杈圭晫XY鍧愭爣鏄剧ず鏂囨湰鍩燂紙3琛岋紝甯︽粴鍔ㄦ潯锛屽湪宸插畬鎴愭寜閽笅鏂癸級
+ boundaryXYTextArea = new JTextArea(3, 0);
+ boundaryXYTextArea.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
+ boundaryXYTextArea.setForeground(TEXT_COLOR);
+ boundaryXYTextArea.setEditable(false);
+ boundaryXYTextArea.setBackground(LIGHT_GRAY);
+ boundaryXYTextArea.setLineWrap(true);
+ boundaryXYTextArea.setWrapStyleWord(true);
+ boundaryXYTextArea.setAlignmentX(Component.LEFT_ALIGNMENT);
+ boundaryXYTextArea.setVisible(false);
+
+ // 鍒涘缓婊氬姩闈㈡澘锛岄粯璁ゆ樉绀�3琛�
+ boundaryXYScrollPane = new JScrollPane(boundaryXYTextArea);
+ boundaryXYScrollPane.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createLineBorder(BORDER_COLOR, 1),
+ BorderFactory.createEmptyBorder(0, 0, 0, 0)
+ ));
+ boundaryXYScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ boundaryXYScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
+ boundaryXYScrollPane.getVerticalScrollBar().setUnitIncrement(16);
+ boundaryXYScrollPane.setAlignmentX(Component.LEFT_ALIGNMENT);
+ boundaryXYScrollPane.setVisible(false);
+ boundaryXYScrollPane.setMaximumSize(new Dimension(Integer.MAX_VALUE, 80));
+
+ stepPanel.add(Box.createRigidArea(new Dimension(0, 15)));
+ stepPanel.add(boundaryXYScrollPane);
+
boundaryCountLabel = new JLabel("宸查噰闆嗗埌杈圭晫鐐�0涓�");
boundaryCountLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
boundaryCountLabel.setForeground(LIGHT_TEXT);
@@ -775,7 +801,7 @@
return false;
}
if (userTriggered && "handheld".equalsIgnoreCase(type) && !hasConfiguredHandheldMarker()) {
- JOptionPane.showMessageDialog(this, "璇峰厛鍘荤郴缁熻缃坊鍔犱究鎼烘墦鐐瑰櫒缂栧彿", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ JOptionPane.showMessageDialog(this, "璇峰厛娣诲姞渚挎惡鎵撶偣鍣ㄧ紪鍙�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
return false;
}
@@ -828,12 +854,18 @@
// 鐢ㄦ埛鍦ㄥ璇濇鍐呬富鍔ㄧ粨鏉燂紙鏈Е鍙戝閮ㄦ祦绋嬶級
isDrawing = false;
Coordinate.setStartSaveGngga(false);
- startEndDrawingBtn.setText("寮�濮嬬粯鍒�");
- startEndDrawingBtn.setBackground(PRIMARY_COLOR);
- updateOtherOptionsState(false);
+ startEndDrawingBtn.setText("宸插畬鎴�");
+ startEndDrawingBtn.setBackground(MEDIUM_GRAY);
+ startEndDrawingBtn.setEnabled(false);
+ updateOtherOptionsState(true);
+
+ // 浼樺寲杈圭晫
+ optimizeBoundaryAndSave();
+
dikuaiData.put("boundaryDrawn", "true");
JOptionPane.showMessageDialog(this, "杈圭晫缁樺埗宸插畬鎴�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
showBoundaryPointSummary();
+ updateBoundaryXYDisplay();
}
}
@@ -884,6 +916,80 @@
hideBoundaryPointSummary();
}
+ /**
+ * 浼樺寲杈圭晫骞朵繚瀛樹紭鍖栧悗鐨勬暟鎹�
+ */
+ private void optimizeBoundaryAndSave() {
+ try {
+ // 鑾峰彇鍩哄噯绔欏潗鏍�
+ BaseStation baseStation = new BaseStation();
+ baseStation.load();
+ String baseStationCoordinates = normalizeCoordinateValue(baseStation.getInstallationCoordinates());
+ if (!isMeaningfulValue(baseStationCoordinates)) {
+ System.err.println("鏈幏鍙栧埌鏈夋晥鐨勫熀鍑嗙珯鍧愭爣锛屾棤娉曚紭鍖栬竟鐣�");
+ return;
+ }
+
+ // 鑾峰彇鍘熷鍧愭爣鍒楄〃
+ List<Coordinate> uniqueCoordinates;
+ synchronized (Coordinate.coordinates) {
+ uniqueCoordinates = sanitizeCoordinateList(Coordinate.coordinates);
+ }
+
+ if (uniqueCoordinates.size() < 3) {
+ System.err.println("閲囬泦鐨勮竟鐣岀偣涓嶈冻锛屾棤娉曚紭鍖栬竟鐣�");
+ return;
+ }
+
+ // 鏋勫缓杈圭晫瀛楃涓诧紝鏍煎紡涓� "(lat1,lon1,alt1;lat2,lon2,alt2;...)"
+ String boundaryStr = buildBoundaryStringForOptimization(uniqueCoordinates);
+
+ // 璋冪敤浼樺寲鏂规硶
+ String optimizedXYStr = Bianjieyouhuatoxy.optimizeBoundary(baseStationCoordinates, boundaryStr);
+
+ // 淇濆瓨浼樺寲鍚庣殑XY鍧愭爣瀛楃涓�
+ if (optimizedXYStr != null && !optimizedXYStr.isEmpty() && !optimizedXYStr.startsWith("ERROR")) {
+ dikuaiData.put("optimizedBoundaryXY", optimizedXYStr);
+ if (activeSession != null) {
+ activeSession.data.put("optimizedBoundaryXY", optimizedXYStr);
+ }
+ } else {
+ System.err.println("杈圭晫浼樺寲澶辫触: " + optimizedXYStr);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.err.println("浼樺寲杈圭晫鏃跺彂鐢熼敊璇�: " + e.getMessage());
+ }
+ }
+
+ /**
+ * 鏋勫缓鐢ㄤ簬浼樺寲鐨勮竟鐣屽瓧绗︿覆锛屾牸寮忎负 "(lat1,lon1,alt1;lat2,lon2,alt2;...)"
+ * 鍏朵腑lat鍜宭on鏄害鍒嗘牸寮忥紙DMM鏍煎紡锛夛紝渚嬪 "3949.89151752"
+ */
+ private static String buildBoundaryStringForOptimization(List<Coordinate> coordinates) {
+ if (coordinates == null || coordinates.isEmpty()) {
+ return "()";
+ }
+ StringBuilder sb = new StringBuilder("(");
+ DecimalFormat elevationFormat = new DecimalFormat("0.00");
+ for (int i = 0; i < coordinates.size(); i++) {
+ Coordinate coord = coordinates.get(i);
+ // Coordinate绫讳腑鐨刧etLatitude()鍜実etLongitude()宸茬粡杩斿洖搴﹀垎鏍煎紡锛圖MM鏍煎紡锛�
+ String latDMM = coord.getLatitude();
+ String lonDMM = coord.getLongitude();
+ double elevation = coord.getElevation();
+
+ if (i > 0) {
+ sb.append(";");
+ }
+ sb.append(latDMM).append(",")
+ .append(lonDMM).append(",")
+ .append(elevationFormat.format(elevation));
+ }
+ sb.append(")");
+ return sb.toString();
+ }
+
private JPanel createStep3Panel() {
JPanel stepPanel = new JPanel();
stepPanel.setLayout(new BoxLayout(stepPanel, BoxLayout.Y_AXIS));
@@ -905,7 +1011,7 @@
settingsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
// 鍓茶崏妯″紡閫夋嫨
- JPanel patternPanel = createFormGroupWithoutHint("鍓茶崏妯″紡");
+ JPanel patternPanel = createFormGroup("鍓茶崏妯″紡", "");
mowingPatternCombo = new JComboBox<>(new String[]{"骞宠绾�", "铻烘棆寮�"});
mowingPatternCombo.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 16));
mowingPatternCombo.setMaximumSize(new Dimension(Integer.MAX_VALUE, 48));
@@ -937,23 +1043,65 @@
patternPanel.add(mowingPatternCombo);
settingsPanel.add(patternPanel);
- settingsPanel.add(Box.createRigidArea(new Dimension(0, 10)));
+ settingsPanel.add(Box.createRigidArea(new Dimension(0, 20)));
// 鍓茶崏鏈哄壊鍒�瀹藉害璁剧疆
- JPanel widthPanel = createFormGroupWithoutHint("鍓茶崏鏈哄壊鍒�瀹藉害");
+ JPanel bladeWidthPanel = createFormGroup("鍓茶崏鏈哄壊鍒�瀹藉害", "");
+ JPanel bladeWidthInputPanel = new JPanel(new BorderLayout());
+ bladeWidthInputPanel.setBackground(WHITE);
+ bladeWidthInputPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 48));
+ bladeWidthInputPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
+
+ bladeWidthField = new JTextField("0.50");
+ bladeWidthField.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 16));
+ bladeWidthField.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createLineBorder(BORDER_COLOR, 2),
+ BorderFactory.createEmptyBorder(10, 12, 10, 12)
+ ));
+ bladeWidthField.addFocusListener(new FocusAdapter() {
+ @Override
+ public void focusGained(FocusEvent e) {
+ bladeWidthField.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createLineBorder(PRIMARY_COLOR, 2),
+ BorderFactory.createEmptyBorder(10, 12, 10, 12)
+ ));
+ }
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ bladeWidthField.setBorder(BorderFactory.createCompoundBorder(
+ BorderFactory.createLineBorder(BORDER_COLOR, 2),
+ BorderFactory.createEmptyBorder(10, 12, 10, 12)
+ ));
+ updateMowingWidthAndSafetyDistance();
+ }
+ });
+
+ JLabel bladeUnitLabel = new JLabel("m");
+ bladeUnitLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+ bladeUnitLabel.setForeground(LIGHT_TEXT);
+ bladeUnitLabel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
+
+ bladeWidthInputPanel.add(bladeWidthField, BorderLayout.CENTER);
+ bladeWidthInputPanel.add(bladeUnitLabel, BorderLayout.EAST);
+
+ bladeWidthPanel.add(bladeWidthInputPanel);
+ settingsPanel.add(bladeWidthPanel);
+ settingsPanel.add(Box.createRigidArea(new Dimension(0, 20)));
+
+ // 鍓茶崏瀹藉害璁剧疆锛堝彲缂栬緫锛�
+ JPanel widthPanel = createFormGroup("鍓茶崏瀹藉害", "璁$畻鏂规硶锛氬壊鑽夊搴� = 鍓插垁瀹� 脳85%");
JPanel widthInputPanel = new JPanel(new BorderLayout());
widthInputPanel.setBackground(WHITE);
widthInputPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 48));
widthInputPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
- mowingWidthField = new JTextField("0.40");
+ mowingWidthField = new JTextField();
mowingWidthField.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 16));
mowingWidthField.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(BORDER_COLOR, 2),
BorderFactory.createEmptyBorder(10, 12, 10, 12)
));
-
- // 娣诲姞鏂囨湰妗嗙劍鐐规晥鏋滃拰鍙樺寲鐩戝惉
mowingWidthField.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
@@ -969,11 +1117,10 @@
BorderFactory.createLineBorder(BORDER_COLOR, 2),
BorderFactory.createEmptyBorder(10, 12, 10, 12)
));
- updateCalculatedMowingWidth();
}
});
- JLabel unitLabel = new JLabel("绫�");
+ JLabel unitLabel = new JLabel("m");
unitLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
unitLabel.setForeground(LIGHT_TEXT);
unitLabel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
@@ -983,107 +1130,25 @@
widthPanel.add(widthInputPanel);
settingsPanel.add(widthPanel);
- settingsPanel.add(Box.createRigidArea(new Dimension(0, 10)));
+ settingsPanel.add(Box.createRigidArea(new Dimension(0, 20)));
- // 鐩搁偦琛岄噸鍙犺窛绂昏缃�
- 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 safetyDistancePanel = createFormGroup("鍓茶崏瀹夊叏璺濈", "鏍规嵁鍓茶崏鏈哄昂瀵歌嚜鍔ㄨ绠楃殑瀹夊叏璺濈");
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(
+ safetyDistanceField = new JTextField();
+ safetyDistanceField.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 16));
+ safetyDistanceField.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(BORDER_COLOR, 2),
BorderFactory.createEmptyBorder(10, 12, 10, 12)
));
-
- // 娣诲姞鏂囨湰妗嗙劍鐐规晥鏋�
- mowingSafetyDistanceField.addFocusListener(new FocusAdapter() {
+ safetyDistanceField.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
- mowingSafetyDistanceField.setBorder(BorderFactory.createCompoundBorder(
+ safetyDistanceField.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(PRIMARY_COLOR, 2),
BorderFactory.createEmptyBorder(10, 12, 10, 12)
));
@@ -1091,29 +1156,37 @@
@Override
public void focusLost(FocusEvent e) {
- mowingSafetyDistanceField.setBorder(BorderFactory.createCompoundBorder(
+ safetyDistanceField.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLineBorder(BORDER_COLOR, 2),
BorderFactory.createEmptyBorder(10, 12, 10, 12)
));
}
});
- JLabel safetyDistanceUnitLabel = new JLabel("绫�");
- safetyDistanceUnitLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
- safetyDistanceUnitLabel.setForeground(LIGHT_TEXT);
- safetyDistanceUnitLabel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
+ JLabel safetyUnitLabel = new JLabel("m");
+ safetyUnitLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+ safetyUnitLabel.setForeground(LIGHT_TEXT);
+ safetyUnitLabel.setBorder(BorderFactory.createEmptyBorder(0, 15, 0, 0));
- safetyDistanceInputPanel.add(mowingSafetyDistanceField, BorderLayout.CENTER);
- safetyDistanceInputPanel.add(safetyDistanceUnitLabel, BorderLayout.EAST);
+ safetyDistanceInputPanel.add(safetyDistanceField, BorderLayout.CENTER);
+ safetyDistanceInputPanel.add(safetyUnitLabel, BorderLayout.EAST);
safetyDistancePanel.add(safetyDistanceInputPanel);
settingsPanel.add(safetyDistancePanel);
settingsPanel.add(Box.createRigidArea(new Dimension(0, 25)));
- stepPanel.add(settingsPanel);
+ // 鍒濆鍖栬绠楀��
+ updateMowingWidthAndSafetyDistance();
- // 鍒濆鍖栬绠楀悗鐨勫壊鑽夊搴�
- updateCalculatedMowingWidth();
+ // 灏嗚缃潰鏉挎斁鍏ユ粴鍔ㄩ潰鏉�
+ JScrollPane scrollPane = new JScrollPane(settingsPanel);
+ scrollPane.setBorder(null);
+ scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
+ scrollPane.getVerticalScrollBar().setUnitIncrement(16);
+ scrollPane.setAlignmentX(Component.LEFT_ALIGNMENT);
+
+ stepPanel.add(scrollPane);
JButton generatePathButton = createPrimaryButton("鐢熸垚鍓茶崏璺緞", 16);
generatePathButton.setAlignmentX(Component.LEFT_ALIGNMENT);
@@ -1150,41 +1223,6 @@
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);
@@ -1223,36 +1261,67 @@
nameLabel.setForeground(TEXT_COLOR);
nameLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
- JLabel hintLabel = new JLabel(hint);
- hintLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 13));
- hintLabel.setForeground(LIGHT_TEXT);
- hintLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
-
formGroup.add(nameLabel);
- formGroup.add(Box.createRigidArea(new Dimension(0, 6)));
- formGroup.add(hintLabel);
- formGroup.add(Box.createRigidArea(new Dimension(0, 8)));
- 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)));
+ // 鍙湁褰撴彁绀烘枃瀛椾笉涓虹┖鏃舵墠鏄剧ず
+ if (hint != null && !hint.trim().isEmpty()) {
+ formGroup.add(Box.createRigidArea(new Dimension(0, 6)));
+ JLabel hintLabel = new JLabel(hint);
+ hintLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 13));
+ hintLabel.setForeground(LIGHT_TEXT);
+ hintLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
+ formGroup.add(hintLabel);
+ formGroup.add(Box.createRigidArea(new Dimension(0, 8)));
+ } else {
+ formGroup.add(Box.createRigidArea(new Dimension(0, 8)));
+ }
return formGroup;
}
+ /**
+ * 鏍规嵁鍓插垁瀹藉害鏇存柊鍓茶崏瀹藉害鍜屽畨鍏ㄨ窛绂�
+ */
+ private void updateMowingWidthAndSafetyDistance() {
+ try {
+ String bladeWidthStr = bladeWidthField.getText().trim();
+ if (bladeWidthStr == null || bladeWidthStr.isEmpty()) {
+ mowingWidthField.setText("");
+ safetyDistanceField.setText("");
+ return;
+ }
+
+ double bladeWidthMeters = Double.parseDouble(bladeWidthStr);
+ if (bladeWidthMeters <= 0) {
+ mowingWidthField.setText("");
+ safetyDistanceField.setText("");
+ return;
+ }
+
+ // 璋冪敤 Gecaokuanjisuan 绫昏绠楀壊鑽夊搴︼紙杩斿洖鍘樼背锛屼繚鐣�2浣嶅皬鏁帮紝闇�瑕佽浆鎹负绫筹級
+ double mowingWidthCm = Gecaokuanjisuan.calculateMowingWidth(bladeWidthMeters);
+ if (mowingWidthCm > 0) {
+ // 灏嗗帢绫宠浆鎹负绫筹紝骞朵繚鐣�2浣嶅皬鏁�
+ double mowingWidthMeters = mowingWidthCm / 100.0;
+ mowingWidthField.setText(String.format(Locale.US, "%.2f", mowingWidthMeters));
+ } else {
+ mowingWidthField.setText("");
+ }
+
+ // 璋冪敤 Gecaoanquanjuli 绫昏绠楀畨鍏ㄨ窛绂�
+ String safetyDistanceStr = Gecaoanquanjuli.calculateSafetyDistanceFromString(bladeWidthStr);
+ safetyDistanceField.setText(safetyDistanceStr);
+
+ } catch (NumberFormatException e) {
+ mowingWidthField.setText("");
+ safetyDistanceField.setText("");
+ } catch (Exception e) {
+ e.printStackTrace();
+ mowingWidthField.setText("");
+ safetyDistanceField.setText("");
+ }
+ }
+
private void generateMowingPath() {
if (!dikuaiData.containsKey("boundaryDrawn")) {
JOptionPane.showMessageDialog(this, "璇峰厛瀹屾垚杈圭晫缁樺埗鍚庡啀鐢熸垚璺緞", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
@@ -1290,89 +1359,64 @@
String patternDisplay = (String) mowingPatternCombo.getSelectedItem();
dikuaiData.put("mowingPattern", patternDisplay);
- String widthText = mowingWidthField.getText().trim();
- if (widthText.isEmpty()) {
- JOptionPane.showMessageDialog(this, "鍓茶崏鏈哄壊鍒�瀹藉害涓嶈兘涓虹┖", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ // 鑾峰彇鍓茶崏瀹藉害锛堜粠鏂囨湰妗嗭紝鍗曚綅锛氱背锛�
+ String mowingWidthStr = mowingWidthField.getText().trim();
+ if (mowingWidthStr == null || mowingWidthStr.isEmpty()) {
+ JOptionPane.showMessageDialog(this, "璇峰厛杈撳叆鍓茶崏瀹藉害", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
dikuaiData.remove("plannedPath");
- showPathGenerationMessage("鍓茶崏鏈哄壊鍒�瀹藉害涓嶈兘涓虹┖锛岃閲嶆柊杈撳叆銆�", false);
+ showPathGenerationMessage("璇峰厛杈撳叆鍓茶崏瀹藉害銆�", false);
setPathAvailability(false);
return;
}
- double bladeWidthMeters;
+
+ double widthMeters;
try {
- bladeWidthMeters = Double.parseDouble(widthText);
+ widthMeters = Double.parseDouble(mowingWidthStr);
} catch (NumberFormatException e) {
- JOptionPane.showMessageDialog(this, "鍓茶崏鏈哄壊鍒�瀹藉害杈撳叆鏃犳晥", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+ JOptionPane.showMessageDialog(this, "鍓茶崏瀹藉害鏍煎紡涓嶆纭�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
dikuaiData.remove("plannedPath");
- showPathGenerationMessage("鍓茶崏鏈哄壊鍒�瀹藉害杈撳叆鏃犳晥锛岃閲嶆柊杈撳叆銆�", false);
- setPathAvailability(false);
- return;
- }
- 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);
+ 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);
+ if (widthMeters <= 0) {
+ JOptionPane.showMessageDialog(this, "鍓茶崏瀹藉害蹇呴』澶т簬0", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
dikuaiData.remove("plannedPath");
- showPathGenerationMessage("璁$畻鍚庣殑鍓茶崏瀹藉害蹇呴』澶т簬0锛岃璋冩暣鍓插垁瀹藉害鎴栭噸鍙犺窛绂汇��", false);
+ showPathGenerationMessage("鍓茶崏瀹藉害蹇呴』澶т簬0锛岃閲嶆柊璁剧疆銆�", false);
setPathAvailability(false);
return;
}
+
+ // 淇濆瓨鍓茶崏瀹藉害锛堣浆鎹负鍘樼背淇濆瓨锛屼繚鎸佷笌鍘熸湁鏁版嵁鏍煎紡涓�鑷达級
+ double widthCm = widthMeters * 100.0;
+ dikuaiData.put("mowingWidth", String.format(Locale.US, "%.2f", widthCm));
- // 淇濆瓨鍓茶崏瀹藉害锛堣绠楀悗鐨勫�硷紝杞崲涓哄帢绫冲瓨鍌紝淇濇寔涓庡師鏈夋暟鎹牸寮忓吋瀹癸級
- double calculatedWidthCm = calculatedWidthMeters * 100.0;
- dikuaiData.put("mowingWidth", String.format(Locale.US, "%.0f", calculatedWidthCm));
-
- String widthMeters = String.format(Locale.US, "%.2f", calculatedWidthMeters);
+ // 鑾峰彇瀹夊叏璺濈
+ String safetyDistanceStr = safetyDistanceField.getText().trim();
+ double safetyDistanceMeters = Double.NaN;
+ if (safetyDistanceStr != null && !safetyDistanceStr.isEmpty()) {
+ try {
+ safetyDistanceMeters = Double.parseDouble(safetyDistanceStr);
+ } catch (NumberFormatException e) {
+ // 浣跨敤NaN锛岃绯荤粺鑷姩璁$畻
+ }
+ }
+
+ String widthMetersStr = String.format(Locale.US, "%.3f", widthMeters);
+ String safetyDistanceMetersStr = Double.isNaN(safetyDistanceMeters) ? null : String.format(Locale.US, "%.3f", safetyDistanceMeters);
String plannerMode = resolvePlannerMode(patternDisplay);
try {
- List<Lunjingguihua.PathSegment> segments = Lunjingguihua.generatePathSegments(
+ // 浣跨敤涓庤矾寰勮鍒掗〉闈㈢浉鍚岀殑鏂规硶锛歀unjingguihua.generatePathFromStrings
+ String plannedPath = Lunjingguihua.generatePathFromStrings(
boundaryCoords,
- obstacleCoords,
- widthMeters,
+ obstacleCoords != null ? obstacleCoords : "",
+ widthMetersStr,
+ safetyDistanceMetersStr,
plannerMode
);
- String plannedPath = Lunjingguihua.formatPathSegments(segments);
+
if (!isMeaningfulValue(plannedPath)) {
JOptionPane.showMessageDialog(this, "鐢熸垚鍓茶崏璺緞澶辫触: 鐢熸垚缁撴灉涓虹┖", "閿欒", JOptionPane.ERROR_MESSAGE);
dikuaiData.remove("plannedPath");
@@ -1380,6 +1424,7 @@
setPathAvailability(false);
return;
}
+
if (isMeaningfulValue(boundaryCoords)) {
dikuaiData.put("boundaryCoordinates", boundaryCoords);
}
@@ -1389,7 +1434,7 @@
dikuaiData.put("plannedPath", plannedPath);
setPathAvailability(true);
showPathGenerationMessage(
- "宸叉牴鎹綋鍓嶈缃敓鎴愬壊鑽夎矾寰勶紝鍏辩敓鎴� " + segments.size() + " 娈点�俓n鐐瑰嚮鈥滈瑙堚�濇寜閽彲鍦ㄤ富椤甸潰鏌ョ湅鏁堟灉銆�",
+ "宸叉牴鎹綋鍓嶈缃敓鎴愬壊鑽夎矾寰勩�俓n鐐瑰嚮棰勮鎸夐挳鍙湪涓婚〉闈㈡煡鐪嬫晥鏋溿��",
true);
} catch (IllegalArgumentException ex) {
JOptionPane.showMessageDialog(this, "鐢熸垚鍓茶崏璺緞澶辫触: " + ex.getMessage(), "閿欒", JOptionPane.ERROR_MESSAGE);
@@ -1485,53 +1530,20 @@
}
}
- // 淇濆瓨鍓茶崏鏈哄壊鍒�瀹藉害
+ // 淇濆瓨鍓茶崏瀹藉害锛堜粠鏂囨湰妗嗚幏鍙栵紝鍗曚綅锛氱背锛岃浆鎹负鍘樼背淇濆瓨锛�
if (mowingWidthField != null) {
- String bladeWidthText = mowingWidthField.getText().trim();
- if (!bladeWidthText.isEmpty()) {
+ String widthStr = mowingWidthField.getText().trim();
+ if (widthStr != null && !widthStr.isEmpty()) {
try {
- double bladeWidthMeters = Double.parseDouble(bladeWidthText);
- dikuaiData.put("mowingBladeWidth", String.format(Locale.US, "%.2f", bladeWidthMeters));
+ double widthMeters = Double.parseDouble(widthStr);
+ double widthCm = widthMeters * 100.0;
+ dikuaiData.put("mowingWidth", String.format(Locale.US, "%.2f", widthCm));
} catch (NumberFormatException e) {
- // 濡傛灉瑙f瀽澶辫触锛岀洿鎺ヤ繚瀛樻枃鏈�
- dikuaiData.put("mowingBladeWidth", bladeWidthText);
+ // 淇濇寔鍘熷��
+ dikuaiData.put("mowingWidth", widthStr);
}
}
}
-
- // 淇濆瓨鐩搁偦琛岄噸鍙犺窛绂�
- 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) {
- // 濡傛灉璁$畻澶辫触锛屼笉淇濆瓨鍓茶崏瀹藉害
- }
- }
}
private void captureSessionSnapshot() {
@@ -1658,10 +1670,20 @@
if (boundaryCountLabel == null) {
return;
}
- int count = Coordinate.coordinates != null ? Coordinate.coordinates.size() : 0;
- double area = jisuanmianjie.calculatePolygonArea();
- DecimalFormat areaFormat = new DecimalFormat("0.00");
- boundaryCountLabel.setText("宸查噰闆嗗埌杈圭晫鐐�" + count + "涓紝褰撳墠鍦板潡闈㈢Н涓�" + areaFormat.format(area) + "銕�");
+
+ // 浣跨敤浼樺寲鍚庣殑杈圭晫鏁版嵁璁$畻鐐规暟鍜岄潰绉�
+ String optimizedXYStr = dikuaiData.get("optimizedBoundaryXY");
+ if (optimizedXYStr != null && !optimizedXYStr.isEmpty() && !optimizedXYStr.startsWith("ERROR")) {
+ int count = Bianjieyouhuatoxy.calculatePointCount(optimizedXYStr);
+ String areaStr = Bianjieyouhuatoxy.calculateArea(optimizedXYStr);
+ boundaryCountLabel.setText("宸查噰闆嗗埌杈圭晫鐐�" + count + "涓紝褰撳墠鍦板潡闈㈢Н涓�" + areaStr + "銕�");
+ } else {
+ // 濡傛灉娌℃湁浼樺寲鍚庣殑鏁版嵁锛屼娇鐢ㄥ師濮嬫暟鎹�
+ int count = Coordinate.coordinates != null ? Coordinate.coordinates.size() : 0;
+ double area = jisuanmianjie.calculatePolygonArea();
+ DecimalFormat areaFormat = new DecimalFormat("0.00");
+ boundaryCountLabel.setText("宸查噰闆嗗埌杈圭晫鐐�" + count + "涓紝褰撳墠鍦板潡闈㈢Н涓�" + areaFormat.format(area) + "銕�");
+ }
boundaryCountLabel.setVisible(true);
}
@@ -1678,7 +1700,6 @@
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);
@@ -1687,13 +1708,11 @@
}
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);
@@ -1749,47 +1768,6 @@
}
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()) {
@@ -1837,6 +1815,53 @@
if (boundaryCountLabel != null) {
boundaryCountLabel.setVisible(false);
}
+ if (boundaryXYTextArea != null) {
+ boundaryXYTextArea.setVisible(false);
+ boundaryXYTextArea.setText("");
+ }
+ if (boundaryXYScrollPane != null) {
+ boundaryXYScrollPane.setVisible(false);
+ }
+ }
+
+ /**
+ * 鏇存柊杈圭晫XY鍧愭爣鏄剧ず
+ */
+ private void updateBoundaryXYDisplay() {
+ if (boundaryXYTextArea == null || boundaryXYScrollPane == null) {
+ return;
+ }
+
+ // 鑾峰彇浼樺寲鍚庣殑杈圭晫XY鍧愭爣
+ String optimizedXYStr = dikuaiData.get("optimizedBoundaryXY");
+ if (optimizedXYStr != null && !optimizedXYStr.isEmpty() && !optimizedXYStr.startsWith("ERROR")) {
+ boundaryXYTextArea.setText(optimizedXYStr);
+ boundaryXYTextArea.setVisible(true);
+ boundaryXYScrollPane.setVisible(true);
+ } else {
+ // 濡傛灉娌℃湁浼樺寲鍚庣殑鏁版嵁锛屽皾璇曚粠鍘熷鍧愭爣浼樺寲骞舵樉绀�
+ // 濡傛灉宸茬粡鏈夊師濮嬪潗鏍囦絾杩樻病鏈変紭鍖栵紝鍒欒繘琛屼紭鍖�
+ if (dikuaiData.containsKey("boundaryDrawn") &&
+ (Coordinate.coordinates != null && !Coordinate.coordinates.isEmpty())) {
+ // 灏濊瘯浼樺寲杈圭晫
+ optimizeBoundaryAndSave();
+ // 鍐嶆鑾峰彇浼樺寲鍚庣殑鍧愭爣
+ optimizedXYStr = dikuaiData.get("optimizedBoundaryXY");
+ if (optimizedXYStr != null && !optimizedXYStr.isEmpty() && !optimizedXYStr.startsWith("ERROR")) {
+ boundaryXYTextArea.setText(optimizedXYStr);
+ boundaryXYTextArea.setVisible(true);
+ boundaryXYScrollPane.setVisible(true);
+ } else {
+ boundaryXYTextArea.setText("杈圭晫鍧愭爣鏁版嵁鏈氨缁�");
+ boundaryXYTextArea.setVisible(true);
+ boundaryXYScrollPane.setVisible(true);
+ }
+ } else {
+ boundaryXYTextArea.setText("杈圭晫鍧愭爣鏁版嵁鏈氨缁�");
+ boundaryXYTextArea.setVisible(true);
+ boundaryXYScrollPane.setVisible(true);
+ }
+ }
}
private boolean hasGeneratedPath() {
@@ -1905,18 +1930,23 @@
String optimizedBoundary;
try {
- optimizedBoundary = bianjieguihua2.processCoordinateListAuto(baseStationCoordinates);
- } catch (RuntimeException ex) {
+ // 鏋勫缓杈圭晫瀛楃涓诧紝鏍煎紡涓� "(lat1,lon1,alt1;lat2,lon2,alt2;...)"
+ String boundaryStr = buildBoundaryStringForOptimization(uniqueCoordinates);
+ // 璋冪敤 Bianjieyouhuatoxy.optimizeBoundary 鏂规硶
+ optimizedBoundary = Bianjieyouhuatoxy.optimizeBoundary(baseStationCoordinates, boundaryStr);
+ if (optimizedBoundary == null || optimizedBoundary.isEmpty() || optimizedBoundary.startsWith("ERROR")) {
+ return BoundarySnapshotResult.failure("鐢熸垚鍦板潡杈圭晫澶辫触: 浼樺寲鍚庣殑杈圭晫鍧愭爣鏃犳晥", JOptionPane.ERROR_MESSAGE);
+ }
+ } catch (Exception ex) {
ex.printStackTrace();
return BoundarySnapshotResult.failure("鐢熸垚鍦板潡杈圭晫澶辫触: " + ex.getMessage(), JOptionPane.ERROR_MESSAGE);
}
String originalBoundary = buildOriginalBoundaryString(uniqueCoordinates);
- String originalBoundaryXY = buildOriginalBoundaryXYString(uniqueCoordinates, baseStationCoordinates);
DecimalFormat areaFormat = new DecimalFormat("0.00");
String areaString = areaFormat.format(area);
- return BoundarySnapshotResult.success(originalBoundary, originalBoundaryXY, optimizedBoundary, areaString, baseStationCoordinates);
+ return BoundarySnapshotResult.success(originalBoundary, optimizedBoundary, areaString, baseStationCoordinates);
}
private String resolvePlannerMode(String patternDisplay) {
@@ -1977,6 +2007,10 @@
private void showStep(int step) {
currentStep = step;
cardLayout.show(stepsPanel, "step" + step);
+
+ if (step == 1) {
+ updateObstacleSummary();
+ }
// 鏇存柊鎸夐挳鐘舵��
updateButtonState(step);
@@ -2047,53 +2081,20 @@
case 3:
dikuaiData.put("mowingPattern", (String) mowingPatternCombo.getSelectedItem());
-
- // 淇濆瓨鍓茶崏鏈哄壊鍒�瀹藉害
+ // 淇濆瓨鍓茶崏瀹藉害锛堜粠鏂囨湰妗嗚幏鍙栵紝鍗曚綅锛氱背锛岃浆鎹负鍘樼背淇濆瓨锛�
if (mowingWidthField != null) {
- String bladeWidthText = mowingWidthField.getText().trim();
- if (!bladeWidthText.isEmpty()) {
+ String widthStr = mowingWidthField.getText().trim();
+ if (widthStr != null && !widthStr.isEmpty()) {
try {
- double bladeWidthMeters = Double.parseDouble(bladeWidthText);
- dikuaiData.put("mowingBladeWidth", String.format(Locale.US, "%.2f", bladeWidthMeters));
+ double widthMeters = Double.parseDouble(widthStr);
+ double widthCm = widthMeters * 100.0;
+ dikuaiData.put("mowingWidth", String.format(Locale.US, "%.2f", widthCm));
} catch (NumberFormatException e) {
- dikuaiData.put("mowingBladeWidth", bladeWidthText);
+ // 淇濇寔鍘熷��
+ dikuaiData.put("mowingWidth", widthStr);
}
}
}
-
- // 淇濆瓨鐩搁偦琛岄噸鍙犺窛绂�
- 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;
@@ -2338,6 +2339,7 @@
isDrawing = false;
showStep(2);
showBoundaryPointSummary();
+ updateBoundaryXYDisplay();
} else {
if (startEndDrawingBtn != null) {
startEndDrawingBtn.setText("寮�濮嬬粯鍒�");
@@ -2374,54 +2376,36 @@
}
}
- // 鎭㈠鍓茶崏鏈哄壊鍒�瀹藉害锛堜紭鍏堜粠mowingBladeWidth鑾峰彇锛�
- if (mowingWidthField != null) {
- String bladeWidth = data.get("mowingBladeWidth");
- if (isMeaningfulValue(bladeWidth)) {
- try {
- 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) {
- // 淇濇寔褰撳墠鍊�
- }
- }
- }
- } 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) {
- // 淇濇寔褰撳墠鍊�
- }
- }
+ // 鎭㈠鍓茶崏瀹藉害锛氫粠淇濆瓨鐨勫壊鑽夊搴︼紙鍘樼背锛夎浆鎹负绫冲苟璁剧疆
+ String width = data.get("mowingWidth");
+ if (isMeaningfulValue(width) && mowingWidthField != null) {
+ try {
+ double mowingWidthCm = Double.parseDouble(width.trim());
+ // 灏嗗帢绫宠浆鎹负绫�
+ double mowingWidthMeters = mowingWidthCm / 100.0;
+ mowingWidthField.setText(String.format(Locale.US, "%.3f", mowingWidthMeters));
+ } 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) {
- // 淇濇寔褰撳墠鍊�
+ // 鎭㈠鍓插垁瀹藉害锛氫粠淇濆瓨鐨勫壊鑽夊搴﹀弽鎺ㄥ壊鍒�瀹藉害骞惰缃�
+ // 鐢变簬鍓茶崏瀹藉害 = 鍓插垁瀹藉害 * 0.85锛屾墍浠ュ壊鍒�瀹藉害 = 鍓茶崏瀹藉害 / 0.85
+ if (isMeaningfulValue(width) && bladeWidthField != null) {
+ try {
+ double mowingWidthCm = Double.parseDouble(width.trim());
+ // 灏嗗帢绫宠浆鎹负绫筹紝鐒跺悗鍙嶆帹鍓插垁瀹藉害
+ double mowingWidthMeters = mowingWidthCm / 100.0;
+ double bladeWidthMeters = mowingWidthMeters / 0.85;
+ bladeWidthField.setText(String.format(Locale.US, "%.3f", bladeWidthMeters));
+ // 瑙﹀彂鑷姩璁$畻瀹夊叏璺濈
+ if (safetyDistanceField != null) {
+ String safetyDistanceStr = Gecaoanquanjuli.calculateSafetyDistanceFromString(
+ String.format(Locale.US, "%.3f", bladeWidthMeters));
+ safetyDistanceField.setText(safetyDistanceStr);
}
+ } catch (NumberFormatException ignored) {
+ // 淇濇寔褰撳墠鍊�
}
}
@@ -2455,7 +2439,6 @@
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);
@@ -2515,9 +2498,6 @@
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"));
}
@@ -2531,81 +2511,14 @@
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