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

Jason Harris kstars at 30doradus.org
Thu Dec 20 20:33:08 CET 2007


SVN commit 750975 by harris:

Enable the --script argument for image dump mode.  This mostly involved 
updating KStarsData::executeScript() to interpret DBUS lines instead of 
DCOP lines.

CCMAIL: kstars-devel at kde.org



 M  +49 -25    kstarsdata.cpp  
 M  +3 -3      main.cpp  
 M  +15 -16    skycomponents/customcatalogcomponent.cpp  
 M  +4 -2      skycomponents/deepskycomponent.cpp  


--- trunk/KDE/kdeedu/kstars/kstars/kstarsdata.cpp #750974:750975
@@ -973,22 +973,11 @@
     return true;
 }
 
-//FIXME: There's way too much code duplication here!
-//We should just execute the script through K3Process.
-//One complication is that we want to ignore some script commands
-//that don't make sense for dump mode.  However, it would be better
-//for the DCOP fcns themselves to detect whether a SkyMap object exists,
-//and act accordingly.
-//
-//"pseudo-execute" a shell script, ignoring all interactive aspects.  Just use
-//the portions of the script that change the state of the program.  This is only
-//used for image-dump mode, where the GUI is not running.  So, some things (such as
-//waitForKey()) don't make sense and should be ignored.
-//also, even functions that do make sense in this context have aspects that should
-//be modified or ignored.  For example, we don't need to call slotCenter() on recentering
-//commands, just setDestination().  (sltoCenter() does additional things that we do not need).
-
-//FIXME JM: This needs to be ported to DBus
+//There's a lot of code duplication here, but it's not avoidable because 
+//this function is only called from main.cpp when the user is using 
+//"dump" mode to produce an image from the command line.  In this mode, 
+//there is no KStars object, so none of the DBus functions can be called 
+//directly.
 bool KStarsData::executeScript( const QString &scriptname, SkyMap *map ) {
     int cmdCount(0);
 
@@ -1001,12 +990,36 @@
     QTextStream istream(&f);
     while ( ! istream.atEnd() ) {
         QString line = istream.readLine();
+        line.replace( "string:", "" );
+        line.replace( "int:", "" );
+        line.replace( "double:", "" );
+        line.replace( "bool:", "");
 
-        //found a dcop line
-        if ( line.startsWith(QLatin1String("dcop")) ) {
-            line = line.mid( 20 );  //strip away leading characters
-            QStringList fn = line.split( ' ' );
+        //find a dbus line and extract the function name and its arguments
+        //The function name starts after the last occurance of "org.kde.kstars."
+        //or perhaps "org.kde.kstars.SimClock.".
+        if ( line.startsWith(QString("dbus-send")) ) {
+            QString funcprefix = "org.kde.kstars.SimClock.";
+            int i = line.lastIndexOf( funcprefix );
+            if ( i >= 0 ) {
+                i += funcprefix.length();
+            } else {
+                funcprefix = "org.kde.kstars.";
+                i = line.lastIndexOf( funcprefix );
+                if ( i >= 0 ) {
+                    i += funcprefix.length();
+                }
+            }
+            if ( i < 0 ) {
+                kWarning() << "Could not parse line: " << line;
+                return false;
+            }
 
+            QStringList fn = line.mid(i).split( ' ' );
+
+            //DEBUG
+            kDebug() << fn << endl;
+
             if ( fn[0] == "lookTowards" && fn.size() >= 2 ) {
                 double az(-1.0);
                 QString arg = fn[1].toLower();
@@ -1020,20 +1033,29 @@
                 if ( arg == "nw" || arg == "northwest" ) az = 335.0;
                 if ( az >= 0.0 ) {
                     map->setFocusAltAz( 90.0, map->focus()->az()->Degrees() );
+                    map->focus()->HorizontalToEquatorial( LST, geo()->lat() );
+                    map->setDestination( map->focus() );
                     cmdCount++;
-                    map->setDestination( map->focus() );
                 }
 
                 if ( arg == "z" || arg == "zenith" ) {
                     map->setFocusAltAz( 90.0, map->focus()->az()->Degrees() );
+                    map->focus()->HorizontalToEquatorial( LST, geo()->lat() );
+                    map->setDestination( map->focus() );
                     cmdCount++;
-                    map->setDestination( map->focus() );
                 }
 
-                //try a named object.  name is everything after the first word (which is 'lookTowards')
+                //try a named object.  The name is everything after fn[0],
+                //concatenated with spaces.
                 fn.removeAll( fn.first() );
-                SkyObject *target = objectNamed( fn.join( " " ) );
-                if ( target ) { map->setFocus( target ); cmdCount++; }
+                QString objname = fn.join( " " );
+                SkyObject *target = objectNamed( objname );
+                if ( target ) { 
+                    map->setFocus( target );
+                    map->focus()->EquatorialToHorizontal( LST, geo()->lat() );
+                    map->setDestination( map->focus() );
+                    cmdCount++;
+                }
 
             } else if ( fn[0] == "setRaDec" && fn.size() == 3 ) {
                 bool ok( false );
@@ -1043,6 +1065,7 @@
                 if ( ok ) ok = d.setFromString( fn[2], true );  //assume angle in degrees
                 if ( ok ) {
                     map->setFocus( r, d );
+                    map->focus()->EquatorialToHorizontal( LST, geo()->lat() );
                     cmdCount++;
                 }
 
@@ -1054,6 +1077,7 @@
                 if ( ok ) ok = az.setFromString( fn[2] );
                 if ( ok ) {
                     map->setFocusAltAz( alt, az );
+                    map->focus()->HorizontalToEquatorial( LST, geo()->lat() );
                     cmdCount++;
                 }
 
--- trunk/KDE/kdeedu/kstars/kstars/main.cpp #750974:750975
@@ -138,6 +138,9 @@
         map->resize( w, h );
         QPixmap sky( w, h );
 
+        dat->setFullTimeUpdate();
+        dat->updateTime(dat->geo(), map );
+
         map->setDestination( new SkyPoint( Options::focusRA(), Options::focusDec() ) );
         map->destination()->EquatorialToHorizontal( dat->lst(), dat->geo()->lat() );
         map->setFocus( map->destination() );
@@ -153,9 +156,6 @@
             }
         }
 
-        dat->setFullTimeUpdate();
-        dat->updateTime(dat->geo(), map );
-
         qApp->processEvents();
         map->setMapGeometry();
         map->exportSkyImage( &sky );
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/customcatalogcomponent.cpp #750974:750975
@@ -145,23 +145,22 @@
         if ( map->checkVisibility( obj ) ) {
             QPointF o = map->toScreen( obj );
 
-            if ( o.x() >= 0. && o.x() <= Width && o.y() >= 0. && o.y() <= Height ) {
+            if ( ! map->onScreen( o ) ) continue;
 
-                if ( obj->type()==0 ) {
-                    StarObject *starobj = (StarObject*)obj;
-                    float zoomlim = 7.0 + ( Options::zoomFactor()/MINZOOM)/50.0;
-                    float mag = starobj->mag();
-                    float sizeFactor = 2.0;
-                    int size = int( map->scale()*sizeFactor*(zoomlim - mag) ) + 1;
-                    if (size>int(23*map->scale())) size=int(23*map->scale());
-                    starobj->draw( psky, o.x(), o.y(), size, Options::starColorMode(), Options::starColorIntensity(), true );
-                } else {
-                    //PA for Deep-Sky objects is 90 + PA because major axis is horizontal at PA=0
-                    DeepSkyObject *dso = (DeepSkyObject*)obj;
-                    double pa = 90. + map->findPA( dso, o.x(), o.y() );
-                    dso->drawImage( psky, o.x(), o.y(), pa, Options::zoomFactor() );
-                    dso->drawSymbol( psky, o.x(), o.y(), pa, Options::zoomFactor() );
-                }
+            if ( obj->type()==0 ) {
+                StarObject *starobj = (StarObject*)obj;
+                float zoomlim = 7.0 + ( Options::zoomFactor()/MINZOOM)/50.0;
+                float mag = starobj->mag();
+                float sizeFactor = 2.0;
+                int size = int( map->scale()*sizeFactor*(zoomlim - mag) ) + 1;
+                if (size>int(23*map->scale())) size=int(23*map->scale());
+                starobj->draw( psky, o.x(), o.y(), size, Options::starColorMode(), Options::starColorIntensity(), true );
+            } else {
+                //PA for Deep-Sky objects is 90 + PA because major axis is horizontal at PA=0
+                DeepSkyObject *dso = (DeepSkyObject*)obj;
+                double pa = 90. + map->findPA( dso, o.x(), o.y() );
+                dso->drawImage( psky, o.x(), o.y(), pa, Options::zoomFactor() );
+                dso->drawSymbol( psky, o.x(), o.y(), pa, Options::zoomFactor() );
             }
         }
     }
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/deepskycomponent.cpp #750974:750975
@@ -355,8 +355,6 @@
             //if ( obj->drawID == drawID ) continue;  // only draw each line once
             //obj->drawID = drawID;
 
-            if ( ! map->checkVisibility( obj ) ) continue;
-
             if ( obj->updateID != updateID ) {
                 obj->updateID = updateID;
                 if ( obj->updateNumID != updateNumID) {
@@ -365,6 +363,8 @@
                 obj->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
             }
 
+            if ( ! map->checkVisibility( obj ) ) continue;
+
             float mag = obj->mag();
             float size = map->scale() * obj->a() * dms::PI * Options::zoomFactor() / 10800.0;
 
@@ -373,8 +373,10 @@
             //undefined (=99.9)
             if ( (size > 1.0 || Options::zoomFactor() > 2000.) &&
                     (mag > 90.0 || mag < (float)maglim) ) {
+
                 QPointF o = map->toScreen( obj );
                 if ( ! map->onScreen( o ) ) continue;
+
                 double PositionAngle = map->findPA( obj, o.x(), o.y() );
 
                 //Draw Image


More information about the Kstars-devel mailing list