From 8d68e8c24e5d7f7f363041ebfe6c2b4c26068fef Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期五, 12 十二月 2025 17:23:12 +0800
Subject: [PATCH] 新增了点击开始判断割草机是否在边界内的判断
---
src/zhuye/Shouye.java | 93 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 93 insertions(+), 0 deletions(-)
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