Changeset 13458

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

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

Files:

Legend:

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

    r13437 r13458  
    5454        {  
    5555                Console.WriteLine("usage: gdaloverviews {GDAL dataset name} {resamplealg} {level1} {level2} ...."); 
     56                Console.WriteLine("example: gdaloverviews sample.tif \"NEAREST\" 2 4"); 
    5657                System.Environment.Exit(-1); 
    5758        } 
     
    9495                levels[i-2] = int.Parse(args[i]); 
    9596            } 
    96             if (ds.BuildOverviews(args[1], levels) != (int)CPLErr.CE_None) 
     97                         
     98            if (ds.BuildOverviews(args[1], levels, new Gdal.GDALProgressFuncDelegate(ProgressFunc), "Sample Data") != (int)CPLErr.CE_None) 
    9799            { 
    98100                Console.WriteLine("The BuildOverviews operation doesn't work"); 
     
    128130        } 
    129131    } 
     132 
     133        public static int ProgressFunc(double Complete, IntPtr Message, IntPtr Data) 
     134        { 
     135                Console.Write("Processing ... " + Complete * 100 + "% Completed."); 
     136                if (Message != IntPtr.Zero) 
     137                        Console.Write(" Message:" + System.Runtime.InteropServices.Marshal.PtrToStringAnsi(Message)); 
     138                if (Data != IntPtr.Zero) 
     139                        Console.Write(" Data:" + System.Runtime.InteropServices.Marshal.PtrToStringAnsi(Data)); 
     140         
     141                Console.WriteLine(""); 
     142                return 1; 
     143        } 
    130144} 
  • trunk/gdal/swig/include/csharp/gdal_csharp.i

    r13436 r13458  
    3535 
    3636%include typemaps_csharp.i 
     37 
     38%pragma(csharp) modulecode="public delegate int GDALProgressFuncDelegate(double Complete, IntPtr Message, IntPtr Data);" 
     39 
     40%typemap(imtype) (GDALProgressFunc callback)  "$module.GDALProgressFuncDelegate" 
     41%typemap(cstype) (GDALProgressFunc callback) "$module.GDALProgressFuncDelegate" 
     42%typemap(csin) (GDALProgressFunc callback)  "$csinput" 
     43%typemap(in) (GDALProgressFunc callback) %{ $1 = ($1_ltype)$input; %} 
     44%typemap(imtype) (void* callback_data) "string" 
     45%typemap(cstype) (void* callback_data) "string" 
     46%typemap(csin) (void* callback_data) "$csinput" 
    3747 
    3848%define %rasterio_functions(GDALTYPE,CSTYPE) 
     
    118128/*! Sixty four bit floating point */ %ds_rasterio_functions(DataType.GDT_Float64,double) 
    119129 
    120 public int BuildOverviews( string resampling, int[] overviewlist) { 
     130public int BuildOverviews( string resampling, int[] overviewlist, $module.GDALProgressFuncDelegate callback, string callback_data) { 
    121131      int retval; 
    122132      if (overviewlist.Length <= 0) 
     
    126136      try { 
    127137          Marshal.Copy(overviewlist, 0, ptr, overviewlist.Length); 
    128           retval = BuildOverviews(resampling, overviewlist.Length, ptr, null, null); 
     138          retval = BuildOverviews(resampling, overviewlist.Length, ptr, callback, callback_data); 
    129139      } finally { 
    130140          Marshal.FreeHGlobal(ptr); 
     
    132142      GC.KeepAlive(this); 
    133143      return retval; 
     144  } 
     145public int BuildOverviews( string resampling, int[] overviewlist) { 
     146      return BuildOverviews( resampling, overviewlist, null, null); 
    134147  } 
    135148}