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

DI = coral.lang.XMIDI20

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



prj=coral.loadDocument("testAttributeCompartmentOrder.xml")

all = coral.Set()

for r in prj.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]

d=get(all, "TheDiagram")
model = get(all, "TheModel")

dv = mw.displayDiagram(d)
feg = fake_events.FakeMouse(mw, dv)

feg.press(5, 5)
feg.move(100, 100, 1)
feg.depress()
feg.press(80,80)
feg.move(100, 100, 1)
feg.depress()

attribute=model.ownedElement[0].feature.select(lambda a: a.oclIsKindOf(coral.lang.UML14.Attribute))[0]
attr_gn=attribute.__getSlotByOppositeName__(coral.lang.XMIDI20.Uml1SemanticModelBridge,"element")[0].graphElement
assert attr_gn.contained[0].semanticModel.typeInfo=="Visibility"

