Skip to content

Commit

Permalink
Merge pull request OpenCPN#4301 from nocodehummel/route-seq
Browse files Browse the repository at this point in the history
Improve route waypoint resequencing
  • Loading branch information
bdbcat authored Jan 16, 2025
2 parents a396683 + 8d4bd5b commit 0063968
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
33 changes: 19 additions & 14 deletions gui/src/MarkInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1753,28 +1753,33 @@ bool MarkInfoDlg::SaveChanges() {
} else {
m_pRoutePoint->SetETD(wxEmptyString);
}

// Here is some logic....
// If the Markname is completely numeric, and is part of a route,
// If the name has 3 numeric characters, and is part of a route,
// Then declare it to be of attribute m_bDynamicName = true
// This is later used for re-numbering points on actions like
// Insert Point, Delete Point, Append Point, etc

if (m_pRoutePoint->m_bIsInRoute) {
bool b_name_is_numeric = true;
for (unsigned int i = 0; i < m_pRoutePoint->GetName().Len(); i++) {
if (i < 2 && wxChar('N') == m_pRoutePoint->GetName()[0] &&
wxChar('M') == m_pRoutePoint->GetName()[1] &&
m_pRoutePoint->GetName().Len() > 2)
continue;
if (wxChar('0') > m_pRoutePoint->GetName()[i])
b_name_is_numeric = false;
if (wxChar('9') < m_pRoutePoint->GetName()[i])
b_name_is_numeric = false;
if (m_pRoutePoint->GetName().Len() >= 2) {
wxString substring = m_pRoutePoint->GetName().Left(2);
if (substring == "NM") {
substring = m_pRoutePoint->GetName().substr(2, 3);
} else {
substring = m_pRoutePoint->GetName().Left(3);
}
for (unsigned int i = 0; i < substring.Len(); i++) {
if (b_name_is_numeric == true) {
b_name_is_numeric = wxIsdigit(substring[i]);
}
}
m_pRoutePoint->m_bDynamicName = b_name_is_numeric;
} else {
m_pRoutePoint->m_bDynamicName = false;
}

m_pRoutePoint->m_bDynamicName = b_name_is_numeric;
} else
} else {
m_pRoutePoint->m_bDynamicName = false;
}

if (m_pRoutePoint->m_bIsInRoute) {
// Update the route segment selectables
Expand Down
14 changes: 12 additions & 2 deletions model/src/route.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,18 @@ void Route::RenameRoutePoints(void) {
while (node) {
RoutePoint *prp = node->GetData();
if (prp->m_bDynamicName) {
wxString name;
name.Printf(_T ( "%03d" ), i);
wxString name = prp->GetName();
if (name.Len() == 3) {
name.Printf(_T ( "%03d" ), i);
} else if (name.Left(2) == "NM") {
name.Printf(_T ( "%03d" ), i);
if (prp->GetName().Len() >= 5) {
name.Append(prp->GetName().Mid(5));
}
} else {
name.Printf(_T ( "%03d" ), i);
name.Append(prp->GetName().Mid(3));
}
prp->SetName(name);
}

Expand Down

0 comments on commit 0063968

Please sign in to comment.