|
|
@@ -80,7 +80,8 @@ public class MainFrame extends JFrame {
|
|
|
private JMenuItem importLayoutItem;
|
|
|
// 项目/设备子菜单(mes123解锁后显示)
|
|
|
private JMenu projectDeviceMenu;
|
|
|
- private JMenuItem switchProjectItem;
|
|
|
+ private JMenuItem switchProjectItem; // 切换产线位置
|
|
|
+ private JMenuItem switchProductItem; // 切换产品号
|
|
|
private JMenuItem switchStationItem;
|
|
|
private JMenuItem deviceIpItem;
|
|
|
private JMenuItem serverIpItem;
|
|
|
@@ -130,11 +131,11 @@ public class MainFrame extends JFrame {
|
|
|
*/
|
|
|
private void initFrame() {
|
|
|
String codes = getStationCodesString();
|
|
|
- // 标题优先用 OprnoRegistry 按当前项目推导的工位名称,其次 yaml 的 name
|
|
|
- String projectId = com.mes.core.ProjectConfigManager.getInstance().getCurrentProjectId();
|
|
|
+ // 标题优先用 OprnoRegistry 按当前产线位置推导的工位名称,其次 yaml 的 name
|
|
|
+ String lineId = com.mes.core.ProjectConfigManager.getInstance().getCurrentLineId();
|
|
|
String name = "";
|
|
|
if (!config.getStations().isEmpty()) {
|
|
|
- name = com.mes.core.OprnoRegistry.getGwDes(projectId, config.getStations().get(0).getCode());
|
|
|
+ name = com.mes.core.OprnoRegistry.getGwDes(lineId, config.getStations().get(0).getCode());
|
|
|
}
|
|
|
if ((name == null || name.isEmpty()) && config.getStationName() != null) {
|
|
|
name = config.getStationName();
|
|
|
@@ -238,9 +239,15 @@ public class MainFrame extends JFrame {
|
|
|
switchProjectItem = new JMenuItem();
|
|
|
switchProjectItem.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/resources/image/bg/menu_setting.png"))));
|
|
|
switchProjectItem.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
- switchProjectItem.addActionListener(e -> showSwitchProjectDialog());
|
|
|
+ switchProjectItem.addActionListener(e -> showSwitchLineDialog());
|
|
|
projectDeviceMenu.add(switchProjectItem);
|
|
|
|
|
|
+ switchProductItem = new JMenuItem();
|
|
|
+ switchProductItem.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/resources/image/bg/menu_setting.png"))));
|
|
|
+ switchProductItem.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
+ switchProductItem.addActionListener(e -> showSwitchProductDialog());
|
|
|
+ projectDeviceMenu.add(switchProductItem);
|
|
|
+
|
|
|
switchStationItem = new JMenuItem();
|
|
|
switchStationItem.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/resources/image/bg/menu_setting.png"))));
|
|
|
switchStationItem.setFont(new Font("微软雅黑", Font.PLAIN, 20));
|
|
|
@@ -426,10 +433,15 @@ public class MainFrame extends JFrame {
|
|
|
toolBar.add(projectMenu);
|
|
|
updateProjectDisplay();
|
|
|
|
|
|
- // 订阅项目切换 → 刷新工具栏显示
|
|
|
+ // 订阅产线位置/产品号切换 → 刷新工具栏显示
|
|
|
com.mes.core.ProjectConfigManager.getInstance().addListener(new com.mes.core.ProjectConfigManager.Listener() {
|
|
|
@Override
|
|
|
- public void onProjectChanged(com.mes.core.ProjectConfigManager.Project project) {
|
|
|
+ public void onLineChanged(com.mes.core.ProjectConfigManager.Line line) {
|
|
|
+ SwingUtilities.invokeLater(() -> updateProjectDisplay());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onProductChanged(com.mes.core.ProjectConfigManager.Product product) {
|
|
|
SwingUtilities.invokeLater(() -> updateProjectDisplay());
|
|
|
}
|
|
|
});
|
|
|
@@ -1318,37 +1330,38 @@ public class MainFrame extends JFrame {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // ========== 项目切换/设备IP修改 ==========
|
|
|
+ // ========== 产线位置/产品号切换/设备IP修改 ==========
|
|
|
|
|
|
/**
|
|
|
- * 刷新工具栏上的项目显示
|
|
|
+ * 刷新工具栏上的产线位置/产品号显示
|
|
|
*/
|
|
|
private void updateProjectDisplay() {
|
|
|
if (projectMenu == null) return;
|
|
|
com.mes.core.ProjectConfigManager pc = com.mes.core.ProjectConfigManager.getInstance();
|
|
|
- com.mes.core.ProjectConfigManager.Project p = pc.getCurrentProject();
|
|
|
- if (p != null) {
|
|
|
- projectMenu.setText(p.getDisplay());
|
|
|
+ com.mes.core.ProjectConfigManager.Line line = pc.getCurrentLine();
|
|
|
+ com.mes.core.ProjectConfigManager.Product product = pc.getCurrentProduct();
|
|
|
+ if (line != null && product != null) {
|
|
|
+ projectMenu.setText(line.getDisplay() + " / " + product.getDisplay());
|
|
|
projectMenu.setToolTipText(String.format(
|
|
|
- "<html>当前项目:%s<br>工件码前缀:%s<br>冷板码前缀:%s<br>底护板码前缀:%s</html>",
|
|
|
- p.getDisplay(), p.getProductPrefix(), p.getColdPlatePrefix(), p.getBottomPlatePrefix()));
|
|
|
+ "<html>产线位置:%s<br>产品号:%s<br>工件码前缀:%s<br>冷板码前缀:%s<br>底护板码前缀:%s</html>",
|
|
|
+ line.getDisplay(), product.getDisplay(),
|
|
|
+ product.getProductPrefix(), product.getColdPlatePrefix(), product.getBottomPlatePrefix()));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 弹出切换项目对话框
|
|
|
+ * 弹出切换产线位置对话框(只影响工位号→工序名称的映射)
|
|
|
*/
|
|
|
- private void showSwitchProjectDialog() {
|
|
|
+ private void showSwitchLineDialog() {
|
|
|
com.mes.core.ProjectConfigManager pc = com.mes.core.ProjectConfigManager.getInstance();
|
|
|
- java.util.List<com.mes.core.ProjectConfigManager.Project> projects = pc.getProjects();
|
|
|
+ java.util.List<com.mes.core.ProjectConfigManager.Line> lines = pc.getLines();
|
|
|
|
|
|
- String[] options = new String[projects.size()];
|
|
|
+ String[] options = new String[lines.size()];
|
|
|
int currentIndex = 0;
|
|
|
- for (int i = 0; i < projects.size(); i++) {
|
|
|
- com.mes.core.ProjectConfigManager.Project p = projects.get(i);
|
|
|
- options[i] = String.format("%s (工件:%s 冷板:%s 底护板:%s)",
|
|
|
- p.getDisplay(), p.getProductPrefix(), p.getColdPlatePrefix(), p.getBottomPlatePrefix());
|
|
|
- if (p.getId().equalsIgnoreCase(pc.getCurrentProjectId())) {
|
|
|
+ for (int i = 0; i < lines.size(); i++) {
|
|
|
+ com.mes.core.ProjectConfigManager.Line l = lines.get(i);
|
|
|
+ options[i] = l.getDisplay();
|
|
|
+ if (l.getId().equalsIgnoreCase(pc.getCurrentLineId())) {
|
|
|
currentIndex = i;
|
|
|
}
|
|
|
}
|
|
|
@@ -1358,37 +1371,31 @@ public class MainFrame extends JFrame {
|
|
|
combo.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
|
|
|
JPanel panel = new JPanel(new BorderLayout(5, 5));
|
|
|
- panel.add(new JLabel("选择项目:"), BorderLayout.NORTH);
|
|
|
+ panel.add(new JLabel("选择产线位置:"), BorderLayout.NORTH);
|
|
|
panel.add(combo, BorderLayout.CENTER);
|
|
|
|
|
|
int result = JOptionPane.showConfirmDialog(this, panel,
|
|
|
- "切换项目", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
|
|
+ "切换产线位置", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
|
|
if (result != JOptionPane.OK_OPTION) return;
|
|
|
|
|
|
int idx = combo.getSelectedIndex();
|
|
|
- if (idx < 0 || idx >= projects.size()) return;
|
|
|
- com.mes.core.ProjectConfigManager.Project target = projects.get(idx);
|
|
|
- if (target.getId().equalsIgnoreCase(pc.getCurrentProjectId())) {
|
|
|
+ if (idx < 0 || idx >= lines.size()) return;
|
|
|
+ com.mes.core.ProjectConfigManager.Line target = lines.get(idx);
|
|
|
+ if (target.getId().equalsIgnoreCase(pc.getCurrentLineId())) {
|
|
|
return;
|
|
|
}
|
|
|
- pc.switchProject(target.getId());
|
|
|
+ pc.switchLine(target.getId());
|
|
|
|
|
|
- // 重置所有工位,避免沿用旧项目扫到一半的码
|
|
|
- for (int i = 0; i < engines.size(); i++) {
|
|
|
- engines.get(i).reset();
|
|
|
- if (i < panels.size()) panels.get(i).reset();
|
|
|
- }
|
|
|
-
|
|
|
- // 切换项目后同步工位名(标题 + context 的 stationName)
|
|
|
- String newProjectId = target.getId();
|
|
|
+ // 切换产线位置后同步工位名(标题 + context 的 stationName)
|
|
|
+ String newLineId = target.getId();
|
|
|
for (StationContext ctx : contexts) {
|
|
|
- String newName = com.mes.core.OprnoRegistry.getGwDes(newProjectId, ctx.getStationCode());
|
|
|
+ String newName = com.mes.core.OprnoRegistry.getGwDes(newLineId, ctx.getStationCode());
|
|
|
if (newName == null || newName.isEmpty()) newName = ctx.getStationCode();
|
|
|
ctx.updateStation(null, newName, null);
|
|
|
}
|
|
|
if (!config.getStations().isEmpty()) {
|
|
|
String code = config.getStations().get(0).getCode();
|
|
|
- String name = com.mes.core.OprnoRegistry.getGwDes(newProjectId, code);
|
|
|
+ String name = com.mes.core.OprnoRegistry.getGwDes(newLineId, code);
|
|
|
String title = "MES系统客户端:" + code;
|
|
|
if (name != null && !name.isEmpty() && !name.equals(code)) title += " - " + name;
|
|
|
setTitle(title);
|
|
|
@@ -1397,6 +1404,58 @@ public class MainFrame extends JFrame {
|
|
|
updateProjectDisplay();
|
|
|
|
|
|
JOptionPane.showMessageDialog(this,
|
|
|
+ "已切换到:" + target.getDisplay() + "\n工位名称已刷新",
|
|
|
+ "切换成功", JOptionPane.INFORMATION_MESSAGE);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 弹出切换产品号对话框(只影响工件码/冷板码/底护板码前缀)
|
|
|
+ */
|
|
|
+ private void showSwitchProductDialog() {
|
|
|
+ com.mes.core.ProjectConfigManager pc = com.mes.core.ProjectConfigManager.getInstance();
|
|
|
+ java.util.List<com.mes.core.ProjectConfigManager.Product> products = pc.getProducts();
|
|
|
+
|
|
|
+ String[] options = new String[products.size()];
|
|
|
+ int currentIndex = 0;
|
|
|
+ for (int i = 0; i < products.size(); i++) {
|
|
|
+ com.mes.core.ProjectConfigManager.Product p = products.get(i);
|
|
|
+ options[i] = String.format("%s (工件:%s 冷板:%s 底护板:%s)",
|
|
|
+ p.getDisplay(), p.getProductPrefix(), p.getColdPlatePrefix(), p.getBottomPlatePrefix());
|
|
|
+ if (p.getId().equalsIgnoreCase(pc.getCurrentProductId())) {
|
|
|
+ currentIndex = i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ JComboBox<String> combo = new JComboBox<>(options);
|
|
|
+ combo.setSelectedIndex(currentIndex);
|
|
|
+ combo.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
+
|
|
|
+ JPanel panel = new JPanel(new BorderLayout(5, 5));
|
|
|
+ panel.add(new JLabel("选择产品号:"), BorderLayout.NORTH);
|
|
|
+ panel.add(combo, BorderLayout.CENTER);
|
|
|
+
|
|
|
+ int result = JOptionPane.showConfirmDialog(this, panel,
|
|
|
+ "切换产品号", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
|
|
|
+ if (result != JOptionPane.OK_OPTION) return;
|
|
|
+
|
|
|
+ int idx = combo.getSelectedIndex();
|
|
|
+ if (idx < 0 || idx >= products.size()) return;
|
|
|
+ com.mes.core.ProjectConfigManager.Product target = products.get(idx);
|
|
|
+ if (target.getId().equalsIgnoreCase(pc.getCurrentProductId())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ pc.switchProduct(target.getId());
|
|
|
+
|
|
|
+ // 重置所有工位,避免沿用旧产品号扫到一半的码
|
|
|
+ for (int i = 0; i < engines.size(); i++) {
|
|
|
+ engines.get(i).reset();
|
|
|
+ if (i < panels.size()) panels.get(i).reset();
|
|
|
+ }
|
|
|
+
|
|
|
+ refreshMenuTexts();
|
|
|
+ updateProjectDisplay();
|
|
|
+
|
|
|
+ JOptionPane.showMessageDialog(this,
|
|
|
"已切换到:" + target.getDisplay() + "\n前缀校验立即生效,所有工位已重置",
|
|
|
"切换成功", JOptionPane.INFORMATION_MESSAGE);
|
|
|
}
|
|
|
@@ -1527,12 +1586,16 @@ public class MainFrame extends JFrame {
|
|
|
private void refreshMenuTexts() {
|
|
|
com.mes.core.ProjectConfigManager pc = com.mes.core.ProjectConfigManager.getInstance();
|
|
|
if (switchProjectItem != null) {
|
|
|
- com.mes.core.ProjectConfigManager.Project p = pc.getCurrentProject();
|
|
|
- switchProjectItem.setText("切换项目 (当前: " + (p != null ? p.getDisplay() : "?") + ")");
|
|
|
+ com.mes.core.ProjectConfigManager.Line line = pc.getCurrentLine();
|
|
|
+ switchProjectItem.setText("切换产线位置 (当前: " + (line != null ? line.getDisplay() : "?") + ")");
|
|
|
+ }
|
|
|
+ if (switchProductItem != null) {
|
|
|
+ com.mes.core.ProjectConfigManager.Product product = pc.getCurrentProduct();
|
|
|
+ switchProductItem.setText("切换产品号 (当前: " + (product != null ? product.getDisplay() : "?") + ")");
|
|
|
}
|
|
|
if (switchStationItem != null && !config.getStations().isEmpty()) {
|
|
|
String code = config.getStations().get(0).getCode();
|
|
|
- String des = com.mes.core.OprnoRegistry.getGwDes(pc.getCurrentProjectId(), code);
|
|
|
+ String des = com.mes.core.OprnoRegistry.getGwDes(pc.getCurrentLineId(), code);
|
|
|
if (des == null || des.isEmpty()) des = "未知工位";
|
|
|
switchStationItem.setText("修改工位号 (当前: " + code + " - " + des + ")");
|
|
|
}
|
|
|
@@ -1546,12 +1609,11 @@ public class MainFrame extends JFrame {
|
|
|
|
|
|
/**
|
|
|
* 弹出修改工位号对话框
|
|
|
- * 工位列表按当前项目(P1-P4)展示;工位名称由 OprnoRegistry 自动推导
|
|
|
+ * 工位列表按当前产线位置(P1-P4)展示;工位名称由 OprnoRegistry 自动推导
|
|
|
*/
|
|
|
private void showSwitchStationDialog() {
|
|
|
com.mes.core.ProjectConfigManager pc = com.mes.core.ProjectConfigManager.getInstance();
|
|
|
- String projectId = pc.getCurrentProjectId();
|
|
|
- com.mes.core.ProjectConfigManager.Project project = pc.getCurrentProject();
|
|
|
+ String lineId = pc.getCurrentLineId();
|
|
|
String currentCode = config.getStations().isEmpty() ? "" : config.getStations().get(0).getCode();
|
|
|
|
|
|
// 拆分当前code为 "基础码" + "后缀"
|
|
|
@@ -1563,10 +1625,10 @@ public class MainFrame extends JFrame {
|
|
|
JComboBox<String> codeCombo = new JComboBox<>();
|
|
|
codeCombo.setEditable(false);
|
|
|
codeCombo.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
- for (String c : com.mes.core.OprnoRegistry.listCodes(projectId)) {
|
|
|
+ for (String c : com.mes.core.OprnoRegistry.listCodes(lineId)) {
|
|
|
codeCombo.addItem(c);
|
|
|
}
|
|
|
- if (com.mes.core.OprnoRegistry.listCodes(projectId).contains(currentBase)) {
|
|
|
+ if (com.mes.core.OprnoRegistry.listCodes(lineId).contains(currentBase)) {
|
|
|
codeCombo.setSelectedItem(currentBase);
|
|
|
}
|
|
|
|
|
|
@@ -1593,7 +1655,7 @@ public class MainFrame extends JFrame {
|
|
|
String sfxReal = ("(无)".equals(sfx) || sfx == null) ? "" : sfx;
|
|
|
String full = base + sfxReal;
|
|
|
previewLabel.setText("最终工位号: " + (full.isEmpty() ? "-" : full));
|
|
|
- String des = com.mes.core.OprnoRegistry.getGwDes(projectId, full);
|
|
|
+ String des = com.mes.core.OprnoRegistry.getGwDes(lineId, full);
|
|
|
desLabel.setText("工位名称: " + (des.isEmpty() ? "(未知工位)" : des));
|
|
|
};
|
|
|
refresh.run();
|
|
|
@@ -1606,9 +1668,9 @@ public class MainFrame extends JFrame {
|
|
|
gbc.anchor = java.awt.GridBagConstraints.WEST;
|
|
|
|
|
|
gbc.gridx = 0; gbc.gridy = 0;
|
|
|
- panel.add(new JLabel("当前项目:"), gbc);
|
|
|
+ panel.add(new JLabel("当前产线位置:"), gbc);
|
|
|
gbc.gridx = 1; gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
|
|
|
- JLabel projectLbl = new JLabel(project != null ? project.getDisplay() : projectId);
|
|
|
+ JLabel projectLbl = new JLabel(lineId);
|
|
|
projectLbl.setFont(new Font("微软雅黑", Font.PLAIN, 16));
|
|
|
panel.add(projectLbl, gbc);
|
|
|
|
|
|
@@ -1644,7 +1706,7 @@ public class MainFrame extends JFrame {
|
|
|
pc.setStationOverride(newCode, null);
|
|
|
applyStationChange(newCode);
|
|
|
|
|
|
- String des = com.mes.core.OprnoRegistry.getGwDes(projectId, newCode);
|
|
|
+ String des = com.mes.core.OprnoRegistry.getGwDes(lineId, newCode);
|
|
|
JOptionPane.showMessageDialog(this,
|
|
|
"工位已更新为:" + newCode + (des.isEmpty() ? "" : (" - " + des)) + "\n已刷新界面并向MES重新同步",
|
|
|
"修改成功", JOptionPane.INFORMATION_MESSAGE);
|
|
|
@@ -1655,7 +1717,7 @@ public class MainFrame extends JFrame {
|
|
|
*/
|
|
|
private void applyStationChange(String newCode) {
|
|
|
String oldCode = config.getStations().isEmpty() ? "" : config.getStations().get(0).getCode();
|
|
|
- String projectId = com.mes.core.ProjectConfigManager.getInstance().getCurrentProjectId();
|
|
|
+ String lineId = com.mes.core.ProjectConfigManager.getInstance().getCurrentLineId();
|
|
|
|
|
|
// 1. 更新 config
|
|
|
if (!config.getStations().isEmpty()) {
|
|
|
@@ -1663,7 +1725,7 @@ public class MainFrame extends JFrame {
|
|
|
}
|
|
|
|
|
|
// 2. 更新 context(推导工位名)
|
|
|
- String name = com.mes.core.OprnoRegistry.getGwDes(projectId, newCode);
|
|
|
+ String name = com.mes.core.OprnoRegistry.getGwDes(lineId, newCode);
|
|
|
if (name == null || name.isEmpty()) name = newCode;
|
|
|
for (StationContext ctx : contexts) {
|
|
|
if (ctx.getStationIndex() == 0) {
|