Subversion Repositories DevTools

Rev

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