From: tgdwyer Date: Sun, 18 Mar 2007 02:16:59 +0000 (+0000) Subject: more judicious checking of results of find on my shape lookup table. Null X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8e8710f98479448f67caaa47ba421748042540fe;p=inkscape.git more judicious checking of results of find on my shape lookup table. Null bounding boxes could have potentially caused problems. --- diff --git a/src/graphlayout/graphlayout.cpp b/src/graphlayout/graphlayout.cpp index a111d7afe..ffab82362 100644 --- a/src/graphlayout/graphlayout.cpp +++ b/src/graphlayout/graphlayout.cpp @@ -36,7 +36,6 @@ using namespace std; using namespace cola; using namespace vpsc; - /** * Returns true if item is a connector */ @@ -48,6 +47,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="<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); } @@ -182,7 +216,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(); @@ -195,12 +230,15 @@ 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)); - 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)); + map::iterator i=nodelookup.find(u->id); + if(i!=nodelookup.end()) { + Rectangle* r=rs[i->second]; + NR::Maybe 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)); + } } } }