From a541fbdc8812337de120aad3792a2033a5dd7afe Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期四, 25 十二月 2025 12:23:01 +0800
Subject: [PATCH] 优化了首页

---
 src/lujing/MowingPathGenerationPage.java |  174 +++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 136 insertions(+), 38 deletions(-)

diff --git a/src/lujing/MowingPathGenerationPage.java b/src/lujing/MowingPathGenerationPage.java
index 503a1fd..bbbe001 100644
--- a/src/lujing/MowingPathGenerationPage.java
+++ b/src/lujing/MowingPathGenerationPage.java
@@ -125,32 +125,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));
@@ -162,7 +195,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());
@@ -372,7 +410,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;
         }
@@ -459,7 +497,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;
@@ -540,9 +578,11 @@
                     // 寮傚舰鍦板潡锛屾棤闅滅鐗� -> 璋冪敤 YixinglujingNoObstacle
                     // 娉ㄦ剰锛氬鏋滆绫昏繕娌℃湁瀹炵幇锛岃繖閲屼細鎶涘嚭寮傚父鎴栬繑鍥瀗ull
                     try {
-                        // 鍋囪 YixinglujingNoObstacle 鏈夌被浼肩殑鏂规硶绛惧悕
-                        // 濡傛灉绫昏繕娌℃湁瀹炵幇锛屽彲鑳介渶瑕佷娇鐢ㄥ師鏉ョ殑鏂规硶浣滀负鍚庡
-                        generated = YixinglujingNoObstacle.planPath(boundary, plannerWidth, safetyMarginStr);
+                        // 璋冪敤 YixinglujingNoObstacle.planPath 鑾峰彇璺緞娈靛垪琛�
+                        List<YixinglujingNoObstacle.PathSegment> segments = 
+                            YixinglujingNoObstacle.planPath(boundary, plannerWidth, safetyMarginStr);
+                        // 鏍煎紡鍖栬矾寰勬鍒楄〃涓哄瓧绗︿覆
+                        generated = formatYixingPathSegments(segments);
                     } catch (Exception e) {
                         // 濡傛灉绫昏繕娌℃湁瀹炵幇锛屼娇鐢ㄥ師鏉ョ殑鏂规硶浣滀负鍚庡
                         if (showMessages) {
@@ -662,25 +702,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;
@@ -711,6 +764,30 @@
     }
     
     /**
+     * 鏍煎紡鍖� 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();
+    }
+    
+    /**
      * 姣旇緝涓や釜鐐规槸鍚︾浉鍚岋紙浣跨敤灏忕殑瀹瑰樊锛�
      */
     private boolean equals2D(AoxinglujingNoObstacle.Point p1, AoxinglujingNoObstacle.Point p2) {
@@ -731,6 +808,27 @@
         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));
+    }
+    
     // ========== UI杈呭姪鏂规硶 ==========
     
     private JTextArea createInfoTextArea(String text, boolean editable, int rows) {

--
Gitblit v1.10.0