Files @ bb80657b6912
Branch filter:

Location: EI/VirtualLeaf/src/canvas.cpp - annotation

Michael Guravage
Export Cell Data at interval specified in the leafML file or explicitly via the file menu.
Added new parameters to VirtualLeafpar.tmpl
Added GPL boilerplate to make_{parameter,pardialog}_source.pl files.
Added new parameters to auxin_growth.xml. See respective ChangeLog files for details.

--
user: Michael Guravage <michael.guravage@cwi.nl>
branch 'default'
changed data/leaves/ChangeLog
changed data/leaves/auxin_growth.xml
changed src/ChangeLog
changed src/VirtualLeafpar.tmpl
changed src/canvas.cpp
changed src/canvas.h
changed src/parameter.cpp
changed src/parameter.h
changed src/pardialog.cpp
changed src/pardialog.h
changed src/perl/ChangeLog
changed src/perl/make_parameter_source.pl
changed src/perl/make_pardialog_source.pl
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
15d600891648
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
15d600891648
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
bb80657b6912
79f94eaa3b9e
21afbd2a2c01
21afbd2a2c01
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
21afbd2a2c01
21afbd2a2c01
18e4f7f50259
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
d897bf22346f
d897bf22346f
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
18e4f7f50259
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
4f82fc35a2b3
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
4f82fc35a2b3
4f82fc35a2b3
79f94eaa3b9e
a58b80c85b6f
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
18e4f7f50259
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
18e4f7f50259
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
d9ce329d84ae
79f94eaa3b9e
d9ce329d84ae
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
18e4f7f50259
782330072e62
18e4f7f50259
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
18e4f7f50259
782330072e62
18e4f7f50259
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
d9ce329d84ae
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
d9ce329d84ae
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
18e4f7f50259
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
18e4f7f50259
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
18e4f7f50259
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
d4a19fde7f8d
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
18e4f7f50259
782330072e62
18e4f7f50259
79f94eaa3b9e
782330072e62
782330072e62
18e4f7f50259
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
18e4f7f50259
782330072e62
18e4f7f50259
782330072e62
18e4f7f50259
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
a58b80c85b6f
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
9a40ab737a73
a58b80c85b6f
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
a58b80c85b6f
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
18e4f7f50259
79f94eaa3b9e
18e4f7f50259
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
15d600891648
15d600891648
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
15d600891648
21afbd2a2c01
15d600891648
15d600891648
15d600891648
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
18e4f7f50259
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
4f82fc35a2b3
79f94eaa3b9e
782330072e62
79f94eaa3b9e
a58b80c85b6f
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
18e4f7f50259
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
18e4f7f50259
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
2c972342206d
79f94eaa3b9e
79f94eaa3b9e
15d600891648
15d600891648
79f94eaa3b9e
2c972342206d
2c972342206d
2c972342206d
782330072e62
2c972342206d
2c972342206d
15d600891648
2c972342206d
2c972342206d
2c972342206d
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
c34d1e30d5b4
c34d1e30d5b4
c34d1e30d5b4
21afbd2a2c01
c34d1e30d5b4
c34d1e30d5b4
21afbd2a2c01
d897bf22346f
21afbd2a2c01
d897bf22346f
d897bf22346f
d897bf22346f
d897bf22346f
d897bf22346f
d897bf22346f
d897bf22346f
d897bf22346f
d897bf22346f
21afbd2a2c01
21afbd2a2c01
c34d1e30d5b4
c34d1e30d5b4
21afbd2a2c01
21afbd2a2c01
21afbd2a2c01
21afbd2a2c01
21afbd2a2c01
21afbd2a2c01
21afbd2a2c01
c34d1e30d5b4
21afbd2a2c01
21afbd2a2c01
21afbd2a2c01
21afbd2a2c01
21afbd2a2c01
21afbd2a2c01
21afbd2a2c01
21afbd2a2c01
21afbd2a2c01
21afbd2a2c01
21afbd2a2c01
c34d1e30d5b4
c34d1e30d5b4
c34d1e30d5b4
c34d1e30d5b4
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
a58b80c85b6f
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
18e4f7f50259
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
18e4f7f50259
782330072e62
18e4f7f50259
18e4f7f50259
782330072e62
18e4f7f50259
18e4f7f50259
18e4f7f50259
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
aaba9e8828d6
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
782330072e62
aaba9e8828d6
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
aaba9e8828d6
aaba9e8828d6
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
782330072e62
aaba9e8828d6
aaba9e8828d6
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
79f94eaa3b9e
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
782330072e62
79f94eaa3b9e
4f82fc35a2b3
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
15d600891648
4f82fc35a2b3
4f82fc35a2b3
79f94eaa3b9e
79f94eaa3b9e
782330072e62
782330072e62
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
79f94eaa3b9e
15d600891648
79f94eaa3b9e
79f94eaa3b9e
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
4f82fc35a2b3
79f94eaa3b9e
79f94eaa3b9e
bb80657b6912
b3943d0b8126
b3943d0b8126
bb80657b6912
b3943d0b8126
9a40ab737a73
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
9a40ab737a73
9a40ab737a73
b3943d0b8126
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
bb80657b6912
79f94eaa3b9e
/*
 *
 *  This file is part of the Virtual Leaf.
 *
 *  VirtualLeaf is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  VirtualLeaf is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with the Virtual Leaf.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  Copyright 2010 Roeland Merks.
 *
 */

#include <time.h>
#include <string>
#include <fstream>
#include <streambuf>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <qdatetime.h>
#include <q3mainwindow.h>
#include <qstatusbar.h>
#include <qmessagebox.h>
#include <qmenubar.h>
#include <qapplication.h>
#include <qpainter.h>
#include <qprinter.h>
#include <qlabel.h>
#include <qimage.h>
#include <q3progressdialog.h>
#include <qtimer.h>
#include <qslider.h>
#include <qpixmap.h>
#include <qfile.h>
#include <qdir.h>
#include <q3filedialog.h>
#include <QGraphicsItem>
#include <QList>
#include <QDir>

#include <QDebug>

#include <set>

//Added by qt3to4:
#include <Q3ValueList>
#include <Q3PopupMenu>
#include <QMouseEvent>
#include <typeinfo>
#include <cstring>
#include <q3process.h>
#include <qlayout.h>
#include <qspinbox.h>
#include <fstream>
#include <sstream>
#include "pardialog.h"
#include "parameter.h"
#include "canvas.h"
#include "node.h"
#include "nodeset.h"
#include "nodeitem.h"
#include "cellitem.h"
#include "wallitem.h"
#include "mesh.h"
#include "xmlwrite.h"
#include "miscq.h"
#include "OptionFileDialog.h"
#include <cstdlib>
#include <cstdio>
#include "modelcatalogue.h"

#include <algorithm>

// Include VIB and PSB logos
#include "psb.xpm"
#include "cwi.xpm"

static const std::string _module_id("$Id$");

using namespace std;

// We use a global variable to save memory - all the brushes and pens in
// the mesh are shared.

#define QUOTE_ME(s) QUOTE_ME_2NDLEV(s)
#define QUOTE_ME_2NDLEV(s) #s

static QColor dark_red("darkRed");


static const int imageRTTI = 984376;
extern Parameter par;
const QString Main::caption("Virtual leaf");
const QString Main::caption_with_file("Virtual leaf: %1");

FigureEditor::FigureEditor(
			   QGraphicsScene& c, Mesh &m, QWidget* parent,
			   const char* name, Qt::WindowFlags f) :
  QGraphicsView(&c,parent), mesh(m)
{
  intersection_line = 0;
  //angle_line = 0;
  setInteractive(true);
  moving = 0;  
  rotation_mode = false;
}


void FigureEditor::clear()
{
  QList<QGraphicsItem *> list = scene()->items();
  QList<QGraphicsItem *>::Iterator it = list.begin();
  for (; it != list.end(); ++it) {
    delete *it;
  }
}

void FigureEditor::wheelEvent(QWheelEvent *event)
{
  scaleView(pow((double)2, -event->delta() / 240.0));
}


void FigureEditor::scaleView (qreal scaleFactor)
{
  qreal factor = matrix().scale(scaleFactor, scaleFactor).mapRect(QRectF(0, 0, 1, 1)). width();
  if (factor < 0.07 || factor > 100) return;
  scale (scaleFactor, scaleFactor);
}

void FigureEditor::Save(const char *fname, const char *format, int sizex, int sizey)
{

  QImage *image = new QImage(sizex, sizey, QImage::Format_RGB32);
  image->fill(QColor(Qt::white).rgb());
  QPainter *painter=new QPainter(image);

  render(painter);

  image->save(QString(fname),format);
  delete painter;
  delete image;
}

void FigureEditor::mousePressEvent(QMouseEvent* e)
{
  static QList<Node*> selected;
  emit MousePressed();

  //QPointF p = matrix().inverted().map(e->pos());
  QPointF p = mapToScene(e->pos());

#ifdef QDEBUG  
  qDebug() << endl << "MousePressEvent location: (" << p.x() << "," << p.y() << ")." << endl;
  qDebug() << "Magnification:  " << Cell::Magnification() << endl;
  qDebug() << "Offsets:  " << Cell::Offset() << endl;
#endif


  QList<QGraphicsItem *> l=scene()->items(p);

#ifdef QDEBUG  
  qDebug() << "MousePressEvents, items: " << l.size() << endl;
  qDebug() << "Mouse button modifier: " << e->modifiers() << endl;
#endif

  if (e->button()==Qt::RightButton || l.size()==0) {

    //cerr << "Drawing an intersection line from " << p.x() << ", " << p.y() << endl;
    intersection_line = new QGraphicsLineItem( 0, scene() );
    intersection_line->setPen( QPen( QColor("red"), 3, Qt::DashLine ) );
    intersection_line->setLine( QLineF(p,p) );
    intersection_line->setZValue( 100 );
    intersection_line->show();
  }

  for (QList<QGraphicsItem *>::Iterator it=l.begin(); it!=l.end(); ++it) {
#ifdef QDEBUG
    qDebug() << typeid(**it).name() << endl;
#endif

    if ( !strcmp(typeid(**it).name(),"8NodeItem")) {

      stringstream data_strstream;
      data_strstream << (dynamic_cast<NodeItem*>(*it))->getNode();
      dynamic_cast<Main *>(parent())->UserMessage(QString(data_strstream.str().c_str()));

      (dynamic_cast<NodeItem*>(*it))->OnClick(e->button());
    }
    else 
      if ( !strcmp(typeid(**it).name(),"8CellItem") ) {

	Cell &c=((dynamic_cast<CellItem *>(*it))->getCell());      
	// OnClick to be defined in end-user code
	c.OnClick(e);
      } else {
	if ( !strcmp(typeid(**it).name(),"8WallItem") ) {
	  (dynamic_cast<WallItem *>(*it))->OnClick(e);
	} 
      }
  }

  FullRedraw();
  moving = 0;
}

void FigureEditor::mouseMoveEvent(QMouseEvent* e)
{

  // User chooses "rotation mode" and we can rotate the object around its center of mass
  if (dynamic_cast<Main *>(parent())->RotationModeP()) {

    QPointF p = mapToScene(e->pos());
    p.setX(p.x() / Cell::Magnification());
    p.setY(p.y() / Cell::Magnification());


    // get object's center of mass
    QPointF rotation_midpoint = mesh.Centroid()*Cell::Factor() - Cell::Offset();


    // calculate rotation angle
    double dy = (rotation_midpoint.y() - p.y());
    double dx = (rotation_midpoint.x() - p.x());
    double new_rot_angle = atan2(dx, dy);
    double d_alpha = new_rot_angle - rot_angle;
    rot_angle = new_rot_angle;

    mesh.Rotate(d_alpha, ( Vector(rotation_midpoint) + Cell::Offset() ) / Cell::Factor() );

    dynamic_cast<Main *>(parent())->Plot(0);
    FullRedraw();
    return;
  }
 
  
  if ( moving ) {

    QPointF p = mapToScene(e->pos());
    moving->userMove(p.x() - moving_start.x(),
		     p.y() - moving_start.y());
    moving_start = p;
    scene()->update();

  }

  //cerr << "event";

  // keep track of intersection line to interactively cut a growing leaf

  if ( intersection_line ) {

    QPointF sp = intersection_line -> line().p1(); // startpoint
    QPointF ep = mapToScene(e->pos()); // endpoint
    intersection_line -> setLine( QLineF(sp, ep) ); 
    scene()->update();
    // Need this for Mac
    FullRedraw();
  }
}

//void FigureEditor::contentsMouseReleaseEvent(QMouseEvent* e)
void FigureEditor::mouseReleaseEvent(QMouseEvent* e)
{

  emit MouseReleased();
  // intersection line for leaf was finished now.

  if (e->button()==Qt::LeftButton) { 
    if (intersection_line ) {
#ifdef QDEBUG
      qDebug() << "Trying to cut leaf" << endl;
#endif
      QPointF sp = intersection_line -> line().p1(); // startpoint
      QPointF ep = mapToScene(e->pos());

      intersection_line -> setLine( QLineF(sp, ep) ); 
      intersection_line -> show();

      vector <CellItem *> intersected_cells = getIntersectedCells();

      // no cells selected, do nothing
      if (intersected_cells.size()==0) {
#ifdef QDEBUG
	qDebug() << "No cells detected :-(" << endl;
#endif
	return;
      }


      Vector startpoint = Vector(sp.x(), sp.y()) / Cell::Factor() - Cell::Offset();
      Vector endpoint = Vector(ep.x(), ep.y()) / Cell::Factor() - Cell::Offset();

      NodeSet *node_set = new NodeSet;

      for (vector<CellItem *>::iterator it = intersected_cells.begin(); it != intersected_cells.end(); it++) {
	(*it)->setBrush(QBrush("purple"));
	
	Cell &c=(*it)->getCell();

	// sometimes the cell hasn't properly divided yet before the
	// next division is called?  so check for it?  let's find a way
	// to do this later. Note that this functionality currently
	// might result in a segmentation fault for users who are
	// quickly dragging and releasing division lines...
	scene()->update();

#ifdef QDEBUG
	qDebug() << "Dividing Cell " << c.Index() << endl;
#endif

	c.DivideOverGivenLine( startpoint, endpoint, true, node_set);
      }

      node_set->CleanUp();
      mesh.AddNodeSet(node_set);

#ifdef QDEBUG
      qDebug() << "Done DivideOverGivenLine" << endl;
#endif

      mesh.TestIllegalWalls();
      // Do the actual cutting and removing
      if (intersected_cells.size()) {
	mesh.CutAwayBelowLine( startpoint, endpoint ); 

	// Correct flags of nodeset
	for (NodeSet::iterator i = node_set->begin(); i != node_set->end(); i++) {
	  (*i)->SetSAM();
	  (*i)->SetBoundary();
	}

	// Make cells attached to nodeset part of the boundary
	// This is a temporary solution for the following:
	//   If a cell attached to a NodeSet divides (with a division plane intersecting the node set), 
	//   we must insert a new node into the node set.
	// For now, we add a layer of "virtual cells" inbetween. 
	list<Cell *> cells_attached_to_nodeset = node_set->getCells();
	for ( list<Cell *>::iterator c = cells_attached_to_nodeset.begin(); c != cells_attached_to_nodeset.end(); c++) {
	  (*c)->SetBoundary(Cell::SAM);
	}



#ifdef QDEBUG
	qDebug() << "Done CutAwayBelowLine" << endl;
#endif
	mesh.TestIllegalWalls();
	mesh.RepairBoundaryPolygon();
#ifdef QDEBUG
	qDebug() << "Done RepairBoundaryPolygon" << endl;
#endif
	mesh.TestIllegalWalls();
	mesh.CleanUpWalls();
#ifdef QDEBUG
	qDebug() << "Done CleanUpWalls" << endl;
#endif
	mesh.TestIllegalWalls();
      }

      dynamic_cast<Main *>(parent())->Plot();

#ifdef QDEBUG
      cerr << "NodeSet of cutting line: " << *node_set << endl;
#endif
    }
  } else 
    if (e->button()==Qt::RightButton) {

      if (intersection_line /* && !angle_line*/) {

	QPointF p = mapToScene(e->pos());
	QPointF sp = intersection_line->line().p1();

	viewport()->setMouseTracking( TRUE );
      } 
    }
}


// returns a vector of pointer to cells colliding with intersection line
vector <CellItem *> FigureEditor::getIntersectedCells(void)
{ 
  vector <CellItem *> colliding_cells;

  QList<QGraphicsItem *> l = intersection_line->collidingItems( );

#ifdef QDEBUG
  qDebug() <<  "l.size() = " << l.size() << endl;
#endif

  for (QList<QGraphicsItem *>::Iterator it=l.begin(); it!=l.end(); ++it) {

#ifdef QDEBUG
    qDebug() << typeid(**it).name() << endl;
#endif

    if ( !strcmp(typeid(**it).name(),"8CellItem") ) {
      colliding_cells.push_back(dynamic_cast<CellItem *>(*it));
    }
  }

  delete intersection_line;
  intersection_line = 0;
  return colliding_cells;
}

void FigureEditor::FullRedraw(void)
{
  QList<QRectF> rl;
  rl << sceneRect();
  updateScene(rl);   
}


NodeItem *FigureEditor::selectedNodeItem(QList<QGraphicsItem *> graphicItems) const
{
  NodeItem *nodeItem = 0;
  // graphicItems is a list of the QgraphicItems under the mouse click event 
  QList<QGraphicsItem *>::Iterator it = graphicItems.begin();
  for (; it != graphicItems.end(); ++it) {
    if ( !strcmp(typeid(**it).name(),"8NodeItem")) {
      // the object under the mouse click is a Nodeitem
      nodeItem = dynamic_cast<NodeItem *>(*it);
      // indicate we've selected it
      nodeItem->setBrush(dark_red);
      break;
    }
  }
  return nodeItem;
}


void FigureEditor::insertNode(QPointF p)
{
  Node *node = new Node(p.x(), p.y(), 0);
  mesh.AddNode(node);
  scene()->clearSelection();
  dynamic_cast<Main *>(parent())->Plot();
  FullRedraw();
#ifdef QDEBUG  
  qDebug() << "Node: " << p << endl;
#endif
}

static uint mainCount = 0;

Main::Main(QGraphicsScene& c, Mesh &m, QWidget* parent, const char* name, Qt::WindowFlags f) :
  Q3MainWindow(parent,name,f),
  MainBase(c,m),
  mesh(m)
{
  editor = new FigureEditor(canvas,mesh, this);

#ifdef QDEBUG
  qDebug() << "Interactive = " << editor->isEnabled();
#endif

  working_dir = 0;
  QObject::connect( editor, SIGNAL(MousePressed()), this, SLOT(PauseIfRunning()));
  QObject::connect( editor, SIGNAL(MouseReleased()), this, SLOT(ContIfRunning()));
  QMenuBar* menu = menuBar();

  Q3PopupMenu* file = new Q3PopupMenu( menu );

  file->insertItem("&Read leaf", this, SLOT(readStateXML()));
  file->insertItem("&Save leaf", this, SLOT(saveStateXML()));
  file->insertItem("Snapshot", this, SLOT(snapshot()), Qt::CTRL+Qt::SHIFT+Qt::Key_S);

  file->insertSeparator();
  file->insertItem("Read next leaf", this, SLOT(readNextStateXML()), Qt::Key_PageDown);
  file->insertItem("Read previous leaf", this, SLOT(readPrevStateXML()), Qt::Key_PageUp);
  file->insertItem("Read last leaf", this, SLOT(readLastStateXML()), Qt::Key_End);
  file->insertItem("Read first leaf", this, SLOT(readFirstStateXML()), Qt::Key_Home);
  file->insertItem("Export cell areas", this, SLOT(exportCellData()));

  file->insertSeparator();
  file->insertItem("&Print...", this, SLOT(print()), Qt::CTRL+Qt::Key_P);
  file->insertSeparator();
  file->insertItem("E&xit", qApp, SLOT(quit()), Qt::CTRL+Qt::Key_Q);
  menu->insertItem("&File", file);

  Q3PopupMenu* edit = new Q3PopupMenu( menu );
  edit->insertItem("Reset Chemicals and Transporters", this, SLOT( CleanMesh()), Qt::CTRL+Qt::Key_R );
  edit->insertItem("Reset Chemicals", this, SLOT( CleanMeshChemicals()) );
  edit->insertItem("Reset Transporters", this, SLOT( CleanMeshTransporters()) );
  edit->insertItem("Randomize PIN1 Transporters", this, SLOT( RandomizeMesh()) );
  edit->insertItem("Cut away SAM", this, SLOT( CutSAM() ));
  menu->insertItem("&Edit", edit);

  run = new Q3PopupMenu( menu );
  running = false;
  paused_id = run->insertItem("&Simulation paused", this, SLOT(togglePaused()), Qt::Key_S);
  run->setItemChecked(paused_id, FALSE);

  menu->insertItem("&Run", run);

  view = new Q3PopupMenu( menu );
  view->insertItem("&Zoom in", this, SLOT(zoomIn()), Qt::CTRL+Qt::Key_Equal);
  view->insertItem("Zoom &out", this, SLOT(zoomOut()), Qt::CTRL+Qt::Key_Minus);
  view->insertSeparator();
  com_id = view->insertItem("Show cell &centers", this, SLOT(toggleShowCellCenters()));
  view->setItemChecked(com_id, FALSE);

  mesh_id = view->insertItem("Show &nodes", this, SLOT(toggleShowNodes()), Qt::CTRL+Qt::SHIFT+Qt::Key_N);
  view->setItemChecked(mesh_id, TRUE);
  node_number_id = view->insertItem("Show node numbers", this, SLOT(toggleNodeNumbers()), Qt::CTRL+Qt::SHIFT+Qt::Key_M);
  view->setItemChecked(node_number_id, FALSE);
  cell_number_id = view->insertItem("Show cell numbers", this, SLOT(toggleCellNumbers()));
  view->setItemChecked(cell_number_id, FALSE);
  hide_cells_id = view->insertItem("Hide cells", this, SLOT(toggleHideCells()));
  view->setItemChecked(hide_cells_id, FALSE);
  border_id = view->insertItem("Show &border cells", this, SLOT(toggleShowBorderCells()));
  view->setItemChecked(border_id, FALSE);
  cell_axes_id = view->insertItem("Show cell &axes", this, SLOT(toggleCellAxes()));
  cell_strain_id = view->insertItem("Show cell &strain", this, SLOT(toggleCellStrain()));
  view->setItemChecked(cell_axes_id, FALSE);
  fluxes_id = view->insertItem("Show &fluxes", this, SLOT(toggleShowFluxes()));
  view->setItemChecked(fluxes_id, FALSE);
  cell_walls_id = view->insertItem("Show transporters", this, SLOT(toggleShowWalls()));
  view->setItemChecked(cell_walls_id, FALSE);
 // apoplasts_id = view->insertItem("Show apoplasts", this, SLOT(toggleShowApoplasts()));
 // view->setItemChecked(apoplasts_id, FALSE);
  view->insertSeparator();
  only_boundary_id = view->insertItem("Show only leaf &boundary", this, SLOT(toggleLeafBoundary()));
  view->insertSeparator();
  movie_frames_id = view->insertItem("Start saving movie &frames", this, SLOT(toggleMovieFrames()));
  view->setItemChecked(movie_frames_id, par.movie);

  view->setItemChecked(only_boundary_id, FALSE);
  menu->insertItem("&View", view);


  options = new Q3PopupMenu( menu );
  dyn_cells_id = options->insertItem("Cell growth", this, SLOT(toggleDynCells()));
  options->setItemChecked(dyn_cells_id, true);

  options->insertItem("Edit &parameters", this, SLOT(EditParameters()), Qt::CTRL+Qt::Key_E);

  rotation_mode_id = options->insertItem("Rotate leaf", this, SLOT(EnterRotationMode()), Qt::CTRL + Qt::SHIFT + Qt::Key_R);
  options->setItemChecked(rotation_mode_id, false);

  menu->insertItem("&Options",options);

  // Menu of models
  modelmenu = new QMenu( menu );
  menu->insertItem("&Models", modelmenu);


  menu->insertSeparator();

  helpmenu = new Q3PopupMenu( menu );
  tooltips_id = helpmenu->insertItem("Show Cell&Info", this, SLOT(Refresh()));
  helpmenu->setItemChecked(tooltips_id, true);
  helpmenu->insertSeparator();
    //helpmenu->insertSeparator();
  helpmenu->insertItem("&LICENSE", this, SLOT(gpl()) );
  helpmenu->insertItem("About", this, SLOT(about()) ); //, Key_F1);
	
	menu->insertItem("&Help",helpmenu);
  statusBar();
  setCentralWidget(editor);
  printer = 0;
  init();

  // Start timer which repetitively invokes
  // a simulation time step
  timer = new QTimer( this );
  connect( timer, SIGNAL(timeout()), SLOT(TimeStepWrap()) );

  stopSimulation();
  statusBar()->addWidget(new QLabel("Ready."));
  setCaption(caption);
  gifanim = 0;

  infobar = new InfoBar();
  addDockWindow(infobar);
}

void Main::RefreshInfoBar(void)
{
  infobar->SetText(mesh.ModelID());
}


void Main::UserMessage(QString message, int timeout)
{
  statusBar()->showMessage(message, timeout);
}


void Main::init()
{
  clear();

  static int r=24;
  srand(++r);

  mainCount++;
}

Main::~Main()
{
  delete printer;
  if ( !--mainCount ) {
  }
  //EndGifAnim();
}

void Main::newView()
{
  // Open a new view... have it delete when closed.
  Main *m = new Main(canvas, mesh, 0, 0, Qt::WDestructiveClose);
  qApp->setMainWidget(m);
  m->show();
  qApp->setMainWidget(0);
}


void Main::EditParameters()
{

  ParameterDialog *pardial = new ParameterDialog(this, "stridediag");

  // Make sure the values in the parameter dialog are updated after a file is read 
  // each method changing the parameters (reading XML or PAR files) should
  // emit this signal
  QObject::connect(   this, SIGNAL( ParsChanged() ), pardial, SLOT( Reset() ) );
}

void Main::savePars()
{

  stopSimulation();

  Q3FileDialog *fd = new Q3FileDialog( this, "file dialog", TRUE );
  fd->setMode( Q3FileDialog::AnyFile );
  fd->setFilter( "Parameter files (*.par)");

  QString fileName;
  if ( fd->exec() == QDialog::Accepted ) {
    fileName = fd->selectedFile();
    ofstream parfile((const char *)fileName);
    par.Write(parfile);
  }

  startSimulation();
}

void Main::readPars()
{

  stopSimulation();

  Q3FileDialog *fd = new Q3FileDialog( this, "file dialog", TRUE );
  fd->setMode( Q3FileDialog::ExistingFile );
  fd->setFilter( "Parameter files (*.par)");

  QString fileName;
  if ( fd->exec() == QDialog::Accepted ) {
    fileName = fd->selectedFile();
    par.Read((const char *)fileName);
  }

  emit ParsChanged();
}


void Main::saveStateXML()
{

  stopSimulation();
  Q3FileDialog *fd = new Q3FileDialog( this, "file dialog", TRUE );
  fd->setMode( Q3FileDialog::AnyFile );
  fd->setFilter( "XML (*.xml)");
  QString fileName;

  if ( fd->exec() == QDialog::Accepted ) {
    fileName = fd->selectedFile();
    if ( QFile::exists( fileName ) &&
	 QMessageBox::question(
			       this,
			       tr("Overwrite File? -- Leaf Growth"),
			       tr("A file called %1 already exists."
				  "Do you want to overwrite it?")
			       .arg( fileName ),
			       tr("&Yes"), tr("&No"),
			       QString::null, 1, 1 ) ) {
      return saveStateXML();

    } else {

      mesh.XMLSave((const char *)fileName, XMLSettingsTree());

    }
  }
}



void Main::snapshot()
{


  stopSimulation();
  Q3FileDialog *fd = new Q3FileDialog( this, "Save snapshot", TRUE );
  fd->setMode( Q3FileDialog::AnyFile );

  QString fileName;

  if ( fd->exec() == QDialog::Accepted ) {
    fileName = fd->selectedFile();
    if ( QFile::exists( fileName ) &&
	 QMessageBox::question(
			       this,
			       tr("Overwrite File? -- Leaf Growth"),
			       tr("A file called %1 already exists."
				  "Do you want to overwrite it?")
			       .arg( fileName ),
			       tr("&Yes"), tr("&No"),
			       QString::null, 1, 1 ) ) {
      return snapshot();

    } else {

      // extract extension from filename
      QString extension = getExtension(fileName);

      // Save bitmaps at 1024x768
      Save((const char *)fileName, extension, 1024, 768);
    }
  }
}



void Main::readPrevStateXML()
{

  // if we have already read a file, read the next file
  if (!currentFile.isEmpty() && working_dir) {
    QString next_file;

    QStringList xml_files = working_dir->entryList("*.xml");
    QString currentFile_nopath = currentFile.section( '/', -1 );
    QString currentFile_path = currentFile.section( '/', 0, -2 );

    QList<QString>::iterator f = xml_files.find( currentFile_nopath );

    if (f == xml_files.end()) {
      return;
    }

    if (f==xml_files.begin()) {
      QMessageBox mb( "Read previous leaf",
		      "No more files",
		      QMessageBox::Information,
		      QMessageBox::Ok | QMessageBox::Default,
		      QMessageBox::NoButton,
		      QMessageBox::NoButton);
      mb.exec();
      return;
    }
    next_file = *(--f);
    next_file = currentFile_path+"/"+next_file;

    readStateXML((const char *)next_file);

  }
}

int Main::readStateXML(const char *filename, bool geometry, bool pars, bool simtime)
{

  try {
    xmlNode *settings;
    mesh.XMLRead((const char *)filename, &settings, geometry, pars, simtime);
#ifdef QDEBUG
    qDebug() << "Reading done."<< endl;
#endif
    XMLReadSettings(settings);
    xmlFree(settings);
    Cell::SetMagnification(1);
    Cell::setOffset(0,0);

    FitLeafToCanvas();
    
    currentFile =  QString(filename);

    Plot();
    QString status_message = QString("Successfully read leaf from file %1. Time is %2 h.").arg(currentFile).arg(mesh.getTimeHours().c_str());
    cerr << status_message.toStdString() << endl;
    setCaption(caption_with_file.arg(filename));
    statusBar()->message(status_message);
    emit ParsChanged();
#ifdef QDEBUG
    qDebug() << "Done. Returning 0." << endl;
#endif
    return 0;
  } catch (const char *error_message) {
    QMessageBox mb( "Read leaf from XML file",
		    QString(error_message),
		    QMessageBox::Critical,
		    QMessageBox::Ok | QMessageBox::Default,
		    Qt::NoButton,
		    Qt::NoButton);
    mb.exec();
    return 1;
  }
}


void Main::readNextStateXML()
{

  // if we have already read a file, read the next file
  if (!currentFile.isEmpty() && working_dir) {
    QString next_file;

    QStringList xml_files = working_dir->entryList("*.xml");
    QString currentFile_nopath = currentFile.section( '/', -1 );
    QString currentFile_path = currentFile.section( '/', 0, -2 );


    QList<QString>::iterator f = xml_files.find( currentFile_nopath );

    if (f == xml_files.end()) {
      return;
    }

    ++f;
    if (f==xml_files.end()) {
      QMessageBox mb( "Read next leaf",
		      "No more files",
		      QMessageBox::Information,
		      QMessageBox::Ok | QMessageBox::Default,
		      QMessageBox::NoButton,
		      QMessageBox::NoButton);
      mb.exec();
      return;
    }
    next_file = *f;
    next_file = currentFile_path+"/"+next_file;

    readStateXML((const char*)next_file);
  }
}

void Main::readLastStateXML()
{

  // if we have already read a file, read the next file
  if (!currentFile.isEmpty() && working_dir) {
    QString next_file;

    QStringList xml_files = working_dir->entryList("*.xml");
    QString currentFile_nopath = currentFile.section( '/', -1 );
    QString currentFile_path = currentFile.section( '/', 0, -2 );


    next_file = xml_files.back();

    next_file = currentFile_path+"/"+next_file;

    readStateXML((const char*)next_file);
  }
}


void Main::readFirstStateXML()
{

  // if we have already read a file, read the next file
  if (!currentFile.isEmpty() && working_dir) {
    QString next_file;

    QStringList xml_files = working_dir->entryList("*.xml");
    QString currentFile_nopath = currentFile.section( '/', -1 );
    QString currentFile_path = currentFile.section( '/', 0, -2 );


    next_file = xml_files.front();

    next_file = currentFile_path+"/"+next_file;

    readStateXML((const char*)next_file);
  }
}

void Main::readStateXML()
{

  //  extern Mesh mesh;

  stopSimulation();
#ifdef QDEBUG
  qDebug() << "Trying to open an OptionFileDialog" << endl;
#endif
  OptionFileDialog *fd = new OptionFileDialog( this, "read dialog", TRUE );
  fd->setMode( OptionFileDialog::ExistingFile );
  fd->setFilter( "XML files (*.xml)");
  if (working_dir) {
    fd->setDir(*working_dir);
  }
  QString fileName;
  if ( fd->exec() == QDialog::Accepted ) {

    fileName = fd->selectedFile();
    if (working_dir) {
      delete working_dir;
    }
    working_dir = fd->dir();

    if (readStateXML((const char *)fileName,fd->readGeometryP(), fd->readParametersP()) )
      return readStateXML(); // user can try again
  }
}


void Main::clear()
{
  editor->clear();
}

void Main::about()
{
  static QMessageBox* about = new QMessageBox
    ( "VirtualLeaf V1.0",
      "<h3>VirtualLeaf V1.0</h3>"
      "<p>"
      "An Open Source framework for cell-based modeling of plant tissue growth and development <br>"
      "(c) 2005-2008, Roeland Merks <i>et al.</i><br>"
      "    <a href=\"http://www.psb.vib-ugent.be\">VIB Department Plant Systems Biology</a>, "
      "Ghent, Belgium <br>"
      "(c) 2008-2010, <a href=\"http://www.cwi.nl/~merks\">Roeland Merks <i>et al.</i></a> <br>"
      "    <a href=\"http://www.cwi.nl\">Centrum Wiskunde & Informatica</a> and <a href=\"http://www.ncsb.nl\">Netherlands Consortium for Systems Biology</a>, Amsterdam, Netherlands <br>"
"<br>VirtualLeaf is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.<br>"
      "<br>If you use this code for your projects, please cite our paper:"
"<br>Merks, Guravage, Inze, and Beemster. An Open Source framework for cell-based modeling of plant tissue growth and development. <i>Plant Physiology,</i> submitted.<br> . <br>"
      "<br>Please share your model plugins and extensions at <a href=\"http://virtualleaf.googlecode.com\">http://virtualleaf.googlecode.com</a>.", 
      QMessageBox::Information, 1, 0, 0, this, 0, FALSE );
  about->setButtonText( 1, "Dismiss" );
  about->show();
}


void Main::gpl()
{
  static QMessageBox* gpl = new QMessageBox ( "GPL License", "", 
      QMessageBox::Information, 1, 0, 0, this, 0, FALSE );

  QDir docDir(QApplication::applicationDirPath());
  docDir.cd("../doc"); // Where Linux expects gpl3.txt
  QString path = docDir.filePath("gpl3.txt");
  if (!docDir.exists("gpl3.txt")){
    docDir = QApplication::applicationDirPath();
    docDir.cd("doc"); // Where Windows expects gpl3.txt
    path = docDir.filePath("gpl3.txt");
  }

  // At this point path points either to the linux variant, which
  // exists, or the windows variant, which may exist. Testing the
  // ifstream object will determine whether we've found gpl3.txt.

  std::ifstream file(path.toStdString().c_str());
  std::string str;

  if (file) {
    file.seekg(0, std::ios::end);   
    str.reserve(file.tellg());
    file.seekg(0, std::ios::beg);

    str.assign((std::istreambuf_iterator<char>(file)),
	       std::istreambuf_iterator<char>());

    gpl->setDetailedText(QString(str.c_str()));
  }

  gpl->setText(QString( "<h3>GNU GENERAL PUBLIC LICENSE</h3>"
			"<p>Version 3, 29 June 2007</p>"
			"<p>Copyright &copy; 2007 Free Software Foundation, Inc. "
			"&lt;<a href=\"http://fsf.org/\">http://fsf.org/</a>&gt;</p><p>"
			"Everyone is permitted to copy and distribute verbatim copies "
			"of this license document, but changing it is not allowed.</p>"
			"<h2>GNU GENERAL PUBLIC LICENSE</h2>"));

  gpl->setButtonText( 1, "Dismiss" );
  gpl->show();
}

void Main::aboutQt(){
  QMessageBox::aboutQt( this, "Virtual Leaf" );
}

void Main::toggleShowCellCenters()
{
  Plot();
}

void Main::toggleShowWalls()
{
  Plot();
}

void Main::toggleShowApoplasts()
{
  Plot();
}

void Main::toggleShowNodes()
{
  Plot();
}

void Main::toggleNodeNumbers(void)
{
  Plot();
}

void Main::toggleCellNumbers(void)
{
  Plot();
}

void Main::toggleCellAxes(void)
{
  Plot();
}

void Main::toggleCellStrain(void)
{
  Plot();
}

void Main::toggleShowFluxes(void)
{
  Plot();
}

void Main::toggleShowBorderCells()
{
  Plot();
}

void Main::toggleHideCells(void)
{
  Plot();
  editor->FullRedraw();
}

void Main::toggleMovieFrames(){}

void Main::toggleLeafBoundary(){}

void Main::toggleDynCells() {}

void Main::startSimulation(void)
{
  timer->start( 0 );
  statusBar()->message("Simulation started");
  running = true;
}

void Main::stopSimulation(void)
{
  timer->stop();
  cerr << "Stopping simulation" << endl;
  statusBar()->message("Simulation paused");
  running = false;
}

void Main::togglePaused()
{
  bool s = run->isItemChecked(paused_id);
  if (s) {
    cerr << "Calling start simulation" << endl;
    startSimulation();
  } else {
    cerr << "Calling stop simulation" << endl;
    stopSimulation();
  }
}

void Main::setFluxArrowSize(int size)
{
  flux_arrow_size = size/100.;
}


void Main::enlarge()
{
  canvas.setSceneRect( QRectF( 0,0, canvas.width()*4./3., canvas.height()*4./3.) );
}

void Main::shrink()
{
  canvas.setSceneRect( QRectF( 0,0, canvas.width()*3/4, canvas.height()*3/4) );
}


void Main::scale(double factor)
{
  QMatrix m = editor->matrix();
  m.scale(factor, factor);
  editor->setMatrix( m );
}

void Main::zoomIn()
{
  QMatrix m = editor->matrix();
  m.scale( 1.1, 1.1 );
  editor->setMatrix( m );
}

void Main::zoomOut()
{
  QMatrix m = editor->matrix();
  m.scale( 0.9, 0.9 );
  editor->setMatrix( m );
}


void Main::print()
{
  if ( !printer ) printer = new QPrinter;

  if ( printer->setup(this) ) {

    //    extern Mesh mesh;
    Vector bbll,bbur;
    mesh.BoundingBox(bbll,bbur);

#ifdef QDEBUG
    qDebug() << "bbll = " << bbll << endl;
    qDebug() << "bbur = " << bbur << endl;
#endif
    double cw = (bbur.x - bbll.x);
    double ch = (bbur.y - bbll.y);
    QPainter pp(printer);
    QRect vp=pp.viewport();
#ifdef QDEBUG
    qDebug() << "Paper width = " << vp.width() << " x " << vp.height() << endl;
#endif

    // Note that Cell is also translated...
    pp.translate(-bbur.x,-bbur.y);
    if (cw>ch) {
      pp.scale(vp.width()/(2*cw*Cell::Magnification()), vp.width()/(2*cw*Cell::Magnification()));
    } else {
      pp.scale(vp.height()/(2*ch*Cell::Magnification()), vp.height()/(2*ch*Cell::Magnification()));
    }
    canvas.render(&pp, QRectF(), QRectF(0.,0.,canvas.width(),canvas.height()));
  }
}


void Main::TimeStepWrap(void)
{
  static int t=0;
  TimeStep();
  t++;

  if ((par.export_interval > 0) && ((t % par.export_interval) == 0)){
    this->exportCellData(QString(par.datadir) + QString('/') + QString(par.export_fn_prefix) + this->TimeStamp());
  }

  // check number of timesteps
  if (t==par.nit) {
    emit SimulationDone();
  }
}


QString Main::TimeStamp(){
  time_t rawtime;
  struct tm * timeinfo;
  char buffer [15];

  time ( &rawtime );
  timeinfo = localtime ( &rawtime );
  strftime (buffer,15,"%Y%m%d%H%M%S",timeinfo);
  return QString(buffer);
}


void Main::RestartSim(void)
{

  stopSimulation();
  if ( QMessageBox::question(
			     this,
			     tr("Restart simulation?"),
			     tr("Restart simulation.\n"
				"Are you sure?"),
			     QMessageBox::Yes | QMessageBox::No, QMessageBox::NoButton ) == QMessageBox::Yes ) {

    cerr << "Restarting simulation" << endl;
    //    extern Mesh mesh;
    mesh.Clear();
    Init();
    Plot();
    editor->FullRedraw();
  } 
  //startSimulation();
}


void Main::FitCanvasToWindow(void)
{

  double scale_factor_x = (double)editor->width()/(double)canvas.width();
  double scale_factor_y = (double)editor->height()/(double)canvas.height();
  double scale_factor = scale_factor_x > scale_factor_y ? scale_factor_x : scale_factor_y;
  QMatrix m = editor->matrix();

#ifdef QDEBUG  
  qDebug() << "editor->width() = " << editor->width() << endl;
  qDebug() << "editor->height() = " << editor->height() << endl;

  qDebug() << "scale_factor = " << scale_factor << endl;
  qDebug() << "scale_factor_x = " << scale_factor_x << endl;
  qDebug() << "scale_factor_y = " << scale_factor_y << endl;
#endif
  m.scale( scale_factor, scale_factor );
  editor->setMatrix( m );
  editor->show();
}

void Main::PauseIfRunning(void)
{
  if (running) {
    timer->stop();
  }
}

void Main::ContIfRunning(void)
{
  if (running) {
    timer->start( 0 );
  }
}

void Main::FitLeafToCanvas(void) 
{

  Vector ll,ur;
  mesh.BoundingBox(ll, ur);

  ll*=Cell::Magnification(); ur*=Cell::Magnification();

  // give the leaf some space
  Vector border = ((ur-ll)/5.);

  QRectF bb( ll.x - border.x, ll.y - border.y, ur.x-ll.x + 2*border.x, ur.y-ll.y + 2*border.y );


  // cerr << ur << ", " << ll << endl;
  // editor->fitInView(bb, Qt::KeepAspectRatio);
  editor->ensureVisible(bb);
  //editor->setTransform(viewport);
}

void Main::CleanMesh(void) 
{
  vector<double> clean_chem(Cell::NChem());
  vector<double> clean_transporters(Cell::NChem());

  for (int i=0;i<Cell::NChem();i++) {
    clean_chem[i]=par.initval[i];
    clean_transporters[i]=0.;		
  }

  mesh.CleanChemicals(clean_chem);
  mesh.CleanTransporters(clean_transporters);

  mesh.setTime(0);
  Plot();

  editor->FullRedraw();
}

void Main::CleanMeshChemicals(void) 
{

  vector<double> clean_chem(Cell::NChem());

  for (int i=0;i<Cell::NChem();i++) {
    clean_chem[i]=par.initval[i];
  }

  mesh.CleanChemicals(clean_chem);
  mesh.setTime(0);
  Plot();

  editor->FullRedraw();
}

void Main::CleanMeshTransporters(void) 
{
  vector<double> clean_transporters(Cell::NChem());
  for (int i=0;i<Cell::NChem();i++) {
    clean_transporters[i]=0.;
  }

  mesh.CleanTransporters(clean_transporters);

  mesh.setTime(0);
  Plot();

  editor->FullRedraw();
}

void Main::RandomizeMesh(void) 
{

  vector<double> max_chem(Cell::NChem());
  vector<double> max_transporters(Cell::NChem());

  for (int i=0;i<Cell::NChem();i++) {
    max_transporters[i]=0.;
    max_chem[i]=par.initval[i];
  }

  // Amount of PIN1 at walls
  max_transporters[1] = 0.01;

  mesh.RandomizeChemicals(max_chem, max_transporters);

  Plot();
}

void Main::XMLReadSettings(xmlNode *settings) 
{

  MainBase::XMLReadSettings(settings);
  
  view->setItemChecked(com_id, showcentersp);
  view->setItemChecked(mesh_id, showmeshp);
  view->setItemChecked(border_id, showbordercellp);
  view->setItemChecked(node_number_id, shownodenumbersp);
  view->setItemChecked(cell_number_id, showcellnumbersp);
  view->setItemChecked(cell_axes_id, showcellsaxesp);
  view->setItemChecked(cell_strain_id, showcellstrainp);
  view->setItemChecked(movie_frames_id, movieframesp);
  view->setItemChecked(only_boundary_id, showboundaryonlyp);
  view->setItemChecked(fluxes_id, showfluxesp);
  view->setItemChecked(hide_cells_id, hidecellsp);
  options->setItemChecked(dyn_cells_id, dynamicscellsp);
  view->setItemChecked( cell_walls_id, showwallsp);
 // view->setItemChecked( apoplasts_id, showapoplastsp);
  
  editor->setTransform(viewport);
}

xmlNode *Main::XMLSettingsTree(void) 
{

  showcentersp = view->isItemChecked(com_id);
  showmeshp = view->isItemChecked(mesh_id);
  showbordercellp =  view->isItemChecked(border_id);
  shownodenumbersp =  view->isItemChecked(node_number_id);
  showcellnumbersp =  view->isItemChecked(cell_number_id);
  showcellsaxesp = view->isItemChecked( cell_axes_id );
  showcellstrainp = view->isItemChecked( cell_strain_id );
  movieframesp = view->isItemChecked(movie_frames_id);;
  showboundaryonlyp =  view->isItemChecked(only_boundary_id);
  showfluxesp = view->isItemChecked(fluxes_id);
  dynamicscellsp = options->isItemChecked(dyn_cells_id);
  showwallsp = view->isItemChecked( cell_walls_id);
  //showapoplastsp = view->isItemChecked( apoplasts_id);
  hidecellsp = view->isItemChecked( hide_cells_id);

  xmlNode *settings = MainBase::XMLSettingsTree();
  QTransform viewport(editor->transform());
  xmlAddChild(settings, XMLViewportTree(viewport));
  return settings;
}

void Main::exportCellData(QString fileName) {
  
#ifdef QDEBUG  
  qDebug() << "exportCellData fileName: " << fileName << endl;
#endif

  QFile file(fileName);
  if ( file.open( IO_WriteOnly ) ) {
    QTextStream stream( &file );
    mesh.CSVExportCellData(stream);
    mesh.CSVExportMeshData(stream);
    file.close();
  }
}


void Main::exportCellData() {
  QString fileName;
  Q3FileDialog *fd = new Q3FileDialog( this, "file dialog", TRUE );

  stopSimulation();
  fd->setMode( Q3FileDialog::AnyFile );
  if ( fd->exec() == QDialog::Accepted ) {
    fileName = fd->selectedFile();
  }
  this->exportCellData(fileName);
}


/* finis */