diff options
Diffstat (limited to 'src/graphlayout')
| -rw-r--r-- | src/graphlayout/graphlayout.cpp | 150 |
1 files changed, 75 insertions, 75 deletions
diff --git a/src/graphlayout/graphlayout.cpp b/src/graphlayout/graphlayout.cpp index 81ea59059..23b0ee13b 100644 --- a/src/graphlayout/graphlayout.cpp +++ b/src/graphlayout/graphlayout.cpp @@ -44,21 +44,21 @@ using namespace vpsc; * Returns true if item is a connector */ bool isConnector(SPItem const *const i) { - SPPath *path = NULL; - if(SP_IS_PATH(i)) { - path = SP_PATH(i); - } - return path && path->connEndPair.isAutoRoutingConn(); + SPPath *path = NULL; + if(SP_IS_PATH(i)) { + path = SP_PATH(i); + } + return path && path->connEndPair.isAutoRoutingConn(); } struct CheckProgress : TestConvergence { CheckProgress(double d,unsigned i,list<SPItem *>& - selected,vector<Rectangle*>& rs,map<string,unsigned>& nodelookup) : + selected,vector<Rectangle*>& rs,map<string,unsigned>& nodelookup) : TestConvergence(d,i), selected(selected), rs(rs), nodelookup(nodelookup) {} - bool operator()(double new_stress, double* X, double* Y) { + 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="<<new_stress<<endl; + cout << "stress="<<new_stress<<endl; cout << "x[0]="<<rs[0]->getMinX()<<endl; for (list<SPItem *>::iterator it(selected.begin()); it != selected.end(); @@ -74,43 +74,43 @@ struct CheckProgress : TestConvergence { } } */ - return TestConvergence::operator()(new_stress,X,Y); - } + return TestConvergence::operator()(new_stress,X,Y); + } list<SPItem *>& selected; vector<Rectangle*>& rs; map<string,unsigned>& nodelookup; }; /** - * Scans the items list and places those items that are + * Scans the items list and places those items that are * not connectors in filtered */ void filterConnectors(GSList const *const items, list<SPItem *> &filtered) { - for(GSList *i=(GSList *)items; i!=NULL; i=i->next) { - SPItem *item=SP_ITEM(i->data); - if(!isConnector(item)) { - filtered.push_back(item); - } - } + for(GSList *i=(GSList *)items; i!=NULL; i=i->next) { + SPItem *item=SP_ITEM(i->data); + if(!isConnector(item)) { + filtered.push_back(item); + } + } } /** -* Takes a list of inkscape items, extracts the graph defined by +* Takes a list of inkscape items, extracts the graph defined by * connectors between them, and uses graph layout techniques to find * a nice layout */ void graphlayout(GSList const *const items) { - if(!items) { - return; - } + if(!items) { + return; + } - using Inkscape::Util::GSListConstIterator; - list<SPItem *> selected; - filterConnectors(items,selected); - if (selected.empty()) return; + using Inkscape::Util::GSListConstIterator; + list<SPItem *> selected; + filterConnectors(items,selected); + if (selected.empty()) return; - const unsigned n=selected.size(); - //Check 2 or more selected objects - if (n < 2) return; + const unsigned n=selected.size(); + //Check 2 or more selected objects + if (n < 2) return; // add the connector spacing to the size of node bounding boxes // so that connectors can always be routed between shapes @@ -118,19 +118,19 @@ void graphlayout(GSList const *const items) { double spacing = 0; if(desktop) spacing = desktop->namedview->connector_spacing+0.1; - map<string,unsigned> nodelookup; - vector<Rectangle*> rs; - vector<Edge> es; - for (list<SPItem *>::iterator i(selected.begin()); - i != selected.end(); - ++i) - { - SPItem *u=*i; - Geom::OptRect const item_box(sp_item_bbox_desktop(u)); + map<string,unsigned> nodelookup; + vector<Rectangle*> rs; + vector<Edge> es; + for (list<SPItem *>::iterator i(selected.begin()); + i != selected.end(); + ++i) + { + SPItem *u=*i; + 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(); + nodelookup[u->getId()]=rs.size(); rs.push_back(new Rectangle(ll[0]-spacing,ur[0]+spacing, ll[1]-spacing,ur[1]+spacing)); } else { @@ -140,29 +140,29 @@ void graphlayout(GSList const *const items) { // probably pretty safe to simply ignore //fprintf(stderr,"NULL item_box found in graphlayout, ignoring!\n"); } - } + } 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"); + 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"); - for (list<SPItem *>::iterator i(selected.begin()); - i != selected.end(); - ++i) - { - SPItem *iu=*i; - map<string,unsigned>::iterator i=nodelookup.find(iu->id); + for (list<SPItem *>::iterator i(selected.begin()); + i != selected.end(); + ++i) + { + SPItem *iu=*i; + map<string,unsigned>::iterator i=nodelookup.find(iu->getId()); if(i==nodelookup.end()) { continue; } unsigned u=i->second; GSList *nlist=iu->avoidRef->getAttachedConnectors(Avoid::runningFrom); list<SPItem *> connectors; - + connectors.insert<GSListConstIterator<SPItem *> >(connectors.end(),nlist,NULL); for (list<SPItem *>::iterator j(connectors.begin()); j != connectors.end(); @@ -177,35 +177,35 @@ void graphlayout(GSList const *const items) { } else { iv=items[0]; } - + if (iv == NULL) { - // The connector is not attached to anything at the + // 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<string,unsigned>::iterator v_pair=nodelookup.find(iv->id); + map<string,unsigned>::iterator v_pair=nodelookup.find(iv->getId()); if(v_pair!=nodelookup.end()) { unsigned v=v_pair->second; //cout << "Edge: (" << u <<","<<v<<")"<<endl; es.push_back(make_pair(u,v)); if(conn->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, + scy.push_back(new SimpleConstraint(v, u, (ideal_connector_length * directed_edge_height_modifier))); } } } } - if(nlist) { - g_slist_free(nlist); - } - } - const unsigned E = es.size(); - double eweights[E]; - fill(eweights,eweights+E,1); + if(nlist) { + g_slist_free(nlist); + } + } + const unsigned E = es.size(); + double eweights[E]; + fill(eweights,eweights+E,1); vector<Component*> cs; connectedComponents(rs,es,scx,scy,cs); for(unsigned i=0;i<cs.size();i++) { @@ -218,15 +218,15 @@ void graphlayout(GSList const *const items) { alg.run(); } separateComponents(cs); - - for (list<SPItem *>::iterator it(selected.begin()); - it != selected.end(); - ++it) - { - SPItem *u=*it; - if(!isConnector(u)) { - map<string,unsigned>::iterator i=nodelookup.find(u->id); - if(i!=nodelookup.end()) { + + for (list<SPItem *>::iterator it(selected.begin()); + it != selected.end(); + ++it) + { + SPItem *u=*it; + if(!isConnector(u)) { + map<string,unsigned>::iterator i=nodelookup.find(u->getId()); + if(i!=nodelookup.end()) { Rectangle* r=rs[i->second]; Geom::OptRect item_box(sp_item_bbox_desktop(u)); if(item_box) { @@ -235,8 +235,8 @@ void graphlayout(GSList const *const items) { sp_item_move_rel(u, Geom::Translate(dest - curr)); } } - } - } + } + } for(unsigned i=0;i<scx.size();i++) { delete scx[i]; } @@ -247,7 +247,7 @@ void graphlayout(GSList const *const items) { delete rs[i]; } } -// vim: set cindent +// vim: set cindent // vim: ts=4 sw=4 et tw=0 wm=0 /* |
