From 6c9349bd065a99bf2066b6ae3f09691270720c9b Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期一, 22 十二月 2025 13:48:27 +0800
Subject: [PATCH] 解决了手动绘制边界的bug,所有返回按钮采用公用方法创建

---
 src/zhuye/Shouye.java |  694 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 651 insertions(+), 43 deletions(-)

diff --git a/src/zhuye/Shouye.java b/src/zhuye/Shouye.java
index e76f5c7..27a166d 100644
--- a/src/zhuye/Shouye.java
+++ b/src/zhuye/Shouye.java
@@ -19,23 +19,24 @@
 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;
+import publicway.Fanhuibutton;
+
 /**
  * 棣栭〉鐣岄潰 - 閫傞厤6.5瀵哥珫灞忥紝浣跨敤鐙珛鐨凪apRenderer杩涜缁樺埗
  */
@@ -80,6 +81,8 @@
 	private JLabel statusLabel;
 	private JLabel speedLabel;  // 閫熷害鏄剧ず鏍囩
 	private JLabel areaNameLabel;
+	private JLabel drawingBoundaryLabel;  // 姝e湪缁樺埗杈圭晫鐘舵�佹爣绛�
+	private JLabel navigationPreviewLabel;  // 瀵艰埅棰勮妯″紡鏍囩
 	
 	// 杈圭晫璀﹀憡鐩稿叧
 	private Timer boundaryWarningTimer;  // 杈圭晫璀﹀憡妫�鏌ュ畾鏃跺櫒
@@ -105,12 +108,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();
 				}
 			}
@@ -123,8 +128,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;
@@ -166,6 +172,7 @@
 	private boolean storedStopButtonActive;
 	private String storedStatusBeforeDrawing;
 	private boolean handheldCaptureInlineUiActive;
+	private WangfanDraw returnPathDrawer;  // 寰�杩旇矾寰勭粯鍒剁鐞嗗櫒
 	private Timer handheldCaptureStatusTimer;
 	private String handheldCaptureStoredStatusText;
 	private Color handheldStartButtonOriginalBackground;
@@ -205,6 +212,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;
@@ -452,6 +507,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 = Fanhuibutton.createReturnButton(null);
+			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() {
@@ -498,14 +798,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 涓潬宸︽樉绀�
@@ -1098,6 +1412,8 @@
 		remoteBtn.addActionListener(e -> showRemoteControlDialog());
 		areaSelectBtn.addActionListener(e -> {
 			// 鐐瑰嚮鈥滃湴鍧椻�濈洿鎺ユ墦寮�鍦板潡绠$悊瀵硅瘽妗嗭紙鑻ラ渶瑕佸彲浼犲叆鐗瑰畾鍦板潡缂栧彿锛�
+//			Dikuaiguanli.showDikuaiManagement(this, null);
+			// 鐩存帴杩涘叆鍦板潡绠$悊鐣岄潰
 			Dikuaiguanli.showDikuaiManagement(this, null);
 		});
 		baseStationBtn.addActionListener(e -> showBaseStationDialog());
@@ -1141,7 +1457,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);
 			}
 		}
@@ -1576,7 +1892,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();
@@ -1808,7 +2128,12 @@
 			updateStopButtonIcon();
 		}
 		if (statusLabel != null) {
-			statusLabel.setText(storedStatusBeforeDrawing != null ? storedStatusBeforeDrawing : "寰呮満");
+			// 濡傛灉鏄線杩旇矾寰勭粯鍒讹紝閫�鍑烘椂鎭㈠涓�"寰呮満"
+			if (returnPathDrawer != null && returnPathDrawer.isActive()) {
+				statusLabel.setText("寰呮満");
+			} else {
+				statusLabel.setText(storedStatusBeforeDrawing != null ? storedStatusBeforeDrawing : "寰呮満");
+			}
 		}
 		storedStatusBeforeDrawing = null;
 	}
@@ -1823,7 +2148,8 @@
 			startBtn.setText(drawingPaused ? "寮�濮嬬粯鍒�" : "鏆傚仠缁樺埗");
 		}
 		if (stopBtn != null) {
-			stopBtn.setText("缁撴潫缁樺埗");
+			// 濡傛灉鏄線杩旇矾寰勭粯鍒舵ā寮忥紝鏄剧ず"瀹屾垚缁樺埗"锛屽惁鍒欐樉绀�"缁撴潫缁樺埗"
+			stopBtn.setText((returnPathDrawer != null && returnPathDrawer.isActive()) ? "瀹屾垚缁樺埗" : "缁撴潫缁樺埗");
 		}
 	}
 
@@ -2119,6 +2445,12 @@
 		mapRenderer.setHandheldMowerIconActive(active);
 	}
 
+	public void setStatusLabelText(String text) {
+		if (statusLabel != null) {
+			statusLabel.setText(text);
+		}
+	}
+
 	public boolean startMowerBoundaryCapture() {
 		if (mapRenderer == null) {
 			return false;
@@ -2762,7 +3094,11 @@
 		if (drawingControlModeActive) {
 			updateDrawingControlButtonLabels();
 			if (statusLabel != null) {
-				statusLabel.setText(paused ? "缁樺埗鏆傚仠" : "缁樺埗涓�");
+				if (returnPathDrawer != null && returnPathDrawer.isActive()) {
+					statusLabel.setText("姝e湪缁樺埗寰�杩旇矾寰�");
+				} else {
+					statusLabel.setText(paused ? "缁樺埗鏆傚仠" : "缁樺埗涓�");
+				}
 			}
 		}
 	}
@@ -2780,6 +3116,19 @@
 		circleDialogMode = false;
 		hideCircleGuidancePanel();
 		enterDrawingControlMode();
+		
+		// 闅愯棌杩斿洖璁剧疆鎸夐挳锛堝鏋滄樉绀虹粯鍒舵寜閽紝鍒欎笉搴旇鏄剧ず杩斿洖鎸夐挳锛�
+//		if (settingsReturnButton != null) {
+//			settingsReturnButton.setVisible(false);
+//		}
+		
+		// 鏄剧ず"姝e湪缁樺埗杈圭晫"鎻愮ず
+		if (drawingBoundaryLabel != null) {
+			// 濡傛灉鏄線杩旇矾寰勭粯鍒讹紝涓嶆樉绀烘鏍囩锛堢姸鎬佹爮宸叉樉绀�"姝e湪缁樺埗寰�杩旇矾寰�"锛�
+//			boolean isReturnPathDrawing = returnPathDrawer != null && returnPathDrawer.isActive();
+//			drawingBoundaryLabel.setVisible(!isReturnPathDrawing);
+			drawingBoundaryLabel.setVisible(true);
+		}
 
 		boolean enableCircleGuidance = drawingShape != null
 				&& "circle".equalsIgnoreCase(drawingShape.trim());
@@ -2889,6 +3238,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();
 	}
@@ -3255,7 +3618,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) {
@@ -3331,34 +3721,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) {
@@ -3457,6 +3824,12 @@
 			activeBoundaryMode = BoundaryCaptureMode.NONE;
 		}
 		endDrawingCallback = null;
+		
+		// 闅愯棌"姝e湪缁樺埗杈圭晫"鎻愮ず
+		if (drawingBoundaryLabel != null) {
+			drawingBoundaryLabel.setVisible(false);
+		}
+		
 		visualizationPanel.revalidate();
 		visualizationPanel.repaint();
 		setHandheldMowerIconActive(false);
@@ -3471,9 +3844,8 @@
 			endDrawingButton.setVisible(false);
 		}
 		if (pathPreviewReturnButton == null) {
-			pathPreviewReturnButton = createFloatingTextButton("杩斿洖");
+			pathPreviewReturnButton = Fanhuibutton.createReturnButton(e -> handlePathPreviewReturn());
 			pathPreviewReturnButton.setToolTipText("杩斿洖鏂板鍦板潡姝ラ");
-			pathPreviewReturnButton.addActionListener(e -> handlePathPreviewReturn());
 		}
 		pathPreviewReturnButton.setVisible(true);
 		if (floatingButtonPanel != null) {
@@ -3510,7 +3882,11 @@
 			String obstacles,
 			String plannedPath,
 			Runnable returnAction) {
-		if (mapRenderer == null || !isMeaningfulValue(plannedPath)) {
+		if (mapRenderer == null) {
+			return false;
+		}
+		// 鍏佽娌℃湁璺緞鐨勯瑙堬紙渚嬪闅滅鐗╅瑙堬級锛屽彧瑕佹湁杩斿洖鍥炶皟鍗冲彲
+		if (!isMeaningfulValue(plannedPath) && returnAction == null) {
 			return false;
 		}
 
@@ -3537,10 +3913,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);
@@ -3591,6 +3974,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;
@@ -3688,6 +4166,136 @@
 	}
 
     
+    /**
+     * 鍚姩寰�杩旇矾寰勭粯鍒�
+     * @param finishCallback 瀹屾垚缁樺埗鏃剁殑鍥炶皟
+     * @param isHandheld 鏄惁浣跨敤鎵嬫寔璁惧妯″紡
+     * @return 鏄惁鎴愬姛鍚姩
+     */
+    public boolean startReturnPathDrawing(Runnable finishCallback, boolean isHandheld) {
+        if (returnPathDrawer == null) {
+            return false;
+        }
+        return returnPathDrawer.start(finishCallback, isHandheld);
+    }
+    
+    /**
+     * 鍋滄寰�杩旇矾寰勭粯鍒�
+     */
+    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) {
+            // 浣跨敤 Fanhuibutton 鍒涘缓杩斿洖鎸夐挳
+            pathPreviewReturnButton = publicway.Fanhuibutton.createReturnButton(e -> {
+                // 鍋滄棰勮
+                stopReturnPathPreview();
+            });
+            pathPreviewReturnButton.setToolTipText("杩斿洖缁樺埗椤甸潰");
+        }
+        
+        // 闅愯棌鍏朵粬鎮诞鎸夐挳
+        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