コード例 #1
0
  /**
   * Reads a sim map from location set to the settings, mirrors the map and moves its upper left
   * corner to origo.
   *
   * @return A new SimMap based on the settings
   */
  private SimMap readMap() {
    SimMap simMap;
    Settings settings = new Settings(MAP_BASE_MOVEMENT_NS);
    WKTMapReader r = new WKTMapReader(true);

    if (cachedMap == null) {
      cachedMapFiles = new ArrayList<String>(); // no cache present
    } else { // something in cache
      // check out if previously asked map was asked again
      SimMap cached = checkCache(settings);
      if (cached != null) {
        nrofMapFilesRead = cachedMapFiles.size();
        return cached; // we had right map cached -> return it
      } else { // no hit -> reset cache
        cachedMapFiles = new ArrayList<String>();
        cachedMap = null;
      }
    }

    try {
      int nrofMapFiles = settings.getInt(NROF_FILES_S);

      for (int i = 1; i <= nrofMapFiles; i++) {
        String pathFile = settings.getSetting(FILE_S + i);
        cachedMapFiles.add(pathFile);
        r.addPaths(new File(pathFile), i);
      }

      nrofMapFilesRead = nrofMapFiles;
    } catch (IOException e) {
      throw new SimError(e.toString(), e);
    }

    simMap = r.getMap();
    checkMapConnectedness(simMap.getNodes());
    // mirrors the map (y' = -y) and moves its upper left corner to origo
    simMap.mirror();
    Coord offset = simMap.getMinBound().clone();
    simMap.translate(-offset.getX(), -offset.getY());
    checkCoordValidity(simMap.getNodes());

    cachedMap = simMap;
    return simMap;
  }