#!/usr/bin/env python
import coral
import time
from coral.modeler import modeler

mw = modeler.ModelerWindow()
mw.main(loop=0)

p = coral.loadDocument("several_UML14_diagrams.xml")

all = coral.Set()

for r in p.contents():
    all.unionWith(r.__getAllParts__())

def get(coll, name):
    def samename(elem):
        try:
            return elem.name == name
        except:
            return False
    t = coll.select(samename)
    assert len(t) == 1
    return t[0]
    

thestuff = []
thestuff.append(get(all, "TheModel"))
thestuff.append(get(all, "TheStateMachine"))

DI = coral.lang.XMIDI20

for elem in thestuff:
    assert elem
    print "CHECKING", elem
    x_ges = elem.__getSlotByOppositeName__(DI.Uml1SemanticModelBridge, "element").diagram
    for x_ge in x_ges:
        assert x_ge.oclIsKindOf(DI.Diagram)
        print "DISPLAYING", x_ge.name
        mw.getDiagramEditorManager().editorSet.notifyFocusOn(x_ge)
        mw.processEvents()
        time.sleep(1)

