/// <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);
 }
Exemple #2
0
        private static PatchEntity FindSimultaneousTransition(List <int> patches, SfcProgramData data)
        {
            PatchEntity transitionPatch = null;

            foreach (int step in patches)
            {
                transitionPatch = data.SfcEntity.Lookup(step);
                if (transitionPatch != null && transitionPatch.ContainsTransition())
                {
                    break;
                }
            }
            if (transitionPatch == null)
            {
                Godot.GD.PushError("It is not allowed wo have Simultaneous branches without one transition!");
            }
            return(transitionPatch);
        }
Exemple #3
0
        /// <summary>
        /// Collects all Simultaneous branches to merge from this step.
        /// null if there is none.
        /// </summary>
        private static List <SfcTransition> CollectUpperSimultaneousMerge(int sourceId, ProgrammableLogicController pu)
        {
            List <int> collected = Collector.CollectHorizontal(sourceId, pu.SfcProgramData, BranchType.Double, true);

            if (collected.Count <= 1)
            {
                PatchEntity currentPatch = pu.SfcProgramData.SfcEntity.Lookup(sourceId);
                int         lowerId      = sourceId + 1;
                PatchEntity lowerPatch   = pu.SfcProgramData.SfcEntity.Lookup(lowerId);
                if (!currentPatch.ContainsTransition() && lowerPatch != null && lowerPatch.SfcStepType == StepType.Pass)
                {
                    return(CollectUpperSimultaneousMerge(lowerId, pu));
                }
                return(null);
            }
            PatchEntity    transitionPatch = FindSimultaneousTransition(collected, pu.SfcProgramData);
            List <SfcStep> connectedSteps  = CollectConnectedSteps(collected, pu.SfcProgramData);
            SfcTransition  transition      = CreateTransition(transitionPatch.Key, pu);

            transition.DependingSteps = connectedSteps;
            return(new List <SfcTransition> {
                transition
            });
        }