Search in sources :

Example 1 with AttachmentInformation

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()));
    }
}
Also used : VehicleCommAdapterFactory(org.opentcs.drivers.vehicle.VehicleCommAdapterFactory) ProcessModelEvent(org.opentcs.drivers.vehicle.management.ProcessModelEvent) AttachmentInformation(org.opentcs.drivers.vehicle.management.AttachmentInformation) VehicleProcessModelTO(org.opentcs.drivers.vehicle.management.VehicleProcessModelTO) AttachmentEvent(org.opentcs.drivers.vehicle.management.AttachmentEvent)

Example 2 with AttachmentInformation

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);
}
Also used : ItemEvent(java.awt.event.ItemEvent) VehicleCommAdapterDescription(org.opentcs.drivers.vehicle.VehicleCommAdapterDescription) AttachmentInformation(org.opentcs.drivers.vehicle.management.AttachmentInformation) BoundsPopupMenuListener(org.opentcs.util.gui.BoundsPopupMenuListener) Point(org.opentcs.data.model.Point) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 3 with AttachmentInformation

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;
}
Also used : AttachmentInformation(org.opentcs.drivers.vehicle.management.AttachmentInformation) VehicleProcessModelTO(org.opentcs.drivers.vehicle.management.VehicleProcessModelTO)

Example 4 with AttachmentInformation

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;
}
Also used : Vehicle(org.opentcs.data.model.Vehicle) AttachmentInformation(org.opentcs.drivers.vehicle.management.AttachmentInformation) VehicleProcessModelTO(org.opentcs.drivers.vehicle.management.VehicleProcessModelTO)

Example 5 with AttachmentInformation

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()));
    }
}
Also used : VehicleCommAdapterFactory(org.opentcs.drivers.vehicle.VehicleCommAdapterFactory) ProcessModelEvent(org.opentcs.drivers.vehicle.management.ProcessModelEvent) AttachmentInformation(org.opentcs.drivers.vehicle.management.AttachmentInformation) VehicleProcessModelTO(org.opentcs.drivers.vehicle.management.VehicleProcessModelTO) AttachmentEvent(org.opentcs.drivers.vehicle.management.AttachmentEvent)

Aggregations

AttachmentInformation (org.opentcs.drivers.vehicle.management.AttachmentInformation)12 VehicleProcessModelTO (org.opentcs.drivers.vehicle.management.VehicleProcessModelTO)8 Vehicle (org.opentcs.data.model.Vehicle)4 VehicleCommAdapterDescription (org.opentcs.drivers.vehicle.VehicleCommAdapterDescription)4 VehicleCommAdapterFactory (org.opentcs.drivers.vehicle.VehicleCommAdapterFactory)4 AttachmentEvent (org.opentcs.drivers.vehicle.management.AttachmentEvent)4 ProcessModelEvent (org.opentcs.drivers.vehicle.management.ProcessModelEvent)4 Strings (com.google.common.base.Strings)2 ItemEvent (java.awt.event.ItemEvent)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Objects.requireNonNull (java.util.Objects.requireNonNull)2 Collectors (java.util.stream.Collectors)2 Nonnull (javax.annotation.Nonnull)2 Nullable (javax.annotation.Nullable)2 Inject (javax.inject.Inject)2 DefaultCellEditor (javax.swing.DefaultCellEditor)2 Lifecycle (org.opentcs.components.Lifecycle)2