From f784463ab019c1113cf0b31a249e8802b07a57fa Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期二, 16 十二月 2025 15:26:15 +0800
Subject: [PATCH] 保存地图最后位置

---
 src/zhuye/MapRenderer.java | 1356 ++++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 1,064 insertions(+), 292 deletions(-)

diff --git a/src/zhuye/MapRenderer.java b/src/zhuye/MapRenderer.java
index 9cb5475..8406d2b 100644
--- a/src/zhuye/MapRenderer.java
+++ b/src/zhuye/MapRenderer.java
@@ -6,35 +6,45 @@
 import java.awt.FontMetrics;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Ellipse2D;
+import java.awt.geom.Path2D;
 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 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;
 
 /**
  * 鍦板浘娓叉煋鍣� - 璐熻矗鍧愭爣绯荤粯鍒躲�佽鍥惧彉鎹㈢瓑鍔熻兘
  */
 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);
@@ -42,16 +52,17 @@
     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 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 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;
@@ -60,28 +71,107 @@
     private String currentObstacleLandNumber;
     private String boundaryName;
     private boolean boundaryPointsVisible;
+    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 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;
+    private double defaultMowerWidthMeters;
+    private double totalLandAreaSqMeters;
+    private double trackLengthMeters;
+    private double completedMowingAreaSqMeters;
+    private double mowingCompletionRatio;
+    private long lastTrackPersistTimeMillis;
+    private boolean trackDirty;
+    private boolean handheldBoundaryPreviewActive;
+    private boolean pendingTrackBreak = true;
+    private boolean idleTrailSuppressed;
+    private Path2D.Double realtimeBoundaryPathCache;
+    private String realtimeBoundaryPathLand;
+
+    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));
     }
     
     /**
@@ -90,10 +180,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);
         });
         
         // 榧犳爣鎷栨嫿绉诲姩
@@ -143,18 +233,16 @@
                     visualizationPanel.repaint();
                 }
             }
-            
-            public void mouseMoved(MouseEvent e) {
-                // 鏇存柊榧犳爣浣嶇疆鐢ㄤ簬鏄剧ず鍧愭爣
-                mousePoint = e.getPoint();
-                visualizationPanel.repaint();
-            }
         });
     }
 
     private Timer createMowerTimer() {
         Timer timer = new Timer(300, e -> {
             mower.refreshFromDevice();
+            updateIdleMowerTrail();
+            if (realtimeTrackRecording) {
+                captureRealtimeTrackPoint();
+            }
             if (visualizationPanel != null) {
                 visualizationPanel.repaint();
             }
@@ -168,34 +256,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();
     }
     
@@ -239,21 +364,32 @@
             drawCircleCaptureOverlay(g2d, circleCaptureOverlay, scale);
         }
 
+    adddikuaiyulan.drawPreview(g2d, handheldBoundaryPreview, scale, handheldBoundaryPreviewActive, boundaryPreviewMarkerScale);
+
         if (hasPlannedPath) {
             drawCurrentPlannedPath(g2d);
         }
 
         if (boundaryPointsVisible && hasBoundary) {
+            double markerScale = boundaryPointSizeScale * (previewSizingEnabled ? PREVIEW_BOUNDARY_MARKER_SCALE : 1.0d);
             pointandnumber.drawBoundaryPoints(
                 g2d,
                 currentBoundary,
                 scale,
                 BOUNDARY_POINT_MERGE_THRESHOLD,
                 BOUNDARY_POINT_COLOR,
-                BOUNDARY_LABEL_COLOR
+                markerScale
             );
         }
 
+        if (shouldRenderIdleTrail()) {
+            tuowei.draw(g2d, idleMowerTrail, scale);
+        }
+
+        if (!realtimeMowingTrack.isEmpty()) {
+            drawRealtimeMowingCoverage(g2d);
+        }
+
         drawMower(g2d);
         
         // 鎭㈠鍘熷鍙樻崲
@@ -269,7 +405,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));
     }
     
     
@@ -281,6 +417,578 @@
         mower.draw(g2d, scale);
     }
 
+    private void drawRealtimeMowingCoverage(Graphics2D g2d) {
+        if (realtimeMowingTrack == null || realtimeMowingTrack.size() < 2) {
+            return;
+        }
+
+        Path2D.Double boundaryPath = getRealtimeBoundaryPath();
+        double effectiveWidth = getEffectiveMowerWidthMeters();
+        gecaolunjing.draw(g2d, realtimeMowingTrack, effectiveWidth, boundaryPath);
+    }
+
+    private Path2D.Double getRealtimeBoundaryPath() {
+        if (realtimeTrackLandNumber == null) {
+            return null;
+        }
+
+        if (currentBoundaryLandNumber != null && realtimeTrackLandNumber.equals(currentBoundaryLandNumber)) {
+            if (currentBoundaryPath == null) {
+                currentBoundaryPath = buildBoundaryPath(currentBoundary);
+            }
+            return currentBoundaryPath;
+        }
+
+        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 = Double.NaN;
+        if (lastPoint != null) {
+            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(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() {
+        double widthMeters = getEffectiveMowerWidthMeters();
+        if (widthMeters > 0 && trackLengthMeters > 0) {
+            completedMowingAreaSqMeters = trackLengthMeters * widthMeters;
+        } else {
+            completedMowingAreaSqMeters = 0.0;
+        }
+
+        if (totalLandAreaSqMeters > 0 && completedMowingAreaSqMeters >= 0) {
+            mowingCompletionRatio = Math.max(0.0, Math.min(1.0, completedMowingAreaSqMeters / totalLandAreaSqMeters));
+        } else {
+            mowingCompletionRatio = 0.0;
+        }
+    }
+
+    private void maybePersistRealtimeTrack(boolean force) {
+        if (!trackDirty) {
+            return;
+        }
+        long now = System.currentTimeMillis();
+        if (!force && (now - lastTrackPersistTimeMillis) < TRACK_PERSIST_INTERVAL_MS) {
+            return;
+        }
+        persistRealtimeTrack();
+    }
+
+    private void persistRealtimeTrack() {
+        if (realtimeTrackLandNumber == null) {
+            trackDirty = false;
+            return;
+        }
+        String serialized = serializeRealtimeTrack();
+        String storedValue = (serialized == null || serialized.isEmpty()) ? "-1" : serialized;
+        boolean updated = Dikuai.updateField(realtimeTrackLandNumber, "mowingTrack", storedValue);
+        if (updated) {
+            Dikuai dikuai = Dikuai.getDikuai(realtimeTrackLandNumber);
+            if (dikuai != null) {
+                dikuai.setMowingTrack(storedValue);
+            }
+            Dikuai.saveToProperties();
+            trackDirty = false;
+            lastTrackPersistTimeMillis = System.currentTimeMillis();
+        }
+    }
+
+    private String serializeRealtimeTrack() {
+        if (realtimeMowingTrack.isEmpty()) {
+            return "";
+        }
+        StringBuilder builder = new StringBuilder();
+        for (Point2D.Double point : realtimeMowingTrack) {
+            if (point == null) {
+                continue;
+            }
+            if (builder.length() > 0) {
+                builder.append(';');
+            }
+            builder.append(formatTrackCoordinate(point.x)).append(',').append(formatTrackCoordinate(point.y));
+        }
+        return builder.toString();
+    }
+
+    private String formatTrackCoordinate(double value) {
+        if (!Double.isFinite(value)) {
+            return "0";
+        }
+        return String.format(Locale.US, "%.3f", value);
+    }
+
+    private double getEffectiveMowerWidthMeters() {
+        if (mowerEffectiveWidthMeters > 0) {
+            return mowerEffectiveWidthMeters;
+        }
+        if (defaultMowerWidthMeters > 0) {
+            return defaultMowerWidthMeters;
+        }
+        return 0.0;
+    }
+
+    public void applyLandMetadata(Dikuai dikuai) {
+        String landNumber = normalizeValue(dikuai != null ? dikuai.getLandNumber() : null);
+        totalLandAreaSqMeters = parseLandAreaSqMeters(dikuai != null ? dikuai.getLandArea() : null);
+        defaultMowerWidthMeters = parseMowerWidthMeters(dikuai != null ? dikuai.getMowingWidth() : null);
+
+        // 鑻ュ綋鍓嶆湭褰曞埗鎴栧垏鎹㈠湴鍧楋紝鍒欐洿鏂版湁鏁堝壊鑽夊搴�
+        if (!realtimeTrackRecording || !equalsLand(landNumber, realtimeTrackLandNumber)) {
+            mowerEffectiveWidthMeters = defaultMowerWidthMeters;
+        }
+
+        loadRealtimeTrack(landNumber, dikuai != null ? dikuai.getMowingTrack() : null);
+        visualizationPanel.repaint();
+    }
+
+    public void startRealtimeTrackRecording(String landNumber, double widthMeters) {
+        String normalizedLand = normalizeValue(landNumber);
+        if (normalizedLand == null) {
+            return;
+        }
+
+        if (!equalsLand(normalizedLand, realtimeTrackLandNumber)) {
+            Dikuai dikuai = Dikuai.getDikuai(normalizedLand);
+            totalLandAreaSqMeters = parseLandAreaSqMeters(dikuai != null ? dikuai.getLandArea() : null);
+            defaultMowerWidthMeters = parseMowerWidthMeters(dikuai != null ? dikuai.getMowingWidth() : null);
+            loadRealtimeTrack(normalizedLand, dikuai != null ? dikuai.getMowingTrack() : null);
+        }
+
+        if (widthMeters > 0) {
+            mowerEffectiveWidthMeters = widthMeters;
+        } else if (mowerEffectiveWidthMeters <= 0) {
+            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);
+    }
+
+    public void forceRealtimeTrackSnapshot() {
+        if (!realtimeTrackRecording) {
+            return;
+        }
+        captureRealtimeTrackPoint();
+    }
+
+    public void clearRealtimeTrack() {
+        realtimeTrackRecording = false;
+        realtimeMowingTrack.clear();
+        trackLengthMeters = 0.0;
+        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;
+    }
+
+    public double getTotalLandAreaSqMeters() {
+        return totalLandAreaSqMeters;
+    }
+
+    public double getTrackLengthMeters() {
+        return trackLengthMeters;
+    }
+
+    private boolean isMowerInsideSelectedBoundary() {
+        Point2D.Double position = mower.getPosition();
+        if (position == null) {
+            return false;
+        }
+        return isPointInsideActiveBoundary(position);
+    }
+
+    public void flushRealtimeTrack() {
+        maybePersistRealtimeTrack(true);
+    }
+
+    private void loadRealtimeTrack(String landNumber, String trackData) {
+        realtimeTrackRecording = false;
+        realtimeTrackLandNumber = landNumber;
+        realtimeMowingTrack.clear();
+        trackLengthMeters = 0.0;
+        completedMowingAreaSqMeters = 0.0;
+        mowingCompletionRatio = 0.0;
+        trackDirty = false;
+        lastTrackPersistTimeMillis = 0L;
+        pendingTrackBreak = true;
+        realtimeBoundaryPathCache = null;
+        realtimeBoundaryPathLand = null;
+
+        String trimmed = normalizeValue(trackData);
+        if (trimmed == null || trimmed.isEmpty()) {
+            updateCompletionMetrics();
+            return;
+        }
+
+        String[] segments = trimmed.split(";");
+        Path2D.Double boundaryPath = getRealtimeBoundaryPath();
+        Point2D.Double lastPoint = null;
+        for (String segment : segments) {
+            if (segment == null || segment.trim().isEmpty()) {
+                continue;
+            }
+            String[] parts = segment.trim().split(",");
+            if (parts.length < 2) {
+                continue;
+            }
+            try {
+                double x = Double.parseDouble(parts[0].trim());
+                double y = Double.parseDouble(parts[1].trim());
+                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) {
+                // 璺宠繃寮傚父鏉$洰
+            }
+        }
+
+        updateCompletionMetrics();
+    }
+
+    private double parseLandAreaSqMeters(String raw) {
+        if (raw == null) {
+            return 0.0;
+        }
+        String trimmed = raw.trim();
+        if (trimmed.isEmpty() || "-1".equals(trimmed)) {
+            return 0.0;
+        }
+        try {
+            double area = Double.parseDouble(trimmed);
+            return area > 0 ? area : 0.0;
+        } catch (NumberFormatException ex) {
+            return 0.0;
+        }
+    }
+
+    private double parseMowerWidthMeters(String raw) {
+        if (raw == null) {
+            return 0.0;
+        }
+        String sanitized = raw.trim().toLowerCase(Locale.ROOT);
+        if (sanitized.isEmpty() || "-1".equals(sanitized)) {
+            return 0.0;
+        }
+        sanitized = sanitized.replace("鍘樼背", "cm");
+        sanitized = sanitized.replace("鍏垎", "cm");
+        sanitized = sanitized.replace("绫�", "m");
+        sanitized = sanitized.replace("cm", "");
+        sanitized = sanitized.replace("m", "");
+        sanitized = sanitized.trim();
+        if (sanitized.isEmpty()) {
+            return 0.0;
+        }
+        try {
+            double value = Double.parseDouble(sanitized);
+            if (value <= 0) {
+                return 0.0;
+            }
+            if (value > 10) {
+                return value / 100.0; // 瑙嗕负鍘樼背
+            }
+            return value;
+        } catch (NumberFormatException ex) {
+            return 0.0;
+        }
+    }
+
+    private String normalizeValue(String value) {
+        if (value == null) {
+            return null;
+        }
+        String trimmed = value.trim();
+        if (trimmed.isEmpty() || "-1".equals(trimmed)) {
+            return null;
+        }
+        return trimmed;
+    }
+
+    private boolean equalsLand(String a, String b) {
+        if (a == null && b == null) {
+            return true;
+        }
+        if (a == null || b == null) {
+            return false;
+        }
+        return a.equals(b);
+    }
+
     private boolean handleMowerClick(Point screenPoint) {
         if (!mower.hasValidPosition()) {
             return false;
@@ -314,7 +1022,8 @@
     }
 
     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) {
@@ -448,217 +1157,9 @@
         }
     }
 
-    private void showMowerInfo() {
-        Device device = Device.getGecaoji();
-        if (device == null) {
-            JOptionPane.showMessageDialog(
-                visualizationPanel,
-                "鏃犺澶囨暟鎹�",
-                "鍓茶崏鏈轰俊鎭�",
-                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;
-            }
-        });
-
-        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;
+    public void showMowerInfo() {
+        if (mowerInfoManager != null) {
+            mowerInfoManager.showMowerInfo();
         }
     }
 
@@ -711,7 +1212,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);
     }
@@ -751,6 +1256,7 @@
 
         if (updated.size() < 2) {
             currentBoundary = null;
+            currentBoundaryPath = null;
             boundaryBounds = null;
             boundaryPointsVisible = false;
             Dikuaiguanli.updateBoundaryPointVisibility(currentBoundaryLandNumber, false);
@@ -758,10 +1264,12 @@
             adjustViewAfterBoundaryReset();
         } else {
             currentBoundary = updated;
+            rebuildBoundaryPath();
             boundaryBounds = computeBounds(updated);
             Dikuaiguanli.updateBoundaryPointVisibility(currentBoundaryLandNumber, boundaryPointsVisible);
             visualizationPanel.repaint();
         }
+        pendingTrackBreak = true;
     }
 
     private boolean persistBoundaryChanges(List<Point2D.Double> updatedBoundary) {
@@ -823,6 +1331,101 @@
         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;
+    }
+
     
     /**
      * 缁樺埗瑙嗗浘淇℃伅
@@ -830,30 +1433,34 @@
     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);
+
+        // 鍦ㄥ湴鍥鹃《閮ㄥ乏渚ф樉绀洪仴鎺ф憞鏉嗗搴旈�熷害锛堣嫢闈為浂锛�
+        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 tips = "婊氳疆缂╂斁 | 鎷栨嫿绉诲姩 | 鍙抽敭閲嶇疆";
-        // g2d.drawString(tips, visualizationPanel.getWidth() - 200, 30);
-    }
-    
-    /**
-     * 鑾峰彇褰撳墠缂╂斁姣斾緥
-     */
-    public double getScale() {
-        return scale;
+
+        // 淇濈暀搴曢儴鐨勭缉鏀炬瘮渚嬩俊鎭�
+        String info = String.format("缂╂斁: %.2fx", scale);
+        g2d.setColor(new Color(80, 80, 80));
+        g2d.drawString(info, 15, visualizationPanel.getHeight() - 15);
     }
     
     /**
@@ -874,7 +1481,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();
@@ -883,6 +1498,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();
@@ -904,8 +1521,10 @@
             return;
         }
 
-        currentBoundary = parsed;
-        boundaryBounds = computeBounds(parsed);
+    currentBoundary = parsed;
+    rebuildBoundaryPath();
+    pendingTrackBreak = true;
+    boundaryBounds = computeBounds(parsed);
 
         Rectangle2D.Double bounds = boundaryBounds;
         SwingUtilities.invokeLater(() -> {
@@ -916,10 +1535,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) {
@@ -1230,6 +1853,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) {
@@ -1239,6 +1865,10 @@
             if (trimmed.isEmpty()) {
                 continue;
             }
+            trimmed = trimmed.replace("(", "").replace(")", "");
+            if (trimmed.isEmpty()) {
+                continue;
+            }
             String[] parts = trimmed.split(",");
             if (parts.length < 2) {
                 continue;
@@ -1400,6 +2030,102 @@
         visualizationPanel.repaint();
     }
 
+    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();
+        visualizationPanel.repaint();
+    }
+
+    public void addHandheldBoundaryPoint(double x, double y) {
+        if (!Double.isFinite(x) || !Double.isFinite(y)) {
+            return;
+        }
+        if (!handheldBoundaryPreviewActive) {
+            beginHandheldBoundaryPreview();
+        }
+        Point2D.Double last = handheldBoundaryPreview.isEmpty() ? null : handheldBoundaryPreview.get(handheldBoundaryPreview.size() - 1);
+        if (last != null) {
+            double dx = x - last.x;
+            double dy = y - last.y;
+            if (Math.hypot(dx, dy) < 1e-6) {
+                visualizationPanel.repaint();
+                return;
+            }
+        }
+        handheldBoundaryPreview.add(new Point2D.Double(x, y));
+        visualizationPanel.repaint();
+    }
+
+    public void clearHandheldBoundaryPreview() {
+        handheldBoundaryPreviewActive = false;
+        handheldBoundaryPreview.clear();
+        boundaryPreviewMarkerScale = 1.0d;
+        visualizationPanel.repaint();
+    }
+
+    public List<Point2D.Double> getHandheldBoundaryPreviewPoints() {
+        return new ArrayList<>(handheldBoundaryPreview);
+    }
+
     private List<Point2D.Double> parseBoundary(String boundaryCoordinates) {
         List<Point2D.Double> points = new ArrayList<>();
         String[] entries = boundaryCoordinates.split(";");
@@ -1448,8 +2174,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;
@@ -1461,18 +2189,62 @@
         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;
-        }
-        resetMowerInfoLabels();
+        mowerInfoManager.dispose();
+    }
+
+    /**
+     * 鑾峰彇褰撳墠杈圭晫鐐瑰垪琛�
+     * @return 褰撳墠杈圭晫鐐瑰垪琛紝濡傛灉娌℃湁杈圭晫鍒欒繑鍥瀗ull
+     */
+    public List<Point2D.Double> getCurrentBoundary() {
+        return currentBoundary;
+    }
+
+    /**
+     * 鑾峰彇鍓茶崏鏈哄疄渚�
+     * @return 鍓茶崏鏈哄疄渚�
+     */
+    public Gecaoji getMower() {
+        return mower;
     }
 
 }
\ No newline at end of file

--
Gitblit v1.10.0