diff --git a/Packages/MIES/MIES_Constants.ipf b/Packages/MIES/MIES_Constants.ipf index a8fb0b502f..b73cccda27 100644 --- a/Packages/MIES/MIES_Constants.ipf +++ b/Packages/MIES/MIES_Constants.ipf @@ -2518,12 +2518,15 @@ StrConstant SF_OP_SELECTIVSCCSWEEPQC = "selivsccsweepqc" StrConstant SF_OP_SELECTIVSCCSETQC = "selivsccsetqc" StrConstant SF_OP_SELECTRANGE = "selrange" StrConstant SF_OP_POWERSPECTRUM = "powerspectrum" +StrConstant SF_OP_TABLE = "table" StrConstant SF_OP_TPSS = "tpss" StrConstant SF_OP_TPINST = "tpinst" StrConstant SF_OP_TPBASE = "tpbase" StrConstant SF_OP_TPFIT = "tpfit" ///@} +StrConstant SF_PROPERTY_TABLE = "Table" + /// @name SF operations shorts /// /// @anchor SFOperationsShorts diff --git a/Packages/MIES/MIES_SweepFormula.ipf b/Packages/MIES/MIES_SweepFormula.ipf index f4cd3b19eb..e74be9ce3e 100644 --- a/Packages/MIES/MIES_SweepFormula.ipf +++ b/Packages/MIES/MIES_SweepFormula.ipf @@ -70,7 +70,7 @@ Function/WAVE SF_GetNamedOperations() SF_OP_MERGE, SF_OP_FIT, SF_OP_FITLINE, SF_OP_DATASET, SF_OP_SELECTVIS, SF_OP_SELECTCM, SF_OP_SELECTSTIMSET, \ SF_OP_SELECTIVSCCSWEEPQC, SF_OP_SELECTIVSCCSETQC, SF_OP_SELECTRANGE, SF_OP_SELECTEXP, SF_OP_SELECTDEV, \ SF_OP_SELECTEXPANDSCI, SF_OP_SELECTEXPANDRAC, SF_OP_SELECTSETCYCLECOUNT, SF_OP_SELECTSETSWEEPCOUNT, \ - SF_OP_SELECTSCIINDEX, SF_OP_SELECTRACINDEX, SF_OP_ANAFUNCPARAM, SF_OP_CONCAT} + SF_OP_SELECTSCIINDEX, SF_OP_SELECTRACINDEX, SF_OP_ANAFUNCPARAM, SF_OP_CONCAT, SF_OP_TABLE} return wt End @@ -544,14 +544,73 @@ static Function/S SF_ShrinkLegend(string annotation) return shrunkAnnotation End +static Function SF_ClearPlotPanel(string win) + + string subWindow + variable wType + + TUD_Clear(win, recursive = 1) + + WAVE/T allWindows = ListToTextWave(GetAllWindows(win), ";") + + for(subWindow : allWindows) + if(IsSubwindow(subWindow)) + // in complex hierarchies we might kill more outer subwindows first + // so the inner ones might later not exist anymore + KillWindow/Z $subWindow + endif + endfor + + RemoveAllControls(win) + wType = WinType(win) + if(wType == WINTYPE_PANEL || wType == WINTYPE_GRAPH) + RemoveAllDrawLayers(win) + endif +End + +/// @brief Creates a new panel for sweepformula display of graph or table and returns the actual window name +/// +/// @param[in] templateName base name of new window +/// @param[in] graph name of sweepbrowser/databrowser window +/// @param[in] winType [optional, default WINTYPE_PANEL] specifies window type +/// @returns name of created window +static Function/S SF_NewSweepFormulaBaseWindow(string templateName, string graph, [variable winType]) + + string win + + winType = ParamIsDefault(winType) ? WINTYPE_PANEL : winType + + win = templateName + if(WindowExists(win)) + SF_ClearPlotPanel(win) + else + if(winType == WINTYPE_GRAPH) + Display/N=$win/K=1/W=(150, 400, 1000, 700) + elseif(winType == WINTYPE_PANEL) + NewPanel/N=$win/K=1/W=(150, 400, 1000, 700) + elseif(winType == WINTYPE_TABLE) + Edit/N=$win/K=1/W=(150, 400, 1000, 700) + else + FATAL_ERROR("Unsupported window type") + endif + win = S_name + + SF_CommonWindowSetup(win, graph) + endif + + return win +End + static Function [WAVE/T plotGraphs, WAVE/WAVE infos] SF_PreparePlotter(string winNameTemplate, string graph, variable winDisplayMode, variable numGraphs) variable i, guidePos, restoreCursorInfo - string panelName, guideName1, guideName2, win + string panelName, guideName1, guideName2, win, winTable, winNameTemplateTable ASSERT(numGraphs > 0, "Can not prepare plotter window for zero graphs") - Make/FREE/T/N=(numGraphs) plotGraphs + winNameTemplateTable = winNameTemplate + "table" + + WAVE/T plotGraphs = GetPlotGraphNames(numGraphs) Make/FREE/WAVE/N=(numGraphs, 3) infos SetDimensionLabels(infos, "axes;cursors;annotations", COLS) @@ -580,41 +639,15 @@ static Function [WAVE/T plotGraphs, WAVE/WAVE infos] SF_PreparePlotter(string wi if(winDisplayMode == SF_DM_NORMAL) for(i = 0; i < numGraphs; i += 1) - win = winNameTemplate + num2istr(i) - - if(!WindowExists(win)) - Display/N=$win/K=1/W=(150, 400, 1000, 700) as win - win = S_name - endif - - SF_CommonWindowSetup(win, graph) - - plotGraphs[i] = win + win = winNameTemplate + num2istr(i) + plotGraphs[i][%GRAPH] = SF_NewSweepFormulaBaseWindow(win, graph, winType = WINTYPE_GRAPH) + win = winNameTemplateTable + num2istr(i) + plotGraphs[i][%TABLE] = SF_NewSweepFormulaBaseWindow(win, graph, winType = WINTYPE_TABLE) endfor elseif(winDisplayMode == SF_DM_SUBWINDOWS) - win = winNameTemplate - if(WindowExists(win)) - TUD_Clear(win, recursive = 1) - - WAVE/T allWindows = ListToTextWave(GetAllWindows(win), ";") - - for(subWindow : allWindows) - if(IsSubwindow(subWindow)) - // in complex hierarchies we might kill more outer subwindows first - // so the inner ones might later not exist anymore - KillWindow/Z $subWindow - endif - endfor - - RemoveAllControls(win) - RemoveAllDrawLayers(win) - else - NewPanel/N=$win/K=1/W=(150, 400, 1000, 700) - win = S_name - - SF_CommonWindowSetup(win, graph) - endif + win = SF_NewSweepFormulaBaseWindow(winNameTemplate, graph) + winTable = SF_NewSweepFormulaBaseWindow(winNameTemplateTable, graph) // now we have an open panel without any subwindows @@ -627,23 +660,32 @@ static Function [WAVE/T plotGraphs, WAVE/WAVE infos] SF_PreparePlotter(string wi guideName1 = SF_PLOTTER_GUIDENAME + num2istr(i) guidePos = i / numGraphs DefineGuide/W=$win $guideName1={FT, guidePos, FB} + DefineGuide/W=$winTable $guideName1={FT, guidePos, FB} endfor DefineGuide/W=$win customLeft={FL, 0.0, FR} DefineGuide/W=$win customRight={FL, 1.0, FR} + DefineGuide/W=$winTable customLeft={FL, 0.0, FR} + DefineGuide/W=$winTable customRight={FL, 1.0, FR} // and now the subwindow graphs for(i = 0; i < numGraphs; i += 1) guideName1 = SF_PLOTTER_GUIDENAME + num2istr(i) guideName2 = SF_PLOTTER_GUIDENAME + num2istr(i + 1) Display/HOST=$win/FG=(customLeft, $guideName1, customRight, $guideName2)/N=$("Graph" + num2str(i)) - plotGraphs[i] = winNameTemplate + "#" + S_name + plotGraphs[i][%GRAPH] = win + "#" + S_name + Edit/HOST=$winTable/FG=(customLeft, $guideName1, customRight, $guideName2)/N=$("Table" + num2str(i)) + plotGraphs[i][%TABLE] = winTable + "#" + S_name endfor endif - for(win : plotGraphs) + for(i = 0; i < numGraphs; i += 1) + win = plotGraphs[i][%GRAPH] RemoveTracesFromGraph(win) ModifyGraph/W=$win swapXY=0 + + win = plotGraphs[i][%TABLE] + RemoveAllColumnsFromTable(win) endfor return [plotGraphs, infos] @@ -788,6 +830,15 @@ static Function/WAVE SF_PrepareResultWaveForPlotting(DFREF dfr, WAVE wvResult, v return plotWave End +static Function SF_IsDataForTableDisplay(WAVE wvY) + + variable useTable + + useTable = JWN_GetNumberFromWaveNote(wvY, SF_PROPERTY_TABLE) + + return IsNaN(useTable) ? 0 : !!useTable +End + /// @brief Plot the formula using the data from graph /// /// @param graph graph to pass to SF_FormulaExecutor @@ -801,7 +852,8 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode variable winDisplayMode, showLegend, tagCounter, overrideMarker, line, lineGraph, lineGraphFormula variable xMxN, yMxN, xPoints, yPoints, keepUserSelection, numAnnotations, formulasAreDifferent, postPlotPSX variable formulaCounter, gdIndex, markerCode, lineCode, lineStyle, traceToFront, isCategoryAxis, xFormulaOffset - string win, wList, winNameTemplate, exWList, wName, annotation, xAxisLabel, yAxisLabel, wvName, info, xAxis + variable showInTable + string win, winTable, wList, winNameTemplate, exWList, wName, annotation, xAxisLabel, yAxisLabel, wvName, info, xAxis string formulasRemain, moreFormulas, yAndXFormula, xFormula, yFormula, tagText, name, winHook STRUCT SF_PlotMetaData plotMetaData STRUCT RGBColor color @@ -838,8 +890,12 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode formulasRemain = graphCode[j][%GRAPHCODE] lineGraph = str2num(graphCode[j][%LINE]) - win = plotGraphs[j] - wList = AddListItem(win, wList) + win = plotGraphs[j][%GRAPH] + winTable = plotGraphs[j][%TABLE] + if(winDisplayMode == SF_DM_NORMAL) + wList = AddListItem(win, wList) + wList = AddListItem(winTable, wList) + endif Make/FREE=1/T/N=(MINIMUM_WAVE_SIZE) wAnnotations, formulaArgSetup Make/FREE=1/WAVE/N=(MINIMUM_WAVE_SIZE) collPlotFormData @@ -886,6 +942,14 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode WAVE/ZZ previousColorGroups endif WAVE/Z colorGroups = SF_GetColorGroups(formulaResults, previousColorGroups) + showInTable = SF_IsDataForTableDisplay(formulaResults) + if(winDisplaymode == SF_DM_NORMAL) + if(showIntable) + KillWindow/Z $win + else + KillWindow/Z $winTable + endif + endif numData = DimSize(formulaResults, ROWS) for(k = 0; k < numData; k += 1) @@ -924,6 +988,12 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode SFH_ASSERT(!(IsTextWave(wvY) && (WaveExists(wvX) && IsTextWave(wvX))), "One wave needs to be numeric for plotting") + if(showIntable) + AppendToTable/W=$winTable wvY.d + dataCnt += 1 + continue + endif + if(IsTextWave(wvY)) SFH_ASSERT(WaveExists(wvX), "Cannot plot a single text wave") ModifyGraph/W=$win swapXY=1 diff --git a/Packages/MIES/MIES_SweepFormula_Executor.ipf b/Packages/MIES/MIES_SweepFormula_Executor.ipf index ca0583da6f..9f9218a033 100644 --- a/Packages/MIES/MIES_SweepFormula_Executor.ipf +++ b/Packages/MIES/MIES_SweepFormula_Executor.ipf @@ -511,6 +511,9 @@ Function/WAVE SFE_FormulaExecutor(STRUCT SF_ExecutionData &exd, [variable srcLoc case SF_OP_SELECTRANGE: WAVE out = SFOS_OperationSelectRange(exdop) break + case SF_OP_TABLE: + WAVE out = SFO_OperationTable(exdop) + break default: SFH_FATAL_ERROR("Undefined Operation", jsonId = exdop.jsonId) endswitch diff --git a/Packages/MIES/MIES_SweepFormula_Operations.ipf b/Packages/MIES/MIES_SweepFormula_Operations.ipf index 493aff5076..2bdf554cf9 100644 --- a/Packages/MIES/MIES_SweepFormula_Operations.ipf +++ b/Packages/MIES/MIES_SweepFormula_Operations.ipf @@ -2420,3 +2420,18 @@ threadsafe static Function/WAVE SFO_SweepAverageHelper(WAVE/WAVE group) return avgResult[0] End + +Function/WAVE SFO_OperationTable(STRUCT SF_ExecutionData &exd) + + SFH_CheckArgumentCount(exd, SF_OP_TABLE, 1, maxArgs = 1) + + WAVE/WAVE input = SF_ResolveDatasetFromJSON(exd, 0) + + WAVE/WAVE output = SFH_CreateSFRefWave(exd.graph, SF_OP_TABLE, DimSize(input, ROWS)) + + output[] = input[p] + + JWN_SetNumberInWaveNote(output, SF_PROPERTY_TABLE, 1) + + return SFH_GetOutputForExecutor(output, exd.graph, SF_OP_TABLE) +End diff --git a/Packages/MIES/MIES_Utilities_GUI.ipf b/Packages/MIES/MIES_Utilities_GUI.ipf index 9989b0f523..e5fa483952 100644 --- a/Packages/MIES/MIES_Utilities_GUI.ipf +++ b/Packages/MIES/MIES_Utilities_GUI.ipf @@ -661,6 +661,20 @@ Function RemoveTracesFromGraph(string graph, [string trace, WAVE/Z wv, DFREF dfr return NaN End +/// @brief Removes all wave columns from a table +Function RemoveAllColumnsFromTable(string win) + + variable i + + for(i = 0;; i += 1) + WAVE/Z wv = WaveRefIndexed(win, i, 3) + if(!WaveExists(wv)) + break + endif + RemoveFromTable/W=$win wv + endfor +End + /// @brief Add user data "panelVersion" to the panel Function AddVersionToPanel(string win, variable version) diff --git a/Packages/MIES/MIES_WaveDataFolderGetters.ipf b/Packages/MIES/MIES_WaveDataFolderGetters.ipf index 3ae72cf33d..337dc46a05 100644 --- a/Packages/MIES/MIES_WaveDataFolderGetters.ipf +++ b/Packages/MIES/MIES_WaveDataFolderGetters.ipf @@ -9213,3 +9213,13 @@ Function/WAVE GetSFAssertData() return wv End + +/// @brief Used for preparing graph and table window names for the SF plotter +Function/WAVE GetPlotGraphNames(variable numGraphs) + + Make/FREE/T/N=(numGraphs, 2) plotGraphs + SetDimlabel COLS, 0, GRAPH, plotGraphs + SetDimlabel COLS, 1, TABLE, plotGraphs + + return plotGraphs +End