diff --git a/lib/logger.cc b/lib/logger.cc index 3bfd61b1..be3ea3d0 100644 --- a/lib/logger.cc +++ b/lib/logger.cc @@ -31,11 +31,12 @@ std::string Logger::toString(const AnyLogMessage& message) { std::stringstream stream; - auto indent = [&]() { - if (!indented) - stream << " "; - indented = false; - }; + auto indent = [&]() + { + if (!indented) + stream << " "; + indented = false; + }; std::visit( overloaded{ @@ -58,7 +59,7 @@ std::string Logger::toString(const AnyLogMessage& message) 60e9 / m.rotationalPeriod); }, - /* Indicates that we're starting a write operation. */ + /* Indicates that we're starting a write operation. */ [&](const BeginWriteOperationLogMessage& m) { stream << fmt::format("{:2}.{}: ", m.cylinder, m.head); @@ -72,10 +73,11 @@ std::string Logger::toString(const AnyLogMessage& message) indented = true; }, - /* We've just read a track (we might reread it if there are errors) */ + /* We've just read a track (we might reread it if there are errors) + */ [&](const TrackReadLogMessage& m) { - const auto& track = *m.track; + const auto& track = *m.track; const auto& trackdataflux = track.trackDatas.end()[-1]; indent(); @@ -98,13 +100,8 @@ std::string Logger::toString(const AnyLogMessage& message) std::vector> sectors( track.sectors.begin(), track.sectors.end()); - std::sort(sectors.begin(), - sectors.end(), - [](const std::shared_ptr& s1, - const std::shared_ptr& s2) - { - return s1->logicalSector < s2->logicalSector; - }); + std::sort( + sectors.begin(), sectors.end(), sectorPointerSortPredicate); for (const auto& sector : sectors) stream << fmt::format(" {}{}", diff --git a/lib/reader.cc b/lib/reader.cc index a5254c2b..5afbf53d 100644 --- a/lib/reader.cc +++ b/lib/reader.cc @@ -99,6 +99,8 @@ std::shared_ptr readDiskCommand(FluxSource& fluxsource, Abstract testForEmergencyStop(); auto track = std::make_shared(); + track->physicalCylinder = cylinder; + track->physicalHead = head; diskflux->tracks.push_back(track); std::set> track_sectors; diff --git a/src/gui/visualisation.cc b/src/gui/visualisation.cc index a44209f5..4ad3a376 100644 --- a/src/gui/visualisation.cc +++ b/src/gui/visualisation.cc @@ -2,6 +2,7 @@ #include "visualisation.h" #include "fluxmap.h" #include "flux.h" +#include "sector.h" #include "fmt/format.h" #include @@ -69,15 +70,43 @@ void VisualisationControl::OnPaint(wxPaintEvent&) ); } - dc.SetBrush(DARK_GREY_BRUSH); - dc.SetPen(DARK_GREY_PEN); for (int track = 0; track <= TRACKS; track++) { int y = scaletop + track*SECTORSIZE; + dc.SetBrush(DARK_GREY_BRUSH); + dc.SetPen(DARK_GREY_PEN); dc.DrawRectangle( { w2-TICK/2, y }, { TICK, SECTORSIZE-1 } ); + + auto drawSectors = + [&](int head) { + key_t key = { track, head }; + std::vector> sectors; + for (auto it = _sectors.lower_bound(key); it != _sectors.upper_bound(key); it++) + sectors.push_back(it->second); + std::sort(sectors.begin(), sectors.end(), sectorPointerSortPredicate); + + int x = 1; + for (const auto& sector : sectors) + { + if (head == 0) + dc.DrawRectangle( + { w2 - x*SECTORSIZE - (SECTORSIZE-1), y }, + { SECTORSIZE-1, SECTORSIZE-1 } + ); + else + dc.DrawRectangle( + { w2 + x*SECTORSIZE, y }, + { SECTORSIZE-1, SECTORSIZE-1 } + ); + x++; + } + }; + + drawSectors(0); + drawSectors(1); } } @@ -97,6 +126,11 @@ void VisualisationControl::Clear() void VisualisationControl::SetTrackData(std::shared_ptr track) { + key_t key = { track->physicalCylinder, track->physicalHead }; + _sectors.erase(key); + for (auto& sector : track->sectors) + _sectors.insert({ key, sector }); + Refresh(); }