[QGIS Commit] r11126 - in branches/symbology-ng-branch/src: core core/pal plugins/labeling

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Jul 21 05:09:27 EDT 2009


Author: wonder
Date: 2009-07-21 05:09:26 -0400 (Tue, 21 Jul 2009)
New Revision: 11126

Modified:
   branches/symbology-ng-branch/src/core/pal/costcalculator.cpp
   branches/symbology-ng-branch/src/core/pal/costcalculator.h
   branches/symbology-ng-branch/src/core/pal/feature.cpp
   branches/symbology-ng-branch/src/core/pal/labelposition.cpp
   branches/symbology-ng-branch/src/core/pal/labelposition.h
   branches/symbology-ng-branch/src/core/pal/pal.cpp
   branches/symbology-ng-branch/src/core/pal/pal.h
   branches/symbology-ng-branch/src/core/pal/pointset.h
   branches/symbology-ng-branch/src/core/pal/problem.cpp
   branches/symbology-ng-branch/src/core/pal/problem.h
   branches/symbology-ng-branch/src/core/qgspalobjectpositionmanager.cpp
   branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp
Log:
pal: created StraightLabelPosition derived from LabelPosition.
Return LabelPosition array instead of Label array.


Modified: branches/symbology-ng-branch/src/core/pal/costcalculator.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/costcalculator.cpp	2009-07-20 22:03:21 UTC (rev 11125)
+++ branches/symbology-ng-branch/src/core/pal/costcalculator.cpp	2009-07-21 09:09:26 UTC (rev 11126)
@@ -60,7 +60,7 @@
 
   ////////
 
-  void CostCalculator::setPolygonCandidatesCost( int nblp, LabelPosition **lPos, int max_p, RTree<PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] )
+  void CostCalculator::setPolygonCandidatesCost( int nblp, StraightLabelPosition **lPos, int max_p, RTree<PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] )
   {
     int i;
 
@@ -118,7 +118,7 @@
   }
 
 
-  void CostCalculator::setCandidateCostFromPolygon( LabelPosition* lp, RTree <PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] )
+  void CostCalculator::setCandidateCostFromPolygon( StraightLabelPosition* lp, RTree <PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] )
   {
 
     double amin[2];
@@ -188,7 +188,7 @@
       {
         int arrangement = feat->feature->getLayer()->getArrangement();
         if ( arrangement == P_FREE || arrangement == P_HORIZ )
-          setPolygonCandidatesCost( stop, feat->lPos, max_p, obstacles, bbx, bby );
+          setPolygonCandidatesCost( stop, (StraightLabelPosition**) feat->lPos, max_p, obstacles, bbx, bby );
       }
 
       return max_p;
@@ -198,7 +198,7 @@
 
   //////////
 
-  PolygonCostCalculator::PolygonCostCalculator( LabelPosition *lp ) : lp( lp )
+  PolygonCostCalculator::PolygonCostCalculator( StraightLabelPosition *lp ) : lp( lp )
   {
     int i;
     double hyp = max( lp->feature->xmax - lp->feature->xmin, lp->feature->ymax - lp->feature->ymin );

Modified: branches/symbology-ng-branch/src/core/pal/costcalculator.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/costcalculator.h	2009-07-20 22:03:21 UTC (rev 11125)
+++ branches/symbology-ng-branch/src/core/pal/costcalculator.h	2009-07-21 09:09:26 UTC (rev 11126)
@@ -6,6 +6,7 @@
 namespace pal
 {
   class Feats;
+  class StraightLabelPosition;
 
   class CostCalculator
   {
@@ -13,10 +14,10 @@
     /** increase candidate's cost according to its collision with passed feature */
     static void addObstacleCostPenalty(LabelPosition* lp, PointSet* feat);
 
-    static void setPolygonCandidatesCost( int nblp, LabelPosition **lPos, int max_p, RTree<PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] );
+    static void setPolygonCandidatesCost( int nblp, StraightLabelPosition **lPos, int max_p, RTree<PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] );
 
     /** Set cost to the smallest distance between lPos's centroid and a polygon stored in geoetry field */
-    static void setCandidateCostFromPolygon( LabelPosition* lp, RTree <PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] );
+    static void setCandidateCostFromPolygon( StraightLabelPosition* lp, RTree <PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] );
 
     /** sort candidates by costs, skip the worse ones, evaluate polygon candidates */
     static int finalizeCandidatesCosts( Feats* feat, int max_p, RTree <PointSet*, double, 2, double> *obstacles, double bbx[4], double bby[4] );
@@ -31,7 +32,7 @@
    */
   class PolygonCostCalculator
   {
-      LabelPosition *lp;
+      StraightLabelPosition *lp;
       double px, py;
       double dist[8];
       double rpx[8];
@@ -41,7 +42,7 @@
       void updatePoint( PointSet *pset );
       double updateLinePoly( PointSet *pset );
     public:
-      PolygonCostCalculator( LabelPosition *lp );
+      PolygonCostCalculator( StraightLabelPosition *lp );
 
       void update( PointSet *pset );
 

Modified: branches/symbology-ng-branch/src/core/pal/feature.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/feature.cpp	2009-07-20 22:03:21 UTC (rev 11125)
+++ branches/symbology-ng-branch/src/core/pal/feature.cpp	2009-07-21 09:09:26 UTC (rev 11126)
@@ -165,11 +165,11 @@
     double offset = label_x / 4;
 
     // at the center
-    ( *lPos )[0] = new LabelPosition( id, lx, ly, label_x, label_y, alpha, cost,  this );
+    ( *lPos )[0] = new StraightLabelPosition( id, lx, ly, label_x, label_y, alpha, cost,  this );
     // shifted to the sides - with higher cost
     cost = 0.0021;
-    ( *lPos )[1] = new LabelPosition( id, lx+offset, ly, label_x, label_y, alpha, cost,  this );
-    ( *lPos )[2] = new LabelPosition( id, lx-offset, ly, label_x, label_y, alpha, cost,  this );
+    ( *lPos )[1] = new StraightLabelPosition( id, lx+offset, ly, label_x, label_y, alpha, cost,  this );
+    ( *lPos )[2] = new StraightLabelPosition( id, lx-offset, ly, label_x, label_y, alpha, cost,  this );
     return nbp;
   }
 
@@ -316,7 +316,7 @@
       else
         cost =  0.0001 + 0.0020 * double( icost ) / double( nbp - 1 );
 
-      ( *lPos )[i] = new LabelPosition( i, lx, ly, xrm, yrm, 0, cost,  this );
+      ( *lPos )[i] = new StraightLabelPosition( i, lx, ly, xrm, yrm, 0, cost,  this );
 
       icost += inc;
 
@@ -488,15 +488,15 @@
           reversed = ( alpha >= M_PI/2 || alpha < -M_PI/2 );
 
         if ( (!reversed && (flags & FLAG_ABOVE_LINE)) || (reversed && (flags & FLAG_BELOW_LINE)) )
-          positions->push_back( new LabelPosition( i, bx + cos( beta ) *distlabel , by + sin( beta ) *distlabel, xrm, yrm, alpha, cost, this ) ); // Line
+          positions->push_back( new StraightLabelPosition( i, bx + cos( beta ) *distlabel , by + sin( beta ) *distlabel, xrm, yrm, alpha, cost, this ) ); // Line
         if ( (!reversed && (flags & FLAG_BELOW_LINE)) || (reversed && (flags & FLAG_ABOVE_LINE)) )
-          positions->push_back( new LabelPosition( i, bx - cos( beta ) * ( distlabel + yrm ) , by - sin( beta ) * ( distlabel + yrm ), xrm, yrm, alpha, cost, this ) ); // Line
+          positions->push_back( new StraightLabelPosition( i, bx - cos( beta ) * ( distlabel + yrm ) , by - sin( beta ) * ( distlabel + yrm ), xrm, yrm, alpha, cost, this ) ); // Line
         if ( flags & FLAG_ON_LINE )
-          positions->push_back( new LabelPosition( i, bx - yrm*cos( beta ) / 2, by - yrm*sin( beta ) / 2, xrm, yrm, alpha, cost, this ) ); // Line
+          positions->push_back( new StraightLabelPosition( i, bx - yrm*cos( beta ) / 2, by - yrm*sin( beta ) / 2, xrm, yrm, alpha, cost, this ) ); // Line
       }
       else if (layer->arrangement == P_HORIZ)
       {
-        positions->push_back( new LabelPosition(i, bx - xrm/2, by - yrm/2, xrm, yrm, 0, cost, this) ); // Line
+        positions->push_back( new StraightLabelPosition(i, bx - xrm/2, by - yrm/2, xrm, yrm, 0, cost, this) ); // Line
         //positions->push_back( new LabelPosition(i, bx -yrm/2, by - yrm*sin(beta)/2, xrm, yrm, alpha, cost, this, line)); // Line
       }
       else
@@ -735,7 +735,7 @@
               if ( isPointInPolygon( mapShape->nbPoints, mapShape->x, mapShape->y, rx,  ry ) )
               {
                 // cost is set to minimal value, evaluated later
-                positions->push_back( new LabelPosition( id++, rx - dlx, ry - dly , xrm, yrm, alpha, 0.0001, this ) ); // Polygon
+                positions->push_back( new StraightLabelPosition( id++, rx - dlx, ry - dly , xrm, yrm, alpha, 0.0001, this ) ); // Polygon
               }
             }
           }

Modified: branches/symbology-ng-branch/src/core/pal/labelposition.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/labelposition.cpp	2009-07-20 22:03:21 UTC (rev 11125)
+++ branches/symbology-ng-branch/src/core/pal/labelposition.cpp	2009-07-21 09:09:26 UTC (rev 11126)
@@ -55,11 +55,15 @@
 
 namespace pal
 {
+  LabelPosition::LabelPosition( int id, double cost, Feature *feature )
+   : id( id ), cost( cost ), feature( feature ), nbOverlap( 0 )
+  {
+  }
 
-  LabelPosition::LabelPosition( int id, double x1, double y1, double w, double h, double alpha, double cost, Feature *feature ) : id( id ), cost( cost ), /*workingCost (0),*/ alpha( alpha ), feature( feature ), nbOverlap( 0 ), w( w ), h( h )
+  StraightLabelPosition::StraightLabelPosition( int id, double x1, double y1, double w, double h, double alpha, double cost, Feature *feature )
+    : LabelPosition( id, cost, feature ), alpha( alpha ), w( w ), h( h )
   {
 
-
     // alpha take his value bw 0 and 2*pi rad
     while ( this->alpha > 2*M_PI )
       this->alpha -= 2 * M_PI;
@@ -119,7 +123,7 @@
     }
   }
 
-  bool LabelPosition::isIn( double *bbox )
+  bool StraightLabelPosition::isIn( double *bbox )
   {
     int i;
 
@@ -134,7 +138,7 @@
 
   }
 
-  void LabelPosition::print()
+  void StraightLabelPosition::print()
   {
     std::cout << feature->getLayer()->getName() << "/" << feature->getUID() << "/" << id;
     std::cout << " cost: " << cost;
@@ -146,8 +150,11 @@
     std::cout << std::endl;
   }
 
-  bool LabelPosition::isInConflict( LabelPosition *ls )
+  bool StraightLabelPosition::isInConflict( LabelPosition *lp )
   {
+    // TODO: more types of labelposition
+    StraightLabelPosition* ls = (StraightLabelPosition*) lp;
+
     int i, i2, j;
     int d1, d2;
 
@@ -194,17 +201,17 @@
     return id;
   }
 
-  double LabelPosition::getX() const
+  double StraightLabelPosition::getX( int i ) const
   {
-    return x[0];
+    return (i >= 0 && i < 4 ? x[i] : -1);
   }
 
-  double LabelPosition::getY() const
+  double StraightLabelPosition::getY( int i ) const
   {
-    return y[0];
+    return (i >= 0 && i < 4 ? y[i] : -1);
   }
 
-  double LabelPosition::getAlpha() const
+  double StraightLabelPosition::getAlpha() const
   {
     return alpha;
   }
@@ -228,7 +235,7 @@
     return feature;
   }
 
-  void LabelPosition::getBoundingBox(double amin[2], double amax[2]) const
+  void StraightLabelPosition::getBoundingBox(double amin[2], double amax[2]) const
   {
     amin[0] = DBL_MAX;
     amax[0] = -DBL_MAX;
@@ -263,12 +270,6 @@
   }
 
 
-  Label *LabelPosition::toLabel( bool active )
-  {
-    return new Label( this->x, this->y, alpha, feature->getUID(), feature->getLayer()->getName(), feature->getUserGeometry() );
-  }
-
-
   bool LabelPosition::polygonObstacleCallback( PointSet *feat, void *ctx )
   {
     PolygonCostCalculator *pCost = ( PolygonCostCalculator* ) ctx;
@@ -385,7 +386,7 @@
 
 
 
-  double LabelPosition::getDistanceToPoint( double xp, double yp )
+  double StraightLabelPosition::getDistanceToPoint( double xp, double yp )
   {
     int i;
     int j;
@@ -436,7 +437,7 @@
   }
 
 
-  bool LabelPosition::isBorderCrossingLine( PointSet* feat )
+  bool StraightLabelPosition::isBorderCrossingLine( PointSet* feat )
   {
     double ca, cb;
     for ( int i = 0;i < 4;i++ )
@@ -462,7 +463,7 @@
     return false;
   }
 
-  int LabelPosition::getNumPointsInPolygon( int npol, double *xp, double *yp )
+  int StraightLabelPosition::getNumPointsInPolygon( int npol, double *xp, double *yp )
   {
     int a, k, count = 0;
     double px, py;

Modified: branches/symbology-ng-branch/src/core/pal/labelposition.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/labelposition.h	2009-07-20 22:03:21 UTC (rev 11125)
+++ branches/symbology-ng-branch/src/core/pal/labelposition.h	2009-07-21 09:09:26 UTC (rev 11126)
@@ -52,17 +52,13 @@
    */
   class LabelPosition
   {
-
       friend class CostCalculator;
       friend class PolygonCostCalculator;
 
-    private:
+    protected:
 
       int id;
       double cost;
-      double x[4], y[4];
-
-      double alpha;
       Feature *feature;
 
       // bug # 1 (maxence 10/23/2008)
@@ -70,43 +66,24 @@
 
       int nbOverlap;
 
-      double w;
-      double h;
-
     public:
       /**
        * \brief create a new LabelPosition
        *
        * \param id id of this labelposition
-       * \param x1 down-left x coordinate
-       * \param y1 down-left y coordinate
-       * \param w label width
-       * \param h label height
-       * \param alpha rotation in rad
        * \param cost geographic cost
        * \param feature labelpos owners
        */
-      LabelPosition( int id, double x1, double y1,
-                     double w, double h,
-                     double alpha, double cost,
-                     Feature *feature );
+      LabelPosition( int id, double cost, Feature *feature );
 
-      /**
-       * \brief load a stored labelposition
-       *
-       * Load a labelPosition from a file
-       * \param id id of this labelPosition
-       * \param feature  this labelposition is for feature
-       * \param file load from this stream
-       */
-      LabelPosition( int id, Feature *feature, std::ifstream *file );
+      // virtual functions
 
       /**
        * \brief is the labelposition in the bounding-box ?
        *
        *\param bbox the bounding-box double[4] = {xmin, ymin, xmax, ymax}
        */
-      bool isIn( double *bbox );
+      virtual bool isIn( double *bbox ) = 0;
 
       /**
        * \brief Check whether or not this overlap with another labelPosition
@@ -114,8 +91,22 @@
        * \param ls other labelposition
        * \return true or false
        */
-      bool isInConflict( LabelPosition *ls );
+      virtual bool isInConflict( LabelPosition *ls ) = 0;
 
+      /** return bounding box - amin: xmin,ymin - amax: xmax,ymax */
+      virtual void getBoundingBox(double amin[2], double amax[2]) const = 0;
+
+      /** get distance from this label to a point. If point lies inside, returns negative number. */
+      virtual double getDistanceToPoint( double xp, double yp ) = 0;
+
+      /** returns true if this label crosses the specified line */
+      virtual bool isBorderCrossingLine( PointSet* feat ) = 0;
+
+      /** returns number of intersections with polygon (testing border and center) */
+      virtual int getNumPointsInPolygon( int npol, double *xp, double *yp ) = 0;
+
+      // end of virtual functions
+
       /** \brief return id
        * \return id
        */
@@ -127,20 +118,6 @@
        */
       Feature * getFeature();
 
-      /**
-       * \brief get the down-left x coordinate
-       * \return x coordinate
-       */
-      double getX() const;
-      /**
-       * \brief get the down-left y coordinate
-       * \return y coordinate
-       */
-      double getY() const;
-
-      double getWidth() const { return w; }
-      double getHeight() const { return h; }
-
       double getNumOverlaps() const { return nbOverlap; }
       void resetNumOverlaps() { nbOverlap = 0; } // called from problem.cpp, pal.cpp
 
@@ -153,12 +130,6 @@
       char* getLayerName() const;
 
       /**
-       * \brief get alpha
-       * \return alpha to rotate text (in rad)
-       */
-      double getAlpha() const;
-
-      /**
        * \brief get the position geographical cost
        * \return geographical cost
        */
@@ -170,17 +141,12 @@
       /** Make sure the cost is less than 1 */
       void validateCost();
 
-      /** return bounding box - amin: xmin,ymin - amax: xmax,ymax */
-      void getBoundingBox(double amin[2], double amax[2]) const;
-
       /**
        * \brief get a final lable from this
        * \return a new Label() object
        */
-      Label* toLabel( bool active );
+      //Label* toLabel( bool active );
 
-      void print();
-
       void removeFromIndex( RTree<LabelPosition*, double, 2, double> *index );
       void insertIntoIndex( RTree<LabelPosition*, double, 2, double> *index );
 
@@ -220,16 +186,80 @@
       // for polygon cost calculation
       static bool polygonObstacleCallback( PointSet *feat, void *ctx );
 
+  };
+
+
+  class StraightLabelPosition : public LabelPosition
+  {
+      friend class CostCalculator;
+      friend class PolygonCostCalculator;
+
+    public:
+      /**
+       * \brief create a new LabelPosition
+       *
+       * \param id id of this labelposition
+       * \param x1 down-left x coordinate
+       * \param y1 down-left y coordinate
+       * \param w label width
+       * \param h label height
+       * \param alpha rotation in rad
+       * \param cost geographic cost
+       * \param feature labelpos owners
+       */
+      StraightLabelPosition( int id, double x1, double y1,
+                             double w, double h,
+                             double alpha, double cost,
+                             Feature *feature );
+
+      // virtual functions
+
+      virtual bool isIn( double *bbox );
+      virtual bool isInConflict( LabelPosition *ls );
+
+      virtual void getBoundingBox(double amin[2], double amax[2]) const;
+
       /** get distance from this label to a point. If point lies inside, returns negative number. */
-      double getDistanceToPoint( double xp, double yp );
+      virtual double getDistanceToPoint( double xp, double yp );
 
       /** returns true if this label crosses the specified line */
-      bool isBorderCrossingLine( PointSet* feat );
+      virtual bool isBorderCrossingLine( PointSet* feat );
 
       /** returns number of intersections with polygon (testing border and center) */
-      int getNumPointsInPolygon( int npol, double *xp, double *yp );
+      virtual int getNumPointsInPolygon( int npol, double *xp, double *yp );
 
-  };
+      // new functions
+
+      /**
+       * \brief get the down-left x coordinate
+       * \return x coordinate
+       */
+      double getX( int i = 0 ) const;
+      /**
+       * \brief get the down-left y coordinate
+       * \return y coordinate
+       */
+      double getY( int i = 0 ) const;
+
+      double getWidth() const { return w; }
+      double getHeight() const { return h; }
+
+      /**
+       * \brief get alpha
+       * \return alpha to rotate text (in rad)
+       */
+      double getAlpha() const;
+
+      void print();
+
+    protected:
+      double x[4], y[4];
+      double alpha;
+      double w;
+      double h;
+
+    };
+
 } // end namespac
 
 #endif

Modified: branches/symbology-ng-branch/src/core/pal/pal.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/pal.cpp	2009-07-20 22:03:21 UTC (rev 11125)
+++ branches/symbology-ng-branch/src/core/pal/pal.cpp	2009-07-21 09:09:26 UTC (rev 11126)
@@ -759,7 +759,7 @@
     return prob;
   }
 
-  std::list<Label*>* Pal::labeller( double scale, double bbox[4], PalStat **stats, bool displayAll )
+  std::list<LabelPosition*>* Pal::labeller( double scale, double bbox[4], PalStat **stats, bool displayAll )
   {
 
 #ifdef _DEBUG_FULL_
@@ -783,7 +783,7 @@
     }
     lyrsMutex->unlock();
 
-    std::list<Label*> * solution = labeller( nbLayers, layersName, priorities, scale, bbox, stats, displayAll );
+    std::list<LabelPosition*> * solution = labeller( nbLayers, layersName, priorities, scale, bbox, stats, displayAll );
 
     delete[] layersName;
     delete[] priorities;
@@ -794,7 +794,7 @@
   /*
    * BIG MACHINE
    */
-  std::list<Label*>* Pal::labeller( int nbLayers, char **layersName , double *layersFactor, double scale, double bbox[4], PalStat **stats, bool displayAll )
+  std::list<LabelPosition*>* Pal::labeller( int nbLayers, char **layersName , double *layersFactor, double scale, double bbox[4], PalStat **stats, bool displayAll )
   {
 #ifdef _DEBUG_
     std::cout << "LABELLER (selection)" << std::endl;
@@ -861,7 +861,7 @@
       // nothing to be done => return an empty result set
       if ( stats )
         ( *stats ) = new PalStat();
-      return new std::list<Label*>();
+      return new std::list<LabelPosition*>();
     }
 
     std::cout << "PAL EXTRACT: " << t.elapsed() / 1000.0 << " s" << std::endl;
@@ -901,7 +901,7 @@
     //prob->post_optimization();
 
 
-    std::list<Label*> * solution = prob->getSolution( displayAll );
+    std::list<LabelPosition*> * solution = prob->getSolution( displayAll );
 
     if ( stats )
       *stats = prob->getStats();
@@ -956,10 +956,10 @@
     return prob;
   }
 
-  std::list<Label*>* Pal::solveProblem(Problem* prob)
+  std::list<LabelPosition*>* Pal::solveProblem(Problem* prob)
   {
     if (prob == NULL)
-      return new std::list<Label*>();
+      return new std::list<LabelPosition*>();
 
     prob->reduce();
 

Modified: branches/symbology-ng-branch/src/core/pal/pal.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/pal.h	2009-07-20 22:03:21 UTC (rev 11125)
+++ branches/symbology-ng-branch/src/core/pal/pal.h	2009-07-21 09:09:26 UTC (rev 11126)
@@ -309,7 +309,7 @@
        *
        * @return A list of label to display on map
        */
-      std::list<Label*> *labeller( double scale, double bbox[4], PalStat **stats, bool displayAll );
+      std::list<LabelPosition*> *labeller( double scale, double bbox[4], PalStat **stats, bool displayAll );
 
 
       /**
@@ -329,7 +329,7 @@
        *
        * @return A list of label to display on map
        */
-      std::list<Label*> *labeller( int nbLayers,
+      std::list<LabelPosition*> *labeller( int nbLayers,
                                    char **layersName,
                                    double *layersFactor,
                                    double scale, double bbox[4],
@@ -339,7 +339,7 @@
 
       Problem* extractProblem(double scale, double bbox[4]);
 
-      std::list<Label*>* solveProblem(Problem* prob);
+      std::list<LabelPosition*>* solveProblem(Problem* prob);
 
       /**
        * \brief Set map resolution

Modified: branches/symbology-ng-branch/src/core/pal/pointset.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/pointset.h	2009-07-20 22:03:21 UTC (rev 11125)
+++ branches/symbology-ng-branch/src/core/pal/pointset.h	2009-07-21 09:09:26 UTC (rev 11126)
@@ -93,7 +93,7 @@
   class PointSet
   {
       friend class Feature;
-      friend class LabelPosition;
+      friend class StraightLabelPosition;
       friend class CostCalculator;
       friend class PolygonCostCalculator;
       friend void extractXYCoord( Feat *f );

Modified: branches/symbology-ng-branch/src/core/pal/problem.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/pal/problem.cpp	2009-07-20 22:03:21 UTC (rev 11125)
+++ branches/symbology-ng-branch/src/core/pal/problem.cpp	2009-07-21 09:09:26 UTC (rev 11126)
@@ -2961,20 +2961,20 @@
 //#undef _DEBUG_FULL_
 #endif
 
-  std::list<Label*> * Problem::getSolution( bool returnInactive )
+  std::list<LabelPosition*> * Problem::getSolution( bool returnInactive )
   {
 
     int i;
-    std::list<Label*> *solList = new std::list<Label*>();
+    std::list<LabelPosition*> *solList = new std::list<LabelPosition*>();
 
     if ( nbft == 0 )
       return solList;
 
     for ( i = 0;i < nbft;i++ )
       if ( sol->s[i] != -1 )
-        solList->push_back( labelpositions[sol->s[i]]->toLabel( true ) );
+        solList->push_back( labelpositions[sol->s[i]] ); // active labels
       else if ( returnInactive )
-        solList->push_back( labelpositions[featStartId[i]]->toLabel( false ) );
+        solList->push_back( labelpositions[featStartId[i]] ); // unplaced label
 
     return solList;
   }

Modified: branches/symbology-ng-branch/src/core/pal/problem.h
===================================================================
--- branches/symbology-ng-branch/src/core/pal/problem.h	2009-07-20 22:03:21 UTC (rev 11125)
+++ branches/symbology-ng-branch/src/core/pal/problem.h	2009-07-21 09:09:26 UTC (rev 11126)
@@ -203,7 +203,7 @@
        */
       void chain_search();
 
-      std::list<Label*> * getSolution( bool returnInactive );
+      std::list<LabelPosition*> * getSolution( bool returnInactive );
 
       PalStat * getStats();
 

Modified: branches/symbology-ng-branch/src/core/qgspalobjectpositionmanager.cpp
===================================================================
--- branches/symbology-ng-branch/src/core/qgspalobjectpositionmanager.cpp	2009-07-20 22:03:21 UTC (rev 11125)
+++ branches/symbology-ng-branch/src/core/qgspalobjectpositionmanager.cpp	2009-07-21 09:09:26 UTC (rev 11126)
@@ -21,7 +21,8 @@
 #include "qgsvectorlayer.h"
 #include "qgsvectoroverlay.h"
 #include "pal.h"
-#include "label.h"
+#include "labelposition.h"
+#include "feature.h"
 #include "layer.h"
 
 QgsPALObjectPositionManager::QgsPALObjectPositionManager(): mNumberOfLayers( 0 )
@@ -126,7 +127,7 @@
   mPositionEngine.setMapUnit( mapUnits );
   mPositionEngine.setDpi(renderContext.scaleFactor() * 25.4);
 
-  std::list<pal::Label*>* resultLabelList = mPositionEngine.labeller( renderContext.rendererScale(), bbox, &stat, false );
+  std::list<pal::LabelPosition*>* resultLabelList = mPositionEngine.labeller( renderContext.rendererScale(), bbox, &stat, false );
   delete stat;
 
   //and read the positions back to the overlay objects
@@ -137,18 +138,20 @@
 
   QgsOverlayObject* currentOverlayObject = 0;
 
-  std::list<pal::Label*>::iterator labelIt = resultLabelList->begin();
+  std::list<pal::LabelPosition*>::iterator labelIt = resultLabelList->begin();
   for ( ; labelIt != resultLabelList->end(); ++labelIt )
   {
-    currentOverlayObject = dynamic_cast<QgsOverlayObject*>(( *labelIt )->getGeometry() );
+    currentOverlayObject = dynamic_cast<QgsOverlayObject*>(( *labelIt )->getFeature()->getUserGeometry() );
     if ( !currentOverlayObject )
     {
       continue;
     }
 
+    pal::StraightLabelPosition* lp = (pal::StraightLabelPosition*) *labelIt;
+
     //QGIS takes the coordinates of the middle points
-    double x = (( *labelIt )->getX( 0 ) + ( *labelIt )->getX( 1 ) + ( *labelIt )->getX( 2 ) + ( *labelIt )->getX( 3 ) ) / 4;
-    double y = (( *labelIt )->getY( 0 ) + ( *labelIt )->getY( 1 ) + ( *labelIt )->getY( 2 ) + ( *labelIt )->getY( 3 ) ) / 4;
+    double x = (lp->getX( 0 ) + lp->getX( 1 ) + lp->getX( 2 ) + lp->getX( 3 ) ) / 4;
+    double y = (lp->getY( 0 ) + lp->getY( 1 ) + lp->getY( 2 ) + lp->getY( 3 ) ) / 4;
     currentOverlayObject->addPosition( QgsPoint( x, y ) );
   }
 }

Modified: branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp
===================================================================
--- branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp	2009-07-20 22:03:21 UTC (rev 11125)
+++ branches/symbology-ng-branch/src/plugins/labeling/pallabeling.cpp	2009-07-21 09:09:26 UTC (rev 11126)
@@ -4,6 +4,7 @@
 #include <list>
 
 #include <pal/pal.h>
+#include <pal/feature.h>
 #include <pal/layer.h>
 #include <pal/palgeometry.h>
 #include <pal/palexception.h>
@@ -321,7 +322,7 @@
   QgsRectangle r = extent;
   double bbox[] = { r.xMinimum(), r.yMinimum(), r.xMaximum(), r.yMaximum() };
 
-  std::list<Label*>* labels;
+  std::list<LabelPosition*>* labels;
   pal::Problem* problem;
   try
   {
@@ -347,7 +348,7 @@
     {
       for (int j = 0; j < problem->getFeatureCandidateCount(i); j++)
       {
-        pal::LabelPosition* lp = problem->getFeatureCandidate(i, j);
+        pal::StraightLabelPosition* lp = (pal::StraightLabelPosition*) problem->getFeatureCandidate(i, j);
 
         QgsPoint outPt = xform->transform(lp->getX(), lp->getY());
         QgsPoint outPt2 = xform->transform(lp->getX()+lp->getWidth(), lp->getY()+lp->getHeight());
@@ -373,22 +374,22 @@
   t.restart();
 
   // draw the labels
-  std::list<Label*>::iterator it = labels->begin();
+  std::list<LabelPosition*>::iterator it = labels->begin();
   for ( ; it != labels->end(); ++it)
   {
-    Label* label = *it;
+    StraightLabelPosition* label = (StraightLabelPosition*) *it;
 
-    QgsPoint outPt = xform->transform(label->getOrigX(), label->getOrigY());
+    QgsPoint outPt = xform->transform(label->getX(), label->getY());
 
     // TODO: optimize access :)
     const LayerSettings& lyr = layer(label->getLayerName());
 
-    QString text = ((MyLabel*)label->getGeometry())->text();
+    QString text = ((MyLabel*)label->getFeature()->getUserGeometry())->text();
 
     // shift by one as we have 2px border
     painter->save();
     painter->translate( QPointF(outPt.x()+1, outPt.y()-1-lyr.fontBaseline) );
-    painter->rotate(-label->getRotation() * 180 / M_PI );
+    painter->rotate(-label->getAlpha() * 180 / M_PI );
     painter->setFont( lyr.textFont );
 
     if (lyr.bufferSize != 0)
@@ -398,7 +399,6 @@
     painter->drawText(0,0, text);
     painter->restore();
 
-    delete label;
   }
 
   std::cout << "LABELING draw:   " << t.elapsed() << "ms" << std::endl;



More information about the QGIS-commit mailing list