PEARL Procedures rev-distro-3.1.0-0-gea838b3-dirty
Igor procedures for the analysis of PEARL data
Loading...
Searching...
No Matches
pearl-elog.ipf
Go to the documentation of this file.
1#pragma TextEncoding = "UTF-8"
2#pragma rtGlobals=3 // Use modern global access method and strict wave access.
3#pragma version = 2.2
4#pragma IgorVersion = 6.36
5#pragma ModuleName = PearlElog
6
7// author: matthias.muntwiler@psi.ch
8// Copyright (c) 2013-25 Paul Scherrer Institut
9
10// Licensed under the Apache License, Version 2.0 (the "License");
11// you may not use this file except in compliance with the License.
12// You may obtain a copy of the License at
13// http://www.apache.org/licenses/LICENSE-2.0
14
80
85
86static strconstant package_name = "pearl_elog"
87static strconstant package_path = "root:packages:pearl_elog:"
88
98function pearl_elog(logbook)
99 string logbook
100
101 if (init_package() == 0)
102 load_prefs()
103 string templates = list_logbooks(templates=1)
104 if (ItemsInList(templates) < 1)
106 endif
107 endif
108
109 if (strlen(logbook) == 0)
110 logbook = elog_prompt_logbook()
111 endif
112
113 string win_name = logbook + "ElogPanel"
114 if (strlen(logbook) > 0)
115 if (strlen(WinList(win_name, ";", "")) > 0)
116 DoWindow /F $win_name
117 else
118 win_name = PearlElogPanel(logbook)
119 STRUCT WMWinHookStruct s
120 s.eventCode = 0
121 s.winName = win_name
123 endif
124 endif
125end
126
128static function IgorBeforeNewHook(igorApplicationNameStr)
129 string igorApplicationNameStr
130 save_prefs()
132 return 0
133end
134
136static function IgorQuitHook(igorApplicationNameStr)
137 string igorApplicationNameStr
138 save_prefs()
140 return 0
141end
142
144static function AfterFileOpenHook(refNum,file,pathName,type,creator,kind)
145 Variable refNum,kind
146 String file,pathName,type,creator
147 if( (kind >= 1) && (kind <= 2))
149 endif
150 return 0
151end
152
153static constant kdfRoot = 0
154static constant kdfVolatile = 1
155static constant kdfPersistent = 2
156static constant kdfTemplates = 3
157
170static function /df get_elog_df(name, category)
171 string name
172 variable category
173
174 dfref df_package = $package_path
175 dfref df_persistent = df_package:persistent
176 dfref df_volatile = df_package:volatile
177
178 switch(category)
179 case kdfRoot:
180 dfref df_parent = df_package
181 break
182 case kdfPersistent:
183 dfref df_parent = df_persistent
184 break
185 case kdfTemplates:
186 dfref df_parent = df_persistent:templates
187 break
188 case kdfVolatile:
189 dfref df_parent = df_volatile
190 break
191 default:
192 Abort "get_elog_df: undefined data folder category."
193 endswitch
194
195 if ((strlen(name) > 0) && (category >= 1))
196 if (category == kdfTemplates)
197 dfref df_logbooks = df_parent
198 else
199 dfref df_logbooks = df_parent:logbooks
200 endif
201 dfref df_logbook = df_logbooks:$name
202 return df_logbook
203 else
204 return df_parent
205 endif
206end
207
212static function clear_package_data()
213 dfref savedf = getdatafolderdfr()
214 dfref df_root = get_elog_df("", kdfRoot)
215
216 if (DataFolderRefStatus(df_root) == 1)
217 string wins = WinList("*ElogPanel*", ";", "WIN:64")
218 variable iwin
219 variable nwin = ItemsInList(wins, ";")
220 string swin
221 for (iwin = 0; iwin < nwin; iwin += 1)
222 swin = StringFromList(iwin, wins, ";")
223 KillWindow /Z $swin
224 endfor
225 KillDataFolder /Z df_root
226 endif
227
228 setdatafolder savedf
229 return 0
230end
231
241static function init_package([clean])
242 variable clean
243
244 if (ParamIsDefault(clean))
245 clean = 0
246 endif
247
248 dfref savedf = getdatafolderdfr()
249 dfref df_root = get_elog_df("", kdfRoot)
250 if ((clean == 0) && (DataFolderRefStatus(df_root) == 1))
251 return 1
252 endif
253
254 setdatafolder root:
255 newdatafolder /o/s packages
256 newdatafolder /o/s $package_name
257 dfref df_package_root = getdatafolderdfr()
258 newdatafolder /o/s volatile
259 dfref df_volatile = getdatafolderdfr()
260 newdatafolder /o logbooks
261 setdatafolder df_package_root
262 newdatafolder /o/s persistent
263 dfref df_persistent = getdatafolderdfr()
264 newdatafolder /o logbooks
265 newdatafolder /o templates
266
267 // common configuration
268 setdatafolder df_persistent
269 string /g elog_path = "c:\\program files (x86)\\ELOG\\elog.exe"
270 string /g hostname = "localhost"
271 variable /g port = 0 // 0 = unspecified (default)
272 variable /g ssl = 0 // 0 = plain text (incl. passwords), 1 = secure connection
273 string /g subdir = ""
274 variable /g loglevel = 4
275
276 setdatafolder savedf
277 return 0
278end
279
287 dfref savedf = getdatafolderdfr()
288
289 dfref df_root = get_elog_df("", kdfRoot)
290 dfref df_persistent = get_elog_df("", kdfPersistent)
291 dfref df_templates = get_elog_df("", kdfTemplates)
292
293 // Experiments template
294 setdatafolder df_templates
295 newdatafolder /o/s Experiments
296
297 // attributes (persistent)
298 // available attributes
299 string /g attributes = "author;project;p-group;sample;source;task;technique;file;valid;"
300 // controls corresponding to attributes
301 // prefix determines the control type: sv_ = setvariable (string), pm_ = popup menu, cb = check box
302 string /g controls = "sv_author;sv_project;sv_pgroup;sv_sample;pm_source;pm_task;pm_technique;sv_file;cb_valid;"
303 // attributes with fixed options, value item declares the options string
304 string /g options = "source=sources;task=tasks;technique=techniques"
305 // attributes which must be defined
306 string /g required_attributes = "author;project;sample;source;task;technique;valid"
307
308 // option lists
309 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"
310 string /g tasks = "Measurement;Optimization;Analysis;Sample Preparation;Sample Storage;Comment;Development;Maintenance;Test;Other"
311 string /g techniques = "XPS;UPS;XPD;XAS;XMCD;PhD;ARUPS;STM;STS;LEED;AES;QMS;MBE;Sputter/Anneal;Test;Other"
312
313 // Calculations template
314 setdatafolder df_templates
315 newdatafolder /o/s Calculations
316
317 // attributes (persistent)
318 // available attributes
319 string /g attributes = "author;project;p-group;sample;program;revision;machine;job;experiment;source path;result path;valid"
320 // controls corresponding to attributes
321 // prefix determines the control type: sv_ = setvariable (string), pm_ = popup menu, cb = check box
322 string /g controls = "sv_author;sv_project;sv_pgroup;sv_sample;pm_program;sv_revision;pm_machine;sv_job;sv_experiment;sv_sourcepath;sv_resultpath;cb_valid"
323 // attributes with fixed options, value item declares the options string
324 string /g options = "program=programs;machine=machines"
325 // attributes which must be defined
326 string /g required_attributes = "author;project;sample"
327
328 // option lists
329 string /g programs = "PMSCO;EDAC;MSC;SSC;MUFPOT;DMSUP;Other"
330 string /g machines = "PC;VM;Ra;Merlin;llcx;Other"
331
332 // System template
333 setdatafolder df_templates
334 newdatafolder /o/s System
335
336 // attributes (persistent)
337 // available attributes
338 string /g attributes = "author;type;system;source;file"
339 // controls corresponding to attributes
340 // prefix determines the control type: sv_ = setvariable (string), pm_ = popup menu, cb = check box
341 string /g controls = "sv_author;pm_type;pm_system;pm_source;sv_file"
342 // attributes with fixed options, value item declares the options string
343 string /g options = "type=types;system=systems;source=sources"
344 // attributes which must be defined
345 string /g required_attributes = "author;type;system"
346
347 // option lists
348 string /g types = "Installation;Repair;Maintenance;Test;Commissioning;Bakeout;Incident;Cool-down;Warm-up;Storage;Other"
349 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;Other"
350 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"
351
352 setdatafolder savedf
353 return 0
354end
355
364static function init_volatile_vars()
365 dfref savedf = GetDataFolderDFR()
366
367 dfref df_volatile_root = get_elog_df("", kdfVolatile)
368 dfref df_volatile_parent = df_volatile_root:logbooks
369
370 string logbooks = list_logbooks()
371 string logbook
372 variable nlb = ItemsInList(logbooks)
373 variable ilb
374
375 SetDataFolder df_volatile_root
376 if (exists("temp_graph_files") != 2)
377 string /g temp_graph_files = ""
378 endif
379
380 for (ilb = 0; ilb < nlb; ilb += 1)
381 logbook = StringFromList(ilb, logbooks)
382
383 SetDataFolder df_volatile_parent
384 if (DataFolderExists(logbook))
385 SetDataFolder $logbook
386 else
387 NewDataFolder /o/s $logbook
388 endif
389
390 if (exists("username") != 2)
391 string /g username = ""
392 endif
393 if (exists("password") != 2)
394 string /g password = ""
395 endif
396 if (exists("msg_id") != 2)
397 variable /g msg_id = 0
398 endif
399 if (exists("att_list") != 1)
400 make /n=(0,3) /t /o attach_list
401 make /n=(0,3) /i /o attach_sel
402 endif
403 if (exists("url") != 2)
404 string /g url = ""
405 endif
406 endfor
407
408 SetDataFolder savedf
409 return 0
410end
411
425
438function elog_create_logbook(name, [template])
439 string name
440 string template
441
442 if (ParamIsDefault(template))
443 template = ""
444 endif
445
446 dfref savedf = getdatafolderdfr()
447 dfref df_root = get_elog_df("", kdfRoot)
448 dfref df_persistent_root = get_elog_df("", kdfPersistent)
449 dfref df_persistent_parent = df_persistent_root:logbooks
450 dfref df_volatile_root = get_elog_df("", kdfVolatile)
451 dfref df_volatile_parent = df_volatile_root:logbooks
452
453 setdatafolder df_persistent_parent
454 if (CheckName(name, 11) != 0)
455 setdatafolder savedf
456 Abort "invalid logbook name"
457 return -1
458 endif
459
460 if (strlen(template) > 0)
461 dfref df_template = get_elog_df(template, kdfTemplates)
462 dfref df_existing = get_elog_df(name, kdfPersistent)
463 if (DataFolderRefStatus(df_existing))
464 KillDataFolder /Z df_existing
465 endif
466 DuplicateDataFolder df_template, df_persistent_parent:$name
467 else
468 NewDataFolder /o/s df_persistent_parent:$name
469
470 // ELOG logbook name
471 string /g logbook = name
472 // attributes (persistent)
473 // available attributes
474 string /g attributes = ""
475 // controls corresponding to attributes
476 // prefix determines the control type: sv_ = setvariable (string), pm_ = popup menu, cb = check box
477 string /g controls = ""
478 // attributes with fixed options, value item declares the options string
479 string /g options = ""
480 // attributes which must be defined
481 string /g required_attributes = ""
482 endif
483
484 // usage data (persistent)
485 setdatafolder get_elog_df(name, kdfPersistent)
486 string /g recent = ""
487 string /g recent_message = ""
488
490
491 setdatafolder savedf
492 return 0
493end
494
497function elog_config([elog_path, hostname, port, subdir])
498 string elog_path
499 string hostname
500 variable port
501 string subdir
502
503 dfref df = get_elog_df("", kdfPersistent)
504
505 if (!ParamIsDefault(elog_path))
506 svar /sdfr=df g_elog_path = elog_path
507 g_elog_path = elog_path
508 endif
509 if (!ParamIsDefault(hostname))
510 svar /sdfr=df g_hostname = hostname
511 g_hostname = hostname
512 endif
513 if (!ParamIsDefault(port))
514 nvar /sdfr=df g_port = port
515 g_port = port
516 endif
517 if (!ParamIsDefault(subdir))
518 svar /sdfr=df g_subdir = subdir
519 g_subdir = subdir
520 endif
521end
522
537function elog_login(logbook, username, password)
538 string logbook
539 string username
540 string password
541
542 dfref df = get_elog_df(logbook, kdfVolatile)
543 svar /sdfr=df g_username=username
544 svar /sdfr=df g_password=password
545 g_username = username
546 g_password = password
547end
548
557function elog_logout(logbook)
558 string logbook
559
560 dfref df = get_elog_df(logbook, kdfVolatile)
561 if (strlen(logbook) > 0)
562 svar /z /sdfr=df g_username=username
563 svar /z /sdfr=df g_password=password
564 if (svar_exists(g_username))
565 g_username = ""
566 endif
567 if (svar_exists(g_password))
568 g_password = ""
569 endif
570 else
571 dfref df2 = df:logbooks
572 variable nlb = CountObjectsDFR(df2, 4)
573 variable ilb
574 string slb
575 for (ilb = 0; ilb < nlb; ilb += 1)
576 slb = GetIndexedObjNameDFR(df2, 4, ilb)
577 if (strlen(slb) > 0)
578 elog_logout(slb)
579 endif
580 endfor
581 endif
582end
583
588static function save_prefs()
589 dfref saveDF = GetDataFolderDFR()
590
591 dfref df = get_elog_df("", kdfPersistent)
592 if (DataFolderRefStatus(df) == 1)
593 string fullPath = SpecialDirPath("Packages", 0, 0, 0)
594 fullPath += package_name
595 NewPath/O/C/Q tempPackagePrefsPath, fullPath
596 fullPath += ":preferences.pxp"
597 SetDataFolder df
598 SaveData /O /Q /R fullPath
599 KillPath/Z tempPackagePrefsPath
600 endif
601
602 SetDataFolder saveDF
603end
604
608static function load_prefs()
609 dfref saveDF = GetDataFolderDFR()
610
611 variable result = -1
613 setdatafolder get_elog_df("", kdfPersistent)
614
615 string fullPath = SpecialDirPath("Packages", 0, 0, 0)
616 fullPath += package_name
617
618 GetFileFolderInfo /Q /Z fullPath
619 if (V_Flag == 0) // Disk directory exists?
620 fullPath += ":preferences.pxp"
621 GetFileFolderInfo /Q /Z fullPath
622 if (V_Flag == 0) // Preference file exist?
623 LoadData /O /R /Q fullPath
625 result = 0
626 endif
627 endif
628
629 SetDataFolder saveDF
630 return result
631end
632
642static function /s list_logbooks([templates])
643 variable templates
644
645 if (ParamIsDefault(templates))
646 templates = 0
647 endif
648
649 dfref df_persistent = get_elog_df("", kdfPersistent)
650 if (templates)
651 dfref df_logbooks = df_persistent:templates
652 else
653 dfref df_logbooks = df_persistent:logbooks
654 endif
655 string logbooks = ""
656
657 variable nlb = CountObjectsDFR(df_logbooks, 4)
658 variable ilb
659 string slb
660 for (ilb = 0; ilb < nlb; ilb += 1)
661 slb = GetIndexedObjNameDFR(df_logbooks, 4, ilb)
662 if (strlen(slb) > 0)
663 logbooks = AddListItem(slb, logbooks)
664 endif
665 endfor
666
667 return SortList(logbooks, ";", 16)
668end
669
677function elog_validate_attributes(logbook, attributes)
678
679 string logbook // name of the logbook (as in igor folder name)
680 string attributes // key=value list of attributes, semicolon separated
681
682 variable result = 0
683 return result
684end
685
709function elog_create_entry(logbook, attributes, message, [encoding, graphs, replyto])
710 string logbook
711 string attributes
712 string message
713 variable encoding
714 string graphs
715 variable replyto
716
717 if (ParamIsDefault(encoding))
718 encoding = 1
719 endif
720 if (ParamIsDefault(graphs))
721 graphs = ""
722 endif
723 if (ParamIsDefault(replyto))
724 replyto = 0
725 endif
726
727 dfref savedf = getdatafolderdfr()
728 dfref df_general = get_elog_df("", kdfPersistent)
729 dfref df_volatile = get_elog_df(logbook, kdfVolatile)
730
731 variable result = 0
732 nvar /sdfr=df_volatile msg_id
733 nvar /sdfr=df_general loglevel
734
735 if (elog_validate_attributes(logbook,attributes) != 0)
736 if (loglevel >= 2)
737 print "ELOG: failed to validate attributes."
738 endif
739 result = -3
740 endif
741
742 string cmd = prepare_command_line(logbook)
743 if (strlen(cmd) == 0)
744 if (loglevel >= 2)
745 print "ELOG: failed to prepare command line."
746 endif
747 result = -2
748 endif
749
750 if (replyto >= 1)
751 cmd += " -r " + num2str(replyto)
752 endif
753 cmd += " -n " + num2str(encoding)
754
755 variable nattr = ItemsInList(attributes, ";")
756 variable iattr
757 string sattr
758 for (iattr = 0; (iattr < nattr) && (result == 0); iattr += 1)
759 sattr = StringFromList(iattr, attributes, ";")
760 if (strlen(StringFromList(1, sattr, "=")) > 0)
761 sattr = ReplaceString("%", sattr, "")
762 cmd += " -a \"" + sattr + "\""
763 endif
764 endfor
765
766 if (result == 0)
767 string cmd_graphs = prepare_graph_attachments(graphs)
768 cmd += " " + cmd_graphs
769 endif
770
771 if ((result == 0) && (strlen(message) > 0))
772 string messagefile = create_message_file(message)
773 if (strlen(messagefile) > 0)
774 cmd += " -m \"" + messagefile + "\""
775 cmd += " > elog.log"
776 if (loglevel >= 5)
777 print cmd
778 endif
779 string cmd_file_path = create_cmd_file(cmd)
780 if (strlen(cmd_file_path) > 0)
781 ExecuteScriptText cmd_file_path
782 variable id = parse_result()
783 if (id > 0)
784 msg_id = id
785 if (loglevel >= 4)
786 print "ELOG: sent message " + num2str(id)
787 endif
788 else
789 if (loglevel >= 2)
790 print "ELOG: sending message failed."
791 endif
792 result = -4
793 endif
794 else
795 result = -2
796 endif
797 else
798 if (loglevel >= 2)
799 print "ELOG: failed to create temporary message file."
800 endif
801 result = -1
802 endif
803 endif
804
805 setdatafolder savedf
806 return result
807end
808
816function elog_add_attachment(logbook, id, graphs)
817 string logbook
818 variable id // existing entry ID
819 string graphs // names of graph windows to be added as attachments, semicolon separated
820
821 dfref savedf = getdatafolderdfr()
822 dfref df_general = get_elog_df("", kdfPersistent)
823 dfref df_volatile = get_elog_df(logbook, kdfVolatile)
824
825 variable result = 0
826 nvar /sdfr=df_volatile msg_id
827 nvar /sdfr=df_general loglevel
828
829 string cmd = prepare_command_line(logbook)
830 if (strlen(cmd) == 0)
831 result = -2 // error: invalid/missing command line
832 endif
833
834 cmd += " -e " + num2str(id)
835
836 if (result == 0)
837 string cmd_graphs = prepare_graph_attachments(graphs)
838 if (strlen(cmd_graphs) == 0)
839 result = -3 // error: invalid/missing graphs
840 endif
841 endif
842
843 if (result == 0)
844 cmd += " " + cmd_graphs
845 cmd += " > elog.log"
846 string cmd_file_path = create_cmd_file(cmd)
847 if (strlen(cmd_file_path) > 0)
848 ExecuteScriptText cmd_file_path
849 id = parse_result()
850 if (id > 0)
851 msg_id = id
852 if (loglevel >= 4)
853 print "ELOG: attached graphs to message " + num2str(id)
854 endif
855 else
856 if (loglevel >= 2)
857 print "ELOG: failed to attach graphs."
858 endif
859 result = -4 // error: elog returned error
860 endif
861 else
862 result = -2 // error: invalid command line
863 endif
864 endif
865
866 setdatafolder savedf
867 return result
868end
869
877static function /s prepare_command_line(logbook)
878 string logbook
879
880 dfref df_general = get_elog_df("", kdfPersistent)
881 dfref df_persistent = get_elog_df(logbook, kdfPersistent)
882 dfref df_volatile = get_elog_df(logbook, kdfVolatile)
883
884 svar /sdfr=df_general elog_path
885 svar /sdfr=df_general hostname
886 nvar /sdfr=df_general port
887 nvar /sdfr=df_general ssl
888 svar /sdfr=df_general subdir
889 nvar /sdfr=df_general loglevel
890 svar /sdfr=df_volatile username
891 svar /sdfr=df_volatile password
892
893 string cmd
894 cmd = "\"" + elog_path + "\""
895 if (loglevel >= 5)
896 cmd += " -v"
897 endif
898 cmd += " -h " + hostname
899 if ((nvar_exists(port)) && (port > 0))
900 cmd += " -p " + num2str(port)
901 endif
902 if ((svar_exists(subdir)) && (strlen(subdir) > 0))
903 cmd += " -d " + subdir
904 endif
905 cmd += " -l \"" + logbook + "\""
906 if ((nvar_exists(ssl)) && (ssl != 0))
907 cmd += " -s"
908 endif
909 //cmd += " -w " + password
910 if (svar_exists(username) && svar_exists(password) && (strlen(username) > 0) && (strlen(password) > 0))
911 cmd += " -u " + username + " " + password
912 endif
913
914 if (loglevel >= 5)
915 print cmd
916 endif
917
918 return cmd
919end
920
926static function /s format_url(logbook)
927 string logbook
928
929 dfref df_general = get_elog_df("", kdfPersistent)
930
931 svar /sdfr=df_general hostname
932 nvar /sdfr=df_general port
933 nvar /sdfr=df_general ssl
934 svar /sdfr=df_general subdir
935
936 string cmd = ""
937 if ((nvar_exists(ssl)) && (ssl != 0))
938 cmd += "https://"
939 else
940 cmd += "http://"
941 endif
942 cmd += hostname
943 if ((nvar_exists(port)) && (port > 0))
944 cmd += ":" + num2str(port)
945 endif
946 if ((svar_exists(subdir)) && (strlen(subdir) > 0))
947 cmd += "/" + subdir
948 endif
949 cmd += "/" + logbook
950
951 return cmd
952end
953
963static function /s prepare_graph_attachments(graphs)
964 string graphs // names of graph windows to be added as attachments, semicolon separated
965
966 string cmd = ""
967 variable ngraphs = ItemsInList(graphs, ";")
968 variable igraph
969 string sgraph
970 string graph_path
971 for (igraph = 0; igraph < ngraphs; igraph += 1)
972 sgraph = StringFromList(igraph, graphs, ";")
973 graph_path = create_graph_file(sgraph, igraph)
974 if (strlen(graph_path) > 0)
975 cmd += " -f \"" + graph_path + "\""
976 endif
977 endfor
978
979 return cmd
980end
981
982static function /s get_timestamp(sep)
983 string sep
984 Variable now = DateTime
985 string dat = ReplaceString("-", Secs2Date(DateTime, -2), "")
986 string tim = ReplaceString(":", Secs2Time(DateTime, 3), "")
987 return dat + sep + tim
988end
989
1006static function /s create_message_file(message)
1007 string message
1008
1009 message = ReplaceString("%", message, "")
1010 string path = SpecialDirPath("Temporary", 0, 1, 0)
1011 variable len = strlen(path)
1012 string filename
1013
1014 if (numtype(len) == 0)
1015 filename = "elog_temp_message.txt"
1016 path += filename
1017 variable f1
1018 Open f1 as path
1019 fprintf f1, message
1020 Close f1
1021 else
1022 filename = ""
1023 endif
1024
1025 return filename
1026end
1027
1047static function /s create_graph_file(graphname, fileindex)
1048 string graphname
1049 variable fileindex
1050
1051 dfref df_volatile_root = get_elog_df("", kdfVolatile)
1052 svar /sdfr=df_volatile_root temp_graph_files
1053
1054 string path = SpecialDirPath("Temporary", 0, 1, 0)
1055 string ts = get_timestamp("_")
1056 variable len = strlen(path)
1057 string filename
1058
1059 if (numtype(len) == 0)
1060 filename = "elog_" + ts + "_" + num2str(fileindex) + ".png"
1061 path += filename
1062 SavePICT /B=72 /E=-5 /M /O /W=(0,0,8,6) /WIN=$graphname /Z as path
1063 if (v_flag == 0)
1064 temp_graph_files = AddListItem(path, temp_graph_files, ";", inf)
1065 else
1066 filename = ""
1067 endif
1068 else
1069 filename = ""
1070 endif
1071
1072 return filename
1073end
1074
1083static function /s create_cmd_file(cmd)
1084 string cmd
1085
1086 dfref df_general = get_elog_df("", kdfPersistent)
1087 nvar /sdfr=df_general loglevel
1088
1089 if (strlen(cmd) >= 1024)
1090 if (loglevel >= 2)
1091 print "ELOG: command line too long (add fewer attachments)."
1092 endif
1093 return ""
1094 endif
1095
1096 string work_path = SpecialDirPath("Temporary", 0, 1, 0)
1097 variable len = strlen(work_path)
1098 if (numtype(len) == 0)
1099 string cmdx
1100 string cmd_path = work_path + "elog_temp_cmd.bat"
1101
1102 variable f1
1103 Open f1 as cmd_path
1104 cmdx = "c:\r\n"
1105 fprintf f1, cmdx
1106 cmdx = "cd \"" + work_path + "\"\r\n"
1107 fprintf f1, cmdx
1108 cmdx = "del elog.log"
1109 fprintf f1, cmdx + "\r\n"
1110 fprintf f1, cmd
1111 Close f1
1112 else
1113 cmd_path = ""
1114 endif
1115
1116 return cmd_path
1117end
1118
1119static function /s get_log_path()
1120 string path = SpecialDirPath("Temporary", 0, 1, 0)
1121 variable len = strlen(path)
1122 if (numtype(len) == 0)
1123 path += "elog.log"
1124 else
1125 path = ""
1126 endif
1127
1128 return path
1129end
1130
1139static function cleanup_temp_files()
1140 dfref df_volatile_root = get_elog_df("", kdfVolatile)
1141 if (DataFolderRefStatus(df_volatile_root))
1142 svar /sdfr=df_volatile_root /z temp_graph_files
1143 if (SVAR_Exists(temp_graph_files))
1144 variable nfi = ItemsInList(temp_graph_files)
1145 variable ifi
1146 string sfi
1147 for (ifi = 0; ifi < nfi; ifi += 1)
1148 sfi = StringFromList(ifi, temp_graph_files)
1149 DeleteFile /Z sfi
1150 endfor
1151 temp_graph_files = ""
1152 endif
1153 endif
1154 return 0
1155end
1156
1157static strconstant elog_success_msg = "Message successfully transmitted"
1158static strconstant elog_parse_id = "ID=%u"
1159
1165static function parse_result()
1166 dfref df_general = get_elog_df("", kdfPersistent)
1167 nvar /sdfr=df_general loglevel
1168
1169 string path = get_log_path()
1170 string line = ""
1171 string output = ""
1172 variable success = 0
1173 variable id = -1
1174 string part1 = ""
1175 string part2 = ""
1176
1177 variable len = strlen(path)
1178 if (numtype(len) == 0)
1179 variable f1
1180 Open /R/Z f1 as path
1181 if (v_flag == 0)
1182 do
1183 FReadLine f1, line
1184 if (strlen(line) > 0)
1185 part1 = StringFromList(0, line, ",")
1186 part2 = ReplaceString(" ", StringFromList(1, line, ","), "")
1187 success = cmpstr(part1, elog_success_msg) == 0
1188 if (success)
1189 sscanf part2, elog_parse_id, id
1190 endif
1191 else
1192 break
1193 endif
1194 output += line
1195 while(!success)
1196 Close f1
1197 endif
1198 endif
1199 if (loglevel >= 5)
1200 print output
1201 endif
1202
1203 return id
1204end
1205
1209 string logbooks = list_logbooks(templates=0)
1210 logbooks = AddListItem("(new)", logbooks)
1211 string templates = list_logbooks(templates=1)
1212 templates = AddListItem("(none)", templates)
1213
1214 string logbook = StringFromList(0, logbooks)
1215 string template = StringFromList(0, logbooks)
1216 string name = ""
1217 string username = ""
1218 string password = ""
1219
1220 prompt logbook, "logbook", popup logbooks
1221 prompt template, "template", popup templates
1222 prompt name, "new logbook name"
1223
1224 doprompt "select logbook", logbook, template, name
1225 if (!v_flag)
1226 if (cmpstr(logbook, "(new)") == 0)
1227 elog_create_logbook(name, template=template)
1228 logbook = name
1229 endif
1230 else
1231 logbook = ""
1232 endif
1233 return logbook
1234end
1235
1238function elog_prompt_login(logbook)
1239 string logbook
1240
1241 string logbooks = list_logbooks(templates=0)
1242
1243 string username = ""
1244 string password = ""
1245
1246 prompt logbook, "logbook", popup logbooks
1247 prompt username, "user name"
1248 prompt password, "password (blank to log out)"
1249
1250 doprompt "log in to logbook", logbook, username, password
1251 if (!v_flag)
1252 elog_login(logbook, username, password)
1253 endif
1254
1255 return v_flag
1256end
1257
1265function /s PearlElogPanel(logbook)
1266 string logbook
1267
1268 dfref savedf = getdatafolderdfr()
1269 dfref df_general = get_elog_df("", kdfPersistent)
1270 dfref df_persistent = get_elog_df(logbook, kdfPersistent)
1271 dfref df_volatile = get_elog_df(logbook, kdfVolatile)
1272
1273 string win_name = logbook + "ElogPanel"
1274 string win_title = "ELOG " + logbook
1275
1276 NewPanel /K=1 /N=$win_name /W=(600,200,1200,700) as win_title
1277 win_name = s_name
1278 ModifyPanel /w=$win_name cbRGB=(52224,52224,65280)
1279
1280 svar /sdfr=df_persistent attributes
1281 svar /sdfr=df_persistent controls
1282 svar /sdfr=df_persistent options
1283 wave /t /sdfr=df_volatile attach_list
1284 wave /sdfr=df_volatile attach_sel
1285 svar /sdfr=df_volatile url
1286
1287 variable iattr
1288 variable nattr = ItemsInList(attributes, ";")
1289 string s_attr
1290 string s_control
1291 string s_option
1292 string persistent_path = GetDataFolder(1, df_persistent)
1293 string volatile_path = GetDataFolder(1, df_volatile)
1294 string options_path
1295 string variable_path
1296 variable ypos = 2
1297 variable height = 0
1298
1299 for (iattr = 0; iattr < nattr; iattr += 1)
1300 s_attr = StringFromList(iattr, attributes, ";")
1301 s_control = StringFromList(iattr, controls, ";")
1302 strswitch(s_control[0,1])
1303 case "sv":
1304 SetVariable $s_control, win=$win_name, pos={0,ypos}, size={300,16}, bodyWidth=230
1305 SetVariable $s_control, win=$win_name, title=s_attr, value= _STR:""
1306 SetVariable $s_control, win=$win_name, userdata(attribute)=s_attr
1307 ypos += 18
1308 break
1309 case "pm":
1310 options_path = persistent_path + StringByKey(s_attr, options, "=", ";")
1311 PopupMenu $s_control, win=$win_name, pos={0,ypos}, size={300,21}, bodyWidth=230
1312 PopupMenu $s_control, win=$win_name, title=s_attr
1313 PopupMenu $s_control, win=$win_name, mode=1, popvalue="Test", value= #options_path
1314 PopupMenu $s_control, win=$win_name, userdata(attribute)=s_attr
1315 ypos += 23
1316 break
1317 case "cb":
1318 CheckBox $s_control, win=$win_name, pos={70,ypos}, size={300,14}
1319 CheckBox $s_control, win=$win_name, title=s_attr, value= 1
1320 CheckBox $s_control, win=$win_name, userdata(attribute)=s_attr
1321 ypos += 17
1322 break
1323 endswitch
1324 endfor
1325 ypos = max(ypos, 80)
1326
1327 TitleBox t_attach, win=$win_name, pos={308,5}, size={70,14}, title="Attachments", frame=0
1328 height = ypos - 21 - 4
1329 ListBox lb_attach, win=$win_name, pos={308,21}, size={264,height}
1330 ListBox lb_attach, win=$win_name, listWave=attach_list
1331 ListBox lb_attach, win=$win_name, mode=1, selWave=attach_sel, selRow=-1
1332 ListBox lb_attach, win=$win_name, widths={20,160,80}
1333 ListBox lb_attach, win=$win_name, help={"Choose graphs to attach to the message."}
1334
1335 Button b_attach_top, win=$win_name, pos={420,2}, size={40,18}, title="top"
1336 Button b_attach_top, win=$win_name, fcolor=(56576,60928,47872)
1337 Button b_attach_top, win=$win_name, proc=PearlElog#bp_attach_top
1338 Button b_attach_top, win=$win_name, help={"Select top graph for attachment."}
1339 Button b_attach_all, win=$win_name, pos={460,2}, size={40,18}, title="all"
1340 Button b_attach_all, win=$win_name, fcolor=(56576,60928,47872)
1341 Button b_attach_all, win=$win_name, proc=PearlElog#bp_attach_allnone
1342 Button b_attach_all, win=$win_name, help={"Select all graphs for attachment."}
1343 Button b_attach_none, win=$win_name, pos={500,2}, size={40,18}, title="none"
1344 Button b_attach_none, win=$win_name, fcolor=(56576,60928,47872)
1345 Button b_attach_none, win=$win_name, proc=PearlElog#bp_attach_allnone
1346 Button b_attach_none, win=$win_name, help={"Deselect all attachments."}
1347 Button b_save_graphs, win=$win_name, pos={540,2}, size={40,18}, title="save"
1348 Button b_save_graphs, win=$win_name, fcolor=(56576,60928,47872)
1349 Button b_save_graphs, win=$win_name, proc=PearlElog#bp_save_graphs
1350 Button b_save_graphs, win=$win_name, help={"Save selected graphs as PNG bitmap files."}
1351 Button b_attach_up, win=$win_name, pos={576,20}, size={20,20}, title="\\W517"
1352 Button b_attach_up, win=$win_name, fcolor=(56576,60928,47872)
1353 Button b_attach_up, win=$win_name, proc=PearlElog#bp_attach_updown
1354 Button b_attach_up, win=$win_name, help={"Move selected graph up."}
1355 Button b_attach_dw, win=$win_name, pos={576,40}, size={20,20}, title="\\W523"
1356 Button b_attach_dw, win=$win_name, fcolor=(56576,60928,47872)
1357 Button b_attach_dw, win=$win_name, proc=PearlElog#bp_attach_updown
1358 Button b_attach_dw, win=$win_name, help={"Move selected graph down."}
1359
1360 ypos += 246-160
1361 Button b_submit,win=$win_name, pos={70,ypos},size={46,20},proc=PearlElog#bp_submit,title="Submit"
1362 Button b_submit,win=$win_name, help={"Submit form data to ELOG (new entry)."}
1363 Button b_submit,win=$win_name, fcolor=(56576,60928,47872)
1364 Button b_clear,win=$win_name, pos={120,ypos},size={46,20},proc=PearlElog#bp_clear,title="Clear"
1365 Button b_clear,win=$win_name, help={"Clear the form fields"}
1366 Button b_clear,win=$win_name, fcolor=(56576,60928,47872)
1367
1368 ypos += 272-246
1369 variable_path = volatile_path + "msg_id"
1370 SetVariable sv_id,win=$win_name, pos={51,ypos},size={119,16},bodyWidth=77
1371 SetVariable sv_id,win=$win_name, title="ID",value=$variable_path
1372 SetVariable sv_id,win=$win_name, help={"ID of last submitted message, or message to attach or reply to."}
1373
1374 TitleBox t_host, win=$win_name, pos={170,ypos+4}, size={112.00,14.00}, frame=0
1375 TitleBox t_host, win=$win_name, variable=url
1376
1377 ypos += 270-272
1378 Button b_attach,win=$win_name, pos={170,ypos},size={48,20},proc=PearlElog#bp_attach,title="Attach"
1379 Button b_attach,win=$win_name, help={"Attach the selected graph to an existing ELOG entry (correct ID required)."}
1380 Button b_attach,win=$win_name, fcolor=(56576,60928,47872)
1381 Button b_reply,win=$win_name, pos={220,ypos},size={48,20},proc=PearlElog#bp_submit,title="Reply"
1382 Button b_reply,win=$win_name, help={"Submit form data to ELOG as a reply to an existing message (correct ID required)."}
1383 Button b_reply,win=$win_name, fcolor=(56576,60928,47872)
1384 Button b_login,win=$win_name, pos={550,ypos},size={46,20},proc=PearlElog#bp_login,title="Login"
1385 Button b_login,win=$win_name, help={"Enter user name and password."}
1386 Button b_login,win=$win_name, fcolor=(56576,60928,47872)
1387 Button b_logout,win=$win_name, pos={550,ypos},size={46,20},proc=PearlElog#bp_logout,title="Logout"
1388 Button b_logout,win=$win_name, help={"Clear user name and password."}
1389 Button b_logout,win=$win_name, fcolor=(56576,60928,47872), disable=3
1390
1391 SetWindow $win_name, hook(elogPanelHook)=PearlElog#elog_panel_hook
1392 SetWindow $win_name, userdata(logbook)=logbook
1393
1394 ypos += 160-270
1395 TitleBox t_message,win=$win_name, pos={10,ypos},size={58,16},fixedSize=1,frame=0,anchor=RT,title="Message"
1396 DefineGuide UGH0={FT,ypos},UGV0={FL,70},UGH1={FB,-52},UGV1={FR,-2}
1397 NewNotebook /F=0 /N=Message /OPTS=3 /W=(115,404,345,341)/FG=(UGV0,UGH0,UGV1,UGH1) /HOST=#
1398 Notebook kwTopWin, defaultTab=20, statusWidth=0, autoSave=0
1399 Notebook kwTopWin fSize=10, fStyle=0, textRGB=(0,0,0)
1400 RenameWindow #,Message
1401 string nb_name = win_name + "#Message"
1402 SetActiveSubwindow ##
1403
1404 // restore recently used attributes and message
1405 svar /z /sdfr=df_persistent recent
1406 if (svar_exists(recent) && (strlen(recent) > 0))
1407 set_panel_attributes(win_name, recent)
1408 endif
1409 svar /z /sdfr=df_persistent recent_message
1410 if (svar_exists(recent_message) && (strlen(recent_message) > 0))
1411 set_panel_message(win_name, recent_message)
1412 endif
1413 Notebook $nb_name selection={startOfFile,startOfFile}, findText={"",1}
1414
1415 setdatafolder savedf
1416 return win_name
1417end
1418
1419static function elog_panel_hook(s)
1420 STRUCT WMWinHookStruct &s
1421
1422 Variable hookResult = 0
1423
1424 switch(s.eventCode)
1425 case 0: // activate
1426 string logbook = GetUserData(s.winName, "", "logbook")
1427 if (strlen(logbook) > 0)
1428 dfref df_volatile = get_elog_df(logbook, kdfVolatile)
1429 svar /sdfr=df_volatile url
1430 url = format_url(logbook)
1431 update_attach_items(logbook)
1432 update_buttons(s.winName, logbook)
1433 endif
1434 break
1435 case 6: // resize
1436 // move bottom-aligned controls when the window is resized
1437 variable b_top = s.winRect.bottom + 4
1438 Button b_submit,pos={70,b_top}
1439 Button b_clear,pos={120,b_top}
1440 TitleBox t_host, pos={170,b_top+4}
1441 b_top += 24
1442 Button b_attach,pos={170,b_top}
1443 Button b_reply,pos={220,b_top}
1444 Button b_login, pos={550,b_top}
1445 Button b_logout, pos={550,b_top}
1446 b_top += 2
1447 SetVariable sv_id,pos={51,b_top}
1448 break
1449 endswitch
1450
1451 return hookResult // 0 if nothing done, else 1
1452end
1453
1454static function update_buttons(win_name, logbook)
1455 string win_name
1456 string logbook
1457 dfref df = get_elog_df(logbook, kdfVolatile)
1458 //string win_name = StringFromList(0, WinList(logbook + "ElogPanel*", ";", "WIN:64"), ";")
1459
1460 variable logged = 0
1461 if (strlen(logbook) > 0)
1462 svar /z /sdfr=df g_username=username
1463 svar /z /sdfr=df g_password=password
1464 if (svar_exists(g_username) && svar_exists(g_password))
1465 logged = strlen(g_username) > 0 && strlen(g_password) > 0
1466 endif
1467 endif
1468
1469 if (strlen(win_name) > 0)
1470 if (logged)
1471 Button b_login, win=$win_name, disable=3
1472 Button b_logout, win=$win_name, disable=0
1473 else
1474 Button b_login, win=$win_name, disable=0
1475 Button b_logout, win=$win_name, disable=3
1476 endif
1477 endif
1478end
1479
1480static constant kAttachColSel = 0
1481static constant kAttachColTitle = 1
1482static constant kAttachColName = 2
1483
1485static function update_attach_items(logbook)
1486 string logbook
1487
1488 dfref savedf = getdatafolderdfr()
1489 dfref df_volatile = get_elog_df(logbook, kdfVolatile)
1490 wave /t /sdfr=df_volatile attach_list
1491 wave /sdfr=df_volatile attach_sel
1492
1493 if (!waveexists(attach_list))
1494 return -1
1495 endif
1496 string names = WinList("*", ";", "WIN:1;VISIBLE:1")
1497 names = SortList(names, ";", 16)
1498
1499 // remove closed graphs
1500 variable i
1501 variable k
1502 variable n = DimSize(attach_list, 0)
1503 string s
1504 for (i = n-1; i >= 0; i -= 1)
1505 s = attach_list[i][kAttachColName]
1506 if (WhichListItem(s, names) < 0)
1507 DeletePoints /M=0 i, 1, attach_list, attach_sel
1508 endif
1509 endfor
1510
1511 // add new graphs
1512 n = ItemsInList(names)
1513 for (i = 0; i < n; i += 1)
1514 s = StringFromList(i, names)
1515 FindValue /text=s /txop=4 /z attach_list
1516 if (v_value < 0)
1517 k = DimSize(attach_list, 0)
1518 Redimension /n=(k+1,3) attach_list, attach_sel
1519 //InsertPoints /M=0 k, 1, attach_list, attach_sel
1520 attach_list[k][kAttachColSel] = ""
1521 attach_list[k][kAttachColTitle] = ""
1522 attach_list[k][kAttachColName] = s
1523 attach_sel[k][kAttachColSel] = 32
1524 attach_sel[k][kAttachColTitle] = 0
1525 attach_sel[k][kAttachColName] = 0
1526 endif
1527 endfor
1528
1529 // update titles
1530 n = DimSize(attach_list, 0)
1531 for (i = n-1; i >= 0; i -= 1)
1532 s = attach_list[i][kAttachColName]
1533 getwindow /z $s, wtitle
1534 if (v_flag == 0)
1535 attach_list[i][kAttachColTitle] = s_value
1536 else
1537 attach_list[i][kAttachColTitle] = s
1538 endif
1539 endfor
1540
1541 setdatafolder savedf
1542 return 0
1543end
1544
1546static function move_attach_item(logbook, item, distance)
1547 string logbook
1548 variable item
1549 variable distance
1550
1551 dfref savedf = getdatafolderdfr()
1552 dfref df_volatile = get_elog_df(logbook, kdfVolatile)
1553 wave /t /sdfr=df_volatile attach_list
1554 wave /sdfr=df_volatile attach_sel
1555 variable n = DimSize(attach_list, 0)
1556 variable dest = item + distance
1557
1558 if ((item >= 0) && (item < n) && (dest >= 0) && (dest < n))
1559 string name = attach_list[item][kAttachColName]
1560 variable sel = attach_sel[item][kAttachColSel]
1561 DeletePoints /M=0 item, 1, attach_list, attach_sel
1562 InsertPoints /M=0 dest, 1, attach_list, attach_sel
1563 attach_list[dest][kAttachColName] = name
1564 update_attach_items(logbook)
1565 attach_sel[dest][kAttachColSel] = sel
1566 endif
1567end
1568
1570static function bp_attach_updown(ba) : ButtonControl
1571 STRUCT WMButtonAction &ba
1572
1573 switch( ba.eventCode )
1574 case 2: // mouse up
1575 string logbook = GetUserData(ba.win, "", "logbook")
1576 ControlInfo /w=$ba.win lb_attach
1577 variable row = v_value
1578 dfref df = $s_datafolder
1579 wave /t /sdfr=df attach_list = $s_value
1580 if (cmpstr(ba.ctrlName, "b_attach_up") == 0)
1581 // up button
1582 if (row >= 1)
1583 move_attach_item(logbook, row, -1)
1584 ListBox lb_attach, win=$ba.win, selRow=(row-1)
1585 endif
1586 else
1587 // down button
1588 if (row < DimSize(attach_list, 0) - 1)
1589 move_attach_item(logbook, row, +1)
1590 ListBox lb_attach, win=$ba.win, selRow=(row+1)
1591 endif
1592 endif
1593 break
1594 case -1: // control being killed
1595 break
1596 endswitch
1597
1598 return 0
1599end
1600
1602static function bp_submit(ba) : ButtonControl
1603 STRUCT WMButtonAction &ba
1604
1605 switch( ba.eventCode )
1606 case 2: // mouse up
1607 string logbook = GetUserData(ba.win, "", "logbook")
1608 string attributes
1609 string message
1610 string graphs
1611 attributes = get_panel_attributes(ba.win)
1612 message = get_panel_message(ba.win)
1613 graphs = get_panel_graphs(ba.win)
1614
1615 variable id
1616 if (cmpstr(ba.ctrlName, "b_reply") == 0)
1617 // Reply button
1618 ControlInfo /w=$ba.win sv_id
1619 id = v_value
1620 else
1621 // Submit button
1622 id = 0
1623 endif
1624
1625 if ((elog_validate_attributes(logbook, attributes) == 0) && (strlen(message) > 0))
1626 variable result
1627 result = elog_create_entry(logbook, attributes, message, graphs=graphs, replyto=id)
1628 if (result == 0)
1629 dfref df = get_elog_df(logbook, kdfPersistent)
1630 svar /sdfr=df recent
1631 recent = attributes
1632 svar /sdfr=df recent_message
1633 recent_message = message
1634 else
1635 abort "Submission failed. Error code " + num2str(result) + "."
1636 endif
1637 else
1638 abort "Submission failed due to missing/invalid attribute."
1639 endif
1640 break
1641 case -1: // control being killed
1642 break
1643 endswitch
1644
1645 return 0
1646end
1647
1649static function bp_attach_top(ba) : ButtonControl
1650 STRUCT WMButtonAction &ba
1651
1652 switch( ba.eventCode )
1653 case 2: // mouse up
1654 string graphs = WinName(0, 1, 1)
1655 set_panel_graphs(ba.win, graphs)
1656 break
1657 case -1: // control being killed
1658 break
1659 endswitch
1660
1661 return 0
1662end
1663
1665static function bp_attach_allnone(ba) : ButtonControl
1666 STRUCT WMButtonAction &ba
1667
1668 switch( ba.eventCode )
1669 case 2: // mouse up
1670 string logbook = GetUserData(ba.win, "", "logbook")
1671 dfref df_volatile = get_elog_df(logbook, kdfVolatile)
1672 wave /sdfr=df_volatile attach_sel
1673 if (cmpstr(ba.ctrlName, "b_attach_all") == 0)
1674 attach_sel[][kAttachColSel] = attach_sel[p][kAttachColSel] | 16
1675 else
1676 attach_sel[][kAttachColSel] = attach_sel[p][kAttachColSel] & ~16
1677 endif
1678 break
1679 case -1: // control being killed
1680 break
1681 endswitch
1682
1683 return 0
1684end
1685
1686static function bp_attach(ba) : ButtonControl
1687 STRUCT WMButtonAction &ba
1688
1689 switch( ba.eventCode )
1690 case 2: // mouse up
1691 string logbook = GetUserData(ba.win, "", "logbook")
1692 string graphs
1693 graphs = get_panel_graphs(ba.win)
1694
1695 variable id
1696 ControlInfo /w=$ba.win sv_id
1697 id = v_value
1698
1699 // TODO : is there a way around this restriction?
1700 DoAlert /T="ELOG" 1, "This operation will replace all existing attachments. Do you want to continue?"
1701
1702 if ((id > 0) && (v_flag == 1))
1703 variable result
1704 result = elog_add_attachment(logbook, id, graphs)
1705 if (result != 0)
1706 abort "Submission failed. Error code " + num2str(result) + "."
1707 endif
1708 else
1709 abort "Submission failed due to missing/invalid attribute."
1710 endif
1711 break
1712 case -1: // control being killed
1713 break
1714 endswitch
1715
1716 return 0
1717end
1718
1719static function bp_save_graphs(ba) : ButtonControl
1720 STRUCT WMButtonAction &ba
1721
1722 switch( ba.eventCode )
1723 case 2: // mouse up
1724 string logbook = GetUserData(ba.win, "", "logbook")
1725 string graphs = get_panel_graphs(ba.win)
1726 variable ngraphs = ItemsInList(graphs, ";")
1727
1728 variable igraph
1729 string sgraph
1730 string graph_path
1731 for (igraph = 0; igraph < ngraphs; igraph += 1)
1732 sgraph = StringFromList(igraph, graphs, ";")
1733 graph_path = create_graph_file(sgraph, igraph)
1734 if (strlen(graph_path) > 0)
1735 print graph_path
1736 endif
1737 endfor
1738
1739 break
1740 case -1: // control being killed
1741 break
1742 endswitch
1743
1744 return 0
1745end
1746
1747static function bp_clear(ba) : ButtonControl
1748 STRUCT WMButtonAction &ba
1749
1750 switch( ba.eventCode )
1751 case 2: // mouse up
1752 set_panel_attributes(ba.win, "", clear=1)
1753 set_panel_message(ba.win, "")
1754 set_panel_graphs(ba.win, "")
1755 break
1756 case -1: // control being killed
1757 break
1758 endswitch
1759
1760 return 0
1761end
1762
1763static function bp_login(ba) : ButtonControl
1764 STRUCT WMButtonAction &ba
1765
1766 switch( ba.eventCode )
1767 case 2: // mouse up
1768 string logbook = GetUserData(ba.win, "", "logbook")
1769 if (elog_prompt_login(logbook) == 0)
1770 Button b_login, win=$ba.win, disable=3
1771 Button b_logout, win=$ba.win, disable=0
1772 endif
1773 break
1774 case -1: // control being killed
1775 break
1776 endswitch
1777
1778 return 0
1779end
1780
1781static function bp_logout(ba) : ButtonControl
1782 STRUCT WMButtonAction &ba
1783
1784 switch( ba.eventCode )
1785 case 2: // mouse up
1786 string logbook = GetUserData(ba.win, "", "logbook")
1787 elog_logout(logbook)
1788 Button b_login, win=$ba.win, disable=0
1789 Button b_logout, win=$ba.win, disable=3
1790 break
1791 case -1: // control being killed
1792 break
1793 endswitch
1794
1795 return 0
1796end
1797
1798static function /s get_default_panel_name()
1799 string windowname
1800 windowname = StringFromList(0, WinList("*ElogPanel*", ";", "WIN:64"), ";")
1801 return windowname
1802end
1803
1811static function /s get_panel_attributes(windowname)
1812 string windowname
1813
1814 if (strlen(windowname) == 0)
1815 windowname = get_default_panel_name()
1816 endif
1817 if (strlen(windowname) == 0)
1818 return ""
1819 endif
1820
1821 string controls = ControlNameList(windowname, ";")
1822 string attributes = ""
1823 string control
1824 string attribute
1825 variable ico
1826 variable nco = ItemsInList(controls, ";")
1827 for (ico = 0; ico < nco; ico += 1)
1828 control = StringFromList(ico, controls, ";")
1829 attribute = GetUserData(windowname, control, "attribute")
1830 if (strlen(attribute) > 0)
1831 ControlInfo /w=$windowname $control
1832 switch(v_flag)
1833 case 2: // checkbox
1834 attributes = ReplaceNumberByKey(attribute, attributes, v_value, ":", ";")
1835 break
1836 case 3: // popupmenu
1837 case 5: // setvariable
1838 attributes = ReplaceStringByKey(attribute, attributes, s_value, ":", ";")
1839 break
1840 endswitch
1841 endif
1842 endfor
1843
1844 return attributes
1845end
1846
1858static function /s set_panel_attributes(windowname, attributes, [clear])
1859 string windowname
1860 string attributes
1861 variable clear
1862
1863 if (strlen(windowname) == 0)
1864 windowname = get_default_panel_name()
1865 endif
1866 if (strlen(windowname) == 0)
1867 return ""
1868 endif
1869 if (ParamIsDefault(clear))
1870 clear = 0
1871 endif
1872
1873 string path
1874
1875 string logbook = GetUserData(windowname, "", "logbook")
1876 dfref df_persistent = get_elog_df(logbook, kdfPersistent)
1877 string persistent_path = GetDataFolder(1, df_persistent)
1878 svar /sdfr=df_persistent options
1879 string options_path
1880
1881 string controls = ControlNameList(windowname, ";")
1882 string control
1883 string attribute
1884 string value
1885 variable numval
1886 variable ico
1887 variable nco = ItemsInList(controls, ";")
1888 for (ico = 0; ico < nco; ico += 1)
1889 control = StringFromList(ico, controls, ";")
1890 attribute = GetUserData(windowname, control, "attribute")
1891 if (strlen(attribute))
1892 value = StringByKey(attribute, attributes, ":", ";")
1893 if (strlen(value) || clear)
1894 ControlInfo /w=$windowname $control
1895 switch(v_flag)
1896 case 2: // checkbox
1897 numval = NumberByKey(attribute, attributes, ":", ";")
1898 if ((numtype(numval) != 0) && clear)
1899 numval = 0
1900 endif
1901 if (numtype(numval) == 0)
1902 CheckBox $control, value=numval, win=$windowname
1903 endif
1904 break
1905 case 3: // popupmenu
1906 options_path = persistent_path + StringByKey(attribute, options, ":", ";")
1907 svar values = $options_path
1908 numval = WhichListItem(value, values, ";") + 1
1909 if (numval >= 1)
1910 PopupMenu $control, mode=numval, win=$windowname
1911 endif
1912 break
1913 case 5: // setvariable
1914 SetVariable /z $control, value= _STR:value, win=$windowname
1915 break
1916 endswitch
1917 endif
1918 endif
1919 endfor
1920
1921 return attributes
1922end
1923
1931static function /s get_panel_message(windowname)
1932 string windowname
1933
1934 if (strlen(windowname) == 0)
1935 windowname = get_default_panel_name()
1936 endif
1937 if (strlen(windowname) == 0)
1938 return ""
1939 endif
1940
1941 string nb = windowname + "#Message"
1942 notebook $nb selection={startOfFile, endOfFile}
1943 getselection notebook, $nb, 2
1944
1945 return s_selection
1946end
1947
1957static function /s set_panel_message(windowname, message)
1958 string windowname
1959 string message
1960
1961 if (strlen(windowname) == 0)
1962 windowname = get_default_panel_name()
1963 endif
1964
1965 string nb = windowname + "#Message"
1966 notebook $nb selection={startOfFile, endOfFile},text=message
1967
1968 return message
1969end
1970
1977static function /s get_panel_graphs(windowname)
1978 string windowname // panel window name
1979
1980 dfref savedf = getdatafolderdfr()
1981 if (strlen(windowname) == 0)
1982 windowname = get_default_panel_name()
1983 endif
1984 if (strlen(windowname) == 0)
1985 return ""
1986 endif
1987
1988 string logbook = GetUserData(windowname, "", "logbook")
1989 dfref df_volatile = get_elog_df(logbook, kdfVolatile)
1990 wave /t /sdfr=df_volatile attach_list
1991 wave /sdfr=df_volatile attach_sel
1992 string graphs = ""
1993 string windows = ""
1994 string graphname
1995
1996 variable n = DimSize(attach_sel, 0)
1997 variable i
1998 for (i = 0; i < n; i += 1)
1999 if (attach_sel[i][kAttachColSel] & 16)
2000 graphname = attach_list[i][kAttachColName]
2001 windows = WinList(graphname, ";", "WIN:1")
2002 if (ItemsInList(windows) == 1)
2003 graphs = AddListItem(graphname, graphs, ";", inf)
2004 endif
2005 endif
2006 endfor
2007
2008 return graphs
2009end
2010
2017static function /s set_panel_graphs(windowname, graphs)
2018 string windowname
2019 string graphs
2020
2021 if (strlen(windowname) == 0)
2022 windowname = get_default_panel_name()
2023 endif
2024 if (strlen(windowname) == 0)
2025 return ""
2026 endif
2027
2028 string logbook = GetUserData(windowname, "", "logbook")
2029 update_attach_items(logbook)
2030 dfref df_volatile = get_elog_df(logbook, kdfVolatile)
2031 wave /t /sdfr=df_volatile attach_list
2032 wave /sdfr=df_volatile attach_sel
2033
2034 variable n = DimSize(attach_sel, 0)
2035 variable i
2036 string graphname
2037 for (i = 0; i < n; i += 1)
2038 graphname = attach_list[i][kAttachColName]
2039 if (WhichListItem(graphname, graphs)>= 0)
2040 attach_sel[i][kAttachColSel] = 48
2041 else
2042 attach_sel[i][kAttachColSel] = 32
2043 endif
2044 endfor
2045end
interface for writing ELOG entries with Igor graphs as attachment.
static variable init_package()
variable elog_create_entry(string logbook, string attributes, string message, variable encoding=defaultValue, string graphs=defaultValue, variable replyto=defaultValue)
create a new entry in ELOG
static string get_default_panel_name()
static variable bp_login(WMButtonAction *ba)
static string create_graph_file(string graphname, variable fileindex)
save a graph to a temporary graphics file
static const variable kdfTemplates
static const variable kdfPersistent
static string list_logbooks(variable templates=defaultValue)
get a list of configured logbooks or templates.
static string set_panel_attributes(string windowname, string attributes, variable clear=defaultValue)
set the fields of the ELOG panel
static string format_url(string logbook)
format the URL for display to the user
variable elog_login(string logbook, string username, string password)
set username and password for login to a logbook
static variable AfterFileOpenHook(variable refNum, string file, string pathName, string type, string creator, variable kind)
initialize the package and reload preferences after an experiment is loaded.
static variable bp_attach_allnone(WMButtonAction *ba)
select/deselect all graph windows for attachment
variable pearl_elog(string logbook)
main function to initialize ELOG and to open an ELOG panel.
variable elog_config(string elog_path=defaultValue, string hostname=defaultValue, variable port=defaultValue, string subdir=defaultValue)
set global module configuration parameters
static string prepare_graph_attachments(string graphs)
prepare screenshots of graph windows for attachments
static variable parse_result()
parse the result file from an elog invokation.
static const variable kAttachColTitle
static const string elog_success_msg
static string get_panel_attributes(string windowname)
get a list of attributes from the fields of the ELOG panel.
static const string elog_parse_id
static string get_timestamp(string sep)
string PearlElogPanel(string logbook)
open a new panel for submitting data to ELOG.
static string set_panel_graphs(string windowname, string graphs)
update selection of graphs for attachment
static variable IgorQuitHook(string igorApplicationNameStr)
save preferences and recent values before Igor quits.
static variable update_buttons(string win_name, string logbook)
static const string package_path
static variable move_attach_item(string logbook, variable item, variable distance)
move an attachment item in the list of attachments
static string get_panel_message(string windowname)
get the message field of the ELOG panel
static variable bp_save_graphs(WMButtonAction *ba)
static variable init_volatile_vars()
initialize volatile variables.
static const variable kdfVolatile
static variable bp_attach_top(WMButtonAction *ba)
select top graph window for attachment
static variable load_prefs()
load persistent package data from the preferences file.
variable elog_logout(string logbook)
clear username and password of a logbook or all logbooks.
static variable update_attach_items(string logbook)
update the list of attachments
static variable bp_attach_updown(WMButtonAction *ba)
button procedure for the attachment up and down buttons
static string set_panel_message(string windowname, string message)
set the message field of the ELOG panel
variable elog_init_pearl_templates()
setup PEARL template logbooks.
static const variable kAttachColSel
variable elog_validate_attributes(string logbook, string attributes)
validate attributes
static variable bp_clear(WMButtonAction *ba)
variable elog_create_logbook(string name, string template=defaultValue)
create a new logbook.
static string prepare_command_line(string logbook)
format the ELOG command and essential address arguments.
variable elog_add_attachment(string logbook, variable id, string graphs)
add one or more graphs to an existing ELOG entry
static dfr get_elog_df(string name, variable category)
get the package, logbook, or template datafolder.
static variable save_prefs()
save persistent package data to the preferences file.
static string create_cmd_file(string cmd)
write the command line to a file.
static const string package_name
static variable bp_attach(WMButtonAction *ba)
static string get_panel_graphs(string windowname)
get the names of the graphs selected for attachment
string elog_prompt_logbook()
prompt to open or create a logbook
static string get_log_path()
static variable bp_logout(WMButtonAction *ba)
static variable cleanup_temp_files()
delete temporary files created by the ELOG module.
static const variable kAttachColName
static variable bp_submit(WMButtonAction *ba)
button procedure for the Submit and Reply buttons
static variable IgorBeforeNewHook(string igorApplicationNameStr)
save preferences and recent values before Igor opens a new experiment.
static const variable kdfRoot
static string create_message_file(string message)
save the message to a temporary text file
static variable elog_panel_hook(WMWinHookStruct *s)
variable elog_prompt_login(string logbook)
prompt the user for login to a logbook
static variable clear_package_data()
delete all package data