Subversion Repositories DevTools

Rev

Rev 2132 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2088 ghuddy 1
using System;
2
using System.Windows.Forms;
3
using System.IO;
4
using System.Collections;
2094 ghuddy 5
using System.Collections.Specialized;
6
using System.Text;
2088 ghuddy 7
 
8
namespace EA_DocGen
9
{
10
   /// <summary>
11
   /// Summary description for EA_DocGenOptions.
12
   /// </summary>
13
   public class EA_DocGenOptions
14
   {
2106 ghuddy 15
      // Strings used in the notes section of an EA_DocGen element that persists the options.
16
      public static string optstr_GeneralOptions = "[GeneralOptions]";
17
      public static string optstr_ElementTypes   = "[ElementTypes]";
2094 ghuddy 18
 
2106 ghuddy 19
      private static string [] options_string = null;
20
      private static bool options_found = false;
2088 ghuddy 21
 
2116 ghuddy 22
      // Boolean options
23
      public enum boolean_options_e
24
      {
25
         SUPPRESS_PRIVATE_CLASSES = 0,
26
         SUPPRESS_PRIVATE_ATTRIBUTES,
27
         SUPPRESS_PRIVATE_METHODS,
28
         SUPPRESS_METHOD_CHARACTERISTICS,
29
         SUPPRESS_CLASS_CHARACTERISTICS,
30
         SUPPRESS_CLASS_REQUIREMENTS,
31
         SUPPRESS_CLASS_CONSTRAINTS,
32
         SUPPRESS_CLASS_BASE_CLASSES,
33
         SUPPRESS_CLASS_REALISES,
34
         SUPPRESS_ATTRIBUTE_CHARACTERISTICS,
35
         SUPPRESS_ELEMENT_DESC_MISSING_WARNINGS,
36
         SUPPRESS_UN_ALLOCATED_RELATIONSHIP_WARNINGS,
37
         CONSIDER_API_ELEMENTS_ONLY,
38
         CONSIDER_API_DIAGRAMS_ONLY,
39
         CONSIDER_API_PACKAGES_ONLY,
40
         RESTRICT_FOR_LINKED_PACKAGES_ONLY,
41
         USE_NUM_PARA_FOR_GENERATED_TEST_CASES,
2124 ghuddy 42
         SUPPRESS_REQUIREMENT_NOTES,
2132 ghuddy 43
         FORCE_HEADING_TABS_TO_2_5_CM,
2136 brianf 44
         SUPPRESS_PARAMETER_KIND,
2116 ghuddy 45
         UNKNOWN = -1
46
      };
2094 ghuddy 47
 
2116 ghuddy 48
      // local class to collect together stuff for a discrete boolean option
49
      private class boolopt
50
      {
51
         public boolean_options_e enumVal;
52
         public int level;
53
         public string optstr;
54
         public string displayName;
55
         public bool value;
56
         public boolopt(int l, boolean_options_e e, string o, string dn, bool v)
57
         {
58
            enumVal = e;
59
            level = l;
60
            optstr = o;
61
            displayName = dn;
62
            value = v;
63
         }
64
      };
2088 ghuddy 65
 
2116 ghuddy 66
      // A collection of boolean options
67
      public static ArrayList boolopts;
68
      private static int i_boolopts;
69
 
2094 ghuddy 70
 
2088 ghuddy 71
      // Element Types list
2106 ghuddy 72
      public static ArrayList opt_ElementTypes = null;
2088 ghuddy 73
 
2116 ghuddy 74
 
2106 ghuddy 75
      public static void initialise()
2088 ghuddy 76
      {
2116 ghuddy 77
         // Create discrete boolean options collection. The ordering of these statements dictates the display order in
78
         // the options form.
79
         //
80
         // WARNING: level number can be 1 or 2, but no higher.
81
         //
82
         // BIG WARNING
83
         // Make sure that if any option string is a substring of another option string, then the longest of the
84
         // two must appear first in this initialisation sequence
85
 
86
         boolopts = new ArrayList();
2124 ghuddy 87
         boolopts.Add(new boolopt(1, boolean_options_e.CONSIDER_API_ELEMENTS_ONLY,         
88
                                  "ConsiderAPIClassesOnly", 
89
                                  "Consider API Stereotyped Elements Only", 
90
                                  false) );
2116 ghuddy 91
 
2124 ghuddy 92
         boolopts.Add(new boolopt(1, boolean_options_e.CONSIDER_API_DIAGRAMS_ONLY,         
93
                                  "ConsiderAPIDiagramsOnly",                    
94
                                  "Consider API Stereotyped Diagrams Only", 
95
                                  false) );
2116 ghuddy 96
 
2124 ghuddy 97
         boolopts.Add(new boolopt(1, boolean_options_e.CONSIDER_API_PACKAGES_ONLY,         
98
                                  "ConsiderAPIPackagesOnly",                    
99
                                  "Consider API Stereotyped Packages Only", 
100
                                  false) );
2116 ghuddy 101
 
2124 ghuddy 102
         boolopts.Add(new boolopt(2, boolean_options_e.RESTRICT_FOR_LINKED_PACKAGES_ONLY,  
103
                                  "APIPackageRestrictionForLinkedPackagesOnly", 
104
                                  "Restriction Applies Only To Linked Packages", 
105
                                  true) );
2116 ghuddy 106
 
2124 ghuddy 107
         boolopts.Add(new boolopt(1, boolean_options_e.SUPPRESS_ATTRIBUTE_CHARACTERISTICS, 
108
                                  "SuppressAttributeCharacteristics", 
109
                                  "Suppress Attribute Characteristics", 
110
                                  false) );
2116 ghuddy 111
 
2124 ghuddy 112
         boolopts.Add(new boolopt(1, boolean_options_e.SUPPRESS_CLASS_BASE_CLASSES,        
113
                                  "SuppressClassBaseClasses",     
114
                                  "Suppress Class Base Class List", 
115
                                  false) );
2116 ghuddy 116
 
2124 ghuddy 117
         boolopts.Add(new boolopt(1, boolean_options_e.SUPPRESS_CLASS_CHARACTERISTICS,     
118
                                  "SuppressClassCharacteristics", 
119
                                  "Suppress Class Characteristics", 
120
                                  false) );
121
 
122
         boolopts.Add(new boolopt(1, boolean_options_e.SUPPRESS_CLASS_CONSTRAINTS,         
123
                                  "SuppressClassConstraints",     
124
                                  "Suppress Class Constraints", 
125
                                  false) );
126
 
127
         boolopts.Add(new boolopt(1, boolean_options_e.SUPPRESS_CLASS_REALISES,            
128
                                  "SuppressClassRealises",        
129
                                  "Suppress Class Realisation List", 
130
                                  false) );
131
 
132
         boolopts.Add(new boolopt(1, boolean_options_e.SUPPRESS_CLASS_REQUIREMENTS,        
133
                                  "SuppressClassRequirements",    
134
                                  "Suppress Class Requirements", 
135
                                  false) );
136
 
137
         boolopts.Add(new boolopt(1, boolean_options_e.SUPPRESS_ELEMENT_DESC_MISSING_WARNINGS,      
138
                                  "SuppressElementDescriptionMissingWarnings", 
139
                                  "Suppress Element Description Missing Warnings", 
140
                                  false) );
141
 
142
         boolopts.Add(new boolopt(1, boolean_options_e.SUPPRESS_METHOD_CHARACTERISTICS,    
143
                                  "SuppressMethodCharacteristics",    
144
                                  "Suppress Method Characteristics", 
145
                                  false) );
146
 
147
         boolopts.Add(new boolopt(1, boolean_options_e.SUPPRESS_PRIVATE_ATTRIBUTES,        
148
                                  "SuppressPrivateAttributes",        
149
                                  "Suppress Private Attributes", 
150
                                  false) );
151
 
152
         boolopts.Add(new boolopt(1, boolean_options_e.SUPPRESS_PRIVATE_CLASSES,           
153
                                  "SuppressPrivateClasses",           
154
                                  "Suppress Private Classes", 
155
                                  false) );
156
 
157
         boolopts.Add(new boolopt(1, boolean_options_e.SUPPRESS_PRIVATE_METHODS,           
158
                                  "SuppressPrivateMethods",           
159
                                  "Suppress Private Methods", 
160
                                  false) );
161
 
162
         boolopts.Add(new boolopt(1, boolean_options_e.SUPPRESS_UN_ALLOCATED_RELATIONSHIP_WARNINGS, 
163
                                  "SuppressUnAllocatedRelationshipWarnings",   
164
                                  "Suppress Un-Allocated Relationship Warnings", 
165
                                  false) );
166
 
167
         boolopts.Add(new boolopt(1, boolean_options_e.SUPPRESS_REQUIREMENT_NOTES,                  
168
                                  "SuppressRequirementNotes", 
169
                                  "Suppress Use Of Requirement Element Notes", 
170
                                  true) );
171
 
172
         boolopts.Add(new boolopt(1, boolean_options_e.USE_NUM_PARA_FOR_GENERATED_TEST_CASES,       
173
                                  "UseNumParaForGeneratedTestCases", 
174
                                  "Use NumPara Styles For Generated Test Case Sections", 
175
                                  true) );
176
 
2132 ghuddy 177
         boolopts.Add(new boolopt(1, boolean_options_e.FORCE_HEADING_TABS_TO_2_5_CM,
178
                                  "ForceHeadingTabsTo2_5cm",
179
                                  "Force Heading Style Tabs To 2.5cm",
180
                                  false) );
2124 ghuddy 181
 
2136 brianf 182
          boolopts.Add(new boolopt(1, boolean_options_e.SUPPRESS_PARAMETER_KIND,
183
                                  "SuppressParameterKind",
184
                                  "Suppress Parameter Kind",
185
                                  true));
2116 ghuddy 186
         // Create element types list
2108 ghuddy 187
         if (opt_ElementTypes == null)
188
            opt_ElementTypes = new ArrayList();
189
         opt_ElementTypes.Clear();
2088 ghuddy 190
         setDefaults();
191
      }
192
 
2116 ghuddy 193
 
194
      /// <summary>
195
      /// Function to return to another class the value of a specified discrete boolean option
196
      /// </summary>
197
      /// <param name="e"></param>
198
      /// <returns></returns>
199
      public static bool optionValue(boolean_options_e e)
200
      {
201
         foreach (boolopt bo in boolopts)
202
         {
203
            if (bo.enumVal == e)
204
            {
205
               return bo.value;
206
            }
207
         }
208
         return false;
209
      }
210
 
211
      /// <summary>
212
      /// Function to allow another class to set the value of a discrete boolean option.
213
      /// Normally, this will only be done from the editing form class.
214
      /// </summary>
215
      /// <param name="e"></param>
216
      /// <param name="value"></param>
217
      public static void optionValue(boolean_options_e e, bool value)
218
      {
219
         foreach (boolopt bo in boolopts)
220
         {
221
            if (bo.enumVal == e)
222
            {
223
               bo.value = value;
224
               break;
225
            }
226
         }
227
      }
228
 
229
      /// <summary>
230
      /// Function to return the option string to use for a specified
231
      /// discrete boolean option. Option strings are used in the actual EA element to record
232
      /// the state of the option. They are (or may be) similar to the display names for the options
233
      /// but without any spaces, and they may be shortened somewhat too.
234
      /// </summary>
235
      /// <param name="e"></param>
236
      /// <returns></returns>
237
      private static string optionString(boolean_options_e e)
238
      {
239
         foreach (boolopt bo in boolopts)
240
         {
241
            if (bo.enumVal == e)
242
            {
243
               return bo.optstr;
244
            }
245
         }
246
         return null;
247
      }
248
 
249
      /// <summary>
250
      /// Helper for getFirstBooleanOption() and getNextBooleanOption()
251
      /// </summary>
252
      /// <param name="index"></param>
253
      /// <param name="e"></param>
254
      /// <param name="level"></param>
255
      /// <param name="displayName"></param>
256
      /// <param name="value"></param>
257
      private static void getBooleanOption(int index, out boolean_options_e e, out int level, out string displayName, out bool value)
258
      {
259
         boolopt o = (boolopt)boolopts[index];
260
         e = o.enumVal;
261
         level = o.level;
262
         displayName = o.displayName;
263
         value = o.value;
264
      }
265
 
266
      /// <summary>
267
      /// Function to return the details of the first discrete boolean option.
268
      /// This will be used by the option editing form class to populate a list for user editing.
269
      /// </summary>
270
      /// <param name="e"></param>
271
      /// <param name="level"></param>
272
      /// <param name="displayName"></param>
273
      /// <param name="value"></param>
274
      /// <returns></returns>
275
      public static bool getFirstBooleanOption(out boolean_options_e e, out int level, out string displayName, out bool value)
276
      {
277
         i_boolopts = 0;
278
 
279
         e = boolean_options_e.UNKNOWN;
280
         level = 1;
281
         displayName = "";
282
         value = false;
283
 
284
         if (i_boolopts < boolopts.Count)
285
         {
286
            getBooleanOption(i_boolopts, out e, out level, out displayName, out value);
287
            return true;
288
         }
289
         else
290
         {
291
            return false;
292
         }
293
      }
294
 
295
      /// <summary>
296
      /// Function to return the details of the next discrete boolean option.
297
      /// This will be used by the option editing form class to populate a list for user editing.
298
      /// </summary>
299
      /// <param name="e"></param>
300
      /// <param name="level"></param>
301
      /// <param name="displayName"></param>
302
      /// <param name="value"></param>
303
      /// <returns></returns>
304
      public static bool getNextBooleanOption(out boolean_options_e e, out int level, out string displayName, out bool value)
305
      {
306
         i_boolopts++;
307
 
308
         e = boolean_options_e.UNKNOWN;
309
         level = 1;
310
         displayName = "";
311
         value = false;
312
 
313
         if (i_boolopts < boolopts.Count)
314
         {
315
            getBooleanOption(i_boolopts, out e, out level, out displayName, out value);
316
            return true;
317
         }
318
         else
319
         {
320
            return false;
321
         }
322
      }
323
 
324
      /// <summary>
325
      /// Set default values for the discrete boolean options.
326
      /// </summary>
2106 ghuddy 327
      private static void setDefaults()
2088 ghuddy 328
      {
2116 ghuddy 329
         optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_ELEMENT_DESC_MISSING_WARNINGS, false);
330
         optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_UN_ALLOCATED_RELATIONSHIP_WARNINGS, false);
331
         optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_PRIVATE_ATTRIBUTES, false);
332
         optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_PRIVATE_METHODS, false);
333
         optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_PRIVATE_CLASSES, false);
334
         optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_METHOD_CHARACTERISTICS, false);
335
         optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_CLASS_CHARACTERISTICS, false);
2124 ghuddy 336
         optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_CLASS_REALISES, false);
2116 ghuddy 337
         optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_CLASS_REQUIREMENTS, false);
338
         optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_CLASS_CONSTRAINTS, false);
2124 ghuddy 339
         optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_CLASS_BASE_CLASSES, false);
2116 ghuddy 340
         optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_ATTRIBUTE_CHARACTERISTICS, false);
341
         optionValue(EA_DocGenOptions.boolean_options_e.CONSIDER_API_ELEMENTS_ONLY, false);
342
         optionValue(EA_DocGenOptions.boolean_options_e.CONSIDER_API_DIAGRAMS_ONLY, false);
343
         optionValue(EA_DocGenOptions.boolean_options_e.CONSIDER_API_PACKAGES_ONLY, false);
344
         optionValue(EA_DocGenOptions.boolean_options_e.RESTRICT_FOR_LINKED_PACKAGES_ONLY, true);
2124 ghuddy 345
         optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_REQUIREMENT_NOTES, false);
346
         optionValue(EA_DocGenOptions.boolean_options_e.USE_NUM_PARA_FOR_GENERATED_TEST_CASES, true);
2132 ghuddy 347
         optionValue(EA_DocGenOptions.boolean_options_e.FORCE_HEADING_TABS_TO_2_5_CM, false);
2136 brianf 348
         optionValue(EA_DocGenOptions.boolean_options_e.SUPPRESS_PARAMETER_KIND, false);
2088 ghuddy 349
      }
350
 
351
 
352
      /// <summary>
353
      /// Looks for the EA_DocGen element in the selected package. To generate a document
354
      /// on a package, the package must contain the EA_DocGen element, even if that elements
355
      /// notes are empty. It serves to denote a package as a document model that is allowed
356
      /// to be processed by this add-in.
357
      /// </summary>
358
      /// <param name="parentPackage"></param>
359
      /// <returns></returns>
2122 ghuddy 360
      public static EA.Package lookForAndProcess_EA_DocGen_Element( EA.Package pkg )
2088 ghuddy 361
      {
2122 ghuddy 362
         options_found = false;
2088 ghuddy 363
 
2122 ghuddy 364
         // iterate up through the package hiearchy
365
         while (pkg != null)
2088 ghuddy 366
         {
2122 ghuddy 367
            // Look for an EA_DocGen element in this package
368
            foreach(EA.Element theElement in pkg.Elements)
369
            {
370
               options_found = lookForAndProcess_EA_DocGen_Element(theElement);
371
               if (options_found)
372
               {
373
                  return pkg;
374
               }
375
            }            
376
 
377
            // Didnt find EA_DocGen element, go up one package level ready for the next loop iteration
378
            if (pkg.ParentID > 0)
379
            {
380
               pkg = Main.EA_Repository.GetPackageByID(pkg.ParentID);
381
            }
382
            else
383
            {
384
               // force loop termination if cannot go up one more package level
385
               pkg = null;
386
            }
387
         }
388
 
389
         return pkg;
2094 ghuddy 390
      }
2088 ghuddy 391
 
2106 ghuddy 392
      public static bool lookForAndProcess_EA_DocGen_Element( EA.Element theElement )
2094 ghuddy 393
      {
2108 ghuddy 394
         initialise();
395
 
2094 ghuddy 396
         options_string = null;
397
         options_found  = false;
2088 ghuddy 398
 
2094 ghuddy 399
         // Special handling for the EA_DocGen element designed to control this document
400
         // generator
401
         if (0 == theElement.Name.CompareTo(EA_Constants.EA_DocGenBaseName))
402
         {
403
            options_found = true;
2088 ghuddy 404
 
2094 ghuddy 405
            // Extract the content of the EA_DocGen element notes section, into a list of
406
            // strings.
407
            string delimStr = "\n";
408
            char [] delim = delimStr.ToCharArray();
2132 ghuddy 409
            options_string = theElement.Notes.Split(delim,400);
2094 ghuddy 410
 
411
            int i = 0;
412
            foreach(string s in options_string)
413
            {
414
               options_string[i] = s.Trim();
415
               i++;
2088 ghuddy 416
            }
417
 
2094 ghuddy 418
            // Extract general options from the list of strings
419
            extractGeneralOptions();
420
 
421
            // Extract element types list from the list of strings
422
            extractElementTypes();
423
         }
424
 
2088 ghuddy 425
         return options_found;
426
      }
427
 
428
 
2106 ghuddy 429
      private static string getOptionValueString(string optionLine)
2088 ghuddy 430
      {
431
         string delimStr = "=";
432
         char [] delim = delimStr.ToCharArray();
433
         string [] optionLineParts = optionLine.Split(delim,2);
434
         if (optionLineParts.GetLength(0) == 2)
435
         {
436
            return optionLineParts[1];
437
         }
438
         else
439
         {
440
            MessageBox.Show( "Error in EA_DocGen option\n\n" + optionLine + "\n\n" + "Missing value" );
441
         }
442
         return null;
443
      }
444
 
445
 
446
      // Overloaded "get option value" methods
2106 ghuddy 447
      public static int getOptionValue(string s, int defaultReturnValue)
2088 ghuddy 448
      {
449
         int returnVal = defaultReturnValue;
450
 
451
         string optionValue = getOptionValueString(s);
452
         if (optionValue != null)
453
         {
454
            try
455
            {
456
               returnVal = Convert.ToInt32(optionValue);
457
            }
458
            catch(Exception)
459
            {
460
               MessageBox.Show( "Error in EA_DocGen option\n\n" + s + "\n\n" + "Expected valid integer" );
461
            }
462
         }   
463
         return returnVal;
464
      }
465
 
2106 ghuddy 466
      public static double getOptionValue(string s, double defaultReturnValue)
2100 ghuddy 467
      {
468
         double returnVal = defaultReturnValue;
469
 
470
         string optionValue = getOptionValueString(s);
471
         if (optionValue != null)
472
         {
473
            try
474
            {
475
               returnVal = Convert.ToDouble(optionValue);
476
            }
477
            catch(Exception)
478
            {
479
               MessageBox.Show( "Error in EA_DocGen option\n\n" + s + "\n\n" + "Expected valid double" );
480
            }
481
         }   
482
         return returnVal;
483
      }
484
 
2106 ghuddy 485
      public static bool getOptionValue(string s, bool defaultReturnValue)
2088 ghuddy 486
      {
487
         bool returnVal = defaultReturnValue;
488
 
489
         string optionValue = getOptionValueString(s);
490
         if (optionValue != null)
491
         {
492
            try
493
            {
494
               returnVal = Convert.ToBoolean(optionValue);
495
            }
496
            catch(Exception)
497
            {
498
               MessageBox.Show( "Error in EA_DocGen option\n\n" + s + "\n\n" + "Expected valid boolean" );
499
            }
500
         }   
501
         return returnVal;
502
      }
503
 
504
 
2106 ghuddy 505
      public static string getOptionValue(string s, string defaultReturnValue)
2088 ghuddy 506
      {
507
         string returnVal = defaultReturnValue;
508
 
509
         string optionValue = getOptionValueString(s);
510
         if (optionValue != null)
511
         {
512
            returnVal = optionValue;
513
         }   
514
         return returnVal;
515
      }
516
 
517
 
2106 ghuddy 518
      public static char getOptionValue(string s, char defaultReturnValue)
2088 ghuddy 519
      {
520
         char returnVal = defaultReturnValue;
521
 
522
         string optionValue = getOptionValueString(s);
523
         if (optionValue != null && optionValue.Length > 0)
524
         {
525
            returnVal = optionValue[0];
526
         }   
527
         return returnVal;
528
      }
529
 
530
 
531
 
532
      /// <summary>
533
      /// Method to extract all the general options from the string array obtained from
534
      /// the EA_DocGen element
535
      /// </summary>
2106 ghuddy 536
      private static void extractGeneralOptions()
2088 ghuddy 537
      {
538
         bool parsingGenOpts = false;
539
 
540
         if (options_string != null)
541
         {
542
            // iterate through the string array obtained from the EA_DocGen element
543
            foreach(string s in options_string)
544
            {
2094 ghuddy 545
               if (s.StartsWith(optstr_GeneralOptions))
2088 ghuddy 546
               {
547
                  parsingGenOpts = true;
548
                  continue;
549
               }
550
               else if (   (parsingGenOpts == true) 
551
                        && (s.Length >= 1)
552
                        && (s.Substring(0,1) == "[") )
553
               {
554
                  // we have gone past the general options and reached another section in EA_DocGen
555
                  // so there is no point in continuing. Exit the loop
556
                  break;
557
               }
558
 
559
               if (parsingGenOpts == true)
560
               {
2116 ghuddy 561
                  foreach(boolopt bo in boolopts)
2088 ghuddy 562
                  {
2116 ghuddy 563
                     if (s.StartsWith(bo.optstr))
564
                     {
565
                        optionValue(bo.enumVal, getOptionValue(s, bo.value));
566
                     }
2088 ghuddy 567
                  }
568
               }
569
            }         
570
         }
571
      }
572
 
573
 
2106 ghuddy 574
      private static void extractElementTypes()
2088 ghuddy 575
      {
576
         bool parsingElementTypes = false;
577
 
578
         opt_ElementTypes.Clear();
579
 
580
         if (options_string != null)
581
         {
582
            // iterate through the string array obtained from the EA_DocGen element
583
            foreach(string s in options_string)
584
            {
2094 ghuddy 585
               if (s.StartsWith(optstr_ElementTypes))
2088 ghuddy 586
               {
587
                  parsingElementTypes = true;
588
                  continue;
589
               }
590
               else if (   (parsingElementTypes == true) 
591
                        && (s.Length >= 1)
592
                        && (s.Substring(0,1) == "[") )
593
               {
594
                  // we have gone past the element types and reached another section in EA_DocGen
595
                  // so there is no point in continuing. Exit the loop
596
                  break;
597
               }
598
 
599
               if (parsingElementTypes == true)
600
               {
601
                  string trimmed_s = s.Trim();
602
                  if (trimmed_s.Length > 0)
603
                  {
604
                     opt_ElementTypes.Add( s );
605
                  }
606
               }
607
            }
608
         }
609
      }
610
 
611
 
612
      /// <summary>
613
      /// This method searches the EA_DocGen string list to find the element types the user
614
      /// has specified that must be included in the document. If the element type given to
615
      /// the function is not in that list then it is excluded from the generated document.
616
      /// The notes of the EA_DocGen element are formed like a .ini file and contain sections 
617
      /// and section content along the lines of:
618
      /// 
619
      /// [sectionName]
620
      /// value
621
      /// value
622
      /// etc
623
      /// [anotherSectionName]
624
      /// value
625
      /// value
626
      /// etc
627
      /// 
628
      /// The [ElementTypes] section is the one this function is interested in
629
      /// 
630
      /// </summary>
631
      /// <param name="elementName"></param>
632
      /// <returns></returns>
2106 ghuddy 633
      public static bool elementTypeFoundInEA_DocGen(string elementType)
2088 ghuddy 634
      {
635
         if (opt_ElementTypes != null && opt_ElementTypes.Count > 0)
636
         {
637
            foreach(string s in opt_ElementTypes)
638
            {
639
               if (s.StartsWith(elementType))
640
               {
641
                  return true;
642
               }
643
            } 
644
            // elementType is not in the opt_ElementTypes list, so element is filtered out
645
            return false;
646
         }
647
         else
648
         {
649
            // opt_ElementTypes is empty so no filtering, return true 
650
            return true;
651
         }
652
      }
653
 
2116 ghuddy 654
      private static void updateEA_DocGen(ref StringBuilder sb, EA_DocGenOptions.boolean_options_e e)
2094 ghuddy 655
      {
2116 ghuddy 656
         boolopt o = (boolopt)boolopts[(int)e];
657
 
658
         sb.Append( o.optstr );
2094 ghuddy 659
         sb.Append( "=" );
2116 ghuddy 660
         sb.Append( o.value.ToString() );
2094 ghuddy 661
         sb.Append( "\r\n" );
662
      }
2088 ghuddy 663
 
2106 ghuddy 664
      private static void updateEA_DocGen(ref StringBuilder sb, int iValue, string s)
2094 ghuddy 665
      {
666
         sb.Append( s );
667
         sb.Append( "=" );
668
         sb.Append( iValue.ToString() );
669
         sb.Append( "\r\n" );
670
      }
671
 
2106 ghuddy 672
      public static void updateEA_DocGen(EA.Element ele)
2094 ghuddy 673
      {
674
         StringBuilder sb = new StringBuilder();
675
 
676
         sb.Append( optstr_GeneralOptions );
677
         sb.Append( "\r\n" );
678
 
2116 ghuddy 679
         // output discrete boolean options
680
         foreach(boolopt bo in boolopts)
681
         {
682
            updateEA_DocGen(ref sb, bo.enumVal);
683
         }
2094 ghuddy 684
 
685
         // Element type filtering options
686
         if (opt_ElementTypes.Count > 0)
687
         {
688
            sb.Append( "\r\n" );
689
            sb.Append( optstr_ElementTypes );
690
            sb.Append( "\r\n" );
691
            foreach (string s in opt_ElementTypes)
692
            {
693
               sb.Append( s );
694
               sb.Append( "\r\n" );
695
            }
696
         }
697
 
698
         ele.Notes = sb.ToString();
699
         ele.Update();
700
 
701
      }
702
 
2088 ghuddy 703
   } // end of class
704
} // end of namespace