Subversion Repositories Projects

Rev

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

Rev Author Line No. Line
674 KeyOz 1
/***************************************************************************
2
 *   Copyright (C) 2009 by Manuel Schrape                                  *
3
 *   manuel.schrape@gmx.de                                                 *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation; either version 2 of the License.        *
8
 *                                                                         *
9
 *   This program is distributed in the hope that it will be useful,       *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU General Public License for more details.                          *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
19
 
20
#include <QMessageBox>
711 KeyOz 21
#include <QCryptographicHash>
674 KeyOz 22
 
23
#include "dlg_Main.h"
24
 
25
// Konstruktor Main-Form
26
dlg_Main::dlg_Main()
27
{
28
    setupUi(this);
29
 
750 KeyOz 30
 
674 KeyOz 31
    o_Settings = new cSettings();
32
 
33
    o_Settings->read_DebugLabels(0);
34
 
750 KeyOz 35
    wg_Connection->set_Client(ID_SCOPE, QA_NAME + " " + QA_VERSION, DataFields);
674 KeyOz 36
 
37
    init_GUI();
38
    init_Connections();
39
    init_Plotter();
40
}
41
 
42
// Grafische Oberfläche initialisieren
43
void dlg_Main::init_GUI()
44
{
45
    setWindowTitle(QA_NAME + " " + QA_VERSION);
46
 
47
    resize(o_Settings->GUI.Size);
48
    move(o_Settings->GUI.Point);
49
 
50
    if (o_Settings->GUI.isMax)
51
    {
52
        showMaximized();
53
    }
54
 
801 - 55
    wg_Connection->set_SelectVisible(true);
56
    wg_Connection->set_ButtonVisible(true);
674 KeyOz 57
 
58
    btn_Start->setCheckable(true);
59
 
60
    for(int z = 0; z < MAX_DebugData; z++)
61
    {
801 - 62
        wg_Index[z] = new wgt_Index();
63
        verticalLayout->addWidget(wg_Index[z]);
674 KeyOz 64
 
801 - 65
        wg_Index[z]->set_Name(o_Settings->DebugData.Label[z]);
66
        wg_Index[z]->set_StyleSheet("color: " + QColor(DEF_DebugColors[z]).name() + ";");
674 KeyOz 67
 
801 - 68
        connect(wg_Index[z], SIGNAL(sig_Clicked()), this, SLOT(slot_btn_ChoseOK()));
674 KeyOz 69
    }
70
}
71
 
72
// Signale mit Slots verbinden
73
void dlg_Main::init_Connections()
74
{
750 KeyOz 75
    connect(ac_Connect, SIGNAL(triggered()), wg_Connection, SLOT(slot_btn_Connect()));
674 KeyOz 76
 
77
    connect(ac_ReadLabels, SIGNAL(triggered()), this, SLOT(slot_ac_ReadLabels()));
78
 
79
    connect(Plotter_Scroll, SIGNAL(valueChanged(int)), this, SLOT(slot_Plotter_Scroll(int)));
80
 
81
    connect(btn_Start, SIGNAL(clicked()), this, SLOT(slot_Plotter_Start()));
801 - 82
//    connect(btn_ChoseOK, SIGNAL(clicked()), this, SLOT(slot_btn_ChoseOK()));
674 KeyOz 83
 
84
    // About QMK-Kernel & About-QT Dialog einfügen
85
    connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About()));
86
    menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt()));
750 KeyOz 87
 
88
    connect(wg_Connection, SIGNAL(sig_Status(int)), this, SLOT(slot_ConnectionStatus(int)));
89
    connect(wg_Connection, SIGNAL(sig_MK_Version(s_Hardware)), this, SLOT(slot_MK_Version(s_Hardware)));
90
    connect(wg_Connection, SIGNAL(sig_MK_Debug(s_MK_Debug)), this, SLOT(slot_MK_Debug(s_MK_Debug)));
91
    connect(wg_Connection, SIGNAL(sig_MK_DebugLabels(s_MK_DebugLabels)), this, SLOT(slot_MK_DebugLabels(s_MK_DebugLabels)));
674 KeyOz 92
}
93
 
94
void dlg_Main::init_Plotter()
95
{
96
    NextPlot = 0;
97
 
98
    qwt_Plotter->setCanvasBackground(QColor(QRgb(0x00000000)));
99
 
801 - 100
//    qwt_Plotter->insertLegend(new QwtLegend(), QwtPlot::RightLegend);
674 KeyOz 101
 
102
    QwtPlotGrid *Grid = new QwtPlotGrid();
103
    Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
104
 
105
    Grid->attach(qwt_Plotter);
106
 
107
    qwt_Plotter->setAxisScale(QwtPlot::xBottom,0,o_Settings->DATA.Plotter_Count,0);
108
 
109
    for (int a = 0; a < MAX_DebugData; a++)
110
    {
111
        Plot[a] = new QwtPlotCurve(o_Settings->DebugData.Label[a]);
112
        Plot[a]->setPen(QPen(QColor(DEF_DebugColors[a])));
113
        Plot[a]->setRenderHint(QwtPlotItem::RenderAntialiased);
114
 
115
        if (o_Settings->DebugData.Show_Plotter[a])
116
            Plot[a]->attach(qwt_Plotter);
117
    }
118
    qwt_Plotter->replot();
801 - 119
 
120
 
674 KeyOz 121
}
122
 
123
void dlg_Main::update_Plotter()
124
{
125
    pl_ID[NextPlot] = NextPlot;
126
 
127
    for (int a = 0; a < MAX_DebugData; a++)
128
    {
129
        pl_Data[a][NextPlot] = Debug_Data[a];
130
        Plot[a]->setData(pl_ID,pl_Data[a],NextPlot);
131
    }
132
 
133
    NextPlot++;
134
 
135
    if ((NextPlot > o_Settings->DATA.Plotter_Count))
136
    {
137
        Plotter_Scroll->setMaximum(NextPlot - o_Settings->DATA.Plotter_Count);
138
    }
139
 
140
    if ((Plotter_Scroll->value() == NextPlot - (o_Settings->DATA.Plotter_Count + 1)))
141
    {
142
        qwt_Plotter->setAxisScale(QwtPlot::xBottom,NextPlot - o_Settings->DATA.Plotter_Count,NextPlot,0);
143
        Plotter_Scroll->setValue(NextPlot - o_Settings->DATA.Plotter_Count);
144
    }
145
 
146
    qwt_Plotter->replot();
147
}
148
 
149
void dlg_Main::config_Plotter()
150
{
151
    qwt_Plotter->setAxisScale(QwtPlot::xBottom,0,o_Settings->DATA.Plotter_Count,0);
152
 
153
    for (int a = 0; a < MAX_DebugData; a++)
154
    {
155
        Plot[a]->detach();
156
        Plot[a]->setPen(QPen(QColor(DEF_DebugColors[a])));
157
 
158
        if (o_Settings->DebugData.Show_Plotter[a])
159
        {
801 - 160
//            Plot[a]->setTitle(o_Settings->DebugData.Label[a]);
674 KeyOz 161
            Plot[a]->attach(qwt_Plotter);
162
        }
163
    }
164
    qwt_Plotter->replot();
165
}
166
 
167
void dlg_Main::slot_Plotter_Scroll(int Position)
168
{
169
    qwt_Plotter->setAxisScale(QwtPlot::xBottom,Position,Position + o_Settings->DATA.Plotter_Count,0);
170
    qwt_Plotter->replot();
171
}
172
 
750 KeyOz 173
///////////
174
// Slots //
175
///////////
176
 
177
// About-Dialog
178
void dlg_Main::slot_ac_About()
674 KeyOz 179
{
750 KeyOz 180
    QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT);
181
}
674 KeyOz 182
 
750 KeyOz 183
void dlg_Main::slot_ConnectionStatus(int li_Status)
184
{
185
    if (li_Status)
674 KeyOz 186
    {
750 KeyOz 187
        ac_Connect->setChecked(true);
188
        ac_Connect->setText(tr("Trennen"));
189
    }
190
    else
191
    {
192
        ac_Connect->setChecked(false);
193
        ac_Connect->setText(tr("Verbinden"));
194
    }
195
}
674 KeyOz 196
 
750 KeyOz 197
void dlg_Main::slot_MK_Version(s_Hardware ls_Version)
198
{
199
    gs_Version = ls_Version;
200
    setWindowTitle(QA_NAME + " " + QA_VERSION + " - " + ls_Version.Hardware + " " + ls_Version.Version);
711 KeyOz 201
 
750 KeyOz 202
    o_Settings->read_DebugLabels(gs_Version.ID);
711 KeyOz 203
 
750 KeyOz 204
    if (o_Settings->DebugData.Version != gs_Version.Version)
205
    {
206
        qDebug(QString("Debug-Labels unterschiedlich. Neue anforden. " + o_Settings->DebugData.Version + " <> " + gs_Version.Version).toLatin1().data());
207
        usleep(50000);
711 KeyOz 208
 
750 KeyOz 209
        slot_ac_ReadLabels();
210
    }
211
    else
212
    {
213
        for(int z = 0; z < MAX_DebugData; z++)
214
        {
801 - 215
            wg_Index[z]->set_Name(o_Settings->DebugData.Label[z]);
216
            wg_Index[z]->set_Checked(o_Settings->DebugData.Show_Plotter[z]);
217
 
674 KeyOz 218
        }
750 KeyOz 219
        config_Plotter();
674 KeyOz 220
    }
221
}
222
 
750 KeyOz 223
void dlg_Main::slot_MK_Debug(s_MK_Debug ls_Debug)
674 KeyOz 224
{
750 KeyOz 225
    gs_Debug = ls_Debug;
674 KeyOz 226
 
750 KeyOz 227
    for (int z = 0; z < MAX_DebugData; z++)
674 KeyOz 228
    {
750 KeyOz 229
        Debug_Data[z] = ls_Debug.Analog[z];
801 - 230
 
231
        wg_Index[z]->set_Wert(QString("%1").arg(Debug_Data[z]));
750 KeyOz 232
    }
233
    if (btn_Start->isChecked())
234
    {
235
       update_Plotter();
236
    }
237
}
674 KeyOz 238
 
750 KeyOz 239
void dlg_Main::slot_MK_DebugLabels(s_MK_DebugLabels MK_DebugLabels)
240
{
241
    if (MK_DebugLabels.Position < 32)
242
    {
243
        o_Settings->DebugData.Label[MK_DebugLabels.Position] = MK_DebugLabels.Text;
244
        if (o_Settings->DebugData.Label[MK_DebugLabels.Position] == "")
245
        {
246
            o_Settings->DebugData.Label[MK_DebugLabels.Position] = "Debug-" + QString("%1").arg(MK_DebugLabels.Position);
247
        }
801 - 248
//        cb_Debug[MK_DebugLabels.Position]->setText("" + o_Settings->DebugData.Label[MK_DebugLabels.Position]);
249
        wg_Index[MK_DebugLabels.Position]->set_Name("" + o_Settings->DebugData.Label[MK_DebugLabels.Position]);
250
//        wg_Index[z]->set_Checked(o_Settings->DebugData.Show_Plotter[z]);
674 KeyOz 251
 
801 - 252
 
674 KeyOz 253
    }
750 KeyOz 254
    if (MK_DebugLabels.Position == 31)
255
    {
256
        o_Settings->DebugData.Version = gs_Version.Version;
257
        o_Settings->write_DebugLabels(gs_Version.ID);
258
        config_Plotter();
259
    }
674 KeyOz 260
}
261
 
262
void dlg_Main::slot_Plotter_Start()
263
{
264
    if (btn_Start->isChecked())
265
    {
266
        btn_Start->setText(tr("Plotter stoppen"));
267
    }
268
    else
269
    {
270
        btn_Start->setText(tr("Plotter starten"));
271
    }
272
}
273
 
274
void dlg_Main::slot_btn_ChoseOK()
275
{
276
    for(int z = 0; z < MAX_DebugData; z++)
277
    {
801 - 278
        o_Settings->DebugData.Show_Plotter[z] = wg_Index[z]->get_Checked();
674 KeyOz 279
    }
280
    config_Plotter();
750 KeyOz 281
    o_Settings->write_DebugLabels(gs_Version.ID);
674 KeyOz 282
}
283
 
284
void dlg_Main::slot_ac_ReadLabels()
285
{
286
    c_Data[0] = 0;
750 KeyOz 287
    wg_Connection->send_Data(HandlerMK::make_Frame('a', ADDRESS_ALL, c_Data, 1).toLatin1().data(), DATA_READ_LABEL);
674 KeyOz 288
}
289
 
290
// Programm Ende
291
dlg_Main::~dlg_Main()
292
{
293
    o_Settings->GUI.isMax       = isMaximized();
294
    o_Settings->GUI.Size        = size();
295
    o_Settings->GUI.Point       = pos();
296
 
297
    o_Settings->write_Settings();
298
}