Search in sources :

Example 1 with ProcessModelEvent

use of org.opentcs.drivers.vehicle.management.ProcessModelEvent 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 ProcessModelEvent

use of org.opentcs.drivers.vehicle.management.ProcessModelEvent in project opentcs by openTCS.

the class DefaultVehicleController method handleProcessModelEvent.

@SuppressWarnings("unchecked")
private void handleProcessModelEvent(PropertyChangeEvent evt) {
    eventBus.onEvent(new ProcessModelEvent(evt.getPropertyName(), commAdapter.createTransferableProcessModel()));
    if (Objects.equals(evt.getPropertyName(), VehicleProcessModel.Attribute.POSITION.name())) {
        updateVehiclePosition((String) evt.getNewValue());
    } else if (Objects.equals(evt.getPropertyName(), VehicleProcessModel.Attribute.PRECISE_POSITION.name())) {
        updateVehiclePrecisePosition((Triple) evt.getNewValue());
    } else if (Objects.equals(evt.getPropertyName(), VehicleProcessModel.Attribute.ORIENTATION_ANGLE.name())) {
        vehicleService.updateVehicleOrientationAngle(vehicle.getReference(), (Double) evt.getNewValue());
    } else if (Objects.equals(evt.getPropertyName(), VehicleProcessModel.Attribute.ENERGY_LEVEL.name())) {
        vehicleService.updateVehicleEnergyLevel(vehicle.getReference(), (Integer) evt.getNewValue());
    } else if (Objects.equals(evt.getPropertyName(), VehicleProcessModel.Attribute.LOAD_HANDLING_DEVICES.name())) {
        vehicleService.updateVehicleLoadHandlingDevices(vehicle.getReference(), (List<LoadHandlingDevice>) evt.getNewValue());
    } else if (Objects.equals(evt.getPropertyName(), VehicleProcessModel.Attribute.STATE.name())) {
        updateVehicleState((Vehicle.State) evt.getNewValue());
    } else if (Objects.equals(evt.getPropertyName(), VehicleProcessModel.Attribute.COMMAND_EXECUTED.name())) {
        commandExecuted((MovementCommand) evt.getNewValue());
    } else if (Objects.equals(evt.getPropertyName(), VehicleProcessModel.Attribute.COMMAND_FAILED.name())) {
        dispatcherService.withdrawByVehicle(vehicle.getReference(), true);
    } else if (Objects.equals(evt.getPropertyName(), VehicleProcessModel.Attribute.USER_NOTIFICATION.name())) {
        notificationService.publishUserNotification((UserNotification) evt.getNewValue());
    } else if (Objects.equals(evt.getPropertyName(), VehicleProcessModel.Attribute.COMM_ADAPTER_EVENT.name())) {
        eventBus.onEvent((VehicleCommAdapterEvent) evt.getNewValue());
    } else if (Objects.equals(evt.getPropertyName(), VehicleProcessModel.Attribute.VEHICLE_PROPERTY.name())) {
        VehicleProcessModel.VehiclePropertyUpdate propUpdate = (VehicleProcessModel.VehiclePropertyUpdate) evt.getNewValue();
        vehicleService.updateObjectProperty(vehicle.getReference(), propUpdate.getKey(), propUpdate.getValue());
    } else if (Objects.equals(evt.getPropertyName(), VehicleProcessModel.Attribute.TRANSPORT_ORDER_PROPERTY.name())) {
        VehicleProcessModel.TransportOrderPropertyUpdate propUpdate = (VehicleProcessModel.TransportOrderPropertyUpdate) evt.getNewValue();
        if (currentDriveOrder != null) {
            vehicleService.updateObjectProperty(currentDriveOrder.getTransportOrder(), propUpdate.getKey(), propUpdate.getValue());
        }
    }
}
Also used : Triple(org.opentcs.data.model.Triple) LoadHandlingDevice(org.opentcs.drivers.vehicle.LoadHandlingDevice) Assertions.checkState(org.opentcs.util.Assertions.checkState) ProcessModelEvent(org.opentcs.drivers.vehicle.management.ProcessModelEvent) VehicleCommAdapterEvent(org.opentcs.drivers.vehicle.VehicleCommAdapterEvent) VehicleProcessModel(org.opentcs.drivers.vehicle.VehicleProcessModel)

Example 3 with ProcessModelEvent

use of org.opentcs.drivers.vehicle.management.ProcessModelEvent 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)

Example 4 with ProcessModelEvent

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

the class DetailPanel method onEvent.

@Override
public void onEvent(Object e) {
    // Ignore events if no vehicle entry is associated with this panel.
    if (vehicleEntry == null) {
        return;
    }
    if (e instanceof AttachmentEvent) {
        AttachmentEvent event = (AttachmentEvent) e;
        if (Objects.equals(vehicleEntry.getVehicleName(), event.getVehicleName())) {
            updateFromVehicleEntry(event);
        }
    }
    if (e instanceof ProcessModelEvent) {
        ProcessModelEvent event = (ProcessModelEvent) e;
        if (Objects.equals(vehicleEntry.getVehicleName(), event.getUpdatedProcessModel().getVehicleName())) {
            updateFromVehicleProcessModel(event);
            // Forward event to the comm adapter panels
            customPanelList.forEach(panel -> panel.processModelChange(event.getAttributeChanged(), event.getUpdatedProcessModel()));
        }
    }
}
Also used : ProcessModelEvent(org.opentcs.drivers.vehicle.management.ProcessModelEvent) AttachmentEvent(org.opentcs.drivers.vehicle.management.AttachmentEvent)

Example 5 with ProcessModelEvent

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

the class LocalVehicleEntryPool method onEvent.

@Override
public void onEvent(Object event) {
    if (event instanceof ProcessModelEvent) {
        ProcessModelEvent e = (ProcessModelEvent) event;
        LocalVehicleEntry entry = getEntryFor(e.getUpdatedProcessModel().getVehicleName());
        if (entry == null) {
            return;
        }
        entry.setProcessModel(e.getUpdatedProcessModel());
    } else if (event instanceof AttachmentEvent) {
        AttachmentEvent e = (AttachmentEvent) event;
        LocalVehicleEntry entry = getEntryFor(e.getVehicleName());
        if (entry == null) {
            return;
        }
        entry.setAttachmentInformation(e.getUpdatedAttachmentInformation());
    }
}
Also used : ProcessModelEvent(org.opentcs.drivers.vehicle.management.ProcessModelEvent) AttachmentEvent(org.opentcs.drivers.vehicle.management.AttachmentEvent)

Aggregations

ProcessModelEvent (org.opentcs.drivers.vehicle.management.ProcessModelEvent)7 AttachmentEvent (org.opentcs.drivers.vehicle.management.AttachmentEvent)6 VehicleCommAdapterFactory (org.opentcs.drivers.vehicle.VehicleCommAdapterFactory)2 AttachmentInformation (org.opentcs.drivers.vehicle.management.AttachmentInformation)2 VehicleProcessModelTO (org.opentcs.drivers.vehicle.management.VehicleProcessModelTO)2 Triple (org.opentcs.data.model.Triple)1 LoadHandlingDevice (org.opentcs.drivers.vehicle.LoadHandlingDevice)1 VehicleCommAdapterEvent (org.opentcs.drivers.vehicle.VehicleCommAdapterEvent)1 VehicleProcessModel (org.opentcs.drivers.vehicle.VehicleProcessModel)1 Assertions.checkState (org.opentcs.util.Assertions.checkState)1