Changeset 13459

Show
Ignore:
Timestamp:
12/28/07 20:49:15 (6 months ago)
Author:
tamas
Message:

Implement GDALProgressFunc callback for C# (fix for #2122)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.5/gdal/swig/csharp/apps/GDALOverviews.cs

    r11217 r13459  
    2424        {  
    2525                Console.WriteLine("usage: gdaloverviews {GDAL dataset name} {resamplealg} {level1} {level2} ...."); 
     26                Console.WriteLine("example: gdaloverviews sample.tif \"NEAREST\" 2 4"); 
    2627                System.Environment.Exit(-1); 
    2728        } 
     
    6465                levels[i-2] = int.Parse(args[i]); 
    6566            } 
    66             if (ds.BuildOverviews(args[1], levels) != (int)CPLErr.CE_None) 
     67            if (ds.BuildOverviews(args[1], levels, new Gdal.GDALProgressFuncDelegate(ProgressFunc), "Sample Data") != (int)CPLErr.CE_None) 
    6768            { 
    6869                Console.WriteLine("The BuildOverviews operation doesn't work"); 
     
    9899        } 
    99100    } 
     101 
     102        public static int ProgressFunc(double Complete, IntPtr Message, IntPtr Data) 
     103        { 
     104                Console.Write("Processing ... " + Complete * 100 + "% Completed."); 
     105                if (Message != IntPtr.Zero) 
     106                        Console.Write(" Message:" + System.Runtime.InteropServices.Marshal.PtrToStringAnsi(Message)); 
     107                if (Data != IntPtr.Zero) 
     108                        Console.Write(" Data:" + System.Runtime.InteropServices.Marshal.PtrToStringAnsi(Data)); 
     109         
     110                Console.WriteLine(""); 
     111                return 1; 
     112        } 
    100113} 
  • branches/1.5/gdal/swig/include/csharp/gdal_csharp.i

    r13112 r13459  
    99 
    1010%include typemaps_csharp.i 
     11 
     12%pragma(csharp) modulecode="public delegate int GDALProgressFuncDelegate(double Complete, IntPtr Message, IntPtr Data);" 
     13 
     14%typemap(imtype) (GDALProgressFunc callback)  "$module.GDALProgressFuncDelegate" 
     15%typemap(cstype) (GDALProgressFunc callback) "$module.GDALProgressFuncDelegate" 
     16%typemap(csin) (GDALProgressFunc callback)  "$csinput" 
     17%typemap(in) (GDALProgressFunc callback) %{ $1 = ($1_ltype)$input; %} 
     18%typemap(imtype) (void* callback_data) "string" 
     19%typemap(cstype) (void* callback_data) "string" 
     20%typemap(csin) (void* callback_data) "$csinput" 
    1121 
    1222%define %rasterio_functions(GDALTYPE,CSTYPE) 
     
    92102/*! Sixty four bit floating point */ %ds_rasterio_functions(DataType.GDT_Float64,double) 
    93103 
    94 public int BuildOverviews( string resampling, int[] overviewlist) { 
     104public int BuildOverviews( string resampling, int[] overviewlist, $module.GDALProgressFuncDelegate callback, string callback_data) { 
    95105      int retval; 
    96106      if (overviewlist.Length <= 0) 
     
    100110      try { 
    101111          Marshal.Copy(overviewlist, 0, ptr, overviewlist.Length); 
    102           retval = BuildOverviews(resampling, overviewlist.Length, ptr, null, null); 
     112          retval = BuildOverviews(resampling, overviewlist.Length, ptr, callback, callback_data); 
    103113      } finally { 
    104114          Marshal.FreeHGlobal(ptr); 
     
    106116      GC.KeepAlive(this); 
    107117      return retval; 
     118  } 
     119public int BuildOverviews( string resampling, int[] overviewlist) { 
     120      return BuildOverviews( resampling, overviewlist, null, null); 
    108121  } 
    109122}