Subversion Repositories DevTools

Rev

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

Rev 2106 Rev 2110
Line 1... Line 1...
1
using System;
1
using System;
2
using System.Collections;
2
using System.Collections;
-
 
3
using System.Text;
3
using Word;
4
using Word;
4
 
5
 
5
namespace EA_DocGen
6
namespace EA_DocGen
6
{
7
{
7
	/// <summary>
8
	/// <summary>
Line 40... Line 41...
40
            wr = appendAndSelectText("Description missing!", styleName, continuation);
41
            wr = appendAndSelectText("Description missing!", styleName, continuation);
41
            // For some wierd reason, if continuing on same paragraph, we have to decrement the range start by 1
42
            // For some wierd reason, if continuing on same paragraph, we have to decrement the range start by 1
42
            // otherwise the D of Description, does not get the red color or italic style
43
            // otherwise the D of Description, does not get the red color or italic style
43
            if (continuation)
44
            if (continuation)
44
               wr.Start--;
45
               wr.Start--;
-
 
46
            if (wr.Characters.Last.Text.Equals("\r"))
-
 
47
               wr.End = wr.End - 1;  // dont italicise the \r char at the end
45
            wr.Font.Italic = 1;
48
            wr.Font.Italic = 1;
46
            wr.Font.Color = Word.WdColor.wdColorRed;
49
            wr.Font.Color = Word.WdColor.wdColorRed;
47
         }
50
         }
48
         return wr;
51
         return wr;
49
      }
52
      }
Line 78... Line 81...
78
 
81
 
79
            WordRange = createWordDoc.WordDocument.Range(ref startLocation, ref endLocation);
82
            WordRange = createWordDoc.WordDocument.Range(ref startLocation, ref endLocation);
80
 
83
 
81
            if (!continuation)
84
            if (!continuation)
82
               WordRange.InsertAfter( "\n" );
85
               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
 
84
            WordRange.InsertAfter( wordText );
94
            WordRange.InsertAfter( wordText );
85
 
95
 
86
            // Make a range out of the pasted text
96
            // Make a range out of the pasted text
87
            startLocation = i;
97
            startLocation = i;
88
            endLocation = createWordDoc.WordDocument.Content.End;
98
            endLocation = createWordDoc.WordDocument.Content.End;
Line 180... Line 190...
180
               }
190
               }
181
            }
191
            }
182
            else
192
            else
183
            {
193
            {
184
               Word.Range wr = appendAndSelectText("Test Cases missing!", EA_Constants.styleName_Body1);
194
               Word.Range wr = appendAndSelectText("Test Cases missing!", EA_Constants.styleName_Body1);
-
 
195
               if (wr.Characters.Last.Text.Equals("\r"))
-
 
196
                  wr.End = wr.End - 1;  // dont italicise the \r char at the end
185
               wr.Font.Italic = 1;
197
               wr.Font.Italic = 1;
186
               wr.Font.Color = Word.WdColor.wdColorRed;
198
               wr.Font.Color = Word.WdColor.wdColorRed;
187
            }
199
            }
188
         }
200
         }
189
      }
201
      }
Line 225... Line 237...
225
         createWordDoc.WordApp.Selection.EndKey(ref unit, ref extend);
237
         createWordDoc.WordApp.Selection.EndKey(ref unit, ref extend);
226
      }
238
      }
227
 
239
 
228
 
240
 
229
      /// <summary>
241
      /// <summary>
230
      /// Generates the text for requirements.  This uses custom styles to format the text 
242
      /// Generates the text for requirements.  
231
      /// rather than formatting it in code.
-
 
232
      /// </summary>
243
      /// </summary>
233
      public static bool generateRequirementText( EA.Element theElement )
244
      public static bool generateRequirementText( EA.Element theElement )
234
      {
245
      {
235
         if ( theElement.Type.StartsWith("Requirement"))
246
         if ( theElement.Type.StartsWith("Requirement"))
236
         {
247
         {
Line 262... Line 273...
262
                  reqHeadingStyle = EA_Constants.styleName_ReqAppHdr;
273
                  reqHeadingStyle = EA_Constants.styleName_ReqAppHdr;
263
                  reqParaStyle    = EA_Constants.styleName_ReqAppBody;
274
                  reqParaStyle    = EA_Constants.styleName_ReqAppBody;
264
                  break;
275
                  break;
265
            }
276
            }
266
 
277
 
-
 
278
            // A requirement name is assumed to consist of:
-
 
279
            //
-
 
280
            //    <ID> [ShortDescription]
-
 
281
            //
-
 
282
            // Where <ID> is defined as
-
 
283
            //
-
 
284
            //    <TAG>n[subLevel]
-
 
285
            //
-
 
286
            // Where n is a numeric integer and sublevel is defined as
-
 
287
            //
-
 
288
            //    .n[sublevel]
-
 
289
            // 
-
 
290
            // Some examples
-
 
291
            //    SPR1  My Requirement
-
 
292
            //    SPR1.1 My Sub-requirement
-
 
293
            //    SPR1.1.1 My Sub-requirements Sub-Requirement
-
 
294
            //    CR1
-
 
295
            // 
-
 
296
            // Also, it is assumed that the element notes contains a long description
-
 
297
            // of the requirement.
-
 
298
 
267
            // Pull out the ID from the name
299
            // Pull out the ID from the name
268
            int pos = theElement.Name.IndexOf( " ", 0, theElement.Name.Length );
300
            int pos = theElement.Name.IndexOf( " ", 0, theElement.Name.Length );
269
            if (pos > 0)
301
            if (pos > 0)
-
 
302
            {
270
               reqID = theElement.Name.Substring( 0, pos );
303
               reqID = theElement.Name.Substring( 0, pos );
-
 
304
            }
271
 
305
 
-
 
306
            // Count '.' chars in the ID in order to support the progressive indentation 
272
            // Count '.' chars in the ID
307
            // of lower level requirements in the generated document
273
            int numDots = 0;
308
            int numDots = 0;
274
            foreach (char c in reqID)
309
            foreach (char c in reqID)
275
            {
310
            {
276
               if (c == '.')
311
               if (c == '.')
277
                  numDots++;
312
                  numDots++;
278
            }
313
            }
279
 
314
 
280
            // Calculate what the left/hanging indent should be based on the standard 2.5 cm plus a 
315
            // Calculate what the left/hanging indent should be based on the standard 2.5 cm plus 
281
            // factor derived from the number of dots in the ID
316
            // 0.5cm * number of dots in the ID
-
 
317
            // Do calculation directly in points (72 points per inch) to avoid having to call
-
 
318
            // CentimetersToPoints repeatedly in the word app com object, which I have seen
-
 
319
            // cause unspecified exceptions on rare occasions.
-
 
320
            float indent_pts = (float)70.866;
-
 
321
            if (numDots > 0)
-
 
322
            {
282
            float indent_cm = (float)(2.5 + (0.5 * numDots));
323
               indent_pts += (float)(14.1732 * numDots);
-
 
324
            }
283
 
325
 
284
            // Pull out the short description from the rest of the name
326
            // Pull out the short description from the rest of the name. If the short description
-
 
327
            // does not exist, substitute in its place, the element notes.
-
 
328
            bool doneNotes = false;
285
            reqShortDesc = theElement.Name.Substring( pos, theElement.Name.Length-pos );
329
            reqShortDesc = theElement.Name.Substring( pos, theElement.Name.Length-pos );
286
            reqShortDesc = reqShortDesc.Trim();
330
            reqShortDesc = reqShortDesc.Trim();
-
 
331
            if (reqShortDesc.Length == 0)
-
 
332
            {
-
 
333
               // If there is no short description, then use the element notes instead
-
 
334
               doneNotes = true;
-
 
335
               if (theElement.Notes != null && theElement.Notes.Length > 0)
-
 
336
               {
-
 
337
                  reqShortDesc = theElement.Notes;
-
 
338
               }
-
 
339
            }
287
 
340
 
288
            // Add the text
341
            // Add the ID to the document
289
            Word.Range wr_id = appendAndSelectText( reqID + '\t', reqHeadingStyle );
342
            Word.Range wr_id = appendAndSelectText( reqID + '\t', reqHeadingStyle );
290
 
343
            
-
 
344
            // Add the short description to the document
291
            Word.Range wr_desc = appendAndSelectText( reqShortDesc, reqHeadingStyle, true );
345
            Word.Range wr_desc = appendAndSelectText( reqShortDesc, reqHeadingStyle, true );
-
 
346
            if (wr_desc != null)
-
 
347
            {
-
 
348
               // Bold the short description, but only if the element notes have not been used
-
 
349
               // as the short description. Element notes may contain a lot of text and having
-
 
350
               // it all bolded can make the document look a little too busy, and the reader
-
 
351
               // may lose sight of the real document headings which are ofcoarse naturally bolded.
292
 
352
 
-
 
353
               wr_desc.Start = wr_desc.Start-1;  //compensate for problem in appendAndSelectText();
293
            //Bold the short description
354
               if (!doneNotes)
-
 
355
               {
294
            wr_desc.Start = wr_desc.Start-1;
356
                  if (wr_desc.Characters.Last.Text.Equals("\r"))
-
 
357
                     wr_desc.End = wr_desc.End - 1;   // Dont boldise the \r paragraph marker
295
            wr_desc.Font.Bold = 1;
358
                  wr_desc.Font.Bold = 1;
-
 
359
               }
296
 
360
 
297
            // Indent according to the number of dots in the tag
361
               // Indent according to the number of dots in the tag
298
            if (numDots > 0)
362
               if (numDots > 0)
299
            {
363
               {
300
               wr_desc.ParagraphFormat.LeftIndent      =  createWordDoc.WordApp.CentimetersToPoints(indent_cm);
364
                  wr_desc.ParagraphFormat.LeftIndent      = indent_pts;
-
 
365
 
301
               wr_desc.ParagraphFormat.FirstLineIndent = -createWordDoc.WordApp.CentimetersToPoints(indent_cm);
366
                  wr_desc.ParagraphFormat.FirstLineIndent = -indent_pts;
-
 
367
               }
302
            }
368
            }
303
 
369
 
304
            // Add requirement notes/body, if there is any
370
            // Add requirement notes/body, if we have not already consumed them for the
-
 
371
            // short description
305
            if (theElement.Notes != null && theElement.Notes.Length > 0)
372
            if (!doneNotes && theElement.Notes != null && theElement.Notes.Length > 0)
306
            {
373
            {
307
               Word.Range wr_body = appendAndSelectText( theElement.Notes, reqParaStyle );
374
               Word.Range wr_body = appendAndSelectText( theElement.Notes, reqParaStyle );
308
 
375
 
309
               // indent according to the number of dots in the tag
376
               // indent according to the number of dots in the tag
310
               if (numDots > 0)
377
               if (numDots > 0)
311
               {
378
               {
312
                  wr_body.ParagraphFormat.LeftIndent = createWordDoc.WordApp.CentimetersToPoints( indent_cm );
379
                  wr_body.ParagraphFormat.LeftIndent = indent_pts;
313
               }
380
               }
314
            }
381
            }
315
            else
382
            else
316
            {
383
            {
317
               // If the requirement has no body text, its SpaceAfter will be 3, so we adjust it here to 6
384
               // If the requirement has no body text, its SpaceAfter will be 3, so we adjust it here to 6
318
               // just like what the body would have, if it were present.
385
               // just like what the body would have, if it were present.
-
 
386
               if (wr_desc != null)
319
               wr_desc.ParagraphFormat.SpaceAfter = 6;
387
                  wr_desc.ParagraphFormat.SpaceAfter = 6;
-
 
388
               else if (wr_id != null)
-
 
389
                  wr_id.ParagraphFormat.SpaceAfter = 6;
-
 
390
            }
-
 
391
 
-
 
392
            // tack on the end a source reference for the requirement, if it contains one
-
 
393
            // as evidenced by tagged values
-
 
394
            string src = EA_Utilities.ReadTag(theElement, "SOURCE");
-
 
395
            if (src.Length > 0)
-
 
396
            {
-
 
397
               StringBuilder sb = new StringBuilder();
-
 
398
 
-
 
399
               string srcVer = EA_Utilities.ReadTag(theElement, "SOURCE_VERSION");
-
 
400
               sb.Append("[");
-
 
401
               sb.Append(src);
-
 
402
 
-
 
403
               if (srcVer.Length > 0)
-
 
404
               {
-
 
405
                  sb.Append(" v");
-
 
406
                  sb.Append(srcVer);
-
 
407
               }
-
 
408
 
-
 
409
               string srcSect = EA_Utilities.ReadTag(theElement, "SOURCE_SECTION");
-
 
410
               if (srcSect.Length > 0)
-
 
411
               {
-
 
412
                  sb.Append(" section ");
-
 
413
                  sb.Append(srcSect);
-
 
414
               }
-
 
415
               sb.Append("]");
-
 
416
 
-
 
417
               Word.Range wrs_body = appendAndSelectText(sb.ToString(), reqParaStyle);
-
 
418
               if (wrs_body.Characters.Last.Text.Equals("\r"))
-
 
419
                  wrs_body.End = wrs_body.End - 1;  // dont italicise the \r char at the end - doing so causes wierd ms-word exceptions later on
-
 
420
               wrs_body.Font.Italic = 1;
-
 
421
               if (numDots > 0)
-
 
422
               {
-
 
423
                  wrs_body.ParagraphFormat.LeftIndent = indent_pts;
-
 
424
               }
320
            }
425
            }
321
 
426
 
322
            return true;
427
            return true;
323
            
428
            
324
         }
429
         }
325
 
430
 
326
         return false;
431
         return false;
327
      }
432
      }
328
 
433
 
329
 
-
 
330
 
-
 
331
   }
434
   }
332
}
435
}