Exemplo n.º 1
0
 /** (Re)Calculates the width of this junction */
 public void calculateWidth() {
   Road road;
   width = 4;
   for (int i = 0; i < 4; i++) {
     road = allRoads[i];
     if (road != null && road.getWidth() > width) width = road.getWidth();
   }
 }
Exemplo n.º 2
0
 /* clockwise order guaranteed */
 public Drivelane[] getAllLanes() throws InfraException {
   int pointer = 0;
   Drivelane[] lanes = new Drivelane[getNumAllLanes()];
   Drivelane[] temp;
   Road road;
   for (int i = 0; i < allRoads.length; i++) {
     road = allRoads[i];
     if (road != null) {
       temp = road.getInboundLanes(this);
       System.arraycopy(temp, 0, lanes, pointer, temp.length);
       pointer += temp.length;
       temp = road.getOutboundLanes(this);
       System.arraycopy(temp, 0, lanes, pointer, temp.length);
       pointer += temp.length;
     }
   }
   return lanes;
 }
Exemplo n.º 3
0
 public void addRoad(Road r, int pos) throws InfraException {
   if (r == null) throw new InfraException("Parameter r is null");
   if (pos > 3 || pos < 0) throw new InfraException("Position out of range");
   if (allRoads[pos] != null)
     throw new InfraException("Road already connected to position " + pos);
   allRoads[pos] = r;
   Node other = r.getOtherNode(this);
   if (other == null || !other.isAlphaRoad(r))
     alphaRoads = (Road[]) Arrayutils.addElement(alphaRoads, r);
   updateLanes();
   calculateWidth();
 }
Exemplo n.º 4
0
 public void loadSecondStage(Dictionary dictionaries)
     throws XMLInvalidInputException, XMLTreeException {
   super.loadSecondStage(dictionaries);
   // Load roads
   Dictionary roadDictionary = (Dictionary) (dictionaries.get("road"));
   allRoads = new Road[loadData.roads.length];
   for (int t = 0; t < loadData.roads.length; t++) {
     allRoads[t] = (Road) (roadDictionary.get(new Integer(loadData.roads[t])));
     if (allRoads[t] == null && loadData.roads[t] != -1)
       System.out.println("Warning : " + getName() + " could not find road " + loadData.roads[t]);
   }
   // Load normal signs
   Dictionary laneDictionary = (Dictionary) (dictionaries.get("lane"));
   signs = new Sign[loadData.signs.length];
   for (int t = 0; t < loadData.signs.length; t++)
     signs[t] = getSign(laneDictionary, loadData.signs[t]);
   // Load Signconfigurations
   signconfigs = new Sign[loadData.signconfigs.length][2];
   for (int t = 0; t < signconfigs.length; t++) {
     signconfigs[t] = new Sign[loadData.signconfigs[t].length];
     for (int u = 0; u < signconfigs[t].length; u++) {
       signconfigs[t][u] = getSign(laneDictionary, loadData.signconfigs[t][u]);
     }
   }
   // Tell *all* roads to load themselves
   // It's possible that this Node has a BetaLane that has not been SecondStageLoaded
   // And so we cant do an UpdateLanes() as that one needs secondStageData to proceed.
   // Hence, we need to 2ndStage all Roads.
   Enumeration e = new ArrayEnumeration(allRoads);
   Road tmpRoad;
   while (e.hasMoreElements()) {
     tmpRoad = (Road) e.nextElement();
     if (tmpRoad != null) tmpRoad.loadSecondStage(dictionaries);
   }
   try { // System.out.println("Trying to updateLanes()");
     updateLanes();
   } catch (InfraException x) {
     throw new XMLInvalidInputException("Cannot initialize lanes of node " + nodeId);
   }
 }