summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3fea53c)
raw | patch | inline | side by side (parent: 3fea53c)
author | tgdwyer <tgdwyer@users.sourceforge.net> | |
Tue, 14 Feb 2006 00:59:15 +0000 (00:59 +0000) | ||
committer | tgdwyer <tgdwyer@users.sourceforge.net> | |
Tue, 14 Feb 2006 00:59:15 +0000 (00:59 +0000) |
src/graphlayout/graphlayout.cpp | patch | blob | history | |
src/graphlayout/graphlayout.h | patch | blob | history |
index 112a942a7ecd238ebad67190ca10b6bd5eafbed7..48d05823e8b9c38b298bf8809e81806f4020bff5 100644 (file)
#include <config.h>
#ifdef HAVE_BOOST_GRAPH_LIB
+#include "util/glib-list-iterators.h"
#include "sp-path.h"
#include "sp-item.h"
#include "sp-item-transform.h"
typedef std::vector<Avoid::Point> PositionVec;
typedef iterator_property_map<PositionVec::iterator, property_map<Graph, vertex_index_t>::type> PositionMap;
-bool isConnector(SPItem *i) {
+/**
+ * Returns true if item is a connector
+ */
+bool isConnector(SPItem const *const i) {
SPPath *path = NULL;
if(SP_IS_PATH(i)) {
path = SP_PATH(i);
}
return path && path->connEndPair.isAutoRoutingConn();
}
-#endif // HAVE_BOOST_GRAPH_LIB
+
+/**
+ * Scans the items list and places those items that are
+ * not connectors in filtered
+ */
+void filterConnectors(GSList const *const items, std::list<SPItem *> &filtered) {
+ for(GSList *i=(GSList *)items; i!=NULL; i=i->next) {
+ SPItem *item=SP_ITEM(i->data);
+ if(!isConnector(item)) {
+ filtered.push_back(item);
+ }
+ }
+}
/**
* Takes a list of inkscape items, extracts the graph defined by
* connectors between them, and uses graph layout techniques to find
if(!items) {
return;
}
-#ifdef HAVE_BOOST_GRAPH_LIB
-
using Inkscape::Util::GSListConstIterator;
std::list<SPItem *> selected;
- selected.insert<GSListConstIterator<SPItem *> >(selected.end(), items, NULL);
+ filterConnectors(items,selected);
if (selected.empty()) return;
+ int n=selected.size();
+ std::cout<<"|V|="<<n<<std::endl;
+
Graph g;
double minX=DBL_MAX, minY=DBL_MAX, maxX=-DBL_MAX, maxY=-DBL_MAX;
std::map<std::string,Vertex> nodelookup;
- std::vector<std::string> labels;
- for (std::list<SPItem *>::iterator it(selected.begin());
- it != selected.end();
- ++it)
+ for (std::list<SPItem *>::iterator i(selected.begin());
+ i != selected.end();
+ ++i)
{
- SPItem *u=*it;
- if(!isConnector(u)) {
- std::cout<<"Creating node for id: "<<u->id<<std::endl;
- nodelookup[u->id]=add_vertex(g);
- labels.push_back(u->id);
- }
+ SPItem *u=*i;
+ std::cout<<"Creating node for id: "<<u->id<<std::endl;
+ nodelookup[u->id]=add_vertex(g);
}
- int n=labels.size();
//Check 2 or more selected objects
if (n < 2) return;
WeightMap weightmap=get(edge_weight, g);
- int i=0;
- for (std::list<SPItem *>::iterator it(selected.begin());
- it != selected.end();
- ++it)
+ for (std::list<SPItem *>::iterator i(selected.begin());
+ i != selected.end();
+ ++i)
{
using NR::X; using NR::Y;
- SPItem *itu=*it;
- Vertex u=nodelookup[itu->id];
- GSList *nlist=itu->avoidRef->getAttachedShapes(Avoid::ConnRef::runningFrom);
+ SPItem *iu=*i;
+ std::cout<<"Getting neighbours for id: "<<iu->id<<std::endl;
+ Vertex u=nodelookup[iu->id];
+ GSList *nlist=iu->avoidRef->getAttachedShapes(Avoid::ConnRef::runningFrom);
std::list<SPItem *> neighbours;
neighbours.insert<GSListConstIterator<SPItem *> >(neighbours.end(),nlist,NULL);
- for (std::list<SPItem *>::iterator ne(neighbours.begin());
- ne != neighbours.end();
- ++ne) {
+ for (std::list<SPItem *>::iterator j(neighbours.begin());
+ j != neighbours.end();
+ ++j) {
- SPItem *itv=*ne;
- Vertex v=nodelookup[itv->id];
+ SPItem *iv=*j;
+ Vertex v=nodelookup[iv->id];
Graph::edge_descriptor e; bool inserted;
tie(e, inserted)=add_edge(u,v,g);
weightmap[e]=1.0;
if(nlist) {
g_slist_free(nlist);
}
- NR::Rect const item_box(sp_item_bbox_desktop(*it));
+ NR::Rect const item_box(sp_item_bbox_desktop(*i));
NR::Point ll(item_box.min());
minX=std::min(ll[0],minX);
kamada_kawai_spring_layout(g, position, weightmap, side_length(width));
graph_traits<Graph>::vertex_iterator vi, vi_end;
- i=0;
for (std::list<SPItem *>::iterator it(selected.begin());
it != selected.end();
++it)
sp_item_move_rel(u, NR::translate(dest - curr));
}
}
+}
#else
+void graphlayout(GSList const *const items) {
std::cout<<"Connector network layout not available! Install boost graph library and recompile to enable."<<std::endl;
-#endif // HAVE_BOOST_GRAPH_LIB
}
+#endif // HAVE_BOOST_GRAPH_LIB
index e37f4c4fa188a9a3ab538f2e7fb6bde996a9a22d..40090ef6b54ad8b3ced046f827cdebec765e51cb 100644 (file)
#ifndef SEEN_GRAPHLAYOUT_H
#define SEEN_GRAPHLAYOUT_H
-#include "util/glib-list-iterators.h"
-void graphlayout(GSList const *const items);
+struct _GSList;
+void graphlayout(_GSList const *const items);
+class SPItem;
+bool isConnector(SPItem const *const item);
+#include <list>
+void filterConnectors(_GSList const *const items, std::list<SPItem *> &filtered);
#endif // SEEN_GRAPHLAYOUT_H