| 1451 | } |
| 1452 | |
| 1453 | void TOPPASScene::topoSort(bool resort_all) |
| 1454 | { |
| 1455 | UInt topo_counter {1}; |
| 1456 | for (TOPPASVertex* tv : vertices_) |
| 1457 | { |
| 1458 | if (resort_all) |
| 1459 | { |
| 1460 | tv->setTopoSortMarked(false); |
| 1461 | } |
| 1462 | else if (tv->isTopoSortMarked()) |
| 1463 | { |
| 1464 | ++topo_counter; // count number of existing/sorted vertices to get correct offset for new vertices |
| 1465 | } |
| 1466 | } |
| 1467 | |
| 1468 | while (true) |
| 1469 | { |
| 1470 | bool some_vertex_not_finished = false; |
| 1471 | for (TOPPASVertex* tv : vertices_) |
| 1472 | { |
| 1473 | if (tv->isTopoSortMarked()) |
| 1474 | { |
| 1475 | continue; |
| 1476 | } |
| 1477 | |
| 1478 | bool has_unmarked_predecessors = false; |
| 1479 | for (TOPPASVertex::ConstEdgeIterator e_it = tv->inEdgesBegin(); e_it != tv->inEdgesEnd(); ++e_it) |
| 1480 | { |
| 1481 | TOPPASVertex* v = (*e_it)->getSourceVertex(); |
| 1482 | if (!(v->isTopoSortMarked())) |
| 1483 | { |
| 1484 | has_unmarked_predecessors = true; |
| 1485 | break; |
| 1486 | } |
| 1487 | } |
| 1488 | if (has_unmarked_predecessors) |
| 1489 | { // needs to be revisited in the next round (where we hopefully have found the predecessors) |
| 1490 | some_vertex_not_finished = true; |
| 1491 | } |
| 1492 | else |
| 1493 | { // mark this node |
| 1494 | // update name of input node |
| 1495 | TOPPASInputFileListVertex* iflv = qobject_cast<TOPPASInputFileListVertex*>(tv); |
| 1496 | if (iflv) |
| 1497 | { |
| 1498 | //check if key was modified by user. if yes, don't update it |
| 1499 | QString old_topo_nr = QString::number(tv->getTopoNr()); |
| 1500 | if (old_topo_nr == iflv->getKey() || iflv->getKey() == "") |
| 1501 | { |
| 1502 | iflv->setKey(QString::number(topo_counter)); |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | tv->setTopoNr(topo_counter); |
| 1507 | tv->setTopoSortMarked(true); |
| 1508 | |
| 1509 | ++topo_counter; |
| 1510 | } |
no test coverage detected