X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fgraphlayout%2Fgraphlayout.cpp;h=60cdab8146c6490e07e810a1ca915e8385a0a243;hb=6958098c760e59aec59c462dccca6502cfbff6eb;hp=ba3ca6e10f1267fcf55c143a5d58c0e75e4b7032;hpb=6b956cc7f8606736070c6189a85bb299b89aab0b;p=inkscape.git diff --git a/src/graphlayout/graphlayout.cpp b/src/graphlayout/graphlayout.cpp index ba3ca6e10..60cdab814 100644 --- a/src/graphlayout/graphlayout.cpp +++ b/src/graphlayout/graphlayout.cpp @@ -3,44 +3,41 @@ */ /* * Authors: -* Tim Dwyer +* 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" #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/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 "prefs-utils.h" +using namespace std; +using namespace cola; +using namespace vpsc; /** * Returns true if item is a connector */ @@ -52,11 +49,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); + boost::optional const item_box(sp_item_bbox_desktop(u)); + if(item_box) { + NR::Point ll(item_box->min()); + NR::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; + SimpleConstraints scx,scy; + double ideal_connector_length = prefs_get_double_attribute("tools.connector","length",100); + double directed_edge_height_modifier = 1.0; + gchar const *directed_str = NULL, *overlaps_str = NULL; + directed_str = prefs_get_string_attribute("tools.connector", + "directedlayout"); + overlaps_str = prefs_get_string_attribute("tools.connector", + "avoidoverlaplayout"); + bool avoid_overlaps = false; + bool directed = false; + if (directed_str && !strcmp(directed_str, "true")) { + directed = true; + } + if (overlaps_str && !strcmp(overlaps_str, "true")) { + avoid_overlaps = true; + } - 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::ConnRef::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|="<