use of org.opentcs.data.model.Location in project OpenTCS-4 by touchmii.
the class Model method getInfo.
/**
* Returns an informational string describing this model's topology.
*
* @return An informational string describing this model's topology.
*/
public String getInfo() {
StringBuilder result = new StringBuilder();
Set<Point> points = new TreeSet<>(Comparators.objectsByName());
Set<Path> paths = new TreeSet<>(Comparators.objectsByName());
Set<LocationType> locationTypes = new TreeSet<>(Comparators.objectsByName());
Set<Location> locations = new TreeSet<>(Comparators.objectsByName());
Set<Vehicle> vehicles = new TreeSet<>(Comparators.objectsByName());
Set<TCSObject<?>> objects = objectPool.getObjects((Pattern) null);
for (TCSObject<?> curObject : objects) {
if (curObject instanceof Point) {
points.add((Point) curObject);
} else if (curObject instanceof Path) {
paths.add((Path) curObject);
} else if (curObject instanceof LocationType) {
locationTypes.add((LocationType) curObject);
} else if (curObject instanceof Location) {
locations.add((Location) curObject);
} else if (curObject instanceof Vehicle) {
vehicles.add((Vehicle) curObject);
}
}
result.append("Model data:\n");
result.append(" Name: " + name + "\n");
result.append("Points:\n");
for (Point curPoint : points) {
result.append(" Point:\n");
result.append(" Name: " + curPoint.getName() + "\n");
result.append(" Type: " + curPoint.getType() + "\n");
result.append(" X: " + curPoint.getPosition().getX() + "\n");
result.append(" Y: " + curPoint.getPosition().getY() + "\n");
result.append(" Z: " + curPoint.getPosition().getZ() + "\n");
}
result.append("Paths:\n");
for (Path curPath : paths) {
result.append(" Path:\n");
result.append(" Name: " + curPath.getName() + "\n");
result.append(" Source: " + curPath.getSourcePoint().getName() + "\n");
result.append(" Destination: " + curPath.getDestinationPoint().getName() + "\n");
result.append(" Length: " + curPath.getLength() + "\n");
}
result.append("LocationTypes:\n");
for (LocationType curType : locationTypes) {
result.append(" LocationType:\n");
result.append(" Name: " + curType.getName() + "\n");
result.append(" Operations: " + curType.getAllowedOperations().toString() + "\n");
}
result.append("Locations:\n");
for (Location curLocation : locations) {
result.append(" Location:\n");
result.append(" Name: " + curLocation.getName() + "\n");
result.append(" Type: " + curLocation.getType().getName() + "\n");
for (Location.Link curLink : curLocation.getAttachedLinks()) {
result.append(" Link:\n");
result.append(" Point: " + curLink.getPoint().getName() + "\n");
result.append(" Allowed operations:" + curLink.getAllowedOperations() + "\n");
}
}
result.append("Vehicles:\n");
for (Vehicle curVehicle : vehicles) {
result.append(" Vehicle:\n");
result.append(" Name: " + curVehicle.getName() + "\n");
result.append(" Length: " + curVehicle.getLength());
}
return result.toString();
}
use of org.opentcs.data.model.Location in project OpenTCS-4 by touchmii.
the class Model method removeLocationLinkAllowedOperation.
/**
* Removes an allowed operation from a link between a location and a point.
*
* @param locRef A reference to the location end of the link to be modified.
* @param pointRef A reference to the point end of the link to be modified.
* @param operation The operation to be removed.
* @throws ObjectUnknownException If any of the referenced objects does not
* exist.
* @deprecated Use {@link #createLocation(org.opentcs.access.to.LocationCreationTO)} instead.
*/
@Deprecated
public void removeLocationLinkAllowedOperation(TCSObjectReference<Location> locRef, TCSObjectReference<Point> pointRef, String operation) throws ObjectUnknownException {
LOG.debug("method entry");
Location location = objectPool.getObjectOrNull(Location.class, locRef);
if (location == null) {
throw new ObjectUnknownException(locRef);
}
Location previousLocationState = location.clone();
Point point = objectPool.getObjectOrNull(Point.class, pointRef);
if (point == null) {
throw new ObjectUnknownException(pointRef);
}
Point previousPointState = point.clone();
// Get the link between the point and location, if any exists.
Location.Link referredLink = null;
for (Location.Link curLink : location.getAttachedLinks()) {
if (curLink.getPoint().equals(point.getReference())) {
referredLink = curLink;
break;
}
}
if (referredLink == null) {
throw new ObjectUnknownException("Described link not in this model");
}
// Emit an event for both the location and the point end of the link.
objectPool.emitObjectEvent(location.clone(), previousLocationState, TCSObjectEvent.Type.OBJECT_MODIFIED);
objectPool.emitObjectEvent(point.clone(), previousPointState, TCSObjectEvent.Type.OBJECT_MODIFIED);
// XXX Do we want to return anything here?
}
use of org.opentcs.data.model.Location in project OpenTCS-4 by touchmii.
the class Model method setLocationPosition.
/**
* Sets the physical coordinates of a given location.
*
* @param ref A reference to the location to be modified.
* @param position The location's new coordinates.
* @return The modified location.
* @throws ObjectUnknownException If the referenced location does not exist.
* @deprecated Use {@link #createLocation(org.opentcs.access.to.LocationCreationTO)} instead.
*/
@Deprecated
public Location setLocationPosition(TCSObjectReference<Location> ref, Triple position) throws ObjectUnknownException {
LOG.debug("method entry");
Location location = objectPool.getObjectOrNull(Location.class, ref);
if (location == null) {
throw new ObjectUnknownException(ref);
}
Location previousState = location.clone();
location.setPosition(position);
objectPool.emitObjectEvent(location.clone(), previousState, TCSObjectEvent.Type.OBJECT_MODIFIED);
return location;
}
use of org.opentcs.data.model.Location in project OpenTCS-4 by touchmii.
the class Model method createLocation.
/**
* Creates a new location with a unique name and all other attributes set to
* default values.
*
* @param objectID The ID of the newly created location. If <code>null</code>,
* a new, unique one will be generated.
* @param typeRef The location type the location will belong to.
* @return The newly created location.
* @throws ObjectUnknownException If the referenced location type does not
* exist.
* @deprecated Use {@link #createLocation(org.opentcs.access.to.LocationCreationTO)} instead.
*/
@Deprecated
public Location createLocation(Integer objectID, TCSObjectReference<LocationType> typeRef) throws ObjectUnknownException {
LOG.debug("method entry");
LocationType type = objectPool.getObjectOrNull(LocationType.class, typeRef);
if (type == null) {
throw new ObjectUnknownException(typeRef);
}
// Get a unique ID and name for the new location and create an instance.
int locID = objectID != null ? objectID : objectPool.getUniqueObjectId();
String locationName = objectPool.getUniqueObjectName("Location-", "0000");
Location newLocation = new Location(locID, locationName, type.getReference());
// Store the instance in the global object pool.
try {
objectPool.addObject(newLocation);
} catch (ObjectExistsException exc) {
LOG.error("Allegedly unique object ID/name already exists", exc);
throw new IllegalStateException("Allegedly unique object ID/name already exists", exc);
}
objectPool.emitObjectEvent(newLocation.clone(), null, TCSObjectEvent.Type.OBJECT_CREATED);
// Return the newly created point.
return newLocation;
}
use of org.opentcs.data.model.Location in project OpenTCS-4 by touchmii.
the class Model method setLocationType.
/**
* Sets a location's type.
*
* @param ref A reference to the location to be modified.
* @param typeRef The location's new type.
* @return The modified location.
* @throws ObjectUnknownException If the referenced location or name do not
* exist.
* @deprecated Use {@link #createLocation(org.opentcs.access.to.LocationCreationTO)} instead.
*/
@Deprecated
public Location setLocationType(TCSObjectReference<Location> ref, TCSObjectReference<LocationType> typeRef) throws ObjectUnknownException {
LOG.debug("method entry");
Location location = objectPool.getObjectOrNull(Location.class, ref);
if (location == null) {
throw new ObjectUnknownException(ref);
}
LocationType type = objectPool.getObjectOrNull(LocationType.class, typeRef);
if (type == null) {
throw new ObjectUnknownException(typeRef);
}
Location previousState = location.clone();
location.setType(type.getReference());
objectPool.emitObjectEvent(location.clone(), previousState, TCSObjectEvent.Type.OBJECT_MODIFIED);
return location;
}
Aggregations