1

Good day All,

I am developing a program that will resemble warehouse in a "graphical" manner. The representation is very basic and I am using: 1. TGroupBox (as parent container) 2. TPanel (as the shelves in the "warehouse" aka parent container.

The challenge I need help with. If I have 2 or more Groupboxes to draw dynamically. How can I determine the next Point to start drawing. So far my code is working very well with only 2 Groupboxes but I need an intelligent algorithm or way to calculate the next point on my canvas to draw the warehouse.

I am sure I can do this by scanning pixel for pixel and check of another components is at that point but there must be a more cleverly algorithm that can assist :)

Also remember the Groupboxes could be rectangles, square. IOW: Height & Width can differ.

How can I do this?

EDIT1: Sorry my explanation might be lacking. I am not painting them myself. Just creating them in code and positioning them dynamically. Unfortunately I can not post a picture due to reputation points too low. I will try to explain better. Let say I have 3 warehouses. Warehouse 1 contains 2 rows and 3 columns (shelves). And Warehouse 2 contains 20 rows and 5 columns. I have created Warehouse 1 (Groupbox Component) in code, positioned it at point 0, 0 on my parent control. Warehouse 2 can now either be created to the right or bottom of Warehouse 1. Depending on what makes most sense (screen real estate) in terms of the open space available on parent. And then also for Warehouse 3, how can I in code determine where to place it on my parent container? Position? And obviously I cant just always assume to draw the next warehouse to the bottom of the previous one. The previous warehouse might for example - only contain 1 row and 1 shelve which will make it a very small in size and and therefore it will make sense to draw next warehouse to it's right. But if previous warehouse's width is large then it would make sense to draw next warehouse to its bottom.

http://www.programmer.co.za/downloads/SOW.png http://www.programmer.co.za/downloads/SOW.png

TLama
  • 75,147
  • 17
  • 214
  • 392
Marius
  • 11
  • 3
  • Wait, if you are using `TGroupBox`, why are you painting it by yourself ? Also, I just can't imagine how and what do you actually want to draw (an image would be great). – TLama Apr 29 '14 at 12:58
  • Sorry my explanation might be lacking. – Marius Apr 29 '14 at 13:02
  • 1
    Hello, perhaps this could be helpful: http://stackoverflow.com/questions/5119734/algorithm-to-organise-rectangles-in-the-fixed-rectangular-container – Wodzu Apr 30 '14 at 05:25
  • possible duplicate of [Algorithm needed for packing rectangles in a fairly optimal way](http://stackoverflow.com/questions/1213394/algorithm-needed-for-packing-rectangles-in-a-fairly-optimal-way) – Rob Kennedy Apr 30 '14 at 14:31

1 Answers1

0

If you cant find any good answers, i think you you can do some research on "cut list" algorithms. Take a look at DelphiForFun site.

José Eduardo
  • 323
  • 1
  • 5
  • 16