diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/CMakeLists.txt | 39 | ||||
-rwxr-xr-x | src/Calibrate.cpp | 278 | ||||
-rwxr-xr-x | src/Calibrate.hpp | 204 | ||||
-rwxr-xr-x | src/Calibrate.hpp~ | 204 | ||||
-rwxr-xr-x | src/LaserDev.cpp | 307 | ||||
-rwxr-xr-x | src/LaserDev.hpp | 201 | ||||
-rwxr-xr-x | src/OpenSkyPlanetarium.cpp | 129 | ||||
-rwxr-xr-x | src/OpenSkyPlanetarium.hpp | 97 | ||||
-rwxr-xr-x | src/OpenSkyPlanetarium.hpp~ | 97 | ||||
-rwxr-xr-x | src/SerialCom.cpp | 120 | ||||
-rwxr-xr-x | src/SerialCom.cpp~ | 117 | ||||
-rwxr-xr-x | src/SerialCom.hpp | 84 | ||||
-rwxr-xr-x | src/SerialCom.hpp~ | 82 | ||||
-rwxr-xr-x | src/gui/OSPMainDialog.cpp | 838 | ||||
-rwxr-xr-x | src/gui/OSPMainDialog.hpp | 312 | ||||
-rwxr-xr-x | src/gui/OSPMainDialog.ui | 758 |
16 files changed, 3867 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100755 index 0000000..a117288 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,39 @@ +INCLUDE_DIRECTORIES(.) + +LINK_DIRECTORIES(${BUILD_DIR}/src) + +SET(OpenSkyPlanetarium_SRCS + OpenSkyPlanetarium.hpp + OpenSkyPlanetarium.cpp + LaserDev.hpp + LaserDev.cpp + Calibrate.hpp + Calibrate.cpp + SerialCom.hpp + SerialCom.cpp + gui/OSPMainDialog.hpp + gui/OSPMainDialog.cpp +) + +SET(OpenSkyPlanetarium_UIS + gui/OSPMainDialog.ui +) + +SET(OpenSkyPlanetarium_RES + ../OpenSkyPlanetarium.qrc +) +QT5_ADD_RESOURCES(OpenSkyPlanetarium_RES_CXX ${OpenSkyPlanetarium_RES}) + +# Wrapping UI +QT5_WRAP_UI(OpenSkyPlanetarium_UIS_H ${OpenSkyPlanetarium_UIS}) + + +# Library Properties +ADD_LIBRARY(OpenSkyPlanetarium-static MODULE +${OpenSkyPlanetarium_SRCS} ${OpenSkyPlanetarium_RES_CXX} +${OpenSkyPlanetarium_UIS_H}) +QT5_USE_MODULES(OpenSkyPlanetarium-static Core Gui Widgets Multimedia) +SET_TARGET_PROPERTIES(OpenSkyPlanetarium-static PROPERTIES OUTPUT_NAME +"OpenSkyPlanetarium" AUTOMOC TRUE COMPILE_FLAGS "-DQT_OSP") +TARGET_LINK_LIBRARIES(OpenSkyPlanetarium-static ${extLinkerOption}) + diff --git a/src/Calibrate.cpp b/src/Calibrate.cpp new file mode 100755 index 0000000..5e3aedc --- /dev/null +++ b/src/Calibrate.cpp @@ -0,0 +1,278 @@ +/* +The MIT License (MIT) + +Copyright (c) 2012 Juan Ramón + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "Calibrate.hpp" +#include <QMediaPlayer> +#include <QCompleter> +#include <QFileDialog> +#include <QFile> +#include <QDebug> +#include <QTextStream> +#include <QObject> +#include <QDebug> +#include <QString> +#include <QTime> +#include <QDateTime> +#include <QMessageBox> +#include <QInputDialog> +#include <QException> +#include <QRegExp> +#include <QRegExpValidator> +#include <QList> +#include <QMessageBox> +#include <QWidget> +#include <QByteArray> +#include <QDateTime> +#include <QCoreApplication> +#include <stdio.h> +Calibrate::Calibrate(){ + _t0 = 0; + _k = 1.002737908; // Constant.. Relationship between the solar time (M) and the sidereal time (S): (S = M * 1.002737908) + _isSetR1 = false; + _isSetR2 = false; + _isSetR3 = false; +} + +/* + * Calculates the inverse of the m[3x3] matrix and returns it in the second parameter. + */ +void Calibrate::_inv(double m[3][3], double res[3][3]){ + double idet; + + //Inverse of the determinant + idet = 1/( + (m[0][0]*m[1][1]*m[2][2]) + (m[0][1]*m[1][2]*m[2][0]) + (m[0][2]*m[1][0]*m[2][1]) + - (m[0][2]*m[1][1]*m[2][0]) - (m[0][1]*m[1][0]*m[2][2]) - (m[0][0]*m[1][2]*m[2][1]) + ); + + res[0][0] = ((m[1][1]*m[2][2]) - (m[2][1]*m[1][2]))*idet; + res[0][1] = ((m[2][1]*m[0][2]) - (m[0][1]*m[2][2]))*idet; + res[0][2] = ((m[0][1]*m[1][2]) - (m[1][1]*m[0][2]))*idet; + + res[1][0] = ((m[1][2]*m[2][0]) - (m[2][2]*m[1][0]))*idet; + res[1][1] = ((m[2][2]*m[0][0]) - (m[0][2]*m[2][0]))*idet; + res[1][2] = ((m[0][2]*m[1][0]) - (m[1][2]*m[0][0]))*idet; + + res[2][0] = ((m[1][0]*m[2][1]) - (m[2][0]*m[1][1]))*idet; + res[2][1] = ((m[2][0]*m[0][1]) - (m[0][0]*m[2][1]))*idet; + res[2][2] = ((m[0][0]*m[1][1]) - (m[1][0]*m[0][1]))*idet; +} + +/* + * Multiplies two matrices, m1[3x3] and m2[3x3], and returns the result in + * the third parameter. + */ +void Calibrate::_m_prod(double m1[3][3], double m2[3][3], double res[3][3]){ + for(int i=0; i<3; i++) + for(int j=0; j<3; j++){ + res[i][j] = 0.0; + for(int k=0; k<3; k++) //multiplying row by column + res[i][j] += m1[i][k] * m2[k][j]; + } +} + +/* + * Calculates the Vector cosines (EVC) from the equatorial coordinates (ar, dec, t). + */ +void Calibrate::_setEVC(double ar, double dec, double t, double* EVC){ + EVC[0] = cos(dec)*cos(ar - _k*(t-_t0)); + EVC[1] = cos(dec)*sin(ar - _k*(t-_t0)); + EVC[2] = sin(dec); + qDebug() << "ardec = ["<<ar <<"," <<dec<<"]"; + qDebug() << "LMN = ["<<EVC[0] <<"," <<EVC[1] <<"," <<EVC[2]<<"]"; +} + +/* + * Calculates the Vector cosines (HVC) from the horizontal coordinates (ac, alt). + */ +void Calibrate::_setHVC(double ac, double alt, double* HVC){ + HVC[0] = cos(alt)*cos(ac); + HVC[1] = cos(alt)*sin(ac); + HVC[2] = sin(alt); + qDebug() << "altac = ["<<alt <<"," <<ac<<"]"; + qDebug() << "clmn=["<<HVC[0] <<"," <<HVC[1] <<"," <<HVC[2]<<"]"; +} + +/* + * Sets the initial observation time. + */ +void Calibrate::setTime(double t0){ + _t0 = t0; +} + +/* + * Sets the first reference object. + * If all the reference objects have been established, calls the function that calculates T and iT. + */ +void Calibrate::setRef_1(double ar, double dec, double t, double ac, double alt){ + _setEVC(ar, dec, t, _LMN1); + _setHVC(ac, alt, _lmn1); + _isSetR1 = true; + _isSetR3 = false; + + if(_isSetR1 && _isSetR2 && _isSetR3) + _setT(); +} + +/* + * Sets the second reference object. + * If all the reference objects have been established, calls the function that calculates T and iT. + */ +void Calibrate::setRef_2(double ar, double dec, double t, double ac, double alt){ + _setEVC(ar, dec, t, _LMN2); + _setHVC(ac, alt, _lmn2); + _isSetR2 = true; + _isSetR3 = false; + + if(_isSetR1 && _isSetR2 && _isSetR3) + _setT(); +} + +/* + * Sets the third reference object. + * If all the reference objects have been established, calls the function that calculates T and iT. + */ +void Calibrate::setRef_3(double ar, double dec, double t, double ac, double alt){ + _setEVC(ar, dec, t, _LMN3); + _setHVC(ac, alt, _lmn3); + _isSetR3 = true; + + if(_isSetR1 && _isSetR2 && _isSetR3) + _setT(); +} + +/* + * Indicates if the three reference objects have been established. + */ +bool Calibrate::isConfigured(){ + return (_isSetR1 && _isSetR2 && _isSetR3); +} + +/* + * Third reference object calculated from the cross product of the two first ones. + * Then calls the function that calculates T and iT. + */ +void Calibrate::autoRef_3(){ + float sqrt1, sqrt2; + qDebug() << "inside autoref"; + _isSetR3 = true; + if(_isSetR1 && _isSetR2){ + sqrt1 = (1/( sqrt( pow(( (_lmn1[1]*_lmn2[2]) - (_lmn1[2]*_lmn2[1])),2) + + pow(( (_lmn1[2]*_lmn2[0]) - (_lmn1[0]*_lmn2[2])),2) + + pow(( (_lmn1[0]*_lmn2[1]) - (_lmn1[1]*_lmn2[0])),2)) + )); + _lmn3[0] = sqrt1 * ( (_lmn1[1]*_lmn2[2]) - (_lmn1[2]*_lmn2[1]) ); + _lmn3[1] = sqrt1 * ( (_lmn1[2]*_lmn2[0]) - (_lmn1[0]*_lmn2[2]) ); + _lmn3[2] = sqrt1 * ( (_lmn1[0]*_lmn2[1]) - (_lmn1[1]*_lmn2[0]) ); + + sqrt2 = (1/( sqrt( pow(( (_LMN1[1]*_LMN2[2]) - (_LMN1[2]*_LMN2[1])),2) + + pow(( (_LMN1[2]*_LMN2[0]) - (_LMN1[0]*_LMN2[2])),2) + + pow(( (_LMN1[0]*_LMN2[1]) - (_LMN1[1]*_LMN2[0])),2)) + )); + _LMN3[0] = sqrt2 * ( (_LMN1[1]*_LMN2[2]) - (_LMN1[2]*_LMN2[1]) ); + _LMN3[1] = sqrt2 * ( (_LMN1[2]*_LMN2[0]) - (_LMN1[0]*_LMN2[2]) ); + _LMN3[2] = sqrt2 * ( (_LMN1[0]*_LMN2[1]) - (_LMN1[1]*_LMN2[0]) ); + + if(_isSetR1 && _isSetR2 && _isSetR3) + _setT(); + } +} + +/* + * Sets the transformation matrix and its inverse (T and iT, respectively). + */ +void Calibrate::_setT(){ + double subT1[3][3], subT2[3][3], aux[3][3]; + + subT1[0][0] = _lmn1[0]; subT1[0][1] = _lmn2[0]; subT1[0][2] = _lmn3[0]; + subT1[1][0] = _lmn1[1]; subT1[1][1] = _lmn2[1]; subT1[1][2] = _lmn3[1]; + subT1[2][0] = _lmn1[2]; subT1[2][1] = _lmn2[2]; subT1[2][2] = _lmn3[2]; + + subT2[0][0] = _LMN1[0]; subT2[0][1] = _LMN2[0]; subT2[0][2] = _LMN3[0]; + subT2[1][0] = _LMN1[1]; subT2[1][1] = _LMN2[1]; subT2[1][2] = _LMN3[1]; + subT2[2][0] = _LMN1[2]; subT2[2][1] = _LMN2[2]; subT2[2][2] = _LMN3[2]; + + _inv(subT2, aux); + _m_prod(subT1, aux, _T); + _inv(_T, _iT); + qDebug() << "LMN3 = ["<<_LMN3[0] <<"," <<_LMN3[1] <<"," <<_LMN3[2]<<"]" ; + qDebug() << "lmn3 = ["<<_lmn3[0] <<"," <<_lmn3[1] <<"," <<_lmn3[2]<<"]" ; + qDebug() << "T1 = ["<<_T[0][0] <<"," <<_T[0][1] <<"," <<_T[0][2] <<"," <<_T[1][0] <<"," <<_T[1][1] <<"," <<_T[1][2] <<"," <<_T[2][0] <<"," <<_T[2][1] <<"," <<_T[2][2] <<"]" ; + //qDebug() << "iT = ["<<_iT[0][0] <<"," <<_iT[0][1] <<"," <<_iT[0][2] <<"," <<_iT[1][0] <<"," <<_iT[1][1] <<"," <<_iT[1][2] <<"," <<_iT[2][0] <<"," <<_iT[2][1] <<"," <<_iT[2][2] <<"]"; + +} + +/* + * Horizontal coordinates (ac, alt) obtained from equatorial ones and time (ar, dec, t). + * + * If the third reference object is not established, it calculates it by calling the + * proper function. + */ +void Calibrate::getHCoords(double ar, double dec, double t, double *ac, double *alt){ + double HVC[3]; + double EVC[3]; + _setEVC(ar, dec, t, EVC); + + if(!_isSetR3){ + autoRef_3(); + } + + for(int i=0; i<3; i++){ + HVC[i] = 0.0; } + for(int i=0; i<3; i++){ + for(int j=0; j<3; j++){ + HVC[i] += _T[i][j] * EVC[j]; + } + } + + qDebug() << "clmnforgoto=["<<HVC[0] <<"," <<HVC[1] <<"," <<HVC[2]<<"]"; + + (*ac) = atan2(HVC[1], HVC[0]); + //(*alt) = atan2(HVC[2]*sin(*ac),HVC[1]); + (*alt) = asin(HVC[2]); +} + +/* + * Equatorial coordinates (ar, dec) obtained from horizontal ones and time (ac, alt, t). + * + * If the third reference object is not established, it calculates it by calling the + * proper function. + */ +void Calibrate::getECoords(double ac, double alt, double t, double *ar, double *dec){ + double HVC[3]; + double EVC[3]; + _setHVC(ac, alt, HVC); + + if(!_isSetR3){ + autoRef_3(); + } + + for(int i=0; i<3; i++) + EVC[i] = 0.0; + for(int i=0; i<3; i++) + for(int j=0; j<3; j++) + EVC[i] += _iT[i][j] * HVC[j]; + + (*ar) = atan2(EVC[1], EVC[0]) + (_k*(t-_t0)); + (*dec) = asin(EVC[2]); +} diff --git a/src/Calibrate.hpp b/src/Calibrate.hpp new file mode 100755 index 0000000..0317405 --- /dev/null +++ b/src/Calibrate.hpp @@ -0,0 +1,204 @@ +/* +The MIT License (MIT) + +Copyright (c) 2012 Juan Ramón + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef Calibrate_h +#define Calibrate_h + + #include <math.h> + + /** + * \brief Library for coordinates transformations. Calculates the equivalent coordinates between both coordinate systems equatorial and horizontal. + * + * It's based on Toshimi Taki's matrix method for coordinates transformation: http://www.geocities.jp/toshimi_taki/matrix/matrix.htm + * Contains the necessary methods for setting the initial time, the reference objects, the transformation matrix, and to + * calculate the equivalent vectors between both coordinate systems. + */ + class Calibrate{ + private: + + /** + * Constant of multiplication for the solar and sidereal time relation. + */ + double _k; + + /** + * Initial timestamp for the observations. + */ + double _t0; + + /** + * Indicators for definition of the three reference objects. + */ + bool _isSetR1, _isSetR2, _isSetR3; + + /** + * Auxiliary matrices. + */ + double _lmn1[3], _LMN1[3], _lmn2[3], _LMN2[3], _lmn3[3], _LMN3[3]; + + /** + * Transformation matrix. Transform vectors from equatorial to horizontal system. + */ + double _T[3][3]; + + /** + * Inverse transformation matrix. Transform vectors from horizontal to equatorial system. + */ + double _iT[3][3]; + + /** + * If the three reference objects have been defined, it calculates the transformation matrix from them. + */ + void _setT(); + + /** + * Obtains a vector in polar notation from the equatorial coordinates and the observation time. + * + * \param ar Right ascension. + * \param dec Declination. + * \param t Timestamp of the observation. + * \param *EVC Pointer to array: Returns the three dimensional vector in polar notation. + */ + void _setEVC(double ar, double dec, double t, double* EVC); + + /** + * Obtains a vector in polar notation from the horizontal coordinates and observation time. + * + * \param ac Azimuth (horizontal coordinates). + * \param alt Altitude (horizontal coordinates). + * \param t Timestamp of the observation. + * \param *HVC Pointer to array: Returns the three dimensional vector in polar notation. + */ + void _setHVC(double ac, double alt, double* HVC); + + /** + * Calculates the 3x3 inverse matrix. + * + * \param m[3][3] Input matrix. + * \param res[3][3] Pointer to array: Returns the inverse matrix. + */ + void _inv(double m[3][3], double res[3][3]); + + /** + * Calculates the product of 3x3 matrices. + * + * \param m1[3][3] Input matrix 1. + * \param m2[3][3] Input matrix 2. + * \param res[3][3] Pointer to array: Returns the result matrix. + */ + void _m_prod(double m1[3][3], double m2[3][3], double res[3][3]); + + public: + + /** + * Class constructor. + */ + Calibrate(); + + /** + * Sets the initial time. + * + * This parameter is used in order to consider time passing on horizontal coordinates system. + * + * \param t0 Unix Timestamp of the initial observation time. + */ + void setTime(double t0); + + /** + * Sets the first reference object from the coordinates in both coordinates systems for + * that object. + * + * \param ar Right Ascension (equatorial coordinates). + * \param dec Declination (equatorial coordinates). + * \param t Unix Timestamp of the Observation. + * \param ac Azimuth (horizontal coordinates). + * \param alt Altitude (horizontal coordinates). + */ + void setRef_1(double ar, double dec, double t, double ac, double alt); + + /** + * Sets the second reference object from the coordinates in both coordinates systems for + * that object. + * + * \param ar Right Ascension (equatorial coordinates). + * \param dec Declination (equatorial coordinates). + * \param t Unix Timestamp of the Observation. + * \param ac Azimuth (horizontal coordinates). + * \param alt Altitude (horizontal coordinates). + */ + void setRef_2(double ar, double dec, double t, double ac, double alt); + + /** + * Sets the third reference object from the coordinates in both coordinates systems for + * that object. + * + * \param ar Right Ascension (equatorial coordinates). + * \param dec Declination (equatorial coordinates). + * \param t Unix Timestamp of the Observation. + * \param ac Azimuth (horizontal coordinates). + * \param alt Altitude (horizontal coordinates). + */ + void setRef_3(double ar, double dec, double t, double ac, double alt); + + /** + * Third reference object calculated from the two others ones. + * + * Calculates the cross product of the two first reference objects in both coordinates systems, in order + * to obtain the third one. + * These two first objects must have 90º from each other, approximately (from 60º to 120º is enough to obtain + * goods results). + */ + void autoRef_3(); + + /** + * Indicates if the three reference objects has been calculated. + * + * \return Boolean. + */ + bool isConfigured(); + + + /** + * Horizontal coordinates calculated from the equatorial ones and time. + * + * \param ar Right Ascension (equatorial coordinates). + * \param dec Declination (equatorial coordinates) + * \param t Unix Timestamp of the Observation. + * \param *ac Pointer to double: Returns the azimuth (horizontal coordiantes). + * \param *alt Pointer to double: Returns the altitude (horizontal coordinates). + */ + void getHCoords(double ar, double dec, double t, double *ac, double *alt); + + /** + * Equatorial coordinates calculated from the horizontal ones and time. + * + * \param ac Azimuth (horizontal coordinates). + * \param alt Altitude (horizontal coordinates). + * \param t Unix Timestamp of the Observation. + * \param *ar Pointer to double: Returns the right ascension (equatorial coordinates). + * \param *dec Pointer to double: Returns the declination (equatorial coordinates). + */ + void getECoords(double ac, double alt, double t, double *ar, double *dec); + }; + +#endif diff --git a/src/Calibrate.hpp~ b/src/Calibrate.hpp~ new file mode 100755 index 0000000..0317405 --- /dev/null +++ b/src/Calibrate.hpp~ @@ -0,0 +1,204 @@ +/* +The MIT License (MIT) + +Copyright (c) 2012 Juan Ramón + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef Calibrate_h +#define Calibrate_h + + #include <math.h> + + /** + * \brief Library for coordinates transformations. Calculates the equivalent coordinates between both coordinate systems equatorial and horizontal. + * + * It's based on Toshimi Taki's matrix method for coordinates transformation: http://www.geocities.jp/toshimi_taki/matrix/matrix.htm + * Contains the necessary methods for setting the initial time, the reference objects, the transformation matrix, and to + * calculate the equivalent vectors between both coordinate systems. + */ + class Calibrate{ + private: + + /** + * Constant of multiplication for the solar and sidereal time relation. + */ + double _k; + + /** + * Initial timestamp for the observations. + */ + double _t0; + + /** + * Indicators for definition of the three reference objects. + */ + bool _isSetR1, _isSetR2, _isSetR3; + + /** + * Auxiliary matrices. + */ + double _lmn1[3], _LMN1[3], _lmn2[3], _LMN2[3], _lmn3[3], _LMN3[3]; + + /** + * Transformation matrix. Transform vectors from equatorial to horizontal system. + */ + double _T[3][3]; + + /** + * Inverse transformation matrix. Transform vectors from horizontal to equatorial system. + */ + double _iT[3][3]; + + /** + * If the three reference objects have been defined, it calculates the transformation matrix from them. + */ + void _setT(); + + /** + * Obtains a vector in polar notation from the equatorial coordinates and the observation time. + * + * \param ar Right ascension. + * \param dec Declination. + * \param t Timestamp of the observation. + * \param *EVC Pointer to array: Returns the three dimensional vector in polar notation. + */ + void _setEVC(double ar, double dec, double t, double* EVC); + + /** + * Obtains a vector in polar notation from the horizontal coordinates and observation time. + * + * \param ac Azimuth (horizontal coordinates). + * \param alt Altitude (horizontal coordinates). + * \param t Timestamp of the observation. + * \param *HVC Pointer to array: Returns the three dimensional vector in polar notation. + */ + void _setHVC(double ac, double alt, double* HVC); + + /** + * Calculates the 3x3 inverse matrix. + * + * \param m[3][3] Input matrix. + * \param res[3][3] Pointer to array: Returns the inverse matrix. + */ + void _inv(double m[3][3], double res[3][3]); + + /** + * Calculates the product of 3x3 matrices. + * + * \param m1[3][3] Input matrix 1. + * \param m2[3][3] Input matrix 2. + * \param res[3][3] Pointer to array: Returns the result matrix. + */ + void _m_prod(double m1[3][3], double m2[3][3], double res[3][3]); + + public: + + /** + * Class constructor. + */ + Calibrate(); + + /** + * Sets the initial time. + * + * This parameter is used in order to consider time passing on horizontal coordinates system. + * + * \param t0 Unix Timestamp of the initial observation time. + */ + void setTime(double t0); + + /** + * Sets the first reference object from the coordinates in both coordinates systems for + * that object. + * + * \param ar Right Ascension (equatorial coordinates). + * \param dec Declination (equatorial coordinates). + * \param t Unix Timestamp of the Observation. + * \param ac Azimuth (horizontal coordinates). + * \param alt Altitude (horizontal coordinates). + */ + void setRef_1(double ar, double dec, double t, double ac, double alt); + + /** + * Sets the second reference object from the coordinates in both coordinates systems for + * that object. + * + * \param ar Right Ascension (equatorial coordinates). + * \param dec Declination (equatorial coordinates). + * \param t Unix Timestamp of the Observation. + * \param ac Azimuth (horizontal coordinates). + * \param alt Altitude (horizontal coordinates). + */ + void setRef_2(double ar, double dec, double t, double ac, double alt); + + /** + * Sets the third reference object from the coordinates in both coordinates systems for + * that object. + * + * \param ar Right Ascension (equatorial coordinates). + * \param dec Declination (equatorial coordinates). + * \param t Unix Timestamp of the Observation. + * \param ac Azimuth (horizontal coordinates). + * \param alt Altitude (horizontal coordinates). + */ + void setRef_3(double ar, double dec, double t, double ac, double alt); + + /** + * Third reference object calculated from the two others ones. + * + * Calculates the cross product of the two first reference objects in both coordinates systems, in order + * to obtain the third one. + * These two first objects must have 90º from each other, approximately (from 60º to 120º is enough to obtain + * goods results). + */ + void autoRef_3(); + + /** + * Indicates if the three reference objects has been calculated. + * + * \return Boolean. + */ + bool isConfigured(); + + + /** + * Horizontal coordinates calculated from the equatorial ones and time. + * + * \param ar Right Ascension (equatorial coordinates). + * \param dec Declination (equatorial coordinates) + * \param t Unix Timestamp of the Observation. + * \param *ac Pointer to double: Returns the azimuth (horizontal coordiantes). + * \param *alt Pointer to double: Returns the altitude (horizontal coordinates). + */ + void getHCoords(double ar, double dec, double t, double *ac, double *alt); + + /** + * Equatorial coordinates calculated from the horizontal ones and time. + * + * \param ac Azimuth (horizontal coordinates). + * \param alt Altitude (horizontal coordinates). + * \param t Unix Timestamp of the Observation. + * \param *ar Pointer to double: Returns the right ascension (equatorial coordinates). + * \param *dec Pointer to double: Returns the declination (equatorial coordinates). + */ + void getECoords(double ac, double alt, double t, double *ar, double *dec); + }; + +#endif diff --git a/src/LaserDev.cpp b/src/LaserDev.cpp new file mode 100755 index 0000000..aafcedc --- /dev/null +++ b/src/LaserDev.cpp @@ -0,0 +1,307 @@ +/* + * 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 "LaserDev.hpp" +#include <QtSerialPort/QSerialPortInfo> +#include <QtSerialPort/QSerialPort> +#include <QCoreApplication> +#include <QTextStream> +#include <QObject> +#include <QDebug> +#include <QString> +#include <QTime> +#include <QDateTime> +#include <QMessageBox> +#include "SerialCom.hpp" + +/* +Constructor: +*/ +LaserDev::LaserDev(QObject *parent) + :QObject(parent) +{ + move_count=0; + connect(&thread, &SerialCom::response, this, &LaserDev::sread); + connect(&thread, &SerialCom::error, this, &LaserDev::processError); + connect(&thread, &SerialCom::timeout, this, &LaserDev::processTimeout); +} + + +/* +Destructor: +*/ +LaserDev::~LaserDev(){ + +} + +/* +processError(const QString): + slot for the error, sends the signal to OSPMainDialog +*/ +void LaserDev :: processError(const QString &s){ +} + +/* +processTimeout(const QString): + slot for the timeout , sends the signal to OSPMainDialog +*/ +void LaserDev :: processTimeout(const QString &s){ +} + + +/* +setPortName(const QString): + function for setting the portName +*/ +void LaserDev :: setPortName(const QString &s){ + osp_serialPort=s; + thread.sendRequest(osp_serialPort,5000,QString("")); +} + +void LaserDev :: releasePort(){ + thread.serial.close(); + qDebug()<<"Releasing Port"; +} + +/* +sread(const QString): + this function is called after writing to the serial port + this function performs various steps like echoData,getSteps,getHorizontalCoords,getVerticalCoords +*/ +void LaserDev::sread(const QString &s){ + QString recvd = s.trimmed(); + QRegExp exp("t_([0-9\\.\\-]{4,9})_([0-9\\.\\-]{4,9})"); + if(recvd.compare("done_init")==0){ + emit debug_send(recvd); + getPos(); + } + else if(recvd.compare("done_movu")==0){ + emit debug_send(recvd); + getPos(); + } + else if(recvd.compare("done_movd")==0){ + emit debug_send(recvd); + getPos(); + } + else if(recvd.compare("done_movr")==0){ + emit debug_send(recvd); + getPos(); + } + else if(recvd.compare("done_movl")==0){ + emit debug_send(recvd); + getPos(); + } + else if(recvd.compare("done_move")==0){ + emit debug_send(recvd); + } + else if(recvd.compare("done_laon")==0){ + emit debug_send(recvd); + } + else if(recvd.compare("done_loff")==0){ + emit debug_send(recvd); + } + else if(recvd.compare("done_high_speed")==0){ + emit debug_send(recvd); + } + else if(recvd.compare("done_low_speed")==0){ + emit debug_send(recvd); + } + else if(recvd.compare("done_reset")==0){ + emit debug_send(recvd); + getPos(); + } + else if(recvd.compare("done_close")==0){ + emit debug_send(recvd); + releasePort(); + } + else if(recvd.compare("done_lase")==0){ + emit debug_send("intensity"); + comm=intense; + thread.sendRequest(osp_serialPort,1000,QString(comm)); + emit debug_send(comm); + } + else if(recvd.compare("float")==0){ + emit debug_send("float"); + bool ac_neg=false,alt_neg=false; + if(dac<0) ac_neg=true; + if(dalt<0) alt_neg=true; + ac=QString::number(dac,'f',4); + alt=QString::number(dalt,'f',4); + if(!ac_neg){ + ac = QString("+"+ac); + } + if(!alt_neg){ + alt = QString("+"+alt); + } + comm=QString("m_%1_%2").arg(ac).arg(alt); + thread.sendRequest(osp_serialPort,1000,QString(comm)); + emit debug_send(comm); + } + else if(exp.exactMatch(recvd)){ + QStringList items = exp.capturedTexts(); + emit pos_received(items[1],items[2]); + } + else { + //emit debug_send(QString("Unexpected Byte Received.Please Restart the device: %1 if problems persist").arg(recvd)); + //thread.sendRequest(osp_serialPort,1000,QString("clear")); + } +} + +/* +init(): + sends the "init" command to the device and after "done_init" is received from the device, + emits "init_received" signal + +*/ +void LaserDev :: init(){ + comm=QString("init"); + thread.sendRequest(osp_serialPort,5000,QString(comm)); +} + +/* +closeWindow(): + sends the "clos" command to the device to reset the hardware + +*/ +void LaserDev :: closeWindow(){ + + comm=QString("clos"); + thread.sendRequest(osp_serialPort,5000,QString(comm)); +} + + +/* +getPos(): + This function is called to get the current position of the telescope in radians +*/ +void LaserDev :: getPos(){ + comm=QString("post"); + thread.sendRequest(osp_serialPort,100,QString(comm)); +} + + + +/* +move(double,double): + sends the telescope coordinates to the device +*/ +void LaserDev :: move(double x,double y){ + //move_count=1; + //ac.setNum(x); + //alt.setNum(y); + dac=x; + dalt=y; + + comm=QString("move"); + thread.sendRequest(osp_serialPort,1000,QString(comm)); + +} + + /* +movy(int): + to move the laser in y direction depending on signDir +*/ +void LaserDev :: movy(int signDir){ + if(signDir) + comm=QString("movu"); + else + comm=QString("movd"); + thread.sendRequest(osp_serialPort,100,QString(comm)); + +} + +/* + movx(int): + to move the laser in x direction depending on signDir +*/ +void LaserDev :: movx(int signDir){ + if(signDir) + comm=QString("movr"); + else + comm=QString("movl"); + thread.sendRequest(osp_serialPort,100,QString(comm)); +} + +/* +stop(): + to stop the laser movements in either of the direction x or y +*/ +void LaserDev :: stop(){ + comm=QString("stop"); + thread.sendRequest(osp_serialPort,100,QString(comm)); +} + +/* +laserOn(): + to turn the laser on +*/ +void LaserDev :: laserOn(){ + comm=QString("laon"); + thread.sendRequest(osp_serialPort,1000,QString(comm)); +} + +void LaserDev :: resetAll(){ + /*comm=QString("rest"); + thread.sendRequest(osp_serialPort,100,QString(comm)); + */ + move(0,0); +} + + +/* +laserOff(): + to turn the laser off +*/ +void LaserDev :: laserOff(){ + comm=QString("loff"); + thread.sendRequest(osp_serialPort,1000,QString(comm)); +} + + +/* + setIntensity(): + to set the intensity of the laser +*/ +void LaserDev ::setIntensity(int x){ + QString s=QString::number(x); + if(s.length()==2) + s="00"+s; + else if(s.length()==3) + s="0"+s; + intense=s; + comm=QString("lase"); + emit debug_send(comm); + thread.sendRequest(osp_serialPort,1000,QString(comm)); +} + +/* +CoarseAdj(): + to let the motors go on high speed +*/ +void LaserDev :: CoarseAdj(){ + comm=QString("coad"); + thread.sendRequest(osp_serialPort,1000,QString(comm)); +} +/* +FineAdj(): + to let the motors go on a low speed +*/ +void LaserDev :: FineAdj(){ + comm=QString("fiad"); + thread.sendRequest(osp_serialPort,1000,QString(comm)); +} diff --git a/src/LaserDev.hpp b/src/LaserDev.hpp new file mode 100755 index 0000000..8d4830f --- /dev/null +++ b/src/LaserDev.hpp @@ -0,0 +1,201 @@ +/* + * 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. + */ +#ifndef LASERDEV_HPP +#define LASERDEV_HPP + +#include <QtSerialPort/QSerialPortInfo> +#include <QtSerialPort/QSerialPort> +#include <QTextStream> +#include <QCoreApplication> +#include <QString> +#include <QObject> +#include <QThread> +#include <QTime> +#include "SerialCom.hpp" + +//! This class is used for funtions related to motion and turning the laser on and off. +class LaserDev : public QObject +{ + Q_OBJECT +public: + /** + * Class constructor. + */ + LaserDev(QObject *parent=0); + + /** + * Class destructor. + */ + ~LaserDev(); + + /** + * function for setting the portName + * \param s port name + */ + void setPortName(const QString &s); + void releasePort(); +signals: + + /** + * Sending the debug signal + */ + void debug_send(QString s); + + /** + * Recieving the position from arduino + */ + void pos_received(QString,QString); +private: + + /** + * Constant for counting the motion in stpper motor. + */ + int move_count; + + /** + * Constant string for azimuth recieved from servo. + */ + QString ac; + + /** + * Constant string for altitude recieved from servo. + */ + QString alt; + + /** + * Constant for sending string. + */ + + QString intense; + + /** + * Constant string for varying the intensity of LASER. + */ + QString comm; + + /** + * Constant double for azimuth recieved from servo. + */ + double dac; + + /** + * Constant double for altitude recieved from servo. + */ + double dalt; + + /** + * Object for using serial class. + */ + SerialCom thread; + + /** + * Constant string for serial port name. + */ + QString osp_serialPort; + + QByteArray osp_ba; + +public slots: + + /** + * This function is called to get the current position of the telescope in radians + */ + void getPos(); + + /** + * slot for the error, sends the signal to OSPMainDialog + */ + void processError(const QString &s); + + /** + * slot for the timeout , sends the signal to OSPMainDialog + */ + void processTimeout(const QString &s); + + /** + * This function is called after writing to the serial port. This function performs various steps like echoData, getSteps, getHorizontalCoords, getVerticalCoords + */ + void sread(const QString &s); + + /** + * sends the "init" command to the device and after "done_init" is received from the device, emits "init_received" signal + */ + void init(); + + /** + * sends the "clos" command to the device to reset the hardware + */ + void closeWindow(); + + /** + * Sends the telescope coordinates to the device + * \param x Azimuth fed to arduino. + * \param y Altitude fed to arduino. + */ + void move(double x,double y); + + /** + * To move the laser in x direction depending on signDir + */ + void movx(int signDir); + + /** + * To move the laser in y direction depending on signDir + * /param signDir 0 to move up 1 to move down + */ + void movy(int signDir); + + /** + * to stop the laser movements in either of the direction x or y + * /param signDir 0 to move up 1 to move down + */ + void stop(); + + /** + * to turn the laser on + */ + void laserOn(); + + /** + * To turn the laser off + */ + void laserOff(); + + /** To set the intensity of the laser + */ + void setIntensity(int x); + + /** + * To hard reset the arduino + */ + void resetAll(); + + /** + * to turn the motor's high speed on + */ + void CoarseAdj(); + + /** + * To turn the motor's high speed off + */ + void FineAdj(); +}; + + + +#endif // LASERDEV_HPP diff --git a/src/OpenSkyPlanetarium.cpp b/src/OpenSkyPlanetarium.cpp new file mode 100755 index 0000000..1a863c7 --- /dev/null +++ b/src/OpenSkyPlanetarium.cpp @@ -0,0 +1,129 @@ +/* + * 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 "StelApp.hpp" +#include "StelCore.hpp" +#include "StelLocaleMgr.hpp" +#include "StelModuleMgr.hpp" +#include "StelGui.hpp" +#include "StelGuiItems.hpp" + +#include "OpenSkyPlanetarium.hpp" +#include "OSPMainDialog.hpp" + +#include <QAction> +#include <QString> +#include <QDebug> +#include <stdexcept> + +/************************************************************************* + This method is the one called automatically by the StelModuleMgr just + after loading the dynamic library +*************************************************************************/ +StelModule* OpenSkyPlanetariumPluginInterface::getStelModule() const +{ + return new OpenSkyPlanetarium(); +} + +StelPluginInfo OpenSkyPlanetariumPluginInterface::getPluginInfo() const +{ + + qDebug() << "[OpenSkyPlanetarium] __debug__ getplugininfo"; + Q_INIT_RESOURCE(OpenSkyPlanetarium); + StelPluginInfo info; + info.id = "OpenSkyPlanetarium"; + info.displayedName = N_("OpenSkyPlanetarium"); + info.authors = "IIT Bombay Interns"; + info.contact = "openskyplanetarium@fossee.in"; + info.description = N_("An open source initiative for Planetarium shows in Open Sky"); + return info; +} + +/************************************************************************* + Constructor +*************************************************************************/ +OpenSkyPlanetarium::OpenSkyPlanetarium() +{ + setObjectName("OpenSkyPlanetarium"); + mainDialog = new OSPMainDialog(); +} + +/************************************************************************* + Destructor +*************************************************************************/ +OpenSkyPlanetarium::~OpenSkyPlanetarium() +{ + +} + +/************************************************************************* + Reimplementation of the getCallOrder method +*************************************************************************/ +double OpenSkyPlanetarium::getCallOrder(StelModuleActionName actionName) const +{ + if (actionName == StelModule::ActionDraw) + return StelApp::getInstance().getModuleMgr().getModule("LandscapeMgr")->getCallOrder(actionName) + 1.; + return 0.; +} + +/************************************************************************* +Configure Gui +*************************************************************************/ +bool OpenSkyPlanetarium::configureGui(bool show) +{ + return false; +} + +/************************************************************************* + Init our module +*************************************************************************/ +void OpenSkyPlanetarium::init() +{ + try{ + + addAction("actionShow_Main_Dialog", N_("OpenSkyPlanetarium"), N_("Show Open Sky Planetarium Window"), mainDialog, "visible", "Ctrl+Shift+P"); + + //Create toolbar button + StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui()); + if (gui!=NULL) + { + toolbarButton = new StelButton(NULL, + QPixmap(":/OpenSkyPlanetarium/bt_osp_on.png"), + QPixmap(":/OpenSkyPlanetarium/bt_osp_off.png"), + QPixmap(":/graphicGui/glow32x32.png"), + "actionShow_Main_Dialog"); + gui->getButtonBar()->addButton(toolbarButton, "065-pluginsGroup"); + } + } + catch (std::runtime_error &e) + { + qWarning() << "[OpemSkyPlanetarium] init() error: " << e.what(); + return; + } +} + +/************************************************************************* +Deinit our Module +*************************************************************************/ +void OpenSkyPlanetarium::deinit() +{ + //qDebug()<<"In OSP mainindow"<<endl; + delete mainDialog; +} + + diff --git a/src/OpenSkyPlanetarium.hpp b/src/OpenSkyPlanetarium.hpp new file mode 100755 index 0000000..a982888 --- /dev/null +++ b/src/OpenSkyPlanetarium.hpp @@ -0,0 +1,97 @@ +/* + * 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. + */ + +#ifndef OPENSKYPLANETARIUM_HPP_ +#define OPENSKYPLANETARIUM_HPP_ + +#include "StelModule.hpp" +#include "StelGui.hpp" +#include<QString> +#include <QFont> + +class OSPMainDialog; + +//! This is used to dynamically load Open Sky Planetarium plugin into stellarium +class OpenSkyPlanetarium :public StelModule +{ + Q_OBJECT +public: + + /** + * Class constructor. + */ + OpenSkyPlanetarium(); + + /** + * Class destructor. + */ + ~OpenSkyPlanetarium(); + + /////////////////////////////////////////////////////////////////////////// + // Methods defined in the StelModule class + + /** + * Init Open Sky Planetarium module + */ + virtual void init(); + + /** + * This method is used to delete the instance of main Window + */ + virtual void deinit(); + virtual void update(double) {;} + + /** + * This method is used to reimplement the getCallOrder method + */ + virtual double getCallOrder(StelModuleActionName actionName) const; + + /** + * This method is used to show the plugin interface + */ + virtual bool configureGui(bool show); +private: + QFont *font; + OSPMainDialog *mainDialog; + StelButton* toolbarButton; +}; + + +#include <QObject> +#include "StelPluginInterface.hpp" + +//! This class is used by Qt to manage a plug-in interface +class OpenSkyPlanetariumPluginInterface : public QObject, public StelPluginInterface +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID StelPluginInterface_iid) + Q_INTERFACES(StelPluginInterface) +public: + + /** + * This method is the one called automatically by the StelModuleMgr just after loading the dynamic library + */ + virtual StelModule* getStelModule() const; + + /** + * This method is used to pass the information about the OpenSky Planetarium plugin. + */ + virtual StelPluginInfo getPluginInfo() const; +}; + +#endif /*OPENSKYPLANETARIUM_HPP_*/ diff --git a/src/OpenSkyPlanetarium.hpp~ b/src/OpenSkyPlanetarium.hpp~ new file mode 100755 index 0000000..a982888 --- /dev/null +++ b/src/OpenSkyPlanetarium.hpp~ @@ -0,0 +1,97 @@ +/* + * 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. + */ + +#ifndef OPENSKYPLANETARIUM_HPP_ +#define OPENSKYPLANETARIUM_HPP_ + +#include "StelModule.hpp" +#include "StelGui.hpp" +#include<QString> +#include <QFont> + +class OSPMainDialog; + +//! This is used to dynamically load Open Sky Planetarium plugin into stellarium +class OpenSkyPlanetarium :public StelModule +{ + Q_OBJECT +public: + + /** + * Class constructor. + */ + OpenSkyPlanetarium(); + + /** + * Class destructor. + */ + ~OpenSkyPlanetarium(); + + /////////////////////////////////////////////////////////////////////////// + // Methods defined in the StelModule class + + /** + * Init Open Sky Planetarium module + */ + virtual void init(); + + /** + * This method is used to delete the instance of main Window + */ + virtual void deinit(); + virtual void update(double) {;} + + /** + * This method is used to reimplement the getCallOrder method + */ + virtual double getCallOrder(StelModuleActionName actionName) const; + + /** + * This method is used to show the plugin interface + */ + virtual bool configureGui(bool show); +private: + QFont *font; + OSPMainDialog *mainDialog; + StelButton* toolbarButton; +}; + + +#include <QObject> +#include "StelPluginInterface.hpp" + +//! This class is used by Qt to manage a plug-in interface +class OpenSkyPlanetariumPluginInterface : public QObject, public StelPluginInterface +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID StelPluginInterface_iid) + Q_INTERFACES(StelPluginInterface) +public: + + /** + * This method is the one called automatically by the StelModuleMgr just after loading the dynamic library + */ + virtual StelModule* getStelModule() const; + + /** + * This method is used to pass the information about the OpenSky Planetarium plugin. + */ + virtual StelPluginInfo getPluginInfo() const; +}; + +#endif /*OPENSKYPLANETARIUM_HPP_*/ diff --git a/src/SerialCom.cpp b/src/SerialCom.cpp new file mode 100755 index 0000000..d3f67c9 --- /dev/null +++ b/src/SerialCom.cpp @@ -0,0 +1,120 @@ +/*
+ * 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 "SerialCom.hpp"
+#include <QtSerialPort/QSerialPort>
+#include <QTime>
+
+QT_USE_NAMESPACE
+
+/**
+Constructor:
+*/
+SerialCom::SerialCom(QObject *parent)
+ : QThread(parent), waitTime(0), quit(false)
+{
+}
+
+/**
+Destructor:
+*/
+SerialCom::~SerialCom()
+{
+ mutex.lock();
+ quit = true;
+ cond.wakeOne();
+ mutex.unlock();
+ wait();
+}
+
+/**
+sendRequest(const QString, int, const QString):
+ Send a request to arduino
+*/
+void SerialCom::sendRequest(const QString &port, int waitTime, const QString &request)
+{
+ QMutexLocker locker(&mutex);
+ this->port = port;
+ this->waitTime = waitTime;
+ this->request = request;
+ if (!isRunning())
+ start();
+ else
+ cond.wakeOne();
+}
+
+/**
+run()
+
+*/
+void SerialCom::run()
+{
+ bool myPortNameChanged = false;
+
+ //mutex.lock();
+ QString myPortName;
+ if (myPortName != port) {
+ myPortName = port;
+ myPortNameChanged = true;
+ }
+
+ int myWaitTimeout = waitTime;
+ QString myRequest = request;
+ //mutex.unlock();
+ //QSerialPort serial;
+
+ while (!quit) {
+ if (myPortNameChanged) {
+ serial.close();
+ serial.setPortName(myPortName);
+
+ if (!serial.open(QIODevice::ReadWrite)) {
+ emit error(tr("Can't open %1, error code %2")
+ .arg(port).arg(serial.error()));
+ return;
+ }
+ }
+ QByteArray requestData = myRequest.toLocal8Bit();
+ serial.write(requestData);
+ if (serial.waitForBytesWritten(waitTime)) {
+ if (serial.waitForReadyRead(myWaitTimeout)) {
+ QByteArray responseData = serial.readAll();
+ while (serial.waitForReadyRead(10))
+ responseData += serial.readAll();
+ QString response(responseData);
+ emit this->response(response);
+ } else {
+ emit timeout(tr("Wait Read Request Timed Out %1")
+ .arg(QTime::currentTime().toString()));
+ }
+ } else {
+ emit timeout(tr("Wait Write Request Timed Out %1")
+ .arg(QTime::currentTime().toString()));
+ }
+ //mutex.lock();
+ cond.wait(&mutex);
+ if (myPortName != port) {
+ myPortName = port;
+ myPortNameChanged = true;
+ } else {
+ myPortNameChanged = false;
+ }
+ myWaitTimeout = waitTime;
+ myRequest = request;
+ // mutex.unlock();
+ }
+}
diff --git a/src/SerialCom.cpp~ b/src/SerialCom.cpp~ new file mode 100755 index 0000000..0edd712 --- /dev/null +++ b/src/SerialCom.cpp~ @@ -0,0 +1,117 @@ +/*
+ * 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 "SerialCom.hpp"
+#include <QtSerialPort/QSerialPort>
+#include <QTime>
+
+QT_USE_NAMESPACE
+
+/**
+Constructor:
+*/
+SerialCom::SerialCom(QObject *parent)
+ : QThread(parent), waitTime(0), quit(false)
+{
+}
+
+/**
+Destructor:
+*/
+SerialCom::~SerialCom()
+{
+ mutex.lock();
+ quit = true;
+ cond.wakeOne();
+ mutex.unlock();
+ wait();
+}
+
+/**
+sendRequest(const QString, int, const QString):
+ Send a request to arduino
+*/
+void SerialCom::sendRequest(const QString &port, int waitTime, const QString &request)
+{
+ QMutexLocker locker(&mutex);
+ this->port = port;
+ this->waitTime = waitTime;
+ this->request = request;
+ if (!isRunning())
+ start();
+ else
+ cond.wakeOne();
+}
+
+
+void SerialCom::run()
+{
+ bool myPortNameChanged = false;
+
+ mutex.lock();
+ QString myPortName;
+ if (myPortName != port) {
+ myPortName = port;
+ myPortNameChanged = true;
+ }
+
+ int myWaitTimeout = waitTime;
+ QString myRequest = request;
+ mutex.unlock();
+ QSerialPort serial;
+
+ while (!quit) {
+ if (myPortNameChanged) {
+ serial.close();
+ serial.setPortName(myPortName);
+
+ if (!serial.open(QIODevice::ReadWrite)) {
+ emit error(tr("Can't open %1, error code %2")
+ .arg(port).arg(serial.error()));
+ return;
+ }
+ }
+ QByteArray requestData = myRequest.toLocal8Bit();
+ serial.write(requestData);
+ if (serial.waitForBytesWritten(waitTime)) {
+ if (serial.waitForReadyRead(myWaitTimeout)) {
+ QByteArray responseData = serial.readAll();
+ while (serial.waitForReadyRead(10))
+ responseData += serial.readAll();
+ QString response(responseData);
+ emit this->response(response);
+ } else {
+ emit timeout(tr("Wait Read Request Timed Out %1")
+ .arg(QTime::currentTime().toString()));
+ }
+ } else {
+ emit timeout(tr("Wait Write Request Timed Out %1")
+ .arg(QTime::currentTime().toString()));
+ }
+ mutex.lock();
+ cond.wait(&mutex);
+ if (myPortName != port) {
+ myPortName = port;
+ myPortNameChanged = true;
+ } else {
+ myPortNameChanged = false;
+ }
+ myWaitTimeout = waitTime;
+ myRequest = request;
+ mutex.unlock();
+ }
+}
diff --git a/src/SerialCom.hpp b/src/SerialCom.hpp new file mode 100755 index 0000000..ca8ab86 --- /dev/null +++ b/src/SerialCom.hpp @@ -0,0 +1,84 @@ +/*
+ * 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.
+ */
+#ifndef SERIALCOM_H
+#define SERIALCOM_H
+
+#include <QThread>
+#include <QMutex>
+#include <QWaitCondition>
+#include <QtSerialPort/QSerialPort>
+
+//! This class is used for funtions related to serial communication with the arduino
+class SerialCom : public QThread
+{
+ Q_OBJECT
+
+private:
+ QString port;
+ QString request;
+ int waitTime;
+ QMutex mutex;
+ QWaitCondition cond;
+ bool quit;
+
+public:
+ QSerialPort serial;
+ /**
+ * Class constructor
+ */
+ SerialCom(QObject *parent = 0);
+
+ /**
+ * Class destructor
+ */
+ ~SerialCom();
+
+ /**
+ * To set the parameters that needed to sent to arduino
+ * \param port name of the port on which request need to be sent
+ * \param waitTime wait time for the response from arduino
+ * \param request a string to be sent to arduino
+ */
+ void sendRequest(const QString &port, int waitTime, const QString &request);
+
+ /**
+ * To send a request to arduino and wait for response and to save it
+ */
+ void run();
+
+signals:
+
+ /**
+ * Response from the arduino
+ */
+ void response(const QString &s);
+
+ /**
+ * Error from arduino
+ */
+ void error(const QString &s);
+
+ /**
+ * Timeout error from arduio
+ */
+ void timeout(const QString &s);
+
+};
+
+
+#endif // SERIALCOM_H
diff --git a/src/SerialCom.hpp~ b/src/SerialCom.hpp~ new file mode 100755 index 0000000..33a21f8 --- /dev/null +++ b/src/SerialCom.hpp~ @@ -0,0 +1,82 @@ +/*
+ * 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.
+ */
+#ifndef SERIALCOM_H
+#define SERIALCOM_H
+
+#include <QThread>
+#include <QMutex>
+#include <QWaitCondition>
+
+//! This class is used for funtions related to motion and turning the laser on and off.
+class SerialCom : public QThread
+{
+ Q_OBJECT
+
+private:
+ QString port;
+ QString request;
+ int waitTime;
+ QMutex mutex;
+ QWaitCondition cond;
+ bool quit;
+
+public:
+ /**
+ * Class constructor
+ */
+ SerialCom(QObject *parent = 0);
+
+ /**
+ * Class destructor
+ */
+ ~SerialCom();
+
+ /**
+ * To set the parameters that needed to sent to arduino
+ * \param port name of the port on which request need to be sent
+ * \param waitTime wait time for the response from arduino
+ * \param request a string to be sent to arduino
+ */
+ void sendRequest(const QString &port, int waitTime, const QString &request);
+
+ /**
+ * To send a request to arduino and wait for response and to save it
+ */
+ void run();
+
+signals:
+
+ /**
+ * Response from the arduino
+ */
+ void response(const QString &s);
+
+ /**
+ * Error from arduino
+ */
+ void error(const QString &s);
+
+ /**
+ * Timeout error from arduio
+ */
+ void timeout(const QString &s);
+
+};
+
+
+#endif // SERIALCOM_H
diff --git a/src/gui/OSPMainDialog.cpp b/src/gui/OSPMainDialog.cpp new file mode 100755 index 0000000..fe3cbbb --- /dev/null +++ b/src/gui/OSPMainDialog.cpp @@ -0,0 +1,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; + } +} + diff --git a/src/gui/OSPMainDialog.hpp b/src/gui/OSPMainDialog.hpp new file mode 100755 index 0000000..c6d37f8 --- /dev/null +++ b/src/gui/OSPMainDialog.hpp @@ -0,0 +1,312 @@ +/* + * 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. + */ + +#ifndef OSPMAINDIALOG_H +#define OSPMAINDIALOG_H + +#include "Calibrate.hpp" +#include "StelDialog.hpp" +#include "LaserDev.hpp" +#include "StarMgr.hpp" +#include<QMediaPlayer> +#include <QWidget> +#include <QtSerialPort/QSerialPort> +#include <QtSerialPort/QSerialPortInfo> +#include<QList> +#include<QHash> +#include <QMediaPlaylist> +#include <QAbstractSlider> + + +class Ui_OSPMainDialog; + +//! This is the main class used in connecting all the signals to gui. +class OSPMainDialog : public StelDialog +{ + Q_OBJECT + +public: + OSPMainDialog(); + + ~OSPMainDialog(); + + + /** + * This function connects the various gui signals to its corresponding slots. + * This function is called in the createDialogContent() function of this class. + */ + void setSignals(); + + /** + * This function is called to display error/information messages + */ + void showMessage(QString m); + + +public slots: + + /** + * This function retranslate the language of plugin. + */ + void retranslate(); + /** + * This funtion is connected to many signals for debugging purpose. + * \param s Debug string + */ + void debug_received(QString s); + /** + * This slot is called when the laser device sends us the coordinates + * The coordinates are then used for setting the references in transformation matrix + * \param x Azimuth in string. + * \param y Altitude in string. + */ + void pos_received(QString x,QString y); + /** + * 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 selectDevice(); + /** + * 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 initDevice(); + /** + * 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 arrow_released(); + /** + * This functions is called when the buttons Up(mvUp) is pressed + */ + void upPressed(); + /** + * This functions is called when the buttons Down(mvDown) is pressed + */ + void downPressed(); + /** + * This functions is called when the buttons Right(mvRight) is pressed + */ + void rightPressed(); + /** + * This functions is called when the buttons Left(mvLeft) is pressed + */ + void leftPressed(); + /** + * This function is connected to the laser turnOn/turnOff radioButtons of the gui + */ + void laserToggled(); + + /** + * This function sets three references for the matrix transformation basically it sends three references for matrix transformation to the device for its calculations + */ + void setReference(); + + /** + * This function is connected to the laser intensity control slider + */ + void setIntensity(int x); + + /** + * This function is connected to the close button of gui + */ + void closeWin(); + + /** + * This function is connected to the motor control radioButtons of the gui + */ + void adjToggled(); + + /** + * 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 goTo(); + + /** + * This function opens an existing file if present in the script directory of our module. + */ + void openScript(); + + /** + * This function is used to save the script + */ + void saveScript(); + + /** + * This function is used to execute script. This function calls compile function before executing + */ + void execScript(); + + /** + * This function is used to compile script. This function maps the user script commands to the C++ functions + */ + void compileScript(); + + /** + * This is a slot for our script engine emit signal comTURN. This is used when playing the script + */ + void laser(bool stat); + + /** + * This function is used to play audio files. This is used to give play Audio functionality in our script + */ + void playAudio(QString fname); + + /** + * This is used when playing the script. This is used to give wait functionality in the script + * \param min time in minute + * \param sec time in second + */ + void waitforsec(int min,int sec); + + /** + * 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 + * \param sra Right Ascension (equatorial coordinates). + * \param dec Declination (equatorial coordinates). + */ + void move(QString,QString); + + /** + * This slot is connected to Goto Button of the Script Engine. Adds the goto command to your script + */ + void gt(); + + /** + * This slot is connected to Play Button of the Script Engine. Adds the play audio command to your script + */ + void pl(); + + /** + * This slot is connected to laser on/off button of the Script Engine. Adds the laser on/off command to your script + */ + void lo(); + + /** + * This slot is connected to wait button of the Script Engine. Adds the wait command to your script + */ + void wt(); + /** + * This slot is for hard reset of the arduino. + */ + void reset(); + +signals: + + /** + * This signal is connected to move of OSPMainDialog class + * \param sra Right Ascension (equatorial coordinates). + * \param dec Declination (equatorial coordinates). + */ + void comGOTO(QString sra,QString sdec); + + /** + * This signal is connected to laser of OSPMainDialog class + * \param stat status of laser + */ + void comTURN(bool stat); + + /** + * This signal is connected to waitforsec of OSPMainDialog class + * \param min time in minute + * \param sec time in second + */ + void comWAIT(int min,int sec); + + + /** + * This signal is connected to playAudio of OSPMainDialog class + * \param fname file name + */ + void comPLAY(QString fname); + +protected: + + /** + * This function is used to create a dialog box and set the current index of the box + */ + void createDialogContent(); + +private: + OpenSkyPlanetarium *osp; + Ui_OSPMainDialog *ui; + LaserDev device; + Calibrate calib; + QString acTemp; + QString altTemp; + double osp_time; + double osp_ra; + double osp_dec; + bool buildStatus; + QString portName; + QHash<QString,QString> i18n_to_coords; + QString moduleDirectoryPath; + QString scriptDirectoryPath; + QString audioDirectoryPath; + QStringList commandsList; + bool calMode; + int nRef; + + // Audio functions + +signals: + + /** + * This signal is connected to play of QMediaPlayer class + */ + void play(); + + + /** + * This signal is connected to pause of QMediaPlayer class + */ + void pause(); + + /** + * This signal is connected to stop of QMediaPlayer class + */ + void stop(); + +public slots: + + /** + * This slot is connected to volume slider. + * \param volume by slider + */ + void setVolume(int volume); + + /** + * This slot is connected to play and pause button. + */ + void playClicked(); + + /** + * This slot is connected to stop button. + */ + void stopClick(); + +private: + QMediaPlayer* player; + QMediaPlaylist* playlist; + QMediaPlayer::State playerState; + QAbstractSlider *volumeSlider; + QTime dieTime; + QTime pauseWait; + qint32 remtim; +}; + +#endif // OSPMAINDIALOG_H diff --git a/src/gui/OSPMainDialog.ui b/src/gui/OSPMainDialog.ui new file mode 100755 index 0000000..4a509ae --- /dev/null +++ b/src/gui/OSPMainDialog.ui @@ -0,0 +1,758 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>OSPMainDialog</class> + <widget class="QWidget" name="OSPMainDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>510</width> + <height>461</height> + </rect> + </property> + <property name="focusPolicy"> + <enum>Qt::ClickFocus</enum> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="BarFrame" name="TitleBar"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>25</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>16777215</width> + <height>30</height> + </size> + </property> + <property name="focusPolicy"> + <enum>Qt::NoFocus</enum> + </property> + <property name="autoFillBackground"> + <bool>false</bool> + </property> + <property name="frameShape"> + <enum>QFrame::StyledPanel</enum> + </property> + <layout class="QHBoxLayout" name="_2"> + <property name="spacing"> + <number>6</number> + </property> + <property name="leftMargin"> + <number>0</number> + </property> + <property name="topMargin"> + <number>0</number> + </property> + <property name="rightMargin"> + <number>4</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item> + <spacer name="leftSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QLabel" name="stelWindowTitle"> + <property name="text"> + <string>Open Sky Planetarium</string> + </property> + </widget> + </item> + <item> + <spacer name="rightSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="closeStelWindow"> + <property name="minimumSize"> + <size> + <width>16</width> + <height>16</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>16</width> + <height>16</height> + </size> + </property> + <property name="focusPolicy"> + <enum>Qt::NoFocus</enum> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QTabWidget" name="tabWidg"> + <property name="tabPosition"> + <enum>QTabWidget::North</enum> + </property> + <property name="tabShape"> + <enum>QTabWidget::Rounded</enum> + </property> + <property name="currentIndex"> + <number>2</number> + </property> + <property name="movable"> + <bool>false</bool> + </property> + <property name="tabBarAutoHide"> + <bool>false</bool> + </property> + <widget class="QWidget" name="calTab"> + <attribute name="title"> + <string>Calibration</string> + </attribute> + <layout class="QHBoxLayout" name="horizontalLayout_4"> + <item> + <layout class="QVBoxLayout" name="verticalLayout_8"> + <item> + <widget class="QGroupBox" name="laserDirControl"> + <property name="toolTip"> + <string/> + </property> + <property name="title"> + <string>LASER Direction Control</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="2" column="2"> + <widget class="QPushButton" name="mvDown"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Makes the LASER move downward only if it is not at (0,0).</string> + </property> + <property name="text"> + <string>down</string> + </property> + </widget> + </item> + <item row="0" column="2"> + <widget class="QPushButton" name="mvUp"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Makes the LASER move upwards upto 90 degrees from (0,0).</string> + </property> + <property name="text"> + <string>up</string> + </property> + </widget> + </item> + <item row="1" column="3"> + <widget class="QPushButton" name="mvRight"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Makes the LASER move rightwards upto 360 degrees from (0,0).</string> + </property> + <property name="text"> + <string>right</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QPushButton" name="mvLeft"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Makes the LASER move leftwards only if it is not at (0,0).</string> + </property> + <property name="text"> + <string>left</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="4"> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="2"> + <widget class="QPushButton" name="reset"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Takes the LASER to (0,0).</string> + </property> + <property name="text"> + <string>reset</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="MotorSwitchingControl"> + <property name="title"> + <string>Motor Speed Control</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <spacer name="horizontalSpacer_6"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>46</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QRadioButton" name="CoarseAdj"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="focusPolicy"> + <enum>Qt::StrongFocus</enum> + </property> + <property name="toolTip"> + <string>Makes the movement of LASER fast during its direction control.</string> + </property> + <property name="text"> + <string>Coarse</string> + </property> + <property name="checked"> + <bool>false</bool> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="FineAdj"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Makes the movement of LASER slow during its direction control. </string> + </property> + <property name="text"> + <string>Fine</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_5"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>45</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="laserlightControl"> + <property name="contextMenuPolicy"> + <enum>Qt::PreventContextMenu</enum> + </property> + <property name="toolTip"> + <string/> + </property> + <property name="title"> + <string>LASER Light Control</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set> + </property> + <layout class="QFormLayout" name="formLayout"> + <item row="0" column="0"> + <spacer name="horizontalSpacer_3"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="0" column="1"> + <widget class="QRadioButton" name="laserOn"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="focusPolicy"> + <enum>Qt::StrongFocus</enum> + </property> + <property name="toolTip"> + <string>Turns the LASER on and enables slider to control intensity.</string> + </property> + <property name="text"> + <string>Turn ON</string> + </property> + <property name="checked"> + <bool>false</bool> + </property> + <attribute name="buttonGroup"> + <string notr="true">buttonGroup</string> + </attribute> + </widget> + </item> + <item row="2" column="1"> + <widget class="QRadioButton" name="laserOff"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Turns the LASER off and sends the slider to its initial position. </string> + </property> + <property name="text"> + <string>Turn OFF</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + <attribute name="buttonGroup"> + <string notr="true">buttonGroup</string> + </attribute> + </widget> + </item> + <item row="3" column="1"> + <spacer name="horizontalSpacer_4"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="4" column="0" colspan="2"> + <widget class="QSlider" name="intensity"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Controls the intensity of LASER. Drag the slider to change the intensity.</string> + </property> + <property name="minimum"> + <number>50</number> + </property> + <property name="maximum"> + <number>255</number> + </property> + <property name="value"> + <number>50</number> + </property> + <property name="sliderPosition"> + <number>50</number> + </property> + <property name="tracking"> + <bool>false</bool> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + </layout> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QVBoxLayout" name="verticalLayout_6"> + <item> + <widget class="QGroupBox" name="configDevice"> + <property name="title"> + <string>Device Configuration</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_5"> + <item> + <widget class="QPushButton" name="selectDev"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="toolTip"> + <string>Selects the connected device.</string> + </property> + <property name="text"> + <string>Select</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="startCal"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Initializes calibration using 2 or 3 reference stars. Also, it sets the current position of LASER as (0,0).</string> + </property> + <property name="text"> + <string>Start Calibrate</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="goTo"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Takes the LASER to selected star after calibration has been accomplished.</string> + </property> + <property name="text"> + <string>GoTo</string> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="refStatus"> + <property name="title"> + <string>Reference Status</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_7"> + <item> + <widget class="QPushButton" name="setRef"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Sets reference when a star is selected. It is disabled when three references have been set successfully.</string> + </property> + <property name="text"> + <string>Set Ref.</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="refStat"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="toolTip"> + <string>Displays the number of references set.</string> + </property> + <property name="text"> + <string>0/3</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + <property name="readOnly"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox_2"> + <property name="toolTip"> + <string/> + </property> + <property name="title"> + <string>Current Coordinates</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_5"> + <item> + <widget class="QLabel" name="label"> + <property name="toolTip"> + <string>Displays the current horizontal position of LASER in degrees. </string> + </property> + <property name="text"> + <string>X:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="X"> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_6"> + <item> + <widget class="QLabel" name="label_3"> + <property name="toolTip"> + <string>Displays the current vertical position of LASER in degrees.</string> + </property> + <property name="text"> + <string>Y:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="Y"> + <property name="text"> + <string/> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <widget class="QWidget" name="scriptTab"> + <attribute name="title"> + <string>ScriptEngine</string> + </attribute> + <widget class="QSplitter" name="splitter"> + <property name="geometry"> + <rect> + <x>341</x> + <y>41</y> + <width>101</width> + <height>291</height> + </rect> + </property> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <widget class="QSlider" name="volumeChanged"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="cursor"> + <cursorShape>BusyCursor</cursorShape> + </property> + <property name="value"> + <number>50</number> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + <widget class="QPushButton" name="playui"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Play</string> + </property> + </widget> + <widget class="QPushButton" name="stopui"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>Stop</string> + </property> + </widget> + <widget class="QPushButton" name="openScript"> + <property name="text"> + <string>Open</string> + </property> + </widget> + <widget class="QPushButton" name="saveScript"> + <property name="text"> + <string>Save</string> + </property> + </widget> + <widget class="QPushButton" name="compScript"> + <property name="text"> + <string>Build</string> + </property> + </widget> + <widget class="QPushButton" name="execScript"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>Build + Run</string> + </property> + </widget> + </widget> + <widget class="QSplitter" name="splitter_2"> + <property name="geometry"> + <rect> + <x>10</x> + <y>10</y> + <width>431</width> + <height>23</height> + </rect> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <widget class="QPushButton" name="gt"> + <property name="text"> + <string>Goto</string> + </property> + </widget> + <widget class="QPushButton" name="pl"> + <property name="text"> + <string>Audio</string> + </property> + </widget> + <widget class="QPushButton" name="wt"> + <property name="text"> + <string>WAIT</string> + </property> + </widget> + <widget class="QPushButton" name="lo"> + <property name="text"> + <string>LASER ON/OFF</string> + </property> + </widget> + </widget> + <widget class="QTextEdit" name="scriptEdit"> + <property name="geometry"> + <rect> + <x>13</x> + <y>42</y> + <width>321</width> + <height>291</height> + </rect> + </property> + <property name="autoFillBackground"> + <bool>true</bool> + </property> + <property name="inputMethodHints"> + <set>Qt::ImhLowercaseOnly|Qt::ImhMultiLine|Qt::ImhNoAutoUppercase</set> + </property> + <property name="frameShape"> + <enum>QFrame::StyledPanel</enum> + </property> + <property name="readOnly"> + <bool>false</bool> + </property> + </widget> + </widget> + <widget class="QWidget" name="abtTab"> + <attribute name="title"> + <string>About</string> + </attribute> + <layout class="QVBoxLayout" name="verticalLayout_4"> + <item> + <widget class="QTextBrowser" name="textBrowser"> + <property name="html"> + <string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> +<html><head><meta name="qrichtext" content="1" /><style type="text/css"> +p, li { white-space: pre-wrap; } +</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:20pt; font-weight:600; text-decoration: underline;">OpenSkyPlanetarium</span></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">An Open Source Initiative by IIT Bombay to bring interesting objects in the Open Sky closer to the common masses and school childrens.</p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Contact: IIT Bombay</p> +<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Email: openskyplanetarium@fossee.in</p></body></html></string> + </property> + </widget> + </item> + </layout> + </widget> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>BarFrame</class> + <extends>QFrame</extends> + <header>Dialog.hpp</header> + <container>1</container> + </customwidget> + </customwidgets> + <resources/> + <connections/> + <buttongroups> + <buttongroup name="buttonGroup"/> + </buttongroups> +</ui> |