// ui.cxx
// This file is part of galvani.
// It contains the user interface.
// Copyright (C) 2020-2024 Burkard Lutz <b.lutz@online.de>
//
// This program 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; either version 2 of the License, or
// (at your option) any later version.
//
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.

#include <gtkmm.h>
#include <glibmm/i18n.h>
#include <filesystem>
#include "config.h"
#include "typedef.h"
#include "ui.h"

namespace fs = std::filesystem;

// The main window

Main_Window::Main_Window ()
: main_box (Gtk::Orientation::VERTICAL)
{
	set_title("Galvani");
	set_default_size(1200, 900);
	set_child (main_box);

	//create dialogs
	//project properties
	projekt_prop = new ProjectDialog;
	projekt_prop->set_transient_for(*this);
	//error
	error_dialog = new Gtk::MessageDialog (_("Error Message"), false, Gtk::MessageType::ERROR, Gtk::ButtonsType::OK, true);
	error_dialog->set_transient_for(*this);
	error_dialog->set_hide_on_close (true);
     //Info and Question Dialog
	msg_dialog = new MsgDialog;
    msg_dialog->set_transient_for (*this);
    info_dialog = Gtk::AlertDialog::create ();

	//File Filter
	dat_filters = Gio::ListStore<Gtk::FileFilter>::create();
	filefilter_dat = Gtk::FileFilter::create();
	filefilter_dat->set_name("Galvani data");
	filefilter_dat->add_pattern("*.dat");
	dat_filters->append(filefilter_dat);
	img_filters = Gio::ListStore<Gtk::FileFilter>::create();
	filefilter_img = Gtk::FileFilter::create();
	filefilter_img->set_name("Images");
   	filefilter_img->add_pattern("*.png");
	filefilter_img->add_pattern("*.svg");
	img_filters->append(filefilter_img);

	//File Dialog for reading and writing data
	file_dialog = Gtk::FileDialog::create();

	//translate functions
	map_func = new MapFunc;
	map_func->set_transient_for(*this);

	//Options Dialog
	options_dialog = new OptionsDialog;
	options_dialog->set_transient_for (*this);

	//Timer Dialog sets timer to start measurement
	timer_dialog = new TimerDialog;
	timer_dialog->set_transient_for (*this);

	// Settings for data evaluation
	data_transform_dialog = new EvalData_Transform_Dialog;
    data_transform_dialog->set_transient_for (*this);
    eval_function_dialog = new Eval_Function_Dialog;
    eval_function_dialog->set_transient_for (*this);

	// Results of data evaluation
	eval_results = new EvalResults;
	eval_results->set_transient_for (*this);

    //Print Dialog
	print_dialog = new Print_Dialog;
	print_dialog->set_transient_for (*this);

	menu = Gio::Menu::create ();
	// menu file
	menu_file = Gio::Menu::create ();
	menu_file->append(_("_New"), "win.new");
	action_new = add_action("new", sigc::mem_fun(*projekt_prop, &ProjectDialog::new_project));
	menu_file->append(_("_Open"), "win.open");
	action_open = add_action("open", sigc::ptr_fun(open_datafile));
	menu_file->append(_("_Save"), "win.save");
	action_save = add_action("save", sigc::ptr_fun(save_data));
	menu_file->append (_("_Export"), "win.export_diag");
	action_export = add_action("export_diag", sigc::ptr_fun(export_diag));
	menu_file->append(_("_Print"), "win.print");
	action_print = add_action("print", sigc::mem_fun(*print_dialog, &Print_Dialog::prepare_printreport));
	menu_file->append(_("_Quit"), "app.quit");	//-> action defined in main.cxx
	menu->append_submenu (_("_File"), menu_file);
	action_save->set_enabled (false);
	action_export->set_enabled (false);
	action_print->set_enabled (false);

	//menu view
	menu_view = Gio::Menu::create ();
	menu_view->append(_("Display"), "win.display");
	display_toggle = add_action_bool("display", sigc::mem_fun(*this, &Main_Window::toggle_display), show_display);
	menu->append_submenu (_("_View"), menu_view);

	//menu measurement
	menu_mess = Gio::Menu::create ();
	menu_mess->append(_("_New Measurement"), "win.mess_new");
	action_mess_new = add_action("mess_new", sigc::ptr_fun(begin_mess));
	menu_mess->append(_("_Start Measurement"), "win.mess_start");
	action_mess_start = add_action("mess_start", sigc::ptr_fun(start_mess));
	menu_mess->append(_("_Start with Timer"), "win.mess_start_with_timer");
	action_mess_start_with_timer = add_action("mess_start_with_timer", sigc::mem_fun(*timer_dialog, &TimerDialog::start_mess_with_timer));
	menu_mess->append(_("_Cancel Measurement"), "win.mess_cancel");
	action_mess_cancel = add_action("mess_cancel", sigc::ptr_fun(cancel_mess));
	menu_mess->append(_("_Stop Measurement"), "win.mess_stop");
	action_mess_stop = add_action("mess_stop", sigc::ptr_fun(stop_mess));
	menu_mess->append(_("_End Measurement"), "win.mess_end");
	action_mess_end = add_action("mess_end", sigc::ptr_fun(end_mess));
	menu->append_submenu (_("_Measurement"), menu_mess);

	//menu evaluation
	menu_eval = Gio::Menu::create ();
	menu_eval->append(_("_Data Transformation"), "win.transform_data");
	action_transform_data = add_action("transform_data", sigc::mem_fun(*project, &Project::show_data_transformation));
	menu_eval->append(_("_Evaluation Functions"), "win.eval_functions");
	action_eval_functions = add_action("eval_functions", sigc::mem_fun(*project, &Project::show_eval_functions));
	menu->append_submenu (_("_Data"), menu_eval);

	//menu options
	menu_options = Gio::Menu::create ();
	menu_options->append(_("_Data Channel X"), "win.options_device_x");
	action_options_device_x = add_action("options_device_x", sigc::mem_fun(*options_dialog, &OptionsDialog::show_options_device_x));
	menu_options->append(_("_Data Channel Y"), "win.options_device_y");
	action_options_device_y = add_action("options_device_y", sigc::mem_fun(*options_dialog, &OptionsDialog::show_options_device_y));
	menu_options->append(_("_Diagram"), "win.options_diag");
	action_options_diag = add_action("options_diag", sigc::mem_fun(*options_dialog, &OptionsDialog::show_options_diag));
	menu_options->append(_("_Load Options"), "win.load_options");
	add_action("load_options", sigc::mem_fun(*options_dialog, &OptionsDialog::load_all_options));
	menu_options->append(_("_Save Options"), "win.save_options");
	add_action("save_options", sigc::mem_fun(*options_dialog, &OptionsDialog::save_all_options));
	menu_options_auto = Gio::Menu::create ();
	menu_options_auto->append(_("Autoload Settings"), "win.options_autoload");
	toggle_autoload = add_action_bool("options_autoload", sigc::mem_fun(*this, &Main_Window::set_autoload), autoload);
	menu_options_auto->append(_("Autosave Settings"), "win.options_autosave");
	toggle_autosave = add_action_bool("options_autosave", sigc::mem_fun(*this, &Main_Window::set_autosave), autosave);
	menu_options->append_section ("", menu_options_auto);
	menu->append_submenu (_("_Settings"), menu_options);

	//menu help
	menu_help = Gio::Menu::create ();
	menu_help->append(_("_Help"), "win.help");
	add_action("help", sigc::mem_fun(*this,&Main_Window::help));
	menu_help->append(_("_About"), "win.about");
	add_action("about", sigc::mem_fun(*this,&Main_Window::about));
	menu->append_submenu (_("_Help"), menu_help);

	action_mess_start->set_enabled (false);
	action_mess_start_with_timer->set_enabled (false);
	action_mess_cancel->set_enabled (false);
	action_mess_stop->set_enabled (false);
	action_mess_end->set_enabled (false);
	action_transform_data->set_enabled (false);
	action_eval_functions->set_enabled (false);

	// create toolbar
	std::string icondir = "/usr/share/galvani/icon/";

	toolbar = Gtk::Box(Gtk::Orientation::HORIZONTAL);
	//button new
	auto new_pix = Gtk::make_managed<Gtk::Image>(icondir+"new-project.svg");
	auto new_pixbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 5);
	new_pixbox->append(*new_pix);
    button_new.set_child (*new_pixbox);
	toolbar.append (button_new);
	button_new.set_tooltip_text (_("New project"));
	button_new.signal_clicked().connect(sigc::mem_fun(*projekt_prop, &ProjectDialog::new_project));
    //button edit
	auto edit_pix = Gtk::make_managed<Gtk::Image>(icondir+"edit-project.svg");
	auto edit_pixbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 5);
    edit_pixbox->append(*edit_pix);
    button_edit.set_child (*edit_pixbox);
	toolbar.append (button_edit);
	button_edit.set_tooltip_text (_("Edit project settings"));
	button_edit.signal_clicked().connect(sigc::mem_fun(*projekt_prop, &ProjectDialog::define_project));
	//button open
	auto open_pix = Gtk::make_managed<Gtk::Image>(icondir+"open.svg");
	auto open_pixbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 5);
    open_pixbox->append(*open_pix);
    button_open.set_child (*open_pixbox);
	button_open.set_tooltip_text (_("Import data from file"));
	button_open.signal_clicked().connect(sigc::ptr_fun(open_datafile));
	toolbar.append (button_open);
    //button save
	auto save_pix = Gtk::make_managed<Gtk::Image>(icondir+"save.svg");
	auto save_pixbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 5);
    save_pixbox->append(*save_pix);
    button_save.set_child (*save_pixbox);
	button_save.set_tooltip_text (_("Save data"));
	button_save.signal_clicked().connect(sigc::ptr_fun(save_data));
	toolbar.append (button_save);
	button_save.set_sensitive (false);
	//button export diagramm
	auto exp_pix = Gtk::make_managed<Gtk::Image>(icondir+"export-diag.svg");
	auto exp_pixbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 5);
    exp_pixbox->append(*exp_pix);
    button_export.set_child (*exp_pixbox);
	button_export.set_tooltip_text (_("Export Diagram"));
	button_export.signal_clicked().connect(sigc::ptr_fun(export_diag));
	toolbar.append (button_export);
	button_export.set_sensitive (false);
	//button print
	auto print_pix = Gtk::make_managed<Gtk::Image>(icondir+"print.svg");
	auto print_pixbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 5);
    print_pixbox->append(*print_pix);
    button_print.set_child (*print_pixbox);
	button_print.set_tooltip_text (_("Print report"));
	button_print.signal_clicked().connect(sigc::mem_fun(*print_dialog, &Print_Dialog::prepare_printreport));
	toolbar.append (button_print);
	button_print.set_sensitive (false);
	//button mess
	auto mess_pix = Gtk::make_managed<Gtk::Image>(icondir+"mess-new.svg");
	auto mess_pixbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 5);
    mess_pixbox->append(*mess_pix);
    button_mess.set_child (*mess_pixbox);
	button_mess.set_tooltip_text (_("New measurement"));
	button_mess.signal_clicked().connect(sigc::ptr_fun(begin_mess));
	toolbar.append (button_mess);
	//button start
	auto start_pix = Gtk::make_managed<Gtk::Image>(icondir+"mess-start.svg");
	auto start_pixbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 5);
    start_pixbox->append(*start_pix);
    button_start.set_child (*start_pixbox);
	button_start.set_tooltip_text (_("Start measurement"));
	button_start.signal_clicked().connect(sigc::ptr_fun(start_mess));
	toolbar.append (button_start);
	button_start.set_visible (false);
	//button timer
	auto timer_pix = Gtk::make_managed<Gtk::Image>(icondir+"mess-timer.svg");
	auto timer_pixbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 5);
    timer_pixbox->append(*timer_pix);
    button_timer.set_child (*timer_pixbox);
	button_timer.set_tooltip_text (_("Start timer"));
	button_timer.signal_clicked().connect(sigc::mem_fun(*timer_dialog, &TimerDialog::start_mess_with_timer));
	toolbar.append (button_timer);
	button_timer.set_visible (false);
	//button cancel
	auto cancel_pix = Gtk::make_managed<Gtk::Image>(icondir+"mess-cancel.svg");
	auto cancel_pixbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 5);
    cancel_pixbox->append(*cancel_pix);
    button_cancel.set_child (*cancel_pixbox);
	button_cancel.set_tooltip_text (_("Cancel measurement"));
	button_cancel.signal_clicked().connect(sigc::ptr_fun(cancel_mess));
	toolbar.append (button_cancel);
	button_cancel.set_visible (false);
	//button stop
	auto stop_pix = Gtk::make_managed<Gtk::Image>(icondir+"mess-stop.svg");
	auto stop_pixbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 5);
    stop_pixbox->append(*stop_pix);
    button_stop.set_child (*stop_pixbox);
	button_stop.set_tooltip_text (_("Stop measurement"));
	button_stop.signal_clicked().connect(sigc::ptr_fun(stop_mess));
	toolbar.append (button_stop);
	button_stop.set_visible (false);
	//button reset
	auto end_pix = Gtk::make_managed<Gtk::Image>(icondir+"mess-end.svg");
	auto end_pixbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 5);
    end_pixbox->append(*end_pix);
    button_reset.set_child (*end_pixbox);
	button_reset.set_tooltip_text (_("Delete diagram and end measurement"));
	button_reset.signal_clicked().connect(sigc::ptr_fun(end_mess));
	toolbar.append (button_reset);
	button_reset.set_visible (false);
	//button reset_scale
	auto reset_scale_pix = Gtk::make_managed<Gtk::Image>(icondir+"reset-zoom.svg");
	auto reset_scale_pixbox = Gtk::make_managed<Gtk::Box>(Gtk::Orientation::HORIZONTAL, 5);
    reset_scale_pixbox->append(*reset_scale_pix);
    button_reset_scale.set_child (*reset_scale_pixbox);
	button_reset_scale.set_tooltip_text (_("Reset scale"));
	button_reset_scale.signal_clicked().connect(sigc::mem_fun(diag, &Diagramm::reset_diagscale));
	toolbar.append (button_reset_scale);
	button_reset_scale.set_visible (false);
	//start timer
	count_down_start.set_text (_("Starting measurement . . ."));
	toolbar.append (count_down_start);
	count_down_start.set_visible (false);
	count_down_progress.set_valign (Gtk::Align::CENTER);
	count_down_progress.set_margin_start (10);
	toolbar.append (count_down_progress);
	count_down_progress.set_visible (false);
	//display values
	frame_x.set_margin_start (10);
	frame_x.set_margin_end (10);
	frame_x.set_obey_child (true);
	toolbar.append (frame_x);
	frame_x.set_visible (false);
	frame_x.set_child (display_x);
	display_x.set_text ("X = ");
	frame_y.set_margin_start (10);
	frame_y.set_margin_end (10);
	frame_y.set_obey_child (true);
	toolbar.append (frame_y);
	frame_y.set_child (display_y);
	display_y.set_text ("Y = ");
	frame_y.set_visible (false);
	status_info.set_text ("");
	status_info.set_hexpand (true);
	status_info.set_xalign (0.95);
	status_info.set_visible (true);
	toolbar.append (status_info);
	toolbar.set_vexpand (false);
	main_box.append (toolbar);
	set_show_menubar (true);

	//add diagram in a frame
	Gtk::Frame diagframe;
	diagframe.set_expand (true);
	main_box.append (diagframe);
	diagframe.set_child (diag);


}

void Main_Window::toggle_display ()
{
	show_display = !show_display;
	display_toggle->change_state (show_display);
	return;
}

void Main_Window::set_autoload ()
{
	autoload = !autoload;
	toggle_autoload->change_state (autoload);
	return;
}

void Main_Window::set_autosave ()
{
	autosave = !autosave;
	toggle_autosave->change_state (autosave);
	return;
}

Main_Window::~Main_Window ()
{
}


void Main_Window::help ()
{
	std::string lcode;
	std::string doc_dir, doc, error_str;
	Glib::RefPtr<Gtk::FileLauncher> browser;

	//locate the help files
	doc_dir = "/usr/share/doc/galvani/";
	lcode = std::locale("").name();
	lcode = lcode.substr(0,2);
	doc_dir += lcode;
	doc += doc_dir + "/index.html";
	if (!fs::exists(doc))
	{
		error_str = _("Documentation ");
		error_str += doc + _(" not found");
		error_msg(error_str);
	}
	else
	{
		docfile = Gio::File::create_for_path(doc);
		cancel = Gio::Cancellable::create();
		browser = Gtk::FileLauncher::create ();
        browser->set_file (docfile);
		browser->launch (help_browser, slot, cancel);
	}

	return;
}

void Main_Window::about ()
{
	std::string version;
	std::vector<Glib::ustring> authors;
	Gtk::License license = Gtk::License::GPL_3_0;

	about_dialog = new Gtk::AboutDialog;
	about_dialog->set_default_size (400, 260);
	about_dialog->set_program_name ("Galvani");
	version = "Version: ";
	version += VERSION;
	about_dialog->set_version (version);
	authors.push_back("Burkard Lutz b.lutz@online.de");
	about_dialog->set_authors (authors);
	about_dialog->set_website ("https://gitlab.com/galvn/galvani");
	about_dialog->set_website_label (_("Galvani on gitlab.com"));
	about_dialog->set_comments (_("Data logging from digital Devices, Evaluation and Simulation of Measurement data"));
	about_dialog->set_logo_icon_name ("galvani");
	about_dialog->set_license_type (license);
	about_dialog->set_modal (true);
	about_dialog->set_transient_for(*this);
  	about_dialog->set_hide_on_close(true);
	about_dialog->set_visible (true);
}

void Main_Window::info (std::string msg)
{
    status_info.set_text (msg);
    status_info.set_visible (true);
    return;
}

MsgDialog::MsgDialog ()
{
    set_modal (true);
    set_hide_on_close (true);
    set_title (""); //no title
    content = get_content_area ();
    message.set_margin_top (10);
    message.set_margin_bottom (10);
    message.set_margin_start (10);
    message.set_margin_end (10);
    content->append (message);
    add_button (_("OK"), Gtk::ResponseType::OK);
	add_button (_("Cancel"), Gtk::ResponseType::CANCEL);
	set_default_response (Gtk::ResponseType::OK);
	resp_loop = Glib::MainLoop::create (false);     // create loop to pause program until signal response is received
    signal_response().connect(sigc::bind(sigc::mem_fun(*this, &MsgDialog::get_response)));
}

MsgDialog::~MsgDialog ()
{
}

void MsgDialog::show_msg (std::string msg)
{
    message.set_text (msg);
    set_visible (true);
    resp_loop-> run (); //start loop
    return;
}


void MsgDialog::get_response (int response_id)
{
	switch(response_id)
  	{
  	  case(Gtk::ResponseType::OK):
  	  dlg_ok = true;
  	  break;
  	  case(Gtk::ResponseType::CANCEL):
  	  dlg_ok = false;
  	  break;
    }
    resp_loop-> quit();     //stop loop dlg_ok has response
	close();
	return;
}

bool MsgDialog::dialog_ok (std::string msg)
{
    show_msg(msg);
    return dlg_ok;
}

ProjectDialog::ProjectDialog ()
{
	//title
	set_title (_("Project Settings"));
	set_modal (true);
	set_hide_on_close (true);
	set_default_size (600, 400);
	content = get_content_area ();
	auto titlebox = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	titlebox.set_margin_top (10);
	content->append (titlebox);
	title.set_text (_("Project Title:"));
	titlebox.append (title);
	project_title.set_margin_start (10);
	project_title.set_hexpand (true);
	titlebox.append (project_title);
	titlebox.set_margin_bottom (20);

	//function X-Channel
	auto x_box = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	content->append (x_box);
	x_funkt.set_text (_("Function X-Axis: "));
	x_funkt.set_size_request (150,-1);
	x_funkt.set_halign (Gtk::Align::START);
	x_box.append (x_funkt);
	for (int i=0; i<m_functions.size (); i++) func_x.append (m_functions[i]);
	func_x.set_active_text (m_functions[0]);
	func_x.signal_changed().connect(sigc::mem_fun(*this, &ProjectDialog::show_settings_device_x));
	x_box.append (func_x);
	device_x.set_label (_("device not configured"));
	device_x.set_tooltip_text (_("Device Channel 1 (X). Click to configure."));
	device_x.signal_clicked().connect(sigc::mem_fun(*this, &ProjectDialog::configure_settings_device_x));
	x_box.append (device_x);

	//function Y-Channel
	auto y_box = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	content->append (y_box);
	y_funkt.set_text (_("Function Y-Axis: "));
	y_funkt.set_size_request (150,-1);
	y_funkt.set_halign (Gtk::Align::START);
	y_box.append (y_funkt);
	for (int i=1; i<m_functions.size (); i++) func_y.append (m_functions[i]);
	func_y.set_active_text (m_functions[1]);
	func_y.signal_changed().connect(sigc::mem_fun(*this, &ProjectDialog::show_settings_device_y));
	y_box.append (func_y);
	device_y.set_label (_("device not configured"));
	device_y.set_tooltip_text (_("Device Channel 2 (Y). Click to configure."));
	device_y.signal_clicked().connect(sigc::mem_fun(*this, &ProjectDialog::configure_settings_device_y));
	y_box.append (device_y);

	// titration options
	tit_options = Gtk::Box (Gtk::Orientation::VERTICAL);
	tit_options.set_margin_top (10);
	tit_options.set_hexpand (true);
	content->append (tit_options);
	//acid name
	auto ha_box =  Gtk::Box (Gtk::Orientation::HORIZONTAL);
	tit_options.append (ha_box);
	ha_box.set_margin_start (150);
	ha_box.set_margin_bottom (10);
	ha_name.set_text (_("Titrand (acid): "));
	ha_box.append (ha_name);
	for (int i=0; i<acid.size (); i++) tit_ha.append (acid[i].name);
	tit_ha.set_active_text (acid[0].name);
	ha_box.append (tit_ha);
	auto b_box =  Gtk::Box (Gtk::Orientation::HORIZONTAL);
	tit_options.append (b_box);
	b_box.set_margin_start (150);
	b_box.set_margin_bottom (10);
	b_name.set_text (_("Titrator (base): Sodium hydroxide"));
	b_box.append(b_name);
	// acid concentration
	auto aconc = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	aconc.set_margin_start (150);
	aconc.set_hexpand (true);
	tit_options.append (aconc);
	ha_conc_label.set_text (_("Acid concentration [mol/L]:"));
	ha_conc_label.set_hexpand (true);
	ha_conc_label.set_halign (Gtk::Align::START);
	aconc.append (ha_conc_label);
	tit_haconc.set_digits (1);
	tit_haconc.set_range (0.1, 2.0);
	tit_haconc.set_increments (0.1, 0.5);
	aconc.append (tit_haconc);
	// base concentration
	auto bconc = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	bconc.set_margin_start (150);
	bconc.set_hexpand (true);
	tit_options.append (bconc);
	b_conc_label.set_text (_("Base concentration [mol/L]:"));
	b_conc_label.set_hexpand (true);
	b_conc_label.set_halign (Gtk::Align::START);
	bconc.append (b_conc_label);
	tit_baseconc.set_digits (1);
	tit_baseconc.set_range (0.1, 2.0);
	tit_baseconc.set_increments (0.1, 0.5);
	bconc.append (tit_baseconc);
	// acid volume
	auto havol = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	havol.set_margin_start (150);
	havol.set_hexpand (true);
	tit_options.append (havol);
	havol_label.set_text (_("Volume of acid [mL]:"));
	havol_label.set_hexpand (true);
	havol_label.set_halign (Gtk::Align::START);
	havol.append (havol_label);
	tit_havol.set_digits (0);
	tit_havol.set_range (10, 50);
	tit_havol.set_increments (5, 10);
	havol.append (tit_havol);
	// titration speed
	auto speed = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	speed.set_margin_start (150);
	speed.set_hexpand (true);
	tit_options.append (speed);
	speed_label.set_text (_("Titration velocity [ml/min]:"));
	speed_label.set_hexpand (true);
	speed_label.set_halign (Gtk::Align::START);
	speed.append (speed_label);
	tit_speed.set_digits (0);
	tit_speed.set_range (1, 100);
	tit_speed.set_value (10);
	tit_speed.set_increments (1, 10);
	speed.append (tit_speed);
	tit_options.set_visible (false);
	//Project comment
	comment_label.set_text (_("Comment:"));
	comment_label.set_margin_top (20);
	comment_label.set_halign (Gtk::Align::START);
	content->append (comment_label);
	text_window.set_min_content_height (100);
	text_window.set_policy (Gtk::PolicyType::AUTOMATIC,Gtk::PolicyType::AUTOMATIC);
	text_window.set_has_frame (true);
	projekt_comment_view.set_vexpand (true);
	projekt_comment_view.set_indent (10);

	projekt_comment = Gtk::TextBuffer::create();
	projekt_comment->set_text(project->comment);
	projekt_comment_view.set_buffer (projekt_comment);
	text_window.set_child (projekt_comment_view);
	content->append (text_window);
	//buttons
	add_button (_("OK"), Gtk::ResponseType::ACCEPT);
	add_button (_("Cancel"), Gtk::ResponseType::CANCEL);
	signal_response().connect([this](int responseID){set_project_options (responseID);});
	resp_loop = Glib::MainLoop::create (false);     // create loop to pause program until signal response is received
}

ProjectDialog::~ProjectDialog ()
{
}


MapFunc::MapFunc ()
{
	//title
	set_title (_("Mapping of diagram functions"));
	set_modal (true);
	set_hide_on_close (true);
	set_default_size (600, 300);
	resp_loop = Glib::MainLoop::create (false);     // create loop to pause program until signal response is received
	content = get_content_area ();
	auto titlebox = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	titlebox.set_margin_top (10);
	content->append (titlebox);
	title.set_text (_("Select appropiate function"));
	titlebox.append (title);
	title.set_margin_start (10);
	title.set_hexpand (true);
	titlebox.set_margin_bottom (20);

	//function X-Channel
	auto x_box = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	content->append (x_box);
	x_funkt.set_text (_("Function X-Axis: "));
	x_funkt.set_size_request (150,-1);
	x_funkt.set_halign (Gtk::Align::START);
	x_box.append (x_funkt);
	x_box.append (file_function_x);
	for (int i=0; i<m_functions.size (); i++) function_x.append (m_functions[i]);
	function_x.set_active_text (m_functions[0]);
	x_box.append (function_x);
	//function Y-Channel
	auto y_box = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	content->append (y_box);
	y_funkt.set_text (_("Function Y-Axis: "));
	y_funkt.set_size_request (150,-1);
	y_funkt.set_halign (Gtk::Align::START);
	y_box.append (y_funkt);
	y_box.append (file_function_y);
	for (int i=1; i<m_functions.size (); i++) function_y.append (m_functions[i]);
	function_y.set_active_text (m_functions[1]);
	y_box.append (function_y);

	//buttons
	add_button (_("OK"), Gtk::ResponseType::ACCEPT);
	add_button (_("Cancel"), Gtk::ResponseType::CANCEL);
	signal_response().connect([this](int responseID){translate_fkt (responseID);});

}

MapFunc::~MapFunc ()
{
}

OptionsDialog::OptionsDialog ()
{
	//title
	set_title (_("Settings"));
	set_modal (true);
	set_hide_on_close (true);
	set_default_size (800, 600);
	resp_loop = Glib::MainLoop::create (false);     // create loop to pause program until signal response is received
	content = get_content_area ();
	content->append (edit_options);
	auto diag_tab = Gtk::Box (Gtk::Orientation::VERTICAL);
	diag_tab.set_margin_start (10);
	auto diag_page = Gtk::Label (_("<b>Diagram</b>"));
	diag_page.set_use_markup (true);
	diag_page.set_xalign (0);
	auto chx_tab = Gtk::Box (Gtk::Orientation::VERTICAL);
	chx_tab.set_margin_start (10);
	auto chx_page = Gtk::Label (_("<b>Channel 1 (X)</b>"));
	chx_page.set_use_markup (true);
	chx_page.set_xalign (0);
	auto chy_tab = Gtk::Box (Gtk::Orientation::VERTICAL);
	chy_tab.set_margin_start (10);
	auto chy_page = Gtk::Label (_("<b>Channel 2 (Y)</b>"));
	chy_page.set_use_markup (true);
	chy_page.set_xalign (0);
	edit_options.append_page (diag_tab, diag_page);
	edit_options.append_page (chx_tab, chx_page);
	edit_options.append_page (chy_tab, chy_page);
	edit_options.set_show_border (true);
	edit_options.set_tab_pos (Gtk::PositionType::LEFT);
	edit_options.set_expand (true);

	///////////File Dialog for loading and saving DMM data//////
	dmm_file_dialog = Gtk::FileDialog::create();
	dmm_filters = Gio::ListStore<Gtk::FileFilter>::create();
	filefilter_dmm = Gtk::FileFilter::create();
	filefilter_dmm->add_pattern("*.dmm");
	dmm_filters->append(filefilter_dmm);
	/////////////////////////////////////

	///////////////// Diagram ////////////////////
	//diagram background color
	auto diag_bg = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	diag_tab.append (diag_bg);
	bg_label.set_text (_("<b>Background</b>"));
	bg_label.set_use_markup (true);
	bg_label.set_xalign (0);
	bg_label.set_size_request (100,-1);
	diag_bg.append (bg_label);
	diag_bkcolor.set_tooltip_text (_("Select background colour"));
	diag_bg.append (diag_bkcolor);
	//diagram axes color
	auto diag_ax = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	diag_tab.append (diag_ax);
	ax_label.set_text (_("<b>Axes</b>"));
	ax_label.set_use_markup (true);
	ax_label.set_size_request (100,-1);
	ax_label.set_xalign (0);
	diag_ax.append (ax_label);
	diag_ax.append (diag_axcolor);
	diag_axcolor.set_tooltip_text (_("Select axes colour"));
	//diagram grid color
	auto diag_grid = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	diag_tab.append (diag_grid);
	grid_label.set_text (_("<b>Grid</b>"));
	grid_label.set_use_markup (true);
	grid_label.set_xalign (0);
	grid_label.set_size_request (100,-1);
	diag_grid.append (grid_label);
	diag_gridsw.set_valign (Gtk::Align::CENTER);
	diag_gridsw.set_tooltip_text (_("Show grid in diagram background"));
	diag_grid.append (diag_gridsw);
	diag_grid.append (diag_gridcolor);
	diag_gridcolor.set_tooltip_text (_("Select grid colour"));
	//diagram values
	auto diag_val = Gtk::Box (Gtk::Orientation::VERTICAL);
	diag_tab.append (diag_val);
	//Symbols
	auto diag_sym = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	diag_val.append (diag_sym);
	val_label.set_text (_("<b>Values</b>"));
	val_label.set_use_markup (true);
	val_label.set_xalign (0);
	val_label.set_size_request (100,-1);
	diag_sym.append (val_label);
	diag_sym.append (diag_symbol);
	diag_sym.set_tooltip_text (_("symbol for data points"));
	diag_symbol.append (_("diamond"));
	diag_symbol.append (_("cross"));
	diag_symbol.append (_("circle"));
	diag_symbol.append (_("square"));
	diag_symbol.append (_("no symbol"));
	diag_symbol.set_active_text (_("no symbol"));
	diag_symbol.set_tooltip_text (_("symbol style"));
	diag_sym.append (diag_symbolstyle);
	diag_symbolstyle.append (_("filled"));
	diag_symbolstyle.append (_("outline"));
	diag_sym.append (diag_symw);
	diag_symw.set_digits (0);
	diag_symw.set_range (5, 50);
	diag_symw.set_value (5);
	diag_symw.set_increments (1, 10);
	diag_symw.set_tooltip_text (_("magnitude of symbols in points"));
	//Line
	auto diag_line = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	diag_val.append (diag_line);
	diag_line.append (diag_graph);
	diag_graph.set_margin_start (100);
	diag_graph.append (_("line"));
	diag_graph.append (_("curve"));
	diag_graph.append (_("no connection"));
	diag_graph.set_tooltip_text (_("connection between data points"));
	diag_symbol.set_active_text (_("line"));
	diag_line.append (diag_linestyle);
	diag_linestyle.append (_("solid"));
	diag_linestyle.append (_("dashed"));
	diag_linestyle.append (_("dotted"));
	diag_linestyle.set_tooltip_text (_("linestyle"));
	diag_linestyle.set_active_text (_("solid"));
	diag_xycolor.set_tooltip_text (_("Select line colour"));
	diag_line.append (diag_xycolor);
	//diagram scaling
	auto diag_scal = Gtk::Box (Gtk::Orientation::VERTICAL);
	diag_tab.append (diag_scal);
	//switch
	auto diag_sw = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	scale_label.set_text (_("<b>Scaling</b>"));
	scale_label.set_size_request (100,-1);
	scale_label.set_use_markup (true);
	scale_label.set_xalign (0);
	diag_sw.append (scale_label);
	sw_auto_label.set_text (_("auto: "));
	diag_sw.append (sw_auto_label);
	diag_sw.append (diag_autoscalesw);
	diag_sw.set_margin_top (10);
	diag_sw.set_margin_bottom (10);
	diag_tab.append (diag_sw);
	// set diag limits manual or auto
	diag_autoscalesw.signal_state_set().connect(sigc::mem_fun(*this, &OptionsDialog::show_diag_manual_limits), false);
	diag_autoscalesw.set_tooltip_text (_("Manual or automatic scaling"));
	auto diag_sw_man = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	sw_man_label.set_text (_("manual: "));
	sw_man_label.set_margin_start (100);
	diag_sw_man.append (sw_man_label);
	diag_tab.append (diag_sw_man);
	//x coordinates
	auto diag_xman = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	diag_xman.append (xmin_label);
	diag_xman.set_margin_top (10);
	diag_xman.set_margin_bottom (10);
	xmin_label.set_text ("xmin: ");
	xmin_label.set_margin_start (100);
	diag_xmin.set_digits (2);
	diag_xmin.set_range (-1000, 1000);
	diag_xmin.set_value (0);
	diag_xmin.set_increments (0.01, 1);
	diag_xman.append (diag_xmin);
	xmax_label.set_text ("xmax: ");
	xmax_label.set_margin_start (20);
	xmax_label.set_margin_end (10);
	diag_xman.append (xmax_label);
	diag_xmax.set_digits (2);
	diag_xmax.set_range (-1000, 1000);
	diag_xmax.set_value (0);
	diag_xmax.set_increments (0.01, 1);
	diag_xman.append (diag_xmax);
	diag_tab.append (diag_xman);
	//y coordinates
	auto diag_yman = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	diag_tab.append (diag_yman);
	ymin_label.set_text ("ymin: ");
	ymin_label.set_margin_start (100);
	diag_yman.append (ymin_label);
	diag_ymin.set_digits (2);
	diag_ymin.set_range (-1000, 1000);
	diag_ymin.set_value (0);
	diag_ymin.set_increments (0.01, 1);
	diag_yman.append (diag_ymin);
	ymax_label.set_text ("ymax: ");
	ymax_label.set_margin_start (20);
	ymax_label.set_margin_end (10);
	diag_yman.append (ymax_label);
	diag_ymax.set_digits (2);
	diag_ymax.set_range (-1000, 1000);
	diag_ymax.set_value (0);
	diag_ymax.set_increments (0.01, 1);
	diag_yman.append (diag_ymax);
	//show zero value
	auto diag_zero = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	diag_zero.append (zero_label);
	zero_label.set_text (_("Show Zero: "));
	zero_label.set_halign (Gtk::Align::START);
	zero_label.set_margin_start (100);
	diag_zerosw.set_tooltip_text (_("Show Zero line"));
	diag_zero.append (diag_zerosw);
	diag_zero.set_margin_top (10);
	diag_tab.append (diag_zero);
	//diagram title
	auto diag_title = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	title_label.set_text (_("<b>Project Title</b>"));
	title_label.set_size_request (100,-1);
	title_label.set_use_markup (true);
	title_label.set_xalign (0);
	diag_title.append (title_label);
	diag_title.append (diag_titlesw);
	diag_titlesw.set_tooltip_text (_("Show Project title as headline in diagram"));
	diag_title.set_margin_top (10);
	diag_tab.append (diag_title);
	//////////////////////////////////////////////////////

	/////////////////// Data Channel 1 (X) //////////////////
	//data source (DMM / Simulation)
	auto xdata_src = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	chx_tab.append (xdata_src);
	src_label.set_text(_("<b>Source</b>"));
	src_label.set_size_request (100,-1);
	src_label.set_use_markup (true);
	src_label.set_xalign (0);
	xdata_src.append (src_label);
	dmm_typ[0].append (_("Time"));
	dmm_typ[0].append (_("Digitalmultimeter"));
	dmm_typ[0].append (_("Simulation"));
	dmm_typ[0].set_active_text (_("Time"));
	dmm_typ[0].set_tooltip_text (_("Data source: device or simulation"));
	dmm_typ[0].set_size_request (250,-1);
	// Recall options if dmm_typ changed
	dmm_typ[0].signal_changed().connect(sigc::mem_fun(*this, &OptionsDialog::restart_options_x));
	xdata_src.append (dmm_typ[0]);
	dmm_simtyp[0].set_tooltip_text (_("Type of simulation"));
	dmm_simtyp[0].append (_("Linear"));
	dmm_simtyp[0].set_active_text (_("Linear"));
	dmm_simtyp[0].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_simulation_options), 0));
	dmm_typ[0].set_tooltip_text (_("Type of simulation"));
	xdata_src.append (dmm_simtyp[0]);

	// dmm options: type, interface, scpi, remote control
	dmm_dmm_options[0] = Gtk::Box (Gtk::Orientation::VERTICAL);
	chx_tab.append (dmm_dmm_options[0]);
	dmm1_type = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm1_label.set_text (_("<b>Type</b>"));
	dmm1_label.set_size_request (100,-1);
	dmm1_label.set_use_markup (true);
	dmm1_label.set_xalign (0);
	dmm1_type.append (dmm1_label);
	dmm_name[0] = Gtk::ComboBoxText (true);
	dmm_name[0].set_size_request (325,-1);
	dmm_name[0].set_hexpand (false);
	dmm_name[0].set_tooltip_text (_("Type of Device"));
	dmm_name[0].append ("");
	dmm_name[0].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::select_dmm), 0));
	dmm1_type.append (dmm_name[0]);
	dmm_loadoptions[0].set_label (_("Load"));
	dmm_loadoptions[0].signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::load_dmm_options), 0));
	dmm1_type.append (dmm_loadoptions[0]);
	dmm_saveoptions[0].set_label (_("Save"));
	dmm_saveoptions[0].signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::save_dmm_options), 0));
	dmm1_type.append (dmm_saveoptions[0]);
	dmm_dmm_options[0].append (dmm1_type);
	dmm1_connect = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	intface_label.set_text (_("<b>Interface</b>"));
	intface_label.set_size_request (100,-1);
	intface_label.set_use_markup (true);
	intface_label.set_xalign (0);
	dmm1_connect.append (intface_label);
	dmm_interface[0].set_size_request (250,-1);
	dmm_interface[0].append ("/dev/ttyS0");
	dmm_interface[0].append ("/dev/ttyS1");
	dmm_interface[0].append ("/dev/ttyS2");
	dmm_interface[0].append ("/dev/ttyS3");
	dmm_interface[0].append ("/dev/ttyS4");
	dmm_interface[0].append ("/dev/ttyUSB0");
	dmm_interface[0].append ("/dev/ttyUSB1");
	dmm_interface[0].append ("/dev/ttyUSB2");
	dmm_interface[0].append ("/dev/ttyUSB3");
	dmm_interface[0].append ("/dev/ttyUSB4");
	dmm_interface[0].set_active_text ("/dev/ttyS0");
	dmm_interface[0].set_tooltip_text (_("List of vailable ports.Connect serial USB-Adaptor first."));
	dmm_interface[0].set_margin_end (20);
	//Show serial options for dmm if RS232C
	dmm_interface[0].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_interface_options), 0));
	dmm1_connect.append (dmm_interface[0]);
	scpi_label.set_text ("<b>SCPI</b>");
	scpi_label.set_use_markup (true);
	scpi_label.set_margin_end (5);
	dmm1_connect.append (scpi_label);
	dmm_scpi[0].set_valign (Gtk::Align::CENTER);
	dmm_scpi[0].set_tooltip_text (_("Send SCPI commands?"));
	dmm1_connect.append (dmm_scpi[0]);
	remote_label.set_text (_("<b>Remote Control</b>"));
	remote_label.set_use_markup (true);
	remote_label.set_margin_start (20);
	remote_label.set_margin_end (5);
	dmm1_connect.append (remote_label);
	dmm_remote_control[0].set_valign (Gtk::Align::CENTER);
	dmm_remote_control[0].set_tooltip_text (_("Remote Setup possible?"));
	// Show/Hide dmm_control_options, if dmm_remote_control changed
	dmm_remote_control[0].signal_state_set().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_control_options), 0), false);
	dmm1_connect.append (dmm_remote_control[0]);
	dmm_dmm_options[0].append (dmm1_connect);

	//device_settings for channel X
	auto device_settings_1  = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	device_settings_1.set_margin_top (20);
	chx_tab.append (device_settings_1);

	// serial options
	dmm_serial_options[0] = Gtk::Box (Gtk::Orientation::VERTICAL);
	dmm_serial_options[0].set_margin_end (20);
	device_settings_1.append (dmm_serial_options[0]);
	auto baud_settings_1 = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[0].append (baud_settings_1);
	baud_label.set_text (_("<b>Baudrate</b>"));
	baud_label.set_size_request (100,-1);
	baud_label.set_use_markup (true);
	baud_label.set_xalign (0);
	baud_settings_1.append (baud_label);
	dmm_baud[0].set_size_request (100,-1);
	dmm_baud[0].append ("600");
	dmm_baud[0].append ("1200");
	dmm_baud[0].append ("1800");
	dmm_baud[0].append ("2400");
	dmm_baud[0].append ("4800");
	dmm_baud[0].append ("9600");
	dmm_baud[0].append ("19200");
	dmm_baud[0].append ("38400");
	dmm_baud[0].append ("57600");
	dmm_baud[0].append ("115200");
	dmm_baud[0].set_active_text ("9600");
	baud_settings_1.append (dmm_baud[0]);
	auto char_settings_1= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[0].append (char_settings_1);
	chrsize_label.set_text (_("<b>Charsize</b>"));
	chrsize_label.set_size_request (100,-1);
	chrsize_label.set_use_markup (true);
	chrsize_label.set_xalign (0);
	char_settings_1.append (chrsize_label);
	dmm_bits[0].set_size_request (100,-1);
	dmm_bits[0].append ("7");
	dmm_bits[0].append ("8");
	dmm_bits[0].set_active_text ("7");
	char_settings_1.append (dmm_bits[0]);
	auto flow_settings_1= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[0].append (flow_settings_1);
	flow_label.set_text (_("<b>Flow control</b>"));
	flow_label.set_size_request (100,-1);
	flow_label.set_use_markup (true);
	flow_label.set_xalign (0);
	flow_settings_1.append (flow_label);
	dmm_flowcontrol[0].set_size_request (100,-1);
	dmm_flowcontrol[0].append (_("hardware"));
	dmm_flowcontrol[0].append (_("software"));
	dmm_flowcontrol[0].append (_("none"));
	dmm_flowcontrol[0].set_active_text (_("none"));
	flow_settings_1.append (dmm_flowcontrol[0]);
	auto stop_settings_1= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[0].append (stop_settings_1);
	stop_label.set_text (_("<b>Stop bits</b>"));
	stop_label.set_size_request (100,-1);
	stop_label.set_use_markup (true);
	stop_label.set_xalign (0);
	stop_settings_1.append (stop_label);
	dmm_stopbits[0].set_size_request (100,-1);
	dmm_stopbits[0].append ("1");
	dmm_stopbits[0].append ("2");
	dmm_stopbits[0].set_active_text ("1");
	stop_settings_1.append (dmm_stopbits[0]);
	auto par_settings_1= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[0].append (par_settings_1);
	par_label.set_text (_("<b>Parity</b>"));
	par_label.set_size_request (100,-1);
	par_label.set_use_markup (true);
	par_label.set_xalign (0);
	par_settings_1.append (par_label);
	dmm_parity[0].set_size_request (100,-1);
	dmm_parity[0].append (_("odd"));
	dmm_parity[0].append (_("even"));
	dmm_parity[0].append (_("none"));
	dmm_parity[0].set_active_text (_("none"));
	par_settings_1.append (dmm_parity[0]);
	auto poll_settings_1= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[0].append (poll_settings_1);
	poll_label.set_text (_("<b>Polling</b>"));
	poll_label.set_size_request (100,-1);
	poll_label.set_use_markup (true);
	poll_label.set_xalign (0);
	poll_settings_1.append (poll_label);
	dmm_polling[0].set_valign (Gtk::Align::CENTER);
	dmm_polling[0].set_tooltip_text(_("Send Character for data polling"));
	poll_settings_1.append (dmm_polling[0]);
	auto nbyte_settings_1= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[0].append (nbyte_settings_1);
	nbyte_label.set_text (_("<b>Bytes</b>"));
	nbyte_label.set_size_request (100,-1);
	nbyte_label.set_use_markup (true);
	nbyte_label.set_xalign (0);
	nbyte_settings_1.append (nbyte_label);
	dmm_num_bytes[0].set_size_request (100,-1);
	dmm_num_bytes[0].set_digits (0);
	dmm_num_bytes[0].set_range (0, 15);
	dmm_num_bytes[0].set_value (0);
	dmm_num_bytes[0].set_increments (1, 10);
	dmm_num_bytes[0].set_tooltip_text(_("Number of transmitted bytes"));
	nbyte_settings_1.append (dmm_num_bytes[0]);
	auto nval_settings_1= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[0].append (nval_settings_1);
	nval_label.set_text (_("<b>Values</b>"));
	nval_label.set_size_request (100,-1);
	nval_label.set_use_markup (true);
	nval_label.set_xalign (0);
	nval_settings_1.append (nval_label);
	dmm_num_val[0].set_size_request (100,-1);
	dmm_num_val[0].set_digits (0);
	dmm_num_val[0].set_range (1, 4);
	dmm_num_val[0].set_value (1);
	dmm_num_val[0].set_increments (1, 1);
	dmm_num_val[0].set_tooltip_text(_("Number of transmitted data values"));
	nval_settings_1.append (dmm_num_val[0]);
	auto timeout_settings_1= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[0].append (timeout_settings_1);
	timeout_label.set_text (_("<b>Timeout</b>"));
	timeout_label.set_size_request (100,-1);
	timeout_label.set_use_markup (true);
	timeout_label.set_xalign (0);
	timeout_settings_1.append (timeout_label);
	dmm_timeout[0].set_size_request (100,-1);
	dmm_timeout[0].set_digits (0);
	dmm_timeout[0].set_range (0, 10000);
	dmm_timeout[0].set_value (1000);
	dmm_timeout[0].set_increments (1, 100);
	dmm_timeout[0].set_tooltip_text(_("Timeout in milliseconds"));
	dmm_timeout[0].signal_changed().connect(sigc::mem_fun(*this, &OptionsDialog::preset_mtime));
	timeout_settings_1.append (dmm_timeout[0]);

	//USB options
	dmm_usb_options[0] = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	chx_tab.append (dmm_usb_options[0]);
	ubyte_label.set_text (_("<b>Bytes (USB)</b>"));
	ubyte_label.set_size_request (100,-1);
	ubyte_label.set_use_markup (true);
	ubyte_label.set_xalign (0);
	dmm_usb_options[0].append (ubyte_label);
	dmm_usb_bytes[0].set_size_request (100,-1);
	dmm_usb_bytes[0].set_digits (0);
	dmm_usb_bytes[0].set_range (0, 64);
	dmm_usb_bytes[0].set_value (0);
	dmm_usb_bytes[0].set_increments (1, 10);
	dmm_usb_bytes[0].set_tooltip_text(_("Number of transmitted bytes"));
	dmm_usb_options[0].append (dmm_usb_bytes[0]);


	// function options
	auto dmm1_function_options = Gtk::Box (Gtk::Orientation::VERTICAL);
	dmm1_function_options.set_margin_start (50);
	device_settings_1.append (dmm1_function_options);
	dmm_function_control[0] = Gtk::Box (Gtk::Orientation::VERTICAL);
	dmm1_function_options.append (dmm_function_control[0]);
	auto dmm1_funkt = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm1_funkt_label.set_text (_("<b>Function</b>"));
	dmm1_funkt_label.set_size_request (120,-1);
	dmm1_funkt_label.set_use_markup (true);
	dmm1_funkt_label.set_xalign (0);
	dmm1_funkt.append (dmm1_funkt_label);
	for (int i=1; i<m_functions.size (); i++) dmm_funktion[0].append (m_functions[i]);
	dmm_funktion[0].set_active_text (m_functions[1]);
	dmm1_funkt.append (dmm_funktion[0]);
	dmm_funktion[0].set_tooltip_text (_("Measurement function"));
	// Change range options, if function changed
	dmm_funktion[0].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::set_range_options_device), 0));
	dmm_function_control[0].append (dmm1_funkt);
	auto dmm1_range = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm1_range_label.set_text (_("<b>Range</b>"));
	dmm1_range_label.set_size_request (150,-1);
	dmm1_range_label.set_use_markup (true);
	dmm1_range_label.set_xalign (0);
	dmm1_range.append (dmm1_range_label);
	dmm_range[0].append ("200 mV");
	dmm_range[0].append("2 V");
	dmm_range[0].append("20 V");
	dmm_range[0].append("200 V");
	dmm_range[0].append("1000 V");
	dmm_range[0].set_active_text ("200 mV");
	dmm1_range.append (dmm_range[0]);
	dmm_range[0].set_tooltip_text (_("Measurement function"));
	dmm_function_control[0].append (dmm1_range);

	// function control strings
	dmm_control_options[0] = Gtk::Box (Gtk::Orientation::VERTICAL);
	dmm1_function_options.append (dmm_control_options[0]);
	auto dmm1_DCV = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm1_DCV_label.set_text (_("<b>DC Voltage</b>"));
	dmm1_DCV_label.set_size_request (150,-1);
	dmm1_DCV_label.set_use_markup (true);
	dmm1_DCV_label.set_xalign (0);
	dmm1_DCV.append (dmm1_DCV_label);
	dmm_DCV[0] = Gtk::ComboBoxText (true);
	dmm_DCV[0].set_hexpand (false);
	dmm_DCV[0].append ("");
	dmm_DCV[0].set_active_text ("");
	dmm_DCV[0].set_tooltip_text(_("Control String"));
	dmm1_DCV.append (dmm_DCV[0]);
	dmm_DCV[0].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 0));
	dmm_control_options[0].append (dmm1_DCV);
	auto dmm1_ACV = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm1_ACV_label.set_text (_("<b>AC Voltage</b>"));
	dmm1_ACV_label.set_size_request (150,-1);
	dmm1_ACV_label.set_use_markup (true);
	dmm1_ACV_label.set_xalign (0);
	dmm1_ACV.append (dmm1_ACV_label);
	dmm_ACV[0] = Gtk::ComboBoxText (true);
	dmm_ACV[0].set_hexpand (false);
	dmm_ACV[0].append ("");
	dmm_ACV[0].set_active_text ("");
	dmm_ACV[0].set_tooltip_text(_("Control String"));
	dmm1_ACV.append (dmm_ACV[0]);
	dmm_ACV[0].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 0));
	dmm_control_options[0].append (dmm1_ACV);
	auto dmm1_DCmA = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm1_DCmA_label.set_text (_("<b>DC Current (mA)</b>"));
	dmm1_DCmA_label.set_size_request (150,-1);
	dmm1_DCmA_label.set_use_markup (true);
	dmm1_DCmA_label.set_xalign (0);
	dmm1_DCmA.append (dmm1_DCmA_label);
	dmm_DCmA[0] = Gtk::ComboBoxText (true);
	dmm_DCmA[0].set_hexpand (false);
	dmm_DCmA[0].append ("");
	dmm_DCmA[0].set_active_text ("");
	dmm_DCmA[0].set_tooltip_text(_("Control String"));
	dmm1_DCmA.append (dmm_DCmA[0]);
	dmm_DCmA[0].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 0));
	dmm_control_options[0].append (dmm1_DCmA);
	auto dmm1_ACmA = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm1_ACmA_label.set_text (_("<b>AC Current (mA)</b>"));
	dmm1_ACmA_label.set_size_request (150,-1);
	dmm1_ACmA_label.set_use_markup (true);
	dmm1_ACmA_label.set_xalign (0);
	dmm1_ACmA.append (dmm1_ACmA_label);
	dmm_ACmA[0] = Gtk::ComboBoxText (true);
	dmm_ACmA[0].set_hexpand (false);
	dmm_ACmA[0].append ("");
	dmm_ACmA[0].set_active_text ("");
	dmm_ACmA[0].set_tooltip_text(_("Control String"));
	dmm1_ACmA.append (dmm_ACmA[0]);
	dmm_ACmA[0].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 0));
	dmm_control_options[0].append (dmm1_ACmA);
	auto dmm1_DCA = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm1_DCA_label.set_text (_("<b>DC Current (A)</b>"));
	dmm1_DCA_label.set_size_request (150,-1);
	dmm1_DCA_label.set_use_markup (true);
	dmm1_DCA_label.set_xalign (0);
	dmm1_DCA.append (dmm1_DCA_label);
	dmm_DCA[0] = Gtk::ComboBoxText (true);
	dmm_DCA[0].set_hexpand (false);
	dmm_DCA[0].append ("");
	dmm_DCA[0].set_active_text ("");
	dmm_DCA[0].set_tooltip_text(_("Control String"));
	dmm1_DCA.append (dmm_DCA[0]);
	dmm_DCA[0].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 0));
	dmm_control_options[0].append (dmm1_DCA);
	auto dmm1_ACA = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm1_ACA_label.set_text (_("<b>AC Current (A)</b>"));
	dmm1_ACA_label.set_size_request (150,-1);
	dmm1_ACA_label.set_use_markup (true);
	dmm1_ACA_label.set_xalign (0);
	dmm1_ACA.append (dmm1_ACA_label);
	dmm_ACA[0] = Gtk::ComboBoxText (true);
	dmm_ACA[0].set_hexpand (false);
	dmm_ACA[0].append ("");
	dmm_ACA[0].set_active_text ("");
	dmm_ACA[0].set_tooltip_text(_("Control String"));
	dmm1_ACA.append (dmm_ACA[0]);
	dmm_ACA[0].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 0));
	dmm_control_options[0].append (dmm1_ACA);
	auto dmm1_res = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm1_res_label.set_text (_("<b>Resistance</b>"));
	dmm1_res_label.set_size_request (150,-1);
	dmm1_res_label.set_use_markup (true);
	dmm1_res_label.set_xalign (0);
	dmm1_res.append (dmm1_res_label);
	dmm_Res[0] = Gtk::ComboBoxText (true);
	dmm_Res[0].set_hexpand (false);
	dmm_Res[0].append ("");
	dmm_Res[0].set_active_text ("");
	dmm_Res[0].set_tooltip_text(_("Control String"));
	dmm1_res.append (dmm_Res[0]);
	dmm_Res[0].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 0));
	dmm_control_options[0].append (dmm1_res);
	auto dmm1_cond = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm1_cond_label.set_text (_("<b>Conductivity</b>"));
	dmm1_cond_label.set_size_request (150,-1);
	dmm1_cond_label.set_use_markup (true);
	dmm1_cond_label.set_xalign (0);
	dmm1_cond.append (dmm1_cond_label);
	dmm_Cond[0] = Gtk::ComboBoxText (true);
	dmm_Cond[0].set_hexpand (false);
	dmm_Cond[0].append ("");
	dmm_Cond[0].set_active_text ("");
	dmm_Cond[0].set_tooltip_text(_("Control String"));
	dmm1_cond.append (dmm_Cond[0]);
	dmm_Cond[0].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 0));
	dmm_control_options[0].append (dmm1_cond);
	auto dmm1_pH = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm1_ph_label.set_text ("<b>pH</b>");
	dmm1_ph_label.set_size_request (150,-1);
	dmm1_ph_label.set_use_markup (true);
	dmm1_ph_label.set_xalign (0);
	dmm1_pH.append (dmm1_ph_label);
	dmm_pH[0] = Gtk::ComboBoxText (true);
	dmm_pH[0].set_hexpand (false);
	dmm_pH[0].append ("");
	dmm_pH[0].set_active_text ("");
	dmm_pH[0].set_tooltip_text(_("Control String"));
	dmm1_pH.append (dmm_pH[0]);
	dmm_pH[0].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 0));
	dmm_control_options[0].append (dmm1_pH);
	auto dmm1_temp = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm1_temp_label.set_text (_("<b>Temperature</b>"));
	dmm1_temp_label.set_size_request (150,-1);
	dmm1_temp_label.set_use_markup (true);
	dmm1_temp_label.set_xalign (0);
	dmm1_temp.append (dmm1_temp_label);
	dmm_Temp[0] = Gtk::ComboBoxText (true);
	dmm_Temp[0].set_hexpand (false);
	dmm_Temp[0].append ("");
	dmm_Temp[0].set_active_text ("");
	dmm_Temp[0].set_tooltip_text(_("Control String"));
	dmm1_temp.append (dmm_Temp[0]);
	dmm_Temp[0].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 0));
	dmm_control_options[0].append (dmm1_temp);
	///////////////////////////////////////////////////////////////

	////////// Simulation Parameter//////////////
	sim_linoptions[0]  = Gtk::Box (Gtk::Orientation::VERTICAL);
	chx_tab.append (sim_linoptions[0]);
	auto dmm1_slope = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm1_slope_label.set_text (_("<b>Slope</b>"));
	dmm1_slope_label.set_size_request (100,-1);
	dmm1_slope_label.set_use_markup (true);
	dmm1_slope_label.set_xalign (0);
	dmm1_slope.append (dmm1_slope_label);
	dmm1_autoslope.set_text ("auto: ");
	dmm1_slope.append (dmm1_autoslope);
	sim_slope_switch[0].set_valign (Gtk::Align::CENTER);
	dmm1_slope.append (sim_slope_switch[0]);
	sim_slope_switch[0].set_tooltip_text(_("Select slope. Auto for random slope."));
	sim_slope_switch[0].signal_state_set().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_simlin_options), 0), false);
	sim_slope[0].set_size_request (100,-1);
	sim_slope[0].set_digits (2);
	sim_slope[0].set_range (-1.0, 1.0);
	sim_slope[0].set_value (0.0);
	sim_slope[0].set_increments (0.01, 0.1);
	sim_slope[0].set_margin_start (10);
	dmm1_slope.append (sim_slope[0]);
	sim_linoptions[0].append (dmm1_slope);
	auto dmm1_shift = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm1_shift_label.set_text (_("<b>Deviation</b>"));
	dmm1_shift_label.set_size_request (100,-1);
	dmm1_shift_label.set_use_markup (true);
	dmm1_shift_label.set_xalign (0);
	dmm1_shift.append (dmm1_shift_label);
	dmm1_autoshift.set_text ("auto: ");
	dmm1_shift.append (dmm1_autoshift);
	sim_shift_switch[0].set_valign (Gtk::Align::CENTER);
	dmm1_shift.append (sim_shift_switch[0]);
	sim_shift_switch[0].set_tooltip_text(_("Select uncertainty of value. Effective deviation is randomized."));
	sim_shift_switch[0].signal_state_set().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_simlin_options), 0), false);
	sim_shift[0].set_size_request (100,-1);
	sim_shift[0].set_digits (2);
	sim_shift[0].set_range (0.1, 10);
	sim_shift[0].set_value (0.0);
	sim_shift[0].set_increments (0.1, 1);
	sim_shift[0].set_margin_start (10);
	dmm1_shift.append (sim_shift[0]);
	Gtk::Label shift_dim2;
	shift_dim2.set_text ("%");
	shift_dim2.set_margin_start (5);
	dmm1_shift.append (shift_dim2);
	sim_linoptions[0].append (dmm1_shift);


	/////////////////// Data Channel 2 (Y) //////////////////
	//data source (DMM / Simulation)
	auto ydata_src = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	chy_tab.append (ydata_src);
	src2_label.set_text(_("<b>Source</b>"));
	src2_label.set_size_request (100,-1);
	src2_label.set_use_markup (true);
	src2_label.set_xalign (0);
	ydata_src.append (src2_label);
	dmm_typ[1].append (_("Device"));
	dmm_typ[1].append (_("Digitalmultimeter"));
	dmm_typ[1].append (_("Simulation"));
	dmm_typ[1].set_active_text (_("Simulation"));
	dmm_typ[1].set_tooltip_text (_("Data source: device or simulation"));
	dmm_typ[1].set_size_request (250,-1);
	// Recall options if dmm_typ changed
	dmm_typ[1].signal_changed().connect(sigc::mem_fun(*this, &OptionsDialog::restart_options_y));
	ydata_src.append (dmm_typ[1]);
	dmm_simtyp[1].set_tooltip_text (_("Type of simulation"));
	dmm_simtyp[1].append (_("Linear"));
	dmm_simtyp[1].append (_("Exponential"));
	dmm_simtyp[1].append (_("Chromatogram"));
	dmm_simtyp[1].append (_("pH"));
	dmm_simtyp[1].set_active_text (_("Linear"));
	dmm_simtyp[1].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_simulation_options), 1));
	dmm_typ[1].set_tooltip_text (_("Type of simulation"));
	ydata_src.append (dmm_simtyp[1]);

	// dmm options: type, interface, scpi, remote control
	dmm_dmm_options[1] = Gtk::Box (Gtk::Orientation::VERTICAL);
	chy_tab.append (dmm_dmm_options[1]);
	dmm2_type = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm2_label.set_text (_("<b>Type</b>"));
	dmm2_label.set_size_request (100,-1);
	dmm2_label.set_use_markup (true);
	dmm2_label.set_xalign (0);
	dmm2_type.append (dmm2_label);
	dmm_name[1] = Gtk::ComboBoxText (true);
	dmm_name[1].set_size_request (325,-1);
	dmm_name[1].set_hexpand (false);
	dmm_name[1].set_tooltip_text (_("Type of Device"));
	dmm_name[1].append ("");
	dmm_name[1].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::select_dmm), 1));
	dmm2_type.append (dmm_name[1]);
	dmm_loadoptions[1].set_label (_("Load"));
	dmm_loadoptions[1].signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::load_dmm_options), 1));
	dmm2_type.append (dmm_loadoptions[1]);
	dmm_saveoptions[1].set_label (_("Save"));
	dmm_saveoptions[1].signal_clicked().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::save_dmm_options), 1));
	dmm2_type.append (dmm_saveoptions[1]);
	dmm_dmm_options[1].append (dmm2_type);
	dmm2_connect = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	intface2_label.set_text (_("<b>Interface</b>"));
	intface2_label.set_size_request (100,-1);
	intface2_label.set_use_markup (true);
	intface2_label.set_xalign (0);
	dmm2_connect.append (intface2_label);
	dmm_interface[1].set_size_request (250,-1);
	dmm_interface[1].append ("/dev/ttyS0");
	dmm_interface[1].append ("/dev/ttyS1");
	dmm_interface[1].append ("/dev/ttyS2");
	dmm_interface[1].append ("/dev/ttyS3");
	dmm_interface[1].append ("/dev/ttyS4");
	dmm_interface[1].append ("/dev/ttyUSB0");
	dmm_interface[1].append ("/dev/ttyUSB1");
	dmm_interface[1].append ("/dev/ttyUSB2");
	dmm_interface[1].append ("/dev/ttyUSB3");
	dmm_interface[1].append ("/dev/ttyUSB4");
	dmm_interface[1].set_active_text ("/dev/ttyS0");
	dmm_interface[1].set_tooltip_text (_("List of vailable ports.Connect serial USB-Adaptor first."));
	dmm_interface[1].set_margin_end (20);
	//Show serial options for dmm if RS232C
	dmm_interface[1].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_interface_options), 1));
	dmm2_connect.append (dmm_interface[1]);
	scpi2_label.set_text ("<b>SCPI</b>");
	scpi2_label.set_use_markup (true);
	scpi2_label.set_margin_end (5);
	dmm2_connect.append (scpi2_label);
	dmm_scpi[1].set_valign (Gtk::Align::CENTER);
	dmm_scpi[1].set_tooltip_text (_("Send SCPI commands?"));
	dmm2_connect.append (dmm_scpi[1]);
	remote2_label.set_text (_("<b>Remote Control</b>"));
	remote2_label.set_use_markup (true);
	remote2_label.set_margin_start (20);
	remote2_label.set_margin_end (5);
	dmm2_connect.append (remote2_label);
	dmm_remote_control[1].set_valign (Gtk::Align::CENTER);
	dmm_remote_control[1].set_tooltip_text (_("Remote Setup possible?"));
	// Show/Hide dmm_control_options, if dmm_remote_control changed
	dmm_remote_control[1].signal_state_set().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_control_options), 1), false);
	dmm2_connect.append (dmm_remote_control[1]);
	dmm_dmm_options[1].append (dmm2_connect);

	// device options: type, interface
	dmm_device_options = Gtk::Box (Gtk::Orientation::VERTICAL);
	chy_tab.append (dmm_device_options);
	device_type = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	device_label.set_text (_("<b>Type</b>"));
	device_label.set_size_request (100,-1);
	device_label.set_use_markup (true);
	device_label.set_xalign (0);
	device_type.append (device_label);
	device_name = Gtk::ComboBoxText (true);
	device_name.set_size_request (325,-1);
	device_name.set_hexpand (false);
	device_name.set_tooltip_text (_("Type of Device"));
	device_name.append ("");
	device_name.append("Lutron PH-207");
	device_type.append (device_name);
	dmm_device_options.append (device_type);
	dev_connect = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dev_intface_label.set_text (_("<b>Interface</b>"));
	dev_intface_label.set_size_request (100,-1);
	dev_intface_label.set_use_markup (true);
	dev_intface_label.set_xalign (0);
	dev_connect.append (dev_intface_label);
	dev_interface.set_size_request (250,-1);
	dev_interface.append ("/dev/ttyS0");
	dev_interface.append ("/dev/ttyS1");
	dev_interface.append ("/dev/ttyS2");
	dev_interface.append ("/dev/ttyS3");
	dev_interface.append ("/dev/ttyS4");
	dev_interface.append ("/dev/ttyUSB0");
	dev_interface.append ("/dev/ttyUSB1");
	dev_interface.append ("/dev/ttyUSB2");
	dev_interface.append ("/dev/ttyUSB3");
	dev_interface.append ("/dev/ttyUSB4");
	dev_interface.set_active_text ("/dev/ttyS0");
	dev_interface.set_tooltip_text (_("List of vailable ports.Connect serial USB-Adaptor first."));
	dev_interface.set_margin_end (20);
	dev_connect.append (dev_interface);
	dmm_device_options.append (dev_connect);

	//measuring time interval
	dev_time = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	chy_tab.append (dev_time);
	dev_mlabel.set_text (_("<b>Time Interval</b>"));
	dev_mlabel.set_size_request (100,-1);
	dev_mlabel.set_use_markup (true);
	dev_mlabel.set_xalign (0);
	dev_time.append (dev_mlabel);
	dmm_mtime.set_digits (3);
	dmm_mtime.set_range (0.01, 3600);
	dmm_mtime.set_value (1.0);
	dmm_mtime.set_increments (0.001, 1);
	dmm_mtime.set_tooltip_text(_("Time Interval in seconds"));
	dev_time.append (dmm_mtime);


	//device_settings for channel Y
	auto device_settings_2  = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	device_settings_2.set_margin_top (20);
	chy_tab.append (device_settings_2);

	// serial options
	dmm_serial_options[1] = Gtk::Box (Gtk::Orientation::VERTICAL);
	dmm_serial_options[1].set_margin_end (20);
	device_settings_2.append (dmm_serial_options[1]);
	auto baud_settings_2 = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[1].append (baud_settings_2);
	baud2_label.set_text (_("<b>Baudrate</b>"));
	baud2_label.set_size_request (100,-1);
	baud2_label.set_use_markup (true);
	baud2_label.set_xalign (0);
	baud_settings_2.append (baud2_label);
	dmm_baud[1].set_size_request (100,-1);
	dmm_baud[1].append ("600");
	dmm_baud[1].append ("1200");
	dmm_baud[1].append ("1800");
	dmm_baud[1].append ("2400");
	dmm_baud[1].append ("4800");
	dmm_baud[1].append ("9600");
	dmm_baud[1].append ("19200");
	dmm_baud[1].append ("38400");
	dmm_baud[1].append ("57600");
	dmm_baud[1].append ("115200");
	dmm_baud[1].set_active_text ("9600");
	baud_settings_2.append (dmm_baud[1]);
	auto char_settings_2= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[1].append (char_settings_2);
	chrsize2_label.set_text (_("<b>Charsize</b>"));
	chrsize2_label.set_size_request (100,-1);
	chrsize2_label.set_use_markup (true);
	chrsize2_label.set_xalign (0);
	char_settings_2.append (chrsize2_label);
	dmm_bits[1].set_size_request (100,-1);
	dmm_bits[1].append ("7");
	dmm_bits[1].append ("8");
	dmm_bits[1].set_active_text ("7");
	char_settings_2.append (dmm_bits[1]);
	auto flow_settings_2= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[1].append (flow_settings_2);
	flow2_label.set_text (_("<b>Flow control</b>"));
	flow2_label.set_size_request (100,-1);
	flow2_label.set_use_markup (true);
	flow2_label.set_xalign (0);
	flow_settings_2.append (flow2_label);
	dmm_flowcontrol[1].set_size_request (100,-1);
	dmm_flowcontrol[1].append (_("hardware"));
	dmm_flowcontrol[1].append (_("software"));
	dmm_flowcontrol[1].append (_("none"));
	dmm_flowcontrol[1].set_active_text (_("none"));
	flow_settings_2.append (dmm_flowcontrol[1]);
	auto stop_settings_2= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[1].append (stop_settings_2);
	stop2_label.set_text (_("<b>Stop bits</b>"));
	stop2_label.set_size_request (100,-1);
	stop2_label.set_use_markup (true);
	stop2_label.set_xalign (0);
	stop_settings_2.append (stop2_label);
	dmm_stopbits[1].set_size_request (100,-1);
	dmm_stopbits[1].append ("1");
	dmm_stopbits[1].append ("2");
	dmm_stopbits[1].set_active_text ("1");
	stop_settings_2.append (dmm_stopbits[1]);
	auto par_settings_2= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[1].append (par_settings_2);
	par2_label.set_text (_("<b>Parity</b>"));
	par2_label.set_size_request (100,-1);
	par2_label.set_use_markup (true);
	par2_label.set_xalign (0);
	par_settings_2.append (par2_label);
	dmm_parity[1].set_size_request (100,-1);
	dmm_parity[1].append (_("odd"));
	dmm_parity[1].append (_("even"));
	dmm_parity[1].append (_("none"));
	dmm_parity[1].set_active_text (_("none"));
	par_settings_2.append (dmm_parity[1]);
	auto poll_settings_2= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[1].append (poll_settings_2);
	poll2_label.set_text (_("<b>Polling</b>"));
	poll2_label.set_size_request (100,-1);
	poll2_label.set_use_markup (true);
	poll2_label.set_xalign (0);
	poll_settings_2.append (poll2_label);
	dmm_polling[1].set_valign (Gtk::Align::CENTER);
	dmm_polling[1].set_tooltip_text(_("Send Character for data polling"));
	poll_settings_2.append (dmm_polling[1]);
	auto nbyte_settings_2= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[1].append (nbyte_settings_2);
	nbyte2_label.set_text (_("<b>Bytes</b>"));
	nbyte2_label.set_size_request (100,-1);
	nbyte2_label.set_use_markup (true);
	nbyte2_label.set_xalign (0);
	nbyte_settings_2.append (nbyte2_label);
	dmm_num_bytes[1].set_size_request (100,-1);
	dmm_num_bytes[1].set_digits (0);
	dmm_num_bytes[1].set_range (0, 15);
	dmm_num_bytes[1].set_value (0);
	dmm_num_bytes[1].set_increments (1, 10);
	dmm_num_bytes[1].set_tooltip_text(_("Number of transmitted bytes"));
	nbyte_settings_2.append (dmm_num_bytes[1]);
	auto nval_settings_2= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[1].append (nval_settings_2);
	nval2_label.set_text (_("<b>Values</b>"));
	nval2_label.set_size_request (100,-1);
	nval2_label.set_use_markup (true);
	nval2_label.set_xalign (0);
	nval_settings_2.append (nval2_label);
	dmm_num_val[1].set_size_request (100,-1);
	dmm_num_val[1].set_digits (0);
	dmm_num_val[1].set_range (1, 4);
	dmm_num_val[1].set_value (1);
	dmm_num_val[1].set_increments (1, 1);
	dmm_num_val[1].set_tooltip_text(_("Number of transmitted data values"));
	nval_settings_2.append (dmm_num_val[1]);
	auto timeout_settings_2= Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm_serial_options[1].append (timeout_settings_2);
	timeout2_label.set_text (_("<b>Timeout</b>"));
	timeout2_label.set_size_request (100,-1);
	timeout2_label.set_use_markup (true);
	timeout2_label.set_xalign (0);
	timeout_settings_2.append (timeout2_label);
	dmm_timeout[1].set_size_request (100,-1);
	dmm_timeout[1].set_digits (0);
	dmm_timeout[1].set_range (0, 10000);
	dmm_timeout[1].set_value (1000);
	dmm_timeout[1].set_increments (1, 100);
	dmm_timeout[1].set_tooltip_text(_("Timeout in milliseconds"));
	dmm_timeout[1].signal_changed().connect(sigc::mem_fun(*this, &OptionsDialog::preset_mtime));
	timeout_settings_2.append (dmm_timeout[1]);

	//USB options
	dmm_usb_options[1] = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	chy_tab.append (dmm_usb_options[1]);
	ubyte2_label.set_text (_("<b>Bytes (USB)</b>"));
	ubyte2_label.set_size_request (100,-1);
	ubyte2_label.set_use_markup (true);
	ubyte2_label.set_xalign (0);
	dmm_usb_options[1].append (ubyte2_label);
	dmm_usb_bytes[1].set_size_request (100,-1);
	dmm_usb_bytes[1].set_digits (0);
	dmm_usb_bytes[1].set_range (0, 64);
	dmm_usb_bytes[1].set_value (0);
	dmm_usb_bytes[1].set_increments (1, 10);
	dmm_usb_bytes[1].set_tooltip_text(_("Number of transmitted bytes"));
	dmm_usb_options[1].append (dmm_usb_bytes[1]);

	// function options
	auto dmm2_function_options = Gtk::Box (Gtk::Orientation::VERTICAL);
	dmm2_function_options.set_margin_start (50);
	device_settings_2.append (dmm2_function_options);
	dmm_function_control[1] = Gtk::Box (Gtk::Orientation::VERTICAL);
	dmm2_function_options.append (dmm_function_control[1]);
	auto dmm2_funkt = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm2_funkt_label.set_text (_("<b>Function</b>"));
	dmm2_funkt_label.set_size_request (150,-1);
	dmm2_funkt_label.set_use_markup (true);
	dmm2_funkt_label.set_xalign (0);
	dmm2_funkt.append (dmm2_funkt_label);
	for (int i=1; i<m_functions.size (); i++) dmm_funktion[1].append (m_functions[i]);
	dmm_funktion[1].set_active_text (m_functions[1]);
	dmm2_funkt.append (dmm_funktion[1]);
	dmm_funktion[1].set_tooltip_text (_("Measurement function"));
	// Change range options, if function changed
	dmm_funktion[1].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::set_range_options_device), 1));
	dmm_function_control[1].append (dmm2_funkt);
	auto dmm2_range = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm2_range_label.set_text (_("<b>Range</b>"));
	dmm2_range_label.set_size_request (150,-1);
	dmm2_range_label.set_use_markup (true);
	dmm2_range_label.set_xalign (0);
	dmm2_range.append (dmm2_range_label);
	dmm_range[1].append ("200 mV");
	dmm_range[1].append("2 V");
	dmm_range[1].append("20 V");
	dmm_range[1].append("200 V");
	dmm_range[1].append("1000 V");
	dmm_range[1].set_active_text ("200 mV");
	dmm2_range.append (dmm_range[1]);
	dmm_range[1].set_tooltip_text (_("Measurement function"));
	dmm_function_control[1].append (dmm2_range);

	// function control strings
	dmm_control_options[1] = Gtk::Box (Gtk::Orientation::VERTICAL);
	dmm2_function_options.append (dmm_control_options[1]);
	auto dmm2_DCV = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm2_DCV_label.set_text (_("<b>DC Voltage</b>"));
	dmm2_DCV_label.set_size_request (150,-1);
	dmm2_DCV_label.set_use_markup (true);
	dmm2_DCV_label.set_xalign (0);
	dmm2_DCV.append (dmm2_DCV_label);
	dmm_DCV[1] = Gtk::ComboBoxText (true);
	dmm_DCV[1].set_hexpand (false);
	dmm_DCV[1].append ("");
	dmm_DCV[1].set_active_text ("");
	dmm_DCV[1].set_tooltip_text(_("Control String"));
	dmm2_DCV.append (dmm_DCV[1]);
	dmm_DCV[1].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 1));
	dmm_control_options[1].append (dmm2_DCV);
	auto dmm2_ACV = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm2_ACV_label.set_text (_("<b>AC Voltage</b>"));
	dmm2_ACV_label.set_size_request (150,-1);
	dmm2_ACV_label.set_use_markup (true);
	dmm2_ACV_label.set_xalign (0);
	dmm2_ACV.append (dmm2_ACV_label);
	dmm_ACV[1] = Gtk::ComboBoxText (true);
	dmm_ACV[1].set_hexpand (false);
	dmm_ACV[1].append ("");
	dmm_ACV[1].set_active_text ("");
	dmm_ACV[1].set_tooltip_text(_("Control String"));
	dmm2_ACV.append (dmm_ACV[1]);
	dmm_ACV[1].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 1));
	dmm_control_options[1].append (dmm2_ACV);
	auto dmm2_DCmA = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm2_DCmA_label.set_text (_("<b>DC Current (mA)</b>"));
	dmm2_DCmA_label.set_size_request (150,-1);
	dmm2_DCmA_label.set_use_markup (true);
	dmm2_DCmA_label.set_xalign (0);
	dmm2_DCmA.append (dmm2_DCmA_label);
	dmm_DCmA[1] = Gtk::ComboBoxText (true);
	dmm_DCmA[1].set_hexpand (false);
	dmm_DCmA[1].append ("");
	dmm_DCmA[1].set_active_text ("");
	dmm_DCmA[1].set_tooltip_text(_("Control String"));
	dmm2_DCmA.append (dmm_DCmA[1]);
	dmm_DCmA[1].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 1));
	dmm_control_options[1].append (dmm2_DCmA);
	auto dmm2_ACmA = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm2_ACmA_label.set_text (_("<b>AC Current (mA)</b>"));
	dmm2_ACmA_label.set_size_request (150,-1);
	dmm2_ACmA_label.set_use_markup (true);
	dmm2_ACmA_label.set_xalign (0);
	dmm2_ACmA.append (dmm2_ACmA_label);
	dmm_ACmA[1] = Gtk::ComboBoxText (true);
	dmm_ACmA[1].set_hexpand (false);
	dmm_ACmA[1].append ("");
	dmm_ACmA[1].set_active_text ("");
	dmm_ACmA[1].set_tooltip_text(_("Control String"));
	dmm2_ACmA.append (dmm_ACmA[1]);
	dmm_ACmA[1].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 1));
	dmm_control_options[1].append (dmm2_ACmA);
	auto dmm2_DCA = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm2_DCA_label.set_text (_("<b>DC Current (A)</b>"));
	dmm2_DCA_label.set_size_request (150,-1);
	dmm2_DCA_label.set_use_markup (true);
	dmm2_DCA_label.set_xalign (0);
	dmm2_DCA.append (dmm2_DCA_label);
	dmm_DCA[1] = Gtk::ComboBoxText (true);
	dmm_DCA[1].set_hexpand (false);
	dmm_DCA[1].append ("");
	dmm_DCA[1].set_active_text ("");
	dmm_DCA[1].set_tooltip_text(_("Control String"));
	dmm2_DCA.append (dmm_DCA[1]);
	dmm_DCA[1].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 1));
	dmm_control_options[1].append (dmm2_DCA);
	auto dmm2_ACA = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm2_ACA_label.set_text (_("<b>AC Current (A)</b>"));
	dmm2_ACA_label.set_size_request (150,-1);
	dmm2_ACA_label.set_use_markup (true);
	dmm2_ACA_label.set_xalign (0);
	dmm2_ACA.append (dmm2_ACA_label);
	dmm_ACA[1] = Gtk::ComboBoxText (true);
	dmm_ACA[1].set_hexpand (false);
	dmm_ACA[1].append ("");
	dmm_ACA[1].set_active_text ("");
	dmm_ACA[1].set_tooltip_text(_("Control String"));
	dmm2_ACA.append (dmm_ACA[1]);
	dmm_ACA[1].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 1));
	dmm_control_options[1].append (dmm2_ACA);
	auto dmm2_res = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm2_res_label.set_text (_("<b>Resistance</b>"));
	dmm2_res_label.set_size_request (150,-1);
	dmm2_res_label.set_use_markup (true);
	dmm2_res_label.set_xalign (0);
	dmm2_res.append (dmm2_res_label);
	dmm_Res[1] = Gtk::ComboBoxText (true);
	dmm_Res[1].set_hexpand (false);
	dmm_Res[1].append ("");
	dmm_Res[1].set_active_text ("");
	dmm_Res[1].set_tooltip_text(_("Control String"));
	dmm2_res.append (dmm_Res[1]);
	dmm_Res[1].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 1));
	dmm_control_options[1].append (dmm2_res);
	auto dmm2_cond = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm2_cond_label.set_text (_("<b>Conductivity</b>"));
	dmm2_cond_label.set_size_request (150,-1);
	dmm2_cond_label.set_use_markup (true);
	dmm2_cond_label.set_xalign (0);
	dmm2_cond.append (dmm2_cond_label);
	dmm_Cond[1] = Gtk::ComboBoxText (true);
	dmm_Cond[1].set_hexpand (false);
	dmm_Cond[1].append ("");
	dmm_Cond[1].set_active_text ("");
	dmm_Cond[1].set_tooltip_text(_("Control String"));
	dmm2_cond.append (dmm_Cond[1]);
	dmm_Cond[1].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 1));
	dmm_control_options[1].append (dmm2_cond);
	auto dmm2_pH = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm2_ph_label.set_text ("<b>pH</b>");
	dmm2_ph_label.set_size_request (150,-1);
	dmm2_ph_label.set_use_markup (true);
	dmm2_ph_label.set_xalign (0);
	dmm2_pH.append (dmm2_ph_label);
	dmm_pH[1] = Gtk::ComboBoxText (true);
	dmm_pH[1].set_hexpand (false);
	dmm_pH[1].append ("");
	dmm_pH[1].set_active_text ("");
	dmm_pH[1].set_tooltip_text(_("Control String"));
	dmm2_pH.append (dmm_pH[1]);
	dmm_pH[1].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 1));
	dmm_control_options[1].append (dmm2_pH);
	auto dmm2_temp = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm2_temp_label.set_text (_("<b>Temperature</b>"));
	dmm2_temp_label.set_size_request (150,-1);
	dmm2_temp_label.set_use_markup (true);
	dmm2_temp_label.set_xalign (0);
	dmm2_temp.append (dmm2_temp_label);
	dmm_Temp[1] = Gtk::ComboBoxText (true);
	dmm_Temp[1].set_hexpand (false);
	dmm_Temp[1].append ("");
	dmm_Temp[1].set_active_text ("");
	dmm_Temp[1].set_tooltip_text(_("Control String"));
	dmm2_temp.append (dmm_Temp[1]);
	dmm_Temp[1].signal_changed().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_dmm_function_control), 1));
	dmm_control_options[1].append (dmm2_temp);
	///////////////////////////////////////////////////////////////

	////////// Simulation Parameter//////////////
	// linear simulation
	sim_linoptions[1]  = Gtk::Box (Gtk::Orientation::VERTICAL);
	chy_tab.append (sim_linoptions[1]);
	auto dmm2_slope = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm2_slope_label.set_text (_("<b>Slope</b>"));
	dmm2_slope_label.set_size_request (100,-1);
	dmm2_slope_label.set_use_markup (true);
	dmm2_slope_label.set_xalign (0);
	dmm2_slope.append (dmm2_slope_label);
	dmm2_autoslope.set_text ("auto: ");
	dmm2_slope.append (dmm2_autoslope);
	sim_slope_switch[1].set_valign (Gtk::Align::CENTER);
	dmm2_slope.append (sim_slope_switch[1]);
	sim_slope_switch[1].set_tooltip_text(_("Select slope. Auto for random slope."));
	sim_slope_switch[1].signal_state_set().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_simlin_options), 1), false);
	sim_slope[1].set_size_request (100,-1);
	sim_slope[1].set_digits (2);
	sim_slope[1].set_range (-1.0, 1.0);
	sim_slope[1].set_value (0.0);
	sim_slope[1].set_increments (0.01, 0.1);
	sim_slope[1].set_margin_start (10);
	dmm2_slope.append (sim_slope[1]);
	sim_linoptions[1].append (dmm2_slope);
	auto dmm2_shift = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	dmm2_shift_label.set_text (_("<b>Deviation</b>"));
	dmm2_shift_label.set_size_request (100,-1);
	dmm2_shift_label.set_use_markup (true);
	dmm2_shift_label.set_xalign (0);
	dmm2_shift.append (dmm2_shift_label);
	dmm2_autoshift.set_text ("auto: ");
	dmm2_shift.append (dmm2_autoshift);
	sim_shift_switch[1].set_valign (Gtk::Align::CENTER);
	dmm2_shift.append (sim_shift_switch[1]);
	sim_shift_switch[1].set_tooltip_text(_("Select uncertainty of value. Effective deviation is randomized."));
	sim_shift_switch[1].signal_state_set().connect(sigc::bind(sigc::mem_fun(*this, &OptionsDialog::show_simlin_options), 1), false);
	sim_shift[1].set_size_request (100,-1);
	sim_shift[1].set_digits (2);
	sim_shift[1].set_range (0.1, 10);
	sim_shift[1].set_value (0.0);
	sim_shift[1].set_increments (0.1, 1);
	sim_shift[1].set_margin_start (10);
	dmm2_shift.append (sim_shift[1]);
	Gtk::Label shift_dim;
	shift_dim.set_text ("%");
	shift_dim.set_margin_start (5);
	dmm2_shift.append (shift_dim);
	sim_linoptions[1].append (dmm2_shift);

	// exponential simulation
	sim_expoptions  = Gtk::Box (Gtk::Orientation::VERTICAL);
	chy_tab.append (sim_expoptions);
	auto exp_init = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	exp_init_label.set_text (_("<b>Initial value</b>"));
	exp_init_label.set_size_request (100,-1);
	exp_init_label.set_use_markup (true);
	exp_init_label.set_xalign (0);
	exp_init.append (exp_init_label);
	exp_init_auto.set_text ("auto: ");
	exp_init.append (exp_init_auto);
	sim_init_sw.set_valign (Gtk::Align::CENTER);
	exp_init.append (sim_init_sw);
	sim_init_sw.set_tooltip_text(_("Select initial value. Auto for random value."));
	sim_init_sw.signal_state_set().connect(sigc::mem_fun(*this, &OptionsDialog::show_simexp_options), false);

	sim_init.set_size_request (100,-1);
	sim_init.set_digits (2);
	sim_init.set_range (0.1, 100);
	sim_init.set_value (0.1);
	sim_init.set_increments (0.1, 1);
	sim_init.set_margin_start (10);
	exp_init.append (sim_init);
	sim_expoptions.append (exp_init);
	auto exp_time = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	exp_time_label.set_text (_("<b>Time constant</b>"));
	exp_time_label.set_size_request (100,-1);
	exp_time_label.set_use_markup (true);
	exp_time_label.set_xalign (0);
	exp_time.append (exp_time_label);
	exp_time_auto.set_text ("auto: ");
	exp_time.append (exp_time_auto);
	sim_tc_sw.set_valign (Gtk::Align::CENTER);
	exp_time.append (sim_tc_sw);
	sim_tc_sw.set_tooltip_text(_("Select time constant. Auto for random value."));
	sim_tc_sw.signal_state_set().connect(sigc::mem_fun(*this, &OptionsDialog::show_simexp_options), false);
	sim_tc.set_size_request (100,-1);
	sim_tc.set_digits (3);
	sim_tc.set_range (0.001, 1.0);
	sim_tc.set_value (0.0);
	sim_tc.set_increments (0.001, 0.1);
	sim_tc.set_margin_start (10);
	exp_time.append (sim_tc);
	sim_expoptions.append (exp_time);
	auto exp_shift = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	exp_shift_label.set_text (_("<b>Deviation</b>"));
	exp_shift_label.set_size_request (100,-1);
	exp_shift_label.set_use_markup (true);
	exp_shift_label.set_xalign (0);
	exp_shift.append (exp_shift_label);
	exp_shift_auto.set_text ("auto: ");
	exp_shift.append (exp_shift_auto);
	sim_expshift_sw.set_valign (Gtk::Align::CENTER);
	exp_shift.append (sim_expshift_sw);
	sim_expshift_sw.set_tooltip_text(_("Select uncertainty of value. Effective deviation is randomized."));
	sim_expshift_sw.signal_state_set().connect(sigc::mem_fun(*this, &OptionsDialog::show_simexp_options), false);
	sim_expshift.set_size_request (100,-1);
	sim_expshift.set_digits (1);
	sim_expshift.set_range (0.1, 10);
	sim_expshift.set_value (0.1);
	sim_expshift.set_increments (0.1, 1);
	sim_expshift.set_margin_start (10);
	exp_shift.append (sim_expshift);
	Gtk::Label expshift_dim;
	expshift_dim.set_text ("%");
	expshift_dim.set_margin_start (5);
	exp_shift.append (expshift_dim);
	sim_expoptions.append (exp_shift);

	// chromatogram simulation
	sim_chromoptions  = Gtk::Box (Gtk::Orientation::VERTICAL);
	chy_tab.append (sim_chromoptions);
	auto chrom_peaks = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	chrom_peaks_label.set_text (_("<b>Number of peaks</b>"));
	chrom_peaks_label.set_size_request (150,-1);
	chrom_peaks_label.set_use_markup (true);
	chrom_peaks_label.set_xalign (0);
	chrom_peaks.append (chrom_peaks_label);
	chrom_peaks_auto.set_text ("auto: ");
	chrom_peaks.append (chrom_peaks_auto);
	sim_np_sw.set_valign (Gtk::Align::CENTER);
	chrom_peaks.append (sim_np_sw);
	sim_np_sw.set_tooltip_text(_("Select number of peaks."));
	sim_np_sw.signal_state_set().connect(sigc::mem_fun(*this, &OptionsDialog::show_simchrom_options), false);
	sim_np.set_size_request (150,-1);
	sim_np.set_digits (0);
	sim_np.set_range (1, 20);
	sim_np.set_value (1);
	sim_np.set_increments (1, 10);
	sim_np.set_margin_start (10);
	chrom_peaks.append (sim_np);
	sim_chromoptions.append (chrom_peaks);
	auto chrom_ret = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	chrom_ret_label.set_text (_("<b>Maximum retention</b>"));
	chrom_ret_label.set_size_request (150,-1);
	chrom_ret_label.set_use_markup (true);
	chrom_ret_label.set_xalign (0);
	chrom_ret.append (chrom_ret_label);
	chrom_ret_auto.set_text ("auto: ");
	chrom_ret.append (chrom_ret_auto);
	sim_max_rt_sw.set_valign (Gtk::Align::CENTER);
	chrom_ret.append (sim_max_rt_sw);
	sim_max_rt_sw.set_tooltip_text(_("Select maximum retention time."));
	sim_max_rt_sw.signal_state_set().connect(sigc::mem_fun(*this, &OptionsDialog::show_simchrom_options), false);
	sim_max_rt.set_size_request (150,-1);
	sim_max_rt.set_digits (0);
	sim_max_rt.set_range (20, 300);
	sim_max_rt.set_value (180);
	sim_max_rt.set_increments (10, 50);
	sim_max_rt.set_margin_start (10);
	chrom_ret.append (sim_max_rt);
	sim_chromoptions.append (chrom_ret);
	auto chrom_bf = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	chrom_bf_label.set_text (_("<b>Peak width</b>"));
	chrom_bf_label.set_size_request (150,-1);
	chrom_bf_label.set_use_markup (true);
	chrom_bf_label.set_xalign (0);
	chrom_bf.append (chrom_bf_label);
	chrom_bf_auto.set_text ("auto: ");
	chrom_bf.append (chrom_bf_auto);
	sim_bf_sw.set_valign (Gtk::Align::CENTER);
	chrom_bf.append (sim_bf_sw);
	sim_bf_sw.set_tooltip_text(_("Select peak width. Effective peak width is randomized."));
	sim_bf_sw.signal_state_set().connect(sigc::mem_fun(*this, &OptionsDialog::show_simchrom_options), false);
	sim_bf.set_size_request (150,-1);
	sim_bf.set_digits (1);
	sim_bf.set_range (0.1, 10);
	sim_bf.set_value (0.1);
	sim_bf.set_increments (0.1, 1);
	sim_bf.set_margin_start (10);
	chrom_bf.append (sim_bf);
	sim_chromoptions.append (chrom_bf);
	auto chrom_drift = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	chrom_drift_label.set_text (_("<b>Drift</b>"));
	chrom_drift_label.set_size_request (150,-1);
	chrom_drift_label.set_use_markup (true);
	chrom_drift_label.set_xalign (0);
	chrom_drift.append (chrom_drift_label);
	chrom_drift_auto.set_text ("auto: ");
	chrom_drift.append (chrom_drift_auto);
	sim_drift_sw.set_valign (Gtk::Align::CENTER);
	chrom_drift.append (sim_drift_sw);
	sim_drift_sw.set_tooltip_text(_("Select baseline drift."));
	sim_drift_sw.signal_state_set().connect(sigc::mem_fun(*this, &OptionsDialog::show_simchrom_options), false);
	sim_drift.set_size_request (150,-1);
	sim_drift.set_digits (4);
	sim_drift.set_range (0.0001, 0.01);
	sim_drift.set_value (0.0);
	sim_drift.set_increments (0.001, 0.001);
	sim_drift.set_margin_start (10);
	chrom_drift.append (sim_drift);
	Gtk::Label chrom_drift_dim;
	chrom_drift_dim.set_text ("%");
	chrom_drift_dim.set_margin_start (5);
	chrom_drift.append (chrom_drift_dim);
	sim_chromoptions.append (chrom_drift);



	//Buttons
	add_button (_("Reset"), 1);
	add_button (_("Cancel"), Gtk::ResponseType::CANCEL);
	add_button (_("OK"), Gtk::ResponseType::ACCEPT);
	signal_response().connect([this](int responseID){accept_options (responseID);});
}

OptionsDialog::~OptionsDialog ()
{
}

TimerDialog::TimerDialog ()
{
	set_title (_("Start Measurement with timer"));
	set_modal (true);
	set_hide_on_close ();
	set_default_size (400, -1);
	content = get_content_area ();
	start_label.set_text(_("Start measurement in"));
	start_label.set_hexpand (true);
	content->append (start_label);
	timer_start.set_digits (0);
	timer_start.set_range (0, 3600);
	timer_start.set_value (0.0);
	timer_start.set_increments (1, 100);
	timer_start.set_margin_start (10);
	timer_start.set_margin_end (10);
	content->append (timer_start);
	sec_label.set_text(_("seconds"));
	sec_label.set_hexpand (true);
	content->append (sec_label);
	add_button (_("Cancel"), Gtk::ResponseType::CANCEL);
	add_button (_("OK"), Gtk::ResponseType::ACCEPT);
	signal_response().connect([this](int responseID){start_mess_timer (responseID);});


}

TimerDialog::~TimerDialog ()
{
}


EvalData_Transform_Dialog::EvalData_Transform_Dialog ()
{
    set_title (_("Data Transformation"));
	set_modal (true);
	set_hide_on_close (true);
	//set_default_size (700, 450);
	resp_loop = Glib::MainLoop::create (false);     // create loop to pause program until signal response is received

    content = Gtk::Box (Gtk::Orientation::VERTICAL);
    content.set_margin (20);
	set_child (content);
	// Channel 1 (X)
	auto kanal_x = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	content.append (kanal_x);
	x_label.set_margin_top (10);
	x_label.set_text (_("<b>Channel 1 (X)</b>"));
	x_label.set_use_markup (true);
	x_label.set_xalign (0);
	kanal_x.append (x_label);

	// titration volume
	auto titvol = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	titvol.set_margin_top (10);
	content.append (titvol);
	titvol_label.set_text (_("<b>Titrator Volume</b>"));
	titvol_label.set_margin_top (5);
	titvol_label.set_size_request (150, -1);
	titvol_label.set_use_markup (true);
	titvol_label.set_xalign (0);
	titvol.append (titvol_label);
	evaloption_vol.set_valign (Gtk::Align::CENTER);
	evaloption_vol.set_tooltip_text (_("Time -> Volume"));
	evaloption_vol.signal_state_set().connect(sigc::mem_fun(*this, &EvalData_Transform_Dialog::show_eval_volspeed), false);
	titvol.append (evaloption_vol);
	evaloption_volspeed.set_digits (2);
	evaloption_volspeed.set_range (0, 100);
	evaloption_volspeed.set_value (0.0);
	evaloption_volspeed.set_increments (0.01, 10);
	evaloption_volspeed.set_margin_start (10);
	evaloption_volspeed.set_margin_end (10);
	titvol.append (evaloption_volspeed);
	Gtk::Label volspeed_dim;
	volspeed_dim.set_text ("ml/min");
	titvol.append (volspeed_dim);

	// thermocouples for temperatur measurement
	auto xtherm = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	xtherm.set_margin_top (10);
	content.append (xtherm);
	xtherm_label.set_text (_("<b>Thermocouple</b>"));
	xtherm_label.set_margin_top (5);
	xtherm_label.set_size_request (150, -1);
	xtherm_label.set_use_markup (true);
	xtherm_label.set_xalign (0);
	xtherm.append (xtherm_label);
	evaloption_xtherm.append (_("none"));
	xtherm.append (evaloption_xtherm);

	// reziprok transformation
	auto xinv = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	xinv.set_margin_top (10);
	content.append (xinv);
	xinv_label.set_text (_("<b>Inversion</b>"));
	xinv_label.set_margin_top (5);
	xinv_label.set_size_request (150, -1);
	xinv_label.set_use_markup (true);
	xinv_label.set_xalign (0);
	xinv.append (xinv_label);
	evaloption_xreziproksw.set_valign (Gtk::Align::CENTER);
	evaloption_xreziproksw.set_margin_start (5);
	evaloption_xreziproksw.set_tooltip_text("x -> 1/x");
	xinv.append (evaloption_xreziproksw);

	// logarithmic transformation
	auto xlog = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	xlog.set_margin_top (10);
	xlog.set_margin_bottom (10);
	content.append (xlog);
	xlog_label.set_text (_("<b>Logarithm</b>"));
	xlog_label.set_margin_top (5);
	xlog_label.set_size_request (150, -1);
	xlog_label.set_use_markup (true);
	xlog_label.set_xalign (0);
	xlog.append (xlog_label);
	evaloption_xlogsw.set_valign (Gtk::Align::CENTER);
	evaloption_xlogsw.set_margin_start (5);
	evaloption_xlogsw.set_tooltip_text("x -> log x");
	xlog.append (evaloption_xlogsw);

	// Channel 2 (Y)
	auto kanal_y = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	content.append (kanal_y);
	y_label.set_margin_top (30);
	y_label.set_text (_("<b>Channel 2 (Y)</b>"));
	y_label.set_use_markup (true);
	y_label.set_xalign (0);
	kanal_y.append (y_label);

	// thermocouples for temperatur measurement
	auto ytherm = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	ytherm.set_margin_top (10);
	content.append (ytherm);
	ytherm_label.set_text (_("<b>Thermocouple</b>"));
	ytherm_label.set_margin_top (5);
	ytherm_label.set_size_request (150, -1);
	ytherm_label.set_use_markup (true);
	ytherm_label.set_xalign (0);
	ytherm.append (ytherm_label);
	evaloption_ytherm.append (_("none"));
	ytherm.append (evaloption_ytherm);

	// reziprok transformation
	auto yinv = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	yinv.set_margin_top (10);
	content.append (yinv);
	yinv_label.set_text (_("<b>Inversion</b>"));
	yinv_label.set_margin_top (5);
	yinv_label.set_size_request (150, -1);
	yinv_label.set_use_markup (true);
	yinv_label.set_xalign (0);
	yinv.append (yinv_label);
	evaloption_yreziproksw.set_valign (Gtk::Align::CENTER);
	evaloption_yreziproksw.set_margin_start (5);
	evaloption_yreziproksw.set_tooltip_text("y -> 1/y");
	yinv.append (evaloption_yreziproksw);

	// logarithmic transformation
	auto ylog = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	ylog.set_margin_top (10);
	content.append (ylog);
	ylog_label.set_text (_("<b>Logarithm</b>"));
	ylog_label.set_margin_top (5);
	ylog_label.set_size_request (150, -1);
	ylog_label.set_use_markup (true);
	ylog_label.set_xalign (0);
	ylog.append (ylog_label);
	evaloption_ylogsw.set_valign (Gtk::Align::CENTER);
	evaloption_ylogsw.set_margin_start (5);
	evaloption_ylogsw.set_tooltip_text("y -> log y");
	ylog.append (evaloption_ylogsw);

	//Buttons
	button_box = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	button_box.set_margin_top (30);
	content.append (button_box);
	button_box.append (button_reset);
	button_reset.set_label (_("Reset"));
    button_reset.signal_clicked().connect(sigc::mem_fun(*this, &EvalData_Transform_Dialog::reset_data_transformation));
	button_box.append (button_cancel);
	button_cancel.set_label (_("Cancel"));
    button_cancel.signal_clicked().connect(sigc::mem_fun(*this, &EvalData_Transform_Dialog::cancel_data_transformation));
	button_box.append (button_ok);
	button_ok.set_label (_("OK"));
    button_ok.signal_clicked().connect(sigc::mem_fun(*project, &Project::transform_data));

}

EvalData_Transform_Dialog::~EvalData_Transform_Dialog ()
{
}

Eval_Function_Dialog::Eval_Function_Dialog ()
{
    set_title (_("Evaluation Functions"));
	set_modal (true);
	set_hide_on_close (true);
	resp_loop = Glib::MainLoop::create (false);     // create loop to pause program until signal response is received

    content = Gtk::Box (Gtk::Orientation::VERTICAL);
    content.set_margin (20);
    	set_child (content);
    // colour of function graph
	auto fgraph = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	content.append (fgraph);
	fgraph_label.set_text (_("<b>Function Graph</b>"));
	fgraph_label.set_size_request (150, -1);
	fgraph_label.set_use_markup (true);
	fgraph_label.set_xalign (0);
	fgraph.append (fgraph_label);
	diag_funktcolor.set_tooltip_text (_("Select color of graph"));
	fgraph.append (diag_funktcolor);

	// linear regression
	auto reglin = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	reglin.set_margin_top (10);
	content.append (reglin);
	reglin_label.set_text (_("<b>Linear Regression</b>"));
	reglin_label.set_size_request (150, -1);
	reglin_label.set_use_markup (true);
	reglin_label.set_xalign (0);
	reglin.append (reglin_label);
	evaloption_reglin.set_valign (Gtk::Align::CENTER);
	evaloption_reglin.set_tooltip_text (_("Calculate linear regression of data"));
	reglin.append (evaloption_reglin);

	// differential function
	auto diff = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	diff.set_margin_top (10);
	content.append (diff);
	diff_label.set_text (_("<b>Differential Function</b>"));
	diff_label.set_size_request (150, -1);
	diff_label.set_use_markup (true);
	diff_label.set_xalign (0);
	diff.append (diff_label);
	evaloption_diff.set_valign (Gtk::Align::CENTER);
	evaloption_diff.signal_state_set().connect(sigc::mem_fun(*this, &Eval_Function_Dialog::show_mindiffscale), false);
	evaloption_diff.set_tooltip_text (_("Calculate differential quotient and gauss model"));
	diff.append (evaloption_diff);
	evaldiff_min_label.set_text (_("Minimum"));
	evaldiff_min_label.set_margin_start (5);
	evaldiff_min_label.set_margin_end (5);
	evaldiff_min_label.set_xalign (0);
	diff.append (evaldiff_min_label);
	evaloption_mindiffscale.set_digits (1);
	evaloption_mindiffscale.set_range (0.1, 90);
	evaloption_mindiffscale.set_value (0.0);
	evaloption_mindiffscale.set_increments (0.1, 10);
	evaloption_mindiffscale.set_margin_end (10);
	evaloption_mindiffscale.set_tooltip_text (_("Minimal size for evaluation"));
	diff.append (evaloption_mindiffscale);
	Gtk::Label mindiffscale_dim;
	mindiffscale_dim.set_text ("%");
	diff.append (mindiffscale_dim);

	// peak integration
	auto peakint = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	peakint.set_margin_top (10);
	content.append (peakint);
	peakint_label.set_text (_("<b>Peak Integration</b>"));
	peakint_label.set_size_request (150, -1);
	peakint_label.set_use_markup (true);
	peakint_label.set_xalign (0);
	peakint.append (peakint_label);
	evaloption_integration.set_valign (Gtk::Align::CENTER);
	evaloption_integration.set_tooltip_text (_("Calculate peak integration"));
	peakint.append (evaloption_integration);
	int_min_label.set_text (_("Minimum"));
	int_min_label.set_margin_start (5);
	int_min_label.set_margin_end (5);
	int_min_label.set_xalign (0);
	peakint.append (int_min_label);
	evaloption_minpeakscale.set_digits (2);
	evaloption_minpeakscale.set_range (0.01, 100);
	evaloption_minpeakscale.set_value (0.0);
	evaloption_minpeakscale.set_increments (0.01, 10);
	evaloption_minpeakscale.set_margin_end (10);
	evaloption_minpeakscale.set_tooltip_text (_("Minimum peak size for evaluation"));
	peakint.append (evaloption_minpeakscale);
	Gtk::Label peakscale_dim;
	peakscale_dim.set_text ("%");
	peakint.append (peakscale_dim);
	evaloption_integration.signal_state_set().connect(sigc::mem_fun(*this, &Eval_Function_Dialog::show_evaloptions_integration), false);

	//peak integration options
	integration_options = Gtk::Box (Gtk::Orientation::VERTICAL);
	integration_options.set_margin_top (10);
	content.append (integration_options);
	// baseline
	auto bline = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	bline.set_margin_top (10);
	integration_options.append (bline);
	bline_label.set_text (_("<b>Show Baseline</b>"));
	bline_label.set_margin_top (5);
	bline_label.set_size_request (200, -1);
	bline_label.set_use_markup (true);
	bline_label.set_xalign (0);
	bline.append (bline_label);
	evaloption_show_baseline.set_valign (Gtk::Align::CENTER);
	evaloption_show_baseline.set_margin_start (5);
	bline.append (evaloption_show_baseline);
	// peak limits
	auto limits = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	limits.set_margin_top (10);
	integration_options.append (limits);
	limits_label.set_text (_("<b>Show Peak Limits</b>"));
	limits_label.set_margin_top (5);
	limits_label.set_size_request (200, -1);
	limits_label.set_use_markup (true);
	limits_label.set_xalign (0);
	limits.append (limits_label);
	evaloption_show_peaklimits.set_valign (Gtk::Align::CENTER);
	evaloption_show_peaklimits.set_margin_start (5);
	limits.append (evaloption_show_peaklimits);
	// peak area
	auto area = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	area.set_margin_top (10);
	integration_options.append (area);
	area_label.set_text (_("<b>Show Peak Area</b>"));
	area_label.set_margin_top (5);
	area_label.set_size_request (200, -1);
	area_label.set_use_markup (true);
	area_label.set_xalign (0);
	area.append (area_label);
	evaloption_show_peakarea.set_valign (Gtk::Align::CENTER);
	evaloption_show_peakarea.set_margin_start (5);
	area.append (evaloption_show_peakarea);

	//Buttons
	button_box = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	button_box.set_margin_top (30);
	button_box.set_valign (Gtk::Align::BASELINE);
	content.append (button_box);
	button_box.append (button_reset);
	button_reset.set_label (_("Reset"));
    button_reset.signal_clicked().connect(sigc::mem_fun(*this, &Eval_Function_Dialog::reset_eval_functions));
    button_box.append (button_cancel);
	button_cancel.set_label (_("Cancel"));
    button_cancel.signal_clicked().connect(sigc::mem_fun(*this, &Eval_Function_Dialog::cancel_eval_functions));
    	button_box.append (button_ok);
	button_ok.set_label (_("OK"));
    button_ok.signal_clicked().connect(sigc::mem_fun(*project, &Project::evaluate_functions));
}

Eval_Function_Dialog::~Eval_Function_Dialog ()
{
}


EvalResults::EvalResults ()
{
	set_title (_("Evaluation Results"));
	set_modal (true);
	set_hide_on_close (true);
	content = Gtk::Box (Gtk::Orientation::VERTICAL);
	set_child (content);
	eval_funktion.set_text (_("Function"));
	eval_funktion.set_margin_top (20);
	eval_funktion.set_margin_bottom (20);
	content.append (eval_funktion);
	content.append (eval_results_view);
	eval_results_view.set_top_margin (10);
	eval_results_view.set_left_margin (20);
	eval_results_view.set_right_margin (20);
	eval_results_view.set_bottom_margin (30);
	eval_results_view.set_editable (false);
	eval_results_view.set_cursor_visible (false);
   	button_close.set_label (_("Close"));
   	content.append (button_close);
    button_close.signal_clicked().connect(sigc::mem_fun(*this, &EvalResults::close_results));
}

EvalResults::~EvalResults ()
{
}

Print_Dialog::Print_Dialog ()
{
    set_title (_("Print Report"));
    set_modal (true);
	set_hide_on_close (true);
	print_settings = Gtk::PrintSettings::create();
	print_settings->set_resolution (300); //set resolution to high quality (300 dpi)
	print_settings->set_quality (Gtk::PrintQuality::HIGH);
	top_margin = 15;    //margins in mm
	bottom_margin = 20;
	left_margin = 15;
	right_margin = 15;

	print_options = Gtk::Box (Gtk::Orientation::VERTICAL);
	set_child (print_options);


    // page elements
    elem_box = Gtk::Box (Gtk::Orientation::VERTICAL);
    print_options.append(elem_box);
    section_elements = Gtk::Label (_("<b>Page Elements</b>"));
    elem_box.append (section_elements);
    section_elements.set_use_markup (true);
    section_elements.set_margin (10);
    section_elements.set_xalign (0);

	// print title?
	title_box = Gtk::Box (Gtk::Orientation::HORIZONTAL, 100);
	elem_box.append(title_box);
	title = Gtk::Label (_("Title"));
	title.set_margin_start (20);
	title.set_xalign (0);
	title.set_size_request (90);
	title_box.append(title);
	title_box.append(titlesw);

	// print comment?
	comment_box = Gtk::Box (Gtk::Orientation::HORIZONTAL, 100);
	comment_box.set_margin_top (10);
	elem_box.append(comment_box);
	comment = Gtk::Label (_("Comment"));
	comment.set_margin_start (20);
	comment.set_xalign (0);
	comment.set_size_request (90);
	comment_box.append(comment);
	comment_box.append(commentsw);

	// print diagram?
	diagram_box = Gtk::Box (Gtk::Orientation::HORIZONTAL, 100);
	diagram_box.set_margin_top (10);
	elem_box.append(diagram_box);
	diagram = Gtk::Label (_("Diagram"));
	diagram.set_margin_start (20);
	diagram.set_xalign (0);
	diagram.set_size_request (90);
	diagram_box.append(diagram);
	diagram_box.append(diagsw);

	// print result?
	result_box = Gtk::Box (Gtk::Orientation::HORIZONTAL, 100);
	result_box.set_margin_top (10);
	elem_box.append(result_box);
	result = Gtk::Label (_("Evaluation"));
	result.set_margin_start (20);
	result.set_xalign (0);
	result.set_size_request (90);
	result_box.append(result);
	result_box.append(resultsw);

	// page orientation
	format_box = Gtk::Box (Gtk::Orientation::VERTICAL);
    format_box.set_margin_top (20);
    print_options.append(format_box);
    section_format = Gtk::Label (_("<b>Page Orientation</b>"));
    format_box.append (section_format);
    section_format.set_use_markup (true);
    section_format.set_margin (10);
    section_format.set_xalign (0);
    	orient_box = Gtk::Box (Gtk::Orientation::HORIZONTAL, 100);
	format_box.append(orient_box);
	orient_box.set_margin_top (10);
	orient = Gtk::Label (_("Orientation"));
	orient.set_margin_start (20);
	orient.set_xalign (0);
	orient.set_size_request (60);
	orient_box.append(orient);
	orient_box.append (page_orientation);
	page_orientation.append (_("Portrait"));
	page_orientation.append (_("Landscape"));
	page_orientation.set_active_text (_("Portrait"));

	// page layout
	// margins
    mrg_box = Gtk::Box (Gtk::Orientation::VERTICAL);
    mrg_box.set_margin_top (20);
    print_options.append(mrg_box);
    layout_box = Gtk::Box (Gtk::Orientation::HORIZONTAL);
    mrg_box.append (layout_box);
    section_margin = Gtk::Label (_("<b>Page Margins</b>"));
    layout_box.append (section_margin);
    section_margin.set_use_markup (true);
    section_margin.set_margin (10);
    section_margin.set_xalign (0);
    unit_str = Gtk::Label (_("<b>Unit: </b>"));
    unit_str.set_use_markup (true);
    layout_box.append (unit_str);
    unit = Gtk::Label ("mm");
    layout_box.append (unit);
    //left
	left_box = Gtk::Box (Gtk::Orientation::HORIZONTAL, 100);
	mrg_box.append(left_box);
	l_margin = Gtk::Label (_("Left:"));
	l_margin.set_margin_start (20);
	l_margin.set_xalign (0);
	l_margin.set_size_request (60);
	left_box.append(l_margin);
	left_box.append(lm);
	lm.set_digits (0);
	lm.set_range (10, 50);
	lm.set_value (0);
	lm.set_increments (5, 10);
	//right
	right_box = Gtk::Box (Gtk::Orientation::HORIZONTAL, 100);
	mrg_box.append(right_box);
	r_margin = Gtk::Label (_("Right:"));
	r_margin.set_margin_start (20);
	r_margin.set_xalign (0);
	r_margin.set_size_request (60);
	right_box.append(r_margin);
	right_box.append(rm);
	rm.set_digits (0);
	rm.set_range (10, 50);
	rm.set_value (0);
	rm.set_increments (5, 10);
	//top
	top_box = Gtk::Box (Gtk::Orientation::HORIZONTAL, 100);
	mrg_box.append(top_box);
	t_margin = Gtk::Label (_("Top:"));
	t_margin.set_margin_start (20);
	t_margin.set_xalign (0);
	t_margin.set_size_request (60);
	top_box.append(t_margin);
	top_box.append(tm);
	tm.set_digits (0);
	tm.set_range (10, 50);
	tm.set_value (0);
	tm.set_increments (5, 10);
	//bottom
	bottom_box = Gtk::Box (Gtk::Orientation::HORIZONTAL, 100);
	mrg_box.append(bottom_box);
	b_margin = Gtk::Label (_("Bottom:"));
	b_margin.set_margin_start (20);
	b_margin.set_xalign (0);
	b_margin.set_size_request (60);
	bottom_box.append(b_margin);
	bottom_box.append(bm);
	bm.set_digits (0);
	bm.set_range (15, 50);
	bm.set_value (0);
	bm.set_increments (5, 10);

	//Buttons
	button_box = Gtk::Box (Gtk::Orientation::HORIZONTAL);
	button_box.set_margin_top (30);
	button_box.set_valign (Gtk::Align::BASELINE);
	button_box.set_halign (Gtk::Align::END);
	print_options.append (button_box);
	//button_box.append (button_preview);   //unix print dialog shows automatically preview
	//button_preview.set_label (_("Preview"));
    //button_preview.signal_clicked().connect(sigc::mem_fun(*this, &PrintOP::preview_printreport));
    button_box.append (button_cancel);
	button_cancel.set_label (_("Cancel"));
    button_cancel.signal_clicked().connect(sigc::mem_fun(*this, &Print_Dialog::cancel_printreport));
    	button_box.append (button_print);
	button_print.set_label (_("Print"));
    button_print.signal_clicked().connect(sigc::mem_fun(*this, &Print_Dialog::print_report));
}

Print_Dialog::~Print_Dialog ()
{
}
