updates: scaling of pshell data, matrix preview, elog panel

- elog panel supports multiple attachments
- matrix (omicron STM) data file preview in data explorer
- various improvements for the scaling of pshell data
This commit is contained in:
2017-02-02 15:31:13 +01:00
parent c8a69460bc
commit 9a65d26984
5 changed files with 1680 additions and 171 deletions

View File

@@ -1,5 +1,5 @@
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
#pragma version = 1.31
#pragma version = 1.40
#pragma IgorVersion = 6.2
#pragma ModuleName = PearlElog
@@ -16,13 +16,38 @@
/// @ingroup ArpesPackage
///
///
/// the functions in this module support the following work flows:
/// 1. send a preview of a selected measurement to ELOG.
/// 2. send any Igor graph to ELOG. (CLI and GUI)
/// 3. direct access to all ELOG parameters. (CLI only)
/// the functions in this module support the following ELOG features:
/// - submit new entries and replies to existing entries.
/// - text field, list box, and check box attributes.
/// - attach any Igor graph to ELOG.
/// - configurable logbook templates for logbooks that share the same configuration.
/// - common server configurations available on the ELOG command line
/// (hostname, port, SSL, username, password, sub-directory).
/// - not specific to the configuration at PEARL.
/// PEARL code is concentrated in the elog_init_pearl_templates() function.
/// - the configuration of the ELOG server and logbooks
/// as well as the most recently used attributes are persisted in the preference file.
///
/// the configuration of the ELOG server and logbooks (except user name and password)
/// as well as the most recently used attributes are persisted in the preference file.
/// usage:
/// 1. the administrator of the ELOG server creates logbook templates
/// according to the configuration of the logbooks.
/// the templates are written in Igor code.
/// 2. the user opens logbooks via the _Open ELOG panel_ menu item.
/// before first use, select a template and enter a name for the logbook.
/// the new logbook is written to the preference file,
/// and can afterwards be opened directly.
/// 3. if the server requires a user name and password,
/// click the login button.
/// 4. edit the message, attributes and attachments as necessary, and submit to ELOG.
/// 5. log out before saving the experiment to clear the password.
///
/// @attention the user name and password are stored in the global data tree of an experiment.
/// it is not possible to handle passwords safely in Igor.
/// they can be read by anyone having access to an open Igor experiment or a saved experiment file
/// (unless the password is reset before saving).
/// therefore:
/// - use a password for the ELOG server which is different from your other passwords.
/// - clear the password (logout button in the panel) before saving an experiment.
///
/// elog command line
///@verbatim
@@ -43,12 +68,6 @@
/// -m <textfile>] | <text>
///@endverbatim
///
/// user name and password are used if configured in the package data folder.
/// there is currently no separate user interface.
///
/// @attention some functions in this module refer specifically to the ELOG configuration at PEARL.
///
/// @todo ask for logbook, username and password before opening the panel.
///
/// @author matthias muntwiler, matthias.muntwiler@psi.ch
///
@@ -82,7 +101,7 @@ function pearl_elog(logbook)
load_prefs()
string templates = list_logbooks(templates=1)
if (ItemsInList(templates) < 1)
init_pearl_templates()
elog_init_pearl_templates()
endif
endif
@@ -95,7 +114,11 @@ function pearl_elog(logbook)
if (strlen(WinList(win_name, ";", "")) > 0)
DoWindow /F $win_name
else
PearlElogPanel(logbook)
win_name = PearlElogPanel(logbook)
STRUCT WMWinHookStruct s
s.eventCode = 0
s.winName = win_name
elog_panel_hook(s)
endif
endif
end
@@ -104,6 +127,7 @@ end
static function IgorBeforeNewHook(igorApplicationNameStr)
string igorApplicationNameStr
save_prefs()
cleanup_temp_files()
return 0
end
@@ -111,6 +135,7 @@ end
static function IgorQuitHook(igorApplicationNameStr)
string igorApplicationNameStr
save_prefs()
cleanup_temp_files()
return 0
end
@@ -234,7 +259,7 @@ end
///
/// @remark this function is specific to the setup at PEARL.
///
static function init_pearl_templates()
function elog_init_pearl_templates()
dfref savedf = getdatafolderdfr()
dfref df_root = get_elog_df("", kdfRoot)
@@ -247,10 +272,10 @@ static function init_pearl_templates()
// attributes (persistent)
// available attributes
string /g attributes = "author;project;sample;source;task;technique;valid;file"
string /g attributes = "author;project;sample;source;task;technique;file;valid;"
// controls corresponding to attributes
// prefix determines the control type: sv_ = setvariable (string), pm_ = popup menu, cb = check box
string /g controls = "sv_author;sv_project;sv_sample;pm_source;pm_task;pm_technique;cb_valid;sv_file"
string /g controls = "sv_author;sv_project;sv_sample;pm_source;pm_task;pm_technique;sv_file;cb_valid;"
// attributes with fixed options, value item declares the options string
string /g options = "source=sources;task=tasks;technique=techniques"
// attributes which must be defined
@@ -258,8 +283,8 @@ static function init_pearl_templates()
// option lists
string /g sources = "Manual Entry;PShell;Scienta Data;SScan Data;Prosilica Data;OTF Data;Beamline Status;LEED Data;QMS Data;Matrix Data;Igor Pro;Other"
string /g tasks = "Measurement;Sample Preparation;Sample Storage;Optimization;Analysis;Development;Maintenance;Test;Comment;Other"
string /g techniques = "XPS;UPS;XPD;XAS;XMCD;PhD;ARUPS;LEED;AES;STM;STS;QMS;MBE;Test;Other"
string /g tasks = "Measurement;Optimization;Analysis;Sample Preparation;Sample Storage;Comment;Development;Maintenance;Test;Other"
string /g techniques = "XPS;UPS;XPD;XAS;XMCD;PhD;ARUPS;STM;STS;LEED;AES;QMS;MBE;Sputter/Anneal;Test;Other"
// Calculations template
setdatafolder df_templates
@@ -267,18 +292,38 @@ static function init_pearl_templates()
// attributes (persistent)
// available attributes
string /g attributes = "author;project;sample;program;revision;machine;job;source path;result path;valid"
string /g attributes = "author;project;sample;program;revision;machine;job;experiment;source path;result path;valid"
// controls corresponding to attributes
// prefix determines the control type: sv_ = setvariable (string), pm_ = popup menu, cb = check box
string /g controls = "sv_author;sv_project;sv_sample;pm_program;sv_revision;pm_machine;sv_job;sv_sourcepath;sv_resultpath;cb_valid"
string /g controls = "sv_author;sv_project;sv_sample;pm_program;sv_revision;pm_machine;sv_job;sv_experiment;sv_sourcepath;sv_resultpath;cb_valid"
// attributes with fixed options, value item declares the options string
string /g options = "program=programs;machine=machines"
// attributes which must be defined
string /g required_attributes = "author;project;sample"
// option lists
string /g programs = "DMSUP;EDAC;MSC;MUFPOT;SSC"
string /g machines = "llcx;Merlin;PC"
string /g programs = "PMSCO;EDAC;MSC;SSC;MUFPOT;DMSUP;Other"
string /g machines = "PC;VM;Ra;Merlin;llcx;Other"
// System template
setdatafolder df_templates
newdatafolder /o/s System
// attributes (persistent)
// available attributes
string /g attributes = "author;type;system;source;file"
// controls corresponding to attributes
// prefix determines the control type: sv_ = setvariable (string), pm_ = popup menu, cb = check box
string /g controls = "sv_author;pm_type;pm_system;pm_source;sv_file"
// attributes with fixed options, value item declares the options string
string /g options = "type=types;system=systems;source=sources"
// attributes which must be defined
string /g required_attributes = "author;type;system"
// option lists
string /g types = "Installation;Repair;Maintenance;Test;Commissioning;Bakeout;Incident;Cool-down;Warm-up;Storage;Other"
string /g systems = "Vacuum;Control System;BL;XA;XP;SA;SP;T;LL;Monochromator;Carving;Scienta;STM;PC-Scienta;PC-Matrix;PC-Console;PC-Console-Win;PC-XP;EPS;LAC;Desiccator"
string /g sources = "Manual Entry;PShell;Scienta Data;SScan Data;Prosilica Data;OTF Data;Beamline Status;LEED Data;QMS Data;Matrix Data;Igor Pro;Other"
setdatafolder savedf
return 0
@@ -303,6 +348,11 @@ static function init_volatile_vars()
variable nlb = ItemsInList(logbooks)
variable ilb
SetDataFolder df_volatile_root
if (exists("temp_graph_files") != 2)
string /g temp_graph_files = ""
endif
for (ilb = 0; ilb < nlb; ilb += 1)
logbook = StringFromList(ilb, logbooks)
@@ -322,6 +372,13 @@ static function init_volatile_vars()
if (exists("msg_id") != 2)
variable /g msg_id = 0
endif
if (exists("att_list") != 1)
make /n=(0,3) /t /o attach_list
make /n=(0,3) /i /o attach_sel
endif
if (exists("url") != 2)
string /g url = ""
endif
endfor
SetDataFolder savedf
@@ -347,6 +404,9 @@ end
/// create a new empty logbook or duplicate from a template.
///
/// @param name name of the new logbook.
/// if the logbook exists, the existing logbook folder is killed
/// and replaced by a new one.
/// this may fail if a window is still open.
///
/// @param template name of the template.
/// if empty string, a new empty logbook is created.
@@ -368,6 +428,10 @@ function elog_create_logbook(name, [template])
if (strlen(template) > 0)
dfref df_template = get_elog_df(template, kdfTemplates)
dfref df_existing = get_elog_df(name, kdfPersistent)
if (DataFolderRefStatus(df_existing))
KillDataFolder /Z df_existing
endif
DuplicateDataFolder df_template, df_persistent_parent:$name
else
NewDataFolder /o/s df_persistent_parent:$name
@@ -695,7 +759,6 @@ function elog_create_entry(logbook, attributes, message, [encoding, graphs, repl
endif
result = -4
endif
cleanup_temp_files()
else
if (loglevel >= 2)
print "ELOG: failed to create temporary message file."
@@ -759,7 +822,6 @@ function elog_add_attachment(logbook, id, graphs)
endif
result = -4 // error: elog returned error
endif
cleanup_temp_files()
endif
setdatafolder savedf
@@ -817,6 +879,39 @@ static function /s prepare_command_line(logbook)
return cmd
end
/// format the URL for display to the user
///
///
/// @param logbook name of the target logbook
///
static function /s format_url(logbook)
string logbook
dfref df_general = get_elog_df("", kdfPersistent)
svar /sdfr=df_general hostname
nvar /sdfr=df_general port
nvar /sdfr=df_general ssl
svar /sdfr=df_general subdir
string cmd = ""
if ((nvar_exists(ssl)) && (ssl != 0))
cmd += "https://"
else
cmd += "http://"
endif
cmd += hostname
if ((nvar_exists(port)) && (port > 0))
cmd += ":" + num2str(port)
endif
if ((svar_exists(subdir)) && (strlen(subdir) > 0))
cmd += "/" + subdir
endif
cmd += "/" + logbook
return cmd
end
/// prepare screenshots of graph windows for attachments
///
/// prepares the attachment files from Igor graph windows
@@ -875,13 +970,18 @@ static function /s create_graph_file(graphname, fileindex)
string graphname
variable fileindex
dfref df_volatile_root = get_elog_df("", kdfVolatile)
svar /sdfr=df_volatile_root temp_graph_files
string path = SpecialDirPath("Temporary", 0, 1, 0)
string ts = get_timestamp("_")
variable len = strlen(path)
if (numtype(len) == 0)
path += "elog_" + ts + "_" + num2str(fileindex) + ".png"
SavePICT /B=72 /E=-5 /M /O /W=(0,0,8,6) /WIN=$graphname /Z as path
if (v_flag != 0)
if (v_flag == 0)
temp_graph_files = AddListItem(path, temp_graph_files, ";", inf)
else
path = ""
endif
else
@@ -921,12 +1021,30 @@ static function /s get_log_path()
return path
end
static function /s cleanup_temp_files()
string path = SpecialDirPath("Temporary", 0, 1, 0)
string cmd
sprintf cmd, "del \"%s\elog*.*\"", path
//ExecuteScriptText cmd
return path
/// delete temporary files created by the ELOG module.
///
/// this deletes all temporary graph files that are referenced by the volatile temp_graph_files list.
/// temp_graph_files is a semicolon-delimited string.
/// items are added by create_graph_file().
///
/// this function should be called before a new experiment is loaded or igor quits.
///
static function cleanup_temp_files()
dfref df_volatile_root = get_elog_df("", kdfVolatile)
if (DataFolderRefStatus(df_volatile_root))
svar /sdfr=df_volatile_root /z temp_graph_files
if (SVAR_Exists(temp_graph_files))
variable nfi = ItemsInList(temp_graph_files)
variable ifi
string sfi
for (ifi = 0; ifi < nfi; ifi += 1)
sfi = StringFromList(ifi, temp_graph_files)
DeleteFile /Z sfi
endfor
temp_graph_files = ""
endif
endif
return 0
end
static strconstant elog_success_msg = "Message successfully transmitted"
@@ -1048,14 +1166,17 @@ function /s PearlElogPanel(logbook)
string win_name = logbook + "ElogPanel"
string win_title = "ELOG " + logbook
NewPanel /K=1 /N=$win_name /W=(600,200,926,494) as win_title
NewPanel /K=1 /N=$win_name /W=(600,200,1200,700) as win_title
win_name = s_name
ModifyPanel /w=$win_name cbRGB=(52224,52224,65280)
svar /sdfr=df_persistent attributes
svar /sdfr=df_persistent controls
svar /sdfr=df_persistent options
wave /t /sdfr=df_volatile attach_list
wave /sdfr=df_volatile attach_sel
svar /sdfr=df_volatile url
variable iattr
variable nattr = ItemsInList(attributes, ";")
string s_attr
@@ -1066,35 +1187,28 @@ function /s PearlElogPanel(logbook)
string options_path
string variable_path
variable ypos = 2
variable height = 0
Button b_login,win=$win_name, pos={264,ypos},size={46,20},proc=PearlElog#bp_login,title="Login"
Button b_login,win=$win_name, help={"Enter user name and password."}
Button b_login,win=$win_name, fcolor=(56576,60928,47872)
Button b_logout,win=$win_name, pos={264,ypos},size={46,20},proc=PearlElog#bp_logout,title="Logout"
Button b_logout,win=$win_name, help={"Clear user name and password."}
Button b_logout,win=$win_name, fcolor=(56576,60928,47872), disable=3
for (iattr = 0; iattr < nattr; iattr += 1)
s_attr = StringFromList(iattr, attributes, ";")
s_control = StringFromList(iattr, controls, ";")
strswitch(s_control[0,1])
case "sv":
SetVariable $s_control, win=$win_name, pos={0,ypos}, size={260,16}, bodyWidth=200
SetVariable $s_control, win=$win_name, pos={0,ypos}, size={300,16}, bodyWidth=230
SetVariable $s_control, win=$win_name, title=s_attr, value= _STR:""
SetVariable $s_control, win=$win_name, userdata(attribute)=s_attr
ypos += 18
break
case "pm":
options_path = persistent_path + StringByKey(s_attr, options, "=", ";")
PopupMenu $s_control, win=$win_name, pos={0,ypos}, size={260,21}, bodyWidth=200
PopupMenu $s_control, win=$win_name, pos={0,ypos}, size={300,21}, bodyWidth=230
PopupMenu $s_control, win=$win_name, title=s_attr
PopupMenu $s_control, win=$win_name, mode=1, popvalue="Test", value= #options_path
PopupMenu $s_control, win=$win_name, userdata(attribute)=s_attr
ypos += 23
break
case "cb":
CheckBox $s_control, win=$win_name, pos={60,ypos}, size={260,14}
CheckBox $s_control, win=$win_name, pos={70,ypos}, size={300,14}
CheckBox $s_control, win=$win_name, title=s_attr, value= 1
CheckBox $s_control, win=$win_name, userdata(attribute)=s_attr
ypos += 17
@@ -1102,48 +1216,81 @@ function /s PearlElogPanel(logbook)
endswitch
endfor
PopupMenu pm_attach,win=$win_name, pos={0,ypos},size={260,21},bodyWidth=200,title="Attachment"
PopupMenu pm_attach,win=$win_name, mode=1,popvalue="(none)",value=PearlElog#pm_list_attach_items()
PopupMenu pm_attach,win=$win_name, help={"Choose any visible Igor graph for attachment."}
Button b_select_attach_top,win=$win_name, pos={264,ypos},size={60,20},proc=PearlElog#bp_select_attach_top,title="Top Graph"
Button b_select_attach_top,win=$win_name, help={"Select top graph window."}
Button b_select_attach_top,win=$win_name, fcolor=(56576,60928,47872)
TitleBox t_attach, win=$win_name, pos={308,5}, size={70,14}, title="Attachments", frame=0
height = ypos - 21 - 4
ListBox lb_attach, win=$win_name, pos={308,21}, size={264,height}
ListBox lb_attach, win=$win_name, listWave=attach_list
ListBox lb_attach, win=$win_name, mode=1, selWave=attach_sel, selRow=-1
ListBox lb_attach, win=$win_name, widths={20,160,80}
ListBox lb_attach, win=$win_name, help={"Choose graphs to attach to the message."}
Button b_attach_top, win=$win_name, pos={420,2}, size={40,18}, title="top"
Button b_attach_top, win=$win_name, fcolor=(56576,60928,47872)
Button b_attach_top, win=$win_name, proc=PearlElog#bp_attach_top
Button b_attach_top, win=$win_name, help={"Select top graph for attachment."}
Button b_attach_all, win=$win_name, pos={460,2}, size={40,18}, title="all"
Button b_attach_all, win=$win_name, fcolor=(56576,60928,47872)
Button b_attach_all, win=$win_name, proc=PearlElog#bp_attach_allnone
Button b_attach_all, win=$win_name, help={"Select all graphs for attachment."}
Button b_attach_none, win=$win_name, pos={500,2}, size={40,18}, title="none"
Button b_attach_none, win=$win_name, fcolor=(56576,60928,47872)
Button b_attach_none, win=$win_name, proc=PearlElog#bp_attach_allnone
Button b_attach_none, win=$win_name, help={"Deselect all attachments."}
Button b_save_graphs, win=$win_name, pos={540,2}, size={40,18}, title="save"
Button b_save_graphs, win=$win_name, fcolor=(56576,60928,47872)
Button b_save_graphs, win=$win_name, proc=PearlElog#bp_save_graphs
Button b_save_graphs, win=$win_name, help={"Save selected graphs as PNG bitmap files."}
Button b_attach_up, win=$win_name, pos={576,20}, size={20,20}, title="\\W517"
Button b_attach_up, win=$win_name, fcolor=(56576,60928,47872)
Button b_attach_up, win=$win_name, proc=PearlElog#bp_attach_updown
Button b_attach_up, win=$win_name, help={"Move selected graph up."}
Button b_attach_dw, win=$win_name, pos={576,40}, size={20,20}, title="\\W523"
Button b_attach_dw, win=$win_name, fcolor=(56576,60928,47872)
Button b_attach_dw, win=$win_name, proc=PearlElog#bp_attach_updown
Button b_attach_dw, win=$win_name, help={"Move selected graph down."}
ypos += 246-160
Button b_submit,win=$win_name, pos={60,ypos},size={46,20},proc=PearlElog#bp_submit,title="Submit"
Button b_submit,win=$win_name, pos={70,ypos},size={46,20},proc=PearlElog#bp_submit,title="Submit"
Button b_submit,win=$win_name, help={"Submit form data to ELOG (new entry)."}
Button b_submit,win=$win_name, fcolor=(56576,60928,47872)
Button b_clear,win=$win_name, pos={110,ypos},size={46,20},proc=PearlElog#bp_clear,title="Clear"
Button b_clear,win=$win_name, pos={120,ypos},size={46,20},proc=PearlElog#bp_clear,title="Clear"
Button b_clear,win=$win_name, help={"Clear the form fields"}
Button b_clear,win=$win_name, fcolor=(56576,60928,47872)
ypos += 272-246
variable_path = volatile_path + "msg_id"
SetVariable sv_id,win=$win_name, pos={46,ypos},size={109,16},bodyWidth=94
SetVariable sv_id,win=$win_name, pos={51,ypos},size={119,16},bodyWidth=77
SetVariable sv_id,win=$win_name, title="ID",value=$variable_path
SetVariable sv_id,win=$win_name, help={"ID of last submitted message, or message to attach or reply to."}
TitleBox t_host, win=$win_name, pos={170,ypos+4}, size={112.00,14.00}, frame=0
TitleBox t_host, win=$win_name, variable=url
ypos += 270-272
Button b_attach,win=$win_name, pos={160,ypos},size={48,20},proc=PearlElog#bp_attach,title="Attach"
Button b_attach,win=$win_name, pos={170,ypos},size={48,20},proc=PearlElog#bp_attach,title="Attach"
Button b_attach,win=$win_name, help={"Attach the selected graph to an existing ELOG entry (correct ID required)."}
Button b_attach,win=$win_name, fcolor=(56576,60928,47872)
Button b_reply,win=$win_name, pos={210,ypos},size={48,20},proc=PearlElog#bp_submit,title="Reply"
Button b_reply,win=$win_name, pos={220,ypos},size={48,20},proc=PearlElog#bp_submit,title="Reply"
Button b_reply,win=$win_name, help={"Submit form data to ELOG as a reply to an existing message (correct ID required)."}
Button b_reply,win=$win_name, fcolor=(56576,60928,47872)
ypos += 184-270
TitleBox t_message,win=$win_name, pos={0,ypos},size={58,16},fixedSize=1,frame=0,anchor=RT,title="Message"
Button b_login,win=$win_name, pos={550,ypos},size={46,20},proc=PearlElog#bp_login,title="Login"
Button b_login,win=$win_name, help={"Enter user name and password."}
Button b_login,win=$win_name, fcolor=(56576,60928,47872)
Button b_logout,win=$win_name, pos={550,ypos},size={46,20},proc=PearlElog#bp_logout,title="Logout"
Button b_logout,win=$win_name, help={"Clear user name and password."}
Button b_logout,win=$win_name, fcolor=(56576,60928,47872), disable=3
SetWindow $win_name, hook(elogPanelHook)=PearlElog#elog_panel_hook
SetWindow $win_name, userdata(logbook)=logbook
DefineGuide UGH0={FT,ypos},UGV0={FL,60},UGH1={FB,-52},UGV1={FR,-2}
ypos += 160-270
TitleBox t_message,win=$win_name, pos={10,ypos},size={58,16},fixedSize=1,frame=0,anchor=RT,title="Message"
DefineGuide UGH0={FT,ypos},UGV0={FL,70},UGH1={FB,-52},UGV1={FR,-2}
NewNotebook /F=0 /N=Message /OPTS=3 /W=(115,404,345,341)/FG=(UGV0,UGH0,UGV1,UGH1) /HOST=#
Notebook kwTopWin, defaultTab=20, statusWidth=0, autoSave=0
Notebook kwTopWin font="Arial", fSize=10, fStyle=0, textRGB=(0,0,0)
Notebook kwTopWin fSize=10, fStyle=0, textRGB=(0,0,0)
RenameWindow #,Message
string nb_name = win_name + "#Message"
SetActiveSubwindow ##
// restore recently used attributes and message
@@ -1155,6 +1302,7 @@ function /s PearlElogPanel(logbook)
if (svar_exists(recent_message) && (strlen(recent_message) > 0))
set_panel_message(win_name, recent_message)
endif
Notebook $nb_name selection={startOfFile,startOfFile}, findText={"",1}
setdatafolder savedf
return win_name
@@ -1166,49 +1314,152 @@ static function elog_panel_hook(s)
Variable hookResult = 0
switch(s.eventCode)
case 0: // activate
string logbook = GetUserData(s.winName, "", "logbook")
if (strlen(logbook) > 0)
dfref df_volatile = get_elog_df(logbook, kdfVolatile)
svar /sdfr=df_volatile url
url = format_url(logbook)
update_attach_items(logbook)
endif
break
case 6: // resize
// move bottom-aligned controls when the window is resized
variable b_top = s.winRect.bottom + 4
Button b_submit,pos={60,b_top}
Button b_clear,pos={110,b_top}
Button b_submit,pos={70,b_top}
Button b_clear,pos={120,b_top}
TitleBox t_host, pos={170,b_top+4}
b_top += 24
Button b_attach,pos={160,b_top}
Button b_reply,pos={210,b_top}
Button b_attach,pos={170,b_top}
Button b_reply,pos={220,b_top}
Button b_login, pos={550,b_top}
Button b_logout, pos={550,b_top}
b_top += 2
SetVariable sv_id,pos={46,b_top}
SetVariable sv_id,pos={51,b_top}
break
endswitch
return hookResult // 0 if nothing done, else 1
end
/// get a list of graph windows for a popup menu.
static function /s pm_list_attach_items()
static constant kAttachColSel = 0
static constant kAttachColTitle = 1
static constant kAttachColName = 2
// get graph names
/// update the list of attachments
static function update_attach_items(logbook)
string logbook
dfref savedf = getdatafolderdfr()
dfref df_volatile = get_elog_df(logbook, kdfVolatile)
wave /t /sdfr=df_volatile attach_list
wave /sdfr=df_volatile attach_sel
if (!waveexists(attach_list))
return -1
endif
string names = WinList("*", ";", "WIN:1;VISIBLE:1")
names = SortList(names, ";", 16)
// get corresponding graph titles
variable nnames = ItemsInList(names, ";")
variable iname
string name
string item
string items = ""
// format each entry like "name: title"
for (iname = 0; iname < nnames; iname += 1)
name = StringFromList(iname, names, ";")
getwindow /z $name, wtitle
if (v_flag == 0)
item = ReplaceString(";", s_value, ", ") // title
item = item + " (" + name + ")"
items = AddListItem(item, items, ";", inf)
// remove closed graphs
variable i
variable k
variable n = DimSize(attach_list, 0)
string s
for (i = n-1; i >= 0; i -= 1)
s = attach_list[i][kAttachColName]
if (WhichListItem(s, names) < 0)
DeletePoints /M=0 i, 1, attach_list, attach_sel
endif
endfor
items = AddListItem("(none)", items, ";")
return items
// add new graphs
n = ItemsInList(names)
for (i = 0; i < n; i += 1)
s = StringFromList(i, names)
FindValue /text=s /txop=4 /z attach_list
if (v_value < 0)
k = DimSize(attach_list, 0)
InsertPoints /M=0 k, 1, attach_list, attach_sel
attach_list[i][kAttachColSel] = ""
attach_list[i][kAttachColTitle] = ""
attach_list[k][kAttachColName] = s
attach_sel[i][kAttachColSel] = 32
attach_sel[i][kAttachColTitle] = 0
attach_sel[i][kAttachColName] = 0
endif
endfor
// update titles
n = DimSize(attach_list, 0)
for (i = n-1; i >= 0; i -= 1)
s = attach_list[i][kAttachColName]
getwindow /z $s, wtitle
if (v_flag == 0)
attach_list[i][kAttachColTitle] = s_value
else
attach_list[i][kAttachColTitle] = s
endif
endfor
setdatafolder savedf
return 0
end
/// move an attachment item in the list of attachments
static function move_attach_item(logbook, item, distance)
string logbook
variable item
variable distance
dfref savedf = getdatafolderdfr()
dfref df_volatile = get_elog_df(logbook, kdfVolatile)
wave /t /sdfr=df_volatile attach_list
wave /sdfr=df_volatile attach_sel
variable n = DimSize(attach_list, 0)
variable dest = item + distance
if ((item >= 0) && (item < n) && (dest >= 0) && (dest < n))
string name = attach_list[item][kAttachColName]
variable sel = attach_sel[item][kAttachColSel]
DeletePoints /M=0 item, 1, attach_list, attach_sel
InsertPoints /M=0 dest, 1, attach_list, attach_sel
attach_list[dest][kAttachColName] = name
update_attach_items(logbook)
attach_sel[dest][kAttachColSel] = sel
endif
end
/// button procedure for the attachment up and down buttons
static function bp_attach_updown(ba) : ButtonControl
STRUCT WMButtonAction &ba
switch( ba.eventCode )
case 2: // mouse up
string logbook = GetUserData(ba.win, "", "logbook")
ControlInfo /w=$ba.win lb_attach
variable row = v_value
dfref df = $s_datafolder
wave /t /sdfr=df attach_list = $s_value
if (cmpstr(ba.ctrlName, "b_attach_up") == 0)
// up button
if (row >= 1)
move_attach_item(logbook, row, -1)
ListBox lb_attach, win=$ba.win, selRow=(row-1)
endif
else
// down button
if (row < DimSize(attach_list, 0) - 1)
move_attach_item(logbook, row, +1)
ListBox lb_attach, win=$ba.win, selRow=(row+1)
endif
endif
break
case -1: // control being killed
break
endswitch
return 0
end
/// button procedure for the Submit and Reply buttons
@@ -1259,7 +1510,7 @@ static function bp_submit(ba) : ButtonControl
end
/// select top graph window for attachment
static function bp_select_attach_top(ba) : ButtonControl
static function bp_attach_top(ba) : ButtonControl
STRUCT WMButtonAction &ba
switch( ba.eventCode )
@@ -1274,6 +1525,28 @@ static function bp_select_attach_top(ba) : ButtonControl
return 0
end
/// select/deselect all graph windows for attachment
static function bp_attach_allnone(ba) : ButtonControl
STRUCT WMButtonAction &ba
switch( ba.eventCode )
case 2: // mouse up
string logbook = GetUserData(ba.win, "", "logbook")
dfref df_volatile = get_elog_df(logbook, kdfVolatile)
wave /sdfr=df_volatile attach_sel
if (cmpstr(ba.ctrlName, "b_attach_all") == 0)
attach_sel[][kAttachColSel] = attach_sel[p][kAttachColSel] | 16
else
attach_sel[][kAttachColSel] = attach_sel[p][kAttachColSel] & ~16
endif
break
case -1: // control being killed
break
endswitch
return 0
end
static function bp_attach(ba) : ButtonControl
STRUCT WMButtonAction &ba
@@ -1307,6 +1580,34 @@ static function bp_attach(ba) : ButtonControl
return 0
end
static function bp_save_graphs(ba) : ButtonControl
STRUCT WMButtonAction &ba
switch( ba.eventCode )
case 2: // mouse up
string logbook = GetUserData(ba.win, "", "logbook")
string graphs = get_panel_graphs(ba.win)
variable ngraphs = ItemsInList(graphs, ";")
variable igraph
string sgraph
string graph_path
for (igraph = 0; igraph < ngraphs; igraph += 1)
sgraph = StringFromList(igraph, graphs, ";")
graph_path = create_graph_file(sgraph, igraph)
if (strlen(graph_path) > 0)
print graph_path
endif
endfor
break
case -1: // control being killed
break
endswitch
return 0
end
static function bp_clear(ba) : ButtonControl
STRUCT WMButtonAction &ba
@@ -1522,15 +1823,14 @@ end
/// get the names of the graphs selected for attachment
///
/// @param windowname panel window name
/// @returns a semicolon-separated list,
/// or the empty string if the selection is not valid.
///
/// in the current version, the function returns at most one graph.
/// in future versions, the function may return more than one graph.
///
static function /s get_panel_graphs(windowname)
string windowname // panel window name
dfref savedf = getdatafolderdfr()
if (strlen(windowname) == 0)
windowname = get_default_panel_name()
endif
@@ -1538,24 +1838,38 @@ static function /s get_panel_graphs(windowname)
return ""
endif
ControlInfo /W=$windowname pm_attach
// menu item has the form: "title (name)"
string graphname = ReplaceString(")", StringFromList(ItemsInList(s_value, "(") - 1, s_value, "("), "")
string logbook = GetUserData(windowname, "", "logbook")
dfref df_volatile = get_elog_df(logbook, kdfVolatile)
wave /t /sdfr=df_volatile attach_list
wave /sdfr=df_volatile attach_sel
string graphs = ""
string windows = WinList(graphname, ";", "WIN:1")
if (ItemsInList(windows) == 1)
graphs = graphname
else
graphs = ""
endif
string windows = ""
string graphname
variable n = DimSize(attach_sel, 0)
variable i
for (i = 0; i < n; i += 1)
if (attach_sel[i][kAttachColSel] & 16)
graphname = attach_list[i][kAttachColName]
windows = WinList(graphname, ";", "WIN:1")
if (ItemsInList(windows) == 1)
graphs = AddListItem(graphname, graphs, ";", inf)
endif
endif
endfor
return graphs
end
/// update selection of graphs for attachment
///
/// @param windowname panel window name. looks for default panel if empty.
///
/// @param graphs semicolon-separated list of names of graph windows to select for attachment.
///
static function /s set_panel_graphs(windowname, graphs)
string windowname // panel window name. looks for default panel if empty.
string graphs // name of graph window to select for attachment.
string windowname
string graphs
if (strlen(windowname) == 0)
windowname = get_default_panel_name()
@@ -1564,23 +1878,21 @@ static function /s set_panel_graphs(windowname, graphs)
return ""
endif
// the panel supports only one graph
string graph = StringFromList(0, graphs, ";")
string items = pm_list_attach_items()
string item
string itemname
variable nitems = ItemsInList(items, ";")
variable iitem
for (iitem = 0; iitem < nitems; iitem += 1)
item = StringFromList(iitem, items, ";")
itemname = ReplaceString(")", StringFromList(ItemsInList(item, "(") - 1, item, "("), "")
if (cmpstr(graph, itemname) == 0)
iitem += 1
PopupMenu pm_attach mode=iitem, win=$windowname
break
string logbook = GetUserData(windowname, "", "logbook")
update_attach_items(logbook)
dfref df_volatile = get_elog_df(logbook, kdfVolatile)
wave /t /sdfr=df_volatile attach_list
wave /sdfr=df_volatile attach_sel
variable n = DimSize(attach_sel, 0)
variable i
string graphname
for (i = 0; i < n; i += 1)
graphname = attach_list[i][kAttachColName]
if (WhichListItem(graphname, graphs)>= 0)
attach_sel[i][kAttachColSel] = 48
else
attach_sel[i][kAttachColSel] = 32
endif
endfor
return graph
end