#!/usr/bin/env python
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
from coral.modeler.coralmodeler import CoralModeler

L = coral.lang.UML14

def isInList(list,item):
    assert list
    for i in list:
        if i == item:
            return True
    return False

def hasChild( container, element):
    for elem in container.contained:
        if elem==element:
            return True
        if hasChild( elem, element):
            return True
    return False

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

st=coral.Project()

p=L.Model()
p.__setProject__(st)

c=L.Class()
p.ownedElement.insert(c)

attribute=L.Attribute()
operation=L.Operation()
stereotype=L.Stereotype()

c.feature.insert(attribute)
c.feature.insert(operation)
c.stereotype.insert(stereotype)
p.ownedElement.insert(stereotype)

deg=DiagramElementGenerator
deg.updateExtensions(CoralModeler.extensionRegistry)



#
#Save the whole thing to an xmi file
#
cd=xmidi_diagrams.createDiagram(st,owner_elem=p,typeinfo="ClassDiagram")

xmidibuilder(p, cd)

assert cd.owner
assert cd.owner.element == p
assert p.__getSlotByOppositeName__(DI.Uml1SemanticModelBridge, "element")[0] == cd.owner

st.setFilename("tmp/testDegenUsingSubclasses.xmi")
st.setXMIFormat("2.0")
coral.saveDocument(st)

