From cbfd1df513c473dd5550d78740c92fc1677b6e9b Mon Sep 17 00:00:00 2001
From: 826220679@qq.com <826220679@qq.com>
Date: 星期六, 27 十二月 2025 13:40:42 +0800
Subject: [PATCH] 异形有障碍物路径规划没完成
---
src/zhuye/Shouye.java | 84 ++++++++++++++++++++++++++---------------
1 files changed, 53 insertions(+), 31 deletions(-)
diff --git a/src/zhuye/Shouye.java b/src/zhuye/Shouye.java
index 6ec9021..cd33de7 100644
--- a/src/zhuye/Shouye.java
+++ b/src/zhuye/Shouye.java
@@ -31,7 +31,8 @@
import java.util.Map;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.function.Consumer;
+// import java.util.function.Consumer;
+import chuankou.DataListener;
import java.awt.geom.Point2D;
import publicway.Gpstoxuzuobiao;
@@ -110,16 +111,25 @@
private boolean pathPreviewActive;
- private final Consumer<String> serialLineListener = line -> {
- SwingUtilities.invokeLater(() -> {
- updateDataPacketCountLabel();
- // 濡傛灉鏀跺埌$GNGGA鏁版嵁锛岀珛鍗虫洿鏂版嫋灏�
- if (line != null && line.trim().startsWith("$GNGGA")) {
- if (mapRenderer != null && !pathPreviewActive) {
- mapRenderer.forceUpdateIdleMowerTrail();
+ private final DataListener<String> serialLineListener = new DataListener<String>() {
+ @Override
+ public void accept(final String line) {
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ updateDataPacketCountLabel();
+ // 濡傛灉鏀跺埌GGA鏁版嵁锛岀珛鍗虫洿鏂版嫋灏�
+ if (line != null) {
+ String trimmed = line.trim();
+ if (trimmed.startsWith("$GNGGA") || trimmed.startsWith("$GPGGA") || trimmed.startsWith("$GBGGA")) {
+ if (mapRenderer != null && !pathPreviewActive) {
+ mapRenderer.forceUpdateIdleMowerTrail();
+ }
+ }
+ }
}
- }
- });
+ });
+ }
};
private static final int FLOAT_ICON_SIZE = 32;
private JButton endDrawingButton;
@@ -190,6 +200,10 @@
scheduleIdentifierCheck();
}
+ private static boolean isFinite(double d) {
+ return !Double.isNaN(d) && !Double.isInfinite(d);
+ }
+
public static Shouye getInstance() {
return instance;
}
@@ -840,7 +854,7 @@
try {
ImageIcon settingsIcon = new ImageIcon("image/sets.png");
// 璋冩暣鍥剧墖澶у皬浠ラ�傚簲鎸夐挳
- Image scaledImage = settingsIcon.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH);
+ Image scaledImage = settingsIcon.getImage().getScaledInstance(25, 25, Image.SCALE_SMOOTH);
settingsBtn.setIcon(new ImageIcon(scaledImage));
} catch (Exception e) {
// 濡傛灉鍥剧墖鍔犺浇澶辫触锛屼娇鐢ㄩ粯璁ゆ枃鏈�
@@ -1206,15 +1220,15 @@
controlPanel = new JPanel(new BorderLayout());
controlPanel.setBackground(PANEL_BACKGROUND);
controlPanel.setBorder(BorderFactory.createEmptyBorder(15, 20, 15, 20));
- controlPanel.setPreferredSize(new Dimension(0, 100));
+ controlPanel.setPreferredSize(new Dimension(0, 80));
JPanel buttonPanel = new JPanel(new GridLayout(1, 2, 20, 0));
buttonPanel.setBackground(PANEL_BACKGROUND);
- startBtn = createControlButton("鏆傚仠", THEME_COLOR);
+ startBtn = createControlButton("鏆傚仠鍓茶崏", THEME_COLOR);
updateStartButtonAppearance();
- stopBtn = createControlButton("缁撴潫", Color.ORANGE);
+ stopBtn = createControlButton("缁撴潫鍓茶崏", Color.ORANGE);
updateStopButtonIcon();
buttonPanel.add(startBtn);
@@ -1320,7 +1334,8 @@
button.setFont(new Font("寰蒋闆呴粦", Font.BOLD, 16));
button.setBackground(color);
button.setForeground(Color.WHITE);
- button.setBorder(BorderFactory.createEmptyBorder(15, 0, 15, 0));
+ button.setPreferredSize(new Dimension(0, 50));
+ button.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
button.setFocusPainted(false);
// 鎮仠鏁堟灉
@@ -2124,7 +2139,7 @@
updateStartButtonAppearance();
}
if (stopBtn != null) {
- stopBtn.setText("缁撴潫");
+ stopBtn.setText("缁撴潫鍓茶崏");
updateStopButtonIcon();
}
if (statusLabel != null) {
@@ -2167,17 +2182,16 @@
if (startBtn == null) {
return;
}
- String iconPath = startButtonShowingPause ? "image/start0.png" : "image/start1.png";
- startBtn.setText(startButtonShowingPause ? "鏆傚仠" : "寮�濮�");
- applyButtonIcon(startBtn, iconPath);
+ startBtn.setText(startButtonShowingPause ? "鏆傚仠鍓茶崏" : "寮�濮嬪壊鑽�");
+ startBtn.setIcon(null);
}
private void updateStopButtonIcon() {
if (stopBtn == null) {
return;
}
- String iconPath = stopButtonActive ? "image/stop1.png" : "image/stop0.png";
- applyButtonIcon(stopBtn, iconPath);
+ stopBtn.setText("缁撴潫鍓茶崏");
+ stopBtn.setIcon(null);
}
private void toggleBluetoothConnection() {
@@ -2552,7 +2566,7 @@
double lat = parseDMToDecimal(latest.getLatitude(), latest.getLatDirection());
double lon = parseDMToDecimal(latest.getLongitude(), latest.getLonDirection());
- if (!Double.isFinite(lat) || !Double.isFinite(lon)) {
+ if (!isFinite(lat) || !isFinite(lon)) {
discardLatestCoordinate(latest);
lastMowerCoordinate = latest;
return;
@@ -2560,7 +2574,7 @@
double[] local = convertLatLonToLocal(lat, lon, base[0], base[1]);
Point2D.Double candidate = new Point2D.Double(local[0], local[1]);
- if (!Double.isFinite(candidate.x) || !Double.isFinite(candidate.y)) {
+ if (!isFinite(candidate.x) || !isFinite(candidate.y)) {
discardLatestCoordinate(latest);
lastMowerCoordinate = latest;
return;
@@ -2658,7 +2672,7 @@
double x = parseMetersValue(device.getRealtimeX());
double y = parseMetersValue(device.getRealtimeY());
- if (!Double.isFinite(x) || !Double.isFinite(y)) {
+ if (!isFinite(x) || !isFinite(y)) {
JOptionPane.showMessageDialog(this, "褰撳墠瀹氫綅鏁版嵁鏃犳晥锛岃绋嶅悗鍐嶈瘯銆�", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
return -1;
}
@@ -2736,7 +2750,7 @@
}
double x = parseMetersValue(device.getRealtimeX());
double y = parseMetersValue(device.getRealtimeY());
- if (!Double.isFinite(x) || !Double.isFinite(y)) {
+ if (!isFinite(x) || !isFinite(y)) {
return false;
}
return isDuplicateHandheldPoint(x, y);
@@ -2749,7 +2763,7 @@
}
double x = parseMetersValue(device.getRealtimeX());
double y = parseMetersValue(device.getRealtimeY());
- return Double.isFinite(x) && Double.isFinite(y);
+ return isFinite(x) && isFinite(y);
}
private boolean isDuplicateHandheldPoint(double x, double y) {
@@ -2992,10 +3006,10 @@
private void ensureBluetoothIconsLoaded() {
if (bluetoothIcon == null) {
- bluetoothIcon = loadScaledIcon("image/blue.png", 28, 28);
+ bluetoothIcon = loadScaledIcon("image/blue.png", 25, 25);
}
if (bluetoothLinkedIcon == null) {
- bluetoothLinkedIcon = loadScaledIcon("image/bluelink.png", 28, 28);
+ bluetoothLinkedIcon = loadScaledIcon("image/bluelink.png", 25, 25);
}
}
@@ -3557,7 +3571,7 @@
double lat = parseDMToDecimal(latest.getLatitude(), latest.getLatDirection());
double lon = parseDMToDecimal(latest.getLongitude(), latest.getLonDirection());
- if (!Double.isFinite(lat) || !Double.isFinite(lon)) {
+ if (!isFinite(lat) || !isFinite(lon)) {
JOptionPane.showMessageDialog(this, "閲囬泦鐐瑰潗鏍囨棤鏁堬紝璇烽噸鏂伴噰闆嗐��", "鎻愮ず", JOptionPane.WARNING_MESSAGE);
return false;
}
@@ -3714,7 +3728,7 @@
}
double baseLat = parseDMToDecimal(parts[0], parts[1]);
double baseLon = parseDMToDecimal(parts[2], parts[3]);
- if (!Double.isFinite(baseLat) || !Double.isFinite(baseLon)) {
+ if (!isFinite(baseLat) || !isFinite(baseLon)) {
return null;
}
return new double[]{baseLat, baseLon};
@@ -3780,7 +3794,7 @@
double centerX = (x1Sq * (y2 - y3) + x2Sq * (y3 - y1) + x3Sq * (y1 - y2)) / d;
double centerY = (x1Sq * (x3 - x2) + x2Sq * (x1 - x3) + x3Sq * (x2 - x1)) / d;
double radius = Math.hypot(centerX - x1, centerY - y1);
- if (!Double.isFinite(centerX) || !Double.isFinite(centerY) || !Double.isFinite(radius)) {
+ if (!isFinite(centerX) || !isFinite(centerY) || !isFinite(radius)) {
return null;
}
if (radius < 0.05) {
@@ -3929,6 +3943,14 @@
updateCurrentAreaName(displayName);
showPathPreviewReturnControls();
+
+ // 鑷姩灏嗚鍥句腑蹇冨鍑嗗湴鍧楀嚑浣曚腑蹇�
+ if (mapRenderer != null) {
+ SwingUtilities.invokeLater(() -> {
+ mapRenderer.centerViewOnBoundary();
+ });
+ }
+
visualizationPanel.revalidate();
visualizationPanel.repaint();
return true;
--
Gitblit v1.10.0