Package de.hpi.eworld.model.db.data

Examples of de.hpi.eworld.model.db.data.NodeModel


      new PolygonEventView(new PolygonEventModel(PolygonEventModel.Type.Rain, 1, null)),
      new PolygonEventView(new PolygonEventModel(PolygonEventModel.Type.Snow, 1, null)),
      new PolygonEventView(new PolygonEventModel(PolygonEventModel.Type.Ice, 1, null)),
      new StreetBarrierView(new RoadSpotModel(RoadSpotModel.Type.Busstop)),
      new StreetBarrierView(new RoadSpotModel(RoadSpotModel.Type.Liftgate)),
      new TrafficLightView(new TrafficLightModel(new NodeModel(0,0))));
    return (List<GraphicsView<EventModel>>) list;
  }
View Full Code Here


  {   
    Random rand = new Random();
    // connect test class with signal
    modelManager.addObserver(this);
    // create test element
    addedElement = new NodeModel(rand.nextDouble(), rand.nextDouble());
    // measure size before add
    int sizebefore = modelManager.getAllModelElements().size();
    // add element to list
    modelManager.addModelElement(addedElement);
    // measure size after
View Full Code Here

  private void addModelElements(int n, ModelManager instance)
  {
    Random rand = new Random();
    for(int i = 0 ; i < n; i++)
    {
      ModelElement e = new NodeModel(rand.nextDouble(), rand.nextDouble());
      instance.addModelElement(e);
    }
  }
View Full Code Here

  {
    Random rand = new Random();
    // connect test class with signal
    modelManager.addObserver(this);
    // create test element
    removedElement = new NodeModel(rand.nextDouble(), rand.nextDouble());
    // add element to list
    modelManager.addModelElement(removedElement);
    // measure size before remove
    int sizebefore = modelManager.getAllModelElements().size();
    Assert.assertEquals(sizebefore,1);
View Full Code Here

    if (vehicleSpeedMeterPerSeconds > DEFAULT_SPEED_METERS_PER_SECOND) {
      vehicleSpeedMeterPerSeconds = DEFAULT_SPEED_METERS_PER_SECOND;
    }

    // calculate position of start edge
    NodeModel startFromNode = startEdge.getFromNode();
    NodeModel startToNode = startEdge.getToNode();
    GlobalPosition startPosition = new GlobalPosition((startFromNode.getLatitude() + startToNode.getLatitude()) / 2.0,
        (startFromNode.getLongitude() + startToNode.getLongitude()) / 2.0);

    // calculate position of end edge
    NodeModel destinationFromNode = destinationEdge.getFromNode();
    NodeModel destinationToNode = destinationEdge.getToNode();

    GlobalPosition destinationPosition = new GlobalPosition((destinationFromNode.getLatitude() + destinationToNode
        .getLatitude()) / 2.0, (destinationFromNode.getLongitude() + destinationToNode.getLongitude()) / 2.0);

    // calculate distance from start edge to destination edge
    double distanceInMeters = startPosition.distanceTo(destinationPosition);

    // calculate the time to drive this distance by the usage of averaged speed
View Full Code Here

    List<?> elementList = (List<?>) argument;
    List<String> idList = new ArrayList<String>();
    String id;
    stringBuffer.append(TEXT_1);
    AbstractNodeModel abstractNode;
    NodeModel node = null;
    String type = "";
    for (Iterator<?> i = elementList.iterator(); i.hasNext();) {
      abstractNode = (AbstractNodeModel) i.next();
      // abstractNode is either NodeModel or TrafficLightModel!
      if (abstractNode.getClass().equals(NodeModel.class)) {
        type = "priority";
        node = (NodeModel) abstractNode;
      }
      else if (abstractNode.getClass().equals(TrafficLightModel.class)) {
        type = "traffic_light";
        node = ((TrafficLightModel) abstractNode).getNode();
      }
     
      id = node.getInternalID();
      if (idList.contains(id)) {
        id = id + "I";
      }
      idList.add(id);
      stringBuffer.append(TEXT_2);
      stringBuffer.append(id);
      stringBuffer.append(TEXT_3);
     
      // Perform projection of coordinates
      GlobalPosition g = node.getPosition();
      Projection p = ProjectionFactory.getInstance().getProjection(g.getLatitude(), g.getLongitude());
      double[] projected = p.projectToSUMO(g.getLongitude(), g.getLatitude());
      stringBuffer.append(projected[0]);
      stringBuffer.append(TEXT_4);
      stringBuffer.append(projected[1]);
View Full Code Here

   */
  private void testAddModelElements() {
    Assert.assertEquals(0, networkView.getGraphModel().items().length);
   
    // adding a node
    node = new NodeModel(0, 0);
    networkView.onModelElementAdded(node);
    Assert.assertEquals(1, networkView.getGraphModel().items().length);

    // adding a way
    way = new WayModel("Way");
    NodeModel to = new NodeModel(1, 1);
    way.addForwardEdge(new EdgeModel("testModelID", node, to));
    networkView.onModelElementAdded(to);
    networkView.onModelElementAdded(way);
    Assert.assertEquals(3, networkView.getGraphModel().items().length);

    // adding a point of interest
    poi = new PointOfInterest(0, 0, 0, "PoI");
    networkView.onModelElementAdded(poi);
    Assert.assertEquals(4, networkView.getGraphModel().items().length);

    // adding a traffic light
    trafficLight = new TrafficLightModel(new NodeModel(0,0));
    networkView.onModelElementAdded(trafficLight);
    Assert.assertEquals(5, networkView.getGraphModel().items().length);
  }
View Full Code Here

      if( qualifiedName.equals( "node" ) ) {
        String at;
        double lat = Double.parseDouble( currentAttributes.get( "lat" ) );
        double lon = Double.parseDouble( currentAttributes.get( "lon" ) );
       
        NodeModel node = null;
       
        at = currentAttributes.get( "highway");
        if( ( at != null ) && ( at.equals( "traffic_signals" ) ) ) {
         
//          node = new  TrafficLightModel( lat, lon );
          node = new NodeModel(lat,lon);
          modelManager.addModelElement(new TrafficLightModel(node));
          // Do not attempt to do this here because this Trafficlight then has no references to any edge.
          // The created nodes (variable n) will be added later at endDocument()!
          // modelManager.addModelElement( new TrafficLight( lat, lon ) );
          // if you do this, it is added twice
         
        } else if ( ( at != null ) && (at.equals( "bus_stop" ) )) {
          node = new RoadSpotModel(lat, lon, RoadSpotModel.Type.Busstop);
          modelManager.addModelElement(node);
        } else if ( ( at != null ) && (at.equals( "stop" ) )) {
         
          PointOfInterest poi = new PointOfInterest(lat, lon, "stop_sign");
          imported = true;
         
          // this means that POIs are added to the model in any case
          // and the node is added an other time if it is referenced
          // by an edge
          modelManager.addModelElement(poi);
         
          node = new NodeModel( lat, lon );

        } else if ( ( at != null ) && (at.equals( "crossing" ) )) {
//          node = new TrafficLightModel(lat, lon, TrafficLightModel.Crossing);
          node = new NodeModel(lat,lon);
          modelManager.addModelElement(new TrafficLightModel(node,TrafficLightModel.Type.Crossing));
        } else {
       
          at = currentAttributes.get( "name" );
          if( at != null ) {
           
            String label = at;
            if( currentAttributes.get( "railway" ) != null ) {
              label = "Railway Station: " + label;
              node = new NodeModel( lat, lon );
            } else {
              PointOfInterest poi = new PointOfInterest( lat, lon, label );
              imported = true;
             
              // this means that POIs are added to the model in any case
              // and the node is added an other time if it is referenced
              // by an edge
              modelManager.addModelElement(poi);
             
              node = new NodeModel( lat, lon );
            }
           
          } else {
           
            at = currentAttributes.get( "barrier");
            if( ( at != null ) && ( at.equals( "lift_gate" ) ) ) {
//              node = new TrafficLightModel(lat,lon, TrafficLightModel.Lift_Gate);
              node = new NodeModel(lat,lon);
              modelManager.addModelElement(new TrafficLightModel(node,TrafficLightModel.Type.Lift_Gate));
            }
            else if ( ( at != null ) && (at.equals( "gate" ) )) {
              PointOfInterest poi = new PointOfInterest(lat, lon, "gate");
              modelManager.addModelElement(poi);
              node = new NodeModel(lat,lon);
            }
            else if (at != null) {
              PointOfInterest poi = new PointOfInterest(lat, lon, "unknown_barrier_type");
              modelManager.addModelElement(poi);
              node = new NodeModel(lat,lon);
            }
            else {
              // just a node, nothing more
              node = new NodeModel( lat, lon );
              // Do not add nodes unless they are referenced by an edge or a way
              modelManager.addModelElement(node);
            } // if not barrier
           
          } // if not poi
View Full Code Here

     * @param noLanes number of lanes for current edge
     * @param way way the edge belongs to
     * @return the created edge
     */
    private EdgeModel createEdge( long fromNode, long toNode, WayModel way ) {
      NodeModel from = nodes.get( fromNode );
      NodeModel to = nodes.get( toNode );

      if(from == null || to == null){
        logger.error("Non existing node referenced!");
        return null;
      }
View Full Code Here

   * Saves the model element to an ewd file via ModelManager.saveToFile and Loads it afterwards to
   * check if all attributes are restored correctly
   */
  @Test
  public void testSaveAndRestore() {
    NodeModel node = new NodeModel(1., 2.);
    NodeModel helperNode = new NodeModel(2., 3.);
    EdgeModel usedByEdge = TestCaseUtil.createTestEdge(node, helperNode);
   
    ModelManager mm = ModelManager.getInstance();
    //make sure the model is empty before we add anything
    mm.clearModel();
   
    mm.addModelElement(node);
    mm.addModelElement(usedByEdge);
    //save it to an ewd file
    PersistenceManager.getInstance().saveToFile(EWD_FILE);
    //fine, now lets restore the saved objects
    mm.clearModel();
    PersistenceManager.getInstance().loadFromFile(EWD_FILE);
   
    Collection<ModelElement> modelElements = mm.getAllModelElements();
    Iterator<ModelElement> iterator = modelElements.iterator();
    Assert.assertEquals(2, modelElements.size());
    Object obj = iterator.next();
    if(obj instanceof NodeModel) {
      NodeModel restoredNode = (NodeModel) obj;
      Assert.assertTrue(node != null);
      Assert.assertEquals(1., restoredNode.getLatitude());
      Assert.assertEquals(2., restoredNode.getLongitude());
      Assert.assertEquals(1, restoredNode.getUsedBy().size());
    }
   
    //cleanup
    Assert.assertTrue(FileSysUtils.deleteFile(EWD_FILE));
  }
View Full Code Here

TOP

Related Classes of de.hpi.eworld.model.db.data.NodeModel

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.