[Kstars-devel] KDE/kdeedu/kstars/kstars

Akarsh Simha akarshsimha at gmail.com
Fri Feb 13 13:11:20 CET 2009


SVN commit 925486 by asimha:

Adding functionality to calculate and display the magnitude of the
moon. The tables for the magnitude vs. phase are taken from the
SkyChart source code.

This fixes wishlist 182551.

FEATURE: 182551
CCMAIL: kstars-devel at kde.org



 M  +6 -5      detaildialog.cpp  
 M  +57 -39    details_data.ui  
 M  +6 -0      ksmoon.cpp  
 M  +24 -0     ksmoon.h  
 M  +21 -1     ksplanetbase.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/detaildialog.cpp #925485:925486
@@ -109,6 +109,8 @@
     #endif
     connect( Data->Image, SIGNAL( clicked() ), this, SLOT( updateThumbnail() ) );
 
+    Data->IllumLabel->setVisible( false );
+
     //Show object thumbnail image
     showThumbnail();
 
@@ -186,13 +188,12 @@
 
         //Magnitude: The moon displays illumination fraction instead
         if ( selectedObject->name() == "Moon" ) {
-            Data->MagLabel->setText( i18n("Illumination:") );
-            Data->Magnitude->setText( QString("%1 %").arg( KGlobal::locale()->formatNumber( ((KSMoon *)selectedObject)->illum()*100., 0 ) ) );
-        } else {
-            Data->Magnitude->setText( i18nc( "number in magnitudes", "%1 mag" ,
-                                             KGlobal::locale()->formatNumber( ps->mag(), 1 ) ) );  //show to tenths place
+            Data->IllumLabel->setVisible( true );
+            Data->Illumination->setText( QString("%1 %").arg( KGlobal::locale()->formatNumber( ((KSMoon *)selectedObject)->illum()*100., 0 ) ) );
         }
 
+        Data->Magnitude->setText( i18nc( "number in magnitudes", "%1 mag" ,
+                                         KGlobal::locale()->formatNumber( ps->mag(), 1 ) ) );  //show to tenths place
         //Distance from Earth.  The moon requires a unit conversion
         if ( ps->name() == "Moon" ) {
             Data->Distance->setText( i18nc("distance in kilometers", "%1 km",
--- trunk/KDE/kdeedu/kstars/kstars/details_data.ui #925485:925486
@@ -10,12 +10,12 @@
    </rect>
   </property>
   <layout class="QVBoxLayout" >
+   <property name="spacing" >
+    <number>0</number>
+   </property>
    <property name="margin" >
     <number>8</number>
    </property>
-   <property name="spacing" >
-    <number>0</number>
-   </property>
    <item>
     <widget class="QLabel" name="Names" >
      <property name="font" >
@@ -55,28 +55,28 @@
       <number>4</number>
      </property>
      <layout class="QHBoxLayout" >
+      <property name="spacing" >
+       <number>6</number>
+      </property>
       <property name="margin" >
        <number>8</number>
       </property>
-      <property name="spacing" >
-       <number>6</number>
-      </property>
       <item>
        <layout class="QVBoxLayout" >
+        <property name="spacing" >
+         <number>6</number>
+        </property>
         <property name="margin" >
          <number>0</number>
         </property>
-        <property name="spacing" >
-         <number>6</number>
-        </property>
         <item>
          <layout class="QHBoxLayout" >
+          <property name="spacing" >
+           <number>6</number>
+          </property>
           <property name="margin" >
            <number>0</number>
           </property>
-          <property name="spacing" >
-           <number>6</number>
-          </property>
           <item>
            <widget class="QLabel" name="Type" >
             <property name="text" >
@@ -103,7 +103,7 @@
             <property name="orientation" >
              <enum>Qt::Horizontal</enum>
             </property>
-            <property name="sizeHint" >
+            <property name="sizeHint" stdset="0" >
              <size>
               <width>40</width>
               <height>20</height>
@@ -118,7 +118,7 @@
           <property name="orientation" >
            <enum>Qt::Vertical</enum>
           </property>
-          <property name="sizeHint" >
+          <property name="sizeHint" stdset="0" >
            <size>
             <width>20</width>
             <height>40</height>
@@ -128,18 +128,16 @@
         </item>
         <item>
          <layout class="QHBoxLayout" >
+          <property name="spacing" >
+           <number>6</number>
+          </property>
           <property name="margin" >
            <number>0</number>
           </property>
-          <property name="spacing" >
-           <number>6</number>
-          </property>
           <item>
            <widget class="ClickLabel" name="Image" >
             <property name="sizePolicy" >
-             <sizepolicy>
-              <hsizetype>7</hsizetype>
-              <vsizetype>7</vsizetype>
+             <sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
               <horstretch>0</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
@@ -157,7 +155,7 @@
              </size>
             </property>
             <property name="cursor" >
-             <cursor>13</cursor>
+             <cursorShape>PointingHandCursor</cursorShape>
             </property>
             <property name="frameShape" >
              <enum>QFrame::StyledPanel</enum>
@@ -172,7 +170,7 @@
             <property name="orientation" >
              <enum>Qt::Horizontal</enum>
             </property>
-            <property name="sizeHint" >
+            <property name="sizeHint" stdset="0" >
              <size>
               <width>40</width>
               <height>20</height>
@@ -186,20 +184,20 @@
       </item>
       <item>
        <layout class="QVBoxLayout" >
+        <property name="spacing" >
+         <number>6</number>
+        </property>
         <property name="margin" >
          <number>0</number>
         </property>
-        <property name="spacing" >
-         <number>6</number>
-        </property>
         <item>
          <layout class="QHBoxLayout" >
+          <property name="spacing" >
+           <number>6</number>
+          </property>
           <property name="margin" >
            <number>0</number>
           </property>
-          <property name="spacing" >
-           <number>6</number>
-          </property>
           <item>
            <layout class="QGridLayout" >
             <property name="margin" >
@@ -283,6 +281,25 @@
               </property>
              </widget>
             </item>
+            <item row="3" column="0" >
+             <widget class="QLabel" name="IllumLabel" >
+              <property name="text" >
+               <string>Illumination:</string>
+              </property>
+             </widget>
+            </item>
+            <item row="3" column="1" >
+             <widget class="QLabel" name="Illumination" >
+              <property name="font" >
+               <font>
+                <family>Monospace</family>
+               </font>
+              </property>
+              <property name="text" >
+               <string/>
+              </property>
+             </widget>
+            </item>
            </layout>
           </item>
           <item>
@@ -290,7 +307,7 @@
             <property name="orientation" >
              <enum>Qt::Horizontal</enum>
             </property>
-            <property name="sizeHint" >
+            <property name="sizeHint" stdset="0" >
              <size>
               <width>40</width>
               <height>20</height>
@@ -305,7 +322,7 @@
           <property name="orientation" >
            <enum>Qt::Vertical</enum>
           </property>
-          <property name="sizeHint" >
+          <property name="sizeHint" stdset="0" >
            <size>
             <width>20</width>
             <height>40</height>
@@ -315,18 +332,18 @@
         </item>
         <item>
          <layout class="QHBoxLayout" >
+          <property name="spacing" >
+           <number>6</number>
+          </property>
           <property name="margin" >
            <number>0</number>
           </property>
-          <property name="spacing" >
-           <number>6</number>
-          </property>
           <item>
            <spacer>
             <property name="orientation" >
              <enum>Qt::Horizontal</enum>
             </property>
-            <property name="sizeHint" >
+            <property name="sizeHint" stdset="0" >
              <size>
               <width>40</width>
               <height>20</height>
@@ -336,12 +353,12 @@
           </item>
           <item>
            <layout class="QVBoxLayout" >
+            <property name="spacing" >
+             <number>6</number>
+            </property>
             <property name="margin" >
              <number>0</number>
             </property>
-            <property name="spacing" >
-             <number>6</number>
-            </property>
             <item>
              <widget class="QPushButton" name="ObsListButton" >
               <property name="text" >
@@ -371,7 +388,7 @@
               <property name="sizeType" >
                <enum>QSizePolicy::Fixed</enum>
               </property>
-              <property name="sizeHint" >
+              <property name="sizeHint" stdset="0" >
                <size>
                 <width>20</width>
                 <height>21</height>
@@ -386,7 +403,7 @@
             <property name="orientation" >
              <enum>Qt::Horizontal</enum>
             </property>
-            <property name="sizeHint" >
+            <property name="sizeHint" stdset="0" >
              <size>
               <width>40</width>
               <height>20</height>
@@ -408,6 +425,7 @@
    <class>ClickLabel</class>
    <extends>QFrame</extends>
    <header>widgets/clicklabel.h</header>
+   <container>1</container>
   </customwidget>
  </customwidgets>
  <resources/>
--- trunk/KDE/kdeedu/kstars/kstars/ksmoon.cpp #925485:925486
@@ -51,6 +51,11 @@
 QList<KSMoon::MoonLRData*> KSMoon::LRData;
 QList<KSMoon::MoonBData*> KSMoon::BData;
 
+const double KSMoon::MagArray[19] = {-12.7,-12.4,-12.1,-11.8,-11.5,-11.2,
+                               -11.0,-10.8,-10.4,-10.0,-9.6,-9.2,
+                               -8.7,-8.2,-7.6,-6.7,-3.4,0,0};
+
+
 bool KSMoon::loadData() {
     if (data_loaded) return true;
 
@@ -203,6 +208,7 @@
     return true;
 }
 
+
 void KSMoon::findPhase( const KSSun *Sun ) {
     Phase.setD( ecLong()->Degrees() - Sun->ecLong()->Degrees() );
     Phase.setD( Phase.reduce().Degrees() );
--- trunk/KDE/kdeedu/kstars/kstars/ksmoon.h #925485:925486
@@ -51,6 +51,11 @@
     	*/
     void findPhase( const KSSun *Sun );
 
+    /**
+     *@short Compute the magnitude of the moon
+     */
+    void findMagnitude(const KSNumbers *num);
+
     /**@return the moon's current phase angle, as a dms angle
     	*/
     dms phase( void ) const { return Phase; }
@@ -67,6 +72,24 @@
     	*/
     virtual bool loadData();
 
+    /*
+     * Data used to calculate moon magnitude
+     *
+     * Formula and data were obtained from SkyChart v3.x Beta
+     *
+     */
+    // intensities in Table 1 of M. Minnaert (1961),
+    // Phase  Frac.            Phase  Frac.            Phase  Frac.
+    // angle  ill.   Mag       angle  ill.   Mag       angle  ill.   Mag
+    //  0    1.00  -12.7        60   0.75  -11.0       120   0.25  -8.7
+    // 10    0.99  -12.4        70   0.67  -10.8       130   0.18  -8.2
+    // 20    0.97  -12.1        80   0.59  -10.4       140   0.12  -7.6
+    // 30    0.93  -11.8        90   0.50  -10.0       150   0.07  -6.7
+    // 40    0.88  -11.5       100   0.41   -9.6       160   0.03  -3.4
+    // 50    0.82  -11.2       110   0.33   -9.2
+    static const double MagArray[19];
+
+
 protected:
     /**Reimplemented from KSPlanetBase, this function employs unique algorithms for
     	*estimating the lunar coordinates.  Finding the position of the moon is
@@ -129,6 +152,7 @@
     };
 
     static QList<MoonBData*> BData;
+
 };
 
 #endif
--- trunk/KDE/kdeedu/kstars/kstars/ksplanetbase.cpp #925485:925486
@@ -142,7 +142,7 @@
         if ( Trail.size() > MAXTRAIL ) Trail.takeFirst();
     }
 
-    if ( isMajorPlanet() || type() == SkyObject::ASTEROID || type() == SkyObject::COMET )
+    if ( isMajorPlanet() || type() == SkyObject::ASTEROID || type() == SkyObject::COMET || type() == SkyObject::MOON )
         findMagnitude(num);
 }
 
@@ -311,6 +311,26 @@
     double param = 5 * log10(rsun() * rearth() );
     double f1 = phase/100.;
 
+    if( name() == "Moon" ) {
+        // This block of code to compute Moon magnitude (and the
+        // relevant data put into ksplanetbase.h) was taken from
+        // SkyChart v3 Beta
+        KSMoon *me = (KSMoon *)this;
+        int p = (int)( floor( me->phase().Degrees() ) );
+        if( p > 180 )
+            p = p - 360;
+        int i = p / 10;
+        int k = p - 10 * i;
+        int j = (i + 1 > 18) ? 18 : i + 1;
+        if( i < 0 )
+            i = -i;
+        if( j < 0 )
+            j = -j;
+        i = 18 - i;
+        j = 18 - j;
+        magnitude = KSMoon::MagArray[ i ] + ( ( KSMoon::MagArray[ j ] - KSMoon::MagArray[ i ] ) * k / 10 );
+    }
+
     if ( name() == i18n( "Mercury" ) ) {
         if ( phase > 150. ) f1 = 1.5;
         magnitude = -0.36 + param + 3.8*f1 - 2.73*f1*f1 + 2*f1*f1*f1;


More information about the Kstars-devel mailing list