Fréchet View  1.6.0
A Tool for Exploring Fréchet Distance Algorithms
frechetviewapplication.h
Go to the documentation of this file.
1 #ifndef FRECHETVIEWAPPLICATION_H
2 #define FRECHETVIEWAPPLICATION_H
3 
4 #include <QApplication>
5 #include <QFileSystemWatcher>
6 #include <exception>
7 
8 #include <data/interval.h>
9 #include <input/datapath.h>
10 #include <input/inputreader.h>
11 
12 #include <view/mainwindow.h>
13 #include <poly/algorithm.h>
14 #include <filehistory.h>
15 #include <workerthread.h>
16 
17 namespace frechet { namespace app {
18 
19 using namespace frechet;
20 using namespace view;
21 using namespace reach;
22 using namespace poly;
23 using namespace k;
24 using namespace input;
43 class FrechetViewApplication : public QObject
44 {
45  Q_OBJECT
46 
47 public:
51  enum Algorithm {
54  ALGORITHM_CURVE=0,
56  ALGORITHM_POLYGON=1,
58  ALGORITHM_K_FRECHET=2
59  };
60 
64  enum TriState {
65  NO,
66  YES,
68  };
69 
70 protected:
73 
77  size_t currentId;
78 
85  QFileSystemWatcher* fileWatch;
86 
87  Curve P;
88  Curve Q;
89  Grid::ptr grid;
105  double epsMax;
108 
109 public:
110  // note: int & is essential !!
111  // otherwise QApplication references a stack location !!
117  FrechetViewApplication(QString exec_path, bool withGui);
120 
125  void init(QString file);
126 
137  int commandLineInterface(QString inputFile, Algorithm algo, bool topo,
138  double accuracy, double epsilon) throw(std::exception);
139 
143  Algorithm currentAlgorithm() const { return _currentAlgorithm; }
149  bool currentAlgorithm(Algorithm alg) const { return _currentAlgorithm==alg; }
154  void setCurrentAlgorithm(Algorithm alg);
158  WorkerJobHandle* backgroundJob() { return &bgJob; }
159 
160 signals:
165  void fileOpened(QString file);
170  void algorithmChanged(int algo);
171 
172  // epsilon changes are triggered by ControlPanel
173 
174 public slots:
179  void open(bool firstTime=false);
184  void open(QString filePath);
189  return frechetViewApp;
190  }
194  void quit() {
195  windowClosed(window);
196  QApplication::quit();
197  }
201  void windowClosed(QMainWindow*)
202  {
203  QSettings settings;
204  if (currentId) saveFileSettings(settings,currentId);
205  window->saveSettings(settings);
206  }
207 
209  Grid::ptr getGrid() { return grid; }
211  FreeSpace::ptr getFreeSpace() { return freeSpace; }
213  FSPath::ptr getFSPath() { return fspath; }
217  poly::Algorithm::ptr getPolyAlgorithm() { return polyAlgorithm; }
218 
220  Curve& getP() { return P; }
222  Curve& getQ() { return Q; }
223 
225  void resetAlgorithms();
226 
228  void showAboutDialog();
230  void createDesktopEntry();
232  void editInputFile();
233 
235  void startStopDecidePolygon();
237  void startStopOptimiseCurve();
239  void startStopApproximateCurve();
241  void startStopOptimisePolygon();
243  void startStopApproximatePolygon();
244 
246  void startKBruteForce();
248  void cancelBackgroundJob();
249 
250 private:
252  QString execPath;
258  void saveFileSettings(QSettings& settings, size_t histId);
264  void restoreFileSettings(QSettings& settings, size_t histId);
269  bool showFirstTimeHint();
275  bool setupCurves(bool topo=false);
276 
279  void startStopDecidePolygon(double epsilon);
282  void startStopOptimiseCurve(double approx);
285  void startStopOptimisePolygon(double approx);
286 
288  void installLinuxDesktopIcons(QSettings&);
290  void installLinuxDesktopEntries(QSettings&);
292  QString linuxDesktopFile();
294  bool populateBookmarks();
295 
301  void cli_setup(QString inputFile, Algorithm algo);
307  int cli_decideKFrechet(double epsilon);
308 
310  static void copyContents(QByteArray contents, QString path);
312  static void copyFile(QString src, QString dest);
313 };
314 
315 } } // namespace
316 
317 #endif // FRECHETVIEWAPPLICATION_H
static FrechetViewApplication * instance()
The k-Frechet algorithm.
Definition: kalgorithm.h:113
size_t currentId
reference to current File
The InputReader class reads input data from a file.
Definition: inputreader.h:32
location of input data in an XML file
Definition: datapath.h:24
InputReader reader
reads files from disk
QString execPath
path to executable file
global definitions for all algorithms.
The single application window.
Definition: mainwindow.h:33
double epsMax
maximum value for epsilon
boost::shared_ptr< Algorithm > ptr
(smart) pointer to an Algorithm object
Definition: algorithm.h:236
void saveSettings(QSettings &settings)
store settings to application preferences
Definition: mainwindow.cpp:150
poly::Algorithm::ptr polyAlgorithm
the algorithm for simple polygons and curves (if available)
Algorithm
we have three Fréchet Distance algorithms
base class for algorithm for simple polygons.
Definition: algorithm.h:51
keeps track of recently used files.
Definition: filehistory.h:48
FSPath::ptr fspath
the feasible path (if available)
FileHistory history
Open Recent file history.
k::kAlgorithm::ptr kAlgorithm
the k-Frechet algorithm (if available)
boost::shared_ptr< FSPath > ptr
smart pointer to an FSPath object
Definition: fs_path.h:65
bool currentAlgorithm(Algorithm alg) const
test current algorithm
QPolygonF Curve
a polygonal curve in the plane; with double floating point precision. This type is heavily used throu...
Definition: types.h:20
static FrechetViewApplication * frechetViewApp
singleton instance
TriState
GPU support (for headless mode only)
void windowClosed(QMainWindow *)
called when the main window is closed by the user
Definition: grid.h:18
boost::shared_ptr< Grid > ptr
smart pointer to a Grid object
Definition: grid.h:128
Thread safe access to a WorkerJob.
Definition: workerthread.h:85
void quit()
quit the application, closing all resources and windows
FreeSpace::ptr freeSpace
the free-space diagram
DataPath path
pointer to input data within an xml file
boost::shared_ptr< kAlgorithm > ptr
smart pointer to an kAlgorithm object
Definition: kalgorithm.h:320
boost::shared_ptr< FreeSpace > ptr
smart pointer to FreeSpace object
Definition: freespace.h:92
Algorithm _currentAlgorithm
selects current Algorithm