Ejemplo n.º 1
0
int main(void)
{
    Avoid::Router *router = new Avoid::Router(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();

    router->outputDiagram("output/example");
    delete router;
    return 0;
}
Ejemplo n.º 2
0
int main(void)
{
    Avoid::Router *router = new Avoid::Router(Avoid::OrthogonalRouting);
    
    Avoid::Point srcPt(0,400);
    Avoid::Point dstPt(775,400);
    Avoid::ConnRef *connRef = new Avoid::ConnRef(router, srcPt, dstPt);
    connRef->setCallback(connCallback, connRef);

    Avoid::Point srcPt2(775,625);
    Avoid::Point dstPt2(350,475);
    Avoid::ConnRef *connRef2 = new Avoid::ConnRef(router, srcPt2, dstPt2);
    connRef2->setCallback(connCallback, connRef2);
    
    router->processTransaction();

    printf("\nShifting endpoint.\n");
    connRef->setEndpoints(Avoid::Point(0,375), Avoid::Point(775,400));
    connRef2->setEndpoints(Avoid::Point(775,625), Avoid::Point(350,450));
    router->processTransaction();

    printf("\nShifting endpoint.\n");
    connRef->setEndpoints(Avoid::Point(0,400), Avoid::Point(775,400));
    connRef2->setEndpoints(Avoid::Point(775,625), Avoid::Point(350,475));
    router->processTransaction();

    delete router;
    return 0;
}
Ejemplo n.º 3
0
int main(void)
{
    Avoid::Router *router = new Avoid::Router(Avoid::OrthogonalRouting);
    
    // Create the ShapeRef:
    Avoid::Rectangle shapeRect1(Avoid::Point(0, 0), Avoid::Point(10, 10));
    Avoid::ShapeRef *shapeRef1 = new Avoid::ShapeRef(router, shapeRect1);
    const unsigned int CENTRE = 1;
    new Avoid::ShapeConnectionPin(shapeRef1, CENTRE, 
            Avoid::ATTACH_POS_CENTRE, Avoid::ATTACH_POS_CENTRE, true, 0.0, Avoid::ConnDirNone);
    
    Avoid::Rectangle shapeRect2(Avoid::Point(0, 0), Avoid::Point(10, 10));
    Avoid::ShapeRef *shapeRef2 = new Avoid::ShapeRef(router, shapeRect1);

    Avoid::ConnEnd dstPt(shapeRef1, CENTRE); 
    Avoid::Point srcPt(1.5, 4);
    Avoid::ConnRef *connRef = new Avoid::ConnRef(router, srcPt, dstPt);
    // Force inital callback:
    router->processTransaction();
    router->outputDiagram("output/connendmove-1");

    Avoid::Point dstPt2(20, 20);
    connRef->setDestEndpoint(dstPt2);
    router->moveShape(shapeRef1, 0.5, 0);

    router->processTransaction();
    router->outputDiagram("output/connendmove-2");

    srcPt.x += 0.5;
    connRef->setSourceEndpoint(srcPt);
    router->moveShape(shapeRef1, 0.5, 0);
    router->moveShape(shapeRef2, 0, 0.5);
    
    srcPt.x += 0.5;
    connRef->setSourceEndpoint(srcPt);
    router->moveShape(shapeRef1, 0.5, 0);
    router->moveShape(shapeRef2, 0, 0.5);
    
    srcPt.x += 0.5;
    connRef->setSourceEndpoint(srcPt);
    router->moveShape(shapeRef1, 0.5, 0);
    router->moveShape(shapeRef2, 0, 0.5);
    
    srcPt.x += 0.5;
    connRef->setSourceEndpoint(srcPt);
    router->moveShape(shapeRef1, 0.5, 0);
    router->moveShape(shapeRef2, 0, 0.5);
    
    router->processTransaction();
    router->outputDiagram("output/connendmove-3");

    delete router;
    return 0;
}
Ejemplo n.º 4
0
int main(void)
{
    Avoid::Router *router = new Avoid::Router(Avoid::OrthogonalRouting);
    
    // Create the ShapeRef:
    Avoid::Rectangle shapePoly(Avoid::Point(0, 0), Avoid::Point(100, 100));
    Avoid::ShapeRef *shapeRef = new Avoid::ShapeRef(router, shapePoly);
    router->addShape(shapeRef);

    Avoid::ConnEnd srcPt(Avoid::Point(200, 200));

    Avoid::ConnEnd dstPt(Avoid::Point(95, 25), 
            ConnDirUp | ConnDirRight | ConnDirDown);
    new Avoid::ConnRef(router, srcPt, dstPt);
    
    dstPt = Avoid::ConnEnd(Avoid::Point(95, 75), 
            ConnDirUp | ConnDirRight | ConnDirDown);
    new Avoid::ConnRef(router, srcPt, dstPt);
    
    // Up goes towards negative coordinates.
    dstPt = Avoid::ConnEnd(Avoid::Point(25, 5), 
            ConnDirLeft | ConnDirRight | ConnDirUp);
    new Avoid::ConnRef(router, srcPt, dstPt);
    
    dstPt = Avoid::ConnEnd(Avoid::Point(75, 5), 
            ConnDirLeft | ConnDirRight | ConnDirUp);
    new Avoid::ConnRef(router, srcPt, dstPt);

    dstPt = Avoid::ConnEnd(Avoid::Point(25, 95), 
            ConnDirLeft | ConnDirRight | ConnDirDown);
    new Avoid::ConnRef(router, srcPt, dstPt);
    
    dstPt = Avoid::ConnEnd(Avoid::Point(75, 95), 
            ConnDirLeft | ConnDirRight | ConnDirDown);
    new Avoid::ConnRef(router, srcPt, dstPt);
    
    router->processTransaction();
    router->outputInstanceToSVG("test-inline");

    delete router;
    return 0;
}
int test()
{
	// The contents of this function can be replaced by the automatically generated test code from the debug svg file
	Avoid::ConnEnd end1;
	Avoid::ConnEnd end2;
	Avoid::Polygon poly;
	Avoid::Router * router = new Avoid::Router(Avoid::OrthogonalRouting);
	router->setTransactionUse(true);
	router->setRoutingPenalty(Avoid::segmentPenalty);
	router->setRoutingPenalty(Avoid::crossingPenalty);
	router->setRoutingPenalty(Avoid::fixedSharedPathPenalty);
	router->setRoutingParameter(idealNudgingDistance, 25);
	router->setRoutingOption(Avoid::improveHyperedgeRoutesMovingJunctions, true);
	poly = Avoid::Polygon(4);
	poly.setPoint(0, Avoid::Point(51160, 50670));
	poly.setPoint(1, Avoid::Point(51160, 50730));
	poly.setPoint(2, Avoid::Point(50950, 50730));
	poly.setPoint(3, Avoid::Point(50950, 50670));
	Avoid::ShapeRef * shape341041314 = new Avoid::ShapeRef(router, poly, 341041314);
	Avoid::ShapeConnectionPin * pin341041314_0 = new Avoid::ShapeConnectionPin(shape341041314, 1, 0.952381, 0.5, 10, 8);
	pin341041314_0->setExclusive(true);
	Avoid::ShapeConnectionPin * pin341041314_1 = new Avoid::ShapeConnectionPin(shape341041314, 2, 0, 0.5, 10, 4);
	pin341041314_1->setExclusive(true);
	poly = Avoid::Polygon(4);
	poly.setPoint(0, Avoid::Point(51160, 50395));
	poly.setPoint(1, Avoid::Point(51160, 50455));
	poly.setPoint(2, Avoid::Point(50950, 50455));
	poly.setPoint(3, Avoid::Point(50950, 50395));
	Avoid::ShapeRef * shape47540376 = new Avoid::ShapeRef(router, poly, 47540376);
	Avoid::ShapeConnectionPin * pin47540376_0 = new Avoid::ShapeConnectionPin(shape47540376, 1, 0.952381, 0.5, 10, 8);
	pin47540376_0->setExclusive(true);
	Avoid::ShapeConnectionPin * pin47540376_1 = new Avoid::ShapeConnectionPin(shape47540376, 2, 0, 0.5, 10, 4);
	pin47540376_1->setExclusive(true);
	poly = Avoid::Polygon(4);
	poly.setPoint(0, Avoid::Point(50850, 50770));
	poly.setPoint(1, Avoid::Point(50850, 50830));
	poly.setPoint(2, Avoid::Point(50665, 50830));
	poly.setPoint(3, Avoid::Point(50665, 50770));
	Avoid::ShapeRef * shape81920772 = new Avoid::ShapeRef(router, poly, 81920772);
	Avoid::ShapeConnectionPin * pin81920772_0 = new Avoid::ShapeConnectionPin(shape81920772, 1, 0.047619, 0.5, 10, 4);
	pin81920772_0->setExclusive(true);
	Avoid::ShapeConnectionPin * pin81920772_1 = new Avoid::ShapeConnectionPin(shape81920772, 2, 1, 0.5, 10, 8);
	pin81920772_1->setExclusive(true);
	Avoid::JunctionRef * junction878282342 = new Avoid::JunctionRef(router, Avoid::Point(50875, 50700), 878282342);
	junction878282342->setPositionFixed(false);
	poly = Avoid::Polygon(4);
	poly.setPoint(0, Avoid::Point(50850, 50470));
	poly.setPoint(1, Avoid::Point(50850, 50530));
	poly.setPoint(2, Avoid::Point(50665, 50530));
	poly.setPoint(3, Avoid::Point(50665, 50470));
	Avoid::ShapeRef * shape206564314 = new Avoid::ShapeRef(router, poly, 206564314);
	Avoid::ShapeConnectionPin * pin206564314_0 = new Avoid::ShapeConnectionPin(shape206564314, 1, 0.047619, 0.5, 10, 4);
	pin206564314_0->setExclusive(true);
	Avoid::ShapeConnectionPin * pin206564314_1 = new Avoid::ShapeConnectionPin(shape206564314, 2, 1, 0.5, 10, 8);
	pin206564314_1->setExclusive(true);
	Avoid::JunctionRef * junction213455341 = new Avoid::JunctionRef(router, Avoid::Point(50875, 50500), 213455341);
	junction213455341->setPositionFixed(false);
	end1 = Avoid::ConnEnd(junction878282342);
	end2 = Avoid::ConnEnd(shape341041314, 2);
	Avoid::ConnRef * conn290033688 = new Avoid::ConnRef(router, end1, end2);
	conn290033688->makePathInvalid();
	end1 = Avoid::ConnEnd(shape81920772, 2);
	end2 = Avoid::ConnEnd(junction878282342);
	Avoid::ConnRef * conn281807178 = new Avoid::ConnRef(router, end1, end2);
	conn281807178->makePathInvalid();
	end1 = Avoid::ConnEnd(shape47540376, 2);
	end2 = Avoid::ConnEnd(junction213455341);
	Avoid::ConnRef * conn762966660 = new Avoid::ConnRef(router, end1, end2);
	conn762966660->makePathInvalid();
	end1 = Avoid::ConnEnd(junction213455341);
	end2 = Avoid::ConnEnd(junction878282342);
	Avoid::ConnRef * conn46508714 = new Avoid::ConnRef(router, end1, end2);
	conn46508714->makePathInvalid();
	end1 = Avoid::ConnEnd(shape206564314, 2);
	end2 = Avoid::ConnEnd(junction213455341);
	Avoid::ConnRef * conn385831514 = new Avoid::ConnRef(router, end1, end2);
	conn385831514->makePathInvalid();
	router->processTransaction();

	outputInstanceToSVG(router);
	poly = Avoid::Polygon(4);
	poly.setPoint(0, Avoid::Point(51160, 50645));
	poly.setPoint(1, Avoid::Point(51160, 50705));
	poly.setPoint(2, Avoid::Point(50950, 50705));
	poly.setPoint(3, Avoid::Point(50950, 50645));
	router->moveShape(shape341041314, poly);
	conn290033688->makePathInvalid();
	conn281807178->makePathInvalid();
	conn46508714->makePathInvalid();
	conn762966660->makePathInvalid();
	router->processTransaction();

	outputInstanceToSVG(router);
	Avoid::Point junctionPos = junction878282342->recommendedPosition();

	delete router;
	
	// Regression test to check that a junction is correctly moved.
	return (junctionPos.y == 50675) ? 0 : 1; 
}
Ejemplo n.º 6
0
/*
 * Make feasible:
 *   - remove overlaps between rectangular boundaries of nodes/clusters
 *     (respecting structural constraints)
 *   - perform routing (preserve previous topology using rubber banding)
 */
void makeFeasible(vpsc::Rectangles& rs, vector<cola::Edge>& edges,
    std::vector<topology::Edge*>& routes,
    std::vector<topology::Node*>& topologyNodes, double defaultEdgeLength) {
    printf("Removing overlaps...\n");
    removeoverlaps(rs,false);
    printf("done.\n");
    printf("Running libavoid to compute routes...\n");
    clock_t libavoidstarttime=clock();
    // find feasible routes for edges
    Avoid::Router *router = new Avoid::Router(Avoid::PolyLineRouting);
    // Use rotational sweep for point visibility
    router->UseLeesAlgorithm = true;
    // Don't use invisibility graph.
    router->InvisibilityGrph = false;
    double g=0; // make shape that libavoid sees slightly smaller
    for(unsigned i=0;i<rs.size();++i) {
        vpsc::Rectangle* r=rs[i];
        double x=r->getMinX()+g;
        double X=r->getMaxX()-g;
        double y=r->getMinY()+g;
        double Y=r->getMaxY()-g;
        // Create the ShapeRef:
        Avoid::Polygon shapePoly(4);
        // AntiClockwise!
        shapePoly.ps[0] = Avoid::Point(X,y);
        shapePoly.ps[1] = Avoid::Point(X,Y);
        shapePoly.ps[2] = Avoid::Point(x,Y);
        shapePoly.ps[3] = Avoid::Point(x,y);
        //if(i==4||i==13||i==9) {
            //printf("rect[%d]:{%f,%f,%f,%f}\n",i,x,y,X,Y);
        //}
        unsigned int shapeID = i + 1;
        Avoid::ShapeRef *shapeRef = new Avoid::ShapeRef(router, shapePoly,
                shapeID);
        // ShapeRef constructor makes a copy of polygon so we can free it:
        //router->addShape(shapeRef); // FIXME
    }
    for(unsigned i=0;i<edges.size();++i) {
        cola::Edge e=edges[i];
        Avoid::ConnRef *connRef;
        unsigned int connID = i + rs.size() + 1;
        Rectangle* r0=rs[e.first], *r1=rs[e.second];
        Avoid::Point srcPt(r0->getCentreX(),r0->getCentreY());
        Avoid::Point dstPt(r1->getCentreX(),r1->getCentreY());
        connRef = new Avoid::ConnRef(router, srcPt, dstPt, connID);
        router->processTransaction();
        const Avoid::Polygon& route = connRef->route();
        vector<topology::EdgePoint*> eps;
        eps.push_back( new topology::EdgePoint( topologyNodes[e.first], 
                    topology::EdgePoint::CENTRE));
        for(size_t j=1;j+1<route.size();j++) {
            const Avoid::Point& p = route.ps[j];
            const unsigned nodeID=p.id-1;
            topology::Node* node=topologyNodes[nodeID];
            topology::EdgePoint::RectIntersect ri;
            switch(p.vn) {
                case 0: ri=topology::EdgePoint::BR; 
                        break;
                case 1: ri=topology::EdgePoint::TR; 
                        break;
                case 2: ri=topology::EdgePoint::TL;
                        break;
                case 3: ri=topology::EdgePoint::BL; 
                        break;
                default: ri=topology::EdgePoint::CENTRE;
            }
            eps.push_back(new topology::EdgePoint(node,ri));
        }
        eps.push_back(new topology::EdgePoint(topologyNodes[e.second],
                    topology::EdgePoint::CENTRE));
        topology::Edge* edgeRoute=new topology::Edge(i,defaultEdgeLength, eps);
        edgeRoute->assertConvexBends();
        routes.push_back(edgeRoute);

    }
    writeFile(topologyNodes,routes,"beautify0.svg");
    assert(topology::assertNoSegmentRectIntersection(topologyNodes,routes));
    double libavoidtime=double(clock()-libavoidstarttime)/double(CLOCKS_PER_SEC);
    cout << "done. Libavoid ran in " << libavoidtime << " seconds" << endl;
    delete router;
}
Ejemplo n.º 7
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;
}