diff -r cac93797c580 -r d922fb6ea482 mapeditor.cpp --- a/mapeditor.cpp Wed Sep 09 12:57:06 2009 +0000 +++ b/mapeditor.cpp Fri Sep 11 12:56:15 2009 +0000 @@ -560,7 +560,7 @@ void MapEditor::testFunction2() { // Create list with all bounding polygons - QList mapobjects; + QList mapobjects; QList polys; ConvexPolygon p; QList vectors; @@ -570,25 +570,16 @@ BranchItem *bi; BranchItem *bi2; BranchObj *bo; - BranchItem *ri=model->getRootItem(); - for (int i=0;ibranchCount();++i) + + // Outer loop: Iterate until we no more changes in orientation + bool orientationChanged=true; + while (orientationChanged) { - bi=ri->getBranchNum (i); - bo=(BranchObj*)bi->getLMO(); - if (bo) + BranchItem *ri=model->getRootItem(); + for (int i=0;ibranchCount();++i) { - mapobjects.append (bo); - p=bo->getBoundingPolygon(); - p.calcCentroid(); - polys.append(p); - vectors.append (QPointF(0,0)); - orgpos.append (p.at(0)); - headings.append (bi->getHeading()); - } - for (int j=0;jbranchCount();++j) - { - bi2=bi->getBranchNum (j); - bo=(BranchObj*)bi2->getLMO(); + bi=ri->getBranchNum (i); + bo=(BranchObj*)bi->getLMO(); if (bo) { mapobjects.append (bo); @@ -597,57 +588,85 @@ polys.append(p); vectors.append (QPointF(0,0)); orgpos.append (p.at(0)); - headings.append (bi2->getHeading()); - } - } - } - - // Iterate moving bounding polygons until we have no more collisions - int collisions=1; - while (collisions>0) - { - collisions=0; - for (int i=0; igetHeading()); + } + for (int j=0;jbranchCount();++j) { - if (polygonCollision (polys.at(i),polys.at(j), QPointF(0,0)).intersect ) + bi2=bi->getBranchNum (j); + bo=(BranchObj*)bi2->getLMO(); + if (bo) { - collisions++; - v=polys.at(j).centroid()-polys.at(i).centroid(); - // Move also away if centroids are identical - if (v.isNull()) - { - //cout << "v==0="<getBoundingPolygon(); + p.calcCentroid(); + polys.append(p); + vectors.append (QPointF(0,0)); + orgpos.append (p.at(0)); + headings.append (bi2->getHeading()); + } } } - for (int i=0;i0) { - //cout << " v="<moveBy(v.x(),v.y() ); - } - model->reposition(); + // Finally move the real objects and update + QList orients; + for (int i=0;igetOrientation()); + mapobjects[i]->moveBy(v.x(),v.y() ); + } + model->reposition(); + orientationChanged=false; + for (int i=0;igetOrientation()) + { + orientationChanged=true; + break; + } + cout << "Final: orientChanged="<setRelPos(); } + } // depth>0 // Maybe we can relink temporary? if (dsti) { @@ -1208,7 +1228,6 @@ } // reposition subbranch lmosel->reposition(); - } // depth>0 QItemSelection sel=model->getSelectionModel()->selection(); updateSelection(sel,sel); // position has changed @@ -1278,7 +1297,11 @@ tmpXLink->setEnd ( ((BranchItem*)dsti) ); tmpXLink->updateXLink(); tmpXLink->activate(); - //FIXME-0 model->saveStateComplete(QString("Activate xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(tmpXLink->getEnd())) ); + model->saveState( + tmpXLink,QString("delete ()"), + dsti,QString("addXLink (\"%1\",\"%2\")").arg(model->getSelectString(tmpXLink->getBegin())).arg(model->getSelectString(dsti)), + QString("Add xLink from %1 to %2").arg(model->getObjectName(tmpXLink->getBegin())).arg(model->getObjectName(dsti)) + ); } else { model->deleteItem(tmpXLink);