/* MACRO (STD) -- Macro Management */ /* MACRO (STD) -- Makros verwalten */ /* // Copyright (c) 2003-2012 Oliver Bartels F+E, Muenchen // Author: Roman Ludwig // Changes History: // rl (120427) RELEASED FOR BAE V7.8. // rl (101019) RELEASED FOR BAE V7.6. // rl (091021) RELEASED FOR BAE V7.4. // rl (081014) RELEASED FOR BAE V7.2. // rl (080922) ENHANCEMENT: // Added favorite grid selection support. // rl (071029) RELEASED FOR BAE V7.0. // rl (060829) RELEASED FOR BAE V6.8. // rl (050906) RELEASED FOR BAE V6.6. // rl (041206) ENHANCEMENT: // Added macro step roll support. // rl (030910) RELEASED FOR BAE V6.2. // rl (040811) RELEASED FOR BAE V6.4. // rl (030910) RELEASED FOR BAE V6.2. // rl (030808) ORIGINAL CODING. // // DESCRIPTION // // The macro User Language program provides functions for maintaining // and executing command macro sequences. */ // Includes #include "pop.ulh" // User Language popup utilities #include "sql.ulh" // User Language SQL utilities // Disable undo state request #pragma ULCALLERNOUNDO // Messages string UPRDIALMFUNC = M("Makros","Macros"); string UPRDIALMEDIT = M("Definition Makro '%s'","Macro Definition '%s'"); string UPRDIALMCEDIT = M("Makrokommando Nr. %d","Macro Command No %d"); string UPRMACRO = M("Makroname ?","Macro Name ?"); string UPRMACSTEPS = M("Makrokommandos :","Macro Commands :"); string UPRMACSEL = M("Makroauswahl","Macro Selection"); string UPRGRIDSEL = M("Rasterauswahl","Grid Selection"); string UPRDCOMMENT = M("Kommentar :","Comment :"); string UPRDPROGSEQ = M("Aufrufsequenz :","Calling sequence :"); string UPRDRUN = M("&Start","&Run"); string UPRDNEW = M("&Neu","&New"); string UPRDADDM = M("Menufunktion hinzufuegen","Add Menu Item"); string UPRDADDH = M("Aus Historie hinzufuegen","Add History Item(s)"); string UPRDADDG = M("Raster hinzufuegen","Add Grid"); string UPRDADDU = M("Anwenderfunktion hinzufuegen","Add User Script"); string UPRDCOPY = M("&Kopieren","&Copy"); string UPRDEDIT = M("&Aendern","&Edit"); string UPRDDEL = M("&Loeschen","&Delete"); string UPRDROLL = M("&Roll","&Roll"); string UPRDIMPORT = M("&Import","&Import"); string UPRDEXPORT = M("&Export","E&xport"); string UPRDDONE = M("&Fertig","D&one"); string UPRNEXTDIAL = M("&Weitere","&Next"); string UPRPREVDIAL = M("&Vorherige","&Previous"); string UPRSRCFILE = M("Quelldatei ? ","Source File ? "); string UPRDSTFILE = M("!Zieldatei ? ","!Destination File ? "); string UPRHISTORY = M("Kommandohistorie","Command History"); string UPRSELMITEM = M("Menupunkt selektieren!","Select Menu Item!"); string UPRSELUITEM = M("Anwenderfunktion fuer Makro '%s' ? ", "User Script for Macro '%s' ? "); string ERRDBINIT = M("SQL/DB-Datei '%s' kann nicht initialisiert werden!", "Error initialyzing SQL/DB file '%s'!"); // INI file parameter name definitions #define PAR_LISTDCNT "MACRODCNT_STD" // Max. dialog list items count // Global definitions #define UL_FAVORITE "favorite" // ULP: Favorite Management static string ULPRGDB = strgetconffilename(ULDEFPRGVNAME,ULDEFPRGFNAME,1); static string BAEMACRODB = strgetconffilename(MACROVNAME,MACROFNAME,1); static string BAEPARAMDB = strgetconffilename(PARAMVNAME,PARAMFNAME,1); int MAXMENULINE = bae_iniintval(PAR_LISTDCNT,12) /* Max. menu list length */; #define DATEXT ".dat" // Data file extension struct maccmddes { // Macro command descriptor string comm /* Macro command comment */; string progseq /* Macro command program sequence */; } maccl[] /* Macro command list */; int maccn = 0 /* Macro command count */; int curmacc = 0 /* Current macro command index */; string macl[] /* Macro name list */; int macn = 0 /* Macro name count */; int callertype=uliptype() /* Calling environment type */; string sqlcommand /* SQL command string */; // Dialog box definitions #define ED_WIDTHF 40.0 // Macro param. edit field width #define CCOLOFFFL 70.0 // Macro. list 2nd ctrl. column offset #define CCOLOFFF 20.0 // Macro. param. 2nd ctrl. column offset #define MBUTWIDTH 9.0 // Menu action button width #define MBUTXSTEP 11.0 // Menu action button x step double BUTXSTEP = bae_swconfig(3)==BAE_WinPulldwn ? 1.5 : 0.0 /* Menu action button x spacing */; #define SELBOXWIDTHFS 100.0 // Macro selection box width // SQL command definitions #define MN_SELECT "select macname from macrotab where ptyp=%d AND midx=0;" #define M_SELECT1 "select midx,comm,progseq from macrotab where " #define M_SELECT2 "ptyp=%d AND macname=%s;" #define M_SELECT M_SELECT1+M_SELECT2 #define M_CREATE1 "create table macrotab (macname string,midx integer," #define M_CREATE2 "ptyp integer,comm string,progseq string);" #define M_CREATE M_CREATE1+M_CREATE2 #define M_HELP "help macrotab;" #define M_INSERT "insert into macrotab values(%s,%d,%d,%s,%s);" #define M_DELETE "delete from macrotab where ptyp=%d AND macname=%s;" #define GN_SELECT "select name from gridtab where ptyp=%d;" // Main program void main() { string dbname /* Database file name */; string macname /* Macro name */; double cy /* Current y value */; double butx /* Current button position */; double dialwidth /* Dialog box width */; double dialheight /* Dialog box height */; double baseheight /* Dialog box base height */; int lbidx /* List box item index */; int repflag = 1 /* Repeat flag */; int i /* Loop control variable */; // Create/init database file dbinit(BAEMACRODB); // Check if dialog box support if (bae_dialclr()) { if ((macname=bae_readedittext(UPRMACRO,"",MAXTEXTLEN))=="" || macname==UINPOPABORT) error_abort(); // Swallow right mouse button activation notification if (macname!="!") { runmacro(macname); exit(0); } } baseheight=DIAL_TOPMARG+2.0*DIAL_SEPVSTEP+DIAL_BUTVSTEP; // Perform the input loop do { macn=0; sprintf(sqlcommand,MN_SELECT,callertype); sqlcmd(BAEMACRODB,sqlcommand,macselfunc); bae_dialclr(); dial_getboxsizemin(5012,dialwidth,dialheight, DIAL_LEFTMARG+SELBOXWIDTHFS+DIAL_RIGHTSMARG,baseheight+16.0, DIAL_LEFTMARG+90.0,baseheight+2.0); cy=DIAL_TOPMARG; // Store list box lbidx=bae_dialadvcontrol(PA_LB|PA_OKSEL|PA_HSCROLL|PA_HBRDREL, (-1),0,(-1),0.0,0.0,0.0,"",0, DIAL_LEFTMARG,cy,DIAL_RIGHTSMARG,dialheight-baseheight,""); // Store list box entries for (i=0;i=0 && i=0 && i0;i--) if (macl[i-1]>macname) macl[i]=macl[i-1]; if (macl[i]!=macname) { macl[i]=macname; macn++; } // Edit macro data editmacro(macname); break; // Copy macro case 3 : bae_dialgetdata(lbidx,i,0.0,""); if (i<0 || i>=macn) break; // Get macro data readmacro(BAEMACRODB,macl[i]); if ((macname=bae_readedittext(UPRMACRO, macl[i],MAXTEXTLEN))=="" || macname==UINPOPABORT) break; macl[macn]=""; for (i=macn;i>0;i--) if (macl[i-1]>macname) macl[i]=macl[i-1]; if (macl[i]!=macname) { macl[i]=macname; macn++; } // Store macro command data writemacro(BAEMACRODB,macname); break; // Delete macro case 4 : bae_dialgetdata(lbidx,i,0.0,""); if (i<0 || i>=macn) break; sprintf(sqlcommand,M_DELETE,callertype, sql_quotestr(macl[i])); sqlcmd(BAEMACRODB,sqlcommand,NULL); macn--; for (i++;i=macn) break; // Select the destination file if (bae_askfilename(dbname,DATEXT,UPRDSTFILE) || dbname=="") error_abort(); // Init. database dbinit(dbname); // Get macro data readmacro(BAEMACRODB,macl[i]); // Store macro command data writemacro(dbname,macl[i]); break; // Resize case (-2) : break; default : repflag=0; } // Stop if no further repeat requests } while (repflag); } void dbinit(string dbname) /* // Initialize database // Parameter : // string dbname : Database name */ { // Create/init database file if (sqlinit(dbname,0)==(-1) && sqlinit(dbname,1)==(-1)) // SQL/DB creation error errormsg(ERRDBINIT,dbname); // Create table in database if (sqlcmd(bae_planfname(),M_HELP,NULL)!=0) if (sqlcmd(dbname,M_CREATE,NULL)) // SQL/DB error (ignore table already defined error) sql_dberror(25); } void readmacro(string dbname,string macname) /* // Read macro command data // Parameter : // string dbname : Database name // string macname : Macro name */ { // Get macro data maccn=0; sprintf(sqlcommand,M_SELECT,callertype,sql_quotestr(macname)); if (sqlcmd(dbname,sqlcommand,maccmdselfunc)) // SQL/DB error sql_dberror(0); } void writemacro(string dbname,string macname) /* // Store macro command data to database // Parameter : // string dbname : Database name // string macname : Macro name */ { int i /* Loop control variable */; // Delete the old macro data sprintf(sqlcommand,M_DELETE,callertype,sql_quotestr(macname)); if (sqlcmd(dbname,sqlcommand,NULL)!=0) // SQL/DB error sql_dberror(29); // Store new macro command data for (i=0;i0;i--) if (macl[i-1]>dstr) macl[i]=macl[i-1]; else break; macl[i]=dstr; macn++; // Return without errors return(0); } static int maccmdselfunc(string dstr,int dint,double ddbl, int dval,int dtype,string dtable,string dfield,int didx) /* // Macro selection callback function // Return value : // zero if done or (-1) on data error // Parameters : // string dstr : String/Date data // int dint : Integer/Boolean data // double ddbl : Float data // int dval : Data valid flag // int dtype : Data type // string dtable : Data table name // string dfield : Data field name // int didx : Data output field index */ { // Store the current entry switch (didx) { // Index case 1 : curmacc=dint; if (curmacc>=maccn) maccn=curmacc+1; break; // Comment case 2 : maccl[curmacc].comm=dstr; break; // Program sequence case 3 : maccl[curmacc].progseq=dstr; break; } // Return without errors return(0); } void editmacro(string macname) /* // Edit macro command data, store result to database // Parameter : // string macname : Macro name */ { struct maccmddes macbuf /* Macro buffer */; string msg /* Message string */; double butx /* Dialog box button x coordinate */; double cy /* Dialog box current y coordinate */; double dialwidth /* Dialog box width */; double dialheight /* Dialog box height */; double baseheight /* Dialog box base height */; int lbidx = (-1) /* List box item index */; int dialres /* Dialog box result buffer */; int repflag /* Repeat flag */; int i, j /* Loop control variables */; // Get macro data readmacro(BAEMACRODB,macname); baseheight=DIAL_TOPMARG+DIAL_CTRVSTEP+DIAL_SEPVSTEP+DIAL_BUTVSTEP+0.2; // Perform input loop do { bae_dialclr(); dial_getboxsizemin(5013,dialwidth,dialheight, DIAL_LEFTMARG+SELBOXWIDTHFS+DIAL_RIGHTSMARG,baseheight+16.0, DIAL_LEFTMARG+105.0,baseheight+2.0); repflag=0; butx=DIAL_LEFTMARG; cy=DIAL_TOPMARG; dial_label(0.0,cy,UPRMACSTEPS); cy+=DIAL_CTRVSTEP; // Store list box lbidx=bae_dialadvcontrol(PA_LB|PA_HSCROLL|PA_OKSEL|PA_HBRDREL, (-1),0,(-1),0.0,0.0,0.0,"",0, DIAL_LEFTMARG,cy,DIAL_RIGHTSMARG,dialheight-baseheight,""); // Store list box entries for (i=0;i=0 && i=0 && i=0 && ii;j--) maccl[j]=maccl[j-1]; maccl[i]=macbuf; } repflag=1; break; // Done case 5 : break; // Add user script case 6 : repflag=1; sprintf(msg,UPRSELUITEM,macname); if (bae_askddbename( maccl[maccn].progseq,ULPRGDB,DDBCLUL,msg)) break; maccl[maccn].comm=maccl[maccn].progseq; maccn++; break; // Add favorite grid selection case 7 : repflag=1; // Get grid entries macn=0; sprintf(sqlcommand,GN_SELECT,callertype); if (sqlcmd(BAEPARAMDB,sqlcommand,macselfunc)!=0) // SQL/DB error sql_dberror(27); bae_setintpar(16,5048); if ((maccl[maccn].comm=popupmenu(1,UPRGRIDSEL,macl,0, macl,macn,UINPOPABORT,0,1,1,macn+2,0,0,""))=="" || maccl[maccn].comm==UINPOPABORT) error_abort(); maccl[maccn].progseq=UL_FAVORITE+ ":\"gridset\":\""+maccl[maccn].comm+"\""; maccn++; break; // Resize case (-2) : repflag=1; break; // Quit/Abort case (-1) : default : return; } } // Stop if no further repeat requests while (repflag); // Store new macro command data writemacro(BAEMACRODB,macname); } void historyitems() /* // Add selected history items to command list */ { double cy /* Dialog box current y coordinate */; string cmddl[] /* Command display name list */; string cmdsl[] /* Command sequence list */; int cmdfl[] /* Command flag list */; int cmdn = 0 /* Command count */; int hcidxl[] /* History command toggle indices */; int hcidx = 0 /* History command index */; int hsidx = 0 /* History start index */; int repflag = 1 /* Repeat flag */; int i /* Loop control variable */; // Get history commands for (i=49;i>=0;i--) if (bae_getcmdbuf(i,cmdsl[cmdn],cmddl[cmdn])==1) { cmdfl[cmdn]=0; cmdn++; } hsidx= cmdn>MAXMENULINE ? cmdn-MAXMENULINE : 0; do { // Create the dialog box controls bae_dialclr(); cy=DIAL_TOPMARG; // Build the history command menu for (i=0;i=cmdn) break; // Store toggle box hcidxl[i]=bae_dialaddcontrol(PA_TOGGLE, 0,0,cmdfl[hcidx],0.0,0.0,0.0,"", 0,DIAL_LEFTMARG,cy,0.0,cmddl[hcidx]); cy+=DIAL_BUTVSTEP; } // Store the OK and abort button with seperator cy+=DIAL_SEPVSTEP; bae_dialaddcontrol(PA_OK, 0,0,0,0.0,0.0,0.0,"",0,DIAL_LEFTMARG,cy,0.0,""); bae_dialaddcontrol(PA_ABORT, 0,0,0,0.0,0.0,0.0,"",0,DIAL_LEFTMARG+5.0,cy,0.0,""); if (hsidx) bae_dialaddcontrol(PA_ACT,0,1,0,0.0,0.0,0.0, "",0,DIAL_LEFTMARG+24.0,cy,0.0,UPRPREVDIAL); if (hsidx<(cmdn-MAXMENULINE)) bae_dialaddcontrol(PA_ACT,0,2,0,0.0,0.0,0.0, "",0,DIAL_LEFTMARG+32.0,cy,0.0,UPRNEXTDIAL); bae_dialaddcontrol(PA_HSEP|PA_HBRDREL,0,0,0,0.0,0.0,0.0,"",0, DIAL_LEFTMARG,cy-DIAL_SEPVSTEP,DIAL_RIGHTSMARG,""); // Call the dialog function bae_setintpar(16,5014); switch (bae_dialaskparams(UPRHISTORY,0, DIAL_LEFTMARG+78.3+DIAL_RIGHTSMARG,cy+1.6)) { // Done case 0 : // Fetch current history flags for (i=0;i(cmdn-MAXMENULINE)) hsidx=cmdn-MAXMENULINE; break; default : return; } } // Stop if no further repeat requests while (repflag); } void editcommand(int maccidx) /* // Edit macro command data // Parameter : // int maccidx : Macro command index */ { string msg /* Message string */; double cy /* Dialog box current y coordinate */; int cmidx /* Comment parameter index */; int psidx /* Prog. sequence parameter index */; bae_dialclr(); // Init. the y coordinate cy=DIAL_TOPMARG; dial_label(0.0,cy,UPRDCOMMENT); cmidx=dial_string(maccl[maccidx].comm,200,CCOLOFFF,cy); dial_label(0.0,cy,UPRDPROGSEQ); psidx=dial_string(maccl[maccidx].progseq,200,CCOLOFFF,cy); // Store the OK and abort button with seperator dial_hsep(cy); dial_okabort(cy); // Call the dialog function sprintf(msg,UPRDIALMCEDIT,maccidx+1); bae_setintpar(16,5015); switch (bae_dialaskparams(msg,0,DIAL_LEFTMARG+CCOLOFFF+ ED_WIDTHF+DIAL_RIGHTSMARG,cy)) { case 0 : bae_dialgetdata(cmidx,0,0.0,maccl[maccidx].comm); bae_dialgetdata(psidx,0,0.0,maccl[maccidx].progseq); break; // Fail/abort case (-1) : default : } // Return without errors return; } void runmacro(string macname) /* // Run macro commands // Parameter : // string macname : Macro name */ { int i /* Loop control variable */; // Get macro data readmacro(BAEMACRODB,macname); // Save current state for undo bae_callmenu(MNU_BAESAVESTATE); // Perform macro steps for (i=0;i