From d0ae1a5baf919cf470d2ab2102587948623cc725 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期三, 24 十二月 2025 17:18:10 +0800
Subject: [PATCH] 将地块编号改成割草机编号+01的自增数字

---
 src/dikuai/addzhangaiwu.java |  347 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 290 insertions(+), 57 deletions(-)

diff --git a/src/dikuai/addzhangaiwu.java b/src/dikuai/addzhangaiwu.java
index 098de63..f914ce4 100644
--- a/src/dikuai/addzhangaiwu.java
+++ b/src/dikuai/addzhangaiwu.java
@@ -46,20 +46,20 @@
 
 import baseStation.BaseStation;
 import gecaoji.Device;
+import publicway.buttonset;
 import set.Setsys;
 import ui.UIConfig;
 import zhuye.Coordinate;
 import zhuye.MapRenderer;
 import zhuye.Shouye;
-import zhangaiwu.AddDikuai;
 import zhangaiwu.Obstacledge;
 import zhangaiwu.yulanzhangaiwu;
-import zhuye.buttonset;
-import bianjie.bianjieguihua2;
-
+import bianjie.Bianjieyouhuatoxy;
 /**
  * 闅滅鐗╂柊澧�/缂栬緫瀵硅瘽妗嗐�傝璁¤瑷�鍙傝�� {@link AddDikuai}锛屾敮鎸侀�氳繃瀹炲湴缁樺埗閲囬泦闅滅鐗╁潗鏍囥��
  */
+import publicway.Gpstoxuzuobiao;
+
 public class addzhangaiwu extends JDialog {
     private static final long serialVersionUID = 1L;
     private static final double METERS_PER_DEGREE_LAT = 111320.0d;
@@ -796,7 +796,7 @@
             return;
         }
         if (userTriggered && "handheld".equalsIgnoreCase(type) && !hasConfiguredHandheldMarker()) {
-            JOptionPane.showMessageDialog(this, "璇峰厛娣诲姞渚挎惡鎵撶偣鍣ㄧ紪鍙�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+            JOptionPane.showMessageDialog(this, "璇峰厛鍘荤郴缁熻缃坊鍔犱究鎼烘墦鐐瑰櫒缂栧彿", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
             return;
         }
         if (selectedMethodPanel != null && selectedMethodPanel != option) {
@@ -921,6 +921,12 @@
             boundaryStatusLabel.setVisible(false);
             boundaryStatusLabel.setText("");
         }
+        // 瀵逛簬鍦嗗舰闅滅鐗╋紝闅愯棌鐢熸垚杈圭晫鎸夐挳
+        String shapeKey = formData.get("obstacleShape");
+        boolean isCircle = "circle".equals(shapeKey);
+        if (isCircle && generateBoundaryButton != null) {
+            generateBoundaryButton.setVisible(false);
+        }
 
         String method = formData.get("drawingMethod");
         if (!isMeaningfulValue(method)) {
@@ -1095,14 +1101,11 @@
                 session.captureMessage = "鏃犳硶鏍规嵁閲囬泦鐨勭偣鐢熸垚鍦嗭紝璇风‘淇濋�夋嫨浜嗕笁涓潪鍏辩嚎鐨勫渾鍛ㄧ偣";
                 return;
             }
-            double[] radiusPoint = pickRadiusPoint(xyPoints, circle);
-            if (radiusPoint == null) {
-                session.captureSuccessful = false;
-                session.captureMessage = "閲囬泦鐨勫渾鍛ㄧ偣寮傚父锛屾棤娉曠敓鎴愬渾";
-                return;
-            }
+            // 浣跨敤璁$畻鍑虹殑鍗婂緞鐢熸垚涓�涓湡姝g殑鍦嗕笂鐐癸紙鍦嗗績鍙充晶鐨勭偣锛夛紝纭繚棰勮鏃惰绠楃殑鍗婂緞鍜岀粨鏉熺粯鍒舵椂鐨勫崐寰勪竴鑷�
+            double radiusX = circle.centerX + circle.radius;
+            double radiusY = circle.centerY;
             String result = String.format(Locale.US, "%.2f,%.2f;%.2f,%.2f",
-                    circle.centerX, circle.centerY, radiusPoint[0], radiusPoint[1]);
+                    circle.centerX, circle.centerY, radiusX, radiusY);
             session.data.put("obstacleCoordinates", result);
             session.captureSuccessful = true;
             session.captureMessage = "宸查噰闆嗗渾褰㈤殰纰嶇墿锛屽叡 " + xyPoints.size() + " 涓偣";
@@ -1213,34 +1216,11 @@
     }
 
     private static double parseDMToDecimal(String dmm, String direction) {
-        if (dmm == null || dmm.trim().isEmpty()) {
-            return Double.NaN;
-        }
-        try {
-            String trimmed = dmm.trim();
-            int dotIndex = trimmed.indexOf('.');
-            if (dotIndex < 2) {
-                return Double.NaN;
-            }
-            int degrees = Integer.parseInt(trimmed.substring(0, dotIndex - 2));
-            double minutes = Double.parseDouble(trimmed.substring(dotIndex - 2));
-            double decimal = degrees + minutes / 60.0;
-            if ("S".equalsIgnoreCase(direction) || "W".equalsIgnoreCase(direction)) {
-                decimal = -decimal;
-            }
-            return decimal;
-        } catch (NumberFormatException ex) {
-            return Double.NaN;
-        }
+        return Gpstoxuzuobiao.parseDMToDecimal(dmm, direction);
     }
 
     private static double[] convertLatLonToLocal(double lat, double lon, double baseLat, double baseLon) {
-        double deltaLat = lat - baseLat;
-        double deltaLon = lon - baseLon;
-        double meanLatRad = Math.toRadians((baseLat + lat) / 2.0);
-        double eastMeters = deltaLon * METERS_PER_DEGREE_LAT * Math.cos(meanLatRad);
-        double northMeters = deltaLat * METERS_PER_DEGREE_LAT;
-        return new double[]{eastMeters, northMeters};
+        return Gpstoxuzuobiao.convertLatLonToLocal(lat, lon, baseLat, baseLon);
     }
 
     private static CircleFitResult fitCircleFromPoints(List<double[]> points) {
@@ -1355,7 +1335,7 @@
         }
         if (!configMap.isEmpty()) {
             List<ExistingObstacle> remaining = new ArrayList<>(configMap.values());
-            remaining.sort(Comparator.comparing(ExistingObstacle::getName, String.CASE_INSENSITIVE_ORDER));
+            remaining.sort((a, b) -> String.CASE_INSENSITIVE_ORDER.compare(a.getName(), b.getName()));
             result.addAll(remaining);
         }
         if (result.isEmpty()) {
@@ -1436,16 +1416,26 @@
             return;
         }
         String coords = formData.get("obstacleCoordinates");
+        String shapeKey = formData.get("obstacleShape");
+        boolean isCircle = "circle".equals(shapeKey);
+        
         if (isMeaningfulValue(coords)) {
-            int count = countCoordinatePairs(coords);
-            drawingStatusLabel.setText("宸查噰闆嗛殰纰嶇墿鏁版嵁锛岀偣鏁帮細" + count);
+            if (isCircle) {
+                // 瀵逛簬鍦嗗舰闅滅鐗╋紝鏄剧ず鍦嗗績鍧愭爣鍜屽崐寰�
+                String statusText = parseCircleStatusText(coords);
+                drawingStatusLabel.setText(statusText);
+            } else {
+                // 瀵逛簬澶氳竟褰㈤殰纰嶇墿锛屾樉绀虹偣鏁�
+                int count = countCoordinatePairs(coords);
+                drawingStatusLabel.setText("宸查噰闆嗛殰纰嶇墿鏁版嵁锛岀偣鏁帮細" + count);
+            }
             if (!drawingInProgress && drawButton != null) {
                 drawButton.setText("閲嶆柊缁樺埗");
                 drawButton.setEnabled(true);
             }
-            // 缁樺埗瀹屾垚鍚庢樉绀�"鐢熸垚闅滅鐗╄竟鐣�"鎸夐挳
+            // 瀵逛簬鍦嗗舰闅滅鐗╋紝涓嶆樉绀�"鐢熸垚闅滅鐗╄竟鐣�"鎸夐挳
             if (generateBoundaryButton != null) {
-                generateBoundaryButton.setVisible(true);
+                generateBoundaryButton.setVisible(!isCircle);
             }
         } else {
             drawingStatusLabel.setText("灏氭湭閲囬泦闅滅鐗╁潗鏍�");
@@ -1493,10 +1483,20 @@
         if (previewButton == null) {
             return;
         }
+        
+        // 瀵逛簬鍦嗗舰闅滅鐗╋紝涓嶆樉绀洪瑙堟寜閽�
+        String shapeKey = formData.get("obstacleShape");
+        boolean isCircle = "circle".equals(shapeKey);
+        if (isCircle) {
+            previewButton.setVisible(false);
+            previewButton.setEnabled(false);
+            return;
+        }
+        
         // 鍙湁鍦ㄧ敓鎴愯竟鐣屽悗鎵嶆樉绀洪瑙堟寜閽�
         String generatedBoundary = formData.get("generatedBoundaryCoordinates");
         boolean hasGeneratedBoundary = isMeaningfulValue(generatedBoundary);
-        
+
         if (hasGeneratedBoundary) {
             // 鐢熸垚杈圭晫鍚庯紝閲嶆柊鍒涘缓缁胯壊鐨勯瑙堟寜閽�
             // 鑾峰彇鎸夐挳鐨勭埗瀹瑰櫒鍜屼綅缃�
@@ -1572,6 +1572,49 @@
         }
         return count;
     }
+    
+    /**
+     * 瑙f瀽鍦嗗舰闅滅鐗╁潗鏍囷紝鐢熸垚鐘舵�佹枃鏈�
+     * 鏍煎紡锛歝enterX,centerY;radiusX,radiusY
+     * 杩斿洖锛氬綋鍓嶉噰闆嗗渾褰㈠渾蹇冨潗鏍噚,y,鍗婂緞n绫�
+     */
+    private String parseCircleStatusText(String coords) {
+        if (!isMeaningfulValue(coords)) {
+            return "灏氭湭閲囬泦鍦嗗舰闅滅鐗╁潗鏍�";
+        }
+        
+        try {
+            String[] pairs = coords.split(";");
+            if (pairs.length < 2) {
+                return "鍦嗗舰闅滅鐗╁潗鏍囨牸寮忛敊璇�";
+            }
+            
+            // 瑙f瀽鍦嗗績鍧愭爣
+            String[] centerParts = pairs[0].trim().split(",");
+            if (centerParts.length < 2) {
+                return "鍦嗗舰闅滅鐗╁潗鏍囨牸寮忛敊璇�";
+            }
+            double centerX = Double.parseDouble(centerParts[0].trim());
+            double centerY = Double.parseDouble(centerParts[1].trim());
+            
+            // 瑙f瀽鍦嗕笂涓�鐐瑰潗鏍�
+            String[] radiusParts = pairs[1].trim().split(",");
+            if (radiusParts.length < 2) {
+                return "鍦嗗舰闅滅鐗╁潗鏍囨牸寮忛敊璇�";
+            }
+            double radiusX = Double.parseDouble(radiusParts[0].trim());
+            double radiusY = Double.parseDouble(radiusParts[1].trim());
+            
+            // 璁$畻鍗婂緞锛堢背锛�
+            double radius = Math.sqrt(Math.pow(radiusX - centerX, 2) + Math.pow(radiusY - centerY, 2));
+            
+            // 鏍煎紡鍖栨樉绀猴細褰撳墠閲囬泦鍦嗗舰鍦嗗績鍧愭爣x,y,鍗婂緞n绫�
+            return String.format(Locale.US, "褰撳墠閲囬泦鍦嗗舰鍦嗗績鍧愭爣%.2f,%.2f,鍗婂緞%.2f绫�", 
+                    centerX, centerY, radius);
+        } catch (Exception e) {
+            return "鍦嗗舰闅滅鐗╁潗鏍囪В鏋愬け璐�";
+        }
+    }
 
     private void updateSaveButtonState() {
         if (saveButton != null) {
@@ -1651,8 +1694,16 @@
 
         String coords = coordsValue.trim();
         String originalCoords = isMeaningfulValue(originalValue) ? originalValue.trim() : null;
-        // 濡傛灉鏈夌敓鎴愮殑杈圭晫鍧愭爣锛屼娇鐢ㄧ敓鎴愮殑杈圭晫鍧愭爣锛涘惁鍒欎娇鐢ㄥ師濮嬪潗鏍�
-        String finalCoords = isMeaningfulValue(generatedBoundaryValue) ? generatedBoundaryValue.trim() : coords;
+        // 瀵逛簬鍦嗗舰闅滅鐗╋紝鐩存帴浣跨敤obstacleCoordinates锛堝湪绗�3涓偣纭鏃跺凡鐢熸垚锛�
+        // 瀵逛簬澶氳竟褰㈤殰纰嶇墿锛屽鏋滄湁鐢熸垚鐨勮竟鐣屽潗鏍囷紝浣跨敤鐢熸垚鐨勮竟鐣屽潗鏍囷紱鍚﹀垯浣跨敤鍘熷鍧愭爣
+        String finalCoords;
+        if ("circle".equals(shapeKey)) {
+            // 鍦嗗舰闅滅鐗╃洿鎺ヤ娇鐢ㄥ凡鐢熸垚鐨勫潗鏍�
+            finalCoords = coords;
+        } else {
+            // 澶氳竟褰㈤殰纰嶇墿浼樺厛浣跨敤鐢熸垚鐨勮竟鐣屽潗鏍�
+            finalCoords = isMeaningfulValue(generatedBoundaryValue) ? generatedBoundaryValue.trim() : coords;
+        }
         String trimmedName = isMeaningfulValue(obstacleName) ? obstacleName.trim() : null;
         if (!isMeaningfulValue(trimmedName)) {
             JOptionPane.showMessageDialog(this, "闅滅鐗╁悕绉版棤鏁�", "閿欒", JOptionPane.ERROR_MESSAGE);
@@ -1694,14 +1745,128 @@
         }
         
         String shapeKey = formData.get("obstacleShape");
-        if (!"polygon".equals(shapeKey)) {
-            JOptionPane.showMessageDialog(this, "鍙湁澶氳竟褰㈤殰纰嶇墿鎵嶉渶瑕佺敓鎴愯竟鐣屽潗鏍�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
-            return;
-        }
         
         try {
-            // 妫�鏌ョ粯鍒舵柟寮忥紝鍙湁鍓茶崏鏈虹粯鍒剁殑澶氳竟褰㈡墠璋冪敤bianjieguihua2
             String method = formData.get("drawingMethod");
+            
+            // 澶勭悊鍦嗗舰闅滅鐗�
+            if ("circle".equals(shapeKey)) {
+                if (!"mower".equals(method)) {
+                    JOptionPane.showMessageDialog(this, "鍙湁鍓茶崏鏈虹粯鍒剁殑鍦嗗舰闅滅鐗╂墠鏀寔鐢熸垚杈圭晫鍧愭爣", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
+                    return;
+                }
+                
+                // 灏嗗師濮嬪潗鏍囪浆鎹负Coordinate瀵硅薄鍒楄〃
+                List<Coordinate> coordinateList = parseOriginalCoordinatesToCoordinateList(originalCoords);
+                if (coordinateList.size() < 3) {
+                    JOptionPane.showMessageDialog(this, "鍦嗗舰闅滅鐗╄嚦灏戦渶瑕佷笁涓噰闆嗙偣", "閿欒", JOptionPane.ERROR_MESSAGE);
+                    return;
+                }
+                
+                // 瑙f瀽鍩虹珯鍧愭爣
+                String[] baseParts = baseStation.split(",");
+                if (baseParts.length < 4) {
+                    JOptionPane.showMessageDialog(this, "鍩虹珯鍧愭爣鏍煎紡鏃犳晥", "閿欒", JOptionPane.ERROR_MESSAGE);
+                    return;
+                }
+                
+                double baseLat = parseDMToDecimal(baseParts[0].trim(), baseParts[1].trim());
+                double baseLon = parseDMToDecimal(baseParts[2].trim(), baseParts[3].trim());
+                
+                // 灏嗗師濮嬪潗鏍囪浆鎹负XY鍧愭爣锛堟湰鍦板潗鏍囩郴锛�
+                List<double[]> xyPoints = new ArrayList<>();
+                for (Coordinate coord : coordinateList) {
+                    double lat = parseDMToDecimal(coord.getLatitude(), coord.getLatDirection());
+                    double lon = parseDMToDecimal(coord.getLongitude(), coord.getLonDirection());
+                    xyPoints.add(convertLatLonToLocal(lat, lon, baseLat, baseLon));
+                }
+                
+                // 浣跨敤ThreePointCircle绠楁硶璁$畻鍦嗗績鍜屽崐寰�
+                if (xyPoints.size() < 3) {
+                    JOptionPane.showMessageDialog(this, "鑷冲皯闇�瑕佷笁涓偣鎵嶈兘鐢熸垚鍦嗗舰杈圭晫", "閿欒", JOptionPane.ERROR_MESSAGE);
+                    return;
+                }
+                
+                // 鍙栧墠涓変釜鐐硅绠楀渾
+                double[] p1 = xyPoints.get(0);
+                double[] p2 = xyPoints.get(1);
+                double[] p3 = xyPoints.get(2);
+                
+                String point1 = String.format(Locale.US, "%.2f,%.2f", p1[0], p1[1]);
+                String point2 = String.format(Locale.US, "%.2f,%.2f", p2[0], p2[1]);
+                String point3 = String.format(Locale.US, "%.2f,%.2f", p3[0], p3[1]);
+                
+                String circleResult = bianjie.ThreePointCircle.getCircleFromPoints(point1, point2, point3);
+                
+                // 瑙f瀽缁撴灉锛氭牸寮忎负 "鍦嗗績: x,y; 鍗婂緞: r"
+                if (circleResult == null || circleResult.startsWith("閿欒")) {
+                    JOptionPane.showMessageDialog(this, "鐢熸垚鍦嗗舰杈圭晫澶辫触: " + circleResult, "閿欒", JOptionPane.ERROR_MESSAGE);
+                    return;
+                }
+                
+                // 瑙f瀽鍦嗗績鍜屽崐寰�
+                String[] parts = circleResult.split(";");
+                if (parts.length < 2) {
+                    JOptionPane.showMessageDialog(this, "瑙f瀽鍦嗗舰杈圭晫缁撴灉澶辫触", "閿欒", JOptionPane.ERROR_MESSAGE);
+                    return;
+                }
+                
+                // 鎻愬彇鍦嗗績鍧愭爣
+                String centerPart = parts[0].trim(); // "鍦嗗績: x,y"
+                String radiusPart = parts[1].trim(); // "鍗婂緞: r"
+                
+                String centerCoords = centerPart.substring(centerPart.indexOf(":") + 1).trim();
+                String radiusStr = radiusPart.substring(radiusPart.indexOf(":") + 1).trim();
+                
+                String[] centerXY = centerCoords.split(",");
+                if (centerXY.length < 2) {
+                    JOptionPane.showMessageDialog(this, "瑙f瀽鍦嗗績鍧愭爣澶辫触", "閿欒", JOptionPane.ERROR_MESSAGE);
+                    return;
+                }
+                
+                double centerX = Double.parseDouble(centerXY[0].trim());
+                double centerY = Double.parseDouble(centerXY[1].trim());
+                double radius = Double.parseDouble(radiusStr.trim());
+                
+                // 璁$畻鍦嗕笂涓�鐐癸紙鍦嗗績鍙充晶鐨勭偣锛�
+                double radiusX = centerX + radius;
+                double radiusY = centerY;
+                
+                // 鐢熸垚杈圭晫鍧愭爣鏍煎紡锛氬渾蹇僗,鍦嗗績Y;鍦嗕笂鐐筙,鍦嗕笂鐐筜
+                String boundaryCoords = String.format(Locale.US, "%.2f,%.2f;%.2f,%.2f", 
+                    centerX, centerY, radiusX, radiusY);
+                
+                // 淇濆瓨鐢熸垚鐨勮竟鐣屽潗鏍�
+                formData.put("generatedBoundaryCoordinates", boundaryCoords);
+                
+                // 鏇存柊杈圭晫鐘舵�佹爣绛炬樉绀猴紙鍦嗗舰鍙湁2涓偣锛氬渾蹇冨拰鍦嗕笂涓�鐐癸級
+                updateBoundaryStatusLabel(2);
+                
+                // 鏇存柊棰勮鎸夐挳鏄剧ず锛堝彉鎴愮豢鑹插彲鐐瑰嚮锛�
+                updatePreviewButtonState();
+                
+                // 鏇存柊淇濆瓨鎸夐挳鐘舵�侊紙鍙樻垚鍙偣鍑伙級
+                updateSaveButtonState();
+                
+                // 寮哄埗鍒锋柊UI
+                SwingUtilities.invokeLater(() -> {
+                    if (previewButton != null) {
+                        previewButton.revalidate();
+                        previewButton.repaint();
+                    }
+                });
+                
+                JOptionPane.showMessageDialog(this, "鍦嗗舰闅滅鐗╄竟鐣屽潗鏍囧凡鐢熸垚", "鎴愬姛", JOptionPane.INFORMATION_MESSAGE);
+                return;
+            }
+            
+            // 澶勭悊澶氳竟褰㈤殰纰嶇墿
+            if (!"polygon".equals(shapeKey)) {
+                JOptionPane.showMessageDialog(this, "鍙湁澶氳竟褰㈡垨鍦嗗舰闅滅鐗╂墠闇�瑕佺敓鎴愯竟鐣屽潗鏍�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
+                return;
+            }
+            
+            // 妫�鏌ョ粯鍒舵柟寮忥紝鍙湁鍓茶崏鏈虹粯鍒剁殑澶氳竟褰㈡墠璋冪敤bianjieguihua2
             if (!"mower".equals(method)) {
                 JOptionPane.showMessageDialog(this, "鍙湁鍓茶崏鏈虹粯鍒剁殑澶氳竟褰㈡墠鏀寔鐢熸垚杈圭晫鍧愭爣", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
                 return;
@@ -1718,14 +1883,13 @@
             List<Coordinate> savedCoordinates = new ArrayList<>(Coordinate.coordinates);
             
             try {
-                // 璁剧疆鍒板叏灞�鍧愭爣鍒楄〃
-                Coordinate.coordinates.clear();
-                Coordinate.coordinates.addAll(coordinateList);
+                // 鏋勫缓杈圭晫瀛楃涓诧紝鏍煎紡涓� "(lat1,lon1,alt1;lat2,lon2,alt2;...)"
+                String boundaryStr = buildBoundaryStringForOptimization(coordinateList);
                 
-                // 璋冪敤bianjieguihua2绠楁硶鐢熸垚浼樺寲鍚庣殑澶氳竟褰㈣竟鐣屽潗鏍�
-                String optimizedCoordsStr = bianjieguihua2.processCoordinateListAuto(baseStation);
+                // 璋冪敤 Bianjieyouhuatoxy.optimizeBoundary 鏂规硶鐢熸垚浼樺寲鍚庣殑澶氳竟褰㈣竟鐣屽潗鏍�
+                String optimizedCoordsStr = Bianjieyouhuatoxy.optimizeBoundary(baseStation, boundaryStr);
                 
-                if (optimizedCoordsStr == null || optimizedCoordsStr.trim().isEmpty()) {
+                if (optimizedCoordsStr == null || optimizedCoordsStr.trim().isEmpty() || optimizedCoordsStr.startsWith("ERROR")) {
                     JOptionPane.showMessageDialog(this, "鐢熸垚杈圭晫鍧愭爣澶辫触", "閿欒", JOptionPane.ERROR_MESSAGE);
                     return;
                 }
@@ -1803,6 +1967,34 @@
     }
     
     /**
+     * 鏋勫缓鐢ㄤ簬浼樺寲鐨勮竟鐣屽瓧绗︿覆锛屾牸寮忎负 "(lat1,lon1,alt1;lat2,lon2,alt2;...)"
+     * 鍏朵腑lat鍜宭on鏄害鍒嗘牸寮忥紙DMM鏍煎紡锛夛紝渚嬪 "3949.89151752"
+     */
+    private String buildBoundaryStringForOptimization(List<Coordinate> coordinates) {
+        if (coordinates == null || coordinates.isEmpty()) {
+            return "()";
+        }
+        StringBuilder sb = new StringBuilder("(");
+        java.text.DecimalFormat elevationFormat = new java.text.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 void previewObstacleBoundary() {
@@ -1816,6 +2008,36 @@
         String landName = targetDikuai.getLandName();
         String boundary = targetDikuai.getBoundaryCoordinates();
         
+        // 鑾峰彇闅滅鐗╁潗鏍囷紙浼樺厛浣跨敤鐢熸垚鐨勮竟鐣屽潗鏍囷紝濡傛灉娌℃湁鍒欎娇鐢ㄥ師濮嬪潗鏍囷級
+        String obstacleCoords = generatedBoundary;
+        String shapeKey = formData.get("obstacleShape");
+        String obstacleName = formData.get("obstacleName");
+        
+        // 瀵逛簬鍦嗗舰闅滅鐗╋紝鐢熸垚鐨勮竟鐣屽潗鏍囨牸寮忓氨鏄殰纰嶇墿鍧愭爣鏍煎紡锛屽彲浠ョ洿鎺ヤ娇鐢�
+        // 瀵逛簬澶氳竟褰㈤殰纰嶇墿锛屼篃闇�瑕佷娇鐢ㄧ敓鎴愮殑杈圭晫鍧愭爣
+        // 濡傛灉鐢熸垚鐨勮竟鐣屽潗鏍囦笉鍙敤锛屽皾璇曚娇鐢ㄥ師濮嬮殰纰嶇墿鍧愭爣
+        if (!isMeaningfulValue(obstacleCoords)) {
+            obstacleCoords = formData.get("obstacleCoordinates");
+            if (!isMeaningfulValue(obstacleCoords)) {
+                JOptionPane.showMessageDialog(this, "鏃犳硶鑾峰彇闅滅鐗╁潗鏍囪繘琛岄瑙�", "鎻愮ず", JOptionPane.INFORMATION_MESSAGE);
+                return;
+            }
+        }
+        
+        // 鏋勫缓闅滅鐗╂暟鎹瓧绗︿覆锛屽寘鍚悕绉般�佸舰鐘跺拰鍧愭爣
+        // 鏍煎紡锛氶殰纰嶇墿鍚嶇О::褰㈢姸::鍧愭爣 鎴� 闅滅鐗╁悕绉�:褰㈢姸:鍧愭爣
+        final String obstacleData;
+        if (isMeaningfulValue(obstacleName) && isMeaningfulValue(shapeKey)) {
+            // 浣跨敤 :: 鍒嗛殧绗︽牸寮忥細鍚嶇О::褰㈢姸::鍧愭爣
+            obstacleData = obstacleName.trim() + "::" + shapeKey.trim() + "::" + obstacleCoords;
+        } else if (isMeaningfulValue(shapeKey)) {
+            // 鍙湁褰㈢姸锛氬舰鐘�::鍧愭爣
+            obstacleData = shapeKey.trim() + "::" + obstacleCoords;
+        } else {
+            // 鍙湁鍧愭爣
+            obstacleData = obstacleCoords;
+        }
+        
         // 鍏抽棴褰撳墠瀵硅瘽妗�
         setVisible(false);
         
@@ -1827,7 +2049,7 @@
                     landNumber,
                     landName,
                     boundary,
-                    generatedBoundary,  // 浣跨敤鐢熸垚鐨勮竟鐣屽潗鏍囦綔涓洪殰纰嶇墿鍧愭爣
+                    obstacleData,  // 浣跨敤鍖呭惈鍚嶇О鍜屽舰鐘剁殑闅滅鐗╂暟鎹�
                     null,
                     () -> SwingUtilities.invokeLater(() -> {
                         // 閲嶆柊鎵撳紑鏂板闅滅鐗╂楠�2椤甸潰
@@ -2056,6 +2278,17 @@
             saveButton.setVisible(true);
             updateDrawingStatus();
             updatePreviewButtonState();
+            // 瀵逛簬鍦嗗舰闅滅鐗╋紝纭繚棰勮鎸夐挳鍜岀敓鎴愯竟鐣屾寜閽殣钘�
+            String shapeKey = formData.get("obstacleShape");
+            boolean isCircle = "circle".equals(shapeKey);
+            if (isCircle) {
+                if (previewButton != null) {
+                    previewButton.setVisible(false);
+                }
+                if (generateBoundaryButton != null) {
+                    generateBoundaryButton.setVisible(false);
+                }
+            }
         }
         updateSaveButtonState();
         revalidate();

--
Gitblit v1.10.0