Skip to content

Commit

Permalink
[#57] Support for KryoFlux and associated images (Part 10.1: Optional…
Browse files Browse the repository at this point in the history
… visualization of inspection windows)
  • Loading branch information
tomas-nestorovic committed Nov 12, 2020
1 parent 4850d39 commit 081d24f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Main/res/resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,8 @@ BEGIN
MENUITEM "Zoom out\t�", ID_ZOOM_OUT
MENUITEM "Zoom to fit\tCtrl+0", ID_ZOOM_FIT
MENUITEM SEPARATOR
MENUITEM "Show inspection", ID_RECOGNIZE
MENUITEM SEPARATOR
MENUITEM "Close\tEsc", IDCANCEL
END
END
Expand Down
79 changes: 78 additions & 1 deletion Main/src/Image_TrackEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
#define ZOOM_FACTOR_MAX 24

class CTrackEditor sealed:public Utils::CRideDialog{
const CImage::CTrackReader &tr;
const LPCTSTR caption;
CMainWindow::CDynMenu menu;
PLogTime iwEndTimes;
HANDLE hAutoscrollTimer;

class CTimeEditor sealed:public CScrollView{
const Utils::CRidePen penIndex;
Utils::CTimeline timeline;
CImage::CTrackReader tr;
TLogTime scrollTime;
PCLogTime iwEndTimes; // inspection window end Times (aka. at which Time they end; the end determines the beginning of the immediately next inspection window)

void OnUpdate(CView *pSender,LPARAM lHint,CObject *pHint) override{
// request to refresh the display of content
Expand Down Expand Up @@ -69,6 +72,27 @@
::SetBkMode( dc, TRANSPARENT );
TLogTime timeA,timeZ; // visible region
timeline.Draw( dc, Utils::CRideFont::StdBold, &timeA, &timeZ );
// . drawing inspection windows (if any)
if (iwEndTimes){
// : determining the first visible inspection window
DWORD L=0, R=timeline.logTimeLength/tr.profile.iwTimeMin;
do{
const DWORD M=(L+R)/2;
if (iwEndTimes[L]<=timeA && timeA<iwEndTimes[M])
R=M;
else
L=M;
}while (R-L>1);
// : drawing visible inspection windows
const CBrush brushDarker(0xE4E4B3), brushLighter(0xECECCE);
TLogTime tA=iwEndTimes[L], tZ;
RECT rc={ timeline.GetUnitCount(tA), 1, 0, 40 };
while (tA<timeZ){
rc.right=timeline.GetUnitCount( tZ=iwEndTimes[++L] );
::FillRect( dc, &rc, L&1?brushLighter:brushDarker );
tA=tZ, rc.left=rc.right;
}
}
// . drawing Index pulses
BYTE i=0;
while (i<tr.GetIndexCount() && tr.GetIndexTime(i)<timeA) // invisible indices before visible region
Expand Down Expand Up @@ -101,7 +125,7 @@
: penIndex( 2, 0xff0000 )
, timeline( tr.GetTotalTime(), 1, 10 )
, tr(tr)
, scrollTime(0) {
, scrollTime(0) , iwEndTimes(nullptr) {
}

inline const Utils::CTimeline &GetTimeline() const{
Expand Down Expand Up @@ -142,6 +166,15 @@
scrollTime=t;
Invalidate(FALSE);
}

inline PCLogTime GetInspectionWindowEndTimes() const{
return iwEndTimes;
}

inline void SetInspectionWindowEndTimes(PCLogTime iwEndTimes){
this->iwEndTimes=iwEndTimes;
Invalidate();
}
} timeEditor;

#define AUTOSCROLL_HALF 64
Expand Down Expand Up @@ -215,6 +248,30 @@
return __super::WindowProc( msg, wParam, lParam );
}

static UINT AFX_CDECL CreateInspectionWindowList_thread(PVOID _pCancelableAction){
// thread to create list of inspection windows used to recognize data in the Track
const PBackgroundActionCancelable pAction=(PBackgroundActionCancelable)_pCancelableAction;
CTrackEditor &rte=*(CTrackEditor *)pAction->GetParams();
CImage::CTrackReader tr=rte.tr;
tr.SetCurrentTime(0);
tr.profile.Reset();
const auto nIwsMax=tr.GetTotalTime()/tr.profile.iwTimeMin+2;
if (rte.iwEndTimes=(PLogTime)::calloc( sizeof(TLogTime), nIwsMax )){
if (pAction->IsCancelled()){
::free(rte.iwEndTimes), rte.iwEndTimes=nullptr;
return ERROR_CANCELLED;
}
PLogTime t=rte.iwEndTimes;
*t++=0; // beginning of the very first inspection window
for( pAction->SetProgressTarget(tr.GetTotalTime()); tr; pAction->UpdateProgress(*t++=tr.GetCurrentTime()) )
tr.ReadBit();
for( const PLogTime last=rte.iwEndTimes+nIwsMax; t<last; )
*t++=INT_MAX; // flooding unused part of the buffer with sensible Times
return pAction->TerminateWithError(ERROR_SUCCESS);
}else
return pAction->TerminateWithError(ERROR_NOT_ENOUGH_MEMORY);
}

BOOL OnCmdMsg(UINT nID,int nCode,LPVOID pExtra,AFX_CMDHANDLERINFO *pHandlerInfo){
// command processing
switch (nCode){
Expand All @@ -231,6 +288,9 @@
case ID_ZOOM_FIT:
case IDCANCEL:
return TRUE;
case ID_RECOGNIZE:
pCmdUi->SetCheck( timeEditor.GetInspectionWindowEndTimes()!=nullptr );
return TRUE;
}
break;
}
Expand All @@ -252,6 +312,15 @@
case IDCANCEL:
EndDialog(nID);
return TRUE;
case ID_RECOGNIZE:
if (timeEditor.GetInspectionWindowEndTimes()!=nullptr)
timeEditor.SetInspectionWindowEndTimes(nullptr);
else{
if (iwEndTimes==nullptr)
CBackgroundActionCancelable( CreateInspectionWindowList_thread, this, THREAD_PRIORITY_LOWEST ).Perform();
timeEditor.SetInspectionWindowEndTimes(iwEndTimes);
}
return TRUE;
}
break;
}
Expand All @@ -264,10 +333,18 @@
// - base
: Utils::CRideDialog(IDR_TRACK_EDITOR)
// - initialization
, tr(tr)
, caption(caption) , menu( IDR_TRACK_EDITOR )
, timeEditor(tr)
, iwEndTimes(nullptr)
, hAutoscrollTimer(INVALID_HANDLE_VALUE) {
}

~CTrackEditor(){
// dtor
if (iwEndTimes)
::free(iwEndTimes);
}
};


Expand Down

0 comments on commit 081d24f

Please sign in to comment.