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