Subversion Repositories DevTools

Rev

Rev 2094 | Rev 2106 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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