/** \file * Interface between Inkscape code (SPItem) and graphlayout functions. */ /* * Authors: * Tim Dwyer * * Copyright (C) 2005 Authors * * Released under GNU GPL. Read the file 'COPYING' for more information. */ #include "graphlayout/graphlayout.h" #include #include #ifdef HAVE_BOOST_GRAPH_LIB #include "sp-path.h" #include "sp-item.h" #include "sp-item-transform.h" #include "sp-conn-end-pair.h" #include "conn-avoid-ref.h" #include "libavoid/connector.h" #include #include #include #include #include #include #include #include #include #include using namespace boost; // create a typedef for the Graph type typedef adjacency_list > Graph; typedef property_map::type WeightMap; typedef graph_traits::vertex_descriptor Vertex; typedef std::vector > PositionVec; typedef iterator_property_map::type> PositionMap; #endif // HAVE_BOOST_GRAPH_LIB bool isConnector(SPItem *i) { SPPath *path = NULL; if(SP_IS_PATH(i)) { path = SP_PATH(i); } return path && path->connEndPair.isAutoRoutingConn(); } /** * Takes a list of inkscape items, extracts the graph defined by * connectors between them, and uses graph layout techniques to find * a nice layout */ void graphlayout(GSList const *const items) { if(!items) { return; } #ifdef HAVE_BOOST_GRAPH_LIB using Inkscape::Util::GSListConstIterator; std::list selected; selected.insert >(selected.end(), items, NULL); if (selected.empty()) return; int n=selected.size(); //Check 2 or more selected objects if (n < 2) return; Graph g; double minX=DBL_MAX, minY=DBL_MAX, maxX=-DBL_MAX, maxY=-DBL_MAX; std::map nodelookup; for (std::list::iterator it(selected.begin()); it != selected.end(); ++it) { SPItem *u=*it; std::cout<<"id:"<id<id]=add_vertex(g); } } WeightMap weightmap=get(edge_weight, g); std::cout<<"Added vertices: Graph has |V|="<::iterator it(selected.begin()); it != selected.end(); ++it) { using NR::X; using NR::Y; SPItem *itu=*it; Vertex u=nodelookup[itu->id]; GSList *nlist=itu->avoidRef->getAttachedConnectors(Avoid::ConnRef::runningFrom); std::list neighbours; neighbours.insert >(neighbours.end(),nlist,NULL); std::cout<<" Node "<id<<" has "<::iterator ne(neighbours.begin()); ne != neighbours.end(); ++ne) { SPItem *itv=*ne; std::cout<<"neighbour: "<id<id]; std::cout<<" Neighbour: "<