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.Collections;
4
using System.IO;
2104 ghuddy 5
using System.Text;
2136 brianf 6
using Microsoft.Office.Interop.Word;
2088 ghuddy 7
 
8
namespace EA_DocGen
9
{
10
   /// <summary>
11
   /// A Base Class designed to work with the findAndProcessPackageElements method.
12
   /// Users will normally derive their own classes from this and add real functionality
13
   /// to the over-ridable methods the base class provides.
14
   /// </summary>
15
   public class EA_UtilitiesRecursionWorker
16
   {
17
      public EA_UtilitiesRecursionWorker()
18
      {
19
      }
20
 
21
      public virtual void processElement( EA.Element theElement )
22
      {
23
      }
24
      public virtual void processPackage( EA.Package thePackage )
25
      {
26
      }
27
   }
28
 
2094 ghuddy 29
 
30
 
2088 ghuddy 31
	/// <summary>
32
	/// Class containing functions that implement the EA_DocGen menu items.
33
	/// </summary>
34
	public class EA_Utilities
35
	{
2106 ghuddy 36
      // data used by followLink() to roll around multiple GUIDs contained in the link
37
      static int lastLinkID = -1;
38
      static int nextGuidIndex = 0;
2088 ghuddy 39
 
40
 
41
 
42
      // Operations
43
 
2122 ghuddy 44
      public static EA.Package findNamedPackage(EA.Package current_pkg, string package_path)
45
      {
46
         string[] package_names = package_path.Split("\\".ToCharArray());
47
 
48
         if (current_pkg.Name.Equals(package_names[0]))
49
         {
50
            if (package_names.GetLength(0) > 1)
51
            {
52
               // prepare the package path for the possible recursion by removing the token we have just
53
               // matched (plus any '\' char which is assumed to be present) from the fron of the string.
54
               package_path = package_path.Remove(0, package_names[0].Length + 1);
55
            }
56
            else
57
            {
58
               // package_path has no more items in it, and we have matched the first item, so we are done
59
               // Exit returning the current package
60
               return current_pkg;
61
            }
62
         }
63
 
64
         foreach(EA.Package subPackage in current_pkg.Packages)
65
         {
66
            EA.Package returned_package = findNamedPackage(subPackage, package_path);
67
            if (returned_package != null)
68
            {
69
               return returned_package;
70
            }
71
         }
72
 
73
         return null;
74
      }
75
 
76
 
2106 ghuddy 77
      public static void identifyClipboardItem()
78
      {
79
         object o = null;
2088 ghuddy 80
 
2106 ghuddy 81
         Main.EA_Repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);
82
         Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "", -1);
83
         Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "Name : " + GUID_Clipboard.name, -1);
84
         Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "GUID : " + GUID_Clipboard.guid, -1);
85
         if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
86
         {
87
            Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "Type : Package", -1);
88
            o = Main.EA_Repository.GetPackageByGuid(GUID_Clipboard.guid);
89
         }
90
         else if (GUID_Clipboard.objType == EA.ObjectType.otElement)
91
         {
92
            Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "Type : Element", -1);
93
            o = Main.EA_Repository.GetElementByGuid(GUID_Clipboard.guid);
94
         }
95
         else if (GUID_Clipboard.objType == EA.ObjectType.otDiagram)
96
         {
97
            Main.EA_Repository.WriteOutput(Main.GUI_OUTPUT_TAB_NAME, "Type : Diagram", -1);
98
            o = Main.EA_Repository.GetDiagramByGuid(GUID_Clipboard.guid);
99
         }
100
         if (o != null)
101
         {
102
            Main.EA_Repository.ShowInProjectView(o);
103
         }
104
      }
2088 ghuddy 105
 
2106 ghuddy 106
      public static void updateLink()
107
      {
108
         EA.ObjectType objType;
109
         object obj;
2094 ghuddy 110
 
2106 ghuddy 111
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
112
         if (objType == EA.ObjectType.otElement)
113
         {
114
            EA.Element ele = (EA.Element)obj;
2094 ghuddy 115
 
2106 ghuddy 116
            if (ele.Name.StartsWith(EA_Constants.EA_DocGenBaseName)
117
               && ele.Name.IndexOf("Link") > 0)
118
            {
119
               char[] sep = new char[] {'\r', '\n'};
120
               string[] strings = ele.Notes.Split(sep, 50);
121
               foreach(string s in strings)
122
               {
123
                  if (s.Length > 0 && s[0] == '{')
124
                  {
125
                     if (ele.Name.StartsWith(EA_Constants.EA_DocGenDiagramLink))
126
                     {
127
                        EA.Diagram diag = (EA.Diagram)Main.EA_Repository.GetDiagramByGuid(s);
128
                        if (diag != null)
129
                        {
130
                           ele.Name = EA_Constants.EA_DocGenDiagramLink + " - " + GetPackagePath(diag.PackageID, diag.Name);
131
                           ele.Update();
132
                           Main.EA_Repository.RefreshModelView(ele.PackageID);
133
                           Main.EA_Repository.ShowInProjectView(ele);
134
                           return;
135
                        }
136
                     }
137
                     else if (ele.Name.StartsWith(EA_Constants.EA_DocGenElementLink))
138
                     {
139
                        EA.Element e = (EA.Element)Main.EA_Repository.GetElementByGuid(s);
140
                        if (e != null)
141
                        {
142
                           ele.Name = EA_Constants.EA_DocGenElementLink + " - " + GetPackagePath(e.PackageID, e.Name);
143
                           ele.Update();
144
                           Main.EA_Repository.RefreshModelView(ele.PackageID);
145
                           Main.EA_Repository.ShowInProjectView(ele);
146
                           return;
147
                        }
148
                     }
149
                     else if (ele.Name.StartsWith(EA_Constants.EA_DocGenPackageLink))
150
                     {
151
                        EA.Package p = (EA.Package)Main.EA_Repository.GetPackageByGuid(s);
152
                        if (p != null)
153
                        {
154
                           ele.Name = EA_Constants.EA_DocGenPackageLink + " - " + GetPackagePath(p.PackageID, p.Name);
155
                           ele.Update();
156
                           Main.EA_Repository.RefreshModelView(ele.PackageID);
157
                           Main.EA_Repository.ShowInProjectView(ele);
158
                           return;
159
                        }
160
                     }
161
                     else if (ele.Name.StartsWith(EA_Constants.EA_DocGenNameLink))
162
                     {
163
                        EA.Package p = (EA.Package)Main.EA_Repository.GetPackageByGuid(s);
164
                        if (p != null)
165
                        {
166
                           ele.Name = EA_Constants.EA_DocGenNameLink + " - " + GetPackagePath(p.PackageID, p.Name);
167
                           ele.Update();
168
                           Main.EA_Repository.RefreshModelView(ele.PackageID);
169
                           Main.EA_Repository.ShowInProjectView(ele);
170
                           return;
171
                        }
172
                     }
173
                     return;
174
                  }
175
               }
176
               MessageBox.Show("Unable to find link GUID");
177
               return;
178
            }
179
         }
180
         MessageBox.Show("You must select an EA_DocGen link element");
181
      }
182
 
183
      public static void followLink()
2088 ghuddy 184
      {
2106 ghuddy 185
         EA.ObjectType objType;
186
         object obj;
187
 
188
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
189
         if (objType == EA.ObjectType.otElement)
190
         {
191
            EA.Element ele = (EA.Element)obj;
192
 
193
            if (ele.Name.StartsWith(EA_Constants.EA_DocGenBaseName)
194
               && ele.Name.IndexOf("Link") > 0)
195
            {
196
 
197
               if (ele.ElementID != lastLinkID)
198
               {
199
                  nextGuidIndex = 0;
200
               }
201
 
202
               char[] sep = new char[] {'\r', '\n'};
203
               string[] strings = ele.Notes.Split(sep, 50);
204
               int thisGUIDIndex = 0;
205
               for(int i=0; i < 2; i++)
206
               {
207
                  foreach(string s in strings)
208
                  {
209
                     if (s.Length > 0 && s[0] == '{')
210
                     {
211
                        if (thisGUIDIndex < nextGuidIndex)
212
                        {
213
                           thisGUIDIndex++;
214
                           continue;
215
                        }
216
 
217
                        object o = null;
218
                        if (ele.Name.StartsWith(EA_Constants.EA_DocGenDiagramLink))
219
                        {
220
                           o = Main.EA_Repository.GetDiagramByGuid(s);
221
                        }
222
                        else if (ele.Name.StartsWith(EA_Constants.EA_DocGenElementLink))
223
                        {
224
                           o = Main.EA_Repository.GetElementByGuid(s);
225
                        }
226
                        else if (ele.Name.StartsWith(EA_Constants.EA_DocGenPackageLink))
227
                        {
228
                           o = Main.EA_Repository.GetPackageByGuid(s);
229
                        }
230
                        else if (ele.Name.StartsWith(EA_Constants.EA_DocGenNameLink))
231
                        {
232
                           o = Main.EA_Repository.GetPackageByGuid(s);
233
                        }
234
                        if (o != null)
235
                        {
236
                           Main.EA_Repository.ShowInProjectView(o);
237
                           lastLinkID = ele.ElementID;
238
                           nextGuidIndex++;
239
                        }
240
                        else
241
                        {
242
                           MessageBox.Show("Unable to resolve link\r\n" + s);
243
                        }
244
                        return;
245
                     }
246
                  }
247
                  if (nextGuidIndex > 0)
248
                  {
249
                     nextGuidIndex = 0;
250
                  }
251
                  else
252
                  {
253
                     break;
254
                  }
255
               }
256
               MessageBox.Show("Unable to find link GUID");
257
               return;
258
            }
259
         }
260
         MessageBox.Show("You must select an EA_DocGen link element");
2088 ghuddy 261
      }
262
 
2104 ghuddy 263
 
2122 ghuddy 264
      public static EA.Package get_selected_package()
265
      {
266
         object o;
267
         EA.ObjectType type;
268
 
269
         type = Main.EA_Repository.GetTreeSelectedItem(out o);
270
         if (type == EA.ObjectType.otElement)
271
         {
272
            return Main.EA_Repository.GetPackageByID(((EA.Element)o).PackageID);
273
         }
274
         else if (type == EA.ObjectType.otDiagram)
275
         {
276
            return Main.EA_Repository.GetPackageByID(((EA.Diagram)o).PackageID);
277
         }
278
         else if (type == EA.ObjectType.otPackage)
279
         {
280
            return (EA.Package)o;
281
         }
282
         return null;
283
      }
284
 
285
 
286
 
2106 ghuddy 287
      public static void modifyOptions()
2094 ghuddy 288
      {
289
         EA.ObjectType objType;
290
         object obj;
2088 ghuddy 291
 
2106 ghuddy 292
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 293
         if (objType == EA.ObjectType.otElement)
294
         {
295
            EA.Element ele = (EA.Element)obj;
2088 ghuddy 296
 
2094 ghuddy 297
            if (0 == ele.Name.CompareTo(EA_Constants.EA_DocGenBaseName))
298
            {
2108 ghuddy 299
               EA_DocGenOptions.initialise();
300
 
2106 ghuddy 301
               if (true == EA_DocGenOptions.lookForAndProcess_EA_DocGen_Element( ele ))
2094 ghuddy 302
               {
303
                  EA_DocGenOptionsForm dlg = new EA_DocGenOptionsForm();
2106 ghuddy 304
                  dlg.populate();
2094 ghuddy 305
                  DialogResult dlgRes = dlg.ShowDialog();
306
                  if (dlgRes == DialogResult.OK)
307
                  {
2106 ghuddy 308
                     dlg.read();
2088 ghuddy 309
 
2106 ghuddy 310
                     EA_DocGenOptions.updateEA_DocGen(ele);
2094 ghuddy 311
                  }
312
               }
313
            }
314
         }
315
      }
316
 
2104 ghuddy 317
 
2088 ghuddy 318
      /// <summary>
319
      /// Begins the document generation process, opening the dialog to capture input/output
320
      /// files. the createWordDoc dialog class does most of the work ofcoarse.
321
      /// </summary>
2106 ghuddy 322
      public static void createWordDoc()
2088 ghuddy 323
      {
2106 ghuddy 324
         Main.threadCreateDocDialogRunning = true;
2088 ghuddy 325
 
2106 ghuddy 326
         try
2088 ghuddy 327
         {
2122 ghuddy 328
            // Get the package in or under which the EA project browser selection exists
329
            EA.Package pkg = EA_Utilities.get_selected_package();
2106 ghuddy 330
 
2122 ghuddy 331
            EA_DocGenOptions.initialise();
332
 
333
            // Make sure this package has an EA_DocGen element
334
            pkg = EA_DocGenOptions.lookForAndProcess_EA_DocGen_Element(pkg);
335
            if (pkg != null)
2088 ghuddy 336
            {
2122 ghuddy 337
               // bring up the dialog for doc generation
338
               createWordDoc dialog = new createWordDoc(pkg);
339
               dialog.Text = "Generate Document From Model Layout";
340
               dialog.textBox_template.Text    = ReadTag(pkg, "TEMPLATE");
341
               dialog.textBox_output_file.Text = ReadTag(pkg, "DOCFILE");
342
               dialog.ShowDialog();
343
               WriteTag(pkg, "TEMPLATE", dialog.textBox_template.Text); 
344
               WriteTag(pkg, "DOCFILE",  dialog.textBox_output_file.Text);
2094 ghuddy 345
            }
2088 ghuddy 346
            else
347
            {
2122 ghuddy 348
               MessageBox.Show("ERROR, failed to find EA_DocGen element.");
2088 ghuddy 349
            }
2122 ghuddy 350
 
2088 ghuddy 351
         }
2106 ghuddy 352
         catch(Exception e)
2088 ghuddy 353
         {
2106 ghuddy 354
            MessageBox.Show(e.Message);
2094 ghuddy 355
         }
2106 ghuddy 356
         Main.threadCreateDocDialogRunning = false;
2088 ghuddy 357
      }
358
 
359
 
360
      /// <summary>
361
      /// Creates a package under the specified parent package. the package is given a tree position
362
      /// as specified in order for it to be ordered in the model as the caller requires.
363
      /// </summary>
364
      /// <param name="parentPackage"></param>
365
      /// <param name="name"></param>
366
      /// <param name="treePos"></param>
367
      /// <returns></returns>
2106 ghuddy 368
      public static EA.Package createPackage(EA.Package parentPackage, string name, int treePos)
2088 ghuddy 369
      {
370
         EA.Package newobj = (EA.Package)parentPackage.Packages.AddNew(name, "Package");
371
         newobj.TreePos = treePos;
372
         newobj.Update();
373
         return newobj;
374
      }
375
 
2094 ghuddy 376
 
2088 ghuddy 377
      /// <summary>
378
      /// Generate a package hierarchy that reflects the document layout of BMS-00289, the
379
      /// ERG Product Software Design Document.
380
      /// </summary>
2106 ghuddy 381
      public static void create_BMS00289_Layout()
2088 ghuddy 382
      {
383
         EA.ObjectType objType;
384
         object obj;
385
 
2106 ghuddy 386
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 387
         if (objType == EA.ObjectType.otPackage)
388
         {
2094 ghuddy 389
            if (  ((EA.Package)obj).Packages.Count == 0
2088 ghuddy 390
               && ((EA.Package)obj).Elements.Count == 0
391
               && ((EA.Package)obj).Diagrams.Count == 0 )
392
            {
393
               EA.Package parentPackage = ((EA.Package)obj);
394
 
395
               EA.Package newobj = null;
396
               EA.Package newobj2 = null;
397
               EA.Package newobj3 = null;
398
               EA.Package newobj4 = null;
399
               EA.Package newobj5 = null;
400
 
401
               newobj  = createPackage(parentPackage, "Introduction", 1);
402
               newobj2 = createPackage(newobj, "Purpose", 1);
403
               newobj2 = createPackage(newobj, "Scope", 2);
404
               newobj2 = createPackage(newobj, "Terminology", 3);
405
               newobj2 = createPackage(newobj, "References", 4);
406
 
407
               newobj  = createPackage(parentPackage, "Design Assumptions And Constraints", 2);
408
 
409
               newobj  = createPackage(parentPackage, "System Overview", 3);
410
 
411
               newobj  = createPackage(parentPackage, "High Level Design", 4);
412
               newobj2 = createPackage(newobj, "Software Architecture", 1);
413
               newobj2 = createPackage(newobj, "External Interfaces", 2);
414
               newobj2 = createPackage(newobj, "Internal Interfaces", 3);
415
               newobj2 = createPackage(newobj, "Memory And Processing Time Allocation", 4);
416
               newobj2 = createPackage(newobj, "Operational Modes", 5);
417
               newobj2 = createPackage(newobj, "Component Descriptions", 6);
418
 
419
               newobj = createPackage(parentPackage, "Detailed Design", 5);
420
 
421
               newobj = createPackage(parentPackage, "Unit Test Design",6);
422
 
423
               newobj2 = createPackage(newobj, "Test Data", 1);
424
               newobj2 = createPackage(newobj, "Test Stubs", 2);
425
               newobj2 = createPackage(newobj, "Other Elements", 3);
426
               newobj2 = createPackage(newobj, "Unit Test Traceability To Design", 4);
427
               newobj2 = createPackage(newobj, "Test Suites and Test Cases", 5);
428
               newobj3 = createPackage(newobj2, "Test Suite Name", 1);
429
               newobj4 = createPackage(newobj3, "Test Name", 1);
430
               newobj5 = createPackage(newobj4, "Description", 1);
431
               newobj5 = createPackage(newobj4, "Inputs", 2);
432
               newobj5 = createPackage(newobj4, "Expected Outputs", 3);
433
 
434
               newobj = createPackage(parentPackage, "Requirements Traceability", 7);
435
 
436
               // create an EA_DocGen element
437
               EA.Element newElement = (EA.Element)parentPackage.Elements.AddNew( "EA_DocGen", "InformationItem" );
2094 ghuddy 438
               newElement.Notes = "[ElementTypes]\r\nRequirement\r\nClass\r\nComponent\r\n";
2088 ghuddy 439
               newElement.Update();
440
 
441
               parentPackage.Packages.Refresh();
442
 
443
               // refresh project browser view
2106 ghuddy 444
               Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
2088 ghuddy 445
            }
446
            else
447
            {
448
               MessageBox.Show("Can only insert layout into an empty package");
449
            }
450
         }
451
         else
452
         {
453
            MessageBox.Show("You must select a package into which the layout will be inserted");
454
         }
455
      }
456
 
457
 
458
      /// <summary>
2094 ghuddy 459
      /// Generate a package hierarchy that reflects a basic document layout.
460
      /// </summary>
2106 ghuddy 461
      public static void create_basic_Layout()
2094 ghuddy 462
      {
463
         EA.ObjectType objType;
464
         object obj;
465
 
2106 ghuddy 466
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 467
         if (objType == EA.ObjectType.otPackage)
468
         {
469
            if (  ((EA.Package)obj).Packages.Count == 0
470
               && ((EA.Package)obj).Elements.Count == 0
471
               && ((EA.Package)obj).Diagrams.Count == 0 )
472
            {
473
               EA.Package parentPackage = ((EA.Package)obj);
474
 
475
               EA.Package newobj = null;
476
               EA.Package newobj2 = null;
477
               //EA.Package newobj3 = null;
478
               //EA.Package newobj4 = null;
479
               //EA.Package newobj5 = null;
480
 
481
               newobj  = createPackage(parentPackage, "Introduction", 1);
482
               newobj2 = createPackage(newobj, "Purpose", 1);
483
               newobj2 = createPackage(newobj, "Scope", 2);
484
               newobj2 = createPackage(newobj, "Terminology", 3);
485
               newobj2 = createPackage(newobj, "References", 4);
486
 
487
               newobj  = createPackage(parentPackage, "Section 2 (rename me as required)", 2);
488
 
489
               newobj  = createPackage(parentPackage, "Section 3 (rename me as required)", 3);
490
 
491
               // create an EA_DocGen element
492
               EA.Element newElement = (EA.Element)parentPackage.Elements.AddNew( EA_Constants.EA_DocGenBaseName,
493
                                                                                  EA_Constants.EA_DocGenElementType );
494
               newElement.Notes = "[ElementTypes]\r\nRequirement\r\nClass\r\nComponent\r\n";
495
               newElement.Update();
496
 
497
               parentPackage.Packages.Refresh();
498
 
499
               // refresh project browser view
2106 ghuddy 500
               Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
2094 ghuddy 501
            }
502
            else
503
            {
504
               MessageBox.Show("Can only insert layout into an empty package");
505
            }
506
         }
507
         else
508
         {
509
            MessageBox.Show("You must select a package into which the layout will be inserted");
510
         }
511
      }
512
 
513
 
514
      /// <summary>
2114 ghuddy 515
      /// Generate a package hierarchy that reflects the standard design views.
516
      /// </summary>
517
      public static void create_StandardView_Layout()
518
      {
519
         EA.ObjectType objType;
520
         object obj;
521
 
522
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
523
         if (objType == EA.ObjectType.otPackage)
524
         {
525
            EA.Package parentPackage = ((EA.Package)obj);
526
 
527
            EA.Package newobj = null;
528
 
529
            newobj  = createPackage(parentPackage, "Component View", 1);
530
 
531
            newobj  = createPackage(parentPackage, "Deployment View", 2);
532
 
533
            newobj  = createPackage(parentPackage, "Document View", 3);
534
 
535
            newobj  = createPackage(parentPackage, "Logical View", 4);
536
 
537
            newobj = createPackage(parentPackage, "Dynamic View", 5);
538
 
539
            newobj = createPackage(parentPackage, "Requirement View",6);
540
 
541
            newobj = createPackage(parentPackage, "Use Case View", 7);
542
 
543
            parentPackage.Packages.Refresh();
544
 
545
            // refresh project browser view
546
            Main.EA_Repository.RefreshModelView(parentPackage.PackageID);
547
         }
548
         else
549
         {
550
            MessageBox.Show("You must select a package into which the layout will be inserted");
551
         }
552
      }
553
 
554
 
555
      /// <summary>
2088 ghuddy 556
      /// This function works its way up the parental hierarchy to the root model, collecting the
2094 ghuddy 557
      /// strings names of each package and prepending them to a string accumulator with a view to
2088 ghuddy 558
      /// obtaing the full path of an element,diagram, or package.
559
      /// </summary>
560
      /// <param name="parentId"></param>
561
      /// <param name="instr"></param>
562
      /// <returns></returns>
2106 ghuddy 563
      public static string GetPackagePath( int parentId, string instr )
2088 ghuddy 564
      {
565
         if (parentId != 0)
566
         {
567
            EA.Package pkg;
2106 ghuddy 568
            pkg = Main.EA_Repository.GetPackageByID( parentId );
2088 ghuddy 569
            if (pkg != null)
570
            {
571
               instr = pkg.Name + "/" + instr;
572
               instr = GetPackagePath(pkg.ParentID, instr);
2094 ghuddy 573
            }
2088 ghuddy 574
         }
575
         return instr;
576
      }
577
 
578
 
2106 ghuddy 579
      private static void copy_GUID_to_clipboard(object obj, EA.ObjectType objType, bool confirm)
2088 ghuddy 580
      {
2106 ghuddy 581
         GUID_Clipboard.copy(obj, objType, confirm);
2088 ghuddy 582
      }
583
 
2094 ghuddy 584
 
2088 ghuddy 585
      /// <summary>
2094 ghuddy 586
      /// For the selected item, copy its GUID to the internal add-in GUID clipboard and the
2088 ghuddy 587
      /// global external clipboard. Also copy to the internal add-in GUID clipboard, the name of
588
      /// the element and its type. This will support the AddLinkElement() method.
589
      /// </summary>
2106 ghuddy 590
      public static void copy_GUID_to_clipboard()
2088 ghuddy 591
      {
592
         EA.ObjectType objType;
593
         object obj;
2106 ghuddy 594
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
595
         GUID_Clipboard.copy(obj, objType, true);
2088 ghuddy 596
      }
597
 
598
 
2106 ghuddy 599
      public static void AddTestTraceabilityElement()
2094 ghuddy 600
      {
601
         EA.ObjectType objType;
602
         object obj;
2106 ghuddy 603
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 604
         AddTestTraceabilityElement(obj, objType);
605
      }
2106 ghuddy 606
      public static void AddTestTraceabilityElement(object obj, EA.ObjectType objType)
2094 ghuddy 607
      {
608
         if (objType == EA.ObjectType.otPackage)
609
         {
610
            object newobj = null;
2088 ghuddy 611
 
2094 ghuddy 612
            newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenTestTraceability, EA_Constants.EA_DocGenElementType);
613
            if (newobj != null)
614
            {
615
               ((EA.Element)newobj).Update();
616
            }         
617
         }
618
         else
619
         {
620
            MessageBox.Show("You must select a package into which the element will be inserted");
621
         }
622
      }
623
 
2104 ghuddy 624
 
2094 ghuddy 625
      /// <summary>
626
      /// Using the internal add-in GUID clipboard, paste a test link element into the selected
627
      /// package.
628
      /// </summary>
2106 ghuddy 629
      public static void AddTestLinkElement()
2094 ghuddy 630
      {
631
         EA.ObjectType objType;
632
         object obj;
2106 ghuddy 633
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 634
         AddTestLinkElement(obj, objType);
635
      }
636
 
2106 ghuddy 637
      private static void AddTestLinkElement(object obj, EA.ObjectType objType)
2094 ghuddy 638
      {
639
         if (objType == EA.ObjectType.otPackage)
640
         {
641
            object newobj = null;
642
 
2106 ghuddy 643
            if (   GUID_Clipboard.objType == EA.ObjectType.otElement
644
                || GUID_Clipboard.objType == EA.ObjectType.otPackage)
2094 ghuddy 645
            {
2106 ghuddy 646
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenTestLink + " - " + GUID_Clipboard.name, EA_Constants.EA_DocGenElementType);
2094 ghuddy 647
 
648
               if (newobj != null)
649
               {
2106 ghuddy 650
                  ((EA.Element)newobj).Notes = GUID_Clipboard.name + "\r\n" + GUID_Clipboard.guid;
2094 ghuddy 651
                  ((EA.Element)newobj).Update();
652
               }
653
            }
654
            else
655
            {
656
               MessageBox.Show("The GUID clipboard must first contain the GUID of an element (normally, a class), or a package");
657
            }
658
         }
659
         else
660
         {
661
            MessageBox.Show("You must select a package into which the test link will be inserted");
662
         }
663
      }
664
 
665
 
666
      /// <summary>
667
      /// Using the internal add-in GUID clipboard, paste a link element into the selected
668
      /// package.
669
      /// </summary>
2106 ghuddy 670
      public static void AddLinkElement()
2094 ghuddy 671
      {
672
         EA.ObjectType objType;
673
         object obj;
2106 ghuddy 674
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 675
         AddLinkElement(obj, objType);
676
      }
677
 
2106 ghuddy 678
      private static void AddLinkElement(object obj, EA.ObjectType objType)
2088 ghuddy 679
      {
680
         if (objType == EA.ObjectType.otPackage)
681
         {
682
            object newobj = null;
683
 
2106 ghuddy 684
            if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
2088 ghuddy 685
            {
2106 ghuddy 686
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenPackageLink + " - " + GUID_Clipboard.name, EA_Constants.EA_DocGenElementType);
2088 ghuddy 687
            }
2106 ghuddy 688
            else if (GUID_Clipboard.objType == EA.ObjectType.otDiagram)
2088 ghuddy 689
            {
2106 ghuddy 690
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenDiagramLink + " - " + GUID_Clipboard.name, EA_Constants.EA_DocGenElementType);
2088 ghuddy 691
            }
2106 ghuddy 692
            else if (GUID_Clipboard.objType == EA.ObjectType.otElement)
2088 ghuddy 693
            {
2106 ghuddy 694
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenElementLink + " - " + GUID_Clipboard.name, EA_Constants.EA_DocGenElementType);
2088 ghuddy 695
            }
2106 ghuddy 696
            else if (GUID_Clipboard.objType == EA.ObjectType.otAttribute)
2088 ghuddy 697
            {
698
               MessageBox.Show("Attribute links are not currently supported");
699
            }
2106 ghuddy 700
            else if (GUID_Clipboard.objType == EA.ObjectType.otMethod)
2088 ghuddy 701
            {
702
               MessageBox.Show("Method links are not currently supported");
703
            }
704
 
705
            if (newobj != null)
706
            {
2106 ghuddy 707
               ((EA.Element)newobj).Notes = GUID_Clipboard.name + "\r\n" + GUID_Clipboard.guid;
2088 ghuddy 708
               ((EA.Element)newobj).Update();
709
            }
710
         }
711
         else
712
         {
713
            MessageBox.Show("You must select a package into which the link will be inserted");
2094 ghuddy 714
         }
2088 ghuddy 715
      }
716
 
2094 ghuddy 717
 
2106 ghuddy 718
      public static void AddNameLinkElement()
2104 ghuddy 719
      {
720
         EA.ObjectType objType;
721
         object obj;
2106 ghuddy 722
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2104 ghuddy 723
         AddNameLinkElement(obj, objType);
724
      }
725
 
2106 ghuddy 726
      private static void AddNameLinkElement(object obj, EA.ObjectType objType)
2104 ghuddy 727
      {
728
         if (objType == EA.ObjectType.otPackage)
729
         {
730
            object newobj = null;
731
 
2106 ghuddy 732
            if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
2104 ghuddy 733
            {
2106 ghuddy 734
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenNameLink + " - " + GUID_Clipboard.name, EA_Constants.EA_DocGenElementType);
2104 ghuddy 735
               if (newobj != null)
736
               {
737
                  StringBuilder sb = new StringBuilder();
2106 ghuddy 738
                  sb.Append(GUID_Clipboard.name);
2104 ghuddy 739
                  sb.Append("\r\n");
2106 ghuddy 740
                  sb.Append(GUID_Clipboard.guid);
2104 ghuddy 741
                  sb.Append("\r\n");
742
                  sb.Append("### Add as many package names as you like below here.\r\n");
743
                  sb.Append("### Each should be of the form: package=name\r\n");
744
                  sb.Append("### Delete any unused package= lines from these notes.\r\n");
745
                  sb.Append("### The names are case sensitive and must match exactly\r\n");
746
                  sb.Append("### the names of the packages you wish to pull in to the\r\n");
747
                  sb.Append("### document model.\r\n");
748
                  sb.Append("package=\r\n");
749
                  sb.Append("package=\r\n");
750
                  sb.Append("package=\r\n");
751
 
752
                  ((EA.Element)newobj).Notes = sb.ToString();
753
                  ((EA.Element)newobj).Update();
754
               }            
755
            }
756
         }
757
         else
758
         {
759
            MessageBox.Show("You must select a package into which the name link will be inserted");
760
         }
761
      }
762
 
763
 
2106 ghuddy 764
      public static void AddTableElement()
2088 ghuddy 765
      {
766
         EA.ObjectType objType;
767
         object obj;
768
 
2106 ghuddy 769
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 770
         if (objType == EA.ObjectType.otPackage)
771
         {
772
            object newobj = null;
2088 ghuddy 773
 
2094 ghuddy 774
            newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenTable, EA_Constants.EA_DocGenElementType);
775
            if (newobj != null)
776
            {
777
               ((EA.Element)newobj).Notes = "title=insertYourTitleHere\r\n"
778
                                          + "columns=2\r\n"
779
                                          + "seperator=,\r\n"
2104 ghuddy 780
                                          + "indent=1\r\n"
781
                                          + "widths=column1Width,column2Width\r\n"
2094 ghuddy 782
                                          + "column1Title,column2Title\r\n"
783
                                          + "cellcontent,cellcontent\r\n"
2104 ghuddy 784
                                          + "cellcontent,cellcontent\r\n"
785
                                          + "cellcontent,cellcontent\r\n"
2094 ghuddy 786
                                          + "etc,etc";
787
               ((EA.Element)newobj).Update();
788
            }
789
         }
790
         else
791
         {
792
            MessageBox.Show("You must select a package into which the Table Element will be inserted");
793
         }
2088 ghuddy 794
      }
795
 
796
 
2106 ghuddy 797
      public static void AddTextElement()
2094 ghuddy 798
      {
799
         EA.ObjectType objType;
800
         object obj;
801
 
2106 ghuddy 802
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 803
         if (objType == EA.ObjectType.otPackage)
804
         {
805
            object newobj = null;
806
 
807
            newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenText, EA_Constants.EA_DocGenElementType);
808
            if (newobj != null)
809
            {
810
               ((EA.Element)newobj).Notes = "Add your text here.";
811
               ((EA.Element)newobj).Update();
812
            }
813
         }
814
         else
815
         {
816
            MessageBox.Show("You must select a package into which the Text Element will be inserted");
817
         }
818
      }
819
 
820
 
2106 ghuddy 821
      public static void AddRelationshipMatrixElement()
2094 ghuddy 822
      {
823
         EA.ObjectType objType;
824
         object obj;
825
 
2106 ghuddy 826
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2094 ghuddy 827
         if (objType == EA.ObjectType.otPackage)
828
         {
2104 ghuddy 829
            RelationshipMatrixType dlg = new RelationshipMatrixType();
830
            DialogResult dlgRes = dlg.ShowDialog();
831
            if (dlgRes == DialogResult.OK)
2094 ghuddy 832
            {
2104 ghuddy 833
               object newobj = null;
834
               newobj = ((EA.Package)obj).Elements.AddNew(EA_Constants.EA_DocGenRelationshipMatrix, EA_Constants.EA_DocGenElementType);
835
               if (newobj != null)
836
               {
837
                  ((EA.Element)newobj).Notes  = EA_RelationshipMatrix.optionTemplateForRelationshipMatrix(dlg.style());
838
                  ((EA.Element)newobj).Update();
839
               }
2094 ghuddy 840
            }
841
         }
842
         else
843
         {
844
            MessageBox.Show("You must select a package into which the RelationshipMatrix Element will be inserted");
845
         }
846
      }
847
 
848
 
2106 ghuddy 849
      public static void GeneratePackagesFromElementList()
2088 ghuddy 850
      {
851
         EA.ObjectType objType;
852
         object obj;
853
 
2106 ghuddy 854
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 855
         if (objType == EA.ObjectType.otPackage)
856
         {
2106 ghuddy 857
            if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
2088 ghuddy 858
            {
2106 ghuddy 859
               EA.Package theFoundPackage = Main.EA_Repository.GetPackageByGuid(GUID_Clipboard.guid);
2088 ghuddy 860
               if (theFoundPackage != null)
861
               {
862
                  EA.Package srcPackage = theFoundPackage;
863
                  EA.Package destPackage = ((EA.Package)obj);
2094 ghuddy 864
 
2088 ghuddy 865
                  foreach( EA.Element srcElement in srcPackage.Elements)
866
                  {
2132 ghuddy 867
                     if (false == EA_Finders.elementNameExistsInPackage(destPackage, srcElement.Name))
2088 ghuddy 868
                     {
2132 ghuddy 869
                        createPackage(destPackage, srcElement.Name, 1);
2088 ghuddy 870
                     }
871
                  }
2094 ghuddy 872
               }
2088 ghuddy 873
            }
874
            else
875
            {
876
               MessageBox.Show("You must first copy a Source Package GUID to the clipboard");
877
            }
878
         }
879
         else
880
         {
881
            MessageBox.Show("You must select a Destination Package into which the Generated Packages will be inserted");
882
         }
883
      }
884
 
885
 
2106 ghuddy 886
      public static void GenerateSubPackageLinks()
2088 ghuddy 887
      {
888
         EA.ObjectType objType;
889
         object obj;
890
 
2106 ghuddy 891
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 892
         if (objType == EA.ObjectType.otPackage)
893
         {
2106 ghuddy 894
            if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
2088 ghuddy 895
            {
2106 ghuddy 896
               EA.Package theFoundPackage = Main.EA_Repository.GetPackageByGuid(GUID_Clipboard.guid);
2088 ghuddy 897
               if (theFoundPackage != null)
898
               {
899
                  EA.Package srcPackage = theFoundPackage;
900
                  EA.Package destPackage = ((EA.Package)obj);
2094 ghuddy 901
 
2106 ghuddy 902
                  GUID_Clipboard.push();
903
 
2088 ghuddy 904
                  foreach( EA.Package subPackage in srcPackage.Packages)
905
                  {
906
                     copy_GUID_to_clipboard( (object)subPackage, EA.ObjectType.otPackage, false);
907
                     AddLinkElement( (object)destPackage, EA.ObjectType.otPackage);
908
                  }
2106 ghuddy 909
 
910
                  GUID_Clipboard.pop();
2094 ghuddy 911
               }
2088 ghuddy 912
            }
913
            else
914
            {
915
               MessageBox.Show("You must first copy a Source Package GUID to the clipboard");
916
            }
917
         }
918
         else
919
         {
920
            MessageBox.Show("You must select a Destination Package into which the Sub-Package Links will be inserted");
921
         }
922
      }
923
 
924
 
2106 ghuddy 925
      public static void GenerateElementLinks()
2088 ghuddy 926
      {
927
         EA.ObjectType objType;
928
         object obj;
929
 
2106 ghuddy 930
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 931
         if (objType == EA.ObjectType.otPackage)
932
         {
2106 ghuddy 933
            if (GUID_Clipboard.objType == EA.ObjectType.otPackage)
2088 ghuddy 934
            {
2106 ghuddy 935
               EA.Package theFoundPackage = Main.EA_Repository.GetPackageByGuid(GUID_Clipboard.guid);
2088 ghuddy 936
               if (theFoundPackage != null)
937
               {
938
                  EA.Package srcPackage = theFoundPackage;
939
                  EA.Package destPackage = ((EA.Package)obj);
2094 ghuddy 940
 
2106 ghuddy 941
                  GUID_Clipboard.push();
942
 
2088 ghuddy 943
                  foreach( EA.Element subElement in srcPackage.Elements)
944
                  {
945
                     copy_GUID_to_clipboard( (object)subElement, EA.ObjectType.otElement, false);
946
                     AddLinkElement( (object)destPackage, EA.ObjectType.otPackage);
947
                  }
2106 ghuddy 948
 
949
                  GUID_Clipboard.pop();
2094 ghuddy 950
               }
2088 ghuddy 951
            }
952
            else
953
            {
954
               MessageBox.Show("You must first copy a Source Package GUID to the clipboard");
955
            }
956
         }
957
         else
958
         {
959
            MessageBox.Show("You must select a Destination Package into which the Element Links will be inserted");
2094 ghuddy 960
         }
2088 ghuddy 961
      }
962
 
2094 ghuddy 963
      /// <summary>
964
      /// This function is designed to parse EA models/packages in a predefined way, whilst allowing
965
      /// a user to specify what processing is to be done upon or with each element found.
966
      /// </summary>
967
      /// <param name="thePackage"></param>
968
      /// <param name="worker"></param>
969
      /// <param name="recurse"></param>
2106 ghuddy 970
      public static void findAndProcessPackageElements( EA.Package thePackage, EA_UtilitiesRecursionWorker worker, bool recurse)
2088 ghuddy 971
      {
2094 ghuddy 972
         worker.processPackage( thePackage );
2088 ghuddy 973
 
2094 ghuddy 974
         foreach (EA.Element theElement in thePackage.Elements)
2088 ghuddy 975
         {
2094 ghuddy 976
            worker.processElement( theElement );
977
         }
2088 ghuddy 978
 
2094 ghuddy 979
         if (recurse == true)
980
         {
981
            foreach (EA.Package subPackage in thePackage.Packages)
2088 ghuddy 982
            {
2094 ghuddy 983
               // RECURSION
984
               findAndProcessPackageElements( subPackage, worker, true);
2088 ghuddy 985
            }
986
         }
2094 ghuddy 987
 
2088 ghuddy 988
      }
989
 
2094 ghuddy 990
 
2106 ghuddy 991
      public static void addDocumentReference()
2088 ghuddy 992
      {
993
         EA.ObjectType objType;
994
         object obj;
995
 
2106 ghuddy 996
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 997
         if (objType == EA.ObjectType.otPackage)
998
         {
2094 ghuddy 999
            DocReferenceForm dlg = new DocReferenceForm();
1000
            DialogResult dlgRes = dlg.ShowDialog();
1001
            if (dlgRes == DialogResult.OK)
1002
            {
1003
               object newobj = null;
2088 ghuddy 1004
 
2094 ghuddy 1005
               newobj = ((EA.Package)obj).Elements.AddNew(dlg.textBox_DocNumber.Text, EA_Constants.EA_DocGenElementType);
1006
               if (newobj != null)
1007
               {
1008
                  ((EA.Element)newobj).Notes = dlg.textBox_DocName.Text;
1009
                  ((EA.Element)newobj).Update();
1010
               }
2088 ghuddy 1011
            }
1012
         }
1013
      }
1014
 
2094 ghuddy 1015
 
2106 ghuddy 1016
      public static void addTerminology()
2088 ghuddy 1017
      {
1018
         EA.ObjectType objType;
1019
         object obj;
1020
 
2106 ghuddy 1021
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 1022
         if (objType == EA.ObjectType.otPackage)
1023
         {
2094 ghuddy 1024
            TerminologyForm dlg = new TerminologyForm();
1025
            DialogResult dlgRes = dlg.ShowDialog();
1026
            if (dlgRes == DialogResult.OK)
1027
            {
1028
               object newobj = null;
2088 ghuddy 1029
 
2094 ghuddy 1030
               newobj = ((EA.Package)obj).Elements.AddNew(dlg.textBox_Term.Text, EA_Constants.EA_DocGenElementType);
1031
               if (newobj != null)
1032
               {
1033
                  ((EA.Element)newobj).Notes = dlg.textBox_TermExpansion.Text;
1034
                  ((EA.Element)newobj).Update();
1035
               }
2088 ghuddy 1036
            }
1037
         }
1038
      }
1039
 
1040
 
2106 ghuddy 1041
      public static string ReadTag(EA.Package thePackage, string tagName)
2098 ghuddy 1042
      {
2106 ghuddy 1043
         EA.Element theElement = Main.EA_Repository.GetElementByGuid(thePackage.PackageGUID);
1044
         if (theElement != null)
1045
         {
1046
            return ReadTag(theElement, tagName);
1047
         }
1048
         return "";
1049
      }
1050
 
1051
      public static string ReadTag(EA.Element theElement, string tagName)
1052
      {
2098 ghuddy 1053
         string result;
1054
 
1055
         EA.TaggedValue tag = (EA.TaggedValue)theElement.TaggedValues.GetByName(tagName);
1056
         if (null != tag)
1057
         {
1058
            result = tag.Value;
1059
         }
1060
         else
1061
         {
1062
            result = "";
1063
         }
1064
         return result;
1065
      }
1066
 
2106 ghuddy 1067
      public static bool WriteTag(EA.Package thePackage, string tagName, string value)
1068
      {
1069
         EA.Element theElement = Main.EA_Repository.GetElementByGuid(thePackage.PackageGUID);
1070
         if (theElement != null)
1071
         {
1072
            return WriteTag(theElement, tagName, value);
1073
         }
1074
         return false;
1075
      }
2098 ghuddy 1076
 
2106 ghuddy 1077
      public static bool WriteTag(EA.Element theElement, string tagName, string value)
2098 ghuddy 1078
      {
1079
         bool result;
1080
         EA.TaggedValue tag;
1081
 
1082
         tag = (EA.TaggedValue)theElement.TaggedValues.GetByName(tagName);
1083
         if (null != tag)
1084
         {
1085
            tag.Value = value;
1086
         }
1087
         else
1088
         {
1089
            tag = (EA.TaggedValue)theElement.TaggedValues.AddNew(tagName, value);
1090
         }
1091
 
1092
         if (tag != null)
1093
         {
1094
            result = tag.Update();
1095
         }
1096
         else
1097
         {
1098
            result = false;
1099
         }
1100
         return result;
1101
      }
1102
 
1103
 
2106 ghuddy 1104
      public static void RemoveAPIStereotypeFromContent()
2104 ghuddy 1105
      {
1106
         EA.ObjectType objType;
1107
         object obj;
2106 ghuddy 1108
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2104 ghuddy 1109
         if (objType == EA.ObjectType.otPackage)
1110
         {
1111
            RemoveAPIStereotypeFromContent((EA.Package)obj);
2106 ghuddy 1112
            Main.EA_Repository.RefreshModelView(((EA.Package)obj).PackageID);
2104 ghuddy 1113
         }
1114
         else if (objType == EA.ObjectType.otDiagram)
1115
         {
1116
            RemoveAPIStereotypeFromDiagram((EA.Diagram)obj);
2106 ghuddy 1117
            Main.EA_Repository.RefreshModelView(((EA.Diagram)obj).PackageID);
2104 ghuddy 1118
         }
1119
         else if (objType == EA.ObjectType.otElement)
1120
         {
1121
            RemoveAPIStereotypeFromContent((EA.Element)obj);
2106 ghuddy 1122
            Main.EA_Repository.RefreshModelView(((EA.Element)obj).PackageID);
2104 ghuddy 1123
         }
1124
      }
1125
 
2106 ghuddy 1126
      private static void RemoveAPIStereotypeFromPackage(EA.Package thePackage)
2104 ghuddy 1127
      {
1128
         thePackage.StereotypeEx = thePackage.StereotypeEx.Replace(",API","");
1129
         thePackage.StereotypeEx = thePackage.StereotypeEx.Replace("API,","");
1130
         thePackage.StereotypeEx = thePackage.StereotypeEx.Replace("API","");
1131
         thePackage.Update();
1132
      }
1133
 
2106 ghuddy 1134
      private static void RemoveAPIStereotypeFromDiagram(EA.Diagram theDiagram)
2104 ghuddy 1135
      {
1136
         // diagrams only use one stereotype, not a list of them
1137
         if (theDiagram.Stereotype.Equals("API"))
1138
         {
1139
            theDiagram.Stereotype = "";
1140
            theDiagram.Update();
1141
         }
1142
      }
1143
 
2106 ghuddy 1144
      private static void RemoveAPIStereotypeFromElement(EA.Element theElement)
2104 ghuddy 1145
      {
1146
         theElement.StereotypeEx = theElement.StereotypeEx.Replace(",API","");
1147
         theElement.StereotypeEx = theElement.StereotypeEx.Replace("API,","");
1148
         theElement.StereotypeEx = theElement.StereotypeEx.Replace("API","");
1149
         theElement.Update();
1150
      }
1151
 
2106 ghuddy 1152
      private static void RemoveAPIStereotypeFromContent(EA.Package thePackage)
2104 ghuddy 1153
      {
1154
         RemoveAPIStereotypeFromPackage(thePackage);
1155
 
1156
         foreach(EA.Diagram diagram in thePackage.Diagrams)
1157
         {
1158
            RemoveAPIStereotypeFromDiagram(diagram);
1159
         }
1160
 
1161
         foreach(EA.Element element in thePackage.Elements)
1162
         {
1163
            RemoveAPIStereotypeFromElement(element);
1164
         }
1165
 
1166
         foreach(EA.Package package in thePackage.Packages)
1167
         {
1168
            RemoveAPIStereotypeFromContent(package); // recursion
1169
         }
1170
      }
1171
 
2106 ghuddy 1172
      private static void RemoveAPIStereotypeFromContent(EA.Element theElement)
2104 ghuddy 1173
      {
1174
         RemoveAPIStereotypeFromElement(theElement);
1175
 
1176
         foreach(EA.Diagram diagram in theElement.Diagrams)
1177
         {
1178
            RemoveAPIStereotypeFromDiagram(diagram);
1179
         }
1180
 
1181
         foreach(EA.Element element in theElement.Elements)
1182
         {
1183
            RemoveAPIStereotypeFromContent(element); // recursion
1184
         }
1185
      }
1186
 
1187
 
2106 ghuddy 1188
      public static void MarkContentWithAPIStereotype()
2104 ghuddy 1189
      {
1190
         EA.ObjectType objType;
1191
         object obj;
2106 ghuddy 1192
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2104 ghuddy 1193
         if (objType == EA.ObjectType.otPackage)
1194
         {
1195
            MarkContentWithAPIStereotype((EA.Package)obj);
2106 ghuddy 1196
            Main.EA_Repository.RefreshModelView(((EA.Package)obj).PackageID);
2104 ghuddy 1197
         }
1198
         else if (objType == EA.ObjectType.otDiagram)
1199
         {
1200
            MarkDiagramWithAPIStereotype((EA.Diagram)obj);
2106 ghuddy 1201
            Main.EA_Repository.RefreshModelView(((EA.Diagram)obj).PackageID);
2104 ghuddy 1202
         }
1203
         else if (objType == EA.ObjectType.otElement)
1204
         {
1205
            MarkContentWithAPIStereotype((EA.Element)obj);
2106 ghuddy 1206
            Main.EA_Repository.RefreshModelView(((EA.Element)obj).PackageID);
2104 ghuddy 1207
         }
1208
      }
1209
 
2106 ghuddy 1210
      private static void MarkPackageWithAPIStereotype(EA.Package thePackage)
2104 ghuddy 1211
      {
1212
         if (thePackage.StereotypeEx.IndexOf("API") < 0)
1213
         {
1214
            if (thePackage.StereotypeEx.Length > 0)
1215
               thePackage.StereotypeEx += ",API";
1216
            else
1217
               thePackage.StereotypeEx = "API";
1218
            thePackage.Update();
1219
         }
1220
      }
1221
 
2106 ghuddy 1222
      private static void MarkDiagramWithAPIStereotype(EA.Diagram theDiagram)
2104 ghuddy 1223
      {
1224
         // diagrams only use one stereotype, not a list of them
1225
         theDiagram.Stereotype = "API";
1226
         theDiagram.Update();
1227
      }
1228
 
2106 ghuddy 1229
      private static void MarkElementWithAPIStereotype(EA.Element theElement)
2104 ghuddy 1230
      {
1231
         if (theElement.StereotypeEx.IndexOf("API") < 0)
1232
         {
1233
            if (theElement.StereotypeEx.Length > 0)
1234
               theElement.StereotypeEx += ",API";
1235
            else
1236
               theElement.Stereotype = "API";
1237
            theElement.Update();
1238
         }
1239
      }
1240
 
2106 ghuddy 1241
      private static void MarkContentWithAPIStereotype(EA.Package thePackage)
2104 ghuddy 1242
      {
1243
         MarkPackageWithAPIStereotype(thePackage);
1244
 
1245
         foreach(EA.Diagram diagram in thePackage.Diagrams)
1246
         {
1247
            MarkDiagramWithAPIStereotype(diagram);
1248
         }
1249
 
1250
         foreach(EA.Element element in thePackage.Elements)
1251
         {
1252
            MarkElementWithAPIStereotype(element);
1253
         }
1254
 
1255
         foreach(EA.Package package in thePackage.Packages)
1256
         {
1257
            MarkContentWithAPIStereotype(package); // recursion
1258
         }
1259
      }
1260
 
2106 ghuddy 1261
      private static void MarkContentWithAPIStereotype(EA.Element theElement)
2104 ghuddy 1262
      {
1263
         MarkElementWithAPIStereotype(theElement);
1264
 
1265
         foreach(EA.Diagram diagram in theElement.Diagrams)
1266
         {
1267
            MarkDiagramWithAPIStereotype(diagram);
1268
         }
1269
 
1270
         foreach(EA.Element element in theElement.Elements)
1271
         {
1272
            MarkContentWithAPIStereotype(element); // recursion
1273
         }
1274
      }
1275
 
2124 ghuddy 1276
      /// <summary>
1277
      /// This processes a requirement tag for use when sorting requirements, in a way designed to overcome 
1278
      /// the problem of sorting alphanumeric strings that contain outline numberig but that do not use
1279
      /// leading zero's in that nunmbering, which distorts the sorting outcome in a way that is undesirable 
1280
      /// for the human reader.
1281
      /// The function will also work ok if the input string does not contain any numbering.
1282
      /// The output of the function is to be used in compare operations by IComparer derived classes.
1283
      /// </summary>
1284
      /// <param name="sIn"></param>
1285
      /// <param name="desiredFieldWidth"></param>
1286
      /// <returns></returns>
1287
      public static string OutlineNumberMunging(string sIn, int desiredFieldWidth)
1288
      {
1289
         // create a "fabric" filled with 0's into which we can serialise our resulting string
1290
         const int max_str_len = 100;     // should easily be big enough for a requirement tag.
1291
         string sOut = new string('0',max_str_len);   
1292
         char[] sOutChArr = sOut.ToCharArray();
1293
 
1294
         int iIn = 0;
1295
         int iOut = 0;
2104 ghuddy 1296
 
2124 ghuddy 1297
         while (iIn < sIn.Length && iOut < max_str_len)
1298
         {
1299
            if ( System.Char.IsNumber(sIn[iIn]) )
1300
            {
1301
               // Here we have to work out how long the number is, and determine how many leading
1302
               // zeros to give it. We assume that the desired field width as given to us is always going 
1303
               // to be sufficient for our needs here. If this is not the case, then the worse that can 
1304
               // happen is that the number will have no leading zeros, and the sorting of tags may not
1305
               // be perfect.
1306
               int iLookAhead = iIn+1;
1307
               while (iLookAhead < sIn.Length && System.Char.IsNumber(sIn[iLookAhead]))
1308
               {
1309
                  iLookAhead++;
1310
               }
1311
               int numberLength = iLookAhead - iIn;
2104 ghuddy 1312
 
2124 ghuddy 1313
               int numberOfLeadingZerosRequired = desiredFieldWidth - numberLength;
1314
 
1315
               // advance by the count of leading zeros required.
1316
               if (numberOfLeadingZerosRequired > 0)
1317
                  iOut += numberOfLeadingZerosRequired;
1318
 
1319
               // Serialise the number. We dont have to serialise the leading zero's because our char array 
1320
               // was initialised with 0's to begin with.
1321
               while(numberLength > 0 && iOut < max_str_len)
1322
               {
1323
                  sOutChArr[iOut++] = sIn[iIn++];  // serialise a char forming the number
1324
                  numberLength--;
1325
               }
1326
            }
1327
            else if (sIn[iIn] == '.')  // do not feed '.' chars through to the output because they can mess up the sorting of tags
1328
            {
1329
               iOut++;
1330
               iIn++;
1331
            }
1332
            else
1333
            {
1334
               sOutChArr[iOut++] = sIn[iIn++];  // just serialise the char from input to output
1335
            }
1336
         }
1337
 
1338
         // If we did produce an output string, return it, else return the input unaltered.
1339
         if (iOut > 0)
1340
            return new string(sOutChArr); 
1341
         else
1342
            return sIn;
1343
      }
1344
 
1345
 
2088 ghuddy 1346
      #region Temporary or experimental code
1347
 
1348
 
2106 ghuddy 1349
      private static void parse_element(int parentId, EA.Element theElement, int recurse_level)
2102 ghuddy 1350
      {
2106 ghuddy 1351
         Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
1352
            "ParentId:"
1353
            + parentId.ToString()
1354
            + ", Level:"
1355
            + recurse_level.ToString()
1356
            + ", TreePos:"
1357
            + theElement.TreePos.ToString() 
1358
            + ", ELE-ParentID:"
1359
            + theElement.ParentID.ToString()
1360
            + ", ELE-PackageID:"
1361
            + theElement.PackageID.ToString()
1362
            + ", ELE-ElementID:"
1363
            + theElement.ElementID.ToString()
1364
            + ",  ELE-Name: " 
1365
            + theElement.Name, -1);
1366
 
1367
         foreach(EA.Diagram theDiagram in theElement.Diagrams)
2102 ghuddy 1368
         {
2106 ghuddy 1369
            Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
1370
               "Level:"
1371
               + recurse_level.ToString() 
1372
               + ", ParentID:"
1373
               + theDiagram.ParentID.ToString()
1374
               + ", PackageID:"
1375
               + theDiagram.PackageID.ToString()
1376
               + ", DiagramID:"
1377
               + theDiagram.DiagramID.ToString()
1378
               + "  DIAGRAM: " 
1379
               + theDiagram.Name, -1);
1380
         }
2088 ghuddy 1381
 
2106 ghuddy 1382
         foreach(EA.Element subElement in theElement.Elements)
1383
         {
1384
            parse_element(theElement.ElementID, subElement, recurse_level+1);
2102 ghuddy 1385
         }
1386
      }
1387
 
1388
 
2088 ghuddy 1389
      /// <summary>
1390
      /// Parse a package structure in a similar way to that taken when users are generating a word
1391
      /// document, only here we simply write diagnostic text to the output tab.
1392
      /// </summary>
1393
      /// <param name="thePackage"></param>
1394
      /// <param name="recurse_level"></param>
2106 ghuddy 1395
      private static void parse_package(EA.Package thePackage, int recurse_level)
2088 ghuddy 1396
      {
2106 ghuddy 1397
         Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
2088 ghuddy 1398
                                      "Level:"
1399
                                    + recurse_level.ToString() 
1400
                                    + ", ParentID:"
1401
                                    + thePackage.ParentID.ToString()
1402
                                    + ", PackageID:"
1403
                                    + thePackage.PackageID.ToString()
1404
                                    + ",  PACKAGE: " 
1405
                                    + thePackage.Name, -1);
1406
 
1407
         // default handling of diagrams
1408
         foreach(EA.Diagram theDiagram in thePackage.Diagrams)
1409
         {
2102 ghuddy 1410
            if (theDiagram.ParentID == 0)
2088 ghuddy 1411
            {
2106 ghuddy 1412
               Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, 
2102 ghuddy 1413
                  "Level:"
1414
                  + recurse_level.ToString() 
2088 ghuddy 1415
                  + ", ParentID:"
2102 ghuddy 1416
                  + theDiagram.ParentID.ToString()
2088 ghuddy 1417
                  + ", PackageID:"
2102 ghuddy 1418
                  + theDiagram.PackageID.ToString()
1419
                  + ", DiagramID:"
1420
                  + theDiagram.DiagramID.ToString()
1421
                  + "  DIAGRAM: " 
1422
                  + theDiagram.Name, -1);
1423
            }
1424
         }
2088 ghuddy 1425
 
2102 ghuddy 1426
         foreach(EA.Element subElement in thePackage.Elements)
1427
         {
1428
            if (subElement.ParentID == 0 || thePackage.PackageID == subElement.ParentID)
1429
               parse_element(thePackage.PackageID, subElement, recurse_level+1);
2088 ghuddy 1430
         }
1431
 
1432
         foreach(EA.Package lowerLevelPackage in thePackage.Packages)
1433
         {
2102 ghuddy 1434
            parse_package(lowerLevelPackage, recurse_level+1);
2088 ghuddy 1435
         }
1436
      }
1437
 
1438
 
1439
      /// <summary>
1440
      /// Parses a specified package in a similar way to what would be done if a user were generating
1441
      /// a word document, but here do nothing except write diagnostic text to the output tab.
1442
      /// </summary>
2106 ghuddy 1443
      public static void showDiscoveryOrder()
2088 ghuddy 1444
      {
1445
         EA.ObjectType objType;
1446
         object obj;
1447
 
2106 ghuddy 1448
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 1449
         if (objType == EA.ObjectType.otPackage)
1450
         {
1451
            EA.Package EA_ParentPackage = ((EA.Package)obj);
1452
 
2106 ghuddy 1453
            Main.EA_Repository.EnsureOutputVisible(Main.GUI_OUTPUT_TAB_NAME);
1454
            Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "", -1);
1455
            Main.EA_Repository.WriteOutput( Main.GUI_OUTPUT_TAB_NAME, "Showing Object Discovery order for " + EA_ParentPackage.Name, -1);
2088 ghuddy 1456
 
2106 ghuddy 1457
            parse_package(EA_ParentPackage, 1);
2088 ghuddy 1458
         }
1459
         else
1460
         {
1461
            MessageBox.Show("You must select a package to parse");
1462
         }
1463
      }
1464
 
1465
 
2106 ghuddy 1466
      public static void SaveVersionControlledPackage()
2088 ghuddy 1467
      {
1468
         EA.ObjectType objType;
1469
         object obj;
1470
 
2106 ghuddy 1471
         objType = Main.EA_Repository.GetTreeSelectedItem( out obj );
2088 ghuddy 1472
         if (objType == EA.ObjectType.otPackage)
1473
         {
1474
            EA.Package EA_Package = ((EA.Package)obj);
1475
 
1476
            if (EA_Package.IsControlled == true)
1477
            {
2106 ghuddy 1478
               EA.Project EA_Project = Main.EA_Repository.GetProjectInterface();
2088 ghuddy 1479
 
1480
               EA_Project.SaveControlledPackage( EA_Package.PackageGUID );
1481
 
1482
               //EA_Project.SaveControlledPackage( EA_Project.GUIDtoXML( EA_Package.PackageGUID ) );
1483
            }
1484
            else
1485
            {
1486
               MessageBox.Show("The package selected is not version controlled");
1487
            }
1488
          }
1489
         else
1490
         {
1491
            MessageBox.Show("You must select a package");
2094 ghuddy 1492
         }
2088 ghuddy 1493
      }
1494
 
1495
 
1496
      #endregion
1497
	}
1498
 
1499
 
1500
}