From 8d68e8c24e5d7f7f363041ebfe6c2b4c26068fef Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期五, 12 十二月 2025 17:23:12 +0800
Subject: [PATCH] 新增了点击开始判断割草机是否在边界内的判断

---
 src/zhuye/MapRenderer.java |   16 ++++++++
 set.properties             |    2 
 src/zhuye/Shouye.java      |   93 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 110 insertions(+), 1 deletions(-)

diff --git a/set.properties b/set.properties
index 04c1619..c823fc5 100644
--- a/set.properties
+++ b/set.properties
@@ -1,5 +1,5 @@
 #Current work land selection updated
-#Fri Dec 12 17:06:21 CST 2025
+#Fri Dec 12 17:21:33 CST 2025
 appVersion=-1
 currentWorkLandNumber=LAND1
 cuttingWidth=200
diff --git a/src/zhuye/MapRenderer.java b/src/zhuye/MapRenderer.java
index c2c3392..635a1b1 100644
--- a/src/zhuye/MapRenderer.java
+++ b/src/zhuye/MapRenderer.java
@@ -2081,4 +2081,20 @@
         mowerInfoManager.dispose();
     }
 
+    /**
+     * 鑾峰彇褰撳墠杈圭晫鐐瑰垪琛�
+     * @return 褰撳墠杈圭晫鐐瑰垪琛紝濡傛灉娌℃湁杈圭晫鍒欒繑鍥瀗ull
+     */
+    public List<Point2D.Double> getCurrentBoundary() {
+        return currentBoundary;
+    }
+
+    /**
+     * 鑾峰彇鍓茶崏鏈哄疄渚�
+     * @return 鍓茶崏鏈哄疄渚�
+     */
+    public Gecaoji getMower() {
+        return mower;
+    }
+
 }
\ No newline at end of file
diff --git a/src/zhuye/Shouye.java b/src/zhuye/Shouye.java
index 5c2923d..29a287f 100644
--- a/src/zhuye/Shouye.java
+++ b/src/zhuye/Shouye.java
@@ -15,6 +15,8 @@
 import dikuai.Dikuaiguanli;
 import dikuai.addzhangaiwu;
 import gecaoji.Device;
+import gecaoji.Gecaoji;
+import gecaoji.MowerBoundaryChecker;
 import set.Sets;
 import set.debug;
 import udpdell.UDPServer;
@@ -1133,6 +1135,14 @@
 		}
 		startButtonShowingPause = !startButtonShowingPause;
 		if (!startButtonShowingPause) {
+			// 妫�鏌ュ壊鑽夋満鏄惁鍦ㄤ綔涓氬湴鍧楄竟鐣岃寖鍥村唴
+			if (!checkMowerInBoundary()) {
+				startButtonShowingPause = true;
+				statusLabel.setText("寰呮満");
+				updateStartButtonAppearance();
+				return;
+			}
+			
 			statusLabel.setText("浣滀笟涓�");
 			if (stopButtonActive) {
 				stopButtonActive = false;
@@ -1151,6 +1161,89 @@
 		updateStartButtonAppearance();
 	}
 
+	/**
+	 * 妫�鏌ュ壊鑽夋満鏄惁鍦ㄥ綋鍓嶉�変腑鐨勪綔涓氬湴鍧楄竟鐣岃寖鍥村唴
+	 * @return 濡傛灉鍓茶崏鏈哄湪杈圭晫鍐呰繑鍥瀟rue锛屽惁鍒欒繑鍥瀎alse骞舵樉绀烘彁绀�
+	 */
+	private boolean checkMowerInBoundary() {
+		if (mapRenderer == null) {
+			return true; // 濡傛灉娌℃湁鍦板浘娓叉煋鍣紝璺宠繃妫�鏌�
+		}
+
+		// 鑾峰彇褰撳墠杈圭晫
+		List<Point2D.Double> boundary = mapRenderer.getCurrentBoundary();
+		if (boundary == null || boundary.size() < 3) {
+			return true; // 濡傛灉娌℃湁杈圭晫鎴栬竟鐣岀偣涓嶈冻锛岃烦杩囨鏌�
+		}
+
+		// 鑾峰彇鍓茶崏鏈轰綅缃�
+		Gecaoji mower = mapRenderer.getMower();
+		if (mower == null || !mower.hasValidPosition()) {
+			showCustomMessageDialog("鏃犳硶鑾峰彇鍓茶崏鏈轰綅缃紝璇锋鏌ヨ澶囪繛鎺�", "鎻愮ず");
+			return false;
+		}
+
+		Point2D.Double mowerPosition = mower.getPosition();
+		if (mowerPosition == null) {
+			showCustomMessageDialog("鏃犳硶鑾峰彇鍓茶崏鏈轰綅缃紝璇锋鏌ヨ澶囪繛鎺�", "鎻愮ず");
+			return false;
+		}
+
+		// 浣跨敤 MowerBoundaryChecker 妫�鏌ユ槸鍚﹀湪杈圭晫鍐�
+		boolean isInside = MowerBoundaryChecker.isInsideBoundaryPoints(
+			boundary, 
+			mowerPosition.x, 
+			mowerPosition.y
+		);
+
+		if (!isInside) {
+			showCustomMessageDialog("璇峰皢鍓茶崏鏈哄紑鍒颁綔涓氬湴鍧楀唴鐒跺悗鐐瑰嚮寮�濮嬩綔涓�", "鎻愮ず");
+			return false;
+		}
+
+		return true;
+	}
+
+	/**
+	 * 鏄剧ず鑷畾涔夋秷鎭璇濇锛屼娇鐢� buttonset 鍒涘缓纭畾鎸夐挳
+	 * @param message 娑堟伅鍐呭
+	 * @param title 瀵硅瘽妗嗘爣棰�
+	 */
+	private void showCustomMessageDialog(String message, String title) {
+		Window parentWindow = SwingUtilities.getWindowAncestor(this);
+		JDialog dialog = new JDialog(parentWindow, title, Dialog.ModalityType.APPLICATION_MODAL);
+		dialog.setLayout(new BorderLayout(20, 20));
+		dialog.setResizable(false);
+		
+		// 鍐呭闈㈡澘
+		JPanel contentPanel = new JPanel(new BorderLayout(0, 15));
+		contentPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 10, 20));
+		contentPanel.setBackground(Color.WHITE);
+		
+		// 娑堟伅鏍囩
+		JLabel messageLabel = new JLabel("<html><div style='text-align: center;'>" + message + "</div></html>");
+		messageLabel.setFont(new Font("寰蒋闆呴粦", Font.PLAIN, 14));
+		messageLabel.setHorizontalAlignment(SwingConstants.CENTER);
+		contentPanel.add(messageLabel, BorderLayout.CENTER);
+		
+		// 鎸夐挳闈㈡澘
+		JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 0));
+		buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
+		buttonPanel.setOpaque(false);
+		
+		// 浣跨敤 buttonset 鍒涘缓纭畾鎸夐挳
+		JButton okButton = buttonset.createStyledButton("纭畾", THEME_COLOR);
+		okButton.addActionListener(e -> dialog.dispose());
+		buttonPanel.add(okButton);
+		
+		contentPanel.add(buttonPanel, BorderLayout.SOUTH);
+		dialog.add(contentPanel, BorderLayout.CENTER);
+		
+		dialog.pack();
+		dialog.setLocationRelativeTo(this);
+		dialog.setVisible(true);
+	}
+
 	private void handleStopAction() {
 		if (handheldCaptureInlineUiActive) {
 			handleHandheldFinishAction();

--
Gitblit v1.10.0