[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kstars-devel
Subject:    Re: [Kstars-devel] Refined patch for wishlist 178232: List all
From:       Abhijit Apte <abhijit.apte () gmail ! com>
Date:       2010-02-04 7:12:25
Message-ID: f7c0912c1002032300i69b21f17i274d8f9b76c0124d () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi,

There is one candidate for separate patch already. It is code for searching
> for objects.
>

I've attached the patch for this candidate. It searches the objects in
rectangle using the approach that you suggested and finally prints the
results of the search on console (upon right-click drag).
I've implemented objectsInArea() only for StarComponent and
DeepSkyComponent, for now. Still got to figure out logic for searching
planets, moons, comets etc.

Please review and let me know your comments.

Rgds
-Abhi

[Attachment #5 (text/html)]

Hi,<br><br><div class="gmail_quote"><blockquote class="gmail_quote" \
style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; \
padding-left: 1ex;"> There is one candidate for separate patch already. It is code \
for searching<br> for objects. <br></blockquote></div><br>I&#39;ve attached the patch \
for this candidate. It searches the objects in rectangle using the approach that you \
suggested and finally prints the results of the search on console (upon right-click \
drag). <br> I&#39;ve implemented objectsInArea() only for StarComponent and \
DeepSkyComponent, for now. Still got to figure out logic for searching planets, \
moons, comets etc.<br><br>Please review and let me know your comments.<br><br> \
Rgds<br>-Abhi<br>

--000e0cd70e4cb57180047ec0e35b--


["patch_selection_feb4.diff" (text/x-patch)]

Index: skymap.cpp
===================================================================
--- skymap.cpp	(revision 1084185)
+++ skymap.cpp	(working copy)
@@ -826,6 +826,36 @@
     HourAngle.setH( data->lst()->Hours() - focus()->ra()->Hours() );
 }
 
+void SkyMap::showObjectsInRectangle()
+{
+    if( (secondRClickPos-firstRClickPos).manhattanLength() < \
QApplication::startDragDistance() ) +    {
+        if( clickedObject() )
+        // Rightclick release happened within the drag limits
+        // Got to populate info about a single clicked object
+            clickedObject()->showPopupMenu( pmenu, QCursor::pos() );
+        else
+        {
+            // Rightclick release happened within the drag limits
+            // Got to populate info with unknown object since there was
+            // no clicked object in the region
+            SkyObject object(
+                        SkyObject::TYPE_UNKNOWN,
+                        clickedPoint()->ra()->Hours(),
+                        clickedPoint()->dec()->Degrees() );
+
+            pmenu->createEmptyMenu( &object );
+            pmenu->popup( QCursor::pos() );
+        }
+    }
+    else
+    {
+        QList<SkyObject*> objList = data->skyComposite()->findObjectsInArea( \
firstPoint, secondPoint ); +        for( QList<SkyObject*>::const_iterator it = \
objList.constBegin(); it != objList.constEnd(); it++ ) +            kDebug() << \
(*it)->name() << endl; +    }
+}
+
 void SkyMap::slewFocus() {
     double dX, dY, fX, fY, r, r0;
     double step0 = 0.5;
Index: skymap.h
===================================================================
--- skymap.h	(revision 1084185)
+++ skymap.h	(working copy)
@@ -441,6 +441,8 @@
     	*/
     void drawObjectLabels( QList<SkyObject*>& labelObjects, QPainter &psky );
 
+    void showObjectsInRectangle();
+
 public slots:
     //DEBUG_KIO_JOB
     void slotJobResult( KJob *j );
@@ -855,6 +857,9 @@
     Quaternion m_rotAxis;
 
     static SkyMap* pinstance;
+    
+    QPointF firstRClickPos, secondRClickPos;
+    SkyPoint firstPoint, secondPoint;
 
 };
 
Index: skymapevents.cpp
===================================================================
--- skymapevents.cpp	(revision 1084185)
+++ skymapevents.cpp	(working copy)
@@ -616,7 +616,21 @@
         zoomOutOrMagStep( e->modifiers() );
 }
 
-void SkyMap::mouseReleaseEvent( QMouseEvent * ) {
+void SkyMap::mouseReleaseEvent( QMouseEvent * e ) {
+    if ( e->button() == Qt::RightButton ) {
+        secondRClickPos = QCursor::pos();
+
+        // The new point after drag has to be recorded and saved for future use
+        setMousePoint( fromScreen( e->pos(), data->lst(), data->geo()->lat() ) );
+        mousePoint()->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
+        setClickedPoint( mousePoint() );
+        clickedPoint()->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
+        secondPoint = ClickedPoint;
+
+        showObjectsInRectangle();
+        return;
+    }
+
     if ( ZoomRect.isValid() ) {
         //Zoom in on center of Zoom Circle, by a factor equal to the ratio
         //of the sky pixmap's width to the Zoom Circle's diameter
@@ -689,6 +703,10 @@
         setClickedPoint( mousePoint() );
         clickedPoint()->EquatorialToHorizontal( data->lst(), data->geo()->lat() );
 
+        // Store this skypoint for future use
+        // in case mouse is right-click dragged
+        firstPoint = ClickedPoint;
+
         //Find object nearest to clickedPoint()
         double maxrad = 1000.0/Options::zoomFactor();
         setClickedObject( data->skyComposite()->objectNearest( clickedPoint(), \
maxrad ) ); @@ -697,7 +715,7 @@
             setClickedPoint( clickedObject() );
 
             if ( e->button() == Qt::RightButton ) {
-                clickedObject()->showPopupMenu( pmenu, QCursor::pos() );
+                firstRClickPos = QCursor::pos();
             }
 
             if ( kstars && e->button() == Qt::LeftButton ) {
@@ -714,9 +732,7 @@
                     kstars->statusBar()->changeItem( i18n( "Empty sky" ), 0 );
                 break;
             case Qt::RightButton: {
-                SkyObject o( SkyObject::TYPE_UNKNOWN, clickedPoint()->ra()->Hours(), \
                clickedPoint()->dec()->Degrees() );
-                pmenu->createEmptyMenu( &o );
-                pmenu->popup( QCursor::pos() );
+                firstRClickPos = QCursor::pos();
                 break;
                 }
             default: ;
Index: skycomponents/starcomponent.cpp
===================================================================
--- skycomponents/starcomponent.cpp	(revision 1084185)
+++ skycomponents/starcomponent.cpp	(working copy)
@@ -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;
Index: skycomponents/deepskycomponent.h
===================================================================
--- skycomponents/deepskycomponent.h	(revision 1084185)
+++ skycomponents/deepskycomponent.h	(working copy)
@@ -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; }
Index: skycomponents/skycomponent.h
===================================================================
--- skycomponents/skycomponent.h	(revision 1084185)
+++ skycomponents/skycomponent.h	(working copy)
@@ -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.
Index: skycomponents/typedef.h
===================================================================
--- skycomponents/typedef.h	(revision 1084185)
+++ skycomponents/typedef.h	(working copy)
@@ -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;
Index: skycomponents/deepskycomponent.cpp
===================================================================
--- skycomponents/deepskycomponent.cpp	(revision 1084185)
+++ skycomponents/deepskycomponent.cpp	(working copy)
@@ -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
Index: skycomponents/skycomponent.cpp
===================================================================
--- skycomponents/skycomponent.cpp	(revision 1084185)
+++ skycomponents/skycomponent.cpp	(working copy)
@@ -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();
 }
Index: skycomponents/skymapcomposite.h
===================================================================
--- skycomponents/skymapcomposite.h	(revision 1084185)
+++ skycomponents/skymapcomposite.h	(working copy)
@@ -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( SkyPoint& p1, SkyPoint& p2 );
+
     void addCustomCatalog( const QString &filename, int index );
     void removeCustomCatalog( const QString &name );
 
@@ -185,6 +192,8 @@
 private:
     virtual QHash<int, QStringList>& getObjectNames();
     
+    const SkyRegion& skyRegion( SkyPoint& p1, SkyPoint& p2 );
+    
     CultureList                 *m_Cultures;
     ConstellationBoundaryLines  *m_CBoundLines;
     ConstellationNamesComponent *m_CNames;
Index: skycomponents/listcomponent.cpp
===================================================================
--- skycomponents/listcomponent.cpp	(revision 1084185)
+++ skycomponents/listcomponent.cpp	(working copy)
@@ -62,6 +62,11 @@
     return 0;
 }
 
+
+void ListComponent::objectsInArea( QList<SkyObject*>& list, const SkyRegion& region \
) { +}
+
+
 SkyObject* ListComponent::objectNearest( SkyPoint *p, double &maxrad ) {
     if ( ! selected() )
         return 0;
Index: skycomponents/starcomponent.h
===================================================================
--- skycomponents/starcomponent.h	(revision 1084185)
+++ skycomponents/starcomponent.h	(working copy)
@@ -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
Index: skycomponents/skymapcomposite.cpp
===================================================================
--- skycomponents/skymapcomposite.cpp	(revision 1084185)
+++ skycomponents/skymapcomposite.cpp	(working copy)
@@ -341,6 +341,33 @@
     return m_ObjectNames;
 }
 
+const SkyRegion& SkyMapComposite::skyRegion( SkyPoint& p1, SkyPoint& p2 )
+{
+    dms ra3(p2.ra()->Degrees()), dec3(p1.dec()->Degrees());
+    dms ra4(p1.ra()->Degrees()), dec4(p2.dec()->Degrees());
+    // find the other two vertices to form bounded rectangular region
+    SkyPoint p3(ra3, dec3), p4( ra4, dec4 );
+    SkyList skylist;
+    // push the vertices of the region in that order
+    skylist.push_back( &p1 );    //  p1 .________. p3
+    skylist.push_back( &p3 );    //     |        |
+    skylist.push_back( &p2 );    //     |        |
+    skylist.push_back( &p4 );    //  p4 .________. p2
+
+    return m_skyMesh->indexPoly( &skylist );
+}
+
+QList<SkyObject*> SkyMapComposite::findObjectsInArea( SkyPoint& p1, SkyPoint& p2 )
+{
+    const SkyRegion& region = this->skyRegion( p1, p2 );
+    QList<SkyObject*> list;
+    // call objectsInArea( QList<SkyObject*>&, const SkyRegion& ) for each of the
+    // components of the SkyMapComposite
+    m_Stars->objectsInArea( list, region );
+    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
Index: skycomponents/listcomponent.h
===================================================================
--- skycomponents/listcomponent.h	(revision 1084185)
+++ skycomponents/listcomponent.h	(working copy)
@@ -54,6 +54,20 @@
     virtual void update( KSNumbers *num=0 );
 
     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 );
+
     virtual SkyObject* objectNearest( SkyPoint *p, double &maxrad );
 
     void clear();



_______________________________________________
Kstars-devel mailing list
Kstars-devel@kde.org
https://mail.kde.org/mailman/listinfo/kstars-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic