| 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 |
|
|
|
8 |
namespace EA_DocGen
|
|
|
9 |
{
|
|
|
10 |
/// <summary>
|
|
|
11 |
/// Summary description for EA_RelationshipMatrix.
|
|
|
12 |
/// </summary>
|
|
|
13 |
public class EA_RelationshipMatrix
|
|
|
14 |
{
|
|
|
15 |
private EA_Utilities EA_Utils = null;
|
| 2104 |
ghuddy |
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;
|
| 2088 |
ghuddy |
21 |
|
|
|
22 |
// declare option variables
|
| 2104 |
ghuddy |
23 |
private int style = 1;
|
| 2088 |
ghuddy |
24 |
|
| 2104 |
ghuddy |
25 |
private string fromIntroText = null; // This one is optional
|
|
|
26 |
private string fromPackageGUID = null;
|
|
|
27 |
private string fromToTableTitle = null; // This one is optional
|
|
|
28 |
private string fromColumnTitle = null;
|
|
|
29 |
private ArrayList fromElementTypes = null;
|
|
|
30 |
private bool fromPackageRecursion = true;
|
|
|
31 |
private EA.Package fromPackage = null;
|
|
|
32 |
private bool fromPackageTrimming = false;
|
| 2088 |
ghuddy |
33 |
|
| 2104 |
ghuddy |
34 |
private string toIntroText = null; // This one is optional
|
|
|
35 |
private string toPackageGUID = null;
|
|
|
36 |
private string toFromTableTitle = null; // This one is optional
|
|
|
37 |
private string toColumnTitle = null;
|
|
|
38 |
private ArrayList toElementTypes = null;
|
|
|
39 |
private bool toPackageRecursion = true;
|
|
|
40 |
private EA.Package toPackage = null;
|
|
|
41 |
private bool toPackageTrimming = false;
|
|
|
42 |
|
| 2094 |
ghuddy |
43 |
|
|
|
44 |
|
| 2088 |
ghuddy |
45 |
private string [] options_string = null;
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
| 2104 |
ghuddy |
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)
|
| 2088 |
ghuddy |
56 |
{
|
| 2104 |
ghuddy |
57 |
EA_Repository = EA_RepRef;
|
|
|
58 |
TableUtils = TableUtilsRef;
|
|
|
59 |
TextUtils = TextUtilsRef;
|
|
|
60 |
EA_Utils = EA_UtilsRef;
|
|
|
61 |
WordDocument = WordDocumentRef;
|
|
|
62 |
processedElements = processedElementsRef;
|
|
|
63 |
|
|
|
64 |
fromElementTypes = new ArrayList();
|
|
|
65 |
toElementTypes = new ArrayList();
|
| 2088 |
ghuddy |
66 |
}
|
|
|
67 |
|
| 2104 |
ghuddy |
68 |
private void reset()
|
| 2088 |
ghuddy |
69 |
{
|
| 2104 |
ghuddy |
70 |
style = 1;
|
|
|
71 |
|
| 2088 |
ghuddy |
72 |
fromIntroText = null;
|
|
|
73 |
fromPackageGUID = null;
|
|
|
74 |
fromToTableTitle = null;
|
|
|
75 |
fromColumnTitle = null;
|
|
|
76 |
fromElementTypes.Clear();
|
|
|
77 |
fromPackageRecursion = true;
|
| 2094 |
ghuddy |
78 |
fromPackageTrimming = false;
|
| 2088 |
ghuddy |
79 |
fromPackage = null;
|
|
|
80 |
toIntroText = null;
|
|
|
81 |
toPackageGUID = null;
|
|
|
82 |
toFromTableTitle = null;
|
|
|
83 |
toColumnTitle = null;
|
|
|
84 |
toElementTypes.Clear();
|
|
|
85 |
toPackageRecursion = true;
|
| 2094 |
ghuddy |
86 |
toPackageTrimming = false;
|
| 2088 |
ghuddy |
87 |
toPackage = null;
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
public bool processRelationshipMatrixOptions(EA.Element theElement)
|
|
|
92 |
{
|
|
|
93 |
reset();
|
|
|
94 |
|
|
|
95 |
// Extract the control options from the notes of the element
|
|
|
96 |
|
|
|
97 |
string delimStr = "\n";
|
|
|
98 |
char [] delim = delimStr.ToCharArray();
|
|
|
99 |
options_string = theElement.Notes.ToString().Split(delim,100);
|
|
|
100 |
int i = 0;
|
|
|
101 |
foreach(string s in options_string)
|
|
|
102 |
{
|
|
|
103 |
options_string[i] = s.Trim();
|
|
|
104 |
i++;
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
// scan the options string and assign values into the options variables as required
|
|
|
108 |
foreach(string s in options_string)
|
|
|
109 |
{
|
|
|
110 |
if (s.Length > 0 && s != "\n" && s != "\r" && s[0] != '\\')
|
|
|
111 |
{
|
| 2104 |
ghuddy |
112 |
if (s.StartsWith("style="))
|
|
|
113 |
{
|
|
|
114 |
style = EA_Utils.options.getOptionValue(s, style);
|
|
|
115 |
}
|
| 2088 |
ghuddy |
116 |
// FROM items
|
| 2104 |
ghuddy |
117 |
else if (s.StartsWith("fromIntroText="))
|
| 2088 |
ghuddy |
118 |
{
|
|
|
119 |
fromIntroText = EA_Utils.options.getOptionValue(s, null);
|
|
|
120 |
}
|
| 2104 |
ghuddy |
121 |
else if (s.StartsWith("fromToTableTitle="))
|
| 2088 |
ghuddy |
122 |
{
|
|
|
123 |
fromToTableTitle = EA_Utils.options.getOptionValue(s, null);
|
|
|
124 |
}
|
| 2104 |
ghuddy |
125 |
else if (s.StartsWith("fromColumnTitle="))
|
| 2088 |
ghuddy |
126 |
{
|
|
|
127 |
fromColumnTitle = EA_Utils.options.getOptionValue(s, fromColumnTitle);
|
|
|
128 |
}
|
| 2104 |
ghuddy |
129 |
else if (s.StartsWith("fromPackageRecursion="))
|
| 2088 |
ghuddy |
130 |
{
|
|
|
131 |
fromPackageRecursion = EA_Utils.options.getOptionValue(s, fromPackageRecursion);
|
|
|
132 |
}
|
| 2104 |
ghuddy |
133 |
else if (s.StartsWith("fromPackageTrimming="))
|
| 2094 |
ghuddy |
134 |
{
|
|
|
135 |
fromPackageTrimming = EA_Utils.options.getOptionValue(s, fromPackageTrimming);
|
|
|
136 |
}
|
| 2104 |
ghuddy |
137 |
else if (s.StartsWith("fromPackage="))
|
| 2088 |
ghuddy |
138 |
{
|
|
|
139 |
fromPackageGUID = EA_Utils.options.getOptionValue(s, fromPackageGUID);
|
|
|
140 |
}
|
| 2104 |
ghuddy |
141 |
else if (s.StartsWith("fromElementType="))
|
| 2088 |
ghuddy |
142 |
{
|
|
|
143 |
string et = EA_Utils.options.getOptionValue(s,null);
|
|
|
144 |
if (et != null)
|
|
|
145 |
{
|
|
|
146 |
fromElementTypes.Add( et );
|
|
|
147 |
}
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
// TO items
|
| 2104 |
ghuddy |
151 |
else if (s.StartsWith("toIntroText="))
|
| 2088 |
ghuddy |
152 |
{
|
|
|
153 |
toIntroText = EA_Utils.options.getOptionValue(s, null);
|
|
|
154 |
}
|
| 2104 |
ghuddy |
155 |
else if (s.StartsWith("toFromTableTitle="))
|
| 2088 |
ghuddy |
156 |
{
|
|
|
157 |
toFromTableTitle = EA_Utils.options.getOptionValue(s, null);
|
|
|
158 |
}
|
| 2104 |
ghuddy |
159 |
else if (s.StartsWith("toColumnTitle="))
|
| 2088 |
ghuddy |
160 |
{
|
|
|
161 |
toColumnTitle = EA_Utils.options.getOptionValue(s, toColumnTitle);
|
|
|
162 |
}
|
| 2104 |
ghuddy |
163 |
else if (s.StartsWith("toPackageRecursion="))
|
| 2088 |
ghuddy |
164 |
{
|
|
|
165 |
toPackageRecursion = EA_Utils.options.getOptionValue(s, toPackageRecursion);
|
|
|
166 |
}
|
| 2104 |
ghuddy |
167 |
else if (s.StartsWith("toPackageTrimming="))
|
| 2094 |
ghuddy |
168 |
{
|
|
|
169 |
toPackageTrimming = EA_Utils.options.getOptionValue(s, toPackageTrimming);
|
|
|
170 |
}
|
| 2104 |
ghuddy |
171 |
else if (s.StartsWith("toPackage="))
|
| 2088 |
ghuddy |
172 |
{
|
|
|
173 |
toPackageGUID = EA_Utils.options.getOptionValue(s, toPackageGUID);
|
|
|
174 |
}
|
| 2104 |
ghuddy |
175 |
else if (s.StartsWith("toElementType="))
|
| 2088 |
ghuddy |
176 |
{
|
|
|
177 |
string et = EA_Utils.options.getOptionValue(s,null);
|
|
|
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
|
|
|
235 |
fromPackage = EA_Utils.EA_Finder.findPackageInRepositoryByGUID( fromPackageGUID );
|
|
|
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 |
|
|
|
243 |
toPackage = EA_Utils.EA_Finder.findPackageInRepositoryByGUID( toPackageGUID );
|
|
|
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"
|
|
|
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 |
}
|
| 2088 |
ghuddy |
296 |
}
|
|
|
297 |
|
| 2104 |
ghuddy |
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;
|
| 2088 |
ghuddy |
312 |
|
| 2104 |
ghuddy |
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 )
|
|
|
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 )
|
|
|
507 |
{
|
|
|
508 |
lastFromElementId = ((EA.Element)de.Key).ElementID;
|
|
|
509 |
row++;
|
|
|
510 |
table.Cell(row,1).Range.Text = ((EA.Element)de.Key).Name;
|
|
|
511 |
firstToFromCon = true;
|
|
|
512 |
}
|
|
|
513 |
|
|
|
514 |
if (((string)de.Value).Length > 0)
|
|
|
515 |
{
|
|
|
516 |
if (firstToFromCon)
|
|
|
517 |
{
|
|
|
518 |
firstToFromCon = false;
|
|
|
519 |
table.Cell(row,2).Range.Text = (string)de.Value;
|
|
|
520 |
}
|
|
|
521 |
else
|
|
|
522 |
{
|
|
|
523 |
table.Cell(row,2).Range.Text += (string)de.Value;
|
|
|
524 |
}
|
|
|
525 |
}
|
|
|
526 |
else
|
|
|
527 |
{
|
|
|
528 |
if (EA_Utils.options.opt_SuppressUnAllocatedRelationshipWarnings == false)
|
|
|
529 |
{
|
|
|
530 |
table.Cell(row,2).Range.Text = "Un-allocated relationship!";
|
|
|
531 |
table.Cell(row,2).Range.Font.Color = Word.WdColor.wdColorRed;
|
|
|
532 |
}
|
|
|
533 |
}
|
|
|
534 |
}
|
|
|
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 |
}
|
|
|
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 |
}
|
|
|
656 |
|
| 2088 |
ghuddy |
657 |
}
|
|
|
658 |
}
|