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;
}
Exemplo n.º 2
0
int main(void)
{
    Avoid::Router *router = new Avoid::Router(Avoid::OrthogonalRouting);
    router->setRoutingPenalty((Avoid::PenaltyType)0, 50);
    
    Avoid::Rectangle shapeRect1(Avoid::Point(0, 0), Avoid::Point(30, 20));
    Avoid::ShapeRef *shapeRef1 = new Avoid::ShapeRef(router, shapeRect1);
    
    Avoid::Rectangle shapeRect2(Avoid::Point(70, 7), Avoid::Point(100, 27));
    new Avoid::ShapeRef(router, shapeRect2);
    
    Avoid::Rectangle shapeRect3(Avoid::Point(50, 60), Avoid::Point(80, 155));
    new Avoid::ShapeRef(router, shapeRect3);
    
    Avoid::Rectangle shapeRect4(Avoid::Point(125, 60), Avoid::Point(155, 80));
    new Avoid::ShapeRef(router, shapeRect4);
    
    Avoid::Rectangle shapeRect5(Avoid::Point(15, 150), Avoid::Point(45, 170));
    Avoid::ShapeRef *shapeRef5 = new Avoid::ShapeRef(router, shapeRect5);
    
    Avoid::Rectangle shapeRect6(Avoid::Point(130, 130), Avoid::Point(160, 150));
    Avoid::ShapeRef *shapeRef6 = new Avoid::ShapeRef(router, shapeRect6);
    
    // Add a centre connection pin for the three shapes we'll be using.
    new Avoid::ShapeConnectionPin(shapeRef1, Avoid::CONNECTIONPIN_CENTRE, 
            Avoid::ATTACH_POS_CENTRE, Avoid::ATTACH_POS_CENTRE, true, 0.0, Avoid::ConnDirNone);
    new Avoid::ShapeConnectionPin(shapeRef5, Avoid::CONNECTIONPIN_CENTRE, 
            Avoid::ATTACH_POS_CENTRE, Avoid::ATTACH_POS_CENTRE, true, 0.0, Avoid::ConnDirNone);
    new Avoid::ShapeConnectionPin(shapeRef6, Avoid::CONNECTIONPIN_CENTRE, 
            Avoid::ATTACH_POS_CENTRE, Avoid::ATTACH_POS_CENTRE, true, 0.0, Avoid::ConnDirNone);

    Avoid::ConnEnd srcEnd(shapeRef1, Avoid::CONNECTIONPIN_CENTRE);
    Avoid::ConnEnd dstEnd(shapeRef6, Avoid::CONNECTIONPIN_CENTRE);
    Avoid::ConnRef *conn1= new Avoid::ConnRef(router, srcEnd, dstEnd);
    
    router->processTransaction();
    router->outputInstanceToSVG("output/junction04-1");

    // Split the connector on its second segment and add a junction point.
    std::pair<Avoid::JunctionRef *, Avoid::ConnRef *> newObjs = 
            conn1->splitAtSegment(2);

    router->processTransaction();
    router->outputInstanceToSVG("output/junction04-2");

    // Create a connector from the centre of shape 5 that connects to 
    // the junction.
    Avoid::ConnEnd srcEnd3(shapeRef5, Avoid::CONNECTIONPIN_CENTRE);
    Avoid::ConnEnd dstEnd3(newObjs.first);
    new Avoid::ConnRef(router, srcEnd3, dstEnd3);

    router->processTransaction();
    router->outputInstanceToSVG("output/junction04-3");

    // Delete one half of the original connector, up to the junction.
    router->deleteConnector(conn1);
    conn1 = NULL;

    router->processTransaction();
    router->outputInstanceToSVG("output/junction04-4");
    
    // The junction just has two connector now, so merge these into one.
    newObjs.first->removeJunctionAndMergeConnectors();
    router->processTransaction();
    router->outputInstanceToSVG("output/junction04-5");
    
    router->processTransaction();

    delete router;
    return 0;
}