From 19a528cb8e524239aaeea16df87558ca4be4cced Mon Sep 17 00:00:00 2001 From: Tim Dwyer Date: Mon, 13 Feb 2006 02:00:14 +0000 Subject: Added connector graph layout functionality (bzr r122) --- src/graphlayout/Makefile_insert | 10 +++ src/graphlayout/graphlayout.cpp | 147 ++++++++++++++++++++++++++++++++++++++++ src/graphlayout/graphlayout.h | 17 +++++ src/graphlayout/makefile | 17 +++++ 4 files changed, 191 insertions(+) create mode 100644 src/graphlayout/Makefile_insert create mode 100644 src/graphlayout/graphlayout.cpp create mode 100644 src/graphlayout/graphlayout.h create mode 100644 src/graphlayout/makefile (limited to 'src/graphlayout') diff --git a/src/graphlayout/Makefile_insert b/src/graphlayout/Makefile_insert new file mode 100644 index 000000000..fc490743d --- /dev/null +++ b/src/graphlayout/Makefile_insert @@ -0,0 +1,10 @@ +## Makefile.am fragment sourced by src/Makefile.am. + +graphlayout/all: graphlayout/libgraphlayout.a + +graphlayout/clean: + rm -f graphlayout/libgraphlayout.a $(graphlayout_libgraphlayout_a_OBJECTS) + +graphlayout_libgraphlayout_a_SOURCES = \ + graphlayout/graphlayout.cpp \ + graphlayout/graphlayout.h diff --git a/src/graphlayout/graphlayout.cpp b/src/graphlayout/graphlayout.cpp new file mode 100644 index 000000000..9828e22fe --- /dev/null +++ b/src/graphlayout/graphlayout.cpp @@ -0,0 +1,147 @@ +/** \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-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 + +/** +* 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; + + std::cout<<"Building graph with "< nodelookup; + for (std::list::iterator it(selected.begin()); + it != selected.end(); + ++it) + { + SPItem *u=*it; + std::cout<<"id:"<id<id,"path",4)) { + nodelookup[u->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: "<id]].x, + minY+height/2.0+position[nodelookup[u->id]].y); + sp_item_move_rel(u, NR::translate(dest - curr)); + } + } +#else + std::cout<<"Connector network layout not available! Install boost graph library and recompile to enable."< + * + * Copyright (C) 2005 Authors + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + +#ifndef SEEN_GRAPHLAYOUT_H +#define SEEN_GRAPHLAYOUT_H +#include "util/glib-list-iterators.h" + +void graphlayout(GSList const *const items); +#endif // SEEN_GRAPHLAYOUT_H diff --git a/src/graphlayout/makefile b/src/graphlayout/makefile new file mode 100644 index 000000000..5d8ac906e --- /dev/null +++ b/src/graphlayout/makefile @@ -0,0 +1,17 @@ +# Convenience stub makefile to call the real Makefile. + + + +# Explicit so that it's the default rule. +all: + cd .. && $(MAKE) graphlayout/all + +clean %.a %.o: + cd .. && $(MAKE) graphlayout/$@ + +.PHONY: all clean + +OBJEXT = o + +.SUFFIXES: +.SUFFIXES: .a .$(OBJEXT) -- cgit v1.2.3