1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
|
/*
* Copyright (C) 2016 Dhiraj Salian
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
*/
#include "OpenSkyPlanetarium.hpp"
#include "OSPMainDialog.hpp"
#include "ui_OSPMainDialog.h"
#include "Calibrate.hpp"
#include "StelApp.hpp"
#include "StelLocaleMgr.hpp"
#include "StelModule.hpp"
#include "StelModuleMgr.hpp"
#include "StelObjectMgr.hpp"
#include "StelUtils.hpp"
#include "StelFileMgr.hpp"
#include "StarMgr.hpp"
#include "StelAudioMgr.hpp"
#include "StelObjectMgr.hpp"
#include <QMediaPlayer>
#include <QCompleter>
#include <QFileDialog>
#include <QFile>
#include <QInputDialog>
#include <QException>
#include <QRegExp>
#include <QRegExpValidator>
#include <QList>
#include <QMessageBox>
#include <QWidget>
#include <QByteArray>
#include <QDateTime>
#include <QCoreApplication>
OSPMainDialog::OSPMainDialog()
{
ui = new Ui_OSPMainDialog();
calMode = false;
nRef = 0;
moduleDirectoryPath = StelFileMgr::getUserDir() + "/modules/OpenSkyPlanetarium";
if(!StelFileMgr::exists(moduleDirectoryPath)){
StelFileMgr::mkDir(moduleDirectoryPath);
}
scriptDirectoryPath = StelFileMgr::getUserDir() + "/modules/OpenSkyPlanetarium/script";
if(!StelFileMgr::exists(scriptDirectoryPath)){
StelFileMgr::mkDir(scriptDirectoryPath);
}
audioDirectoryPath = StelFileMgr::getUserDir() + "/modules/OpenSkyPlanetarium/audio";
if(!StelFileMgr::exists(audioDirectoryPath)){
StelFileMgr::mkDir(audioDirectoryPath);
}
// Objects Initialization
player = new QMediaPlayer();
playlist = new QMediaPlaylist();
volumeSlider = new QAbstractSlider();
player->setPlaylist(playlist);
player->setVolume(50);
playerState = QMediaPlayer::StoppedState;
remtim = 0;
}
OSPMainDialog::~OSPMainDialog()
{
//qDebug()<<"Closing Window"<<endl;
//device.closeWindow();
delete ui;
}
void OSPMainDialog::retranslate()
{
if (dialog)
{
ui->retranslateUi(dialog);
}
}
void OSPMainDialog::createDialogContent()
{
ui->setupUi(dialog);
ui->tabWidg->setCurrentIndex(2);
setSignals();
connect(&StelApp::getInstance(), SIGNAL(languageChanged()), this, SLOT(retranslate()));
connect(ui->closeStelWindow, SIGNAL(clicked()), this, SLOT(closeWin()));
}
/*
setSignals():
THis function connects the various gui signals to its corresponding slots
this function is called in the createDialogContent() function of this classs
*/
void OSPMainDialog :: setSignals(){
//Setting signals for the laser movements
connect(ui->mvUp,SIGNAL(pressed()),this,SLOT(upPressed()));
connect(ui->mvDown,SIGNAL(pressed()),this,SLOT(downPressed()));
connect(ui->mvLeft,SIGNAL(pressed()),this,SLOT(leftPressed()));
connect(ui->mvRight,SIGNAL(pressed()),this,SLOT(rightPressed()));
connect(ui->mvUp,SIGNAL(released()),this,SLOT(arrow_released()));
connect(ui->mvDown,SIGNAL(released()),this,SLOT(arrow_released()));
connect(ui->mvRight,SIGNAL(released()),this,SLOT(arrow_released()));
connect(ui->mvLeft,SIGNAL(released()),this,SLOT(arrow_released()));
connect(ui->reset,SIGNAL(clicked()),this,SLOT(reset()));
//Connecting LaserDev signals to their respective slots
connect(&device,SIGNAL(debug_send(QString)),this,SLOT(debug_received(QString)));
connect(&device,SIGNAL(pos_received(QString,QString)),this,SLOT(pos_received(QString,QString)));
//Device connection and Calibration buttons
connect(ui->selectDev,SIGNAL(clicked()),this,SLOT(selectDevice()));
connect(ui->startCal,SIGNAL(clicked()),this,SLOT(initDevice()));
//LASER on/off
connect(ui->laserOn,SIGNAL(clicked()),this,SLOT(laserToggled()));
connect(ui->laserOff,SIGNAL(clicked()),this,SLOT(laserToggled()));
connect(ui->intensity,SIGNAL(valueChanged(int)),this,SLOT(setIntensity(int)));
// Motor speed control
connect(ui->CoarseAdj,SIGNAL(clicked()),this,SLOT(adjToggled()));
connect(ui->FineAdj,SIGNAL(clicked()),this,SLOT(adjToggled()));
//setReference and goTo button
connect(ui->setRef,SIGNAL(clicked()),this,SLOT(setReference()));
connect(ui->goTo,SIGNAL(clicked()),this,SLOT(goTo()));
//script engine buttons
connect(ui->compScript,SIGNAL(clicked()),this,SLOT(compileScript()));
connect(ui->openScript,SIGNAL(clicked()),this,SLOT(openScript()));
connect(ui->saveScript,SIGNAL(clicked()),this,SLOT(saveScript()));
connect(ui->execScript,SIGNAL(clicked()),this,SLOT(execScript()));
//scriptEngine Command Buttons
connect(ui->gt,SIGNAL(clicked()),this,SLOT(gt()));
connect(ui->pl,SIGNAL(clicked()),this,SLOT(pl()));
connect(ui->wt,SIGNAL(clicked()),this,SLOT(wt()));
connect(ui->lo,SIGNAL(clicked()),this,SLOT(lo()));
//all emit signals for our scriptEngine connected to their respective functions
connect(this,SIGNAL(comGOTO(QString,QString)),this,SLOT(move(QString,QString)));
connect(this,SIGNAL(comTURN(bool)),this,SLOT(laser(bool)));
connect(this,SIGNAL(comPLAY(QString)),this,SLOT(playAudio(QString)));
connect(this,SIGNAL(comWAIT(int,int)),this,SLOT(waitforsec(int,int)));
//Signals for audio
connect(ui->playui,SIGNAL(clicked()),this,SLOT(playClicked()));
connect(ui->stopui,SIGNAL(clicked()),this,SLOT(stopClick()));
connect(ui->volumeChanged,SIGNAL(sliderMoved(int)),this,SLOT(setVolume(int)));
connect(this,SIGNAL(play()),player,SLOT(play()));
connect(this,SIGNAL(pause()),player,SLOT(pause()));
connect(this,SIGNAL(stop()),player,SLOT(stop()));
}
/*
/////////////////////////////////////User Defined Functions and Slots//////////////////////////////////////
All the required functions and slots for the gui written below
*/
///////////////////////////////////////////////Programmer helper slots////////////////////////////////////////////
/*
debug_received():
Connected to many signals for debugging purpose
*/
void OSPMainDialog :: debug_received(QString s){
qDebug() << "[OpenSkyPlanetarium] __debug__"<<s;
}
/*
pos_received():
This slot is called when the laser device sends us the coordinates
The coordinates are then used for setting the references in transformation matrix
*/
void OSPMainDialog :: pos_received(QString x,QString y){
qDebug() << "Printing X and Y = ["<<x <<","<<y<<"]";
acTemp = x;
altTemp = y;
double l=x.toDouble()*(180.0/3.14159);
double m=y.toDouble()*(180.0/3.14159);
QString s=QString::number(l);
QString t=QString::number(m);
ui->X->setText(s);
ui->Y->setText(t);
}
/*
showMessage(QString):
this function is called to display error/information messages
*/
void OSPMainDialog :: showMessage(QString m){
QMessageBox msgBox;
msgBox.setWindowTitle("OpenSkyPlanetarium");
msgBox.setText(m);
msgBox.exec();
}
//////////////////////////////////////////DEvice RElated slots////////////////////////////////////////////////////////////////////////////
/*
initDevice():
This function initiates the arduino device i-e:Counts the no. of steps and sets device's postion .
This function is connected to "Start Calibration" (startCal) button of the gui
*/
void OSPMainDialog :: initDevice(){
nRef=0;
QDateTime dt = QDateTime::currentDateTime();
double time = StelUtils::hmsToRad (dt.time().hour(), dt.time().minute(), dt.time().second());
calib.setTime(time);
qDebug() << "t0 =["<<time<<"] //Initial time";
device.init();
ui->setRef->setEnabled(true);
ui->goTo->setEnabled(false);
ui->execScript->setEnabled(true); //change after testing to false
ui->mvUp->setEnabled(true);
ui->mvLeft->setEnabled(true);
ui->mvDown->setEnabled(true);
ui->mvRight->setEnabled(true);
ui->reset->setEnabled(true);
ui->refStat->setText("0/3");
}
/*
selectDevice():
this slot is connected to the selectDev button of the gui
this slot shows a list of connected device to select from
after selection enables many buttons
*/
void OSPMainDialog :: selectDevice(){
nRef=0;
QStringList itemsList;
bool ok;
foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
itemsList.append(info.portName());
portName = QInputDialog::getItem(NULL, "Open Sky Planetarium","Select Device:",itemsList, 0, false, &ok);
device.setPortName(portName);
if (ok && !portName.isEmpty()){
ui->mvUp->setEnabled(false);
ui->mvDown->setEnabled(false);
ui->mvRight->setEnabled(false);
ui->mvLeft->setEnabled(false);
ui->selectDev->setEnabled(true);
ui->startCal->setEnabled(true);
ui->reset->setEnabled(false);
ui->setRef->setEnabled(false);
ui->goTo->setEnabled(false);
ui->execScript->setEnabled(true); //change after testing to false
ui->laserOn->setEnabled(true);
ui->laserOff->setEnabled(true);
ui->CoarseAdj->setEnabled(true);
ui->FineAdj->setEnabled(true);
ui->refStat->setText("0/3");
}
else{
showMessage("Please select the device");
}
}
/*
arrow_released():
this function is called when the Up(mvUp), Down(mvDown), Right(mvRight) and Left(mvLeft) button is released
this function sends the stop command to the arduino device to stop its movement along any of the four directions
*/
void OSPMainDialog :: arrow_released(){
device.stop();
}
/*
upPressed(), downPressed(), rightPressed(), leftPressed():
these functions are called when the buttons Up(mvUp), Down(mvDown), Right(mvRight) and Left(mvLeft) is pressed
these functions send appropriate move signals to the arduino device
*/
void OSPMainDialog :: upPressed(){
device.movy(1);
}
void OSPMainDialog :: downPressed(){
device.movy(0);
}
void OSPMainDialog :: rightPressed(){
device.movx(1);
}
void OSPMainDialog :: leftPressed(){
device.movx(0);
}
/*
reset():
this function is called when the reset button is clicked.
this function calls move(0,0) and takes the laser to the initial coordinates.
*/
void OSPMainDialog ::reset(){
//this->initDevice();
device.resetAll();
QString val="0.000000";
ui->X->setText(val);
ui->Y->setText(val);
}
/*
laserToggled():
this slot is connected to the laser turnOn/turnOff radioButtons of the gui
*/
void OSPMainDialog :: laserToggled(){
if (ui->laserOn->isChecked()){
device.laserOn();
ui->intensity->setEnabled(true);
qDebug() << "[OpenSkyPlanetarium]:Turning LASER on" << endl;
}
else{
ui->intensity->setEnabled(false);
// ui->intensity->setSliderPosition(50);
device.laserOff();
qDebug() << "[OpenSkyPlanetarium]:Turning LASER off" << endl;
}
}
/*
closeWin():
this slot is connected to the close button of the gui
*/
void OSPMainDialog :: closeWin(){
debug_received("closing window");
device.closeWindow();
close();
}
///////////////////////////////////Calibration Related SLots/////////////////////////////////////////////////////////////////////////
/*
setIntensity():
this function is connected to the laser intensity control slider of the gui
*/
void OSPMainDialog :: setIntensity(int x){
int l=ui->intensity->value();
device.setIntensity(l);
qDebug() << "[OpenSkyPlanetarium]:Changing intensity" << endl;
}
/*
adjToggled():
this slot is connected to the motor speed control radio buttons of the gui
*/
void OSPMainDialog :: adjToggled(){
if (ui->CoarseAdj->isChecked()){
device.CoarseAdj();
qDebug() << "[OpenSkyPlanetarium]:High Speed ON" << endl;
}
else{
device.FineAdj();
qDebug() << "[OpenSkyPlanetarium]:Low Speed ON" << endl;
}
}
/*
setReference():
this function sets three references for the matrix transformation
basically it sends three references for matrix transformation to the device for its calculations
*/
void OSPMainDialog :: setReference(){
nRef++;
QString sRef;
double dec = 0,ra = 0;
QDateTime dt = QDateTime::currentDateTime();
double time = StelUtils::hmsToRad (dt.time().hour(), dt.time().minute(), dt.time().second());
const QList<StelObjectP>& selected = GETSTELMODULE(StelObjectMgr)->getSelectedObject();
if(nRef>3)
{
nRef=3;
ui->setRef->setEnabled(false);
}
if (!selected.isEmpty()) {
StelUtils::rectToSphe(&ra,&dec,selected[0]->getEquinoxEquatorialPos(StelApp::getInstance().getCore()));
osp_ra=ra - 3.14159;
osp_dec=dec;
osp_time=time;
qDebug() << "Star = ["<<osp_time <<"," <<osp_ra <<"," <<osp_dec<<"]";
double ac,alt;
switch(nRef){
case 1:
device.getPos();
ac = acTemp.toDouble();
alt = altTemp.toDouble();
calib.setRef_1(osp_ra,osp_dec,osp_time,ac,alt);
showMessage(QString("First reference point has been set\n az = %1; alt = %2").arg(ac).arg(alt));
break;
case 2:
device.getPos();
ac = acTemp.toDouble();
alt = altTemp.toDouble();
calib.setRef_2(osp_ra,osp_dec,osp_time,ac,alt);
ui->goTo->setEnabled(true);
ui->execScript->setEnabled(true);
showMessage(QString("Second reference point has been set\n az = %1; alt = %2").arg(ac).arg(alt));
//showMessage("Second reference point has been set");
break;
case 3:
device.getPos();
ac = acTemp.toDouble();
alt = altTemp.toDouble();
calib.setRef_3(osp_ra,osp_dec,osp_time,ac,alt);
ui->setRef->setEnabled(false);
ui->goTo->setEnabled(true);
ui->execScript->setEnabled(true);
ui->mvDown->setEnabled(false);
ui->mvUp->setEnabled(false);
ui->mvRight->setEnabled(false);
ui->mvLeft->setEnabled(false);
showMessage(QString("Third reference point has been set\n az = %1; alt = %2").arg(ac).arg(alt));
//showMessage("Third reference point has been set");
break;
}
sRef.setNum(nRef);
ui->refStat->setText(sRef+"/3");
}
else{
showMessage("Please select a star to set as a Reference");
}
}
/*
goTo():
This function sends the coordinates from stellarium to device so that the laser could point the star
this function is enabled only after calibration is performed
*/
void OSPMainDialog :: goTo(){
QString sora,sodec,snra,sndec,sac,salt; //for testing purpose
double dec=0,ra=0,ac=0,alt=0;
QDateTime dt = QDateTime::currentDateTime();
double time = StelUtils::hmsToRad (dt.time().hour(), dt.time().minute(), dt.time().second());
const QList<StelObjectP>& selected = GETSTELMODULE(StelObjectMgr)->getSelectedObject();
if (!selected.isEmpty()) {
StelUtils::rectToSphe(&ra,&dec,selected[0]->getEquinoxEquatorialPos(StelApp::getInstance().getCore()));
}
qDebug() << "[goto_star_ra,dec,time]:"<<ra <<"," <<dec <<"," <<time;
calib.getHCoords(ra-3.14159,dec,time,&ac,&alt);
salt.setNum(alt); //for testing purpose
sac.setNum(ac); //for testing purpose
sora.setNum(3.14159+ra); //for testing purpose
sodec.setNum(dec); //for testing purpose
calib.getECoords(ac,alt,time,&ra,&dec); //for testing purpose
snra.setNum(ra); //for testing purpose
sndec.setNum(dec); //for testing purpose
showMessage(QString("Old ra/dec = %1/%2 ; New ra/dec = %3/%4 ; LASER Coordinates = %5/%6").arg(sora).arg(sodec).arg(snra).arg(sndec).arg(sac).arg(salt)); //for testing purpose
device.move(ac,alt);
double xo=ac*(180.0/3.14159);
double yo=alt*(180.0/3.14159);
QString s=QString::number(xo);
QString t=QString::number(yo);
ui->X->setText(s);
ui->Y->setText(t);
qDebug() << "[goto_telescope_ac,alt]:"<<ac <<"," <<alt;
}
/*
openScript():
This function opens an existing file if present in the script directory of our module
*/
void OSPMainDialog :: openScript(){
QString fileName = QFileDialog::getOpenFileName(NULL,QString("Open Script"), scriptDirectoryPath,QString("Script Files (*.osp)"));
if(!fileName.isNull()){
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
showMessage("File Not Accessible");
return;
}
ui->scriptEdit->setText(file.readAll());
file.close();
}
}
/*
saveScript():
This function is used to save the script
*/
void OSPMainDialog :: saveScript(){
if(!ui->scriptEdit->toPlainText().isEmpty()){
QString fileName = QFileDialog::getSaveFileName(NULL,QString("Save Script"), scriptDirectoryPath,QString("Script Files (*.osp)"));
if(!fileName.isNull()){
QFile file(fileName+".osp");
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)){
showMessage("File Not Accessible");
return;
}
file.write(ui->scriptEdit->toPlainText().toLocal8Bit());
file.close();
}
}
}
/*
execScript():
This function is used to execute script
This function calls compile function before executing
*/
void OSPMainDialog :: execScript(){
compileScript();
if(buildStatus){
foreach(QString commands, commandsList){
QStringList com = commands.split("_");
if(com[0].compare("goto")==0){
qDebug()<<com;
emit comGOTO(com[1],com[2]);
}
else if(com[0].compare("wait")==0){
emit comWAIT(com[1].toInt(),com[2].toInt());
}
else if(com[0].compare("turn")==0){
if(com[1].compare("on")==0){
emit comTURN(true);
}
else{
emit comTURN(false);
}
}
else if(com[0].compare("play")==0){
emit comPLAY(com[1]);
}
}
}
}
/*
compileScript():
This function is used to compile script
this function maps the user script commands to the C++ functions
*/
void OSPMainDialog :: compileScript(){
QRegExp scriptExp("^([goto | wait | turn | play]{4})\\s*([\u0370-\u03FF0-9a-zA-Z\\.\\s]*)\\s*;$");
bool compileStatus = true,i;
int line_count=0;
commandsList.clear();
i = playlist->clear();
if(nRef<2)
{
compileStatus=false;
showMessage(QString("Please do the calibration"));
}
else{
foreach(QString w, ui->scriptEdit->toPlainText().split("\n")){
line_count++;
if(!scriptExp.exactMatch(w) && w.compare("")!=0){
compileStatus=false;
showMessage(QString("Syntax Error at line %1").arg(line_count));
}
else{
QStringList com_par=scriptExp.capturedTexts();
if(com_par[1].compare("goto")==0){
double ra=0.0,dec=0.0;
QString sra,sdec;
//Todo:add checks before going down
StelObjectP star = GETSTELMODULE(StelObjectMgr)->searchByNameI18n(com_par[2].trimmed());
if(!star.isNull()){
StelUtils::rectToSphe(&ra,&dec,star->getEquinoxEquatorialPos(StelApp::getInstance().getCore()));
sra.setNum(ra);
sdec.setNum(dec);
commandsList << QString("goto_"+sra+"_"+sdec);
qDebug()<<sra<<sdec;
}
else{
showMessage("Could not find the star with the given name");
}
}
else if(com_par[1].compare("turn")==0){
if(com_par[2].trimmed().compare("on")!=0 && com_par[2].trimmed().compare("off")!=0){
compileStatus=false;
showMessage(QString("The parameter for laser must be either 'on' or 'off' at line %1").arg(line_count));
break;
}
else{
commandsList << QString("turn_"+com_par[2].trimmed());
}
}
else if(com_par[1].compare("play")==0){
QFile f(QString(audioDirectoryPath+"/"+com_par[2].trimmed()));
if(!f.exists()){
compileStatus=false;
showMessage(QString("File not found in [{Stellarium User Directory}/modules/OpenSkyPlanetarium/audio/] at line %1").arg(line_count));
break;
}
else{
commandsList << QString("play_"+com_par[2].trimmed());
}
}
else if(com_par[1].compare("wait")==0){
QRegExp a("([1-5]?[0-9])\\s*m\\s*([1-5]?[0-9])\\s*s");
if(!a.exactMatch(com_par[2].trimmed())){
showMessage(QString("(X)m(Y)s format expected as argument for wait at line %1").arg(line_count));
compileStatus=false;
break;
}
else{
QStringList temp = a.capturedTexts();
commandsList << QString("wait_"+temp[1].trimmed()+"_"+temp[2].trimmed());
}
}
}
}
}
if (!compileStatus){
commandsList.clear();
}
else{
//showMessage("Build Successful");
}
buildStatus=compileStatus;
}
////////////////////////SLOTS FOR FUNCTIONS TO BE CALLED WHILE EXECUTION OF SCRIPT///////////////////////////////////////////
/*
move(QString,QString):
This is slot connected to goto command from our script engine
It takes ra/dec of star as its parameters and converts them to move
*/
void OSPMainDialog :: move(QString x,QString y){
qDebug() << "Moveto X and Y = ["<<x <<","<<y<<"]";
double ra,dec,ac,alt;
ra=x.toDouble();
dec=y.toDouble();
QDateTime dt = QDateTime::currentDateTime();
double time = StelUtils::hmsToRad (dt.time().hour(), dt.time().minute(), dt.time().second());
calib.getHCoords(ra - 3.14159,dec,time,&ac,&alt);
device.move(ac,alt);
}
/*
laser(bool):
This is a slot for our script engine emit signal comTURN
This is used when playing the script
*/
void OSPMainDialog :: laser(bool stat){
if(stat){
device.laserOn();
ui->laserOn->setChecked(true);
ui->laserOff->setChecked(false);
}
else{
device.laserOff();
ui->laserOff->setChecked(true);
ui->laserOn->setChecked(false);
}
}
/*
waitforsec(int,int):
this is used when playing the script
this is used to give wait functionality in the script
*/
void OSPMainDialog :: waitforsec(int min,int sec){
dieTime = QTime::currentTime().addSecs(min*60 + sec);
qDebug()<<"Current Time"<<QTime::currentTime();
qDebug()<<"before While"<<dieTime;
while( QTime::currentTime() < dieTime || playerState == QMediaPlayer::PausedState)
{
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
qDebug()<<"remTim"<<remtim;
qDebug()<<"After while"<<dieTime;
}
/*
playAudio(QString):
This function is used to play audio files
This is used to give play Audio functionality in our script
*/
void OSPMainDialog :: playAudio(QString fname){
playlist->addMedia(QUrl::fromLocalFile(QString(audioDirectoryPath+QString("/")+fname)));
emit play();
ui->playui->setEnabled(true);
ui->playui->setText(QString("Pause"));
playerState = QMediaPlayer::PlayingState;
}
//////////////////////////////////////////////////////////////////SLOTS FOR SCRIPT ENGINE COMMAND BUTTONS///////////////////////////////
/*
gt():
This slot is connected to Goto Button of the Script Engine
Adds the goto command to your script
*/
void OSPMainDialog :: gt(){
QString sra,sdec;
const QList<StelObjectP>& selected = GETSTELMODULE(StelObjectMgr)->getSelectedObject();
if (!selected.isEmpty()) {
double dec_equinox = 0;
double ra_equinox = 0;
StelUtils::rectToSphe(&ra_equinox,&dec_equinox,selected[0]->getEquinoxEquatorialPos(StelApp::getInstance().getCore()));
ui->scriptEdit->setText(ui->scriptEdit->toPlainText().append(QString("goto %1;\n").arg(selected[0]->getNameI18n())));
}
else {
showMessage("Please select an object first");
}
}
/*
pl():
This slot is connected to Play Button of the Script Engine
Adds the play audio command to your script
*/
void OSPMainDialog :: pl(){
QString fileName = QFileDialog::getOpenFileName(NULL,QString("Select Audio File"), audioDirectoryPath,QString("Audio Files (*.wav)"));
if (!fileName.isNull()){
QFileInfo f(fileName);
ui->scriptEdit->setText(ui->scriptEdit->toPlainText().append(QString("play %1;\n").arg(f.fileName())));
}
else{
showMessage("Please select the audio file");
}
}
/*
lo():
This slot is connected to laser on/off button of the Script Engine
Adds the laser on/off command to your script
*/
void OSPMainDialog :: lo(){
QStringList items;
items << "on"<<"off";
bool ok;
QString item = QInputDialog::getItem(NULL, "Open Sky Planetarium","Select State(on/off):", items, 0, false, &ok);
if (ok && !item.isEmpty()){
ui->scriptEdit->setText(ui->scriptEdit->toPlainText().append(QString("turn %1;\n").arg(item)));
}
else{
showMessage("Please select either on/off");
}
}
/*
wt():
This slot is connected to wait button of the Script Engine
Adds the wait command to your script
*/
void OSPMainDialog :: wt(){
bool ok;
QRegExp a("([1-5][0-9])\\s*m\\s*([1-5][0-9])\\s*s");
QString time = QInputDialog::getText(NULL,"Open Sky Planetarium","Enter time(in [X]m[Y]s):",QLineEdit::Normal,"", &ok);
if (ok && !time.isEmpty() && !a.exactMatch(time)){
ui->scriptEdit->setText(ui->scriptEdit->toPlainText().append(QString("wait %1;\n").arg(time)));
}
else{
showMessage("Please enter time in (X)m(Y)s format");
}
}
////////////////////// Media Functions /////////////////////////////
/*
setVolume(int):
This slot is connected to the volume slider of the Script Engine
Sets the volume for the player.
*/
void OSPMainDialog::setVolume(int volume)
{
player->setVolume(volume);
}
/*
stopClick():
This slot is connected to the stopui function of the Script Engine
Stops the player.
*/
void OSPMainDialog::stopClick()
{
playerState = QMediaPlayer::StoppedState;
ui->playui->setText(QString("Play"));
player->stop();
}
/*
playClicked():
This slot is connected to the playui function of the Script Engine
Play or pause the audio in the script engine.
*/
void OSPMainDialog::playClicked()
{
switch (playerState) {
case QMediaPlayer::StoppedState:
emit play();
emit execScript();
ui->playui->setText(QString("Pause"));
playerState = QMediaPlayer::PlayingState;
break;
case QMediaPlayer::PausedState:
emit play();
ui->playui->setText(QString("Pause"));
remtim = pauseWait.restart();
dieTime = dieTime.addMSecs(remtim);
playerState = QMediaPlayer::PlayingState;
break;
case QMediaPlayer::PlayingState:
emit pause();
pauseWait.start();
ui->playui->setText(QString("Play"));
playerState = QMediaPlayer::PausedState;
break;
}
}
|