From 07c4a573fb37123709d30ee7a6cc15c9bb15925c Mon Sep 17 00:00:00 2001 From: Tim Dwyer Date: Sun, 16 Jul 2006 13:48:42 +0000 Subject: Layout algorithm is now applied to each connected component in the selection separately. Previously, behaviour of layout on disconnected graphs was... undefined! (bzr r1421) --- src/graphlayout/graphlayout.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'src/graphlayout/graphlayout.cpp') diff --git a/src/graphlayout/graphlayout.cpp b/src/graphlayout/graphlayout.cpp index 403145636..72c47d9bf 100644 --- a/src/graphlayout/graphlayout.cpp +++ b/src/graphlayout/graphlayout.cpp @@ -76,8 +76,6 @@ void graphlayout(GSList const *const items) { //Check 2 or more selected objects if (n < 2) return; - double minX=DBL_MAX, minY=DBL_MAX, maxX=-DBL_MAX, maxY=-DBL_MAX; - map nodelookup; vector rs; vector es; @@ -89,8 +87,6 @@ void graphlayout(GSList const *const items) { NR::Rect const item_box(sp_item_bbox_desktop(u)); NR::Point ll(item_box.min()); NR::Point ur(item_box.max()); - minX=min(ll[0],minX); minY=min(ll[1],minY); - maxX=max(ur[0],maxX); maxY=max(ur[1],maxY); nodelookup[u->id]=rs.size(); rs.push_back(new Rectangle(ll[0],ur[0],ll[1],ur[1])); } @@ -140,7 +136,7 @@ void graphlayout(GSList const *const items) { 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")) { @@ -154,16 +150,25 @@ void graphlayout(GSList const *const items) { g_slist_free(nlist); } } - //double width=maxX-minX; - //double height=maxY-minY; const unsigned E = es.size(); double eweights[E]; fill(eweights,eweights+E,1); - - ConstrainedMajorizationLayout alg(rs,es,eweights,ideal_connector_length); - alg.setupConstraints(NULL,NULL,avoid_overlaps, - NULL,NULL,NULL,&scy,NULL,NULL); - alg.run(); + vector cs; + connectedComponents(rs,es,cs); + for(unsigned i=0;iedges.size();j++) { + Edge& e=c->edges[j]; + printf("(%d,%d) ",e.first,e.second); + } + if(c->edges.size()<2) continue; + cout << endl; + ConstrainedMajorizationLayout alg(c->rects,c->edges,eweights,ideal_connector_length); + alg.setupConstraints(NULL,NULL,avoid_overlaps, + NULL,NULL,NULL,&scy,NULL,NULL); + alg.run(); + } for (list::iterator it(selected.begin()); it != selected.end(); -- cgit v1.2.3