From cbfd1df513c473dd5550d78740c92fc1677b6e9b Mon Sep 17 00:00:00 2001
From: 826220679@qq.com <826220679@qq.com>
Date: 星期六, 27 十二月 2025 13:40:42 +0800
Subject: [PATCH] 异形有障碍物路径规划没完成

---
 src/lujing/MowingPathGenerationPage.java |   56 ++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 36 insertions(+), 20 deletions(-)

diff --git a/src/lujing/MowingPathGenerationPage.java b/src/lujing/MowingPathGenerationPage.java
index 77c496c..675d83f 100644
--- a/src/lujing/MowingPathGenerationPage.java
+++ b/src/lujing/MowingPathGenerationPage.java
@@ -140,8 +140,21 @@
         contentPanel.add(createTextAreaSection(obstacleTitle, obstacleArea));
         
         // 鍓茶崏瀹藉害
-        widthField = createInfoTextField(widthValue != null ? widthValue : "", true);
-        contentPanel.add(createTextFieldSection("鍓茶崏瀹藉害 (cm)", widthField));
+        String displayWidth = "";
+        if (widthValue != null && !widthValue.trim().isEmpty() && !"-1".equals(widthValue.trim())) {
+            try {
+                double val = Double.parseDouble(widthValue.trim());
+                // 绠�鍗曠殑鍚彂寮忚浆鎹細濡傛灉鍊煎ぇ浜�5锛屽亣璁炬槸鍘樼背锛岃浆鎹负绫�
+                if (val > 5) {
+                    val = val / 100.0;
+                }
+                displayWidth = String.format(Locale.US, "%.2f", val);
+            } catch (NumberFormatException e) {
+                displayWidth = widthValue;
+            }
+        }
+        widthField = createInfoTextField(displayWidth, true);
+        contentPanel.add(createTextFieldSection("鍓茶崏瀹藉害 (m)", widthField));
         
         // 鍓茶崏瀹夊叏璺濈锛堝彧璇绘樉绀猴級
         // 浼樺厛浠嶥ikuai瀵硅薄鑾峰彇锛屽鏋淒ikuai涓病鏈夛紝鍐嶄粠Device鑾峰彇
@@ -223,9 +236,9 @@
         String sanitizedWidth = sanitizeWidthString(widthField.getText());
         if (sanitizedWidth != null) {
             try {
-                double widthCm = Double.parseDouble(sanitizedWidth);
-                widthField.setText(formatWidthForStorage(widthCm));
-                sanitizedWidth = formatWidthForStorage(widthCm);
+                double widthMeters = Double.parseDouble(sanitizedWidth);
+                widthField.setText(formatWidthForStorage(widthMeters));
+                sanitizedWidth = formatWidthForStorage(widthMeters);
             } catch (NumberFormatException ex) {
                 widthField.setText(sanitizedWidth);
             }
@@ -407,25 +420,25 @@
         String rawWidthInput = widthField.getText() != null ? widthField.getText().trim() : "";
         String widthSanitized = sanitizeWidthString(widthField.getText());
         if (widthSanitized == null) {
-                String message = rawWidthInput.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(cm)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
+                String message = rawWidthInput.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(m)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
             JOptionPane.showMessageDialog(this, message, "鎻愮ず", JOptionPane.WARNING_MESSAGE);
             return;
         }
         
-        double widthCm;
+        double widthMeters;
         try {
-            widthCm = Double.parseDouble(widthSanitized);
+            widthMeters = Double.parseDouble(widthSanitized);
         } catch (NumberFormatException ex) {
             JOptionPane.showMessageDialog(this, "鍓茶崏瀹藉害鏍煎紡涓嶆纭�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
             return;
         }
         
-        if (widthCm <= 0) {
+        if (widthMeters <= 0) {
             JOptionPane.showMessageDialog(this, "鍓茶崏瀹藉害蹇呴』澶т簬0", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
             return;
         }
         
-        String widthNormalized = formatWidthForStorage(widthCm);
+        String widthNormalized = formatWidthForStorage(widthMeters);
         widthField.setText(widthNormalized);
         
         String pathNormalized = normalizeCoordinateInput(pathArea.getText());
@@ -518,15 +531,15 @@
         String widthStr = sanitizeWidthString(widthCmInput);
         if (widthStr == null) {
             if (showMessages) {
-                String message = rawWidth.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(cm)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
+                String message = rawWidth.isEmpty() ? "璇峰厛璁剧疆鍓茶崏瀹藉害(m)" : "鍓茶崏瀹藉害鏍煎紡涓嶆纭�";
                 JOptionPane.showMessageDialog(parentComponent, message, "鎻愮ず", JOptionPane.WARNING_MESSAGE);
             }
             return null;
         }
         
-        double widthCm;
+        double widthVal;
         try {
-            widthCm = Double.parseDouble(widthStr);
+            widthVal = Double.parseDouble(widthStr);
         } catch (NumberFormatException ex) {
             if (showMessages) {
                 JOptionPane.showMessageDialog(parentComponent, "鍓茶崏瀹藉害鏍煎紡涓嶆纭�", 
@@ -535,7 +548,7 @@
             return null;
         }
         
-        if (widthCm <= 0) {
+        if (widthVal <= 0) {
             if (showMessages) {
                 JOptionPane.showMessageDialog(parentComponent, "鍓茶崏瀹藉害蹇呴』澶т簬0", 
                     "鎻愮ず", JOptionPane.WARNING_MESSAGE);
@@ -543,7 +556,7 @@
             return null;
         }
         
-        double widthMeters = widthCm / 100.0d;
+        double widthMeters = widthVal;
         String plannerWidth = BigDecimal.valueOf(widthMeters)
             .setScale(3, RoundingMode.HALF_UP)
             .stripTrailingZeros()
@@ -596,12 +609,14 @@
                 // 鏃犻殰纰嶇墿鐨勬儏鍐�
                 if (grassType == 1) {
                     // 鍑稿舰鍦板潡锛屾棤闅滅鐗� -> 璋冪敤 AoxinglujingNoObstacle
+                    System.out.println("璋冪敤绠楁硶: 鍑稿舰鏃犻殰纰嶇墿, 绫诲悕: AoxinglujingNoObstacle");
                     List<AoxinglujingNoObstacle.PathSegment> segments = 
                         AoxinglujingNoObstacle.planPath(boundary, plannerWidth, safetyMarginStr);
                     generated = formatAoxingPathSegments(segments);
                 } else if (grassType == 2) {
                     // 寮傚舰鍦板潡锛屾棤闅滅鐗� -> 璋冪敤 YixinglujingNoObstacle
                     // 璋冪敤 YixinglujingNoObstacle.planPath 鑾峰彇璺緞娈靛垪琛�
+                    System.out.println("璋冪敤绠楁硶: 寮傚舰鏃犻殰纰嶇墿, 绫诲悕: YixinglujingNoObstacle");
                     List<YixinglujingNoObstacle.PathSegment> segments = 
                         YixinglujingNoObstacle.planPath(boundary, plannerWidth, safetyMarginStr);
                     // 鏍煎紡鍖栬矾寰勬鍒楄〃涓哄瓧绗︿覆
@@ -612,6 +627,7 @@
                         JOptionPane.showMessageDialog(parentComponent, "鏃犳硶鍒ゆ柇鍦板潡绫诲瀷锛屽皾璇曟寜鍑稿舰鍦板潡澶勭悊", 
                             "鎻愮ず", JOptionPane.WARNING_MESSAGE);
                     }
+                    System.out.println("璋冪敤绠楁硶: 鏃犳硶鍒ゆ柇绫诲瀷(榛樿鍑稿舰鏃犻殰纰嶇墿), 绫诲悕: AoxinglujingNoObstacle");
                     List<AoxinglujingNoObstacle.PathSegment> segments = 
                         AoxinglujingNoObstacle.planPath(boundary, plannerWidth, safetyMarginStr);
                     generated = formatAoxingPathSegments(segments);
@@ -621,12 +637,14 @@
                 if (grassType == 1) {
                     // 鍑稿舰鍦板潡锛屾湁闅滅鐗� -> 璋冪敤 AoxinglujingHaveObstacel
                     // 浼犲叆鍙傛暟锛歜oundary(A), obstacles(B), plannerWidth(C), safetyMarginStr(D)
+                    System.out.println("璋冪敤绠楁硶: 鍑稿舰鏈夐殰纰嶇墿, 绫诲悕: AoxinglujingHaveObstacel");
                     List<AoxinglujingHaveObstacel.PathSegment> segments = 
                         AoxinglujingHaveObstacel.planPath(boundary, obstacles, plannerWidth, safetyMarginStr);
                     generated = formatAoxingHaveObstaclePathSegments(segments);
                 } else if (grassType == 2) {
                     // 寮傚舰鍦板潡锛屾湁闅滅鐗� -> 璋冪敤 YixinglujingHaveObstacel
                     // 浼犲叆鍙傛暟锛歜oundary(A), obstacles(B), plannerWidth(C), safetyMarginStr(D)
+                    System.out.println("璋冪敤绠楁硶: 寮傚舰鏈夐殰纰嶇墿, 绫诲悕: YixinglujingHaveObstacel");
                     List<YixinglujingHaveObstacel.PathSegment> segments = 
                         YixinglujingHaveObstacel.planPath(boundary, obstacles, plannerWidth, safetyMarginStr);
                     generated = formatYixingHaveObstaclePathSegments(segments);
@@ -636,6 +654,7 @@
                         JOptionPane.showMessageDialog(parentComponent, "鏃犳硶鍒ゆ柇鍦板潡绫诲瀷锛屽皾璇曟寜鍑稿舰鍦板潡澶勭悊", 
                             "鎻愮ず", JOptionPane.WARNING_MESSAGE);
                     }
+                    System.out.println("璋冪敤绠楁硶: 鏃犳硶鍒ゆ柇绫诲瀷(榛樿鍑稿舰鏈夐殰纰嶇墿), 绫诲悕: AoxinglujingHaveObstacel");
                     List<AoxinglujingHaveObstacel.PathSegment> segments = 
                         AoxinglujingHaveObstacel.planPath(boundary, obstacles, plannerWidth, safetyMarginStr);
                     generated = formatAoxingHaveObstaclePathSegments(segments);
@@ -1081,11 +1100,8 @@
         return cleaned.isEmpty() ? null : cleaned;
     }
     
-    private String formatWidthForStorage(double widthCm) {
-        return BigDecimal.valueOf(widthCm)
-            .setScale(2, RoundingMode.HALF_UP)
-            .stripTrailingZeros()
-            .toPlainString();
+    private String formatWidthForStorage(double widthVal) {
+        return String.format(Locale.US, "%.2f", widthVal);
     }
     
     private String formatMowingPatternForDialog(String patternValue) {

--
Gitblit v1.10.0