#!/usr/bin/env python
#
# This test opens up a class diagram file without a
# size slot on the XMIDI.Diagram. This should cause Coral to calculate
# the bounding box.
#
#
from coral.modeler.diagram.degen import *
from coral import modeler
from coral.modeler.modeler import *
DI = coral.lang.XMIDI20
from coral.modeler.xmidigraphbuilder import xmidibuilder
from coral.modeler.diagram import xmidi_diagrams
import time

L=coral.lang.UML14
DI = coral.lang.XMIDI20

m=ModelerWindow()
m.main(loop=0)

tm = coral.getTransactionManager()

tm.beginModifyCmd()
try:
    prj = coral.loadDocument("initial_diagram_without_size.xmi")
finally:
    tm.endModifyCmd()


cd = prj.contents()[1]
assert cd.oclIsKindOf(DI.Diagram)

m.getDiagramEditorManager().editorSet.notifyFocusOn(cd)
m.processEvents()

size_slot = cd.__getSlotRO__("size")
assert len(size_slot) == 1
size_elem = size_slot[0]

assert size_elem

assert size_elem.width > 0
assert size_elem.height > 0

p = cd.contained[0]
assert p.semanticModel.element.oclIsKindOf(L.Package)

assert p.position.x + p.size.width == size_elem.width
assert p.position.y + p.size.height == size_elem.height

m.processEvents()
time.sleep(2)
