[kstars] kstars/ekos/align: This patch adds export functionality to the solutions table, a spin box for the mount model wizard align point number, makes nicely formatted greek names appear in the greek names box, and makes the wizard search for stars in the alignment list in its search radius

Jasem Mutlaq null at kde.org
Fri Mar 10 09:33:08 UTC 2017


Git commit b44d8b45651be5a89160d7e8c790b744e67b29ab by Jasem Mutlaq, on behalf of Robert Lancaster.
Committed on 10/03/2017 at 09:32.
Pushed by mutlaqja into branch 'master'.

This patch adds export functionality to the solutions table, a spin box for the mount model wizard align point number, makes nicely formatted greek names appear in the greek names box, and makes the wizard search for stars in the alignment list in its search radius
before just finding the nearest obscure object near the alignment point.

CCMAIL:kstars-devel at kde.org

M  +116  -21   kstars/ekos/align/align.cpp
M  +2    -0    kstars/ekos/align/align.h
M  +24   -2    kstars/ekos/align/align.ui
M  +114  -108  kstars/ekos/align/mountmodel.ui

https://commits.kde.org/kstars/b44d8b45651be5a89160d7e8c790b744e67b29ab

diff --git a/kstars/ekos/align/align.cpp b/kstars/ekos/align/align.cpp
index 29e6d701e..57df6e889 100644
--- a/kstars/ekos/align/align.cpp
+++ b/kstars/ekos/align/align.cpp
@@ -321,6 +321,9 @@ Align::Align()
     removeSolutionB->setIcon(QIcon::fromTheme("list-remove", QIcon(":/icons/breeze/default/list-remove.svg") ));
     removeSolutionB->setAttribute(Qt::WA_LayoutUsesWidgetRect);
 
+    exportSolutionsCSV->setIcon(QIcon::fromTheme("document-save-as", QIcon(":/icons/breeze/default/document-save-as.svg") ));
+    exportSolutionsCSV->setAttribute(Qt::WA_LayoutUsesWidgetRect);
+
 
     mountModel.setupUi(&mountModelDialog);
     mountModelDialog.setWindowTitle("Mount Model Tool");
@@ -330,9 +333,6 @@ Align::Align()
     mountModel.alignTable->setColumnWidth(2,80);
     mountModel.alignTable->setColumnWidth(3,30);
 
-    for(int i=1;i<20;i++)
-        mountModel.alignPtNum->addItem(QString::number(i+1));
-
     mountModel.wizardAlignB->setIcon(QIcon::fromTheme("tools-wizard", QIcon(":/icons/breeze/default/tools-wizard.svg") ));
     mountModel.wizardAlignB->setAttribute(Qt::WA_LayoutUsesWidgetRect);
 
@@ -375,6 +375,7 @@ Align::Align()
 
     connect(clearAllSolutionsB, SIGNAL(clicked()), this, SLOT(slotClearAllSolutionPoints()));
     connect(removeSolutionB, SIGNAL(clicked()), this, SLOT(slotRemoveSolutionPoint()));
+    connect(exportSolutionsCSV, SIGNAL(clicked()), this, SLOT(exportSolutionPoints()));
     connect(mountModelB, SIGNAL(clicked()), this, SLOT(slotMountModel()));
     connect(solutionTable, SIGNAL(cellClicked(int, int)), this, SLOT(selectSolutionTableRow(int, int)));
 
@@ -557,8 +558,7 @@ void Align::buildTarget(){
 }
 
 void Align::slotWizardAlignmentPoints(){
-    QString numText=mountModel.alignPtNum->currentText();
-    int points=numText.toInt();
+    int points=mountModel.alignPtNum->value();
     if(points<2)
         return;
     double angle = 120 / (points-1);  //180 degrees of sky - 30 degrees at each horizon.
@@ -568,13 +568,11 @@ void Align::slotWizardAlignmentPoints(){
     spWest.setAz(270);
     spWest.HorizontalToEquatorial(KStars::Instance()->data()->lst(), KStars::Instance()->data()->geo()->lat());
 
-
     for(int i=0;i<points;i++){
         double ra=spWest.ra().Degrees()+i*angle;
         double dec=spWest.dec().Degrees();
 
-        double maxrad = 10000.0/Options::zoomFactor();
-        SkyObject *o = KStarsData::Instance()->skyComposite()->objectNearest(new SkyPoint(dms(ra),dms(dec)), maxrad );
+        const SkyObject *o = getClosestAlignStar(ra,dec,angle);
 
         if(o){
             int currentRow = mountModel.alignTable->rowCount();
@@ -594,7 +592,7 @@ void Align::slotWizardAlignmentPoints(){
             mountModel.alignTable->setItem(currentRow, 1, DECReport);
 
             QTableWidgetItem *ObjNameReport = new QTableWidgetItem();
-            ObjNameReport->setText(o->name());
+            ObjNameReport->setText(o->longname());
             ObjNameReport->setTextAlignment(Qt::AlignHCenter);
             mountModel.alignTable->setItem(currentRow, 2, ObjNameReport);
 
@@ -604,16 +602,40 @@ void Align::slotWizardAlignmentPoints(){
         }
 
     }
+}
 
-
+const SkyObject* Align::getClosestAlignStar(double ra, double dec, double angle){
+    double bestDiff=360;
+    double index=-1;
+     for(int i=0;i<alignStars.size();i++){
+         QPair<QString, const SkyObject *> pair=alignStars.value(i);
+         const SkyObject *o=pair.second;
+         if( o != 0 ) {
+             double thisRADiff=qAbs(ra-(o->ra().Degrees()));
+             double thisDEDiff=qAbs(dec-(o->dec().Degrees()));
+             double thisDiff=qSqrt(thisRADiff*thisRADiff+thisDEDiff*thisDEDiff);
+             if(thisDiff<bestDiff){
+                 index=i;
+                 bestDiff=thisDiff;
+             }
+         }
+     }
+     if(index==-1||bestDiff>angle){
+         double maxSearch=5.0;
+         SkyObject *o = KStarsData::Instance()->skyComposite()->starNearest(new SkyPoint(dms(ra),dms(dec)), maxSearch );
+         return o;
+     }
+    QPair<QString, const SkyObject *> pair=alignStars.value(index);
+    qDebug()<<pair.first;
+    return pair.second;
 }
 
 void Align::slotStarSelected(const QString selectedStar){
     for(int i=0;i<alignStars.size();i++){
         QPair<QString, const SkyObject *> pair=alignStars.value(i);
-        if(pair.first==selectedStar){
-            const SkyObject *o=pair.second;
-            if( o != 0 ) {
+        const SkyObject *o=pair.second;
+        if( o != 0 ) {
+            if(pair.first==selectedStar||o->longname()==selectedStar){
                 int currentRow = mountModel.alignTable->rowCount();
                 mountModel.alignTable->insertRow(currentRow);
 
@@ -631,7 +653,7 @@ void Align::slotStarSelected(const QString selectedStar){
                 mountModel.alignTable->setItem(currentRow, 1, DECReport);
 
                 QTableWidgetItem *ObjNameReport = new QTableWidgetItem();
-                ObjNameReport->setText(o->name());
+                ObjNameReport->setText(o->longname());
                 ObjNameReport->setTextAlignment(Qt::AlignHCenter);
                 mountModel.alignTable->setItem(currentRow, 2, ObjNameReport);
 
@@ -656,13 +678,19 @@ void Align::generateAlignStarList(){
 
     for(int i=0;i<alignStars.size();i++){
         QPair<QString, const SkyObject *> pair=alignStars.value(i);
-        if(!isVisible(pair.second))
+        if(!isVisible(pair.second)){
             alignStars.remove(i);
-        else if(pair.first.startsWith("HD"))
+            i--;
+        }else if(pair.first.startsWith("HD")){
             alignStars.remove(i);
-        else{
-            if(pair.first.startsWith("alpha")||pair.first.startsWith("beta")||pair.first.startsWith("delta")||pair.first.startsWith("gamma")||pair.first.startsWith("epsilon")||pair.first.startsWith("zeta")||pair.first.startsWith("sigma")||pair.first.startsWith("chi")||pair.first.startsWith("xi")||pair.first.startsWith("kappa")||pair.first.startsWith("eta")||pair.first.startsWith("mu")||pair.first.startsWith("nu")||pair.first.startsWith("theta")||pair.first.startsWith("psi")||pair.first.startsWith("iota")||pair.first.startsWith("lambda")||pair.first.startsWith("omicron"))
-                greekBoxNames << pair.first;
+            i--;
+        }else{
+            if(pair.first.startsWith("alpha")||pair.first.startsWith("beta")||pair.first.startsWith("gamma")||pair.first.startsWith("delta")||pair.first.startsWith("epsilon")||pair.first.startsWith("zeta")||pair.first.startsWith("eta")||pair.first.startsWith("theta")||pair.first.startsWith("iota")||pair.first.startsWith("kappa")||pair.first.startsWith("lambda")||pair.first.startsWith("mu")||pair.first.startsWith("nu")||pair.first.startsWith("xi")||pair.first.startsWith("omicron")||pair.first.startsWith("pi")||pair.first.startsWith("rho")||pair.first.startsWith("sigma")||pair.first.startsWith("tau")||pair.first.startsWith("upsilon")||pair.first.startsWith("phi")||pair.first.startsWith("chi")||pair.first.startsWith("psi")||pair.first.startsWith("omega"))
+            {
+                const SkyObject *o=pair.second;
+                if( o != 0 )
+                    greekBoxNames << o->longname();
+            }
             else
                 boxNames << pair.first;
         }
@@ -683,7 +711,11 @@ void Align::generateAlignStarList(){
 }
 
 bool Align::isVisible(const SkyObject *so){
-    return (getAltitude(so) > 30);
+    //QList<double> limits=Ekos::Mount *mountModule()->getAltitudeLimits();
+   // if(limits.first()>30)
+   //     return (getAltitude(so) > limits.first());
+  //  else
+        return (getAltitude(so) > 30);
 }
 
 double Align::getAltitude(const SkyObject *so){
@@ -886,12 +918,75 @@ bool Align::saveAlignmentPoints(const QString &path){
         outstream << "</AlignmentPoint>" << endl;
     }
     outstream << "</AlignmentList>" << endl;
-    appendLogText(i18n("Sequence queue saved to %1", path));
+    appendLogText(i18n("Alignment List saved to %1", path));
     file.close();
     return true;
 
 }
 
+void Align::exportSolutionPoints(){
+
+    QUrl exportFile = QFileDialog::getSaveFileUrl(KStars::Instance(), i18n("Export Solution Points"), alignURLPath, "CSV File (*.csv)");
+    if (exportFile.isEmpty())   // if user presses cancel
+        return;
+    if (exportFile.toLocalFile().endsWith(".csv") == false)
+        exportFile.setPath(exportFile.toLocalFile() + ".csv");
+
+    QString path=exportFile.toLocalFile();
+
+    if (QFile::exists(path))
+    {
+        int r = KMessageBox::warningContinueCancel(0,
+                    i18n( "A file named \"%1\" already exists. "
+                          "Overwrite it?", exportFile.fileName() ),
+                    i18n( "Overwrite File?" ),
+                    KStandardGuiItem::overwrite() );
+        if(r==KMessageBox::Cancel) return;
+    }
+
+    if ( !exportFile.isValid() )
+    {
+        QString message = i18n( "Invalid URL: %1", exportFile.url() );
+        KMessageBox::sorry(KStars::Instance(), message, i18n( "Invalid URL" ) );
+        return;
+    }
+
+    QFile file;
+    file.setFileName(path);
+    if ( !file.open( QIODevice::WriteOnly))
+    {
+        QString message = i18n( "Unable to write to file %1",  path);
+        KMessageBox::sorry( 0, message, i18n( "Could Not Open File" ) );
+        return;
+    }
+
+    QTextStream outstream(&file);
+
+    outstream << "RA,DE,Name,RA Error (arcsec),DE Error (arcsec)"<< endl;
+
+    for (int i=0; i < solutionTable->rowCount(); i++)
+    {
+        QTableWidgetItem *raCell=solutionTable->item(i,0);
+        QTableWidgetItem *deCell=solutionTable->item(i,1);
+        QTableWidgetItem *objNameCell=solutionTable->item(i,2);
+        QTableWidgetItem *raErrorCell=solutionTable->item(i,4);
+        QTableWidgetItem *deErrorCell=solutionTable->item(i,5);
+
+        if(!raCell||!deCell||!objNameCell||!raErrorCell||!deErrorCell){
+            KMessageBox::sorry( 0, i18n( "Error in table structure." ) );
+            return;
+        }
+        outstream << raCell->text()<<","
+                  << deCell->text()<<","
+                  << objNameCell->text()<<","
+                  << raErrorCell->text().remove("\"")<<","
+                  << deErrorCell->text().remove("\"")
+                  << endl;
+    }
+    appendLogText(i18n("Solution Points Saved as: %1", path));
+    file.close();
+}
+
 void Align::slotClearAllSolutionPoints()
 {
     if (solutionTable->rowCount() == 0)
diff --git a/kstars/ekos/align/align.h b/kstars/ekos/align/align.h
index 6ced9da20..154675ae9 100644
--- a/kstars/ekos/align/align.h
+++ b/kstars/ekos/align/align.h
@@ -388,6 +388,7 @@ private slots:
     void startAlignmentPoint();
     void finishAlignmentPoint(bool solverSucceeded);
     void moveAlignPoint(int logicalIndex, int oldVisualIndex, int newVisualIndex);
+    void exportSolutionPoints();
 
 signals:
         void newLog();
@@ -626,6 +627,7 @@ private:
     void generateAlignStarList();
     bool isVisible(const SkyObject *so);
     double getAltitude(const SkyObject *so);
+    const SkyObject* getClosestAlignStar(double ra, double de, double angle);
 };
 
 }
diff --git a/kstars/ekos/align/align.ui b/kstars/ekos/align/align.ui
index c915675dc..44952d37d 100644
--- a/kstars/ekos/align/align.ui
+++ b/kstars/ekos/align/align.ui
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>602</width>
-    <height>459</height>
+    <width>682</width>
+    <height>529</height>
    </rect>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout_19">
@@ -915,6 +915,28 @@
                  </widget>
                 </item>
                 <item>
+                 <widget class="QPushButton" name="exportSolutionsCSV">
+                  <property name="minimumSize">
+                   <size>
+                    <width>32</width>
+                    <height>32</height>
+                   </size>
+                  </property>
+                  <property name="maximumSize">
+                   <size>
+                    <width>32</width>
+                    <height>33</height>
+                   </size>
+                  </property>
+                  <property name="toolTip">
+                   <string><html><head/><body><p>Export all of the solutions in the Solution Results table to CSV file of your choosing for further analysis in a spreadsheet.</p></body></html></string>
+                  </property>
+                  <property name="text">
+                   <string/>
+                  </property>
+                 </widget>
+                </item>
+                <item>
                  <spacer name="horizontalSpacer_11">
                   <property name="orientation">
                    <enum>Qt::Horizontal</enum>
diff --git a/kstars/ekos/align/mountmodel.ui b/kstars/ekos/align/mountmodel.ui
index f68d8fead..5231cf177 100644
--- a/kstars/ekos/align/mountmodel.ui
+++ b/kstars/ekos/align/mountmodel.ui
@@ -32,61 +32,55 @@
      <property name="title">
       <string>Mount Model Wizard</string>
      </property>
-     <layout class="QVBoxLayout" name="verticalLayout_3">
-      <property name="leftMargin">
-       <number>3</number>
-      </property>
-      <property name="topMargin">
-       <number>3</number>
-      </property>
-      <property name="rightMargin">
-       <number>3</number>
-      </property>
-      <property name="bottomMargin">
-       <number>3</number>
-      </property>
+     <layout class="QHBoxLayout" name="horizontalLayout_3">
       <item>
-       <layout class="QHBoxLayout" name="horizontalLayout_3">
-        <property name="topMargin">
-         <number>0</number>
+       <widget class="QLabel" name="label_2">
+        <property name="text">
+         <string>Number of Points</string>
         </property>
-        <item>
-         <widget class="QLabel" name="label_2">
-          <property name="text">
-           <string>Number of Points</string>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <widget class="QComboBox" name="alignPtNum">
-          <property name="toolTip">
-           <string><html><head/><body><p>This is the number of alignment points that the wizard will add to the table.</p></body></html></string>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <widget class="QPushButton" name="wizardAlignB">
-          <property name="minimumSize">
-           <size>
-            <width>32</width>
-            <height>32</height>
-           </size>
-          </property>
-          <property name="maximumSize">
-           <size>
-            <width>32</width>
-            <height>32</height>
-           </size>
-          </property>
-          <property name="toolTip">
-           <string><html><head/><body><p>This button will automatically generate the specified number of alignment points in the table below.  They will be equally spread across the sky from 30 degrees above the horizon in the west to 30 degrees above the horizon in the east.</p></body></html></string>
-          </property>
-          <property name="text">
-           <string/>
-          </property>
-         </widget>
-        </item>
-       </layout>
+       </widget>
+      </item>
+      <item>
+       <widget class="QSpinBox" name="alignPtNum">
+        <property name="minimum">
+         <number>2</number>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QPushButton" name="wizardAlignB">
+        <property name="minimumSize">
+         <size>
+          <width>32</width>
+          <height>32</height>
+         </size>
+        </property>
+        <property name="maximumSize">
+         <size>
+          <width>32</width>
+          <height>32</height>
+         </size>
+        </property>
+        <property name="toolTip">
+         <string><html><head/><body><p>Automatically generate the specified number of alignment points in the table below.  They will be equally spread across the sky from 30 degrees above the horizon in the west to 30 degrees above the horizon in the east.</p></body></html></string>
+        </property>
+        <property name="text">
+         <string/>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <spacer name="horizontalSpacer_3">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>171</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
       </item>
      </layout>
     </widget>
@@ -96,60 +90,59 @@
      <property name="title">
       <string>Currently Visible Stars</string>
      </property>
-     <layout class="QVBoxLayout" name="verticalLayout_4">
-      <property name="leftMargin">
-       <number>3</number>
-      </property>
-      <property name="topMargin">
-       <number>3</number>
-      </property>
-      <property name="rightMargin">
-       <number>3</number>
-      </property>
-      <property name="bottomMargin">
-       <number>3</number>
-      </property>
-      <item>
-       <layout class="QHBoxLayout" name="horizontalLayout_4">
-        <property name="topMargin">
-         <number>0</number>
+     <layout class="QGridLayout" name="gridLayout">
+      <item row="0" column="0">
+       <widget class="QLabel" name="label_4">
+        <property name="text">
+         <string>Common Names</string>
         </property>
-        <item>
-         <widget class="QLabel" name="label_4">
-          <property name="text">
-           <string>Common Names</string>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <widget class="QComboBox" name="starListBox">
-          <property name="toolTip">
-           <string><html><head/><body><p>These are the common names for the named stars that are currently up at your location.  If you select a star, it will be added to the table below.</p></body></html></string>
-          </property>
-         </widget>
-        </item>
-       </layout>
+       </widget>
       </item>
-      <item>
-       <layout class="QHBoxLayout" name="horizontalLayout_5">
-        <property name="topMargin">
-         <number>0</number>
+      <item row="0" column="1">
+       <widget class="QComboBox" name="starListBox">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
         </property>
-        <item>
-         <widget class="QLabel" name="label_5">
-          <property name="text">
-           <string>Greek</string>
-          </property>
-         </widget>
-        </item>
-        <item>
-         <widget class="QComboBox" name="greekStarListBox">
-          <property name="toolTip">
-           <string><html><head/><body><p>These are the Greek names for the brighter stars that are currently up at your location.  If you select a star, it will be added to the table below.</p></body></html></string>
-          </property>
-         </widget>
-        </item>
-       </layout>
+        <property name="toolTip">
+         <string><html><head/><body><p>These are the common names for the named stars that are currently up at your location.  If you select a star, it will be added to the table below.</p></body></html></string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="2" rowspan="2">
+       <spacer name="horizontalSpacer_4">
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>125</width>
+          <height>20</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="label_5">
+        <property name="text">
+         <string>Greek</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1">
+       <widget class="QComboBox" name="greekStarListBox">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
+          <horstretch>0</horstretch>
+          <verstretch>0</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="toolTip">
+         <string><html><head/><body><p>These are the Greek names for the brighter stars that are currently up at your location.  If you select a star, it will be added to the table below.</p></body></html></string>
+        </property>
+       </widget>
       </item>
      </layout>
     </widget>
@@ -268,6 +261,19 @@
           </property>
          </widget>
         </item>
+        <item>
+         <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>
        </layout>
       </item>
       <item>
@@ -397,7 +403,7 @@
       </spacer>
      </item>
      <item>
-      <widget class="QPushButton" name="stopAlignB">
+      <widget class="QPushButton" name="startAlignB">
        <property name="minimumSize">
         <size>
          <width>32</width>
@@ -411,7 +417,7 @@
         </size>
        </property>
        <property name="toolTip">
-        <string><html><head/><body><p>Stop the mount model routine.  It will <b>not</b> clear any points from your telescope's pointing model.  It will stop the routine and any points currently being solved. If you run the mount model again after hitting stop, it will start the routine over again with the first point.</p></body></html></string>
+        <string><html><head/><body><p>Start or pause the mount model routine.  It will slew to and astrometrically solve the list of points in the table above using the settings in the align module.  If the routine was previously paused, it will pick up where it left off.  If it was stopped or it had finished it will start the routine over again.</p></body></html></string>
        </property>
        <property name="text">
         <string/>
@@ -419,7 +425,7 @@
       </widget>
      </item>
      <item>
-      <widget class="QPushButton" name="startAlignB">
+      <widget class="QPushButton" name="stopAlignB">
        <property name="minimumSize">
         <size>
          <width>32</width>
@@ -433,7 +439,7 @@
         </size>
        </property>
        <property name="toolTip">
-        <string><html><head/><body><p>Start or pause the mount model routine.  It will slew to and astrometrically solve the list of points in the table above using the settings in the align module.  If the routine was previously paused, it will pick up where it left off.  If it was stopped or it had finished it will start the routine over again.</p></body></html></string>
+        <string><html><head/><body><p>Stop the mount model routine.  It will <b>not</b> clear any points from your telescope's pointing model.  It will stop the routine and any points currently being solved. If you run the mount model again after hitting stop, it will start the routine over again with the first point.</p></body></html></string>
        </property>
        <property name="text">
         <string/>


More information about the Kstars-devel mailing list