Subversion Repositories DevTools

Rev

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

Rev 2124 Rev 2126
Line 37... Line 37...
37
            wr = appendAndSelectText(wordText, styleName, continuation);
37
            wr = appendAndSelectText(wordText, styleName, continuation);
38
         }
38
         }
39
         else if (!EA_DocGenOptions.optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_ELEMENT_DESC_MISSING_WARNINGS))
39
         else if (!EA_DocGenOptions.optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_ELEMENT_DESC_MISSING_WARNINGS))
40
         {
40
         {
41
            wr = appendAndSelectText("Description missing!", styleName, continuation);
41
            wr = appendAndSelectText("Description missing!", styleName, continuation);
42
            // For some wierd reason, if continuing on same paragraph, we have to decrement the range start by 1
-
 
43
            // otherwise the D of Description, does not get the red color or italic style
-
 
44
            if (continuation)
-
 
45
               wr.Start--;
-
 
-
 
42
 
46
            if (wr.Characters.Last.Text.Equals("\r"))
43
            if (wr.Characters.Last.Text.Equals("\r"))
47
               wr.End = wr.End - 1;  // dont italicise the \r char at the end
44
               wr.End = wr.End - 1;  // dont italicise the \r char at the end
48
            wr.Font.Italic = 1;
45
            wr.Font.Italic = 1;
49
            wr.Font.Color = Word.WdColor.wdColorRed;
46
            wr.Font.Color = Word.WdColor.wdColorRed;
50
         }
47
         }
51
         return wr;
48
         return wr;
52
      }
49
      }
53
 
50
 
54
 
51
 
55
      
52
 
56
      /// <summary>
53
      /// <summary>
57
      /// Appends a specified text string to the word document, selects the new text, and applies
54
      /// Appends a specified text string to the word document, selects the new text, and applies
58
      /// the specified style formatting to it.
55
      /// the specified style formatting to it.
59
      /// </summary>
56
      /// </summary>
60
      /// <param name="wordText"></param>
57
      /// <param name="wordText"></param>
61
      /// <param name="styleText"></param>
58
      /// <param name="styleText"></param>
62
      /// <param name="continuation"></param>
59
      /// <param name="continuation"></param>
63
      public static Word.Range appendAndSelectText(string wordText, string styleText) 
60
      public static Word.Range appendAndSelectText(string wordText, string styleText)
64
      { 
61
      {
65
         return appendAndSelectText(wordText, styleText, false );
62
         return appendAndSelectText(wordText, styleText, false );
66
      }
63
      }
67
 
64
 
68
 
65
 
69
      public static Word.Range appendAndSelectText(string wordText, string styleText, bool continuation )
66
      public static Word.Range appendAndSelectText(string wordText, string styleText, bool continuation )
Line 82... Line 79...
82
            WordRange = createWordDoc.WordDocument.Range(ref startLocation, ref endLocation);
79
            WordRange = createWordDoc.WordDocument.Range(ref startLocation, ref endLocation);
83
 
80
 
84
            if (!continuation)
81
            if (!continuation)
85
               WordRange.InsertAfter( "\n" );
82
               WordRange.InsertAfter( "\n" );
86
 
83
 
87
            // TODO
-
 
88
            // 1) need to fix the problem with range starting one-char too late when function is called
-
 
89
            //    with continuation = true.
-
 
90
            //    This will entail finding all the places that call the function with continuation
-
 
91
            //    set to true and making sure they do not compensate for the problem, and ofcoarse
-
 
92
            //    putting the compensation locally in here instead.
-
 
93
 
-
 
94
            WordRange.InsertAfter( wordText );
84
            WordRange.InsertAfter( wordText );
95
 
85
 
96
            // Make a range out of the pasted text
86
            // Make a range out of the pasted text
97
            startLocation = i;
87
            startLocation = i;
98
            endLocation = createWordDoc.WordDocument.Content.End;
88
            endLocation = createWordDoc.WordDocument.Content.End;
99
            WordRange = createWordDoc.WordDocument.Range(ref startLocation, ref endLocation);
89
            WordRange = createWordDoc.WordDocument.Range(ref startLocation, ref endLocation);
100
 
90
 
101
            // and set the pasted text style
91
            // and set the pasted text style
102
            WordRange.set_Style(ref style);
92
            WordRange.set_Style(ref style);
-
 
93
 
-
 
94
            // compensate for wierd off by one error in the range object when using continuation
-
 
95
            if (continuation)
-
 
96
                WordRange.Start--;
-
 
97
 
103
            return WordRange;
98
            return WordRange;
104
         }
99
         }
105
         return null;
100
         return null;
106
      }
101
      }
107
   
102
 
108
 
103
 
109
      /// <summary>
104
      /// <summary>
110
      /// Appends a specified text string to the word document, selects the new text, and applies
105
      /// Appends a specified text string to the word document, selects the new text, and applies
111
      /// a heading level style to it. 
106
      /// a heading level style to it.
112
      /// </summary>
107
      /// </summary>
113
      /// <param name="wordText"></param>
108
      /// <param name="wordText"></param>
114
      /// <param name="level"></param>
109
      /// <param name="level"></param>
115
      public static void appendAndSelectHeadingText(string wordText, int level)
110
      public static void appendAndSelectHeadingText(string wordText, int level)
116
      {
111
      {
Line 131... Line 126...
131
            case 6: styleText = EA_Constants.styleName_Heading6; break;
126
            case 6: styleText = EA_Constants.styleName_Heading6; break;
132
            case 7: styleText = EA_Constants.styleName_Heading7; break;
127
            case 7: styleText = EA_Constants.styleName_Heading7; break;
133
            case 8: styleText = EA_Constants.styleName_Heading8; break;
128
            case 8: styleText = EA_Constants.styleName_Heading8; break;
134
            case 9: styleText = EA_Constants.styleName_Heading9; break;
129
            case 9: styleText = EA_Constants.styleName_Heading9; break;
135
 
130
 
136
            default: 
131
            default:
137
               // MS-Word cannot produce headings above level 9 and so we have to 
132
               // MS-Word cannot produce headings above level 9 and so we have to
138
               // fake a heading by constructing it from our document section tracking data.
133
               // fake a heading by constructing it from our document section tracking data.
139
               styleText = EA_Constants.styleName_Heading10OrAbove;
134
               styleText = EA_Constants.styleName_Heading10OrAbove;
140
               wordText = DocSectionTracking.formHeadingString(wordText);
135
               wordText = DocSectionTracking.formHeadingString(wordText);
141
               break;
136
               break;
142
         }
137
         }
Line 144... Line 139...
144
         appendAndSelectText(wordText, styleText);
139
         appendAndSelectText(wordText, styleText);
145
      }
140
      }
146
 
141
 
147
      /// <summary>
142
      /// <summary>
148
      /// Appends a specified text string to the word document, selects the new text, and applies
143
      /// Appends a specified text string to the word document, selects the new text, and applies
149
      /// a numpara level style to it. 
144
      /// a numpara level style to it.
150
      /// </summary>
145
      /// </summary>
151
      /// <param name="wordText"></param>
146
      /// <param name="wordText"></param>
152
      /// <param name="level"></param>
147
      /// <param name="level"></param>
153
      public static void appendAndSelectNumParaText(string wordText, int level)
148
      public static void appendAndSelectNumParaText(string wordText, int level)
154
      {
149
      {
Line 169... Line 164...
169
            case 6: styleText = EA_Constants.styleName_NumPara6; break;
164
            case 6: styleText = EA_Constants.styleName_NumPara6; break;
170
            case 7: styleText = EA_Constants.styleName_NumPara7; break;
165
            case 7: styleText = EA_Constants.styleName_NumPara7; break;
171
            case 8: styleText = EA_Constants.styleName_NumPara8; break;
166
            case 8: styleText = EA_Constants.styleName_NumPara8; break;
172
            case 9: styleText = EA_Constants.styleName_NumPara9; break;
167
            case 9: styleText = EA_Constants.styleName_NumPara9; break;
173
 
168
 
174
            default: 
169
            default:
175
               // MS-Word cannot produce headings above level 9 and so we have to 
170
               // MS-Word cannot produce headings above level 9 and so we have to
176
               // fake a heading by constructing it from our document section tracking data.
171
               // fake a heading by constructing it from our document section tracking data.
177
               styleText = EA_Constants.styleName_NumPara10OrAbove;
172
               styleText = EA_Constants.styleName_NumPara10OrAbove;
178
               wordText = DocSectionTracking.formHeadingString(wordText);
173
               wordText = DocSectionTracking.formHeadingString(wordText);
179
               break;
174
               break;
180
         }
175
         }
Line 188... Line 183...
188
         if (s != null)
183
         if (s != null)
189
            return s.TrimEnd(trim_newlines);
184
            return s.TrimEnd(trim_newlines);
190
         else
185
         else
191
            return null;
186
            return null;
192
      }
187
      }
193
   
188
 
194
   
189
 
195
 
190
 
196
      public static string testSuiteName(EA.Element theElement)
191
      public static string testSuiteName(EA.Element theElement)
197
      {
192
      {
198
         return "Test Suite - " + theElement.Name;
193
         return "Test Suite - " + theElement.Name;
199
      }
194
      }
Line 278... Line 273...
278
      }
273
      }
279
 
274
 
280
 
275
 
281
      public static void SelectInsertionPointAtEndOfDocument()
276
      public static void SelectInsertionPointAtEndOfDocument()
282
      {
277
      {
283
         object unit; 
278
         object unit;
284
         object extend;
279
         object extend;
285
 
280
 
286
         unit = Word.WdUnits.wdStory; 
281
         unit = Word.WdUnits.wdStory;
287
         extend = Word.WdMovementType.wdMove;
282
         extend = Word.WdMovementType.wdMove;
288
         createWordDoc.WordApp.Selection.EndKey(ref unit, ref extend);
283
         createWordDoc.WordApp.Selection.EndKey(ref unit, ref extend);
289
      }
284
      }
290
 
285
 
291
 
286
 
292
      /// <summary>
287
      /// <summary>
293
      /// Generates the text for requirements.  
288
      /// Generates the text for requirements.
294
      /// </summary>
289
      /// </summary>
295
      public static bool generateRequirementText( EA.Element theElement )
290
      public static bool generateRequirementText( EA.Element theElement )
296
      {
291
      {
297
         if (theElement.Type.StartsWith("Requirement"))
292
         if (theElement.Type.StartsWith("Requirement"))
298
         {
293
         {
299
            string reqID = "";
294
            string reqID = "";
300
            string reqShortDesc = "";
295
            string reqShortDesc = "";
301
            string reqHeadingStyle ="";
296
            string reqHeadingStyle ="";
302
            string reqParaStyle = "";
297
            string reqParaStyle = "";
303
            
298
 
304
 
299
 
305
            // Set the style depending on the status
300
            // Set the style depending on the status
306
            switch ( theElement.Status )
301
            switch ( theElement.Status )
307
            {
302
            {
308
               case "Proposed":
303
               case "Proposed":
Line 335... Line 330...
335
            //    <TAG>n[subLevel]
330
            //    <TAG>n[subLevel]
336
            //
331
            //
337
            // Where n is a numeric integer and sublevel is defined as
332
            // Where n is a numeric integer and sublevel is defined as
338
            //
333
            //
339
            //    .n[sublevel]
334
            //    .n[sublevel]
340
            // 
335
            //
341
            // Some examples
336
            // Some examples
342
            //    SPR1  My Requirement
337
            //    SPR1  My Requirement
343
            //    SPR1.1 My Sub-requirement
338
            //    SPR1.1 My Sub-requirement
344
            //    SPR1.1.1 My Sub-requirements Sub-Requirement
339
            //    SPR1.1.1 My Sub-requirements Sub-Requirement
345
            //    CR1
340
            //    CR1
346
            // 
341
            //
347
            // Also, it is assumed that the element notes contains a long description
342
            // Also, it is assumed that the element notes contains a long description
348
            // of the requirement.
343
            // of the requirement.
349
 
344
 
350
            // Pull out the ID from the name
345
            // Pull out the ID from the name
351
            int pos = theElement.Name.IndexOf( " ", 0, theElement.Name.Length );
346
            int pos = theElement.Name.IndexOf( " ", 0, theElement.Name.Length );
352
            if (pos > 0)
347
            if (pos > 0)
353
            {
348
            {
354
               reqID = theElement.Name.Substring( 0, pos );
349
               reqID = theElement.Name.Substring( 0, pos );
355
            }
350
            }
356
 
351
 
357
            // Count '.' chars in the ID in order to support the progressive indentation 
352
            // Count '.' chars in the ID in order to support the progressive indentation
358
            // of lower level requirements in the generated document
353
            // of lower level requirements in the generated document
359
            int numDots = 0;
354
            int numDots = 0;
360
            foreach (char c in reqID)
355
            foreach (char c in reqID)
361
            {
356
            {
362
               if (c == '.')
357
               if (c == '.')
363
                  numDots++;
358
                  numDots++;
364
            }
359
            }
365
 
360
 
366
            // Calculate what the left/hanging indent should be based on the standard 2.5 cm plus 
361
            // Calculate what the left/hanging indent should be based on the standard 2.5 cm plus
367
            // 0.5cm * number of dots in the ID
362
            // 0.5cm * number of dots in the ID
368
            // Do calculation directly in points (72 points per inch) to avoid having to call
363
            // Do calculation directly in points (72 points per inch) to avoid having to call
369
            // CentimetersToPoints repeatedly in the word app com object, which I have seen
364
            // CentimetersToPoints repeatedly in the word app com object, which I have seen
370
            // cause unspecified exceptions on rare occasions.
365
            // cause unspecified exceptions on rare occasions.
371
            float indent_pts = (float)70.866;
366
            float indent_pts = (float)70.866;
Line 389... Line 384...
389
               }
384
               }
390
            }
385
            }
391
 
386
 
392
            // Add the ID to the document
387
            // Add the ID to the document
393
            Word.Range wr_id = appendAndSelectText( reqID + '\t', reqHeadingStyle );
388
            Word.Range wr_id = appendAndSelectText( reqID + '\t', reqHeadingStyle );
394
            
389
 
395
            // Add the short description to the document
390
            // Add the short description to the document
396
            Word.Range wr_desc = appendAndSelectText( reqShortDesc, reqHeadingStyle, true );
391
            Word.Range wr_desc = appendAndSelectText( reqShortDesc, reqHeadingStyle, true );
397
            if (wr_desc != null)
392
            if (wr_desc != null)
398
            {
393
            {
399
               // Bold the short description, but only if the element notes have not been used
394
               // Bold the short description, but only if the element notes have not been used
400
               // as the short description. Element notes may contain a lot of text and having
395
               // as the short description. Element notes may contain a lot of text and having
401
               // it all bolded can make the document look a little too busy, and the reader
396
               // it all bolded can make the document look a little too busy, and the reader
402
               // may lose sight of the real document headings which are ofcoarse naturally bolded.
397
               // may lose sight of the real document headings which are ofcoarse naturally bolded.
403
 
398
 
404
               wr_desc.Start = wr_desc.Start-1;  //compensate for problem in appendAndSelectText();
-
 
405
               if (!doneNotes)
399
               if (!doneNotes)
406
               {
400
               {
407
                  if (wr_desc.Characters.Last.Text.Equals("\r"))
401
                  if (wr_desc.Characters.Last.Text.Equals("\r"))
408
                     wr_desc.End = wr_desc.End - 1;   // Dont boldise the \r paragraph marker
402
                     wr_desc.End = wr_desc.End - 1;   // Dont boldise the \r paragraph marker
409
                  wr_desc.Font.Bold = 1;
403
                  wr_desc.Font.Bold = 1;
Line 420... Line 414...
420
 
414
 
421
            // Add requirement notes/body, if we have not already consumed them for the
415
            // Add requirement notes/body, if we have not already consumed them for the
422
            // short description
416
            // short description
423
            if (!doneNotes && theElement.Notes != null && theElement.Notes.Length > 0 && !EA_DocGenOptions.optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_REQUIREMENT_NOTES))
417
            if (!doneNotes && theElement.Notes != null && theElement.Notes.Length > 0 && !EA_DocGenOptions.optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_REQUIREMENT_NOTES))
424
            {
418
            {
425
               Word.Range wr_body = appendAndSelectText( theElement.Notes, reqParaStyle );
419
               Word.Range wr_body = appendAndSelectText( "\n", reqParaStyle );
426
 
420
 
427
               // indent according to the number of dots in the tag
-
 
428
               if (numDots > 0)
-
 
429
               {
-
 
430
                  wr_body.ParagraphFormat.LeftIndent = indent_pts;
421
               TextParser.parse(theElement.Notes, theElement.ElementID, reqParaStyle, numDots > 0 ? indent_pts:0, false );
431
               }
-
 
432
            }
422
            }
433
            else
423
            else
434
            {
424
            {
435
               // If the requirement has no body text, its SpaceAfter will be 3, so we adjust it here to 6
425
               // If the requirement has no body text, its SpaceAfter will be 3, so we adjust it here to 6
436
               // just like what the body would have, if it were present.
426
               // just like what the body would have, if it were present.
Line 474... Line 464...
474
                  wrs_body.ParagraphFormat.LeftIndent = indent_pts;
464
                  wrs_body.ParagraphFormat.LeftIndent = indent_pts;
475
               }
465
               }
476
            }
466
            }
477
 
467
 
478
            return true;
468
            return true;
479
            
469
 
480
         }
470
         }
481
 
471
 
482
         return false;
472
         return false;
483
      }
473
      }
484
 
474