Package com.dcaiti.eworld.visualizer.simulation.models

Examples of com.dcaiti.eworld.visualizer.simulation.models.Vehicle


  };

  @Override
  public void update(Observable obj, Object arg) {
    if (arg instanceof Vehicle) {
      Vehicle addedVehicle = (Vehicle) arg;

      String id = addedVehicle.getID();
      String type = addedVehicle.getPrettyName();
      Double latitude = GlobalPosition.from(Point2DUtils.convertPoint(addedVehicle.getPosition())).getLatitude();
      Double longitude = GlobalPosition.from(Point2DUtils.convertPoint(addedVehicle.getPosition()))
          .getLongitude();
      String speed = Double.toString(Math.round(addedVehicle.getSpeed() * 100.) / 100.);
      String direction = Double.toString(Math.round(addedVehicle.getDirection() * 100.) / 100.) + " ("
          + Utilities.getCardinalDirection(addedVehicle.getDirection()) + ")";
      String coveredDistance = Double.toString(Math.round(addedVehicle.getDistance() * 100.) / 100.);
      String communicationCount = addedVehicle.getSentCount() + "/" + addedVehicle.getReceivedCount();

      Object[] addedData = new Object[] { id, type, latitude, longitude, speed, direction, coveredDistance,
          communicationCount };

      // Add a new model to the table
      if (!modelsToRows.containsKey(addedVehicle.getID())) {
        // No speed and direction yet
        addedData[columns.get("Speed [km/h]")] = "Awaiting...";
        addedData[columns.get("Direction [\u00b0]")] = "Awaiting...";
        tableModel.addRow(addedData);
        modelsToRows.put(addedVehicle.getID(), tableModel.getRowCount() - 1);
        tableModel.setValueAt(true, modelsToRows.get(addedVehicle.getID()), columns.get("Annotation"));
        tableModel.setValueAt(true, modelsToRows.get(addedVehicle.getID()), columns.get("Radius"));
        tableModel.setValueAt(false, modelsToRows.get(addedVehicle.getID()), columns.get("Destination"));
        tableModel.setValueAt(false, modelsToRows.get(addedVehicle.getID()), columns.get("V2X-Tracing"));
        tableModel.setValueAt(false, modelsToRows.get(addedVehicle.getID()), columns.get("Hide"));
        updateGlobalSettings(modelsToRows.get(addedVehicle.getID()), modelsToRows.get(addedVehicle.getID()));
      }
      // Modify an existing model in the table
      else {
        tableModel.setValueAt(id, modelsToRows.get(addedVehicle.getID()), columns.get("ID"));
        tableModel.setValueAt(type, modelsToRows.get(addedVehicle.getID()), columns.get("Type"));
        tableModel.setValueAt(latitude, modelsToRows.get(addedVehicle.getID()), columns.get("Latitude"));
        tableModel.setValueAt(longitude, modelsToRows.get(addedVehicle.getID()), columns.get("Longitude"));
        tableModel.setValueAt(speed, modelsToRows.get(addedVehicle.getID()), columns.get("Speed [km/h]"));
        tableModel.setValueAt(direction, modelsToRows.get(addedVehicle.getID()), columns.get("Direction [\u00b0]"));
        tableModel.setValueAt(coveredDistance, modelsToRows.get(addedVehicle.getID()),
            columns.get("Distance [km]"));
        tableModel.setValueAt(communicationCount, modelsToRows.get(addedVehicle.getID()),
            columns.get("# Sent/Received"));

        Boolean displayAnnotations = (Boolean) tableModel.getValueAt(modelsToRows.get(addedVehicle.getID()),
            columns.get("Annotation"));
        if (displayAnnotations)
          addedVehicle.setDisplayingAnnotations(true);
        else
          addedVehicle.setDisplayingAnnotations(false);

        Boolean displayRadius = (Boolean) tableModel.getValueAt(modelsToRows.get(addedVehicle.getID()),
            columns.get("Radius"));
        if (displayRadius)
          addedVehicle.setDisplayingRadius(true);
        else
          addedVehicle.setDisplayingRadius(false);

        Boolean displayDestination = (Boolean) tableModel.getValueAt(modelsToRows.get(addedVehicle.getID()),
            columns.get("Destination"));
        if (displayDestination)
          addedVehicle.setDisplayingDestination(true);
        else
          addedVehicle.setDisplayingDestination(false);

        Boolean v2xTracing = (Boolean) tableModel.getValueAt(modelsToRows.get(addedVehicle.getID()),
            columns.get("V2X-Tracing"));
        if (v2xTracing)
          addedVehicle.setV2XTracing(true);
        else
          addedVehicle.setV2XTracing(false);

        Boolean hidden = (Boolean) tableModel.getValueAt(modelsToRows.get(addedVehicle.getID()),
            columns.get("Hide"));
        if (hidden)
          addedVehicle.setHidden(true);
        else
          addedVehicle.setHidden(false);
      }
    }
    else if (arg instanceof RoadsideUnit) {
      RoadsideUnit addedRoadsideUnit = (RoadsideUnit) arg;

View Full Code Here


   *      The speed of the Vehicle in meters per second (m/s)
   * @param direction
   *      The direction of the Vehicle in degrees
   */
  public void updateVehicle(String id, double[] position, float speed, float direction) {
    Vehicle updatedVehicle = vehicles.get(id);
    if (updatedVehicle != null) {
      updatedVehicle.setPosition(position);
      updatedVehicle.setSpeed(speed);
      updatedVehicle.setDirection(direction);
      updateCounter();
      if (SimulationSettings.getInstance().isShowingStatusBarSteps()) {
        MainStatusBar.getInstance().showMessage(
            "Updated Vehicle [id: " + id + "] [latitude: " + Double.toString(position[0]) + ", longitude: "
                + Double.toString(position[1]) + "]");
View Full Code Here

   *
   * @param id
   *      The unique identifier (e.g. SUMO ID) of the model, that was removed from the simulation
   */
  public void removeModel(String id) {
    Vehicle removedVehicle = vehicles.get(id);
    if (removedVehicle != null) {
      networkViewPlugin.removeVolatileModelElement(removedVehicle);
      vehicles.remove(id);
      updateCounter();
//      MonitorWidget.getInstance().remove(id);
      if (SimulationSettings.getInstance().isShowingStatusBarSteps()) {
        MainStatusBar.getInstance().showMessage("Removed Vehicle [id: " + id + "]");
      }
      switch (removedVehicle.getType()) {
        case 0x01:
          setChanged();
          notifyObservers(ObserverNotifications.classicVehicleRemoved);

          break;
View Full Code Here

   * @param destinationRadius
   *      The radius of the destination (if destination is geographic)
   */
  public void sendNetworkMessage(String id, int messageID, byte[] ipSegments, double destinationLatitude,
      double destinationLongitude, float destinationRadius) {
    Vehicle sendingVehicle = vehicles.get(id);
    if (sendingVehicle != null) {
      sendingVehicle.sendMessage(messageID, ipSegments, destinationLatitude, destinationLongitude,
          destinationRadius);
      updateCounter();
      if (SimulationSettings.getInstance().isShowingStatusBarSteps()) {
        if (ipSegments == null)
          ipSegments = new byte[] { 0, 0, 0, 0 };
View Full Code Here

   *      message
   * @param messageID
   *      The unique ID of the sent network message
   */
  public void receiveNetworkMessage(String id, int messageID) {
    Vehicle receivingVehicle = vehicles.get(id);
    if (receivingVehicle != null) {
      receivingVehicle.receiveMessage(messageID);
      updateCounter();
      if (SimulationSettings.getInstance().isShowingStatusBarSteps()) {
        MainStatusBar.getInstance().showMessage(
            "Vehicle is receiving a messsage [id: " + id + "] [message id: " + Integer.toString(messageID)
                + "]");
View Full Code Here

  private void addVehicle(final String id, final double latitude,
      final double longitude, final byte type) {
    Runnable worker = new Runnable() {
      @Override
      public synchronized void run() {
        Vehicle addedVehicle = new Vehicle(id, type, Utilities.project(
            latitude, longitude));
        modelController.addVehicle(addedVehicle);

        if (simulationSettings.isBuffering()) {
          simulationBuffer.add(
              VisualizationConstants.CMD_ADD,
              new Vehicle(id, type, Utilities.project(latitude,
                  longitude)));
        }

        if (sync)
          try {
View Full Code Here

      public synchronized void run() {
        modelController.updateVehicle(id,
            Utilities.project(latitude, longitude), speed,
            direction);
        if (simulationSettings.isBuffering()) {
          Vehicle updatedVehicle = new Vehicle(modelController
              .getVehicle(id).getID(), modelController
              .getVehicle(id).getType(), modelController
              .getVehicle(id).getPosition());
          updatedVehicle.setSpeed(speed);
          updatedVehicle.setDirection(direction);
          simulationBuffer.add(VisualizationConstants.CMD_UPDATE,
              updatedVehicle);
        }

        if (sync)
View Full Code Here

                destinationLatitude, destinationLongitude)[1],
            destinationRadius);

        if (simulationSettings.isBuffering()) {
          if (modelController.getVehicle(id) != null) {
            Vehicle sendingVehicle = new Vehicle(modelController
                .getVehicle(id).getID(), modelController
                .getVehicle(id).getType(), modelController
                .getVehicle(id).getPosition());
            sendingVehicle.setSentMessageID(messageID);
            sendingVehicle.setIPSegments(ipSegments);
            sendingVehicle
                .setDestinationLatitude(destinationLatitude);
            sendingVehicle
                .setDestinationLongitude(destinationLongitude);
            sendingVehicle.setDestinationRadius(destinationRadius);
            simulationBuffer.add(
                VisualizationConstants.CMD_SENDV2X,
                sendingVehicle);
          } else if (modelController.getRoadsideUnit(id) != null) {
            RoadsideUnit sendingRoadsideUnit = new RoadsideUnit(
View Full Code Here

      @Override
      public synchronized void run() {
        modelController.receiveNetworkMessage(id, messageID);
        if (simulationSettings.isBuffering()) {
          if (modelController.getVehicle(id) != null) {
            Vehicle receivingVehicle = new Vehicle(modelController
                .getVehicle(id).getID(), modelController
                .getVehicle(id).getType(), modelController
                .getVehicle(id).getPosition());
            receivingVehicle.setReceivedMessageID(messageID);
            simulationBuffer.add(
                VisualizationConstants.CMD_RECVV2X,
                receivingVehicle);
          } else if (modelController.getRoadsideUnit(id) != null) {
            RoadsideUnit receivingRoadsideUnit = new RoadsideUnit(
View Full Code Here

   * @param model
   *      The models new state
   */
  public void add(byte command, VolatileModelElement model) {
    if (model instanceof Vehicle) {
      Vehicle addedVehicle = (Vehicle) model;
      // Convert speed back to meters per second (m/s)
      addedVehicle.setSpeed(addedVehicle.getSpeed() / 3.6f / 3.6f);
      buffer.add(new SimulationStep<Byte, VolatileModelElement>(command, addedVehicle));
    }
    else if (model instanceof RoadsideUnit) {
      RoadsideUnit addedRoadsideUnit = (RoadsideUnit) model;
      buffer.add(new SimulationStep<Byte, VolatileModelElement>(command, addedRoadsideUnit));
View Full Code Here

TOP

Related Classes of com.dcaiti.eworld.visualizer.simulation.models.Vehicle

Copyright © 2018 www.massapicom. 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.