bool makeNextLayer(SmartLayer currentLayer, State veryStartState) { SmartLayer nextLayer = new SmartLayer(); foreach (var step in currentLayer) { //Find destination states from current step's state var endStates = _fpcDs.GetDestinationStates(step.State.Id); //add them to nextLayer (after converting them to SmartSteps) nextLayer.AddRange(endStates.Select(state => new SmartStep(this, state, step))); } if (nextLayer.Count == 0) { if (currentLayer.Count == 1) if (currentLayer.Single().State.StateType == Common.StateType.Final) { Layers.Remove(currentLayer); return true; } if (veryStartState.OnProductRework == null || veryStartState.OnProductRework.Rework == null) { throw new SoheilExceptionBase( string.Format("FPC {0} در مسیر تولید اصلی به مرحله نهایی ختم نمی شود", _fpcModel.Product.Name), ExceptionLevel.Warning, "مسیریابی خودکار FPC"); } else if (veryStartState.OutConnectors.Any()) { throw new SoheilExceptionBase( string.Format( "FPC {0} پس از گذر از {1} به مرحله نهایی ختم نمی شود", _fpcModel.Product.Name, veryStartState.OnProductRework.Name), ExceptionLevel.Warning, "مسیریابی خودکار FPC"); } return true; } //Remove duplicate steps (present in nextLayer) from nextLayer nextLayer.RemoveDuplicateSteps(); //Remove duplicate steps (present in nextLayer) from all previous layers nextLayer.RemoveDuplicateStepsFrom(Layers); //Add nextLayer to Layers Layers.Add(nextLayer); //preform the next layer search currentLayerIndex++; if (currentLayerIndex == LIMIT_numberOfLayers) return false; return makeNextLayer(nextLayer, veryStartState); }
/// <summary> /// /// </summary> /// <param name="startState">Must fill OnProductRework</param> /// <returns></returns> bool buildLayers(State startState) { var currentLayer = new SmartLayer(new SmartStep(this, startState, null)); currentLayerIndex = 0; return makeNextLayer(currentLayer, startState); }