/// <summary> /// Collects all steps horizontally connected with the given targetType from sourceId /// </summary> public static List <int> CollectHorizontal(int sourceId, SfcProgramData data, BranchType targetType, bool upperBranch) { CollectorEntity entity = new CollectorEntity(data, targetType, upperBranch); entity.CollectedSteps.Add(sourceId); CollectLeftDependingSteps(sourceId, entity); CollectRightDependingSteps(sourceId, entity); return(entity.CollectedSteps); }
/// <summary> /// Looks for right depending steps. /// </summary> private static void CollectRightDependingSteps(int currentId, CollectorEntity entity) { PatchEntity step = entity.Data.SfcEntity.Lookup(currentId); if ((entity.UpperBranch && step.UpperBranch == entity.TargetType) || (!entity.UpperBranch && step.LowerBranch == entity.TargetType)) { int rightId = currentId + (1 << SfcEntity.XKeyShift); if (entity.Data.SfcEntity.Lookup(rightId) != null) { entity.CollectedSteps.Add(rightId); CollectRightDependingSteps(rightId, entity); } } }
/// <summary> /// Looks for left depending steps. /// </summary> private static void CollectLeftDependingSteps(int currentId, CollectorEntity entity) { int leftId = currentId - (1 << SfcEntity.XKeyShift); PatchEntity leftStep = entity.Data.SfcEntity.Lookup(leftId); if (leftStep != null) { if ((entity.UpperBranch && leftStep.UpperBranch == entity.TargetType) || (!entity.UpperBranch && leftStep.LowerBranch == entity.TargetType)) { entity.CollectedSteps.Add(leftId); CollectLeftDependingSteps(leftId, entity); } } }