Fréchet View  1.6.0
A Tool for Exploring Fréchet Distance Algorithms
scriptinput.cpp
Go to the documentation of this file.
1 
2 #include <inputreader.h>
3 
4 #include <QJSEngine>
5 #include <QQmlEngine>
6 #include <QTextStream>
7 #include <QDebug>
8 
9 Q_DECLARE_METATYPE(Path)
10 Q_DECLARE_METATYPE(Path*)
11 
12 bool frechet::input::InputReader::readScript(QString program) {
13 
14  //QQmlEngine qmlEngine;
15  //qmlRegisterType<Path>();
16  qmlRegisterType<Path>("de.fuhagen.ti", 1,0, "Path");
17  qmlRegisterType<Path>("de.fuhagen.ti", 1,0, "frechet::input::Path");
18  //qmlRegisterType<LineStyle>("de.fuhagen.ti", 1,0, "LineStyle");
19  //qmlRegisterType<Path*>("de.fugahen.ti", 1.0,"Path");
20  //qmlRegisterInterface<Path>("Path");
21 
22  QJSEngine engine;
23  engine.installExtensions(QJSEngine::ConsoleExtension);
24  // provide a logging facility
25 
26  Path P, Q;
27  QJSValue global = engine.globalObject();
28 
29  global.setProperty("Path", engine.newQMetaObject<Path>());
30  // important for Constructors!!
31  global.setProperty("P", engine.newQObject(&P));
32  global.setProperty("Q", engine.newQObject(&Q));
33 
34  global.setProperty("SOLID", SOLID);
35  global.setProperty("THIN", THIN);
36  global.setProperty("DOTTED", DOTTED);
37  global.setProperty("NONE", NONE);
38 
39  QJSValue value = engine.evaluate(program);
40  if (value.isError()) {
41  // an error happened
42  QTextStream str(&error_message);
43  str << "Script Error " << "\n"
44  << " line "<< value.property("lineNumber").toInt() << "\n"
45  << value.toString() << "\n";
46  qDebug() << error_message;
47  return false;
48  }
49 
50  Path* pp = dynamic_cast<Path*> (global.property("P").toQObject());
51  Path* pq = dynamic_cast<Path*> (global.property("Q").toQObject());
52  if (!pp || ! pq) {
53  error_message = "P, Q undefined";
54  return false;
55  }
56 
57  results.append(*pp);
58  results.append(*pq);
59 
60  // TODO copy lineStyles to grid
61 
62  return true;
63 }
The InputReader class reads input data from a file.
Definition: inputreader.h:32
global definitions for all algorithms.
void append(QPointF p, char opcode)
Definition: path.cpp:354
draw a dotted line
Definition: grid.h:21
draw a solid line
Definition: grid.h:19
Represents a polygonal curve.
Definition: path.h:30
draw a thin, solid line
Definition: grid.h:20
draw no grid line
Definition: grid.h:22
#define str(S)