dunnart
dunnart copied to clipboard
bux fix in multi-edge
I am currently using the dunnartcanvas library and trying to connect it with my own application. I need to display multi-edge connections nicely. I found some bugs in the algorithm I'd like to share.
- GraphData::setupMultiEdges() is not updating Connectors correctly. The first for loop is initialising m_is_multiedge = false for every Connector, but you need also to initialise m_multiedge_size and m_multiedge_index. The code:
for(list<Connector*>::iterator i=conList.begin();i!=conList.end();i++) { (_i)->m_is_multiedge=false; (_i)->m_multiedge_size=1; // ADD THIS LINE (*i)->m_multiedge_index=0; // ADD THIS LINE }
- when two connectors connect the same shapes but in reverse directions the indexing is wrong. I introduced a bool (m_multiedge_reverse) for that. Below the last for loop in GraphData::setupMultiEdges() :
for(list<list<Connector*> >::iterator i=conDups.begin();i!=conDups.end();i++) { unsigned ctr=0; uint firstShapeId; // ADD THIS LINE for(list<Connector*>::iterator j=i->begin();j!=i->end();j++) { QPair<ShapeObj *, ShapeObj *> p = (_j)->getAttachedShapes(); if (ctr==0) {firstShapeId = p.first->internalId();} // ADD THIS LINE (_j)->m_multiedge_size=i->size(); (_j)->m_multiedge_index=ctr++; (_j)->m_multiedge_reverse=!(firstShapeId == p.first->internalId()); // ADD THIS LINE } }
also m_multiedge_reverse has to be initialised to false at the beginning of the function.
below a few modifications in Connector::applyMultiEdgeOffset: ... double reverse = m_multiedge_reverse ? -1 : 1; // ADD THIS LINE Point offset(nx_pos_pointOffset_reverse, ny_pos_pointOffset_reverse);