Subversion Repositories Projects

Rev

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

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