[Kstars-devel] branches/kstars/unfrozen/kstars/kstars/tools

Jason Harris kstars at 30doradus.org
Thu Jul 3 07:14:35 CEST 2008


SVN commit 827475 by harris:

Applying variable timestep patch from trunk (r827206).

Akarsh, your commit message mentioned fixing a few bugs that my original patch 
revealed...was there anything besides reducing the tolerance of findPrecise() to 1 
minute?

Also adding a nice progress bar that appears in place of the Compute button while 
the computation takes place, and then disappears when it's done.

TODO: 

+ it would be nice to see conjunctions added to the results box as they are found, 
rather than waiting until the computation is finished.

+ Add a "Show conjunction" button that will set the date/time to the time found by 
the tool for the highlighted event, and set the focus to Object1.

CCMAIL: kstars-devel at kde.org



 M  +9 -2      conjunctions.cpp  
 M  +1 -0      conjunctions.h  
 M  +94 -38    conjunctions.ui  
 M  +49 -16    ksconjunct.cpp  
 M  +7 -2      ksconjunct.h  


--- branches/kstars/unfrozen/kstars/kstars/tools/conjunctions.cpp #827474:827475
@@ -86,7 +86,6 @@
   // signals and slots connections
   connect(LocationButton, SIGNAL(clicked()), this, SLOT(slotLocation()));
   connect(ComputeButton, SIGNAL(clicked()), this, SLOT(slotCompute()));
-  
   show();
 }
 
@@ -119,13 +118,21 @@
   Object2 = KSPlanetBase::createPlanet( Obj2ComboBox->currentIndex() );
 
   KSConjunct ksc;
+  ComputeStack->setCurrentIndex( 1 );
+  connect( &ksc, SIGNAL(madeProgress(int)), this, SLOT(showProgress(int)) );
+  
   showConjunctions(ksc.findClosestApproach(*Object1, *Object2, startJD, stopJD, maxSeparation));
-
+  ComputeStack->setCurrentIndex( 0 );
+    
   delete Object1;
   delete Object2;
 
 }
 
+void ConjunctionsTool::showProgress(int n) {
+  progress->setValue( n );
+}
+
 void ConjunctionsTool::showConjunctions(QMap<long double, dms> conjunctionlist) {
 
   KStarsDateTime dt;
--- branches/kstars/unfrozen/kstars/kstars/tools/conjunctions.h #827474:827475
@@ -49,6 +49,7 @@
 
     void slotLocation();
     void slotCompute();
+    void showProgress(int);
 
 private:
     void showConjunctions(QMap<long double, dms> conjunctionlist);
--- branches/kstars/unfrozen/kstars/kstars/tools/conjunctions.ui #827474:827475
@@ -5,8 +5,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>479</width>
-    <height>547</height>
+    <width>464</width>
+    <height>408</height>
    </rect>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout_2" >
@@ -96,41 +96,97 @@
     </layout>
    </item>
    <item>
-    <layout class="QHBoxLayout" name="horizontalLayout_2" >
-     <item>
-      <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>
-      <widget class="QPushButton" name="ComputeButton" >
-       <property name="text" >
-        <string>Compute</string>
-       </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>
+    <widget class="QStackedWidget" name="ComputeStack" >
+     <property name="sizePolicy" >
+      <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="currentIndex" >
+      <number>0</number>
+     </property>
+     <widget class="QWidget" name="page" >
+      <property name="geometry" >
+       <rect>
+        <x>0</x>
+        <y>0</y>
+        <width>456</width>
+        <height>40</height>
+       </rect>
+      </property>
+      <property name="sizePolicy" >
+       <sizepolicy vsizetype="Minimum" hsizetype="Preferred" >
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <layout class="QHBoxLayout" name="horizontalLayout_4" >
+       <item>
+        <layout class="QHBoxLayout" name="horizontalLayout_2" >
+         <item>
+          <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>
+          <widget class="QPushButton" name="ComputeButton" >
+           <property name="text" >
+            <string>Compute</string>
+           </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>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="page_2" >
+      <property name="geometry" >
+       <rect>
+        <x>0</x>
+        <y>0</y>
+        <width>456</width>
+        <height>40</height>
+       </rect>
+      </property>
+      <property name="sizePolicy" >
+       <sizepolicy vsizetype="Minimum" hsizetype="Preferred" >
+        <horstretch>0</horstretch>
+        <verstretch>0</verstretch>
+       </sizepolicy>
+      </property>
+      <layout class="QHBoxLayout" name="horizontalLayout_3" >
+       <item>
+        <widget class="QProgressBar" name="progress" >
+         <property name="value" >
+          <number>24</number>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+    </widget>
    </item>
    <item>
     <widget class="QGroupBox" name="groupBox_2" >
@@ -141,7 +197,7 @@
       <item>
        <widget class="QListWidget" name="OutputView" >
         <property name="sizePolicy" >
-         <sizepolicy vsizetype="MinimumExpanding" hsizetype="Expanding" >
+         <sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
           <horstretch>0</horstretch>
           <verstretch>0</verstretch>
          </sizepolicy>
--- branches/kstars/unfrozen/kstars/kstars/tools/ksconjunct.cpp #827474:827475
@@ -35,38 +35,68 @@
   QPair<long double, dms> extremum;
   dms Dist;
   dms prevDist;
-  double step;
+  double step, step0;
   int Sign, prevSign;
-  long double jd;
 
-  jd = startJD;
   ksdata = KStarsData::Instance();
-  prevDist = findDistance(jd, &Object1, &Object2);
   //  kDebug() << "Entered KSConjunct::findClosestApproach() with startJD = " << (double)startJD;
   //  kDebug() << "Initial Positional Information: \n";
   //  kDebug() << Object1.name() << ": RA = " << Object1.ra() -> toHMSString() << "; Dec = " << Object1.dec() -> toDMSString() << "\n";
   //  kDebug() << Object2.name() << ": RA = " << Object2.ra() -> toHMSString() << "; Dec = " << Object2.dec() -> toDMSString() << "\n";
   prevSign = 0;
   
-  step = (stopJD - startJD) / 4.0;
+  step0 = (stopJD - startJD) / 4.0;
   if(Object1.name() == "Mars" || Object2.name() == "Mars")
-    if (step > 10.0)
-      step = 10.0;
+    if (step0 > 10.0)
+      step0 = 10.0;
   if(Object1.name() == "Venus" || Object1.name() == "Mercury" || Object2.name() == "Mercury" || Object2.name() == "Venus") 
-    if (step > 5.0)
-      step = 5.0;
+    if (step0 > 5.0)
+      step0 = 5.0;
   if(Object1.name() == "Moon" || Object2.name() == "Moon")
-    if (step > 0.25)
-      step = 0.25;
+    if (step0 > 0.25)
+      step0 = 0.25;
 
-  //  kDebug() << "Initial Separation between " << Object1.name() << " and " << Object2.name() << " = " << (prevDist.toDMSString());
+  step = step0;
+  
+//  kDebug() << "Initial Separation between " << Object1.name() << " and " << Object2.name() << " = " << (prevDist.toDMSString());
 
-  for(jd = startJD + step; jd <= stopJD; jd += step) {
+  long double jd = startJD;
+  prevDist = findDistance(jd, &Object1, &Object2);
+  jd += step;
+  while ( jd <= stopJD ) {
+    int progress = int( 100.0*(jd - startJD)/(stopJD - startJD) );
+    emit madeProgress( progress );
+    
     Dist = findDistance(jd, &Object1, &Object2);
-    //    kDebug() << "Dist = " << Dist.toDMSString() << "; prevDist = " << prevDist.toDMSString() << "; Difference = " << (Dist - prevDist).toDMSString();
     Sign = sgn(Dist.Degrees() - prevDist.Degrees()); 
+//    kDebug() << "Dist = " << Dist.toDMSString() << "; prevDist = " << prevDist.toDMSString() << "; Difference = " << (Dist.Degrees() - prevDist.Degrees()) << "; Step = " << step;
 
-    if( Sign != prevSign ) {   
+    //How close are we to a conjunction, and how fast are we approaching one?
+    double factor = fabs( Dist.Degrees() / (Dist.Degrees() - prevDist.Degrees()) );
+    if ( factor > 10.0 ) { //let's go faster!
+        step = step0 * factor/10.0;
+    } else { //slow down, we're getting close!
+        step = step0;
+    }
+    
+    if( Sign != prevSign ) { //all right, we may have just passed a conjunction
+      if ( step > step0 ) { //mini-loop to back up and make sure we're close enough
+//        kDebug() << "Entering slow loop: " << endl;
+        jd -= step;
+        step = step0;
+        Sign = prevSign;
+        while ( jd <= stopJD ) {
+          Dist = findDistance(jd, &Object1, &Object2);
+          Sign = sgn(Dist.Degrees() - prevDist.Degrees()); 
+//          kDebug() << "Dist = " << Dist.toDMSString() << "; prevDist = " << prevDist.toDMSString() << "; Difference = " << (Dist.Degrees() - prevDist.Degrees());
+          if ( Sign != prevSign ) break;
+
+          prevDist = Dist;
+          prevSign = Sign;
+          jd += step;
+        }
+      }
+      
       //      kDebug() << "Sign = " << Sign << " and " << "prevSign = " << prevSign << ": Entering findPrecise()\n";
       if(findPrecise(&extremum, &Object1, &Object2, jd, step, prevSign))
         if(extremum.second.radians() < maxSeparation.radians())
@@ -75,6 +105,7 @@
 
     prevDist = Dist;
     prevSign = Sign;
+    jd += step;
   }
 
   return Separations;
@@ -121,7 +152,7 @@
     jd += step;
     Dist = findDistance(jd, Object1, Object2);
 
-    if(fabs(step) < 1.0 / 24.0) {
+    if(fabs(step) < 1.0 / (24.0*60.0) ) {
       out -> first = jd - step / 2.0;
       out -> second = findDistance(jd - step/2.0, Object1, Object2);
       if(out -> second.radians() < findDistance(jd - 5.0, Object1, Object2).radians())
@@ -147,3 +178,5 @@
   return ((a.radians() > 0)?1:((a.radians() < 0)?-1:0));
 
 }
+
+#include "ksconjunct.moc"
--- branches/kstars/unfrozen/kstars/kstars/tools/ksconjunct.h #827474:827475
@@ -20,6 +20,7 @@
 #define KSCONJUNCT_H_
 
 #include <QMap>
+#include <QObject>
 
 #include "dms.h"
 #include "ksplanet.h"
@@ -42,8 +43,9 @@
   *@version 1.0
   */
 
-class KSConjunct {
-
+class KSConjunct :public QObject {
+ Q_OBJECT
+ 
  public:
   /**
     *Constructor.  Instantiates a KSNumbers for internal computations.
@@ -71,6 +73,9 @@
 
   QMap<long double, dms> findClosestApproach(KSPlanetBase& Object1, KSPlanetBase& Object2, long double startJD, long double stopJD, dms maxSeparation);
 
+ signals:
+  void madeProgress( int progress );
+
  private:
 
 


More information about the Kstars-devel mailing list