X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fgraphlayout%2Fgraphlayout.cpp;h=81ea590598397ba993e4163abb4b6e456dcad680;hb=11c5de79de3c200331e168a745b0505a50aeffea;hp=00829dac889cdafce1590b08dc3bcdd28f28b7bc;hpb=e8325ddfe05ac8dd00fbf1e25a583ee33887c031;p=inkscape.git diff --git a/src/graphlayout/graphlayout.cpp b/src/graphlayout/graphlayout.cpp index 00829dac8..81ea59059 100644 --- a/src/graphlayout/graphlayout.cpp +++ b/src/graphlayout/graphlayout.cpp @@ -1,46 +1,45 @@ -/** \file - * Interface between Inkscape code (SPItem) and graphlayout functions. +/** @file + * @brief 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 "util/glib-list-iterators.h" -#include "graphlayout/graphlayout.h" + * Authors: + * Tim Dwyer + * + * Copyright (C) 2005 Authors + * + * Released under GNU GPL. Read the file 'COPYING' for more information. + */ + #include #include +#include +#include +#include +#include +#include +#include -#ifdef HAVE_BOOST_GRAPH_LIB +#include "desktop.h" +#include "inkscape.h" +#include "sp-namedview.h" +#include "util/glib-list-iterators.h" +#include "graphlayout/graphlayout.h" #include "sp-path.h" #include "sp-item.h" #include "sp-item-transform.h" #include "sp-conn-end-pair.h" +#include "style.h" #include "conn-avoid-ref.h" #include "libavoid/connector.h" +#include "libavoid/router.h" #include "libavoid/geomtypes.h" -#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; +#include "libcola/cola.h" +#include "libvpsc/generate-constraints.h" +#include "preferences.h" +using namespace std; +using namespace cola; +using namespace vpsc; /** * Returns true if item is a connector */ @@ -52,11 +51,41 @@ bool isConnector(SPItem const *const i) { return path && path->connEndPair.isAutoRoutingConn(); } +struct CheckProgress : TestConvergence { + CheckProgress(double d,unsigned i,list& + selected,vector& rs,map& nodelookup) : + TestConvergence(d,i), selected(selected), rs(rs), nodelookup(nodelookup) {} + bool operator()(double new_stress, double* X, double* Y) { + /* This is where, if we wanted to animate the layout, we would need to update + * the positions of all objects and redraw the canvas and maybe sleep a bit + cout << "stress="<id<id]=add_vertex(g); + Geom::OptRect const item_box(sp_item_bbox_desktop(u)); + if(item_box) { + Geom::Point ll(item_box->min()); + Geom::Point ur(item_box->max()); + nodelookup[u->id]=rs.size(); + rs.push_back(new Rectangle(ll[0]-spacing,ur[0]+spacing, + ll[1]-spacing,ur[1]+spacing)); + } else { + // I'm not actually sure if it's possible for something with a + // NULL item-box to be attached to a connector in which case we + // should never get to here... but if such a null box can occur it's + // probably pretty safe to simply ignore + //fprintf(stderr,"NULL item_box found in graphlayout, ignoring!\n"); + } } - //Check 2 or more selected objects - if (n < 2) return; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + SimpleConstraints scx,scy; + double ideal_connector_length = prefs->getDouble("/tools/connector/length", 100.0); + double directed_edge_height_modifier = 1.0; + + bool directed = prefs->getBool("/tools/connector/directedlayout"); + bool avoid_overlaps = prefs->getBool("/tools/connector/avoidoverlaplayout"); - WeightMap weightmap=get(edge_weight, g); - for (std::list::iterator i(selected.begin()); + for (list::iterator i(selected.begin()); i != selected.end(); ++i) { - using NR::X; using NR::Y; SPItem *iu=*i; - std::cout<<"Getting neighbours for id: "<id<id]; - GSList *nlist=iu->avoidRef->getAttachedShapes(Avoid::runningFrom); - std::list neighbours; - neighbours.insert >(neighbours.end(),nlist,NULL); - for (std::list::iterator j(neighbours.begin()); - j != neighbours.end(); - ++j) { - - 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; - } + map::iterator i=nodelookup.find(iu->id); + if(i==nodelookup.end()) { + continue; + } + unsigned u=i->second; + GSList *nlist=iu->avoidRef->getAttachedConnectors(Avoid::runningFrom); + list connectors; + + connectors.insert >(connectors.end(),nlist,NULL); + for (list::iterator j(connectors.begin()); + j != connectors.end(); + ++j) { + SPItem *conn=*j; + SPItem *iv; + SPItem *items[2]; + assert(isConnector(conn)); + SP_PATH(conn)->connEndPair.getAttachedItems(items); + if(items[0]==iu) { + iv=items[1]; + } else { + iv=items[0]; + } + + if (iv == NULL) { + // The connector is not attached to anything at the + // other end so we should just ignore it. + continue; + } + + // If iv not in nodelookup we again treat the connector + // as disconnected and continue + map::iterator v_pair=nodelookup.find(iv->id); + if(v_pair!=nodelookup.end()) { + unsigned v=v_pair->second; + //cout << "Edge: (" << u <<","<style->marker[SP_MARKER_LOC_END].set) { + if(directed && strcmp(conn->style->marker[SP_MARKER_LOC_END].value,"none")) { + scy.push_back(new SimpleConstraint(v, u, + (ideal_connector_length * directed_edge_height_modifier))); + } + } + } + } if(nlist) { g_slist_free(nlist); } - NR::Rect const item_box(sp_item_bbox_desktop(*i)); - - NR::Point ll(item_box.min()); - minX=std::min(ll[0],minX); - minY=std::min(ll[1],minY); - NR::Point ur(item_box.max()); - maxX=std::max(ur[0],maxX); - maxY=std::max(ur[1],maxY); } - double width=maxX-minX; - double height=maxY-minY; - std::cout<<"Graph has |V|="<