From dc9dce0555beb85d1262893fd5d56747d6a83855 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期五, 19 十二月 2025 11:48:37 +0800
Subject: [PATCH] 新增了导航预览功能
---
src/zhuye/Shouye.java | 183 ++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 162 insertions(+), 21 deletions(-)
diff --git a/src/zhuye/Shouye.java b/src/zhuye/Shouye.java
index 7c20720..b588d83 100644
--- a/src/zhuye/Shouye.java
+++ b/src/zhuye/Shouye.java
@@ -11,6 +11,8 @@
import java.awt.event.*;
import chuankou.dellmessage;
+import chuankou.sendmessage;
+import chuankou.SerialPortService;
import dikuai.Dikuai;
import dikuai.Dikuaiguanli;
import dikuai.addzhangaiwu;
@@ -78,6 +80,8 @@
private JLabel statusLabel;
private JLabel speedLabel; // 閫熷害鏄剧ず鏍囩
private JLabel areaNameLabel;
+ private JLabel drawingBoundaryLabel; // 姝e湪缁樺埗杈圭晫鐘舵�佹爣绛�
+ private JLabel navigationPreviewLabel; // 瀵艰埅棰勮妯″紡鏍囩
// 杈圭晫璀﹀憡鐩稿叧
private Timer boundaryWarningTimer; // 杈圭晫璀﹀憡妫�鏌ュ畾鏃跺櫒
@@ -287,6 +291,8 @@
// 杈圭晫妫�鏌ュ畾鏃跺櫒锛氭瘡500ms妫�鏌ヤ竴娆″壊鑽夋満鏄惁鍦ㄨ竟鐣屽唴
boundaryWarningTimer = new Timer(500, e -> {
checkMowerBoundaryStatus();
+ // 鍚屾椂鏇存柊钃濈墮鍥炬爣鐘舵��
+ updateBluetoothButtonIcon();
});
boundaryWarningTimer.setInitialDelay(0);
boundaryWarningTimer.start();
@@ -316,7 +322,7 @@
}
// 鍏抽棴妯″紡鏃朵笉闇�瑕佸仛浠讳綍鎿嶄綔锛岀敤鎴峰凡缁忓彲浠ヨ嚜鐢辩Щ鍔ㄥ湴鍥�
- // 鏇存柊宸ュ叿鎻愮ず
+ // 鏇存柊鍥炬爣鏄剧ず锛堥噸缁樹互鍒囨崲鍥炬爣锛�
if (visualizationPanel != null) {
visualizationPanel.repaint();
}
@@ -448,6 +454,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() {
@@ -494,14 +513,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 涓潬宸︽樉绀�
@@ -560,14 +593,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);
+ gecaojiIcon1 = loadScaledIcon("image/gecaojishijiao1.png", GECAOJI_ICON_SIZE, GECAOJI_ICON_SIZE);
+ gecaojiIcon2 = loadScaledIcon("image/gecaojishijiao2.png", GECAOJI_ICON_SIZE, GECAOJI_ICON_SIZE);
}
/**
@@ -603,11 +638,15 @@
if (isMowerOutsideBoundary && warningIconVisible) {
// 缁樺埗绾㈣壊涓夎褰㈣鍛婂浘鏍囷紙甯﹀徆鍙凤級
drawWarningIcon(g, GECAOJI_ICON_X, GECAOJI_ICON_Y, GECAOJI_ICON_SIZE);
- } else if (gecaojiIcon != null) {
- // 缁樺埗姝e父鐨勫壊鑽夋満鍥炬爣
- // 姘村钩鏂瑰悜涓庨�熷害鎸囩ず鍣ㄥ榻愶紙x=37锛�
- // 鍨傜洿鏂瑰悜涓庡崼鏄熺姸鎬佸浘鏍囧榻愶紙y=10锛岄�熷害鎸囩ず鍣ㄩ潰鏉块《閮ㄨ竟璺�10鍍忕礌锛屼娇鍥炬爣涓績瀵归綈锛�
- g.drawImage(gecaojiIcon.getImage(), GECAOJI_ICON_X, GECAOJI_ICON_Y, null);
+ } 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);
+ }
}
}
@@ -957,12 +996,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;
}
@@ -1129,7 +1170,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);
}
}
@@ -1862,13 +1903,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 ? "宸茶繛" : "钃濈墮");
}
}
@@ -2766,6 +2809,11 @@
circleDialogMode = false;
hideCircleGuidancePanel();
enterDrawingControlMode();
+
+ // 鏄剧ず"姝e湪缁樺埗杈圭晫"鎻愮ず
+ if (drawingBoundaryLabel != null) {
+ drawingBoundaryLabel.setVisible(true);
+ }
boolean enableCircleGuidance = drawingShape != null
&& "circle".equalsIgnoreCase(drawingShape.trim());
@@ -3241,7 +3289,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) {
@@ -3443,6 +3518,12 @@
activeBoundaryMode = BoundaryCaptureMode.NONE;
}
endDrawingCallback = null;
+
+ // 闅愯棌"姝e湪缁樺埗杈圭晫"鎻愮ず
+ if (drawingBoundaryLabel != null) {
+ drawingBoundaryLabel.setVisible(false);
+ }
+
visualizationPanel.revalidate();
visualizationPanel.repaint();
setHandheldMowerIconActive(false);
@@ -3496,7 +3577,11 @@
String obstacles,
String plannedPath,
Runnable returnAction) {
- if (mapRenderer == null || !isMeaningfulValue(plannedPath)) {
+ if (mapRenderer == null) {
+ return false;
+ }
+ // 鍏佽娌℃湁璺緞鐨勯瑙堬紙渚嬪闅滅鐗╅瑙堬級锛屽彧瑕佹湁杩斿洖鍥炶皟鍗冲彲
+ if (!isMeaningfulValue(plannedPath) && returnAction == null) {
return false;
}
@@ -3523,10 +3608,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);
@@ -3577,6 +3669,55 @@
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);
+ }
+ }
+
+ /**
+ * 鑾峰彇鍙鍖栭潰鏉垮疄渚�
+ */
+ public JPanel getVisualizationPanel() {
+ return visualizationPanel;
+ }
+
+ /**
+ * 鑾峰彇涓诲唴瀹归潰鏉垮疄渚嬶紙鐢ㄤ簬娣诲姞娴姩鎸夐挳锛�
+ */
+ public JPanel getMainContentPanel() {
+ return mainContentPanel;
+ }
+
+
public void updateCurrentAreaName(String areaName) {
if (areaNameLabel == null) {
return;
--
Gitblit v1.10.0