public void GenerateLocation()
{
_location.X = _boundingBox.X + _padding.Width;
switch (_diagram.Alignement)
{
case DiagramAlignement.Center:
_location.Y = _boundingBox.Y +
(_boundingBox.Height - _size.Height) / 2;
if(_diagram.ShowDocumentation && !_documentationBox.IsEmpty)
{
_location.Y = _boundingBox.Y +
(_boundingBox.Height - (2 * _padding.Height + _documentationBox.Height)) / 2;
}
break;
case DiagramAlignement.Near:
if (_itemType == DiagramItemType.group && _parent != null && _parent.ChildElements.Count == 1)
_location.Y = _parent.Location.Y + (_parent._elementBox.Height - _elementBox.Height) / 2;
else
_location.Y = _boundingBox.Y + _padding.Height;
break;
case DiagramAlignement.Far:
if (_itemType == DiagramItemType.group && _parent != null && _parent.ChildElements.Count == 1)
_location.Y = _parent.Location.Y + (_parent._elementBox.Height - _elementBox.Height) / 2;
else
_location.Y = _boundingBox.Y +
_boundingBox.Height - _size.Height - _padding.Height;
break;
}
if (_showChildElements)
{
int childrenHeight = 0;
foreach (DiagramItem element in _childElements)
childrenHeight += element.BoundingBox.Height;
int childrenX = _boundingBox.X + 2 * _padding.Width + Size.Width;
int childrenY = _boundingBox.Y + Math.Max(0, (_boundingBox.Height - childrenHeight) / 2);
foreach (DiagramItem element in _childElements)
{
Rectangle elementBoundingBox = element.BoundingBox;
elementBoundingBox.X = childrenX;
elementBoundingBox.Y = childrenY;
element.BoundingBox = elementBoundingBox;
element.GenerateLocation();
childrenY += element.BoundingBox.Height;
}
}
if (_hasChildElements)
_childExpandButtonBox.Offset(_location);
_elementBox.Offset(_location);
if (!_documentationBox.IsEmpty)
{
if(_diagram.Alignement == DiagramAlignement.Far)
_documentationBox.Offset(_location.X, _location.Y - _documentationBox.Height - _padding.Height);
else
_documentationBox.Offset(_location.X, _location.Y + _elementBox.Height + _padding.Height);
}
}