#!/usr/bin/env python
# This file is part of the Coral project.
# Please read the copyright notice in the LICENSE file.

# Remove (0,0) waypoints from a model.
# This became a necessary transition tool due to an internal change in Coral
# which doesn't serialize a XMI-DI.Point as three Points anymore.
#

import sys
import coral

if len(sys.argv) < 2:
    print "Usage: remove_null_waypoints inputfile1"
    sys.exit(2)

DI = coral.lang.XMIDI20
P = coral.loadDocument(sys.argv[1])

for root in P.contents():
    for element in root.__getAllParts__():
        if not element.oclIsKindOf(DI.GraphEdge):
            continue
        for point in element.waypoints:
            if point.x == 0.0 and point.y == 0.0:
                # Note that this removing-while-iterating
                # is allowed in Coral, even though
                # that is not true in general for e.g.
                # Python lists.
                element.waypoints.remove(point)

coral.saveDocument(P)
