Subversion Repositories DevTools

Rev

Rev 2106 | Rev 2118 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2088 ghuddy 1
using System;
2
using System.Collections;
2104 ghuddy 3
using System.Text;
2088 ghuddy 4
using System.ComponentModel;
5
using System.Windows.Forms;
6
 
7
namespace EA_DocGen
8
{
9
	/// <summary>
10
	/// Summary description for EA_RelationshipMatrix.
11
	/// </summary>
12
	public class EA_RelationshipMatrix
13
	{
2106 ghuddy 14
      private static ArrayList processedElements = null;
2088 ghuddy 15
 
16
      // declare option variables
2106 ghuddy 17
      private static int style = 1;
2088 ghuddy 18
 
2106 ghuddy 19
      private static string fromIntroText = null;     // This one is optional 
20
      private static string fromPackageGUID = null;
21
      private static string fromToTableTitle = null;  // This one is optional
22
      private static string fromColumnTitle = null;
23
      private static ArrayList fromElementTypes = null;
24
      private static bool fromPackageRecursion = true;
25
      private static EA.Package fromPackage = null;
26
      private static bool fromPackageTrimming = false;
2088 ghuddy 27
 
2106 ghuddy 28
      private static string toIntroText = null;       // This one is optional
29
      private static string toPackageGUID = null;
30
      private static string toFromTableTitle = null;  // This one is optional
31
      private static string toColumnTitle = null;
32
      private static ArrayList toElementTypes = null;
33
      private static bool toPackageRecursion = true;
34
      private static EA.Package toPackage = null;
35
      private static bool toPackageTrimming = false;
2104 ghuddy 36
 
2094 ghuddy 37
 
38
 
2106 ghuddy 39
      private static string [] options_string = null;
2088 ghuddy 40
 
41
 
42
 
2106 ghuddy 43
		public static void initialise(ArrayList processedElementsRef)
2088 ghuddy 44
		{
2104 ghuddy 45
         processedElements = processedElementsRef;
46
 
47
         fromElementTypes  = new ArrayList();
48
         toElementTypes    = new ArrayList();
2088 ghuddy 49
		}
50
 
2106 ghuddy 51
      private static void reset()
2088 ghuddy 52
      {
2104 ghuddy 53
         style = 1;
54
 
2088 ghuddy 55
         fromIntroText = null;
56
         fromPackageGUID = null;
57
         fromToTableTitle = null;
58
         fromColumnTitle = null;
59
         fromElementTypes.Clear();
60
         fromPackageRecursion = true;
2094 ghuddy 61
         fromPackageTrimming = false;
2088 ghuddy 62
         fromPackage = null;
63
         toIntroText = null;
64
         toPackageGUID = null;
65
         toFromTableTitle = null;
66
         toColumnTitle = null;
67
         toElementTypes.Clear();
68
         toPackageRecursion = true;
2094 ghuddy 69
         toPackageTrimming = false;
2088 ghuddy 70
         toPackage = null;
71
      }
72
 
73
 
2106 ghuddy 74
      public static bool processRelationshipMatrixOptions(EA.Element theElement)
2088 ghuddy 75
      {
76
         reset();
77
 
78
         // Extract the control options from the notes of the element
79
 
80
         string delimStr = "\n";
81
         char [] delim = delimStr.ToCharArray();
82
         options_string = theElement.Notes.ToString().Split(delim,100);
83
         int i = 0;
84
         foreach(string s in options_string)
85
         {
86
            options_string[i] = s.Trim();
87
            i++;
88
         }
89
 
90
         // scan the options string and assign values into the options variables as required
91
         foreach(string s in options_string)
92
         {
93
            if (s.Length > 0 && s != "\n" && s != "\r" && s[0] != '\\')
94
            {
2104 ghuddy 95
               if (s.StartsWith("style="))
96
               {
2106 ghuddy 97
                  style = EA_DocGenOptions.getOptionValue(s, style);
2104 ghuddy 98
               }
2088 ghuddy 99
               // FROM items
2104 ghuddy 100
               else if (s.StartsWith("fromIntroText="))
2088 ghuddy 101
               {
2106 ghuddy 102
                  fromIntroText = EA_DocGenOptions.getOptionValue(s, null);
2088 ghuddy 103
               }
2104 ghuddy 104
               else if (s.StartsWith("fromToTableTitle=")) 
2088 ghuddy 105
               {
2106 ghuddy 106
                  fromToTableTitle = EA_DocGenOptions.getOptionValue(s, null);
2088 ghuddy 107
               }
2104 ghuddy 108
               else if (s.StartsWith("fromColumnTitle=")) 
2088 ghuddy 109
               {
2106 ghuddy 110
                  fromColumnTitle = EA_DocGenOptions.getOptionValue(s, fromColumnTitle);
2088 ghuddy 111
               }
2104 ghuddy 112
               else if (s.StartsWith("fromPackageRecursion=")) 
2088 ghuddy 113
               {
2106 ghuddy 114
                  fromPackageRecursion = EA_DocGenOptions.getOptionValue(s, fromPackageRecursion);
2088 ghuddy 115
               }
2104 ghuddy 116
               else if (s.StartsWith("fromPackageTrimming="))
2094 ghuddy 117
               {
2106 ghuddy 118
                  fromPackageTrimming = EA_DocGenOptions.getOptionValue(s, fromPackageTrimming);
2094 ghuddy 119
               }
2104 ghuddy 120
               else if (s.StartsWith("fromPackage=")) 
2088 ghuddy 121
               {
2106 ghuddy 122
                  fromPackageGUID = EA_DocGenOptions.getOptionValue(s, fromPackageGUID);
2088 ghuddy 123
               }
2104 ghuddy 124
               else if (s.StartsWith("fromElementType=")) 
2088 ghuddy 125
               {
2106 ghuddy 126
                  string et = EA_DocGenOptions.getOptionValue(s,null);
2088 ghuddy 127
                  if (et != null) 
128
                  {
129
                     fromElementTypes.Add( et );
130
                  }
131
               }
132
 
133
                  // TO items
2104 ghuddy 134
               else if (s.StartsWith("toIntroText="))
2088 ghuddy 135
               {
2106 ghuddy 136
                  toIntroText = EA_DocGenOptions.getOptionValue(s, null);
2088 ghuddy 137
               }
2104 ghuddy 138
               else if (s.StartsWith("toFromTableTitle=")) 
2088 ghuddy 139
               {
2106 ghuddy 140
                  toFromTableTitle = EA_DocGenOptions.getOptionValue(s, null);
2088 ghuddy 141
               }
2104 ghuddy 142
               else if (s.StartsWith("toColumnTitle=")) 
2088 ghuddy 143
               {
2106 ghuddy 144
                  toColumnTitle = EA_DocGenOptions.getOptionValue(s, toColumnTitle);
2088 ghuddy 145
               }
2104 ghuddy 146
               else if (s.StartsWith("toPackageRecursion=")) 
2088 ghuddy 147
               {
2106 ghuddy 148
                  toPackageRecursion = EA_DocGenOptions.getOptionValue(s, toPackageRecursion);
2088 ghuddy 149
               }
2104 ghuddy 150
               else if (s.StartsWith("toPackageTrimming=")) 
2094 ghuddy 151
               {
2106 ghuddy 152
                  toPackageTrimming = EA_DocGenOptions.getOptionValue(s, toPackageTrimming);
2094 ghuddy 153
               }               
2104 ghuddy 154
               else if (s.StartsWith("toPackage=")) 
2088 ghuddy 155
               {
2106 ghuddy 156
                  toPackageGUID = EA_DocGenOptions.getOptionValue(s, toPackageGUID);
2088 ghuddy 157
               }
2104 ghuddy 158
               else if (s.StartsWith("toElementType=")) 
2088 ghuddy 159
               {
2106 ghuddy 160
                  string et = EA_DocGenOptions.getOptionValue(s,null);
2088 ghuddy 161
                  if (et != null) 
162
                  {
163
                     toElementTypes.Add( et );
164
                  }
165
               }
166
            }
167
         }
168
 
169
         // Verify that we have all the necessary compulsory options
170
         if (fromToTableTitle == null && toFromTableTitle == null)
171
         {
172
            MessageBox.Show("Error in EA_DocGenRelationshipMatrix options list\n\n" +
173
               "Missing option: Must specify at least one table title");
174
            return false;
175
         }
176
 
177
         // FROM items
178
         if (fromColumnTitle == null)
179
         {
180
            MessageBox.Show("Error in EA_DocGenRelationshipMatrix options list\n\n" +
181
               "Missing option: fromColumnTitle");
182
            return false;
183
         }
184
         if (fromPackageGUID == null)
185
         {
186
            MessageBox.Show("Error in EA_DocGenRelationshipMatrix options list\n\n" +
187
               "Missing option: fromPackageGUID");
188
            return false;
189
         }
190
         if (fromElementTypes.Count == 0)
191
         {
192
            MessageBox.Show("Error in EA_DocGenRelationshipMatrix options list\n\n" +
193
               "Missing option(s): fromElementTypes");
194
            return false;
195
         }      
196
 
197
         // TO items
198
         if (toColumnTitle == null)
199
         {
200
            MessageBox.Show("Error in EA_DocGenRelationshipMatrix options list\n\n" +
201
               "Missing option: toColumnTitle");
202
            return false;
203
         }
204
         if (toPackageGUID == null)
205
         {
206
            MessageBox.Show("Error in EA_DocGenRelationshipMatrix options list\n\n" +
207
               "Missing option: toPackageGUID");
208
            return false;
209
         }
210
         if (toElementTypes.Count == 0)
211
         {
212
            MessageBox.Show("Error in EA_DocGenRelationshipMatrix options list\n\n" +
213
               "Missing option(s): toElementTypes");
214
            return false;
215
         }   
216
 
217
         // Find GUID linked packages in the repository
2106 ghuddy 218
         fromPackage = Main.EA_Repository.GetPackageByGuid( fromPackageGUID );
2088 ghuddy 219
         if (fromPackage == null)
220
         {
221
            MessageBox.Show("Error processing EA_DocGenRelationshipMatrix\n\n" +
222
               "could not locate fromPackage in Repository");
223
            return false;
224
         }
225
 
2106 ghuddy 226
         toPackage = Main.EA_Repository.GetPackageByGuid( toPackageGUID );
2088 ghuddy 227
         if (toPackage == null)
228
         {
229
            MessageBox.Show("Error processing EA_DocGenRelationshipMatrix\n\n" +
230
               "could not locate toPackage in Repository");
231
            return false;
232
         }
233
 
234
         return true;
235
      }
236
 
237
 
2104 ghuddy 238
      public static string optionTemplateForRelationshipMatrix(int style)
2088 ghuddy 239
      {
2104 ghuddy 240
         switch (style)
241
         {
242
            case 1:
243
               return
244
               "style=1\r\n"
245
               + "fromToTableTitle=\r\n"
246
               + "fromIntroText=\r\n"
247
               + "fromColumnTitle=\r\n"
248
               + "fromPackage=\r\n"
249
               + "fromElementType=\r\n"
250
               + "fromElementType=\r\n"
251
               + "fromPackageRecursion=true\r\n"
252
               + "fromPackageTrimming=false\r\n"
253
 
254
               + "toFromTableTitle=\r\n"
255
               + "toIntroText=\r\n"
256
               + "toColumnTitle=\r\n"
257
               + "toPackage=\r\n"
258
               + "toElementType=\r\n"
259
               + "toPackageRecursion=true\r\n"
260
               + "toPackageTrimming=false\r\n";
261
            case 2:
262
               return
263
               "style=2\r\n"
264
               + "fromToTableTitle=Requirement Dependencies\r\n"
265
               + "fromIntroText=The following table identifies the source requirements (if any) for each requirement stated in this document.\r\n"
266
               + "fromColumnTitle=Requirement\r\n"
267
               + "fromPackage=\r\n"
268
               + "fromElementType=Requirement\r\n"
269
               + "fromPackageRecursion=true\r\n"
270
               + "fromPackageTrimming=false\r\n"
271
 
272
               + "toPackageRecursion=true\r\n"
273
               + "toPackage=\r\n"
274
               + "toColumnTitle=Source Requirements\r\n"
275
               + "toElementType=Requirement\r\n";
276
            default:
277
               return "";
278
         }
2088 ghuddy 279
      }
280
 
2104 ghuddy 281
      /// <summary>
282
      /// This function will insert one or more relationship matrix tables into the document, 
283
      /// built from content specified in options that are provided in the notes section of 
284
      /// the special element that has led to this function being called.
285
      /// </summary>
286
      /// <param name="theElement"></param>
287
      /// <param name="recurse_level"></param>
2106 ghuddy 288
      public static void processRelationshipMatrixElement( EA.Element theElement, int recurse_level )
2104 ghuddy 289
      {
290
         switch (style)
291
         {
292
            case 1:
293
               processRelationshipMatrixElementStyle1();
294
               break;
2088 ghuddy 295
 
2104 ghuddy 296
            case 2:
297
               processRelationshipMatrixElementStyle2();
298
               break;
299
         }
300
      }
301
 
302
      /// <summary>
303
      /// This function will insert a relationship matrix table into the document, built from content
304
      /// specified in options that are provided in the notes section of the special element that
305
      /// has led to this function being called.
306
      /// 
307
      /// The style of these tables is that required for requirement to design traceability.
308
      /// </summary>
309
      /// <param name="EA_RelMatrix"></param>
2106 ghuddy 310
      private static void processRelationshipMatrixElementStyle1()
2104 ghuddy 311
      {
312
         int tableNum = 0;
313
         Word.Table table = null;
314
 
315
         // Scan the fromPackage to find all the "from elements".
2106 ghuddy 316
         ElementAccumulator fromLister = new ElementAccumulator(fromElementTypes);
317
         EA_Utilities.findAndProcessPackageElements( fromPackage, fromLister, fromPackageRecursion );
2104 ghuddy 318
 
2106 ghuddy 319
         if (createWordDoc.abortCreationThread)
320
            return;
321
 
2104 ghuddy 322
         // Sort the "from elements"
323
         elementSortByName sorter = new elementSortByName();
324
         fromLister.Elements.Sort( sorter );
325
 
2106 ghuddy 326
         if (createWordDoc.abortCreationThread)
327
            return;
328
 
2104 ghuddy 329
         // dictionary to support from-to table construction.
330
         ArrayList fromToDictionary = new ArrayList();
331
 
332
         // dictionary to support to-from table construction.
333
         ArrayList toFromDictionary = new ArrayList();
334
 
335
         bool needFromToTable = false;
336
         if (fromToTableTitle != null && fromToTableTitle.Length > 0)
337
            needFromToTable = true;
338
 
339
         bool needToFromTable = false;
340
         if (toFromTableTitle != null && toFromTableTitle.Length > 0)
341
            needToFromTable = true;
342
 
343
         // NOTE: this code has to execute even if no from-to table is needed, in order to support the
344
         // generation of a to-from table, assuming the user has requested one.
345
         int numberOfFromToRows = 0;
346
 
347
         foreach(EA.Element fromElement in fromLister.Elements)
348
         {
2106 ghuddy 349
            if (createWordDoc.abortCreationThread)
350
               return;
351
 
2104 ghuddy 352
            // look at the elements connection collection to find references to the
353
            // destination elements
354
            bool foundToElement = false;
355
 
356
            EA.Collection conCollection = fromElement.Connectors;
357
 
358
            foreach (EA.Connector thisCon in conCollection)
359
            {
2106 ghuddy 360
               if (createWordDoc.abortCreationThread)
361
                  return;
362
 
363
               EA.Element destE = Main.EA_Repository.GetElementByID( thisCon.SupplierID );
2104 ghuddy 364
               if (destE == null)
365
                  continue;
366
 
367
               // ignore self-referential connections
368
               if (fromElement.ElementID == thisCon.SupplierID)
369
                  continue;
370
 
371
               // if the destination element is of a type that the user has requested to include...
372
               if (!toElementTypes.Contains( destE.Type ))
373
                  continue;
374
 
375
               // Capture the from-to relationship in a dictionary where the key is the
376
               // "from element", and the value is the "to element".
377
               DictionaryEntry newFromToEntry = new DictionaryEntry(fromElement, destE);
378
               fromToDictionary.Add( newFromToEntry );
379
               foundToElement = true;
380
 
381
               // Capture the from-to relationship in a dictionary where the key is the
382
               // ID of the destination element, and the value is the from element name.
383
               // This dictionary will enable rapid construction of the to-from table if
384
               // the user has requested it, from the exact same relationship info used
385
               // to construct the from-to table.
386
               if (needToFromTable)
387
               {
388
                  DictionaryEntry newToFromEntry = new DictionaryEntry(destE.ElementID, fromElement.Name);
389
                  toFromDictionary.Add( newToFromEntry );
390
               }
391
            }
392
 
393
            // If we found a from-to relationship that table needs a new row.
394
            if (foundToElement)
395
            {
396
               numberOfFromToRows++;
397
            }
398
               // If we did not find a from-to relationship that table still needs a new row 
399
               // if the user wants all "from elements", even if some have no "to elements".
400
            else if (fromPackageTrimming == false)
401
            {
402
               DictionaryEntry newFromToEntry = new DictionaryEntry(fromElement, null);
403
               fromToDictionary.Add( newFromToEntry );
404
               numberOfFromToRows++;
405
            }
406
         }
407
 
2106 ghuddy 408
         if (createWordDoc.abortCreationThread)
409
            return;
410
 
2104 ghuddy 411
         if (needFromToTable)
412
         {
413
            // Now we can actually serialise the table
414
 
415
            if (fromIntroText != null && fromIntroText.Length > 0)
416
            {
2106 ghuddy 417
               TextualContent.appendAndSelectText( fromIntroText, EA_Constants.styleName_Body1 );
2104 ghuddy 418
            }
419
 
420
            // create the from-to table in the word doc
2106 ghuddy 421
            tableNum = TabularContent.Table_Create( fromToTableTitle, true, numberOfFromToRows + 1, 2 );
422
            table = createWordDoc.WordDocument.Tables[tableNum];
2104 ghuddy 423
 
2106 ghuddy 424
            TabularContent.Table_SetTableColumnTitle(table, fromColumnTitle, 1);
425
            TabularContent.Table_SetTableColumnTitle(table, toColumnTitle, 2);
2104 ghuddy 426
 
427
            fillInTable(fromToDictionary, table);
428
         }
429
 
2106 ghuddy 430
         if (createWordDoc.abortCreationThread)
431
            return;
432
 
2104 ghuddy 433
         // Does user want a to-from table ?
434
         if (needToFromTable)
435
         {
436
            // re-use the fromToDictionary to prepare the to-from table content 
437
            fromToDictionary.Clear();
438
 
439
            // find all elements for the left hand column of the to-from table.
2106 ghuddy 440
            ElementAccumulator toLister = new ElementAccumulator(toElementTypes);
441
            EA_Utilities.findAndProcessPackageElements( toPackage, toLister, toPackageRecursion );
2104 ghuddy 442
 
2106 ghuddy 443
            if (createWordDoc.abortCreationThread)
444
               return;
445
 
2104 ghuddy 446
            // Sort the "to" elements
447
            toLister.Elements.Sort( sorter );
448
 
2106 ghuddy 449
            if (createWordDoc.abortCreationThread)
450
               return;
451
 
2104 ghuddy 452
            // To make the to-from table, we use the dictionary that was built when making the from-to
453
            // table. The dictionary will allow rapid determination of what "from" items belong to each
454
            // "to" item, without us having to go back to EA and enquire on the database.
455
            // We build a new fromToDictionary from the toFromDictionary, in advance of actually making 
456
            // the table so that we can figure out how many rows the table needs to have.
457
            numberOfFromToRows = 0;
458
 
459
            foreach(EA.Element toElement in toLister.Elements)
460
            {
2106 ghuddy 461
               if (createWordDoc.abortCreationThread)
462
                  return;
463
 
2104 ghuddy 464
               bool foundToElement = false;
465
 
466
               // right-column cell content
467
               foreach (DictionaryEntry de in toFromDictionary)
468
               {
469
                  if ((int)de.Key == toElement.ElementID)
470
                  {
471
                     DictionaryEntry newFromToEntry = new DictionaryEntry(toElement, (string)de.Value);
472
                     fromToDictionary.Add( newFromToEntry );
473
                     foundToElement = true;
474
                  }
475
               }
476
 
2106 ghuddy 477
               if (createWordDoc.abortCreationThread)
478
                  return;
479
 
2104 ghuddy 480
               // If we found a from-to relationship that table needs a new row.
481
               if (foundToElement)
482
               {
483
                  numberOfFromToRows++;
484
               }
485
                  // if user wants all "from elements", even if some have no "to elements", then add a dictionary
486
                  // entry and bump row count.
487
               else if (toPackageTrimming == false)
488
               {
489
                  DictionaryEntry newFromToEntry = new DictionaryEntry(toElement, "");
490
                  fromToDictionary.Add( newFromToEntry );
491
                  numberOfFromToRows++;
492
               }
493
            }
494
 
2106 ghuddy 495
            if (createWordDoc.abortCreationThread)
496
               return;
497
 
2104 ghuddy 498
            // Now begin to add the to-from table to the word document
499
            if (toIntroText != null && toIntroText.Length > 0)
500
            {
2106 ghuddy 501
               TextualContent.appendAndSelectText( toIntroText, EA_Constants.styleName_Body1 );
2104 ghuddy 502
            }
503
 
504
            // create the table in the word doc
2106 ghuddy 505
            tableNum = TabularContent.Table_Create( toFromTableTitle, true, numberOfFromToRows + 1, 2 );
506
            table = createWordDoc.WordDocument.Tables[tableNum];
2104 ghuddy 507
 
2106 ghuddy 508
            TabularContent.Table_SetTableColumnTitle(table, toColumnTitle, 1);
509
            TabularContent.Table_SetTableColumnTitle(table, fromColumnTitle, 2);
2104 ghuddy 510
 
511
            fillInTable(fromToDictionary, table);
512
         }
513
      }
514
 
2106 ghuddy 515
      private static void fillInTable(ArrayList fromToDictionary, Word.Table table )
2104 ghuddy 516
      {
517
         int lastFromElementId = -1;
518
         bool firstToFromCon = true;
519
         int row = 1;
520
         foreach (DictionaryEntry de in fromToDictionary)
521
         {
2106 ghuddy 522
            if (createWordDoc.abortCreationThread)
523
               return;
524
 
2104 ghuddy 525
            if ( ((EA.Element)de.Key).ElementID != lastFromElementId )
526
            {
527
               lastFromElementId = ((EA.Element)de.Key).ElementID;
528
               row++;
529
               table.Cell(row,1).Range.Text = ((EA.Element)de.Key).Name;
530
               firstToFromCon = true;
531
            }
532
 
533
            if (((string)de.Value).Length > 0)
534
            {
535
               if (firstToFromCon)
536
               {
537
                  firstToFromCon = false;
538
                  table.Cell(row,2).Range.Text = (string)de.Value;
539
               }
540
               else
541
               {
542
                  table.Cell(row,2).Range.Text += (string)de.Value;
543
               }
544
            }
545
            else
546
            {
2116 ghuddy 547
               if (EA_DocGenOptions.optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_UN_ALLOCATED_RELATIONSHIP_WARNINGS) == false)
2104 ghuddy 548
               {
549
                  table.Cell(row,2).Range.Text = "Un-allocated relationship!";
550
                  table.Cell(row,2).Range.Font.Color = Word.WdColor.wdColorRed;
551
               }
552
            }
553
         }
554
      }
555
 
556
      /// <summary>
557
      /// This function will insert a relationship matrix table into the document, built from content
558
      /// specified in options that are provided in the notes section of the special element that
559
      /// has led to this function being called.
560
      /// 
561
      /// The style of this single table is that required for requirement to requirement traceability.
562
      /// Here, only a single table is generated, and the only elements in the left hand column will
563
      /// be those serialised to the document earlier on, and the content of the right hand column
564
      /// will be the parental requirements (all the way up to root requirements).
565
      /// </summary>
566
      /// <param name="EA_RelMatrix"></param>
2106 ghuddy 567
      private static void processRelationshipMatrixElementStyle2()
2104 ghuddy 568
      {
569
         int i;
570
         int tableNum = 0;
571
         Word.Table table = null;
572
 
573
         // Scan the fromPackage to find all the "from elements".
2106 ghuddy 574
         ElementAccumulator fromLister = new ElementAccumulator(fromElementTypes);
575
         EA_Utilities.findAndProcessPackageElements( fromPackage, fromLister, fromPackageRecursion );
2104 ghuddy 576
 
2106 ghuddy 577
         if (createWordDoc.abortCreationThread)
578
            return;
579
 
2104 ghuddy 580
         // Remove all elements from the list that did not go to form content in the document
581
         // prior to this point in the document generation process.
582
         for (i=0; i<fromLister.Elements.Count; )
583
         {
2106 ghuddy 584
            if (createWordDoc.abortCreationThread)
585
               return;
586
 
2104 ghuddy 587
            if ( !processedElements.Contains( ((EA.Element)fromLister.Elements[i]).ElementID ) )
588
            {
589
               fromLister.Elements.RemoveAt(i);
590
               continue;
591
            }
592
            i++;
593
         }
594
 
2106 ghuddy 595
         if (createWordDoc.abortCreationThread)
596
            return;
597
 
2104 ghuddy 598
         // Sort the remaining "from elements"
599
         elementSortByName sorter = new elementSortByName();
600
         fromLister.Elements.Sort( sorter );
2106 ghuddy 601
 
602
         if (createWordDoc.abortCreationThread)
603
            return;
604
 
2104 ghuddy 605
         // Scan the toPackage to find all the "to elements".
606
         // Extract their element IDs into a new list.
2106 ghuddy 607
         ElementAccumulator toLister = new ElementAccumulator(toElementTypes);
608
         EA_Utilities.findAndProcessPackageElements( toPackage, toLister, toPackageRecursion );
2104 ghuddy 609
         ArrayList acceptableParents = new ArrayList();
610
         foreach(EA.Element ele in toLister.Elements)
611
         {
2106 ghuddy 612
            if (createWordDoc.abortCreationThread)
613
               return;
614
 
2104 ghuddy 615
            acceptableParents.Add( ele.ElementID);
616
         }
617
 
2106 ghuddy 618
         if (createWordDoc.abortCreationThread)
619
            return;
620
 
2104 ghuddy 621
         // The list of from elements dictates the number of rows in our table.
622
         int numberOfFromToRows = fromLister.Elements.Count;
623
 
624
         if (fromIntroText != null && fromIntroText.Length > 0)
625
         {
2106 ghuddy 626
            TextualContent.appendAndSelectText( fromIntroText, EA_Constants.styleName_Body1 );
2104 ghuddy 627
         }
628
 
629
         // create the from-to table in the word doc
2106 ghuddy 630
         tableNum = TabularContent.Table_Create( fromToTableTitle, true, numberOfFromToRows + 1, 2 );
631
         table = createWordDoc.WordDocument.Tables[tableNum];
2104 ghuddy 632
 
2106 ghuddy 633
         TabularContent.Table_SetTableColumnTitle(table, fromColumnTitle, 1);
634
         TabularContent.Table_SetTableColumnTitle(table, toColumnTitle, 2);
2104 ghuddy 635
 
636
         int row = 2;
637
         foreach(EA.Element ele in fromLister.Elements)
638
         {
2106 ghuddy 639
            if (createWordDoc.abortCreationThread)
640
               return;
641
 
2104 ghuddy 642
            table.Cell(row,1).Range.Text = ele.Name;
643
 
644
            StringBuilder sb = new StringBuilder();
645
 
646
            ArrayList parentsDiscovered = new ArrayList();
647
 
648
            // Find this requirement's parent (source) requirements
649
            elementParenthood(ele, ref acceptableParents, ref parentsDiscovered, ref sb);
650
 
651
            // if no source requirements found and user has opted for trimming, delete the table row
652
            if (fromPackageTrimming == true && sb.Length == 0)
653
            {
2106 ghuddy 654
               TabularContent.Table_DeleteThisRow(table, row);
2104 ghuddy 655
               continue;
656
            }
657
 
658
            // fill in the right hand cell on this row of the table with the source requirement list
659
            table.Cell(row,2).Range.Text = sb.ToString();
660
            row++;
661
         }
662
 
663
      }
664
 
2106 ghuddy 665
      private static void elementParenthood(EA.Element ele, ref ArrayList acceptableParents, ref ArrayList parentsDiscovered, ref StringBuilder sb)
2104 ghuddy 666
      {
667
         foreach(EA.Connector con in ele.Connectors)
668
         {
2106 ghuddy 669
            if (createWordDoc.abortCreationThread)
670
               return;
671
 
2104 ghuddy 672
            // ignore downwards direction, indicated by the client ID being equal to the element ID
673
            if (con.ClientID != ele.ElementID)
674
            {
675
               // if we have not already come across this upward path before...
676
               if (!parentsDiscovered.Contains(con.ClientID))
677
               {
678
                  parentsDiscovered.Add(con.ClientID);
679
 
680
                  // is this parent is in the list of acceptable parents...
681
                  if (acceptableParents.Contains(con.ClientID))
682
                  {
683
                     // get the parent element, add its name to our list, and ascend through the element
684
                     // using recursion.
2106 ghuddy 685
                     EA.Element client = Main.EA_Repository.GetElementByID(con.ClientID);
2104 ghuddy 686
                     if (client != null)
687
                     {
688
                        if (sb.Length > 0)
689
                           sb.Append("\n");
690
                        sb.Append(client.Name);
691
 
692
                        elementParenthood(client, ref acceptableParents, ref parentsDiscovered, ref sb);
693
                     }
694
                  }
695
               }
696
            }
697
         }
698
      }
699
 
2088 ghuddy 700
	}
701
}