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

Alexey Khudyakov alexey.skladnoy at gmail.com
Mon Feb 8 16:35:30 CET 2010


SVN commit 1087148 by khudyakov:

* Add function for finding all objects in square region to SkyComponent

* Add covenience function to SkyMapComosite for finding all objects in
  square. Square is defined by two points.

Patch from Abhijit Apte

CCMAIL: kstars-devel at kde.org

 M  +17 -0     deepskycomponent.cpp  
 M  +11 -0     deepskycomponent.h  
 M  +4 -0      skycomponent.cpp  
 M  +14 -0     skycomponent.h  
 M  +13 -0     skymapcomposite.cpp  
 M  +7 -0      skymapcomposite.h  
 M  +13 -0     starcomponent.cpp  
 M  +11 -0     starcomponent.h  
 M  +1 -0      typedef.h  


--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/deepskycomponent.cpp #1087147:1087148
@@ -193,6 +193,8 @@
         //Assign object to general DeepSkyObjects list,
         //and a secondary list based on its catalog.
         m_DeepSkyList.append( o );
+        appendIndex( o, &m_DeepSkyIndex, trixel );
+
         if ( o->isCatalogM()) {
             m_MessierList.append( o );
             appendIndex( o, &m_MessierIndex, trixel );
@@ -456,6 +458,21 @@
     return nameHash[ name.toLower() ];
 }
 
+void DeepSkyComponent::objectsInArea( QList<SkyObject*>& list, const SkyRegion& region ) 
+{
+    for( SkyRegion::const_iterator it = region.constBegin(); it != region.constEnd(); it++ )
+    {
+        Trixel trixel = it.key();
+        if( m_DeepSkyIndex.contains( trixel ) )
+        {
+            DeepSkyList* dsoList = m_DeepSkyIndex.value(trixel);
+            for( DeepSkyList::iterator dsit = dsoList->begin(); dsit != dsoList->end(); dsit++ )
+                list.append( *dsit );
+        }
+    }
+}
+
+
 //we multiply each catalog's smallest angular distance by the
 //following factors before selecting the final nearest object:
 // IC catalog = 0.8
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/deepskycomponent.h #1087147:1087148
@@ -119,6 +119,17 @@
      */
     virtual SkyObject* findByName( const QString &name );
 
+    /**
+     * @short Searches the region(s) and appends the SkyObjects found to the list of sky objects
+     *
+     * Look for a SkyObject that is in one of the regions 
+     * If found, then append to the list of sky objects
+     * @p list list of SkyObject to which matching list has to be appended to
+     * @p region defines the regions in which the search for SkyObject should be done within
+     * @return void
+     */
+    virtual void objectsInArea( QList<SkyObject*>& list, const SkyRegion& region );
+
     virtual SkyObject* objectNearest( SkyPoint *p, double &maxrad );
 
     const QList<DeepSkyObject*>& objectList() const { return m_DeepSkyList; }
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skycomponent.cpp #1087147:1087148
@@ -48,6 +48,10 @@
 void SkyComponent::drawTrails( QPainter & )
 {}
 
+void SkyComponent::objectsInArea( QList<SkyObject*>& list, const SkyRegion& region )
+{}
+
+
 QHash<int, QStringList>& SkyComponent::getObjectNames() {
     return parent()->objectNames();
 }
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skycomponent.h #1087147:1087148
@@ -20,6 +20,7 @@
 
 
 #include <kdebug.h>
+#include "typedef.h"
 
 class QPainter;
 class QString;
@@ -95,6 +96,19 @@
     virtual SkyObject* findByName( const QString &name );
 
     /**
+     * @short Searches the region(s) and appends the SkyObjects found to the list of sky objects
+     *
+     * Look for a SkyObject that is in one of the regions 
+     * If found, then append to the list of sky objects
+     * @p list list of SkyObject to which matching list has to be appended to
+     * @p region defines the regions in which the search for SkyObject should be done within
+     * @return void
+     * @note This function simply returns; it is
+     * reimplemented in various sub-classes.
+     */
+    virtual void objectsInArea( QList<SkyObject*>& list, const SkyRegion& region );
+
+    /**
      * @short Find the SkyObject nearest the given SkyPoint
      *
      * Look for a SkyObject that is nearer to point p than maxrad.
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skymapcomposite.cpp #1087147:1087148
@@ -341,6 +341,19 @@
     return m_ObjectNames;
 }
 
+QList<SkyObject*> SkyMapComposite::findObjectsInArea( const SkyPoint& p1, const SkyPoint& p2 )
+{
+    const SkyRegion& region = m_skyMesh->skyRegion( p1, p2 );
+    QList<SkyObject*> list;
+    // call objectsInArea( QList<SkyObject*>&, const SkyRegion& ) for each of the
+    // components of the SkyMapComposite
+    if( m_Stars->selected() )
+        m_Stars->objectsInArea( list, region );
+    if( m_DeepSky->selected() )
+        m_DeepSky->objectsInArea( list, region );
+    return list;
+}
+
 SkyObject* SkyMapComposite::findByName( const QString &name ) {
     //We search the children in an "intelligent" order (most-used
     //object types first), in order to avoid wasting too much time
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/skymapcomposite.h #1087147:1087148
@@ -142,6 +142,13 @@
     	*/
     virtual SkyObject* findByName( const QString &name );
 
+    /**
+      *@return the list of objects in the region defined by skypoints 
+      *@param p1 first sky point (top-left vertex of rectangular region)
+      *@param p2 second sky point (bottom-right vertex of rectangular region)
+      */     
+    QList<SkyObject*> findObjectsInArea( const SkyPoint& p1, const SkyPoint& p2 );
+
     void addCustomCatalog( const QString &filename, int index );
     void removeCustomCatalog( const QString &name );
 
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/starcomponent.cpp #1087147:1087148
@@ -37,6 +37,7 @@
 #include "binfilehelper.h"
 #include "starblockfactory.h"
 
+
 #if defined(Q_OS_FREEBSD) || defined(Q_OS_NETBSD)
 #include <sys/endian.h>
 #define bswap_16(x) bswap16(x)
@@ -544,6 +545,18 @@
     return 0;
 }
 
+void StarComponent::objectsInArea( QList<SkyObject*>& list, const SkyRegion& region ) 
+{
+    for( SkyRegion::const_iterator it = region.constBegin(); it != region.constEnd(); it++ )
+    {
+        Trixel trixel = it.key();
+        StarList* starlist = m_starIndex->at( trixel );
+        for( int i = 0; starlist && i < starlist->size(); i++ )
+            if( starlist->at(i) && starlist->at(i)->name() != QString("star") )
+                list.push_back( starlist->at(i) );
+    }
+}
+
 SkyObject *StarComponent::findByHDIndex( int HDnum ) {
     KStarsData* data = KStarsData::Instance();
     SkyObject *o;
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/starcomponent.h #1087147:1087148
@@ -110,6 +110,17 @@
     virtual SkyObject* findByName( const QString &name );
 
     /**
+     * @short Searches the region(s) and appends the SkyObjects found to the list of sky objects
+     *
+     * Look for a SkyObject that is in one of the regions 
+     * If found, then append to the list of sky objects
+     * @p list list of SkyObject to which matching list has to be appended to
+     * @p region defines the regions in which the search for SkyObject should be done within
+     * @return void
+     */
+    virtual void objectsInArea( QList<SkyObject*>& list, const SkyRegion& region );
+
+    /**
      *@short Find stars by HD catalog index
      *@param HDnum HD Catalog Number of the star to find
      *@return If the star is a static star, a pointer to the star will be returned
--- trunk/KDE/kdeedu/kstars/kstars/skycomponents/typedef.h #1087147:1087148
@@ -43,6 +43,7 @@
 
 typedef QVector< SkyPoint*>            SkyList;
 typedef QHash< Trixel, bool>           IndexHash;
+typedef QHash< Trixel, bool>           SkyRegion;
 typedef QList< StarObject*>            StarList;
 typedef QVector< StarList*>            StarIndex;
 typedef QVector< LineList*>            LineListList;


More information about the Kstars-devel mailing list