-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmetaitem.cpp
More file actions
executable file
·2436 lines (2086 loc) · 62.7 KB
/
Copy pathmetaitem.cpp
File metadata and controls
executable file
·2436 lines (2086 loc) · 62.7 KB
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
/****************************************************************************
**
** Copyright (C) 2007-2009 Kevin Clague. All rights reserved.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://www.trolltech.com/products/qt/opensource.html
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
/****************************************************************************
*
* This file describes a class that is used to implement backannotation
* of user Gui input into the LDraw file. Furthermore it implements
* some functions to provide higher level editing capabilities, such
* as adding and removing steps from step groups, adding, moving and
* deleting dividers.
*
* Please see lpub.h for an overall description of how the files in LPub
* make up the LPub program.
*
***************************************************************************/
#include <QFont>
#include <QFontDatabase>
#include <QFontDialog>
#include <QColor>
#include <QColorDialog>
#include <QFile>
#include <QFileInfo>
#include <QDir>
#include <QTextStream>
#include <QFileDialog>
#include <QMessageBox>
#include <QInputDialog>
#include "metaitem.h"
#include "lpub.h"
#include "range.h"
#include "color.h"
#include "placementdialog.h"
#include "pliconstraindialog.h"
#include "pairdialog.h"
#include "scaledialog.h"
#include "borderdialog.h"
#include "backgrounddialog.h"
#include "dividerdialog.h"
#include "paths.h"
#include "render.h"
void MetaItem::setGlobalMeta(
QString &topLevelFile,
LeafMeta *leaf)
{
QString newMeta = leaf->format(false,true);
if (leaf->here().modelName != "undefined") {
replaceMeta(leaf->here(),newMeta);
} else {
Where here = sortedGlobalWhere(topLevelFile,newMeta);
insertMeta(here,newMeta);
}
}
const QString stepGroupBegin = "0 !LPUB MULTI_STEP BEGIN";
const QString stepGroupDivider = "0 !LPUB MULTI_STEP DIVIDER";
const QString stepGroupEnd = "0 !LPUB MULTI_STEP END";
const QString step = "0 STEP";
Rc MetaItem::scanForwardStepGroup(Where &here, bool &partsAdded)
{
return scanForward(here,StepMask|StepGroupMask,partsAdded);
}
Rc MetaItem::scanForwardStepGroup(Where &here)
{
return scanForward(here,StepMask|StepGroupMask);
}
Rc MetaItem::scanBackwardStepGroup(Where &here, bool &partsAdded)
{
return scanBackward(here,StepMask|StepGroupMask,partsAdded);
}
Rc MetaItem::scanBackwardStepGroup(Where &here)
{
return scanBackward(here,StepMask|StepGroupMask);
}
// TOS EOS
// STEP (END) BEGIN PART STEP (DIVIDER) PART STEP END
// STEP (END) xxxxx PART STEP xxxxxxxxx PART STEP xxx
// TOS EOS
// STEP (END) BEGIN PART STEP (DIVIDER) PART STEP PART
// STEP (END) xxxxx PART STEP (BEGIN) PART STEP PART
// TOS EOS
// STEP (END) BEGIN PART STEP (DIVIDER) PART STEP DIVIDER
// STEP (END) xxxxx PART STEP (BEGIN) PART STEP DIVIDER
int MetaItem::removeFirstStep(
const Where &topOfSteps)
{
int sum = 0;
Where secondStep = topOfSteps + 1; // STEP
Rc rc = scanForwardStepGroup(secondStep);
if (rc == StepGroupEndRc) { // (END)
++secondStep;
rc = scanForwardStepGroup(secondStep);
}
if (rc == StepGroupBeginRc) { // BEGIN
Where begin = secondStep++;
rc = scanForwardStepGroup(secondStep);
if (rc == StepRc || rc == RotStepRc) { // STEP
Where thirdStep = secondStep + 1;
rc = scanForwardStepGroup(thirdStep);
Where divider;
if (rc == StepGroupDividerRc) { // (DIVIDER)
divider = thirdStep++;
rc = scanForwardStepGroup(thirdStep);
}
if (rc == StepRc || rc == RotStepRc) { // STEP
++thirdStep;
rc = scanForwardStepGroup(thirdStep);
if (rc == StepGroupEndRc) { // END
// remove this end and then begin
deleteMeta(thirdStep);
if (divider.lineNumber) {
deleteMeta(divider);
}
} else {
if (divider.lineNumber) {
replaceMeta(divider,stepGroupBegin);
} else {
appendMeta(secondStep,stepGroupBegin);
}
}
deleteMeta(begin); --sum;
}
}
}
return sum;
}
void MetaItem::addNextMultiStep(
const Where &topOfSteps,
const Where &bottomOfSteps) // always add at end
{
Rc rc1;
bool firstChange = true;
bool partsAdded;
// TOR BOR
// EOF PART STEP PART EOF
// EOF BEGIN PART STEP PART STEP END
// EOF PART STEP PART STEP
// EOF BEGIN PART STEP PART STEP END
// STEP END PART EOF
// STEP PART STEP END
// STEP END PART STEP
// STEP PART STEP END
Where walk = bottomOfSteps + 1;
Where finalTopOfSteps = topOfSteps;
rc1 = scanForward(walk,StepMask|StepGroupMask,partsAdded);
Where end;
if (rc1 == StepGroupEndRc) { // END
end = walk++;
rc1 = scanForward(walk,StepMask|StepGroupMask,partsAdded);
}
if (rc1 == StepGroupBeginRc) { // BEGIN
firstChange = false;
beginMacro("addNextStep1");
removeFirstStep(bottomOfSteps); // remove BEGIN
partsAdded = false;
rc1 = scanForwardStepGroup(walk,partsAdded);
}
// bottomOfSteps - STEP
// end - StepGroupEnd
// walk - (STEP || EOF)
if (firstChange) {
beginMacro("addNextStep2");
firstChange = false;
}
if (rc1 == EndOfFileRc && partsAdded) {
insertMeta(walk,step);
}
appendMeta(walk,stepGroupEnd);
if (end.lineNumber) {
deleteMeta(end);
} else {
walk = topOfSteps + 1;
rc1 = scanForward(walk,StepMask|StepGroupMask);
if (rc1 == StepGroupEndRc) {
finalTopOfSteps = walk+1;
appendMeta(walk,stepGroupBegin);
} else {
walk = topOfSteps;
scanPastGlobal(walk);
finalTopOfSteps = walk+1;
appendMeta(walk,stepGroupBegin);
}
}
//movePageToEndOfStepGroup(finalTopOfSteps);
endMacro();
}
void MetaItem::movePageToEndOfStepGroup(
const Where &topOfSteps)
{
Where bottomOfSteps, topOfPage, bottomOfPage;
while (1) {
bottomOfSteps = topOfSteps;
// Find bottom of step group
scanForward(bottomOfSteps,StepGroupEndMask);
Meta meta;
// find top of page
topOfPage = bottomOfSteps;
for (topOfPage = bottomOfSteps - 1; topOfPage >= topOfSteps.lineNumber; topOfPage--) {
QString line = gui->readLine(topOfPage);
Rc rc = meta.parse(line,topOfPage);
if (rc == StepGroupBeginRc) {
return;
}
if (rc == InsertPageRc || rc == InsertCoverPageRc) {
break;
}
}
// find bottom of page
for (bottomOfPage = topOfPage + 1; bottomOfPage < bottomOfSteps.lineNumber; bottomOfPage++) {
QString line = gui->readLine(bottomOfPage);
Rc rc = meta.parse(line,bottomOfPage);
if (rc == StepRc || rc == RotStepRc) {
break;
}
}
Where walk = bottomOfSteps;
// copy page to after step group
for (Where walk2 = topOfPage; walk2 <= bottomOfPage.lineNumber; walk2++) {
QString line = gui->readLine(walk2);
appendMeta(walk++,line);
}
for (Where walk2 = topOfPage; walk2 <= bottomOfPage.lineNumber; walk2++) {
deleteMeta(topOfPage);
}
}
}
// TOS
// BEGIN PART STEP DIVIDER PART STEP END
// xxxxx PART STEP xxxxxxx PART STEP xxx
// TOS
// BEGIN PART STEP PART STEP DIVIDER PART STEP END
// BEGIN PART STEP PART STEP xxxxxxx (END) PART STEP xxx
// TOS
// BEGIN PART STEP PART STEP PART STEP END
// BEGIN PART STEP PART STEP (END) PART STEP xxx
// $$$$$ $$$ $$$$$$$ $$$
int MetaItem::removeLastStep(
const Where &topOfSteps, // STEP
const Where &bottomOfSteps)
{
int sum = 0;
// Find the top of us
Where walk = topOfSteps + 1;
Rc rc = scanForwardStepGroup(walk);
if (rc == StepGroupEndRc) {
++walk;
rc = scanForwardStepGroup(walk);
}
Where begin = walk;
if (rc == StepGroupBeginRc) { // BEGIN
// Find the next step
Where secondStep = walk + 1;
Rc rc = scanForward(secondStep,StepMask);
// find the next next step
if (rc == StepRc || rc == RotStepRc) { // STEP
Where thirdStep = secondStep + 1;
rc = scanForwardStepGroup(thirdStep);
Where divider;
if (rc == StepGroupDividerRc) { // (DIVIDER)
divider = thirdStep;
++thirdStep;
rc = scanForwardStepGroup(thirdStep);
}
//-----------------------------------------------------
Where lastStep = bottomOfSteps - 1;
rc = scanBackward(lastStep,StepMask);
if (rc == StepRc || rc == RotStepRc) { // STEP
walk = lastStep + 1;
rc = scanForward(walk,StepMask|StepGroupMask);
Where divider2;
if (rc == StepGroupDividerRc) { // (DIVIDER)
divider2 = walk++;
rc = scanForwardStepGroup(walk);
}
if (rc == StepRc || rc == RotStepRc) { // STEP
++walk;
rc = scanForwardStepGroup(walk);
if (rc == StepGroupEndRc) { // END
deleteMeta(walk);
--sum;
if (secondStep.lineNumber == lastStep.lineNumber) {
if (divider.lineNumber) {
--sum;
deleteMeta(divider);
}
--sum;
deleteMeta(begin);
} else if (divider2.lineNumber) {
replaceMeta(divider2,stepGroupEnd);
} else {
++sum;
appendMeta(lastStep,stepGroupEnd);
}
}
}
}
}
}
return sum;
}
// TOS
// SOF PART STEP PART (EOF|STEP)
// SOF (BEGIN) PART STEP PART (STEP) (END)
// TOS
// SOF PART STEP PART STEP PART (EOF|STEP)
// SOF PART STEP (BEGIN) PART STEP PART (STEP) (END)
// TOS
// BEGIN PART STEP PART STEP END PART (EOF|STEP)
// xxxxx PART STEP (BEGIN) PART STEP xxx PART (STEP) (END)
// TOS
// BEGIN PART STEP DIVIDER PART STEP END PART (EOF|STEP)
// xxxxx PART STEP (BEGIN) PART STEP xxx PART (STEP) (END)
// TOS
// BEGIN PART STEP PART STEP DIVIDER PART STEP END PART (EOF|STEP)
// BEGIN PART STEP PART STEP (END) (BEGIN) PART STEP xxx PART (STEP) (END)
// BEGIN PART STEP PART STEP PART STEP END PART (EOF|STEP)
// BEGIN PART STEP PART STEP (END) (BEGIN) PART STEP xxx PART (STEP) (END)
void MetaItem::addPrevMultiStep(
const Where &topOfStepsIn,
const Where &bottomOfStepsIn)
{
Rc rc1;
bool firstChange = true;
bool partsAdded;
Where topOfSteps = topOfStepsIn;
Where bottomOfSteps = bottomOfStepsIn;
Where walk = topOfSteps + 1;
rc1 = scanForward(walk,StepMask|StepGroupMask,partsAdded);
// TOS end begin BOR
// STEP BEGIN PART STEP PART STEP END BEGIN PART STEP PART STEP END
Where begin;
if (rc1 == StepGroupEndRc) { // END
beginMacro("AddPreviousStep");
firstChange = false;
Where prevTopOfSteps = topOfSteps-1;
scanBackward(prevTopOfSteps,StepGroupBeginMask);
--prevTopOfSteps;
scanBackward(prevTopOfSteps,StepMask);
int removed = removeLastStep(prevTopOfSteps,topOfSteps); // shift by removal count
topOfSteps.lineNumber += removed + 1;
bottomOfSteps.lineNumber += removed;
walk = topOfSteps + 1; // skip past
rc1 = scanForwardStepGroup(walk, partsAdded);
}
// if I'm the first step of an existing step group
if (rc1 == StepGroupBeginRc) { // BEGIN
begin = walk++; // remember
rc1 = scanForward(walk,StepMask,partsAdded); // next?
}
// PREV TOS begin BOR
// STEP PART STEP END PART STEP BEGIN PART STEP PART STEP END
// STEP PART STEP END BEGIN PART STEP PART STEP PART STEP END
if (firstChange) {
beginMacro("AddPreviousStep2");
firstChange = false;
}
// Handle end of step/group
if (rc1 == EndOfFileRc && partsAdded) {
insertMeta(walk,step);
}
if (begin.lineNumber == 0) {
appendMeta(walk,stepGroupEnd);
}
Where prevStep = topOfSteps - 1;
scanBackward(prevStep,StepMask);
if (begin.lineNumber) {
deleteMeta(begin);
Where end = prevStep+1;
rc1 = scanForwardStepGroup(end);
prevStep.lineNumber += rc1 == StepGroupEndRc;
}
appendMeta(prevStep,stepGroupBegin);
++prevStep;
movePageToBeginOfStepGroup(prevStep);
// gui->displayPageNum--;
endMacro();
}
void MetaItem::movePageToBeginOfStepGroup(
const Where &topOfStepsIn)
{
Where topOfSteps, bottomOfSteps, topOfPage, bottomOfPage;
topOfSteps = topOfStepsIn;
while (1) {
bottomOfSteps = topOfSteps;
// Find bottom of step group
scanForward(bottomOfSteps,StepGroupEndMask);
Meta meta;
// find top of page
for (topOfPage = topOfSteps + 1; topOfPage <= bottomOfSteps.lineNumber; topOfPage++) {
QString line = gui->readLine(topOfPage);
Rc rc = meta.parse(line,topOfPage);
if (rc == StepGroupEndRc) {
return;
}
if (rc == InsertPageRc || rc == InsertCoverPageRc) {
break;
}
}
// find bottom of page
for (bottomOfPage = topOfPage + 1; bottomOfPage < bottomOfSteps.lineNumber; bottomOfPage++) {
QString line = gui->readLine(bottomOfPage);
Rc rc = meta.parse(line,bottomOfPage);
if (rc == StepRc || rc == RotStepRc) {
break;
}
}
Where walk = bottomOfSteps;
// copy page to before step group
for (Where walk2 = topOfPage; walk2 <= bottomOfPage.lineNumber; walk2.lineNumber += 2) {
QString line = gui->readLine(walk2);
insertMeta(topOfSteps,line);
++topOfSteps;
++bottomOfSteps;
++topOfPage;
++bottomOfPage;
}
for (Where walk2 = topOfPage; walk2 <= bottomOfPage.lineNumber; walk2++) {
deleteMeta(topOfPage);
}
}
}
void MetaItem::deleteFirstMultiStep(
const Where &topOfSteps)
{
beginMacro("removeFirstStep");
removeFirstStep(topOfSteps);
endMacro();
}
void MetaItem::deleteLastMultiStep(
const Where &topOfSteps,
const Where &bottomOfSteps)
{
beginMacro("deleteLastMultiStep");
removeLastStep(topOfSteps,bottomOfSteps);
endMacro();
}
void MetaItem::addDivider(
PlacementType parentRelativeType,
const Where &bottomOfStep,
RcMeta *divider)
{
Where walk = bottomOfStep;
Rc rc;
QString divString = divider->preamble;
int mask = parentRelativeType == StepGroupType ? StepMask|StepGroupMask : StepMask|CalloutMask;
rc = scanForward(walk, mask);
if (rc == StepRc || rc == RotStepRc) {
// we can add a divider after meta->context.curStep().lineNumber
appendMeta(bottomOfStep,divString);
}
}
void MetaItem::deleteDivider(
PlacementType parentRelativeType,
const Where ÷rIn)
{
Where divider = dividerIn;
if (divider.modelName != "undefined") {
Rc rc;
int mask = parentRelativeType == StepGroupType ? StepMask|StepGroupMask : StepMask|CalloutMask;
Rc expRc = parentRelativeType == StepGroupType ? StepGroupDividerRc : CalloutDividerRc;
++divider;
rc = scanForward(divider,mask);
if (rc == expRc) {
beginMacro("deleteDivider");
deleteMeta(divider);
endMacro();
}
}
}
/***********************************************************************
*
* These "short-cuts" move steps to the other side of a divider
*
**********************************************************************/
const QString calloutDivider = "0 !LPUB CALLOUT DIVIDER";
void MetaItem::addToNext(
PlacementType parentRelativeType,
const Where &topOfStep)
{
if (parentRelativeType == CalloutType) {
calloutAddToNext(topOfStep);
} else {
stepGroupAddToNext(topOfStep);
}
}
void MetaItem::calloutAddToNext(
const Where &topOfStep)
{
Where walk = topOfStep + 1;
Rc rc = scanForward(walk,StepMask);
if (rc == StepRc || rc == RotStepRc) {
++walk;
rc = scanForward(walk,StepMask|CalloutMask);
if (rc == CalloutDividerRc) {
Where test = topOfStep - 1;
Rc rc2 = scanBackward(test,StepMask|CalloutMask);
beginMacro("moveStepPrev");
deleteMeta(walk);
if (rc != EndOfFileRc && rc2 != CalloutDividerRc && rc2 != EndOfFileRc) {
appendMeta(topOfStep,calloutDivider);
}
endMacro();
}
}
}
void MetaItem::stepGroupAddToNext(
const Where &topOfStep)
{
Where walk = topOfStep + 1;
Rc rc = scanForward(walk,StepMask|StepGroupMask);
Where divider;
if (rc == StepGroupBeginRc || rc == StepGroupDividerRc) {
divider = walk++;
rc = scanForward(walk,StepMask|StepGroupMask);
}
if (rc == StepRc || rc == RotStepRc) {
++walk;
rc = scanForward(walk,StepMask|StepGroupMask);
if (rc == StepGroupDividerRc) {
beginMacro("moveStepPrev");
deleteMeta(walk);
if (divider.lineNumber == 0) {
appendMeta(topOfStep,stepGroupDivider);
}
endMacro();
}
}
}
void MetaItem::addToPrev(
PlacementType parentRelativeType,
const Where &topOfStep)
{
if (parentRelativeType == CalloutType) {
calloutAddToPrev(topOfStep);
} else {
stepGroupAddToPrev(topOfStep);
}
}
void MetaItem::calloutAddToPrev(
const Where &topOfStep)
{
Where walk = topOfStep + 1;
Rc rc;
// 1 2 3*
// TOS PART STEP PART STEP DIVIDER PART EOF
// TOS PART STEP PART STEP PART EOF
// 1 2 3
// SOF PART STEP DIVIDER PART STEP PART EOF
// SOF PART STEP PART STEP DIVIDER PART EOF
rc = scanForward(walk,StepMask|CalloutMask);
if (rc == CalloutDividerRc) {
Where divider = walk++;
rc = scanForward(walk,StepMask|CalloutMask);
if (rc == StepRc || RotStepRc) {
Where lastStep = walk;
++walk;
rc = scanForward(walk,StepMask|CalloutMask);
beginMacro("moveStepNext");
if (rc != EndOfFileRc && rc != CalloutDividerRc) {
appendMeta(lastStep,calloutDivider);
}
deleteMeta(divider);
endMacro();
}
}
}
void MetaItem::stepGroupAddToPrev(
const Where &topOfStep)
{
// 1 2 3*
// TOS PART STEP PART STEP DIVIDER PART EOF
// TOS PART STEP PART STEP PART EOF
// 1 2 3
// SOF PART STEP DIVIDER PART STEP PART EOF
// SOF PART STEP PART STEP DIVIDER PART EOF
Where walk = topOfStep + 1; // STEP
Rc rc = scanForward(walk,StepMask|StepGroupMask);
if (rc == StepGroupDividerRc) { // DIVIDER
Where divider = walk++;
rc = scanForward(walk,StepMask|StepGroupMask);
if (rc == StepRc || rc == RotStepRc) { // STEP
Where nextStep = walk++;
rc = scanForward(walk,StepMask|StepGroupMask);
beginMacro("moveStepNext");
if (rc != StepGroupEndRc && rc != StepGroupDividerRc) {
appendMeta(nextStep,stepGroupDivider);
}
deleteMeta(divider);
endMacro();
}
}
}
void MetaItem::convertToIgnore(Meta *meta)
{
gui->maxPages = -1;
SubmodelStack tos = meta->submodelStack[meta->submodelStack.size() - 1];
Where calledOut(tos.modelName,tos.lineNumber);
Where here = calledOut+1;
beginMacro("ignoreSubmodel");
insertMeta(here, "0 !LPUB PART END");
insertMeta(calledOut, "0 !LPUB PART BEGIN IGN");
endMacro();
}
void MetaItem::convertToPart(Meta *meta)
{
gui->maxPages = -1;
SubmodelStack tos = meta->submodelStack[meta->submodelStack.size() - 1];
Where calledOut(tos.modelName,tos.lineNumber);
Where here = calledOut+1;
QString line = gui->readLine(calledOut);
QStringList tokens;
split(line,tokens);
if (tokens.size() == 15) {
beginMacro("submodelIsPart");
insertMeta(here, "0 !LPUB PART END");
insertMeta(here, "0 !LPUB PLI END");
insertMeta(calledOut, "0 !LPUB PART BEGIN IGN");
insertMeta(calledOut, "0 !LPUB PLI BEGIN SUB " + tokens[14] + " " + tokens[1]);
endMacro();
}
}
/*******************************************************************************
*
*
******************************************************************************/
void MetaItem::setMeta(
const Where &topOf,
const Where &bottomOf,
LeafMeta *meta,
bool useTop,
int append,
bool local,
bool askLocal,
bool global)
{
if (useTop) {
setMetaTopOf(topOf,bottomOf,meta,append,local,askLocal,global);
} else {
setMetaBottomOf(topOf,bottomOf,meta,append,local,askLocal,global);
}
}
void MetaItem::setMetaTopOf(
const Where &topOf,
const Where &bottomOf,
LeafMeta *meta,
int append,
bool local,
bool askLocal,
bool global)
{
int lineNumber = meta->here().lineNumber;
bool metaInRange;
QString modelName = meta->here().modelName;
metaInRange = meta->here().modelName == topOf.modelName;
metaInRange = metaInRange
&& lineNumber >= topOf.lineNumber
&& lineNumber <= bottomOf.lineNumber;
if (metaInRange) {
QString line = meta->format(meta->pushed,meta->global);
replaceMeta(meta->here(),line);
} else {
if (askLocal) {
local = LocalDialog::getLocal(LPUB, "Change only this step?",gui);
}
QString line = meta->format(local,global);
Where topOfFile = topOf;
if (topOf.lineNumber == 0) {
QString line = gui->readLine(topOf);
QStringList argv;
split(line,argv);
if (argv.size() >= 1 && argv[0] != "0") {
insertMeta(topOf,"0");
}
} else {
Where walk = topOf+1;
Rc rc = scanForward(walk,StepMask|StepGroupMask);
if (rc == StepGroupEndRc) {
topOfFile = walk++;
rc = scanForward(walk,StepMask|StepGroupMask);
}
if (rc == StepGroupBeginRc) {
topOfFile = walk;
}
}
topOfFile.lineNumber += append;
insertMeta(topOfFile, line);
}
}
void MetaItem::setMetaBottomOf(
const Where &topOf,
const Where &bottomOf,
LeafMeta *meta,
int append,
bool local,
bool askLocal,
bool global)
{
int lineNumber = meta->here().lineNumber;
bool metaInRange;
metaInRange = meta->here().modelName == topOf.modelName
&& lineNumber >= topOf.lineNumber
&& lineNumber <= bottomOf.lineNumber;
if (metaInRange) {
QString line = meta->format(meta->pushed,meta->global);
replaceMeta(meta->here(),line);
} else {
if (askLocal) {
local = LocalDialog::getLocal(LPUB, "Change only this step?",gui);
}
QString line = meta->format(local, global);
int numLines = gui->subFileSize(topOf.modelName);
bool eof = bottomOf.lineNumber + 1 == numLines;
if (eof) {
QString tline = gui->readLine(bottomOf);
QStringList argv;
split(tline,argv);
if (argv.size() >= 2 && argv[0] == "0" && (argv[1] == "STEP" || argv[1] == "ROTSTEP")) {
insertMeta(bottomOf,line);
} else {
if (append) {
appendMeta(bottomOf,line);
} else {
insertMeta(bottomOf,line);
}
}
} else if (append) {
appendMeta(bottomOf,line);
} else {
insertMeta(bottomOf,line);
}
}
}
void MetaItem::changePlacement(
PlacementType parentType,
PlacementType relativeType,
QString title,
const Where &topOfSteps,
const Where &bottomOfSteps,
PlacementMeta *placement,
bool useTop,
int append,
bool local,
bool useLocal)
{
PlacementData placementData = placement->value();
bool ok;
ok = PlacementDialog
::getPlacement(parentType,relativeType,placementData,title);
if (ok) {
placement->setValue(placementData);
setMeta(topOfSteps,bottomOfSteps,placement,useTop,append,local,useLocal);
}
}
void MetaItem::changePlacement(
PlacementType parentType,
bool pliPerStep,
PlacementType relativeType,
QString title,
const Where &topOfSteps,
const Where &bottomOfSteps,
PlacementMeta *placement,
bool useTop,
int append,
bool local,
bool useLocal)
{
PlacementData placementData = placement->value();
bool ok;
ok = PlacementDialog
::getPlacement(parentType,relativeType,placementData,title,NULL,pliPerStep);
if (ok) {
placement->setValue(placementData);
setMeta(topOfSteps,bottomOfSteps,placement,useTop,append,local,useLocal);
}
}
void MetaItem::changePlacementOffset(
Where defaultWhere,
PlacementMeta *placement,
PlacementType type,
bool /* unused */,
bool local,
bool global)
{
QString newMetaString = placement->format(local,global);
Where walk = defaultWhere + 1;
if (placement->here().modelName == "undefined") {
Where walk = defaultWhere + 1;
bool partsAdded;
if (scanBackward(walk,StepMask,partsAdded) == EndOfFileRc) {
defaultWhere = firstLine(defaultWhere.modelName);
}
if (type == StepGroupType) {
scanForward(defaultWhere,StepGroupBeginMask);
} else if (type == CalloutType) {
scanForward(defaultWhere,CalloutEndMask);
--defaultWhere;
} else if (defaultWhere.modelName == gui->topLevelFile()) {
scanPastGlobal(defaultWhere);
}
appendMeta(defaultWhere,newMetaString);
} else {
replaceMeta(placement->here(),newMetaString);
}
}
void MetaItem::changeConstraint(
Where topOfStep,
Where bottomOfStep,
ConstrainMeta *constraint,
int append,
bool useBot)
{
if (useBot) {
setMetaBottomOf(topOfStep,bottomOfStep,constraint,append,true,false);
} else {
setMetaTopOf(topOfStep,bottomOfStep,constraint,append,true,false);
}
}
void MetaItem::changeConstraintStepGroup(
Where topOfStep,
Where bottomOfStep,
ConstrainMeta *constraint,
int append)
{
setMetaBottomOf(topOfStep,bottomOfStep,constraint,append,true,false);
}
void MetaItem::changeInsertOffset(
InsertMeta *placement)
{
QString newMetaString = placement->format(false,false);
replaceMeta(placement->here(),newMetaString);
}
void MetaItem::changeBackground(
QString title,
const Where &topOfStep,
const Where &bottomOfStep,
BackgroundMeta *background,
bool useTop,
int append,
bool local)
{
BackgroundData backgroundData = background->value();
bool ok;
ok = BackgroundDialog::getBackground(backgroundData,title,gui);
if (ok) {
background->setValue(backgroundData);
setMeta(topOfStep,bottomOfStep,background,useTop,append,local);
}
}
void MetaItem::changeConstraint(
QString title,