X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fgraphlayout%2Fgraphlayout.cpp;h=60cdab8146c6490e07e810a1ca915e8385a0a243;hb=6958098c760e59aec59c462dccca6502cfbff6eb;hp=78053271853acd99d045d64ddc237ba2690299a9;hpb=6e3576be211b59b7d8a9e7afe3493d961c053b75;p=inkscape.git diff --git a/src/graphlayout/graphlayout.cpp b/src/graphlayout/graphlayout.cpp index 780532718..60cdab814 100644 --- a/src/graphlayout/graphlayout.cpp +++ b/src/graphlayout/graphlayout.cpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include "desktop.h" @@ -36,7 +38,6 @@ using namespace std; using namespace cola; using namespace vpsc; - /** * Returns true if item is a connector */ @@ -48,6 +49,36 @@ 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]; - 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]; - } - + 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; } - // What do we do if iv not in nodelookup?!?! - 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, + // 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); } @@ -175,7 +218,8 @@ void graphlayout(GSList const *const items) { for(unsigned i=0;iedges.size()<2) continue; - ConstrainedMajorizationLayout alg(c->rects,c->edges,eweights,ideal_connector_length); + CheckProgress test(0.0001,100,selected,rs,nodelookup); + ConstrainedMajorizationLayout alg(c->rects,c->edges,eweights,ideal_connector_length,test); alg.setupConstraints(NULL,NULL,avoid_overlaps, NULL,NULL,&c->scx,&c->scy,NULL,NULL); alg.run(); @@ -188,12 +232,16 @@ void graphlayout(GSList const *const items) { { SPItem *u=*it; if(!isConnector(u)) { - Rectangle* r=rs[nodelookup[u->id]]; - NR::Maybe item_box(sp_item_bbox_desktop(u)); - g_assert(item_box); - NR::Point const curr(item_box->midpoint()); - NR::Point const dest(r->getCentreX(),r->getCentreY()); - sp_item_move_rel(u, NR::translate(dest - curr)); + map::iterator i=nodelookup.find(u->id); + if(i!=nodelookup.end()) { + Rectangle* r=rs[i->second]; + boost::optional item_box(sp_item_bbox_desktop(u)); + if(item_box) { + NR::Point const curr(item_box->midpoint()); + NR::Point const dest(r->getCentreX(),r->getCentreY()); + sp_item_move_rel(u, NR::translate(dest - curr)); + } + } } } for(unsigned i=0;i