Example #1
0
        public override void Execute(ObjectSet originalObjects)
        {
            Position3D positionToPlace = null;

            ShelfContainer3D selectedContainer = containers.Last() as ShelfContainer3D;

            selectedContainer.AddShelf();

            ShelfSubContainer3D selectedShelf = selectedContainer.TopShelf as ShelfSubContainer3D;

            var objectsCopy = originalObjects.ToObjectList();

            while (objectsCopy.Any())
            {
                Object3D selectedObject = objectsCopy.First() as Object3D;

                for (int i = 0; positionToPlace == null; i++)
                {
                    selectedContainer = containers[i] as ShelfContainer3D;

                    for (int j = 0; positionToPlace == null; j++)
                    {
                        selectedShelf = selectedContainer.Subcontainers[j] as ShelfSubContainer3D;

                        //positionToPlace = selectedShelf.TryToFitObject(selectedObject);

                        if ((j == selectedContainer.Subcontainers.Count - 1 && selectedObject.Depth + selectedShelf.Z <= selectedContainer.Depth) ||
                            (j != selectedContainer.Subcontainers.Count - 1 && selectedObject.Depth < selectedShelf.Depth))
                        {
                            positionToPlace = selectedShelf.TryToFitObject(selectedObject);
                        }
                        if (positionToPlace == null)
                        {
                            if (selectedObject.Depth + selectedShelf.Z > selectedContainer.Depth && i == containers.Count - 1 && j == selectedContainer.Subcontainers.Count - 1)
                            {
                                AddContainer();
                                (containers.Last() as ShelfContainer3D).AddShelf();
                                break;
                            }
                            else if (selectedObject.Depth + selectedShelf.Z > selectedContainer.Depth && j == selectedContainer.Subcontainers.Count - 1)
                            {
                                break;
                            }
                            else if (j == selectedContainer.Subcontainers.Count - 1)
                            {
                                positionToPlace = selectedShelf.TryToFitObject(selectedObject);
                                if (positionToPlace == null)
                                {
                                    selectedContainer.AddShelf();
                                }
                            }
                        }
                    }
                }

                objectsCopy.Remove(selectedObject);
                selectedContainer.PlaceObject(selectedObject, positionToPlace);
                positionToPlace = null;
            }
        }
Example #2
0
        public override void Execute(ObjectSet originalObjects)
        {
            Position3D positionToPlace;

            ShelfContainer3D selectedContainer = containers.Last() as ShelfContainer3D;

            selectedContainer.AddShelf();

            ShelfSubContainer3D selectedShelf = selectedContainer.TopShelf as ShelfSubContainer3D;

            var objectsCopy = originalObjects.ToObjectList();

            while (objectsCopy.Any())
            {
                Object3D selectedObject = objectsCopy.First() as Object3D;


                // Change Container if object is too deep
                if (selectedObject.Depth + selectedContainer.TopShelf.Z > selectedContainer.Depth)
                {
                    AddContainer();

                    selectedContainer = containers.Last() as ShelfContainer3D;

                    selectedContainer.AddShelf();

                    selectedShelf = selectedContainer.TopShelf as ShelfSubContainer3D;
                }

                positionToPlace = selectedShelf.TryToFitObject(selectedObject);

                // Change Shelf
                if (positionToPlace == null)
                {
                    selectedContainer.AddShelf();

                    selectedShelf = selectedContainer.TopShelf as ShelfSubContainer3D;

                    if (selectedObject.Depth + selectedContainer.TopShelf.Z > selectedContainer.Depth)
                    {
                        AddContainer();

                        selectedContainer = containers.Last() as ShelfContainer3D;

                        selectedContainer.AddShelf();

                        selectedShelf = selectedContainer.TopShelf as ShelfSubContainer3D;
                    }

                    positionToPlace = selectedShelf.TryToFitObject(selectedObject);
                }

                //positionToPlace = new Position3D(selectedShelf.LastPlacedObject.X2, selectedShelf.Y);

                objectsCopy.Remove(selectedObject);
                selectedContainer.PlaceObject(selectedObject, positionToPlace);
            }
        }