Subversion Repositories DevTools

Rev

Rev 2094 | 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",
                               "&Generate Packages From Element List",
                               "&Generate Sub-Package Links",
                               "&Generate Element Links" };
               menutItems = ar;
               break;
            }  

            case "-&Misc Utils":
            {
               string[] ar = { "&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",
                               "&Generate Model Layout For Design Document",
                               "-&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;
         }
      }

      //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
            {
               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":        
               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 "&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 "&About...":
               AboutForm anAbout = new AboutForm();
               anAbout.ShowDialog();
               break;


            //////////////////////////////////////////////////////////////////////
            /// EXPERIMENTAL ITEMS ONLY
            //////////////////////////////////////////////////////////////////////
            case "&Generate Model Layout For Design Document":
               EA_Utils.create_BMS00289_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;

         }
      }
      

        }
}