From 5b685e9066ccfbc432c29739b5524f1d42a20891 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期一, 22 十二月 2025 19:37:30 +0800
Subject: [PATCH] 进一步优化边界管理页面功能

---
 src/zhuye/MapRenderer.java | 2203 ++++++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 1,788 insertions(+), 415 deletions(-)

diff --git a/src/zhuye/MapRenderer.java b/src/zhuye/MapRenderer.java
index 3352dc2..9db0014 100644
--- a/src/zhuye/MapRenderer.java
+++ b/src/zhuye/MapRenderer.java
@@ -10,32 +10,43 @@
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 import java.math.BigDecimal;
-import java.text.SimpleDateFormat;
+import java.util.ArrayDeque;
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.Date;
+import java.util.Deque;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Set;
+import java.io.File;
+import set.Setsys;
 import gecaoji.Device;
 import gecaoji.Gecaoji;
+import gecaoji.GecaojiMeg;
+import gecaoji.gecaolunjing;
+import gecaoji.lujingdraw;
 import dikuai.Dikuaiguanli;
 import dikuai.Dikuai;
 import zhangaiwu.Obstacledraw;
 import zhangaiwu.Obstacledge;
 import zhangaiwu.yulanzhangaiwu;
+import yaokong.Control03;
+import bianjie.shudongdraw;
 
 /**
  * 鍦板浘娓叉煋鍣� - 璐熻矗鍧愭爣绯荤粯鍒躲�佽鍥惧彉鎹㈢瓑鍔熻兘
  */
 public class MapRenderer {
     // 瑙嗗浘鍙樻崲鍙傛暟
-    private double scale = 1.0;
+    private static final double DEFAULT_SCALE = 20.0; // 榛樿缂╂斁姣斾緥
+    private double scale = DEFAULT_SCALE;
     private double translateX = 0.0;
     private double translateY = 0.0;
     private Point lastDragPoint;
-    private Point mousePoint;
+    private static final double MIN_SCALE = 0.05d;
+    private static final double MAX_SCALE = 50.0d;
+    private static final double SCALE_EPSILON = 1e-6d;
+    private static final String MAP_SCALE_PROPERTY = "mapScale"; // 灞炴�ф枃浠朵腑鐨勯敭鍚�
     
     // 涓婚棰滆壊
     private final Color THEME_COLOR = new Color(46, 139, 87);
@@ -43,20 +54,18 @@
     private static final Color GRASS_FILL_COLOR = new Color(144, 238, 144, 120);
     private static final Color GRASS_BORDER_COLOR = new Color(60, 179, 113);
     private static final Color BOUNDARY_POINT_COLOR = new Color(128, 0, 128);
-    private static final Color BOUNDARY_LABEL_COLOR = Color.BLACK;
+    private static final Color OBSTACLE_POINT_COLOR = new Color(255, 140, 0); // 姗欒壊锛岀敤浜庡尯鍒嗛殰纰嶇墿鐐�
     private static final Color CIRCLE_SAMPLE_COLOR = new Color(220, 20, 60, 230);
     private static final double CIRCLE_SAMPLE_SIZE = 0.54d;
     private static final double BOUNDARY_POINT_MERGE_THRESHOLD = 0.05;
-    private static final SimpleDateFormat TIMESTAMP_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-    private static final Color HANDHELD_BOUNDARY_FILL = new Color(51, 153, 255, 60);
-    private static final Color HANDHELD_BOUNDARY_BORDER = new Color(51, 102, 204, 220);
-    private static final Color HANDHELD_BOUNDARY_POINT = new Color(51, 102, 204);
-    private static final Color HANDHELD_BOUNDARY_LABEL = new Color(22, 62, 138);
+    private static final double BOUNDARY_CONTAINS_TOLERANCE = 0.05;
+    private static final double PREVIEW_BOUNDARY_MARKER_SCALE = 0.25d;
     
     // 缁勪欢寮曠敤
     private JPanel visualizationPanel;
     private List<Point2D.Double> currentBoundary;
     private Rectangle2D.Double boundaryBounds;
+    private Path2D.Double currentBoundaryPath;
     private List<Point2D.Double> currentPlannedPath;
     private Rectangle2D.Double plannedPathBounds;
     private List<Obstacledge.Obstacle> currentObstacles;
@@ -65,24 +74,22 @@
     private String currentObstacleLandNumber;
     private String boundaryName;
     private boolean boundaryPointsVisible;
+    private boolean obstaclePointsVisible;
+    private boolean boundaryLengthVisible = false;  // 鏄惁鏄剧ず杈圭晫璺濈锛岄粯璁ゅ叧闂�
+    private double boundaryPointSizeScale = 1.0d;
+    private boolean previewSizingEnabled;
     private String currentBoundaryLandNumber;
     private boolean dragInProgress;
     private final Gecaoji mower;
     private final Timer mowerUpdateTimer;
-    private JDialog mowerInfoDialog;
-    private Timer mowerInfoRefreshTimer;
-    private JLabel mowerNumberValueLabel;
-    private JLabel realtimeXValueLabel;
-    private JLabel realtimeYValueLabel;
-    private JLabel positioningStatusValueLabel;
-    private JLabel satelliteCountValueLabel;
-    private JLabel realtimeSpeedValueLabel;
-    private JLabel headingValueLabel;
-    private JLabel updateTimeValueLabel;
+    private final GecaojiMeg mowerInfoManager;
     private CircleCaptureOverlay circleCaptureOverlay;
     private final List<double[]> circleSampleMarkers = new ArrayList<>();
     private final List<Point2D.Double> realtimeMowingTrack = new ArrayList<>();
+    private final List<Point2D.Double> navigationPreviewTrack = new ArrayList<>(); // 瀵艰埅棰勮杞ㄨ抗
+    private final Deque<tuowei.TrailSample> idleMowerTrail = new ArrayDeque<>();
     private final List<Point2D.Double> handheldBoundaryPreview = new ArrayList<>();
+    private double boundaryPreviewMarkerScale = 1.0d;
     private boolean realtimeTrackRecording;
     private String realtimeTrackLandNumber;
     private double mowerEffectiveWidthMeters;
@@ -93,16 +100,92 @@
     private double mowingCompletionRatio;
     private long lastTrackPersistTimeMillis;
     private boolean trackDirty;
+    private boolean measurementModeActive = false;  // 娴嬮噺妯″紡鏄惁婵�娲�
     private boolean handheldBoundaryPreviewActive;
+    private boolean pendingTrackBreak = true;
+    private bianjie.shudongdraw manualBoundaryDrawer = new bianjie.shudongdraw();  // 鎵嬪姩缁樺埗杈圭晫缁樺埗鍣�
+    private boolean idleTrailSuppressed;
+    private Path2D.Double realtimeBoundaryPathCache;
+    private String realtimeBoundaryPathLand;
+    private WangfanDraw returnPathDrawer;  // 寰�杩旇矾寰勭粯鍒剁鐞嗗櫒
+    private List<Point2D.Double> currentReturnPath; // 褰撳墠鍦板潡鐨勫線杩旇矾寰勶紙鐢ㄤ簬鏄剧ず锛�
+    private List<Point2D.Double> previewReturnPath; // 棰勮鐨勫線杩旇矾寰�
+    private List<Point2D.Double> previewOriginalBoundary; // 棰勮鐨勫師濮嬭竟鐣岋紙绱壊锛�
+    private List<Point2D.Double> previewOptimizedBoundary; // 棰勮鐨勪紭鍖栧悗杈圭晫
+    private boolean boundaryPreviewActive; // 鏄惁澶勪簬杈圭晫棰勮妯″紡
 
-    private static final double TRACK_SAMPLE_MIN_DISTANCE_METERS = 0.1d;
+    private static final double TRACK_SAMPLE_MIN_DISTANCE_METERS = 0.2d;
+    private static final double TRACK_DUPLICATE_TOLERANCE_METERS = 1e-3d;
     private static final long TRACK_PERSIST_INTERVAL_MS = 5_000L;
+    public static final int DEFAULT_IDLE_TRAIL_DURATION_SECONDS = 60;
+    private static final double IDLE_TRAIL_SAMPLE_DISTANCE_METERS = 0.05d;
+    private long idleTrailDurationMs = DEFAULT_IDLE_TRAIL_DURATION_SECONDS * 1_000L;
+    private static final double ZOOM_STEP_FACTOR = 1.2d;
     
     public MapRenderer(JPanel visualizationPanel) {
         this.visualizationPanel = visualizationPanel;
         this.mower = new Gecaoji();
         this.mowerUpdateTimer = createMowerTimer();
+        this.mowerInfoManager = new GecaojiMeg(visualizationPanel, mower);
         setupMouseListeners();
+        // 浠庨厤缃枃浠惰鍙栦笂娆′繚瀛樼殑缂╂斁姣斾緥鍜岃鍥句腑蹇冨潗鏍�
+        loadViewSettingsFromProperties();
+    }
+    
+    /**
+     * 浠庨厤缃枃浠惰鍙栫缉鏀炬瘮渚嬪拰瑙嗗浘涓績鍧愭爣
+     */
+    private void loadViewSettingsFromProperties() {
+        // 鍔犺浇缂╂斁姣斾緥
+        String scaleValue = Setsys.getPropertyValue(MAP_SCALE_PROPERTY);
+        if (scaleValue != null && !scaleValue.trim().isEmpty()) {
+            try {
+                double savedScale = Double.parseDouble(scaleValue.trim());
+                // 楠岃瘉缂╂斁姣斾緥鏄惁鍦ㄦ湁鏁堣寖鍥村唴
+                if (savedScale >= MIN_SCALE && savedScale <= MAX_SCALE) {
+                    scale = savedScale;
+                } else {
+                    scale = DEFAULT_SCALE;
+                }
+            } catch (NumberFormatException e) {
+                // 濡傛灉瑙f瀽澶辫触锛屼娇鐢ㄩ粯璁ゅ��
+                scale = DEFAULT_SCALE;
+            }
+        } else {
+            // 濡傛灉娌℃湁淇濆瓨鐨勫�硷紝浣跨敤榛樿鍊�
+            scale = DEFAULT_SCALE;
+        }
+        
+        // 鍔犺浇瑙嗗浘涓績鍧愭爣
+        String viewCenterXValue = Setsys.getPropertyValue("viewCenterX");
+        String viewCenterYValue = Setsys.getPropertyValue("viewCenterY");
+        if (viewCenterXValue != null && !viewCenterXValue.trim().isEmpty()) {
+            try {
+                translateX = Double.parseDouble(viewCenterXValue.trim());
+            } catch (NumberFormatException e) {
+                translateX = 0.0;
+            }
+        } else {
+            translateX = 0.0;
+        }
+        if (viewCenterYValue != null && !viewCenterYValue.trim().isEmpty()) {
+            try {
+                translateY = Double.parseDouble(viewCenterYValue.trim());
+            } catch (NumberFormatException e) {
+                translateY = 0.0;
+            }
+        } else {
+            translateY = 0.0;
+        }
+    }
+    
+    /**
+     * 淇濆瓨缂╂斁姣斾緥鍒伴厤缃枃浠�
+     */
+    private void saveScaleToProperties() {
+        Setsys setsys = new Setsys();
+        // 淇濈暀2浣嶅皬鏁�
+        setsys.updateProperty(MAP_SCALE_PROPERTY, String.format("%.2f", scale));
     }
     
     /**
@@ -111,10 +194,10 @@
     private void setupMouseListeners() {
         // 榧犳爣婊氳疆缂╂斁
         visualizationPanel.addMouseWheelListener(e -> {
-            mousePoint = e.getPoint();
+            Point referencePoint = e.getPoint();
             int notches = e.getWheelRotation();
-            double zoomFactor = notches < 0 ? 1.2 : 1/1.2;
-            zoomAtPoint(zoomFactor);
+            double zoomFactor = notches < 0 ? ZOOM_STEP_FACTOR : 1 / ZOOM_STEP_FACTOR;
+            zoomAtPoint(referencePoint, zoomFactor);
         });
         
         // 榧犳爣鎷栨嫿绉诲姩
@@ -132,6 +215,14 @@
                 lastDragPoint = null;
                 dragInProgress = false;
             }
+            
+            public void mouseExited(MouseEvent e) {
+                // 榧犳爣绂诲紑闈㈡澘鏃讹紝娓呴櫎榧犳爣浣嶇疆鏄剧ず
+                if (manualBoundaryDrawer.isManualBoundaryDrawingMode()) {
+                    manualBoundaryDrawer.clearMousePosition();
+                    visualizationPanel.repaint();
+                }
+            }
 
             public void mouseClicked(MouseEvent e) {
                 if (dragInProgress) {
@@ -141,9 +232,30 @@
                 if (!SwingUtilities.isLeftMouseButton(e) || e.getClickCount() != 1) {
                     return;
                 }
+                // 浼樺厛澶勭悊鎵嬪姩缁樺埗杈圭晫妯″紡鐐瑰嚮
+                if (manualBoundaryDrawer.isManualBoundaryDrawingMode()) {
+                    Point2D.Double worldPoint = screenToWorld(e.getPoint());
+                    if (manualBoundaryDrawer.handleClick(worldPoint)) {
+                        visualizationPanel.repaint();
+                        return;
+                    }
+                }
+                // 浼樺厛澶勭悊娴嬮噺妯″紡鐐瑰嚮
+                if (measurementModeActive && handleMeasurementClick(e.getPoint())) {
+                    return;
+                }
                 if (handleMowerClick(e.getPoint())) {
                     return;
                 }
+                // 浼樺厛澶勭悊浼樺寲鍚庤竟鐣屽潗鏍囩偣鐐瑰嚮锛堣竟鐣岄瑙堟ā寮忎笅锛�
+                if (boundaryPreviewActive && handleOptimizedBoundaryPointClick(e.getPoint())) {
+                    return;
+                }
+                // 浼樺厛澶勭悊闅滅鐗╄竟鐣岀偣鐐瑰嚮锛堝鏋滃彲瑙侊級
+                if (obstaclePointsVisible && handleObstaclePointClick(e.getPoint())) {
+                    return;
+                }
+                // 鐒跺悗澶勭悊鍦板潡杈圭晫鐐圭偣鍑�
                 if (boundaryPointsVisible) {
                     handleBoundaryPointClick(e.getPoint());
                 }
@@ -166,9 +278,14 @@
             }
             
             public void mouseMoved(MouseEvent e) {
-                // 鏇存柊榧犳爣浣嶇疆鐢ㄤ簬鏄剧ず鍧愭爣
-                mousePoint = e.getPoint();
-                visualizationPanel.repaint();
+                // 鍦ㄦ墜鍔ㄧ粯鍒惰竟鐣屾ā寮忔椂锛屾洿鏂伴紶鏍囦綅缃�
+                if (manualBoundaryDrawer.isManualBoundaryDrawingMode()) {
+                    Point2D.Double worldPoint = screenToWorld(e.getPoint());
+                    manualBoundaryDrawer.updateMousePosition(worldPoint);
+                    visualizationPanel.repaint();
+                } else {
+                    manualBoundaryDrawer.clearMousePosition();
+                }
             }
         });
     }
@@ -176,6 +293,7 @@
     private Timer createMowerTimer() {
         Timer timer = new Timer(300, e -> {
             mower.refreshFromDevice();
+            updateIdleMowerTrail();
             if (realtimeTrackRecording) {
                 captureRealtimeTrackPoint();
             }
@@ -192,34 +310,71 @@
     /**
      * 鍩轰簬榧犳爣浣嶇疆鐨勭缉鏀�
      */
-    private void zoomAtPoint(double zoomFactor) {
-        if (mousePoint == null) return;
-        
-        // 璁$畻榧犳爣浣嶇疆鍦ㄤ笘鐣屽潗鏍囩郴涓殑鍧愭爣
-        double worldX = (mousePoint.x - visualizationPanel.getWidth()/2) / scale - translateX;
-        double worldY = (mousePoint.y - visualizationPanel.getHeight()/2) / scale - translateY;
+    private void zoomAtPoint(Point referencePoint, double zoomFactor) {
+        if (visualizationPanel == null) {
+            return;
+        }
+        if (referencePoint == null) {
+            referencePoint = new Point(visualizationPanel.getWidth() / 2, visualizationPanel.getHeight() / 2);
+        }
 
-        scale *= zoomFactor;
-        scale = Math.max(0.05, Math.min(scale, 50.0)); // 闄愬埗缂╂斁鑼冨洿锛屽厑璁告渶澶氱缉灏忚嚦鍘熷鐨�1/20
-        
-        // 璁$畻缂╂斁鍚庡悓涓�榧犳爣浣嶇疆鍦ㄤ笘鐣屽潗鏍囩郴涓殑鏂板潗鏍�
-        double newWorldX = (mousePoint.x - visualizationPanel.getWidth()/2) / scale - translateX;
-        double newWorldY = (mousePoint.y - visualizationPanel.getHeight()/2) / scale - translateY;
-        
-        // 璋冩暣骞崇Щ閲忥紝浣块紶鏍囨寚鍚戠殑涓栫晫鍧愭爣淇濇寔涓嶅彉
+        double panelCenterX = visualizationPanel.getWidth() / 2.0;
+        double panelCenterY = visualizationPanel.getHeight() / 2.0;
+
+        double worldX = (referencePoint.x - panelCenterX) / scale - translateX;
+        double worldY = (referencePoint.y - panelCenterY) / scale - translateY;
+
+    scale *= zoomFactor;
+    scale = Math.max(MIN_SCALE, Math.min(scale, MAX_SCALE)); // 闄愬埗缂╂斁鑼冨洿锛屽厑璁告渶澶氱缉灏忚嚦鍘熷鐨�1/20
+
+        double newWorldX = (referencePoint.x - panelCenterX) / scale - translateX;
+        double newWorldY = (referencePoint.y - panelCenterY) / scale - translateY;
+
         translateX += (newWorldX - worldX);
         translateY += (newWorldY - worldY);
-        
+
+        // 淇濆瓨缂╂斁姣斾緥鍒伴厤缃枃浠�
+        saveScaleToProperties();
         visualizationPanel.repaint();
     }
+
+    public void zoomInFromCenter() {
+        zoomAtPoint(null, ZOOM_STEP_FACTOR);
+    }
+
+    public void zoomOutFromCenter() {
+        zoomAtPoint(null, 1 / ZOOM_STEP_FACTOR);
+    }
+    
+    public boolean canZoomIn() {
+        return scale < MAX_SCALE - SCALE_EPSILON;
+    }
+
+    public boolean canZoomOut() {
+        return scale > MIN_SCALE + SCALE_EPSILON;
+    }
+
+    public double getScale() {
+        return scale;
+    }
+
+    public double getMaxScale() {
+        return MAX_SCALE;
+    }
+
+    public double getMinScale() {
+        return MIN_SCALE;
+    }
     
     /**
      * 閲嶇疆瑙嗗浘
      */
     public void resetView() {
-        scale = 1.0;
+        scale = DEFAULT_SCALE;
         translateX = 0.0;
         translateY = 0.0;
+        // 淇濆瓨缂╂斁姣斾緥鍒伴厤缃枃浠�
+        saveScaleToProperties();
         visualizationPanel.repaint();
     }
     
@@ -245,12 +400,14 @@
         boolean hasPlannedPath = currentPlannedPath != null && currentPlannedPath.size() >= 2;
         boolean hasObstacles = currentObstacles != null && !currentObstacles.isEmpty();
 
+        // 缁樺埗鍦板潡杈圭晫锛堝簳灞傦級
         if (hasBoundary) {
             drawCurrentBoundary(g2d);
         }
-
-        if (hasObstacles) {
-            Obstacledraw.drawObstacles(g2d, currentObstacles, scale, selectedObstacleName);
+        
+        // 缁樺埗杈圭晫棰勮锛堝師濮嬭竟鐣�-绱壊锛屼紭鍖栧悗杈圭晫锛�
+        if (boundaryPreviewActive) {
+            drawBoundaryPreview(g2d);
         }
 
         yulanzhangaiwu.renderPreview(g2d, scale);
@@ -263,34 +420,95 @@
             drawCircleCaptureOverlay(g2d, circleCaptureOverlay, scale);
         }
 
-        if (handheldBoundaryPreviewActive) {
-            drawHandheldBoundaryPreview(g2d);
-        }
+    adddikuaiyulan.drawPreview(g2d, handheldBoundaryPreview, scale, handheldBoundaryPreviewActive, boundaryPreviewMarkerScale);
 
-        if (hasPlannedPath) {
+        // 缁樺埗鎵嬪姩缁樺埗鐨勮竟鐣�
+        manualBoundaryDrawer.drawBoundary(g2d, scale);
+        
+        // 缁樺埗榧犳爣瀹炴椂浣嶇疆锛堟墜鍔ㄧ粯鍒惰竟鐣屾ā寮忔椂锛�
+        manualBoundaryDrawer.drawMousePosition(g2d, scale);
+
+        // 缁樺埗瀵艰埅璺緞锛堜腑灞傦級- 杈圭晫棰勮妯″紡涓嬩笉鏄剧ず瀵艰埅璺緞
+        if (hasPlannedPath && !boundaryPreviewActive) {
             drawCurrentPlannedPath(g2d);
         }
 
-        if (boundaryPointsVisible && hasBoundary) {
-            pointandnumber.drawBoundaryPoints(
-                g2d,
-                currentBoundary,
-                scale,
-                BOUNDARY_POINT_MERGE_THRESHOLD,
-                BOUNDARY_POINT_COLOR,
-                BOUNDARY_LABEL_COLOR
-            );
+        // 缁樺埗闅滅鐗╋紙椤跺眰锛屾樉绀哄湪鍦板潡鍜屽鑸矾寰勪笂鏂癸級
+        if (hasObstacles) {
+            Obstacledraw.drawObstacles(g2d, currentObstacles, scale, selectedObstacleName);
+        }
+
+        // 鏄剧ず杈圭晫鐐癸紙濡傛灉杈圭晫鐐瑰彲瑙侊紝鎴栬�呰竟鐣岃窛绂诲彲瑙侊級
+        if ((boundaryPointsVisible || boundaryLengthVisible) && hasBoundary) {
+            // 棰勮妯″紡涓嬫樉绀哄簭鍙�
+            if (previewSizingEnabled) {
+                drawBoundaryPointsWithNumbers(g2d, currentBoundary, scale);
+            } else {
+                double markerScale = boundaryPointSizeScale;
+                pointandnumber.drawBoundaryPoints(
+                    g2d,
+                    currentBoundary,
+                    scale,
+                    BOUNDARY_POINT_MERGE_THRESHOLD,
+                    BOUNDARY_POINT_COLOR,
+                    markerScale
+                );
+            }
+        }
+        
+        // 缁樺埗闅滅鐗╁潗鏍囩偣锛堝甫搴忓彿锛�
+        if (obstaclePointsVisible && hasObstacles) {
+            drawObstaclePointsWithNumbers(g2d, currentObstacles, scale);
+        }
+
+        if (shouldRenderIdleTrail()) {
+            tuowei.draw(g2d, idleMowerTrail, scale);
         }
 
         if (!realtimeMowingTrack.isEmpty()) {
             drawRealtimeMowingCoverage(g2d);
         }
+        
+        // 缁樺埗瀵艰埅棰勮宸插壊鍖哄煙
+        if (!navigationPreviewTrack.isEmpty()) {
+            drawNavigationPreviewCoverage(g2d);
+        }
+
+        // 鍏堢敾寰�杩旇矾寰勶紙绾�+鐐癸級锛屼繚璇佸壊鑽夋満鍥炬爣鍦ㄥ叾涓婃柟
+        if (returnPathDrawer != null && returnPathDrawer.isActive()) {
+            returnPathDrawer.draw(g2d, scale);
+        } else if (previewReturnPath != null && !previewReturnPath.isEmpty()) {
+            // 缁樺埗棰勮鐨勫線杩旇矾寰勶紙閾佺嚎璺浘椋庢牸锛�
+            WangfanDraw.drawRailwayPath(g2d, previewReturnPath, scale);
+        } else if (currentReturnPath != null && !currentReturnPath.isEmpty()) {
+            // 缁樺埗淇濆瓨鐨勫線杩旇矾寰勶紙閾佺嚎璺浘椋庢牸锛�
+            WangfanDraw.drawRailwayPath(g2d, currentReturnPath, scale);
+        }
 
         drawMower(g2d);
         
+        // 缁樺埗瀵艰埅棰勮閫熷害锛堝鏋滄鍦ㄥ鑸瑙堬級
+        if (navigationPreviewSpeed > 0 && mower != null && mower.hasValidPosition()) {
+            drawNavigationPreviewSpeed(g2d, scale);
+        }
+        
+        // 缁樺埗娴嬮噺妯″紡锛堝鏋滄縺娲伙級
+        if (measurementModeActive) {
+            drawMeasurementMode(g2d, scale);
+        }
+        
+        // 淇濆瓨褰撳墠鍙樻崲锛堝寘鍚鍥惧彉鎹級鐢ㄤ簬鍧愭爣杞崲
+        AffineTransform currentTransformForLength = g2d.getTransform();
+        
         // 鎭㈠鍘熷鍙樻崲
         g2d.setTransform(originalTransform);
         
+        // 缁樺埗杈圭晫闀垮害锛堝鏋滃惎鐢級- 鍦ㄦ仮澶嶅師濮嬪彉鎹㈠悗缁樺埗
+        if (boundaryLengthVisible && hasBoundary) {
+            bianjie.BoundaryLengthDrawer.drawBoundaryLengths(g2d, currentBoundary, scale, 
+                visualizationPanel.getWidth(), visualizationPanel.getHeight(), translateX, translateY);
+        }
+        
         // 缁樺埗瑙嗗浘淇℃伅
         drawViewInfo(g2d);
     }
@@ -301,7 +519,7 @@
     private void drawCoordinateSystem(Graphics2D g2d) {
         // 缁樺埗鍘熺偣 - 绾㈣壊瀹炲績灏忓渾鍦�
         g2d.setColor(Color.RED);
-        g2d.fillOval(-1, -1, 2, 2);      
+        g2d.fill(new Ellipse2D.Double(-0.5d, -0.5d, 1d, 1d));
     }
     
     
@@ -312,153 +530,373 @@
     private void drawMower(Graphics2D g2d) {
         mower.draw(g2d, scale);
     }
-
-    private void drawRealtimeMowingCoverage(Graphics2D g2d) {
-        if (realtimeMowingTrack.size() < 2) {
+    
+    /**
+     * 缁樺埗瀵艰埅棰勮閫熷害锛堝湪鍓茶崏鏈哄浘鏍囦笂鏂癸級
+     */
+    private void drawNavigationPreviewSpeed(Graphics2D g2d, double scale) {
+        if (mower == null || !mower.hasValidPosition()) {
             return;
         }
-
-        Path2D.Double path = new Path2D.Double();
-        boolean started = false;
-        for (Point2D.Double point : realtimeMowingTrack) {
-            if (point == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
-                continue;
-            }
-            if (!started) {
-                path.moveTo(point.x, point.y);
-                started = true;
-            } else {
-                path.lineTo(point.x, point.y);
-            }
-        }
-
-        if (!started) {
+        
+        Point2D.Double mowerPos = mower.getPosition();
+        if (mowerPos == null) {
             return;
         }
-
-        Stroke originalStroke = g2d.getStroke();
-        Color originalColor = g2d.getColor();
-
-        double effectiveWidth = getEffectiveMowerWidthMeters();
-        if (effectiveWidth > 0) {
-            float coverageWidth = (float) Math.max(effectiveWidth, 0.1d);
-            g2d.setStroke(new BasicStroke(coverageWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
-            g2d.setColor(new Color(46, 139, 87, 80));
-            g2d.draw(path);
-        }
-
-        float spineWidth = (float) (effectiveWidth > 0 ? Math.max(effectiveWidth / 4.0, 0.18d) : 0.3d);
-        g2d.setStroke(new BasicStroke(spineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
-        g2d.setColor(new Color(34, 139, 34, 200));
-        g2d.draw(path);
-
-        g2d.setStroke(originalStroke);
-        g2d.setColor(originalColor);
+        
+        // 灏嗛�熷害浠庣背/绉掕浆鎹负KM/h
+        double speedKmh = navigationPreviewSpeed * 3.6;
+        String speedText = String.format("%.1f km/h", speedKmh);
+        
+        // 淇濆瓨鍘熷鍙樻崲
+        AffineTransform originalTransform = g2d.getTransform();
+        
+        // 灏嗕笘鐣屽潗鏍囪浆鎹负灞忓箷鍧愭爣
+        Point2D.Double screenPos = worldToScreen(mowerPos);
+        
+        // 鎭㈠鍘熷鍙樻崲浠ョ粯鍒舵枃瀛楋紙鍥哄畾澶у皬锛屼笉闅忕缉鏀惧彉鍖栵級
+        g2d.setTransform(new AffineTransform());
+        
+        // 璁剧疆瀛椾綋锛堜笌缂╂斁鏂囧瓧澶у皬涓�鑷达紝11鍙峰瓧浣擄級
+        Font labelFont = new Font("寰蒋闆呴粦", Font.PLAIN, 11);
+        g2d.setFont(labelFont);
+        FontMetrics metrics = g2d.getFontMetrics(labelFont);
+        
+        // 璁$畻鏂囧瓧浣嶇疆锛堝湪鍓茶崏鏈哄浘鏍囦笂鏂癸級
+        int textWidth = metrics.stringWidth(speedText);
+        int textHeight = metrics.getHeight();
+        int textX = (int)Math.round(screenPos.x - textWidth / 2.0);
+        // 鍦ㄥ壊鑽夋満鍥炬爣涓婃柟锛岀暀鍑轰竴瀹氶棿璺�
+        // 鍥炬爣鍦ㄤ笘鐣屽潗鏍囩郴涓殑澶у皬绾︿负 48 * 0.8 / scale 绫�
+        // 杞崲涓哄睆骞曞儚绱狅細鍥炬爣楂樺害锛堝儚绱狅級= (48 * 0.8 / scale) * scale = 48 * 0.8 = 38.4 鍍忕礌
+        double iconSizePixels = 48.0 * 0.8; // 鍥炬爣鍦ㄥ睆骞曚笂鐨勫ぇ灏忥紙鍍忕礌锛�
+        int spacing = 8; // 闂磋窛锛堝儚绱狅級
+        int textY = (int)Math.round(screenPos.y - iconSizePixels / 2.0 - spacing - textHeight);
+        
+        // 缁樺埗鏂囧瓧鑳屾櫙锛堝崐閫忔槑鐧借壊锛屽寮哄彲璇绘�э級
+        g2d.setColor(new Color(255, 255, 255, 200));
+        g2d.fillRoundRect(textX - 4, textY - metrics.getAscent() - 2, textWidth + 8, textHeight + 4, 4, 4);
+        
+        // 缁樺埗鏂囧瓧
+        g2d.setColor(new Color(46, 139, 87)); // 浣跨敤涓婚缁胯壊
+        g2d.drawString(speedText, textX, textY);
+        
+        // 鎭㈠鍙樻崲
+        g2d.setTransform(originalTransform);
     }
 
-    private void drawHandheldBoundaryPreview(Graphics2D g2d) {
-        if (!handheldBoundaryPreviewActive || handheldBoundaryPreview.isEmpty()) {
+    private void drawRealtimeMowingCoverage(Graphics2D g2d) {
+        if (realtimeMowingTrack == null || realtimeMowingTrack.size() < 2) {
             return;
         }
 
-        Path2D.Double path = new Path2D.Double();
-        boolean started = false;
-        for (Point2D.Double point : handheldBoundaryPreview) {
-            if (point == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
-                continue;
-            }
-            if (!started) {
-                path.moveTo(point.x, point.y);
-                started = true;
-            } else {
-                path.lineTo(point.x, point.y);
-            }
-        }
-
-        if (!started) {
+        Path2D.Double boundaryPath = getRealtimeBoundaryPath();
+        double effectiveWidth = getEffectiveMowerWidthMeters();
+        gecaolunjing.draw(g2d, realtimeMowingTrack, effectiveWidth, boundaryPath);
+    }
+    
+    /**
+     * 缁樺埗瀵艰埅棰勮宸插壊鍖哄煙
+     */
+    private void drawNavigationPreviewCoverage(Graphics2D g2d) {
+        if (navigationPreviewTrack == null || navigationPreviewTrack.size() < 2) {
             return;
         }
-
-        Stroke originalStroke = g2d.getStroke();
-        Color originalColor = g2d.getColor();
-
-        if (handheldBoundaryPreview.size() >= 3) {
-            path.closePath();
-            g2d.setColor(HANDHELD_BOUNDARY_FILL);
-            g2d.fill(path);
+        
+        Path2D.Double boundaryPath = currentBoundaryPath;
+        // 鑾峰彇瀵艰埅棰勮鐨勫壊鑽夊搴︼紙浠巇aohangyulan鑾峰彇锛�
+        double previewWidth = getNavigationPreviewWidth();
+        if (previewWidth <= 0) {
+            previewWidth = 0.5; // 榛樿50鍘樼背
         }
-
-        float outlineWidth = (float) Math.max(1.5f / scale, 0.2f);
-        g2d.setStroke(new BasicStroke(outlineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
-        g2d.setColor(HANDHELD_BOUNDARY_BORDER);
-        g2d.draw(path);
-
-        double markerSize = Math.max(0.5d, 3.0d / scale);
-        double markerRadius = markerSize / 2.0d;
-        Font originalFont = g2d.getFont();
-        float labelFontSize = (float) Math.max(6.0f, 16.0f / Math.max(scale, 0.2));
-        Font labelFont = originalFont.deriveFont(Font.BOLD, labelFontSize);
-        FontMetrics metrics = g2d.getFontMetrics(labelFont);
-
-        for (Point2D.Double point : handheldBoundaryPreview) {
-            if (point == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
-                continue;
+        gecaolunjing.draw(g2d, navigationPreviewTrack, previewWidth, boundaryPath);
+    }
+    
+    /**
+     * 璁剧疆瀵艰埅棰勮杞ㄨ抗
+     */
+    public void setNavigationPreviewTrack(List<Point2D.Double> track) {
+        if (track == null) {
+            navigationPreviewTrack.clear();
+        } else {
+            navigationPreviewTrack.clear();
+            navigationPreviewTrack.addAll(track);
+        }
+        if (visualizationPanel != null) {
+            visualizationPanel.repaint();
+        }
+    }
+    
+    /**
+     * 娣诲姞瀵艰埅棰勮杞ㄨ抗鐐�
+     */
+    public void addNavigationPreviewTrackPoint(Point2D.Double point) {
+        if (point != null && Double.isFinite(point.x) && Double.isFinite(point.y)) {
+            navigationPreviewTrack.add(new Point2D.Double(point.x, point.y));
+            if (visualizationPanel != null) {
+                visualizationPanel.repaint();
             }
-            Shape marker = new Ellipse2D.Double(point.x - markerRadius, point.y - markerRadius, markerSize, markerSize);
-            g2d.setColor(HANDHELD_BOUNDARY_POINT);
-            g2d.fill(marker);
+        }
+    }
+    
+    /**
+     * 娓呴櫎瀵艰埅棰勮杞ㄨ抗
+     */
+    public void clearNavigationPreviewTrack() {
+        navigationPreviewTrack.clear();
+        if (visualizationPanel != null) {
+            visualizationPanel.repaint();
+        }
+    }
+    
+    private double navigationPreviewWidth = 0.5; // 瀵艰埅棰勮鐨勫壊鑽夊搴︼紙绫筹級
+    private double navigationPreviewSpeed = 0.0; // 瀵艰埅棰勮鐨勫壊鑽夋満閫熷害锛堢背/绉掞級
+    
+    /**
+     * 璁剧疆瀵艰埅棰勮鐨勫壊鑽夊搴�
+     */
+    public void setNavigationPreviewWidth(double widthMeters) {
+        navigationPreviewWidth = widthMeters > 0 ? widthMeters : 0.5;
+    }
+    
+    /**
+     * 鑾峰彇瀵艰埅棰勮鐨勫壊鑽夊搴�
+     */
+    private double getNavigationPreviewWidth() {
+        return navigationPreviewWidth;
+    }
+    
+    /**
+     * 璁剧疆瀵艰埅棰勮鐨勫壊鑽夋満閫熷害锛堢背/绉掞級
+     */
+    public void setNavigationPreviewSpeed(double speedMetersPerSecond) {
+        navigationPreviewSpeed = speedMetersPerSecond >= 0 ? speedMetersPerSecond : 0.0;
+    }
+    
+    /**
+     * 鑾峰彇瀵艰埅棰勮鐨勫壊鑽夋満閫熷害锛堢背/绉掞級
+     */
+    private double getNavigationPreviewSpeed() {
+        return navigationPreviewSpeed;
+    }
+
+    private Path2D.Double getRealtimeBoundaryPath() {
+        if (realtimeTrackLandNumber == null) {
+            return null;
         }
 
-        g2d.setFont(labelFont);
-        g2d.setColor(HANDHELD_BOUNDARY_LABEL);
-        int index = 1;
-        for (Point2D.Double point : handheldBoundaryPreview) {
-            if (point == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
-                index++;
-                continue;
+        if (currentBoundaryLandNumber != null && realtimeTrackLandNumber.equals(currentBoundaryLandNumber)) {
+            if (currentBoundaryPath == null) {
+                currentBoundaryPath = buildBoundaryPath(currentBoundary);
             }
-            String label = String.valueOf(index++);
-            int textWidth = metrics.stringWidth(label);
-            int ascent = metrics.getAscent();
-            int descent = metrics.getDescent();
-            float textX = (float) (point.x - textWidth / 2.0);
-            float textY = (float) (point.y + (ascent - descent) / 2.0);
-            g2d.drawString(label, textX, textY);
+            return currentBoundaryPath;
         }
 
-        g2d.setStroke(originalStroke);
-        g2d.setFont(originalFont);
-        g2d.setColor(originalColor);
+        if (realtimeBoundaryPathCache != null && realtimeTrackLandNumber.equals(realtimeBoundaryPathLand)) {
+            return realtimeBoundaryPathCache;
+        }
+
+        Dikuai dikuai = Dikuai.getDikuai(realtimeTrackLandNumber);
+        if (dikuai == null) {
+            realtimeBoundaryPathCache = null;
+            realtimeBoundaryPathLand = null;
+            return null;
+        }
+
+        String normalized = normalizeValue(dikuai.getBoundaryCoordinates());
+        if (normalized == null) {
+            realtimeBoundaryPathCache = null;
+            realtimeBoundaryPathLand = null;
+            return null;
+        }
+
+        List<Point2D.Double> parsed = parseBoundary(normalized);
+        if (parsed.size() < 3) {
+            realtimeBoundaryPathCache = null;
+            realtimeBoundaryPathLand = null;
+            return null;
+        }
+
+        realtimeBoundaryPathCache = buildBoundaryPath(parsed);
+        realtimeBoundaryPathLand = realtimeTrackLandNumber;
+        return realtimeBoundaryPathCache;
+    }
+
+    private boolean shouldRenderIdleTrail() {
+        return !idleTrailSuppressed
+            && !realtimeTrackRecording
+            && !handheldBoundaryPreviewActive
+            && idleMowerTrail.size() >= 2;
     }
 
     private void captureRealtimeTrackPoint() {
+        if (!realtimeTrackRecording) {
+            return;
+        }
         if (realtimeTrackLandNumber == null || visualizationPanel == null) {
+            pendingTrackBreak = true;
+            return;
+        }
+        Device device = Device.getGecaoji();
+        if (device == null) {
+            pendingTrackBreak = true;
+            return;
+        }
+
+        String fixQuality = device.getPositioningStatus();
+        if (!isHighPrecisionFix(fixQuality)) {
+            pendingTrackBreak = true;
             return;
         }
         Point2D.Double position = mower.getPosition();
         if (position == null || !Double.isFinite(position.x) || !Double.isFinite(position.y)) {
+            pendingTrackBreak = true;
             return;
         }
 
+        if (!isPointInsideActiveBoundary(position)) {
+            pendingTrackBreak = true;
+            return;
+        }
+
+        Point2D.Double candidate = new Point2D.Double(position.x, position.y);
         Point2D.Double lastPoint = realtimeMowingTrack.isEmpty() ? null : realtimeMowingTrack.get(realtimeMowingTrack.size() - 1);
-        double distance = 0.0;
+        double distance = Double.NaN;
         if (lastPoint != null) {
-            double dx = position.x - lastPoint.x;
-            double dy = position.y - lastPoint.y;
+            double dx = candidate.x - lastPoint.x;
+            double dy = candidate.y - lastPoint.y;
             distance = Math.hypot(dx, dy);
+            if (distance <= TRACK_DUPLICATE_TOLERANCE_METERS) {
+                return;
+            }
             if (distance < TRACK_SAMPLE_MIN_DISTANCE_METERS) {
                 return;
             }
         }
 
-        realtimeMowingTrack.add(new Point2D.Double(position.x, position.y));
-        if (distance > 0.0) {
+        realtimeMowingTrack.add(candidate);
+        if (!pendingTrackBreak && lastPoint != null && Double.isFinite(distance)) {
             trackLengthMeters += distance;
         }
 
         updateCompletionMetrics();
         trackDirty = true;
         maybePersistRealtimeTrack(false);
+    pendingTrackBreak = false;
+    }
+
+    private void updateIdleMowerTrail() {
+        long now = System.currentTimeMillis();
+        pruneIdleMowerTrail(now);
+
+        if (idleTrailSuppressed || realtimeTrackRecording) {
+            if (!idleMowerTrail.isEmpty()) {
+                clearIdleMowerTrail();
+            }
+            return;
+        }
+
+        Device device = Device.getGecaoji();
+        if (device == null) {
+            return;
+        }
+        // 浣跨敤鏇村鏉剧殑瀹氫綅鐘舵�佸垽鏂紝鍏佽鐘舵��1鍜�4鏄剧ず鎷栧熬
+        if (!isValidFixForTrail(device.getPositioningStatus())) {
+            return;
+        }
+
+        Point2D.Double position = mower.getPosition();
+        if (position == null || !Double.isFinite(position.x) || !Double.isFinite(position.y)) {
+            return;
+        }
+
+        tuowei.TrailSample lastSample = idleMowerTrail.peekLast();
+        if (lastSample != null) {
+            Point2D.Double lastPoint = lastSample.getPoint();
+            double dx = position.x - lastPoint.x;
+            double dy = position.y - lastPoint.y;
+            if (Math.hypot(dx, dy) < IDLE_TRAIL_SAMPLE_DISTANCE_METERS) {
+                return;
+            }
+        }
+
+        idleMowerTrail.addLast(new tuowei.TrailSample(now, new Point2D.Double(position.x, position.y)));
+        pruneIdleMowerTrail(now);
+    }
+    
+    /**
+     * 寮哄埗鏇存柊鎷栧熬锛堢敤浜庢敹鍒�$GNGGA鏁版嵁鏃剁珛鍗虫洿鏂帮級
+     * 杩欎釜鏂规硶浼氬埛鏂癿ower浣嶇疆骞剁珛鍗虫坊鍔犲埌鎷栧熬
+     */
+    public void forceUpdateIdleMowerTrail() {
+        long now = System.currentTimeMillis();
+        pruneIdleMowerTrail(now);
+
+        if (idleTrailSuppressed || realtimeTrackRecording) {
+            if (!idleMowerTrail.isEmpty()) {
+                clearIdleMowerTrail();
+            }
+            return;
+        }
+
+        Device device = Device.getGecaoji();
+        if (device == null) {
+            return;
+        }
+        // 浣跨敤鏇村鏉剧殑瀹氫綅鐘舵�佸垽鏂紝鍏佽鐘舵��1鍜�4鏄剧ず鎷栧熬
+        if (!isValidFixForTrail(device.getPositioningStatus())) {
+            return;
+        }
+
+        // 鍒锋柊mower浣嶇疆锛屼娇鐢ㄦ渶鏂扮殑Device鏁版嵁
+        mower.refreshFromDevice();
+        Point2D.Double position = mower.getPosition();
+        if (position == null || !Double.isFinite(position.x) || !Double.isFinite(position.y)) {
+            return;
+        }
+
+        tuowei.TrailSample lastSample = idleMowerTrail.peekLast();
+        if (lastSample != null) {
+            Point2D.Double lastPoint = lastSample.getPoint();
+            double dx = position.x - lastPoint.x;
+            double dy = position.y - lastPoint.y;
+            if (Math.hypot(dx, dy) < IDLE_TRAIL_SAMPLE_DISTANCE_METERS) {
+                return;
+            }
+        }
+
+        idleMowerTrail.addLast(new tuowei.TrailSample(now, new Point2D.Double(position.x, position.y)));
+        pruneIdleMowerTrail(now);
+        
+        // 绔嬪嵆閲嶇粯锛岀‘淇濇嫋灏惧強鏃舵樉绀�
+        if (visualizationPanel != null) {
+            visualizationPanel.repaint();
+        }
+    }
+
+    private void pruneIdleMowerTrail(long now) {
+        if (idleMowerTrail.isEmpty()) {
+            return;
+        }
+    long cutoff = now - idleTrailDurationMs;
+        boolean modified = false;
+        while (!idleMowerTrail.isEmpty() && idleMowerTrail.peekFirst().getTimestamp() < cutoff) {
+            idleMowerTrail.removeFirst();
+            modified = true;
+        }
+        if (modified && visualizationPanel != null) {
+            visualizationPanel.repaint();
+        }
+    }
+
+    private void clearIdleMowerTrail() {
+        if (idleMowerTrail.isEmpty()) {
+            return;
+        }
+        idleMowerTrail.clear();
+        if (visualizationPanel != null) {
+            visualizationPanel.repaint();
+        }
     }
 
     private void updateCompletionMetrics() {
@@ -550,6 +988,14 @@
             mowerEffectiveWidthMeters = defaultMowerWidthMeters;
         }
 
+        // 鍔犺浇寰�杩旇矾寰�
+        String returnPathStr = dikuai != null ? dikuai.getReturnPathCoordinates() : null;
+        if (returnPathStr != null && !returnPathStr.isEmpty() && !"-1".equals(returnPathStr)) {
+            currentReturnPath = lujingdraw.parsePlannedPath(returnPathStr);
+        } else {
+            currentReturnPath = null;
+        }
+
         loadRealtimeTrack(landNumber, dikuai != null ? dikuai.getMowingTrack() : null);
         visualizationPanel.repaint();
     }
@@ -573,18 +1019,26 @@
             mowerEffectiveWidthMeters = defaultMowerWidthMeters;
         }
 
+        idleTrailSuppressed = true;
+        clearIdleMowerTrail();
+
         realtimeTrackLandNumber = normalizedLand;
         realtimeTrackRecording = true;
+        pendingTrackBreak = true;
         captureRealtimeTrackPoint();
     }
 
     public void pauseRealtimeTrackRecording() {
         realtimeTrackRecording = false;
+        pendingTrackBreak = true;
+        idleTrailSuppressed = false;
         maybePersistRealtimeTrack(true);
     }
 
     public void stopRealtimeTrackRecording() {
         realtimeTrackRecording = false;
+        pendingTrackBreak = true;
+        idleTrailSuppressed = false;
         maybePersistRealtimeTrack(true);
     }
 
@@ -602,15 +1056,47 @@
         completedMowingAreaSqMeters = 0.0;
         mowingCompletionRatio = 0.0;
         trackDirty = true;
+        pendingTrackBreak = true;
+        idleTrailSuppressed = false;
         maybePersistRealtimeTrack(true);
         visualizationPanel.repaint();
     }
 
+    public void clearIdleTrail() {
+        clearIdleMowerTrail();
+    }
+
+    public void setIdleTrailDurationSeconds(int seconds) {
+        int sanitized = seconds;
+        if (sanitized < 5 || sanitized > 600) {
+            sanitized = DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
+        }
+        idleTrailDurationMs = sanitized * 1_000L;
+        pruneIdleMowerTrail(System.currentTimeMillis());
+    }
+
+    public int getIdleTrailDurationSeconds() {
+        long seconds = idleTrailDurationMs / 1_000L;
+        if (seconds <= 0L) {
+            return DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
+        }
+        if (seconds > Integer.MAX_VALUE) {
+            return DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
+        }
+        return (int) seconds;
+    }
+
     public double getMowingCompletionRatio() {
+        if (!isMowerInsideSelectedBoundary()) {
+            return 0.0;
+        }
         return mowingCompletionRatio;
     }
 
     public double getCompletedMowingAreaSqMeters() {
+        if (!isMowerInsideSelectedBoundary()) {
+            return 0.0;
+        }
         return completedMowingAreaSqMeters;
     }
 
@@ -622,6 +1108,14 @@
         return trackLengthMeters;
     }
 
+    private boolean isMowerInsideSelectedBoundary() {
+        Point2D.Double position = mower.getPosition();
+        if (position == null) {
+            return false;
+        }
+        return isPointInsideActiveBoundary(position);
+    }
+
     public void flushRealtimeTrack() {
         maybePersistRealtimeTrack(true);
     }
@@ -635,6 +1129,9 @@
         mowingCompletionRatio = 0.0;
         trackDirty = false;
         lastTrackPersistTimeMillis = 0L;
+        pendingTrackBreak = true;
+        realtimeBoundaryPathCache = null;
+        realtimeBoundaryPathLand = null;
 
         String trimmed = normalizeValue(trackData);
         if (trimmed == null || trimmed.isEmpty()) {
@@ -643,6 +1140,7 @@
         }
 
         String[] segments = trimmed.split(";");
+        Path2D.Double boundaryPath = getRealtimeBoundaryPath();
         Point2D.Double lastPoint = null;
         for (String segment : segments) {
             if (segment == null || segment.trim().isEmpty()) {
@@ -655,11 +1153,26 @@
             try {
                 double x = Double.parseDouble(parts[0].trim());
                 double y = Double.parseDouble(parts[1].trim());
-                Point2D.Double current = new Point2D.Double(x, y);
-                realtimeMowingTrack.add(current);
-                if (lastPoint != null) {
-                    trackLengthMeters += Math.hypot(current.x - lastPoint.x, current.y - lastPoint.y);
+                if (!Double.isFinite(x) || !Double.isFinite(y)) {
+                    continue;
                 }
+                Point2D.Double current = new Point2D.Double(x, y);
+                if (boundaryPath != null && !isPointInsideBoundary(current, boundaryPath)) {
+                    continue;
+                }
+                if (lastPoint != null) {
+                    double dx = current.x - lastPoint.x;
+                    double dy = current.y - lastPoint.y;
+                    double distance = Math.hypot(dx, dy);
+                    if (distance <= TRACK_DUPLICATE_TOLERANCE_METERS) {
+                        continue;
+                    }
+                    if (distance < TRACK_SAMPLE_MIN_DISTANCE_METERS) {
+                        continue;
+                    }
+                    trackLengthMeters += distance;
+                }
+                realtimeMowingTrack.add(current);
                 lastPoint = current;
             } catch (NumberFormatException ignored) {
                 // 璺宠繃寮傚父鏉$洰
@@ -764,46 +1277,233 @@
         double worldY = (screenPoint.y - visualizationPanel.getHeight() / 2.0) / scale - translateY;
         return new Point2D.Double(worldX, worldY);
     }
+    
+    /**
+     * 澶勭悊娴嬮噺妯″紡鐐瑰嚮
+     */
+    private boolean handleMeasurementClick(Point screenPoint) {
+        if (!measurementModeActive) {
+            return false;
+        }
+        Point2D.Double worldPoint = screenToWorld(screenPoint);
+        celiangmoshi.addPoint(worldPoint);
+        visualizationPanel.repaint();
+        return true;
+    }
+    
+    /**
+     * 璁剧疆鎵嬪姩缁樺埗杈圭晫妯″紡
+     */
+    public void setManualBoundaryDrawingMode(boolean active) {
+        manualBoundaryDrawer.setManualBoundaryDrawingMode(active);
+        if (visualizationPanel != null) {
+            visualizationPanel.repaint();
+        }
+    }
+    
+    /**
+     * 鑾峰彇鎵嬪姩缁樺埗鐨勮竟鐣岀偣鍒楄〃
+     */
+    public List<Point2D.Double> getManualBoundaryPoints() {
+        return manualBoundaryDrawer.getManualBoundaryPoints();
+    }
+    
+    /**
+     * 娓呯┖鎵嬪姩缁樺埗鐨勮竟鐣岀偣
+     */
+    public void clearManualBoundaryPoints() {
+        manualBoundaryDrawer.clearManualBoundaryPoints();
+        if (visualizationPanel != null) {
+            visualizationPanel.repaint();
+        }
+    }
+    
+    /**
+     * 璁剧疆娴嬮噺妯″紡
+     */
+    public void setMeasurementMode(boolean active) {
+        measurementModeActive = active;
+        if (!active) {
+            celiangmoshi.clear();
+        }
+        if (visualizationPanel != null) {
+            visualizationPanel.repaint();
+        }
+    }
+    
+    /**
+     * 瑙﹀彂鍦板浘閲嶇粯
+     */
+    public void repaint() {
+        if (visualizationPanel != null) {
+            visualizationPanel.repaint();
+        }
+    }
+    
+    /**
+     * 缁樺埗娴嬮噺妯″紡
+     */
+    private void drawMeasurementMode(Graphics2D g2d, double scale) {
+        List<Point2D.Double> points = celiangmoshi.getPoints();
+        if (points.isEmpty()) {
+            return;
+        }
+        
+        // 淇濆瓨鍘熷鍙樻崲
+        AffineTransform originalTransform = g2d.getTransform();
+        
+        // 璁剧疆娴嬮噺妯″紡棰滆壊
+        Color lineColor = new Color(255, 0, 0, 200);  // 绾㈣壊鍗婇�忔槑
+        Color pointColor = new Color(255, 0, 0, 255);  // 绾㈣壊
+        Color textColor = new Color(33, 37, 41, 220);  // 娣辩伆鑹叉枃瀛�
+        
+        // 璁剧疆绾垮鍜岀偣鐨勫ぇ灏忥紙纭繚鐐瑰拰绾胯繛鎺ワ級
+        float lineWidth = (float)(2.0 / scale);
+        // 鐐圭殑澶у皬锛堝湪涓栫晫鍧愭爣绯讳腑锛岀背锛夛紝纭繚鐐硅冻澶熷ぇ浠ヨ鐩栫嚎鐨勭鐐�
+        double pointSizeInWorld = 0.15d;  // 鐐圭殑澶у皬锛堢背锛�
+        double halfSize = pointSizeInWorld / 2.0;
+        
+        // 鍏堢粯鍒舵墍鏈夋祴閲忕偣锛堜綔涓哄熀纭�灞傦級
+        g2d.setColor(pointColor);
+        for (Point2D.Double point : points) {
+            // 鐐圭殑涓績鍦� point.x, point.y
+            Ellipse2D.Double pointShape = new Ellipse2D.Double(
+                point.x - halfSize,
+                point.y - halfSize,
+                pointSizeInWorld,
+                pointSizeInWorld
+            );
+            g2d.fill(pointShape);
+        }
+        
+        // 鐒跺悗缁樺埗杩炵嚎锛岀‘淇濈嚎浠庣偣鐨勪腑蹇冨紑濮嬪拰缁撴潫锛岀偣鍜岀嚎杩炴帴鍦ㄤ竴璧�
+        g2d.setColor(lineColor);
+        g2d.setStroke(new BasicStroke(lineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
+        
+        // 缁樺埗杩炵嚎鍜岃窛绂绘枃瀛楋紙鏄剧ず涓や釜鐩搁偦鐐硅繛绾跨殑闀垮害锛�
+        for (int i = 0; i < points.size() - 1; i++) {
+            Point2D.Double p1 = points.get(i);
+            Point2D.Double p2 = points.get(i + 1);
+            
+            // 缁樺埗杩炵嚎锛堜粠绗竴涓偣鐨勪腑蹇冨埌绗簩涓偣鐨勪腑蹇冿級
+            // 浣跨敤 Path2D 纭繚绮剧‘缁樺埗锛屼繚鎸佹诞鐐圭簿搴�
+            Path2D.Double linePath = new Path2D.Double();
+            linePath.moveTo(p1.x, p1.y);
+            linePath.lineTo(p2.x, p2.y);
+            g2d.draw(linePath);
+            
+            // 璁$畻璺濈锛堜袱涓浉閭荤偣杩炵嚎鐨勯暱搴︼級
+            double distance = celiangmoshi.calculateDistance(p1, p2);
+            String distanceText = celiangmoshi.formatDistance(distance);
+            
+            // 璁$畻涓偣浣嶇疆锛堢敤浜庢樉绀烘枃瀛楋級
+            double midX = (p1.x + p2.x) / 2.0;
+            double midY = (p1.y + p2.y) / 2.0;
+            
+            // 灏嗕笘鐣屽潗鏍囪浆鎹负灞忓箷鍧愭爣锛堢敤浜庢枃瀛楁樉绀猴級
+            Point2D.Double worldMid = new Point2D.Double(midX, midY);
+            Point2D.Double screenMid = worldToScreen(worldMid);
+            
+            // 鎭㈠鍘熷鍙樻崲浠ョ粯鍒舵枃瀛楋紙鍥哄畾澶у皬锛屼笉闅忕缉鏀惧彉鍖栵級
+            g2d.setTransform(new AffineTransform());
+            
+            // 璁剧疆瀛椾綋锛堜笌缂╂斁鏂囧瓧澶у皬涓�鑷达紝11鍙峰瓧浣擄級
+            Font labelFont = new Font("寰蒋闆呴粦", Font.PLAIN, 11);
+            g2d.setFont(labelFont);
+            FontMetrics metrics = g2d.getFontMetrics(labelFont);
+            
+            // 璁$畻鏂囧瓧浣嶇疆锛堝眳涓樉绀猴級
+            int textWidth = metrics.stringWidth(distanceText);
+            int textHeight = metrics.getHeight();
+            int textX = (int)Math.round(screenMid.x - textWidth / 2.0);
+            int textY = (int)Math.round(screenMid.y - textHeight / 2.0) + metrics.getAscent();
+            
+            // 缁樺埗鏂囧瓧鑳屾櫙锛堝彲閫夛紝鐢ㄤ簬鎻愰珮鍙鎬э級
+            g2d.setColor(new Color(255, 255, 255, 200));
+            g2d.fillRoundRect(textX - 2, textY - metrics.getAscent() - 2, textWidth + 4, textHeight + 4, 4, 4);
+            
+            // 缁樺埗鏂囧瓧
+            g2d.setColor(textColor);
+            g2d.drawString(distanceText, textX, textY);
+            
+            // 鎭㈠鍙樻崲
+            g2d.setTransform(originalTransform);
+        }
+        
+        // 鏈�鍚庡啀娆$粯鍒舵祴閲忕偣锛堝湪杩炵嚎涔嬩笂锛岀‘淇濈偣瑕嗙洊鍦ㄧ嚎鐨勭鐐逛笂锛岀偣鍜岀嚎杩炴帴鍦ㄤ竴璧凤級
+        g2d.setColor(pointColor);
+        for (Point2D.Double point : points) {
+            // 鐐圭殑涓績鍦� point.x, point.y锛屾濂芥槸绾跨殑绔偣浣嶇疆
+            Ellipse2D.Double pointShape = new Ellipse2D.Double(
+                point.x - halfSize,
+                point.y - halfSize,
+                pointSizeInWorld,
+                pointSizeInWorld
+            );
+            g2d.fill(pointShape);
+        }
+    }
 
     private void drawCurrentBoundary(Graphics2D g2d) {
         bianjiedrwa.drawBoundary(g2d, currentBoundary, scale, GRASS_FILL_COLOR, GRASS_BORDER_COLOR);
     }
 
     private void drawCurrentPlannedPath(Graphics2D g2d) {
-        lujingdraw.drawPlannedPath(g2d, currentPlannedPath, scale);
+        double arrowScale = previewSizingEnabled ? 0.5d : 1.0d;
+        lujingdraw.drawPlannedPath(g2d, currentPlannedPath, scale, arrowScale);
     }
 
     private void drawCircleSampleMarkers(Graphics2D g2d, List<double[]> markers, double scale) {
         if (markers == null || markers.isEmpty()) {
             return;
         }
+        
+        // 淇濆瓨鍘熷鍙樻崲
+        AffineTransform originalTransform = g2d.getTransform();
+        
         Shape markerShape;
         double half = CIRCLE_SAMPLE_SIZE / 2.0;
         g2d.setColor(CIRCLE_SAMPLE_COLOR);
         g2d.setStroke(new BasicStroke((float) (1.2f / scale), BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
-        Font originalFont = g2d.getFont();
-        float baseSize = (float) Math.max(12f / scale, 9f);
-        float reducedSize = Math.max(baseSize / 3f, 3f);
-        Font labelFont = originalFont.deriveFont(reducedSize);
+        
+        // 璁剧疆瀛椾綋锛堜笌缂╂斁鏂囧瓧澶у皬涓�鑷达紝11鍙峰瓧浣擄紝涓嶉殢缂╂斁鍙樺寲锛�
+        Font labelFont = new Font("寰蒋闆呴粦", Font.PLAIN, 11);
         g2d.setFont(labelFont);
-        FontMetrics metrics = g2d.getFontMetrics();
+        FontMetrics metrics = g2d.getFontMetrics(labelFont);
+        
         for (double[] pt : markers) {
             if (pt == null || pt.length < 2 || !Double.isFinite(pt[0]) || !Double.isFinite(pt[1])) {
                 continue;
             }
             double x = pt[0];
             double y = pt[1];
+            
+            // 缁樺埗鐐癸紙鍦ㄤ笘鐣屽潗鏍囩郴涓紝闅忕缉鏀惧彉鍖栵級
             markerShape = new Ellipse2D.Double(x - half, y - half, CIRCLE_SAMPLE_SIZE, CIRCLE_SAMPLE_SIZE);
             g2d.fill(markerShape);
+            
+            // 灏嗕笘鐣屽潗鏍囪浆鎹负灞忓箷鍧愭爣浠ョ粯鍒舵枃瀛楋紙涓嶉殢缂╂斁鍙樺寲锛�
+            Point2D.Double worldPoint = new Point2D.Double(x, y);
+            Point2D.Double screenPoint = new Point2D.Double();
+            originalTransform.transform(worldPoint, screenPoint);
+            
+            // 鎭㈠鍘熷鍙樻崲浠ヤ娇鐢ㄥ睆骞曞潗鏍囩粯鍒舵枃瀛�
+            g2d.setTransform(new AffineTransform());
+            
             String label = String.format(Locale.US, "%.2f,%.2f", x, y);
             int textWidth = metrics.stringWidth(label);
-            float textX = (float) (x - textWidth / 2.0);
-            float textY = (float) (y - half - 0.2d) - metrics.getDescent();
+            int textHeight = metrics.getHeight();
+            
+            // 鍦ㄥ睆骞曞潗鏍囩郴涓粯鍒舵枃瀛楋紙涓嶉殢缂╂斁鍙樺寲锛�
+            int textX = (int)(screenPoint.x - textWidth / 2.0);
+            int textY = (int)(screenPoint.y - half - 0.2d) - metrics.getDescent();
             g2d.setColor(new Color(33, 37, 41, 220));
             g2d.drawString(label, textX, textY);
+            
+            // 鎭㈠鍘熷鍙樻崲
+            g2d.setTransform(originalTransform);
             g2d.setColor(CIRCLE_SAMPLE_COLOR);
         }
-        g2d.setFont(originalFont);
     }
 
     private void drawCircleCaptureOverlay(Graphics2D g2d, CircleCaptureOverlay overlay, double scale) {
@@ -904,217 +1604,142 @@
         }
     }
 
-    private void showMowerInfo() {
-        Device device = Device.getGecaoji();
-        if (device == null) {
+    public void showMowerInfo() {
+        if (mowerInfoManager != null) {
+            mowerInfoManager.showMowerInfo();
+        }
+    }
+
+    /**
+     * 澶勭悊闅滅鐗╄竟鐣岀偣鐐瑰嚮
+     * @param screenPoint 灞忓箷鍧愭爣鐐�
+     * @return 濡傛灉澶勭悊浜嗙偣鍑昏繑鍥瀟rue锛屽惁鍒欒繑鍥瀎alse
+     */
+    private boolean handleObstaclePointClick(Point screenPoint) {
+        if (currentObstacles == null || currentObstacles.isEmpty() || currentObstacleLandNumber == null) {
+            return false;
+        }
+
+        double threshold = computeSelectionThresholdPixels();
+        
+        // 閬嶅巻鎵�鏈夐殰纰嶇墿锛屾壘鍒拌鐐瑰嚮鐨勭偣
+        for (Obstacledge.Obstacle obstacle : currentObstacles) {
+            if (obstacle == null) {
+                continue;
+            }
+            
+            List<Obstacledge.XYCoordinate> xyCoords = obstacle.getXyCoordinates();
+            if (xyCoords == null || xyCoords.isEmpty()) {
+                continue;
+            }
+            
+            // 妫�鏌ユ瘡涓偣
+            for (int i = 0; i < xyCoords.size(); i++) {
+                Obstacledge.XYCoordinate coord = xyCoords.get(i);
+                Point2D.Double worldPoint = new Point2D.Double(coord.getX(), coord.getY());
+                Point2D.Double screenPosition = worldToScreen(worldPoint);
+                
+                double dx = screenPosition.x - screenPoint.x;
+                double dy = screenPosition.y - screenPoint.y;
+                if (Math.hypot(dx, dy) <= threshold) {
+                    // 鎵惧埌琚偣鍑荤殑鐐�
+                    String obstacleName = obstacle.getObstacleName();
+                    String pointLabel = (i + 1) + "";
+                    String message = "纭畾瑕佸垹闄ら殰纰嶇墿 \"" + obstacleName + "\" 鐨勭" + pointLabel + "鍙疯竟鐣岀偣鍚楋紵";
+                    
+                    int choice = JOptionPane.showConfirmDialog(
+                        visualizationPanel,
+                        message,
+                        "鍒犻櫎闅滅鐗╄竟鐣岀偣",
+                        JOptionPane.OK_CANCEL_OPTION,
+                        JOptionPane.WARNING_MESSAGE
+                    );
+                    
+                    if (choice == JOptionPane.OK_OPTION) {
+                        removeObstaclePoint(obstacle, i);
+                    }
+                    return true;
+                }
+            }
+        }
+        
+        return false;
+    }
+
+    /**
+     * 鍒犻櫎闅滅鐗╃殑鎸囧畾杈圭晫鐐�
+     */
+    private void removeObstaclePoint(Obstacledge.Obstacle obstacle, int pointIndex) {
+        if (obstacle == null || currentObstacleLandNumber == null) {
+            return;
+        }
+        
+        List<Obstacledge.XYCoordinate> xyCoords = obstacle.getXyCoordinates();
+        if (xyCoords == null || pointIndex < 0 || pointIndex >= xyCoords.size()) {
+            return;
+        }
+        
+        // 妫�鏌ュ垹闄ゅ悗鏄惁杩樻湁瓒冲鐨勭偣
+        Obstacledge.ObstacleShape shape = obstacle.getShape();
+        int minPoints = (shape == Obstacledge.ObstacleShape.CIRCLE) ? 2 : 3;
+        
+        if (xyCoords.size() <= minPoints) {
             JOptionPane.showMessageDialog(
                 visualizationPanel,
-                "鏃犺澶囨暟鎹�",
-                "鍓茶崏鏈轰俊鎭�",
+                "闅滅鐗╄嚦灏戦渶瑕�" + minPoints + "涓偣锛屾棤娉曞垹闄�",
+                "鎻愮ず",
                 JOptionPane.INFORMATION_MESSAGE
             );
             return;
         }
-
-        ensureMowerInfoDialog();
-        updateMowerInfoLabels();
-        positionMowerDialog();
-        if (!mowerInfoDialog.isVisible()) {
-            mowerInfoDialog.setVisible(true);
-        } else {
-            mowerInfoDialog.toFront();
-        }
-        startMowerInfoTimer();
-    }
-
-    private void ensureMowerInfoDialog() {
-        if (mowerInfoDialog != null) {
-            return;
-        }
-
-        Window owner = SwingUtilities.getWindowAncestor(visualizationPanel);
-        JDialog dialog = new JDialog(owner, "鍓茶崏鏈轰俊鎭�", Dialog.ModalityType.MODELESS);
-        dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
-
-        JPanel content = new JPanel(new BorderLayout(0, 12));
-        content.setBorder(BorderFactory.createEmptyBorder(16, 20, 16, 20));
-
-        JPanel grid = new JPanel(new GridLayout(0, 2, 12, 8));
-
-    grid.add(new JLabel("璁惧缂栧彿锛�"));
-        mowerNumberValueLabel = createValueLabel();
-        grid.add(mowerNumberValueLabel);
-
-    grid.add(new JLabel("瀹炴椂X鍧愭爣锛�"));
-        realtimeXValueLabel = createValueLabel();
-        grid.add(realtimeXValueLabel);
-
-    grid.add(new JLabel("瀹炴椂Y鍧愭爣锛�"));
-        realtimeYValueLabel = createValueLabel();
-        grid.add(realtimeYValueLabel);
-
-    grid.add(new JLabel("瀹氫綅璐ㄩ噺锛�"));
-        positioningStatusValueLabel = createValueLabel();
-        grid.add(positioningStatusValueLabel);
-
-    grid.add(new JLabel("鍗槦棰楁暟锛�"));
-        satelliteCountValueLabel = createValueLabel();
-        grid.add(satelliteCountValueLabel);
-
-    grid.add(new JLabel("琛岄┒閫熷害锛�"));
-        realtimeSpeedValueLabel = createValueLabel();
-        grid.add(realtimeSpeedValueLabel);
-
-    grid.add(new JLabel("杩愬姩鑸悜锛�"));
-        headingValueLabel = createValueLabel();
-        grid.add(headingValueLabel);
-
-    grid.add(new JLabel("鏇存柊鏃堕棿锛�"));
-        updateTimeValueLabel = createValueLabel();
-        grid.add(updateTimeValueLabel);
-
-        content.add(grid, BorderLayout.CENTER);
-
-        JButton closeButton = new JButton("鍏抽棴");
-        closeButton.addActionListener(e -> dialog.dispose());
-        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
-        buttonPanel.add(closeButton);
-        content.add(buttonPanel, BorderLayout.SOUTH);
-
-    dialog.setContentPane(content);
-    dialog.pack();
-        dialog.setResizable(false);
-        dialog.addWindowListener(new WindowAdapter() {
-            @Override
-            public void windowClosed(WindowEvent e) {
-                stopMowerInfoTimer();
-                resetMowerInfoLabels();
-                mowerInfoDialog = null;
+        
+        // 鍒涘缓鏂扮殑鍧愭爣鍒楄〃锛堢Щ闄ゆ寚瀹氱偣锛�
+        List<Obstacledge.XYCoordinate> updatedCoords = new ArrayList<>(xyCoords);
+        updatedCoords.remove(pointIndex);
+        
+        // 鏇存柊闅滅鐗╁潗鏍�
+        obstacle.setXyCoordinates(updatedCoords);
+        
+        // 淇濆瓨鍒伴厤缃枃浠�
+        try {
+            File configFile = new File("Obstacledge.properties");
+            Obstacledge.ConfigManager manager = new Obstacledge.ConfigManager();
+            if (configFile.exists()) {
+                manager.loadFromFile(configFile.getAbsolutePath());
             }
-        });
-
-        mowerInfoDialog = dialog;
-    }
-
-    private void positionMowerDialog() {
-        if (mowerInfoDialog == null || visualizationPanel == null) {
-            return;
-        }
-        int panelWidth = visualizationPanel.getWidth();
-        int panelHeight = visualizationPanel.getHeight();
-        int dialogHeight = mowerInfoDialog.getHeight();
-        if (dialogHeight <= 0) {
-            dialogHeight = mowerInfoDialog.getPreferredSize().height;
-        }
-        if (panelWidth > 0) {
-            mowerInfoDialog.setSize(panelWidth, dialogHeight);
-        }
-
-        try {
-            Point panelOnScreen = visualizationPanel.getLocationOnScreen();
-            int dialogWidth = mowerInfoDialog.getWidth();
-            int targetX = panelOnScreen.x + (panelWidth - dialogWidth) / 2;
-            int targetY = panelOnScreen.y + panelHeight / 3 - dialogHeight / 2;
-            mowerInfoDialog.setLocation(targetX, targetY);
-        } catch (IllegalComponentStateException ex) {
-            // component not yet showing; ignore positioning
-        }
-    }
-
-    private JLabel createValueLabel() {
-        JLabel label = new JLabel("--");
-        label.setHorizontalAlignment(SwingConstants.LEFT);
-        return label;
-    }
-
-    private void startMowerInfoTimer() {
-        if (mowerInfoRefreshTimer == null) {
-            mowerInfoRefreshTimer = new Timer(1000, e -> updateMowerInfoLabels());
-            mowerInfoRefreshTimer.setRepeats(true);
-        }
-        if (!mowerInfoRefreshTimer.isRunning()) {
-            mowerInfoRefreshTimer.start();
-        }
-    }
-
-    private void stopMowerInfoTimer() {
-        if (mowerInfoRefreshTimer != null) {
-            mowerInfoRefreshTimer.stop();
-            mowerInfoRefreshTimer = null;
-        }
-    }
-
-    private void resetMowerInfoLabels() {
-        mowerNumberValueLabel = null;
-        realtimeXValueLabel = null;
-        realtimeYValueLabel = null;
-        positioningStatusValueLabel = null;
-        satelliteCountValueLabel = null;
-        realtimeSpeedValueLabel = null;
-        headingValueLabel = null;
-        updateTimeValueLabel = null;
-    }
-
-    private void updateMowerInfoLabels() {
-        if (mowerNumberValueLabel == null) {
-            return;
-        }
-
-        Device device = Device.getGecaoji();
-        if (device == null) {
-            setMowerInfoLabels("--");
-            return;
-        }
-
-        mower.refreshFromDevice();
-
-        mowerNumberValueLabel.setText(formatDeviceValue(device.getMowerNumber()));
-        realtimeXValueLabel.setText(formatDeviceValue(device.getRealtimeX()));
-        realtimeYValueLabel.setText(formatDeviceValue(device.getRealtimeY()));
-        positioningStatusValueLabel.setText(formatDeviceValue(device.getPositioningStatus()));
-        satelliteCountValueLabel.setText(formatDeviceValue(device.getSatelliteCount()));
-        realtimeSpeedValueLabel.setText(formatDeviceValue(device.getRealtimeSpeed()));
-        headingValueLabel.setText(formatDeviceValue(device.getHeading()));
-        updateTimeValueLabel.setText(formatTimestamp(device.getGupdateTime()));
-    }
-
-    private void setMowerInfoLabels(String value) {
-        if (mowerNumberValueLabel != null) mowerNumberValueLabel.setText(value);
-        if (realtimeXValueLabel != null) realtimeXValueLabel.setText(value);
-        if (realtimeYValueLabel != null) realtimeYValueLabel.setText(value);
-        if (positioningStatusValueLabel != null) positioningStatusValueLabel.setText(value);
-        if (satelliteCountValueLabel != null) satelliteCountValueLabel.setText(value);
-        if (realtimeSpeedValueLabel != null) realtimeSpeedValueLabel.setText(value);
-        if (headingValueLabel != null) headingValueLabel.setText(value);
-        if (updateTimeValueLabel != null) updateTimeValueLabel.setText(value);
-    }
-
-    private String sanitizeDeviceValue(String value) {
-        if (value == null) {
-            return null;
-        }
-        String trimmed = value.trim();
-        if (trimmed.isEmpty() || "-1".equals(trimmed)) {
-            return null;
-        }
-        return trimmed;
-    }
-
-    private String formatDeviceValue(String value) {
-        String sanitized = sanitizeDeviceValue(value);
-        return sanitized == null ? "--" : sanitized;
-    }
-
-    private String formatTimestamp(String value) {
-        String sanitized = sanitizeDeviceValue(value);
-        if (sanitized == null) {
-            return "--";
-        }
-        try {
-            long millis = Long.parseLong(sanitized);
-            return TIMESTAMP_FORMAT.format(new Date(millis));
-        } catch (NumberFormatException ex) {
-            return sanitized;
+            
+            Obstacledge.Plot plot = manager.getPlotById(currentObstacleLandNumber.trim());
+            if (plot != null) {
+                // 绉婚櫎鏃ч殰纰嶇墿骞舵坊鍔犳洿鏂板悗鐨勯殰纰嶇墿
+                plot.removeObstacleByName(obstacle.getObstacleName());
+                plot.addObstacle(obstacle);
+                manager.saveToFile(configFile.getAbsolutePath());
+                
+                // 鏇存柊鍦板潡鏇存柊鏃堕棿
+                Dikuai.updateField(currentObstacleLandNumber.trim(), "updateTime", 
+                    new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new java.util.Date()));
+                Dikuai.saveToProperties();
+                
+                // 閲嶆柊鍔犺浇闅滅鐗╂暟鎹互鍒锋柊鏄剧ず
+                List<Obstacledge.Obstacle> updatedObstacles = new ArrayList<>();
+                for (Obstacledge.Obstacle obs : currentObstacles) {
+                    if (obs.getObstacleName().equals(obstacle.getObstacleName())) {
+                        updatedObstacles.add(obstacle); // 浣跨敤鏇存柊鍚庣殑闅滅鐗�
+                    } else {
+                        updatedObstacles.add(obs); // 淇濇寔鍏朵粬闅滅鐗╀笉鍙�
+                    }
+                }
+                applyObstaclesToRenderer(updatedObstacles, currentObstacleLandNumber);
+                visualizationPanel.repaint();
+            }
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            JOptionPane.showMessageDialog(
+                visualizationPanel,
+                "淇濆瓨澶辫触: " + ex.getMessage(),
+                "閿欒",
+                JOptionPane.ERROR_MESSAGE
+            );
         }
     }
 
@@ -1167,7 +1792,11 @@
 
     private double computeSelectionThresholdPixels() {
         double scaleFactor = Math.max(0.5, scale);
-        double markerDiameterWorld = Math.max(1.0, (10.0 / scaleFactor) * 0.2);
+        double diameterScale = boundaryPointSizeScale * (previewSizingEnabled ? PREVIEW_BOUNDARY_MARKER_SCALE : 1.0d);
+        if (!Double.isFinite(diameterScale) || diameterScale <= 0.0d) {
+            diameterScale = 1.0d;
+        }
+        double markerDiameterWorld = Math.max(1.0, (10.0 / scaleFactor) * 0.2 * diameterScale);
         double markerDiameterPixels = markerDiameterWorld * scale;
         return Math.max(8.0, markerDiameterPixels * 1.5);
     }
@@ -1207,6 +1836,7 @@
 
         if (updated.size() < 2) {
             currentBoundary = null;
+            currentBoundaryPath = null;
             boundaryBounds = null;
             boundaryPointsVisible = false;
             Dikuaiguanli.updateBoundaryPointVisibility(currentBoundaryLandNumber, false);
@@ -1214,10 +1844,12 @@
             adjustViewAfterBoundaryReset();
         } else {
             currentBoundary = updated;
+            rebuildBoundaryPath();
             boundaryBounds = computeBounds(updated);
             Dikuaiguanli.updateBoundaryPointVisibility(currentBoundaryLandNumber, boundaryPointsVisible);
             visualizationPanel.repaint();
         }
+        pendingTrackBreak = true;
     }
 
     private boolean persistBoundaryChanges(List<Point2D.Double> updatedBoundary) {
@@ -1279,37 +1911,314 @@
         return Math.hypot(dx, dy) <= BOUNDARY_POINT_MERGE_THRESHOLD;
     }
 
+    private boolean isHighPrecisionFix(String fixQuality) {
+        if (fixQuality == null) {
+            return false;
+        }
+        String trimmed = fixQuality.trim();
+        if (trimmed.isEmpty()) {
+            return false;
+        }
+        if ("4".equals(trimmed)) {
+            return true;
+        }
+        try {
+            double value = Double.parseDouble(trimmed);
+            return Math.abs(value - 4.0d) < 1e-6;
+        } catch (NumberFormatException ex) {
+            return false;
+        }
+    }
+    
+    /**
+     * 鍒ゆ柇瀹氫綅鐘舵�佹槸鍚︽湁鏁堬紝鍙敤浜庢樉绀烘嫋灏�
+     * 鎺ュ彈鐘舵��1锛堝崟鐐瑰畾浣嶏級銆�2锛堢爜宸垎锛夈��3锛堟棤鏁圥PS锛夈��4锛堝浐瀹氳В锛夈��5锛堟诞鐐硅В锛�
+     */
+    private boolean isValidFixForTrail(String fixQuality) {
+        if (fixQuality == null) {
+            return false;
+        }
+        String trimmed = fixQuality.trim();
+        if (trimmed.isEmpty()) {
+            return false;
+        }
+        // 鎺ュ彈鐘舵��1,2,3,4,5锛堝彧瑕佷笉鏄�0鎴栨棤鏁堢姸鎬侊級
+        if ("1".equals(trimmed) || "2".equals(trimmed) || "3".equals(trimmed) || 
+            "4".equals(trimmed) || "5".equals(trimmed)) {
+            return true;
+        }
+        try {
+            double value = Double.parseDouble(trimmed);
+            // 鎺ュ彈1.0, 2.0, 3.0, 4.0, 5.0锛堝彧瑕佷笉鏄�0锛�
+            return value >= 1.0 && value <= 5.0;
+        } catch (NumberFormatException ex) {
+            return false;
+        }
+    }
+
+    private boolean isPointInsideActiveBoundary(Point2D.Double point) {
+        if (point == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
+            return false;
+        }
+        if (realtimeTrackLandNumber == null) {
+            return false;
+        }
+        Path2D.Double path = getRealtimeBoundaryPath();
+        return isPointInsideBoundary(point, path);
+    }
+
+    private boolean isPointInsideBoundary(Point2D.Double point, Path2D.Double path) {
+        if (point == null || path == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
+            return false;
+        }
+        if (path.contains(point.x, point.y)) {
+            return true;
+        }
+        double size = BOUNDARY_CONTAINS_TOLERANCE * 2.0;
+        return path.intersects(point.x - BOUNDARY_CONTAINS_TOLERANCE, point.y - BOUNDARY_CONTAINS_TOLERANCE, size, size);
+    }
+
+    private void rebuildBoundaryPath() {
+        currentBoundaryPath = buildBoundaryPath(currentBoundary);
+    }
+
+    private Path2D.Double buildBoundaryPath(List<Point2D.Double> boundary) {
+        if (boundary == null || boundary.size() < 3) {
+            return null;
+        }
+        Path2D.Double path = new Path2D.Double();
+        boolean started = false;
+        for (Point2D.Double point : boundary) {
+            if (point == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
+                continue;
+            }
+            if (!started) {
+                path.moveTo(point.x, point.y);
+                started = true;
+            } else {
+                path.lineTo(point.x, point.y);
+            }
+        }
+        if (!started) {
+            return null;
+        }
+        path.closePath();
+        return path;
+    }
+
     
     /**
      * 缁樺埗瑙嗗浘淇℃伅
      */
-    private void drawViewInfo(Graphics2D g2d) {
-        g2d.setColor(new Color(80, 80, 80));
-        g2d.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 11));
-        
-        // 鍙樉绀虹缉鏀炬瘮渚嬶紝鍘绘帀骞崇Щ淇℃伅
-        String info = String.format("缂╂斁: %.2fx", scale);
-        g2d.drawString(info, 15, visualizationPanel.getHeight() - 15);
-        
-        if (mousePoint != null) {
-            // 璁$畻榧犳爣浣嶇疆鍦ㄤ笘鐣屽潗鏍囩郴涓殑鍧愭爣
-            double worldX = (mousePoint.x - visualizationPanel.getWidth()/2) / scale - translateX;
-            double worldY = (mousePoint.y - visualizationPanel.getHeight()/2) / scale - translateY;
-            
-            String mouseCoord = String.format("鍧愭爣: (%.1f, %.1f)m", worldX, worldY);
-            g2d.drawString(mouseCoord, visualizationPanel.getWidth() - 150, visualizationPanel.getHeight() - 15);
+    /**
+     * 缁樺埗闅滅鐗╁潗鏍囩偣锛堝甫搴忓彿锛�
+     * 搴忓彿鏄剧ず鍦ㄧ偣涓績锛屽瓧浣撳ぇ灏忎笌闅滅鐗╁悕绉颁竴鑷达紙11鍙凤級锛屼笉闅忕缉鏀惧彉鍖�
+     */
+    private void drawObstaclePointsWithNumbers(Graphics2D g2d, List<Obstacledge.Obstacle> obstacles, double scale) {
+        if (obstacles == null || obstacles.isEmpty()) {
+            return;
         }
         
-        // 鍘绘帀鎿嶄綔鎻愮ず锛�"婊氳疆缂╂斁 | 鎷栨嫿绉诲姩 | 鍙抽敭閲嶇疆"
-        // String tips = "婊氳疆缂╂斁 | 鎷栨嫿绉诲姩 | 鍙抽敭閲嶇疆";
-        // g2d.drawString(tips, visualizationPanel.getWidth() - 200, 30);
+        // 淇濆瓨鍘熷鍙樻崲
+        AffineTransform originalTransform = g2d.getTransform();
+        
+        // 璁剧疆鐐圭殑澶у皬锛堥殢缂╂斁鍙樺寲锛�
+        double scaleFactor = Math.max(0.5, scale);
+        double clampedScale = boundaryPointSizeScale * (previewSizingEnabled ? PREVIEW_BOUNDARY_MARKER_SCALE : 1.0d);
+        if (!Double.isFinite(clampedScale) || clampedScale <= 0.0d) {
+            clampedScale = 1.0d;
+        }
+        double minimumDiameter = clampedScale < 1.0 ? 0.5 : 1.0;
+        double markerDiameter = Math.max(minimumDiameter, (10.0 / scaleFactor) * 0.2 * clampedScale);
+        double markerRadius = markerDiameter / 2.0;
+        
+        // 璁剧疆瀛椾綋锛堜笌闅滅鐗╁悕绉颁竴鑷达紝涓嶉殢缂╂斁鍙樺寲锛�
+        Font labelFont = new Font("寰蒋闆呴粦", Font.PLAIN, 11);
+        g2d.setFont(labelFont);
+        FontMetrics fontMetrics = g2d.getFontMetrics(labelFont);
+        
+        // 閬嶅巻鎵�鏈夐殰纰嶇墿
+        for (Obstacledge.Obstacle obstacle : obstacles) {
+            if (obstacle == null || !obstacle.isValid()) {
+                continue;
+            }
+            
+            List<Obstacledge.XYCoordinate> xyCoords = obstacle.getXyCoordinates();
+            if (xyCoords == null || xyCoords.isEmpty()) {
+                continue;
+            }
+            
+            // 缁樺埗姣忎釜鐐瑰強鍏跺簭鍙�
+            for (int i = 0; i < xyCoords.size(); i++) {
+                Obstacledge.XYCoordinate coord = xyCoords.get(i);
+                double x = coord.getX();
+                double y = coord.getY();
+                
+                // 缁樺埗鐐癸紙鍦ㄤ笘鐣屽潗鏍囩郴涓紝闅忕缉鏀惧彉鍖栵級
+                g2d.setColor(OBSTACLE_POINT_COLOR);
+                Ellipse2D.Double marker = new Ellipse2D.Double(
+                    x - markerRadius, 
+                    y - markerRadius, 
+                    markerDiameter, 
+                    markerDiameter
+                );
+                g2d.fill(marker);
+                
+                // 灏嗕笘鐣屽潗鏍囪浆鎹负灞忓箷鍧愭爣浠ョ粯鍒跺簭鍙凤紙涓嶉殢缂╂斁鍙樺寲锛�
+                Point2D.Double worldPoint = new Point2D.Double(x, y);
+                Point2D.Double screenPoint = new Point2D.Double();
+                originalTransform.transform(worldPoint, screenPoint);
+                
+                // 淇濆瓨褰撳墠鍙樻崲
+                AffineTransform savedTransform = g2d.getTransform();
+                
+                // 閲嶇疆鍙樻崲涓哄睆骞曞潗鏍囩郴缁�
+                g2d.setTransform(new AffineTransform());
+                
+                // 缁樺埗搴忓彿锛堝湪灞忓箷鍧愭爣绯讳腑锛屼笉闅忕缉鏀惧彉鍖栵級
+                String numberText = String.valueOf(i + 1);
+                int textWidth = fontMetrics.stringWidth(numberText);
+                int textHeight = fontMetrics.getHeight();
+                
+                // 鍦ㄧ偣涓績缁樺埗搴忓彿
+                int textX = (int)(screenPoint.x - textWidth / 2.0);
+                int textY = (int)(screenPoint.y + textHeight / 4.0);
+                
+                // 缁樺埗搴忓彿鏂囧瓧锛堟棤鑳屾櫙锛�
+                g2d.setColor(Color.BLACK);
+                g2d.drawString(numberText, textX, textY);
+                
+                // 鎭㈠鍙樻崲
+                g2d.setTransform(savedTransform);
+            }
+        }
+        
+        // 鎭㈠鍘熷鍙樻崲
+        g2d.setTransform(originalTransform);
     }
     
     /**
-     * 鑾峰彇褰撳墠缂╂斁姣斾緥
+     * 缁樺埗杈圭晫鐐癸紙甯﹀簭鍙凤級
+     * 搴忓彿鏄剧ず鍦ㄧ偣涓績锛屽瓧浣撳ぇ灏忎笌闅滅鐗╁簭鍙蜂竴鑷达紙11鍙凤級锛屼笉闅忕缉鏀惧彉鍖�
      */
-    public double getScale() {
-        return scale;
+    private void drawBoundaryPointsWithNumbers(Graphics2D g2d, List<Point2D.Double> boundary, double scale) {
+        if (boundary == null || boundary.size() < 2) {
+            return;
+        }
+        
+        // 淇濆瓨鍘熷鍙樻崲
+        AffineTransform originalTransform = g2d.getTransform();
+        
+        int totalPoints = boundary.size();
+        boolean closed = totalPoints > 2 && areBoundaryPointsClose(boundary.get(0), boundary.get(totalPoints - 1));
+        int effectiveCount = closed ? totalPoints - 1 : totalPoints;
+        if (effectiveCount <= 0) {
+            return;
+        }
+        
+        // 璁剧疆鐐圭殑澶у皬锛堣竟鐣岀嚎瀹藉害鐨�2鍊嶏級
+        // 杈圭晫绾垮搴︼細3 / Math.max(0.5, scale)
+        double scaleFactor = Math.max(0.5, scale);
+        double boundaryLineWidth = 3.0 / scaleFactor;  // 杈圭晫绾垮搴�
+        double markerDiameter = boundaryLineWidth * 2.0;  // 杈圭晫鐐圭洿寰� = 杈圭晫绾垮搴︾殑2鍊�
+        double markerRadius = markerDiameter / 2.0;
+        
+        // 璁剧疆瀛椾綋锛堜笌闅滅鐗╁簭鍙蜂竴鑷达紝涓嶉殢缂╂斁鍙樺寲锛�
+        Font labelFont = new Font("寰蒋闆呴粦", Font.PLAIN, 11);
+        g2d.setFont(labelFont);
+        FontMetrics fontMetrics = g2d.getFontMetrics(labelFont);
+        
+        // 缁樺埗姣忎釜鐐瑰強鍏跺簭鍙�
+        for (int i = 0; i < effectiveCount; i++) {
+            Point2D.Double point = boundary.get(i);
+            double x = point.x;
+            double y = point.y;
+            
+            // 缁樺埗鐐癸紙鍦ㄤ笘鐣屽潗鏍囩郴涓紝闅忕缉鏀惧彉鍖栵級
+            g2d.setColor(BOUNDARY_POINT_COLOR);
+            Ellipse2D.Double marker = new Ellipse2D.Double(
+                x - markerRadius, 
+                y - markerRadius, 
+                markerDiameter, 
+                markerDiameter
+            );
+            g2d.fill(marker);
+            
+            // 灏嗕笘鐣屽潗鏍囪浆鎹负灞忓箷鍧愭爣浠ョ粯鍒跺簭鍙凤紙涓嶉殢缂╂斁鍙樺寲锛�
+            Point2D.Double worldPoint = new Point2D.Double(x, y);
+            Point2D.Double screenPoint = new Point2D.Double();
+            originalTransform.transform(worldPoint, screenPoint);
+            
+            // 淇濆瓨褰撳墠鍙樻崲
+            AffineTransform savedTransform = g2d.getTransform();
+            
+            // 閲嶇疆鍙樻崲涓哄睆骞曞潗鏍囩郴缁�
+            g2d.setTransform(new AffineTransform());
+            
+            // 缁樺埗搴忓彿锛堝湪灞忓箷鍧愭爣绯讳腑锛屼笉闅忕缉鏀惧彉鍖栵級
+            String numberText = String.valueOf(i + 1);
+            int textWidth = fontMetrics.stringWidth(numberText);
+            int textHeight = fontMetrics.getHeight();
+            
+            // 鍦ㄧ偣涓績缁樺埗搴忓彿
+            int textX = (int)(screenPoint.x - textWidth / 2.0);
+            int textY = (int)(screenPoint.y + textHeight / 4.0);
+            
+            // 缁樺埗搴忓彿鏂囧瓧锛堟棤鑳屾櫙锛�
+            g2d.setColor(Color.BLACK);
+            g2d.drawString(numberText, textX, textY);
+            
+            // 鎭㈠鍙樻崲
+            g2d.setTransform(savedTransform);
+        }
+        
+        // 鎭㈠鍘熷鍙樻崲
+        g2d.setTransform(originalTransform);
+    }
+    
+    /**
+     * 妫�鏌ヤ袱涓竟鐣岀偣鏄惁鎺ヨ繎锛堢敤浜庡垽鏂竟鐣屾槸鍚﹂棴鍚堬級
+     */
+    private boolean areBoundaryPointsClose(Point2D.Double a, Point2D.Double b) {
+        if (a == null || b == null) {
+            return false;
+        }
+        double dx = a.x - b.x;
+        double dy = a.y - b.y;
+        return Math.hypot(dx, dy) <= BOUNDARY_POINT_MERGE_THRESHOLD;
+    }
+    
+    private void drawViewInfo(Graphics2D g2d) {
+        g2d.setColor(new Color(80, 80, 80));
+        g2d.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 11));
+
+        // 鍦ㄥ湴鍥鹃《閮ㄥ乏渚ф樉绀洪仴鎺ф憞鏉嗗搴旈�熷害锛堣嫢闈為浂锛�
+        try {
+            int forward = Control03.getCurrentForwardSpeed();
+            int steer = Control03.getCurrentSteeringSpeed();
+            if (forward != 0 || steer != 0) {
+                String speedInfo = String.format("琛岃繘:%d 杞悜:%d", forward, steer);
+                // 鑳屾櫙鍗婇�忔槑鐭╁舰澧炲己鍙鎬�
+                FontMetrics fm = g2d.getFontMetrics();
+                int padding = 6;
+                int w = fm.stringWidth(speedInfo) + padding * 2;
+                int h = fm.getHeight() + padding;
+                int x = 12;
+                int y = 12;
+                Color bg = new Color(255, 255, 255, 180);
+                g2d.setColor(bg);
+                g2d.fillRoundRect(x, y, w, h, 8, 8);
+                g2d.setColor(new Color(120, 120, 120));
+                g2d.drawString(speedInfo, x + padding, y + fm.getAscent() + (padding/2));
+            }
+        } catch (Throwable t) {
+            // 涓嶅簲闃诲娓叉煋锛岄潤榛樺鐞嗕换浣曞紓甯�
+        }
+
+        // 淇濈暀搴曢儴鐨勭缉鏀炬瘮渚嬩俊鎭�
+        String info = String.format("缂╂斁: %.2fx", scale);
+        g2d.setColor(new Color(80, 80, 80));
+        g2d.drawString(info, 15, visualizationPanel.getHeight() - 15);
     }
     
     /**
@@ -1330,7 +2239,15 @@
      * 璁剧疆瑙嗗浘鍙樻崲鍙傛暟锛堢敤浜庣▼搴忓寲鎺у埗锛�
      */
     public void setViewTransform(double scale, double translateX, double translateY) {
-        this.scale = scale;
+        // 闄愬埗缂╂斁鑼冨洿
+        scale = Math.max(MIN_SCALE, Math.min(scale, MAX_SCALE));
+        // 濡傛灉缂╂斁姣斾緥鏀瑰彉浜嗭紝淇濆瓨鍒伴厤缃枃浠�
+        if (Math.abs(this.scale - scale) > SCALE_EPSILON) {
+            this.scale = scale;
+            saveScaleToProperties();
+        } else {
+            this.scale = scale;
+        }
         this.translateX = translateX;
         this.translateY = translateY;
         visualizationPanel.repaint();
@@ -1339,6 +2256,8 @@
     public void setCurrentBoundary(String boundaryCoordinates, String landNumber, String landName) {
         this.boundaryName = landName;
         this.currentBoundaryLandNumber = landNumber;
+        this.realtimeBoundaryPathCache = null;
+        this.realtimeBoundaryPathLand = null;
 
         if (boundaryCoordinates == null) {
             clearBoundaryData();
@@ -1360,8 +2279,10 @@
             return;
         }
 
-        currentBoundary = parsed;
-        boundaryBounds = computeBounds(parsed);
+    currentBoundary = parsed;
+    rebuildBoundaryPath();
+    pendingTrackBreak = true;
+    boundaryBounds = computeBounds(parsed);
 
         Rectangle2D.Double bounds = boundaryBounds;
         SwingUtilities.invokeLater(() -> {
@@ -1372,10 +2293,14 @@
 
     private void clearBoundaryData() {
         currentBoundary = null;
+        currentBoundaryPath = null;
         boundaryBounds = null;
         boundaryName = null;
         boundaryPointsVisible = false;
         currentBoundaryLandNumber = null;
+        pendingTrackBreak = true;
+        realtimeBoundaryPathCache = null;
+        realtimeBoundaryPathLand = null;
     }
 
     public void setCurrentObstacles(String obstaclesData, String landNumber) {
@@ -1576,6 +2501,7 @@
         obstacleBounds = null;
         selectedObstacleName = null;
         currentObstacleLandNumber = null;
+        obstaclePointsVisible = false;
     }
 
     private List<Obstacledge.Obstacle> parseObstacles(String obstaclesData, String landNumber) {
@@ -1686,6 +2612,9 @@
             return coords;
         }
 
+        // Remove wrapper characters like parentheses that are used when persisting payloads
+        sanitized = sanitized.replace("(", "").replace(")", "");
+
         String[] pairs = sanitized.split(";");
         for (String pair : pairs) {
             if (pair == null) {
@@ -1695,6 +2624,10 @@
             if (trimmed.isEmpty()) {
                 continue;
             }
+            trimmed = trimmed.replace("(", "").replace(")", "");
+            if (trimmed.isEmpty()) {
+                continue;
+            }
             String[] parts = trimmed.split(",");
             if (parts.length < 2) {
                 continue;
@@ -1856,6 +2789,87 @@
         visualizationPanel.repaint();
     }
 
+    public void setObstaclePointsVisible(boolean visible) {
+        this.obstaclePointsVisible = visible;
+        visualizationPanel.repaint();
+    }
+    
+    /**
+     * 璁剧疆鏄惁鏄剧ず杈圭晫璺濈
+     */
+    public void setBoundaryLengthVisible(boolean visible) {
+        boundaryLengthVisible = visible;
+        if (visualizationPanel != null) {
+            visualizationPanel.repaint();
+        }
+    }
+    
+    /**
+     * 鑾峰彇鏄惁鏄剧ず杈圭晫璺濈
+     */
+    public boolean isBoundaryLengthVisible() {
+        return boundaryLengthVisible;
+    }
+
+    public void setBoundaryPointSizeScale(double sizeScale) {
+        double normalized = (Double.isFinite(sizeScale) && sizeScale > 0.0d) ? sizeScale : 1.0d;
+        if (Math.abs(boundaryPointSizeScale - normalized) < 1e-6) {
+            return;
+        }
+        boundaryPointSizeScale = normalized;
+        if (visualizationPanel == null) {
+            return;
+        }
+        if (SwingUtilities.isEventDispatchThread()) {
+            visualizationPanel.repaint();
+        } else {
+            SwingUtilities.invokeLater(visualizationPanel::repaint);
+        }
+    }
+
+    public void setPathPreviewSizingEnabled(boolean enabled) {
+        previewSizingEnabled = enabled;
+        if (visualizationPanel == null) {
+            return;
+        }
+        if (SwingUtilities.isEventDispatchThread()) {
+            visualizationPanel.repaint();
+        } else {
+            SwingUtilities.invokeLater(visualizationPanel::repaint);
+        }
+    }
+
+    public void setBoundaryPreviewMarkerScale(double markerScale) {
+        double normalized = Double.isFinite(markerScale) && markerScale > 0.0d ? markerScale : 1.0d;
+        if (Math.abs(boundaryPreviewMarkerScale - normalized) < 1e-6) {
+            return;
+        }
+        boundaryPreviewMarkerScale = normalized;
+        if (visualizationPanel == null) {
+            return;
+        }
+        if (SwingUtilities.isEventDispatchThread()) {
+            visualizationPanel.repaint();
+        } else {
+            SwingUtilities.invokeLater(visualizationPanel::repaint);
+        }
+    }
+
+    public boolean setHandheldMowerIconActive(boolean handheldActive) {
+        if (mower == null) {
+            return false;
+        }
+        boolean changed = mower.useHandheldIcon(handheldActive);
+        if (changed && visualizationPanel != null) {
+            if (SwingUtilities.isEventDispatchThread()) {
+                visualizationPanel.repaint();
+            } else {
+                SwingUtilities.invokeLater(visualizationPanel::repaint);
+            }
+        }
+        return changed;
+    }
+
     public void beginHandheldBoundaryPreview() {
         handheldBoundaryPreviewActive = true;
         handheldBoundaryPreview.clear();
@@ -1885,6 +2899,7 @@
     public void clearHandheldBoundaryPreview() {
         handheldBoundaryPreviewActive = false;
         handheldBoundaryPreview.clear();
+        boundaryPreviewMarkerScale = 1.0d;
         visualizationPanel.repaint();
     }
 
@@ -1940,8 +2955,10 @@
             return;
         }
 
-        double width = Math.max(bounds.width, 1);
-        double height = Math.max(bounds.height, 1);
+        Rectangle2D.Double targetBounds = includeMowerInBounds(bounds);
+
+        double width = Math.max(targetBounds.width, 1);
+        double height = Math.max(targetBounds.height, 1);
 
         double targetWidth = width * 1.2;
         double targetHeight = height * 1.2;
@@ -1953,18 +2970,374 @@
         newScale = Math.max(0.05, Math.min(newScale, 50.0));
 
         this.scale = newScale;
-        this.translateX = -bounds.getCenterX();
-        this.translateY = -bounds.getCenterY();
+        this.translateX = -targetBounds.getCenterX();
+        this.translateY = -targetBounds.getCenterY();
+    }
+
+    // Keep the mower marker inside the viewport whenever the camera refits to scene bounds.
+    private Rectangle2D.Double includeMowerInBounds(Rectangle2D.Double bounds) {
+        Rectangle2D.Double expanded = new Rectangle2D.Double(
+            bounds.x,
+            bounds.y,
+            Math.max(0.0, bounds.width),
+            Math.max(0.0, bounds.height)
+        );
+
+        if (mower == null || !mower.hasValidPosition()) {
+            return expanded;
+        }
+
+        Point2D.Double mowerPosition = mower.getPosition();
+        if (mowerPosition == null
+            || !Double.isFinite(mowerPosition.x)
+            || !Double.isFinite(mowerPosition.y)) {
+            return expanded;
+        }
+
+        double minX = Math.min(expanded.x, mowerPosition.x);
+        double minY = Math.min(expanded.y, mowerPosition.y);
+        double maxX = Math.max(expanded.x + expanded.width, mowerPosition.x);
+        double maxY = Math.max(expanded.y + expanded.height, mowerPosition.y);
+
+        expanded.x = minX;
+        expanded.y = minY;
+        expanded.width = Math.max(0.0, maxX - minX);
+        expanded.height = Math.max(0.0, maxY - minY);
+
+        return expanded;
     }
 
     public void dispose() {
         mowerUpdateTimer.stop();
-        stopMowerInfoTimer();
-        if (mowerInfoDialog != null) {
-            mowerInfoDialog.dispose();
-            mowerInfoDialog = null;
+        mowerInfoManager.dispose();
+    }
+
+    /**
+     * 鑾峰彇褰撳墠杈圭晫鐐瑰垪琛�
+     * @return 褰撳墠杈圭晫鐐瑰垪琛紝濡傛灉娌℃湁杈圭晫鍒欒繑鍥瀗ull
+     */
+    public List<Point2D.Double> getCurrentBoundary() {
+        return currentBoundary;
+    }
+
+    /**
+     * 鑾峰彇鍓茶崏鏈哄疄渚�
+     * @return 鍓茶崏鏈哄疄渚�
+     */
+    public Gecaoji getMower() {
+        return mower;
+    }
+    
+    /**
+     * 璁剧疆寰�杩旇矾寰勭粯鍒剁鐞嗗櫒
+     */
+    public void setReturnPathDrawer(WangfanDraw drawer) {
+        this.returnPathDrawer = drawer;
+    }
+
+    /**
+     * 璁剧疆棰勮鐨勫線杩旇矾寰�
+     */
+    public void setPreviewReturnPath(List<Point2D.Double> path) {
+        this.previewReturnPath = path;
+        if (visualizationPanel != null) {
+            visualizationPanel.repaint();
         }
-        resetMowerInfoLabels();
+    }
+    
+    /**
+     * 寮�濮嬪線杩旇矾寰勭粯鍒�
+     */
+    public void startReturnPathDrawing() {
+        if (returnPathDrawer != null) {
+            // 绂佺敤鎷栧熬鏁堟灉锛堝湪寰�杩旇矾寰勭粯鍒舵ā寮忎笅涓嶆樉绀哄疄鏃惰建杩规嫋灏撅級
+            idleTrailSuppressed = true;
+            clearIdleMowerTrail();
+            // 娓呯┖涔嬪墠鐨勮矾寰勭偣锛堥�氳繃 WangfanDraw 绠$悊锛�
+            repaint();
+        }
+    }
+    
+    /**
+     * 鍋滄寰�杩旇矾寰勭粯鍒�
+     */
+    public void stopReturnPathDrawing() {
+        // 鎭㈠鎷栧熬鏁堟灉
+        idleTrailSuppressed = false;
+        repaint();
+    }
+    
+    /**
+     * 璁剧疆鎷栧熬鎶戝埗鐘舵��
+     * @param suppressed true琛ㄧず鎶戝埗鎷栧熬缁樺埗锛宖alse琛ㄧず鍏佽鎷栧熬缁樺埗
+     */
+    public void setIdleTrailSuppressed(boolean suppressed) {
+        idleTrailSuppressed = suppressed;
+        if (suppressed && !idleMowerTrail.isEmpty()) {
+            clearIdleMowerTrail();
+        }
+        if (visualizationPanel != null) {
+            visualizationPanel.repaint();
+        }
+    }
+    
+    /**
+     * 娣诲姞寰�杩旇矾寰勭偣锛堝凡搴熷純锛岃矾寰勭偣鐢� WangfanDraw 鐩存帴绠$悊锛�
+     */
+    @Deprecated
+    public void addReturnPathPoint(double x, double y) {
+        // 璺緞鐐圭敱 WangfanDraw 鐩存帴绠$悊锛岃繖閲屽彧闇�瑕侀噸缁�
+        repaint();
+    }
+    
+    /**
+     * 鑾峰彇寰�杩旇矾寰勭偣鍒楄〃鐨勫揩鐓�
+     */
+    public List<Point2D.Double> getReturnPathPointsSnapshot() {
+        if (returnPathDrawer != null) {
+            return returnPathDrawer.getPointsSnapshot();
+        }
+        return new ArrayList<>();
+    }
+    
+    /**
+     * 璁剧疆杈圭晫棰勮鏁版嵁锛堝師濮嬭竟鐣屽拰浼樺寲鍚庤竟鐣岋級
+     */
+    public void setBoundaryPreview(String originalBoundaryXY, String optimizedBoundary) {
+        if (originalBoundaryXY != null && !originalBoundaryXY.trim().isEmpty() && !"-1".equals(originalBoundaryXY.trim())) {
+            previewOriginalBoundary = parseBoundary(originalBoundaryXY.trim());
+        } else {
+            previewOriginalBoundary = null;
+        }
+        
+        if (optimizedBoundary != null && !optimizedBoundary.trim().isEmpty() && !"-1".equals(optimizedBoundary.trim())) {
+            previewOptimizedBoundary = parseBoundary(optimizedBoundary.trim());
+        } else {
+            previewOptimizedBoundary = null;
+        }
+        
+        boundaryPreviewActive = (previewOriginalBoundary != null && previewOriginalBoundary.size() >= 2) ||
+                               (previewOptimizedBoundary != null && previewOptimizedBoundary.size() >= 2);
+        
+        if (boundaryPreviewActive) {
+            // 璁$畻棰勮杈圭晫鐨勮竟鐣屾骞惰皟鏁磋鍥�
+            List<Point2D.Double> allPoints = new ArrayList<>();
+            if (previewOriginalBoundary != null) allPoints.addAll(previewOriginalBoundary);
+            if (previewOptimizedBoundary != null) allPoints.addAll(previewOptimizedBoundary);
+            if (!allPoints.isEmpty()) {
+                Rectangle2D.Double bounds = computeBounds(allPoints);
+                SwingUtilities.invokeLater(() -> {
+                    fitBoundsToView(bounds);
+                    visualizationPanel.repaint();
+                });
+            }
+        } else {
+            visualizationPanel.repaint();
+        }
+    }
+    
+    /**
+     * 娓呴櫎杈圭晫棰勮
+     */
+    public void clearBoundaryPreview() {
+        previewOriginalBoundary = null;
+        previewOptimizedBoundary = null;
+        boundaryPreviewActive = false;
+        visualizationPanel.repaint();
+    }
+    
+    /**
+     * 缁樺埗杈圭晫棰勮锛堝師濮嬭竟鐣�-绱壊锛屼紭鍖栧悗杈圭晫-缁胯壊锛�
+     */
+    private void drawBoundaryPreview(Graphics2D g2d) {
+        // 缁樺埗鍘熷杈圭晫锛堢传鑹诧級
+        if (previewOriginalBoundary != null && previewOriginalBoundary.size() >= 2) {
+            Color purpleFill = new Color(128, 0, 128, 80); // 绱壊鍗婇�忔槑濉厖
+            Color purpleBorder = new Color(128, 0, 128, 255); // 绱壊杈规
+            bianjiedrwa.drawBoundary(g2d, previewOriginalBoundary, scale, purpleFill, purpleBorder);
+        }
+        
+        // 缁樺埗浼樺寲鍚庤竟鐣岋紙缁胯壊锛屼笌姝e父杈圭晫棰滆壊涓�鑷达級
+        if (previewOptimizedBoundary != null && previewOptimizedBoundary.size() >= 2) {
+            bianjiedrwa.drawBoundary(g2d, previewOptimizedBoundary, scale, GRASS_FILL_COLOR, GRASS_BORDER_COLOR);
+            
+            // 缁樺埗浼樺寲鍚庤竟鐣屽潗鏍囩偣锛堢传鑹插疄蹇冨渾鍦堬紝鏄剧ず搴忓彿锛�
+            drawOptimizedBoundaryPointsWithNumbers(g2d, previewOptimizedBoundary, scale);
+        }
+    }
+    
+    /**
+     * 缁樺埗浼樺寲鍚庤竟鐣屽潗鏍囩偣锛堢传鑹插疄蹇冨渾鍦堬紝鏄剧ず搴忓彿锛�
+     * 搴忓彿鏄剧ず鍦ㄧ偣涓績锛屽瓧浣撳ぇ灏�11鍙凤紝涓嶉殢缂╂斁鍙樺寲
+     */
+    private void drawOptimizedBoundaryPointsWithNumbers(Graphics2D g2d, List<Point2D.Double> boundary, double scale) {
+        if (boundary == null || boundary.isEmpty()) {
+            return;
+        }
+        
+        // 淇濆瓨鍘熷鍙樻崲
+        AffineTransform originalTransform = g2d.getTransform();
+        
+        // 璁剧疆鐐圭殑澶у皬锛堝疄蹇冨渾鍦堬紝鐩村緞绾�0.3绫筹級
+        double scaleFactor = Math.max(0.5, scale);
+        double markerDiameter = 0.3; // 鍦嗗湀鐩村緞锛堢背锛�
+        double markerRadius = markerDiameter / 2.0;
+        
+        // 璁剧疆瀛椾綋锛�11鍙凤紝涓嶉殢缂╂斁鍙樺寲锛�
+        Font labelFont = new Font("寰蒋闆呴粦", Font.PLAIN, 11);
+        g2d.setFont(labelFont);
+        FontMetrics fontMetrics = g2d.getFontMetrics(labelFont);
+        
+        // 绱壊瀹炲績鍦嗗湀棰滆壊
+        Color purpleColor = new Color(128, 0, 128, 255); // 绱壊
+        
+        // 缁樺埗姣忎釜鐐瑰強鍏跺簭鍙�
+        for (int i = 0; i < boundary.size(); i++) {
+            Point2D.Double point = boundary.get(i);
+            double x = point.x;
+            double y = point.y;
+            
+            // 缁樺埗绱壊瀹炲績鍦嗗湀锛堝湪涓栫晫鍧愭爣绯讳腑锛岄殢缂╂斁鍙樺寲锛�
+            g2d.setColor(purpleColor);
+            Ellipse2D.Double marker = new Ellipse2D.Double(
+                x - markerRadius, 
+                y - markerRadius, 
+                markerDiameter, 
+                markerDiameter
+            );
+            g2d.fill(marker);
+            
+            // 灏嗕笘鐣屽潗鏍囪浆鎹负灞忓箷鍧愭爣浠ョ粯鍒跺簭鍙凤紙涓嶉殢缂╂斁鍙樺寲锛�
+            Point2D.Double worldPoint = new Point2D.Double(x, y);
+            Point2D.Double screenPoint = new Point2D.Double();
+            originalTransform.transform(worldPoint, screenPoint);
+            
+            // 淇濆瓨褰撳墠鍙樻崲
+            AffineTransform savedTransform = g2d.getTransform();
+            
+            // 閲嶇疆鍙樻崲涓哄睆骞曞潗鏍囩郴缁�
+            g2d.setTransform(new AffineTransform());
+            
+            // 缁樺埗搴忓彿锛堝湪灞忓箷鍧愭爣绯讳腑锛屼笉闅忕缉鏀惧彉鍖栵級
+            String numberText = String.valueOf(i + 1);
+            int textWidth = fontMetrics.stringWidth(numberText);
+            int textHeight = fontMetrics.getHeight();
+            
+            // 鍦ㄧ偣涓績缁樺埗搴忓彿
+            int textX = (int)(screenPoint.x - textWidth / 2.0);
+            int textY = (int)(screenPoint.y + textHeight / 4.0);
+            
+            // 缁樺埗搴忓彿鏂囧瓧锛堥粦鑹诧級
+            g2d.setColor(Color.BLACK);
+            g2d.drawString(numberText, textX, textY);
+            
+            // 鎭㈠鍙樻崲
+            g2d.setTransform(savedTransform);
+        }
+        
+        // 鎭㈠鍘熷鍙樻崲
+        g2d.setTransform(originalTransform);
+    }
+    
+    /**
+     * 澶勭悊浼樺寲鍚庤竟鐣屽潗鏍囩偣鐐瑰嚮
+     * @param screenPoint 灞忓箷鍧愭爣鐐�
+     * @return 鏄惁澶勭悊浜嗙偣鍑�
+     */
+    private boolean handleOptimizedBoundaryPointClick(Point screenPoint) {
+        if (previewOptimizedBoundary == null || previewOptimizedBoundary.isEmpty()) {
+            return false;
+        }
+        
+        // 璁$畻閫夋嫨闃堝�硷紙鍍忕礌锛�
+        double threshold = computeOptimizedBoundaryPointSelectionThreshold();
+        
+        // 鏌ユ壘琚偣鍑荤殑鐐�
+        int hitIndex = -1;
+        for (int i = 0; i < previewOptimizedBoundary.size(); i++) {
+            Point2D.Double worldPoint = previewOptimizedBoundary.get(i);
+            Point2D.Double screenPosition = worldToScreen(worldPoint);
+            double dx = screenPosition.x - screenPoint.x;
+            double dy = screenPosition.y - screenPoint.y;
+            if (Math.hypot(dx, dy) <= threshold) {
+                hitIndex = i;
+                break;
+            }
+        }
+        
+        if (hitIndex < 0) {
+            return false;
+        }
+        
+        // 寮瑰嚭纭瀵硅瘽妗�
+        String pointLabel = String.valueOf(hitIndex + 1);
+        int choice = JOptionPane.showConfirmDialog(
+            visualizationPanel,
+            "纭畾瑕佸垹闄ょ" + pointLabel + "鍙蜂紭鍖栧悗杈圭晫鍧愭爣鐐瑰悧锛�",
+            "鍒犻櫎杈圭晫鍧愭爣鐐�",
+            JOptionPane.OK_CANCEL_OPTION,
+            JOptionPane.WARNING_MESSAGE
+        );
+        
+        if (choice == JOptionPane.OK_OPTION) {
+            // 鍒犻櫎鍧愭爣鐐�
+            List<Point2D.Double> updated = new ArrayList<>(previewOptimizedBoundary);
+            updated.remove(hitIndex);
+            
+            // 鏇存柊棰勮杈圭晫
+            previewOptimizedBoundary = updated;
+            
+            // 杞崲涓哄瓧绗︿覆鏍煎紡骞朵繚瀛�
+            String updatedBoundaryString = convertBoundaryToString(updated);
+            
+            // 閫氱煡 Shouye 淇濆瓨鏇存柊鍚庣殑杈圭晫鍧愭爣
+            if (boundaryPreviewUpdateCallback != null) {
+                boundaryPreviewUpdateCallback.accept(updatedBoundaryString);
+            }
+            
+            // 鍒锋柊鏄剧ず
+            visualizationPanel.repaint();
+        }
+        
+        return true;
+    }
+    
+    /**
+     * 璁$畻浼樺寲鍚庤竟鐣屽潗鏍囩偣鐨勯�夋嫨闃堝�硷紙鍍忕礌锛�
+     */
+    private double computeOptimizedBoundaryPointSelectionThreshold() {
+        double scaleFactor = Math.max(0.5, scale);
+        double markerDiameterWorld = 0.3; // 鍦嗗湀鐩村緞锛堢背锛�
+        double markerDiameterPixels = markerDiameterWorld * scale;
+        return Math.max(8.0, markerDiameterPixels * 1.5);
+    }
+    
+    /**
+     * 灏嗚竟鐣岀偣鍒楄〃杞崲涓哄瓧绗︿覆鏍煎紡
+     */
+    private String convertBoundaryToString(List<Point2D.Double> boundary) {
+        if (boundary == null || boundary.isEmpty()) {
+            return "";
+        }
+        
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < boundary.size(); i++) {
+            Point2D.Double point = boundary.get(i);
+            sb.append(String.format(Locale.US, "%.2f,%.2f", point.x, point.y));
+            if (i < boundary.size() - 1) {
+                sb.append(";");
+            }
+        }
+        return sb.toString();
+    }
+    
+    /**
+     * 璁剧疆杈圭晫棰勮鏇存柊鍥炶皟
+     */
+    private java.util.function.Consumer<String> boundaryPreviewUpdateCallback;
+    
+    public void setBoundaryPreviewUpdateCallback(java.util.function.Consumer<String> callback) {
+        this.boundaryPreviewUpdateCallback = callback;
     }
 
 }
\ No newline at end of file

--
Gitblit v1.10.0