use of org.opentcs.drivers.vehicle.management.AttachmentInformation in project opentcs by openTCS.
the class AttachmentManager method updateAttachmentInformation.
private void updateAttachmentInformation(VehicleEntry entry) {
String vehicleName = entry.getVehicleName();
VehicleCommAdapterFactory factory = entry.getCommAdapterFactory();
AttachmentInformation newAttachment = attachmentPool.get(vehicleName).withAttachedCommAdapter(factory.getDescription());
attachmentPool.put(vehicleName, newAttachment);
eventHandler.onEvent(new AttachmentEvent(vehicleName, newAttachment));
if (entry.getCommAdapter() == null) {
// In case we are detached
eventHandler.onEvent(new ProcessModelEvent(vehicleName, new VehicleProcessModelTO()));
} else {
eventHandler.onEvent(new ProcessModelEvent(vehicleName, entry.getCommAdapter().createTransferableProcessModel()));
}
}
use of org.opentcs.drivers.vehicle.management.AttachmentInformation in project opentcs by openTCS.
the class DriverGUI method initCommAdaptersComboBox.
private void initCommAdaptersComboBox(LocalVehicleEntry vehicleEntry, int rowIndex, SingleCellEditor adapterCellEditor) {
final CommAdapterComboBox comboBox = new CommAdapterComboBox();
AttachmentInformation ai;
try {
ai = callWrapper.call(() -> servicePortal.getVehicleService().fetchAttachmentInformation(vehicleEntry.getAttachmentInformation().getVehicleReference()));
} catch (Exception ex) {
LOG.warn("Error fetching attachment information for {}", vehicleEntry.getVehicleName(), ex);
return;
}
ai.getAvailableCommAdapters().forEach(factory -> comboBox.addItem(factory));
// Set the selection to the attached comm adapter, (The vehicle is already attached to a comm
// adapter due to auto attachment on startup.)
comboBox.setSelectedItem(vehicleEntry.getAttachmentInformation().getAttachedCommAdapter());
comboBox.setRenderer(new AdapterFactoryCellRenderer());
comboBox.addPopupMenuListener(new BoundsPopupMenuListener());
comboBox.addItemListener((ItemEvent evt) -> {
if (evt.getStateChange() == ItemEvent.DESELECTED) {
return;
}
// If we selected a comm adapter that's already attached, do nothing.
if (Objects.equals(evt.getItem(), vehicleEntry.getAttachedCommAdapterDescription())) {
LOG.debug("{} is already attached to: {}", vehicleEntry.getVehicleName(), evt.getItem());
return;
}
int reply = JOptionPane.showConfirmDialog(null, bundle.getString("driverGui.optionPane_driverChangeConfirmation.message"), bundle.getString("driverGui.optionPane_driverChangeConfirmation.title"), JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.NO_OPTION) {
return;
}
VehicleCommAdapterDescription factory = comboBox.getSelectedItem();
try {
callWrapper.call(() -> servicePortal.getVehicleService().attachCommAdapter(vehicleEntry.getAttachmentInformation().getVehicleReference(), factory));
} catch (Exception ex) {
LOG.warn("Error attaching adapter {} to vehicle {}", factory, vehicleEntry.getVehicleName(), ex);
return;
}
LOG.info("Attaching comm adapter {} to {}", factory, vehicleEntry.getVehicleName());
});
adapterCellEditor.setEditorAt(rowIndex, new DefaultCellEditor(comboBox));
vehicleEntry.addPropertyChangeListener(comboBox);
}
use of org.opentcs.drivers.vehicle.management.AttachmentInformation in project opentcs by openTCS.
the class VehicleTableModel method isRelevantUpdate.
private boolean isRelevantUpdate(PropertyChangeEvent evt) {
if (Objects.equals(evt.getPropertyName(), LocalVehicleEntry.Attribute.ATTACHMENT_INFORMATION.name())) {
AttachmentInformation oldInfo = (AttachmentInformation) evt.getOldValue();
AttachmentInformation newInfo = (AttachmentInformation) evt.getNewValue();
return !oldInfo.getAttachedCommAdapter().equals(newInfo.getAttachedCommAdapter());
}
if (Objects.equals(evt.getPropertyName(), LocalVehicleEntry.Attribute.PROCESS_MODEL.name())) {
VehicleProcessModelTO oldTo = (VehicleProcessModelTO) evt.getOldValue();
VehicleProcessModelTO newTo = (VehicleProcessModelTO) evt.getNewValue();
return oldTo.isCommAdapterEnabled() != newTo.isCommAdapterEnabled() || oldTo.getVehicleState() != newTo.getVehicleState() || !Objects.equals(oldTo.getVehiclePosition(), newTo.getVehiclePosition());
}
return false;
}
use of org.opentcs.drivers.vehicle.management.AttachmentInformation in project OpenTCS-4 by touchmii.
the class LocalVehicleEntryPool method initialize.
@Override
public void initialize() {
if (isInitialized()) {
LOG.debug("Already initialized.");
return;
}
eventSource.subscribe(this);
try {
Set<Vehicle> vehicles = callWrapper.call(() -> servicePortal.getVehicleService().fetchObjects(Vehicle.class));
for (Vehicle vehicle : vehicles) {
AttachmentInformation ai = callWrapper.call(() -> servicePortal.getVehicleService().fetchAttachmentInformation(vehicle.getReference()));
VehicleProcessModelTO processModel = callWrapper.call(() -> servicePortal.getVehicleService().fetchProcessModel(vehicle.getReference()));
LocalVehicleEntry entry = new LocalVehicleEntry(ai, processModel);
entries.put(vehicle.getName(), entry);
}
} catch (Exception ex) {
LOG.warn("Error initializing local vehicle entry pool", ex);
entries.clear();
return;
}
LOG.debug("Initialized vehicle entry pool: {}", entries);
initialized = true;
}
use of org.opentcs.drivers.vehicle.management.AttachmentInformation in project OpenTCS-4 by touchmii.
the class AttachmentManager method updateAttachmentInformation.
private void updateAttachmentInformation(VehicleEntry entry) {
String vehicleName = entry.getVehicleName();
VehicleCommAdapterFactory factory = entry.getCommAdapterFactory();
AttachmentInformation newAttachment = attachmentPool.get(vehicleName).withAttachedCommAdapter(factory.getDescription());
attachmentPool.put(vehicleName, newAttachment);
eventHandler.onEvent(new AttachmentEvent(vehicleName, newAttachment));
if (entry.getCommAdapter() == null) {
// In case we are detached
eventHandler.onEvent(new ProcessModelEvent(vehicleName, new VehicleProcessModelTO()));
} else {
eventHandler.onEvent(new ProcessModelEvent(vehicleName, entry.getCommAdapter().createTransferableProcessModel()));
}
}
Aggregations