Example #1
0
        public static PackedItem Create(ModelFootprint modelFootprint)
        {
            PackedItem packedItem = new PackedItem()
            {
                ModelFootprint = modelFootprint,
                SizeX          = modelFootprint.SizeX,
                SizeY          = modelFootprint.SizeY,
                RotateModel    = modelFootprint.RotateModel,
            };

            return(packedItem);
        }
Example #2
0
        private static void FillContainer(Container container, PackModelsRequest packModelsRequest, int maxCloneCount, List <ModelFootprint> orderedModelFootprints, int[] modelsCloneCount)
        {
            ModelFootprint modelFootprint = GetBestFitModelFootprint(packModelsRequest, maxCloneCount, orderedModelFootprints, modelsCloneCount, container);

            if (modelFootprint != null)
            {
                int modelIndex = orderedModelFootprints.IndexOf(modelFootprint);
                modelsCloneCount[modelIndex]++;
                modelFootprint.CloneCount++;

                PackedItem item = PackedItem.Create(modelFootprint);
                item.CloneNumber = modelsCloneCount[modelIndex];
                item.ClearanceY  = packModelsRequest.Clearance;
                item.ClearanceX  = packModelsRequest.Clearance;
                item.PositionX   = container.PositionX;
                item.PositionY   = container.PositionY;
                container.Items.Add(item);

                Container spaceNextToModel = new Container()
                {
                    SizeX     = container.SizeX - item.TotalSizeX,
                    SizeY     = item.ModelFootprint.SizeY,
                    PositionX = item.PositionX + item.TotalSizeX,
                    PositionY = item.PositionY
                };

                if (spaceNextToModel.SizeX > packModelsRequest.Clearance)
                {
                    container.AddChild(spaceNextToModel);
                    FillContainer(spaceNextToModel, packModelsRequest, maxCloneCount, orderedModelFootprints, modelsCloneCount);
                }

                Container remainingSpaceAboveModel = new Container()
                {
                    SizeX     = container.SizeX,
                    SizeY     = container.SizeY - item.TotalSizeY,
                    PositionX = container.PositionX,
                    PositionY = container.PositionY + item.TotalSizeY
                };

                if (remainingSpaceAboveModel.SizeY > packModelsRequest.Clearance)
                {
                    container.AddChild(remainingSpaceAboveModel);
                    FillContainer(remainingSpaceAboveModel, packModelsRequest, maxCloneCount, orderedModelFootprints, modelsCloneCount);
                }
            }
        }