张世豪
2025-12-12 8d68e8c24e5d7f7f363041ebfe6c2b4c26068fef
新增了点击开始判断割草机是否在边界内的判断
已修改3个文件
111 ■■■■■ 文件已修改
set.properties 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/zhuye/MapRenderer.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/zhuye/Shouye.java 93 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
set.properties
@@ -1,5 +1,5 @@
#Current work land selection updated
#Fri Dec 12 17:06:21 CST 2025
#Fri Dec 12 17:21:33 CST 2025
appVersion=-1
currentWorkLandNumber=LAND1
cuttingWidth=200
src/zhuye/MapRenderer.java
@@ -2081,4 +2081,20 @@
        mowerInfoManager.dispose();
    }
    /**
     * 获取当前边界点列表
     * @return 当前边界点列表,如果没有边界则返回null
     */
    public List<Point2D.Double> getCurrentBoundary() {
        return currentBoundary;
    }
    /**
     * 获取割草机实例
     * @return 割草机实例
     */
    public Gecaoji getMower() {
        return mower;
    }
}
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 如果割草机在边界内返回true,否则返回false并显示提示
     */
    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();