From 1175f5fbe8fd832943880bfc37c0e2a451a0688a Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期四, 25 十二月 2025 19:34:38 +0800
Subject: [PATCH] 删除了几个类优化了路径生成的逻辑

---
 src/lujing/MowingPathGenerationPage.java |  531 +++++++++++++++++++++++++++++++---------------------------
 1 files changed, 287 insertions(+), 244 deletions(-)

diff --git a/src/lujing/MowingPathGenerationPage.java b/src/lujing/MowingPathGenerationPage.java
index 73a8fde..8bd2ba9 100644
--- a/src/lujing/MowingPathGenerationPage.java
+++ b/src/lujing/MowingPathGenerationPage.java
@@ -1,26 +1,12 @@
 package lujing;
-
 import javax.swing.*;
 import javax.swing.SwingUtilities;
 import java.awt.*;
-import java.awt.datatransfer.Clipboard;
-import java.awt.datatransfer.StringSelection;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.ArrayList;
 import java.util.List;
-
 import dikuai.Dikuai;
-import lujing.Lunjingguihua;
-import lujing.ObstaclePathPlanner;
-import lujing.Qufenxingzhuang;
-import lujing.AoxinglujingNoObstacle;
-import lujing.YixinglujingNoObstacle;
-import lujing.AoxinglujingHaveObstacel;
-import lujing.YixinglujingHaveObstacel;
-import org.locationtech.jts.geom.Coordinate;
+import publicway.Fuzhibutton;
 import gecaoji.Device;
 import java.util.Locale;
 
@@ -50,6 +36,7 @@
         boolean saveObstacleCoordinates(Dikuai dikuai, String baseStationValue, String obstacleValue);
         boolean saveMowingWidth(Dikuai dikuai, String value);
         boolean savePlannedPath(Dikuai dikuai, String value);
+        boolean saveMowingSafetyDistance(Dikuai dikuai, String value);
     }
     
     private final Dikuai dikuai;
@@ -126,32 +113,65 @@
         
         // 鍦板潡杈圭晫
         boundaryArea = createInfoTextArea(boundaryValue != null ? boundaryValue : "", true, 6);
-        contentPanel.add(createTextAreaSection("鍦板潡杈圭晫", boundaryArea));
+        String boundaryTitle = "鍦板潡杈圭晫";
+        if (boundaryValue != null && !boundaryValue.trim().isEmpty() && !"-1".equals(boundaryValue.trim())) {
+            int boundaryCount = boundaryValue.split(";").length;
+            boundaryTitle = "鍦板潡杈圭晫 (" + boundaryCount + "鐐�)";
+        }
+        contentPanel.add(createTextAreaSection(boundaryTitle, boundaryArea));
         
         // 闅滅鐗╁潗鏍�
         obstacleArea = createInfoTextArea(obstacleValue != null ? obstacleValue : "", true, 6);
-        contentPanel.add(createTextAreaSection("闅滅鐗╁潗鏍�", obstacleArea));
+        String obstacleTitle = "闅滅鐗╁潗鏍�";
+        if (obstacleValue != null && !obstacleValue.trim().isEmpty() && !"-1".equals(obstacleValue.trim())) {
+            // 闅滅鐗╁潗鏍囨牸寮忓彲鑳芥槸绌烘牸鍒嗛殧鐨勫涓殰纰嶇墿锛屾瘡涓殰纰嶇墿鐢ㄥ垎鍙峰垎闅斿潗鏍囩偣
+            // 璁$畻鎵�鏈夐殰纰嶇墿鐨勬�诲潗鏍囩偣鏁�
+            String[] obstacles = obstacleValue.trim().split("\\s+");
+            int totalObstaclePoints = 0;
+            for (String obstacle : obstacles) {
+                if (obstacle != null && !obstacle.trim().isEmpty()) {
+                    totalObstaclePoints += obstacle.split(";").length;
+                }
+            }
+            if (totalObstaclePoints > 0) {
+                obstacleTitle = "闅滅鐗╁潗鏍� (" + totalObstaclePoints + "鐐�)";
+            }
+        }
+        contentPanel.add(createTextAreaSection(obstacleTitle, obstacleArea));
         
         // 鍓茶崏瀹藉害
         widthField = createInfoTextField(widthValue != null ? widthValue : "", true);
-        contentPanel.add(createTextFieldSection("鍓茶崏瀹藉害 (鍘樼背)", widthField));
+        contentPanel.add(createTextFieldSection("鍓茶崏瀹藉害 (cm)", widthField));
         
         // 鍓茶崏瀹夊叏璺濈锛堝彧璇绘樉绀猴級
+        // 浼樺厛浠嶥ikuai瀵硅薄鑾峰彇锛屽鏋淒ikuai涓病鏈夛紝鍐嶄粠Device鑾峰彇
         String displaySafetyDistance = "鏈缃�";
-        Device device = Device.getActiveDevice();
-        if (device != null) {
-            String safetyDistanceValue = device.getMowingSafetyDistance();
-            if (safetyDistanceValue != null && !"-1".equals(safetyDistanceValue) && !safetyDistanceValue.trim().isEmpty()) {
-                try {
-                    double distanceMeters = Double.parseDouble(safetyDistanceValue.trim());
-                    // 濡傛灉鍊煎ぇ浜�100锛岃涓烘槸鍘樼背锛岄渶瑕佽浆鎹负绫�
-                    if (distanceMeters > 100) {
-                        distanceMeters = distanceMeters / 100.0;
-                    }
-                    displaySafetyDistance = String.format("%.2f绫�", distanceMeters);
-                } catch (NumberFormatException e) {
-                    displaySafetyDistance = "鏈缃�";
+        String safetyDistanceValue = null;
+        
+        // 棣栧厛灏濊瘯浠嶥ikuai瀵硅薄鑾峰彇
+        if (dikuai != null) {
+            safetyDistanceValue = dikuai.getMowingSafetyDistance();
+        }
+        
+        // 濡傛灉Dikuai涓病鏈夛紝浠嶥evice鑾峰彇
+        if ((safetyDistanceValue == null || "-1".equals(safetyDistanceValue) || safetyDistanceValue.trim().isEmpty())) {
+            Device device = Device.getActiveDevice();
+            if (device != null) {
+                safetyDistanceValue = device.getMowingSafetyDistance();
+            }
+        }
+        
+        // 鏍煎紡鍖栨樉绀哄��
+        if (safetyDistanceValue != null && !"-1".equals(safetyDistanceValue) && !safetyDistanceValue.trim().isEmpty()) {
+            try {
+                double distanceMeters = Double.parseDouble(safetyDistanceValue.trim());
+                // 濡傛灉鍊煎ぇ浜�100锛岃涓烘槸鍘樼背锛岄渶瑕佽浆鎹负绫�
+                if (distanceMeters > 100) {
+                    distanceMeters = distanceMeters / 100.0;
                 }
+                displaySafetyDistance = String.format(Locale.US, "%.2fm", distanceMeters);
+            } catch (NumberFormatException e) {
+                displaySafetyDistance = "鏈缃�";
             }
         }
         contentPanel.add(createInfoValueSection("鍓茶崏瀹夊叏璺濈", displaySafetyDistance));
@@ -163,7 +183,12 @@
         String existingPath = prepareCoordinateForEditor(dikuai.getPlannedPath());
         String pathSeed = initialGeneratedPath != null ? initialGeneratedPath : existingPath;
         pathArea = createInfoTextArea(pathSeed != null ? pathSeed : "", true, 10);
-        contentPanel.add(createTextAreaSection("鍓茶崏璺緞鍧愭爣", pathArea));
+        String pathTitle = "鍓茶崏璺緞鍧愭爣";
+        if (pathSeed != null && !pathSeed.trim().isEmpty() && !"-1".equals(pathSeed.trim())) {
+            int pathCount = pathSeed.split(";").length;
+            pathTitle = "鍓茶崏璺緞鍧愭爣 (" + pathCount + "鐐�)";
+        }
+        contentPanel.add(createTextAreaSection(pathTitle, pathArea));
         
         JScrollPane dialogScrollPane = new JScrollPane(contentPanel);
         dialogScrollPane.setBorder(BorderFactory.createEmptyBorder());
@@ -225,30 +250,35 @@
      * 棰勮璺緞
      */
     private void previewPath() {
-        // 鍏堜繚瀛樺綋鍓嶈矾寰勫埌鍦板潡锛堜复鏃朵繚瀛橈紝鐢ㄤ簬棰勮锛�
-        String pathNormalized = normalizeCoordinateInput(pathArea.getText());
+        // 鐩存帴浠庢枃鏈煙鑾峰彇璺緞鏁版嵁
+        String rawPath = pathArea.getText();
+        String pathNormalized = normalizeCoordinateInput(rawPath);
+        
         if (!"-1".equals(pathNormalized)) {
+            // 瑙勮寖鍖栬矾寰勬暟鎹細鏀寔鎹㈣銆佺┖鏍肩瓑鍒嗛殧绗�
             pathNormalized = pathNormalized
                 .replace("\r\n", ";")
                 .replace('\r', ';')
                 .replace('\n', ';')
-                .replaceAll(";+", ";")
-                .replaceAll("\\s*;\\s*", ";")
-                .trim();
+                .replaceAll("\\s+", ";") // 灏嗘墍鏈夌┖鐧藉瓧绗︽浛鎹负鍒嗗彿
+                .replaceAll(";+", ";");  // 鍚堝苟杩炵画鍒嗗彿
+            
+            // 鍘婚櫎棣栧熬鍒嗗彿
+            if (pathNormalized.startsWith(";")) pathNormalized = pathNormalized.substring(1);
+            if (pathNormalized.endsWith(";")) pathNormalized = pathNormalized.substring(0, pathNormalized.length() - 1);
+            
             if (pathNormalized.isEmpty()) {
                 pathNormalized = "-1";
             }
         }
         
         if ("-1".equals(pathNormalized)) {
-            JOptionPane.showMessageDialog(this, "璇峰厛鐢熸垚鍓茶崏璺緞", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
+            JOptionPane.showMessageDialog(this, "璇峰厛鐢熸垚鍓茶崏璺緞鎴栧湪鏂囨湰妗嗕腑杈撳叆鏈夋晥鍧愭爣", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
             return;
         }
         
-        // 涓存椂淇濆瓨璺緞鍒板湴鍧楀璞★紙涓嶆寔涔呭寲锛�
-        if (saveCallback != null) {
-            saveCallback.savePlannedPath(dikuai, pathNormalized);
-        }
+        // 娉ㄦ剰锛氶瑙堟椂涓嶈嚜鍔ㄤ繚瀛樿矾寰勫埌鍦板潡锛屼粎浣跨敤鏂囨湰鍩熶腑鐨勬暟鎹繘琛岄瑙�
+        // 鍙湁鐐瑰嚮"淇濆瓨璺緞"鎸夐挳鏃舵墠鎸佷箙鍖栨暟鎹�
         
         // 淇濆瓨褰撳墠椤甸潰鐘舵�侊紝鐢ㄤ簬杩斿洖鏃舵仮澶�
         String currentBaseStation = baseStationField.getText();
@@ -265,12 +295,16 @@
         String boundaryInput = normalizeCoordinateInput(boundaryArea.getText());
         final String boundary;
         if (!"-1".equals(boundaryInput)) {
-            String processed = boundaryInput.replace("\r\n", ";")
+            String processed = boundaryInput
+                .replace("\r\n", ";")
                 .replace('\r', ';')
                 .replace('\n', ';')
-                .replaceAll(";+", ";")
-                .replaceAll("\\s*;\\s*", ";")
-                .trim();
+                .replaceAll("\\s+", ";")
+                .replaceAll(";+", ";");
+            
+            if (processed.startsWith(";")) processed = processed.substring(1);
+            if (processed.endsWith(";")) processed = processed.substring(0, processed.length() - 1);
+
             if (processed.isEmpty()) {
                 boundary = dikuai.getBoundaryCoordinates();
             } else {
@@ -373,7 +407,7 @@
         String rawWidthInput = widthField.getText() != null ? widthField.getText().trim() : "";
         String widthSanitized = sanitizeWidthString(widthField.getText());
         if (widthSanitized == null) {
-            String message = rawWidthInput.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(鍘樼背)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
+                String message = rawWidthInput.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(cm)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
             JOptionPane.showMessageDialog(this, message, "鎻愮ず", JOptionPane.WARNING_MESSAGE);
             return;
         }
@@ -412,6 +446,21 @@
             JOptionPane.showMessageDialog(this, "璇峰厛鐢熸垚鍓茶崏璺緞", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
             return;
         }
+
+        // 鏇存柊褰撳墠鍦板潡瀵硅薄鐨勫睘鎬�
+        if (dikuai != null) {
+            dikuai.setBaseStationCoordinates(baseStationNormalized);
+            dikuai.setBoundaryCoordinates(boundaryNormalized);
+            dikuai.setMowingWidth(widthNormalized);
+            dikuai.setPlannedPath(pathNormalized);
+            dikuai.setObstacleCoordinates(obstacleNormalized);
+            
+            // 鑾峰彇骞舵洿鏂板畨鍏ㄨ窛绂�
+            String safetyDistance = getSafetyDistanceString();
+            if (safetyDistance != null) {
+                dikuai.setMowingSafetyDistance(safetyDistance);
+            }
+        }
         
         // 璋冪敤鍥炶皟淇濆瓨鏁版嵁
         if (saveCallback != null) {
@@ -435,10 +484,19 @@
                 JOptionPane.showMessageDialog(this, "鏃犳硶淇濆瓨鍓茶崏璺緞", "閿欒", JOptionPane.ERROR_MESSAGE);
                 return;
             }
+            
+            // 淇濆瓨瀹夊叏璺濈
+            String safetyDistance = getSafetyDistanceString();
+            if (safetyDistance != null) {
+                if (!saveCallback.saveMowingSafetyDistance(dikuai, safetyDistance)) {
+                    JOptionPane.showMessageDialog(this, "鏃犳硶淇濆瓨鍓茶崏瀹夊叏璺濈", "閿欒", JOptionPane.ERROR_MESSAGE);
+                    return;
+                }
+            }
         }
         
         JOptionPane.showMessageDialog(this, "鍓茶崏璺緞宸蹭繚瀛�", "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
-        dispose();
+        // dispose(); // 鐢ㄦ埛瑕佹眰淇濆瓨鍚庝笉鍏抽棴椤甸潰
     }
     
     /**
@@ -460,7 +518,7 @@
         String widthStr = sanitizeWidthString(widthCmInput);
         if (widthStr == null) {
             if (showMessages) {
-                String message = rawWidth.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(鍘樼背)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
+                String message = rawWidth.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(cm)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
                 JOptionPane.showMessageDialog(parentComponent, message, "鎻愮ず", JOptionPane.WARNING_MESSAGE);
             }
             return null;
@@ -497,7 +555,20 @@
         
         String obstacles = sanitizeValueOrNull(obstacleInput);
         if (obstacles != null) {
-            obstacles = obstacles.replace("\r\n", " ").replace('\r', ' ').replace('\n', ' ');
+            // 鎸夌収鐢ㄦ埛瑕佹眰锛屽涓殰纰嶇墿涔嬮棿鐢� $ 绗﹀彿鍒嗛殧
+            // 濡傛灉杈撳叆涓寘鍚� $锛屽垯淇濈暀 $锛屽惁鍒欏皢鎹㈣绗︽浛鎹负 $
+            if (obstacles.contains("$")) {
+                // 宸茬粡鏄� $ 鍒嗛殧鐨勬牸寮忥紝鍙渶娓呯悊鎹㈣绗�
+                obstacles = obstacles.replace("\r\n", "").replace('\r', ' ').replace('\n', ' ');
+            } else {
+                // 灏濊瘯灏嗘崲琛岀杞崲涓� $锛屾垨鑰呭鏋滄槸涓�琛屽垯淇濇寔鍘熸牱
+                // 杩欓噷鍋囪鐢ㄦ埛鍙兘鐢ㄦ崲琛屽垎闅斿涓殰纰嶇墿
+                // 浣嗘牴鎹渶姹傛弿杩帮紝浼间箮杈撳叆鏈韩灏卞簲璇ユ槸 $ 鍒嗛殧鐨勶紝鎴栬�呮垜浠渶瑕佸鐞嗘垚 $ 鍒嗛殧
+                // 涓轰簡鍏煎鎬э紝濡傛灉鐢ㄦ埛杈撳叆鐨勬槸鎹㈣鍒嗛殧鐨勫涓殰纰嶇墿锛屾垜浠皢鍏惰浆鎹负 $ 鍒嗛殧
+                // 浣嗛�氬父闅滅鐗╁潗鏍囨槸涓�涓插潗鏍囩偣锛屽鏋滅敤鎴锋病鏈夋樉寮忕敤 $ 鍒嗛殧锛屾垜浠緢闅惧尯鍒嗘槸鍚屼竴涓殰纰嶇墿鐨勭偣杩樻槸澶氫釜闅滅鐗�
+                // 鍥犳锛岃繖閲屼富瑕佸鐞嗘竻鐞嗗伐浣滐紝鍏蜂綋鐨勮В鏋愰�昏緫鍦ㄥ悇瀹炵幇绫讳腑澶勭悊
+                obstacles = obstacles.replace("\r\n", " ").replace('\r', ' ').replace('\n', ' ');
+            }
         }
 
         // 鑾峰彇瀹夊叏璺濈
@@ -518,19 +589,10 @@
             int grassType = shapeJudger.judgeGrassType(boundary);
             // grassType: 0=鏃犳硶鍒ゆ柇, 1=鍑稿舰, 2=寮傚舰
             
-            // 瑙f瀽闅滅鐗╁垪琛�
-            List<List<Coordinate>> obstacleList = Lunjingguihua.parseObstacles(obstacles);
-            if (obstacleList == null) {
-                obstacleList = new ArrayList<>();
-            }
-
-            // 鍒ゆ柇鏄惁鏈夋湁鏁堢殑闅滅鐗╋細鍙湁褰撹В鏋愭垚鍔熶笖鍒楄〃涓嶄负绌烘椂锛屾墠璁や负鏈夐殰纰嶇墿
-            boolean hasValidObstacles = !obstacleList.isEmpty();
-            
             String generated = null;
             
             // 2. 鏍规嵁鍦板潡绫诲瀷鍜屾槸鍚︽湁闅滅鐗╋紝璋冪敤涓嶅悓鐨勮矾寰勭敓鎴愮被
-            if (!hasValidObstacles) {
+            if (!hasObstacleInput) {
                 // 鏃犻殰纰嶇墿鐨勬儏鍐�
                 if (grassType == 1) {
                     // 鍑稿舰鍦板潡锛屾棤闅滅鐗� -> 璋冪敤 AoxinglujingNoObstacle
@@ -539,97 +601,43 @@
                     generated = formatAoxingPathSegments(segments);
                 } else if (grassType == 2) {
                     // 寮傚舰鍦板潡锛屾棤闅滅鐗� -> 璋冪敤 YixinglujingNoObstacle
-                    // 娉ㄦ剰锛氬鏋滆绫昏繕娌℃湁瀹炵幇锛岃繖閲屼細鎶涘嚭寮傚父鎴栬繑鍥瀗ull
-                    try {
-                        // 鍋囪 YixinglujingNoObstacle 鏈夌被浼肩殑鏂规硶绛惧悕
-                        // 濡傛灉绫昏繕娌℃湁瀹炵幇锛屽彲鑳介渶瑕佷娇鐢ㄥ師鏉ョ殑鏂规硶浣滀负鍚庡
-                        generated = YixinglujingNoObstacle.planPath(boundary, plannerWidth, safetyMarginStr);
-                    } catch (Exception e) {
-                        // 濡傛灉绫昏繕娌℃湁瀹炵幇锛屼娇鐢ㄥ師鏉ョ殑鏂规硶浣滀负鍚庡
-                        if (showMessages) {
-                            System.err.println("YixinglujingNoObstacle 灏氭湭瀹炵幇锛屼娇鐢ㄩ粯璁ゆ柟娉�: " + e.getMessage());
-                        }
-                        generated = Lunjingguihua.generatePathFromStrings(
-                            boundary, obstacles != null ? obstacles : "", plannerWidth, safetyMarginStr, mode);
-                    }
+                    // 璋冪敤 YixinglujingNoObstacle.planPath 鑾峰彇璺緞娈靛垪琛�
+                    List<YixinglujingNoObstacle.PathSegment> segments = 
+                        YixinglujingNoObstacle.planPath(boundary, plannerWidth, safetyMarginStr);
+                    // 鏍煎紡鍖栬矾寰勬鍒楄〃涓哄瓧绗︿覆
+                    generated = formatYixingPathSegments(segments);
                 } else {
-                    // 鏃犳硶鍒ゆ柇鍦板潡绫诲瀷锛屼娇鐢ㄥ師鏉ョ殑鏂规硶浣滀负鍚庡
+                    // 鏃犳硶鍒ゆ柇鍦板潡绫诲瀷锛岄粯璁ゆ寜鍑稿舰澶勭悊鎴栨彁绀�
                     if (showMessages) {
-                        JOptionPane.showMessageDialog(parentComponent, "鏃犳硶鍒ゆ柇鍦板潡绫诲瀷锛屼娇鐢ㄩ粯璁よ矾寰勭敓鎴愭柟娉�", 
+                        JOptionPane.showMessageDialog(parentComponent, "鏃犳硶鍒ゆ柇鍦板潡绫诲瀷锛屽皾璇曟寜鍑稿舰鍦板潡澶勭悊", 
                             "鎻愮ず", JOptionPane.WARNING_MESSAGE);
                     }
-                    generated = Lunjingguihua.generatePathFromStrings(
-                        boundary, obstacles != null ? obstacles : "", plannerWidth, safetyMarginStr, mode);
+                    List<AoxinglujingNoObstacle.PathSegment> segments = 
+                        AoxinglujingNoObstacle.planPath(boundary, plannerWidth, safetyMarginStr);
+                    generated = formatAoxingPathSegments(segments);
                 }
             } else {
                 // 鏈夐殰纰嶇墿鐨勬儏鍐�
                 if (grassType == 1) {
                     // 鍑稿舰鍦板潡锛屾湁闅滅鐗� -> 璋冪敤 AoxinglujingHaveObstacel
-                    try {
-                        // 鍋囪 AoxinglujingHaveObstacel 鏈夌被浼肩殑鏂规硶绛惧悕
-                        generated = AoxinglujingHaveObstacel.planPath(boundary, obstacles, plannerWidth, safetyMarginStr);
-                    } catch (Exception e) {
-                        // 濡傛灉绫昏繕娌℃湁瀹炵幇锛屼娇鐢ㄥ師鏉ョ殑鏂规硶浣滀负鍚庡
-                        if (showMessages) {
-                            System.err.println("AoxinglujingHaveObstacel 灏氭湭瀹炵幇锛屼娇鐢ㄩ粯璁ゆ柟娉�: " + e.getMessage());
-                        }
-                        List<Coordinate> polygon = Lunjingguihua.parseCoordinates(boundary);
-                        if (polygon.size() < 4) {
-                            if (showMessages) {
-                                JOptionPane.showMessageDialog(parentComponent, "澶氳竟褰㈠潗鏍囨暟閲忎笉瓒筹紝鑷冲皯闇�瑕佷笁涓偣",
-                                    "閿欒", JOptionPane.ERROR_MESSAGE);
-                            }
-                            return null;
-                        }
-                        double safetyDistance = Double.parseDouble(safetyMarginStr);
-                        ObstaclePathPlanner pathPlanner = new ObstaclePathPlanner(
-                            polygon, widthMeters, mode, obstacleList, safetyDistance);
-                        List<Lunjingguihua.PathSegment> segments = pathPlanner.generate();
-                        generated = Lunjingguihua.formatPathSegments(segments);
-                    }
+                    // 浼犲叆鍙傛暟锛歜oundary(A), obstacles(B), plannerWidth(C), safetyMarginStr(D)
+                    List<AoxinglujingHaveObstacel.PathSegment> segments = 
+                        AoxinglujingHaveObstacel.planPath(boundary, obstacles, plannerWidth, safetyMarginStr);
+                    generated = formatAoxingHaveObstaclePathSegments(segments);
                 } else if (grassType == 2) {
                     // 寮傚舰鍦板潡锛屾湁闅滅鐗� -> 璋冪敤 YixinglujingHaveObstacel
-                    try {
-                        // 鍋囪 YixinglujingHaveObstacel 鏈夌被浼肩殑鏂规硶绛惧悕
-                        generated = YixinglujingHaveObstacel.planPath(boundary, obstacles, plannerWidth, safetyMarginStr);
-                    } catch (Exception e) {
-                        // 濡傛灉绫昏繕娌℃湁瀹炵幇锛屼娇鐢ㄥ師鏉ョ殑鏂规硶浣滀负鍚庡
-                        if (showMessages) {
-                            System.err.println("YixinglujingHaveObstacel 灏氭湭瀹炵幇锛屼娇鐢ㄩ粯璁ゆ柟娉�: " + e.getMessage());
-                        }
-                        List<Coordinate> polygon = Lunjingguihua.parseCoordinates(boundary);
-                        if (polygon.size() < 4) {
-                            if (showMessages) {
-                                JOptionPane.showMessageDialog(parentComponent, "澶氳竟褰㈠潗鏍囨暟閲忎笉瓒筹紝鑷冲皯闇�瑕佷笁涓偣",
-                                    "閿欒", JOptionPane.ERROR_MESSAGE);
-                            }
-                            return null;
-                        }
-                        double safetyDistance = Double.parseDouble(safetyMarginStr);
-                        ObstaclePathPlanner pathPlanner = new ObstaclePathPlanner(
-                            polygon, widthMeters, mode, obstacleList, safetyDistance);
-                        List<Lunjingguihua.PathSegment> segments = pathPlanner.generate();
-                        generated = Lunjingguihua.formatPathSegments(segments);
-                    }
+                    // 浼犲叆鍙傛暟锛歜oundary(A), obstacles(B), plannerWidth(C), safetyMarginStr(D)
+                    // 娉ㄦ剰锛歒ixinglujingHaveObstacel.planPath 杩斿洖 String
+                    generated = YixinglujingHaveObstacel.planPath(boundary, obstacles, plannerWidth, safetyMarginStr);
                 } else {
-                    // 鏃犳硶鍒ゆ柇鍦板潡绫诲瀷锛屼娇鐢ㄥ師鏉ョ殑鏂规硶浣滀负鍚庡
+                    // 鏃犳硶鍒ゆ柇鍦板潡绫诲瀷锛岄粯璁ゆ寜鍑稿舰澶勭悊鎴栨彁绀�
                     if (showMessages) {
-                        JOptionPane.showMessageDialog(parentComponent, "鏃犳硶鍒ゆ柇鍦板潡绫诲瀷锛屼娇鐢ㄩ粯璁よ矾寰勭敓鎴愭柟娉�", 
+                        JOptionPane.showMessageDialog(parentComponent, "鏃犳硶鍒ゆ柇鍦板潡绫诲瀷锛屽皾璇曟寜鍑稿舰鍦板潡澶勭悊", 
                             "鎻愮ず", JOptionPane.WARNING_MESSAGE);
                     }
-                    List<Coordinate> polygon = Lunjingguihua.parseCoordinates(boundary);
-                    if (polygon.size() < 4) {
-                        if (showMessages) {
-                            JOptionPane.showMessageDialog(parentComponent, "澶氳竟褰㈠潗鏍囨暟閲忎笉瓒筹紝鑷冲皯闇�瑕佷笁涓偣",
-                                "閿欒", JOptionPane.ERROR_MESSAGE);
-                        }
-                        return null;
-                    }
-                    double safetyDistance = Double.parseDouble(safetyMarginStr);
-                    ObstaclePathPlanner pathPlanner = new ObstaclePathPlanner(
-                        polygon, widthMeters, mode, obstacleList, safetyDistance);
-                    List<Lunjingguihua.PathSegment> segments = pathPlanner.generate();
-                    generated = Lunjingguihua.formatPathSegments(segments);
+                    List<AoxinglujingHaveObstacel.PathSegment> segments = 
+                        AoxinglujingHaveObstacel.planPath(boundary, obstacles, plannerWidth, safetyMarginStr);
+                    generated = formatAoxingHaveObstaclePathSegments(segments);
                 }
             }
             
@@ -663,25 +671,38 @@
     
     /**
      * 鑾峰彇瀹夊叏璺濈瀛楃涓诧紙绫筹級
+     * 浼樺厛浠嶥ikuai瀵硅薄鑾峰彇锛屽鏋淒ikuai涓病鏈夛紝鍐嶄粠Device鑾峰彇
      */
     private String getSafetyDistanceString() {
-        Device device = Device.getActiveDevice();
-        if (device != null) {
-            String safetyDistanceValue = device.getMowingSafetyDistance();
-            if (safetyDistanceValue != null && !"-1".equals(safetyDistanceValue) && !safetyDistanceValue.trim().isEmpty()) {
-                try {
-                    double distanceMeters = Double.parseDouble(safetyDistanceValue.trim());
-                    // 濡傛灉鍊煎ぇ浜�100锛岃涓烘槸鍘樼背锛岄渶瑕佽浆鎹负绫�
-                    if (distanceMeters > 100) {
-                        distanceMeters = distanceMeters / 100.0;
-                    }
-                    return BigDecimal.valueOf(distanceMeters)
-                        .setScale(3, RoundingMode.HALF_UP)
-                        .stripTrailingZeros()
-                        .toPlainString();
-                } catch (NumberFormatException e) {
-                    // 瑙f瀽澶辫触锛岃繑鍥瀗ull锛屼娇鐢ㄩ粯璁ゅ��
+        String safetyDistanceValue = null;
+        
+        // 棣栧厛灏濊瘯浠嶥ikuai瀵硅薄鑾峰彇
+        if (dikuai != null) {
+            safetyDistanceValue = dikuai.getMowingSafetyDistance();
+        }
+        
+        // 濡傛灉Dikuai涓病鏈夛紝浠嶥evice鑾峰彇
+        if ((safetyDistanceValue == null || "-1".equals(safetyDistanceValue) || safetyDistanceValue.trim().isEmpty())) {
+            Device device = Device.getActiveDevice();
+            if (device != null) {
+                safetyDistanceValue = device.getMowingSafetyDistance();
+            }
+        }
+        
+        // 鏍煎紡鍖栧苟杩斿洖
+        if (safetyDistanceValue != null && !"-1".equals(safetyDistanceValue) && !safetyDistanceValue.trim().isEmpty()) {
+            try {
+                double distanceMeters = Double.parseDouble(safetyDistanceValue.trim());
+                // 濡傛灉鍊煎ぇ浜�100锛岃涓烘槸鍘樼背锛岄渶瑕佽浆鎹负绫�
+                if (distanceMeters > 100) {
+                    distanceMeters = distanceMeters / 100.0;
                 }
+                return BigDecimal.valueOf(distanceMeters)
+                    .setScale(3, RoundingMode.HALF_UP)
+                    .stripTrailingZeros()
+                    .toPlainString();
+            } catch (NumberFormatException e) {
+                // 瑙f瀽澶辫触锛岃繑鍥瀗ull锛屼娇鐢ㄩ粯璁ゅ��
             }
         }
         return null;
@@ -712,6 +733,54 @@
     }
     
     /**
+     * 鏍煎紡鍖� YixinglujingNoObstacle.PathSegment 鍒楄〃涓哄潗鏍囧瓧绗︿覆
+     */
+    private String formatYixingPathSegments(List<YixinglujingNoObstacle.PathSegment> segments) {
+        if (segments == null || segments.isEmpty()) {
+            return "";
+        }
+        StringBuilder sb = new StringBuilder();
+        YixinglujingNoObstacle.Point last = null;
+        for (YixinglujingNoObstacle.PathSegment segment : segments) {
+            // 鍙坊鍔犲壊鑽夊伐浣滄锛岃烦杩囪繃娓℃
+            if (segment.isMowing) {
+                // 濡傛灉璧风偣涓庝笂涓�涓粓鐐逛笉鍚岋紝娣诲姞璧风偣
+                if (last == null || !equalsYixingPoint(last, segment.start)) {
+                    appendYixingPoint(sb, segment.start);
+                }
+                // 娣诲姞缁堢偣
+                appendYixingPoint(sb, segment.end);
+                last = segment.end;
+            }
+        }
+        return sb.toString();
+    }
+    
+    /**
+     * 鏍煎紡鍖� AoxinglujingHaveObstacel.PathSegment 鍒楄〃涓哄潗鏍囧瓧绗︿覆
+     */
+    private String formatAoxingHaveObstaclePathSegments(List<AoxinglujingHaveObstacel.PathSegment> segments) {
+        if (segments == null || segments.isEmpty()) {
+            return "";
+        }
+        StringBuilder sb = new StringBuilder();
+        AoxinglujingHaveObstacel.Point last = null;
+        for (AoxinglujingHaveObstacel.PathSegment segment : segments) {
+            // 鍙坊鍔犲壊鑽夊伐浣滄锛岃烦杩囪繃娓℃
+            if (segment.isMowing) {
+                // 濡傛灉璧风偣涓庝笂涓�涓粓鐐逛笉鍚岋紝娣诲姞璧风偣
+                if (last == null || !equals2D(last, segment.start)) {
+                    appendPoint(sb, segment.start);
+                }
+                // 娣诲姞缁堢偣
+                appendPoint(sb, segment.end);
+                last = segment.end;
+            }
+        }
+        return sb.toString();
+    }
+
+    /**
      * 姣旇緝涓や釜鐐规槸鍚︾浉鍚岋紙浣跨敤灏忕殑瀹瑰樊锛�
      */
     private boolean equals2D(AoxinglujingNoObstacle.Point p1, AoxinglujingNoObstacle.Point p2) {
@@ -732,6 +801,48 @@
         sb.append(String.format(Locale.US, "%.6f,%.6f", point.x, point.y));
     }
     
+    /**
+     * 姣旇緝涓や釜 YixinglujingNoObstacle.Point 鏄惁鐩稿悓锛堜娇鐢ㄥ皬鐨勫宸級
+     */
+    private boolean equalsYixingPoint(YixinglujingNoObstacle.Point p1, YixinglujingNoObstacle.Point p2) {
+        if (p1 == null || p2 == null) {
+            return p1 == p2;
+        }
+        double tolerance = 1e-6;
+        return Math.abs(p1.x - p2.x) < tolerance && Math.abs(p1.y - p2.y) < tolerance;
+    }
+    
+    /**
+     * 娣诲姞 YixinglujingNoObstacle.Point 鍒板瓧绗︿覆鏋勫缓鍣�
+     */
+    private void appendYixingPoint(StringBuilder sb, YixinglujingNoObstacle.Point point) {
+        if (sb.length() > 0) {
+            sb.append(";");
+        }
+        sb.append(String.format(Locale.US, "%.6f,%.6f", point.x, point.y));
+    }
+
+    /**
+     * 姣旇緝涓や釜 AoxinglujingHaveObstacel.Point 鏄惁鐩稿悓锛堜娇鐢ㄥ皬鐨勫宸級
+     */
+    private boolean equals2D(AoxinglujingHaveObstacel.Point p1, AoxinglujingHaveObstacel.Point p2) {
+        if (p1 == null || p2 == null) {
+            return p1 == p2;
+        }
+        double tolerance = 1e-6;
+        return Math.abs(p1.x - p2.x) < tolerance && Math.abs(p1.y - p2.y) < tolerance;
+    }
+
+    /**
+     * 娣诲姞 AoxinglujingHaveObstacel.Point 鍒板瓧绗︿覆鏋勫缓鍣�
+     */
+    private void appendPoint(StringBuilder sb, AoxinglujingHaveObstacel.Point point) {
+        if (sb.length() > 0) {
+            sb.append(";");
+        }
+        sb.append(String.format(Locale.US, "%.6f,%.6f", point.x, point.y));
+    }
+    
     // ========== UI杈呭姪鏂规硶 ==========
     
     private JTextArea createInfoTextArea(String text, boolean editable, int rows) {
@@ -762,15 +873,18 @@
         titleLabel.setForeground(TEXT_COLOR);
         titlePanel.add(titleLabel, BorderLayout.WEST);
         
-        // 鍒涘缓澶嶅埗鎸夐挳
-        JButton copyButton = createCopyButton(title, () -> {
-            String text = textArea.getText();
-            if (text == null || text.trim().isEmpty()) {
-                JOptionPane.showMessageDialog(this, title + " 鏈缃�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
-                return;
-            }
-            copyToClipboard(text, title);
-        });
+        // 鍒涘缓澶嶅埗鎸夐挳锛堜娇鐢� Fuzhibutton锛�
+        JButton copyButton = Fuzhibutton.createCopyButton(
+            () -> {
+                String text = textArea.getText();
+                if (text == null || text.trim().isEmpty() || "-1".equals(text.trim())) {
+                    return null; // 杩斿洖null浼氳Е鍙�"鏈缃�"鎻愮ず
+                }
+                return text;
+            },
+            "澶嶅埗" + title,
+            new Color(230, 250, 240)
+        );
         titlePanel.add(copyButton, BorderLayout.EAST);
         
         section.add(titlePanel, BorderLayout.NORTH);
@@ -812,15 +926,18 @@
         titleLabel.setForeground(TEXT_COLOR);
         titlePanel.add(titleLabel, BorderLayout.WEST);
         
-        // 鍒涘缓澶嶅埗鎸夐挳
-        JButton copyButton = createCopyButton(title, () -> {
-            String text = textField.getText();
-            if (text == null || text.trim().isEmpty()) {
-                JOptionPane.showMessageDialog(this, title + " 鏈缃�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
-                return;
-            }
-            copyToClipboard(text, title);
-        });
+        // 鍒涘缓澶嶅埗鎸夐挳锛堜娇鐢� Fuzhibutton锛�
+        JButton copyButton = Fuzhibutton.createCopyButton(
+            () -> {
+                String text = textField.getText();
+                if (text == null || text.trim().isEmpty() || "-1".equals(text.trim())) {
+                    return null; // 杩斿洖null浼氳Е鍙�"鏈缃�"鎻愮ず
+                }
+                return text;
+            },
+            "澶嶅埗" + title,
+            new Color(230, 250, 240)
+        );
         titlePanel.add(copyButton, BorderLayout.EAST);
         
         section.add(titlePanel, BorderLayout.NORTH);
@@ -962,80 +1079,6 @@
         return "parallel";
     }
     
-    /**
-     * 鍒涘缓澶嶅埗鎸夐挳
-     */
-    private JButton createCopyButton(String title, Runnable copyAction) {
-        JButton copyButton = new JButton();
-        Font titleFont = new Font("寰蒋闆呴粦", Font.BOLD, 14);
-        FontMetrics metrics = getFontMetrics(titleFont);
-        int iconSize = metrics.getHeight(); // 浣跨敤鏍囬瀛椾綋楂樺害浣滀负鍥炬爣澶у皬
-        
-        // 鍔犺浇澶嶅埗鍥炬爣
-        ImageIcon copyIcon = null;
-        ImageIcon successIcon = null;
-        try {
-            ImageIcon originalCopyIcon = new ImageIcon("image/fuzhi.png");
-            Image scaledCopyImage = originalCopyIcon.getImage().getScaledInstance(iconSize, iconSize, Image.SCALE_SMOOTH);
-            copyIcon = new ImageIcon(scaledCopyImage);
-            
-            // 鍔犺浇鎴愬姛鍥炬爣
-            ImageIcon originalSuccessIcon = new ImageIcon("image/fuzhisucc.png");
-            Image scaledSuccessImage = originalSuccessIcon.getImage().getScaledInstance(iconSize, iconSize, Image.SCALE_SMOOTH);
-            successIcon = new ImageIcon(scaledSuccessImage);
-        } catch (Exception e) {
-            // 濡傛灉鍥剧墖鍔犺浇澶辫触锛屼娇鐢ㄦ枃鏈�
-            copyButton.setText("澶嶅埗");
-            copyButton.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
-            System.err.println("鏃犳硶鍔犺浇澶嶅埗鍥炬爣: " + e.getMessage());
-        }
-        
-        final ImageIcon finalCopyIcon = copyIcon;
-        final ImageIcon finalSuccessIcon = successIcon;
-        
-        copyButton.setIcon(finalCopyIcon);
-        copyButton.setContentAreaFilled(false);
-        copyButton.setBorder(null);
-        copyButton.setFocusPainted(false);
-        copyButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
-        copyButton.setToolTipText("澶嶅埗" + title);
-        
-        // 娣诲姞鐐瑰嚮浜嬩欢
-        copyButton.addActionListener(e -> {
-            copyAction.run();
-            // 澶嶅埗鎴愬姛鍚庡垏鎹㈠浘鏍�
-            if (finalSuccessIcon != null) {
-                copyButton.setIcon(finalSuccessIcon);
-                // 1绉掑悗鎭㈠鍘熷浘鏍�
-                Timer timer = new Timer(1000, evt -> {
-                    copyButton.setIcon(finalCopyIcon);
-                });
-                timer.setRepeats(false);
-                timer.start();
-            }
-        });
-        
-        return copyButton;
-    }
-    
-    /**
-     * 澶嶅埗鏂囨湰鍒板壀璐存澘
-     */
-    private void copyToClipboard(String text, String title) {
-        if (text == null || text.trim().isEmpty()) {
-            JOptionPane.showMessageDialog(this, title + " 鏈缃�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
-            return;
-        }
-        
-        try {
-            StringSelection selection = new StringSelection(text);
-            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
-            clipboard.setContents(selection, selection);
-            // 鍘绘帀鎴愬姛鎻愮ず寮圭獥
-        } catch (Exception ex) {
-            JOptionPane.showMessageDialog(this, "澶嶅埗澶辫触: " + ex.getMessage(), "閿欒", JOptionPane.ERROR_MESSAGE);
-        }
-    }
 }
 
 

--
Gitblit v1.10.0