Skip to content

Commit 529c345

Browse files
committed
changes
1 parent 878fb45 commit 529c345

File tree

5 files changed

+185
-52
lines changed

5 files changed

+185
-52
lines changed

Packages/MIES/MIES_Constants.ipf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2525,6 +2525,8 @@ StrConstant SF_OP_TPBASE = "tpbase"
25252525
StrConstant SF_OP_TPFIT = "tpfit"
25262526
///@}
25272527

2528+
StrConstant SF_PROPERTY_TABLE = "Table"
2529+
25282530
/// @name SF operations shorts
25292531
///
25302532
/// @anchor SFOperationsShorts

Packages/MIES/MIES_SweepFormula.ipf

Lines changed: 158 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -544,14 +544,73 @@ static Function/S SF_ShrinkLegend(string annotation)
544544
return shrunkAnnotation
545545
End
546546

547+
static Function SF_ClearPlotPanel(string win)
548+
549+
string subWindow
550+
variable wType
551+
552+
TUD_Clear(win, recursive = 1)
553+
554+
WAVE/T allWindows = ListToTextWave(GetAllWindows(win), ";")
555+
556+
for(subWindow : allWindows)
557+
if(IsSubwindow(subWindow))
558+
// in complex hierarchies we might kill more outer subwindows first
559+
// so the inner ones might later not exist anymore
560+
KillWindow/Z $subWindow
561+
endif
562+
endfor
563+
564+
RemoveAllControls(win)
565+
wType = WinType(win)
566+
if(wType == WINTYPE_PANEL || wType == WINTYPE_GRAPH)
567+
RemoveAllDrawLayers(win)
568+
endif
569+
End
570+
571+
/// @brief Creates a new panel for sweepformula display of graph or table and returns the actual window name
572+
///
573+
/// @param[in] templateName base name of new window
574+
/// @param[in] graph name of sweepbrowser/databrowser window
575+
/// @param[in] winType [optional, default WINTYPE_PANEL] specifies window type
576+
/// @returns name of created window
577+
static Function/S SF_NewSweepFormulaBaseWindow(string templateName, string graph, [variable winType])
578+
579+
string win
580+
581+
winType = ParamIsDefault(winType) ? WINTYPE_PANEL : winType
582+
583+
win = templateName
584+
if(WindowExists(win))
585+
SF_ClearPlotPanel(win)
586+
else
587+
if(winType == WINTYPE_GRAPH)
588+
Display/N=$win/K=1/W=(150, 400, 1000, 700)
589+
elseif(winType == WINTYPE_PANEL)
590+
NewPanel/N=$win/K=1/W=(150, 400, 1000, 700)
591+
elseif(winType == WINTYPE_TABLE)
592+
Edit/N=$win/K=1/W=(150, 400, 1000, 700)
593+
else
594+
FATAL_ERROR("Unsupported window type")
595+
endif
596+
win = S_name
597+
598+
SF_CommonWindowSetup(win, graph)
599+
endif
600+
601+
return win
602+
End
603+
547604
static Function [WAVE/T plotGraphs, WAVE/WAVE infos] SF_PreparePlotter(string winNameTemplate, string graph, variable winDisplayMode, variable numGraphs)
548605

549606
variable i, guidePos, restoreCursorInfo
550-
string panelName, guideName1, guideName2, win
607+
string panelName, guideName1, guideName2, win, winTable, winNameTemplateTable
551608

552609
ASSERT(numGraphs > 0, "Can not prepare plotter window for zero graphs")
553610

554-
Make/FREE/T/N=(numGraphs) plotGraphs
611+
winNameTemplateTable = winNameTemplate + "table"
612+
613+
WAVE/T plotGraphs = GetPlotGraphNames(numGraphs)
555614
Make/FREE/WAVE/N=(numGraphs, 3) infos
556615
SetDimensionLabels(infos, "axes;cursors;annotations", COLS)
557616

@@ -580,41 +639,15 @@ static Function [WAVE/T plotGraphs, WAVE/WAVE infos] SF_PreparePlotter(string wi
580639

581640
if(winDisplayMode == SF_DM_NORMAL)
582641
for(i = 0; i < numGraphs; i += 1)
583-
win = winNameTemplate + num2istr(i)
584-
585-
if(!WindowExists(win))
586-
Display/N=$win/K=1/W=(150, 400, 1000, 700) as win
587-
win = S_name
588-
endif
589-
590-
SF_CommonWindowSetup(win, graph)
591-
592-
plotGraphs[i] = win
642+
win = winNameTemplate + num2istr(i)
643+
plotGraphs[i][%GRAPH] = SF_NewSweepFormulaBaseWindow(win, graph, winType = WINTYPE_GRAPH)
644+
win = winNameTemplateTable + num2istr(i)
645+
plotGraphs[i][%TABLE] = SF_NewSweepFormulaBaseWindow(win, graph, winType = WINTYPE_TABLE)
593646
endfor
594647
elseif(winDisplayMode == SF_DM_SUBWINDOWS)
595648

596-
win = winNameTemplate
597-
if(WindowExists(win))
598-
TUD_Clear(win, recursive = 1)
599-
600-
WAVE/T allWindows = ListToTextWave(GetAllWindows(win), ";")
601-
602-
for(subWindow : allWindows)
603-
if(IsSubwindow(subWindow))
604-
// in complex hierarchies we might kill more outer subwindows first
605-
// so the inner ones might later not exist anymore
606-
KillWindow/Z $subWindow
607-
endif
608-
endfor
609-
610-
RemoveAllControls(win)
611-
RemoveAllDrawLayers(win)
612-
else
613-
NewPanel/N=$win/K=1/W=(150, 400, 1000, 700)
614-
win = S_name
615-
616-
SF_CommonWindowSetup(win, graph)
617-
endif
649+
win = SF_NewSweepFormulaBaseWindow(winNameTemplate, graph)
650+
winTable = SF_NewSweepFormulaBaseWindow(winNameTemplateTable, graph)
618651

619652
// now we have an open panel without any subwindows
620653

@@ -627,23 +660,32 @@ static Function [WAVE/T plotGraphs, WAVE/WAVE infos] SF_PreparePlotter(string wi
627660
guideName1 = SF_PLOTTER_GUIDENAME + num2istr(i)
628661
guidePos = i / numGraphs
629662
DefineGuide/W=$win $guideName1={FT, guidePos, FB}
663+
DefineGuide/W=$winTable $guideName1={FT, guidePos, FB}
630664
endfor
631665

632666
DefineGuide/W=$win customLeft={FL, 0.0, FR}
633667
DefineGuide/W=$win customRight={FL, 1.0, FR}
668+
DefineGuide/W=$winTable customLeft={FL, 0.0, FR}
669+
DefineGuide/W=$winTable customRight={FL, 1.0, FR}
634670

635671
// and now the subwindow graphs
636672
for(i = 0; i < numGraphs; i += 1)
637673
guideName1 = SF_PLOTTER_GUIDENAME + num2istr(i)
638674
guideName2 = SF_PLOTTER_GUIDENAME + num2istr(i + 1)
639675
Display/HOST=$win/FG=(customLeft, $guideName1, customRight, $guideName2)/N=$("Graph" + num2str(i))
640-
plotGraphs[i] = winNameTemplate + "#" + S_name
676+
plotGraphs[i][%GRAPH] = win + "#" + S_name
677+
Edit/HOST=$winTable/FG=(customLeft, $guideName1, customRight, $guideName2)/N=$("Table" + num2str(i))
678+
plotGraphs[i][%TABLE] = winTable + "#" + S_name
641679
endfor
642680
endif
643681

644-
for(win : plotGraphs)
682+
for(i = 0; i < numGraphs; i += 1)
683+
win = plotGraphs[i][%GRAPH]
645684
RemoveTracesFromGraph(win)
646685
ModifyGraph/W=$win swapXY=0
686+
687+
win = plotGraphs[i][%TABLE]
688+
RemoveAllColumnsFromTable(win)
647689
endfor
648690

649691
return [plotGraphs, infos]
@@ -740,16 +782,55 @@ static Function SF_CheckNumTraces(string graph, variable numTraces)
740782
endif
741783
End
742784

743-
static Function SF_CleanUpPlotWindowsOnFail(WAVE/T plotGraphs)
785+
static Function SF_KillEmptyDataWindows(WAVE/T plotGraphs)
744786

745787
for(str : plotGraphs)
746-
WAVE/Z wv = WaveRefIndexed(str, 0, 1)
747-
if(!WaveExists(wv))
748-
KillWindow/Z $str
788+
if(WindowExists(str))
789+
WAVE/Z wv = WaveRefIndexed(str, 0, 1)
790+
if(!WaveExists(wv))
791+
KillWindow/Z $str
792+
endif
749793
endif
750794
endfor
751795
End
752796

797+
/// @brief Tiles the subwindows in the panels acording to existing data, requires SF_DM_SUBWINDOWS mode
798+
static Function SF_TileExistingData(WAVE/T plotGraphs)
799+
800+
variable numSubWins, numData, guidePos, i, j, col, numCols
801+
string guideName1, guideName2, win
802+
803+
numCols = DimSize(plotGraphs, COLS)
804+
for(col = 0; col < numCols; col += 1)
805+
win = plotGraphs[0][col]
806+
win = RemoveEnding(win, "#" + StringFromList(ItemsInList(win, "#") - 1, win, "#"))
807+
808+
numSubWins = DimSize(plotGraphs, ROWS)
809+
Make/FREE/N=(numSubWins) hasData
810+
hasData[] = WaveExists(WaveRefIndexed(plotGraphs[p][col], 0, 1))
811+
812+
WAVE/Z idx = FindIndizes(hasData, var = 1)
813+
if(!WaveExists(idx))
814+
KillWindow/Z $win
815+
return NaN
816+
endif
817+
818+
numData = DimSize(idx, ROWS)
819+
j = 0
820+
for(i : idx)
821+
guideName1 = SF_PLOTTER_GUIDENAME + num2istr(i)
822+
guidePos = j / numData
823+
DefineGuide/W=$win $guideName1={FT, guidePos, FB}
824+
825+
guideName2 = SF_PLOTTER_GUIDENAME + num2istr(i + 1)
826+
guidePos = (j + 1) / numData
827+
DefineGuide/W=$win $guideName2={FT, guidePos, FB}
828+
829+
j += 1
830+
endfor
831+
endfor
832+
End
833+
753834
static Function SF_KillWorkingDF(string graph)
754835

755836
DFREF dfrWork = SFH_GetWorkingDF(graph)
@@ -788,6 +869,15 @@ static Function/WAVE SF_PrepareResultWaveForPlotting(DFREF dfr, WAVE wvResult, v
788869
return plotWave
789870
End
790871

872+
static Function SF_IsDataForTableDisplay(WAVE wvY)
873+
874+
variable useTable
875+
876+
useTable = JWN_GetNumberFromWaveNote(wvY, SF_PROPERTY_TABLE)
877+
878+
return IsNaN(useTable) ? 0 : !!useTable
879+
End
880+
791881
/// @brief Plot the formula using the data from graph
792882
///
793883
/// @param graph graph to pass to SF_FormulaExecutor
@@ -801,7 +891,8 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
801891
variable winDisplayMode, showLegend, tagCounter, overrideMarker, line, lineGraph, lineGraphFormula
802892
variable xMxN, yMxN, xPoints, yPoints, keepUserSelection, numAnnotations, formulasAreDifferent, postPlotPSX
803893
variable formulaCounter, gdIndex, markerCode, lineCode, lineStyle, traceToFront, isCategoryAxis, xFormulaOffset
804-
string win, wList, winNameTemplate, exWList, wName, annotation, xAxisLabel, yAxisLabel, wvName, info, xAxis
894+
variable showInTable
895+
string win, winTable, wList, winNameTemplate, exWList, wName, annotation, xAxisLabel, yAxisLabel, wvName, info, xAxis
805896
string formulasRemain, moreFormulas, yAndXFormula, xFormula, yFormula, tagText, name, winHook
806897
STRUCT SF_PlotMetaData plotMetaData
807898
STRUCT RGBColor color
@@ -838,8 +929,12 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
838929
formulasRemain = graphCode[j][%GRAPHCODE]
839930
lineGraph = str2num(graphCode[j][%LINE])
840931

841-
win = plotGraphs[j]
842-
wList = AddListItem(win, wList)
932+
win = plotGraphs[j][%GRAPH]
933+
winTable = plotGraphs[j][%TABLE]
934+
if(winDisplayMode == SF_DM_NORMAL)
935+
wList = AddListItem(win, wList)
936+
wList = AddListItem(winTable, wList)
937+
endif
843938

844939
Make/FREE=1/T/N=(MINIMUM_WAVE_SIZE) wAnnotations, formulaArgSetup
845940
Make/FREE=1/WAVE/N=(MINIMUM_WAVE_SIZE) collPlotFormData
@@ -865,7 +960,7 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
865960
try
866961
[formulaResults, plotMetaData] = SF_GatherFormulaResults(xFormula, yFormula, graph, line, xFormulaOffset)
867962
catch
868-
SF_CleanUpPlotWindowsOnFail(plotGraphs)
963+
SF_KillEmptyDataWindows(plotGraphs)
869964
Abort
870965
endtry
871966

@@ -886,6 +981,14 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
886981
WAVE/ZZ previousColorGroups
887982
endif
888983
WAVE/Z colorGroups = SF_GetColorGroups(formulaResults, previousColorGroups)
984+
showInTable = SF_IsDataForTableDisplay(formulaResults)
985+
if(winDisplaymode == SF_DM_NORMAL)
986+
if(showIntable)
987+
KillWindow/Z $win
988+
else
989+
KillWindow/Z $winTable
990+
endif
991+
endif
889992

890993
numData = DimSize(formulaResults, ROWS)
891994
for(k = 0; k < numData; k += 1)
@@ -924,6 +1027,12 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
9241027

9251028
SFH_ASSERT(!(IsTextWave(wvY) && (WaveExists(wvX) && IsTextWave(wvX))), "One wave needs to be numeric for plotting")
9261029

1030+
if(showIntable)
1031+
AppendToTable/W=$winTable wvY.d
1032+
dataCnt += 1
1033+
continue
1034+
endif
1035+
9271036
if(IsTextWave(wvY))
9281037
SFH_ASSERT(WaveExists(wvX), "Cannot plot a single text wave")
9291038
ModifyGraph/W=$win swapXY=1
@@ -932,13 +1041,6 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
9321041
WAVE wvX = dummy
9331042
endif
9341043

935-
variable useTable = !!JWN_GetNumberFromWaveNote(wvY, "Table")
936-
937-
if(useTable)
938-
Edit/HOST=$win/FG=(FL, FT, FR, FB) wvY.d
939-
continue
940-
endif
941-
9421044
if(!WaveExists(wvX))
9431045
numTraces = yMxN
9441046
SF_CheckNumTraces(graph, numTraces)
@@ -1252,6 +1354,11 @@ static Function SF_FormulaPlotter(string graph, string formula, [variable dmMode
12521354
endif
12531355
endfor
12541356

1357+
if(winDisplayMode == SF_DM_SUBWINDOWS)
1358+
SF_TileExistingData(plotGraphs)
1359+
endif
1360+
SF_KillEmptyDataWindows(plotGraphs)
1361+
12551362
if(winDisplayMode == SF_DM_NORMAL)
12561363
exWList = WinList(winNameTemplate + "*", ";", "WIN:1")
12571364
numWins = ItemsInList(exWList)

Packages/MIES/MIES_SweepFormula_Operations.ipf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,7 @@ Function/WAVE SFO_OperationTable(STRUCT SF_ExecutionData &exd)
24312431

24322432
output[] = input[p]
24332433

2434-
JWN_SetNumberInWaveNote(input, "Table", 1)
2434+
JWN_SetNumberInWaveNote(output, SF_PROPERTY_TABLE, 1)
24352435

24362436
return SFH_GetOutputForExecutor(output, exd.graph, SF_OP_TABLE)
24372437
End

Packages/MIES/MIES_Utilities_GUI.ipf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,20 @@ Function RemoveTracesFromGraph(string graph, [string trace, WAVE/Z wv, DFREF dfr
661661
return NaN
662662
End
663663

664+
/// @brief Removes all wave columns from a table
665+
Function RemoveAllColumnsFromTable(string win)
666+
667+
variable i
668+
669+
for(i = 0;; i += 1)
670+
WAVE/Z wv = WaveRefIndexed(win, i, 3)
671+
if(!WaveExists(wv))
672+
break
673+
endif
674+
RemoveFromTable/W=$win wv
675+
endfor
676+
End
677+
664678
/// @brief Add user data "panelVersion" to the panel
665679
Function AddVersionToPanel(string win, variable version)
666680

Packages/MIES/MIES_WaveDataFolderGetters.ipf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9213,3 +9213,13 @@ Function/WAVE GetSFAssertData()
92139213

92149214
return wv
92159215
End
9216+
9217+
/// @brief Used for preparing graph and table window names for the SF plotter
9218+
Function/WAVE GetPlotGraphNames(variable numGraphs)
9219+
9220+
Make/FREE/T/N=(numGraphs, 2) plotGraphs
9221+
SetDimlabel COLS, 0, GRAPH, plotGraphs
9222+
SetDimlabel COLS, 1, TABLE, plotGraphs
9223+
9224+
return plotGraphs
9225+
End

0 commit comments

Comments
 (0)