Search in sources :

Example 1 with VehicleCommAdapterDescription

use of org.opentcs.drivers.vehicle.VehicleCommAdapterDescription in project OpenTCS-4 by touchmii.

the class AttachmentManager method initAttachmentPool.

private void initAttachmentPool() {
    vehicleEntryPool.getEntries().forEach((vehicleName, entry) -> {
        List<VehicleCommAdapterDescription> availableCommAdapters = commAdapterRegistry.getFactories().stream().filter(f -> f.providesAdapterFor(entry.getVehicle())).map(f -> f.getDescription()).collect(Collectors.toList());
        attachmentPool.put(vehicleName, new AttachmentInformation(entry.getVehicle().getReference(), availableCommAdapters, new DefaultVehicleCommAdapterDescription("-")));
    });
}
Also used : TCSObjectService(org.opentcs.components.kernel.services.TCSObjectService) AttachmentEvent(org.opentcs.drivers.vehicle.management.AttachmentEvent) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) VehicleProcessModelTO(org.opentcs.drivers.vehicle.management.VehicleProcessModelTO) VehicleCommAdapter(org.opentcs.drivers.vehicle.VehicleCommAdapter) Inject(javax.inject.Inject) LocalVehicleControllerPool(org.opentcs.kernel.vehicles.LocalVehicleControllerPool) Strings(com.google.common.base.Strings) EventHandler(org.opentcs.util.event.EventHandler) Lifecycle(org.opentcs.components.Lifecycle) Vehicle(org.opentcs.data.model.Vehicle) ProcessModelEvent(org.opentcs.drivers.vehicle.management.ProcessModelEvent) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) AttachmentInformation(org.opentcs.drivers.vehicle.management.AttachmentInformation) VehicleCommAdapterFactory(org.opentcs.drivers.vehicle.VehicleCommAdapterFactory) VehicleCommAdapterDescription(org.opentcs.drivers.vehicle.VehicleCommAdapterDescription) Nonnull(javax.annotation.Nonnull) VehicleCommAdapterRegistry(org.opentcs.kernel.vehicles.VehicleCommAdapterRegistry) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) KernelApplicationConfiguration(org.opentcs.kernel.KernelApplicationConfiguration) Assertions(org.opentcs.util.Assertions) Collectors(java.util.stream.Collectors) ApplicationEventBus(org.opentcs.customizations.ApplicationEventBus) Objects(java.util.Objects) List(java.util.List) DefaultVehicleCommAdapterDescription(org.opentcs.drivers.vehicle.DefaultVehicleCommAdapterDescription) DefaultVehicleCommAdapterDescription(org.opentcs.drivers.vehicle.DefaultVehicleCommAdapterDescription) VehicleCommAdapterDescription(org.opentcs.drivers.vehicle.VehicleCommAdapterDescription) DefaultVehicleCommAdapterDescription(org.opentcs.drivers.vehicle.DefaultVehicleCommAdapterDescription) AttachmentInformation(org.opentcs.drivers.vehicle.management.AttachmentInformation)

Example 2 with VehicleCommAdapterDescription

use of org.opentcs.drivers.vehicle.VehicleCommAdapterDescription in project OpenTCS-4 by touchmii.

the class DriverGUI method createDriverMenu.

private void createDriverMenu() {
    driverMenu.removeAll();
    // Collect all available comm adapters/factories
    Set<VehicleCommAdapterDescription> availableDescriptions = new HashSet<>();
    vehicleEntryPool.getEntries().forEach((vehicleName, entry) -> {
        availableDescriptions.addAll(entry.getAttachmentInformation().getAvailableCommAdapters());
    });
    for (VehicleCommAdapterDescription description : availableDescriptions) {
        // If there's one vehicle not supported by this factory the selection can't be attached to it
        boolean factorySupportsSelectedVehicles = getSelectedVehicleEntries().stream().map(entry -> entry.getAttachmentInformation().getAvailableCommAdapters()).allMatch(descriptions -> !Collections.disjoint(descriptions, availableDescriptions));
        List<String> vehiclesToAttach = new ArrayList<>();
        if (factorySupportsSelectedVehicles) {
            vehiclesToAttach = getSelectedVehicleNames();
        }
        Action action = new AttachCommAdapterAction(vehiclesToAttach, description);
        JMenuItem menuItem = driverMenu.add(action);
        menuItem.setEnabled(!vehiclesToAttach.isEmpty());
    }
}
Also used : BUNDLE_PATH(org.opentcs.kernelcontrolcenter.I18nKernelControlCenter.BUNDLE_PATH) ControlCenterPanel(org.opentcs.components.kernelcontrolcenter.ControlCenterPanel) Comparators(org.opentcs.util.Comparators) LoggerFactory(org.slf4j.LoggerFactory) Action(javax.swing.Action) VehicleProcessModelTO(org.opentcs.drivers.vehicle.management.VehicleProcessModelTO) ServiceCallWrapper(org.opentcs.customizations.ServiceCallWrapper) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ResourceBundle(java.util.ResourceBundle) JMenuItem(javax.swing.JMenuItem) StringListCellRenderer(org.opentcs.util.gui.StringListCellRenderer) Objects.requireNonNull(java.util.Objects.requireNonNull) AttachmentInformation(org.opentcs.drivers.vehicle.management.AttachmentInformation) VehicleCommAdapterDescription(org.opentcs.drivers.vehicle.VehicleCommAdapterDescription) LinkedList(java.util.LinkedList) JComboBox(javax.swing.JComboBox) Nonnull(javax.annotation.Nonnull) EventQueue(java.awt.EventQueue) ItemEvent(java.awt.event.ItemEvent) Logger(org.slf4j.Logger) Assertions.checkState(org.opentcs.util.Assertions.checkState) BoundsPopupMenuListener(org.opentcs.util.gui.BoundsPopupMenuListener) Collection(java.util.Collection) Set(java.util.Set) KernelServicePortal(org.opentcs.access.KernelServicePortal) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) Collectors(java.util.stream.Collectors) DefaultCellEditor(javax.swing.DefaultCellEditor) Objects(java.util.Objects) List(java.util.List) Kernel(org.opentcs.access.Kernel) AbstractAction(javax.swing.AbstractAction) Point(org.opentcs.data.model.Point) InitPositionCommand(org.opentcs.drivers.vehicle.commands.InitPositionCommand) CallWrapper(org.opentcs.util.CallWrapper) Collections(java.util.Collections) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) VehicleCommAdapterDescription(org.opentcs.drivers.vehicle.VehicleCommAdapterDescription) ArrayList(java.util.ArrayList) JMenuItem(javax.swing.JMenuItem) HashSet(java.util.HashSet)

Example 3 with VehicleCommAdapterDescription

use of org.opentcs.drivers.vehicle.VehicleCommAdapterDescription 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 4 with VehicleCommAdapterDescription

use of org.opentcs.drivers.vehicle.VehicleCommAdapterDescription in project OpenTCS-4 by touchmii.

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 5 with VehicleCommAdapterDescription

use of org.opentcs.drivers.vehicle.VehicleCommAdapterDescription in project opentcs by openTCS.

the class AttachmentManager method initAttachmentPool.

private void initAttachmentPool() {
    vehicleEntryPool.getEntries().forEach((vehicleName, entry) -> {
        List<VehicleCommAdapterDescription> availableCommAdapters = commAdapterRegistry.getFactories().stream().filter(f -> f.providesAdapterFor(entry.getVehicle())).map(f -> f.getDescription()).collect(Collectors.toList());
        attachmentPool.put(vehicleName, new AttachmentInformation(entry.getVehicle().getReference(), availableCommAdapters, new NullVehicleCommAdapterDescription()));
    });
}
Also used : TCSObjectService(org.opentcs.components.kernel.services.TCSObjectService) AttachmentEvent(org.opentcs.drivers.vehicle.management.AttachmentEvent) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) VehicleProcessModelTO(org.opentcs.drivers.vehicle.management.VehicleProcessModelTO) VehicleCommAdapter(org.opentcs.drivers.vehicle.VehicleCommAdapter) Inject(javax.inject.Inject) LocalVehicleControllerPool(org.opentcs.kernel.vehicles.LocalVehicleControllerPool) Strings(com.google.common.base.Strings) EventHandler(org.opentcs.util.event.EventHandler) Lifecycle(org.opentcs.components.Lifecycle) Vehicle(org.opentcs.data.model.Vehicle) ProcessModelEvent(org.opentcs.drivers.vehicle.management.ProcessModelEvent) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) AttachmentInformation(org.opentcs.drivers.vehicle.management.AttachmentInformation) VehicleCommAdapterFactory(org.opentcs.drivers.vehicle.VehicleCommAdapterFactory) VehicleCommAdapterDescription(org.opentcs.drivers.vehicle.VehicleCommAdapterDescription) Nonnull(javax.annotation.Nonnull) VehicleCommAdapterRegistry(org.opentcs.kernel.vehicles.VehicleCommAdapterRegistry) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) KernelApplicationConfiguration(org.opentcs.kernel.KernelApplicationConfiguration) Assertions(org.opentcs.util.Assertions) Collectors(java.util.stream.Collectors) ApplicationEventBus(org.opentcs.customizations.ApplicationEventBus) Objects(java.util.Objects) List(java.util.List) VehicleCommAdapterDescription(org.opentcs.drivers.vehicle.VehicleCommAdapterDescription) AttachmentInformation(org.opentcs.drivers.vehicle.management.AttachmentInformation)

Aggregations

VehicleCommAdapterDescription (org.opentcs.drivers.vehicle.VehicleCommAdapterDescription)6 AttachmentInformation (org.opentcs.drivers.vehicle.management.AttachmentInformation)6 ItemEvent (java.awt.event.ItemEvent)4 List (java.util.List)4 Objects (java.util.Objects)4 Objects.requireNonNull (java.util.Objects.requireNonNull)4 Collectors (java.util.stream.Collectors)4 Nonnull (javax.annotation.Nonnull)4 Inject (javax.inject.Inject)4 DefaultCellEditor (javax.swing.DefaultCellEditor)4 Point (org.opentcs.data.model.Point)4 VehicleProcessModelTO (org.opentcs.drivers.vehicle.management.VehicleProcessModelTO)4 BoundsPopupMenuListener (org.opentcs.util.gui.BoundsPopupMenuListener)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Strings (com.google.common.base.Strings)2 EventQueue (java.awt.EventQueue)2 ActionEvent (java.awt.event.ActionEvent)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2