From 2144172c7b961d4112850692ed77b46f1ae5d373 Mon Sep 17 00:00:00 2001
From: 张世豪 <979909237@qq.com>
Date: 星期五, 05 十二月 2025 19:34:53 +0800
Subject: [PATCH] 20251205
---
src/zhuye/MapRenderer.java | 593 ++++++++++++++++++++---------------------------------------
1 files changed, 202 insertions(+), 391 deletions(-)
diff --git a/src/zhuye/MapRenderer.java b/src/zhuye/MapRenderer.java
index b5665ee..5f5dd06 100644
--- a/src/zhuye/MapRenderer.java
+++ b/src/zhuye/MapRenderer.java
@@ -10,16 +10,19 @@
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.math.BigDecimal;
-import java.text.SimpleDateFormat;
+import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Date;
+import java.util.Deque;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import gecaoji.Device;
import gecaoji.Gecaoji;
+import gecaoji.GecaojiMeg;
+import gecaoji.gecaolunjing;
+import gecaoji.lujingdraw;
import dikuai.Dikuaiguanli;
import dikuai.Dikuai;
import zhangaiwu.Obstacledraw;
@@ -43,15 +46,9 @@
private static final Color GRASS_FILL_COLOR = new Color(144, 238, 144, 120);
private static final Color GRASS_BORDER_COLOR = new Color(60, 179, 113);
private static final Color BOUNDARY_POINT_COLOR = new Color(128, 0, 128);
- private static final Color BOUNDARY_LABEL_COLOR = Color.BLACK;
private static final Color CIRCLE_SAMPLE_COLOR = new Color(220, 20, 60, 230);
private static final double CIRCLE_SAMPLE_SIZE = 0.54d;
private static final double BOUNDARY_POINT_MERGE_THRESHOLD = 0.05;
- private static final SimpleDateFormat TIMESTAMP_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- private static final Color HANDHELD_BOUNDARY_FILL = new Color(51, 153, 255, 60);
- private static final Color HANDHELD_BOUNDARY_BORDER = new Color(51, 102, 204, 220);
- private static final Color HANDHELD_BOUNDARY_POINT = new Color(51, 102, 204);
- private static final Color HANDHELD_BOUNDARY_LABEL = new Color(22, 62, 138);
private static final double BOUNDARY_CONTAINS_TOLERANCE = 0.05;
// 缁勪欢寮曠敤
@@ -71,19 +68,11 @@
private boolean dragInProgress;
private final Gecaoji mower;
private final Timer mowerUpdateTimer;
- private JDialog mowerInfoDialog;
- private Timer mowerInfoRefreshTimer;
- private JLabel mowerNumberValueLabel;
- private JLabel realtimeXValueLabel;
- private JLabel realtimeYValueLabel;
- private JLabel positioningStatusValueLabel;
- private JLabel satelliteCountValueLabel;
- private JLabel realtimeSpeedValueLabel;
- private JLabel headingValueLabel;
- private JLabel updateTimeValueLabel;
+ private final GecaojiMeg mowerInfoManager;
private CircleCaptureOverlay circleCaptureOverlay;
private final List<double[]> circleSampleMarkers = new ArrayList<>();
private final List<Point2D.Double> realtimeMowingTrack = new ArrayList<>();
+ private final Deque<tuowei.TrailSample> idleMowerTrail = new ArrayDeque<>();
private final List<Point2D.Double> handheldBoundaryPreview = new ArrayList<>();
private boolean realtimeTrackRecording;
private String realtimeTrackLandNumber;
@@ -97,14 +86,22 @@
private boolean trackDirty;
private boolean handheldBoundaryPreviewActive;
private boolean pendingTrackBreak = true;
+ private boolean idleTrailSuppressed;
+ private Path2D.Double realtimeBoundaryPathCache;
+ private String realtimeBoundaryPathLand;
- private static final double TRACK_SAMPLE_MIN_DISTANCE_METERS = 0.1d;
+ private static final double TRACK_SAMPLE_MIN_DISTANCE_METERS = 0.2d;
+ private static final double TRACK_DUPLICATE_TOLERANCE_METERS = 1e-3d;
private static final long TRACK_PERSIST_INTERVAL_MS = 5_000L;
+ public static final int DEFAULT_IDLE_TRAIL_DURATION_SECONDS = 60;
+ private static final double IDLE_TRAIL_SAMPLE_DISTANCE_METERS = 0.05d;
+ private long idleTrailDurationMs = DEFAULT_IDLE_TRAIL_DURATION_SECONDS * 1_000L;
public MapRenderer(JPanel visualizationPanel) {
this.visualizationPanel = visualizationPanel;
this.mower = new Gecaoji();
this.mowerUpdateTimer = createMowerTimer();
+ this.mowerInfoManager = new GecaojiMeg(visualizationPanel, mower);
setupMouseListeners();
}
@@ -179,6 +176,7 @@
private Timer createMowerTimer() {
Timer timer = new Timer(300, e -> {
mower.refreshFromDevice();
+ updateIdleMowerTrail();
if (realtimeTrackRecording) {
captureRealtimeTrackPoint();
}
@@ -266,9 +264,7 @@
drawCircleCaptureOverlay(g2d, circleCaptureOverlay, scale);
}
- if (handheldBoundaryPreviewActive) {
- drawHandheldBoundaryPreview(g2d);
- }
+ adddikuaiyulan.drawPreview(g2d, handheldBoundaryPreview, scale, handheldBoundaryPreviewActive);
if (hasPlannedPath) {
drawCurrentPlannedPath(g2d);
@@ -280,11 +276,14 @@
currentBoundary,
scale,
BOUNDARY_POINT_MERGE_THRESHOLD,
- BOUNDARY_POINT_COLOR,
- BOUNDARY_LABEL_COLOR
+ BOUNDARY_POINT_COLOR
);
}
+ if (shouldRenderIdleTrail()) {
+ tuowei.draw(g2d, idleMowerTrail, scale);
+ }
+
if (!realtimeMowingTrack.isEmpty()) {
drawRealtimeMowingCoverage(g2d);
}
@@ -304,7 +303,7 @@
private void drawCoordinateSystem(Graphics2D g2d) {
// 缁樺埗鍘熺偣 - 绾㈣壊瀹炲績灏忓渾鍦�
g2d.setColor(Color.RED);
- g2d.fillOval(-1, -1, 2, 2);
+ g2d.fill(new Ellipse2D.Double(-0.5d, -0.5d, 1d, 1d));
}
@@ -317,121 +316,62 @@
}
private void drawRealtimeMowingCoverage(Graphics2D g2d) {
- if (realtimeMowingTrack.size() < 2) {
+ if (realtimeMowingTrack == null || realtimeMowingTrack.size() < 2) {
return;
}
- Path2D.Double path = new Path2D.Double();
- boolean started = false;
- for (Point2D.Double point : realtimeMowingTrack) {
- if (point == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
- continue;
- }
- if (!started) {
- path.moveTo(point.x, point.y);
- started = true;
- } else {
- path.lineTo(point.x, point.y);
- }
- }
-
- if (!started) {
- return;
- }
-
- Stroke originalStroke = g2d.getStroke();
- Color originalColor = g2d.getColor();
-
+ Path2D.Double boundaryPath = getRealtimeBoundaryPath();
double effectiveWidth = getEffectiveMowerWidthMeters();
- if (effectiveWidth > 0) {
- float coverageWidth = (float) Math.max(effectiveWidth, 0.1d);
- g2d.setStroke(new BasicStroke(coverageWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
- g2d.setColor(new Color(46, 139, 87, 80));
- g2d.draw(path);
- }
-
- float spineWidth = (float) (effectiveWidth > 0 ? Math.max(effectiveWidth / 4.0, 0.18d) : 0.3d);
- g2d.setStroke(new BasicStroke(spineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
- g2d.setColor(new Color(34, 139, 34, 200));
- g2d.draw(path);
-
- g2d.setStroke(originalStroke);
- g2d.setColor(originalColor);
+ gecaolunjing.draw(g2d, realtimeMowingTrack, effectiveWidth, boundaryPath);
}
- private void drawHandheldBoundaryPreview(Graphics2D g2d) {
- if (!handheldBoundaryPreviewActive || handheldBoundaryPreview.isEmpty()) {
- return;
+ private Path2D.Double getRealtimeBoundaryPath() {
+ if (realtimeTrackLandNumber == null) {
+ return null;
}
- Path2D.Double path = new Path2D.Double();
- boolean started = false;
- for (Point2D.Double point : handheldBoundaryPreview) {
- if (point == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
- continue;
+ if (currentBoundaryLandNumber != null && realtimeTrackLandNumber.equals(currentBoundaryLandNumber)) {
+ if (currentBoundaryPath == null) {
+ currentBoundaryPath = buildBoundaryPath(currentBoundary);
}
- if (!started) {
- path.moveTo(point.x, point.y);
- started = true;
- } else {
- path.lineTo(point.x, point.y);
- }
+ return currentBoundaryPath;
}
- if (!started) {
- return;
+ if (realtimeBoundaryPathCache != null && realtimeTrackLandNumber.equals(realtimeBoundaryPathLand)) {
+ return realtimeBoundaryPathCache;
}
- Stroke originalStroke = g2d.getStroke();
- Color originalColor = g2d.getColor();
-
- if (handheldBoundaryPreview.size() >= 3) {
- path.closePath();
- g2d.setColor(HANDHELD_BOUNDARY_FILL);
- g2d.fill(path);
+ Dikuai dikuai = Dikuai.getDikuai(realtimeTrackLandNumber);
+ if (dikuai == null) {
+ realtimeBoundaryPathCache = null;
+ realtimeBoundaryPathLand = null;
+ return null;
}
- float outlineWidth = (float) Math.max(1.5f / scale, 0.2f);
- g2d.setStroke(new BasicStroke(outlineWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
- g2d.setColor(HANDHELD_BOUNDARY_BORDER);
- g2d.draw(path);
-
- double markerSize = Math.max(0.5d, 3.0d / scale);
- double markerRadius = markerSize / 2.0d;
- Font originalFont = g2d.getFont();
- float labelFontSize = (float) Math.max(6.0f, 16.0f / Math.max(scale, 0.2));
- Font labelFont = originalFont.deriveFont(Font.BOLD, labelFontSize);
- FontMetrics metrics = g2d.getFontMetrics(labelFont);
-
- for (Point2D.Double point : handheldBoundaryPreview) {
- if (point == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
- continue;
- }
- Shape marker = new Ellipse2D.Double(point.x - markerRadius, point.y - markerRadius, markerSize, markerSize);
- g2d.setColor(HANDHELD_BOUNDARY_POINT);
- g2d.fill(marker);
+ String normalized = normalizeValue(dikuai.getBoundaryCoordinates());
+ if (normalized == null) {
+ realtimeBoundaryPathCache = null;
+ realtimeBoundaryPathLand = null;
+ return null;
}
- g2d.setFont(labelFont);
- g2d.setColor(HANDHELD_BOUNDARY_LABEL);
- int index = 1;
- for (Point2D.Double point : handheldBoundaryPreview) {
- if (point == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
- index++;
- continue;
- }
- String label = String.valueOf(index++);
- int textWidth = metrics.stringWidth(label);
- int ascent = metrics.getAscent();
- int descent = metrics.getDescent();
- float textX = (float) (point.x - textWidth / 2.0);
- float textY = (float) (point.y + (ascent - descent) / 2.0);
- g2d.drawString(label, textX, textY);
+ List<Point2D.Double> parsed = parseBoundary(normalized);
+ if (parsed.size() < 3) {
+ realtimeBoundaryPathCache = null;
+ realtimeBoundaryPathLand = null;
+ return null;
}
- g2d.setStroke(originalStroke);
- g2d.setFont(originalFont);
- g2d.setColor(originalColor);
+ realtimeBoundaryPathCache = buildBoundaryPath(parsed);
+ realtimeBoundaryPathLand = realtimeTrackLandNumber;
+ return realtimeBoundaryPathCache;
+ }
+
+ private boolean shouldRenderIdleTrail() {
+ return !idleTrailSuppressed
+ && !realtimeTrackRecording
+ && !handheldBoundaryPreviewActive
+ && idleMowerTrail.size() >= 2;
}
private void captureRealtimeTrackPoint() {
@@ -464,29 +404,93 @@
return;
}
+ Point2D.Double candidate = new Point2D.Double(position.x, position.y);
Point2D.Double lastPoint = realtimeMowingTrack.isEmpty() ? null : realtimeMowingTrack.get(realtimeMowingTrack.size() - 1);
- if (pendingTrackBreak) {
- lastPoint = null;
- }
- double distance = 0.0;
+ double distance = Double.NaN;
if (lastPoint != null) {
- double dx = position.x - lastPoint.x;
- double dy = position.y - lastPoint.y;
+ double dx = candidate.x - lastPoint.x;
+ double dy = candidate.y - lastPoint.y;
distance = Math.hypot(dx, dy);
+ if (distance <= TRACK_DUPLICATE_TOLERANCE_METERS) {
+ return;
+ }
if (distance < TRACK_SAMPLE_MIN_DISTANCE_METERS) {
return;
}
}
- realtimeMowingTrack.add(new Point2D.Double(position.x, position.y));
- if (distance > 0.0) {
+ realtimeMowingTrack.add(candidate);
+ if (!pendingTrackBreak && lastPoint != null && Double.isFinite(distance)) {
trackLengthMeters += distance;
}
updateCompletionMetrics();
trackDirty = true;
maybePersistRealtimeTrack(false);
- pendingTrackBreak = false;
+ pendingTrackBreak = false;
+ }
+
+ private void updateIdleMowerTrail() {
+ long now = System.currentTimeMillis();
+ pruneIdleMowerTrail(now);
+
+ if (idleTrailSuppressed || realtimeTrackRecording) {
+ if (!idleMowerTrail.isEmpty()) {
+ clearIdleMowerTrail();
+ }
+ return;
+ }
+
+ Device device = Device.getGecaoji();
+ if (device == null) {
+ return;
+ }
+ if (!isHighPrecisionFix(device.getPositioningStatus())) {
+ return;
+ }
+
+ Point2D.Double position = mower.getPosition();
+ if (position == null || !Double.isFinite(position.x) || !Double.isFinite(position.y)) {
+ return;
+ }
+
+ tuowei.TrailSample lastSample = idleMowerTrail.peekLast();
+ if (lastSample != null) {
+ Point2D.Double lastPoint = lastSample.getPoint();
+ double dx = position.x - lastPoint.x;
+ double dy = position.y - lastPoint.y;
+ if (Math.hypot(dx, dy) < IDLE_TRAIL_SAMPLE_DISTANCE_METERS) {
+ return;
+ }
+ }
+
+ idleMowerTrail.addLast(new tuowei.TrailSample(now, new Point2D.Double(position.x, position.y)));
+ pruneIdleMowerTrail(now);
+ }
+
+ private void pruneIdleMowerTrail(long now) {
+ if (idleMowerTrail.isEmpty()) {
+ return;
+ }
+ long cutoff = now - idleTrailDurationMs;
+ boolean modified = false;
+ while (!idleMowerTrail.isEmpty() && idleMowerTrail.peekFirst().getTimestamp() < cutoff) {
+ idleMowerTrail.removeFirst();
+ modified = true;
+ }
+ if (modified && visualizationPanel != null) {
+ visualizationPanel.repaint();
+ }
+ }
+
+ private void clearIdleMowerTrail() {
+ if (idleMowerTrail.isEmpty()) {
+ return;
+ }
+ idleMowerTrail.clear();
+ if (visualizationPanel != null) {
+ visualizationPanel.repaint();
+ }
}
private void updateCompletionMetrics() {
@@ -601,6 +605,9 @@
mowerEffectiveWidthMeters = defaultMowerWidthMeters;
}
+ idleTrailSuppressed = true;
+ clearIdleMowerTrail();
+
realtimeTrackLandNumber = normalizedLand;
realtimeTrackRecording = true;
pendingTrackBreak = true;
@@ -610,12 +617,14 @@
public void pauseRealtimeTrackRecording() {
realtimeTrackRecording = false;
pendingTrackBreak = true;
+ idleTrailSuppressed = false;
maybePersistRealtimeTrack(true);
}
public void stopRealtimeTrackRecording() {
realtimeTrackRecording = false;
pendingTrackBreak = true;
+ idleTrailSuppressed = false;
maybePersistRealtimeTrack(true);
}
@@ -634,10 +643,31 @@
mowingCompletionRatio = 0.0;
trackDirty = true;
pendingTrackBreak = true;
+ idleTrailSuppressed = false;
maybePersistRealtimeTrack(true);
visualizationPanel.repaint();
}
+ public void setIdleTrailDurationSeconds(int seconds) {
+ int sanitized = seconds;
+ if (sanitized < 5 || sanitized > 600) {
+ sanitized = DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
+ }
+ idleTrailDurationMs = sanitized * 1_000L;
+ pruneIdleMowerTrail(System.currentTimeMillis());
+ }
+
+ public int getIdleTrailDurationSeconds() {
+ long seconds = idleTrailDurationMs / 1_000L;
+ if (seconds <= 0L) {
+ return DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
+ }
+ if (seconds > Integer.MAX_VALUE) {
+ return DEFAULT_IDLE_TRAIL_DURATION_SECONDS;
+ }
+ return (int) seconds;
+ }
+
public double getMowingCompletionRatio() {
if (!isMowerInsideSelectedBoundary()) {
return 0.0;
@@ -682,6 +712,8 @@
trackDirty = false;
lastTrackPersistTimeMillis = 0L;
pendingTrackBreak = true;
+ realtimeBoundaryPathCache = null;
+ realtimeBoundaryPathLand = null;
String trimmed = normalizeValue(trackData);
if (trimmed == null || trimmed.isEmpty()) {
@@ -690,6 +722,7 @@
}
String[] segments = trimmed.split(";");
+ Path2D.Double boundaryPath = getRealtimeBoundaryPath();
Point2D.Double lastPoint = null;
for (String segment : segments) {
if (segment == null || segment.trim().isEmpty()) {
@@ -702,11 +735,26 @@
try {
double x = Double.parseDouble(parts[0].trim());
double y = Double.parseDouble(parts[1].trim());
- Point2D.Double current = new Point2D.Double(x, y);
- realtimeMowingTrack.add(current);
- if (lastPoint != null) {
- trackLengthMeters += Math.hypot(current.x - lastPoint.x, current.y - lastPoint.y);
+ if (!Double.isFinite(x) || !Double.isFinite(y)) {
+ continue;
}
+ Point2D.Double current = new Point2D.Double(x, y);
+ if (boundaryPath != null && !isPointInsideBoundary(current, boundaryPath)) {
+ continue;
+ }
+ if (lastPoint != null) {
+ double dx = current.x - lastPoint.x;
+ double dy = current.y - lastPoint.y;
+ double distance = Math.hypot(dx, dy);
+ if (distance <= TRACK_DUPLICATE_TOLERANCE_METERS) {
+ continue;
+ }
+ if (distance < TRACK_SAMPLE_MIN_DISTANCE_METERS) {
+ continue;
+ }
+ trackLengthMeters += distance;
+ }
+ realtimeMowingTrack.add(current);
lastPoint = current;
} catch (NumberFormatException ignored) {
// 璺宠繃寮傚父鏉$洰
@@ -951,248 +999,9 @@
}
}
- private void showMowerInfo() {
- Device device = Device.getGecaoji();
- if (device == null) {
- JOptionPane.showMessageDialog(
- visualizationPanel,
- "鏃犺澶囨暟鎹�",
- "鍓茶崏鏈轰俊鎭�",
- JOptionPane.INFORMATION_MESSAGE
- );
- return;
- }
-
- ensureMowerInfoDialog();
- updateMowerInfoLabels();
- positionMowerDialog();
- if (!mowerInfoDialog.isVisible()) {
- mowerInfoDialog.setVisible(true);
- } else {
- mowerInfoDialog.toFront();
- }
- startMowerInfoTimer();
- }
-
- private void ensureMowerInfoDialog() {
- if (mowerInfoDialog != null) {
- return;
- }
-
- Window owner = SwingUtilities.getWindowAncestor(visualizationPanel);
- JDialog dialog = new JDialog(owner, "鍓茶崏鏈轰俊鎭�", Dialog.ModalityType.MODELESS);
- dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
-
- JPanel content = new JPanel(new BorderLayout(0, 12));
- content.setBorder(BorderFactory.createEmptyBorder(16, 20, 16, 20));
-
- JPanel grid = new JPanel(new GridLayout(0, 2, 12, 8));
-
- grid.add(new JLabel("璁惧缂栧彿锛�"));
- mowerNumberValueLabel = createValueLabel();
- grid.add(mowerNumberValueLabel);
-
- grid.add(new JLabel("瀹炴椂X鍧愭爣锛�"));
- realtimeXValueLabel = createValueLabel();
- grid.add(realtimeXValueLabel);
-
- grid.add(new JLabel("瀹炴椂Y鍧愭爣锛�"));
- realtimeYValueLabel = createValueLabel();
- grid.add(realtimeYValueLabel);
-
- grid.add(new JLabel("瀹氫綅璐ㄩ噺锛�"));
- positioningStatusValueLabel = createValueLabel();
- grid.add(positioningStatusValueLabel);
-
- grid.add(new JLabel("鍗槦棰楁暟锛�"));
- satelliteCountValueLabel = createValueLabel();
- grid.add(satelliteCountValueLabel);
-
- grid.add(new JLabel("琛岄┒閫熷害锛�"));
- realtimeSpeedValueLabel = createValueLabel();
- grid.add(realtimeSpeedValueLabel);
-
- grid.add(new JLabel("杩愬姩鑸悜锛�"));
- headingValueLabel = createValueLabel();
- grid.add(headingValueLabel);
-
- grid.add(new JLabel("鏇存柊鏃堕棿锛�"));
- updateTimeValueLabel = createValueLabel();
- grid.add(updateTimeValueLabel);
-
- content.add(grid, BorderLayout.CENTER);
-
- JButton closeButton = new JButton("鍏抽棴");
- closeButton.addActionListener(e -> dialog.dispose());
- JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
- buttonPanel.add(closeButton);
- content.add(buttonPanel, BorderLayout.SOUTH);
-
- dialog.setContentPane(content);
- dialog.pack();
- dialog.setResizable(false);
- dialog.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosed(WindowEvent e) {
- stopMowerInfoTimer();
- resetMowerInfoLabels();
- mowerInfoDialog = null;
- }
- });
-
- mowerInfoDialog = dialog;
- }
-
- private void positionMowerDialog() {
- if (mowerInfoDialog == null || visualizationPanel == null) {
- return;
- }
- int panelWidth = visualizationPanel.getWidth();
- int panelHeight = visualizationPanel.getHeight();
- int dialogHeight = mowerInfoDialog.getHeight();
- if (dialogHeight <= 0) {
- dialogHeight = mowerInfoDialog.getPreferredSize().height;
- }
- if (panelWidth > 0) {
- mowerInfoDialog.setSize(panelWidth, dialogHeight);
- }
-
- try {
- Point panelOnScreen = visualizationPanel.getLocationOnScreen();
- int dialogWidth = mowerInfoDialog.getWidth();
- int targetX = panelOnScreen.x + (panelWidth - dialogWidth) / 2;
- int targetY = panelOnScreen.y + panelHeight / 3 - dialogHeight / 2;
- mowerInfoDialog.setLocation(targetX, targetY);
- } catch (IllegalComponentStateException ex) {
- // component not yet showing; ignore positioning
- }
- }
-
- private JLabel createValueLabel() {
- JLabel label = new JLabel("--");
- label.setHorizontalAlignment(SwingConstants.LEFT);
- return label;
- }
-
- private void startMowerInfoTimer() {
- if (mowerInfoRefreshTimer == null) {
- mowerInfoRefreshTimer = new Timer(1000, e -> updateMowerInfoLabels());
- mowerInfoRefreshTimer.setRepeats(true);
- }
- if (!mowerInfoRefreshTimer.isRunning()) {
- mowerInfoRefreshTimer.start();
- }
- }
-
- private void stopMowerInfoTimer() {
- if (mowerInfoRefreshTimer != null) {
- mowerInfoRefreshTimer.stop();
- mowerInfoRefreshTimer = null;
- }
- }
-
- private void resetMowerInfoLabels() {
- mowerNumberValueLabel = null;
- realtimeXValueLabel = null;
- realtimeYValueLabel = null;
- positioningStatusValueLabel = null;
- satelliteCountValueLabel = null;
- realtimeSpeedValueLabel = null;
- headingValueLabel = null;
- updateTimeValueLabel = null;
- }
-
- private void updateMowerInfoLabels() {
- if (mowerNumberValueLabel == null) {
- return;
- }
-
- Device device = Device.getGecaoji();
- if (device == null) {
- setMowerInfoLabels("--");
- return;
- }
-
- mower.refreshFromDevice();
-
- mowerNumberValueLabel.setText(formatDeviceValue(device.getMowerNumber()));
- realtimeXValueLabel.setText(formatDeviceValue(device.getRealtimeX()));
- realtimeYValueLabel.setText(formatDeviceValue(device.getRealtimeY()));
- positioningStatusValueLabel.setText(formatFixQualityValue(device.getPositioningStatus()));
- satelliteCountValueLabel.setText(formatDeviceValue(device.getSatelliteCount()));
- realtimeSpeedValueLabel.setText(formatDeviceValue(device.getRealtimeSpeed()));
- headingValueLabel.setText(formatDeviceValue(device.getHeading()));
- updateTimeValueLabel.setText(formatTimestamp(device.getGupdateTime()));
- }
-
- private void setMowerInfoLabels(String value) {
- if (mowerNumberValueLabel != null) mowerNumberValueLabel.setText(value);
- if (realtimeXValueLabel != null) realtimeXValueLabel.setText(value);
- if (realtimeYValueLabel != null) realtimeYValueLabel.setText(value);
- if (positioningStatusValueLabel != null) positioningStatusValueLabel.setText(value);
- if (satelliteCountValueLabel != null) satelliteCountValueLabel.setText(value);
- if (realtimeSpeedValueLabel != null) realtimeSpeedValueLabel.setText(value);
- if (headingValueLabel != null) headingValueLabel.setText(value);
- if (updateTimeValueLabel != null) updateTimeValueLabel.setText(value);
- }
-
- private String sanitizeDeviceValue(String value) {
- if (value == null) {
- return null;
- }
- String trimmed = value.trim();
- if (trimmed.isEmpty() || "-1".equals(trimmed)) {
- return null;
- }
- return trimmed;
- }
-
- private String formatDeviceValue(String value) {
- String sanitized = sanitizeDeviceValue(value);
- return sanitized == null ? "--" : sanitized;
- }
-
- private String formatFixQualityValue(String value) {
- String sanitized = sanitizeDeviceValue(value);
- if (sanitized == null) {
- return "--";
- }
- switch (sanitized) {
- case "0":
- return "鏈畾浣�";
- case "1":
- return "鍗曠偣瀹氫綅";
- case "2":
- return "鐮佸樊鍒�";
- case "3":
- return "鏃犳晥PPS";
- case "4":
- return "鍥哄畾瑙�";
- case "5":
- return "娴偣瑙�";
- case "6":
- return "姝e湪浼扮畻";
- case "7":
- return "浜哄伐杈撳叆鍥哄畾鍊�";
- case "8":
- return "妯℃嫙妯″紡";
- case "9":
- return "WAAS宸垎";
- default:
- return sanitized;
- }
- }
-
- private String formatTimestamp(String value) {
- String sanitized = sanitizeDeviceValue(value);
- if (sanitized == null) {
- return "--";
- }
- try {
- long millis = Long.parseLong(sanitized);
- return TIMESTAMP_FORMAT.format(new Date(millis));
- } catch (NumberFormatException ex) {
- return sanitized;
+ public void showMowerInfo() {
+ if (mowerInfoManager != null) {
+ mowerInfoManager.showMowerInfo();
}
}
@@ -1386,16 +1195,12 @@
if (realtimeTrackLandNumber == null) {
return false;
}
- if (currentBoundaryLandNumber != null && !currentBoundaryLandNumber.equals(realtimeTrackLandNumber)) {
- return false;
- }
+ Path2D.Double path = getRealtimeBoundaryPath();
+ return isPointInsideBoundary(point, path);
+ }
- Path2D.Double path = currentBoundaryPath;
- if (path == null) {
- path = buildBoundaryPath(currentBoundary);
- currentBoundaryPath = path;
- }
- if (path == null) {
+ private boolean isPointInsideBoundary(Point2D.Double point, Path2D.Double path) {
+ if (point == null || path == null || !Double.isFinite(point.x) || !Double.isFinite(point.y)) {
return false;
}
if (path.contains(point.x, point.y)) {
@@ -1493,6 +1298,8 @@
public void setCurrentBoundary(String boundaryCoordinates, String landNumber, String landName) {
this.boundaryName = landName;
this.currentBoundaryLandNumber = landNumber;
+ this.realtimeBoundaryPathCache = null;
+ this.realtimeBoundaryPathLand = null;
if (boundaryCoordinates == null) {
clearBoundaryData();
@@ -1534,6 +1341,8 @@
boundaryPointsVisible = false;
currentBoundaryLandNumber = null;
pendingTrackBreak = true;
+ realtimeBoundaryPathCache = null;
+ realtimeBoundaryPathLand = null;
}
public void setCurrentObstacles(String obstaclesData, String landNumber) {
@@ -1844,6 +1653,9 @@
return coords;
}
+ // Remove wrapper characters like parentheses that are used when persisting payloads
+ sanitized = sanitized.replace("(", "").replace(")", "");
+
String[] pairs = sanitized.split(";");
for (String pair : pairs) {
if (pair == null) {
@@ -1853,6 +1665,10 @@
if (trimmed.isEmpty()) {
continue;
}
+ trimmed = trimmed.replace("(", "").replace(")", "");
+ if (trimmed.isEmpty()) {
+ continue;
+ }
String[] parts = trimmed.split(",");
if (parts.length < 2) {
continue;
@@ -2117,12 +1933,7 @@
public void dispose() {
mowerUpdateTimer.stop();
- stopMowerInfoTimer();
- if (mowerInfoDialog != null) {
- mowerInfoDialog.dispose();
- mowerInfoDialog = null;
- }
- resetMowerInfoLabels();
+ mowerInfoManager.dispose();
}
}
\ No newline at end of file
--
Gitblit v1.10.0