forked from DongwanCho/IfcDoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FormMerge.cs
899 lines (781 loc) · 44.5 KB
/
FormMerge.cs
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
// Name: FormMerge.cs
// Description: Dialog box for merging files.
// Author: Tim Chipman
// Origination: Work performed for BuildingSmart by Constructivity.com LLC.
// Copyright: (c) 2012 BuildingSmart International Ltd.
// License: http://www.buildingsmart-tech.org/legal
// Portions of code within this file originated from DifferenceEngine on CodeProject.org (file containing referenced data definitions).
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using IfcDoc.Schema.DOC;
using DifferenceEngine;
namespace IfcDoc
{
public partial class FormMerge : Form
{
bool m_ignore;
Dictionary<Guid, DocObject> m_mapOriginal;
public FormMerge()
{
InitializeComponent();
m_ignore = false;
}
public FormMerge(Dictionary<Guid, DocObject> mapOriginal, DocProject docChange) : this()
{
this.m_mapOriginal = mapOriginal;
// add nodes for everything, then delete ones that haven't changed or don't have any children
// iterate and find changes in documentation
foreach (DocSection docChangeSection in docChange.Sections)
{
DocObject docOriginalSection = null;
if(mapOriginal.TryGetValue(docChangeSection.Uuid, out docOriginalSection))
{
foreach (DocSchema docChangeSchema in docChangeSection.Schemas)
{
DocObject docOriginalSchema;
if (mapOriginal.TryGetValue(docChangeSchema.Uuid, out docOriginalSchema))
{
// compare schemas
TreeNode tnSchema = this.AddNode(null, new ChangeInfo(docOriginalSchema.Name, docOriginalSchema, docChangeSchema));
foreach (DocType docChangeType in docChangeSchema.Types)
{
DocObject docOriginalType = null;
if (mapOriginal.TryGetValue(docChangeType.Uuid, out docOriginalType))
{
TreeNode tnType = null;
if (!String.Equals(docOriginalType.Documentation, docChangeType.Documentation))
{
tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name, docOriginalType, docChangeType));
}
if (docChangeType is DocEnumeration)
{
DocEnumeration docChangeEnum = (DocEnumeration)docChangeType;
foreach (DocConstant docChangeConst in docChangeEnum.Constants)
{
DocObject docOriginalConst = null;
if (mapOriginal.TryGetValue(docChangeConst.Uuid, out docOriginalConst))
{
if (!String.Equals(docOriginalConst.Documentation, docChangeConst.Documentation))
{
if (tnType == null)
{
tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name, docOriginalType, docChangeType));
}
this.AddNode(tnType, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name + "." + docOriginalConst.Name, docOriginalConst, docChangeConst));
}
}
else
{
if (tnType == null)
{
tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name, docOriginalType, docChangeType));
}
// NEW:
this.AddNode(tnType, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalType.Name + "." + docOriginalConst.Name, null, docChangeConst));
}
}
}
}
}
foreach (DocEntity docChangeEntity in docChangeSchema.Entities)
{
DocObject docOriginalObj = null;
if (mapOriginal.TryGetValue(docChangeEntity.Uuid, out docOriginalObj))
{
DocEntity docOriginalEntity = (DocEntity)docOriginalObj;
TreeNode tnEntity = null;
if(!String.Equals(docOriginalEntity.Documentation, docChangeEntity.Documentation))
{
tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity));
}
// add attributes
foreach (DocAttribute docChangeAttr in docChangeEntity.Attributes)
{
DocObject docOriginalAttr = null;
if (mapOriginal.TryGetValue(docChangeAttr.Uuid, out docOriginalAttr))
{
if (!String.Equals(docOriginalAttr.Name, docChangeAttr.Name) ||
!String.Equals(docOriginalAttr.Documentation, docChangeAttr.Documentation))
{
if(tnEntity == null)
{
tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity));
}
this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalAttr.Name, docOriginalAttr, docChangeAttr));
}
}
else
{
if (tnEntity == null)
{
tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity));
}
// new attribute
this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docChangeAttr.Name, null, docChangeAttr));
}
}
// remove attributes
foreach (DocAttribute docOriginalAttr in docOriginalEntity.Attributes)
{
bool bFound = false;
foreach(DocAttribute docChangeAttr in docChangeEntity.Attributes)
{
if (docOriginalAttr.Uuid.Equals(docChangeAttr.Uuid))
{
bFound = true;
break;
}
}
if(!bFound)
{
if (tnEntity == null)
{
tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity));
}
// delete attribute
this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalAttr.Name, docOriginalAttr, null));
}
}
foreach (DocWhereRule docChangeWhere in docChangeEntity.WhereRules)
{
DocObject docOriginalWhere = null;
if (mapOriginal.TryGetValue(docChangeWhere.Uuid, out docOriginalWhere))
{
DocWhereRule docOriginalWhereRule = (DocWhereRule)docOriginalWhere;
if (!String.Equals(docOriginalWhere.Name, docChangeWhere.Name) ||
!String.Equals(docOriginalWhere.Documentation, docChangeWhere.Documentation) ||
!String.Equals(docOriginalWhereRule.Expression, docChangeWhere.Expression))
{
if (tnEntity == null)
{
tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity));
}
this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalWhere.Name, docOriginalWhere, docChangeWhere));
}
}
else
{
if (tnEntity == null)
{
tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity));
}
// new where rule
this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docChangeWhere.Name, null, docChangeWhere));
}
}
foreach (DocUniqueRule docChangeAttr in docChangeEntity.UniqueRules)
{
DocObject docOriginalAttr = null;
if (mapOriginal.TryGetValue(docChangeAttr.Uuid, out docOriginalAttr))
{
if (!String.Equals(docOriginalAttr.Documentation, docChangeAttr.Documentation))
{
if (tnEntity == null)
{
tnEntity = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name, docOriginalEntity, docChangeEntity));
}
this.AddNode(tnEntity, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalEntity.Name + "." + docOriginalAttr.Name, docOriginalAttr, docChangeAttr));
}
}
}
}
}
foreach (DocFunction docChangeFunction in docChangeSchema.Functions)
{
DocObject docOriginalFunc = null;
if (mapOriginal.TryGetValue(docChangeFunction.Uuid, out docOriginalFunc))
{
TreeNode tnType = null;
DocFunction docOriginalFunction = (DocFunction)docOriginalFunc;
if (!String.Equals(docOriginalFunction.Name, docChangeFunction.Name) ||
!String.Equals(docOriginalFunction.Documentation, docChangeFunction.Documentation) ||
!String.Equals(docOriginalFunction.Expression, docChangeFunction.Expression))
{
tnType = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalFunction.Name, docOriginalFunction, docChangeFunction));
}
}
else
{
// new attribute
this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docChangeFunction.Name, null, docChangeFunction));
}
}
foreach (DocPropertySet docChangePset in docChangeSchema.PropertySets)
{
DocObject docOriginalPset = null;
if (mapOriginal.TryGetValue(docChangePset.Uuid, out docOriginalPset))
{
TreeNode tnPset = null;
if (!String.Equals(docOriginalPset.Documentation, docChangePset.Documentation))
{
tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
}
foreach (DocProperty docChangeProp in docChangePset.Properties)
{
DocObject docOriginalProp = ((DocPropertySet)docOriginalPset).GetProperty(docChangeProp.Name);
if (docOriginalProp != null)
{
TreeNode tnProperty = null;
if (!String.Equals(docOriginalProp.Documentation, docChangeProp.Documentation))
{
if (tnPset == null)
{
tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
}
tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp));
}
// localization
foreach (DocLocalization docChangeLocal in docChangeProp.Localization)
{
DocLocalization docOriginalLocal = docOriginalProp.GetLocalization(docChangeLocal.Locale);
if (docOriginalLocal != null)
{
if(!String.Equals(docOriginalLocal.Documentation, docChangeLocal.Documentation))
{
if (tnPset == null)
{
tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
}
if (tnProperty == null)
{
tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp));
}
this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal));
}
}
else
{
if (tnPset == null)
{
tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
}
if (tnProperty == null)
{
tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp));
}
// new localization
this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal));
}
}
}
else
{
if (tnPset == null)
{
tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
}
// NEW:
this.AddNode(tnPset, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name + "." + docChangeProp.Name, null, docChangeProp));
}
}
}
else
{
// NEW:
this.AddNode(tnSchema, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name, null, docChangePset));
}
}
foreach (DocPropertyEnumeration docChangePset in docChangeSchema.PropertyEnums)
{
DocObject docOriginalPset = null;
if (mapOriginal.TryGetValue(docChangePset.Uuid, out docOriginalPset))
{
TreeNode tnPset = null;
if (!String.Equals(docOriginalPset.Documentation, docChangePset.Documentation))
{
tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
}
foreach (DocPropertyConstant docChangeProp in docChangePset.Constants)
{
DocObject docOriginalProp = ((DocPropertyEnumeration)docOriginalPset).GetConstant(docChangeProp.Name);
if (docOriginalProp != null)
{
TreeNode tnProperty = null;
if (!String.Equals(docOriginalProp.Documentation, docChangeProp.Documentation))
{
if (tnPset == null)
{
tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
}
tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp));
}
// localization
foreach (DocLocalization docChangeLocal in docChangeProp.Localization)
{
DocLocalization docOriginalLocal = docOriginalProp.GetLocalization(docChangeLocal.Locale);
if (docOriginalLocal != null)
{
if (!String.Equals(docOriginalLocal.Documentation, docChangeLocal.Documentation))
{
if (tnPset == null)
{
tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
}
if (tnProperty == null)
{
tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp));
}
this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal));
}
}
else
{
if (tnPset == null)
{
tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
}
if (tnProperty == null)
{
tnProperty = this.AddNode(tnPset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp));
}
// new localization
this.AddNode(tnProperty, new ChangeInfo(docChangeLocal.Locale, docOriginalLocal, docChangeLocal));
}
}
}
else
{
if (tnPset == null)
{
tnPset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
}
// NEW:
this.AddNode(tnPset, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name + "." + docChangeProp.Name, null, docChangeProp));
}
}
}
else
{
// NEW:
this.AddNode(tnSchema, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name, null, docChangePset));
}
}
foreach (DocQuantitySet docChangePset in docChangeSchema.QuantitySets)
{
DocObject docOriginalPset = null;
if (mapOriginal.TryGetValue(docChangePset.Uuid, out docOriginalPset))
{
TreeNode tnQset = null;
if (!String.Equals(docOriginalPset.Documentation, docChangePset.Documentation))
{
tnQset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
}
foreach (DocQuantity docChangeProp in docChangePset.Quantities)
{
DocObject docOriginalProp = ((DocQuantitySet)docOriginalPset).GetQuantity(docChangeProp.Name);
if (docOriginalProp != null)
{
if (!String.Equals(docOriginalProp.Documentation, docChangeProp.Documentation))
{
if (tnQset == null)
{
tnQset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
}
this.AddNode(tnQset, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name + "." + docOriginalProp.Name, docOriginalProp, docChangeProp));
}
}
else
{
if (tnQset == null)
{
tnQset = this.AddNode(tnSchema, new ChangeInfo(docOriginalSchema.Name + "." + docOriginalPset.Name, docOriginalPset, docChangePset));
}
// NEW:
this.AddNode(tnQset, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name + "." + docChangeProp.Name, null, docChangeProp));
}
}
}
else
{
// NEW:
this.AddNode(tnSchema, new ChangeInfo(docChangeSchema.Name + "." + docChangePset.Name, null, docChangePset));
}
}
}
}
}
}
if (this.treeView.Nodes.Count > 0)
{
this.treeView.SelectedNode = this.treeView.Nodes[0];
}
}
private void SaveNode(TreeNode tn)
{
ChangeInfo info = (ChangeInfo)tn.Tag;
if (tn.Checked)
{
if (info.Original == null)
{
// add new item
if (info.Change is DocLocalization)
{
DocLocalization localChange = (DocLocalization)info.Change;
ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
DocObject docObj = (DocObject)parentinfo.Original;
docObj.RegisterLocalization(localChange.Locale, localChange.Name, localChange.Documentation);
}
else if(info.Change is DocAttribute)
{
DocAttribute localAttr = (DocAttribute)info.Change;
ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
DocEntity docEntity = (DocEntity)parentinfo.Original;
DocAttribute docAttr = (DocAttribute)localAttr.Clone();
docEntity.Attributes.Add(docAttr);
}
else if(info.Change is DocWhereRule)
{
DocWhereRule localAttr = (DocWhereRule)info.Change;
ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
DocEntity docEntity = (DocEntity)parentinfo.Original;
DocWhereRule docAttr = (DocWhereRule)localAttr.Clone();
docEntity.WhereRules.Add(docAttr);
}
else if(info.Change is DocFunction)
{
DocFunction localAttr = (DocFunction)info.Change;
ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
DocSchema docSchema = (DocSchema)parentinfo.Original;
DocFunction docAttr = (DocFunction)localAttr.Clone();
docSchema.Functions.Add(docAttr);
}
else if(info.Change is DocConstant)
{
this.ToString();
}
else if(info.Change is DocProperty)
{
this.ToString();
DocProperty localProp = (DocProperty)info.Change;
ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
DocPropertySet docPset = (DocPropertySet)parentinfo.Original;
DocProperty docProperty = (DocProperty)localProp.Clone();
docPset.Properties.Add(docProperty);
}
else if(info.Change is DocPropertyConstant)
{
this.ToString();
DocPropertyConstant localProp = (DocPropertyConstant)info.Change;
ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
DocPropertyEnumeration docPset = (DocPropertyEnumeration)parentinfo.Original;
DocPropertyEnumeration docEnumChange = (DocPropertyEnumeration)parentinfo.Change;
int index = docEnumChange.Constants.IndexOf(localProp);
DocPropertyConstant docProperty = (DocPropertyConstant)localProp.Clone();
docPset.Constants.Insert(index, docProperty);
}
else
{
this.ToString();
}
}
else if(info.Change == null)
{
// removal of definition
if (info.Original is DocAttribute)
{
DocAttribute docAttr = (DocAttribute)info.Original;
ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
DocEntity docEntity = (DocEntity)parentinfo.Original;
docEntity.Attributes.Remove(docAttr);
docAttr.Delete();
}
else
{
this.ToString();
}
}
else
{
// change of documentation
info.Original.Name = info.Change.Name;
info.Original.Documentation = info.Change.Documentation;
if (info.Original is DocWhereRule)
{
DocWhereRule whereOriginal = (DocWhereRule)info.Original;
DocWhereRule whereChange = (DocWhereRule)info.Change;
whereOriginal.Expression = whereChange.Expression;
}
else if(info.Original is DocFunction)
{
DocFunction whereOriginal = (DocFunction)info.Original;
DocFunction whereChange = (DocFunction)info.Change;
whereOriginal.Expression = whereChange.Expression;
}
}
}
foreach (TreeNode tnSub in tn.Nodes)
{
SaveNode(tnSub);
}
}
protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
if (this.DialogResult == System.Windows.Forms.DialogResult.OK)
{
foreach (TreeNode tn in this.treeView.Nodes)
{
SaveNode(tn);
}
}
}
private void radioButtonOriginal_Click(object sender, EventArgs e)
{
this.treeView.SelectedNode.Checked = false;
}
private void radioButtonChange_Click(object sender, EventArgs e)
{
this.treeView.SelectedNode.Checked = true;
}
private void UpdateNode(TreeNode tn)
{
ChangeInfo changeinfo = (ChangeInfo)tn.Tag;
if (changeinfo.Change != null)
{
tn.Text = changeinfo.Change.Name;
}
else if(changeinfo.Original != null)
{
tn.Text = changeinfo.Original.Name;
}
// back color indicates change type
if (changeinfo.Original == null)
{
// addition
tn.BackColor = Color.Lime;
}
else if (changeinfo.Change == null)
{
// deletion
tn.BackColor = Color.Red;
}
else if (changeinfo.Original.Documentation != changeinfo.Change.Documentation ||
(changeinfo.Original.Documentation != null && !changeinfo.Original.Documentation.Equals(changeinfo.Change.Documentation)))
{
// update
tn.BackColor = Color.Yellow;
}
else
{
tn.BackColor = Color.Empty;
}
// checkbox indicates accept or reject
//tn.Checked = changeinfo.Accept;
}
private TreeNode AddNode(TreeNode tnParent, ChangeInfo changeinfo)
{
TreeNode tn = new TreeNode();
tn.Tag = changeinfo;
UpdateNode(tn);
if (tnParent != null)
{
tnParent.Nodes.Add(tn);
}
else
{
this.treeView.Nodes.Add(tn);
}
return tn;
}
private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
{
this.lvSource.Items.Clear();
this.lvDestination.Items.Clear();
ChangeInfo info = (ChangeInfo)this.treeView.SelectedNode.Tag;
DiffList_TextString source = new DiffList_TextString(info.Original != null ? info.Original.Documentation : String.Empty);
DiffList_TextString destination = new DiffList_TextString(info.Change != null ? info.Change.Documentation : String.Empty);
DiffEngine de = new DiffEngine();
de.ProcessDiff(source, destination, DiffEngineLevel.SlowPerfect);
ArrayList DiffLines = de.DiffReport();
ListViewItem lviS;
ListViewItem lviD;
int cnt = 1;
int i;
foreach (DiffResultSpan drs in DiffLines)
{
switch (drs.Status)
{
case DiffResultSpanStatus.DeleteSource:
for (i = 0; i < drs.Length; i++)
{
lviS = new ListViewItem(cnt.ToString("00000"));
lviD = new ListViewItem(cnt.ToString("00000"));
lviS.BackColor = Color.Red;
lviS.SubItems.Add(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line);
lviD.BackColor = Color.LightGray;
lviD.SubItems.Add("");
lvSource.Items.Add(lviS);
lvDestination.Items.Add(lviD);
cnt++;
}
break;
case DiffResultSpanStatus.NoChange:
for (i = 0; i < drs.Length; i++)
{
lviS = new ListViewItem(cnt.ToString("00000"));
lviD = new ListViewItem(cnt.ToString("00000"));
lviS.BackColor = Color.White;
lviS.SubItems.Add(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line);
lviD.BackColor = Color.White;
lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line);
lvSource.Items.Add(lviS);
lvDestination.Items.Add(lviD);
cnt++;
}
break;
case DiffResultSpanStatus.AddDestination:
for (i = 0; i < drs.Length; i++)
{
lviS = new ListViewItem(cnt.ToString("00000"));
lviD = new ListViewItem(cnt.ToString("00000"));
lviS.BackColor = Color.LightGray;
lviS.SubItems.Add("");
lviD.BackColor = Color.LightGreen;
lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line);
lvSource.Items.Add(lviS);
lvDestination.Items.Add(lviD);
cnt++;
}
break;
case DiffResultSpanStatus.Replace:
for (i = 0; i < drs.Length; i++)
{
lviS = new ListViewItem(cnt.ToString("00000"));
lviD = new ListViewItem(cnt.ToString("00000"));
lviS.BackColor = Color.Red;
lviS.SubItems.Add(((TextLine)source.GetByIndex(drs.SourceIndex + i)).Line);
lviD.BackColor = Color.LightGreen;
lviD.SubItems.Add(((TextLine)destination.GetByIndex(drs.DestIndex + i)).Line);
lvSource.Items.Add(lviS);
lvDestination.Items.Add(lviD);
cnt++;
}
break;
}
}
this.radioButtonOriginal.Checked = !this.treeView.SelectedNode.Checked;
this.radioButtonChange.Checked = this.treeView.SelectedNode.Checked;
}
private void treeView_AfterCheck(object sender, TreeViewEventArgs e)
{
if (m_ignore)
return;
m_ignore = true;
this.radioButtonOriginal.Checked = !this.treeView.SelectedNode.Checked;
this.radioButtonChange.Checked = this.treeView.SelectedNode.Checked;
CheckNode(e.Node, e.Node.Checked);
m_ignore = false;
}
/// <summary>
/// Recurses through all tree nodes setting check state
/// </summary>
/// <param name="tn"></param>
private void CheckNode(TreeNode tn, bool state)
{
tn.Checked = state;
foreach (TreeNode tnSub in tn.Nodes)
{
CheckNode(tnSub, state);
}
}
private void lvSource_SelectedIndexChanged(object sender, EventArgs e)
{
if (lvSource.SelectedItems.Count > 0)
{
ListViewItem lvi = lvDestination.Items[lvSource.SelectedItems[0].Index];
lvi.Selected = true;
lvi.EnsureVisible();
}
}
private void lvDestination_SelectedIndexChanged(object sender, EventArgs e)
{
if (lvDestination.SelectedItems.Count > 0)
{
ListViewItem lvi = lvSource.Items[lvDestination.SelectedItems[0].Index];
lvi.Selected = true;
lvi.EnsureVisible();
}
}
private void lvSource_Resize(object sender, EventArgs e)
{
if (lvSource.Width > 100)
{
lvSource.Columns[1].Width = -2;
}
}
private void lvDestination_Resize(object sender, EventArgs e)
{
if (lvDestination.Width > 100)
{
lvDestination.Columns[1].Width = -2;
}
}
}
public class ChangeInfo
{
string m_caption;
IDocumentation m_original;
IDocumentation m_change;
bool m_accept;
public ChangeInfo(string caption, IDocumentation docOriginal, IDocumentation docChange)
{
m_caption = caption;
m_original = docOriginal;
m_change = docChange;
m_accept = false;
}
public override string ToString()
{
string action = ": ";
if (m_original == null)
{
action = "+ ";
}
else if (m_change == null)
{
action = "- ";
}
if (m_accept)
{
return action + m_caption + " [ACCEPT]";
}
else
{
return action + m_caption;
}
}
public IDocumentation Original
{
get
{
return m_original;
}
}
public IDocumentation Change
{
get
{
return m_change;
}
}
/*
public bool Accept
{
get
{
return this.m_accept;
}
set
{
this.m_accept = value;
}
}
*/
}
}