| Line 2... |
Line 2... |
| 2 |
using System.Drawing;
|
2 |
using System.Drawing;
|
| 3 |
using System.Collections;
|
3 |
using System.Collections;
|
| 4 |
using System.ComponentModel;
|
4 |
using System.ComponentModel;
|
| 5 |
using System.Windows.Forms;
|
5 |
using System.Windows.Forms;
|
| 6 |
using Word;
|
6 |
using Word;
|
| - |
|
7 |
using Microsoft.Office.Core;
|
| - |
|
8 |
|
| 7 |
|
9 |
|
| 8 |
namespace EA_DocGen
|
10 |
namespace EA_DocGen
|
| 9 |
{
|
11 |
{
|
| 10 |
|
12 |
|
| 11 |
|
13 |
|
| Line 31... |
Line 33... |
| 31 |
private object endLocation;
|
33 |
private object endLocation;
|
| 32 |
|
34 |
|
| 33 |
private int[] DocSection = null;
|
35 |
private int[] DocSection = null;
|
| 34 |
private int iDocSection = 0;
|
36 |
private int iDocSection = 0;
|
| 35 |
|
37 |
|
| - |
|
38 |
// Some style names used in EA_DocGen - most are expected to exist in the input template/doc
|
| - |
|
39 |
// but the Requirement formatting styles are programmatcally generated if they are found to not
|
| - |
|
40 |
// exist. The reason for this is that as of writing this add-in, they do not exist in the ERG
|
| - |
|
41 |
// standard template.
|
| - |
|
42 |
private const string styleName_ReqAppBody = "Requirements Approved Body";
|
| - |
|
43 |
private const string styleName_ReqAppHdr = "Requirements Approved Heading";
|
| - |
|
44 |
private const string styleName_ReqPropBody = "Requirements Proposed Body";
|
| - |
|
45 |
private const string styleName_ReqPropHdr = "Requirements Proposed Heading";
|
| - |
|
46 |
private const string styleName_ReqRejBody = "Requirements Rejected Body";
|
| - |
|
47 |
private const string styleName_ReqRejHdr = "Requirements Rejected Heading";
|
| - |
|
48 |
private const string styleName_ReqName = "Requirements Name";
|
| - |
|
49 |
private const string styleName_Body1 = "Body 1";
|
| - |
|
50 |
private const string styleName_Heading1 = "Heading 1";
|
| - |
|
51 |
private const string styleName_Heading2 = "Heading 2";
|
| - |
|
52 |
private const string styleName_Heading3 = "Heading 3";
|
| - |
|
53 |
private const string styleName_Heading4 = "Heading 4";
|
| - |
|
54 |
private const string styleName_Heading5 = "Heading 5";
|
| - |
|
55 |
private const string styleName_Heading6 = "Heading 6";
|
| - |
|
56 |
private const string styleName_Heading7 = "Heading 7";
|
| - |
|
57 |
private const string styleName_Heading8 = "Heading 8";
|
| - |
|
58 |
private const string styleName_Heading9 = "Heading 9";
|
| - |
|
59 |
private const string styleName_NumPara1 = "NumPara 1";
|
| - |
|
60 |
private const string styleName_NumPara2 = "NumPara 2";
|
| - |
|
61 |
private const string styleName_NumPara3 = "NumPara 3";
|
| - |
|
62 |
private const string styleName_NumPara4 = "NumPara 4";
|
| - |
|
63 |
private const string styleName_NumPara5 = "NumPara 5";
|
| - |
|
64 |
private const string styleName_NumPara6 = "NumPara 6";
|
| - |
|
65 |
private const string styleName_NumPara7 = "NumPara 7";
|
| - |
|
66 |
private const string styleName_NumPara8 = "NumPara 8";
|
| - |
|
67 |
private const string styleName_NumPara9 = "NumPara 9";
|
| - |
|
68 |
private const string styleName_TableText = "Table Text";
|
| - |
|
69 |
private const string styleName_RefListNum = "Reference List Number";
|
| - |
|
70 |
private const string styleName_RefListText = "Reference List Text";
|
| - |
|
71 |
private const string styleName_Normal = "Normal";
|
| - |
|
72 |
|
| - |
|
73 |
|
| 36 |
private System.Windows.Forms.TextBox textBox_template;
|
74 |
private System.Windows.Forms.TextBox textBox_template;
|
| 37 |
private System.Windows.Forms.Button button_browse_template;
|
75 |
private System.Windows.Forms.Button button_browse_template;
|
| 38 |
private System.Windows.Forms.TextBox textBox_output_file;
|
76 |
private System.Windows.Forms.TextBox textBox_output_file;
|
| 39 |
private System.Windows.Forms.Button button_browse_output_file;
|
77 |
private System.Windows.Forms.Button button_browse_output_file;
|
| 40 |
private System.Windows.Forms.Button button_cancel;
|
78 |
private System.Windows.Forms.Button button_cancel;
|
| Line 425... |
Line 463... |
| 425 |
|
463 |
|
| 426 |
// Paste the diagram into the document
|
464 |
// Paste the diagram into the document
|
| 427 |
WordRange.Paste();
|
465 |
WordRange.Paste();
|
| 428 |
|
466 |
|
| 429 |
// Set style of the diagram to "Normal" so that it can occupy space all the way to the left margin
|
467 |
// Set style of the diagram to "Normal" so that it can occupy space all the way to the left margin
|
| 430 |
object l_style = "Normal";
|
468 |
object l_style = styleName_Normal;
|
| 431 |
endLocation = WordDocument.Content.End;
|
469 |
endLocation = WordDocument.Content.End;
|
| 432 |
WordRange = WordDocument.Range(ref startLocation, ref endLocation);
|
470 |
WordRange = WordDocument.Range(ref startLocation, ref endLocation);
|
| 433 |
WordRange.set_Style(ref l_style);
|
471 |
WordRange.set_Style(ref l_style);
|
| 434 |
|
472 |
|
| 435 |
// Center the diagram on the page
|
473 |
// Center the diagram on the page
|
| Line 510... |
Line 548... |
| 510 |
/// <param name="wordText"></param>
|
548 |
/// <param name="wordText"></param>
|
| 511 |
/// <param name="level"></param>
|
549 |
/// <param name="level"></param>
|
| 512 |
private void appendAndSelectHeadingText(string wordText, int level)
|
550 |
private void appendAndSelectHeadingText(string wordText, int level)
|
| 513 |
{
|
551 |
{
|
| 514 |
// Convert level to heading style
|
552 |
// Convert level to heading style
|
| 515 |
String styleText;
|
553 |
string styleText;
|
| 516 |
switch(level)
|
554 |
switch(level)
|
| 517 |
{
|
555 |
{
|
| 518 |
case 1: styleText = "Heading 1"; break;
|
556 |
case 1: styleText = styleName_Heading1; break;
|
| 519 |
case 2: styleText = "Heading 2"; break;
|
557 |
case 2: styleText = styleName_Heading2; break;
|
| 520 |
case 3: styleText = "Heading 3"; break;
|
558 |
case 3: styleText = styleName_Heading3; break;
|
| 521 |
case 4: styleText = "Heading 4"; break;
|
559 |
case 4: styleText = styleName_Heading4; break;
|
| 522 |
case 5: styleText = "Heading 5"; break;
|
560 |
case 5: styleText = styleName_Heading5; break;
|
| 523 |
case 6: styleText = "Heading 6"; break;
|
561 |
case 6: styleText = styleName_Heading6; break;
|
| 524 |
case 7: styleText = "Heading 7"; break;
|
562 |
case 7: styleText = styleName_Heading7; break;
|
| 525 |
case 8: styleText = "Heading 8"; break;
|
563 |
case 8: styleText = styleName_Heading8; break;
|
| 526 |
case 9: styleText = "Heading 9"; break;
|
564 |
case 9: styleText = styleName_Heading9; break;
|
| 527 |
default: styleText = "Body 1"; break;
|
565 |
default: styleText = styleName_Heading9; break;
|
| 528 |
}
|
566 |
}
|
| 529 |
// append the text as a heading
|
567 |
// append the text as a heading
|
| 530 |
appendAndSelectText(wordText, styleText);
|
568 |
appendAndSelectText(wordText, styleText);
|
| 531 |
}
|
569 |
}
|
| 532 |
|
570 |
|
| Line 538... |
Line 576... |
| 538 |
/// <param name="wordText"></param>
|
576 |
/// <param name="wordText"></param>
|
| 539 |
/// <param name="level"></param>
|
577 |
/// <param name="level"></param>
|
| 540 |
private void appendAndSelectNumParaText(string wordText, int level)
|
578 |
private void appendAndSelectNumParaText(string wordText, int level)
|
| 541 |
{
|
579 |
{
|
| 542 |
// Convert level to heading style
|
580 |
// Convert level to heading style
|
| 543 |
String styleText;
|
581 |
string styleText;
|
| 544 |
switch(level)
|
582 |
switch(level)
|
| 545 |
{
|
583 |
{
|
| 546 |
case 1: styleText = "NumPara 1"; break;
|
584 |
case 1: styleText = styleName_NumPara1; break;
|
| 547 |
case 2: styleText = "NumPara 2"; break;
|
585 |
case 2: styleText = styleName_NumPara2; break;
|
| 548 |
case 3: styleText = "NumPara 3"; break;
|
586 |
case 3: styleText = styleName_NumPara3; break;
|
| 549 |
case 4: styleText = "NumPara 4"; break;
|
587 |
case 4: styleText = styleName_NumPara4; break;
|
| 550 |
case 5: styleText = "NumPara 5"; break;
|
588 |
case 5: styleText = styleName_NumPara5; break;
|
| 551 |
case 6: styleText = "NumPara 6"; break;
|
589 |
case 6: styleText = styleName_NumPara6; break;
|
| 552 |
case 7: styleText = "NumPara 7"; break;
|
590 |
case 7: styleText = styleName_NumPara7; break;
|
| 553 |
case 8: styleText = "NumPara 8"; break;
|
591 |
case 8: styleText = styleName_NumPara8; break;
|
| 554 |
case 9: styleText = "NumPara 9"; break;
|
592 |
case 9: styleText = styleName_NumPara9; break;
|
| 555 |
default: styleText = "Body 1"; break;
|
593 |
default: styleText = styleName_NumPara9; break;
|
| 556 |
}
|
594 |
}
|
| 557 |
// append the text as a heading
|
595 |
// append the text as a heading
|
| 558 |
appendAndSelectText(wordText, styleText);
|
596 |
appendAndSelectText(wordText, styleText);
|
| 559 |
}
|
597 |
}
|
| 560 |
|
598 |
|
| Line 604... |
Line 642... |
| 604 |
Table.Rows[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray10;
|
642 |
Table.Rows[1].Shading.BackgroundPatternColor = Word.WdColor.wdColorGray10;
|
| 605 |
Table.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
|
643 |
Table.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
|
| 606 |
Table.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
|
644 |
Table.Borders.InsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
|
| 607 |
|
645 |
|
| 608 |
Table.Select();
|
646 |
Table.Select();
|
| 609 |
object tableTextStyle = "Table Text";
|
647 |
object tableTextStyle = styleName_TableText;
|
| 610 |
Table.Range.set_Style( ref tableTextStyle );
|
648 |
Table.Range.set_Style( ref tableTextStyle );
|
| 611 |
|
649 |
|
| 612 |
return WordDocument.Tables.Count;
|
650 |
return WordDocument.Tables.Count;
|
| 613 |
}
|
651 |
}
|
| 614 |
|
652 |
|
| Line 877... |
Line 915... |
| 877 |
/// </summary>
|
915 |
/// </summary>
|
| 878 |
/// <param name="theElement"></param>
|
916 |
/// <param name="theElement"></param>
|
| 879 |
/// <param name="recurse_level"></param>
|
917 |
/// <param name="recurse_level"></param>
|
| 880 |
private void processTextElement(EA.Element theElement, int recurse_level )
|
918 |
private void processTextElement(EA.Element theElement, int recurse_level )
|
| 881 |
{
|
919 |
{
|
| 882 |
appendAndSelectText( theElement.Notes.ToString(), "Body 1" );
|
920 |
appendAndSelectText( theElement.Notes.ToString(), styleName_Body1 );
|
| 883 |
}
|
921 |
}
|
| 884 |
|
922 |
|
| 885 |
|
923 |
|
| 886 |
|
924 |
|
| 887 |
|
925 |
|
| Line 894... |
Line 932... |
| 894 |
{
|
932 |
{
|
| 895 |
foreach(EA.Element theElement in thePackage.Elements)
|
933 |
foreach(EA.Element theElement in thePackage.Elements)
|
| 896 |
{
|
934 |
{
|
| 897 |
// Here we want to apply the special ERG template styles for each reference
|
935 |
// Here we want to apply the special ERG template styles for each reference
|
| 898 |
// item.
|
936 |
// item.
|
| 899 |
appendAndSelectText( theElement.Name.ToString(), "Reference List Number" );
|
937 |
appendAndSelectText( theElement.Name.ToString(), styleName_RefListNum );
|
| 900 |
appendAndSelectText( theElement.Notes.ToString(), "Reference List Text" );
|
938 |
appendAndSelectText( theElement.Notes.ToString(), styleName_RefListText );
|
| 901 |
}
|
939 |
}
|
| 902 |
}
|
940 |
}
|
| 903 |
|
941 |
|
| 904 |
|
942 |
|
| 905 |
private void createTerminologySection(EA.Package thePackage)
|
943 |
private void createTerminologySection(EA.Package thePackage)
|
| Line 973... |
Line 1011... |
| 973 |
appendAndSelectHeadingText( thePackage.Name.ToString(), recurse_level );
|
1011 |
appendAndSelectHeadingText( thePackage.Name.ToString(), recurse_level );
|
| 974 |
|
1012 |
|
| 975 |
// Special handling for package called "Terminology"
|
1013 |
// Special handling for package called "Terminology"
|
| 976 |
if (thePackage.Name == "Terminology")
|
1014 |
if (thePackage.Name == "Terminology")
|
| 977 |
{
|
1015 |
{
|
| 978 |
appendAndSelectText( thePackage.Notes.ToString(), "Body 1" );
|
1016 |
appendAndSelectText( thePackage.Notes.ToString(), styleName_Body1 );
|
| 979 |
createTerminologySection(thePackage);
|
1017 |
createTerminologySection(thePackage);
|
| 980 |
return true;
|
1018 |
return true;
|
| 981 |
}
|
1019 |
}
|
| 982 |
|
1020 |
|
| 983 |
if (thePackage.Name == "References")
|
1021 |
if (thePackage.Name == "References")
|
| 984 |
{
|
1022 |
{
|
| 985 |
appendAndSelectText( thePackage.Notes.ToString(), "Body 1" );
|
1023 |
appendAndSelectText( thePackage.Notes.ToString(), styleName_Body1 );
|
| 986 |
createReferencesSection(thePackage);
|
1024 |
createReferencesSection(thePackage);
|
| 987 |
return true;
|
1025 |
return true;
|
| 988 |
}
|
1026 |
}
|
| 989 |
|
1027 |
|
| 990 |
// use the package notes as body text and indicate to caller that package elements
|
1028 |
// use the package notes as body text and indicate to caller that package elements
|
| 991 |
// have not been consumed
|
1029 |
// have not been consumed
|
| 992 |
appendAndSelectText( thePackage.Notes.ToString(), "Body 1" );
|
1030 |
appendAndSelectText( thePackage.Notes.ToString(), styleName_Body1 );
|
| 993 |
return false;
|
1031 |
return false;
|
| 994 |
}
|
1032 |
}
|
| 995 |
|
1033 |
|
| 996 |
|
1034 |
|
| 997 |
private void generatePackageDiagrams( EA.Package thePackage )
|
1035 |
private void generatePackageDiagrams( EA.Package thePackage )
|
| Line 1030... |
Line 1068... |
| 1030 |
&& EA_Utils.options.opt_DisplayRequirementElementsAsSections == false )
|
1068 |
&& EA_Utils.options.opt_DisplayRequirementElementsAsSections == false )
|
| 1031 |
{
|
1069 |
{
|
| 1032 |
string s;
|
1070 |
string s;
|
| 1033 |
s = EA_Utils.options.opt_RequirementElementDisplayFormat;
|
1071 |
s = EA_Utils.options.opt_RequirementElementDisplayFormat;
|
| 1034 |
s = s.Replace(@"%s",@"{0}");
|
1072 |
s = s.Replace(@"%s",@"{0}");
|
| 1035 |
appendAndSelectText( String.Format( s, theElement.Name ), "Body 1");
|
1073 |
appendAndSelectText( String.Format( s, theElement.Name ), styleName_Body1);
|
| 1036 |
WordRange.Font.Bold = 1;
|
1074 |
WordRange.Font.Bold = 1;
|
| 1037 |
}
|
1075 |
}
|
| 1038 |
else if ( EA_Utils.options.opt_ElementHeadingTransitionLevel > 0
|
1076 |
else if ( EA_Utils.options.opt_ElementHeadingTransitionLevel > 0
|
| 1039 |
&& EA_Utils.options.opt_ElementHeadingTransitionLevel <= recurse_level )
|
1077 |
&& EA_Utils.options.opt_ElementHeadingTransitionLevel <= recurse_level )
|
| 1040 |
appendAndSelectNumParaText( theElement.Name.ToString(), recurse_level );
|
1078 |
appendAndSelectNumParaText( theElement.Name.ToString(), recurse_level );
|
| 1041 |
else
|
1079 |
else
|
| 1042 |
appendAndSelectHeadingText( theElement.Name.ToString(), recurse_level );
|
1080 |
appendAndSelectHeadingText( theElement.Name.ToString(), recurse_level );
|
| 1043 |
|
1081 |
|
| 1044 |
appendAndSelectText( theElement.Notes.ToString(), "Body 1" );
|
1082 |
appendAndSelectText( theElement.Notes.ToString(), styleName_Body1 );
|
| 1045 |
}
|
1083 |
}
|
| 1046 |
}
|
1084 |
}
|
| 1047 |
else
|
1085 |
else
|
| 1048 |
{
|
1086 |
{
|
| 1049 |
displayProgress( "FILTERED: ", theElement.Type );
|
1087 |
displayProgress( "FILTERED: ", theElement.Type );
|
| Line 1085... |
Line 1123... |
| 1085 |
/// </summary>
|
1123 |
/// </summary>
|
| 1086 |
private void removeExistingDocumentContent()
|
1124 |
private void removeExistingDocumentContent()
|
| 1087 |
{
|
1125 |
{
|
| 1088 |
//WordApp.Visible = true; // enable this when debugging this horrible function
|
1126 |
//WordApp.Visible = true; // enable this when debugging this horrible function
|
| 1089 |
Word.Selection aSelection;
|
1127 |
Word.Selection aSelection;
|
| 1090 |
object findStyle = getStyle("Heading 1");
|
1128 |
object findStyle = getStyle( styleName_Heading1 );
|
| 1091 |
|
1129 |
|
| 1092 |
WordApp.Selection.WholeStory();
|
1130 |
WordApp.Selection.WholeStory();
|
| 1093 |
aSelection = WordApp.Selection;
|
1131 |
aSelection = WordApp.Selection;
|
| 1094 |
|
1132 |
|
| 1095 |
aSelection.Find.ClearFormatting();
|
1133 |
aSelection.Find.ClearFormatting();
|
| Line 1116... |
Line 1154... |
| 1116 |
// generated content. Extend the range to the end of the document and cut out the
|
1154 |
// generated content. Extend the range to the end of the document and cut out the
|
| 1117 |
// old content.
|
1155 |
// old content.
|
| 1118 |
Word.Range range = aSelection.Range;
|
1156 |
Word.Range range = aSelection.Range;
|
| 1119 |
range.End = WordDocument.Content.End;
|
1157 |
range.End = WordDocument.Content.End;
|
| 1120 |
range.Cut();
|
1158 |
range.Cut();
|
| - |
|
1159 |
// try and ensure that no heading style is left in place following the removal
|
| - |
|
1160 |
object style = styleName_Body1;
|
| - |
|
1161 |
range.set_Style(ref style);
|
| 1121 |
}
|
1162 |
}
|
| 1122 |
}
|
1163 |
}
|
| 1123 |
|
1164 |
|
| 1124 |
|
1165 |
|
| 1125 |
/// <summary>
|
1166 |
/// <summary>
|
| Line 1250... |
Line 1291... |
| 1250 |
/// an input template, sets various characteristics of the document, schedules the
|
1291 |
/// an input template, sets various characteristics of the document, schedules the
|
| 1251 |
/// EA parsing function, before finally saving the document to the output file name.
|
1292 |
/// EA parsing function, before finally saving the document to the output file name.
|
| 1252 |
/// </summary>
|
1293 |
/// </summary>
|
| 1253 |
private void createTheWordDoc()
|
1294 |
private void createTheWordDoc()
|
| 1254 |
{
|
1295 |
{
|
| - |
|
1296 |
// caputre initial security settings
|
| - |
|
1297 |
MsoAutomationSecurity securityBefore = WordApp.AutomationSecurity;
|
| - |
|
1298 |
|
| 1255 |
try
|
1299 |
try
|
| 1256 |
{
|
1300 |
{
|
| 1257 |
object template = this.textBox_template.Text;
|
1301 |
object template = this.textBox_template.Text;
|
| 1258 |
object newTemplate = Type.Missing;
|
1302 |
object newTemplate = Type.Missing;
|
| 1259 |
object outputFilename = this.textBox_output_file.Text;
|
1303 |
object outputFilename = this.textBox_output_file.Text;
|
| Line 1265... |
Line 1309... |
| 1265 |
|
1309 |
|
| 1266 |
EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "", 0);
|
1310 |
EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "", 0);
|
| 1267 |
EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,
|
1311 |
EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME,
|
| 1268 |
String.Format( "Generating Document {0}", this.textBox_output_file.Text), 0 );
|
1312 |
String.Format( "Generating Document {0}", this.textBox_output_file.Text), 0 );
|
| 1269 |
|
1313 |
|
| 1270 |
// tell word not to show itself
|
1314 |
// tell word not to show itself unless user has checked the option to say otherwise
|
| 1271 |
WordApp.Visible = this.checkBox_WordVisibility.Checked;
|
1315 |
WordApp.Visible = this.checkBox_WordVisibility.Checked;
|
| 1272 |
|
1316 |
|
| - |
|
1317 |
// disable VB macros from running in the document
|
| - |
|
1318 |
WordApp.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;
|
| - |
|
1319 |
WordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
|
| - |
|
1320 |
|
| 1273 |
// Create a document from the input template
|
1321 |
// Create a document from the input template
|
| 1274 |
WordDocument = WordApp.Documents.Add(ref template, ref newTemplate, ref docType, ref visible);
|
1322 |
WordDocument = WordApp.Documents.Add(ref template, ref newTemplate, ref docType, ref visible);
|
| 1275 |
|
1323 |
|
| 1276 |
// Remove all old content from the input document/template. Note that this assumes
|
1324 |
// Remove all old content from the input document/template. Note that this assumes
|
| 1277 |
// that content will begin at section 1 with the title "Introduction" and it will have
|
1325 |
// that content will begin at section 1 with the title "Introduction" and it will have
|
| Line 1280... |
Line 1328... |
| 1280 |
|
1328 |
|
| 1281 |
// turn off grammar and spell checking
|
1329 |
// turn off grammar and spell checking
|
| 1282 |
WordDocument.GrammarChecked = false;
|
1330 |
WordDocument.GrammarChecked = false;
|
| 1283 |
WordDocument.SpellingChecked = false;
|
1331 |
WordDocument.SpellingChecked = false;
|
| 1284 |
|
1332 |
|
| - |
|
1333 |
// If the input template does not contain the styles needed for requirement documents,
|
| - |
|
1334 |
// programmatically create them just in case.
|
| - |
|
1335 |
createRequirementStylesIfNecessary();
|
| - |
|
1336 |
|
| 1285 |
// Parse EA_DocGen Document Model. The parent package is the document model itself
|
1337 |
// Parse EA_DocGen Document Model. The parent package is the document model itself
|
| 1286 |
// and the packages within it are the top level packages only.
|
1338 |
// and the packages within it are the top level packages only.
|
| 1287 |
// Question: do we have to parse diagrams and elements at this top level? So far,
|
1339 |
// Question: do we have to parse diagrams and elements at this top level? So far,
|
| 1288 |
// this has been found to be unecessary, but you never know. For now, dont do it.
|
1340 |
// this has been found to be unecessary, but you never know. For now, dont do it.
|
| 1289 |
foreach(EA.Package thePackage in EA_ParentPackage.Packages)
|
1341 |
foreach(EA.Package thePackage in EA_ParentPackage.Packages)
|
| 1290 |
{
|
1342 |
{
|
| 1291 |
parse_package(thePackage, 0);
|
1343 |
parse_package(thePackage, 0);
|
| 1292 |
}
|
1344 |
}
|
| 1293 |
|
1345 |
|
| 1294 |
// TODO
|
- |
|
| 1295 |
// Can we run a word macro from this addin? If so, we should open the doc properties
|
- |
|
| 1296 |
// dialog to let user enter/update the properties.
|
- |
|
| 1297 |
// We could emulate the UpdateAllDocumentFields subroutine written in VB within the
|
- |
|
| 1298 |
// ERG standard template. For now though, do some basic stuff only.
|
- |
|
| 1299 |
|
1346 |
|
| 1300 |
// Select the entire document, and Update all fields, including Table of Contents
|
1347 |
// Select the entire document, and Update all fields, including Table of Contents
|
| 1301 |
// and then collapse the selection in case user wants to view the document, because
|
1348 |
// and then collapse the selection in case user wants to view the document, because
|
| 1302 |
// they wont want to see the inverse video of the selection.
|
1349 |
// they wont want to see the inverse video of the selection.
|
| 1303 |
WordApp.Selection.WholeStory();
|
1350 |
WordApp.Selection.WholeStory();
|
| Line 1320... |
Line 1367... |
| 1320 |
}
|
1367 |
}
|
| 1321 |
catch (Exception createTheWordDoc_exception)
|
1368 |
catch (Exception createTheWordDoc_exception)
|
| 1322 |
{
|
1369 |
{
|
| 1323 |
MessageBox.Show("Document Generation Failed\n\n" + createTheWordDoc_exception.Message);
|
1370 |
MessageBox.Show("Document Generation Failed\n\n" + createTheWordDoc_exception.Message);
|
| 1324 |
}
|
1371 |
}
|
| - |
|
1372 |
|
| - |
|
1373 |
// restore security settings
|
| - |
|
1374 |
WordApp.AutomationSecurity = securityBefore;
|
| - |
|
1375 |
}
|
| - |
|
1376 |
|
| - |
|
1377 |
/// <summary>
|
| - |
|
1378 |
/// Creates a wdStyleTypeParagraph based style
|
| - |
|
1379 |
/// </summary>
|
| - |
|
1380 |
/// <param name="newStyleName"></param>
|
| - |
|
1381 |
/// <param name="followingStyleName"></param>
|
| - |
|
1382 |
/// <param name="baseStyle"></param>
|
| - |
|
1383 |
/// <returns></returns>
|
| - |
|
1384 |
private Word.Style createParagrapghStyle(string newStyleName,
|
| - |
|
1385 |
string followingStyleName,
|
| - |
|
1386 |
Word.Style baseStyle)
|
| - |
|
1387 |
{
|
| - |
|
1388 |
Word.Style s = getStyle(newStyleName);
|
| - |
|
1389 |
if (s == null)
|
| - |
|
1390 |
{
|
| - |
|
1391 |
object o_styleType = Word.WdStyleType.wdStyleTypeParagraph;
|
| - |
|
1392 |
s = WordDocument.Styles.Add(newStyleName, ref o_styleType);
|
| - |
|
1393 |
|
| - |
|
1394 |
object o_baseStyle = baseStyle.NameLocal;
|
| - |
|
1395 |
object o_followingStyle = followingStyleName;
|
| - |
|
1396 |
s.set_BaseStyle(ref o_baseStyle);
|
| - |
|
1397 |
s.set_NextParagraphStyle(ref o_followingStyle);
|
| - |
|
1398 |
|
| - |
|
1399 |
s.Font = baseStyle.Font;
|
| - |
|
1400 |
s.ParagraphFormat = baseStyle.ParagraphFormat;
|
| - |
|
1401 |
s.LanguageID = Word.WdLanguageID.wdEnglishAUS;
|
| - |
|
1402 |
s.NoProofing = 0;
|
| - |
|
1403 |
s.Frame.Delete();
|
| - |
|
1404 |
s.NoSpaceBetweenParagraphsOfSameStyle = false;
|
| - |
|
1405 |
|
| - |
|
1406 |
}
|
| - |
|
1407 |
return s;
|
| - |
|
1408 |
}
|
| - |
|
1409 |
|
| - |
|
1410 |
/// <summary>
|
| - |
|
1411 |
/// Creates a wdStyleTypeCharacter based style
|
| - |
|
1412 |
/// </summary>
|
| - |
|
1413 |
/// <param name="newStyleName"></param>
|
| - |
|
1414 |
/// <param name="baseStyle"></param>
|
| - |
|
1415 |
/// <returns></returns>
|
| - |
|
1416 |
private Word.Style createCharacterStyle(string newStyleName, Word.Style baseStyle)
|
| - |
|
1417 |
{
|
| - |
|
1418 |
Word.Style s = getStyle(newStyleName);
|
| - |
|
1419 |
if (s == null)
|
| - |
|
1420 |
{
|
| - |
|
1421 |
object o_styleType = Word.WdStyleType.wdStyleTypeCharacter;
|
| - |
|
1422 |
s = WordDocument.Styles.Add(newStyleName, ref o_styleType);
|
| - |
|
1423 |
object o_baseStyle = baseStyle.NameLocal;
|
| - |
|
1424 |
s.set_BaseStyle(ref o_baseStyle);
|
| - |
|
1425 |
s.Font = baseStyle.Font;
|
| - |
|
1426 |
s.LanguageID = Word.WdLanguageID.wdEnglishAUS;
|
| - |
|
1427 |
s.NoProofing = 0;
|
| - |
|
1428 |
}
|
| - |
|
1429 |
return s;
|
| - |
|
1430 |
}
|
| - |
|
1431 |
|
| - |
|
1432 |
|
| - |
|
1433 |
/// <summary>
|
| - |
|
1434 |
/// Creates the styles needed for generating requirement documentation, if they do not
|
| - |
|
1435 |
/// already exist.
|
| - |
|
1436 |
/// </summary>
|
| - |
|
1437 |
private void createRequirementStylesIfNecessary()
|
| - |
|
1438 |
{
|
| - |
|
1439 |
Word.Style s_Body1 = getStyle(styleName_Body1);
|
| - |
|
1440 |
if (s_Body1 != null)
|
| - |
|
1441 |
{
|
| - |
|
1442 |
// APPROVED ///////////////////////////////////////////////////////////////////////////////////////////////
|
| - |
|
1443 |
Word.Style s_ReqAppBody = createParagrapghStyle(styleName_ReqAppBody, styleName_ReqAppBody, s_Body1);
|
| - |
|
1444 |
if (s_ReqAppBody != null)
|
| - |
|
1445 |
{
|
| - |
|
1446 |
// No changes needed - this is just a copy of Body 1
|
| - |
|
1447 |
}
|
| - |
|
1448 |
|
| - |
|
1449 |
Word.Style s_ReqAppHdr = null;
|
| - |
|
1450 |
if (s_ReqAppBody != null)
|
| - |
|
1451 |
{
|
| - |
|
1452 |
s_ReqAppHdr = createParagrapghStyle(styleName_ReqAppHdr, styleName_ReqAppBody, s_Body1);
|
| - |
|
1453 |
if (s_ReqAppHdr != null)
|
| - |
|
1454 |
{
|
| - |
|
1455 |
// Indent:Hanging: 2.5cm, Space After: 3pt, Keep with next, Tabs: 16.5cm, Right
|
| - |
|
1456 |
s_ReqAppHdr.ParagraphFormat.FirstLineIndent = WordApp.CentimetersToPoints((float)-2.5);
|
| - |
|
1457 |
s_ReqAppHdr.ParagraphFormat.SpaceAfter = 3;
|
| - |
|
1458 |
s_ReqAppHdr.ParagraphFormat.KeepWithNext = (int)MsoTriState.msoTrue;
|
| - |
|
1459 |
s_ReqAppHdr.ParagraphFormat.TabStops.ClearAll();
|
| - |
|
1460 |
object alignment = Word.WdTabAlignment.wdAlignTabRight;
|
| - |
|
1461 |
object leader = Word.WdTabLeader.wdTabLeaderSpaces;
|
| - |
|
1462 |
s_ReqAppHdr.ParagraphFormat.TabStops.Add( WordApp.CentimetersToPoints((float)16.5), ref alignment, ref leader );
|
| - |
|
1463 |
}
|
| - |
|
1464 |
}
|
| - |
|
1465 |
|
| - |
|
1466 |
// PROPOSED ///////////////////////////////////////////////////////////////////////////////////////////////
|
| - |
|
1467 |
Word.Style s_ReqPropBody = null;
|
| - |
|
1468 |
if (s_ReqAppBody != null)
|
| - |
|
1469 |
{
|
| - |
|
1470 |
s_ReqPropBody = createParagrapghStyle(styleName_ReqPropBody, styleName_ReqPropBody, s_ReqAppBody );
|
| - |
|
1471 |
if (s_ReqPropBody != null)
|
| - |
|
1472 |
{
|
| - |
|
1473 |
// Font: Italic
|
| - |
|
1474 |
s_ReqPropBody.Font.Italic = (int)MsoTriState.msoTrue;
|
| - |
|
1475 |
}
|
| - |
|
1476 |
}
|
| - |
|
1477 |
|
| - |
|
1478 |
if (s_ReqAppHdr != null && s_ReqPropBody != null)
|
| - |
|
1479 |
{
|
| - |
|
1480 |
Word.Style s_ReqPropHdr = createParagrapghStyle(styleName_ReqPropHdr, styleName_ReqPropBody, s_ReqAppHdr );
|
| - |
|
1481 |
if (s_ReqPropHdr != null)
|
| - |
|
1482 |
{
|
| - |
|
1483 |
// Font: Italic
|
| - |
|
1484 |
s_ReqPropHdr.Font.Italic = (int)MsoTriState.msoTrue;
|
| - |
|
1485 |
}
|
| - |
|
1486 |
}
|
| - |
|
1487 |
|
| - |
|
1488 |
// REJECTED ///////////////////////////////////////////////////////////////////////////////////////////////
|
| - |
|
1489 |
Word.Style s_ReqRejBody = null;
|
| - |
|
1490 |
if (s_ReqAppBody != null)
|
| - |
|
1491 |
{
|
| - |
|
1492 |
s_ReqRejBody = createParagrapghStyle(styleName_ReqRejBody, styleName_ReqRejBody, s_ReqAppBody );
|
| - |
|
1493 |
if (s_ReqRejBody != null)
|
| - |
|
1494 |
{
|
| - |
|
1495 |
// Font: Italic
|
| - |
|
1496 |
s_ReqRejBody.Font.StrikeThrough = (int)MsoTriState.msoTrue;
|
| - |
|
1497 |
}
|
| - |
|
1498 |
}
|
| - |
|
1499 |
|
| - |
|
1500 |
if (s_ReqAppHdr != null && s_ReqRejBody != null)
|
| - |
|
1501 |
{
|
| - |
|
1502 |
Word.Style s_ReqRejHdr = createParagrapghStyle(styleName_ReqRejHdr, styleName_ReqRejBody, s_ReqAppHdr );
|
| - |
|
1503 |
if (s_ReqRejHdr != null)
|
| - |
|
1504 |
{
|
| - |
|
1505 |
// Font: Italic
|
| - |
|
1506 |
s_ReqRejHdr.Font.StrikeThrough = (int)MsoTriState.msoTrue;
|
| - |
|
1507 |
}
|
| - |
|
1508 |
}
|
| - |
|
1509 |
|
| - |
|
1510 |
// REQUIREMENT NAME ///////////////////////////////////////////////////////////////////////////////////////////////
|
| - |
|
1511 |
Word.Style s_DefParaFont = getStyle("Default Paragraph Font");
|
| - |
|
1512 |
if (s_DefParaFont != null)
|
| - |
|
1513 |
{
|
| - |
|
1514 |
Word.Style s_ReqName = createCharacterStyle(styleName_ReqName, s_DefParaFont );
|
| - |
|
1515 |
if (s_ReqName != null)
|
| - |
|
1516 |
{
|
| - |
|
1517 |
s_ReqName.Font.Bold = (int)MsoTriState.msoTrue;
|
| - |
|
1518 |
}
|
| - |
|
1519 |
}
|
| - |
|
1520 |
}
|
| 1325 |
}
|
1521 |
}
|
| 1326 |
|
1522 |
|
| 1327 |
/// <summary>
|
1523 |
/// <summary>
|
| 1328 |
/// Generates the text for requirements. This uses custom styles to format the text
|
1524 |
/// Generates the text for requirements. This uses custom styles to format the text
|
| 1329 |
/// rather than formatting it in code.
|
1525 |
/// rather than formatting it in code.
|
| Line 1334... |
Line 1530... |
| 1334 |
string reqShortDesc = "";
|
1530 |
string reqShortDesc = "";
|
| 1335 |
string reqNotes = "";
|
1531 |
string reqNotes = "";
|
| 1336 |
string reqStatusText = "";
|
1532 |
string reqStatusText = "";
|
| 1337 |
string reqHeadingStyle ="";
|
1533 |
string reqHeadingStyle ="";
|
| 1338 |
string reqParaStyle = "";
|
1534 |
string reqParaStyle = "";
|
| 1339 |
object reqNameStyle = "Requirements Name";
|
1535 |
object reqNameStyle = styleName_ReqName;
|
| 1340 |
Word.Range shortDescRange;
|
1536 |
Word.Range shortDescRange;
|
| 1341 |
|
1537 |
|
| 1342 |
// Set the style depending on the status
|
1538 |
// Set the style depending on the status
|
| 1343 |
switch ( theElement.Status )
|
1539 |
switch ( theElement.Status )
|
| 1344 |
{
|
1540 |
{
|
| 1345 |
case "Proposed":
|
1541 |
case "Proposed":
|
| 1346 |
reqStatusText = "(Proposed)";
|
1542 |
reqStatusText = "(Proposed)";
|
| 1347 |
reqHeadingStyle = "Requirements Proposed Heading";
|
1543 |
reqHeadingStyle = styleName_ReqPropHdr;
|
| 1348 |
reqParaStyle = "Requirements Proposed Body";
|
1544 |
reqParaStyle = styleName_ReqPropBody;
|
| 1349 |
break;
|
1545 |
break;
|
| 1350 |
|
1546 |
|
| 1351 |
case "Rejected":
|
1547 |
case "Rejected":
|
| 1352 |
reqHeadingStyle = "Requirements Rejected Heading";
|
1548 |
reqHeadingStyle = styleName_ReqRejHdr;
|
| 1353 |
reqParaStyle = "Requirements Rejected Body";
|
1549 |
reqParaStyle = styleName_ReqRejBody;
|
| 1354 |
break;
|
1550 |
break;
|
| 1355 |
|
1551 |
|
| 1356 |
case "Approved":
|
1552 |
case "Approved":
|
| 1357 |
reqStatusText = "(Phase " + theElement.Phase + ")";
|
1553 |
reqStatusText = "(Phase " + theElement.Phase + ")";
|
| 1358 |
reqHeadingStyle = "Requirements Approved Heading";
|
1554 |
reqHeadingStyle = styleName_ReqAppHdr;
|
| 1359 |
reqParaStyle = "Requirements Approved Body";
|
1555 |
reqParaStyle = styleName_ReqAppBody;
|
| 1360 |
break;
|
1556 |
break;
|
| 1361 |
|
1557 |
|
| 1362 |
default:
|
1558 |
default:
|
| 1363 |
reqStatusText = "(" + theElement.Status + ")(Phase " + theElement.Phase + ")";
|
1559 |
reqStatusText = "(" + theElement.Status + ")(Phase " + theElement.Phase + ")";
|
| 1364 |
reqHeadingStyle = "Requirements Approved Heading";
|
1560 |
reqHeadingStyle = styleName_ReqAppHdr;
|
| 1365 |
reqParaStyle = "Requirements Approved Body";
|
1561 |
reqParaStyle = styleName_ReqAppBody;
|
| 1366 |
break;
|
1562 |
break;
|
| 1367 |
}
|
1563 |
}
|
| 1368 |
|
1564 |
|
| 1369 |
// Pull out the ID from the name
|
1565 |
// Pull out the ID from the name
|
| 1370 |
int pos = theElement.Name.IndexOf( " ", 0, theElement.Name.Length );
|
1566 |
int pos = theElement.Name.IndexOf( " ", 0, theElement.Name.Length );
|
| Line 1391... |
Line 1587... |
| 1391 |
appendAndSelectText( reqNotes, reqParaStyle );
|
1587 |
appendAndSelectText( reqNotes, reqParaStyle );
|
| 1392 |
|
1588 |
|
| 1393 |
}
|
1589 |
}
|
| 1394 |
|
1590 |
|
| 1395 |
|
1591 |
|
| - |
|
1592 |
/// <summary>
|
| - |
|
1593 |
/// Class to sort EA elements alphabetically, in a case insensitive way.
|
| - |
|
1594 |
/// This is used by the processRelationshipMatrixElement method.
|
| - |
|
1595 |
/// </summary>
|
| 1396 |
public class elementSortByName : IComparer
|
1596 |
public class elementSortByName : IComparer
|
| 1397 |
{
|
1597 |
{
|
| 1398 |
int IComparer.Compare( object x, object y)
|
1598 |
int IComparer.Compare( object x, object y)
|
| 1399 |
{
|
1599 |
{
|
| 1400 |
if (x!=null & y!= null)
|
1600 |
if (x!=null & y!= null)
|
| Line 1446... |
Line 1646... |
| 1446 |
|
1646 |
|
| 1447 |
if (needFromToTable)
|
1647 |
if (needFromToTable)
|
| 1448 |
{
|
1648 |
{
|
| 1449 |
if (EA_RelMatrix.fromIntroText != null && EA_RelMatrix.fromIntroText.Length > 0)
|
1649 |
if (EA_RelMatrix.fromIntroText != null && EA_RelMatrix.fromIntroText.Length > 0)
|
| 1450 |
{
|
1650 |
{
|
| 1451 |
appendAndSelectText( EA_RelMatrix.fromIntroText, "Body 1" );
|
1651 |
appendAndSelectText( EA_RelMatrix.fromIntroText, styleName_Body1 );
|
| 1452 |
}
|
1652 |
}
|
| 1453 |
|
1653 |
|
| 1454 |
// create the from-to table in the word doc
|
1654 |
// create the from-to table in the word doc
|
| 1455 |
tableNum = createTable( EA_RelMatrix.fromToTableTitle, fromLister.Elements.Count + 1, 2 );
|
1655 |
tableNum = createTable( EA_RelMatrix.fromToTableTitle, fromLister.Elements.Count + 1, 2 );
|
| 1456 |
table = WordDocument.Tables[tableNum];
|
1656 |
table = WordDocument.Tables[tableNum];
|
| Line 1528... |
Line 1728... |
| 1528 |
// Sort the "to" elements
|
1728 |
// Sort the "to" elements
|
| 1529 |
toLister.Elements.Sort( sorter );
|
1729 |
toLister.Elements.Sort( sorter );
|
| 1530 |
|
1730 |
|
| 1531 |
if (EA_RelMatrix.toIntroText != null && EA_RelMatrix.toIntroText.Length > 0)
|
1731 |
if (EA_RelMatrix.toIntroText != null && EA_RelMatrix.toIntroText.Length > 0)
|
| 1532 |
{
|
1732 |
{
|
| 1533 |
appendAndSelectText( EA_RelMatrix.toIntroText, "Body 1" );
|
1733 |
appendAndSelectText( EA_RelMatrix.toIntroText, styleName_Body1 );
|
| 1534 |
}
|
1734 |
}
|
| 1535 |
|
1735 |
|
| 1536 |
// create the table in the word doc
|
1736 |
// create the table in the word doc
|
| 1537 |
tableNum = createTable( EA_RelMatrix.toFromTableTitle, toLister.Elements.Count + 1, 2 );
|
1737 |
tableNum = createTable( EA_RelMatrix.toFromTableTitle, toLister.Elements.Count + 1, 2 );
|
| 1538 |
table = WordDocument.Tables[tableNum];
|
1738 |
table = WordDocument.Tables[tableNum];
|