Subversion Repositories DevTools

Rev

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

Rev 2104 Rev 2106
Line 5... Line 5...
5
namespace EA_DocGen
5
namespace EA_DocGen
6
{
6
{
7
	/// <summary>
7
	/// <summary>
8
	/// Summary description for TextualContent.
8
	/// Summary description for TextualContent.
9
	/// </summary>
9
	/// </summary>
10
	public class TextualContent
10
   public class TextualContent
11
	{
11
   {
12
      private Word.Application WordApp = null;
-
 
13
      private Word.Document WordDocument = null;
12
      private static char[] trim_newlines;
14
      private DocSectionTracking DocSectionTracker = null;
-
 
15
 
13
 
16
		public TextualContent(Word.Application wordApp, Word.Document wordDocument, DocSectionTracking docSectionTracker)
-
 
17
		{
-
 
18
         WordApp = wordApp;
-
 
19
         WordDocument = wordDocument;
14
      public static void initialise()
20
         DocSectionTracker = docSectionTracker;
-
 
21
		}
-
 
22
 
-
 
23
 
-
 
24
      public void AcceptWordAppAndDoc(Word.Application wordApp, Word.Document wordDocument)
-
 
25
      {
15
      {
26
         WordApp = wordApp;
16
         string s_trim_newlines = "\r\n";
27
         WordDocument = wordDocument;
17
         trim_newlines = s_trim_newlines.ToCharArray();
28
      }
18
      }
29
 
19
 
30
      public Word.Range appendDescription(string wordText, EA_Utilities EA_Utils)
20
      public static Word.Range appendDescription(string wordText)
31
      {
21
      {
32
         return appendDescription(wordText, EA_Utils, false);
22
         return appendDescription(wordText, false);
33
      }
23
      }
34
 
24
 
35
      public Word.Range appendDescription(string wordText, EA_Utilities EA_Utils, bool continuation)
25
      public static Word.Range appendDescription(string wordText, bool continuation)
36
      {
26
      {
37
         return appendDescription(wordText, EA_Constants.styleName_Body1, EA_Utils, continuation);
27
         return appendDescription(wordText, EA_Constants.styleName_Body1, continuation);
38
      }
28
      }
39
 
29
 
40
      public Word.Range appendDescription(string wordText, string styleName, EA_Utilities EA_Utils, bool continuation)
30
      public static Word.Range appendDescription(string wordText, string styleName, bool continuation)
41
      {
31
      {
42
         Word.Range wr = null;
32
         Word.Range wr = null;
43
 
33
 
44
         if (wordText != null && wordText.Length > 0)
34
         if (wordText != null && wordText.Length > 0)
-
 
35
         {
45
            wr = appendAndSelectText(wordText, styleName, continuation);
36
            wr = appendAndSelectText(wordText, styleName, continuation);
-
 
37
         }
46
         else if (!EA_Utils.options.opt_SuppressElementDescriptionMissingWarnings)
38
         else if (!EA_DocGenOptions.opt_SuppressElementDescriptionMissingWarnings)
47
         {
39
         {
48
            wr = appendAndSelectText("Description missing!", styleName, continuation);
40
            wr = appendAndSelectText("Description missing!", styleName, continuation);
49
            // For some wierd reason, if continuing on same paragraph, we have to decrement the range start by 1
41
            // For some wierd reason, if continuing on same paragraph, we have to decrement the range start by 1
50
            // otherwise the D of Description, does not get the red color or italic style
42
            // otherwise the D of Description, does not get the red color or italic style
51
            if (continuation)
43
            if (continuation)
Line 63... Line 55...
63
      /// the specified style formatting to it.
55
      /// the specified style formatting to it.
64
      /// </summary>
56
      /// </summary>
65
      /// <param name="wordText"></param>
57
      /// <param name="wordText"></param>
66
      /// <param name="styleText"></param>
58
      /// <param name="styleText"></param>
67
      /// <param name="continuation"></param>
59
      /// <param name="continuation"></param>
68
      public Word.Range appendAndSelectText(string wordText, string styleText) 
60
      public static Word.Range appendAndSelectText(string wordText, string styleText) 
69
      { 
61
      { 
70
         return appendAndSelectText(wordText, styleText, false );
62
         return appendAndSelectText(wordText, styleText, false );
71
      }
63
      }
72
 
64
 
73
 
65
 
74
      public Word.Range appendAndSelectText(string wordText, string styleText, bool continuation )
66
      public static Word.Range appendAndSelectText(string wordText, string styleText, bool continuation )
75
      {
67
      {
76
         if (wordText.Length > 0)
68
         if (wordText.Length > 0)
77
         {
69
         {
78
            Word.Range WordRange = null;
70
            Word.Range WordRange = null;
79
            object startLocation;
71
            object startLocation;
80
            object endLocation;
72
            object endLocation;
81
 
73
 
82
            object style = styleText;
74
            object style = styleText;
83
            int i;
75
            int i;
84
            startLocation = 0;
76
            startLocation = 0;
85
            endLocation = i = WordDocument.Content.End;
77
            endLocation = i = createWordDoc.WordDocument.Content.End;
86
 
78
 
87
            WordRange = WordDocument.Range(ref startLocation, ref endLocation);
79
            WordRange = createWordDoc.WordDocument.Range(ref startLocation, ref endLocation);
88
 
80
 
89
            if (!continuation)
81
            if (!continuation)
90
               WordRange.InsertAfter( "\n" );
82
               WordRange.InsertAfter( "\n" );
91
            
83
            
92
            WordRange.InsertAfter( wordText );
84
            WordRange.InsertAfter( wordText );
93
 
85
 
94
            // Make a range out of the pasted text
86
            // Make a range out of the pasted text
95
            startLocation = i;
87
            startLocation = i;
96
            endLocation = WordDocument.Content.End;
88
            endLocation = createWordDoc.WordDocument.Content.End;
97
            WordRange = WordDocument.Range(ref startLocation, ref endLocation);
89
            WordRange = createWordDoc.WordDocument.Range(ref startLocation, ref endLocation);
98
 
90
 
99
            // and set the pasted text style
91
            // and set the pasted text style
100
            WordRange.set_Style(ref style);
92
            WordRange.set_Style(ref style);
101
            return WordRange;
93
            return WordRange;
102
         }
94
         }
Line 108... Line 100...
108
      /// Appends a specified text string to the word document, selects the new text, and applies
100
      /// Appends a specified text string to the word document, selects the new text, and applies
109
      /// a heading level style to it. 
101
      /// a heading level style to it. 
110
      /// </summary>
102
      /// </summary>
111
      /// <param name="wordText"></param>
103
      /// <param name="wordText"></param>
112
      /// <param name="level"></param>
104
      /// <param name="level"></param>
113
      public void appendAndSelectHeadingText(string wordText, int level)
105
      public static void appendAndSelectHeadingText(string wordText, int level)
114
      {
106
      {
115
         // A caller is requesting a new heading level so pass the level to the tracking
107
         // A caller is requesting a new heading level so pass the level to the tracking
116
         // object so that we can predict exactly what the level numbering should be for
108
         // object so that we can predict exactly what the level numbering should be for
117
         // diagnostics and fake heading generation (see below in the switch statement).
109
         // diagnostics and fake heading generation (see below in the switch statement).
118
         DocSectionTracker.trackDocSection(level);
110
         DocSectionTracking.trackDocSection(level);
119
 
111
 
120
         // Convert level to heading style
112
         // Convert level to heading style
121
         string styleText;
113
         string styleText;
122
         switch(level)
114
         switch(level)
123
         {
115
         {
Line 133... Line 125...
133
 
125
 
134
            default: 
126
            default: 
135
               // MS-Word cannot produce headings above level 9 and so we have to 
127
               // MS-Word cannot produce headings above level 9 and so we have to 
136
               // fake a heading by constructing it from our document section tracking data.
128
               // fake a heading by constructing it from our document section tracking data.
137
               styleText = EA_Constants.styleName_Heading10OrAbove;
129
               styleText = EA_Constants.styleName_Heading10OrAbove;
138
               wordText = DocSectionTracker.formHeadingString(wordText);
130
               wordText = DocSectionTracking.formHeadingString(wordText);
139
               break;
131
               break;
140
         }
132
         }
141
         // append the text as a heading
133
         // append the text as a heading
142
         appendAndSelectText(wordText, styleText);
134
         appendAndSelectText(wordText, styleText);
143
      }
135
      }
144
 
-
 
145
 
136
 
-
 
137
      public static string trimTrailingReturns(string s)
-
 
138
      {
-
 
139
          return s.TrimEnd(trim_newlines);
-
 
140
      }
-
 
141
   
-
 
142
   
-
 
143
 
146
      public string testSuiteName(EA.Element theElement)
144
      public static string testSuiteName(EA.Element theElement)
147
      {
145
      {
148
         return "Test Suite - " + theElement.Name;
146
         return "Test Suite - " + theElement.Name;
149
      }
147
      }
150
 
148
 
151
 
149
 
152
      public void appendUnitTestSuite(EA.Element theElement, int recurse_level, ref ArrayList classList, ref EA_Utilities EA_Utils)
150
      public static void appendUnitTestSuite(EA.Element theElement, int recurse_level, ref ArrayList classList)
153
      {
151
      {
154
         if (theElement.StereotypeEx.IndexOf("API") < 0)
152
         if (theElement.StereotypeEx.IndexOf("API") < 0)
155
         {
153
         {
156
            // element does not have an API stereotype, so is not a class for which unit tests are expected.
154
            // element does not have an API stereotype, so is not a class for which unit tests are expected.
157
            return;
155
            return;
Line 189... Line 187...
189
            }
187
            }
190
         }
188
         }
191
      }
189
      }
192
 
190
 
193
 
191
 
194
      public void appendUnitTestSuite(EA.Package thePackage, int recurse_level, ref ArrayList classList, ref EA_Utilities EA_Utils)
192
      public static void appendUnitTestSuite(EA.Package thePackage, int recurse_level, ref ArrayList classList)
195
      {
193
      {
196
         EA_ElementSorter elementSorter = new EA_ElementSorter(thePackage);
194
         EA_ElementSorter elementSorter = new EA_ElementSorter(thePackage);
197
         EA.Element theElement = null;
195
         EA.Element theElement = null;
198
         int theElementsRelativeLevel = 0;
196
         int theElementsRelativeLevel = 0;
199
         if (true == elementSorter.getFirst(ref theElement, ref theElementsRelativeLevel))
197
         if (true == elementSorter.getFirst(ref theElement, ref theElementsRelativeLevel))
200
         {
198
         {
201
            do
199
            do
202
            {
200
            {
203
               if (theElement.Type.StartsWith("Class"))
201
               if (theElement.Type.StartsWith("Class"))
204
               {
202
               {
205
                  appendUnitTestSuite(theElement, recurse_level, ref classList, ref EA_Utils);
203
                  appendUnitTestSuite(theElement, recurse_level, ref classList);
206
               }
204
               }
207
 
205
 
208
            } while (true == elementSorter.getNext(ref theElement, ref theElementsRelativeLevel));
206
            } while (true == elementSorter.getNext(ref theElement, ref theElementsRelativeLevel));
209
         }
207
         }
210
 
208
 
211
         // Scan through the packages within this package.
209
         // Scan through the packages within this package.
212
         foreach(EA.Package lowerLevelPackage in thePackage.Packages)
210
         foreach(EA.Package lowerLevelPackage in thePackage.Packages)
213
         {
211
         {
214
            // recurse
212
            // recurse
215
            appendUnitTestSuite(lowerLevelPackage, recurse_level, ref classList, ref EA_Utils);
213
            appendUnitTestSuite(lowerLevelPackage, recurse_level, ref classList);
216
         }
214
         }
217
      }
215
      }
218
 
216
 
219
 
217
 
220
      public void SelectInsertionPointAtEndOfDocument()
218
      public static void SelectInsertionPointAtEndOfDocument()
221
      {
219
      {
222
         object unit; 
220
         object unit; 
223
         object extend;
221
         object extend;
224
 
222
 
225
         unit = Word.WdUnits.wdStory; 
223
         unit = Word.WdUnits.wdStory; 
226
         extend = Word.WdMovementType.wdMove;
224
         extend = Word.WdMovementType.wdMove;
227
         WordApp.Selection.EndKey(ref unit, ref extend);
225
         createWordDoc.WordApp.Selection.EndKey(ref unit, ref extend);
228
      }
226
      }
229
 
227
 
230
 
228
 
231
      /// <summary>
229
      /// <summary>
232
      /// Generates the text for requirements.  This uses custom styles to format the text 
230
      /// Generates the text for requirements.  This uses custom styles to format the text 
233
      /// rather than formatting it in code.
231
      /// rather than formatting it in code.
234
      /// </summary>
232
      /// </summary>
235
      public bool generateRequirementText( EA.Element theElement, EA_Utilities EA_Utils )
233
      public static bool generateRequirementText( EA.Element theElement )
236
      {
234
      {
237
         if ( theElement.Type.StartsWith("Requirement"))
235
         if ( theElement.Type.StartsWith("Requirement"))
238
         {
236
         {
239
            string reqID = "";
237
            string reqID = "";
240
            string reqShortDesc = "";
238
            string reqShortDesc = "";
241
            string reqNotes = "";
-
 
242
            string reqStatusText = "";
-
 
243
            string reqHeadingStyle ="";
239
            string reqHeadingStyle ="";
244
            string reqParaStyle = "";
240
            string reqParaStyle = "";
245
            object reqNameStyle = EA_Constants.styleName_ReqName;
-
 
246
            Word.Range shortDescRange;
241
            
247
 
242
 
248
            // Set the style depending on the status
243
            // Set the style depending on the status
249
            switch ( theElement.Status )
244
            switch ( theElement.Status )
250
            {
245
            {
251
               case "Proposed":
246
               case "Proposed":
252
                  reqStatusText = "(Proposed)";
-
 
253
                  reqHeadingStyle = EA_Constants.styleName_ReqPropHdr;
247
                  reqHeadingStyle = EA_Constants.styleName_ReqPropHdr;
254
                  reqParaStyle    = EA_Constants.styleName_ReqPropBody;
248
                  reqParaStyle    = EA_Constants.styleName_ReqPropBody;
255
                  break;
249
                  break;
256
 
250
 
257
               case "Rejected":
251
               case "Rejected":
258
                  reqHeadingStyle = EA_Constants.styleName_ReqRejHdr;
252
                  reqHeadingStyle = EA_Constants.styleName_ReqRejHdr;
259
                  reqParaStyle    = EA_Constants.styleName_ReqRejBody;
253
                  reqParaStyle    = EA_Constants.styleName_ReqRejBody;
260
                  break;
254
                  break;
261
 
255
 
262
               case "Approved":
256
               case "Approved":
263
                  //reqStatusText = "(Approved)";
-
 
264
                  //reqStatusText = "(Phase " + theElement.Phase + ")";
-
 
265
                  reqHeadingStyle = EA_Constants.styleName_ReqAppHdr;
257
                  reqHeadingStyle = EA_Constants.styleName_ReqAppHdr;
266
                  reqParaStyle    = EA_Constants.styleName_ReqAppBody;
258
                  reqParaStyle    = EA_Constants.styleName_ReqAppBody;
267
                  break;
259
                  break;
268
 
260
 
269
               default:
261
               default:
270
                  reqStatusText = "(" + theElement.Status + ")";
-
 
271
                  //reqStatusText = "(" + theElement.Status + ")(Phase " + theElement.Phase + ")";
-
 
272
                  reqHeadingStyle = EA_Constants.styleName_ReqAppHdr;
262
                  reqHeadingStyle = EA_Constants.styleName_ReqAppHdr;
273
                  reqParaStyle    = EA_Constants.styleName_ReqAppBody;
263
                  reqParaStyle    = EA_Constants.styleName_ReqAppBody;
274
                  break;
264
                  break;
275
            }
265
            }
276
 
266
 
277
            // Pull out the ID from the name
267
            // Pull out the ID from the name
278
            int pos = theElement.Name.IndexOf( " ", 0, theElement.Name.Length );
268
            int pos = theElement.Name.IndexOf( " ", 0, theElement.Name.Length );
-
 
269
            if (pos > 0)
279
            reqID = theElement.Name.Substring( 0, pos );
270
               reqID = theElement.Name.Substring( 0, pos );
-
 
271
 
-
 
272
            // Count '.' chars in the ID
-
 
273
            int numDots = 0;
-
 
274
            foreach (char c in reqID)
-
 
275
            {
-
 
276
               if (c == '.')
-
 
277
                  numDots++;
-
 
278
            }
-
 
279
 
-
 
280
            // Calculate what the left/hanging indent should be based on the standard 2.5 cm plus a 
-
 
281
            // factor derived from the number of dots in the ID
-
 
282
            float indent_cm = (float)(2.5 + (0.5 * numDots));
280
 
283
 
281
            // Pull out the short description from the rest of the name
284
            // Pull out the short description from the rest of the name
282
            reqShortDesc = theElement.Name.Substring( pos, theElement.Name.Length-pos );
285
            reqShortDesc = theElement.Name.Substring( pos, theElement.Name.Length-pos );
283
            reqShortDesc = reqShortDesc.Trim();
286
            reqShortDesc = reqShortDesc.Trim();
284
 
287
 
285
            // Pull out the notes
-
 
286
            reqNotes = theElement.Notes.ToString();
-
 
287
 
-
 
288
            // Add the text
288
            // Add the text
289
            appendAndSelectText( reqID + '\t', reqHeadingStyle );
289
            Word.Range wr_id = appendAndSelectText( reqID + '\t', reqHeadingStyle );
-
 
290
 
290
            shortDescRange = appendAndSelectText( reqShortDesc, reqHeadingStyle, true );
291
            Word.Range wr_desc = appendAndSelectText( reqShortDesc, reqHeadingStyle, true );
-
 
292
 
-
 
293
            //Bold the short description
-
 
294
            wr_desc.Start = wr_desc.Start-1;
-
 
295
            wr_desc.Font.Bold = 1;
-
 
296
 
-
 
297
            // Indent according to the number of dots in the tag
-
 
298
            if (numDots > 0)
-
 
299
            {
-
 
300
               wr_desc.ParagraphFormat.LeftIndent      =  createWordDoc.WordApp.CentimetersToPoints(indent_cm);
-
 
301
               wr_desc.ParagraphFormat.FirstLineIndent = -createWordDoc.WordApp.CentimetersToPoints(indent_cm);
-
 
302
            }
-
 
303
 
-
 
304
            // Add requirement notes/body, if there is any
-
 
305
            if (theElement.Notes != null && theElement.Notes.Length > 0)
-
 
306
            {
291
            Word.Range WordRange = appendAndSelectText( '\t' + reqStatusText, reqHeadingStyle, true );
307
               Word.Range wr_body = appendAndSelectText( theElement.Notes, reqParaStyle );
292
 
308
 
293
            //reapply the name char style to the short desc.
309
               // indent according to the number of dots in the tag
294
            shortDescRange.Start = shortDescRange.Start-1;
310
               if (numDots > 0)
-
 
311
               {
-
 
312
                  wr_body.ParagraphFormat.LeftIndent = createWordDoc.WordApp.CentimetersToPoints( indent_cm );
-
 
313
               }
-
 
314
            }
-
 
315
            else
-
 
316
            {
-
 
317
               // If the requirement has no body text, its SpaceAfter will be 3, so we adjust it here to 6
295
            shortDescRange.End = WordRange.Start-1;
318
               // just like what the body would have, if it were present.
296
            shortDescRange.set_Style( ref reqNameStyle );
319
               wr_desc.ParagraphFormat.SpaceAfter = 6;
-
 
320
            }
297
 
321
 
298
            appendAndSelectText( reqNotes, reqParaStyle );
-
 
299
            return true;
322
            return true;
300
            
323
            
301
         }
324
         }
302
 
325
 
303
         return false;
326
         return false;
304
      }
327
      }
305
 
328
 
306
 
329
 
307
 
330
 
308
	}
331
   }
309
}
332
}