Exemplo n.º 1
0
int main(void)
{
    Avoid::Router *router = new Avoid::Router(Avoid::OrthogonalRouting |
            Avoid::PolyLineRouting);
    
    Avoid::Point srcPt(1.2, 0.5);
    Avoid::Point dstPt(1.5, 4);
    Avoid::ConnRef *connRef = new Avoid::ConnRef(router, srcPt, dstPt);
    connRef->setCallback(connCallback, connRef);
    // Force inital callback:
    router->processTransaction();

    printf("\nAdding a shape.\n");
    // Create the ShapeRef:
    Avoid::Polygon shapePoly(3);
    shapePoly.ps[0] = Avoid::Point(1, 1);
    shapePoly.ps[1] = Avoid::Point(2.5, 1.5);
    shapePoly.ps[2] = Avoid::Point(1.5, 2.5);
    Avoid::ShapeRef *shapeRef = new Avoid::ShapeRef(router, shapePoly);
    router->processTransaction();

    printf("\nShifting endpoint.\n");
    Avoid::Point dstPt2(6, 4.5);
    connRef->setDestEndpoint(dstPt2);
    // It's expected you know the connector needs rerouting, so the callback
    // isn't called.  You can force it to be called though, via:
    router->processTransaction();

    printf("\nMoving shape right by 0.5.\n");
    router->moveShape(shapeRef, 0.5, 0);
    router->processTransaction();

    printf("\nChanging type to orthogonal.\n");
    connRef->setRoutingType(Avoid::ConnType_Orthogonal);
    router->processTransaction();

    printf("\nChanging type back to polyline.\n");
    connRef->setRoutingType(Avoid::ConnType_PolyLine);
    router->processTransaction();

    router->deleteConnector(connRef);
    printf("\nRemoving shape.\n");
    router->deleteShape(shapeRef);
    router->processTransaction();

    printf("\nReadding shape.\n");
    shapeRef = new Avoid::ShapeRef(router, shapePoly);
    router->processTransaction();

    printf("\nMoving shape right by 0.5.\n");
    router->moveShape(shapeRef, 0.5, 0);
    router->processTransaction();

    router->deleteShape(shapeRef);
    shapeRef = NULL;
    router->processTransaction();

    delete router;
    return 0;
}