;================================================================================================= ; Copyright 2007 Craig Edward Given ;================================================================================================= ; 04/03/2007 ; This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License ; For more information visit http://creativecommons.org/licenses/by-nc-sa/3.0/us/ ;================================================================================================= ; PURPOSE: Import CSV files containing waypoints (latitude, longitude, name, etc.) into MSST (Microsoft's ; Streets & Trips 2005) mapping program. Each CSV is a dataset that is represented by a custom ; pushpin graphic that is also imported by this program. This program requires a parameter file ; that contains the following information in this format: ; ; {CSVfile} ; {BMPfile} ; ; Here is an example: ; ; C:\GPS\PushPins\Benchmark.CSV ; C:\GPS\Pushpins\Icons\Benchmark.bmp ; C:\GPS\PushPins\Multicache.CSV ; C:\GPS\Pushpins\Icons\Multicache.bmp ; C:\GPS\PushPins\Archived.CSV ; C:\GPS\Pushpins\Icons\Archived.bmp ; ; There can be multiple files imported, each on its own line. Any line beginning with a # will ; be ignored. The sequence may be important if your data sets have overlapping waypoints. The last ; data set imported will have its icon on top. ; ;================================================================================================= ; Version History ;================================================================================================= ; 02/20/2005 1.00 ; 03/22/2005 1.01 ; Add optional command line parameter for icon offset, so if a user already has 2 ; custom push pin graphics imported into a map, then they should specify 2 as the ; next command line parameter. ; Also added a file open dialog prompt if no parameters are specified or if the ; file specified does not exist. ; 04/29/2005 1.02 ; Added balloon field activation for new fields sent by new GSAK 5.5.0.10 ; 05/06/2005 1.03 ; Time delay for loading and changing of entire data sets is now calculated instead ; of being a hard coded delay. Small data sets will not be unnecessarily cause delays ; and larger datasets will have enough time to process. Eventually the delay factor ; will be parameterized so that users with slower machines can adjust this to their ; particular environment. ; Add third parameter to control file that controls balloon fields. Each character ; in the third field is either Y or N and determines if a balloon field should be ; shown. If the third parameter is missing then no balloon field processing ; will take place. The parameter must have the exact same number of characters ; as the balloon fields available. Currently 8 being sent by GSAK/GPSBabel, so the ; most common parameter will be YYYNYYYY since this turns off the URL (it isn't ; helpful information for most people, it takes up valuable balloon space -- which ; can force some information out-of-bounds [not visible], and Ctrl-click will still ; open the cache page whether it is displayed or not. NOTE: this program assumes that the ; FIRST TWO fields [latitude and longitude] are ALREADY turned on! This works fine ; for GSAK 5.5.1 and MSST 2005 but different versions may work differently. ; If this should occur to you, use the opposite values than expected to get the ; desired results. ; Add INI file support to allow parameters to be passed by a configuration file. ; Command line parameters can also be used simultaneously and they take precedence ; over duplicate settings in the INI file. This program will prompt the user for ; any pieces that can't be defaulted and are not supplied by either method. The ; INI file must be named PUSHPINS.INI and located in the same directory as the ; PUSHPINS.EXE file. ; 08/04/205 1.04 ; Added FLAVOR parameter (command line or INI file). The European version of MSST is ; named "AutoRoute" so the window activation didn't work for them. Now they can ; override the default with this parameter so the right window is activated. ; ; If you use this parameter you must be very precise. The name ; must be what appears in the upper left of the program's ; window. You should only specify the core name of the window ; -- just enough so that it's uniquely identifiable. E.g., ; the default window name for MSST is: ; ; "Map - Microsoft Streets & Trips" ; ; So all you'd really need is the piece "Streets & Trips" as ; the window name. BUT, the portion that you do specify must ; match exactly! Spelling, spacing, punctuation, and upper/lower ; case are all critical! "Streets and Trips" would be WRONG, ; since it is "&" not "and" that appears in the program's title. ; Since the default program name contains spaces, we must ; enclose the name in double quotes. Useable examples for both ; ; FLAVOR="Streets & Trips" ; FLAVOR="AutoRoute" ; 10/31/2006 1.05 ; Added TYPINGSPEED to allow delay between keystrokes in the SENDKEY commands ;################################################################################################# ;################################################################################################# ;================================================================================================= #DefineFunction stripquotes( thisstring) ;================================================================================================= ; Remove leading and trailing quotes IF StrSub( thisstring, 1, 1) == '"' || StrSub( thisstring, 1, 1) == "'" thisstring = StrSub( thisstring, 2, -1) ENDIF IF StrSub( thisstring, StrLen( thisstring), 1) == '"' || StrSub( thisstring, StrLen( thisstring), 1) == "'" thisstring = StrSub( thisstring, 1, StrLen( thisstring) -1) ENDIF RETURN StrTrim( thisstring) #EndFunction ;################################################################################################# ;################################################################################################# ; :main ;################################################################################################# ;################################################################################################# datalist = "" ; List of data files to be imported iconoffset = 0 ; How many custom pushping graphics are already in the map? shortpause = 1 ; Delay for short pauses in seconds longdelay = 3 ; Mimimum delay for data load/changes in seconds perk = 0.01 ; Increase in delay for each K cumulatively loaded skdelay = 0.1 ; Delay between keystrokes of SENDKEY command flavor = "~Streets & Trips" ; US version is 'Streets & Trips' while European version is called 'AutoRoute' ;================================================================================================= ; Read in defaults from INI file or set to internal defaults if not specified ;================================================================================================= inifile = "PUSHPINS.INI" IF FileExist( StrCat( DirHome(), inifile)) inifile = StrCat( DirHome(), inifile) ENDIF datalist = stripquotes( IniReadPvt("Main" ,"LIST","",inifile)) iconoffset = IniReadPvt("Main","ICONS" ,"0" ,inifile) shortpause = IniReadPvt("Main","SHORTPAUSE" ,"1" ,inifile) longdelay = IniReadPvt("Main","LONGDELAY" ,"3" ,inifile) typingspeed = IniReadPvt("Main","TYPINGSPEED","100" ,inifile) perk = IniReadPvt("Main","PERK" ,"0.01" ,inifile) flavor = IniReadPvt("Main","FLAVOR" ,"Streets & Trips",inifile) ;====================================================================== ; EXPLANATION OF INI SETTINGS ;====================================================================== ; LIST: The full path and file name of the list of data files to be ; imported into Microsoft Streets & Trips as pushpins. By default ; this is NOT enabled since everyone's directory structures are ; unique. Here is an example of how it looks: ; LIST=C:\GPS\PushPins\PushPinList.txt ;====================================================================== ; ICONS: If a map already has custom pushpin graphics loaded, you must ; tell the import process about it. This setting is the number ; of custom pushpin icons already exist in the map before the ; pushpin program begins the import. The default is zero. ;====================================================================== ;###################################################################### ; ; WARNING! ; ; Changing the INI values below may cause the PUSHPIN program to ; misbehave during the import process. Only change them (usually by ; INCREASING them) if PUSHPINS is misbehaving. ; ;###################################################################### ;====================================================================== ; TYPINGSPEED: The delay, in miliseconds, between keystrokes. ; If your computer is not keeping up, you can tell PUSHPINS ; if it should pause. Make this bigger for slower computers ; and smaller for faster computers. The default is 100ms ; (there are 1000ms in a second) ;====================================================================== ; SHORTPAUSE: The import process needs to pause occasionally to allow ; your computer to keep up with the keystrokes it is entering. ; If you computer is not keeping up, you can tell PUSHPINS ; seconds it should pause. Make this bigger for slower computers ; and smaller for faster computers. The default is 1 ; (i.e., a short pause is one second in length) ;====================================================================== ; LONGDELAY: The more data that is loaded, the more time we must give ; your computer to process the pushpins. This is the MIMIMUM ; delay and the delays will get longer with each data set. The ; length of each subsequent delay is calculated from the file ; size of the data being imported. ; If you computer is not keeping up, you can tell PUSHPINS ; how many seconds it should delay after a major change to a ; set of pushpins. Make this bigger for slower computers ; and smaller for faster computers. The default is 3 ; (i.e., a major delay is three seconds in length) ;====================================================================== ; PERK: The more data that is loaded, the more time we must give your ; computer to process the pushpins. This is how long the delay ; will GROW for every K (kilobyte) of data inported. This ensures ; that the delays get longer, by the proper amount, with each ; data set. ; If you computer is not keeping up, you can tell PUSHPINS ; how many seconds it should delay, for every K that has been ; cumulatively loaded, after a major change to a set of ; pushpins. Make this bigger for slower computers and smaller ; for faster computers. The default is 0.01 (i.e., a major ; delay increases by a hundredth of a second for every kilobyte ; that has been cumulatively loaded) ;====================================================================== ;================================================================================================= ; Get command line parameters and override INI settings ;================================================================================================= FOR option = 1 TO param0 thisparam = param%option% IF StrUpper( StrSub( thisparam, 1, 5)) == "LIST=" datalist = stripquotes( StrTrim( StrSub( thisparam, 6, -1))) ELSE IF StrUpper( StrSub( thisparam, 1, 6)) == "ICONS=" iconoffset = stripquotes( StrTrim( StrSub( thisparam, 7, -1))) ELSE IF StrUpper( StrSub( thisparam, 1, 11)) == "SHORTPAUSE=" shortpause = stripquotes( StrTrim( StrSub( thisparam, 12, -1))) ELSE IF StrUpper( StrSub( thisparam, 1, 10)) == "LONGDELAY=" longdelay = stripquotes( StrTrim( StrSub( thisparam, 11, -1))) ELSE IF StrUpper( StrSub( thisparam, 1, 5)) == "PERK=" perk = stripquotes( StrTrim( StrSub( thisparam, 6, -1))) ELSE IF StrUpper( StrSub( thisparam, 1, 7)) == "FLAVOR=" flavor = stripquotes( StrTrim( StrSub( thisparam, 8, -1))) ELSE IF StrUpper( StrSub( thisparam, 1, 12)) == "TYPINGSPEED=" typingspeed = stripquotes( StrTrim( StrSub( thisparam, 13, -1))) ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF NEXT INTCONTROL(35, typingspeed, 0,0,0) ; set speed at which typing is faked IF StrTrim( datalist) == "" || !FileExist( datalist) datalist = AskFileName( "Select Push Pin List", DIRHOME(),"All File|*.*|Text Files|*.txt|", "*.txt",1) ENDIF IF FileExist( datalist) window_name = StrCat("~", flavor) IF WinExist( window_name ) == @FALSE DISPLAY( 12, "ERROR!", "Window ""%window_name%"" does not exist!") GOTO end ELSE IF WinActivate( window_name ) == @FALSE DISPLAY( 8, "ERROR!", "Unable to activate window >%window_name%<") GOTO end ELSE IF FILEEXIST( datalist) == 1 handle = FILEOPEN( datalist, "READ") IF handle > 0 setnum = iconoffset + 1 WHILE @TRUE paramline = FILEREAD( handle) IF paramline == "*EOF*" BREAK ELSE paramline = STRTRIM( paramline) IF paramline <> "" && STRSUB( paramline, 1, 1) <> "#" ; Skip blank or comment lines dataset = STRTRIM( ITEMEXTRACT( 1, paramline, ";")) ; Full path and file name to CSV file graphic = STRTRIM( ITEMEXTRACT( 2, paramline, ";")) ; Full path and file name to BMP file balloons = STRUPPER( STRTRIM( ITEMEXTRACT( 3, paramline, ";"))) ; How many balloons and which to hide and which to show thisdelay = ((FILESIZE( dataset)/1024) * perk) longdelay = longdelay + thisdelay ; as the number of pushpins on the map increases, the slower the program responds, requiring a gradual increase in intra-dialog delays ;====================================================================== ; Read in the dataset file ;====================================================================== SENDKEY("^i") ;Ctrl-I /Data/Import TIMEDELAY( shortpause) SENDKEY( dataset) SENDKEY("{ENTER}") TIMEDELAY( shortpause) SENDKEY("!n") ;Alt-N NEXT TIMEDELAY( shortpause) SENDKEY("{ENTER}") TIMEDELAY( longdelay) ; Give MSST time to import ;====================================================================== ; Import the icon ;====================================================================== SENDKEY("!dd") ; /Data /Data Properties SENDKEY("{TAB}") SENDKEY("{SPACE}") ; Open Push Pin Palette SENDKEY("{HOME}") SENDKEY("{UP}") SENDKEY("{ENTER}") TIMEDELAY( shortpause) SENDKEY( graphic) SENDKEY("{ENTER}") TIMEDELAY( shortpause) ;====================================================================== ; Assign the icon ;====================================================================== ; Icons are arranged with 8 icons in a horizontal row. ;====================================================================== row = INT( setnum / 8) col = setnum MOD 8 IF col == 0 row = row - 1 col = 8 ENDIF ; Rows are zero based so first row is row 0 ; Columns are one based so first column is colum 1 ; Convert location to DOWN and RIGHT keystrokes downs = row + 1 rights = col - 1 WHILE downs > 0 downs = downs - 1 SENDKEY("{DOWN}") ENDWHILE WHILE rights > 0 rights = rights - 1 SENDKEY("{RIGHT}") ENDWHILE ; Select the graphic TIMEDELAY( shortpause) SENDKEY("{ENTER}") IF STRLEN( balloons) > 0 ;====================================================================== ; Move to the BALOON tab of the dialog ;====================================================================== SENDKEY("{TAB}") SENDKEY("{TAB}") SENDKEY("{TAB}") SENDKEY("{TAB}") SENDKEY("{RIGHT}") SENDKEY("{RIGHT}") SENDKEY("{RIGHT}") ;====================================================================== ; Enable check boxes that are not already ON ;====================================================================== SENDKEY("{TAB}") ;Latitude IF STRSUB(balloons, 1, 1) == "N" SENDKEY("{SPACE}") ; It's already ON so toggle it OFF ENDIF IF STRLEN( balloons) >= 2 SENDKEY("{DOWN}") ; Longitude IF STRSUB(balloons, 2, 1) == "N" SENDKEY("{SPACE}") ; It's already ON so toggle it OFF ENDIF IF STRLEN( balloons) >= 3 SENDKEY("{DOWN}") ; Description IF STRSUB(balloons, 3, 1) == "Y" SENDKEY("{SPACE}") ; Toggle it ON ENDIF IF STRLEN( balloons) >= 4 SENDKEY("{DOWN}") ; URL IF STRSUB(balloons, 4, 1) == "Y" SENDKEY("{SPACE}") ; Toggle it ON ENDIF IF STRLEN( balloons) >= 5 SENDKEY("{DOWN}") ; Type IF STRSUB(balloons, 5, 1) == "Y" SENDKEY("{SPACE}") ; Toggle it ON ENDIF IF STRLEN( balloons) >= 6 SENDKEY("{DOWN}") ; Container IF STRSUB(balloons, 6, 1) == "Y" SENDKEY("{SPACE}") ; Toggle it ON ENDIF IF STRLEN( balloons) >= 7 SENDKEY("{DOWN}") ; Diff IF STRSUB(balloons, 7, 1) == "Y" SENDKEY("{SPACE}") ; Toggle it ON ENDIF IF STRLEN( balloons) >= 8 SENDKEY("{DOWN}") ; Terrain IF STRSUB(balloons, 8, 1) == "Y" SENDKEY("{SPACE}") ; Toggle it ON ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF TIMEDELAY( shortpause) SENDKEY("{ENTER}") TIMEDELAY( longdelay) ; Allow MSST to process the change setnum = setnum + 1 ENDIF ENDIF ENDWHILE ELSE DISPLAY( 8, "ERROR!", "Unable to open parameter file %datalist%") GOTO end ENDIF FILECLOSE( handle) ELSE DISPLAY( 8, "ERROR!", "Unable to open parameter file %datalist%") GOTO end ENDIF ENDIF ENDIF ENDIF GOTO end ;====================================================================== :end ;====================================================================== EXIT