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


XMIDI = coral.lang.XMIDI20
UML14 = coral.lang.UML14

m=modeler.ModelerWindow()
storage=m.openProject("2classes_with_assoc_with_wp.xmi")
m.main(loop=0)

action.searchStart("Type Name","Diagram")
while action.searchIsActive():
    m.processEvents()
diagram=action.searchGetResults()[0]

m.getDiagramEditorManager().editorSet.notifyFocusOn(diagram)

# Search for Association
action.searchStart("Type Name","Association")
while action.searchIsActive():
    m.processEvents()
association=action.searchGetResults()[0]
assert association

# take its graphEdge
gedge=coral.gfx(association)[0]

wp=gedge.waypoints

assert len(wp)==3

assert wp[0].x < wp[1].x and wp[1].x < wp[2].x
assert wp[0].y < wp[1].y and wp[1].y > wp[2].y

coral.getTransactionManager().beginModifyCmd()
try:
    gedge.anchor[0].graphElement.position.x += 200
finally:
    coral.getTransactionManager().endModifyCmd()
m.processEvents()

print wp[0].x, " == ", wp[1].x
assert wp[0].x == wp[1].x

coral.getTransactionManager().beginModifyCmd()
try:
    gedge.anchor[1].graphElement.position.y += 150
finally:
    coral.getTransactionManager().endModifyCmd()

assert wp[1].y == wp[2].y

coral.getTransactionManager().beginModifyCmd()
try:
    gedge.anchor[1].graphElement.position.x -= 300
finally:
    coral.getTransactionManager().endModifyCmd()

assert wp[1].y == wp[2].y
