Initial commit
Some checks failed
Gradle Build / build (push) Has been cancelled

This commit is contained in:
CaiXiang
2024-11-30 18:36:13 +08:00
commit aa56926258
2134 changed files with 232943 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
apply from: "${rootDir}/gradle/java-project.gradle"
apply from: "${rootDir}/gradle/java-codequality.gradle"
apply from: "${rootDir}/gradle/publishing-java.gradle"
dependencies {
api project(':opentcs-api-base')
api group: 'jakarta.xml.bind', name: 'jakarta.xml.bind-api', version: '2.3.3'
api group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.9'
implementation group: 'org.semver4j', name: 'semver4j', version: '5.4.0'
}
processResources.doLast {
// Write a properties file with the build version and date.
def props = new Properties()
props.setProperty('opentcs.version', version)
props.setProperty('opentcs.builddate', project.ext.buildDate)
new File(sourceSets.main.output.resourcesDir, 'opentcs.properties').withWriter() {
props.store(it, null)
}
}
task release {
dependsOn build
}

View File

@@ -0,0 +1,40 @@
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.wrapAnnotationArgs=WRAP_IF_LONG
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineMethodParams=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.wrapAfterDotInChainedMethodCalls=false
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineDisjunctiveCatchTypes=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineFor=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineImplements=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.wrapFor=WRAP_IF_LONG
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.sortMembersByVisibility=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.visibilityOrder=PUBLIC;PROTECTED;DEFAULT;PRIVATE
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeFinallyOnNewLine=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.wrapMethodParams=WRAP_IF_LONG
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.enable-indent=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineArrayInit=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineCallArgs=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.wrapDisjunctiveCatchTypes=WRAP_IF_LONG
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.keepGettersAndSettersTogether=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.wrapExtendsImplementsList=WRAP_ALWAYS
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.wrapThrowsKeyword=WRAP_ALWAYS
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.wrapExtendsImplementsKeyword=WRAP_ALWAYS
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.classMembersOrder=STATIC FIELD;FIELD;STATIC_INIT;CONSTRUCTOR;INSTANCE_INIT;STATIC METHOD;METHOD;STATIC CLASS;CLASS
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.wrapEnumConstants=WRAP_ALWAYS
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.wrapCommentText=false
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.wrapThrowsList=WRAP_IF_LONG
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.wrapAssert=WRAP_IF_LONG
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.importGroupsOrder=*
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.continuationIndentSize=4
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeElseOnNewLine=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.placeCatchOnNewLine=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineAnnotationArgs=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineTryResources=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.preserveNewLinesInComments=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineParenthesized=true
netbeans.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.alignMultilineThrows=true
netbeans.org-netbeans-modules-editor-indent.CodeStyle.project.text-line-wrap=none
netbeans.org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width=2
netbeans.org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab=2
netbeans.org-netbeans-modules-editor-indent.CodeStyle.project.tab-size=2
netbeans.org-netbeans-modules-editor-indent.CodeStyle.project.text-limit-width=100
netbeans.org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs=true
netbeans.org-netbeans-modules-editor-indent.CodeStyle.usedProfile=project

View File

@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.common;
/**
* Defines the modes in which an application may be in.
*/
public enum ClientConnectionMode {
/**
* The application SHOULD be connected/online.
*/
ONLINE,
/**
* The application SHOULD be disconnected/offline.
*/
OFFLINE
}

View File

@@ -0,0 +1,197 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.common;
import static java.util.Objects.requireNonNull;
import jakarta.inject.Inject;
import java.util.List;
import java.util.ResourceBundle;
import javax.swing.JOptionPane;
import org.opentcs.access.KernelRuntimeException;
import org.opentcs.access.KernelServicePortal;
import org.opentcs.customizations.ApplicationEventBus;
import org.opentcs.util.I18nCommon;
import org.opentcs.util.event.EventHandler;
import org.opentcs.util.gui.dialog.ConnectToServerDialog;
import org.opentcs.util.gui.dialog.ConnectionParamSet;
import org.opentcs.util.gui.dialog.NullConnectionParamSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The default implementation of {@link PortalManager}, providing a single
* {@link KernelServicePortal}.
*/
public class DefaultPortalManager
implements
PortalManager {
/**
* This class's logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(DefaultPortalManager.class);
/**
* This class's resource bundle.
*/
private static final ResourceBundle BUNDLE
= ResourceBundle.getBundle(I18nCommon.BUNDLE_PATH);
/**
* The handler to send events to.
*/
private final EventHandler eventHandler;
/**
* The connection bookmarks to use.
*/
private final List<ConnectionParamSet> connectionBookmarks;
/**
* The service portal instance we are working with.
*/
private final KernelServicePortal servicePortal;
/**
* The last successfully established connection.
*/
private ConnectionParamSet lastConnection = new NullConnectionParamSet();
/**
* The current connection. {@link NullConnectionParamSet}, if no connection is currently
* established.
*/
private ConnectionParamSet currentConnection = new NullConnectionParamSet();
/**
* Creates a new instance.
*
* @param servicePortal The service portal instance we a working with.
* @param eventHandler The handler to send events to.
* @param connectionBookmarks The connection bookmarks to use.
*/
@Inject
public DefaultPortalManager(
KernelServicePortal servicePortal,
@ApplicationEventBus
EventHandler eventHandler,
List<ConnectionParamSet> connectionBookmarks
) {
this.eventHandler = requireNonNull(eventHandler, "eventHandler");
this.servicePortal = requireNonNull(servicePortal, "servicePortal");
this.connectionBookmarks = requireNonNull(connectionBookmarks, "connectionBookmarks");
}
@Override
public boolean connect(ConnectionMode mode) {
if (isConnected()) {
return true;
}
switch (mode) {
case AUTO:
if (connectionBookmarks.isEmpty()) {
LOG.info("Cannot connect automatically. No connection bookmarks available.");
return false;
}
ConnectionParamSet paramSet = connectionBookmarks.get(0);
return connect(paramSet.getDescription(), paramSet.getHost(), paramSet.getPort());
case MANUAL:
return connectWithDialog();
case RECONNECT:
if (lastConnection instanceof NullConnectionParamSet) {
LOG.info("Cannot reconnect. No portal we were previously connected to.");
return false;
}
return connect(
lastConnection.getDescription(),
lastConnection.getHost(),
lastConnection.getPort()
);
default:
LOG.warn("Unhandled connection mode '{}'. Not connecting.", mode.name());
return false;
}
}
@Override
public void disconnect() {
if (!isConnected()) {
return;
}
eventHandler.onEvent(ConnectionState.DISCONNECTING);
try {
servicePortal.logout();
}
catch (KernelRuntimeException e) {
LOG.warn("Exception trying to disconnect from remote portal", e);
}
lastConnection = currentConnection;
currentConnection = new NullConnectionParamSet();
eventHandler.onEvent(ConnectionState.DISCONNECTED);
}
@Override
public boolean isConnected() {
return !(currentConnection instanceof NullConnectionParamSet);
}
@Override
public KernelServicePortal getPortal() {
return servicePortal;
}
@Override
public String getDescription() {
return currentConnection.getDescription();
}
@Override
public String getHost() {
return currentConnection.getHost();
}
@Override
public int getPort() {
return currentConnection.getPort();
}
/**
* Tries to establish a connection to the portal.
*
* @param host The name of the host running the kernel/portal.
* @param port The port to connect to.
* @return {@code true} if, and only if, the connection was established successfully.
*/
private boolean connect(String description, String host, int port) {
try {
eventHandler.onEvent(ConnectionState.CONNECTING);
servicePortal.login(host, port);
}
catch (KernelRuntimeException e) {
LOG.warn("Failed to connect to remote portal", e);
eventHandler.onEvent(ConnectionState.DISCONNECTED);
JOptionPane.showMessageDialog(
null,
BUNDLE.getString("connectToServerDialog.optionPane_noConnection.message"),
BUNDLE.getString("connectToServerDialog.optionPane_noConnection.message"),
JOptionPane.ERROR_MESSAGE
);
// Retry connection attempt
return connectWithDialog();
}
currentConnection = new ConnectionParamSet(description, host, port);
eventHandler.onEvent(ConnectionState.CONNECTED);
return true;
}
private boolean connectWithDialog() {
ConnectToServerDialog dialog = new ConnectToServerDialog(connectionBookmarks);
dialog.setVisible(true);
if (dialog.getReturnStatus() == ConnectToServerDialog.RET_OK) {
return connect(dialog.getDescription(), dialog.getHost(), dialog.getPort());
}
return false;
}
}

View File

@@ -0,0 +1,18 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.common;
/**
* Defines the credentials for a guest user account.
*/
public interface GuestUserCredentials {
/**
* The default/guest user name.
*/
String USER = "Alice";
/**
* The default/guest password.
*/
String PASSWORD = "xyz";
}

View File

@@ -0,0 +1,33 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.common;
import org.opentcs.components.Lifecycle;
/**
* Provides methods used in a kernel client application's context.
*/
public interface KernelClientApplication
extends
Lifecycle {
/**
* Tells the application to switch its state to online.
*
* @param autoConnect Whether to connect automatically to the kernel or to show a connect dialog
* when going online.
*/
void online(boolean autoConnect);
/**
* Tells the application to switch its state to offline.
*/
void offline();
/**
* Checks whether the application's state is online.
*
* @return Whether the application's state is online.
*/
boolean isOnline();
}

View File

@@ -0,0 +1,82 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.common;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.RunnableScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Extends the {@link ScheduledThreadPoolExecutor} by logging exceptions thrown by scheduled tasks.
*/
public class LoggingScheduledThreadPoolExecutor
extends
ScheduledThreadPoolExecutor {
/**
* This class's logger.
*/
private static final Logger LOG
= LoggerFactory.getLogger(LoggingScheduledThreadPoolExecutor.class);
/**
* Creates a new instance.
*
* @param corePoolSize The number of threads to keep in the pool.
* @param threadFactory The factory to use when the executor creates a new thread.
* @throws IllegalArgumentException If {@code corePoolSize < 0}
* @throws NullPointerException If {@code threadFactory} is null
*/
public LoggingScheduledThreadPoolExecutor(int corePoolSize, ThreadFactory threadFactory) {
super(corePoolSize, threadFactory);
}
@Override
protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t);
if (t == null && r instanceof Future<?>) {
try {
Future<?> future = (Future<?>) r;
if (future.isDone()) {
future.get();
}
else if (isPeriodic(future)) {
// Periodic futures will never be done
return;
}
else {
LOG.debug("Future was not done: {}", future);
}
}
catch (ExecutionException ee) {
LOG.warn("Unhandled exception in executed task", ee.getCause());
}
catch (CancellationException ce) {
LOG.debug("Task was cancelled", ce);
}
catch (InterruptedException ie) {
LOG.debug("Interrupted during Future.get()", ie);
// Ignore/Reset
Thread.currentThread().interrupt();
}
}
if (t != null) {
LOG.error("Abrupt termination", t);
}
}
private boolean isPeriodic(Future<?> future) {
if (future instanceof RunnableScheduledFuture<?>) {
RunnableScheduledFuture<?> runnableFuture = (RunnableScheduledFuture<?>) future;
if (runnableFuture.isPeriodic()) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,45 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.common;
/**
* This interface provides access to vehicle-property keys that are used in both the
* plant overview as well as in the kernel.
*/
public interface LoopbackAdapterConstants {
/**
* The key of the vehicle property that specifies the vehicle's initial position.
*/
String PROPKEY_INITIAL_POSITION = "loopback:initialPosition";
/**
* The key of the vehicle property that specifies the default operating time.
*/
String PROPKEY_OPERATING_TIME = "loopback:operatingTime";
/**
* The key of the vehicle property that specifies which operation loads the load handling device.
*/
String PROPKEY_LOAD_OPERATION = "loopback:loadOperation";
/**
* The default value of the load operation property.
*/
String PROPVAL_LOAD_OPERATION_DEFAULT = "Load cargo";
/**
* The key of the vehicle property that specifies which operation unloads the load handling
* device.
*/
String PROPKEY_UNLOAD_OPERATION = "loopback:unloadOperation";
/**
* The default value of the unload operation property.
*/
String PROPVAL_UNLOAD_OPERATION_DEFAULT = "Unload cargo";
/**
* The key of the vehicle property that specifies the maximum acceleration of a vehicle.
*/
String PROPKEY_ACCELERATION = "loopback:acceleration";
/**
* The key of the vehicle property that specifies the maximum decceleration of a vehicle.
*/
String PROPKEY_DECELERATION = "loopback:deceleration";
}

View File

@@ -0,0 +1,104 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.common;
import org.opentcs.access.KernelServicePortal;
import org.opentcs.components.kernel.services.ServiceUnavailableException;
/**
* Declares methods for managing a connection to a remote portal.
*/
public interface PortalManager {
/**
* Tries to establish a connection to the portal.
*
* @param mode The mode to use for the connection attempt.
* @return {@code true} if, and only if, the connection was established successfully.
*/
boolean connect(ConnectionMode mode);
/**
* Tells the portal manager the connection to the portal was lost.
*/
void disconnect();
/**
* Checks whether a connection to the portal is established.
*
* @return {@code true} if, and only if, a connection to the portal is established.
*/
boolean isConnected();
/**
* Returns the remote kernel client portal the manager is working with.
*
* @return The remote kernel client portal.
*/
KernelServicePortal getPortal();
/**
* Returns a description for the current connection.
*
* @return A description for the current connection.
*/
String getDescription();
/**
* Returns the host currently connected to.
*
* @return The host currently connected to, or {@code null}, if not connected.
*/
String getHost();
/**
* Returns the port currently connected to.
*
* @return The port currently connected to, or {@code -1}, if not connected.
*/
int getPort();
/**
* Defines the states in which a portal manager instance may be in.
*/
enum ConnectionState {
/**
* Indicates the portal manager is trying to connect to the remote portal.
*/
CONNECTING,
/**
* Indicates the portal is connected and logged in to a remote portal, thus in a usable state.
*/
CONNECTED,
/**
* Indicates the portal is disconnecting from the remote portal.
*/
DISCONNECTING,
/**
* Indicates the portal is not connected to a remote portal.
* While in this state, calls to the portal's service methods will result in a
* {@link ServiceUnavailableException}.
*/
DISCONNECTED;
}
/**
* Defines the modes a portal manager uses to establish a connection to a portal.
*/
enum ConnectionMode {
/**
* Connect automatically by using a predefined set of connection parameters.
*/
AUTO,
/**
* Connect manually by showing a dialog allowing to enter connection parameters.
*/
MANUAL,
/**
* Connect to the portal we were previously connected to.
*/
RECONNECT;
}
}

View File

@@ -0,0 +1,150 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.common;
import static java.util.Objects.requireNonNull;
import static org.opentcs.util.Assertions.checkArgument;
import static org.opentcs.util.Assertions.checkState;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
/**
* An executor service that executes all task directly on the same thread.
*/
public class SameThreadExecutorService
implements
ExecutorService {
private boolean shutdown;
public SameThreadExecutorService() {
shutdown = false;
}
@Override
public void shutdown() {
shutdown = true;
}
@Override
public List<Runnable> shutdownNow() {
shutdown = true;
return List.of();
}
@Override
public boolean isShutdown() {
return shutdown;
}
@Override
public boolean isTerminated() {
return shutdown;
}
@Override
public boolean awaitTermination(long timeout, TimeUnit unit)
throws InterruptedException {
// Calling `awaitTermination` before calling shutdown is not a valid use for an executor
// service and therefore should throw an exeception.
checkState(shutdown, "Awaiting termination before shutdown was called");
return true;
}
@Override
public <T> Future<T> submit(Callable<T> task) {
CompletableFuture<T> future = new CompletableFuture<>();
try {
future.complete(task.call());
}
catch (Exception e) {
future.completeExceptionally(e);
}
return future;
}
@Override
public <T> Future<T> submit(Runnable task, T result) {
return this.submit(() -> {
task.run();
return result;
});
}
@Override
public Future<?> submit(Runnable task) {
return this.submit(task, null);
}
@Override
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
throws InterruptedException {
return tasks.stream()
.map(task -> submit(task))
.collect(Collectors.toList());
}
@Override
public <T> List<Future<T>> invokeAll(
Collection<? extends Callable<T>> tasks,
long timeout,
TimeUnit unit
)
throws InterruptedException {
return invokeAll(tasks);
}
@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
throws InterruptedException,
ExecutionException {
requireNonNull(tasks, "tasks");
checkArgument(tasks.isEmpty(), "tasks is empty");
if (tasks.stream().anyMatch(task -> task == null)) {
throw new NullPointerException("At least one task given is null");
}
// This implementation interprets the method documentation so that all tasks are started
// before the result of the first successful one is returned.
// Since all task are executed directly on the same thread, all task will finish before this
// method returns the value of any successful task.
List<Future<T>> futures = invokeAll(tasks);
for (Future<T> future : futures) {
try {
return future.get();
}
catch (InterruptedException e) {
throw e;
}
catch (Exception e) {
// any other exception thrown by the future is ignored
}
}
throw new ExecutionException(new Exception("None of the provided task sucessfully terminated"));
}
@Override
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
throws InterruptedException,
ExecutionException,
TimeoutException {
return invokeAny(tasks);
}
@Override
public void execute(Runnable command) {
command.run();
}
}

View File

@@ -0,0 +1,24 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.common.peripherals;
import org.opentcs.drivers.peripherals.PeripheralCommAdapterDescription;
/**
* A {@link PeripheralCommAdapterDescription} for no comm adapter.
*/
public class NullPeripheralCommAdapterDescription
extends
PeripheralCommAdapterDescription {
/**
* Creates a new instance.
*/
public NullPeripheralCommAdapterDescription() {
}
@Override
public String getDescription() {
return "-";
}
}

View File

@@ -0,0 +1,60 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.awt.Color;
/**
* Provides utilty methods for working with colors.
*/
public class Colors {
/**
* Prevents instantiation of this utility class.
*/
private Colors() {
}
/**
* Returns a hexadecimal representation of the given color in the RGB color space.
* <p>
* The pattern of the strings returned by this method is {@code "#RRGGBB"}.
* </p>
*
* @param color The color to be encoded.
* @return The representation of the given color.
*/
@Nonnull
public static String encodeToHexRGB(
@Nonnull
Color color
) {
requireNonNull(color, "color");
return String.format("#%06X", color.getRGB() & 0x00FFFFFF);
}
/**
* Returns a {@code Color} instance described by the given hexadecimal representation.
*
* @param rgbHex The hexadecimal representation of the color to be returned in the RGB color
* space.
*
* @return A {@code Color} instance described by the given value.
* @throws NumberFormatException If the given string cannot be parsed.
*/
@Nonnull
public static Color decodeFromHexRGB(
@Nonnull
String rgbHex
)
throws NumberFormatException {
requireNonNull(rgbHex, "rgbHex");
return Color.decode(rgbHex);
}
}

View File

@@ -0,0 +1,71 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util;
import java.util.Comparator;
import org.opentcs.data.TCSObject;
import org.opentcs.data.TCSObjectReference;
import org.opentcs.data.order.TransportOrder;
import org.opentcs.data.peripherals.PeripheralJob;
/**
* Some commonly used comparator implementations.
*/
public final class Comparators {
/**
* Prevents undesired instantiation.
*/
private Comparators() {
}
/**
* Returns a comparator for sorting <code>TCSObject</code>s lexicographically by their names.
*
* @return A comparator for sorting <code>TCSObject</code>s lexicographically by their names.
*/
public static Comparator<TCSObject<?>> objectsByName() {
return Comparator.comparing(TCSObject::getName);
}
/**
* Returns a comparator for sorting <code>TCSObjectReference</code>s lexicographically by their
* names.
*
* @return A comparator for sorting <code>TCSObjectReference</code>s lexicographically by their
* names.
*/
public static Comparator<TCSObjectReference<?>> referencesByName() {
return Comparator.comparing(TCSObjectReference::getName);
}
/**
* A comparator for sorting transport orders by their deadlines, with the most urgent ones coming
* first.
* Transport orders are sorted by their deadlines first; if two orders have exactly the same
* deadline, they are sorted by their (unique) creation times, with the older one coming first.
*
* @return A comparator for sorting transport orders by their deadlines.
*/
public static Comparator<TransportOrder> ordersByDeadline() {
return Comparator.comparing(TransportOrder::getDeadline).thenComparing(ordersByAge());
}
/**
* A comparator for sorting transport orders by their age, with the oldest ones coming first.
*
* @return A comparator for sorting transport orders by their age.
*/
public static Comparator<TransportOrder> ordersByAge() {
return Comparator.comparing(TransportOrder::getCreationTime).thenComparing(objectsByName());
}
/**
* A comparator for sorting peripheral jobs by their age, with the oldest ones coming first.
*
* @return A comparator for sorting peripheral jobs by their age.
*/
public static Comparator<PeripheralJob> jobsByAge() {
return Comparator.comparing(PeripheralJob::getCreationTime).thenComparing(objectsByName());
}
}

View File

@@ -0,0 +1,144 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Provides generic information about the openTCS environment.
*/
public final class Environment {
/**
* The baseline properties file.
*/
private static final String BASELINE_PROPS_FILE = "/opentcs.properties";
/**
* The customization properties file.
*/
private static final String CUSTOMIZATION_PROPS_FILE = "/opentcs-customization.properties";
/**
* The openTCS baseline version as a string.
*/
private static final String BASELINE_VERSION;
/**
* The build date of the openTCS baseline as a string.
*/
private static final String BASELINE_BUILD_DATE;
/**
* The name of the customized distribution.
*/
private static final String CUSTOMIZATION_NAME;
/**
* The version of the customized distribution as a string.
*/
private static final String CUSTOMIZATION_VERSION;
/**
* The build date of the customized distribution as a string.
*/
private static final String CUSTOMIZATION_BUILD_DATE;
/**
* This class's Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(Environment.class);
static {
Properties props = new Properties();
try {
InputStream inStream = Environment.class.getResourceAsStream(BASELINE_PROPS_FILE);
if (inStream != null) {
props.load(inStream);
}
inStream = Environment.class.getResourceAsStream(CUSTOMIZATION_PROPS_FILE);
if (inStream != null) {
props.load(inStream);
}
}
catch (IOException exc) {
throw new IllegalStateException("Could not load environment properties", exc);
}
BASELINE_VERSION = props.getProperty("opentcs.version", "unknown version");
BASELINE_BUILD_DATE = props.getProperty("opentcs.builddate", "unknown build date");
CUSTOMIZATION_NAME = props.getProperty("opentcs.customization.name", "-");
CUSTOMIZATION_VERSION = props.getProperty("opentcs.customization.version", "-");
CUSTOMIZATION_BUILD_DATE = props.getProperty("opentcs.customization.builddate", "-");
}
/**
* Prevents undesired instantiation.
*/
private Environment() {
}
/**
* Returns the version of openTCS (i.e. the base library) as a string.
*
* @return The version of openTCS (i.e. the base library) as a string.
*/
public static String getBaselineVersion() {
return BASELINE_VERSION;
}
/**
* Returns the build date of openTCS (i.e. the base library) as a string.
*
* @return The build date of openTCS (i.e. the base library) as a string.
*/
public static String getBaselineBuildDate() {
return BASELINE_BUILD_DATE;
}
/**
* Returns the name of the customized distribution.
*
* @return The name of the customized distribution.
*/
public static String getCustomizationName() {
return CUSTOMIZATION_NAME;
}
/**
* Returns the version of the customized distribution as a string.
*
* @return The version of the customized distribution as a string.
*/
public static String getCustomizationVersion() {
return CUSTOMIZATION_VERSION;
}
/**
* Returns the build date of the customized distribution as a string.
*
* @return The build date of the customized distribution as a string.
*/
public static String getCustomizationBuildDate() {
return CUSTOMIZATION_BUILD_DATE;
}
/**
* Write information about the OpenTCS version, the operating system and
* the running Java VM to the log.
*/
public static void logSystemInfo() {
LOG.info(
"openTCS baseline version: {} (build date: {}), "
+ "customization '{}' version {} (build date: {}), "
+ "Java: {}, {}; JVM: {}, {}; OS: {}, {}",
BASELINE_VERSION,
BASELINE_BUILD_DATE,
CUSTOMIZATION_NAME,
CUSTOMIZATION_VERSION,
CUSTOMIZATION_BUILD_DATE,
System.getProperty("java.version"),
System.getProperty("java.vendor"),
System.getProperty("java.vm.version"),
System.getProperty("java.vm.vendor"),
System.getProperty("os.name"),
System.getProperty("os.arch")
);
}
}

View File

@@ -0,0 +1,51 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util;
import static java.util.Objects.requireNonNull;
import java.io.File;
/**
* This class provides helper methods for working with file systems.
*/
public final class FileSystems {
/**
* Prevents creation of instances.
*/
private FileSystems() {
}
/**
* Recursively deletes a given file/directory.
*
* @param target The file/directory to be deleted recursively.
* @return <code>true</code> if deleting the target was successful, else
* <code>false</code>.
*/
public static boolean deleteRecursively(File target) {
requireNonNull(target, "target");
// If the target is a directory, remove its contents first.
if (target.isDirectory()) {
File[] entries = target.listFiles();
for (File curEntry : entries) {
boolean successful;
if (curEntry.isDirectory()) {
successful = deleteRecursively(curEntry);
}
else {
successful = curEntry.delete();
}
if (!successful) {
return false;
}
}
}
return target.delete();
}
}

View File

@@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util;
/**
* Defines constants regarding internationalization.
*/
public interface I18nCommon {
/**
* The path to the project's resource bundle.
*/
String BUNDLE_PATH = "i18n/org/opentcs/common/Bundle";
}

View File

@@ -0,0 +1,111 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util;
import static java.util.Objects.requireNonNull;
import static org.opentcs.util.Assertions.checkInRange;
/**
* Provides methods for optimized parsing of numbers from character sequences.
*/
public final class NumberParsers {
/**
* The number of characters used for <code>Long.MAX_VALUE</code>.
*/
private static final int MAX_POSITIVE_LONG_CHARS = Long.toString(Long.MAX_VALUE).length();
/**
* The number of characters used for <code>Long.MIN_VALUE</code>.
*/
private static final int MAX_NEGATIVE_LONG_CHARS = Long.toString(Long.MIN_VALUE).length();
/**
* Prevents creation of instances of this class.
*/
private NumberParsers() {
}
/**
* Parses a sequence of characters as a decimal number and returns the latter.
*
* @param source The character sequence to be parsed.
* @return The decimal number represented by the given character sequence.
* @throws NumberFormatException If the parsed sequence of characters does not
* represent a decimal number.
*/
public static long parsePureDecimalLong(CharSequence source)
throws NumberFormatException {
return parsePureDecimalLong(source, 0, source.length());
}
/**
* Parses a (sub)sequence of characters as a decimal number and returns the
* latter.
*
* @param source The character sequence to be parsed.
* @param startIndex The position at which to start parsing.
* @param length The number of characters to parse.
* @return The decimal number represented by the given character sequence.
* @throws NumberFormatException If the parsed sequence of characters does not
* represent a decimal number.
*/
public static long parsePureDecimalLong(
CharSequence source,
int startIndex,
int length
)
throws NumberFormatException {
requireNonNull(source, "source");
checkInRange(startIndex, 0, source.length() - 1, "startIndex");
checkInRange(length, 1, Integer.MAX_VALUE, "length");
long result = 0;
int index = 0;
boolean negative;
long limit;
// Check if we have a negative number and initialize accordingly.
if (source.charAt(startIndex) == '-') {
if (length > MAX_NEGATIVE_LONG_CHARS) {
throw new NumberFormatException("too long to be parsed");
}
negative = true;
limit = Long.MIN_VALUE;
index++;
}
else {
if (length > MAX_POSITIVE_LONG_CHARS) {
throw new NumberFormatException("too long to be parsed");
}
negative = false;
limit = -Long.MAX_VALUE;
}
while (index < length) {
int digit = source.charAt(startIndex + index) - '0';
// If we've just read something other than a digit, throw an exception.
if (digit < 0 || digit > 9) {
throw new NumberFormatException(
"not a decimal digit: " + source.charAt(startIndex + index)
);
}
result *= 10;
// Check if the next operation would overflow the result.
if (result < limit + digit) {
throw new NumberFormatException(
"parsed number exceeds value boundaries"
);
}
result -= digit;
index++;
}
if (negative) {
// If we did not parse at least one digit, throw an exception.
if (index < 2) {
throw new NumberFormatException("minus sign without succeeding digits");
}
return result;
}
else {
return -result;
}
}
}

View File

@@ -0,0 +1,197 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util;
import static java.util.Objects.requireNonNull;
import static org.opentcs.util.Assertions.checkArgument;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.SortedSet;
import java.util.TreeSet;
/**
* Provides a way to acquire unique strings.
*
* @param <S> The type of the selectors/keys to be used for mapping to name
* patterns.
*/
public class UniqueStringGenerator<S> {
/**
* Configured name patterns.
*/
private final Map<S, NamePattern> namePatterns = new HashMap<>();
/**
* All strings known to this generator, sorted lexicographically.
*/
private final SortedSet<String> existingStrings = new TreeSet<>();
/**
* Creates a new instance without any name patterns.
*/
public UniqueStringGenerator() {
// Do nada.
}
/**
* Registers a name pattern for the given selector.
*
* @param selector The selector.
* @param prefix The prefix of names to be used for the given selector.
* @param suffixPattern The suffix pattern to be used for the given selector.
*/
public void registerNamePattern(
S selector,
String prefix,
String suffixPattern
) {
namePatterns.put(selector, new NamePattern(prefix, suffixPattern));
}
/**
* Adds a String to those known by this generator. As a result, this generator
* will never return a String that is equal to the given one.
*
* @param newString The string to be added.
*/
public void addString(final String newString) {
requireNonNull(newString, "newString is null");
existingStrings.add(newString);
}
/**
* Makes this generator forget a known String. As a result, this generator
* might return a String that is equal to the given one in the future.
*
* @param rmString The string to be forgotten.
*/
public void removeString(final String rmString) {
requireNonNull(rmString, "rmString is null");
existingStrings.remove(rmString);
}
/**
* Returns true if this generator has this string.
*
* @param str The string to test.
* @return true if this generator already has this string.
*/
public boolean hasString(String str) {
return existingStrings.contains(str);
}
/**
* Removes all known Strings.
*/
public void clear() {
existingStrings.clear();
}
/**
* Returns a string that is unique among all strings registered with this
* generator.
*
* @param selector A selector for the name pattern to be used.
* @return A string that is unique among all strings registered with this
* generator.
*/
public String getUniqueString(S selector) {
requireNonNull(selector, "selector");
NamePattern namePattern = namePatterns.get(selector);
checkArgument(namePattern != null, "Unknown selector: %s", selector);
return getUniqueString(namePattern.prefix, namePattern.suffixPattern);
}
/**
* Returns a String that is unique among all known Strings in this generator.
* The returned String will consist of the given prefix followed by an integer
* formatted according to the given pattern. The pattern has to be of the form
* understood by <code>java.text.DecimalFormat</code>.
*
* @param prefix The prefix of the String to be generated.
* @param suffixPattern A pattern describing the suffix of the generated
* String. Must be of the form understood by
* <code>java.text.DecimalFormat</code>.
* @return A String that is unique among all known Strings.
*/
public String getUniqueString(
final String prefix,
final String suffixPattern
) {
requireNonNull(suffixPattern, "suffixPattern is null");
final String actualPrefix = prefix == null ? "" : prefix;
final DecimalFormat format = new DecimalFormat(suffixPattern);
final String lBound = actualPrefix + "0";
final String uBound = actualPrefix + ":";
final int prefixLength = actualPrefix.length();
long maxSuffixValue = 0;
// Get all existing strings with the same prefix and at least one digit
// following it.
for (String curName : existingStrings.subSet(lBound, uBound)) {
// Check if the suffix contains only digits.
boolean allDigits = containsOnlyDigits(curName.substring(prefixLength));
// If the suffix contains only digits, parse it and remember the maximum
// suffix value we found so far. (If the suffix contains other characters,
// ignore this string - we generate suffixes with digits only, so there
// can't be a collision.
if (allDigits) {
final long curSuffixValue = NumberParsers.parsePureDecimalLong(
curName, prefixLength, curName.length() - prefixLength
);
maxSuffixValue
= maxSuffixValue > curSuffixValue ? maxSuffixValue : curSuffixValue;
}
}
// Increment the highest value found and use that as the suffix
return actualPrefix + format.format(maxSuffixValue + 1);
}
/**
* Checks if the given string contains only (decimal) digits.
*
* @param input The string to be checked.
* @return <code>true</code> if, and only if, the given string contains only
* (decimal) digits.
*/
private boolean containsOnlyDigits(String input) {
assert input != null;
for (int i = 0; i < input.length(); i++) {
int digit = input.charAt(i) - '0';
if (digit < 0 || digit > 9) {
return false;
}
}
return true;
}
/**
* A name pattern.
*/
private static class NamePattern {
/**
* The prefix to be used.
*/
private final String prefix;
/**
* The suffix pattern to be used.
*/
private final String suffixPattern;
/**
* Creates a new instance.
*
* @param prefix The prefix to be used.
* @param suffixPattern The suffix pattern to be used.
*/
private NamePattern(String prefix, String suffixPattern) {
this.prefix = requireNonNull(prefix, "prefix");
this.suffixPattern = requireNonNull(suffixPattern, "suffixPattern");
}
}
}

View File

@@ -0,0 +1,138 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.gui;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Point;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import javax.swing.plaf.basic.BasicComboPopup;
/**
* Changes the bounds of a JComboBox's popup menu to allow the popup to be wieder than the combo
* box.
* Register it with a combo box using
* {@link JComboBox#addPopupMenuListener(javax.swing.event.PopupMenuListener)}.
*
* <p>
* This class will only work for a JComboBox that uses a BasicComboPop.
* </p>
*/
public class BoundsPopupMenuListener
implements
PopupMenuListener {
/**
* The scrollpane of the combobox.
*/
private JScrollPane scrollPane;
/**
* General purpose constructor to set all popup properties at once.
*
*/
public BoundsPopupMenuListener() {
}
/**
* Alter the bounds of the popup just before it is made visible.
*
* @param e The event.
*/
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
JComboBox<?> comboBox = (JComboBox) e.getSource();
if (comboBox.getItemCount() == 0) {
return;
}
final Object child = comboBox.getAccessibleContext().getAccessibleChild(0);
if (child instanceof BasicComboPopup) {
SwingUtilities.invokeLater(() -> customizePopup((BasicComboPopup) child));
}
}
@Override
public void popupMenuCanceled(PopupMenuEvent e) {
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
// In its normal state the scrollpane does not have a scrollbar
if (scrollPane != null) {
scrollPane.setHorizontalScrollBar(null);
}
}
protected void customizePopup(BasicComboPopup popup) {
scrollPane = getScrollPane(popup);
popupWider(popup);
// For some reason in JDK7 the popup will not display at its preferred
// width unless its location has been changed from its default
// (ie. for normal "pop down" shift the popup and reset)
Component comboBox = popup.getInvoker();
Point location = comboBox.getLocationOnScreen();
int height = comboBox.getSize().height;
popup.setLocation(location.x, location.y + height - 1);
popup.setLocation(location.x, location.y + height);
}
/**
* Adjusts the width of the scrollpane used by the popup.
*
* @param popup The popup.
*/
protected void popupWider(BasicComboPopup popup) {
JList<?> list = popup.getList();
// Determine the maximimum width to use:
// a) determine the popup preferred width
// b) ensure width is not less than the scroll pane width
int popupWidth = list.getPreferredSize().width
+ 5 // make sure horizontal scrollbar doesn't appear
+ getScrollBarWidth(popup, scrollPane);
Dimension scrollPaneSize = scrollPane.getPreferredSize();
popupWidth = Math.max(popupWidth, scrollPaneSize.width);
// Adjust the width
scrollPaneSize.width = popupWidth;
scrollPane.setPreferredSize(scrollPaneSize);
scrollPane.setMaximumSize(scrollPaneSize);
}
/**
* Returns the scroll pane used by the popup so its bounds can be adjusted.
*
* @param popup The popup.
* @return The scroll pane used by the popup .
*/
protected JScrollPane getScrollPane(BasicComboPopup popup) {
JList<?> list = popup.getList();
Container c = SwingUtilities.getAncestorOfClass(JScrollPane.class, list);
return (JScrollPane) c;
}
protected int getScrollBarWidth(BasicComboPopup popup, JScrollPane scrollPane) {
// I can't find any property on the scrollBar to determine if it will be
// displayed or not so use brute force to determine this.
JComboBox<?> comboBox = (JComboBox) popup.getInvoker();
if (comboBox.getItemCount() > comboBox.getMaximumRowCount()) {
return scrollPane.getVerticalScrollBar().getPreferredSize().width;
}
else {
return 0;
}
}
}

View File

@@ -0,0 +1,62 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.gui;
import java.awt.Image;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Static methods related to window icons.
*/
public final class Icons {
/**
* This class's logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(Icons.class);
/**
* Path to the openTCS window icons.
*/
private static final String ICON_PATH = "/org/opentcs/util/gui/res/icons/";
/**
* File names of the openTCS window icons.
*/
private static final String[] ICON_FILES = {"opentcs_icon_016.png",
"opentcs_icon_032.png",
"opentcs_icon_064.png",
"opentcs_icon_128.png",
"opentcs_icon_256.png"};
/**
* Prevents instantiation.
*/
private Icons() {
// Do nada.
}
/**
* Get the icon for OpenTCS windows in different resolutions.
*
* @return List of icons
*/
public static List<Image> getOpenTCSIcons() {
try {
List<Image> icons = new ArrayList<>();
for (String iconFile : ICON_FILES) {
String iconURL = ICON_PATH + iconFile;
final Image icon = ImageIO.read(Icons.class.getResource(iconURL));
icons.add(icon);
}
return icons;
}
catch (IOException | IllegalArgumentException exc) {
LOG.warn("Couldn't load icon images from path {}", ICON_PATH, exc);
return new ArrayList<>();
}
}
}

View File

@@ -0,0 +1,61 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.gui;
import static java.util.Objects.requireNonNull;
import java.awt.Component;
import java.util.function.Function;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
/**
* Renders values to JLabels.
*
* @param <E> The type of the values to be rendered.
*/
public class StringListCellRenderer<E>
implements
ListCellRenderer<E> {
/**
* A default renderer for creating the label.
*/
private final DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
/**
* Returns a String representation of E.
*/
private final Function<E, String> representer;
/**
* Creates an instance.
*
* @param representer a string representation provider for the values of the list.
* Null value as parameter for the representer is possible.
* The result is set as text of the JLabel.
*/
public StringListCellRenderer(Function<E, String> representer) {
this.representer = requireNonNull(representer, "representer");
}
@Override
public Component getListCellRendererComponent(
JList<? extends E> list,
E value,
int index,
boolean isSelected,
boolean cellHasFocus
) {
JLabel label = (JLabel) defaultRenderer.getListCellRendererComponent(
list,
value,
index,
isSelected,
cellHasFocus
);
label.setText(representer.apply(value));
return label;
}
}

View File

@@ -0,0 +1,61 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.gui;
import static java.util.Objects.requireNonNull;
import java.awt.Component;
import java.util.function.Function;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
/**
* Renders values to JLabels.
*
* @param <E> The type of the table cell values that the representer can represent.
*/
public class StringTableCellRenderer<E>
implements
TableCellRenderer {
/**
* The default renderer we delegate to.
*/
private final DefaultTableCellRenderer delegate = new DefaultTableCellRenderer();
/**
* Returns a String representation of E.
*/
private final Function<E, String> representer;
/**
* Creates an instance.
*
* @param representer a string representation provider for the values of the list.
* Null value as parameter for the representer is possible.
* The result is set as text of the JLabel.
*/
public StringTableCellRenderer(Function<E, String> representer) {
this.representer = requireNonNull(representer, "representer");
}
@Override
public Component getTableCellRendererComponent(
JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column
) {
JLabel label = (JLabel) delegate.getTableCellRendererComponent(
table,
value,
isSelected,
hasFocus,
row,
column
);
@SuppressWarnings("unchecked")
E val = (E) value;
label.setText(representer.apply(val));
return label;
}
}

View File

@@ -0,0 +1,52 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.gui.dialog;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.KeyStroke;
/**
* Cancel Button which closes a dialog by pressing ESC.
*/
public class CancelButton
extends
JButton {
/**
* Creates a new instance.
*/
public CancelButton() {
this(null);
}
/**
* Creates a new instance.
*
* @param text Label of this button.
*/
@SuppressWarnings("this-escape")
public CancelButton(String text) {
super(text);
ActionListener al = new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
String cmd = event.getActionCommand();
if (cmd.equals("PressedESCAPE")) {
doClick();
}
}
};
registerKeyboardAction(
al, "PressedESCAPE",
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
JButton.WHEN_IN_FOCUSED_WINDOW
);
}
}

View File

@@ -0,0 +1,204 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
<Property name="title" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="i18n/org/opentcs/common/Bundle.properties" key="connectToServerDialog.title" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,0,-97,0,0,0,-29"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Component class="javax.swing.JLabel" name="labelDescription">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
<FontInfo relative="true">
<Font component="labelDescription" property="font" relativeSize="true" size="0"/>
</FontInfo>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="i18n/org/opentcs/common/Bundle.properties" key="connectToServerDialog.label_description.text" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="8" insetsBottom="0" insetsRight="4" anchor="17" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JTextField" name="textFieldDescription">
<Properties>
<Property name="columns" type="int" value="15"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
<FontInfo relative="true">
<Font component="textFieldDescription" property="font" relativeSize="true" size="0"/>
</FontInfo>
</Property>
<Property name="text" type="java.lang.String" value="Localhost"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="0" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="0" insetsBottom="0" insetsRight="8" anchor="17" weightX="0.0" weightY="1.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="labelServer">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
<FontInfo relative="true">
<Font component="labelServer" property="font" relativeSize="true" size="0"/>
</FontInfo>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="i18n/org/opentcs/common/Bundle.properties" key="connectToServerDialog.label_host.text" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="1" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="8" insetsBottom="0" insetsRight="4" anchor="17" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JTextField" name="textFieldServer">
<Properties>
<Property name="columns" type="int" value="15"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
<FontInfo relative="true">
<Font component="textFieldServer" property="font" relativeSize="true" size="0"/>
</FontInfo>
</Property>
<Property name="text" type="java.lang.String" value="localhost"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="1" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="0" insetsBottom="0" insetsRight="8" anchor="17" weightX="0.0" weightY="1.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JLabel" name="labelPort">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
<FontInfo relative="true">
<Font component="labelPort" property="font" relativeSize="true" size="0"/>
</FontInfo>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="i18n/org/opentcs/common/Bundle.properties" key="connectToServerDialog.label_port.text" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="2" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="0" insetsLeft="8" insetsBottom="0" insetsRight="4" anchor="17" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JTextField" name="textFieldPort">
<Properties>
<Property name="columns" type="int" value="15"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
<FontInfo relative="true">
<Font component="textFieldPort" property="font" relativeSize="true" size="0"/>
</FontInfo>
</Property>
<Property name="text" type="java.lang.String" value="1099"/>
</Properties>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="2" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="0" insetsBottom="0" insetsRight="8" anchor="17" weightX="0.0" weightY="1.0"/>
</Constraint>
</Constraints>
</Component>
<Container class="javax.swing.JPanel" name="panelButtons">
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="4" gridWidth="2" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="4" insetsBottom="4" insetsRight="4" anchor="20" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout"/>
<SubComponents>
<Component class="javax.swing.JButton" name="okButton">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
<FontInfo relative="true">
<Font bold="true" component="okButton" property="font" relativeSize="true" size="0"/>
</FontInfo>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="i18n/org/opentcs/common/Bundle.properties" key="connectToServerDialog.button_ok.text" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="okButtonActionPerformed"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="0" gridWidth="1" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="4" insetsBottom="4" insetsRight="4" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JButton" name="cancelButton">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
<FontInfo relative="true">
<Font component="cancelButton" property="font" relativeSize="true" size="0"/>
</FontInfo>
</Property>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="i18n/org/opentcs/common/Bundle.properties" key="connectToServerDialog.button_cancle.text" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cancelButtonActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new CancelButton()"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="0" gridWidth="2" gridHeight="1" fill="0" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="4" insetsBottom="4" insetsRight="4" anchor="18" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JComboBox" name="cbComboBox">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Arial" size="11" style="0"/>
</Property>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="0"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbComboBoxActionPerformed"/>
</Events>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;ConnectionParamSet&gt;"/>
</AuxValues>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="1" gridY="3" gridWidth="1" gridHeight="1" fill="2" ipadX="0" ipadY="0" insetsTop="4" insetsLeft="0" insetsBottom="0" insetsRight="8" anchor="11" weightX="0.0" weightY="1.0"/>
</Constraint>
</Constraints>
</Component>
</SubComponents>
</Form>

View File

@@ -0,0 +1,355 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.gui.dialog;
import static java.util.Objects.requireNonNull;
import java.rmi.registry.Registry;
import java.util.List;
import java.util.ResourceBundle;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import org.opentcs.util.I18nCommon;
import org.opentcs.util.gui.Icons;
/**
* A dialog that lets the user enter parameters for a connection to the portal.
*/
public class ConnectToServerDialog
extends
JDialog {
/**
* A return status code - returned if Cancel button has been pressed.
*/
public static final int RET_CANCEL = 0;
/**
* A return status code - returned if OK button has been pressed.
*/
public static final int RET_OK = 1;
/**
* This class's resource bundle.
*/
private static final ResourceBundle BUNDLE
= ResourceBundle.getBundle(I18nCommon.BUNDLE_PATH);
/**
* The connection's description.
*/
private String description;
/**
* The host to connect to.
*/
private String host;
/**
* The port to connect to.
*/
private int port;
/**
* The list of connection param sets.
*/
private final List<ConnectionParamSet> paramSets;
/**
* This dialog's return status code.
*/
private int returnStatus = RET_CANCEL;
/**
* Creates a new instance.
*
* @param paramSets The list of connection param sets.
*/
@SuppressWarnings("this-escape")
public ConnectToServerDialog(List<ConnectionParamSet> paramSets) {
super((JFrame) null, true);
this.paramSets = requireNonNull(paramSets, "paramSets");
initComponents();
initConnectionBookmarks();
if (paramSets.isEmpty()) {
description = "Localhost";
host = "localhost";
port = Registry.REGISTRY_PORT;
}
else {
description = paramSets.get(0).getDescription();
host = paramSets.get(0).getHost();
port = paramSets.get(0).getPort();
}
textFieldDescription.setText(description);
textFieldServer.setText(host);
textFieldPort.setText(String.valueOf(port));
getRootPane().setDefaultButton(okButton);
setIconImages(Icons.getOpenTCSIcons());
setLocationRelativeTo(null);
pack();
}
public String getDescription() {
return description;
}
public int getPort() {
return port;
}
public String getHost() {
return host;
}
/**
* Returns the return status of this dialog.
*
* @return the return status of this dialog - one of {@link #RET_OK} or {@link #RET_CANCEL}.
*/
public int getReturnStatus() {
return returnStatus;
}
private void doClose(int retStatus) {
returnStatus = retStatus;
setVisible(false);
dispose();
}
/**
* Initializes connection bookmarks from the config file.
*/
private void initConnectionBookmarks() {
DefaultComboBoxModel<ConnectionParamSet> model
= (DefaultComboBoxModel<ConnectionParamSet>) cbComboBox.getModel();
for (ConnectionParamSet bookmark : paramSets) {
model.addElement(bookmark);
}
}
// FORMATTER:OFF
// CHECKSTYLE:OFF
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
labelDescription = new javax.swing.JLabel();
textFieldDescription = new javax.swing.JTextField();
labelServer = new javax.swing.JLabel();
textFieldServer = new javax.swing.JTextField();
labelPort = new javax.swing.JLabel();
textFieldPort = new javax.swing.JTextField();
panelButtons = new javax.swing.JPanel();
okButton = new javax.swing.JButton();
cancelButton = new CancelButton();
cbComboBox = new javax.swing.JComboBox<>();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("i18n/org/opentcs/common/Bundle"); // NOI18N
setTitle(bundle.getString("connectToServerDialog.title")); // NOI18N
getContentPane().setLayout(new java.awt.GridBagLayout());
labelDescription.setFont(labelDescription.getFont());
labelDescription.setText(bundle.getString("connectToServerDialog.label_description.text")); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 8, 0, 4);
getContentPane().add(labelDescription, gridBagConstraints);
textFieldDescription.setColumns(15);
textFieldDescription.setFont(textFieldDescription.getFont());
textFieldDescription.setText("Localhost");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 8);
getContentPane().add(textFieldDescription, gridBagConstraints);
labelServer.setFont(labelServer.getFont());
labelServer.setText(bundle.getString("connectToServerDialog.label_host.text")); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 8, 0, 4);
getContentPane().add(labelServer, gridBagConstraints);
textFieldServer.setColumns(15);
textFieldServer.setFont(textFieldServer.getFont());
textFieldServer.setText("localhost");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 8);
getContentPane().add(textFieldServer, gridBagConstraints);
labelPort.setFont(labelPort.getFont());
labelPort.setText(bundle.getString("connectToServerDialog.label_port.text")); // NOI18N
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.insets = new java.awt.Insets(0, 8, 0, 4);
getContentPane().add(labelPort, gridBagConstraints);
textFieldPort.setColumns(15);
textFieldPort.setFont(textFieldPort.getFont());
textFieldPort.setText("1099");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 8);
getContentPane().add(textFieldPort, gridBagConstraints);
panelButtons.setLayout(new java.awt.GridBagLayout());
okButton.setFont(okButton.getFont().deriveFont(okButton.getFont().getStyle() | java.awt.Font.BOLD));
okButton.setText(bundle.getString("connectToServerDialog.button_ok.text")); // NOI18N
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 0;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
panelButtons.add(okButton, gridBagConstraints);
cancelButton.setFont(cancelButton.getFont());
cancelButton.setText(bundle.getString("connectToServerDialog.button_cancle.text")); // NOI18N
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 0;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
panelButtons.add(cancelButton, gridBagConstraints);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 4;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_END;
gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
getContentPane().add(panelButtons, gridBagConstraints);
cbComboBox.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
cbComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbComboBoxActionPerformed(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 3;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
gridBagConstraints.weighty = 1.0;
gridBagConstraints.insets = new java.awt.Insets(4, 0, 0, 8);
getContentPane().add(cbComboBox, gridBagConstraints);
pack();
}// </editor-fold>//GEN-END:initComponents
// CHECKSTYLE:ON
// FORMATTER:ON
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
description = textFieldDescription.getText();
if (description.isEmpty()) {
JOptionPane.showMessageDialog(
this,
BUNDLE.getString("connectToServerDialog.optionPane_invalidDescription.message"),
BUNDLE.getString("connectToServerDialog.optionPane_invalidDescription.title"),
JOptionPane.ERROR_MESSAGE
);
return;
}
host = textFieldServer.getText();
if (host.isEmpty()) {
JOptionPane.showMessageDialog(
this,
BUNDLE.getString("connectToServerDialog.optionPane_invalidHost.message"),
BUNDLE.getString("connectToServerDialog.optionPane_invalidHost.title"),
JOptionPane.ERROR_MESSAGE
);
return;
}
try {
port = Integer.parseInt(textFieldPort.getText());
if (port < 0 || port > 65535) {
throw new NumberFormatException();
}
}
catch (NumberFormatException e) {
JOptionPane.showMessageDialog(
this,
BUNDLE.getString("connectToServerDialog.optionPane_invalidPort.message"),
BUNDLE.getString("connectToServerDialog.optionPane_invalidPort.title"),
JOptionPane.ERROR_MESSAGE
);
return;
}
doClose(RET_OK);
}//GEN-LAST:event_okButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
doClose(RET_CANCEL);
}//GEN-LAST:event_cancelButtonActionPerformed
private void cbComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbComboBoxActionPerformed
DefaultComboBoxModel<ConnectionParamSet> model
= (DefaultComboBoxModel<ConnectionParamSet>) cbComboBox.getModel();
ConnectionParamSet cb = (ConnectionParamSet) model.getSelectedItem();
if (cb != null) {
textFieldDescription.setText(cb.getDescription());
textFieldServer.setText(cb.getHost());
textFieldPort.setText(String.valueOf(cb.getPort()));
}
}//GEN-LAST:event_cbComboBoxActionPerformed
// FORMATTER:OFF
// CHECKSTYLE:OFF
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JComboBox<ConnectionParamSet> cbComboBox;
private javax.swing.JLabel labelDescription;
private javax.swing.JLabel labelPort;
private javax.swing.JLabel labelServer;
private javax.swing.JButton okButton;
private javax.swing.JPanel panelButtons;
private javax.swing.JTextField textFieldDescription;
private javax.swing.JTextField textFieldPort;
private javax.swing.JTextField textFieldServer;
// End of variables declaration//GEN-END:variables
// CHECKSTYLE:ON
// FORMATTER:OFF
}

View File

@@ -0,0 +1,134 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.gui.dialog;
import static java.util.Objects.requireNonNull;
import static org.opentcs.util.Assertions.checkArgument;
import static org.opentcs.util.Assertions.checkInRange;
import java.rmi.registry.Registry;
import java.util.Objects;
/**
* A set of parameters for a connection to the portal.
*/
public class ConnectionParamSet {
/**
* The description.
*/
private final String description;
/**
* The host name.
*/
private final String host;
/**
* The port number.
*/
private final int port;
/**
* Creates a new instance.
*
* @param description The description for this connection.
* @param host The host to be used.
* @param port The port number to be used.
* @throws IllegalArgumentException If the port number is out of the range of valid port numbers.
*/
public ConnectionParamSet(String description, String host, int port) {
this.description = requireNonNull(description, "description");
this.host = requireNonNull(host);
this.port = checkInRange(port, 0, 65535, "port");
}
/**
* Creates a new instance.
*
* @param description The description for this connection.
* @param host The host to be used.
* @param port The port number to be used.
* @throws NumberFormatException If the port string does not contain a parseable port number.
* @throws IllegalArgumentException If the port number is out of the range of valid port numbers.
*/
public ConnectionParamSet(String description, String host, String port)
throws NumberFormatException,
IllegalArgumentException {
this(description, host, Integer.parseInt(port));
}
/**
* Creates a new instance with the description, host and port parsed from the given string, which
* must follow a pattern of "description:host:port".
*
* @param paramString The string containing the description, host and port.
*/
public ConnectionParamSet(String paramString) {
requireNonNull(paramString, "paramString");
String[] split = paramString.split("\\|", 3);
checkArgument(
split.length == 3,
"Could not parse input as 'description:host:port': %s",
paramString
);
this.description = split[0];
this.host = split[1];
this.port = checkInRange(Integer.parseInt(split[2]), 0, 65535, "port");
}
/**
* Creates a new instance for host "localhost" and port 1099.
*/
public ConnectionParamSet() {
this("Localhost", "localhost", Registry.REGISTRY_PORT);
}
/**
* Returns the description.
*
* @return The description.
*/
public String getDescription() {
return description;
}
/**
* Returns the host parameter.
*
* @return The host parameter.
*/
public String getHost() {
return host;
}
/**
* Returns the port parameter.
*
* @return The port parameter.
*/
public int getPort() {
return port;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof ConnectionParamSet)) {
return false;
}
ConnectionParamSet other = (ConnectionParamSet) o;
return description.equals(other.description) && host.equals(other.host) && port == other.port;
}
@Override
public int hashCode() {
int hash = 7;
hash = 23 * hash + Objects.hashCode(this.description);
hash = 23 * hash + Objects.hashCode(this.host);
hash = 23 * hash + this.port;
return hash;
}
@Override
public String toString() {
return getDescription() + " - " + getHost() + ":" + getPort();
}
}

View File

@@ -0,0 +1,15 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.gui.dialog;
/**
* A connection param set used for not established connections.
*/
public class NullConnectionParamSet
extends
ConnectionParamSet {
public NullConnectionParamSet() {
super("-", "", 0);
}
}

View File

@@ -0,0 +1,6 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
/**
* Supportive classes for graphical frontends.
*/
package org.opentcs.util.gui;

View File

@@ -0,0 +1,85 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.logging;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
/**
* A <code>Formatter</code> for <code>LogRecord</code>s that formats messages
* for output on a single line (except when a <code>Throwable</code> is
* associated with the <code>LogRecord</code>.
*/
public class SingleLineFormatter
extends
Formatter {
/**
* A <code>DateFormat</code> instance for formatting timestamps.
*/
private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd-HH:mm:ss-SSS");
/**
* A <code>Date</code> instance for formatting timestamps.
*/
private final Date date = new Date();
/**
* Line separator for wrapping lines at the end of log messages.
*/
private final String lineSeparator = System.getProperty("line.separator");
/**
* Creates a new SingleLineFormatter.
*/
public SingleLineFormatter() {
}
@Override
public synchronized String format(LogRecord record) {
date.setTime(record.getMillis());
StringBuilder result = new StringBuilder();
result.append('[')
.append(DATE_FORMAT.format(date))
.append("] ")
.append(String.format("%1$-7.7s", record.getLevel().getName()))
.append(' ')
.append(String.format("%1$-20s", Thread.currentThread().getName()))
.append(' ')
.append(String.format("%1$-55s", source(record)))
.append(": ")
.append(formatMessage(record))
.append(lineSeparator);
if (record.getThrown() != null) {
result.append(stackTrace(record.getThrown()));
result.append(lineSeparator);
}
return result.toString();
}
private String source(LogRecord record) {
return record.getSourceClassName() != null
? record.getSourceClassName()
.replaceAll("\\B\\w+(\\.[a-z])", "$1") + "." + record.getSourceMethodName() + "()"
: record.getLoggerName();
}
private String stackTrace(Throwable thrown) {
try (StringWriter sWriter = new StringWriter();
PrintWriter pWriter = new PrintWriter(sWriter)) {
thrown.printStackTrace(pWriter);
pWriter.flush();
return sWriter.toString();
}
catch (IOException exc) {
throw new IllegalStateException("Could not print stack trace for log output", exc);
}
}
}

View File

@@ -0,0 +1,43 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.logging;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* An UncaughtExceptionHandler that logs everything not caught and then exits.
*/
public class UncaughtExceptionLogger
implements
Thread.UncaughtExceptionHandler {
/**
* This class's Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(UncaughtExceptionLogger.class);
/**
* A flag indicating whether to exit on uncaught exceptions or not.
*/
private final boolean doExit;
/**
* Creates a new UncaughtExceptionLogger.
*
* @param exitOnException A flag indicating whether to exit on uncaught
* exceptions or not.
*/
public UncaughtExceptionLogger(boolean exitOnException) {
super();
doExit = exitOnException;
}
@Override
public void uncaughtException(Thread t, Throwable e) {
// Log the exception, and then get out of here.
LOG.error("Unhandled exception", e);
if (doExit) {
System.exit(1);
}
}
}

View File

@@ -0,0 +1,6 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
/**
* Utility classes extending basic logging features.
*/
package org.opentcs.util.logging;

View File

@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlTransient;
/**
* The base class for a plant model transfer object.
*/
@XmlTransient
@XmlAccessorType(XmlAccessType.PROPERTY)
public class BasePlantModelTO {
private String version = "";
/**
* Creates a new instance.
*/
public BasePlantModelTO() {
}
@XmlAttribute(required = true)
public String getVersion() {
return version;
}
public BasePlantModelTO setVersion(
@Nonnull
String version
) {
requireNonNull(version, "version");
this.version = version;
return this;
}
}

View File

@@ -0,0 +1,99 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
import org.opentcs.access.to.model.PlantModelCreationTO;
import org.opentcs.util.persistence.v6.V6ModelParser;
import org.opentcs.util.persistence.v6.V6PlantModelTO;
import org.opentcs.util.persistence.v6.V6TOMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Provides methods for parsing {@link PlantModelCreationTO}s from/to a file.
*/
public class ModelParser {
/**
* This class's logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(ModelParser.class);
/**
* The charset to use for the reader/writer.
*/
private static final Charset CHARSET = Charset.forName("UTF-8");
/**
* Creates a new instance.
*/
public ModelParser() {
}
/**
* Reads a model from the given file and parses it to a {@link PlantModelCreationTO} instance.
*
* @param file The model file to read.
* @return The parsed {@link PlantModelCreationTO}.
* @throws IOException If there was an error reading the model file.
* @throws IllegalArgumentException If there is no parser for the version of the model file.
*/
public PlantModelCreationTO readModel(File file)
throws IOException {
String modelVersion = peekModelVersion(file);
LOG.debug("File '{}' contains a model version '{}'.", file.getAbsolutePath(), modelVersion);
try (Reader reader = new BufferedReader(
new InputStreamReader(
new FileInputStream(file),
CHARSET
)
)) {
return new V6ModelParser().read(reader, modelVersion);
}
}
/**
* Writes the given {@link PlantModelCreationTO} to the given file.
*
* @param model The model.
* @param file The file to write the model to.
* @throws IOException If there was an error writing to the model file.
*/
public void writeModel(PlantModelCreationTO model, File file)
throws IOException {
try (Writer writer = new BufferedWriter(
new OutputStreamWriter(
new FileOutputStream(file),
CHARSET
)
)) {
V6TOMapper mapper = new V6TOMapper();
V6PlantModelTO mappedModel = mapper.map(model);
mappedModel.toXml(writer);
}
}
private String peekModelVersion(File file)
throws IOException {
try (Reader reader = new BufferedReader(
new InputStreamReader(
new FileInputStream(file),
CHARSET
)
)) {
return ProbePlantModelTO.fromXml(reader).getVersion();
}
}
}

View File

@@ -0,0 +1,66 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.io.IOException;
import java.io.Reader;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.xml.sax.SAXException;
/**
* Allows reading a model file to access basic information (such as the model version) for
* validation purposes.
*/
@XmlRootElement(name = "model")
@XmlAccessorType(XmlAccessType.PROPERTY)
public class ProbePlantModelTO
extends
BasePlantModelTO {
/**
* Creates a new instance.
*/
public ProbePlantModelTO() {
}
/**
* Unmarshals an instance of this class from the given XML representation.
*
* @param reader Provides the XML representation to parse to an instance.
* @return The instance unmarshalled from the given reader.
* @throws IOException If there was a problem unmarshalling the given string.
*/
public static ProbePlantModelTO fromXml(
@Nonnull
Reader reader
)
throws IOException {
requireNonNull(reader, "reader");
try {
return (ProbePlantModelTO) createUnmarshaller().unmarshal(reader);
}
catch (JAXBException | SAXException exc) {
throw new IOException("Exception unmarshalling data", exc);
}
}
private static Unmarshaller createUnmarshaller()
throws JAXBException,
SAXException {
return createContext().createUnmarshaller();
}
private static JAXBContext createContext()
throws JAXBException {
return JAXBContext.newInstance(ProbePlantModelTO.class);
}
}

View File

@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AllowedOperationTO
extends
PlantModelElementTO {
/**
* Creates a new instance.
*/
public AllowedOperationTO() {
}
}

View File

@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AllowedPeripheralOperationTO
extends
PlantModelElementTO {
/**
* Creates a new instance.
*/
public AllowedPeripheralOperationTO() {
}
}

View File

@@ -0,0 +1,99 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"name", "type", "members", "properties", "blockLayout"})
public class BlockTO
extends
PlantModelElementTO {
private String type = "SINGLE_VEHICLE_ONLY";
private List<MemberTO> members = new ArrayList<>();
private BlockLayout blockLayout = new BlockLayout();
/**
* Creates a new instance.
*/
public BlockTO() {
}
@XmlAttribute(required = true)
public String getType() {
return type;
}
public BlockTO setType(
@Nonnull
String type
) {
requireNonNull(type, "type");
this.type = type;
return this;
}
@XmlElement(name = "member")
public List<MemberTO> getMembers() {
return members;
}
public BlockTO setMembers(
@Nonnull
List<MemberTO> members
) {
requireNonNull(members, "members");
this.members = members;
return this;
}
@XmlElement(required = true)
public BlockLayout getBlockLayout() {
return blockLayout;
}
public BlockTO setBlockLayout(
@Nonnull
BlockLayout blockLayout
) {
this.blockLayout = requireNonNull(blockLayout, "blockLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class BlockLayout {
private String color = "";
/**
* Creates a new instance.
*/
public BlockLayout() {
}
@XmlAttribute(required = true)
public String getColor() {
return color;
}
public BlockLayout setColor(
@Nonnull
String color
) {
this.color = requireNonNull(color, "color");
return this;
}
}
}

View File

@@ -0,0 +1,53 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import java.util.Comparator;
/**
* Some comparator implementations for JAXB classes.
*/
public final class Comparators {
/**
* Prevents instantiation.
*/
private Comparators() {
}
/**
* Returns a comparator for ordering <code>PlantModelElementTO</code>s ascendingly by their names.
*
* @return A comparator for ordering <code>PlantModelElementTO</code>s ascendingly by their names.
*/
public static Comparator<PlantModelElementTO> elementsByName() {
return Comparator.comparing(PlantModelElementTO::getName);
}
/**
* Returns a comparator for ordering <code>OutgoingPath</code>s ascendingly by their names.
*
* @return A comparator for ordering <code>OutgoingPath</code>s ascendingly by their names.
*/
public static Comparator<PointTO.OutgoingPath> outgoingPathsByName() {
return Comparator.comparing(PointTO.OutgoingPath::getName);
}
/**
* Returns a comparator for ordering <code>Link</code>s ascendingly by their point names.
*
* @return A comparator for ordering <code>Link</code>s ascendingly by their point names.
*/
public static Comparator<LocationTO.Link> linksByPointName() {
return Comparator.comparing(LocationTO.Link::getPoint);
}
/**
* Returns a comparator for ordering <code>Properties</code>s ascendingly by their names.
*
* @return A comparator for ordering <code>Properties</code> ascendingly by their names.
*/
public static Comparator<PropertyTO> propertiesByName() {
return Comparator.comparing(PropertyTO::getName);
}
}

View File

@@ -0,0 +1,50 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"x", "y"})
public class CoupleTO {
private Long x;
private Long y;
public CoupleTO() {
}
@XmlAttribute(required = true)
public Long getX() {
return x;
}
public CoupleTO setX(
@Nonnull
Long x
) {
this.x = requireNonNull(x, "x");
return this;
}
@XmlAttribute(required = true)
public Long getY() {
return y;
}
public CoupleTO setY(
@Nonnull
Long y
) {
this.y = requireNonNull(y, "y");
return this;
}
}

View File

@@ -0,0 +1,259 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"name", "xPosition", "yPosition", "zPosition", "links", "locked",
"properties", "locationLayout"}
)
public class LocationTO
extends
PlantModelElementTO {
private Long xPosition = 0L;
private Long yPosition = 0L;
private Long zPosition = 0L;
private String type = "";
private List<Link> links = new ArrayList<>();
private Boolean locked = false;
private LocationLayout locationLayout = new LocationLayout();
/**
* Creates a new instance.
*/
public LocationTO() {
}
@XmlAttribute
public Long getxPosition() {
return xPosition;
}
public LocationTO setxPosition(
@Nonnull
Long xPosition
) {
requireNonNull(xPosition, "xPosition");
this.xPosition = xPosition;
return this;
}
@XmlAttribute
public Long getyPosition() {
return yPosition;
}
public LocationTO setyPosition(
@Nonnull
Long yPosition
) {
requireNonNull(yPosition, "yPosition");
this.yPosition = yPosition;
return this;
}
@XmlAttribute
public Long getzPosition() {
return zPosition;
}
public LocationTO setzPosition(
@Nonnull
Long zPosition
) {
requireNonNull(zPosition, "zPosition");
this.zPosition = zPosition;
return this;
}
@XmlAttribute
public String getType() {
return type;
}
public LocationTO setType(
@Nonnull
String type
) {
requireNonNull(type, "type");
this.type = type;
return this;
}
@XmlElement(name = "link", required = true)
public List<Link> getLinks() {
return links;
}
public LocationTO setLinks(
@Nonnull
List<Link> links
) {
requireNonNull(links, "links");
this.links = links;
return this;
}
@XmlAttribute(required = true)
public Boolean isLocked() {
return locked;
}
public LocationTO setLocked(Boolean locked) {
this.locked = locked;
return this;
}
@XmlElement(required = true)
public LocationLayout getLocationLayout() {
return locationLayout;
}
public LocationTO setLocationLayout(
@Nonnull
LocationLayout locationLayout
) {
this.locationLayout = requireNonNull(locationLayout, "locationLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"point", "allowedOperations"})
public static class Link {
private String point = "";
private List<AllowedOperationTO> allowedOperations = new ArrayList<>();
/**
* Creates a new instance.
*/
public Link() {
}
@XmlAttribute(required = true)
public String getPoint() {
return point;
}
public Link setPoint(
@Nonnull
String point
) {
requireNonNull(point, "point");
this.point = point;
return this;
}
@XmlElement(name = "allowedOperation")
public List<AllowedOperationTO> getAllowedOperations() {
return allowedOperations;
}
public Link setAllowedOperations(
@Nonnull
List<AllowedOperationTO> allowedOperations
) {
requireNonNull(allowedOperations, "allowedOperations");
this.allowedOperations = allowedOperations;
return this;
}
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"xPosition", "yPosition", "xLabelOffset", "yLabelOffset",
"locationRepresentation", "layerId"}
)
public static class LocationLayout {
private Long xPosition = 0L;
private Long yPosition = 0L;
private Long xLabelOffset = 0L;
private Long yLabelOffset = 0L;
private String locationRepresentation = "";
private Integer layerId = 0;
/**
* Creates a new instance.
*/
public LocationLayout() {
}
@XmlAttribute(required = true)
public Long getxPosition() {
return xPosition;
}
public LocationLayout setxPosition(Long xPosition) {
this.xPosition = requireNonNull(xPosition, "xPosition");
return this;
}
@XmlAttribute(required = true)
public Long getyPosition() {
return yPosition;
}
public LocationLayout setyPosition(Long yPosition) {
this.yPosition = requireNonNull(yPosition, "yPosition");
return this;
}
@XmlAttribute(required = true)
public Long getxLabelOffset() {
return xLabelOffset;
}
public LocationLayout setxLabelOffset(Long xLabelOffset) {
this.xLabelOffset = requireNonNull(xLabelOffset, "xLabelOffset");
return this;
}
@XmlAttribute(required = true)
public Long getyLabelOffset() {
return yLabelOffset;
}
public LocationLayout setyLabelOffset(Long yLabelOffset) {
this.yLabelOffset = requireNonNull(yLabelOffset, "yLabelOffset");
return this;
}
@XmlAttribute(required = true)
public String getLocationRepresentation() {
return locationRepresentation;
}
public LocationLayout setLocationRepresentation(String locationRepresentation) {
this.locationRepresentation = requireNonNull(
locationRepresentation,
"locationRepresentation"
);
return this;
}
@XmlAttribute(required = true)
public Integer getLayerId() {
return layerId;
}
public LocationLayout setLayerId(Integer layerId) {
this.layerId = requireNonNull(layerId, "layerId");
return this;
}
}
}

View File

@@ -0,0 +1,108 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"name",
"allowedOperations",
"allowedPeripheralOperations",
"properties",
"locationTypeLayout"}
)
public class LocationTypeTO
extends
PlantModelElementTO {
private List<AllowedOperationTO> allowedOperations = new ArrayList<>();
private List<AllowedPeripheralOperationTO> allowedPeripheralOperations = new ArrayList<>();
private LocationTypeLayout locationTypeLayout = new LocationTypeLayout();
/**
* Creates a new instance.
*/
public LocationTypeTO() {
}
@XmlElement(name = "allowedOperation")
public List<AllowedOperationTO> getAllowedOperations() {
return allowedOperations;
}
public LocationTypeTO setAllowedOperations(
@Nonnull
List<AllowedOperationTO> allowedOperations
) {
this.allowedOperations = requireNonNull(allowedOperations, "allowedOperations");
return this;
}
@XmlElement(name = "allowedPeripheralOperation")
public List<AllowedPeripheralOperationTO> getAllowedPeripheralOperations() {
return allowedPeripheralOperations;
}
public LocationTypeTO setAllowedPeripheralOperations(
List<AllowedPeripheralOperationTO> allowedPeripheralOperations
) {
this.allowedPeripheralOperations = requireNonNull(
allowedPeripheralOperations,
"allowedPeripheralOperations"
);
return this;
}
@XmlElement(required = true)
public LocationTypeLayout getLocationTypeLayout() {
return locationTypeLayout;
}
public LocationTypeTO setLocationTypeLayout(
@Nonnull
LocationTypeLayout locationTypeLayout
) {
this.locationTypeLayout = requireNonNull(locationTypeLayout, "locationTypeLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class LocationTypeLayout {
private String locationRepresentation = "";
/**
* Creates a new instance.
*/
public LocationTypeLayout() {
}
@XmlAttribute(required = true)
public String getLocationRepresentation() {
return locationRepresentation;
}
public LocationTypeLayout setLocationRepresentation(
@Nonnull
String locationRepresentation
) {
this.locationRepresentation = requireNonNull(
locationRepresentation,
"locationRepresentation"
);
return this;
}
}
}

View File

@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
public class MemberTO
extends
PlantModelElementTO {
/**
* Creates a new instance.
*/
public MemberTO() {
}
}

View File

@@ -0,0 +1,265 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"name",
"sourcePoint",
"destinationPoint",
"length",
"maxVelocity",
"maxReverseVelocity",
"peripheralOperations",
"locked",
"vehicleEnvelopes",
"properties",
"pathLayout"}
)
public class PathTO
extends
PlantModelElementTO {
private String sourcePoint = "";
private String destinationPoint = "";
private Long length = 0L;
private Long maxVelocity = 0L;
private Long maxReverseVelocity = 0L;
private List<PeripheralOperationTO> peripheralOperations = new ArrayList<>();
private Boolean locked = false;
private List<VehicleEnvelopeTO> vehicleEnvelopes = new ArrayList<>();
private PathLayout pathLayout = new PathLayout();
/**
* Creates a new instance.
*/
public PathTO() {
}
@XmlAttribute(required = true)
public String getSourcePoint() {
return sourcePoint;
}
public PathTO setSourcePoint(
@Nonnull
String sourcePoint
) {
requireNonNull(sourcePoint, "sourcePoint");
this.sourcePoint = sourcePoint;
return this;
}
@XmlAttribute(required = true)
public String getDestinationPoint() {
return destinationPoint;
}
public PathTO setDestinationPoint(
@Nonnull
String destinationPoint
) {
requireNonNull(destinationPoint, "destinationPoint");
this.destinationPoint = destinationPoint;
return this;
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public Long getLength() {
return length;
}
public PathTO setLength(
@Nonnull
Long length
) {
requireNonNull(length, "length");
this.length = length;
return this;
}
@XmlAttribute(required = true)
@XmlSchemaType(name = "unsignedInt")
public Long getMaxVelocity() {
return maxVelocity;
}
public PathTO setMaxVelocity(
@Nonnull
Long maxVelocity
) {
requireNonNull(maxVelocity, "maxVelocity");
this.maxVelocity = maxVelocity;
return this;
}
@XmlAttribute(required = true)
@XmlSchemaType(name = "unsignedInt")
public Long getMaxReverseVelocity() {
return maxReverseVelocity;
}
public PathTO setMaxReverseVelocity(
@Nonnull
Long maxReverseVelocity
) {
requireNonNull(maxReverseVelocity, "maxReverseVelocity");
this.maxReverseVelocity = maxReverseVelocity;
return this;
}
@XmlElement(name = "peripheralOperation")
public List<PeripheralOperationTO> getPeripheralOperations() {
return peripheralOperations;
}
public PathTO setPeripheralOperations(List<PeripheralOperationTO> peripheralOperations) {
this.peripheralOperations = requireNonNull(peripheralOperations, "peripheralOperations");
return this;
}
@XmlAttribute(required = true)
public Boolean isLocked() {
return locked;
}
public PathTO setLocked(Boolean locked) {
this.locked = locked;
return this;
}
@XmlElement(name = "vehicleEnvelope")
public List<VehicleEnvelopeTO> getVehicleEnvelopes() {
return vehicleEnvelopes;
}
public PathTO setVehicleEnvelopes(
@Nonnull
List<VehicleEnvelopeTO> vehicleEnvelopes
) {
this.vehicleEnvelopes = requireNonNull(vehicleEnvelopes, "vehicleEnvelopes");
return this;
}
@XmlElement(required = true)
public PathLayout getPathLayout() {
return pathLayout;
}
public PathTO setPathLayout(
@Nonnull
PathLayout pathLayout
) {
this.pathLayout = requireNonNull(pathLayout, "pathLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"connectionType", "layerId", "controlPoints"})
public static class PathLayout {
private String connectionType = "";
private Integer layerId = 0;
private List<ControlPoint> controlPoints = new ArrayList<>();
/**
* Creates a new instance.
*/
public PathLayout() {
}
@XmlAttribute(required = true)
public String getConnectionType() {
return connectionType;
}
public PathLayout setConnectionType(
@Nonnull
String connectionType
) {
this.connectionType = requireNonNull(connectionType, "connectionType");
return this;
}
@XmlAttribute(required = true)
public Integer getLayerId() {
return layerId;
}
public PathLayout setLayerId(
@Nonnull
Integer layerId
) {
this.layerId = requireNonNull(layerId, "layerId");
return this;
}
@XmlElement(name = "controlPoint")
public List<ControlPoint> getControlPoints() {
return controlPoints;
}
public PathLayout setControlPoints(
@Nonnull
List<ControlPoint> controlPoints
) {
this.controlPoints = requireNonNull(controlPoints, "controlPoints");
return this;
}
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"x", "y"})
public static class ControlPoint {
private Long x = 0L;
private Long y = 0L;
/**
* Creates a new instance.
*/
public ControlPoint() {
}
@XmlAttribute(required = true)
public Long getX() {
return x;
}
public ControlPoint setX(
@Nonnull
Long x
) {
this.x = requireNonNull(x, "x");
return this;
}
@XmlAttribute(required = true)
public Long getY() {
return y;
}
public ControlPoint setY(
@Nonnull
Long y
) {
this.y = requireNonNull(y, "y");
return this;
}
}
}

View File

@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import static java.util.Objects.requireNonNull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
public class PeripheralOperationTO
extends
PlantModelElementTO {
private String locationName = "";
private String executionTrigger = "";
private boolean completionRequired;
/**
* Creates a new instance.
*/
public PeripheralOperationTO() {
}
@XmlAttribute(required = true)
public String getLocationName() {
return locationName;
}
public PeripheralOperationTO setLocationName(String locationName) {
this.locationName = requireNonNull(locationName, "locationName");
return this;
}
@XmlAttribute(required = true)
public String getExecutionTrigger() {
return executionTrigger;
}
public PeripheralOperationTO setExecutionTrigger(String executionTrigger) {
this.executionTrigger = requireNonNull(executionTrigger, "executionTrigger");
return this;
}
@XmlAttribute(required = true)
public boolean isCompletionRequired() {
return completionRequired;
}
public PeripheralOperationTO setCompletionRequired(boolean completionRequired) {
this.completionRequired = completionRequired;
return this;
}
}

View File

@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*/
@XmlTransient
@XmlAccessorType(XmlAccessType.PROPERTY)
public class PlantModelElementTO {
private String name = "";
private List<PropertyTO> properties = new ArrayList<>();
/**
* Creates a new instance.
*/
public PlantModelElementTO() {
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public PlantModelElementTO setName(
@Nonnull
String name
) {
requireNonNull(name, "name");
this.name = name;
return this;
}
@XmlElement(name = "property")
public List<PropertyTO> getProperties() {
return properties;
}
public PlantModelElementTO setProperties(
@Nonnull
List<PropertyTO> properties
) {
requireNonNull(properties, "properties");
this.properties = properties;
return this;
}
}

View File

@@ -0,0 +1,259 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"name", "xPosition", "yPosition", "zPosition", "vehicleOrientationAngle",
"type", "vehicleEnvelopes", "outgoingPaths", "properties", "pointLayout"}
)
public class PointTO
extends
PlantModelElementTO {
private Long xPosition = 0L;
private Long yPosition = 0L;
private Long zPosition = 0L;
private Float vehicleOrientationAngle = 0.0F;
private String type = "HALT_POSITION";
private List<VehicleEnvelopeTO> vehicleEnvelopes = new ArrayList<>();
private List<OutgoingPath> outgoingPaths = new ArrayList<>();
private PointLayout pointLayout = new PointLayout();
/**
* Creates a new instance.
*/
public PointTO() {
}
@XmlAttribute(required = true)
public Long getxPosition() {
return xPosition;
}
public PointTO setxPosition(
@Nonnull
Long xPosition
) {
requireNonNull(xPosition, "xPosition");
this.xPosition = xPosition;
return this;
}
@XmlAttribute(required = true)
public Long getyPosition() {
return yPosition;
}
public PointTO setyPosition(
@Nonnull
Long yPosition
) {
requireNonNull(yPosition, "yPosition");
this.yPosition = yPosition;
return this;
}
@XmlAttribute
public Long getzPosition() {
return zPosition;
}
public PointTO setzPosition(
@Nonnull
Long zPosition
) {
requireNonNull(zPosition, "zPosition");
this.zPosition = zPosition;
return this;
}
@XmlAttribute
public Float getVehicleOrientationAngle() {
return vehicleOrientationAngle;
}
public PointTO setVehicleOrientationAngle(
@Nonnull
Float vehicleOrientationAngle
) {
requireNonNull(vehicleOrientationAngle, "vehicleOrientationAngle");
this.vehicleOrientationAngle = vehicleOrientationAngle;
return this;
}
@XmlAttribute(required = true)
public String getType() {
return type;
}
public PointTO setType(
@Nonnull
String type
) {
requireNonNull(type, "type");
this.type = type;
return this;
}
@XmlElement(name = "outgoingPath")
public List<OutgoingPath> getOutgoingPaths() {
return outgoingPaths;
}
public PointTO setOutgoingPaths(
@Nonnull
List<OutgoingPath> outgoingPath
) {
requireNonNull(outgoingPath, "outgoingPath");
this.outgoingPaths = outgoingPath;
return this;
}
@XmlElement(name = "vehicleEnvelope")
public List<VehicleEnvelopeTO> getVehicleEnvelopes() {
return vehicleEnvelopes;
}
public PointTO setVehicleEnvelopes(
@Nonnull
List<VehicleEnvelopeTO> vehicleEnvelopes
) {
this.vehicleEnvelopes = requireNonNull(vehicleEnvelopes, "vehicleEnvelopes");
return this;
}
@XmlElement(required = true)
public PointLayout getPointLayout() {
return pointLayout;
}
public PointTO setPointLayout(
@Nonnull
PointLayout pointLayout
) {
this.pointLayout = requireNonNull(pointLayout, "pointLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class OutgoingPath {
private String name = "";
/**
* Creates a new instance.
*/
public OutgoingPath() {
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public OutgoingPath setName(
@Nonnull
String name
) {
requireNonNull(name, "name");
this.name = name;
return this;
}
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"xPosition", "yPosition", "xLabelOffset", "yLabelOffset", "layerId"})
public static class PointLayout {
private Long xPosition = 0L;
private Long yPosition = 0L;
private Long xLabelOffset = 0L;
private Long yLabelOffset = 0L;
private Integer layerId = 0;
/**
* Creates a new instance.
*/
public PointLayout() {
}
@XmlAttribute(required = true)
public Long getxPosition() {
return xPosition;
}
public PointLayout setxPosition(
@Nonnull
Long xPosition
) {
this.xPosition = requireNonNull(xPosition, "xPosition");
return this;
}
@XmlAttribute(required = true)
public Long getyPosition() {
return yPosition;
}
public PointLayout setyPosition(
@Nonnull
Long yPosition
) {
this.yPosition = requireNonNull(yPosition, "yPosition");
return this;
}
@XmlAttribute(required = true)
public Long getxLabelOffset() {
return xLabelOffset;
}
public PointLayout setxLabelOffset(
@Nonnull
Long xLabelOffset
) {
this.xLabelOffset = requireNonNull(xLabelOffset, "xLabelOffset");
return this;
}
@XmlAttribute(required = true)
public Long getyLabelOffset() {
return yLabelOffset;
}
public PointLayout setyLabelOffset(
@Nonnull
Long yLabelOffset
) {
this.yLabelOffset = requireNonNull(yLabelOffset, "yLabelOffset");
return this;
}
@XmlAttribute(required = true)
public Integer getLayerId() {
return layerId;
}
public PointLayout setLayerId(
@Nonnull
Integer layerId
) {
this.layerId = requireNonNull(layerId, "layerId");
return this;
}
}
}

View File

@@ -0,0 +1,54 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"name", "value"})
public class PropertyTO {
private String name = "";
private String value = "";
/**
* Creates a new instance.
*/
public PropertyTO() {
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public PropertyTO setName(
@Nonnull
String name
) {
this.name = requireNonNull(name, "name");
return this;
}
@XmlAttribute(required = true)
public String getValue() {
return value;
}
public PropertyTO setValue(
@Nonnull
String value
) {
requireNonNull(value, "value");
this.value = value;
return this;
}
}

View File

@@ -0,0 +1,39 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import java.io.IOException;
import java.io.Reader;
import java.util.Objects;
/**
* The parser for V004 models.
*/
public class V004ModelParser {
/**
* Creates a new instance.
*/
public V004ModelParser() {
}
/**
* Reads a model with the given reader and parses it to a {@link V004PlantModelTO} instance.
*
* @param reader The reader to use.
* @param modelVersion The model version.
* @return The parsed {@link V004PlantModelTO}.
* @throws IOException If there was an error reading the model.
*/
public V004PlantModelTO readRaw(Reader reader, String modelVersion)
throws IOException {
if (Objects.equals(modelVersion, V004PlantModelTO.VERSION_STRING)) {
return V004PlantModelTO.fromXml(reader);
}
else {
throw new IllegalArgumentException(
String.format("There is no parser for a model file with version: %s.", modelVersion)
);
}
}
}

View File

@@ -0,0 +1,260 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.opentcs.util.persistence.BasePlantModelTO;
import org.xml.sax.SAXException;
/**
*/
@XmlRootElement(name = "model")
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"version", "name", "points", "paths", "vehicles", "locationTypes",
"locations", "blocks", "visualLayout", "properties"}
)
public class V004PlantModelTO
extends
BasePlantModelTO {
/**
* This plant model implementation's version string.
*/
public static final String VERSION_STRING = "0.0.4";
private String name = "";
private List<PointTO> points = new ArrayList<>();
private List<PathTO> paths = new ArrayList<>();
private List<VehicleTO> vehicles = new ArrayList<>();
private List<LocationTypeTO> locationTypes = new ArrayList<>();
private List<LocationTO> locations = new ArrayList<>();
private List<BlockTO> blocks = new ArrayList<>();
private VisualLayoutTO visualLayout = new VisualLayoutTO();
private List<PropertyTO> properties = new ArrayList<>();
/**
* Creates a new instance.
*/
public V004PlantModelTO() {
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public V004PlantModelTO setName(
@Nonnull
String name
) {
requireNonNull(name, "name");
this.name = name;
return this;
}
@XmlElement(name = "point")
public List<PointTO> getPoints() {
return points;
}
public V004PlantModelTO setPoints(
@Nonnull
List<PointTO> points
) {
requireNonNull(points, "points");
this.points = points;
return this;
}
@XmlElement(name = "path")
public List<PathTO> getPaths() {
return paths;
}
public V004PlantModelTO setPaths(
@Nonnull
List<PathTO> paths
) {
requireNonNull(paths, "paths");
this.paths = paths;
return this;
}
@XmlElement(name = "vehicle")
public List<VehicleTO> getVehicles() {
return vehicles;
}
public V004PlantModelTO setVehicles(
@Nonnull
List<VehicleTO> vehicles
) {
requireNonNull(vehicles, "vehicles");
this.vehicles = vehicles;
return this;
}
@XmlElement(name = "locationType")
public List<LocationTypeTO> getLocationTypes() {
return locationTypes;
}
public V004PlantModelTO setLocationTypes(
@Nonnull
List<LocationTypeTO> locationTypes
) {
requireNonNull(locationTypes, "locationTypes");
this.locationTypes = locationTypes;
return this;
}
@XmlElement(name = "location")
public List<LocationTO> getLocations() {
return locations;
}
public V004PlantModelTO setLocations(
@Nonnull
List<LocationTO> locations
) {
requireNonNull(locations, "locations");
this.locations = locations;
return this;
}
@XmlElement(name = "block")
public List<BlockTO> getBlocks() {
return blocks;
}
public V004PlantModelTO setBlocks(
@Nonnull
List<BlockTO> blocks
) {
requireNonNull(blocks, "blocks");
this.blocks = blocks;
return this;
}
@XmlElement
public VisualLayoutTO getVisualLayout() {
return visualLayout;
}
public V004PlantModelTO setVisualLayout(
@Nonnull
VisualLayoutTO visualLayout
) {
this.visualLayout = requireNonNull(visualLayout, "visualLayout");
return this;
}
@XmlElement(name = "property")
public List<PropertyTO> getProperties() {
return properties;
}
public V004PlantModelTO setProperties(
@Nonnull
List<PropertyTO> properties
) {
requireNonNull(properties, "properties");
this.properties = properties;
return this;
}
/**
* Marshals this instance to its XML representation and writes it to the given writer.
*
* @param writer The writer to write this instance's XML representation to.
* @throws IOException If there was a problem marshalling this instance.
*/
public void toXml(
@Nonnull
Writer writer
)
throws IOException {
requireNonNull(writer, "writer");
try {
createMarshaller().marshal(this, writer);
}
catch (JAXBException | SAXException exc) {
throw new IOException("Exception marshalling data", exc);
}
}
/**
* Unmarshals an instance of this class from the given XML representation.
*
* @param reader Provides the XML representation to parse to an instance.
* @return The instance unmarshalled from the given reader.
* @throws IOException If there was a problem unmarshalling the given string.
*/
public static V004PlantModelTO fromXml(
@Nonnull
Reader reader
)
throws IOException {
requireNonNull(reader, "reader");
try {
return (V004PlantModelTO) createUnmarshaller().unmarshal(reader);
}
catch (JAXBException | SAXException exc) {
throw new IOException("Exception unmarshalling data", exc);
}
}
private static Marshaller createMarshaller()
throws JAXBException,
SAXException {
Marshaller marshaller = createContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setSchema(createSchema());
return marshaller;
}
private static Unmarshaller createUnmarshaller()
throws JAXBException,
SAXException {
Unmarshaller unmarshaller = createContext().createUnmarshaller();
unmarshaller.setSchema(createSchema());
return unmarshaller;
}
private static JAXBContext createContext()
throws JAXBException {
return JAXBContext.newInstance(V004PlantModelTO.class);
}
private static Schema createSchema()
throws SAXException {
URL schemaUrl
= V004PlantModelTO.class.getResource("/org/opentcs/util/persistence/model-0.0.4.xsd");
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
return schemaFactory.newSchema(schemaUrl);
}
}

View File

@@ -0,0 +1,52 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"key", "vertices"})
public class VehicleEnvelopeTO {
private String key;
private List<CoupleTO> vertices;
public VehicleEnvelopeTO() {
}
public String getKey() {
return key;
}
@XmlAttribute
public VehicleEnvelopeTO setKey(
@Nonnull
String key
) {
this.key = requireNonNull(key, "key");
return this;
}
@XmlElement(name = "vertex")
public List<CoupleTO> getVertices() {
return vertices;
}
public VehicleEnvelopeTO setVertices(
@Nonnull
List<CoupleTO> vertices
) {
this.vertices = requireNonNull(vertices, "vertices");
return this;
}
}

View File

@@ -0,0 +1,200 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"name", "length", "energyLevelCritical", "energyLevelGood",
"energyLevelFullyRecharged", "energyLevelSufficientlyRecharged",
"maxVelocity", "maxReverseVelocity", "properties", "vehicleLayout"}
)
public class VehicleTO
extends
PlantModelElementTO {
//max velocity in mm/s.
private int maxVelocity;
//max rev velocity in mm/s.
private int maxReverseVelocity;
private Long length = 0L;
private Long energyLevelCritical = 0L;
private Long energyLevelGood = 0L;
private Long energyLevelFullyRecharged = 0L;
private Long energyLevelSufficientlyRecharged = 0L;
private String envelopeKey;
private VehicleLayout vehicleLayout = new VehicleLayout();
/**
* Creates a new instance.
*/
public VehicleTO() {
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public Long getLength() {
return length;
}
public VehicleTO setLength(
@Nonnull
Long length
) {
requireNonNull(length, "length");
this.length = length;
return this;
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public Long getEnergyLevelCritical() {
return energyLevelCritical;
}
public VehicleTO setEnergyLevelCritical(
@Nonnull
Long energyLevelCritical
) {
requireNonNull(energyLevelCritical, "energyLevelCritical");
this.energyLevelCritical = energyLevelCritical;
return this;
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public Long getEnergyLevelGood() {
return energyLevelGood;
}
public VehicleTO setEnergyLevelGood(
@Nonnull
Long energyLevelGood
) {
requireNonNull(energyLevelGood, "energyLevelGood");
this.energyLevelGood = energyLevelGood;
return this;
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public Long getEnergyLevelFullyRecharged() {
return energyLevelFullyRecharged;
}
public VehicleTO setEnergyLevelFullyRecharged(
@Nonnull
Long energyLevelFullyRecharged
) {
requireNonNull(energyLevelFullyRecharged, "energyLevelFullyRecharged");
this.energyLevelFullyRecharged = energyLevelFullyRecharged;
return this;
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public Long getEnergyLevelSufficientlyRecharged() {
return energyLevelSufficientlyRecharged;
}
public VehicleTO setEnergyLevelSufficientlyRecharged(
@Nonnull
Long energyLevelSufficientlyRecharged
) {
requireNonNull(energyLevelSufficientlyRecharged, "energyLevelSufficientlyRecharged");
this.energyLevelSufficientlyRecharged = energyLevelSufficientlyRecharged;
return this;
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public int getMaxVelocity() {
return maxVelocity;
}
public VehicleTO setMaxVelocity(
@Nonnull
int maxVelocity
) {
this.maxVelocity = maxVelocity;
return this;
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public int getMaxReverseVelocity() {
return maxReverseVelocity;
}
public VehicleTO setMaxReverseVelocity(
@Nonnull
int maxReverseVelocity
) {
this.maxReverseVelocity = maxReverseVelocity;
return this;
}
@XmlAttribute
@Nullable
public String getEnvelopeKey() {
return envelopeKey;
}
public VehicleTO setEnvelopeKey(
@Nullable
String envelopeKey
) {
this.envelopeKey = envelopeKey;
return this;
}
@XmlElement(required = true)
public VehicleLayout getVehicleLayout() {
return vehicleLayout;
}
public VehicleTO setVehicleLayout(
@Nonnull
VehicleLayout vehicleLayout
) {
this.vehicleLayout = requireNonNull(vehicleLayout, "vehicleLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class VehicleLayout {
private String color = "";
/**
* Creates a new instance.
*/
public VehicleLayout() {
}
@XmlAttribute(required = true)
public String getColor() {
return color;
}
public VehicleLayout setColor(
@Nonnull
String color
) {
this.color = requireNonNull(color, "color");
return this;
}
}
}

View File

@@ -0,0 +1,200 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v004;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"name", "scaleX", "scaleY", "layers", "layerGroups", "properties"})
public class VisualLayoutTO
extends
PlantModelElementTO {
private Float scaleX = 0.0F;
private Float scaleY = 0.0F;
private List<Layer> layers = new ArrayList<>();
private List<LayerGroup> layerGroups = new ArrayList<>();
/**
* Creates a new instance.
*/
public VisualLayoutTO() {
}
@XmlAttribute(required = true)
public Float getScaleX() {
return scaleX;
}
public VisualLayoutTO setScaleX(
@Nonnull
Float scaleX
) {
requireNonNull(scaleX, "scaleX");
this.scaleX = scaleX;
return this;
}
@XmlAttribute(required = true)
public Float getScaleY() {
return scaleY;
}
public VisualLayoutTO setScaleY(
@Nonnull
Float scaleY
) {
requireNonNull(scaleY, "scaleY");
this.scaleY = scaleY;
return this;
}
@XmlElement(name = "layer")
public List<Layer> getLayers() {
return layers;
}
public VisualLayoutTO setLayers(
@Nonnull
List<Layer> layers
) {
this.layers = requireNonNull(layers, "layers");
return this;
}
@XmlElement(name = "layerGroup")
public List<LayerGroup> getLayerGroups() {
return layerGroups;
}
public VisualLayoutTO setLayerGroups(
@Nonnull
List<LayerGroup> layerGroups
) {
this.layerGroups = requireNonNull(layerGroups, "layerGroups");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"id", "ordinal", "visible", "name", "groupId"})
public static class Layer {
private Integer id = 0;
private Integer ordinal = 0;
private Boolean visible = true;
private String name = "";
private Integer groupId = 0;
/**
* Creates a new instance.
*/
public Layer() {
}
@XmlAttribute(required = true)
public Integer getId() {
return id;
}
public Layer setId(Integer id) {
this.id = requireNonNull(id, "id");
return this;
}
@XmlAttribute(required = true)
public Integer getOrdinal() {
return ordinal;
}
public Layer setOrdinal(Integer ordinal) {
this.ordinal = requireNonNull(ordinal, "ordinal");
return this;
}
@XmlAttribute(required = true)
public Boolean isVisible() {
return visible;
}
public Layer setVisible(Boolean visible) {
this.visible = requireNonNull(visible, "visible");
return this;
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public Layer setName(String name) {
this.name = requireNonNull(name, "name");
return this;
}
@XmlAttribute(required = true)
public Integer getGroupId() {
return groupId;
}
public Layer setGroupId(Integer groupId) {
this.groupId = requireNonNull(groupId, "groupId");
return this;
}
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"id", "name", "visible"})
public static class LayerGroup {
private Integer id = 0;
private String name = "";
private Boolean visible = true;
/**
* Creates a new instance.
*/
public LayerGroup() {
}
@XmlAttribute(required = true)
public Integer getId() {
return id;
}
public LayerGroup setId(Integer id) {
this.id = requireNonNull(id, "id");
return this;
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public LayerGroup setName(String name) {
this.name = requireNonNull(name, "name");
return this;
}
@XmlAttribute(required = true)
public Boolean isVisible() {
return visible;
}
public LayerGroup setVisible(Boolean visible) {
this.visible = requireNonNull(visible, "visible");
return this;
}
}
}

View File

@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AllowedOperationTO
extends
PlantModelElementTO {
/**
* Creates a new instance.
*/
public AllowedOperationTO() {
}
}

View File

@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AllowedPeripheralOperationTO
extends
PlantModelElementTO {
/**
* Creates a new instance.
*/
public AllowedPeripheralOperationTO() {
}
}

View File

@@ -0,0 +1,99 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"name", "type", "members", "properties", "blockLayout"})
public class BlockTO
extends
PlantModelElementTO {
private String type = "SINGLE_VEHICLE_ONLY";
private List<MemberTO> members = new ArrayList<>();
private BlockLayout blockLayout = new BlockLayout();
/**
* Creates a new instance.
*/
public BlockTO() {
}
@XmlAttribute(required = true)
public String getType() {
return type;
}
public BlockTO setType(
@Nonnull
String type
) {
requireNonNull(type, "type");
this.type = type;
return this;
}
@XmlElement(name = "member")
public List<MemberTO> getMembers() {
return members;
}
public BlockTO setMembers(
@Nonnull
List<MemberTO> members
) {
requireNonNull(members, "members");
this.members = members;
return this;
}
@XmlElement(required = true)
public BlockLayout getBlockLayout() {
return blockLayout;
}
public BlockTO setBlockLayout(
@Nonnull
BlockLayout blockLayout
) {
this.blockLayout = requireNonNull(blockLayout, "blockLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class BlockLayout {
private String color = "";
/**
* Creates a new instance.
*/
public BlockLayout() {
}
@XmlAttribute(required = true)
public String getColor() {
return color;
}
public BlockLayout setColor(
@Nonnull
String color
) {
this.color = requireNonNull(color, "color");
return this;
}
}
}

View File

@@ -0,0 +1,53 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import java.util.Comparator;
/**
* Some comparator implementations for JAXB classes.
*/
public final class Comparators {
/**
* Prevents instantiation.
*/
private Comparators() {
}
/**
* Returns a comparator for ordering <code>PlantModelElementTO</code>s ascendingly by their names.
*
* @return A comparator for ordering <code>PlantModelElementTO</code>s ascendingly by their names.
*/
public static Comparator<PlantModelElementTO> elementsByName() {
return Comparator.comparing(PlantModelElementTO::getName);
}
/**
* Returns a comparator for ordering <code>OutgoingPath</code>s ascendingly by their names.
*
* @return A comparator for ordering <code>OutgoingPath</code>s ascendingly by their names.
*/
public static Comparator<PointTO.OutgoingPath> outgoingPathsByName() {
return Comparator.comparing(PointTO.OutgoingPath::getName);
}
/**
* Returns a comparator for ordering <code>Link</code>s ascendingly by their point names.
*
* @return A comparator for ordering <code>Link</code>s ascendingly by their point names.
*/
public static Comparator<LocationTO.Link> linksByPointName() {
return Comparator.comparing(LocationTO.Link::getPoint);
}
/**
* Returns a comparator for ordering <code>Properties</code>s ascendingly by their names.
*
* @return A comparator for ordering <code>Properties</code> ascendingly by their names.
*/
public static Comparator<PropertyTO> propertiesByName() {
return Comparator.comparing(PropertyTO::getName);
}
}

View File

@@ -0,0 +1,50 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"x", "y"})
public class CoupleTO {
private Long x;
private Long y;
public CoupleTO() {
}
@XmlAttribute(required = true)
public Long getX() {
return x;
}
public CoupleTO setX(
@Nonnull
Long x
) {
this.x = requireNonNull(x, "x");
return this;
}
@XmlAttribute(required = true)
public Long getY() {
return y;
}
public CoupleTO setY(
@Nonnull
Long y
) {
this.y = requireNonNull(y, "y");
return this;
}
}

View File

@@ -0,0 +1,259 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"name", "xPosition", "yPosition", "zPosition", "links", "locked",
"properties", "locationLayout"}
)
public class LocationTO
extends
PlantModelElementTO {
private Long xPosition = 0L;
private Long yPosition = 0L;
private Long zPosition = 0L;
private String type = "";
private List<Link> links = new ArrayList<>();
private Boolean locked = false;
private LocationLayout locationLayout = new LocationLayout();
/**
* Creates a new instance.
*/
public LocationTO() {
}
@XmlAttribute
public Long getxPosition() {
return xPosition;
}
public LocationTO setxPosition(
@Nonnull
Long xPosition
) {
requireNonNull(xPosition, "xPosition");
this.xPosition = xPosition;
return this;
}
@XmlAttribute
public Long getyPosition() {
return yPosition;
}
public LocationTO setyPosition(
@Nonnull
Long yPosition
) {
requireNonNull(yPosition, "yPosition");
this.yPosition = yPosition;
return this;
}
@XmlAttribute
public Long getzPosition() {
return zPosition;
}
public LocationTO setzPosition(
@Nonnull
Long zPosition
) {
requireNonNull(zPosition, "zPosition");
this.zPosition = zPosition;
return this;
}
@XmlAttribute
public String getType() {
return type;
}
public LocationTO setType(
@Nonnull
String type
) {
requireNonNull(type, "type");
this.type = type;
return this;
}
@XmlElement(name = "link", required = true)
public List<Link> getLinks() {
return links;
}
public LocationTO setLinks(
@Nonnull
List<Link> links
) {
requireNonNull(links, "links");
this.links = links;
return this;
}
@XmlAttribute(required = true)
public Boolean isLocked() {
return locked;
}
public LocationTO setLocked(Boolean locked) {
this.locked = locked;
return this;
}
@XmlElement(required = true)
public LocationLayout getLocationLayout() {
return locationLayout;
}
public LocationTO setLocationLayout(
@Nonnull
LocationLayout locationLayout
) {
this.locationLayout = requireNonNull(locationLayout, "locationLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"point", "allowedOperations"})
public static class Link {
private String point = "";
private List<AllowedOperationTO> allowedOperations = new ArrayList<>();
/**
* Creates a new instance.
*/
public Link() {
}
@XmlAttribute(required = true)
public String getPoint() {
return point;
}
public Link setPoint(
@Nonnull
String point
) {
requireNonNull(point, "point");
this.point = point;
return this;
}
@XmlElement(name = "allowedOperation")
public List<AllowedOperationTO> getAllowedOperations() {
return allowedOperations;
}
public Link setAllowedOperations(
@Nonnull
List<AllowedOperationTO> allowedOperations
) {
requireNonNull(allowedOperations, "allowedOperations");
this.allowedOperations = allowedOperations;
return this;
}
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"xPosition", "yPosition", "xLabelOffset", "yLabelOffset",
"locationRepresentation", "layerId"}
)
public static class LocationLayout {
private Long xPosition = 0L;
private Long yPosition = 0L;
private Long xLabelOffset = 0L;
private Long yLabelOffset = 0L;
private String locationRepresentation = "";
private Integer layerId = 0;
/**
* Creates a new instance.
*/
public LocationLayout() {
}
@XmlAttribute(required = true)
public Long getxPosition() {
return xPosition;
}
public LocationLayout setxPosition(Long xPosition) {
this.xPosition = requireNonNull(xPosition, "xPosition");
return this;
}
@XmlAttribute(required = true)
public Long getyPosition() {
return yPosition;
}
public LocationLayout setyPosition(Long yPosition) {
this.yPosition = requireNonNull(yPosition, "yPosition");
return this;
}
@XmlAttribute(required = true)
public Long getxLabelOffset() {
return xLabelOffset;
}
public LocationLayout setxLabelOffset(Long xLabelOffset) {
this.xLabelOffset = requireNonNull(xLabelOffset, "xLabelOffset");
return this;
}
@XmlAttribute(required = true)
public Long getyLabelOffset() {
return yLabelOffset;
}
public LocationLayout setyLabelOffset(Long yLabelOffset) {
this.yLabelOffset = requireNonNull(yLabelOffset, "yLabelOffset");
return this;
}
@XmlAttribute(required = true)
public String getLocationRepresentation() {
return locationRepresentation;
}
public LocationLayout setLocationRepresentation(String locationRepresentation) {
this.locationRepresentation = requireNonNull(
locationRepresentation,
"locationRepresentation"
);
return this;
}
@XmlAttribute(required = true)
public Integer getLayerId() {
return layerId;
}
public LocationLayout setLayerId(Integer layerId) {
this.layerId = requireNonNull(layerId, "layerId");
return this;
}
}
}

View File

@@ -0,0 +1,108 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"name",
"allowedOperations",
"allowedPeripheralOperations",
"properties",
"locationTypeLayout"}
)
public class LocationTypeTO
extends
PlantModelElementTO {
private List<AllowedOperationTO> allowedOperations = new ArrayList<>();
private List<AllowedPeripheralOperationTO> allowedPeripheralOperations = new ArrayList<>();
private LocationTypeLayout locationTypeLayout = new LocationTypeLayout();
/**
* Creates a new instance.
*/
public LocationTypeTO() {
}
@XmlElement(name = "allowedOperation")
public List<AllowedOperationTO> getAllowedOperations() {
return allowedOperations;
}
public LocationTypeTO setAllowedOperations(
@Nonnull
List<AllowedOperationTO> allowedOperations
) {
this.allowedOperations = requireNonNull(allowedOperations, "allowedOperations");
return this;
}
@XmlElement(name = "allowedPeripheralOperation")
public List<AllowedPeripheralOperationTO> getAllowedPeripheralOperations() {
return allowedPeripheralOperations;
}
public LocationTypeTO setAllowedPeripheralOperations(
List<AllowedPeripheralOperationTO> allowedPeripheralOperations
) {
this.allowedPeripheralOperations = requireNonNull(
allowedPeripheralOperations,
"allowedPeripheralOperations"
);
return this;
}
@XmlElement(required = true)
public LocationTypeLayout getLocationTypeLayout() {
return locationTypeLayout;
}
public LocationTypeTO setLocationTypeLayout(
@Nonnull
LocationTypeLayout locationTypeLayout
) {
this.locationTypeLayout = requireNonNull(locationTypeLayout, "locationTypeLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class LocationTypeLayout {
private String locationRepresentation = "";
/**
* Creates a new instance.
*/
public LocationTypeLayout() {
}
@XmlAttribute(required = true)
public String getLocationRepresentation() {
return locationRepresentation;
}
public LocationTypeLayout setLocationRepresentation(
@Nonnull
String locationRepresentation
) {
this.locationRepresentation = requireNonNull(
locationRepresentation,
"locationRepresentation"
);
return this;
}
}
}

View File

@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
public class MemberTO
extends
PlantModelElementTO {
/**
* Creates a new instance.
*/
public MemberTO() {
}
}

View File

@@ -0,0 +1,265 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"name",
"sourcePoint",
"destinationPoint",
"length",
"maxVelocity",
"maxReverseVelocity",
"peripheralOperations",
"locked",
"vehicleEnvelopes",
"properties",
"pathLayout"}
)
public class PathTO
extends
PlantModelElementTO {
private String sourcePoint = "";
private String destinationPoint = "";
private Long length = 0L;
private Long maxVelocity = 0L;
private Long maxReverseVelocity = 0L;
private List<PeripheralOperationTO> peripheralOperations = new ArrayList<>();
private Boolean locked = false;
private List<VehicleEnvelopeTO> vehicleEnvelopes = new ArrayList<>();
private PathLayout pathLayout = new PathLayout();
/**
* Creates a new instance.
*/
public PathTO() {
}
@XmlAttribute(required = true)
public String getSourcePoint() {
return sourcePoint;
}
public PathTO setSourcePoint(
@Nonnull
String sourcePoint
) {
requireNonNull(sourcePoint, "sourcePoint");
this.sourcePoint = sourcePoint;
return this;
}
@XmlAttribute(required = true)
public String getDestinationPoint() {
return destinationPoint;
}
public PathTO setDestinationPoint(
@Nonnull
String destinationPoint
) {
requireNonNull(destinationPoint, "destinationPoint");
this.destinationPoint = destinationPoint;
return this;
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public Long getLength() {
return length;
}
public PathTO setLength(
@Nonnull
Long length
) {
requireNonNull(length, "length");
this.length = length;
return this;
}
@XmlAttribute(required = true)
@XmlSchemaType(name = "unsignedInt")
public Long getMaxVelocity() {
return maxVelocity;
}
public PathTO setMaxVelocity(
@Nonnull
Long maxVelocity
) {
requireNonNull(maxVelocity, "maxVelocity");
this.maxVelocity = maxVelocity;
return this;
}
@XmlAttribute(required = true)
@XmlSchemaType(name = "unsignedInt")
public Long getMaxReverseVelocity() {
return maxReverseVelocity;
}
public PathTO setMaxReverseVelocity(
@Nonnull
Long maxReverseVelocity
) {
requireNonNull(maxReverseVelocity, "maxReverseVelocity");
this.maxReverseVelocity = maxReverseVelocity;
return this;
}
@XmlElement(name = "peripheralOperation")
public List<PeripheralOperationTO> getPeripheralOperations() {
return peripheralOperations;
}
public PathTO setPeripheralOperations(List<PeripheralOperationTO> peripheralOperations) {
this.peripheralOperations = requireNonNull(peripheralOperations, "peripheralOperations");
return this;
}
@XmlAttribute(required = true)
public Boolean isLocked() {
return locked;
}
public PathTO setLocked(Boolean locked) {
this.locked = locked;
return this;
}
@XmlElement(name = "vehicleEnvelope")
public List<VehicleEnvelopeTO> getVehicleEnvelopes() {
return vehicleEnvelopes;
}
public PathTO setVehicleEnvelopes(
@Nonnull
List<VehicleEnvelopeTO> vehicleEnvelopes
) {
this.vehicleEnvelopes = requireNonNull(vehicleEnvelopes, "vehicleEnvelopes");
return this;
}
@XmlElement(required = true)
public PathLayout getPathLayout() {
return pathLayout;
}
public PathTO setPathLayout(
@Nonnull
PathLayout pathLayout
) {
this.pathLayout = requireNonNull(pathLayout, "pathLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"connectionType", "layerId", "controlPoints"})
public static class PathLayout {
private String connectionType = "";
private Integer layerId = 0;
private List<ControlPoint> controlPoints = new ArrayList<>();
/**
* Creates a new instance.
*/
public PathLayout() {
}
@XmlAttribute(required = true)
public String getConnectionType() {
return connectionType;
}
public PathLayout setConnectionType(
@Nonnull
String connectionType
) {
this.connectionType = requireNonNull(connectionType, "connectionType");
return this;
}
@XmlAttribute(required = true)
public Integer getLayerId() {
return layerId;
}
public PathLayout setLayerId(
@Nonnull
Integer layerId
) {
this.layerId = requireNonNull(layerId, "layerId");
return this;
}
@XmlElement(name = "controlPoint")
public List<ControlPoint> getControlPoints() {
return controlPoints;
}
public PathLayout setControlPoints(
@Nonnull
List<ControlPoint> controlPoints
) {
this.controlPoints = requireNonNull(controlPoints, "controlPoints");
return this;
}
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"x", "y"})
public static class ControlPoint {
private Long x = 0L;
private Long y = 0L;
/**
* Creates a new instance.
*/
public ControlPoint() {
}
@XmlAttribute(required = true)
public Long getX() {
return x;
}
public ControlPoint setX(
@Nonnull
Long x
) {
this.x = requireNonNull(x, "x");
return this;
}
@XmlAttribute(required = true)
public Long getY() {
return y;
}
public ControlPoint setY(
@Nonnull
Long y
) {
this.y = requireNonNull(y, "y");
return this;
}
}
}

View File

@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import static java.util.Objects.requireNonNull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
public class PeripheralOperationTO
extends
PlantModelElementTO {
private String locationName = "";
private String executionTrigger = "";
private boolean completionRequired;
/**
* Creates a new instance.
*/
public PeripheralOperationTO() {
}
@XmlAttribute(required = true)
public String getLocationName() {
return locationName;
}
public PeripheralOperationTO setLocationName(String locationName) {
this.locationName = requireNonNull(locationName, "locationName");
return this;
}
@XmlAttribute(required = true)
public String getExecutionTrigger() {
return executionTrigger;
}
public PeripheralOperationTO setExecutionTrigger(String executionTrigger) {
this.executionTrigger = requireNonNull(executionTrigger, "executionTrigger");
return this;
}
@XmlAttribute(required = true)
public boolean isCompletionRequired() {
return completionRequired;
}
public PeripheralOperationTO setCompletionRequired(boolean completionRequired) {
this.completionRequired = completionRequired;
return this;
}
}

View File

@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*/
@XmlTransient
@XmlAccessorType(XmlAccessType.PROPERTY)
public class PlantModelElementTO {
private String name = "";
private List<PropertyTO> properties = new ArrayList<>();
/**
* Creates a new instance.
*/
public PlantModelElementTO() {
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public PlantModelElementTO setName(
@Nonnull
String name
) {
requireNonNull(name, "name");
this.name = name;
return this;
}
@XmlElement(name = "property")
public List<PropertyTO> getProperties() {
return properties;
}
public PlantModelElementTO setProperties(
@Nonnull
List<PropertyTO> properties
) {
requireNonNull(properties, "properties");
this.properties = properties;
return this;
}
}

View File

@@ -0,0 +1,259 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"name", "xPosition", "yPosition", "zPosition", "vehicleOrientationAngle",
"type", "vehicleEnvelopes", "outgoingPaths", "properties", "pointLayout"}
)
public class PointTO
extends
PlantModelElementTO {
private Long xPosition = 0L;
private Long yPosition = 0L;
private Long zPosition = 0L;
private Float vehicleOrientationAngle = 0.0F;
private String type = "HALT_POSITION";
private List<VehicleEnvelopeTO> vehicleEnvelopes = new ArrayList<>();
private List<OutgoingPath> outgoingPaths = new ArrayList<>();
private PointLayout pointLayout = new PointLayout();
/**
* Creates a new instance.
*/
public PointTO() {
}
@XmlAttribute(required = true)
public Long getxPosition() {
return xPosition;
}
public PointTO setxPosition(
@Nonnull
Long xPosition
) {
requireNonNull(xPosition, "xPosition");
this.xPosition = xPosition;
return this;
}
@XmlAttribute(required = true)
public Long getyPosition() {
return yPosition;
}
public PointTO setyPosition(
@Nonnull
Long yPosition
) {
requireNonNull(yPosition, "yPosition");
this.yPosition = yPosition;
return this;
}
@XmlAttribute
public Long getzPosition() {
return zPosition;
}
public PointTO setzPosition(
@Nonnull
Long zPosition
) {
requireNonNull(zPosition, "zPosition");
this.zPosition = zPosition;
return this;
}
@XmlAttribute
public Float getVehicleOrientationAngle() {
return vehicleOrientationAngle;
}
public PointTO setVehicleOrientationAngle(
@Nonnull
Float vehicleOrientationAngle
) {
requireNonNull(vehicleOrientationAngle, "vehicleOrientationAngle");
this.vehicleOrientationAngle = vehicleOrientationAngle;
return this;
}
@XmlAttribute(required = true)
public String getType() {
return type;
}
public PointTO setType(
@Nonnull
String type
) {
requireNonNull(type, "type");
this.type = type;
return this;
}
@XmlElement(name = "outgoingPath")
public List<OutgoingPath> getOutgoingPaths() {
return outgoingPaths;
}
public PointTO setOutgoingPaths(
@Nonnull
List<OutgoingPath> outgoingPath
) {
requireNonNull(outgoingPath, "outgoingPath");
this.outgoingPaths = outgoingPath;
return this;
}
@XmlElement(name = "vehicleEnvelope")
public List<VehicleEnvelopeTO> getVehicleEnvelopes() {
return vehicleEnvelopes;
}
public PointTO setVehicleEnvelopes(
@Nonnull
List<VehicleEnvelopeTO> vehicleEnvelopes
) {
this.vehicleEnvelopes = requireNonNull(vehicleEnvelopes, "vehicleEnvelopes");
return this;
}
@XmlElement(required = true)
public PointLayout getPointLayout() {
return pointLayout;
}
public PointTO setPointLayout(
@Nonnull
PointLayout pointLayout
) {
this.pointLayout = requireNonNull(pointLayout, "pointLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class OutgoingPath {
private String name = "";
/**
* Creates a new instance.
*/
public OutgoingPath() {
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public OutgoingPath setName(
@Nonnull
String name
) {
requireNonNull(name, "name");
this.name = name;
return this;
}
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"xPosition", "yPosition", "xLabelOffset", "yLabelOffset", "layerId"})
public static class PointLayout {
private Long xPosition = 0L;
private Long yPosition = 0L;
private Long xLabelOffset = 0L;
private Long yLabelOffset = 0L;
private Integer layerId = 0;
/**
* Creates a new instance.
*/
public PointLayout() {
}
@XmlAttribute(required = true)
public Long getxPosition() {
return xPosition;
}
public PointLayout setxPosition(
@Nonnull
Long xPosition
) {
this.xPosition = requireNonNull(xPosition, "xPosition");
return this;
}
@XmlAttribute(required = true)
public Long getyPosition() {
return yPosition;
}
public PointLayout setyPosition(
@Nonnull
Long yPosition
) {
this.yPosition = requireNonNull(yPosition, "yPosition");
return this;
}
@XmlAttribute(required = true)
public Long getxLabelOffset() {
return xLabelOffset;
}
public PointLayout setxLabelOffset(
@Nonnull
Long xLabelOffset
) {
this.xLabelOffset = requireNonNull(xLabelOffset, "xLabelOffset");
return this;
}
@XmlAttribute(required = true)
public Long getyLabelOffset() {
return yLabelOffset;
}
public PointLayout setyLabelOffset(
@Nonnull
Long yLabelOffset
) {
this.yLabelOffset = requireNonNull(yLabelOffset, "yLabelOffset");
return this;
}
@XmlAttribute(required = true)
public Integer getLayerId() {
return layerId;
}
public PointLayout setLayerId(
@Nonnull
Integer layerId
) {
this.layerId = requireNonNull(layerId, "layerId");
return this;
}
}
}

View File

@@ -0,0 +1,54 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"name", "value"})
public class PropertyTO {
private String name = "";
private String value = "";
/**
* Creates a new instance.
*/
public PropertyTO() {
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public PropertyTO setName(
@Nonnull
String name
) {
this.name = requireNonNull(name, "name");
return this;
}
@XmlAttribute(required = true)
public String getValue() {
return value;
}
public PropertyTO setValue(
@Nonnull
String value
) {
requireNonNull(value, "value");
this.value = value;
return this;
}
}

View File

@@ -0,0 +1,355 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import static org.opentcs.data.ObjectPropConstants.LOCTYPE_DEFAULT_REPRESENTATION;
import static org.opentcs.data.ObjectPropConstants.LOC_DEFAULT_REPRESENTATION;
import java.io.IOException;
import java.io.Reader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import org.opentcs.data.model.visualization.LocationRepresentation;
import org.opentcs.util.persistence.v004.V004ModelParser;
import org.opentcs.util.persistence.v004.V004PlantModelTO;
/**
* The parser for V005 models.
*/
public class V005ModelParser {
/**
* Creates a new instance.
*/
public V005ModelParser() {
}
/**
* Reads a model with the given reader and parses it to a {@link V005PlantModelTO} instance.
*
* @param reader The reader to use.
* @param modelVersion The model version.
* @return The parsed {@link V005PlantModelTO}.
* @throws IOException If there was an error reading the model.
*/
public V005PlantModelTO readRaw(Reader reader, String modelVersion)
throws IOException {
if (Objects.equals(modelVersion, V005PlantModelTO.VERSION_STRING)) {
return V005PlantModelTO.fromXml(reader);
}
else {
return convert(new V004ModelParser().readRaw(reader, modelVersion));
}
}
private V005PlantModelTO convert(V004PlantModelTO to) {
return new V005PlantModelTO()
.setName(to.getName())
.setPoints(convertPoints(to))
.setPaths(convertPaths(to))
.setVehicles(convertVehicles(to))
.setLocationTypes(convertLocationTypes(to))
.setLocations(convertLocations(to))
.setBlocks(convertBlocks(to))
.setVisualLayout(convertVisualLayout(to))
.setProperties(convertProperties(to.getProperties()));
}
private List<PropertyTO> convertProperties(
List<org.opentcs.util.persistence.v004.PropertyTO> tos
) {
return tos.stream()
.map(property -> new PropertyTO().setName(property.getName()).setValue(property.getValue()))
.toList();
}
private List<PointTO> convertPoints(V004PlantModelTO to) {
return to.getPoints().stream()
.map(point -> {
PointTO result = new PointTO();
result.setName(point.getName())
.setProperties(convertProperties(point.getProperties()));
result.setxPosition(point.getxPosition())
.setyPosition(point.getyPosition())
.setzPosition(point.getzPosition())
.setVehicleOrientationAngle(point.getVehicleOrientationAngle())
.setType(point.getType())
.setVehicleEnvelopes(convertVehicleEnvelopes(point.getVehicleEnvelopes()))
.setOutgoingPaths(convertOutgoingPaths(point))
.setPointLayout(
new PointTO.PointLayout()
.setxPosition(point.getPointLayout().getxPosition())
.setyPosition(point.getPointLayout().getyPosition())
.setxLabelOffset(point.getPointLayout().getxLabelOffset())
.setyLabelOffset(point.getPointLayout().getyLabelOffset())
.setLayerId(point.getPointLayout().getLayerId())
);
return result;
})
.toList();
}
private List<VehicleEnvelopeTO> convertVehicleEnvelopes(
List<org.opentcs.util.persistence.v004.VehicleEnvelopeTO> tos
) {
return tos.stream()
.map(
vehicleEnvelope -> new VehicleEnvelopeTO()
.setKey(vehicleEnvelope.getKey())
.setVertices(
vehicleEnvelope.getVertices().stream()
.map(
couple -> new CoupleTO()
.setX(couple.getX())
.setY(couple.getY())
)
.toList()
)
)
.toList();
}
private Map<String, String> toPropertiesMap(
List<org.opentcs.util.persistence.v004.PropertyTO> properties
) {
Map<String, String> result = new HashMap<>();
for (org.opentcs.util.persistence.v004.PropertyTO property : properties) {
result.put(property.getName(), property.getValue());
}
return result;
}
private List<PointTO.OutgoingPath> convertOutgoingPaths(
org.opentcs.util.persistence.v004.PointTO to
) {
return to.getOutgoingPaths().stream()
.map(path -> new PointTO.OutgoingPath().setName(path.getName()))
.toList();
}
private List<PathTO> convertPaths(V004PlantModelTO to) {
return to.getPaths().stream()
.map(path -> {
PathTO result = new PathTO();
result.setName(path.getName())
.setProperties(convertProperties(path.getProperties()));
result.setSourcePoint(path.getSourcePoint())
.setDestinationPoint(path.getDestinationPoint())
.setLength(path.getLength())
.setMaxVelocity(path.getMaxVelocity())
.setMaxReverseVelocity(path.getMaxReverseVelocity())
.setPeripheralOperations(convertPeripheralOperations(path.getPeripheralOperations()))
.setLocked(path.isLocked())
.setVehicleEnvelopes(convertVehicleEnvelopes(path.getVehicleEnvelopes()))
.setPathLayout(
new PathTO.PathLayout()
.setConnectionType(path.getPathLayout().getConnectionType())
.setControlPoints(
path.getPathLayout().getControlPoints().stream()
.map(
controlPoint -> new PathTO.ControlPoint()
.setX(controlPoint.getX())
.setY(controlPoint.getY())
)
.toList()
)
.setLayerId(path.getPathLayout().getLayerId())
);
return result;
})
.toList();
}
private List<PeripheralOperationTO> convertPeripheralOperations(
List<org.opentcs.util.persistence.v004.PeripheralOperationTO> tos
) {
return tos.stream()
.map(
peripheralOperation -> {
PeripheralOperationTO result = new PeripheralOperationTO();
result.setName(peripheralOperation.getName())
.setProperties(convertProperties(peripheralOperation.getProperties()));
result.setLocationName(peripheralOperation.getLocationName())
.setExecutionTrigger(peripheralOperation.getExecutionTrigger())
.setCompletionRequired(peripheralOperation.isCompletionRequired());
return result;
}
)
.toList();
}
private List<VehicleTO> convertVehicles(V004PlantModelTO to) {
return to.getVehicles().stream()
.map(vehicle -> {
VehicleTO result = new VehicleTO();
result.setName(vehicle.getName())
.setProperties(convertProperties(vehicle.getProperties()));
result.setLength(vehicle.getLength())
.setEnergyLevelCritical(vehicle.getEnergyLevelCritical())
.setEnergyLevelGood(vehicle.getEnergyLevelGood())
.setEnergyLevelFullyRecharged(vehicle.getEnergyLevelFullyRecharged())
.setEnergyLevelSufficientlyRecharged(vehicle.getEnergyLevelSufficientlyRecharged())
.setMaxVelocity(vehicle.getMaxVelocity())
.setMaxReverseVelocity(vehicle.getMaxReverseVelocity())
.setEnvelopeKey(vehicle.getEnvelopeKey())
.setVehicleLayout(
new VehicleTO.VehicleLayout()
.setColor(vehicle.getVehicleLayout().getColor())
);
return result;
})
.toList();
}
private List<LocationTypeTO> convertLocationTypes(V004PlantModelTO to) {
return to.getLocationTypes().stream()
.map(locationType -> {
String locationRepresentation = toPropertiesMap(locationType.getProperties())
.getOrDefault(LOCTYPE_DEFAULT_REPRESENTATION, LocationRepresentation.NONE.name());
LocationTypeTO result = new LocationTypeTO();
result.setName(locationType.getName())
.setProperties(convertProperties(locationType.getProperties()));
result.setAllowedOperations(convertAllowedOperations(locationType.getAllowedOperations()))
.setAllowedPeripheralOperations(
convertAllowedPeripheralOperations(locationType.getAllowedPeripheralOperations())
)
.setLocationTypeLayout(
new LocationTypeTO.LocationTypeLayout()
.setLocationRepresentation(locationRepresentation)
);
return result;
})
.toList();
}
private List<AllowedOperationTO> convertAllowedOperations(
List<org.opentcs.util.persistence.v004.AllowedOperationTO> tos
) {
return tos.stream()
.map(allowedOperation -> {
AllowedOperationTO result = new AllowedOperationTO();
result.setName(allowedOperation.getName());
result.setProperties(convertProperties(allowedOperation.getProperties()));
return result;
})
.toList();
}
private List<AllowedPeripheralOperationTO> convertAllowedPeripheralOperations(
List<org.opentcs.util.persistence.v004.AllowedPeripheralOperationTO> tos
) {
return tos.stream()
.map(
allowedPeripheralOperation -> {
AllowedPeripheralOperationTO result = new AllowedPeripheralOperationTO();
result.setName(allowedPeripheralOperation.getName());
result.setProperties(convertProperties(allowedPeripheralOperation.getProperties()));
return result;
}
)
.toList();
}
private List<LocationTO> convertLocations(V004PlantModelTO to) {
return to.getLocations().stream()
.map(location -> {
String locationRepresentation = toPropertiesMap(location.getProperties())
.getOrDefault(LOC_DEFAULT_REPRESENTATION, LocationRepresentation.DEFAULT.name());
LocationTO result = new LocationTO();
result.setName(location.getName())
.setProperties(convertProperties(location.getProperties()));
result.setxPosition(location.getxPosition())
.setyPosition(location.getyPosition())
.setzPosition(location.getzPosition())
.setType(location.getType())
.setLinks(convertLinks(location))
.setLocked(location.isLocked())
.setLocationLayout(
new LocationTO.LocationLayout()
.setxPosition(location.getLocationLayout().getxPosition())
.setyPosition(location.getLocationLayout().getyPosition())
.setxLabelOffset(location.getLocationLayout().getxLabelOffset())
.setyLabelOffset(location.getLocationLayout().getyLabelOffset())
.setLocationRepresentation(locationRepresentation)
.setLayerId(location.getLocationLayout().getLayerId())
);
return result;
})
.toList();
}
private List<LocationTO.Link> convertLinks(org.opentcs.util.persistence.v004.LocationTO to) {
return to.getLinks().stream()
.map(link -> {
return new LocationTO.Link()
.setPoint(link.getPoint())
.setAllowedOperations(convertAllowedOperations(link.getAllowedOperations()));
})
.toList();
}
private List<BlockTO> convertBlocks(V004PlantModelTO to) {
return to.getBlocks().stream()
.map(block -> {
BlockTO result = new BlockTO();
result.setName(block.getName())
.setProperties(convertProperties(block.getProperties()));
result.setType(block.getType())
.setMembers(convertMembers(block.getMembers()))
.setBlockLayout(
new BlockTO.BlockLayout()
.setColor(block.getBlockLayout().getColor())
);
return result;
})
.toList();
}
private List<MemberTO> convertMembers(List<org.opentcs.util.persistence.v004.MemberTO> tos) {
return tos.stream()
.map(member -> {
MemberTO result = new MemberTO();
result.setName(member.getName())
.setProperties(convertProperties(member.getProperties()));
return result;
})
.toList();
}
private VisualLayoutTO convertVisualLayout(V004PlantModelTO to) {
VisualLayoutTO result = new VisualLayoutTO()
.setScaleX(to.getVisualLayout().getScaleX())
.setScaleY(to.getVisualLayout().getScaleY())
.setLayers(
to.getVisualLayout().getLayers().stream()
.map(
layer -> new VisualLayoutTO.Layer()
.setId(layer.getId())
.setOrdinal(layer.getOrdinal())
.setVisible(layer.isVisible())
.setName(layer.getName())
.setGroupId(layer.getGroupId())
)
.toList()
)
.setLayerGroups(
to.getVisualLayout().getLayerGroups().stream()
.map(
layerGroup -> new VisualLayoutTO.LayerGroup()
.setId(layerGroup.getId())
.setName(layerGroup.getName())
.setVisible(layerGroup.isVisible())
)
.toList()
);
result
.setProperties(convertProperties(to.getVisualLayout().getProperties()))
.setName(to.getVisualLayout().getName());
return result;
}
}

View File

@@ -0,0 +1,260 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.opentcs.util.persistence.BasePlantModelTO;
import org.xml.sax.SAXException;
/**
*/
@XmlRootElement(name = "model")
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"version", "name", "points", "paths", "vehicles", "locationTypes",
"locations", "blocks", "visualLayout", "properties"}
)
public class V005PlantModelTO
extends
BasePlantModelTO {
/**
* This plant model implementation's version string.
*/
public static final String VERSION_STRING = "0.0.5";
private String name = "";
private List<PointTO> points = new ArrayList<>();
private List<PathTO> paths = new ArrayList<>();
private List<VehicleTO> vehicles = new ArrayList<>();
private List<LocationTypeTO> locationTypes = new ArrayList<>();
private List<LocationTO> locations = new ArrayList<>();
private List<BlockTO> blocks = new ArrayList<>();
private VisualLayoutTO visualLayout = new VisualLayoutTO();
private List<PropertyTO> properties = new ArrayList<>();
/**
* Creates a new instance.
*/
public V005PlantModelTO() {
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public V005PlantModelTO setName(
@Nonnull
String name
) {
requireNonNull(name, "name");
this.name = name;
return this;
}
@XmlElement(name = "point")
public List<PointTO> getPoints() {
return points;
}
public V005PlantModelTO setPoints(
@Nonnull
List<PointTO> points
) {
requireNonNull(points, "points");
this.points = points;
return this;
}
@XmlElement(name = "path")
public List<PathTO> getPaths() {
return paths;
}
public V005PlantModelTO setPaths(
@Nonnull
List<PathTO> paths
) {
requireNonNull(paths, "paths");
this.paths = paths;
return this;
}
@XmlElement(name = "vehicle")
public List<VehicleTO> getVehicles() {
return vehicles;
}
public V005PlantModelTO setVehicles(
@Nonnull
List<VehicleTO> vehicles
) {
requireNonNull(vehicles, "vehicles");
this.vehicles = vehicles;
return this;
}
@XmlElement(name = "locationType")
public List<LocationTypeTO> getLocationTypes() {
return locationTypes;
}
public V005PlantModelTO setLocationTypes(
@Nonnull
List<LocationTypeTO> locationTypes
) {
requireNonNull(locationTypes, "locationTypes");
this.locationTypes = locationTypes;
return this;
}
@XmlElement(name = "location")
public List<LocationTO> getLocations() {
return locations;
}
public V005PlantModelTO setLocations(
@Nonnull
List<LocationTO> locations
) {
requireNonNull(locations, "locations");
this.locations = locations;
return this;
}
@XmlElement(name = "block")
public List<BlockTO> getBlocks() {
return blocks;
}
public V005PlantModelTO setBlocks(
@Nonnull
List<BlockTO> blocks
) {
requireNonNull(blocks, "blocks");
this.blocks = blocks;
return this;
}
@XmlElement
public VisualLayoutTO getVisualLayout() {
return visualLayout;
}
public V005PlantModelTO setVisualLayout(
@Nonnull
VisualLayoutTO visualLayout
) {
this.visualLayout = requireNonNull(visualLayout, "visualLayout");
return this;
}
@XmlElement(name = "property")
public List<PropertyTO> getProperties() {
return properties;
}
public V005PlantModelTO setProperties(
@Nonnull
List<PropertyTO> properties
) {
requireNonNull(properties, "properties");
this.properties = properties;
return this;
}
/**
* Marshals this instance to its XML representation and writes it to the given writer.
*
* @param writer The writer to write this instance's XML representation to.
* @throws IOException If there was a problem marshalling this instance.
*/
public void toXml(
@Nonnull
Writer writer
)
throws IOException {
requireNonNull(writer, "writer");
try {
createMarshaller().marshal(this, writer);
}
catch (JAXBException | SAXException exc) {
throw new IOException("Exception marshalling data", exc);
}
}
/**
* Unmarshals an instance of this class from the given XML representation.
*
* @param reader Provides the XML representation to parse to an instance.
* @return The instance unmarshalled from the given reader.
* @throws IOException If there was a problem unmarshalling the given string.
*/
public static V005PlantModelTO fromXml(
@Nonnull
Reader reader
)
throws IOException {
requireNonNull(reader, "reader");
try {
return (V005PlantModelTO) createUnmarshaller().unmarshal(reader);
}
catch (JAXBException | SAXException exc) {
throw new IOException("Exception unmarshalling data", exc);
}
}
private static Marshaller createMarshaller()
throws JAXBException,
SAXException {
Marshaller marshaller = createContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setSchema(createSchema());
return marshaller;
}
private static Unmarshaller createUnmarshaller()
throws JAXBException,
SAXException {
Unmarshaller unmarshaller = createContext().createUnmarshaller();
unmarshaller.setSchema(createSchema());
return unmarshaller;
}
private static JAXBContext createContext()
throws JAXBException {
return JAXBContext.newInstance(V005PlantModelTO.class);
}
private static Schema createSchema()
throws SAXException {
URL schemaUrl
= V005PlantModelTO.class.getResource("/org/opentcs/util/persistence/model-0.0.5.xsd");
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
return schemaFactory.newSchema(schemaUrl);
}
}

View File

@@ -0,0 +1,52 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"key", "vertices"})
public class VehicleEnvelopeTO {
private String key;
private List<CoupleTO> vertices;
public VehicleEnvelopeTO() {
}
public String getKey() {
return key;
}
@XmlAttribute
public VehicleEnvelopeTO setKey(
@Nonnull
String key
) {
this.key = requireNonNull(key, "key");
return this;
}
@XmlElement(name = "vertex")
public List<CoupleTO> getVertices() {
return vertices;
}
public VehicleEnvelopeTO setVertices(
@Nonnull
List<CoupleTO> vertices
) {
this.vertices = requireNonNull(vertices, "vertices");
return this;
}
}

View File

@@ -0,0 +1,200 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"name", "length", "energyLevelCritical", "energyLevelGood",
"energyLevelFullyRecharged", "energyLevelSufficientlyRecharged",
"maxVelocity", "maxReverseVelocity", "properties", "vehicleLayout"}
)
public class VehicleTO
extends
PlantModelElementTO {
//max velocity in mm/s.
private int maxVelocity;
//max rev velocity in mm/s.
private int maxReverseVelocity;
private Long length = 0L;
private Long energyLevelCritical = 0L;
private Long energyLevelGood = 0L;
private Long energyLevelFullyRecharged = 0L;
private Long energyLevelSufficientlyRecharged = 0L;
private String envelopeKey;
private VehicleLayout vehicleLayout = new VehicleLayout();
/**
* Creates a new instance.
*/
public VehicleTO() {
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public Long getLength() {
return length;
}
public VehicleTO setLength(
@Nonnull
Long length
) {
requireNonNull(length, "length");
this.length = length;
return this;
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public Long getEnergyLevelCritical() {
return energyLevelCritical;
}
public VehicleTO setEnergyLevelCritical(
@Nonnull
Long energyLevelCritical
) {
requireNonNull(energyLevelCritical, "energyLevelCritical");
this.energyLevelCritical = energyLevelCritical;
return this;
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public Long getEnergyLevelGood() {
return energyLevelGood;
}
public VehicleTO setEnergyLevelGood(
@Nonnull
Long energyLevelGood
) {
requireNonNull(energyLevelGood, "energyLevelGood");
this.energyLevelGood = energyLevelGood;
return this;
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public Long getEnergyLevelFullyRecharged() {
return energyLevelFullyRecharged;
}
public VehicleTO setEnergyLevelFullyRecharged(
@Nonnull
Long energyLevelFullyRecharged
) {
requireNonNull(energyLevelFullyRecharged, "energyLevelFullyRecharged");
this.energyLevelFullyRecharged = energyLevelFullyRecharged;
return this;
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public Long getEnergyLevelSufficientlyRecharged() {
return energyLevelSufficientlyRecharged;
}
public VehicleTO setEnergyLevelSufficientlyRecharged(
@Nonnull
Long energyLevelSufficientlyRecharged
) {
requireNonNull(energyLevelSufficientlyRecharged, "energyLevelSufficientlyRecharged");
this.energyLevelSufficientlyRecharged = energyLevelSufficientlyRecharged;
return this;
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public int getMaxVelocity() {
return maxVelocity;
}
public VehicleTO setMaxVelocity(
@Nonnull
int maxVelocity
) {
this.maxVelocity = maxVelocity;
return this;
}
@XmlAttribute
@XmlSchemaType(name = "unsignedInt")
public int getMaxReverseVelocity() {
return maxReverseVelocity;
}
public VehicleTO setMaxReverseVelocity(
@Nonnull
int maxReverseVelocity
) {
this.maxReverseVelocity = maxReverseVelocity;
return this;
}
@XmlAttribute
@Nullable
public String getEnvelopeKey() {
return envelopeKey;
}
public VehicleTO setEnvelopeKey(
@Nullable
String envelopeKey
) {
this.envelopeKey = envelopeKey;
return this;
}
@XmlElement(required = true)
public VehicleLayout getVehicleLayout() {
return vehicleLayout;
}
public VehicleTO setVehicleLayout(
@Nonnull
VehicleLayout vehicleLayout
) {
this.vehicleLayout = requireNonNull(vehicleLayout, "vehicleLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class VehicleLayout {
private String color = "";
/**
* Creates a new instance.
*/
public VehicleLayout() {
}
@XmlAttribute(required = true)
public String getColor() {
return color;
}
public VehicleLayout setColor(
@Nonnull
String color
) {
this.color = requireNonNull(color, "color");
return this;
}
}
}

View File

@@ -0,0 +1,200 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v005;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"name", "scaleX", "scaleY", "layers", "layerGroups", "properties"})
public class VisualLayoutTO
extends
PlantModelElementTO {
private Float scaleX = 0.0F;
private Float scaleY = 0.0F;
private List<Layer> layers = new ArrayList<>();
private List<LayerGroup> layerGroups = new ArrayList<>();
/**
* Creates a new instance.
*/
public VisualLayoutTO() {
}
@XmlAttribute(required = true)
public Float getScaleX() {
return scaleX;
}
public VisualLayoutTO setScaleX(
@Nonnull
Float scaleX
) {
requireNonNull(scaleX, "scaleX");
this.scaleX = scaleX;
return this;
}
@XmlAttribute(required = true)
public Float getScaleY() {
return scaleY;
}
public VisualLayoutTO setScaleY(
@Nonnull
Float scaleY
) {
requireNonNull(scaleY, "scaleY");
this.scaleY = scaleY;
return this;
}
@XmlElement(name = "layer")
public List<Layer> getLayers() {
return layers;
}
public VisualLayoutTO setLayers(
@Nonnull
List<Layer> layers
) {
this.layers = requireNonNull(layers, "layers");
return this;
}
@XmlElement(name = "layerGroup")
public List<LayerGroup> getLayerGroups() {
return layerGroups;
}
public VisualLayoutTO setLayerGroups(
@Nonnull
List<LayerGroup> layerGroups
) {
this.layerGroups = requireNonNull(layerGroups, "layerGroups");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"id", "ordinal", "visible", "name", "groupId"})
public static class Layer {
private Integer id = 0;
private Integer ordinal = 0;
private Boolean visible = true;
private String name = "";
private Integer groupId = 0;
/**
* Creates a new instance.
*/
public Layer() {
}
@XmlAttribute(required = true)
public Integer getId() {
return id;
}
public Layer setId(Integer id) {
this.id = requireNonNull(id, "id");
return this;
}
@XmlAttribute(required = true)
public Integer getOrdinal() {
return ordinal;
}
public Layer setOrdinal(Integer ordinal) {
this.ordinal = requireNonNull(ordinal, "ordinal");
return this;
}
@XmlAttribute(required = true)
public Boolean isVisible() {
return visible;
}
public Layer setVisible(Boolean visible) {
this.visible = requireNonNull(visible, "visible");
return this;
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public Layer setName(String name) {
this.name = requireNonNull(name, "name");
return this;
}
@XmlAttribute(required = true)
public Integer getGroupId() {
return groupId;
}
public Layer setGroupId(Integer groupId) {
this.groupId = requireNonNull(groupId, "groupId");
return this;
}
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"id", "name", "visible"})
public static class LayerGroup {
private Integer id = 0;
private String name = "";
private Boolean visible = true;
/**
* Creates a new instance.
*/
public LayerGroup() {
}
@XmlAttribute(required = true)
public Integer getId() {
return id;
}
public LayerGroup setId(Integer id) {
this.id = requireNonNull(id, "id");
return this;
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public LayerGroup setName(String name) {
this.name = requireNonNull(name, "name");
return this;
}
@XmlAttribute(required = true)
public Boolean isVisible() {
return visible;
}
public LayerGroup setVisible(Boolean visible) {
this.visible = requireNonNull(visible, "visible");
return this;
}
}
}

View File

@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AllowedOperationTO
extends
PlantModelElementTO {
/**
* Creates a new instance.
*/
public AllowedOperationTO() {
}
}

View File

@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
public class AllowedPeripheralOperationTO
extends
PlantModelElementTO {
/**
* Creates a new instance.
*/
public AllowedPeripheralOperationTO() {
}
}

View File

@@ -0,0 +1,99 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"name", "type", "members", "properties", "blockLayout"})
public class BlockTO
extends
PlantModelElementTO {
private String type = "SINGLE_VEHICLE_ONLY";
private List<MemberTO> members = new ArrayList<>();
private BlockLayout blockLayout = new BlockLayout();
/**
* Creates a new instance.
*/
public BlockTO() {
}
@XmlAttribute(required = true)
public String getType() {
return type;
}
public BlockTO setType(
@Nonnull
String type
) {
requireNonNull(type, "type");
this.type = type;
return this;
}
@XmlElement(name = "member")
public List<MemberTO> getMembers() {
return members;
}
public BlockTO setMembers(
@Nonnull
List<MemberTO> members
) {
requireNonNull(members, "members");
this.members = members;
return this;
}
@XmlElement(required = true)
public BlockLayout getBlockLayout() {
return blockLayout;
}
public BlockTO setBlockLayout(
@Nonnull
BlockLayout blockLayout
) {
this.blockLayout = requireNonNull(blockLayout, "blockLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class BlockLayout {
private String color = "";
/**
* Creates a new instance.
*/
public BlockLayout() {
}
@XmlAttribute(required = true)
public String getColor() {
return color;
}
public BlockLayout setColor(
@Nonnull
String color
) {
this.color = requireNonNull(color, "color");
return this;
}
}
}

View File

@@ -0,0 +1,77 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"length", "width", "height", "referenceOffsetX", "referenceOffsetY"})
public class BoundingBoxTO {
private long length;
private long width;
private long height;
private long referenceOffsetX;
private long referenceOffsetY;
/**
* Creates a new instance.
*/
public BoundingBoxTO() {
}
@XmlAttribute(required = true)
public long getLength() {
return length;
}
public BoundingBoxTO setLength(long length) {
this.length = length;
return this;
}
@XmlAttribute(required = true)
public long getWidth() {
return width;
}
public BoundingBoxTO setWidth(long width) {
this.width = width;
return this;
}
@XmlAttribute(required = true)
public long getHeight() {
return height;
}
public BoundingBoxTO setHeight(long height) {
this.height = height;
return this;
}
@XmlAttribute(required = true)
public long getReferenceOffsetX() {
return referenceOffsetX;
}
public BoundingBoxTO setReferenceOffsetX(long referenceOffsetX) {
this.referenceOffsetX = referenceOffsetX;
return this;
}
@XmlAttribute(required = true)
public long getReferenceOffsetY() {
return referenceOffsetY;
}
public BoundingBoxTO setReferenceOffsetY(long referenceOffsetY) {
this.referenceOffsetY = referenceOffsetY;
return this;
}
}

View File

@@ -0,0 +1,53 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import java.util.Comparator;
/**
* Some comparator implementations for JAXB classes.
*/
public final class Comparators {
/**
* Prevents instantiation.
*/
private Comparators() {
}
/**
* Returns a comparator for ordering <code>PlantModelElementTO</code>s ascendingly by their names.
*
* @return A comparator for ordering <code>PlantModelElementTO</code>s ascendingly by their names.
*/
public static Comparator<PlantModelElementTO> elementsByName() {
return Comparator.comparing(PlantModelElementTO::getName);
}
/**
* Returns a comparator for ordering <code>OutgoingPath</code>s ascendingly by their names.
*
* @return A comparator for ordering <code>OutgoingPath</code>s ascendingly by their names.
*/
public static Comparator<PointTO.OutgoingPath> outgoingPathsByName() {
return Comparator.comparing(PointTO.OutgoingPath::getName);
}
/**
* Returns a comparator for ordering <code>Link</code>s ascendingly by their point names.
*
* @return A comparator for ordering <code>Link</code>s ascendingly by their point names.
*/
public static Comparator<LocationTO.Link> linksByPointName() {
return Comparator.comparing(LocationTO.Link::getPoint);
}
/**
* Returns a comparator for ordering <code>Properties</code>s ascendingly by their names.
*
* @return A comparator for ordering <code>Properties</code> ascendingly by their names.
*/
public static Comparator<PropertyTO> propertiesByName() {
return Comparator.comparing(PropertyTO::getName);
}
}

View File

@@ -0,0 +1,50 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"x", "y"})
public class CoupleTO {
private Long x;
private Long y;
public CoupleTO() {
}
@XmlAttribute(required = true)
public Long getX() {
return x;
}
public CoupleTO setX(
@Nonnull
Long x
) {
this.x = requireNonNull(x, "x");
return this;
}
@XmlAttribute(required = true)
public Long getY() {
return y;
}
public CoupleTO setY(
@Nonnull
Long y
) {
this.y = requireNonNull(y, "y");
return this;
}
}

View File

@@ -0,0 +1,259 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"name", "positionX", "positionY", "positionZ", "links", "locked",
"properties", "locationLayout"}
)
public class LocationTO
extends
PlantModelElementTO {
private Long positionX = 0L;
private Long positionY = 0L;
private Long positionZ = 0L;
private String type = "";
private List<Link> links = new ArrayList<>();
private Boolean locked = false;
private LocationLayout locationLayout = new LocationLayout();
/**
* Creates a new instance.
*/
public LocationTO() {
}
@XmlAttribute(required = true)
public Long getPositionX() {
return positionX;
}
public LocationTO setPositionX(
@Nonnull
Long positionX
) {
requireNonNull(positionX, "positionX");
this.positionX = positionX;
return this;
}
@XmlAttribute(required = true)
public Long getPositionY() {
return positionY;
}
public LocationTO setPositionY(
@Nonnull
Long positionY
) {
requireNonNull(positionY, "positionY");
this.positionY = positionY;
return this;
}
@XmlAttribute(required = true)
public Long getPositionZ() {
return positionZ;
}
public LocationTO setPositionZ(
@Nonnull
Long positionZ
) {
requireNonNull(positionZ, "positionZ");
this.positionZ = positionZ;
return this;
}
@XmlAttribute
public String getType() {
return type;
}
public LocationTO setType(
@Nonnull
String type
) {
requireNonNull(type, "type");
this.type = type;
return this;
}
@XmlElement(name = "link", required = true)
public List<Link> getLinks() {
return links;
}
public LocationTO setLinks(
@Nonnull
List<Link> links
) {
requireNonNull(links, "links");
this.links = links;
return this;
}
@XmlAttribute(required = true)
public Boolean isLocked() {
return locked;
}
public LocationTO setLocked(Boolean locked) {
this.locked = locked;
return this;
}
@XmlElement(required = true)
public LocationLayout getLocationLayout() {
return locationLayout;
}
public LocationTO setLocationLayout(
@Nonnull
LocationLayout locationLayout
) {
this.locationLayout = requireNonNull(locationLayout, "locationLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"point", "allowedOperations"})
public static class Link {
private String point = "";
private List<AllowedOperationTO> allowedOperations = new ArrayList<>();
/**
* Creates a new instance.
*/
public Link() {
}
@XmlAttribute(required = true)
public String getPoint() {
return point;
}
public Link setPoint(
@Nonnull
String point
) {
requireNonNull(point, "point");
this.point = point;
return this;
}
@XmlElement(name = "allowedOperation")
public List<AllowedOperationTO> getAllowedOperations() {
return allowedOperations;
}
public Link setAllowedOperations(
@Nonnull
List<AllowedOperationTO> allowedOperations
) {
requireNonNull(allowedOperations, "allowedOperations");
this.allowedOperations = allowedOperations;
return this;
}
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"positionX", "positionY", "labelOffsetX", "labelOffsetY",
"locationRepresentation", "layerId"}
)
public static class LocationLayout {
private Long positionX = 0L;
private Long positionY = 0L;
private Long labelOffsetX = 0L;
private Long labelOffsetY = 0L;
private String locationRepresentation = "";
private Integer layerId = 0;
/**
* Creates a new instance.
*/
public LocationLayout() {
}
@XmlAttribute(required = true)
public Long getPositionX() {
return positionX;
}
public LocationLayout setPositionX(Long positionX) {
this.positionX = requireNonNull(positionX, "positionX");
return this;
}
@XmlAttribute(required = true)
public Long getPositionY() {
return positionY;
}
public LocationLayout setPositionY(Long positionY) {
this.positionY = requireNonNull(positionY, "positionY");
return this;
}
@XmlAttribute(required = true)
public Long getLabelOffsetX() {
return labelOffsetX;
}
public LocationLayout setLabelOffsetX(Long labelOffsetX) {
this.labelOffsetX = requireNonNull(labelOffsetX, "labelOffsetX");
return this;
}
@XmlAttribute(required = true)
public Long getLabelOffsetY() {
return labelOffsetY;
}
public LocationLayout setLabelOffsetY(Long labelOffsetY) {
this.labelOffsetY = requireNonNull(labelOffsetY, "labelOffsetY");
return this;
}
@XmlAttribute(required = true)
public String getLocationRepresentation() {
return locationRepresentation;
}
public LocationLayout setLocationRepresentation(String locationRepresentation) {
this.locationRepresentation = requireNonNull(
locationRepresentation,
"locationRepresentation"
);
return this;
}
@XmlAttribute(required = true)
public Integer getLayerId() {
return layerId;
}
public LocationLayout setLayerId(Integer layerId) {
this.layerId = requireNonNull(layerId, "layerId");
return this;
}
}
}

View File

@@ -0,0 +1,108 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"name",
"allowedOperations",
"allowedPeripheralOperations",
"properties",
"locationTypeLayout"}
)
public class LocationTypeTO
extends
PlantModelElementTO {
private List<AllowedOperationTO> allowedOperations = new ArrayList<>();
private List<AllowedPeripheralOperationTO> allowedPeripheralOperations = new ArrayList<>();
private LocationTypeLayout locationTypeLayout = new LocationTypeLayout();
/**
* Creates a new instance.
*/
public LocationTypeTO() {
}
@XmlElement(name = "allowedOperation")
public List<AllowedOperationTO> getAllowedOperations() {
return allowedOperations;
}
public LocationTypeTO setAllowedOperations(
@Nonnull
List<AllowedOperationTO> allowedOperations
) {
this.allowedOperations = requireNonNull(allowedOperations, "allowedOperations");
return this;
}
@XmlElement(name = "allowedPeripheralOperation")
public List<AllowedPeripheralOperationTO> getAllowedPeripheralOperations() {
return allowedPeripheralOperations;
}
public LocationTypeTO setAllowedPeripheralOperations(
List<AllowedPeripheralOperationTO> allowedPeripheralOperations
) {
this.allowedPeripheralOperations = requireNonNull(
allowedPeripheralOperations,
"allowedPeripheralOperations"
);
return this;
}
@XmlElement(required = true)
public LocationTypeLayout getLocationTypeLayout() {
return locationTypeLayout;
}
public LocationTypeTO setLocationTypeLayout(
@Nonnull
LocationTypeLayout locationTypeLayout
) {
this.locationTypeLayout = requireNonNull(locationTypeLayout, "locationTypeLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class LocationTypeLayout {
private String locationRepresentation = "";
/**
* Creates a new instance.
*/
public LocationTypeLayout() {
}
@XmlAttribute(required = true)
public String getLocationRepresentation() {
return locationRepresentation;
}
public LocationTypeLayout setLocationRepresentation(
@Nonnull
String locationRepresentation
) {
this.locationRepresentation = requireNonNull(
locationRepresentation,
"locationRepresentation"
);
return this;
}
}
}

View File

@@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
public class MemberTO
extends
PlantModelElementTO {
/**
* Creates a new instance.
*/
public MemberTO() {
}
}

View File

@@ -0,0 +1,265 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"name",
"sourcePoint",
"destinationPoint",
"length",
"maxVelocity",
"maxReverseVelocity",
"peripheralOperations",
"locked",
"vehicleEnvelopes",
"properties",
"pathLayout"}
)
public class PathTO
extends
PlantModelElementTO {
private String sourcePoint = "";
private String destinationPoint = "";
private Long length = 0L;
private Long maxVelocity = 0L;
private Long maxReverseVelocity = 0L;
private List<PeripheralOperationTO> peripheralOperations = new ArrayList<>();
private Boolean locked = false;
private List<VehicleEnvelopeTO> vehicleEnvelopes = new ArrayList<>();
private PathLayout pathLayout = new PathLayout();
/**
* Creates a new instance.
*/
public PathTO() {
}
@XmlAttribute(required = true)
public String getSourcePoint() {
return sourcePoint;
}
public PathTO setSourcePoint(
@Nonnull
String sourcePoint
) {
requireNonNull(sourcePoint, "sourcePoint");
this.sourcePoint = sourcePoint;
return this;
}
@XmlAttribute(required = true)
public String getDestinationPoint() {
return destinationPoint;
}
public PathTO setDestinationPoint(
@Nonnull
String destinationPoint
) {
requireNonNull(destinationPoint, "destinationPoint");
this.destinationPoint = destinationPoint;
return this;
}
@XmlAttribute(required = true)
@XmlSchemaType(name = "unsignedInt")
public Long getLength() {
return length;
}
public PathTO setLength(
@Nonnull
Long length
) {
requireNonNull(length, "length");
this.length = length;
return this;
}
@XmlAttribute(required = true)
@XmlSchemaType(name = "unsignedInt")
public Long getMaxVelocity() {
return maxVelocity;
}
public PathTO setMaxVelocity(
@Nonnull
Long maxVelocity
) {
requireNonNull(maxVelocity, "maxVelocity");
this.maxVelocity = maxVelocity;
return this;
}
@XmlAttribute(required = true)
@XmlSchemaType(name = "unsignedInt")
public Long getMaxReverseVelocity() {
return maxReverseVelocity;
}
public PathTO setMaxReverseVelocity(
@Nonnull
Long maxReverseVelocity
) {
requireNonNull(maxReverseVelocity, "maxReverseVelocity");
this.maxReverseVelocity = maxReverseVelocity;
return this;
}
@XmlElement(name = "peripheralOperation")
public List<PeripheralOperationTO> getPeripheralOperations() {
return peripheralOperations;
}
public PathTO setPeripheralOperations(List<PeripheralOperationTO> peripheralOperations) {
this.peripheralOperations = requireNonNull(peripheralOperations, "peripheralOperations");
return this;
}
@XmlAttribute(required = true)
public Boolean isLocked() {
return locked;
}
public PathTO setLocked(Boolean locked) {
this.locked = locked;
return this;
}
@XmlElement(name = "vehicleEnvelope")
public List<VehicleEnvelopeTO> getVehicleEnvelopes() {
return vehicleEnvelopes;
}
public PathTO setVehicleEnvelopes(
@Nonnull
List<VehicleEnvelopeTO> vehicleEnvelopes
) {
this.vehicleEnvelopes = requireNonNull(vehicleEnvelopes, "vehicleEnvelopes");
return this;
}
@XmlElement(required = true)
public PathLayout getPathLayout() {
return pathLayout;
}
public PathTO setPathLayout(
@Nonnull
PathLayout pathLayout
) {
this.pathLayout = requireNonNull(pathLayout, "pathLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"connectionType", "layerId", "controlPoints"})
public static class PathLayout {
private String connectionType = "";
private Integer layerId = 0;
private List<ControlPoint> controlPoints = new ArrayList<>();
/**
* Creates a new instance.
*/
public PathLayout() {
}
@XmlAttribute(required = true)
public String getConnectionType() {
return connectionType;
}
public PathLayout setConnectionType(
@Nonnull
String connectionType
) {
this.connectionType = requireNonNull(connectionType, "connectionType");
return this;
}
@XmlAttribute(required = true)
public Integer getLayerId() {
return layerId;
}
public PathLayout setLayerId(
@Nonnull
Integer layerId
) {
this.layerId = requireNonNull(layerId, "layerId");
return this;
}
@XmlElement(name = "controlPoint")
public List<ControlPoint> getControlPoints() {
return controlPoints;
}
public PathLayout setControlPoints(
@Nonnull
List<ControlPoint> controlPoints
) {
this.controlPoints = requireNonNull(controlPoints, "controlPoints");
return this;
}
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"x", "y"})
public static class ControlPoint {
private Long x = 0L;
private Long y = 0L;
/**
* Creates a new instance.
*/
public ControlPoint() {
}
@XmlAttribute(required = true)
public Long getX() {
return x;
}
public ControlPoint setX(
@Nonnull
Long x
) {
this.x = requireNonNull(x, "x");
return this;
}
@XmlAttribute(required = true)
public Long getY() {
return y;
}
public ControlPoint setY(
@Nonnull
Long y
) {
this.y = requireNonNull(y, "y");
return this;
}
}
}

View File

@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import static java.util.Objects.requireNonNull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
public class PeripheralOperationTO
extends
PlantModelElementTO {
private String locationName = "";
private String executionTrigger = "";
private boolean completionRequired;
/**
* Creates a new instance.
*/
public PeripheralOperationTO() {
}
@XmlAttribute(required = true)
public String getLocationName() {
return locationName;
}
public PeripheralOperationTO setLocationName(String locationName) {
this.locationName = requireNonNull(locationName, "locationName");
return this;
}
@XmlAttribute(required = true)
public String getExecutionTrigger() {
return executionTrigger;
}
public PeripheralOperationTO setExecutionTrigger(String executionTrigger) {
this.executionTrigger = requireNonNull(executionTrigger, "executionTrigger");
return this;
}
@XmlAttribute(required = true)
public boolean isCompletionRequired() {
return completionRequired;
}
public PeripheralOperationTO setCompletionRequired(boolean completionRequired) {
this.completionRequired = completionRequired;
return this;
}
}

View File

@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
/**
*/
@XmlTransient
@XmlAccessorType(XmlAccessType.PROPERTY)
public class PlantModelElementTO {
private String name = "";
private List<PropertyTO> properties = new ArrayList<>();
/**
* Creates a new instance.
*/
public PlantModelElementTO() {
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public PlantModelElementTO setName(
@Nonnull
String name
) {
requireNonNull(name, "name");
this.name = name;
return this;
}
@XmlElement(name = "property")
public List<PropertyTO> getProperties() {
return properties;
}
public PlantModelElementTO setProperties(
@Nonnull
List<PropertyTO> properties
) {
requireNonNull(properties, "properties");
this.properties = properties;
return this;
}
}

View File

@@ -0,0 +1,275 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"name", "positionX", "positionY", "positionZ", "vehicleOrientationAngle",
"type", "maxVehicleBoundingBox", "vehicleEnvelopes", "outgoingPaths", "properties",
"pointLayout"}
)
public class PointTO
extends
PlantModelElementTO {
private Long positionX = 0L;
private Long positionY = 0L;
private Long positionZ = 0L;
private Float vehicleOrientationAngle = 0.0F;
private String type = "HALT_POSITION";
private BoundingBoxTO maxVehicleBoundingBox = new BoundingBoxTO();
private List<VehicleEnvelopeTO> vehicleEnvelopes = new ArrayList<>();
private List<OutgoingPath> outgoingPaths = new ArrayList<>();
private PointLayout pointLayout = new PointLayout();
/**
* Creates a new instance.
*/
public PointTO() {
}
@XmlAttribute(required = true)
public Long getPositionX() {
return positionX;
}
public PointTO setPositionX(
@Nonnull
Long positionX
) {
requireNonNull(positionX, "positionX");
this.positionX = positionX;
return this;
}
@XmlAttribute(required = true)
public Long getPositionY() {
return positionY;
}
public PointTO setPositionY(
@Nonnull
Long positionY
) {
requireNonNull(positionY, "positionY");
this.positionY = positionY;
return this;
}
@XmlAttribute(required = true)
public Long getPositionZ() {
return positionZ;
}
public PointTO setPositionZ(
@Nonnull
Long positionZ
) {
requireNonNull(positionZ, "positionZ");
this.positionZ = positionZ;
return this;
}
@XmlAttribute
public Float getVehicleOrientationAngle() {
return vehicleOrientationAngle;
}
public PointTO setVehicleOrientationAngle(
@Nonnull
Float vehicleOrientationAngle
) {
requireNonNull(vehicleOrientationAngle, "vehicleOrientationAngle");
this.vehicleOrientationAngle = vehicleOrientationAngle;
return this;
}
@XmlAttribute(required = true)
public String getType() {
return type;
}
public PointTO setType(
@Nonnull
String type
) {
requireNonNull(type, "type");
this.type = type;
return this;
}
@XmlElement
@Nonnull
public BoundingBoxTO getMaxVehicleBoundingBox() {
return maxVehicleBoundingBox;
}
public PointTO setMaxVehicleBoundingBox(
@Nonnull
BoundingBoxTO maxVehicleBoundingBox
) {
this.maxVehicleBoundingBox = requireNonNull(maxVehicleBoundingBox, "maxVehicleBoundingBox");
return this;
}
@XmlElement(name = "outgoingPath")
public List<OutgoingPath> getOutgoingPaths() {
return outgoingPaths;
}
public PointTO setOutgoingPaths(
@Nonnull
List<OutgoingPath> outgoingPath
) {
requireNonNull(outgoingPath, "outgoingPath");
this.outgoingPaths = outgoingPath;
return this;
}
@XmlElement(name = "vehicleEnvelope")
public List<VehicleEnvelopeTO> getVehicleEnvelopes() {
return vehicleEnvelopes;
}
public PointTO setVehicleEnvelopes(
@Nonnull
List<VehicleEnvelopeTO> vehicleEnvelopes
) {
this.vehicleEnvelopes = requireNonNull(vehicleEnvelopes, "vehicleEnvelopes");
return this;
}
@XmlElement(required = true)
public PointLayout getPointLayout() {
return pointLayout;
}
public PointTO setPointLayout(
@Nonnull
PointLayout pointLayout
) {
this.pointLayout = requireNonNull(pointLayout, "pointLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class OutgoingPath {
private String name = "";
/**
* Creates a new instance.
*/
public OutgoingPath() {
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public OutgoingPath setName(
@Nonnull
String name
) {
requireNonNull(name, "name");
this.name = name;
return this;
}
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"positionX", "positionY", "labelOffsetX", "labelOffsetY", "layerId"})
public static class PointLayout {
private Long positionX = 0L;
private Long positionY = 0L;
private Long labelOffsetX = 0L;
private Long labelOffsetY = 0L;
private Integer layerId = 0;
/**
* Creates a new instance.
*/
public PointLayout() {
}
@XmlAttribute(required = true)
public Long getPositionX() {
return positionX;
}
public PointLayout setPositionX(
@Nonnull
Long positionX
) {
this.positionX = requireNonNull(positionX, "positionX");
return this;
}
@XmlAttribute(required = true)
public Long getPositionY() {
return positionY;
}
public PointLayout setPositionY(
@Nonnull
Long positionY
) {
this.positionY = requireNonNull(positionY, "positionY");
return this;
}
@XmlAttribute(required = true)
public Long getLabelOffsetX() {
return labelOffsetX;
}
public PointLayout setLabelOffsetX(
@Nonnull
Long labelOffsetX
) {
this.labelOffsetX = requireNonNull(labelOffsetX, "labelOffsetX");
return this;
}
@XmlAttribute(required = true)
public Long getLabelOffsetY() {
return labelOffsetY;
}
public PointLayout setLabelOffsetY(
@Nonnull
Long labelOffsetY
) {
this.labelOffsetY = requireNonNull(labelOffsetY, "labelOffsetY");
return this;
}
@XmlAttribute(required = true)
public Integer getLayerId() {
return layerId;
}
public PointLayout setLayerId(
@Nonnull
Integer layerId
) {
this.layerId = requireNonNull(layerId, "layerId");
return this;
}
}
}

View File

@@ -0,0 +1,54 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"name", "value"})
public class PropertyTO {
private String name = "";
private String value = "";
/**
* Creates a new instance.
*/
public PropertyTO() {
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public PropertyTO setName(
@Nonnull
String name
) {
this.name = requireNonNull(name, "name");
return this;
}
@XmlAttribute(required = true)
public String getValue() {
return value;
}
public PropertyTO setValue(
@Nonnull
String value
) {
requireNonNull(value, "value");
this.value = value;
return this;
}
}

View File

@@ -0,0 +1,407 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import static java.util.Objects.requireNonNull;
import static org.opentcs.data.ObjectPropConstants.LOCTYPE_DEFAULT_REPRESENTATION;
import static org.opentcs.data.ObjectPropConstants.LOC_DEFAULT_REPRESENTATION;
import jakarta.annotation.Nonnull;
import java.io.IOException;
import java.io.Reader;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.opentcs.access.to.model.PlantModelCreationTO;
import org.opentcs.data.model.visualization.LocationRepresentation;
import org.opentcs.util.persistence.v005.V005ModelParser;
import org.opentcs.util.persistence.v005.V005PlantModelTO;
import org.semver4j.Semver;
import org.semver4j.SemverException;
/**
* The parser for V6 models.
*/
public class V6ModelParser {
/**
* The maximum supported schema version for model files.
*/
private static final Semver V6_SUPPORTED_VERSION = new Semver(V6PlantModelTO.VERSION_STRING);
/**
* Creates a new instance.
*/
public V6ModelParser() {
}
/**
* Reads a model with the given reader and parses it to a {@link PlantModelCreationTO} instance.
*
* @param reader The reader to use.
* @param modelVersion The model version.
* @return The parsed {@link PlantModelCreationTO}.
* @throws IOException If there was an error reading the model.
*/
public PlantModelCreationTO read(Reader reader, String modelVersion)
throws IOException {
return new V6TOMapper().map(readRaw(reader, modelVersion));
}
/**
* Reads a model with the given reader and parses it to a {@link V6PlantModelTO} instance.
*
* @param reader The reader to use.
* @param modelVersion The model version.
* @return The parsed {@link V6PlantModelTO}.
* @throws IOException If there was an error reading the model.
*/
public V6PlantModelTO readRaw(
@Nonnull
Reader reader,
@Nonnull
String modelVersion
)
throws IOException {
requireNonNull(reader, "reader");
requireNonNull(modelVersion, "modelVersion");
Semver fileVersionNumber;
try {
fileVersionNumber = new Semver(modelVersion);
}
catch (SemverException e) {
throw new IOException(e);
}
if (fileVersionNumber.getMajor() == V6_SUPPORTED_VERSION.getMajor()
&& fileVersionNumber.isLowerThanOrEqualTo(V6_SUPPORTED_VERSION)) {
return V6PlantModelTO.fromXml(reader);
}
else {
return convert(new V005ModelParser().readRaw(reader, modelVersion));
}
}
private V6PlantModelTO convert(V005PlantModelTO to) {
return new V6PlantModelTO()
.setName(to.getName())
.setPoints(convertPoints(to))
.setPaths(convertPaths(to))
.setVehicles(convertVehicles(to))
.setLocationTypes(convertLocationTypes(to))
.setLocations(convertLocations(to))
.setBlocks(convertBlocks(to))
.setVisualLayout(convertVisualLayout(to))
.setProperties(convertProperties(to.getProperties()));
}
private List<PropertyTO> convertProperties(
List<org.opentcs.util.persistence.v005.PropertyTO> tos
) {
return tos.stream()
.map(property -> new PropertyTO().setName(property.getName()).setValue(property.getValue()))
.toList();
}
private List<PointTO> convertPoints(V005PlantModelTO to) {
return to.getPoints().stream()
.map(point -> {
PointTO result = new PointTO();
result.setName(point.getName())
.setProperties(convertProperties(point.getProperties()));
result.setPositionX(point.getxPosition())
.setPositionY(point.getyPosition())
.setPositionZ(point.getzPosition())
.setVehicleOrientationAngle(point.getVehicleOrientationAngle())
.setType(point.getType())
.setVehicleEnvelopes(convertVehicleEnvelopes(point.getVehicleEnvelopes()))
.setOutgoingPaths(convertOutgoingPaths(point))
.setMaxVehicleBoundingBox(
new BoundingBoxTO()
.setLength(1000)
.setWidth(1000)
.setHeight(1000)
.setReferenceOffsetX(0)
.setReferenceOffsetY(0)
)
.setPointLayout(
new PointTO.PointLayout()
.setPositionX(point.getPointLayout().getxPosition())
.setPositionY(point.getPointLayout().getyPosition())
.setLabelOffsetX(point.getPointLayout().getxLabelOffset())
.setLabelOffsetY(point.getPointLayout().getyLabelOffset())
.setLayerId(point.getPointLayout().getLayerId())
);
return result;
})
.toList();
}
private List<VehicleEnvelopeTO> convertVehicleEnvelopes(
List<org.opentcs.util.persistence.v005.VehicleEnvelopeTO> tos
) {
return tos.stream()
.map(
vehicleEnvelope -> new VehicleEnvelopeTO()
.setKey(vehicleEnvelope.getKey())
.setVertices(
vehicleEnvelope.getVertices().stream()
.map(
couple -> new CoupleTO()
.setX(couple.getX())
.setY(couple.getY())
)
.toList()
)
)
.toList();
}
private Map<String, String> toPropertiesMap(
List<org.opentcs.util.persistence.v005.PropertyTO> properties
) {
Map<String, String> result = new HashMap<>();
for (org.opentcs.util.persistence.v005.PropertyTO property : properties) {
result.put(property.getName(), property.getValue());
}
return result;
}
private List<PointTO.OutgoingPath> convertOutgoingPaths(
org.opentcs.util.persistence.v005.PointTO to
) {
return to.getOutgoingPaths().stream()
.map(path -> new PointTO.OutgoingPath().setName(path.getName()))
.toList();
}
private List<PathTO> convertPaths(V005PlantModelTO to) {
return to.getPaths().stream()
.map(path -> {
PathTO result = new PathTO();
result.setName(path.getName())
.setProperties(convertProperties(path.getProperties()));
result.setSourcePoint(path.getSourcePoint())
.setDestinationPoint(path.getDestinationPoint())
.setLength(path.getLength())
.setMaxVelocity(path.getMaxVelocity())
.setMaxReverseVelocity(path.getMaxReverseVelocity())
.setPeripheralOperations(convertPeripheralOperations(path.getPeripheralOperations()))
.setLocked(path.isLocked())
.setVehicleEnvelopes(convertVehicleEnvelopes(path.getVehicleEnvelopes()))
.setPathLayout(
new PathTO.PathLayout()
.setConnectionType(path.getPathLayout().getConnectionType())
.setControlPoints(
path.getPathLayout().getControlPoints().stream()
.map(
controlPoint -> new PathTO.ControlPoint()
.setX(controlPoint.getX())
.setY(controlPoint.getY())
)
.toList()
)
.setLayerId(path.getPathLayout().getLayerId())
);
return result;
})
.toList();
}
private List<PeripheralOperationTO> convertPeripheralOperations(
List<org.opentcs.util.persistence.v005.PeripheralOperationTO> tos
) {
return tos.stream()
.map(
peripheralOperation -> {
PeripheralOperationTO result = new PeripheralOperationTO();
result.setName(peripheralOperation.getName())
.setProperties(convertProperties(peripheralOperation.getProperties()));
result.setLocationName(peripheralOperation.getLocationName())
.setExecutionTrigger(peripheralOperation.getExecutionTrigger())
.setCompletionRequired(peripheralOperation.isCompletionRequired());
return result;
}
)
.toList();
}
private List<VehicleTO> convertVehicles(V005PlantModelTO to) {
return to.getVehicles().stream()
.map(vehicle -> {
VehicleTO result = new VehicleTO();
result.setName(vehicle.getName())
.setProperties(convertProperties(vehicle.getProperties()));
result.setEnergyLevelCritical(vehicle.getEnergyLevelCritical())
.setEnergyLevelGood(vehicle.getEnergyLevelGood())
.setEnergyLevelFullyRecharged(vehicle.getEnergyLevelFullyRecharged())
.setEnergyLevelSufficientlyRecharged(vehicle.getEnergyLevelSufficientlyRecharged())
.setMaxVelocity(vehicle.getMaxVelocity())
.setMaxReverseVelocity(vehicle.getMaxReverseVelocity())
.setEnvelopeKey(vehicle.getEnvelopeKey())
.setBoundingBox(
new BoundingBoxTO()
.setLength(vehicle.getLength())
.setWidth(1000)
.setHeight(1000)
)
.setVehicleLayout(
new VehicleTO.VehicleLayout()
.setColor(vehicle.getVehicleLayout().getColor())
);
return result;
})
.toList();
}
private List<LocationTypeTO> convertLocationTypes(V005PlantModelTO to) {
return to.getLocationTypes().stream()
.map(locationType -> {
String locationRepresentation = toPropertiesMap(locationType.getProperties())
.getOrDefault(LOCTYPE_DEFAULT_REPRESENTATION, LocationRepresentation.NONE.name());
LocationTypeTO result = new LocationTypeTO();
result.setName(locationType.getName())
.setProperties(convertProperties(locationType.getProperties()));
result.setAllowedOperations(convertAllowedOperations(locationType.getAllowedOperations()))
.setAllowedPeripheralOperations(
convertAllowedPeripheralOperations(locationType.getAllowedPeripheralOperations())
)
.setLocationTypeLayout(
new LocationTypeTO.LocationTypeLayout()
.setLocationRepresentation(locationRepresentation)
);
return result;
})
.toList();
}
private List<AllowedOperationTO> convertAllowedOperations(
List<org.opentcs.util.persistence.v005.AllowedOperationTO> tos
) {
return tos.stream()
.map(allowedOperation -> {
AllowedOperationTO result = new AllowedOperationTO();
result.setName(allowedOperation.getName());
result.setProperties(convertProperties(allowedOperation.getProperties()));
return result;
})
.toList();
}
private List<AllowedPeripheralOperationTO> convertAllowedPeripheralOperations(
List<org.opentcs.util.persistence.v005.AllowedPeripheralOperationTO> tos
) {
return tos.stream()
.map(
allowedPeripheralOperation -> {
AllowedPeripheralOperationTO result = new AllowedPeripheralOperationTO();
result.setName(allowedPeripheralOperation.getName());
result.setProperties(convertProperties(allowedPeripheralOperation.getProperties()));
return result;
}
)
.toList();
}
private List<LocationTO> convertLocations(V005PlantModelTO to) {
return to.getLocations().stream()
.map(location -> {
String locationRepresentation = toPropertiesMap(location.getProperties())
.getOrDefault(LOC_DEFAULT_REPRESENTATION, LocationRepresentation.DEFAULT.name());
LocationTO result = new LocationTO();
result.setName(location.getName())
.setProperties(convertProperties(location.getProperties()));
result.setPositionX(location.getxPosition())
.setPositionY(location.getyPosition())
.setPositionZ(location.getzPosition())
.setType(location.getType())
.setLinks(convertLinks(location))
.setLocked(location.isLocked())
.setLocationLayout(
new LocationTO.LocationLayout()
.setPositionX(location.getLocationLayout().getxPosition())
.setPositionY(location.getLocationLayout().getyPosition())
.setLabelOffsetX(location.getLocationLayout().getxLabelOffset())
.setLabelOffsetY(location.getLocationLayout().getyLabelOffset())
.setLocationRepresentation(locationRepresentation)
.setLayerId(location.getLocationLayout().getLayerId())
);
return result;
})
.toList();
}
private List<LocationTO.Link> convertLinks(org.opentcs.util.persistence.v005.LocationTO to) {
return to.getLinks().stream()
.map(link -> {
return new LocationTO.Link()
.setPoint(link.getPoint())
.setAllowedOperations(convertAllowedOperations(link.getAllowedOperations()));
})
.toList();
}
private List<BlockTO> convertBlocks(V005PlantModelTO to) {
return to.getBlocks().stream()
.map(block -> {
BlockTO result = new BlockTO();
result.setName(block.getName())
.setProperties(convertProperties(block.getProperties()));
result.setType(block.getType())
.setMembers(convertMembers(block.getMembers()))
.setBlockLayout(
new BlockTO.BlockLayout()
.setColor(block.getBlockLayout().getColor())
);
return result;
})
.toList();
}
private List<MemberTO> convertMembers(List<org.opentcs.util.persistence.v005.MemberTO> tos) {
return tos.stream()
.map(member -> {
MemberTO result = new MemberTO();
result.setName(member.getName())
.setProperties(convertProperties(member.getProperties()));
return result;
})
.toList();
}
private VisualLayoutTO convertVisualLayout(V005PlantModelTO to) {
VisualLayoutTO result = new VisualLayoutTO()
.setScaleX(to.getVisualLayout().getScaleX())
.setScaleY(to.getVisualLayout().getScaleY())
.setLayers(
to.getVisualLayout().getLayers().stream()
.map(
layer -> new VisualLayoutTO.Layer()
.setId(layer.getId())
.setOrdinal(layer.getOrdinal())
.setVisible(layer.isVisible())
.setName(layer.getName())
.setGroupId(layer.getGroupId())
)
.toList()
)
.setLayerGroups(
to.getVisualLayout().getLayerGroups().stream()
.map(
layerGroup -> new VisualLayoutTO.LayerGroup()
.setId(layerGroup.getId())
.setName(layerGroup.getName())
.setVisible(layerGroup.isVisible())
)
.toList()
);
result
.setProperties(convertProperties(to.getVisualLayout().getProperties()))
.setName(to.getVisualLayout().getName());
return result;
}
}

View File

@@ -0,0 +1,260 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.opentcs.util.persistence.BasePlantModelTO;
import org.xml.sax.SAXException;
/**
*/
@XmlRootElement(name = "model")
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"version", "name", "points", "paths", "vehicles", "locationTypes",
"locations", "blocks", "visualLayout", "properties"}
)
public class V6PlantModelTO
extends
BasePlantModelTO {
/**
* This plant model implementation's version string.
*/
public static final String VERSION_STRING = "6.0.0";
private String name = "";
private List<PointTO> points = new ArrayList<>();
private List<PathTO> paths = new ArrayList<>();
private List<VehicleTO> vehicles = new ArrayList<>();
private List<LocationTypeTO> locationTypes = new ArrayList<>();
private List<LocationTO> locations = new ArrayList<>();
private List<BlockTO> blocks = new ArrayList<>();
private VisualLayoutTO visualLayout = new VisualLayoutTO();
private List<PropertyTO> properties = new ArrayList<>();
/**
* Creates a new instance.
*/
public V6PlantModelTO() {
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public V6PlantModelTO setName(
@Nonnull
String name
) {
requireNonNull(name, "name");
this.name = name;
return this;
}
@XmlElement(name = "point")
public List<PointTO> getPoints() {
return points;
}
public V6PlantModelTO setPoints(
@Nonnull
List<PointTO> points
) {
requireNonNull(points, "points");
this.points = points;
return this;
}
@XmlElement(name = "path")
public List<PathTO> getPaths() {
return paths;
}
public V6PlantModelTO setPaths(
@Nonnull
List<PathTO> paths
) {
requireNonNull(paths, "paths");
this.paths = paths;
return this;
}
@XmlElement(name = "vehicle")
public List<VehicleTO> getVehicles() {
return vehicles;
}
public V6PlantModelTO setVehicles(
@Nonnull
List<VehicleTO> vehicles
) {
requireNonNull(vehicles, "vehicles");
this.vehicles = vehicles;
return this;
}
@XmlElement(name = "locationType")
public List<LocationTypeTO> getLocationTypes() {
return locationTypes;
}
public V6PlantModelTO setLocationTypes(
@Nonnull
List<LocationTypeTO> locationTypes
) {
requireNonNull(locationTypes, "locationTypes");
this.locationTypes = locationTypes;
return this;
}
@XmlElement(name = "location")
public List<LocationTO> getLocations() {
return locations;
}
public V6PlantModelTO setLocations(
@Nonnull
List<LocationTO> locations
) {
requireNonNull(locations, "locations");
this.locations = locations;
return this;
}
@XmlElement(name = "block")
public List<BlockTO> getBlocks() {
return blocks;
}
public V6PlantModelTO setBlocks(
@Nonnull
List<BlockTO> blocks
) {
requireNonNull(blocks, "blocks");
this.blocks = blocks;
return this;
}
@XmlElement
public VisualLayoutTO getVisualLayout() {
return visualLayout;
}
public V6PlantModelTO setVisualLayout(
@Nonnull
VisualLayoutTO visualLayout
) {
this.visualLayout = requireNonNull(visualLayout, "visualLayout");
return this;
}
@XmlElement(name = "property")
public List<PropertyTO> getProperties() {
return properties;
}
public V6PlantModelTO setProperties(
@Nonnull
List<PropertyTO> properties
) {
requireNonNull(properties, "properties");
this.properties = properties;
return this;
}
/**
* Marshals this instance to its XML representation and writes it to the given writer.
*
* @param writer The writer to write this instance's XML representation to.
* @throws IOException If there was a problem marshalling this instance.
*/
public void toXml(
@Nonnull
Writer writer
)
throws IOException {
requireNonNull(writer, "writer");
try {
createMarshaller().marshal(this, writer);
}
catch (JAXBException | SAXException exc) {
throw new IOException("Exception marshalling data", exc);
}
}
/**
* Unmarshals an instance of this class from the given XML representation.
*
* @param reader Provides the XML representation to parse to an instance.
* @return The instance unmarshalled from the given reader.
* @throws IOException If there was a problem unmarshalling the given string.
*/
public static V6PlantModelTO fromXml(
@Nonnull
Reader reader
)
throws IOException {
requireNonNull(reader, "reader");
try {
return (V6PlantModelTO) createUnmarshaller().unmarshal(reader);
}
catch (JAXBException | SAXException exc) {
throw new IOException("Exception unmarshalling data", exc);
}
}
private static Marshaller createMarshaller()
throws JAXBException,
SAXException {
Marshaller marshaller = createContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.setSchema(createSchema());
return marshaller;
}
private static Unmarshaller createUnmarshaller()
throws JAXBException,
SAXException {
Unmarshaller unmarshaller = createContext().createUnmarshaller();
unmarshaller.setSchema(createSchema());
return unmarshaller;
}
private static JAXBContext createContext()
throws JAXBException {
return JAXBContext.newInstance(V6PlantModelTO.class);
}
private static Schema createSchema()
throws SAXException {
URL schemaUrl
= V6PlantModelTO.class.getResource("/org/opentcs/util/persistence/model-6.0.0.xsd");
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
return schemaFactory.newSchema(schemaUrl);
}
}

View File

@@ -0,0 +1,772 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import org.opentcs.access.to.model.BlockCreationTO;
import org.opentcs.access.to.model.BoundingBoxCreationTO;
import org.opentcs.access.to.model.CoupleCreationTO;
import org.opentcs.access.to.model.LocationCreationTO;
import org.opentcs.access.to.model.LocationTypeCreationTO;
import org.opentcs.access.to.model.PathCreationTO;
import org.opentcs.access.to.model.PlantModelCreationTO;
import org.opentcs.access.to.model.PointCreationTO;
import org.opentcs.access.to.model.VehicleCreationTO;
import org.opentcs.access.to.model.VisualLayoutCreationTO;
import org.opentcs.access.to.peripherals.PeripheralOperationCreationTO;
import org.opentcs.data.model.Block;
import org.opentcs.data.model.Couple;
import org.opentcs.data.model.Envelope;
import org.opentcs.data.model.Path;
import org.opentcs.data.model.Point;
import org.opentcs.data.model.Pose;
import org.opentcs.data.model.Triple;
import org.opentcs.data.model.visualization.Layer;
import org.opentcs.data.model.visualization.LayerGroup;
import org.opentcs.data.model.visualization.LocationRepresentation;
import org.opentcs.data.peripherals.PeripheralOperation;
import org.opentcs.util.Colors;
/**
* Provides methods for mapping {@link PlantModelCreationTO} to {@link V6PlantModelTO} and
* vice versa.
*/
public class V6TOMapper {
/**
* Creates a new instance.
*/
public V6TOMapper() {
}
/**
* Maps the given model to a {@link PlantModelCreationTO} instance.
*
* @param model The model to map.
* @return The mapped {@link PlantModelCreationTO} instance.
*/
public PlantModelCreationTO map(V6PlantModelTO model) {
return new PlantModelCreationTO(model.getName())
.withPoints(toPointCreationTO(model.getPoints()))
.withVehicles(toVehicleCreationTO(model.getVehicles()))
.withPaths(toPathCreationTO(model.getPaths()))
.withLocationTypes(toLocationTypeCreationTO(model.getLocationTypes()))
.withLocations(toLocationCreationTO(model.getLocations()))
.withBlocks(toBlockCreationTO(model.getBlocks()))
.withVisualLayout(toVisualLayoutCreationTO(model.getVisualLayout()))
.withProperties(convertProperties(model.getProperties()));
}
/**
* Maps the given model to a {@link V6PlantModelTO} instance.
*
* @param model The model to map.
* @return The mapped {@link V6PlantModelTO} instance.
*/
public V6PlantModelTO map(PlantModelCreationTO model) {
V6PlantModelTO result = new V6PlantModelTO();
result.setName(model.getName());
result.setVersion(V6PlantModelTO.VERSION_STRING);
result.getPoints().addAll(toPointTO(model.getPoints(), model.getPaths()));
result.getVehicles().addAll(toVehicleTO(model.getVehicles()));
result.getPaths().addAll(toPathTO(model.getPaths()));
result.getLocationTypes().addAll(toLocationTypeTO(model.getLocationTypes()));
result.getLocations().addAll(toLocationTO(model.getLocations()));
result.getBlocks().addAll(toBlockTO(model.getBlocks()));
result.setVisualLayout(toVisualLayoutTO(model.getVisualLayout()));
result.getProperties().addAll(convertProperties(model.getProperties()));
return result;
}
//Methods for mapping from PlantModelElementTO to CreationTO start here.
private List<PointCreationTO> toPointCreationTO(List<PointTO> points) {
List<PointCreationTO> result = new ArrayList<>();
for (PointTO point : points) {
result.add(
new PointCreationTO(point.getName())
.withPose(
new Pose(
new Triple(point.getPositionX(), point.getPositionY(), point.getPositionZ()),
point.getVehicleOrientationAngle().doubleValue()
)
)
.withType(Point.Type.valueOf(point.getType()))
.withVehicleEnvelopes(toEnvelopeMap(point.getVehicleEnvelopes()))
.withMaxVehicleBoundingBox(toBoundingBoxCreationTO(point.getMaxVehicleBoundingBox()))
.withProperties(convertProperties(point.getProperties()))
.withLayout(
new PointCreationTO.Layout(
new Couple(
point.getPointLayout().getPositionX(),
point.getPointLayout().getPositionY()
),
new Couple(
point.getPointLayout().getLabelOffsetX(),
point.getPointLayout().getLabelOffsetY()
),
point.getPointLayout().getLayerId()
)
)
);
}
return result;
}
private List<VehicleCreationTO> toVehicleCreationTO(List<VehicleTO> vehicles) {
List<VehicleCreationTO> result = new ArrayList<>();
for (VehicleTO vehicle : vehicles) {
result.add(
new VehicleCreationTO(vehicle.getName())
.withBoundingBox(toBoundingBoxCreationTO(vehicle.getBoundingBox()))
.withEnergyLevelThresholdSet(toEnergyLevelThresholdSetCreationTO(vehicle))
.withMaxReverseVelocity(vehicle.getMaxReverseVelocity())
.withMaxVelocity(vehicle.getMaxVelocity())
.withEnvelopeKey(vehicle.getEnvelopeKey())
.withProperties(convertProperties(vehicle.getProperties()))
.withLayout(
new VehicleCreationTO.Layout(
Colors.decodeFromHexRGB(vehicle.getVehicleLayout().getColor())
)
)
);
}
return result;
}
private List<PathCreationTO> toPathCreationTO(List<PathTO> paths) {
List<PathCreationTO> result = new ArrayList<>();
for (PathTO path : paths) {
result.add(
new PathCreationTO(
path.getName(),
path.getSourcePoint(),
path.getDestinationPoint()
)
.withLength(path.getLength())
.withLocked(path.isLocked())
.withMaxVelocity(path.getMaxVelocity().intValue())
.withMaxReverseVelocity(path.getMaxReverseVelocity().intValue())
.withPeripheralOperations(
toPeripheralOperationCreationTOs(path.getPeripheralOperations())
)
.withVehicleEnvelopes(toEnvelopeMap(path.getVehicleEnvelopes()))
.withProperties(convertProperties(path.getProperties()))
.withLayout(
new PathCreationTO.Layout(
Path.Layout.ConnectionType.valueOf(path.getPathLayout().getConnectionType()),
path.getPathLayout().getControlPoints().stream()
.map(controlPoint -> new Couple(controlPoint.getX(), controlPoint.getY()))
.toList(),
path.getPathLayout().getLayerId()
)
)
);
}
return result;
}
private List<PeripheralOperationCreationTO> toPeripheralOperationCreationTOs(
List<PeripheralOperationTO> tos
) {
return tos.stream()
.map(
to -> new PeripheralOperationCreationTO(to.getName(), to.getLocationName())
.withExecutionTrigger(
PeripheralOperation.ExecutionTrigger.valueOf(to.getExecutionTrigger())
)
.withCompletionRequired(to.isCompletionRequired())
)
.toList();
}
private List<LocationTypeCreationTO> toLocationTypeCreationTO(
List<LocationTypeTO> locationTypes
) {
List<LocationTypeCreationTO> result = new ArrayList<>();
for (LocationTypeTO locationType : locationTypes) {
result.add(
new LocationTypeCreationTO(locationType.getName())
.withAllowedOperations(getOperationNames(locationType.getAllowedOperations()))
.withAllowedPeripheralOperations(
getPeripheralOperationNames(
locationType.getAllowedPeripheralOperations()
)
)
.withProperties(convertProperties(locationType.getProperties()))
.withLayout(
new LocationTypeCreationTO.Layout(
LocationRepresentation.valueOf(
locationType.getLocationTypeLayout().getLocationRepresentation()
)
)
)
);
}
return result;
}
private List<LocationCreationTO> toLocationCreationTO(List<LocationTO> locations) {
List<LocationCreationTO> result = new ArrayList<>();
for (LocationTO location : locations) {
result.add(
new LocationCreationTO(
location.getName(),
location.getType(),
new Triple(
location.getPositionX(),
location.getPositionY(),
location.getPositionZ()
)
)
.withLinks(getLinks(location))
.withLocked(location.isLocked())
.withProperties(convertProperties(location.getProperties()))
.withLayout(
new LocationCreationTO.Layout(
new Couple(
location.getLocationLayout().getPositionX(),
location.getLocationLayout().getPositionY()
),
new Couple(
location.getLocationLayout().getLabelOffsetX(),
location.getLocationLayout().getLabelOffsetY()
),
LocationRepresentation.valueOf(
location.getLocationLayout().getLocationRepresentation()
),
location.getLocationLayout().getLayerId()
)
)
);
}
return result;
}
private List<BlockCreationTO> toBlockCreationTO(List<BlockTO> blocks) {
List<BlockCreationTO> result = new ArrayList<>();
for (BlockTO block : blocks) {
result.add(
new BlockCreationTO(block.getName())
.withType(Block.Type.valueOf(block.getType()))
.withMemberNames(
block.getMembers().stream()
.map(member -> member.getName())
.collect(Collectors.toSet())
)
.withProperties(convertProperties(block.getProperties()))
.withLayout(
new BlockCreationTO.Layout(
Colors.decodeFromHexRGB(block.getBlockLayout().getColor())
)
)
);
}
return result;
}
private VisualLayoutCreationTO toVisualLayoutCreationTO(VisualLayoutTO visualLayout) {
return new VisualLayoutCreationTO(visualLayout.getName())
.withScaleX(visualLayout.getScaleX())
.withScaleY(visualLayout.getScaleY())
.withLayers(convertLayers(visualLayout.getLayers()))
.withLayerGroups(convertLayerGroups(visualLayout.getLayerGroups()))
.withProperties(convertProperties(visualLayout.getProperties()));
}
private List<Layer> convertLayers(List<VisualLayoutTO.Layer> layers) {
List<Layer> result = new ArrayList<>();
for (VisualLayoutTO.Layer layer : layers) {
result.add(
new Layer(
layer.getId(),
layer.getOrdinal(),
layer.isVisible(),
layer.getName(),
layer.getGroupId()
)
);
}
return result;
}
private List<LayerGroup> convertLayerGroups(List<VisualLayoutTO.LayerGroup> layerGroups) {
List<LayerGroup> result = new ArrayList<>();
for (VisualLayoutTO.LayerGroup layerGroup : layerGroups) {
result.add(
new LayerGroup(
layerGroup.getId(),
layerGroup.getName(),
layerGroup.isVisible()
)
);
}
return result;
}
private Map<String, String> convertProperties(List<PropertyTO> propsList) {
Map<String, String> result = new HashMap<>();
for (PropertyTO property : propsList) {
String propName
= isNullOrEmpty(property.getName()) ? "Property unknown" : property.getName();
String propValue
= isNullOrEmpty(property.getValue()) ? "Value unknown" : property.getValue();
result.put(propName, propValue);
}
return result;
}
private List<String> getOperationNames(List<AllowedOperationTO> ops) {
List<String> result = new ArrayList<>(ops.size());
for (AllowedOperationTO operation : ops) {
result.add(operation.getName());
}
return result;
}
private List<String> getPeripheralOperationNames(List<AllowedPeripheralOperationTO> ops) {
List<String> result = new ArrayList<>(ops.size());
for (AllowedPeripheralOperationTO operation : ops) {
result.add(operation.getName());
}
return result;
}
private Map<String, Set<String>> getLinks(LocationTO to) {
Map<String, Set<String>> result = new HashMap<>();
for (LocationTO.Link linkTO : to.getLinks()) {
result.put(
linkTO.getPoint(),
new HashSet<>(getOperationNames(linkTO.getAllowedOperations()))
);
}
return result;
}
//Methods for mapping from CreationTO to PlantModelElementTO start here.
private List<PointTO> toPointTO(List<PointCreationTO> points, List<PathCreationTO> paths) {
List<PointTO> result = new ArrayList<>();
for (PointCreationTO point : points) {
PointTO pointTO = new PointTO();
pointTO.setName(point.getName());
pointTO.setPositionX(point.getPose().getPosition().getX())
.setPositionY(point.getPose().getPosition().getY())
.setVehicleOrientationAngle((float) point.getPose().getOrientationAngle())
.setType(point.getType().name())
.setOutgoingPaths(getOutgoingPaths(point, paths))
.setVehicleEnvelopes(toVehicleEnvelopeTOs(point.getVehicleEnvelopes()))
.setMaxVehicleBoundingBox(toBoundingBoxTO(point.getMaxVehicleBoundingBox()))
.setPointLayout(
new PointTO.PointLayout()
.setPositionX(point.getLayout().getPosition().getX())
.setPositionY(point.getLayout().getPosition().getY())
.setLabelOffsetX(point.getLayout().getLabelOffset().getX())
.setLabelOffsetY(point.getLayout().getLabelOffset().getY())
.setLayerId(point.getLayout().getLayerId())
)
.setProperties(convertProperties(point.getProperties()));
result.add(pointTO);
}
Collections.sort(result, Comparators.elementsByName());
return result;
}
private List<VehicleTO> toVehicleTO(List<VehicleCreationTO> vehicles) {
List<VehicleTO> result = new ArrayList<>();
for (VehicleCreationTO vehicle : vehicles) {
VehicleTO vehicleTO = new VehicleTO();
vehicleTO.setName(vehicle.getName());
vehicleTO.setBoundingBox(toBoundingBoxTO(vehicle.getBoundingBox()))
.setMaxVelocity(vehicle.getMaxVelocity())
.setMaxReverseVelocity(vehicle.getMaxReverseVelocity())
.setEnergyLevelGood((long) vehicle.getEnergyLevelThresholdSet().getEnergyLevelGood())
.setEnergyLevelCritical(
(long) vehicle.getEnergyLevelThresholdSet().getEnergyLevelCritical()
)
.setEnergyLevelFullyRecharged(
(long) vehicle.getEnergyLevelThresholdSet().getEnergyLevelFullyRecharged()
)
.setEnergyLevelSufficientlyRecharged(
(long) vehicle.getEnergyLevelThresholdSet().getEnergyLevelSufficientlyRecharged()
)
.setEnvelopeKey(vehicle.getEnvelopeKey())
.setVehicleLayout(
new VehicleTO.VehicleLayout()
.setColor(Colors.encodeToHexRGB(vehicle.getLayout().getRouteColor()))
)
.setProperties(convertProperties(vehicle.getProperties()));
result.add(vehicleTO);
}
Collections.sort(result, Comparators.elementsByName());
return result;
}
private List<PathTO> toPathTO(List<PathCreationTO> paths) {
List<PathTO> result = new ArrayList<>();
for (PathCreationTO path : paths) {
PathTO pathTO = new PathTO();
pathTO.setName(path.getName());
pathTO.setSourcePoint(path.getSrcPointName())
.setDestinationPoint(path.getDestPointName())
.setLength(path.getLength())
.setMaxVelocity((long) path.getMaxVelocity())
.setMaxReverseVelocity((long) path.getMaxReverseVelocity())
.setPeripheralOperations(toPeripheralOperationTOs(path.getPeripheralOperations()))
.setLocked(path.isLocked())
.setVehicleEnvelopes(toVehicleEnvelopeTOs(path.getVehicleEnvelopes()))
.setPathLayout(
new PathTO.PathLayout()
.setConnectionType(path.getLayout().getConnectionType().name())
.setControlPoints(
path.getLayout().getControlPoints().stream()
.map(controlPoint -> {
return new PathTO.ControlPoint()
.setX(controlPoint.getX())
.setY(controlPoint.getY());
})
.toList()
)
.setLayerId(path.getLayout().getLayerId())
)
.setProperties(convertProperties(path.getProperties()));
result.add(pathTO);
}
Collections.sort(result, Comparators.elementsByName());
return result;
}
private List<PeripheralOperationTO> toPeripheralOperationTOs(
List<PeripheralOperationCreationTO> tos
) {
return tos.stream()
.map(
to -> (PeripheralOperationTO) new PeripheralOperationTO()
.setLocationName(to.getLocationName())
.setExecutionTrigger(to.getExecutionTrigger().name())
.setCompletionRequired(to.isCompletionRequired())
.setName(to.getOperation())
)
.toList();
}
private List<LocationTypeTO> toLocationTypeTO(
List<LocationTypeCreationTO> locationTypes
) {
List<LocationTypeTO> result = new ArrayList<>();
for (LocationTypeCreationTO locationType : locationTypes) {
LocationTypeTO locationTypeTO = new LocationTypeTO();
locationTypeTO.setName(locationType.getName());
locationTypeTO.setAllowedOperations(
toAllowedOperationTOs(locationType.getAllowedOperations())
)
.setAllowedPeripheralOperations(
toAllowedPeripheralOperationTOs(locationType.getAllowedPeripheralOperations())
)
.setLocationTypeLayout(
new LocationTypeTO.LocationTypeLayout()
.setLocationRepresentation(
locationType.getLayout().getLocationRepresentation().name()
)
)
.setProperties(convertProperties(locationType.getProperties()));
result.add(locationTypeTO);
}
Collections.sort(result, Comparators.elementsByName());
return result;
}
private List<LocationTO> toLocationTO(List<LocationCreationTO> locations) {
List<LocationTO> result = new ArrayList<>();
for (LocationCreationTO location : locations) {
LocationTO locationTO = new LocationTO();
locationTO.setName(location.getName());
locationTO.setPositionX(location.getPosition().getX())
.setPositionY(location.getPosition().getY())
.setType(location.getTypeName())
.setLinks(toLocationTOLinks(location.getLinks()))
.setLocked(location.isLocked())
.setLocationLayout(
new LocationTO.LocationLayout()
.setPositionX(location.getLayout().getPosition().getX())
.setPositionY(location.getLayout().getPosition().getY())
.setLabelOffsetX(location.getLayout().getLabelOffset().getX())
.setLabelOffsetY(location.getLayout().getLabelOffset().getY())
.setLocationRepresentation(
location.getLayout().getLocationRepresentation().name()
)
.setLayerId(location.getLayout().getLayerId())
)
.setProperties(convertProperties(location.getProperties()));
result.add(locationTO);
}
Collections.sort(result, Comparators.elementsByName());
return result;
}
private List<BlockTO> toBlockTO(List<BlockCreationTO> blocks) {
List<BlockTO> result = new ArrayList<>();
for (BlockCreationTO block : blocks) {
BlockTO blockTO = new BlockTO();
blockTO.setName(block.getName());
blockTO.setType(block.getType().name())
.setMembers(toMemberTOs(block.getMemberNames()))
.setBlockLayout(
new BlockTO.BlockLayout()
.setColor(Colors.encodeToHexRGB(block.getLayout().getColor()))
)
.setProperties(convertProperties(block.getProperties()));
result.add(blockTO);
}
Collections.sort(result, Comparators.elementsByName());
return result;
}
private VisualLayoutTO toVisualLayoutTO(VisualLayoutCreationTO layout) {
VisualLayoutTO result = new VisualLayoutTO();
result.setName(layout.getName())
.setProperties(convertProperties(layout.getProperties()));
result.setScaleX((float) layout.getScaleX())
.setScaleY((float) layout.getScaleY())
.setLayers(toLayerTOs(layout.getLayers()))
.setLayerGroups(toLayerGroupTOs(layout.getLayerGroups()));
return result;
}
private List<VisualLayoutTO.Layer> toLayerTOs(List<Layer> layers) {
List<VisualLayoutTO.Layer> result = new ArrayList<>();
for (Layer layer : layers) {
result.add(
new VisualLayoutTO.Layer()
.setId(layer.getId())
.setOrdinal(layer.getOrdinal())
.setVisible(layer.isVisible())
.setName(layer.getName())
.setGroupId(layer.getGroupId())
);
}
return result;
}
private List<VisualLayoutTO.LayerGroup> toLayerGroupTOs(List<LayerGroup> layerGroups) {
List<VisualLayoutTO.LayerGroup> result = new ArrayList<>();
for (LayerGroup layerGroup : layerGroups) {
result.add(
new VisualLayoutTO.LayerGroup()
.setId(layerGroup.getId())
.setName(layerGroup.getName())
.setVisible(layerGroup.isVisible())
);
}
return result;
}
private List<PointTO.OutgoingPath> getOutgoingPaths(
PointCreationTO point,
List<PathCreationTO> paths
) {
List<PointTO.OutgoingPath> result = new ArrayList<>();
for (PathCreationTO path : paths) {
if (Objects.equals(path.getSrcPointName(), point.getName())) {
result.add(new PointTO.OutgoingPath().setName(path.getName()));
}
}
Collections.sort(result, Comparators.outgoingPathsByName());
return result;
}
private List<AllowedOperationTO> toAllowedOperationTOs(Collection<String> allowedOperations) {
return allowedOperations.stream()
.sorted()
.map(allowedOperation -> {
return (AllowedOperationTO) new AllowedOperationTO().setName(allowedOperation);
})
.toList();
}
private List<AllowedPeripheralOperationTO> toAllowedPeripheralOperationTOs(
Collection<String> allowedOperations
) {
return allowedOperations.stream()
.sorted()
.map(allowedOperation -> {
return (AllowedPeripheralOperationTO) new AllowedPeripheralOperationTO()
.setName(allowedOperation);
})
.toList();
}
private List<LocationTO.Link> toLocationTOLinks(Map<String, Set<String>> links) {
List<LocationTO.Link> result = new ArrayList<>();
links.forEach((key, value) -> {
result.add(
new LocationTO.Link()
.setPoint(key)
.setAllowedOperations(toAllowedOperationTOs(value))
);
});
Collections.sort(result, Comparators.linksByPointName());
return result;
}
private List<MemberTO> toMemberTOs(Collection<String> members) {
return members.stream()
.map(member -> (MemberTO) new MemberTO().setName(member))
.sorted(Comparators.elementsByName())
.toList();
}
private List<PropertyTO> convertProperties(Map<String, String> properties) {
List<PropertyTO> result = new ArrayList<>();
properties.forEach((key, value) -> {
result.add(new PropertyTO().setName(key).setValue(value));
});
Collections.sort(result, Comparators.propertiesByName());
return result;
}
private boolean isNullOrEmpty(String s) {
return s == null || s.isEmpty();
}
private Map<String, Envelope> toEnvelopeMap(List<VehicleEnvelopeTO> envelopeTOs) {
return envelopeTOs.stream()
.collect(
Collectors.toMap(
VehicleEnvelopeTO::getKey,
vehicleEnvelopeTO -> toEnvelope(vehicleEnvelopeTO)
)
);
}
private Envelope toEnvelope(VehicleEnvelopeTO vehicleEnvelopeTO) {
return new Envelope(
vehicleEnvelopeTO.getVertices().stream()
.map(coupleTO -> new Couple(coupleTO.getX(), coupleTO.getY()))
.toList()
);
}
private List<VehicleEnvelopeTO> toVehicleEnvelopeTOs(Map<String, Envelope> envelopeMap) {
return envelopeMap.entrySet()
.stream()
.sorted(Map.Entry.comparingByKey())
.map(
entry -> new VehicleEnvelopeTO()
.setKey(entry.getKey())
.setVertices(toCoupleTOs(entry.getValue().getVertices()))
)
.toList();
}
private List<CoupleTO> toCoupleTOs(List<Couple> couples) {
return couples.stream()
.map(
couple -> new CoupleTO()
.setX(couple.getX())
.setY(couple.getY())
)
.toList();
}
private BoundingBoxCreationTO toBoundingBoxCreationTO(BoundingBoxTO boundingBox) {
return new BoundingBoxCreationTO(
boundingBox.getLength(),
boundingBox.getWidth(),
boundingBox.getHeight()
)
.withReferenceOffset(
new CoupleCreationTO(
boundingBox.getReferenceOffsetX(),
boundingBox.getReferenceOffsetY()
)
);
}
private VehicleCreationTO.EnergyLevelThresholdSet toEnergyLevelThresholdSetCreationTO(
VehicleTO vehicle
) {
return new VehicleCreationTO.EnergyLevelThresholdSet(
vehicle.getEnergyLevelCritical().intValue(),
vehicle.getEnergyLevelGood().intValue(),
vehicle.getEnergyLevelSufficientlyRecharged().intValue(),
vehicle.getEnergyLevelFullyRecharged().intValue()
);
}
private BoundingBoxTO toBoundingBoxTO(BoundingBoxCreationTO boundingBox) {
return new BoundingBoxTO()
.setLength(boundingBox.getLength())
.setWidth(boundingBox.getWidth())
.setHeight(boundingBox.getHeight())
.setReferenceOffsetX(boundingBox.getReferenceOffset().getX())
.setReferenceOffsetY(boundingBox.getReferenceOffset().getY());
}
}

View File

@@ -0,0 +1,52 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"key", "vertices"})
public class VehicleEnvelopeTO {
private String key;
private List<CoupleTO> vertices;
public VehicleEnvelopeTO() {
}
public String getKey() {
return key;
}
@XmlAttribute
public VehicleEnvelopeTO setKey(
@Nonnull
String key
) {
this.key = requireNonNull(key, "key");
return this;
}
@XmlElement(name = "vertex")
public List<CoupleTO> getVertices() {
return vertices;
}
public VehicleEnvelopeTO setVertices(
@Nonnull
List<CoupleTO> vertices
) {
this.vertices = requireNonNull(vertices, "vertices");
return this;
}
}

View File

@@ -0,0 +1,202 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import org.opentcs.util.annotations.ScheduledApiChange;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(
propOrder = {"name", "energyLevelCritical", "energyLevelGood", "energyLevelFullyRecharged",
"energyLevelSufficientlyRecharged", "maxVelocity", "maxReverseVelocity", "boundingBox",
"properties", "vehicleLayout"}
)
public class VehicleTO
extends
PlantModelElementTO {
//max velocity in mm/s.
private int maxVelocity;
//max rev velocity in mm/s.
private int maxReverseVelocity;
private Long energyLevelCritical = 0L;
private Long energyLevelGood = 0L;
private Long energyLevelFullyRecharged = 0L;
private Long energyLevelSufficientlyRecharged = 0L;
private String envelopeKey;
private BoundingBoxTO boundingBox = new BoundingBoxTO();
private VehicleLayout vehicleLayout = new VehicleLayout();
/**
* Creates a new instance.
*/
public VehicleTO() {
}
@XmlAttribute(required = true)
@XmlSchemaType(name = "unsignedInt")
public Long getEnergyLevelCritical() {
return energyLevelCritical;
}
public VehicleTO setEnergyLevelCritical(
@Nonnull
Long energyLevelCritical
) {
requireNonNull(energyLevelCritical, "energyLevelCritical");
this.energyLevelCritical = energyLevelCritical;
return this;
}
@XmlAttribute(required = true)
@XmlSchemaType(name = "unsignedInt")
public Long getEnergyLevelGood() {
return energyLevelGood;
}
public VehicleTO setEnergyLevelGood(
@Nonnull
Long energyLevelGood
) {
requireNonNull(energyLevelGood, "energyLevelGood");
this.energyLevelGood = energyLevelGood;
return this;
}
@XmlAttribute(required = true)
@XmlSchemaType(name = "unsignedInt")
public Long getEnergyLevelFullyRecharged() {
return energyLevelFullyRecharged;
}
public VehicleTO setEnergyLevelFullyRecharged(
@Nonnull
Long energyLevelFullyRecharged
) {
requireNonNull(energyLevelFullyRecharged, "energyLevelFullyRecharged");
this.energyLevelFullyRecharged = energyLevelFullyRecharged;
return this;
}
@XmlAttribute(required = true)
@XmlSchemaType(name = "unsignedInt")
public Long getEnergyLevelSufficientlyRecharged() {
return energyLevelSufficientlyRecharged;
}
public VehicleTO setEnergyLevelSufficientlyRecharged(
@Nonnull
Long energyLevelSufficientlyRecharged
) {
requireNonNull(energyLevelSufficientlyRecharged, "energyLevelSufficientlyRecharged");
this.energyLevelSufficientlyRecharged = energyLevelSufficientlyRecharged;
return this;
}
@XmlAttribute(required = true)
@XmlSchemaType(name = "unsignedInt")
public int getMaxVelocity() {
return maxVelocity;
}
public VehicleTO setMaxVelocity(
@Nonnull
int maxVelocity
) {
this.maxVelocity = maxVelocity;
return this;
}
@XmlAttribute(required = true)
@XmlSchemaType(name = "unsignedInt")
public int getMaxReverseVelocity() {
return maxReverseVelocity;
}
public VehicleTO setMaxReverseVelocity(
@Nonnull
int maxReverseVelocity
) {
this.maxReverseVelocity = maxReverseVelocity;
return this;
}
@ScheduledApiChange(when = "7.0", details = "Envelope key will become non-null.")
@XmlAttribute
@Nullable
public String getEnvelopeKey() {
return envelopeKey;
}
@ScheduledApiChange(when = "7.0", details = "Envelope key will become non-null.")
public VehicleTO setEnvelopeKey(
@Nullable
String envelopeKey
) {
this.envelopeKey = envelopeKey;
return this;
}
@XmlElement
@Nonnull
public BoundingBoxTO getBoundingBox() {
return boundingBox;
}
public VehicleTO setBoundingBox(
@Nonnull
BoundingBoxTO boundingBox
) {
this.boundingBox = requireNonNull(boundingBox, "boundingBox");
return this;
}
@XmlElement(required = true)
public VehicleLayout getVehicleLayout() {
return vehicleLayout;
}
public VehicleTO setVehicleLayout(
@Nonnull
VehicleLayout vehicleLayout
) {
this.vehicleLayout = requireNonNull(vehicleLayout, "vehicleLayout");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
public static class VehicleLayout {
private String color = "";
/**
* Creates a new instance.
*/
public VehicleLayout() {
}
@XmlAttribute(required = true)
public String getColor() {
return color;
}
public VehicleLayout setColor(
@Nonnull
String color
) {
this.color = requireNonNull(color, "color");
return this;
}
}
}

View File

@@ -0,0 +1,200 @@
// SPDX-FileCopyrightText: The openTCS Authors
// SPDX-License-Identifier: MIT
package org.opentcs.util.persistence.v6;
import static java.util.Objects.requireNonNull;
import jakarta.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
/**
*/
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"name", "scaleX", "scaleY", "layers", "layerGroups", "properties"})
public class VisualLayoutTO
extends
PlantModelElementTO {
private Float scaleX = 0.0F;
private Float scaleY = 0.0F;
private List<Layer> layers = new ArrayList<>();
private List<LayerGroup> layerGroups = new ArrayList<>();
/**
* Creates a new instance.
*/
public VisualLayoutTO() {
}
@XmlAttribute(required = true)
public Float getScaleX() {
return scaleX;
}
public VisualLayoutTO setScaleX(
@Nonnull
Float scaleX
) {
requireNonNull(scaleX, "scaleX");
this.scaleX = scaleX;
return this;
}
@XmlAttribute(required = true)
public Float getScaleY() {
return scaleY;
}
public VisualLayoutTO setScaleY(
@Nonnull
Float scaleY
) {
requireNonNull(scaleY, "scaleY");
this.scaleY = scaleY;
return this;
}
@XmlElement(name = "layer")
public List<Layer> getLayers() {
return layers;
}
public VisualLayoutTO setLayers(
@Nonnull
List<Layer> layers
) {
this.layers = requireNonNull(layers, "layers");
return this;
}
@XmlElement(name = "layerGroup")
public List<LayerGroup> getLayerGroups() {
return layerGroups;
}
public VisualLayoutTO setLayerGroups(
@Nonnull
List<LayerGroup> layerGroups
) {
this.layerGroups = requireNonNull(layerGroups, "layerGroups");
return this;
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"id", "ordinal", "visible", "name", "groupId"})
public static class Layer {
private Integer id = 0;
private Integer ordinal = 0;
private Boolean visible = true;
private String name = "";
private Integer groupId = 0;
/**
* Creates a new instance.
*/
public Layer() {
}
@XmlAttribute(required = true)
public Integer getId() {
return id;
}
public Layer setId(Integer id) {
this.id = requireNonNull(id, "id");
return this;
}
@XmlAttribute(required = true)
public Integer getOrdinal() {
return ordinal;
}
public Layer setOrdinal(Integer ordinal) {
this.ordinal = requireNonNull(ordinal, "ordinal");
return this;
}
@XmlAttribute(required = true)
public Boolean isVisible() {
return visible;
}
public Layer setVisible(Boolean visible) {
this.visible = requireNonNull(visible, "visible");
return this;
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public Layer setName(String name) {
this.name = requireNonNull(name, "name");
return this;
}
@XmlAttribute(required = true)
public Integer getGroupId() {
return groupId;
}
public Layer setGroupId(Integer groupId) {
this.groupId = requireNonNull(groupId, "groupId");
return this;
}
}
@XmlAccessorType(XmlAccessType.PROPERTY)
@XmlType(propOrder = {"id", "name", "visible"})
public static class LayerGroup {
private Integer id = 0;
private String name = "";
private Boolean visible = true;
/**
* Creates a new instance.
*/
public LayerGroup() {
}
@XmlAttribute(required = true)
public Integer getId() {
return id;
}
public LayerGroup setId(Integer id) {
this.id = requireNonNull(id, "id");
return this;
}
@XmlAttribute(required = true)
public String getName() {
return name;
}
public LayerGroup setName(String name) {
this.name = requireNonNull(name, "name");
return this;
}
@XmlAttribute(required = true)
public Boolean isVisible() {
return visible;
}
public LayerGroup setVisible(Boolean visible) {
this.visible = requireNonNull(visible, "visible");
return this;
}
}
}

View File

@@ -0,0 +1,10 @@
# SPDX-FileCopyrightText: The openTCS Authors
# SPDX-License-Identifier: CC0-1.0
version = 1
[[annotations]]
path = ["**/*.gif", "**/*.jpg", "**/*.png", "**/*.svg"]
precedence = "closest"
SPDX-FileCopyrightText = "The openTCS Authors"
SPDX-License-Identifier = "CC-BY-4.0"

View File

@@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: The openTCS Authors
# SPDX-License-Identifier: CC-BY-4.0
connectToServerDialog.button_cancle.text=Cancel
connectToServerDialog.button_ok.text=OK
connectToServerDialog.label_description.text=Description:
connectToServerDialog.label_host.text=Host:
connectToServerDialog.label_port.text=RMI Port:
connectToServerDialog.optionPane_invalidDescription.message=Please enter a description.
connectToServerDialog.optionPane_invalidDescription.title=Invalid description
connectToServerDialog.optionPane_invalidHost.message=Please enter a hostname.
connectToServerDialog.optionPane_invalidHost.title=Invalid hostname
connectToServerDialog.optionPane_invalidPort.message=Please choose a port between 0 and 65535.
connectToServerDialog.optionPane_invalidPort.title=Invalid port
connectToServerDialog.optionPane_noConnection.message=Could not establish connection to kernel.
connectToServerDialog.title=Connect to kernel

View File

@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: The openTCS Authors
# SPDX-License-Identifier: CC-BY-4.0
connectToServerDialog.button_cancle.text=Abbrechen
connectToServerDialog.label_description.text=Beschreibung:
connectToServerDialog.label_host.text=Rechnername:
connectToServerDialog.optionPane_invalidDescription.message=Bitte tragen Sie eine Beschreibung ein.
connectToServerDialog.optionPane_invalidDescription.title=Ung\u00fcltige Beschreibung
connectToServerDialog.optionPane_invalidHost.message=Bitte tragen Sie einen Rechnernamen ein.
connectToServerDialog.optionPane_invalidHost.title=Ung\u00fcltiger Rechnername
connectToServerDialog.optionPane_invalidPort.message=Bitte w\u00e4hlen Sie einen Port zwischen 0 und 65535.
connectToServerDialog.optionPane_invalidPort.title=Ung\u00fcltiger Port
connectToServerDialog.optionPane_noConnection.message=Verbindung zum Kernel konnte nicht aufgebaut werden.
connectToServerDialog.title=Mit Kernel verbinden

Binary file not shown.

After

Width:  |  Height:  |  Size: 637 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="256"
height="256"
id="svg2"
version="1.1"
inkscape:version="0.48.4 r9939"
sodipodi:docname="template.svg"
inkscape:export-filename="C:\var\tmarquar\openTCS_trunk.git\src\org\opentcs\util\gui\res\icons\opentcs_icon_16.png"
inkscape:export-xdpi="5.6300001"
inkscape:export-ydpi="5.6300001">
<defs
id="defs4" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.8"
inkscape:cx="81.199577"
inkscape:cy="105.63439"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:window-width="1600"
inkscape:window-height="1138"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-796.36218)">
<rect
style="fill:#ffffff;fill-opacity:1;stroke:none"
id="rect2995"
width="255.35713"
height="255.35713"
x="0.35714287"
y="797.00507"
ry="18.571428" />
<text
xml:space="preserve"
style="font-size:99.02412415px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#484848;fill-opacity:1;stroke:none;font-family:Lucida Console;-inkscape-font-specification:Lucida Console Bold"
x="9.6911697"
y="891.34259"
id="text2985"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan2987"
x="9.6911697"
y="891.34259">open</tspan><tspan
sodipodi:role="line"
x="9.6911697"
y="1015.1227"
id="tspan2989" /></text>
<text
xml:space="preserve"
style="font-size:129.19404602px;font-style:oblique;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:start;line-height:125%;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#0000ff;fill-opacity:1;stroke:none;font-family:Lucida Console;-inkscape-font-specification:Lucida Console Bold Oblique"
x="-9.6509142"
y="1007.6895"
id="text2991"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan2993"
x="-9.6509142"
y="1007.6895">TCS</tspan></text>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.2 KiB

View File

@@ -0,0 +1,24 @@
# SPDX-FileCopyrightText: The openTCS Authors
# SPDX-License-Identifier: CC-BY-4.0
= Information on openTCS plant model XML schemas
== General information
The openTCS plant model XML schemas adhere to link:https://semver.org/spec/v2.0.0.html[Semantic Versioning].
This means:
* If something is removed from the schema (e.g. a plant model element property that is no longer supported), the MAJOR version is incremented.
* If something is added to the schema in a backward compatible manner (e.g. a new plant model element property), the MINOR version is incremented.
* If something is fixed in the schema (e.g. a typo), the PATCH version is incremented.
== Implementation remarks
* For every MAJOR version, only _a single_ implementation is maintained here -- the one for the most recent MINOR/PATCH schema version.
* If the MINOR or PATCH version changes, the version string in the corresponding implementation must be updated.
* When reading a plant model file, an implementation must check whether the version that is read is compatible with the maximum version that the implementation supports.
If the version is not compatible (e.g. because it is a more recent MINOR/PATCH version than the one supported by the implementation), reading the respective plant model file must fail.
* When writing a plant model file, an implementation must always apply the most recent MINOR/PATCH version for the MAJOR version it supports.
* When a new MAJOR version is introduced, the previous MAJOR version's code for mapping to/from base API data structures can and should be removed, as it will no longer be used then.
(With the design applied at the time of this writing, this would be the `V6ModelParser` class's `read()` method and the class `V6TOMapper`.)

Some files were not shown because too many files have changed in this diff Show More