From f66407df7e4971a7a85e4b281cc199a05ec84987 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期二, 23 十二月 2025 16:25:58 +0800
Subject: [PATCH] 优化了功能

---
 src/zhangaiwu/AddDikuai.java | 1300 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 1,186 insertions(+), 114 deletions(-)

diff --git a/src/zhangaiwu/AddDikuai.java b/src/zhangaiwu/AddDikuai.java
index ee81258..52de9ce 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,27 +7,29 @@
 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;
 import java.util.Locale;
 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 gecaoji.Device;
-import bianjie.bianjieguihua2;
+import dikuai.Gecaokuanjisuan;
+import dikuai.Gecaoanquanjuli;
+import bianjie.Bianjieyouhuatoxy;
 import lujing.Lunjingguihua;
+import set.Setsys;
 import ui.UIConfig;
 import zhuye.MowerLocationData;
 import zhuye.Shouye;
 import zhuye.Coordinate;
+import publicway.buttonset;
 
 /**
  * 鏂板鍦板潡瀵硅瘽妗� - 澶氭楠よ〃鍗曡璁�
@@ -49,6 +49,9 @@
     private final Color LIGHT_TEXT = new Color(108, 117, 125);
     private final Color BORDER_COLOR = new Color(222, 226, 230);
     private final Color SUCCESS_COLOR = new Color(40, 167, 69);
+    private final Color ERROR_COLOR = new Color(220, 53, 69);
+    private static final String KEY_PATH_MESSAGE_TEXT = "__pathMessageText";
+    private static final String KEY_PATH_MESSAGE_SUCCESS = "__pathMessageSuccess";
     
     // 姝ラ闈㈡澘
     private JPanel mainPanel;
@@ -59,7 +62,9 @@
     private JTextField landNumberField;
     private JTextField areaNameField;
     private JComboBox<String> mowingPatternCombo;
-    private JSpinner mowingWidthSpinner;
+    private JTextField bladeWidthField;  // 鍓茶崏鏈哄壊鍒�瀹藉害锛坢锛�
+    private JTextField mowingWidthField;  // 鍓茶崏瀹藉害锛坢锛屽彲缂栬緫锛�
+    private JTextField safetyDistanceField;  // 鍓茶崏瀹夊叏璺濈锛坢锛屽彲缂栬緫锛�
     private JPanel previewPanel;
     private Map<String, JPanel> drawingOptionPanels = new HashMap<>();
     
@@ -68,8 +73,15 @@
     private JButton prevButton;
     private JButton nextButton;
     private JButton createButton;
+    private JButton previewButton;  // 姝ラ3鐨勯瑙堟寜閽紙棰勮鍓茶崏璺緞锛�
+    private JButton boundaryPreviewButton;  // 姝ラ2鐨勯瑙堟寜閽紙棰勮杈圭晫锛�
+    private Component previewButtonSpacer;
     private JLabel boundaryCountLabel;
+    private JTextArea boundaryXYTextArea;  // 鏄剧ず杈圭晫XY鍧愭爣鐨勬枃鏈煙
+    private JScrollPane boundaryXYScrollPane;  // 杈圭晫XY鍧愭爣鏂囨湰鍩熺殑婊氬姩闈㈡澘
     private JPanel obstacleListContainer;
+    private JTextArea pathGenerationMessageArea;
+    private JPanel pathMessageWrapper;
     
     // 鍦板潡鏁版嵁
     private Map<String, String> dikuaiData = new HashMap<>();
@@ -249,7 +261,7 @@
         ));
         areaNameField.setAlignmentX(Component.LEFT_ALIGNMENT);
         
-        // 娣诲姞杈撳叆妗嗙劍鐐规晥鏋�
+        // 娣诲姞杈撳叆妗嗙劍鐐规晥鏋滃拰鏂囨湰鍙樺寲鐩戝惉
         areaNameField.addFocusListener(new FocusAdapter() {
             @Override
             public void focusGained(FocusEvent e) {
@@ -265,6 +277,16 @@
                     BorderFactory.createLineBorder(BORDER_COLOR, 2),
                     BorderFactory.createEmptyBorder(12, 15, 12, 15)
                 ));
+                // 鏇存柊涓嬩竴姝ユ寜閽姸鎬�
+                updateStep1ButtonState();
+            }
+        });
+        
+        // 娣诲姞鏂囨湰鍙樺寲鐩戝惉锛屽疄鏃舵洿鏂版寜閽姸鎬�
+        areaNameField.addKeyListener(new KeyAdapter() {
+            @Override
+            public void keyReleased(KeyEvent e) {
+                updateStep1ButtonState();
             }
         });
         
@@ -643,10 +665,39 @@
         startEndDrawingBtn.setAlignmentX(Component.LEFT_ALIGNMENT);
         startEndDrawingBtn.setMaximumSize(new Dimension(400, 55));
         startEndDrawingBtn.setEnabled(false); // 鍒濆涓嶅彲鐢�
+        startEndDrawingBtn.setBackground(MEDIUM_GRAY); // 鍒濆鐏拌壊鑳屾櫙
         
         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);
@@ -733,8 +784,9 @@
                 if (!optionPanel.isEnabled()) {
                     return;
                 }
-                selectDrawingOption(optionPanel, type);
-                startEndDrawingBtn.setEnabled(true); // 閫夋嫨鍚庡惎鐢ㄦ寜閽�
+                if (selectDrawingOption(optionPanel, type, true)) {
+                    updateStartDrawingButtonState(); // 閫夋嫨鍚庢洿鏂版寜閽姸鎬�
+                }
             }
             
             @Override
@@ -756,7 +808,15 @@
         return optionPanel;
     }
     
-    private void selectDrawingOption(JPanel optionPanel, String type) {
+    private boolean selectDrawingOption(JPanel optionPanel, String type, boolean userTriggered) {
+        if (optionPanel == null) {
+            return false;
+        }
+        if (userTriggered && "handheld".equalsIgnoreCase(type) && !hasConfiguredHandheldMarker()) {
+            JOptionPane.showMessageDialog(this, "璇峰厛娣诲姞渚挎惡鎵撶偣鍣ㄧ紪鍙�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+            return false;
+        }
+
         // 閲嶇疆涔嬪墠閫変腑鐨勯�夐」
         if (selectedOptionPanel != null) {
             selectedOptionPanel.setBorder(BorderFactory.createLineBorder(BORDER_COLOR, 2));
@@ -766,7 +826,7 @@
                 ((JLabel) oldTitle).setForeground(TEXT_COLOR);
             }
         }
-        
+
         // 璁剧疆鏂扮殑閫変腑鐘舵��
         optionPanel.setBorder(BorderFactory.createLineBorder(PRIMARY_COLOR, 3));
         optionPanel.setBackground(PRIMARY_LIGHT);
@@ -775,9 +835,15 @@
             ((JLabel) titleObj).setForeground(PRIMARY_COLOR);
         }
         selectedOptionPanel = optionPanel;
-        
+
         // 淇濆瓨閫夋嫨
         dikuaiData.put("drawingMethod", type);
+        return true;
+    }
+
+    private boolean hasConfiguredHandheldMarker() {
+        String handheldId = Setsys.getPropertyValue("handheldMarkerId");
+        return handheldId != null && !handheldId.trim().isEmpty();
     }
     
     private void toggleDrawing() {
@@ -800,12 +866,20 @@
             // 鐢ㄦ埛鍦ㄥ璇濇鍐呬富鍔ㄧ粨鏉燂紙鏈Е鍙戝閮ㄦ祦绋嬶級
             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();
+            // 鏇存柊棰勮鍜屼笅涓�姝ユ寜閽姸鎬侊紙鑳屾櫙棰滆壊鍙樼豢鑹诧紝鍙偣鍑伙級
+            updateStep2ButtonsAfterDrawing();
         }
     }
 
@@ -856,6 +930,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));
@@ -877,7 +1025,7 @@
         settingsPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
         
         // 鍓茶崏妯″紡閫夋嫨
-        JPanel patternPanel = createFormGroup("鍓茶崏妯″紡", "閫夋嫨鍓茶崏璺緞鐨勭敓鎴愭ā寮�");
+        JPanel patternPanel = createFormGroup("鍓茶崏妯″紡", "");
         mowingPatternCombo = new JComboBox<>(new String[]{"骞宠绾�", "铻烘棆寮�"});
         mowingPatternCombo.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 16));
         mowingPatternCombo.setMaximumSize(new Dimension(Integer.MAX_VALUE, 48));
@@ -911,27 +1059,23 @@
         settingsPanel.add(patternPanel);
         settingsPanel.add(Box.createRigidArea(new Dimension(0, 20)));
         
-        // 鍓茶崏瀹藉害璁剧疆
-        JPanel widthPanel = createFormGroup("鍓茶崏瀹藉害", "璁剧疆鍓茶崏鏈哄崟娆″壊鑽夌殑瀹藉害");
-        JPanel widthInputPanel = new JPanel(new BorderLayout());
-        widthInputPanel.setBackground(WHITE);
-        widthInputPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, 48));
-        widthInputPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
+        // 鍓茶崏鏈哄壊鍒�瀹藉害璁剧疆
+        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);
         
-        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(
+        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)
         ));
-        
-        // 娣诲姞寰皟鍣ㄧ劍鐐规晥鏋�
-        mowingWidthSpinner.addFocusListener(new FocusAdapter() {
+        bladeWidthField.addFocusListener(new FocusAdapter() {
             @Override
             public void focusGained(FocusEvent e) {
-                editor.getTextField().setBorder(BorderFactory.createCompoundBorder(
+                bladeWidthField.setBorder(BorderFactory.createCompoundBorder(
                     BorderFactory.createLineBorder(PRIMARY_COLOR, 2),
                     BorderFactory.createEmptyBorder(10, 12, 10, 12)
                 ));
@@ -939,26 +1083,124 @@
             
             @Override
             public void focusLost(FocusEvent e) {
-                editor.getTextField().setBorder(BorderFactory.createCompoundBorder(
+                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();
+        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) {
+                mowingWidthField.setBorder(BorderFactory.createCompoundBorder(
+                    BorderFactory.createLineBorder(PRIMARY_COLOR, 2),
+                    BorderFactory.createEmptyBorder(10, 12, 10, 12)
+                ));
+            }
+            
+            @Override
+            public void focusLost(FocusEvent e) {
+                mowingWidthField.setBorder(BorderFactory.createCompoundBorder(
                     BorderFactory.createLineBorder(BORDER_COLOR, 2),
                     BorderFactory.createEmptyBorder(10, 12, 10, 12)
                 ));
             }
         });
         
-        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));
         
-        widthInputPanel.add(mowingWidthSpinner, BorderLayout.CENTER);
+        widthInputPanel.add(mowingWidthField, BorderLayout.CENTER);
         widthInputPanel.add(unitLabel, BorderLayout.EAST);
         
         widthPanel.add(widthInputPanel);
         settingsPanel.add(widthPanel);
+        settingsPanel.add(Box.createRigidArea(new Dimension(0, 20)));
+        
+        // 鍓茶崏瀹夊叏璺濈璁剧疆锛堝彲缂栬緫锛�
+        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);
+        
+        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)
+        ));
+        safetyDistanceField.addFocusListener(new FocusAdapter() {
+            @Override
+            public void focusGained(FocusEvent e) {
+                safetyDistanceField.setBorder(BorderFactory.createCompoundBorder(
+                    BorderFactory.createLineBorder(PRIMARY_COLOR, 2),
+                    BorderFactory.createEmptyBorder(10, 12, 10, 12)
+                ));
+            }
+            
+            @Override
+            public void focusLost(FocusEvent e) {
+                safetyDistanceField.setBorder(BorderFactory.createCompoundBorder(
+                    BorderFactory.createLineBorder(BORDER_COLOR, 2),
+                    BorderFactory.createEmptyBorder(10, 12, 10, 12)
+                ));
+            }
+        });
+        
+        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(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();
+        
+        // 灏嗚缃潰鏉挎斁鍏ユ粴鍔ㄩ潰鏉�
+        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);
@@ -967,6 +1209,29 @@
 
         stepPanel.add(Box.createRigidArea(new Dimension(0, 20)));
         stepPanel.add(generatePathButton);
+        stepPanel.add(Box.createRigidArea(new Dimension(0, 12)));
+
+        pathMessageWrapper = new JPanel(new BorderLayout());
+        pathMessageWrapper.setAlignmentX(Component.LEFT_ALIGNMENT);
+        pathMessageWrapper.setBackground(PRIMARY_LIGHT);
+        pathMessageWrapper.setBorder(BorderFactory.createCompoundBorder(
+            BorderFactory.createLineBorder(PRIMARY_COLOR, 1),
+            BorderFactory.createEmptyBorder(12, 12, 12, 12)
+        ));
+        pathMessageWrapper.setVisible(false);
+
+        pathGenerationMessageArea = new JTextArea();
+        pathGenerationMessageArea.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+        pathGenerationMessageArea.setForeground(TEXT_COLOR);
+        pathGenerationMessageArea.setOpaque(false);
+        pathGenerationMessageArea.setEditable(false);
+        pathGenerationMessageArea.setLineWrap(true);
+        pathGenerationMessageArea.setWrapStyleWord(true);
+        pathGenerationMessageArea.setFocusable(false);
+        pathGenerationMessageArea.setBorder(null);
+
+        pathMessageWrapper.add(pathGenerationMessageArea, BorderLayout.CENTER);
+        stepPanel.add(pathMessageWrapper);
         stepPanel.add(Box.createVerticalGlue());
 
         return stepPanel;
@@ -1010,22 +1275,73 @@
         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)));
+        
+        // 鍙湁褰撴彁绀烘枃瀛椾笉涓虹┖鏃舵墠鏄剧ず
+        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);
+            dikuaiData.remove("plannedPath");
+            showPathGenerationMessage("璇峰厛瀹屾垚杈圭晫缁樺埗鍚庡啀鐢熸垚璺緞銆�", false);
+            setPathAvailability(false);
             showStep(2);
             return;
         }
@@ -1039,9 +1355,9 @@
         }
         if (boundaryCoords == null) {
             JOptionPane.showMessageDialog(this, "鏈壘鍒版湁鏁堢殑鍦板潡杈圭晫鍧愭爣锛屾棤娉曠敓鎴愯矾寰�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
-            if (createButton != null) {
-                createButton.setEnabled(false);
-            }
+            dikuaiData.remove("plannedPath");
+            showPathGenerationMessage("鏈壘鍒版湁鏁堢殑鍦板潡杈圭晫鍧愭爣锛屾棤娉曠敓鎴愯矾寰勩��", false);
+            setPathAvailability(false);
             return;
         }
 
@@ -1057,95 +1373,288 @@
         String patternDisplay = (String) mowingPatternCombo.getSelectedItem();
         dikuaiData.put("mowingPattern", patternDisplay);
 
-        Object widthObj = mowingWidthSpinner.getValue();
-        if (!(widthObj instanceof Number)) {
-            JOptionPane.showMessageDialog(this, "鍓茶崏瀹藉害杈撳叆鏃犳晥", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
-            if (createButton != null) {
-                createButton.setEnabled(false);
-            }
+        // 鑾峰彇鍓茶崏瀹藉害锛堜粠鏂囨湰妗嗭紝鍗曚綅锛氱背锛�
+        String mowingWidthStr = mowingWidthField.getText().trim();
+        if (mowingWidthStr == null || mowingWidthStr.isEmpty()) {
+            JOptionPane.showMessageDialog(this, "璇峰厛杈撳叆鍓茶崏瀹藉害", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+            dikuaiData.remove("plannedPath");
+            showPathGenerationMessage("璇峰厛杈撳叆鍓茶崏瀹藉害銆�", false);
+            setPathAvailability(false);
             return;
         }
-        double widthCm = ((Number) widthObj).doubleValue();
-        if (widthCm <= 0) {
+        
+        double widthMeters;
+        try {
+            widthMeters = Double.parseDouble(mowingWidthStr);
+        } catch (NumberFormatException e) {
+            JOptionPane.showMessageDialog(this, "鍓茶崏瀹藉害鏍煎紡涓嶆纭�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+            dikuaiData.remove("plannedPath");
+            showPathGenerationMessage("鍓茶崏瀹藉害鏍煎紡涓嶆纭紝璇烽噸鏂拌緭鍏ャ��", false);
+            setPathAvailability(false);
+            return;
+        }
+        
+        if (widthMeters <= 0) {
             JOptionPane.showMessageDialog(this, "鍓茶崏瀹藉害蹇呴』澶т簬0", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
-            if (createButton != null) {
-                createButton.setEnabled(false);
-            }
+            dikuaiData.remove("plannedPath");
+            showPathGenerationMessage("鍓茶崏瀹藉害蹇呴』澶т簬0锛岃閲嶆柊璁剧疆銆�", false);
+            setPathAvailability(false);
             return;
         }
-        dikuaiData.put("mowingWidth", widthObj.toString());
+        
+        // 淇濆瓨鍓茶崏瀹藉害锛堣浆鎹负鍘樼背淇濆瓨锛屼繚鎸佷笌鍘熸湁鏁版嵁鏍煎紡涓�鑷达級
+        double widthCm = widthMeters * 100.0;
+        dikuaiData.put("mowingWidth", String.format(Locale.US, "%.2f", widthCm));
 
-        String widthMeters = String.format(Locale.US, "%.2f", widthCm / 100.0);
+        // 鑾峰彇瀹夊叏璺濈
+        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);
-                if (createButton != null) {
-                    createButton.setEnabled(false);
-                }
+                dikuaiData.remove("plannedPath");
+                showPathGenerationMessage("鐢熸垚鍓茶崏璺緞澶辫触锛氱敓鎴愮粨鏋滀负绌恒��", false);
+                setPathAvailability(false);
                 return;
             }
-            dikuaiData.put("plannedPath", plannedPath);
-            if (createButton != null) {
-                createButton.setEnabled(true);
+            
+            if (isMeaningfulValue(boundaryCoords)) {
+                dikuaiData.put("boundaryCoordinates", boundaryCoords);
             }
-            JOptionPane.showMessageDialog(this,
-                "宸叉牴鎹綋鍓嶈缃敓鎴愬壊鑽夎矾寰勶紝鍏辩敓鎴� " + segments.size() + " 娈点��",
-                "鎴愬姛",
-                JOptionPane.INFORMATION_MESSAGE);
+            if (isMeaningfulValue(obstacleCoords)) {
+                dikuaiData.put("obstacleCoordinates", obstacleCoords);
+            }
+            dikuaiData.put("plannedPath", plannedPath);
+            setPathAvailability(true);
+            showPathGenerationMessage(
+                "宸叉牴鎹綋鍓嶈缃敓鎴愬壊鑽夎矾寰勩�俓n鐐瑰嚮棰勮鎸夐挳鍙湪涓婚〉闈㈡煡鐪嬫晥鏋溿��",
+                true);
         } catch (IllegalArgumentException ex) {
             JOptionPane.showMessageDialog(this, "鐢熸垚鍓茶崏璺緞澶辫触: " + ex.getMessage(), "閿欒", JOptionPane.ERROR_MESSAGE);
-            if (createButton != null) {
-                createButton.setEnabled(false);
-            }
+            dikuaiData.remove("plannedPath");
+            showPathGenerationMessage("鐢熸垚鍓茶崏璺緞澶辫触锛�" + ex.getMessage(), false);
+            setPathAvailability(false);
         } catch (Exception ex) {
             ex.printStackTrace();
             JOptionPane.showMessageDialog(this, "鐢熸垚鍓茶崏璺緞鏃跺彂鐢熷紓甯�: " + ex.getMessage(), "閿欒", JOptionPane.ERROR_MESSAGE);
-            if (createButton != null) {
-                createButton.setEnabled(false);
+            dikuaiData.remove("plannedPath");
+            showPathGenerationMessage("鐢熸垚鍓茶崏璺緞鏃跺彂鐢熷紓甯革細" + ex.getMessage(), false);
+            setPathAvailability(false);
+        }
+    }
+
+    private void previewMowingPath() {
+        if (!hasGeneratedPath()) {
+            showPathGenerationMessage("璇峰厛鐢熸垚鍓茶崏璺緞鍚庡啀棰勮銆�", false);
+            setPathAvailability(false);
+            return;
+        }
+
+        persistStep3Inputs();
+
+        String landNumber = getPendingLandNumber();
+        String trimmedAreaName = areaNameField.getText() != null ? areaNameField.getText().trim() : "";
+        String displayAreaName = isMeaningfulValue(trimmedAreaName) ? trimmedAreaName : landNumber;
+
+        String plannedPath = dikuaiData.get("plannedPath");
+        if (!isMeaningfulValue(plannedPath)) {
+            showPathGenerationMessage("璇峰厛鐢熸垚鍓茶崏璺緞鍚庡啀棰勮銆�", false);
+            setPathAvailability(false);
+            return;
+        }
+
+        String boundary = null;
+        Dikuai pending = getOrCreatePendingDikuai();
+        if (pending != null) {
+            boundary = normalizeCoordinateValue(pending.getBoundaryCoordinates());
+        }
+        if (boundary == null) {
+            boundary = normalizeCoordinateValue(dikuaiData.get("boundaryCoordinates"));
+        }
+
+        String obstacles = normalizeCoordinateValue(dikuaiData.get("obstacleCoordinates"));
+        if (!isMeaningfulValue(obstacles)) {
+            obstacles = resolveObstaclePayloadFromConfig(landNumber);
+            if (isMeaningfulValue(obstacles)) {
+                dikuaiData.put("obstacleCoordinates", obstacles);
+            }
+        }
+
+        Shouye shouye = Shouye.getInstance();
+        if (shouye == null) {
+            JOptionPane.showMessageDialog(this, "鏃犳硶鎵撳紑涓婚〉闈紝璇风◢鍚庨噸璇�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+
+        dikuaiData.put("areaName", trimmedAreaName);
+        if (isMeaningfulValue(boundary)) {
+            dikuaiData.put("boundaryCoordinates", boundary);
+        }
+
+        pendingLandNumber = landNumber;
+        captureSessionSnapshot();
+
+        resumeRequested = true;
+        boolean started = shouye.startMowingPathPreview(
+            landNumber,
+            displayAreaName,
+            boundary,
+            obstacles,
+            plannedPath,
+            AddDikuai::resumeFromPreview
+        );
+        if (!started) {
+            resumeRequested = false;
+            JOptionPane.showMessageDialog(this, "鏃犳硶鍚姩棰勮锛岃绋嶅悗鍐嶈瘯", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+        
+        // 鍦ㄦ楠�3棰勮鏃讹紝涓嶆樉绀鸿竟鐣岀偣鍦嗗湀
+        if (shouye.getMapRenderer() != null) {
+            shouye.getMapRenderer().setBoundaryPointsVisible(false);
+        }
+
+        closePreviewAndDispose();
+    }
+
+    private void persistStep3Inputs() {
+        String trimmedName = areaNameField.getText() != null ? areaNameField.getText().trim() : "";
+        dikuaiData.put("areaName", trimmedName);
+
+        if (mowingPatternCombo != null) {
+            Object selection = mowingPatternCombo.getSelectedItem();
+            if (selection != null) {
+                dikuaiData.put("mowingPattern", selection.toString());
+            }
+        }
+
+        // 淇濆瓨鍓茶崏瀹藉害锛堜粠鏂囨湰妗嗚幏鍙栵紝鍗曚綅锛氱背锛岃浆鎹负鍘樼背淇濆瓨锛�
+        if (mowingWidthField != null) {
+            String widthStr = mowingWidthField.getText().trim();
+            if (widthStr != null && !widthStr.isEmpty()) {
+                try {
+                    double widthMeters = Double.parseDouble(widthStr);
+                    double widthCm = widthMeters * 100.0;
+                    dikuaiData.put("mowingWidth", String.format(Locale.US, "%.2f", widthCm));
+                } catch (NumberFormatException e) {
+                    // 淇濇寔鍘熷��
+                    dikuaiData.put("mowingWidth", widthStr);
+                }
             }
         }
     }
+
+    private void captureSessionSnapshot() {
+        if (activeSession == null) {
+            activeSession = new DrawingSession();
+        }
+        String landNumber = getPendingLandNumber();
+        activeSession.landNumber = landNumber;
+        activeSession.areaName = areaNameField.getText() != null ? areaNameField.getText().trim() : "";
+        activeSession.drawingCompleted = true;
+        activeSession.data = new HashMap<>(dikuaiData);
+    }
+
+    private void closePreviewAndDispose() {
+        setVisible(false);
+        dispose();
+    }
     
     private JButton createPrimaryButton(String text, int fontSize) {
-        JButton button = new JButton(text);
+        JButton button = buttonset.createStyledButton(text, PRIMARY_COLOR);
         button.setFont(new Font("寰蒋闆呴粦", Font.BOLD, fontSize));
-        button.setBackground(PRIMARY_COLOR);
-        button.setForeground(WHITE);
         button.setBorder(BorderFactory.createCompoundBorder(
             BorderFactory.createLineBorder(PRIMARY_DARK, 2),
             BorderFactory.createEmptyBorder(12, 25, 12, 25)
         ));
-        button.setFocusPainted(false);
         button.setCursor(new Cursor(Cursor.HAND_CURSOR));
-        
-        // 鎸夐挳鎮仠鏁堟灉
+
         button.addMouseListener(new MouseAdapter() {
             @Override
             public void mouseEntered(MouseEvent e) {
                 if (button.isEnabled()) {
-                    button.setBackground(PRIMARY_DARK);
+                    // 濡傛灉鎸夐挳鍙敤锛岄紶鏍囨偓鍋滄椂鏄剧ず娣辩豢鑹�
+                    if (button.getBackground().equals(PRIMARY_COLOR)) {
+                        button.setBackground(PRIMARY_DARK);
+                    }
                 }
             }
-            
+
             @Override
             public void mouseExited(MouseEvent e) {
                 if (button.isEnabled()) {
-                    button.setBackground(PRIMARY_COLOR);
+                    // 濡傛灉鎸夐挳鍙敤锛岄紶鏍囩寮�鏃舵仮澶嶇豢鑹�
+                    if (!button.getBackground().equals(MEDIUM_GRAY)) {
+                        button.setBackground(PRIMARY_COLOR);
+                    }
+                } else {
+                    // 濡傛灉鎸夐挳涓嶅彲鐢紝淇濇寔鐏拌壊
+                    button.setBackground(MEDIUM_GRAY);
                 }
             }
         });
-        
+
         return button;
     }
+
+    private void showPathGenerationMessage(String message, boolean success) {
+        if (pathGenerationMessageArea == null || pathMessageWrapper == null) {
+            return;
+        }
+        String display = message == null ? "" : message.trim();
+        if (display.isEmpty()) {
+            dikuaiData.remove(KEY_PATH_MESSAGE_TEXT);
+            dikuaiData.remove(KEY_PATH_MESSAGE_SUCCESS);
+        } else {
+            dikuaiData.put(KEY_PATH_MESSAGE_TEXT, display);
+            dikuaiData.put(KEY_PATH_MESSAGE_SUCCESS, success ? "true" : "false");
+        }
+        pathGenerationMessageArea.setText(display);
+        Color borderColor = success ? PRIMARY_COLOR : ERROR_COLOR;
+        Color textColor = success ? PRIMARY_DARK : ERROR_COLOR;
+        Color backgroundColor = success ? PRIMARY_LIGHT : new Color(255, 235, 238);
+        pathGenerationMessageArea.setForeground(textColor);
+        pathMessageWrapper.setBackground(backgroundColor);
+        pathMessageWrapper.setBorder(BorderFactory.createCompoundBorder(
+            BorderFactory.createLineBorder(borderColor, 1),
+            BorderFactory.createEmptyBorder(12, 12, 12, 12)
+        ));
+        pathMessageWrapper.setVisible(!display.isEmpty());
+        pathMessageWrapper.revalidate();
+        pathMessageWrapper.repaint();
+    }
+
+    private void setPathAvailability(boolean available) {
+        boolean effective = available && currentStep == 3;
+        if (createButton != null) {
+            createButton.setEnabled(effective);
+        }
+        if (previewButton != null) {
+            boolean visible = previewButton.isVisible();
+            previewButton.setEnabled(effective && visible);
+        }
+    }
     
     private JPanel createButtonPanel() {
         JPanel buttonPanel = new JPanel();
@@ -1153,25 +1662,42 @@
         buttonPanel.setBackground(WHITE);
         buttonPanel.setBorder(BorderFactory.createEmptyBorder(20, 0, 0, 0));
 
-        prevButton = new JButton("涓婁竴姝�");
+        prevButton = buttonset.createStyledButton("涓婁竴姝�", MEDIUM_GRAY);
         prevButton.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 16));
-        prevButton.setBackground(MEDIUM_GRAY);
         prevButton.setForeground(TEXT_COLOR);
         prevButton.setBorder(BorderFactory.createCompoundBorder(
             BorderFactory.createLineBorder(BORDER_COLOR, 2),
             BorderFactory.createEmptyBorder(10, 25, 10, 25)
         ));
-        prevButton.setFocusPainted(false);
         prevButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
 
+        boundaryPreviewButton = createPrimaryButton("棰勮", 16);
+        boundaryPreviewButton.setVisible(false);
+        boundaryPreviewButton.setEnabled(false);
+        boundaryPreviewButton.addActionListener(e -> previewBoundary());
+
         nextButton = createPrimaryButton("涓嬩竴姝�", 16);
+        nextButton.setBackground(MEDIUM_GRAY); // 鍒濆鐏拌壊鑳屾櫙
+        nextButton.setEnabled(false); // 鍒濆涓嶅彲鐢�
+        
         createButton = createPrimaryButton("淇濆瓨", 16);
         createButton.setVisible(false);
-    createButton.setEnabled(false);
+        createButton.setEnabled(false);
+
+        previewButton = createPrimaryButton("棰勮", 16);
+        previewButton.setVisible(false);
+        previewButton.setEnabled(false);
+
+        previewButtonSpacer = Box.createHorizontalStrut(15);
+        previewButtonSpacer.setVisible(false);
 
         buttonPanel.add(prevButton);
         buttonPanel.add(Box.createHorizontalGlue());
+        buttonPanel.add(boundaryPreviewButton);
+        buttonPanel.add(Box.createHorizontalStrut(15));
         buttonPanel.add(nextButton);
+        buttonPanel.add(previewButtonSpacer);
+        buttonPanel.add(previewButton);
         buttonPanel.add(Box.createHorizontalStrut(15));
         buttonPanel.add(createButton);
 
@@ -1182,10 +1708,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);
     }
 
@@ -1206,6 +1742,11 @@
             dikuai.setLandArea(snapshot.areaSqMeters);
             dikuai.setBaseStationCoordinates(snapshot.baseStationCoordinates);
             dikuai.setUpdateTime(getCurrentTime());
+            // 璁$畻骞惰缃師濮嬭竟鐣孹Y鍧愭爣
+            String originalBoundaryXY = convertOriginalBoundaryToXY(snapshot.originalBoundary, snapshot.baseStationCoordinates);
+            if (originalBoundaryXY != null && !originalBoundaryXY.isEmpty()) {
+                dikuai.setBoundaryOriginalXY(originalBoundaryXY);
+            }
             Dikuai.putDikuai(landNumber, dikuai);
         }
 
@@ -1223,14 +1764,40 @@
         return true;
     }
 
-    private static String buildOriginalBoundaryString() {
-        if (Coordinate.coordinates == null || Coordinate.coordinates.isEmpty()) {
+    private static List<Coordinate> sanitizeCoordinateList(List<Coordinate> source) {
+        if (source == null || source.isEmpty()) {
+            return Collections.emptyList();
+        }
+
+        List<Coordinate> snapshot = new ArrayList<>();
+        for (Coordinate coordinate : source) {
+            if (coordinate != null) {
+                snapshot.add(coordinate);
+            }
+        }
+        if (snapshot.isEmpty()) {
+            return Collections.emptyList();
+        }
+
+        DecimalFormat latLonFormat = new DecimalFormat("0.000000");
+        LinkedHashMap<String, Coordinate> unique = new LinkedHashMap<>();
+        for (Coordinate coord : snapshot) {
+            double lat = convertToDecimalDegree(coord.getLatitude(), coord.getLatDirection());
+            double lon = convertToDecimalDegree(coord.getLongitude(), coord.getLonDirection());
+            String key = latLonFormat.format(lat) + "," + latLonFormat.format(lon);
+            unique.putIfAbsent(key, coord);
+        }
+        return new ArrayList<>(unique.values());
+    }
+
+    private static String buildOriginalBoundaryString(List<Coordinate> coordinates) {
+        if (coordinates == null || coordinates.isEmpty()) {
             return "-1";
         }
         StringBuilder sb = new StringBuilder();
         DecimalFormat latLonFormat = new DecimalFormat("0.000000");
         DecimalFormat elevationFormat = new DecimalFormat("0.00");
-        for (Coordinate coord : Coordinate.coordinates) {
+        for (Coordinate coord : coordinates) {
             double lat = convertToDecimalDegree(coord.getLatitude(), coord.getLatDirection());
             double lon = convertToDecimalDegree(coord.getLongitude(), coord.getLonDirection());
             double elevation = coord.getElevation();
@@ -1286,11 +1853,196 @@
         }
         return dikuai;
     }
+    
+    /**
+     * 灏嗗師濮嬭竟鐣屽潗鏍囷紙缁忕含搴︽牸寮忥級杞崲涓篨Y鍧愭爣
+     * @param originalBoundary 鍘熷杈圭晫鍧愭爣瀛楃涓诧紝鏍煎紡锛�"lat1,lon1,alt1;lat2,lon2,alt2;..."
+     * @param baseStationCoordinates 鍩哄噯绔欏潗鏍囷紝鏍煎紡锛�"lat,N/S,lon,E/W"
+     * @return XY鍧愭爣瀛楃涓诧紝鏍煎紡锛�"X0,Y0;X1,Y1;X2,Y2;..." 濡傛灉杞崲澶辫触杩斿洖null
+     */
+    private static String convertOriginalBoundaryToXY(String originalBoundary, String baseStationCoordinates) {
+        if (originalBoundary == null || originalBoundary.trim().isEmpty() || "-1".equals(originalBoundary.trim())) {
+            return null;
+        }
+        if (baseStationCoordinates == null || baseStationCoordinates.trim().isEmpty()) {
+            return null;
+        }
+        
+        try {
+            // 瑙f瀽鍩哄噯绔欏潗鏍�
+            String[] baseParts = baseStationCoordinates.trim().split(",");
+            if (baseParts.length != 4) {
+                return null;
+            }
+            double baseLat = convertToDecimalDegree(baseParts[0], baseParts[1]);
+            double baseLon = convertToDecimalDegree(baseParts[2], baseParts[3]);
+            
+            // 瑙f瀽鍘熷杈圭晫鍧愭爣
+            String[] points = originalBoundary.split(";");
+            StringBuilder xyStr = new StringBuilder();
+            
+            for (int i = 0; i < points.length; i++) {
+                String point = points[i].trim();
+                if (point.isEmpty()) {
+                    continue;
+                }
+                
+                String[] coords = point.split(",");
+                if (coords.length >= 2) {
+                    try {
+                        double lat = Double.parseDouble(coords[0].trim());
+                        double lon = Double.parseDouble(coords[1].trim());
+                        
+                        // 杞崲涓篨Y鍧愭爣
+                        double[] xy = publicway.Gpstoxuzuobiao.convertLatLonToLocal(lat, lon, baseLat, baseLon);
+                        if (xy != null && xy.length >= 2) {
+                            if (xyStr.length() > 0) {
+                                xyStr.append(";");
+                            }
+                            xyStr.append(String.format(Locale.US, "%.3f,%.3f", xy[0], xy[1]));
+                        }
+                    } catch (NumberFormatException e) {
+                        // 璺宠繃鏃犳晥鐨勫潗鏍囩偣
+                        continue;
+                    }
+                }
+            }
+            
+            return xyStr.length() > 0 ? xyStr.toString() : null;
+        } catch (Exception e) {
+            System.err.println("杞崲鍘熷杈圭晫鍧愭爣鍒癤Y澶辫触: " + e.getMessage());
+            return null;
+        }
+    }
+    
+    /**
+     * 棰勮杈圭晫
+     */
+    private void previewBoundary() {
+        if (!dikuaiData.containsKey("boundaryDrawn")) {
+            JOptionPane.showMessageDialog(this, "璇峰厛瀹屾垚杈圭晫缁樺埗鍚庡啀棰勮", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+        
+        // 鑾峰彇鎴栧垱寤哄湴鍧楀璞�
+        String landNumber = getPendingLandNumber();
+        Dikuai dikuai = getOrCreatePendingDikuai();
+        if (dikuai == null) {
+            JOptionPane.showMessageDialog(this, "鏃犳硶鑾峰彇鍦板潡淇℃伅", "閿欒", JOptionPane.ERROR_MESSAGE);
+            return;
+        }
+        
+        // 纭繚鍦板潡鏁版嵁鏄渶鏂扮殑
+        String optimizedBoundaryXY = dikuaiData.get("optimizedBoundaryXY");
+        if (optimizedBoundaryXY == null || optimizedBoundaryXY.isEmpty() || optimizedBoundaryXY.startsWith("ERROR")) {
+            // 濡傛灉娌℃湁浼樺寲鍚庣殑杈圭晫锛屽皾璇曚粠boundaryCoordinates鑾峰彇
+            String boundaryCoords = dikuaiData.get("boundaryCoordinates");
+            if (boundaryCoords != null && !boundaryCoords.isEmpty() && !"-1".equals(boundaryCoords)) {
+                optimizedBoundaryXY = boundaryCoords;
+            } else {
+                // 灏濊瘯浠庡湴鍧楀璞¤幏鍙�
+                optimizedBoundaryXY = dikuai.getBoundaryCoordinates();
+            }
+        }
+        
+        if (optimizedBoundaryXY == null || optimizedBoundaryXY.isEmpty() || "-1".equals(optimizedBoundaryXY)) {
+            JOptionPane.showMessageDialog(this, "鏈壘鍒版湁鏁堢殑杈圭晫鍧愭爣锛屾棤娉曢瑙�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+        
+        // 纭繚鍘熷杈圭晫XY鍧愭爣宸茶绠�
+        String originalBoundaryXY = dikuai.getBoundaryOriginalXY();
+        if (originalBoundaryXY == null || originalBoundaryXY.isEmpty() || "-1".equals(originalBoundaryXY)) {
+            // 璁$畻鍘熷杈圭晫XY鍧愭爣
+            String originalBoundary = dikuaiData.get("boundaryOriginalCoordinates");
+            String baseStationCoordinates = dikuaiData.get("baseStationCoordinates");
+            if (originalBoundary != null && baseStationCoordinates != null) {
+                originalBoundaryXY = convertOriginalBoundaryToXY(originalBoundary, baseStationCoordinates);
+                if (originalBoundaryXY != null && !originalBoundaryXY.isEmpty()) {
+                    dikuai.setBoundaryOriginalXY(originalBoundaryXY);
+                    Dikuai.putDikuai(landNumber, dikuai);
+                }
+            }
+        }
+        
+        // 淇濆瓨浼氳瘽蹇収
+        captureSessionSnapshot();
+        
+        // 鍒涘缓final鍙橀噺渚沴ambda浣跨敤
+        final String finalOptimizedBoundaryXY = optimizedBoundaryXY;
+        final Dikuai finalDikuai = dikuai;
+        
+        // 鍏抽棴瀵硅瘽妗�
+        setVisible(false);
+        dispose();
+        
+        // 璋冪敤棣栭〉鏄剧ず棰勮锛堜笌杈圭晫绠$悊椤甸潰閫昏緫涓�鑷达級
+        SwingUtilities.invokeLater(() -> {
+            Shouye.showBoundaryPreview(finalDikuai, finalOptimizedBoundaryXY, () -> {
+                // 杩斿洖鍥炶皟锛氶噸鏂版墦寮�鏂板鍦板潡瀵硅瘽妗嗭紝骞舵樉绀烘楠�2
+                Component parent = Shouye.getInstance();
+                if (parent != null) {
+                    // 纭繚浼氳瘽鐘舵�佹纭紝浠ヤ究杩斿洖鏃舵樉绀烘楠�2
+                    if (activeSession != null && activeSession.drawingCompleted) {
+                        resumeRequested = true;
+                    }
+                    showAddDikuaiDialog(parent);
+                }
+            });
+        });
+    }
 
     private void hideBoundaryPointSummary() {
         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() {
@@ -1334,8 +2086,14 @@
     }
 
     private static BoundarySnapshotResult computeBoundarySnapshot() {
-        int count = Coordinate.coordinates != null ? Coordinate.coordinates.size() : 0;
-        if (count < 3) {
+        List<Coordinate> uniqueCoordinates;
+        synchronized (Coordinate.coordinates) {
+            uniqueCoordinates = sanitizeCoordinateList(Coordinate.coordinates);
+            Coordinate.coordinates.clear();
+            Coordinate.coordinates.addAll(uniqueCoordinates);
+        }
+
+        if (uniqueCoordinates.size() < 3) {
             return BoundarySnapshotResult.failure("閲囬泦鐨勮竟鐣岀偣涓嶈冻锛屾棤娉曠敓鎴愬湴鍧楄竟鐣�", JOptionPane.WARNING_MESSAGE);
         }
 
@@ -1344,22 +2102,28 @@
             return BoundarySnapshotResult.failure("褰撳墠鍦板潡闈㈢Н涓�0锛屾棤娉曠户缁�", JOptionPane.WARNING_MESSAGE);
         }
 
-        Device device = new Device();
-        device.initFromProperties();
-        String baseStationCoordinates = normalizeCoordinateValue(device.getBaseStationCoordinates());
+    BaseStation baseStation = new BaseStation();
+    baseStation.load();
+    String baseStationCoordinates = normalizeCoordinateValue(baseStation.getInstallationCoordinates());
         if (!isMeaningfulValue(baseStationCoordinates)) {
             return BoundarySnapshotResult.failure("鏈幏鍙栧埌鏈夋晥鐨勫熀鍑嗙珯鍧愭爣锛岃鍏堝湪鍩哄噯绔欑鐞嗕腑璁剧疆", JOptionPane.WARNING_MESSAGE);
         }
 
         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();
+    String originalBoundary = buildOriginalBoundaryString(uniqueCoordinates);
         DecimalFormat areaFormat = new DecimalFormat("0.00");
         String areaString = areaFormat.format(area);
 
@@ -1407,6 +2171,10 @@
         
         // 鍒涘缓鍦板潡鎸夐挳
         createButton.addActionListener(e -> createDikuai());
+
+        if (previewButton != null) {
+            previewButton.addActionListener(e -> previewMowingPath());
+        }
         
         // 鍏抽棴瀵硅瘽妗�
         addWindowListener(new WindowAdapter() {
@@ -1423,6 +2191,8 @@
         
         if (step == 1) {
             updateObstacleSummary();
+            // 姝ラ1鏄剧ず鏃讹紝绔嬪嵆鏇存柊鎸夐挳鐘舵��
+            SwingUtilities.invokeLater(() -> updateStep1ButtonState());
         }
 
         // 鏇存柊鎸夐挳鐘舵��
@@ -1435,11 +2205,61 @@
         if (step < 3) {
             nextButton.setVisible(true);
             createButton.setVisible(false);
-            createButton.setEnabled(false);
+            setPathAvailability(false);
+            if (previewButton != null) {
+                previewButton.setVisible(false);
+                previewButton.setEnabled(false);
+            }
+            if (previewButtonSpacer != null) {
+                previewButtonSpacer.setVisible(false);
+            }
+            // 姝ラ1锛氭牴鎹獙璇佺粨鏋滄洿鏂颁笅涓�姝ユ寜閽姸鎬�
+            if (step == 1) {
+                updateStep1ButtonState();
+            }
+            // 姝ラ2鏄剧ず杈圭晫棰勮鎸夐挳
+            if (step == 2) {
+                if (boundaryPreviewButton != null) {
+                    boundaryPreviewButton.setVisible(true);
+                    // 鏍规嵁鏄惁瀹屾垚杈圭晫缁樺埗鏉ヨ缃寜閽姸鎬佸拰鑳屾櫙棰滆壊
+                    boolean boundaryDrawn = dikuaiData.containsKey("boundaryDrawn");
+                    boundaryPreviewButton.setEnabled(boundaryDrawn);
+                    if (boundaryDrawn) {
+                        boundaryPreviewButton.setBackground(PRIMARY_COLOR); // 缁胯壊鑳屾櫙
+                    } else {
+                        boundaryPreviewButton.setBackground(MEDIUM_GRAY); // 鐏拌壊鑳屾櫙
+                    }
+                }
+                // 鏇存柊涓嬩竴姝ユ寜閽姸鎬侊紙鏍规嵁鏄惁瀹屾垚杈圭晫缁樺埗锛�
+                boolean boundaryDrawn = dikuaiData.containsKey("boundaryDrawn");
+                nextButton.setEnabled(boundaryDrawn);
+                if (boundaryDrawn) {
+                    nextButton.setBackground(PRIMARY_COLOR); // 缁胯壊鑳屾櫙
+                } else {
+                    nextButton.setBackground(MEDIUM_GRAY); // 鐏拌壊鑳屾櫙
+                }
+                // 鏇存柊寮�濮嬬粯鍒舵寜閽姸鎬�
+                updateStartDrawingButtonState();
+            } else {
+                if (boundaryPreviewButton != null) {
+                    boundaryPreviewButton.setVisible(false);
+                    boundaryPreviewButton.setEnabled(false);
+                }
+            }
         } else {
             nextButton.setVisible(false);
             createButton.setVisible(true);
-            createButton.setEnabled(hasGeneratedPath());
+            if (previewButton != null) {
+                previewButton.setVisible(true);
+            }
+            if (previewButtonSpacer != null) {
+                previewButtonSpacer.setVisible(true);
+            }
+            if (boundaryPreviewButton != null) {
+                boundaryPreviewButton.setVisible(false);
+                boundaryPreviewButton.setEnabled(false);
+            }
+            setPathAvailability(hasGeneratedPath());
         }
 
         Container parent = prevButton.getParent();
@@ -1449,6 +2269,85 @@
         }
     }
     
+    /**
+     * 鏇存柊姝ラ1鐨勪笅涓�姝ユ寜閽姸鎬�
+     * 鏍规嵁鍦板潡鍚嶇О鏄惁濉啓鏉ヨ缃寜閽殑鍚敤鐘舵�佸拰鑳屾櫙棰滆壊
+     */
+    private void updateStep1ButtonState() {
+        if (nextButton == null || currentStep != 1) {
+            return;
+        }
+        
+        String name = areaNameField.getText().trim();
+        boolean canProceed = !name.isEmpty();
+        
+        nextButton.setEnabled(canProceed);
+        if (canProceed) {
+            // 鍙偣鍑绘椂锛氱豢鑹茶儗鏅�
+            nextButton.setBackground(PRIMARY_COLOR);
+        } else {
+            // 涓嶅彲鐐瑰嚮鏃讹細鐏拌壊鑳屾櫙
+            nextButton.setBackground(MEDIUM_GRAY);
+        }
+    }
+    
+    /**
+     * 鏇存柊姝ラ2鐨勫紑濮嬬粯鍒舵寜閽姸鎬�
+     * 鏍规嵁鏄惁閫夋嫨浜嗙粯鍒舵柟寮忔潵璁剧疆鎸夐挳鐨勫惎鐢ㄧ姸鎬佸拰鑳屾櫙棰滆壊
+     */
+    private void updateStartDrawingButtonState() {
+        if (startEndDrawingBtn == null || currentStep != 2) {
+            return;
+        }
+        
+        boolean hasSelectedMethod = dikuaiData.containsKey("drawingMethod");
+        boolean isDrawingActive = isDrawing;
+        
+        // 濡傛灉姝e湪缁樺埗锛屾寜閽姸鎬佺敱toggleDrawing鏂规硶鎺у埗
+        if (isDrawingActive) {
+            return;
+        }
+        
+        // 濡傛灉宸茬粡瀹屾垚缁樺埗锛屾寜閽樉绀�"宸插畬鎴�"涓斾笉鍙敤
+        boolean boundaryDrawn = dikuaiData.containsKey("boundaryDrawn");
+        if (boundaryDrawn) {
+            startEndDrawingBtn.setEnabled(false);
+            startEndDrawingBtn.setBackground(MEDIUM_GRAY);
+            return;
+        }
+        
+        startEndDrawingBtn.setEnabled(hasSelectedMethod);
+        if (hasSelectedMethod) {
+            // 宸查�夋嫨缁樺埗鏂瑰紡锛氱豢鑹茶儗鏅紝鍙偣鍑�
+            startEndDrawingBtn.setBackground(PRIMARY_COLOR);
+        } else {
+            // 鏈�夋嫨缁樺埗鏂瑰紡锛氱伆鑹茶儗鏅紝涓嶅彲鐐瑰嚮
+            startEndDrawingBtn.setBackground(MEDIUM_GRAY);
+        }
+    }
+    
+    /**
+     * 鏇存柊姝ラ2鐨勯瑙堝拰涓嬩竴姝ユ寜閽姸鎬侊紙鍦ㄥ畬鎴愯竟鐣岀粯鍒跺悗璋冪敤锛�
+     * 灏嗘寜閽儗鏅鑹茶缃负缁胯壊锛岃〃绀哄彲浠ョ偣鍑绘搷浣�
+     */
+    private void updateStep2ButtonsAfterDrawing() {
+        if (currentStep != 2) {
+            return;
+        }
+        
+        // 鏇存柊棰勮鎸夐挳
+        if (boundaryPreviewButton != null) {
+            boundaryPreviewButton.setEnabled(true);
+            boundaryPreviewButton.setBackground(PRIMARY_COLOR); // 缁胯壊鑳屾櫙
+        }
+        
+        // 鏇存柊涓嬩竴姝ユ寜閽�
+        if (nextButton != null) {
+            nextButton.setEnabled(true);
+            nextButton.setBackground(PRIMARY_COLOR); // 缁胯壊鑳屾櫙
+        }
+    }
+    
     private boolean validateCurrentStep() {
         switch (currentStep) {
             case 1:
@@ -1481,7 +2380,20 @@
 
             case 3:
                 dikuaiData.put("mowingPattern", (String) mowingPatternCombo.getSelectedItem());
-                dikuaiData.put("mowingWidth", mowingWidthSpinner.getValue().toString());
+                // 淇濆瓨鍓茶崏瀹藉害锛堜粠鏂囨湰妗嗚幏鍙栵紝鍗曚綅锛氱背锛岃浆鎹负鍘樼背淇濆瓨锛�
+                if (mowingWidthField != null) {
+                    String widthStr = mowingWidthField.getText().trim();
+                    if (widthStr != null && !widthStr.isEmpty()) {
+                        try {
+                            double widthMeters = Double.parseDouble(widthStr);
+                            double widthCm = widthMeters * 100.0;
+                            dikuaiData.put("mowingWidth", String.format(Locale.US, "%.2f", widthCm));
+                        } catch (NumberFormatException e) {
+                            // 淇濇寔鍘熷��
+                            dikuaiData.put("mowingWidth", widthStr);
+                        }
+                    }
+                }
                 if (!hasGeneratedPath()) {
                     JOptionPane.showMessageDialog(this, "璇峰厛鐢熸垚鍓茶崏璺緞", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
                     return false;
@@ -1711,7 +2623,7 @@
         if (method != null) {
             JPanel panel = drawingOptionPanels.get(method);
             if (panel != null) {
-                selectDrawingOption(panel, method);
+                selectDrawingOption(panel, method, false);
             }
         }
 
@@ -1726,6 +2638,9 @@
             isDrawing = false;
             showStep(2);
             showBoundaryPointSummary();
+            updateBoundaryXYDisplay();
+            // 鏇存柊棰勮鍜屼笅涓�姝ユ寜閽姸鎬侊紙鑳屾櫙棰滆壊鍙樼豢鑹诧紝鍙偣鍑伙級
+            updateStep2ButtonsAfterDrawing();
         } else {
             if (startEndDrawingBtn != null) {
                 startEndDrawingBtn.setText("寮�濮嬬粯鍒�");
@@ -1736,6 +2651,83 @@
             showStep(1);
             hideBoundaryPointSummary();
         }
+
+        restoreGeneratedPathState(session);
+    }
+
+    private void restoreGeneratedPathState(DrawingSession session) {
+        if (session == null || session.data == null) {
+            showPathGenerationMessage("", true);
+            return;
+        }
+
+        Map<String, String> data = session.data;
+
+        if (mowingPatternCombo != null) {
+            String pattern = data.get("mowingPattern");
+            if (pattern != null) {
+                ComboBoxModel<String> model = mowingPatternCombo.getModel();
+                for (int i = 0; i < model.getSize(); i++) {
+                    String candidate = model.getElementAt(i);
+                    if (pattern.equals(candidate)) {
+                        mowingPatternCombo.setSelectedIndex(i);
+                        break;
+                    }
+                }
+            }
+        }
+
+        // 鎭㈠鍓茶崏瀹藉害锛氫粠淇濆瓨鐨勫壊鑽夊搴︼紙鍘樼背锛夎浆鎹负绫冲苟璁剧疆
+        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) {
+                // 淇濇寔褰撳墠鍊�
+            }
+        }
+        
+        // 鎭㈠鍓插垁瀹藉害锛氫粠淇濆瓨鐨勫壊鑽夊搴﹀弽鎺ㄥ壊鍒�瀹藉害骞惰缃�
+        // 鐢变簬鍓茶崏瀹藉害 = 鍓插垁瀹藉害 * 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) {
+                // 淇濇寔褰撳墠鍊�
+            }
+        }
+
+        boolean hasPath = isMeaningfulValue(data.get("plannedPath"));
+        if (!hasPath) {
+            showPathGenerationMessage("", true);
+            if (currentStep == 3) {
+                setPathAvailability(false);
+            }
+            return;
+        }
+
+        String message = data.get(KEY_PATH_MESSAGE_TEXT);
+        boolean success = !"false".equalsIgnoreCase(data.get(KEY_PATH_MESSAGE_SUCCESS));
+        showStep(3);
+        if (isMeaningfulValue(message)) {
+            showPathGenerationMessage(message, success);
+        } else {
+            showPathGenerationMessage("宸茬敓鎴愬壊鑽夎矾寰勶紝鍙偣鍑烩�滈瑙堚�濇寜閽煡鐪嬫晥鏋溿��", true);
+        }
+        setPathAvailability(true);
     }
 
     public static void finishDrawingSession() {
@@ -1769,6 +2761,19 @@
         Component parent = shouye != null ? shouye : null;
         showAddDikuaiDialog(parent);
     }
+
+    public static void resumeFromPreview() {
+        Shouye shouye = Shouye.getInstance();
+        if (shouye != null) {
+            shouye.exitMowingPathPreview();
+        }
+        if (activeSession == null) {
+            return;
+        }
+        resumeRequested = true;
+        Component parent = shouye != null ? shouye : null;
+        SwingUtilities.invokeLater(() -> showAddDikuaiDialog(parent));
+    }
     
     private void createDikuai() {
         if (!validateCurrentStep()) {
@@ -1807,10 +2812,70 @@
         if (dikuaiData.containsKey("mowingPattern")) {
             dikuai.setMowingPattern(dikuaiData.get("mowingPattern"));
         }
-        if (dikuaiData.containsKey("mowingWidth")) {
+        
+        // 淇濆瓨鍓茶崏瀹藉害锛堜粠鏂囨湰妗嗚幏鍙栵紝鍗曚綅锛氱背锛岃浆鎹负鍘樼背淇濆瓨锛�
+        if (mowingWidthField != null) {
+            String mowingWidthStr = mowingWidthField.getText().trim();
+            if (mowingWidthStr != null && !mowingWidthStr.isEmpty()) {
+                try {
+                    double mowingWidthMeters = Double.parseDouble(mowingWidthStr);
+                    // 杞崲涓哄帢绫充繚瀛�
+                    double mowingWidthCm = mowingWidthMeters * 100.0;
+                    dikuai.setMowingWidth(String.format(Locale.US, "%.2f", mowingWidthCm));
+                } catch (NumberFormatException e) {
+                    // 濡傛灉瑙f瀽澶辫触锛屽皾璇曚娇鐢╠ikuaiData涓殑鍊�
+                    if (dikuaiData.containsKey("mowingWidth")) {
+                        dikuai.setMowingWidth(dikuaiData.get("mowingWidth"));
+                    }
+                }
+            } else if (dikuaiData.containsKey("mowingWidth")) {
+                dikuai.setMowingWidth(dikuaiData.get("mowingWidth"));
+            }
+        } else if (dikuaiData.containsKey("mowingWidth")) {
             dikuai.setMowingWidth(dikuaiData.get("mowingWidth"));
         }
+        
+        // 淇濆瓨鍓茶崏鏈哄壊鍒�瀹藉害锛堜粠鏂囨湰妗嗚幏鍙栵紝鍗曚綅锛氱背锛�
+        if (bladeWidthField != null) {
+            String bladeWidthStr = bladeWidthField.getText().trim();
+            if (bladeWidthStr != null && !bladeWidthStr.isEmpty()) {
+                try {
+                    double bladeWidthMeters = Double.parseDouble(bladeWidthStr);
+                    // 淇濆瓨涓虹背锛屼繚鐣�2浣嶅皬鏁�
+                    dikuai.setMowingBladeWidth(String.format(Locale.US, "%.2f", bladeWidthMeters));
+                } catch (NumberFormatException e) {
+                    // 瑙f瀽澶辫触鏃讹紝淇濆瓨鍘熷瀛楃涓�
+                    dikuai.setMowingBladeWidth(bladeWidthStr);
+                }
+            }
+        }
+        
+        // 淇濆瓨鍓茶崏瀹夊叏璺濈锛堜粠鏂囨湰妗嗚幏鍙栵紝鍗曚綅锛氱背锛�
+        if (safetyDistanceField != null) {
+            String safetyDistanceStr = safetyDistanceField.getText().trim();
+            if (safetyDistanceStr != null && !safetyDistanceStr.isEmpty()) {
+                try {
+                    double safetyDistanceMeters = Double.parseDouble(safetyDistanceStr);
+                    // 淇濆瓨涓虹背锛屼繚鐣�2浣嶅皬鏁�
+                    String formattedValue = String.format(Locale.US, "%.2f", safetyDistanceMeters);
+                    dikuai.setMowingSafetyDistance(formattedValue);
+                    // 鍚屾椂淇濆瓨鍒癲ikuaiData涓紝浠ヤ究鍚庣画浣跨敤
+                    dikuaiData.put("mowingSafetyDistance", formattedValue);
+                } catch (NumberFormatException e) {
+                    // 瑙f瀽澶辫触鏃讹紝淇濆瓨鍘熷瀛楃涓�
+                    dikuai.setMowingSafetyDistance(safetyDistanceStr);
+                    dikuaiData.put("mowingSafetyDistance", safetyDistanceStr);
+                }
+            } else if (dikuaiData.containsKey("mowingSafetyDistance")) {
+                // 濡傛灉鏂囨湰妗嗕负绌猴紝灏濊瘯浠巇ikuaiData鑾峰彇
+                dikuai.setMowingSafetyDistance(dikuaiData.get("mowingSafetyDistance"));
+            }
+        } else if (dikuaiData.containsKey("mowingSafetyDistance")) {
+            // 濡傛灉safetyDistanceField涓簄ull锛屼粠dikuaiData鑾峰彇
+            dikuai.setMowingSafetyDistance(dikuaiData.get("mowingSafetyDistance"));
+        }
 
+        // 淇濆瓨鍓茶崏璺緞鍧愭爣
         String plannedPath = dikuaiData.get("plannedPath");
         if (isMeaningfulValue(plannedPath)) {
             dikuai.setPlannedPath(plannedPath);
@@ -1865,6 +2930,13 @@
         if (resumeRequested && activeSession != null) {
             dialog.applySessionData(activeSession);
             resumeRequested = false;
+            // 濡傛灉浼氳瘽宸茬敓鎴愯矾寰勶紝浼樺厛鏄剧ず姝ラ3
+            if (activeSession.data != null && isMeaningfulValue(activeSession.data.get("plannedPath"))) {
+                dialog.showStep(3);
+            } else if (activeSession.drawingCompleted) {
+                // 濡傛灉浼氳瘽宸插畬鎴愮粯鍒讹紝鏄剧ず姝ラ2
+                dialog.showStep(2);
+            }
         }
         
         dialog.setVisible(true);

--
Gitblit v1.10.0