Examples of ParcelState


Examples of rinde.sim.core.model.pdp.PDPModel.ParcelState

      for (final Parcel p : parcels) {
        float rotation = AT_SITE_ROTATION;
        int offsetX = 0;
        int offsetY = 0;
        @Nullable
        final ParcelState ps = pdpModel.get().getParcelState(p);
        if (ps == ParcelState.AVAILABLE) {
          final Point pos = roadModel.get().getPosition(p);
          final int x = vp.toCoordX(pos.x);
          final int y = vp.toCoordY(pos.y);
          offsetX = (int) img.atSiteOffset.x + x - image.getBounds().width / 2;
          offsetY = (int) img.atSiteOffset.y + y - image.getBounds().height / 2;
        } else if (ps == ParcelState.PICKING_UP || ps == ParcelState.DELIVERING) {

          final Vehicle v = mapping.get(p);
          final PDPModel.VehicleParcelActionInfo vpai = pdpModel.get()
              .getVehicleActionInfo(v);
          final Point pos = roadModel.get().getPosition(v);
          final int x = vp.toCoordX(pos.x);
          final int y = vp.toCoordY(pos.y);
          final double percentage = 1d - vpai.timeNeeded()
              / (double) p.getPickupDuration();
          final String text = ((int) (percentage * 100d)) + "%";

          final float rotFac = (float) (ps == ParcelState.PICKING_UP ? percentage
              : 1d - percentage);
          rotation = IN_CARGO_ROTATION * rotFac;

          final int textWidth = gc.textExtent(text).x;
          gc.setBackground(gc.getDevice().getSystemColor(SWT.COLOR_BLUE));
          gc.drawText(text, (int) LABEL_OFFSET.x + x - textWidth / 2,
              (int) LABEL_OFFSET.y + y, true);

          Point from = new Point(img.atSiteOffset.x + x
              - image.getBounds().width
              / 2d, img.atSiteOffset.y + y - image.getBounds().height / 2d);
          Point to = new Point(img.inCargoOffset.x + x
              - image.getBounds().width
              / 2d, img.inCargoOffset.y + y - image.getBounds().height / 2d);

          if (ps == ParcelState.DELIVERING) {
            final Point temp = from;
            from = to;
            to = temp;
          }

          final Point diff = Point.diff(to, from);
          offsetX = (int) (from.x + (percentage * diff.x));
          offsetY = (int) (from.y + (percentage * diff.y));

        } else if (ps == ParcelState.IN_CARGO) {
          rotation = IN_CARGO_ROTATION;
          final Point pos = roadModel.get().getPosition(mapping.get(p));
          final int x = vp.toCoordX(pos.x);
          final int y = vp.toCoordY(pos.y);
          offsetX = (int) img.inCargoOffset.x + x - image.getBounds().width / 2;
          offsetY = (int) img.inCargoOffset.y + y - image.getBounds().height
              / 2;
        }

        if (ps != null && !ps.isDelivered()) {
          if (rotation == 0f) {
            gc.drawImage(image, offsetX, offsetY);
          } else {
            final Transform oldTransform = new Transform(gc.getDevice());
            gc.getTransform(oldTransform);
View Full Code Here

Examples of rinde.sim.core.model.pdp.PDPModel.ParcelState

    return getParcelPos(obj1).equals(getParcelPos(obj2));
  }

  Point getParcelPos(RoadUser obj) {
    if (!containsObject(obj) && obj instanceof DefaultParcel) {
      final ParcelState state = pdpModel.get().getParcelState(
          (DefaultParcel) obj);
      checkArgument(
          state == ParcelState.IN_CARGO,
          "Can only move to parcels which are either on the map or in cargo, state is %s, obj is %s.",
          state, obj);
View Full Code Here

Examples of rinde.sim.core.model.pdp.PDPModel.ParcelState

   */
  @Nullable
  public DefaultParcel getDestinationToParcel(MovingRoadUser obj) {
    if (destinations.containsKey(obj)
        && destinations.get(obj).type != DestType.DEPOT) {
      final ParcelState parcelState = pdpModel.get().getParcelState(
          (Parcel) destinations.get(obj).roadUser);
      // if it is a pickup destination it must still be available
      if ((destinations.get(obj).type == DestType.PICKUP
          && parcelState == ParcelState.AVAILABLE || parcelState == ParcelState.ANNOUNCED)
          // if it is a delivery destination it must still be in cargo
View Full Code Here

Examples of rinde.sim.core.model.pdp.PDPModel.ParcelState

   */
  public void setRoute(Collection<DefaultParcel> r) {
    // note: the following checks can not detect if a parcel has been set to
    // multiple vehicles at the same time
    for (final DefaultParcel dp : r) {
      final ParcelState state = pdpModel.get().getParcelState(dp);
      checkArgument(
          !state.isDelivered(),
          "A parcel that is already delivered can not be part of a route. Parcel %s in route %s.",
          dp, r);
      if (state.isTransitionState()) {
        if (state == ParcelState.PICKING_UP) {
          checkArgument(
              pdpModel.get().getVehicleState(this) == VehicleState.PICKING_UP,
              "When a parcel in the route is in PICKING UP state the vehicle must also be in that state.");
        } else {
          checkArgument(
              pdpModel.get().getVehicleState(this) == VehicleState.DELIVERING,
              "When a parcel in the route is in DELIVERING state the vehicle must also be in that state.");
        }
        checkArgument(
            pdpModel.get().getVehicleActionInfo(this).getParcel() == dp,
            "A parcel in the route that is being serviced should be serviced by this truck. This truck is servicing %s.",
            pdpModel.get().getVehicleActionInfo(this).getParcel());
      }

      final int frequency = Collections.frequency(r, dp);
      if (state.isPickedUp()) {
        checkArgument(pdpModel.get().getContents(this).contains(dp),
            "A parcel that is in cargo state must be in cargo of this vehicle.");
        checkArgument(
            frequency <= 1,
            "A parcel that is in cargo may not occur more than once in a route, found %s instance(s) of %s.",
View Full Code Here

Examples of rinde.sim.core.model.pdp.PDPModel.ParcelState

   * @param time The current time.
   * @return <code>true</code> when leaving in this tick would mean arriving too
   *         early, <code>false</code> otherwise.
   */
  protected boolean isTooEarly(Parcel p, TimeLapse time) {
    final ParcelState parcelState = pdpModel.get().getParcelState(p);
    checkArgument(
        !parcelState.isTransitionState() && !parcelState.isDelivered(),
        "Parcel state may not be a transition state nor may it be delivered, it is %s.",
        parcelState, parcelState.isTransitionState() ? pdpModel.get()
            .getVehicleActionInfo(this).timeNeeded() : null);
    final boolean isPickup = !parcelState.isPickedUp();
    // if it is available, we know we can't be too early
    if (isPickup && parcelState == ParcelState.AVAILABLE) {
      return false;
    }
    final Point loc = isPickup ? ((DefaultParcel) p).dto.pickupLocation : p
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.