Exemple #1
0
        public override void Execute(ObjectSet originalObjects)
        {
            double         bestFittingQuality = Double.MaxValue;
            double         localFittingQuality;
            PlacedObject2D newPlacedObject;
            Position2D     positionToPlace = null;

            GuillotineCutContainer2D selectedContainer = containers.First() as GuillotineCutContainer2D;

            GuillotineCutSubcontainer2D selectedSubcontainer = selectedContainer.Subcontainers.First() as GuillotineCutSubcontainer2D;

            var objectsCopy = originalObjects.ToObjectList();

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


                foreach (GuillotineCutContainer2D container in containers)
                {
                    foreach (GuillotineCutSubcontainer2D subcontainer in container.Subcontainers)
                    {
                        if (FittingStrategy.ValidateObjectPlacement(selectedObject, subcontainer))
                        {
                            localFittingQuality = FittingStrategy.CalculateFittingQuality(selectedObject, subcontainer);
                            if (localFittingQuality < bestFittingQuality)
                            {
                                bestFittingQuality   = localFittingQuality;
                                selectedContainer    = container;
                                selectedSubcontainer = subcontainer;
                                positionToPlace      = subcontainer.Position;
                            }
                        }
                    }
                }
                if (positionToPlace == null)
                {
                    AddContainer();

                    selectedContainer    = containers.Last() as GuillotineCutContainer2D;
                    selectedSubcontainer = selectedContainer.Subcontainers.Last() as GuillotineCutSubcontainer2D;
                    positionToPlace      = selectedSubcontainer.Position;
                }


                objectsCopy.Remove(selectedObject);
                newPlacedObject = selectedContainer.PlaceObject(selectedObject, positionToPlace) as PlacedObject2D;
                selectedContainer.SplitSubcontainer(selectedSubcontainer, newPlacedObject);
                positionToPlace    = null;
                bestFittingQuality = Double.MaxValue;
            }
        }
        public Position3D TryToFitObject(Object3D selectedObject)
        {
            double     bestFittingQuality = Double.MaxValue;
            double     localFittingQuality;
            Position2D positionToPlace = null;

            GuillotineCutContainer2D selectedContainer = GuillotineContainer;

            // No space in container - return from function
            if (selectedContainer.Subcontainers.Count == 0)
            {
                return(null);
            }

            GuillotineCutSubcontainer2D selectedSubcontainer = selectedContainer.Subcontainers.First() as GuillotineCutSubcontainer2D;

            // flattens object to 2D during single shelf placement
            Object2D selectedObject2D = new Object2D(selectedObject.Width, selectedObject.Height);

            foreach (GuillotineCutSubcontainer2D subcontainer in selectedContainer.Subcontainers)
            {
                if (ValidateObjectPlacement(selectedObject2D, subcontainer))
                {
                    localFittingQuality = CalculateFittingQuality(selectedObject2D, subcontainer);
                    if (localFittingQuality < bestFittingQuality)
                    {
                        bestFittingQuality   = localFittingQuality;
                        selectedSubcontainer = subcontainer;
                        positionToPlace      = subcontainer.Position;
                    }
                }
            }


            if (positionToPlace != null)
            {
                var newPlacedObject = selectedContainer.PlaceObject(selectedObject2D, positionToPlace) as PlacedObject2D;
                UpdateMaxDepth(selectedObject.Depth);
                selectedContainer.SplitSubcontainer(selectedSubcontainer, newPlacedObject);
                return(new Position3D(positionToPlace.X, positionToPlace.Y, this.Depth));
            }
            else
            {
                return(null);
            }
        }