diff --git a/openTCS-API-Base/src/main/java/org/opentcs/drivers/vehicle/BasicVehicleCommAdapter.java b/openTCS-API-Base/src/main/java/org/opentcs/drivers/vehicle/BasicVehicleCommAdapter.java index 9e96f1ec1..4b1d890ec 100644 --- a/openTCS-API-Base/src/main/java/org/opentcs/drivers/vehicle/BasicVehicleCommAdapter.java +++ b/openTCS-API-Base/src/main/java/org/opentcs/drivers/vehicle/BasicVehicleCommAdapter.java @@ -206,7 +206,7 @@ public VehicleProcessModelTO createTransferableProcessModel() { .setPrecisePosition(getProcessModel().getPrecisePosition()) .setPosition(getProcessModel().getPosition()) .setState(getProcessModel().getState()) - .setLength(getProcessModel().getLength()); + .setBoundingBox(getProcessModel().getBoundingBox()); } @Override diff --git a/openTCS-API-Base/src/main/java/org/opentcs/drivers/vehicle/VehicleProcessModel.java b/openTCS-API-Base/src/main/java/org/opentcs/drivers/vehicle/VehicleProcessModel.java index 49b0f8669..03cfd6f89 100644 --- a/openTCS-API-Base/src/main/java/org/opentcs/drivers/vehicle/VehicleProcessModel.java +++ b/openTCS-API-Base/src/main/java/org/opentcs/drivers/vehicle/VehicleProcessModel.java @@ -21,9 +21,11 @@ import java.util.Objects; import java.util.Queue; import org.opentcs.data.TCSObjectReference; +import org.opentcs.data.model.BoundingBox; import org.opentcs.data.model.Triple; import org.opentcs.data.model.Vehicle; import org.opentcs.data.notification.UserNotification; +import org.opentcs.util.annotations.ScheduledApiChange; /** * An observable model of a vehicle's and its comm adapter's attributes. @@ -94,9 +96,9 @@ public class VehicleProcessModel { */ private Vehicle.State state = Vehicle.State.UNKNOWN; /** - * The vehicle's current length. + * The vehicle's current bounding box. */ - private int length; + private BoundingBox boundingBox; /** * Creates a new instance. @@ -109,7 +111,7 @@ public VehicleProcessModel( ) { this.vehicle = requireNonNull(attachedVehicle, "attachedVehicle"); this.vehicleReference = vehicle.getReference(); - this.length = (int) vehicle.getBoundingBox().getLength(); + this.boundingBox = vehicle.getBoundingBox(); } /** @@ -471,24 +473,59 @@ else if (oldState == Vehicle.State.ERROR && newState != Vehicle.State.ERROR) { * Returns the vehicle's current length. * * @return The vehicle's current length. + * @deprecated Use {@link #getBoundingBox()} instead. */ + @Deprecated + @ScheduledApiChange(when = "7.0", details = "Will be removed.") public int getLength() { - return length; + return (int) boundingBox.getLength(); } /** * Sets the vehicle's current length. * * @param length The new length. + * @deprecated Use {@link #setBoundingBox(BoundingBox)} instead. */ + @Deprecated + @ScheduledApiChange(when = "7.0", details = "Will be removed.") public void setLength(int length) { - int oldValue = this.length; - this.length = length; + setBoundingBox(getBoundingBox().withLength(length)); + } + + /** + * Returns the vehicle's current bounding box. + * + * @return The vehicle's current bounding box. + */ + @Nonnull + public BoundingBox getBoundingBox() { + return boundingBox; + } + + /** + * Sets the vehicle's current bounding box. + * + * @param boundingBox The new bounding box. + */ + public void setBoundingBox( + @Nonnull + BoundingBox boundingBox + ) { + requireNonNull(boundingBox, "boundingBox"); + + BoundingBox oldValue = this.boundingBox; + this.boundingBox = boundingBox; getPropertyChangeSupport().firePropertyChange( - Attribute.LENGTH.name(), + Attribute.BOUNDING_BOX.name(), oldValue, - length + boundingBox + ); + getPropertyChangeSupport().firePropertyChange( + Attribute.LENGTH.name(), + oldValue.getLength(), + boundingBox.getLength() ); } @@ -752,7 +789,13 @@ public enum Attribute { /** * Indicates a change of the vehicle's length. */ + @Deprecated + @ScheduledApiChange(when = "7.0", details = "Will be removed.") LENGTH, + /** + * Indicates a change of the vehicle's bounding box. + */ + BOUNDING_BOX, /** * Indicates a new user notification was published. */ diff --git a/openTCS-API-Base/src/main/java/org/opentcs/drivers/vehicle/management/VehicleProcessModelTO.java b/openTCS-API-Base/src/main/java/org/opentcs/drivers/vehicle/management/VehicleProcessModelTO.java index 508314f82..e06cf4869 100644 --- a/openTCS-API-Base/src/main/java/org/opentcs/drivers/vehicle/management/VehicleProcessModelTO.java +++ b/openTCS-API-Base/src/main/java/org/opentcs/drivers/vehicle/management/VehicleProcessModelTO.java @@ -16,11 +16,13 @@ import java.util.ArrayList; import java.util.List; import java.util.Queue; +import org.opentcs.data.model.BoundingBox; import org.opentcs.data.model.Triple; import org.opentcs.data.model.Vehicle; import org.opentcs.data.notification.UserNotification; import org.opentcs.drivers.vehicle.LoadHandlingDevice; import org.opentcs.drivers.vehicle.VehicleProcessModel; +import org.opentcs.util.annotations.ScheduledApiChange; /** * A serializable representation of a {@link VehicleProcessModel}. @@ -43,7 +45,7 @@ public class VehicleProcessModelTO private int energyLevel; private List loadHandlingDevices = new ArrayList<>(); private Vehicle.State state = Vehicle.State.UNKNOWN; - private int length; + private BoundingBox boundingBox = new BoundingBox(1000, 1000, 1000); /** * Creates a new instance. @@ -164,12 +166,28 @@ public VehicleProcessModelTO setState( return this; } + @Deprecated + @ScheduledApiChange(when = "7.0", details = "Will be removed.") public int getLength() { - return length; + return (int) boundingBox.getLength(); } + @Deprecated + @ScheduledApiChange(when = "7.0", details = "Will be removed.") public VehicleProcessModelTO setLength(int length) { - this.length = length; + setBoundingBox(getBoundingBox().withLength(length)); + return this; + } + + public BoundingBox getBoundingBox() { + return boundingBox; + } + + public VehicleProcessModelTO setBoundingBox( + @Nonnull + BoundingBox boundingBox + ) { + this.boundingBox = requireNonNull(boundingBox, "boundingBox"); return this; } } diff --git a/openTCS-CommAdapter-Loopback/src/main/java/org/opentcs/virtualvehicle/LoopbackCommunicationAdapter.java b/openTCS-CommAdapter-Loopback/src/main/java/org/opentcs/virtualvehicle/LoopbackCommunicationAdapter.java index 00e56d070..b50a57ffc 100644 --- a/openTCS-CommAdapter-Loopback/src/main/java/org/opentcs/virtualvehicle/LoopbackCommunicationAdapter.java +++ b/openTCS-CommAdapter-Loopback/src/main/java/org/opentcs/virtualvehicle/LoopbackCommunicationAdapter.java @@ -162,11 +162,15 @@ public void propertyChange(PropertyChangeEvent evt) { if (!getProcessModel().getLoadHandlingDevices().isEmpty() && getProcessModel().getLoadHandlingDevices().get(0).isFull()) { loadState = LoadState.FULL; - getProcessModel().setLength(configuration.vehicleLengthLoaded()); + getProcessModel().setBoundingBox( + getProcessModel().getBoundingBox().withLength(configuration.vehicleLengthLoaded()) + ); } else { loadState = LoadState.EMPTY; - getProcessModel().setLength(configuration.vehicleLengthUnloaded()); + getProcessModel().setBoundingBox( + getProcessModel().getBoundingBox().withLength(configuration.vehicleLengthUnloaded()) + ); } } if (Objects.equals( diff --git a/openTCS-Kernel/src/main/java/org/opentcs/kernel/vehicles/DefaultVehicleController.java b/openTCS-Kernel/src/main/java/org/opentcs/kernel/vehicles/DefaultVehicleController.java index f6f378bbc..844d40585 100644 --- a/openTCS-Kernel/src/main/java/org/opentcs/kernel/vehicles/DefaultVehicleController.java +++ b/openTCS-Kernel/src/main/java/org/opentcs/kernel/vehicles/DefaultVehicleController.java @@ -39,6 +39,7 @@ import org.opentcs.data.ObjectUnknownException; import org.opentcs.data.TCSObjectEvent; import org.opentcs.data.TCSObjectReference; +import org.opentcs.data.model.BoundingBox; import org.opentcs.data.model.Location; import org.opentcs.data.model.Path; import org.opentcs.data.model.Point; @@ -285,7 +286,7 @@ public void initialize() { commAdapter.getProcessModel().getLoadHandlingDevices() ); updateVehicleState(commAdapter.getProcessModel().getState()); - updateVehicleLength(commAdapter.getProcessModel().getLength()); + updateVehicleBoundingBox(commAdapter.getProcessModel().getBoundingBox()); claimedResources.clear(); allocatedResources.clear(); @@ -985,8 +986,11 @@ else if (Objects.equals( else if (Objects.equals(evt.getPropertyName(), VehicleProcessModel.Attribute.STATE.name())) { updateVehicleState((Vehicle.State) evt.getNewValue()); } - else if (Objects.equals(evt.getPropertyName(), VehicleProcessModel.Attribute.LENGTH.name())) { - updateVehicleLength((int) evt.getNewValue()); + else if (Objects.equals( + evt.getPropertyName(), + VehicleProcessModel.Attribute.BOUNDING_BOX.name() + )) { + updateVehicleBoundingBox((BoundingBox) evt.getNewValue()); } else if (Objects.equals( evt.getPropertyName(), @@ -1170,7 +1174,7 @@ private void commandExecuted(MovementCommand executedCommand) { = ResourceMath.freeableResourceSetCount( SplitResources.from(allocatedResources, Set.of(currentVehiclePosition)) .getResourcesPassed(), - commAdapter.getProcessModel().getLength() + commAdapter.getProcessModel().getBoundingBox().getLength() ); for (int i = 0; i < freeableResourceSetCount; i++) { Set> oldResources = allocatedResources.poll(); @@ -1244,13 +1248,9 @@ private void updateVehicleState(Vehicle.State newState) { vehicleService.updateVehicleState(vehicle.getReference(), newState); } - private void updateVehicleLength(int newLength) { - vehicleService.updateVehicleBoundingBox( - vehicle.getReference(), - vehicleService.fetchObject(Vehicle.class, vehicle.getReference()) - .getBoundingBox() - .withLength(newLength) - ); + private void updateVehicleBoundingBox(BoundingBox newBoundingBox) { + requireNonNull(newBoundingBox, "newBoundingBox"); + vehicleService.updateVehicleBoundingBox(vehicle.getReference(), newBoundingBox); } /** diff --git a/openTCS-Kernel/src/main/java/org/opentcs/kernel/vehicles/ResourceMath.java b/openTCS-Kernel/src/main/java/org/opentcs/kernel/vehicles/ResourceMath.java index 87e653965..602f5ef64 100644 --- a/openTCS-Kernel/src/main/java/org/opentcs/kernel/vehicles/ResourceMath.java +++ b/openTCS-Kernel/src/main/java/org/opentcs/kernel/vehicles/ResourceMath.java @@ -42,7 +42,7 @@ private ResourceMath() { public static int freeableResourceSetCount( @Nonnull List>> resourcesPassed, - int vehicleLength + long vehicleLength ) { requireNonNull(resourcesPassed, "resourcesPassed"); checkArgument(vehicleLength > 0, "vehicleLength <= 0"); @@ -52,7 +52,7 @@ public static int freeableResourceSetCount( List>> reversedPassedResources = new ArrayList<>(resourcesPassed); Collections.reverse(reversedPassedResources); - int remainingRequiredLength = vehicleLength; + long remainingRequiredLength = vehicleLength; int result = 0; for (Set> curSet : reversedPassedResources) { if (remainingRequiredLength > 0) { @@ -66,11 +66,10 @@ public static int freeableResourceSetCount( return result; } - private static int requiredLength(Set> resources) { + private static long requiredLength(Set> resources) { return resources.stream() .filter(resource -> resource instanceof Path) .mapToLong(resource -> ((Path) resource).getLength()) - .mapToInt(length -> (int) length) .sum(); }