// File: inputdata.h
// Created by: <Jörn Reimerdes>
// Created on: 22.03.2005

/**
 * dcagmarkassistant.h - is part of the iwear-framework
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 * In particular this file is part of the Framework Input 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
 */

#ifndef __DCAGMARKASSISTANT_H
#define __DCAGMARKASSISTANT_H

#ifndef __SERVICEMANAGER_H
#include <iwear/servicemanager.h>
#endif

#ifndef __OUTPUTMANAGER_H
#include <iwear_output/outputmanager.h>
#endif

#ifndef __INPUTMANAGER_H
#include <iwear_input/inputmanager.h>
#endif

#ifndef __APPLICATIONSERVICE_H
#include <iwear_uiservices/applicationservice.h>
#endif

#ifndef __APPLICATION_H
#include <iwear_uiservices/application.h>
#endif

#ifndef __I18N_H
#include <iwear/i18n.h>
#endif

#ifndef __TEXTDATA_H
#include <iwear_output/textdata.h>
#endif

#ifndef __IMAGEDATA_H
#include <iwear_output/imagedata.h>
#endif

#ifndef __WIDGETDATA_H
#include <iwear_output/widgetdata.h>
#endif

#ifndef __CAR_H
#include <iwear_dcag_mark_assistant/car.h>
#endif

#ifndef __WELDPOINT_H
#include <iwear_dcag_mark_assistant/weldpoint.h>
#endif

#ifndef __CONFIGURATION_H
#include <iwear/configuration.h>
#endif

#ifndef __CHECK_H
#include <iwear_dcag_mark_assistant/check.h>
#endif

#ifndef __MARKASSISTANTMENUFUNCTOR_H
#include <iwear_dcag_mark_assistant/markassistantmenufunctor.h>
#endif

#ifndef __POINTSELECTOR_H
#include <iwear_dcag_mark_assistant/pointselector.h>
#endif

using namespace iwear;
using namespace iwear::uiservices;
using namespace iwear::input;
using namespace iwear::output;
using namespace iwear::dcag;

namespace iwear {
namespace dcag {

/** DCAGMarkAssistant is an iWear Applicaction to support the weld
 * point marking within the breaking test pocess.
 */
class DCAGMarkAssistant : public Application
{
public:

    /**
     * The constructor
     * @param as A pointer to the application service
     */
    DCAGMarkAssistant(ApplicationService* as,
	const std::string& dn = "markassistant",
		  const std::string& dd = string(i18n::trans("DCAG Mark Assistant Quality Check Tool")));

    /**
     * A special constructor which is required to load the 
     * markassistant as a plugin (Development version)
     */
//    DCAGMarkAssistant( void );

    /**
     * The destructor
     */
    virtual ~DCAGMarkAssistant( void );

    virtual void Run( void );

    virtual void Init_Application( void );

    virtual void Final_Application( void );

    /** Is called when a menu element is activated.
     * It takes the button id and will call the method which is
     * related to the related button.
     * @param button_id The id of the activated button.
     * @todo make it protected
     */
    void on_menu_element_activated(const uint32_t button_id);


    /** Execute on menu element selection 
     * @param button_id The id of the activated button.
     */
    void on_element_selected(const uint32_t button_id);

protected:

    virtual void set_default_configuration( void );

    /** The mark assistant application configuration. */
    //Configuration& config;

    /** The home directory of the mark assiatnat application. */
    string markassistant_home;
    
    /** The path of the directory where the new checks are stored. */
    string check_dir;

    /** The path of the directory where the saved checks are stored. */
    string saved_check_dir;

    /** The content which will be displayed as a TextData. */
    //string text_content;

    /** The path to the image which will be displayed as a ImageData. */
    string image_dir;

    /** The path where the temporary images will be stored. */
    string image_tmp_dir;

    /** The path where the system images like backgrounds will be stored. */
    string image_system_dir;

private: 

    bool text_on_display;

    bool image_on_display;

    bool image_zoomed;

    /** The text data which is displayed by the MarkAssistant. */
    TextData* text_data;

    /** The image data which is displayed by the MarkAssistant. */
    ImageData* image_data;

   /** This widget shows the status of the current check, e.g. "15 / 100". */
    WidgetData* status_widget;

    /** stores all submenues which already have been generated. */
    list<uint32_t> already_initialised_submenues;

    /** List of the checks which can be continued. */
    list<Check*> saved_checks;

    /** List of checks which are new. */
    list<Check*> new_checks;
    
    /** List of available cars of the current check. */
    list<Car*> car_list;

    /** The current selected car. */
    Car* current_car;

    /** The current selected check. */
    Check* current_check;

   /** Is true when a error message is shown */
   //bool has_error;

    /** The list of images for the current weldpoint */
    list<string> current_image_list;

    /** The Iterator to the current displayed picture */
    list<string>::iterator current_image;

    /** The Functor which will be registeder to and called by the menu. */
    MarkAssistantMenuFunctor* menu_functor;

    /** Initializes some class fields with values from the config. */
    void load_configuration();

    /** The point which is currently selected.  */
    list<Weldpoint*>::iterator current_weldpoint;

    /** point selector */
    PointSelector* point_selector;

    /** point selector status variable */
    bool point_selector_started;
    
    /** The id of the submenu which contains the actions which are
     *  related to continue a check. */
    uint32_t check_continue_submenu_id;

    /** The id of the submenu which contains the actions which are
     *	related to a new check. */
    uint32_t check_new_submenu_id;

    /** The id of the submenu which contains the check process functions.
     */
    uint32_t check_process_submenu_id;

    /** The id of the mark point button.
     */
    uint32_t mark_button_id;

    /** The id of the previous point button.
     */
    uint32_t previous_point_button_id;

    /** The id of the next point button.
     */
    uint32_t next_point_button_id;

    /** The id of the zoom in/out button.
     */
    uint32_t zoom_button_id;

    /** The id of the change point view button.
     */
    uint32_t change_view_button_id;

    /** The id of the select points submenu.
     */
    uint32_t select_points_submenu_id;

    /** The id of the add point to list button.
     */
    uint32_t add_point_button_id;

    /** The id of the delete point from list button.
     */
    uint32_t delete_point_button_id;

    /** The id of the start check button.
     */
    uint32_t start_check_button_id;

    /** The id of the select last point button.
     */
    uint32_t select_last_point_button_id;

    /** The number of Lines of Points to be displayed by Pointselector
     */
    int pointselector_list_length;
    
    /** The id of the submenu which contains select buttons for each
     * 	available car. */
//     uint32_t car_submenu_id;

    /** The default representation of a button or submenu.
     * @ToDo: Create and use a config file which contains the
     * representations for the menu elements.
     */
    const string default_representation;
    
    /** A map of car submenu ids and the related cars. */
    map<uint32_t, Car*> car_submenu_map; 

    /** Maps submenu ids to the check which belongs to it. */
    map<uint32_t, Check*> new_check_submenu_map;

    /** Maps submenu ids to the check which belongs to it. */
    map<uint32_t, Check*> saved_check_submenu_map;

    /** Laods the car list depending on the current check. */
    void load_car_list(string folder);

    /** Adds all available cars to the menu.
     * @note It is required that the menu structure was initialised
     *  first.
     * @param submenu_id The submenu id which identifies the submenu
     * where the cars should be added to. In most cases this would be
     * a check submenu.
     * @param car_list A list of the available cars.
     */
    void add_available_cars_to_menu(uint32_t submenu_id, list<Car*>& car_list );

    /** Adds all available saved checks to the menu.
     * @param saved_checks The saved checks which are available.
     */
    void add_saved_checks_to_menu( list<Check*>& saved_checks );
    
    /** Adds all available new checks to the menu.
     * @param new_checks The new checks which are available.
     */
    void add_new_checks_to_menu( list<Check*>& new_checks );

    /** Adds all checks to menu.
     * The list should allsow be displayed within a TextData.
     * The submenu id to which the checks should be added is 
     * <code>this->check_continue_submenu_id</code>
     * @param check A list of Checks
     */
    void add_old_checks_to_menu(list<Check*> check);

    /** 
     */
    void set_welding_points_output_data( void );

    /** Initialises the menu structure of the DCAG Mark Assistant.
     */
    void init_menu_base_structure( void );

    /** Initialises the new checks menu structure of the DCAG Mark Assistant.
     */
    void init_submenu_new_checks_structure( void );

    /** Initialises the new checks menu structure of the DCAG Mark Assistant.
     */
    void init_submenu_saved_checks_structure( void );

    /** Initialises the submenu for the check process.
     */
    void init_submenu_check_process_structure( void );
    
    /** Initialises the submenu for the check process.
     */
    void init_submenu_select_points_structure( void );

    /** Displays the about information. */
    void display_about_info();

    /** Stops displaying the about information */
    void stop_about_info();

    /** Is called if a car button was activated.
     * @param button_id The id of the button which is related to a car.
     */
    void on_car_button_activation( uint32_t button_id );

    /** Is called if the "next point" button was activated. */
    void on_next_point_activation(bool next_unmarked = false);

    /** Is called if the "previous point" button was activated. */
    void on_previous_point_activation();

    /** Is called if the "change view" button was activated. */
    void on_change_view_activation();

    /** Is called if the "zoom" button was activated. */
    void on_zoom_activation() ;

    /** displays the image_data */
    void show_current_weldpoint();

    /** Checks whether a submenu is already initialised.
     * @param submenu_id The menu which should be checked.
     * @return true if the menu was already initialised else false.
     */
    inline bool is_already_initialised_submenu(uint32_t submenu_id){
	list<uint32_t>::iterator id_iterator = 
	    this->already_initialised_submenues.begin();
	/* Check all entries. */
	while (id_iterator != this->already_initialised_submenues.end()){
	    if (submenu_id == *id_iterator){
		return true;
	    }
	}
	return false;
    }

    /** The about information image data. */
    ImageData* about_data;

    /** The id of the about button. */
    uint32_t about_button_id;


};

} // input
} // iwear
#endif	//__DCAGMARKASSISTANT_H

