#pragma rtGlobals=1 // Use modern global access method. #pragma version = 1.00 //#include "JTG_Utilities Option Panel" version >= 1.00 Menu "Option Panels" "Progress Meter Options" "--" End //################################################################ // Directory of JTG_Utilities Progress Meter //################################################################ //****************************************************************************************** // Progress Meter Functions //****************************************************************************************** // Function/S ProgressMeterCreate(MeterName, MeterTitle, ValMin, ValMax, // Increment, ProgMeterType) // Function ProgressMeterDestroy(MeterName) // Function ProgressMeterUpdate(MeterName, Value) // Routines to create, update and destroy a little progress meter. //****************************************************************************************** // VerifyName //****************************************************************************************** // Function/S VerifyName(MeterName) // Used with routines to display progress meters. Ensures that name of meter // is legal and unique. It also makes certain that the name will be unique // name for a window. //****************************************************************************************** // ProgressMeterOptions //****************************************************************************************** // Panel for setting progress meter options // ckbShowProgress -- show or don't show meter // popMeterType -- type of meter //*****************************************************************************************************************// //***** Function ProgressMeterInitializeOptions *****// //*****************************************************************************************************************// // 7/09/2012 // // --This function will check for the existance of the Progress Meter options folder. This folder is // // needed because the user can call the Progress Meter create function telling it to use // // settings defined with its options panel. Options are whether to show Progress Meter and the // // type of panel to display. // // --If the options folder doesn't exist, the function will try to create it set the parameters to // // default values. // // --It the folder exists, the function will try to ensure that parameters are within correct range. // //*****************************************************************************************************************// // --Called by: ProgressMeterCreate // // --Calls: InitializePanel // //*****************************************************************************************************************// //################################################################ // End of Directory of JTG_Utilities //################################################################ //****************************************************************************************** // Function ProgressMeter routines //****************************************************************************************** // Routines to create, update and destroy a little progress meter. This uses // igor drawing commands in a panel. Data is normalized to a 0 to 100 unit // scale and meter is updated every 5 units (20 increments). // Truncates name to 40 characters and ensures that name is igor legal. Always // use return value (string) from ProgressMeterCreate as MeterName parameter // for ProgressMeterUpdate and ProgressMeterDestroy. // Checks ckbShowProgress to see if progress meters are to be displayed. // Programmer can select meter type or let it be selected by options panel (with type 0) // type 1: thermometer, type 2: digital (numeric), type 3: clock. // Update Meter routine returns "100" if named meter doesn't exist. // // 2/13/2001 ProgressMeterCreate checks for other progress meters (by checking // ProgressMeter folder) and uses AutoPositionWindow operation to keep from // overlapping most recent Meter panel. // 07/09/2012 // Adding code to check for existance of progress meter options folder and // variables. Attempts to create folder and variables if they don't exist. This should // fix problem of code executing endlessly because the prog meter code would hang. // 07/10/2012 // Moved initialization code to its own function. //****************************************************************************************** //------------------------------ProgressMeterCreate------------------------------------- Function/S ProgressMeterCreate(MeterName, MeterTitle, ValMin, ValMax, Increment, ProgMeterType) String MeterName String MeterTitle Variable ValMin Variable ValMax Variable Increment Variable ProgMeterType //variables for initializing options folder String VarList String StrList String sWaveList VarList = "ckbShowProgress:1; popMeterType:3" StrList = "" sWaveList = "" String OptionsPath = "root:Packages:OptionPanels:ProgressMeter:" String MeterFolder = "root:Packages:ProgressMeter:" If(!DataFolderExists("root:Packages:ProgressMeter:")) If(!DataFolderExists("root:Packages:")) NewDataFolder root:Packages NewDataFolder root:Packages:ProgressMeter Else NewDataFolder root:Packages:ProgressMeter EndIf EndIf //check that options folder exists & has been initialized if(ProgressMeterInitializeOptions(OptionsPath, VarList, StrList, sWaveList) == 0) print "There is a problem with the Progress Meter options folder." print "Progress Meter will not be shown." return "" //failed endif NVAR /Z ckbShowProgress = $(OptionsPath + "ckbShowProgress") NVAR /Z popMeterType = $(OptionsPath + "popMeterType") ////07/09/2012 ////*****start of prog meter option folder check ////check for existance/initialization of panel options ////the following are use to ensure that the control pane datafolder and variables exist // String VarList // String StrList // String sWaveList // // VarList = "ckbShowProgress:1; popMeterType:3" // StrList = "" // sWaveList = "" // ////call initialize panel if data folder doesn't exist. This will create data folders and ////create global strings and variables and waves. // If(DataFolderExists(OptionsPath)) // //check for variables // if(NVAR_Exists(ckbShowProgress) == 0) //doesn't exist // Variable/G ckbShowProgress = 1 //create and initialize // endif // if(NVAR_Exists(popMeterType) == 0) //doesn't exist // Variable/G popMeterType = 1 //create and initialize // elseif((popMeterType > 3) || (popMeterType < 1)) //must be integer between 1 & 3 // popMeterType = 1 //default meter type // endif // else //data folder doesn't exist, so create it and initialize // //if InitializePanel encounters an error it will return 0 and try to set error information // //so make a call to UserDefinedErrorHandler, to inform user of problem // If(!InitializePanel("ProgressMeter", VarList, StrList, sWaveList)) // UserDefinedErrorHandler(0,"", "") // return "" //error // EndIf // //the following variables were created by InitializePlane, so get reference to them now // NVAR ckbShowProgress = $(OptionsPath + "ckbShowProgress") // NVAR popMeterType = $(OptionsPath + "popMeterType") // Endif ////*****end of prog meter option folder check //Get name of highest numbered meter panel String RefMeter = "" String FoldName = "" Variable i Do FoldName = GetIndexedObjName(MeterFolder, 4, i) If(strlen(FoldName) == 0) break endif //check if FolderName is also a panel name if(WinType(FoldName) == 7) RefMeter = FoldName endif print RefMeter i += 1 While(1) // print "progressmeterCreate" If (!ckbShowProgress) //option controls showing of progress meter return MeterName EndIf Variable Xcenter Variable Ycenter Variable Xdist Variable Ydist Variable XOval1 Variable XOval2 Variable YOval1 Variable YOval2 Variable Radius Variable XLine2 Variable YLine2 //check name of meter; it must be legal since it is used for a folder and window String NewMeterName MeterName = VerifyName(MeterName) String MeterPath = MeterFolder + MeterName String savedDataFolder = GetDataFolder(1) // save NewDataFolder/O/S $MeterPath //create or overwrite folder & switch to it Variable/G MeterMin = ValMin Variable/G MeterMax = ValMax Variable/G MeterSpan = ValMax - ValMin Variable/G MeterStep = 5 //Increment Variable/G MeterValue = 0 Variable/G MeterValuePrev = 0 Variable/G MeterType //programmer can select meter type or let it be selected by options panel (with type 0) //ensure that ProgMeterType is positive integer between 1 and 3 (or max number of types) ProgMeterType = Max(min(floor(ProgMeterType),3),0) // print progmeterType, "progmeterType" If (!ProgMeterType) MeterType = popMeterType Else MeterType = ProgMeterType EndIf // print meterType, "meterType" If(strlen(MeterTitle) > 20) MeterTitle = MeterTitle[0,20] EndIf Do If (MeterType == 1) //create thermometer progress meter NewPanel /W=(170,170,430,207)/K=1 as "Progress" //K=1 kill with no dialog DoWindow/C $MeterName SetDrawLayer ProgBack DrawRect 18,4,244,15 SetDrawEnv textrot=0, textxjust=1, textyjust=0, fsize=12, fstyle=0 DrawText 131,35,MeterTitle break EndIf If (MeterType == 2) //create digital progress meter NewPanel /K=1 /W=(270.0,70,400,170.0) as "Progress" DoWindow/C $MeterName Xcenter = 65 Ycenter = 40 Xdist = 45 Ydist = 30 XOval1 = Xcenter - Xdist XOval2 = Xcenter + Xdist YOval1 = Ycenter - Ydist YOval2 = Ycenter + Ydist SetDrawEnv xcoord=abs, ycoord=abs SetDrawLayer ProgBack SetDrawEnv xcoord=abs, ycoord=abs SetDrawEnv fillpat= 0,linefgc= (0,0,0)//,fillbgc= (65535,65535,65535) DrawRect XOval1,YOval1,XOval2,YOval2 SetDrawEnv textrot = 0, textxjust=1, textyjust=1, xcoord=abs, ycoord=abs, fsize=10,fstyle=0 SetDrawEnv textrgb= (0,0,0),xcoord=abs, ycoord=abs DrawText Xcenter,80,MeterTitle SetDrawLayer/K UserBack SetDrawEnv textrot = 0, textxjust=1, textyjust=1, xcoord=abs, ycoord=abs, fsize=30,fstyle=0 SetDrawEnv textrgb= (0,0,0),xcoord=abs, ycoord=abs DrawText Xcenter,Ycenter,"0%" break EndIf If (MeterType == 3) //create clock progress meter NewPanel /K=1 /W=(270.0,70,400,170.0) as "Progress" //K=1 kill with no dialog DoWindow/C $MeterName Xcenter = 65 Ycenter = 40 Radius = 30 XOval1 = Xcenter - Radius XOval2 = Xcenter + Radius YOval1 = Ycenter - Radius YOval2 = Ycenter + Radius SetDrawEnv xcoord=abs, ycoord=abs SetDrawLayer ProgBack SetDrawEnv xcoord=abs, ycoord=abs SetDrawEnv fillpat= 0,linefgc= (0,0,0)//,fillbgc= (65535,65535,65535) DrawOval XOval1,YOval1,XOval2,YOval2 SetDrawEnv linefgc= (0,0,0) DrawLine Xcenter +25,Ycenter,Xcenter +30,Ycenter SetDrawEnv linefgc= (0,0,0) DrawLine Xcenter -25,Ycenter,Xcenter -30,Ycenter SetDrawEnv linefgc= (0,0,0) DrawLine Xcenter,Ycenter +25,Xcenter,Ycenter +30 SetDrawEnv linefgc= (65280,0,0) DrawLine Xcenter,Ycenter -25, Xcenter,Ycenter -30 SetDrawEnv textrot = 0, textxjust=1, textyjust=1, xcoord=abs, ycoord=abs, fsize=10,fstyle=0 SetDrawEnv textrgb= (0,0,0),xcoord=abs, ycoord=abs DrawText Xcenter,80,MeterTitle //draw initial clock line to zero position (12 oclock) XLine2 = Xcenter + Radius * cos( PI * (-90) / 180) YLine2 = Ycenter + Radius * sin( PI * (-90) / 180) SetDrawLayer/K UserBack SetDrawEnv linefgc= (0,0,0) DrawLine Xcenter,Ycenter,XLine2,YLine2 break EndIf While(1) //use AutopostionWindow operation to keep progressmeter window from sitting on to of another if(strlen(RefMeter)) AutopositionWindow/E/M=0/R=$RefMeter endif //Progress meter setup SetDataFolder savedDataFolder // and restore to initial folder Return MeterName End //------------------------------ProgressMeterCreate------------------------------------- //------------------------------ProgressMeterUpdate------------------------------------- Function ProgressMeterUpdate(MeterName, Value) String MeterName Variable Value String OptionsPath = "root:Packages:OptionPanels:ProgressMeter:" String MeterFolder = "root:Packages:ProgressMeter:" NVAR ckbShowProgress = $(OptionsPath + "ckbShowProgress") If (!ckbShowProgress) //option controls showing of progress meter return 0 EndIf DoWindow $MeterName //check to see if a window named NewName exists If(!V_Flag) //V_Flag = 1 if meter exists return 100 //exit routine if 0, return error EndIf String MeterPath = MeterFolder + MeterName String savedDataFolder = GetDataFolder(1) // save SetDataFolder MeterPath // and restore to initial folder NVAR MeterMin = MeterMin NVAR MeterMax = MeterMax NVAR MeterSpan = MeterSpan NVAR MeterStep = MeterStep NVAR MeterValuePrev = MeterValuePrev NVAR MeterType = MeterType Variable NewValue Variable inc Variable BulletStart Variable BulletEnd Variable Xcenter = 65 Variable Ycenter = 40 Variable Radius =30 String DispValue Variable XLine2 Variable YLine2 DoWindow /F $MeterName SetDrawLayer ProgBack Do If (MeterType == 1) //create thermometer progress meter NewValue = floor(100 * (Value - MeterMin) / (MeterSpan * 5)) If (NewValue > MeterValuePrev ) inc = MeterValuePrev + 1 Do If(inc > 20) DoWindow /T $MeterName, "Complete" break EndIf BulletStart = 11 + inc * 11 BulletEnd = 16 + inc * 11 SetDrawEnv linethick= 5,linefgc= (0,0,65280) DrawLine BulletStart,9,BulletEnd,9 inc += 1 While (inc <= NewValue) MeterValuePrev = NewValue EndIf break EndIf If (MeterType == 2) //create digital progress meter NewValue = floor(100 * (Value - MeterMin) / (MeterSpan)) If (NewValue > MeterValuePrev ) DispValue = num2str(NewValue) + "%" SetDrawLayer/K UserBack SetDrawEnv textrot = 0, textxjust=1, textyjust=1, xcoord=abs, ycoord=abs, fsize=30,fstyle=0 SetDrawEnv textrgb= (0,0,0),xcoord=abs, ycoord=abs DrawText Xcenter,Ycenter,DispValue MeterValuePrev = NewValue EndIf break EndIf If (MeterType == 3) //create clock progress meter NewValue = floor(360 * (Value - MeterMin) / (MeterSpan)) If (NewValue > MeterValuePrev ) NewValue -= 90 XLine2 = Xcenter + Radius * cos( PI * NewValue / 180) YLine2 = Ycenter + Radius * sin( PI * NewValue / 180) SetDrawLayer/K UserBack SetDrawEnv linefgc= (0,0,0) DrawLine Xcenter,Ycenter,XLine2,YLine2 MeterValuePrev = NewValue EndIf break EndIf While(1) //Progress meter update //End of progress meter update SetDataFolder savedDataFolder // and restore to initial folder End //------------------------------ProgressMeterUpdate------------------------------------- //------------------------------ProgressMeterDestroy------------------------------------- Function ProgressMeterDestroy(MeterName) String MeterName String OptionsPath = "root:Packages:OptionPanels:ProgressMeter:" String MeterFolder = "root:Packages:ProgressMeter:" NVAR ckbShowProgress = $(OptionsPath + "ckbShowProgress") If (!ckbShowProgress) //option controls showing of progress meter return 0 EndIf String MeterPath = MeterFolder + MeterName //Kill progress meter DoWindow /K $MeterName KillDataFolder MeterPath //End of Kill progress meter End //------------------------------ProgressMeterDestroy------------------------------------- //****************************************************************************************** // End ProgressMeter routines //****************************************************************************************** //*****************************************************************************************************************// //***** Function ProgressMeterInitializeOptions *****// //*****************************************************************************************************************// // 7/09/2012 // // --This function will check for the existance of the Progress Meter options folder. This folder is // // needed because the user can call the Progress Meter create function telling it to use // // settings defined with its options panel. Options are whether to show Progress Meter and the // // type of panel to display. // // --If the options folder doesn't exist, the function will try to create it set the parameters to // // default values. // // --It the folder exists, the function will try to ensure that parameters are within correct range. // //*****************************************************************************************************************// // --Called by: ProgressMeterCreate // // --Calls: InitializePanel // //*****************************************************************************************************************// Function ProgressMeterInitializeOptions(OptionsPath, VarList, StrList, sWaveList) String VarList String StrList String sWaveList String OptionsPath NVAR /Z ckbShowProgress = $(OptionsPath + "ckbShowProgress") NVAR /Z popMeterType = $(OptionsPath + "popMeterType") //call initialize panel if data folder doesn't exist. This will create data folders and //create global strings and variables and waves. If(DataFolderExists(OptionsPath)) //folder exists //check for variables if(NVAR_Exists(ckbShowProgress) == 0) //doesn't exist Variable/G ckbShowProgress = 1 //create and initialize endif if(NVAR_Exists(popMeterType) == 0) //doesn't exist Variable/G popMeterType = 1 //create and initialize elseif((popMeterType > 3) || (popMeterType < 1)) //must be integer between 1 & 3 popMeterType = 1 //default meter type endif else //data folder doesn't exist, so create it and initialize //if InitializePanel encounters an error it will return 0 and try to set error information //so make a call to UserDefinedErrorHandler, to inform user of problem If(!InitializePanel("ProgressMeter", VarList, StrList, sWaveList)) UserDefinedErrorHandler(0,"", "") return 0 //error EndIf Endif return 1 //all is well End //*****************************************************************************************************************// //***** End of ProgressMeterInitializeOptions *****// //*****************************************************************************************************************// //****************************************************************************************** // VerifyName routines //****************************************************************************************** // used with routines to display progress meters. Ensures that name of meter // is legal (only alpha-numeric characters or underscore) and unique (no meter // folders or windows with same name). Returns new valid name if initial name // is invalid. If fed null string ("") returns name of form "ProgMeterxx", where // "xx" are digits, as in "ProgMeter0". // Like the progress meter routines, this routine operates in the data folder: // "root:imagepackage:meters:" It uses igor functions (CleanupName and // UniqueName) to produce a name which is legal for igor objects and which // is unique in the target data folder. It also makes certain that the name will // be unique name for a window, since the progress meter routines create a // panel window. //****************************************************************************************** Function/S VerifyName(MeterName) String MeterName String NewName String NamePrefix Variable LegalNameLength Variable StartingSuffix = 0 String StrSuffix String MeterFolder = "root:Packages:ProgressMeter:" String savedDataFolder = GetDataFolder(1) // save SetDataFolder MeterFolder If(stringmatch(MeterName, "")) NewName = "ProgMeter" //Default Name prefix Else NewName = CleanupName(MeterName, 0) //returns legal name: char, num, underscore EndIf LegalNameLength = strlen(NewName) NamePrefix = NewName Do NewName = UniqueName(NamePrefix, 11, StartingSuffix) DoWindow $NewName //check to see if a window named NewName exists If(!V_Flag) //V_Flag = 1 if win of same name exists break //exit routine if 0 EndIf //name is not unique for windows, get suffix and increment by 1. use this for starting suffix again StrSuffix = NewName[LegalNameLength,strlen(NewName)] StartingSuffix = str2num(StrSuffix) + 1 // print StartingSuffix While (1) SetDataFolder savedDataFolder // and restore return NewName End //****************************************************************************************** // End VerifyName routines //****************************************************************************************** //****************************************************************************************** // Options panel functions //****************************************************************************************** Function ProgressMeterOptions() : Panel //the following are use to ensure that the control pane datafolder and variables exist String VarList String StrList String WavList VarList = "ckbShowProgress:1; popMeterType:3" StrList = "" WavList = "" //call initialize panel if data folder doesn't exist. This will create data folders and //create global strings and variables and waves. If(!DataFolderExists("root:Packages:OptionPanels:ProgressMeter")) //if InitializePanel encounters an error it will return 0 and try to set error information //so make a call to UserDefinedErrorHandler, to inform user of problem If(!InitializePanel("ProgressMeter", VarList, StrList, WavList)) UserDefinedErrorHandler(0,"", "") return 0 EndIf EndIf //Check if Options Panel already is open... DoWindow ProgressMeter // NVAR V_flag = V_flag If (V_flag == 1) //window exists print "ProgressMeter Options Panel already open" DoWindow /F ProgressMeter return 0 EndIf //initialize datafolder which holds variables set in this panel. //You must feed InitializePanel // InitializePanel PauseUpdate // building window... NewPanel /K=1 /W=(260.25,107,560.25,307.25) as "Progress Meter Options" DoWindow/C ProgressMeter SetDrawEnv fillpat= 0,fillfgc= (34816,34816,34816) SetDrawLayer ProgBack SetDrawEnv fillpat= 0,fillfgc= (34816,34816,34816) DrawRect 4,49,217,102 CheckBox ckbShowProgress,pos={10,50},size={200,20},title="Show Progress Meters" CheckBox ckbShowProgress,help={"Permit display of progress meters."},value=0 PopupMenu popMeterType title="Meter Type" PopupMenu popMeterType value="Thermometer;Digital ;Clock " PopupMenu popMeterType, pos={10,75},size={200,20}, help={"Select default appearance of progress meters."} Button btnCancel,pos={130,150},size={50,20},proc=CancelPanelChanges,title="Cancel" Button btnCancel,help={"Cancel changes and exit."} Button btnApply,pos={10,150},size={50,20},proc=SavePanelSettings,title="Apply" Button btnApply,help={"Apply current settings and exit."} Button btnReset,pos={70,150},size={50,20},proc=RetrievePanelSettings,title="Reset" Button btnReset,help={"Reset options to original settings."} RetrievePanelSettings("ImagePlateOptions") //set hook function for window, SetWindow ProgressMeter, hook = OptionsHookFcn //call DeleteGraphDirectory when graph is killed End