Bridge completing

Every bridge is built of bridge items. Each bridge type can have several bridge items, which are joined together, but there are some constraining rules.
Example:
I have three type of bridge items:
  _        _____________       ~~~~~~~~~~~~~~~~~~~~~~~~
 / \  (a)  |           | (b)   |                      |  (c)
|   | ,    |           |  and  |                      |
lengths are 1,2,4 squares
If bridge of length 1 is required, it looks:
  _   
 / \  (d)
|   | 
If bridge of length 2 is required, it looks:
  _     _  
 / \   / \   (e)
|   | |   |
or
 _____________ 
 |           |  (f)
 |           | 
If bridge of length 6 is required, it looks:
  _  ~~~~~~~~~~~~~~~~~~~~~~~~  _  
 / \ |                      | / \  (g)
|   ||                      ||   |
or
_____________ _____________ _____________
|           | |           | |           | (h)
|           | |           | |           |
In this case also other result bridges are possible. To determine which bridge will be built, constraining conditions can be set. E.g. minimal distance of egde can be set. If you set eg. by second bridge item (b) minimal distance from edge 1, last bridge (h) cannot be built, because distance of bridge item (b) from edge is 0.

Railway station completing

The principle is the same as in bridge completing, but it has two dimensions. First dimension is tracks, and second dimension is one track (ore more tracks besides, but with the same structure). Railway station item has two dimension, width (track count) and length (track length).