Subversion Repositories DevTools

Rev

Rev 2094 | Rev 2106 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

using System;
using System.Windows.Forms;
using System.IO;
using Word;


namespace EA_DocGen
{
        /// <summary>
        /// 
        /// </summary>
        public class Main
        {
      public string filecontents = "";
      public AboutForm theForm;

      private EA_Utilities EA_Utils = new EA_Utilities();


      public readonly static String GUI_OUTPUT_TAB_NAME = "EA_DocGen";
      


      //Called Before EA starts to check Add-In Exists
      public String EA_Connect(EA.Repository Repository)
      {
         //No special processing required.
         return "a string";
      }

      /// <summary>
      /// Called when EA initialised. Creates an output tab for the add in.
      /// </summary>
      /// <param name="repository"></param>
      public void EA_OnPostInitialized(EA.Repository repository)
      {
         repository.CreateOutputTab(GUI_OUTPUT_TAB_NAME);
         repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
      }


 

      //Called when user Click Add-Ins Menu item from within EA.
      //Populates the Menu with our desired selections.
      public object EA_GetMenuItems(EA.Repository Repository, string Location, string MenuName)
      {
         object menutItems = null;
                 
         switch( MenuName )
         {
            case "":
               menutItems = "-&EA DocGen";
               break;

            case "-&Using Copied GUID...":
            {
               string[] ar = { "&Add Link Element",
                               "&Add Test Link Element",
                               "&Add Name Link Element",
                               "&Generate Packages From Element List",
                               "&Generate Sub-Package Links",
                               "&Generate Element Links" };
               menutItems = ar;
               break;
            }  

            case "-&Misc Utils":
            {
               string[] ar = { "&Mark Content With API Stereotype",
                               "&Remove API Stereotype From Content",
                               "&Show Package/Element Discovery Order",

                             };
               menutItems = ar;
               break;
            }

            case "-&EA DocGen":
            {
               string[] ar = { "&Generate Document From Model Layout", 
                               "-",
                               "&Copy GUID To Clipboard",
                               "-&Using Copied GUID...",
                                "-",
                               "&Add Table Element",
                               "&Add Text Element",
                               "&Add RelationshipMatrix Element",
                               "&Add Test Traceability Element",
                                "-",
                               "&Add Document Reference",
                               "&Add Terminology Entry",
                               "&Modify EA_DocGen Options",
                               "-",
                               "&Generate Model Layout For Design Document",
                               "&Generate Basic Document Model Layout",
                                "-",
                               "-&Misc Utils",
//                               "&Get TreePos"
//                               "&Save Version Controlled Package",
                               "&About..." };
               menutItems = ar;
               break;
            }
               // TODO - more menu options
               //
               // 1. Generate Package Structure Layout from a QMS outline document.
               //    User needs to select a QMS outline document, and the addin opens it and reads
               //    all of the document headings and their heading levels (styles) and forms a
               //    package structure from them. The user would have to also specify the Parent
               //    package name under which this structure should be created in the EA model.
               //
               // 2. Import/Export requirements from/to RequisitePro
               //    What is possible here will need investigating. 
               //    Does ReqPro have an interoperability interface? 
               //    Do we have to export/import via a file (eg. csv file).
               //
               //
          }

         return menutItems;
      }

      //Sets the state of the menu depending if there is an active project or not
      bool IsProjectOpen(EA.Repository Repository)
      {
         try
         {
            EA.Collection c = Repository.Models;
            return true;
         }
         catch
         {
            return false;
         }
      }

      private bool isEA_DocGenSelected(EA.Repository Repository)
      {
         EA.ObjectType objType;
         object obj;

         objType = Repository.GetTreeSelectedItem( out obj );
         if (objType == EA.ObjectType.otElement)
         {
            if (0 == ((EA.Element)obj).Name.CompareTo(EA_Constants.EA_DocGenBaseName))
               return true;
         }
         return false;
      }

      private bool isPackageSelected(EA.Repository Repository, string pkgName)
      {
         EA.ObjectType objType;
         object obj;

         objType = Repository.GetTreeSelectedItem( out obj );
         if (objType == EA.ObjectType.otPackage)
         {
            if (pkgName != null)
            {
               if ( 0 == ((EA.Package)obj).Name.CompareTo(pkgName) )
               {
                  return true;
               }
            }
            else
            {
               return true;
            }
         }
         return false;                                            
      }


      //Called once Menu has been opened to see what menu items are active.
      public void EA_GetMenuState(EA.Repository Repository, string Location, string MenuName, string ItemName, ref bool IsEnabled, ref bool IsChecked)
      {
         if( IsProjectOpen(Repository) )
         {
            if ((MenuName == "-&Using Copied GUID...") && (EA_Utils.guid_clipboard.objType == EA.ObjectType.otNone))
            {
               IsEnabled = false;
            }
            else
            {
               if (ItemName == "&Add Document Reference")
               {
                  IsEnabled = isPackageSelected(Repository, "References");
               }
               else if (ItemName == "&Add Terminology Entry")
               {
                  IsEnabled = isPackageSelected(Repository, "Terminology");
               }
               else if (ItemName == "&Add Table Element")
               {
                  IsEnabled = isPackageSelected(Repository, null);
               }
               else if (ItemName == "&Add Text Element")
               {
                  IsEnabled = isPackageSelected(Repository, null);
               }
               else if (ItemName == "&Add RelationshipMatrix Element")
               {
                  IsEnabled = isPackageSelected(Repository, null);
               }
               else if (ItemName == "&Generate Model Layout For Design Document")
               {
                  IsEnabled = isPackageSelected(Repository, null);
               }
               else if (ItemName == "&Generate Basic Document Model Layout")
               {
                  IsEnabled = isPackageSelected(Repository, null);
               }
               else if (ItemName == "&Generate Document From Model Layout")
               {
                  IsEnabled = isPackageSelected(Repository, null);
               }
               else if (ItemName == "&Add Test Traceability Element")
               {
                  IsEnabled = isPackageSelected(Repository, null);
               }
               else if (ItemName == "&Modify EA_DocGen Options")
               {
                  IsEnabled = isEA_DocGenSelected(Repository);
               }

               else
               {
                  IsEnabled = true;
               }
            }
         }
         else
         {
            // If no open project, disable all menu options
            IsEnabled = false;
         }
      }

      //Called when user makes a selection in the menu.
      //This is your main exit point to the rest of your Add-in
      public void EA_MenuClick(EA.Repository Repository, string Location, string MenuName, string ItemName)
      {
         EA.ObjectType objType;
                   object obj;

         EA_Utils.accept_EA_RepositoryRef(Repository);

         switch( ItemName )
         {
            case "&Generate Document From Model Layout":        
               Repository.EnsureOutputVisible(GUI_OUTPUT_TAB_NAME);
               EA_Utils.createWordDoc();
               break;

            case "&Copy GUID To Clipboard":
               EA_Utils.copy_GUID_to_clipboard();
               break;
 
            case "&Add Link Element":
               EA_Utils.AddLinkElement();
               break;

            case "&Add Name Link Element":
               EA_Utils.AddNameLinkElement();
               break;

            case "&Add Test Link Element":
               EA_Utils.AddTestLinkElement();
               break;

            case "&Generate Packages From Element List":
               EA_Utils.GeneratePackagesFromElementList();
               break;

            case "&Generate Sub-Package Links":
               EA_Utils.GenerateSubPackageLinks();
               break;

            case "&Generate Element Links":
               EA_Utils.GenerateElementLinks();
               break;

            case "&Add Table Element":
               EA_Utils.AddTableElement();
               break;

            case "&Add Text Element":
               EA_Utils.AddTextElement();
               break;

            case "&Add RelationshipMatrix Element":
               EA_Utils.AddRelationshipMatrixElement();
               break;

            case "&Add Test Traceability Element":
               EA_Utils.AddTestTraceabilityElement();
               break;

            case "&About...":
               AboutForm anAbout = new AboutForm();
               anAbout.ShowDialog();
               break;

            case "&Add Document Reference":
               EA_Utils.addDocumentReference();
               break;

            case "&Add Terminology Entry":
               EA_Utils.addTerminology();
               break;

            case "&Modify EA_DocGen Options":
               EA_Utils.modifyOptions();
               break;

            case "&Mark Content With API Stereotype":
               EA_Utils.MarkContentWithAPIStereotype();
               break;

            case "&Remove API Stereotype From Content":
               EA_Utils.RemoveAPIStereotypeFromContent();
               break;

            //////////////////////////////////////////////////////////////////////
            /// EXPERIMENTAL ITEMS ONLY
            //////////////////////////////////////////////////////////////////////
            case "&Generate Model Layout For Design Document":
               EA_Utils.create_BMS00289_Layout();
               break;

            case "&Generate Basic Document Model Layout":
               EA_Utils.create_basic_Layout();
               break;

            case "&Show Package/Element Discovery Order":
               EA_Utils.showDiscoveryOrder();
               break;

            case "&Get TreePos":
               objType = Repository.GetTreeSelectedItem( out obj );
               if (objType == EA.ObjectType.otPackage)
               {
                  MessageBox.Show(((EA.Package)obj).TreePos.ToString());
               }
               break;

            case "&Save Version Controlled Package":
               EA_Utils.SaveVersionControlledPackage();
               break;

         }
      }
        }
}