Ticket #1419: code.diff

File code.diff, 3.9 KB (added by LonelyPixel, 12 years ago)

Patch of my proposed implementation

  • merkaartor\Map\FeatureManipulations.cpp

    old new  
    246246
    247247        if (Roads.size() == 0 && Points.size() == 1)
    248248        {
    249                 Road * R = Road::GetSingleParentRoad(Points[0]);
     249                Road * R = Road::GetSingleParentRoadInner(Points[0]);
    250250                if (R)
    251251                        Roads.push_back(R);
    252252        }
  • merkaartor\PropertiesDock.cpp

    old new  
    6767        delete theTemplates;
    6868}
    6969
    70 static bool isChildOfSingleRoad(MapFeature *mapFeature)
     70static bool isChildOfSingleRoadInner(MapFeature *mapFeature)
    7171{
    72         unsigned int parents = mapFeature->sizeParents();
    73 
    74         if (parents == 0)
    75                 return false;
    76 
    77         unsigned int parentRoads = 0;
    78 
    79         unsigned int i;
    80         for (i=0; i<parents; i++)
    81         {
    82                 MapFeature * parent = mapFeature->getParent(i);
    83                 bool isParentRoad = dynamic_cast<Road*>(parent) != 0;
    84                 if (isParentRoad) {
    85                         parentRoads++;
    86                         if (parentRoads > 1)
    87                                 return false;
    88                 }
    89         }
     72        return Road::GetSingleParentRoadInner(mapFeature) != NULL;
     73}
    9074
    91         return (parentRoads == 1);
     75static bool isChildOfSingleRoad(MapFeature *mapFeature)
     76{
     77        return Road::GetSingleParentRoad(mapFeature) != NULL;
    9278}
    9379
    9480static bool isChildOfSingleRelation(MapFeature *mapFeature)
     
    137123        bool IsPoint = false;
    138124        bool IsRoad = false;
    139125        bool IsParentRoad = false;
     126        bool IsParentRoadInner = false;
    140127        bool IsParentRelation = false;
    141128        unsigned int NumRoads = 0;
    142129        unsigned int NumCommitableFeature = 0;
     
    148135                IsPoint = dynamic_cast<TrackPoint*>(Selection[0]) != 0;
    149136                IsRoad = dynamic_cast<Road*>(Selection[0]) != 0;
    150137                IsParentRoad = IsPoint && isChildOfSingleRoad(Selection[0]);
     138                IsParentRoadInner = IsPoint && isChildOfSingleRoadInner(Selection[0]);
    151139                IsParentRelation = isChildOfSingleRelation(Selection[0]);
    152140        }
    153141        for (unsigned int i=0; i<Selection.size(); ++i)
     
    169157        Main->editMoveAction->setEnabled(true);
    170158        Main->editReverseAction->setEnabled(IsRoad);
    171159        Main->roadJoinAction->setEnabled(NumRoads > 1 && canJoinRoads(this));
    172         Main->roadSplitAction->setEnabled(IsParentRoad || (NumRoads && NumPoints));
     160        Main->roadSplitAction->setEnabled(IsParentRoadInner || (NumRoads && NumPoints));
    173161        Main->roadBreakAction->setEnabled(NumRoads > 1 && canBreakRoads(this));
    174162        Main->featureCommitAction->setEnabled(NumCommitableFeature);
    175163        Main->nodeMergeAction->setEnabled(NumPoints > 1);
  • merkaartor\Map\Road.cpp

    old new  
    938938        return parentRoad;
    939939}
    940940
     941Road * Road::GetSingleParentRoadInner(MapFeature * mapFeature)
     942{
     943        unsigned int parents = mapFeature->sizeParents();
     944
     945        if (parents == 0)
     946                return NULL;
     947
     948        Road * parentRoad = NULL;
     949        TrackPoint* trackPoint = dynamic_cast<TrackPoint*>(mapFeature);
     950
     951        unsigned int i;
     952        for (i=0; i<parents; i++)
     953        {
     954                MapFeature * parent = mapFeature->getParent(i);
     955                Road * road = dynamic_cast<Road*>(parent);
     956
     957                if (road == NULL)
     958                        continue;
     959
     960                if (road->isExtrimity(trackPoint))
     961                        continue;
     962               
     963                if (parentRoad)
     964                        return NULL;
     965
     966                if (road->layer()->isEnabled())
     967                        parentRoad = road;
     968        }
     969
     970        return parentRoad;
     971}
     972
  • merkaartor\Map\Road.h

    old new  
    4848
    4949                TrackPoint* getNode(unsigned int idx);
    5050                const TrackPoint* getNode(unsigned int idx) const;
     51               
     52                bool isNodeAtEnd(TrackPoint* node);
    5153
    5254                /** Set the tag "key=value" to the current object
    5355                 * If a tag with the same key exist, it is replaced
     
    98100
    99101                bool isExtrimity(TrackPoint* node);
    100102                static Road * GetSingleParentRoad(MapFeature * mapFeature);
     103                static Road * GetSingleParentRoadInner(MapFeature * mapFeature);
    101104
    102105        protected:
    103106                RoadPrivate* p;