Rev 1010 | Rev 1024 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | |||
961 | werner | 2 | #include "barkbeetlescript.h" |
3 | |||
4 | #include "barkbeetlemodule.h" |
||
5 | |||
6 | |||
7 | |||
8 | BarkBeetleScript::BarkBeetleScript(QObject *) |
||
9 | { |
||
10 | mBeetle = 0; |
||
11 | } |
||
12 | |||
13 | void BarkBeetleScript::test(QString value) |
||
14 | { |
||
15 | qDebug() << value; |
||
16 | } |
||
17 | |||
18 | void BarkBeetleScript::init(QJSValue fun) |
||
19 | { |
||
20 | QJSValueList args = QJSValueList() << 0 << 0; |
||
21 | |||
22 | if (!fun.isCallable()) { |
||
23 | qDebug() << "no valid function in init!!"; |
||
24 | return; |
||
25 | } |
||
26 | for (int y=0;y < mBeetle->mGrid.sizeY(); ++y) |
||
27 | for (int x=0;x < mBeetle->mGrid.sizeX(); ++x) { |
||
28 | args[0] = x; args[1] = y; |
||
29 | double result = fun.call(args).toNumber(); |
||
30 | mBeetle->mGrid.valueAtIndex(x,y).n = result; |
||
31 | } |
||
32 | } |
||
33 | |||
34 | void BarkBeetleScript::run(QJSValue fun) |
||
35 | { |
||
36 | QJSValueList args = QJSValueList() << 0 << 0; |
||
37 | |||
38 | if (!fun.isCallable()) { |
||
39 | qDebug() << "no valid function in run!!"; |
||
40 | return; |
||
41 | } |
||
42 | for (int y=0;y < mBeetle->mGrid.sizeY(); ++y) |
||
43 | for (int x=0;x < mBeetle->mGrid.sizeX(); ++x) { |
||
44 | args[0] = x; args[1] = y; |
||
45 | fun.call(args); |
||
46 | } |
||
47 | } |
||
48 | |||
49 | double BarkBeetleScript::pixelValue(int ix, int iy) |
||
50 | { |
||
51 | if (mBeetle->mGrid.isIndexValid(ix,iy)) { |
||
52 | return mBeetle->mGrid.valueAtIndex(ix, iy).n; |
||
53 | } else { |
||
54 | return -9999; |
||
55 | } |
||
56 | } |
||
57 | |||
58 | void BarkBeetleScript::setPixelValue(int ix, int iy, double val) |
||
59 | { |
||
60 | if (mBeetle->mGrid.isIndexValid(ix,iy)) { |
||
61 | mBeetle->mGrid.valueAtIndex(ix, iy).n = val; |
||
62 | } |
||
63 | } |
||
1008 | werner | 64 | |
65 | double BarkBeetleScript::generations(int ix, int iy) |
||
66 | { |
||
67 | if (mBeetle->mGrid.isIndexValid(ix,iy)) { |
||
68 | return mBeetle->mRUGrid.valueAt( mBeetle->mGrid.cellCenterPoint(QPoint(ix,iy)) ).generations; |
||
69 | } else { |
||
70 | return -9999; |
||
71 | } |
||
72 | |||
73 | } |
||
74 | |||
1010 | werner | 75 | void BarkBeetleScript::reloadSettings() |
76 | { |
||
77 | mBeetle->loadParameters(); |
||
78 | } |
||
79 | |||
1013 | werner | 80 | void BarkBeetleScript::runBB(int iteration) |
1008 | werner | 81 | { |
82 | qDebug() << "running bark beetle module...."; |
||
1013 | werner | 83 | mBeetle->run(iteration); |
1008 | werner | 84 | } |
1013 | werner | 85 | |
86 | void BarkBeetleScript::clear() |
||
87 | { |
||
88 | qDebug() << "clear bark beetle module...."; |
||
89 | mBeetle->clearGrids(); |
||
90 | } |