/// <summary>
 /// Creates a transition between two fork-joins.
 /// </summary>
 /// <param name="name">User assigned name for transition.</param>
 /// <param name="source">Transition source.</param>
 /// <param name="target">Transition target.</param>
 /// <param name="region">Transition region.</param>
 /// <param name="action">Transition action.</param>
 /// <remarks>
 /// This class is an extension to UML 2.x.  It allows a transition to be made between two fork-joins,
 /// optionally specifying a region associated with the transition.  If a region is specified, its
 /// active substate will be the target fork-join after the transition is taken.  If a NULL region is
 /// specified, then no region's active substate will be the target fork-join as a result of taking 
 /// this transition.  This latter case, where the associated region is NULL, is equivalent to using
 /// an external transition between the two fork-joins.
 /// </remarks>
 public NSFForkJoinTransition(NSFString name, NSFForkJoin source, NSFForkJoin target, NSFRegion region, NSFVoidAction<NSFStateMachineContext> action)
     : base(name, source, target, null, null, action)
 {
     ForkJoinRegion = region;
 }
 /// <summary>
 /// Creates a transition between two fork-joins.
 /// </summary>
 /// <param name="name">User assigned name for transition.</param>
 /// <param name="source">Transition source.</param>
 /// <param name="target">Transition target.</param>
 /// <param name="region">Transition region.</param>
 /// <param name="action">Transition action.</param>
 /// <remarks>
 /// This class is an extension to UML 2.x.  It allows a transition to be made between two fork-joins,
 /// optionally specifying a region associated with the transition.  If a region is specified, its
 /// active substate will be the target fork-join after the transition is taken.  If a NULL region is
 /// specified, then no region's active substate will be the target fork-join as a result of taking
 /// this transition.  This latter case, where the associated region is NULL, is equivalent to using
 /// an external transition between the two fork-joins.
 /// </remarks>
 public NSFForkJoinTransition(NSFString name, NSFForkJoin source, NSFForkJoin target, NSFRegion region, NSFVoidAction <NSFStateMachineContext> action)
     : base(name, source, target, null, null, action)
 {
     ForkJoinRegion = region;
 }
        public ForkJoinToForkJoinTransitionTest(String name)
            : base(name, new NSFEventThread(name))
        {
            // Fork Joins
            bSynch = new NSFForkJoin("BSynch", this);
            abForkJoin = new NSFForkJoin("ABForkJoin", this);
            bcForkJoin = new NSFForkJoin("BCForkJoin", this);
            // ARegion
            // Events
            evA1 = new NSFEvent("EvA1", this);
            // States
            aRegion = new NSFRegion("ARegion", this);
            initialAState = new NSFInitialState("InitialA", aRegion);
            stateA1 = new NSFCompositeState("StateA1", aRegion, null, null);
            stateA2 = new NSFCompositeState("StateA2", aRegion, null, null);
            // Transitions, ordered internal, local, external
            initialAToStateA1Transition = new NSFExternalTransition("InitialAToStateA1", initialAState, stateA1, null, null, null);
            stateA1ToABForkJoinTransition = new NSFExternalTransition("StateA1ToABForkJoin", stateA1, abForkJoin, evA1, null, null);
            abForkJoinToA2Transition = new NSFExternalTransition("ABForkJoinToA2", abForkJoin, stateA2, null, null, null);
            // B Region
            // Events
            evB1 = new NSFEvent("EvB1", this);
            // States
            bRegion = new NSFRegion("BRegion", this);
            initialBState = new NSFInitialState("InitialB", bRegion);
            stateB1 = new NSFCompositeState("StateB1", bRegion, null, null);
            stateB2 = new NSFCompositeState("StateB2", bRegion, null, null);
            // Transitions, ordered internal, local, external
            initialBToStateB1Transition = new NSFExternalTransition("InitialBToStateB1", initialBState, stateB1, null, null, null);
            stateB1ToBSynchTransition = new NSFExternalTransition("StateB1ToBSynch", stateB1, bSynch, evB1, null, null);
            bSynchToStateB2Transition = new NSFExternalTransition("BSynchToStateB2", bSynch, stateB2, null, null, null);
            // C Region
            // Events
            evC1 = new NSFEvent("EvC1", this);
            // States
            cRegion = new NSFRegion("CRegion", this);
            initialCState = new NSFInitialState("InitialC", cRegion);
            stateC1 = new NSFCompositeState("StateC1", cRegion, null, null);
            stateC2 = new NSFCompositeState("StateC2", cRegion, null, null);
            // Transitions, ordered internal, local, external
            initialCToStateC1Transition = new NSFExternalTransition("InitialCToStateC1", initialCState, stateC1, null, null, null);
            stateC1ToBCForkJoinTransition = new NSFExternalTransition("StateC1ToBCForkJoin", stateC1, bcForkJoin, evC1, null, null);
            bcForkJoinToC2Transition = new NSFExternalTransition("BCForkJoinToC2", bcForkJoin, stateC2, null, null, null);

            // Extra Regional Transitions
            bSynchToABForkJoinTransition = new NSFExternalTransition("BSynchToABForkJoin", bSynch, abForkJoin, null, null, null);
            bSynchToBCForkJoinTransition = new NSFExternalTransition("BSynchToBCForkJoin", bSynch, bcForkJoin, null, null, null);
        }
        private void createStateMachine()
        {
            // State Machine Components
            // Define and initialize in the order:
            //   1) Events
            //   2) Regions and states, from outer to inner
            //   3) Transitions, ordered internal, local, external
            //   4) Group states and transitions within a region together.
            // Maintain the same order of declaration and initialization.

            // Events
            // Event constructors take the form (name, parent)
            cycleEvent = new NSFEvent("CycleEvent", this);
            aReadyEvent = new NSFEvent("AReadyEvent", this);
            bReadyEvent = new NSFEvent("BReadyEvent", this);
            aCompleteEvent = new NSFEvent("ACompleteEvent", this);
            bCompleteEvent = new NSFEvent("BCompleteEvent", this);

            // Regions and states, from outer to inner
            systemRegion = new NSFRegion("SystemRegion", this);
            subsystemARegion = new NSFRegion("SubsystemARegion", this);
            subsystemBRegion = new NSFRegion("SubsystemBRegion", this);
            initializeForkJoin = new NSFForkJoin("InitializeForkJoin", this);
            cycleForkJoin = new NSFForkJoin("CycleForkJoin", this);
            completeForkJoin = new NSFForkJoin("CompleteForkJoin", this);

            // System Region
            // Regions and states, from outer to inner
            // Initial state construtors take the form (name, parent)
            systemInitialState = new NSFInitialState("SystemInitial", systemRegion);
            // Composite state construtors take the form (name, parent, entry actions, exit actions)
            waitForCycleEventState = new NSFCompositeState("WaitForCycleEvent", systemRegion, null, null);
            // Transitions, ordered internal, local, external
            // External transition construtors take the form (name, source, target, trigger, guard, action)
            systemInitialToInitializeForkJoinTransition = new NSFExternalTransition("SystemInitialToInitializeForkJoin", systemInitialState, initializeForkJoin, null, null, null);
            initializeForkJoinToWaitForCycleEventTransition = new NSFExternalTransition("InitializeForkJoinToWaitForCycleEvent", initializeForkJoin, waitForCycleEventState, null, null, null);
            waitForCycleEventToCycleForkJoinTransition = new NSFExternalTransition("WaitForCycleEventToCycleForkJoin", waitForCycleEventState, cycleForkJoin, cycleEvent, null, null);
            cycleForkJoinToCompleteForkJoinTransiiton = new NSFForkJoinTransition("CycleForkJoinToCompleteForkJoin", cycleForkJoin, completeForkJoin, systemRegion, null);
            completeForkJoinToWaitForCycleEventTransition = new NSFExternalTransition("CompleteForkJoinToWaitForCycleEvent", completeForkJoin, waitForCycleEventState, null, null, null);

            // Subystem A Region
            // Regions and states, from outer to inner
            // Initial state construtors take the form (name, parent)
            subsystemAInitialState = new NSFInitialState("SubsystemAInitial", subsystemARegion);
            // Composite state construtors take the form (name, parent, entry actions, exit actions)
            initializeAState = new NSFCompositeState("InitializeA", subsystemARegion, initializeAEntryActions, null);
            cycleAState = new NSFCompositeState("CycleA", subsystemARegion, cycleAEntryActions, null);
            // Transitions, ordered internal, local, external
            // External transition construtors take the form (name, source, target, trigger, guard, action)
            subsystemAInitialToInitializeATransition = new NSFExternalTransition("SubsystemAInitialToInitializeA", subsystemAInitialState, initializeAState, null, null, null);
            initializeAToInitializeForkJoinTransition = new NSFExternalTransition("InitializeAToInitializeForkJoin", initializeAState, initializeForkJoin, aReadyEvent, null, null);
            initializeForkJoinToCycleForkJoinARegionTransition = new NSFForkJoinTransition("InitializeForkJoinToCycleForkJoinARegion", initializeForkJoin, cycleForkJoin, subsystemARegion, null);
            cycleForkJoinToCycleATransition = new NSFExternalTransition("CycleForkJoinToCycleA", cycleForkJoin, cycleAState, null, null, null);
            cycleAToCompleteForkJoinTransition = new NSFExternalTransition("CycleAToCompleteForkJoin", cycleAState, completeForkJoin, aCompleteEvent, null, null);

            // Subystem B Region
            // Regions and states, from outer to inner
            // Initial state construtors take the form (name, parent)
            subsystemBInitialState = new NSFInitialState("SubsystemBInitial", subsystemBRegion);
            // Composite state construtors take the form (name, parent, entry actions, exit actions)
            initializeBState = new NSFCompositeState("InitializeB", subsystemBRegion, initializeBEntryActions, null);
            cycleBState = new NSFCompositeState("CycleB", subsystemBRegion, cycleBEntryActions, null);
            // Transitions, ordered internal, local, external
            // External transition construtors take the form (name, source, target, trigger, guard, action)
            subsystemBInitialToInitializeBTransition = new NSFExternalTransition("SubsystemBInitialToInitializeB", subsystemBInitialState, initializeBState, null, null, null);
            initializeBToInitializeForkJoinTransition = new NSFExternalTransition("InitializeBToInitializeForkJoin", initializeBState, initializeForkJoin, bReadyEvent, null, null);
            initializeForkJoinToCycleForkJoinBRegionTransition = new NSFForkJoinTransition("InitializeForkJoinToCycleForkJoinBRegion", initializeForkJoin, cycleForkJoin, subsystemBRegion, null);
            cycleForkJoinToCycleBTransition = new NSFExternalTransition("CycleForkJoinToCycleB", cycleForkJoin, cycleBState, null, null, null);
            cycleBToCompleteForkJoinTransition = new NSFExternalTransition("CycleBToCompleteForkJoin", cycleBState, completeForkJoin, bCompleteEvent, null, null);
        }