Example #1
0
        internal void Move2NextLocation(Point nextLocation, ColoBox boxToPlace, ColoOptimizer optimizer, int boxId, int indexToStop)
        {
            if (boxId == 47)
            {
            }
            bool  isValid          = false;
            Point calcNextLocation = nextLocation;

            //isInsideBoundingBox = true;
            locationMachine.CurrentBoxToPlace = boxToPlace;

            //reseting the flag indicates we are hitting a tilted wall
            isMeetingTiltedWall = false;

            int i = 0;

            while (!isValid)
            {
                //opening a rack space if it required
                if (locationMachine.NeedOpenRackSpace)
                {
                    calcNextLocation.X += locationMachine.direction.GetNextRackLocationAfterSpace(locationMachine.InitParam.RacksOpenningSpace);
                    locationMachine.RacksCountBeforeSpace = 0;
                }


                boxToPlace.MoveOriginTo(calcNextLocation);

                //if (locationMachine.ROWSTARTS.IsAdvancedFromFirstPositionInALine)
                //{
                //    locationMachine.AssertBoxLocation();
                //}



                //optimizer.OnBoxLookAhead(boxToPlace.PointsCollection, boxId,false);

                //this call makes sure that if a box cross a line either to outside the bounding box, or back inside, we are updating the state accordingly
                Point?nextAfterGap = locationMachine.UpdateMachineState(boxToPlace);
                if (nextAfterGap.HasValue)
                {
                    locationMachine.RacksCountBeforeSpace = 0;
                    boxToPlace.MoveOriginTo(nextAfterGap.Value);
                    locationMachine.INSIDEBOUNDINGBOX.SetCurrent();
                    if (nextSpaceValid(boxToPlace))
                    {
                        locationMachine.ResetOverride();
                        break;
                    }

                    locationMachine.INSIDEBOUNDINGBOX.SetCurrent();
                }


                if (locationMachine.currentState == locationMachine.ROWSTARTS)
                {
                    locationMachine.ROWSTARTS.IsAdvancedFromFirstPositionInALine = true;
                }

                //if we are in a situation that we are placing outside the bounding box (and there is more space to place inside)
                //we need to verify if we crossed back into the internal side of the bounding box. if we did, switch the stateMachine to indicate
                //that state (inside the box)
                //if (locationMachine.CurrentlyOutsideTheBox)
                //{
                //    if (locationMachine.LocationWithinBoundingBox)
                //    {
                //        locationMachine.INSIDEBOUNDINGBOX.SetCurrent();
                //    }
                //}
                ++i;
                if (i > indexToStop)
                {
                    // break;
                }

                if (nextSpaceValid(boxToPlace))
                {
                    locationMachine.NextState();


                    //if we are out of the bounding box, the break should not hit until we either step out of the outer bounding box or until
                    //we got back in
                    if (!locationMachine.IsSteppedOutBoundingBox)
                    {
                        break;
                    }
                }
                calcNextLocation = locationMachine.NextLocation;
                if (calcNextLocation.X == locationMachine.direction.ExtremeX)
                {
                    throw new ExtremeFoundException();
                }

                locationMachine.ResetOverride();
            }
            locationMachine.RacksCountBeforeSpace++;
        }