Skip to content

Commit

Permalink
Merge pull request #2038 from AllenInstitute/bugfix/2038-analysisbrow…
Browse files Browse the repository at this point in the history
…ser-reusing-wrong-index-in-map-backport

Fix wrong index handling in analysis browser
  • Loading branch information
t-b authored Mar 8, 2024
2 parents f85d45e + 825c14e commit 4d92b38
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 29 deletions.
68 changes: 39 additions & 29 deletions Packages/MIES/MIES_AnalysisBrowser.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ End
static Function AB_AddMapEntry(baseFolder, discLocation)
string baseFolder, discLocation

variable index, fileID, nwbVersion, dim
variable nextFreeIndex, fileID, nwbVersion, dim, writeIndex
string dataFolder, fileType, relativePath, extension
WAVE/T map = GetAnalysisBrowserMap()

Expand All @@ -99,21 +99,22 @@ static Function AB_AddMapEntry(baseFolder, discLocation)
return -1
endif

index = GetNumberFromWaveNote(map, NOTE_INDEX)
nextFreeIndex = GetNumberFromWaveNote(map, NOTE_INDEX)
dim = FindDimLabel(map, COLS, "DiscLocation")
FindValue/TEXT=""/TXOP=4/RMD=[][dim] map
if(V_row < index)
index = V_row
FindValue/TEXT=""/TXOP=4/RMD=[0, nextFreeIndex - 1][dim] map
if(V_row >= 0)
writeIndex = V_row
else
EnsureLargeEnoughWave(map, indexShouldExist=index, dimension=ROWS)
writeIndex = nextFreeIndex
EnsureLargeEnoughWave(map, indexShouldExist=writeIndex, dimension=ROWS)
endif

// %DiscLocation = full path to file
map[index][%DiscLocation] = discLocation
map[writeIndex][%DiscLocation] = discLocation

// %FileName = filename + extension
relativePath = RemovePrefix(discLocation, start = baseFolder)
map[index][%FileName] = relativePath
map[writeIndex][%FileName] = relativePath

extension = "." + GetFileSuffix(discLocation)

Expand Down Expand Up @@ -141,19 +142,21 @@ static Function AB_AddMapEntry(baseFolder, discLocation)
default:
ASSERT(0, "invalid file type")
endswitch
map[index][%FileType] = fileType
map[writeIndex][%FileType] = fileType

DFREF dfrAB = GetAnalysisFolder()
DFREF dfr = dfrAB:$AB_GetUserData(AB_UDATA_WORKINGDF)
DFREF expFolder = UniqueDataFolder(dfr, RemoveEnding(relativePath, extension))
dataFolder = RemovePrefix(GetDataFolder(1, expFolder), start = GetDataFolder(1, dfrAB))
map[index][%DataFolder] = RemoveEnding(dataFolder, ":")
map[writeIndex][%DataFolder] = RemoveEnding(dataFolder, ":")
RefCounterDFIncrease(expFolder)

index += 1
SetNumberInWaveNote(map, NOTE_INDEX, index)
if(writeIndex == nextFreeIndex)
nextFreeIndex += 1
SetNumberInWaveNote(map, NOTE_INDEX, nextFreeIndex)
endif

return index - 1
return writeIndex
End

static Function AB_RemoveMapEntry(variable index)
Expand Down Expand Up @@ -2925,28 +2928,35 @@ Function AB_ButtonProc_AddFiles(ba) : ButtonControl
break
endif
WAVE/T selFiles = ListToTextWave(fileList, "\r")
Duplicate/FREE/T selFiles, newFiles

WAVE/T folderList = GetAnalysisBrowserGUIFolderList()
size = DimSize(selFiles, ROWS)
for(i = 0; i < size; i += 1)
FindValue/TEXT=selFiles[i]/TXOP=4 folderList
if(V_Value >= 0)
continue
endif
AB_AddElementToSourceList(selFiles[i])
newFiles[index] = selFiles[i]
index += 1
endfor
Redimension/N=(index) newFiles

AB_AddExperimentEntries(ba.win, newFiles)
AB_AddFiles(ba.win, selFiles)
break
endswitch

return 0
End

static Function AB_AddFiles(string win, WAVE/T selFiles)

variable i, index, size

Duplicate/FREE/T selFiles, newFiles

WAVE/T folderList = GetAnalysisBrowserGUIFolderList()
size = DimSize(selFiles, ROWS)
for(i = 0; i < size; i += 1)
FindValue/TEXT=selFiles[i]/TXOP=4 folderList
if(V_Value >= 0)
continue
endif
AB_AddElementToSourceList(selFiles[i])
newFiles[index] = selFiles[i]
index += 1
endfor
Redimension/N=(index) newFiles

AB_AddExperimentEntries(win, newFiles)
End

static Function AB_AddElementToSourceList(string entry)

variable size
Expand Down
30 changes: 30 additions & 0 deletions Packages/MIES/MIES_GuiUtilities.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,36 @@ Function GetListBoxSelRow(win, ctrl)
return V_Value
End

/// @brief Set the listbox selection
///
/// @param win panel
/// @param ctrl control
/// @param val One of @ref ListBoxSelectionWaveFlags
/// @param row row index
/// @param col [optional, defaults to all columns] column index
Function SetListBoxSelection(string win, string ctrl, variable val, variable row, [variable col])

variable colStart, colEnd

if(ParamIsDefault(col))
colStart = 0
colEnd = inf
else
colStart = col
colEnd = col
endif

ControlInfo/W=$win $ctrl
ASSERT(V_flag == 11, "Not a listbox control")
WAVE/Z selWave = $GetValueFromRecMacro("selWave", S_recreation)
ASSERT(WaveExists(selWave), "Missing selection wave")

ASSERT(row < DimSize(selWave, ROWS), "Invalid row")
ASSERT(col < DimSize(selWave, COLS), "Invalid col")

selWave[row][colStart, colEnd][0][0] = val
End

/// @brief Check if the location `loc` is inside the rectangle `r`
Function IsInsideRect(loc, r)
STRUCT Point& loc
Expand Down
26 changes: 26 additions & 0 deletions Packages/tests/HistoricData/UTF_HistoricDashboard.ipf
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,29 @@ Function TestDashboardWithHistoricData([string str])
bsPanel = BSP_GetPanel(sbWin)
PGC_SetAndActivateControl(bsPanel, "check_BrowserSettings_DS", val = 1)
End

Function TestAnalysisBrowserAddingFiles()

string abWin, sweepBrowsers, fileToReadd
variable holeIndex

WAVE/T files = GetHistoricDataFiles()
files[] = "input:" + files[p]

[abWin, sweepBrowsers] = OpenAnalysisBrowser(files)

PGC_SetAndActivateControl(abWin, "button_collapse_all")

WAVE/T map = GetAnalysisBrowserMap()
CHECK_EQUAL_VAR(GetNumberFromWaveNote(map, NOTE_INDEX), DimSize(files, ROWS))

holeIndex = 1
fileToReadd = map[holeIndex]

SetListBoxSelection(abWin, "listbox_AB_Folders", LISTBOX_SELECTED, holeIndex)
PGC_SetAndActivateControl(abWin, "button_AB_Remove")
CHECK_EQUAL_VAR(GetNumberFromWaveNote(map, NOTE_INDEX), DimSize(files, ROWS))

MIES_AB#AB_AddFiles(abWin, {fileToReadd})
CHECK_EQUAL_VAR(GetNumberFromWaveNote(map, NOTE_INDEX), DimSize(files, ROWS))
End

0 comments on commit 4d92b38

Please sign in to comment.