1 /**********************************************************************************************
2     Copyright (C) 2018 Michel Durand <zero@cms123.fr>
3 
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License
15     along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 
17 **********************************************************************************************/
18 
19 #include "canvas/CCanvas.h"
20 #include "gis/trk/CGisItemTrk.h"
21 #include "gis/trk/filter/CFilterLoopsCut.h"
22 #include "helpers/CSettings.h"
23 #include "units/IUnit.h"
24 
25 #include <QtWidgets>
26 
CFilterLoopsCut(CGisItemTrk & trk,QWidget * parent)27 CFilterLoopsCut::CFilterLoopsCut(CGisItemTrk& trk, QWidget* parent)
28     : QWidget(parent)
29     , trk(trk)
30 {
31     setupUi(this);
32 
33     spinBox->setSuffix(IUnit::self().baseUnit);
34 
35     SETTINGS;
36     spinBox->setValue(cfg.value("TrackDetails/Filter/LoopsCut/minLoopLength", 10 * IUnit::self().baseFactor).toInt() * IUnit::self().baseFactor);
37 
38     connect(toolApply, &QToolButton::clicked, this, &CFilterLoopsCut::slotApply);
39     connect(help, &QToolButton::clicked, this, &CFilterLoopsCut::showHelp);
40 }
41 
~CFilterLoopsCut()42 CFilterLoopsCut::~CFilterLoopsCut()
43 {
44     SETTINGS;
45     cfg.setValue("TrackDetails/Filter/LoopsCut/minLoopLength", spinBox->value() / IUnit::self().baseFactor);
46 }
47 
slotApply()48 void CFilterLoopsCut::slotApply()
49 {
50     CCanvasCursorLock cursorLock(Qt::WaitCursor, __func__);
51     trk.filterLoopsCut(spinBox->value() / IUnit::self().baseFactor);
52 }
53 
showHelp()54 void CFilterLoopsCut::showHelp()
55 {
56     QMessageBox::information(CMainWindow::getBestWidgetForParent(), tr("Help")
57                              , tr("Sometimes tracks have loops.\n\n"
58                                   "It is often the case for mountain bikes tours where the same fire road is used several "
59                                   "times to go back uphill to a high point. "
60                                   "Several downhill paths start from this high point and the same fire road is used again "
61                                   "and again to go back up. The recorded track is made of several loops. However following "
62                                   "a track made of loops on a Garmin device is difficult, as it is impossible to know in what "
63                                   "order loops have to be ridden.\n\n"
64                                   "The purpose of this filter is to split the input track into several separate tracks. "
65                                   "The obtained tracks have no loops and are easy to follow on a Garmin device: start with part 1, "
66                                   "at the end of part 1 switch to part 2, etc..\n\n"
67                                   "This filter detects loops by looking for intersections. A new track is created as soon as an "
68                                   "intersection is detected.\n\n"
69                                   "The only input parameter is minimum loop length: this is to prevent cutting tracks in "
70                                   "tight switchbacks, where recorded tracks can be made of tiny loops. These loops will be ignored "
71                                   "if their lengths are smaller that the given value.")  );
72 }
73