From c498385fb7e372d13e2ee76d7b54ae2381728082 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期三, 17 十二月 2025 19:35:57 +0800
Subject: [PATCH] 新增了测量模式
---
src/zhuye/Shouye.java | 516 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 482 insertions(+), 34 deletions(-)
diff --git a/src/zhuye/Shouye.java b/src/zhuye/Shouye.java
index b1334a0..30c1444 100644
--- a/src/zhuye/Shouye.java
+++ b/src/zhuye/Shouye.java
@@ -11,11 +11,16 @@
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 set.Sets;
+import set.debug;
import udpdell.UDPServer;
import zhangaiwu.AddDikuai;
import yaokong.Control04;
@@ -75,6 +80,15 @@
private JLabel statusLabel;
private JLabel speedLabel; // 閫熷害鏄剧ず鏍囩
private JLabel areaNameLabel;
+
+ // 杈圭晫璀﹀憡鐩稿叧
+ private Timer boundaryWarningTimer; // 杈圭晫璀﹀憡妫�鏌ュ畾鏃跺櫒
+ private Timer warningBlinkTimer; // 璀﹀憡鍥炬爣闂儊瀹氭椂鍣�
+ private boolean isMowerOutsideBoundary = false; // 鍓茶崏鏈烘槸鍚﹀湪杈圭晫澶�
+ private boolean warningIconVisible = true; // 璀﹀憡鍥炬爣鏄剧ず鐘舵�侊紙鐢ㄤ簬闂儊锛�
+
+ // 浠ュ壊鑽夋満涓轰腑蹇冭鍥炬ā寮�
+ private boolean centerOnMowerMode = false; // 鏄惁澶勪簬浠ュ壊鑽夋満涓轰腑蹇冪殑妯″紡
// 褰撳墠閫変腑鐨勫鑸寜閽�
private JButton currentNavButton;
@@ -88,10 +102,20 @@
private Sets settingsDialog;
private BaseStation baseStation;
- private final Consumer<String> serialLineListener = line -> SwingUtilities.invokeLater(this::updateDataPacketCountLabel);
-
// 鍦板浘娓叉煋鍣�
private MapRenderer mapRenderer;
+
+ private final Consumer<String> serialLineListener = line -> {
+ SwingUtilities.invokeLater(() -> {
+ updateDataPacketCountLabel();
+ // 濡傛灉鏀跺埌$GNGGA鏁版嵁锛岀珛鍗虫洿鏂版嫋灏�
+ if (line != null && line.trim().startsWith("$GNGGA")) {
+ if (mapRenderer != null) {
+ mapRenderer.forceUpdateIdleMowerTrail();
+ }
+ }
+ });
+ };
private static final int FLOAT_ICON_SIZE = 32;
private JButton endDrawingButton;
private JButton drawingPauseButton;
@@ -194,6 +218,9 @@
initializeDefaultAreaSelection();
refreshMapForSelectedArea();
+
+ // 鍚姩杈圭晫璀﹀憡妫�鏌ュ畾鏃跺櫒
+ startBoundaryWarningTimer();
}
private void scheduleIdentifierCheck() {
@@ -205,12 +232,200 @@
SwingUtilities.invokeLater(() -> {
Shouye.this.checkIdentifiersAndPromptIfNeeded();
Shouye.this.showInitialMowerSelfCheckDialogIfNeeded();
+ // 璁剧疆绐楀彛鍏抽棴鐩戝惉鍣紝鍦ㄥ叧闂椂淇濆瓨缂╂斁姣斾緥
+ setupWindowCloseListener();
});
}
}
};
addHierarchyListener(listener);
}
+
+ /**
+ * 璁剧疆绐楀彛鍏抽棴鐩戝惉鍣紝鍦ㄧ獥鍙e叧闂椂淇濆瓨褰撳墠缂╂斁姣斾緥
+ */
+ private void setupWindowCloseListener() {
+ Window window = SwingUtilities.getWindowAncestor(this);
+ if (window != null && window instanceof JFrame) {
+ JFrame frame = (JFrame) window;
+ frame.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ // 淇濆瓨褰撳墠缂╂斁姣斾緥
+ saveCurrentScale();
+ // 鍋滄杈圭晫璀﹀憡瀹氭椂鍣�
+ if (boundaryWarningTimer != null && boundaryWarningTimer.isRunning()) {
+ boundaryWarningTimer.stop();
+ }
+ // 鍋滄闂儊瀹氭椂鍣�
+ if (warningBlinkTimer != null && warningBlinkTimer.isRunning()) {
+ warningBlinkTimer.stop();
+ }
+ }
+ });
+ }
+ }
+
+ /**
+ * 淇濆瓨褰撳墠鍦板浘缂╂斁姣斾緥鍜岃鍥句腑蹇冨潗鏍囧埌閰嶇疆鏂囦欢
+ */
+ public void saveCurrentScale() {
+ if (mapRenderer != null) {
+ double currentScale = mapRenderer.getScale();
+ double translateX = mapRenderer.getTranslateX();
+ double translateY = mapRenderer.getTranslateY();
+ Setsys setsys = new Setsys();
+ // 淇濈暀2浣嶅皬鏁�
+ setsys.updateProperty("mapScale", String.format("%.2f", currentScale));
+ setsys.updateProperty("viewCenterX", String.format("%.2f", translateX));
+ 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() {
// 宸茬Щ闄よ繘鍏ヤ富椤垫椂鐨勮嚜妫�鎻愮ず锛堟寜鐢ㄦ埛瑕佹眰鍒犻櫎锛�
@@ -237,6 +452,19 @@
}
}
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();
+ }
}
private void createHeaderPanel() {
@@ -349,6 +577,39 @@
// 鍙鍖栧尯鍩� - 浣跨敤MapRenderer杩涜缁樺埗
visualizationPanel = new JPanel() {
+ 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鍍忕礌
+ gecaojiIcon1 = loadScaledIcon("image/gecaojishijiao1.png", GECAOJI_ICON_SIZE, GECAOJI_ICON_SIZE);
+ gecaojiIcon2 = loadScaledIcon("image/gecaojishijiao2.png", GECAOJI_ICON_SIZE, GECAOJI_ICON_SIZE);
+ }
+
+ /**
+ * 妫�鏌ラ紶鏍囦綅缃槸鍚﹀湪鍓茶崏鏈哄浘鏍囧尯鍩熷唴
+ */
+ private boolean isMouseOnGecaojiIcon(Point mousePoint) {
+ return mousePoint.x >= GECAOJI_ICON_X &&
+ mousePoint.x <= GECAOJI_ICON_X + GECAOJI_ICON_SIZE &&
+ mousePoint.y >= GECAOJI_ICON_Y &&
+ mousePoint.y <= GECAOJI_ICON_Y + GECAOJI_ICON_SIZE;
+ }
+
+ @Override
+ public String getToolTipText(MouseEvent event) {
+ // 濡傛灉榧犳爣鍦ㄥ壊鑽夋満鍥炬爣鍖哄煙鍐咃紝鏄剧ず鎻愮ず鏂囧瓧
+ if (isMouseOnGecaojiIcon(event.getPoint())) {
+ // 鏍规嵁褰撳墠妯″紡鏄剧ず涓嶅悓鐨勬彁绀烘枃瀛�
+ return centerOnMowerMode ? "鍙栨秷浠ュ壊鑽夋満涓轰腑蹇�" : "浠ュ壊鑽夋満涓轰腑蹇�";
+ }
+ // 涓嶅湪鍥炬爣涓婃椂杩斿洖null锛屼笉鏄剧ず宸ュ叿鎻愮ず妗�
+ return null;
+ }
+
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
@@ -356,14 +617,75 @@
if (mapRenderer != null) {
mapRenderer.renderMap(g);
}
+
+ // 妫�鏌ユ槸鍚﹂渶瑕佹樉绀鸿鍛婂浘鏍�
+ 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());
+
+ // 娣诲姞榧犳爣鐐瑰嚮鐩戝惉鍣紝妫�娴嬫槸鍚︾偣鍑讳簡鍓茶崏鏈哄浘鏍�
+ visualizationPanel.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if (SwingUtilities.isLeftMouseButton(e)) {
+ Point clickPoint = e.getPoint();
+ // 妫�鏌ユ槸鍚︾偣鍑讳簡鍓茶崏鏈哄浘鏍囧尯鍩燂紙37, 10, 20, 20锛�
+ if (clickPoint.x >= 37 && clickPoint.x <= 57 &&
+ clickPoint.y >= 10 && clickPoint.y <= 30) {
+ // 鍒囨崲浠ュ壊鑽夋満涓轰腑蹇冪殑妯″紡
+ toggleCenterOnMowerMode();
+ }
+ }
+ }
+ });
JPanel speedIndicatorPanel = createSpeedIndicatorPanel();
visualizationPanel.add(speedIndicatorPanel, BorderLayout.NORTH);
- // 鍒涘缓鍔熻兘鎸夐挳闈㈡澘锛堟斁鍦ㄥ乏涓婅锛�
+ // 鍒涘缓鍔熻兘鎸夐挳闈㈡澘
JPanel functionButtonsPanel = new JPanel();
functionButtonsPanel.setLayout(new BoxLayout(functionButtonsPanel, BoxLayout.Y_AXIS));
functionButtonsPanel.setOpaque(false);
@@ -658,12 +980,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;
}
@@ -1132,26 +1456,115 @@
}
startButtonShowingPause = !startButtonShowingPause;
if (!startButtonShowingPause) {
- statusLabel.setText("浣滀笟涓�");
- if (stopButtonActive) {
- stopButtonActive = false;
- updateStopButtonIcon();
- }
- if (!beginMowingSession()) {
+ // 妫�鏌ュ壊鑽夋満鏄惁鍦ㄤ綔涓氬湴鍧楄竟鐣岃寖鍥村唴
+ if (!checkMowerInBoundary()) {
startButtonShowingPause = true;
statusLabel.setText("寰呮満");
updateStartButtonAppearance();
return;
}
- Control04.sendStartCommandIfDebugSerialOpen();
+
+ statusLabel.setText("浣滀笟涓�");
+ if (stopButtonActive) {
+ stopButtonActive = false;
+ updateStopButtonIcon();
+ }
+ if (!beginMowingSession()) {
+ startButtonShowingPause = true;
+ statusLabel.setText("寰呮満");
+ updateStartButtonAppearance();
+ return;
+ }
} else {
statusLabel.setText("鏆傚仠涓�");
pauseMowingSession();
- Control04.sendPauseCommandIfDebugSerialOpen();
}
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();
@@ -1167,7 +1580,6 @@
statusLabel.setText("宸茬粨鏉�");
startButtonShowingPause = false;
stopMowingSession();
- Control04.sendStopCommandIfDebugSerialOpen();
} else {
statusLabel.setText("寰呮満");
startButtonShowingPause = true;
@@ -1459,19 +1871,15 @@
if (bluetoothBtn == null) {
return;
}
- if (Bluelink.isConnected()) {
- Bluelink.disconnect();
- bluetoothConnected = false;
- } else {
- boolean success = Bluelink.connect();
- if (success) {
- bluetoothConnected = true;
- } else {
- bluetoothConnected = false;
- JOptionPane.showMessageDialog(this, "钃濈墮杩炴帴澶辫触锛岃閲嶈瘯", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
- }
- }
- updateBluetoothButtonIcon();
+ // 寮瑰嚭绯荤粺璋冭瘯椤甸潰
+ showDebugDialog();
+ }
+
+ private void showDebugDialog() {
+ Window parentWindow = SwingUtilities.getWindowAncestor(this);
+ debug debugDialog = new debug(parentWindow, THEME_COLOR);
+ debugDialog.setLocationRelativeTo(this); // 灞呬腑鏄剧ず鍦ㄩ椤�
+ debugDialog.setVisible(true);
}
private void updateBluetoothButtonIcon() {
@@ -1479,13 +1887,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 ? "宸茶繛" : "钃濈墮");
}
}
@@ -2858,7 +3268,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) {
@@ -3113,7 +3550,11 @@
String obstacles,
String plannedPath,
Runnable returnAction) {
- if (mapRenderer == null || !isMeaningfulValue(plannedPath)) {
+ if (mapRenderer == null) {
+ return false;
+ }
+ // 鍏佽娌℃湁璺緞鐨勯瑙堬紙渚嬪闅滅鐗╅瑙堬級锛屽彧瑕佹湁杩斿洖鍥炶皟鍗冲彲
+ if (!isMeaningfulValue(plannedPath) && returnAction == null) {
return false;
}
@@ -3140,10 +3581,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);
--
Gitblit v1.10.0