Skip to content

Commit

Permalink
[pal] Small cleanups to Layer API
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 15, 2015
1 parent 2e772b2 commit fea58eb
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 185 deletions.
2 changes: 1 addition & 1 deletion src/core/pal/costcalculator.cpp
Expand Up @@ -191,7 +191,7 @@ namespace pal

if ( feat->feature->getGeosType() == GEOS_POLYGON )
{
int arrangement = feat->feature->getLayer()->getArrangement();
int arrangement = feat->feature->getLayer()->arrangement();
if ( arrangement == P_FREE || arrangement == P_HORIZ )
setPolygonCandidatesCost( stop, ( LabelPosition** ) feat->lPos, max_p, obstacles, bbx, bby );
}
Expand Down
26 changes: 13 additions & 13 deletions src/core/pal/feature.cpp
Expand Up @@ -89,7 +89,7 @@ namespace pal

double Feature::calculatePriority() const
{
return mPriority >= 0 ? mPriority : layer->getPriority();
return mPriority >= 0 ? mPriority : layer->priority();
}

////////////
Expand Down Expand Up @@ -357,7 +357,7 @@ namespace pal
}
}

if ( f->layer->getArrangement() == P_POINT )
if ( f->layer->arrangement() == P_POINT )
{
//if in "around point" placement mode, then we use the label distance to determine
//the label's offset
Expand Down Expand Up @@ -563,7 +563,7 @@ namespace pal
double alpha;
double cost;

unsigned long flags = f->layer->getArrangementFlags();
unsigned long flags = f->layer->arrangementFlags();
if ( flags == 0 )
flags = FLAG_ON_LINE; // default flag

Expand Down Expand Up @@ -669,7 +669,7 @@ namespace pal
#ifdef _DEBUG_FULL_
std::cout << " Create new label" << std::endl;
#endif
if ( f->layer->arrangement == P_LINE )
if ( f->layer->arrangement() == P_LINE )
{
// find out whether the line direction for this candidate is from right to left
bool isRightToLeft = ( alpha > M_PI / 2 || alpha <= -M_PI / 2 );
Expand All @@ -686,7 +686,7 @@ namespace pal
if ( flags & FLAG_ON_LINE )
positions.append( new LabelPosition( i, bx - yrm*cos( beta ) / 2, by - yrm*sin( beta ) / 2, xrm, yrm, alpha, cost, this, isRightToLeft ) ); // Line
}
else if ( f->layer->arrangement == P_HORIZ )
else if ( f->layer->arrangement() == P_HORIZ )
{
positions.append( new LabelPosition( i, bx - xrm / 2, by - yrm / 2, xrm, yrm, 0, cost, this ) ); // Line
}
Expand Down Expand Up @@ -956,7 +956,7 @@ namespace pal
QLinkedList<LabelPosition*> positions;
double delta = qMax( f->labelInfo->label_height, total_distance / 10.0 );

unsigned long flags = f->layer->getArrangementFlags();
unsigned long flags = f->layer->arrangementFlags();
if ( flags == 0 )
flags = FLAG_ON_LINE; // default flag

Expand Down Expand Up @@ -1129,7 +1129,7 @@ namespace pal
#endif

bool enoughPlace = false;
if ( f->layer->getArrangement() == P_FREE )
if ( f->layer->arrangement() == P_FREE )
{
enoughPlace = true;
px = ( box->x[0] + box->x[2] ) / 2 - xrm;
Expand Down Expand Up @@ -1158,7 +1158,7 @@ namespace pal

} // arrangement== FREE ?

if ( f->layer->getArrangement() == P_HORIZ || enoughPlace )
if ( f->layer->arrangement() == P_HORIZ || enoughPlace )
{
alpha = 0.0; // HORIZ
}
Expand Down Expand Up @@ -1308,26 +1308,26 @@ namespace pal
switch ( type )
{
case GEOS_POINT:
if ( f->layer->getArrangement() == P_POINT_OVER || f->fixedQuadrant() )
if ( f->layer->arrangement() == P_POINT_OVER || f->fixedQuadrant() )
nbp = setPositionOverPoint( x[0], y[0], lPos, angle );
else
nbp = setPositionForPoint( x[0], y[0], lPos, angle );
break;
case GEOS_LINESTRING:
if ( f->layer->getArrangement() == P_CURVED )
if ( f->layer->arrangement() == P_CURVED )
nbp = setPositionForLineCurved( lPos, mapShape );
else
nbp = setPositionForLine( lPos, mapShape );
break;

case GEOS_POLYGON:
switch ( f->layer->getArrangement() )
switch ( f->layer->arrangement() )
{
case P_POINT:
case P_POINT_OVER:
double cx, cy;
mapShape->getCentroid( cx, cy, f->layer->getCentroidInside() );
if ( f->layer->getArrangement() == P_POINT_OVER )
mapShape->getCentroid( cx, cy, f->layer->centroidInside() );
if ( f->layer->arrangement() == P_POINT_OVER )
nbp = setPositionOverPoint( cx, cy, lPos, angle );
else
nbp = setPositionForPoint( cx, cy, lPos, angle );
Expand Down
6 changes: 3 additions & 3 deletions src/core/pal/labelposition.cpp
Expand Up @@ -97,12 +97,12 @@ namespace pal
y[3] = y1 + dy2;

// upside down ? (curved labels are always correct)
if ( feature->getLayer()->getArrangement() != P_CURVED &&
if ( feature->getLayer()->arrangement() != P_CURVED &&
this->alpha > M_PI / 2 && this->alpha <= 3*M_PI / 2 )
{
bool uprightLabel = false;

switch ( feature->getLayer()->getUpsidedownLabels() )
switch ( feature->getLayer()->upsidedownLabels() )
{
case Layer::Upright:
uprightLabel = true;
Expand Down Expand Up @@ -388,7 +388,7 @@ namespace pal

QString LabelPosition::getLayerName() const
{
return feature->getLayer()->name;
return feature->getLayer()->name();
}

bool LabelPosition::costShrink( void *l, void *r )
Expand Down
96 changes: 20 additions & 76 deletions src/core/pal/layer.cpp
Expand Up @@ -49,18 +49,18 @@ namespace pal
{

Layer::Layer( const QString &lyrName, Arrangement arrangement, double defaultPriority, bool obstacle, bool active, bool toLabel, Pal *pal, bool displayAll )
: name( lyrName )
: mName( lyrName )
, pal( pal )
, obstacle( obstacle )
, active( active )
, toLabel( toLabel )
, displayAll( displayAll )
, centroidInside( false )
, arrangement( arrangement )
, arrangementFlags( 0 )
, mode( LabelPerFeature )
, mergeLines( false )
, upsidedownLabels( Upright )
, mObstacle( obstacle )
, mActive( active )
, mLabelLayer( toLabel )
, mDisplayAll( displayAll )
, mCentroidInside( false )
, mArrangement( arrangement )
, mArrangementFlags( 0 )
, mMode( LabelPerFeature )
, mMergeLines( false )
, mUpsidedownLabels( Upright )
{
rtree = new RTree<FeaturePart*, double, 2, double>();
hashtable = new QHash< QString, Feature*>;
Expand All @@ -69,11 +69,11 @@ namespace pal
connectedTexts = new QLinkedList< QString >;

if ( defaultPriority < 0.0001 )
this->defaultPriority = 0.0001;
mDefaultPriority = 0.0001;
else if ( defaultPriority > 1.0 )
this->defaultPriority = 1.0;
mDefaultPriority = 1.0;
else
this->defaultPriority = defaultPriority;
mDefaultPriority = defaultPriority;

featureParts = new QLinkedList<FeaturePart*>;
features = new QLinkedList<Feature*>;
Expand Down Expand Up @@ -115,70 +115,14 @@ namespace pal
return 0;
}

int Layer::getNbFeatures()
{
return features->size();
}

QString Layer::getName()
{
return name;
}

Arrangement Layer::getArrangement()
{
return arrangement;
}

void Layer::setArrangement( Arrangement arrangement )
{
this->arrangement = arrangement;
}


bool Layer::isObstacle()
{
return obstacle;
}

bool Layer::isToLabel()
{
return toLabel;
}

bool Layer::isActive()
{
return active;
}

double Layer::getPriority()
{
return defaultPriority;
}

void Layer::setObstacle( bool obstacle )
{
this->obstacle = obstacle;
}

void Layer::setActive( bool active )
{
this->active = active;
}

void Layer::setToLabel( bool toLabel )
{
this->toLabel = toLabel;
}

void Layer::setPriority( double priority )
{
if ( priority >= 1.0 ) // low priority
defaultPriority = 1.0;
mDefaultPriority = 1.0;
else if ( priority <= 0.0001 )
defaultPriority = 0.0001; // high priority
mDefaultPriority = 0.0001; // high priority
else
defaultPriority = priority;
mDefaultPriority = priority;
}

bool Layer::registerFeature( const QString& geom_id, PalGeometry *userGeom, double label_x, double label_y, const QString &labelText,
Expand Down Expand Up @@ -278,7 +222,7 @@ namespace pal
continue;
}

if ( mode == LabelPerFeature && ( type == GEOS_POLYGON || type == GEOS_LINESTRING ) )
if ( mMode == LabelPerFeature && ( type == GEOS_POLYGON || type == GEOS_LINESTRING ) )
{
if ( type == GEOS_LINESTRING )
GEOSLength_r( geosctxt, geom, &geom_size );
Expand Down Expand Up @@ -307,7 +251,7 @@ namespace pal
mMutex.unlock();

// if using only biggest parts...
if (( mode == LabelPerFeature || f->fixedPosition() ) && biggest_part != NULL )
if (( mMode == LabelPerFeature || f->fixedPosition() ) && biggest_part != NULL )
{
addFeaturePart( biggest_part, labelText );
first_feat = false;
Expand Down Expand Up @@ -340,7 +284,7 @@ namespace pal
rtree->Insert( bmin, bmax, fpart );

// add to hashtable with equally named feature parts
if ( mergeLines && !labelText.isEmpty() )
if ( mMergeLines && !labelText.isEmpty() )
{
QHash< QString, QLinkedList<FeaturePart*>* >::const_iterator lstPtr = connectedHashtable->find( labelText );
QLinkedList< FeaturePart*>* lst;
Expand Down

0 comments on commit fea58eb

Please sign in to comment.