/// <summary>
 /// Checks if this patch can skip the transition if it is connected to
 /// StepType.Pass with a upper BranchType.
 /// </summary>
 private static bool CheckPossibleTransitionSkip(Sfc2dEditorControl control, PatchEntity sourcePatch)
 {
     if (sourcePatch.ContainsTransition())
     {
         return(false);
     }
     if (sourcePatch.ContainsRealStep())
     {
         PatchEntity leftPatch = control.Data.SfcEntity.Lookup(sourcePatch.X - 1, sourcePatch.Y);
         if (HasUpperBranchConnection(sourcePatch, leftPatch))
         {
             return(false);
         }
         if (HasLowerBranchConnection(sourcePatch, leftPatch))
         {
             return(false);
         }
         return(FindUpperBranchConnectionsThroughPasses(control, sourcePatch));
     }
     else if (sourcePatch.SfcStepType == StepType.Pass)
     {
         PatchEntity leftPatch = control.Data.SfcEntity.Lookup(sourcePatch.X - 1, sourcePatch.Y);
         return(!HasUpperBranchConnection(sourcePatch, leftPatch));
     }
     return(false);
 }
 /// <summary>
 /// Visualises the active or inactive status of the steps.
 /// </summary>
 public void VisualiseStatus(Sfc2dEditorControl sfc2dEditorControl)
 {
     foreach (var SfcStep in Plc.SfcProgramData.ActiveSteps)
     {
         sfc2dEditorControl.MarkStep(SfcStep.Id, true);
     }
     foreach (var SfcStep in Plc.SfcProgramData.InactiveSteps)
     {
         sfc2dEditorControl.MarkStep(SfcStep.Id, false);
     }
 }
        /// <summary>
        /// Traverses down along passes and tries to find a patch with upper connections but without lower ones.
        /// </summary>
        private static bool FindUpperBranchConnectionsThroughPasses(Sfc2dEditorControl control, PatchEntity currentPatch)
        {
            PatchEntity lowerPatch             = control.Data.SfcEntity.Lookup(currentPatch.X, currentPatch.Y + 1);
            bool        hasLowerTransitionStep = lowerPatch != null && lowerPatch.SfcStepType == StepType.Pass;

            if (!hasLowerTransitionStep)
            {
                return(false);
            }
            PatchEntity leftPatch = control.Data.SfcEntity.Lookup(lowerPatch.X - 1, lowerPatch.Y);

            if (HasUpperBranchConnection(lowerPatch, leftPatch))
            {
                return(true);
            }
            if (HasLowerBranchConnection(lowerPatch, leftPatch))
            {
                return(false);
            }
            return(FindUpperBranchConnectionsThroughPasses(control, lowerPatch));
        }