From 48ee74129bb09a817a0bbbabe860c4007b74c66b Mon Sep 17 00:00:00 2001
From: 826220679@qq.com <826220679@qq.com>
Date: 星期日, 21 十二月 2025 12:37:44 +0800
Subject: [PATCH] 新增了往返路径

---
 src/zhuye/Shouye.java |  927 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 857 insertions(+), 70 deletions(-)

diff --git a/src/zhuye/Shouye.java b/src/zhuye/Shouye.java
index c462a83..22f8fc6 100644
--- a/src/zhuye/Shouye.java
+++ b/src/zhuye/Shouye.java
@@ -11,29 +11,31 @@
 import java.awt.event.*;
 
 import chuankou.dellmessage;
+import chuankou.sendmessage;
+import chuankou.SerialPortService;
 import dikuai.Dikuai;
 import dikuai.Dikuaiguanli;
 import dikuai.addzhangaiwu;
 import gecaoji.Device;
 import gecaoji.Gecaoji;
 import gecaoji.MowerBoundaryChecker;
+import publicway.buttonset;
 import set.Sets;
 import set.debug;
 import udpdell.UDPServer;
 import zhangaiwu.AddDikuai;
-import yaokong.Control04;
 import yaokong.RemoteControlDialog;
-
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Locale;
-import java.util.Objects;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.function.Consumer;
 import java.awt.geom.Point2D;
 
+import publicway.Gpstoxuzuobiao;
+
 /**
  * 棣栭〉鐣岄潰 - 閫傞厤6.5瀵哥珫灞忥紝浣跨敤鐙珛鐨凪apRenderer杩涜缁樺埗
  */
@@ -78,6 +80,17 @@
 	private JLabel statusLabel;
 	private JLabel speedLabel;  // 閫熷害鏄剧ず鏍囩
 	private JLabel areaNameLabel;
+	private JLabel drawingBoundaryLabel;  // 姝e湪缁樺埗杈圭晫鐘舵�佹爣绛�
+	private JLabel navigationPreviewLabel;  // 瀵艰埅棰勮妯″紡鏍囩
+	
+	// 杈圭晫璀﹀憡鐩稿叧
+	private Timer boundaryWarningTimer;  // 杈圭晫璀﹀憡妫�鏌ュ畾鏃跺櫒
+	private Timer warningBlinkTimer;  // 璀﹀憡鍥炬爣闂儊瀹氭椂鍣�
+	private boolean isMowerOutsideBoundary = false;  // 鍓茶崏鏈烘槸鍚﹀湪杈圭晫澶�
+	private boolean warningIconVisible = true;  // 璀﹀憡鍥炬爣鏄剧ず鐘舵�侊紙鐢ㄤ簬闂儊锛�
+	
+	// 浠ュ壊鑽夋満涓轰腑蹇冭鍥炬ā寮�
+	private boolean centerOnMowerMode = false;  // 鏄惁澶勪簬浠ュ壊鑽夋満涓轰腑蹇冪殑妯″紡
 
 	// 褰撳墠閫変腑鐨勫鑸寜閽�
 	private JButton currentNavButton;
@@ -94,12 +107,14 @@
 	// 鍦板浘娓叉煋鍣�
 	private MapRenderer mapRenderer;
 	
+	private boolean pathPreviewActive;
+	
 	private final Consumer<String> serialLineListener = line -> {
 		SwingUtilities.invokeLater(() -> {
 			updateDataPacketCountLabel();
 			// 濡傛灉鏀跺埌$GNGGA鏁版嵁锛岀珛鍗虫洿鏂版嫋灏�
 			if (line != null && line.trim().startsWith("$GNGGA")) {
-				if (mapRenderer != null) {
+				if (mapRenderer != null && !pathPreviewActive) {
 					mapRenderer.forceUpdateIdleMowerTrail();
 				}
 			}
@@ -112,8 +127,9 @@
 	private JPanel floatingButtonColumn;
 	private Runnable endDrawingCallback;
 	private JButton pathPreviewReturnButton;
-	private boolean pathPreviewActive;
 	private Runnable pathPreviewReturnAction;
+	private JButton settingsReturnButton;  // 杩斿洖绯荤粺璁剧疆椤甸潰鐨勬偓娴寜閽�
+	private JButton saveManualBoundaryButton;  // 淇濆瓨鎵嬪姩缁樺埗杈圭晫鐨勬寜閽�
 	private String previewRestoreLandNumber;
 	private String previewRestoreLandName;
 	private boolean drawingPaused;
@@ -155,6 +171,7 @@
 	private boolean storedStopButtonActive;
 	private String storedStatusBeforeDrawing;
 	private boolean handheldCaptureInlineUiActive;
+	private WangfanDraw returnPathDrawer;  // 寰�杩旇矾寰勭粯鍒剁鐞嗗櫒
 	private Timer handheldCaptureStatusTimer;
 	private String handheldCaptureStoredStatusText;
 	private Color handheldStartButtonOriginalBackground;
@@ -194,6 +211,54 @@
 		// 鍒濆鍖栧湴鍥炬覆鏌撳櫒
 		mapRenderer = new MapRenderer(visualizationPanel);
 		applyIdleTrailDurationFromSettings();
+		
+		// 鍒濆鍖栧線杩旇矾寰勭粯鍒剁鐞嗗櫒
+		returnPathDrawer = new WangfanDraw(this, mapRenderer, new WangfanDraw.DrawingHelper() {
+			@Override
+			public double[] resolveBaseLatLon() {
+				return resolveCircleBaseLatLon();
+			}
+			
+			@Override
+			public Coordinate getLatestCoordinate() {
+				return Shouye.this.getLatestCoordinate();
+			}
+			
+			@Override
+			public double parseDMToDecimal(String dmm, String direction) {
+				return Shouye.this.parseDMToDecimal(dmm, direction);
+			}
+			
+			@Override
+			public double[] convertLatLonToLocal(double lat, double lon, double baseLat, double baseLon) {
+				return Shouye.this.convertLatLonToLocal(lat, lon, baseLat, baseLon);
+			}
+			
+			@Override
+			public boolean arePointsClose(Point2D.Double a, Point2D.Double b) {
+				return Shouye.this.arePointsClose(a, b);
+			}
+			
+			@Override
+			public void enterDrawingControlMode() {
+				Shouye.this.enterDrawingControlMode();
+			}
+			
+			@Override
+			public void exitDrawingControlMode() {
+				Shouye.this.exitDrawingControlMode();
+			}
+			
+			@Override
+			public boolean isDrawingPaused() {
+				return drawingPaused;
+			}
+		});
+		
+		// 璁剧疆 MapRenderer 鐨勫線杩旇矾寰勭粯鍒剁鐞嗗櫒
+		if (mapRenderer != null) {
+			mapRenderer.setReturnPathDrawer(returnPathDrawer);
+		}
 
 		// 鍒濆鍖栧璇濇寮曠敤涓簄ull锛屽欢杩熷垱寤�
 		legendDialog = null;
@@ -207,6 +272,9 @@
 
 		initializeDefaultAreaSelection();
 		refreshMapForSelectedArea();
+		
+		// 鍚姩杈圭晫璀﹀憡妫�鏌ュ畾鏃跺櫒
+		startBoundaryWarningTimer();
 	}
 
 	private void scheduleIdentifierCheck() {
@@ -239,6 +307,14 @@
 				public void windowClosing(WindowEvent e) {
 					// 淇濆瓨褰撳墠缂╂斁姣斾緥
 					saveCurrentScale();
+					// 鍋滄杈圭晫璀﹀憡瀹氭椂鍣�
+					if (boundaryWarningTimer != null && boundaryWarningTimer.isRunning()) {
+						boundaryWarningTimer.stop();
+					}
+					// 鍋滄闂儊瀹氭椂鍣�
+					if (warningBlinkTimer != null && warningBlinkTimer.isRunning()) {
+						warningBlinkTimer.stop();
+					}
 				}
 			});
 		}
@@ -259,6 +335,151 @@
 			setsys.updateProperty("viewCenterY", String.format("%.2f", translateY));
 		}
 	}
+	
+	/**
+	 * 鍚姩杈圭晫璀﹀憡妫�鏌ュ畾鏃跺櫒
+	 */
+	private void startBoundaryWarningTimer() {
+		// 杈圭晫妫�鏌ュ畾鏃跺櫒锛氭瘡500ms妫�鏌ヤ竴娆″壊鑽夋満鏄惁鍦ㄨ竟鐣屽唴
+		boundaryWarningTimer = new Timer(500, e -> {
+			checkMowerBoundaryStatus();
+			// 鍚屾椂鏇存柊钃濈墮鍥炬爣鐘舵��
+			updateBluetoothButtonIcon();
+		});
+		boundaryWarningTimer.setInitialDelay(0);
+		boundaryWarningTimer.start();
+		
+		// 闂儊瀹氭椂鍣細姣�1绉掑垏鎹竴娆¤鍛婂浘鏍囨樉绀虹姸鎬�
+		warningBlinkTimer = new Timer(1000, e -> {
+			if (isMowerOutsideBoundary) {
+				warningIconVisible = !warningIconVisible;
+				if (visualizationPanel != null) {
+					visualizationPanel.repaint();
+				}
+			}
+		});
+		warningBlinkTimer.setInitialDelay(0);
+		warningBlinkTimer.start();
+	}
+	
+	/**
+	 * 鍒囨崲浠ュ壊鑽夋満涓轰腑蹇冪殑妯″紡
+	 */
+	private void toggleCenterOnMowerMode() {
+		centerOnMowerMode = !centerOnMowerMode;
+		
+		if (centerOnMowerMode) {
+			// 寮�鍚ā寮忥細绔嬪嵆灏嗚鍥句腑蹇冪Щ鍔ㄥ埌鍓茶崏鏈轰綅缃�
+			updateViewToCenterOnMower();
+		}
+		// 鍏抽棴妯″紡鏃朵笉闇�瑕佸仛浠讳綍鎿嶄綔锛岀敤鎴峰凡缁忓彲浠ヨ嚜鐢辩Щ鍔ㄥ湴鍥�
+		
+		// 鏇存柊鍥炬爣鏄剧ず锛堥噸缁樹互鍒囨崲鍥炬爣锛�
+		if (visualizationPanel != null) {
+			visualizationPanel.repaint();
+		}
+	}
+	
+	/**
+	 * 鏇存柊瑙嗗浘涓績鍒板壊鑽夋満浣嶇疆
+	 */
+	private void updateViewToCenterOnMower() {
+		if (mapRenderer == null) {
+			return;
+		}
+		
+		Gecaoji mower = mapRenderer.getMower();
+		if (mower != null && mower.hasValidPosition()) {
+			Point2D.Double mowerPosition = mower.getPosition();
+			if (mowerPosition != null) {
+				// 鑾峰彇褰撳墠缂╂斁姣斾緥
+				double currentScale = mapRenderer.getScale();
+				// 璁剧疆瑙嗗浘鍙樻崲锛屼娇鍓茶崏鏈轰綅缃搴斿埌灞忓箷涓績
+				// translateX = -mowerX, translateY = -mowerY 鍙互璁╁壊鑽夋満鍦ㄥ睆骞曚腑蹇�
+				mapRenderer.setViewTransform(currentScale, -mowerPosition.x, -mowerPosition.y);
+			}
+		}
+	}
+	
+	/**
+	 * 妫�鏌ュ壊鑽夋満杈圭晫鐘舵��
+	 */
+	private void checkMowerBoundaryStatus() {
+		// 濡傛灉澶勪簬浠ュ壊鑽夋満涓轰腑蹇冪殑妯″紡锛屽疄鏃舵洿鏂拌鍥句腑蹇�
+		if (centerOnMowerMode) {
+			updateViewToCenterOnMower();
+		}
+		
+		// 妫�鏌ユ槸鍚﹀湪浣滀笟涓�
+		if (statusLabel == null || !"浣滀笟涓�".equals(statusLabel.getText())) {
+			// 涓嶅湪浣滀笟涓紝閲嶇疆鐘舵��
+			if (isMowerOutsideBoundary) {
+				isMowerOutsideBoundary = false;
+				warningIconVisible = true;
+				if (visualizationPanel != null) {
+					visualizationPanel.repaint();
+				}
+			}
+			return;
+		}
+		
+		// 鍦ㄤ綔涓氫腑锛屾鏌ユ槸鍚﹀湪杈圭晫鍐�
+		if (mapRenderer == null) {
+			return;
+		}
+		
+		// 鑾峰彇褰撳墠杈圭晫
+		List<Point2D.Double> boundary = mapRenderer.getCurrentBoundary();
+		if (boundary == null || boundary.size() < 3) {
+			// 娌℃湁杈圭晫锛岄噸缃姸鎬�
+			if (isMowerOutsideBoundary) {
+				isMowerOutsideBoundary = false;
+				warningIconVisible = true;
+				if (visualizationPanel != null) {
+					visualizationPanel.repaint();
+				}
+			}
+			return;
+		}
+		
+		// 鑾峰彇鍓茶崏鏈轰綅缃�
+		Gecaoji mower = mapRenderer.getMower();
+		if (mower == null || !mower.hasValidPosition()) {
+			// 鏃犳硶鑾峰彇浣嶇疆锛岄噸缃姸鎬�
+			if (isMowerOutsideBoundary) {
+				isMowerOutsideBoundary = false;
+				warningIconVisible = true;
+				if (visualizationPanel != null) {
+					visualizationPanel.repaint();
+				}
+			}
+			return;
+		}
+		
+		Point2D.Double mowerPosition = mower.getPosition();
+		if (mowerPosition == null) {
+			return;
+		}
+		
+		// 浣跨敤 MowerBoundaryChecker 妫�鏌ユ槸鍚﹀湪杈圭晫鍐�
+		boolean isInside = MowerBoundaryChecker.isInsideBoundaryPoints(
+			boundary, 
+			mowerPosition.x, 
+			mowerPosition.y
+		);
+		
+		// 鏇存柊鐘舵��
+		boolean wasOutside = isMowerOutsideBoundary;
+		isMowerOutsideBoundary = !isInside;
+		
+		// 濡傛灉鐘舵�佹敼鍙橈紝绔嬪嵆閲嶇粯
+		if (wasOutside != isMowerOutsideBoundary) {
+			warningIconVisible = true;
+			if (visualizationPanel != null) {
+				visualizationPanel.repaint();
+			}
+		}
+	}
 
 	private void showInitialMowerSelfCheckDialogIfNeeded() {
 		// 宸茬Щ闄よ繘鍏ヤ富椤垫椂鐨勮嚜妫�鎻愮ず锛堟寜鐢ㄦ埛瑕佹眰鍒犻櫎锛�
@@ -285,6 +506,251 @@
 			}
 		}
 		mapRenderer.setIdleTrailDurationSeconds(durationSeconds);
+		
+		// 搴旂敤杈圭晫璺濈鏄剧ず璁剧疆鍜屾祴閲忔ā寮忚缃�
+		Setsys setsys = new Setsys();
+		setsys.initializeFromProperties();
+		mapRenderer.setBoundaryLengthVisible(setsys.isBoundaryLengthVisible());
+		// 鍒濆鍖栨祴閲忔ā寮�
+		boolean measurementEnabled = setsys.isMeasurementModeEnabled();
+		mapRenderer.setMeasurementMode(measurementEnabled);
+		if (measurementEnabled) {
+			celiangmoshi.start();
+		} else {
+			celiangmoshi.stop();
+		}
+		// 鍒濆鍖栨墜鍔ㄧ粯鍒惰竟鐣屾ā寮�
+		boolean manualBoundaryDrawingEnabled = setsys.isManualBoundaryDrawingMode();
+		if (mapRenderer != null) {
+			mapRenderer.setManualBoundaryDrawingMode(manualBoundaryDrawingEnabled);
+		}
+		// 鏇存柊杩斿洖璁剧疆鎸夐挳鐨勬樉绀虹姸鎬�
+		updateSettingsReturnButtonVisibility();
+	}
+	
+	/**
+	 * 鏇存柊杩斿洖绯荤粺璁剧疆鎸夐挳鐨勬樉绀虹姸鎬�
+	 * 褰撴墜鍔ㄧ粯鍒惰竟鐣屾ā寮忋�佹樉绀鸿竟鐣岃窛绂绘垨寮�鍚祴閲忔ā寮忎换涓�寮�鍚椂鏄剧ず
+	 */
+	public void updateSettingsReturnButtonVisibility() {
+		Setsys setsys = new Setsys();
+		setsys.initializeFromProperties();
+		
+		boolean manualBoundaryDrawingEnabled = setsys.isManualBoundaryDrawingMode();
+		boolean shouldShow = manualBoundaryDrawingEnabled
+			|| setsys.isBoundaryLengthVisible() 
+			|| setsys.isMeasurementModeEnabled();
+		
+		if (shouldShow) {
+			showSettingsReturnButton();
+			// 濡傛灉鎵嬪姩缁樺埗杈圭晫妯″紡寮�鍚紝鏄剧ず淇濆瓨鎸夐挳
+			if (manualBoundaryDrawingEnabled) {
+				showSaveManualBoundaryButton();
+			} else {
+				hideSaveManualBoundaryButton();
+			}
+		} else {
+			hideSettingsReturnButton();
+			hideSaveManualBoundaryButton();
+		}
+	}
+	
+	/**
+	 * 鏄剧ず杩斿洖绯荤粺璁剧疆鎸夐挳
+	 */
+	private void showSettingsReturnButton() {
+		ensureFloatingButtonInfrastructure();
+		if (settingsReturnButton == null) {
+			settingsReturnButton = createFloatingTextButton("杩斿洖");
+			settingsReturnButton.setToolTipText("杩斿洖绯荤粺璁剧疆");
+			settingsReturnButton.addActionListener(e -> {
+				// 鍏抽棴鎵�鏈夌浉鍏虫ā寮�
+				Setsys setsys = new Setsys();
+				setsys.initializeFromProperties();
+				
+				boolean modeChanged = false;
+				
+				// 鍏抽棴鎵嬪姩缁樺埗杈圭晫妯″紡
+				if (setsys.isManualBoundaryDrawingMode()) {
+					setsys.setManualBoundaryDrawingMode(false);
+					setsys.updateProperty("manualBoundaryDrawingMode", "false");
+					// 娓呯┖鎵嬪姩缁樺埗鐨勮竟鐣岀偣
+					if (mapRenderer != null) {
+						mapRenderer.clearManualBoundaryPoints();
+					}
+					modeChanged = true;
+				}
+				
+				// 鍏抽棴鏄剧ず杈圭晫璺濈
+				if (setsys.isBoundaryLengthVisible()) {
+					setsys.setBoundaryLengthVisible(false);
+					setsys.updateProperty("boundaryLengthVisible", "false");
+					if (mapRenderer != null) {
+						mapRenderer.setBoundaryLengthVisible(false);
+					}
+					modeChanged = true;
+				}
+				
+				// 鍏抽棴娴嬮噺妯″紡
+				if (setsys.isMeasurementModeEnabled()) {
+					setsys.setMeasurementModeEnabled(false);
+					setsys.updateProperty("measurementModeEnabled", "false");
+					if (mapRenderer != null) {
+						mapRenderer.setMeasurementMode(false);
+					}
+					celiangmoshi.stop();
+					modeChanged = true;
+				}
+				
+				// 濡傛灉鍏抽棴浜嗕换浣曟ā寮忥紝绔嬪嵆闅愯棌杩斿洖鎸夐挳骞跺埛鏂扮晫闈�
+				if (modeChanged) {
+					// 绔嬪嵆闅愯棌杩斿洖鎸夐挳
+					if (settingsReturnButton != null) {
+						settingsReturnButton.setVisible(false);
+					}
+					// 鏇存柊鎸夐挳鍒楋紙绉婚櫎杩斿洖鎸夐挳锛�
+					rebuildFloatingButtonColumn();
+					// 濡傛灉鎵�鏈夋寜閽兘闅愯棌浜嗭紝闅愯棌鎮诞鎸夐挳闈㈡澘
+					if (floatingButtonPanel != null && floatingButtonColumn != null
+							&& floatingButtonColumn.getComponentCount() == 0) {
+						floatingButtonPanel.setVisible(false);
+					}
+					// 鍒锋柊鐣岄潰
+					if (visualizationPanel != null) {
+						visualizationPanel.revalidate();
+						visualizationPanel.repaint();
+					}
+				}
+				
+				// 鏇存柊杩斿洖鎸夐挳鏄剧ず鐘舵�侊紙纭繚鐘舵�佸悓姝ワ級
+				updateSettingsReturnButtonVisibility();
+				
+				// 鎵撳紑绯荤粺璁剧疆椤甸潰
+				showSettingsDialog();
+			});
+		}
+		settingsReturnButton.setVisible(true);
+		// 闅愯棌缁樺埗鐩稿叧鐨勬寜閽紙鏆傚仠銆佺粨鏉熺粯鍒讹級
+		if (drawingPauseButton != null) {
+			drawingPauseButton.setVisible(false);
+		}
+		if (endDrawingButton != null) {
+			endDrawingButton.setVisible(false);
+		}
+		if (floatingButtonPanel != null) {
+			floatingButtonPanel.setVisible(true);
+			if (floatingButtonPanel.getParent() != visualizationPanel) {
+				visualizationPanel.add(floatingButtonPanel, BorderLayout.SOUTH);
+			}
+		}
+		rebuildFloatingButtonColumn();
+	}
+	
+	/**
+	 * 闅愯棌杩斿洖绯荤粺璁剧疆鎸夐挳
+	 */
+	private void hideSettingsReturnButton() {
+		if (settingsReturnButton != null) {
+			settingsReturnButton.setVisible(false);
+		}
+		rebuildFloatingButtonColumn();
+		if (floatingButtonPanel != null && floatingButtonColumn != null
+				&& floatingButtonColumn.getComponentCount() == 0) {
+			floatingButtonPanel.setVisible(false);
+		}
+	}
+	
+	/**
+	 * 鏄剧ず淇濆瓨鎵嬪姩缁樺埗杈圭晫鎸夐挳
+	 */
+	private void showSaveManualBoundaryButton() {
+		ensureFloatingButtonInfrastructure();
+		if (saveManualBoundaryButton == null) {
+			saveManualBoundaryButton = createFloatingTextButton("淇濆瓨");
+			saveManualBoundaryButton.setToolTipText("淇濆瓨鎵嬪姩缁樺埗鐨勮竟鐣�");
+			saveManualBoundaryButton.addActionListener(e -> saveManualBoundary());
+		}
+		saveManualBoundaryButton.setVisible(true);
+		if (floatingButtonPanel != null) {
+			floatingButtonPanel.setVisible(true);
+			if (floatingButtonPanel.getParent() != visualizationPanel) {
+				visualizationPanel.add(floatingButtonPanel, BorderLayout.SOUTH);
+			}
+		}
+		rebuildFloatingButtonColumn();
+	}
+	
+	/**
+	 * 闅愯棌淇濆瓨鎵嬪姩缁樺埗杈圭晫鎸夐挳
+	 */
+	private void hideSaveManualBoundaryButton() {
+		if (saveManualBoundaryButton != null) {
+			saveManualBoundaryButton.setVisible(false);
+		}
+		rebuildFloatingButtonColumn();
+		if (floatingButtonPanel != null && floatingButtonColumn != null
+				&& floatingButtonColumn.getComponentCount() == 0) {
+			floatingButtonPanel.setVisible(false);
+		}
+	}
+	
+	/**
+	 * 淇濆瓨鎵嬪姩缁樺埗鐨勮竟鐣屽埌鏂囦欢
+	 */
+	private void saveManualBoundary() {
+		if (mapRenderer == null) {
+			JOptionPane.showMessageDialog(this, "鍦板浘娓叉煋鍣ㄦ湭鍒濆鍖�", "閿欒", JOptionPane.ERROR_MESSAGE);
+			return;
+		}
+		
+		List<Point2D.Double> points = mapRenderer.getManualBoundaryPoints();
+		if (points == null || points.isEmpty()) {
+			JOptionPane.showMessageDialog(this, "娌℃湁鍙繚瀛樼殑杈圭晫鐐癸紝璇峰厛鍦ㄥ湴鍥句笂鐐瑰嚮缁樺埗杈圭晫", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+			return;
+		}
+		
+		// 鏋勫缓鍧愭爣瀛楃涓诧細x1,y1;x2,y2;...;xn,yn锛堝崟浣嶏細绫筹紝绮剧‘鍒板皬鏁扮偣鍚�2浣嶏級
+		StringBuilder coordinates = new StringBuilder();
+		for (int i = 0; i < points.size(); i++) {
+			Point2D.Double point = points.get(i);
+			if (i > 0) {
+				coordinates.append(";");
+			}
+			coordinates.append(String.format(Locale.US, "%.2f,%.2f", point.x, point.y));
+		}
+		
+		// 淇濆瓨鍒� properties 鏂囦欢
+		try {
+			java.util.Properties props = new java.util.Properties();
+			java.io.File file = new java.io.File("shoudongbianjie.properties");
+			
+			// 濡傛灉鏂囦欢瀛樺湪锛屽厛鍔犺浇鐜版湁鍐呭
+			if (file.exists()) {
+				try (java.io.FileInputStream input = new java.io.FileInputStream(file)) {
+					props.load(input);
+				}
+			}
+			
+			// 淇濆瓨鍧愭爣
+			props.setProperty("boundaryCoordinates", coordinates.toString());
+			props.setProperty("pointCount", String.valueOf(points.size()));
+			
+			// 鍐欏洖鏂囦欢
+			try (java.io.FileOutputStream output = new java.io.FileOutputStream(file)) {
+				props.store(output, "鎵嬪姩缁樺埗杈圭晫鍧愭爣 - 鏍煎紡: x1,y1;x2,y2;...;xn,yn (鍗曚綅:绫�,绮剧‘鍒板皬鏁扮偣鍚�2浣�)");
+			}
+			
+			JOptionPane.showMessageDialog(this, 
+				String.format("杈圭晫宸蹭繚瀛樻垚鍔燂紒\n鍏� %d 涓偣", points.size()), 
+				"淇濆瓨鎴愬姛", 
+				JOptionPane.INFORMATION_MESSAGE);
+		} catch (Exception ex) {
+			ex.printStackTrace();
+			JOptionPane.showMessageDialog(this, 
+				"淇濆瓨澶辫触: " + ex.getMessage(), 
+				"閿欒", 
+				JOptionPane.ERROR_MESSAGE);
+		}
 	}
 
 	private void createHeaderPanel() {
@@ -331,14 +797,28 @@
 
 		// 娣诲姞閫熷害鏄剧ず鏍囩
 		speedLabel = new JLabel("");
-		speedLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
-		speedLabel.setForeground(Color.GRAY);
-		speedLabel.setVisible(false);  // 榛樿闅愯棌
+	speedLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 12));
+	speedLabel.setForeground(Color.GRAY);
+	speedLabel.setVisible(false);  // 榛樿闅愯棌
+
+	// 姝e湪缁樺埗杈圭晫鐘舵�佹爣绛�
+	drawingBoundaryLabel = new JLabel("姝e湪缁樺埗杈圭晫");
+	drawingBoundaryLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+	drawingBoundaryLabel.setForeground(new Color(46, 139, 87));
+	drawingBoundaryLabel.setVisible(false);  // 榛樿闅愯棌
+
+	// 瀵艰埅棰勮妯″紡鏍囩
+	navigationPreviewLabel = new JLabel("褰撳墠瀵艰埅棰勮妯″紡");
+	navigationPreviewLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+	navigationPreviewLabel.setForeground(new Color(46, 139, 87));
+	navigationPreviewLabel.setVisible(false);  // 榛樿闅愯棌
 
 	// 灏嗙姸鎬佷笌閫熷害鏀惧湪鍚屼竴琛岋紝鏄剧ず鍦ㄥ湴鍧楀悕绉颁笅闈竴琛�
 	JPanel statusRow = new JPanel(new FlowLayout(FlowLayout.LEFT, 8, 0));
 	statusRow.setOpaque(false);
 	statusRow.add(statusLabel);
+	statusRow.add(drawingBoundaryLabel);
+	statusRow.add(navigationPreviewLabel);
 	statusRow.add(speedLabel);
 
 	// 宸﹀榻愭爣绛句笌鐘舵�佽锛岀‘淇濆畠浠湪 BoxLayout 涓潬宸︽樉绀�
@@ -397,16 +877,16 @@
 
 		// 鍙鍖栧尯鍩� - 浣跨敤MapRenderer杩涜缁樺埗
 		visualizationPanel = new JPanel() {
-			private ImageIcon gecaojiIcon = null;
+			private ImageIcon gecaojiIcon1 = null;  // 榛樿鍥炬爣
+			private ImageIcon gecaojiIcon2 = null;  // 浠ュ壊鑽夋満涓轰腑蹇冩ā寮忓浘鏍�
 			private static final int GECAOJI_ICON_X = 37;
 			private static final int GECAOJI_ICON_Y = 10;
 			private static final int GECAOJI_ICON_SIZE = 20;
 			
 			{
 				// 鍔犺浇鍓茶崏鏈哄浘鏍囷紝澶у皬20x20鍍忕礌
-				gecaojiIcon = loadScaledIcon("image/gecaoji.png", GECAOJI_ICON_SIZE, GECAOJI_ICON_SIZE);
-				// 鍚敤宸ュ叿鎻愮ず
-				setToolTipText("");
+				gecaojiIcon1 = loadScaledIcon("image/gecaojishijiao1.png", GECAOJI_ICON_SIZE, GECAOJI_ICON_SIZE);
+				gecaojiIcon2 = loadScaledIcon("image/gecaojishijiao2.png", GECAOJI_ICON_SIZE, GECAOJI_ICON_SIZE);
 			}
 			
 			/**
@@ -423,9 +903,11 @@
 			public String getToolTipText(MouseEvent event) {
 				// 濡傛灉榧犳爣鍦ㄥ壊鑽夋満鍥炬爣鍖哄煙鍐咃紝鏄剧ず鎻愮ず鏂囧瓧
 				if (isMouseOnGecaojiIcon(event.getPoint())) {
-					return "浠ュ壊鑽夋満涓轰腑蹇�";
+					// 鏍规嵁褰撳墠妯″紡鏄剧ず涓嶅悓鐨勬彁绀烘枃瀛�
+					return centerOnMowerMode ? "鍙栨秷浠ュ壊鑽夋満涓轰腑蹇�" : "浠ュ壊鑽夋満涓轰腑蹇�";
 				}
-				return super.getToolTipText(event);
+				// 涓嶅湪鍥炬爣涓婃椂杩斿洖null锛屼笉鏄剧ず宸ュ叿鎻愮ず妗�
+				return null;
 			}
 			
 			@Override
@@ -435,13 +917,52 @@
 				if (mapRenderer != null) {
 					mapRenderer.renderMap(g);
 				}
-				// 鍦ㄥ湴鍥惧乏涓婅缁樺埗鍓茶崏鏈哄浘鏍�
-				// 姘村钩鏂瑰悜涓庨�熷害鎸囩ず鍣ㄥ榻愶紙x=37锛�
-				// 鍨傜洿鏂瑰悜涓庡崼鏄熺姸鎬佸浘鏍囧榻愶紙y=10锛岄�熷害鎸囩ず鍣ㄩ潰鏉块《閮ㄨ竟璺�10鍍忕礌锛屼娇鍥炬爣涓績瀵归綈锛�
-				if (gecaojiIcon != null) {
-					g.drawImage(gecaojiIcon.getImage(), GECAOJI_ICON_X, GECAOJI_ICON_Y, null);
+				
+				// 妫�鏌ユ槸鍚﹂渶瑕佹樉绀鸿鍛婂浘鏍�
+				if (isMowerOutsideBoundary && warningIconVisible) {
+					// 缁樺埗绾㈣壊涓夎褰㈣鍛婂浘鏍囷紙甯﹀徆鍙凤級
+					drawWarningIcon(g, GECAOJI_ICON_X, GECAOJI_ICON_Y, GECAOJI_ICON_SIZE);
+				} else {
+					// 鏍规嵁妯″紡閫夋嫨涓嶅悓鐨勫浘鏍�
+					ImageIcon iconToDraw = centerOnMowerMode ? gecaojiIcon2 : gecaojiIcon1;
+					if (iconToDraw != null) {
+						// 缁樺埗鍓茶崏鏈哄浘鏍�
+						// 姘村钩鏂瑰悜涓庨�熷害鎸囩ず鍣ㄥ榻愶紙x=37锛�
+						// 鍨傜洿鏂瑰悜涓庡崼鏄熺姸鎬佸浘鏍囧榻愶紙y=10锛岄�熷害鎸囩ず鍣ㄩ潰鏉块《閮ㄨ竟璺�10鍍忕礌锛屼娇鍥炬爣涓績瀵归綈锛�
+						g.drawImage(iconToDraw.getImage(), GECAOJI_ICON_X, GECAOJI_ICON_Y, null);
+					}
 				}
 			}
+			
+			/**
+			 * 缁樺埗绾㈣壊涓夎褰㈣鍛婂浘鏍囷紙甯﹀徆鍙凤級
+			 */
+			private void drawWarningIcon(Graphics g, int x, int y, int size) {
+				Graphics2D g2d = (Graphics2D) g.create();
+				g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+				
+				// 缁樺埗绾㈣壊涓夎褰�
+				int[] xPoints = {x + size / 2, x, x + size};
+				int[] yPoints = {y, y + size, y + size};
+				g2d.setColor(Color.RED);
+				g2d.fillPolygon(xPoints, yPoints, 3);
+				
+				// 缁樺埗鐧借壊杈规
+				g2d.setColor(Color.WHITE);
+				g2d.setStroke(new BasicStroke(1.5f));
+				g2d.drawPolygon(xPoints, yPoints, 3);
+				
+				// 缁樺埗鐧借壊鍙瑰彿
+				g2d.setColor(Color.WHITE);
+				g2d.setFont(new Font("Arial", Font.BOLD, size * 3 / 4));
+				FontMetrics fm = g2d.getFontMetrics();
+				String exclamation = "!";
+				int textWidth = fm.stringWidth(exclamation);
+				int textHeight = fm.getAscent();
+				g2d.drawString(exclamation, x + (size - textWidth) / 2, y + (size + textHeight) / 2 - 2);
+				
+				g2d.dispose();
+			}
 		};
 		visualizationPanel.setLayout(new BorderLayout());
 		
@@ -454,20 +975,8 @@
 					// 妫�鏌ユ槸鍚︾偣鍑讳簡鍓茶崏鏈哄浘鏍囧尯鍩燂紙37, 10, 20, 20锛�
 					if (clickPoint.x >= 37 && clickPoint.x <= 57 && 
 					    clickPoint.y >= 10 && clickPoint.y <= 30) {
-						// 鐐瑰嚮浜嗗壊鑽夋満鍥炬爣锛屽皢鍦板浘瑙嗗浘涓績绉诲姩鍒板壊鑽夋満浣嶇疆
-						if (mapRenderer != null) {
-							Gecaoji mower = mapRenderer.getMower();
-							if (mower != null && mower.hasValidPosition()) {
-								Point2D.Double mowerPosition = mower.getPosition();
-								if (mowerPosition != null) {
-									// 鑾峰彇褰撳墠缂╂斁姣斾緥
-									double currentScale = mapRenderer.getScale();
-									// 璁剧疆瑙嗗浘鍙樻崲锛屼娇鍓茶崏鏈轰綅缃搴斿埌灞忓箷涓績
-									// translateX = -mowerX, translateY = -mowerY 鍙互璁╁壊鑽夋満鍦ㄥ睆骞曚腑蹇�
-									mapRenderer.setViewTransform(currentScale, -mowerPosition.x, -mowerPosition.y);
-								}
-							}
-						}
+						// 鍒囨崲浠ュ壊鑽夋満涓轰腑蹇冪殑妯″紡
+						toggleCenterOnMowerMode();
 					}
 				}
 			}
@@ -771,12 +1280,14 @@
 			}
 		});
 		ensureBluetoothIconsLoaded();
-		bluetoothConnected = Bluelink.isConnected();
-		ImageIcon initialIcon = bluetoothConnected ? bluetoothLinkedIcon : bluetoothIcon;
+		// 鏍规嵁涓插彛杩炴帴鐘舵�佹樉绀哄浘鏍�
+		SerialPortService service = sendmessage.getActiveService();
+		boolean serialConnected = (service != null && service.isOpen());
+		ImageIcon initialIcon = serialConnected ? bluetoothLinkedIcon : bluetoothIcon;
 		if (initialIcon != null) {
 			button.setIcon(initialIcon);
 		} else {
-			button.setText(bluetoothConnected ? "宸茶繛" : "钃濈墮");
+			button.setText(serialConnected ? "宸茶繛" : "钃濈墮");
 		}
 		return button;
 	}
@@ -943,7 +1454,7 @@
 			if (parentWindow != null) {
 				// 浣跨敤 yaokong 鍖呬腑鐨� RemoteControlDialog 瀹炵幇
 				remoteDialog = new yaokong.RemoteControlDialog(this, THEME_COLOR, speedLabel);
-			} else {
+			} else {/*  */
 				remoteDialog = new yaokong.RemoteControlDialog((JFrame) null, THEME_COLOR, speedLabel);
 			}
 		}
@@ -1378,7 +1889,11 @@
 	}
 
 	private void handleDrawingStopFromControlPanel() {
-		if (endDrawingCallback != null) {
+		// 濡傛灉鏄線杩旇矾寰勭粯鍒舵ā寮忥紝璋冪敤瀹屾垚缁樺埗鍥炶皟
+		if (returnPathDrawer != null && returnPathDrawer.isActive()) {
+			returnPathDrawer.stop();
+			returnPathDrawer.executeFinishCallback();
+		} else if (endDrawingCallback != null) {
 			endDrawingCallback.run();
 		} else {
 			addzhangaiwu.finishDrawingSession();
@@ -1625,7 +2140,8 @@
 			startBtn.setText(drawingPaused ? "寮�濮嬬粯鍒�" : "鏆傚仠缁樺埗");
 		}
 		if (stopBtn != null) {
-			stopBtn.setText("缁撴潫缁樺埗");
+			// 濡傛灉鏄線杩旇矾寰勭粯鍒舵ā寮忥紝鏄剧ず"瀹屾垚缁樺埗"锛屽惁鍒欐樉绀�"缁撴潫缁樺埗"
+			stopBtn.setText((returnPathDrawer != null && returnPathDrawer.isActive()) ? "瀹屾垚缁樺埗" : "缁撴潫缁樺埗");
 		}
 	}
 
@@ -1676,13 +2192,15 @@
 			return;
 		}
 		ensureBluetoothIconsLoaded();
-		bluetoothConnected = Bluelink.isConnected();
-		ImageIcon icon = bluetoothConnected ? bluetoothLinkedIcon : bluetoothIcon;
+		// 鏍规嵁涓插彛杩炴帴鐘舵�佹樉绀哄浘鏍�
+		SerialPortService service = sendmessage.getActiveService();
+		boolean serialConnected = (service != null && service.isOpen());
+		ImageIcon icon = serialConnected ? bluetoothLinkedIcon : bluetoothIcon;
 		if (icon != null) {
 			bluetoothBtn.setIcon(icon);
 			bluetoothBtn.setText(null);
 		} else {
-			bluetoothBtn.setText(bluetoothConnected ? "宸茶繛" : "钃濈墮");
+			bluetoothBtn.setText(serialConnected ? "宸茶繛" : "钃濈墮");
 		}
 	}
 
@@ -2580,6 +3098,16 @@
 		circleDialogMode = false;
 		hideCircleGuidancePanel();
 		enterDrawingControlMode();
+		
+		// 闅愯棌杩斿洖璁剧疆鎸夐挳锛堝鏋滄樉绀虹粯鍒舵寜閽紝鍒欎笉搴旇鏄剧ず杩斿洖鎸夐挳锛�
+		if (settingsReturnButton != null) {
+			settingsReturnButton.setVisible(false);
+		}
+		
+		// 鏄剧ず"姝e湪缁樺埗杈圭晫"鎻愮ず
+		if (drawingBoundaryLabel != null) {
+			drawingBoundaryLabel.setVisible(true);
+		}
 
 		boolean enableCircleGuidance = drawingShape != null
 				&& "circle".equalsIgnoreCase(drawingShape.trim());
@@ -2689,6 +3217,20 @@
 			floatingButtonColumn.add(pathPreviewReturnButton);
 			added = true;
 		}
+		if (saveManualBoundaryButton != null && saveManualBoundaryButton.isVisible()) {
+			if (added) {
+				floatingButtonColumn.add(Box.createRigidArea(new Dimension(0, 10)));
+			}
+			floatingButtonColumn.add(saveManualBoundaryButton);
+			added = true;
+		}
+		if (settingsReturnButton != null && settingsReturnButton.isVisible()) {
+			if (added) {
+				floatingButtonColumn.add(Box.createRigidArea(new Dimension(0, 10)));
+			}
+			floatingButtonColumn.add(settingsReturnButton);
+			added = true;
+		}
 		floatingButtonColumn.revalidate();
 		floatingButtonColumn.repaint();
 	}
@@ -3055,7 +3597,34 @@
 		if (latest == null) {
 			return false;
 		}
-		return lastCapturedCoordinate == null || latest != lastCapturedCoordinate;
+		
+		// 妫�鏌ユ槸鍚︽湁鏂扮殑鍧愭爣锛堜笌涓婃閲囬泦鐨勪笉鍚岋級
+		if (lastCapturedCoordinate != null && latest == lastCapturedCoordinate) {
+			return false;
+		}
+		
+		// 妫�鏌ュ畾浣嶇姸鎬佹槸鍚︿负4锛堝浐瀹氳В锛�
+		// 褰撻�夋嫨鍓茶崏鏈虹粯鍒跺渾褰㈤殰纰嶇墿鏃讹紝闇�瑕佹鏌ヨ澶囩紪鍙峰拰瀹氫綅鐘舵��
+		Device device = Device.getGecaoji();
+		if (device == null) {
+			return false;
+		}
+		
+		String positioningStatus = device.getPositioningStatus();
+		if (positioningStatus == null || !"4".equals(positioningStatus.trim())) {
+			return false;
+		}
+		
+		// 妫�鏌ヨ澶囩紪鍙锋槸鍚﹀尮閰嶅壊鑽夋満缂栧彿
+		String mowerId = Setsys.getPropertyValue("mowerId");
+		String deviceId = device.getMowerNumber();
+		if (mowerId != null && !mowerId.trim().isEmpty()) {
+			if (deviceId == null || !mowerId.trim().equals(deviceId.trim())) {
+				return false;
+			}
+		}
+		
+		return true;
 	}
 
 	private void applyCirclePrimaryButtonState(boolean enabled) {
@@ -3131,34 +3700,11 @@
 	}
 
 	private double parseDMToDecimal(String dmm, String direction) {
-		if (dmm == null || dmm.trim().isEmpty()) {
-			return Double.NaN;
-		}
-		try {
-			String trimmed = dmm.trim();
-			int dotIndex = trimmed.indexOf('.');
-			if (dotIndex < 2) {
-				return Double.NaN;
-			}
-			int degrees = Integer.parseInt(trimmed.substring(0, dotIndex - 2));
-			double minutes = Double.parseDouble(trimmed.substring(dotIndex - 2));
-			double decimal = degrees + minutes / 60.0;
-			if ("S".equalsIgnoreCase(direction) || "W".equalsIgnoreCase(direction)) {
-				decimal = -decimal;
-			}
-			return decimal;
-		} catch (NumberFormatException ex) {
-			return Double.NaN;
-		}
+		return Gpstoxuzuobiao.parseDMToDecimal(dmm, direction);
 	}
 
 	private double[] convertLatLonToLocal(double lat, double lon, double baseLat, double baseLon) {
-		double deltaLat = lat - baseLat;
-		double deltaLon = lon - baseLon;
-		double meanLatRad = Math.toRadians((baseLat + lat) / 2.0);
-		double eastMeters = deltaLon * METERS_PER_DEGREE_LAT * Math.cos(meanLatRad);
-		double northMeters = deltaLat * METERS_PER_DEGREE_LAT;
-		return new double[]{eastMeters, northMeters};
+		return Gpstoxuzuobiao.convertLatLonToLocal(lat, lon, baseLat, baseLon);
 	}
 
 	private CircleSolution fitCircleFromPoints(List<double[]> points) {
@@ -3257,6 +3803,12 @@
 			activeBoundaryMode = BoundaryCaptureMode.NONE;
 		}
 		endDrawingCallback = null;
+		
+		// 闅愯棌"姝e湪缁樺埗杈圭晫"鎻愮ず
+		if (drawingBoundaryLabel != null) {
+			drawingBoundaryLabel.setVisible(false);
+		}
+		
 		visualizationPanel.revalidate();
 		visualizationPanel.repaint();
 		setHandheldMowerIconActive(false);
@@ -3310,7 +3862,11 @@
 			String obstacles,
 			String plannedPath,
 			Runnable returnAction) {
-		if (mapRenderer == null || !isMeaningfulValue(plannedPath)) {
+		if (mapRenderer == null) {
+			return false;
+		}
+		// 鍏佽娌℃湁璺緞鐨勯瑙堬紙渚嬪闅滅鐗╅瑙堬級锛屽彧瑕佹湁杩斿洖鍥炶皟鍗冲彲
+		if (!isMeaningfulValue(plannedPath) && returnAction == null) {
 			return false;
 		}
 
@@ -3337,10 +3893,17 @@
 
 		mapRenderer.setCurrentBoundary(boundary, landNumber, landName);
 		mapRenderer.setCurrentObstacles(obstacles, landNumber);
-		mapRenderer.setCurrentPlannedPath(plannedPath);
+		// 鍙湁鍦ㄦ湁璺緞鏃舵墠璁剧疆璺緞
+		if (isMeaningfulValue(plannedPath)) {
+			mapRenderer.setCurrentPlannedPath(plannedPath);
+		} else {
+			mapRenderer.setCurrentPlannedPath(null);
+		}
 		mapRenderer.clearHandheldBoundaryPreview();
 		mapRenderer.setBoundaryPointSizeScale(1.0d);
 		mapRenderer.setBoundaryPointsVisible(isMeaningfulValue(boundary));
+		// 鍚敤闅滅鐗╄竟鐣岀偣鏄剧ず
+		mapRenderer.setObstaclePointsVisible(isMeaningfulValue(obstacles));
 
 		String displayName = isMeaningfulValue(landName) ? landName : landNumber;
 		updateCurrentAreaName(displayName);
@@ -3391,6 +3954,101 @@
 		return mapRenderer;
 	}
 
+	/**
+	 * 鑾峰彇鎺у埗闈㈡澘锛堢敤浜庡鑸瑙堟椂鏇挎崲鎸夐挳锛�
+	 * @return 鎺у埗闈㈡澘
+	 */
+	public JPanel getControlPanel() {
+		return controlPanel;
+	}
+
+	/**
+	 * 鑾峰彇寮�濮嬫寜閽紙鐢ㄤ簬瀵艰埅棰勮鏃堕殣钘忥級
+	 * @return 寮�濮嬫寜閽�
+	 */
+	public JButton getStartButton() {
+		return startBtn;
+	}
+
+	/**
+	 * 鑾峰彇缁撴潫鎸夐挳锛堢敤浜庡鑸瑙堟椂闅愯棌锛�
+	 * @return 缁撴潫鎸夐挳
+	 */
+	public JButton getStopButton() {
+		return stopBtn;
+	}
+
+	/**
+	 * 璁剧疆瀵艰埅棰勮妯″紡鏍囩鐨勬樉绀虹姸鎬�
+	 * @param visible 鏄惁鏄剧ず
+	 */
+	public void setNavigationPreviewLabelVisible(boolean visible) {
+		if (navigationPreviewLabel != null) {
+			navigationPreviewLabel.setVisible(visible);
+		}
+	}
+
+	/**
+	 * 鏇存柊瀵艰埅棰勮鐘舵�佹樉绀�
+	 * @param active 鏄惁澶勪簬瀵艰埅棰勮妯″紡
+	 */
+	public void updateNavigationPreviewStatus(boolean active) {
+		setNavigationPreviewLabelVisible(active);
+	}
+
+	/**
+	 * 鏇存柊鍓茶崏杩涘害鏄剧ず
+	 * @param percentage 瀹屾垚鐧惧垎姣�
+	 * @param completedArea 宸插畬鎴愰潰绉紙骞虫柟绫筹級
+	 * @param totalArea 鎬婚潰绉紙骞虫柟绫筹級
+	 */
+	public void updateMowingProgress(double percentage, double completedArea, double totalArea) {
+		if (mowingProgressLabel == null) {
+			return;
+		}
+		if (totalArea <= 0) {
+			mowingProgressLabel.setText("--%");
+			mowingProgressLabel.setToolTipText("鏆傛棤鍦板潡闈㈢Н鏁版嵁");
+			return;
+		}
+		double percent = Math.max(0.0, Math.min(100.0, percentage));
+		mowingProgressLabel.setText(String.format(Locale.US, "%.1f%%", percent));
+		mowingProgressLabel.setToolTipText(String.format(Locale.US, "%.1f銕� / %.1f銕�", completedArea, totalArea));
+	}
+
+	/**
+	 * 鏇存柊鍓茶崏鏈洪�熷害鏄剧ず
+	 * @param speed 閫熷害鍊硷紙鍗曚綅锛歬m/h锛�
+	 */
+	public void updateMowerSpeed(double speed) {
+		if (mowerSpeedValueLabel == null) {
+			return;
+		}
+		if (speed < 0) {
+			mowerSpeedValueLabel.setText("--");
+		} else {
+			mowerSpeedValueLabel.setText(String.format(Locale.US, "%.1f", speed));
+		}
+		if (mowerSpeedUnitLabel != null) {
+			mowerSpeedUnitLabel.setText("km/h");
+		}
+	}
+
+	/**
+	 * 鑾峰彇鍙鍖栭潰鏉垮疄渚�
+	 */
+	public JPanel getVisualizationPanel() {
+		return visualizationPanel;
+	}
+	
+	/**
+	 * 鑾峰彇涓诲唴瀹归潰鏉垮疄渚嬶紙鐢ㄤ簬娣诲姞娴姩鎸夐挳锛�
+	 */
+	public JPanel getMainContentPanel() {
+		return mainContentPanel;
+	}
+
+
 	public void updateCurrentAreaName(String areaName) {
 		if (areaNameLabel == null) {
 			return;
@@ -3488,6 +4146,135 @@
 	}
 
     
+    /**
+     * 鍚姩寰�杩旇矾寰勭粯鍒�
+     * @param finishCallback 瀹屾垚缁樺埗鏃剁殑鍥炶皟
+     * @return 鏄惁鎴愬姛鍚姩
+     */
+    public boolean startReturnPathDrawing(Runnable finishCallback) {
+        if (returnPathDrawer == null) {
+            return false;
+        }
+        return returnPathDrawer.start(finishCallback);
+    }
+    
+    /**
+     * 鍋滄寰�杩旇矾寰勭粯鍒�
+     */
+    public void stopReturnPathDrawing() {
+        if (returnPathDrawer != null) {
+            returnPathDrawer.stop();
+        }
+    }
+    
+    /**
+     * 鑾峰彇寰�杩旇矾寰勭粯鍒剁鐞嗗櫒
+     */
+    public WangfanDraw getReturnPathDrawer() {
+        return returnPathDrawer;
+    }
+    
+    /**
+     * 鍚姩寰�杩旇矾寰勯瑙�
+     * @param coordinatesStr 璺緞鍧愭爣瀛楃涓� (x,y;x,y)
+     * @param returnCallback 杩斿洖鍥炶皟
+     */
+    public void startReturnPathPreview(String coordinatesStr, Runnable returnCallback) {
+        if (returnPathDrawer == null || coordinatesStr == null || coordinatesStr.isEmpty()) {
+            return;
+        }
+        
+        // 瑙f瀽鍧愭爣
+        List<Point2D.Double> points = new ArrayList<>();
+        String[] pairs = coordinatesStr.split(";");
+        for (String pair : pairs) {
+            String[] xy = pair.split(",");
+            if (xy.length == 2) {
+                try {
+                    double x = Double.parseDouble(xy[0]);
+                    double y = Double.parseDouble(xy[1]);
+                    points.add(new Point2D.Double(x, y));
+                } catch (NumberFormatException e) {
+                    // 蹇界暐鏃犳晥鍧愭爣
+                }
+            }
+        }
+        
+        if (points.isEmpty()) {
+            JOptionPane.showMessageDialog(this, "娌℃湁鏈夋晥鐨勮矾寰勭偣鍙瑙�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
+            return;
+        }
+        
+        // 璁剧疆棰勮鐐�
+        returnPathDrawer.setPoints(points);
+        if (mapRenderer != null) {
+            mapRenderer.setPreviewReturnPath(points);
+        }
+        
+        // 寮�鍚瑙堟ā寮�
+        pathPreviewActive = true;
+        if (mapRenderer != null) {
+            mapRenderer.clearIdleTrail();
+        }
+        pathPreviewReturnAction = returnCallback;
+        
+        // 纭繚鎮诞鎸夐挳鍩虹璁炬柦宸插垱寤�
+        ensureFloatingButtonInfrastructure();
+        
+        // 鍒涘缓鎴栨樉绀鸿繑鍥炴寜閽�
+        if (pathPreviewReturnButton == null) {
+            pathPreviewReturnButton = publicway.buttonset.createStyledButton("杩斿洖", null);
+            pathPreviewReturnButton.setToolTipText("杩斿洖缁樺埗椤甸潰");
+            pathPreviewReturnButton.addActionListener(e -> {
+                // 鍋滄棰勮
+                stopReturnPathPreview();
+            });
+        }
+        
+        // 闅愯棌鍏朵粬鎮诞鎸夐挳
+        hideFloatingDrawingControls();
+        
+        // 鏄剧ず杩斿洖鎸夐挳
+        pathPreviewReturnButton.setVisible(true);
+        floatingButtonPanel.setVisible(true);
+        if (floatingButtonPanel.getParent() != visualizationPanel) {
+            visualizationPanel.add(floatingButtonPanel, BorderLayout.SOUTH);
+        }
+        rebuildFloatingButtonColumn();
+        
+        visualizationPanel.revalidate();
+        visualizationPanel.repaint();
+    }
+    
+    /**
+     * 鍋滄寰�杩旇矾寰勯瑙�
+     */
+    private void stopReturnPathPreview() {
+        pathPreviewActive = false;
+        
+        // 娓呯┖棰勮鐐�
+        if (returnPathDrawer != null) {
+            returnPathDrawer.clearPoints();
+        }
+        if (mapRenderer != null) {
+            mapRenderer.setPreviewReturnPath(null);
+        }
+        
+        // 闅愯棌杩斿洖鎸夐挳
+        if (pathPreviewReturnButton != null) {
+            pathPreviewReturnButton.setVisible(false);
+        }
+        
+        // 闅愯棌鎮诞闈㈡澘
+        if (floatingButtonPanel != null) {
+            floatingButtonPanel.setVisible(false);
+        }
+        
+        // 鎵ц杩斿洖鍥炶皟
+        if (pathPreviewReturnAction != null) {
+            pathPreviewReturnAction.run();
+        }
+    }
 
 	// 娴嬭瘯鏂规硶
     public static void main(String[] args) {

--
Gitblit v1.10.0