Beispiel #1
0
void CDirectLink::addLink(Cconnector *A, Cconnector *B, bool close)
{
    addlinkMutex.lock();
    if (close) {

        AConnList.append(A);
        BConnList.append(B);
        closeList.append(close);
    }
    else {  // Create a link object
#if 1
        AConnList.append(A);
        BConnList.append(B);
        closeList.append(close);
#ifdef AVOID
        Avoid::ConnEnd srcEnd(mainwindow->shapeRefList[A->Parent],A->Id+1);
        Avoid::ConnEnd dstEnd(mainwindow->shapeRefList[B->Parent],B->Id+1);
        new Avoid::ConnRef(mainwindow->router, srcEnd, dstEnd);
        mainwindow->router->processTransaction();
        mainwindow->router->outputInstanceToSVG("test-connectionpin01");
#endif
#else
        // 1 - create the CCable object
         Ccable *pPC = (Ccable*)mainwindow->LoadPocket(CABLE11Pins);
        // 2 - define its size and position
         bool reverse = pPC->Adapt(A,B);
         pPC->standard = true;
         addLink(A,pPC->ConnList.at(reverse?1:0),true);
         pPC->ConnList.at(reverse?1:0)->setOppDir(A->getDir());
         addLink(pPC->ConnList.at(reverse?0:1),B,true);
         pPC->ConnList.at(reverse?0:1)->setOppDir(B->getDir());
#endif
    }
    addlinkMutex.unlock();
}
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;
}