Beispiel #1
0
        /// <function>
        /// Function to get all transitions of state diagram
        /// </function>
        private void GetAllTransitions(EA.Repository rep, StateDiagram diagramElementsObj, EA.Element element)
        {
            foreach (EA.Connector item in element.Connectors)
            {
                bool   isOld      = false;
                int    clientId   = item.ClientID;   // "From" state of a transition, from where the transition begins
                int    supplierId = item.SupplierID; // "To" state of a transition, where the transition ends
                char[] charsToReplaceFromEffects = new char[] { ';', '\r', '\t', '\n' };

                EA.Element clientElement   = rep.GetElementByID(clientId);
                EA.Element supplierElement = rep.GetElementByID(supplierId);

                Transition transitionObj = new Transition();
                GetStateName(clientElement.Name, rep, clientElement);
                transitionObj.from = stateName;
                GetStateName(supplierElement.Name, rep, supplierElement);
                transitionObj.to      = stateName;
                transitionObj.trigger = item.TransitionEvent;

                effectsList = item.TransitionAction;
                effectsList = effectsList.ReplaceAll(charsToReplaceFromEffects, ',');
                effectsList = Utilities.TruncateCommas(effectsList);

                if (string.IsNullOrEmpty(effectsList))
                {
                    transitionObj.effects = "";
                }
                else
                {
                    transitionObj.effects = "[" + effectsList + "]";
                }

                // To remove duplicate transitions returned by Enterprise architect API
                foreach (var transItem in diagramElementsObj.transitions)
                {
                    if (transItem.from.Equals(transitionObj.from) && transItem.to.Equals(transitionObj.to))
                    {
                        isOld = true;
                        break;
                    }
                }
                if (!isOld)
                {
                    diagramElementsObj.transitions.Add(transitionObj);
                }
            }
        }
Beispiel #2
0
        /// <function>
        /// Function to create an object of type StateDiagram using Enterprise Architect API which later used
        /// to be serialized as YAML
        /// </function>
        public void CreateObjectForStateDiagram(EA.Repository rep, EA.Diagram diag, StateDiagram diagramElementsObj)
        {
            char[] charsToReplaceFromDiagramId = new char[] { '{', '}' };
            diagramElementsObj.refDiagramName = diag.Name;
            diagramElementsObj.refDiagramId   = diag.DiagramGUID.Trim(charsToReplaceFromDiagramId);

            diagramElementsObj.states      = new List <State>();
            diagramElementsObj.transitions = new List <Transition>();

            foreach (EA.DiagramObject diagramObj in diag.DiagramObjects)
            {
                int        elementId = diagramObj.ElementID;
                EA.Element element   = rep.GetElementByID(elementId);

                State stateObj = new State();

                if (element.MetaType == "Pseudostate") // EA state diagram initial state is referred as Pseudostate
                {
                    diagramElementsObj.initialState = element.Name;
                }
                else if (element.MetaType == "FinalState") // EA state diagram final state is referred as FinalState
                {
                    diagramElementsObj.finalState = element.Name;
                }
                else
                {
                    if (element.MetaType == "State")
                    {
                        GetStateName(element.Name, rep, element);
                        stateObj.name = stateName;
                        diagramElementsObj.states.Add(stateObj);
                    }
                }

                if (element.Methods.Count > 0)
                {
                    GetActionsByState(element, stateObj);
                }

                GetAllTransitions(rep, diagramElementsObj, element);
            }
        }
        public void EA_MenuClick(EA.Repository rep, string location, string menuName, string itemName)
        {
            if (itemName == "Save diagram as YAML")
            {
                EA.Diagram diag;

                // To get what a user selected from project browser, a package, a diagram or an element within a diagram
                switch (rep.GetContextItemType())
                {
                case EA.ObjectType.otPackage:
                {
                    MessageBox.Show("Please select a diagram");
                    break;
                }

                case EA.ObjectType.otDiagram:
                {
                    diag = rep.GetContextObject();

                    if (diag.Type.Equals("Statechart"))         // EA State Diagram type is Statechart
                    {
                        StateDiagram stateDiagram = new StateDiagram();
                        stateDiagram.CreateObjectForStateDiagram(rep, diag, stateDiagram);
                        Utilities.SerializeAsYaml(stateDiagram);
                        Utilities.SaveAsYaml(stateDiagram.refDiagramName);
                    }

                    break;
                }

                case EA.ObjectType.otElement:
                {
                    MessageBox.Show("Please select a diagram");
                    break;
                }
                }
            }
            else if (itemName == "About")
            {
                MessageBox.Show("Yaml Generator - Version 1.0");
            }
        }