/**
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 * In particular this file is part of the Framework Core Library
 *
 * The iWear Framework is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the
 * Free Software Foundation as in version 2 of the License.

 *
 * The iWear Framework is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * The iWear Framework; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#include "iostream"
#include "stdlib.h"
#include "stdio.h"
#include "unistd.h"
#include "fcntl.h"
#include "string.h"
#include "math.h"
#include "sys/ioctl.h"
#include "stddef.h"
#include "sys/wait.h"
namespace iwear{
namespace iwearmap{
 
    class Pimp_Tile_Load {

      private:
      /**
       * @author Okhan Senkal
       * Deklaration the class variable
       *
       */
        
      /**
       * The pixel x size of the map
       */
        int mapsize_x;

      /**
       * The pixel y size of the map
       */
	int mapsize_y;

      /**
       * The maximal spatial x size of the map
       */
	double max_spatial_x;

      /**
       * The maximal spatial y size of the map
       */
	double max_spatial_y;

      /**
       * The directory where the tiles will be filed
       */
	char* directory;
      



    protected:

    public:

	/**
	 * standard constructor
	 */
	Pimp_Tile_Load();
	
        /**
         * @author Okhan Senkal
         * constructor
	 * @param mapsize_x: The pixel x size of the map
	 * @param mapsize_y: The pixel y size of the map
	 * @param max_spatial_x: The maximal spatial x size of the map
	 * @param max_spatial_y: The maximal spatial y size of the map
	 * @param directory: The directory where the tiles will be filed
	 */
	Pimp_Tile_Load(int mapsize_x, int mapsize_y,
                       double max_spatial_x, double max_spatial_y,
                       char* directory) ;
	
        /**
         * @author Okhan Senkal
         * destructor
         */
	~Pimp_Tile_Load();
	
        /**
         * @author Marius Mueller
         */
	void deliver_points();

	/**
	 * @author Okhan Senkal, Marius Mueller
	 * execute a unix command
	 * @param cmd This is the unix commando to execute 
	 * @param params These are the params for unix commando
	 */
	int exec_cmd(char* cmd, char* params[]);
	
    private:

	/**
	 *
	 * @author  Marius Mueller
	 */
	void filename();


    public:
	
	/**
	 *
	 * @author Okhan Senkal
	 * Get the tile on the basis of params. The tiles are loaded from a mapserver and will be saved in the filename where
	 * the user wanted  
	 * @param spatial_x1: The spatial lower left x coordinate in meters of the map 
	 * @param spatial_y1: The spatial lower left y coordinate in meters of the map
	 * @param spatial_x2: The spatial upper right x coordinate in meters of the map
	 * @param spatial_y2: The spatial upper right y coordinate in meters of the map
	 * @param mapsize_x: The pixel x size of the map
	 * @param mapsize_y: The pixel y size of the map
	 * @param host: The hostname  
	 * @param mapserver: The URL to the mapserver
	 * @param options: The further options who are in the URL
	 * @param filename: The filename where the map image will be saved 
	 */
	void get_tile(double spatial_x1, double spatial_y1, 
                      double spatial_x2, double spatial_y2, 
                      int mapsize_x, int mapsize_y,
		      char* host, char* mapserver, char* options,
                      char* filename);
	


    private:
	/**
	 *
	 * @author Marius Mueller
         */
	void tile_load();

        /**
         *
         * @author Marius Mueller
         */    	
	void del_tile(char* filename);

    };

}
}

