iLand
scripttree.h
Go to the documentation of this file.
1#ifndef SCRIPTTREE_H
2#define SCRIPTTREE_H
3
4#include <QObject>
5#include "tree.h"
6#include "species.h"
7#include "expressionwrapper.h"
8
9class ScriptTree : public QObject
10{
11 Q_OBJECT
12 Q_PROPERTY(bool valid READ valid)
13 Q_PROPERTY(double x READ x)
14 Q_PROPERTY(double y READ y)
15 Q_PROPERTY(double dbh READ dbh)
16 Q_PROPERTY(double height READ height)
17 Q_PROPERTY(QString species READ species)
18 Q_PROPERTY(int flags READ flags)
19public:
20 enum TreeRemovalType { RemovedDeath=1, RemovedHarvest=2, RemovedDisturbance=4, RemovedSalavaged=8, RemovedKilled=16, RemovedCutDown=32}; // the same enum as in tree.h, but encoded binary
21 //enum TreeRemovalType { TreeDeath=0, TreeHarvest=1, TreeDisturbance=2, TreeSalavaged=3, TreeKilled=4, TreeCutDown=5}; // the enum in tree.h
22 Q_ENUM(TreeRemovalType)
23 // selected tree flags from tree.h
24 enum Flags { TreeDead=1,
26 TreeAffectedBite=8192 // affected or killed by biotic disturbance module (BITE)
27 };
28 Q_ENUM(Flags)
29 static void addToScriptEngine(QJSEngine &engine);
30
31 explicit ScriptTree(QObject *parent = nullptr);
32 void setTree(Tree *t) { mTree = t; }
33 const Tree *tree() { return mTree; }
34 void clear() { mTree = nullptr; }
35
36 bool valid() const { return mTree != nullptr; }
37 double x() const { return mTree ? mTree->position().x() : -1.; }
38 double y() const { return mTree ? mTree->position().y() : -1; }
39 double dbh() const { return mTree ? static_cast<double>(mTree->dbh()) : -1.; }
40 double height() const { return mTree ? static_cast<double>(mTree->height()) : -1.; }
41 QString species() const { return mTree ? mTree->species()->id() : QStringLiteral("invalid"); }
42 int flags() const { return mTree ? mTree->flags() : 0; }
43
44signals:
45
46public slots:
47 QString info();
48 double expr(QString expr_str);
49
50private:
51 Tree *mTree;
52};
53
54// Expression class
55class ScriptTreeExpr : public QObject
56{
57 Q_OBJECT
58 Q_PROPERTY(QString expression READ expression WRITE setExpression)
59public:
60 Q_INVOKABLE ScriptTreeExpr(QString expr);
61 static void addToScriptEngine(QJSEngine &engine);
62public slots:
63 QString expression() { return mExpression.expression(); }
64 void setExpression(QString expr) { mExpression.setExpression(expr); mExpression.setModelObject(&mTW); }
65 double value(ScriptTree *script_tree );
66private:
67 Expression mExpression;
68 TreeWrapper mTW;
69};
70
71#endif // SCRIPTTREE_H
An expression engine for mathematical expressions provided as strings.
Definition: expression.h:29
void setModelObject(ExpressionWrapper *wrapper)
Definition: expression.h:38
void setExpression(const QString &aExpression)
set expression
Definition: expression.cpp:200
const QString & expression() const
Definition: expression.h:39
Definition: scripttree.h:56
Q_INVOKABLE ScriptTreeExpr(QString expr)
Definition: scripttree.cpp:46
void setExpression(QString expr)
Definition: scripttree.h:64
double value(ScriptTree *script_tree)
Definition: scripttree.cpp:57
QString expression
Definition: scripttree.h:58
QString expression()
Definition: scripttree.h:63
static void addToScriptEngine(QJSEngine &engine)
Definition: scripttree.cpp:51
Definition: scripttree.h:10
double x() const
Definition: scripttree.h:37
double y() const
Definition: scripttree.h:38
double expr(QString expr_str)
Definition: scripttree.cpp:29
bool valid() const
Definition: scripttree.h:36
ScriptTree(QObject *parent=nullptr)
Definition: scripttree.cpp:15
double dbh
Definition: scripttree.h:15
static void addToScriptEngine(QJSEngine &engine)
Definition: scripttree.cpp:8
void setTree(Tree *t)
Definition: scripttree.h:32
bool valid
Definition: scripttree.h:12
double height
Definition: scripttree.h:16
QString species
Definition: scripttree.h:17
double height() const
Definition: scripttree.h:40
double x
Definition: scripttree.h:13
QString species() const
Definition: scripttree.h:41
double y
Definition: scripttree.h:14
int flags
Definition: scripttree.h:18
QString info()
Definition: scripttree.cpp:20
TreeRemovalType
Definition: scripttree.h:20
@ RemovedDeath
Definition: scripttree.h:20
@ RemovedCutDown
Definition: scripttree.h:20
@ RemovedHarvest
Definition: scripttree.h:20
@ RemovedKilled
Definition: scripttree.h:20
@ RemovedSalavaged
Definition: scripttree.h:20
@ RemovedDisturbance
Definition: scripttree.h:20
void clear()
Definition: scripttree.h:34
int flags() const
Definition: scripttree.h:42
const Tree * tree()
Definition: scripttree.h:33
Flags
Definition: scripttree.h:24
@ TreeDead
Definition: scripttree.h:24
@ TreeHarvested
Definition: scripttree.h:25
@ TreeDeadFire
Definition: scripttree.h:25
@ TreeDeadKillAndDrop
Definition: scripttree.h:25
@ TreeDeadWind
Definition: scripttree.h:25
@ TreeDeadBarkBeetle
Definition: scripttree.h:25
@ TreeAffectedBite
Definition: scripttree.h:26
double dbh() const
Definition: scripttree.h:39
const QString & id() const
Definition: species.h:87
A tree is the basic simulation entity of iLand and represents a single tree.
Definition: tree.h:44
const QPointF position() const
metric coordinates of the tree
Definition: tree.h:54
float height() const
tree height in m
Definition: tree.h:63
const Species * species() const
pointer to the tree species of the tree.
Definition: tree.h:58
float dbh() const
dimater at breast height in cm
Definition: tree.h:62
Definition: expressionwrapper.h:42