source: BAORadio/libindi/libindi/BAOcontrol/baoqt.cpp @ 681

Last change on this file since 681 was 681, checked in by frichard, 12 years ago
File size: 13.6 KB
Line 
1#include <QtGui>
2#include "baoqt.h"
3#include "baocontrol.h"
4#include "ui_baoqt.h"
5
6
7
8BAOqt::BAOqt(QWidget *parent) :
9    QDialog(parent),
10    ui(new Ui::BAOqt)
11{
12    QPoint pointPos;
13   
14    RechercheOptimisation = false;
15
16    bao = new BAOcontrol();
17
18    dialog = new QDialog;
19
20    ui->setupUi(dialog);
21
22    pointPos.setX(1);
23    pointPos.setY(1);
24
25    dialog->move(pointPos);
26
27    dialog->show();
28
29    connect(ui->pushButtonPark, SIGNAL(clicked()), this, SLOT(on_pushButtonPark_clicked()));
30
31    connect(ui->pushButtonCommande, SIGNAL(clicked()), this, SLOT(on_pushButtonCommande_clicked()));
32
33    connect(ui->pushButtonAbort, SIGNAL(clicked()), this, SLOT(on_pushButtonAbort_clicked()));
34
35    connect(ui->pushButtonAzM, SIGNAL(clicked()), this, SLOT(on_pushButtonAzM_clicked()));
36
37    connect(ui->pushButtonAzP, SIGNAL(clicked()), this, SLOT(on_pushButtonAzP_clicked()));
38
39    connect(ui->pushButtonHaP, SIGNAL(clicked()), this, SLOT(on_pushButtonHaP_clicked()));
40
41    connect(ui->pushButtonHaM, SIGNAL(clicked()), this, SLOT(on_pushButtonHaM_clicked()));
42
43    connect(ui->pushButton1x, SIGNAL(clicked()), this, SLOT(on_pushButton1x_clicked()));
44
45    connect(ui->pushButton10x, SIGNAL(clicked()), this, SLOT(on_pushButton10x_clicked()));
46
47    connect(ui->pushButtonIP, SIGNAL(clicked()), this, SLOT(on_pushButtonIP_clicked()));
48
49    connect(ui->pushButtonChoisir, SIGNAL(clicked()), this, SLOT(on_pushButtonChoisir_clicked()));
50
51    connect(ui->pushButtonSelectionner, SIGNAL(clicked()), this, SLOT(on_pushButtonSelectionner_clicked()));
52
53    connect(ui->pushButtonValider, SIGNAL(clicked()), this, SLOT(on_pushButtonValider_clicked()));
54
55    connect(ui->pushButtonSauvegarder, SIGNAL(clicked()), this, SLOT(on_pushButtonSauvegarder_clicked()));
56
57    connect(ui->pushButtonReset, SIGNAL(clicked()), this, SLOT(on_pushButtonReset_clicked()));
58
59    connect(ui->pushButtonListe, SIGNAL(clicked()), this, SLOT(on_pushButtonListe_clicked()));
60
61    connect(ui->pushButtonMap, SIGNAL(clicked()), this, SLOT(on_pushButtonMap_clicked()));
62
63    connect(ui->pushButton1pt, SIGNAL(clicked()), this, SLOT(on_pushButton1pt_clicked()));
64
65    connect(ui->pushButtonGoto, SIGNAL(clicked()), this, SLOT(on_pushButtonGoto_clicked()));
66
67    connect(ui->pushButtonTo00, SIGNAL(clicked()), this, SLOT(on_pushButtonTo00_clicked()));
68
69    connect(ui->pushButtonScript, SIGNAL(clicked()), this, SLOT(on_pushButtonScript_clicked()));
70   
71    connect(ui->pushButtonCalculMatrices, SIGNAL(clicked()), this, SLOT(on_pushButtonCalculMatrices_clicked()));
72   
73    connect(ui->pushButtonOptGeom, SIGNAL(clicked()), this, SLOT(on_pushButtonOptGeom_clicked()));
74
75    DisableButtons(true);
76
77    ui->pushButton1x->setDown(false);
78    ui->pushButton10x->setDown(true);
79
80    timer = new QTimer(this);
81
82    connect(timer, SIGNAL(timeout()), this, SLOT(updateCaption()));
83
84    timer->start(100);
85
86    ui->lineEditIP->setText("127.0.0.1");
87}
88
89BAOqt::~BAOqt()
90{
91    delete ui;
92    delete dialog;
93    delete bao;
94
95    delete timer;
96}
97
98void BAOqt::DisableButtons(bool b)
99{
100    ui->pushButtonChoisir->setDisabled(b);
101
102    ui->pushButtonSelectionner->setDisabled(b);
103
104    ui->pushButtonValider->setDisabled(b);
105
106    ui->pushButtonSauvegarder->setDisabled(b);
107
108    ui->pushButtonReset->setDisabled(b);
109
110    ui->pushButtonListe->setDisabled(b);
111
112    ui->pushButtonMap->setDisabled(b);
113
114    ui->pushButton1pt->setDisabled(b);
115   
116    ui->pushButtonCalculMatrices->setDisabled(b);
117   
118    ui->pushButtonOptGeom->setDisabled(b);
119}
120
121void BAOqt::updateCaption()
122{
123    if (RechercheOptimisation) return;
124   
125    bao->thread_process();
126
127    const QString *var = new QString( bao->chaineDateHeure);
128
129    ui->lineStatus->setText(*var);
130
131    delete var;
132
133    // Affichage des messages venant du serveur indi_BAO et récupérés par la fonction LireReponse()
134    // Les messages d'erreurs sont affichés en rouge
135    ui->textEdit->clear();
136
137    for (int i=0; i<bao->lognum; i++)
138    {
139        if (i>bao->lognum-11)
140        {
141            if ((bao->logs[i].find("Err")!=string::npos)
142                    || (bao->logs[i].find("ALERTE")!=string::npos))
143            {
144                ui->textEdit->setTextColor(QColor(255,0,0));
145            }
146            else
147            {
148                ui->textEdit->setTextColor(QColor(0,0,0));
149            }
150
151            ui->textEdit->append(bao->logs[i].c_str());
152        }
153    }
154}
155
156void BAOqt::on_pushButtonPark_clicked()
157{
158    bao->DecodageEntreesUtilisateur("park");
159}
160
161void BAOqt::on_pushButtonAbort_clicked()
162{
163    bao->DecodageEntreesUtilisateur("abort");
164}
165
166void BAOqt::on_pushButtonCommande_clicked()
167{
168    QString chaine = ui->lineEditCommande->text();
169
170    bao->DecodageEntreesUtilisateur("send " + chaine.toStdString());
171}
172
173void BAOqt::on_pushButtonAzM_clicked()
174{
175    bao->AlignementDelta("-1", true);
176}
177
178void BAOqt::on_pushButtonAzP_clicked()
179{
180    bao->AlignementDelta("1", true);
181}
182
183void BAOqt::on_pushButtonHaM_clicked()
184{
185    bao->AlignementDelta("-1", false);
186}
187
188void BAOqt::on_pushButtonHaP_clicked()
189{
190    bao->AlignementDelta("1", false);
191}
192
193void BAOqt::on_pushButton1x_clicked()
194{
195    bao->VitesseAlignement(1);
196
197    ui->pushButton1x->setDown(true);
198    ui->pushButton10x->setDown(false);
199}
200
201void BAOqt::on_pushButton10x_clicked()
202{
203    bao->VitesseAlignement(10);
204
205    ui->pushButton1x->setDown(false);
206    ui->pushButton10x->setDown(true);
207}
208
209void BAOqt::on_pushButtonIP_clicked()
210{
211    QString chaine = ui->lineEditIP->text();
212
213    if (bao->SelectionIP(chaine.toStdString()))
214    {
215        QMessageBox::information(this, tr("Selection d'une antenne pour l'alignement"), tr("L'antenne indiquee est maintenant prete pour l'alignement."));
216
217        DisableButtons(false);
218    }
219    else
220    {
221        QMessageBox::information(this, tr("Selection d'une antenne pour l'alignement"), tr("Aucune antenne ne porte cette adresse IP !"));
222    }
223}
224
225void BAOqt::on_pushButtonChoisir_clicked()
226{
227    bao->AlignementAntenneIP(ui->lineEditIP->text().toStdString());
228
229    SelectStars selectstar;
230
231    stringstream os;
232
233    int NumListeEtoilesSelectionnees = 0;
234
235    for (int i=0; i<bao->numEtoiles; i++)
236    {
237        if ( bao->Etoiles[i].selectionnee )
238        {
239            os.str("");
240            os.width(20);
241            os << bao->Etoiles[i].nom;
242            os << " (" << bao->Etoiles[i].cons << "), ";
243            string c ="az=" + bao->DHMS(bao->Etoiles[i].az * N180divPi, false) + ",     ";
244            os << c.substr(0 ,17);
245            c= "ha=" + bao->DHMS(bao->Etoiles[i].ha * N180divPi, false) + ",     ";
246            os << c.substr(0, 17);
247            os << " magnitude=";
248            os << bao->Etoiles[i].mag;
249
250            selectstar.Noms[NumListeEtoilesSelectionnees++] = os.str();
251        }
252    }
253
254    selectstar.Num = NumListeEtoilesSelectionnees;
255
256    selectstar.UpdateDatas();
257
258    selectstar.exec();
259
260
261    int EtoileSelectionnee = selectstar.NumSelectionne;
262
263    if (EtoileSelectionnee != -1)
264    {
265        int NumListeEtoilesSelectionnees = 0;
266
267        for (int i=0; i<bao->numEtoiles; i++)
268        {
269            if ( bao->Etoiles[i].selectionnee )
270            {
271                if ( NumListeEtoilesSelectionnees == EtoileSelectionnee )
272                {
273                    ui->lineEditEtoileSelectionneeAD->setText(  QString( bao->DHMS(bao->Etoiles[i].ad * N180divPi, true ).c_str()) );
274                    ui->lineEditEtoileSelectionneeDec->setText( QString( bao->DHMS(bao->Etoiles[i].de * N180divPi, false).c_str()) );
275                    on_pushButtonSelectionner_clicked();
276                }
277
278                NumListeEtoilesSelectionnees++;
279            }
280        }
281    }
282}
283
284void BAOqt::on_pushButtonSelectionner_clicked()
285{
286    bao->Goto( ui->lineEditEtoileSelectionneeAD->text().toStdString(), ui->lineEditEtoileSelectionneeDec->text().toStdString(), bao->Transit, false);
287}
288
289void BAOqt::on_pushButtonValider_clicked()
290{
291    bao->ValidationAlignement();
292}
293
294void BAOqt::on_pushButtonSauvegarder_clicked()
295{
296    bao->SauvegardeAlignement();
297}
298
299void BAOqt::on_pushButtonReset_clicked()
300{
301    QMessageBox::StandardButton reply;
302
303    reply = QMessageBox::question(this, tr("Reset alignement"),
304                                  "Voulez-vous reinitialiser l'alignement de l'antenne ?",
305                                  QMessageBox::Yes | QMessageBox::No );
306
307    if (reply == QMessageBox::Yes) bao->ResetAlignement();
308}
309
310void BAOqt::on_pushButtonListe_clicked()
311{
312    Liste liste;
313
314    stringstream os;
315
316    int NumListeEtoilesSelectionnees = 0;
317
318    for (int i=0; i<bao->numEtoiles; i++)
319    {
320        if ( bao->Etoiles[i].selectionnee )
321        {
322            os.str("");
323            os.width(20);
324            os << bao->Etoiles[i].nom;
325            os << " (" << bao->Etoiles[i].cons << "), ";
326            string c ="az=" + bao->DHMS(bao->Etoiles[i].az * N180divPi, false) + ",     ";
327            os << c.substr(0 ,17);
328            c= "ha=" + bao->DHMS(bao->Etoiles[i].ha * N180divPi, false) + ",     ";
329            os << c.substr(0, 17);
330            os << " magnitude=";
331            os << bao->Etoiles[i].mag;
332
333            liste.Noms[NumListeEtoilesSelectionnees++] = os.str();
334        }
335    }
336
337    liste.Num = NumListeEtoilesSelectionnees;
338
339    liste.UpdateDatas();
340
341    liste.exec();
342}
343
344void BAOqt::on_pushButtonMap_clicked()
345{
346    Map map1;
347
348    string str = bao->DecodageEntreesUtilisateur("send C");
349
350    map1.Corrections = str;
351
352    map1.UpdateDatas();
353
354    map1.exec();
355}
356
357void BAOqt::on_pushButton1pt_clicked()
358{
359    static int etape = 1;
360
361    switch (etape)
362    {
363    case 1:
364    {
365        etape=2;
366
367        QMessageBox::information(this, tr("Alignement 1pt de l antenne"), tr("Choisissez un objet facile a pointer"));
368
369        on_pushButtonGoto_clicked();
370
371        QMessageBox::information(this, tr("Alignement 1pt de l antenne"), tr("Attendez la fin du pointage. Centrez l'objet dans le viseur et rappuyez sur le bouton 'alignement 1pt' pour terminer."));
372
373    };
374    break;
375
376    case 2:
377    {
378        etape=1;
379
380        QMessageBox::information(this, tr("Alignement 1pt de l antenne"), tr("Annulation du mouvement en cours."));
381
382        bao->Abort();
383
384        sleep(1);
385
386        string str = bao->DecodageEntreesUtilisateur("send X");
387
388        string str2;
389
390        int x = 0;
391        int y = 0;
392
393        char a1='b';
394        char a2='b';
395
396        size_t pos = str.find("/");
397
398        if (pos != string::npos)
399        {
400            str2 = str.substr(pos + 1);
401
402            pos = str2.find("/");
403
404            if (pos != string::npos)
405            {
406                x = atol( str2.substr(0, pos).c_str() );
407
408                y = atol( str2.substr(pos + 1).c_str() );
409            }
410        }
411
412        sleep(1);
413
414        str = bao->DecodageEntreesUtilisateur("send D");
415
416        int dx = 0;
417        int dy = 0;
418
419        pos = str.find("/");
420
421        if (pos != string::npos)
422        {
423            str2 = str.substr(pos + 1);
424
425            pos = str2.find("/");
426
427            if (pos != string::npos)
428            {
429                dx = atol( str2.substr(0, pos).c_str() );
430
431                x += dx;
432
433                dy = atol( str2.substr(pos + 1).c_str() );
434
435                y += dy;
436
437                if ( x < 0 ) {
438                    a1 = 'f';
439                    x = -x;
440                }
441
442                if ( y < 0 ) {
443                    a2 = 'f';
444                    y = -y;
445                }
446
447                char chaine[100];
448
449                sprintf(chaine, "send g%c%04d%c%04d", a1, x, a2, y);
450
451                str = bao->DecodageEntreesUtilisateur(string(chaine));
452
453                QMessageBox::information(this, tr("Alignement 1pt de l antenne"), tr("Appuyez sur les deux boutons places dans la boite de l'antenne."));
454               
455                 str = bao->DecodageEntreesUtilisateur("send p");
456               
457                QMessageBox::StandardButton reply;
458               
459                reply = QMessageBox::question(this, tr("Alignement 1pt de l antenne"),
460                                  "Voulez-vous reinitialiser les codeurs de l'antenne en envoyant la c ommande Park ?",
461                                  QMessageBox::Yes | QMessageBox::No );
462
463               if (reply == QMessageBox::Yes)
464               {
465
466                str = bao->DecodageEntreesUtilisateur("send z");
467
468                sleep(1);
469
470                str = bao->DecodageEntreesUtilisateur("send p");
471               }
472               QMessageBox::information(this, tr("Alignement 1pt de l antenne"), tr("Fin de la procedure."));
473            }
474        }
475    }
476    break;
477    }
478}
479
480
481void BAOqt::on_pushButtonGoto_clicked()
482{
483    bool ok;
484    QString text = QInputDialog::getText(this, tr("Goto"),
485                                         tr("Entrez le nom ou les coordonnees de l'objet a suivre"), QLineEdit::Normal,
486                                         "", &ok);
487    if (ok && !text.isEmpty())
488        bao->DecodageEntreesUtilisateur("goto " + text.toStdString());
489
490}
491
492void BAOqt::on_pushButtonTo00_clicked()
493{
494    string str = bao->DecodageEntreesUtilisateur("send X");
495
496    string str2;
497
498    int x = 0;
499    int y = 0;
500
501    size_t pos = str.find("/");
502
503    if (pos != string::npos)
504    {
505        str2 = str.substr(pos + 1);
506
507        pos = str2.find("/");
508
509        if (pos != string::npos)
510        {
511            char a1='b';
512            char a2='b';
513
514            x = atol( str2.substr(0, pos).c_str() );
515
516            if ( x < 0 ) {
517                a1 = 'f';
518                x = -x;
519            }
520
521            y = atol( str2.substr(pos + 1).c_str() );
522
523            if ( y < 0 ) {
524                a2 = 'f';
525                y = -y;
526            }
527
528            char chaine[100];
529
530            sprintf(chaine, "send g%c%04d%c%04d", a1, x, a2, y);
531
532            string str = bao->DecodageEntreesUtilisateur(string(chaine));
533        }
534    }
535}
536
537void BAOqt::on_pushButtonCalculMatrices_clicked()
538{
539   bao->DecodageEntreesUtilisateur("send m");
540}
541
542void BAOqt::on_pushButtonScript_clicked()
543{
544
545}
546
547void BAOqt::on_pushButtonOptGeom_clicked()
548{
549  RechercheOptimisation=true;
550 
551    bao->DecodageEntreesUtilisateur("send o");
552}
Note: See TracBrowser for help on using the repository browser.