Subversion Repositories Projects

Rev

Rev 750 | Blame | Compare with Previous | Last modification | View Log | RSS feed

/***************************************************************************
 *   Copyright (C) 2009 by Manuel Schrape                                  *
 *   manuel.schrape@gmx.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.        *
 *                                                                         *
 *   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, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/


#include <QMessageBox>
#include <QCryptographicHash>

#include "dlg_Main.h"

// Konstruktor Main-Form
dlg_Main::dlg_Main()
{
    setupUi(this);


    o_Settings = new cSettings();

    o_Settings->read_DebugLabels(0);

    wg_Connection->set_Client(ID_SCOPE, QA_NAME + " " + QA_VERSION, DataFields);

    init_GUI();
    init_Connections();
    init_Plotter();
}

// Grafische Oberfläche initialisieren
void dlg_Main::init_GUI()
{
    setWindowTitle(QA_NAME + " " + QA_VERSION);

    resize(o_Settings->GUI.Size);
    move(o_Settings->GUI.Point);

    if (o_Settings->GUI.isMax)
    {
        showMaximized();
    }

    wg_Connection->set_SelectVisible(true);
    wg_Connection->set_ButtonVisible(true);

    btn_Start->setCheckable(true);

    for(int z = 0; z < MAX_DebugData; z++)
    {
        wg_Index[z] = new wgt_Index();
        verticalLayout->addWidget(wg_Index[z]);

        wg_Index[z]->set_Name(o_Settings->DebugData.Label[z]);
        wg_Index[z]->set_StyleSheet("color: " + QColor(DEF_DebugColors[z]).name() + ";");

        connect(wg_Index[z], SIGNAL(sig_Clicked()), this, SLOT(slot_btn_ChoseOK()));
    }
}

// Signale mit Slots verbinden
void dlg_Main::init_Connections()
{
    connect(ac_Connect, SIGNAL(triggered()), wg_Connection, SLOT(slot_btn_Connect()));

    connect(ac_ReadLabels, SIGNAL(triggered()), this, SLOT(slot_ac_ReadLabels()));

    connect(Plotter_Scroll, SIGNAL(valueChanged(int)), this, SLOT(slot_Plotter_Scroll(int)));

    connect(btn_Start, SIGNAL(clicked()), this, SLOT(slot_Plotter_Start()));
//    connect(btn_ChoseOK, SIGNAL(clicked()), this, SLOT(slot_btn_ChoseOK()));

    // About QMK-Kernel & About-QT Dialog einfügen
    connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About()));
    menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt()));

    connect(wg_Connection, SIGNAL(sig_Status(int)), this, SLOT(slot_ConnectionStatus(int)));
    connect(wg_Connection, SIGNAL(sig_MK_Version(s_Hardware)), this, SLOT(slot_MK_Version(s_Hardware)));
    connect(wg_Connection, SIGNAL(sig_MK_Debug(s_MK_Debug)), this, SLOT(slot_MK_Debug(s_MK_Debug)));
    connect(wg_Connection, SIGNAL(sig_MK_DebugLabels(s_MK_DebugLabels)), this, SLOT(slot_MK_DebugLabels(s_MK_DebugLabels)));
}

void dlg_Main::init_Plotter()
{
    NextPlot = 0;

    qwt_Plotter->setCanvasBackground(QColor(QRgb(0x00000000)));

//    qwt_Plotter->insertLegend(new QwtLegend(), QwtPlot::RightLegend);

    QwtPlotGrid *Grid = new QwtPlotGrid();
    Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));

    Grid->attach(qwt_Plotter);

    qwt_Plotter->setAxisScale(QwtPlot::xBottom,0,o_Settings->DATA.Plotter_Count,0);

    for (int a = 0; a < MAX_DebugData; a++)
    {
        Plot[a] = new QwtPlotCurve(o_Settings->DebugData.Label[a]);
        Plot[a]->setPen(QPen(QColor(DEF_DebugColors[a])));
        Plot[a]->setRenderHint(QwtPlotItem::RenderAntialiased);

        if (o_Settings->DebugData.Show_Plotter[a])
            Plot[a]->attach(qwt_Plotter);
    }
    qwt_Plotter->replot();


}

void dlg_Main::update_Plotter()
{
    pl_ID[NextPlot] = NextPlot;

    for (int a = 0; a < MAX_DebugData; a++)
    {
        pl_Data[a][NextPlot] = Debug_Data[a];
        Plot[a]->setData(pl_ID,pl_Data[a],NextPlot);
    }

    NextPlot++;

    if ((NextPlot > o_Settings->DATA.Plotter_Count))
    {
        Plotter_Scroll->setMaximum(NextPlot - o_Settings->DATA.Plotter_Count);
    }

    if ((Plotter_Scroll->value() == NextPlot - (o_Settings->DATA.Plotter_Count + 1)))
    {
        qwt_Plotter->setAxisScale(QwtPlot::xBottom,NextPlot - o_Settings->DATA.Plotter_Count,NextPlot,0);
        Plotter_Scroll->setValue(NextPlot - o_Settings->DATA.Plotter_Count);
    }

    qwt_Plotter->replot();
}

void dlg_Main::config_Plotter()
{
    qwt_Plotter->setAxisScale(QwtPlot::xBottom,0,o_Settings->DATA.Plotter_Count,0);

    for (int a = 0; a < MAX_DebugData; a++)
    {
        Plot[a]->detach();
        Plot[a]->setPen(QPen(QColor(DEF_DebugColors[a])));

        if (o_Settings->DebugData.Show_Plotter[a])
        {
//            Plot[a]->setTitle(o_Settings->DebugData.Label[a]);
            Plot[a]->attach(qwt_Plotter);
        }
    }
    qwt_Plotter->replot();
}

void dlg_Main::slot_Plotter_Scroll(int Position)
{
    qwt_Plotter->setAxisScale(QwtPlot::xBottom,Position,Position + o_Settings->DATA.Plotter_Count,0);
    qwt_Plotter->replot();
}

///////////
// Slots //
///////////

// About-Dialog
void dlg_Main::slot_ac_About()
{
    QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT);
}

void dlg_Main::slot_ConnectionStatus(int li_Status)
{
    if (li_Status)
    {
        ac_Connect->setChecked(true);
        ac_Connect->setText(tr("Trennen"));
    }
    else
    {
        ac_Connect->setChecked(false);
        ac_Connect->setText(tr("Verbinden"));
    }
}

void dlg_Main::slot_MK_Version(s_Hardware ls_Version)
{
    gs_Version = ls_Version;
    setWindowTitle(QA_NAME + " " + QA_VERSION + " - " + ls_Version.Hardware + " " + ls_Version.Version);

    o_Settings->read_DebugLabels(gs_Version.ID);

    if (o_Settings->DebugData.Version != gs_Version.Version)
    {
        qDebug(QString("Debug-Labels unterschiedlich. Neue anforden. " + o_Settings->DebugData.Version + " <> " + gs_Version.Version).toLatin1().data());
        usleep(50000);

        slot_ac_ReadLabels();
    }
    else
    {
        for(int z = 0; z < MAX_DebugData; z++)
        {
            wg_Index[z]->set_Name(o_Settings->DebugData.Label[z]);
            wg_Index[z]->set_Checked(o_Settings->DebugData.Show_Plotter[z]);

        }
        config_Plotter();
    }
}

void dlg_Main::slot_MK_Debug(s_MK_Debug ls_Debug)
{
    gs_Debug = ls_Debug;

    for (int z = 0; z < MAX_DebugData; z++)
    {
        Debug_Data[z] = ls_Debug.Analog[z];

        wg_Index[z]->set_Wert(QString("%1").arg(Debug_Data[z]));
    }
    if (btn_Start->isChecked())
    {
       update_Plotter();
    }
}

void dlg_Main::slot_MK_DebugLabels(s_MK_DebugLabels MK_DebugLabels)
{
    if (MK_DebugLabels.Position < 32)
    {
        o_Settings->DebugData.Label[MK_DebugLabels.Position] = MK_DebugLabels.Text;
        if (o_Settings->DebugData.Label[MK_DebugLabels.Position] == "")
        {
            o_Settings->DebugData.Label[MK_DebugLabels.Position] = "Debug-" + QString("%1").arg(MK_DebugLabels.Position);
        }
//        cb_Debug[MK_DebugLabels.Position]->setText("" + o_Settings->DebugData.Label[MK_DebugLabels.Position]);
        wg_Index[MK_DebugLabels.Position]->set_Name("" + o_Settings->DebugData.Label[MK_DebugLabels.Position]);
//        wg_Index[z]->set_Checked(o_Settings->DebugData.Show_Plotter[z]);


    }
    if (MK_DebugLabels.Position == 31)
    {
        o_Settings->DebugData.Version = gs_Version.Version;
        o_Settings->write_DebugLabels(gs_Version.ID);
        config_Plotter();
    }
}

void dlg_Main::slot_Plotter_Start()
{
    if (btn_Start->isChecked())
    {
        btn_Start->setText(tr("Plotter stoppen"));
    }
    else
    {
        btn_Start->setText(tr("Plotter starten"));
    }
}

void dlg_Main::slot_btn_ChoseOK()
{
    for(int z = 0; z < MAX_DebugData; z++)
    {
        o_Settings->DebugData.Show_Plotter[z] = wg_Index[z]->get_Checked();
    }
    config_Plotter();
    o_Settings->write_DebugLabels(gs_Version.ID);
}

void dlg_Main::slot_ac_ReadLabels()
{
    c_Data[0] = 0;
    wg_Connection->send_Data(HandlerMK::make_Frame('a', ADDRESS_ALL, c_Data, 1).toLatin1().data(), DATA_READ_LABEL);
}

// Programm Ende
dlg_Main::~dlg_Main()
{
    o_Settings->GUI.isMax       = isMaximized();
    o_Settings->GUI.Size        = size();
    o_Settings->GUI.Point       = pos();

    o_Settings->write_Settings();
}