| 594 | } |
| 595 | |
| 596 | void templateRotationTest() |
| 597 | { |
| 598 | #ifdef MAPPER_USE_GDAL |
| 599 | GdalManager().setFormatEnabled(GdalManager::GPX, false); |
| 600 | #endif |
| 601 | |
| 602 | QFETCH(QString, map_file); |
| 603 | QFETCH(int, template_index); |
| 604 | |
| 605 | Map map; |
| 606 | MapView view{ &map }; |
| 607 | QVERIFY(map.loadFrom(map_file, &view)); |
| 608 | |
| 609 | auto const& georef = map.getGeoreferencing(); |
| 610 | QCOMPARE(georef.getState(), Georeferencing::Geospatial); |
| 611 | QVERIFY(std::abs(georef.getGrivation()) >= 0.01); |
| 612 | |
| 613 | QVERIFY(map.getNumTemplates() > template_index); |
| 614 | auto const* temp = map.getTemplate(template_index); |
| 615 | QCOMPARE(temp->getTemplateState(), Template::Unloaded); |
| 616 | |
| 617 | // A clone of temp which is loaded before map rotation |
| 618 | auto* loaded_clone = temp->duplicate(); |
| 619 | map.addTemplate(map.getNumTemplates(), std::unique_ptr<Template>(loaded_clone)); |
| 620 | if (loaded_clone->getTemplateState() != Template::Loaded) |
| 621 | QVERIFY(loaded_clone->loadTemplateFile()); |
| 622 | QCOMPARE(loaded_clone->getTemplateState(), Template::Loaded); |
| 623 | |
| 624 | // A clone of temp which is loaded and unloaded before map rotation |
| 625 | auto* reloaded_clone = temp->duplicate(); |
| 626 | map.addTemplate(map.getNumTemplates(), std::unique_ptr<Template>(reloaded_clone)); |
| 627 | if (reloaded_clone->getTemplateState() != Template::Loaded) |
| 628 | QVERIFY(reloaded_clone->loadTemplateFile()); |
| 629 | reloaded_clone->unloadTemplateFile(); |
| 630 | QCOMPARE(reloaded_clone->getTemplateState(), Template::Unloaded); |
| 631 | |
| 632 | auto initially_georeferenced = temp->isTemplateGeoreferenced(); |
| 633 | auto initial_rotation = temp->getTemplateRotation(); // radians |
| 634 | if (initially_georeferenced) |
| 635 | QCOMPARE(initial_rotation, 0.0); |
| 636 | |
| 637 | // ROTATION |
| 638 | auto const ref_point = map.getGeoreferencing().getMapRefPoint(); |
| 639 | map.rotateMap(0.1, ref_point, true, true, true); // radians |
| 640 | |
| 641 | if (!initially_georeferenced) |
| 642 | QCOMPARE(temp->getTemplateRotation(), initial_rotation + 0.1); // radians |
| 643 | |
| 644 | // TEMPLATE LOADING |
| 645 | QVERIFY(map.getTemplate(template_index)->loadTemplateFile()); |
| 646 | QCOMPARE(temp->getTemplateState(), Template::Loaded); |
| 647 | |
| 648 | QVERIFY(reloaded_clone->loadTemplateFile()); |
| 649 | QCOMPARE(reloaded_clone->getTemplateState(), Template::Loaded); |
| 650 | |
| 651 | // The template rectangle is in the interior of the map figure. |
| 652 | auto const expected_center = map.calculateExtent().center(); |
| 653 | // Template instance loaded only after configuration |
nothing calls this directly
no test coverage detected