From b315a6943e6c0d6bdf0d5f7565c570d719154d6c Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期三, 17 十二月 2025 14:56:58 +0800
Subject: [PATCH] 新增了障碍物管理页面

---
 src/lujing/MowingPathGenerationPage.java |  121 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 121 insertions(+), 0 deletions(-)

diff --git a/src/lujing/MowingPathGenerationPage.java b/src/lujing/MowingPathGenerationPage.java
index 8f96af2..5c080b0 100644
--- a/src/lujing/MowingPathGenerationPage.java
+++ b/src/lujing/MowingPathGenerationPage.java
@@ -1,6 +1,7 @@
 package lujing;
 
 import javax.swing.*;
+import javax.swing.SwingUtilities;
 import java.awt.*;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
@@ -143,14 +144,17 @@
         buttonPanel.setBackground(BACKGROUND_COLOR);
         
         JButton generateBtn = createPrimaryFooterButton("鐢熸垚鍓茶崏璺緞");
+        JButton previewBtn = createPrimaryFooterButton("棰勮");
         JButton saveBtn = createPrimaryFooterButton("淇濆瓨璺緞");
         JButton cancelBtn = createPrimaryFooterButton("鍙栨秷");
         
         generateBtn.addActionListener(e -> generatePath(modeValue));
+        previewBtn.addActionListener(e -> previewPath());
         saveBtn.addActionListener(e -> savePath());
         cancelBtn.addActionListener(e -> dispose());
         
         buttonPanel.add(generateBtn);
+        buttonPanel.add(previewBtn);
         buttonPanel.add(saveBtn);
         buttonPanel.add(cancelBtn);
         add(buttonPanel, BorderLayout.SOUTH);
@@ -187,6 +191,123 @@
     }
     
     /**
+     * 棰勮璺緞
+     */
+    private void previewPath() {
+        // 鍏堜繚瀛樺綋鍓嶈矾寰勫埌鍦板潡锛堜复鏃朵繚瀛橈紝鐢ㄤ簬棰勮锛�
+        String pathNormalized = normalizeCoordinateInput(pathArea.getText());
+        if (!"-1".equals(pathNormalized)) {
+            pathNormalized = pathNormalized
+                .replace("\r\n", ";")
+                .replace('\r', ';')
+                .replace('\n', ';')
+                .replaceAll(";+", ";")
+                .replaceAll("\\s*;\\s*", ";")
+                .trim();
+            if (pathNormalized.isEmpty()) {
+                pathNormalized = "-1";
+            }
+        }
+        
+        if ("-1".equals(pathNormalized)) {
+            JOptionPane.showMessageDialog(this, "璇峰厛鐢熸垚鍓茶崏璺緞", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
+            return;
+        }
+        
+        // 涓存椂淇濆瓨璺緞鍒板湴鍧楀璞★紙涓嶆寔涔呭寲锛�
+        if (saveCallback != null) {
+            saveCallback.savePlannedPath(dikuai, pathNormalized);
+        }
+        
+        // 淇濆瓨褰撳墠椤甸潰鐘舵�侊紝鐢ㄤ簬杩斿洖鏃舵仮澶�
+        String currentBaseStation = baseStationField.getText();
+        String currentBoundary = boundaryArea.getText();
+        String currentObstacle = obstacleArea.getText();
+        String currentWidth = widthField.getText();
+        String currentPath = pathArea.getText();
+        
+        // 鑾峰彇鍦板潡淇℃伅
+        String landNumber = dikuai.getLandNumber();
+        String landName = dikuai.getLandName();
+        
+        // 澶勭悊杈圭晫鍧愭爣锛岀‘淇濆彉閲忔槸 effectively final
+        String boundaryInput = normalizeCoordinateInput(boundaryArea.getText());
+        final String boundary;
+        if (!"-1".equals(boundaryInput)) {
+            String processed = boundaryInput.replace("\r\n", ";")
+                .replace('\r', ';')
+                .replace('\n', ';')
+                .replaceAll(";+", ";")
+                .replaceAll("\\s*;\\s*", ";")
+                .trim();
+            if (processed.isEmpty()) {
+                boundary = dikuai.getBoundaryCoordinates();
+            } else {
+                boundary = processed;
+            }
+        } else {
+            boundary = dikuai.getBoundaryCoordinates();
+        }
+        
+        // 澶勭悊闅滅鐗╁潗鏍囷紝纭繚鍙橀噺鏄� effectively final
+        String obstaclesInput = normalizeCoordinateInput(obstacleArea.getText());
+        final String obstacles;
+        if (!"-1".equals(obstaclesInput)) {
+            String processed = obstaclesInput.replace("\r\n", " ")
+                .replace('\r', ' ')
+                .replace('\n', ' ')
+                .replaceAll("\\s{2,}", " ")
+                .trim();
+            if (processed.isEmpty()) {
+                obstacles = null;
+            } else {
+                obstacles = processed;
+            }
+        } else {
+            obstacles = null;
+        }
+        
+        // 淇濆瓨鏈�缁堝�煎埌 final 鍙橀噺锛屼互渚垮湪 lambda 涓娇鐢�
+        final String finalPathNormalized = pathNormalized;
+        final String finalLandNumber = landNumber;
+        final String finalLandName = landName;
+        
+        // 鍏抽棴璺緞瑙勫垝椤甸潰
+        setVisible(false);
+        
+        // 鎵撳紑涓婚〉闈㈠苟鏄剧ず璺緞棰勮
+        SwingUtilities.invokeLater(() -> {
+            zhuye.Shouye shouye = zhuye.Shouye.getInstance();
+            if (shouye != null) {
+                // 鏄剧ず璺緞棰勮锛屽苟璁剧疆杩斿洖鍥炶皟
+                shouye.startMowingPathPreview(
+                    finalLandNumber,
+                    finalLandName,
+                    boundary,
+                    obstacles,
+                    finalPathNormalized,
+                    () -> {
+                        // 杩斿洖鍥炶皟锛氶噸鏂版墦寮�璺緞瑙勫垝椤甸潰
+                        SwingUtilities.invokeLater(() -> {
+                            setVisible(true);
+                            // 鎭㈠涔嬪墠鐨勭姸鎬�
+                            baseStationField.setText(currentBaseStation);
+                            boundaryArea.setText(currentBoundary);
+                            obstacleArea.setText(currentObstacle);
+                            widthField.setText(currentWidth);
+                            pathArea.setText(currentPath);
+                        });
+                    }
+                );
+            } else {
+                // 濡傛灉涓婚〉闈笉瀛樺湪锛屾彁绀虹敤鎴峰苟閲嶆柊鏄剧ず璺緞瑙勫垝椤甸潰
+                JOptionPane.showMessageDialog(null, "鏃犳硶鎵撳紑涓婚〉闈㈣繘琛岄瑙�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+                setVisible(true);
+            }
+        });
+    }
+    
+    /**
      * 淇濆瓨璺緞
      */
     private void savePath() {

--
Gitblit v1.10.0